t7x/src/client/component/client_patches.cpp

90 lines
1.9 KiB
C++
Raw Normal View History

2023-02-13 12:47:22 -05:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
2023-02-16 13:38:13 -05:00
#include <game/game.hpp>
#include <utils/hook.hpp>
#include <mmeapi.h>
2023-02-13 12:47:22 -05:00
namespace client_patches
{
namespace
{
utils::hook::detour preload_map_hook;
void stop_zombies_intro_if_needed()
{
if (game::Com_SessionMode_GetMode() != game::MODE_ZOMBIES)
{
return;
}
scheduler::once([]
{
scheduler::schedule([]
{
if (!game::Sys_IsDatabaseReady())
{
return scheduler::cond_continue;
}
game::Cinematic_StopPlayback(0, true);
return scheduler::cond_end;
}, scheduler::main);
}, scheduler::main, 15s);
}
void preload_map_stub(int localClientNum, const char* mapname, const char* gametype)
{
2023-02-25 12:46:00 -05:00
game::Com_GametypeSettings_SetGametype(gametype, false, false);
stop_zombies_intro_if_needed();
preload_map_hook.invoke(localClientNum, mapname, gametype);
}
2023-02-13 12:47:22 -05:00
void reduce_process_affinity()
{
2023-02-17 02:36:58 -05:00
const DWORD_PTR affinity = (1ULL << (std::min(std::thread::hardware_concurrency(), 4U))) - 1;
2023-02-13 12:47:22 -05:00
SetProcessAffinityMask(GetCurrentProcess(), affinity);
}
void reset_process_affinity()
{
DWORD_PTR affinity_proc, affinity_sys;
GetProcessAffinityMask(GetCurrentProcess(), &affinity_proc, &affinity_sys);
SetProcessAffinityMask(GetCurrentProcess(), affinity_sys);
}
void fix_amd_cpu_stuttering()
{
scheduler::once([]
{
reduce_process_affinity();
scheduler::once(reset_process_affinity, scheduler::pipeline::main, 1s);
}, scheduler::pipeline::main);
}
MMRESULT mixer_open_stub()
{
return MMSYSERR_NODRIVER;
}
2023-02-13 12:47:22 -05:00
}
class component final : public client_component
{
public:
void post_unpack() override
{
fix_amd_cpu_stuttering();
// Kill microphones for now
2023-02-16 13:38:13 -05:00
utils::hook::set(0x15AAEB254_g, mixer_open_stub);
preload_map_hook.create(0x14135A1E0_g, preload_map_stub);
2023-02-13 12:47:22 -05:00
}
};
}
REGISTER_COMPONENT(client_patches::component)