Skip to content

Commit

Permalink
[Repentogon] Proof of stack balancing in DumpRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylmir committed Nov 6, 2024
1 parent 2cc4d34 commit fead992
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions repentogon/LuaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ static void RegisterMetatables(lua_State* L) {
std::map<std::string, void*> metatables;

while (lua_next(L, LUA_REGISTRYINDEX)) {
if (lua_type(L, -2) == LUA_TLIGHTUSERDATA) {
if (lua_type(L, -1) == LUA_TTABLE) {
lua_pushstring(L, "__type");
int __type = lua_rawget(L, -2);
if (lua_type(L, -2) == LUA_TLIGHTUSERDATA) { // key value
if (lua_type(L, -1) == LUA_TTABLE) { // key value
lua_pushstring(L, "__type"); // key value (table) __type
int __type = lua_rawget(L, -2); // key table table["__type"]

if (__type == LUA_TSTRING) {
std::string type(lua_tostring(L, -1));
void* addr = lua_touserdata(L, -3);

if (type == "Room" || type == "const Room") {
lua_pushstring(L, "GetBossID");
int bossID = lua_rawget(L, -3);
lua_pushstring(L, "GetBossID"); // key table table["__type"] GetBossID
int bossID = lua_rawget(L, -3); // key table table["__type"] table["GetBossID"]

if (bossID == LUA_TNIL) {
if (type.find("const") != std::string::npos) {
Expand All @@ -136,7 +136,7 @@ static void RegisterMetatables(lua_State* L) {
}
}

lua_pop(L, 1);
lua_pop(L, 1); // key table table["__type"]
}
else if (type == "RoomDescriptor" || type == "const RoomDescriptor") {
lua_pushstring(L, "Get");
Expand All @@ -158,11 +158,11 @@ static void RegisterMetatables(lua_State* L) {
ExtractGameFunctions(L, _functions[type.c_str()], logger.GetFile());
}

lua_pop(L, 1);
lua_pop(L, 1); // key table
}
}

lua_pop(L, 1);
lua_pop(L, 1); // key
}

logger.Log("Done dumping Lua registry\n");
Expand Down

0 comments on commit fead992

Please sign in to comment.