public void DecodeSingleDespawn(Packet p) { uint uniqueId = p.ReadUInt(); try { var check = Items.Remove(Items.FirstOrDefault(i => i.ObjectId == uniqueId)); if (check) { return; } check = Players.Remove(Players.FirstOrDefault(i => i.ObjectId == uniqueId)); if (check) { return; } check = Pets.Remove(Pets.FirstOrDefault(i => i.ObjectId == uniqueId)); if (check) { return; } check = Monsters.Remove(Monsters.FirstOrDefault(i => i.ObjectId == uniqueId)); if (check) { return; } } catch { // } }
private void GatewaySocket_PacketReceived(Packet packet) { switch ((OpCodes.GatewayServer)packet.Opcode) { #region OpCodes.GatewayServer.ServerList case OpCodes.GatewayServer.ServerList: Servers.Clear(); while (packet.ReadByte() != 0) { packet.ReadByte(); //server ID packet.ReadAscii(); //Server Name } while (packet.ReadByte() == 1) { var serverId = packet.ReadShort(); var serverName = packet.ReadAscii(); var currentCapacity = packet.ReadShort(); var maxCapacity = packet.ReadShort(); var status = packet.ReadByte(); Servers.Add(new ServerList(serverId, serverName, currentCapacity, maxCapacity, status)); } break; #endregion #region OpCodes.GatewayServer.LoginReply case OpCodes.GatewayServer.LoginReply: if (packet.ReadByte() == 1) { var sessionId = packet.ReadUInt(); _agentServerIp = packet.ReadAscii(); _agentServerPort = packet.ReadUShort(); _doAgentServerConnect = true; var response = new Packet((ushort)OpCodes.GatewayServer.LoginReply, true); response.WriteByte(1); response.WriteUInt(sessionId); response.WriteAscii("127.0.0.1"); response.WriteUShort(_mLocalPort); packet = response; packet.Lock(); } break; #endregion } if (InvokeMethodWithSkip(GatewayPacketReceived, packet)) { return; //Skip } SendFromServer(packet); }
public void DecodeSingleSpawn(Packet p) { try { var model = p.ReadUInt(); var character = Data.Characters.FindById((int)model); if (character == null) { #region Is Item var item = Data.Items.FindById((int)model); if (item != null) //YES! { var CurrentItem = new Item(); CurrentItem.AssocItem = item; if (item.CodeName.StartsWith("ITEM_ETC_GOLD")) { CurrentItem.Amount = p.ReadUInt(); } else if (item.CodeName.StartsWith("ITEM_QSP")) { p.ReadAscii(); //Owner name } else if (item.CodeName.StartsWith("ITEM_CH") || item.CodeName.StartsWith("ITEM_EU")) { CurrentItem.Plus = p.ReadByte(); } CurrentItem.ObjectId = p.ReadUInt(); CurrentItem.XSector = p.ReadByte(); CurrentItem.YSector = p.ReadByte(); CurrentItem.XOffset = p.ReadFloat(); CurrentItem.ZOffset = p.ReadFloat(); CurrentItem.YOffset = p.ReadFloat(); p.ReadShort(); //ANGLE if (p.ReadByte() == 1) //Has owner? { CurrentItem.OwnerId = p.ReadUInt(); } if (p.ReadByte() == 1) { CurrentItem.IsBlue = true; } p.ReadByte(); //?? p.ReadUInt(); //Dropper UID Items.Add(CurrentItem); } #endregion } else { if (character != null) { #region Monster if (character.CodeName.StartsWith("MOB")) { var CurrentMonster = new Monster(); uint ObjectId = p.ReadUInt(); byte xSec = p.ReadByte(); byte ySec = p.ReadByte(); float xCoordinate = p.ReadFloat(); float zCoordinate = p.ReadFloat(); float yCoordinate = p.ReadFloat(); p.ReadShort(); //Angle byte HasDestination = p.ReadByte(); //Has Destination p.ReadByte(); //Walking flag (00: walking 01: running) if (HasDestination == 1) { xSec = p.ReadByte(); ySec = p.ReadByte(); if (ySec == 0x80) { xCoordinate = p.ReadFloat() - p.ReadFloat(); p.ReadShort(); p.ReadShort(); yCoordinate = p.ReadFloat() - p.ReadFloat(); } else //Destination X,Y,Z { xCoordinate = p.ReadFloat(); zCoordinate = p.ReadFloat(); yCoordinate = p.ReadFloat(); } } else { p.ReadByte(); //No destination p.ReadShort(); //direction Angle } if (p.ReadByte() == 2) //death flag { CurrentMonster.IsAlive = false; } p.ReadByte(); byte move = p.ReadByte(); //Move flag byte zerk = p.ReadByte(); //Berzerk flag float walkS = p.ReadFloat(); //walk speed float runS = p.ReadFloat(); //run speed; float zerkS = p.ReadFloat(); //zerk speed byte buffCount = p.ReadByte(); for (int i = 0; i < buffCount; i++) { p.ReadUInt(); //Buff Id p.ReadUInt(); //Duration (in ms) } p.ReadByte(); // Name type byte Type = p.ReadByte(); // Monster type (general, champ...) CurrentMonster.ObjectId = ObjectId; CurrentMonster.Type = (Types.Monster)Type; CurrentMonster.AssocMonster = character; CurrentMonster.XSector = xSec; CurrentMonster.YSector = ySec; CurrentMonster.XOffset = xCoordinate; CurrentMonster.YOffset = yCoordinate; CurrentMonster.ZOffset = zCoordinate; Monsters.Add(CurrentMonster); } #endregion #region Pet else if (character.CodeName.StartsWith("COS")) { var CurrentPet = new Pet(); uint UniqueId = p.ReadUInt(); byte xSec = p.ReadByte(); byte ySec = p.ReadByte(); float xCoordinate = p.ReadFloat(); float zCoordinate = p.ReadFloat(); float yCoordinate = p.ReadFloat(); p.ReadShort(); byte HasDestination = p.ReadByte(); //Has Destination p.ReadByte(); //Walking flag (00: walking 01: running) if (HasDestination == 1) { xSec = p.ReadByte(); ySec = p.ReadByte(); //if (ySec == 0x80) //{ // xCoordinate = p.ReadFloat() - p.ReadFloat(); // p.ReadShort(); // p.ReadShort(); // yCoordinate = p.ReadFloat() - p.ReadFloat(); //} //else //{ xCoordinate = p.ReadFloat(); zCoordinate = p.ReadFloat(); yCoordinate = p.ReadFloat(); //} } else { p.ReadByte(); //No destination p.ReadShort(); //direction Angle } if (p.ReadByte() == 2) //death flag { CurrentPet.IsAlive = false; } p.ReadByte(); p.ReadByte(); //Move flag p.ReadByte(); //Berzerk flag p.ReadFloat(); //walk speed p.ReadFloat(); //run speed; p.ReadFloat(); //zerk speed byte buffCount = p.ReadByte(); for (int i = 0; i < buffCount; i++) { p.ReadUInt(); //Buff Id p.ReadUInt(); //Duration (in ms) } p.ReadByte(); // Name type CurrentPet.Name = p.ReadAscii(); CurrentPet.ObjectId = UniqueId; if (CurrentPet.Name == string.Empty) { CurrentPet.Name = "No Name"; } CurrentPet.OwnerName = p.ReadAscii(); CurrentPet.AssocPet = character; CurrentPet.XOffset = xCoordinate; CurrentPet.YOffset = yCoordinate; CurrentPet.ZOffset = zCoordinate; CurrentPet.XSector = xSec; CurrentPet.YSector = ySec; Pets.Add(CurrentPet); } #endregion #region NPC else if (character.CodeName.StartsWith("NPC")) { var CurrentNPC = new NPC(); uint ObjectId = p.ReadUInt(); byte xSec = p.ReadByte(); byte ySec = p.ReadByte(); float xCoordinate = p.ReadFloat(); float zCoordinate = p.ReadFloat(); float yCoordinate = p.ReadFloat(); CurrentNPC.AssocNPC = character; CurrentNPC.ObjectId = ObjectId; CurrentNPC.XOffset = xCoordinate; CurrentNPC.YOffset = yCoordinate; CurrentNPC.ZOffset = zCoordinate; CurrentNPC.XSector = xSec; CurrentNPC.YSector = ySec; NPCs.Add(CurrentNPC); } #endregion #region Player else if (character.CodeName.StartsWith("CHAR")) { var CurrentPlayer = new Structs.Agent.Spawns.Player(); p.ReadByte(); //VOLUME p.ReadShort(); //Noob icon/Knight? p.ReadByte(); //Max item slot p.ReadByte(); byte itemCount = p.ReadByte(); for (int i = 0; i < itemCount; i++) { short itemId = p.ReadShort(); var item = Data.Items.FindById((int)itemId); if (item != null) { if (item.CodeName.StartsWith("ITEM_EU") || item.CodeName.StartsWith("ITEM_CH")) { byte plus = p.ReadByte(); p.ReadShort(); } } } p.ReadByte(); //Max avatars byte avatarCount = p.ReadByte(); for (int i = 0; i < avatarCount; i++) { uint avatarId = p.ReadUInt(); byte Plus = p.ReadByte(); } byte Mask = p.ReadByte(); if (Mask == 1) { uint Id = p.ReadUInt(); var item = Data.Items.FindById((int)Id); if (item != null) { if (item.CodeName.StartsWith("CHAR")) { p.ReadByte(); byte itemsCount = p.ReadByte(); for (int i = 0; i < itemsCount; i++) { p.ReadUInt(); //Item Id } } } } CurrentPlayer.ObjectId = p.ReadUInt(); byte xSec = p.ReadByte(); byte ySec = p.ReadByte(); float xCoordinate = p.ReadFloat(); float zCoordinate = p.ReadFloat(); float yCoordinate = p.ReadFloat(); p.ReadShort(); //Angle; byte HasDestination = p.ReadByte(); p.ReadByte(); //Walking flag if (HasDestination == 1) { xSec = p.ReadByte(); ySec = p.ReadByte(); if (ySec == 0x80) { xCoordinate = p.ReadShort() - p.ReadShort(); p.ReadShort(); p.ReadShort(); yCoordinate = p.ReadShort() - p.ReadShort(); } else { xCoordinate = p.ReadShort(); p.ReadShort(); yCoordinate = p.ReadShort(); } } else { p.ReadByte(); //NO DESTINATION p.ReadShort(); //Angle?? } byte Alive = p.ReadByte(); if (Alive == 2) { CurrentPlayer.IsAlive = false; } p.ReadByte(); p.ReadByte(); //Move flag p.ReadByte(); //zerk flag p.ReadFloat(); p.ReadFloat(); p.ReadFloat(); byte ActiveSkills = p.ReadByte(); for (byte i = 0; i < ActiveSkills; i++) { uint SkillId = p.ReadUInt(); var skill = Data.Skills.FindById((int)SkillId); uint Duration = p.ReadUInt(); //Duration in ms if (skill != null) { if (skill.UiSkillName.StartsWith("SKILL_EU_CLERIC_RECOVERYA_GROUP") || skill.UiSkillName.StartsWith("SKILL_EU_BARD_BATTLAA_GUARD") || skill.UiSkillName.StartsWith("SKILL_EU_BARD_DANCEA") || skill.UiSkillName.StartsWith("SKILL_EU_BARD_SPEEDUPA_HITRATE")) { p.ReadByte(); } } } string Name = p.ReadAscii(); CurrentPlayer.Name = Name; CurrentPlayer.Level = 0; CurrentPlayer.ModelId = model; CurrentPlayer.XOffset = xCoordinate; CurrentPlayer.YOffset = yCoordinate; CurrentPlayer.ZOffset = zCoordinate; CurrentPlayer.XSector = xSec; CurrentPlayer.YSector = ySec; Players.Add(CurrentPlayer); } #endregion //Structures / Teleports } } } catch (Exception ex) { Debug.Print("Spawn Parsing Error:" + ex.Message); } }
private void AgentSocket_PacketReceived(Packet packet) { switch ((OpCodes.AgentServer)packet.Opcode) { #region OpCodes.AgentServer.CharacterListing case OpCodes.AgentServer.CharacterListing: if (packet.ReadByte() == 2) { if (packet.ReadByte() == 1) { CharacterListings.Clear(); var charCount = packet.ReadByte(); for (var i = 0; i < charCount; i++) { var modelId = packet.ReadInt(); var name = packet.ReadAscii(); var volume = packet.ReadByte(); var level = packet.ReadByte(); var exp = packet.ReadLong(); var strength = packet.ReadUShort(); var intelligence = packet.ReadUShort(); var statPoints = packet.ReadUShort(); var hp = packet.ReadUInt(); var mp = packet.ReadUInt(); var isInDeletion = false; if (packet.ReadByte() == 1) { isInDeletion = true; packet.ReadInt(); //TICKS ... } //packet.ReadByte(); //packet.ReadByte(); //packet.ReadByte(); packet.ReadByteArray(3); var itemCount = packet.ReadByte(); /*for (var iItem = 1; iItem <= itemCount; iItem++) * { * packet.ReadUInt(); //Item ID * packet.ReadByte(); //item Plus * }*/ packet.ReadByteArray(5 * itemCount); byte avatarCount = packet.ReadByte(); /*for (var iAvatar = 1; iAvatar <= avatarCount; iAvatar++) * { * packet.ReadUInt(); //Item ID * packet.ReadByte(); //Item plus * }*/ packet.ReadByteArray(5 * avatarCount); CharacterListings.Add(new CharacterListing(modelId, name, volume, level, exp, strength, intelligence, statPoints, hp, mp, isInDeletion)); } } } break; #endregion case OpCodes.AgentServer.GroupSpawnBegin: DecodeGroupSpawnStart(packet); break; case OpCodes.AgentServer.GroupeSpawn: DecodeGroupSpawn(packet); break; case OpCodes.AgentServer.GroupSpawnEnd: DecodeGroupSpawnEnd(packet); break; case OpCodes.AgentServer.SingleSpawn: DecodeSingleSpawn(packet); break; case OpCodes.AgentServer.SingleDespawn: DecodeSingleDespawn(packet); break; } if (InvokeMethodWithSkip(AgentPacketReceived, packet)) { return; //Skip } SendFromServer(packet); }