source: oup/current/Code/Exporters.pas@ 99

Last change on this file since 99 was 86, checked in by alloc, 18 years ago
File size: 7.4 KB
RevLine 
[46]1unit Exporters;
2
3interface
4
[86]5uses Classes, Dialogs, StrUtils, SysUtils, Math, Data, OniImgClass, OniDataClass;
[46]6
[86]7type
8 TExportHandlers = record
9 Ext: String[4];
10 needed: Boolean;
11 Handler: function(connection: TOniData; fileid: LongWord; filename: String): Integer;
12 end;
[46]13
[86]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;
[46]18
[86]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
[46]24var
[74]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);
[46]34
35
36
37implementation
38
[86]39uses Functions, DataStructures;
[46]40
41
42
[86]43procedure ExportDatFile(connection: TOniData; fileid: LongWord; filename: String);
[46]44var
45 filestream: TFileStream;
46 Data: Tdata;
47begin
[86]48 Data := connection.LoadDatFile(fileid);
[46]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
[86]63procedure ExportRawFiles(connection: TOniData; fileid: LongWord; filename: String);
[74]64var
65 i: Integer;
66 rawlist: TRawList;
67begin
[86]68 rawlist := connection.GetRawList(fileid);
[74]69 if Length(rawlist) > 0 then
70 for i := 0 to High(rawlist) do
[86]71 ExportRawFile(connection, fileid, rawlist[i].src_offset, filename);
[74]72end;
[46]73
[86]74procedure ExportRawFile(connection: TOniData; fileid: LongWord; dat_offset: LongWord; filename: String);
[46]75var
76 filestream: TFileStream;
77 Data: Tdata;
78begin
[86]79 SetLength(Data, connection.GetRawInfo(fileid, dat_offset).raw_size);
80 connection.LoadRawFile(fileid, dat_offset, @Data[0]);
[46]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
[86]95function ExportConverted(connection: TOniData; fileid: LongWord; filename: String): Integer;
[74]96var
97 i: Integer;
98 fileinfo: TFileInfo;
99begin
[86]100 fileinfo := connection.GetFileInfo(fileid);
[74]101 if Length(ExportHandlers) > 0 then
102 for i := 0 to High(ExportHandlers) do
103 if ExportHandlers[i].Ext = fileinfo.Extension then
[86]104 ExportHandlers[i].Handler(connection, fileid, filename);
[74]105end;
[46]106
107
108
[74]109
[46]110function ExportSNDD;
[74]111type
112 TDatData = packed record
[46]113 {0x00}
[74]114 _fileid: LongWord;
115 level: LongWord;
116 FormatSize: LongWord;
117 AudioFormat: Word;
118 NumChannels: Word;
[46]119 {0x10}
[74]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;
[46]131 {0x40}
[74]132 RawSize: LongWord;
133 RawPos: LongWord;
[46]134 end;
135var
136 filestream: TFileStream;
[74]137 DatData: TDatData;
138 i: Integer;
139 Data: Tdata;
[46]140
141 //Wave Header Stuff
[74]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;
[46]149begin
150 Result := export_noerror;
[86]151 connection.LoadDatFilePart(fileid, 0, SizeOf(DatData), @DatData);
[46]152 with DatData do
153 begin
154 //Initializing Header vars
[74]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;
[46]162 SetLength(Data, RAWSize);
[86]163 connection.LoadRawFile(fileid, $44, Data);
[46]164
[74]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));
[46]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
[86]201 connection.LoadDatFilePart(fileid, $18, SizeOf(link), @link);
[46]202 link := link div 256;
203
[86]204 connection.LoadDatFilePart(fileid, $1E, SizeOf(linkcount), @linkcount);
[46]205 for i := 1 to linkcount do
206 begin
[86]207 connection.LoadDatFilePart(fileid, $20 + (i - 1) * 12 + 8, SizeOf(link), @link);
[46]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
[86]224 connection.LoadDatFilePart(fileid, $14, SizeOf(loop_speed), @loop_speed);
225 connection.LoadDatFilePart(fileid, $16, SizeOf(unknown), @unknown);
[46]226
[86]227 connection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
[46]228 for i := 0 to linkcount - 1 do
229 begin
[86]230 connection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
[46]231 link := link div 256;
232 if link = 0 then
233 link := fileid - 1;
234 end;
235end;
236
237
238
239
[74]240function ExportImage;
[46]241var
242 filestream: TFileStream;
[74]243 img: TOniImage;
244 data: Tdata;
[46]245begin
246 Result := export_noerror;
247
[74]248 img := TOniImage.Create;
[86]249 img.Load(connection, fileid);
[74]250 data := img.GetAsBMP;
251 img.Free;
[46]252
[74]253 filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
254 filestream.Write(data[0],Length(data));
255 filestream.Free;
256end;
[46]257
258end.
Note: See TracBrowser for help on using the repository browser.