source: oup/releases/0.24a/Unit9_data_structures.pas@ 1043

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