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

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