Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit datReader;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, addresses;
- procedure loadTibiaDat(filename: string);
- implementation
- procedure loadTibiaDat(filename: string);
- var
- f: File;
- index: integer;
- tmpI, i, ID_OFFSET: integer;
- w, nItems, nCreatures, nEffects, nMissile, nCount: word;
- b, optByte, optbyte2: byte;
- lWidth, lHeight, lBlendframes, lXdiv, lYdiv, lAnimcount, lRare, skipcount: integer;
- tmpName: string;
- begin
- ID_OFFSET := 99;
- AssignFile(f, filename);
- Reset(f, 1);
- BlockRead(f, i, 4);
- BlockRead(f, nItems, 2);
- BlockRead(f, nCreatures, 2);
- BlockRead(f, nEffects, 2);
- BlockRead(f, nMissile, 2);
- nCount := nItems + nCreatures + nEffects + nMissile;
- setlength( DatTiles, nCount );
- for index := 0 to nCount do
- begin
- DatTiles[index].isContainer := false;
- DatTiles[index].RWInfo := 0;
- DatTiles[index].fluidContainer := false;
- DatTiles[index].stackable := false;
- DatTiles[index].multiType := false;
- DatTiles[index].useable := false;
- DatTiles[index].notMoveable := false;
- DatTiles[index].alwaysOnTop := false;
- DatTiles[index].groundTile := false;
- DatTiles[index].blocking := false;
- DatTiles[index].blockPickupable := false;
- DatTiles[index].pickupable := false;
- DatTiles[index].blockingProjectile := false;
- DatTiles[index].canWalkThrough := false;
- DatTiles[index].noFloorChange := false;
- DatTiles[index].isDoor := false;
- DatTiles[index].isDoorWithLock := false;
- DatTiles[index].speed := 0;
- DatTiles[index].canDecay := false;
- DatTiles[index].haveExtraByte := false;
- DatTiles[index].haveExtraByte2 := false;
- DatTiles[index].totalExtraBytes := 0;
- DatTiles[index].isWater := false;
- DatTiles[index].stackPriority := 0;
- DatTiles[index].haveFish := false;
- DatTiles[index].floorChangeUP := false;
- DatTiles[index].floorChangeDOWN := false;
- DatTiles[index].requireRightClick := false;
- DatTiles[index].requireRope := false;
- DatTiles[index].requireShovel := false;
- DatTiles[index].isFood := false;
- DatTiles[index].isField := false;
- DatTiles[index].isDepot := false;
- DatTiles[index].moreAlwaysOnTop := false;
- DatTiles[index].usable2 := false;
- DatTiles[index].multiCharge := false;
- DatTiles[index].haveName := false;
- DatTiles[index].itemName := '';
- end;
- DatTiles[0].stackPriority := 0;
- DatTiles[97].stackPriority := 2;
- DatTiles[98].stackPriority := 2;
- DatTiles[99].stackPriority := 2;
- DatTiles[97].blocking := true;
- DatTiles[98].blocking := true;
- DatTiles[99].blocking := true;
- index := 100;
- repeat
- // read next byte
- BlockRead(f, optByte, 1);
- while (optByte <> $FF) and not eof(f) do
- begin
- case optByte of
- $00:
- begin
- DatTiles[index].groundTile := true;
- // read speed
- BlockRead(f, b, 1);
- DatTiles[index].speed := b;
- // if speed is 0 then blocking
- if b = 0 then
- DatTiles[index].blocking := true;
- // ignore next byte
- BlockRead(f, b, 1);
- end;
- $01: DatTiles[index].moreAlwaysOnTop := true;
- $02: DatTiles[index].alwaysOnTop := true;
- $03:
- begin
- DatTiles[index].canWalkThrough := true;
- DatTiles[index].alwaysOnTop := true;
- end;
- $04: DatTiles[index].isContainer := true;
- $05: DatTiles[index].stackable := true;
- $06: DatTiles[index].useable := true;
- $07: DatTiles[index].usable2 := true;
- $08:
- begin
- DatTiles[index].RWInfo := 3;
- BlockRead(f, b, 1); // max characters that can be written in it (0 unlimited)
- BlockRead(f, b, 1); // max number of newlines ? 0, 2, 4, 7
- end;
- $09:
- begin
- DatTiles[index].RWInfo := 1;
- BlockRead(f, b, 1); // max characters that can be written in it (0 unlimited)
- BlockRead(f, b, 1); // always 4 max number of newlines ?
- end;
- $0A: DatTiles[index].fluidContainer := true;
- $0B: DatTiles[index].multiType := true;
- $0C: DatTiles[index].blocking := true;
- $0D: DatTiles[index].notMoveable := true;
- $0E: DatTiles[index].blockingProjectile := true;
- $0F: ;// ignored
- $10: DatTiles[index].pickupable := true;
- $15:
- begin
- BlockRead(f, b, 1); // number of tiles around
- BlockRead(f, b, 1); // 0
- BlockRead(f, b, 1); // 215 for items , 208 for non items
- BlockRead(f, b, 1); // ??
- end;
- $11: ;// can see what is under (ladder holes, stairs holes etc)
- $1E: DatTiles[index].noFloorChange := true;
- $19:
- begin
- DatTiles[index].blockPickupable := false;
- BlockRead(f, b, 1); // always 8
- BlockRead(f, b, 1); // always 0
- end;
- $14: ; // unknown
- $18: BlockRead(f, i, 4); // dunno
- $1C: BlockRead(f, w, 2); // 2 bytes for colour (b and b)
- $17: DatTiles[index].floorChangeDOWN := true;
- $1A: DatTiles[index].canDecay := false;
- $1B: ;// wall items
- $12: ;// action possible
- $13: ;// walls 2 types of them same material (total 4 pairs)
- $1D:
- begin
- // line spot ...
- BlockRead(f, optbyte2, 1);
- case optbyte2 of
- $4C:
- begin
- DatTiles[index].floorChangeUP := true;
- DatTiles[index].requireRightClick := true;
- end;
- $4D: DatTiles[index].requireRightClick := true;
- $4E:
- begin
- DatTiles[index].floorChangeUP := true;
- DatTiles[index].requireRope := true;
- end;
- $4F: ;// switch
- $50: DatTiles[index].isDoor := true;
- $51: DatTiles[index].isDoorWithLock := true;
- $52: DatTiles[index].floorChangeUP := true;
- $53: DatTiles[index].isDepot := true;
- $55: ;// trash
- $56:
- begin
- DatTiles[index].floorChangeDOWN := true;
- DatTiles[index].requireShovel := true;
- DatTiles[index].alwaysOnTop := true;
- DatTiles[index].multiType := false;
- end;
- $57: ; // items with special description?
- $58: DatTiles[index].RWInfo := 1; // read only
- end;
- BlockRead(f, b, 1);
- end;
- $1F: ;// new flag since 8.57
- $20:
- begin
- BlockRead(f, w, 2); // unknown meaning
- end;
- $16: ;// new flag since tibia 8.57
- $21: // item group, something, and name (tibia 9.4)
- begin
- BlockRead(f, b, 1); // group 1
- BlockRead(f, b, 1); // group 2
- BlockRead(f, b, 1); // unknown meaning
- BlockRead(f, b, 1); // unknown meaning
- BlockRead(f, b, 1); // unknown meaning
- BlockRead(f, b, 1); // unknown meaning
- BlockRead(f, w, 2); // length of text
- for tmpI := 1 to w do
- begin
- BlockRead(f, b, 1);
- tmpName := tmpName + chr(b);
- end;
- DatTiles[index].haveName := true;
- DatTiles[index].itemName := tmpName;
- BlockRead(f, b, 1); // unknown meaning
- BlockRead(f, b, 1); // unknown meaning
- BlockRead(f, b, 1); // unknown meaning
- BlockRead(f, b, 1); // unknown meaning
- end;
- end; // end case
- BlockRead(f, optByte, 1); // next byte
- end; // end while
- if DatTiles[index].stackable or DatTiles[index].multiType or
- DatTiles[index].fluidContainer then
- begin
- DatTiles[index].haveExtraByte := true;
- end;
- if DatTiles[index].multiCharge then
- begin
- DatTiles[index].haveExtraByte := true;
- end;
- if DatTiles[index].alwaysOnTop then
- begin
- DatTiles[index].stackPriority := 3;
- end;
- if DatTiles[index].moreAlwaysOnTop then
- begin
- DatTiles[index].alwaysOnTop := true;
- DatTiles[index].stackPriority := 4;
- end;
- BlockRead(f, b, 1);
- lWidth := b;
- BlockRead(f, b, 1);
- lHeight := b;
- if (lWidth > 1) or (lHeight > 1) then
- begin
- // skip 1 byte
- BlockRead(f, b, 1);
- end;
- BlockRead(f, b, 1);
- lBlendframes := b;
- BlockRead(f, b, 1);
- lXdiv := b;
- BlockRead(f, b, 1);
- lYdiv := b;
- BlockRead(f, b, 1);
- lAnimcount := b;
- BlockRead(f, b, 1);
- lRare := b;
- if lRare > $1 then
- begin
- DatTiles[index].haveExtraByte2 := true;
- end;
- DatTiles[index].totalExtraBytes := 0;
- if DatTiles[index].haveExtraByte then
- inc(DatTiles[index].totalExtraBytes);
- if DatTiles[index].haveExtraByte2 then
- inc(DatTiles[index].totalExtraBytes);
- skipcount := (lWidth * lHeight * lBlendframes * lXdiv * lYdiv * lAnimcount * lRare * 2);
- for tmpI := 1 to skipcount do
- begin
- BlockRead(f, b, 2); //Read 2 bytes T9.83, not 1 as T9.44 version
- end;
- index := index + 1;
- until ( Eof(f) );
- CloseFile(f);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement