How can I create a new instance of a Ray struct? #336
-
I want to call a method with a custom Ray object. A ray has a constructor of Vector3 Origin and Vector3 Direction, these are also structs. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I managed to do this, but i am myself still a little bit confused about how the import 'frida-il2cpp-bridge';
const log = console.log.bind(console);
function Vector3(x = 0, y = 0, z = 0) {
const Vector3 = Il2Cpp.domain.assembly('UnityEngine.CoreModule').image.class('UnityEngine.Vector3');
const vector3 = Vector3.alloc();
vector3.method('.ctor', 3).invoke(x, y, z);
return vector3;
}
function Ray(origin = Vector3(), direction = Vector3(0, 0, 1)) {
const Ray = Il2Cpp.domain.assembly('UnityEngine.CoreModule').image.class('UnityEngine.Ray');
const ray = Ray.alloc();
ray.method('.ctor', 2).invoke(origin.unbox(), direction.unbox());
return ray;
}
Il2Cpp.perform(() => {
const origin = Vector3();
const direction = Vector3(10, 20, 30);
const ray = Ray(origin, direction);
log();
log('ray', ray);
log('GetPoint', ray.method('GetPoint', 1).invoke(10));
}); |
Beta Was this translation helpful? Give feedback.
-
and also, instead of changing the ray reference, you could just call the |
Beta Was this translation helpful? Give feedback.
I managed to do this, but i am myself still a little bit confused about how the
unbox
work maybe @vfsfitvnm will have a good explanation for all of us