using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("CheatsAPI")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("CheatsAPI")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("15641f70-6e86-4e0b-8007-3fe188875421")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace CheatsAPI; [BepInPlugin("com.nico.cheatsapi", "Cheats API", "0.0.3")] public class CheatInjector : BaseUnityPlugin { internal static ManualLogSource Logger; private static readonly List<(ICheat cheat, string category)> pendingCheats = new List<(ICheat, string)>(); internal static CheatsManager ActiveManager; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown Logger = ((BaseUnityPlugin)this).Logger; Harmony val = new Harmony("com.nico.cheatsapi"); val.PatchAll(); Logger.LogInfo((object)"Cheats API loaded!"); } public static void RegisterCheat(ICheat cheat, string category = null) { if ((Object)(object)ActiveManager != (Object)null) { ActiveManager.RegisterCheat(cheat, category); ActiveManager.RebuildMenu(); ManualLogSource logger = Logger; if (logger != null) { logger.LogInfo((object)("Registered cheat '" + cheat.Identifier + "' (" + cheat.LongName + ") in category '" + (category ?? "misc") + "'.")); } } else { pendingCheats.Add((cheat, category)); ManualLogSource logger2 = Logger; if (logger2 != null) { logger2.LogInfo((object)("Queued cheat '" + cheat.Identifier + "' (" + cheat.LongName + ") for category '" + (category ?? "misc") + "' — CheatsManager not loaded yet.")); } } } public static void RegisterCheats(ICheat[] cheats, string category = null) { if ((Object)(object)ActiveManager != (Object)null) { foreach (ICheat val in cheats) { ActiveManager.RegisterCheat(val, category); ManualLogSource logger = Logger; if (logger != null) { logger.LogInfo((object)("Registered cheat '" + val.Identifier + "' (" + val.LongName + ") in category '" + (category ?? "misc") + "'.")); } } ActiveManager.RebuildMenu(); return; } foreach (ICheat val2 in cheats) { pendingCheats.Add((val2, category)); ManualLogSource logger2 = Logger; if (logger2 != null) { logger2.LogInfo((object)("Queued cheat '" + val2.Identifier + "' (" + val2.LongName + ") for category '" + (category ?? "misc") + "' — CheatsManager not loaded yet.")); } } } internal static void FlushPending(CheatsManager manager) { foreach (var (val, text) in pendingCheats) { manager.RegisterCheat(val, text); ManualLogSource logger = Logger; if (logger != null) { logger.LogInfo((object)("Registered queued cheat '" + val.Identifier + "' (" + val.LongName + ") in category '" + (text ?? "misc") + "'.")); } } } } [HarmonyPatch(typeof(CheatsManager))] public static class CheatsManagerPatch { [HarmonyPatch("Start")] [HarmonyPostfix] private static void AddCustomCheats(CheatsManager __instance) { CheatInjector.ActiveManager = __instance; RegisterAndLog(__instance, (ICheat)(object)new MyTestToggle(), "example"); RegisterAndLog(__instance, (ICheat)(object)new MyTestButton(), "example"); CheatInjector.FlushPending(__instance); __instance.RebuildMenu(); CheatInjector.Logger.LogInfo((object)"Custom cheats injected!"); } private static void RegisterAndLog(CheatsManager manager, ICheat cheat, string category) { manager.RegisterCheat(cheat, category); CheatInjector.Logger.LogInfo((object)("Registered cheat '" + cheat.Identifier + "' (" + cheat.LongName + ") in category '" + (category ?? "misc") + "'.")); } [HarmonyPatch("OnDestroy")] [HarmonyPostfix] private static void OnDestroyed(CheatsManager __instance) { if ((Object)(object)CheatInjector.ActiveManager == (Object)(object)__instance) { CheatInjector.ActiveManager = null; } } } public class MyTestToggle : ICheat { public string LongName => "My Test Toggle"; public string Identifier => "custom.test-toggle"; public string ButtonEnabledOverride => null; public string ButtonDisabledOverride => null; public string Icon => null; public bool IsActive { get; private set; } public bool DefaultState => false; public StatePersistenceMode PersistenceMode => (StatePersistenceMode)0; public IEnumerator Coroutine(CheatsManager manager) { yield break; } public void Enable(CheatsManager manager) { IsActive = true; CheatInjector.Logger.LogInfo((object)"Toggle enabled!"); } public void Disable() { IsActive = false; CheatInjector.Logger.LogInfo((object)"Toggle disabled!"); } } public class MyTestButton : ICheat { public string LongName => "My Test Button"; public string Identifier => "custom.test-button"; public string ButtonEnabledOverride => null; public string ButtonDisabledOverride => "Press"; public string Icon => null; public bool IsActive => false; public bool DefaultState => false; public StatePersistenceMode PersistenceMode => (StatePersistenceMode)0; public IEnumerator Coroutine(CheatsManager manager) { yield break; } public void Enable(CheatsManager manager) { CheatInjector.Logger.LogInfo((object)"Button pressed!"); } public void Disable() { } }