Config changes

This commit is contained in:
Cj 2024-06-13 17:55:06 -04:00
parent 8284605d04
commit e235b27d99
6 changed files with 69 additions and 40 deletions

View File

@ -3,16 +3,35 @@
/// <summary>
/// Remap config
/// </summary>
internal class Settings
{
public AppSettings AppSettings { get; set; }
public RemapperSettings RemapperSettings { get; set; }
public AutoMapperSettings AutoMapperSettings { get; set; }
}
internal class AppSettings
{
public bool Debug { get; set; }
public bool SilentMode { get; set; }
public int MaxMatchCount { get; set; }
public bool ScoringMode { get; set; }
public bool Publicize { get; set; }
public bool Unseal { get; set; }
public bool Debug { get; set; } = false;
public bool SilentMode { get; set; } = true;
public bool MatchMode { get; set; } = false;
}
public string AssemblyPath { get; set; }
public string OutputPath { get; set; }
public string MappingPath { get; set; }
internal class RemapperSettings
{
public int MaxMatchCount { get; set; } = 5;
public bool Publicize { get; set; } = false;
public bool Unseal { get; set; } = false;
public string AssemblyPath { get; set; } = string.Empty;
public string OutputPath { get; set; } = string.Empty;
public string MappingPath { get; set; } = string.Empty;
}
internal class AutoMapperSettings
{
public bool Publicize { get; set; } = false;
public bool Unseal { get; set; } = false;
}

View File

