Guest User

ShowWheelAddress

a guest
Sep 11th, 2017
255
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include "script.h"
  4. #include "Pattern.h"
  5. #include <vector>
  6.  
  7. bool triedToFindPattern = false;
  8. int wheelId = 0;
  9. std::string addressStr("0");
  10.  
  11. typedef __int64(*GetWheelById_t)(BYTE * vehicleMemoryAddress, int wheelId);
  12. GetWheelById_t GetWheelById;
  13.  
  14. void update()
  15. {
  16.     if (!triedToFindPattern)
  17.     {
  18.         uint64_t patternAddr = reinterpret_cast<uint64_t>(Utility::pattern("BA ? ? ? ? 48 8B CF E8 ? ? ? ? 48 85 C0 0F 84 ? ? ? ? 48 8B 4F 20").count(1).get(0).get<char>(0));
  19.         GetWheelById = (GetWheelById_t)(patternAddr + 8);
  20.         triedToFindPattern = true;
  21.     }
  22.  
  23.     if (IsKeyDown('I') && wheelId >= 0)
  24.     {
  25.         wheelId--;
  26.     }
  27.     else if (IsKeyDown('O') && wheelId <= 500)
  28.     {
  29.         wheelId++;
  30.     }
  31.  
  32.     std::stringstream ss;
  33.     ss << std::dec << wheelId;
  34.     addressStr = ss.str();
  35.     DrawGtaText(addressStr.c_str(), 0.15f, 0.0f);
  36.  
  37.     ss.str("");
  38.     ss.clear(std::stringstream::goodbit);
  39.  
  40.     ss << std::hex << GetWheelById;
  41.     addressStr = ss.str();
  42.     DrawGtaText(addressStr.c_str(), 0.15f, 0.04f);
  43.  
  44.     ss.str("");
  45.     ss.clear(std::stringstream::goodbit);
  46.  
  47.     Player player = PLAYER::PLAYER_ID();
  48.     Ped playerPed = PLAYER::PLAYER_PED_ID();
  49.  
  50.     if (!ENTITY::DOES_ENTITY_EXIST(playerPed))
  51.     {
  52.         return;
  53.     }
  54.  
  55.     Vehicle* vehArray = new Vehicle[512];
  56.  
  57.     int vehCount = worldGetAllVehicles(vehArray, 512);
  58.  
  59.     Vector3 playerPos = ENTITY::GET_ENTITY_COORDS(player, false);
  60.    
  61.     Vehicle nVeh = GetNearestVehicle(vehArray, vehCount, playerPos);
  62.     delete[] vehArray;
  63.  
  64.     if (ENTITY::DOES_ENTITY_EXIST(nVeh))
  65.     {
  66.  
  67.         Vector3 vehPos = ENTITY::GET_ENTITY_COORDS(nVeh, false);
  68.         GRAPHICS::DRAW_LIGHT_WITH_RANGE(vehPos.x, vehPos.y, vehPos.z, 30, 255, 30, 20.0f, 20.0f);
  69.  
  70.         if (!IsKeyDown('U'))
  71.         {
  72.             return;
  73.         }
  74.  
  75.         BYTE * address = getScriptHandleBaseAddress(nVeh);
  76.  
  77.         ss << std::hex << reinterpret_cast<unsigned long long>(address);
  78.         addressStr = ss.str();
  79.         DrawGtaText(addressStr.c_str(), 0.15f, 0.08f);
  80.  
  81.         ss.str("");
  82.         ss.clear(std::stringstream::goodbit);
  83.  
  84.         if (address != nullptr)
  85.         {
  86.             unsigned long long wheelAddress = static_cast<unsigned long long>(GetWheelById(address, wheelId));
  87.  
  88.             ss << std::hex << wheelAddress;
  89.             addressStr = ss.str();
  90.             DrawGtaText(addressStr.c_str(), 0.15f, 0.12f);
  91.         }
  92.     }
  93.  
  94.  
  95. }
  96.  
  97. Vehicle GetNearestVehicle(Vehicle* vehicleArray, int arraySize, Vector3 basePos)
  98. {
  99.     float closestDist = FLT_MAX;
  100.     Vehicle retVeh = 0;
  101.  
  102.     for (int i = 0; i < arraySize; i++)
  103.     {
  104.         if (ENTITY::DOES_ENTITY_EXIST(vehicleArray[i]))
  105.         {
  106.             Vector3 vehPos = ENTITY::GET_ENTITY_COORDS(vehicleArray[i], false);
  107.             float dist = CalcVector3DistanceSquared(vehPos, basePos);
  108.            
  109.             if (dist < closestDist)
  110.             {
  111.                 closestDist = dist;
  112.                 retVeh = vehicleArray[i];
  113.             }
  114.         }
  115.     }
  116.  
  117.     return retVeh;
  118. }
  119.  
  120. float CalcVector3Distance(Vector3 vec1, Vector3 vec2)
  121. {
  122.     float x = vec1.x - vec2.x;
  123.     float y = vec1.y - vec2.y;
  124.     float z = vec1.z - vec2.z;
  125.  
  126.     return sqrtf((x*x) + (y*y) + (z*z));
  127. }
  128.  
  129. float CalcVector3DistanceSquared(Vector3 vec1, Vector3 vec2)
  130. {
  131.     float x = vec1.x - vec2.x;
  132.     float y = vec1.y - vec2.y;
  133.     float z = vec1.z - vec2.z;
  134.  
  135.     return (x*x) + (y*y) + (z*z);
  136. }
  137.  
  138. void DrawGtaText(const char* text, float drawPosX, float drawPosY)
  139. {
  140.     UI::SET_TEXT_FONT(0);
  141.     UI::SET_TEXT_SCALE(0.5, 0.5);
  142.     UI::SET_TEXT_COLOUR(255, 255, 255, 255);
  143.     UI::SET_TEXT_WRAP(0.0, 1.0);
  144.     UI::SET_TEXT_CENTRE(0);
  145.     UI::SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0);
  146.     UI::SET_TEXT_OUTLINE();
  147.     UI::_SET_TEXT_ENTRY("STRING");
  148.     UI::_ADD_TEXT_COMPONENT_STRING(const_cast<char*>(text));
  149.     UI::_DRAW_TEXT(drawPosX, drawPosY);
  150. }
  151.  
  152. void main()
  153. {      
  154.     while (true)
  155.     {
  156.         update();
  157.         WAIT(0);
  158.     }
  159. }
  160.  
  161. void ScriptMain()
  162. {  
  163.     srand(GetTickCount());
  164.     main();
  165. }
RAW Paste Data