From c2e9aad698774e7db9b85292da9077f8462d2f5a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 26 Mar 2023 13:32:33 -0400 Subject: [PATCH] adjust ModContentManager.HandleUnknownFileTypes to let mods patch it --- docs/release-notes.md | 1 + .../Framework/ContentManagers/ModContentManager.cs | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 991f8faa..4daf97ce 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -18,6 +18,7 @@ * For mod authors: * Added `IsActiveForScreen()` method to `PerScreen`. * Updated to [FluentHttpClient](https://github.com/Pathoschild/FluentHttpClient#readme) 4.3.0 (see [changes](https://github.com/Pathoschild/FluentHttpClient/blob/develop/RELEASE-NOTES.md#430)). + * Adjusted `ModContentManager.HandleUnknownFileType` to let mods patch it. * Fixed `Context.IsWorldReady` being editable by mods. ## 3.18.2 diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index badbd766..2c068784 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -130,7 +130,7 @@ namespace StardewModdingAPI.Framework.ContentManagers ".png" => this.LoadImageFile(assetName, file), ".tbin" or ".tmx" => this.LoadMapFile(assetName, file), ".xnb" => this.LoadXnbFile(assetName), - _ => this.HandleUnknownFileType(assetName, file) + _ => (T)this.HandleUnknownFileType(assetName, file, typeof(T)) }; } catch (Exception ex) @@ -323,13 +323,15 @@ namespace StardewModdingAPI.Framework.ContentManagers } /// Handle a request to load a file type that isn't supported by SMAPI. - /// The expected file type. /// The asset name relative to the loader root directory. /// The file to load. - private T HandleUnknownFileType(IAssetName assetName, FileInfo file) + /// The expected file type. + private object HandleUnknownFileType(IAssetName assetName, FileInfo file, Type assetType) { this.ThrowLoadError(assetName, ContentLoadErrorType.InvalidName, $"unknown file extension '{file.Extension}'; must be one of '.fnt', '.json', '.png', '.tbin', '.tmx', or '.xnb'."); - return default; + return assetType.IsValueType + ? Activator.CreateInstance(assetType) + : null; } /// Assert that the asset type is compatible with one of the allowed types.