Ejemplo n.º 1
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.º 2
0
        private bool CheckPlatformDomainAttribute()
        {
            MelonPlatformDomainAttribute platformDomainAttribute = MelonUtils.PullAttributeFromAssembly <MelonPlatformDomainAttribute>(Assembly);

            if ((platformDomainAttribute == null) ||
                (platformDomainAttribute.Domain == MelonPlatformDomainAttribute.CompatibleDomains.UNIVERSAL))
            {
                return(true);
            }
            bool is_il2cpp_expected_mono = (MelonUtils.IsGameIl2Cpp() && (platformDomainAttribute.Domain == MelonPlatformDomainAttribute.CompatibleDomains.MONO));
            bool is_mono_expected_il2cpp = (!MelonUtils.IsGameIl2Cpp() && (platformDomainAttribute.Domain == MelonPlatformDomainAttribute.CompatibleDomains.IL2CPP));

            if (is_il2cpp_expected_mono || is_mono_expected_il2cpp)
            {
                MelonLogger.Error($"Incompatible Platform Domain for {(is_plugin ? "Plugin" : "Mod")}: {FilePath}");
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        private bool CheckVerifyLoaderVersionAttribute()
        {
            VerifyLoaderVersionAttribute verifyLoaderVersionAttribute = MelonUtils.PullAttributeFromAssembly <VerifyLoaderVersionAttribute>(Assembly);

            if (verifyLoaderVersionAttribute == null)
            {
                return(true);
            }

            bool is_acceptable = verifyLoaderVersionAttribute.IsMinimum
                ? (verifyLoaderVersionAttribute.SemVer <= BuildInfo.Version)
                : (verifyLoaderVersionAttribute.SemVer == BuildInfo.Version);

            if (!is_acceptable)
            {
                MelonLogger.Error($"Incompatible MelonLoader Version for {(is_plugin ? "Plugin" : "Mod")}: {FilePath}");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        private bool CheckVerifyLoaderBuildAttribute()
        {
            VerifyLoaderBuildAttribute verifyLoaderBuildAttribute = MelonUtils.PullAttributeFromAssembly <VerifyLoaderBuildAttribute>(Assembly);

            if ((verifyLoaderBuildAttribute == null) ||
                string.IsNullOrEmpty(verifyLoaderBuildAttribute.HashCode))
            {
                return(true);
            }
            string currentHashCode = MelonUtils.HashCode;

            if (string.IsNullOrEmpty(currentHashCode))
            {
                return(true);
            }
            if (!currentHashCode.Equals(verifyLoaderBuildAttribute.HashCode))
            {
                MelonLogger.Error($"Incompatible MelonLoader Build for {(is_plugin ? "Plugin" : "Mod")}: {FilePath}");
                return(false);
            }
            return(true);
        }
Ejemplo n.º 5
0
        private bool CheckPlatformDomainAttribute()
        {
            MelonPlatformDomainAttribute platformDomainAttribute = MelonUtils.PullAttributeFromAssembly <MelonPlatformDomainAttribute>(Assembly);

            if ((platformDomainAttribute == null) ||
                (platformDomainAttribute.Domain == MelonPlatformDomainAttribute.CompatibleDomains.UNIVERSAL))
            {
                return(true);
            }

            bool is_acceptable = MelonUtils.IsGameIl2Cpp()
                ? (platformDomainAttribute.Domain == MelonPlatformDomainAttribute.CompatibleDomains.IL2CPP)
                : (platformDomainAttribute.Domain == MelonPlatformDomainAttribute.CompatibleDomains.MONO);

            if (!is_acceptable)
            {
                MelonLogger.Error($"Incompatible Platform Domain for {(is_plugin ? "Plugin" : "Mod")}: {FilePath}");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
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 (!CheckProcessAttributes())
            {
                return;
            }

            if (!CheckGameVersionAttribute())
            {
                return;
            }

            if (!CheckPlatformAttribute())
            {
                return;
            }

            if (!CheckPlatformDomainAttribute())
            {
                return;
            }

            if (!CheckVerifyLoaderVersionAttribute())
            {
                return;
            }

            if (!CheckVerifyLoaderBuildAttribute())
            {
                return;
            }

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

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

            if (instance == null)
            {
                return;
            }

            melonTbl.Add(instance);
        }