/*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            ModHelper = helper;
            monitor   = Monitor;

            if (this.Helper.ModRegistry.IsLoaded("DIGUS.BUTCHER"))
            {
                Monitor.Log("Animal Husbandry Mod can't run along side its older version, ButcherMod. " +
                            "You need to copy the 'data' directory from the ButcherMod directory, into the AnimalHusbandryMod directory, then delete the ButcherMod directory. " +
                            "Animal Husbandry Mod won't load until this is done.", LogLevel.Error);
            }
            else
            {
                DataLoader                   = new DataLoader(helper);
                _meatCleaverSpawnKey         = DataLoader.ModConfig.AddMeatCleaverToInventoryKey;
                _inseminationSyringeSpawnKey = DataLoader.ModConfig.AddInseminationSyringeToInventoryKey;
                _feedingBasketSpawnKey       = DataLoader.ModConfig.AddFeedingBasketToInventoryKey;

                helper.Events.GameLoop.SaveLoaded += DataLoader.ToolsLoader.ReplaceOldTools;
                helper.Events.GameLoop.SaveLoaded += (x, y) => FarmerLoader.LoadData();
                helper.Events.GameLoop.SaveLoaded += (x, y) => DataLoader.ToolsLoader.LoadMail();

                helper.Events.GameLoop.DayStarted += (x, y) => DataLoader.LivingWithTheAnimalsChannel.CheckChannelDay();

                //TimeEvents.AfterDayStarted += (x, y) => EventsLoader.CheckEventDay();

                if (!DataLoader.ModConfig.DisableMeat)
                {
                    helper.Events.GameLoop.DayStarted += (x, y) => DataLoader.RecipeLoader.MeatFridayChannel.CheckChannelDay();
                    ModHelper.ConsoleCommands.Add("player_addallmeatrecipes", "Add all meat recipes to the player.", DataLoader.RecipeLoader.AddAllMeatRecipes);
                }

                if (_meatCleaverSpawnKey != null || _inseminationSyringeSpawnKey != null || _feedingBasketSpawnKey != null)
                {
                    helper.Events.Input.ButtonPressed += this.OnButtonPressed;
                }

                if (!DataLoader.ModConfig.DisablePregnancy)
                {
                    helper.Events.GameLoop.DayStarted += (x, y) => PregnancyController.CheckForBirth();
                    helper.Events.GameLoop.Saving     += (x, y) => PregnancyController.UpdatePregnancy();
                }



                var harmony = HarmonyInstance.Create("Digus.AnimalHusbandryMod");

                try
                {
                    var farmAnimalPet = typeof(FarmAnimal).GetMethod("pet");
                    var animalQueryMenuExtendedPet = typeof(AnimalQueryMenuExtended).GetMethod("Pet");
                    harmony.Patch(farmAnimalPet, new HarmonyMethod(animalQueryMenuExtendedPet), null);
                }
                catch (Exception)
                {
                    Monitor.Log("Erro patching the FarmAnimal 'pet' Method. Applying old method of opening the extended animal query menu.", LogLevel.Warn);
                    helper.Events.Display.MenuChanged += (s, e) =>
                    {
                        if (e.NewMenu is AnimalQueryMenu && !(e.NewMenu is AnimalQueryMenuExtended))
                        {
                            Game1.activeClickableMenu = new AnimalQueryMenuExtended(this.Helper.Reflection.GetField <FarmAnimal>(e.NewMenu, "animal").GetValue());
                        }
                    };
                }

                if (!DataLoader.ModConfig.DisableRancherMeatPriceAjust)
                {
                    var sellToStorePrice       = typeof(StardewValley.Object).GetMethod("sellToStorePrice");
                    var sellToStorePricePrefix = typeof(MeatOverrides).GetMethod("sellToStorePrice");
                    harmony.Patch(sellToStorePrice, new HarmonyMethod(sellToStorePricePrefix), null);
                }

                if (!DataLoader.ModConfig.DisableMeat)
                {
                    var objectIsPotentialBasicShippedCategory        = typeof(StardewValley.Object).GetMethod("isPotentialBasicShippedCategory");
                    var meatOverridesIsPotentialBasicShippedCategory = typeof(MeatOverrides).GetMethod("isPotentialBasicShippedCategory");
                    harmony.Patch(objectIsPotentialBasicShippedCategory, new HarmonyMethod(meatOverridesIsPotentialBasicShippedCategory), null);

                    var objectCountsForShippedCollection        = typeof(StardewValley.Object).GetMethod("countsForShippedCollection");
                    var meatOverridesCountsForShippedCollection = typeof(MeatOverrides).GetMethod("countsForShippedCollection");
                    harmony.Patch(objectCountsForShippedCollection, new HarmonyMethod(meatOverridesCountsForShippedCollection), null);
                }



                //var addSpecificTemporarySprite = typeof(Event).GetMethod("addSpecificTemporarySprite");
                //var addSpecificTemporarySprite = this.Helper.Reflection.GetMethod(new Event(), "addSpecificTemporarySprite").MethodInfo;
                //var addSpecificTemporarySpritePostfix = typeof(EventsOverrides).GetMethod("addSpecificTemporarySprite");
                //harmony.Patch(addSpecificTemporarySprite, null, new HarmonyMethod(addSpecificTemporarySpritePostfix));

                //var petCheckAction = typeof(Pet).GetMethod("checkAction");
                //var petCheckActionPrefix = typeof(PetOverrides).GetMethod("checkAction");
                //harmony.Patch(petCheckAction, new HarmonyMethod(petCheckActionPrefix), null);
            }
        }
Ejemplo n.º 2
0
        /*********
        ** Private methods
        *********/
        /// <summary>Raised after the game is launched, right before the first update tick. This happens once per game session (unrelated to loading saves). All mods are loaded and initialised at this point, so this is a good time to set up mod integrations.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="args">The event data.</param>
        private void OnGameLaunched(object sender, GameLaunchedEventArgs args)
        {
            if (this.Helper.ModRegistry.IsLoaded("DIGUS.BUTCHER"))
            {
                Monitor.Log("Animal Husbandry Mod can't run along side its older version, ButcherMod. " +
                            "You need to copy the 'data' directory from the ButcherMod directory, into the AnimalHusbandryMod directory, then delete the ButcherMod directory. " +
                            "Animal Husbandry Mod won't load until this is done.", LogLevel.Error);
                IsEnabled = false;
            }
            else
            {
                DataLoader                   = new DataLoader(Helper);
                _meatCleaverSpawnKey         = DataLoader.ModConfig.AddMeatCleaverToInventoryKey;
                _inseminationSyringeSpawnKey = DataLoader.ModConfig.AddInseminationSyringeToInventoryKey;
                _feedingBasketSpawnKey       = DataLoader.ModConfig.AddFeedingBasketToInventoryKey;

                //TimeEvents.AfterDayStarted += (x, y) => EventsLoader.CheckEventDay();

                if (!DataLoader.ModConfig.DisableMeat)
                {
                    ModHelper.ConsoleCommands.Add("player_addallmeatrecipes", "Add all meat recipes to the player.", DataLoader.RecipeLoader.AddAllMeatRecipes);
                }

                if (_meatCleaverSpawnKey != null || _inseminationSyringeSpawnKey != null || _feedingBasketSpawnKey != null)
                {
                    Helper.Events.Input.ButtonPressed += this.OnButtonPressed;
                }

                var harmony = HarmonyInstance.Create("Digus.AnimalHusbandryMod");

                try
                {
                    harmony.Patch(
                        original: AccessTools.Method(typeof(FarmAnimal), nameof(FarmAnimal.pet)),
                        prefix: new HarmonyMethod(typeof(AnimalQueryMenuExtended), nameof(AnimalQueryMenuExtended.Pet))
                        );
                }
                catch (Exception)
                {
                    Monitor.Log("Error patching the FarmAnimal 'pet' Method. Applying old method of opening the extended animal query menu.", LogLevel.Warn);
                    Helper.Events.Display.MenuChanged += (s, e) =>
                    {
                        if (e.NewMenu is AnimalQueryMenu && !(e.NewMenu is AnimalQueryMenuExtended))
                        {
                            Game1.activeClickableMenu = new AnimalQueryMenuExtended(this.Helper.Reflection.GetField <FarmAnimal>(e.NewMenu, "animal").GetValue());
                        }
                    };
                }

                if (!DataLoader.ModConfig.DisableRancherMeatPriceAjust)
                {
                    harmony.Patch(
                        original: AccessTools.Method(typeof(SObject), nameof(SObject.sellToStorePrice)),
                        prefix: new HarmonyMethod(typeof(MeatOverrides), nameof(MeatOverrides.sellToStorePrice))
                        );
                }

                if (!DataLoader.ModConfig.DisableMeat)
                {
                    harmony.Patch(
                        original: AccessTools.Method(typeof(SObject), nameof(SObject.isPotentialBasicShippedCategory)),
                        prefix: new HarmonyMethod(typeof(MeatOverrides), nameof(MeatOverrides.isPotentialBasicShippedCategory))
                        );
                    harmony.Patch(
                        original: AccessTools.Method(typeof(SObject), nameof(SObject.countsForShippedCollection)),
                        prefix: new HarmonyMethod(typeof(MeatOverrides), nameof(MeatOverrides.countsForShippedCollection))
                        );
                }

                //harmony.Patch(
                //    original: AccessTools.Method(typeof(Event), "addSpecificTemporarySprite"),
                //    transpiler: new HarmonyMethod(typeof(EventsOverrides), nameof(EventsOverrides.addSpecificTemporarySprite))
                //);

                //harmony.Patch(
                //    original: AccessTools.Method(typeof(Pet), nameof(Pet.checkAction)),
                //    prefix: new HarmonyMethod(typeof(PetOverrides), nameof(PetOverrides.checkAction))
                //);
            }
        }