Question: How can I create my own instance of an existing struct?
matl4c opened this issue · comments
I understand how to create an instance of an existing class...
const AssemblyCSharp = Il2Cpp.Domain.assembly("Assembly-CSharp").image;
const interestingClass = Il2Cpp.Domain.class("Some.Namespace.interestingClass");
let myInstanceOfInterestingClass = interestingClass.alloc();
...
If the namespace Some.Namespace
has a struct of interestingStruct
, how would I reference and create my own instance of that?
Create the object, then call Il2Cpp.Object::unbox
to get a Il2Cpp::ValueType
(a struct).
PS: Il2Cpp.Class::alloc
only allocates the instance: its constructor will not be invoked - you need to call it aftwerwards like any other method:
const myInstanceOfInterestingClass = interestingClass.alloc();
myInstanceOfInterestingClass.method(".ctor").invoke(...);
// shorthand to alloc + ctor (but without arguments)
const myInstanceOfInterestingClass = interestingClass.new();