using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace DevToggle
{
[BepInPlugin("YouDied.DevToggle", "DevToggle", "1.0.0")]
public class DevToggle : BaseUnityPlugin
{
[HarmonyPatch(typeof(Game), "SpawnPlayer")]
private static class Patch_SpawnPlayer
{
[CompilerGenerated]
private sealed class <ApplyOnLoadDelayed>d__1 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ApplyOnLoadDelayed>d__1(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(2f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
((BaseUnityPlugin)_instance).Logger.LogInfo((object)"DevToggle: Applying auto-settings on world load...");
ApplyAutoSettings();
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static void Postfix()
{
_devCommandsOn = false;
_debugModeOn = false;
_godModeOn = false;
_ghostModeOn = false;
DevToggle instance = _instance;
if (instance != null)
{
((MonoBehaviour)instance).StartCoroutine(ApplyOnLoadDelayed());
}
}
[IteratorStateMachine(typeof(<ApplyOnLoadDelayed>d__1))]
private static IEnumerator ApplyOnLoadDelayed()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ApplyOnLoadDelayed>d__1(0);
}
}
public const string PluginGUID = "YouDied.DevToggle";
public const string PluginName = "DevToggle";
public const string PluginVersion = "1.0.0";
private static readonly Harmony harmony = new Harmony("YouDied.DevToggle");
private static DevToggle _instance;
public static ConfigEntry<bool> AutoEnableDevCommands;
public static ConfigEntry<bool> AutoEnableDebugMode;
public static ConfigEntry<bool> AutoEnableGodMode;
public static ConfigEntry<bool> AutoEnableGhostMode;
public static ConfigEntry<KeyboardShortcut> HotkeyDevCommands;
public static ConfigEntry<KeyboardShortcut> HotkeyDebugMode;
public static ConfigEntry<KeyboardShortcut> HotkeyGodMode;
public static ConfigEntry<KeyboardShortcut> HotkeyGhostMode;
public static ConfigEntry<bool> AutoSetTOD;
public static ConfigEntry<float> AutoTODValue;
public static ConfigEntry<KeyboardShortcut> HotkeyResetTOD;
public static ConfigEntry<KeyboardShortcut> HotkeyApplyTOD;
public static ConfigEntry<bool> AutoSetEnv;
public static ConfigEntry<string> AutoEnvName;
public static ConfigEntry<KeyboardShortcut> HotkeyResetEnv;
public static ConfigEntry<KeyboardShortcut> HotkeyApplyEnv;
private static bool _devCommandsOn = false;
private static bool _debugModeOn = false;
private static bool _godModeOn = false;
private static bool _ghostModeOn = false;
private static readonly FieldInfo _chatWindowField = typeof(Terminal).GetField("m_chatWindow", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
private void Awake()
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Expected O, but got Unknown
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_028a: Unknown result type (might be due to invalid IL or missing references)
_instance = this;
AutoEnableDevCommands = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - DevCommands", "EnableDevCommands", true, "Automatically enable devcommands when loading into a world.\nDevCommands is the master switch — it must be ON before debugmode, god, or ghost will work.");
HotkeyDevCommands = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("1 - DevCommands", "ToggleDevCommands", new KeyboardShortcut((KeyCode)48, Array.Empty<KeyCode>()), "Hotkey to toggle devcommands on/off. Default: 0\nWARNING: Turning this off will also disable debugmode, god mode, and ghost mode.");
AutoEnableDebugMode = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - DebugMode", "EnableDebugMode", true, "Automatically enable debugmode when loading into a world.\nRequires DevCommands to be enabled. Enables: B=no-cost build, Z=fly, K=kill enemies, L=remove drops.");
HotkeyDebugMode = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("2 - DebugMode", "ToggleDebugMode", new KeyboardShortcut((KeyCode)45, Array.Empty<KeyCode>()), "Hotkey to toggle debugmode on/off. Default: -\nHas no effect if DevCommands is not enabled.");
AutoEnableGodMode = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - God Mode", "EnableGodMode", false, "Automatically enable god mode (invincible) when loading into a world.\nRequires DevCommands to be enabled.");
HotkeyGodMode = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("3 - God Mode", "ToggleGodMode", new KeyboardShortcut((KeyCode)103, Array.Empty<KeyCode>()), "Hotkey to toggle god mode on/off. Default: G\nHas no effect if DevCommands is not enabled.");
AutoEnableGhostMode = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Ghost Mode", "EnableGhostMode", false, "Automatically enable ghost mode (enemies ignore you) when loading into a world.\nRequires DevCommands to be enabled.");
HotkeyGhostMode = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("4 - Ghost Mode", "ToggleGhostMode", new KeyboardShortcut((KeyCode)104, Array.Empty<KeyCode>()), "Hotkey to toggle ghost mode on/off. Default: H\nHas no effect if DevCommands is not enabled.");
AutoSetTOD = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Time of Day", "AutoSetTOD", false, "Automatically apply the TODValue below when loading into a world.");
AutoTODValue = ((BaseUnityPlugin)this).Config.Bind<float>("5 - Time of Day", "TODValue", 0.5f, new ConfigDescription("Time of day value. 0.0 = midnight, 0.5 = noon, 1.0 = midnight.\nApplied on load if AutoSetTOD is true, or instantly via the Apply hotkey.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
HotkeyResetTOD = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("5 - Time of Day", "HotkeyResetTOD", new KeyboardShortcut((KeyCode)287, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Hotkey to reset time of day back to the normal day/night cycle. Default: Alt+F6.");
HotkeyApplyTOD = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("5 - Time of Day", "HotkeyApplyTOD", new KeyboardShortcut((KeyCode)287, Array.Empty<KeyCode>()), "Hotkey to apply the TODValue above immediately. Default: F6.");
AutoSetEnv = ((BaseUnityPlugin)this).Config.Bind<bool>("6 - Environment", "AutoSetEnv", false, "Automatically apply the environment override below when loading into a world.");
AutoEnvName = ((BaseUnityPlugin)this).Config.Bind<string>("6 - Environment", "EnvName", "Clear", "Environment override to apply on load or via hotkey.\nValid values: Clear, Twilight_Clear, Misty, Darklands_dark, Heath clear, DeepForest Mist, GDKing, Rain, LightRain, ThunderStorm, Eikthyr, GoblinKing, nofogts, SwampRain, Bonemass, Snow, Twilight_Snow, Twilight_SnowStorm, SnowStorm, Moder, Ashrain, Crypt, SunkenCrypt.");
HotkeyResetEnv = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("6 - Environment", "HotkeyResetEnv", new KeyboardShortcut((KeyCode)288, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Hotkey to reset environment override and return to normal weather. Default: Alt+F7.");
HotkeyApplyEnv = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("6 - Environment", "HotkeyApplyEnv", new KeyboardShortcut((KeyCode)288, Array.Empty<KeyCode>()), "Hotkey to apply the environment override above immediately. Default: F7.");
AutoEnableDevCommands.SettingChanged += delegate
{
OnAutoSettingChanged();
};
AutoEnableDebugMode.SettingChanged += delegate
{
OnAutoSettingChanged();
};
AutoEnableGodMode.SettingChanged += delegate
{
OnAutoSettingChanged();
};
AutoEnableGhostMode.SettingChanged += delegate
{
OnAutoSettingChanged();
};
AutoSetTOD.SettingChanged += delegate
{
if (AutoSetTOD.Value && IsInGame())
{
ApplyTOD();
}
};
AutoTODValue.SettingChanged += delegate
{
if (AutoSetTOD.Value && IsInGame())
{
ApplyTOD();
}
};
AutoSetEnv.SettingChanged += delegate
{
if (AutoSetEnv.Value && IsInGame())
{
ApplyEnv();
}
};
AutoEnvName.SettingChanged += delegate
{
if (AutoSetEnv.Value && IsInGame())
{
ApplyEnv();
}
};
harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"DevToggle v1.0.0 by YouDied! loaded.");
}
private static void ToggleConsole()
{
if ((Object)(object)Console.instance == (Object)null || _chatWindowField == null)
{
return;
}
object value = _chatWindowField.GetValue(Console.instance);
Component val = (Component)((value is Component) ? value : null);
if (val == null)
{
return;
}
bool flag = !val.gameObject.activeSelf;
val.gameObject.SetActive(flag);
if (flag)
{
object? obj = typeof(Terminal).GetField("m_input", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(Console.instance);
TMP_InputField val2 = (TMP_InputField)((obj is TMP_InputField) ? obj : null);
if ((Object)(object)val2 != (Object)null)
{
val2.ActivateInputField();
val2.text = string.Empty;
}
}
}
private void OnDestroy()
{
harmony.UnpatchSelf();
}
private void Update()
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
if (ZInput.GetKeyDown((KeyCode)47, true) && ZInput.GetKey((KeyCode)307, true) && IsInGame())
{
ToggleConsole();
}
else if (IsInGame() && !IsTyping())
{
KeyboardShortcut value = HotkeyDevCommands.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
ToggleDevCommands();
}
value = HotkeyDebugMode.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
ToggleDebugMode();
}
value = HotkeyGodMode.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
ToggleGodMode();
}
value = HotkeyGhostMode.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
ToggleGhostMode();
}
value = HotkeyResetTOD.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
ResetTOD();
}
value = HotkeyApplyTOD.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
ApplyTOD();
}
value = HotkeyResetEnv.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
ResetEnv();
}
value = HotkeyApplyEnv.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
ApplyEnv();
}
}
}
private static bool IsInGame()
{
return (Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)ZNet.instance != (Object)null;
}
private static bool IsTyping()
{
if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus())
{
return true;
}
if (Console.IsVisible())
{
return true;
}
if (TextInput.IsVisible())
{
return true;
}
return false;
}
private static void ShowMessage(string text)
{
if ((Object)(object)MessageHud.instance != (Object)null)
{
MessageHud.instance.ShowMessage((MessageType)1, text, 0, (Sprite)null, false);
}
}
private static void SetDevCommands(bool enable)
{
if (_devCommandsOn != enable)
{
RunConsoleCommand("devcommands");
_devCommandsOn = enable;
ShowMessage("Dev Commands: " + (enable ? "ON" : "OFF"));
((BaseUnityPlugin)_instance).Logger.LogInfo((object)("DevCommands -> " + (enable ? "ON" : "OFF")));
if (!enable)
{
_debugModeOn = false;
_godModeOn = false;
_ghostModeOn = false;
}
}
}
private static void SetDebugMode(bool enable)
{
if (enable && !_devCommandsOn)
{
((BaseUnityPlugin)_instance).Logger.LogWarning((object)"DebugMode blocked — DevCommands not enabled.");
return;
}
bool debugMode = Player.m_debugMode;
if (debugMode == enable)
{
_debugModeOn = debugMode;
return;
}
RunConsoleCommand("debugmode");
_debugModeOn = Player.m_debugMode;
ShowMessage("Debug Mode: " + (_debugModeOn ? "ON" : "OFF"));
((BaseUnityPlugin)_instance).Logger.LogInfo((object)("DebugMode -> " + (_debugModeOn ? "ON" : "OFF")));
}
private static void SetGodMode(bool enable)
{
if (enable && !_devCommandsOn)
{
((BaseUnityPlugin)_instance).Logger.LogWarning((object)"GodMode blocked — DevCommands not enabled.");
return;
}
bool flag = (Object)(object)Player.m_localPlayer != (Object)null && ((Character)Player.m_localPlayer).InGodMode();
if (flag == enable)
{
_godModeOn = flag;
return;
}
RunConsoleCommand("god");
_godModeOn = (Object)(object)Player.m_localPlayer != (Object)null && ((Character)Player.m_localPlayer).InGodMode();
ShowMessage("God Mode: " + (_godModeOn ? "ON" : "OFF"));
((BaseUnityPlugin)_instance).Logger.LogInfo((object)("GodMode -> " + (_godModeOn ? "ON" : "OFF")));
}
private static void SetGhostMode(bool enable)
{
if (enable && !_devCommandsOn)
{
((BaseUnityPlugin)_instance).Logger.LogWarning((object)"GhostMode blocked — DevCommands not enabled.");
return;
}
bool flag = (Object)(object)Player.m_localPlayer != (Object)null && ((Character)Player.m_localPlayer).InGhostMode();
if (flag == enable)
{
_ghostModeOn = flag;
return;
}
RunConsoleCommand("ghost");
_ghostModeOn = (Object)(object)Player.m_localPlayer != (Object)null && ((Character)Player.m_localPlayer).InGhostMode();
ShowMessage("Ghost Mode: " + (_ghostModeOn ? "ON" : "OFF"));
((BaseUnityPlugin)_instance).Logger.LogInfo((object)("GhostMode -> " + (_ghostModeOn ? "ON" : "OFF")));
}
private static void ToggleDevCommands()
{
SetDevCommands(!_devCommandsOn);
}
private static void ToggleDebugMode()
{
if (!_devCommandsOn)
{
ShowMessage("Dev Commands must be ON to toggle Debug Mode.");
}
else
{
SetDebugMode(!Player.m_debugMode);
}
}
private static void ToggleGodMode()
{
if (!_devCommandsOn)
{
ShowMessage("Dev Commands must be ON to toggle God Mode.");
return;
}
bool flag = (Object)(object)Player.m_localPlayer != (Object)null && ((Character)Player.m_localPlayer).InGodMode();
SetGodMode(!flag);
}
private static void ToggleGhostMode()
{
if (!_devCommandsOn)
{
ShowMessage("Dev Commands must be ON to toggle Ghost Mode.");
return;
}
bool flag = (Object)(object)Player.m_localPlayer != (Object)null && ((Character)Player.m_localPlayer).InGhostMode();
SetGhostMode(!flag);
}
private static void ApplyTOD()
{
if (!_devCommandsOn)
{
ShowMessage("Dev Commands must be ON to set Time of Day.");
return;
}
float value = AutoTODValue.Value;
RunConsoleCommand("tod " + value.ToString("F2", CultureInfo.InvariantCulture));
string arg = ((value == 0.5f) ? " (Noon)" : ((value == 0f || value == 1f) ? " (Midnight)" : ""));
ShowMessage($"Time of Day: {value:F2}{arg}");
((BaseUnityPlugin)_instance).Logger.LogInfo((object)$"TOD -> {value}");
}
private static void ResetTOD()
{
if (!_devCommandsOn)
{
ShowMessage("Dev Commands must be ON to reset Time of Day.");
return;
}
RunConsoleCommand("tod -1");
ShowMessage("Time of Day: Default cycle restored");
((BaseUnityPlugin)_instance).Logger.LogInfo((object)"TOD reset to default cycle.");
}
private static void ApplyEnv()
{
if (!_devCommandsOn)
{
ShowMessage("Dev Commands must be ON to set Environment.");
return;
}
string text = AutoEnvName.Value?.Trim();
if (!string.IsNullOrEmpty(text))
{
RunConsoleCommand("env " + text);
ShowMessage("Environment: " + text);
((BaseUnityPlugin)_instance).Logger.LogInfo((object)("Environment -> '" + text + "'"));
}
}
private static void ResetEnv()
{
if (!_devCommandsOn)
{
ShowMessage("Dev Commands must be ON to reset Environment.");
return;
}
RunConsoleCommand("resetenv");
ShowMessage("Environment: Default weather restored");
((BaseUnityPlugin)_instance).Logger.LogInfo((object)"Environment reset to default.");
}
private static void ApplyAutoSettings()
{
if (!IsInGame())
{
return;
}
if (AutoEnableDevCommands.Value)
{
SetDevCommands(enable: true);
}
if (_devCommandsOn)
{
if (AutoEnableDebugMode.Value)
{
SetDebugMode(enable: true);
}
if (AutoEnableGodMode.Value)
{
SetGodMode(enable: true);
}
if (AutoEnableGhostMode.Value)
{
SetGhostMode(enable: true);
}
if (AutoSetTOD.Value)
{
ApplyTOD();
}
if (AutoSetEnv.Value)
{
ApplyEnv();
}
}
}
private static void OnAutoSettingChanged()
{
if (IsInGame())
{
if (!AutoEnableDevCommands.Value && _devCommandsOn)
{
SetDevCommands(enable: false);
}
if (!AutoEnableDebugMode.Value && _debugModeOn)
{
SetDebugMode(enable: false);
}
if (!AutoEnableGodMode.Value && _godModeOn)
{
SetGodMode(enable: false);
}
if (!AutoEnableGhostMode.Value && _ghostModeOn)
{
SetGhostMode(enable: false);
}
ApplyAutoSettings();
}
}
private static void RunConsoleCommand(string command)
{
if ((Object)(object)Console.instance != (Object)null)
{
((Terminal)Console.instance).TryRunCommand(command, false, false);
}
}
}
}