h1-mod/src/client/component/virtuallobby.cpp

65 lines
1.3 KiB
C++
Raw Normal View History

2022-02-27 00:31:12 +02:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include <utils/hook.hpp>
namespace virtuallobby
{
namespace
{
2022-05-22 19:11:42 +02:00
game::dvar_t* virtual_lobby_fovscale;
2022-02-27 00:31:12 +02:00
2022-11-01 00:09:02 -05:00
void get_get_fovscale_stub(utils::hook::assembler& a)
2022-02-27 00:31:12 +02:00
{
2022-11-01 00:09:02 -05:00
const auto ret = a.newLabel();
const auto original = a.newLabel();
2022-02-27 00:31:12 +02:00
2022-11-01 00:09:02 -05:00
a.pushad64();
a.mov(rax, qword_ptr(0x2999CE8_b)); // virtualLobbyInFiringRange
a.cmp(byte_ptr(rax, 0x10), 1);
a.je(original);
a.call_aligned(game::VirtualLobby_Loaded);
a.cmp(al, 0);
a.je(original);
2022-02-27 00:31:12 +02:00
2022-11-01 00:09:02 -05:00
// virtuallobby
a.popad64();
a.mov(rax, ptr(reinterpret_cast<int64_t>(&virtual_lobby_fovscale)));
a.jmp(ret);
2022-02-27 00:31:12 +02:00
2022-11-01 00:09:02 -05:00
// original
a.bind(original);
a.popad64();
a.mov(rax, qword_ptr(0x14C4EC8_b));
a.jmp(ret);
2022-02-27 00:31:12 +02:00
2022-11-01 00:09:02 -05:00
a.bind(ret);
a.mov(rdi, rax);
a.mov(ecx, 8);
a.jmp(0x104545_b);
2022-05-22 19:11:42 +02:00
}
2022-02-27 00:31:12 +02:00
}
class component final : public component_interface
{
public:
void post_unpack() override
{
if (!game::environment::is_mp())
{
return;
}
2022-05-22 19:11:42 +02:00
virtual_lobby_fovscale = dvars::register_float_hashed("virtualLobby_fovScale", 0.7f, 0.0f, 2.0f,
2022-03-13 00:56:15 +01:00
game::DVAR_FLAG_SAVED, "Field of view scaled for the virtual lobby");
2022-02-27 00:31:12 +02:00
2022-11-01 00:09:02 -05:00
utils::hook::jump(0x104539_b, utils::hook::assemble(get_get_fovscale_stub), true);
2022-02-27 00:31:12 +02:00
}
};
}
2022-05-22 19:11:42 +02:00
REGISTER_COMPONENT(virtuallobby::component)