mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-12 20:30:43 -05:00
Start removing null state, very broken
This commit is contained in:
parent
7f4b8ba0e5
commit
3fbef827fc
File diff suppressed because it is too large
Load Diff
23
ReCodeItCLI/Commands/AddMissingProperties.cs
Normal file
23
ReCodeItCLI/Commands/AddMissingProperties.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using CliFx;
|
||||||
|
using CliFx.Attributes;
|
||||||
|
using CliFx.Infrastructure;
|
||||||
|
using ReCodeItLib.Utils;
|
||||||
|
|
||||||
|
namespace ReCodeItCLI.Commands;
|
||||||
|
|
||||||
|
[Command("AddMissingProperties", Description = "[DEVELOPMENT COMMAND] This command will add missing properties to the provided mapping.json.")]
|
||||||
|
public class AddMissingProperties : ICommand
|
||||||
|
{
|
||||||
|
[CommandParameter(0, IsRequired = true, Description = "Path to the mapping.json file to be fixed")]
|
||||||
|
public string MappingsPath { get; init; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
var remaps = DataProvider.LoadMappingFile(MappingsPath);
|
||||||
|
DataProvider.UpdateMapping(MappingsPath, remaps);
|
||||||
|
|
||||||
|
Logger.LogSync("Successfully updated mapping file");
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
@ -25,8 +25,7 @@ public class AutoMatchCommand : ICommand
|
|||||||
|
|
||||||
[CommandParameter(3, IsRequired = true, Description = "The name you want the type to be renamed to")]
|
[CommandParameter(3, IsRequired = true, Description = "The name you want the type to be renamed to")]
|
||||||
public required string NewTypeName { get; init; }
|
public required string NewTypeName { get; init; }
|
||||||
|
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
#if WAIT_FOR_DEBUGGER
|
#if WAIT_FOR_DEBUGGER
|
||||||
|
@ -56,11 +56,11 @@ public class SearchParams
|
|||||||
public class GenericParams
|
public class GenericParams
|
||||||
{
|
{
|
||||||
public bool IsPublic { get; set; } = true;
|
public bool IsPublic { get; set; } = true;
|
||||||
public bool? IsAbstract { get; set; } = null;
|
public bool IsAbstract { get; set; }
|
||||||
public bool? IsInterface { get; set; } = null;
|
public bool IsInterface { get; set; }
|
||||||
public bool? IsStruct { get; set; } = null;
|
public bool? IsStruct { get; set; } = null;
|
||||||
public bool? IsEnum { get; set; } = null;
|
public bool? IsEnum { get; set; } = null;
|
||||||
public bool? IsSealed { get; set; } = null;
|
public bool IsSealed { get; set; }
|
||||||
public bool? HasAttribute { get; set; } = null;
|
public bool? HasAttribute { get; set; } = null;
|
||||||
public bool? HasGenericParameters { get; set; } = null;
|
public bool? HasGenericParameters { get; set; } = null;
|
||||||
public bool? IsDerived { get; set; } = null;
|
public bool? IsDerived { get; set; } = null;
|
||||||
|
@ -6,66 +6,22 @@ namespace ReCodeItLib.ReMapper.Filters;
|
|||||||
|
|
||||||
internal static class GenericTypeFilters
|
internal static class GenericTypeFilters
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Filters based on public, or nested public or private if the nested flag is set. This is a
|
|
||||||
/// required property
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="types"></param>
|
|
||||||
/// <param name="parms"></param>
|
|
||||||
/// <returns>Filtered list</returns>
|
|
||||||
public static IEnumerable<TypeDef> FilterPublic(IEnumerable<TypeDef> types, SearchParams parms)
|
public static IEnumerable<TypeDef> FilterPublic(IEnumerable<TypeDef> types, SearchParams parms)
|
||||||
{
|
{
|
||||||
return types.Where(t => t.IsPublic == parms.GenericParams.IsPublic);
|
return types.Where(t => t.IsPublic == parms.GenericParams.IsPublic);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Filters based on IsAbstract
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="types"></param>
|
|
||||||
/// <param name="parms"></param>
|
|
||||||
/// <returns>Filtered list</returns>
|
|
||||||
public static IEnumerable<TypeDef> FilterAbstract(IEnumerable<TypeDef> types, SearchParams parms)
|
public static IEnumerable<TypeDef> FilterAbstract(IEnumerable<TypeDef> types, SearchParams parms)
|
||||||
{
|
{
|
||||||
// Filter based on abstract or not
|
// NOTE: Interfaces are abstract
|
||||||
if (parms.GenericParams.IsAbstract is true)
|
return types.Where(t => t.IsAbstract == parms.GenericParams.IsAbstract);
|
||||||
{
|
|
||||||
types = types.Where(t => t.IsAbstract && !t.IsInterface);
|
|
||||||
}
|
|
||||||
else if (parms.GenericParams.IsAbstract is false)
|
|
||||||
{
|
|
||||||
types = types.Where(t => !t.IsAbstract);
|
|
||||||
}
|
|
||||||
|
|
||||||
return types;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Filters based on IsAbstract
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="types"></param>
|
|
||||||
/// <param name="parms"></param>
|
|
||||||
/// <returns>Filtered list</returns>
|
|
||||||
public static IEnumerable<TypeDef> FilterSealed(IEnumerable<TypeDef> types, SearchParams parms)
|
public static IEnumerable<TypeDef> FilterSealed(IEnumerable<TypeDef> types, SearchParams parms)
|
||||||
{
|
{
|
||||||
// Filter based on abstract or not
|
return types.Where(t => t.IsSealed == parms.GenericParams.IsSealed);
|
||||||
if (parms.GenericParams.IsSealed is true)
|
|
||||||
{
|
|
||||||
types = types.Where(t => t.IsSealed);
|
|
||||||
}
|
|
||||||
else if (parms.GenericParams.IsSealed is false)
|
|
||||||
{
|
|
||||||
types = types.Where(t => !t.IsSealed);
|
|
||||||
}
|
|
||||||
|
|
||||||
return types;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Filters based on IsInterface
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="types"></param>
|
|
||||||
/// <param name="parms"></param>
|
|
||||||
/// <returns>Filtered list</returns>
|
|
||||||
public static IEnumerable<TypeDef> FilterInterface(IEnumerable<TypeDef> types, SearchParams parms)
|
public static IEnumerable<TypeDef> FilterInterface(IEnumerable<TypeDef> types, SearchParams parms)
|
||||||
{
|
{
|
||||||
// Filter based on interface or not
|
// Filter based on interface or not
|
||||||
@ -80,13 +36,7 @@ internal static class GenericTypeFilters
|
|||||||
|
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Filters based on IsStruct
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="types"></param>
|
|
||||||
/// <param name="parms"></param>
|
|
||||||
/// <returns>Filtered list</returns>
|
|
||||||
public static IEnumerable<TypeDef> FilterStruct(IEnumerable<TypeDef> types, SearchParams parms)
|
public static IEnumerable<TypeDef> FilterStruct(IEnumerable<TypeDef> types, SearchParams parms)
|
||||||
{
|
{
|
||||||
if (parms.GenericParams.IsStruct is true)
|
if (parms.GenericParams.IsStruct is true)
|
||||||
@ -100,13 +50,7 @@ internal static class GenericTypeFilters
|
|||||||
|
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Filters based on IsEnum
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="types"></param>
|
|
||||||
/// <param name="parms"></param>
|
|
||||||
/// <returns>Filtered list</returns>
|
|
||||||
public static IEnumerable<TypeDef> FilterEnum(IEnumerable<TypeDef> types, SearchParams parms)
|
public static IEnumerable<TypeDef> FilterEnum(IEnumerable<TypeDef> types, SearchParams parms)
|
||||||
{
|
{
|
||||||
// Filter based on enum or not
|
// Filter based on enum or not
|
||||||
@ -121,13 +65,7 @@ internal static class GenericTypeFilters
|
|||||||
|
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Filters based on HasAttribute
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="types"></param>
|
|
||||||
/// <param name="parms"></param>
|
|
||||||
/// <returns>Filtered list</returns>
|
|
||||||
public static IEnumerable<TypeDef> FilterAttributes(IEnumerable<TypeDef> types, SearchParams parms)
|
public static IEnumerable<TypeDef> FilterAttributes(IEnumerable<TypeDef> types, SearchParams parms)
|
||||||
{
|
{
|
||||||
// Filter based on HasAttribute or not
|
// Filter based on HasAttribute or not
|
||||||
@ -142,13 +80,7 @@ internal static class GenericTypeFilters
|
|||||||
|
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Filters based on HasAttribute
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="types"></param>
|
|
||||||
/// <param name="parms"></param>
|
|
||||||
/// <returns>Filtered list</returns>
|
|
||||||
public static IEnumerable<TypeDef> FilterDerived(IEnumerable<TypeDef> types, SearchParams parms)
|
public static IEnumerable<TypeDef> FilterDerived(IEnumerable<TypeDef> types, SearchParams parms)
|
||||||
{
|
{
|
||||||
// Filter based on IsDerived or not
|
// Filter based on IsDerived or not
|
||||||
@ -168,13 +100,7 @@ internal static class GenericTypeFilters
|
|||||||
|
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Filters based on method count
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="types"></param>
|
|
||||||
/// <param name="parms"></param>
|
|
||||||
/// <returns>Filtered list</returns>
|
|
||||||
public static IEnumerable<TypeDef> FilterByGenericParameters(IEnumerable<TypeDef> types, SearchParams parms)
|
public static IEnumerable<TypeDef> FilterByGenericParameters(IEnumerable<TypeDef> types, SearchParams parms)
|
||||||
{
|
{
|
||||||
if (parms.GenericParams.HasGenericParameters is null) return types;
|
if (parms.GenericParams.HasGenericParameters is null) return types;
|
||||||
|
@ -69,7 +69,7 @@ public class ReMapper
|
|||||||
|
|
||||||
RenameMatches(types);
|
RenameMatches(types);
|
||||||
|
|
||||||
Publicize();
|
//Publicize();
|
||||||
|
|
||||||
// We are done, write the assembly
|
// We are done, write the assembly
|
||||||
WriteAssembly();
|
WriteAssembly();
|
||||||
@ -118,9 +118,9 @@ public class ReMapper
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!renameTasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion))
|
while (!renameTasks.TrueForAll(t => t.Status is TaskStatus.RanToCompletion or TaskStatus.Faulted))
|
||||||
{
|
{
|
||||||
Logger.DrawProgressBar(renameTasks.Where(t => t.IsCompleted)!.Count() + 1, renameTasks.Count, 50);
|
Logger.DrawProgressBar(renameTasks.Where(t => t.IsCompleted)!.Count(), renameTasks.Count, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
Task.WaitAll(renameTasks.ToArray());
|
Task.WaitAll(renameTasks.ToArray());
|
||||||
|
@ -39,15 +39,17 @@ internal class Renamer
|
|||||||
{
|
{
|
||||||
foreach (var type in typesToCheck)
|
foreach (var type in typesToCheck)
|
||||||
{
|
{
|
||||||
var methods = type.Methods
|
List<MethodDef> methodsToFix = [];
|
||||||
.Where(method => method.Name.StartsWith(remap!.TypePrimeCandidate!.Name.String)
|
|
||||||
&& type.Methods.Count(m2 => m2.Name.String.EndsWith(method.Name.String.Split(".")[1])) < 2);
|
methodsToFix.AddRange(
|
||||||
|
from method in type.Methods where method.Name.StartsWith(remap.TypePrimeCandidate!.Name.String)
|
||||||
|
let splitName = method.Name.String.Split(".") where splitName.Length != 1 select method);
|
||||||
|
|
||||||
foreach (var method in methods)
|
foreach (var method in methodsToFix)
|
||||||
{
|
{
|
||||||
var name = method.Name.String.Split(".");
|
var name = method.Name.String.Split(".");
|
||||||
|
|
||||||
if (methods.Count(m => m.Name.String.EndsWith(name[1])) > 1)
|
if (methodsToFix.Count(m => m.Name.String.EndsWith(name[1])) > 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
method.Name = name[1];
|
method.Name = name[1];
|
||||||
|
@ -33,7 +33,7 @@ public static class DataProvider
|
|||||||
return remaps ?? [];
|
return remaps ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateMapping(string path, List<RemapModel> remaps)
|
public static void UpdateMapping(string path, List<RemapModel> remaps, bool ignoreNull = true)
|
||||||
{
|
{
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
{
|
{
|
||||||
@ -42,7 +42,7 @@ public static class DataProvider
|
|||||||
|
|
||||||
JsonSerializerSettings settings = new()
|
JsonSerializerSettings settings = new()
|
||||||
{
|
{
|
||||||
NullValueHandling = NullValueHandling.Ignore,
|
NullValueHandling = ignoreNull ? NullValueHandling.Ignore : NullValueHandling.Include,
|
||||||
Formatting = Formatting.Indented
|
Formatting = Formatting.Indented
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user