pardeike / Harmony

A library for patching, replacing and decorating .NET and Mono methods during runtime
https://www.patreon.com/pardeike
MIT License
5.15k stars 485 forks source link

Postfix with "bool __result" parameter causes NullRefException (master 2.0.0) #168

Closed boformer closed 5 years ago

boformer commented 5 years ago

Describe the bug New problem with the master version that I didn't have in 1.2:

static void Postfix(ref ushort segment, NetInfo info, bool __result) {
…

throws an error in Harmony

A quick fix is changing bool __result to ref bool __result

Then the patching works!

To Reproduce

Original method:

class NetManager {
    public bool CreateSegment(out ushort segment, ref Randomizer randomizer, NetInfo info, ushort startNode, ushort endNode, Vector3 startDirection, Vector3 endDirection, uint buildIndex, uint modifiedIndex, bool invert)
    { … }
}

The patch:

[HarmonyPatch(typeof(NetManager), "CreateSegment")]
public class NetManagerCreateSegmentPatch
{
    static void Postfix(ref ushort segment, NetInfo info, ref bool __result)
    {
    }
}

Harmony log and Unity log: https://gist.github.com/boformer/a5eb8b87cc621b03939351d6ad3eb353

Expected behavior It should not throw exceptions!

Runtime environment (please complete the following information):

boformer commented 5 years ago

Fixed in latest master