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

Fix a bunch of compiler warnings

This commit is contained in:
Cj 2024-12-31 03:13:29 -05:00
parent c4d81ce4ba
commit 3de6be24ce
12 changed files with 97 additions and 170 deletions

View File

@ -818,7 +818,7 @@ public partial class ReCodeItForm : Form
AutoMapperFPBox.Items.Add(fp); AutoMapperFPBox.Items.Add(fp);
} }
foreach (var mp in settings.MethodParamaterBlackList) foreach (var mp in settings.MethodParameterBlackList)
{ {
AutoMapperMethodBox.Items.Add(mp); AutoMapperMethodBox.Items.Add(mp);
} }
@ -908,7 +908,7 @@ public partial class ReCodeItForm : Form
{ {
AutoMapperMethodBox.Items.Add(AutoMapperMethodTextBox.Text); AutoMapperMethodBox.Items.Add(AutoMapperMethodTextBox.Text);
AppSettings.AutoMapper.MethodParamaterBlackList.Add(AutoMapperMethodTextBox.Text); AppSettings.AutoMapper.MethodParameterBlackList.Add(AutoMapperMethodTextBox.Text);
DataProvider.SaveAppSettings(); DataProvider.SaveAppSettings();
AutoMapperMethodTextBox.Clear(); AutoMapperMethodTextBox.Clear();
@ -919,7 +919,7 @@ public partial class ReCodeItForm : Form
{ {
if (AutoMapperMethodBox.SelectedItem != null) if (AutoMapperMethodBox.SelectedItem != null)
{ {
AppSettings.AutoMapper.MethodParamaterBlackList AppSettings.AutoMapper.MethodParameterBlackList
.RemoveAt(AutoMapperMethodBox.SelectedIndex); .RemoveAt(AutoMapperMethodBox.SelectedIndex);
AutoMapperMethodBox.Items AutoMapperMethodBox.Items

View File

@ -225,8 +225,8 @@ public class DumperClass
// as of 01/11/24 firstMethod returns true, so its now only 2 instructions, was 55 (this may change, BSG have byppassed their own SSL checks atm) // as of 01/11/24 firstMethod returns true, so its now only 2 instructions, was 55 (this may change, BSG have byppassed their own SSL checks atm)
if (firstMethod?.Body.Instructions.Count != 2 || secondMethod?.Body.Instructions.Count != 14) if (firstMethod?.Body.Instructions.Count != 2 || secondMethod?.Body.Instructions.Count != 14)
{ {
Logger.Log($"Instruction count has changed, method with 'certificate' as a param - before: 51, now: {firstMethod.Body.Instructions.Count}, " + Logger.Log($"Instruction count has changed, method with 'certificate' as a param - before: 51, now: {firstMethod?.Body.Instructions.Count}, " +
$"method with 'certificateData' as a param - before: 14, now: {secondMethod.Body.Instructions.Count}", ConsoleColor.Red); $"method with 'certificateData' as a param - before: 14, now: {secondMethod?.Body.Instructions.Count}", ConsoleColor.Red);
} }
if (methods.Count() != 2) if (methods.Count() != 2)
@ -266,41 +266,41 @@ public class DumperClass
if (method == null || method.Body.Instructions.Count != 23) if (method == null || method.Body.Instructions.Count != 23)
{ {
Logger.Log($"RunValidation Instructions count has changed from 23 to {method.Body.Instructions.Count}"); Logger.Log($"RunValidation Instructions count has changed from 23 to {method?.Body.Instructions.Count}");
} }
if (method2 == null || method2.Body.Instructions.Count != 171) if (method2 == null || method2.Body.Instructions.Count != 171)
{ {
Logger.Log($"RunValidation's MoveNext Instructions count has changed from 171 to {method2.Body.Instructions.Count}"); Logger.Log($"RunValidation's MoveNext Instructions count has changed from 171 to {method2?.Body.Instructions.Count}");
} }
// Clear these from the body of each method respectively // Clear these from the body of each method respectively
method.Body.Instructions.Clear(); method?.Body.Instructions.Clear();
method2.Body.Instructions.Clear(); method2?.Body.Instructions.Clear();
method2.Body.Variables.Clear(); method2?.Body.Variables.Clear();
method2.Body.ExceptionHandlers.Clear(); method2?.Body.ExceptionHandlers.Clear();
var liList = DumpyILHelper.GetRunValidationInstructions(method, _gameModule, _msModule, _gameImporter); var liList = DumpyILHelper.GetRunValidationInstructions(method!, _gameModule!, _msModule!, _gameImporter);
var liList2 = DumpyILHelper.GetRunValidationInstructionsMoveNext(method2, _gameModule, _msModule, _gameImporter); var liList2 = DumpyILHelper.GetRunValidationInstructionsMoveNext(method2!, _gameModule!, _msModule!, _gameImporter);
foreach (var instruction in liList) foreach (var instruction in liList)
{ {
method.Body.Instructions.Add(instruction); method?.Body.Instructions.Add(instruction);
} }
foreach (var instruction in liList2) foreach (var instruction in liList2)
{ {
method2.Body.Instructions.Add(instruction); method2?.Body.Instructions.Add(instruction);
} }
var ins = Instruction.Create(OpCodes.Leave_S, method2.Body.Instructions[14]); // Create instruction to jump to index 14 var ins = Instruction.Create(OpCodes.Leave_S, method2?.Body.Instructions[14]); // Create instruction to jump to index 14
var ins1 = Instruction.Create(OpCodes.Leave_S, method2.Body.Instructions.Last()); // Create instruction to jump to last index var ins1 = Instruction.Create(OpCodes.Leave_S, method2?.Body.Instructions.Last()); // Create instruction to jump to last index
method2.Body.Instructions.InsertAfter(method2.Body.Instructions[5], ins); // Instruction to jump from 5 to 14 method2?.Body.Instructions.InsertAfter(method2.Body.Instructions[5], ins); // Instruction to jump from 5 to 14
method2.Body.Instructions.InsertAfter(method2.Body.Instructions[14], ins1); // Instruction to jump from 14 to last index method2?.Body.Instructions.InsertAfter(method2.Body.Instructions[14], ins1); // Instruction to jump from 14 to last index
// Add exception handler to method body // Add exception handler to method body
method2.Body.ExceptionHandlers.Add(DumpyILHelper.GetExceptionHandler(method2, _gameImporter, _msModule)); method2?.Body.ExceptionHandlers.Add(DumpyILHelper.GetExceptionHandler(method2, _gameImporter, _msModule!));
} }
private void SetDumpyTaskCode(TypeDef type) private void SetDumpyTaskCode(TypeDef type)
@ -312,13 +312,13 @@ public class DumperClass
Logger.Log($"MainMenu is null or isnt 62 instructions, SOMETHING HAD CHANGED!", ConsoleColor.Red); Logger.Log($"MainMenu is null or isnt 62 instructions, SOMETHING HAD CHANGED!", ConsoleColor.Red);
} }
var liList = DumpyILHelper.GetDumpyTaskInstructions(method,_dumpModule, _gameImporter); var liList = DumpyILHelper.GetDumpyTaskInstructions(method!,_dumpModule!, _gameImporter);
var index = method.Body.Instructions.First(x => x.OpCode == OpCodes.Ret); var index = method?.Body.Instructions.First(x => x.OpCode == OpCodes.Ret);
foreach (var item in liList) foreach (var item in liList)
{ {
method.Body.Instructions.InsertBefore(index, item); method?.Body.Instructions.InsertBefore(index!, item);
} }
} }
@ -335,19 +335,19 @@ public class DumperClass
if (method == null || method.Body.Instructions.Count != 152) if (method == null || method.Body.Instructions.Count != 152)
{ {
Logger.Log($"EnsureConsistency Instructions count has changed from 152 to {method.Body.Instructions.Count}", ConsoleColor.Red); Logger.Log($"EnsureConsistency Instructions count has changed from 152 to {method?.Body.Instructions.Count}", ConsoleColor.Red);
} }
// clear these from the method body // clear these from the method body
method.Body.Instructions.Clear(); method?.Body.Instructions.Clear();
method.Body.Variables.Clear(); method?.Body.Variables.Clear();
method.Body.ExceptionHandlers.Clear(); method?.Body.ExceptionHandlers.Clear();
var liList = DumpyILHelper.GetEnsureConsistencyInstructions(method, _checkerModule, _msModule, _checkImporter); var liList = DumpyILHelper.GetEnsureConsistencyInstructions(method!, _checkerModule!, _msModule!, _checkImporter);
foreach (var li in liList) foreach (var li in liList)
{ {
method.Body.Instructions.Add(li); method?.Body.Instructions.Add(li);
} }
} }
@ -364,19 +364,19 @@ public class DumperClass
if (method == null || method.Body.Instructions.Count != 101) if (method == null || method.Body.Instructions.Count != 101)
{ {
Logger.Log($"EnsureConsistencySingle Instructions count has changed from 101 to {method.Body.Instructions.Count}", ConsoleColor.Red); Logger.Log($"EnsureConsistencySingle Instructions count has changed from 101 to {method?.Body.Instructions.Count}", ConsoleColor.Red);
} }
// clear these from the method body // clear these from the method body
method.Body.Instructions.Clear(); method?.Body.Instructions.Clear();
method.Body.Variables.Clear(); method?.Body.Variables.Clear();
method.Body.ExceptionHandlers.Clear(); method?.Body.ExceptionHandlers.Clear();
var liList = DumpyILHelper.GetEnsureConsistencyInstructions(method, _checkerModule, _msModule, _checkImporter); var liList = DumpyILHelper.GetEnsureConsistencyInstructions(method!, _checkerModule!, _msModule!, _checkImporter);
foreach (var li in liList) foreach (var li in liList)
{ {
method.Body.Instructions.Add(li); method?.Body.Instructions.Add(li);
} }
} }
} }

