Created
August 14, 2023 22:44
-
-
Save alextd/01ff204bd52e8cb07d8781800d54a738 to your computer and use it in GitHub Desktop.
Visual Studio Code Snippit to insert Harmony patches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<Title>Harmony Transpiler (foreach)</Title> | |
<Shortcut>htp</Shortcut> | |
<Author>AlexTD</Author> | |
<Description>Sets up a Harmony Transpiler using foreach</Description> | |
</Header> | |
<Snippet> | |
<Declarations> | |
<Literal> | |
<ID>PatchClassName</ID> | |
<ToolTip>Name For the new class where the patch lives</ToolTip> | |
<Default>NewFeature</Default> | |
</Literal> | |
<Literal> | |
<ID>Method</ID> | |
<ToolTip>Method to patch</ToolTip> | |
<Default>Method</Default> | |
</Literal> | |
<Literal> | |
<ID>Type</ID> | |
<ToolTip>Class type to patch</ToolTip> | |
<Default>Type</Default> | |
</Literal> | |
</Declarations> | |
<Code Language="CSharp"> | |
<![CDATA[[HarmonyPatch(typeof($Type$), nameof($Type$.$Method$))] | |
public static class $PatchClassName$ | |
{ | |
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) | |
{ | |
foreach(var inst in instructions) | |
{ | |
yield return inst; | |
} | |
} | |
}]]> | |
</Code> | |
</Snippet> | |
</CodeSnippet> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<Title>Harmony Prefix</Title> | |
<Shortcut>hpr</Shortcut> | |
<Author>AlexTD</Author> | |
<Description>Sets up a Harmony Prefix</Description> | |
</Header> | |
<Snippet> | |
<Declarations> | |
<Literal> | |
<ID>PatchClassName</ID> | |
<ToolTip>Name For the new class where the patch lives</ToolTip> | |
<Default>NewFeature</Default> | |
</Literal> | |
<Literal> | |
<ID>Method</ID> | |
<ToolTip>Method to patch</ToolTip> | |
<Default>Method</Default> | |
</Literal> | |
<Literal> | |
<ID>Type</ID> | |
<ToolTip>Class type to patch</ToolTip> | |
<Default>Type</Default> | |
</Literal> | |
</Declarations> | |
<Code Language="CSharp"> | |
<![CDATA[[HarmonyPatch(typeof($Type$), nameof($Type$.$Method$))] | |
public static class $PatchClassName$ | |
{ | |
public static void Prefix($Type$ __instance) | |
{ | |
} | |
}]]> | |
</Code> | |
</Snippet> | |
</CodeSnippet> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<Title>Harmony Postfix</Title> | |
<Shortcut>hpo</Shortcut> | |
<Author>AlexTD</Author> | |
<Description>Sets up a Harmony Postfix</Description> | |
</Header> | |
<Snippet> | |
<Declarations> | |
<Literal> | |
<ID>PatchClassName</ID> | |
<ToolTip>Name For the new class where the patch lives</ToolTip> | |
<Default>NewFeature</Default> | |
</Literal> | |
<Literal> | |
<ID>Method</ID> | |
<ToolTip>Method to patch</ToolTip> | |
<Default>Method</Default> | |
</Literal> | |
<Literal> | |
<ID>Type</ID> | |
<ToolTip>Class type to patch</ToolTip> | |
<Default>Type</Default> | |
</Literal> | |
</Declarations> | |
<Code Language="CSharp"> | |
<![CDATA[[HarmonyPatch(typeof($Type$), nameof($Type$.$Method$))] | |
public static class $PatchClassName$ | |
{ | |
public static void Postfix($Type$ __instance) | |
{ | |
} | |
}]]> | |
</Code> | |
</Snippet> | |
</CodeSnippet> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<Title>Harmony Passthru Postfix</Title> | |
<Shortcut>hpopt</Shortcut> | |
<Author>AlexTD</Author> | |
<Description>Sets up a Harmony Passthru-Postfix</Description> | |
</Header> | |
<Snippet> | |
<Declarations> | |
<Literal> | |
<ID>PatchClassName</ID> | |
<ToolTip>Name For the new class where the patch lives</ToolTip> | |
<Default>NewFeature</Default> | |
</Literal> | |
<Literal> | |
<ID>Method</ID> | |
<ToolTip>Method to patch</ToolTip> | |
<Default>Method</Default> | |
</Literal> | |
<Literal> | |
<ID>Type</ID> | |
<ToolTip>Class type to patch</ToolTip> | |
<Default>Type</Default> | |
</Literal> | |
<Literal> | |
<ID>ReturnType</ID> | |
<ToolTip>The return type of the method</ToolTip> | |
<Default>ReturnType</Default> | |
</Literal> | |
</Declarations> | |
<Code Language="CSharp"> | |
<![CDATA[[HarmonyPatch(typeof($Type$), nameof($Type$.$Method$))] | |
public static class $PatchClassName$ | |
{ | |
public static $ReturnType$ Postfix($ReturnType$ result) | |
{ | |
return result; | |
} | |
}]]> | |
</Code> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this as a Visual Studio code snippit (https://learn.microsoft.com/en-us/visualstudio/ide/code-snippets?view=vs-2022)
Now you can type
htp
and tab-tab to get a Harmony-annotated transpiler. Start typing to name the type you're patching, tab and type for the method, tab and type to name the class you just made.also
hpr
andhpo
for prefix/postfix, andhpopt
for a passthru postfix.