public static FieldInfo MethodBaseToIl2CppFieldInfo(MethodBase method) { if (!MelonUtils.IsGameIl2Cpp()) { throw new Exception("MethodBaseToIl2CppFieldInfo can't be used on Non-Il2Cpp Games"); } if (method == null) { throw new NullReferenceException("The method cannot be null."); } FieldInfo methodPtr = (FieldInfo)GetIl2CppMethodInfoPointerFieldForGeneratedMethod.Invoke(null, new object[] { method }); if (methodPtr == null) { throw new NotSupportedException($"Cannot get IntPtr for {method.Name} as there is no corresponding IL2CPP method"); } return(methodPtr); }
internal static bool Run() { if (!MelonUtils.IsGameIl2Cpp()) { return(true); } if (RunMethod != null) { DisableCloseButton(); int returnval = (int)RunMethod.Invoke(null, new object[0]); EnableCloseButton(); Fixes.ApplicationBase.Run(AppDomain.CurrentDomain); return(returnval == 0); } return(false); }
public static void RegisterAssembly(Assembly asm) { if (!MelonUtils.IsGameIl2Cpp()) return; IEnumerable<Type> typeTbl = asm.GetValidTypes(); if ((typeTbl == null) || (typeTbl.Count() <= 0)) return; foreach (Type type in typeTbl) { object[] attTbl = type.GetCustomAttributes(typeof(RegisterTypeInIl2Cpp), false); if ((attTbl == null) || (attTbl.Length <= 0)) continue; RegisterTypeInIl2Cpp att = (RegisterTypeInIl2Cpp)attTbl[0]; if (att == null) continue; UnhollowerSupport.RegisterTypeInIl2CppDomain(type, att.LogSuccess); } }
internal static void Setup() { WithoutArg["quitfix"] = () => QuitFix = true; WithoutArg["melonloader.disablestartscreen"] = () => StartScreen = false; WithArg["melonloader.loadmodeplugins"] = (string arg) => { if (int.TryParse(arg, out int valueint)) { LoadMode_Plugins = (LoadModeEnum)MelonUtils.Clamp(valueint, (int)LoadModeEnum.NORMAL, (int)LoadModeEnum.BOTH); } }; WithArg["melonloader.loadmodemods"] = (string arg) => { if (int.TryParse(arg, out int valueint)) { LoadMode_Mods = (LoadModeEnum)MelonUtils.Clamp(valueint, (int)LoadModeEnum.NORMAL, (int)LoadModeEnum.BOTH); } }; }
static Core() { AppDomain curDomain = AppDomain.CurrentDomain; HarmonyInstance = new HarmonyLib.Harmony(BuildInfo.Name); Fixes.UnhandledException.Run(curDomain); Fixes.InvariantCurrentCulture.Install(); try { MelonUtils.Setup(); } catch (Exception ex) { MelonLogger.Error("MelonUtils.Setup Exception: " + ex.ToString()); throw ex; } Fixes.ApplicationBase.Run(curDomain); Fixes.ExtraCleanup.Run(); MelonPreferences.Load(); MelonLaunchOptions.Load(); MelonCompatibilityLayer.Setup(curDomain); //PatchShield.Install(); }
static Core() { try { MelonUtils.Setup(); } catch (Exception ex) { MelonLogger.Error("MelonUtils.Setup Exception: " + ex.ToString()); throw ex; } Harmony.HarmonyInstance harmonyInstance = Harmony.HarmonyInstance.Create("MelonLoader"); try { harmonyInstance.Patch(typeof(Thread).GetProperty("CurrentCulture", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), new Harmony.HarmonyMethod(typeof(Core).GetMethod("GetCurrentCulturePrefix", BindingFlags.NonPublic | BindingFlags.Static))); } catch (Exception ex) { MelonLogger.Warning("Thread.CurrentCulture Exception: " + ex.ToString()); } try { harmonyInstance.Patch(typeof(Thread).GetProperty("CurrentUICulture", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), new Harmony.HarmonyMethod(typeof(Core).GetMethod("GetCurrentCulturePrefix", BindingFlags.NonPublic | BindingFlags.Static))); } catch (Exception ex) { MelonLogger.Warning("Thread.CurrentUICulture Exception: " + ex.ToString()); } try { ((AppDomainSetup)typeof(AppDomain).GetProperty("SetupInformationNoCopy", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(AppDomain.CurrentDomain, new object[0])).ApplicationBase = MelonUtils.GameDirectory; } catch (Exception ex) { MelonLogger.Warning("AppDomainSetup.ApplicationBase Exception: " + ex.ToString()); } Directory.SetCurrentDirectory(MelonUtils.GameDirectory); AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveHandler; AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += AssemblyResolveHandler; try { MelonPreferences.LegacyCheck(); } catch (Exception ex) { MelonLogger.Error("MelonPreferences.LegacyCheck Exception: " + ex.ToString()); MelonPreferences.WasError = true; } try { MelonPreferences.Load_Internal(); } catch (Exception ex) { MelonLogger.Error("MelonPreferences.Load_Internal Exception: " + ex.ToString()); MelonPreferences.WasError = true; } if (MelonPreferences.WasLegacyLoaded) { try { MelonPreferences.Save_Internal(); } catch (Exception ex) { MelonLogger.Error("MelonPreferences.Save_Internal Exception: " + ex.ToString()); MelonPreferences.WasError = true; } } MelonPreferences.SaveAfterEntryCreation = true; try { bHaptics_NativeLibrary.Load(); } catch (Exception ex) { MelonLogger.Error("bHaptics_NativeLibrary.Load Exception: " + ex.ToString()); bHaptics.WasError = true; } }
static UnhollowerSupport() { if (!MelonUtils.IsGameIl2Cpp()) { return; } Assembly UnhollowerBaseLib = Assembly.Load("UnhollowerBaseLib"); if (UnhollowerBaseLib == null) { MelonLogger.ThrowInternalFailure("Failed to Load Assembly for UnhollowerBaseLib!"); return; } Il2CppObjectBaseType = UnhollowerBaseLib.GetType("UnhollowerBaseLib.Il2CppObjectBase"); Il2CppMethodInfoType = UnhollowerBaseLib.GetType("UnhollowerBaseLib.Runtime.Il2CppMethodInfo"); Il2CppObjectBaseToPtrMethod = UnhollowerBaseLib.GetType("UnhollowerBaseLib.IL2CPP").GetMethod("Il2CppObjectBaseToPtr"); Il2CppStringToManagedMethod = UnhollowerBaseLib.GetType("UnhollowerBaseLib.IL2CPP").GetMethod("Il2CppStringToManaged"); ManagedStringToIl2CppMethod = UnhollowerBaseLib.GetType("UnhollowerBaseLib.IL2CPP").GetMethod("ManagedStringToIl2Cpp"); GetIl2CppMethodInfoPointerFieldForGeneratedMethod = UnhollowerBaseLib.GetType("UnhollowerBaseLib.UnhollowerUtils").GetMethod("GetIl2CppMethodInfoPointerFieldForGeneratedMethod"); Il2CppCallerCountAttributeType = UnhollowerBaseLib.GetType("UnhollowerBaseLib.Attributes.CallerCountAttribute"); Il2CppCallerCountField = Il2CppCallerCountAttributeType.GetField("Count", BindingFlags.Public | BindingFlags.Instance); }
private static int Start() { bHaptics.Start(); MelonHandler.OnApplicationStart_Plugins(); MelonHandler.LoadMods(); MelonHandler.OnPreSupportModule(); if (!SupportModule.Setup()) { return(1); } if (MelonUtils.IsGameIl2Cpp()) { HarmonyLib.Public.Patching.PatchManager.ResolvePatcher += HarmonyIl2CppMethodPatcher.TryResolve; } MelonCompatibilityLayer.SetupModules(MelonCompatibilityLayer.SetupType.OnApplicationStart); AddUnityDebugLog(); MelonHandler.OnApplicationStart_Mods(); //MelonStartScreen.DisplayModLoadIssuesIfNeeded(); return(0); }
static UnhollowerSupport() { if (!MelonUtils.IsGameIl2Cpp()) { return; } Assembly UnhollowerBaseLib = Assembly.Load("UnhollowerBaseLib"); if (UnhollowerBaseLib == null) { MelonLogger.ThrowInternalFailure("Failed to Load Assembly for UnhollowerBaseLib!"); return; } IL2CPPType = UnhollowerBaseLib.GetType("UnhollowerBaseLib.IL2CPP"); Il2CppObjectBaseType = UnhollowerBaseLib.GetType("UnhollowerBaseLib.Il2CppObjectBase"); CopyMethodInfoStructMethod = UnhollowerBaseLib.GetType("UnhollowerBaseLib.Runtime.UnityVersionHandler").GetMethod("CopyMethodInfoStruct"); Il2CppObjectBaseToPtrMethod = IL2CPPType.GetMethod("Il2CppObjectBaseToPtr"); Il2CppStringToManagedMethod = IL2CPPType.GetMethod("Il2CppStringToManaged"); ManagedStringToIl2CppMethod = IL2CPPType.GetMethod("ManagedStringToIl2Cpp"); ClassInjectorRegisterTypeInIl2Cpp = UnhollowerBaseLib.GetType("UnhollowerRuntimeLib.ClassInjector").GetMethods().First(x => x.Name.Equals("RegisterTypeInIl2Cpp") && !x.IsGenericMethod && (x.GetParameters().Count() == 2)); GetIl2CppMethodInfoPointerFieldForGeneratedMethod = UnhollowerBaseLib.GetType("UnhollowerBaseLib.UnhollowerUtils").GetMethod("GetIl2CppMethodInfoPointerFieldForGeneratedMethod"); Il2CppCallerCountAttributeType = UnhollowerBaseLib.GetType("UnhollowerBaseLib.Attributes.CallerCountAttribute"); Il2CppCallerCountField = Il2CppCallerCountAttributeType.GetField("Count", BindingFlags.Public | BindingFlags.Instance); }
private static int Initialize() { AppDomain curDomain = AppDomain.CurrentDomain; Fixes.UnhandledException.Install(curDomain); Fixes.ServerCertificateValidation.Install(); MelonUtils.Setup(curDomain); Assertions.LemonAssertMapping.Setup(); MelonHandler.Setup(); if (!MonoLibrary.Setup() || !MonoResolveManager.Setup()) { return(1); } HarmonyInstance = new HarmonyLib.Harmony(BuildInfo.Name); Fixes.ForcedCultureInfo.Install(); Fixes.InstancePatchFix.Install(); Fixes.ProcessFix.Install(); PatchShield.Install(); MelonPreferences.Load(); MelonLaunchOptions.Load(); bHaptics.Load(); MelonCompatibilityLayer.Setup(); MelonCompatibilityLayer.SetupModules(MelonCompatibilityLayer.SetupType.OnPreInitialization); MelonHandler.LoadPlugins(); MelonHandler.OnPreInitialization(); return(0); }
public static bool IsIl2CppGame() => MelonUtils.IsGameIl2Cpp();
private static int Il2CppGameSetup() => (MelonUtils.IsGameIl2Cpp() && !Il2CppAssemblyGenerator.Run()) ? 1 : 0;
public static void SetTitle(string title) => MelonUtils.SetConsoleTitle(title);
internal static void Load() { #if DEBUG Core.DebugMode = true; #endif string[] args = Environment.GetCommandLineArgs(); if ((args == null) || (args.Length <= 0)) { return; } for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (string.IsNullOrEmpty(arg)) { continue; } arg = arg.ToLowerInvariant(); int valueint = 0; string valuestr = null; if ((i + 1) < args.Length) { valuestr = args[i + 1]; } switch (arg) { #if !DEBUG case "--melonloader.debug": Core.DebugMode = true; goto default; #endif case "--quitfix": Core.QuitFix = true; goto default; case "--melonloader.agfregenerate": Il2CppAssemblyGenerator.ForceRegeneration = true; goto default; case "--melonloader.agfvdumper": if (string.IsNullOrEmpty(valuestr)) { goto default; } Il2CppAssemblyGenerator.ForceVersion_Dumper = valuestr; goto default; case "--melonloader.agfvunhollower": if (string.IsNullOrEmpty(valuestr)) { goto default; } Il2CppAssemblyGenerator.ForceVersion_Il2CppAssemblyUnhollower = valuestr; goto default; case "--melonloader.agfvunity": if (string.IsNullOrEmpty(valuestr)) { goto default; } Il2CppAssemblyGenerator.ForceVersion_UnityDependencies = valuestr; goto default; case "--melonloader.loadmodeplugins": if (string.IsNullOrEmpty(valuestr)) { goto default; } if (!int.TryParse(valuestr, out valueint)) { goto default; } Core.LoadMode_Plugins = (Core.LoadModeEnum)MelonUtils.Clamp(valueint, (int)Core.LoadModeEnum.NORMAL, (int)Core.LoadModeEnum.BOTH); goto default; case "--melonloader.loadmodemods": if ((i + 1) < args.Length) { valuestr = args[i + 1]; } if (string.IsNullOrEmpty(valuestr)) { goto default; } if (!int.TryParse(valuestr, out valueint)) { goto default; } Core.LoadMode_Mods = (Core.LoadModeEnum)MelonUtils.Clamp(valueint, (int)Core.LoadModeEnum.NORMAL, (int)Core.LoadModeEnum.BOTH); goto default; default: break; } } }
public static string GetGameDataDirectory() => MelonUtils.GetGameDataDirectory();
private static void SendError(string txt) => ManualMelonError(MelonUtils.GetMelonFromStackTrace(), txt ?? "null");
public static string GetAssemblyDirectory() => MelonUtils.GetManagedDirectory();
public static void Unhook(IntPtr target, IntPtr detour) => MelonUtils.NativeHookDetach(target, detour);
public static string GetUnityVersion() => string.Copy(MelonUtils.GetUnityVersion());