diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-11 17:25:06 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-11 17:25:06 -0400 |
commit | d097825c84bbe7d4b4812d4948358dd22abd166a (patch) | |
tree | 53ba6d271c8a63c8f44ac34e230cee1c98b12dce /src/SMAPI/Framework | |
parent | e14916f9622592a993fad54fe184a03de0b95c7b (diff) | |
download | SMAPI-d097825c84bbe7d4b4812d4948358dd22abd166a.tar.gz SMAPI-d097825c84bbe7d4b4812d4948358dd22abd166a.tar.bz2 SMAPI-d097825c84bbe7d4b4812d4948358dd22abd166a.zip |
fix error when mod loads XNB mod file without extension
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r-- | src/SMAPI/Framework/ModHelpers/ContentHelper.cs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs index 24e511c3..427adac2 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs @@ -132,7 +132,32 @@ namespace StardewModdingAPI.Framework.ModHelpers return this.GameContentManager.LoadLocalized<T>(assetName, this.CurrentLocaleConstant, useCache: false); case ContentSource.ModFolder: - return this.ModContentManager.LoadExact<T>(assetName, useCache: false); + try + { + return this.ModContentManager.LoadExact<T>(assetName, useCache: false); + } + catch (SContentLoadException ex) when (ex.ErrorType == ContentLoadErrorType.AssetDoesNotExist) + { + // legacy behavior: you can load a .xnb file without the file extension + try + { + IAssetName newName = this.ContentCore.ParseAssetName(assetName.Name + ".xnb", allowLocales: false); + if (this.ModContentManager.DoesAssetExist<T>(newName)) + { + T data = this.ModContentManager.LoadExact<T>(newName, useCache: false); + SCore.DeprecationManager.Warn( + this.Mod, + "loading XNB files from the mod folder without the .xnb file extension", + "3.14.0", + DeprecationLevel.Notice + ); + return data; + } + } + catch { /* legacy behavior failed, rethrow original error */ } + + throw; + } default: throw new SContentLoadException(ContentLoadErrorType.Other, $"{this.Mod.DisplayName} failed loading content asset '{key}' from {source}: unknown content source '{source}'."); |