Merge pull request #729 from diamante0018/main

feat: cl_yawspeed & cl_pitchspeed
This commit is contained in:
Maurice Heumann 2023-05-18 09:33:04 +02:00 committed by GitHub
commit 6762da248b
5 changed files with 67 additions and 5 deletions

View File

@ -4,6 +4,7 @@
#include "scheduler.hpp" #include "scheduler.hpp"
#include <game/game.hpp> #include <game/game.hpp>
#include <game/utils.hpp>
#include <utils/hook.hpp> #include <utils/hook.hpp>
#include <utils/io.hpp> #include <utils/io.hpp>
@ -16,6 +17,9 @@ namespace client_patches
{ {
utils::hook::detour preload_map_hook; utils::hook::detour preload_map_hook;
const game::dvar_t* cl_yaw_speed;
const game::dvar_t* cl_pitch_speed;
void stop_intro_if_needed() void stop_intro_if_needed()
{ {
if (game::Com_SessionMode_GetMode() != game::MODE_ZOMBIES && if (game::Com_SessionMode_GetMode() != game::MODE_ZOMBIES &&
@ -110,6 +114,16 @@ namespace client_patches
} }
} }
float cl_key_state_yaw_speed_stub(void* key)
{
return game::CL_KeyState(key) * cl_yaw_speed->current.value.value;
}
float cl_key_state_pitch_speed_stub(void* key)
{
return game::CL_KeyState(key) * cl_pitch_speed->current.value.value;
}
game::fileHandle_t fs_f_open_file_write_to_dir_stub(const char* filename, [[maybe_unused]] const char* dir, game::fileHandle_t fs_f_open_file_write_to_dir_stub(const char* filename, [[maybe_unused]] const char* dir,
const char* os_base_path) const char* os_base_path)
{ {
@ -183,6 +197,8 @@ namespace client_patches
class component final : public client_component class component final : public client_component
{ {
public: public:
static_assert(offsetof(game::clientActive_t, viewangles) == 0xB8C8);
component() component()
{ {
migrate_if_needed(); // TODO: Remove me after some time migrate_if_needed(); // TODO: Remove me after some time
@ -210,6 +226,17 @@ namespace client_patches
// Always get loadscreen gametype from s_gametype // Always get loadscreen gametype from s_gametype
utils::hook::set<uint8_t>(0x14228F5DC_g, 0xEB); utils::hook::set<uint8_t>(0x14228F5DC_g, 0xEB);
cl_yaw_speed = game::register_dvar_float("cl_yawspeed", 140.0f, std::numeric_limits<float>::min(), std::numeric_limits<float>::max(),
game::DVAR_NONE, "Max yaw speed in degrees for game pad and keyboard");
cl_pitch_speed = game::register_dvar_float("cl_pitchspeed", 140.0f, std::numeric_limits<float>::min(), std::numeric_limits<float>::max(),
game::DVAR_NONE, "Max pitch speed in degrees for game pad");
// CL_AdjustAngles
utils::hook::call(0x1412F3324_g, cl_key_state_yaw_speed_stub); // cl_yawspeed
utils::hook::call(0x1412F3344_g, cl_key_state_yaw_speed_stub); // ^^
utils::hook::call(0x1412F3380_g, cl_key_state_pitch_speed_stub); // cl_pitchspeed
utils::hook::call(0x1412F33A1_g, cl_key_state_pitch_speed_stub); // ^^
patch_players_folder_name(); patch_players_folder_name();
} }
}; };

View File

@ -11,7 +11,6 @@ namespace patches
namespace namespace
{ {
const game::dvar_t* lobby_min_players; const game::dvar_t* lobby_min_players;
const game::dvar_t* cl_yaw_speed;
void script_errors_stub([[maybe_unused]] const char* file, [[maybe_unused]] int line, void script_errors_stub([[maybe_unused]] const char* file, [[maybe_unused]] int line,
[[maybe_unused]] unsigned int code, const char* fmt, ...) [[maybe_unused]] unsigned int code, const char* fmt, ...)
@ -79,9 +78,6 @@ namespace patches
lobby_min_players = game::register_dvar_int("lobby_min_players", 0, 0, 8, game::DVAR_NONE, ""); lobby_min_players = game::register_dvar_int("lobby_min_players", 0, 0, 8, game::DVAR_NONE, "");
utils::hook::jump(game::select(0x141A7BCF0, 0x1402CB900), scr_get_num_expected_players, true); utils::hook::jump(game::select(0x141A7BCF0, 0x1402CB900), scr_get_num_expected_players, true);
cl_yaw_speed = game::register_dvar_float("cl_yawspeed", 140.0f, std::numeric_limits<float>::min(), std::numeric_limits<float>::max(),
game::DVAR_NONE, "Max yaw speed in degrees for game pad and keyboard");
} }
}; };
} }

View File

@ -634,6 +634,41 @@ namespace game
void* errorData; void* errorData;
}; };
enum connstate_t
{
CA_DISCONNECTED = 0x0,
CA_CINEMATIC = 0x1,
CA_UICINEMATIC = 0x2,
CA_LOGO = 0x3,
CA_CONNECTING = 0x4,
CA_CHALLENGING = 0x5,
CA_CONFIRMLOADING = 0x6,
CA_CONNECTED = 0x7,
CA_SENDINGDATA = 0x8,
CA_LOADING = 0x9,
CA_PRIMED = 0xA,
CA_ACTIVE = 0xB,
};
struct clientUIActive_t
{
int flags;
int keyCatchers;
connstate_t connectionState;
unsigned char __pad0[0x106C];
};
static_assert(sizeof(clientUIActive_t) == 0x1078);
struct clientActive_t
{
char __pad0[0xB8C8];
float viewangles[3];
char __pad1[0x18C15C];
};
static_assert(sizeof(clientActive_t) == 0x197A30);
typedef void* fileHandle_t; typedef void* fileHandle_t;
typedef uint32_t dvarStrHash_t; typedef uint32_t dvarStrHash_t;

View File

@ -20,6 +20,8 @@ namespace game
WEAK symbol<bool(int localClientNum, int index, char* buf, int size, bool addClanName)> CL_GetClientName{ WEAK symbol<bool(int localClientNum, int index, char* buf, int size, bool addClanName)> CL_GetClientName{
0x1413E3140 0x1413E3140
}; };
WEAK symbol<bool(int localClientNum)> CL_LocalClient_IsActive{0x14283AA50};
WEAK symbol<float(void* key)> CL_KeyState{0x1412FF860};
// Game // Game
WEAK symbol<void(gentity_s* ent, gentity_s* target, int mode, const char* chatText)> G_Say{0x0, 0x140299170}; WEAK symbol<void(gentity_s* ent, gentity_s* target, int mode, const char* chatText)> G_Say{0x0, 0x140299170};
@ -282,6 +284,8 @@ namespace game
// Dvar variables // Dvar variables
WEAK symbol<dvar_t*> com_maxclients{0x0, 0x14948EE70}; WEAK symbol<dvar_t*> com_maxclients{0x0, 0x14948EE70};
WEAK symbol<clientUIActive_t> clientUIActives{0x1453D8BC0};
namespace s_wcd namespace s_wcd
{ {
WEAK symbol<HWND> codLogo{0x157E75A50, 0x14A640BC0}; WEAK symbol<HWND> codLogo{0x157E75A50, 0x14A640BC0};