private void DebugCheck() { if (!MelonDebug.IsEnabled()) { return; } PatchInfo patchInfo = Original.GetPatchInfo(); Patch basePatch = ((patchInfo.prefixes.Count() > 0) ? patchInfo.prefixes.First() : ((patchInfo.postfixes.Count() > 0) ? patchInfo.postfixes.First() : ((patchInfo.transpilers.Count() > 0) ? patchInfo.transpilers.First() : ((patchInfo.finalizers.Count() > 0) ? patchInfo.finalizers.First() : null)))); string melonName = FindMelon(melon => ((basePatch != null) && melon.HarmonyInstance.Id.Equals(basePatch.owner))); if ((melonName == null) && (basePatch != null)) { // Patching using a custom Harmony instance; try to infer the melon assembly from the container type, prefix, postfix, or transpiler. Assembly melonAssembly = basePatch.PatchMethod.DeclaringType?.Assembly; if (melonAssembly != null) { melonName = FindMelon(melon => melon.Assembly == melonAssembly); } } WarnIfHasTranspiler(patchInfo, melonName); WarnIfOriginalMethodIsInlined(melonName); }
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); }
private static bool LoadInterface(string ModulePath) { Assembly assembly = Assembly.LoadFrom(ModulePath); if (assembly == null) { 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); } MelonDebug.Msg($"Support Module Loaded: {ModulePath}"); return(true); }
internal static void SetupModules(SetupType setupType) { if (!Directory.Exists(BaseDirectory)) { return; } 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) { ModuleListing.LoadSpecifierArgs args = new ModuleListing.LoadSpecifierArgs(); args.SetupType = setupType; enumerator.Current.LoadSpecifier(args); if (!args.ShouldLoad) { continue; } if (args.ShouldDelete) { File.Delete(ModulePath); continue; } } Assembly assembly = Assembly.LoadFrom(ModulePath); if (assembly == null) { continue; } Type[] ModuleTypes = assembly.GetValidTypes(x => x.IsSubclassOf(typeof(Module))).ToArray(); if ((ModuleTypes.Length <= 0) || (ModuleTypes[0] == null)) { continue; } Module moduleInstance = Activator.CreateInstance(ModuleTypes[0], BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, null, null) as Module; if (moduleInstance == null) { continue; } moduleInstance.Setup(); enumerator.Current.Interface = moduleInstance; MelonDebug.Msg($"Loaded Compatibility Layer: {enumerator.Current.FileName}"); } catch (Exception ex) { MelonDebug.Error($"Compatibility Layer [{enumerator.Current.FileName}] threw an Exception: {ex}"); continue; } } }
public static bool IsDebugMode() => MelonDebug.IsEnabled();