/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="contentHelper">The underlying content helper.</param> /// <param name="monitor">Writes messages to the log and allows exiting the game.</param> public ContentHelperWrapper(IContentHelper contentHelper, IMonitor monitor) { this.ContentHelper = contentHelper; // get real type Type type = typeof(IContentHelper).Assembly.GetType("StardewModdingAPI.Framework.ModHelpers.ContentHelper"); if (type == null) { monitor.ExitGameImmediately("Could not access SMAPI's internal content helper. Make sure you have the latest version of both Entoarox Framework and SMAPI."); return; } // get asset loaders { PropertyInfo property = type.GetProperty("AssetLoaders", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); if (property == null) { monitor.ExitGameImmediately("Could not access SMAPI's asset loaders. Make sure you have the latest version of both Entoarox Framework and SMAPI."); return; } this.AssetLoaders = (IList <IAssetLoader>)property.GetValue(contentHelper); } // get InvalidateCache method { MethodInfo method = type.GetMethod("InvalidateCache", new[] { typeof(string) }); if (method == null) { monitor.ExitGameImmediately("Could not access SMAPI's cache invalidation method. Make sure you have the latest version of both Entoarox Framework and SMAPI."); return; } this.InvalidateCacheMethod = method; } }
public static void ExitGameImmediately(this IMonitor self, string message, Exception error = null) { if (error != null) { message += Environment.NewLine + error.ToString(); } self.ExitGameImmediately(message); }
public static void ExitGameImmediately(this IMonitor self, string message, Exception error = null, params string[] replacements) { if (new List <string>(replacements).Count > 0) { message = string.Format(message, replacements.ToArray()); } if (error != null) { message = message + Environment.NewLine + error.Message + Environment.NewLine + error.StackTrace; } self.ExitGameImmediately(message); }