Skip to content

Commit

Permalink
fix Hook_OnPhysicsSimulate crash and other crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyano1337 committed Jan 31, 2025
1 parent 551f06d commit f1d1df2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/core/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ bool IFACE::Setup(ISmmAPI* ismm, char* error, size_t maxlen) {
GET_V_IFACE_CURRENT(GetEngineFactory, IFACE::pGameEventSystem, IGameEventSystem, GAMEEVENTSYSTEM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetFileSystemFactory, g_pFullFileSystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION);

return true;
}

bool IFACE::PostSetup() {
IFACE::pGameEventManager = (IGameEventManager2*)GAMEDATA::GetAddress("GetGameEventManager");
IFACE::pGameTraceService = (CGameTraceService*)GAMEDATA::GetAddress("GetGameTraceService");

Expand Down
1 change: 1 addition & 0 deletions src/core/interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ namespace IFACE {
inline CGameTraceService* pGameTraceService = nullptr;

bool Setup(ISmmAPI* ismm, char* error, size_t maxlen);
bool PostSetup();
} // namespace IFACE
5 changes: 3 additions & 2 deletions src/cs2surf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ bool CSurfPlugin::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, b

g_SMAPI->AddListener(this, this);

FORWARD_POST(CCoreForward, OnPluginStart);

return true;
}

void CSurfPlugin::AllPluginsLoaded() {
IFACE::PostSetup();
MEM::SetupHooks();
MOVEMENT::SetupHooks();

g_pMultiAddonManager = (IMultiAddonManager*)g_SMAPI->MetaFactory(MULTIADDONMANAGER_INTERFACE, nullptr, nullptr);

FORWARD_POST(CCoreForward, OnPluginStart);
}

void CSurfPlugin::OnLevelInit(char const* pMapName, char const* pMapEntities, char const* pOldLevel, char const* pLandmarkName, bool loadGame, bool background) {
Expand Down
12 changes: 7 additions & 5 deletions src/movement/mv_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ static void Hook_OnProcessMovement(CCSPlayer_MovementServices* ms, CMoveData* mv
FORWARD_POST(CMovementForward, OnProcessMovementPost, ms, mv);
}

static void Hook_OnPhysicsSimulate(CCSPlayerController* pController) {
static float Hook_OnPhysicsSimulate(CCSPlayerController* pController) {
if (pController->m_bIsHLTV()) {
return;
return 0.0f;
}

if (!pController) {
return MEM::SDKCall<void>(MOVEMENT::TRAMPOLINE::g_fnPhysicsSimulate, pController);
return MEM::SDKCall<float>(MOVEMENT::TRAMPOLINE::g_fnPhysicsSimulate, pController);
}

SurfPlugin()->simulatingPhysics = true;
Expand All @@ -224,14 +224,16 @@ static void Hook_OnPhysicsSimulate(CCSPlayerController* pController) {
}
}
if (block) {
return;
return 0.0f;
}

MEM::SDKCall<void>(MOVEMENT::TRAMPOLINE::g_fnPhysicsSimulate, pController);
float flSimulationTime = MEM::SDKCall<float>(MOVEMENT::TRAMPOLINE::g_fnPhysicsSimulate, pController);

SurfPlugin()->simulatingPhysics = false;

FORWARD_POST(CMovementForward, OnPhysicsSimulatePost, pController);

return flSimulationTime;
}

static float Hook_OnGetMaxSpeed(CCSPlayerPawn* pawn) {
Expand Down

0 comments on commit f1d1df2

Please sign in to comment.