From 939d1582f5506f014a38510e1809309abd97cd5e Mon Sep 17 00:00:00 2001
From: Cai <13110818005@qq.com>
Date: Sun, 15 Jun 2025 22:39:57 +0800
Subject: [PATCH 1/4] feat(GetDataHandler): add `ForceItemIntoNearestChest`
---
TShockAPI/GetDataHandlers.cs | 37 ++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index 6ed0f8de..d587515c 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -130,6 +130,7 @@ namespace TShockAPI
{ PacketTypes.NumberOfAnglerQuestsCompleted, HandleNumberOfAnglerQuestsCompleted },
{ PacketTypes.PlaceObject, HandlePlaceObject },
{ PacketTypes.LoadNetModule, HandleLoadNetModule },
+ { PacketTypes.ForceItemIntoNearestChest, HandleForceItemIntoNearestChest },
{ PacketTypes.PlaceTileEntity, HandlePlaceTileEntity },
{ PacketTypes.PlaceItemFrame, HandlePlaceItemFrame },
{ PacketTypes.UpdateItemDrop, HandleItemDrop },
@@ -1790,6 +1791,30 @@ namespace TShockAPI
return args.Handled;
}
+ /// For use in a ForceItemIntoNearestChest event.
+ public class ForceItemIntoNearestChestEventArgs : GetDataHandledEventArgs
+ {
+ /// The slot index of the item being attempted to put into a chest.
+ public short Slot { get; set; }
+
+ }
+
+ /// Fired when a ForceItemIntoNearestChest event occurs.
+ public static HandlerList ForceItemIntoNearestChest = new HandlerList();
+ private static bool OnForceItemIntoNearest(TSPlayer player, MemoryStream data, short slot)
+ {
+
+ var args = new ForceItemIntoNearestChestEventArgs
+ {
+ Player = player,
+ Data = data,
+ Slot = slot
+ };
+
+ ForceItemIntoNearestChest.Invoke(null, args);
+ return args.Handled;
+ }
+
/// For use in a PlaceTileEntity event.
public class PlaceTileEntityEventArgs : GetDataHandledEventArgs
{
@@ -4088,6 +4113,18 @@ namespace TShockAPI
return false;
}
+ private static bool HandleForceItemIntoNearestChest(GetDataHandlerArgs args)
+ {
+ var slot = args.Data.ReadInt16();
+
+ if (OnForceItemIntoNearest(args.Player, args.Data, slot))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
private static bool HandlePlaceTileEntity(GetDataHandlerArgs args)
{
var x = args.Data.ReadInt16();
From 6c500dfa70ebba1a0fdcda12deabb4ca5b175d12 Mon Sep 17 00:00:00 2001
From: Cai <13110818005@qq.com>
Date: Sun, 15 Jun 2025 23:41:25 +0800
Subject: [PATCH 2/4] fix(Bouncer): players bypass region protection and build
permissions when using Quick Stack
---
TShockAPI/Bouncer.cs | 43 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 41 insertions(+), 2 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 488abe61..238c0992 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -19,7 +19,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Terraria.ID;
-using TShockAPI.Net;
using Terraria;
using Microsoft.Xna.Framework;
using TShockAPI.Localization;
@@ -29,6 +28,7 @@ using Terraria.DataStructures;
using Terraria.Localization;
using TShockAPI.Models.PlayerUpdate;
using System.Threading.Tasks;
+using OTAPI;
using Terraria.GameContent.Tile_Entities;
namespace TShockAPI
@@ -137,6 +137,7 @@ namespace TShockAPI
GetDataHandlers.KillMe += OnKillMe;
GetDataHandlers.FishOutNPC += OnFishOutNPC;
GetDataHandlers.FoodPlatterTryPlacing += OnFoodPlatterTryPlacing;
+ OTAPI.Hooks.Chest.QuickStack += OnChestOnQuickStack;
// The following section is based off Player.PlaceThing_Tiles_PlaceIt and Player.PlaceThing_Tiles_PlaceIt_GetLegacyTileStyle.
@@ -2505,7 +2506,7 @@ namespace TShockAPI
Main.item[num].playerIndexTheItemIsReservedFor = args.Player.Index;
NetMessage.SendData((int)PacketTypes.ItemDrop, args.Player.Index, -1, NetworkText.Empty, num, 1f);
NetMessage.SendData((int)PacketTypes.ItemOwner, args.Player.Index, -1, NetworkText.Empty, num);
-
+
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlaceItemFrame rejected permissions from {0}", args.Player.Name));
NetMessage.SendData((int)PacketTypes.UpdateTileEntity, -1, -1, NetworkText.Empty, args.ItemFrame.ID, 0, 1);
args.Handled = true;
@@ -2871,6 +2872,44 @@ namespace TShockAPI
}
}
+ ///
+ /// Called when a player is trying to put an item into chest through Quick Stack.
+ ///
+ ///
+ ///
+ internal void OnChestOnQuickStack(object sender, OTAPI.Hooks.Chest.QuickStackEventArgs args)
+ {
+ var id = args.ChestIndex;
+ var plr = TShock.Players[args.PlayerId];
+
+ if (plr is not { Active: true })
+ {
+ args.Result = HookResult.Cancel;
+ return;
+ }
+
+ if (plr.IsBeingDisabled())
+ {
+ TShock.Log.ConsoleDebug(GetString("Bouncer / OnQuickStack rejected from disable from {0}", plr.Name));
+ args.Result = HookResult.Cancel;
+ return;
+ }
+
+ if (!plr.HasBuildPermission(Main.chest[id].x, Main.chest[id].y) && TShock.Config.Settings.RegionProtectChests)
+ {
+ TShock.Log.ConsoleDebug(GetString("Bouncer / OnQuickStack rejected from region protection? from {0}", plr.Name));
+ args.Result = HookResult.Cancel;
+ return;
+ }
+
+ if (!plr.IsInRange(Main.chest[id].x, Main.chest[id].y, 600/16))
+ {
+ TShock.Log.ConsoleDebug(GetString("Bouncer / OnQuickStack rejected from range check from {0}", plr.Name));
+ args.Result = HookResult.Cancel;
+ return;
+ }
+ }
+
internal void OnSecondUpdate()
{
Task.Run(() =>
From 0b79a6bee4f8434178a264fba43ca4b4d755b45b Mon Sep 17 00:00:00 2001
From: Cai <13110818005@qq.com>
Date: Tue, 17 Jun 2025 06:44:28 +0800
Subject: [PATCH 3/4] refactor(Bouncer): remove RangeCheck for
ChestOnQuickStack operations and rename method
Players are not able to quick-stack items into out-of-range chests.
---
TShockAPI/Bouncer.cs | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 238c0992..dde7f1a5 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -137,7 +137,7 @@ namespace TShockAPI
GetDataHandlers.KillMe += OnKillMe;
GetDataHandlers.FishOutNPC += OnFishOutNPC;
GetDataHandlers.FoodPlatterTryPlacing += OnFoodPlatterTryPlacing;
- OTAPI.Hooks.Chest.QuickStack += OnChestOnQuickStack;
+ OTAPI.Hooks.Chest.QuickStack += OnQuickStack;
// The following section is based off Player.PlaceThing_Tiles_PlaceIt and Player.PlaceThing_Tiles_PlaceIt_GetLegacyTileStyle.
@@ -2877,7 +2877,7 @@ namespace TShockAPI
///
///
///
- internal void OnChestOnQuickStack(object sender, OTAPI.Hooks.Chest.QuickStackEventArgs args)
+ internal void OnQuickStack(object sender, OTAPI.Hooks.Chest.QuickStackEventArgs args)
{
var id = args.ChestIndex;
var plr = TShock.Players[args.PlayerId];
@@ -2901,13 +2901,6 @@ namespace TShockAPI
args.Result = HookResult.Cancel;
return;
}
-
- if (!plr.IsInRange(Main.chest[id].x, Main.chest[id].y, 600/16))
- {
- TShock.Log.ConsoleDebug(GetString("Bouncer / OnQuickStack rejected from range check from {0}", plr.Name));
- args.Result = HookResult.Cancel;
- return;
- }
}
internal void OnSecondUpdate()
From 2cf08d393c34d807fece0789cbd828700299b542 Mon Sep 17 00:00:00 2001
From: Cai <13110818005@qq.com>
Date: Sat, 12 Jul 2025 17:06:21 +0800
Subject: [PATCH 4/4] Revert "feat(GetDataHandler): add
`ForceItemIntoNearestChest`"
This reverts commit 939d1582f5506f014a38510e1809309abd97cd5e.
---
TShockAPI/GetDataHandlers.cs | 37 ------------------------------------
1 file changed, 37 deletions(-)
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index d587515c..6ed0f8de 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -130,7 +130,6 @@ namespace TShockAPI
{ PacketTypes.NumberOfAnglerQuestsCompleted, HandleNumberOfAnglerQuestsCompleted },
{ PacketTypes.PlaceObject, HandlePlaceObject },
{ PacketTypes.LoadNetModule, HandleLoadNetModule },
- { PacketTypes.ForceItemIntoNearestChest, HandleForceItemIntoNearestChest },
{ PacketTypes.PlaceTileEntity, HandlePlaceTileEntity },
{ PacketTypes.PlaceItemFrame, HandlePlaceItemFrame },
{ PacketTypes.UpdateItemDrop, HandleItemDrop },
@@ -1791,30 +1790,6 @@ namespace TShockAPI
return args.Handled;
}
- /// For use in a ForceItemIntoNearestChest event.
- public class ForceItemIntoNearestChestEventArgs : GetDataHandledEventArgs
- {
- /// The slot index of the item being attempted to put into a chest.
- public short Slot { get; set; }
-
- }
-
- /// Fired when a ForceItemIntoNearestChest event occurs.
- public static HandlerList ForceItemIntoNearestChest = new HandlerList();
- private static bool OnForceItemIntoNearest(TSPlayer player, MemoryStream data, short slot)
- {
-
- var args = new ForceItemIntoNearestChestEventArgs
- {
- Player = player,
- Data = data,
- Slot = slot
- };
-
- ForceItemIntoNearestChest.Invoke(null, args);
- return args.Handled;
- }
-
/// For use in a PlaceTileEntity event.
public class PlaceTileEntityEventArgs : GetDataHandledEventArgs
{
@@ -4113,18 +4088,6 @@ namespace TShockAPI
return false;
}
- private static bool HandleForceItemIntoNearestChest(GetDataHandlerArgs args)
- {
- var slot = args.Data.ReadInt16();
-
- if (OnForceItemIntoNearest(args.Player, args.Data, slot))
- {
- return true;
- }
-
- return false;
- }
-
private static bool HandlePlaceTileEntity(GetDataHandlerArgs args)
{
var x = args.Data.ReadInt16();