public static void ShowWindowTest(Character chr) { Packet pw = new Packet(ServerMessages.MINI_ROOM_BASE); pw.WriteByte(5); pw.WriteByte((byte)MiniRoomTypes.Omok); pw.WriteByte(2); pw.WriteBool(true); pw.WriteByte(0); PacketHelper.AddAvatar(pw, chr); pw.WriteString(chr.Name); pw.WriteByte(0xFF); pw.WriteByte(0); pw.WriteInt(1); pw.WriteInt(1); pw.WriteInt(1); pw.WriteInt(1); pw.WriteInt(2000); pw.WriteString("lolo"); pw.WriteByte(4); //Pieces type //Continue, no idea what this part is. pw.WriteByte(0); chr.SendPacket(pw); }
public static void ShowWindow(MiniRoomBase pRoom, Character pTo) { Packet pw = new Packet(ServerMessages.MINI_ROOM_BASE); pw.WriteByte(5); pw.WriteByte((byte)pRoom.Type); pw.WriteByte(pRoom.MaxUsers); pw.WriteByte(pTo.RoomSlotId); for (int i = 0; i < pRoom.Users.Length; i++) { Character character = pRoom.Users[i]; if (character == null) { continue; } pw.WriteByte(character.RoomSlotId); PacketHelper.AddAvatar(pw, character); pw.WriteString(character.Name); } pw.WriteByte(0xFF); pRoom.EncodeEnter(pTo, pw); pTo.SendPacket(pw); }
public static void ShowWindow(Character pOwner, MiniRoomBase mrb, byte OmokType) { Packet pw = new Packet(ServerMessages.MINI_ROOM_BASE); pw.WriteByte(5); pw.WriteByte((byte)MiniRoomTypes.Omok); pw.WriteByte(mrb.MaxUsers); pw.WriteBool(mrb.Users[0] == pOwner ? false : true); for (byte i = 0; i < 2; i++) { Character pUser = pOwner.Room.Users[i]; if (pUser != null) { pw.WriteByte(i); PacketHelper.AddAvatar(pw, pUser); pw.WriteString(pUser.Name); } } pw.WriteByte(0xFF); //End of Regular Enter base //Start of Omok Enter Base pw.WriteByte(0); //slot id //GW_Minigamerecord_Decode (20 bytes) pw.WriteInt(1); //pw.WriteInt(0); //pw.WriteInt(0); //pw.WriteInt(0); pw.WriteInt(mrb.Users[0].GameStats.OmokWins); pw.WriteInt(mrb.Users[0].GameStats.OmokTies); pw.WriteInt(mrb.Users[0].GameStats.OmokLosses); pw.WriteInt(2000); if (mrb.EnteredUsers > 1) { pw.WriteByte(1); //slot id pw.WriteInt(1); //pw.WriteInt(0); //pw.WriteInt(0); //pw.WriteInt(0); pw.WriteInt(pOwner.GameStats.OmokWins); pw.WriteInt(pOwner.GameStats.OmokTies); pw.WriteInt(pOwner.GameStats.OmokLosses); pw.WriteInt(2000); } pw.WriteByte(0xFF); //Rest of packet pw.WriteString(mrb.Title); pw.WriteByte(OmokType); //Pieces type //Continue, no idea what this part is. pw.WriteByte(0); pw.WriteByte(0); pw.WriteLong(0); pOwner.SendPacket(pw); }
public void MessengerAvatar(Character chr) { Packet packet = new Packet(ISClientMessages.MessengerAvatar); packet.WriteInt(chr.ID); packet.WriteString(chr.Name); PacketHelper.AddAvatar(packet, chr); SendPacket(packet); }
public static void AddPlayer(Character pCharacter, Character pTo) { Packet pw = new Packet(ServerMessages.MINI_ROOM_BASE); pw.WriteByte(4); pw.WriteByte(pCharacter.RoomSlotId); PacketHelper.AddAvatar(pw, pCharacter); pw.WriteString(pCharacter.Name); pTo.SendPacket(pw); }
public static void Test(Character chr) { Packet pw = new Packet(); pw.WriteByte(0xAF); pw.WriteByte(4); pw.WriteByte(0); PacketHelper.AddAvatar(pw, chr); pw.WriteString(chr.Name); chr.SendPacket(pw); }
public static void ShowJoin(MiniRoomBase pRoom, Character pWho) { Packet pw = new Packet(ServerMessages.MINI_ROOM_BASE); pw.WriteByte(4); pw.WriteByte(pWho.RoomSlotId); PacketHelper.AddAvatar(pw, pWho); pw.WriteString(pWho.Name); pRoom.EncodeEnterResult(pWho, pw); pRoom.BroadcastPacket(pw, pWho); }
public static void SendCharacterEnterPacket(Character player, Character victim) { Packet pw = new Packet(ServerMessages.USER_ENTER_FIELD); pw.WriteInt(player.ID); pw.WriteString(player.Name); BuffPacket.AddMapBuffValues(player, pw); PacketHelper.AddAvatar(pw, player); pw.WriteInt(player.GetSpawnedPet()?.ItemID ?? 0); pw.WriteInt(player.Inventory.ActiveItemID); pw.WriteInt(player.Inventory.ChocoCount); pw.WriteShort(player.Position.X); pw.WriteShort(player.Position.Y); pw.WriteByte(player.Stance); pw.WriteShort(player.Foothold); pw.WriteBool(player.IsGM && !player.Undercover); var petItem = player.GetSpawnedPet(); pw.WriteBool(petItem != null); if (petItem != null) { pw.WriteInt(petItem.ItemID); pw.WriteString(petItem.Name); pw.WriteLong(petItem.CashId); var ml = petItem.MovableLife; pw.WriteShort(ml.Position.X); pw.WriteShort(ml.Position.Y); pw.WriteByte(ml.Stance); pw.WriteShort(ml.Foothold); } // Mini Game & Player Shops pw.WriteByte(0); // Hardcoded end of minigame & player shops until implemented //Rings pw.WriteByte(0); // Number of Rings, hardcoded 0 until implemented. //Ring packet structure /** * for (Ring ring in player.Rings()) { * pw.WriteLong(ring.getRingId()); // R * pw.WriteLong(ring.getPartnerRingId()); * pw.WriteInt(ring.getItemId()); * } */ victim.SendPacket(pw); }
// This packet feels wonky and insecure - wackyracer public static void AddItem(Character pTo, byte TradeSlot, BaseItem pItem, byte User) { int itemType = (pItem.ItemID / 1000000); Packet pw = new Packet(ServerMessages.MINI_ROOM_BASE); pw.WriteByte(13); pw.WriteByte(User); // 0 or 1 based on left/right side of trade window pw.WriteByte(TradeSlot); // item slot in the trade window pw.WriteByte((byte)itemType); // Item Type (EQ, USE, SETUP, ETC, PET) PacketHelper.AddItemData(pw, pItem, 0, false); pTo.SendPacket(pw); }
public static void AddVisitor(Character chr, Character to) { Packet pw = new Packet(ServerMessages.MINI_ROOM_BASE); pw.WriteByte(0x04); pw.WriteByte(0x01); PacketHelper.AddAvatar(pw, chr); pw.WriteString("lolwat123"); pw.WriteInt(1); pw.WriteInt(0); pw.WriteInt(0); pw.WriteInt(0); pw.WriteInt(2000); //total score: should be 0 to.SendPacket(pw); }
public static void HandleSummonMove(Character chr, Packet packet) { var skillId = packet.ReadInt(); if (chr.Summons.GetSummon(skillId, out var summon)) { var movePath = new MovePath(); movePath.DecodeFromPacket(packet, MovePath.MovementSource.Summon); chr.TryTraceMovement(movePath); PacketHelper.ValidateMovePath(summon, movePath); SendMoveSummon(chr, summon, movePath); } }
public static void PersonalShopRefresh(Character pCharacter, PlayerShop ps) { Packet pw = new Packet(ServerMessages.MINI_ROOM_BASE); pw.WriteByte(0x15); pw.WriteByte((byte)ps.Items.Count); foreach (KeyValuePair <byte, PlayerShopItem> pst in ps.Items) { pw.WriteShort(pst.Value.Bundles); pw.WriteShort(pst.Value.BundleAmount); pw.WriteInt(pst.Value.Price); pw.WriteByte(WvsBeta.Common.Constants.getItemTypeInPacket(pst.Value.sItem.ItemID)); PacketHelper.AddItemData(pw, pst.Value.sItem, 0, false); } ps.BroadcastPacket(pw); }
public static void AddShop(Character chr) { Packet pw = new Packet(ServerMessages.MINI_ROOM_BASE); pw.WriteByte(5); pw.WriteByte((byte)MiniRoomTypes.Shop); pw.WriteByte(4); pw.WriteBool(false); pw.WriteByte(0); PacketHelper.AddAvatar(pw, chr); pw.WriteString("loltest123"); pw.WriteByte(0xFF); pw.WriteString("lolwattest"); pw.WriteByte(0x10); pw.WriteByte(0); chr.SendPacket(pw); }
public static void HandleMove(Character chr, Packet packet) { if (packet.ReadByte() != chr.PortalCount) { return; } var movePath = new MovePath(); movePath.DecodeFromPacket(packet, MovePath.MovementSource.Player); chr.TryTraceMovement(movePath); if (chr.AssertForHack(movePath.Elements.Length == 0, "Received Empty Move Path")) { return; } bool allowed = PacketHelper.ValidateMovePath(chr, movePath); if (!allowed && !chr.IsGM) { //this.Session.Socket.Shutdown(System.Net.Sockets.SocketShutdown.Both); //return; // TODO: Update speed of character // Program.MainForm.LogAppendFormat("Move incorrect: {0}", chr.Name); } SendPlayerMove(chr, movePath); if (!chr.Field.ReallyOutOfBounds.Contains(chr.Position.X, chr.Position.Y)) { if (chr.OutOfMBRCount++ > 5) { // Okay, reset. chr.ChangeMap(chr.MapID, chr.Field.GetClosestStartPoint(chr.Position)); chr.OutOfMBRCount = 0; } } else { chr.OutOfMBRCount = 0; } }
public static void AddVisitor(Character chr, MiniRoomBase mrb) { Packet pw = new Packet(ServerMessages.MINI_ROOM_BASE); pw.WriteByte(4); pw.WriteByte(chr.RoomSlotId); PacketHelper.AddAvatar(pw, chr); pw.WriteString(chr.Name); //GW_Minigamerecord_Decode pw.WriteInt(1); //pw.WriteInt(0); //pw.WriteInt(0); //pw.WriteInt(0); pw.WriteInt(chr.GameStats.OmokWins); pw.WriteInt(chr.GameStats.OmokTies); pw.WriteInt(chr.GameStats.OmokLosses); pw.WriteInt(2000); mrb.BroadcastPacket(pw, chr); }
public static void HandleMovePet(Character chr, Packet packet) { // 48 00 00 00 00 03 00 00 00 D1 00 00 00 9E 02 00 00 06 E0 01 00 00 00 D7 00 00 00 00 00 00 00 06 09 00 00 00 00 D7 00 00 00 00 00 88 00 04 15 00 00 var petItem = chr.GetSpawnedPet(); if (petItem == null) { return; } var movePath = new MovePath(); movePath.DecodeFromPacket(packet, MovePath.MovementSource.Pet); chr.TryTraceMovement(movePath); PacketHelper.ValidateMovePath(petItem.MovableLife, movePath); SendMovePet(chr, movePath); }
public void GenerateInventoryPacket(Packet packet) { packet.WriteInt(Mesos); foreach (var item in Equips[0]) { if (item == null) { continue; } PacketHelper.AddItemData(packet, item, item.InventorySlot, false); } packet.WriteByte(0); foreach (var item in Equips[1]) { if (item == null) { continue; } PacketHelper.AddItemData(packet, item, item.InventorySlot, false); } packet.WriteByte(0); for (int i = 0; i < 5; i++) { packet.WriteByte(MaxSlots[i]); foreach (BaseItem item in Items[i]) { if (item != null && item.InventorySlot > 0) { PacketHelper.AddItemData(packet, item, item.InventorySlot, false); } } packet.WriteByte(0); } }
public static void AddItem2(Character chr, byte inventory, BaseItem item, bool isNew, short amount) { Packet pw = new Packet(ServerMessages.INVENTORY_OPERATION); pw.WriteByte(0x01); pw.WriteByte(0x01); pw.WriteBool(!isNew); pw.WriteByte(inventory); if (isNew) { PacketHelper.AddItemData(pw, item, item.InventorySlot, true); } else { pw.WriteShort(item.InventorySlot); pw.WriteShort(amount); } pw.WriteLong(0x00); pw.WriteLong(0x00); pw.WriteLong(0x00); chr.SendPacket(pw); }
public static void OpenPlayerShop(Character pOwner, MiniRoomBase mrb) { Packet pw = new Packet(ServerMessages.MINI_ROOM_BASE); pw.WriteByte(5); pw.WriteByte((byte)mrb.Type); pw.WriteByte(mrb.MaxUsers); pw.WriteBool(mrb.Users[0] == pOwner ? false : true); //owner for (byte i = 0; i < 4; i++) { Character pUser = mrb.Users[i]; if (pUser != null) { pw.WriteByte(i); PacketHelper.AddAvatar(pw, pUser); pw.WriteString(pUser.Name); } } pw.WriteByte(0xFF); pw.WriteString(mrb.Title); pw.WriteByte(0x10); pw.WriteByte(0); pOwner.SendPacket(pw); }
public static void HandleMobControl(Character victim, Packet packet) { int mobid = packet.ReadInt(); var mob = victim.Field.GetMob(mobid); short moveID = packet.ReadShort(); var x = packet.ReadByte(); bool bNextAttackPossible = (x & 0x0F) != 0; sbyte action = packet.ReadSByte(); int actualAction = action < 0 ? -1 : (byte)(action >> 1); uint dwData = packet.ReadUInt(); var movePath = new MovePath(); movePath.DecodeFromPacket(packet, MovePath.MovementSource.Mob); if (mob == null) { return; } if (mob.Controller != victim && (!bNextAttackPossible || mob.NextAttackPossible || !mob.Field.FindNewController(mob, victim, true))) { SendMobRequestEndControl(victim, mobid); return; } victim.TryTraceMovement(movePath); if (mob.Controller != null && victim.ID != mob.Controller.ID) { Program.MainForm.LogAppend("returning mobpacket"); return; } var lastMoveMillis = MasterThread.CurrentTime - mob.LastMove; bool justStartedControlling = (MasterThread.CurrentTime - mob.LastControllerAssignTime) < 2000; PacketHelper.ValidateMovePath(mob, movePath); //Program.MainForm.LogDebug("[" + DateTime.Now.ToString() + "]" + "Received movement packet from " + victim.Name + ". Original pos: x:" + movePath.OriginalPosition.X + " y: " + movePath.OriginalPosition.Y + "\r\nNew position: x: " + movePath.NewPosition.X + " y: " + movePath.NewPosition.Y); // Skill related? if (actualAction >= 21 && actualAction <= 25) { short attackDelay = (short)(dwData >> 16); byte level = (byte)(dwData >> 8); byte skillId = (byte)(dwData); if (mob.DoSkill(skillId, level, attackDelay) == false) { // invalid return; } } else if (actualAction > 12 && actualAction < 20) { // regular attack? var attackIdx = (byte)(actualAction - 12); if (mob.Data.Attacks == null || !mob.Data.Attacks.ContainsKey(attackIdx)) { Program.MainForm.LogAppend( "Unknown attack for mob: " + mob.MobID + "; " + attackIdx + "; " + packet); } else { var attack = mob.Data.Attacks[attackIdx]; mob.MP = Math.Max(0, mob.MP - attack.MPConsume); mob.LastAttack = MasterThread.CurrentTime; } } if ((MasterThread.CurrentTime - mob.LastAttack) > 5000) { // Reassign controller! MobDamageInfo lastHitCharacter; if (mob.IsControlled) { var currentControllerID = mob.Controller.ID; lastHitCharacter = mob.DamageLog.Log.FirstOrDefault(mobDamageInfo => { if (mobDamageInfo.CharacterID == currentControllerID) { return(false); } if (mob.Field.GetPlayer(mobDamageInfo.CharacterID) == null) { return(false); } return((MasterThread.CurrentDate - mobDamageInfo.Time).TotalSeconds <= 5.0); }); } else { lastHitCharacter = mob.DamageLog.Log.FirstOrDefault(mobDamageInfo => { if (mob.Field.GetPlayer(mobDamageInfo.CharacterID) == null) { return(false); } return((MasterThread.CurrentDate - mobDamageInfo.Time).TotalSeconds <= 5.0); }); } if (lastHitCharacter != null) { Program.MainForm.LogDebug("Setting new controller: " + Server.Instance.GetCharacter(lastHitCharacter.CharacterID)); mob.SetController(mob.Field.GetPlayer(lastHitCharacter.CharacterID), true, false); return; } } mob.NextAttackPossible = bNextAttackPossible; // Prepare next skill byte forceControllerSkillLevel = 0; if (mob.NextAttackPossible == false || mob.SkillCommand != 0 || (mob.HasAnyStatus && mob.Status.BuffSealSkill.IsSet()) || mob.Data.Skills == null || mob.Data.Skills.Count == 0 || (MasterThread.CurrentTime - mob.LastSkillUse) < 3000) { // No skill } else { var availableSkills = mob.Data.Skills.Where(skill => { Dictionary <byte, MobSkillLevelData> msdLevels; if (!DataProvider.MobSkills.TryGetValue(skill.SkillID, out msdLevels) || !msdLevels.ContainsKey(skill.Level)) { return(false); } // Handle HP restriction var msd = msdLevels[skill.Level]; if (msd.HPLimit > 0 && (mob.HP / (double)mob.MaxHP * 100.0) > msd.HPLimit) { return(false); } // Skip if we already used a skill and it was not yet cooled down if (mob.SkillsInUse.TryGetValue(msd.SkillID, out long lastUse) && (lastUse + (msd.Cooldown * 1000)) > MasterThread.CurrentTime) { return(false); } // Do not reach the summon limit if (skill.SkillID == (byte)Constants.MobSkills.Skills.Summon && mob.SummonCount + msd.Summons.Count > msd.SummonLimit) { return(false); } // Can we boost stats? if (mob.HasAnyStatus) { short currentX = 0; int maxX = Math.Abs(100 - msd.X); switch ((Constants.MobSkills.Skills)skill.SkillID) { case Constants.MobSkills.Skills.WeaponAttackUp: case Constants.MobSkills.Skills.WeaponAttackUpAoe: currentX = mob.Status.BuffPowerUp.N; break; case Constants.MobSkills.Skills.MagicAttackUp: case Constants.MobSkills.Skills.MagicAttackUpAoe: currentX = mob.Status.BuffMagicUp.N; break; case Constants.MobSkills.Skills.WeaponDefenseUp: case Constants.MobSkills.Skills.WeaponDefenseUpAoe: currentX = mob.Status.BuffPowerGuardUp.N; break; case Constants.MobSkills.Skills.MagicDefenseUp: case Constants.MobSkills.Skills.MagicDefenseUpAoe: currentX = mob.Status.BuffMagicGuardUp.N; break; } if (currentX == 0) { return(true); } if (Math.Abs(100 - currentX) >= maxX) { return(false); } } return(true); }).ToArray(); if (availableSkills.Length > 0) { var randomSkill = availableSkills[Rand32.Next() % availableSkills.Length]; mob.SkillCommand = randomSkill.SkillID; forceControllerSkillLevel = randomSkill.Level; } } byte forceControllerSkillID = mob.SkillCommand; // Fix crash (zero level skill) if (forceControllerSkillLevel == 0) { forceControllerSkillID = 0; } SendMobControlResponse(victim, mobid, moveID, bNextAttackPossible, (short)mob.MP, forceControllerSkillID, forceControllerSkillLevel); SendMobControlMove(victim, mob, bNextAttackPossible, (byte)action, dwData, movePath); mob.CheckVacHack(lastMoveMillis, movePath.OriginalPosition, movePath.NewPosition, victim); // Good luck on getting less. if (lastMoveMillis < 500 && !justStartedControlling && !victim.IsAFK) { if (victim.AssertForHack(mob.HackReportCounter++ > 5, $"Movement speed too high! {lastMoveMillis}ms since last movement.")) { mob.HackReportCounter = 0; } } }