Skip to content

Commit

Permalink
fix rpg laser client crash
Browse files Browse the repository at this point in the history
also added a safety check for attachments
  • Loading branch information
wootguy committed Nov 7, 2024
1 parent a2520a6 commit 0839324
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
12 changes: 9 additions & 3 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,15 +1283,21 @@ int AddToFullPack( struct entity_state_s *state, int e, edict_t *ent, edict_t *h

}

if (e >= plr->GetMaxClientEdicts()) {
int maxClientEdicts = plr->GetMaxClientEdicts();
if (e >= maxClientEdicts) {
//ALERT(at_console, "Can't send edict %d '%s' (index too high)\n", e, STRING(ent->v.classname));
g_numEdictOverflows[player]++;
plr->SendLegacyClientWarning();
return 0;
}
if (ENTINDEX(ent->v.aiment) >= maxClientEdicts) {
//ALERT(at_console, "Can't send attachment %d '%s' (index too high)\n", ENTINDEX(ent->v.aiment), STRING(ent->v.aiment->v.classname));
g_numEdictOverflows[player]++;
plr->SendLegacyClientWarning();
return 0;
}

CBaseEntity* pEntity = static_cast<CBaseEntity*>(GET_PRIVATE(ent));
if (pEntity && pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE)
if (baseent->Classify() != CLASS_NONE && baseent->Classify() != CLASS_MACHINE)
state->eflags |= EFLAG_FLESH_SOUND;
else
state->eflags &= ~EFLAG_FLESH_SOUND;
Expand Down
4 changes: 0 additions & 4 deletions dlls/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,4 @@ bool ModelIsValid(entvars_t* edict, studiohdr_t* header) {
}

return true;
}

const char* cstr(string_t s) {
return STRING(s);
}
5 changes: 1 addition & 4 deletions dlls/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,4 @@ EXPORT void writeNetworkMessageHistory(std::string reason);
EXPORT void clearNetworkMessageHistory();

// for debugging
bool ModelIsValid(entvars_t* edict, studiohdr_t* header);

// same as the STRING macro but defined as a function for easy calling in the debugger
const char* cstr(string_t s);
bool ModelIsValid(entvars_t* edict, studiohdr_t* header);
3 changes: 3 additions & 0 deletions dlls/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ struct RGBA {
#define STRING(offset) ((const char *)(gpGlobals->pStringBase + (unsigned int)(offset)))
#define MAKE_STRING(str) ((uint64)(str) - (uint64)(STRING(0)))

// same as the STRING macro but defined as a function for easy calling in the debugger
inline const char* cstr(string_t s) { return STRING(s); }

inline edict_t *FIND_ENTITY_BY_CLASSNAME(edict_t *entStart, const char *pszName)
{
return FIND_ENTITY_BY_STRING(entStart, "classname", pszName);
Expand Down
35 changes: 23 additions & 12 deletions dlls/weapon/CRpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,17 +639,6 @@ void CRpg::UpdateSpot( void )
}
CLaserSpot* m_pSpot = (CLaserSpot*)m_hSpot.GetEntity();

if (!m_hBeam) {
CBeam* beam = CBeam::BeamCreate("sprites/laserbeam.spr", 8);
beam->EntsInit(m_pPlayer->entindex(), m_pSpot->entindex());
beam->SetStartAttachment(1);
beam->SetColor(255, 32, 32);
beam->SetNoise(0);
beam->SetBrightness(48);
beam->SetScrollRate(64);
m_hBeam = beam;
}

UTIL_MakeVectors( m_pPlayer->pev->v_angle );
Vector vecSrc = m_pPlayer->GetGunPosition( );;
Vector vecAiming = gpGlobals->v_forward;
Expand All @@ -659,15 +648,37 @@ void CRpg::UpdateSpot( void )

UTIL_SetOrigin( m_pSpot->pev, tr.vecEndPos );

if (!m_hBeam) {
CBeam* beam = CBeam::BeamCreate("sprites/laserbeam.spr", 8);
beam->PointEntInit(tr.vecEndPos, m_pPlayer->entindex());
beam->SetEndAttachment(1);
beam->SetColor(255, 32, 32);
beam->SetNoise(0);
beam->SetBrightness(48);
beam->SetScrollRate(64);
m_hBeam = beam;
}

CBeam* beam = (CBeam*)m_hBeam.GetEntity();
if (beam) {
beam->pev->effects = m_pSpot->pev->effects;
if (UTIL_PointContents(tr.vecEndPos) == CONTENTS_SKY) {

const bool fix_crash = true;

if (fix_crash || UTIL_PointContents(tr.vecEndPos) == CONTENTS_SKY) {
// dot exits the PVS in this case
beam->PointEntInit(tr.vecEndPos, m_pPlayer->entindex());
beam->SetEndAttachment(1);
}
else {
// DON'T DO THIS. Somehow, it is causing client crashes.
// In a replay, I see a laser spot switches from index 922 to 934
// and then every client loses connection at the same time.
// Can't reproduce and I've only seen it happen twice in months.
// The player index never changes so that should be safe.
// Removing the dot randomly doesn't crash. Messing with attachments
// here doesn't crash. idk what happened.

beam->EntsInit(m_pPlayer->entindex(), m_pSpot->entindex());
beam->SetStartAttachment(1);
}
Expand Down

0 comments on commit 0839324

Please sign in to comment.