Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        private void LoadPlugin(Type plugin_type, string filelocation, ref List <MelonBase> melonTbl)
        {
            IPlugin pluginInstance = Activator.CreateInstance(plugin_type) as IPlugin;

            string[] filter = null;
            if (pluginInstance is IEnhancedPlugin)
            {
                filter = ((IEnhancedPlugin)pluginInstance).Filter;
            }

            List <MelonGameAttribute> gamestbl = null;

            if ((filter != null) && (filter.Count() > 0))
            {
                string exe_name = Path.GetFileNameWithoutExtension(string.Copy(MelonUtils.GetApplicationPath()));
                gamestbl = new List <MelonGameAttribute>();
                bool game_found = false;
                foreach (string x in filter)
                {
                    if (string.IsNullOrEmpty(x))
                    {
                        continue;
                    }
                    gamestbl.Add(new MelonGameAttribute(name: x));
                    if (x.Equals(exe_name))
                    {
                        game_found = true;
                    }
                }
                if (!game_found)
                {
                    MelonLogger.Error($"Incompatible Game for {filelocation}");
                    return;
                }
            }

            string plugin_name = pluginInstance.Name;

            if (string.IsNullOrEmpty(plugin_name))
            {
                plugin_name = plugin_type.FullName;
            }

            if (MelonHandler.IsModAlreadyLoaded(plugin_name))
            {
                MelonLogger.Error($"Duplicate File {plugin_name}: {filelocation}");
                return;
            }

            string plugin_version = pluginInstance.Version;

            if (string.IsNullOrEmpty(plugin_version))
            {
                plugin_version = asm.GetName().Version.ToString();
            }
            if (string.IsNullOrEmpty(plugin_version) || plugin_version.Equals("0.0.0.0"))
            {
                plugin_version = "1.0.0.0";
            }

            MelonModWrapper wrapper = new MelonCompatibilityLayer.WrapperData()
            {
                Assembly = asm,
                Info     = new MelonInfoAttribute(typeof(MelonModWrapper), plugin_name, plugin_version),
                Games    = (gamestbl != null) ? gamestbl.ToArray() : null,
                Priority = 0,
                Location = filelocation
            }.CreateMelon <MelonModWrapper>();

            if (wrapper == null)
            {
                return;
            }

            wrapper.pluginInstance = pluginInstance;
            melonTbl.Add(wrapper);
            PluginManager._Plugins.Add(pluginInstance);
        }