From 06e8f1dc29af88d77e49442d0950da960dcb53e9 Mon Sep 17 00:00:00 2001 From: rei-2 <174158077+rei-2@users.noreply.github.com> Date: Wed, 19 Feb 2025 03:40:41 -0500 Subject: [PATCH] fix crash while in jump while swimming --- .../src/Features/EnginePrediction/EnginePrediction.cpp | 2 ++ .../MovementSimulation/MovementSimulation.cpp | 9 ++++++--- Amalgam/src/SDK/Definitions/Interfaces/IMoveHelper.h | 10 ++++++++++ Amalgam/src/SDK/Vars.h | 4 ++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Amalgam/src/Features/EnginePrediction/EnginePrediction.cpp b/Amalgam/src/Features/EnginePrediction/EnginePrediction.cpp index 20d1f3d4..acb921c1 100644 --- a/Amalgam/src/Features/EnginePrediction/EnginePrediction.cpp +++ b/Amalgam/src/Features/EnginePrediction/EnginePrediction.cpp @@ -43,6 +43,7 @@ void CEnginePrediction::Simulate(CTFPlayer* pLocal, CUserCmd* pCmd) const bool bOldIsFirstPrediction = I::Prediction->m_bFirstTimePredicted; const bool bOldInPrediction = I::Prediction->m_bInPrediction; + I::MoveHelper->SetHost(pLocal); pLocal->SetCurrentCmd(pCmd); *G::RandomSeed() = MD5_PseudoRandom(pCmd->command_number) & std::numeric_limits::max(); @@ -81,6 +82,7 @@ void CEnginePrediction::Simulate(CTFPlayer* pLocal, CUserCmd* pCmd) I::Prediction->FinishMove(pLocal, pCmd, &m_MoveData); } + I::MoveHelper->SetHost(nullptr); pLocal->SetCurrentCmd(nullptr); *G::RandomSeed() = -1; diff --git a/Amalgam/src/Features/Simulation/MovementSimulation/MovementSimulation.cpp b/Amalgam/src/Features/Simulation/MovementSimulation/MovementSimulation.cpp index 297af4db..13bdb92a 100644 --- a/Amalgam/src/Features/Simulation/MovementSimulation/MovementSimulation.cpp +++ b/Amalgam/src/Features/Simulation/MovementSimulation/MovementSimulation.cpp @@ -388,7 +388,9 @@ bool CMovementSimulation::Initialize(CBaseEntity* pEntity, PlayerStorage& player auto pPlayer = pEntity->As(); playerStorageOut.m_pPlayer = pPlayer; - playerStorageOut.m_pPlayer->SetCurrentCmd(&DummyCmd); + + I::MoveHelper->SetHost(pPlayer); + pPlayer->SetCurrentCmd(&DummyCmd); // store player restore data Store(playerStorageOut); @@ -458,7 +460,7 @@ bool CMovementSimulation::Initialize(CBaseEntity* pEntity, PlayerStorage& player // really hope this doesn't work like shit if (useHitchance && bCalculated && !pPlayer->m_vecVelocity().IsZero() && Vars::Aimbot::Projectile::Hitchance.Value) { - const auto& vRecords = mRecords[playerStorageOut.m_pPlayer->entindex()]; + const auto& vRecords = mRecords[pPlayer->entindex()]; const auto iSamples = vRecords.size(); float flCurrentChance = 1.f, flAverageYaw = 0.f; @@ -588,7 +590,7 @@ static int GetYawDifference(std::deque& vRecords, size_t i, float* pYa static int iChanges, iStart; bool bStraight = fabsf(*pYaw) * pRecord1.m_vVelocity.Length2D() * iTicks <= flStraightFuzzyValue; // dumb way to get straight bool - bool bChanged = iLastSign != iCurSign; + bool bChanged = iLastSign && iCurSign && iLastSign != iCurSign; if (!i) { iChanges = 0, iStart = TIME_TO_TICKS(flTime1); @@ -792,6 +794,7 @@ void CMovementSimulation::Restore(PlayerStorage& playerStorage) if (playerStorage.m_bInitFailed || !playerStorage.m_pPlayer) return; + I::MoveHelper->SetHost(nullptr); playerStorage.m_pPlayer->SetCurrentCmd(nullptr); Reset(playerStorage); diff --git a/Amalgam/src/SDK/Definitions/Interfaces/IMoveHelper.h b/Amalgam/src/SDK/Definitions/Interfaces/IMoveHelper.h index 2b37fadf..fb20475b 100644 --- a/Amalgam/src/SDK/Definitions/Interfaces/IMoveHelper.h +++ b/Amalgam/src/SDK/Definitions/Interfaces/IMoveHelper.h @@ -28,6 +28,16 @@ public: virtual IPhysicsSurfaceProps* GetSurfaceProps(void) = 0; virtual bool IsWorldEntity(const CBaseHandle& handle) = 0; + inline CBasePlayer* GetHost() + { + return *reinterpret_cast(uintptr_t(this) + 40); + } + + inline void SetHost(CBasePlayer* pHost) + { + *reinterpret_cast(uintptr_t(this) + 40) = pHost; + } + protected: virtual ~IMoveHelper() {} }; diff --git a/Amalgam/src/SDK/Vars.h b/Amalgam/src/SDK/Vars.h index 0c130987..77ace768 100644 --- a/Amalgam/src/SDK/Vars.h +++ b/Amalgam/src/SDK/Vars.h @@ -167,7 +167,7 @@ namespace Vars CVar(GroundMaxChanges, 0, DEBUGVAR) CVar(GroundMaxChangeTime, 0, DEBUGVAR) CVar(GroundNewWeight, 100.f, DEBUGVAR) - CVar(GroundOldWeight, 0.f, DEBUGVAR) + CVar(GroundOldWeight, 100.f, DEBUGVAR) CVar(AirSamples, 33, DEBUGVAR) CVar(AirStraightFuzzyValue, 10.f, DEBUGVAR) @@ -178,7 +178,7 @@ namespace Vars CVar(AirMaxChanges, 1, DEBUGVAR) CVar(AirMaxChangeTime, 10, DEBUGVAR) CVar(AirNewWeight, 100.f, DEBUGVAR) - CVar(AirOldWeight, 0.f, DEBUGVAR) + CVar(AirOldWeight, 100.f, DEBUGVAR) CVar(VelocityAverageCount, 5, DEBUGVAR) CVar(VerticalShift, 5.f, DEBUGVAR)