Skip to content

Commit

Permalink
Update documentation [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike-bot committed Oct 16, 2022
1 parent d0da150 commit 40e4820
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions docs/articles/patching.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ <h2 id="patch-methods">Patch methods</h2>
</code></pre>
<p>If you prefer manual patching, you can use any method name or class structure you want. You are responsible to retrieve the MethodInfo for the different patch methods and supply them to the Patch() method by wrapping them into HarmonyMethod objects.</p>
<p><img src="https://raw.githubusercontent.com/pardeike/Harmony/master/Harmony/Documentation/images/note.png" alt="note"> Patch methods <em>must</em> be static but you can define them public or private. They cannot be dynamic methods but you can write static patch factory methods that return dynamic methods.</p>
<pre><code class="lang-csharp">[HarmonyPatch(...)]
class Patch
{
// the return type of factory methods can be either MethodInfo or DynamicMethod
[HarmonyPrefix]
static MethodInfo PrefixFactory(MethodBase originalMethod)
{
// return an instance of MethodInfo or an instance of DynamicMethod
}

[HarmonyPostfix]
static MethodInfo PostfixFactory(MethodBase originalMethod)
{
// return an instance of MethodInfo or an instance of DynamicMethod
}
}
</code></pre>
<h3 id="method-names">Method names</h3>
<p>Manual patching knows four main patch types: <strong>Prefix</strong>, <strong>Postfix</strong>, <strong>Transpiler</strong> and <strong>Finalizer</strong>. If you use attributes for patching, you can also use the helper methods: <strong>Prepare</strong>, <strong>TargetMethod</strong>, <strong>TargetMethods</strong> and <strong>Cleanup</strong> as explained below.</p>
<p>Each of those names has a corresponding attribute starting with [Harmony...]. So instead of calling one of your methods &quot;Prepare&quot;, you can call it anything and decorate it with a <code>[HarmonyPrepare]</code> attribute.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@
"output": {
".html": {
"relative_path": "articles/patching.html",
"hash": "SAcl10jykAsOVeSWY0HkZs0HlEj1rTHwjUMqMMs7Xmo="
"hash": "xOiUvxGqlPzsfhYfgYXJIxbIOnl4wFIX+NCc27TjSBk="
}
},
"is_incremental": false,
Expand Down

0 comments on commit 40e4820

Please sign in to comment.