2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2022-12-26 07:07:24 -05:00
|
|
|
#include "Elevators.hpp"
|
2021-11-29 07:26:53 -05:00
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
2021-12-26 11:25:13 -05:00
|
|
|
Dvar::Var Elevators::BG_Elevators;
|
2021-11-29 07:26:53 -05:00
|
|
|
|
2021-12-22 10:25:58 -05:00
|
|
|
int Elevators::PM_CorrectAllSolid(Game::pmove_s* pm, Game::pml_t* pml, Game::trace_t* trace)
|
2021-11-29 12:16:18 -05:00
|
|
|
{
|
2021-12-22 10:25:58 -05:00
|
|
|
assert(pm != nullptr);
|
|
|
|
assert(pm->ps != nullptr);
|
|
|
|
|
|
|
|
Game::vec3_t point;
|
|
|
|
auto* ps = pm->ps;
|
|
|
|
|
|
|
|
auto i = 0;
|
2021-12-26 11:25:13 -05:00
|
|
|
const auto elevatorSetting = Elevators::BG_Elevators.get<int>();
|
|
|
|
while (true)
|
2021-11-29 12:16:18 -05:00
|
|
|
{
|
2022-05-05 05:20:10 -04:00
|
|
|
point[0] = ps->origin[0] + (*Game::CorrectSolidDeltas)[i][0];
|
|
|
|
point[1] = ps->origin[1] + (*Game::CorrectSolidDeltas)[i][1];
|
|
|
|
point[2] = ps->origin[2] + (*Game::CorrectSolidDeltas)[i][2];
|
2021-12-22 10:25:58 -05:00
|
|
|
|
|
|
|
Game::PM_playerTrace(pm, trace, point, point, &pm->bounds, ps->clientNum, pm->tracemask);
|
|
|
|
|
|
|
|
// If the player wishes to glitch without effort they can do so
|
2021-12-26 11:25:13 -05:00
|
|
|
if (!trace->startsolid || elevatorSetting == Elevators::EASY)
|
2021-12-22 10:25:58 -05:00
|
|
|
{
|
|
|
|
ps->origin[0] = point[0];
|
|
|
|
ps->origin[1] = point[1];
|
|
|
|
ps->origin[2] = point[2];
|
|
|
|
point[2] = (ps->origin[2] - 1.0f) - 0.25f;
|
|
|
|
|
|
|
|
Game::PM_playerTrace(pm, trace, ps->origin, point, &pm->bounds, ps->clientNum, pm->tracemask);
|
|
|
|
|
|
|
|
// If elevators are disabled we need to check that startsolid is false before proceeding
|
|
|
|
// like later versions of the game do
|
2021-12-26 11:25:13 -05:00
|
|
|
if (!trace->startsolid || elevatorSetting >= Elevators::ENABLED)
|
2021-12-22 10:25:58 -05:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-05 05:20:10 -04:00
|
|
|
++i;
|
|
|
|
if (i >= 26) // CorrectSolidDeltas count
|
2021-12-22 10:25:58 -05:00
|
|
|
{
|
|
|
|
ps->groundEntityNum = Game::ENTITYNUM_NONE;
|
|
|
|
pml->groundPlane = 0;
|
|
|
|
pml->almostGroundPlane = 0;
|
|
|
|
pml->walking = 0;
|
|
|
|
Game::Jump_ClearState(ps);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 11:33:48 -05:00
|
|
|
pml->groundTrace = *trace;
|
|
|
|
|
|
|
|
const auto fraction = trace->fraction;
|
|
|
|
ps->origin[0] += fraction * (point[0] - ps->origin[0]);
|
|
|
|
ps->origin[1] += fraction * (point[1] - ps->origin[1]);
|
|
|
|
ps->origin[2] += fraction * (point[2] - ps->origin[2]);
|
|
|
|
|
2021-12-22 10:25:58 -05:00
|
|
|
return 1;
|
|
|
|
}
|
2021-11-29 12:16:18 -05:00
|
|
|
|
2022-05-05 05:20:10 -04:00
|
|
|
void Elevators::PM_Trace_Hk(Game::pmove_s* pm, Game::trace_t* results, const float* start,
|
|
|
|
const float* end, const Game::Bounds* bounds, int passEntityNum, int contentMask)
|
2021-12-22 10:25:58 -05:00
|
|
|
{
|
2022-05-05 05:20:10 -04:00
|
|
|
Game::PM_Trace(pm, results, start, end, bounds, passEntityNum, contentMask);
|
2021-11-29 12:16:18 -05:00
|
|
|
|
2021-12-22 10:40:30 -05:00
|
|
|
// Allow the player to stand even when there is no headroom
|
2021-12-26 11:25:13 -05:00
|
|
|
if (Elevators::BG_Elevators.get<int>() == Elevators::EASY)
|
2021-12-22 10:25:58 -05:00
|
|
|
{
|
2022-05-05 05:20:10 -04:00
|
|
|
results->allsolid = false;
|
2021-12-22 10:25:58 -05:00
|
|
|
}
|
|
|
|
}
|
2021-11-29 12:16:18 -05:00
|
|
|
|
2021-12-22 10:25:58 -05:00
|
|
|
__declspec(naked) void Elevators::PM_CorrectAllSolidStub()
|
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
push eax
|
|
|
|
pushad
|
2021-11-29 12:16:18 -05:00
|
|
|
|
2021-12-22 10:25:58 -05:00
|
|
|
push [esp + 0x8 + 0x24]
|
|
|
|
push [esp + 0x8 + 0x24]
|
|
|
|
push eax
|
|
|
|
call Elevators::PM_CorrectAllSolid
|
|
|
|
add esp, 0xC
|
2021-11-29 12:16:18 -05:00
|
|
|
|
2021-12-22 10:25:58 -05:00
|
|
|
mov [esp + 0x20], eax
|
|
|
|
popad
|
|
|
|
pop eax
|
2021-11-29 12:16:18 -05:00
|
|
|
|
2021-12-22 10:25:58 -05:00
|
|
|
ret
|
2021-11-29 12:16:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-29 07:26:53 -05:00
|
|
|
Elevators::Elevators()
|
|
|
|
{
|
2022-05-27 06:19:28 -04:00
|
|
|
Scheduler::Once([]
|
2021-11-29 07:26:53 -05:00
|
|
|
{
|
2021-12-22 10:25:58 -05:00
|
|
|
static const char* values[] =
|
|
|
|
{
|
2021-12-26 11:25:13 -05:00
|
|
|
"off",
|
|
|
|
"normal",
|
|
|
|
"easy",
|
2021-12-22 10:25:58 -05:00
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
2021-12-26 11:25:13 -05:00
|
|
|
Elevators::BG_Elevators = Game::Dvar_RegisterEnum("bg_elevators", values,
|
2022-03-08 07:20:28 -05:00
|
|
|
Elevators::ENABLED, Game::DVAR_CODINFO, "Elevators glitch settings");
|
2022-05-27 06:19:28 -04:00
|
|
|
}, Scheduler::Pipeline::MAIN);
|
2021-11-29 07:26:53 -05:00
|
|
|
|
2022-05-05 05:20:10 -04:00
|
|
|
Utils::Hook(0x57369E, Elevators::PM_CorrectAllSolidStub, HOOK_CALL).install()->quick(); // PM_GroundTrace
|
2021-12-22 10:40:30 -05:00
|
|
|
|
2021-12-28 04:07:39 -05:00
|
|
|
// Place hooks in PM_CheckDuck. If the elevators dvar is set to easy the
|
|
|
|
// flags for duck/prone will always be removed from the player state
|
2021-12-26 11:25:13 -05:00
|
|
|
Utils::Hook(0x570EC5, Elevators::PM_Trace_Hk, HOOK_CALL).install()->quick();
|
2021-12-28 04:07:39 -05:00
|
|
|
Utils::Hook(0x570E0B, Elevators::PM_Trace_Hk, HOOK_CALL).install()->quick();
|
2022-01-07 06:33:53 -05:00
|
|
|
Utils::Hook(0x570D70, Elevators::PM_Trace_Hk, HOOK_CALL).install()->quick();
|
2021-11-29 07:26:53 -05:00
|
|
|
}
|
|
|
|
}
|