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]attribute andModBaselifecycle (OnLoad,OnUpdate)Loggeroutput (Info, Warning, Error, Debug)- ImGui window creation and basic widgets
[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();
}
}
π’ 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:
- Declarative patching with
[Patch],[PatchMethod],[Prefix] - Targeting Unity Engine classes by namespace + name
- Prefix hooks that allow the original method to continue
[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;
}
}
π‘ GameStats Dashboard
A medium-complexity mod that tracks game statistics and demonstrates the full patching + IL2CPP Bridge + ImGui toolkit.
What youβll learn:
- All patch types:
[Prefix],[Postfix],[Finalizer] - Targeting by namespace + class name, including obfuscated names and global namespace classes
- Special parameters:
__instance,__0/__1,ref __result,__exception - Positional parameter mapping with named parameters
- IL2CPP Bridge: find classes, invoke methods, read fields
- Advanced ImGui: tabs, trees, tooltips, popups, menus, draw list overlay
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);
π΄ 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:
- Runtime IL2CPP reflection (enumerate classes, fields, methods, properties)
- Scene traversal via IL2CPP Bridge
- Complex ImGui application architecture (multiple panels, drag-to-resize)
- Deobfuscation system integration
Features
- Scene Hierarchy β Tree view of all loaded scenes and GameObjects
- Inspector Panel β View/edit fields, read properties, browse methods
- Drill-through Navigation β Click object references to navigate deeper
- Deobfuscation Tool β Map obfuscated names to friendly names in real-time
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 |
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 β |