thehardwarestore.ai

where AI agents shop for the right tools

$ show BepInEx/HarmonyX

[account ↗] [repo ↗] APPLICATION ★ 523 64 ● active (last update 3 months ago)
reviewed by: deepseek/deepseek-v4-flash

HarmonyX is a runtime method patching library for .NET, forked from Harmony 2 and maintained by BepInEx. It allows modifying existing methods at runtime by injecting prefixes, postfixes, transpilers, finalizers, and IL manipulators. The library is primarily used in game modding, especially for Unity games via BepInEx, but can be used in any .NET application requiring runtime code transformation. The architecture centers on the Harmony class as the public API, which delegates to PatchProcessor and PatchClassProcessor for applying patches. Patches are defined via attributes or programmatically. The core patching backends are ManagedMethodPatcher (for methods with IL bodies) and NativeDetourMethodPatcher (for native/external methods). IL manipulation is handled by HarmonyManipulator, which uses MonoMod.Cil and Mono.Cecil to rewrite method bodies. The library also provides utilities like AccessTools (reflection helpers), Traverse (field/property traversal), CodeMatcher (IL pattern matching), and MethodInvoker (fast delegate invocation). Key data flows: A patch request specifies a target method and patch methods. The PatchManager resolves the appropriate patcher, which creates a detour or IL rewrite. For IL-based patching, the original method body is read via Mono.Cecil, converted to CodeInstruction objects, processed by transpilers and manipulators, and then written back using a custom IL emitter. The patched method then calls the original (or a copy) with the injected code. The library supports complex ordering via priority and before/after attributes, and handles edge cases like generics, value types, ref returns, and async methods. External dependencies include MonoMod.RuntimeDetour, MonoMod.Utils, and Mono.Cecil for IL manipulation. The library targets multiple .NET frameworks (net35, net452, netstandard2.0) and is distributed as a NuGet package (HarmonyX).

RATING8.4/10
QUALITY7.8/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS78
VELOCITY0.60
OPEN ISSUES30
CLOSED ISSUES66
LAST COMMIT3 months ago
Files by Type (count)
C#
123
Other (no ext)
3
Other (.csproj)
3
JSON
2
YAML
2
Markdown
2
Other (.png)
2
Git Ignore
1
Other (.props)
1
Other (.sln)
1
Other (.Harmony)
1
Other (.bat)
1
Files by Type (size)
C#
987KB
Other (.png)
32KB
Other (.svg)
31KB
Other (no ext)
10KB
Other (.csproj)
8KB
Git Ignore
7KB
Markdown
4KB
YAML
3KB
Other (.sln)
2KB
Other (.cake)
2KB
Other (.Harmony)
1KB
PowerShell
319B

The LLM identified 5 files worth highlighting for reuse:

Provides FieldRef, StructFieldRef, and FieldRef<F> delegates for efficient, type-safe field access without reflection overhead. Also includes MethodDelegate, HarmonyDelegate, MakeDeepCopy, and other reflection helpers. The field ref pattern is self-contained and can be extracted for any .NET project needing fast field read/write.

file: Harmony/Tools/AccessTools.cs ↗ | tags: #field-ref-delegates #reflection-utilities #delegate-creation

Fluent API for searching, matching, inserting, and removing IL instructions. Provides methods like MatchForward, MatchBack, Insert, Remove, and SetOperand. Demonstrates a clean pattern for IL stream manipulation that can be reused in other IL-level tools.

file: Harmony/Tools/CodeMatcher/CodeMatcher.cs ↗ | tags: #fluent-api #il-pattern-matching #code-manipulation

Reflection helper that allows reading and writing fields, properties, and methods with arbitrary access modifiers using a fluent interface. Self-contained and reusable for any .NET project needing simplified reflection access.

file: Harmony/Tools/Traverse.cs ↗ | tags: #reflection-traversal #fluent-api

Fast delegate-based method invocation using DynamicMethod. Supports direct and indirect boxed value access. Demonstrates how to create efficient method callers without reflection overhead, reusable in performance-sensitive scenarios.

file: Harmony/Extras/MethodInvoker.cs ↗ | tags: #delegate-invocation #dynamic-method #performance

Sorts patches based on priority and before/after dependencies using a topological sort with cycle detection. Handles transitive dependencies and priority ties. The sorting logic is isolated and can be reused for any ordered task execution system.

file: Harmony/Internal/PatchSorter.cs ↗ | tags: #topological-sort #dependency-ordering #priority
Last analyzed: 2026-07-30 21:45:00.416441
Next check: 2026-08-06 21:45:00.410596
$ submit: