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/StardewModdingAPI/Constants.cs | |
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/StardewModdingAPI/Constants.cs')
-rw-r--r-- | src/StardewModdingAPI/Constants.cs | 12 |
1 files changed, 12 insertions, 0 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 |