diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-02-24 00:15:45 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-02-24 00:15:45 -0500 |
commit | be0aa19f30ac1168214f0dcf39a37587e8f4abb3 (patch) | |
tree | 66e0617535f47b8940dd054e89b9912e98431a2e /src | |
parent | 2ed3b25b6b886092e16980288491b47d7b54a309 (diff) | |
download | SMAPI-be0aa19f30ac1168214f0dcf39a37587e8f4abb3.tar.gz SMAPI-be0aa19f30ac1168214f0dcf39a37587e8f4abb3.tar.bz2 SMAPI-be0aa19f30ac1168214f0dcf39a37587e8f4abb3.zip |
fix game version always being detected as 1.2.9 because Game1.version is a const now
Diffstat (limited to 'src')
-rw-r--r-- | src/StardewModdingAPI/Constants.cs | 12 | ||||
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 12 |
2 files changed, 18 insertions, 6 deletions
diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs index 8b085eac..69dd1fa8 100644 --- a/src/StardewModdingAPI/Constants.cs +++ b/src/StardewModdingAPI/Constants.cs @@ -71,6 +71,18 @@ namespace StardewModdingAPI /// <summary>Whether a player save has been loaded.</summary> 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 diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index df64de3b..3431e02f 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -102,8 +102,8 @@ namespace StardewModdingAPI { // initialise logging 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); - Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Game1.version}"; + this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {Environment.OSVersion}", LogLevel.Info); + Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion}"; // inject compatibility shims #pragma warning disable 618 @@ -142,9 +142,9 @@ namespace StardewModdingAPI try { // 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; } @@ -245,7 +245,7 @@ namespace StardewModdingAPI this.GameInstance = new SGame(this.Monitor); this.GameInstance.Exiting += (sender, e) => this.IsGameRunning = false; 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); // configure @@ -538,7 +538,7 @@ namespace StardewModdingAPI this.Monitor.Log($"Loaded {modsLoaded} mods."); foreach (Action warning in deprecationWarnings) 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> |