SP Support

This commit is contained in:
Federico Cecchetto
2022-06-10 18:54:34 +02:00
parent f05fdd33e9
commit 97e39635e0
11 changed files with 293 additions and 148 deletions

View File

@ -4,6 +4,57 @@
namespace scripting
{
namespace
{
std::vector<script_value> get_keys_sp(unsigned int id)
{
std::vector<script_value> result;
auto current = game::scr_VarGlob->variableList_sp[id + 1].nextSibling;
while (current)
{
const auto var = &game::scr_VarGlob->variableList_sp[current + 0x6000];
const auto key_value = game::Scr_GetArrayIndexValue(game::SCRIPTINSTANCE_SERVER, var->w.status >> 8);
result.push_back(key_value);
const auto next_sibling = game::scr_VarGlob->variableList_sp[current + 0x6000].nextSibling;
if (!next_sibling)
{
break;
}
current = static_cast<unsigned __int16>(game::scr_VarGlob->variableList_sp[next_sibling + 0x6000].id);
}
return result;
}
std::vector<script_value> get_keys_mp(unsigned int id)
{
std::vector<script_value> result;
auto current = game::scr_VarGlob->variableList_mp[id + 1].nextSibling;
while (current)
{
const auto var = &game::scr_VarGlob->variableList_mp[current + 0x8000];
const auto key_value = game::Scr_GetArrayIndexValue(game::SCRIPTINSTANCE_SERVER, var->w.status >> 8);
result.push_back(key_value);
const auto next_sibling = game::scr_VarGlob->variableList_mp[current + 0x8000].nextSibling;
if (!next_sibling)
{
break;
}
current = game::scr_VarGlob->variableList_mp[next_sibling + 0x8000].hash.id;
}
return result;
}
}
array_value::array_value(unsigned int parent_id, unsigned int id)
: id_(id)
, parent_id_(parent_id)
@ -13,12 +64,22 @@ namespace scripting
return;
}
const auto value = game::scr_VarGlob->variableList[this->id_];
game::VariableValue variable{};
variable.u = value.u.u;
variable.type = value.w.type & 0x1F;
game::VariableValue variable_{};
this->value_ = variable;
if (game::environment::is_sp())
{
const auto variable = &game::scr_VarGlob->variableList_sp[this->id_ + 0x6000];
variable_.type = variable->w.type & 0x1F;
variable_.u = variable->u.u;
}
else
{
const auto variable = &game::scr_VarGlob->variableList_mp[this->id_ + 0x8000];
variable_.type = variable->w.type & 0x1F;
variable_.u = variable->u.u;
}
this->value_ = variable_;
}
void array_value::operator=(const script_value& value)
@ -30,16 +91,29 @@ namespace scripting
const auto& value_0 = value.get_raw();
const auto variable = &game::scr_VarGlob->variableList[this->id_];
game::VariableValue variable_{};
variable_.type = variable->w.type & 0x1F;
variable_.u = variable->u.u;
game::VariableValue previous{};
if (game::environment::is_sp())
{
const auto variable = &game::scr_VarGlob->variableList_sp[this->id_ + 0x6000];
previous.type = variable->w.type & 0x1F;
previous.u = variable->u.u;
variable->w.type |= value_0.type;
variable->u.u = value_0.u;
}
else
{
const auto variable = &game::scr_VarGlob->variableList_mp[this->id_ + 0x8000];
previous.type = variable->w.type & 0x1F;
previous.u = variable->u.u;
variable->w.type |= value_0.type;
variable->u.u = value_0.u;
}
game::AddRefToValue(game::SCRIPTINSTANCE_SERVER, &value_0);
game::RemoveRefToValue(game::SCRIPTINSTANCE_SERVER, variable_.type, variable_.u);
variable->w.type = value_0.type & 0x1F;
variable->u.u = value_0.u;
game::RemoveRefToValue(game::SCRIPTINSTANCE_SERVER, previous.type, previous.u);
this->value_ = value_0;
}
@ -121,26 +195,7 @@ namespace scripting
std::vector<script_value> array::get_keys() const
{
std::vector<script_value> result;
auto current = game::scr_VarGlob->variableList[this->id_ + 1].nextSibling;
while (current)
{
const auto var = &game::scr_VarGlob->variableList[current + 0x8000];
const auto key_value = game::Scr_GetArrayIndexValue(game::SCRIPTINSTANCE_SERVER, var->w.status >> 8);
result.push_back(key_value);
const auto next_sibling = game::scr_VarGlob->variableList[current + 0x8000].nextSibling;
if (!next_sibling)
{
break;
}
current = game::scr_VarGlob->variableList[next_sibling + 0x8000].hash.id;
}
return result;
return SELECT_VALUE(get_keys_sp, get_keys_mp)(this->id_);
}
int array::size() const
@ -190,12 +245,22 @@ namespace scripting
return {};
}
const auto value = game::scr_VarGlob->variableList[variable_id + 0x8000];
game::VariableValue variable{};
variable.u = value.u.u;
variable.type = value.w.type & 0x1F;
game::VariableValue variable_{};
return variable;
if (game::environment::is_sp())
{
const auto variable = &game::scr_VarGlob->variableList_sp[variable_id + 0x6000];
variable_.type = variable->w.type & 0x1F;
variable_.u = variable->u.u;
}
else
{
const auto variable = &game::scr_VarGlob->variableList_mp[variable_id + 0x8000];
variable_.type = variable->w.type & 0x1F;
variable_.u = variable->u.u;
}
return variable_;
}
script_value array::get(const unsigned int index) const
@ -207,12 +272,22 @@ namespace scripting
return {};
}
const auto value = game::scr_VarGlob->variableList[variable_id + 0x8000];
game::VariableValue variable{};
variable.u = value.u.u;
variable.type = value.w.type & 0x1F;
game::VariableValue variable_{};
return variable;
if (game::environment::is_sp())
{
const auto variable = &game::scr_VarGlob->variableList_sp[variable_id + 0x6000];
variable_.type = variable->w.type & 0x1F;
variable_.u = variable->u.u;
}
else
{
const auto variable = &game::scr_VarGlob->variableList_mp[variable_id + 0x8000];
variable_.type = variable->w.type & 0x1F;
variable_.u = variable->u.u;
}
return variable_;
}
script_value array::get(const script_value& key) const
@ -240,16 +315,29 @@ namespace scripting
return;
}
const auto variable = &game::scr_VarGlob->variableList[variable_id + 0x8000];
game::VariableValue variable_{};
variable_.type = variable->w.type & 0x1F;
variable_.u = variable->u.u;
game::VariableValue previous{};
if (game::environment::is_sp())
{
const auto variable = &game::scr_VarGlob->variableList_sp[variable_id + 0x6000];
previous.type = variable->w.type & 0x1F;
previous.u = variable->u.u;
variable->w.type |= value_.type;
variable->u.u = value_.u;
}
else
{
const auto variable = &game::scr_VarGlob->variableList_mp[variable_id + 0x8000];
previous.type = variable->w.type & 0x1F;
previous.u = variable->u.u;
variable->w.type |= value_.type;
variable->u.u = value_.u;
}
game::AddRefToValue(game::SCRIPTINSTANCE_SERVER, &value_);
game::RemoveRefToValue(game::SCRIPTINSTANCE_SERVER, variable_.type, variable_.u);
variable->w.type |= value_.type;
variable->u.u = value_.u;
game::RemoveRefToValue(game::SCRIPTINSTANCE_SERVER, previous.type, previous.u);
}
void array::set(const unsigned int index, const script_value& value) const
@ -262,17 +350,29 @@ namespace scripting
return;
}
auto variable_list = *game::scr_VarGlob;
const auto variable = &game::scr_VarGlob->variableList[variable_id + 0x8000];
game::VariableValue variable_{};
variable_.type = variable->w.type & 0x1F;
variable_.u = variable->u.u;
game::VariableValue previous{};
if (game::environment::is_sp())
{
const auto variable = &game::scr_VarGlob->variableList_sp[variable_id + 0x6000];
previous.type = variable->w.type & 0x1F;
previous.u = variable->u.u;
variable->w.type |= value_.type;
variable->u.u = value_.u;
}
else
{
const auto variable = &game::scr_VarGlob->variableList_mp[variable_id + 0x8000];
previous.type = variable->w.type & 0x1F;
previous.u = variable->u.u;
variable->w.type |= value_.type;
variable->u.u = value_.u;
}
game::AddRefToValue(game::SCRIPTINSTANCE_SERVER, &value_);
game::RemoveRefToValue(game::SCRIPTINSTANCE_SERVER, variable_.type, variable_.u);
variable->w.type |= value_.type;
variable->u.u = value_.u;
game::RemoveRefToValue(game::SCRIPTINSTANCE_SERVER, previous.type, previous.u);
}
void array::set(const script_value& key, const script_value& _value) const

