public override void Entry(IModHelper helper) { this.config = this.Helper.ReadConfig <ModUpdateMenuConfig>(); this.button = new UpdateButton(helper); this.menu = new UpdateMenu(); GameEvents.UpdateTick += this.GameEvents_UpdateTick; GraphicsEvents.OnPostRenderEvent += this.GraphicsEvents_OnPostRenderHudEvent; InputEvents.ButtonPressed += this.InputEvents_ButtonPressed; new Thread(() => { IUpdateStatusRetriever statusRetriever = new UpdateStatusRetriever(this.Helper); int attempts = 50; while (true) { Thread.Sleep(1000); try { if (statusRetriever.GetUpdateStatuses(out IList <ModStatus> statuses)) { if (this.currentStatuses != null && this.currentStatuses.Count == statuses.Count) { this.Notify(statuses); try { this.NotifySMAPI(statusRetriever.GetSMAPIUpdateVersion()); } catch { this.NotifySMAPI(null); } break; } else { this.currentStatuses = statuses; } } attempts--; if (attempts == 0) { throw new Exception("All update attempts failed."); } } catch (Exception e) { this.Monitor.Log("Failed retrieving update info from SMAPI: ", LogLevel.Debug); this.Monitor.Log(e.ToString(), LogLevel.Debug); this.Notify(null); this.NotifySMAPI(null); break; } } }).Start(); }
/// <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) { this.config = this.Helper.ReadConfig <ModUpdateMenuConfig>(); this.button = new UpdateButton(helper); helper.Events.GameLoop.GameLaunched += this.OnGameLaunched; helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked; helper.Events.Display.Rendered += this.OnRendered; helper.Events.Input.ButtonPressed += this.OnButtonPressed; }