source: oup/current/Code_Exporters.pas@ 44

Last change on this file since 44 was 43, checked in by alloc, 18 years ago

DevTree 0.33a.

File size: 7.0 KB
Line 
1unit Code_Exporters;
2
3interface
4
5uses Classes, Dialogs, StrUtils, SysUtils, Math, Data, Code_OniImgClass;
6
7procedure ExportDatFile(fileid: LongWord; filename: String);
8procedure ExportRawFile(fileid: LongWord; dat_offset: LongWord; filename: String);
9
10function ExportSNDD(fileid: LongWord; filename: String; convert: Boolean): Integer;
11function ExportTRAC(fileid: LongWord; filename: String; convert: Boolean): Integer;
12function ExportTXAN(fileid: LongWord; filename: String; convert: Boolean): Integer;
13function ExportTXMB(fileid: LongWord; filename: String; convert: Boolean): Integer;
14function ExportTXMP(fileid: LongWord; filename: String; convert: Boolean): Integer;
15
16var
17 ExportHandlers: array[1..1] of TExportHandlers = (
18 // (Ext:'ABNA'; needed:False),
19 //(Ext:'AGDB'; needed:False),
20 (Ext: 'SNDD'; needed: True; Handler: ExportSNDD)
21{ (Ext:'TRAC'; needed:True; Handler:ExportTRAC),
22 (Ext:'TXAN'; needed:True; Handler:ExportTXAN),
23 (Ext:'TXMB'; needed:True; Handler:ExportTXMB),
24 (Ext:'TXMP'; needed:True; Handler:ExportTXMP)
25});
26
27
28
29implementation
30
31uses Code_Functions, Code_DataStructures, Code_OniDataClass;
32
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
56
57
58procedure ExportRawFile(fileid: LongWord; dat_offset: LongWord; filename: String);
59var
60 filestream: TFileStream;
61 Data: Tdata;
62begin
63 SetLength(Data, OniDataConnection.GetRawInfo(fileid, dat_offset).raw_size);
64 OniDataConnection.LoadRawFile(fileid, dat_offset, @Data[0]);
65 if FileExists(filename + '.raw0x' + IntToHex(dat_offset, 8)) then
66 begin
67 filestream := TFileStream.Create(filename + '.raw0x' + IntToHex(
68 dat_offset, 8), fmOpenReadWrite);
69 filestream.Seek(0, soFromEnd);
70 end
71 else
72 begin
73 filestream := TFileStream.Create(filename + '.raw0x' + IntToHex(dat_offset, 8), fmCreate);
74 end;
75 filestream.Write(Data[0], Length(Data));
76 filestream.Free;
77end;
78
79
80
81
82function ExportSNDD;
83{ CONST
84 WAVheader:Array[0..0] OF Byte=(
85 Ord('R'),Ord('I'),Ord('F'),Ord('F'),0,0,0,0,Ord('W'),Ord('A'),Ord('V'),Ord('E'),
86 Ord('f'),Ord('m'),Ord('t'),Ord(' '),24,0,0,0,
87 );
88} type
89 TDatData = record
90 {0x00}
91 _fileid: LongWord;
92 level: LongWord;
93 Flag: LongWord;
94 FormatTag: Word;
95 ChanNo: Word;
96 {0x10}
97 SampleRate: LongWord;
98 BytesPSec: LongWord;
99 BPSample: LongWord;
100 BitsPS: LongWord;
101 {0x20}
102 Unknown: array[1..7] of LongWord;
103 Unknown2: Word;
104 {0x40}
105 RawSize: LongWord;
106 RawPos: LongWord;
107 end;
108var
109 filestream: TFileStream;
110
111 DatData: TDatData;
112 //Wave Header Stuff
113 ASCII_Group: LongWord; //"RIFF"
114 WAV_Len: LongWord;
115 ASCII_WAV: LongWord; //"WAVE"
116 ASCII_FMT: LongWord; //"fmt "
117 WAV_FMT_Len: LongWord;
118 ASCII_DATA: LongWord; //"data"
119 WAV_FolLen: LongWord;
120
121 Data: Tdata;
122begin
123 Result := export_noerror;
124 OniDataConnection.LoadDatFilePart(fileid, 0, SizeOf(DatData), @DatData);
125 with DatData do
126 begin
127 //Initializing Header vars
128 ASCII_Group := 1179011410; // 'RIFF'
129 WAV_Len := RAWSize + 70;
130 ASCII_WAV := 1163280727; // 'WAVE'
131 ASCII_FMT := 544501094; // 'fmt '
132 WAV_FMT_Len := 50; // 50 bytes
133 ASCII_DATA := 1635017060; // 'data'
134 WAV_FolLen := RAWSize;
135 SetLength(Data, RAWSize);
136 OniDataConnection.LoadRawFile(fileid, $44, Data);
137
138 filestream := TFileStream.Create(filename + '.raw', fmCreate);
139 filestream.Write(Data[0], Length(Data));
140 filestream.Free;
141
142 if convert then
143 begin
144 //Now start packing this into a neat wave...
145 filestream := TFileStream.Create(filename + '.wav', fmCreate);
146 filestream.Write(ASCII_Group, SizeOf(ASCII_Group));
147 filestream.Write(WAV_Len, SizeOf(WAV_Len));
148 filestream.Write(ASCII_WAV, SizeOf(ASCII_WAV));
149 filestream.Write(ASCII_FMT, SizeOf(ASCII_FMT));
150 filestream.Write(WAV_FMT_Len, SizeOf(WAV_FMT_Len));
151 filestream.Write(ChanNo, SizeOf(ChanNo));
152 filestream.Write(Samplerate, SizeOf(Samplerate));
153 filestream.Write(BytesPSec, SizeOf(BytesPSec));
154 filestream.Write(BPSample, SizeOf(BPSample));
155 filestream.Write(BitsPS, SizeOf(BitsPS));
156 filestream.Write(Unknown[1], SizeOf(Unknown));
157 filestream.Write(Unknown2, SizeOf(Unknown2));
158 filestream.Write(ASCII_DATA, SizeOf(ASCII_DATA));
159 filestream.Write(WAV_FolLen, SizeOf(WAV_FolLen));
160 filestream.Write(Data[0], Length(Data));
161 filestream.Free;
162 end;
163 end;
164end;
165
166
167
168
169function ExportTRAC;
170var
171 link: LongWord;
172 linkcount: Word;
173 i: LongWord;
174begin
175 Result := export_noerror;
176
177 OniDataConnection.LoadDatFilePart(fileid, $18, SizeOf(link), @link);
178 link := link div 256;
179
180 OniDataConnection.LoadDatFilePart(fileid, $1E, SizeOf(linkcount), @linkcount);
181 for i := 1 to linkcount do
182 begin
183 OniDataConnection.LoadDatFilePart(fileid, $20 + (i - 1) * 12 + 8, SizeOf(link), @link);
184 link := link div 256;
185 end;
186end;
187
188
189
190
191function ExportTXAN;
192var
193 loop_speed, unknown: Word;
194 linkcount: LongWord;
195 link: LongWord;
196 i: Byte;
197begin
198 Result := export_noerror;
199
200 OniDataConnection.LoadDatFilePart(fileid, $14, SizeOf(loop_speed), @loop_speed);
201 OniDataConnection.LoadDatFilePart(fileid, $16, SizeOf(unknown), @unknown);
202
203 OniDataConnection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
204 for i := 0 to linkcount - 1 do
205 begin
206 OniDataConnection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
207 link := link div 256;
208 if link = 0 then
209 link := fileid - 1;
210 end;
211end;
212
213
214
215
216function ExportTXMB;
217var
218 filestream: TFileStream;
219 // img:TImgPackage;
220 Data: Tdata;
221begin
222 Result := export_noerror;
223 if convert then
224 begin
225{ img:=LoadTXMBconnected(fileid);
226 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
227 filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
228 filestream.Write(data[0],Length(data));
229 filestream.Free;
230} end;
231end;
232
233
234
235
236function ExportTXMP;
237var
238 filestream: TFileStream;
239 // img:TImgPackage;
240begin
241 Result := export_noerror;
242{ img:=LoadImgData(fileid);
243
244 filestream:=TFileStream.Create(filename+'.raw',fmCreate);
245 filestream.Write(img.imgdata[0],Length(img.imgdata));
246 filestream.Free;
247
248 IF convert THEN BEGIN
249 img.imgdata:=ImgdataToBMP(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
250 filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
251 filestream.Write(img.imgdata[0],Length(img.imgdata));
252 filestream.Free;
253 END;
254} end;
255
256end.
Note: See TracBrowser for help on using the repository browser.