Skip to content

Commit 8b2e087

Browse files
committed
revert workaround for game's Data/ChairTiles logic not handling mod IDs in tilesheet names correctly
This reverts commit f828029, which caused crashes loading map tiles in some cases.
1 parent 47ade7b commit 8b2e087

2 files changed

Lines changed: 15 additions & 17 deletions

File tree

docs/release-notes.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
[README](README.md)
22

33
# Release notes
4+
## Upcoming release
5+
* For players:
6+
* Fixed crash when some mods' custom tiles are on-screen.
7+
8+
* For mod authors:
9+
* Reverted the fix for the game's `Data/ChairTiles` logic not handling unique string IDs like `Maps/Author.ModName` correctly.
10+
_The fix caused crashes loading map tiles in some cases. This will be fixed in the next game update instead._
11+
412
## 4.2.0
513
Released 24 March 2025 for Stardew Valley 1.6.14 or later. See [release highlights](https://www.patreon.com/posts/125017679).
614

@@ -13,7 +21,8 @@ Released 24 March 2025 for Stardew Valley 1.6.14 or later. See [release highligh
1321
* For mod authors:
1422
* Mod events are now raised on the shipping menu (except when it's actually saving).
1523
* Added translation API methods to query translation keys (`ContainsKey` and `GetKeys`).
16-
* Fixed the game's `Data/ChairTiles` logic not handling unique string IDs like `Maps/Author.ModName` correctly.
24+
* ~~Fixed the game's `Data/ChairTiles` logic not handling unique string IDs like `Maps/Author.ModName` correctly.~~
25+
_Reverted in 4.2.1._
1726
* Fixed exception thrown if `modRegistry.GetApi<T>` can't proxy the API to the given interface. It now logs an error and returns null as intended.
1827

1928
* For external tools:

src/SMAPI/Framework/ContentManagers/ModContentManager.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -419,21 +419,15 @@ private void FixTilesheetPaths(Map map, string relativeMapPath, bool fixEagerPat
419419
// load best match
420420
try
421421
{
422-
if (!this.TryGetTilesheetAssetName(relativeMapFolder, imageSource, out IAssetName? assetName, out bool isInternalAssetKey, out string? error))
422+
if (!this.TryGetTilesheetAssetName(relativeMapFolder, imageSource, out IAssetName? assetName, out string? error))
423423
throw new SContentLoadException(ContentLoadErrorType.InvalidData, $"{errorPrefix} {error}");
424424

425425
if (assetName is not null)
426426
{
427-
// Some game code is hardcoded to expect a file extension, which results in issues like the
428-
// `Data/ChairTiles` key for `Author.ModName_Tilesheet` being `Author`.
429-
string newImageSource = !isInternalAssetKey && Path.GetExtension(assetName.Name).ToLowerInvariant() is not (".xnb" or ".png")
430-
? assetName.Name + ".xnb"
431-
: assetName.Name;
432-
433-
// set path
434-
if (this.Monitor.IsVerbose && PathUtilities.NormalizeAssetName(tilesheet.ImageSource) != PathUtilities.NormalizePath(newImageSource))
427+
if (!assetName.IsEquivalentTo(tilesheet.ImageSource))
435428
this.Monitor.VerboseLog($" Mapped tilesheet '{tilesheet.ImageSource}' to '{assetName}'.");
436-
tilesheet.ImageSource = newImageSource;
429+
430+
tilesheet.ImageSource = assetName.Name;
437431
}
438432
}
439433
catch (Exception ex)
@@ -450,19 +444,17 @@ private void FixTilesheetPaths(Map map, string relativeMapPath, bool fixEagerPat
450444
/// <param name="modRelativeMapFolder">The folder path containing the map, relative to the mod folder.</param>
451445
/// <param name="relativePath">The tilesheet path to load.</param>
452446
/// <param name="assetName">The found asset name.</param>
453-
/// <param name="isInternalAssetKey">Whether the <paramref name="assetName"/> is an internal asset key which points to a file in the mod folder, rather than an asset name in the game's normal content pipeline.</param>
454447
/// <param name="error">A message indicating why the file couldn't be loaded.</param>
455448
/// <returns>Returns whether the asset name was found.</returns>
456449
/// <remarks>See remarks on <see cref="FixTilesheetPaths"/>.</remarks>
457-
private bool TryGetTilesheetAssetName(string modRelativeMapFolder, string relativePath, out IAssetName? assetName, out bool isInternalAssetKey, out string? error)
450+
private bool TryGetTilesheetAssetName(string modRelativeMapFolder, string relativePath, out IAssetName? assetName, out string? error)
458451
{
459452
error = null;
460453

461454
// nothing to do
462455
if (string.IsNullOrWhiteSpace(relativePath))
463456
{
464457
assetName = null;
465-
isInternalAssetKey = false;
466458
return true;
467459
}
468460

@@ -481,7 +473,6 @@ private bool TryGetTilesheetAssetName(string modRelativeMapFolder, string relati
481473
if (this.GetModFile<Texture2D>(localKey).Exists)
482474
{
483475
assetName = this.GetInternalAssetKey(localKey);
484-
isInternalAssetKey = true;
485476
return true;
486477
}
487478
}
@@ -492,7 +483,6 @@ private bool TryGetTilesheetAssetName(string modRelativeMapFolder, string relati
492483
{
493484
this.GameContentManager.LoadLocalized<Texture2D>(contentKey, this.GameContentManager.Language, useCache: true); // no need to bypass cache here, since we're not storing the asset
494485
assetName = contentKey;
495-
isInternalAssetKey = false;
496486
return true;
497487
}
498488
catch
@@ -510,7 +500,6 @@ private bool TryGetTilesheetAssetName(string modRelativeMapFolder, string relati
510500

511501
// not found
512502
assetName = null;
513-
isInternalAssetKey = false;
514503
error = "The tilesheet couldn't be found relative to either the map file or the game's content folder.";
515504
return false;
516505
}

0 commit comments

Comments
 (0)