private static void OnApplicationStart() { if (Imports.IsIl2CppGame()) { Assembly_CSharp = Assembly.Load("Assembly-CSharp"); UnhollowerSupport.Initialize(); } SupportModule.Initialize(); MelonModLogger.Log("------------------------------"); MelonModLogger.Log("Unity " + UnityVersion); MelonModLogger.Log("------------------------------"); MelonModLogger.Log("Name: " + CurrentGameAttribute.GameName); MelonModLogger.Log("Developer: " + CurrentGameAttribute.Developer); MelonModLogger.Log("Type: " + (Imports.IsIl2CppGame() ? "Il2Cpp" : (Imports.IsOldMono() ? "Mono" : "MonoBleedingEdge"))); MelonModLogger.Log("------------------------------"); MelonModLogger.Log("Using v" + BuildInfo.Version + " Open-Beta"); MelonModLogger.Log("------------------------------"); LoadMods(); if (Mods.Count > 0) { for (int i = 0; i < Mods.Count; i++) { MelonMod mod = Mods[i]; if (mod != null) { MelonModLogger.Log(mod.InfoAttribute.Name + (!string.IsNullOrEmpty(mod.InfoAttribute.Version) ? (" v" + mod.InfoAttribute.Version) : "") + (!string.IsNullOrEmpty(mod.InfoAttribute.Author) ? (" by " + mod.InfoAttribute.Author) : "") + (!string.IsNullOrEmpty(mod.InfoAttribute.DownloadLink) ? (" (" + mod.InfoAttribute.DownloadLink + ")") : "") ); if (Imports.IsDebugMode()) { MelonModLogger.Log("Preload: " + mod.IsPreload.ToString()); } MelonModLogger.LogModStatus((mod.GameAttributes.Any()) ? (mod.IsUniversal ? 0 : 1) : 2); MelonModLogger.Log("------------------------------"); } } for (int i = 0; i < Mods.Count; i++) { MelonMod mod = Mods[i]; if (mod != null) { try { mod.OnApplicationStart(); } catch (Exception ex) { MelonModLogger.LogModError(ex.ToString(), mod.InfoAttribute.Name); } } } } else { MelonModLogger.Log("No Mods Loaded!"); MelonModLogger.Log("------------------------------"); } }
private static void LoadModFromAssembly(Assembly assembly, bool isPlugin = false) { MelonModInfoAttribute modInfoAttribute = assembly.GetCustomAttributes(false).FirstOrDefault(x => (x.GetType() == typeof(MelonModInfoAttribute))) as MelonModInfoAttribute; if ((modInfoAttribute != null) && (modInfoAttribute.ModType != null) && modInfoAttribute.ModType.IsSubclassOf(typeof(MelonMod))) { bool should_continue = false; bool isUniversal = false; MelonModGameAttribute[] modGameAttributes = assembly.GetCustomAttributes(typeof(MelonModGameAttribute), true) as MelonModGameAttribute[]; int modGameAttributes_Count = modGameAttributes.Length; if (modGameAttributes_Count > 0) { for (int i = 0; i < modGameAttributes_Count; i++) { MelonModGameAttribute modGameAttribute = modGameAttributes[i]; if (CurrentGameAttribute.IsCompatible(modGameAttribute)) { isUniversal = CurrentGameAttribute.IsCompatibleBecauseUniversal(modGameAttribute); should_continue = true; break; } } } else { isUniversal = true; should_continue = true; } if (should_continue) { try { MelonMod modInstance = Activator.CreateInstance(modInfoAttribute.ModType) as MelonMod; if (modInstance != null) { modInstance.IsUniversal = isUniversal; modInstance.IsPlugin = isPlugin; modInstance.InfoAttribute = modInfoAttribute; if (modGameAttributes_Count > 0) { modInstance.GameAttributes = modGameAttributes; } else { modInstance.GameAttributes = null; } modInstance.ModAssembly = assembly; Harmony.HarmonyInstance.Create(assembly.FullName).PatchAll(assembly); Mods.Add(modInstance); } else { MelonModLogger.LogError("Unable to load Mod in " + assembly.GetName() + "! Failed to Create Instance!"); } } catch (Exception e) { MelonModLogger.LogError("Unable to load Mod in " + assembly.GetName() + "! " + e.ToString()); } } else { MelonModLogger.LogModStatus(3); } } }
private static void LoadModsFromAssembly(Assembly assembly) { MelonModInfoAttribute modInfoAttribute = assembly.GetCustomAttribute(typeof(MelonModInfoAttribute)) as MelonModInfoAttribute; if ((modInfoAttribute != null) && (modInfoAttribute.ModType != null) && modInfoAttribute.ModType.IsSubclassOf(typeof(MelonMod))) { MelonModLogger.Log(modInfoAttribute.Name + (!string.IsNullOrEmpty(modInfoAttribute.Version) ? (" v" + modInfoAttribute.Version) : "") + (!string.IsNullOrEmpty(modInfoAttribute.Author) ? (" by " + modInfoAttribute.Author) : "") + (!string.IsNullOrEmpty(modInfoAttribute.DownloadLink) ? (" (" + modInfoAttribute.DownloadLink + ")") : "")); bool should_continue = false; bool isUniversal = false; MelonModGameAttribute[] modGameAttributes = assembly.GetCustomAttributes(typeof(MelonModGameAttribute), true) as MelonModGameAttribute[]; int modGameAttributes_Count = modGameAttributes.Length; if (modGameAttributes_Count > 0) { for (int i = 0; i < modGameAttributes_Count; i++) { MelonModGameAttribute modGameAttribute = modGameAttributes[i]; if (CurrentGameAttribute.IsCompatible(modGameAttribute)) { isUniversal = CurrentGameAttribute.IsCompatibleBecauseUniversal(modGameAttribute); should_continue = true; break; } } } else { isUniversal = true; should_continue = true; } if (should_continue) { try { MelonMod modInstance = Activator.CreateInstance(modInfoAttribute.ModType) as MelonMod; if (modInstance != null) { modInstance.IsUniversal = isUniversal; modInstance.InfoAttribute = modInfoAttribute; if (modGameAttributes_Count > 0) { modInstance.GameAttributes = modGameAttributes; } else { modInstance.GameAttributes = null; } Mods.Add(modInstance); MelonModLogger.LogModStatus((modGameAttributes_Count > 0) ? (isUniversal ? 0 : 1) : 2); } else { MelonModLogger.LogError("Unable to load Mod in " + assembly.GetName() + "! Failed to Create Instance!"); } } catch (Exception e) { MelonModLogger.LogError("Unable to load Mod in " + assembly.GetName() + "! " + e.ToString()); } } else { MelonModLogger.LogModStatus(3); } } }