Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //m_filter 1
- #include <Windows.h>
- #include <cmath>
- #include "detours.h"
- uintptr_t client, engine;
- typedef void(__cdecl* cbuf_addtext_fn)(const char*);
- typedef void(__thiscall* apply_mouse_fn)(void*, void*, void*, float, float);
- typedef void(__thiscall* controller_move_fn)(void*, float, void*);
- apply_mouse_fn o_apply_mouse;
- controller_move_fn o_controller_move;
- cbuf_addtext_fn o_cbuf_addtext;
- typedef void(__cdecl* conmsg_fn)(const char*, ...);
- conmsg_fn con_msg;
- float frametime;
- float power = 1.f, gain = 1.f;
- bool enabled = false;
- void __fastcall apply_mouse_hk(void* thisptr, void* edx, void* viewangles, void* cmd, float mouse_x, float mouse_y)
- {
- uintptr_t localplayer = *(uintptr_t*)(client + 0x4C6708);
- float* host_frametime = (float*)(engine + 0x63A62C);
- float ft = frametime <= *(float*)host_frametime ? frametime : *(float*)host_frametime;
- *(float*)host_frametime -= ft;
- if (enabled && GetAsyncKeyState(VK_SPACE) && mouse_x)
- {
- float velocity[2] = { *(float*)(localplayer + 0xF4), *(float*)(localplayer + 0xF8) };
- float velocity_length = sqrt(velocity[0] * velocity[0] + velocity[1] * velocity[1]);
- float sidemove = *(float*)((uintptr_t)cmd + 0x1C);
- if (velocity_length > 280.f && ((sidemove < 0.f && mouse_x < 0.f) || (sidemove > 0.f && mouse_x > 0.f)))
- {
- float m_yaw = *(float*)(client + 0x4F3EAC);
- float sensitivity = *(float*)(client + 0x4F3F84);
- float interval_per_tick = *(float*)(*(uintptr_t*)((uintptr_t)(client + 0x49826C)) + 0x1C);
- float diff = std::copysignf(asin(30.f / velocity_length) * 57.2958f * gain * ft * 1.f / interval_per_tick / m_yaw, mouse_x);
- mouse_x = round((mouse_x * (1.f - power) + diff * power) / sensitivity) * sensitivity;
- }
- }
- o_apply_mouse(thisptr, viewangles, cmd, mouse_x, mouse_y);
- }
- void __fastcall controller_move_hk(void* thisptr, void* a, float ft, void* cmd)
- {
- frametime = ft;
- o_controller_move(thisptr, frametime, cmd);
- }
- void cbuf_addtext_hk(const char* text)
- {
- char* cmd = new char[255];
- strcpy_s(cmd, 255, text);
- int start = 0;
- char* buf = cmd;
- char* buffer = buf;
- while (*buf && *buf++ == ' ') ++start;
- while (*buf++);
- int end = buf - buffer - 1;
- while (end > 0 && buffer[end - 1] == ' ') --end;
- buffer[end] = 0;
- if (end > start || start != 0)
- {
- buf = buffer + start;
- while ((*buffer++ = *buf++));
- }
- if (strstr(cmd, "opti_power ") == cmd || strcmp(cmd, "opti_power") == 0)
- {
- if (strcmp(cmd, "opti_power") != 0)
- power = atof(cmd + 10) / 100.0;
- con_msg("optimizer power: %.2f%%\n", power * 100.0);
- }
- else if (strstr(cmd, "opti_gain ") == cmd || strcmp(cmd, "opti_gain") == 0)
- {
- if (strcmp(cmd, "opti_gain") != 0)
- gain = atof(cmd + 9) / 100.0;
- con_msg("optimizer target gain: %.2f%%\n", gain * 100.0);
- }
- else if (strcmp(cmd, "opti_toggle") == 0)
- {
- enabled = !enabled;
- con_msg("strafe optimizer %s\n", enabled ? "ON" : "OFF");
- }
- else
- {
- o_cbuf_addtext(text);
- }
- delete[] cmd;
- }
- DWORD WINAPI main_thread(LPVOID lpThreadParameter)
- {
- client = (uintptr_t)GetModuleHandle("client.dll");
- engine = (uintptr_t)GetModuleHandle("engine.dll");
- con_msg = (conmsg_fn)((uintptr_t)GetModuleHandle("tier0.dll") + 0x40E0);
- o_cbuf_addtext = (cbuf_addtext_fn)(engine + 0x16DDA0);
- o_apply_mouse = (apply_mouse_fn)(client + 0x148D50);
- o_controller_move = (controller_move_fn)(client + 0x146660);
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
- DetourAttach(&(PVOID&)o_cbuf_addtext, cbuf_addtext_hk);
- DetourAttach(&(PVOID&)o_apply_mouse, apply_mouse_hk);
- DetourAttach(&(PVOID&)o_controller_move, controller_move_hk);
- DetourTransactionCommit();
- return TRUE;
- }
- BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- DisableThreadLibraryCalls(hModule);
- CreateThread(0, 0, main_thread, hModule, 0, 0);
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment