source: oup/releases/0.23a/Unit10_leveldb.pas@ 1050

Last change on this file since 1050 was 23, checked in by alloc, 18 years ago
File size: 32.6 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 FOR i:=0 TO links-1 DO BEGIN
662 LoadFilePart(fileid,$20+i*4,4,@link);
663 SetLength(data,1024);
664 filestream:=TFileStream.Create(AnsiReplaceStr(dat_filename,'.dat','.raw'),fmOpenRead);
665 filestream.Seek(baselink+link,soFromBeginning);
666 filestream.Read(data[0],1024);
667 filestream.Free;
668 k:=0;
669 FOR j:=0 TO 1024 DO BEGIN
670 IF (data[j]=$00) OR (j=1024) THEN BEGIN
671 IF j<1024 THEN BEGIN
672 IF k=0 THEN BEGIN
673 k:=1;
674 END ELSE BEGIN
675 InsertRawFileToDB(fileid,$20+i*4,baselink+link,j);
676 Break;
677 END;
678 END ELSE
679 ShowMessage('Error: Didn''t find message-end-marker...');
680 END;
681 END;
682 END;
683 END;
684 END ELSE BEGIN
685 END;
686 END;
687PROCEDURE STNA(fileid:LongWord; dir_dat2db:Boolean);
688 VAR
689 packages:Word;
690 i:LongWord;
691 BEGIN
692 IF dir_dat2db THEN BEGIN
693 LoadFilePart(fileid,$1E,2,@packages);
694 IF packages>0 THEN
695 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
696 END ELSE BEGIN
697 END;
698 END;
699PROCEDURE TRAC(fileid:LongWord; dir_dat2db:Boolean);
700 VAR
701 packages:Word;
702 i:LongWord;
703 BEGIN
704 IF dir_dat2db THEN BEGIN
705 InsertDatLinkToDB(fileid,$18);
706 LoadFilePart(fileid,$1E,2,@packages);
707 IF packages>0 THEN
708 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*12+8);
709 END ELSE BEGIN
710 END;
711 END;
712PROCEDURE TRAM(fileid:LongWord; dir_dat2db:Boolean);
713 VAR
714 i:Byte;
715 link:LongWord;
716 frames:Word;
717 tempb:Byte;
718 tempw:Word;
719 templ:LongWord;
720 data:Tdata;
721 offset:Word;
722 BEGIN
723 IF dir_dat2db THEN BEGIN
724 LoadFilePart(fileid,$16C,2,@frames);
725 {y-pos}
726 LoadFilePart(fileid,$0C,4,@link);
727 InsertRawFileToDB(fileid,$0C,link,frames*4);
728 {x-z-pos}
729 LoadFilePart(fileid,$10,4,@link);
730 InsertRawFileToDB(fileid,$10,link,frames*8);
731 {attacks}
732 LoadFilePart(fileid,$182,1,@tempb);
733 LoadFilePart(fileid,$14,4,@link);
734 InsertRawFileToDB(fileid,$14,link,tempb*32);
735 {damage}
736 LoadFilePart(fileid,$183,1,@tempb);
737 LoadFilePart(fileid,$18,4,@link);
738 InsertRawFileToDB(fileid,$18,link,tempb*8);
739 {motionblur}
740 LoadFilePart(fileid,$184,1,@tempb);
741 LoadFilePart(fileid,$1C,4,@link);
742 InsertRawFileToDB(fileid,$1C,link,tempb*8);
743 {shortcut}
744 LoadFilePart(fileid,$185,1,@tempb);
745 LoadFilePart(fileid,$20,4,@link);
746 InsertRawFileToDB(fileid,$20,link,tempb*8);
747 {throw}
748 LoadFilePart(fileid,$24,4,@link);
749 InsertRawFileToDB(fileid,$24,link,24);
750 {footstep}
751 LoadFilePart(fileid,$186,1,@tempb);
752 LoadFilePart(fileid,$28,4,@link);
753 InsertRawFileToDB(fileid,$28,link,tempb*4);
754 {particle}
755 LoadFilePart(fileid,$187,1,@tempb);
756 LoadFilePart(fileid,$2C,4,@link);
757 InsertRawFileToDB(fileid,$2C,link,tempb*24);
758 {position}
759 LoadFilePart(fileid,$30,4,@link);
760 InsertRawFileToDB(fileid,$30,link,frames*8);
761 {particle}
762 LoadFilePart(fileid,$154,2,@tempw);
763 LoadFilePart(fileid,$38,4,@link);
764 InsertRawFileToDB(fileid,$38,link,tempw*34);
765 {extent}
766 LoadFilePart(fileid,$138,1,@templ);
767 LoadFilePart(fileid,$13C,4,@link);
768 InsertRawFileToDB(fileid,$13C,link,templ*12);
769
770 LoadFilePart(fileid,$34,4,@link);
771 tempw:=0;
772 IF link>0 THEN BEGIN
773 {BODY ANIMATIONS PART DECODE!!!}
774 SetLength(data,$FFFF);
775 filestream:=TFileStream.Create(AnsiReplaceStr(dat_filename,'.dat','.raw'),fmOpenRead);
776 filestream.Seek(link,soFromBeginning);
777 filestream.Read(data[0],$FFFF);
778 filestream.Free;
779 offset:=data[24]+data[25]*255;
780 {}
781 END;
782 InsertRawFileToDB(fileid,$34,link,tempw);
783 END ELSE BEGIN
784 END;
785 END;
786PROCEDURE TRAS(fileid:LongWord; dir_dat2db:Boolean);
787 BEGIN
788 IF dir_dat2db THEN BEGIN
789 InsertDatLinkToDB(fileid,$08);
790 END ELSE BEGIN
791 END;
792 END;
793PROCEDURE TRBS(fileid:LongWord; dir_dat2db:Boolean);
794 VAR
795 i:LongWord;
796 BEGIN
797 IF dir_dat2db THEN BEGIN
798 FOR i:=0 TO 4 DO InsertDatLinkToDB(fileid,$08+i*4);
799 END ELSE BEGIN
800 END;
801 END;
802PROCEDURE TRCM(fileid:LongWord; dir_dat2db:Boolean);
803 VAR
804 i:LongWord;
805 BEGIN
806 IF dir_dat2db THEN BEGIN
807 FOR i:=0 TO 2 DO InsertDatLinkToDB(fileid,$5C+i*4);
808 END ELSE BEGIN
809 END;
810 END;
811PROCEDURE TRGA(fileid:LongWord; dir_dat2db:Boolean);
812 VAR
813 i:LongWord;
814 packages:Word;
815 BEGIN
816 IF dir_dat2db THEN BEGIN
817 LoadFilePart(fileid,$1E,2,@packages);
818 IF packages>0 THEN
819 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
820 END ELSE BEGIN
821 END;
822 END;
823PROCEDURE TRGE(fileid:LongWord; dir_dat2db:Boolean);
824 BEGIN
825 IF dir_dat2db THEN BEGIN
826 InsertDatLinkToDB(fileid,$20);
827 END ELSE BEGIN
828 END;
829 END;
830PROCEDURE TRIG(fileid:LongWord; dir_dat2db:Boolean);
831 BEGIN
832 IF dir_dat2db THEN BEGIN
833 InsertDatLinkToDB(fileid,$18);
834 InsertDatLinkToDB(fileid,$24);
835 InsertDatLinkToDB(fileid,$28);
836 END ELSE BEGIN
837 END;
838 END;
839PROCEDURE TRMA(fileid:LongWord; dir_dat2db:Boolean);
840 VAR
841 i:LongWord;
842 packages:Word;
843 BEGIN
844 IF dir_dat2db THEN BEGIN
845 LoadFilePart(fileid,$1E,2,@packages);
846 IF packages>0 THEN
847 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
848 END ELSE BEGIN
849 END;
850 END;
851PROCEDURE TRSC(fileid:LongWord; dir_dat2db:Boolean);
852 VAR
853 i:LongWord;
854 packages:Word;
855 BEGIN
856 IF dir_dat2db THEN BEGIN
857 LoadFilePart(fileid,$1E,2,@packages);
858 IF packages>0 THEN
859 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
860 END ELSE BEGIN
861 END;
862 END;
863PROCEDURE TSFF(fileid:LongWord; dir_dat2db:Boolean);
864 VAR
865 i:LongWord;
866 packages:LongWord;
867 BEGIN
868 IF dir_dat2db THEN BEGIN
869 LoadFilePart(fileid,$1C,4,@packages);
870 IF packages>0 THEN
871 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
872 END ELSE BEGIN
873 END;
874 END;
875PROCEDURE TSFT(fileid:LongWord; dir_dat2db:Boolean);
876 BEGIN
877 IF dir_dat2db THEN BEGIN
878 InsertDatLinkToDB(fileid,$1C);
879 END ELSE BEGIN
880 END;
881 END;
882PROCEDURE TURR(fileid:LongWord; dir_dat2db:Boolean);
883 BEGIN
884 IF dir_dat2db THEN BEGIN
885 InsertDatLinkToDB(fileid,$60);
886 InsertDatLinkToDB(fileid,$6C);
887 InsertDatLinkToDB(fileid,$74);
888 END ELSE BEGIN
889 END;
890 END;
891PROCEDURE TXAN(fileid:LongWord; dir_dat2db:Boolean);
892 VAR
893 i:LongWord;
894 packages:LongWord;
895 BEGIN
896 IF dir_dat2db THEN BEGIN
897 LoadFilePart(fileid,$1C,4,@packages);
898 IF packages>0 THEN
899 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
900 END ELSE BEGIN
901 END;
902 END;
903PROCEDURE TXMA(fileid:LongWord; dir_dat2db:Boolean);
904 VAR
905 i:LongWord;
906 packages:LongWord;
907 BEGIN
908 IF dir_dat2db THEN BEGIN
909 LoadFilePart(fileid,$1C,4,@packages);
910 IF packages>0 THEN
911 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
912 END ELSE BEGIN
913 END;
914 END;
915PROCEDURE TXMB(fileid:LongWord; dir_dat2db:Boolean);
916 VAR
917 i:LongWord;
918 packages:LongWord;
919 BEGIN
920 IF dir_dat2db THEN BEGIN
921 LoadFilePart(fileid,$1C,4,@packages);
922 IF packages>0 THEN
923 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
924 END ELSE BEGIN
925 END;
926 END;
927PROCEDURE TXMP(fileid:LongWord; dir_dat2db:Boolean);
928 VAR
929 link:LongWord;
930 x,y:Word;
931 storetype:Byte;
932 datasize:LongWord;
933 BEGIN
934 IF dir_dat2db THEN BEGIN
935 LoadFilePart(fileid,$8C,SizeOf(x),@x);
936 LoadFilePart(fileid,$8E,SizeOf(y),@y);
937 LoadFilePart(fileid,$90,SizeOf(storetype),@storetype);
938 LoadFilePart(fileid,$9C,4,@link);
939 CASE storetype OF
940 0,1,2: datasize:=x*y*2;
941 8: datasize:=x*y*4;
942 9: datasize:=x*y DIV 2;
943 END;
944 InsertRawFileToDB(fileid,$9C,link,datasize);
945 InsertDatLinkToDB(fileid,$94);
946 InsertDatLinkToDB(fileid,$98);
947 END ELSE BEGIN
948 END;
949 END;
950PROCEDURE TXTC(fileid:LongWord; dir_dat2db:Boolean);
951 BEGIN
952 IF dir_dat2db THEN BEGIN
953 InsertDatLinkToDB(fileid,$08);
954 END ELSE BEGIN
955 END;
956 END;
957PROCEDURE WMCL(fileid:LongWord; dir_dat2db:Boolean);
958 BEGIN
959 IF dir_dat2db THEN BEGIN
960 InsertDatLinkToDB(fileid,$24);
961 END ELSE BEGIN
962 END;
963 END;
964PROCEDURE WMMB(fileid:LongWord; dir_dat2db:Boolean);
965 VAR
966 i:LongWord;
967 packages:LongWord;
968 BEGIN
969 IF dir_dat2db THEN BEGIN
970 LoadFilePart(fileid,$1C,4,@packages);
971 IF packages>0 THEN
972 FOR i:=0 TO packages-1 DO InsertDatLinkToDB(fileid,$20+i*4);
973 END ELSE BEGIN
974 END;
975 END;
976PROCEDURE WPGE(fileid:LongWord; dir_dat2db:Boolean);
977 BEGIN
978 IF dir_dat2db THEN BEGIN
979 InsertDatLinkToDB(fileid,$08);
980 InsertDatLinkToDB(fileid,$0C);
981 END ELSE BEGIN
982 END;
983 END;
984
985PROCEDURE InsertHandler(ext:String; needed:Boolean; handler:THandler);
986 BEGIN
987 SetLength(ConvertHandlers,Length(ConvertHandlers)+1);
988 ConvertHandlers[High(ConvertHandlers)].Ext:=ext;
989 ConvertHandlers[High(ConvertHandlers)].needed:=needed;
990 ConvertHandlers[High(ConvertHandlers)].handler:=handler;
991 END;
992
993BEGIN
994 InsertHandler('ABNA',False,NIL);
995// InsertHandler('AGDB',True,AGDB);
996 InsertHandler('AGDB',False,NIL);
997 InsertHandler('AGQC',False,NIL);
998 InsertHandler('AGQG',False,NIL);
999 InsertHandler('AGQR',False,NIL);
1000 InsertHandler('AISA',False,NIL);
1001 InsertHandler('AITR',False,NIL);
1002 InsertHandler('AKAA',False,NIL);
1003 InsertHandler('AKBA',False,NIL);
1004 InsertHandler('AKBP',False,NIL);
1005 InsertHandler('AKDA',False,NIL);
1006 InsertHandler('AKEV',True,AKEV);
1007 InsertHandler('AKOT',True,AKOT);
1008 InsertHandler('AKVA',False,NIL);
1009 InsertHandler('BINA',True,BINA);
1010 InsertHandler('CBPI',True,CBPI);
1011 InsertHandler('CBPM',True,CBPM);
1012 InsertHandler('CONS',True,CONS);
1013 InsertHandler('CRSA',True,CRSA);
1014 InsertHandler('DOOR',True,DOOR);
1015 InsertHandler('DPGE',True,DPGE);
1016 InsertHandler('ENVP',False,NIL);
1017 InsertHandler('FILM',False,NIL);
1018 InsertHandler('HPGE',True,HPGE);
1019 InsertHandler('IDXA',False,NIL);
1020 InsertHandler('IGHH',True,IGHH);
1021 InsertHandler('IGPA',True,IGPA);
1022 InsertHandler('IGPG',True,IGPG);
1023 InsertHandler('IGSA',True,IGSA);
1024 InsertHandler('IMPT',True,IMPT);
1025 InsertHandler('IPGE',True,IPGE);
1026 InsertHandler('KEYI',True,KEYI);
1027 InsertHandler('M3GA',True,M3GA);
1028 InsertHandler('M3GM',True,M3GM);
1029 InsertHandler('MTRL',True,MTRL);
1030 InsertHandler('OBAN',False,NIL);
1031 InsertHandler('OBDC',False,NIL);
1032 InsertHandler('OBOA',True,OBOA);
1033 InsertHandler('OFGA',True,OFGA);
1034 InsertHandler('ONCC',True,ONCC);
1035 InsertHandler('ONCP',False,NIL);
1036 InsertHandler('ONCV',True,ONCV);
1037 InsertHandler('ONFA',False,NIL);
1038 InsertHandler('ONGS',False,NIL);
1039 InsertHandler('ONIA',False,NIL);
1040 InsertHandler('ONLD',False,NIL);
1041 InsertHandler('ONLV',True,ONLV);
1042 InsertHandler('ONMA',False,NIL);
1043 InsertHandler('ONOA',True,ONOA);
1044 InsertHandler('ONSA',False,NIL);
1045 InsertHandler('ONSK',True,ONSK);
1046 InsertHandler('ONTA',False,NIL);
1047 InsertHandler('ONVL',True,ONVL);
1048 InsertHandler('ONWC',True,ONWC);
1049 InsertHandler('OPGE',True,OPGE);
1050 InsertHandler('OSBD',True,OSBD);
1051 InsertHandler('OTIT',False,NIL);
1052 InsertHandler('OTLF',False,NIL);
1053 InsertHandler('PLEA',False,NIL);
1054 InsertHandler('PNTA',False,NIL);
1055 InsertHandler('PSPC',True,PSPC);
1056 InsertHandler('PSPL',True,PSPL);
1057 InsertHandler('PSUI',True,PSUI);
1058 InsertHandler('QTNA',False,NIL);
1059 InsertHandler('SNDD',True,SNDD);
1060 InsertHandler('STNA',True,STNA);
1061 InsertHandler('SUBT',True,SUBT);
1062 InsertHandler('TRAC',True,TRAC);
1063 InsertHandler('TRAM',True,TRAM);
1064 InsertHandler('TRAS',True,TRAS);
1065 InsertHandler('TRBS',True,TRBS);
1066 InsertHandler('TRCM',True,TRCM);
1067 InsertHandler('TRGA',True,TRGA);
1068 InsertHandler('TRGE',True,TRGE);
1069 InsertHandler('TRIA',False,NIL);
1070 InsertHandler('TRIG',True,TRIG);
1071 InsertHandler('TRMA',True,TRMA);
1072 InsertHandler('TRSC',True,TRSC);
1073 InsertHandler('TRTA',False,NIL);
1074 InsertHandler('TSFF',True,TSFF);
1075 InsertHandler('TSFL',False,NIL);
1076 InsertHandler('TSFT',True,TSFT);
1077 InsertHandler('TSGA',False,NIL);
1078 InsertHandler('TSTR',False,NIL);
1079 InsertHandler('TURR',True,TURR);
1080 InsertHandler('TXAN',True,TXAN);
1081 InsertHandler('TXCA',False,NIL);
1082 InsertHandler('TXMA',True,TXMA);
1083 InsertHandler('TXMB',True,TXMB);
1084 InsertHandler('TXMP',True,TXMP);
1085 InsertHandler('TXTC',True,TXTC);
1086 InsertHandler('VCRA',False,NIL);
1087 InsertHandler('WMCL',True,WMCL);
1088 InsertHandler('WMDD',False,NIL);
1089 InsertHandler('WMM_',False,NIL);
1090 InsertHandler('WMMB',True,WMMB);
1091 InsertHandler('WPGE',True,WPGE);
1092END.
Note: See TracBrowser for help on using the repository browser.