Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void ParseDat()
- {
- string FileName = null;
- Microsoft.Win32.OpenFileDialog OpenFileDialog = new Microsoft.Win32.OpenFileDialog() { DefaultExt = ".dat", Filter = "Dat file (*.dat)|*.dat|" + "All files|*.*" };
- if ((Boolean)OpenFileDialog.ShowDialog())
- FileName = OpenFileDialog.FileName;
- else
- return;
- using (System.IO.BinaryReader BinaryReader = new System.IO.BinaryReader(System.IO.File.OpenRead(FileName)))
- {
- uint DatVersion = BinaryReader.ReadUInt32();
- int ItemCount = BinaryReader.ReadUInt16();
- int OutfitCount = BinaryReader.ReadUInt16();
- int EffectCount = BinaryReader.ReadUInt16();
- int ProjectileCount = BinaryReader.ReadUInt16();
- int MaxID = ItemCount + OutfitCount + EffectCount + ProjectileCount;
- Objects = new List<DAT.ObjectData>(MaxID);
- int ID = 100;
- byte Flag = 0;
- while (ID < MaxID)
- {
- DAT.ObjectData CurrentObject = new DAT.ObjectData();
- CurrentObject.ID = ID;
- do
- {
- Flag = BinaryReader.ReadByte();
- switch (Flag)
- {
- case DAT.FLAG_BANK:
- CurrentObject.isBank = true;
- CurrentObject.Waypoints = BinaryReader.ReadUInt16();
- break;
- case DAT.FLAG_CLIP:
- CurrentObject.isClip = true;
- break;
- case DAT.FLAG_BOTTOM:
- CurrentObject.isBottom = true;
- break;
- case DAT.FLAG_TOP:
- CurrentObject.isTop = true;
- break;
- case DAT.FLAG_CONTAINER:
- CurrentObject.isContainer = true;
- break;
- case DAT.FLAG_CUMULATIVE:
- CurrentObject.isCumulative = true;
- break;
- case DAT.FLAG_USABLE:
- CurrentObject.isUsable = true;
- break;
- case DAT.FLAG_FORCEUSE:
- CurrentObject.isForceUse = true;
- break;
- case DAT.FLAG_MULTIUSE:
- CurrentObject.isMultiUse = true;
- break;
- case DAT.FLAG_WRITE:
- CurrentObject.isWriteable = true;
- CurrentObject.MaxTextLength = BinaryReader.ReadUInt16();
- break;
- case DAT.FLAG_WRITEONCE:
- CurrentObject.isWriteableOnce = true;
- CurrentObject.MaxTextLength = BinaryReader.ReadUInt16();
- break;
- case DAT.FLAG_LIQUIDCONTAINER:
- CurrentObject.isLiquidContainer = true;
- break;
- case DAT.FLAG_LIQUIDPOOL:
- CurrentObject.isLiquidPool = true;
- break;
- case DAT.FLAG_UNPASS:
- CurrentObject.isUnpassable = true;
- break;
- case DAT.FLAG_UNMOVE:
- CurrentObject.isUnmoveable = true;
- break;
- case DAT.FLAG_UNSIGHT:
- CurrentObject.isUnsight = true;
- break;
- case DAT.FLAG_AVOID:
- CurrentObject.isAvoid = true;
- break;
- case DAT.FLAG_NOMOVEMENTANIMATION:
- CurrentObject.isNoMovementAnimation = true;
- break;
- case DAT.FLAG_TAKE:
- CurrentObject.isTakeable = true;
- break;
- case DAT.FLAG_HANG:
- CurrentObject.isHangable = true;
- break;
- case DAT.FLAG_HOOKSOUTH:
- CurrentObject.isHookSouth = true;
- break;
- case DAT.FLAG_HOOKEAST:
- CurrentObject.isHookEast = true;
- break;
- case DAT.FLAG_ROTATE:
- CurrentObject.isRotateable = true;
- break;
- case DAT.FLAG_LIGHT:
- CurrentObject.isLight = true;
- CurrentObject.Brightness = BinaryReader.ReadUInt16();
- CurrentObject.LightColor = BinaryReader.ReadUInt16();
- break;
- case DAT.FLAG_DONTHIDE:
- CurrentObject.isDontHide = true;
- break;
- case DAT.FLAG_TRANSLUCENT:
- CurrentObject.isTranslucent = true;
- break;
- case DAT.FLAG_SHIFT:
- CurrentObject.isDisplaced = true;
- CurrentObject.DisplacementX = BinaryReader.ReadUInt16();
- CurrentObject.DisplacementY = BinaryReader.ReadUInt16();
- break;
- case DAT.FLAG_HEIGHT:
- CurrentObject.isHeight = true;
- CurrentObject.Elevation = BinaryReader.ReadUInt16();
- break;
- case DAT.FLAG_LYINGOBJECT:
- CurrentObject.isLyingObject = true;
- break;
- case DAT.FLAG_ANIMATEALWAYS:
- CurrentObject.isAnimateAlways = true;
- break;
- case DAT.FLAG_AUTOMAP:
- CurrentObject.isAutomap = true;
- CurrentObject.AutomapColor = BinaryReader.ReadUInt16();
- break;
- case DAT.FLAG_LENSHELP:
- CurrentObject.isLensHelp = true;
- CurrentObject.LensHelp = BinaryReader.ReadUInt16();
- break;
- case DAT.FLAG_FULLBANK:
- CurrentObject.isFullBank = true;
- break;
- case DAT.FLAG_IGNORELOOK:
- CurrentObject.isIgnoreLook = true;
- break;
- case DAT.FLAG_CLOTHES:
- CurrentObject.isCloth = true;
- CurrentObject.ClothSlot = BinaryReader.ReadUInt16();
- break;
- case DAT.FLAG_DEFAULTACTION:
- CurrentObject.isDefaultAction = true;
- int Action = BinaryReader.ReadUInt16();
- switch (Action)
- {
- case 0:
- CurrentObject.DefaultAction = DAT.DefaultAction.None;
- break;
- case 1:
- CurrentObject.DefaultAction = DAT.DefaultAction.Look;
- break;
- case 2:
- CurrentObject.DefaultAction = DAT.DefaultAction.Use;
- break;
- case 3:
- CurrentObject.DefaultAction = DAT.DefaultAction.Open;
- break;
- case 4:
- CurrentObject.DefaultAction = DAT.DefaultAction.AutoWalk_Highlight;
- break;
- default:
- break;
- }
- break;
- case DAT.FLAG_MARKET:
- CurrentObject.isMarket = true;
- CurrentObject.MarketCategory = (DAT.MarketCategory)BinaryReader.ReadUInt16();
- CurrentObject.MarketTradeAs = BinaryReader.ReadUInt16();
- CurrentObject.MarketShowAs = BinaryReader.ReadUInt16();
- int MarketNameLength = BinaryReader.ReadUInt16();
- CurrentObject.MarketName = System.Text.Encoding.GetEncoding("iso-8859-1").GetString(BinaryReader.ReadBytes(MarketNameLength));
- CurrentObject.MarketRestrictProfession = BinaryReader.ReadUInt16();
- CurrentObject.MarketRestrictLevel = BinaryReader.ReadUInt16();
- break;
- case 255:
- break;
- default:
- break;
- }
- } while (Flag != 255);
- int FrameGroupCount = (ID > ItemCount && ID <= (ItemCount + OutfitCount)) ? BinaryReader.ReadByte() : 1;
- CurrentObject.FrameGroups = new List<DAT.FrameGroup>(FrameGroupCount);
- for (int i = 0; i < FrameGroupCount; i++)
- {
- int FrameGroupID = (ID > ItemCount && ID <= (ItemCount + OutfitCount)) ? BinaryReader.ReadByte() : 0;
- DAT.FrameGroup FrameGroup = new DAT.FrameGroup();
- FrameGroup.Width = BinaryReader.ReadByte();
- FrameGroup.Height = BinaryReader.ReadByte();
- if (FrameGroup.Width > 1 || FrameGroup.Height > 1)
- FrameGroup.ExactSize = BinaryReader.ReadByte();
- else
- FrameGroup.ExactSize = 32;
- FrameGroup.Layers = BinaryReader.ReadByte();
- FrameGroup.PatternWidth = BinaryReader.ReadByte();
- FrameGroup.PatternHeight = BinaryReader.ReadByte();
- FrameGroup.PatternDepth = BinaryReader.ReadByte();
- FrameGroup.Phases = BinaryReader.ReadByte();
- if (FrameGroup.Phases > 1)
- {
- FrameGroup.isAnimation = true;
- FrameGroup.AnimationType = (DAT.AnimationType)BinaryReader.ReadByte();
- FrameGroup.AnimationLoopCount = BinaryReader.ReadInt32();
- FrameGroup.StartPhase = BinaryReader.ReadByte();
- FrameGroup.FrameDurations = new List<DAT.FrameDuration>(FrameGroup.Phases);
- for (int j = 0; j < FrameGroup.Phases; j++)
- {
- DAT.FrameDuration FrameDuration = new DAT.FrameDuration();
- FrameDuration.MinimumDuration = BinaryReader.ReadUInt32();
- FrameDuration.MaximumDuration = BinaryReader.ReadUInt32();
- FrameGroup.FrameDurations.Add(FrameDuration);
- }
- }
- FrameGroup.NumberOfSprites = FrameGroup.Width * FrameGroup.Height;
- FrameGroup.NumberOfSprites *= FrameGroup.Layers * FrameGroup.PatternWidth;
- FrameGroup.NumberOfSprites *= FrameGroup.PatternHeight * FrameGroup.PatternDepth;
- FrameGroup.NumberOfSprites *= FrameGroup.Phases;
- FrameGroup.SpriteIDs = new List<uint>(FrameGroup.NumberOfSprites);
- for (int x = 0; x < FrameGroup.NumberOfSprites; x++)
- FrameGroup.SpriteIDs.Add(BinaryReader.ReadUInt32());
- CurrentObject.FrameGroups.Add(FrameGroup);
- }
- ID++;
- Objects.Add(CurrentObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement