#if STANDALONE using HarmonyLib; using System; using System.IO; using System.Reflection; using UnityEngine; #if CPP using UnhollowerRuntimeLib; #endif namespace UnityExplorer { public class ExplorerStandalone : IExplorerLoader { /// /// Call this to initialize UnityExplorer. Optionally, also subscribe to the 'OnLog' event to handle logging. /// /// The new (or active, if one exists) instance of ExplorerStandalone. public static ExplorerStandalone CreateInstance() { if (Instance != null) return Instance; return new ExplorerStandalone(); } private ExplorerStandalone() { Init(); } public static ExplorerStandalone Instance { get; private set; } /// /// Invoked whenever Explorer logs something. Subscribe to this to handle logging. /// public static event Action OnLog; public Harmony HarmonyInstance => s_harmony; public static readonly Harmony s_harmony = new Harmony(ExplorerCore.GUID); public string ExplorerFolder { get { if (s_explorerFolder == null) { s_explorerFolder = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath; s_explorerFolder = Uri.UnescapeDataString(s_explorerFolder); s_explorerFolder = Path.GetDirectoryName(s_explorerFolder); } return s_explorerFolder; } } private static string s_explorerFolder; public string ConfigFolder => ExplorerFolder; Action IExplorerLoader.OnLogMessage => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Log); }; Action IExplorerLoader.OnLogWarning => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Warning); }; Action IExplorerLoader.OnLogError => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Error); }; private void Init() { Instance = this; #if CPP ClassInjector.RegisterTypeInIl2Cpp(); var obj = new GameObject( "ExplorerBehaviour", new Il2CppSystem.Type[] { Il2CppType.Of() } ); #else var obj = new GameObject( "ExplorerBehaviour", new Type[] { typeof(ExplorerBehaviour) } ); #endif obj.hideFlags = HideFlags.HideAndDontSave; GameObject.DontDestroyOnLoad(obj); new ExplorerCore(); } public class ExplorerBehaviour : MonoBehaviour { #if CPP public ExplorerBehaviour(IntPtr ptr) : base(ptr) { } #endif internal void Update() { ExplorerCore.Update(); } } } } #endif