Skip to content

Commit

Permalink
Fix PotionSicknessPE reverting potions everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
sgkoishi committed Dec 20, 2023
1 parent b6b4776 commit fb0031e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
35 changes: 15 additions & 20 deletions Core/Mitigations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,7 @@ private void OTHook_Mitigation_GetData(object? sender, OTAPI.Hooks.MessageBuffer
if (Terraria.Main.player[index].inventory[Terraria.Main.player[index].selectedItem].potion)
{
var amount = BitConverter.ToInt16(args.Instance.readBuffer.AsSpan(args.ReadOffset + 1, 2));
this[index].PendingRevertHeal = amount;
}
break;
}
case (int) PacketTypes.PlayerBuff when mitigation.PotionSicknessPE:
{
var index = args.Instance.whoAmI;
if (args.Instance.readBuffer[args.ReadOffset] != index)
{
args.CancelPacket();
break;
}
var buffcount = (args.Length - 1) / 2;
for (var i = 0; i < buffcount; i++)
{
var buff = BitConverter.ToInt16(args.Instance.readBuffer.AsSpan(args.ReadOffset + 1 + (i * 2), 2));
if (buff == Terraria.ID.BuffID.PotionSickness)
{
this[index].PendingRevertHeal = 0;
}
this[index].PendingRevertHeal = Math.Min(amount, Terraria.Main.player[index].statLifeMax2 - Terraria.Main.player[index].statLife);
}
break;
}
Expand Down Expand Up @@ -699,4 +680,18 @@ private void MMHook_Mitigation_WorldGenNextCount(On.Terraria.WorldGen.orig_nextC
}
Terraria.WorldGen.numTileCount = Terraria.WorldGen.maxTileCount;
}

private void GDHook_Mitigation_PlayerBuffUpdate(object? sender, TShockAPI.GetDataHandlers.PlayerBuffUpdateEventArgs args)
{
var currentPosition = args.Data.Position;
for (var i = 0; i < Terraria.Player.maxBuffs; i++)
{
var buff = System.IO.Streams.StreamExt.ReadUInt16(args.Data);
if (buff == Terraria.ID.BuffID.PotionSickness)
{
this[args.Player.Index].PendingRevertHeal = 0;
}
}
args.Data.Position = currentPosition;
}
}
4 changes: 3 additions & 1 deletion Core/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public override void Initialize()
TShockAPI.TShock.Initialized += this.PostTShockInitialize;
TShockAPI.GetDataHandlers.Sign.Register(this.GDHook_Permission_Sign);
TShockAPI.GetDataHandlers.NPCAddBuff.Register(this.GDHook_Mitigation_NpcAddBuff);
TShockAPI.GetDataHandlers.PlayerBuffUpdate.Register(this.GDHook_Mitigation_PlayerBuffUpdate);
}

protected override void Dispose(bool disposing)
Expand Down Expand Up @@ -287,8 +288,9 @@ protected override void Dispose(bool disposing)
TShockAPI.Hooks.PlayerHooks.PlayerPermission -= this.TSHook_Sudo_OnPlayerPermission;
TShockAPI.Hooks.GeneralHooks.ReloadEvent -= this.OnReload;
TShockAPI.TShock.Initialized -= this.PostTShockInitialize;
TShockAPI.GetDataHandlers.NPCAddBuff.UnRegister(this.GDHook_Mitigation_NpcAddBuff);
TShockAPI.GetDataHandlers.Sign.UnRegister(this.GDHook_Permission_Sign);
TShockAPI.GetDataHandlers.NPCAddBuff.UnRegister(this.GDHook_Mitigation_NpcAddBuff);
TShockAPI.GetDataHandlers.PlayerBuffUpdate.UnRegister(this.GDHook_Mitigation_PlayerBuffUpdate);
var asm = Assembly.GetExecutingAssembly();
Commands.ChatCommands.RemoveAll(c => c.CommandDelegate.Method?.DeclaringType?.Assembly == asm);
foreach (var detour in this._detours.Values)
Expand Down

0 comments on commit fb0031e

Please sign in to comment.