Add Module

This commit is contained in:
FutureRave 2021-11-07 11:16:56 +00:00
parent 1112eba7fa
commit 1b1a53cef6
3 changed files with 172 additions and 1 deletions

View File

@ -299,7 +299,7 @@ namespace Components
// Uncheat ui_debugMode // Uncheat ui_debugMode
Utils::Hook::Xor<BYTE>(0x6312DE, Game::dvar_flag::DVAR_FLAG_CHEAT); Utils::Hook::Xor<BYTE>(0x6312DE, Game::dvar_flag::DVAR_FLAG_CHEAT);
// Remove unknown flag (to prevent unknown behaviour) // Remove unknown flag (prevent unknown behaviour)
Utils::Hook::Xor<BYTE>(0x448B42, Game::dvar_flag::DVAR_FLAG_UNKNOWN80); Utils::Hook::Xor<BYTE>(0x448B42, Game::dvar_flag::DVAR_FLAG_UNKNOWN80);
// Hook dvar 'name' registration // Hook dvar 'name' registration

View File

@ -0,0 +1,151 @@
#include "STDInclude.hpp"
namespace Components
{
Dvar::Var Movement::PlayerDuckedSpeedScale;
Dvar::Var Movement::PlayerLastStandCrawlSpeedScale;
Dvar::Var Movement::PlayerProneSpeedScale;
int Movement::PMGetEffectiveStance(Game::playerState_s* ps)
{
auto heightTarget = ps->viewHeightTarget;
if (heightTarget == 0x16)
return Game::PM_EFF_STANCE_LASTSTANDCRAWL;
if (heightTarget == 0x28)
return Game::PM_EFF_STANCE_DUCKED;
if (heightTarget == 0xB)
return Game::PM_EFF_STANCE_PRONE;
return Game::PM_EFF_STANCE_DEFAULT;
}
float Movement::PMCmdScaleForStance(Game::pmove_s* move)
{
auto* playerState = move->ps;
float scale;
if (playerState->viewHeightLerpTime != 0 && playerState->viewHeightLerpTarget == 0xB)
{
scale = move->cmd.serverTime - playerState->viewHeightLerpTime / 400.0f;
if (0.0f <= scale)
{
auto flags = 0;
if (scale < 1.0f)
{
flags |= 1 << 8;
}
if (scale == 1.0f)
{
flags |= 1 << 14;
}
if (flags == 0)
{
scale = 1.0f;
return scale * 0.15f + (1.0f - scale) * 0.65f;
}
if (scale != 0.0f)
{
return scale * 0.15f + (1.0f - scale) * 0.65f;
}
}
}
if ((playerState->viewHeightLerpTime != 0 && playerState->viewHeightLerpTarget == 0x28) &&
playerState->viewHeightLerpDown == 0)
{
scale = 400.0f / move->cmd.serverTime - playerState->viewHeightLerpTime;
if (0.0f <= scale)
{
auto flags = 0;
if (scale < 1.0f)
{
flags |= 1 << 8;
}
if (scale == 1.0f)
{
flags |= 1 << 14;
}
if (flags == 0)
{
scale = 1.0f;
}
else if (scale != 0.0f)
{
return scale * 0.65f + (1.0f - scale) * 0.15f;
}
}
}
scale = 1.0f;
auto stance = Movement::PMGetEffectiveStance(playerState);
if (stance == Game::PM_EFF_STANCE_PRONE)
{
scale = Movement::PlayerProneSpeedScale.get<float>();
}
else if (stance == Game::PM_EFF_STANCE_DUCKED)
{
scale = Movement::PlayerDuckedSpeedScale.get<float>();
}
else if (stance == Game::PM_EFF_STANCE_LASTSTANDCRAWL)
{
scale = Movement::PlayerLastStandCrawlSpeedScale.get<float>();
}
return scale;
}
__declspec(naked) void Movement::PMCmdScaleForStanceStub()
{
__asm
{
pushad
push edx
call Movement::PMCmdScaleForStance
add esp, 4
popad
ret
}
}
Movement::Movement()
{
Dvar::OnInit([]
{
Movement::PlayerDuckedSpeedScale = Dvar::Register<float>("player_duckedSpeedScale",
0.65f, 0.0f, 5.0f, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED,
"The scale applied to the player speed when ducking");
Movement::PlayerLastStandCrawlSpeedScale = Dvar::Register<float>("player_lastStandCrawlSpeedScale",
0.2f, 0.0f, 5.0f, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED,
"The scale applied to the player speed when crawling in last stand");
Movement::PlayerProneSpeedScale = Dvar::Register<float>("player_proneSpeedScale",
0.15f, 0.0f, 5.0f, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED,
"The scale applied to the player speed when crawling");
});
Utils::Hook(0x572F34, Movement::PMCmdScaleForStanceStub, HOOK_CALL).install()->quick();
Utils::Hook(0x57395F, Movement::PMCmdScaleForStanceStub, HOOK_CALL).install()->quick();
}
Movement::~Movement()
{
}
}

View File

@ -0,0 +1,20 @@
#pragma once
namespace Components
{
class Movement : public Component
{
public:
Movement();
~Movement();
private:
static Dvar::Var PlayerDuckedSpeedScale;
static Dvar::Var PlayerLastStandCrawlSpeedScale;
static Dvar::Var PlayerProneSpeedScale;
static int PMGetEffectiveStance(Game::playerState_s* ps);
static float PMCmdScaleForStance(Game::pmove_s* move);
static void PMCmdScaleForStanceStub();
};
}