fix: Harmony finalizers return void, so errors from other mods keep their stack trace
An Exception-returning finalizer makes Harmony throw the exception again instead of rethrowing it, which cuts the stack trace at the patched method. All ten finalizers only passed the exception on, so they now return void. A smoke test fails if a finalizer returns a value again. Version 1.2.2.
This commit is contained in:
parent
ef7d7f86b0
commit
ccaf4ac01b
Binary file not shown.
Binary file not shown.
|
|
@ -3,7 +3,7 @@
|
|||
<name>Blax Slaves</name>
|
||||
<author>Blax Gaming</author>
|
||||
<packageId>blax.slaves</packageId>
|
||||
<modVersion>1.2.1</modVersion>
|
||||
<modVersion>1.2.2</modVersion>
|
||||
<supportedVersions>
|
||||
<li>1.7</li>
|
||||
</supportedVersions>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## 1.2.2
|
||||
|
||||
- Errors from other mods or the game in the hooked methods now keep their full stack trace, so they no longer look like Blax Slaves errors.
|
||||
|
||||
## 1.2.1
|
||||
|
||||
- Works with any DLC combination, core only included. Without Ideology the slave features stay off and their settings show greyed out with a "needs Ideology" note; every trader still buys your prisoners, and the slaver changes still apply.
|
||||
|
|
|
|||
|
|
@ -129,10 +129,9 @@ namespace BlaxSlaves
|
|||
{
|
||||
public static void Prefix(Pawn victim, out SlaveHarm.Frame __state) => __state = SlaveHarm.Push(victim);
|
||||
|
||||
public static Exception Finalizer(Exception __exception, SlaveHarm.Frame __state)
|
||||
public static void Finalizer(SlaveHarm.Frame __state)
|
||||
{
|
||||
SlaveHarm.Pop(__state);
|
||||
return __exception;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -141,10 +140,9 @@ namespace BlaxSlaves
|
|||
{
|
||||
public static void Prefix(Pawn victim, out SlaveHarm.Frame __state) => __state = SlaveHarm.Push(victim);
|
||||
|
||||
public static Exception Finalizer(Exception __exception, SlaveHarm.Frame __state)
|
||||
public static void Finalizer(SlaveHarm.Frame __state)
|
||||
{
|
||||
SlaveHarm.Pop(__state);
|
||||
return __exception;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -161,10 +159,9 @@ namespace BlaxSlaves
|
|||
__state.protectedVictim = false;
|
||||
}
|
||||
|
||||
public static Exception Finalizer(Exception __exception, SlaveHarm.Frame __state)
|
||||
public static void Finalizer(SlaveHarm.Frame __state)
|
||||
{
|
||||
SlaveHarm.Pop(__state);
|
||||
return __exception;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -179,10 +176,9 @@ namespace BlaxSlaves
|
|||
__state.protectedVictim = false;
|
||||
}
|
||||
|
||||
public static Exception Finalizer(Exception __exception, SlaveHarm.Frame __state)
|
||||
public static void Finalizer(SlaveHarm.Frame __state)
|
||||
{
|
||||
SlaveHarm.Pop(__state);
|
||||
return __exception;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -192,10 +188,9 @@ namespace BlaxSlaves
|
|||
{
|
||||
public static void Prefix(Pawn patient, out SlaveHarm.Frame __state) => __state = SlaveHarm.Push(patient);
|
||||
|
||||
public static Exception Finalizer(Exception __exception, SlaveHarm.Frame __state)
|
||||
public static void Finalizer(SlaveHarm.Frame __state)
|
||||
{
|
||||
SlaveHarm.Pop(__state);
|
||||
return __exception;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -218,10 +213,9 @@ namespace BlaxSlaves
|
|||
}
|
||||
}
|
||||
|
||||
public static Exception Finalizer(Exception __exception, SlaveHarm.Frame __state)
|
||||
public static void Finalizer(SlaveHarm.Frame __state)
|
||||
{
|
||||
SlaveHarm.Pop(__state);
|
||||
return __exception;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -256,10 +250,9 @@ namespace BlaxSlaves
|
|||
soldInGift = queue;
|
||||
}
|
||||
|
||||
public static Exception Finalizer(Exception __exception, Queue<Pawn> __state)
|
||||
public static void Finalizer(Queue<Pawn> __state)
|
||||
{
|
||||
soldInGift = __state;
|
||||
return __exception;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -302,10 +295,9 @@ namespace BlaxSlaves
|
|||
}
|
||||
}
|
||||
|
||||
public static Exception Finalizer(Exception __exception, SlaveHarm.Frame __state)
|
||||
public static void Finalizer(SlaveHarm.Frame __state)
|
||||
{
|
||||
SlaveHarm.Pop(__state);
|
||||
return __exception;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -343,10 +335,9 @@ namespace BlaxSlaves
|
|||
|
||||
public static void Prefix() => depth++;
|
||||
|
||||
public static Exception Finalizer(Exception __exception)
|
||||
public static void Finalizer()
|
||||
{
|
||||
depth--;
|
||||
return __exception;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -431,10 +422,9 @@ namespace BlaxSlaves
|
|||
}
|
||||
}
|
||||
|
||||
public static Exception FrameFinalizer(Exception __exception, SlaveHarm.Frame __state)
|
||||
public static void FrameFinalizer(SlaveHarm.Frame __state)
|
||||
{
|
||||
SlaveHarm.Pop(__state);
|
||||
return __exception;
|
||||
}
|
||||
|
||||
public static void NotPendingPostfix(Pawn pawn, ref bool __result)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,22 @@ namespace BlaxSlavesTests
|
|||
T.Check(warnings.Count == 0, "warnings mentioning Blax Slaves at startup: " + string.Join(" | ", warnings.Take(3).Select(e => e.text)));
|
||||
}
|
||||
|
||||
[BlaxTest("startup: every Blax Slaves finalizer returns void, so Harmony rethrows exceptions with their stack trace")]
|
||||
public static void FinalizersReturnVoid()
|
||||
{
|
||||
// One finalizer returning Exception on a method makes Harmony "throw ex" instead of "rethrow"
|
||||
// (0Harmony EmitFinalizers), which cuts the inner frames off every exception passing through it.
|
||||
var finalizers = Harmony.GetAllPatchedMethods()
|
||||
.Select(Harmony.GetPatchInfo)
|
||||
.Where(info => info != null)
|
||||
.SelectMany(info => info.Finalizers)
|
||||
.Where(p => p.owner == "blax.slaves")
|
||||
.ToList();
|
||||
T.Check(finalizers.Count >= 9, "Blax Slaves finalizers found: " + finalizers.Count + ", expected at least 9");
|
||||
var bad = finalizers.Where(p => p.PatchMethod.ReturnType != typeof(void)).Select(p => p.PatchMethod.DeclaringType?.Name + "." + p.PatchMethod.Name).ToList();
|
||||
T.Check(bad.Count == 0, "finalizers that return a value: " + string.Join(", ", bad));
|
||||
}
|
||||
|
||||
[BlaxTest("startup: settings and defs loaded")]
|
||||
public static void DefsLoaded()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue