source: oup/current/Global/Exporters.pas@ 192

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