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