Adding a cheat

Updated 3 days ago

How to add a cheat

To add a cheat, use this line:

CheatInjector.RegisterCheat(new CheatName(), "cheat tab");

This runs some code that basically hands the cheat to the manager and rebuilds the menu at the start of each scene.

To add multiple cheats at once, use this:

CheatInjector.RegisterCheats(new ICheat[]
{
    new FlyingCheat(),
    new InstaKillCheat(),
    new FullestAutoCheat()
}, "deez nuts");

This adds mutliple cheats to one category at once.

Making a cheat function

To make a cheat work, you need a seperate script like this.

using System.Collections;
using CheatsAPI;
using ULTRAKILL.Cheats;

public class CheatName : ICheat
{
    public string LongName => "Cool Cheat";
    public string Identifier => "yourmod.coolcheat";
    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.NotPersistent;

    public IEnumerator Coroutine(CheatsManager manager) { yield break; }

    public void Enable(CheatsManager manager)
    {
        IsActive = true;
        ExampleCheatMod.Plugin.Log.LogInfo("Cool cheat = " + IsActive);
    }

    public void Disable()
    {
        IsActive = false;
        ExampleCheatMod.Plugin.Log.LogInfo("Cool cheat = " + IsActive);
    }
}

That script is a simple toggle script that does something once when its enabled and once when its disabled. for a script that does something every tick the cheat is on, a script like this would work:

using System.Collections;
using CheatsAPI;
using ULTRAKILL.Cheats;
using UnityEngine;

public class TickingCheat : ICheat
{
    public string LongName => "Ticking Cheat";
    public string Identifier => "yourmod.tickingcheat";
    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.NotPersistent;

    public void Enable(CheatsManager manager)
    {
        IsActive = true;
    }

    public void Disable()
    {
        IsActive = false;
    }

    public IEnumerator Coroutine(CheatsManager manager)
    {
        while (IsActive)
        {
            // this runs every frame while the cheat is on
            ExampleCheatMod.Plugin.Log.LogInfo("Ticking!");
            yield return null;
        }
    }
}

The properties at the top just tell the menu how to display your cheat:

  • LongName — the name shown in the menu
  • Identifier — a unique internal ID, always "yourmodname.cheatname" so it doesn't clash with anyone else's
  • ButtonEnabledOverride / ButtonDisabledOverride — custom button text instead of the default "ENABLED"/"DISABLED"
  • Icon — optional icon key, null for none
  • DefaultState — whether the cheat starts ON when the menu loads
  • PersistenceMode — whether the game remembers this cheat's state between sessions

The methods do the actual work:

  • Enable() runs once when the player turns the cheat on — put your effect here
  • Disable() runs once when they turn it off — undo it here
  • Coroutine() is for anything that needs to run continuously while active; most cheats just yield break;

You can repeat this process for each cheat you have. a mod with many cheats might have a Plugin.cs like this:

using BepInEx;
using BepInEx.Logging;
using CheatsAPI;

namespace ExampleCheatMod
{
    [BepInPlugin("com.nico.example", "Example Cheat", "1.0.0")]
    public class Plugin : BaseUnityPlugin
    {
        internal static ManualLogSource Log;

        private void Awake()
        {
            Log = Logger;
            CheatInjector.RegisterCheat(new FlyingCheat(), "silly cheats");
            CheatInjector.RegisterCheat(new InstaKillCheat(), "debug cheats");
            CheatInjector.RegisterCheat(new FullestAutoCheat(), "silly cheats");
            CheatInjector.RegisterCheat(new HakitaIsCoolCheat(), "silly cheats");
            CheatInjector.RegisterCheat(new FnafTwoOnDeathCheat(), "silly cheats");
            CheatInjector.RegisterCheat(new KnockKnockCheat(), "funny cheats");
            CheatInjector.RegisterCheat(new WhosThereCheat(), "funny cheats");
            CheatInjector.RegisterCheat(new JoeCheat(), "funny cheats");
            CheatInjector.RegisterCheat(new JoeWhoCheat(), "funny cheats");
            CheatInjector.RegisterCheat(new JoeMamaCheat(), "funny cheats");
        }
    }
}

or:

using BepInEx;
using BepInEx.Logging;
using CheatsAPI;

namespace ExampleCheatMod
{
    [BepInPlugin("com.nico.example", "Example Cheat", "1.0.0")]
    public class Plugin : BaseUnityPlugin
    {
        internal static ManualLogSource Log;

        private void Awake()
        {
            Log = Logger;

            CheatInjector.RegisterCheats(new ICheat[]
            {
                new FlyingCheat(),
                new HakitaIsCoolCheat(),
                new FnafTwoOnDeathCheat(),
                new FullestAutoCheat()
            }, "silly cheats");
            CheatInjector.RegisterCheat(new InstaKillCheat(), "debug cheats");
            CheatInjector.RegisterCheats(new ICheat[]
            {
                new KnockKnockCheat(),
                new WhosThereCheat(),
                new JoeCheat(),
                new JoeWhoCheat(),
                new JoeMamaCheat()
            }, "funny cheats");
        }
    }
}