Advertisement
Guest User

Untitled

a guest
May 4th, 2022
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. #include "Nvidia.h"
  2. #include <cstdint>
  3. #include <comdef.h>
  4. #include <thread>
  5.  
  6. namespace memory
  7. {
  8. static DWORD process_id = 14004;
  9. static uint64_t process_base = 0x7ff609700000;
  10. static HANDLE process_handle = NULL;
  11.  
  12. static uint64_t world = 0;
  13. static uint64_t camera = 0;
  14. static uint64_t near_ent_size = 0;
  15. static uint64_t near_ent = 0;
  16.  
  17. template <typename T>
  18. T read(uintptr_t address)
  19. {
  20. T value;
  21. ReadProcessMemory(process_handle, (LPCVOID)address, &value, sizeof(T), NULL);
  22. return value;
  23. }
  24.  
  25. template <typename T>
  26. bool write(uintptr_t address, T value)
  27. {
  28. return WriteProcessMemory(process_handle, (LPVOID)address, &value, sizeof(T), NULL);
  29. }
  30. }
  31. using namespace memory;
  32.  
  33. class Vector3
  34. {
  35. public:
  36. Vector3() : x(0.f), y(0.f), z(0.f)
  37. {
  38.  
  39. }
  40.  
  41. Vector3(float _x, float _y, float _z) : x(_x), y(_y), z(_z)
  42. {
  43.  
  44. }
  45. ~Vector3()
  46. {
  47.  
  48. }
  49.  
  50. float x;
  51. float y;
  52. float z;
  53.  
  54. inline float Dot(Vector3 v)
  55. {
  56. return x * v.x + y * v.y + z * v.z;
  57. }
  58.  
  59. inline float Distance(Vector3 v)
  60. {
  61. return float(sqrtf(powf(v.x - x, 2.0) + powf(v.y - y, 2.0) + powf(v.z - z, 2.0)));
  62. }
  63.  
  64. inline float Length()
  65. {
  66. float ls = x * x + y * y + z * z;
  67. return sqrt(ls);
  68. }
  69.  
  70. float DistTo(const Vector3& vOther) const
  71. {
  72. Vector3 delta;
  73.  
  74. delta.x = x - vOther.x;
  75. delta.y = y - vOther.y;
  76. delta.z = z - vOther.z;
  77.  
  78. return delta.Length();
  79. }
  80.  
  81. bool operator==(const Vector3& in) const {
  82. return (this->x == in.x && this->y == in.y && this->z == in.z);
  83. }
  84.  
  85. Vector3 operator+(Vector3 v)
  86. {
  87. return Vector3(x + v.x, y + v.y, z + v.z);
  88. }
  89.  
  90. Vector3 operator-(Vector3 v)
  91. {
  92. return Vector3(x - v.x, y - v.y, z - v.z);
  93. }
  94.  
  95. Vector3 operator*(float number) const {
  96. return Vector3(x * number, y * number, z * number);
  97. }
  98.  
  99. Vector3& operator/=(float fl) {
  100. x /= fl;
  101. y /= fl;
  102. z /= fl;
  103. return *this;
  104. }
  105.  
  106. Vector3& operator-=(const Vector3& v)
  107. {
  108. x -= v.x;
  109. y -= v.y;
  110. z -= v.z;
  111.  
  112. return *this;
  113. }
  114. };
  115.  
  116. Vector3 get_inverted_view_right()
  117. {
  118. return Vector3(read<Vector3>(camera + 0x8));
  119. }
  120. Vector3 get_inverted_view_up()
  121. {
  122. return Vector3(read<Vector3>(camera + 0x14));
  123. }
  124. Vector3 get_inverted_view_forward()
  125. {
  126. return Vector3(read<Vector3>(camera + 0x20));
  127. }
  128. Vector3 get_viewport_size()
  129. {
  130. return Vector3(read<Vector3>(camera + 0x58));
  131. }
  132. Vector3 get_inverted_view_translation()
  133. {
  134. return Vector3(read<Vector3>(camera + 0x2C));
  135. }
  136. Vector3 get_projection_d1()
  137. {
  138. return Vector3(read<Vector3>(camera + 0xD0));
  139. }
  140. Vector3 get_projection_d2()
  141. {
  142. return Vector3(read<Vector3>(camera + 0xDC));
  143. }
  144. Vector3 world_to_screen(Vector3 position)
  145. {
  146. Vector3 temp = position - get_inverted_view_translation();
  147.  
  148. float x = temp.Dot(get_inverted_view_right());
  149. float y = temp.Dot(get_inverted_view_up());
  150. float z = temp.Dot(get_inverted_view_forward());
  151.  
  152. if (z > 0)
  153. {
  154. return Vector3(get_viewport_size().x * (1 + (x / get_projection_d1().x / z)), get_viewport_size().y * (1 - (y / get_projection_d2().y / z)), z);
  155. }
  156.  
  157. return { 0, 0, 0 };
  158. }
  159. Vector3 get_head_position(uint64_t entity)
  160. {
  161. return Vector3(read<Vector3>(read<uint64_t>(entity + 0xD0) + 0x168));
  162. }
  163. Vector3 get_feet_position(uint64_t entity)
  164. {
  165. return Vector3(read<Vector3>(read<uint64_t>(entity + 0xD0) + 0x2C));
  166. }
  167.  
  168. void create_all()
  169. {
  170. process_handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_id);
  171. world = read<uint64_t>(process_base + 0x26166D8);
  172. camera = read<uint64_t>(world + 0xB50);
  173. near_ent_size = read<uint64_t>(world + 0x1A48);
  174. near_ent = read<uint64_t>(world + 0x1A40);
  175. }
  176.  
  177. int main()
  178. {
  179. CreateThread(0, 0, (LPTHREAD_START_ROUTINE)create_all, 0, 0, 0);
  180.  
  181. Nvidia* overlay = { 0 };
  182.  
  183. // Initialize the window
  184. if (!overlay->window_init())
  185. exit(-1);
  186.  
  187. // D2D Failed to initialize?
  188. if (!overlay->init_d2d())
  189. exit(-1);
  190.  
  191. while (true)
  192. {
  193. overlay->begin_scene();
  194. overlay->clear_scene();
  195.  
  196. for (uint64_t i = 0; i < near_ent_size; i++)
  197. {
  198. uint64_t entity = read<uint64_t>(near_ent + (i * 0x8));
  199.  
  200. Vector3 sh = world_to_screen(get_head_position(entity));
  201.  
  202. overlay->draw_text_red(sh.x, sh.y, "test");
  203. }
  204.  
  205. overlay->end_scene();
  206. }
  207.  
  208. overlay->d2d_shutdown();
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement