From 611182e394c86ff8c6b050a4bd69c09b9e5f7987 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Sun, 23 Jul 2023 15:50:01 +0200 Subject: [PATCH] Add correct_movement, call from CL_CreateMove --- src/features/features.h | 1 + src/features/movement.c | 23 +++++++++++++++++++++++ src/hooks.c | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/src/features/features.h b/src/features/features.h index dfc1487..e4ce1fb 100644 --- a/src/features/features.h +++ b/src/features/features.h @@ -9,5 +9,6 @@ void bhop(usercmd_t* cmd); /* src/features/esp.c */ void esp(void); +void correct_movement(usercmd_t* cmd, vec3_t old_angles); #endif /* FEATURES_H_ */ diff --git a/src/features/movement.c b/src/features/movement.c index a6778bd..79a2ef9 100644 --- a/src/features/movement.c +++ b/src/features/movement.c @@ -1,10 +1,12 @@ #include +#include #include "features.h" #include "../include/sdk.h" #include "../include/globals.h" #include "../include/cvars.h" +#include "../include/util.h" static void autostrafe_legit(usercmd_t* cmd) { /* Get mouse delta */ @@ -41,3 +43,24 @@ void bhop(usercmd_t* cmd) { } } } + +/* + * Unfortunately I don't know shit about math, so this is pasted from: + * https://github.com/deboogerxyz/ahc/blob/0492646e28dd7234a8cd431d37b152dc18a21b04/ahc.c#L377 + */ +void correct_movement(usercmd_t* cmd, vec3_t old_angles) { + float old_y = old_angles[1] + (old_angles[1] < 0 ? 360 : 0); + float new_y = cmd->viewangles[1] + (cmd->viewangles[1] < 0 ? 360 : 0); + float delta = (new_y < old_y) ? fabsf(new_y - old_y) + : 360 - fabsf(new_y - old_y); + + delta = 360 - delta; + + float forward = cmd->forwardmove; + float side = cmd->sidemove; + + cmd->forwardmove = + cos(DEG2RAD(delta)) * forward + cos(DEG2RAD(delta + 90)) * side; + cmd->sidemove = + sin(DEG2RAD(delta)) * forward + sin(DEG2RAD(delta + 90)) * side; +} diff --git a/src/hooks.c b/src/hooks.c index ace9721..19ac27c 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -19,10 +19,14 @@ bool hooks_init(void) { void h_CL_CreateMove(float frametime, usercmd_t* cmd, int active) { ORIGINAL(CL_CreateMove, frametime, cmd, active); + vec3_t old_angles = cmd->viewangles; + /* Declared in globals.c */ localplayer = i_engine->GetLocalPlayer(); bhop(cmd); + + correct_movement(cmd, old_angles); } int h_HUD_Redraw(float time, int intermission) {