summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/SCore.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/SCore.cs')
-rw-r--r--src/SMAPI/Framework/SCore.cs76
1 files changed, 36 insertions, 40 deletions
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index f9a36593..cd094ff4 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -124,9 +124,6 @@ namespace StardewModdingAPI.Framework
/// <summary>The maximum number of consecutive attempts SMAPI should make to recover from an update error.</summary>
private readonly Countdown UpdateCrashTimer = new Countdown(60); // 60 ticks = roughly one second
- /// <summary>Whether custom content was removed from the save data to avoid a crash.</summary>
- private bool IsSaveContentRemoved;
-
/// <summary>Asset interceptors added or removed since the last tick.</summary>
private readonly List<AssetInterceptorChange> ReloadAssetInterceptorsQueue = new List<AssetInterceptorChange>();
@@ -135,7 +132,7 @@ namespace StardewModdingAPI.Framework
private readonly ConcurrentQueue<string> RawCommandQueue = new ConcurrentQueue<string>();
/// <summary>A list of commands to execute on each screen.</summary>
- private readonly PerScreen<List<Tuple<Command, string, string[]>>> ScreenCommandQueue = new(() => new());
+ private readonly PerScreen<List<Tuple<Command, string, string[]>>> ScreenCommandQueue = new PerScreen<List<Tuple<Command, string, string[]>>>(() => new List<Tuple<Command, string, string[]>>());
/*********
@@ -145,6 +142,10 @@ namespace StardewModdingAPI.Framework
/// <remarks>This is initialized after the game starts. This is accessed directly because it's not part of the normal class model.</remarks>
internal static DeprecationManager DeprecationManager { get; private set; }
+ /// <summary>The singleton instance.</summary>
+ /// <remarks>This is only intended for use by external code like the Error Handler mod.</remarks>
+ internal static SCore Instance { get; private set; }
+
/// <summary>The number of update ticks which have already executed. This is similar to <see cref="Game1.ticks"/>, but incremented more consistently for every tick.</summary>
internal static uint TicksElapsed { get; private set; }
@@ -157,6 +158,8 @@ namespace StardewModdingAPI.Framework
/// <param name="writeToConsole">Whether to output log messages to the console.</param>
public SCore(string modsPath, bool writeToConsole)
{
+ SCore.Instance = this;
+
// init paths
this.VerifyPath(modsPath);
this.VerifyPath(Constants.LogDir);
@@ -205,6 +208,7 @@ namespace StardewModdingAPI.Framework
{
JsonConverter[] converters = {
new ColorConverter(),
+ new KeybindConverter(),
new PointConverter(),
new Vector2Converter(),
new RectangleConverter()
@@ -245,12 +249,7 @@ namespace StardewModdingAPI.Framework
// apply game patches
new GamePatcher(this.Monitor).Apply(
- new EventErrorPatch(this.LogManager.MonitorForGame),
- new DialogueErrorPatch(this.LogManager.MonitorForGame, this.Reflection),
- new ObjectErrorPatch(),
- new LoadContextPatch(this.Reflection, this.OnLoadStageChanged),
- new LoadErrorPatch(this.Monitor, this.OnSaveContentRemoved),
- new ScheduleErrorPatch(this.LogManager.MonitorForGame)
+ new LoadContextPatch(this.Reflection, this.OnLoadStageChanged)
);
// add exit handler
@@ -278,7 +277,7 @@ namespace StardewModdingAPI.Framework
// log basic info
this.LogManager.HandleMarkerFiles();
- this.LogManager.LogSettingsHeader(this.Settings.DeveloperMode, this.Settings.CheckForUpdates);
+ this.LogManager.LogSettingsHeader(this.Settings.DeveloperMode, this.Settings.CheckForUpdates, this.Settings.RewriteMods);
// set window titles
this.SetWindowTitles(
@@ -517,15 +516,6 @@ namespace StardewModdingAPI.Framework
this.ScreenCommandQueue.GetValueForScreen(screenId).Add(Tuple.Create(command, name, args));
}
- /*********
- ** Show in-game warnings (for main player only)
- *********/
- // save content removed
- if (this.IsSaveContentRemoved && Context.IsWorldReady)
- {
- this.IsSaveContentRemoved = false;
- Game1.addHUDMessage(new HUDMessage(this.Translator.Get("warn.invalid-content-removed"), HUDMessage.error_type));
- }
/*********
** Run game update
@@ -827,24 +817,29 @@ namespace StardewModdingAPI.Framework
}
// raise input button events
- foreach (var pair in inputState.ButtonStates)
+ if (inputState.ButtonStates.Count > 0)
{
- SButton button = pair.Key;
- SButtonState status = pair.Value;
+ events.ButtonsChanged.Raise(new ButtonsChangedEventArgs(cursor, inputState));
- if (status == SButtonState.Pressed)
+ foreach (var pair in inputState.ButtonStates)
{
- if (this.Monitor.IsVerbose)
- this.Monitor.Log($"Events: button {button} pressed.");
+ SButton button = pair.Key;
+ SButtonState status = pair.Value;
- events.ButtonPressed.Raise(new ButtonPressedEventArgs(button, cursor, inputState));
- }
- else if (status == SButtonState.Released)
- {
- if (this.Monitor.IsVerbose)
- this.Monitor.Log($"Events: button {button} released.");
+ if (status == SButtonState.Pressed)
+ {
+ if (this.Monitor.IsVerbose)
+ this.Monitor.Log($"Events: button {button} pressed.");
- events.ButtonReleased.Raise(new ButtonReleasedEventArgs(button, cursor, inputState));
+ events.ButtonPressed.Raise(new ButtonPressedEventArgs(button, cursor, inputState));
+ }
+ else if (status == SButtonState.Released)
+ {
+ if (this.Monitor.IsVerbose)
+ this.Monitor.Log($"Events: button {button} released.");
+
+ events.ButtonReleased.Raise(new ButtonReleasedEventArgs(button, cursor, inputState));
+ }
}
}
}
@@ -1065,6 +1060,13 @@ namespace StardewModdingAPI.Framework
this.OnReturnedToTitle();
}
+ // override chatbox
+ if (newStage == LoadStage.Loaded)
+ {
+ Game1.onScreenMenus.Remove(Game1.chatBox);
+ Game1.onScreenMenus.Add(Game1.chatBox = new SChatBox(this.LogManager.MonitorForGame));
+ }
+
// raise events
this.EventManager.LoadStageChanged.Raise(new LoadStageChangedEventArgs(oldStage, newStage));
if (newStage == LoadStage.None)
@@ -1105,12 +1107,6 @@ namespace StardewModdingAPI.Framework
Game1.CustomData[migrationKey] = Constants.ApiVersion.ToString();
}
- /// <summary>Raised after custom content is removed from the save data to avoid a crash.</summary>
- internal void OnSaveContentRemoved()
- {
- this.IsSaveContentRemoved = true;
- }
-
/// <summary>A callback invoked before <see cref="Game1.newDayAfterFade"/> runs.</summary>
protected void OnNewDayAfterFade()
{
@@ -1406,7 +1402,7 @@ namespace StardewModdingAPI.Framework
// load mods
IList<IModMetadata> skippedMods = new List<IModMetadata>();
- using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor, this.Settings.ParanoidWarnings))
+ using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor, this.Settings.ParanoidWarnings, this.Settings.RewriteMods))
{
// init
HashSet<string> suppressUpdateChecks = new HashSet<string>(this.Settings.SuppressUpdateChecks, StringComparer.OrdinalIgnoreCase);