Exemple #1
0
		public bool LoadDat(string filename, SupportedClient client, bool extended)
		{
			FileStream fileStream = new FileStream(filename, FileMode.Open);
			try
			{
				using (BinaryReader reader = new BinaryReader(fileStream))
				{
					UInt32 datSignature = reader.ReadUInt32();
					if (client.DatSignature != datSignature)
					{
						string message = "PluginOne: Bad dat signature. Expected signature is {0:X} and loaded signature is {1:X}.";
						Trace.WriteLine(String.Format(message, client.DatSignature, datSignature));
						return false;
					}

					//get max id
					UInt16 itemCount = reader.ReadUInt16();
					UInt16 creatureCount = reader.ReadUInt16();
					UInt16 effectCount = reader.ReadUInt16();
					UInt16 distanceCount = reader.ReadUInt16();

					UInt16 minclientID = 100; //items starts at 100
					UInt16 maxclientID = itemCount;

					UInt16 id = minclientID;
					while (id <= maxclientID)
					{
						ClientItem item = new ClientItem();
						item.id = id;
						items[id] = item;

						// read the options until we find 0xff
						ItemFlag flag;
						do
						{
							flag = (ItemFlag)reader.ReadByte();

							switch (flag)
							{
								case ItemFlag.Ground:
									item.type = ItemType.Ground;
									item.groundSpeed = reader.ReadUInt16();
									break;

								case ItemFlag.GroundBorder:
									item.alwaysOnTop = true;
									item.alwaysOnTopOrder = 1;
									break;

								case ItemFlag.OnBottom:
									item.alwaysOnTop = true;
									item.alwaysOnTopOrder = 2;
									break;

								case ItemFlag.OnTop:
									item.alwaysOnTop = true;
									item.alwaysOnTopOrder = 3;
									break;

								case ItemFlag.Container:
									item.type = ItemType.Container;
									break;

								case ItemFlag.Stackable:
									item.isStackable = true;
									break;

								case ItemFlag.ForceUse:
									break;

								case ItemFlag.MultiUse:
									item.multiUse = true;
									break;

								case ItemFlag.HasCharges:
									break;

								case ItemFlag.Writable:
									item.isReadable = true;
									item.maxReadWriteChars = reader.ReadUInt16();
									break;

								case ItemFlag.WritableOnce:
									item.isReadable = true;
									item.maxReadChars = reader.ReadUInt16();
									break;

								case ItemFlag.FluidContainer:
									item.type = ItemType.Fluid;
									break;

								case ItemFlag.Fluid:
									item.type = ItemType.Splash;
									break;

								case ItemFlag.IsUnpassable:
									item.isUnpassable = true;
									break;

								case ItemFlag.IsUnmoveable:
									item.isMoveable = false;
									break;

								case ItemFlag.BlockMissiles:
									item.blockMissiles = true;
									break;

								case ItemFlag.BlockPathfinder:
									item.blockPathfinder = true;
									break;

								case ItemFlag.Pickupable:
									item.isPickupable = true;
									break;

								case ItemFlag.Hangable:
									item.isHangable = true;
									break;

								case ItemFlag.IsHorizontal:
									item.isHorizontal = true;
									break;

								case ItemFlag.IsVertical:
									item.isVertical = true;
									break;

								case ItemFlag.Rotatable:
									item.isRotatable = true;
									break;

								case ItemFlag.HasLight:
									item.lightLevel = reader.ReadUInt16();
									item.lightColor = reader.ReadUInt16();
									break;

								case ItemFlag.DontHide:
									break;

								case ItemFlag.FloorChange:
									break;

								case ItemFlag.HasOffset:
									reader.ReadUInt16(); // OffsetX
									reader.ReadUInt16(); // OffsetY
									break;

								case ItemFlag.HasElevation:
									item.hasElevation = true;
									reader.ReadUInt16(); // Height
									break;

								case ItemFlag.Lying:
									break;

								case ItemFlag.AnimateAlways:
									break;

								case ItemFlag.Minimap:
									item.minimapColor = reader.ReadUInt16();
									break;

								case ItemFlag.LensHelp:
									UInt16 opt = reader.ReadUInt16();
									if (opt == 1112)
									{
										item.isReadable = true;
									}
									break;

								case ItemFlag.FullGround:
									item.fullGround = true;
									break;

								case ItemFlag.IgnoreLook:
									item.ignoreLook = true;
									break;

								case ItemFlag.LastFlag:
									break;

								default:
									Trace.WriteLine(String.Format("PluginOne: Error while parsing, unknown flag 0x{0:X} at id {1}.", flag, id));
									return false;
							}

						} while (flag != ItemFlag.LastFlag);

						item.width = reader.ReadByte();
						item.height = reader.ReadByte();
						if ((item.width > 1) || (item.height > 1))
						{
							reader.BaseStream.Position++;
						}

						item.layers = reader.ReadByte();
						item.patternX = reader.ReadByte();
						item.patternY = reader.ReadByte();
						item.patternZ = reader.ReadByte();
						item.frames = reader.ReadByte();
						item.isAnimation = item.frames > 1;
						item.numSprites = (UInt32)item.width * item.height * item.layers * item.patternX * item.patternY * item.patternZ * item.frames;

						// Read the sprite ids
						for (UInt32 i = 0; i < item.numSprites; ++i)
						{
							uint spriteId;
							if (extended)
							{
								spriteId = reader.ReadUInt32();
							}
							else
							{
								spriteId = reader.ReadUInt16();
							}

							Sprite sprite;
							if (!sprites.TryGetValue(spriteId, out sprite))
							{
								sprite = new Sprite();
								sprite.id = spriteId;
								sprites[spriteId] = sprite;
							}
							item.spriteList.Add(sprite);
						}
						++id;
					}
				}
			}
			finally
			{
				fileStream.Close();
			}
			return true;
		}
Exemple #2
0
        public bool LoadDat(string filename, SupportedClient client, bool extended)
        {
            using (FileStream fileStream = new FileStream(filename, FileMode.Open))
            {
                BinaryReader reader = new BinaryReader(fileStream);
                uint datSignature = reader.ReadUInt32();
                if (client.DatSignature != datSignature)
                {
                    string message = "PluginTwo: Bad dat signature. Expected signature is {0:X} and loaded signature is {1:X}.";
                    Trace.WriteLine(String.Format(message, client.DatSignature, datSignature));
                    return false;
                }

                // get max id
                this.itemCount = reader.ReadUInt16();
                reader.ReadUInt16(); // skipping outfits count
                reader.ReadUInt16(); // skipping effects count
                reader.ReadUInt16(); // skipping missiles count

                ushort id = 100;
                while (id <= this.itemCount)
                {
                    ClientItem item = new ClientItem();
                    item.ID = id;
                    this.Items[id] = item;

                    // read the options until we find 0xff
                    ItemFlag flag;
                    do
                    {
                        flag = (ItemFlag)reader.ReadByte();

                        switch (flag)
                        {
                            case ItemFlag.Ground:
                                item.Type = ServerItemType.Ground;
                                item.GroundSpeed = reader.ReadUInt16();
                                break;

                            case ItemFlag.GroundBorder:
                                item.HasStackOrder = true;
                                item.StackOrder = TileStackOrder.Border;
                                break;

                            case ItemFlag.OnBottom:
                                item.HasStackOrder = true;
                                item.StackOrder = TileStackOrder.Bottom;
                                break;

                            case ItemFlag.OnTop:
                                item.HasStackOrder = true;
                                item.StackOrder = TileStackOrder.Top;
                                break;

                            case ItemFlag.Container:
                                item.Type = ServerItemType.Container;
                                break;

                            case ItemFlag.Stackable:
                                item.Stackable = true;
                                break;

                            case ItemFlag.ForceUse:
                                break;

                            case ItemFlag.MultiUse:
                                item.MultiUse = true;
                                break;

                            case ItemFlag.Writable:
                                item.Readable = true;
                                item.MaxReadWriteChars = reader.ReadUInt16();
                                break;

                            case ItemFlag.WritableOnce:
                                item.Readable = true;
                                item.MaxReadChars = reader.ReadUInt16();
                                break;

                            case ItemFlag.FluidContainer:
                                item.Type = ServerItemType.Fluid;
                                break;

                            case ItemFlag.Fluid:
                                item.Type = ServerItemType.Splash;
                                break;

                            case ItemFlag.IsUnpassable:
                                item.Unpassable = true;
                                break;

                            case ItemFlag.IsUnmoveable:
                                item.Movable = false;
                                break;

                            case ItemFlag.BlockMissiles:
                                item.BlockMissiles = true;
                                break;

                            case ItemFlag.BlockPathfinder:
                                item.BlockPathfinder = true;
                                break;

                            case ItemFlag.Pickupable:
                                item.Pickupable = true;
                                break;

                            case ItemFlag.Hangable:
                                item.Hangable = true;
                                break;

                            case ItemFlag.IsHorizontal:
                                item.HookEast = true;
                                break;

                            case ItemFlag.IsVertical:
                                item.HookSouth = true;
                                break;

                            case ItemFlag.Rotatable:
                                item.Rotatable = true;
                                break;

                            case ItemFlag.HasLight:
                                item.LightLevel = reader.ReadUInt16();
                                item.LightColor = reader.ReadUInt16();
                                break;

                            case ItemFlag.DontHide:
                                break;

                            case ItemFlag.Translucent:
                                break;

                            case ItemFlag.HasOffset:
                                reader.ReadUInt16(); // OffsetX
                                reader.ReadUInt16(); // OffsetY
                                break;

                            case ItemFlag.HasElevation:
                                item.HasElevation = true;
                                reader.ReadUInt16(); // Height
                                break;

                            case ItemFlag.Lying:
                                break;

                            case ItemFlag.AnimateAlways:
                                break;

                            case ItemFlag.Minimap:
                                item.MinimapColor = reader.ReadUInt16();
                                break;

                            case ItemFlag.LensHelp:
                                ushort opt = reader.ReadUInt16();
                                if (opt == 1112)
                                {
                                    item.Readable = true;
                                }
                                break;

                            case ItemFlag.FullGround:
                                item.FullGround = true;
                                break;

                            case ItemFlag.IgnoreLook:
                                item.IgnoreLook = true;
                                break;

                            case ItemFlag.Cloth:
                                reader.ReadUInt16();
                                break;

                            case ItemFlag.Market:
                                reader.ReadUInt16(); // category
                                item.TradeAs = reader.ReadUInt16(); // trade as
                                reader.ReadUInt16(); // show as
                                ushort nameLength = reader.ReadUInt16();
                                byte[] buffer = reader.ReadBytes(nameLength);
                                item.Name = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                                reader.ReadUInt16(); // profession
                                reader.ReadUInt16(); // level
                                break;

                            case ItemFlag.LastFlag:
                                break;

                            default:
                                Trace.WriteLine(String.Format("PluginTwo: Error while parsing, unknown flag 0x{0:X} at id {1}.", flag, id));
                                return false;
                        }
                    }
                    while (flag != ItemFlag.LastFlag);

                    item.Width = reader.ReadByte();
                    item.Height = reader.ReadByte();

                    if ((item.Width > 1) || (item.Height > 1))
                    {
                        reader.BaseStream.Position++;
                    }

                    item.Layers = reader.ReadByte();
                    item.PatternX = reader.ReadByte();
                    item.PatternY = reader.ReadByte();
                    item.PatternZ = reader.ReadByte();
                    item.Frames = reader.ReadByte();
                    item.IsAnimation = item.Frames > 1;
                    item.NumSprites = (uint)item.Width * item.Height * item.Layers * item.PatternX * item.PatternY * item.PatternZ * item.Frames;

                    // Read the sprite ids
                    for (uint i = 0; i < item.NumSprites; ++i)
                    {
                        uint spriteId;
                        if (extended)
                        {
                            spriteId = reader.ReadUInt32();
                        }
                        else
                        {
                            spriteId = reader.ReadUInt16();
                        }

                        Sprite sprite;
                        if (!sprites.TryGetValue(spriteId, out sprite))
                        {
                            sprite = new Sprite();
                            sprite.ID = spriteId;
                            sprites[spriteId] = sprite;
                        }

                        item.SpriteList.Add(sprite);
                    }

                    ++id;
                }
            }

            return true;
        }