Advertisement
Guest User

Untitled

a guest
Jan 19th, 2021
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <d3d9.h>
  4. #include <d3dx9.h>
  5.  
  6. #pragma comment(lib, "d3d9.lib")
  7. #pragma comment(lib, "d3dx9.lib")
  8.  
  9. #include "detours.h"
  10. #pragma comment(lib, "detours.lib")
  11.  
  12. INT SCREEN_WIDTH = 1440;
  13. INT SCREEN_HEIGHT = 900;
  14.  
  15. HINSTANCE DllHandle;
  16.  
  17. typedef HRESULT(__stdcall* endScene)(IDirect3DDevice9* pDevice);
  18. endScene pEndScene;
  19.  
  20. LPD3DXFONT font;
  21. using namespace std;
  22.  
  23. struct Vec3
  24. {
  25. float x, y, z;
  26. };
  27.  
  28. struct Vec4
  29. {
  30. float x, y, z, w;
  31. };
  32.  
  33. struct Vec2
  34. {
  35. float x, y;
  36. };
  37.  
  38. float Matrix[16];
  39. Vec2 vScreen;
  40. DWORD gameModule;
  41. DWORD gameModuleS;
  42. DWORD viewMatrix = 0x5ADBF8;
  43. DWORD entityList = 0x4D3904;
  44. DWORD gameModuleEntity;
  45. DWORD vecOrigin = 0x260;
  46. DWORD localPlayer;
  47. DWORD healthhh = 0x94;
  48. DWORD iTeamNum = 0x9C;
  49. DWORD isdormant = 0x17E;
  50. DWORD dwLocalPlayer = 0xD8B2AC;
  51. DWORD isDormat;
  52. //defining our vectors
  53.  
  54.  
  55. bool WorldToScreen(Vec3 pos, Vec2& screen, float matrix[16], int windowWidth, int windowHeight)
  56. {
  57. Vec4 clipCoords;
  58. clipCoords.x = pos.x * matrix[0] + pos.y * matrix[1] + pos.z * matrix[2] + matrix[3];
  59. clipCoords.y = pos.x * matrix[4] + pos.y * matrix[5] + pos.z * matrix[6] + matrix[7];
  60. clipCoords.z = pos.x * matrix[8] + pos.y * matrix[9] + pos.z * matrix[10] + matrix[11];
  61. clipCoords.w = pos.x * matrix[12] + pos.y * matrix[13] + pos.z * matrix[14] + matrix[15];
  62.  
  63. if (clipCoords.w < 0.1f)
  64. return false;
  65.  
  66.  
  67. Vec3 NDC;
  68. NDC.x = clipCoords.x / clipCoords.w;
  69. NDC.y = clipCoords.y / clipCoords.w;
  70. NDC.z = clipCoords.z / clipCoords.w;
  71.  
  72. screen.x = (windowWidth / 2 * NDC.x) + (NDC.x + windowWidth / 2);
  73. screen.y = -(windowHeight / 2 * NDC.y) + (NDC.y + windowHeight / 2);
  74. return true;
  75. }
  76.  
  77. void Line(float x1, float y1, float x2, float y2, float width, bool antilias, DWORD color,LPDIRECT3DDEVICE9 pDevice) {
  78. ID3DXLine* line;
  79. D3DXCreateLine(pDevice, &line);
  80. D3DXVECTOR2 linePos[] = { D3DXVECTOR2(x1,y1),D3DXVECTOR2(x2,y2) };
  81. line->SetWidth(width);
  82. if (antilias) {
  83. line->SetAntialias(antilias);
  84. }
  85. line->Begin();
  86. line->Draw(linePos, 2, color);
  87. line->End();
  88. line->Release();
  89. }
  90.  
  91. HRESULT __stdcall hookedEndScene(IDirect3DDevice9* pDevice) {
  92. //now here we can create our own graphics
  93. int padding = 2;
  94. int rectx1 = 100, rectx2 = 300, recty1 = 50, recty2 = 100;
  95. D3DRECT rectangle = { rectx1, recty1, rectx2, recty2 };
  96. pDevice->Clear(1, &rectangle, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0, 0, 0), 0.0f, 0); // this draws a rectangle
  97. if (!font)
  98. D3DXCreateFont(pDevice, 16, 0, FW_BOLD, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &font);
  99. RECT textRectangle;
  100. SetRect(&textRectangle, rectx1 + padding, recty1 + padding, rectx2 - padding, recty2 - padding);
  101. if (localPlayer == NULL)//checks if your local player is existant
  102. {
  103.  
  104. while (localPlayer == NULL)
  105. {
  106. localPlayer = *(DWORD*)(gameModuleEntity + entityList);
  107. }
  108.  
  109. }
  110. for (short int i = 1; i < 64; i++)
  111. {
  112. //each entity is 0x10 apart in memory
  113. DWORD entity = *(DWORD*)(gameModuleEntity + entityList + i * 0x10);
  114. if (entity != NULL)
  115. {
  116. if (entity != localPlayer)//Makes sure we dont draw on our own player
  117. {
  118. int entityTeam = *(int*)(entity + iTeamNum);
  119. Vec3 entityLocation = *(Vec3*)(entity + vecOrigin);
  120. isDormat = *(DWORD*)(entity + isdormant);
  121. DWORD health = *(DWORD*)(entity + healthhh);
  122. if (isDormat == 4294901760)//Checks if the entity is culled
  123. {
  124. if (health > 0)
  125. {
  126. if (WorldToScreen(entityLocation, vScreen, Matrix, SCREEN_WIDTH, SCREEN_HEIGHT)) {
  127. Line(SCREEN_WIDTH / 2, SCREEN_HEIGHT, vScreen.x, vScreen.y, 3, true, D3DCOLOR_ARGB(255, 255, 0, 255), pDevice);
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134.  
  135. font->DrawText(NULL, "Stasik", -1, &textRectangle, DT_NOCLIP | DT_LEFT, D3DCOLOR_ARGB(255, 153, 255, 153)); //draw text;
  136.  
  137. return pEndScene(pDevice); // call original endScene
  138. }
  139.  
  140. void hookEndScene() {
  141. IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION); // create IDirect3D9 object
  142. if (!pD3D)
  143. return;
  144.  
  145. D3DPRESENT_PARAMETERS d3dparams = { 0 };
  146. d3dparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
  147. d3dparams.hDeviceWindow = GetForegroundWindow();
  148. d3dparams.Windowed = true;
  149.  
  150. IDirect3DDevice9* pDevice = nullptr;
  151.  
  152. HRESULT result = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3dparams.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dparams, &pDevice);
  153. if (FAILED(result) || !pDevice) {
  154. pD3D->Release();
  155. return;
  156. }
  157. //if device creation worked out -> lets get the virtual table:
  158. void** vTable = *reinterpret_cast<void***>(pDevice);
  159.  
  160. //now detour:
  161.  
  162. pEndScene = (endScene)DetourFunction((PBYTE)vTable[42], (PBYTE)hookedEndScene);
  163.  
  164. pDevice->Release();
  165. pD3D->Release();
  166. }
  167.  
  168.  
  169. DWORD __stdcall EjectThread(LPVOID lpParameter) {
  170. Sleep(100);
  171. FreeLibraryAndExitThread(DllHandle, 0);
  172. return 0;
  173. }
  174.  
  175. DWORD WINAPI Menue(HINSTANCE hModule) {
  176. AllocConsole();
  177. FILE* fp;
  178. freopen_s(&fp, "CONOUT$", "w", stdout); //sets cout to be used with our newly created console
  179.  
  180. hookEndScene();
  181. gameModuleEntity = (DWORD)GetModuleHandle("client.dll");
  182. gameModuleS = (DWORD)GetModuleHandle("engine.dll");
  183.  
  184. while (true) {
  185. memcpy(&Matrix, (PBYTE*)(gameModuleS + viewMatrix), sizeof(Matrix));
  186. localPlayer = *(DWORD*)(gameModuleEntity + entityList);
  187. if (GetAsyncKeyState(VK_F3)) {
  188. DetourRemove((PBYTE)pEndScene, (PBYTE)hookedEndScene); //unhook to avoid game crash
  189. break;
  190. }
  191. }
  192. std::cout << "ight imma head out" << std::endl;
  193. Sleep(1000);
  194. fclose(fp);
  195. FreeConsole();
  196. CreateThread(0, 0, EjectThread, 0, 0, 0);
  197. return 0;
  198. }
  199.  
  200. BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  201. {
  202. switch (ul_reason_for_call)
  203. {
  204. case DLL_PROCESS_ATTACH:
  205. DllHandle = hModule;
  206. CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Menue, NULL, 0, NULL);
  207. case DLL_THREAD_ATTACH:
  208. case DLL_THREAD_DETACH:
  209. case DLL_PROCESS_DETACH:
  210. break;
  211. }
  212. return TRUE;
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement