Skip to content

Commit

Permalink
Merge pull request #634 from psiberx/master
Browse files Browse the repository at this point in the history
Stability hotfix for overrides
  • Loading branch information
Yamashi authored Dec 12, 2021
2 parents a11e02f + 4d6025c commit 4ed5744
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 101 deletions.
1 change: 0 additions & 1 deletion src/overlay/widgets/TweakDBEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,6 @@ bool TweakDBEditor::DrawFlatCName(RED4ext::TweakDBID aDBID, RED4ext::CStackType&
{
auto* pCName = static_cast<RED4ext::CName*>(aStackType.value);

ImGui::TextUnformatted("This is not just a string.");
ImGui::TextUnformatted("Game is expecting specific values.");
// Is it worth it to implement a dropdown like DrawTweakDBID?

Expand Down
91 changes: 44 additions & 47 deletions src/reverse/RTTIMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,53 +40,6 @@ void RTTIMapper::Register()
RegisterSpecialAccessors(luaState, luaGlobal);
}

RED4ext::CName TryResolveTypeName(sol::object aValue)
{
if (IsLuaCData(aValue))
return "Uint64";

switch (aValue.get_type())
{
case sol::type::string:
return "String";

case sol::type::boolean:
return "Bool";

// case sol::type::number:
// return "Int32";

case sol::type::userdata:
{
sol::userdata userdata = aValue;
sol::table metatable = userdata[sol::metatable_key];
std::string name = metatable.raw_get_or<std::string>("__name", "");

if (!name.empty())
return name.c_str() + 4;

break;
}

case sol::type::table:
{
sol::table table = aValue;

if (table.size() > 0)
{
RED4ext::CName innerType = TryResolveTypeName(table[1]);

if (!innerType.IsNone())
return std::string("array:").append(innerType.ToString()).c_str();
}

break;
}
}

return RED4ext::CName();
}

void RTTIMapper::RegisterSimpleTypes(sol::state& aLuaState, sol::table& aLuaGlobal)
{
aLuaState.new_usertype<Variant>("Variant",
Expand Down Expand Up @@ -297,3 +250,47 @@ void RTTIMapper::SanitizeName(std::string& aName)
{
std::replace(aName.begin(), aName.end(), '.', '_');
}

RED4ext::CName RTTIMapper::TryResolveTypeName(sol::object aValue)
{
if (IsLuaCData(aValue))
return "Uint64";

switch (aValue.get_type())
{
case sol::type::string:
return "String";

case sol::type::boolean:
return "Bool";

case sol::type::userdata:
{
sol::userdata userdata = aValue;
sol::table metatable = userdata[sol::metatable_key];
std::string name = metatable.raw_get_or<std::string>("__name", "");

if (!name.empty())
return name.c_str() + 4;

break;
}

case sol::type::table:
{
sol::table table = aValue;

if (table.size() > 0)
{
RED4ext::CName innerType = TryResolveTypeName(table[1]);

if (!innerType.IsNone())
return std::string("array:").append(innerType.ToString()).c_str();
}

break;
}
}

return RED4ext::CName();
}
1 change: 1 addition & 0 deletions src/reverse/RTTIMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct RTTIMapper
void Register();

static void SanitizeName(std::string& aName);
static RED4ext::CName TryResolveTypeName(sol::object aValue);

private:

Expand Down
Loading

0 comments on commit 4ed5744

Please sign in to comment.