source: oup/current/Global/RawList.pas@ 147

Last change on this file since 147 was 147, checked in by alloc, 18 years ago
File size: 12.7 KB
Line 
1unit RawList;
2interface
3uses TypeDefs;
4
5type
6 THandler = function(ConnectionID, FileID: Integer): TRawDataList;
7 TRawListHandler = record
8 Ext: String[4];
9 needed: Boolean;
10 Handler: THandler;
11 end;
12 TRawListHandlers = array of TRawListHandler;
13
14 TRawLists = class
15 private
16 FRawListHandlers: TRawListHandlers;
17 public
18 property RawListHandlers: TRawListHandlers read FRawListHandlers;
19 procedure InsertRawListHandler(ext: String; needed: Boolean; handler: THandler);
20 function GetRawList(ConnectionID, FileID: Integer): TRawDataList;
21 function GetRawInfo(ConnectionID, FileID, DatOffset: Integer): TRawDataInfo;
22 end;
23
24
25var
26 RawLists: TRawLists;
27
28
29implementation
30
31uses
32 Template, ConnectionManager, Access_OniArchive, Classes, SysUtils, Math;
33
34
35function AGDB(ConnectionID, FileID: Integer): TRawDataList;
36var
37 link: Integer;
38 links: Integer;
39 i: Integer;
40begin
41 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, 4, @links);
42 links := links * 2;
43 SetLength(Result, links);
44 for i := 0 to links - 1 do
45 begin
46 Result[i].SrcOffset := $20 + i * 4;
47 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * 4, 4, @link);
48 Result[i].RawAddr := link;
49 Result[i].RawSize := 32;
50 Result[i].LocSep := False;
51 end;
52end;
53
54
55
56
57function AKVA(ConnectionID, FileID: Integer): TRawDataList;
58var
59 link: Integer;
60 links: Integer;
61 i: Integer;
62begin
63 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, 4, @links);
64 SetLength(Result, links);
65 for i := 0 to links - 1 do
66 begin
67 Result[i].SrcOffset := $20 + i * $74 + $24;
68 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * $74 + $24, 4, @link);
69 Result[i].RawAddr := link;
70 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * $74 + $28, 4, @link);
71 Result[i].RawSize := link;
72 Result[i].LocSep := False;
73 end;
74end;
75
76
77
78
79function BINA(ConnectionID, FileID: Integer): TRawDataList;
80var
81 link: Integer;
82 datasize: Integer;
83begin
84 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $0C, 4, @link);
85 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $08, 4, @datasize);
86 SetLength(Result, 1);
87 Result[0].SrcOffset := $0C;
88 Result[0].RawAddr := link;
89 Result[0].RawSize := datasize;
90 Result[0].LocSep := not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN);
91end;
92
93
94
95
96function OSBD(ConnectionID, FileID: Integer): TRawDataList;
97var
98 link: Integer;
99 datasize: Integer;
100begin
101 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $08, 4, @datasize);
102 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $0C, 4, @link);
103 SetLength(Result, 1);
104 Result[0].SrcOffset := $0C;
105 Result[0].RawAddr := link;
106 Result[0].RawSize := datasize;
107 Result[0].LocSep := not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN);
108end;
109
110
111
112
113function SNDD(ConnectionID, FileID: Integer): TRawDataList;
114var
115 link: Integer;
116 datasize: Integer;
117begin
118 SetLength(Result, 1);
119 if ConManager.Connection[ConnectionID].DataOS = DOS_MAC then
120 begin
121 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $10, 4, @datasize);
122 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $14, 4, @link);
123 Result[0].SrcOffset := $14;
124 end
125 else
126 begin
127 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $40, 4, @datasize);
128 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $44, 4, @link);
129 Result[0].SrcOffset := $44;
130 end;
131 Result[0].RawAddr := link;
132 Result[0].RawSize := datasize;
133 Result[0].LocSep := False;
134end;
135
136
137
138
139function SUBT(ConnectionID, FileID: Integer): TRawDataList;
140var
141 baselink, lastlink: Integer;
142 links: Integer;
143 Data: TStream;
144 read: Integer;
145 char: Byte;
146 foundzeros: Byte;
147begin
148 SetLength(Result, 0);
149
150 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $18, 4, @baselink);
151 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, 4, @links);
152 if links > 0 then
153 begin
154 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + (links - 1) * 4, 4, @lastlink);
155 Data := nil;
156 TAccess_OniArchive(ConManager.Connection[ConnectionID]).LoadRawOffset(
157 False, baselink, lastlink + 1024, Data);
158
159 foundzeros := 0;
160 repeat
161 read := Data.Read(char, 1);
162 if (read > 0) and (char = 0) then
163 begin
164 Inc(foundzeros);
165 end;
166 until (read = 0) or (foundzeros = 2);
167
168 if foundzeros = 2 then
169 begin
170 SetLength(Result, 1);
171 Result[0].SrcID := FileID;
172 Result[0].SrcOffset := $18;
173 Result[0].RawAddr := baselink;
174 Result[0].RawSize := Data.Position;
175 Result[0].LocSep := False;
176 end;
177 end;
178end;
179
180
181
182
183function TRAM(ConnectionID, FileID: Integer): TRawDataList;
184var
185 i: Integer;
186 link: Integer;
187 frames: Word;
188 tempb: Byte;
189 tempw: Word;
190 templ: Integer;
191 Data: TByteData;
192 offset: Word;
193 frame_count: Byte;
194begin
195 SetLength(Result, 13);
196 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $16C, 2, @frames);
197 {y-pos}
198 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $0C, 4, @link);
199 Result[0].SrcOffset := $0C;
200 Result[0].RawAddr := link;
201 Result[0].RawSize := frames * 4;
202 {x-z-pos}
203 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $10, 4, @link);
204 Result[1].SrcOffset := $10;
205 Result[1].RawAddr := link;
206 Result[1].RawSize := frames * 8;
207 {attacks}
208 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $182, 1, @tempb);
209 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $14, 4, @link);
210 Result[2].SrcOffset := $14;
211 Result[2].RawAddr := link;
212 Result[2].RawSize := tempb * 32;
213 {damage}
214 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $183, 1, @tempb);
215 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $18, 4, @link);
216 Result[3].SrcOffset := $18;
217 Result[3].RawAddr := link;
218 Result[3].RawSize := tempb * 8;
219 {motionblur}
220 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $184, 1, @tempb);
221 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, 4, @link);
222 Result[4].SrcOffset := $1C;
223 Result[4].RawAddr := link;
224 Result[4].RawSize := tempb * 8;
225 {shortcut}
226 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $185, 1, @tempb);
227 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20, 4, @link);
228 Result[5].SrcOffset := $20;
229 Result[5].RawAddr := link;
230 Result[5].RawSize := tempb * 8;
231 {throw}
232 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $24, 4, @link);
233 Result[6].SrcOffset := $24;
234 Result[6].RawAddr := link;
235 if link > 0 then
236 Result[6].RawSize := 24
237 else
238 Result[6].RawSize := 0;
239 {footstep}
240 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $186, 1, @tempb);
241 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $28, 4, @link);
242 Result[7].SrcOffset := $28;
243 Result[7].RawAddr := link;
244 Result[7].RawSize := tempb * 4;
245 {particle}
246 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $187, 1, @tempb);
247 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $2C, 4, @link);
248 Result[8].SrcOffset := $2C;
249 Result[8].RawAddr := link;
250 Result[8].RawSize := tempb * 24;
251 {position}
252 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $30, 4, @link);
253 Result[9].SrcOffset := $30;
254 Result[9].RawAddr := link;
255 Result[9].RawSize := frames * 8;
256 {particle}
257 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $154, 2, @tempw);
258 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $38, 4, @link);
259 Result[11].SrcOffset := $38;
260 Result[11].RawAddr := link;
261 Result[11].RawSize := tempw * 34;
262 {extent}
263 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $138, 4, @templ);
264 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $13C, 4, @link);
265 Result[12].SrcOffset := $13C;
266 Result[12].RawAddr := link;
267 Result[12].RawSize := templ * 12;
268
269 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $34, 4, @link);
270 if link > 0 then
271 begin
272 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $160, 2, @tempw);
273 frame_count := 0;
274 i := 0;
275 SetLength(Data, $FFFF);
276 TAccess_OniArchive(ConManager.Connection[ConnectionID]).LoadRawOffset(
277 False, link, $FFFF, Data);
278 offset := Data[$24] + Data[$25] * 256;
279 while (offset + i < Length(Data)) and (frame_count < frames - 1) do
280 begin
281 Inc(i, tempw);
282 frame_count := frame_count + Data[offset + i];
283 Inc(i);
284 end;
285 if offset + i < Length(Data) then
286 begin
287 Inc(i, tempw);
288 Result[10].RawSize := offset + i;
289 end
290 else
291 begin
292 Result[10].RawSize := 0;
293 end;
294 end;
295 Result[10].SrcOffset := $34;
296 Result[10].RawAddr := link;
297end;
298
299
300
301
302function TXMP(ConnectionID, FileID: Integer): TRawDataList;
303var
304 link_pc: Integer;
305 link_mac: Integer;
306 x, y: Word;
307 storetype: Byte;
308 datasize: Integer;
309 mipmap: Byte;
310
311 function GetImgSize(w,h, storetype: Integer): Integer;
312 begin
313 case storetype of
314 0, 1, 2:
315 Result := w*h*2;
316 8:
317 Result := w*h*4;
318 9:
319 Result := Max(1, w div 4) * Max(1, h div 4) * 8;
320 else
321 Result := -1;
322 end;
323 end;
324
325begin
326 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(mipmap), @mipmap);
327 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8C, SizeOf(x), @x);
328 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8E, SizeOf(y), @y);
329 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(storetype), @storetype);
330 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, 4, @link_pc);
331 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $A0, 4, @link_mac);
332
333
334 datasize := GetImgSize(x, y, storetype);
335 if (mipmap and $01) > 0 then
336 begin
337 repeat
338 x := Max(x div 2, 1);
339 y := Max(y div 2, 1);
340 datasize := datasize + GetImgSize(x, y, storetype);
341 until (x = 1) and (y = 1);
342 end;
343
344 SetLength(Result, 1);
345 if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
346 begin
347 Result[0].SrcOffset := $9C;
348 Result[0].RawAddr := link_pc;
349 end
350 else
351 begin
352 Result[0].SrcOffset := $A0;
353 Result[0].RawAddr := link_mac;
354 end;
355 Result[0].RawSize := datasize;
356 Result[0].LocSep := not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN);
357end;
358
359
360
361
362function TRawLists.GetRawInfo(ConnectionID, FileID,
363 DatOffset: Integer): TRawDataInfo;
364var
365 i: Integer;
366 RawList: TRawDataList;
367begin
368 RawList := GetRawList(ConnectionID, FileID);
369 Result.SrcID := -1;
370 Result.SrcOffset := -1;
371 Result.RawAddr := -1;
372 Result.RawSize := -1;
373 if Length(RawList) > 0 then
374 begin
375 for i := 0 to High(RawList) do
376 begin
377 if RawList[i].SrcOffset = DatOffset then
378 begin
379 Result.SrcID := FileID;
380 Result.SrcOffset := RawList[i].SrcOffset;
381 Result.RawAddr := RawList[i].RawAddr;
382 Result.RawSize := RawList[i].RawSize;
383 Result.LocSep := RawList[i].LocSep;
384 Break;
385 end;
386 end;
387 end;
388end;
389
390
391function TRawLists.GetRawList(ConnectionID, FileID: Integer): TRawDataList;
392var
393 i: Integer;
394 fileinfo: TFileInfo;
395begin
396 SetLength(Result, 0);
397 fileinfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID);
398 for i := 0 to High(FRawListHandlers) do
399 if UpperCase(FRawListHandlers[i].Ext) = UpperCase(fileinfo.extension) then
400 begin
401 if FRawListHandlers[i].needed then
402 Result := FRawListHandlers[i].Handler(ConnectionID, FileID);
403 Break;
404 end;
405end;
406
407procedure TRawLists.InsertRawListHandler(ext: String; needed: Boolean; handler: THandler);
408begin
409 SetLength(FRawListHandlers, Length(FRawListHandlers) + 1);
410 FRawListHandlers[High(FRawListHandlers)].Ext := ext;
411 FRawListHandlers[High(FRawListHandlers)].needed := needed;
412 FRawListHandlers[High(FRawListHandlers)].handler := handler;
413// Raws := Raws + ext;
414 AddToolListEntry('rawedit', '', ext);
415end;
416
417
418
419
420initialization
421 RawLists := TRawLists.Create;
422 RawLists.InsertRawListHandler('AGDB', False, AGDB);
423 RawLists.InsertRawListHandler('AKVA', True, AKVA);
424 RawLists.InsertRawListHandler('BINA', True, BINA);
425 RawLists.InsertRawListHandler('OSBD', True, OSBD);
426 RawLists.InsertRawListHandler('SNDD', True, SNDD);
427 RawLists.InsertRawListHandler('SUBT', True, SUBT);
428 RawLists.InsertRawListHandler('TRAM', True, TRAM);
429 RawLists.InsertRawListHandler('TXMP', True, TXMP);
430end.
Note: See TracBrowser for help on using the repository browser.