-
Notifications
You must be signed in to change notification settings - Fork 0
Table Builders
BlazingTwist edited this page Jan 17, 2023
·
1 revision
Use this to create tables for logging.
TextTableBuilder tableBuilder = new TextTableBuilder();
tableBuilder.Row("Column1", "Column2", "Column3");
tableBuilder.ThinRowSeparator();
tableBuilder.Row("A", "B", "C");
tableBuilder.Row("1", "2", "3");
tableBuilder.EndTable();
Console.WriteLine(tableBuilder.BuildTable(" "));
Results in
| Column1 | Column2 | Column3 |
|----------+----------+----------|
| A | B | C |
| 1 | 2 | 3 |
\================================/
Useful for logging instructions.
private static class TargetClass {
private static void TargetMethod() {
Console.WriteLine("msg0");
if (Condition1()) {
Console.WriteLine("msg1");
} else {
Console.WriteLine("msg2");
}
Console.WriteLine("msg3");
}
}
public static class PatcherClass {
[HarmonyTranspiler, HarmonyPatch(declaringType: typeof(TargetClass), methodName: "TargetMethod")]
private static IEnumerable<CodeInstruction> ExampleTranspiler(IEnumerable<CodeInstruction> codeInstructions) {
IEnumerable<CodeInstruction> instructions = codeInstructions.ToList();
Console.WriteLine(InstructionTableBuilder.BuildTable(instructions));
return instructions;
}
}
Results in
| Labels | OpCode | Operand |
|---------+----------+--------------------------------|
| | ldstr | msg0 |
| | call | Void WriteLine(System.String) |
| | call | Boolean Condition1() |
| | brfalse | 1 |
| | ldstr | msg1 |
| | call | Void WriteLine(System.String) |
| | br | 2 |
| 1 | ldstr | msg2 |
| | call | Void WriteLine(System.String) |
| 2 | ldstr | msg3 |
| | call | Void WriteLine(System.String) |
| | ret | null |
\=====================================================/
Made with ❤️ by BlazingTwist
If you like my work and wish to support me, a
goes a long way