fix RewriteMods option ignored when rewriting mod for OS

This commit is contained in:
Jesse Plamondon-Willard 2021-03-04 21:59:49 -05:00
parent 699a07ecf7
commit 5a2258f419
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 31 additions and 27 deletions

View File

@ -13,6 +13,7 @@
* For mod authors: * 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). * 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. * 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 ## 3.9.2

View File

@ -276,37 +276,40 @@ namespace StardewModdingAPI.Framework.ModLoading
// swap assembly references if needed (e.g. XNA => MonoGame) // swap assembly references if needed (e.g. XNA => MonoGame)
bool platformChanged = false; bool platformChanged = false;
for (int i = 0; i < module.AssemblyReferences.Count; i++) if (this.RewriteMods)
{ {
// remove old assembly reference for (int i = 0; i < module.AssemblyReferences.Count; i++)
if (this.AssemblyMap.RemoveNames.Any(name => module.AssemblyReferences[i].Name == name))
{ {
this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Rewriting {filename} for OS..."); // remove old assembly reference
platformChanged = true; if (this.AssemblyMap.RemoveNames.Any(name => module.AssemblyReferences[i].Name == name))
module.AssemblyReferences.RemoveAt(i);
i--;
}
}
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 types using custom attributes
foreach (TypeDefinition type in module.GetTypes())
{
foreach (var attr in type.CustomAttributes)
{ {
foreach (var conField in attr.ConstructorArguments) 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);
// 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)
{ {
if (conField.Value is TypeReference typeRef) foreach (var conField in attr.ConstructorArguments)
this.ChangeTypeScope(typeRef); {
if (conField.Value is TypeReference typeRef)
this.ChangeTypeScope(typeRef);
}
} }
} }
} }