From e4357c3c7d0bb3de0494e7c3547ae0dd39ee966b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 2 May 2017 00:43:15 -0400 Subject: fix error when using content API to load a PNG during early game init (#280) --- src/StardewModdingAPI/Framework/ContentHelper.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI/Framework/ContentHelper.cs b/src/StardewModdingAPI/Framework/ContentHelper.cs index 762b7e35..425e0f8c 100644 --- a/src/StardewModdingAPI/Framework/ContentHelper.cs +++ b/src/StardewModdingAPI/Framework/ContentHelper.cs @@ -181,14 +181,13 @@ namespace StardewModdingAPI.Framework throw new NotSupportedException("Can't load a PNG file while the game is drawing to the screen. Make sure you load content outside the draw loop."); // process texture + SpriteBatch spriteBatch = Game1.spriteBatch; + GraphicsDevice gpu = Game1.graphics.GraphicsDevice; using (RenderTarget2D renderTarget = new RenderTarget2D(Game1.graphics.GraphicsDevice, texture.Width, texture.Height)) - using (SpriteBatch spriteBatch = new SpriteBatch(Game1.graphics.GraphicsDevice)) { - //Viewport originalViewport = Game1.graphics.GraphicsDevice.Viewport; - - // create blank slate in render target - Game1.graphics.GraphicsDevice.SetRenderTarget(renderTarget); - Game1.graphics.GraphicsDevice.Clear(Color.Black); + // create blank render target to premultiply + gpu.SetRenderTarget(renderTarget); + gpu.Clear(Color.Black); // multiply each color by the source alpha, and write just the color values into the final texture spriteBatch.Begin(SpriteSortMode.Immediate, new BlendState @@ -214,16 +213,17 @@ namespace StardewModdingAPI.Framework spriteBatch.Draw(texture, texture.Bounds, Color.White); spriteBatch.End(); - // release the GPU - Game1.graphics.GraphicsDevice.SetRenderTarget(null); - //Game1.graphics.GraphicsDevice.Viewport = originalViewport; + // release GPU + gpu.SetRenderTarget(null); - // store data from render target because the RenderTarget2D is volatile + // extract premultiplied data Color[] data = new Color[texture.Width * texture.Height]; renderTarget.GetData(data); - // unset texture from graphic device and set modified data back to it - Game1.graphics.GraphicsDevice.Textures[0] = null; + // unset texture from GPU to regain control + gpu.Textures[0] = null; + + // update texture with premultiplied data texture.SetData(data); } -- cgit From 8503bf9cd99e094c425212264583a3416c8a5595 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 2 May 2017 23:25:23 -0400 Subject: fix XNBs loaded from the mod folder through the content API never being found on Mac (#278) --- release-notes.md | 3 +- src/StardewModdingAPI/Framework/ContentHelper.cs | 59 +++++++++++++--------- src/StardewModdingAPI/Framework/SContentManager.cs | 2 + src/StardewModdingAPI/IContentHelper.cs | 4 +- 4 files changed, 42 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/release-notes.md b/release-notes.md index 3f16c2b0..b39ab276 100644 --- a/release-notes.md +++ b/release-notes.md @@ -14,7 +14,8 @@ For mod developers: See [log](https://github.com/Pathoschild/SMAPI/compare/1.11...1.12). For mod developers: -* Fixed error when using content API to load a PNG during early game init (e.g. in mod's `Entry`). +* Fixed content API error when loading a PNG during early game init (e.g. in mod's `Entry`). +* Fixed content API error when loading an XNB from the mod folder on Mac. ## 1.11 See [log](https://github.com/Pathoschild/SMAPI/compare/1.10...1.11). diff --git a/src/StardewModdingAPI/Framework/ContentHelper.cs b/src/StardewModdingAPI/Framework/ContentHelper.cs index 425e0f8c..61bd52a7 100644 --- a/src/StardewModdingAPI/Framework/ContentHelper.cs +++ b/src/StardewModdingAPI/Framework/ContentHelper.cs @@ -45,7 +45,7 @@ namespace StardewModdingAPI.Framework /// Load content from the game folder or mod folder (if not already cached), and return it. When loading a .png file, this must be called outside the game's draw loop. /// The expected data type. The main supported types are and dictionaries; other types may be supported by the game's content pipeline. - /// The asset key to fetch (if the is ), or the local path to an XNB file relative to the mod folder. + /// The asset key to fetch (if the is ), or the local path to a content file relative to the mod folder. /// Where to search for a matching content asset. /// The is empty or contains invalid characters. /// The content asset couldn't be loaded (e.g. because it doesn't exist). @@ -57,25 +57,22 @@ namespace StardewModdingAPI.Framework switch (source) { case ContentSource.GameContent: - return this.ContentManager.Load(this.StripXnbExtension(key)); + return this.ContentManager.Load(key); case ContentSource.ModFolder: - // find content file - key = this.ContentManager.NormalisePathSeparators(key); - FileInfo file = new FileInfo(Path.Combine(this.ModFolderPath, key)); - if (!file.Exists && file.Extension == "") - file = new FileInfo(Path.Combine(this.ModFolderPath, key + ".xnb")); + // get file + FileInfo file = this.GetModFile(key); if (!file.Exists) throw new ContentLoadException($"There is no file at path '{file.FullName}'."); - // get underlying asset key - string actualKey = this.GetActualAssetKey(key, source); + // get asset path + string assetPath = this.GetModAssetPath(key, file.FullName); // load content switch (file.Extension.ToLower()) { case ".xnb": - return this.ContentManager.Load(actualKey); + return this.ContentManager.Load(assetPath); case ".png": // validate @@ -83,15 +80,15 @@ namespace StardewModdingAPI.Framework throw new ContentLoadException($"Can't read file with extension '{file.Extension}' as type '{typeof(T)}'; must be type '{typeof(Texture2D)}'."); // try cache - if (this.ContentManager.IsLoaded(actualKey)) - return this.ContentManager.Load(actualKey); + if (this.ContentManager.IsLoaded(assetPath)) + return this.ContentManager.Load(assetPath); // fetch & cache using (FileStream stream = File.OpenRead(file.FullName)) { Texture2D texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, stream); texture = this.PremultiplyTransparency(texture); - this.ContentManager.Inject(actualKey, texture); + this.ContentManager.Inject(assetPath, texture); return (T)(object)texture; } @@ -110,7 +107,7 @@ namespace StardewModdingAPI.Framework } /// Get the underlying key in the game's content cache for an asset. This can be used to load custom map tilesheets, but should be avoided when you can use the content API instead. This does not validate whether the asset exists. - /// The asset key to fetch (if the is ), or the local path to an XNB file relative to the mod folder. + /// The asset key to fetch (if the is ), or the local path to a content file relative to the mod folder. /// Where to search for a matching content asset. /// The is empty or contains invalid characters. public string GetActualAssetKey(string key, ContentSource source) @@ -118,11 +115,11 @@ namespace StardewModdingAPI.Framework switch (source) { case ContentSource.GameContent: - return this.ContentManager.NormaliseAssetName(this.StripXnbExtension(key)); + return this.ContentManager.NormaliseAssetName(key); case ContentSource.ModFolder: - string contentPath = Path.Combine(this.ModFolderPathFromContent, key); - return this.ContentManager.NormaliseAssetName(this.StripXnbExtension(contentPath)); + FileInfo file = this.GetModFile(key); + return this.ContentManager.NormaliseAssetName(this.GetModAssetPath(key, file.FullName)); default: throw new NotSupportedException($"Unknown content source '{source}'."); @@ -145,13 +142,29 @@ namespace StardewModdingAPI.Framework throw new ArgumentException("The asset key or local path contains invalid characters."); } - /// Strip the .xnb extension from an asset key, since it's assumed by the underlying content manager. - /// The asset key. - private string StripXnbExtension(string key) + /// Get a file from the mod folder. + /// The asset path relative to the mod folder. + private FileInfo GetModFile(string path) { - if (key.EndsWith(".xnb", StringComparison.InvariantCultureIgnoreCase)) - return key.Substring(0, key.Length - 4); - return key; + path = Path.Combine(this.ModFolderPath, this.ContentManager.NormalisePathSeparators(path)); + FileInfo file = new FileInfo(path); + if (!file.Exists && file.Extension == "") + file = new FileInfo(Path.Combine(this.ModFolderPath, path + ".xnb")); + return file; + } + + /// Get the asset path which loads a mod folder through a content manager. + /// The file path relative to the mod's folder. + /// The absolute file path. + private string GetModAssetPath(string localPath, string absolutePath) + { +#if SMAPI_FOR_WINDOWS + // XNA doesn't allow absolute asset paths, so get a path relative to the content folder + return Path.Combine(this.ModFolderPathFromContent, localPath); +#else + // MonoGame is weird about relative paths on Mac, but allows absolute paths + return absolutePath; +#endif } /// Get a directory path relative to a given root. diff --git a/src/StardewModdingAPI/Framework/SContentManager.cs b/src/StardewModdingAPI/Framework/SContentManager.cs index 88e1df2b..54349a91 100644 --- a/src/StardewModdingAPI/Framework/SContentManager.cs +++ b/src/StardewModdingAPI/Framework/SContentManager.cs @@ -99,6 +99,8 @@ namespace StardewModdingAPI.Framework public string NormaliseAssetName(string assetName) { assetName = this.NormalisePathSeparators(assetName); + if (assetName.EndsWith(".xnb", StringComparison.InvariantCultureIgnoreCase)) + return assetName.Substring(0, assetName.Length - 4); return this.NormaliseAssetNameForPlatform(assetName); } diff --git a/src/StardewModdingAPI/IContentHelper.cs b/src/StardewModdingAPI/IContentHelper.cs index 7cde413b..49182ce9 100644 --- a/src/StardewModdingAPI/IContentHelper.cs +++ b/src/StardewModdingAPI/IContentHelper.cs @@ -9,14 +9,14 @@ namespace StardewModdingAPI { /// Load content from the game folder or mod folder (if not already cached), and return it. When loading a .png file, this must be called outside the game's draw loop. /// The expected data type. The main supported types are and dictionaries; other types may be supported by the game's content pipeline. - /// The asset key to fetch (if the is ), or the local path to an XNB file relative to the mod folder. + /// The asset key to fetch (if the is ), or the local path to a content file relative to the mod folder. /// Where to search for a matching content asset. /// The is empty or contains invalid characters. /// The content asset couldn't be loaded (e.g. because it doesn't exist). T Load(string key, ContentSource source); /// Get the underlying key in the game's content cache for an asset. This can be used to load custom map tilesheets, but should be avoided when you can use the content API instead. This does not validate whether the asset exists. - /// The asset key to fetch (if the is ), or the local path to an XNB file relative to the mod folder. + /// The asset key to fetch (if the is ), or the local path to a content file relative to the mod folder. /// Where to search for a matching content asset. /// The is empty or contains invalid characters. string GetActualAssetKey(string key, ContentSource source); -- cgit From 24aa8bb64d27840b9fb9ba2cbef0ab222928a21e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 2 May 2017 23:45:25 -0400 Subject: default content API to ContentSource.ModFolder (#276) --- release-notes.md | 1 + src/StardewModdingAPI/Framework/ContentHelper.cs | 4 ++-- src/StardewModdingAPI/IContentHelper.cs | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/release-notes.md b/release-notes.md index b39ab276..f1aa5b15 100644 --- a/release-notes.md +++ b/release-notes.md @@ -14,6 +14,7 @@ For mod developers: See [log](https://github.com/Pathoschild/SMAPI/compare/1.11...1.12). For mod developers: +* The content API now defaults to `ContentSource.ModFolder`. * Fixed content API error when loading a PNG during early game init (e.g. in mod's `Entry`). * Fixed content API error when loading an XNB from the mod folder on Mac. diff --git a/src/StardewModdingAPI/Framework/ContentHelper.cs b/src/StardewModdingAPI/Framework/ContentHelper.cs index 61bd52a7..893fa2c8 100644 --- a/src/StardewModdingAPI/Framework/ContentHelper.cs +++ b/src/StardewModdingAPI/Framework/ContentHelper.cs @@ -49,7 +49,7 @@ namespace StardewModdingAPI.Framework /// Where to search for a matching content asset. /// The is empty or contains invalid characters. /// The content asset couldn't be loaded (e.g. because it doesn't exist). - public T Load(string key, ContentSource source) + public T Load(string key, ContentSource source = ContentSource.ModFolder) { this.AssertValidAssetKeyFormat(key); try @@ -110,7 +110,7 @@ namespace StardewModdingAPI.Framework /// The asset key to fetch (if the is ), or the local path to a content file relative to the mod folder. /// Where to search for a matching content asset. /// The is empty or contains invalid characters. - public string GetActualAssetKey(string key, ContentSource source) + public string GetActualAssetKey(string key, ContentSource source = ContentSource.ModFolder) { switch (source) { diff --git a/src/StardewModdingAPI/IContentHelper.cs b/src/StardewModdingAPI/IContentHelper.cs index 49182ce9..1d520135 100644 --- a/src/StardewModdingAPI/IContentHelper.cs +++ b/src/StardewModdingAPI/IContentHelper.cs @@ -13,12 +13,12 @@ namespace StardewModdingAPI /// Where to search for a matching content asset. /// The is empty or contains invalid characters. /// The content asset couldn't be loaded (e.g. because it doesn't exist). - T Load(string key, ContentSource source); + T Load(string key, ContentSource source = ContentSource.ModFolder); /// Get the underlying key in the game's content cache for an asset. This can be used to load custom map tilesheets, but should be avoided when you can use the content API instead. This does not validate whether the asset exists. /// The asset key to fetch (if the is ), or the local path to a content file relative to the mod folder. /// Where to search for a matching content asset. /// The is empty or contains invalid characters. - string GetActualAssetKey(string key, ContentSource source); + string GetActualAssetKey(string key, ContentSource source = ContentSource.ModFolder); } } -- cgit From 45613b4851919dec915fed6a2e81d982b2971b4e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 2 May 2017 23:53:15 -0400 Subject: store unknown fields in IManifest::ExtraFields (#275) --- release-notes.md | 1 + src/StardewModdingAPI/Framework/Manifest.cs | 6 ++++++ src/StardewModdingAPI/IManifest.cs | 7 ++++++- 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/release-notes.md b/release-notes.md index f1aa5b15..d1d2f82a 100644 --- a/release-notes.md +++ b/release-notes.md @@ -14,6 +14,7 @@ For mod developers: See [log](https://github.com/Pathoschild/SMAPI/compare/1.11...1.12). For mod developers: +* Unknown mod manifest fields are now stored in `IManifest::ExtraFields`. * The content API now defaults to `ContentSource.ModFolder`. * Fixed content API error when loading a PNG during early game init (e.g. in mod's `Entry`). * Fixed content API error when loading an XNB from the mod folder on Mac. diff --git a/src/StardewModdingAPI/Framework/Manifest.cs b/src/StardewModdingAPI/Framework/Manifest.cs index 189da9a8..62c711e2 100644 --- a/src/StardewModdingAPI/Framework/Manifest.cs +++ b/src/StardewModdingAPI/Framework/Manifest.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using StardewModdingAPI.Framework.Serialisation; namespace StardewModdingAPI.Framework @@ -35,5 +37,9 @@ namespace StardewModdingAPI.Framework /// Whether the mod uses per-save config files. [Obsolete("Use " + nameof(Mod) + "." + nameof(Mod.Helper) + "." + nameof(IModHelper.ReadConfig) + " instead")] public bool PerSaveConfigs { get; set; } + + /// Any manifest fields which didn't match a valid field. + [JsonExtensionData] + public IDictionary ExtraFields { get; set; } } } diff --git a/src/StardewModdingAPI/IManifest.cs b/src/StardewModdingAPI/IManifest.cs index 3e4b7513..d7c503a4 100644 --- a/src/StardewModdingAPI/IManifest.cs +++ b/src/StardewModdingAPI/IManifest.cs @@ -1,4 +1,6 @@ -namespace StardewModdingAPI +using System.Collections.Generic; + +namespace StardewModdingAPI { /// A manifest which describes a mod for SMAPI. public interface IManifest @@ -23,5 +25,8 @@ /// The name of the DLL in the directory that has the method. string EntryDll { get; set; } + + /// Any manifest fields which didn't match a valid field. + IDictionary ExtraFields { get; set; } } } \ No newline at end of file -- cgit From 0ef31f0b9ee892493f6f5319240bde8f3dd270ca Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 3 May 2017 00:40:21 -0400 Subject: support players with multiple copies of the game when installing (#274) --- release-notes.md | 3 ++ .../InteractiveInstaller.cs | 41 ++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/release-notes.md b/release-notes.md index d1d2f82a..df0a51da 100644 --- a/release-notes.md +++ b/release-notes.md @@ -13,6 +13,9 @@ For mod developers: ## 1.12 See [log](https://github.com/Pathoschild/SMAPI/compare/1.11...1.12). +For players: +* The installer now lets you choose the install path if you have multiple copies of the game, instead of using the first path found. + For mod developers: * Unknown mod manifest fields are now stored in `IManifest::ExtraFields`. * The content API now defaults to `ContentSource.ModFolder`. diff --git a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs index 38c19d2b..86e3d38a 100644 --- a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs +++ b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Reflection; @@ -128,7 +129,11 @@ namespace StardewModdingApi.Installer /**** ** collect details ****/ + // get platform Platform platform = this.DetectPlatform(); + this.PrintDebug($"Platform: {(platform == Platform.Windows ? "Windows" : "Linux or Mac")}."); + + // get folders DirectoryInfo packageDir = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "internal", platform.ToString())); DirectoryInfo installDir = this.InteractivelyGetInstallPath(platform); DirectoryInfo modsDir = new DirectoryInfo(Path.Combine(installDir.FullName, "Mods")); @@ -139,7 +144,7 @@ namespace StardewModdingApi.Installer unixLauncher = Path.Combine(installDir.FullName, "StardewValley"), unixLauncherBackup = Path.Combine(installDir.FullName, "StardewValley-original") }; - this.PrintDebug($"Detected {(platform == Platform.Windows ? "Windows" : "Linux or Mac")} with game in {installDir}."); + this.PrintDebug($"Install path: {installDir}."); /**** ** validate assumptions @@ -494,7 +499,7 @@ namespace StardewModdingApi.Installer } } - /// Interactively locate the game's install path. + /// Interactively locate the game install path to update. /// The current platform. private DirectoryInfo InteractivelyGetInstallPath(Platform platform) { @@ -503,12 +508,34 @@ namespace StardewModdingApi.Installer ? "Stardew Valley.exe" : "StardewValley.exe"; - // try default paths - foreach (string defaultPath in this.GetDefaultInstallPaths(platform)) + // get installed paths + DirectoryInfo[] defaultPaths = + ( + from path in this.GetDefaultInstallPaths(platform).Distinct() + let dir = new DirectoryInfo(path) + where dir.Exists && dir.EnumerateFiles(executableFilename).Any() + select dir + ) + .ToArray(); + + // choose where to install + if (defaultPaths.Any()) { - DirectoryInfo dir = new DirectoryInfo(defaultPath); - if (dir.Exists && dir.EnumerateFiles(executableFilename).Any()) - return new DirectoryInfo(defaultPath); + // only one path + if (defaultPaths.Length == 1) + return defaultPaths.First(); + + // let user choose path + Console.WriteLine(); + Console.WriteLine("Found multiple copies of the game:"); + for (int i = 0; i < defaultPaths.Length; i++) + Console.WriteLine($"[{i + 1}] {defaultPaths[i].FullName}"); + Console.WriteLine(); + + string[] validOptions = Enumerable.Range(1, defaultPaths.Length).Select(p => p.ToString(CultureInfo.InvariantCulture)).ToArray(); + string choice = this.InteractivelyChoose("Where do you want to add/remove SMAPI? Type the number next to your choice, then press enter.", validOptions); + int index = int.Parse(choice, CultureInfo.InvariantCulture) - 1; + return defaultPaths[index]; } // ask user -- cgit From e6d5883224863f3bf436b50179eadf1d686387da Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 3 May 2017 01:23:24 -0400 Subject: fix mods on Linux/Mac no longer working after the game saves (#281) --- release-notes.md | 1 + src/StardewModdingAPI/Context.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/release-notes.md b/release-notes.md index df0a51da..bf9367e5 100644 --- a/release-notes.md +++ b/release-notes.md @@ -15,6 +15,7 @@ See [log](https://github.com/Pathoschild/SMAPI/compare/1.11...1.12). For players: * The installer now lets you choose the install path if you have multiple copies of the game, instead of using the first path found. +* Fixed an issue where mods on Linux/Mac stopped working after the game saves. For mod developers: * Unknown mod manifest fields are now stored in `IManifest::ExtraFields`. diff --git a/src/StardewModdingAPI/Context.cs b/src/StardewModdingAPI/Context.cs index 415b4aac..2da14eed 100644 --- a/src/StardewModdingAPI/Context.cs +++ b/src/StardewModdingAPI/Context.cs @@ -1,4 +1,5 @@ using StardewValley; +using StardewValley.Menus; namespace StardewModdingAPI { @@ -12,7 +13,7 @@ namespace StardewModdingAPI public static bool IsSaveLoaded => Game1.hasLoadedGame && !string.IsNullOrEmpty(Game1.player.name); /// Whether the game is currently writing to the save file. - public static bool IsSaving => SaveGame.IsProcessing; + public static bool IsSaving => SaveGame.IsProcessing && (Game1.activeClickableMenu is SaveGameMenu || Game1.activeClickableMenu is ShippingMenu); // IsProcessing is never set to false on Linux/Mac /// Whether the game is currently running the draw loop. public static bool IsInDrawLoop { get; set; } -- cgit From 3ed16a8ea67cf847d08d463deef969a3edf99b2e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 3 May 2017 11:36:36 -0400 Subject: recover game after draw errors to prevent crash --- release-notes.md | 1 + src/StardewModdingAPI/Framework/SGame.cs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'src') diff --git a/release-notes.md b/release-notes.md index bf9367e5..5d646276 100644 --- a/release-notes.md +++ b/release-notes.md @@ -14,6 +14,7 @@ For mod developers: See [log](https://github.com/Pathoschild/SMAPI/compare/1.11...1.12). For players: +* SMAPI now recovers the game from mod draw errors to prevent a game crash. * The installer now lets you choose the install path if you have multiple copies of the game, instead of using the first path found. * Fixed an issue where mods on Linux/Mac stopped working after the game saves. diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs index fe7d3aa3..3a82963d 100644 --- a/src/StardewModdingAPI/Framework/SGame.cs +++ b/src/StardewModdingAPI/Framework/SGame.cs @@ -947,7 +947,28 @@ namespace StardewModdingAPI.Framework } catch (Exception ex) { + // log error this.Monitor.Log($"An error occured in the overridden draw loop: {ex.GetLogSummary()}", LogLevel.Error); + + // fix sprite batch + try + { + bool isSpriteBatchOpen = +#if SMAPI_FOR_WINDOWS + SGame.Reflection.GetPrivateValue(Game1.spriteBatch, "inBeginEndPair"); +#else + SGame.Reflection.GetPrivateValue(Game1.spriteBatch, "_beginCalled"); +#endif + if (isSpriteBatchOpen) + { + this.Monitor.Log("Recovering sprite batch from error...", LogLevel.Trace); + Game1.spriteBatch.End(); + } + } + catch (Exception innerEx) + { + this.Monitor.Log($"Could not recover sprite batch state: {innerEx.GetLogSummary()}", LogLevel.Error); + } } Context.IsInDrawLoop = false; } -- cgit From dfa4bbaa395cbcd3bc99d88b6d6066409ef1b013 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 3 May 2017 11:58:33 -0400 Subject: adopt pufferchick as SMAPI icon --- release-notes.md | 1 + src/StardewModdingAPI/icon.ico | Bin 4286 -> 15086 bytes 2 files changed, 1 insertion(+) (limited to 'src') diff --git a/release-notes.md b/release-notes.md index 5d646276..362b35e8 100644 --- a/release-notes.md +++ b/release-notes.md @@ -17,6 +17,7 @@ For players: * SMAPI now recovers the game from mod draw errors to prevent a game crash. * The installer now lets you choose the install path if you have multiple copies of the game, instead of using the first path found. * Fixed an issue where mods on Linux/Mac stopped working after the game saves. +* Adopted pufferchick. For mod developers: * Unknown mod manifest fields are now stored in `IManifest::ExtraFields`. diff --git a/src/StardewModdingAPI/icon.ico b/src/StardewModdingAPI/icon.ico index 2985c5cd..587a6e74 100644 Binary files a/src/StardewModdingAPI/icon.ico and b/src/StardewModdingAPI/icon.ico differ -- cgit From 6557c5241bce0770c193dc5e47ac6bea1843916c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 3 May 2017 12:28:05 -0400 Subject: bundle libgdiplus into SMAPI on Linux/Mac to fix errors loading PNGs (#277) --- lib/libgdiplus.dylib | Bin 0 -> 1202796 bytes release-notes.md | 5 +++-- src/prepare-install-package.targets | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 lib/libgdiplus.dylib (limited to 'src') diff --git a/lib/libgdiplus.dylib b/lib/libgdiplus.dylib new file mode 100644 index 00000000..8a9676c8 Binary files /dev/null and b/lib/libgdiplus.dylib differ diff --git a/release-notes.md b/release-notes.md index 362b35e8..af535895 100644 --- a/release-notes.md +++ b/release-notes.md @@ -14,9 +14,10 @@ For mod developers: See [log](https://github.com/Pathoschild/SMAPI/compare/1.11...1.12). For players: -* SMAPI now recovers the game from mod draw errors to prevent a game crash. * The installer now lets you choose the install path if you have multiple copies of the game, instead of using the first path found. -* Fixed an issue where mods on Linux/Mac stopped working after the game saves. +* Fixed mod draw errors breaking the game. +* Fixed mods on Linux/Mac no longer working after the game saves. +* Fixed libgdiplus DLL-not-found errors on Linux/Mac when mods read PNG files. * Adopted pufferchick. For mod developers: diff --git a/src/prepare-install-package.targets b/src/prepare-install-package.targets index 709bd8d4..ce257cc2 100644 --- a/src/prepare-install-package.targets +++ b/src/prepare-install-package.targets @@ -33,6 +33,9 @@ + + + -- cgit From 0530270790a0c2a026377faf0374b719bfed5702 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 3 May 2017 12:30:40 -0400 Subject: bump version for release --- src/GlobalAssemblyInfo.cs | 4 ++-- src/StardewModdingAPI/Constants.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/GlobalAssemblyInfo.cs b/src/GlobalAssemblyInfo.cs index 3de78da4..06b99c67 100644 --- a/src/GlobalAssemblyInfo.cs +++ b/src/GlobalAssemblyInfo.cs @@ -2,5 +2,5 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] -[assembly: AssemblyVersion("1.11.0.0")] -[assembly: AssemblyFileVersion("1.11.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.12.0.0")] +[assembly: AssemblyFileVersion("1.12.0.0")] \ No newline at end of file diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs index fec634e0..1860795d 100644 --- a/src/StardewModdingAPI/Constants.cs +++ b/src/StardewModdingAPI/Constants.cs @@ -33,7 +33,7 @@ namespace StardewModdingAPI ** Public ****/ /// SMAPI's current semantic version. - public static ISemanticVersion ApiVersion { get; } = new SemanticVersion(1, 11, 0); + public static ISemanticVersion ApiVersion { get; } = new SemanticVersion(1, 12, 0); /// The minimum supported version of Stardew Valley. public static ISemanticVersion MinimumGameVersion { get; } = new SemanticVersion("1.2.26"); -- cgit From 0a2f7e52b9fc1e60fe491b8fd28cf8377f79290b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 3 May 2017 12:46:48 -0400 Subject: fix code style --- src/StardewModdingAPI/Framework/SGame.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs index 3a82963d..1f2bf3ac 100644 --- a/src/StardewModdingAPI/Framework/SGame.cs +++ b/src/StardewModdingAPI/Framework/SGame.cs @@ -1366,8 +1366,8 @@ namespace StardewModdingAPI.Framework /// The enumeration of items to hash. private int GetHash(IEnumerable enumerable) { - var hash = 0; - foreach (var v in enumerable) + int hash = 0; + foreach (object v in enumerable) hash ^= v.GetHashCode(); return hash; } -- cgit