/********* ** 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) { Config = helper.ReadConfig <ModConfig>(); ModHelper = helper; Reflection = helper.Reflection; Logger = Monitor; Enum.TryParse(Config.IntroSkipTo, true, out SkipIntro.SkipTo); Enum.TryParse(Config.SaveAnytimeKey, true, out SaveAnytimeKey); if (SkipIntro.SkipTo != SkipIntro.Screen.Intro && Config.ForgetLastOnTitle) { helper.Events.GameLoop.ReturnedToTitle += (s, e) => { SkipIntro.SetLastFile(""); } } ; BackupSaves(); helper.Events.GameLoop.Saved += OnSaved; if (!Config.DisableSaveAnyTime) { SaveManager = new SaveManager(); helper.Events.GameLoop.SaveLoaded += OnSaveLoaded; helper.Events.GameLoop.UpdateTicked += OnUpdateTicked; helper.Events.GameLoop.DayStarted += OnDayStarted; helper.Events.Input.ButtonPressed += OnButtonPressed; customMenuOpen = false; } }
/// <summary>Raised after the player loads a save slot and the world is initialised.</summary> private static void OnSaveLoaded(object sender, SaveLoadedEventArgs e) { // reset state IsCustomSaving = false; ShouldResetSchedules = false; // load positions SaveManager.LoadData(); SkipIntro.SetLastFile(Constants.SaveFolderName); if (Config.ShareOptions) { StartupPreferences options = new StartupPreferences(); options.loadPreferences(false, false); Game1.options = options.clientOptions; } }
/// <summary>Raised after the game state is updated (≈60 times per second).</summary> private static void OnUpdateTicked(object sender, UpdateTickedEventArgs e) { if (SkipIntro.Current != SkipIntro.Step.Done) { SkipIntro.SkipIntroUpdateTicked(); } // let save manager run background logic if (Context.IsWorldReady) { if (!Game1.player.IsMainPlayer) { return; } SaveManager.Update(); } // reset NPC schedules if (Context.IsWorldReady && ShouldResetSchedules) { ShouldResetSchedules = false; ApplySchedules(); } if (Game1.activeClickableMenu == null && !customMenuOpen) { return; } if (Game1.activeClickableMenu == null && customMenuOpen) { restoreMonsters(); customMenuOpen = false; return; } if (Game1.activeClickableMenu != null) { if (Game1.activeClickableMenu.GetType() == typeof(NewSaveGameMenu)) { customMenuOpen = true; } } }