source: oup/releases/0.24a/Unit10_leveldb.pas@ 821

Last change on this file since 821 was 24, checked in by alloc, 18 years ago
File size: 32.5 KB
Line 
1UNIT Unit10_leveldb;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, ComCtrls, StdCtrls, StrUtils;
6
7TYPE
8 TForm10 = Class(TForm)
9 group_progress: TGroupBox;
10 progress: TProgressBar;
11 lbl_progress: TLabel;
12 btn_abortok: TButton;
13 lbl_estimation: TLabel;
14 PROCEDURE btn_abortokClick(Sender: TObject);
15 PRIVATE
16 PROCEDURE HandleFile(ext:String; fileid:LongWord; dir_dat2db:Boolean);
17 PROCEDURE stop_convert;
18 PUBLIC
19 PROCEDURE CreateDatabase(FileName:String);
20 END;
21
22
23VAR
24 Form10: TForm10;
25
26IMPLEMENTATION
27{$R *.dfm}
28USES ABSMain, ABSDecUtil, Unit1_main, Unit2_functions, Unit3_data;
29TYPE
30 THandler=PROCEDURE(fileid:LongWord; dir_dat2db:Boolean);
31 TConvertHandlers=RECORD
32 Ext:String[4];
33 needed:Boolean;
34 Handler:THandler;
35 END;
36VAR
37 ConvertHandlers:Array OF TConvertHandlers;
38 loaded_filename:String;
39 converting:Boolean=False;
40 abort:Boolean=False;
41 filestream:TFileStream;
42 dat_stream:TMemoryStream;
43 mem:TMemoryStream;
44 DataBase:TABSDatabase;
45 Query:TABSQuery;
46 MimeCoder: TStringFormat_MIME64;
47
48PROCEDURE TForm10.HandleFile;
49 VAR
50 i:Byte;
51 BEGIN
52 FOR i:=1 TO Length(ConvertHandlers) DO
53 IF UpperCase(ConvertHandlers[i].Ext)=UpperCase(ext) THEN
54 IF ConvertHandlers[i].needed THEN BEGIN
55 ConvertHandlers[i].Handler(fileid, dir_dat2db);
56 Break;
57 END ELSE
58 Break;
59 END;
60
61PROCEDURE TForm10.CreateDatabase(FileName:String);
62 VAR
63 i,j:LongWord;
64 temps,temps2:String;
65 data:Tdata;
66 absolutebegintime,begintime:Double;
67 step:Byte;
68 CONST
69 steps:Byte=4;
70 PROCEDURE DoStep(stepname:String);
71 BEGIN
72 Inc(step);
73 IF stepname<>'FIN' THEN
74 group_progress.Caption:='Creating DB (Step '+IntToStr(step)+'/'+IntToStr(steps)+': '+stepname+')'
75 ELSE
76 group_progress.Caption:='Creating DB (FINISHED)';
77 END;
78 BEGIN
79 Form10.Visible:=True;
80 Form1.Visible:=False;
81 step:=0;
82 converting:=True;
83 abort:=False;
84 loaded_filename:=FileName;
85 btn_abortok.Caption:='&Abort...';
86 btn_abortok.Default:=False;
87
88 absolutebegintime:=Time;
89
90 DataBase:=TABSDatabase.Create(Self);
91 DataBase.DatabaseName:='OLDB';
92 DataBase.DatabaseFileName:=FileName;
93 DataBase.CreateDatabase;
94
95 DoStep('Creating tables');
96 progress.Position:=0;
97 lbl_progress.Caption:='';
98 lbl_estimation.Caption:='Estimated finishing time: unknown';
99 Application.ProcessMessages;
100
101 Query:=TABSQuery.Create(Self);
102 Query.DatabaseName:='OLDB';
103 Query.SQL.Text:='CREATE TABLE globals ( id AUTOINC PRIMARY KEY, name STRING(128), value STRING(128) );';
104 Query.ExecSQL;
105 Query.SQL.Text:='CREATE TABLE linkmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, target_id INTEGER );';
106 Query.ExecSQL;
107 Query.SQL.Text:='CREATE TABLE rawmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
108// Query.SQL.Text:='CREATE TABLE rawmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
109 Query.ExecSQL;
110 Query.SQL.Text:='CREATE TABLE datfiles ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
111// Query.SQL.Text:='CREATE TABLE datfiles ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
112 Query.ExecSQL;
113 Query.SQL.Text:='CREATE TABLE extlist ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
114 Query.ExecSQL;
115
116 Query.SQL.Text:='INSERT INTO globals (name,value) VALUES ("dbversion","'+dbversion+'");';
117 Query.ExecSQL;
118 SetLength(data,Length(dat_header.Ident));
119 FOR i:=0 TO High(dat_header.Ident) DO data[i]:=dat_header.Ident[i];
120 temps:=CreateHexString(data,True);
121 Query.SQL.Text:='INSERT INTO globals (name,value) VALUES ("ident","'+temps+'");';
122 Query.ExecSQL;
123 data:=LoadDatFile(0);
124 i:=data[7];
125 i:=i DIV 2;
126 Query.SQL.Text:='INSERT INTO globals (name,value) VALUES ("lvl","'+IntToStr(i)+'");';
127 Query.ExecSQL;
128
129 DoStep('Writing extensionslist');
130 progress.Max:=dat_header.Extensions;
131 Application.ProcessMessages;
132
133 FOR i:=0 TO dat_header.Extensions-1 DO BEGIN
134 SetLength(data,Length(dat_extensionsmap[i].Ident));
135 FOR j:=0 TO High(dat_extensionsmap[i].Ident) DO data[j]:=dat_extensionsmap[i].Ident[j];
136 temps:=CreateHexString(data,True);
137 temps2:=dat_extensionsmap[i].Extension[3]+dat_extensionsmap[i].Extension[2]+dat_extensionsmap[i].Extension[1]+dat_extensionsmap[i].Extension[0];
138 Query.SQL.Text:='INSERT INTO extlist (ext,ident) VALUES ("'+temps2+'","'+temps+'");';
139 Query.ExecSQL;
140 progress.Position:=i;
141 lbl_progress.Caption:='Extensions done: '+IntToStr(i)+'/'+IntToStr(dat_header.Extensions);
142 Application.ProcessMessages;
143 IF abort THEN BEGIN
144 stop_convert;
145 Exit;
146 END;
147 END;
148 lbl_progress.Caption:='';
149
150 DoStep('Loading .dat into memory');
151 Application.ProcessMessages;
152
153 progress.Position:=0;
154 lbl_progress.Caption:='Files done: '+IntToStr(0)+'/'+IntToStr(dat_header.Files);
155 lbl_estimation.Caption:='Estimated finishing time: unknown';
156
157 filestream:=TFileStream.Create(dat_filename, fmOpenRead);
158 dat_stream:=TMemoryStream.Create;
159 dat_stream.CopyFrom(filestream,0);
160 dat_stream.Seek(0,soFromBeginning);
161 filestream.Free;
162
163 progress.Max:=dat_header.Files;
164 begintime:=Time;
165 DoStep('Writing .dat-fileslist');
166 Application.ProcessMessages;
167
168 Database.StartTransaction;
169 FOR i:=0 TO dat_header.Files-1 DO BEGIN
170 IF (dat_files[i].FileType AND $02)=0 THEN BEGIN
171 dat_stream.Seek(dat_files[i].DatAddr,soFromBeginning);
172 mimecoder:=TStringFormat_MIME64.Create;
173 mem:=TMemoryStream.Create;
174 mem.CopyFrom(dat_stream,dat_files[i].Size);
175 Query.SQL.Text:='INSERT INTO datfiles (id,extension,name,contenttype,size,data) VALUES ('+IntToStr(i)+',"'+dat_files[i].Extension+'","'+dat_files[i].Name+'","'+IntToHex(dat_files[i].FileType,8)+'",'+IntToStr(dat_files[i].size)+',MimeToBin("'+MimeCoder.StrTo(mem.Memory, mem.Size)+'") );';
176 Query.ExecSQL;
177 mem.Free;
178 mimecoder.Free;
179 HandleFile(dat_files[i].Extension,i,True);
180 END ELSE BEGIN
181 Query.SQL.Text:='INSERT INTO datfiles (id,extension,name,contenttype,size) VALUES ('+IntToStr(i)+',"'+dat_files[i].Extension+'","'+dat_files[i].Name+'","'+IntToHex(dat_files[i].FileType,8)+'",0);';
182 Query.ExecSQL;
183 END;
184 IF ( (i MOD 100)=0 ) AND (i>0) THEN BEGIN
185 Database.Commit(False);
186 Database.StartTransaction;
187 END;
188 IF ( (i MOD 25)=0 ) AND (i>=100) THEN
189 lbl_estimation.Caption:='Estimated finishing time: '+TimeToStr((Time-begintime)/i*dat_header.Files+begintime);
190 progress.Position:=i;
191 lbl_progress.Caption:='Files done: '+IntToStr(i)+'/'+IntToStr(dat_header.Files);
192 Application.ProcessMessages;
193 IF abort THEN BEGIN
194 stop_convert;
195 Exit;
196 END;
197 END;
198 Database.Commit(False);
199 progress.Position:=dat_header.Files;
200 lbl_progress.Caption:='Files done: '+IntToStr(dat_header.Files)+'/'+IntToStr(dat_header.Files);
201 lbl_estimation.Caption:='FINISHED (duration: '+TimeToStr(Time-absolutebegintime)+')';
202
203 DoStep('FIN');
204 btn_abortok.Caption:='&OK';
205 btn_abortok.Default:=True;
206
207 loaded_filename:='';
208 converting:=False;
209 dat_stream.Free;
210
211 database.Close;
212 database.Free;
213 END;
214
215PROCEDURE TForm10.stop_convert;
216 BEGIN
217 btn_abortok.Caption:='&Close';
218 btn_abortok.Default:=True;
219 converting:=False;
220 lbl_estimation.Caption:='ABORTED';
221 group_progress.Caption:='Creating DB (ABORTED)';
222 DataBase.Close;
223 IF MessageBox(Self.Handle, PChar('Delete the unfinished DB-file?'), PChar('Delete file?'), MB_YESNO)=IDYES THEN BEGIN
224 DeleteFile(loaded_filename);
225 END;
226 END;
227
228PROCEDURE TForm10.btn_abortokClick(Sender: TObject);
229 BEGIN
230 IF converting THEN BEGIN
231 IF MessageBox(Self.Handle, PChar('Do you really want to cancel the convert-progress?'), PChar('Warning: Converting'), MB_YESNO)=IDYES THEN
232 abort:=True;
233 END ELSE BEGIN
234 Form10.Visible:=False;
235 Form1.Visible:=True;
236 END;
237 END;
238
239
240PROCEDURE LoadFilePart(fileid,offset,size:LongWord; target:Pointer);
241 BEGIN
242 dat_stream.Seek(dat_files[fileid].DatAddr+offset,soFromBeginning);
243 dat_stream.Read(target^,size);
244 END;
245
246PROCEDURE InsertDatLinkToDB(fileid:LongWord; offset:LongWord);
247 VAR
248 link:LongWord;
249 BEGIN
250 LoadFilePart(fileid,offset,4,@link);
251 IF link=0 THEN
252 link:=$FFFFFFFF
253 ELSE
254 link:=link DIV 256;
255 Query.SQL.Text:='INSERT INTO linkmap (src_id,src_link_offset,target_id) VALUES ('+IntToStr(fileid)+','+IntToStr(offset)+','+IntToStr(link)+');';
256 Query.ExecSQL;
257 END;
258
259PROCEDURE InsertRawFileToDB(fileid:LongWord; src_offset,raw_addr,size:LongWord);
260 VAR
261 localmem:TMemoryStream;
262// temps:String;
263 BEGIN
264 IF size>0 THEN BEGIN
265 localmem:=TMemoryStream.Create;
266 filestream:=TFileStream.Create(raw_filename,fmOpenRead);
267 filestream.Seek(raw_addr,soFromBeginning);
268 localmem.CopyFrom(filestream,size);
269 filestream.Free;
270 mimecoder:=TStringFormat_MIME64.Create;
271 Query.SQL.Text:='INSERT INTO rawmap (src_id,src_link_offset,size,data) VALUES ('+IntToStr(fileid)+','+IntToStr(src_offset)+','+IntToStr(size)+',MimeToBin("'+MimeCoder.StrTo(localmem.Memory, localmem.Size)+'") );';
272 Query.ExecSQL;
273 localmem.Free;
274 mimecoder.Free;
275 END ELSE BEGIN
276 Query.SQL.Text:='INSERT INTO rawmap (src_id,src_link_offset,size) VALUES ('+IntToStr(fileid)+','+IntToStr(src_offset)+',0);';
277 Query.ExecSQL;
278 END;
279{ IF (raw_addr MOD 32)>0 THEN BEGIN
280 temps:='FileID='+FormatNumber(fileid,5,'0')+' - dat-Offset=0x'+IntToHex(src_offset,8)+' - raw-address=0x'+IntToHex(raw_addr,8)+#13+#10;
281 filestream:=TFileStream.Create('D:\not32.txt',fmOpenReadWrite);
282 filestream.Seek(0,soFromEnd);
283 filestream.Write(temps[1],Length(temps));
284 filestream.Free;
285 END; }
286 END;
287
288
289
290PROCEDURE AGDB(fileid:LongWord; dir_dat2db:Boolean);
291 VAR
292 link:LongWord;
293 links:LongWord;
294 i:LongWord;
295 BEGIN
296 IF dir_dat2db THEN BEGIN
297 LoadFilePart(fileid,$1C,4,@links);
298 links:=links*2;
299 FOR i:=0 TO links-1 DO BEGIN
300 LoadFilePart(fileid,$20+i*4,4,@link);
301 InsertRawFileToDB(fileid,$20+i*4,link,1(*????????????????????????????????*));
302 END;
303 END ELSE BEGIN
304 END;
305 END;
306PROCEDURE AKEV(fileid:LongWord; dir_dat2db:Boolean);
307 VAR
308 i:LongWord;
309 BEGIN
310 IF dir_dat2db THEN BEGIN
311 FOR i:=0 TO 16 DO InsertDatLinkToDB(fileid,$8+i*4);
312 END ELSE BEGIN
313 END;
314 END;
315PROCEDURE AKOT(fileid:LongWord; dir_dat2db:Boolean);
316 VAR
317 i:LongWord;
318 BEGIN
319 IF dir_dat2db THEN BEGIN
320 FOR i:=0 TO 4 DO InsertDatLinkToDB(fileid,$8+i*4);
321 END ELSE BEGIN
322 END;
323 END;
324PROCEDURE BINA(fileid:LongWord; dir_dat2db:Boolean);
325 VAR
326 link:LongWord;
327 datasize:LongWord;
328 BEGIN
329 IF dir_dat2db THEN BEGIN
330 LoadFilePart(fileid,$0C,4,@link);
331 LoadFilePart(fileid,$08,4,@datasize);
332 InsertRawFileToDB(fileid,$0C,link,datasize);
333 END ELSE BEGIN
334 END;
335 END;
336PROCEDURE CBPI(fileid:LongWord; dir_dat2db:Boolean);
337 VAR
338 i:LongWord;
339 BEGIN
340 IF dir_dat2db THEN BEGIN
341 FOR i:=0 TO 56 DO InsertDatLinkToDB(fileid,$8+i*4);
342 END ELSE BEGIN
343 END;
344 END;
345PROCEDURE CBPM(fileid:LongWord; dir_dat2db:Boolean);
346 VAR
347 i:LongWord;
348 BEGIN
349 IF dir_dat2db THEN BEGIN
350 FOR i:=0 TO 18 DO InsertDatLinkToDB(fileid,$8+i*4);
351 END ELSE BEGIN
352 END;
353 END;
354PROCEDURE CONS(fileid:LongWord; dir_dat2db:Boolean);
355 VAR
356 i:LongWord;
357 BEGIN
358 IF dir_dat2db THEN BEGIN
359 FOR i:=0 TO 1 DO InsertDatLinkToDB(fileid,$24+i*4);
360 END ELSE BEGIN
361 END;
362 END;
363PROCEDURE CRSA(fileid:LongWord; dir_dat2db:Boolean);
364 VAR
365 packages:LongWord;
366 i:LongWord;
367 BEGIN
368 IF dir_dat2db THEN BEGIN
369 LoadFilePart(fileid,$14,4,@packages);
370 IF packages>0 THEN
371 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*1100+$A0);
372 END ELSE BEGIN
373 END;
374 END;
375PROCEDURE DOOR(fileid:LongWord; dir_dat2db:Boolean);
376 BEGIN
377 IF dir_dat2db THEN BEGIN
378 InsertDatLinkToDB(fileid,$08);
379 InsertDatLinkToDB(fileid,$10);
380 END ELSE BEGIN
381 END;
382 END;
383PROCEDURE DPGE(fileid:LongWord; dir_dat2db:Boolean);
384 BEGIN
385 IF dir_dat2db THEN BEGIN
386 InsertDatLinkToDB(fileid,$40);
387 END ELSE BEGIN
388 END;
389 END;
390PROCEDURE HPGE(fileid:LongWord; dir_dat2db:Boolean);
391 BEGIN
392 IF dir_dat2db THEN BEGIN
393 InsertDatLinkToDB(fileid,$0C);
394 END ELSE BEGIN
395 END;
396 END;
397PROCEDURE IGHH(fileid:LongWord; dir_dat2db:Boolean);
398 BEGIN
399 IF dir_dat2db THEN BEGIN
400 InsertDatLinkToDB(fileid,$24);
401 InsertDatLinkToDB(fileid,$28);
402 END ELSE BEGIN
403 END;
404 END;
405PROCEDURE IGPA(fileid:LongWord; dir_dat2db:Boolean);
406 VAR
407 links:LongWord;
408 i:LongWord;
409 BEGIN
410 IF dir_dat2db THEN BEGIN
411 LoadFilePart(fileid,$1C,4,@links);
412 IF links>0 THEN
413 FOR i:=0 TO links-1 DO InsertDatLinkToDB(fileid,$20+i*4);
414 END ELSE BEGIN
415 END;
416 END;
417PROCEDURE IGPG(fileid:LongWord; dir_dat2db:Boolean);
418 VAR
419 i:LongWord;
420 BEGIN
421 IF dir_dat2db THEN BEGIN
422 FOR i:=0 TO 1 DO InsertDatLinkToDB(fileid,$1C+i*4);
423 END ELSE BEGIN
424 END;
425 END;
426PROCEDURE IGSA(fileid:LongWord; dir_dat2db:Boolean);
427 VAR
428 links:LongWord;
429 i:LongWord;
430 BEGIN
431 IF dir_dat2db THEN BEGIN
432 LoadFilePart(fileid,$1C,4,@links);
433 IF links>0 THEN
434 FOR i:=0 TO links-1 DO InsertDatLinkToDB(fileid,$20+i*4);
435 END ELSE BEGIN
436 END;
437 END;
438PROCEDURE IMPT(fileid:LongWord; dir_dat2db:Boolean);
439 BEGIN
440 IF dir_dat2db THEN BEGIN
441 InsertDatLinkToDB(fileid,$10);
442 END ELSE BEGIN
443 END;
444 END;
445PROCEDURE IPGE(fileid:LongWord; dir_dat2db:Boolean);
446 BEGIN
447 IF dir_dat2db THEN BEGIN
448 InsertDatLinkToDB(fileid,$0C);
449 END ELSE BEGIN
450 END;
451 END;
452PROCEDURE KEYI(fileid:LongWord; dir_dat2db:Boolean);
453 VAR
454 i:LongWord;
455 BEGIN
456 IF dir_dat2db THEN BEGIN
457 FOR i:=0 TO 9 DO InsertDatLinkToDB(fileid,$08+i*4);
458 END ELSE BEGIN
459 END;
460 END;
461PROCEDURE M3GA(fileid:LongWord; dir_dat2db:Boolean);
462 VAR
463 links:LongWord;
464 i:LongWord;
465 BEGIN
466 IF dir_dat2db THEN BEGIN
467 LoadFilePart(fileid,$1C,4,@links);
468 IF links>0 THEN
469 FOR i:=0 TO links-1 DO InsertDatLinkToDB(fileid,$20+i*4);
470 END ELSE BEGIN
471 END;
472 END;
473PROCEDURE M3GM(fileid:LongWord; dir_dat2db:Boolean);
474 VAR
475 i:LongWord;
476 BEGIN
477 IF dir_dat2db THEN BEGIN
478 FOR i:=0 TO 6 DO InsertDatLinkToDB(fileid,$0C+i*4);
479 END ELSE BEGIN
480 END;
481 END;
482PROCEDURE MTRL(fileid:LongWord; dir_dat2db:Boolean);
483 BEGIN
484 IF dir_dat2db THEN BEGIN
485 InsertDatLinkToDB(fileid,$10);
486 END ELSE BEGIN
487 END;
488 END;
489PROCEDURE OBOA(fileid:LongWord; dir_dat2db:Boolean);
490 VAR
491 packages:Word;
492 i:LongWord;
493 BEGIN
494 IF dir_dat2db THEN BEGIN
495 LoadFilePart(fileid,$1E,2,@packages);
496 IF packages>0 THEN
497 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*240);
498 END ELSE BEGIN
499 END;
500 END;
501PROCEDURE OFGA(fileid:LongWord; dir_dat2db:Boolean);
502 VAR
503 packages:LongWord;
504 i:LongWord;
505 BEGIN
506 IF dir_dat2db THEN BEGIN
507 LoadFilePart(fileid,$1C,4,@packages);
508 IF packages>0 THEN
509 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*12+$04);
510 END ELSE BEGIN
511 END;
512 END;
513PROCEDURE ONCC(fileid:LongWord; dir_dat2db:Boolean);
514 VAR
515 i:LongWord;
516 BEGIN
517 IF dir_dat2db THEN BEGIN
518 END ELSE BEGIN
519 END;
520 END;
521PROCEDURE ONCV(fileid:LongWord; dir_dat2db:Boolean);
522 BEGIN
523 IF dir_dat2db THEN BEGIN
524 InsertDatLinkToDB(fileid,$08);
525 END ELSE BEGIN
526 END;
527 END;
528PROCEDURE ONLV(fileid:LongWord; dir_dat2db:Boolean);
529 VAR
530 i:LongWord;
531 BEGIN
532 IF dir_dat2db THEN BEGIN
533 FOR i:=0 TO 5 DO InsertDatLinkToDB(fileid,$48+i*4);
534 FOR i:=0 TO 5 DO InsertDatLinkToDB(fileid,$64+i*4);
535 InsertDatLinkToDB(fileid,$300);
536 END ELSE BEGIN
537 END;
538 END;
539PROCEDURE ONOA(fileid:LongWord; dir_dat2db:Boolean);
540 VAR
541 packages:LongWord;
542 i:LongWord;
543 BEGIN
544 IF dir_dat2db THEN BEGIN
545 LoadFilePart(fileid,$1C,4,@packages);
546 IF packages>0 THEN
547 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*8+$04);
548 END ELSE BEGIN
549 END;
550 END;
551PROCEDURE ONSK(fileid:LongWord; dir_dat2db:Boolean);
552 BEGIN
553 IF dir_dat2db THEN BEGIN
554 InsertDatLinkToDB(fileid,$08);
555 InsertDatLinkToDB(fileid,$0C);
556 InsertDatLinkToDB(fileid,$10);
557 InsertDatLinkToDB(fileid,$14);
558 InsertDatLinkToDB(fileid,$18);
559 InsertDatLinkToDB(fileid,$20);
560 InsertDatLinkToDB(fileid,$44);
561 END ELSE BEGIN
562 END;
563 END;
564PROCEDURE ONVL(fileid:LongWord; dir_dat2db:Boolean);
565 VAR
566 packages:LongWord;
567 i:LongWord;
568 BEGIN
569 IF dir_dat2db THEN BEGIN
570 LoadFilePart(fileid,$1C,4,@packages);
571 IF packages>0 THEN
572 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
573 END ELSE BEGIN
574 END;
575 END;
576PROCEDURE ONWC(fileid:LongWord; dir_dat2db:Boolean);
577 BEGIN
578 IF dir_dat2db THEN BEGIN
579 InsertDatLinkToDB(fileid,$28);
580 InsertDatLinkToDB(fileid,$34);
581 InsertDatLinkToDB(fileid,$54);
582 InsertDatLinkToDB(fileid,$58);
583 InsertDatLinkToDB(fileid,$5C);
584 InsertDatLinkToDB(fileid,$60);
585 InsertDatLinkToDB(fileid,$6FC);
586 InsertDatLinkToDB(fileid,$700);
587 END ELSE BEGIN
588 END;
589 END;
590PROCEDURE OPGE(fileid:LongWord; dir_dat2db:Boolean);
591 BEGIN
592 IF dir_dat2db THEN BEGIN
593 InsertDatLinkToDB(fileid,$1C);
594 END ELSE BEGIN
595 END;
596 END;
597PROCEDURE OSBD(fileid:LongWord; dir_dat2db:Boolean);
598 VAR
599 link:LongWord;
600 datasize:LongWord;
601 BEGIN
602 IF dir_dat2db THEN BEGIN
603 LoadFilePart(fileid,$08,4,@datasize);
604 LoadFilePart(fileid,$0C,4,@link);
605 InsertRawFileToDB(fileid,$0C,link,datasize);
606 END ELSE BEGIN
607 END;
608 END;
609PROCEDURE PSPC(fileid:LongWord; dir_dat2db:Boolean);
610 BEGIN
611 IF dir_dat2db THEN BEGIN
612 InsertDatLinkToDB(fileid,$50);
613 END ELSE BEGIN
614 END;
615 END;
616PROCEDURE PSPL(fileid:LongWord; dir_dat2db:Boolean);
617 VAR
618 packages:LongWord;
619 i:LongWord;
620 BEGIN
621 IF dir_dat2db THEN BEGIN
622 LoadFilePart(fileid,$1C,4,@packages);
623 IF packages>0 THEN
624 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$24+i*8);
625 END ELSE BEGIN
626 END;
627 END;
628PROCEDURE PSUI(fileid:LongWord; dir_dat2db:Boolean);
629 VAR
630 i:LongWord;
631 BEGIN
632 IF dir_dat2db THEN BEGIN
633 FOR i:=0 TO 43 DO InsertDatLinkToDB(fileid,$08+i*4);
634 END ELSE BEGIN
635 END;
636 END;
637PROCEDURE SNDD(fileid:LongWord; dir_dat2db:Boolean);
638 VAR
639 link:LongWord;
640 datasize:LongWord;
641 BEGIN
642 IF dir_dat2db THEN BEGIN
643 LoadFilePart(fileid,$40,4,@datasize);
644 LoadFilePart(fileid,$44,4,@link);
645 InsertRawFileToDB(fileid,$44,link,datasize);
646 END ELSE BEGIN
647 END;
648 END;
649PROCEDURE SUBT(fileid:LongWord; dir_dat2db:Boolean);
650 VAR
651 baselink,link:LongWord;
652 links:LongWord;
653 i,j,k:LongWord;
654 data:Tdata;
655 filestream:TFileStream;
656 BEGIN
657 IF dir_dat2db THEN BEGIN
658 LoadFilePart(fileid,$18,4,@baselink);
659 LoadFilePart(fileid,$1C,4,@links);
660 IF links>0 THEN BEGIN
661 LoadFilePart(fileid,$20+(links-1)*4,4,@link);
662 SetLength(data,1024);
663 filestream:=TFileStream.Create(AnsiReplaceStr(dat_filename,'.dat','.raw'),fmOpenRead);
664 filestream.Seek(baselink+link,soFromBeginning);
665 filestream.Read(data[0],1024);
666 filestream.Free;
667 k:=0;
668 FOR j:=0 TO 1024 DO BEGIN
669 IF (data[j]=$00) OR (j=1024) THEN BEGIN
670 IF j<1024 THEN BEGIN
671 IF k=0 THEN BEGIN
672 k:=1;
673 END ELSE BEGIN
674 InsertRawFileToDB(fileid,$1C,baselink,link+j);
675 Break;
676 END;
677 END ELSE
678 ShowMessage('Error: Didn''t find message-end-marker...');
679 END;
680 END;
681 END;
682 END ELSE BEGIN
683 END;
684 END;
685PROCEDURE STNA(fileid:LongWord; dir_dat2db:Boolean);
686 VAR
687 packages:Word;
688 i:LongWord;
689 BEGIN
690 IF dir_dat2db THEN BEGIN
691 LoadFilePart(fileid,$1E,2,@packages);
692 IF packages>0 THEN
693 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
694 END ELSE BEGIN
695 END;
696 END;
697PROCEDURE TRAC(fileid:LongWord; dir_dat2db:Boolean);
698 VAR
699 packages:Word;
700 i:LongWord;
701 BEGIN
702 IF dir_dat2db THEN BEGIN
703 InsertDatLinkToDB(fileid,$18);
704 LoadFilePart(fileid,$1E,2,@packages);
705 IF packages>0 THEN
706 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*12+8);
707 END ELSE BEGIN
708 END;
709 END;
710PROCEDURE TRAM(fileid:LongWord; dir_dat2db:Boolean);
711 VAR
712 i:Byte;
713 link:LongWord;
714 frames:Word;
715 tempb:Byte;
716 tempw:Word;
717 templ:LongWord;
718 data:Tdata;
719 offset:Word;
720 BEGIN
721 IF dir_dat2db THEN BEGIN
722 LoadFilePart(fileid,$16C,2,@frames);
723 {y-pos}
724 LoadFilePart(fileid,$0C,4,@link);
725 InsertRawFileToDB(fileid,$0C,link,frames*4);
726 {x-z-pos}
727 LoadFilePart(fileid,$10,4,@link);
728 InsertRawFileToDB(fileid,$10,link,frames*8);
729 {attacks}
730 LoadFilePart(fileid,$182,1,@tempb);
731 LoadFilePart(fileid,$14,4,@link);
732 InsertRawFileToDB(fileid,$14,link,tempb*32);
733 {damage}
734 LoadFilePart(fileid,$183,1,@tempb);
735 LoadFilePart(fileid,$18,4,@link);
736 InsertRawFileToDB(fileid,$18,link,tempb*8);
737 {motionblur}
738 LoadFilePart(fileid,$184,1,@tempb);
739 LoadFilePart(fileid,$1C,4,@link);
740 InsertRawFileToDB(fileid,$1C,link,tempb*8);
741 {shortcut}
742 LoadFilePart(fileid,$185,1,@tempb);
743 LoadFilePart(fileid,$20,4,@link);
744 InsertRawFileToDB(fileid,$20,link,tempb*8);
745 {throw}
746 LoadFilePart(fileid,$24,4,@link);
747 InsertRawFileToDB(fileid,$24,link,24);
748 {footstep}
749 LoadFilePart(fileid,$186,1,@tempb);
750 LoadFilePart(fileid,$28,4,@link);
751 InsertRawFileToDB(fileid,$28,link,tempb*4);
752 {particle}
753 LoadFilePart(fileid,$187,1,@tempb);
754 LoadFilePart(fileid,$2C,4,@link);
755 InsertRawFileToDB(fileid,$2C,link,tempb*24);
756 {position}
757 LoadFilePart(fileid,$30,4,@link);
758 InsertRawFileToDB(fileid,$30,link,frames*8);
759 {particle}
760 LoadFilePart(fileid,$154,2,@tempw);
761 LoadFilePart(fileid,$38,4,@link);
762 InsertRawFileToDB(fileid,$38,link,tempw*34);
763 {extent}
764 LoadFilePart(fileid,$138,1,@templ);
765 LoadFilePart(fileid,$13C,4,@link);
766 InsertRawFileToDB(fileid,$13C,link,templ*12);
767
768 LoadFilePart(fileid,$34,4,@link);
769 tempw:=0;
770 IF link>0 THEN BEGIN
771 {BODY ANIMATIONS PART DECODE!!!}
772 SetLength(data,$FFFF);
773 filestream:=TFileStream.Create(AnsiReplaceStr(dat_filename,'.dat','.raw'),fmOpenRead);
774 filestream.Seek(link,soFromBeginning);
775 filestream.Read(data[0],$FFFF);
776 filestream.Free;
777 offset:=data[24]+data[25]*255;
778 {}
779 END;
780 InsertRawFileToDB(fileid,$34,link,tempw);
781 END ELSE BEGIN
782 END;
783 END;
784PROCEDURE TRAS(fileid:LongWord; dir_dat2db:Boolean);
785 BEGIN
786 IF dir_dat2db THEN BEGIN
787 InsertDatLinkToDB(fileid,$08);
788 END ELSE BEGIN
789 END;
790 END;
791PROCEDURE TRBS(fileid:LongWord; dir_dat2db:Boolean);
792 VAR
793 i:LongWord;
794 BEGIN
795 IF dir_dat2db THEN BEGIN
796 FOR i:=0 TO 4 DO InsertDatLinkToDB(fileid,$08+i*4);
797 END ELSE BEGIN
798 END;
799 END;
800PROCEDURE TRCM(fileid:LongWord; dir_dat2db:Boolean);
801 VAR
802 i:LongWord;
803 BEGIN
804 IF dir_dat2db THEN BEGIN
805 FOR i:=0 TO 2 DO InsertDatLinkToDB(fileid,$5C+i*4);
806 END ELSE BEGIN
807 END;
808 END;
809PROCEDURE TRGA(fileid:LongWord; dir_dat2db:Boolean);
810 VAR
811 i:LongWord;
812 packages:Word;
813 BEGIN
814 IF dir_dat2db THEN BEGIN
815 LoadFilePart(fileid,$1E,2,@packages);
816 IF packages>0 THEN
817 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
818 END ELSE BEGIN
819 END;
820 END;
821PROCEDURE TRGE(fileid:LongWord; dir_dat2db:Boolean);
822 BEGIN
823 IF dir_dat2db THEN BEGIN
824 InsertDatLinkToDB(fileid,$20);
825 END ELSE BEGIN
826 END;
827 END;
828PROCEDURE TRIG(fileid:LongWord; dir_dat2db:Boolean);
829 BEGIN
830 IF dir_dat2db THEN BEGIN
831 InsertDatLinkToDB(fileid,$18);
832 InsertDatLinkToDB(fileid,$24);
833 InsertDatLinkToDB(fileid,$28);
834 END ELSE BEGIN
835 END;
836 END;
837PROCEDURE TRMA(fileid:LongWord; dir_dat2db:Boolean);
838 VAR
839 i:LongWord;
840 packages:Word;
841 BEGIN
842 IF dir_dat2db THEN BEGIN
843 LoadFilePart(fileid,$1E,2,@packages);
844 IF packages>0 THEN
845 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
846 END ELSE BEGIN
847 END;
848 END;
849PROCEDURE TRSC(fileid:LongWord; dir_dat2db:Boolean);
850 VAR
851 i:LongWord;
852 packages:Word;
853 BEGIN
854 IF dir_dat2db THEN BEGIN
855 LoadFilePart(fileid,$1E,2,@packages);
856 IF packages>0 THEN
857 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
858 END ELSE BEGIN
859 END;
860 END;
861PROCEDURE TSFF(fileid:LongWord; dir_dat2db:Boolean);
862 VAR
863 i:LongWord;
864 packages:LongWord;
865 BEGIN
866 IF dir_dat2db THEN BEGIN
867 LoadFilePart(fileid,$1C,4,@packages);
868 IF packages>0 THEN
869 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
870 END ELSE BEGIN
871 END;
872 END;
873PROCEDURE TSFT(fileid:LongWord; dir_dat2db:Boolean);
874 BEGIN
875 IF dir_dat2db THEN BEGIN
876 InsertDatLinkToDB(fileid,$1C);
877 END ELSE BEGIN
878 END;
879 END;
880PROCEDURE TURR(fileid:LongWord; dir_dat2db:Boolean);
881 BEGIN
882 IF dir_dat2db THEN BEGIN
883 InsertDatLinkToDB(fileid,$60);
884 InsertDatLinkToDB(fileid,$6C);
885 InsertDatLinkToDB(fileid,$74);
886 END ELSE BEGIN
887 END;
888 END;
889PROCEDURE TXAN(fileid:LongWord; dir_dat2db:Boolean);
890 VAR
891 i:LongWord;
892 packages:LongWord;
893 BEGIN
894 IF dir_dat2db THEN BEGIN
895 LoadFilePart(fileid,$1C,4,@packages);
896 IF packages>0 THEN
897 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
898 END ELSE BEGIN
899 END;
900 END;
901PROCEDURE TXMA(fileid:LongWord; dir_dat2db:Boolean);
902 VAR
903 i:LongWord;
904 packages:LongWord;
905 BEGIN
906 IF dir_dat2db THEN BEGIN
907 LoadFilePart(fileid,$1C,4,@packages);
908 IF packages>0 THEN
909 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
910 END ELSE BEGIN
911 END;
912 END;
913PROCEDURE TXMB(fileid:LongWord; dir_dat2db:Boolean);
914 VAR
915 i:LongWord;
916 packages:LongWord;
917 BEGIN
918 IF dir_dat2db THEN BEGIN
919 LoadFilePart(fileid,$1C,4,@packages);
920 IF packages>0 THEN
921 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
922 END ELSE BEGIN
923 END;
924 END;
925PROCEDURE TXMP(fileid:LongWord; dir_dat2db:Boolean);
926 VAR
927 link:LongWord;
928 x,y:Word;
929 storetype:Byte;
930 datasize:LongWord;
931 BEGIN
932 IF dir_dat2db THEN BEGIN
933 LoadFilePart(fileid,$8C,SizeOf(x),@x);
934 LoadFilePart(fileid,$8E,SizeOf(y),@y);
935 LoadFilePart(fileid,$90,SizeOf(storetype),@storetype);
936 LoadFilePart(fileid,$9C,4,@link);
937 CASE storetype OF
938 0,1,2: datasize:=x*y*2;
939 8: datasize:=x*y*4;
940 9: datasize:=x*y DIV 2;
941 END;
942 InsertRawFileToDB(fileid,$9C,link,datasize);
943 InsertDatLinkToDB(fileid,$94);
944 InsertDatLinkToDB(fileid,$98);
945 END ELSE BEGIN
946 END;
947 END;
948PROCEDURE TXTC(fileid:LongWord; dir_dat2db:Boolean);
949 BEGIN
950 IF dir_dat2db THEN BEGIN
951 InsertDatLinkToDB(fileid,$08);
952 END ELSE BEGIN
953 END;
954 END;
955PROCEDURE WMCL(fileid:LongWord; dir_dat2db:Boolean);
956 BEGIN
957 IF dir_dat2db THEN BEGIN
958 InsertDatLinkToDB(fileid,$24);
959 END ELSE BEGIN
960 END;
961 END;
962PROCEDURE WMMB(fileid:LongWord; dir_dat2db:Boolean);
963 VAR
964 i:LongWord;
965 packages:LongWord;
966 BEGIN
967 IF dir_dat2db THEN BEGIN
968 LoadFilePart(fileid,$1C,4,@packages);
969 IF packages>0 THEN
970 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
971 END ELSE BEGIN
972 END;
973 END;
974PROCEDURE WPGE(fileid:LongWord; dir_dat2db:Boolean);
975 BEGIN
976 IF dir_dat2db THEN BEGIN
977 InsertDatLinkToDB(fileid,$08);
978 InsertDatLinkToDB(fileid,$0C);
979 END ELSE BEGIN
980 END;
981 END;
982
983PROCEDURE InsertHandler(ext:String; needed:Boolean; handler:THandler);
984 BEGIN
985 SetLength(ConvertHandlers,Length(ConvertHandlers)+1);
986 ConvertHandlers[High(ConvertHandlers)].Ext:=ext;
987 ConvertHandlers[High(ConvertHandlers)].needed:=needed;
988 ConvertHandlers[High(ConvertHandlers)].handler:=handler;
989 END;
990
991BEGIN
992 InsertHandler('ABNA',False,NIL);
993// InsertHandler('AGDB',True,AGDB);
994 InsertHandler('AGDB',False,NIL);
995 InsertHandler('AGQC',False,NIL);
996 InsertHandler('AGQG',False,NIL);
997 InsertHandler('AGQR',False,NIL);
998 InsertHandler('AISA',False,NIL);
999 InsertHandler('AITR',False,NIL);
1000 InsertHandler('AKAA',False,NIL);
1001 InsertHandler('AKBA',False,NIL);
1002 InsertHandler('AKBP',False,NIL);
1003 InsertHandler('AKDA',False,NIL);
1004 InsertHandler('AKEV',True,AKEV);
1005 InsertHandler('AKOT',True,AKOT);
1006 InsertHandler('AKVA',False,NIL);
1007 InsertHandler('BINA',True,BINA);
1008 InsertHandler('CBPI',True,CBPI);
1009 InsertHandler('CBPM',True,CBPM);
1010 InsertHandler('CONS',True,CONS);
1011 InsertHandler('CRSA',True,CRSA);
1012 InsertHandler('DOOR',True,DOOR);
1013 InsertHandler('DPGE',True,DPGE);
1014 InsertHandler('ENVP',False,NIL);
1015 InsertHandler('FILM',False,NIL);
1016 InsertHandler('HPGE',True,HPGE);
1017 InsertHandler('IDXA',False,NIL);
1018 InsertHandler('IGHH',True,IGHH);
1019 InsertHandler('IGPA',True,IGPA);
1020 InsertHandler('IGPG',True,IGPG);
1021 InsertHandler('IGSA',True,IGSA);
1022 InsertHandler('IMPT',True,IMPT);
1023 InsertHandler('IPGE',True,IPGE);
1024 InsertHandler('KEYI',True,KEYI);
1025 InsertHandler('M3GA',True,M3GA);
1026 InsertHandler('M3GM',True,M3GM);
1027 InsertHandler('MTRL',True,MTRL);
1028 InsertHandler('OBAN',False,NIL);
1029 InsertHandler('OBDC',False,NIL);
1030 InsertHandler('OBOA',True,OBOA);
1031 InsertHandler('OFGA',True,OFGA);
1032 InsertHandler('ONCC',True,ONCC);
1033 InsertHandler('ONCP',False,NIL);
1034 InsertHandler('ONCV',True,ONCV);
1035 InsertHandler('ONFA',False,NIL);
1036 InsertHandler('ONGS',False,NIL);
1037 InsertHandler('ONIA',False,NIL);
1038 InsertHandler('ONLD',False,NIL);
1039 InsertHandler('ONLV',True,ONLV);
1040 InsertHandler('ONMA',False,NIL);
1041 InsertHandler('ONOA',True,ONOA);
1042 InsertHandler('ONSA',False,NIL);
1043 InsertHandler('ONSK',True,ONSK);
1044 InsertHandler('ONTA',False,NIL);
1045 InsertHandler('ONVL',True,ONVL);
1046 InsertHandler('ONWC',True,ONWC);
1047 InsertHandler('OPGE',True,OPGE);
1048 InsertHandler('OSBD',True,OSBD);
1049 InsertHandler('OTIT',False,NIL);
1050 InsertHandler('OTLF',False,NIL);
1051 InsertHandler('PLEA',False,NIL);
1052 InsertHandler('PNTA',False,NIL);
1053 InsertHandler('PSPC',True,PSPC);
1054 InsertHandler('PSPL',True,PSPL);
1055 InsertHandler('PSUI',True,PSUI);
1056 InsertHandler('QTNA',False,NIL);
1057 InsertHandler('SNDD',True,SNDD);
1058 InsertHandler('STNA',True,STNA);
1059 InsertHandler('SUBT',True,SUBT);
1060 InsertHandler('TRAC',True,TRAC);
1061 InsertHandler('TRAM',True,TRAM);
1062 InsertHandler('TRAS',True,TRAS);
1063 InsertHandler('TRBS',True,TRBS);
1064 InsertHandler('TRCM',True,TRCM);
1065 InsertHandler('TRGA',True,TRGA);
1066 InsertHandler('TRGE',True,TRGE);
1067 InsertHandler('TRIA',False,NIL);
1068 InsertHandler('TRIG',True,TRIG);
1069 InsertHandler('TRMA',True,TRMA);
1070 InsertHandler('TRSC',True,TRSC);
1071 InsertHandler('TRTA',False,NIL);
1072 InsertHandler('TSFF',True,TSFF);
1073 InsertHandler('TSFL',False,NIL);
1074 InsertHandler('TSFT',True,TSFT);
1075 InsertHandler('TSGA',False,NIL);
1076 InsertHandler('TSTR',False,NIL);
1077 InsertHandler('TURR',True,TURR);
1078 InsertHandler('TXAN',True,TXAN);
1079 InsertHandler('TXCA',False,NIL);
1080 InsertHandler('TXMA',True,TXMA);
1081 InsertHandler('TXMB',True,TXMB);
1082 InsertHandler('TXMP',True,TXMP);
1083 InsertHandler('TXTC',True,TXTC);
1084 InsertHandler('VCRA',False,NIL);
1085 InsertHandler('WMCL',True,WMCL);
1086 InsertHandler('WMDD',False,NIL);
1087 InsertHandler('WMM_',False,NIL);
1088 InsertHandler('WMMB',True,WMMB);
1089 InsertHandler('WPGE',True,WPGE);
1090END.
Note: See TracBrowser for help on using the repository browser.