From c37fe62ca2ea8a072a16acd28bb38bc69911fd5b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 29 May 2019 23:17:13 -0400 Subject: no longer forward managed asset keys loaded through a mod content manager (#644) That isn't needed for any documented functionality, and allowed mods to load (and in some cases edit) a different mod's local assets. --- .../Framework/ContentManagers/ModContentManager.cs | 25 ++++++++-------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'src/SMAPI/Framework/ContentManagers') diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index 45303f6b..d6f077cb 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -59,26 +59,19 @@ namespace StardewModdingAPI.Framework.ContentManagers { assetName = this.AssertAndNormaliseAssetName(assetName); - // get managed asset - if (this.IsLoaded(assetName)) - return base.Load(assetName, language); + // resolve managed asset key if (this.Coordinator.TryParseManagedAssetKey(assetName, out string contentManagerID, out string relativePath)) { if (contentManagerID != this.Name) - { - T data = this.Coordinator.LoadAndCloneManagedAsset(assetName, contentManagerID, relativePath, language); - this.Inject(assetName, data, language); - return data; - } - - return this.LoadManagedAsset(assetName, contentManagerID, relativePath, language); + throw new SContentLoadException($"Can't load managed asset key '{assetName}' through content manager '{this.Name}' for a different mod."); + assetName = relativePath; } // get local asset string internalKey = this.GetInternalAssetKey(assetName); if (this.IsLoaded(internalKey)) return base.Load(internalKey, language); - return this.LoadManagedAsset(internalKey, this.Name, assetName, this.Language); + return this.LoadImpl(internalKey, this.Name, assetName, this.Language); } /// Create a new content manager for temporary use. @@ -108,13 +101,13 @@ namespace StardewModdingAPI.Framework.ContentManagers return this.Cache.ContainsKey(normalisedAssetName); } - /// Load a managed mod asset. + /// Load a local mod asset. /// The type of asset to load. - /// The internal asset key. + /// The mod asset cache key to save. /// The unique name for the content manager which should load this asset. /// The relative path within the mod folder. /// The language code for which to load content. - private T LoadManagedAsset(string internalKey, string contentManagerID, string relativePath, LanguageCode language) + private T LoadImpl(string cacheKey, string contentManagerID, string relativePath, LanguageCode language) { SContentLoadException GetContentError(string reasonPhrase) => new SContentLoadException($"Failed loading asset '{relativePath}' from {contentManagerID}: {reasonPhrase}"); try @@ -151,7 +144,7 @@ namespace StardewModdingAPI.Framework.ContentManagers { Texture2D texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, stream); texture = this.PremultiplyTransparency(texture); - this.Inject(internalKey, texture, language); + this.Inject(cacheKey, texture, language); return (T)(object)texture; } @@ -167,7 +160,7 @@ namespace StardewModdingAPI.Framework.ContentManagers this.FixCustomTilesheetPaths(map, relativeMapPath: relativePath); // inject map - this.Inject(internalKey, map, this.Language); + this.Inject(cacheKey, map, this.Language); return (T)(object)map; default: -- cgit