View File

@ -7,9 +7,9 @@ namespace ReCodeIt.Models;
/// </summary> /// </summary>
public class Settings public class Settings
{ {
private AppSettings _appSettings; private AppSettings? _appSettings;
public AppSettings AppSettings public AppSettings? AppSettings
{ {
get { return _appSettings; } get { return _appSettings; }
set set
@ -19,9 +19,9 @@ public class Settings
} }
} }
private RemapperSettings _remapper; private RemapperSettings? _remapper;
public RemapperSettings Remapper public RemapperSettings? Remapper
{ {
get { return _remapper; } get { return _remapper; }
set set
@ -31,9 +31,9 @@ public class Settings
} }
} }
private AutoMapperSettings _autoMapper; private AutoMapperSettings? _autoMapper;
public AutoMapperSettings AutoMapper public AutoMapperSettings? AutoMapper
{ {
get { return _autoMapper; } get { return _autoMapper; }
set set
@ -89,7 +89,7 @@ public class AppSettings
/// </summary> /// </summary>
public class RemapperSettings public class RemapperSettings
{ {
private string _assemblyPath; private string _assemblyPath = string.Empty;
/// <summary> /// <summary>
/// Path to the assembly we want to remap /// Path to the assembly we want to remap
@ -104,7 +104,7 @@ public class RemapperSettings
} }
} }
private string _outputPath; private string _outputPath = string.Empty;
/// <summary> /// <summary>
/// Path including the filename and extension we want to write the changes to /// Path including the filename and extension we want to write the changes to
@ -119,7 +119,7 @@ public class RemapperSettings
} }
} }
private string _mappingPath; private string _mappingPath = string.Empty;
/// <summary> /// <summary>
/// Path to the mapping file /// Path to the mapping file
@ -149,9 +149,9 @@ public class RemapperSettings
} }
} }
private MappingSettings _mappingSettings; private MappingSettings? _mappingSettings;
public MappingSettings MappingSettings public MappingSettings? MappingSettings
{ {
get { return _mappingSettings; } get { return _mappingSettings; }
set set
@ -172,7 +172,7 @@ public class RemapperSettings
/// </summary> /// </summary>
public class AutoMapperSettings public class AutoMapperSettings
{ {
private string _assemblyPath; private string _assemblyPath = string.Empty;
/// <summary> /// <summary>
/// Path to the assembly we want to remap /// Path to the assembly we want to remap
@ -187,7 +187,7 @@ public class AutoMapperSettings
} }
} }
private string _outputPath; private string _outputPath = string.Empty;
/// <summary> /// <summary>
/// Path including the filename and extension we want to write the changes to /// Path including the filename and extension we want to write the changes to
@ -248,9 +248,9 @@ public class AutoMapperSettings
} }
} }
private MappingSettings _mappingSettings; private MappingSettings? _mappingSettings;
public MappingSettings MappingSettings public MappingSettings? MappingSettings
{ {
get { return _mappingSettings; } get { return _mappingSettings; }
set set
@ -260,7 +260,7 @@ public class AutoMapperSettings
} }
} }
private List<string> _typesToIgnore; private List<string> _typesToIgnore = [];
/// <summary> /// <summary>
/// Any member name you want to ignore while iterating through the assembly /// Any member name you want to ignore while iterating through the assembly
@ -275,7 +275,7 @@ public class AutoMapperSettings
} }
} }
private List<string> _tokensToMatch; private List<string> _tokensToMatch = [];
/// <summary> /// <summary>
/// The auto mapper will look for these tokens in class names and prioritize those /// The auto mapper will look for these tokens in class names and prioritize those
@ -290,7 +290,7 @@ public class AutoMapperSettings
} }
} }
private List<string> _propertyFieldBlacklist; private List<string> _propertyFieldBlacklist = [];
/// <summary> /// <summary>
/// Property or fields names to ignore in the automap, these are case sanitized so case does not matter /// Property or fields names to ignore in the automap, these are case sanitized so case does not matter
@ -305,17 +305,17 @@ public class AutoMapperSettings
} }
} }
private List<string> _methodParamaterBlackList; private List<string> _methodParameterBlackList = [];
/// <summary> /// <summary>
/// method parameter names to ignore in the automap, these are case sanitized so case does not matter /// method parameter names to ignore in the automap, these are case sanitized so case does not matter
/// </summary> /// </summary>
public List<string> MethodParamaterBlackList public List<string> MethodParameterBlackList
{ {
get { return _methodParamaterBlackList; } get { return _methodParameterBlackList; }
set set
{ {
_methodParamaterBlackList = value; _methodParameterBlackList = value;
Save(); Save();
} }
} }

