v0.9.0 #401
vfsfitvnm
announced in
Announcements
v0.9.0
#401
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Bind
this
to aIl2Cpp.ValueType
Historically, when overriding a method implementation,
this
was either aIl2Cpp.Class
(in case of static methods) or aIl2Cpp.Object
(in case of instance methods).In the following example, we are trying to hook
UnityEngine.Rect::get_x
(an instance method of a struct), so we write:However, if you run this code on Unity < 2017.x.x (?) or > 2021.2.0, you'll get an access violation error. In fact, in those versions, struct methods are expected to receive structs (or unboxed objects), not pure objects.
(struct methods are those methods that are definited within a struct class definition!)
To address this issue, struct methods now bind
this
toIl2Cpp.ValueType
, always:Keep in mind the difference between an unboxed object and a object is the former is just a pointer to raw data, whereas the latter is a pointer to an header (containing a reference to its class) plus the raw data.
In code:
In other words, unboxing an object simply returns its handle plus the object header size.
Relevant changes
Use @ts-ignore:
If you override a method implementation and specify types for any of its parameters, you now must tell the TypeScript compiler to stop complaining.
Setters cannot have generics, and TypeScript complains if we try to narrow down an union type, sadly. And I don't want to use
any
.Add
Il2Cpp.Class::isStruct
:A property to determine whether the class is a
struct
.Add
Il2Cpp.ValueType::method
andIl2Cpp.ValueType::tryMethod
:You can now invoke methods against value types, without having to box them! Keep in mind only struct methods can be invoked without boxing.
Add
Il2Cpp.Object::monitor
:An object to incapsulate synchronization-related methods. These methods are rarely used, so I decided to move them away from
Il2Cpp.Object
to avoid clogging more significant APIs.Drop
Il2Cpp.Object::enter
,Il2Cpp.Object::exit
,Il2Cpp.Object::pulse
,Il2Cpp.Object::pulseAll
,Il2Cpp.Object::tryEnter
,Il2Cpp.Object::tryWait
andIl2Cpp.Object::wait
:Superseded by
Il2Cpp.Object.Monitor::enter
,Il2Cpp.Object.Monitor::exit
,Il2Cpp.Object.Monitor::pulse
,Il2Cpp.Object.Monitor::pulseAll
,Il2Cpp.Object.Monitor::tryEnter
,Il2Cpp.Object.Monitor::tryWait
andIl2Cpp.Object.Monitor::wait
, respectively.Full Changelog: v0.8.8...v0.9.0
Beta Was this translation helpful? Give feedback.
All reactions