mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-04 12:58:20 +00:00
Rewrite nested types
Fixes zero-RVA exception for OpenGL extensions (e.g. GL.Ext etc)
This commit is contained in:
parent
c369bfc75e
commit
6bde1beb91
|
@ -127,31 +127,14 @@ namespace OpenTK.Rewrite
|
||||||
var entry_points = type.Fields.FirstOrDefault(f => f.Name == "EntryPoints");
|
var entry_points = type.Fields.FirstOrDefault(f => f.Name == "EntryPoints");
|
||||||
if (entry_points != null)
|
if (entry_points != null)
|
||||||
{
|
{
|
||||||
// Build list of entry point signatures and slots
|
// Build list of entry point signatures (one per entry point)
|
||||||
var native_signatures = new List<MethodDefinition>();
|
var entry_signatures = new List<MethodDefinition>();
|
||||||
native_signatures.AddRange(type.Methods
|
entry_signatures.AddRange(type.Methods
|
||||||
.Where(t => t.CustomAttributes.Any(a => a.AttributeType.Name == "SlotAttribute")));
|
.Where(t => t.CustomAttributes.Any(a => a.AttributeType.Name == "SlotAttribute")));
|
||||||
|
|
||||||
// Rewrite all wrapper methods
|
Rewrite(type, entry_points, entry_signatures);
|
||||||
var wrapper_signatures = new List<MethodDefinition>();
|
|
||||||
wrapper_signatures.AddRange(type.Methods
|
|
||||||
.Where(m => m.IsPublic && m.CustomAttributes.Any(a => a.AttributeType.Name == "AutoGeneratedAttribute")));
|
|
||||||
|
|
||||||
foreach (var wrapper in wrapper_signatures)
|
RemoveNativeSignatures(type, entry_signatures);
|
||||||
{
|
|
||||||
var signature_name = (string)wrapper.CustomAttributes
|
|
||||||
.First(a => a.AttributeType.Name == "AutoGeneratedAttribute")
|
|
||||||
.Fields.First(f => f.Name == "EntryPoint").Argument.Value;
|
|
||||||
var signature = native_signatures.First(s => s.Name == signature_name);
|
|
||||||
var slot = (int)signature.CustomAttributes
|
|
||||||
.First(a => a.AttributeType.Name == "SlotAttribute")
|
|
||||||
.ConstructorArguments[0].Value;
|
|
||||||
|
|
||||||
ProcessMethod(wrapper, signature, slot, entry_points);
|
|
||||||
}
|
|
||||||
|
|
||||||
RemoveNativeSignatures(type, native_signatures);
|
|
||||||
RemoveSupportingAttributes(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.Name == "RewrittenAttribute")
|
if (type.Name == "RewrittenAttribute")
|
||||||
|
@ -162,6 +145,42 @@ namespace OpenTK.Rewrite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Rewrite(TypeDefinition type, FieldDefinition entry_points,
|
||||||
|
List<MethodDefinition> entry_signatures)
|
||||||
|
{
|
||||||
|
// Rewrite all wrapper methods
|
||||||
|
var wrapper_signatures = new List<MethodDefinition>();
|
||||||
|
wrapper_signatures.AddRange(type.Methods
|
||||||
|
.Where(m => m.IsPublic && m.CustomAttributes.Any(a => a.AttributeType.Name == "AutoGeneratedAttribute")));
|
||||||
|
|
||||||
|
foreach (var wrapper in wrapper_signatures)
|
||||||
|
{
|
||||||
|
var autogenerated = wrapper.CustomAttributes
|
||||||
|
.Where(a => a.AttributeType.Name == "AutoGeneratedAttribute");
|
||||||
|
if (autogenerated.Count() > 0)
|
||||||
|
{
|
||||||
|
var signature_name = (string)autogenerated.First()
|
||||||
|
.Fields.First(f => f.Name == "EntryPoint").Argument.Value;
|
||||||
|
var signature = entry_signatures.First(s => s.Name == signature_name);
|
||||||
|
var slot = (int)signature.CustomAttributes
|
||||||
|
.First(a => a.AttributeType.Name == "SlotAttribute")
|
||||||
|
.ConstructorArguments[0].Value;
|
||||||
|
|
||||||
|
ProcessMethod(wrapper, signature, slot, entry_points);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoveSupportingAttributes(type);
|
||||||
|
|
||||||
|
if (type.NestedTypes.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var nested_type in type.NestedTypes)
|
||||||
|
{
|
||||||
|
Rewrite(nested_type, entry_points, entry_signatures);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RemoveNativeSignatures(TypeDefinition type, List<MethodDefinition> methods)
|
void RemoveNativeSignatures(TypeDefinition type, List<MethodDefinition> methods)
|
||||||
{
|
{
|
||||||
while (methods.Count > 0)
|
while (methods.Count > 0)
|
||||||
|
|
Loading…
Reference in a new issue