Properties, constructors, misc
This commit is contained in:
parent
a7a4ee33ce
commit
0453f3d4d6
@ -7,7 +7,7 @@ internal class AppSettings
|
|||||||
{
|
{
|
||||||
public bool Debug { get; set; }
|
public bool Debug { get; set; }
|
||||||
public bool SilentMode { get; set; }
|
public bool SilentMode { get; set; }
|
||||||
|
public int MaxMatchCount { get; set; }
|
||||||
public bool ScoringMode { get; set; }
|
public bool ScoringMode { get; set; }
|
||||||
public bool Publicize { get; set; }
|
public bool Publicize { get; set; }
|
||||||
public bool Unseal { get; set; }
|
public bool Unseal { get; set; }
|
||||||
|
@ -245,7 +245,11 @@ internal class Remapper
|
|||||||
{
|
{
|
||||||
if (scores.Count == 0) { return; }
|
if (scores.Count == 0) { return; }
|
||||||
|
|
||||||
var highestScore = scores.OrderByDescending(score => score.Score).FirstOrDefault();
|
var filteredScores = scores
|
||||||
|
.OrderByDescending(score => score.Score)
|
||||||
|
.Take(DataProvider.AppSettings.MaxMatchCount);
|
||||||
|
|
||||||
|
var highestScore = filteredScores.FirstOrDefault();
|
||||||
|
|
||||||
if (highestScore is null) { return; }
|
if (highestScore is null) { return; }
|
||||||
|
|
||||||
@ -256,9 +260,9 @@ internal class Remapper
|
|||||||
|
|
||||||
if (scores.Count > 1)
|
if (scores.Count > 1)
|
||||||
{
|
{
|
||||||
Logger.Log($"Warning! There were {scores.Count - 1} possible matches. Considering adding more search parameters", ConsoleColor.Yellow);
|
Logger.Log($"Warning! There were {filteredScores.Count()} possible matches. Considering adding more search parameters", ConsoleColor.Yellow);
|
||||||
|
|
||||||
foreach (var score in scores.OrderByDescending(score => score.Score).Skip(1))
|
foreach (var score in filteredScores.Skip(1))
|
||||||
{
|
{
|
||||||
Logger.Log($"{score.Definition.Name} - Score [{score.Score}]", ConsoleColor.Yellow);
|
Logger.Log($"{score.Definition.Name} - Score [{score.Score}]", ConsoleColor.Yellow);
|
||||||
}
|
}
|
||||||
|
@ -15,22 +15,14 @@ internal static class Constructors
|
|||||||
/// <returns>Match if constructor parameters matches</returns>
|
/// <returns>Match if constructor parameters matches</returns>
|
||||||
public static EMatchResult GetTypeByParameterCount(TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult GetTypeByParameterCount(TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.ConstructorParameterCount is null)
|
if (parms.ConstructorParameterCount is null) return EMatchResult.Disabled;
|
||||||
{
|
|
||||||
return EMatchResult.Disabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
var constructors = type.GetConstructors();
|
var match = type.GetConstructors()
|
||||||
|
.Where(c => c.Parameters.Count == parms.ConstructorParameterCount)
|
||||||
|
.Any();
|
||||||
|
|
||||||
foreach (var constructor in constructors)
|
return match
|
||||||
{
|
? EMatchResult.Match
|
||||||
if (constructor.Parameters.Count == parms.ConstructorParameterCount)
|
: EMatchResult.NoMatch;
|
||||||
{
|
|
||||||
score.Score++;
|
|
||||||
return EMatchResult.Match;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return EMatchResult.NoMatch;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ internal static class Fields
|
|||||||
/// <param name="parms"></param>
|
/// <param name="parms"></param>
|
||||||
/// <param name="score"></param>
|
/// <param name="score"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static EMatchResult GetTypeWithFields(TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult IncludeFields(TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.MatchFields is null || parms.MatchFields.Count == 0) return EMatchResult.Disabled;
|
if (parms.MatchFields is null || parms.MatchFields.Count == 0) return EMatchResult.Disabled;
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ internal static class Fields
|
|||||||
/// <param name="parms"></param>
|
/// <param name="parms"></param>
|
||||||
/// <param name="score"></param>
|
/// <param name="score"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static EMatchResult GetTypeWithoutFields(TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult ExcludeFields(TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.IgnoreFields is null || parms.IgnoreFields.Count == 0) return EMatchResult.Disabled;
|
if (parms.IgnoreFields is null || parms.IgnoreFields.Count == 0) return EMatchResult.Disabled;
|
||||||
|
|
||||||
@ -47,8 +47,8 @@ internal static class Fields
|
|||||||
score.Score += matches;
|
score.Score += matches;
|
||||||
|
|
||||||
return matches > 0
|
return matches > 0
|
||||||
? EMatchResult.Match
|
? EMatchResult.NoMatch
|
||||||
: EMatchResult.NoMatch;
|
: EMatchResult.Match;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -58,7 +58,7 @@ internal static class Fields
|
|||||||
/// <param name="parms"></param>
|
/// <param name="parms"></param>
|
||||||
/// <param name="score"></param>
|
/// <param name="score"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static EMatchResult GetTypeByNumberOfFields(TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult MatchFieldCount(TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.FieldCount is null) return EMatchResult.Disabled;
|
if (parms.FieldCount is null) return EMatchResult.Disabled;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ internal static class Methods
|
|||||||
/// <param name="parms"></param>
|
/// <param name="parms"></param>
|
||||||
/// <param name="score"></param>
|
/// <param name="score"></param>
|
||||||
/// <returns>Match if type contains any supplied methods</returns>
|
/// <returns>Match if type contains any supplied methods</returns>
|
||||||
public static EMatchResult GetTypeWithMethods(TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult IncludeMethods(TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.MatchMethods is null || parms.MatchMethods.Count == 0) return EMatchResult.Disabled;
|
if (parms.MatchMethods is null || parms.MatchMethods.Count == 0) return EMatchResult.Disabled;
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ internal static class Methods
|
|||||||
/// <param name="parms"></param>
|
/// <param name="parms"></param>
|
||||||
/// <param name="score"></param>
|
/// <param name="score"></param>
|
||||||
/// <returns>Match if type has no methods</returns>
|
/// <returns>Match if type has no methods</returns>
|
||||||
public static EMatchResult GetTypeWithoutMethods(TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult ExcludeMethods(TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.IgnoreMethods is null || parms.IgnoreMethods.Count == 0) return EMatchResult.Disabled;
|
if (parms.IgnoreMethods is null || parms.IgnoreMethods.Count == 0) return EMatchResult.Disabled;
|
||||||
|
|
||||||
@ -47,11 +47,11 @@ internal static class Methods
|
|||||||
score.Score += matches;
|
score.Score += matches;
|
||||||
|
|
||||||
return matches > 0
|
return matches > 0
|
||||||
? EMatchResult.Match
|
? EMatchResult.NoMatch
|
||||||
: EMatchResult.NoMatch;
|
: EMatchResult.Match;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EMatchResult GetTypeByNumberOfMethods(TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult MatchMethodCount(TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.MethodCount is null) return EMatchResult.Disabled;
|
if (parms.MethodCount is null) return EMatchResult.Disabled;
|
||||||
|
|
||||||
|
@ -1,6 +1,53 @@
|
|||||||
namespace AssemblyRemapper.Remapper.Search
|
using AssemblyRemapper.Enums;
|
||||||
|
using AssemblyRemapper.Models;
|
||||||
|
using Mono.Cecil;
|
||||||
|
using MoreLinq;
|
||||||
|
|
||||||
|
namespace AssemblyRemapper.Remapper.Search
|
||||||
{
|
{
|
||||||
internal class Properties
|
internal class Properties
|
||||||
{
|
{
|
||||||
|
public static EMatchResult IncludeProperties(TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
|
{
|
||||||
|
if (parms.MatchProperties is null || parms.MatchProperties.Count == 0) return EMatchResult.Disabled;
|
||||||
|
|
||||||
|
var matches = type.Properties
|
||||||
|
.Where(property => parms.MatchProperties.Contains(property.Name))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
score.Score += matches;
|
||||||
|
|
||||||
|
return matches > 0
|
||||||
|
? EMatchResult.Match
|
||||||
|
: EMatchResult.NoMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EMatchResult ExcludeProperties(TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
|
{
|
||||||
|
if (parms.IgnorePropterties is null || parms.IgnorePropterties.Count == 0) return EMatchResult.Disabled;
|
||||||
|
|
||||||
|
var matches = type.Properties
|
||||||
|
.Where(property => parms.IgnorePropterties.Contains(property.Name))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
score.Score += matches;
|
||||||
|
|
||||||
|
return matches > 0
|
||||||
|
? EMatchResult.NoMatch
|
||||||
|
: EMatchResult.Match;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EMatchResult MatchPropertyCount(TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
|
{
|
||||||
|
if (parms.PropertyCount is null) return EMatchResult.Disabled;
|
||||||
|
|
||||||
|
var match = type.Properties.Exactly((int)parms.PropertyCount);
|
||||||
|
|
||||||
|
if (match) { score.Score++; }
|
||||||
|
|
||||||
|
return match
|
||||||
|
? EMatchResult.Match
|
||||||
|
: EMatchResult.NoMatch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -202,9 +202,9 @@ internal static class TypeDefExtensions
|
|||||||
{
|
{
|
||||||
var matches = new List<EMatchResult>
|
var matches = new List<EMatchResult>
|
||||||
{
|
{
|
||||||
Methods.GetTypeWithMethods(type, parms, score),
|
Methods.IncludeMethods(type, parms, score),
|
||||||
Methods.GetTypeWithoutMethods(type, parms, score),
|
Methods.ExcludeMethods(type, parms, score),
|
||||||
Methods.GetTypeByNumberOfMethods(type, parms, score)
|
Methods.MatchMethodCount(type, parms, score)
|
||||||
};
|
};
|
||||||
|
|
||||||
// return match if any condition matched
|
// return match if any condition matched
|
||||||
@ -215,9 +215,9 @@ internal static class TypeDefExtensions
|
|||||||
{
|
{
|
||||||
var matches = new List<EMatchResult>
|
var matches = new List<EMatchResult>
|
||||||
{
|
{
|
||||||
Fields.GetTypeWithFields(type, parms, score),
|
Fields.IncludeFields(type, parms, score),
|
||||||
Fields.GetTypeWithoutFields(type, parms, score),
|
Fields.ExcludeFields(type, parms, score),
|
||||||
Fields.GetTypeByNumberOfFields(type, parms, score)
|
Fields.MatchFieldCount(type, parms, score)
|
||||||
};
|
};
|
||||||
|
|
||||||
// return match if any condition matched
|
// return match if any condition matched
|
||||||
@ -226,41 +226,15 @@ internal static class TypeDefExtensions
|
|||||||
|
|
||||||
public static EMatchResult MatchProperties(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult MatchProperties(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.MatchProperties.Count is 0 && parms.IgnorePropterties.Count is 0)
|
var matches = new List<EMatchResult>
|
||||||
{
|
{
|
||||||
return EMatchResult.Disabled;
|
Properties.IncludeProperties(type, parms, score),
|
||||||
}
|
Properties.ExcludeProperties(type, parms, score),
|
||||||
|
Properties.MatchPropertyCount(type, parms, score)
|
||||||
|
};
|
||||||
|
|
||||||
var skippAll = parms.IgnorePropterties.Contains("*");
|
// return match if any condition matched
|
||||||
|
return matches.GetMatch();
|
||||||
// Type has fields, we dont want any
|
|
||||||
if (type.HasProperties is false && skippAll is true)
|
|
||||||
{
|
|
||||||
return EMatchResult.Match;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var property in type.Properties)
|
|
||||||
{
|
|
||||||
if (parms.IgnorePropterties.Contains(property.Name))
|
|
||||||
{
|
|
||||||
// Type contains blacklisted property
|
|
||||||
score.FailureReason = EFailureReason.HasProperties;
|
|
||||||
return EMatchResult.NoMatch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int matchCount = 0;
|
|
||||||
|
|
||||||
foreach (var property in type.Properties)
|
|
||||||
{
|
|
||||||
if (parms.MatchProperties.Contains(property.Name))
|
|
||||||
{
|
|
||||||
matchCount++;
|
|
||||||
score.Score++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return matchCount > 0 ? EMatchResult.Match : EMatchResult.NoMatch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EMatchResult MatchNestedTypes(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult MatchNestedTypes(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
|
@ -14,7 +14,6 @@ internal static class ExtentionMethods
|
|||||||
{
|
{
|
||||||
if (outVal.Definition.Name == model.Definition.Name)
|
if (outVal.Definition.Name == model.Definition.Name)
|
||||||
{
|
{
|
||||||
Logger.Log("Skipping adding duplicate type match to list", ConsoleColor.Yellow);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"Debug": true, // Enables extra debug logging, slows down the program by alot
|
"Debug": false, // Enables extra debug logging, slows down the program by alot
|
||||||
"SilentMode": true, // The tool will stop and prompt you to continue on every remapping if disabled
|
"SilentMode": true, // The tool will stop and prompt you to continue on every remapping if disabled
|
||||||
|
"MaxMatchCount": 5, // Default max matches the remapper will return
|
||||||
"Publicize": true, // Publicize all types, methods, and properties : NOTE: Not run until after the remap has completed
|
"Publicize": true, // Publicize all types, methods, and properties : NOTE: Not run until after the remap has completed
|
||||||
"Unseal": true, // Unseal all types : NOTE: Not run until after the remap has completed
|
"Unseal": true, // Unseal all types : NOTE: Not run until after the remap has completed
|
||||||
"AssemblyPath": "./Data/Managed/Assembly-CSharp.dll", // Path to the assembly we want to remap
|
"AssemblyPath": "./Data/Managed/Assembly-CSharp.dll", // Path to the assembly we want to remap
|
||||||
|
Loading…
x
Reference in New Issue
Block a user