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