From 2461876719872b2d50bf933426cb3ceb28513feb Mon Sep 17 00:00:00 2001
From: Eve <85962933+obvEve@users.noreply.github.com>
Date: Tue, 5 May 2026 20:58:21 +0200
Subject: [PATCH] CodeMatcherExtensions.cs
---
SecretAPI/Extensions/CodeMatcherExtensions.cs | 75 +++++++++++++++++++
SecretAPI/SecretAPI.csproj | 2 +-
2 files changed, 76 insertions(+), 1 deletion(-)
create mode 100644 SecretAPI/Extensions/CodeMatcherExtensions.cs
diff --git a/SecretAPI/Extensions/CodeMatcherExtensions.cs b/SecretAPI/Extensions/CodeMatcherExtensions.cs
new file mode 100644
index 0000000..12c726b
--- /dev/null
+++ b/SecretAPI/Extensions/CodeMatcherExtensions.cs
@@ -0,0 +1,75 @@
+namespace SecretAPI.Extensions;
+
+using System;
+using System.Linq;
+using System.Reflection.Emit;
+using HarmonyLib;
+
+///
+/// Extensions related to .
+///
+public static class CodeMatcherExtensions
+{
+ extension(CodeMatcher matcher)
+ {
+ ///
+ /// Sets to the end and then backtracks X amount.
+ ///
+ /// The amount to reverse. Must be positive number.
+ /// The current .
+ public CodeMatcher EndAndBacktrack(int backtrackCount)
+ {
+ matcher.End();
+ matcher.Advance(-backtrackCount);
+ return matcher;
+ }
+
+ ///
+ /// Declares a local to be used of a certain .
+ ///
+ /// The of the local to declare.
+ /// The declared.
+ /// The current .
+ public CodeMatcher DeclareLocal(Type localType, out LocalBuilder localBuilder)
+ {
+ localBuilder = matcher.generator.DeclareLocal(localType);
+ return matcher;
+ }
+
+ ///
+ /// Declares a local to be used of a certain .
+ ///
+ /// The of the local to declare.
+ /// The index of the local declared.
+ /// The current .
+ public CodeMatcher DeclareLocal(Type localType, out int localIndex)
+ {
+ DeclareLocal(matcher, localType, out LocalBuilder builder);
+ localIndex = builder.LocalIndex;
+ return matcher;
+ }
+
+ ///
+ /// Gets the first label at the current position.
+ ///
+ /// The first label at the current position.
+ /// The current .
+ public CodeMatcher GetFirstLabel(out Label label)
+ {
+ label = matcher.Labels.FirstOrDefault();
+ return matcher;
+ }
+
+ ///
+ /// Gets the first label at a specific position.
+ ///
+ /// The position to get label at.
+ /// The label at the position.
+ /// The current .
+ public CodeMatcher GetFirstLabelAt(int position, out Label label)
+ {
+ label = matcher.codes[position].labels.FirstOrDefault();
+ return matcher;
+ }
+ }
+}
\ No newline at end of file
diff --git a/SecretAPI/SecretAPI.csproj b/SecretAPI/SecretAPI.csproj
index 055b9de..db3c6ac 100644
--- a/SecretAPI/SecretAPI.csproj
+++ b/SecretAPI/SecretAPI.csproj
@@ -26,7 +26,7 @@
-
+