-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfmt_sho_ps2_map_bsp.py
92 lines (66 loc) · 2.66 KB
/
fmt_sho_ps2_map_bsp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""Noesis Python Plugin
File: fmt_sho_ps2_map_bsp.py
Authors: Rodolfo Nuñez (roocker666)
Laurynas Zubavičius (Sparagas)
Purpose: Silent Hill Origins / Silent Hill Zero (Sony - PlayStation 2)
Category: 3D static map models
File Mask: *.bsp
ID Bytes:
"""
from inc_noesis import *
HAS_PADDING = b'\x6C'
HAS_NO_PADDING = b'\x68'
def registerNoesisTypes():
handle = noesis.register("SHO Map PS2", ".bsp")
noesis.setHandlerTypeCheck(handle, CheckType)
noesis.setHandlerLoadModel(handle, LoadModel)
return 1
def CheckType(data):
return 1
def LoadModel(data, mdlList):
bs = NoeBitStream(data)
ctx = rapi.rpgCreateContext()
search_pos = 0
i = 0
while True:
# Find the next occurrence of the pattern
search_pos = data.find(b'\x05\x04\x01\x00\x01\x00', search_pos)
if search_pos == -1:
break # Exit the loop if no more occurrences are found
search_pos += 7 # Skip searched bytes
# try to skip bad SHSM data
original_pos = search_pos
next_pos = data.find(b'\x05\x04\x01\x00\x01\x00', search_pos)
if next_pos > 0 and next_pos - original_pos < 50:
search_pos = next_pos + 7
# sorry was lazy to do it in a loop
original_pos = search_pos
next_pos = data.find(b'\x05\x04\x01\x00\x01\x00', search_pos)
if next_pos > 0 and next_pos - original_pos < 50:
search_pos = next_pos + 7
bs.seek(search_pos)
vnum = bs.readByte()
check_pad = bs.read(1)
if check_pad == HAS_PADDING:
vbuf = bs.read(vnum * 16)
elif check_pad == HAS_NO_PADDING:
vbuf = bs.read(vnum * 12)
bs.seek(data.find(b'\x05\x04\x01\x00\x01\x01', bs.tell()) + 9)
uvbuf = bs.read(vnum * 8)
bs.seek(data.find(b'\x05\x04\x01\x00\x01\x02', bs.tell()) + 9)
vcolbuf = bs.read(vnum * 4)
bs.seek(data.find(b'\x05\x04\x01\x00\x01\x03', bs.tell()) + 9)
print('found ', i)
if check_pad == HAS_PADDING:
rapi.rpgBindPositionBuffer(vbuf, noesis.RPGEODATA_FLOAT, 16)
elif check_pad == HAS_NO_PADDING:
rapi.rpgBindPositionBuffer(vbuf, noesis.RPGEODATA_FLOAT, 12)
rapi.rpgBindUV1Buffer(uvbuf, noesis.RPGEODATA_FLOAT, 8)
rapi.rpgBindColorBuffer(vcolbuf, noesis.RPGEODATA_UBYTE, 4, 4)
rapi.rpgCommitTriangles(None, noesis.RPGEO_NONE, vnum, noesis.RPGEO_TRIANGLE_STRIP)
rapi.rpgSetName('mesh{}'.format(i))
i += 1
mdl = rapi.rpgConstructModel()
mdl.setModelMaterials(NoeModelMaterials([], [NoeMaterial('mat0', '')]))
mdlList.append(mdl)
return 1