From 8d31466fc5fa7999358841b85e1ce36bbeb26e0d Mon Sep 17 00:00:00 2001 From: FutureRave Date: Wed, 4 May 2022 12:44:45 +0100 Subject: [PATCH] [Script] GScr_IsArray --- src/Components/Modules/ClientCommand.cpp | 2 +- src/Components/Modules/Download.cpp | 4 +- src/Components/Modules/Script.cpp | 26 +++---- src/Components/Modules/ScriptExtension.cpp | 34 ++++++++-- src/Game/Functions.cpp | 1 + src/Game/Functions.hpp | 5 +- src/Game/Structs.hpp | 79 ++++++++++++++++------ 7 files changed, 108 insertions(+), 43 deletions(-) diff --git a/src/Components/Modules/ClientCommand.cpp b/src/Components/Modules/ClientCommand.cpp index 060fb81f..7d8436da 100644 --- a/src/Components/Modules/ClientCommand.cpp +++ b/src/Components/Modules/ClientCommand.cpp @@ -354,7 +354,7 @@ namespace Components } }); - Script::AddFunction("DropAllBots", []() // gsc: DropAllBots(); + Script::AddFunction("DropAllBots", [] // gsc: DropAllBots(); { Game::SV_DropAllBots(); }); diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index c9d875da..5865d569 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -964,7 +964,7 @@ namespace Components Download::ScriptDownloads.clear(); }); - Script::AddFunction("HttpGet", []() + Script::AddFunction("HttpGet", [] { if (!Flags::HasFlag("scriptablehttp")) return; @@ -985,7 +985,7 @@ namespace Components Game::RemoveRefToObject(object); }); - Script::AddFunction("HttpCancel", []() + Script::AddFunction("HttpCancel", [] { if (!Flags::HasFlag("scriptablehttp")) return; diff --git a/src/Components/Modules/Script.cpp b/src/Components/Modules/Script.cpp index 798a2541..cb4dc4e9 100644 --- a/src/Components/Modules/Script.cpp +++ b/src/Components/Modules/Script.cpp @@ -431,7 +431,7 @@ namespace Components { std::memmove(&Game::scrVmPub->top[-4], &Game::scrVmPub->top[-5], sizeof(Game::VariableValue) * 6); Game::scrVmPub->top += 1; - Game::scrVmPub->top[-6].type = Game::VAR_FLOAT; + Game::scrVmPub->top[-6].type = Game::scrParamType_t::VAR_FLOAT; Game::scrVmPub->top[-6].u.floatValue = 0.0f; ++Game::scrVmPub->outparamcount; @@ -450,7 +450,7 @@ namespace Components const auto value = &Game::scrVmPub->top[-index]; - if (value->type != Game::VAR_FUNCTION) + if (value->type != Game::scrParamType_t::VAR_FUNCTION) { Game::Scr_ParamError(static_cast(index), "^1GetCodePosForParam: Expects a function as parameter!\n"); return ""; @@ -549,7 +549,7 @@ namespace Components void Script::AddFunctions() { - Script::AddFunction("ReplaceFunc", []() // gsc: ReplaceFunc(, ) + Script::AddFunction("ReplaceFunc", [] // gsc: ReplaceFunc(, ) { if (Game::Scr_GetNumParam() != 2u) { @@ -564,7 +564,7 @@ namespace Components }); // System time - Script::AddFunction("GetSystemTime", []() // gsc: GetSystemTime() + Script::AddFunction("GetSystemTime", [] // gsc: GetSystemTime() { SYSTEMTIME time; GetSystemTime(&time); @@ -572,7 +572,7 @@ namespace Components Game::Scr_AddInt(time.wSecond); }); - Script::AddFunction("GetSystemMilliseconds", []() // gsc: GetSystemMilliseconds() + Script::AddFunction("GetSystemMilliseconds", [] // gsc: GetSystemMilliseconds() { SYSTEMTIME time; GetSystemTime(&time); @@ -581,7 +581,7 @@ namespace Components }); // Executes command to the console - Script::AddFunction("Exec", []() // gsc: Exec() + Script::AddFunction("Exec", [] // gsc: Exec() { const auto str = Game::Scr_GetString(0); @@ -595,7 +595,7 @@ namespace Components }); // Allow printing to the console even when developer is 0 - Script::AddFunction("PrintConsole", []() // gsc: PrintConsole() + Script::AddFunction("PrintConsole", [] // gsc: PrintConsole() { for (auto i = 0u; i < Game::Scr_GetNumParam(); i++) { @@ -612,7 +612,7 @@ namespace Components }); // Script Storage Functions - Script::AddFunction("StorageSet", []() // gsc: StorageSet(, ); + Script::AddFunction("StorageSet", [] // gsc: StorageSet(, ); { const auto* key = Game::Scr_GetString(0); const auto* value = Game::Scr_GetString(1); @@ -626,7 +626,7 @@ namespace Components Script::ScriptStorage.insert_or_assign(key, value); }); - Script::AddFunction("StorageRemove", []() // gsc: StorageRemove(); + Script::AddFunction("StorageRemove", [] // gsc: StorageRemove(); { const auto* key = Game::Scr_GetString(0); @@ -645,7 +645,7 @@ namespace Components Script::ScriptStorage.erase(key); }); - Script::AddFunction("StorageGet", []() // gsc: StorageGet(); + Script::AddFunction("StorageGet", [] // gsc: StorageGet(); { const auto* key = Game::Scr_GetString(0); @@ -665,7 +665,7 @@ namespace Components Game::Scr_AddString(data.data()); }); - Script::AddFunction("StorageHas", []() // gsc: StorageHas(); + Script::AddFunction("StorageHas", [] // gsc: StorageHas(); { const auto* key = Game::Scr_GetString(0); @@ -678,7 +678,7 @@ namespace Components Game::Scr_AddBool(static_cast(Script::ScriptStorage.count(key))); // Until C++17 }); - Script::AddFunction("StorageClear", []() // gsc: StorageClear(); + Script::AddFunction("StorageClear", [] // gsc: StorageClear(); { Script::ScriptStorage.clear(); }); @@ -746,7 +746,7 @@ namespace Components }); #ifdef _DEBUG - Script::AddFunction("DebugBox", []() + Script::AddFunction("DebugBox", [] { const auto* message = Game::Scr_GetString(0); diff --git a/src/Components/Modules/ScriptExtension.cpp b/src/Components/Modules/ScriptExtension.cpp index 68e80a7a..66e166de 100644 --- a/src/Components/Modules/ScriptExtension.cpp +++ b/src/Components/Modules/ScriptExtension.cpp @@ -116,7 +116,7 @@ namespace Components void ScriptExtension::AddFunctions() { // File functions - Script::AddFunction("FileWrite", []() // gsc: FileWrite(, , ) + Script::AddFunction("FileWrite", [] // gsc: FileWrite(, , ) { const auto* path = Game::Scr_GetString(0); auto* text = Game::Scr_GetString(1); @@ -159,7 +159,7 @@ namespace Components } }); - Script::AddFunction("FileRead", []() // gsc: FileRead() + Script::AddFunction("FileRead", [] // gsc: FileRead() { const auto* path = Game::Scr_GetString(0); @@ -187,7 +187,7 @@ namespace Components Game::Scr_AddString(FileSystem::FileReader(path).getBuffer().data()); }); - Script::AddFunction("FileExists", []() // gsc: FileExists() + Script::AddFunction("FileExists", [] // gsc: FileExists() { const auto* path = Game::Scr_GetString(0); @@ -209,7 +209,7 @@ namespace Components Game::Scr_AddInt(FileSystem::FileReader(path).exists()); }); - Script::AddFunction("FileRemove", []() // gsc: FileRemove() + Script::AddFunction("FileRemove", [] // gsc: FileRemove() { const auto* path = Game::Scr_GetString(0); @@ -235,7 +235,7 @@ namespace Components }); // Misc functions - Script::AddFunction("ToUpper", []() // gsc: ToUpper() + Script::AddFunction("ToUpper", [] // gsc: ToUpper() { const auto scriptValue = Game::Scr_GetConstString(0); const auto* string = Game::SL_ConvertToString(scriptValue); @@ -280,7 +280,7 @@ namespace Components }); // Func present on IW5 - Script::AddFunction("StrICmp", []() // gsc: StrICmp(, ) + Script::AddFunction("StrICmp", [] // gsc: StrICmp(, ) { const auto value1 = Game::Scr_GetConstString(0); const auto value2 = Game::Scr_GetConstString(1); @@ -292,7 +292,7 @@ namespace Components }); // Func present on IW5 - Script::AddFunction("IsEndStr", []() // gsc: IsEndStr(, ) + Script::AddFunction("IsEndStr", [] // gsc: IsEndStr(, ) { const auto* s1 = Game::Scr_GetString(0); const auto* s2 = Game::Scr_GetString(1); @@ -305,6 +305,26 @@ namespace Components Game::Scr_AddBool(Utils::String::EndsWith(s1, s2)); }); + + Script::AddFunction("IsArray", [] + { + const auto type = Game::Scr_GetType(0); + + bool result; + if (type == Game::scrParamType_t::VAR_POINTER) + { + const auto ptr_type = Game::Scr_GetPointerType(0); + assert(ptr_type >= Game::FIRST_OBJECT); + result = (ptr_type == Game::scrParamType_t::VAR_ARRAY); + } + else + { + assert(type < Game::FIRST_OBJECT); + result = false; + } + + Game::Scr_AddBool(result); + }); } void ScriptExtension::AddMethods() diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 5fb7505a..4dab19e6 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -293,6 +293,7 @@ namespace Game Scr_ParamError_t Scr_ParamError = Scr_ParamError_t(0x4FBC70); Scr_GetType_t Scr_GetType = Scr_GetType_t(0x422900); + Scr_GetPointerType_t Scr_GetPointerType = Scr_GetPointerType_t(0x4828E0); Scr_ClearOutParams_t Scr_ClearOutParams = Scr_ClearOutParams_t(0x4386E0); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 4369bbad..a03f0c85 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -735,9 +735,12 @@ namespace Game typedef bool(__cdecl * Scr_IsSystemActive_t)(); extern Scr_IsSystemActive_t Scr_IsSystemActive; - typedef int(__cdecl * Scr_GetType_t)(unsigned int); + typedef int(__cdecl * Scr_GetType_t)(unsigned int index); extern Scr_GetType_t Scr_GetType; + typedef int(__cdecl * Scr_GetPointerType_t)(unsigned int index); + extern Scr_GetPointerType_t Scr_GetPointerType; + typedef void(__cdecl * Scr_Error_t)(const char*); extern Scr_Error_t Scr_Error; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index e0eb5dcc..f30a607d 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -234,7 +234,7 @@ namespace Game CS_ACTIVE = 0x5, } clientstate_t; - typedef enum + enum errorParm_t { ERR_FATAL = 0x0, ERR_DROP = 0x1, @@ -244,7 +244,39 @@ namespace Game ERR_SCRIPT_DROP = 0x5, ERR_LOCALIZATION = 0x6, ERR_MAPLOADERRORSUMMARY = 0x7 - } errorParm_t; + }; + + enum conChannel_t + { + CON_CHANNEL_DONT_FILTER, + CON_CHANNEL_ERROR, + CON_CHANNEL_GAMENOTIFY, + CON_CHANNEL_BOLDGAME, + CON_CHANNEL_SUBTITLE, + CON_CHANNEL_OBITUARY, + CON_CHANNEL_LOGFILEONLY, + CON_CHANNEL_CONSOLEONLY, + CON_CHANNEL_GFX, + CON_CHANNEL_SOUND, + CON_CHANNEL_FILES, + CON_CHANNEL_DEVGUI, + CON_CHANNEL_PROFILE, + CON_CHANNEL_UI, + CON_CHANNEL_CLIENT, + CON_CHANNEL_SERVER, + CON_CHANNEL_SYSTEM, + CON_CHANNEL_PLAYERWEAP, + CON_CHANNEL_AI, + CON_CHANNEL_ANIM, + CON_CHANNEL_PHYS, + CON_CHANNEL_FX, + CON_CHANNEL_LEADERBOARDS, + CON_CHANNEL_PARSERSCRIPT, + CON_CHANNEL_SCRIPT, + CON_CHANNEL_NETWORK, + + CON_BUILTIN_CHANNEL_COUNT, + }; enum entityFlag { @@ -5096,7 +5128,7 @@ namespace Game char buf[1]; }; - enum VariableType + enum scrParamType_t { VAR_UNDEFINED = 0x0, VAR_BEGIN_REF = 0x1, @@ -5114,21 +5146,30 @@ namespace Game VAR_BUILTIN_METHOD = 0xB, VAR_STACK = 0xC, VAR_ANIMATION = 0xD, - VAR_PRE_ANIMATION = 0xE, - VAR_THREAD = 0xF, - VAR_NOTIFY_THREAD = 0x10, - VAR_TIME_THREAD = 0x11, - VAR_CHILD_THREAD = 0x12, - VAR_OBJECT = 0x13, - VAR_DEAD_ENTITY = 0x14, - VAR_ENTITY = 0x15, - VAR_ARRAY = 0x16, - VAR_DEAD_THREAD = 0x17, - VAR_COUNT = 0x18, - VAR_FREE = 0x18, - VAR_THREAD_LIST = 0x19, - VAR_ENDON_LIST = 0x1A, - VAR_TOTAL_COUNT = 0x1B, + VAR_DEVELOPER_CODEPOS = 0xE, + VAR_PRE_ANIMATION = 0xF, + VAR_THREAD = 0x10, + VAR_NOTIFY_THREAD = 0x11, + VAR_TIME_THREAD = 0x12, + VAR_CHILD_THREAD = 0x13, + VAR_OBJECT = 0x14, + VAR_DEAD_ENTITY = 0x15, + VAR_ENTITY = 0x16, + VAR_ARRAY = 0x17, + VAR_DEAD_THREAD = 0x18, + VAR_COUNT = 0x19, + VAR_THREAD_LIST = 0x1A, + VAR_ENDON_LIST = 0x1B, + }; + + enum $2441F0C7E439C64E6C27842ECB570A7C + { + FIRST_OBJECT = 0x10, + FIRST_CLEARABLE_OBJECT = 0x14, + LAST_NONENTITY_OBJECT = 0x14, + FIRST_ENTITY_OBJECT = 0x16, + FIRST_NONFIELD_OBJECT = 0x17, + FIRST_DEAD_OBJECT = 0x18, }; union VariableUnion @@ -5147,7 +5188,7 @@ namespace Game struct VariableValue { VariableUnion u; - VariableType type; + scrParamType_t type; }; struct function_stack_t