Lightweight Unity C# module detecting unauthorized mod loader frameworks (MelonLoader & BepInEx) via runtime filesystem and proxy DLL heuristic checks.
main 1 Sterren 0 Vorken 0 Kijkers Bijgewerkt Aug 19, 2024
C# 100%
Alle activiteit
Alleen releases
Negeren
unreliablecode / Unity-AntiModLoader โ€” src/Detectors/MelonLoaderDetector.cs [Visuele studio]
main CSHARP
MelonLoaderDetector.cs ×
Unity-AntiModLoader / src / Detectors / MelonLoaderDetector.cs
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
using System;
using System.IO;
using UnityAntiModLoader.Models;

namespace UnityAntiModLoader.Detectors
{
    public static class MelonLoaderDetector
    {
        // Known MelonLoader directory structures
        private static readonly string[] s_KnownDirectories = new string[]
        {
            "MelonLoader",
            "MelonLoader/Dependencies",
            "MelonLoader/Managed",
            "MelonLoader/Libs",
            "Mods",
            "Plugins",
            "UserLibs",
            "UserData"
        };

        // Known MelonLoader binaries, proxies, and logfiles
        private static readonly string[] s_KnownFiles = new string[]
        {
            "version.dll",
            "winmm.dll",
            "MelonLoader/MelonLoader.dll",
            "MelonLoader/Dependencies/Bootstrap.dll",
            "MelonLoader/Dependencies/Harmony/0Harmony.dll",
            "MelonLoader/Dependencies/Il2CppAssemblyGenerator/Il2CppAssemblyGenerator.dll",
            "MelonLoader/Dependencies/Mono.Cecil.dll",
            "MelonLoader/Latest.log"
        };

        /// <summary>
        /// Scans the game directory for MelonLoader mod loader artifacts.
        /// </summary>
        /// <param name="gameRootDirectory">Base path of the game executable.</param>
        /// <returns>ModDetectionResult with detected files and directories.</returns>
        public static ModDetectionResult Scan(string gameRootDirectory)
        {
            var result = new ModDetectionResult
            {
                FrameworkName = "MelonLoader",
                DetectionTimestamp = DateTime.UtcNow
            };

            if (string.IsNullOrEmpty(gameRootDirectory) || !Directory.Exists(gameRootDirectory))
            {
                return result;
            }

            // 1. Check for known MelonLoader directories
            foreach (string relDir in s_KnownDirectories)
            {
                string fullDirPath = Path.Combine(gameRootDirectory, relDir);
                try
                {
                    if (Directory.Exists(fullDirPath))
                    {
                        result.DetectedArtifacts.Add($"Directory: {relDir}");
                    }
                }
                catch
                {
                    // Ignore filesystem access exceptions
                }
            }

            // 2. Check for known MelonLoader files & bootstrap hooks
            foreach (string relFile in s_KnownFiles)
            {
                string fullFilePath = Path.Combine(gameRootDirectory, relFile);
                try
                {
                    if (File.Exists(fullFilePath))
                    {
                        result.DetectedArtifacts.Add($"File: {relFile}");
                    }
                }
                catch
                {
                    // Ignore filesystem access exceptions
                }
            }

            // Evaluate severity
            if (result.DetectedArtifacts.Count > 0)
            {
                result.Severity = result.DetectedArtifacts.Count >= 2 ? DetectionSeverity.Critical : DetectionSeverity.High;
            }

            return result;
        }
    }
}
main 0 fouten Klaar
Ln 1, Kol 1 Lijnen: 96 Ruimtes: 4 UTF-8 CRLF CSHARP