using System; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityAntiModLoader.Detectors; using UnityAntiModLoader.Models; namespace UnityAntiModLoader { public static class AntiModLoader { /// /// Runs a comprehensive detection check across all supported mod loaders (BepInEx & MelonLoader). /// /// Optional custom game root path. Defaults to Application.dataPath parent directory. /// List of positive detection results. public static List RunFullCheck(string customGamePath = null) { string rootPath = customGamePath; if (string.IsNullOrEmpty(rootPath)) { rootPath = GetGameRootDirectory(); } var detections = new List(); // 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; } /// /// Returns true if any mod loader (BepInEx or MelonLoader) is detected. /// public static bool IsAnyModLoaderPresent() { var results = RunFullCheck(); return results.Count > 0; } /// /// Resolves the root game installation directory regardless of Editor or Standalone Player runtime. /// public static string GetGameRootDirectory() { try { if (Application.isEditor) { return Directory.GetCurrentDirectory(); } // In standalone builds, Application.dataPath points to _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; } } } }