View File

@ -1,71 +0,0 @@
namespace ReCodeIt.Models;
public class CrossCompilerProjectModel
{
#region REQUIRED_ON_CREATION
/// <summary>
/// The path of the original assembly
///
/// (Required on creation)
/// </summary>
public string OriginalAssemblyPath { get; set; }
/// <summary>
/// The path to the working directory vs project
///
/// (Required on creation)
/// </summary>
public string VisualStudioSolutionPath { get; set; }
/// <summary>
/// The path to the dependency folder for the active solution. Also where the remapped dll is
/// built to and replaced
///
/// (Required on creation)
/// </summary>
public string VisualStudioDependencyPath { get; set; }
/// <summary>
/// This is where the final dll is built to
///
/// (Required on creation)
/// </summary>
public string BuildDirectory { get; set; }
#endregion REQUIRED_ON_CREATION
/// <summary>
/// The path to the working directory vs project
/// </summary>
public string VisualStudioSolutionDirectoryPath => Path.GetDirectoryName(VisualStudioSolutionPath)!;
public string ProjectDllName => SolutionName.Replace(".sln", ".dll");
public string OriginalAssemblyDllName => Path.GetFileName(OriginalAssemblyPath);
/// <summary>
/// Name of the solution
/// </summary>
public string SolutionName => Path.GetFileName(VisualStudioSolutionPath);
/// <summary>
/// Remapped output hash
/// </summary>
public string OriginalAssemblyHash { get; set; }
/// <summary>
/// Remapped output hash
/// </summary>
public string RemappedAssemblyHash { get; set; }
/// <summary>
/// Key: Remapped name, value: old name
/// </summary>
public Dictionary<string, string> ChangedTypes { get; set; } = [];
/// <summary>
/// Remap models used on this project
/// </summary>
public List<RemapModel> RemapModels { get; set; } = [];
}

View File

@ -2,8 +2,8 @@
public class ItemTemplateModel public class ItemTemplateModel
{ {
public string _id; public string? _id;
public string _name; public string? _name;
public string _parent; public string? _parent;
public string _type; public string? _type;
} }

View File

@ -27,7 +27,7 @@ public class RemapModel
/// This is the final chosen type we will use to remap /// This is the final chosen type we will use to remap
/// </summary> /// </summary>
[JsonIgnore] [JsonIgnore]
public TypeDef TypePrimeCandidate { get; set; } public TypeDef? TypePrimeCandidate { get; set; }
public string NewTypeName { get; set; } = string.Empty; public string NewTypeName { get; set; } = string.Empty;

View File

@ -60,7 +60,6 @@ public static class Deobfuscator
: $"--un-name \"!^<>[a-z0-9]$&!^<>[a-z0-9]__.*$&![A-Z][A-Z]\\$<>.*$&^[a-zA-Z_<{{$][a-zA-Z_0-9<>{{}}$.`-]*$\" \"{assemblyPath}\" --strtyp delegate --strtok \"{token}\""; : $"--un-name \"!^<>[a-z0-9]$&!^<>[a-z0-9]__.*$&![A-Z][A-Z]\\$<>.*$&^[a-zA-Z_<{{$][a-zA-Z_0-9<>{{}}$.`-]*$\" \"{assemblyPath}\" --strtyp delegate --strtok \"{token}\"";
var executablePath = Path.Combine(AppContext.BaseDirectory, "de4dot", "de4dot-x64.exe"); var executablePath = Path.Combine(AppContext.BaseDirectory, "de4dot", "de4dot-x64.exe");
var two = 2;
var process = Process.Start(executablePath, cmd); var process = Process.Start(executablePath, cmd);
process.WaitForExit(); process.WaitForExit();

View File

@ -5,12 +5,14 @@ namespace ReCodeIt.ReMapper;
internal static class SPTPublicizer internal static class SPTPublicizer
{ {
private static ModuleDefMD MainModule; private static ModuleDefMD? MainModule;
public static void PublicizeClasses(ModuleDefMD definition, bool isLauncher = false) public static void PublicizeClasses(ModuleDefMD definition, bool isLauncher = false)
{ {
var types = definition.GetTypes(); var types = definition.GetTypes();
MainModule = definition;
foreach (var type in types) foreach (var type in types)
{ {
if (type.IsNested) continue; // Nested types are handled when publicizing the parent type if (type.IsNested) continue; // Nested types are handled when publicizing the parent type
@ -124,7 +126,7 @@ internal static class SPTPublicizer
if (type.BaseType != null && !type.BaseType.Name.Contains("Object")) if (type.BaseType != null && !type.BaseType.Name.Contains("Object"))
{ {
var baseTypeDefinition = MainModule?.Find(type.BaseType).ResolveTypeDef(); var baseTypeDefinition = MainModule?.Find(type.BaseType).ResolveTypeDef();
var baseTypeInterfaces = GetFlattenedInterfacesRecursive(baseTypeDefinition); var baseTypeInterfaces = GetFlattenedInterfacesRecursive(baseTypeDefinition!);
if (baseTypeInterfaces.Any()) if (baseTypeInterfaces.Any())
{ {

View File

@ -26,7 +26,7 @@ public class ReCodeItRemapper
private static readonly Stopwatch Stopwatch = new(); private static readonly Stopwatch Stopwatch = new();
private RemapperSettings Settings => DataProvider.Settings.Remapper; private RemapperSettings? Settings => DataProvider.Settings?.Remapper;
private string OutPath { get; set; } = string.Empty; private string OutPath { get; set; } = string.Empty;
@ -71,7 +71,7 @@ public class ReCodeItRemapper
cleanedName = $"{cleanedName}-cleaned.dll"; cleanedName = $"{cleanedName}-cleaned.dll";
var newPath = Path.GetDirectoryName(assemblyPath); var newPath = Path.GetDirectoryName(assemblyPath);
newPath = Path.Combine(newPath, cleanedName); newPath = Path.Combine(newPath!, cleanedName);
Console.WriteLine($"Cleaning assembly: {newPath}"); Console.WriteLine($"Cleaning assembly: {newPath}");
@ -119,7 +119,7 @@ public class ReCodeItRemapper
Task.WaitAll(renameTasks.ToArray()); Task.WaitAll(renameTasks.ToArray());
// Don't publicize and unseal until after the remapping, so we can use those as search parameters // Don't publicize and unseal until after the remapping, so we can use those as search parameters
if (Settings.MappingSettings.Publicize) if (Settings!.MappingSettings!.Publicize)
{ {
Logger.Log("Publicizing classes...", ConsoleColor.Yellow); Logger.Log("Publicizing classes...", ConsoleColor.Yellow);
@ -160,7 +160,7 @@ public class ReCodeItRemapper
/// <param name="mapping">Mapping to score</param> /// <param name="mapping">Mapping to score</param>
private void ScoreMapping(RemapModel mapping, IEnumerable<TypeDef> types) private void ScoreMapping(RemapModel mapping, IEnumerable<TypeDef> types)
{ {
var tokens = DataProvider.Settings.AutoMapper.TokensToMatch; var tokens = DataProvider.Settings?.AutoMapper?.TokensToMatch;
if (mapping.UseForceRename) if (mapping.UseForceRename)
{ {
@ -171,7 +171,7 @@ public class ReCodeItRemapper
// Filter down nested objects // Filter down nested objects
if (mapping.SearchParams.IsNested is false or null) if (mapping.SearchParams.IsNested is false or null)
{ {
types = types.Where(type => tokens.Any(token => type.Name.StartsWith(token))); types = types.Where(type => tokens!.Any(token => type.Name.StartsWith(token)));
} }
// Run through a series of filters and report an error if all types are filtered out. // Run through a series of filters and report an error if all types are filtered out.
@ -477,13 +477,13 @@ public class ReCodeItRemapper
.GetField("TypeTable") .GetField("TypeTable")
.GetValue(templateMappingClass); .GetValue(templateMappingClass);
BuildAssociationFromTable(typeTable, "ItemClass"); BuildAssociationFromTable(typeTable!, "ItemClass");
var templateTypeTable = (Dictionary<string, Type>)templateMappingClass var templateTypeTable = (Dictionary<string, Type>)templateMappingClass
.GetField("TemplateTypeTable") .GetField("TemplateTypeTable")
.GetValue(templateMappingClass); .GetValue(templateMappingClass);
BuildAssociationFromTable(templateTypeTable, "TemplateClass"); BuildAssociationFromTable(templateTypeTable!, "TemplateClass");
} }
private void BuildAssociationFromTable(Dictionary<string, Type> table, string extName) private void BuildAssociationFromTable(Dictionary<string, Type> table, string extName)
@ -558,18 +558,18 @@ public class ReCodeItRemapper
/// </summary> /// </summary>
private void WriteAssembly() private void WriteAssembly()
{ {
var moduleName = Module.Name; var moduleName = Module?.Name;
var dllName = "-cleaned-remapped.dll"; var dllName = "-cleaned-remapped.dll";
if (Settings.MappingSettings.Publicize) if (Settings!.MappingSettings!.Publicize)
{ {
dllName = "-cleaned-remapped-publicized.dll"; dllName = "-cleaned-remapped-publicized.dll";
} }
OutPath = Path.Combine(OutPath, moduleName.Replace(".dll", dllName)); OutPath = Path.Combine(OutPath, moduleName?.Replace(".dll", dllName));
try try
{ {
Module.Write(OutPath); Module!.Write(OutPath);
} }
catch (Exception e) catch (Exception e)
{ {
@ -581,7 +581,7 @@ public class ReCodeItRemapper
Hollow(); Hollow();
var hollowedDir = Path.GetDirectoryName(OutPath); var hollowedDir = Path.GetDirectoryName(OutPath);
var hollowedPath = Path.Combine(hollowedDir, "Assembly-CSharp-hollowed.dll"); var hollowedPath = Path.Combine(hollowedDir!, "Assembly-CSharp-hollowed.dll");
try try
{ {
@ -595,9 +595,9 @@ public class ReCodeItRemapper
DisplayEndBanner(hollowedPath); DisplayEndBanner(hollowedPath);
if (DataProvider.Settings.Remapper.MappingPath != string.Empty) if (DataProvider.Settings?.Remapper?.MappingPath != string.Empty)
{ {
DataProvider.UpdateMapping(DataProvider.Settings.Remapper.MappingPath.Replace("mappings.", "mappings-new."), _remaps); DataProvider.UpdateMapping(DataProvider.Settings!.Remapper!.MappingPath.Replace("mappings.", "mappings-new."), _remaps);
} }
Stopwatch.Reset(); Stopwatch.Reset();
@ -612,7 +612,7 @@ public class ReCodeItRemapper
/// </summary> /// </summary>
private void Hollow() private void Hollow()
{ {
foreach (var type in Module.GetTypes()) foreach (var type in Module!.GetTypes())
{ {
foreach (var method in type.Methods.Where(m => m.HasBody)) foreach (var method in type.Methods.Where(m => m.HasBody))
{ {

View File

@ -6,7 +6,7 @@ namespace ReCodeIt.ReMapper;
internal static class RenameHelper internal static class RenameHelper
{ {
private static List<string> TokensToMatch => DataProvider.Settings.AutoMapper.TokensToMatch; private static List<string>? TokensToMatch => DataProvider.Settings?.AutoMapper?.TokensToMatch;
/// <summary> /// <summary>
/// Only used by the manual remapper, should probably be removed /// Only used by the manual remapper, should probably be removed
@ -17,9 +17,9 @@ internal static class RenameHelper
public static void RenameAll(IEnumerable<TypeDef> types, RemapModel remap) public static void RenameAll(IEnumerable<TypeDef> types, RemapModel remap)
{ {
// Rename all fields and properties first // Rename all fields and properties first
if (DataProvider.Settings.Remapper.MappingSettings.RenameFields) if (DataProvider.Settings!.Remapper!.MappingSettings!.RenameFields)
{ {
if (remap.TypePrimeCandidate == null) if (remap.TypePrimeCandidate is null)
{ {
Logger.Log($"Unable to rename {remap.NewTypeName} as TypePrimeCandidate value is null/empty, skipping", ConsoleColor.Red); Logger.Log($"Unable to rename {remap.NewTypeName} as TypePrimeCandidate value is null/empty, skipping", ConsoleColor.Red);
return; return;
@ -34,7 +34,7 @@ internal static class RenameHelper
if (DataProvider.Settings.Remapper.MappingSettings.RenameProperties) if (DataProvider.Settings.Remapper.MappingSettings.RenameProperties)
{ {
RenameAllProperties( RenameAllProperties(
remap.TypePrimeCandidate.Name.String, remap!.TypePrimeCandidate!.Name.String,
remap.NewTypeName, remap.NewTypeName,
types); types);
} }
@ -42,7 +42,7 @@ internal static class RenameHelper
FixMethods(types, remap); FixMethods(types, remap);
RenameType(types, remap); RenameType(types, remap);
//Logger.Log($"{remap.TypePrimeCandidate.Name.String} Renamed.", ConsoleColor.Green); Logger.Log($"{remap!.TypePrimeCandidate!.Name.String} Renamed.", ConsoleColor.Green);
} }
private static void FixMethods( private static void FixMethods(
@ -52,7 +52,7 @@ internal static class RenameHelper
foreach (var type in typesToCheck) foreach (var type in typesToCheck)
{ {
var methods = type.Methods var methods = type.Methods
.Where(method => method.Name.StartsWith(remap.TypePrimeCandidate.Name.String)); .Where(method => method.Name.StartsWith(remap!.TypePrimeCandidate!.Name.String));
foreach (var method in methods) foreach (var method in methods)
{ {
@ -68,8 +68,7 @@ internal static class RenameHelper
/// <param name="oldTypeName"></param> /// <param name="oldTypeName"></param>
/// <param name="newTypeName"></param> /// <param name="newTypeName"></param>
/// <param name="typesToCheck"></param> /// <param name="typesToCheck"></param>
/// <returns></returns> private static void RenameAllFields(
public static IEnumerable<TypeDef> RenameAllFields(
string oldTypeName, string oldTypeName,
string newTypeName, string newTypeName,
@ -78,7 +77,7 @@ internal static class RenameHelper
foreach (var type in typesToCheck) foreach (var type in typesToCheck)
{ {
var fields = type.Fields var fields = type.Fields
.Where(field => field.Name.IsFieldOrPropNameInList(TokensToMatch)); .Where(field => field.Name.IsFieldOrPropNameInList(TokensToMatch!));
if (!fields.Any()) { continue; } if (!fields.Any()) { continue; }
@ -103,8 +102,6 @@ internal static class RenameHelper
} }
} }
} }
return typesToCheck;
} }
private static void UpdateAllTypeFieldMemberRefs(IEnumerable<TypeDef> typesToCheck, FieldDef newDef, string oldName) private static void UpdateAllTypeFieldMemberRefs(IEnumerable<TypeDef> typesToCheck, FieldDef newDef, string oldName)
@ -139,7 +136,7 @@ internal static class RenameHelper
/// <param name="oldTypeName"></param> /// <param name="oldTypeName"></param>
/// <param name="newTypeName"></param> /// <param name="newTypeName"></param>
/// <param name="typesToCheck"></param> /// <param name="typesToCheck"></param>
public static void RenameAllProperties( private static void RenameAllProperties(
string oldTypeName, string oldTypeName,
string newTypeName, string newTypeName,
IEnumerable<TypeDef> typesToCheck) IEnumerable<TypeDef> typesToCheck)
@ -147,7 +144,7 @@ internal static class RenameHelper
foreach (var type in typesToCheck) foreach (var type in typesToCheck)
{ {
var properties = type.Properties var properties = type.Properties
.Where(prop => prop.Name.IsFieldOrPropNameInList(TokensToMatch)); .Where(prop => prop.Name.IsFieldOrPropNameInList(TokensToMatch!));
if (!properties.Any()) { continue; } if (!properties.Any()) { continue; }
@ -187,10 +184,10 @@ internal static class RenameHelper
{ {
if (type.HasNestedTypes) if (type.HasNestedTypes)
{ {
RenameType(type.NestedTypes, remap); RenameType(type.NestedTypes, remap!);
} }
if (remap.TypePrimeCandidate.Name is null) { continue; } if (remap?.TypePrimeCandidate?.Name is null) { continue; }
if (remap.SearchParams.IsNested is true && if (remap.SearchParams.IsNested is true &&
type.IsNested && type.Name == remap.TypePrimeCandidate.Name) type.IsNested && type.Name == remap.TypePrimeCandidate.Name)

View File

@ -22,7 +22,7 @@ public static class DataProvider
public static List<RemapModel> Remaps { get; set; } = []; public static List<RemapModel> Remaps { get; set; } = [];
public static Dictionary<string, ItemTemplateModel>? ItemTemplates { get; private set; } public static Dictionary<string, ItemTemplateModel>? ItemTemplates { get; private set; }
public static Settings Settings { get; private set; } public static Settings? Settings { get; private set; }
public static void LoadAppSettings() public static void LoadAppSettings()
{ {
@ -91,11 +91,11 @@ public static class DataProvider
Formatting = Formatting.Indented Formatting = Formatting.Indented
}; };
var path = Settings.Remapper.MappingPath; var path = Settings?.Remapper?.MappingPath;
var jsonText = JsonConvert.SerializeObject(Remaps, settings); var jsonText = JsonConvert.SerializeObject(Remaps, settings);
File.WriteAllText(path, jsonText); File.WriteAllText(path!, jsonText);
Logger.Log($"Mapping File Saved To {path}"); Logger.Log($"Mapping File Saved To {path}");
} }

View File

@ -128,7 +128,7 @@ public static class Logger
} }
private class LogMessage private class LogMessage
{ {
public object Message { get; init; } public object? Message { get; init; }
public ConsoleColor Color { get; init; } public ConsoleColor Color { get; init; }
public bool Silent { get; init; } public bool Silent { get; init; }
public int ThreadId { get; init; } public int ThreadId { get; init; }