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 ExportRawFiles(fileid: LongWord; filename: String);
|
---|
9 | procedure ExportRawFile(fileid: LongWord; dat_offset: LongWord; filename: String);
|
---|
10 | function ExportConverted(fileid: LongWord; filename: String): Integer;
|
---|
11 |
|
---|
12 | function ExportSNDD(fileid: LongWord; filename: String): Integer;
|
---|
13 | function ExportTRAC(fileid: LongWord; filename: String): Integer;
|
---|
14 | function ExportTXAN(fileid: LongWord; filename: String): Integer;
|
---|
15 | function ExportImage(fileid: LongWord; filename: String): Integer;
|
---|
16 |
|
---|
17 | var
|
---|
18 | ExportHandlers: array[1..3] of TExportHandlers = (
|
---|
19 | // (Ext:'ABNA'; needed:False),
|
---|
20 | // (Ext:'AGDB'; needed:False),
|
---|
21 | (Ext: 'SNDD'; needed: True; Handler: ExportSNDD),
|
---|
22 | // (Ext:'TRAC'; needed:True; Handler:ExportTRAC),
|
---|
23 | // (Ext:'TXAN'; needed:True; Handler:ExportTXAN),
|
---|
24 | (Ext:'TXMB'; needed:True; Handler:ExportImage),
|
---|
25 | (Ext:'TXMP'; needed:True; Handler:ExportImage)
|
---|
26 | );
|
---|
27 |
|
---|
28 |
|
---|
29 |
|
---|
30 | implementation
|
---|
31 |
|
---|
32 | uses Functions, DataStructures, OniDataClass;
|
---|
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 | procedure ExportRawFiles(fileid: LongWord; filename: String);
|
---|
57 | var
|
---|
58 | i: Integer;
|
---|
59 | rawlist: TRawList;
|
---|
60 | begin
|
---|
61 | rawlist := OniDataConnection.GetRawList(fileid);
|
---|
62 | if Length(rawlist) > 0 then
|
---|
63 | for i := 0 to High(rawlist) do
|
---|
64 | ExportRawFile(fileid, rawlist[i].src_offset, filename);
|
---|
65 | end;
|
---|
66 |
|
---|
67 | procedure ExportRawFile(fileid: LongWord; dat_offset: LongWord; filename: String);
|
---|
68 | var
|
---|
69 | filestream: TFileStream;
|
---|
70 | Data: Tdata;
|
---|
71 | begin
|
---|
72 | SetLength(Data, OniDataConnection.GetRawInfo(fileid, dat_offset).raw_size);
|
---|
73 | OniDataConnection.LoadRawFile(fileid, dat_offset, @Data[0]);
|
---|
74 | if FileExists(filename + '.raw0x' + IntToHex(dat_offset, 8)) then
|
---|
75 | begin
|
---|
76 | filestream := TFileStream.Create(filename + '.raw0x' + IntToHex(
|
---|
77 | dat_offset, 8), fmOpenReadWrite);
|
---|
78 | filestream.Seek(0, soFromEnd);
|
---|
79 | end
|
---|
80 | else
|
---|
81 | begin
|
---|
82 | filestream := TFileStream.Create(filename + '.raw0x' + IntToHex(dat_offset, 8), fmCreate);
|
---|
83 | end;
|
---|
84 | filestream.Write(Data[0], Length(Data));
|
---|
85 | filestream.Free;
|
---|
86 | end;
|
---|
87 |
|
---|
88 | function ExportConverted(fileid: LongWord; filename: String): Integer;
|
---|
89 | var
|
---|
90 | i: Integer;
|
---|
91 | fileinfo: TFileInfo;
|
---|
92 | begin
|
---|
93 | fileinfo := OniDataConnection.GetFileInfo(fileid);
|
---|
94 | if Length(ExportHandlers) > 0 then
|
---|
95 | for i := 0 to High(ExportHandlers) do
|
---|
96 | if ExportHandlers[i].Ext = fileinfo.Extension then
|
---|
97 | ExportHandlers[i].Handler(fileid, filename);
|
---|
98 | end;
|
---|
99 |
|
---|
100 |
|
---|
101 |
|
---|
102 |
|
---|
103 | function ExportSNDD;
|
---|
104 | type
|
---|
105 | TDatData = packed record
|
---|
106 | {0x00}
|
---|
107 | _fileid: LongWord;
|
---|
108 | level: LongWord;
|
---|
109 | FormatSize: LongWord;
|
---|
110 | AudioFormat: Word;
|
---|
111 | NumChannels: Word;
|
---|
112 | {0x10}
|
---|
113 | SampleRate: LongWord;
|
---|
114 | ByteRate: LongWord;
|
---|
115 | BlockAlign: Word;
|
---|
116 | BitsPerSample: Word;
|
---|
117 | {0x1C}
|
---|
118 | SizeExtHeader: Word;
|
---|
119 | SamplesPerBlock: Word;
|
---|
120 | NumCoefficients: Word;
|
---|
121 | Coefficients: array[0..6] of LongWord;
|
---|
122 | {0x3E}
|
---|
123 | Duration: Word;
|
---|
124 | {0x40}
|
---|
125 | RawSize: LongWord;
|
---|
126 | RawPos: LongWord;
|
---|
127 | end;
|
---|
128 | var
|
---|
129 | filestream: TFileStream;
|
---|
130 | DatData: TDatData;
|
---|
131 | i: Integer;
|
---|
132 | Data: Tdata;
|
---|
133 |
|
---|
134 | //Wave Header Stuff
|
---|
135 | ASCII_RIFF: LongWord; //"RIFF"
|
---|
136 | WAVE_Len: LongWord;
|
---|
137 | ASCII_WAVE: LongWord; //"WAVE"
|
---|
138 | ASCII_FMT: LongWord; //"fmt "
|
---|
139 | WAVE_FMT_Len: LongWord;
|
---|
140 | ASCII_DATA: LongWord; //"data"
|
---|
141 | WAVE_DataLen: LongWord;
|
---|
142 | begin
|
---|
143 | Result := export_noerror;
|
---|
144 | OniDataConnection.LoadDatFilePart(fileid, 0, SizeOf(DatData), @DatData);
|
---|
145 | with DatData do
|
---|
146 | begin
|
---|
147 | //Initializing Header vars
|
---|
148 | ASCII_RIFF := 1179011410; // 'RIFF'
|
---|
149 | WAVE_Len := RAWSize + 70;
|
---|
150 | ASCII_WAVE := 1163280727; // 'WAVE'
|
---|
151 | ASCII_FMT := 544501094; // 'fmt '
|
---|
152 | WAVE_FMT_Len := 50; // 50 bytes
|
---|
153 | ASCII_DATA := 1635017060; // 'data'
|
---|
154 | WAVE_DataLen := RAWSize;
|
---|
155 | SetLength(Data, RAWSize);
|
---|
156 | OniDataConnection.LoadRawFile(fileid, $44, Data);
|
---|
157 |
|
---|
158 | //Now start packing this into a neat wave...
|
---|
159 | filestream := TFileStream.Create(filename + '.wav', fmCreate);
|
---|
160 | filestream.Write(ASCII_RIFF, SizeOf(ASCII_RIFF));
|
---|
161 | filestream.Write(WAVE_Len, SizeOf(WAVE_Len));
|
---|
162 | filestream.Write(ASCII_WAVE, SizeOf(ASCII_WAVE));
|
---|
163 | filestream.Write(ASCII_FMT, SizeOf(ASCII_FMT));
|
---|
164 | filestream.Write(WAVE_FMT_Len, SizeOf(WAVE_FMT_Len));
|
---|
165 | filestream.Write(AudioFormat, SizeOf(AudioFormat));
|
---|
166 | filestream.Write(NumChannels, SizeOf(NumChannels));
|
---|
167 | filestream.Write(Samplerate, SizeOf(Samplerate));
|
---|
168 | filestream.Write(ByteRate, SizeOf(ByteRate));
|
---|
169 | filestream.Write(BlockAlign, SizeOf(BlockAlign));
|
---|
170 | filestream.Write(BitsPerSample, SizeOf(BitsPerSample));
|
---|
171 | filestream.Write(SizeExtHeader, SizeOf(SizeExtHeader));
|
---|
172 | filestream.Write(SamplesPerBlock, SizeOf(SamplesPerBlock));
|
---|
173 | filestream.Write(NumCoefficients, SizeOf(NumCoefficients));
|
---|
174 | for i := 0 to High(Coefficients) do
|
---|
175 | filestream.Write(Coefficients[i], SizeOf(Coefficients[i]));
|
---|
176 | filestream.Write(ASCII_DATA, SizeOf(ASCII_DATA));
|
---|
177 | filestream.Write(WAVE_DataLen, SizeOf(WAVE_DataLen));
|
---|
178 | filestream.Write(Data[0], Length(Data));
|
---|
179 | filestream.Free;
|
---|
180 | end;
|
---|
181 | end;
|
---|
182 |
|
---|
183 |
|
---|
184 |
|
---|
185 |
|
---|
186 | function ExportTRAC;
|
---|
187 | var
|
---|
188 | link: LongWord;
|
---|
189 | linkcount: Word;
|
---|
190 | i: LongWord;
|
---|
191 | begin
|
---|
192 | Result := export_noerror;
|
---|
193 |
|
---|
194 | OniDataConnection.LoadDatFilePart(fileid, $18, SizeOf(link), @link);
|
---|
195 | link := link div 256;
|
---|
196 |
|
---|
197 | OniDataConnection.LoadDatFilePart(fileid, $1E, SizeOf(linkcount), @linkcount);
|
---|
198 | for i := 1 to linkcount do
|
---|
199 | begin
|
---|
200 | OniDataConnection.LoadDatFilePart(fileid, $20 + (i - 1) * 12 + 8, SizeOf(link), @link);
|
---|
201 | link := link div 256;
|
---|
202 | end;
|
---|
203 | end;
|
---|
204 |
|
---|
205 |
|
---|
206 |
|
---|
207 |
|
---|
208 | function ExportTXAN;
|
---|
209 | var
|
---|
210 | loop_speed, unknown: Word;
|
---|
211 | linkcount: LongWord;
|
---|
212 | link: LongWord;
|
---|
213 | i: Byte;
|
---|
214 | begin
|
---|
215 | Result := export_noerror;
|
---|
216 |
|
---|
217 | OniDataConnection.LoadDatFilePart(fileid, $14, SizeOf(loop_speed), @loop_speed);
|
---|
218 | OniDataConnection.LoadDatFilePart(fileid, $16, SizeOf(unknown), @unknown);
|
---|
219 |
|
---|
220 | OniDataConnection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
|
---|
221 | for i := 0 to linkcount - 1 do
|
---|
222 | begin
|
---|
223 | OniDataConnection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
|
---|
224 | link := link div 256;
|
---|
225 | if link = 0 then
|
---|
226 | link := fileid - 1;
|
---|
227 | end;
|
---|
228 | end;
|
---|
229 |
|
---|
230 |
|
---|
231 |
|
---|
232 |
|
---|
233 | function ExportImage;
|
---|
234 | var
|
---|
235 | filestream: TFileStream;
|
---|
236 | img: TOniImage;
|
---|
237 | data: Tdata;
|
---|
238 | begin
|
---|
239 | Result := export_noerror;
|
---|
240 |
|
---|
241 | img := TOniImage.Create;
|
---|
242 | img.Load(fileid);
|
---|
243 | data := img.GetAsBMP;
|
---|
244 | img.Free;
|
---|
245 |
|
---|
246 | filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
|
---|
247 | filestream.Write(data[0],Length(data));
|
---|
248 | filestream.Free;
|
---|
249 | end;
|
---|
250 |
|
---|
251 | end.
|
---|