From 403616b07c6da6479ce77fd45b41f622e9972915 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 28 Feb 2021 12:39:37 -0500 Subject: fix mods with suppressed warnings counted for showing the log section --- src/SMAPI/Framework/ModLoading/ModMetadata.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/src/SMAPI/Framework/ModLoading/ModMetadata.cs b/src/SMAPI/Framework/ModLoading/ModMetadata.cs index 18d2b112..b4de3d6c 100644 --- a/src/SMAPI/Framework/ModLoading/ModMetadata.cs +++ b/src/SMAPI/Framework/ModLoading/ModMetadata.cs @@ -13,6 +13,13 @@ namespace StardewModdingAPI.Framework.ModLoading /// Metadata for a mod. internal class ModMetadata : IModMetadata { + /********* + ** Fields + *********/ + /// The non-error issues with the mod, including warnings suppressed by the data record. + private ModWarning ActualWarnings = ModWarning.None; + + /********* ** Accessors *********/ @@ -41,7 +48,7 @@ namespace StardewModdingAPI.Framework.ModLoading public ModFailReason? FailReason { get; private set; } /// - public ModWarning Warnings { get; private set; } + public ModWarning Warnings => this.ActualWarnings & ~(this.DataRecord?.DataRecord.SuppressWarnings ?? ModWarning.None); /// public string Error { get; private set; } @@ -116,7 +123,7 @@ namespace StardewModdingAPI.Framework.ModLoading /// public IModMetadata SetWarning(ModWarning warning) { - this.Warnings |= warning; + this.ActualWarnings |= warning; return this; } @@ -218,12 +225,10 @@ namespace StardewModdingAPI.Framework.ModLoading } /// - public bool HasUnsuppressedWarnings(params ModWarning[] warnings) + public bool HasWarnings(params ModWarning[] warnings) { - return warnings.Any(warning => - this.Warnings.HasFlag(warning) - && (this.DataRecord?.DataRecord == null || !this.DataRecord.DataRecord.SuppressWarnings.HasFlag(warning)) - ); + ModWarning curWarnings = this.Warnings; + return warnings.Any(warning => curWarnings.HasFlag(warning)); } /// -- cgit From 5a2258f4194986df3dea7dca9b17cdc96b3e63d5 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 4 Mar 2021 21:59:49 -0500 Subject: fix RewriteMods option ignored when rewriting mod for OS --- docs/release-notes.md | 1 + src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 51 +++++++++++++----------- 2 files changed, 28 insertions(+), 24 deletions(-) (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/docs/release-notes.md b/docs/release-notes.md index 6f69479e..7a4a0409 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -13,6 +13,7 @@ * For mod authors: * Added three stages to the `LoadStageChanged` event: `CreatedInitialLocations`/`SaveAddedLocations` (raised immediately after the game adds locations but before they're initialized), and `ReturningToTitle` (raised before exiting to the title screen). + * Fixed `RewriteMods` option in `smapi-internal/config.json` ignored when rewriting mod for OS compatibility. * Fixed edge case when playing as a farmhand in non-English where translatable assets loaded via `IAssetLoader` weren't reapplied immediately when the server disconnects. ## 3.9.2 diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index 4fae0f44..69535aa5 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -276,37 +276,40 @@ namespace StardewModdingAPI.Framework.ModLoading // swap assembly references if needed (e.g. XNA => MonoGame) bool platformChanged = false; - for (int i = 0; i < module.AssemblyReferences.Count; i++) + if (this.RewriteMods) { - // remove old assembly reference - if (this.AssemblyMap.RemoveNames.Any(name => module.AssemblyReferences[i].Name == name)) + for (int i = 0; i < module.AssemblyReferences.Count; i++) { - this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Rewriting {filename} for OS..."); - platformChanged = true; - module.AssemblyReferences.RemoveAt(i); - i--; + // remove old assembly reference + if (this.AssemblyMap.RemoveNames.Any(name => module.AssemblyReferences[i].Name == name)) + { + this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Rewriting {filename} for OS..."); + platformChanged = true; + module.AssemblyReferences.RemoveAt(i); + i--; + } } - } - if (platformChanged) - { - // add target assembly references - foreach (AssemblyNameReference target in this.AssemblyMap.TargetReferences.Values) - module.AssemblyReferences.Add(target); + if (platformChanged) + { + // add target assembly references + foreach (AssemblyNameReference target in this.AssemblyMap.TargetReferences.Values) + module.AssemblyReferences.Add(target); - // rewrite type scopes to use target assemblies - IEnumerable typeReferences = module.GetTypeReferences().OrderBy(p => p.FullName); - foreach (TypeReference type in typeReferences) - this.ChangeTypeScope(type); + // rewrite type scopes to use target assemblies + IEnumerable typeReferences = module.GetTypeReferences().OrderBy(p => p.FullName); + foreach (TypeReference type in typeReferences) + this.ChangeTypeScope(type); - // rewrite types using custom attributes - foreach (TypeDefinition type in module.GetTypes()) - { - foreach (var attr in type.CustomAttributes) + // rewrite types using custom attributes + foreach (TypeDefinition type in module.GetTypes()) { - foreach (var conField in attr.ConstructorArguments) + foreach (var attr in type.CustomAttributes) { - if (conField.Value is TypeReference typeRef) - this.ChangeTypeScope(typeRef); + foreach (var conField in attr.ConstructorArguments) + { + if (conField.Value is TypeReference typeRef) + this.ChangeTypeScope(typeRef); + } } } } -- cgit