Advertisement
Guest User

Untitled

a guest
Apr 13th, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unit datReader;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, addresses;
  8.  
  9.  
  10. procedure loadTibiaDat(filename: string);
  11. implementation
  12.  
  13.  
  14. procedure loadTibiaDat(filename: string);
  15. var
  16.   f: File;
  17.   index: integer;
  18.   tmpI, i, ID_OFFSET: integer;
  19.   w, nItems, nCreatures, nEffects, nMissile, nCount: word;
  20.   b, optByte, optbyte2: byte;
  21.   lWidth, lHeight, lBlendframes, lXdiv, lYdiv, lAnimcount, lRare, skipcount: integer;
  22.   tmpName: string;
  23. begin
  24.  
  25.   ID_OFFSET := 99;
  26.  
  27.   AssignFile(f, filename);
  28.   Reset(f, 1);
  29.  
  30.   BlockRead(f, i, 4);
  31.   BlockRead(f, nItems, 2);
  32.   BlockRead(f, nCreatures, 2);
  33.   BlockRead(f, nEffects, 2);
  34.   BlockRead(f, nMissile, 2);
  35.  
  36.   nCount := nItems + nCreatures + nEffects + nMissile;
  37.  
  38.   setlength( DatTiles, nCount );
  39.  
  40.   for index := 0 to nCount do
  41.   begin
  42.     DatTiles[index].isContainer := false;
  43.     DatTiles[index].RWInfo := 0;
  44.     DatTiles[index].fluidContainer := false;
  45.     DatTiles[index].stackable := false;
  46.     DatTiles[index].multiType := false;
  47.     DatTiles[index].useable := false;
  48.     DatTiles[index].notMoveable := false;
  49.     DatTiles[index].alwaysOnTop := false;
  50.     DatTiles[index].groundTile := false;
  51.     DatTiles[index].blocking := false;
  52.     DatTiles[index].blockPickupable := false;
  53.     DatTiles[index].pickupable := false;
  54.     DatTiles[index].blockingProjectile := false;
  55.     DatTiles[index].canWalkThrough := false;
  56.     DatTiles[index].noFloorChange := false;
  57.     DatTiles[index].isDoor := false;
  58.     DatTiles[index].isDoorWithLock := false;
  59.     DatTiles[index].speed := 0;
  60.     DatTiles[index].canDecay := false;
  61.     DatTiles[index].haveExtraByte := false;
  62.     DatTiles[index].haveExtraByte2 := false;
  63.     DatTiles[index].totalExtraBytes := 0;
  64.     DatTiles[index].isWater := false;
  65.     DatTiles[index].stackPriority := 0;
  66.     DatTiles[index].haveFish := false;
  67.     DatTiles[index].floorChangeUP := false;
  68.     DatTiles[index].floorChangeDOWN := false;
  69.     DatTiles[index].requireRightClick := false;
  70.     DatTiles[index].requireRope := false;
  71.     DatTiles[index].requireShovel := false;
  72.     DatTiles[index].isFood := false;
  73.     DatTiles[index].isField := false;
  74.     DatTiles[index].isDepot := false;
  75.     DatTiles[index].moreAlwaysOnTop := false;
  76.     DatTiles[index].usable2 := false;
  77.     DatTiles[index].multiCharge := false;
  78.     DatTiles[index].haveName := false;
  79.     DatTiles[index].itemName := '';
  80.   end;
  81.  
  82.   DatTiles[0].stackPriority := 0;
  83.   DatTiles[97].stackPriority := 2;
  84.   DatTiles[98].stackPriority := 2;
  85.   DatTiles[99].stackPriority := 2;
  86.   DatTiles[97].blocking := true;
  87.   DatTiles[98].blocking := true;
  88.   DatTiles[99].blocking := true;
  89.  
  90.   index := 100;
  91.  
  92.   repeat
  93.     // read next byte
  94.     BlockRead(f, optByte, 1);
  95.  
  96.     while (optByte <> $FF) and not eof(f) do
  97.     begin
  98.  
  99.       case optByte of
  100.  
  101.         $00:
  102.           begin
  103.             DatTiles[index].groundTile := true;
  104.  
  105.             // read speed
  106.             BlockRead(f, b, 1);
  107.             DatTiles[index].speed := b;
  108.  
  109.             // if speed is 0 then blocking
  110.             if b = 0 then
  111.               DatTiles[index].blocking := true;
  112.  
  113.             // ignore next byte
  114.             BlockRead(f, b, 1);
  115.           end;
  116.  
  117.         $01: DatTiles[index].moreAlwaysOnTop := true;
  118.         $02: DatTiles[index].alwaysOnTop := true;
  119.         $03:
  120.           begin
  121.             DatTiles[index].canWalkThrough := true;
  122.             DatTiles[index].alwaysOnTop := true;
  123.           end;
  124.  
  125.         $04: DatTiles[index].isContainer := true;
  126.         $05: DatTiles[index].stackable := true;
  127.         $06: DatTiles[index].useable := true;
  128.         $07: DatTiles[index].usable2 := true;
  129.         $08:
  130.           begin
  131.             DatTiles[index].RWInfo := 3;
  132.             BlockRead(f, b, 1); // max characters that can be written in it (0 unlimited)
  133.             BlockRead(f, b, 1); // max number of  newlines ? 0, 2, 4, 7
  134.           end;
  135.  
  136.         $09:
  137.           begin
  138.             DatTiles[index].RWInfo := 1;
  139.             BlockRead(f, b, 1); // max characters that can be written in it (0 unlimited)
  140.             BlockRead(f, b, 1); // always 4 max number of  newlines ?
  141.           end;
  142.  
  143.         $0A: DatTiles[index].fluidContainer := true;
  144.         $0B: DatTiles[index].multiType := true;
  145.         $0C: DatTiles[index].blocking := true;
  146.         $0D: DatTiles[index].notMoveable := true;
  147.         $0E: DatTiles[index].blockingProjectile := true;
  148.         $0F: ;// ignored
  149.         $10: DatTiles[index].pickupable := true;
  150.         $15:
  151.           begin
  152.             BlockRead(f, b, 1); // number of tiles around
  153.             BlockRead(f, b, 1); // 0
  154.             BlockRead(f, b, 1); // 215 for items , 208 for non items
  155.             BlockRead(f, b, 1); // ??
  156.           end;
  157.  
  158.         $11: ;// can see what is under (ladder holes, stairs holes etc)
  159.         $1E: DatTiles[index].noFloorChange := true;
  160.         $19:
  161.           begin
  162.             DatTiles[index].blockPickupable := false;
  163.             BlockRead(f, b, 1); // always 8
  164.             BlockRead(f, b, 1); // always 0
  165.           end;
  166.  
  167.         $14: ; // unknown
  168.         $18: BlockRead(f, i, 4); // dunno
  169.         $1C: BlockRead(f, w, 2); // 2 bytes for colour (b and b)
  170.         $17: DatTiles[index].floorChangeDOWN := true;
  171.         $1A: DatTiles[index].canDecay := false;
  172.         $1B: ;// wall items
  173.         $12: ;// action possible
  174.         $13: ;// walls 2 types of them same material (total 4 pairs)
  175.  
  176.         $1D:
  177.           begin
  178.             // line spot ...
  179.             BlockRead(f, optbyte2, 1);
  180.             case optbyte2 of
  181.               $4C:
  182.                 begin
  183.                   DatTiles[index].floorChangeUP := true;
  184.                   DatTiles[index].requireRightClick := true;
  185.                 end;
  186.               $4D: DatTiles[index].requireRightClick := true;
  187.               $4E:
  188.                 begin
  189.                   DatTiles[index].floorChangeUP := true;
  190.                   DatTiles[index].requireRope := true;
  191.                 end;
  192.               $4F: ;// switch
  193.               $50: DatTiles[index].isDoor := true;
  194.               $51: DatTiles[index].isDoorWithLock := true;
  195.               $52: DatTiles[index].floorChangeUP := true;
  196.               $53: DatTiles[index].isDepot := true;
  197.               $55: ;// trash
  198.               $56:
  199.                 begin
  200.                   DatTiles[index].floorChangeDOWN := true;
  201.                   DatTiles[index].requireShovel := true;
  202.                   DatTiles[index].alwaysOnTop := true;
  203.                   DatTiles[index].multiType := false;
  204.                 end;
  205.               $57: ; // items with special description?
  206.               $58: DatTiles[index].RWInfo := 1; // read only
  207.             end;
  208.             BlockRead(f, b, 1);
  209.           end;
  210.  
  211.         $1F: ;// new flag since 8.57
  212.         $20:
  213.           begin
  214.             BlockRead(f, w, 2); // unknown meaning
  215.           end;
  216.  
  217.         $16: ;// new flag since tibia 8.57
  218.         $21: // item group, something, and name (tibia 9.4)
  219.           begin
  220.             BlockRead(f, b, 1); // group 1
  221.             BlockRead(f, b, 1); // group 2
  222.             BlockRead(f, b, 1); // unknown meaning
  223.             BlockRead(f, b, 1); // unknown meaning
  224.             BlockRead(f, b, 1); // unknown meaning
  225.             BlockRead(f, b, 1); // unknown meaning
  226.  
  227.             BlockRead(f, w, 2); // length of text
  228.             for tmpI := 1 to w do
  229.             begin
  230.               BlockRead(f, b, 1);
  231.               tmpName := tmpName + chr(b);
  232.             end;
  233.  
  234.             DatTiles[index].haveName := true;
  235.             DatTiles[index].itemName := tmpName;
  236.  
  237.             BlockRead(f, b, 1); // unknown meaning
  238.             BlockRead(f, b, 1); // unknown meaning
  239.             BlockRead(f, b, 1); // unknown meaning
  240.             BlockRead(f, b, 1); // unknown meaning
  241.           end;
  242.       end; // end case
  243.  
  244.       BlockRead(f, optByte, 1); // next byte
  245.     end; // end while
  246.  
  247.     if DatTiles[index].stackable or DatTiles[index].multiType or
  248.        DatTiles[index].fluidContainer then
  249.     begin
  250.       DatTiles[index].haveExtraByte := true;
  251.     end;
  252.  
  253.     if DatTiles[index].multiCharge then
  254.     begin
  255.       DatTiles[index].haveExtraByte := true;
  256.     end;
  257.  
  258.     if DatTiles[index].alwaysOnTop then
  259.     begin
  260.       DatTiles[index].stackPriority := 3;
  261.     end;
  262.  
  263.     if DatTiles[index].moreAlwaysOnTop then
  264.     begin
  265.       DatTiles[index].alwaysOnTop := true;
  266.       DatTiles[index].stackPriority := 4;
  267.     end;
  268.  
  269.  
  270.  
  271.     BlockRead(f, b, 1);
  272.     lWidth := b;
  273.  
  274.     BlockRead(f, b, 1);
  275.     lHeight := b;
  276.  
  277.     if (lWidth > 1) or (lHeight > 1) then
  278.     begin
  279.       // skip 1 byte
  280.       BlockRead(f, b, 1);
  281.     end;
  282.  
  283.     BlockRead(f, b, 1);
  284.     lBlendframes := b;
  285.  
  286.     BlockRead(f, b, 1);
  287.     lXdiv := b;
  288.  
  289.     BlockRead(f, b, 1);
  290.     lYdiv := b;
  291.  
  292.     BlockRead(f, b, 1);
  293.     lAnimcount := b;
  294.  
  295.     BlockRead(f, b, 1);
  296.     lRare := b;
  297.  
  298.     if lRare > $1 then
  299.     begin
  300.       DatTiles[index].haveExtraByte2 := true;
  301.     end;
  302.     DatTiles[index].totalExtraBytes := 0;
  303.  
  304.     if DatTiles[index].haveExtraByte then
  305.       inc(DatTiles[index].totalExtraBytes);
  306.  
  307.     if DatTiles[index].haveExtraByte2 then
  308.       inc(DatTiles[index].totalExtraBytes);
  309.  
  310.  
  311.     skipcount := (lWidth * lHeight * lBlendframes * lXdiv * lYdiv * lAnimcount * lRare * 2);
  312.  
  313.     for tmpI := 1 to skipcount do
  314.     begin
  315.       BlockRead(f, b, 2);  //Read 2 bytes T9.83, not 1 as T9.44 version
  316.     end;
  317.  
  318.     index := index + 1;
  319.  
  320.  
  321.   until ( Eof(f) );
  322.  
  323.   CloseFile(f);
  324.  
  325. end;
  326.  
  327.  
  328. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement