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>
|
2023-02-16 13:19:00 -05:00
|
|
|
#include <utils/hook.hpp>
|
|
|
|
|
|
|
|
#include <mmeapi.h>
|
|
|
|
|
2023-02-13 12:47:22 -05:00
|
|
|
namespace client_patches
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2023-02-23 13:37:38 -05:00
|
|
|
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);
|
2023-02-23 13:37:38 -05:00
|
|
|
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);
|
|
|
|
}
|
2023-02-16 13:19:00 -05:00
|
|
|
|
|
|
|
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();
|
2023-02-16 13:19:00 -05:00
|
|
|
|
|
|
|
// Kill microphones for now
|
2023-03-04 10:29:40 -05:00
|
|
|
utils::hook::set(0x15AAE9254_g, mixer_open_stub);
|
2023-02-23 13:37:38 -05:00
|
|
|
|
|
|
|
preload_map_hook.create(0x14135A1E0_g, preload_map_stub);
|
2023-02-13 12:47:22 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-04 10:29:40 -05:00
|
|
|
REGISTER_COMPONENT_WORKING(client_patches::component)
|