How to detect BepInEx and MelonLoader in your Unity game

BepInEx and MelonLoader get into a Unity game through a proxy DLL that Windows loads from the game folder. Here is how that works, and three checks in C# that find the traces they leave.

By Tim UhlottFounder|Last updated: December 4, 2026|16 minutes read
unityanti cheatmod loader
How to detect BepInEx and MelonLoader in your Unity game
A player downloads a zip file and extracts it into the folder of your Unity game. The zip has a winhttp.dll, a doorstop_config.ini, and a folder named BepInEx. They start the game as always. Before your first scene loads, code from other people is already running inside your game. None of your files was changed for that. The game folder only got a few new files. You cannot stop a mod loader from starting, because it runs before your own code does. But it leaves traces in the folder and in the process, and your game can look for them. Let us first look at how a loader gets into a Unity game through a proxy DLL. Then we go through the traces it leaves, and write a small check in C# for each of them.

What is a mod loader?

A mod loader is a tool that loads code from other people into your game. The two best known ones for Unity are BepInEx and MelonLoader. BepInEx (opens in a new tab) describes itself as "a plugin / modding framework for Unity Mono, IL2CPP and .NET framework games". MelonLoader (opens in a new tab) calls itself "a Universal Mod-Loader for Games built in the Unity Engine". The loader itself is not a cheat. It only loads mods. A mod can be anything, a new language or a bigger inventory. But it can also be a wallhack or a free shop. Under the hood, most mods use a patching library like HarmonyX. I wrote an extended article about What HarmonyX is and how Unity developers can detect it.

How the loader gets in: the proxy DLL

A Unity game on Windows does not only load its own files. It also uses DLLs that belong to Windows, for example winhttp.dll for network requests and version.dll for version information. The game asks for such a DLL by name, without a full path. Windows then searches a list of places. Microsoft documents this list as the DLL search order (opens in a new tab). Two entries in it matter for us, and they come in this order:
  1. "The folder from which the application loaded."
  2. "The system folder."
So the game folder is searched before the Windows system folder. If a file named winhttp.dll is in the game folder, Windows loads that one and never gets to the real one in System32. Windows protects a short list of "known DLLs" from this. Microsoft keeps that list in the registry, and a DLL that is not on it can be replaced this way. This is what the loaders use. BepInEx is started by a small tool named UnityDoorstop (opens in a new tab). Doorstop is a tool to execute managed .NET assemblies inside Unity as early as possible. And then relies on winhttp.dll to inject itself into the game. MelonLoader does the same with another name. MelonLoader uses a proxy DLL to trick the game into loading itself on startup. By Default the Proxy is named as 'version.dll'. The file is called a proxy DLL because it stands in front of the real one. The game still needs the real functions of winhttp.dll. So the proxy loads the original DLL from the system folder and passes every call on to it. You can read this in the Doorstop source (opens in a new tab). The game works as before, and it has one more DLL in its process that it did not ask for.
Remember: Windows itself loads the proxy, because the file has the name of a system DLL and is in the game folder.

What the proxy does after it is loaded

Once the proxy is loaded, the loader wants to run managed code, which means C# assemblies, and it wants to do that before your game code runs. Let us go through what Doorstop does on Windows. The steps are in its entrypoint.c (opens in a new tab).
  1. Windows loads the proxy winhttp.dll into the game process.
  2. The proxy reads doorstop_config.ini. The file says which assembly to start. For BepInEx 5 that is BepInEx\core\BepInEx.Preloader.dll.
  3. The proxy hooks the Windows function GetProcAddress for the Unity player. Unity uses this function to find the start function of its scripting runtime.
  4. When Unity asks for mono_jit_init_version (Mono) or il2cpp_init (IL2CPP), it gets a function of Doorstop back.
  5. Unity calls that function. Doorstop starts the real runtime, and then runs the loader assembly first.
  6. The loader loads the mods. After that, your game continues as normal.
On a Mono build the mods then live in the same runtime as your code. The Doorstop README says: "On Unity Mono, your assembly is executed in the same runtime." On an IL2CPP build there is no runtime that can load a C# assembly, and the loader brings its own. The README says: "On Il2Cpp, your assembly is executed in CoreCLR runtime because Il2Cpp cannot run managed assemblies." The mods run in that second runtime and reach into your game through the native IL2CPP functions.

Common questions about mod loaders

Does IL2CPP stop mod loaders? No. MelonLoader supports IL2CPP games, and BepInEx 6 does too, although its README says that "currently only Unity Mono has stable releases". IL2CPP makes mods harder to write, but the loader still gets in. Do I notice it in my files? Not in your own files. No file that you shipped is changed, and a hash of your files is still correct. Only the folder is different, because it has new files in it. Can I delete the loader files at startup? No. When your first script runs, the proxy is already loaded and the mods are already running. Does it work on Linux and macOS? Yes, but without a proxy DLL. There the game is started through a script. In the Doorstop script (opens in a new tab), LD_PRELOAD on Linux and DYLD_INSERT_LIBRARIES on macOS tell the system to load libdoorstop into the game first. Is every mod a cheat? No, and that is your decision to make. In a single player game, mods can be welcome. In a game with a leaderboard, a shop, or other players, the same loader runs the cheats.
Takeaway: A mod loader adds files and never changes yours. A check for changed files finds nothing, so look for files and code that should not be there.

Trace 1: files next to the game

The first trace is the simplest one. The loader has to be installed, and the files are in your game folder. I looked at the official downloads to see what a fresh install puts there:
BepInEx 5MelonLoader 0.7
Proxy DLLwinhttp.dllversion.dll
Configdoorstop_config.ini, .doorstop_versionUserData/Loader.cfg
FolderBepInEx/MelonLoader/
Folders for modsBepInEx/plugins/Mods/, Plugins/
We look for these names next to the game:
using System.IO; using UnityEngine; public static class ModLoaderCheck { private static readonly string[] loaderFiles = { "doorstop_config.ini", ".doorstop_version" }; private static readonly string[] loaderFolders = { "BepInEx", "MelonLoader" }; public static bool HasLoaderFiles() { // On Windows, dataPath is the "MyGame_Data" folder. // The game folder is one level above it. string root = Directory.GetParent(Application.dataPath).FullName; foreach (string file in loaderFiles) { if (File.Exists(Path.Combine(root, file))) { return true; } } foreach (string folder in loaderFolders) { if (Directory.Exists(Path.Combine(root, folder))) { return true; } } return false; } }
I left Mods and Plugins out of the list on purpose. These names are too common, and your own game may have a folder with that name. A file on the disk also does not prove that the loader is running. The player may have turned it off. I would treat this trace as a hint and the next one as the proof.

Trace 2: a Windows DLL that was loaded from the game folder

The second trace is the proxy itself. A DLL named winhttp.dll in a process is normal. A winhttp.dll that was loaded from your game folder is not, because you did not ship one. Windows can tell us where a loaded DLL came from. GetModuleHandle (opens in a new tab) returns a handle to a module that "must have been loaded by the calling process". GetModuleFileName (opens in a new tab) returns "the fully qualified path for the file that contains the specified module". So we ask for the DLL by name, get its path, and check if the path is inside the Windows folder:
using System; using System.Runtime.InteropServices; using System.Text; public static class ProxyDllCheck { [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] private static extern IntPtr GetModuleHandleW(string moduleName); [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] private static extern uint GetModuleFileNameW( IntPtr module, StringBuilder fileName, uint size); private static readonly string[] proxyNames = { "winhttp.dll", "version.dll" }; public static bool HasProxyDll() { string windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows); foreach (string name in proxyNames) { IntPtr module = GetModuleHandleW(name); if (module == IntPtr.Zero) { // Not loaded at all. Nothing to check. continue; } StringBuilder path = new StringBuilder(1024); if (GetModuleFileNameW(module, path, (uint)path.Capacity) == 0) { continue; } // The real DLL is somewhere below C:\Windows. if (!path.ToString().StartsWith( windowsFolder, StringComparison.OrdinalIgnoreCase)) { return true; } } return false; } }
We call the two Windows functions directly and do not use Process.GetCurrentProcess().Modules. The reason is IL2CPP. The Unity manual (opens in a new tab) says: "IL2CPP doesn't support the System.Diagnostics.Process API methods." The two functions above work on both scripting backends. The sample is for Windows builds only. There is one more small trace of this kind. Doorstop sets an environment variable in the game process. Its README says about DOORSTOP_INITIALIZED: "Always set to TRUE." So one line finds a default Doorstop setup:
bool doorstop = Environment.GetEnvironmentVariable("DOORSTOP_INITIALIZED") != null;

Trace 3: assemblies that are not yours

The third trace is the loaded code. On a Mono build, the loader and its mods are loaded into the same runtime as your game, and they are in the list of loaded assemblies with their names:
using System; using System.Reflection; public static class AssemblyCheck { private static readonly string[] loaderPrefixes = { "BepInEx", "MelonLoader", "0Harmony", "MonoMod" }; public static bool HasLoaderAssembly() { foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { string name = assembly.GetName().Name; foreach (string prefix in loaderPrefixes) { if (name.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) { return true; } } } return false; } }
0Harmony and MonoMod are the patching libraries that come with BepInEx. If your own game uses one of them, remove that entry. On an IL2CPP build I would not expect this check to find anything. The loader runs in its own CoreCLR runtime there, and the Doorstop README says that this runtime "is isolated from Il2Cpp". So on IL2CPP, use the first two traces. Here are the three traces next to each other:
TraceMonoIL2CPPHow strong
Files next to the gameyesyesA hint. The loader may be turned off
Proxy DLL from the game folderyesyesStrong. The loader is in the process
Loader assembliesyesnot expectedStrong. The loader code is running

What does it cost?

Very little. The file check looks at four names. The proxy check asks Windows two questions per DLL. The assembly check goes through a list of names once. The loader gets in at startup, so one check at startup finds it. I would still repeat the check from time to time, for example after a level was loaded. If it runs only once, a mod has to remove it only once.

What these checks do not stop

The checks detect a loader that was installed in the normal way. They do not keep it out, and they can be avoided. The biggest limit is that the loader runs before your code. On a Mono build a mod can find your check and replace the method, so that it always returns false. Obfuscation makes that harder, because the mod author first has to find the method. The names can change too. The MelonLoader README lists 13 file names its proxy can have, among them winmm.dll, dinput8.dll, and d3d11.dll. A launch option named --melonloader.basedir moves its folder. And BepInEx has a setting that hides its manager object. The description in the source says it "can fix loading issues in some games that attempt to prevent BepInEx from being loaded". The loader authors already react to games that try to detect them. A better version of the second check starts from your own files and needs no list of bad names. You know which DLL files you ship in your game folder, and every other DLL that was loaded from there does not belong to your game. And a cheat does not need one of these loaders. A custom injector leaves none of these traces. What you do after a find is up to you. I would not ban on the first hit, and in a single player game I would not punish at all. I would turn off what has to stay fair: the leaderboard, the achievements, or the online mode. For anything that touches other players or real money, you still need checks on the server. A mod can change everything the client does, but your server decides what it accepts.

Conclusion

BepInEx and MelonLoader get into a Unity game through a proxy DLL. Windows loads it, because it has the name of a system DLL and is in the game folder. Your own files stay as they are, so a check for changed files does not find it. What you can find are loader files next to the game, a Windows DLL that was loaded from the game folder, and on Mono the assemblies that are not yours. Repeat the check, and decide per game mode how strict you want to be. The samples above are the idea in its smallest form, for Windows. A real game also needs macOS and Linux, lists you can change without a new build, repeated checks, and a reaction that fits your game. If you do not want to write and test all of that yourself, have a look at GuardingPearSoftware Anti-Cheat. It has a detector that looks for these three traces on desktop builds and reports what it found.
00 views
00 shares

Discussion about this post

Comments are reviewed before they appear on the article.

No comments yet. Be the first to start the discussion.

Frequently asked questions

Newsletter

Stay in the Loop.

Subscribe to our newsletter to receive the latest news, updates, and special offers directly in your inbox. Don't miss out!