summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/release-notes.md2
-rw-r--r--src/SMAPI/Framework/Patching/GameLocationPatch.cs60
-rw-r--r--src/SMAPI/Program.cs1
-rw-r--r--src/SMAPI/StardewModdingAPI.csproj1
4 files changed, 64 insertions, 0 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 11a2a04c..e62f5e7c 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -29,6 +29,8 @@
* Added `Context.IsMultiplayer` and `Context.IsMainPlayer` flags.
* Added `Constants.TargetPlatform` which says whether the game is running on Linux, Mac, or Windows.
* Added `semanticVersion.IsPrerelease()` method.
+ * Added Harmony DLL managed by SMAPI.
+ * Fixed error when loading an unpacked `.tbin` map that references custom seasonal tilesheets.
* Fixed error if a mod loads a PNG while the game is loading (e.g. custom map tilesheets via `IAssetLoader`).
* Fixed assets loaded by temporary content managers not being editable by mods.
* Fixed assets not reloaded consistently when the player switches language.
diff --git a/src/SMAPI/Framework/Patching/GameLocationPatch.cs b/src/SMAPI/Framework/Patching/GameLocationPatch.cs
new file mode 100644
index 00000000..669c700a
--- /dev/null
+++ b/src/SMAPI/Framework/Patching/GameLocationPatch.cs
@@ -0,0 +1,60 @@
+using System.Diagnostics.CodeAnalysis;
+using System.IO;
+using System.Reflection;
+using Harmony;
+using StardewValley;
+using xTile.Tiles;
+
+namespace StardewModdingAPI.Framework.Patching
+{
+ /// <summary>A Harmony patch for the <see cref="GameLocation.updateSeasonalTileSheets"/> method.</summary>
+ internal class GameLocationPatch : IHarmonyPatch
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>A unique name for this patch.</summary>
+ public string Name => $"{nameof(GameLocation)}.{nameof(GameLocation.updateSeasonalTileSheets)}";
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Apply the Harmony patch.</summary>
+ /// <param name="harmony">The Harmony instance.</param>
+ public void Apply(HarmonyInstance harmony)
+ {
+ MethodInfo method = AccessTools.Method(typeof(GameLocation), nameof(GameLocation.updateSeasonalTileSheets));
+ MethodInfo prefix = AccessTools.Method(this.GetType(), nameof(GameLocationPatch.Prefix));
+
+ harmony.Patch(method, new HarmonyMethod(prefix), null);
+ }
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>An implementation of <see cref="GameLocation.updateSeasonalTileSheets"/> which correctly handles custom map tilesheets.</summary>
+ /// <param name="__instance">The location instance being patched.</param>
+ [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument name is defined by Harmony.")]
+ private static bool Prefix(ref GameLocation __instance)
+ {
+ if (!__instance.IsOutdoors || __instance.Name.Equals("Desert"))
+ return false;
+ foreach (TileSheet tilesheet in __instance.Map.TileSheets)
+ {
+ string imageSource = tilesheet.ImageSource;
+ string imageFile = Path.GetFileName(imageSource);
+ if (imageFile.StartsWith("spring_") || imageFile.StartsWith("summer_") || imageFile.StartsWith("fall_") || imageFile.StartsWith("winter_"))
+ {
+ string imageDir = Path.GetDirectoryName(imageSource);
+ if (string.IsNullOrWhiteSpace(imageDir))
+ imageDir = "Maps";
+ tilesheet.ImageSource = Path.Combine(imageDir, Game1.currentSeason + "_" + imageFile.Split('_')[1]);
+ }
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index bf673fe6..85306641 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -155,6 +155,7 @@ namespace StardewModdingAPI
// apply game patches
new GamePatcher(this.Monitor).Apply(
+ new GameLocationPatch()
);
// init JSON parser
diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj
index 125e7746..2df3e63f 100644
--- a/src/SMAPI/StardewModdingAPI.csproj
+++ b/src/SMAPI/StardewModdingAPI.csproj
@@ -285,6 +285,7 @@
<Compile Include="Framework\Monitor.cs" />
<Compile Include="Metadata\InstructionMetadata.cs" />
<Compile Include="Mod.cs" />
+ <Compile Include="Framework\Patching\GameLocationPatch.cs" />
<Compile Include="PatchMode.cs" />
<Compile Include="GamePlatform.cs" />
<Compile Include="Program.cs" />