Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. from ctypes import *
  2. import sys
  3. class memoryHacks:
  4. # WARNNING: from_address(NULL) will not fire an exception, it will HARD CRASH python and the server, ALWAYS check for nulls
  5.  
  6. if "linux" in sys.platform:
  7. # TODO
  8. # - vptr might be somewhere else on linux compilers (https://en.wikipedia.org/wiki/Virtual_method_table)
  9. # - All unknowns offsets need to be checked, they might have 64bit pointers there changing the offset
  10. class PhysicalObject(Structure):
  11. _fields_ = [("vptr", c_void_p),
  12. ("ObjectFlags", c_int32),
  13. ("unknown1", c_int8 * 4),
  14. ("Obj_Root", c_void_p),
  15. ("object_id", c_int32),
  16. ("Obj_Template", c_void_p),
  17. ("unknown2", c_int8 * 16),
  18. ("object_hierarchy_root", c_void_p),
  19. ("object_hierarchy_left", c_void_p),
  20. ("object_hierarchy_right", c_void_p),
  21. ("unknown3", c_int8 * 4),
  22. ("object_mesh", c_void_p),
  23. ("Health", c_void_p), # CHealth Object
  24. ("object_collision", c_void_p),
  25. ("Obj_Physics", c_void_p),
  26. ("unknown4", c_int8 * 64),
  27. ("Matrix", c_int8 * 40),
  28. ("Matrix_Transpose", c_int8 * 40),
  29. ("unknown5", c_int8 * 28),
  30. ("boundingSphereRadius", c_float),
  31. ("unknown6", c_int8 * 28),
  32. ("object_name", c_char * 0x1c),
  33. ("unknown7", c_int8 * 40),
  34. ("object_end", c_int32),
  35. ]
  36.  
  37. elif "win" in sys.platform:
  38. class PhysicalObject(Structure):
  39. _fields_ = [("vptr", c_void_p),
  40. ("ObjectFlags", c_int32),
  41. ("unknown1", c_int8 * 4),
  42. ("Obj_Root", c_void_p),
  43. ("object_id", c_int32),
  44. ("Obj_Template", c_void_p),
  45. ("unknown2", c_int8 * 16),
  46. ("object_hierarchy_root", c_void_p),
  47. ("object_hierarchy_left", c_void_p),
  48. ("object_hierarchy_right", c_void_p),
  49. ("unknown3", c_int8 * 4),
  50. ("object_mesh", c_void_p),
  51. ("Health", c_void_p), # CHealth Object
  52. ("object_collision", c_void_p),
  53. ("Obj_Physics", c_void_p),
  54. ("unknown4", c_int8 * 64),
  55. ("Matrix", c_int8 * 40),
  56. ("Matrix_Transpose", c_int8 * 40),
  57. ("unknown5", c_int8 * 28),
  58. ("boundingSphereRadius", c_float),
  59. ("unknown6", c_int8 * 28),
  60. ("object_name", c_char * 0x1c),
  61. ("unknown7", c_int8 * 40),
  62. ("object_end", c_int32),
  63. ]
  64.  
  65.  
  66. # May return NULL!!!! Check return value!
  67. @classmethod
  68. def _pointerWalk(cls, start, *offsets):
  69. ptr = start
  70. for offset in offsets:
  71. if ptr == 0:
  72. raise Exception('Attempt to dereference null! input: s: %s, offsets: %s' % (start, str(offsets)))
  73.  
  74. ptr = c_void_p.from_address(ptr + offset).value
  75.  
  76. return ptr
  77.  
  78. @classmethod
  79. def _getPhysicalObjectEngine(cls, pythonObject):
  80. if not hasattr(pythonObject, 'token'):
  81. raise Exception('Token missing from object! Are you sure this is a PhysicalObject?')
  82.  
  83. tokenPythonAddress = id(pythonObject.token)
  84. ptr = cls._pointerWalk(tokenPythonAddress, 4 + sizeof(c_void_p), 0, 4)
  85. if ptr == 0:
  86. raise Exception('Object is null')
  87.  
  88. return cls.PhysicalObject.from_address(ptr)
  89.  
  90. @classmethod
  91. def getObjectId(cls, obj):
  92. engineobj = cls._getPhysicalObjectEngine(obj)
  93. return engineobj.object_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement