fix game version always being detected as 1.2.9 because Game1.version is a const now
This commit is contained in:
parent
2ed3b25b6b
commit
be0aa19f30
|
@ -71,6 +71,18 @@ namespace StardewModdingAPI
|
||||||
/// <summary>Whether a player save has been loaded.</summary>
|
/// <summary>Whether a player save has been loaded.</summary>
|
||||||
internal static bool PlayerNull => !Game1.hasLoadedGame || Game1.player == null || string.IsNullOrEmpty(Game1.player.name);
|
internal static bool PlayerNull => !Game1.hasLoadedGame || Game1.player == null || string.IsNullOrEmpty(Game1.player.name);
|
||||||
|
|
||||||
|
/// <summary>The actual game version.</summary>
|
||||||
|
/// <remarks>This is necessary because <see cref="Game1.version"/> is a constant, so SMAPI's references to it are inlined at compile-time.</remarks>
|
||||||
|
internal static string GameVersion
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
FieldInfo field = typeof(Game1).GetField(nameof(Game1.version), BindingFlags.Public | BindingFlags.Static);
|
||||||
|
if (field == null)
|
||||||
|
throw new InvalidOperationException($"The {nameof(Game1)}.{nameof(Game1.version)} field could not be found.");
|
||||||
|
return (string)field.GetValue(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*********
|
/*********
|
||||||
** Protected methods
|
** Protected methods
|
||||||
|
|
|
@ -102,8 +102,8 @@ namespace StardewModdingAPI
|
||||||
{
|
{
|
||||||
// initialise logging
|
// initialise logging
|
||||||
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB"); // for consistent log formatting
|
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB"); // for consistent log formatting
|
||||||
this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Game1.version} on {Environment.OSVersion}", LogLevel.Info);
|
this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {Environment.OSVersion}", LogLevel.Info);
|
||||||
Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Game1.version}";
|
Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion}";
|
||||||
|
|
||||||
// inject compatibility shims
|
// inject compatibility shims
|
||||||
#pragma warning disable 618
|
#pragma warning disable 618
|
||||||
|
@ -142,9 +142,9 @@ namespace StardewModdingAPI
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// verify version
|
// verify version
|
||||||
if (string.Compare(Game1.version, Constants.MinimumGameVersion, StringComparison.InvariantCultureIgnoreCase) < 0)
|
if (string.Compare(Constants.GameVersion, Constants.MinimumGameVersion, StringComparison.InvariantCultureIgnoreCase) < 0)
|
||||||
{
|
{
|
||||||
this.Monitor.Log($"Oops! You're running Stardew Valley {Game1.version}, but the oldest supported version is {Constants.MinimumGameVersion}. Please update your game before using SMAPI. If you're on the Steam beta channel, note that the beta channel may not receive the latest updates.", LogLevel.Error);
|
this.Monitor.Log($"Oops! You're running Stardew Valley {Constants.GameVersion}, but the oldest supported version is {Constants.MinimumGameVersion}. Please update your game before using SMAPI. If you're on the Steam beta channel, note that the beta channel may not receive the latest updates.", LogLevel.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ namespace StardewModdingAPI
|
||||||
this.GameInstance = new SGame(this.Monitor);
|
this.GameInstance = new SGame(this.Monitor);
|
||||||
this.GameInstance.Exiting += (sender, e) => this.IsGameRunning = false;
|
this.GameInstance.Exiting += (sender, e) => this.IsGameRunning = false;
|
||||||
this.GameInstance.Window.ClientSizeChanged += (sender, e) => GraphicsEvents.InvokeResize(this.Monitor, sender, e);
|
this.GameInstance.Window.ClientSizeChanged += (sender, e) => GraphicsEvents.InvokeResize(this.Monitor, sender, e);
|
||||||
this.GameInstance.Window.Title = $"Stardew Valley {Game1.version}";
|
this.GameInstance.Window.Title = $"Stardew Valley {Constants.GameVersion}";
|
||||||
gameProgramType.GetField("gamePtr").SetValue(gameProgramType, this.GameInstance);
|
gameProgramType.GetField("gamePtr").SetValue(gameProgramType, this.GameInstance);
|
||||||
|
|
||||||
// configure
|
// configure
|
||||||
|
@ -538,7 +538,7 @@ namespace StardewModdingAPI
|
||||||
this.Monitor.Log($"Loaded {modsLoaded} mods.");
|
this.Monitor.Log($"Loaded {modsLoaded} mods.");
|
||||||
foreach (Action warning in deprecationWarnings)
|
foreach (Action warning in deprecationWarnings)
|
||||||
warning();
|
warning();
|
||||||
Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Game1.version} with {modsLoaded} mods";
|
Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion} with {modsLoaded} mods";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Run a loop handling console input.</summary>
|
/// <summary>Run a loop handling console input.</summary>
|
||||||
|
|
Loading…
Reference in New Issue