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 void Load() { LemonEnumerator <string> argEnumerator = new LemonEnumerator <string>(Environment.GetCommandLineArgs()); while (argEnumerator.MoveNext()) { if (string.IsNullOrEmpty(argEnumerator.Current)) { continue; } if (!argEnumerator.Current.StartsWith("--")) { continue; } string cmd = argEnumerator.Current.Remove(0, 2); if (WithoutArg.TryGetValue(cmd, out Action withoutArgFunc)) { withoutArgFunc(); } else if (WithArg.TryGetValue(cmd, out Action <string> withArgFunc)) { if (!argEnumerator.MoveNext()) { continue; } if (string.IsNullOrEmpty(argEnumerator.Current)) { continue; } if (argEnumerator.Current.StartsWith("--")) { continue; } withArgFunc(argEnumerator.Current); } } }
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; } } }