/// <summary> /// Gets all mods, this should be fired before gameInitialization. /// </summary> public void GetMods() { ModBase[] mods = FindObjectsOfType <ModBase>(); foreach (ModBase mod in mods) { ModInfo info = new ModInfo { ModClass = mod }; Logging.Info(Language.ForgeModRegistered + GenericHelpers.GetAttribute <Mod>(mod.GetType()).ModId); mod.transform.SetParent(transform.parent); _registeredMods.Add(GenericHelpers.GetAttribute <Mod>(mod.GetType()).ModId, info); } foreach (Type type in GenericHelpers.GetTypesWithAttribute(typeof(Mod), null)) { if (mods.Any(m => type.Name == m.GetType().Name)) { continue; } ModInfo info = TypeToModInfo(type); Logging.Info(Language.ForgeModRegistered + GenericHelpers.GetAttribute <Mod>(type).ModId); _registeredMods.Add(GenericHelpers.GetAttribute <Mod>(type).ModId, info); } }
/// <summary> /// Gets a list of mods from the given assembly /// </summary> /// <param name="assembly">The assembly from which the mods will be registered</param> /// <returns>An array of all found mods converted to ModInfo objects</returns> public ModInfo[] GetMods(Assembly assembly) { List <ModInfo> modInfos = new List <ModInfo>(); foreach (Type type in GenericHelpers.GetTypesWithAttribute(typeof(Mod), assembly)) { ModInfo info = TypeToModInfo(type); Logging.Info(Language.ForgeModRegistered + GenericHelpers.GetAttribute <Mod>(type).ModId); _registeredMods.Add(GenericHelpers.GetAttribute <Mod>(type).ModId, info); modInfos.Add(info); } return(modInfos.ToArray()); }
/// <summary> /// Parses all config classes for file conversion /// </summary> /// <param name="assembly">The assembly to parse from</param> private Dictionary <string, Dictionary <string, Dictionary <string, ConfigParseItem> > > ParseConfig(Assembly assembly = null) { Dictionary <string, Dictionary <string, Dictionary <string, ConfigParseItem> > > parseDict = new Dictionary <string, Dictionary <string, Dictionary <string, ConfigParseItem> > >(); foreach (Type type in GenericHelpers.GetTypesWithAttribute(typeof(ConfigGroup), assembly)) { if (!type.IsAbstract && !type.IsSealed) { throw new ForgeCritical(Language.ForgeCriticalInvalidConfigGroupClassType + type.Name); } ConfigGroup config = type.GetCustomAttributes(typeof(ConfigGroup), true).FirstOrDefault() as ConfigGroup; foreach (PropertyInfo propertyInfo in type.GetProperties()) { //Turn all config items into ParseItems foreach (ConfigItem configItem in propertyInfo.GetCustomAttributes(typeof(ConfigItem), true)) { ConfigParseItem parseItem = new ConfigParseItem { ConfigDefault = configItem.DefaultValue, ConfigName = configItem.Name, Property = propertyInfo, }; if (parseItem.ConfigName == null) { parseItem.ConfigName = parseItem.Property.Name; } if (config != null && parseDict.ContainsKey(config.FileName)) { if (parseDict[config.FileName].ContainsKey(config.GroupName)) { parseDict[config.FileName][config.GroupName].Add(parseItem.ConfigName, parseItem); } else { parseDict[config.FileName].Add(config.GroupName, new Dictionary <string, ConfigParseItem> { { parseItem.ConfigName, parseItem } }); } } else { if (config != null) { parseDict.Add( config.FileName, new Dictionary <string, Dictionary <string, ConfigParseItem> > { { config.GroupName, new Dictionary <string, ConfigParseItem> { { parseItem.ConfigName, parseItem } } } } ); } } } } } return(parseDict); }