2021-09-06 18:40:37 -04:00
|
|
|
#include <std_include.hpp>
|
2021-04-23 14:57:21 -04:00
|
|
|
#include "loader/component_loader.hpp"
|
|
|
|
|
|
|
|
#include "game/game.hpp"
|
2021-04-26 16:34:43 -04:00
|
|
|
#include "game/dvars.hpp"
|
2021-04-23 14:57:21 -04:00
|
|
|
|
|
|
|
#include <utils/hook.hpp>
|
2022-01-06 17:13:23 -05:00
|
|
|
#include <utils/string.hpp>
|
2021-04-23 14:57:21 -04:00
|
|
|
|
|
|
|
namespace patches
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2022-01-06 17:13:23 -05:00
|
|
|
utils::hook::detour gscr_set_save_dvar_hook;
|
|
|
|
utils::hook::detour dvar_register_float_hook;
|
|
|
|
|
2021-09-06 18:40:37 -04:00
|
|
|
void* sub_46148()
|
|
|
|
{
|
2021-12-27 22:25:14 -05:00
|
|
|
static uint64_t off_11C52460 = 0xAD0C58_b;
|
2021-09-06 18:40:37 -04:00
|
|
|
return &off_11C52460;
|
|
|
|
}
|
2021-12-27 22:25:14 -05:00
|
|
|
|
2021-12-28 11:14:47 -05:00
|
|
|
DECLSPEC_NORETURN void quit_stub()
|
2021-12-27 22:25:14 -05:00
|
|
|
{
|
|
|
|
component_loader::pre_destroy();
|
|
|
|
exit(0);
|
|
|
|
}
|
2022-01-06 17:13:23 -05:00
|
|
|
|
|
|
|
void gscr_set_save_dvar_stub()
|
|
|
|
{
|
|
|
|
const auto string = utils::string::to_lower(utils::hook::invoke<const char*>(0x5C7C20_b, 0));
|
|
|
|
if (string == "cg_fov" || string == "cg_fovscale")
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gscr_set_save_dvar_hook.invoke<void>();
|
|
|
|
}
|
|
|
|
|
|
|
|
game::dvar_t* dvar_register_float_stub(int hash, const char* dvarName, float value, float min, float max, unsigned int flags)
|
|
|
|
{
|
|
|
|
static const auto cg_fov_hash = game::generateHashValue("cg_fov");
|
|
|
|
static const auto cg_fov_scale_hash = game::generateHashValue("cg_fovscale");
|
|
|
|
|
|
|
|
if (hash == cg_fov_hash || hash == cg_fov_scale_hash)
|
|
|
|
{
|
2022-01-09 19:03:16 -05:00
|
|
|
flags = game::DvarFlags::DVAR_FLAG_SAVED;
|
2022-01-06 17:13:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return dvar_register_float_hook.invoke<game::dvar_t*>(hash, dvarName, value, min, max, flags);
|
|
|
|
}
|
2021-04-23 14:57:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class component final : public component_interface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void post_unpack() override
|
|
|
|
{
|
2021-12-28 11:14:47 -05:00
|
|
|
// Fix startup crashes
|
2021-12-03 14:47:16 -05:00
|
|
|
utils::hook::set(0x633080_b, 0xC301B0);
|
|
|
|
utils::hook::set(0x272F70_b, 0xC301B0);
|
|
|
|
utils::hook::jump(0x46148_b, sub_46148, true);
|
2021-09-06 18:40:37 -04:00
|
|
|
|
2021-12-27 22:25:14 -05:00
|
|
|
utils::hook::jump(0x64EF10_b, quit_stub, true);
|
|
|
|
|
2021-04-23 14:57:21 -04:00
|
|
|
// Unlock fps in main menu
|
2021-12-03 14:47:16 -05:00
|
|
|
utils::hook::set<BYTE>(0x3D8E1B_b, 0xEB);
|
2021-04-23 14:57:21 -04:00
|
|
|
|
|
|
|
// Disable battle net popup
|
2021-12-03 14:47:16 -05:00
|
|
|
utils::hook::nop(0x5F4496_b, 5);
|
2022-01-06 17:13:23 -05:00
|
|
|
|
2022-01-06 17:14:01 -05:00
|
|
|
// Allow kbam input when gamepad is enabled
|
|
|
|
utils::hook::nop(0x3D2F8E_b, 2);
|
|
|
|
utils::hook::nop(0x3D0C9C_b, 6);
|
|
|
|
|
2022-01-06 17:13:23 -05:00
|
|
|
// Prevent game from overriding cg_fov and cg_fovscale values
|
|
|
|
gscr_set_save_dvar_hook.create(0x504C60_b, &gscr_set_save_dvar_stub);
|
|
|
|
// Make cg_fov and cg_fovscale saved dvars
|
|
|
|
dvar_register_float_hook.create(game::Dvar_RegisterFloat.get(), dvar_register_float_stub);
|
2021-04-23 14:57:21 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_COMPONENT(patches::component)
|