@ -6,8 +6,6 @@ internal static class Publicizer
{
public static void Publicize()
{
if (!DataProvider.AppSettings.Publicize) { return; }
Logger.Log("Starting publicization...", ConsoleColor.Green);
foreach (var type in DataProvider.ModuleDefinition.Types)
@ -44,8 +42,6 @@ internal static class Publicizer
public static void Unseal()
{
if (!DataProvider.AppSettings.Unseal) { return; }
Logger.Log("Starting unseal...", ConsoleColor.Green);
foreach (var type in DataProvider.ModuleDefinition.Types)

View File

@ -29,11 +29,18 @@ internal class Remapper
ChooseBestMatches();
if (DataProvider.AppSettings.ScoringMode) { return; }
if (DataProvider.Settings.AppSettings.MatchMode) { return; }
// Dont publicize and unseal until after the remapping so we can use those as search parameters
Publicizer.Publicize();
Publicizer.Unseal();
if (!DataProvider.Settings.RemapperSettings.Publicize)
{
Publicizer.Publicize();
}
if (!DataProvider.Settings.RemapperSettings.Unseal)
{
Publicizer.Unseal();
}
// We are done, write the assembly
WriteAssembly();
@ -47,8 +54,8 @@ internal class Remapper
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
Logger.Log($"Starting remap...", ConsoleColor.Yellow);
Logger.Log($"Module contains {DataProvider.ModuleDefinition.Types.Count} Types", ConsoleColor.Yellow);
Logger.Log($"Publicize: {DataProvider.AppSettings.Publicize}", ConsoleColor.Yellow);
Logger.Log($"Unseal: {DataProvider.AppSettings.Unseal}", ConsoleColor.Yellow);
Logger.Log($"Publicize: {DataProvider.Settings.RemapperSettings.Publicize}", ConsoleColor.Yellow);
Logger.Log($"Unseal: {DataProvider.Settings.RemapperSettings.Unseal}", ConsoleColor.Yellow);
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
}
@ -192,7 +199,7 @@ internal class Remapper
var filteredScores = scores
.OrderByDescending(score => score.Score)
.Take(DataProvider.AppSettings.MaxMatchCount);
.Take(DataProvider.Settings.RemapperSettings.MaxMatchCount);
var highestScore = filteredScores.FirstOrDefault();
@ -213,6 +220,8 @@ internal class Remapper
}
}
if (DataProvider.Settings.AppSettings.MatchMode) { return; }
highestScore.ReMap.OriginalTypeName = highestScore.Definition.Name;
// Rename type and all associated type members
@ -226,7 +235,7 @@ internal class Remapper
/// </summary>
private void WriteAssembly()
{
var filename = Path.GetFileNameWithoutExtension(DataProvider.AppSettings.AssemblyPath);
var filename = Path.GetFileNameWithoutExtension(DataProvider.Settings.RemapperSettings.AssemblyPath);
var strippedPath = Path.GetDirectoryName(filename);
filename = $"{filename}-Remapped.dll";

View File

@ -15,7 +15,7 @@ internal static class DataProvider
public static Dictionary<string, HashSet<ScoringModel>> ScoringModels { get; set; } = [];
public static AppSettings AppSettings { get; private set; }
public static Settings Settings { get; private set; }
public static AssemblyDefinition AssemblyDefinition { get; private set; }
@ -37,17 +37,17 @@ internal static class DataProvider
NullValueHandling = NullValueHandling.Ignore
};
AppSettings = JsonConvert.DeserializeObject<AppSettings>(jsonText, settings);
Settings = JsonConvert.DeserializeObject<Settings>(jsonText, settings);
}
public static void LoadMappingFile()
{
if (!File.Exists(AppSettings.MappingPath))
if (!File.Exists(Settings.RemapperSettings.MappingPath))
{
throw new InvalidOperationException($"path `{AppSettings.MappingPath}` does not exist...");
throw new InvalidOperationException($"path `{Settings.RemapperSettings.MappingPath}` does not exist...");
}
var jsonText = File.ReadAllText(AppSettings.MappingPath);
var jsonText = File.ReadAllText(Settings.RemapperSettings.MappingPath);
Remaps = [];
ScoringModels = [];
@ -70,9 +70,9 @@ internal static class DataProvider
public static void UpdateMapping()
{
if (!File.Exists(AppSettings.MappingPath))
if (!File.Exists(Settings.RemapperSettings.MappingPath))
{
throw new InvalidOperationException($"path `{AppSettings.MappingPath}` does not exist...");
throw new InvalidOperationException($"path `{Settings.RemapperSettings.MappingPath}` does not exist...");
}
JsonSerializerSettings settings = new JsonSerializerSettings
@ -100,23 +100,23 @@ internal static class DataProvider
var jsonText = JsonConvert.SerializeObject(Remaps, settings);
File.WriteAllText(AppSettings.MappingPath, jsonText);
File.WriteAllText(Settings.RemapperSettings.MappingPath, jsonText);
}
public static void LoadAssemblyDefinition()
{
DefaultAssemblyResolver resolver = new();
resolver.AddSearchDirectory(Path.GetDirectoryName(AppSettings.AssemblyPath)); // Replace with the correct path
resolver.AddSearchDirectory(Path.GetDirectoryName(Settings.RemapperSettings.AssemblyPath)); // Replace with the correct path
ReaderParameters parameters = new() { AssemblyResolver = resolver };
AssemblyDefinition = AssemblyDefinition.ReadAssembly(AppSettings.AssemblyPath, parameters);
AssemblyDefinition = AssemblyDefinition.ReadAssembly(Settings.RemapperSettings.AssemblyPath, parameters);
if (AssemblyDefinition is null)
{
throw new InvalidOperationException("AssemblyDefinition was null...");
}
var fileName = Path.GetFileName(AppSettings.AssemblyPath);
var fileName = Path.GetFileName(Settings.RemapperSettings.AssemblyPath);
foreach (var module in AssemblyDefinition.Modules.ToArray())
{

View File

@ -44,7 +44,7 @@ internal static class Logger
return;
}
if (DataProvider.AppSettings.Debug)
if (DataProvider.Settings.AppSettings.Debug)
{
Console.ForegroundColor = color;
Console.WriteLine(message);

View File

@ -1,14 +1,19 @@
{
"AppSettings": {
"Debug": false, // Enables extra debug logging, slows down the program by alot
"SilentMode": true // The tool will stop and prompt you to continue on every remapping if disabled
"Debug": false, // Enables extra debug logging, slows down the program by alot
"SilentMode": true, // The tool will stop and prompt you to continue on every remapping if disabled
"MatchMode": false // The assembly will not be written back to disk used only to score mappings
},
"Remapper": {
"MaxMatchCount": 5, // Max matches the remapper will return
"Publicize": true, // Publicize all types, methods, and properties : NOTE: Not run until after the remap has completed
"Unseal": true, // Unseal all types : NOTE: Not run until after the remap has completed
"AssemblyPath": "./Data/Managed/Assembly-CSharp.dll", // Path to the assembly we want to remap
"OutputPath": "./Data/Assembly-CSharp-Remapped.dll", // Path including the filename and extension we want to write the changes to
"MappingPath": "./Data/Mappings.jsonc" // Path to the mapping file
"MaxMatchCount": 5, // Max matches the remapper will return
"Publicize": true, // Publicize all types, methods, and properties : NOTE: Not run until after the remap has completed
"Unseal": true, // Unseal all types : NOTE: Not run until after the remap has completed
"AssemblyPath": "./Data/Managed/Assembly-CSharp.dll", // Path to the assembly we want to remap
"OutputPath": "./Data/Assembly-CSharp-Remapped.dll", // Path including the filename and extension we want to write the changes to
"MappingPath": "./Data/Mappings.jsonc" // Path to the mapping file
},
"AutoMapper": {
"Publicize": true, // Publicize all types, methods, and properties : NOTE: Not run until after the remap has completed
"Unseal": true, // Unseal all types : NOTE: Not run until after the remap has completed
}
}