Modding Wiki
  • 🏠Home
  • 🫂How to contribute
  • Playing with Mods
    • Discovering Mods
    • Installing Mods
      • On Game Clients
      • For Multiplayer
      • On Dedicated Servers
      • No Console Support
    • Troubleshooting
    • Reporting Bugs
    • Uninstalling Mods
  • Creating Mods
    • Getting Started Modding
      • Setting Up the Modding SDK
      • Testing the Example Mods
      • Viewing Console Logs
    • Modding Limitations
    • Inspecting Other Mods' Code
    • Modding Tools
      • Scripting IDE
      • Unity Explorer
      • Asset Ripper
      • NG Tools Missing Script Recovery
      • DnSpy
      • Attaching a Debugger
    • Common Concepts
      • Unique Names and IDs
    • Modding Libraries
      • CoreLib
    • Modding Examples
      • Items
        • Weapons and Tools
        • Armor
        • Food
      • Obtaining items
        • Adding Crafting Recipe
        • Adding your items to crafters
        • Adding items to Enemy loot
      • Placeables
        • Tiles
      • NPCs and Enemies
      • UI and Interactions
      • Client-Server communications
    • Inspecting Base Game Content
      • Importing Ripped Assets to your Editor
      • Inspecting Assets In-Game
      • Inspecting Game Code
    • Updating your Modding SDK
    • Releasing Mods
      • Create a mod.io Page
      • Mod Files Upload
  • Concepts
    • Important Folder Paths
    • Technologies and Tools
    • Elevated Access
  • Archive
    • General Reference
    • Outdated Unity Setup Guide
    • Outdated IL2CPP Guides
      • Getting started with modding
      • How to view game source code
      • How to setup your Unity project
      • How to install Core Keeper mono version
Powered by GitBook
On this page
  • Getting the main manager instance
  • Ensuring the game is in its main loop
  • Listening to Input
  • Changing a recipe
  • Running MonoBehaviour classes through IL2CPP

Was this helpful?

Edit on GitHub
Export as PDF
  1. Archive

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.

In your plugin Load() method call:

RewiredKeybinds.AddKeybind("KeyBindUniqueId", "My Key Bind", KeyboardKeyCode.K);

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

public class UpdateMono : MonoBehaviour
{
    private Player player;

    private void Awake()
    {
        RewiredKeybinds.rewiredStart += OnRewiredStart;
    }

    private void OnRewiredStart()
    {
        player = ReInput.players.GetPlayer(0);
    }

    private void Update()
    {
        if (player != null)
        {
            if (player.GetButtonDown("KeyBindUniqueId"))
            {
                // Do something
            }
        }
    }
}

Changing a recipe

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

foreach (var objectType in PugDatabase.objectsByType) {
    if (ot.Value.objectID == ObjectID.CopperMiningPick) { // ObjectID can be anything!
        List<CraftingObject> newList = new List<CraftingObject>(); // Create a new list of Crafting Objects

        CraftingObject newCO = new CraftingObject(); Create a new Crafting Object
        newCO.objectID = ObjectID.Wood; // Set the ObjectID to wood (can be anything)
        newCO.amount = 1; // Set the required amount
        newList.Add(newCO); // Add the requirement to the recipe

        ot.Value.requiredObjectsToCraft = newList; // Set the new recipe
    }
}

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.

public class Plugin : BasePlugin {
    public override void Load() {
        AddComponent<CustomMono>();
    }
}

public class CustomMono : MonoBehaviour {
    public CustomMono(IntPtr handle) : base(handle) { }

    private void Update() {
        CoreLib.Logger.LogInfo("Every update"); // This will run on every frame!
    }
}
PreviousElevated AccessNextOutdated Unity Setup Guide

Last updated 9 months ago

Was this helpful?

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

CoreLib