Guest User

Untitled

a guest
Jul 2nd, 2021
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. #include "Offsets.h"
  2. #include <iostream>
  3. #include <Windows.h>
  4. #include <TlHelp32.h>
  5.  
  6. #define EnemyPen 0x000000FF
  7. HBRUSH EnemyBrush = CreateSolidBrush(0x000000FF);
  8.  
  9. int screenX = GetSystemMetrics(SM_CXSCREEN);
  10. int screenY = GetSystemMetrics(SM_CYSCREEN);
  11.  
  12. DWORD GetProcId(const wchar_t* procName)
  13. {
  14. DWORD procId = 0;
  15. HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  16. if (hSnap != INVALID_HANDLE_VALUE)
  17. {
  18. PROCESSENTRY32 procEntry;
  19. procEntry.dwSize = sizeof(procEntry);
  20.  
  21. if (Process32First(hSnap, &procEntry))
  22. {
  23. do
  24. {
  25. if (!_wcsicmp(procEntry.szExeFile, procName))
  26. {
  27. procId = procEntry.th32ProcessID;
  28. break;
  29. }
  30. } while (Process32Next(hSnap, &procEntry));
  31.  
  32. }
  33. }
  34. CloseHandle(hSnap);
  35. return procId;
  36. }
  37.  
  38. uintptr_t GetModuleBaseAddress(DWORD procId, const wchar_t* modName)
  39. {
  40. uintptr_t modBaseAddr = 0;
  41. HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, procId);
  42. if (hSnap != INVALID_HANDLE_VALUE)
  43. {
  44. MODULEENTRY32 modEntry;
  45. modEntry.dwSize = sizeof(modEntry);
  46. if (Module32First(hSnap, &modEntry))
  47. {
  48. do
  49. {
  50. if (!_wcsicmp(modEntry.szModule, modName))
  51. {
  52. modBaseAddr = (uintptr_t)modEntry.modBaseAddr;
  53. break;
  54. }
  55. } while (Module32Next(hSnap, &modEntry));
  56. }
  57. }
  58. CloseHandle(hSnap);
  59. return modBaseAddr;
  60. }
  61.  
  62. uintptr_t moduleBase = GetModuleBaseAddress(GetProcId(L"SpaceEngineers.exe"), L"client_panorama.dll");
  63. HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, NULL, GetProcId(L"SpaceEngineers.exe"));
  64. HDC hdc = GetDC(FindWindowA(NULL, "Space Engineers"));
  65.  
  66. template<typename T> T RPM(SIZE_T address) {
  67. //The buffer for data that is going to be read from memory
  68. T buffer;
  69.  
  70. //The actual RPM
  71. ReadProcessMemory(hProcess, (LPCVOID)address, &buffer, sizeof(T), NULL);
  72.  
  73. //Return our buffer
  74. return buffer;
  75. }
  76.  
  77. struct view_matrix_t {
  78. float* operator[ ](int index) {
  79. return matrix[index];
  80. }
  81.  
  82. float matrix[4][4];
  83. };
  84.  
  85. struct Vector3
  86. {
  87. float x, y, z;
  88. };
  89.  
  90. Vector3 WorldToScreen(const Vector3 pos, view_matrix_t matrix) {
  91. float _x = matrix[0][0] * pos.x + matrix[0][1] * pos.y + matrix[0][2] * pos.z + matrix[0][3];
  92. float _y = matrix[1][0] * pos.x + matrix[1][1] * pos.y + matrix[1][2] * pos.z + matrix[1][3];
  93.  
  94. float w = matrix[3][0] * pos.x + matrix[3][1] * pos.y + matrix[3][2] * pos.z + matrix[3][3];
  95.  
  96. float inv_w = 1.f / w;
  97. _x *= inv_w;
  98. _y *= inv_w;
  99.  
  100. float x = screenX * .5f;
  101. float y = screenY * .5f;
  102.  
  103. x += 0.5f * _x * screenX + 0.5f;
  104. y -= 0.5f * _y * screenY + 0.5f;
  105.  
  106. return { x,y,w };
  107. }
  108.  
  109. void DrawFilledRect(int x, int y, int w, int h)
  110. {
  111. RECT rect = { x, y, x + w, y + h };
  112. FillRect(hdc, &rect, EnemyBrush);
  113. }
  114.  
  115. void DrawBorderBox(int x, int y, int w, int h, int thickness)
  116. {
  117. DrawFilledRect(x, y, w, thickness); //Top horiz line
  118. DrawFilledRect(x, y, thickness, h); //Left vertical line
  119. DrawFilledRect((x + w), y, thickness, h); //right vertical line
  120. DrawFilledRect(x, y + h, w + thickness, thickness); //bottom horiz line
  121. }
  122.  
  123. void DrawLine(float StartX, float StartY, float EndX, float EndY)
  124. {
  125. int a, b = 0;
  126. HPEN hOPen;
  127. HPEN hNPen = CreatePen(PS_SOLID, 2, EnemyPen);// penstyle, width, color
  128. hOPen = (HPEN)SelectObject(hdc, hNPen);
  129. MoveToEx(hdc, StartX, StartY, NULL); //start
  130. a = LineTo(hdc, EndX, EndY); //end
  131. DeleteObject(SelectObject(hdc, hOPen));
  132. }
  133.  
  134. int main()
  135. {
  136. // while (true)
  137. // {
  138. // view_matrix_t vm = RPM<view_matrix_t>(moduleBase + dwViewMatrix);
  139.  
  140. // for (int i = 1; i < 64; i++)
  141. // {
  142. // uintptr_t pEnt = RPM<DWORD>(moduleBase + dwEntityList + (i * 0x10));
  143.  
  144.  
  145. // Vector3 pos = RPM<Vector3>(pEnt + m_vecOrigin);
  146. // Vector3 head;
  147. // head.x = pos.x;
  148. // head.y = pos.y;
  149. // head.z = pos.z + 75.f;
  150. // Vector3 screenpos = WorldToScreen(pos, vm);
  151. // Vector3 screenhead = WorldToScreen(head, vm);
  152. // float height = screenhead.y - screenpos.y;
  153. // float width = height / 2.4f;
  154.  
  155. // if (screenpos.z >= 0.01f) {
  156. // DrawBorderBox(screenpos.x - (width / 2), screenpos.y, width, height, 1);
  157. // DrawLine(screenX / 2, screenY, screenpos.x, screenpos.y);
  158. // }
  159. // }
  160. // }
  161. }
  162.  
  163.  
  164.  
Advertisement
Add Comment
Please, Sign In to add comment