From 6e8420477e622f22213f9278272f418b91416a59 Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Tue, 31 Dec 2024 14:15:11 -0500 Subject: [PATCH] Put filters into their own class, refactor remapper class --- .../{Search => Filters}/CtorTypeFilters.cs | 2 +- .../{Search => Filters}/EventTypeFilters.cs | 2 +- .../{Search => Filters}/FieldTypeFilters.cs | 2 +- .../{Search => Filters}/GenericTypeFilters.cs | 2 +- .../{Search => Filters}/MethodTypeFilters.cs | 2 +- .../{Search => Filters}/NestedTypeFilters.cs | 2 +- .../PropertyTypeFilters.cs | 2 +- RecodeItLib/Remapper/ReMapper.cs | 344 +++--------------- RecodeItLib/Remapper/TypeFilters.cs | 278 ++++++++++++++ 9 files changed, 331 insertions(+), 305 deletions(-) rename RecodeItLib/Remapper/{Search => Filters}/CtorTypeFilters.cs (96%) rename RecodeItLib/Remapper/{Search => Filters}/EventTypeFilters.cs (97%) rename RecodeItLib/Remapper/{Search => Filters}/FieldTypeFilters.cs (98%) rename RecodeItLib/Remapper/{Search => Filters}/GenericTypeFilters.cs (99%) rename RecodeItLib/Remapper/{Search => Filters}/MethodTypeFilters.cs (98%) rename RecodeItLib/Remapper/{Search => Filters}/NestedTypeFilters.cs (98%) rename RecodeItLib/Remapper/{Search => Filters}/PropertyTypeFilters.cs (98%) create mode 100644 RecodeItLib/Remapper/TypeFilters.cs diff --git a/RecodeItLib/Remapper/Search/CtorTypeFilters.cs b/RecodeItLib/Remapper/Filters/CtorTypeFilters.cs similarity index 96% rename from RecodeItLib/Remapper/Search/CtorTypeFilters.cs rename to RecodeItLib/Remapper/Filters/CtorTypeFilters.cs index 92a8152..020c2e6 100644 --- a/RecodeItLib/Remapper/Search/CtorTypeFilters.cs +++ b/RecodeItLib/Remapper/Filters/CtorTypeFilters.cs @@ -1,7 +1,7 @@ using dnlib.DotNet; using ReCodeItLib.Models; -namespace ReCodeItLib.ReMapper.Search; +namespace ReCodeItLib.ReMapper.Filters; internal static class CtorTypeFilters { diff --git a/RecodeItLib/Remapper/Search/EventTypeFilters.cs b/RecodeItLib/Remapper/Filters/EventTypeFilters.cs similarity index 97% rename from RecodeItLib/Remapper/Search/EventTypeFilters.cs rename to RecodeItLib/Remapper/Filters/EventTypeFilters.cs index f2eeeff..ed55a0f 100644 --- a/RecodeItLib/Remapper/Search/EventTypeFilters.cs +++ b/RecodeItLib/Remapper/Filters/EventTypeFilters.cs @@ -1,7 +1,7 @@ using dnlib.DotNet; using ReCodeItLib.Models; -namespace ReCodeItLib.ReMapper.Search; +namespace ReCodeItLib.ReMapper.Filters; internal static class EventTypeFilters { diff --git a/RecodeItLib/Remapper/Search/FieldTypeFilters.cs b/RecodeItLib/Remapper/Filters/FieldTypeFilters.cs similarity index 98% rename from RecodeItLib/Remapper/Search/FieldTypeFilters.cs rename to RecodeItLib/Remapper/Filters/FieldTypeFilters.cs index fb9f033..b463902 100644 --- a/RecodeItLib/Remapper/Search/FieldTypeFilters.cs +++ b/RecodeItLib/Remapper/Filters/FieldTypeFilters.cs @@ -1,7 +1,7 @@ using dnlib.DotNet; using ReCodeItLib.Models; -namespace ReCodeItLib.ReMapper.Search; +namespace ReCodeItLib.ReMapper.Filters; internal static class FieldTypeFilters { diff --git a/RecodeItLib/Remapper/Search/GenericTypeFilters.cs b/RecodeItLib/Remapper/Filters/GenericTypeFilters.cs similarity index 99% rename from RecodeItLib/Remapper/Search/GenericTypeFilters.cs rename to RecodeItLib/Remapper/Filters/GenericTypeFilters.cs index f15c922..111a9a3 100644 --- a/RecodeItLib/Remapper/Search/GenericTypeFilters.cs +++ b/RecodeItLib/Remapper/Filters/GenericTypeFilters.cs @@ -1,7 +1,7 @@ using dnlib.DotNet; using ReCodeItLib.Models; -namespace ReCodeItLib.ReMapper.Search; +namespace ReCodeItLib.ReMapper.Filters; internal static class GenericTypeFilters { diff --git a/RecodeItLib/Remapper/Search/MethodTypeFilters.cs b/RecodeItLib/Remapper/Filters/MethodTypeFilters.cs similarity index 98% rename from RecodeItLib/Remapper/Search/MethodTypeFilters.cs rename to RecodeItLib/Remapper/Filters/MethodTypeFilters.cs index bcb93a7..dd850cb 100644 --- a/RecodeItLib/Remapper/Search/MethodTypeFilters.cs +++ b/RecodeItLib/Remapper/Filters/MethodTypeFilters.cs @@ -1,7 +1,7 @@ using dnlib.DotNet; using ReCodeItLib.Models; -namespace ReCodeItLib.ReMapper.Search; +namespace ReCodeItLib.ReMapper.Filters; internal static class MethodTypeFilters { diff --git a/RecodeItLib/Remapper/Search/NestedTypeFilters.cs b/RecodeItLib/Remapper/Filters/NestedTypeFilters.cs similarity index 98% rename from RecodeItLib/Remapper/Search/NestedTypeFilters.cs rename to RecodeItLib/Remapper/Filters/NestedTypeFilters.cs index cb186bc..4484c0d 100644 --- a/RecodeItLib/Remapper/Search/NestedTypeFilters.cs +++ b/RecodeItLib/Remapper/Filters/NestedTypeFilters.cs @@ -1,7 +1,7 @@ using dnlib.DotNet; using ReCodeItLib.Models; -namespace ReCodeItLib.ReMapper.Search; +namespace ReCodeItLib.ReMapper.Filters; internal static class NestedTypeFilters { diff --git a/RecodeItLib/Remapper/Search/PropertyTypeFilters.cs b/RecodeItLib/Remapper/Filters/PropertyTypeFilters.cs similarity index 98% rename from RecodeItLib/Remapper/Search/PropertyTypeFilters.cs rename to RecodeItLib/Remapper/Filters/PropertyTypeFilters.cs index 7d1f90d..657de0e 100644 --- a/RecodeItLib/Remapper/Search/PropertyTypeFilters.cs +++ b/RecodeItLib/Remapper/Filters/PropertyTypeFilters.cs @@ -1,7 +1,7 @@ using dnlib.DotNet; using ReCodeItLib.Models; -namespace ReCodeItLib.ReMapper.Search; +namespace ReCodeItLib.ReMapper.Filters; internal static class PropertyTypeFilters { diff --git a/RecodeItLib/Remapper/ReMapper.cs b/RecodeItLib/Remapper/ReMapper.cs index 3dc340a..9427e93 100644 --- a/RecodeItLib/Remapper/ReMapper.cs +++ b/RecodeItLib/Remapper/ReMapper.cs @@ -2,7 +2,6 @@ using dnlib.DotNet.Emit; using ReCodeItLib.Enums; using ReCodeItLib.Models; -using ReCodeItLib.ReMapper.Search; using ReCodeItLib.Utils; using System.Diagnostics; using System.Reflection; @@ -53,9 +52,31 @@ public class ReMapper var types = Module.GetTypes(); - if (!types.Any(t => t.Name.Contains("GClass"))) + TryDeObfuscate(ref types, assemblyPath); + FindBestMatches(types); + ChooseBestMatches(); + + // Don't go any further during a validation + if (validate) { - Logger.Log("Assembly is obfuscated, running de-obfuscation...\n", ConsoleColor.Yellow); + new Statistics(_remaps, Stopwatch, OutPath) + .DisplayStatistics(true); + + return; + } + + RenameMatches(types); + Publicize(); + + // We are done, write the assembly + WriteAssembly(); + } + + private void TryDeObfuscate(ref IEnumerable types, string assemblyPath) + { + if (!Module!.GetTypes().Any(t => t.Name.Contains("GClass"))) + { + Logger.LogSync("Assembly is obfuscated, running de-obfuscation...\n", ConsoleColor.Yellow); Module.Dispose(); Module = null; @@ -74,16 +95,18 @@ public class ReMapper types = Module.GetTypes(); GenerateDynamicRemaps(newPath, types); - } - else - { - GenerateDynamicRemaps(assemblyPath, types); + return; } + GenerateDynamicRemaps(assemblyPath, types); + } + + private void FindBestMatches(IEnumerable types) + { Logger.LogSync("Finding Best Matches...", ConsoleColor.Green); - var tasks = new List(remapModels.Count); - foreach (var remap in remapModels) + var tasks = new List(_remaps.Count); + foreach (var remap in _remaps) { tasks.Add( Task.Factory.StartNew(() => @@ -99,22 +122,14 @@ public class ReMapper } Task.WaitAll(tasks.ToArray()); + } - ChooseBestMatches(); - - // Don't go any further during a validation - if (validate) - { - new Statistics(_remaps, Stopwatch, OutPath) - .DisplayStatistics(true); - - return; - } - + private void RenameMatches(IEnumerable types) + { Logger.LogSync("\nRenaming...", ConsoleColor.Green); - var renameTasks = new List(remapModels.Count); - foreach (var remap in remapModels) + var renameTasks = new List(_remaps.Count); + foreach (var remap in _remaps) { renameTasks.Add( Task.Factory.StartNew(() => @@ -126,11 +141,14 @@ public class ReMapper while (!renameTasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion)) { - Logger.DrawProgressBar(renameTasks.Where(t => t.IsCompleted)!.Count(), tasks.Count - 1, 50); + Logger.DrawProgressBar(renameTasks.Where(t => t.IsCompleted)!.Count(), renameTasks.Count, 50); } Task.WaitAll(renameTasks.ToArray()); - + } + + private void Publicize() + { // Don't publicize and unseal until after the remapping, so we can use those as search parameters if (Settings!.MappingSettings!.Publicize) { @@ -138,11 +156,8 @@ public class ReMapper SPTPublicizer.PublicizeClasses(Module); } - - // We are done, write the assembly - WriteAssembly(); } - + private bool Validate(List remaps) { var duplicateGroups = remaps @@ -188,270 +203,13 @@ public class ReMapper } // Run through a series of filters and report an error if all types are filtered out. + var filters = new TypeFilters(); - if (!FilterTypesByGeneric(mapping, ref types)) return; - if (!FilterTypesByMethods(mapping, ref types)) return; - if (!FilterTypesByFields(mapping, ref types)) return; - if (!FilterTypesByProps(mapping, ref types)) return; - if (!FilterTypesByEvents(mapping, ref types)) return; - if (!FilterTypesByNested(mapping, ref types)) return; - - types = CtorTypeFilters.FilterByParameterCount(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.ConstructorParameterCount); - mapping.TypeCandidates.UnionWith(types); - return; - } + if (!filters.DoesTypePassFilters(mapping, ref types)) return; mapping.TypeCandidates.UnionWith(types); } - - private static bool FilterTypesByGeneric(RemapModel mapping, ref IEnumerable types) - { - types = GenericTypeFilters.FilterPublic(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsPublic); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = GenericTypeFilters.FilterAbstract(types, mapping.SearchParams); - if (types.Count() == 1) return true; - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsPublic); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = GenericTypeFilters.FilterSealed(types, mapping.SearchParams); - if (types.Count() == 1) return true; - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsSealed); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = GenericTypeFilters.FilterInterface(types, mapping.SearchParams); - if (types.Count() == 1) return true; - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsInterface); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = GenericTypeFilters.FilterStruct(types, mapping.SearchParams); - if (types.Count() == 1) return true; - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsStruct); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = GenericTypeFilters.FilterEnum(types, mapping.SearchParams); - if (types.Count() == 1) return true; - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsEnum); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = GenericTypeFilters.FilterAttributes(types, mapping.SearchParams); - if (types.Count() == 1) return true; - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.HasAttribute); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = GenericTypeFilters.FilterDerived(types, mapping.SearchParams); - if (types.Count() == 1) return true; - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsDerived); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = GenericTypeFilters.FilterByGenericParameters(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.HasGenericParameters); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - return true; - } - - private static bool FilterTypesByMethods(RemapModel mapping, ref IEnumerable types) - { - types = MethodTypeFilters.FilterByInclude(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsInclude); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = MethodTypeFilters.FilterByExclude(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsExclude); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = MethodTypeFilters.FilterByCount(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsCount); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - return true; - } - - private static bool FilterTypesByFields(RemapModel mapping, ref IEnumerable types) - { - types = FieldTypeFilters.FilterByInclude(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsInclude); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = FieldTypeFilters.FilterByExclude(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsExclude); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = FieldTypeFilters.FilterByCount(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsCount); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - return true; - } - - private static bool FilterTypesByProps(RemapModel mapping, ref IEnumerable types) - { - types = PropertyTypeFilters.FilterByInclude(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesInclude); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = PropertyTypeFilters.FilterByExclude(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesExclude); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = PropertyTypeFilters.FilterByCount(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesCount); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - return true; - } - - private static bool FilterTypesByNested(RemapModel mapping, ref IEnumerable types) - { - types = NestedTypeFilters.FilterByInclude(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeInclude); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = NestedTypeFilters.FilterByExclude(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeExclude); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = NestedTypeFilters.FilterByCount(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeCount); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - return true; - } - - private static bool FilterTypesByEvents(RemapModel mapping, ref IEnumerable types) - { - types = EventTypeFilters.FilterByInclude(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.EventsInclude); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - types = EventTypeFilters.FilterByExclude(types, mapping.SearchParams); - - if (!types.Any()) - { - AllTypesFilteredOutFor(mapping, ENoMatchReason.EventsExclude); - mapping.TypeCandidates.UnionWith(types); - return false; - } - - return true; - } - + private void HandleDirectRename(RemapModel mapping, ref IEnumerable types) { foreach (var type in types) @@ -640,14 +398,4 @@ public class ReMapper } } } - - /// - /// This is used to log that all types for a given remap were filtered out. - /// - /// remap model that failed - /// Reason for filtering - private static void AllTypesFilteredOutFor(RemapModel remap, ENoMatchReason noMatchReason) - { - Logger.Log($"All types filtered out after `{noMatchReason}` filter for: `{remap.NewTypeName}`", ConsoleColor.Red); - } } \ No newline at end of file diff --git a/RecodeItLib/Remapper/TypeFilters.cs b/RecodeItLib/Remapper/TypeFilters.cs new file mode 100644 index 0000000..4e4e558 --- /dev/null +++ b/RecodeItLib/Remapper/TypeFilters.cs @@ -0,0 +1,278 @@ +using dnlib.DotNet; +using ReCodeItLib.Enums; +using ReCodeItLib.Models; +using ReCodeItLib.ReMapper.Filters; +using ReCodeItLib.Utils; + +namespace ReCodeItLib.ReMapper; + +public class TypeFilters +{ + public bool DoesTypePassFilters(RemapModel mapping, ref IEnumerable types) + { + if (!FilterTypesByGeneric(mapping, ref types)) return false; + if (!FilterTypesByMethods(mapping, ref types)) return false; + if (!FilterTypesByFields(mapping, ref types)) return false; + if (!FilterTypesByProps(mapping, ref types)) return false; + if (!FilterTypesByEvents(mapping, ref types)) return false; + if (!FilterTypesByNested(mapping, ref types)) return false; + + return true; + } + + private static bool FilterTypesByGeneric(RemapModel mapping, ref IEnumerable types) + { + types = GenericTypeFilters.FilterPublic(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.IsPublic); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = GenericTypeFilters.FilterAbstract(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.IsPublic); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = GenericTypeFilters.FilterSealed(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.IsSealed); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = GenericTypeFilters.FilterInterface(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.IsInterface); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = GenericTypeFilters.FilterStruct(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.IsStruct); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = GenericTypeFilters.FilterEnum(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.IsEnum); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = GenericTypeFilters.FilterAttributes(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.HasAttribute); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = GenericTypeFilters.FilterDerived(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.IsDerived); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = GenericTypeFilters.FilterByGenericParameters(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.HasGenericParameters); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + return true; + } + + private static bool FilterTypesByMethods(RemapModel mapping, ref IEnumerable types) + { + types = MethodTypeFilters.FilterByInclude(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsInclude); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = MethodTypeFilters.FilterByExclude(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsExclude); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = MethodTypeFilters.FilterByCount(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsCount); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = CtorTypeFilters.FilterByParameterCount(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.ConstructorParameterCount); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + return true; + } + + private static bool FilterTypesByFields(RemapModel mapping, ref IEnumerable types) + { + types = FieldTypeFilters.FilterByInclude(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsInclude); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = FieldTypeFilters.FilterByExclude(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsExclude); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = FieldTypeFilters.FilterByCount(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsCount); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + return true; + } + + private static bool FilterTypesByProps(RemapModel mapping, ref IEnumerable types) + { + types = PropertyTypeFilters.FilterByInclude(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesInclude); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = PropertyTypeFilters.FilterByExclude(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesExclude); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = PropertyTypeFilters.FilterByCount(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesCount); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + return true; + } + + private static bool FilterTypesByNested(RemapModel mapping, ref IEnumerable types) + { + types = NestedTypeFilters.FilterByInclude(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeInclude); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = NestedTypeFilters.FilterByExclude(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeExclude); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = NestedTypeFilters.FilterByCount(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeCount); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + return true; + } + + private static bool FilterTypesByEvents(RemapModel mapping, ref IEnumerable types) + { + types = EventTypeFilters.FilterByInclude(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.EventsInclude); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = EventTypeFilters.FilterByExclude(types, mapping.SearchParams); + + if (!types.Any()) + { + AllTypesFilteredOutFor(mapping, ENoMatchReason.EventsExclude); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + return true; + } + + /// + /// This is used to log that all types for a given remap were filtered out. + /// + /// remap model that failed + /// Reason for filtering + private static void AllTypesFilteredOutFor(RemapModel remap, ENoMatchReason noMatchReason) + { + Logger.Log($"All types filtered out after `{noMatchReason}` filter for: `{remap.NewTypeName}`", ConsoleColor.Red); + } +} \ No newline at end of file