Advertisement
Guest User

dat structure

a guest
Jan 14th, 2015
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.27 KB | None | 0 0
  1.         private void ParseDat()
  2.         {
  3.             string FileName = null;
  4.             Microsoft.Win32.OpenFileDialog OpenFileDialog = new Microsoft.Win32.OpenFileDialog() { DefaultExt = ".dat", Filter = "Dat file (*.dat)|*.dat|" + "All files|*.*" };
  5.             if ((Boolean)OpenFileDialog.ShowDialog())
  6.                 FileName = OpenFileDialog.FileName;
  7.             else
  8.                 return;
  9.  
  10.             using (System.IO.BinaryReader BinaryReader = new System.IO.BinaryReader(System.IO.File.OpenRead(FileName)))
  11.             {
  12.                 uint DatVersion = BinaryReader.ReadUInt32();
  13.                 int ItemCount = BinaryReader.ReadUInt16();
  14.                 int OutfitCount = BinaryReader.ReadUInt16();
  15.                 int EffectCount = BinaryReader.ReadUInt16();
  16.                 int ProjectileCount = BinaryReader.ReadUInt16();
  17.                 int MaxID = ItemCount + OutfitCount + EffectCount + ProjectileCount;
  18.                 Objects = new List<DAT.ObjectData>(MaxID);
  19.                 int ID = 100;
  20.                 byte Flag = 0;
  21.  
  22.                 while (ID < MaxID)
  23.                 {
  24.                     DAT.ObjectData CurrentObject = new DAT.ObjectData();
  25.                     CurrentObject.ID = ID;
  26.                     do
  27.                     {
  28.                         Flag = BinaryReader.ReadByte();
  29.                         switch (Flag)
  30.                         {
  31.                             case DAT.FLAG_BANK:
  32.                                 CurrentObject.isBank = true;
  33.                                 CurrentObject.Waypoints = BinaryReader.ReadUInt16();
  34.                                 break;
  35.                             case DAT.FLAG_CLIP:
  36.                                 CurrentObject.isClip = true;
  37.                                 break;
  38.                             case DAT.FLAG_BOTTOM:
  39.                                 CurrentObject.isBottom = true;
  40.                                 break;
  41.                             case DAT.FLAG_TOP:
  42.                                 CurrentObject.isTop = true;
  43.                                 break;
  44.                             case DAT.FLAG_CONTAINER:
  45.                                 CurrentObject.isContainer = true;
  46.                                 break;
  47.                             case DAT.FLAG_CUMULATIVE:
  48.                                 CurrentObject.isCumulative = true;
  49.                                 break;
  50.                             case DAT.FLAG_USABLE:
  51.                                 CurrentObject.isUsable = true;
  52.                                 break;
  53.                             case DAT.FLAG_FORCEUSE:
  54.                                 CurrentObject.isForceUse = true;
  55.                                 break;
  56.                             case DAT.FLAG_MULTIUSE:
  57.                                 CurrentObject.isMultiUse = true;
  58.                                 break;
  59.                             case DAT.FLAG_WRITE:
  60.                                 CurrentObject.isWriteable = true;
  61.                                 CurrentObject.MaxTextLength = BinaryReader.ReadUInt16();
  62.                                 break;
  63.                             case DAT.FLAG_WRITEONCE:
  64.                                 CurrentObject.isWriteableOnce = true;
  65.                                 CurrentObject.MaxTextLength = BinaryReader.ReadUInt16();
  66.                                 break;
  67.                             case DAT.FLAG_LIQUIDCONTAINER:
  68.                                 CurrentObject.isLiquidContainer = true;
  69.                                 break;
  70.                             case DAT.FLAG_LIQUIDPOOL:
  71.                                 CurrentObject.isLiquidPool = true;
  72.                                 break;
  73.                             case DAT.FLAG_UNPASS:
  74.                                 CurrentObject.isUnpassable = true;
  75.                                 break;
  76.                             case DAT.FLAG_UNMOVE:
  77.                                 CurrentObject.isUnmoveable = true;
  78.                                 break;
  79.                             case DAT.FLAG_UNSIGHT:
  80.                                 CurrentObject.isUnsight = true;
  81.                                 break;
  82.                             case DAT.FLAG_AVOID:
  83.                                 CurrentObject.isAvoid = true;
  84.                                 break;
  85.                             case DAT.FLAG_NOMOVEMENTANIMATION:
  86.                                 CurrentObject.isNoMovementAnimation = true;
  87.                                 break;
  88.                             case DAT.FLAG_TAKE:
  89.                                 CurrentObject.isTakeable = true;
  90.                                 break;
  91.                             case DAT.FLAG_HANG:
  92.                                 CurrentObject.isHangable = true;
  93.                                 break;
  94.                             case DAT.FLAG_HOOKSOUTH:
  95.                                 CurrentObject.isHookSouth = true;
  96.                                 break;
  97.                             case DAT.FLAG_HOOKEAST:
  98.                                 CurrentObject.isHookEast = true;
  99.                                 break;
  100.                             case DAT.FLAG_ROTATE:
  101.                                 CurrentObject.isRotateable = true;
  102.                                 break;
  103.                             case DAT.FLAG_LIGHT:
  104.                                 CurrentObject.isLight = true;
  105.                                 CurrentObject.Brightness = BinaryReader.ReadUInt16();
  106.                                 CurrentObject.LightColor = BinaryReader.ReadUInt16();
  107.                                 break;
  108.                             case DAT.FLAG_DONTHIDE:
  109.                                 CurrentObject.isDontHide = true;
  110.                                 break;
  111.                             case DAT.FLAG_TRANSLUCENT:
  112.                                 CurrentObject.isTranslucent = true;
  113.                                 break;
  114.                             case DAT.FLAG_SHIFT:
  115.                                 CurrentObject.isDisplaced = true;
  116.                                 CurrentObject.DisplacementX = BinaryReader.ReadUInt16();
  117.                                 CurrentObject.DisplacementY = BinaryReader.ReadUInt16();
  118.                                 break;
  119.                             case DAT.FLAG_HEIGHT:
  120.                                 CurrentObject.isHeight = true;
  121.                                 CurrentObject.Elevation = BinaryReader.ReadUInt16();
  122.                                 break;
  123.                             case DAT.FLAG_LYINGOBJECT:
  124.                                 CurrentObject.isLyingObject = true;
  125.                                 break;
  126.                             case DAT.FLAG_ANIMATEALWAYS:
  127.                                 CurrentObject.isAnimateAlways = true;
  128.                                 break;
  129.                             case DAT.FLAG_AUTOMAP:
  130.                                 CurrentObject.isAutomap = true;
  131.                                 CurrentObject.AutomapColor = BinaryReader.ReadUInt16();
  132.                                 break;
  133.                             case DAT.FLAG_LENSHELP:
  134.                                 CurrentObject.isLensHelp = true;
  135.                                 CurrentObject.LensHelp = BinaryReader.ReadUInt16();
  136.                                 break;
  137.                             case DAT.FLAG_FULLBANK:
  138.                                 CurrentObject.isFullBank = true;
  139.                                 break;
  140.                             case DAT.FLAG_IGNORELOOK:
  141.                                 CurrentObject.isIgnoreLook = true;
  142.                                 break;
  143.                             case DAT.FLAG_CLOTHES:
  144.                                 CurrentObject.isCloth = true;
  145.                                 CurrentObject.ClothSlot = BinaryReader.ReadUInt16();
  146.                                 break;
  147.                             case DAT.FLAG_DEFAULTACTION:
  148.                                 CurrentObject.isDefaultAction = true;
  149.                                 int Action = BinaryReader.ReadUInt16();
  150.                                 switch (Action)
  151.                                 {
  152.                                     case 0:
  153.                                         CurrentObject.DefaultAction = DAT.DefaultAction.None;
  154.                                         break;
  155.                                     case 1:
  156.                                         CurrentObject.DefaultAction = DAT.DefaultAction.Look;
  157.                                         break;
  158.                                     case 2:
  159.                                         CurrentObject.DefaultAction = DAT.DefaultAction.Use;
  160.                                         break;
  161.                                     case 3:
  162.                                         CurrentObject.DefaultAction = DAT.DefaultAction.Open;
  163.                                         break;
  164.                                     case 4:
  165.                                         CurrentObject.DefaultAction = DAT.DefaultAction.AutoWalk_Highlight;
  166.                                         break;
  167.                                     default:
  168.                                         break;
  169.                                 }
  170.                                 break;
  171.                             case DAT.FLAG_MARKET:
  172.                                 CurrentObject.isMarket = true;
  173.                                 CurrentObject.MarketCategory = (DAT.MarketCategory)BinaryReader.ReadUInt16();
  174.                                 CurrentObject.MarketTradeAs = BinaryReader.ReadUInt16();
  175.                                 CurrentObject.MarketShowAs = BinaryReader.ReadUInt16();
  176.                                 int MarketNameLength = BinaryReader.ReadUInt16();
  177.                                 CurrentObject.MarketName = System.Text.Encoding.GetEncoding("iso-8859-1").GetString(BinaryReader.ReadBytes(MarketNameLength));
  178.                                 CurrentObject.MarketRestrictProfession = BinaryReader.ReadUInt16();
  179.                                 CurrentObject.MarketRestrictLevel = BinaryReader.ReadUInt16();
  180.                                 break;
  181.                             case 255:
  182.                                 break;
  183.                             default:
  184.                                 break;
  185.                         }
  186.                     } while (Flag != 255);
  187.  
  188.                     int FrameGroupCount = (ID > ItemCount && ID <= (ItemCount + OutfitCount)) ? BinaryReader.ReadByte() : 1;
  189.                     CurrentObject.FrameGroups = new List<DAT.FrameGroup>(FrameGroupCount);
  190.                     for (int i = 0; i < FrameGroupCount; i++)
  191.                     {
  192.                         int FrameGroupID = (ID > ItemCount && ID <= (ItemCount + OutfitCount)) ? BinaryReader.ReadByte() : 0;
  193.                         DAT.FrameGroup FrameGroup = new DAT.FrameGroup();
  194.                         FrameGroup.Width = BinaryReader.ReadByte();
  195.                         FrameGroup.Height = BinaryReader.ReadByte();
  196.                         if (FrameGroup.Width > 1 || FrameGroup.Height > 1)
  197.                             FrameGroup.ExactSize = BinaryReader.ReadByte();
  198.                         else
  199.                             FrameGroup.ExactSize = 32;
  200.                         FrameGroup.Layers = BinaryReader.ReadByte();
  201.                         FrameGroup.PatternWidth = BinaryReader.ReadByte();
  202.                         FrameGroup.PatternHeight = BinaryReader.ReadByte();
  203.                         FrameGroup.PatternDepth = BinaryReader.ReadByte();
  204.                         FrameGroup.Phases = BinaryReader.ReadByte();
  205.                         if (FrameGroup.Phases > 1)
  206.                         {
  207.                             FrameGroup.isAnimation = true;
  208.                             FrameGroup.AnimationType = (DAT.AnimationType)BinaryReader.ReadByte();
  209.                             FrameGroup.AnimationLoopCount = BinaryReader.ReadInt32();
  210.                             FrameGroup.StartPhase = BinaryReader.ReadByte();
  211.                             FrameGroup.FrameDurations = new List<DAT.FrameDuration>(FrameGroup.Phases);
  212.                             for (int j = 0; j < FrameGroup.Phases; j++)
  213.                             {
  214.                                 DAT.FrameDuration FrameDuration = new DAT.FrameDuration();
  215.                                 FrameDuration.MinimumDuration = BinaryReader.ReadUInt32();
  216.                                 FrameDuration.MaximumDuration = BinaryReader.ReadUInt32();
  217.                                 FrameGroup.FrameDurations.Add(FrameDuration);
  218.                             }
  219.                         }
  220.                         FrameGroup.NumberOfSprites = FrameGroup.Width * FrameGroup.Height;
  221.                         FrameGroup.NumberOfSprites *= FrameGroup.Layers * FrameGroup.PatternWidth;
  222.                         FrameGroup.NumberOfSprites *= FrameGroup.PatternHeight * FrameGroup.PatternDepth;
  223.                         FrameGroup.NumberOfSprites *= FrameGroup.Phases;
  224.                         FrameGroup.SpriteIDs = new List<uint>(FrameGroup.NumberOfSprites);
  225.                         for (int x = 0; x < FrameGroup.NumberOfSprites; x++)
  226.                             FrameGroup.SpriteIDs.Add(BinaryReader.ReadUInt32());
  227.                         CurrentObject.FrameGroups.Add(FrameGroup);
  228.                     }
  229.                     ID++;
  230.                     Objects.Add(CurrentObject);
  231.                 }
  232.             }
  233.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement