Example #1
0
        /// <summary>
        /// Check if a plugin is loaded and has at least the minimum version.
        /// If the plugin is missing or older than minimumVersion, user is shown an error message on screen and false is returned.
        /// Warning: Run only from Start, not from constructor or Awake because some plugins might not be loaded yet!
        /// </summary>
        /// <param name="origin">Your plugin</param>
        /// <param name="guid">Guid of the plugin your plugin is dependant on</param>
        /// <param name="minimumVersion">Minimum version of the required plugin</param>
        /// <param name="level">Level of the issue - <code>Error</code> if plugin can't work, <code>Warning</code> if there might be issues, or <code>None</code> to not show any message.</param>
        /// <returns>True if plugin exists and it's version equals or is newer than minimumVersion, otherwise false</returns>
        public static bool CheckRequiredPlugin(BaseUnityPlugin origin, string guid, Version minimumVersion, LogLevel level = LogLevel.Error)
        {
            var target = BepInEx.Bootstrap.Chainloader.Plugins
                         .Select(MetadataHelper.GetMetadata)
                         .FirstOrDefault(x => x.GUID == guid);

            if (target == null)
            {
                if (level != LogLevel.None)
                {
                    KoikatuAPI.Log(LogLevel.Message | level,
                                   $"{level.ToString().ToUpper()}: Plugin \"{guid}\" required by \"{MetadataHelper.GetMetadata(origin).GUID}\" was not found!");
                }

                return(false);
            }
            if (minimumVersion > target.Version)
            {
                if (level != LogLevel.None)
                {
                    KoikatuAPI.Log(LogLevel.Message | level,
                                   $"{level.ToString().ToUpper()}: Plugin \"{guid}\" required by \"{MetadataHelper.GetMetadata(origin).GUID}\" is outdated! At least v{minimumVersion} is needed!");
                }

                return(false);
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// Check if a plugin that is not compatible with your plugin is loaded.
        /// If the plugin is loaded, user is shown a warning message on screen and true is returned.
        /// Warning: Run only from Start, not from constructor or Awake because some plugins might not be loaded yet!
        /// </summary>
        /// <param name="origin">Your plugin</param>
        /// <param name="guid">Guid of the plugin your plugin is incompatible with</param>
        /// <param name="level">Level of the issue - <code>Error</code> if plugin can't work, <code>Warning</code> if there might be issues, or <code>None</code> to not show any message.</param>
        /// <returns>True if plugin exists, otherwise false</returns>
        public static bool CheckIncompatiblePlugin(BaseUnityPlugin origin, string guid, LogLevel level = LogLevel.Warning)
        {
            var target = BepInEx.Bootstrap.Chainloader.Plugins
                         .Select(MetadataHelper.GetMetadata)
                         .FirstOrDefault(x => x.GUID == guid);

            if (target != null)
            {
                if (level != LogLevel.None)
                {
                    KoikatuAPI.Log(LogLevel.Message | level,
                                   $"{level.ToString().ToUpper()}: Plugin \"{guid}\" is incompatible with \"{MetadataHelper.GetMetadata(origin).GUID}\"!");
                }

                return(true);
            }
            return(false);
        }