Skip to content

Commit

Permalink
Fix pers array access
Browse files Browse the repository at this point in the history
  • Loading branch information
alicealys committed Jan 25, 2022
1 parent 1fd9349 commit a17d6ed
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
30 changes: 28 additions & 2 deletions src/game/scripting/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@

namespace scripting
{
namespace
{
// using this class (specifically adding/removing ref)
// with `player.pers` causes a crash in Scr_EvalArrayRef,
// this seems to be the only case in which this happens
// and i don't know why yet so ill just use this shitty
// work around for now. pers is persistent so it doesnt
// need to be referenced anyways

bool is_script_pers(unsigned int id)
{
const auto sv_maxclients = game::Dvar_FindVar("sv_maxclients");

for (auto i = 0; i < sv_maxclients->current.integer; i++)
{
const auto client = &game::svs_clients[i];
if (id == client->scriptId)
{
return true;
}
}

return false;
}
}

array_value::array_value(unsigned int parent_id, unsigned int id)
: id_(id)
, parent_id_(parent_id)
Expand Down Expand Up @@ -93,15 +119,15 @@ namespace scripting

void array::add() const
{
if (this->id_)
if (this->id_ && !is_script_pers(this->id_))
{
game::AddRefToObject(this->id_);
}
}

void array::release() const
{
if (this->id_)
if (this->id_ && !is_script_pers(this->id_))
{
game::RemoveRefToObject(this->id_);
}
Expand Down
8 changes: 7 additions & 1 deletion src/game/structs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ namespace game
{
char __pad0[0x28];
netadr_s remote;
char __pad1[0x78658];
char __pad1[0x41C76];
unsigned __int16 scriptId; // 269490
int bIsTestClient; // 269492
int serverId; // 269496
char __pad2[0x369DC];
};

static_assert(sizeof(client_t) == 493208);
}

0 comments on commit a17d6ed

Please sign in to comment.