diff --git a/Assets/mappings.jsonc b/Assets/mappings.jsonc index 8064ca1..d05b0a9 100644 --- a/Assets/mappings.jsonc +++ b/Assets/mappings.jsonc @@ -10282,7 +10282,7 @@ "GenericParams": { "IsPublic": true, "IsNested": true, - "NTParentName": "SkillManager", + "NestedTypeParentName": "SkillManager", "IsDerived": false }, "Methods": { @@ -10322,7 +10322,7 @@ "GenericParams": { "IsPublic": true, "IsNested": true, - "NTParentName": "SkillManager" + "NestedTypeParentName": "SkillManager" }, "Methods": { "ConstructorParameterCount": -1, @@ -10362,7 +10362,7 @@ "IsPublic": true, "IsAbstract": true, "IsNested": true, - "NTParentName": "SkillManager" + "NestedTypeParentName": "SkillManager" }, "Methods": { "ConstructorParameterCount": -1, @@ -10450,7 +10450,7 @@ "GenericParams": { "IsPublic": true, "IsNested": true, - "NTParentName": "TraderDialogScreen", + "NestedTypeParentName": "TraderDialogScreen", "IsSealed": true }, "Methods": { @@ -10496,7 +10496,7 @@ "IsPublic": true, "IsAbstract": false, "IsNested": true, - "NTParentName": "MatchmakerOfflineRaidScreen" + "NestedTypeParentName": "MatchmakerOfflineRaidScreen" }, "Methods": { "ConstructorParameterCount": -1, @@ -10621,7 +10621,7 @@ "GenericParams": { "IsPublic": true, "IsNested": true, - "NTParentName": "Profile" + "NestedTypeParentName": "Profile" }, "Methods": { "ConstructorParameterCount": -1, @@ -11019,7 +11019,7 @@ "GenericParams": { "IsPublic": true, "IsNested": true, - "NTParentName": "MatchmakerTimeHasCome", + "NestedTypeParentName": "MatchmakerTimeHasCome", "IsSealed": false }, "Methods": { @@ -11201,7 +11201,7 @@ "IsPublic": true, "IsInterface": true, "IsNested": true, - "NTParentName": "BetterAudio" + "NestedTypeParentName": "BetterAudio" }, "Methods": { "ConstructorParameterCount": -1, @@ -11243,7 +11243,7 @@ "IsPublic": true, "IsInterface": true, "IsNested": true, - "NTParentName": "ClientPlayer" + "NestedTypeParentName": "ClientPlayer" }, "Methods": { "ConstructorParameterCount": -1, @@ -13990,7 +13990,7 @@ "IsPublic": true, "IsAbstract": true, "IsNested": true, - "NTParentName": "Player" + "NestedTypeParentName": "Player" }, "Methods": { "ConstructorParameterCount": -1, @@ -15690,7 +15690,7 @@ "IsPublic": true, "IsStruct": true, "IsNested": true, - "NTParentName": "WorldInteractiveObject" + "NestedTypeParentName": "WorldInteractiveObject" }, "Methods": { "ConstructorParameterCount": -1, diff --git a/RecodeItGUI/GUI/Main.cs b/RecodeItGUI/GUI/Main.cs index af5e5a9..ab583eb 100644 --- a/RecodeItGUI/GUI/Main.cs +++ b/RecodeItGUI/GUI/Main.cs @@ -227,20 +227,12 @@ public partial class ReCodeItForm : Form ? bool.Parse(HasGenericParamsComboBox.GetSelectedItem().AsSpan()) : null, - IsNested = IsNestedUpDown.GetEnabled(), + IsDerived = IsDerivedUpDown.GetEnabled(), - NTParentName = NestedTypeParentName.Text == string.Empty - ? null - : NestedTypeParentName.Text, - MatchBaseClass = BaseClassIncludeTextFIeld.Text == string.Empty ? null : BaseClassIncludeTextFIeld.Text, - - IgnoreBaseClass = BaseClassExcludeTextField.Text == string.Empty - ? null - : BaseClassExcludeTextField.Text, }, Methods = @@ -264,6 +256,10 @@ public partial class ReCodeItForm : Form }, NestedTypes = { + IsNested = IsNestedUpDown.GetEnabled(), + NestedTypeParentName = NestedTypeParentName.Text == string.Empty + ? null + : NestedTypeParentName.Text, NestedTypeCount = (int)NestedTypeCountEnabled.GetCount(NestedTypeCountUpDown), IncludeNestedTypes = GUIHelpers.GetAllEntriesFromListBox(NestedTypesIncludeBox).ToHashSet(), ExcludeNestedTypes = GUIHelpers.GetAllEntriesFromListBox(NestedTypesExcludeBox).ToHashSet(), @@ -829,8 +825,7 @@ public partial class ReCodeItForm : Form RemapperUseForceRename.Checked = remap.UseForceRename; BaseClassIncludeTextFIeld.Text = remap.SearchParams.GenericParams.MatchBaseClass; - BaseClassExcludeTextField.Text = remap.SearchParams.GenericParams.IgnoreBaseClass; - NestedTypeParentName.Text = remap.SearchParams.GenericParams.NTParentName; + NestedTypeParentName.Text = remap.SearchParams.NestedTypes.NestedTypeParentName; ConstructorCountEnabled.Checked = remap.SearchParams.Methods.ConstructorParameterCount >= 0; @@ -882,7 +877,7 @@ public partial class ReCodeItForm : Form ? remap.SearchParams.GenericParams.HasGenericParameters.ToString() : "Disabled"; - IsNestedUpDown.BuildStringList("IsNested", false, remap.SearchParams.GenericParams.IsNested); + IsNestedUpDown.BuildStringList("IsNested", false, remap.SearchParams.NestedTypes.IsNested); IsDerivedUpDown.BuildStringList("IsDerived", false, remap.SearchParams.GenericParams.IsDerived); foreach (var method in remap.SearchParams.Methods.IncludeMethods) diff --git a/RecodeItGUI/Utils/GUIHelpers.cs b/RecodeItGUI/Utils/GUIHelpers.cs index cc12d50..f436ad4 100644 --- a/RecodeItGUI/Utils/GUIHelpers.cs +++ b/RecodeItGUI/Utils/GUIHelpers.cs @@ -106,7 +106,7 @@ internal static class GUIHelpers var isInterface = model.SearchParams.GenericParams.IsInterface == null ? null : model.SearchParams.GenericParams.IsInterface; var isStruct = model.SearchParams.GenericParams.IsStruct == null ? null : model.SearchParams.GenericParams.IsStruct; var isEnum = model.SearchParams.GenericParams.IsEnum == null ? null : model.SearchParams.GenericParams.IsEnum; - var isNested = model.SearchParams.GenericParams.IsNested == null ? null : model.SearchParams.GenericParams.IsNested; + var isNested = model.SearchParams.NestedTypes.IsNested == null ? null : model.SearchParams.NestedTypes.IsNested; var isSealed = model.SearchParams.GenericParams.IsSealed == null ? null : model.SearchParams.GenericParams.IsSealed; var HasAttribute = model.SearchParams.GenericParams.HasAttribute == null ? null : model.SearchParams.GenericParams.HasAttribute; var IsDerived = model.SearchParams.GenericParams.IsDerived == null ? null : model.SearchParams.GenericParams.IsDerived; diff --git a/RecodeItLib/Models/RemapModel.cs b/RecodeItLib/Models/RemapModel.cs index 028b922..3df2372 100644 --- a/RecodeItLib/Models/RemapModel.cs +++ b/RecodeItLib/Models/RemapModel.cs @@ -61,26 +61,15 @@ public class GenericParams public bool? IsInterface { get; set; } = null; public bool? IsStruct { get; set; } = null; public bool? IsEnum { get; set; } = null; - public bool? IsNested { get; set; } = null; - - /// - /// Name of the nested types parent - /// - public string? NTParentName { get; set; } = null; public bool? IsSealed { get; set; } = null; public bool? HasAttribute { get; set; } = null; + public bool? HasGenericParameters { get; set; } = null; public bool? IsDerived { get; set; } = null; /// /// Name of the derived classes declaring type /// public string? MatchBaseClass { get; set; } = null; - - /// - /// Name of the derived classes declaring type we want to ignore - /// - public string? IgnoreBaseClass { get; set; } = null; - public bool? HasGenericParameters { get; set; } = null; } public class MethodParams @@ -107,6 +96,12 @@ public class PropertyParams public class NestedTypeParams { + public bool? IsNested { get; set; } = null; + + /// + /// Name of the nested types parent + /// + public string? NestedTypeParentName { get; set; } = null; public int NestedTypeCount { get; set; } = -1; public HashSet IncludeNestedTypes { get; set; } = []; public HashSet ExcludeNestedTypes { get; set; } = []; @@ -114,6 +109,7 @@ public class NestedTypeParams public class EventParams { + public int EventCount { get; set; } = -1; public HashSet IncludeEvents { get; set; } = []; public HashSet ExcludeEvents { get; set; } = []; } \ No newline at end of file diff --git a/RecodeItLib/Remapper/AutoMatcher.cs b/RecodeItLib/Remapper/AutoMatcher.cs index cc5a0e5..03150ec 100644 --- a/RecodeItLib/Remapper/AutoMatcher.cs +++ b/RecodeItLib/Remapper/AutoMatcher.cs @@ -78,6 +78,12 @@ public class AutoMatcher(List mappings, string mappingPath) } if (!ContainsTargetNestedTypes(target, candidate, remapModel.SearchParams.NestedTypes)) + { + CandidateTypes!.Remove(candidate); + continue; + } + + if (!ContainsTargetEvents(target, candidate, remapModel.SearchParams.Events)) { CandidateTypes!.Remove(candidate); } @@ -119,7 +125,6 @@ public class AutoMatcher(List mappings, string mappingPath) parms.IsEnum = target.IsEnum; parms.IsStruct = target.IsValueType && !target.IsEnum; parms.HasGenericParameters = target.HasGenericParameters; - parms.IsNested = target.IsNested; parms.IsSealed = target.IsSealed; parms.HasAttribute = target.HasCustomAttributes; parms.IsDerived = target.BaseType != null && target.BaseType.Name != "Object"; @@ -320,10 +325,58 @@ public class AutoMatcher(List mappings, string mappingPath) } nt.NestedTypeCount = target.NestedTypes.Count; + nt.IsNested = target.IsNested; + + if (target.DeclaringType is not null) + { + nt.NestedTypeParentName = target.DeclaringType.Name.String; + } return commonNts.Any() || !target.IsNested; } + private bool ContainsTargetEvents(TypeDef target, TypeDef candidate, EventParams events) + { + // Target has no events but type has events + if (!target.Events.Any() && candidate.Events.Any()) + { + events.EventCount = 0; + return false; + } + + // Target has events but type has no events + if (target.Events.Any() && !candidate.Events.Any()) return false; + + // Target has a different number of events + if (target.Events.Count != candidate.Events.Count) return false; + + var commonEvents = target.Events + .Select(s => s.Name) + .Intersect(candidate.Events.Select(s => s.Name)); + + var includeEvents = target.Events + .Select(s => s.Name.ToString()) + .Except(candidate.Events.Select(s => s.Name.ToString())); + + var excludeEvents = candidate.Events + .Select(s => s.Name.ToString()) + .Except(target.Events.Select(s => s.Name.ToString())); + + foreach (var include in includeEvents) + { + events.IncludeEvents.Add(include); + } + + foreach (var exclude in excludeEvents) + { + events.ExcludeEvents.Add(exclude); + } + + events.EventCount = target.NestedTypes.Count; + + return commonEvents.Any() || target.Events.Count == 0; + } + private void ProcessEndQuestions(RemapModel remapModel, string assemblyPath) { Thread.Sleep(1000); diff --git a/RecodeItLib/Remapper/Filters/GenericTypeFilters.cs b/RecodeItLib/Remapper/Filters/GenericTypeFilters.cs index c24bf37..42cd74f 100644 --- a/RecodeItLib/Remapper/Filters/GenericTypeFilters.cs +++ b/RecodeItLib/Remapper/Filters/GenericTypeFilters.cs @@ -17,7 +17,7 @@ internal static class GenericTypeFilters // REQUIRED PROPERTY if (parms.GenericParams.IsPublic) { - if (parms.GenericParams.IsNested is true) + if (parms.NestedTypes.IsNested is true) { types = types.Where(t => t.IsNestedPublic); @@ -30,7 +30,7 @@ internal static class GenericTypeFilters } else { - if (parms.GenericParams.IsNested is true) + if (parms.NestedTypes.IsNested is true) { types = types.Where(t => t.IsNestedPrivate || t.IsNestedFamily @@ -50,9 +50,9 @@ internal static class GenericTypeFilters private static IEnumerable FilterNestedByName(IEnumerable types, SearchParams parms) { - if (parms.GenericParams.NTParentName is not null) + if (parms.NestedTypes.NestedTypeParentName is not null) { - types = types.Where(t => t.DeclaringType.Name.String == parms.GenericParams.NTParentName); + types = types.Where(t => t.DeclaringType.Name.String == parms.NestedTypes.NestedTypeParentName); } return types; @@ -200,11 +200,6 @@ internal static class GenericTypeFilters { types = types.Where(t => t.GetBaseType()?.Name?.String == parms.GenericParams.MatchBaseClass); } - - if (parms.GenericParams.IgnoreBaseClass is not null and not "") - { - types = types.Where(t => t.GetBaseType()?.Name?.String != parms.GenericParams.IgnoreBaseClass); - } } else if (parms.GenericParams.IsDerived is false) { diff --git a/RecodeItLib/Remapper/ReMapper.cs b/RecodeItLib/Remapper/ReMapper.cs index 4ccf524..2977f49 100644 --- a/RecodeItLib/Remapper/ReMapper.cs +++ b/RecodeItLib/Remapper/ReMapper.cs @@ -180,7 +180,7 @@ public class ReMapper } // Filter down nested objects - if (mapping.SearchParams.GenericParams.IsNested is false or null) + if (mapping.SearchParams.NestedTypes.IsNested is false or null) { types = types.Where(type => tokens!.Any(token => type.Name.StartsWith(token))); } diff --git a/RecodeItLib/Remapper/RenameHelper.cs b/RecodeItLib/Remapper/RenameHelper.cs index 438791c..4c210fe 100644 --- a/RecodeItLib/Remapper/RenameHelper.cs +++ b/RecodeItLib/Remapper/RenameHelper.cs @@ -187,7 +187,7 @@ internal static class RenameHelper if (remap?.TypePrimeCandidate?.Name is null) { continue; } - if (remap.SearchParams.GenericParams.IsNested is true && + if (remap.SearchParams.NestedTypes.IsNested is true && type.IsNested && type.Name == remap.TypePrimeCandidate.Name) { type.Name = remap.NewTypeName;