This commit is contained in:
m 2022-11-03 12:43:50 -05:00
parent 4ff0b521c9
commit 199b5f711d
15 changed files with 79 additions and 95 deletions

View File

@ -427,7 +427,7 @@ namespace gsc
const auto what = args[0].get_raw(); const auto what = args[0].get_raw();
const auto with = args[1].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"); throw std::runtime_error("replaceFunc: parameter 1 must be a function");
} }

View File

@ -66,32 +66,32 @@ namespace json
switch (type) switch (type)
{ {
case (game::SCRIPT_NONE): case (game::VAR_UNDEFINED):
return {}; return {};
case (game::SCRIPT_INTEGER): case (game::VAR_INTEGER):
return value.intValue; return value.intValue;
case (game::SCRIPT_FLOAT): case (game::VAR_FLOAT):
return value.floatValue; return value.floatValue;
case (game::SCRIPT_STRING): case (game::VAR_STRING):
case (game::SCRIPT_ISTRING): case (game::VAR_ISTRING):
return game::SL_ConvertToString(static_cast<game::scr_string_t>(value.stringValue)); return game::SL_ConvertToString(static_cast<game::scr_string_t>(value.stringValue));
case (game::SCRIPT_VECTOR): case (game::VAR_VECTOR):
return vector_to_array(value.vectorValue); 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; const auto object_type = game::scr_VarGlob->objectVariableValue[value.uintValue].w.type;
switch (object_type) switch (object_type)
{ {
case (game::SCRIPT_STRUCT): case (game::VAR_OBJECT):
return "[struct]"; return "[struct]";
case (game::SCRIPT_ARRAY): case (game::VAR_ARRAY):
return entity_to_array(value.uintValue); return entity_to_array(value.uintValue);
default: default:
return "[entity]"; return "[entity]";
} }
} }
case (game::SCRIPT_FUNCTION): case (game::VAR_FUNCTION):
return _value.as<scripting::function>().get_name(); return _value.as<scripting::function>().get_name();
default: default:
return utils::string::va("[%s]", _value.type_name().data()); return utils::string::va("[%s]", _value.type_name().data());

View File

@ -196,7 +196,7 @@ namespace logfile
const auto top = game::scr_function_stack->top; 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)); args.push_back(scripting::lua::convert(state, *value));
} }

View File

@ -67,7 +67,7 @@ namespace scripting
e.name = string; e.name = string;
e.entity = notify_list_owner_id; 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); e.arguments.emplace_back(*value);
} }

View File

@ -17,7 +17,7 @@ namespace scripting
const auto value = game::scr_VarGlob->childVariableValue[this->id_ + 0xFA00 * (this->parent_id_ & 3)]; const auto value = game::scr_VarGlob->childVariableValue[this->id_ + 0xFA00 * (this->parent_id_ & 3)];
game::VariableValue variable; game::VariableValue variable;
variable.u = value.u.u; variable.u = value.u.u;
variable.type = (game::scriptType_e)value.type; variable.type = value.type;
this->value_ = variable; this->value_ = variable;
} }
@ -115,7 +115,7 @@ namespace scripting
{ {
if (this->id_) if (this->id_)
{ {
game::AddRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->id_)}); game::AddRefToValue(game::VAR_POINTER, {static_cast<int>(this->id_)});
} }
} }
@ -123,7 +123,7 @@ namespace scripting
{ {
if (this->id_) if (this->id_)
{ {
game::RemoveRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->id_)}); game::RemoveRefToValue(game::VAR_POINTER, {static_cast<int>(this->id_)});
} }
} }
@ -138,7 +138,7 @@ namespace scripting
{ {
const auto var = game::scr_VarGlob->childVariableValue[i]; const auto var = game::scr_VarGlob->childVariableValue[i];
if (var.type == game::SCRIPT_NONE) if (var.type == game::VAR_UNDEFINED)
{ {
current = var.nextSibling; current = var.nextSibling;
continue; continue;
@ -227,7 +227,7 @@ namespace scripting
const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xFA00 * (this->id_ & 3)]; const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xFA00 * (this->id_ & 3)];
game::VariableValue variable; game::VariableValue variable;
variable.u = value.u.u; variable.u = value.u.u;
variable.type = (game::scriptType_e)value.type; variable.type = value.type;
return variable; return variable;
} }
@ -244,7 +244,7 @@ namespace scripting
const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xFA00 * (this->id_ & 3)]; const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xFA00 * (this->id_ & 3)];
game::VariableValue variable; game::VariableValue variable;
variable.u = value.u.u; variable.u = value.u.u;
variable.type = (game::scriptType_e)value.type; variable.type = value.type;
return variable; return variable;
} }

