From ec36ae4049241b40acb0bd6217db8efdcb67aac6 Mon Sep 17 00:00:00 2001 From: Dylan Montgomery Date: Sun, 11 Dec 2022 22:57:04 -0800 Subject: [PATCH] Add /nomana, add param for toggle cmds to always set on/off --- src/CommandHandler.cs | 79 ++++++++++++++++++++++++++++++++----------- src/Gungnir.cs | 3 +- src/PatchManager.cs | 57 +++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 20 deletions(-) diff --git a/src/CommandHandler.cs b/src/CommandHandler.cs index 7009c15..6b790bd 100644 --- a/src/CommandHandler.cs +++ b/src/CommandHandler.cs @@ -211,16 +211,20 @@ public void ClearConsole() } [Command("creative", "Toggles creative mode, which removes the need for resources.")] - public void ToggleNoCost() + public void ToggleNoCost(bool? enabled = null) { - bool enabled = Player.m_localPlayer.ToggleNoPlacementCost(); + enabled = enabled ?? !Player.m_localPlayer.GetPrivateField("m_noPlacementCost"); - if (!enabled && !Player.m_localPlayer.IsDebugFlying()) + Player.m_localPlayer.SetPrivateField("m_noPlacementCost", enabled); + + if (!(bool)enabled && !Player.m_localPlayer.IsDebugFlying()) Player.m_debugMode = false; else Player.m_debugMode = true; - Logger.Log($"Creative mode: {(enabled ? "ON".WithColor(Logger.GoodColor) : "OFF".WithColor(Logger.ErrorColor))}", true); + Player.m_localPlayer.InvokePrivate("UpdateAvailablePiecesList"); + + Logger.Log($"Creative mode: {((bool)enabled ? "ON".WithColor(Logger.GoodColor) : "OFF".WithColor(Logger.ErrorColor))}", true); } [Command("echo", "Shout into the void.")] @@ -286,12 +290,12 @@ public void Give(string itemName, int amount = 1, Player player = null, int leve } catch (TooManyValuesException) { - Logger.Error($"Found more than one prefab containing the text {itemName}, please be more specific.", true); + Logger.Error($"Found more than one item containing the text {itemName}, please be more specific.", true); return; } catch (NoMatchFoundException) { - Logger.Error($"Couldn't find any prefabs named {itemName}.", true); + Logger.Error($"Couldn't find any items named {itemName}.", true); return; } @@ -343,16 +347,20 @@ public void Goto(Player player) } [Command("ghost", "Toggles ghost mode. Prevents hostile creatures from detecting you.")] - public void ToggleGhostMode() + public void ToggleGhostMode(bool? enabled = null) { - Player.m_localPlayer.SetGhostMode(!Player.m_localPlayer.InGhostMode()); + enabled = enabled ?? !Player.m_localPlayer.InGhostMode(); + + Player.m_localPlayer.SetGhostMode((bool)enabled); Logger.Log($"Ghost mode: {(Player.m_localPlayer.InGhostMode() ? "ON".WithColor(Logger.GoodColor) : "OFF".WithColor(Logger.ErrorColor))}", true); } [Command("god", "Toggles invincibility.")] - public void ToggleGodmode() + public void ToggleGodmode(bool? enabled = null) { - Player.m_localPlayer.SetGodMode(!Player.m_localPlayer.InGodMode()); + enabled = enabled ?? !Player.m_localPlayer.InGodMode(); + + Player.m_localPlayer.SetGodMode((bool)enabled); Logger.Log($"God mode: {(Player.m_localPlayer.InGodMode() ? "ON".WithColor(Logger.GoodColor) : "OFF".WithColor(Logger.ErrorColor))}", true); } @@ -635,10 +643,38 @@ public void ListSkills() global::Console.instance.Print(skillType.ToString()); } + [Command("nomana", "Toggles infintie eitr (mana).")] + public void ToggleMana(bool? enabled = null) + { + enabled = enabled ?? !Plugin.NoMana; + + if ((bool)enabled) + { + Player.m_localPlayer.m_eitrRegenDelay = 0.0f; + Player.m_localPlayer.m_eiterRegen = 1000f; + Player.m_localPlayer.SetMaxEitr(1000f, true); + Plugin.NoMana = true; + } + else + { + Player.m_localPlayer.m_eitrRegenDelay = 1f; + Player.m_localPlayer.m_eiterRegen = 5f; + Player.m_localPlayer.SetMaxEitr(100f, true); + Plugin.NoMana = false; + } + + Logger.Log( + $"Infinite mana: {(Plugin.NoMana ? "ON".WithColor(Logger.GoodColor) : "OFF".WithColor(Logger.ErrorColor))}", + true + ); + } + [Command("nostam", "Toggles infinite stamina.")] - public void ToggleStamina() + public void ToggleStamina(bool? enabled = null) { - if (!Plugin.NoStamina) + enabled = enabled ?? !Plugin.NoStamina; + + if ((bool)enabled) { Player.m_localPlayer.m_staminaRegenDelay = 0.05f; Player.m_localPlayer.m_staminaRegen = 999f; @@ -662,25 +698,30 @@ public void ToggleStamina() } [Command("nores", "Toggle building restrictions. Allows you to place objects even when the preview is red.")] - public void ToggleBuildAnywhere() + public void ToggleBuildAnywhere(bool? enabled = null) { - Plugin.BuildAnywhere = !Plugin.BuildAnywhere; + enabled = enabled ?? !Plugin.BuildAnywhere; + + Plugin.BuildAnywhere = (bool)enabled; Logger.Log($"No build restrictions: {(Plugin.BuildAnywhere ? "ON".WithColor(Logger.GoodColor) : "OFF".WithColor(Logger.ErrorColor))}", true); } [Command("noslide", "Toggle the ability to walk up steep angles without sliding.")] - public void ToggleNoSlide() + public void ToggleNoSlide(bool? enabled = null) { - Plugin.NoSlide = !Plugin.NoSlide; + enabled = enabled ?? !Plugin.NoSlide; + + Plugin.NoSlide = (bool)enabled; Logger.Log($"No slide: {(Plugin.NoSlide ? "ON".WithColor(Logger.GoodColor) : "OFF".WithColor(Logger.ErrorColor))}", true); } [Command("nosup", "Toggle the need for structural support.")] - public void ToggleNoSupport() + public void ToggleNoSupport(bool? enabled = null) { - Plugin.NoStructuralSupport = !Plugin.NoStructuralSupport; - Logger.Log($"No structural support: {(Plugin.NoStructuralSupport ? "ON".WithColor(Logger.GoodColor) : "OFF".WithColor(Logger.ErrorColor))}", true); + enabled = enabled ?? !Plugin.NoSlide; + Plugin.NoStructuralSupport = (bool)enabled; + Logger.Log($"No structural support: {(Plugin.NoStructuralSupport ? "ON".WithColor(Logger.GoodColor) : "OFF".WithColor(Logger.ErrorColor))}", true); } [Command("pos", "Print your current position as XZY coordinates. (XZY is used for tp command.)")] diff --git a/src/Gungnir.cs b/src/Gungnir.cs index b0bac3a..26945a0 100644 --- a/src/Gungnir.cs +++ b/src/Gungnir.cs @@ -16,7 +16,7 @@ public class Gungnir : BaseUnityPlugin public const string ModName = "Gungnir"; public const string ModOrg = "zamboni"; public const string ModGUID = ModOrg + "." + ModName; - public const string ModVersion = "1.5.5"; + public const string ModVersion = "1.6.0"; private readonly Harmony m_harmony = new Harmony(ModGUID); private CommandHandler m_handler = new CommandHandler(); @@ -28,6 +28,7 @@ public class Gungnir : BaseUnityPlugin public bool NoStructuralSupport = false; public bool NoStamina = false; public bool NoSlide = false; + public bool NoMana = false; internal Dictionary Binds { get => m_binds; set => m_binds = value; } internal CommandHandler Handler { get => m_handler; set => m_handler = value; } diff --git a/src/PatchManager.cs b/src/PatchManager.cs index 0d46f16..2f9c3f6 100644 --- a/src/PatchManager.cs +++ b/src/PatchManager.cs @@ -135,6 +135,63 @@ private static bool Prefix(ref bool __result, ref ZNetView ___m_nview) } } + [HarmonyPatch(typeof(Player), "UseEitr")] + public static class UseEitrPatch + { + private static bool Prefix(ref ZNetView ___m_nview, float ___m_maxEitr) + { + if (Plugin.NoMana && ___m_nview.IsValid() && ___m_nview.IsOwner()) + { + ___m_nview.GetZDO().Set("eitr", 1000f); + return false; + } + + return true; + } + } + + [HarmonyPatch(typeof(Player), "HaveEitr")] + public static class HaveEitrPatch + { + private static bool Prefix(ref bool __result, ref ZNetView ___m_nview) + { + if (Plugin.NoMana && ___m_nview.IsValid() && ___m_nview.IsOwner()) + { + __result = true; + return false; + } + + return true; + } + } + + [HarmonyPatch(typeof(Player), "GetMaxEitr")] + public static class GetMaxEitrPatch + { + private static bool Prefix(ref float __result, ref ZNetView ___m_nview) + { + if (Plugin.NoMana && ___m_nview.IsValid() && ___m_nview.IsOwner()) + { + __result = 1000f; + return false; + } + + return true; + } + } + + [HarmonyPatch(typeof(Player), "UpdateStats")] + public static class UpdateStatsEitrPatch + { + private static void Postfix(ref ZNetView ___m_nview, ref float ___m_eitr) + { + if (Plugin.NoMana && ___m_nview.IsValid() && ___m_nview.IsOwner()) + { + ___m_eitr = 1000f; + } + } + } + [HarmonyPatch(typeof(Terminal), "TryRunCommand")] public static class CommandChainingPatch {