private static string GetNameSection() { StackTrace st = new StackTrace(2, true); StackFrame sf = st.GetFrame(0); if (sf != null) { MethodBase method = sf.GetMethod(); if (!method.Equals(null)) { Type methodClassType = method.DeclaringType; if (!methodClassType.Equals(null)) { Assembly asm = methodClassType.Assembly; if (!asm.Equals(null)) { object[] attrArray = asm.GetCustomAttributes(typeof(MelonModInfoAttribute), false); if ((attrArray.Count() > 0) && (attrArray[0] != null)) { MelonModInfoAttribute attr = attrArray[0] as MelonModInfoAttribute; if (!string.IsNullOrEmpty(attr.Name)) { return("[" + attr.Name.Replace(" ", "_") + "] "); } } } } } } return(""); }
private static void LoadModFromAssembly(Assembly assembly, string filelocation = null) { MelonModInfoAttribute modInfoAttribute = assembly.GetCustomAttributes(false).FirstOrDefault(x => (x.GetType() == typeof(MelonModInfoAttribute))) as MelonModInfoAttribute; if ((modInfoAttribute != null) && (modInfoAttribute.SystemType != null) && modInfoAttribute.SystemType.IsSubclassOf(typeof(MelonMod))) { bool isCompatible = false; bool isUniversal = false; bool hasAttribute = true; 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)) { isCompatible = true; isUniversal = CurrentGameAttribute.IsCompatibleBecauseUniversal(modGameAttribute); break; } } } else { hasAttribute = false; } try { MelonMod modInstance = Activator.CreateInstance(modInfoAttribute.SystemType) as MelonMod; if (modInstance != null) { modInstance.InfoAttribute = modInfoAttribute; if (modGameAttributes_Count > 0) { modInstance.GameAttributes = modGameAttributes; } else { modInstance.GameAttributes = null; } modInstance.Location = filelocation; modInstance.Compatibility = (isUniversal ? MelonBase.MelonCompatibility.UNIVERSAL : (isCompatible ? MelonBase.MelonCompatibility.COMPATIBLE : (!hasAttribute ? MelonBase.MelonCompatibility.NOATTRIBUTE : MelonBase.MelonCompatibility.INCOMPATIBLE))); if (modInstance.Compatibility < MelonBase.MelonCompatibility.INCOMPATIBLE) { modInstance.Assembly = 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()); } } }
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); } } }