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