Beispiel #1
0
        public override void CheckAndCreate(ref List <MelonBase> melonTbl)
        {
            MelonInfoAttribute infoAttribute = null;

            if (!CheckInfoAttribute(ref infoAttribute))
            {
                return;
            }

            List <MelonGameAttribute> gameAttributes = null;

            if (!CheckGameAttributes(ref gameAttributes))
            {
                return;
            }

            if (!CheckPlatformAttribute())
            {
                return;
            }

            if (!CheckPlatformDomainAttribute())
            {
                return;
            }

            if (!CheckVerifyLoaderVersionAttribute())
            {
                return;
            }

            if (!CheckVerifyLoaderBuildAttribute())
            {
                return;
            }

            MelonColorAttribute    coloratt    = MelonUtils.PullAttributeFromAssembly <MelonColorAttribute>(asm);
            MelonPriorityAttribute priorityatt = MelonUtils.PullAttributeFromAssembly <MelonPriorityAttribute>(asm, true);

            MelonBase instance = new MelonCompatibilityLayer.WrapperData()
            {
                Assembly             = asm,
                Info                 = infoAttribute,
                Games                = gameAttributes.ToArray(),
                OptionalDependencies = MelonUtils.PullAttributeFromAssembly <MelonOptionalDependenciesAttribute>(asm),
                ConsoleColor         = (coloratt == null) ? MelonLogger.DefaultMelonColor : coloratt.Color,
                Priority             = (priorityatt == null) ? 0 : priorityatt.Priority,
                Location             = filepath
            }.CreateMelon();

            if (instance == null)
            {
                return;
            }

            melonTbl.Add(instance);
        }
Beispiel #2
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);
        }