Ejemplo n.º 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);
        }
Ejemplo 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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the MelonInfo of the mod with the provided Assembly
        /// </summary>
        /// <param name="modAssembly">Assembly of the mod you want to get MelonInfo for</param>
        /// <returns></returns>
        public static MelonInfoAttribute GetModInfo(System.Reflection.Assembly modAssembly)
        {
            MelonInfoAttribute callingMod = null;

            var cust = MelonInfoAttribute.GetCustomAttributes(modAssembly);

            foreach (var item in cust)
            {
                if (item is MelonInfoAttribute)
                {
                    callingMod = (MelonInfoAttribute)item;
                }
            }

            return(callingMod);
        }
Ejemplo n.º 4
0
 public static void GetMelonAttrib(string filePath, out MelonInfoAttribute melonItemAttribute)
 {
     melonItemAttribute = null;
     try {
         var asm     = Assembly.Load(File.ReadAllBytes(filePath));
         var attribs = Attribute.GetCustomAttributes(asm);
         foreach (var attrib in attribs)
         {
             if (attrib is MelonInfoAttribute)
             {
                 melonItemAttribute = attrib as MelonInfoAttribute;
             }
         }
     }
     catch (Exception e)
     {
         Console.Write(e);
         return;
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Get the MelonInfo of the mod with the provided Assembly
        /// </summary>
        /// <param name="modAssembly">Assembly of the mod you want to get MelonInfo for</param>
        /// <returns></returns>
        public static MelonInfoAttribute GetModInfo(System.Reflection.Assembly modAssembly)
        {
            MelonInfoAttribute callingMod = null;

            var cust = MelonInfoAttribute.GetCustomAttributes(modAssembly);

            var att = modAssembly.GetCustomAttribute <MelonModInfoAttribute>();

            Debug.WriteLine(att is null);

            foreach (var item in cust)
            {
                //Debug.WriteLine(item);

                if (item is MelonInfoAttribute)
                {
                    callingMod = (MelonInfoAttribute)item;
                }
            }

            return(callingMod);
        }