From 06602ce03775e0ce6cb5fb500b9ad30d8e2acd4b Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Tue, 5 Nov 2024 21:16:37 -0500 Subject: [PATCH] Remove more not needed manual remaps, dynamically remap item templates (different from the item objects) and clean up --- Assets/mappings.jsonc | 90 ------------------------ RecodeItLib/Remapper/ReCodeItRemapper.cs | 36 +++++++--- 2 files changed, 27 insertions(+), 99 deletions(-) diff --git a/Assets/mappings.jsonc b/Assets/mappings.jsonc index e5001b0..0a0089a 100644 --- a/Assets/mappings.jsonc +++ b/Assets/mappings.jsonc @@ -1189,96 +1189,6 @@ "ExcludeNestedTypes": [] } }, - { - "NewTypeName": "SecureContainerTemplateClass", - "OriginalTypeName": "GClass2827", - "UseForceRename": false, - "SearchParams": { - "IsPublic": true, - "IncludeMethods": [], - "ExcludeMethods": [], - "IncludeFields": [ - "containType" - ], - "ExcludeFields": [], - "IncludeProperties": [], - "ExcludeProperties": [], - "IncludeNestedTypes": [], - "ExcludeNestedTypes": [] - } - }, - { - "NewTypeName": "Meds2Class", - "OriginalTypeName": "GClass2855", - "UseForceRename": false, - "SearchParams": { - "IsPublic": true, - "IncludeMethods": [], - "ExcludeMethods": [], - "IncludeFields": [ - "BodyPartTimeMults" - ], - "ExcludeFields": [], - "IncludeProperties": [], - "ExcludeProperties": [], - "IncludeNestedTypes": [], - "ExcludeNestedTypes": [] - } - }, - { - "NewTypeName": "RepairKitClass", - "OriginalTypeName": "GClass2860", - "UseForceRename": false, - "SearchParams": { - "IsPublic": true, - "IncludeMethods": [], - "ExcludeMethods": [], - "IncludeFields": [ - "TargetItemFilter" - ], - "ExcludeFields": [], - "IncludeProperties": [], - "ExcludeProperties": [], - "IncludeNestedTypes": [], - "ExcludeNestedTypes": [] - } - }, - { - "NewTypeName": "MoneyClass", - "OriginalTypeName": "GClass2870", - "UseForceRename": false, - "SearchParams": { - "IsPublic": true, - "IncludeMethods": [], - "ExcludeMethods": [], - "IncludeFields": [ - "eqMax" - ], - "ExcludeFields": [], - "IncludeProperties": [], - "ExcludeProperties": [], - "IncludeNestedTypes": [], - "ExcludeNestedTypes": [] - } - }, - { - "NewTypeName": "ThrowableWeaponClass", - "OriginalTypeName": "GClass2872", - "UseForceRename": false, - "SearchParams": { - "IsPublic": true, - "IncludeMethods": [], - "ExcludeMethods": [], - "IncludeFields": [ - "MinFragmentDamage" - ], - "ExcludeFields": [], - "IncludeProperties": [], - "ExcludeProperties": [], - "IncludeNestedTypes": [], - "ExcludeNestedTypes": [] - } - }, { "NewTypeName": "BossKnightBrainClass", "OriginalTypeName": "GClass292", diff --git a/RecodeItLib/Remapper/ReCodeItRemapper.cs b/RecodeItLib/Remapper/ReCodeItRemapper.cs index 3a172c6..95d54d8 100644 --- a/RecodeItLib/Remapper/ReCodeItRemapper.cs +++ b/RecodeItLib/Remapper/ReCodeItRemapper.cs @@ -62,8 +62,8 @@ public class ReCodeItRemapper Logger.Log("You must de-obfuscate the assembly before remapping it.\n", ConsoleColor.Red); return; } - - HandleTypeTableRemaps(assemblyPath, types); + + GenerateDynamicRemaps(assemblyPath, types); var tasks = new List(remapModels.Count); foreach (var remap in remapModels) @@ -430,28 +430,46 @@ public class ReCodeItRemapper } } - private void HandleTypeTableRemaps(string path, IEnumerable types) + private void GenerateDynamicRemaps(string path, IEnumerable types) { // HACK: Because this is written in net8 and the assembly is net472 we must resolve the type this way instead of // filtering types directly using GetTypes() Otherwise, it causes serialization issues. // This is also necessary because we can't access non-compile time constants with dnlib. - var templateMappingTypeDef = types.Single(t => t.FindField("TypeTable") != null); + var templateMappingTypeDef = types.SingleOrDefault(t => t.FindField("TypeTable") != null); + + if (templateMappingTypeDef is null) + { + Logger.Log("Could not find type for field TypeTable", ConsoleColor.Red); + return; + } + var assembly = Assembly.LoadFrom(path); var templateMappingClass = assembly.Modules .First() .GetType(templateMappingTypeDef.Name); - + if (templateMappingClass is null) { - Logger.Log($"Could not find {templateMappingTypeDef.Name} in the assembly.", ConsoleColor.Red); + Logger.Log($"Could not resolve type for {templateMappingTypeDef.Name}", ConsoleColor.Red); return; } var typeTable = (Dictionary)templateMappingClass .GetField("TypeTable") .GetValue(templateMappingClass); - - foreach (var type in typeTable) + + BuildAssociationFromTable(typeTable, "ItemClass"); + + var templateTypeTable = (Dictionary)templateMappingClass + .GetField("TemplateTypeTable") + .GetValue(templateMappingClass); + + BuildAssociationFromTable(templateTypeTable, "TemplateClass"); + } + + private void BuildAssociationFromTable(Dictionary table, string extName) + { + foreach (var type in table) { if (DataProvider.ItemTemplates!.TryGetValue(type.Key, out var template)) { @@ -462,7 +480,7 @@ public class ReCodeItRemapper var remap = new RemapModel { OriginalTypeName = type.Value.Name, - NewTypeName = $"{template._name}Class", + NewTypeName = $"{template._name}{extName}", UseForceRename = true };