private void ParsePacket(InMessage message) { while (message.ReadPosition < message.Size) { var packetType = (TibiaCastPacketType)message.ReadByte(); switch (packetType) { case TibiaCastPacketType.CloseShopWindow: //this.g(ax); message.ReadByte(); break; case TibiaCastPacketType.Initialize: ParseInitialize(message); break; case TibiaCastPacketType.TibiaPackets: ParseTibiaPackets(message); break; case TibiaCastPacketType.Message: message.ReadString(); message.ReadString(); break; default: throw new Exception(string.Format("Unknown packet type ({0}) when reading TibiaCast file.", packetType)); } } }
private void ParseInitialize(InMessage message) { int count = message.ReadUShort(); for (int i = 0; i < count; i++) { var creature = new Creature(message.ReadUInt()); creature.Type = (CreatureType)message.ReadByte(); creature.Name = message.ReadString(); //Trace.WriteLine(String.Format("Creature[{0}]: {1}", i, creature.Name)); creature.Health = message.ReadByte(); var direction = (Direction)message.ReadByte(); creature.LookDirection = direction; creature.TurnDirection = direction; //Outfit creature.Outfit = message.ReadOutfit(); creature.LightLevel = message.ReadByte(); creature.LightColor = message.ReadByte(); creature.Speed = message.ReadUShort(); creature.Skull = message.ReadByte(); creature.Shield = message.ReadByte(); creature.Emblem = message.ReadByte(); creature.IsImpassable = message.ReadByte() == 0x01; client.BattleList.AddCreature(creature); } ParseTibiaPackets(message); }
private void ParseTile() { var tile = new OtTile(message.ReadLocation()); //Console.WriteLine("[Debug] Tile received, location: " + tile.Location); var thingCount = message.ReadByte(); for (int i = 0; i < thingCount; i++) { var thingType = message.ReadByte(); if (thingType == 0x01) //Creature { var id = message.ReadUInt(); var name = message.ReadString(); var type = (CreatureType)message.ReadByte(); if (type != CreatureType.PLAYER) { map.AddCreature(new OtCreature { Id = id, Name = name, Type = type, Location = tile.Location }); } } else { var id = message.ReadUShort(); var subType = message.ReadByte(); var itemType = items.GetItemBySpriteId(id); if (itemType != null) { var item = OtItem.Create(itemType); if (item.Type.IsStackable) { item.SetAttribute(OtItemAttribute.COUNT, subType); } else if (item.Type.Group == OtItemGroup.Splash || item.Type.Group == OtItemGroup.FluidContainer) { item.SetAttribute(OtItemAttribute.COUNT, OtConverter.TibiaFluidToOtFluid(subType)); } tile.AddItem(item); } } } if (map.GetTile(tile.Location) == null) { map.SetTile(tile); } }
private void ParseInitialize(InMessage message) { if (minorVersion >= 10) { message.ReadByte(); //? } int count = message.ReadUShort(); for (int i = 0; i < count; i++) { var creature = new Creature(message.ReadUInt()); creature.Type = (CreatureType)message.ReadByte(); creature.Name = message.ReadString(); //Trace.WriteLine(String.Format("Creature[{0}]: {1}", i, creature.Name)); creature.Health = message.ReadByte(); var direction = (Direction)message.ReadByte(); creature.LookDirection = direction; creature.TurnDirection = direction; //Outfit creature.Outfit = message.ReadOutfit(); creature.LightLevel = message.ReadByte(); creature.LightColor = message.ReadByte(); creature.Speed = message.ReadUShort(); creature.Skull = message.ReadByte(); creature.Shield = message.ReadByte(); creature.Emblem = message.ReadByte(); creature.IsImpassable = message.ReadByte() == 0x01; //10.20+ includes an extra 4 bytes per creature //These bytes could alter the read order, but since I don't know what they are for yet, I'll read them out of the way. message.ReadUInt(); //speech category? if (client.Version.Number >= ClientVersion.Version1036.Number) { message.ReadByte(); } client.BattleList.AddCreature(creature); } ParseTibiaPackets(message); }