Fix IsPublic and move publicizer out of the remapper

This commit is contained in:
Cj 2024-06-12 20:16:12 -04:00
parent ce86e9dd15
commit 34434e1a50
3 changed files with 67 additions and 55 deletions

View File

@ -0,0 +1,56 @@
using AssemblyRemapper.Utils;
namespace AssemblyRemapper.Reflection;
internal static class Publicizer
{
public static void Publicize()
{
if (!DataProvider.AppSettings.Publicize) { return; }
Logger.Log("Starting publicization...", ConsoleColor.Green);
foreach (var type in DataProvider.ModuleDefinition.Types)
{
if (type.IsNotPublic) { type.IsPublic = true; }
// We only want to do methods and properties
if (type.HasMethods)
{
foreach (var method in type.Methods)
{
method.IsPublic = true;
}
}
if (type.HasProperties)
{
foreach (var property in type.Properties)
{
if (property.SetMethod != null)
{
property.SetMethod.IsPublic = true;
}
if (property.GetMethod != null)
{
property.GetMethod.IsPublic = true;
}
}
}
}
}
public static void Unseal()
{
if (!DataProvider.AppSettings.Unseal) { return; }
Logger.Log("Starting unseal...", ConsoleColor.Green);
foreach (var type in DataProvider.ModuleDefinition.Types)
{
if (type.IsSealed) { type.IsSealed = false; }
}
}
}

View File

@ -23,8 +23,8 @@ internal class Remapper
if (DataProvider.AppSettings.ScoringMode) { return; } if (DataProvider.AppSettings.ScoringMode) { return; }
// Dont publicize and unseal until after the remapping so we can use those as search parameters // Dont publicize and unseal until after the remapping so we can use those as search parameters
HandlePublicize(); Publicizer.Publicize();
HandleUnseal(); Publicizer.Unseal();
// We are done, write the assembly // We are done, write the assembly
WriteAssembly(); WriteAssembly();
@ -53,56 +53,6 @@ internal class Remapper
} }
} }
private void HandlePublicize()
{
if (!DataProvider.AppSettings.Publicize) { return; }
Logger.Log("Starting publicization...", ConsoleColor.Green);
foreach (var type in DataProvider.ModuleDefinition.Types)
{
if (type.IsNotPublic) { type.IsPublic = true; }
// We only want to do methods and properties
if (type.HasMethods)
{
foreach (var method in type.Methods)
{
method.IsPublic = true;
}
}
if (type.HasProperties)
{
foreach (var property in type.Properties)
{
if (property.SetMethod != null)
{
property.SetMethod.IsPublic = true;
}
if (property.GetMethod != null)
{
property.GetMethod.IsPublic = true;
}
}
}
}
}
private void HandleUnseal()
{
if (!DataProvider.AppSettings.Unseal) { return; }
Logger.Log("Starting unseal...", ConsoleColor.Green);
foreach (var type in DataProvider.ModuleDefinition.Types)
{
if (type.IsSealed) { type.IsSealed = false; }
}
}
private EFailureReason ScoreType(TypeDefinition type, RemapModel remap, string parentTypeName = "") private EFailureReason ScoreType(TypeDefinition type, RemapModel remap, string parentTypeName = "")
{ {
// Handle Direct Remaps by strict naming first bypasses everything else // Handle Direct Remaps by strict naming first bypasses everything else
@ -192,6 +142,7 @@ internal class Remapper
return EFailureReason.HasNestedTypes; return EFailureReason.HasNestedTypes;
} }
remap.OriginalTypeName = type.Name;
score.AddScoreToResult(); score.AddScoreToResult();
return EFailureReason.None; return EFailureReason.None;
@ -204,6 +155,8 @@ internal class Remapper
var oldName = type.Name; var oldName = type.Name;
type.Name = remap.NewTypeName; type.Name = remap.NewTypeName;
remap.OriginalTypeName = type.Name;
Logger.Log("-----------------------------------------------", ConsoleColor.Green); Logger.Log("-----------------------------------------------", ConsoleColor.Green);
Logger.Log($"Renamed {oldName} to {type.Name} directly", ConsoleColor.Green); Logger.Log($"Renamed {oldName} to {type.Name} directly", ConsoleColor.Green);

View File

@ -139,9 +139,12 @@ internal static class SearchProvider
return EMatchResult.Disabled; return EMatchResult.Disabled;
} }
var boolToCheck = parms.IsPublic == true ? type.IsPublic : type.IsNotPublic; if (parms.IsPublic is false && type.IsNotPublic is true)
{
if (boolToCheck == !parms.IsPublic) score.Score++;
return EMatchResult.Match;
}
else if (parms.IsPublic is true && type.IsPublic is true)
{ {
score.Score++; score.Score++;
return EMatchResult.Match; return EMatchResult.Match;