Skip to content

Commit 9163f2a

Browse files
committed
Unstripped abstract members should be made virtual
Also, don't unstrip pinvoke methods Related: #7
1 parent ce94d2d commit 9163f2a

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

Il2CppInterop.Generator/UnstripBaseProcessingLayer.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Cpp2IL.Core.Logging;
55
using Cpp2IL.Core.Model.Contexts;
66
using Cpp2IL.Core.Model.CustomAttributes;
7+
using Il2CppInterop.Generator.Operands;
78
using LibCpp2IL.BinaryStructures;
89

910
namespace Il2CppInterop.Generator;
@@ -128,6 +129,12 @@ protected static void InjectAssemblies(ApplicationAnalysisContext appContext, IR
128129
Dictionary<MethodDefinition, MethodAnalysisContext> methodLookup = new();
129130
foreach (var method in type.Methods)
130131
{
132+
if (method.IsPInvokeImpl)
133+
{
134+
// No p/invoke methods
135+
continue;
136+
}
137+
131138
if (TryInjectMethod(method, typeContext, out var methodContext))
132139
{
133140
methodLookup.Add(method, methodContext);
@@ -193,11 +200,33 @@ protected static void InjectAssemblies(ApplicationAnalysisContext appContext, IR
193200
continue;
194201
}
195202

203+
if (method.IsPInvokeImpl)
204+
{
205+
// No p/invoke methods
206+
continue;
207+
}
208+
196209
if (!TryInjectMethod(method, typeContext, out var methodContext))
197210
continue;
198211

199212
methodLookup.Add(method, methodContext);
200-
methodsNeedingBodies.Add((methodContext, method));
213+
if (method.IsAbstract)
214+
{
215+
methodContext.Attributes &= ~System.Reflection.MethodAttributes.Abstract; // We convert abstract methods to virtual methods
216+
217+
methodContext.PutExtraData(new OriginalMethodBody()
218+
{
219+
Instructions =
220+
[
221+
new Instruction(CilOpCodes.Ldnull),
222+
new Instruction(CilOpCodes.Throw),
223+
]
224+
});
225+
}
226+
else
227+
{
228+
methodsNeedingBodies.Add((methodContext, method));
229+
}
201230

202231
foreach (var implementation in type.MethodImplementations)
203232
{

0 commit comments

Comments
 (0)