Advertisement
Guest User

Untitled

a guest
May 25th, 2017
2,100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.14 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #include <cstdio>
  4. #include <stdlib.h>
  5. #include <time.h>
  6. #include <math.h>
  7. #include <Windows.h>
  8. #include <Xinput.h>
  9.  
  10. using namespace std;
  11.  
  12. #define KEY_PRESSED_MASK 0x1
  13. #define KEY_DOWN_MASK 0x8000
  14.  
  15. #define REPLACED_CODE_SIZE 4
  16.  
  17. #define PI 3.14159265
  18. #define TAU 6.28318530718
  19.  
  20. #define distance(a, b, c) sqrt(a*a + b*b + c*c)
  21. #define distance2d(a, b) sqrt(a*a + b*b)
  22.  
  23. void init();
  24. void hook();
  25. void hack();
  26. void unload();
  27.  
  28. long messageDisplayTime = 0;
  29. wchar_t * message = (wchar_t*)0x0078B600;
  30.  
  31. void gameMessage(long displayTime, const wchar_t * format, ...);
  32.  
  33. void scrnprintf(int x, int y, bool shadow, const char * format, ...);
  34.  
  35. void copy(LPVOID source, LPVOID dest, int count);
  36.  
  37. void(*gameUpdate)() = (void(*)()) 0x004A42D0;
  38. unsigned int originalGameUpdateCall = 0x004A5C70 + 0x01;
  39. BYTE originalGameUpdateFunctionAddress[4];
  40.  
  41. float vectorDistance3d(float x, float y, float z);
  42. float vectorDistance2d(float x, float y);
  43.  
  44. RECT rect;
  45. HDC canvas;
  46. HWND window = 0;
  47. HFONT arial;
  48.  
  49. HINSTANCE hDLL = NULL;
  50.  
  51. DWORD oldAccess;
  52.  
  53. BOOL WINAPI DllMain(
  54.     HINSTANCE hinstDLL,
  55.     DWORD fdwReason,
  56.     LPVOID lpvReserved
  57. )
  58. {
  59.     if (fdwReason == DLL_PROCESS_ATTACH)
  60.     {
  61.         hDLL = hinstDLL;
  62.         //DisableThreadLibraryCalls(hDLL);
  63.         //CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)hack, 0, NULL, NULL);
  64.  
  65.         unsigned int pHook = (unsigned int)&hook - originalGameUpdateCall - 0x04;
  66.         DWORD old;
  67.         unsigned char data[] = { 0, 0, 0, 0 };
  68.         copy((LPVOID)&pHook, (LPVOID)data, sizeof(data));
  69.         VirtualProtect((LPVOID)originalGameUpdateCall, sizeof(data), PAGE_EXECUTE_READWRITE, &old);
  70.         copy((LPVOID)&originalGameUpdateCall, (LPVOID)originalGameUpdateFunctionAddress, sizeof(originalGameUpdateFunctionAddress));
  71.         copy((LPVOID)data, (LPVOID)originalGameUpdateCall, sizeof(data));
  72.         VirtualProtect((LPVOID)originalGameUpdateCall, sizeof(data), old, &old);
  73.     }
  74.     else if (fdwReason == DLL_PROCESS_DETACH)
  75.     {
  76.  
  77.     }
  78.     return TRUE;
  79. }
  80.  
  81. void hook() {
  82.     gameUpdate();
  83.     hack();
  84. }
  85.  
  86. bool initiated = false;
  87.  
  88. int frames;
  89. long start;
  90.  
  91. void init()
  92. {
  93.     window = FindWindow(NULL, L"GTA: Vice City");
  94.     //MessageBox(NULL, L"Success!", L"GTA: Vice City", MB_OK);
  95.     VirtualProtect((LPVOID)0, 0x80000000, PAGE_EXECUTE_READWRITE, &oldAccess);
  96.     LoadLibrary(L"XINPUT1_4.dll");
  97.     initiated = true;
  98.     start = GetTickCount64();
  99.     srand(time(NULL));
  100.     frames = 0;
  101. }
  102.  
  103. void teleportEntity(unsigned int target, float x, float y, float z)
  104. {
  105.     *(float*)(target + 0x34) = x;
  106.     *(float*)(target + 0x38) = y;
  107.     *(float*)(target + 0x3C) = z;
  108.  
  109.     //Reset all velocities (no coming in hot!)
  110.  
  111.     *(float*)(target + 0x70) = 0.0f;
  112.     *(float*)(target + 0x74) = 0.0f;
  113.     *(float*)(target + 0x78) = 0.0f;
  114.  
  115.     *(float*)(target + 0x7C) = 0.0f;
  116.     *(float*)(target + 0x80) = 0.0f;
  117.     *(float*)(target + 0x84) = 0.0f;
  118. }
  119.  
  120. bool isValidID(unsigned short id) {
  121.     return id > 0 && id != 0xFFFF;
  122. }
  123.  
  124. bool isEntityCar(unsigned int id)
  125. {
  126.     return id >= 0x5A && id <= 0x93;
  127. }
  128.  
  129. bool isEntityPed(unsigned int id)
  130. {
  131.     return id > 0x00 && id < 0x5A;
  132. }
  133.  
  134. bool quit = false;
  135.  
  136. bool hovercar = false;
  137.  
  138. unsigned int lasttouch = 0;
  139.  
  140. unsigned int enemies[] = { 0x01, 0x02, 0x03, 0x74, 0x75, 0x6B, 0x7B };
  141. bool enemyIsCar[] = { false, false, false, true, true, true };
  142.  
  143. unsigned int weaponIDs[] = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0B, 0x08 }; //-0x0c
  144. unsigned int weaponAmmoOffsets[] = { 0x398, 0x3B0, 0x3C8, 0x3E0, 0x3F8, 0x410, 0x440, 0x470, 0x428 };
  145.  
  146. unsigned int lowestCarAddress = 0xFFFFFFFF, highestCarAddress = 0x00000000;
  147. unsigned int lowestPedAddress = 0xFFFFFFFF, highestPedAddress = 0x00000000;
  148.  
  149. WORD previousButtonState = 0;
  150.  
  151. float leftStickX = 0.0f, leftStickY = 0.0f;
  152. float rightStickX = 0.0f, rightStickY = 0.0f;
  153.  
  154. long bombTimer = MAXLONG;
  155. unsigned int bombTarget = 0;
  156.  
  157. unsigned int lastCar = 0;
  158.  
  159. void getStickInputs(XINPUT_STATE state)
  160. {
  161.     float LX = state.Gamepad.sThumbLX;
  162.     float LY = state.Gamepad.sThumbLY;
  163.  
  164.     //determine how far the controller is pushed
  165.     float magnitude = sqrt(LX*LX + LY*LY);
  166.  
  167.     //determine the direction the controller is pushed
  168.     float normalizedLX = LX / magnitude;
  169.     float normalizedLY = LY / magnitude;
  170.  
  171.     float normalizedMagnitude = 0;
  172.  
  173.     //check if the controller is outside a circular dead zone
  174.     if (magnitude > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
  175.     {
  176.         //clip the magnitude at its expected maximum value
  177.         if (magnitude > 32767) magnitude = 32767;
  178.  
  179.         //adjust magnitude relative to the end of the dead zone
  180.         magnitude -= XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE;
  181.  
  182.         //optionally normalize the magnitude with respect to its expected range
  183.         //giving a magnitude value of 0.0 to 1.0
  184.         normalizedMagnitude = magnitude / (32767 - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE);
  185.     }
  186.     else //if the controller is in the deadzone zero out the magnitude
  187.     {
  188.         magnitude = 0.0;
  189.         normalizedMagnitude = 0.0;
  190.     }
  191. }
  192.  
  193. /* VICE CITY
  194.     *************
  195. ~~~* PEDESTRIANS *~~~
  196.     *************
  197. struct size 0x5A0 probably wrong
  198.  
  199. 0x04 Right Vector
  200. 0x14 Forward Vector
  201. 0x24 Up Vector
  202.  
  203. 0x108 pointer to touched item
  204.  
  205. 0x354 Health
  206. 0x358 Armor
  207.  
  208.     **********
  209. ~~~* VEHICLES *~~~
  210.     **********
  211. 0x04 Right Vector
  212. 0x14 Forward Vector
  213. 0x24 Up Vector
  214.  
  215. 0x70 Velocity vector
  216. 0x7C Rotational velocity vector
  217.  
  218. 0xB4 Mass
  219.  
  220. 0x204 Health
  221.  
  222. 0x4A4 wheels on ground
  223.  
  224. */
  225.  
  226. float maxVelocity = 2.0f;
  227. float acceleration = 0.1f;
  228. float friction = 0.1f;
  229. float forwardForce = 1.0f - friction;
  230.  
  231. float gravity = 0.0f;
  232. float spin = 0.0f;
  233. float gravitySwap = 0.0f;
  234.  
  235. long puntTimer = 0;
  236. unsigned char puntState = 0;
  237. float snapx, snapy, snapz;
  238. float snapvx, snapvy, snapvz;
  239. float snaprvx, snaprvy, snaprvz;
  240. float snapMass;
  241.  
  242. float revertx, reverty, revertz;
  243.  
  244. bool driveOnWalls = false;
  245.  
  246. void hack()
  247. {
  248.     if (!initiated)
  249.         init();
  250.  
  251.     if (GetAsyncKeyState(VK_DELETE) & KEY_PRESSED_MASK) //CreateThread(0, 0, (LPTHREAD_START_ROUTINE)unload, 0, 0, 0);
  252.     {
  253.         CreateThread(0, 0, (LPTHREAD_START_ROUTINE)unload, 0, 0, 0);
  254.         return;
  255.     }
  256.     unsigned int pplayer = *(unsigned int*)(0x00949D30); //0x7E3B94, 0x949D30, 0x78E864
  257.     unsigned int pcar = 0;
  258.  
  259.     if (pplayer)
  260.         pcar = *(unsigned int*)(0x009B5A88);
  261.  
  262.     unsigned int pobj = pcar ? pcar : pplayer;
  263.  
  264.     XINPUT_STATE state;
  265.     ZeroMemory(&state, sizeof(XINPUT_STATE));
  266.     bool gamepad = XInputGetState(0, &state) == ERROR_SUCCESS;
  267.  
  268.     WORD buttonsHeld = state.Gamepad.wButtons;
  269.     WORD buttonsPressed = (~previousButtonState) & state.Gamepad.wButtons;
  270.     WORD buttonsReleased = previousButtonState & (~state.Gamepad.wButtons);
  271.  
  272.     if (pplayer)
  273.     {
  274.         *(float*)(pplayer + 0x354) = 500.0f + (rand() % 100); //player health
  275.         *(float*)(pplayer + 0x358) = 500.0f + (rand() % 100); //player armor
  276.  
  277.         if (!pcar)
  278.         {
  279.             if (gamepad)
  280.             {
  281.                 if (buttonsHeld & XINPUT_GAMEPAD_X)
  282.                 {
  283.                     *(float*)(pplayer + 0x70) = *(float*)(pplayer + 0x14) * 0.2f;
  284.                     *(float*)(pplayer + 0x74) = *(float*)(pplayer + 0x18) * 0.2f;
  285.                     *(float*)(pplayer + 0x78) = 0.2f;
  286.                 }
  287.             }
  288.             else if (GetAsyncKeyState(VK_SPACE) & KEY_DOWN_MASK)
  289.             {
  290.                 *(float*)(pplayer + 0x70) = *(float*)(pplayer + 0x14) * 0.2f;
  291.                 *(float*)(pplayer + 0x74) = *(float*)(pplayer + 0x18) * 0.2f;
  292.                 *(float*)(pplayer + 0x78) = 0.2f;
  293.             }
  294.         }
  295.  
  296.         //Toggle gravity
  297.         if (GetAsyncKeyState(VK_NUMPAD2) & KEY_PRESSED_MASK) {
  298.             float g = *(float*)0x0068E5F8; //0.00800000038
  299.             *(float*)0x0068E5F8 = gravitySwap;
  300.             gravitySwap = g;
  301.         }
  302.     }
  303.     if (pcar)
  304.     {
  305.         if (pcar != lastCar)
  306.         {
  307.             //Undo invincibility if a new car is entered
  308.             if (lastCar) {
  309.                 *(unsigned char*)(lastCar + 0x53) &= 0xF0;
  310.                 if (*(unsigned char*)(lastCar + 0x52) & 0x10)
  311.                     *(unsigned char*)(lastCar + 0x52) &= ~0x10;
  312.             }
  313.         }
  314.  
  315.         if (*(unsigned int*)(pcar + 0x4A4) && *(unsigned int*)(pcar + 0x4A8) && *(unsigned int*)(pcar + 0x4AC) && *(unsigned int*)(pcar + 0x4B0)) {
  316.             revertx = *(float*)(pcar + 0x34); reverty = *(float*)(pcar + 0x38); revertz = *(float*)(pcar + 0x3C);
  317.         }
  318.         if (*(unsigned char*)(pcar + 0x54) & 0x04)
  319.         {
  320.             //Teleport car back to land
  321.             *(float*)(pcar + 0x34) = revertx; *(float*)(pcar + 0x38) = reverty; *(float*)(pcar + 0x3C) = revertz;
  322.             float fvx = *(float*)(pcar + 0x14); float fvy = *(float*)(pcar + 0x18);
  323.             float fvd = distance(fvx, fvy, *(float*)(pcar + 0x1C));
  324.             fvx /= fvd; fvy /= fvd;
  325.             //Reset rotational matrix
  326.             *(float*)(pcar + 0x04) = fvy; *(float*)(pcar + 0x08) = -fvx; *(float*)(pcar + 0x0C) = 0.0f;
  327.             *(float*)(pcar + 0x14) = fvx; *(float*)(pcar + 0x18) = fvy; *(float*)(pcar + 0x1C) = 0.0f;
  328.             *(float*)(pcar + 0x24) = 0.0f; *(float*)(pcar + 0x28) = 0; *(float*)(pcar + 0x2C) = 1.0f;
  329.             //Reset velocities
  330.             *(float*)(pcar + 0x70) = 0.0f; *(float*)(pcar + 0x74) = 0.0f; *(float*)(pcar + 0x78) = 0.0f;
  331.             //Reset rotational velocities
  332.             *(float*)(pcar + 0x7C) = 0.0f; *(float*)(pcar + 0x80) = 0.0f; *(float*)(pcar + 0x84) = 0.0f;
  333.         }
  334.  
  335.  
  336.         *(unsigned char*)(pcar + 0x53) |= 0x0F; //everything but rhino proof
  337.  
  338.         if (GetAsyncKeyState(VK_NUMPAD1) & KEY_PRESSED_MASK)  //rhino proof toggle on Numpad 1 pressed
  339.             *(unsigned char*)(pcar + 0x52) ^= 0x10;
  340.  
  341.         *(float*)(pcar + 0x204) = 10000.0f; //infinite health
  342.  
  343.         if (gamepad)
  344.         {
  345.             if (buttonsPressed & XINPUT_GAMEPAD_DPAD_DOWN)
  346.                 hovercar = !hovercar;
  347.             if (hovercar)
  348.             {
  349.                 float leftStickX = 0.0f, leftStickY = 0.0f;
  350.                 float rightStickX = 0.0f, rightStickY = 0.0f;
  351.  
  352.                 if (abs(state.Gamepad.sThumbLX) > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
  353.                     leftStickX = state.Gamepad.sThumbLX / (float)(32767 - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE);
  354.                 if (abs(state.Gamepad.sThumbLY) > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
  355.                     leftStickY = state.Gamepad.sThumbLY / (float)(32767 - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE);
  356.                 if (abs(state.Gamepad.sThumbRX) > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
  357.                     rightStickX = state.Gamepad.sThumbRX / (float)(32767 - XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE);
  358.                 if (abs(state.Gamepad.sThumbRY) > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
  359.                     rightStickY = state.Gamepad.sThumbRY / (float)(32767 - XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE);
  360.  
  361.                 float rx = *(float*)(pcar + 0x14);
  362.                 float ry = *(float*)(pcar + 0x18);
  363.                 float rv = sqrt(rx*rx + ry*ry);
  364.                 rx /= rv;
  365.                 ry /= rv;
  366.  
  367.                 *(float*)(pcar + 0x14) = rx;
  368.                 *(float*)(pcar + 0x18) = ry;
  369.                 *(float*)(pcar + 0x1C) = 0.0f;
  370.  
  371.                 *(float*)(pcar + 0x04) = ry; //cos(rot)
  372.                 *(float*)(pcar + 0x08) = -rx; //-sin(rot)
  373.                 *(float*)(pcar + 0x0C) = 0.0f;
  374.  
  375.                 *(float*)(pcar + 0x24) = 0.0f;
  376.                 *(float*)(pcar + 0x28) = 0.0f;
  377.                 *(float*)(pcar + 0x2C) = 1.0f;
  378.  
  379.                 *(float*)(pcar + 0x7C) = 0;
  380.                 *(float*)(pcar + 0x80) = 0;
  381.                 *(float*)(pcar + 0x84) = 0;
  382.  
  383.                 if (buttonsHeld & XINPUT_GAMEPAD_A) {
  384.                     float vx = *(float*)(pcar + 0x70);
  385.                     float vy = *(float*)(pcar + 0x74);
  386.                     float v = vectorDistance2d(vx, vy);
  387.                     v = min(v, maxVelocity);
  388.                     *(float*)(pcar + 0x70) = *(float*)(pcar + 0x14) * v * forwardForce + *(float*)(pcar + 0x70) * friction + *(float*)(pcar + 0x14) * acceleration;
  389.                     *(float*)(pcar + 0x74) = *(float*)(pcar + 0x18) * v * forwardForce + *(float*)(pcar + 0x74) * friction + *(float*)(pcar + 0x18) * acceleration;
  390.                 }
  391.                 else if (buttonsHeld & XINPUT_GAMEPAD_X) {
  392.                     *(float*)(pcar + 0x70) = *(float*)(pcar + 0x14) * -0.8f;
  393.                     *(float*)(pcar + 0x74) = *(float*)(pcar + 0x18) * -0.8f;
  394.                 }
  395.                 else {
  396.                     *(float*)(pcar + 0x70) *= 0.9f;
  397.                     *(float*)(pcar + 0x74) *= 0.9f;
  398.                 }
  399.                 if (leftStickY != 0.0f)
  400.                     *(float*)(pcar + 0x78) = 0.4f * leftStickY; //-0.04 gravity
  401.                 else
  402.                     *(float*)(pcar + 0x78) = 0.00800000038f;
  403.                 *(float*)(pcar + 0x84) = 0.05f * -leftStickX; //5c3610
  404.             }
  405.         }
  406.         else {
  407.             if (GetAsyncKeyState(VK_SPACE) & KEY_DOWN_MASK)
  408.             {
  409.  
  410.                 *(float*)(pcar + 0x78) = 0.2f; //float up
  411.  
  412.                 *(float*)(pcar + 0x7C) = 0.0f; //lock rotation
  413.                 *(float*)(pcar + 0x80) = 0.0f;
  414.                 *(float*)(pcar + 0x84) = 0.0f;
  415.             }
  416.  
  417.             /* PUNT!! */
  418.             if (GetAsyncKeyState(VK_NUMPAD8) & KEY_PRESSED_MASK && !puntState) {
  419.                 snapx = *(float*)(pcar + 0x34); snapy = *(float*)(pcar + 0x38); snapz = *(float*)(pcar + 0x3C);
  420.                 snapvx = *(float*)(pcar + 0x70); snapvy = *(float*)(pcar + 0x74); snapvz = *(float*)(pcar + 0x78);
  421.                 snaprvx = *(float*)(pcar + 0x7C); snaprvy = *(float*)(pcar + 0x80); snaprvz = *(float*)(pcar + 0x84);
  422.                 *(float*)(pcar + 0x70) += *(float*)(pcar + 0x14) * 5.0f;
  423.                 *(float*)(pcar + 0x74) += *(float*)(pcar + 0x18) * 5.0f;
  424.                 *(float*)(pcar + 0x78) += *(float*)(pcar + 0x1C) * 5.0f;
  425.                 *(float*)(pcar + 0xB4) *= 10;
  426.                 puntState = 1;
  427.             }
  428.             else if (puntState) {
  429.                 *(float*)(pcar + 0x34) = snapx + 2 * snapvx; *(float*)(pcar + 0x38) = snapy + 2 * snapvy; *(float*)(pcar + 0x3C) = snapz + 2 * snapvz;
  430.                 *(float*)(pcar + 0x70) = snapvx; *(float*)(pcar + 0x74) = snapvy; *(float*)(pcar + 0x78) = snapvz;
  431.                 *(float*)(pcar + 0x7C) = snaprvx; *(float*)(pcar + 0x80) = snaprvy; *(float*)(pcar + 0x84) = snaprvz;
  432.                 *(float*)(pcar + 0xB4) /= 10;
  433.                 puntState = 0;
  434.             }
  435.  
  436.             if (GetAsyncKeyState(VK_NUMPAD0) & KEY_PRESSED_MASK)
  437.                 hovercar = !hovercar;
  438.             if (hovercar)
  439.             {
  440.                 float rx = *(float*)(pcar + 0x14);
  441.                 float ry = *(float*)(pcar + 0x18);
  442.                 float rv = sqrt(rx*rx + ry*ry);
  443.                 rx /= rv;
  444.                 ry /= rv;
  445.  
  446.                 *(float*)(pcar + 0x14) = rx;
  447.                 *(float*)(pcar + 0x18) = ry;
  448.                 *(float*)(pcar + 0x1C) = 0.0f;
  449.  
  450.                 *(float*)(pcar + 0x04) = ry; //cos(rot)
  451.                 *(float*)(pcar + 0x08) = -rx; //-sin(rot)
  452.                 *(float*)(pcar + 0x0C) = 0.0f;
  453.  
  454.                 *(float*)(pcar + 0x24) = 0.0f;
  455.                 *(float*)(pcar + 0x28) = 0.0f;
  456.                 *(float*)(pcar + 0x2C) = 1.0f;
  457.  
  458.                 *(float*)(pcar + 0x7C) = 0;
  459.                 *(float*)(pcar + 0x80) = 0;
  460.                 *(float*)(pcar + 0x84) = 0;
  461.  
  462.                 if (GetAsyncKeyState('W') & KEY_DOWN_MASK) {
  463.                     float vx = *(float*)(pcar + 0x70);
  464.                     float vy = *(float*)(pcar + 0x74);
  465.                     float v = vectorDistance2d(vx, vy);
  466.                     v = min(v, maxVelocity);
  467.                     *(float*)(pcar + 0x70) = *(float*)(pcar + 0x14) * v * forwardForce + *(float*)(pcar + 0x70) * friction + *(float*)(pcar + 0x14) * acceleration;
  468.                     *(float*)(pcar + 0x74) = *(float*)(pcar + 0x18) * v * forwardForce + *(float*)(pcar + 0x74) * friction + *(float*)(pcar + 0x18) * acceleration;
  469.                 }
  470.                 else if (GetAsyncKeyState('S') & KEY_DOWN_MASK) {
  471.                     *(float*)(pcar + 0x70) = *(float*)(pcar + 0x14) * -0.8f;
  472.                     *(float*)(pcar + 0x74) = *(float*)(pcar + 0x18) * -0.8f;
  473.                 }
  474.                 else {
  475.                     *(float*)(pcar + 0x70) *= 0.9f;
  476.                     *(float*)(pcar + 0x74) *= 0.9f;
  477.                 }
  478.  
  479.                 //Up and Down
  480.                 if (GetAsyncKeyState(VK_SPACE) & KEY_DOWN_MASK)
  481.                     *(float*)(pcar + 0x78) = 0.8f;
  482.                 else if (GetAsyncKeyState(VK_LCONTROL) & KEY_DOWN_MASK)
  483.                     *(float*)(pcar + 0x78) = -0.8f;
  484.                 else
  485.                     *(float*)(pcar + 0x78) = 0.0f;
  486.  
  487.                 //Turning
  488.                 if (GetAsyncKeyState('A') & KEY_DOWN_MASK)
  489.                     *(float*)(pcar + 0x84) = 0.06f;
  490.                 else if(GetAsyncKeyState('D') & KEY_DOWN_MASK)
  491.                     *(float*)(pcar + 0x84) = -0.06f;
  492.             }
  493.         }
  494.  
  495.         if (GetAsyncKeyState(VK_NUMPAD3) & KEY_PRESSED_MASK) {
  496.             driveOnWalls = !driveOnWalls;
  497.             gameMessage(2000, L"Drive on walls %s", driveOnWalls ? L"ON":L"OFF");
  498.         }
  499.         if (driveOnWalls)
  500.         {
  501.             float g = *(float*)0x0068E5F8;
  502.             *(float*)(pcar + 0x70) -= *(float*)(pcar + 0x24) * 0.00800000038;
  503.             *(float*)(pcar + 0x74) -= *(float*)(pcar + 0x28) * 0.00800000038;
  504.             *(float*)(pcar + 0x78) -= *(float*)(pcar + 0x2C) * 0.00800000038;
  505.             *(float*)(pcar + 0x78) += g;
  506.         }
  507.         else {
  508.             //auto flip
  509.             if (*(float*)(pcar + 0x2C) < -0.2f) {
  510.                 if (*(float*)(pcar + 0x80) > 0)
  511.                     *(float*)(pcar + 0x80) = 0.05f;
  512.                 else
  513.                     *(float*)(pcar + 0x80) = -0.05f;
  514.             }
  515.         }
  516.  
  517.         lastCar = pcar;
  518.     }
  519.  
  520.     if (pobj)
  521.     {
  522.         if (GetAsyncKeyState('7') & KEY_DOWN_MASK)
  523.             teleportEntity(pobj, -1012.68f, -892.03f, 12.72f);
  524.  
  525.         unsigned int ptouch = *(unsigned int*)(pobj + 0x108);
  526.         if (ptouch)
  527.             gameMessage(200, L"0x%08X", ptouch);
  528.  
  529.         if (GetTickCount64() < messageDisplayTime) {
  530.             *(unsigned int*)(0x0094CBD4) = 0x00000008;
  531.         }
  532.         else if (messageDisplayTime) {
  533.             messageDisplayTime = 0;
  534.             *(unsigned int*)(0x0094CBD4) = 0x00000000;
  535.             wcscpy(message, L"");
  536.         }
  537.  
  538.         /*canvas = GetDC(window);
  539.         arial = CreateFont(16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
  540.             CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH, TEXT("Arial"));
  541.         SelectObject(canvas, arial);
  542.         SetBkMode(canvas, TRANSPARENT);
  543.         SetTextColor(canvas, RGB(255, 0, 140));
  544.  
  545.         scrnprintf(10, 26, true, "FPS %00.0f", frames / (float)((GetTickCount64() - start) / 1000));
  546.  
  547.         DeleteObject(arial);
  548.         ReleaseDC(window, canvas);*/
  549.     }
  550.     previousButtonState = state.Gamepad.wButtons;
  551.     frames++;
  552. }
  553.  
  554. void unload()
  555. {
  556.     //Undo the function call:
  557.     /*DWORD old;
  558.     VirtualProtect((LPVOID)0x007f9a01, 6, PAGE_EXECUTE_READWRITE, &old);
  559.     copy((LPVOID)d3dCode, (LPVOID)0x007f9a01, 6);
  560.     VirtualProtect((LPVOID)0x007f9a01, 6, old, &old);*/
  561.     //Unload the DLL and kill the thread
  562.     copy((LPVOID)originalGameUpdateFunctionAddress, (LPVOID)originalGameUpdateCall, sizeof(originalGameUpdateFunctionAddress));
  563.     HMODULE h;
  564.     GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, L"VCDevice.dll", &h);
  565.     FreeLibraryAndExitThread(hDLL, 0);
  566. }
  567.  
  568. void gameMessage(long displayTime, const wchar_t * format, ...) {
  569.     wchar_t buffer[256];
  570.     va_list args;
  571.     va_start(args, format);
  572.     vswprintf(buffer, 256, format, args);
  573.     va_end(args);
  574.  
  575.     wcscpy(message, buffer);
  576.  
  577.     messageDisplayTime = GetTickCount64() + displayTime;
  578. }
  579.  
  580. void scrnprintf(int x, int y, bool shadow, const char * format, ...)
  581. {
  582.     if (!canvas)
  583.         return;
  584.     char buffer[256];
  585.     va_list args;
  586.     va_start(args, format);
  587.     int count = vsprintf(buffer, format, args);
  588.     va_end(args);
  589.     rect.left = x;
  590.     rect.top = y;
  591.     rect.right = x + 800;
  592.     rect.bottom = y + 20;
  593.     if (shadow)
  594.     {
  595.         COLORREF color = GetTextColor(canvas);
  596.         SetTextColor(canvas, (COLORREF)0);
  597.         rect.left++;
  598.         rect.top++;
  599.         DrawTextA(canvas, buffer, count, &rect, DT_TOP | DT_LEFT);
  600.         rect.left--;
  601.         rect.top--;
  602.         SetTextColor(canvas, color);
  603.     }
  604.     DrawTextA(canvas, buffer, count, &rect, DT_TOP | DT_LEFT);
  605. }
  606.  
  607. void copy(LPVOID source, LPVOID dest, int count)
  608. {
  609.     __asm
  610.     {
  611.         push ecx
  612.         push edi
  613.         push esi
  614.         mov ecx, count
  615.         mov esi, source
  616.         mov edi, dest
  617.         repe movsb
  618.         pop esi
  619.         pop edi
  620.         pop ecx
  621.     }
  622. }
  623.  
  624. float vectorDistance3d(float x, float y, float z)
  625. {
  626.     return sqrt(x*x + y*y + z*z);
  627. }
  628.  
  629. float vectorDistance2d(float x, float y)
  630. {
  631.     return sqrt(x*x + y*y);
  632. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement