From 0fb4c9293cc837fbcef86aa0737f4d732530b8e9 Mon Sep 17 00:00:00 2001 From: emyhrberg <121192176+emyhrberg@users.noreply.github.com> Date: Sat, 29 Nov 2025 02:32:55 +0100 Subject: [PATCH 1/2] Add Tool reset for cheat options when players join in multiplayer or lose admin permissions. See PermissionHandler:OnEnterWorld and PermissionHandler:HandlePacket and PermissionHandler:ResetToolsForNonAdmin and files in Content/Tools folder --- Content/Tools/Gameplay/FastForward.cs | 5 ++++- Content/Tools/Gameplay/Godmode.cs | 6 ++++++ Content/Tools/Gameplay/InfiniteReach.cs | 5 +++++ Content/Tools/Gameplay/Noclip.cs | 5 +++++ Content/Tools/Map/MapTeleport.cs | 5 ++++- Content/Tools/Visualization/Floodlight.cs | 5 +++++ Content/Tools/Visualization/FreeCamera.cs | 5 ++++- Content/Tools/Visualization/Hitboxes.cs | 15 +++++++++++++++ Core/Systems/PermissionHandler.cs | 21 +++++++++++++++++++++ Core/Systems/ToolSystem/Tool.cs | 8 ++++++++ DragonLens.csproj | 2 +- build.txt | 2 +- 12 files changed, 79 insertions(+), 5 deletions(-) diff --git a/Content/Tools/Gameplay/FastForward.cs b/Content/Tools/Gameplay/FastForward.cs index 70cf093..92446b7 100644 --- a/Content/Tools/Gameplay/FastForward.cs +++ b/Content/Tools/Gameplay/FastForward.cs @@ -13,7 +13,10 @@ internal class FastForward : Tool public override string IconKey => "FastForward"; public override bool HasRightClick => true; - + public override void ResetForNonAdmin(Player player) + { + speedup = 0; + } public override void OnActivate() { if (Main.netMode != NetmodeID.SinglePlayer) diff --git a/Content/Tools/Gameplay/Godmode.cs b/Content/Tools/Gameplay/Godmode.cs index 11f0073..b1796c0 100644 --- a/Content/Tools/Gameplay/Godmode.cs +++ b/Content/Tools/Gameplay/Godmode.cs @@ -17,6 +17,12 @@ internal class Godmode : Tool public override bool HasRightClick => true; + public override void ResetForNonAdmin(Player player) + { + godMode = false; + dogMode = false; + } + public override void OnActivate() { godMode = !godMode; diff --git a/Content/Tools/Gameplay/InfiniteReach.cs b/Content/Tools/Gameplay/InfiniteReach.cs index 777cb45..7d9e0d2 100644 --- a/Content/Tools/Gameplay/InfiniteReach.cs +++ b/Content/Tools/Gameplay/InfiniteReach.cs @@ -12,6 +12,11 @@ internal class InfiniteReach : Tool public override string IconKey => "InfiniteReach"; + public override void ResetForNonAdmin(Player player) + { + active = false; + } + public override void OnActivate() { active = !active; diff --git a/Content/Tools/Gameplay/Noclip.cs b/Content/Tools/Gameplay/Noclip.cs index 967e44a..dce5689 100644 --- a/Content/Tools/Gameplay/Noclip.cs +++ b/Content/Tools/Gameplay/Noclip.cs @@ -3,6 +3,7 @@ using DragonLens.Core.Systems.ThemeSystem; using DragonLens.Core.Systems.ToolSystem; using DragonLens.Helpers; +using System; using System.IO; using Terraria.ID; @@ -26,6 +27,10 @@ public bool Active public override string IconKey => "Noclip"; + public override void ResetForNonAdmin(Player player) + { + Active = false; + } public override void OnActivate() { Active = !Active; diff --git a/Content/Tools/Map/MapTeleport.cs b/Content/Tools/Map/MapTeleport.cs index 0cfca20..f78bbd7 100644 --- a/Content/Tools/Map/MapTeleport.cs +++ b/Content/Tools/Map/MapTeleport.cs @@ -14,7 +14,10 @@ internal class MapTeleport : Tool public static bool active = true; public override string IconKey => "MapTeleport"; - + public override void ResetForNonAdmin(Player player) + { + active = false; + } public override void OnActivate() { active = !active; diff --git a/Content/Tools/Visualization/Floodlight.cs b/Content/Tools/Visualization/Floodlight.cs index f83fc25..f4cd48b 100644 --- a/Content/Tools/Visualization/Floodlight.cs +++ b/Content/Tools/Visualization/Floodlight.cs @@ -1,6 +1,7 @@ using DragonLens.Core.Systems.ThemeSystem; using DragonLens.Core.Systems.ToolSystem; using DragonLens.Helpers; +using System; using Terraria.ModLoader.IO; namespace DragonLens.Content.Tools.Visualization @@ -12,6 +13,10 @@ internal class Floodlight : Tool public override string IconKey => "Lighting"; public override bool HasRightClick => true; + public override void ResetForNonAdmin(Player player) + { + strength = 0f; + } public override void OnActivate() { diff --git a/Content/Tools/Visualization/FreeCamera.cs b/Content/Tools/Visualization/FreeCamera.cs index b693c35..c6ad92e 100644 --- a/Content/Tools/Visualization/FreeCamera.cs +++ b/Content/Tools/Visualization/FreeCamera.cs @@ -11,7 +11,10 @@ internal class FreeCamera : Tool public static Vector2 freeCameraPos; public override string IconKey => "FreeCamera"; - + public override void ResetForNonAdmin(Player player) + { + active = false; + } public override void OnActivate() { active = !active; diff --git a/Content/Tools/Visualization/Hitboxes.cs b/Content/Tools/Visualization/Hitboxes.cs index f82152b..7f21a7b 100644 --- a/Content/Tools/Visualization/Hitboxes.cs +++ b/Content/Tools/Visualization/Hitboxes.cs @@ -15,6 +15,21 @@ internal class Hitboxes : Tool { public override string IconKey => "Hitboxes"; + public override void ResetForNonAdmin(Player player) + { + // Hide the hitbox window entirely for non-admins + HitboxWindow state = UILoader.GetUIState(); + state.visible = false; + + // Also force all options to "none" so no boxes are drawn + state.NPCOption?.boxState = HitboxOption.BoxType.none; + state.ProjectileOption?.boxState = HitboxOption.BoxType.none; + state.PlayerOption?.boxState = HitboxOption.BoxType.none; + state.ItemOption?.boxState = HitboxOption.BoxType.none; + state.MeleeOption?.boxState = HitboxOption.BoxType.none; + state.TileEntityOption?.boxState = HitboxOption.BoxType.none; + } + public override void OnActivate() { HitboxWindow state = UILoader.GetUIState(); diff --git a/Core/Systems/PermissionHandler.cs b/Core/Systems/PermissionHandler.cs index 8ac67d8..693e767 100644 --- a/Core/Systems/PermissionHandler.cs +++ b/Core/Systems/PermissionHandler.cs @@ -29,6 +29,21 @@ internal class PermissionHandler : ModSystem /// public static List visualAdmins = new(); + /// + /// Resets all tools for a player who is not an admin. + /// + /// The player to reset tools for. + public static void ResetToolsForNonAdmin(Player player) + { + if (Main.netMode == NetmodeID.Server) + return; + + foreach (Tool tool in ModContent.GetContent()) + { + tool.ResetForNonAdmin(player); + } + } + /// /// Determines if a player can use tools or not, based on their netmode and admin status. /// @@ -196,6 +211,9 @@ public static void HandlePacket(BinaryReader reader, int whoAmI) item.Visible = false; } + + // Client loses admin permissions -> reset all tools + ResetToolsForNonAdmin(Main.LocalPlayer); } } else if (operation == 2) //Sync visual only @@ -354,6 +372,9 @@ public override void OnEnterWorld() // Send an admin list sync request on enteri packet.Write("AdminUpdate"); packet.Write(2); packet.Send(); + + // Client enters world -> reset all tools + PermissionHandler.ResetToolsForNonAdmin(Player); } if (Netplay.Connection.Socket.GetRemoteAddress().IsLocalHost()) // The host is automatically an admin! diff --git a/Core/Systems/ToolSystem/Tool.cs b/Core/Systems/ToolSystem/Tool.cs index 398c4c2..fabcc47 100644 --- a/Core/Systems/ToolSystem/Tool.cs +++ b/Core/Systems/ToolSystem/Tool.cs @@ -62,6 +62,14 @@ public abstract class Tool : ModType /// public virtual bool SyncOnClientJoint => true; + /// + /// Resets cheat abilities (e.g godmode) for non-admin players. + /// + /// + public virtual void ResetForNonAdmin(Player player) + { + } + /// /// What happens when the user activates this tool, either by clicking on it or using it's hotkey. /// diff --git a/DragonLens.csproj b/DragonLens.csproj index f8dd8d3..8cf5e6a 100644 --- a/DragonLens.csproj +++ b/DragonLens.csproj @@ -22,7 +22,7 @@ dotnet - + diff --git a/build.txt b/build.txt index 19bf4c7..498945f 100644 --- a/build.txt +++ b/build.txt @@ -1,4 +1,4 @@ displayName = DragonLens author = ScalarVector & Tomat & HeartPlusUp & QuestionMark -version = 1.9.2.1 +version = 1.11 dllReferences = StructureHelper \ No newline at end of file From e50aae018552c35dd1b87d5e2ab1b02fbef956b7 Mon Sep 17 00:00:00 2001 From: emyhrberg <121192176+emyhrberg@users.noreply.github.com> Date: Sat, 29 Nov 2025 02:51:16 +0100 Subject: [PATCH 2/2] Fixed admin toggle --- Content/Commands/DedservAdmin.cs | 4 ++-- .../Themes/ru-RU_Mods.DragonLens.hjson | 24 +++++++++++++++---- .../Themes/zh-Hans_Mods.DragonLens.hjson | 24 +++++++++++++++---- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/Content/Commands/DedservAdmin.cs b/Content/Commands/DedservAdmin.cs index 2a5ed5b..c1ad820 100644 --- a/Content/Commands/DedservAdmin.cs +++ b/Content/Commands/DedservAdmin.cs @@ -26,13 +26,13 @@ public override void Action(CommandCaller caller, string input, string[] args) throw new UsageException("You must provide a players name!"); } - string name = input[(Command.Length + 1)..]; + string name = input[(Command.Length + 1)..].ToLower(); Player player = Main.player.FirstOrDefault(n => n.name.ToLower() == name); if (player != null) { - if (PermissionHandler.CanUseTools(player) || true) + if (PermissionHandler.CanUseTools(player)) { ChatHelper.BroadcastChatMessage(NetworkText.FromLiteral($"The server made {name} not an admin!"), Color.Orange); PermissionHandler.RemoveAdmin(player); diff --git a/Localization/Themes/ru-RU_Mods.DragonLens.hjson b/Localization/Themes/ru-RU_Mods.DragonLens.hjson index 5376157..42e369a 100644 --- a/Localization/Themes/ru-RU_Mods.DragonLens.hjson +++ b/Localization/Themes/ru-RU_Mods.DragonLens.hjson @@ -60,14 +60,30 @@ Configs: { BoxStyle: { Tooltip: "" - simple.Label: "{$Mods.DragonLens.BoxStyle.simple}" - vanilla.Label: "{$Mods.DragonLens.BoxStyle.vanilla}" + + simple: { + Label: "{$Mods.DragonLens.BoxStyle.simple}" + // Tooltip: "" + } + + vanilla: { + Label: "{$Mods.DragonLens.BoxStyle.vanilla}" + // Tooltip: "" + } } IconStyle: { Tooltip: "" - basic.Label: "{$Mods.DragonLens.IconStyle.basic}" - HEROs.Label: "{$Mods.DragonLens.IconStyle.HEROs}" + + basic: { + Label: "{$Mods.DragonLens.IconStyle.basic}" + // Tooltip: "" + } + + HEROs: { + Label: "{$Mods.DragonLens.IconStyle.HEROs}" + // Tooltip: "" + } } ToolConfig: { diff --git a/Localization/Themes/zh-Hans_Mods.DragonLens.hjson b/Localization/Themes/zh-Hans_Mods.DragonLens.hjson index 599885b..24f98ad 100644 --- a/Localization/Themes/zh-Hans_Mods.DragonLens.hjson +++ b/Localization/Themes/zh-Hans_Mods.DragonLens.hjson @@ -60,14 +60,30 @@ Configs: { BoxStyle: { // Tooltip: "" - // simple.Label: "{$Mods.DragonLens.BoxStyle.simple}" - // vanilla.Label: "{$Mods.DragonLens.BoxStyle.vanilla}" + + simple: { + // Label: "{$Mods.DragonLens.BoxStyle.simple}" + // Tooltip: "" + } + + vanilla: { + // Label: "{$Mods.DragonLens.BoxStyle.vanilla}" + // Tooltip: "" + } } IconStyle: { // Tooltip: "" - // basic.Label: "{$Mods.DragonLens.IconStyle.basic}" - // HEROs.Label: "{$Mods.DragonLens.IconStyle.HEROs}" + + basic: { + // Label: "{$Mods.DragonLens.IconStyle.basic}" + // Tooltip: "" + } + + HEROs: { + // Label: "{$Mods.DragonLens.IconStyle.HEROs}" + // Tooltip: "" + } } ToolConfig: {