mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-13 03:10:45 -05:00
Remove unused settings. streamline remap command
This commit is contained in:
parent
6bce67b479
commit
c3bba19df7
@ -7,13 +7,6 @@
|
|||||||
"AssemblyPath": "",
|
"AssemblyPath": "",
|
||||||
"OutputPath": "",
|
"OutputPath": "",
|
||||||
"MappingPath": "",
|
"MappingPath": "",
|
||||||
"UseProjectMappings": false,
|
|
||||||
"MappingSettings": {
|
|
||||||
"RenameFields": true,
|
|
||||||
"RenameProperties": true,
|
|
||||||
"Publicize": true,
|
|
||||||
"Unseal": true
|
|
||||||
},
|
|
||||||
"TokensToMatch": [
|
"TokensToMatch": [
|
||||||
"Class",
|
"Class",
|
||||||
"GClass",
|
"GClass",
|
||||||
|
@ -17,24 +17,12 @@ public class ReMap : ICommand
|
|||||||
[CommandParameter(1, IsRequired = true, Description = "The absolute path to your dll, containing all references that it needs to resolve.")]
|
[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; }
|
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)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
DataProvider.IsCli = true;
|
DataProvider.IsCli = true;
|
||||||
DataProvider.LoadAppSettings();
|
DataProvider.LoadAppSettings();
|
||||||
DataProvider.Settings.Remapper.MappingPath = MappingJsonPath;
|
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);
|
var remaps = DataProvider.LoadMappingFile(MappingJsonPath);
|
||||||
|
|
||||||
var outPath = Path.GetDirectoryName(AssemblyPath);
|
var outPath = Path.GetDirectoryName(AssemblyPath);
|
||||||
|
@ -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.
|
- `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 `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 `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
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -77,36 +77,6 @@ public class AppSettings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class RemapperSettings
|
public class RemapperSettings
|
||||||
{
|
{
|
||||||
private string _assemblyPath = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Path to the assembly we want to remap
|
|
||||||
/// </summary>
|
|
||||||
public string AssemblyPath
|
|
||||||
{
|
|
||||||
get { return _assemblyPath; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_assemblyPath = value;
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private string _outputPath = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Path including the filename and extension we want to write the changes to
|
|
||||||
/// </summary>
|
|
||||||
public string OutputPath
|
|
||||||
{
|
|
||||||
get { return _outputPath; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_outputPath = value;
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private string _mappingPath = string.Empty;
|
private string _mappingPath = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -122,33 +92,6 @@ public class RemapperSettings
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _useProjectMappings;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Use the projects mappings instead of a standalone file
|
|
||||||
/// </summary>
|
|
||||||
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<string> _tokensToMatch = [];
|
private List<string> _tokensToMatch = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -169,74 +112,3 @@ public class RemapperSettings
|
|||||||
DataProvider.SaveAppSettings();
|
DataProvider.SaveAppSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// These are settings that all versions of the remappers use
|
|
||||||
/// </summary>
|
|
||||||
public class MappingSettings
|
|
||||||
{
|
|
||||||
private bool _renameFields;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Names of fields of the matched type will be renamed to the type name with approproiate convention
|
|
||||||
/// </summary>
|
|
||||||
public bool RenameFields
|
|
||||||
{
|
|
||||||
get { return _renameFields; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_renameFields = value;
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _renameProps;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Names of properties of the matched type will be renamed to the type name with approproiate convention
|
|
||||||
/// </summary>
|
|
||||||
public bool RenameProperties
|
|
||||||
{
|
|
||||||
get { return _renameProps; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_renameProps = value;
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _publicize;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Publicize all types, methods, and properties : NOTE: Not run until after the remap has completed
|
|
||||||
/// </summary>
|
|
||||||
public bool Publicize
|
|
||||||
{
|
|
||||||
get { return _publicize; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_publicize = value;
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _unseal;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Unseal all types : NOTE: Not run until after the remap has completed
|
|
||||||
/// </summary>
|
|
||||||
public bool Unseal
|
|
||||||
{
|
|
||||||
get { return _unseal; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_unseal = value;
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Save()
|
|
||||||
{
|
|
||||||
DataProvider.SaveAppSettings();
|
|
||||||
}
|
|
||||||
}
|
|
@ -130,12 +130,9 @@ public class ReMapper
|
|||||||
private void Publicize()
|
private void Publicize()
|
||||||
{
|
{
|
||||||
// Don't publicize and unseal until after the remapping, so we can use those as search parameters
|
// 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<RemapModel> remaps)
|
private bool Validate(List<RemapModel> remaps)
|
||||||
@ -319,11 +316,7 @@ public class ReMapper
|
|||||||
{
|
{
|
||||||
var moduleName = Module?.Name;
|
var moduleName = Module?.Name;
|
||||||
|
|
||||||
var dllName = "-cleaned-remapped.dll";
|
var dllName = "-cleaned-remapped-publicized.dll";
|
||||||
if (Settings!.MappingSettings!.Publicize)
|
|
||||||
{
|
|
||||||
dllName = "-cleaned-remapped-publicized.dll";
|
|
||||||
}
|
|
||||||
OutPath = Path.Combine(OutPath, moduleName?.Replace(".dll", dllName));
|
OutPath = Path.Combine(OutPath, moduleName?.Replace(".dll", dllName));
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -16,28 +16,22 @@ internal static class RenameHelper
|
|||||||
/// <param name="direct"></param>
|
/// <param name="direct"></param>
|
||||||
public static void RenameAll(IEnumerable<TypeDef> types, RemapModel remap)
|
public static void RenameAll(IEnumerable<TypeDef> 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
|
// Rename all fields and properties first
|
||||||
if (DataProvider.Settings!.Remapper!.MappingSettings!.RenameFields)
|
RenameAllFields(
|
||||||
{
|
remap.TypePrimeCandidate.Name.String,
|
||||||
if (remap.TypePrimeCandidate is null)
|
remap.NewTypeName,
|
||||||
{
|
types);
|
||||||
Logger.Log($"Unable to rename {remap.NewTypeName} as TypePrimeCandidate value is null/empty, skipping", ConsoleColor.Red);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
RenameAllFields(
|
RenameAllProperties(
|
||||||
remap.TypePrimeCandidate.Name.String,
|
remap!.TypePrimeCandidate!.Name.String,
|
||||||
remap.NewTypeName,
|
remap.NewTypeName,
|
||||||
types);
|
types);
|
||||||
}
|
|
||||||
|
|
||||||
if (DataProvider.Settings.Remapper.MappingSettings.RenameProperties)
|
|
||||||
{
|
|
||||||
RenameAllProperties(
|
|
||||||
remap!.TypePrimeCandidate!.Name.String,
|
|
||||||
remap.NewTypeName,
|
|
||||||
types);
|
|
||||||
}
|
|
||||||
|
|
||||||
FixMethods(types, remap);
|
FixMethods(types, remap);
|
||||||
RenameType(types, remap);
|
RenameType(types, remap);
|
||||||
@ -93,7 +87,6 @@ internal static class RenameHelper
|
|||||||
|
|
||||||
field.Name = newFieldName;
|
field.Name = newFieldName;
|
||||||
|
|
||||||
UpdateTypeFieldMemberRefs(type, field, oldName);
|
|
||||||
UpdateAllTypeFieldMemberRefs(typesToCheck, field, oldName);
|
UpdateAllTypeFieldMemberRefs(typesToCheck, field, oldName);
|
||||||
|
|
||||||
fieldCount++;
|
fieldCount++;
|
||||||
@ -120,8 +113,6 @@ internal static class RenameHelper
|
|||||||
{
|
{
|
||||||
if (instr.Operand is MemberRef memRef && memRef.Name == oldName)
|
if (instr.Operand is MemberRef memRef && memRef.Name == oldName)
|
||||||
{
|
{
|
||||||
//if (!memRef.Name.IsFieldOrPropNameInList(TokensToMatch)) continue;
|
|
||||||
|
|
||||||
memRef.Name = newDef.Name;
|
memRef.Name = newDef.Name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user