Add custom entity field support

This commit is contained in:
Federico Cecchetto
2021-11-07 23:42:56 +01:00
parent 7526de9b76
commit eee68760e4
7 changed files with 176 additions and 37 deletions

View File

@ -129,9 +129,9 @@ namespace scripting
}
}
std::vector<array_key> array::get_keys() const
std::vector<script_value> array::get_keys() const
{
std::vector<array_key> result;
std::vector<script_value> result;
const auto offset = 0xC800 * (this->id_ & 1);
auto current = game::scr_VarGlob->objectVariableChildren[this->id_].firstChild;
@ -149,16 +149,14 @@ namespace scripting
const auto string_value = (unsigned int)((unsigned __int8)var.name_lo + (var.k.keys.name_hi << 8));
const auto* str = game::SL_ConvertToString(string_value);
array_key key;
script_value key;
if (string_value < 0x40000 && str)
{
key.is_string = true;
key.key = str;
key = str;
}
else
{
key.is_integer = true;
key.index = (string_value - 0x800000) & 0xFFFFFF;
key = (string_value - 0x800000) & 0xFFFFFF;
}
result.push_back(key);
@ -206,16 +204,18 @@ namespace scripting
return value;
}
script_value array::get(const array_key& key) const
script_value array::get(const script_value& key) const
{
if (key.is_integer)
if (key.is<int>())
{
return this->get(key.index);
return this->get(key.as<int>());
}
else
{
return this->get(key.key);
return this->get(key.as<std::string>());
}
return {};
}
script_value array::get(const std::string& key) const
@ -253,15 +253,15 @@ namespace scripting
return variable;
}
void array::set(const array_key& key, const script_value& value) const
void array::set(const script_value& key, const script_value& value) const
{
if (key.is_integer)
if (key.is<int>())
{
this->set(key.index, value);
this->set(key.as<int>(), value);
}
else
{
this->set(key.key, value);
this->set(key.as<std::string>(), value);
}
}

View File

@ -3,14 +3,6 @@
namespace scripting
{
struct array_key
{
bool is_string = false;
bool is_integer = false;
unsigned int index{};
std::string key{};
};
class array_value : public script_value
{
public:
@ -38,7 +30,7 @@ namespace scripting
array& operator=(const array& other);
array& operator=(array&& other) noexcept;
std::vector<array_key> get_keys() const;
std::vector<script_value> get_keys() const;
unsigned int size() const;
unsigned int push(script_value) const;
@ -46,11 +38,11 @@ namespace scripting
void erase(const std::string&) const;
script_value pop() const;
script_value get(const array_key&) const;
script_value get(const script_value&) const;
script_value get(const std::string&) const;
script_value get(const unsigned int) const;
void set(const array_key&, const script_value&) const;
void set(const script_value&, const script_value&) const;
void set(const std::string&, const script_value&) const;
void set(const unsigned int, const script_value&) const;
@ -71,15 +63,17 @@ namespace scripting
return {this->id_, this->get_value_id(key)};
}
array_value operator[](const array_key& key) const
template <typename I = int, typename S = std::string>
array_value operator[](const script_value& key) const
{
if (key.is_integer)
if (key.is<I>())
{
return {this->id_, this->get_value_id(key.index)};
return { this->id_, this->get_value_id(key.as<I>()) };
}
else
if (key.is<S>())
{
return {this->id_, this->get_value_id(key.key)};
return { this->id_, this->get_value_id(key.as<S>()) };
}
}

View File

@ -314,7 +314,7 @@ namespace game
struct gclient_s
{
playerState_s ps;
char __pad0[0x2ED];
char __pad0[0x2CC];
int flags;
};

View File

@ -49,8 +49,10 @@ namespace game
WEAK symbol<unsigned int(unsigned int threadId)> Scr_GetSelf{0x5655E0};
WEAK symbol<void()> Scr_MakeArray{0x56ADE0};
WEAK symbol<void(unsigned int stringValue)> Scr_AddArrayStringIndexed{0x56AE70};
WEAK symbol<void(unsigned int classnum, unsigned int name, unsigned int canonicalString, unsigned int offset)> Scr_AddClassField{0x567CD0};
WEAK symbol<unsigned int(const char* str, unsigned int user)> SL_GetString{0x5649E0};
WEAK symbol<unsigned int(const char* str)> SL_GetCanonicalString{0x5619A0};
WEAK symbol<const char*(unsigned int stringValue)> SL_ConvertToString{0x564270};
WEAK symbol<void(int clientNum, int type, const char* command)> SV_GameSendServerCommand{0x573220};
@ -81,5 +83,6 @@ namespace game
{
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> function_map_rev{0x20691228};
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> method_map_rev{0x20691248};
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> token_map_rev{0x20691288};
}
}