iw5-mod/src/module/patches.cpp

78 lines
1.9 KiB
C++
Raw Normal View History

2019-09-24 04:30:08 -04:00
#include <std_include.hpp>
2022-03-23 09:48:13 -04:00
#include <loader/module_loader.hpp>
#include <utils/hook.hpp>
2019-09-24 04:30:08 -04:00
#include "game/game.hpp"
class patches final : public module
{
public:
void post_load() override
{
if (!game::is_dedi()) this->patch_clients();
if (game::is_sp()) this->patch_sp();
else if (game::is_mp()) this->patch_mp();
else if (game::is_dedi()) this->patch_dedi();
utils::hook(game::native::_longjmp, long_jump_stub, HOOK_JUMP).install()->quick();
}
private:
void patch_clients() const
{
// Remove improper quit check
utils::hook::nop(SELECT_VALUE(0x53444A, 0x5CCDC0, 0), 9);
// Ignore sdm files
utils::hook::nop(SELECT_VALUE(0x4438BA, 0x6371EA, 0), 2);
}
void patch_sp() const
{
// SP doesn't initialize WSA
WSADATA wsa_data;
WSAStartup(MAKEWORD(2, 2), &wsa_data);
// Disable remote storage
utils::hook::set<BYTE>(0x663B5A, 0xEB);
utils::hook::set<BYTE>(0x663C54, 0xEB);
}
void patch_mp() const
{
2022-03-23 09:49:42 -04:00
// Note: on SP the max value is already 1000
2022-03-22 17:30:44 -04:00
utils::hook(0x55411F, &dvar_register_com_max_fps, HOOK_CALL).install()->quick();
2019-09-24 04:30:08 -04:00
}
void patch_dedi() const
{
2022-03-22 07:44:37 -04:00
// Skip call to queryserverinfo handler in SV_ConnectionlessPacket
2022-03-22 06:51:37 -04:00
utils::hook::nop(0x4FE051, 5);
2022-04-07 16:39:38 -04:00
// Disable callvote/vote exploit
utils::hook::nop(0x47EB9D, 5);
utils::hook::nop(0x47EBC9, 5);
2019-09-24 04:30:08 -04:00
}
static __declspec(noreturn) void long_jump_stub(jmp_buf buf, const int value) noexcept(false)
{
#ifdef DEBUG
{
printf("Unwinding the stack...\n");
}
#endif
longjmp(buf, value);
}
2022-03-22 17:30:44 -04:00
static const game::native::dvar_t* dvar_register_com_max_fps(const char* dvarName, int value,
2022-03-23 09:49:42 -04:00
int min, int /*max*/, unsigned __int16 /*flags*/, const char* description)
2022-03-22 17:30:44 -04:00
{
2022-03-23 09:49:42 -04:00
return game::native::Dvar_RegisterInt(dvarName, value, min, 1000,
game::native::dvar_flags::DVAR_ARCHIVE, description);
2022-03-22 17:30:44 -04:00
}
2019-09-24 04:30:08 -04:00
};
REGISTER_MODULE(patches)