[Script] GScr_IsArray

This commit is contained in:
FutureRave 2022-05-04 12:44:45 +01:00
parent 219a10d6a0
commit 8d31466fc5
No known key found for this signature in database
GPG Key ID: E883E2BC9657D955
7 changed files with 108 additions and 43 deletions

View File

@ -354,7 +354,7 @@ namespace Components
} }
}); });
Script::AddFunction("DropAllBots", []() // gsc: DropAllBots(); Script::AddFunction("DropAllBots", [] // gsc: DropAllBots();
{ {
Game::SV_DropAllBots(); Game::SV_DropAllBots();
}); });

View File

@ -964,7 +964,7 @@ namespace Components
Download::ScriptDownloads.clear(); Download::ScriptDownloads.clear();
}); });
Script::AddFunction("HttpGet", []() Script::AddFunction("HttpGet", []
{ {
if (!Flags::HasFlag("scriptablehttp")) if (!Flags::HasFlag("scriptablehttp"))
return; return;
@ -985,7 +985,7 @@ namespace Components
Game::RemoveRefToObject(object); Game::RemoveRefToObject(object);
}); });
Script::AddFunction("HttpCancel", []() Script::AddFunction("HttpCancel", []
{ {
if (!Flags::HasFlag("scriptablehttp")) if (!Flags::HasFlag("scriptablehttp"))
return; return;

View File

@ -431,7 +431,7 @@ namespace Components
{ {
std::memmove(&Game::scrVmPub->top[-4], &Game::scrVmPub->top[-5], sizeof(Game::VariableValue) * 6); std::memmove(&Game::scrVmPub->top[-4], &Game::scrVmPub->top[-5], sizeof(Game::VariableValue) * 6);
Game::scrVmPub->top += 1; 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->top[-6].u.floatValue = 0.0f;
++Game::scrVmPub->outparamcount; ++Game::scrVmPub->outparamcount;
@ -450,7 +450,7 @@ namespace Components
const auto value = &Game::scrVmPub->top[-index]; 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<unsigned int>(index), "^1GetCodePosForParam: Expects a function as parameter!\n"); Game::Scr_ParamError(static_cast<unsigned int>(index), "^1GetCodePosForParam: Expects a function as parameter!\n");
return ""; return "";
@ -549,7 +549,7 @@ namespace Components
void Script::AddFunctions() void Script::AddFunctions()
{ {
Script::AddFunction("ReplaceFunc", []() // gsc: ReplaceFunc(<function>, <function>) Script::AddFunction("ReplaceFunc", [] // gsc: ReplaceFunc(<function>, <function>)
{ {
if (Game::Scr_GetNumParam() != 2u) if (Game::Scr_GetNumParam() != 2u)
{ {
@ -564,7 +564,7 @@ namespace Components
}); });
// System time // System time
Script::AddFunction("GetSystemTime", []() // gsc: GetSystemTime() Script::AddFunction("GetSystemTime", [] // gsc: GetSystemTime()
{ {
SYSTEMTIME time; SYSTEMTIME time;
GetSystemTime(&time); GetSystemTime(&time);
@ -572,7 +572,7 @@ namespace Components
Game::Scr_AddInt(time.wSecond); Game::Scr_AddInt(time.wSecond);
}); });
Script::AddFunction("GetSystemMilliseconds", []() // gsc: GetSystemMilliseconds() Script::AddFunction("GetSystemMilliseconds", [] // gsc: GetSystemMilliseconds()
{ {
SYSTEMTIME time; SYSTEMTIME time;
GetSystemTime(&time); GetSystemTime(&time);
@ -581,7 +581,7 @@ namespace Components
}); });
// Executes command to the console // Executes command to the console
Script::AddFunction("Exec", []() // gsc: Exec(<string>) Script::AddFunction("Exec", [] // gsc: Exec(<string>)
{ {
const auto str = Game::Scr_GetString(0); const auto str = Game::Scr_GetString(0);
@ -595,7 +595,7 @@ namespace Components
}); });
// Allow printing to the console even when developer is 0 // Allow printing to the console even when developer is 0
Script::AddFunction("PrintConsole", []() // gsc: PrintConsole(<string>) Script::AddFunction("PrintConsole", [] // gsc: PrintConsole(<string>)
{ {
for (auto i = 0u; i < Game::Scr_GetNumParam(); i++) for (auto i = 0u; i < Game::Scr_GetNumParam(); i++)
{ {
@ -612,7 +612,7 @@ namespace Components
}); });
// Script Storage Functions // Script Storage Functions
Script::AddFunction("StorageSet", []() // gsc: StorageSet(<str key>, <str data>); Script::AddFunction("StorageSet", [] // gsc: StorageSet(<str key>, <str data>);
{ {
const auto* key = Game::Scr_GetString(0); const auto* key = Game::Scr_GetString(0);
const auto* value = Game::Scr_GetString(1); const auto* value = Game::Scr_GetString(1);
@ -626,7 +626,7 @@ namespace Components
Script::ScriptStorage.insert_or_assign(key, value); Script::ScriptStorage.insert_or_assign(key, value);
}); });
Script::AddFunction("StorageRemove", []() // gsc: StorageRemove(<str key>); Script::AddFunction("StorageRemove", [] // gsc: StorageRemove(<str key>);
{ {
const auto* key = Game::Scr_GetString(0); const auto* key = Game::Scr_GetString(0);
@ -645,7 +645,7 @@ namespace Components
Script::ScriptStorage.erase(key); Script::ScriptStorage.erase(key);
}); });
Script::AddFunction("StorageGet", []() // gsc: StorageGet(<str key>); Script::AddFunction("StorageGet", [] // gsc: StorageGet(<str key>);
{ {
const auto* key = Game::Scr_GetString(0); const auto* key = Game::Scr_GetString(0);
@ -665,7 +665,7 @@ namespace Components
Game::Scr_AddString(data.data()); Game::Scr_AddString(data.data());
}); });
Script::AddFunction("StorageHas", []() // gsc: StorageHas(<str key>); Script::AddFunction("StorageHas", [] // gsc: StorageHas(<str key>);
{ {
const auto* key = Game::Scr_GetString(0); const auto* key = Game::Scr_GetString(0);
@ -678,7 +678,7 @@ namespace Components
Game::Scr_AddBool(static_cast<int>(Script::ScriptStorage.count(key))); // Until C++17 Game::Scr_AddBool(static_cast<int>(Script::ScriptStorage.count(key))); // Until C++17
}); });
Script::AddFunction("StorageClear", []() // gsc: StorageClear(); Script::AddFunction("StorageClear", [] // gsc: StorageClear();
{ {
Script::ScriptStorage.clear(); Script::ScriptStorage.clear();
}); });
@ -746,7 +746,7 @@ namespace Components
}); });
#ifdef _DEBUG #ifdef _DEBUG
Script::AddFunction("DebugBox", []() Script::AddFunction("DebugBox", []
{ {
const auto* message = Game::Scr_GetString(0); const auto* message = Game::Scr_GetString(0);

View File

@ -116,7 +116,7 @@ namespace Components
void ScriptExtension::AddFunctions() void ScriptExtension::AddFunctions()
{ {
// File functions // File functions
Script::AddFunction("FileWrite", []() // gsc: FileWrite(<filepath>, <string>, <mode>) Script::AddFunction("FileWrite", [] // gsc: FileWrite(<filepath>, <string>, <mode>)
{ {
const auto* path = Game::Scr_GetString(0); const auto* path = Game::Scr_GetString(0);
auto* text = Game::Scr_GetString(1); auto* text = Game::Scr_GetString(1);
@ -159,7 +159,7 @@ namespace Components
} }
}); });
Script::AddFunction("FileRead", []() // gsc: FileRead(<filepath>) Script::AddFunction("FileRead", [] // gsc: FileRead(<filepath>)
{ {
const auto* path = Game::Scr_GetString(0); const auto* path = Game::Scr_GetString(0);
@ -187,7 +187,7 @@ namespace Components
Game::Scr_AddString(FileSystem::FileReader(path).getBuffer().data()); Game::Scr_AddString(FileSystem::FileReader(path).getBuffer().data());
}); });
Script::AddFunction("FileExists", []() // gsc: FileExists(<filepath>) Script::AddFunction("FileExists", [] // gsc: FileExists(<filepath>)
{ {
const auto* path = Game::Scr_GetString(0); const auto* path = Game::Scr_GetString(0);
@ -209,7 +209,7 @@ namespace Components
Game::Scr_AddInt(FileSystem::FileReader(path).exists()); Game::Scr_AddInt(FileSystem::FileReader(path).exists());
}); });
Script::AddFunction("FileRemove", []() // gsc: FileRemove(<filepath>) Script::AddFunction("FileRemove", [] // gsc: FileRemove(<filepath>)
{ {
const auto* path = Game::Scr_GetString(0); const auto* path = Game::Scr_GetString(0);
@ -235,7 +235,7 @@ namespace Components
}); });
// Misc functions // Misc functions
Script::AddFunction("ToUpper", []() // gsc: ToUpper(<string>) Script::AddFunction("ToUpper", [] // gsc: ToUpper(<string>)
{ {
const auto scriptValue = Game::Scr_GetConstString(0); const auto scriptValue = Game::Scr_GetConstString(0);
const auto* string = Game::SL_ConvertToString(scriptValue); const auto* string = Game::SL_ConvertToString(scriptValue);
@ -280,7 +280,7 @@ namespace Components
}); });
// Func present on IW5 // Func present on IW5
Script::AddFunction("StrICmp", []() // gsc: StrICmp(<string>, <string>) Script::AddFunction("StrICmp", [] // gsc: StrICmp(<string>, <string>)
{ {
const auto value1 = Game::Scr_GetConstString(0); const auto value1 = Game::Scr_GetConstString(0);
const auto value2 = Game::Scr_GetConstString(1); const auto value2 = Game::Scr_GetConstString(1);
@ -292,7 +292,7 @@ namespace Components
}); });
// Func present on IW5 // Func present on IW5
Script::AddFunction("IsEndStr", []() // gsc: IsEndStr(<string>, <string>) Script::AddFunction("IsEndStr", [] // gsc: IsEndStr(<string>, <string>)
{ {
const auto* s1 = Game::Scr_GetString(0); const auto* s1 = Game::Scr_GetString(0);
const auto* s2 = Game::Scr_GetString(1); const auto* s2 = Game::Scr_GetString(1);
@ -305,6 +305,26 @@ namespace Components
Game::Scr_AddBool(Utils::String::EndsWith(s1, s2)); 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() void ScriptExtension::AddMethods()

View File

@ -293,6 +293,7 @@ namespace Game
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_GetPointerType_t Scr_GetPointerType = Scr_GetPointerType_t(0x4828E0);
Scr_ClearOutParams_t Scr_ClearOutParams = Scr_ClearOutParams_t(0x4386E0); Scr_ClearOutParams_t Scr_ClearOutParams = Scr_ClearOutParams_t(0x4386E0);

View File

@ -735,9 +735,12 @@ namespace Game
typedef bool(__cdecl * Scr_IsSystemActive_t)(); typedef bool(__cdecl * Scr_IsSystemActive_t)();
extern Scr_IsSystemActive_t Scr_IsSystemActive; 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; 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*); typedef void(__cdecl * Scr_Error_t)(const char*);
extern Scr_Error_t Scr_Error; extern Scr_Error_t Scr_Error;

View File

@ -234,7 +234,7 @@ namespace Game
CS_ACTIVE = 0x5, CS_ACTIVE = 0x5,
} clientstate_t; } clientstate_t;
typedef enum enum errorParm_t
{ {
ERR_FATAL = 0x0, ERR_FATAL = 0x0,
ERR_DROP = 0x1, ERR_DROP = 0x1,
@ -244,7 +244,39 @@ namespace Game
ERR_SCRIPT_DROP = 0x5, ERR_SCRIPT_DROP = 0x5,
ERR_LOCALIZATION = 0x6, ERR_LOCALIZATION = 0x6,
ERR_MAPLOADERRORSUMMARY = 0x7 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 enum entityFlag
{ {
@ -5096,7 +5128,7 @@ namespace Game
char buf[1]; char buf[1];
}; };
enum VariableType enum scrParamType_t
{ {
VAR_UNDEFINED = 0x0, VAR_UNDEFINED = 0x0,
VAR_BEGIN_REF = 0x1, VAR_BEGIN_REF = 0x1,
@ -5114,21 +5146,30 @@ namespace Game
VAR_BUILTIN_METHOD = 0xB, VAR_BUILTIN_METHOD = 0xB,
VAR_STACK = 0xC, VAR_STACK = 0xC,
VAR_ANIMATION = 0xD, VAR_ANIMATION = 0xD,
VAR_PRE_ANIMATION = 0xE, VAR_DEVELOPER_CODEPOS = 0xE,
VAR_THREAD = 0xF, VAR_PRE_ANIMATION = 0xF,
VAR_NOTIFY_THREAD = 0x10, VAR_THREAD = 0x10,
VAR_TIME_THREAD = 0x11, VAR_NOTIFY_THREAD = 0x11,
VAR_CHILD_THREAD = 0x12, VAR_TIME_THREAD = 0x12,
VAR_OBJECT = 0x13, VAR_CHILD_THREAD = 0x13,
VAR_DEAD_ENTITY = 0x14, VAR_OBJECT = 0x14,
VAR_ENTITY = 0x15, VAR_DEAD_ENTITY = 0x15,
VAR_ARRAY = 0x16, VAR_ENTITY = 0x16,
VAR_DEAD_THREAD = 0x17, VAR_ARRAY = 0x17,
VAR_COUNT = 0x18, VAR_DEAD_THREAD = 0x18,
VAR_FREE = 0x18, VAR_COUNT = 0x19,
VAR_THREAD_LIST = 0x19, VAR_THREAD_LIST = 0x1A,
VAR_ENDON_LIST = 0x1A, VAR_ENDON_LIST = 0x1B,
VAR_TOTAL_COUNT = 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 union VariableUnion
@ -5147,7 +5188,7 @@ namespace Game
struct VariableValue struct VariableValue
{ {
VariableUnion u; VariableUnion u;
VariableType type; scrParamType_t type;
}; };
struct function_stack_t struct function_stack_t