View File

@ -149,12 +149,6 @@ namespace scripting
unsigned int make_object()
{
unsigned int index = 0;
const auto id = game::AllocVariable(game::SCRIPTINSTANCE_SERVER);
const auto variable = &game::scr_VarGlob->variableList[id + 1];
variable->w.type = game::SCRIPT_STRUCT;
variable->u.o.refCount = 0;
return index;
return 0;
}
}

View File

@ -258,7 +258,7 @@ namespace scripting
}
const auto id = this->get_raw().u.uintValue;
const auto type = game::scr_VarGlob->variableList[id + 1].w.type & 0x1F;
const auto type = game::GetObjectType(game::SCRIPTINSTANCE_SERVER, id);
return type == game::SCRIPT_ARRAY;
}
@ -282,7 +282,7 @@ namespace scripting
}
const auto id = this->get_raw().u.uintValue;
const auto type = game::scr_VarGlob->variableList[id + 1].w.type & 0x1F;
const auto type = game::GetObjectType(game::SCRIPTINSTANCE_SERVER, id);
return type == game::SCRIPT_STRUCT || type == game::SCRIPT_ENTITY;
}

View File

@ -46,7 +46,7 @@ namespace scripting
auto type_ = 0;
if (value.type == game::SCRIPT_OBJECT)
{
type_ = game::scr_VarGlob->variableList[value.u.uintValue].w.type & 0x1F;
type_ = game::GetObjectType(game::SCRIPTINSTANCE_SERVER, value.u.uintValue);
}
else
{

View File

@ -7,7 +7,7 @@ namespace scripting
{
thread::thread(unsigned int id)
: id_(id)
, type_(game::scr_VarGlob->variableList[id].w.type & 0x7F)
, type_(game::GetObjectType(game::SCRIPTINSTANCE_SERVER, id))
{
}
@ -32,12 +32,12 @@ namespace scripting
unsigned int thread::get_wait_time() const
{
return game::scr_VarGlob->variableList[this->id_].w.waitTime >> 8;
return 0;
}
unsigned int thread::get_notify_name_id() const
{
return game::scr_VarGlob->variableList[this->id_].w.notifyName >> 8;
return 0;
}
unsigned int thread::get_self() const