Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ctypes import *
- import sys
- class memoryHacks:
- # WARNNING: from_address(NULL) will not fire an exception, it will HARD CRASH python and the server, ALWAYS check for nulls
- if "linux" in sys.platform:
- # TODO
- # - vptr might be somewhere else on linux compilers (https://en.wikipedia.org/wiki/Virtual_method_table)
- # - All unknowns offsets need to be checked, they might have 64bit pointers there changing the offset
- class PhysicalObject(Structure):
- _fields_ = [("vptr", c_void_p),
- ("ObjectFlags", c_int32),
- ("unknown1", c_int8 * 4),
- ("Obj_Root", c_void_p),
- ("object_id", c_int32),
- ("Obj_Template", c_void_p),
- ("unknown2", c_int8 * 16),
- ("object_hierarchy_root", c_void_p),
- ("object_hierarchy_left", c_void_p),
- ("object_hierarchy_right", c_void_p),
- ("unknown3", c_int8 * 4),
- ("object_mesh", c_void_p),
- ("Health", c_void_p), # CHealth Object
- ("object_collision", c_void_p),
- ("Obj_Physics", c_void_p),
- ("unknown4", c_int8 * 64),
- ("Matrix", c_int8 * 40),
- ("Matrix_Transpose", c_int8 * 40),
- ("unknown5", c_int8 * 28),
- ("boundingSphereRadius", c_float),
- ("unknown6", c_int8 * 28),
- ("object_name", c_char * 0x1c),
- ("unknown7", c_int8 * 40),
- ("object_end", c_int32),
- ]
- elif "win" in sys.platform:
- class PhysicalObject(Structure):
- _fields_ = [("vptr", c_void_p),
- ("ObjectFlags", c_int32),
- ("unknown1", c_int8 * 4),
- ("Obj_Root", c_void_p),
- ("object_id", c_int32),
- ("Obj_Template", c_void_p),
- ("unknown2", c_int8 * 16),
- ("object_hierarchy_root", c_void_p),
- ("object_hierarchy_left", c_void_p),
- ("object_hierarchy_right", c_void_p),
- ("unknown3", c_int8 * 4),
- ("object_mesh", c_void_p),
- ("Health", c_void_p), # CHealth Object
- ("object_collision", c_void_p),
- ("Obj_Physics", c_void_p),
- ("unknown4", c_int8 * 64),
- ("Matrix", c_int8 * 40),
- ("Matrix_Transpose", c_int8 * 40),
- ("unknown5", c_int8 * 28),
- ("boundingSphereRadius", c_float),
- ("unknown6", c_int8 * 28),
- ("object_name", c_char * 0x1c),
- ("unknown7", c_int8 * 40),
- ("object_end", c_int32),
- ]
- # May return NULL!!!! Check return value!
- @classmethod
- def _pointerWalk(cls, start, *offsets):
- ptr = start
- for offset in offsets:
- if ptr == 0:
- raise Exception('Attempt to dereference null! input: s: %s, offsets: %s' % (start, str(offsets)))
- ptr = c_void_p.from_address(ptr + offset).value
- return ptr
- @classmethod
- def _getPhysicalObjectEngine(cls, pythonObject):
- if not hasattr(pythonObject, 'token'):
- raise Exception('Token missing from object! Are you sure this is a PhysicalObject?')
- tokenPythonAddress = id(pythonObject.token)
- ptr = cls._pointerWalk(tokenPythonAddress, 4 + sizeof(c_void_p), 0, 4)
- if ptr == 0:
- raise Exception('Object is null')
- return cls.PhysicalObject.from_address(ptr)
- @classmethod
- def getObjectId(cls, obj):
- engineobj = cls._getPhysicalObjectEngine(obj)
- return engineobj.object_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement