using dnlib.DotNet; using ReCodeItLib.Utils; namespace ReCodeItLib.ReMapper; internal class Publicizer { public void PublicizeType(TypeDef type) { // if (type.CustomAttributes.Any(a => a.AttributeType.Name == // nameof(CompilerGeneratedAttribute))) { return; } if (!type.IsNested && !type.IsPublic || type.IsNested && !type.IsNestedPublic) { if (!type.Interfaces.Any(i => i.Interface.Name == "IEffect")) { type.Attributes &= ~TypeAttributes.VisibilityMask; // Remove all visibility mask attributes type.Attributes |= type.IsNested ? TypeAttributes.NestedPublic : TypeAttributes.Public; // Apply a public visibility attribute } } if (type.IsSealed) { type.Attributes &= ~TypeAttributes.Sealed; // Remove the Sealed attribute if it exists } foreach (var method in type.Methods) { PublicizeMethod(method); } foreach (var property in type.Properties) { if (property.GetMethod != null) PublicizeMethod(property.GetMethod); if (property.SetMethod != null) PublicizeMethod(property.SetMethod); } foreach (var nestedType in type.NestedTypes) { PublicizeType(nestedType); } } private static void PublicizeMethod(MethodDef method) { if (method.IsCompilerControlled /*|| method.CustomAttributes.Any(a => a.AttributeType.Name == nameof(CompilerGeneratedAttribute))*/) { return; } if (method.IsPublic) return; // if (!CanPublicizeMethod(method)) return; // Workaround to not publicize a specific method so the game doesn't crash if (method.Name == "TryGetScreen") return; method.Attributes &= ~MethodAttributes.MemberAccessMask; method.Attributes |= MethodAttributes.Public; } }