Merge pull request #1053 from diamante0018/develop
This commit is contained in:
commit
d1865584df
@ -12,6 +12,9 @@ namespace Components
|
|||||||
Utils::Concurrency::Container<Events::Callback> Events::DvarInitTasks_;
|
Utils::Concurrency::Container<Events::Callback> Events::DvarInitTasks_;
|
||||||
Utils::Concurrency::Container<Events::Callback> Events::NetworkInitTasks_;
|
Utils::Concurrency::Container<Events::Callback> Events::NetworkInitTasks_;
|
||||||
|
|
||||||
|
Events::ClientCmdCallback Events::ClientCmdButtonsTasks_;
|
||||||
|
Events::ClientCmdCallback Events::ClientKeyMoveTasks_;
|
||||||
|
|
||||||
void Events::OnClientDisconnect(const std::function<void(int clientNum)>& callback)
|
void Events::OnClientDisconnect(const std::function<void(int clientNum)>& callback)
|
||||||
{
|
{
|
||||||
ClientDisconnectTasks_.access([&callback](ClientCallback& tasks)
|
ClientDisconnectTasks_.access([&callback](ClientCallback& tasks)
|
||||||
@ -52,6 +55,16 @@ namespace Components
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Events::OnClientCmdButtons(const std::function<void(Game::usercmd_s*)>& callback)
|
||||||
|
{
|
||||||
|
ClientCmdButtonsTasks_.emplace_back(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Events::OnClientKeyMove(const std::function<void(Game::usercmd_s*)>& callback)
|
||||||
|
{
|
||||||
|
ClientKeyMoveTasks_.emplace_back(callback);
|
||||||
|
}
|
||||||
|
|
||||||
void Events::OnSVInit(const std::function<void()>& callback)
|
void Events::OnSVInit(const std::function<void()>& callback)
|
||||||
{
|
{
|
||||||
ServerInitTasks_.access([&callback](Callback& tasks)
|
ServerInitTasks_.access([&callback](Callback& tasks)
|
||||||
@ -147,6 +160,60 @@ namespace Components
|
|||||||
Utils::Hook::Call<void()>(0x404CA0)(); // CL_InitOnceForAllClients
|
Utils::Hook::Call<void()>(0x404CA0)(); // CL_InitOnceForAllClients
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Events::CL_CmdButtons(Game::usercmd_s* cmd)
|
||||||
|
{
|
||||||
|
for (const auto& func : ClientCmdButtonsTasks_)
|
||||||
|
{
|
||||||
|
func(cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void __declspec(naked) Events::CL_CmdButtons_Stub()
|
||||||
|
{
|
||||||
|
static const DWORD CL_CmdButtons_t = 0x5A6510;
|
||||||
|
|
||||||
|
__asm
|
||||||
|
{
|
||||||
|
call CL_CmdButtons_t
|
||||||
|
|
||||||
|
pushad
|
||||||
|
|
||||||
|
push esi
|
||||||
|
call CL_CmdButtons
|
||||||
|
add esp, 0x4
|
||||||
|
|
||||||
|
popad
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Events::CL_KeyMove(Game::usercmd_s* cmd)
|
||||||
|
{
|
||||||
|
for (const auto& func : ClientKeyMoveTasks_)
|
||||||
|
{
|
||||||
|
func(cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void __declspec(naked) Events::CL_KeyMove_Stub()
|
||||||
|
{
|
||||||
|
static const DWORD CL_KeyMove_t = 0x5A5F40;
|
||||||
|
|
||||||
|
__asm
|
||||||
|
{
|
||||||
|
call CL_KeyMove_t
|
||||||
|
|
||||||
|
pushad
|
||||||
|
|
||||||
|
push esi
|
||||||
|
call CL_KeyMove
|
||||||
|
add esp, 0x4
|
||||||
|
|
||||||
|
popad
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Events::SV_Init_Hk()
|
void Events::SV_Init_Hk()
|
||||||
{
|
{
|
||||||
ServerInitTasks_.access([](Callback& tasks)
|
ServerInitTasks_.access([](Callback& tasks)
|
||||||
@ -213,6 +280,10 @@ namespace Components
|
|||||||
|
|
||||||
Utils::Hook(0x60BE5B, CL_InitOnceForAllClients_HK, HOOK_CALL).install()->quick(); // Com_Init_Try_Block_Function
|
Utils::Hook(0x60BE5B, CL_InitOnceForAllClients_HK, HOOK_CALL).install()->quick(); // Com_Init_Try_Block_Function
|
||||||
|
|
||||||
|
Utils::Hook(0x5A6D84, CL_CmdButtons_Stub, HOOK_CALL).install()->quick();
|
||||||
|
|
||||||
|
Utils::Hook(0x5A6D8B, CL_KeyMove_Stub, HOOK_CALL).install()->quick();
|
||||||
|
|
||||||
Utils::Hook(0x60BB3A, Com_InitDvars_Hk, HOOK_CALL).install()->quick(); // Com_Init_Try_Block_Function
|
Utils::Hook(0x60BB3A, Com_InitDvars_Hk, HOOK_CALL).install()->quick(); // Com_Init_Try_Block_Function
|
||||||
|
|
||||||
Utils::Hook(0x4D3665, SV_Init_Hk, HOOK_CALL).install()->quick(); // SV_Init
|
Utils::Hook(0x4D3665, SV_Init_Hk, HOOK_CALL).install()->quick(); // SV_Init
|
||||||
|
@ -8,6 +8,7 @@ namespace Components
|
|||||||
using Callback = std::vector<std::function<void()>>;
|
using Callback = std::vector<std::function<void()>>;
|
||||||
using ClientConnectCallback = std::vector<std::function<void(Game::client_s* cl)>>;
|
using ClientConnectCallback = std::vector<std::function<void(Game::client_s* cl)>>;
|
||||||
using ClientCallback = std::vector<std::function<void(int clientNum)>>;
|
using ClientCallback = std::vector<std::function<void(int clientNum)>>;
|
||||||
|
using ClientCmdCallback = std::vector<std::function<void(Game::usercmd_s* cmd)>>;
|
||||||
|
|
||||||
Events();
|
Events();
|
||||||
|
|
||||||
@ -24,12 +25,17 @@ namespace Components
|
|||||||
|
|
||||||
static void OnClientInit(const std::function<void()>& callback);
|
static void OnClientInit(const std::function<void()>& callback);
|
||||||
|
|
||||||
|
static void OnClientCmdButtons(const std::function<void(Game::usercmd_s*)>& callback);
|
||||||
|
|
||||||
|
static void OnClientKeyMove(const std::function<void(Game::usercmd_s*)>& callback);
|
||||||
|
|
||||||
// Client & Server (triggered once)
|
// Client & Server (triggered once)
|
||||||
static void OnSVInit(const std::function<void()>& callback);
|
static void OnSVInit(const std::function<void()>& callback);
|
||||||
|
|
||||||
// Client & Server (triggered once)
|
// Client & Server (triggered once)
|
||||||
static void OnDvarInit(const std::function<void()>& callback);
|
static void OnDvarInit(const std::function<void()>& callback);
|
||||||
|
|
||||||
|
// Client & Server (triggered once)
|
||||||
static void OnNetworkInit(const std::function<void()>& callback);
|
static void OnNetworkInit(const std::function<void()>& callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -42,11 +48,21 @@ namespace Components
|
|||||||
static Utils::Concurrency::Container<Callback> DvarInitTasks_;
|
static Utils::Concurrency::Container<Callback> DvarInitTasks_;
|
||||||
static Utils::Concurrency::Container<Callback> NetworkInitTasks_;
|
static Utils::Concurrency::Container<Callback> NetworkInitTasks_;
|
||||||
|
|
||||||
|
// For speed this one does not use concurrency container. Be careful
|
||||||
|
static ClientCmdCallback ClientCmdButtonsTasks_;
|
||||||
|
static ClientCmdCallback ClientKeyMoveTasks_;
|
||||||
|
|
||||||
static void ClientDisconnect_Hk(int clientNum);
|
static void ClientDisconnect_Hk(int clientNum);
|
||||||
static void SV_UserinfoChanged_Hk(Game::client_s* cl);
|
static void SV_UserinfoChanged_Hk(Game::client_s* cl);
|
||||||
static void SteamDisconnect_Hk();
|
static void SteamDisconnect_Hk();
|
||||||
static void Scr_ShutdownSystem_Hk(unsigned char sys);
|
static void Scr_ShutdownSystem_Hk(unsigned char sys);
|
||||||
static void CL_InitOnceForAllClients_HK();
|
static void CL_InitOnceForAllClients_HK();
|
||||||
|
|
||||||
|
static void CL_CmdButtons(Game::usercmd_s* cmd);
|
||||||
|
static void CL_CmdButtons_Stub();
|
||||||
|
static void CL_KeyMove(Game::usercmd_s* cmd);
|
||||||
|
static void CL_KeyMove_Stub();
|
||||||
|
|
||||||
static void SV_Init_Hk();
|
static void SV_Init_Hk();
|
||||||
static void Com_InitDvars_Hk();
|
static void Com_InitDvars_Hk();
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include <STDInclude.hpp>
|
#include <STDInclude.hpp>
|
||||||
|
|
||||||
|
#include "Events.hpp"
|
||||||
#include "Lean.hpp"
|
#include "Lean.hpp"
|
||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
@ -28,7 +30,7 @@ namespace Components
|
|||||||
Game::IN_KeyDown(&in_leanright);
|
Game::IN_KeyDown(&in_leanright);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lean::SetLeanFlags(Game::usercmd_s* cmd)
|
void Lean::ApplyLeanFlags(Game::usercmd_s* cmd)
|
||||||
{
|
{
|
||||||
if ((in_leanleft.active || in_leanleft.wasPressed) && BGLean.get<bool>())
|
if ((in_leanleft.active || in_leanleft.wasPressed) && BGLean.get<bool>())
|
||||||
{
|
{
|
||||||
@ -44,23 +46,6 @@ namespace Components
|
|||||||
in_leanright.wasPressed = false;
|
in_leanright.wasPressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __declspec(naked) Lean::CL_CmdButtons_Stub()
|
|
||||||
{
|
|
||||||
__asm
|
|
||||||
{
|
|
||||||
// CL_CmdButtons
|
|
||||||
mov ecx, 5A6510h
|
|
||||||
call ecx
|
|
||||||
|
|
||||||
pushad
|
|
||||||
push esi
|
|
||||||
call SetLeanFlags
|
|
||||||
pop esi
|
|
||||||
popad
|
|
||||||
retn
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Lean::PM_UpdateLean_Stub(Game::playerState_s* ps, float msec, Game::usercmd_s* cmd, void(*capsuleTrace)(Game::trace_t*, const float*, const float*, const Game::Bounds*, int, int))
|
void Lean::PM_UpdateLean_Stub(Game::playerState_s* ps, float msec, Game::usercmd_s* cmd, void(*capsuleTrace)(Game::trace_t*, const float*, const float*, const Game::Bounds*, int, int))
|
||||||
{
|
{
|
||||||
if (BGLean.get<bool>())
|
if (BGLean.get<bool>())
|
||||||
@ -77,12 +62,11 @@ namespace Components
|
|||||||
Command::AddRaw("+leanright", IN_LeanRight_Down, true);
|
Command::AddRaw("+leanright", IN_LeanRight_Down, true);
|
||||||
Command::AddRaw("-leanright", IN_LeanRight_Up, true);
|
Command::AddRaw("-leanright", IN_LeanRight_Up, true);
|
||||||
|
|
||||||
Utils::Hook(0x5A6D84, CL_CmdButtons_Stub, HOOK_CALL).install()->quick();
|
Events::OnClientCmdButtons(ApplyLeanFlags);
|
||||||
|
|
||||||
Utils::Hook(0x4A0C72, PM_UpdateLean_Stub, HOOK_CALL).install()->quick();
|
Utils::Hook(0x4A0C72, PM_UpdateLean_Stub, HOOK_CALL).install()->quick();
|
||||||
Utils::Hook(0x4A0D72, PM_UpdateLean_Stub, HOOK_CALL).install()->quick();
|
Utils::Hook(0x4A0D72, PM_UpdateLean_Stub, HOOK_CALL).install()->quick();
|
||||||
|
|
||||||
BGLean = Dvar::Register<bool>("bg_lean", true,
|
BGLean = Dvar::Register<bool>("bg_lean", true, Game::DVAR_CODINFO, "Enable CoD4 leaning");
|
||||||
Game::DVAR_CODINFO, "Enable CoD4 leaning");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,7 @@ namespace Components
|
|||||||
static void IN_LeanRight_Up();
|
static void IN_LeanRight_Up();
|
||||||
static void IN_LeanRight_Down();
|
static void IN_LeanRight_Down();
|
||||||
|
|
||||||
static void CL_CmdButtons_Stub();
|
static void ApplyLeanFlags(Game::usercmd_s* cmd);
|
||||||
static void SetLeanFlags(Game::usercmd_s* cmd);
|
|
||||||
|
|
||||||
static void PM_UpdateLean_Stub(Game::playerState_s* ps, float msec, Game::usercmd_s* cmd, void(*capsuleTrace)(Game::trace_t*, const float*, const float*, const Game::Bounds*, int, int));
|
static void PM_UpdateLean_Stub(Game::playerState_s* ps, float msec, Game::usercmd_s* cmd, void(*capsuleTrace)(Game::trace_t*, const float*, const float*, const Game::Bounds*, int, int));
|
||||||
};
|
};
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
Dvar::Var PlayerMovement::BGRocketJump;
|
const Game::dvar_t* PlayerMovement::BGRocketJump;
|
||||||
Dvar::Var PlayerMovement::BGRocketJumpScale;
|
const Game::dvar_t* PlayerMovement::BGRocketJumpScale;
|
||||||
Dvar::Var PlayerMovement::BGPlayerEjection;
|
const Game::dvar_t* PlayerMovement::BGPlayerEjection;
|
||||||
Dvar::Var PlayerMovement::BGPlayerCollision;
|
const Game::dvar_t* PlayerMovement::BGPlayerCollision;
|
||||||
Dvar::Var PlayerMovement::BGClimbAnything;
|
const Game::dvar_t* PlayerMovement::BGClimbAnything;
|
||||||
const Game::dvar_t* PlayerMovement::CGNoclipScaler;
|
const Game::dvar_t* PlayerMovement::CGNoclipScaler;
|
||||||
const Game::dvar_t* PlayerMovement::CGUfoScaler;
|
const Game::dvar_t* PlayerMovement::CGUfoScaler;
|
||||||
const Game::dvar_t* PlayerMovement::PlayerSpectateSpeedScale;
|
const Game::dvar_t* PlayerMovement::PlayerSpectateSpeedScale;
|
||||||
@ -26,7 +26,7 @@ namespace Components
|
|||||||
{
|
{
|
||||||
Game::PM_playerTrace(pm, results, start, end, bounds, passEntityNum, contentMask);
|
Game::PM_playerTrace(pm, results, start, end, bounds, passEntityNum, contentMask);
|
||||||
|
|
||||||
if (results && BGClimbAnything.get<bool>())
|
if (results && BGClimbAnything->current.enabled)
|
||||||
{
|
{
|
||||||
results[0].surfaceFlags |= SURF_LADDER;
|
results[0].surfaceFlags |= SURF_LADDER;
|
||||||
}
|
}
|
||||||
@ -187,10 +187,9 @@ namespace Components
|
|||||||
{
|
{
|
||||||
auto* result = Game::Weapon_RocketLauncher_Fire(ent, weaponIndex, spread, wp, gunVel, lockParms, magicBullet);
|
auto* result = Game::Weapon_RocketLauncher_Fire(ent, weaponIndex, spread, wp, gunVel, lockParms, magicBullet);
|
||||||
|
|
||||||
if (ent->client != nullptr && BGRocketJump.get<bool>() &&
|
if (ent->client && BGRocketJump->current.enabled && wp->weapDef->inventoryType != Game::WEAPINVENTORY_EXCLUSIVE)
|
||||||
wp->weapDef->inventoryType != Game::WEAPINVENTORY_EXCLUSIVE)
|
|
||||||
{
|
{
|
||||||
const auto scale = BGRocketJumpScale.get<float>();
|
const auto scale = BGRocketJumpScale->current.value;
|
||||||
ent->client->ps.velocity[0] += (0.0f - wp->forward[0]) * scale;
|
ent->client->ps.velocity[0] += (0.0f - wp->forward[0]) * scale;
|
||||||
ent->client->ps.velocity[1] += (0.0f - wp->forward[1]) * scale;
|
ent->client->ps.velocity[1] += (0.0f - wp->forward[1]) * scale;
|
||||||
ent->client->ps.velocity[2] += (0.0f - wp->forward[2]) * scale;
|
ent->client->ps.velocity[2] += (0.0f - wp->forward[2]) * scale;
|
||||||
@ -201,7 +200,7 @@ namespace Components
|
|||||||
|
|
||||||
int PlayerMovement::StuckInClient_Hk(Game::gentity_s* self)
|
int PlayerMovement::StuckInClient_Hk(Game::gentity_s* self)
|
||||||
{
|
{
|
||||||
if (BGPlayerEjection.get<bool>())
|
if (BGPlayerEjection->current.enabled)
|
||||||
{
|
{
|
||||||
return Utils::Hook::Call<int(Game::gentity_s*)>(0x402D30)(self); // StuckInClient
|
return Utils::Hook::Call<int(Game::gentity_s*)>(0x402D30)(self); // StuckInClient
|
||||||
}
|
}
|
||||||
@ -212,7 +211,7 @@ namespace Components
|
|||||||
void PlayerMovement::CM_TransformedCapsuleTrace_Hk(Game::trace_t* results, const float* start, const float* end,
|
void PlayerMovement::CM_TransformedCapsuleTrace_Hk(Game::trace_t* results, const float* start, const float* end,
|
||||||
const Game::Bounds* bounds, const Game::Bounds* capsule, int contents, const float* origin, const float* angles)
|
const Game::Bounds* bounds, const Game::Bounds* capsule, int contents, const float* origin, const float* angles)
|
||||||
{
|
{
|
||||||
if (BGPlayerCollision.get<bool>())
|
if (BGPlayerCollision->current.enabled)
|
||||||
{
|
{
|
||||||
Utils::Hook::Call<void(Game::trace_t*, const float*, const float*,
|
Utils::Hook::Call<void(Game::trace_t*, const float*, const float*,
|
||||||
const Game::Bounds*, const Game::Bounds*, int, const float*, const float*)>
|
const Game::Bounds*, const Game::Bounds*, int, const float*, const float*)>
|
||||||
@ -299,20 +298,20 @@ namespace Components
|
|||||||
BGBunnyHopAuto = Game::Dvar_RegisterBool("bg_bunnyHopAuto",
|
BGBunnyHopAuto = Game::Dvar_RegisterBool("bg_bunnyHopAuto",
|
||||||
false, Game::DVAR_CODINFO, "Constantly jump when holding space");
|
false, Game::DVAR_CODINFO, "Constantly jump when holding space");
|
||||||
|
|
||||||
BGRocketJump = Dvar::Register<bool>("bg_rocketJump",
|
BGRocketJump = Game::Dvar_RegisterBool("bg_rocketJump",
|
||||||
false, Game::DVAR_CODINFO, "Enable CoD4 rocket jumps");
|
false, Game::DVAR_CODINFO, "Enable CoD4 rocket jumps");
|
||||||
|
|
||||||
BGRocketJumpScale = Dvar::Register<float>("bg_rocketJumpScale",
|
BGRocketJumpScale = Game::Dvar_RegisterFloat("bg_rocketJumpScale",
|
||||||
64.0f, 1.0f, std::numeric_limits<float>::max(), Game::DVAR_CODINFO,
|
64.0f, 1.0f, std::numeric_limits<float>::max(), Game::DVAR_CODINFO,
|
||||||
"The scale applied to the pushback force of a rocket");
|
"The scale applied to the pushback force of a rocket");
|
||||||
|
|
||||||
BGPlayerEjection = Dvar::Register<bool>("bg_playerEjection",
|
BGPlayerEjection = Game::Dvar_RegisterBool("bg_playerEjection",
|
||||||
true, Game::DVAR_CODINFO, "Push intersecting players away from each other");
|
true, Game::DVAR_CODINFO, "Push intersecting players away from each other");
|
||||||
|
|
||||||
BGPlayerCollision = Dvar::Register<bool>("bg_playerCollision",
|
BGPlayerCollision = Game::Dvar_RegisterBool("bg_playerCollision",
|
||||||
true, Game::DVAR_CODINFO, "Push intersecting players away from each other");
|
true, Game::DVAR_CODINFO, "Push intersecting players away from each other");
|
||||||
|
|
||||||
BGClimbAnything = Dvar::Register<bool>("bg_climbAnything",
|
BGClimbAnything = Game::Dvar_RegisterBool("bg_climbAnything",
|
||||||
false, Game::DVAR_CODINFO, "Treat any surface as a ladder");
|
false, Game::DVAR_CODINFO, "Treat any surface as a ladder");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,12 +12,11 @@ namespace Components
|
|||||||
|
|
||||||
static constexpr auto SURF_LADDER = 0x8;
|
static constexpr auto SURF_LADDER = 0x8;
|
||||||
|
|
||||||
static Dvar::Var BGRocketJump;
|
static const Game::dvar_t* BGRocketJump;
|
||||||
static Dvar::Var BGRocketJumpScale;
|
static const Game::dvar_t* BGRocketJumpScale;
|
||||||
static Dvar::Var BGPlayerEjection;
|
static const Game::dvar_t* BGPlayerEjection;
|
||||||
static Dvar::Var BGPlayerCollision;
|
static const Game::dvar_t* BGPlayerCollision;
|
||||||
static Dvar::Var BGClimbAnything;
|
static const Game::dvar_t* BGClimbAnything;
|
||||||
// Can't use Var class inside assembly stubs
|
|
||||||
static const Game::dvar_t* CGNoclipScaler;
|
static const Game::dvar_t* CGNoclipScaler;
|
||||||
static const Game::dvar_t* CGUfoScaler;
|
static const Game::dvar_t* CGUfoScaler;
|
||||||
static const Game::dvar_t* PlayerSpectateSpeedScale;
|
static const Game::dvar_t* PlayerSpectateSpeedScale;
|
||||||
|
Loading…
Reference in New Issue
Block a user