private void ParseServerCreatureSpeak(InMessage message) { var statementId = message.ReadUInt(); var name = message.ReadString(); var level = message.ReadUShort(); var type = (MessageClasses)message.ReadByte(); Location location = null; switch (type) { case MessageClasses.SPEAK_SAY: case MessageClasses.SPEAK_WHISPER: case MessageClasses.SPEAK_YELL: case MessageClasses.SPEAK_MONSTER_SAY: case MessageClasses.SPEAK_MONSTER_YELL: case MessageClasses.SPEAK_SPELL: case MessageClasses.NPC_FROM: location = message.ReadLocation(); break; case MessageClasses.CHANNEL: case MessageClasses.CHANNEL_HIGHLIGHT: case MessageClasses.GAMEMASTER_CHANNEL: var channelId = message.ReadUShort(); break; default: break; } var text = message.ReadString(); client.Chat.OnCreatureSpeak(statementId, name, level, type, location, text); }
private void ParseClientSay(InMessage message) { string receiver = null; ushort channelId = 0; MessageClasses type = (MessageClasses)message.ReadByte(); switch (type) { case MessageClasses.PRIVATE_TO: case MessageClasses.GAMEMASTER_PRIVATE_TO: receiver = message.ReadString(); break; case MessageClasses.CHANNEL: case MessageClasses.CHANNEL_HIGHLIGHT: case MessageClasses.GAMEMASTER_CHANNEL: channelId = message.ReadUShort(); break; default: break; } string text = message.ReadString(); client.Chat.OnPlayerSpeak(receiver, channelId, type, text); }
private void ParseClientSay(InMessage message) { string receiver = null; ushort channelId = 0; MessageClasses type = (MessageClasses)message.ReadByte(); switch (type) { case MessageClasses.PRIVATE_TO: case MessageClasses.GAMEMASTER_PRIVATE_TO: receiver = message.ReadString(); break; case MessageClasses.CHANNEL: case MessageClasses.CHANNEL_HIGHLIGHT: case MessageClasses.GAMEMASTER_CHANNEL: channelId = message.ReadUShort(); break; default: break; } string text = message.ReadString(); client.Chat.OnPlayerSpeak(receiver, channelId, type, text); }
private void ParseServerCreatePrivateChannel(InMessage message) { var channelId = message.ReadUShort(); var name = message.ReadString(); message.ReadUShort(); message.ReadString(); message.ReadUShort(); }
private void ParseServerItemTextWindow(InMessage message) { var windowID = message.ReadUInt(); var itemID = message.ReadUShort(); var maxlen = message.ReadUShort(); var text = message.ReadString(); var writter = message.ReadString(); var date = message.ReadString(); }
private void ParseServerQuestPartList(InMessage message) { var questsID = message.ReadUShort(); var nMission = message.ReadByte(); for (uint i = 0; i < nMission; ++i) { var questsName = message.ReadString(); var questsDesc = message.ReadString(); } }
private void ParseServerVipState(InMessage message) { var creatureID = message.ReadUInt(); var name = message.ReadString(); if (client.Version.Number > ClientVersion.Version961.Number) { var unk1 = message.ReadString(); var unk2 = message.ReadUInt(); var unk3 = message.ReadByte(); } var unk4 = message.ReadByte(); //status? }
private void ParseServerOpenChannel(InMessage message) { var channelId = message.ReadUShort(); var name = message.ReadString(); var num = message.ReadUShort(); for (int i = 0; i < num; i++) { message.ReadString(); } num = message.ReadUShort(); for (int i = 0; i < num; i++) { message.ReadString(); } }
private void ParseServerSafeTradeRequest(InMessage message, bool ack) { var name = message.ReadString(); var count = message.ReadByte(); for (uint i = 0; i < count; ++i) { Item item = GetItem(message, ushort.MaxValue); } }
private void ParseServerChannelList(InMessage message) { var count = message.ReadByte(); for (uint i = 0; i < count; ++i) { var channelId = message.ReadUShort(); var name = message.ReadString(); } }
private void ParseServerOpenShopWindow(InMessage message) { var shop = new Shop(message.ReadString()); var size = message.ReadUShort(); for (uint i = 0; i < size; ++i) { var shopItem = new ShopItem(); shopItem.Id = message.ReadUShort(); shopItem.SubType = message.ReadByte(); shopItem.Name = message.ReadString(); shopItem.Weight = message.ReadUInt(); shopItem.BuyPrice = message.ReadUInt(); shopItem.SellPrice = message.ReadUInt(); shop.Items.Add(shopItem); } client.OnOpenShopWindow(shop); }
private void ParseServerQuestList(InMessage message) { var nQuests = message.ReadUShort(); for (uint i = 0; i < nQuests; ++i) { var questsID = message.ReadUShort(); var questsName = message.ReadString(); var questsState = message.ReadByte(); } }
private void ParseServerOutfitWindow(InMessage message) { message.ReadOutfit(); var nOutfits = message.ReadByte(); for (uint i = 0; i < nOutfits; ++i) { var outfitID = message.ReadUShort(); var name = message.ReadString(); var addons = message.ReadByte(); } int mountCount = message.ReadByte(); for (int i = 0; i < mountCount; ++i) { int mountId = message.ReadUShort(); // mount type string mountName = message.ReadString(); // mount name } }
private void ParseServerOpenContainer(InMessage message) { var containerId = message.ReadByte(); var containerItem = GetItem(message, ushort.MaxValue); var name = message.ReadString(); var capacity = message.ReadByte(); var hasParent = message.ReadByte(); var itemCount = message.ReadByte(); for (uint i = 0; i < itemCount; ++i) { Item item = GetItem(message, ushort.MaxValue); if (item == null) { throw new Exception("Container Open - !item"); } } }
private void ParseServerMarketDetail(InMessage message) { message.ReadUShort(); for (int i = 0; i < 15; i++) { message.ReadString(); } var num2 = message.ReadByte(); if (num2 > 0) { message.ReadBytes(num2 * 16); } num2 = message.ReadByte(); if (num2 > 0) { message.ReadBytes(num2 * 16); } }
private void ParseServerTextMessage(InMessage message) { var mClass = (MessageClasses)message.ReadByte(); switch (mClass) { case MessageClasses.DAMAGE_DEALT: case MessageClasses.DAMAGE_RECEIVED: case MessageClasses.DAMAGE_OTHERS: { Location location = message.ReadLocation(); var detailsValue = message.ReadUInt(); var detailsColor = message.ReadByte(); var detailsSubValue = message.ReadUInt(); var deatilsSubColor = message.ReadByte(); break; } case MessageClasses.EXPERIENCE: case MessageClasses.EXPERIENCE_OTHERS: case MessageClasses.HEALED: case MessageClasses.HEALED_OTHERS: { Location location = message.ReadLocation(); var detailsValue = message.ReadUInt(); var detailsColor = message.ReadByte(); break; } default: break; } var text = message.ReadString(); }
private void ReadMarketOffer(InMessage message, OfferKind offer, ushort request) { uint Timestamp = message.ReadUInt(); ushort Counter = message.ReadUShort(); ushort TypeId = 0; switch (request) { case 65534: case 65535: TypeId = message.ReadUShort(); break; default: TypeId = request; break; } ushort Amount = message.ReadUShort(); uint PiecePrice = message.ReadUInt(); string Character = ""; TerminationType TerminationType = Domain.TerminationType.Active; switch (request) { case 65534: break; case 65535: TerminationType = (TerminationType)message.ReadByte(); break; default: Character = message.ReadString(); break; } client.Market.Offers.Add(new Offer(new OfferId(Timestamp, Counter), offer, TypeId, Amount, PiecePrice, Character, TerminationType)); }
private void ParseServerSafeTradeRequest(InMessage message, bool ack) { var name = message.ReadString(); var count = message.ReadByte(); for (uint i = 0; i < count; ++i) { Item item = GetItem(message, ushort.MaxValue); } }
private void ParseServerAddMapMarker(InMessage message) { Location location = message.ReadLocation(); var icon = message.ReadByte(); var desc = message.ReadString(); }
private void ParseServerOpenShopWindow(InMessage message) { var shop = new Shop(message.ReadString()); var size = message.ReadUShort(); for (uint i = 0; i < size; ++i) { var shopItem = new ShopItem(); shopItem.Id = message.ReadUShort(); shopItem.SubType = message.ReadByte(); shopItem.Name = message.ReadString(); shopItem.Weight = message.ReadUInt(); shopItem.BuyPrice = message.ReadUInt(); shopItem.SellPrice = message.ReadUInt(); shop.Items.Add(shopItem); } client.OnOpenShopWindow(shop); }
private void ParseServerOutfitWindow(InMessage message) { message.ReadOutfit(); var nOutfits = message.ReadByte(); for (uint i = 0; i < nOutfits; ++i) { var outfitID = message.ReadUShort(); var name = message.ReadString(); var addons = message.ReadByte(); } int mountCount = message.ReadByte(); for (int i = 0; i < mountCount; ++i) { int mountId = message.ReadUShort(); // mount type string mountName = message.ReadString(); // mount name } }
private void ParseServerAddMapMarker(InMessage message) { Location location = message.ReadLocation(); var icon = message.ReadByte(); var desc = message.ReadString(); }
private void ParseServerHouseTextWindow(InMessage message) { var unk = message.ReadByte(); var windowId = message.ReadUInt(); var text = message.ReadString(); }
private void ParseServerFYIMessage(InMessage message) { message.ReadString(); }
private void ParseServerCreatureSpeak(InMessage message) { var statementId = message.ReadUInt(); var name = message.ReadString(); var level = message.ReadUShort(); var type = (MessageClasses)message.ReadByte(); Location location = null; switch (type) { case MessageClasses.SPEAK_SAY: case MessageClasses.SPEAK_WHISPER: case MessageClasses.SPEAK_YELL: case MessageClasses.SPEAK_MONSTER_SAY: case MessageClasses.SPEAK_MONSTER_YELL: case MessageClasses.SPEAK_SPELL: case MessageClasses.NPC_FROM: location = message.ReadLocation(); break; case MessageClasses.CHANNEL: case MessageClasses.CHANNEL_HIGHLIGHT: case MessageClasses.GAMEMASTER_CHANNEL: var channelId = message.ReadUShort(); break; default: break; } var text = message.ReadString(); client.Chat.OnCreatureSpeak(statementId, name, level, type, location, text); }
private void ParseServerCreatePrivateChannel(InMessage message) { var channelId = message.ReadUShort(); var name = message.ReadString(); message.ReadUShort(); message.ReadString(); message.ReadUShort(); }
private void ParseServerChannelList(InMessage message) { var count = message.ReadByte(); for (uint i = 0; i < count; ++i) { var channelId = message.ReadUShort(); var name = message.ReadString(); } }
private void ParseServerChannelEvent(InMessage message) { var channelId = message.ReadUShort(); var playerName = message.ReadString(); var channelEvent = message.ReadByte(); }
private void ParseServerAnimatedText(InMessage message) { Location location = message.ReadLocation(); var color = message.ReadByte(); var text = message.ReadString(); }
private void ParseServerQuestList(InMessage message) { var nQuests = message.ReadUShort(); for (uint i = 0; i < nQuests; ++i) { var questsID = message.ReadUShort(); var questsName = message.ReadString(); var questsState = message.ReadByte(); } }
private void ParseServerChannelEvent(InMessage message) { var channelId = message.ReadUShort(); var playerName = message.ReadString(); var channelEvent = message.ReadByte(); }
private void ParseServerItemTextWindow(InMessage message) { var windowID = message.ReadUInt(); var itemID = message.ReadUShort(); var maxlen = message.ReadUShort(); var text = message.ReadString(); var writter = message.ReadString(); var date = message.ReadString(); }
private void ParseServerMarketBrowser(InMessage message) { ushort num = message.ReadUShort(); if (num == 65535) { var count = message.ReadUInt(); for (int i = 0; i < count; i++) { message.ReadUInt(); message.ReadUShort(); message.ReadUShort(); message.ReadUShort(); message.ReadUInt(); message.ReadByte(); } count = message.ReadUInt(); for (int j = 0; j <= count; j++) { message.ReadUInt(); message.ReadUShort(); message.ReadUShort(); message.ReadUShort(); message.ReadUInt(); message.ReadByte(); } } else if (num == 65534) { var count = message.ReadUInt(); for (int k = 0; k <= count; k++) { message.ReadUInt(); message.ReadUShort(); message.ReadUShort(); message.ReadUShort(); message.ReadUInt(); } count = message.ReadUInt(); for (int l = 0; l <= count; l++) { message.ReadUInt(); message.ReadUShort(); message.ReadUShort(); message.ReadUShort(); message.ReadUInt(); } } else { var count = message.ReadUInt(); for (int m = 0; m < count; m++) { message.ReadUInt(); message.ReadUShort(); message.ReadUShort(); message.ReadUInt(); message.ReadString(); } count = message.ReadUInt(); for (int n = 0; n < count; n++) { message.ReadUInt(); message.ReadUShort(); message.ReadUShort(); message.ReadUInt(); message.ReadString(); } } }
private void ParseServerOpenPrivatePlayerChat(InMessage message) { var name = message.ReadString(); }
private void ParseServerVipState(InMessage message) { var creatureID = message.ReadUInt(); var name = message.ReadString(); if (client.Version.Number > ClientVersion.Version961.Number) { var unk1 = message.ReadString(); var unk2 = message.ReadUInt(); var unk3 = message.ReadByte(); } var unk4 = message.ReadByte(); //status? }
private void ParseServerWaitingList(InMessage message) { message.ReadString(); message.ReadByte(); }
private void ParseServerTextMessage(InMessage message) { var mClass = (MessageClasses)message.ReadByte(); switch (mClass) { case MessageClasses.DAMAGE_DEALT: case MessageClasses.DAMAGE_RECEIVED: case MessageClasses.DAMAGE_OTHERS: { Location location = message.ReadLocation(); var detailsValue = message.ReadUInt(); var detailsColor = message.ReadByte(); var detailsSubValue = message.ReadUInt(); var deatilsSubColor = message.ReadByte(); break; } case MessageClasses.EXPERIENCE: case MessageClasses.EXPERIENCE_OTHERS: case MessageClasses.HEALED: case MessageClasses.HEALED_OTHERS: { Location location = message.ReadLocation(); var detailsValue = message.ReadUInt(); var detailsColor = message.ReadByte(); break; } default: break; } var text = message.ReadString(); }
private void ParseServerHouseTextWindow(InMessage message) { var unk = message.ReadByte(); var windowId = message.ReadUInt(); var text = message.ReadString(); }
private void ParseServerAnimatedText(InMessage message) { Location location = message.ReadLocation(); var color = message.ReadByte(); var text = message.ReadString(); }
private Thing GetThing(InMessage message) { //get thing type var thingId = message.ReadUShort(); if (thingId == 0x0061 || thingId == 0x0062) { //creatures Creature creature = null; if (thingId == 0x0062) { creature = client.BattleList.GetCreature(message.ReadUInt()); if (creature == null) throw new Exception("[GetThing] (0x0062) Can't find the creature in the battle list."); creature.Health = message.ReadByte(); } else if (thingId == 0x0061) { //creature is not known client.BattleList.RemoveCreature(message.ReadUInt()); creature = new Creature(message.ReadUInt()); client.BattleList.AddCreature(creature); creature.Type = (CreatureType)message.ReadByte(); creature.Name = message.ReadString(); creature.Health = message.ReadByte(); } var direction = (Direction)message.ReadByte(); creature.LookDirection = direction; creature.TurnDirection = direction; creature.Outfit = message.ReadOutfit(); creature.LightLevel = message.ReadByte(); creature.LightColor = message.ReadByte(); creature.Speed = message.ReadUShort(); creature.Skull = message.ReadByte(); creature.Shield = message.ReadByte(); if (thingId == 0x0061) // emblem is sent only in packet type 0x61 creature.Emblem = message.ReadByte(); creature.IsImpassable = message.ReadBool(); return creature; } else if (thingId == 0x0063) { Creature creature = client.BattleList.GetCreature(message.ReadUInt()); if (creature == null) throw new Exception("[GetThing] (0x0063) Can't find the creature in the battle list."); creature.TurnDirection = (Direction)message.ReadByte(); creature.IsImpassable = message.ReadBool(); return creature; } else return GetItem(message, thingId); }
private void ParseServerOpenPrivatePlayerChat(InMessage message) { var name = message.ReadString(); }
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); }
private void ParseServerOpenContainer(InMessage message) { var containerId = message.ReadByte(); var containerItem = GetItem(message, ushort.MaxValue); var name = message.ReadString(); var capacity = message.ReadByte(); var hasParent = message.ReadByte(); var itemCount = message.ReadByte(); for (uint i = 0; i < itemCount; ++i) { Item item = GetItem(message, ushort.MaxValue); if (item == null) throw new Exception("Container Open - !item"); } }
private void ParseServerLoginMessage() { #if DEBUG_PROXY Trace.WriteLine("[DEBUG] Proxy [ParseServerLoginMessage]"); #endif serverInMessage.ReadPosition = 2; if (Adler.Generate(serverInMessage) != serverInMessage.ReadChecksum()) { throw new Exception("Wrong checksum."); } Xtea.Decrypt(serverInMessage, xteaKey); serverInMessage.Size = serverInMessage.ReadInternalHead() + 8; serverInMessage.ReadPosition = 8; clientOutMessage.Reset(); Array.Copy(serverInMessage.Buffer, clientOutMessage.Buffer, serverInMessage.Size); clientOutMessage.Size = serverInMessage.Size; while (serverInMessage.ReadPosition < serverInMessage.Size) { byte cmd = serverInMessage.ReadByte(); switch (cmd) { case 0x0A: //Error message var msg = serverInMessage.ReadString(); break; case 0x0B: //For your information serverInMessage.ReadString(); break; case 0x14: //MOTD serverInMessage.ReadString(); break; case 0x1E: //Patching exe/dat/spr messages case 0x1F: case 0x20: //DisconnectClient(0x0A, "A new client is avalible, please download it first!"); break; case 0x28: //Select other login server //selectedLoginServer = random.Next(0, loginServers.Length - 1); break; case 0x64: //character list int nChar = (int)serverInMessage.ReadByte(); charList = new CharacterLoginInfo[nChar]; for (int i = 0; i < nChar; i++) { charList[i].CharName = serverInMessage.ReadString(); charList[i].WorldName = serverInMessage.ReadString(); clientOutMessage.WriteAt(new byte[] { 127, 0, 0, 1 }, serverInMessage.ReadPosition); charList[i].WorldIP = serverInMessage.ReadUInt(); clientOutMessage.WriteAt(BitConverter.GetBytes((ushort)worldClientPort), serverInMessage.ReadPosition); charList[i].WorldPort = serverInMessage.ReadUShort(); } break; default: break; } } clientOutMessage.WriteInternalHead(); Xtea.Encrypt(clientOutMessage, xteaKey); Adler.Generate(clientOutMessage, true); clientOutMessage.WriteHead(); SendToClient(clientOutMessage); }
private void ParseServerVipState(InMessage message) { var creatureID = message.ReadUInt(); var name = message.ReadString(); if (client.Version.Number > ClientVersion.Version961.Number) { var description = message.ReadString(); var icon = message.ReadUInt(); var notifyAtLogin = message.ReadByte().Equals(0x1); } var connectionStatus = message.ReadByte(); }
private void ParseServerLoginMessage() { #if DEBUG_PROXY Trace.WriteLine("[DEBUG] Proxy [ParseServerLoginMessage]"); #endif serverInMessage.ReadPosition = 2; if (Adler.Generate(serverInMessage) != serverInMessage.ReadChecksum()) { throw new Exception("Wrong checksum."); } Xtea.Decrypt(serverInMessage, xteaKey); serverInMessage.Size = serverInMessage.ReadInternalHead() + 8; serverInMessage.ReadPosition = 8; clientOutMessage.Reset(); Array.Copy(serverInMessage.Buffer, clientOutMessage.Buffer, serverInMessage.Size); clientOutMessage.Size = serverInMessage.Size; while (serverInMessage.ReadPosition < serverInMessage.Size) { byte cmd = serverInMessage.ReadByte(); switch (cmd) { case 0x0A: //Error message var msg = serverInMessage.ReadString(); break; case 0x0B: //For your information serverInMessage.ReadString(); break; case 0x14: //MOTD serverInMessage.ReadString(); break; case 0x1E: //Patching exe/dat/spr messages case 0x1F: case 0x20: //DisconnectClient(0x0A, "A new client is avalible, please download it first!"); break; case 0x28: //Select other login server //selectedLoginServer = random.Next(0, loginServers.Length - 1); break; case 0x64: //character list if (client.Version.Number <= ClientVersion.Version1011.Number) { int nChar = (int)serverInMessage.ReadByte(); charList = new CharacterLoginInfo[nChar]; for (int i = 0; i < nChar; i++) { charList[i].CharName = serverInMessage.ReadString(); charList[i].WorldName = serverInMessage.ReadString(); clientOutMessage.WriteAt(new byte[] { 127, 0, 0, 1 }, serverInMessage.ReadPosition); charList[i].WorldIP = serverInMessage.ReadUInt(); clientOutMessage.WriteAt(BitConverter.GetBytes((ushort)worldClientPort), serverInMessage.ReadPosition); charList[i].WorldPort = serverInMessage.ReadUShort(); if (client.Version.Number >= ClientVersion.Version981.Number) { serverInMessage.ReadByte(); //isPreviewWorld } } if (client.Version.Number >= ClientVersion.Version1011.Number) { serverInMessage.ReadUShort(); //PremiumTime } } else if (client.Version.Number >= ClientVersion.Version1012.Number) { clientOutMessage.WritePosition = serverInMessage.ReadPosition; byte nWorlds = serverInMessage.ReadByte(); clientOutMessage.WriteByte(nWorlds); WorldLoginInfo[] worldList = new WorldLoginInfo[nWorlds]; for (byte i = 0; i < nWorlds; i++) { worldList[i].ID = serverInMessage.ReadByte(); clientOutMessage.WriteByte(worldList[i].ID); worldList[i].Name = serverInMessage.ReadString(); clientOutMessage.WriteString(worldList[i].Name); worldList[i].Hostname = serverInMessage.ReadString(); clientOutMessage.WriteString("127.0.0.1"); worldList[i].Port = serverInMessage.ReadUShort(); clientOutMessage.WriteUShort((ushort)worldClientPort); worldList[i].IsPreviewWorld = serverInMessage.ReadBool(); clientOutMessage.WriteByte(Convert.ToByte(worldList[i].IsPreviewWorld)); } byte nChars = serverInMessage.ReadByte(); clientOutMessage.WriteByte(nChars); charList = new CharacterLoginInfo[nChars]; for (byte j = 0; j < nChars; j++) { byte WorldID = serverInMessage.ReadByte(); clientOutMessage.WriteByte(WorldID); charList[j].CharName = serverInMessage.ReadString(); clientOutMessage.WriteString(charList[j].CharName); charList[j].WorldName = worldList[WorldID].Name; charList[j].WorldIP = BitConverter.ToUInt32(Dns.GetHostAddresses(worldList[WorldID].Hostname)[0].GetAddressBytes(), 0); charList[j].WorldPort = worldList[WorldID].Port; charList[j].WorldIPString = worldList[WorldID].Hostname; } ushort PremiumTime = serverInMessage.ReadUShort(); clientOutMessage.WriteUShort(PremiumTime); clientOutMessage.Size = clientOutMessage.WritePosition; } break; default: break; } } clientOutMessage.WriteInternalHead(); Xtea.Encrypt(clientOutMessage, xteaKey); Adler.Generate(clientOutMessage, true); clientOutMessage.WriteHead(); SendToClient(clientOutMessage); }
private void ParseServerMarketBrowser(InMessage message) { ushort num = message.ReadUShort(); if (num == 65535) { var count = message.ReadUInt(); for (int i = 0; i < count; i++) { message.ReadUInt(); message.ReadUShort(); message.ReadUShort(); message.ReadUShort(); message.ReadUInt(); message.ReadByte(); } count = message.ReadUInt(); for (int j = 0; j <= count; j++) { message.ReadUInt(); message.ReadUShort(); message.ReadUShort(); message.ReadUShort(); message.ReadUInt(); message.ReadByte(); } } else if (num == 65534) { var count = message.ReadUInt(); for (int k = 0; k <= count; k++) { message.ReadUInt(); message.ReadUShort(); message.ReadUShort(); message.ReadUShort(); message.ReadUInt(); } count = message.ReadUInt(); for (int l = 0; l <= count; l++) { message.ReadUInt(); message.ReadUShort(); message.ReadUShort(); message.ReadUShort(); message.ReadUInt(); } } else { var count = message.ReadUInt(); for (int m = 0; m < count; m++) { message.ReadUInt(); message.ReadUShort(); message.ReadUShort(); message.ReadUInt(); message.ReadString(); } count = message.ReadUInt(); for (int n = 0; n < count; n++) { message.ReadUInt(); message.ReadUShort(); message.ReadUShort(); message.ReadUInt(); message.ReadString(); } } }
private void ParseServerQuestPartList(InMessage message) { var questsID = message.ReadUShort(); var nMission = message.ReadByte(); for (uint i = 0; i < nMission; ++i) { var questsName = message.ReadString(); var questsDesc = message.ReadString(); } }
private void ParseServerMarketDetail(InMessage message) { message.ReadUShort(); for (int i = 0; i < 15; i++) message.ReadString(); var num2 = message.ReadByte(); if (num2 > 0) message.ReadBytes(num2 * 16); num2 = message.ReadByte(); if (num2 > 0) message.ReadBytes(num2 * 16); }
private void ParseServerOpenChannel(InMessage message) { var channelId = message.ReadUShort(); var name = message.ReadString(); var num = message.ReadUShort(); for (int i = 0; i < num; i++) message.ReadString(); num = message.ReadUShort(); for (int i = 0; i < num; i++) message.ReadString(); }
private void ParseServerWaitingList(InMessage message) { message.ReadString(); message.ReadByte(); }
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 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 ParseServerErrorMessage(InMessage message) { message.ReadString(); }
private void ParseServerLoginMessage() { #if DEBUG_PROXY Trace.WriteLine("[DEBUG] Proxy [ParseServerLoginMessage]"); #endif serverInMessage.ReadPosition = 2; if (Adler.Generate(serverInMessage) != serverInMessage.ReadChecksum()) { throw new Exception("Wrong checksum."); } Xtea.Decrypt(serverInMessage, xteaKey); serverInMessage.Size = serverInMessage.ReadInternalHead() + 8; serverInMessage.ReadPosition = 8; clientOutMessage.Reset(); Array.Copy(serverInMessage.Buffer, clientOutMessage.Buffer, serverInMessage.Size); clientOutMessage.Size = serverInMessage.Size; while (serverInMessage.ReadPosition < serverInMessage.Size) { byte cmd = serverInMessage.ReadByte(); switch (cmd) { case 0x0A: //Error message var msg = serverInMessage.ReadString(); break; case 0x0B: //For your information serverInMessage.ReadString(); break; case 0x0C: //token succes case 0x0D: //token error serverInMessage.ReadByte(); break; case 0x11: //update serverInMessage.ReadString(); break; case 0x14: //MOTD serverInMessage.ReadString(); break; case 0x1E: //Patching exe/dat/spr messages case 0x1F: case 0x20: //DisconnectClient(0x0A, "A new client is avalible, please download it first!"); break; case 0x28: //session key serverInMessage.ReadString(); break; case 0x64: //character list if (client.Version.Number <= ClientVersion.Version1011.Number) { int nChar = (int)serverInMessage.ReadByte(); charList = new CharacterLoginInfo[nChar]; for (int i = 0; i < nChar; i++) { charList[i].CharName = serverInMessage.ReadString(); charList[i].WorldName = serverInMessage.ReadString(); clientOutMessage.WriteAt(new byte[] { 127, 0, 0, 1 }, serverInMessage.ReadPosition); charList[i].WorldIP = serverInMessage.ReadUInt(); clientOutMessage.WriteAt(BitConverter.GetBytes((ushort)worldClientPort), serverInMessage.ReadPosition); charList[i].WorldPort = serverInMessage.ReadUShort(); if (client.Version.Number >= ClientVersion.Version981.Number) { serverInMessage.ReadByte(); //isPreviewWorld } } if (client.Version.Number >= ClientVersion.Version1011.Number) { serverInMessage.ReadUShort(); //PremiumTime } } else if (client.Version.Number >= ClientVersion.Version1012.Number) { clientOutMessage.WritePosition = serverInMessage.ReadPosition; byte nWorlds = serverInMessage.ReadByte(); clientOutMessage.WriteByte(nWorlds); WorldLoginInfo[] worldList = new WorldLoginInfo[nWorlds]; for (byte i = 0; i < nWorlds; i++) { worldList[i].ID = serverInMessage.ReadByte(); clientOutMessage.WriteByte(worldList[i].ID); worldList[i].Name = serverInMessage.ReadString(); clientOutMessage.WriteString(worldList[i].Name); worldList[i].Hostname = serverInMessage.ReadString(); clientOutMessage.WriteString("127.0.0.1"); worldList[i].Port = serverInMessage.ReadUShort(); clientOutMessage.WriteUShort((ushort)worldClientPort); worldList[i].IsPreviewWorld = serverInMessage.ReadBool(); clientOutMessage.WriteByte(Convert.ToByte(worldList[i].IsPreviewWorld)); } byte nChars = serverInMessage.ReadByte(); clientOutMessage.WriteByte(nChars); charList = new CharacterLoginInfo[nChars]; for (byte j = 0; j < nChars; j++) { byte WorldID = serverInMessage.ReadByte(); clientOutMessage.WriteByte(WorldID); charList[j].CharName = serverInMessage.ReadString(); clientOutMessage.WriteString(charList[j].CharName); charList[j].WorldName = worldList[WorldID].Name; charList[j].WorldIP = BitConverter.ToUInt32(Dns.GetHostAddresses(worldList[WorldID].Hostname)[0].GetAddressBytes(), 0); charList[j].WorldPort = worldList[WorldID].Port; charList[j].WorldIPString = worldList[WorldID].Hostname; } /** * Not very accurately named variables, but I'll settle for some pseudocode in case of futher implementations * * if version < 10.80: * ushort PremiumTime * else if version < 10.82 * bool isPremium * uint PremiumTime (In seconds from epoch - don't quote me on this :D) * else if version >= 10.82 * byte AccountStatus (0 = normal, 1 = frozen, 2 = suspended) * bool isPremium * uint PremiumTime */ ushort PremiumTime = serverInMessage.ReadUShort(); clientOutMessage.WriteUShort(PremiumTime); if (client.Version.Number >= ClientVersion.Version1090.Number) // From 10.80 - but haven't added 10.80 support. { uint PremiumSeconds = serverInMessage.ReadUInt(); // Not sure about this name. clientOutMessage.WriteUInt(PremiumSeconds); } clientOutMessage.Size = clientOutMessage.WritePosition; } break; default: break; } } clientOutMessage.WriteInternalHead(); Xtea.Encrypt(clientOutMessage, xteaKey); Adler.Generate(clientOutMessage, true); clientOutMessage.WriteHead(); SendToClient(clientOutMessage); }
private Thing GetThing(InMessage message) { //get thing type var thingId = message.ReadUShort(); if (thingId == 0x0061 || thingId == 0x0062) { //creatures Creature creature = null; if (thingId == 0x0062) { creature = client.BattleList.GetCreature(message.ReadUInt()); if (creature == null) { throw new Exception("[GetThing] (0x0062) Can't find the creature in the battle list."); } creature.Health = message.ReadByte(); } else if (thingId == 0x0061) { //creature is not known client.BattleList.RemoveCreature(message.ReadUInt()); creature = new Creature(message.ReadUInt()); client.BattleList.AddCreature(creature); creature.Type = (CreatureType)message.ReadByte(); creature.Name = message.ReadString(); creature.Health = message.ReadByte(); } var direction = (Direction)message.ReadByte(); creature.LookDirection = direction; creature.TurnDirection = direction; creature.Outfit = message.ReadOutfit(); creature.LightLevel = message.ReadByte(); creature.LightColor = message.ReadByte(); creature.Speed = message.ReadUShort(); creature.Skull = message.ReadByte(); creature.Shield = message.ReadByte(); if (thingId == 0x0061) // emblem is sent only in packet type 0x61 { creature.Emblem = message.ReadByte(); } creature.IsImpassable = message.ReadBool(); return(creature); } else if (thingId == 0x0063) { Creature creature = client.BattleList.GetCreature(message.ReadUInt()); if (creature == null) { throw new Exception("[GetThing] (0x0063) Can't find the creature in the battle list."); } creature.TurnDirection = (Direction)message.ReadByte(); creature.IsImpassable = message.ReadBool(); return(creature); } else { return(GetItem(message, thingId)); } }
private void ParseFirstClientMessage() { #if DEBUG_PROXY Trace.WriteLine("[DEBUG] Proxy [ParseFirstClientMessage]"); #endif clientInMessage.ReadPosition = 2; clientInMessage.Encrypted = false; if (Adler.Generate(clientInMessage) != clientInMessage.ReadUInt()) { throw new Exception("Wrong checksum."); } byte protocolId = clientInMessage.ReadByte(); if (protocolId == 0x01) //Login { protocol = Protocol.Login; ushort clientType = clientInMessage.ReadUShort(); ushort protocolVersion = clientInMessage.ReadUShort(); if (client.Version.Number >= ClientVersion.Version981.Number) { uint clientVersion = clientInMessage.ReadUInt(); } uint datSignature = clientInMessage.ReadUInt(); uint sprSignature = clientInMessage.ReadUInt(); uint picSignature = clientInMessage.ReadUInt(); if (client.Version.Number >= ClientVersion.Version981.Number) { byte clientPreviewState = clientInMessage.ReadByte(); } Rsa.OpenTibiaDecrypt(clientInMessage); Array.Copy(clientInMessage.Buffer, serverOutMessage.Buffer, clientInMessage.Size); serverOutMessage.Size = clientInMessage.Size; serverOutMessage.WritePosition = clientInMessage.ReadPosition - 1; //the first byte is zero xteaKey = new uint[4]; xteaKey[0] = clientInMessage.ReadUInt(); xteaKey[1] = clientInMessage.ReadUInt(); xteaKey[2] = clientInMessage.ReadUInt(); xteaKey[3] = clientInMessage.ReadUInt(); var acc = clientInMessage.ReadString(); //account name var pass = clientInMessage.ReadString(); //password if (client.IsOpenTibiaServer) { Rsa.OpenTibiaEncrypt(serverOutMessage); } else { Rsa.RealTibiaEncrypt(serverOutMessage); } Adler.Generate(serverOutMessage, true); serverOutMessage.WriteHead(); serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); serverSocket.Connect(loginServers[0].Server, loginServers[0].Port); serverSocket.Send(serverOutMessage.Buffer, 0, serverOutMessage.Size, SocketFlags.None); serverInMessage.Reset(); serverSocket.BeginReceive(serverInMessage.Buffer, 0, 2, SocketFlags.None, ServerReceiveCallback, null); } else if (protocolId == 0x0A) //Game { protocol = Protocol.World; ushort clientType = clientInMessage.ReadUShort(); ushort protocolVersion = clientInMessage.ReadUShort(); if (client.Version.Number >= ClientVersion.Version981.Number) { uint clientVersion = clientInMessage.ReadUInt(); byte clientPreviewState = clientInMessage.ReadByte(); } Rsa.OpenTibiaDecrypt(clientInMessage); Array.Copy(clientInMessage.Buffer, serverOutMessage.Buffer, clientInMessage.Size); serverOutMessage.Size = clientInMessage.Size; serverOutMessage.WritePosition = clientInMessage.ReadPosition - 1; //the first byte is zero xteaKey = new uint[4]; xteaKey[0] = clientInMessage.ReadUInt(); xteaKey[1] = clientInMessage.ReadUInt(); xteaKey[2] = clientInMessage.ReadUInt(); xteaKey[3] = clientInMessage.ReadUInt(); clientInMessage.ReadByte(); var accountName = clientInMessage.ReadString(); var characterName = clientInMessage.ReadString(); var password = clientInMessage.ReadString(); if (client.IsOpenTibiaServer) { Rsa.OpenTibiaEncrypt(serverOutMessage); } else { Rsa.RealTibiaEncrypt(serverOutMessage); } Adler.Generate(serverOutMessage, true); serverOutMessage.WriteHead(); serverSocket.Send(serverOutMessage.Buffer, 0, serverOutMessage.Size, SocketFlags.None); } else { throw new Exception("Invalid protocol " + protocolId.ToString("X2")); } }
private void ParseServerMarketDetail(InMessage message) { client.Market.BrowseType = message.ReadUShort(); //? client.Market.BrowseDetails.Clear(); for (int i = 0; i < 15; i++) { client.Market.BrowseDetails.Add(message.ReadString()); //? } client.Market.OfferStatistics.Clear(); DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime(); double TimeStamp = dt.Millisecond / (1000 * 86400); double ts1 = TimeStamp; int num1 = message.ReadByte() - 1; while (num1 >= 0) { ts1 -= 86400; uint TotalTransactions = message.ReadUInt(); uint TotalPrice = message.ReadUInt(); uint MaximumPrice = message.ReadUInt(); uint MinimumPrice = message.ReadUInt(); client.Market.OfferStatistics.Add(new OfferStatistic(ts1, OfferKind.Buy, TotalTransactions, TotalPrice, MaximumPrice, MinimumPrice)); num1--; } double ts2 = TimeStamp; int num2 = message.ReadByte() - 1; while (num2 >= 0) { ts2 -= 86400; uint TotalTransactions = message.ReadUInt(); uint TotalPrice = message.ReadUInt(); uint MaximumPrice = message.ReadUInt(); uint MinimumPrice = message.ReadUInt(); client.Market.OfferStatistics.Add(new OfferStatistic(ts2, OfferKind.Sell, TotalTransactions, TotalPrice, MaximumPrice, MinimumPrice)); num2--; } }