https://github.com/nbkredspy/transpileutilities
A Harmony Transpiler helper that can create the complement of a local Load or Store OpCode. Useful for supporting multiple versions of code which vary the local load/store operations.
https://github.com/nbkredspy/transpileutilities
harmony transpiler utility
Last synced: about 1 year ago
JSON representation
A Harmony Transpiler helper that can create the complement of a local Load or Store OpCode. Useful for supporting multiple versions of code which vary the local load/store operations.
- Host: GitHub
- URL: https://github.com/nbkredspy/transpileutilities
- Owner: NBKRedSpy
- License: mit
- Created: 2023-03-22T20:16:01.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-23T21:30:36.000Z (over 3 years ago)
- Last Synced: 2025-06-29T19:18:05.606Z (about 1 year ago)
- Topics: harmony, transpiler, utility
- Language: C#
- Homepage:
- Size: 33.2 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Description
A Harmony transpiler helper class that can take a local variable load or store operation and create the complement.
Useful when different versions of the target code may change operations. For example, stloc_3 to stloc_s.
# Examples
## Code Matcher Example:
```csharp
StackVariableInstruction fooVariable = null; //The local variable
return codeMatcher
.MatchForward(true,
...
//The first parameter determines if a load or store operation is required for a successful CodeMatch.
new CodeMatch(instruction => StackVariableInstruction.Create(expectStore: true, instruction, out fooVariable))
...
)
.ThrowIfNotMatch("Did not find load section")
.Insert(
//Inserts a load operation
fooVariable.Load,
//Some function call
CodeInstruction.Call(typeof(Foo), nameof(Foo.Bar)),
//Inserts a store operation
fooVariable.Store
)
.InstructionEnumeration();
```
## Using Directly:
```csharp
var instruction = new StackVariableInstruction(new CodeInstruction(OpCodes.Stloc_2));
instruction.Load; //Return the load version
instruction.Store; //Return the store version
```
# Using the Code
Copy the StackVariableInstruction.cs file from [releases](https://github.com/NBKRedSpy/TranspileUtilities/releases) into the target project.
# StackVariableInstruction.Create
A utility function to create a stack variable while using a code matcher.
|Parameter|Description|
|--|--|
|isStore|If true, will expect the codeInstruction to be a store opcode. Otherwise a load opcode.|
|codeInstruction|The instruction source.|
|stackVariable|The newly created stack variable. Will be null if no match.|
|returns|True if the opcode matched the isStore expectations.|
# Project Folders
|Project|Description|
|--|--|
|src/TranspileUtilities|Creates the /StackVariableInstruction.cs file|
|src/TranspileUtilitiesTest|The tests for the TranspileUtilities project|
|src/ILTest|Creates a DLL with the various load/store operations for testing purposes. Not used in this project|