General Reference

This page is intended to serve as a reference while no other tutorials have been made. It is basically a pastebin.

Getting the main manager instance

Getting the main manager instance opens a lot of doors to the rest of the game's functionality! Almost everything related to the game is stored in this object instance.

Basic patch:

 [HarmonyPatch(typeof(Manager))]
 internal class ManagerPatch
 {   
     [HarmonyPatch("Awake")]
     [HarmonyPostfix]
     static void ManagerUpdatePatch(Manager __instance) {
         // Your code here, use __instance to get access to the Manager Instance
     }
}

Ensuring the game is in its main loop

Use this boolean to see if the game is in its main loop: Manager.currentSceneHandler.isInGame

Listening to Input

The normal Unity Input system works so it's possible to assign functionalities to keys that haven't been defined by the game itself. A Input.GetKeyDown() in an Update method should be enough.

Also CoreLib provides an API to add new Rewired keybinds. These keybinds will be rebindable by the user.

In your plugin Load() method call:

Then in your MonoBehavior Update() method you can check the button:

Changing a recipe

It is possible to change the recipe of an item by changing the requiredObjectsToCraft value.

Running MonoBehaviour classes through IL2CPP

BepInEx allows to run normal MonoBehaviour classes through the IL2CPP BasePlugin.

The way it is set up is through an AddComponent<T>() statement in the Load() method. <T> is your custom MonoBehaviour class.

This is handy for when you need to run code every frame without patching into an existing class' lifecycle.

Last updated

Was this helpful?