Advertisement
BratokHR

CoD2 draw k/d in status bar

Oct 7th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <iostream>
  3.  
  4. void cracking_hook_call(int from, const int to)
  5. {
  6.     DWORD dwback;
  7.     const int len = 5;
  8.  
  9.     VirtualProtect((LPVOID)from, len, PAGE_READWRITE, &dwback);
  10.  
  11.     int relative = to - (from + 5); // +5 is the position of next opcode
  12.     memcpy((void *)(from + 1), &relative, 4); // set relative address with endian
  13.  
  14.     VirtualProtect((LPVOID)from, len, dwback, &dwback);
  15. }
  16.  
  17. char static_text[128] = "\0";
  18. char *new_text = &static_text[0];
  19. int is_player, ptr_text;
  20. float score;
  21.  
  22. void save_score()
  23. {
  24.     score = atof((char*)ptr_text);
  25. }
  26.  
  27. void change_death()
  28. {
  29.     float death, kd;
  30.  
  31.     death = atof((char*)ptr_text);
  32.  
  33.     if (!score && !death)
  34.         kd = 0;
  35.     else if (!score && death)
  36.         kd = -death;
  37.     else if (score && !death)
  38.         kd = score;
  39.     else
  40.         kd = score / death;
  41.  
  42.     sprintf_s<128>(static_text, "%s (%.1f)", (char*)ptr_text, kd);
  43. }
  44.  
  45. bool draw_player()
  46. {
  47.     return (**(byte**)is_player == 0);
  48. }
  49.  
  50. bool cmp( char *txt )
  51. {
  52.     return (strcmp(*(char**)is_player, txt) == 0);
  53. }
  54.  
  55. bool draw_score()
  56. {
  57.     return cmp("CGAME_SB_SCORE");
  58. }
  59.  
  60. bool draw_death()
  61. {
  62.     return cmp("CGAME_SB_DEATHS");
  63. }
  64.  
  65. void __declspec(naked)Ui_DrawStatusBar()
  66. {
  67.     _asm
  68.     {
  69.         add ebp, 0x4
  70.         mov is_player, ebp
  71.         sub ebp, 0x4
  72.     }
  73.  
  74.     if (draw_score())
  75.     {
  76.         _asm
  77.         {
  78.             add esp, 0x4
  79.             pop eax
  80.             mov ptr_text, eax
  81.             push eax
  82.             sub esp, 0x4
  83.         }
  84.  
  85.         save_score();
  86.     }
  87.  
  88.     if (draw_death())
  89.     {
  90.         _asm
  91.         {
  92.             add esp, 0x4
  93.             pop eax
  94.             mov ptr_text, eax
  95.             push eax
  96.             sub esp, 0x4
  97.         }
  98.  
  99.         change_death();
  100.  
  101.         _asm
  102.         {
  103.             add esp, 0x4
  104.             pop eax
  105.             push new_text
  106.             sub esp, 0x4
  107.         }
  108.     }
  109.  
  110.     _asm
  111.     {
  112.         mov eax, 0x52BEF0
  113.         jmp eax
  114.     }
  115. }
  116.  
  117. void _main()
  118. {
  119.     while (GetModuleHandleA("gfx_d3d_mp_x86_s.dll") == 0)
  120.         Sleep(100);
  121.  
  122.     cracking_hook_call((int)0x4D419A, (int)Ui_DrawStatusBar);
  123. }
  124.  
  125. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID)
  126. {
  127.     DisableThreadLibraryCalls(hinstDLL);
  128.  
  129.     if (fdwReason == DLL_PROCESS_ATTACH)
  130.         CreateThread(0, 0, (LPTHREAD_START_ROUTINE)_main, 0, 0, 0);
  131.  
  132.     return true;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement