diff --git a/src/client/component/fov.cpp b/src/client/component/fov.cpp new file mode 100644 index 00000000..a6bba9e2 --- /dev/null +++ b/src/client/component/fov.cpp @@ -0,0 +1,73 @@ +#include +#include "loader/component_loader.hpp" + +#include "game/game.hpp" +#include "game/dvars.hpp" + +#include "scheduler.hpp" +#include "dvars.hpp" + +#include + +namespace fov +{ + constexpr float max_fov = 160.0f; + + namespace + { + game::dvar_t* cg_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) + { + return 0.0f; + } + + return cg_view_calc_fov_compensation_hook.invoke(blob); + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + if (game::environment::is_dedi()) + { + return; + } + + cg_fov = game::Dvar_RegisterFloat("cg_fov", 65.0f, 1.0f, 160.f, game::DVAR_FLAG_SAVED, + "The field of view angle in degrees"); + cg_fovScale = game::Dvar_RegisterFloat("cg_fovScale", 1.0f, 0.1f, 2.0f, game::DVAR_FLAG_SAVED, + "Scale applied to the field of view"); + + *reinterpret_cast(0x141FA6DA0) = cg_fov; + dvars::disable::re_register("cg_fov"); + dvars::disable::de_register("cg_fov"); + + *reinterpret_cast(0x141FA6DB0) = cg_fovScale; + dvars::disable::re_register("cg_fovScale"); + dvars::disable::de_register("cg_fovScale"); + + // don't reset our fov + utils::hook::set(0x1408A6160, 0xC3); + + // 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); + + // patch max fov values + utils::hook::inject(0x14087E08B + 4, &max_fov); + utils::hook::inject(0x140898C4B + 4, &max_fov); // mp max + utils::hook::inject(0x140898C55 + 4, &max_fov); // sp max + } + }; +} + +REGISTER_COMPONENT(fov::component) \ No newline at end of file diff --git a/src/client/component/gameplay.cpp b/src/client/component/gameplay.cpp index 16d6fa22..2d1479b8 100644 --- a/src/client/component/gameplay.cpp +++ b/src/client/component/gameplay.cpp @@ -101,7 +101,7 @@ namespace gameplay void cg_calculate_weapon_movement_debug_stub(game::cg_s* glob, float* origin) { - // Retrieve the hook value + // CG_View_CalcFovCompensation float value = utils::hook::invoke(0x140889B60, glob, origin); // Initialize values diff --git a/src/client/component/patches.cpp b/src/client/component/patches.cpp index 5646bbf4..3b60244a 100644 --- a/src/client/component/patches.cpp +++ b/src/client/component/patches.cpp @@ -38,28 +38,14 @@ namespace patches { game::dvar_t* name_dvar; game::dvar_t* com_maxfps; - game::dvar_t* cg_fov; - game::dvar_t* cg_fovScale; name_dvar = game::Dvar_RegisterString("name", get_login_username().data(), game::DVAR_FLAG_SAVED, "Player name."); com_maxfps = game::Dvar_RegisterInt("com_maxfps", 0, 0, 1000, game::DVAR_FLAG_SAVED, "Cap frames per second"); - cg_fov = game::Dvar_RegisterFloat("cg_fov", 65.0f, 1.0f, 160.f, game::DVAR_FLAG_SAVED, - "The field of view angle in degrees"); - cg_fovScale = game::Dvar_RegisterFloat("cg_fovScale", 1.0f, 0.1f, 2.0f, game::DVAR_FLAG_SAVED, - "Scale applied to the field of view"); *reinterpret_cast(0x146005758) = com_maxfps; dvars::disable::re_register("com_maxfps"); dvars::disable::de_register("com_maxfps"); - *reinterpret_cast(0x141FA6DA0) = cg_fov; - dvars::disable::re_register("cg_fov"); - dvars::disable::de_register("cg_fov"); - - *reinterpret_cast(0x141FA6DB0) = cg_fovScale; - dvars::disable::re_register("cg_fovScale"); - dvars::disable::de_register("cg_fovScale"); - return com_register_common_dvars_hook.invoke(); } @@ -266,9 +252,6 @@ namespace patches // Add cheat override to exec utils::hook::call(0x140B7CF11, cbuf_execute_buffer_internal_stub); - // don't reset our fov - utils::hook::set(0x1408A6160, 0xC3); - // don't register every replicated dvar as a network dvar init_network_dvars_hook.create(0x140B7A920, init_network_dvars_stub);