Config changes
This commit is contained in:
parent
8284605d04
commit
e235b27d99
@ -3,16 +3,35 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remap config
|
/// Remap config
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
internal class Settings
|
||||||
|
{
|
||||||
|
public AppSettings AppSettings { get; set; }
|
||||||
|
public RemapperSettings RemapperSettings { get; set; }
|
||||||
|
|
||||||
|
public AutoMapperSettings AutoMapperSettings { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
internal class AppSettings
|
internal class AppSettings
|
||||||
{
|
{
|
||||||
public bool Debug { get; set; }
|
public bool Debug { get; set; } = false;
|
||||||
public bool SilentMode { get; set; }
|
public bool SilentMode { get; set; } = true;
|
||||||
public int MaxMatchCount { get; set; }
|
public bool MatchMode { get; set; } = false;
|
||||||
public bool ScoringMode { get; set; }
|
}
|
||||||
public bool Publicize { get; set; }
|
|
||||||
public bool Unseal { get; set; }
|
internal class RemapperSettings
|
||||||
|
{
|
||||||
public string AssemblyPath { get; set; }
|
public int MaxMatchCount { get; set; } = 5;
|
||||||
public string OutputPath { get; set; }
|
|
||||||
public string MappingPath { get; set; }
|
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;
|
||||||
}
|
}
|
@ -6,8 +6,6 @@ internal static class Publicizer
|
|||||||
{
|
{
|
||||||
public static void Publicize()
|
public static void Publicize()
|
||||||
{
|
{
|
||||||
if (!DataProvider.AppSettings.Publicize) { return; }
|
|
||||||
|
|
||||||
Logger.Log("Starting publicization...", ConsoleColor.Green);
|
Logger.Log("Starting publicization...", ConsoleColor.Green);
|
||||||
|
|
||||||
foreach (var type in DataProvider.ModuleDefinition.Types)
|
foreach (var type in DataProvider.ModuleDefinition.Types)
|
||||||
@ -44,8 +42,6 @@ internal static class Publicizer
|
|||||||
|
|
||||||
public static void Unseal()
|
public static void Unseal()
|
||||||
{
|
{
|
||||||
if (!DataProvider.AppSettings.Unseal) { return; }
|
|
||||||
|
|
||||||
Logger.Log("Starting unseal...", ConsoleColor.Green);
|
Logger.Log("Starting unseal...", ConsoleColor.Green);
|
||||||
|
|
||||||
foreach (var type in DataProvider.ModuleDefinition.Types)
|
foreach (var type in DataProvider.ModuleDefinition.Types)
|
||||||
|
@ -29,11 +29,18 @@ internal class Remapper
|
|||||||
|
|
||||||
ChooseBestMatches();
|
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
|
// Dont publicize and unseal until after the remapping so we can use those as search parameters
|
||||||
Publicizer.Publicize();
|
if (!DataProvider.Settings.RemapperSettings.Publicize)
|
||||||
Publicizer.Unseal();
|
{
|
||||||
|
Publicizer.Publicize();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DataProvider.Settings.RemapperSettings.Unseal)
|
||||||
|
{
|
||||||
|
Publicizer.Unseal();
|
||||||
|
}
|
||||||
|
|
||||||
// We are done, write the assembly
|
// We are done, write the assembly
|
||||||
WriteAssembly();
|
WriteAssembly();
|
||||||
@ -47,8 +54,8 @@ internal class Remapper
|
|||||||
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
|
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
|
||||||
Logger.Log($"Starting remap...", ConsoleColor.Yellow);
|
Logger.Log($"Starting remap...", ConsoleColor.Yellow);
|
||||||
Logger.Log($"Module contains {DataProvider.ModuleDefinition.Types.Count} Types", ConsoleColor.Yellow);
|
Logger.Log($"Module contains {DataProvider.ModuleDefinition.Types.Count} Types", ConsoleColor.Yellow);
|
||||||
Logger.Log($"Publicize: {DataProvider.AppSettings.Publicize}", ConsoleColor.Yellow);
|
Logger.Log($"Publicize: {DataProvider.Settings.RemapperSettings.Publicize}", ConsoleColor.Yellow);
|
||||||
Logger.Log($"Unseal: {DataProvider.AppSettings.Unseal}", ConsoleColor.Yellow);
|
Logger.Log($"Unseal: {DataProvider.Settings.RemapperSettings.Unseal}", ConsoleColor.Yellow);
|
||||||
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
|
Logger.Log("-----------------------------------------------", ConsoleColor.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +199,7 @@ internal class Remapper
|
|||||||
|
|
||||||
var filteredScores = scores
|
var filteredScores = scores
|
||||||
.OrderByDescending(score => score.Score)
|
.OrderByDescending(score => score.Score)
|
||||||
.Take(DataProvider.AppSettings.MaxMatchCount);
|
.Take(DataProvider.Settings.RemapperSettings.MaxMatchCount);
|
||||||
|
|
||||||
var highestScore = filteredScores.FirstOrDefault();
|
var highestScore = filteredScores.FirstOrDefault();
|
||||||
|
|
||||||
@ -213,6 +220,8 @@ internal class Remapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DataProvider.Settings.AppSettings.MatchMode) { return; }
|
||||||
|
|
||||||
highestScore.ReMap.OriginalTypeName = highestScore.Definition.Name;
|
highestScore.ReMap.OriginalTypeName = highestScore.Definition.Name;
|
||||||
|
|
||||||
// Rename type and all associated type members
|
// Rename type and all associated type members
|
||||||
@ -226,7 +235,7 @@ internal class Remapper
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void WriteAssembly()
|
private void WriteAssembly()
|
||||||
{
|
{
|
||||||
var filename = Path.GetFileNameWithoutExtension(DataProvider.AppSettings.AssemblyPath);
|
var filename = Path.GetFileNameWithoutExtension(DataProvider.Settings.RemapperSettings.AssemblyPath);
|
||||||
var strippedPath = Path.GetDirectoryName(filename);
|
var strippedPath = Path.GetDirectoryName(filename);
|
||||||
|
|
||||||
filename = $"{filename}-Remapped.dll";
|
filename = $"{filename}-Remapped.dll";
|
||||||
|
@ -15,7 +15,7 @@ internal static class DataProvider
|
|||||||
|
|
||||||
public static Dictionary<string, HashSet<ScoringModel>> ScoringModels { get; set; } = [];
|
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; }
|
public static AssemblyDefinition AssemblyDefinition { get; private set; }
|
||||||
|
|
||||||
@ -37,17 +37,17 @@ internal static class DataProvider
|
|||||||
NullValueHandling = NullValueHandling.Ignore
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
};
|
};
|
||||||
|
|
||||||
AppSettings = JsonConvert.DeserializeObject<AppSettings>(jsonText, settings);
|
Settings = JsonConvert.DeserializeObject<Settings>(jsonText, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadMappingFile()
|
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 = [];
|
Remaps = [];
|
||||||
ScoringModels = [];
|
ScoringModels = [];
|
||||||
@ -70,9 +70,9 @@ internal static class DataProvider
|
|||||||
|
|
||||||
public static void UpdateMapping()
|
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
|
JsonSerializerSettings settings = new JsonSerializerSettings
|
||||||
@ -100,23 +100,23 @@ internal static class DataProvider
|
|||||||
|
|
||||||
var jsonText = JsonConvert.SerializeObject(Remaps, settings);
|
var jsonText = JsonConvert.SerializeObject(Remaps, settings);
|
||||||
|
|
||||||
File.WriteAllText(AppSettings.MappingPath, jsonText);
|
File.WriteAllText(Settings.RemapperSettings.MappingPath, jsonText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadAssemblyDefinition()
|
public static void LoadAssemblyDefinition()
|
||||||
{
|
{
|
||||||
DefaultAssemblyResolver resolver = new();
|
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 };
|
ReaderParameters parameters = new() { AssemblyResolver = resolver };
|
||||||
|
|
||||||
AssemblyDefinition = AssemblyDefinition.ReadAssembly(AppSettings.AssemblyPath, parameters);
|
AssemblyDefinition = AssemblyDefinition.ReadAssembly(Settings.RemapperSettings.AssemblyPath, parameters);
|
||||||
|
|
||||||
if (AssemblyDefinition is null)
|
if (AssemblyDefinition is null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("AssemblyDefinition was 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())
|
foreach (var module in AssemblyDefinition.Modules.ToArray())
|
||||||
{
|
{
|
||||||
|
@ -44,7 +44,7 @@ internal static class Logger
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DataProvider.AppSettings.Debug)
|
if (DataProvider.Settings.AppSettings.Debug)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = color;
|
Console.ForegroundColor = color;
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
{
|
{
|
||||||
"AppSettings": {
|
"AppSettings": {
|
||||||
"Debug": false, // Enables extra debug logging, slows down the program by alot
|
"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
|
"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": {
|
"Remapper": {
|
||||||
"MaxMatchCount": 5, // Max matches the remapper will return
|
"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
|
"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
|
"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
|
"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
|
"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
|
"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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user