Advertisement
Dimitri_UA

Lensflare

May 1st, 2012
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.58 KB | None | 0 0
  1. /*
  2. Lensflare Modification for GTA San Andreas
  3. vol-gta.com      01/05/2012        DK22Pac
  4. */
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #define patch(a, v, s) _patch((void*)(a), (DWORD)(v), (s))
  9. #define rwRENDERSTATETEXTURERASTER 1
  10. #define _RwEngineInstance 0xC97B24
  11. #define _txdIndexByName 0x731850
  12. #define _getTexDictionary 0x408340
  13. #define _RwTexDictionaryFindNamedTexture 0x7F39F0
  14. #define _drawTexturedRect 0x728350
  15. #define _RGBA__set 0x7170C0
  16. #define _processLineOfSight 0x56BA00
  17. #define playerPtr 0xB6F5F0
  18. #define ignoringEntity 0xB7CD68
  19.  
  20. BOOL APIENTRY DllMain(HMODULE, DWORD, LPVOID);
  21. void _patch(void*,DWORD,DWORD);
  22. void LensflareDisableRandomizer(void);
  23. void NotTestPlayer(void);
  24. void setHaloSizeAndTexture(void);
  25.  
  26. typedef struct halo
  27. {
  28.     float distance, size;
  29.     short red, green, blue, alpha;
  30.     char  texture[32];
  31. } h;
  32.  
  33. char buf[1024];
  34. char aFx[8] = "fx";
  35. int i;
  36. float fZero = 0.0f;
  37. float fOne = 0.003921568627451f;
  38. float a[4];
  39. float t1, t2, t3;
  40. float t4 = 4.0f;
  41. char b[16];
  42. DWORD rwT;
  43. DWORD * pT = &rwT;
  44. h list[50];
  45. halo * pList = &list[0];
  46.  
  47. BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID lpReserved)
  48. {
  49.     if(reason==DLL_PROCESS_ATTACH)
  50.     {
  51.         patch(0x6FB30A, pList, 4);
  52.         patch(0x88DBA8, pList, 4);
  53.         patch(0x6FB46B, (char)sizeof(halo), 1);
  54.         patch(0x6FB355, 0xE9, 1);
  55.         patch(0x6FB356, (DWORD)&LensflareDisableRandomizer - 0x6FB35A, 4);
  56.         patch(0x6FB409, 0xE9, 1);
  57.         patch(0x6FB40A, (DWORD)&NotTestPlayer - 0x6FB40E, 4);
  58.         patch(0x6FB461, 0xE9, 1);
  59.         patch(0x6FB462, (DWORD)&setHaloSizeAndTexture - 0x6FB466, 4);
  60.  
  61.         FILE * f = fopen("lensflare.dat", "rt");
  62.         i = 0;
  63.         while(!feof(f))
  64.         {
  65.             fgets(buf, 1024, f);
  66.             if (buf[0] == ';') continue;
  67.             if (buf[0] == '\0' || i > 49) break;
  68.             sscanf(buf, "%*d %f %f %d %d %d %d %s", &list[i].distance,
  69.             &list[i].size, &list[i].red, &list[i].green, &list[i].blue,
  70.             &list[i].alpha, list[i].texture);
  71.             if (strncmp (list[i].texture, "null", 4) == 0) memset(&list[i].texture, 0, 32);
  72.             i++;
  73.         }
  74.         fclose(f);
  75.     }
  76.     return TRUE;
  77. }
  78.  
  79. void _patch(void* pAddress, DWORD data, DWORD iSize)
  80. {
  81.     unsigned long dwProtect[2];                            
  82.     VirtualProtect(pAddress, iSize, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
  83.     switch(iSize)
  84.     {
  85.             case 1: *(BYTE*)pAddress = (BYTE)data;
  86.                 break;
  87.             case 2: *(WORD*)pAddress = (WORD)data;
  88.                 break;
  89.             case 4: *(DWORD*)pAddress = (DWORD)data;
  90.                 break;
  91.             default: memset(pAddress, data, iSize);
  92.                 break;
  93.     }
  94.     VirtualProtect(pAddress, iSize, dwProtect[0], &dwProtect[1]);
  95. }
  96.  
  97. void __declspec(naked) LensflareDisableRandomizer()
  98. {
  99.     _asm
  100.     {
  101.         fmul    [fZero]
  102.         fadd    [fOne]
  103.         mov     eax, 0x6FB35B
  104.         jmp     eax
  105.     }
  106. }
  107.  
  108. void __declspec(naked) NotTestPlayer()
  109. {
  110.     _asm
  111.     {
  112.         mov     eax, playerPtr
  113.         mov     edx, [eax]
  114.         mov     eax, ignoringEntity
  115.         mov     [eax], edx
  116.         mov     eax, _processLineOfSight
  117.         call    eax
  118.         mov     edx, 0x6FB40E
  119.         jmp     edx
  120.     }
  121. }
  122.  
  123. void __declspec(naked) setHaloSizeAndTexture()
  124. {
  125.     _asm
  126.     {
  127.         mov     ecx, [esp]
  128.         mov     t1, ecx
  129.         mov     ecx, [esp+4]
  130.         mov     t2, ecx
  131.         fld     dword ptr [esi+4]
  132.         fmul    [t4]
  133.         fstp    [t3]
  134.     }
  135.     a[0] = t1-t3;
  136.     a[1] = t2-t3;
  137.     a[2] = t1+t3;
  138.     a[3] = t2+t3;
  139.     __asm{
  140.         xor     eax, eax
  141.         movsx   eax, [esi+0xE]
  142.         push    eax
  143.         movsx   eax, [esi+0xC]
  144.         push    eax
  145.         movsx   eax, [esi+0xA]
  146.         push    eax
  147.         movsx   eax, [esi+8]
  148.         push    eax
  149.         lea     ecx, [b]
  150.         mov     eax, _RGBA__set
  151.         call    eax
  152.         push    eax
  153.         lea     eax, [a]
  154.         push    eax
  155.         lea     eax, [aFx]
  156.         push    eax
  157.         mov     eax, _txdIndexByName
  158.         call    eax
  159.         add     esp, 4
  160.         push    eax
  161.         mov     eax, _getTexDictionary
  162.         call    eax
  163.         add     esp, 4
  164.         lea     edx, [esi+0x10]
  165.         push    edx
  166.         push    eax
  167.         mov     eax, _RwTexDictionaryFindNamedTexture
  168.         call    eax
  169.         add     esp, 8
  170.         mov     rwT, eax
  171.         mov     ecx, pT
  172.         mov     eax, _drawTexturedRect
  173.         call    eax
  174.         mov     eax, 0x6FB466
  175.         jmp     eax
  176.     }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement