1 | UNIT Unit4_Exporters;
|
---|
2 | INTERFACE
|
---|
3 | USES Classes, Dialogs, StrUtils, SysUtils, Math, Unit3_data, Unit6_imgfuncs;
|
---|
4 |
|
---|
5 | PROCEDURE ExportDatFile(fileid:LongWord; filename:String);
|
---|
6 | PROCEDURE ExportRawFile(fileid:LongWord; dat_offset:LongWord; filename:String);
|
---|
7 |
|
---|
8 | FUNCTION ExportSNDD(fileid:LongWord; filename:String; convert:Boolean):Integer;
|
---|
9 | FUNCTION ExportTRAC(fileid:LongWord; filename:String; convert:Boolean):Integer;
|
---|
10 | FUNCTION ExportTXAN(fileid:LongWord; filename:String; convert:Boolean):Integer;
|
---|
11 | FUNCTION ExportTXMB(fileid:LongWord; filename:String; convert:Boolean):Integer;
|
---|
12 | FUNCTION ExportTXMP(fileid:LongWord; filename:String; convert:Boolean):Integer;
|
---|
13 | VAR
|
---|
14 | ExportHandlers:Array[1..1] OF TExportHandlers=(
|
---|
15 | // (Ext:'ABNA'; needed:False),
|
---|
16 | //(Ext:'AGDB'; needed:False),
|
---|
17 | (Ext:'SNDD'; needed:True; Handler:ExportSNDD)
|
---|
18 | { (Ext:'TRAC'; needed:True; Handler:ExportTRAC),
|
---|
19 | (Ext:'TXAN'; needed:True; Handler:ExportTXAN),
|
---|
20 | (Ext:'TXMB'; needed:True; Handler:ExportTXMB),
|
---|
21 | (Ext:'TXMP'; needed:True; Handler:ExportTXMP)
|
---|
22 | } );
|
---|
23 |
|
---|
24 |
|
---|
25 |
|
---|
26 | IMPLEMENTATION
|
---|
27 | USES Unit2_functions, Unit9_data_structures, Unit15_Classes;
|
---|
28 |
|
---|
29 | PROCEDURE ExportDatFile(fileid:LongWord; filename:String);
|
---|
30 | VAR
|
---|
31 | filestream:TFileStream;
|
---|
32 | data:Tdata;
|
---|
33 | BEGIN
|
---|
34 | data:=OniDataConnection.LoadDatFile(fileid);
|
---|
35 | IF FileExists(filename) THEN BEGIN
|
---|
36 | filestream:=TFileStream.Create(filename,fmOpenReadWrite);
|
---|
37 | filestream.Seek(0,soFromEnd);
|
---|
38 | END ELSE BEGIN
|
---|
39 | filestream:=TFileStream.Create(filename,fmCreate);
|
---|
40 | END;
|
---|
41 | filestream.Write(data[0],Length(data));
|
---|
42 | filestream.Free;
|
---|
43 | END;
|
---|
44 |
|
---|
45 | PROCEDURE ExportRawFile(fileid:LongWord; dat_offset:LongWord; filename:String);
|
---|
46 | VAR
|
---|
47 | filestream:TFileStream;
|
---|
48 | data:Tdata;
|
---|
49 | BEGIN
|
---|
50 | SetLength(data, OniDataConnection.GetRawInfo(fileid, dat_offset).raw_size);
|
---|
51 | OniDataConnection.LoadRawFile(fileid,dat_offset,@data[0]);
|
---|
52 | IF FileExists(filename+'.raw0x'+IntToHex(dat_offset,8)) THEN BEGIN
|
---|
53 | filestream:=TFileStream.Create(filename+'.raw0x'+IntToHex(dat_offset,8),fmOpenReadWrite);
|
---|
54 | filestream.Seek(0,soFromEnd);
|
---|
55 | END ELSE BEGIN
|
---|
56 | filestream:=TFileStream.Create(filename+'.raw0x'+IntToHex(dat_offset,8),fmCreate);
|
---|
57 | END;
|
---|
58 | filestream.Write(data[0],Length(data));
|
---|
59 | filestream.Free;
|
---|
60 | END;
|
---|
61 |
|
---|
62 | FUNCTION ExportSNDD;
|
---|
63 | { CONST
|
---|
64 | WAVheader:Array[0..0] OF Byte=(
|
---|
65 | Ord('R'),Ord('I'),Ord('F'),Ord('F'),0,0,0,0,Ord('W'),Ord('A'),Ord('V'),Ord('E'),
|
---|
66 | Ord('f'),Ord('m'),Ord('t'),Ord(' '),24,0,0,0,
|
---|
67 | );
|
---|
68 | } TYPE
|
---|
69 | TDatData=RECORD
|
---|
70 | {0x00}
|
---|
71 | _fileid:LongWord;
|
---|
72 | level:LongWord;
|
---|
73 | Flag:LongWord;
|
---|
74 | FormatTag:Word;
|
---|
75 | ChanNo:Word;
|
---|
76 | {0x10}
|
---|
77 | SampleRate:LongWord;
|
---|
78 | BytesPSec:LongWord;
|
---|
79 | BPSample:LongWord;
|
---|
80 | BitsPS:LongWord;
|
---|
81 | {0x20}
|
---|
82 | Unknown:Array[1..7] OF LongWord;
|
---|
83 | Unknown2:Word;
|
---|
84 | {0x40}
|
---|
85 | RawSize:LongWord;
|
---|
86 | RawPos:LongWord;
|
---|
87 | END;
|
---|
88 | VAR
|
---|
89 | filestream:TFileStream;
|
---|
90 |
|
---|
91 | DatData:TDatData;
|
---|
92 | //Wave Header Stuff
|
---|
93 | ASCII_Group:LongWord; //"RIFF"
|
---|
94 | WAV_Len:LongWord;
|
---|
95 | ASCII_WAV:LongWord; //"WAVE"
|
---|
96 | ASCII_FMT:LongWord; //"fmt "
|
---|
97 | WAV_FMT_Len:LongWord;
|
---|
98 | ASCII_DATA:LongWord; //"data"
|
---|
99 | WAV_FolLen:LongWord;
|
---|
100 |
|
---|
101 | data:Tdata;
|
---|
102 | BEGIN
|
---|
103 | Result:=export_noerror;
|
---|
104 | OniDataConnection.LoadDatFilePart(fileid,0,SizeOf(DatData),@DatData);
|
---|
105 | WITH DatData DO BEGIN
|
---|
106 | //Initializing Header vars
|
---|
107 | ASCII_Group:=1179011410; // 'RIFF'
|
---|
108 | WAV_Len:=RAWSize+70;
|
---|
109 | ASCII_WAV:=1163280727; // 'WAVE'
|
---|
110 | ASCII_FMT:=544501094; // 'fmt '
|
---|
111 | WAV_FMT_Len:=50; // 50 bytes
|
---|
112 | ASCII_DATA:=1635017060; // 'data'
|
---|
113 | WAV_FolLen:=RAWSize;
|
---|
114 | SetLength(data,RAWSize);
|
---|
115 | OniDataConnection.LoadRawFile(fileid,$44,data);
|
---|
116 |
|
---|
117 | filestream:=TFileStream.Create(filename+'.raw',fmCreate);
|
---|
118 | filestream.Write(data[0],Length(data));
|
---|
119 | filestream.Free;
|
---|
120 |
|
---|
121 | IF convert THEN BEGIN
|
---|
122 | //Now start packing this into a neat wave...
|
---|
123 | filestream:=TFileStream.Create(filename+'.wav',fmCreate);
|
---|
124 | filestream.Write(ASCII_Group,SizeOf(ASCII_Group));
|
---|
125 | filestream.Write(WAV_Len,SizeOf(WAV_Len));
|
---|
126 | filestream.Write(ASCII_WAV,SizeOf(ASCII_WAV));
|
---|
127 | filestream.Write(ASCII_FMT,SizeOf(ASCII_FMT));
|
---|
128 | filestream.Write(WAV_FMT_Len,SizeOf(WAV_FMT_Len));
|
---|
129 | filestream.Write(ChanNo,SizeOf(ChanNo));
|
---|
130 | filestream.Write(Samplerate,SizeOf(Samplerate));
|
---|
131 | filestream.Write(BytesPSec,SizeOf(BytesPSec));
|
---|
132 | filestream.Write(BPSample,SizeOf(BPSample));
|
---|
133 | filestream.Write(BitsPS,SizeOf(BitsPS));
|
---|
134 | filestream.Write(Unknown[1],SizeOf(Unknown));
|
---|
135 | filestream.Write(Unknown2,SizeOf(Unknown2));
|
---|
136 | filestream.Write(ASCII_DATA,SizeOf(ASCII_DATA));
|
---|
137 | filestream.Write(WAV_FolLen,SizeOf(WAV_FolLen));
|
---|
138 | filestream.Write(data[0],Length(data));
|
---|
139 | filestream.Free;
|
---|
140 | END;
|
---|
141 | END;
|
---|
142 | END;
|
---|
143 |
|
---|
144 | FUNCTION ExportTRAC;
|
---|
145 | VAR
|
---|
146 | link:LongWord;
|
---|
147 | linkcount:Word;
|
---|
148 | i:LongWord;
|
---|
149 | BEGIN
|
---|
150 | Result:=export_noerror;
|
---|
151 |
|
---|
152 | OniDataConnection.LoadDatFilePart(fileid,$18,SizeOf(link),@link);
|
---|
153 | link:=link DIV 256;
|
---|
154 |
|
---|
155 | OniDataConnection.LoadDatFilePart(fileid,$1E,SizeOf(linkcount),@linkcount);
|
---|
156 | FOR i:=1 TO linkcount DO BEGIN
|
---|
157 | OniDataConnection.LoadDatFilePart(fileid,$20+(i-1)*12+8,SizeOf(link),@link);
|
---|
158 | link:=link DIV 256;
|
---|
159 | END;
|
---|
160 | END;
|
---|
161 |
|
---|
162 | FUNCTION ExportTXAN;
|
---|
163 | VAR
|
---|
164 | loop_speed,unknown:Word;
|
---|
165 | linkcount:LongWord;
|
---|
166 | link:LongWord;
|
---|
167 | i:Byte;
|
---|
168 | BEGIN
|
---|
169 | Result:=export_noerror;
|
---|
170 |
|
---|
171 | OniDataConnection.LoadDatFilePart(fileid,$14,SizeOf(loop_speed),@loop_speed);
|
---|
172 | OniDataConnection.LoadDatFilePart(fileid,$16,SizeOf(unknown),@unknown);
|
---|
173 |
|
---|
174 | OniDataConnection.LoadDatFilePart(fileid,$1C,SizeOf(linkcount),@linkcount);
|
---|
175 | FOR i:=0 TO linkcount-1 DO BEGIN
|
---|
176 | OniDataConnection.LoadDatFilePart(fileid,$20+i*4,SizeOf(link),@link);
|
---|
177 | link:=link DIV 256;
|
---|
178 | IF link=0 THEN link:=fileid-1;
|
---|
179 | END;
|
---|
180 | END;
|
---|
181 |
|
---|
182 | FUNCTION ExportTXMB;
|
---|
183 | VAR
|
---|
184 | filestream:TFileStream;
|
---|
185 | img:TImgPackage;
|
---|
186 | data:Tdata;
|
---|
187 | BEGIN
|
---|
188 | Result:=export_noerror;
|
---|
189 | IF convert THEN BEGIN
|
---|
190 | img:=LoadTXMBconnected(fileid);
|
---|
191 | data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
|
---|
192 | filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
|
---|
193 | filestream.Write(data[0],Length(data));
|
---|
194 | filestream.Free;
|
---|
195 | END;
|
---|
196 | END;
|
---|
197 |
|
---|
198 | FUNCTION ExportTXMP;
|
---|
199 | VAR
|
---|
200 | filestream:TFileStream;
|
---|
201 | img:TImgPackage;
|
---|
202 | BEGIN
|
---|
203 | Result:=export_noerror;
|
---|
204 | img:=LoadImgData(fileid);
|
---|
205 |
|
---|
206 | filestream:=TFileStream.Create(filename+'.raw',fmCreate);
|
---|
207 | filestream.Write(img.imgdata[0],Length(img.imgdata));
|
---|
208 | filestream.Free;
|
---|
209 |
|
---|
210 | IF convert THEN BEGIN
|
---|
211 | img.imgdata:=ImgdataToBMP(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
|
---|
212 | filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
|
---|
213 | filestream.Write(img.imgdata[0],Length(img.imgdata));
|
---|
214 | filestream.Free;
|
---|
215 | END;
|
---|
216 | END;
|
---|
217 |
|
---|
218 | END.
|
---|