Merge branch 'develop' into harmony2
This commit is contained in:
commit
409e2f7c47
|
@ -6,6 +6,7 @@
|
||||||
* Mod warnings are now listed alphabetically.
|
* Mod warnings are now listed alphabetically.
|
||||||
* MacOS files starting with `._` are now ignored and can no longer cause skipped mods.
|
* MacOS files starting with `._` are now ignored and can no longer cause skipped mods.
|
||||||
* Simplified paranoid warning logs and reduced their log level.
|
* Simplified paranoid warning logs and reduced their log level.
|
||||||
|
* Reduced startup time when loading mod DLLs (thanks to ZaneYork!).
|
||||||
* Fixed `BadImageFormatException` error detection.
|
* Fixed `BadImageFormatException` error detection.
|
||||||
* Fixed black maps on Android for mods which use `.tmx` files.
|
* Fixed black maps on Android for mods which use `.tmx` files.
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@
|
||||||
* Improved mod rewriting for compatibility:
|
* Improved mod rewriting for compatibility:
|
||||||
* Fixed rewriting types in custom attributes.
|
* Fixed rewriting types in custom attributes.
|
||||||
* Fixed rewriting generic types to method references.
|
* Fixed rewriting generic types to method references.
|
||||||
|
* Fixed `helper.Reflection` blocking access to game methods/properties that were extended by SMAPI.
|
||||||
* Fixed asset propagation for Gil's portraits.
|
* Fixed asset propagation for Gil's portraits.
|
||||||
* Fixed `.pdb` files ignored for error stack traces for mods rewritten by SMAPI.
|
* Fixed `.pdb` files ignored for error stack traces for mods rewritten by SMAPI.
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,8 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
||||||
/// <returns>Returns the same property instance for convenience.</returns>
|
/// <returns>Returns the same property instance for convenience.</returns>
|
||||||
private IReflectedProperty<T> AssertAccessAllowed<T>(IReflectedProperty<T> property)
|
private IReflectedProperty<T> AssertAccessAllowed<T>(IReflectedProperty<T> property)
|
||||||
{
|
{
|
||||||
this.AssertAccessAllowed(property?.PropertyInfo);
|
this.AssertAccessAllowed(property?.PropertyInfo.GetMethod?.GetBaseDefinition());
|
||||||
|
this.AssertAccessAllowed(property?.PropertyInfo.SetMethod?.GetBaseDefinition());
|
||||||
return property;
|
return property;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
||||||
/// <returns>Returns the same method instance for convenience.</returns>
|
/// <returns>Returns the same method instance for convenience.</returns>
|
||||||
private IReflectedMethod AssertAccessAllowed(IReflectedMethod method)
|
private IReflectedMethod AssertAccessAllowed(IReflectedMethod method)
|
||||||
{
|
{
|
||||||
this.AssertAccessAllowed(method?.MethodInfo);
|
this.AssertAccessAllowed(method?.MethodInfo.GetBaseDefinition());
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using Mono.Cecil;
|
using Mono.Cecil;
|
||||||
using Mono.Cecil.Cil;
|
using Mono.Cecil.Cil;
|
||||||
using Mono.Collections.Generic;
|
using Mono.Collections.Generic;
|
||||||
|
@ -57,16 +58,22 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework
|
||||||
/// <returns>Returns whether the module was modified.</returns>
|
/// <returns>Returns whether the module was modified.</returns>
|
||||||
public bool RewriteModule()
|
public bool RewriteModule()
|
||||||
{
|
{
|
||||||
Tuple<bool,Exception> aggregateResult = this.Module.GetTypes()
|
// rewrite each type in the assembly, tracking whether any type was rewritten (Item1)
|
||||||
.AsParallel().WithExecutionMode(ParallelExecutionMode.ForceParallelism)
|
// and any exception that occurred during rewriting (Item2).
|
||||||
|
var cancellationToken = new CancellationTokenSource();
|
||||||
|
Tuple<bool, Exception> result = this.Module
|
||||||
|
.GetTypes()
|
||||||
|
.Where(type => type.BaseType != null) // skip special types like <Module>
|
||||||
|
.AsParallel()
|
||||||
|
.WithExecutionMode(ParallelExecutionMode.ForceParallelism)
|
||||||
.Select(type =>
|
.Select(type =>
|
||||||
{
|
{
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
return Tuple.Create(false, null as Exception);
|
||||||
|
|
||||||
|
bool anyRewritten = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bool anyRewritten = false;
|
|
||||||
if (type.BaseType == null)
|
|
||||||
return new Tuple<bool, Exception>(anyRewritten, null); // special type like <Module>
|
|
||||||
|
|
||||||
anyRewritten |= this.RewriteCustomAttributes(type.CustomAttributes);
|
anyRewritten |= this.RewriteCustomAttributes(type.CustomAttributes);
|
||||||
anyRewritten |= this.RewriteGenericParameters(type.GenericParameters);
|
anyRewritten |= this.RewriteGenericParameters(type.GenericParameters);
|
||||||
|
|
||||||
|
@ -112,19 +119,21 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Tuple<bool, Exception>(anyRewritten, null);
|
return Tuple.Create(anyRewritten, null as Exception);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return new Tuple<bool, Exception>(false, e.InnerException ?? e);
|
cancellationToken.Cancel();
|
||||||
|
return Tuple.Create(anyRewritten, e);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.Aggregate((tupleA, tupleB) => new Tuple<bool, Exception>(tupleA.Item1 | tupleB.Item1, tupleA.Item2 ?? tupleB.Item2)); // Aggregate result and exception
|
.Aggregate((a, b) => Tuple.Create(a.Item1 || b.Item1, a.Item2 ?? b.Item2));
|
||||||
if (aggregateResult.Item2 != null)
|
|
||||||
{
|
bool rewritten = result.Item1;
|
||||||
throw aggregateResult.Item2; // rethrow inner Exception
|
Exception exception = result.Item2;
|
||||||
}
|
return exception == null
|
||||||
return aggregateResult.Item1;
|
? rewritten
|
||||||
|
: throw exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue