Skip to content

Commit

Permalink
Merge pull request #33 from zambony/preview
Browse files Browse the repository at this point in the history
Add /nomana, add param for toggle cmds to always set on/off
  • Loading branch information
zambony authored Dec 12, 2022
2 parents 9685715 + ec36ae4 commit 86fb294
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 20 deletions.
79 changes: 60 additions & 19 deletions src/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("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<object>("UpdateAvailablePiecesList");

Logger.Log($"Creative mode: {((bool)enabled ? "ON".WithColor(Logger.GoodColor) : "OFF".WithColor(Logger.ErrorColor))}", true);
}

[Command("echo", "Shout into the void.")]
Expand Down Expand Up @@ -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 <color=white>{itemName}</color>, please be more specific.", true);
Logger.Error($"Found more than one item containing the text <color=white>{itemName}</color>, please be more specific.", true);
return;
}
catch (NoMatchFoundException)
{
Logger.Error($"Couldn't find any prefabs named <color=white>{itemName}</color>.", true);
Logger.Error($"Couldn't find any items named <color=white>{itemName}</color>.", true);
return;
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand All @@ -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.)")]
Expand Down
3 changes: 2 additions & 1 deletion src/Gungnir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<KeyCode, string> Binds { get => m_binds; set => m_binds = value; }
internal CommandHandler Handler { get => m_handler; set => m_handler = value; }
Expand Down
57 changes: 57 additions & 0 deletions src/PatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 86fb294

Please sign in to comment.