public override void Entry(IModHelper helper) { ModFestiveSlimes.Instance = this; this.Helper.Events.GameLoop.GameLaunched += (sender, args) => { if (helper.ModRegistry.GetApi <ICoreApiFactory>("TehPers.CoreMod") is ICoreApiFactory coreFactory) { ModFestiveSlimes.CoreApi = coreFactory.GetApi(this); this.InitializeMod(ModFestiveSlimes.CoreApi); } else { this.Monitor.Log("Failed to get core API. This mod will be disabled.", LogLevel.Error); } }; }
private void ReplaceSlimes(ICoreApi coreApi) { // Create slime managers ModFestiveSlimes._greenSlimeManager = new GreenSlimeManager(coreApi); ModFestiveSlimes._bigSlimeManager = new BigSlimeManager(coreApi); // Add seasonal textures this.Helper.Content.AssetLoaders.Add(ModFestiveSlimes._greenSlimeManager); this.Helper.Content.AssetLoaders.Add(ModFestiveSlimes._bigSlimeManager); // Make sure to check if the season has changed and invalidate the textures if needed at the start of each day this.Helper.Events.GameLoop.Saved += (sender, args) => ModFestiveSlimes.CheckSeason(); this.Helper.Events.GameLoop.SaveLoaded += (sender, args) => ModFestiveSlimes.CheckSeason(); // Create harmony instance HarmonyInstance harmony = HarmonyInstance.Create(this.ModManifest.UniqueID); // Green slime - drops MethodInfo target = typeof(GreenSlime).GetMethod(nameof(GreenSlime.getExtraDropItems), BindingFlags.Public | BindingFlags.Instance); MethodInfo replacement = typeof(ModFestiveSlimes).GetMethod(nameof(ModFestiveSlimes.GreenSlime_GetExtraDropItemsPostfix), BindingFlags.NonPublic | BindingFlags.Static); harmony.Patch(target, postfix: new HarmonyMethod(replacement)); // Green slime - drawing target = typeof(GreenSlime).GetMethod(nameof(GreenSlime.draw), new[] { typeof(SpriteBatch) }); replacement = typeof(ModFestiveSlimes).GetMethod(nameof(ModFestiveSlimes.GreenSlime_DrawPostfix), BindingFlags.NonPublic | BindingFlags.Static); harmony.Patch(target, postfix: new HarmonyMethod(replacement)); // Big slime - drops target = typeof(Monster).GetMethod(nameof(Monster.getExtraDropItems), BindingFlags.Public | BindingFlags.Instance); replacement = typeof(ModFestiveSlimes).GetMethod(nameof(ModFestiveSlimes.Monster_GetExtraDropItemsPostfix), BindingFlags.NonPublic | BindingFlags.Static); harmony.Patch(target, postfix: new HarmonyMethod(replacement)); // Big slime - drawing target = typeof(BigSlime).GetMethod(nameof(Monster.draw), new[] { typeof(SpriteBatch) }); replacement = typeof(ModFestiveSlimes).GetMethod(nameof(ModFestiveSlimes.BigSlime_DrawPostfix), BindingFlags.NonPublic | BindingFlags.Static); harmony.Patch(target, postfix: new HarmonyMethod(replacement)); }