Example #1
0
        public override void Entry(IModHelper helper)
        {
            try
            {
                Config = Helper.ReadConfig <UmbrellaConfig>();
            }
            catch (Exception ex)
            {
                Monitor.Log($"Encountered an error while loading the config.json file. Default settings will be used instead. Full error message:\n-----\n{ex.ToString()}", LogLevel.Error);
                Config = new UmbrellaConfig();
            }
            this.Helper.WriteConfig <UmbrellaConfig>(Config);

            FarmerRendererPatches.Initialize(this.Monitor);
            UmbrellaPatch.Initialize(this.Monitor);

            //add new umbrellas here
            umbrellaTextureBack.Add(this.Helper.Content.Load <Texture2D>("assets/tattered/umbrella_overlay_back.png", ContentSource.ModFolder));
            umbrellaTextureBack.Add(this.Helper.Content.Load <Texture2D>("assets/red/umbrella_overlay_back.png", ContentSource.ModFolder));
            umbrellaTextureBack.Add(this.Helper.Content.Load <Texture2D>("assets/orange/umbrella_overlay_back.png", ContentSource.ModFolder));
            umbrellaTextureBack.Add(this.Helper.Content.Load <Texture2D>("assets/yellow/umbrella_overlay_back.png", ContentSource.ModFolder));
            umbrellaTextureBack.Add(this.Helper.Content.Load <Texture2D>("assets/green/umbrella_overlay_back.png", ContentSource.ModFolder));
            umbrellaTextureBack.Add(this.Helper.Content.Load <Texture2D>("assets/blue/umbrella_overlay_back.png", ContentSource.ModFolder));
            umbrellaTextureBack.Add(this.Helper.Content.Load <Texture2D>("assets/purple/umbrella_overlay_back.png", ContentSource.ModFolder));
            umbrellaTextureBack.Add(this.Helper.Content.Load <Texture2D>("assets/black/umbrella_overlay_back.png", ContentSource.ModFolder));
            //umbrellaTextureBack.Add(this.Helper.Content.Load<Texture2D>("assets/pink/umbrella_overlay_back.png", ContentSource.ModFolder));

            //add new umbrellas here
            umbrellaTextureSide.Add(this.Helper.Content.Load <Texture2D>("assets/tattered/umbrella_overlay_side.png", ContentSource.ModFolder));
            umbrellaTextureSide.Add(this.Helper.Content.Load <Texture2D>("assets/red/umbrella_overlay_side.png", ContentSource.ModFolder));
            umbrellaTextureSide.Add(this.Helper.Content.Load <Texture2D>("assets/orange/umbrella_overlay_side.png", ContentSource.ModFolder));
            umbrellaTextureSide.Add(this.Helper.Content.Load <Texture2D>("assets/yellow/umbrella_overlay_side.png", ContentSource.ModFolder));
            umbrellaTextureSide.Add(this.Helper.Content.Load <Texture2D>("assets/green/umbrella_overlay_side.png", ContentSource.ModFolder));
            umbrellaTextureSide.Add(this.Helper.Content.Load <Texture2D>("assets/blue/umbrella_overlay_side.png", ContentSource.ModFolder));
            umbrellaTextureSide.Add(this.Helper.Content.Load <Texture2D>("assets/purple/umbrella_overlay_side.png", ContentSource.ModFolder));
            umbrellaTextureSide.Add(this.Helper.Content.Load <Texture2D>("assets/black/umbrella_overlay_side.png", ContentSource.ModFolder));
            //umbrellaTextureBack.Add(this.Helper.Content.Load<Texture2D>("assets/pink/umbrella_overlay_back.png", ContentSource.ModFolder));

            //Events
            helper.Events.GameLoop.UpdateTicked    += this.OnUpdateTicked;
            helper.Events.GameLoop.SaveLoaded      += this.OnSaveLoaded;
            helper.Events.GameLoop.ReturnedToTitle += this.OnReturnedToTitle;
            helper.Events.GameLoop.GameLaunched    += this.OnGameLaunched;
            helper.Events.Display.MenuChanged      += this.onMenuChanged;

            harmony = HarmonyInstance.Create(ModManifest.UniqueID);

            //Harmony Patches
            harmony.Patch(
                original: AccessTools.Method(typeof(StardewValley.FarmerRenderer), nameof(StardewValley.FarmerRenderer.draw),
                                             new Type[] { typeof(SpriteBatch), typeof(FarmerSprite.AnimationFrame), typeof(int), typeof(Rectangle), typeof(Vector2), typeof(Vector2), typeof(float), typeof(int), typeof(Color), typeof(float), typeof(float), typeof(Farmer) }),
                postfix: new HarmonyMethod(typeof(FarmerRendererPatches), nameof(FarmerRendererPatches.draw_Postfix)));

            harmony.Patch(
                original: AccessTools.Method(typeof(StardewValley.Menus.IClickableMenu), nameof(StardewValley.Menus.IClickableMenu.drawHoverText),
                                             new System.Type[] { typeof(SpriteBatch), typeof(StringBuilder), typeof(SpriteFont), typeof(int), typeof(int), typeof(int), typeof(string), typeof(int), typeof(string[]), typeof(Item), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(float), typeof(CraftingRecipe), typeof(IList <Item>) }),
                prefix: new HarmonyMethod(typeof(UmbrellaPatch), nameof(UmbrellaPatch.drawHoverTextPrefix)),
                postfix: new HarmonyMethod(typeof(UmbrellaPatch), nameof(UmbrellaPatch.drawHoverTextPostfix))
                );
        }
