1 | UNIT Unit9_data_structures;
|
---|
2 | INTERFACE
|
---|
3 | USES SysUtils, ABSMain, DB, ABSDecUtil, Unit3_data;
|
---|
4 |
|
---|
5 | TYPE
|
---|
6 | Tstructure_entry=RECORD
|
---|
7 | name:String;
|
---|
8 | offset:LongWord;
|
---|
9 | datatype:Word; // 1..4: Integer[1..4] dec; 5..8: Integer[1..4] hex; 9: float; 10: bitset; 11: raw-addr; 10000+: string[0+]
|
---|
10 | description:String;
|
---|
11 | END;
|
---|
12 | Tstructure_info=RECORD
|
---|
13 | extension:String;
|
---|
14 | typedesc:String;
|
---|
15 | entries:Array OF Tstructure_entry;
|
---|
16 | END;
|
---|
17 | Tstructures=Array OF Tstructure_info;
|
---|
18 | THandler=FUNCTION(fileid:LongWord):TRawList;
|
---|
19 | TRawListHandlers=RECORD
|
---|
20 | Ext:String[4];
|
---|
21 | needed:Boolean;
|
---|
22 | Handler:THandler;
|
---|
23 | END;
|
---|
24 |
|
---|
25 | VAR
|
---|
26 | structure_infos:Tstructures;
|
---|
27 | RawListHandlers:Array OF TRawListHandlers;
|
---|
28 |
|
---|
29 |
|
---|
30 | FUNCTION GetDataType(typeid:Word):String;
|
---|
31 | FUNCTION GetStructureInfoId(ext:String):Integer;
|
---|
32 | FUNCTION GetTypeDataLength(datatype:Word):Word;
|
---|
33 | FUNCTION GetRawInfo(fileid,dat_offset:LongWord):TRawInfo;
|
---|
34 | FUNCTION GetRawList(fileid:LongWord):TRawList;
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 | IMPLEMENTATION
|
---|
39 | USES Unit2_functions;
|
---|
40 |
|
---|
41 | FUNCTION GetTypeDataLength(datatype:Word):Word;
|
---|
42 | BEGIN
|
---|
43 | CASE datatype OF
|
---|
44 | 1..4: Result:=datatype;
|
---|
45 | 5..8: Result:=datatype-4;
|
---|
46 | 9: Result:=4;
|
---|
47 | 10: Result:=1;
|
---|
48 | 11: Result:=4;
|
---|
49 | 10000..65535: Result:=datatype-10000;
|
---|
50 | END;
|
---|
51 | END;
|
---|
52 |
|
---|
53 |
|
---|
54 | FUNCTION GetStructureInfoId(ext:String):Integer;
|
---|
55 | VAR
|
---|
56 | i:Integer;
|
---|
57 | BEGIN
|
---|
58 | FOR i:=0 TO High(structure_infos) DO BEGIN
|
---|
59 | IF structure_infos[i].extension=ext THEN BEGIN
|
---|
60 | Result:=i;
|
---|
61 | Exit;
|
---|
62 | END;
|
---|
63 | END;
|
---|
64 | Result:=-1;
|
---|
65 | END;
|
---|
66 |
|
---|
67 |
|
---|
68 | FUNCTION GetDataType(typeid:Word):String;
|
---|
69 | BEGIN
|
---|
70 | CASE typeid OF
|
---|
71 | 1..4: Result:='Int'+IntToStr(typeid*8);
|
---|
72 | 5..8: Result:='Int'+IntToStr((typeid-4)*8);
|
---|
73 | 9: Result:='Float';
|
---|
74 | 10: Result:='BitSet';
|
---|
75 | 11: Result:='Raw-Address';
|
---|
76 | 10000..65535: Result:='String('+IntToStr(typeid-10000)+')';
|
---|
77 | END;
|
---|
78 | END;
|
---|
79 |
|
---|
80 |
|
---|
81 | FUNCTION GetRawInfo(fileid,dat_offset:LongWord):TRawInfo;
|
---|
82 | VAR
|
---|
83 | i:LongWord;
|
---|
84 | raw_list:TRawList;
|
---|
85 | BEGIN
|
---|
86 | raw_list:=GetRawList(fileid);
|
---|
87 | Result.src_id:=0;
|
---|
88 | Result.src_offset:=0;
|
---|
89 | Result.raw_addr:=0;
|
---|
90 | Result.raw_size:=0;
|
---|
91 | FOR i:=0 TO High(raw_list) DO BEGIN
|
---|
92 | IF raw_list[i].src_offset=dat_offset THEN BEGIN
|
---|
93 | Result.src_id:=fileid;
|
---|
94 | Result.src_offset:=raw_list[i].src_offset;
|
---|
95 | Result.raw_addr:=raw_list[i].raw_addr;
|
---|
96 | Result.raw_size:=raw_list[i].raw_size;
|
---|
97 | Result.loc_sep:=raw_list[i].loc_sep;
|
---|
98 | Break;
|
---|
99 | END;
|
---|
100 | END;
|
---|
101 | END;
|
---|
102 |
|
---|
103 | FUNCTION GetRawList(fileid:LongWord):TRawList;
|
---|
104 | VAR
|
---|
105 | i:LongWord;
|
---|
106 | Query:TABSQuery;
|
---|
107 | BEGIN
|
---|
108 | IF opened_state=opened_dat THEN BEGIN
|
---|
109 | FOR i:=0 TO High(RawListHandlers) DO
|
---|
110 | IF UpperCase(RawListHandlers[i].Ext)=UpperCase(dat_files[fileid].extension) THEN
|
---|
111 | IF RawListHandlers[i].needed THEN BEGIN
|
---|
112 | Result:=RawListHandlers[i].Handler(fileid);
|
---|
113 | Break;
|
---|
114 | END ELSE
|
---|
115 | Break;
|
---|
116 | END ELSE BEGIN
|
---|
117 | SetLength(Result,0);
|
---|
118 | Query.SQL.Text:='SELECT [src_link_offset],[size] FROM rawmap WHERE [src_id]='+IntToStr(fileid)+' ORDER BY src_link_offset ASC;';
|
---|
119 | Query.Open;
|
---|
120 | IF Query.RecordCount>0 THEN BEGIN
|
---|
121 | Query.First;
|
---|
122 | SetLength(Result,Query.RecordCount);
|
---|
123 | i:=0;
|
---|
124 | REPEAT
|
---|
125 | Result[i].src_id:=fileid;
|
---|
126 | Result[i].src_offset:=Query.FieldByName('src_link_offset').AsInteger;
|
---|
127 | Result[i].raw_addr:=0;
|
---|
128 | Result[i].raw_size:=Query.FieldByName('size').AsInteger;
|
---|
129 | Inc(i);
|
---|
130 | Query.Next;
|
---|
131 | UNTIL Query.EOF;
|
---|
132 | END;
|
---|
133 | Query.Close;
|
---|
134 | END;
|
---|
135 | END;
|
---|
136 |
|
---|
137 |
|
---|
138 | FUNCTION AGDB(fileid:LongWord):TRawList;
|
---|
139 | VAR
|
---|
140 | link:LongWord;
|
---|
141 | links:LongWord;
|
---|
142 | i:LongWord;
|
---|
143 | BEGIN
|
---|
144 | IF NOT dat_os_mac THEN BEGIN
|
---|
145 | LoadDatFilePart(fileid,$1C,4,@links);
|
---|
146 | links:=links*2;
|
---|
147 | SetLength(Result,links);
|
---|
148 | FOR i:=0 TO links-1 DO BEGIN
|
---|
149 | Result[i].src_offset:=$20+i*4;
|
---|
150 | LoadDatFilePart(fileid,$20+i*4,4,@link);
|
---|
151 | Result[i].raw_addr:=link;
|
---|
152 | Result[i].raw_size:=0{????????????????????????????????};
|
---|
153 | Result[i].loc_sep:=False;
|
---|
154 | END;
|
---|
155 | END;
|
---|
156 | END;
|
---|
157 | FUNCTION BINA(fileid:LongWord):TRawList;
|
---|
158 | VAR
|
---|
159 | link:LongWord;
|
---|
160 | datasize:LongWord;
|
---|
161 | BEGIN
|
---|
162 | LoadDatFilePart(fileid,$0C,4,@link);
|
---|
163 | LoadDatFilePart(fileid,$08,4,@datasize);
|
---|
164 | SetLength(Result,1);
|
---|
165 | Result[0].src_offset:=$0C;
|
---|
166 | Result[0].raw_addr:=link;
|
---|
167 | Result[0].raw_size:=datasize;
|
---|
168 | Result[0].loc_sep:=dat_os_mac;
|
---|
169 | END;
|
---|
170 | FUNCTION OSBD(fileid:LongWord):TRawList;
|
---|
171 | VAR
|
---|
172 | link:LongWord;
|
---|
173 | datasize:LongWord;
|
---|
174 | BEGIN
|
---|
175 | LoadDatFilePart(fileid,$08,4,@datasize);
|
---|
176 | LoadDatFilePart(fileid,$0C,4,@link);
|
---|
177 | SetLength(Result,1);
|
---|
178 | Result[0].src_offset:=$0C;
|
---|
179 | Result[0].raw_addr:=link;
|
---|
180 | Result[0].raw_size:=datasize;
|
---|
181 | Result[0].loc_sep:=dat_os_mac;
|
---|
182 | END;
|
---|
183 | FUNCTION SNDD(fileid:LongWord):TRawList;
|
---|
184 | VAR
|
---|
185 | link:LongWord;
|
---|
186 | datasize:LongWord;
|
---|
187 | BEGIN
|
---|
188 | LoadDatFilePart(fileid,$40,4,@datasize);
|
---|
189 | LoadDatFilePart(fileid,$44,4,@link);
|
---|
190 | SetLength(Result,1);
|
---|
191 | Result[0].src_offset:=$44;
|
---|
192 | Result[0].raw_addr:=link;
|
---|
193 | Result[0].raw_size:=datasize;
|
---|
194 | END;
|
---|
195 | FUNCTION SUBT(fileid:LongWord):TRawList;
|
---|
196 | VAR
|
---|
197 | baselink,link:LongWord;
|
---|
198 | links:LongWord;
|
---|
199 | i,j,k:LongWord;
|
---|
200 | data:Tdata;
|
---|
201 | BEGIN
|
---|
202 | LoadDatFilePart(fileid,$18,4,@baselink);
|
---|
203 | LoadDatFilePart(fileid,$1C,4,@links);
|
---|
204 | IF links>0 THEN BEGIN
|
---|
205 | LoadDatFilePart(fileid,$20+(links-1)*4,4,@link);
|
---|
206 | SetLength(data,link+1024);
|
---|
207 | LoadRawFile(fileid,$1C,baselink,link+1024,False,@data[0]);
|
---|
208 | k:=0;
|
---|
209 | FOR j:=0 TO 1024 DO BEGIN
|
---|
210 | IF (data[link+j]=$00) OR (j=1024) THEN BEGIN
|
---|
211 | IF j<1024 THEN BEGIN
|
---|
212 | IF k=0 THEN BEGIN
|
---|
213 | k:=1;
|
---|
214 | END ELSE BEGIN
|
---|
215 | SetLength(Result,1);
|
---|
216 | Result[0].src_offset:=$18;
|
---|
217 | Result[0].raw_addr:=baselink;
|
---|
218 | Result[0].raw_size:=link+j;
|
---|
219 | Break;
|
---|
220 | END;
|
---|
221 | END;
|
---|
222 | END;
|
---|
223 | END;
|
---|
224 | END;
|
---|
225 | END;
|
---|
226 | FUNCTION TRAM(fileid:LongWord):TRawList;
|
---|
227 | VAR
|
---|
228 | i:Byte;
|
---|
229 | link:LongWord;
|
---|
230 | frames:Word;
|
---|
231 | tempb:Byte;
|
---|
232 | tempw:Word;
|
---|
233 | templ:LongWord;
|
---|
234 | data:Tdata;
|
---|
235 | offset:Word;
|
---|
236 | BEGIN
|
---|
237 | SetLength(Result,13);
|
---|
238 | LoadDatFilePart(fileid,$16C,2,@frames);
|
---|
239 | {y-pos}
|
---|
240 | LoadDatFilePart(fileid,$0C,4,@link);
|
---|
241 | Result[0].src_offset:=$0C;
|
---|
242 | Result[0].raw_addr:=link;
|
---|
243 | Result[0].raw_size:=frames*4;
|
---|
244 | {x-z-pos}
|
---|
245 | LoadDatFilePart(fileid,$10,4,@link);
|
---|
246 | Result[1].src_offset:=$10;
|
---|
247 | Result[1].raw_addr:=link;
|
---|
248 | Result[1].raw_size:=frames*8;
|
---|
249 | {attacks}
|
---|
250 | LoadDatFilePart(fileid,$182,1,@tempb);
|
---|
251 | LoadDatFilePart(fileid,$14,4,@link);
|
---|
252 | Result[2].src_offset:=$14;
|
---|
253 | Result[2].raw_addr:=link;
|
---|
254 | Result[2].raw_size:=tempb*32;
|
---|
255 | {damage}
|
---|
256 | LoadDatFilePart(fileid,$183,1,@tempb);
|
---|
257 | LoadDatFilePart(fileid,$18,4,@link);
|
---|
258 | Result[3].src_offset:=$18;
|
---|
259 | Result[3].raw_addr:=link;
|
---|
260 | Result[3].raw_size:=tempb*8;
|
---|
261 | {motionblur}
|
---|
262 | LoadDatFilePart(fileid,$184,1,@tempb);
|
---|
263 | LoadDatFilePart(fileid,$1C,4,@link);
|
---|
264 | Result[4].src_offset:=$1C;
|
---|
265 | Result[4].raw_addr:=link;
|
---|
266 | Result[4].raw_size:=tempb*8;
|
---|
267 | {shortcut}
|
---|
268 | LoadDatFilePart(fileid,$185,1,@tempb);
|
---|
269 | LoadDatFilePart(fileid,$20,4,@link);
|
---|
270 | Result[5].src_offset:=$20;
|
---|
271 | Result[5].raw_addr:=link;
|
---|
272 | Result[5].raw_size:=tempb*8;
|
---|
273 | {throw}
|
---|
274 | LoadDatFilePart(fileid,$24,4,@link);
|
---|
275 | Result[6].src_offset:=$24;
|
---|
276 | Result[6].raw_addr:=link;
|
---|
277 | IF link>0 THEN
|
---|
278 | Result[6].raw_size:=24
|
---|
279 | ELSE
|
---|
280 | Result[6].raw_size:=0;
|
---|
281 | {footstep}
|
---|
282 | LoadDatFilePart(fileid,$186,1,@tempb);
|
---|
283 | LoadDatFilePart(fileid,$28,4,@link);
|
---|
284 | Result[7].src_offset:=$28;
|
---|
285 | Result[7].raw_addr:=link;
|
---|
286 | Result[7].raw_size:=tempb*4;
|
---|
287 | {particle}
|
---|
288 | LoadDatFilePart(fileid,$187,1,@tempb);
|
---|
289 | LoadDatFilePart(fileid,$2C,4,@link);
|
---|
290 | Result[8].src_offset:=$2C;
|
---|
291 | Result[8].raw_addr:=link;
|
---|
292 | Result[8].raw_size:=tempb*24;
|
---|
293 | {position}
|
---|
294 | LoadDatFilePart(fileid,$30,4,@link);
|
---|
295 | Result[9].src_offset:=$30;
|
---|
296 | Result[9].raw_addr:=link;
|
---|
297 | Result[9].raw_size:=frames*8;
|
---|
298 | {particle}
|
---|
299 | LoadDatFilePart(fileid,$154,2,@tempw);
|
---|
300 | LoadDatFilePart(fileid,$38,4,@link);
|
---|
301 | Result[11].src_offset:=$38;
|
---|
302 | Result[11].raw_addr:=link;
|
---|
303 | Result[11].raw_size:=tempw*34;
|
---|
304 | {extent}
|
---|
305 | LoadDatFilePart(fileid,$138,1,@templ);
|
---|
306 | LoadDatFilePart(fileid,$13C,4,@link);
|
---|
307 | Result[12].src_offset:=$13C;
|
---|
308 | Result[12].raw_addr:=link;
|
---|
309 | Result[12].raw_size:=templ*12;
|
---|
310 |
|
---|
311 | LoadDatFilePart(fileid,$34,4,@link);
|
---|
312 | tempw:=0;
|
---|
313 | IF link>0 THEN BEGIN
|
---|
314 | {BODY ANIMATIONS PART DECODE!!!}
|
---|
315 | SetLength(data,$FFFF);
|
---|
316 | LoadRawFile(fileid,$34,link,$FFFF,False,@data[0]);
|
---|
317 | offset:=data[24]+data[25]*255;
|
---|
318 | {}
|
---|
319 | END;
|
---|
320 | Result[10].src_offset:=$34;
|
---|
321 | Result[10].raw_addr:=link;
|
---|
322 | Result[10].raw_size:=tempw;
|
---|
323 | END;
|
---|
324 | FUNCTION TXMP(fileid:LongWord):TRawList;
|
---|
325 | VAR
|
---|
326 | link_pc:LongWord;
|
---|
327 | link_mac:LongWord;
|
---|
328 | x,y:Word;
|
---|
329 | storetype:Byte;
|
---|
330 | datasize:LongWord;
|
---|
331 | BEGIN
|
---|
332 | LoadDatFilePart(fileid,$8C,SizeOf(x),@x);
|
---|
333 | LoadDatFilePart(fileid,$8E,SizeOf(y),@y);
|
---|
334 | LoadDatFilePart(fileid,$90,SizeOf(storetype),@storetype);
|
---|
335 | LoadDatFilePart(fileid,$9C,4,@link_pc);
|
---|
336 | LoadDatFilePart(fileid,$A0,4,@link_mac);
|
---|
337 | CASE storetype OF
|
---|
338 | 0,1,2: datasize:=x*y*2;
|
---|
339 | 8: datasize:=x*y*4;
|
---|
340 | 9: datasize:=x*y DIV 2;
|
---|
341 | END;
|
---|
342 | SetLength(Result,1);
|
---|
343 | IF NOT dat_os_mac THEN BEGIN
|
---|
344 | Result[0].src_offset:=$9C;
|
---|
345 | Result[0].raw_addr:=link_pc
|
---|
346 | END ELSE BEGIN
|
---|
347 | Result[0].src_offset:=$A0;
|
---|
348 | Result[0].raw_addr:=link_mac;
|
---|
349 | END;
|
---|
350 | Result[0].raw_size:=datasize;
|
---|
351 | Result[0].loc_sep:=dat_os_mac;
|
---|
352 | END;
|
---|
353 |
|
---|
354 |
|
---|
355 |
|
---|
356 | PROCEDURE AddEntry(_ext:String; _name:String; _offset:LongWord; _datatype:Word; _description:String);
|
---|
357 | VAR
|
---|
358 | sid:Integer;
|
---|
359 | BEGIN
|
---|
360 | sid:=GetStructureInfoId(_ext);
|
---|
361 | IF sid>=0 THEN BEGIN
|
---|
362 | WITH structure_infos[sid] DO BEGIN
|
---|
363 | SetLength(entries,Length(entries)+1);
|
---|
364 | WITH entries[High(entries)] DO BEGIN
|
---|
365 | name:=_name;
|
---|
366 | offset:=_offset;
|
---|
367 | datatype:=_datatype;
|
---|
368 | description:=_description;
|
---|
369 | END;
|
---|
370 | END;
|
---|
371 | END;
|
---|
372 | END;
|
---|
373 |
|
---|
374 | PROCEDURE AddExtension(_ext:String; _typedesc:String);
|
---|
375 | BEGIN
|
---|
376 | IF GetStructureInfoId(_ext)<0 THEN BEGIN
|
---|
377 | SetLength(structure_infos,Length(structure_infos)+1);
|
---|
378 | WITH structure_infos[High(structure_infos)] DO BEGIN
|
---|
379 | extension:=_ext;
|
---|
380 | typedesc:=_typedesc;
|
---|
381 | END;
|
---|
382 | END;
|
---|
383 | END;
|
---|
384 |
|
---|
385 | PROCEDURE InsertRawListHandler(ext:String; needed:Boolean; handler:THandler);
|
---|
386 | BEGIN
|
---|
387 | SetLength(RawListHandlers,Length(RawListHandlers)+1);
|
---|
388 | RawListHandlers[High(RawListHandlers)].Ext:=ext;
|
---|
389 | RawListHandlers[High(RawListHandlers)].needed:=needed;
|
---|
390 | RawListHandlers[High(RawListHandlers)].handler:=handler;
|
---|
391 | END;
|
---|
392 |
|
---|
393 |
|
---|
394 | BEGIN
|
---|
395 | AddExtension('SUBT','Subtitles');
|
---|
396 | AddEntry('SUBT','ID',$00,4,'ID of this file');
|
---|
397 | AddEntry('SUBT','LevelID',$04,8,'ID of the level this file is in');
|
---|
398 | AddEntry('SUBT','Raw-Link',$18,11,'Address of the subtitle data in the .raw-file');
|
---|
399 | AddEntry('SUBT','Subtitle count',$1C,4,'Number of subtitles in this file');
|
---|
400 | AddExtension('TXMP','Texture');
|
---|
401 | AddEntry('TXMP','ID',$00,4,'ID of this file');
|
---|
402 | AddEntry('TXMP','LevelID',$04,8,'ID of the level this file is in');
|
---|
403 | AddEntry('TXMP','FileName',$08,10128,'');
|
---|
404 | AddEntry('TXMP','MIP Mapping',$88,10,'MIP Mapping Bitset');
|
---|
405 | AddEntry('TXMP','Depth',$89,10,'Depth-Bitset');
|
---|
406 | AddEntry('TXMP','Width',$8C,2,'x-resolution of image');
|
---|
407 | AddEntry('TXMP','Height',$8E,2,'y-resolution of image');
|
---|
408 | AddEntry('TXMP','Storetype',$90,10,'Storetype-Bitset');
|
---|
409 | AddEntry('TXMP','TXAN-Link',$94,8,'Link to the TXAN-file (if this TXMP is the first image of an animation)');
|
---|
410 | AddEntry('TXMP','TXMP-Link',$98,8,'Link to another TXMP-file');
|
---|
411 | AddEntry('TXMP','Raw-Link',$9C,11,'Address of the image data in the .raw-file (only for PC-dat-files)');
|
---|
412 | AddEntry('TXMP','Raw-Link',$A0,11,'Address of the image data in the .raw-file (only for MAC-dat-files)');
|
---|
413 |
|
---|
414 | {$I Include_DataStructureDefs.pas}
|
---|
415 |
|
---|
416 | // InsertRawListHandler('AGDB',True,AGDB);
|
---|
417 | InsertRawListHandler('BINA',True,BINA);
|
---|
418 | InsertRawListHandler('OSBD',True,OSBD);
|
---|
419 | InsertRawListHandler('SNDD',True,SNDD);
|
---|
420 | InsertRawListHandler('SUBT',True,SUBT);
|
---|
421 | InsertRawListHandler('TRAM',True,TRAM);
|
---|
422 | InsertRawListHandler('TXMP',True,TXMP);
|
---|
423 | END.
|
---|