cleanup
This commit is contained in:
parent
d745e9df04
commit
79ce249c2f
@ -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");
|
||||
}
|
||||
|
@ -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<game::scr_string_t>(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<scripting::function>().get_name();
|
||||
default:
|
||||
return utils::string::va("[%s]", _value.type_name().data());
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<int>(this->id_)});
|
||||
game::AddRefToValue(game::VAR_POINTER, {static_cast<int>(this->id_)});
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ namespace scripting
|
||||
{
|
||||
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];
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ namespace scripting
|
||||
{
|
||||
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_)
|
||||
{
|
||||
game::RemoveRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->entity_id_)});
|
||||
game::RemoveRefToValue(game::VAR_POINTER, {static_cast<int>(this->entity_id_)});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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<int>() 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<float>() 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 char*>() 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<array>() 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<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;
|
||||
}
|
||||
@ -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<function>() 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<entity>() 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<vector>() const
|
||||
{
|
||||
return this->get_raw().type == game::SCRIPT_VECTOR;
|
||||
return this->get_raw().type == game::VAR_VECTOR;
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -14,47 +14,47 @@ namespace scripting
|
||||
|
||||
namespace
|
||||
{
|
||||
std::unordered_map<int, std::string> typenames =
|
||||
std::array<const char*, 27> 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, "<free>"},
|
||||
{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",
|
||||
"<free>",
|
||||
"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];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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};
|
||||
};
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user