Lightweight Unity C# module detecting unauthorized mod loader frameworks (MelonLoader & BepInEx) via runtime filesystem and proxy DLL heuristic checks.
main
1 별
0 포크
0 감시자
업데이트됨 Aug 19, 2024
C#
100%
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
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityAntiModLoader.Detectors;
using UnityAntiModLoader.Models;
namespace UnityAntiModLoader
{
public static class AntiModLoader
{
/// <summary>
/// Runs a comprehensive detection check across all supported mod loaders (BepInEx & MelonLoader).
/// </summary>
/// <param name="customGamePath">Optional custom game root path. Defaults to Application.dataPath parent directory.</param>
/// <returns>List of positive detection results.</returns>
public static List<ModDetectionResult> RunFullCheck(string customGamePath = null)
{
string rootPath = customGamePath;
if (string.IsNullOrEmpty(rootPath))
{
rootPath = GetGameRootDirectory();
}
var detections = new List<ModDetectionResult>();
// 1. Scan for BepInEx
var bepinexResult = BepInExDetector.Scan(rootPath);
if (bepinexResult.IsModLoaderDetected)
{
detections.Add(bepinexResult);
}
// 2. Scan for MelonLoader
var melonResult = MelonLoaderDetector.Scan(rootPath);
if (melonResult.IsModLoaderDetected)
{
detections.Add(melonResult);
}
return detections;
}
/// <summary>
/// Returns true if any mod loader (BepInEx or MelonLoader) is detected.
/// </summary>
public static bool IsAnyModLoaderPresent()
{
var results = RunFullCheck();
return results.Count > 0;
}
/// <summary>
/// Resolves the root game installation directory regardless of Editor or Standalone Player runtime.
/// </summary>
public static string GetGameRootDirectory()
{
try
{
if (Application.isEditor)
{
return Directory.GetCurrentDirectory();
}
// In standalone builds, Application.dataPath points to <GameName>_Data
string dataPath = Application.dataPath;
DirectoryInfo parentDir = Directory.GetParent(dataPath);
return parentDir != null ? parentDir.FullName : dataPath;
}
catch (Exception ex)
{
Debug.LogWarning($"[AntiModLoader] Failed to resolve game root directory: {ex.Message}");
return AppDomain.CurrentDomain.BaseDirectory;
}
}
}
}