Refactor hooking API

This completely changes how method patching works under the hood. Unlike
the previous API (`Hook.HookMethod`), the new API (`Hook.Patch`)
generates a Harmony patch method at runtime, using IL generation.

This fixes methods with ByRef (out/ref) parameters getting silently corrupted
due to the ByRef semantics being lost when passed through the `object[] __args`
parameter.

This new API also makes it possible to:
  - modify parameters (including ByRef params)
  - change the return value to `null` (old API would use `return nil`
    for Harmony control flow)
  - prevent execution of the original method (and other harmony
    patches), independently of modifying the return value
This commit is contained in:
peelz
2022-08-03 21:34:41 -04:00
parent 768abd5ce1
commit 08836088fb
10 changed files with 1223 additions and 482 deletions
+2 -1
View File
@@ -134,6 +134,7 @@
<PackageReference Include="MonoMod.Common" Version="22.5.1.1" />
<PackageReference Include="NVorbis" Version="0.8.6" />
<PackageReference Include="RestSharp" Version="106.13.0" />
<PackageReference Include="Sigil" Version="5.0.0" />
</ItemGroup>
<!-- Sourced from https://stackoverflow.com/a/45248069 -->
@@ -224,4 +225,4 @@
</PropertyGroup>
<Import Project="../BarotraumaShared/DeployGameAnalytics.props" />
</Project>
</Project>