From 7d66ea6fd5e5e9c865c7afb616b98e2918c390de Mon Sep 17 00:00:00 2001 From: Inori Date: Thu, 1 Aug 2019 01:14:49 -0400 Subject: [PATCH] Make getPrivateDataCheck more accurate --- binding/binding-util.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/binding/binding-util.h b/binding/binding-util.h index 2a34d893..3159b49c 100644 --- a/binding/binding-util.h +++ b/binding/binding-util.h @@ -186,13 +186,18 @@ getPrivateDataCheck(VALUE self, const char *type) { #ifndef OLD_RUBY void *obj = Check_TypedStruct(self, &type); -#else +#else // RGSS1 works in a more permissive way than the above, + // See the function at ram:10012AB0 in RGSS104E for an example + // This isn't an exact replica, but should have pretty much the same result rb_check_type(self, T_DATA); - /* RMXP apparently didn't check for this? - const char *ownname = rb_obj_classname(self); - if (strcmp(ownname, type)) - rb_raise(rb_eTypeError, "Type mismatch between %s and %s", ownname, type); - */ + VALUE otherObj = rb_const_get(rb_cObject, rb_intern(type)); + const char *ownname, *othername; + if (!rb_obj_is_kind_of(self, otherObj)) + { + ownname = rb_obj_classname(self); + othername = rb_obj_classname(otherObj); + rb_raise(rb_eTypeError, "Can't convert %s into %s", othername, ownname); + } void *obj = DATA_PTR(self); #endif