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); }
public static void SetUpModConfigMenu(CookoutKitConfig config, PermanentCookoutKit mod) { IGenericModConfigMenuAPI api = mod.Helper.ModRegistry.GetApi <IGenericModConfigMenuAPI>("spacechase0.GenericModConfigMenu"); if (api == null) { return; } var manifest = mod.ModManifest; api.RegisterModConfig(manifest, () => config = new CookoutKitConfig(), delegate { mod.Helper.WriteConfig(config); VerifyConfigValues(config, mod); }); api.RegisterLabel(manifest, "Cookout Kit Reignition Cost", null); api.RegisterSimpleOption(manifest, "Wood Needed", null, () => config.WoodNeeded, (int val) => config.WoodNeeded = val); api.RegisterSimpleOption(manifest, "Coal Needed", null, () => config.CoalNeeded, (int val) => config.CoalNeeded = val); api.RegisterSimpleOption(manifest, "Fiber/ Kindling Needed", null, () => config.FiberNeeded, (int val) => config.FiberNeeded = val); api.RegisterLabel(manifest, "Charcoal Kiln", null); api.RegisterSimpleOption(manifest, "Wood Needed", "Also works with driftwood and hardwood", () => config.CharcoalKilnWoodNeeded, (int val) => config.CharcoalKilnWoodNeeded = val); api.RegisterSimpleOption(manifest, "Time Needed", "The game only checks every 10 minutes", () => config.CharcoalKilnTimeNeeded, (int val) => config.CharcoalKilnTimeNeeded = val); api.RegisterLabel(manifest, "Wood Multipliers", null); api.RegisterSimpleOption(manifest, "Driftwood Multiplier¹", null, () => config.DriftwoodMultiplier, (float val) => config.DriftwoodMultiplier = val); api.RegisterSimpleOption(manifest, "Hardwood Multiplier¹", null, () => config.HardwoodMultiplier, (float val) => config.HardwoodMultiplier = val); api.RegisterLabel(manifest, "Kindling Multipliers", null); api.RegisterSimpleOption(manifest, "Newspaper Multiplier¹", null, () => config.NewspaperMultiplier, (float val) => config.NewspaperMultiplier = val); api.RegisterSimpleOption(manifest, "Wool Multiplier¹", null, () => config.WoolMultiplier, (float val) => config.WoolMultiplier = val); api.RegisterSimpleOption(manifest, "Cloth Multiplier¹", null, () => config.ClothMultiplier, (float val) => config.ClothMultiplier = val); // this is a spacer api.RegisterLabel(manifest, string.Empty, null); api.RegisterLabel(manifest, "1: Set To 0 To Disallow Using It", null); }
public static void VerifyConfigValues(CookoutKitConfig config, PermanentCookoutKit mod) { bool invalidConfig = false; if (config.WoodNeeded < 0) { invalidConfig = true; config.WoodNeeded = 0; } if (config.FiberNeeded < 0) { invalidConfig = true; config.FiberNeeded = 0; } if (config.CoalNeeded < 0) { invalidConfig = true; config.CoalNeeded = 0; } if (config.DriftwoodMultiplier < 0) { invalidConfig = true; config.DriftwoodMultiplier = 0; } if (config.HardwoodMultiplier < 0) { invalidConfig = true; config.HardwoodMultiplier = 0; } if (config.NewspaperMultiplier < 0) { invalidConfig = true; config.NewspaperMultiplier = 0; } if (config.WoolMultiplier < 0) { invalidConfig = true; config.WoolMultiplier = 0; } if (config.ClothMultiplier < 0) { invalidConfig = true; config.ClothMultiplier = 0; } if (config.CharcoalKilnWoodNeeded < 1) { invalidConfig = true; config.CharcoalKilnWoodNeeded = 1; } if (config.CharcoalKilnTimeNeeded < 10) { invalidConfig = true; config.CharcoalKilnTimeNeeded = 10; } if (invalidConfig) { mod.DebugLog("At least one config value was out of range and was reset."); mod.Helper.WriteConfig(config); } }
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); } } }