mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-12 16:50:44 -05:00
Remove unused settings. streamline remap command
This commit is contained in:
parent
6bce67b479
commit
c3bba19df7
@ -7,13 +7,6 @@
|
||||
"AssemblyPath": "",
|
||||
"OutputPath": "",
|
||||
"MappingPath": "",
|
||||
"UseProjectMappings": false,
|
||||
"MappingSettings": {
|
||||
"RenameFields": true,
|
||||
"RenameProperties": true,
|
||||
"Publicize": true,
|
||||
"Unseal": true
|
||||
},
|
||||
"TokensToMatch": [
|
||||
"Class",
|
||||
"GClass",
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
||||
---
|
||||
|
||||
|
@ -77,36 +77,6 @@ public class AppSettings
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
@ -121,34 +91,7 @@ public class RemapperSettings
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
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 = [];
|
||||
|
||||
/// <summary>
|
||||
@ -164,77 +107,6 @@ public class RemapperSettings
|
||||
}
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
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()
|
||||
{
|
||||
// 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)
|
||||
@ -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
|
||||
|
@ -16,28 +16,22 @@ internal static class RenameHelper
|
||||
/// <param name="direct"></param>
|
||||
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
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user