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 e08ab7a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 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
13 changes: 11 additions & 2 deletions source/modules/sourcetv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,20 @@ 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;
}

Msg("HLTV: %s\n", pClient->IsHLTV() ? "true" : "false");
Msg("Server: %p - %p\n", pClient->GetServer(), hltv);

if (pClient->IsHLTV()) // pClient->GetServer()->IsHLTV() crashes... Why.
{
if (Lua::PushHook("HolyLib:OnSourceTVClientDisconnect"))
{
Expand Down

0 comments on commit e08ab7a

Please sign in to comment.