Example #2
0
        public void OnGameLaunched(object sender, GameLaunchedEventArgs e)
        {
            try
            {
                JsonAssets = Helper.ModRegistry.GetApi <IJsonAssetsApi>("spacechase0.JsonAssets");
                this.Helper.Content.InvalidateCache("Data/mail");
            }
            catch (Exception ex)
            {
                Monitor.Log("Error loading JSON assets", LogLevel.Warn);
            }

            try
            {
                GenericModConfigMenuAPI api = this.Helper.ModRegistry.GetApi <GenericModConfigMenuAPI>("spacechase0.GenericModConfigMenu");

                if (api == null)
                {
                    return;
                }

                api.RegisterModConfig(ModManifest, () => Config = new UmbrellaConfig(), () => Helper.WriteConfig(Config));

                api.RegisterSimpleOption
                (
                    ModManifest,
                    "Enable wetness",
                    "",
                    () => Config.enableWetness,
                    (bool val) => Config.enableWetness = val
                );

                api.RegisterParagraph(ModManifest, "If this box is checked, the farmer will get wet when standing outside in the rain without an umbrella. When the farmer is wet, stamina will be slowly drained. More information about the wetness system can be found on the mod page.");

                api.RegisterSimpleOption(
                    ModManifest,
                    "Stamina drain rate",
                    "",
                    () => Config.staminaDrainRate,
                    (float val) => Config.staminaDrainRate = val
                    );

                api.RegisterParagraph(ModManifest, "How much stamina to drain every 10 minutes (in game time) when the farmer is wet.");
            }
            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);
            }
        }
Example #3
0
        private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
        {
            /* future Climates of Ferngill Integration
             * if (Helper.ModRegistry.IsLoaded(cofModID))
             * {
             *  int currentRain = Helper.Reflection.GetMethod(Helper.ModRegistry.GetApi(cofModID), "GetCurrentRain").Invoke<int>();
             *  Monitor.Log(currentRain.ToString(), LogLevel.Debug);
             * }
             */

            fullRedraw   = false;
            isMaleFarmer = Game1.player.isMale.Value;
            isBaldFarmer = Game1.player.IsBaldHairStyle(Game1.player.getHair());
            customBestHats.AddRange(Config.bestRainHats.Split(',').ToList());
            customGoodHats.AddRange(Config.goodRainHats.Split(',').ToList());

            try
            {
                Config = Helper.ReadConfig <UmbrellaConfig>();
            }
            catch (Exception ex)
            {
                Monitor.Log($"Encountered an error while loading the config.json file. Default settings will be used instead. Full error message:\n-----\n{ex.ToString()}", LogLevel.Error);
                Config = new UmbrellaConfig();
            }

            staminaDrainRatePerTick = (float)(Config.staminaDrainRate / 420);
            this.Helper.Content.InvalidateCache("Data/hats");

            loadUmbrellaTextures();

            if (Config.enableWetness & !Game1.player.mailReceived.Contains("lewis_umbrella"))
            {
                Game1.addMailForTomorrow("lewis_umbrella");
            }
        }