source: oup/releases/0.25a/Unit9_data_structures.pas@ 246

Last change on this file since 246 was 25, checked in by alloc, 18 years ago
File size: 11.7 KB
Line 
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 IF link>0 THEN
276 Result[6].raw_size:=24
277 ELSE
278 Result[6].raw_size:=0;
279 {footstep}
280 LoadDatFilePart(fileid,$186,1,@tempb);
281 LoadDatFilePart(fileid,$28,4,@link);
282 Result[7].src_offset:=$28;
283 Result[7].raw_addr:=link;
284 Result[7].raw_size:=tempb*4;
285 {particle}
286 LoadDatFilePart(fileid,$187,1,@tempb);
287 LoadDatFilePart(fileid,$2C,4,@link);
288 Result[8].src_offset:=$2C;
289 Result[8].raw_addr:=link;
290 Result[8].raw_size:=tempb*24;
291 {position}
292 LoadDatFilePart(fileid,$30,4,@link);
293 Result[9].src_offset:=$30;
294 Result[9].raw_addr:=link;
295 Result[9].raw_size:=frames*8;
296 {particle}
297 LoadDatFilePart(fileid,$154,2,@tempw);
298 LoadDatFilePart(fileid,$38,4,@link);
299 Result[11].src_offset:=$38;
300 Result[11].raw_addr:=link;
301 Result[11].raw_size:=tempw*34;
302 {extent}
303 LoadDatFilePart(fileid,$138,1,@templ);
304 LoadDatFilePart(fileid,$13C,4,@link);
305 Result[12].src_offset:=$13C;
306 Result[12].raw_addr:=link;
307 Result[12].raw_size:=templ*12;
308
309 LoadDatFilePart(fileid,$34,4,@link);
310 tempw:=0;
311 IF link>0 THEN BEGIN
312 {BODY ANIMATIONS PART DECODE!!!}
313 SetLength(data,$FFFF);
314 LoadRawFile(fileid,$34,link,$FFFF,@data[0]);
315 offset:=data[24]+data[25]*255;
316 {}
317 END;
318 Result[10].src_offset:=$34;
319 Result[10].raw_addr:=link;
320 Result[10].raw_size:=tempw;
321 END;
322FUNCTION TXMP(fileid:LongWord):TRawList;
323 VAR
324 link:LongWord;
325 x,y:Word;
326 storetype:Byte;
327 datasize:LongWord;
328 BEGIN
329 LoadDatFilePart(fileid,$8C,SizeOf(x),@x);
330 LoadDatFilePart(fileid,$8E,SizeOf(y),@y);
331 LoadDatFilePart(fileid,$90,SizeOf(storetype),@storetype);
332 LoadDatFilePart(fileid,$9C,4,@link);
333 CASE storetype OF
334 0,1,2: datasize:=x*y*2;
335 8: datasize:=x*y*4;
336 9: datasize:=x*y DIV 2;
337 END;
338 SetLength(Result,1);
339 Result[0].src_offset:=$9C;
340 Result[0].raw_addr:=link;
341 Result[0].raw_size:=datasize;
342 END;
343
344
345
346PROCEDURE AddEntry(_ext:String; _name:String; _offset:LongWord; _datatype:Word; _description:String);
347 VAR
348 sid:Integer;
349 BEGIN
350 sid:=GetStructureInfoId(_ext);
351 IF sid>=0 THEN BEGIN
352 WITH structure_infos[sid] DO BEGIN
353 SetLength(entries,Length(entries)+1);
354 WITH entries[High(entries)] DO BEGIN
355 name:=_name;
356 offset:=_offset;
357 datatype:=_datatype;
358 description:=_description;
359 END;
360 END;
361 END;
362 END;
363
364PROCEDURE AddExtension(_ext:String; _typedesc:String);
365 BEGIN
366 IF GetStructureInfoId(_ext)<0 THEN BEGIN
367 SetLength(structure_infos,Length(structure_infos)+1);
368 WITH structure_infos[High(structure_infos)] DO BEGIN
369 extension:=_ext;
370 typedesc:=_typedesc;
371 END;
372 END;
373 END;
374
375PROCEDURE InsertRawListHandler(ext:String; needed:Boolean; handler:THandler);
376 BEGIN
377 SetLength(RawListHandlers,Length(RawListHandlers)+1);
378 RawListHandlers[High(RawListHandlers)].Ext:=ext;
379 RawListHandlers[High(RawListHandlers)].needed:=needed;
380 RawListHandlers[High(RawListHandlers)].handler:=handler;
381 END;
382
383
384BEGIN
385 AddExtension('SUBT','Subtitles');
386 AddEntry('SUBT','ID',$00,4,'ID of this file');
387 AddEntry('SUBT','LevelID',$04,8,'ID of the level this file is in');
388 AddEntry('SUBT','Raw-Link',$18,11,'Address of the subtitle data in the .raw-file');
389 AddEntry('SUBT','Subtitle count',$1C,4,'Number of subtitles in this file');
390 AddExtension('TXMP','Texture');
391 AddEntry('TXMP','ID',$00,4,'ID of this file');
392 AddEntry('TXMP','LevelID',$04,8,'ID of the level this file is in');
393 AddEntry('TXMP','FileName',$08,10128,'');
394 AddEntry('TXMP','Fading',$88,10,'Fading-Bitset');
395 AddEntry('TXMP','Depth',$89,10,'Depth-Bitset');
396 AddEntry('TXMP','Width',$8C,2,'x-resolution of image');
397 AddEntry('TXMP','Height',$8E,2,'y-resolution of image');
398 AddEntry('TXMP','Storetype',$90,10,'Storetype-Bitset');
399 AddEntry('TXMP','TXAN-Link',$94,8,'Link to the TXAN-file (if this TXMP is the first image of an animation)');
400 AddEntry('TXMP','TXMP-Link',$98,8,'Link to another TXMP-file');
401 AddEntry('TXMP','Raw-Link',$9C,11,'Address of the image data in the .raw-file');
402
403 InsertRawListHandler('BINA',True,BINA);
404 InsertRawListHandler('OSBD',True,OSBD);
405 InsertRawListHandler('SNDD',True,SNDD);
406 InsertRawListHandler('SUBT',True,SUBT);
407 InsertRawListHandler('TRAM',True,TRAM);
408 InsertRawListHandler('TXMP',True,TXMP);
409END.
Note: See TracBrowser for help on using the repository browser.