Пример #1
0
        /// <summary>Applies any Harmony patches used by this mod.</summary>
        private void ApplyHarmonyPatches()
        {
            HarmonyInstance harmony = HarmonyInstance.Create(ModManifest.UniqueID); //create this mod's Harmony instance

            HarmonyPatch_FloatingItemBehavior.ApplyPatch(harmony);

            HarmonyPatch_FloatingItemVisualEffect.Instance = harmony; //pass the harmony instance to this patch (handled differently to support reuse after launch)
            if (Config?.EnableCosmeticFloatingEffect == true)         //if the cosmetic effect is enabled
            {
                HarmonyPatch_FloatingItemVisualEffect.ApplyPatch();
            }
        }
Пример #2
0
        /// <summary>A SMAPI GameLaunched event that enables GMCM support if that mod is available.</summary>
        public void EnableGMCM(object sender, GameLaunchedEventArgs e)
        {
            try
            {
                GenericModConfigMenuAPI api = Helper.ModRegistry.GetApi <GenericModConfigMenuAPI>("spacechase0.GenericModConfigMenu"); //attempt to get GMCM's API instance

                if (api == null)                                                                                                       //if the API is not available
                {
                    return;
                }

                api.RegisterModConfig(ModManifest, () => Config = new ModConfig(), () => Helper.WriteConfig(Config)); //register "revert to default" and "write" methods for this mod's config

                //register an option for each of this mod's config settings
                api.RegisterSimpleOption
                (
                    ModManifest,
                    "Enable cosmetic floating effect",
                    "Check this box to enable the cosmetic \"floating\" effect on items in water.\nDisabling this might improve performance on some systems.",
                    () => Config.EnableCosmeticFloatingEffect,
                    (bool val) =>
                {
                    if (val)                                                 //if this is being set to true
                    {
                        HarmonyPatch_FloatingItemVisualEffect.ApplyPatch();  //apply this patch if necessary
                    }
                    else                                                     //if this is being set to false
                    {
                        HarmonyPatch_FloatingItemVisualEffect.RemovePatch(); //remove this patch if necessary
                    }
                    Config.EnableCosmeticFloatingEffect = val;
                }
                );

                api.RegisterSimpleOption
                (
                    ModManifest,
                    "Teleport floating items to player",
                    "Check this box to make items in water teleport to the nearest player whenever possible.\nEnabling this makes it easier to retrieve items.",
                    () => Config.TeleportItemsOutOfWater,
                    (bool val) => Config.TeleportItemsOutOfWater = val
                );
            }
            catch (Exception ex)
            {
                Monitor.Log($"An error happened while loading this mod's GMCM options menu. Its menu might be missing or fail to work. The auto-generated error message has been added to the log.", LogLevel.Warn);
                Monitor.Log($"----------", LogLevel.Trace);
                Monitor.Log($"{ex.ToString()}", LogLevel.Trace);
            }
        }