summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModLoading
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-03-07 20:15:10 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-03-07 20:15:10 -0500
commit5399239c2be01396958ed454d6ae56f006d20ca5 (patch)
tree87683eda0873a0c24d9bcee5d47f1cec896f21bb /src/SMAPI/Framework/ModLoading
parentdb011ee751bdfb8bbd9abbeb706966db4c4e2461 (diff)
parenta571f459f59a6ecfdd53e3158ba8d29157598920 (diff)
downloadSMAPI-5399239c2be01396958ed454d6ae56f006d20ca5.tar.gz
SMAPI-5399239c2be01396958ed454d6ae56f006d20ca5.tar.bz2
SMAPI-5399239c2be01396958ed454d6ae56f006d20ca5.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/ModLoading')
-rw-r--r--src/SMAPI/Framework/ModLoading/AssemblyLoader.cs51
-rw-r--r--src/SMAPI/Framework/ModLoading/ModMetadata.cs19
2 files changed, 39 insertions, 31 deletions
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<TypeReference> typeReferences = module.GetTypeReferences().OrderBy(p => p.FullName);
- foreach (TypeReference type in typeReferences)
- this.ChangeTypeScope(type);
+ // rewrite type scopes to use target assemblies
+ IEnumerable<TypeReference> 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);
+ }
}
}
}
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
@@ -14,6 +14,13 @@ namespace StardewModdingAPI.Framework.ModLoading
internal class ModMetadata : IModMetadata
{
/*********
+ ** Fields
+ *********/
+ /// <summary>The non-error issues with the mod, including warnings suppressed by the data record.</summary>
+ private ModWarning ActualWarnings = ModWarning.None;
+
+
+ /*********
** Accessors
*********/
/// <inheritdoc />
@@ -41,7 +48,7 @@ namespace StardewModdingAPI.Framework.ModLoading
public ModFailReason? FailReason { get; private set; }
/// <inheritdoc />
- public ModWarning Warnings { get; private set; }
+ public ModWarning Warnings => this.ActualWarnings & ~(this.DataRecord?.DataRecord.SuppressWarnings ?? ModWarning.None);
/// <inheritdoc />
public string Error { get; private set; }
@@ -116,7 +123,7 @@ namespace StardewModdingAPI.Framework.ModLoading
/// <inheritdoc />
public IModMetadata SetWarning(ModWarning warning)
{
- this.Warnings |= warning;
+ this.ActualWarnings |= warning;
return this;
}
@@ -218,12 +225,10 @@ namespace StardewModdingAPI.Framework.ModLoading
}
/// <inheritdoc />
- 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));
}
/// <inheritdoc />