From 3fa0433c9862d1922cd0540848d2bd8716934d1f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 2 Apr 2021 21:30:55 -0400 Subject: add initial support for 64-bit Windows hack (#767) --- src/SMAPI/Framework/Logging/LogManager.cs | 3 +++ src/SMAPI/Framework/SCore.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs index 243ca3ae..38d561e5 100644 --- a/src/SMAPI/Framework/Logging/LogManager.cs +++ b/src/SMAPI/Framework/Logging/LogManager.cs @@ -287,6 +287,9 @@ namespace StardewModdingAPI.Framework.Logging string platformLabel = EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform); if ((Constants.GameFramework == GameFramework.Xna) != (Constants.Platform == Platform.Windows)) platformLabel += $" with {Constants.GameFramework}"; +#if SMAPI_FOR_WINDOWS_64BIT_HACK + platformLabel += " 64-bit hack"; +#endif // init logging this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {platformLabel}", LogLevel.Info); diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index ebb21555..22c58099 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -419,7 +419,7 @@ namespace StardewModdingAPI.Framework Game1.mapDisplayDevice = new SDisplayDevice(Game1.content, Game1.game1.GraphicsDevice); // log GPU info -#if SMAPI_FOR_WINDOWS +#if SMAPI_FOR_WINDOWS && !SMAPI_FOR_WINDOWS_64BIT_HACK this.Monitor.Log($"Running on GPU: {Game1.game1.GraphicsDevice?.Adapter?.Description ?? ""}"); #endif } -- cgit From 60b563267ea7bc308d7eda55477f61fa063b069a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 2 Apr 2021 21:30:55 -0400 Subject: fix asset key normalization for 64-bit hack (#767) --- src/SMAPI/Framework/Content/ContentCache.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/Content/ContentCache.cs b/src/SMAPI/Framework/Content/ContentCache.cs index 7edc9ab9..5c7ad778 100644 --- a/src/SMAPI/Framework/Content/ContentCache.cs +++ b/src/SMAPI/Framework/Content/ContentCache.cs @@ -57,6 +57,8 @@ namespace StardewModdingAPI.Framework.Content IReflectedMethod method = reflection.GetMethod(typeof(TitleContainer), "GetCleanPath"); this.NormalizeAssetNameForPlatform = path => method.Invoke(path); } + else if (EarlyConstants.IsWindows64BitHack) + this.NormalizeAssetNameForPlatform = PathUtilities.NormalizePath; else this.NormalizeAssetNameForPlatform = key => key.Replace('\\', '/'); // based on MonoGame's ContentManager.Load logic } -- cgit From 2d8f916053a1b4b039a41a8bbe8018ebe2654022 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 3 Apr 2021 11:39:58 -0400 Subject: log failed root dependencies in their own group --- src/SMAPI/Framework/IModMetadata.cs | 5 + src/SMAPI/Framework/Logging/LogManager.cs | 163 +++++++++++++++++--------- src/SMAPI/Framework/ModLoading/ModMetadata.cs | 53 +++++++-- 3 files changed, 155 insertions(+), 66 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/IModMetadata.cs b/src/SMAPI/Framework/IModMetadata.cs index 5d2f352d..f5babafb 100644 --- a/src/SMAPI/Framework/IModMetadata.cs +++ b/src/SMAPI/Framework/IModMetadata.cs @@ -117,6 +117,11 @@ namespace StardewModdingAPI.Framework /// Only return valid update keys. IEnumerable GetUpdateKeys(bool validOnly = true); + /// Get whether the given mod ID must be installed to load this mod. + /// The mod ID to check. + /// Whether to include optional dependencies. + bool HasRequiredModId(string modId, bool includeOptional); + /// Get the mod IDs that must be installed to load this mod. /// Whether to include optional dependencies. IEnumerable GetRequiredModIds(bool includeOptional = false); diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs index 38d561e5..4ba4fffc 100644 --- a/src/SMAPI/Framework/Logging/LogManager.cs +++ b/src/SMAPI/Framework/Logging/LogManager.cs @@ -429,67 +429,38 @@ namespace StardewModdingAPI.Framework.Logging // log skipped mods if (skippedMods.Any()) { - // get logging logic - HashSet loggedDuplicateIds = new HashSet(); - void LogSkippedMod(IModMetadata mod) - { - string message = $" - {mod.DisplayName}{(mod.Manifest?.Version != null ? " " + mod.Manifest.Version.ToString() : "")} because {mod.Error}"; + var loggedDuplicateIds = new HashSet(); - // handle duplicate mods - // (log first duplicate only, don't show redundant version) - if (mod.FailReason == ModFailReason.Duplicate && mod.HasManifest()) + this.Monitor.Log(" Skipped mods", LogLevel.Error); + this.Monitor.Log(" " + "".PadRight(50, '-'), LogLevel.Error); + this.Monitor.Log(" These mods could not be added to your game.", LogLevel.Error); + this.Monitor.Newline(); + foreach (var list in this.GroupFailedModsByPriority(skippedMods)) + { + if (list.Any()) { - if (!loggedDuplicateIds.Add(mod.Manifest.UniqueID)) - return; // already logged + foreach (IModMetadata mod in list.OrderBy(p => p.DisplayName)) + { + string message = $" - {mod.DisplayName}{(" " + mod.Manifest?.Version?.ToString()).TrimEnd()} because {mod.Error}"; - message = $" - {mod.DisplayName} because {mod.Error}"; - } + // duplicate mod: log first one only, don't show redundant version + if (mod.FailReason == ModFailReason.Duplicate && mod.HasManifest()) + { + if (loggedDuplicateIds.Add(mod.Manifest.UniqueID)) + continue; // already logged - // log message - this.Monitor.Log(message, LogLevel.Error); - if (mod.ErrorDetails != null) - this.Monitor.Log($" ({mod.ErrorDetails})"); - } + message = $" - {mod.DisplayName} because {mod.Error}"; + } - // group mods - List skippedDependencies = new List(); - List otherSkippedMods = new List(); - { - // track broken dependencies - HashSet skippedDependencyIds = new HashSet(StringComparer.OrdinalIgnoreCase); - HashSet skippedModIds = new HashSet(from mod in skippedMods where mod.HasID() select mod.Manifest.UniqueID, StringComparer.OrdinalIgnoreCase); - foreach (IModMetadata mod in skippedMods) - { - foreach (string requiredId in skippedModIds.Intersect(mod.GetRequiredModIds())) - skippedDependencyIds.Add(requiredId); - } + // log message + this.Monitor.Log(message, LogLevel.Error); + if (mod.ErrorDetails != null) + this.Monitor.Log($" ({mod.ErrorDetails})"); + } - // collect mod groups - foreach (IModMetadata mod in skippedMods) - { - if (mod.HasID() && skippedDependencyIds.Contains(mod.Manifest.UniqueID)) - skippedDependencies.Add(mod); - else - otherSkippedMods.Add(mod); + this.Monitor.Newline(); } } - - // log skipped mods - this.Monitor.Log(" Skipped mods", LogLevel.Error); - this.Monitor.Log(" " + "".PadRight(50, '-'), LogLevel.Error); - this.Monitor.Log(" These mods could not be added to your game.", LogLevel.Error); - this.Monitor.Newline(); - - if (skippedDependencies.Any()) - { - foreach (IModMetadata mod in skippedDependencies.OrderBy(p => p.DisplayName)) - LogSkippedMod(mod); - this.Monitor.Newline(); - } - - foreach (IModMetadata mod in otherSkippedMods.OrderBy(p => p.DisplayName)) - LogSkippedMod(mod); - this.Monitor.Newline(); } // log warnings @@ -561,6 +532,92 @@ namespace StardewModdingAPI.Framework.Logging } } + /// Group failed mods by the priority players should update them, where mods in earlier groups are more likely to fix multiple mods. + /// The failed mods to group. + private IEnumerable> GroupFailedModsByPriority(IList failedMods) + { + var failedOthers = failedMods.ToList(); + var skippedModIds = new HashSet(from mod in failedMods where mod.HasID() select mod.Manifest.UniqueID, StringComparer.OrdinalIgnoreCase); + + // group B: dependencies which failed + var failedOtherDependencies = new List(); + { + // get failed dependency IDs + var skippedDependencyIds = new HashSet(StringComparer.OrdinalIgnoreCase); + foreach (IModMetadata mod in failedMods) + { + foreach (string requiredId in skippedModIds.Intersect(mod.GetRequiredModIds())) + skippedDependencyIds.Add(requiredId); + } + + // group matching mods + this.FilterThrough( + fromList: failedOthers, + toList: failedOtherDependencies, + match: mod => mod.HasID() && skippedDependencyIds.Contains(mod.Manifest.UniqueID) + ); + } + + // group A: failed root dependencies which other dependencies need + var failedRootDependencies = new List(); + { + var skippedDependencyIds = new HashSet(failedOtherDependencies.Select(p => p.Manifest.UniqueID)); + this.FilterThrough( + fromList: failedOtherDependencies, + toList: failedRootDependencies, + match: mod => + { + // has no failed dependency + foreach (string requiredId in mod.GetRequiredModIds()) + { + if (skippedDependencyIds.Contains(requiredId)) + return false; + } + + // another dependency depends on this mod + bool isDependedOn = false; + foreach (IModMetadata other in failedOtherDependencies) + { + if (other.HasRequiredModId(mod.Manifest.UniqueID, includeOptional: false)) + { + isDependedOn = true; + break; + } + } + + return isDependedOn; + } + ); + } + + // return groups + return new[] + { + failedRootDependencies, + failedOtherDependencies, + failedOthers + }; + } + + /// Filter matching items from one list and add them to the other. + /// The list item type. + /// The list to filter. + /// The list to which to add filtered items. + /// Matches items to filter through. + private void FilterThrough(IList fromList, IList toList, Func match) + { + for (int i = 0; i < fromList.Count; i++) + { + TItem item = fromList[i]; + if (match(item)) + { + toList.Add(item); + fromList.RemoveAt(i); + i--; + } + } + } + /// Write a mod warning group to the console and log. /// The mods to search. /// Matches mods to include in the warning group. diff --git a/src/SMAPI/Framework/ModLoading/ModMetadata.cs b/src/SMAPI/Framework/ModLoading/ModMetadata.cs index b4de3d6c..0d89fd20 100644 --- a/src/SMAPI/Framework/ModLoading/ModMetadata.cs +++ b/src/SMAPI/Framework/ModLoading/ModMetadata.cs @@ -19,6 +19,9 @@ namespace StardewModdingAPI.Framework.ModLoading /// The non-error issues with the mod, including warnings suppressed by the data record. private ModWarning ActualWarnings = ModWarning.None; + /// The mod IDs which are listed as a requirement by this mod. The value for each pair indicates whether the dependency is required (i.e. not an optional dependency). + private Lazy> Dependencies; + /********* ** Accessors @@ -100,6 +103,8 @@ namespace StardewModdingAPI.Framework.ModLoading this.Manifest = manifest; this.DataRecord = dataRecord; this.IsIgnored = isIgnored; + + this.Dependencies = new Lazy>(this.ExtractDependencies); } /// @@ -199,23 +204,21 @@ namespace StardewModdingAPI.Framework.ModLoading } /// - public IEnumerable GetRequiredModIds(bool includeOptional = false) + public bool HasRequiredModId(string modId, bool includeOptional) { - HashSet required = new HashSet(StringComparer.OrdinalIgnoreCase); + return + this.Dependencies.Value.TryGetValue(modId, out bool isRequired) + && (includeOptional || isRequired); + } - // yield dependencies - if (this.Manifest?.Dependencies != null) + /// + public IEnumerable GetRequiredModIds(bool includeOptional = false) + { + foreach (var pair in this.Dependencies.Value) { - foreach (var entry in this.Manifest?.Dependencies) - { - if ((entry.IsRequired || includeOptional) && required.Add(entry.UniqueID)) - yield return entry.UniqueID; - } + if (includeOptional || pair.Value) + yield return pair.Key; } - - // yield content pack parent - if (this.Manifest?.ContentPackFor?.UniqueID != null && required.Add(this.Manifest.ContentPackFor.UniqueID)) - yield return this.Manifest.ContentPackFor.UniqueID; } /// @@ -237,5 +240,29 @@ namespace StardewModdingAPI.Framework.ModLoading string rootFolderName = Path.GetFileName(this.RootPath) ?? ""; return Path.Combine(rootFolderName, this.RelativeDirectoryPath); } + + + /********* + ** Private methods + *********/ + /// Extract mod IDs from the manifest that must be installed to load this mod. + /// Returns a dictionary of mod ID => is required (i.e. not an optional dependency). + public IDictionary ExtractDependencies() + { + var ids = new Dictionary(StringComparer.OrdinalIgnoreCase); + + // yield dependencies + if (this.Manifest?.Dependencies != null) + { + foreach (var entry in this.Manifest?.Dependencies) + ids[entry.UniqueID] = entry.IsRequired; + } + + // yield content pack parent + if (this.Manifest?.ContentPackFor?.UniqueID != null) + ids[this.Manifest.ContentPackFor.UniqueID] = true; + + return ids; + } } } -- cgit From 222183c651c5b5d9e402db1b8009e2e0a0681b06 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 4 Apr 2021 11:37:11 -0400 Subject: standardize spelling of 'macOS' --- src/SMAPI/Framework/Content/AssetDataForImage.cs | 4 ++-- src/SMAPI/Framework/ContentPack.cs | 2 +- src/SMAPI/Framework/Logging/LogFileManager.cs | 2 +- src/SMAPI/Framework/Logging/LogManager.cs | 2 +- src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs | 2 +- src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs | 4 ++-- src/SMAPI/Framework/SCore.cs | 4 ++-- src/SMAPI/Framework/Serialization/ColorConverter.cs | 2 +- src/SMAPI/Framework/Serialization/PointConverter.cs | 2 +- src/SMAPI/Framework/Serialization/RectangleConverter.cs | 2 +- src/SMAPI/Framework/Serialization/Vector2Converter.cs | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/Content/AssetDataForImage.cs b/src/SMAPI/Framework/Content/AssetDataForImage.cs index 5f91610e..529fb93a 100644 --- a/src/SMAPI/Framework/Content/AssetDataForImage.cs +++ b/src/SMAPI/Framework/Content/AssetDataForImage.cs @@ -12,7 +12,7 @@ namespace StardewModdingAPI.Framework.Content ** Fields *********/ /// The minimum value to consider non-transparent. - /// On Linux/Mac, fully transparent pixels may have an alpha up to 4 for some reason. + /// On Linux/macOS, fully transparent pixels may have an alpha up to 4 for some reason. private const byte MinOpacity = 5; @@ -82,7 +82,7 @@ namespace StardewModdingAPI.Framework.Content // premultiplied by the content pipeline. The formula is derived from // https://blogs.msdn.microsoft.com/shawnhar/2009/11/06/premultiplied-alpha/. // Note: don't use named arguments here since they're different between - // Linux/Mac and Windows. + // Linux/macOS and Windows. float alphaBelow = 1 - (above.A / 255f); newData[i] = new Color( (int)(above.R + (below.R * alphaBelow)), // r diff --git a/src/SMAPI/Framework/ContentPack.cs b/src/SMAPI/Framework/ContentPack.cs index a6835dbe..0660a367 100644 --- a/src/SMAPI/Framework/ContentPack.cs +++ b/src/SMAPI/Framework/ContentPack.cs @@ -18,7 +18,7 @@ namespace StardewModdingAPI.Framework /// Encapsulates SMAPI's JSON file parsing. private readonly JsonHelper JsonHelper; - /// A cache of case-insensitive => exact relative paths within the content pack, for case-insensitive file lookups on Linux/Mac. + /// A cache of case-insensitive => exact relative paths within the content pack, for case-insensitive file lookups on Linux/macOS. private readonly IDictionary RelativePaths = new Dictionary(StringComparer.OrdinalIgnoreCase); diff --git a/src/SMAPI/Framework/Logging/LogFileManager.cs b/src/SMAPI/Framework/Logging/LogFileManager.cs index 6b5babcd..6ab2bdfb 100644 --- a/src/SMAPI/Framework/Logging/LogFileManager.cs +++ b/src/SMAPI/Framework/Logging/LogFileManager.cs @@ -44,7 +44,7 @@ namespace StardewModdingAPI.Framework.Logging public void WriteLine(string message) { // always use Windows-style line endings for convenience - // (Linux/Mac editors are fine with them, Windows editors often require them) + // (Linux/macOS editors are fine with them, Windows editors often require them) this.Stream.Write(message + "\r\n"); } diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs index 4ba4fffc..0cc2da9f 100644 --- a/src/SMAPI/Framework/Logging/LogManager.cs +++ b/src/SMAPI/Framework/Logging/LogManager.cs @@ -527,7 +527,7 @@ namespace StardewModdingAPI.Framework.Logging // not crossplatform this.LogModWarningGroup(modsWithWarnings, ModWarning.UsesDynamic, LogLevel.Debug, "Not crossplatform", - "These mods use the 'dynamic' keyword, and won't work on Linux/Mac." + "These mods use the 'dynamic' keyword, and won't work on Linux/macOS." ); } } diff --git a/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs b/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs index a948213b..baffc50e 100644 --- a/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs +++ b/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs @@ -20,7 +20,7 @@ namespace StardewModdingAPI.Framework.ModLoading /// The instruction is compatible, but affects the save serializer in a way that may make saves unloadable without the mod. DetectedSaveSerializer, - /// The instruction is compatible, but uses the dynamic keyword which won't work on Linux/Mac. + /// The instruction is compatible, but uses the dynamic keyword which won't work on Linux/macOS. DetectedDynamic, /// The instruction is compatible, but references or which may impact stability. diff --git a/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs b/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs index cf71af77..aefd1c20 100644 --- a/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs +++ b/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchFacade.cs @@ -4,10 +4,10 @@ using Microsoft.Xna.Framework.Graphics; namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades { - /// Provides method signatures that can be injected into mod code for compatibility between Linux/Mac or Windows. + /// Provides method signatures that can be injected into mod code for compatibility between Linux/macOS or Windows. /// This is public to support SMAPI rewriting and should not be referenced directly by mods. [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = "Used via assembly rewriting")] - [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Linux/Mac.")] + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Linux/macOS.")] [SuppressMessage("ReSharper", "CS1591", Justification = "Documentation not needed for facade classes.")] public class SpriteBatchFacade : SpriteBatch { diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 22c58099..e8c8a8e5 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -187,7 +187,7 @@ namespace StardewModdingAPI.Framework #if SMAPI_FOR_WINDOWS if (Constants.Platform != Platform.Windows) { - this.Monitor.Log("Oops! You're running Windows, but this version of SMAPI is for Linux or Mac. Please reinstall SMAPI to fix this.", LogLevel.Error); + this.Monitor.Log("Oops! You're running Windows, but this version of SMAPI is for Linux or macOS. Please reinstall SMAPI to fix this.", LogLevel.Error); this.LogManager.PressAnyKeyToExit(); } #else @@ -1259,7 +1259,7 @@ namespace StardewModdingAPI.Framework // create client string url = this.Settings.WebApiBaseUrl; #if !SMAPI_FOR_WINDOWS - url = url.Replace("https://", "http://"); // workaround for OpenSSL issues with the game's bundled Mono on Linux/Mac + url = url.Replace("https://", "http://"); // workaround for OpenSSL issues with the game's bundled Mono on Linux/macOS #endif WebApiClient client = new WebApiClient(url, Constants.ApiVersion); this.Monitor.Log("Checking for updates..."); diff --git a/src/SMAPI/Framework/Serialization/ColorConverter.cs b/src/SMAPI/Framework/Serialization/ColorConverter.cs index 7315f1a5..3b3720b5 100644 --- a/src/SMAPI/Framework/Serialization/ColorConverter.cs +++ b/src/SMAPI/Framework/Serialization/ColorConverter.cs @@ -8,7 +8,7 @@ namespace StardewModdingAPI.Framework.Serialization { /// Handles deserialization of for crossplatform compatibility. /// - /// - Linux/Mac format: { "B": 76, "G": 51, "R": 25, "A": 102 } + /// - Linux/macOS format: { "B": 76, "G": 51, "R": 25, "A": 102 } /// - Windows format: "26, 51, 76, 102" /// internal class ColorConverter : SimpleReadOnlyConverter diff --git a/src/SMAPI/Framework/Serialization/PointConverter.cs b/src/SMAPI/Framework/Serialization/PointConverter.cs index 6cf795dc..21d1f845 100644 --- a/src/SMAPI/Framework/Serialization/PointConverter.cs +++ b/src/SMAPI/Framework/Serialization/PointConverter.cs @@ -8,7 +8,7 @@ namespace StardewModdingAPI.Framework.Serialization { /// Handles deserialization of for crossplatform compatibility. /// - /// - Linux/Mac format: { "X": 1, "Y": 2 } + /// - Linux/macOS format: { "X": 1, "Y": 2 } /// - Windows format: "1, 2" /// internal class PointConverter : SimpleReadOnlyConverter diff --git a/src/SMAPI/Framework/Serialization/RectangleConverter.cs b/src/SMAPI/Framework/Serialization/RectangleConverter.cs index 8f7318b3..31f3ad77 100644 --- a/src/SMAPI/Framework/Serialization/RectangleConverter.cs +++ b/src/SMAPI/Framework/Serialization/RectangleConverter.cs @@ -9,7 +9,7 @@ namespace StardewModdingAPI.Framework.Serialization { /// Handles deserialization of for crossplatform compatibility. /// - /// - Linux/Mac format: { "X": 1, "Y": 2, "Width": 3, "Height": 4 } + /// - Linux/macOS format: { "X": 1, "Y": 2, "Width": 3, "Height": 4 } /// - Windows format: "{X:1 Y:2 Width:3 Height:4}" /// internal class RectangleConverter : SimpleReadOnlyConverter diff --git a/src/SMAPI/Framework/Serialization/Vector2Converter.cs b/src/SMAPI/Framework/Serialization/Vector2Converter.cs index 3e2ab776..589febf8 100644 --- a/src/SMAPI/Framework/Serialization/Vector2Converter.cs +++ b/src/SMAPI/Framework/Serialization/Vector2Converter.cs @@ -8,7 +8,7 @@ namespace StardewModdingAPI.Framework.Serialization { /// Handles deserialization of for crossplatform compatibility. /// - /// - Linux/Mac format: { "X": 1, "Y": 2 } + /// - Linux/macOS format: { "X": 1, "Y": 2 } /// - Windows format: "1, 2" /// internal class Vector2Converter : SimpleReadOnlyConverter -- cgit From 2b1b3b19a507876e106a444c93b4c33aca35c353 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 4 Apr 2021 11:40:08 -0400 Subject: improve error-handling during asset propagation --- src/SMAPI/Framework/ContentCoordinator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index 2920e670..d0e759c2 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -132,7 +132,7 @@ namespace StardewModdingAPI.Framework ); this.ContentManagers.Add(contentManagerForAssetPropagation); this.VanillaContentManager = new LocalizedContentManager(serviceProvider, rootDirectory); - this.CoreAssets = new CoreAssetPropagator(this.MainContentManager, contentManagerForAssetPropagation, reflection, aggressiveMemoryOptimizations); + this.CoreAssets = new CoreAssetPropagator(this.MainContentManager, contentManagerForAssetPropagation, this.Monitor, reflection, aggressiveMemoryOptimizations); } /// Get a new content manager which handles reading files from the game content folder with support for interception. -- cgit From f961a376ee5347d5ac2b830ce82b28f116889e72 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 15 Apr 2021 21:17:19 -0400 Subject: log Stardew64Installer patch version if applicable (#767) --- src/SMAPI/Framework/Logging/LogManager.cs | 37 +++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs index 0cc2da9f..804acfb3 100644 --- a/src/SMAPI/Framework/Logging/LogManager.cs +++ b/src/SMAPI/Framework/Logging/LogManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; +using System.Reflection; using System.Text.RegularExpressions; using System.Threading; using StardewModdingAPI.Framework.Commands; @@ -11,6 +12,7 @@ using StardewModdingAPI.Framework.ModLoading; using StardewModdingAPI.Internal.ConsoleWriting; using StardewModdingAPI.Toolkit.Framework.ModData; using StardewModdingAPI.Toolkit.Utilities; +using StardewValley; namespace StardewModdingAPI.Framework.Logging { @@ -283,16 +285,16 @@ namespace StardewModdingAPI.Framework.Logging /// The custom SMAPI settings. public void LogIntro(string modsPath, IDictionary customSettings) { - // get platform label - string platformLabel = EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform); - if ((Constants.GameFramework == GameFramework.Xna) != (Constants.Platform == Platform.Windows)) - platformLabel += $" with {Constants.GameFramework}"; -#if SMAPI_FOR_WINDOWS_64BIT_HACK - platformLabel += " 64-bit hack"; -#endif + // log platform & patches + { + this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform)}", LogLevel.Info); - // init logging - this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {platformLabel}", LogLevel.Info); + string[] patchLabels = this.GetPatchLabels().ToArray(); + if (patchLabels.Any()) + this.Monitor.Log($"Detected custom version: {string.Join(", ", patchLabels)}", LogLevel.Info); + } + + // log basic info this.Monitor.Log($"Mods go here: {modsPath}", LogLevel.Info); if (modsPath != Constants.DefaultModsPath) this.Monitor.Log("(Using custom --mods-path argument.)"); @@ -409,6 +411,23 @@ namespace StardewModdingAPI.Framework.Logging gameMonitor.Log(message, level); } + /// Get human-readable labels to log for detected SMAPI and Stardew Valley customizations. + private IEnumerable GetPatchLabels() + { + // custom game framework + if (EarlyConstants.IsWindows64BitHack) + yield return $"running 64-bit SMAPI with {Constants.GameFramework}"; + else if ((Constants.GameFramework == GameFramework.Xna) != (Constants.Platform == Platform.Windows)) + yield return $"running {Constants.GameFramework}"; + + // patched by Stardew64Installer + { + PropertyInfo patcherProperty = typeof(Game1).GetProperty("Stardew64InstallerVersion"); + if (patcherProperty != null) + yield return $"patched by Stardew64Installer {patcherProperty.GetValue(null)}"; + } + } + /// Write a summary of mod warnings to the console and log. /// The loaded mods. /// The mods which could not be loaded. -- cgit From 9174e17f5372905d3f494e1b36688f41dff367cc Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 17 Apr 2021 22:10:51 -0400 Subject: mark field readonly --- src/SMAPI/Framework/ModLoading/ModMetadata.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ModLoading/ModMetadata.cs b/src/SMAPI/Framework/ModLoading/ModMetadata.cs index 0d89fd20..17e6d59a 100644 --- a/src/SMAPI/Framework/ModLoading/ModMetadata.cs +++ b/src/SMAPI/Framework/ModLoading/ModMetadata.cs @@ -20,7 +20,7 @@ namespace StardewModdingAPI.Framework.ModLoading private ModWarning ActualWarnings = ModWarning.None; /// The mod IDs which are listed as a requirement by this mod. The value for each pair indicates whether the dependency is required (i.e. not an optional dependency). - private Lazy> Dependencies; + private readonly Lazy> Dependencies; /********* -- cgit From 665c6806d3797f8329ef8c6fcaa80d469fef5005 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 22 Apr 2021 21:52:09 -0400 Subject: add update alerts for Stardew64Installer (#767) --- src/SMAPI/Framework/Logging/LogManager.cs | 9 ++------ src/SMAPI/Framework/Models/SConfig.cs | 3 +++ src/SMAPI/Framework/SCore.cs | 35 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs index 804acfb3..a4df3c18 100644 --- a/src/SMAPI/Framework/Logging/LogManager.cs +++ b/src/SMAPI/Framework/Logging/LogManager.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; -using System.Reflection; using System.Text.RegularExpressions; using System.Threading; using StardewModdingAPI.Framework.Commands; @@ -12,7 +11,6 @@ using StardewModdingAPI.Framework.ModLoading; using StardewModdingAPI.Internal.ConsoleWriting; using StardewModdingAPI.Toolkit.Framework.ModData; using StardewModdingAPI.Toolkit.Utilities; -using StardewValley; namespace StardewModdingAPI.Framework.Logging { @@ -421,11 +419,8 @@ namespace StardewModdingAPI.Framework.Logging yield return $"running {Constants.GameFramework}"; // patched by Stardew64Installer - { - PropertyInfo patcherProperty = typeof(Game1).GetProperty("Stardew64InstallerVersion"); - if (patcherProperty != null) - yield return $"patched by Stardew64Installer {patcherProperty.GetValue(null)}"; - } + if (Constants.IsPatchedByStardew64Installer(out ISemanticVersion patchedByVersion)) + yield return $"patched by Stardew64Installer {patchedByVersion}"; } /// Write a summary of mod warnings to the console and log. diff --git a/src/SMAPI/Framework/Models/SConfig.cs b/src/SMAPI/Framework/Models/SConfig.cs index 4a80e34c..a71bafd9 100644 --- a/src/SMAPI/Framework/Models/SConfig.cs +++ b/src/SMAPI/Framework/Models/SConfig.cs @@ -52,6 +52,9 @@ namespace StardewModdingAPI.Framework.Models /// SMAPI's GitHub project name, used to perform update checks. public string GitHubProjectName { get; set; } + /// Stardew64Installer's GitHub project name, used to perform update checks. + public string Stardew64InstallerGitHubProjectName { get; set; } + /// The base URL for SMAPI's web API, used to perform update checks. public string WebApiBaseUrl { get; set; } diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index e8c8a8e5..85a2bb8f 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1302,6 +1302,41 @@ namespace StardewModdingAPI.Framework this.LogManager.WriteUpdateMarker(updateFound.ToString(), updateUrl); } + // check Stardew64Installer version + if (Constants.IsPatchedByStardew64Installer(out ISemanticVersion patchedByVersion)) + { + ISemanticVersion updateFound = null; + string updateUrl = null; + try + { + // fetch update check + ModEntryModel response = client.GetModInfo(new[] { new ModSearchEntryModel("Steviegt6.Stardew64Installer", patchedByVersion, new[] { $"GitHub:{this.Settings.Stardew64InstallerGitHubProjectName}" }) }, apiVersion: Constants.ApiVersion, gameVersion: Constants.GameVersion, platform: Constants.Platform).Single().Value; + updateFound = response.SuggestedUpdate?.Version; + updateUrl = response.SuggestedUpdate?.Url ?? Constants.HomePageUrl; + + // log message + if (updateFound != null) + this.Monitor.Log($"You can update Stardew64Installer to {updateFound}: {updateUrl}", LogLevel.Alert); + else + this.Monitor.Log(" Stardew64Installer okay."); + + // show errors + if (response.Errors.Any()) + { + this.Monitor.Log("Couldn't check for a new version of Stardew64Installer. This won't affect your game, but you may not be notified of new versions if this keeps happening.", LogLevel.Warn); + this.Monitor.Log($"Error: {string.Join("\n", response.Errors)}"); + } + } + catch (Exception ex) + { + this.Monitor.Log("Couldn't check for a new version of Stardew64Installer. This won't affect your game, but you won't be notified of new versions if this keeps happening.", LogLevel.Warn); + this.Monitor.Log(ex is WebException && ex.InnerException == null + ? $"Error: {ex.Message}" + : $"Error: {ex.GetLogSummary()}" + ); + } + } + // check mod versions if (mods.Any()) { -- cgit From fa72198d1d38a77df6b92fcf936862f644a04f10 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 23 Apr 2021 22:12:41 -0400 Subject: add [64-bit] tag to window titles (#767) --- src/SMAPI/Framework/SCore.cs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 85a2bb8f..5862b112 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -263,10 +263,7 @@ namespace StardewModdingAPI.Framework }); // set window titles - this.SetWindowTitles( - game: $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion}", - smapi: $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion}" - ); + this.UpdateWindowTitles(); } catch (Exception ex) { @@ -280,10 +277,7 @@ namespace StardewModdingAPI.Framework this.LogManager.LogSettingsHeader(this.Settings); // set window titles - this.SetWindowTitles( - game: $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion}", - smapi: $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion}" - ); + this.UpdateWindowTitles(); // start game this.Monitor.Log("Starting game...", LogLevel.Debug); @@ -387,11 +381,7 @@ namespace StardewModdingAPI.Framework } // update window titles - int modsLoaded = this.ModRegistry.GetAll().Count(); - this.SetWindowTitles( - game: $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion} with {modsLoaded} mods", - smapi: $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion} with {modsLoaded} mods" - ); + this.UpdateWindowTitles(); } /// Raised after the game finishes initializing. @@ -1238,13 +1228,23 @@ namespace StardewModdingAPI.Framework return !issuesFound; } - /// Set the window titles for the game and console windows. - /// The game window text. - /// The SMAPI window text. - private void SetWindowTitles(string game, string smapi) + /// Set the titles for the game and console windows. + private void UpdateWindowTitles() { - this.Game.Window.Title = game; - this.LogManager.SetConsoleTitle(smapi); + string smapiVersion = $"{Constants.ApiVersion}{(EarlyConstants.IsWindows64BitHack ? " [64-bit]" : "")}"; + + string consoleTitle = $"SMAPI {smapiVersion} - running Stardew Valley {Constants.GameVersion}"; + string gameTitle = $"Stardew Valley {Constants.GameVersion} - running SMAPI {smapiVersion}"; + + if (this.ModRegistry.AreAllModsLoaded) + { + int modsLoaded = this.ModRegistry.GetAll().Count(); + consoleTitle += $" with {modsLoaded} mods"; + gameTitle += $" with {modsLoaded} mods"; + } + + this.Game.Window.Title = gameTitle; + this.LogManager.SetConsoleTitle(consoleTitle); } /// Asynchronously check for a new version of SMAPI and any installed mods, and print alerts to the console if an update is available. -- cgit From 99f70f963459912ce66f5a586eb4fc36e561b69d Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 1 May 2021 12:33:09 -0400 Subject: match tilesheets without extension to .png files automatically if possible --- .../Framework/ContentManagers/ModContentManager.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index 9af14cb5..0cd431e8 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -34,6 +34,9 @@ namespace StardewModdingAPI.Framework.ContentManagers /// The language code for language-agnostic mod assets. private readonly LanguageCode DefaultLanguage = Constants.DefaultLanguage; + /// If a map tilesheet's image source has no file extensions, the file extensions to check for in the local mod folder. + private readonly string[] LocalTilesheetExtensions = { ".png", ".xnb" }; + /********* ** Public methods @@ -215,11 +218,17 @@ namespace StardewModdingAPI.Framework.ContentManagers FileInfo file = new FileInfo(Path.Combine(this.FullRootDirectory, path)); // try with default extension - if (!file.Exists && file.Extension.ToLower() != ".xnb") + if (!file.Exists && file.Extension == string.Empty) { - FileInfo result = new FileInfo(file.FullName + ".xnb"); - if (result.Exists) - file = result; + foreach (string extension in this.LocalTilesheetExtensions) + { + FileInfo result = new FileInfo(file.FullName + extension); + if (result.Exists) + { + file = result; + break; + } + } } return file; -- cgit From eef6a9c2e8d124ad0856a8b351f9cae68e54f6eb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 2 May 2021 18:34:26 -0400 Subject: add support for dot-ignoring local map tilesheet files (#732) --- src/SMAPI/Framework/ContentManagers/ModContentManager.cs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index 0cd431e8..f32e3be6 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -317,6 +317,15 @@ namespace StardewModdingAPI.Framework.ContentManagers return true; } + // special case: local filenames starting with a dot should be ignored + // For example, this lets mod authors have a '.spring_town.png' file in their map folder so it can be + // opened in Tiled, while still mapping it to the vanilla 'Maps/spring_town' asset at runtime. + { + string filename = Path.GetFileName(relativePath); + if (filename.StartsWith(".")) + relativePath = Path.Combine(Path.GetDirectoryName(relativePath) ?? "", filename.TrimStart('.')); + } + // get relative to map file { string localKey = Path.Combine(modRelativeMapFolder, relativePath); -- cgit From 2cc5509e9828fd5194ca6ef7ae9ea23bd3628971 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 2 May 2021 18:35:34 -0400 Subject: add verbose logs for map tilesheet changes --- src/SMAPI/Framework/ContentManagers/ModContentManager.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index f32e3be6..4f6aa775 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -268,6 +268,7 @@ namespace StardewModdingAPI.Framework.ContentManagers string relativeMapFolder = Path.GetDirectoryName(relativeMapPath) ?? ""; // folder path containing the map, relative to the mod folder // fix tilesheets + this.Monitor.VerboseLog($"Fixing tilesheet paths for map '{relativeMapPath}' from mod '{this.ModName}'..."); foreach (TileSheet tilesheet in map.TileSheets) { // get image source @@ -289,6 +290,9 @@ namespace StardewModdingAPI.Framework.ContentManagers if (!this.TryGetTilesheetAssetName(relativeMapFolder, imageSource, out string assetName, out string error)) throw new SContentLoadException($"{errorPrefix} {error}"); + if (assetName != tilesheet.ImageSource) + this.Monitor.VerboseLog($" Mapped tilesheet '{tilesheet.ImageSource}' to '{assetName}'."); + tilesheet.ImageSource = assetName; } catch (Exception ex) when (!(ex is SContentLoadException)) -- cgit