diff --git a/src/client/component/gsc/script_extension.cpp b/src/client/component/gsc/script_extension.cpp index 56682adf..0afe32dd 100644 --- a/src/client/component/gsc/script_extension.cpp +++ b/src/client/component/gsc/script_extension.cpp @@ -427,7 +427,7 @@ namespace gsc const auto what = args[0].get_raw(); const auto with = args[1].get_raw(); - if (what.type != game::SCRIPT_FUNCTION || with.type != game::SCRIPT_FUNCTION) + if (what.type != game::VAR_FUNCTION || with.type != game::VAR_FUNCTION) { throw std::runtime_error("replaceFunc: parameter 1 must be a function"); } diff --git a/src/client/component/json.cpp b/src/client/component/json.cpp index 8ff70958..7144652b 100644 --- a/src/client/component/json.cpp +++ b/src/client/component/json.cpp @@ -66,32 +66,32 @@ namespace json switch (type) { - case (game::SCRIPT_NONE): + case (game::VAR_UNDEFINED): return {}; - case (game::SCRIPT_INTEGER): + case (game::VAR_INTEGER): return value.intValue; - case (game::SCRIPT_FLOAT): + case (game::VAR_FLOAT): return value.floatValue; - case (game::SCRIPT_STRING): - case (game::SCRIPT_ISTRING): + case (game::VAR_STRING): + case (game::VAR_ISTRING): return game::SL_ConvertToString(static_cast(value.stringValue)); - case (game::SCRIPT_VECTOR): + case (game::VAR_VECTOR): return vector_to_array(value.vectorValue); - case (game::SCRIPT_OBJECT): + case (game::VAR_POINTER): { const auto object_type = game::scr_VarGlob->objectVariableValue[value.uintValue].w.type; switch (object_type) { - case (game::SCRIPT_STRUCT): + case (game::VAR_OBJECT): return "[struct]"; - case (game::SCRIPT_ARRAY): + case (game::VAR_ARRAY): return entity_to_array(value.uintValue); default: return "[entity]"; } } - case (game::SCRIPT_FUNCTION): + case (game::VAR_FUNCTION): return _value.as().get_name(); default: return utils::string::va("[%s]", _value.type_name().data()); diff --git a/src/client/component/logfile.cpp b/src/client/component/logfile.cpp index ddf5b5b5..7177fdc3 100644 --- a/src/client/component/logfile.cpp +++ b/src/client/component/logfile.cpp @@ -196,7 +196,7 @@ namespace logfile const auto top = game::scr_function_stack->top; - for (auto* value = top; value->type != game::SCRIPT_END; --value) + for (auto* value = top; value->type != game::VAR_PRECODEPOS; --value) { args.push_back(scripting::lua::convert(state, *value)); } diff --git a/src/client/component/scripting.cpp b/src/client/component/scripting.cpp index 524102c0..8e92ce6b 100644 --- a/src/client/component/scripting.cpp +++ b/src/client/component/scripting.cpp @@ -67,7 +67,7 @@ namespace scripting e.name = string; e.entity = notify_list_owner_id; - for (auto* value = top; value->type != game::SCRIPT_END; --value) + for (auto* value = top; value->type != game::VAR_PRECODEPOS; --value) { e.arguments.emplace_back(*value); } diff --git a/src/client/game/scripting/array.cpp b/src/client/game/scripting/array.cpp index 33164bd9..38fff5e2 100644 --- a/src/client/game/scripting/array.cpp +++ b/src/client/game/scripting/array.cpp @@ -17,7 +17,7 @@ namespace scripting const auto value = game::scr_VarGlob->childVariableValue[this->id_ + 0xFA00 * (this->parent_id_ & 3)]; game::VariableValue variable; variable.u = value.u.u; - variable.type = (game::scriptType_e)value.type; + variable.type = value.type; this->value_ = variable; } @@ -115,7 +115,7 @@ namespace scripting { if (this->id_) { - game::AddRefToValue(game::SCRIPT_OBJECT, {static_cast(this->id_)}); + game::AddRefToValue(game::VAR_POINTER, {static_cast(this->id_)}); } } @@ -123,7 +123,7 @@ namespace scripting { if (this->id_) { - game::RemoveRefToValue(game::SCRIPT_OBJECT, {static_cast(this->id_)}); + game::RemoveRefToValue(game::VAR_POINTER, {static_cast(this->id_)}); } } @@ -138,7 +138,7 @@ namespace scripting { const auto var = game::scr_VarGlob->childVariableValue[i]; - if (var.type == game::SCRIPT_NONE) + if (var.type == game::VAR_UNDEFINED) { current = var.nextSibling; continue; @@ -227,7 +227,7 @@ namespace scripting const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xFA00 * (this->id_ & 3)]; game::VariableValue variable; variable.u = value.u.u; - variable.type = (game::scriptType_e)value.type; + variable.type = value.type; return variable; } @@ -244,7 +244,7 @@ namespace scripting const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xFA00 * (this->id_ & 3)]; game::VariableValue variable; variable.u = value.u.u; - variable.type = (game::scriptType_e)value.type; + variable.type = value.type; return variable; } diff --git a/src/client/game/scripting/entity.cpp b/src/client/game/scripting/entity.cpp index b81dea1b..1119220c 100644 --- a/src/client/game/scripting/entity.cpp +++ b/src/client/game/scripting/entity.cpp @@ -90,7 +90,7 @@ namespace scripting { if (this->entity_id_) { - game::AddRefToValue(game::SCRIPT_OBJECT, {static_cast(this->entity_id_)}); + game::AddRefToValue(game::VAR_POINTER, {static_cast(this->entity_id_)}); } } @@ -98,7 +98,7 @@ namespace scripting { if (this->entity_id_) { - game::RemoveRefToValue(game::SCRIPT_OBJECT, {static_cast(this->entity_id_)}); + game::RemoveRefToValue(game::VAR_POINTER, {static_cast(this->entity_id_)}); } } diff --git a/src/client/game/scripting/execution.cpp b/src/client/game/scripting/execution.cpp index 76f3713d..d72fc358 100644 --- a/src/client/game/scripting/execution.cpp +++ b/src/client/game/scripting/execution.cpp @@ -199,7 +199,7 @@ namespace scripting { unsigned int index = 0; const auto variable = game::AllocVariable(&index); - variable->w.type = game::SCRIPT_ARRAY; + variable->w.type = game::VAR_ARRAY; variable->u.f.prev = 0; variable->u.f.next = 0; diff --git a/src/client/game/scripting/function.cpp b/src/client/game/scripting/function.cpp index 158e8800..a70cf95b 100644 --- a/src/client/game/scripting/function.cpp +++ b/src/client/game/scripting/function.cpp @@ -15,7 +15,7 @@ namespace scripting script_value function::get_raw() const { game::VariableValue value; - value.type = game::SCRIPT_FUNCTION; + value.type = game::VAR_FUNCTION; value.u.codePosValue = this->pos_; return value; diff --git a/src/client/game/scripting/lua/value_conversion.cpp b/src/client/game/scripting/lua/value_conversion.cpp index ed63c02b..ffe0c6da 100644 --- a/src/client/game/scripting/lua/value_conversion.cpp +++ b/src/client/game/scripting/lua/value_conversion.cpp @@ -30,7 +30,7 @@ namespace scripting::lua { const auto var = game::scr_VarGlob->childVariableValue[i]; - if (var.type == game::SCRIPT_NONE) + if (var.type == game::VAR_UNDEFINED) { current = var.nextSibling; continue; @@ -124,7 +124,7 @@ namespace scripting::lua logfile::set_lua_hook(index, function); game::VariableValue func{}; - func.type = game::SCRIPT_FUNCTION; + func.type = game::VAR_FUNCTION; func.u.codePosValue = index; return func; diff --git a/src/client/game/scripting/safe_execution.cpp b/src/client/game/scripting/safe_execution.cpp index 92daa3b7..d100a928 100644 --- a/src/client/game/scripting/safe_execution.cpp +++ b/src/client/game/scripting/safe_execution.cpp @@ -56,7 +56,7 @@ namespace scripting::safe_execution *game::g_script_error_level += 1; if (game::_setjmp(&game::g_script_error[*game::g_script_error_level])) { - value->type = game::SCRIPT_NONE; + value->type = game::VAR_UNDEFINED; value->u.intValue = 0; *game::g_script_error_level -= 1; return false; diff --git a/src/client/game/scripting/script_value.cpp b/src/client/game/scripting/script_value.cpp index ca0d75c5..1cd7af4e 100644 --- a/src/client/game/scripting/script_value.cpp +++ b/src/client/game/scripting/script_value.cpp @@ -23,7 +23,7 @@ namespace scripting script_value::script_value(const int value) { game::VariableValue variable{}; - variable.type = game::SCRIPT_INTEGER; + variable.type = game::VAR_INTEGER; variable.u.intValue = value; this->value_ = variable; @@ -32,7 +32,7 @@ namespace scripting script_value::script_value(const unsigned int value) { game::VariableValue variable{}; - variable.type = game::SCRIPT_INTEGER; + variable.type = game::VAR_INTEGER; variable.u.uintValue = value; this->value_ = variable; @@ -46,7 +46,7 @@ namespace scripting script_value::script_value(const float value) { game::VariableValue variable{}; - variable.type = game::SCRIPT_FLOAT; + variable.type = game::VAR_FLOAT; variable.u.floatValue = value; this->value_ = variable; @@ -60,7 +60,7 @@ namespace scripting script_value::script_value(const char* value) { game::VariableValue variable{}; - variable.type = game::SCRIPT_STRING; + variable.type = game::VAR_STRING; variable.u.stringValue = game::SL_GetString(value, 0); const auto _ = gsl::finally([&variable]() @@ -79,7 +79,7 @@ namespace scripting script_value::script_value(const entity& value) { game::VariableValue variable{}; - variable.type = game::SCRIPT_OBJECT; + variable.type = game::VAR_POINTER; variable.u.pointerValue = value.get_entity_id(); this->value_ = variable; @@ -88,7 +88,7 @@ namespace scripting script_value::script_value(const array& value) { game::VariableValue variable{}; - variable.type = game::SCRIPT_OBJECT; + variable.type = game::VAR_POINTER; variable.u.pointerValue = value.get_entity_id(); this->value_ = variable; @@ -97,7 +97,7 @@ namespace scripting script_value::script_value(const function& value) { game::VariableValue variable{}; - variable.type = game::SCRIPT_FUNCTION; + variable.type = game::VAR_FUNCTION; variable.u.codePosValue = value.get_pos(); this->value_ = variable; @@ -106,7 +106,7 @@ namespace scripting script_value::script_value(const vector& value) { game::VariableValue variable{}; - variable.type = game::SCRIPT_VECTOR; + variable.type = game::VAR_VECTOR; variable.u.vectorValue = game::Scr_AllocVector(value); const auto _ = gsl::finally([&variable]() @@ -124,7 +124,7 @@ namespace scripting template <> bool script_value::is() const { - return this->get_raw().type == game::SCRIPT_INTEGER; + return this->get_raw().type == game::VAR_INTEGER; } template <> @@ -164,7 +164,7 @@ namespace scripting template <> bool script_value::is() const { - return this->get_raw().type == game::SCRIPT_FLOAT; + return this->get_raw().type == game::VAR_FLOAT; } template <> @@ -192,7 +192,7 @@ namespace scripting template <> bool script_value::is() const { - return this->get_raw().type == game::SCRIPT_STRING; + return this->get_raw().type == game::VAR_STRING; } template <> @@ -220,7 +220,7 @@ namespace scripting template <> bool script_value::is() const { - if (this->get_raw().type != game::SCRIPT_OBJECT) + if (this->get_raw().type != game::VAR_POINTER) { return false; } @@ -228,7 +228,7 @@ namespace scripting const auto id = this->get_raw().u.uintValue; const auto type = game::scr_VarGlob->objectVariableValue[id].w.type; - return type == game::SCRIPT_ARRAY; + return type == game::VAR_ARRAY; } template <> @@ -244,7 +244,7 @@ namespace scripting template <> bool script_value::is>() const { - if (this->get_raw().type != game::SCRIPT_OBJECT) + if (this->get_raw().type != game::VAR_POINTER) { return false; } @@ -252,7 +252,7 @@ namespace scripting const auto id = this->get_raw().u.uintValue; const auto type = game::scr_VarGlob->objectVariableValue[id].w.type; - return type == game::SCRIPT_STRUCT; + return type == game::VAR_OBJECT; } /*************************************************************** @@ -262,7 +262,7 @@ namespace scripting template <> bool script_value::is() const { - return this->get_raw().type == game::SCRIPT_FUNCTION; + return this->get_raw().type == game::VAR_FUNCTION; } template <> @@ -278,7 +278,7 @@ namespace scripting template <> bool script_value::is() const { - return this->get_raw().type == game::SCRIPT_OBJECT; + return this->get_raw().type == game::VAR_POINTER; } template <> @@ -294,7 +294,7 @@ namespace scripting template <> bool script_value::is() const { - return this->get_raw().type == game::SCRIPT_VECTOR; + return this->get_raw().type == game::VAR_VECTOR; } template <> diff --git a/src/client/game/scripting/script_value.hpp b/src/client/game/scripting/script_value.hpp index ee703e09..8f8428a1 100644 --- a/src/client/game/scripting/script_value.hpp +++ b/src/client/game/scripting/script_value.hpp @@ -14,47 +14,47 @@ namespace scripting namespace { - std::unordered_map typenames = + std::array var_typename = { - {0, "undefined"}, - {1, "object"}, - {2, "string"}, - {3, "localized string"}, - {4, "vector"}, - {5, "float"}, - {6, "int"}, - {7, "codepos"}, - {8, "precodepos"}, - {9, "function"}, - {10, "builtin function"}, - {11, "builtin method"}, - {12, "stack"}, - {13, "animation"}, - {14, "pre animation"}, - {15, "thread"}, - {16, "notify thread"}, - {17, "time thread"}, - {18, "child thread"}, - {19, "struct"}, - {20, "removed entity"}, - {21, "entity"}, - {22, "array"}, - {23, "removed thread"}, - {24, ""}, - {25, "thread list"}, - {26, "endon list"}, + "undefined", + "object", + "string", + "localized string", + "vector", + "float", + "int", + "codepos", + "precodepos", + "function", + "builtin function", + "builtin method", + "stack", + "animation", + "pre animation", + "thread", + "thread", + "thread", + "thread", + "struct", + "removed entity", + "entity", + "array", + "removed thread", + "", + "thread list", + "endon list", }; std::string get_typename(const game::VariableValue& value) { - if (value.type == game::SCRIPT_OBJECT) + if (value.type == game::VAR_POINTER) { const auto type = game::scr_VarGlob->objectVariableValue[value.u.uintValue].w.type; - return typenames[type]; + return var_typename[type]; } else { - return typenames[value.type]; + return var_typename[value.type]; } } diff --git a/src/client/game/scripting/variable_value.cpp b/src/client/game/scripting/variable_value.cpp index 69a20023..74f5f510 100644 --- a/src/client/game/scripting/variable_value.cpp +++ b/src/client/game/scripting/variable_value.cpp @@ -35,7 +35,7 @@ namespace scripting { this->release(); this->value_ = other.value_; - other.value_.type = game::SCRIPT_NONE; + other.value_.type = game::VAR_UNDEFINED; } return *this; @@ -59,10 +59,10 @@ namespace scripting void variable_value::release() { - if (this->value_.type != game::SCRIPT_NONE) + if (this->value_.type != game::VAR_UNDEFINED) { game::RemoveRefToValue(this->value_.type, this->value_.u); - this->value_.type = game::SCRIPT_NONE; + this->value_.type = game::VAR_UNDEFINED; } } } diff --git a/src/client/game/scripting/variable_value.hpp b/src/client/game/scripting/variable_value.hpp index 7a962612..af533ee5 100644 --- a/src/client/game/scripting/variable_value.hpp +++ b/src/client/game/scripting/variable_value.hpp @@ -22,6 +22,6 @@ namespace scripting void assign(const game::VariableValue& value); void release(); - game::VariableValue value_{{0}, game::SCRIPT_NONE}; + game::VariableValue value_{{0}, game::VAR_UNDEFINED}; }; } diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index 67bb8fe7..5fb49d9d 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -22,22 +22,6 @@ namespace game unsigned short classnum; }; - enum scriptType_e - { - SCRIPT_NONE = 0, - SCRIPT_OBJECT = 1, - SCRIPT_STRING = 2, - SCRIPT_ISTRING = 3, - SCRIPT_VECTOR = 4, - SCRIPT_FLOAT = 5, - SCRIPT_INTEGER = 6, - SCRIPT_END = 8, - SCRIPT_FUNCTION = 9, - SCRIPT_STRUCT = 19, - SCRIPT_ARRAY = 22 - }; - - // recreated from IW6 pdb and H1 elf (no structs :/) enum VariableType { VAR_UNDEFINED = 0x0,