From 9fc383140369710b9c8bb549283b8cf08950f0aa Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Mon, 4 Sep 2023 23:17:08 -0700 Subject: [PATCH] Try fix SwapWhileUsePE --- Core/Mitigations.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Core/Mitigations.cs b/Core/Mitigations.cs index a843e0b..2268cb1 100644 --- a/Core/Mitigations.cs +++ b/Core/Mitigations.cs @@ -26,11 +26,27 @@ private void OTHook_Mitigation_GetData(object? sender, OTAPI.Hooks.MessageBuffer switch (args.PacketId) { - case (int) PacketTypes.PlayerSlot when mitigation.InventorySlotPE: + case (int) PacketTypes.PlayerSlot: { var index = args.Instance.whoAmI; var data = args.Instance.readBuffer.AsSpan(args.ReadOffset, args.Length - 1); + if (mitigation.SwapWhileUsePE) + { + var slot = BitConverter.ToInt16(data.Slice(1, 2)); + if (Terraria.Main.player[index].controlUseItem && slot == Terraria.Main.player[index].selectedItem) + { + this.Statistics.MitigationRejectedSwapWhileUse++; + Terraria.Main.player[index].controlUseItem = false; + Terraria.NetMessage.TrySendData((int) PacketTypes.PlayerUpdate, -1, -1, null, index); + } + } + + if (!mitigation.InventorySlotPE) + { + break; + } + if (data.Length == 8 && data[0] == index) { var slot = BitConverter.ToInt16(data.Slice(1, 2)); @@ -46,7 +62,7 @@ private void OTHook_Mitigation_GetData(object? sender, OTAPI.Hooks.MessageBuffer break; } - if (!existingItem.IsAir || type != 0 && stack != 0) + if (!existingItem.IsAir || (type != 0 && stack != 0)) { if (existingItem.netID != type || existingItem.stack != stack || existingItem.prefix != prefix) {