Guest User

Untitled

a guest
Oct 5th, 2019
3,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.95 KB | None | 0 0
  1. //m_filter 1
  2.  
  3. #include <Windows.h>
  4. #include <cmath>
  5.  
  6. #include "detours.h"
  7.  
  8. uintptr_t client, engine;
  9.  
  10. typedef void(__cdecl* cbuf_addtext_fn)(const char*);
  11. typedef void(__thiscall* apply_mouse_fn)(void*, void*, void*, float, float);
  12. typedef void(__thiscall* controller_move_fn)(void*, float, void*);
  13.  
  14. apply_mouse_fn o_apply_mouse;
  15. controller_move_fn o_controller_move;
  16.  
  17. cbuf_addtext_fn o_cbuf_addtext;
  18.  
  19. typedef void(__cdecl* conmsg_fn)(const char*, ...);
  20. conmsg_fn con_msg;
  21.  
  22. float frametime;
  23.  
  24. float power = 1.f, gain = 1.f;
  25. bool enabled = false;
  26.  
  27. void __fastcall apply_mouse_hk(void* thisptr, void* edx, void* viewangles, void* cmd, float mouse_x, float mouse_y)
  28. {
  29.     uintptr_t localplayer = *(uintptr_t*)(client + 0x4C6708);
  30.  
  31.     float* host_frametime = (float*)(engine + 0x63A62C);
  32.     float ft = frametime <= *(float*)host_frametime ? frametime : *(float*)host_frametime;
  33.     *(float*)host_frametime -= ft;
  34.  
  35.     if (enabled && GetAsyncKeyState(VK_SPACE) && mouse_x)
  36.     {
  37.         float velocity[2] = { *(float*)(localplayer + 0xF4), *(float*)(localplayer + 0xF8) };
  38.         float velocity_length = sqrt(velocity[0] * velocity[0] + velocity[1] * velocity[1]);
  39.        
  40.         float sidemove = *(float*)((uintptr_t)cmd + 0x1C);
  41.  
  42.         if (velocity_length > 280.f && ((sidemove < 0.f && mouse_x < 0.f) || (sidemove > 0.f && mouse_x > 0.f)))
  43.         {
  44.             float m_yaw = *(float*)(client + 0x4F3EAC);
  45.             float sensitivity = *(float*)(client + 0x4F3F84);
  46.             float interval_per_tick = *(float*)(*(uintptr_t*)((uintptr_t)(client + 0x49826C)) + 0x1C);
  47.             float diff = std::copysignf(asin(30.f / velocity_length) * 57.2958f * gain * ft * 1.f / interval_per_tick / m_yaw, mouse_x);
  48.             mouse_x = round((mouse_x * (1.f - power) + diff * power) / sensitivity) * sensitivity;
  49.         }
  50.     }
  51.  
  52.     o_apply_mouse(thisptr, viewangles, cmd, mouse_x, mouse_y);
  53. }
  54.  
  55. void __fastcall controller_move_hk(void* thisptr, void* a, float ft, void* cmd)
  56. {
  57.     frametime = ft;
  58.  
  59.     o_controller_move(thisptr, frametime, cmd);
  60. }
  61.  
  62. void cbuf_addtext_hk(const char* text)
  63. {
  64.     char* cmd = new char[255];
  65.     strcpy_s(cmd, 255, text);
  66.    
  67.     int start = 0;
  68.     char* buf = cmd;
  69.     char* buffer = buf;
  70.     while (*buf && *buf++ == ' ') ++start;
  71.     while (*buf++);
  72.     int end = buf - buffer - 1;
  73.     while (end > 0 && buffer[end - 1] == ' ') --end;
  74.     buffer[end] = 0;
  75.     if (end > start || start != 0)
  76.     {
  77.         buf = buffer + start;
  78.         while ((*buffer++ = *buf++));
  79.     }
  80.    
  81.     if (strstr(cmd, "opti_power ") == cmd || strcmp(cmd, "opti_power") == 0)
  82.     {
  83.         if (strcmp(cmd, "opti_power") != 0)
  84.             power = atof(cmd + 10) / 100.0;
  85.  
  86.         con_msg("optimizer power: %.2f%%\n", power * 100.0);
  87.     }
  88.     else if (strstr(cmd, "opti_gain ") == cmd || strcmp(cmd, "opti_gain") == 0)
  89.     {
  90.         if (strcmp(cmd, "opti_gain") != 0)
  91.             gain = atof(cmd + 9) / 100.0;
  92.  
  93.         con_msg("optimizer target gain: %.2f%%\n", gain * 100.0);
  94.     }
  95.     else if (strcmp(cmd, "opti_toggle") == 0)
  96.     {
  97.         enabled = !enabled;
  98.         con_msg("strafe optimizer %s\n", enabled ? "ON" : "OFF");
  99.     }
  100.     else
  101.     {
  102.         o_cbuf_addtext(text);
  103.     }
  104.  
  105.     delete[] cmd;
  106. }
  107.  
  108. DWORD WINAPI main_thread(LPVOID lpThreadParameter)
  109. {
  110.     client = (uintptr_t)GetModuleHandle("client.dll");
  111.     engine = (uintptr_t)GetModuleHandle("engine.dll");
  112.  
  113.     con_msg = (conmsg_fn)((uintptr_t)GetModuleHandle("tier0.dll") + 0x40E0);
  114.  
  115.     o_cbuf_addtext = (cbuf_addtext_fn)(engine + 0x16DDA0);
  116.  
  117.     o_apply_mouse = (apply_mouse_fn)(client + 0x148D50);
  118.     o_controller_move = (controller_move_fn)(client + 0x146660);
  119.  
  120.     DetourTransactionBegin();
  121.     DetourUpdateThread(GetCurrentThread());
  122.     DetourAttach(&(PVOID&)o_cbuf_addtext, cbuf_addtext_hk);
  123.     DetourAttach(&(PVOID&)o_apply_mouse, apply_mouse_hk);
  124.     DetourAttach(&(PVOID&)o_controller_move, controller_move_hk);
  125.     DetourTransactionCommit();
  126.  
  127.     return TRUE;
  128. }
  129.  
  130. BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
  131. {
  132.     switch (ul_reason_for_call)
  133.     {
  134.     case DLL_PROCESS_ATTACH:
  135.  
  136.         DisableThreadLibraryCalls(hModule);
  137.  
  138.         CreateThread(0, 0, main_thread, hModule, 0, 0);
  139.     }
  140.     return TRUE;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment