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

Finish migration

This commit is contained in:
Cj 2025-01-01 02:13:19 -05:00
parent 572b3e037f
commit 664ff994cf
8 changed files with 2121 additions and 8696 deletions

File diff suppressed because it is too large Load Diff

View File

@ -195,50 +195,53 @@ public partial class ReCodeItForm : Form
UseForceRename = RemapperUseForceRename.Checked, UseForceRename = RemapperUseForceRename.Checked,
SearchParams = new SearchParams SearchParams = new SearchParams
{ {
IsPublic = bool.Parse(IsPublicComboBox.GetSelectedItem<string>().AsSpan()), GenericParams =
{
IsPublic = bool.Parse(IsPublicComboBox.GetSelectedItem<string>().AsSpan()),
IsAbstract = IsAbstractComboBox.SelectedItem as string != "Disabled" IsAbstract = IsAbstractComboBox.SelectedItem as string != "Disabled"
? bool.Parse(IsAbstractComboBox.GetSelectedItem<string>().AsSpan()) ? bool.Parse(IsAbstractComboBox.GetSelectedItem<string>().AsSpan())
: null, : null,
IsSealed = IsSealedComboBox.SelectedItem as string != "Disabled" IsSealed = IsSealedComboBox.SelectedItem as string != "Disabled"
? bool.Parse(IsSealedComboBox.GetSelectedItem<string>().AsSpan()) ? bool.Parse(IsSealedComboBox.GetSelectedItem<string>().AsSpan())
: null, : null,
IsInterface = IsInterfaceComboBox.SelectedItem as string != "Disabled" IsInterface = IsInterfaceComboBox.SelectedItem as string != "Disabled"
? bool.Parse(IsInterfaceComboBox.GetSelectedItem<string>().AsSpan()) ? bool.Parse(IsInterfaceComboBox.GetSelectedItem<string>().AsSpan())
: null, : null,
IsStruct = IsStructComboBox.SelectedItem as string != "Disabled" IsStruct = IsStructComboBox.SelectedItem as string != "Disabled"
? bool.Parse(IsStructComboBox.GetSelectedItem<string>().AsSpan()) ? bool.Parse(IsStructComboBox.GetSelectedItem<string>().AsSpan())
: null, : null,
IsEnum = IsEnumComboBox.SelectedItem as string != "Disabled" IsEnum = IsEnumComboBox.SelectedItem as string != "Disabled"
? bool.Parse(IsEnumComboBox.GetSelectedItem<string>().AsSpan()) ? bool.Parse(IsEnumComboBox.GetSelectedItem<string>().AsSpan())
: null, : null,
HasAttribute = HasAttributeComboBox.SelectedItem as string != "Disabled" HasAttribute = HasAttributeComboBox.SelectedItem as string != "Disabled"
? bool.Parse(HasAttributeComboBox.GetSelectedItem<string>().AsSpan()) ? bool.Parse(HasAttributeComboBox.GetSelectedItem<string>().AsSpan())
: null, : null,
HasGenericParameters = HasGenericParamsComboBox.SelectedItem as string != "Disabled" HasGenericParameters = HasGenericParamsComboBox.SelectedItem as string != "Disabled"
? bool.Parse(HasGenericParamsComboBox.GetSelectedItem<string>().AsSpan()) ? bool.Parse(HasGenericParamsComboBox.GetSelectedItem<string>().AsSpan())
: null, : null,
IsNested = IsNestedUpDown.GetEnabled(), IsNested = IsNestedUpDown.GetEnabled(),
IsDerived = IsDerivedUpDown.GetEnabled(), IsDerived = IsDerivedUpDown.GetEnabled(),
NTParentName = NestedTypeParentName.Text == string.Empty
? null
: NestedTypeParentName.Text,
NTParentName = NestedTypeParentName.Text == string.Empty MatchBaseClass = BaseClassIncludeTextFIeld.Text == string.Empty
? null ? null
: NestedTypeParentName.Text, : BaseClassIncludeTextFIeld.Text,
MatchBaseClass = BaseClassIncludeTextFIeld.Text == string.Empty IgnoreBaseClass = BaseClassExcludeTextField.Text == string.Empty
? null ? null
: BaseClassIncludeTextFIeld.Text, : BaseClassExcludeTextField.Text,
},
IgnoreBaseClass = BaseClassExcludeTextField.Text == string.Empty
? null
: BaseClassExcludeTextField.Text,
Methods = Methods =
{ {
@ -825,9 +828,9 @@ public partial class ReCodeItForm : Form
OriginalTypeName.Text = remap.OriginalTypeName; OriginalTypeName.Text = remap.OriginalTypeName;
RemapperUseForceRename.Checked = remap.UseForceRename; RemapperUseForceRename.Checked = remap.UseForceRename;
BaseClassIncludeTextFIeld.Text = remap.SearchParams.MatchBaseClass; BaseClassIncludeTextFIeld.Text = remap.SearchParams.GenericParams.MatchBaseClass;
BaseClassExcludeTextField.Text = remap.SearchParams.IgnoreBaseClass; BaseClassExcludeTextField.Text = remap.SearchParams.GenericParams.IgnoreBaseClass;
NestedTypeParentName.Text = remap.SearchParams.NTParentName; NestedTypeParentName.Text = remap.SearchParams.GenericParams.NTParentName;
ConstructorCountEnabled.Checked = remap.SearchParams.Methods.ConstructorParameterCount >= 0; ConstructorCountEnabled.Checked = remap.SearchParams.Methods.ConstructorParameterCount >= 0;
@ -849,38 +852,38 @@ public partial class ReCodeItForm : Form
NestedTypeCountUpDown.Value = remap.SearchParams.NestedTypes.NestedTypeCount; NestedTypeCountUpDown.Value = remap.SearchParams.NestedTypes.NestedTypeCount;
IsPublicComboBox.SelectedItem = remap.SearchParams.IsPublic.ToString(); IsPublicComboBox.SelectedItem = remap.SearchParams.GenericParams.IsPublic.ToString();
IsAbstractComboBox.SelectedItem = remap.SearchParams.IsAbstract is not null IsAbstractComboBox.SelectedItem = remap.SearchParams.GenericParams.IsAbstract is not null
? remap.SearchParams.IsAbstract.ToString() ? remap.SearchParams.GenericParams.IsAbstract.ToString()
: "Disabled"; : "Disabled";
IsSealedComboBox.SelectedItem = remap.SearchParams.IsSealed is not null IsSealedComboBox.SelectedItem = remap.SearchParams.GenericParams.IsSealed is not null
? remap.SearchParams.IsSealed.ToString() ? remap.SearchParams.GenericParams.IsSealed.ToString()
: "Disabled"; : "Disabled";
IsInterfaceComboBox.SelectedItem = remap.SearchParams.IsInterface is not null IsInterfaceComboBox.SelectedItem = remap.SearchParams.GenericParams.IsInterface is not null
? remap.SearchParams.IsInterface.ToString() ? remap.SearchParams.GenericParams.IsInterface.ToString()
: "Disabled"; : "Disabled";
IsStructComboBox.SelectedItem = remap.SearchParams.IsStruct is not null IsStructComboBox.SelectedItem = remap.SearchParams.GenericParams.IsStruct is not null
? remap.SearchParams.IsStruct.ToString() ? remap.SearchParams.GenericParams.IsStruct.ToString()
: "Disabled"; : "Disabled";
IsEnumComboBox.SelectedItem = remap.SearchParams.IsEnum is not null IsEnumComboBox.SelectedItem = remap.SearchParams.GenericParams.IsEnum is not null
? remap.SearchParams.IsEnum.ToString() ? remap.SearchParams.GenericParams.IsEnum.ToString()
: "Disabled"; : "Disabled";
HasAttributeComboBox.SelectedItem = remap.SearchParams.HasAttribute is not null HasAttributeComboBox.SelectedItem = remap.SearchParams.GenericParams.HasAttribute is not null
? remap.SearchParams.HasAttribute.ToString() ? remap.SearchParams.GenericParams.HasAttribute.ToString()
: "Disabled"; : "Disabled";
HasGenericParamsComboBox.SelectedItem = remap.SearchParams.HasGenericParameters is not null HasGenericParamsComboBox.SelectedItem = remap.SearchParams.GenericParams.HasGenericParameters is not null
? remap.SearchParams.HasGenericParameters.ToString() ? remap.SearchParams.GenericParams.HasGenericParameters.ToString()
: "Disabled"; : "Disabled";
IsNestedUpDown.BuildStringList("IsNested", false, remap.SearchParams.IsNested); IsNestedUpDown.BuildStringList("IsNested", false, remap.SearchParams.GenericParams.IsNested);
IsDerivedUpDown.BuildStringList("IsDerived", false, remap.SearchParams.IsDerived); IsDerivedUpDown.BuildStringList("IsDerived", false, remap.SearchParams.GenericParams.IsDerived);
foreach (var method in remap.SearchParams.Methods.IncludeMethods) foreach (var method in remap.SearchParams.Methods.IncludeMethods)
{ {

View File

@ -101,16 +101,16 @@ internal static class GUIHelpers
/// <returns></returns> /// <returns></returns>
public static TreeNode GenerateTreeNode(RemapModel model, ReCodeItForm gui) public static TreeNode GenerateTreeNode(RemapModel model, ReCodeItForm gui)
{ {
var isPublic = model.SearchParams.IsPublic; var isPublic = model.SearchParams.GenericParams.IsPublic;
var isAbstract = model.SearchParams.IsAbstract == null ? null : model.SearchParams.IsAbstract; var isAbstract = model.SearchParams.GenericParams.IsAbstract == null ? null : model.SearchParams.GenericParams.IsAbstract;
var isInterface = model.SearchParams.IsInterface == null ? null : model.SearchParams.IsInterface; var isInterface = model.SearchParams.GenericParams.IsInterface == null ? null : model.SearchParams.GenericParams.IsInterface;
var isStruct = model.SearchParams.IsStruct == null ? null : model.SearchParams.IsStruct; var isStruct = model.SearchParams.GenericParams.IsStruct == null ? null : model.SearchParams.GenericParams.IsStruct;
var isEnum = model.SearchParams.IsEnum == null ? null : model.SearchParams.IsEnum; var isEnum = model.SearchParams.GenericParams.IsEnum == null ? null : model.SearchParams.GenericParams.IsEnum;
var isNested = model.SearchParams.IsNested == null ? null : model.SearchParams.IsNested; var isNested = model.SearchParams.GenericParams.IsNested == null ? null : model.SearchParams.GenericParams.IsNested;
var isSealed = model.SearchParams.IsSealed == null ? null : model.SearchParams.IsSealed; var isSealed = model.SearchParams.GenericParams.IsSealed == null ? null : model.SearchParams.GenericParams.IsSealed;
var HasAttribute = model.SearchParams.HasAttribute == null ? null : model.SearchParams.HasAttribute; var HasAttribute = model.SearchParams.GenericParams.HasAttribute == null ? null : model.SearchParams.GenericParams.HasAttribute;
var IsDerived = model.SearchParams.IsDerived == null ? null : model.SearchParams.IsDerived; var IsDerived = model.SearchParams.GenericParams.IsDerived == null ? null : model.SearchParams.GenericParams.IsDerived;
var HasGenericParameters = model.SearchParams.HasGenericParameters == null ? null : model.SearchParams.HasGenericParameters; var HasGenericParameters = model.SearchParams.GenericParams.HasGenericParameters == null ? null : model.SearchParams.GenericParams.HasGenericParameters;
var remapTreeItem = new TreeNode($"{model.NewTypeName}"); var remapTreeItem = new TreeNode($"{model.NewTypeName}");

View File

@ -43,11 +43,16 @@ public class RemapModel
/// </summary> /// </summary>
public class SearchParams public class SearchParams
{ {
#region BOOL_PARAMS public GenericParams GenericParams { get; set; } = new();
public MethodParams Methods { get; set; } = new();
public FieldParams Fields { get; set; } = new();
public PropertyParams Properties { get; set; } = new();
public NestedTypeParams NestedTypes { get; set; } = new();
public EventParams Events { get; set; } = new();
}
/// <summary> public class GenericParams
/// Default to true, most types are public {
/// </summary>
public bool IsPublic { get; set; } = true; public bool IsPublic { get; set; } = true;
public bool? IsAbstract { get; set; } = null; public bool? IsAbstract { get; set; } = null;
@ -55,20 +60,15 @@ public class SearchParams
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? IsNested { get; set; } = null; public bool? IsNested { get; set; } = null;
public bool? IsSealed { get; set; } = null;
public bool? HasAttribute { get; set; } = null;
public bool? IsDerived { get; set; } = null;
public bool? HasGenericParameters { get; set; } = null;
#endregion BOOL_PARAMS
#region STR_PARAMS
/// <summary> /// <summary>
/// Name of the nested types parent /// Name of the nested types parent
/// </summary> /// </summary>
public string? NTParentName { get; set; } = null; public string? NTParentName { get; set; } = null;
public bool? IsSealed { get; set; } = null;
public bool? HasAttribute { get; set; } = null;
public bool? IsDerived { get; set; } = null;
/// <summary> /// <summary>
/// Name of the derived classes declaring type /// Name of the derived classes declaring type
/// </summary> /// </summary>
@ -78,18 +78,7 @@ public class SearchParams
/// Name of the derived classes declaring type we want to ignore /// Name of the derived classes declaring type we want to ignore
/// </summary> /// </summary>
public string? IgnoreBaseClass { get; set; } = null; public string? IgnoreBaseClass { get; set; } = null;
public bool? HasGenericParameters { get; set; } = null;
#endregion STR_PARAMS
#region LISTS
public MethodParams Methods { get; set; } = new();
public FieldParams Fields { get; set; } = new();
public PropertyParams Properties { get; set; } = new();
public NestedTypeParams NestedTypes { get; set; } = new();
public EventParams Events { get; set; } = new();
#endregion LISTS
} }
public class MethodParams public class MethodParams

View File

@ -15,9 +15,9 @@ internal static class GenericTypeFilters
public static IEnumerable<TypeDef> FilterPublic(IEnumerable<TypeDef> types, SearchParams parms) public static IEnumerable<TypeDef> FilterPublic(IEnumerable<TypeDef> types, SearchParams parms)
{ {
// REQUIRED PROPERTY // REQUIRED PROPERTY
if (parms.IsPublic) if (parms.GenericParams.IsPublic)
{ {
if (parms.IsNested is true) if (parms.GenericParams.IsNested is true)
{ {
types = types.Where(t => t.IsNestedPublic); types = types.Where(t => t.IsNestedPublic);
@ -30,7 +30,7 @@ internal static class GenericTypeFilters
} }
else else
{ {
if (parms.IsNested is true) if (parms.GenericParams.IsNested is true)
{ {
types = types.Where(t => t.IsNestedPrivate types = types.Where(t => t.IsNestedPrivate
|| t.IsNestedFamily || t.IsNestedFamily
@ -50,9 +50,9 @@ internal static class GenericTypeFilters
private static IEnumerable<TypeDef> FilterNestedByName(IEnumerable<TypeDef> types, SearchParams parms) private static IEnumerable<TypeDef> FilterNestedByName(IEnumerable<TypeDef> types, SearchParams parms)
{ {
if (parms.NTParentName is not null) if (parms.GenericParams.NTParentName is not null)
{ {
types = types.Where(t => t.DeclaringType.Name.String == parms.NTParentName); types = types.Where(t => t.DeclaringType.Name.String == parms.GenericParams.NTParentName);
} }
return types; return types;
@ -67,11 +67,11 @@ internal static class GenericTypeFilters
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 // Filter based on abstract or not
if (parms.IsAbstract is true) if (parms.GenericParams.IsAbstract is true)
{ {
types = types.Where(t => t.IsAbstract && !t.IsInterface); types = types.Where(t => t.IsAbstract && !t.IsInterface);
} }
else if (parms.IsAbstract is false) else if (parms.GenericParams.IsAbstract is false)
{ {
types = types.Where(t => !t.IsAbstract); types = types.Where(t => !t.IsAbstract);
} }
@ -88,11 +88,11 @@ internal static class GenericTypeFilters
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 // Filter based on abstract or not
if (parms.IsSealed is true) if (parms.GenericParams.IsSealed is true)
{ {
types = types.Where(t => t.IsSealed); types = types.Where(t => t.IsSealed);
} }
else if (parms.IsSealed is false) else if (parms.GenericParams.IsSealed is false)
{ {
types = types.Where(t => !t.IsSealed); types = types.Where(t => !t.IsSealed);
} }
@ -109,11 +109,11 @@ internal static class GenericTypeFilters
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
if (parms.IsInterface is true) if (parms.GenericParams.IsInterface is true)
{ {
types = types.Where(t => t.IsInterface); types = types.Where(t => t.IsInterface);
} }
else if (parms.IsInterface is false) else if (parms.GenericParams.IsInterface is false)
{ {
types = types.Where(t => !t.IsInterface); types = types.Where(t => !t.IsInterface);
} }
@ -129,11 +129,11 @@ internal static class GenericTypeFilters
/// <returns>Filtered list</returns> /// <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.IsStruct is true) if (parms.GenericParams.IsStruct is true)
{ {
types = types.Where(t => t.IsValueType && !t.IsEnum); types = types.Where(t => t.IsValueType && !t.IsEnum);
} }
else if (parms.IsStruct is false) else if (parms.GenericParams.IsStruct is false)
{ {
types = types.Where(t => !t.IsValueType); types = types.Where(t => !t.IsValueType);
} }
@ -150,11 +150,11 @@ internal static class GenericTypeFilters
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
if (parms.IsEnum is true) if (parms.GenericParams.IsEnum is true)
{ {
types = types.Where(t => t.IsEnum); types = types.Where(t => t.IsEnum);
} }
else if (parms.IsEnum is false) else if (parms.GenericParams.IsEnum is false)
{ {
types = types.Where(t => !t.IsEnum); types = types.Where(t => !t.IsEnum);
} }
@ -171,11 +171,11 @@ internal static class GenericTypeFilters
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
if (parms.HasAttribute is true) if (parms.GenericParams.HasAttribute is true)
{ {
types = types.Where(t => t.HasCustomAttributes); types = types.Where(t => t.HasCustomAttributes);
} }
else if (parms.HasAttribute is false) else if (parms.GenericParams.HasAttribute is false)
{ {
types = types.Where(t => !t.HasCustomAttributes); types = types.Where(t => !t.HasCustomAttributes);
} }
@ -192,21 +192,21 @@ internal static class GenericTypeFilters
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
if (parms.IsDerived is true) if (parms.GenericParams.IsDerived is true)
{ {
types = types.Where(t => t.GetBaseType()?.Name?.String != "Object"); types = types.Where(t => t.GetBaseType()?.Name?.String != "Object");
if (parms.MatchBaseClass is not null and not "") if (parms.GenericParams.MatchBaseClass is not null and not "")
{ {
types = types.Where(t => t.GetBaseType()?.Name?.String == parms.MatchBaseClass); types = types.Where(t => t.GetBaseType()?.Name?.String == parms.GenericParams.MatchBaseClass);
} }
if (parms.IgnoreBaseClass is not null and not "") if (parms.GenericParams.IgnoreBaseClass is not null and not "")
{ {
types = types.Where(t => t.GetBaseType()?.Name?.String != parms.IgnoreBaseClass); types = types.Where(t => t.GetBaseType()?.Name?.String != parms.GenericParams.IgnoreBaseClass);
} }
} }
else if (parms.IsDerived is false) else if (parms.GenericParams.IsDerived is false)
{ {
types = types.Where(t => t.GetBaseType()?.Name?.String is "Object"); types = types.Where(t => t.GetBaseType()?.Name?.String is "Object");
} }
@ -222,9 +222,9 @@ internal static class GenericTypeFilters
/// <returns>Filtered list</returns> /// <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.HasGenericParameters is null) return types; if (parms.GenericParams.HasGenericParameters is null) return types;
types = types.Where(t => t.HasGenericParameters == parms.HasGenericParameters); types = types.Where(t => t.HasGenericParameters == parms.GenericParams.HasGenericParameters);
return types; return types;
} }

View File

@ -197,7 +197,7 @@ public class ReMapper
} }
// Filter down nested objects // Filter down nested objects
if (mapping.SearchParams.IsNested is false or null) if (mapping.SearchParams.GenericParams.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)));
} }

View File

@ -187,7 +187,7 @@ internal static class RenameHelper
if (remap?.TypePrimeCandidate?.Name is null) { continue; } if (remap?.TypePrimeCandidate?.Name is null) { continue; }
if (remap.SearchParams.IsNested is true && if (remap.SearchParams.GenericParams.IsNested is true &&
type.IsNested && type.Name == remap.TypePrimeCandidate.Name) type.IsNested && type.Name == remap.TypePrimeCandidate.Name)
{ {
type.Name = remap.NewTypeName; type.Name = remap.NewTypeName;

View File

@ -73,28 +73,8 @@ public static class DataProvider
var jsonText = File.ReadAllText(path); var jsonText = File.ReadAllText(path);
var remaps = JsonConvert.DeserializeObject<List<RemapModel>>(jsonText); var remaps = JsonConvert.DeserializeObject<List<RemapModel>>(jsonText);
if (remaps is null) return [];
MigrateMappings(remaps);
return remaps;
}
private static void MigrateMappings(List<RemapModel> models)
{
foreach (var model in models)
{
MigrateMapping(model);
}
UpdateMapping(Path.Combine(DataPath, "Mappings-migrated.jsonc"), models);
}
private static void MigrateMapping(RemapModel model)
{
var searchParams = model.SearchParams;
return remaps ?? [];
} }
public static void SaveMapping() public static void SaveMapping()
@ -130,7 +110,7 @@ public static class DataProvider
File.WriteAllText(path, jsonText); File.WriteAllText(path, jsonText);
Logger.Log($"Mapping file updated with new type names and saved to {path}", ConsoleColor.Yellow); Logger.Log($"Mapping file updated with new type names and saved to {path}", ConsoleColor.Green);
} }
public static ModuleDefMD LoadModule(string path) public static ModuleDefMD LoadModule(string path)