mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-13 01:50:45 -05:00
clean up Publicizer
This commit is contained in:
parent
b3a676f044
commit
6fd351e2ba
@ -6,14 +6,10 @@ namespace ReCodeIt.ReMapper;
|
|||||||
|
|
||||||
internal static class SPTPublicizer
|
internal static class SPTPublicizer
|
||||||
{
|
{
|
||||||
private static ModuleDefMD? MainModule;
|
|
||||||
|
|
||||||
public static void PublicizeClasses(ModuleDefMD definition, bool isLauncher = false)
|
public static void PublicizeClasses(ModuleDefMD definition, bool isLauncher = false)
|
||||||
{
|
{
|
||||||
var types = definition.GetTypes();
|
var types = definition.GetTypes();
|
||||||
|
|
||||||
MainModule = definition;
|
|
||||||
|
|
||||||
var typeCount = types.Where(t => !t.IsNested).Count();
|
var typeCount = types.Where(t => !t.IsNested).Count();
|
||||||
var count = 0;
|
var count = 0;
|
||||||
foreach (var type in types)
|
foreach (var type in types)
|
||||||
@ -55,25 +51,7 @@ internal static class SPTPublicizer
|
|||||||
if (property.GetMethod != null) PublicizeMethod(property.GetMethod);
|
if (property.GetMethod != null) PublicizeMethod(property.GetMethod);
|
||||||
if (property.SetMethod != null) PublicizeMethod(property.SetMethod);
|
if (property.SetMethod != null) PublicizeMethod(property.SetMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
// var eventNames = new HashSet<string>(type.Events.Select(e => e.Name)); foreach (var field
|
|
||||||
// in type.Fields) { if (eventNames.Contains(field.Name)) { continue; }
|
|
||||||
//
|
|
||||||
// // if (type.Name.StartsWith("GClass") || !type.Namespace.Contains("EFT") ||
|
|
||||||
// !type.Namespace.Contains("UI") || !string.IsNullOrWhiteSpace(type.Namespace)) // if
|
|
||||||
// (type.Namespace.Length > 0 && type.Namespace[0] > 'E') PublicizeField(field); }
|
|
||||||
|
|
||||||
// Workaround to not publicize some nested types that cannot be patched easily and cause
|
|
||||||
// issues Specifically, we want to find any type that implements the "IHealthController"
|
|
||||||
// interface and make sure none of it's nested types that implement "IEffect" are changed
|
|
||||||
/*
|
|
||||||
if (GetFlattenedInterfacesRecursive(type).Any(i => i.Interface.Name == "IHealthController"))
|
|
||||||
{
|
|
||||||
// Specifically, any type that implements the IHealthController interface needs to not
|
|
||||||
// publicize any nested types that implement the IEffect interface
|
|
||||||
nestedTypesToPublicize = type.NestedTypes.Where(t => t.IsAbstract || t.Interfaces.All(i => i.Interface.Name != "IEffect")).ToArray();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
foreach (var nestedType in type.NestedTypes)
|
foreach (var nestedType in type.NestedTypes)
|
||||||
{
|
{
|
||||||
PublicizeType(nestedType, isLauncher);
|
PublicizeType(nestedType, isLauncher);
|
||||||
@ -97,48 +75,4 @@ internal static class SPTPublicizer
|
|||||||
method.Attributes &= ~MethodAttributes.MemberAccessMask;
|
method.Attributes &= ~MethodAttributes.MemberAccessMask;
|
||||||
method.Attributes |= MethodAttributes.Public;
|
method.Attributes |= MethodAttributes.Public;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unused for now - publicizing fields is tricky, as it often creates MonoBehaviour loading
|
|
||||||
// errors and prevents scenes from loading, most notably breaking the initial game loader scene
|
|
||||||
// and causing the game to CTD right after starting
|
|
||||||
private static void PublicizeField(FieldDef field)
|
|
||||||
{
|
|
||||||
if (field.CustomAttributes.Any(a => a.AttributeType.Name == nameof(CompilerGeneratedAttribute))
|
|
||||||
// || field.HasCustomAttributes
|
|
||||||
|| field.Name.StartsWith("delegate")
|
|
||||||
|| field.Name.Contains("__BackingField"))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (field.IsPublic || field.IsCompilerControlled || field.IsLiteral || field.IsStatic || field.IsInitOnly) return;
|
|
||||||
|
|
||||||
field.Attributes &= ~FieldAttributes.FieldAccessMask;
|
|
||||||
field.Attributes |= FieldAttributes.Public;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<InterfaceImpl> GetFlattenedInterfacesRecursive(TypeDef type)
|
|
||||||
{
|
|
||||||
var interfaces = new List<InterfaceImpl>();
|
|
||||||
|
|
||||||
if (type is null) return interfaces;
|
|
||||||
|
|
||||||
if (type.Interfaces.Any())
|
|
||||||
{
|
|
||||||
interfaces.AddRange(type.Interfaces);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.BaseType != null && !type.BaseType.Name.Contains("Object"))
|
|
||||||
{
|
|
||||||
var baseTypeDefinition = MainModule?.Find(type.BaseType).ResolveTypeDef();
|
|
||||||
var baseTypeInterfaces = GetFlattenedInterfacesRecursive(baseTypeDefinition!);
|
|
||||||
|
|
||||||
if (baseTypeInterfaces.Any())
|
|
||||||
{
|
|
||||||
interfaces.AddRange(baseTypeInterfaces);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return interfaces;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user