internal static void LoadAll(string folderpath, bool is_plugins = false) { string[] filearr = Directory.GetFiles(folderpath).ToArray(); if (filearr.Length <= 0) { return; } MelonLaunchOptions.Core.LoadModeEnum loadMode = is_plugins ? MelonLaunchOptions.Core.LoadMode_Plugins : MelonLaunchOptions.Core.LoadMode_Mods; for (int i = 0; i < filearr.Length; i++) { string filepath = filearr[i]; if (string.IsNullOrEmpty(filepath)) { continue; } if (IsExtensionBlacklisted(filepath)) { MelonLogger.Error($"Invalid File Extension for {filepath}"); continue; } string lowerFilePath = filepath.ToLowerInvariant(); if ((loadMode == MelonLaunchOptions.Core.LoadModeEnum.NORMAL) && !lowerFilePath.EndsWith(".dll")) { continue; } if ((loadMode == MelonLaunchOptions.Core.LoadModeEnum.DEV) && !lowerFilePath.EndsWith(".dev.dll")) { continue; } // To-Do: File Type Check string melonname = MelonUtils.GetFileProductName(filepath); if (string.IsNullOrEmpty(melonname)) { melonname = Path.GetFileNameWithoutExtension(filepath); } if (is_plugins ? MelonHandler.IsPluginAlreadyLoaded(melonname) : MelonHandler.IsModAlreadyLoaded(melonname)) { MelonLogger.Error($"Duplicate File: {filepath}"); continue; } LoadFromFile(filepath); } }
private bool CheckInfoAttribute(ref MelonInfoAttribute infoAttribute) { infoAttribute = MelonUtils.PullAttributeFromAssembly <MelonInfoAttribute>(Assembly); // Legacy Support if (infoAttribute == null) { infoAttribute = MelonUtils.PullAttributeFromAssembly <MelonModInfoAttribute>(Assembly)?.Convert(); } if (infoAttribute == null) { infoAttribute = MelonUtils.PullAttributeFromAssembly <MelonPluginInfoAttribute>(Assembly)?.Convert(); } if ((infoAttribute == null) || (infoAttribute.SystemType == null)) { MelonLogger.Error($"No {((infoAttribute == null) ? "MelonInfoAttribute Found" : "Type given to MelonInfoAttribute")} in {FilePath}"); return(false); } is_plugin = infoAttribute.SystemType.IsSubclassOf(typeof(MelonPlugin)); bool is_mod_subclass = infoAttribute.SystemType.IsSubclassOf(typeof(MelonMod)); if (!is_plugin && !is_mod_subclass) { MelonLogger.Error($"Type Specified {infoAttribute.SystemType.AssemblyQualifiedName} is not a Subclass of MelonPlugin or MelonMod in {FilePath}"); return(false); } bool nullcheck_name = string.IsNullOrEmpty(infoAttribute.Name); bool nullcheck_version = string.IsNullOrEmpty(infoAttribute.Version); if (nullcheck_name || nullcheck_version) { MelonLogger.Error($"No {(nullcheck_name ? "Name" : (nullcheck_version ? "Version" : ""))} given to MelonInfoAttribute in {FilePath}"); return(false); } if (is_plugin ? MelonHandler.IsPluginAlreadyLoaded(infoAttribute.Name) : MelonHandler.IsModAlreadyLoaded(infoAttribute.Name)) { MelonLogger.Error($"Duplicate {(is_plugin ? "Plugin" : "Mod")} {infoAttribute.Name}: {FilePath}"); return(false); } return(true); }
internal static void LoadAll(string folderpath, bool is_plugins = false) { MelonLaunchOptions.Core.LoadModeEnum loadMode = is_plugins ? MelonLaunchOptions.Core.LoadMode_Plugins : MelonLaunchOptions.Core.LoadMode_Mods; string[] filearr = Directory.GetFiles(folderpath).Where(x => Path.GetExtension(x).ToLowerInvariant().Equals(".dll") && ((loadMode == MelonLaunchOptions.Core.LoadModeEnum.DEV) ? x.ToLowerInvariant().EndsWith(".dev.dll") : ((loadMode == MelonLaunchOptions.Core.LoadModeEnum.NORMAL) ? !x.ToLowerInvariant().EndsWith(".dev.dll") : true)) ).ToArray(); if (filearr.Length <= 0) { return; } for (int i = 0; i < filearr.Length; i++) { string filepath = filearr[i]; if (string.IsNullOrEmpty(filepath)) { continue; } string melonname = MelonUtils.GetFileProductName(filepath); if (string.IsNullOrEmpty(melonname)) { melonname = Path.GetFileNameWithoutExtension(filepath); } if (is_plugins ? MelonHandler.IsPluginAlreadyLoaded(melonname) : MelonHandler.IsModAlreadyLoaded(melonname)) { MelonLogger.Error($"Duplicate File: {filepath}"); continue; } LoadFromFile(filepath); } }