Пример #1
0
        public override void Entry(IModHelper helper)
        {
            Config = Helper.ReadConfig <CookoutKitConfig>();

            CookoutKitConfig.VerifyConfigValues(Config, this);

            Helper.Events.GameLoop.GameLaunched += delegate { CookoutKitConfig.SetUpModConfigMenu(Config, this); };

            Helper.Events.GameLoop.DayEnding += delegate { SaveCookingKits(); };

            Patcher.PatchAll(this);
        }
Пример #2
0
        public override void Entry(IModHelper helper)
        {
            mod = this;

            config = Helper.ReadConfig <CookoutKitConfig>();

            CookoutKitConfig.VerifyConfigValues(config, this);

            Helper.Events.GameLoop.GameLaunched += delegate { CookoutKitConfig.SetUpModConfigMenu(config, this); };

            Helper.Events.GameLoop.DayEnding += delegate { SaveCookingKits(); };

            var harmony = HarmonyInstance.Create(ModManifest.UniqueID);

            try
            {
                harmony.Patch(
                    original: AccessTools.Method(typeof(Torch), "draw", new[] { typeof(SpriteBatch), typeof(int), typeof(int), typeof(float) }),
                    postfix: new HarmonyMethod(typeof(PermanentCookoutKit), nameof(Draw_Post))
                    );

                harmony.Patch(
                    original: AccessTools.Method(typeof(Torch), "updateWhenCurrentLocation"),
                    postfix: new HarmonyMethod(typeof(PermanentCookoutKit), nameof(UpdateWhenCurrentLocation_Post))
                    );

                harmony.Patch(
                    original: AccessTools.Method(typeof(Torch), "checkForAction"),
                    prefix: new HarmonyMethod(typeof(PermanentCookoutKit), nameof(CheckForAction_Pre))
                    );

                harmony.Patch(
                    original: AccessTools.Method(typeof(StardewObject), "performObjectDropInAction", new[] { typeof(Item), typeof(bool), typeof(Farmer) }),
                    prefix: new HarmonyMethod(typeof(PermanentCookoutKit), nameof(UpdateCharcoalKilnInput))
                    );
            }
            catch (Exception e)
            {
                ErrorLog("Error while trying to setup required patches:", e);
            }

            if (mod.Helper.ModRegistry.IsLoaded("Pathoschild.Automate"))
            {
                try
                {
                    mod.DebugLog("This mod patches Automate. If you notice issues with Automate, make sure it happens without this mod before reporting it to the Automate page.");

                    // this is so ugly but I can't include a reference
                    Assembly assembly = null;

                    foreach (var item in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        if (item.GetName().Name.Trim() == "Automate")
                        {
                            assembly = item;
                            break;
                        }
                    }

                    if (assembly == null)
                    {
                        mod.ErrorLog($"Error while trying to patch Automate. Please report this to the mod page of {mod.ModManifest.Name}, not Automate.");
                        return;
                    }

                    // I don't see a use in using MachineWrapper because it's also internal I need to check for the type of the machine anyway which would be way too much reflection at runtime
                    var charcoalKiln = assembly.GetType("Pathoschild.Stardew.Automate.Framework.Machines.Objects.CharcoalKilnMachine");

                    harmony.Patch(
                        original: AccessTools.Method(charcoalKiln, "SetInput"),
                        prefix: new HarmonyMethod(typeof(PermanentCookoutKit), nameof(PatchCharcoalKiln))
                        );
                }
                catch (Exception e)
                {
                    mod.ErrorLog($"Error while trying to patch Automate. Please report this to the mod page of {mod.ModManifest.Name}, not Automate:", e);
                }
            }
        }