source: oup/_old_/Code/Exporters.pas@ 174

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