Skip to content

Commit

Permalink
Construct non-blittable value types like objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasuromi committed Oct 30, 2023
1 parent e8d1acb commit a342054
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,12 @@ public static void DoPass(RewriteGlobalContext context)

typeContext.NewType.Methods.Add(emptyCtor);

var local0 = new VariableDefinition(assemblyContext.Imports.Module.IntPtr());
emptyCtor.Body.Variables.Add(local0);

// NOTE(Kas): This used to stackalloc data of the valuetype's size and box it into an object
// but it seems like it caused issues on certain games. If more issues arise - revert this.
var bodyBuilder = emptyCtor.Body.GetILProcessor();
bodyBuilder.Emit(OpCodes.Ldsfld, typeContext.ClassPointerFieldRef);
bodyBuilder.Emit(OpCodes.Ldc_I4_0);
bodyBuilder.Emit(OpCodes.Conv_U);
bodyBuilder.Emit(OpCodes.Call, assemblyContext.Imports.IL2CPP_il2cpp_class_value_size.Value);
bodyBuilder.Emit(OpCodes.Conv_U);
bodyBuilder.Emit(OpCodes.Localloc);
bodyBuilder.Emit(OpCodes.Stloc_0);
bodyBuilder.Emit(OpCodes.Ldarg_0);
bodyBuilder.Emit(OpCodes.Ldsfld, typeContext.ClassPointerFieldRef);
bodyBuilder.Emit(OpCodes.Ldloc_0);
bodyBuilder.Emit(OpCodes.Call, assemblyContext.Imports.IL2CPP_il2cpp_value_box.Value);
bodyBuilder.Emit(OpCodes.Call, assemblyContext.Imports.IL2CPP_il2cpp_object_new.Value);
bodyBuilder.Emit(OpCodes.Call,
new MethodReference(".ctor", assemblyContext.Imports.Module.Void(), typeContext.NewType.BaseType)
{
Expand Down

0 comments on commit a342054

Please sign in to comment.