2y ago · May 8, 2024 2:20 PM
What is BepInEx for IL2CPP?
BepInEx 6.x is the standard plugin framework for Unity IL2CPP games. Unlike older Mono games that ran on .NET bytecode, IL2CPP compiles C# to native C++. BepInEx generates C# proxy assemblies at runtime using Il2CppInterop, allowing you to write clean C# mods, hook methods with HarmonyX, and interact with game objects effortlessly.
---
Step 1: Installing BepInEx 6 on Target Game
1. Download the latest **BepInEx 6 Unity (IL2CPP) x64** release from GitHub.
2. Extract all contents (, , ) directly into the game's root folder (where the game's [.exe] is located).
3. Run the game once. BepInEx will automatically unhollow/generate interop assemblies inside and create a folder.
---
Step 2: Setting up your C# Plugin Project
Create a new C# **Class Library** project in Visual Studio or Rider targeting **.NET 6.0** (or .NET Standard 2.1):
Or add direct assembly references from and .
---
Step 3: Creating your Base Plugin Class
---
Step 4: Hooking Game Methods with HarmonyX
Suppose you want to hook the player movement or stamina system in the target game:
---
Step 5: Building & Testing
1. Build the solution ().
2. Copy the compiled from into .
3. Launch the game and check the console output!
BepInEx 6.x is the standard plugin framework for Unity IL2CPP games. Unlike older Mono games that ran on .NET bytecode, IL2CPP compiles C# to native C++. BepInEx generates C# proxy assemblies at runtime using Il2CppInterop, allowing you to write clean C# mods, hook methods with HarmonyX, and interact with game objects effortlessly.
---
Step 1: Installing BepInEx 6 on Target Game
1. Download the latest **BepInEx 6 Unity (IL2CPP) x64** release from GitHub.
2. Extract all contents (
CODE
BepInEx/ CODE
doorstop_config.ini CODE
winhttp.dll3. Run the game once. BepInEx will automatically unhollow/generate interop assemblies inside
CODE
BepInEx/interop/ CODE
plugins/---
Step 2: Setting up your C# Plugin Project
Create a new C# **Class Library** project in Visual Studio or Rider targeting **.NET 6.0** (or .NET Standard 2.1):
XML
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.*" IncludeAssets="compile" />
<PackageReference Include="HarmonyX" Version="2.10.*" />
</ItemGroup>
</Project>Or add direct assembly references from
CODE
BepInEx/core/ CODE
BepInEx/interop/---
Step 3: Creating your Base Plugin Class
CSHARP
using BepInEx;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
namespace MyFirstIl2CppMod
{
[BepInPlugin("com.unreliablecode.firstmod", "My First Mod", "1.0.0")]
public class Plugin : BasePlugin
{
public static Plugin Instance { get; private set; } = null!;
private Harmony _harmony = null!;
public override void Load()
{
Instance = this;
Log.LogInfo("Plugin loaded successfully!");
// Apply all Harmony patches in this assembly
_harmony = new Harmony("com.unreliablecode.firstmod");
_harmony.PatchAll();
}
}
}---
Step 4: Hooking Game Methods with HarmonyX
Suppose you want to hook the player movement or stamina system in the target game:
CSHARP
using HarmonyLib;
using UnityEngine;
namespace MyFirstIl2CppMod.Patches
{
// Hook target method inside the game's PlayerController class
[HarmonyPatch(typeof(PlayerController), nameof(PlayerController.Update))]
public static class PlayerControllerUpdatePatch
{
[HarmonyPostfix]
public static void Postfix(PlayerController __instance)
{
if (__instance == null) return;
// Example: Infinite Stamina
__instance.stamina = 100f;
// Check for hotkey press
if (Input.GetKeyDown(KeyCode.F1))
{
Plugin.Instance.Log.LogInfo($"Player Position: {__instance.transform.position}");
}
}
}
}---
Step 5: Building & Testing
1. Build the solution (
CODE
Ctrl+Shift+B2. Copy the compiled
CODE
MyFirstIl2CppMod.dll CODE
bin/Debug/net6.0/ CODE
GameFolder/BepInEx/plugins/3. Launch the game and check the console output!
ParanormalDev | MelonLoader & ImGui Modding
The following users thanked ParanormalDev for this post: