source: oup/releases/0.33a/Code/Exporters.pas@ 76

Last change on this file since 76 was 74, checked in by alloc, 18 years ago
File size: 7.0 KB
Line 
1unit Exporters;
2
3interface
4
5uses Classes, Dialogs, StrUtils, SysUtils, Math, Data, OniImgClass;
6
7procedure ExportDatFile(fileid: LongWord; filename: String);
8procedure ExportRawFiles(fileid: LongWord; filename: String);
9procedure ExportRawFile(fileid: LongWord; dat_offset: LongWord; filename: String);
10function ExportConverted(fileid: LongWord; filename: String): Integer;
11
12function ExportSNDD(fileid: LongWord; filename: String): Integer;
13function ExportTRAC(fileid: LongWord; filename: String): Integer;
14function ExportTXAN(fileid: LongWord; filename: String): Integer;
15function ExportImage(fileid: LongWord; filename: String): Integer;
16
17var
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
30implementation
31
32uses Functions, DataStructures, OniDataClass;
33
34
35
36procedure ExportDatFile(fileid: LongWord; filename: String);
37var
38 filestream: TFileStream;
39 Data: Tdata;
40begin
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;
53end;
54
55
56procedure ExportRawFiles(fileid: LongWord; filename: String);
57var
58 i: Integer;
59 rawlist: TRawList;
60begin
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);
65end;
66
67procedure ExportRawFile(fileid: LongWord; dat_offset: LongWord; filename: String);
68var
69 filestream: TFileStream;
70 Data: Tdata;
71begin
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;
86end;
87
88function ExportConverted(fileid: LongWord; filename: String): Integer;
89var
90 i: Integer;
91 fileinfo: TFileInfo;
92begin
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);
98end;
99
100
101
102
103function ExportSNDD;
104type
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;
128var
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;
142begin
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;
181end;
182
183
184
185
186function ExportTRAC;
187var
188 link: LongWord;
189 linkcount: Word;
190 i: LongWord;
191begin
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;
203end;
204
205
206
207
208function ExportTXAN;
209var
210 loop_speed, unknown: Word;
211 linkcount: LongWord;
212 link: LongWord;
213 i: Byte;
214begin
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;
228end;
229
230
231
232
233function ExportImage;
234var
235 filestream: TFileStream;
236 img: TOniImage;
237 data: Tdata;
238begin
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;
249end;
250
251end.
Note: See TracBrowser for help on using the repository browser.