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; } } }