internal static void Setup() { Assembly assembly = Assembly.Load( File.Exists(Path.Combine(MelonUtils.GetManagedDirectory(), "UnityEngine.CoreModule.dll")) ? "UnityEngine.CoreModule" : "UnityEngine"); if (assembly != null) { Type applicationType = assembly.GetType("UnityEngine.Application"); if (applicationType != null) { PropertyInfo versionProp = applicationType.GetProperty("version"); if (versionProp != null) { Application_get_version = versionProp.GetGetMethod(); } PropertyInfo buildGUIDProp = applicationType.GetProperty("buildGUID"); if (buildGUIDProp != null) { Application_get_buildGUID = buildGUIDProp.GetGetMethod(); } } } string game_version = "0"; MethodInfoCheck(Application_get_version, ref game_version); MethodInfoCheck(Application_get_buildGUID, ref game_version); Version = game_version; MelonLogger.Msg($"Game Version: {game_version}"); SetDefaultConsoleTitleWithGameName(game_version); }
internal static bool Setup() { UnityEngine_CoreModule_Path = Path.Combine(MelonUtils.GetManagedDirectory(), "UnityEngine.CoreModule.dll"); BaseDirectory = Path.Combine(Path.Combine(Path.Combine(MelonUtils.BaseDirectory, "MelonLoader"), "Dependencies"), "SupportModules"); if (!Directory.Exists(BaseDirectory)) { MelonLogger.Error("Failed to Find SupportModules Directory!"); return(false); } LemonEnumerator <ModuleListing> enumerator = new LemonEnumerator <ModuleListing>(Modules); while (enumerator.MoveNext()) { string ModulePath = Path.Combine(BaseDirectory, enumerator.Current.FileName); if (!File.Exists(ModulePath)) { continue; } try { if (enumerator.Current.LoadSpecifier != null) { if (!enumerator.Current.LoadSpecifier()) { File.Delete(ModulePath); continue; } } if (Interface != null) { continue; } if (!LoadInterface(ModulePath)) { continue; } } catch (Exception ex) { MelonDebug.Error($"Support Module [{enumerator.Current.FileName}] threw an Exception: {ex}"); continue; } } if (Interface == null) { MelonLogger.Error("No Support Module Loaded!"); return(false); } return(true); }
internal static bool Initialize() { MelonLogger.Msg("Loading Support Module..."); string BaseDirectory = Path.Combine(Path.Combine(Path.Combine(MelonUtils.GameDirectory, "MelonLoader"), "Dependencies"), "SupportModules"); if (!Directory.Exists(BaseDirectory)) { MelonLogger.Error("Failed to Find SupportModules Directory!"); return(false); } string ModuleName = (MelonUtils.IsGameIl2Cpp() ? "Il2Cpp.dll" : (File.Exists(Path.Combine(MelonUtils.GetManagedDirectory(), "UnityEngine.CoreModule.dll")) ? "Mono.dll" : (IsOldUnity() ? "Mono.Pre-5.dll" : "Mono.Pre-2017.dll"))); string ModulePath = Path.Combine(BaseDirectory, ModuleName); if (!File.Exists(ModulePath)) { MelonLogger.Error("Failed to Find Support Module " + ModuleName + "!"); return(false); } try { Assembly assembly = Assembly.LoadFrom(ModulePath); if (assembly == null) { MelonLogger.Error("Failed to Load Assembly from " + ModuleName + "!"); return(false); } Type type = assembly.GetType("MelonLoader.Support.Main"); if (type == null) { MelonLogger.Error("Failed to Get Type MelonLoader.Support.Main!"); return(false); } MethodInfo method = type.GetMethod("Initialize", BindingFlags.NonPublic | BindingFlags.Static); if (method == null) { MelonLogger.Error("Failed to Get Method Initialize!"); return(false); } Interface = (ISupportModule_To)method.Invoke(null, new object[] { new SupportModule_From() }); if (Interface == null) { MelonLogger.Error("Failed to Initialize Interface!"); return(false); } } catch (Exception ex) { MelonLogger.Error(ex.ToString()); return(false); } return(true); }
public static string GetAssemblyDirectory() => MelonUtils.GetManagedDirectory();