From 77ded2882625ba1d427853dc3cf3ab8bc5ad930f Mon Sep 17 00:00:00 2001 From: Zoom L1 <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 2 Dec 2021 22:13:25 +0700 Subject: [PATCH 01/15] Corrected customDeathReason in OnPlayerDamage Previously it was called for absolutely any damage from the player. --- TShockAPI/Bouncer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 1d1ccf26..380a40d0 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -2250,7 +2250,7 @@ namespace TShockAPI * If the player was not specified, that is, the player index is -1, then it is definitely a custom cause, as you can only deal damage with a projectile or another player. * This is how everything else works. If an NPC is specified, its value is not -1, which is a custom cause. */ - if (TShock.Config.Settings.DisableCustomDeathMessages && + if (TShock.Config.Settings.DisableCustomDeathMessages && id != args.Player.Index && (reason._sourcePlayerIndex == -1 || reason._sourceNPCIndex != -1 || reason._sourceOtherIndex != -1 || reason._sourceCustomReason != null)) { TShock.Log.ConsoleDebug("Bouncer / OnPlayerDamage rejected custom death message from {0}", args.Player.Name); From 97f33fea63c4155f4018bbf14abd943dc7dfb188 Mon Sep 17 00:00:00 2001 From: James Puleo Date: Thu, 2 Dec 2021 09:37:17 -0500 Subject: [PATCH 02/15] Added check to `HandleNpcTalk` to ensure the passed NPC index is within bounds (>= -1 && < `Main.maxNPCs`). --- CHANGELOG.md | 1 + TShockAPI/GetDataHandlers.cs | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44dda4f3..27485f95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * 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) * Fixed the ability to create custom messages with your death (or the death of another player) (@AgaSpace) +* Added check to `HandleNpcTalk` to ensure the passed NPC index is within bounds (>= -1 && < `Main.maxNPCs`). (@drunderscore) ## 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 bf0fb54e..20621c72 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3160,9 +3160,16 @@ namespace TShockAPI TShock.Log.ConsoleDebug("Bouncer / HandleNpcTalk rejected from bouncer throttle from {0}", args.Player.Name); return true; } + + // -1 is a magic value, represents not talking to an NPC + if (npc < -1 || npc >= Main.maxNPCs) + { + TShock.Log.ConsoleDebug("Bouncer / HandleNpcTalk rejected from bouncer out of bounds from {0}", args.Player.Name); + return true; + } return false; - } - + } + private static bool HandlePlayerAnimation(GetDataHandlerArgs args) { if (OnPlayerAnimation(args.Player, args.Data)) From 4dab0802a1e953ed734122978832f5eb62c50450 Mon Sep 17 00:00:00 2001 From: James Puleo Date: Thu, 2 Dec 2021 10:23:50 -0500 Subject: [PATCH 03/15] Added the `OnSignRead` handler in `GetDataHandlers`, and added the `SignRead` event. Added check to ensure the sign being read is within world bounds (x >= 0 && y >= 0 && x < Main.maxTilesX && y < Main.maxTilesY) --- CHANGELOG.md | 1 + TShockAPI/GetDataHandlers.cs | 55 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44dda4f3..b110aaad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * 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) * Fixed the ability to create custom messages with your death (or the death of another player) (@AgaSpace) +* Added the `OnSignRead` handler in `GetDataHandler`, and added the `SignRead` event. Added check to ensure the sign being read is within world bounds `(x >= 0 && y >= 0 && x < Main.maxTilesX && y < Main.maxTilesY)`. (@drunderscore) ## 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 bf0fb54e..5998ad18 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -122,6 +122,7 @@ namespace TShockAPI { PacketTypes.PlayerAnimation, HandlePlayerAnimation }, { PacketTypes.PlayerMana, HandlePlayerMana }, { PacketTypes.PlayerTeam, HandlePlayerTeam }, + { PacketTypes.SignRead, HandleSignRead }, { PacketTypes.SignNew, HandleSign }, { PacketTypes.LiquidSet, HandleLiquidSet }, { PacketTypes.PlayerBuff, HandlePlayerBuffList }, @@ -1187,6 +1188,43 @@ namespace TShockAPI return args.Handled; } + /// + /// For use in a SignRead event + /// + public class SignReadEventArgs : GetDataHandledEventArgs + { + /// + /// X location of the sign + /// + public int X { get; set; } + + /// + /// Y location of the sign + /// + public int Y { get; set; } + } + + /// + /// Sign - Called when a sign is read + /// + public static HandlerList SignRead = new HandlerList(); + + private static bool OnSignRead(TSPlayer player, MemoryStream data, int x, int y) + { + if (SignRead == null) + return false; + + var args = new SignReadEventArgs + { + Player = player, + Data = data, + X = x, + Y = y, + }; + SignRead.Invoke(null, args); + return args.Handled; + } + /// /// For use in a Sign event /// @@ -3217,6 +3255,23 @@ namespace TShockAPI return false; } + private static bool HandleSignRead(GetDataHandlerArgs args) + { + var x = args.Data.ReadInt16(); + var y = args.Data.ReadInt16(); + + if (OnSignRead(args.Player, args.Data, x, y)) + return true; + + if (x < 0 || y < 0 || x >= Main.maxTilesX || y >= Main.maxTilesY) + { + TShock.Log.ConsoleDebug("GetDataHandlers / HandleSignRead rejected out of bounds {0}", args.Player.Name); + return true; + } + + return false; + } + private static bool HandleSign(GetDataHandlerArgs args) { var id = args.Data.ReadInt16(); From 5230598ba3a4200944d380cbe288ab0d29970fdf Mon Sep 17 00:00:00 2001 From: Zoom L1 <46046453+AgaSpace@users.noreply.github.com> Date: Sat, 4 Dec 2021 10:37:16 +0700 Subject: [PATCH 04/15] Comments updated --- TShockAPI/Bouncer.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 380a40d0..e15209d4 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -2249,6 +2249,8 @@ namespace TShockAPI * * If the player was not specified, that is, the player index is -1, then it is definitely a custom cause, as you can only deal damage with a projectile or another player. * This is how everything else works. If an NPC is specified, its value is not -1, which is a custom cause. + * + * Checking whether this damage came from the player is necessary, because the damage from the player can come even when it is hit by a NPC */ if (TShock.Config.Settings.DisableCustomDeathMessages && id != args.Player.Index && (reason._sourcePlayerIndex == -1 || reason._sourceNPCIndex != -1 || reason._sourceOtherIndex != -1 || reason._sourceCustomReason != null)) From f3b1a8482162b7355d402f297aeb682497b717fd Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 6 Dec 2021 21:31:03 -0800 Subject: [PATCH 05/15] Version tick: 4.5.12 --- TShockAPI/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs index 3a2c541d..df44eb86 100644 --- a/TShockAPI/Properties/AssemblyInfo.cs +++ b/TShockAPI/Properties/AssemblyInfo.cs @@ -53,5 +53,5 @@ using System.Runtime.InteropServices; // Also, be sure to release on github with the exact assembly version tag as below // so that the update manager works correctly (via the Github releases api and mimic) -[assembly: AssemblyVersion("4.5.11")] -[assembly: AssemblyFileVersion("4.5.11")] +[assembly: AssemblyVersion("4.5.12")] +[assembly: AssemblyFileVersion("4.5.12")] From fe3a59f84af857b8f4abeac380289094f52e551b Mon Sep 17 00:00:00 2001 From: James Puleo Date: Tue, 7 Dec 2021 02:41:17 -0500 Subject: [PATCH 06/15] Fixed rejection check inside of `HandlePaintTile` to account for the Paint Sprayer (or Architect Gizmo Pack) being inside your inventory, rather than on an accessory slot. --- CHANGELOG.md | 3 +++ TShockAPI/GetDataHandlers.cs | 9 +++++++-- TShockAPI/TSPlayer.cs | 12 ++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7a1e596..34992433 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Do not forget to sign every line you change with your name. (@hakusaro) * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. +## Upcoming changes +* Fixed rejection check inside of `HandlePaintTile` to account for the Paint Sprayer (or Architect Gizmo Pack) being inside your inventory, rather than on an accessory slot. (@drunderscore) + ## 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) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index a860596d..45e13183 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3549,6 +3549,11 @@ namespace TShockAPI return true; } + bool hasPaintSprayerAbilities(Item item) => + item != null + && item.stack > 0 + && (item.type == ItemID.PaintSprayer || item.type == ItemID.ArchitectGizmoPack); + // Not selecting paintbrush or paint scraper or the spectre versions? Hacking. if (args.Player.SelectedItem.type != ItemID.PaintRoller && args.Player.SelectedItem.type != ItemID.PaintScraper && @@ -3556,8 +3561,8 @@ namespace TShockAPI args.Player.SelectedItem.type != ItemID.SpectrePaintRoller && args.Player.SelectedItem.type != ItemID.SpectrePaintScraper && args.Player.SelectedItem.type != ItemID.SpectrePaintbrush && - !args.Player.Accessories.Any(i => i != null && i.stack > 0 && - (i.type == ItemID.PaintSprayer || i.type == ItemID.ArchitectGizmoPack))) + !args.Player.Accessories.Any(hasPaintSprayerAbilities) && + !args.Player.Inventory.Any(hasPaintSprayerAbilities)) { TShock.Log.ConsoleDebug("GetDataHandlers / HandlePaintTile rejected select consistency {0}", args.Player.Name); args.Player.SendData(PacketTypes.PaintTile, "", x, y, Main.tile[x, y].color()); diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index e6ceac32..00ff790b 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -898,6 +898,18 @@ namespace TShockAPI } } + /// + /// Gets the player's inventory (first 5 rows) + /// + public IEnumerable Inventory + { + get + { + for (int i = 0; i < 50; i++) + yield return TPlayer.inventory[i]; + } + } + /// /// Gets the player's accessories. /// From bd7b1c1460609d471b5dd22b42f2a7e7ea0301db Mon Sep 17 00:00:00 2001 From: tru321 <84877585+tru321@users.noreply.github.com> Date: Wed, 8 Dec 2021 11:05:33 +0800 Subject: [PATCH 07/15] Update GetDataHandlers.cs --- TShockAPI/GetDataHandlers.cs | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index bf0fb54e..4e1ae400 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -135,6 +135,7 @@ namespace TShockAPI { PacketTypes.Teleport, HandleTeleport }, { PacketTypes.PlayerHealOther, HandleHealOther }, { PacketTypes.CatchNPC, HandleCatchNpc }, + { PacketTypes.ReleaseNPC, HandleReleaseNpc }, { PacketTypes.TeleportationPotion, HandleTeleportationPotion }, { PacketTypes.CompleteAnglerQuest, HandleCompleteAnglerQuest }, { PacketTypes.NumberOfAnglerQuestsCompleted, HandleNumberOfAnglerQuestsCompleted }, @@ -1638,6 +1639,56 @@ namespace TShockAPI return args.Handled; } + /// + /// The ReleaseNPC event arguments + /// + public class ReleaseNpcEventArgs : GetDataHandledEventArgs + { + /// + /// The X value of where NPC released + /// + public int X { get; set; } + + /// + /// The Y value of where NPC released + /// + public int Y { get; set; } + + /// + /// The NPC Type that player release + /// + public short Type { get; set; } + + /// + /// The NPC release style + /// + public byte Style { get; set; } + } + + /// + /// Called when player release a NPC, for checking critter released from item. + /// + public static HandlerList ReleaseNPC = new HandlerList(); + private static bool OnReleaseNpc(TSPlayer player, MemoryStream data, int _x, int _y, short _type, byte _style) + { + if (ReleaseNPC == null) + { + return false; + } + + var args = new ReleaseNpcEventArgs + { + Player = player, + Data = data, + X = _x, + Y = _y, + Type = _type, + Style = _style + }; + ReleaseNPC.Invoke(null, args); + return args.Handled; + } + /// The arguments to the PlaceObject hook. public class PlaceObjectEventArgs : GetDataHandledEventArgs { @@ -3658,10 +3709,33 @@ namespace TShockAPI NetMessage.SendData((int)PacketTypes.NpcUpdate, -1, -1, NetworkText.Empty, npcID); return true; } + + if(args.Player.IsBeingDisabled()) + { + TShock.Log.ConsoleDebug("GetDataHandlers / HandleCatchNpc rejected catch npc {0}", args.Player.Name); + Main.npc[npcID].active = true; + NetMessage.SendData((int)PacketTypes.NpcUpdate, -1, -1, NetworkText.Empty, npcID); + return true; + } return false; } + private static bool HandleReleaseNpc(GetDataHandlerArgs args) + { + var x = args.Data.ReadInt32(); + var y = args.Data.ReadInt32(); + var type = args.Data.ReadInt16(); + var style = args.Data.ReadInt8(); + + if (OnReleaseNpc(args.Player, args.Data, x, y, type, style)) + { + return true; + } + + return false; + } + private static bool HandleTeleportationPotion(GetDataHandlerArgs args) { var type = args.Data.ReadByte(); From d4befdeff01ca4905afb18624e771a0209c7f8af Mon Sep 17 00:00:00 2001 From: tru321 <84877585+tru321@users.noreply.github.com> Date: Wed, 8 Dec 2021 11:10:12 +0800 Subject: [PATCH 08/15] Update Bouncer.cs --- TShockAPI/Bouncer.cs | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 2145b373..d7797fed 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -105,6 +105,7 @@ namespace TShockAPI GetDataHandlers.NPCAddBuff += OnNPCAddBuff; GetDataHandlers.NPCHome += OnUpdateNPCHome; GetDataHandlers.HealOtherPlayer += OnHealOtherPlayer; + GetDataHandlers.ReleaseNPC += OnReleaseNPC; GetDataHandlers.PlaceObject += OnPlaceObject; GetDataHandlers.PlaceTileEntity += OnPlaceTileEntity; GetDataHandlers.PlaceItemFrame += OnPlaceItemFrame; @@ -1829,6 +1830,52 @@ namespace TShockAPI return; } + /// + /// A bouncer for checking NPC released by player + /// + /// The object that triggered the event. + /// The packet arguments that the event has. + internal void OnReleaseNPC(object sender, GetDataHandlers.ReleaseNpcEventArgs args) + { + int x = args.X; + int y = args.Y; + short type = args.Type; + byte style = args.Style; + + // if npc released outside allowed tile + if ( x >= Main.maxTilesX * 16 - 16 || x < 0 || y >= Main.maxTilesY * 16 - 16 || y < 0) + { + TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC rejected out of bounds from {0}", args.Player.Name); + args.Handled = true; + return; + } + + // if player disabled + if (args.Player.IsBeingDisabled()) + { + TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC rejected npc release from {0}", args.Player.Name); + args.Handled = true; + return; + } + + // if released npc not from its item (from crafted packet) + // e.g. using bunny item to release golden bunny + if(args.Player.TPlayer.lastVisualizedSelectedItem.makeNPC != type) + { + TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC rejected npc release from {0}", args.Player.Name); + args.Player.Kick("Trying to release different critter exploit!", true); + args.Handled = true; + return; + } + + if (args.Player.IsBouncerThrottled()) + { + TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC rejected throttle from {0}", args.Player.Name); + args.Handled = true; + return; + } + } + /// Bouncer's PlaceObject hook reverts malicious tile placement. /// The object that triggered the event. /// The packet arguments that the event has. From 26a46ef40c005d19ee7e1ddde708125e0fb895f1 Mon Sep 17 00:00:00 2001 From: tru321 <84877585+tru321@users.noreply.github.com> Date: Wed, 8 Dec 2021 11:48:55 +0800 Subject: [PATCH 09/15] Update Bouncer.cs --- TShockAPI/Bouncer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index d7797fed..e8a2b43c 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -1860,7 +1860,7 @@ namespace TShockAPI // if released npc not from its item (from crafted packet) // e.g. using bunny item to release golden bunny - if(args.Player.TPlayer.lastVisualizedSelectedItem.makeNPC != type) + if(args.Player.TPlayer.lastVisualizedSelectedItem.makeNPC != type && args.Player.TPlayer.lastVisualizedSelectedItem.placeStyle != style) { TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC rejected npc release from {0}", args.Player.Name); args.Player.Kick("Trying to release different critter exploit!", true); From 8d54033404c97b48ddac39e6e7a20c9fc935ca78 Mon Sep 17 00:00:00 2001 From: tru321 <84877585+tru321@users.noreply.github.com> Date: Wed, 8 Dec 2021 12:04:47 +0800 Subject: [PATCH 10/15] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4412bdb8..719c0258 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Do not insert tabs into this file, under any circumstances, ever. * Do not forget to sign every line you change with your name. (@hakusaro) * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. +## Upcoming changes +* Added hook `GetDataHandlers.OnReleaseNpc` to handling ReleaseNPC packet and a bouncer to stops unregistered and logged out players from releasing critters NPC. The bouncer has additional filter to stops players who tried to release different critter using crafted packet, e.g. using bunny item to release golden bunny. (@tru321) +* Added filter in `GetDataHandlers.HandleCatchNpc` that stops unregistered and logged out players to catch critters. (@tru321) ## TShock 4.5.12 * Fixed the ability to spawn Zenith projectile with non-original items. (@AgaSpace) From d70f715616f37285aee7d6e54265b001154a1361 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 7 Dec 2021 21:02:19 -0800 Subject: [PATCH 11/15] Add AppVeyor CI Because we're adding otapi3 on a different branch it is now necessary to have the appveyor CI config versioned so that the other branch can have its own build routine. --- appveyor.yml | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..245dbcdc --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,56 @@ +version: '{build}' +max_jobs: 16 +image: Visual Studio 2019 +build_script: +- ps: >- + git submodule update --init --recursive + + cd ./TerrariaServerAPI/ + + + nuget restore TShock.4.OTAPI.sln + + msbuild TShock.4.OTAPI.sln /p:Configuration=Debug + + + cd ./TShock.Modifications.Bootstrapper/bin/Debug/ + + + ./TShock.Modifications.Bootstrapper.exe + + + cd ../../../ + + + msbuild ./TerrariaServerAPI/TerrariaServerAPI.csproj /p:Configuration=Debug + + + msbuild TShock.4.OTAPI.sln /p:Configuration=Release + + + cd ./TShock.Modifications.Bootstrapper/bin/Release/ + + + ./TShock.Modifications.Bootstrapper.exe + + + cd ../../../ + + + msbuild ./TerrariaServerAPI/TerrariaServerAPI.csproj /p:Configuration=Release + + + cd ../ + + + nuget restore TShock.sln + + + msbuild ./TShockAPI/TShockAPI.csproj /p:Configuration=Release + + msbuild ./TShockAPI/TShockAPI.csproj /p:Configuration=Debug +artifacts: +- path: ./TShockAPI/bin/Debug/ + name: TShockAVDebug +- path: ./TShockAPI/bin/Release/ + name: TShockAVRelease From 16f7c876e135a4e816438f05be363280cba702ec Mon Sep 17 00:00:00 2001 From: tru321 <84877585+tru321@users.noreply.github.com> Date: Wed, 8 Dec 2021 14:44:03 +0800 Subject: [PATCH 12/15] Apply suggestions from code review Co-authored-by: Lucas Nicodemus --- TShockAPI/Bouncer.cs | 4 ++-- TShockAPI/GetDataHandlers.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index e8a2b43c..cdb4e3c6 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -1843,7 +1843,7 @@ namespace TShockAPI byte style = args.Style; // if npc released outside allowed tile - if ( x >= Main.maxTilesX * 16 - 16 || x < 0 || y >= Main.maxTilesY * 16 - 16 || y < 0) + if (x >= Main.maxTilesX * 16 - 16 || x < 0 || y >= Main.maxTilesY * 16 - 16 || y < 0) { TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC rejected out of bounds from {0}", args.Player.Name); args.Handled = true; @@ -1860,7 +1860,7 @@ namespace TShockAPI // if released npc not from its item (from crafted packet) // e.g. using bunny item to release golden bunny - if(args.Player.TPlayer.lastVisualizedSelectedItem.makeNPC != type && args.Player.TPlayer.lastVisualizedSelectedItem.placeStyle != style) + if (args.Player.TPlayer.lastVisualizedSelectedItem.makeNPC != type && args.Player.TPlayer.lastVisualizedSelectedItem.placeStyle != style) { TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC rejected npc release from {0}", args.Player.Name); args.Player.Kick("Trying to release different critter exploit!", true); diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 4e1ae400..a3da07f8 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1666,7 +1666,7 @@ namespace TShockAPI } /// - /// Called when player release a NPC, for checking critter released from item. + /// Called when player release a NPC, for checking critter released from item. /// public static HandlerList ReleaseNPC = new HandlerList(); private static bool OnReleaseNpc(TSPlayer player, MemoryStream data, int _x, int _y, short _type, byte _style) From e0d6252693daf6ffcfc56fb1ee4845322c422ba3 Mon Sep 17 00:00:00 2001 From: tru321 <84877585+tru321@users.noreply.github.com> Date: Fri, 10 Dec 2021 10:53:58 +0800 Subject: [PATCH 13/15] Update GetDataHandlers.cs --- TShockAPI/GetDataHandlers.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index a3da07f8..d67a4d53 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3713,8 +3713,6 @@ namespace TShockAPI if(args.Player.IsBeingDisabled()) { TShock.Log.ConsoleDebug("GetDataHandlers / HandleCatchNpc rejected catch npc {0}", args.Player.Name); - Main.npc[npcID].active = true; - NetMessage.SendData((int)PacketTypes.NpcUpdate, -1, -1, NetworkText.Empty, npcID); return true; } From f20ce4aaa92d5faa50188e800544a04ffabd8977 Mon Sep 17 00:00:00 2001 From: tru321 <84877585+tru321@users.noreply.github.com> Date: Fri, 10 Dec 2021 10:57:56 +0800 Subject: [PATCH 14/15] Update Bouncer.cs --- TShockAPI/Bouncer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index cdb4e3c6..5269d0d2 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -1862,8 +1862,8 @@ namespace TShockAPI // e.g. using bunny item to release golden bunny if (args.Player.TPlayer.lastVisualizedSelectedItem.makeNPC != type && args.Player.TPlayer.lastVisualizedSelectedItem.placeStyle != style) { - TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC rejected npc release from {0}", args.Player.Name); - args.Player.Kick("Trying to release different critter exploit!", true); + TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC released different critter from {0}", args.Player.Name); + args.Player.Kick("Released critter was not from its item.", true); args.Handled = true; return; } From 3ab630e731f970f74c40d9d92f28c5224655f063 Mon Sep 17 00:00:00 2001 From: tru321 <84877585+tru321@users.noreply.github.com> Date: Sun, 12 Dec 2021 19:13:29 +0800 Subject: [PATCH 15/15] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 719c0258..0aba9c42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Do not forget to sign every line you change with your name. (@hakusaro) * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. ## Upcoming changes -* Added hook `GetDataHandlers.OnReleaseNpc` to handling ReleaseNPC packet and a bouncer to stops unregistered and logged out players from releasing critters NPC. The bouncer has additional filter to stops players who tried to release different critter using crafted packet, e.g. using bunny item to release golden bunny. (@tru321) -* Added filter in `GetDataHandlers.HandleCatchNpc` that stops unregistered and logged out players to catch critters. (@tru321) +* Added hook `GetDataHandlers.OnReleaseNpc` to handling ReleaseNPC packet and a bouncer to stops unregistered and logged out players on SSC servers from releasing critters NPC. The bouncer has additional filter to stops players who tried to release different critter using crafted packet, e.g. using bunny item to release golden bunny. (@tru321) +* Added filter in `GetDataHandlers.HandleCatchNpc` that stops unregistered and logged out players on SSC servers to catch critters. (@tru321) ## TShock 4.5.12 * Fixed the ability to spawn Zenith projectile with non-original items. (@AgaSpace)