Example Mods

Working example mods covering every major MDB API. Each targets universal Unity types and works across any IL2CPP game.


Example Difficulty Key APIs
HelloWorld 🟒 Simple ModBase, Logger, ImGui widgets
UnityDebugInterceptor 🟒 Simple Declarative patching
GameStats 🟑 Medium Patching, IL2CPP Bridge
MDB Explorer πŸ”΄ Complex Full IL2CPP reflection, scene traversal

All examples build with dotnet build -c Release and deploy to <GameDir>/MDB/Mods/.


🟒 HelloWorld

A minimal mod demonstrating the core building blocks.

What you’ll learn:

[Mod("Examples.HelloWorld", "Hello World", "1.0.0",
    Author = "MDB Framework",
    Description = "A simple example mod showing basic framework usage.")]
public class HelloWorldMod : ModBase
{
    private bool _windowOpen = true;
    private int _clickCount;
    private string _userName = "Modder";

    public override void OnLoad()
    {
        Logger.Info("Hello World mod loaded!");
        ImGuiManager.RegisterCallback("HelloWorld", DrawImGui,
            ImGuiCallbackPriority.Normal);
    }

    private void DrawImGui()
    {
        if (ImGui.Begin("Hello World Mod", ref _windowOpen))
        {
            ImGui.Text("Hello from MDB!");
            ImGui.InputText("Name", ref _userName, 64);
            if (ImGui.Button("Click Me!"))
                Logger.Info($"Clicked {++_clickCount} times!");
        }
        ImGui.End();
    }
}

πŸ“ View source on GitHub


🟒 Unity Debug Interceptor

Intercepts Unity’s Debug.Log, Debug.LogWarning, and Debug.LogError and redirects them to the MDB console with color coding.

What you’ll learn:

[Patch("UnityEngine", "Debug")]
[PatchMethod("Log", 1)]
public static class DebugLogPatch
{
    [Prefix]
    public static bool Prefix(string __0)
    {
        ModLogger.LogInternal("Unity", __0 ?? "<null>", ConsoleColor.Gray);
        return true; // Continue to original
    }
}

[Patch("UnityEngine", "Debug")]
[PatchMethod("LogWarning", 1)]
public static class DebugLogWarningPatch
{
    [Prefix]
    public static bool Prefix(string __0)
    {
        ModLogger.LogInternal("Unity.Warn", __0 ?? "<null>", ConsoleColor.Yellow);
        return true;
    }
}

[Patch("UnityEngine", "Debug")]
[PatchMethod("LogError", 1)]
public static class DebugLogErrorPatch
{
    [Prefix]
    public static bool Prefix(string __0)
    {
        ModLogger.LogInternal("Unity.Error", __0 ?? "<null>", ConsoleColor.Red);
        return true;
    }
}

πŸ“ View source on GitHub


🟑 GameStats Dashboard

A medium-complexity mod that tracks game statistics and demonstrates the full patching + IL2CPP Bridge + ImGui toolkit.

What you’ll learn:

Patching APIs Covered

// Target by namespace + class name
[Patch("UnityEngine", "Time")]
[PatchMethod("get_deltaTime", 0)]
public static class TimePatch
{
    [Postfix]
    public static void Postfix(ref IntPtr __result) { /* modify return */ }
}

// Target obfuscated classes (global namespace)
[Patch("", "ABCDEFGHIJK")]
[PatchMethod("LMNOPQRSTUV", 3)]
public static class ObfuscatedPatch
{
    [Prefix]
    public static bool Prefix(IntPtr __instance, int damage, float multiplier, bool isCritical)
    {
        // Named parameters map positionally to IL2CPP args
        return true;
    }
}

IL2CPP Bridge

IntPtr klass = Il2CppBridge.mdb_find_class("Assembly-CSharp", "", "Player");
IntPtr method = Il2CppBridge.mdb_get_method(klass, "GetHealth", 0);
IntPtr result = Il2CppBridge.mdb_invoke_method(method, instance, null, out ex);

πŸ“ View source on GitHub


πŸ”΄ MDB Explorer (ImGui)

A full-featured runtime Unity scene explorer. Browse GameObjects, inspect Components, and map obfuscated names β€” all through a Dear ImGui interface.

What you’ll learn:

Features

Architecture

File Purpose
ExplorerMod.cs Main mod entry, panel layout, menu bar
SceneHierarchy.cs Scene tree traversal via IL2CPP
GameObjectInspector.cs Component/field/property reflection
ComponentReflector.cs IL2CPP type introspection helpers
DeobfuscationPanel.cs Name mapping UI
DeobfuscationHelper.cs Mapping database integration
ImGuiBindings.cs ImGui helper extensions

πŸ“ View source on GitHub


Building Any Example

cd Documentation/Examples/<ExampleName>
dotnet build -c Release

Copy the output DLL from bin/Release/ to <GameDir>/MDB/Mods/.


← Back to Home API Reference β†’