check minimum compatibility earlier, move some initialising after game starts
This commit is contained in:
parent
248ba90b75
commit
e27ada0f61
|
@ -127,6 +127,10 @@ namespace StardewModdingAPI
|
||||||
/// <param name="writeToConsole">Whether to output log messages to the console.</param>
|
/// <param name="writeToConsole">Whether to output log messages to the console.</param>
|
||||||
public Program(bool writeToConsole)
|
public Program(bool writeToConsole)
|
||||||
{
|
{
|
||||||
|
// init paths
|
||||||
|
this.VerifyPath(Constants.ModPath);
|
||||||
|
this.VerifyPath(Constants.LogDir);
|
||||||
|
|
||||||
// init log file
|
// init log file
|
||||||
this.PurgeLogFiles();
|
this.PurgeLogFiles();
|
||||||
string logPath = this.GetLogPath();
|
string logPath = this.GetLogPath();
|
||||||
|
@ -142,56 +146,11 @@ namespace StardewModdingAPI
|
||||||
};
|
};
|
||||||
this.EventManager = new EventManager(this.Monitor, this.ModRegistry);
|
this.EventManager = new EventManager(this.Monitor, this.ModRegistry);
|
||||||
|
|
||||||
// apply game patches
|
|
||||||
new GamePatcher(this.Monitor).Apply(
|
|
||||||
new GameLocationPatch()
|
|
||||||
);
|
|
||||||
|
|
||||||
// init JSON parser
|
|
||||||
JsonConverter[] converters = {
|
|
||||||
new StringEnumConverter<Buttons>(),
|
|
||||||
new StringEnumConverter<Keys>(),
|
|
||||||
new StringEnumConverter<SButton>(),
|
|
||||||
new ColorConverter(),
|
|
||||||
new PointConverter(),
|
|
||||||
new RectangleConverter(),
|
|
||||||
new Framework.Serialisation.SemanticVersionConverter()
|
|
||||||
};
|
|
||||||
foreach (JsonConverter converter in converters)
|
|
||||||
this.JsonHelper.JsonSettings.Converters.Add(converter);
|
|
||||||
|
|
||||||
// hook up events
|
|
||||||
ContentEvents.Init(this.EventManager);
|
|
||||||
ControlEvents.Init(this.EventManager);
|
|
||||||
GameEvents.Init(this.EventManager);
|
|
||||||
GraphicsEvents.Init(this.EventManager);
|
|
||||||
InputEvents.Init(this.EventManager);
|
|
||||||
LocationEvents.Init(this.EventManager);
|
|
||||||
MenuEvents.Init(this.EventManager);
|
|
||||||
MineEvents.Init(this.EventManager);
|
|
||||||
MultiplayerEvents.Init(this.EventManager);
|
|
||||||
PlayerEvents.Init(this.EventManager);
|
|
||||||
SaveEvents.Init(this.EventManager);
|
|
||||||
SpecialisedEvents.Init(this.EventManager);
|
|
||||||
TimeEvents.Init(this.EventManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Launch SMAPI.</summary>
|
|
||||||
[HandleProcessCorruptedStateExceptions, SecurityCritical] // let try..catch handle corrupted state exceptions
|
|
||||||
public void RunInteractively()
|
|
||||||
{
|
|
||||||
// initialise SMAPI
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// init logging
|
// init logging
|
||||||
this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform)}", LogLevel.Info);
|
this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform)}", LogLevel.Info);
|
||||||
this.Monitor.Log($"Mods go here: {Constants.ModPath}");
|
this.Monitor.Log($"Mods go here: {Constants.ModPath}");
|
||||||
this.Monitor.Log($"Log started at {DateTime.UtcNow:s} UTC", LogLevel.Trace);
|
this.Monitor.Log($"Log started at {DateTime.UtcNow:s} UTC", LogLevel.Trace);
|
||||||
|
|
||||||
// validate paths
|
|
||||||
this.VerifyPath(Constants.ModPath);
|
|
||||||
this.VerifyPath(Constants.LogDir);
|
|
||||||
|
|
||||||
// validate game version
|
// validate game version
|
||||||
if (Constants.GameVersion.IsOlderThan(Constants.MinimumGameVersion))
|
if (Constants.GameVersion.IsOlderThan(Constants.MinimumGameVersion))
|
||||||
{
|
{
|
||||||
|
@ -206,6 +165,47 @@ namespace StardewModdingAPI
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// apply game patches
|
||||||
|
new GamePatcher(this.Monitor).Apply(
|
||||||
|
new GameLocationPatch()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Launch SMAPI.</summary>
|
||||||
|
[HandleProcessCorruptedStateExceptions, SecurityCritical] // let try..catch handle corrupted state exceptions
|
||||||
|
public void RunInteractively()
|
||||||
|
{
|
||||||
|
// initialise SMAPI
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// hook up events
|
||||||
|
ContentEvents.Init(this.EventManager);
|
||||||
|
ControlEvents.Init(this.EventManager);
|
||||||
|
GameEvents.Init(this.EventManager);
|
||||||
|
GraphicsEvents.Init(this.EventManager);
|
||||||
|
InputEvents.Init(this.EventManager);
|
||||||
|
LocationEvents.Init(this.EventManager);
|
||||||
|
MenuEvents.Init(this.EventManager);
|
||||||
|
MineEvents.Init(this.EventManager);
|
||||||
|
MultiplayerEvents.Init(this.EventManager);
|
||||||
|
PlayerEvents.Init(this.EventManager);
|
||||||
|
SaveEvents.Init(this.EventManager);
|
||||||
|
SpecialisedEvents.Init(this.EventManager);
|
||||||
|
TimeEvents.Init(this.EventManager);
|
||||||
|
|
||||||
|
// init JSON parser
|
||||||
|
JsonConverter[] converters = {
|
||||||
|
new StringEnumConverter<Buttons>(),
|
||||||
|
new StringEnumConverter<Keys>(),
|
||||||
|
new StringEnumConverter<SButton>(),
|
||||||
|
new ColorConverter(),
|
||||||
|
new PointConverter(),
|
||||||
|
new RectangleConverter(),
|
||||||
|
new Framework.Serialisation.SemanticVersionConverter()
|
||||||
|
};
|
||||||
|
foreach (JsonConverter converter in converters)
|
||||||
|
this.JsonHelper.JsonSettings.Converters.Add(converter);
|
||||||
|
|
||||||
// add error handlers
|
// add error handlers
|
||||||
#if SMAPI_FOR_WINDOWS
|
#if SMAPI_FOR_WINDOWS
|
||||||
Application.ThreadException += (sender, e) => this.Monitor.Log($"Critical thread exception: {e.Exception.GetLogSummary()}", LogLevel.Error);
|
Application.ThreadException += (sender, e) => this.Monitor.Log($"Critical thread exception: {e.Exception.GetLogSummary()}", LogLevel.Error);
|
||||||
|
|
Loading…
Reference in New Issue