Command work + dont panic when settings are not found
This commit is contained in:
parent
1363d91fcd
commit
141fb6807a
@ -7,12 +7,12 @@ using ReCodeItLib.Utils;
|
|||||||
|
|
||||||
namespace ReCodeIt.Commands;
|
namespace ReCodeIt.Commands;
|
||||||
|
|
||||||
[Command("Build", Description = "Build your project and get a dll output for the original assembly. You dont need to provide a path if the last project you built is the one you want to target, or you are running this command from inside a directory where a project file exists.")]
|
[Command("Build", Description = "(Compile Time Reflection) Build your project and get a dll output for the original assembly.")]
|
||||||
public class BuildCommand : ICommand
|
public class BuildCommand : ICommand
|
||||||
{
|
{
|
||||||
private ReCodeItCrossCompiler CrossCompiler { get; set; }
|
private ReCodeItCrossCompiler CrossCompiler { get; set; }
|
||||||
|
|
||||||
[CommandParameter(0, IsRequired = false, Description = "the location of your project file (ReCodeItProj.json)")]
|
[CommandParameter(0, IsRequired = false, Description = "the location of your project file (ReCodeItProj.json). You don't need to provide a path if the last project you built is the one you want to target, or you are running this command from inside a directory where a project file exists.")]
|
||||||
public string ProjectJsonPath { get; init; }
|
public string ProjectJsonPath { get; init; }
|
||||||
|
|
||||||
public async ValueTask ExecuteAsync(IConsole console)
|
public async ValueTask ExecuteAsync(IConsole console)
|
||||||
|
@ -7,7 +7,7 @@ using ReCodeItLib.Utils;
|
|||||||
|
|
||||||
namespace ReCodeIt.Commands;
|
namespace ReCodeIt.Commands;
|
||||||
|
|
||||||
[Command("BuildRef", Description = "Builds or rebuilds a new reference DLL for your project")]
|
[Command("BuildRef", Description = "(Compile Time Reflection) Builds or rebuilds a new reference DLL for your project")]
|
||||||
public class BuildRef : ICommand
|
public class BuildRef : ICommand
|
||||||
{
|
{
|
||||||
private ReCodeItCrossCompiler CrossCompiler { get; set; }
|
private ReCodeItCrossCompiler CrossCompiler { get; set; }
|
||||||
|
43
ReCodeItCLI/Commands/ReMapCommand.cs
Normal file
43
ReCodeItCLI/Commands/ReMapCommand.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using CliFx;
|
||||||
|
using CliFx.Attributes;
|
||||||
|
using CliFx.Infrastructure;
|
||||||
|
using ReCodeIt.ReMapper;
|
||||||
|
using ReCodeIt.Utils;
|
||||||
|
|
||||||
|
namespace ReCodeIt.Commands;
|
||||||
|
|
||||||
|
[Command("ReMap", Description = "Generates a re-mapped dll provided a mapping file and de-obfuscated dll")]
|
||||||
|
public class ReMapCommand : ICommand
|
||||||
|
{
|
||||||
|
private ReCodeItRemapper _remapper { get; set; } = new();
|
||||||
|
|
||||||
|
[CommandParameter(0, IsRequired = true, Description = "The absolute path to your mapping.json file, supports .json and .jsonc")]
|
||||||
|
public string MappingJsonPath { get; init; }
|
||||||
|
|
||||||
|
[CommandParameter(1, IsRequired = true, Description = "The absolute path to your de-obfuscated dll, containing all references that it needs to resolve.")]
|
||||||
|
public 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.LoadAppSettings();
|
||||||
|
DataProvider.IsCli = true;
|
||||||
|
|
||||||
|
var remapperSettings = DataProvider.Settings.Remapper.MappingSettings;
|
||||||
|
|
||||||
|
remapperSettings.RenameFields = ReName ?? false;
|
||||||
|
remapperSettings.RenameProperties = ReName ?? false;
|
||||||
|
remapperSettings.Publicize = Publicize;
|
||||||
|
|
||||||
|
var remaps = DataProvider.LoadMappingFile(MappingJsonPath);
|
||||||
|
|
||||||
|
_remapper.InitializeRemap(remaps, AssemblyPath, Path.GetDirectoryName(AssemblyPath));
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
@ -385,7 +385,7 @@ public partial class ReCodeItForm : Form
|
|||||||
Remapper.InitializeRemap(
|
Remapper.InitializeRemap(
|
||||||
DataProvider.Remaps,
|
DataProvider.Remaps,
|
||||||
AppSettings.Remapper.AssemblyPath,
|
AppSettings.Remapper.AssemblyPath,
|
||||||
AppSettings.Remapper.OutputPath);
|
Path.GetDirectoryName(AppSettings.Remapper.OutputPath));
|
||||||
|
|
||||||
ReloadRemapTreeView(DataProvider.Remaps);
|
ReloadRemapTreeView(DataProvider.Remaps);
|
||||||
}
|
}
|
||||||
|
@ -305,17 +305,14 @@ public class ReCodeItRemapper
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void WriteAssembly()
|
private void WriteAssembly()
|
||||||
{
|
{
|
||||||
if (!OutPath.EndsWith(".dll"))
|
var moduleName = DataProvider.AssemblyDefinition.MainModule.Name;
|
||||||
{
|
moduleName = moduleName.Replace(".dll", "-Remapped.dll");
|
||||||
var moduleName = DataProvider.AssemblyDefinition.MainModule.Name;
|
|
||||||
moduleName = moduleName.Replace(".dll", "-Remapped.dll");
|
|
||||||
|
|
||||||
OutPath = Path.Combine(OutPath, moduleName);
|
OutPath = Path.Combine(OutPath, moduleName);
|
||||||
}
|
|
||||||
|
|
||||||
var path = DataProvider.WriteAssemblyDefinition(OutPath);
|
var path = DataProvider.WriteAssemblyDefinition(OutPath);
|
||||||
|
|
||||||
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
Logger.Log("Creating Hollow...", ConsoleColor.Yellow);
|
||||||
Hollow();
|
Hollow();
|
||||||
|
|
||||||
var hollowedDir = Path.GetDirectoryName(OutPath);
|
var hollowedDir = Path.GetDirectoryName(OutPath);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Mono.Cecil;
|
using Microsoft.Win32;
|
||||||
|
using Mono.Cecil;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using ReCodeIt.Models;
|
using ReCodeIt.Models;
|
||||||
using ReCodeItLib.Utils;
|
using ReCodeItLib.Utils;
|
||||||
@ -28,7 +29,7 @@ public static class DataProvider
|
|||||||
|
|
||||||
public static Dictionary<string, HashSet<ScoringModel>> ScoringModels { get; set; } = [];
|
public static Dictionary<string, HashSet<ScoringModel>> ScoringModels { get; set; } = [];
|
||||||
|
|
||||||
public static Settings Settings { get; private set; }
|
public static Settings Settings { get; set; }
|
||||||
|
|
||||||
public static AssemblyDefinition AssemblyDefinition { get; private set; }
|
public static AssemblyDefinition AssemblyDefinition { get; private set; }
|
||||||
|
|
||||||
@ -40,7 +41,14 @@ public static class DataProvider
|
|||||||
|
|
||||||
if (!File.Exists(settingsPath))
|
if (!File.Exists(settingsPath))
|
||||||
{
|
{
|
||||||
throw new FileNotFoundException($"path `{settingsPath}` does not exist...");
|
Logger.Log($"Could not find settings path `{settingsPath}`, loading defaults");
|
||||||
|
Settings = CreateFakeSettings();
|
||||||
|
|
||||||
|
RegistryHelper.SetRegistryValue("SettingsPath", Path.Combine(DataPath, "Settings.json"), RegistryValueKind.String);
|
||||||
|
RegistryHelper.SetRegistryValue("LogPath", Path.Combine(DataPath, "Log.log"), RegistryValueKind.String);
|
||||||
|
|
||||||
|
SaveAppSettings();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var jsonText = File.ReadAllText(settingsPath);
|
var jsonText = File.ReadAllText(settingsPath);
|
||||||
@ -61,7 +69,7 @@ public static class DataProvider
|
|||||||
|
|
||||||
if (!File.Exists(settingsPath))
|
if (!File.Exists(settingsPath))
|
||||||
{
|
{
|
||||||
Logger.Log($"path `{settingsPath}` does not exist...", ConsoleColor.Red);
|
Logger.Log($"path `{settingsPath}` does not exist. Could not save settings", ConsoleColor.Red);
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonSerializerSettings settings = new()
|
JsonSerializerSettings settings = new()
|
||||||
@ -80,7 +88,7 @@ public static class DataProvider
|
|||||||
{
|
{
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
{
|
{
|
||||||
Logger.Log($"Error loading mapping.json from `{path}`, First time running? Please select a mapping path");
|
Logger.Log($"Error loading mapping.json from `{path}`, First time running? Please select a mapping path in the gui", ConsoleColor.Red);
|
||||||
}
|
}
|
||||||
|
|
||||||
var jsonText = File.ReadAllText(path);
|
var jsonText = File.ReadAllText(path);
|
||||||
@ -195,4 +203,91 @@ public static class DataProvider
|
|||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Settings CreateFakeSettings()
|
||||||
|
{
|
||||||
|
var settings = new Settings
|
||||||
|
{
|
||||||
|
AppSettings = new AppSettings
|
||||||
|
{
|
||||||
|
Debug = false,
|
||||||
|
SilentMode = true
|
||||||
|
},
|
||||||
|
Remapper = new RemapperSettings
|
||||||
|
{
|
||||||
|
MappingPath = string.Empty,
|
||||||
|
OutputPath = string.Empty,
|
||||||
|
UseProjectMappings = false,
|
||||||
|
MappingSettings = new MappingSettings
|
||||||
|
{
|
||||||
|
RenameFields = false,
|
||||||
|
RenameProperties = false,
|
||||||
|
Publicize = false,
|
||||||
|
Unseal = false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
AutoMapper = new AutoMapperSettings
|
||||||
|
{
|
||||||
|
AssemblyPath = string.Empty,
|
||||||
|
OutputPath = string.Empty,
|
||||||
|
RequiredMatches = 5,
|
||||||
|
MinLengthToMatch = 7,
|
||||||
|
SearchMethods = true,
|
||||||
|
MappingSettings = new MappingSettings
|
||||||
|
{
|
||||||
|
RenameFields = false,
|
||||||
|
RenameProperties = false,
|
||||||
|
Publicize = false,
|
||||||
|
Unseal = false,
|
||||||
|
},
|
||||||
|
TypesToIgnore = [
|
||||||
|
"Boolean",
|
||||||
|
"List",
|
||||||
|
"Dictionary",
|
||||||
|
"Byte",
|
||||||
|
"Int16",
|
||||||
|
"Int32",
|
||||||
|
"Func",
|
||||||
|
"Action",
|
||||||
|
"Object",
|
||||||
|
"String",
|
||||||
|
"Vector2",
|
||||||
|
"Vector3",
|
||||||
|
"Vector4",
|
||||||
|
"Stream",
|
||||||
|
"HashSet",
|
||||||
|
"Double",
|
||||||
|
"IEnumerator"
|
||||||
|
],
|
||||||
|
TokensToMatch = [
|
||||||
|
"Class",
|
||||||
|
"GClass",
|
||||||
|
"GStruct",
|
||||||
|
"Interface",
|
||||||
|
"GInterface"
|
||||||
|
],
|
||||||
|
PropertyFieldBlackList = [
|
||||||
|
"Columns",
|
||||||
|
"mColumns",
|
||||||
|
"Template",
|
||||||
|
"Condition",
|
||||||
|
"Conditions",
|
||||||
|
"Counter",
|
||||||
|
"Instance",
|
||||||
|
"Command",
|
||||||
|
"_template"
|
||||||
|
],
|
||||||
|
MethodParamaterBlackList = [
|
||||||
|
|
||||||
|
],
|
||||||
|
},
|
||||||
|
CrossCompiler = new CrossCompilerSettings
|
||||||
|
{
|
||||||
|
LastLoadedProject = string.Empty,
|
||||||
|
AutoLoadLastActiveProject = true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user