From 89cb791cae0db9637be051db1a1543a8b1ee4745 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 24 Feb 2017 19:44:19 -0500 Subject: [PATCH] fix content manager compatibility with MonoGame (#173) --- .../Framework/SContentManager.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/StardewModdingAPI/Framework/SContentManager.cs b/src/StardewModdingAPI/Framework/SContentManager.cs index 27001a06..24237c63 100644 --- a/src/StardewModdingAPI/Framework/SContentManager.cs +++ b/src/StardewModdingAPI/Framework/SContentManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.Threading; using Microsoft.Xna.Framework; +using StardewModdingAPI.AssemblyRewriters; using StardewModdingAPI.Framework.Reflection; using StardewValley; @@ -49,7 +50,9 @@ namespace StardewModdingAPI.Framework this.Cache = reflection .GetPrivateField>(this, "loadedAssets") .GetValue(); - this.NormaliseAssetKey = reflection.GetPrivateMethod(typeof(TitleContainer), "GetCleanPath"); + this.NormaliseAssetKey = Constants.TargetPlatform == Platform.Windows + ? reflection.GetPrivateMethod(typeof(TitleContainer), "GetCleanPath") + : reflection.GetPrivateMethod(this, nameof(this.NormaliseKeyForMono)); } /// Load an asset that has been processed by the Content Pipeline. @@ -57,7 +60,19 @@ namespace StardewModdingAPI.Framework /// The asset path relative to the loader root directory, not including the .xnb extension. public override T Load(string assetName) { + assetName = this.NormaliseAssetKey.Invoke(assetName); return base.Load(assetName); } + + + /********* + ** Private methods + *********/ + /// Normalise an asset key for Mono. + /// The asset key. + private string NormaliseKeyForMono(string key) + { + return key.Replace('\\', '/'); // based on MonoGame's ContentManager.Load logic + } } }