t7x/src/client/component/dedicated_patches.cpp

95 lines
2.1 KiB
C++
Raw Normal View History

2023-01-09 17:03:43 -05:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
2023-02-23 03:55:36 -05:00
#include "scheduler.hpp"
2023-01-09 17:03:43 -05:00
#include <utils/hook.hpp>
2023-02-21 12:00:59 -05:00
namespace dedicated_patches
2023-01-09 17:03:43 -05:00
{
namespace
{
utils::hook::detour spawn_server_hook;
2023-01-09 17:03:43 -05:00
void scr_are_textures_loaded_stub([[maybe_unused]] game::scriptInstance_t inst)
{
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1);
}
2023-02-23 03:55:36 -05:00
2023-02-25 13:26:40 -05:00
game::eNetworkModes get_online_mode_stub()
2023-02-23 03:55:36 -05:00
{
return game::MODE_NETWORK_ONLINE;
}
2023-02-25 13:26:40 -05:00
bool is_online_stub()
{
return true;
}
bool is_mod_loaded_stub()
{
return false;
}
void patch_is_mod_loaded_checks()
{
const std::vector<uintptr_t> is_mod_loaded_addresses =
{
2023-03-05 15:41:29 -05:00
{ 0x14019CFC4_g },
2023-02-25 13:26:40 -05:00
{ 0x14024D4A0_g },
{ 0x14024D669_g },
{ 0x14024D939_g },
{ 0x14024DC64_g },
{ 0x14024E13A_g },
{ 0x14024E5A3_g },
{ 0x14024FFB9_g },
{ 0x140251E9E_g },
{ 0x140253680_g },
{ 0x140257BF6_g },
2023-03-05 15:41:29 -05:00
{ 0x1402D296D_g },
{ 0x1402D58E9_g },
2023-02-25 13:26:40 -05:00
{ 0x140468374_g },
2023-03-05 15:41:29 -05:00
{ 0x14046B796_g },
{ 0x14048003D_g },
2023-02-25 13:26:40 -05:00
};
for (const auto& address : is_mod_loaded_addresses)
{
utils::hook::call(address, is_mod_loaded_stub);
}
}
void spawn_server_stub(int controllerIndex, const char* server, game::MapPreload preload, bool savegame)
{
game::Com_SessionMode_SetNetworkMode(game::MODE_NETWORK_ONLINE);
game::Com_SessionMode_SetGameMode(game::MODE_GAME_MATCHMAKING_PLAYLIST);
spawn_server_hook.invoke(controllerIndex, server, preload, savegame);
}
2023-01-09 17:03:43 -05:00
}
struct component final : server_component
2023-01-09 17:03:43 -05:00
{
void post_unpack() override
{
// Fix infinite loop
utils::hook::jump(0x1402E86B0_g, scr_are_textures_loaded_stub);
2023-02-23 03:55:36 -05:00
2023-02-25 13:26:40 -05:00
// Online classes
utils::hook::jump(0x1405003E0_g, get_online_mode_stub);
utils::hook::jump(0x1405003B0_g, get_online_mode_stub);
// Progression / Ranked
utils::hook::jump(0x140500A50_g, is_online_stub);
utils::hook::jump(0x140500980_g, is_online_stub);
utils::hook::jump(0x1402565D0_g, is_online_stub);
patch_is_mod_loaded_checks();
2023-02-23 03:55:36 -05:00
spawn_server_hook.create(game::SV_SpawnServer, spawn_server_stub);
2023-01-09 17:03:43 -05:00
}
};
}
2023-02-21 12:00:59 -05:00
REGISTER_COMPONENT(dedicated_patches::component)