From 82eec7b657f34c3144321ae47990cf6112800955 Mon Sep 17 00:00:00 2001
From: Cj <161484149+CJ-SPT@users.noreply.github.com>
Date: Wed, 8 Jan 2025 22:26:34 -0500
Subject: [PATCH] Don't automatch deobfuscator given method names
---
Assets/Templates/Settings.jsonc | 7 ++++++-
RecodeItLib/Models/AppSettingsModel.cs | 9 +++++++--
RecodeItLib/Remapper/AutoMatcher.cs | 11 +++++++----
3 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/Assets/Templates/Settings.jsonc b/Assets/Templates/Settings.jsonc
index 1a63339..2dac8c4 100644
--- a/Assets/Templates/Settings.jsonc
+++ b/Assets/Templates/Settings.jsonc
@@ -1,6 +1,6 @@
{
"MappingPath": "",
- "TokensToMatch": [
+ "TypeNamesToMatch": [
"Class",
"GClass",
"GStruct",
@@ -8,5 +8,10 @@
"ValueStruct",
"Interface",
"GInterface"
+ ],
+ "MethodsToIgnore": [
+ "method_",
+ "smethod_",
+ "vmethod_"
]
}
\ No newline at end of file
diff --git a/RecodeItLib/Models/AppSettingsModel.cs b/RecodeItLib/Models/AppSettingsModel.cs
index 656ceab..29cbe9f 100644
--- a/RecodeItLib/Models/AppSettingsModel.cs
+++ b/RecodeItLib/Models/AppSettingsModel.cs
@@ -13,7 +13,12 @@ public class Settings
public string MappingPath { get; set; } = string.Empty;
///
- /// The re-mapper will look for these tokens in class names, otherwise they will be skipped
+ /// The re-mapper will look for these classes, otherwise they will be skipped
///
- public required List TokensToMatch { get; set; }
+ public required List TypeNamesToMatch { get; set; }
+
+ ///
+ /// List of method names to be ignored during the auto-match process.
+ ///
+ public required List MethodsToIgnore { get; set; }
}
\ No newline at end of file
diff --git a/RecodeItLib/Remapper/AutoMatcher.cs b/RecodeItLib/Remapper/AutoMatcher.cs
index 9c33f66..43712c8 100644
--- a/RecodeItLib/Remapper/AutoMatcher.cs
+++ b/RecodeItLib/Remapper/AutoMatcher.cs
@@ -10,8 +10,8 @@ public class AutoMatcher(List mappings, string mappingPath)
private List? CandidateTypes { get; set; }
- private static List _tokens = DataProvider.Settings.TypeNamesToMatch;
- private static List _methodsToIgnore = DataProvider.Settings.TypeNamesToMatch;
+ private static readonly List TypesToMatch = DataProvider.Settings.TypeNamesToMatch;
+ private static readonly List MethodsToIgnore = DataProvider.Settings.MethodsToIgnore;
public void AutoMatch(string assemblyPath, string oldTypeName, string newTypeName)
{
@@ -22,8 +22,7 @@ public class AutoMatcher(List mappings, string mappingPath)
Module = module;
CandidateTypes = Module.GetTypes()
- .Where(t => _tokens.Any(token => t.Name.StartsWith(token)))
- // .Where(t => t.Name != oldTypeName)
+ .Where(t => TypesToMatch.Any(token => t.Name.StartsWith(token)))
.ToList();
var targetTypeDef = FindTargetType(oldTypeName);
@@ -166,17 +165,21 @@ public class AutoMatcher(List mappings, string mappingPath)
// Methods in target that are not in candidate
var includeMethods = target.Methods
.Where(m => !m.IsConstructor && !m.IsGetter && !m.IsSetter)
+ .Where(m => !MethodsToIgnore.Any(mi => m.Name.String.StartsWith(mi)))
.Select(s => s.Name.ToString())
.Except(candidate.Methods
.Where(m => !m.IsConstructor && !m.IsGetter && !m.IsSetter)
+ .Where(m => !MethodsToIgnore.Any(mi => m.Name.String.StartsWith(mi)))
.Select(s => s.Name.ToString()));
// Methods in candidate that are not in target
var excludeMethods = candidate.Methods
.Where(m => !m.IsConstructor && !m.IsGetter && !m.IsSetter)
+ .Where(m => !MethodsToIgnore.Any(mi => m.Name.String.StartsWith(mi)))
.Select(s => s.Name.ToString())
.Except(target.Methods
.Where(m => !m.IsConstructor && !m.IsGetter && !m.IsSetter)
+ .Where(m => !MethodsToIgnore.Any(mi => m.Name.String.StartsWith(mi)))
.Select(s => s.Name.ToString()));
foreach (var include in includeMethods)