-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNAOMI MODEL EXTRACTOR.bms
239 lines (158 loc) · 4.95 KB
/
NAOMI MODEL EXTRACTOR.bms
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#----------------------------------------------------------------------
# NaomiLib | Models Extractor Ver 1.3
#
# *Script by VincentNL
#
#
# Credits: DKDave & Chrrox for their awesome QBMS input!
#
#----------------------------------------------------------------------
get XXX FILENAME
#print "%NAME%"
Math MVAR = 0
Math A = 1 #Filename number
FOR START
if MVAR = 0
FindLoc FILE_START String "\x01\x00\x00\x00\x01\x00\x00\x00" 0 ""
If FILE_START == ""
Math MVAR = 1
#print "MAGIC TYPE A NOT FOUND!"
endif
endif
if MVAR = 1
FindLoc FILE_START String "\x01\x00\x00\x00\x03\x00\x00\x00" 0 ""
If FILE_START == ""
Math MVAR = 2
#print "MAGIC TYPE B NOT FOUND!"
endif
endif
if MVAR = 2
FindLoc FILE_START String "\x01\x00\x00\x00\x05\x00\x00\x00" 0 ""
If FILE_START == ""
Math MVAR = 3
#print "MAGIC TYPE C NOT FOUND!"
endif
endif
if MVAR = 3
FindLoc FILE_START String "\x00\x00\x00\x00\x05\x00\x00\x00" 0 ""
If FILE_START == ""
Math MVAR = 4
#print "MAGIC TYPE D NOT FOUND!"
endif
endif
if MVAR = 4
FindLoc FILE_START String "\x00\x00\x00\x00\x01\x00\x00\x00" 0 ""
If FILE_START == ""
Math MVAR = 5
#print "MAGIC TYPE E NOT FOUND!"
endif
endif
if MVAR = 5
print "MODELS NOT FOUND!"
break
endif
get FILE_END asize
Xmath FILE_END "FILE_END-0x8" # Last Mesh in a model archive is always at -0x8 from file end
goto 0x0
#--------------------------------
# MAIN LOOP1
#--------------------------------
For LOOP1
if MVAR = 0
FindLoc MODEL_START String "\x01\x00\x00\x00\x01\x00\x00\x00" 0 ""
endif
if MVAR = 1
FindLoc MODEL_START String "\x01\x00\x00\x00\x03\x00\x00\x00" 0 ""
endif
if MVAR = 2
FindLoc MODEL_START String "\x01\x00\x00\x00\x05\x00\x00\x00" 0 ""
endif
if MVAR = 3
FindLoc MODEL_START String "\x00\x00\x00\x00\x05\x00\x00\x00" 0 ""
endif
if MVAR = 4
FindLoc MODEL_START String "\x00\x00\x00\x00\x01\x00\x00\x00" 0 ""
endif
if MVAR = 5
break
endif
#-------------------------------------
# MAGIC A TYPE
#-------------------------------------
If MODEL_START == "" && MVAR = 4
break
endif
If MODEL_START == "" && MVAR != 4
goto 0x0
Xmath MVAR "MVAR + 1"
Else
#------------------------
# CHECK IF NAOMILIB MODEL
#------------------------
Xmath MODEL_TEST "MODEL_START + 0x1B"
goto MODEL_TEST
get TEST byte
XMath MODEL_CHECK "MODEL_START + 0x68"
goto MODEL_CHECK
get CHECK_VALUE long
If CHECK_VALUE > 0x09 && CHECK_VALUE <= 0x01FF && TEST >= 0x80 && TEST <= 0x82 # If value is in range
#--------------------
# YES! NAOMI LIB MODEL
#--------------------
Math CHECK = 1
Xmath MESH_END_POINTER "MODEL_START+0x64"
goto MESH_END_POINTER
get MESH_SIZE long
Xmath MESH_END "MESH_SIZE+MESH_END_POINTER+0x4"
if MESH_END <= FILE_END && MESH_END > 0 && MESH_SIZE >= 0 # Mesh is within file offset, valid model
goto MESH_END
get NEXT_HEADER long
goto MESH_END
Else # Mesh is out of bounds, not a valid model
goto MODEL_START
get JUNK longlong
break
Endif
Else
#--------------------------
# NO! NOT A NAOMILIB MODEL
#--------------------------
Math CHECK = 2
goto MODEL_START
get JUNK longlong
Endif
For LOOP2
If CHECK = 1
#--------------------------------
# NEW MESH: LOOP2
#--------------------------------
#--------------------
# NEW MESH
#--------------------
if NEXT_HEADER != 0
Xmath MESH_END_POINTER "MESH_END+0x48+0x4"
goto MESH_END_POINTER
get MESH_SIZE long
Xmath MESH_END "MESH_SIZE+MESH_END_POINTER+0x4"
if MESH_END <= FILE_END && MESH_END > 0 && MESH_SIZE >= 0 # Mesh is within file offset, valid model
goto MESH_END
get NEXT_HEADER long
Else # Mesh is out of bounds, not a valid model
goto MODEL_START
get JUNK longlong
break
Endif
Else
Xmath MESH_END "MESH_END+8" # Add endstring 8 bytes
Xmath MODEL_SIZE "MESH_END-MODEL_START"
String NAME P "%XXX%_MODEL_%A%.bin"
log NAME MODEL_START MODEL_SIZE # Log the model with detected meshes so far
XMath A "A+1"
goto MODEL_START
get JUNK longlong
break
Endif
Next LOOP2
Endif
Endif
Next LOOP1