0
0
mirror of https://github.com/sp-tarkov/assembly-tool.git synced 2025-02-13 05:50:45 -05:00

58 lines
1.8 KiB
C#
Raw Normal View History

// Uncomment this to have the application wait for a debugger to attach before running.
#define WAIT_FOR_DEBUGGER
using System.Diagnostics;
using CliFx;
2025-01-01 19:17:56 -05:00
using CliFx.Attributes;
using CliFx.Infrastructure;
using ReCodeItLib.Models;
using ReCodeItLib.ReMapper;
using ReCodeItLib.Utils;
namespace ReCodeItCLI.Commands;
2025-01-01 22:48:18 -05:00
[Command("AutoMatch", Description = "This command will automatically try to generate a mapping object given old type and new type names.")]
2025-01-01 19:17:56 -05:00
public class AutoMatchCommand : ICommand
{
2025-01-01 22:48:18 -05:00
[CommandParameter(0, IsRequired = true, Description = "The absolute path to your assembly, folder must contain all references to be resolved.")]
2025-01-01 19:17:56 -05:00
public required string AssemblyPath { get; init; }
2025-01-02 01:21:37 -05:00
[CommandParameter(1, IsRequired = true, Description = "Path to your mapping file so it can be updated if a match is found")]
public string MappingsPath { get; init; }
[CommandParameter(2, IsRequired = true, Description = "Full old type name including namespace")]
2025-01-01 19:17:56 -05:00
public required string OldTypeName { get; init; }
2025-01-02 01:21:37 -05:00
[CommandParameter(3, IsRequired = true, Description = "The name you want the type to be renamed to")]
2025-01-01 19:17:56 -05:00
public required string NewTypeName { get; init; }
2025-01-10 06:35:51 -05:00
2025-01-01 19:17:56 -05:00
public ValueTask ExecuteAsync(IConsole console)
{
#if WAIT_FOR_DEBUGGER
Logger.LogSync("Waiting for debugger...");
while (!Debugger.IsAttached)
{
Thread.Sleep(100);
}
#endif
2025-01-01 19:17:56 -05:00
Logger.LogSync("Finding match...");
var remaps = new List<RemapModel>();
2025-01-01 19:17:56 -05:00
if (!string.IsNullOrEmpty(MappingsPath))
{
2025-01-01 20:07:20 -05:00
Logger.LogSync("Loaded mapping file", ConsoleColor.Green);
2025-01-01 19:17:56 -05:00
remaps.AddRange(DataProvider.LoadMappingFile(MappingsPath));
}
2025-01-01 20:07:20 -05:00
new AutoMatcher(remaps, MappingsPath)
2025-01-01 19:17:56 -05:00
.AutoMatch(AssemblyPath, OldTypeName, NewTypeName);
// Wait for log termination
Logger.Terminate();
while(Logger.IsRunning()) {}
return default;
}
}