Skip to content

Commit

Permalink
sourcetv: try to fix a crash
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelIT7 committed Nov 19, 2024
1 parent a859cdb commit 32a9b04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,10 @@ Returns `IPhysicsEnvironment [NULL]` if invalid.
Else it returns `IPhysicsEnvironment`.

#### bool IPhysicsEnvironment:TransferObject(IPhysicsObject obj, IPhysicsEnvironment newEnvironment)
Transfers the physics object from this environment to the new environment.
Transfers the physics object from this environment to the new environment. #

> [!WARNING]
> You shouldn't transfer players or vehicles.
#### IPhysicsEnvironment:SetGravity(Vector newGravity)
Sets the new gravity in `source_unit/s^2`
Expand Down
15 changes: 9 additions & 6 deletions source/modules/sourcetv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,21 @@ static void hook_CHLTVClient_Deconstructor(CHLTVClient* pClient)
}

static Detouring::Hook detour_CSteam3Server_NotifyClientDisconnect;
static void hook_CSteam3Server_NotifyClientDisconnect(void* pServer, IClient* pClient)
static void hook_CSteam3Server_NotifyClientDisconnect(void* pServer, CBaseClient* pClient)
{
VPROF_BUDGET("HolyLib - CSteam3Server::NotifyClientDisconnect", VPROF_BUDGETGROUP_HOLYLIB);

if (pClient->GetServer()->IsHLTV())
if (!hltv)
{
detour_CSteam3Server_NotifyClientDisconnect.GetTrampoline<Symbols::CSteam3Server_NotifyClientDisconnect>()(pServer, pClient);
return;
}

if (((CHLTVServer*)pClient->GetServer()) == hltv) // pClient->GetServer()->IsHLTV() crashes... Why.
{
if (Lua::PushHook("HolyLib:OnSourceTVClientDisconnect"))
{
if (g_pSourceTVLibModule.InDebug())
Push_CHLTVClient((CHLTVClient*)pClient); // In debug we try to push the HLTVClient.
else
g_Lua->PushNumber(pClient->GetPlayerSlot());
Push_CHLTVClient((CHLTVClient*)pClient);
g_Lua->CallFunctionProtected(2, 0, true);
}

Expand Down

0 comments on commit 32a9b04

Please sign in to comment.