Copy Link
Add to Bookmark
Report
NULL mag Issue 09 24 Read .DAT files in mystic
in case u were wondering how the fuck to use the DATMAKER program you saw earlier... here it is ;) i written it in MPL so you could use it to make some nice MPL scripts/doors, but the code can, very easy, translated to Free/Turbo Pascal... even Python.
make sure to use the same verifystring as in the DATMAKER program. you can change it to match your needs, but it has to be the same for both the DATMAKER and this script to work.
the getheaderby_id function will read the header for a file, specified by its ID. read the datmaker article if you don't remember what this is.
with the extractfile function you can extract any file included in the .DAT file. see the example bellow, on how it works. it's not difficult.
uses cfg;
Const
verifystring = 'datmkv10byxqtr';
type
trec = record
verify : string[14];
title : string[30];
author : string[30];
category : string[30];
id : string[5];
ftype : string[3];
ptr : string[10];
size : string[10];
end;
procedure getheaderby_id(fn:string; id:string; var r:trec);
var
f:file;
t:trec;
size:longint;
wo:word;
begin
if not fileexist(fn) then exit;
fassign(f,fn,66);
freset(f);
fillchar(t,sizeof(t),#0);
fread(f,t,sizeof(t));
while t.verify = verifystring do begin
//writeln(t.id);
//writeln(t.title);
//writeln(t.ptr);
//writeln(t.size);
if t.id=id then begin
r:=t;
break;
end;
fillchar(t,sizeof(t),#0);
fread(f,t,sizeof(t));
end;
fclose(f);
//writeln('rec size:'+int2str(sizeof(t)));
end;
procedure extractfile(from:string; r:trec; fn:string);
var
f:file;
g:file;
d:longint;
b,c,l:byte;
fg:byte;
bg:byte;
cfg:byte;
cbg:byte;
s:string;
size:longint;
ptr:longint;
step:byte;
begin
if not fileexist(from) then exit;
fassign(f,from,66);
freset(f);
size:=str2int(r.size);
//writeln(r.size);
ptr:=str2int(r.ptr);
fseek(f,ptr);
d:=0;
fassign(g,fn,66);
frewrite(g);
fg:=255;
bg:=255;
s:='';
step:=0;
while d<=size do begin
fread(f,c,1);
step:=step+1;
fread(f,b,1);
if c<>0 then begin
cfg:=b % 16;
cbg:=b / 16;
if fg <> cfg then begin
s:=s+'|'+padlt(int2str(b % 16),2,'0');
fg:=cfg;
end;
if bg <> cbg then begin
s:=s+'|'+int2str((b / 16)+16);
bg:=cbg;
end;
end;
if c<>0 then s:=s+chr(c);
if step>=80 then begin
fwriteln(g,s);
s:='';
step:=0;
end;
d:=d+2;
end;
fclose(g);
fclose(f);
end;
var
z:trec;
begin
textcolor(7);
getheaderby_id(cfgmpepath+'null.dat','12___',z);
if z.id = '12___' then begin
writeln('extractint to:'+cfgmpepath+'null-extract.txt');
extractfile(cfgmpepath+'null.dat', z, cfgmpepath+'null-extract.txt');
end;
end;