[Script]: Use the correct function to get ent (#825)

This commit is contained in:
Edo 2023-03-10 20:55:22 +00:00 committed by GitHub
parent be259519d5
commit e02e833ee5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 35 deletions

View File

@ -209,7 +209,7 @@ namespace Components
GSC::Script::AddMethod("BotStop", [](Game::scr_entref_t entref) // Usage: <bot> BotStop();
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref);
if (Game::SV_IsTestClient(ent->s.number) == 0)
{
@ -224,7 +224,7 @@ namespace Components
GSC::Script::AddMethod("BotWeapon", [](Game::scr_entref_t entref) // Usage: <bot> BotWeapon(<str>);
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref);
if (Game::SV_IsTestClient(ent->s.number) == 0)
{
@ -247,7 +247,7 @@ namespace Components
GSC::Script::AddMethod("BotAction", [](Game::scr_entref_t entref) // Usage: <bot> BotAction(<str action>);
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref);
if (Game::SV_IsTestClient(ent->s.number) == 0)
{
@ -288,7 +288,7 @@ namespace Components
GSC::Script::AddMethod("BotMovement", [](Game::scr_entref_t entref) // Usage: <bot> BotMovement(<int>, <int>);
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref);
if (Game::SV_IsTestClient(ent->s.number) == 0)
{

View File

@ -314,6 +314,7 @@ namespace Components
{
if (IsSettingArchiveDvarsDisabled())
{
Logger::Debug("Not allowing server to set '{}'", dvarName);
return;
}

View File

@ -220,6 +220,26 @@ namespace Components::GSC
return &Game::svs_clients[ent->s.number];
}
Game::gentity_s* Script::Scr_GetPlayerEntity(Game::scr_entref_t entref)
{
if (entref.classnum)
{
Game::Scr_ObjectError("not an entity");
return nullptr;
}
assert(entref.entnum < Game::MAX_GENTITIES);
auto* ent = &Game::g_entities[entref.entnum];
if (!ent->client)
{
Game::Scr_ObjectError(Utils::String::VA("entity %i is not a player", entref.entnum));
return nullptr;
}
return ent;
}
Script::Script()
{
// Skip check in GScr_CheckAllowedToSetPersistentData to prevent log spam in RuntimeError.

View File

@ -15,27 +15,8 @@ namespace Components::GSC
static void AddMethMultiple(Game::BuiltinMethod func, bool type, scriptNames);
static Game::client_t* GetClient(const Game::gentity_t* gentity);
// Probably a macro 'originally' but this is fine
static Game::gentity_s* Scr_GetPlayerEntity(Game::scr_entref_t entref)
{
if (entref.classnum)
{
Game::Scr_ObjectError("not an entity");
return nullptr;
}
assert(entref.entnum < Game::MAX_GENTITIES);
auto* ent = &Game::g_entities[entref.entnum];
if (!ent->client)
{
Game::Scr_ObjectError(Utils::String::VA("entity %i is not a player", entref.entnum));
return nullptr;
}
return ent;
}
static Game::gentity_s* Scr_GetPlayerEntity(Game::scr_entref_t entref);
private:
struct ScriptFunction

View File

@ -276,7 +276,7 @@ namespace Components::GSC
// ScriptExtension methods
Script::AddMethod("GetIp", [](const Game::scr_entref_t entref) // gsc: self GetIp()
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = Script::Scr_GetPlayerEntity(entref);
const auto* client = Script::GetClient(ent);
std::string ip = Game::NET_AdrToString(client->header.netchan.remoteAddress);
@ -300,7 +300,7 @@ namespace Components::GSC
Script::AddMethod("GetPing", [](const Game::scr_entref_t entref) // gsc: self GetPing()
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = Script::Scr_GetPlayerEntity(entref);
const auto* client = Script::GetClient(ent);
Game::Scr_AddInt(client->ping);
@ -312,7 +312,7 @@ namespace Components::GSC
ping = std::clamp(ping, 0, 999);
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = Script::Scr_GetPlayerEntity(entref);
auto* client = Script::GetClient(ent);
client->ping = ping;

View File

@ -49,7 +49,7 @@ namespace Components::GSC
{
Script::AddMethod("SetName", [](Game::scr_entref_t entref) // gsc: self SetName(<string>)
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = Script::Scr_GetPlayerEntity(entref);
const auto* name = Game::Scr_GetString(0);
if (!name)
@ -65,7 +65,7 @@ namespace Components::GSC
Script::AddMethod("ResetName", [](Game::scr_entref_t entref) // gsc: self ResetName()
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = Script::Scr_GetPlayerEntity(entref);
Logger::Debug("Resetting name of {}", ent->s.number);
UserInfoOverrides[ent->s.number].erase("name");
@ -74,7 +74,7 @@ namespace Components::GSC
Script::AddMethod("SetClanTag", [](Game::scr_entref_t entref) // gsc: self SetClanTag(<string>)
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = Script::Scr_GetPlayerEntity(entref);
const auto* clanName = Game::Scr_GetString(0);
if (!clanName)
@ -90,7 +90,7 @@ namespace Components::GSC
Script::AddMethod("ResetClanTag", [](Game::scr_entref_t entref) // gsc: self ResetClanTag()
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = Script::Scr_GetPlayerEntity(entref);
Logger::Debug("Resetting clanName of {}", ent->s.number);
UserInfoOverrides[ent->s.number].erase("clanAbbrev");

View File

@ -81,7 +81,7 @@ namespace Components
{
GSC::Script::AddMethod("GetStat", [](const Game::scr_entref_t entref)
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref);
const auto index = Game::Scr_GetInt(0);
if (index < 0 || index > 3499)
@ -99,7 +99,7 @@ namespace Components
GSC::Script::AddMethod("SetStat", [](const Game::scr_entref_t entref)
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref);
const auto iNumParms = Game::Scr_GetNumParam();
if (iNumParms != 2)

View File

@ -582,14 +582,14 @@ namespace Components
{
GSC::Script::AddMethod("DisableWeaponPickup", [](Game::scr_entref_t entref)
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref);
ent->client->ps.weapCommon.weapFlags |= Game::PWF_DISABLE_WEAPON_PICKUP;
});
GSC::Script::AddMethod("EnableWeaponPickup", [](Game::scr_entref_t entref)
{
const auto* ent = Game::GetPlayerEntity(entref);
const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref);
ent->client->ps.weapCommon.weapFlags &= ~Game::PWF_DISABLE_WEAPON_PICKUP;
});