Skip to content

Commit

Permalink
Try fix SwapWhileUsePE
Browse files Browse the repository at this point in the history
  • Loading branch information
sgkoishi committed Sep 5, 2023
1 parent 8ead073 commit 9fc3831
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Core/Mitigations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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)
{
Expand Down

0 comments on commit 9fc3831

Please sign in to comment.