Advertisement
XForceP

GTA 5 Map for EFLC 1.1.2.0

Jan 25th, 2014
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.84 KB | None | 0 0
  1.  
  2. #define _USE_MATH_DEFINES // for C
  3. #include <math.h>
  4. #include <float.h>
  5. #include <Windows.h>
  6. #include <iostream>
  7.  
  8. /* Contains code posted by Wesser
  9. http://gtaforums.com/topic/569955-gta-sa-rectangular-hud/?p=1062888280
  10. */
  11.  
  12. struct Vec2
  13. {
  14.     Vec2(float x, float y)
  15.     {
  16.         fX = x;
  17.         fY = y;
  18.     }
  19.  
  20.     float fX;
  21.     float fY;
  22. };
  23.  
  24. struct Vector2
  25. {
  26.     Vector2(float x, float y)
  27.     {
  28.         fX = x;
  29.         fY = y;
  30.     }
  31.     Vector2()
  32.     { }
  33.  
  34.     float fX;
  35.     float fY;
  36. };
  37.  
  38. double otherMethod(Vector2 *a1);
  39.  
  40.  
  41. struct SRwV2d
  42. {
  43.     float m_fX;
  44.     float m_fY;
  45. };
  46.  
  47. struct SRwRect
  48. {
  49.     float m_fLeft;
  50.     float m_fTop;
  51.     float m_fRight;
  52.     float m_fBottom;
  53.  
  54.     void SetBounds(float fLeft, float fTop, float fRight, float fBottom)
  55.     {
  56.         m_fLeft = fLeft;
  57.         m_fTop = fTop;
  58.         m_fRight = fRight;
  59.         m_fBottom = fBottom;
  60.     }
  61. };
  62.  
  63. float clampWithinBounds(float fValue, float fMin, float fMax)
  64. {
  65.     return fValue > fMin ? (fValue < fMax ? fValue : fMax) : fMin;
  66. }
  67.  
  68. float isWithinEpsilonAbs(float fValue, float fCheck)
  69. {
  70.     return fabs(fValue - fCheck) < FLT_EPSILON;
  71. }
  72.  
  73. #ifdef METHOD1
  74. bool testPointWithinAARect(SRwV2d *pstPoint, SRwRect *pstRect, SRwV2d *pstClamp, float *pfDist)
  75. {
  76.     if (pstPoint->m_fX < pstRect->m_fLeft
  77.         || pstPoint->m_fY < pstRect->m_fTop
  78.         || pstPoint->m_fX > pstRect->m_fRight
  79.         || pstPoint->m_fY > pstRect->m_fBottom) {
  80.         pstClamp->m_fX = clampWithinBounds(pstPoint->m_fX, pstRect->m_fLeft, pstRect->m_fRight);
  81.         pstClamp->m_fY = clampWithinBounds(pstPoint->m_fY, pstRect->m_fTop, pstRect->m_fBottom);
  82.  
  83.         *pfDist = 1.0f + FLT_EPSILON;
  84.  
  85.         return false;
  86.     }
  87.  
  88.     pstClamp->m_fX = 0.0f;
  89.     pstClamp->m_fY = 0.0f;
  90.  
  91.     *pfDist = 0.0f;
  92.  
  93.     return true;
  94. }
  95. #else /* METHOD 1 */
  96. /* METHOD 2 */
  97. bool testPointWithinAARect(SRwV2d *pstPoint, SRwRect *pstRect, SRwV2d *pstClamp, float *pfDist)
  98. {
  99.     float fPointX, fPointY, fClampX, fClampY, fDistX, fDistY;
  100.  
  101.     fPointX = pstPoint->m_fX;
  102.     fPointY = pstPoint->m_fY;
  103.     fClampX = clampWithinBounds(fPointX, pstRect->m_fLeft, pstRect->m_fRight);
  104.     fClampY = clampWithinBounds(fPointY, pstRect->m_fTop, pstRect->m_fBottom);
  105.  
  106.     if (pstClamp) {
  107.         pstClamp->m_fX = fClampX;
  108.         pstClamp->m_fY = fClampY;
  109.     }
  110.  
  111.     if (pfDist) {
  112.         fDistX = fPointX - fClampX;
  113.         fDistY = fPointY - fClampY;
  114.  
  115.         // Is the point outside the rectangle?
  116.         if (fDistX) {
  117.             // Is the point in one of the outer squared regions in front of vertices?
  118.             if (fDistY) {
  119.                 // Isn't the point oblique relative to one of the vertices?
  120.                 if (!isWithinEpsilonAbs(fDistX, fDistY)) {
  121.                     *pfDist = sqrt((fPointX * fPointX) + (fPointY * fPointY));
  122.                     // The point lies on one of the rectangle (square) diagonals.
  123.                 }
  124.                 else {
  125.                     *pfDist = fabs(fDistX) * (float)M_SQRT2;
  126.                 }
  127.                 // The point is perpendicular to one of the edges on the Y axis.
  128.             }
  129.             else {
  130.                 *pfDist = fabs(fDistX);
  131.             }
  132.             // Is the point still outside the rectangle and perpendicular to one of the edges on the X axis?
  133.         }
  134.         else if (fDistY) {
  135.             *pfDist = fabs(fDistY);
  136.             // The point either lies on the border or is inside the rectangle and thus perpendicular to one of the edges.
  137.         }
  138.         else {
  139.             fPointX = fabs(fPointX);
  140.             fPointY = fabs(fPointY);
  141.             *pfDist = 1.0f - (fPointX < fPointY ? fPointX : fPointY);
  142.  
  143.             return true;
  144.         }
  145.  
  146.         return false;
  147.     }
  148.  
  149.     return fPointX == fClampX && fPointY == fClampY;
  150. }
  151. #endif
  152.  
  153.  
  154. // Converts degrees to radians.
  155. #define degreesToRadians(angleDegrees) (angleDegrees * M_PI / 180.0)
  156.  
  157. // Converts radians to degrees.
  158. #define radiansToDegrees(angleRadians) (angleRadians * 180.0 / M_PI)
  159.  
  160. #define MINX 1.0
  161. #define MINY 1.0
  162. #define MAXX 0.0
  163. #define MAXY 0.0
  164.  
  165.  
  166. #define ADD 1
  167. #define DIV 2
  168.  
  169. double otherMethod(Vector2 *a1)
  170. {
  171.     double result;
  172.     double degrees;
  173.  
  174.     result = sqrt(a1->fY * a1->fY + a1->fX * a1->fX);
  175.     if (result > 1.0)
  176.     {
  177.         if (a1->fX > MAXX && a1->fX < MINX && a1->fY > MAXY && a1->fY < MINY)
  178.             return 0.99;
  179.         degrees = radiansToDegrees(atan2(a1->fX, a1->fY));
  180.         if (degrees > 45.0 || degrees <= -45.0)
  181.         {
  182.             if (degrees > 45.0 && degrees <= 135.0)
  183.             {
  184.                 a1->fX = ((cos(degreesToRadians(degrees)) * M_SQRT2) + ADD) / DIV;
  185.                 a1->fY = MAXY;
  186.             }
  187.             else if (degrees <= 135.0 && degrees > -135.0)
  188.             {
  189.                 a1->fX = ((cos(degreesToRadians(degrees)) * M_SQRT2) + ADD) / DIV;
  190.                 a1->fY = MINY;
  191.             }
  192.             else
  193.             {
  194.                 a1->fX = MINX;
  195.                 a1->fY = ((sin(degreesToRadians(degrees)) * M_SQRT2) + ADD) / DIV;
  196.             }
  197.         }
  198.         else
  199.         {
  200.             a1->fX = MAXX;
  201.             a1->fY = ((sin(degreesToRadians(degrees)) * M_SQRT2) + ADD) / DIV;
  202.         }
  203.     }
  204.  
  205. #if 0
  206.     result = sqrt(a1->fY * a1->fY + a1->fX * a1->fX);
  207.     if (result > 1.0)
  208.     {
  209.         if (a1->fX > -1.0 && a1->fX < 1.0 && a1->fY > -1.0 && a1->fY < 1.0)
  210.             return 0.99;
  211.         degrees = radiansToDegrees(atan2(a1->fX, a1->fY));
  212.         if (degrees > 45.0 || degrees <= -45.0)
  213.         {
  214.             if (degrees > 45.0 && degrees <= 135.0)
  215.             {
  216.                 a1->fX = cos(degreesToRadians(degrees)) * M_SQRT2;
  217.                 a1->fY = 1.0;
  218.             }
  219.             else if (degrees <= 135.0 && degrees > -135.0)
  220.             {
  221.                 a1->fX = cos(degreesToRadians(degrees)) * M_SQRT2;
  222.                 a1->fY = -1.0;
  223.             }
  224.             else
  225.             {
  226.                 a1->fX = -1.0;
  227.                 a1->fY = sin(degreesToRadians(degrees)) * M_SQRT2;
  228.             }
  229.         }
  230.         else
  231.         {
  232.             a1->fX = 1.0;
  233.             a1->fY = sin(degreesToRadians(degrees)) * M_SQRT2;
  234.         }
  235.     }
  236. #endif
  237.  
  238.     return result;
  239. }
  240.  
  241. float getPointAARectDistance(SRwV2d *pstPoint)
  242. {
  243.     SRwRect stRect;
  244.     SRwV2d stClamp;
  245.     float fDist;
  246.  
  247.     stRect.SetBounds(0.0f /* Top */, 0.0f, 1.0f, 1.0f);
  248.  
  249.     if (!testPointWithinAARect(pstPoint, &stRect, &stClamp, &fDist)) {
  250.         pstPoint->m_fX = stClamp.m_fX;
  251.         pstPoint->m_fY = stClamp.m_fY;
  252.     }
  253.  
  254.     return fDist;
  255. }
  256.  
  257. Vector2 * v12;
  258. Vector2 * pViewportSize = new Vector2();
  259. float center;
  260. int bAbsolut;
  261.  
  262. #define MIN_X 0.025f
  263. #define MAX_X 0.975f
  264. #define MIN_Y 0.025f
  265. #define MAX_Y 0.975f
  266. #define ZERO 0.0f
  267. float fOriginalX;
  268. float fOriginalY;
  269.  
  270. void TestCalc()
  271. {
  272.     Vec2 * vec = new Vec2(0, 0);
  273.     for (float x = -2.0, y = -1.0, n = 0; x <= 2.0 && y <= 2.0; x += 0.1, y += 0.001, n++)
  274.     {
  275.         vec->fX = x;
  276.         vec->fY = y;
  277.         float k = otherMethod((Vector2*)vec);
  278.  
  279.         printf("[%.2f | %.2f ] %.2f %.2f %.2f", x, y, vec->fX, vec->fY, k);
  280.  
  281.         //if((int)n % 15 == 0)
  282.         printf("\n");
  283.     }
  284. }
  285.  
  286. void _declspec(naked) Keks()
  287. {
  288.     _asm  mov v12, edx;
  289.     _asm  push eax; get absolute flag
  290.     _asm  mov eax, [ebp + 14h]; 3rd parameter
  291.     _asm  mov bAbsolut, eax;
  292.     _asm  pop eax;
  293.  
  294.     fOriginalX = v12->fX;
  295.     fOriginalY = v12->fY;
  296.  
  297.     // Calculate and check our coordinates
  298.     if (!bAbsolut)
  299.     {
  300. //#define USE_NEW_METHOD
  301. #ifdef USE_NEW_METHOD
  302.         //getPointAARectDistance((SRwV2d*)v12);
  303.         otherMethod(v12);
  304. #else
  305.         if (v12->fX < MAX_X && v12->fX > MIN_X)
  306.         { // Check if the X axis is smaller than 1, but still positive
  307.             if (v12->fY < MAX_Y && v12->fY > MIN_Y) // Check if the Y Acis is smaller than 1, but still positive
  308.             {
  309.                 goto out; // Let GTA calc the position on itself
  310.             }
  311.             else
  312.             {
  313.                 if (v12->fY > MAX_Y) // Check if the Y Axis is bigger than 1 (set it 0.05 so it's not cutted of)
  314.                     v12->fY = MAX_Y;
  315.  
  316.                 if (v12->fY < MIN_Y) // Check if the Y Axis is smaller than 0 (set it +0.05 so it's not cutted of)
  317.                     v12->fY = MIN_Y;
  318.             }
  319.  
  320.             goto out;
  321.         }
  322.         else
  323.         {
  324.             if (v12->fX > MAX_X)
  325.                 v12->fX = MAX_X; // Check if the X Axis is bigger than 1 (set it 0.05 so it's not cutted of)
  326.  
  327.             if (v12->fX < MIN_X)
  328.                 v12->fX = MIN_X; // Check if the X Axis is smaller than 0 (set it +0.05 so it's not cutted of)
  329.         }
  330.  
  331.         if (v12->fY < MAX_Y && v12->fY > MIN_Y)
  332.         { // Check if the Y Acis is smaller than 1, but still positive
  333.             if (v12->fX < MAX_X && v12->fX > MIN_X)// Check if the X axis is smaller than 1, but still positive
  334.             {
  335.                 goto out;
  336.             }
  337.             else
  338.             {
  339.                 if (v12->fX > MAX_X) // Check if the X Axis is bigger than 1 (set it 0.05 so it's not cutted of)
  340.                     v12->fX = MAX_X;
  341.  
  342.                 if (v12->fX < 0) // Check if the X Axis is smaller than 0 (set it +0.05 so it's not cutted of)
  343.                     v12->fX = MIN_X;
  344.             }
  345.  
  346.             goto out;
  347.         }
  348.         else
  349.         {
  350.             if (v12->fY > MAX_Y) // Check if the Y Axis is bigger than 1 (set it 0.05 so it's not cutted of)
  351.                 v12->fY = MAX_Y;
  352.  
  353.             if (v12->fY < MIN_Y) // Check if the Y Axis is smaller than 0 (set it +0.05 so it's not cutted of)
  354.                 v12->fY = MIN_Y;
  355.         }
  356.         goto out;
  357. #endif
  358.     }
  359.  
  360. out:
  361.  
  362.     _asm    mov esp, ebp;
  363.     _asm    pop ebp;
  364.     _asm    retn;
  365. }
  366.  
  367. DWORD GetBase()
  368. {
  369.     static DWORD base = (DWORD)((DWORD)GetModuleHandle(NULL) - 0x400000);
  370.     return base;
  371. }
  372.  
  373. DWORD ResizeMapJmpBack;
  374. int a1, a2, a3;
  375.  
  376. _declspec(naked) signed int ResizeMap()
  377. {
  378.     _asm push eax;
  379.     _asm mov eax, [ebp + 4];
  380.     _asm mov a1, eax;
  381.     _asm mov eax, [ebp + 8];
  382.     _asm mov a2, eax;
  383.     _asm mov eax, [ebp + 0Ch];
  384.     _asm mov a3, eax;
  385.     _asm pushad;
  386.  
  387.     ResizeMapJmpBack = (g_pCore->GetBase() + 0x8364D7);
  388.  
  389.     _asm popad;
  390.     _asm pop eax;
  391.     _asm jmp ResizeMapJmpBack;
  392. }
  393.  
  394. DWORD sub_849BC0;
  395. _declspec(naked) void RenderMap()
  396. {
  397.     sub_849BC0 = (g_pCore->GetBase() + 0x849BC0);
  398.     _asm  call sub_849BC0;
  399.     _asm  add esp, 4;
  400.     _asm  popad;
  401.  
  402.     /*g_pCore->GetGame()->SetRadarVisible(true);*/
  403.  
  404.     _asm  pushad;
  405.     _asm  retn;
  406. }
  407.  
  408.  
  409. typedef unsigned char BYTE;
  410.  
  411. void PatchAddress(bool bJmp, DWORD dwAddress, DWORD dwNewAddress)
  412. {
  413.     if (bJmp)
  414.         *(BYTE *)(dwAddress) = 0xE9; // jmp
  415.     else
  416.         *(BYTE *)(dwAddress) = 0xE8; // call
  417.  
  418.     *(DWORD *)(dwAddress + 0x1) = (DWORD)dwNewAddress;
  419. }
  420.  
  421.  
  422. #define X86_NOP 0x90
  423. #define X86_RETN 0xC3
  424. #define X86_CALL 0xE8
  425. #define X86_JMP 0xE9
  426.  
  427. struct stProtectionInfo
  428. {
  429.     DWORD dwAddress;
  430.     DWORD dwOldProtection;
  431.     int   iSize;
  432. };
  433.  
  434.  
  435. stProtectionInfo Unprotect(DWORD dwAddress, int iSize)
  436. {
  437.     stProtectionInfo protectionInfo;
  438.     protectionInfo.dwAddress = dwAddress;
  439.     protectionInfo.iSize = iSize;
  440.     DWORD dwOldProtection;
  441.     VirtualProtect((void *)dwAddress, iSize, PAGE_EXECUTE_READWRITE, &dwOldProtection);
  442.     return protectionInfo;
  443. }
  444.  
  445. void Reprotect(stProtectionInfo protectionInfo)
  446. {
  447.     DWORD dwProtection;
  448.     VirtualProtect((void *)protectionInfo.dwAddress, protectionInfo.iSize, protectionInfo.dwOldProtection, &dwProtection);
  449. }
  450.  
  451. void * InstallDetourPatchInternal(DWORD dwAddress, DWORD dwDetourAddress, BYTE byteType, int iSize)
  452. {
  453.     // Allocate the trampoline memory
  454.     BYTE * pbyteTrampoline = (BYTE *)malloc(iSize + 5);
  455.  
  456.     // Unprotect the trampoline memory
  457.     Unprotect((DWORD)pbyteTrampoline, (iSize + 5));
  458.  
  459.     // Unprotect the address memory
  460.     stProtectionInfo protectionInfo = Unprotect(dwAddress, (iSize + 5));
  461.  
  462.     // Copy the overwritten address memory to the trampoline memory
  463.     memcpy(pbyteTrampoline, (void *)dwAddress, iSize);
  464.  
  465.     // Write the type to the trampoline memory
  466.     DWORD dwTrampoline = (DWORD)(pbyteTrampoline + iSize);
  467.     *(BYTE *)dwTrampoline = byteType;
  468.     *(DWORD *)(dwTrampoline + 1) = ((dwAddress + iSize) - dwTrampoline - 5);
  469.  
  470.     // Write the type to the address memory
  471.     *(BYTE *)dwAddress = byteType;
  472.     *(DWORD *)(dwAddress + 1) = (dwDetourAddress - dwAddress - 5);
  473.  
  474.     // Re-protect the address memory
  475.     Reprotect(protectionInfo);
  476.  
  477.     return pbyteTrampoline;
  478. }
  479.  
  480. void InstallJmpPatch(DWORD dwAddress, DWORD dwJmpAddress)
  481. {
  482.     InstallDetourPatchInternal(dwAddress, dwJmpAddress, X86_JMP, 5);
  483. }
  484.  
  485. void InstallCallPatch(DWORD dwAddress, DWORD dwCallAddress)
  486. {
  487.     InstallDetourPatchInternal(dwAddress, dwCallAddress, X86_CALL, 5);
  488. }
  489.  
  490.  
  491. void UnprotectMemory()
  492. {
  493.     BYTE                                                               *pImageBase = (BYTE *)(GetModuleHandle(NULL));
  494.     PIMAGE_DOS_HEADER                                               pDosHeader = (PIMAGE_DOS_HEADER)pImageBase;
  495.     PIMAGE_NT_HEADERS                                               pNtHeader = (PIMAGE_NT_HEADERS)(pImageBase + pDosHeader->e_lfanew);
  496.     PIMAGE_SECTION_HEADER                                   pSection = IMAGE_FIRST_SECTION(pNtHeader);
  497.     char                                                               *pszSectionName;
  498.  
  499.     for (int iSection = 0; iSection < pNtHeader->FileHeader.NumberOfSections; iSection++, pSection++) {
  500.         // Set value for compare
  501.         pszSectionName = (char *)pSection->Name;
  502.  
  503.         // Compare and check if the given memory segment identifier compares with our given segments
  504.         if (!strcmp(pszSectionName, ".text") || !strcmp(pszSectionName, ".rdata"))
  505.             Unprotect((DWORD)(pImageBase + pSection->VirtualAddress), ((pSection->Misc.VirtualSize + 4095) & ~4095));
  506.     }
  507. }
  508.  
  509. void Patch()
  510. {
  511.     // Other section
  512.     UnprotectMemory();
  513.  
  514.     // Change calc from circle to square(blips)
  515.     *(BYTE*)(GetBase() + 0x8385E7 + 0x6) = 0x1;
  516.     InstallJmpPatch(GetBase() + 0x8386AB, (DWORD)Keks); // E9
  517.  
  518.     // Enable square map(instead of circle map)
  519.     InstallJmpPatch(GetBase() + 0xA22C53, GetBase() + 0xA22EF3); // E9
  520.  
  521.     // Enable big radar
  522.     *(BYTE *)(GetBase() + 0x08364D0 + 0x6) = 0x1;
  523.  
  524.     // Hook resize map function
  525.     InstallJmpPatch(GetBase() + 0x8364D0, (DWORD)ResizeMap); // E9
  526.     *(WORD *)(GetBase() + 0x8364D0 + 0x5) = 0x9090;
  527.  
  528.     // Make blip small
  529.     *(BYTE *)(GetBase() + 0x4B516F + 0x6) = 0x1;
  530.     *(BYTE *)(GetBase() + 0x4B516F + 0x6) = 0x1;
  531.  
  532.     // Hook render map function
  533.     InstallCallPatch((GetBase() + 0xA22E71), (DWORD)RenderMap); // E8
  534. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement