Lightweight Unity C# module detecting unauthorized mod loader frameworks (MelonLoader & BepInEx) via runtime filesystem and proxy DLL heuristic checks.
main 1 Stars 0 Forks 0 Watchers Updated Aug 19, 2024
C# 100%
All Activity
Releases Only
Ignore
unreliablecode / Unity-AntiModLoader โ€” README.md [Visual Studio]
main MARKDOWN
README.md ×
Unity-AntiModLoader / README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Unity Anti Mod Loader Framework

A lightweight, zero-dependency C# security utility for Unity games designed to detect unauthorized mod loader frameworks (**MelonLoader** and **BepInEx**) using fast filesystem verification (`File.Exists` & `Directory.Exists`) and DLL proxy heuristic checks.

---

## Features

- **MelonLoader Detection**:
  - Detects core directory structures (`MelonLoader/`, `MelonLoader/Dependencies/`, `Mods/`, `UserLibs/`).
  - Scans for bootstrap DLLs and loader hooks (`version.dll`, `winmm.dll`, `MelonLoader.dll`, `Bootstrap.dll`).
- **BepInEx Detection**:
  - Detects core directory structures (`BepInEx/`, `BepInEx/core/`, `BepInEx/plugins/`, `BepInEx/patchers/`).
  - Scans for Unity Doorstop files and injection proxies (`winhttp.dll`, `doorstop_config.ini`, `BepInEx.Core.dll`, `0Harmony.dll`).
- **Zero Overhead**: Synchronous filesystem checks executed at startup before scene load with 0 runtime GC pressure.
- **Cross-Platform Compatibility**: Fully compatible with Unity Standalone Windows (x86 / x64), macOS, and Linux builds.

---

## Detection Mechanism

Mod loaders for Unity games rely on DLL proxying / hijacking to intercept the engine runtime before `UnityPlayer.dll` initializes:
1. **BepInEx**: Uses Unity Doorstop (`winhttp.dll` or `doorstop_config.ini`) and places assemblies inside the `BepInEx/` directory.
2. **MelonLoader**: Uses native proxy DLLs (`version.dll` or `winmm.dll`) and initializes modules inside `MelonLoader/Dependencies/`.

`Unity-AntiModLoader` inspects the active game execution root using `Application.dataPath` parent resolution and queries standard path signatures.

---

## Quick Start

### Basic Check

```csharp
using UnityEngine;
using UnityAntiModLoader;

public class SecurityBootstrapper : MonoBehaviour
{
    private void Awake()
    {
        if (AntiModLoader.IsAnyModLoaderPresent())
        {
            Debug.LogError("[Security] Mod loader detected! Terminating game.");
            Application.Quit();
        }
    }
}
```

### Detailed Detection Results

```csharp
using System.Collections.Generic;
using UnityEngine;
using UnityAntiModLoader;
using UnityAntiModLoader.Models;

public class GameSecurityManager : MonoBehaviour
{
    private void Start()
    {
        List<ModDetectionResult> results = AntiModLoader.RunFullCheck();

        foreach (ModDetectionResult result in results)
        {
            Debug.LogWarning($"Detected Framework: {result.FrameworkName}");
            Debug.LogWarning($"Severity Level: {result.Severity}");
            
            foreach (string artifact in result.DetectedArtifacts)
            {
                Debug.LogWarning($"  -> Artifact: {artifact}");
            }
        }
    }
}
```

---

## Project Structure

```
src/
โ”œโ”€โ”€ Detectors/
โ”‚   โ”œโ”€โ”€ BepInExDetector.cs      # BepInEx files, doorstop configs & proxy DLL checks
โ”‚   โ””โ”€โ”€ MelonLoaderDetector.cs  # MelonLoader directory & version.dll checks
โ”œโ”€โ”€ Example/
โ”‚   โ””โ”€โ”€ ModDetectionListener.cs # Example MonoBehaviour integration & auto-quit
โ”œโ”€โ”€ Models/
โ”‚   โ””โ”€โ”€ ModDetectionResult.cs   # Detection result data container & severity enum
โ””โ”€โ”€ AntiModLoader.cs            # Primary entry point & game root resolver
```

---

## License

Released under the [MIT License](LICENSE).
main 0 errors Ready
Ln 1, Col 1 Lines: 99 Spaces: 4 UTF-8 CRLF MARKDOWN