Skip to content

Commit

Permalink
gameevent: trying to fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelIT7 committed Nov 25, 2024
1 parent 9809ba8 commit bab500a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
5 changes: 0 additions & 5 deletions source/modules/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,6 @@ static void ReadSearchCache()
g_pAbsoluteSearchCache[pathStr] = absolutePathStr;
}

/*for (auto& [key, val] : g_pAbsoluteSearchCache)
{
Msg("Key: %s\nValue: %s\n", key.data(), val.data());
}*/

//if (g_pFileSystemModule.InDebug())
Msg("holylib - filesystem: Loaded searchcache file (%i)\n", searchCache->usedPaths);
delete searchCache;
Expand Down
46 changes: 37 additions & 9 deletions source/modules/gameevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,30 @@ void CGameeventLibModule::Init(CreateInterfaceFn* appfn, CreateInterfaceFn* game
void CGameeventLibModule::LuaInit(bool bServerInit)
{
if (bServerInit)
{
if (Util::PushTable("gameevent"))
{
g_Lua->GetField(-1, "Listen");
if (g_Lua->IsType(-1, GarrysMod::Lua::Type::Function))
{
g_Lua->PushString("vote_cast"); // Yes this is a valid gameevent.
g_Lua->CallFunctionProtected(1, 0, true);
CGameEventDescriptor* descriptor = pManager->GetEventDescriptor("vote_cast");
FOR_EACH_VEC(descriptor->listeners, i)
{
pLuaGameEventListener = (IGameEventListener2*)descriptor->listeners[i]->m_pCallback;
descriptor->listeners.Remove(i); // We also remove the listener again
break;
}
if (!pLuaGameEventListener)
Warning("holylib: Failed to find pLuaGameEventListener!\n");
} else {
g_Lua->Pop(1);
}
}
Util::PopTable();
return;
}

IGameEvent_TypeID = g_Lua->CreateMetaTable("IGameEvent");
Util::AddFunc(IGameEvent__tostring, "__tostring");
Expand Down Expand Up @@ -616,17 +639,22 @@ void CGameeventLibModule::LuaInit(bool bServerInit)
Util::AddFunc(gameevent_BlockCreation, "BlockCreation");

g_Lua->GetField(-1, "Listen");
g_Lua->PushString("vote_cast"); // Yes this is a valid gameevent.
g_Lua->CallFunctionProtected(1, 0, true);
CGameEventDescriptor* descriptor = pManager->GetEventDescriptor("vote_cast");
FOR_EACH_VEC(descriptor->listeners, i)
if (g_Lua->IsType(-1, GarrysMod::Lua::Type::Function))
{
pLuaGameEventListener = (IGameEventListener2*)descriptor->listeners[i]->m_pCallback;
descriptor->listeners.Remove(i); // We also remove the listener again
break;
g_Lua->PushString("vote_cast"); // Yes this is a valid gameevent.
g_Lua->CallFunctionProtected(1, 0, true);
CGameEventDescriptor* descriptor = pManager->GetEventDescriptor("vote_cast");
FOR_EACH_VEC(descriptor->listeners, i)
{
pLuaGameEventListener = (IGameEventListener2*)descriptor->listeners[i]->m_pCallback;
descriptor->listeners.Remove(i); // We also remove the listener again
break;
}
if (!pLuaGameEventListener)
Warning("holylib: Failed to find pLuaGameEventListener!\n");
} else {
g_Lua->Pop(1);
}
if (!pLuaGameEventListener)
Warning("holylib: Failed to find pLuaGameEventListener!\n");
}
Util::PopTable();
}
Expand Down

0 comments on commit bab500a

Please sign in to comment.