source: oup/_old_/text/_irf_oni.onlv.vb@ 124

Last change on this file since 124 was 46, checked in by alloc, 18 years ago
File size: 14.3 KB
Line 
1Public Type LWOPolygon
2 NumVe As Integer
3 P1 As Integer
4 P2 As Integer
5 P3 As Integer
6 Surfa As Integer
7End Type
8
9Public Type PolDef
10 P1 As Integer
11 P2 As Integer
12 P3 As Integer
13End Type
14
15'Texture Coordinate Entry
16Public Type TXCAentry
17 X As Single
18 Y As Single
19End Type
20
21'Texture Coordinate Lists
22Public Type TXCA 'Length
23 ID As Long '4
24 Version As Long '8
25 Filler(1 To 5) As Long '28
26 NumEntries As Long '32
27End Type
28
29'Level Data Reference List
30Public Type ONLV 'Length
31 ID As Long '4
32 Version As Long '8
33 LevelName As String * 64 '72
34 AKEVid As Long '76
35 OBOAid As Long '80
36 ONMAid As Long '84
37 ONFAid As Long '88
38 ONTAid As Long '92
39 ONSKid As Long '96
40 Unkn As Long '100
41 AISAid As Long '104
42 AITRid As Long '108
43 ONSAid As Long '112
44 OBDCid As Long '116
45 ONOAid As Long '120
46 Fill(1 To 161) As Long '764
47 CRSAid As Long '768
48End Type
49
50Public Type AGQG
51 ID As Long
52 unk(1 To 24) As Byte
53 NumEntries As Long
54End Type
55
56Public Type AGQGEntry
57 VertIndex(1 To 4) As Long
58 VertUVIndex(1 To 4) As Long
59 LData_1(1 To 4) As Byte
60 LData_2(1 To 4) As Byte
61 LData_3(1 To 4) As Byte
62 LData_4(1 To 4) As Byte
63 unk(1 To 2) As Long
64End Type
65
66Public Type AGQREntry
67 TexIndex As Integer
68 unk As Integer
69End Type
70
71Public Type TXMA
72 ID As Long
73 shit(1 To 24) As Byte
74 NumEntries As Long
75End Type
76
77Public Type TXMAEntry
78 TXMP_ID As Long
79End Type
80
81
82
83
84
85Public Sub CExportONLV(Optional FileName As String)
86Form1.StatusBar1.SimpleText = "Status: Extracting LEVEL....."
87Dim ID4 As Long
88Dim I As Long
89Dim L As Long
90Dim LwoP() As LWOPolygon
91Dim OniPol2() As PolDef
92Dim NP As Long
93Dim numb As Long
94
95Dim TXMA1 As TXMA
96Dim AGQR1 As TXMA
97Dim TXCA1 As TXCA
98Dim TXCA_E() As TXCAentry
99Dim TXMA_E() As TXMAEntry
100Dim AGQR_E() As AGQREntry
101Dim TexNames() As String
102
103If FileName = "" Then
104 Form1.CD.DialogTitle = "Unpack resource..."
105 Form1.CD.FileName = OniEntry(Curr).szTagName
106 Form1.CD.Filter = "LightWave (*.lwo)|*.lwo"
107 Form1.CD.Flags = &H2 + &H4
108 Form1.CD.ShowSave
109 FileName = Form1.CD.FileName
110 If FileName = "" Then Exit Sub
111End If
112
113DoEvents
114
115Open DatFile For Binary As #1
116 Get 1, OniEntry(Curr).rDataPosition, ONLV
117 For I = 0 To UBound(OniEntry) - 1
118 Get 1, OniEntry(I).rDataPosition, ID4
119 If ID4 = ONLV.AKEVid Then
120 Get 1, OniEntry(I).rDataPosition, AKEV
121 Exit For
122 End If
123 Next I
124
125 'Find ID of PNTA
126 For I = 0 To UBound(OniEntry) - 1
127 Get 1, OniEntry(I).rDataPosition, ID4
128 If ID4 = AKEV.PNTAid Then
129 Get 1, OniEntry(I).rDataPosition, PNTA
130 ReDim PNTAentry(PNTA.NumEntries - 1)
131 Get 1, , PNTAentry
132 Exit For
133 End If
134 Next I
135
136 For I = 0 To UBound(OniEntry) - 1
137 Get 1, OniEntry(I).rDataPosition, ID4
138 If ID4 = AKEV.AGQGid Then
139 Get 1, OniEntry(I).rDataPosition, AGQG
140 ReDim AGQGEntry(AGQG.NumEntries - 1)
141 Get 1, , AGQGEntry
142 Exit For
143 End If
144 Next I
145
146 'TXCA
147 For I = 0 To UBound(OniEntry) - 1
148 Get 1, OniEntry(I).rDataPosition, ID4
149 If ID4 = AKEV.TXCAid Then
150 Get 1, OniEntry(I).rDataPosition, TXCA1
151 ReDim TXCA_E(TXCA1.NumEntries - 1)
152 Get 1, , TXCA_E
153 ReDim Preserve TXCA_E(PNTA.NumEntries - 1)
154 Exit For
155 End If
156 Next I
157
158 'TXMA
159 For I = 0 To UBound(OniEntry) - 1
160 Get 1, OniEntry(I).rDataPosition, ID4
161 If ID4 = AKEV.TXMAid Then
162 Get 1, OniEntry(I).rDataPosition, TXMA1
163 ReDim TXMA_E(TXMA1.NumEntries - 1)
164 Get 1, , TXMA_E
165 Exit For
166 End If
167 Next I
168
169 'AGQR
170 For I = 0 To UBound(OniEntry) - 1
171 Get 1, OniEntry(I).rDataPosition, ID4
172 If ID4 = AKEV.AGQRid Then
173 Get 1, OniEntry(I).rDataPosition, AGQR1
174 ReDim AGQR_E(AGQR1.NumEntries - 1)
175 Get 1, , AGQR_E
176 Exit For
177 End If
178 Next I
179
180 ReDim TexNames(TXMA1.NumEntries - 1)
181
182 For I = 0 To TXMA1.NumEntries - 1
183 For L = 0 To UBound(OniEntry) - 1
184 Get 1, OniEntry(L).rDataPosition, ID4
185 If ID4 = TXMA_E(I).TXMP_ID Then
186 TexNames(I) = OniEntry(L).szTagName + Ext
187 Exit For
188 End If
189 Next L
190 Next I
191
192Close
193'Ok
194' so we have: 3D points, Texture coordinates and list of polygons,
195' end reading, now convert data
196I = 0
197Open App.Path + "\lwo.tmp" For Binary As #11
198Form1.StatusBar1.SimpleText = "Status: Extracting LEVEL [Reading Polygons...]"
199Seek 11, 1
200
201'reading polygons.......
202
203NP = AGQG.NumEntries * 2
204For I = 0 To AGQG.NumEntries - 1
205Select Case GetPureFile(TexNames(AGQR_E(I).TexIndex))
206 Case "BLUEGRID02", "_DOOR_FRAME", "", "COLLISION"
207 NP = NP - 2
208 Case Else
209 Select Case Mid$(GetPureFile(TexNames(AGQR_E(I).TexIndex)), 1, 5)
210 Case "_DOOR"
211 NP = NP - 2
212 Case Else
213 Put 11, , TestSwapInt(AGQGEntry(I).VertIndex(1))
214 Put 11, , TestSwapInt(AGQGEntry(I).VertIndex(2))
215 Put 11, , TestSwapInt(AGQGEntry(I).VertIndex(3))
216 Put 11, , TestSwapInt(AGQGEntry(I).VertIndex(3))
217 Put 11, , TestSwapInt(AGQGEntry(I).VertIndex(4))
218 Put 11, , TestSwapInt(AGQGEntry(I).VertIndex(1))
219 End Select
220 End Select
221Next I
222
223
224
225ReDim OniPol2(NP - 1)
226ReDim LwoP(NP - 1)
227Get 11, 1, OniPol2
228
229For I = 0 To NP - 1
230 LwoP(I).NumVe = ISItoMSI(3)
231 LwoP(I).P1 = OniPol2(I).P1
232 LwoP(I).P2 = OniPol2(I).P2
233 LwoP(I).P3 = OniPol2(I).P3
234 LwoP(I).Surfa = ISItoMSI(1)
235Next I
236
237I = Empty
238
239Close
240
241On Error Resume Next
242 Kill App.Path + "\*.tmp"
243On Error GoTo 0
244
245Form1.StatusBar1.SimpleText = "Status: Extracting LEVEL [Writing...]"
246Form1.ProgressBar1.Max = PNTA.NumEntries
247Form1.ProgressBar1.Value = 0
248If LevelType = 5 Or LevelType = 10 Then
249 FileName = GetPureFile(FileName) + ".raw"
250End If
251
252For I = 0 To PNTA.NumEntries - 1
253 If PNTAentry(I).X > 2000000.1 Then PNTAentry(I).X = 0
254 If PNTAentry(I).Y > 2000000.1 Then PNTAentry(I).Y = 0
255 If PNTAentry(I).Z > 2000000.1 Then PNTAentry(I).Z = 0
256 If PNTAentry(I).X < -2000000.1 Then PNTAentry(I).X = 0
257 If PNTAentry(I).Y < -2000000.1 Then PNTAentry(I).Y = 0
258 If PNTAentry(I).Z < -2000000.1 Then PNTAentry(I).Z = 0
259Next I
260
261Select Case LevelType
262Case 1
263
264Open FileName For Binary As #1
265 Put 1, , "FORM"
266 Put 1, , ISLtoMSL(12 + (PNTA.NumEntries * 12) + 8 + 6 + 8 + (NP * 10))
267 Put 1, , "LWOBPNTS"
268 Put 1, , ISLtoMSL(PNTA.NumEntries * 12)
269 For I = 0 To PNTA.NumEntries - 1
270 Put 1, , SwapFloat(PNTAentry(I).X)
271 Put 1, , SwapFloat(PNTAentry(I).Y)
272 Put 1, , SwapFloat(PNTAentry(I).Z)
273 Form1.ProgressBar1.Value = I
274 Next I
275 Put 1, , "SRFS"
276 Put 1, , ISLtoMSL(6)
277 Put 1, , "Level"
278 Put 1, , CByte(0)
279 Put 1, , "POLS"
280 Put 1, , ISLtoMSL(NP * 10)
281 Put 1, , LwoP
282Close
283Case 6
284
285' Convert Oni level to RAW 3D Binary
286Open GetPureFile(FileName) + ".rwb" For Binary As #1
287For I = 0 To AGQG.NumEntries - 1
288 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(1)).X
289 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(1)).Y
290 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(1)).Z
291 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(2)).X
292 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(2)).Y
293 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(2)).Z
294 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(3)).X
295 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(3)).Y
296 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(3)).Z
297 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(3)).X
298 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(3)).Y
299 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(3)).Z
300 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(4)).X
301 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(4)).Y
302 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(4)).Z
303 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(1)).X
304 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(1)).Y
305 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(1)).Z
306Next I
307
308Close
309Case 7
310
311' B3D
312Open GetPureFile(FileName) + ".b3d" For Binary As #1
313Put 1, , "Big3DbyOleg"
314Put 1, , CLng(1067030938)
315Put 1, , "POINTS "
316Put 1, , CLng(PNTA.NumEntries)
317For I = 0 To PNTA.NumEntries - 1
318 Put 1, , PNTAentry(I).X
319 Put 1, , PNTAentry(I).Y
320 Put 1, , PNTAentry(I).Z
321Next I
322
323Put 1, , "POLYGONS"
324Put 1, , CLng(NP * 2)
325For I = 0 To AGQG.NumEntries - 1
326Select Case GetPureFile(TexNames(AGQR_E(I).TexIndex))
327 Case "BLUEGRID02", "_DOOR_FRAME", "", "COLLISION"
328 'nothing
329 Case Else
330 Select Case Mid$(GetPureFile(TexNames(AGQR_E(I).TexIndex)), 1, 5)
331 Case "_DOOR"
332 'nothing
333 Case Else
334 Put 1, , CLng(3)
335 Put 1, , AGQGEntry(I).VertIndex(1)
336 Put 1, , AGQGEntry(I).VertIndex(2)
337 Put 1, , AGQGEntry(I).VertIndex(3)
338 Put 1, , CLng(0)
339 Put 1, , CLng(3)
340 Put 1, , AGQGEntry(I).VertIndex(3)
341 Put 1, , AGQGEntry(I).VertIndex(4)
342 Put 1, , AGQGEntry(I).VertIndex(1)
343 Put 1, , CLng(0)
344 End Select
345End Select
346Next I
347Put 1, , CLng(0)
348Close
349
350Case 8
351
352'Delete shit from the Oni level
353numb = AGQG.NumEntries
354 ReDim Preserve PNTAentry(PNTA.NumEntries + 3)
355 PNTAentry(PNTA.NumEntries + 0).X = -9
356 PNTAentry(PNTA.NumEntries + 0).Y = 0
357 PNTAentry(PNTA.NumEntries + 0).Z = -3
358 PNTAentry(PNTA.NumEntries + 1).X = -9
359 PNTAentry(PNTA.NumEntries + 1).Y = 0
360 PNTAentry(PNTA.NumEntries + 1).Z = 8
361 PNTAentry(PNTA.NumEntries + 2).X = 11
362 PNTAentry(PNTA.NumEntries + 2).Y = 0
363 PNTAentry(PNTA.NumEntries + 2).Z = -3
364 PNTAentry(PNTA.NumEntries + 3).X = 11
365 PNTAentry(PNTA.NumEntries + 3).Y = 0
366 PNTAentry(PNTA.NumEntries + 3).Z = 8
367
368 If Form1.mnuDelGarbage.Checked = True Then
369 For I = 0 To AGQG.NumEntries - 1
370 Select Case Mid$(GetPureFile(TexNames(AGQR_E(I).TexIndex)), 1, 5)
371 Case "_DOOR"
372 AGQGEntry(I).VertIndex(1) = PNTA.NumEntries + 0
373 AGQGEntry(I).VertIndex(2) = PNTA.NumEntries + 1
374 AGQGEntry(I).VertIndex(3) = PNTA.NumEntries + 2
375 AGQGEntry(I).VertIndex(4) = PNTA.NumEntries + 3
376 'numb = numb - 1
377 End Select
378 Next I
379 End If
380
381 For I = 0 To AGQG.NumEntries - 1
382 Select Case GetPureFile(TexNames(AGQR_E(I).TexIndex))
383 Case "BLUEGRID02", "_DOOR_FRAME", "", "COLLISION"
384 AGQGEntry(I).VertIndex(1) = PNTA.NumEntries + 0
385 AGQGEntry(I).VertIndex(2) = PNTA.NumEntries + 1
386 AGQGEntry(I).VertIndex(3) = PNTA.NumEntries + 2
387 AGQGEntry(I).VertIndex(4) = PNTA.NumEntries + 3
388 numb = numb - 1
389 End Select
390 Next I
391
392'B3D + materials
393Open GetPureFile(FileName) + ".b3d" For Binary As #1
394Put 1, , "Big3DbyOleg"
395Put 1, , CLng(1067030938)
396Put 1, , "POINTS "
397Put 1, , CLng(numb * 4)
398
399For I = 0 To AGQG.NumEntries - 1
400 ' Begin polygon
401Select Case GetPureFile(TexNames(AGQR_E(I).TexIndex))
402 Case "BLUEGRID02", "_DOOR_FRAME", "", "COLLISION"
403 'nothing
404 Case Else
405 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(1)).X
406 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(1)).Y
407 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(1)).Z
408
409 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(2)).X
410 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(2)).Y
411 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(2)).Z
412
413 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(3)).X
414 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(3)).Y
415 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(3)).Z
416
417 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(4)).X
418 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(4)).Y
419 Put 1, , PNTAentry(AGQGEntry(I).VertIndex(4)).Z
420End Select
421 ' end polygon
422Next I
423
424Put 1, , "POLYGONS"
425Put 1, , CLng(numb * 2)
426L = 0
427ID4 = 0
428For I = 0 To AGQG.NumEntries - 1
429Select Case GetPureFile(TexNames(AGQR_E(I).TexIndex))
430 Case "BLUEGRID02", "_DOOR_FRAME", "", "COLLISION"
431 'nothing
432 Case Else
433 Put 1, , CLng(3)
434 Put 1, , CLng(L)
435 Put 1, , CLng(L + 1)
436 Put 1, , CLng(L + 2)
437 Put 1, , CLng(ID4)
438 Put 1, , CLng(3)
439 Put 1, , CLng(L + 2)
440 Put 1, , CLng(L + 3)
441 Put 1, , CLng(L)
442 Put 1, , CLng(ID4)
443 ID4 = ID4 + 1
444 L = L + 4
445End Select
446Next I
447
448Put 1, , CLng(1)
449Put 1, , "TEX_UV "
450Put 1, , CLng(numb * 4)
451L = 0
452
453For I = 0 To AGQG.NumEntries - 1
454Select Case GetPureFile(TexNames(AGQR_E(I).TexIndex))
455 Case "BLUEGRID02", "_DOOR_FRAME", "", "COLLISION"
456 'nothing
457 Case Else
458 Put 1, , CLng(L)
459 L = L + 1
460 Put 1, , TXCA_E(AGQGEntry(I).VertUVIndex(1)).X
461 Put 1, , TXCA_E(AGQGEntry(I).VertUVIndex(1)).Y
462 Put 1, , CLng(L)
463 L = L + 1
464 Put 1, , TXCA_E(AGQGEntry(I).VertUVIndex(2)).X
465 Put 1, , TXCA_E(AGQGEntry(I).VertUVIndex(2)).Y
466 Put 1, , CLng(L)
467 L = L + 1
468 Put 1, , TXCA_E(AGQGEntry(I).VertUVIndex(3)).X
469 Put 1, , TXCA_E(AGQGEntry(I).VertUVIndex(3)).Y
470 Put 1, , CLng(L)
471 L = L + 1
472 Put 1, , TXCA_E(AGQGEntry(I).VertUVIndex(4)).X
473 Put 1, , TXCA_E(AGQGEntry(I).VertUVIndex(4)).Y
474End Select
475 'Put 1, , CSng((-TXCA_E(I).Y) + 1)
476Next I
477
478L = 0
479Put 1, , "MATERIAL"
480Put 1, , CLng(numb)
481For I = 0 To AGQG.NumEntries - 1
482Select Case GetPureFile(TexNames(AGQR_E(I).TexIndex))
483 Case "BLUEGRID02", "_DOOR_FRAME", "", "COLLISION"
484 'nothing
485 Case Else
486 Put 1, , CLng(1)
487 Put 1, , CLng(L)
488 Put 1, , CLng(Len(TexNames(AGQR_E(I).TexIndex)))
489 Put 1, , TexNames(AGQR_E(I).TexIndex)
490 L = L + 1
491End Select
492Next I
493Close
494
495Open GetPureFile(FileName) + ".tlist" For Binary As #4
496 For I = 0 To AGQR1.NumEntries - 1
497 Select Case GetPureFile(TexNames(AGQR_E(I).TexIndex))
498 Case "BLUEGRID02", "_DOOR_FRAME", "", "COLLISION"
499 'nothing
500 Case Else
501 Put 4, , AGQR_E(I).TexIndex
502 End Select
503 Next I
504Close
505
506Open GetPureFile(FileName) + ".txt" For Output As #4
507 Print #4, CStr(TXMA1.NumEntries)
508 For I = 0 To TXMA1.NumEntries - 1
509 Print #4, CStr(GetPureFile(TexNames(I)))
510 Next I
511Close
512
513If Form1.mnuB3DLight.Checked = True Then
514Open GetPureFile(FileName) + ".ltcs" For Binary As #4
515 For I = 0 To AGQR1.NumEntries - 1
516 Select Case GetPureFile(TexNames(AGQR_E(I).TexIndex))
517 Case "BLUEGRID02", "_DOOR_FRAME", "", "COLLISION"
518 'nothing
519 Case Else
520 Put 4, , AGQGEntry(I).LData_1
521 Put 4, , AGQGEntry(I).LData_2
522 Put 4, , AGQGEntry(I).LData_3
523 Put 4, , AGQGEntry(I).LData_4
524 End Select
525 Next I
526Close
527End If
528End Select
529
530Form1.ProgressBar1.Value = 0
531Form1.ProgressBar1.Max = UBound(OniEntry)
532
533Form1.StatusBar1.SimpleText = "OK"
534'Dispose
535I = Empty
536NP = Empty
537Erase LwoP
538Erase PNTAentry
539Erase OniPol2
540Erase AGQGEntry
541Erase AGQR_E
542Erase TXMA_E
543Erase TXCA_E
544Erase TexNames
545End Sub
Note: See TracBrowser for help on using the repository browser.