Use getentity and getplayerentity game functions
This commit is contained in:
parent
a7de8bdbce
commit
20d0337880
@ -127,8 +127,8 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
const auto* gentity = Script::GetEntity(entref);
|
||||
auto* client = Script::GetClient(gentity);
|
||||
const auto* ent = Game::GetPlayerEntity(entref);
|
||||
auto* client = Script::GetClient(ent);
|
||||
|
||||
if (!client->bIsTestClient)
|
||||
{
|
||||
@ -141,7 +141,7 @@ namespace Components
|
||||
|
||||
Script::AddFunction("IsTestClient", [](Game::scr_entref_t entref) // Usage: <bot> IsTestClient();
|
||||
{
|
||||
const auto* gentity = Script::GetEntity(entref);
|
||||
const auto* gentity = Game::GetPlayerEntity(entref);
|
||||
const auto* client = Script::GetClient(gentity);
|
||||
|
||||
Game::Scr_AddBool(client->bIsTestClient == 1);
|
||||
@ -149,8 +149,8 @@ namespace Components
|
||||
|
||||
Script::AddFunction("BotStop", [](Game::scr_entref_t entref) // Usage: <bot> BotStop();
|
||||
{
|
||||
const auto* gentity = Script::GetEntity(entref);
|
||||
const auto* client = Script::GetClient(gentity);
|
||||
const auto* ent = Game::GetPlayerEntity(entref);
|
||||
const auto* client = Script::GetClient(ent);
|
||||
|
||||
if (!client->bIsTestClient)
|
||||
{
|
||||
@ -167,8 +167,8 @@ namespace Components
|
||||
{
|
||||
const auto* weapon = Game::Scr_GetString(0);
|
||||
|
||||
const auto* gentity = Script::GetEntity(entref);
|
||||
const auto* client = Script::GetClient(gentity);
|
||||
const auto* ent = Game::GetPlayerEntity(entref);
|
||||
const auto* client = Script::GetClient(ent);
|
||||
|
||||
if (!client->bIsTestClient)
|
||||
{
|
||||
@ -197,8 +197,8 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
const auto* gentity = Script::GetEntity(entref);
|
||||
const auto* client = Script::GetClient(gentity);
|
||||
const auto* ent = Game::GetPlayerEntity(entref);
|
||||
const auto* client = Script::GetClient(ent);
|
||||
|
||||
if (!client->bIsTestClient)
|
||||
{
|
||||
@ -234,8 +234,8 @@ namespace Components
|
||||
auto forwardInt = Game::Scr_GetInt(0);
|
||||
auto rightInt = Game::Scr_GetInt(1);
|
||||
|
||||
const auto* gentity = Script::GetEntity(entref);
|
||||
const auto* client = Script::GetClient(gentity);
|
||||
const auto* ent = Game::GetPlayerEntity(entref);
|
||||
const auto* client = Script::GetClient(ent);
|
||||
|
||||
if (!client->bIsTestClient)
|
||||
{
|
||||
|
@ -177,13 +177,7 @@ namespace Components
|
||||
{
|
||||
Script::AddFunction("Noclip", [](Game::scr_entref_t entref) // gsc: Noclip(<optional int toggle>);
|
||||
{
|
||||
const auto* ent = Script::GetEntity(entref);
|
||||
|
||||
if (ent->client == nullptr)
|
||||
{
|
||||
Game::Scr_ObjectError(Utils::String::VA("^1NoClip: entity %i is not a client\n", ent->s.number));
|
||||
return;
|
||||
}
|
||||
const auto* ent = Game::GetPlayerEntity(entref);
|
||||
|
||||
if (Game::Scr_GetNumParam() >= 1u)
|
||||
{
|
||||
@ -204,13 +198,7 @@ namespace Components
|
||||
|
||||
Script::AddFunction("Ufo", [](Game::scr_entref_t entref) // gsc: Ufo(<optional int toggle>);
|
||||
{
|
||||
const auto* ent = Script::GetEntity(entref);
|
||||
|
||||
if (ent->client == nullptr)
|
||||
{
|
||||
Game::Scr_ObjectError(Utils::String::VA("^1Ufo: entity %i is not a client\n", ent->s.number));
|
||||
return;
|
||||
}
|
||||
const auto* ent = Game::GetPlayerEntity(entref);
|
||||
|
||||
if (Game::Scr_GetNumParam() >= 1u)
|
||||
{
|
||||
@ -231,7 +219,7 @@ namespace Components
|
||||
|
||||
Script::AddFunction("God", [](Game::scr_entref_t entref) // gsc: God(<optional int toggle>);
|
||||
{
|
||||
auto* ent = Script::GetEntity(entref);
|
||||
auto* ent = Game::GetPlayerEntity(entref);
|
||||
|
||||
if (Game::Scr_GetNumParam() >= 1u)
|
||||
{
|
||||
@ -252,7 +240,7 @@ namespace Components
|
||||
|
||||
Script::AddFunction("Demigod", [](Game::scr_entref_t entref) // gsc: Demigod(<optional int toggle>);
|
||||
{
|
||||
auto* ent = Script::GetEntity(entref);
|
||||
auto* ent = Game::GetEntity(entref);
|
||||
|
||||
if (Game::Scr_GetNumParam() >= 1u)
|
||||
{
|
||||
@ -273,7 +261,7 @@ namespace Components
|
||||
|
||||
Script::AddFunction("Notarget", [](Game::scr_entref_t entref) // gsc: Notarget(<optional int toggle>);
|
||||
{
|
||||
auto* ent = Script::GetEntity(entref);
|
||||
auto* ent = Game::GetEntity(entref);
|
||||
|
||||
if (Game::Scr_GetNumParam() >= 1u)
|
||||
{
|
||||
|
@ -517,32 +517,23 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
Game::gentity_t* Script::GetEntity(const Game::scr_entref_t entref)
|
||||
Game::client_t* Script::GetClient(const Game::gentity_t* ent)
|
||||
{
|
||||
if (entref.classnum != 0 || entref.entnum >= Game::MAX_GENTITIES)
|
||||
assert(ent != nullptr);
|
||||
|
||||
if (ent->client == nullptr)
|
||||
{
|
||||
Game::Scr_ObjectError("Not an entity");
|
||||
Game::Scr_ObjectError(Utils::String::VA("Entity %i is not a player", ent->s.number));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &Game::g_entities[entref.entnum];
|
||||
}
|
||||
|
||||
Game::client_t* Script::GetClient(const Game::gentity_t* gentity)
|
||||
if (ent->s.number >= *Game::svs_numclients)
|
||||
{
|
||||
if (gentity->client == nullptr)
|
||||
{
|
||||
Game::Scr_ObjectError(Utils::String::VA("Entity %i is not a player", gentity->s.number));
|
||||
Game::Scr_ObjectError(Utils::String::VA("Entity %i is out of bounds", ent->s.number));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (gentity->s.number >= *Game::svs_numclients)
|
||||
{
|
||||
Game::Scr_ObjectError(Utils::String::VA("Entity %i is out of bounds", gentity->s.number));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &Game::svs_clients[gentity->s.number];
|
||||
return &Game::svs_clients[ent->s.number];
|
||||
}
|
||||
|
||||
void Script::AddFunctions()
|
||||
@ -684,13 +675,7 @@ namespace Components
|
||||
// PlayerCmd_AreControlsFrozen GSC function from Black Ops 2
|
||||
Script::AddFunction("AreControlsFrozen", [](Game::scr_entref_t entref) // Usage: self AreControlsFrozen();
|
||||
{
|
||||
const auto* ent = Script::GetEntity(entref);
|
||||
|
||||
if (ent->client == nullptr)
|
||||
{
|
||||
Game::Scr_ObjectError(Utils::String::VA("Entity %i is not a player", ent->s.number));
|
||||
return;
|
||||
}
|
||||
const auto* ent = Game::GetPlayerEntity(entref);
|
||||
|
||||
Game::Scr_AddBool((ent->client->flags & Game::PLAYER_FLAG_FROZEN) != 0);
|
||||
});
|
||||
|
@ -29,7 +29,6 @@ namespace Components
|
||||
|
||||
static void OnVMShutdown(Utils::Slot<Scheduler::Callback> callback);
|
||||
|
||||
static Game::gentity_t* GetEntity(const Game::scr_entref_t entref);
|
||||
static Game::client_t* GetClient(const Game::gentity_t* gentity);
|
||||
|
||||
private:
|
||||
|
@ -132,8 +132,8 @@ namespace Components
|
||||
// ScriptExtension methods
|
||||
Script::AddFunction("GetIp", [](Game::scr_entref_t entref) // gsc: self GetIp()
|
||||
{
|
||||
const auto* gentity = Script::GetEntity(entref);
|
||||
const auto* client = Script::GetClient(gentity);
|
||||
const auto* ent = Game::GetPlayerEntity(entref);
|
||||
const auto* client = Script::GetClient(ent);
|
||||
|
||||
std::string ip = Game::NET_AdrToString(client->netchan.remoteAddress);
|
||||
|
||||
@ -147,8 +147,8 @@ namespace Components
|
||||
|
||||
Script::AddFunction("GetPing", [](Game::scr_entref_t entref) // gsc: self GetPing()
|
||||
{
|
||||
const auto* gentity = Script::GetEntity(entref);
|
||||
const auto* client = Script::GetClient(gentity);
|
||||
const auto* ent = Game::GetPlayerEntity(entref);
|
||||
const auto* client = Script::GetClient(ent);
|
||||
|
||||
Game::Scr_AddInt(client->ping);
|
||||
});
|
||||
|
@ -276,13 +276,18 @@ namespace Game
|
||||
Scr_AddObject_t Scr_AddObject = Scr_AddObject_t(0x430F40);
|
||||
Scr_Notify_t Scr_Notify = Scr_Notify_t(0x4A4750);
|
||||
Scr_NotifyLevel_t Scr_NotifyLevel = Scr_NotifyLevel_t(0x4D9C30);
|
||||
|
||||
Scr_Error_t Scr_Error = Scr_Error_t(0x61E8B0);
|
||||
Scr_ObjectError_t Scr_ObjectError = Scr_ObjectError_t(0x42EF40);
|
||||
Scr_ParamError_t Scr_ParamError = Scr_ParamError_t(0x4FBC70);
|
||||
|
||||
Scr_GetType_t Scr_GetType = Scr_GetType_t(0x422900);
|
||||
|
||||
Scr_ClearOutParams_t Scr_ClearOutParams = Scr_ClearOutParams_t(0x4386E0);
|
||||
|
||||
GetEntity_t GetEntity = GetEntity_t(0x4BC270);
|
||||
GetPlayerEntity_t GetPlayerEntity = GetPlayerEntity_t(0x49C4A0);
|
||||
|
||||
Scr_RegisterFunction_t Scr_RegisterFunction = Scr_RegisterFunction_t(0x492D50);
|
||||
Scr_ShutdownAllocNode_t Scr_ShutdownAllocNode = Scr_ShutdownAllocNode_t(0x441650);
|
||||
Scr_IsSystemActive_t Scr_IsSystemActive = Scr_IsSystemActive_t(0x4B24E0);
|
||||
|
@ -717,6 +717,12 @@ namespace Game
|
||||
typedef void(__cdecl * Scr_ParamError_t)(unsigned int paramIndex, const char*);
|
||||
extern Scr_ParamError_t Scr_ParamError;
|
||||
|
||||
typedef gentity_s*(__cdecl * GetPlayerEntity_t)(scr_entref_t entref);
|
||||
extern GetPlayerEntity_t GetPlayerEntity;
|
||||
|
||||
typedef gentity_s*(__cdecl * GetEntity_t)(scr_entref_t entref);
|
||||
extern GetEntity_t GetEntity;
|
||||
|
||||
typedef script_t* (__cdecl * Script_Alloc_t)(int length);
|
||||
extern Script_Alloc_t Script_Alloc;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user