View File

@ -90,7 +90,7 @@ namespace scripting
{ {
if (this->entity_id_) if (this->entity_id_)
{ {
game::AddRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->entity_id_)}); game::AddRefToValue(game::VAR_POINTER, {static_cast<int>(this->entity_id_)});
} }
} }
@ -98,7 +98,7 @@ namespace scripting
{ {
if (this->entity_id_) if (this->entity_id_)
{ {
game::RemoveRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->entity_id_)}); game::RemoveRefToValue(game::VAR_POINTER, {static_cast<int>(this->entity_id_)});
} }
} }

View File

@ -199,7 +199,7 @@ namespace scripting
{ {
unsigned int index = 0; unsigned int index = 0;
const auto variable = game::AllocVariable(&index); 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.prev = 0;
variable->u.f.next = 0; variable->u.f.next = 0;

View File

@ -15,7 +15,7 @@ namespace scripting
script_value function::get_raw() const script_value function::get_raw() const
{ {
game::VariableValue value; game::VariableValue value;
value.type = game::SCRIPT_FUNCTION; value.type = game::VAR_FUNCTION;
value.u.codePosValue = this->pos_; value.u.codePosValue = this->pos_;
return value; return value;

View File

@ -30,7 +30,7 @@ namespace scripting::lua
{ {
const auto var = game::scr_VarGlob->childVariableValue[i]; const auto var = game::scr_VarGlob->childVariableValue[i];
if (var.type == game::SCRIPT_NONE) if (var.type == game::VAR_UNDEFINED)
{ {
current = var.nextSibling; current = var.nextSibling;
continue; continue;
@ -124,7 +124,7 @@ namespace scripting::lua
logfile::set_lua_hook(index, function); logfile::set_lua_hook(index, function);
game::VariableValue func{}; game::VariableValue func{};
func.type = game::SCRIPT_FUNCTION; func.type = game::VAR_FUNCTION;
func.u.codePosValue = index; func.u.codePosValue = index;
return func; return func;

View File

@ -56,7 +56,7 @@ namespace scripting::safe_execution
*game::g_script_error_level += 1; *game::g_script_error_level += 1;
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level])) 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; value->u.intValue = 0;
*game::g_script_error_level -= 1; *game::g_script_error_level -= 1;
return false; return false;

View File

@ -23,7 +23,7 @@ namespace scripting
script_value::script_value(const int value) script_value::script_value(const int value)
{ {
game::VariableValue variable{}; game::VariableValue variable{};
variable.type = game::SCRIPT_INTEGER; variable.type = game::VAR_INTEGER;
variable.u.intValue = value; variable.u.intValue = value;
this->value_ = variable; this->value_ = variable;
@ -32,7 +32,7 @@ namespace scripting
script_value::script_value(const unsigned int value) script_value::script_value(const unsigned int value)
{ {
game::VariableValue variable{}; game::VariableValue variable{};
variable.type = game::SCRIPT_INTEGER; variable.type = game::VAR_INTEGER;
variable.u.uintValue = value; variable.u.uintValue = value;
this->value_ = variable; this->value_ = variable;
@ -46,7 +46,7 @@ namespace scripting
script_value::script_value(const float value) script_value::script_value(const float value)
{ {
game::VariableValue variable{}; game::VariableValue variable{};
variable.type = game::SCRIPT_FLOAT; variable.type = game::VAR_FLOAT;
variable.u.floatValue = value; variable.u.floatValue = value;
this->value_ = variable; this->value_ = variable;
@ -60,7 +60,7 @@ namespace scripting
script_value::script_value(const char* value) script_value::script_value(const char* value)
{ {
game::VariableValue variable{}; game::VariableValue variable{};
variable.type = game::SCRIPT_STRING; variable.type = game::VAR_STRING;
variable.u.stringValue = game::SL_GetString(value, 0); variable.u.stringValue = game::SL_GetString(value, 0);
const auto _ = gsl::finally([&variable]() const auto _ = gsl::finally([&variable]()
@ -79,7 +79,7 @@ namespace scripting
script_value::script_value(const entity& value) script_value::script_value(const entity& value)
{ {
game::VariableValue variable{}; game::VariableValue variable{};
variable.type = game::SCRIPT_OBJECT; variable.type = game::VAR_POINTER;
variable.u.pointerValue = value.get_entity_id(); variable.u.pointerValue = value.get_entity_id();
this->value_ = variable; this->value_ = variable;
@ -88,7 +88,7 @@ namespace scripting
script_value::script_value(const array& value) script_value::script_value(const array& value)
{ {
game::VariableValue variable{}; game::VariableValue variable{};
variable.type = game::SCRIPT_OBJECT; variable.type = game::VAR_POINTER;
variable.u.pointerValue = value.get_entity_id(); variable.u.pointerValue = value.get_entity_id();
this->value_ = variable; this->value_ = variable;
@ -97,7 +97,7 @@ namespace scripting
script_value::script_value(const function& value) script_value::script_value(const function& value)
{ {
game::VariableValue variable{}; game::VariableValue variable{};
variable.type = game::SCRIPT_FUNCTION; variable.type = game::VAR_FUNCTION;
variable.u.codePosValue = value.get_pos(); variable.u.codePosValue = value.get_pos();
this->value_ = variable; this->value_ = variable;
@ -106,7 +106,7 @@ namespace scripting
script_value::script_value(const vector& value) script_value::script_value(const vector& value)
{ {
game::VariableValue variable{}; game::VariableValue variable{};
variable.type = game::SCRIPT_VECTOR; variable.type = game::VAR_VECTOR;
variable.u.vectorValue = game::Scr_AllocVector(value); variable.u.vectorValue = game::Scr_AllocVector(value);
const auto _ = gsl::finally([&variable]() const auto _ = gsl::finally([&variable]()
@ -124,7 +124,7 @@ namespace scripting
template <> template <>
bool script_value::is<int>() const bool script_value::is<int>() const
{ {
return this->get_raw().type == game::SCRIPT_INTEGER; return this->get_raw().type == game::VAR_INTEGER;
} }
template <> template <>
@ -164,7 +164,7 @@ namespace scripting
template <> template <>
bool script_value::is<float>() const bool script_value::is<float>() const
{ {
return this->get_raw().type == game::SCRIPT_FLOAT; return this->get_raw().type == game::VAR_FLOAT;
} }
template <> template <>
@ -192,7 +192,7 @@ namespace scripting
template <> template <>
bool script_value::is<const char*>() const bool script_value::is<const char*>() const
{ {
return this->get_raw().type == game::SCRIPT_STRING; return this->get_raw().type == game::VAR_STRING;
} }
template <> template <>
@ -220,7 +220,7 @@ namespace scripting
template <> template <>
bool script_value::is<array>() const bool script_value::is<array>() const
{ {
if (this->get_raw().type != game::SCRIPT_OBJECT) if (this->get_raw().type != game::VAR_POINTER)
{ {
return false; return false;
} }
@ -228,7 +228,7 @@ namespace scripting
const auto id = this->get_raw().u.uintValue; const auto id = this->get_raw().u.uintValue;
const auto type = game::scr_VarGlob->objectVariableValue[id].w.type; const auto type = game::scr_VarGlob->objectVariableValue[id].w.type;
return type == game::SCRIPT_ARRAY; return type == game::VAR_ARRAY;
} }
template <> template <>
@ -244,7 +244,7 @@ namespace scripting
template <> template <>
bool script_value::is<std::map<std::string, script_value>>() const bool script_value::is<std::map<std::string, script_value>>() const
{ {
if (this->get_raw().type != game::SCRIPT_OBJECT) if (this->get_raw().type != game::VAR_POINTER)
{ {
return false; return false;
} }
@ -252,7 +252,7 @@ namespace scripting
const auto id = this->get_raw().u.uintValue; const auto id = this->get_raw().u.uintValue;
const auto type = game::scr_VarGlob->objectVariableValue[id].w.type; 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 <> template <>
bool script_value::is<function>() const bool script_value::is<function>() const
{ {
return this->get_raw().type == game::SCRIPT_FUNCTION; return this->get_raw().type == game::VAR_FUNCTION;
} }
template <> template <>
@ -278,7 +278,7 @@ namespace scripting
template <> template <>
bool script_value::is<entity>() const bool script_value::is<entity>() const
{ {
return this->get_raw().type == game::SCRIPT_OBJECT; return this->get_raw().type == game::VAR_POINTER;
} }
template <> template <>
@ -294,7 +294,7 @@ namespace scripting
template <> template <>
bool script_value::is<vector>() const bool script_value::is<vector>() const
{ {
return this->get_raw().type == game::SCRIPT_VECTOR; return this->get_raw().type == game::VAR_VECTOR;
} }
template <> template <>

View File

@ -14,47 +14,47 @@ namespace scripting
namespace namespace
{ {
std::unordered_map<int, std::string> typenames = std::array<const char*, 27> var_typename =
{ {
{0, "undefined"}, "undefined",
{1, "object"}, "object",
{2, "string"}, "string",
{3, "localized string"}, "localized string",
{4, "vector"}, "vector",
{5, "float"}, "float",
{6, "int"}, "int",
{7, "codepos"}, "codepos",
{8, "precodepos"}, "precodepos",
{9, "function"}, "function",
{10, "builtin function"}, "builtin function",
{11, "builtin method"}, "builtin method",
{12, "stack"}, "stack",
{13, "animation"}, "animation",
{14, "pre animation"}, "pre animation",
{15, "thread"}, "thread",
{16, "notify thread"}, "thread",
{17, "time thread"}, "thread",
{18, "child thread"}, "thread",
{19, "struct"}, "struct",
{20, "removed entity"}, "removed entity",
{21, "entity"}, "entity",
{22, "array"}, "array",
{23, "removed thread"}, "removed thread",
{24, "<free>"}, "<free>",
{25, "thread list"}, "thread list",
{26, "endon list"}, "endon list",
}; };
std::string get_typename(const game::VariableValue& value) 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; const auto type = game::scr_VarGlob->objectVariableValue[value.u.uintValue].w.type;
return typenames[type]; return var_typename[type];
} }
else else
{ {
return typenames[value.type]; return var_typename[value.type];
} }
} }

View File

@ -35,7 +35,7 @@ namespace scripting
{ {
this->release(); this->release();
this->value_ = other.value_; this->value_ = other.value_;
other.value_.type = game::SCRIPT_NONE; other.value_.type = game::VAR_UNDEFINED;
} }
return *this; return *this;
@ -59,10 +59,10 @@ namespace scripting
void variable_value::release() 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); game::RemoveRefToValue(this->value_.type, this->value_.u);
this->value_.type = game::SCRIPT_NONE; this->value_.type = game::VAR_UNDEFINED;
} }
} }
} }

View File

@ -22,6 +22,6 @@ namespace scripting
void assign(const game::VariableValue& value); void assign(const game::VariableValue& value);
void release(); void release();
game::VariableValue value_{{0}, game::SCRIPT_NONE}; game::VariableValue value_{{0}, game::VAR_UNDEFINED};
}; };
} }

View File

@ -22,22 +22,6 @@ namespace game
unsigned short classnum; 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 enum VariableType
{ {
VAR_UNDEFINED = 0x0, VAR_UNDEFINED = 0x0,