diff --git a/CHANGELOG.md b/CHANGELOG.md
index 62a73f8c..4412bdb8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
## TShock 4.5.12
* Fixed the ability to spawn Zenith projectile with non-original items. (@AgaSpace)
+* Added hook `GetDataHandlers.OnNpcTalk` for NpcTalk and a handler for it that stops unregistered and logged out players from interacting with NPCs, preventing them from smuggling or duplicating items via NPC item slots. (@tru321)
## TShock 4.5.11
* Add the new allowed buff TentacleSpike to NPC buff cheat detection bouncer. (@sgkoishi)
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index c4366961..bf0fb54e 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -118,6 +118,7 @@ namespace TShockAPI
{ PacketTypes.PlaceChest, HandlePlaceChest },
{ PacketTypes.Zones, HandlePlayerZone },
{ PacketTypes.PasswordSend, HandlePassword },
+ { PacketTypes.NpcTalk, HandleNpcTalk },
{ PacketTypes.PlayerAnimation, HandlePlayerAnimation },
{ PacketTypes.PlayerMana, HandlePlayerMana },
{ PacketTypes.PlayerTeam, HandlePlayerTeam },
@@ -1066,6 +1067,40 @@ namespace TShockAPI
return args.Handled;
}
+ ///
+ /// Using when player trying to talk to a NPC
+ ///
+ public class NpcTalkEventArgs : GetDataHandledEventArgs
+ {
+ ///
+ /// The Terraria ID of the player talking to the NPC
+ ///
+ public byte PlayerId { get; set; }
+
+ ///
+ /// The NPC ID of the NPC the player is talking to
+ ///
+ public short NPCTalkTarget { get; set; }
+ }
+ public static HandlerList NpcTalk = new HandlerList();
+ private static bool OnNpcTalk(TSPlayer player, MemoryStream data, byte _plr, short _npctarget)
+ {
+ if (NpcTalk == null)
+ {
+ return false;
+ }
+
+ var args = new NpcTalkEventArgs
+ {
+ Player = player,
+ Data = data,
+ PlayerId = _plr,
+ NPCTalkTarget = _npctarget,
+ };
+ NpcTalk.Invoke(null, args);
+ return args.Handled;
+ }
+
///
/// For use with a PlayerAnimation event
///
@@ -3104,6 +3139,30 @@ namespace TShockAPI
return true;
}
+ private static bool HandleNpcTalk(GetDataHandlerArgs args)
+ {
+ var plr = args.Data.ReadInt8();
+ var npc = args.Data.ReadInt16();
+
+ if (OnNpcTalk(args.Player, args.Data, plr, npc))
+ return true;
+
+ //Rejecting player who trying to talk to a npc if player were disabled, mainly for unregistered and logged out players. Preventing smuggling or duplicating their items if player put it in a npc's item slot
+ if (args.Player.IsBeingDisabled())
+ {
+ TShock.Log.ConsoleDebug("GetDataHandlers / HandleNpcTalk rejected npc talk {0}", args.Player.Name);
+ args.Player.SendData(PacketTypes.NpcTalk, "", plr, -1);
+ return true;
+ }
+
+ if (args.Player.IsBouncerThrottled())
+ {
+ TShock.Log.ConsoleDebug("Bouncer / HandleNpcTalk rejected from bouncer throttle from {0}", args.Player.Name);
+ return true;
+ }
+ return false;
+ }
+
private static bool HandlePlayerAnimation(GetDataHandlerArgs args)
{
if (OnPlayerAnimation(args.Player, args.Data))