From c3bba19df7de59d837c39070efdd9d64b30844e7 Mon Sep 17 00:00:00 2001
From: Cj <161484149+CJ-SPT@users.noreply.github.com>
Date: Thu, 2 Jan 2025 11:47:51 -0500
Subject: [PATCH] Remove unused settings. streamline remap command
---
Assets/Templates/Settings.jsonc | 7 --
ReCodeItCLI/Commands/ReMap.cs | 14 +--
ReCodeItCLI/readme.md | 3 -
RecodeItLib/Models/AppSettingsModel.cs | 130 +------------------------
RecodeItLib/Remapper/ReMapper.cs | 13 +--
RecodeItLib/Remapper/RenameHelper.cs | 39 +++-----
6 files changed, 20 insertions(+), 186 deletions(-)
diff --git a/Assets/Templates/Settings.jsonc b/Assets/Templates/Settings.jsonc
index 682ada6..601cd0f 100644
--- a/Assets/Templates/Settings.jsonc
+++ b/Assets/Templates/Settings.jsonc
@@ -7,13 +7,6 @@
"AssemblyPath": "",
"OutputPath": "",
"MappingPath": "",
- "UseProjectMappings": false,
- "MappingSettings": {
- "RenameFields": true,
- "RenameProperties": true,
- "Publicize": true,
- "Unseal": true
- },
"TokensToMatch": [
"Class",
"GClass",
diff --git a/ReCodeItCLI/Commands/ReMap.cs b/ReCodeItCLI/Commands/ReMap.cs
index 176d50c..50e57f1 100644
--- a/ReCodeItCLI/Commands/ReMap.cs
+++ b/ReCodeItCLI/Commands/ReMap.cs
@@ -16,24 +16,12 @@ public class ReMap : ICommand
[CommandParameter(1, IsRequired = true, Description = "The absolute path to your dll, containing all references that it needs to resolve.")]
public required string AssemblyPath { get; init; }
-
- [CommandParameter(2, IsRequired = true, Description = "If true, the re-mapper will publicize all types, methods, and properties")]
- public bool Publicize { get; init; }
-
- [CommandParameter(3, IsRequired = false, Description = "If true, the re-mapper will rename all changed types associated variable names to be the same as the declaring type")]
- public bool? ReName { get; init; }
-
+
public ValueTask ExecuteAsync(IConsole console)
{
DataProvider.IsCli = true;
DataProvider.LoadAppSettings();
DataProvider.Settings.Remapper.MappingPath = MappingJsonPath;
-
- var remapperSettings = DataProvider.Settings.Remapper.MappingSettings;
-
- remapperSettings.RenameFields = ReName ?? false;
- remapperSettings.RenameProperties = ReName ?? false;
- remapperSettings.Publicize = Publicize;
var remaps = DataProvider.LoadMappingFile(MappingJsonPath);
diff --git a/ReCodeItCLI/readme.md b/ReCodeItCLI/readme.md
index 88d3efe..26a1f5b 100644
--- a/ReCodeItCLI/readme.md
+++ b/ReCodeItCLI/readme.md
@@ -28,9 +28,6 @@ references needed to be resolved.
- `remap` - Generates a re-mapped dll provided a mapping file and dll. If the dll is obfuscated, it will automatically de-obfuscate.
- Param `MappingJsonPath` - The absolute path to the `mapping.json` file supports both `json` and `jsonc`.
- Param `AssemblyPath` - The absolute path to the dll generated from the `deobfuscate` command.
- - Param `Publicize` - if true, the re-mapper will publicize all types, methods, and properties in the assembly.
- - Param `Rename` - If true, the re-mapper will rename all changed types associated variable names to be the same as
-the declaring type
---
diff --git a/RecodeItLib/Models/AppSettingsModel.cs b/RecodeItLib/Models/AppSettingsModel.cs
index d855c9a..eaabb73 100644
--- a/RecodeItLib/Models/AppSettingsModel.cs
+++ b/RecodeItLib/Models/AppSettingsModel.cs
@@ -77,36 +77,6 @@ public class AppSettings
///
public class RemapperSettings
{
- private string _assemblyPath = string.Empty;
-
- ///
- /// Path to the assembly we want to remap
- ///
- public string AssemblyPath
- {
- get { return _assemblyPath; }
- set
- {
- _assemblyPath = value;
- Save();
- }
- }
-
- private string _outputPath = string.Empty;
-
- ///
- /// Path including the filename and extension we want to write the changes to
- ///
- public string OutputPath
- {
- get { return _outputPath; }
- set
- {
- _outputPath = value;
- Save();
- }
- }
-
private string _mappingPath = string.Empty;
///
@@ -121,34 +91,7 @@ public class RemapperSettings
Save();
}
}
-
- private bool _useProjectMappings;
-
- ///
- /// Use the projects mappings instead of a standalone file
- ///
- public bool UseProjectMappings
- {
- get { return _useProjectMappings; }
- set
- {
- _useProjectMappings = value;
- Save();
- }
- }
-
- private MappingSettings? _mappingSettings;
-
- public MappingSettings? MappingSettings
- {
- get { return _mappingSettings; }
- set
- {
- _mappingSettings = value;
- Save();
- }
- }
-
+
private List _tokensToMatch = [];
///
@@ -164,77 +107,6 @@ public class RemapperSettings
}
}
- private void Save()
- {
- DataProvider.SaveAppSettings();
- }
-}
-
-///
-/// These are settings that all versions of the remappers use
-///
-public class MappingSettings
-{
- private bool _renameFields;
-
- ///
- /// Names of fields of the matched type will be renamed to the type name with approproiate convention
- ///
- public bool RenameFields
- {
- get { return _renameFields; }
- set
- {
- _renameFields = value;
- Save();
- }
- }
-
- private bool _renameProps;
-
- ///
- /// Names of properties of the matched type will be renamed to the type name with approproiate convention
- ///
- public bool RenameProperties
- {
- get { return _renameProps; }
- set
- {
- _renameProps = value;
- Save();
- }
- }
-
- private bool _publicize;
-
- ///
- /// Publicize all types, methods, and properties : NOTE: Not run until after the remap has completed
- ///
- public bool Publicize
- {
- get { return _publicize; }
- set
- {
- _publicize = value;
- Save();
- }
- }
-
- private bool _unseal;
-
- ///
- /// Unseal all types : NOTE: Not run until after the remap has completed
- ///
- public bool Unseal
- {
- get { return _unseal; }
- set
- {
- _unseal = value;
- Save();
- }
- }
-
private void Save()
{
DataProvider.SaveAppSettings();
diff --git a/RecodeItLib/Remapper/ReMapper.cs b/RecodeItLib/Remapper/ReMapper.cs
index 042f3d8..3411b56 100644
--- a/RecodeItLib/Remapper/ReMapper.cs
+++ b/RecodeItLib/Remapper/ReMapper.cs
@@ -130,12 +130,9 @@ public class ReMapper
private void Publicize()
{
// Don't publicize and unseal until after the remapping, so we can use those as search parameters
- if (Settings!.MappingSettings!.Publicize)
- {
- Logger.LogSync("\nPublicizing classes...", ConsoleColor.Green);
+ Logger.LogSync("\nPublicizing classes...", ConsoleColor.Green);
- SPTPublicizer.PublicizeClasses(Module);
- }
+ SPTPublicizer.PublicizeClasses(Module);
}
private bool Validate(List remaps)
@@ -319,11 +316,7 @@ public class ReMapper
{
var moduleName = Module?.Name;
- var dllName = "-cleaned-remapped.dll";
- if (Settings!.MappingSettings!.Publicize)
- {
- dllName = "-cleaned-remapped-publicized.dll";
- }
+ var dllName = "-cleaned-remapped-publicized.dll";
OutPath = Path.Combine(OutPath, moduleName?.Replace(".dll", dllName));
try
diff --git a/RecodeItLib/Remapper/RenameHelper.cs b/RecodeItLib/Remapper/RenameHelper.cs
index 4c210fe..c2e9948 100644
--- a/RecodeItLib/Remapper/RenameHelper.cs
+++ b/RecodeItLib/Remapper/RenameHelper.cs
@@ -16,28 +16,22 @@ internal static class RenameHelper
///
public static void RenameAll(IEnumerable types, RemapModel remap)
{
+ if (remap.TypePrimeCandidate is null)
+ {
+ Logger.Log($"Unable to rename {remap.NewTypeName} as TypePrimeCandidate value is null/empty, skipping", ConsoleColor.Red);
+ return;
+ }
+
// Rename all fields and properties first
- if (DataProvider.Settings!.Remapper!.MappingSettings!.RenameFields)
- {
- if (remap.TypePrimeCandidate is null)
- {
- Logger.Log($"Unable to rename {remap.NewTypeName} as TypePrimeCandidate value is null/empty, skipping", ConsoleColor.Red);
- return;
- }
+ RenameAllFields(
+ remap.TypePrimeCandidate.Name.String,
+ remap.NewTypeName,
+ types);
- RenameAllFields(
- remap.TypePrimeCandidate.Name.String,
- remap.NewTypeName,
- types);
- }
-
- if (DataProvider.Settings.Remapper.MappingSettings.RenameProperties)
- {
- RenameAllProperties(
- remap!.TypePrimeCandidate!.Name.String,
- remap.NewTypeName,
- types);
- }
+ RenameAllProperties(
+ remap!.TypePrimeCandidate!.Name.String,
+ remap.NewTypeName,
+ types);
FixMethods(types, remap);
RenameType(types, remap);
@@ -92,8 +86,7 @@ internal static class RenameHelper
var oldName = field.Name.ToString();
field.Name = newFieldName;
-
- UpdateTypeFieldMemberRefs(type, field, oldName);
+
UpdateAllTypeFieldMemberRefs(typesToCheck, field, oldName);
fieldCount++;
@@ -120,8 +113,6 @@ internal static class RenameHelper
{
if (instr.Operand is MemberRef memRef && memRef.Name == oldName)
{
- //if (!memRef.Name.IsFieldOrPropNameInList(TokensToMatch)) continue;
-
memRef.Name = newDef.Name;
}
}