using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HBS;
using HBS.DebugConsole;
using HarmonyLib;
using UnityEngine;
[assembly: AssemblyCopyright("Copyright © 2025 KoMiKoZa")]
[assembly: AssemblyTitle("Dev Console")]
[assembly: AssemblyDescription("Configurable hotkey to toggle Necropolis developer console")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("KoMiKoZa")]
[assembly: AssemblyProduct("Dev Console")]
[assembly: Guid("6cceec35-e261-4d4b-a191-2579e5767e8f")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("1.0.1.0")]
namespace KoMiKoZa.Necropolis.DevConsole;
[BepInPlugin("komikoza.necropolis.devconsole", "Dev Console", "1.0.1")]
public class DevConsolePlugin : BaseUnityPlugin
{
private const string GUID = "komikoza.necropolis.devconsole";
private const string NAME = "Dev Console";
private const string VERSION = "1.0.1";
internal static ManualLogSource Logger;
internal static ConfigEntry<bool> ModEnabled;
internal static ConfigEntry<bool> DebugMode;
internal static ConfigEntry<KeyCode> ToggleKey;
internal static ConfigEntry<ConsoleMode> PreferredMode;
private static DebugConsole cachedConsole;
private void Awake()
{
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Expected O, but got Unknown
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ModEnabled", true, "Enable or disable this mod");
DebugMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DebugMode", false, "Enable debug logging");
ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "ToggleKey", (KeyCode)96, "Key to toggle the console (default is ` / tilde key)");
PreferredMode = ((BaseUnityPlugin)this).Config.Bind<ConsoleMode>("Console", "PreferredMode", ConsoleMode.Mini, "Console display mode when visible (Icon = 0, Mini = 1, LogWindow = 2, Filtered = 3)");
if (!ModEnabled.Value)
{
Logger.LogInfo((object)string.Format("[{0}] Disabled", "Dev Console"));
return;
}
try
{
Harmony val = new Harmony("komikoza.necropolis.devconsole");
val.PatchAll();
Logger.LogInfo((object)"================================================");
Logger.LogInfo((object)string.Format("[{0}] v{1} loaded!", "Dev Console", "1.0.1"));
Logger.LogInfo((object)$"Console toggle key: {ToggleKey.Value}");
Logger.LogInfo((object)"================================================");
}
catch (Exception arg)
{
Logger.LogError((object)string.Format("[{0}] Failed to load: {1}", "Dev Console", arg));
}
}
private void Update()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!ModEnabled.Value || !Input.GetKeyDown(ToggleKey.Value))
{
return;
}
if ((Object)(object)cachedConsole == (Object)null)
{
cachedConsole = LazySingletonBehavior<DebugConsole>.Instance;
}
if ((Object)(object)cachedConsole == (Object)null)
{
if (DebugMode.Value)
{
Logger.LogWarning((object)"[DEV CONSOLE] Console instance not found");
}
}
else
{
ToggleConsole();
}
}
catch (Exception ex)
{
Logger.LogError((object)("[DEV CONSOLE] Update error: " + ex));
}
}
private static void ToggleConsole()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Invalid comparison between Unknown and I4
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
try
{
WindowMode mode = cachedConsole.mode;
if ((int)mode == -1)
{
WindowMode val = ConvertToWindowMode(PreferredMode.Value);
cachedConsole.SetMode(val);
if (DebugMode.Value)
{
Logger.LogInfo((object)$"[DEV CONSOLE] Showing console in mode: {val}");
}
}
else
{
cachedConsole.SetMode((WindowMode)(-1));
if (DebugMode.Value)
{
Logger.LogInfo((object)$"[DEV CONSOLE] Hiding console (was in mode: {mode})");
}
}
}
catch (Exception ex)
{
Logger.LogError((object)("[DEV CONSOLE] Toggle error: " + ex));
}
}
private static WindowMode ConvertToWindowMode(ConsoleMode mode)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
return (WindowMode)(mode switch
{
ConsoleMode.Icon => 0,
ConsoleMode.Mini => 1,
ConsoleMode.LogWindow => 2,
ConsoleMode.Filtered => 3,
_ => 1,
});
}
}
public enum ConsoleMode
{
Icon,
Mini,
LogWindow,
Filtered
}