use different hook for some detours

This commit is contained in:
quaK 2025-04-30 12:48:01 +03:00
parent 71ef00d29c
commit 699cf54010
9 changed files with 27 additions and 57 deletions

View File

@ -18,8 +18,6 @@ namespace fov
game::dvar_t* cg_fovScale;
game::dvar_t* cg_use_fov_comp;
utils::hook::detour cg_view_calc_fov_compensation_hook;
float cg_view_calc_fov_compensation_stub(game::cg_s* blob)
{
if (!cg_use_fov_comp->current.enabled)
@ -27,7 +25,7 @@ namespace fov
return 0.0f;
}
return cg_view_calc_fov_compensation_hook.invoke<float>(blob);
return utils::hook::invoke<float>(0x140889B60, blob);
}
}
@ -63,7 +61,8 @@ namespace fov
// disable FOV compensation by default
cg_use_fov_comp = game::Dvar_RegisterBool("cg_use_fov_comp", false, game::DVAR_FLAG_SAVED, "Use FOV offset compensation for the viewmodel");
cg_view_calc_fov_compensation_hook.create(0x140889B60, cg_view_calc_fov_compensation_stub);
utils::hook::call(0x140186FC4, cg_view_calc_fov_compensation_stub);
utils::hook::call(0x1408D5940, cg_view_calc_fov_compensation_stub);
// patch max fov values
utils::hook::inject(0x14087E08B + 4, &max_fov);

View File

@ -16,13 +16,11 @@ namespace gameplay
{
namespace
{
utils::hook::detour stuck_in_client_hook;
void stuck_in_client_stub(void* entity)
{
if (dvars::bg_playerEjection->current.enabled)
{
stuck_in_client_hook.invoke<void>(entity);
utils::hook::invoke<void>(0x140AFD9B0, entity);
}
}
@ -144,7 +142,7 @@ namespace gameplay
{
// Implement ejection dvar
dvars::bg_playerEjection = game::Dvar_RegisterBool("bg_playerEjection", true, game::DVAR_FLAG_REPLICATED, "Flag whether player ejection is on or off");
stuck_in_client_hook.create(0x140AFD9B0, stuck_in_client_stub);
utils::hook::call(0x140AFA739, stuck_in_client_stub);
// Implement bounces dvar
dvars::bg_bounces = game::Dvar_RegisterBool("bg_bounces", false, game::DVAR_FLAG_REPLICATED, "Enables bounces");

View File

@ -9,8 +9,6 @@ namespace intro
{
namespace
{
utils::hook::detour cinematic_start_playback_hook;
void cinematic_start_playback(const char* name, const int playbackFlags, const int startOffsetMsec,
const bool fillerBink, const int pauseState)
{
@ -26,7 +24,7 @@ namespace intro
}
}
cinematic_start_playback_hook.invoke(name, playbackFlags, startOffsetMsec, fillerBink, pauseState);
utils::hook::invoke<void>(0x140DD6A10, name, playbackFlags, startOffsetMsec, fillerBink, pauseState);
}
}
@ -35,7 +33,8 @@ namespace intro
public:
void post_unpack() override
{
cinematic_start_playback_hook.create(0x140DD6A10, cinematic_start_playback);
utils::hook::call(0x140DD69FF, cinematic_start_playback);
utils::hook::call(0x140DD69CF, cinematic_start_playback);
}
};
}

View File

@ -58,7 +58,6 @@ namespace network
namespace
{
utils::hook::detour cl_dispatch_connectionless_packet_hook;
bool cl_dispatch_connectionless_packet_stub(int client_num, game::netadr_s* from, game::msg_t* msg, int time)
{
if (handle_command(from, game::Cmd_Argv(0), msg))
@ -66,7 +65,7 @@ namespace network
return true;
}
return cl_dispatch_connectionless_packet_hook.invoke<bool>(client_num, from, msg, time);
return utils::hook::invoke<bool>(0x1409B2250, client_num, from, msg, time);
}
int dw_send_to_stub(const int length, const char* data, game::netadr_s* to)
@ -310,7 +309,7 @@ namespace network
utils::hook::jump(0x140D93D70, dw_recv_from_stub);
// intercept command handling
cl_dispatch_connectionless_packet_hook.create(0x1409B2250, cl_dispatch_connectionless_packet_stub);
utils::hook::call(0x1403572B7, cl_dispatch_connectionless_packet_stub);
// handle xuid without secure connection
utils::hook::nop(0x140C53315, 2);

View File

@ -483,13 +483,6 @@ namespace party
utils::hook::invoke<void>(0x140341430, 0, cmd); // CL_Main_AddReliableCommand
}
utils::hook::detour cl_prepare_for_map_restart_hook;
void cl_prepare_for_map_restart_stub(const char* mapname, const char* gametype)
{
cl_prepare_for_map_restart_hook.invoke<void>(mapname, gametype);
}
utils::hook::detour cl_initialize_gamestate_hook;
void cl_initialize_gamestate_stub(int local_client_num)
{
if (!game::Com_IsAnyLocalServerRunning())
@ -497,7 +490,7 @@ namespace party
send_user_info();
}
cl_initialize_gamestate_hook.invoke<void>(local_client_num);
utils::hook::invoke<void>(0x1409B2FA0, local_client_num);
}
}
@ -718,8 +711,7 @@ namespace party
// enable custom kick reason in GScr_KickPlayer
utils::hook::set<uint8_t>(0x140B5377E, 0xEB);
cl_prepare_for_map_restart_hook.create(0x1409B3FE0, cl_prepare_for_map_restart_stub);
cl_initialize_gamestate_hook.create(0x1409B2FA0, cl_initialize_gamestate_stub);
utils::hook::call(0x1409B70A1, cl_initialize_gamestate_stub);
command::add("senduserinfo", []()
{

View File

@ -17,10 +17,8 @@ namespace patches
{
utils::hook::detour com_register_common_dvars_hook;
utils::hook::detour com_game_mode_supports_feature_hook;
utils::hook::detour cg_set_client_dvar_from_server_hook;
utils::hook::detour live_get_map_index_hook;
utils::hook::detour content_do_we_have_content_pack_hook;
utils::hook::detour init_network_dvars_hook;
std::string get_login_username()
{
@ -168,7 +166,7 @@ namespace patches
if (result)
{
std::string index_str = std::to_string(index);
return cg_set_client_dvar_from_server_hook.invoke<void>(client_num, cgame_glob, index_str.data(), value);
return utils::hook::invoke<void>(0x140856D70, client_num, cgame_glob, index_str.data(), value);
}
}
@ -252,7 +250,7 @@ namespace patches
content_do_we_have_content_pack_hook.create(0x140CE8550, content_do_we_have_content_pack_stub);
// make setclientdvar behave like older games
cg_set_client_dvar_from_server_hook.create(0x140856D70, cg_set_client_dvar_from_server_stub);
utils::hook::call(0x14084A136, cg_set_client_dvar_from_server_stub);
utils::hook::call(0x140B0A9BB, get_client_dvar_checksum); // setclientdvar
utils::hook::call(0x140B0ACD7, get_client_dvar_checksum); // setclientdvars
utils::hook::call(0x140B0A984, get_client_dvar); // setclientdvar
@ -266,7 +264,7 @@ namespace patches
utils::hook::call(0x140B7CF11, cbuf_execute_buffer_internal_stub);
// don't register every replicated dvar as a network dvar
init_network_dvars_hook.create(0x140B7A920, init_network_dvars_stub);
utils::hook::jump(0x140B7A920, init_network_dvars_stub);
// some [data validation] anti tamper thing that kills performance
dvars::override::register_int("dvl", 0, 0, 0, game::DVAR_FLAG_READ);

View File

@ -207,22 +207,11 @@ namespace profile_infos
});
}
namespace
{
utils::hook::detour session_unregister_remote_player_hook;
void session_unregister_remote_player_stub(game::SessionData* session, const int slot)
{
session_unregister_remote_player_hook.invoke<void>(session, slot);
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
session_unregister_remote_player_hook.create(0x140C73970, session_unregister_remote_player_stub);
//dvars::override::register_int("playercard_cache_validity_life", 5000, 0, 3600000, 0x0); // 5sec
network::on("profileInfo", [](const game::netadr_s& client_addr, const std::string_view& data)

View File

@ -13,7 +13,6 @@ namespace renderer
namespace
{
utils::hook::detour r_init_draw_method_hook;
utils::hook::detour r_update_front_end_dvar_options_hook;
int get_fullbright_technique()
{
@ -49,7 +48,7 @@ namespace renderer
gfxdrawmethod();
}
return r_update_front_end_dvar_options_hook.invoke<bool>();
return utils::hook::invoke<bool>(0x140E28B60);
}
}
@ -65,8 +64,8 @@ namespace renderer
dvars::r_fullbright = game::Dvar_RegisterInt("r_fullbright", 0, 0, 2, game::DVAR_FLAG_SAVED, "Toggles rendering without lighting");
r_init_draw_method_hook.create(0x140DE9260, &r_init_draw_method_stub);
r_update_front_end_dvar_options_hook.create(0x140E28B60, &r_update_front_end_dvar_options_stub);
r_init_draw_method_hook.create(0x140DE9260, r_init_draw_method_stub);
utils::hook::call(0x140E264B3, r_update_front_end_dvar_options_stub);
}
};
}

View File

@ -86,10 +86,6 @@ namespace scheduler
volatile bool kill = false;
std::thread thread;
task_pipeline pipelines[pipeline::count];
utils::hook::detour r_end_frame_hook;
utils::hook::detour g_run_frame_hook;
utils::hook::detour main_frame_hook;
utils::hook::detour hks_frame_hook;
void execute(const pipeline type)
{
@ -100,12 +96,12 @@ namespace scheduler
void r_end_frame_stub()
{
execute(pipeline::renderer);
r_end_frame_hook.invoke<void>();
utils::hook::invoke<void>(0x140E267B0);
}
void server_frame_stub()
{
g_run_frame_hook.invoke<void>();
utils::hook::invoke<void>(0x140B15E20);
execute(pipeline::server);
}
@ -116,7 +112,7 @@ namespace scheduler
execute(pipeline::main);
});
return main_frame_hook.invoke<void*>();
return utils::hook::invoke<void*>(0x140B8E2D0);
}
void hks_frame_stub()
@ -126,7 +122,7 @@ namespace scheduler
{
execute(pipeline::lui);
}
hks_frame_hook.invoke<bool>();
utils::hook::invoke<bool>(0x140613440);
}
}
@ -196,10 +192,11 @@ namespace scheduler
void post_unpack() override
{
r_end_frame_hook.create(0x140E267B0, scheduler::r_end_frame_stub);
g_run_frame_hook.create(0x140B15E20, scheduler::server_frame_stub);
main_frame_hook.create(0x140B8E2D0, scheduler::main_frame_stub);
hks_frame_hook.create(0x140613440, scheduler::hks_frame_stub);
utils::hook::call(0x14034728C, scheduler::r_end_frame_stub);
utils::hook::call(0x14048A7B9, scheduler::server_frame_stub); // sp call
utils::hook::call(0x140B21941, scheduler::server_frame_stub); // mp call
utils::hook::call(0x140B8E272, scheduler::main_frame_stub);
utils::hook::call(0x1406173C2, scheduler::hks_frame_stub);
}
void pre_destroy() override