Advertisement
Guest User

Untitled

a guest
May 8th, 2015
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 16.32 KB | None | 0 0
  1.      public enum DAT
  2.       {
  3.        Flag_Bank = 0,
  4.        Flag_Clip = 1,
  5.        Flag_Bottom = 2,
  6.        Flag_Top = 3,
  7.        Flag_Container = 4,  
  8.        Flag_Cumulative = 5,      
  9.        Flag_ForceUse = 6,
  10.        Flag_UseAble = 254,  
  11.        Flag_MultiUse = 7,      
  12.        Flag_Write = 8,        
  13.        Flag_WriteOnce = 9,
  14.        Flag_LiquidContainer = 10,      
  15.        Flag_LiquidPool = 11,
  16.        Flag_Unpass = 12,
  17.        Flag_Unmove = 13,
  18.        Flag_Unsight = 14,
  19.        Flag_Avoid = 15,
  20.        Flag_NOMOVEMENTANIMATION = 16,
  21.        Flag_Take = 17,
  22.        Flag_Hang = 18,
  23.        Flag_HookSouth = 19,
  24.        Flag_HookEast = 20,
  25.        Flag_Rotate = 21,
  26.        Flag_Light = 22,
  27.        Flag_DontHide = 23,
  28.        Flag_Translucent = 24,
  29.        Flag_Shift = 25,
  30.        Flag_Height = 26,
  31.        Flag_LyingObject = 27,
  32.        Flag_AnimateAlways = 28,
  33.        Flag_Automap = 29,
  34.        Flag_LensHelp = 30,
  35.        Flag_FullBank = 31,
  36.        Flag_IgnoreLook = 32,
  37.        Flag_Clothes = 33,
  38.        Flag_Market = 34,
  39.        Flag_DefaultAction = 35,
  40.        BreakFlag = 255,
  41.  
  42.       }
  43.         public int MaxItems;
  44.  
  45.         public enum MarketCategory : byte
  46.         {
  47.             Armors = 1,
  48.             Amulets = 2,
  49.             Boots = 3,
  50.             Containers = 4,
  51.             Decoration = 5,
  52.             Food = 6,
  53.             Helmets_Hats = 7,
  54.             Legs = 8,
  55.             Others = 9,
  56.             Potions = 10,
  57.             Rings = 11,
  58.             Runes = 12,
  59.             Shields = 13,
  60.             Tools = 14,
  61.             Valuables = 15,
  62.             Ammunition = 16,
  63.             Axes = 17,
  64.             Clubs = 18,
  65.             DistanceWeapons = 19,
  66.             Swords = 20,
  67.             Wands_Rods = 21,
  68.             MetaWeapons = 22
  69.             //all weapons
  70.         }
  71.  
  72.         public struct ItemData
  73.         {
  74.             public int ID;
  75.  
  76.             public bool isBank;
  77.             public int Waypoints;
  78.             public bool isClip;
  79.             public bool isBottom;
  80.             public bool isTop;
  81.             public bool isContainer;
  82.             public bool isCumulative;
  83.             public bool isUseAble;
  84.             public bool isForceUse;
  85.             public bool isMultiUse;
  86.             public bool isWriteable;
  87.             public int MaxTextLength;
  88.             public bool isWriteableOnce;
  89.             public bool isLiquidContainer;
  90.             public bool isLiquidPool;
  91.             public bool isUnpassable;
  92.             public bool isUnmoveable;
  93.             public bool isUnsight;
  94.             public bool isAvoid;
  95.             public bool isTakeable;
  96.             public bool isHangable;
  97.             public bool isHookSouth;
  98.             public bool isHookEast;
  99.             public bool isRotateable;
  100.             public bool noMovmentAction;
  101.             public bool isLight;
  102.             public int Brightness;
  103.             public int LightColor;
  104.             public bool isDontHide;
  105.             public bool isTranslucent;
  106.             public bool isDisplaced;
  107.             public int DisplacementX;
  108.             public int DisplacementY;
  109.             public bool isHeight;
  110.             public int Elevation;
  111.             public bool isLyingObject;
  112.             public bool isAnimateAlways;
  113.             public bool isAutomap;
  114.             public int isAutomapColor;
  115.             public bool isLensHelp;
  116.             public int LensHelp;
  117.             public bool isFullBank;
  118.             public bool isIgnoreLook;
  119.             public bool isCloth;
  120.             public bool FloorChangeUp;
  121.             public bool FloorChangeDown;
  122.             public bool RequireUse;
  123.             public bool RequireShovel;
  124.             public bool RequireRope;
  125.             public int ClothSlot;
  126.             public bool isMarket;
  127.             public MarketCategory MarketCategory;
  128.             public int MarketTradeAs;
  129.             public int MarketShowAs;
  130.             public string MarketName;
  131.             public int MarketRestrictProfession;
  132.             public int MarketRestrictLevel;
  133.             public bool DefaultAction;
  134.             public int Width;
  135.             public int Height;
  136.             public int ExactSize;
  137.             public int Layers;
  138.             public int PatternWidth;
  139.             public int PatternHeight;
  140.             public int PatternDepth;
  141.             public int Phases;
  142.             public int NumberOfSprites;
  143.  
  144.             public int[] Sprites;
  145.         }
  146.         private Client client;
  147.         private string path;
  148.         private List<ItemData> Objects;
  149.         public DatReader(Client _client)
  150.         {
  151.             client = _client;
  152.            path = Path.Combine(Path.GetDirectoryName(client.Process.MainModule.FileName), "Tibia.dat");
  153.            ParseDat(path);
  154.         }
  155.         public ItemData GetData(int id)
  156.         {
  157.             if (id >= 100 && id - 100 <= Objects.Count)
  158.             {
  159.  
  160.               //  return dataArray[id - 100];
  161.                 return Objects[id - 100];
  162.             }
  163.             return new ItemData();
  164.         }
  165.         public void ParseDat(string path)
  166.         {
  167.             string FileName = path;
  168.    
  169.             using (System.IO.BinaryReader BinaryReader = new System.IO.BinaryReader(System.IO.File.OpenRead(FileName)))
  170.             {
  171.                 uint DatVersion = BinaryReader.ReadUInt32();
  172.                 int ItemCount = BinaryReader.ReadUInt16();
  173.                 int OutfitCount = BinaryReader.ReadUInt16();
  174.                 int EffectCount = BinaryReader.ReadUInt16();
  175.                 int ProjectileCount = BinaryReader.ReadUInt16();
  176.                 int MaxID = ItemCount + OutfitCount + EffectCount + ProjectileCount;
  177.                 Objects = new List<ItemData>(MaxID);
  178.                 int ID = 100;
  179.                 DAT Flag = 0;
  180.  
  181.                 while (ID < MaxID)
  182.                 {
  183.                     ItemData CurrentObject = new ItemData();
  184.                     CurrentObject.ID = ID;
  185.                     do
  186.                     {
  187.                         Flag = (DAT)BinaryReader.ReadByte();
  188.                         switch (Flag)
  189.                         {
  190.                             case DAT.Flag_Bank:
  191.                                 CurrentObject.isBank = true;
  192.                                 CurrentObject.Waypoints = BinaryReader.ReadUInt16();
  193.                                 break;
  194.                             case DAT.Flag_Clip:
  195.                                 CurrentObject.isClip = true;
  196.                                 break;
  197.                             case DAT.Flag_Bottom:
  198.                                 CurrentObject.isBottom = true;
  199.                                 break;
  200.                             case DAT.Flag_Top:
  201.                                 CurrentObject.isTop = true;
  202.                                 break;
  203.                             case DAT.Flag_Container:
  204.                                 CurrentObject.isContainer = true;
  205.                                 break;
  206.                             case DAT.Flag_Cumulative:
  207.                                 CurrentObject.isCumulative = true;
  208.                                 break;
  209.                             case DAT.Flag_UseAble:
  210.                                 CurrentObject.isUseAble = true;
  211.                                 break;
  212.                             case DAT.Flag_ForceUse:
  213.                                 CurrentObject.isForceUse = true;
  214.                                 break;
  215.                             case DAT.Flag_MultiUse:
  216.                                 CurrentObject.isMultiUse = true;
  217.                                 break;
  218.                             case DAT.Flag_Write:
  219.                                 CurrentObject.isWriteable = true;
  220.                                 CurrentObject.MaxTextLength = BinaryReader.ReadUInt16();
  221.                                 break;
  222.                             case DAT.Flag_WriteOnce:
  223.                                 CurrentObject.isWriteableOnce = true;
  224.                                 CurrentObject.MaxTextLength = BinaryReader.ReadUInt16();
  225.                                 break;
  226.                             case DAT.Flag_LiquidContainer:
  227.                                 CurrentObject.isLiquidContainer = true;
  228.                                 break;
  229.                             case DAT.Flag_LiquidPool:
  230.                                 CurrentObject.isLiquidPool = true;
  231.                                 break;
  232.                             case DAT.Flag_Unpass:
  233.                                 CurrentObject.isUnpassable = true;
  234.                                 break;
  235.                             case DAT.Flag_Unmove:
  236.                                 CurrentObject.isUnmoveable = true;
  237.                                 break;
  238.                             case DAT.Flag_Unsight:
  239.                                 CurrentObject.isUnsight = true;
  240.                                 break;
  241.                             case DAT.Flag_Avoid:
  242.                                 CurrentObject.isAvoid = true;
  243.                                 break;
  244.                             case DAT.Flag_NOMOVEMENTANIMATION:
  245.                                 CurrentObject.noMovmentAction = true;
  246.                                 break;
  247.                             case DAT.Flag_Take:
  248.                                 CurrentObject.isTakeable = true;
  249.                                 break;
  250.                             case DAT.Flag_Hang:
  251.                                 CurrentObject.isHangable = true;
  252.                                 break;
  253.                             case DAT.Flag_HookSouth:
  254.                                 CurrentObject.isHookSouth = true;
  255.                                 break;
  256.                             case DAT.Flag_HookEast:
  257.                                 CurrentObject.isHookEast = true;
  258.                                 break;
  259.                             case DAT.Flag_Rotate:
  260.                                 CurrentObject.isRotateable = true;
  261.                                 break;
  262.                             case DAT.Flag_Light:
  263.                                 CurrentObject.isLight = true;
  264.                                 CurrentObject.Brightness = BinaryReader.ReadUInt16();
  265.                                 CurrentObject.LightColor = BinaryReader.ReadUInt16();
  266.                                 break;
  267.                             case DAT.Flag_DontHide:
  268.                                 CurrentObject.isDontHide = true;
  269.                                 break;
  270.                             case DAT.Flag_Translucent:
  271.                                 CurrentObject.isTranslucent = true;
  272.                                 break;
  273.                             case DAT.Flag_Shift:
  274.                                 CurrentObject.isDisplaced = true;
  275.                                 CurrentObject.DisplacementX = BinaryReader.ReadUInt16();
  276.                                 CurrentObject.DisplacementY = BinaryReader.ReadUInt16();
  277.                                 break;
  278.                             case DAT.Flag_Height:
  279.                                 CurrentObject.isHeight = true;
  280.                                 CurrentObject.Elevation = BinaryReader.ReadUInt16();
  281.                                 break;
  282.                             case DAT.Flag_LyingObject:
  283.                                 CurrentObject.isLyingObject = true;
  284.                                 break;
  285.                             case DAT.Flag_AnimateAlways:
  286.                                 CurrentObject.isAnimateAlways = true;
  287.                                 break;
  288.                             case DAT.Flag_Automap:
  289.                                 CurrentObject.isAutomap = true;
  290.                                 CurrentObject.isAutomapColor = BinaryReader.ReadUInt16();
  291.                                 break;
  292.                             case DAT.Flag_LensHelp:
  293.                                 CurrentObject.isLensHelp = true;
  294.                                 CurrentObject.LensHelp = BinaryReader.ReadUInt16();
  295.                                 break;
  296.                             case DAT.Flag_FullBank:
  297.                                 CurrentObject.isFullBank = true;
  298.                                 break;
  299.                             case DAT.Flag_IgnoreLook:
  300.                                 CurrentObject.isIgnoreLook = true;
  301.                                 break;
  302.                             case DAT.Flag_Clothes:
  303.                                 CurrentObject.isCloth = true;
  304.                                 CurrentObject.ClothSlot = BinaryReader.ReadUInt16();
  305.                                 break;
  306.                             case DAT.Flag_DefaultAction:
  307.                                 CurrentObject.DefaultAction = true;
  308.                                 int Action = BinaryReader.ReadUInt16();
  309.                                
  310.                            
  311.                                 break;
  312.                             case DAT.Flag_Market:
  313.                                 CurrentObject.isMarket = true;
  314.                                 CurrentObject.MarketCategory = (MarketCategory)BinaryReader.ReadUInt16();
  315.                                 CurrentObject.MarketTradeAs = BinaryReader.ReadUInt16();
  316.                                 CurrentObject.MarketShowAs = BinaryReader.ReadUInt16();
  317.                                 int MarketNameLength = BinaryReader.ReadUInt16();
  318.                                 CurrentObject.MarketName = System.Text.Encoding.GetEncoding("iso-8859-1").GetString(BinaryReader.ReadBytes(MarketNameLength));
  319.                                 CurrentObject.MarketRestrictProfession = BinaryReader.ReadUInt16();
  320.                                 CurrentObject.MarketRestrictLevel = BinaryReader.ReadUInt16();
  321.                                 break;
  322.                             case DAT.BreakFlag:
  323.                                
  324.                                 break;
  325.                             default:
  326.                                 break;
  327.                         }
  328.                     } while ((byte)Flag != 255);
  329.                     int FrameGroupCount = (ID > ItemCount && ID <= (ItemCount + OutfitCount)) ? BinaryReader.ReadByte() : 1;
  330.                     for (int k = 0; k < FrameGroupCount; k++)
  331.                     {
  332.                         int FrameGroupID = (ID > ItemCount && ID <= (ItemCount + OutfitCount)) ? BinaryReader.ReadByte() : 0;
  333.                  
  334.                     CurrentObject.Width = BinaryReader.ReadByte();
  335.                     CurrentObject.Height = BinaryReader.ReadByte();
  336.                     if (CurrentObject.Width > 1 | CurrentObject.Height > 1)
  337.                     {
  338.                         CurrentObject.ExactSize = BinaryReader.ReadByte();
  339.                     }
  340.  
  341.                     CurrentObject.Layers = BinaryReader.ReadByte();
  342.                     CurrentObject.PatternWidth = BinaryReader.ReadByte();
  343.                     CurrentObject.PatternHeight = BinaryReader.ReadByte();
  344.                     CurrentObject.PatternDepth = BinaryReader.ReadByte();
  345.                     CurrentObject.Phases = BinaryReader.ReadByte();
  346.                     if (CurrentObject.Phases > 1)
  347.                     {
  348.  
  349.                         int loc8 = 0;
  350.                         byte unkNown = BinaryReader.ReadByte();
  351.                         int unknown1 = BinaryReader.ReadInt32();
  352.                         byte unkNown2 = BinaryReader.ReadByte();
  353.                         while (loc8 < CurrentObject.Phases)
  354.                         {
  355.                             int unknown3 = BinaryReader.ReadInt32();
  356.                             int unknown4 = BinaryReader.ReadInt32();
  357.  
  358.                             loc8 += 1;
  359.  
  360.                         }
  361.                     }
  362.                     int numSpr = CurrentObject.Width * CurrentObject.Height;
  363.                     numSpr *= CurrentObject.Layers * CurrentObject.PatternWidth;
  364.                     numSpr *= CurrentObject.PatternHeight * CurrentObject.PatternDepth;
  365.                     numSpr *= CurrentObject.Phases;
  366.  
  367.                     CurrentObject.NumberOfSprites = numSpr;
  368.  
  369.                     CurrentObject.Sprites = (int[])Array.CreateInstance(typeof(int), CurrentObject.NumberOfSprites);
  370.                     for (int i = 0; i <= CurrentObject.NumberOfSprites - 1; i++)
  371.                     {
  372.                         CurrentObject.Sprites[i] = BinaryReader.ReadInt32();
  373.                     }
  374.                     }
  375.                     ID++;
  376.                     Objects.Add(CurrentObject);
  377.                 }
  378.             }
  379.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement