ValveSoftware / halflife

Half-Life 1 engine based games
Other
3.74k stars 631 forks source link

[GoldSource] PEntityOfEntIndex may not return the last player #2272

Open 2010kohtep opened 5 years ago

2010kohtep commented 5 years ago

PEntityOfEntIndex function has a condition that prevents the last player from being returned. This is because the player index starts at 1, since the map is already located at index 0 and therefore we must perform a check in the range 1 .. sv::maxplayers.

image

The solution is to replace the >= check with > to allow the last player to be checked.

mikela-valve commented 5 years ago

Fixed, will be in next beta update.

mikela-valve commented 5 years ago

Fixed in beta 'Exe build: 11:12:36 May 21 2019 (8244)'.

mikela-valve commented 5 years ago

Closing as fixed.

mikela-valve commented 5 years ago

Unfortunately it looks like CZ:DS and likely some other games rely on this bug being present and it's a bit difficult to test for this without playing through every single scene of every single game. I'm going to revert this in PEntityOfEntIndex to avoid causing crashes in places using the returned entity unchecked and revisit actually fixing it later.

For mods using this that want the fixed behaviour, I did add a parallel function to the engine interface, PEntityOfEntIndexAllEntities. This function properly checks the [1, svs.maxclients] range and can be used while PEntityOfEntIndex has this issue.

mikela-valve commented 5 years ago

This has been updated in beta 8279.

CS-PRO1 commented 5 years ago

@mikela-valve Here's all I found in CZ:DS Beta 8265: Recoil: Crashes the game after helicopter takedown scene (after CS:CZ logo) Fastline: Crashes the game after the tram explosion (after CS:CZ logo) Run!: Crashes the game upon loading the mission's first map. Truth in Chaos & Rise Hard: Crashes the game after the end of conversation with gaurds (when the next map loading screen hits) Other missions are playing good without crashes. Still we need someone to confirm if this happens in other Single player titles (HL, OF, BS etc..) Since I don't own any of these unfortunately :\

tschumann commented 5 years ago

@mikela-valve so right after int (*pfnCheckParm)( const char *pchCmdLineToken, char **ppnext ); is edict_t* (*PEntityOfEntIndexAllEntities)(int iEntIndex); in enginefuncs_t? And this will be live once the next beta is promoted to release?

mikela-valve commented 5 years ago

Thanks @CS-PRO1.

@tschumann That's correct (though it will be pfnPEntityOfEntIndexAllEntities). I'll update eiface.h when the update is released.