Skip to content

Commit b603dc4

Browse files
committed
feat(scripting/gameevents): AllPluginsLoaded
1 parent 59ef159 commit b603dc4

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

docgen/data/data.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,15 @@
12071207
"params": {},
12081208
"additional": {}
12091209
},
1210+
"allpluginsloaded": {
1211+
"title": "AllPluginsLoaded",
1212+
"template": "event-syntax",
1213+
"language": "both",
1214+
"description": "This game event triggers when all plugins have been loaded.",
1215+
"return": "void",
1216+
"params": {},
1217+
"additional": {}
1218+
},
12101219
"onpluginstop": {
12111220
"title": "OnPluginStop",
12121221
"template": "event-syntax",

plugin_files/scripting/includes/swiftly/gameevents.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void BombDefused(Player *player, unsigned short site) __attribute__((weak));
4242
void BombExploded(Player *player, unsigned short site) __attribute__((weak));
4343
void BombDropped(Player *player) __attribute__((weak));
4444
void BombPickup(Player *player) __attribute__((weak));
45-
45+
void AllPluginsLoaded() __attribute__((weak));
4646
void OnMapLoad(const char *mapName) __attribute__((weak));
4747
void OnMapUnload(const char *mapName) __attribute__((weak));
4848
bool OnClientGameMessage(Player *player, int destination, const char *message) __attribute__((weak));
@@ -75,6 +75,11 @@ extern "C"
7575
if (OnPluginStart)
7676
OnPluginStart();
7777
}
78+
void Internal_AllPluginsLoaded()
79+
{
80+
if (AllPluginsLoaded)
81+
AllPluginsLoaded();
82+
}
7883
void Internal_OnPluginStop()
7984
{
8085
if (OnPluginStop)

src/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define PATH "addons/swiftly"
3535

3636
class CCSGameRules;
37+
class PluginsComponent;
3738

3839
class GameSessionConfiguration_t
3940
{
@@ -76,6 +77,7 @@ class SwiftlyPlugin : public ISmmPlugin, public IMetamodListener
7677

7778
public:
7879
std::deque<std::function<void()>> m_nextFrame;
80+
bool m_allpluginsloaded = false;
7981
};
8082

8183
class CEntityListener : public IEntityListener

src/components/Plugins/src/Plugin.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ void Plugin::StartPlugin()
3030
}
3131

3232
ExecuteGameEventWithNoReturn(this, "OnPluginStart");
33-
3433
this->SetPluginLoaded(true);
34+
35+
if (g_Plugin.m_allpluginsloaded)
36+
ExecuteGameEventWithNoReturn(this, "AllPluginsLoaded");
3537
}
3638

3739
void Plugin::StopPlugin()

src/components/Plugins/src/PluginsComponent.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,18 @@ void PluginsComponent::LoadPlugin(std::string init_path, std::string dir)
6363
}
6464
}
6565

66+
template <typename... Args>
67+
void ExecuteGameEventWithNoReturn(Plugin *plugin, std::string game_event_name, Args &&...args);
68+
6669
void PluginsComponent::StartPlugins()
6770
{
6871
for (uint32 i = 0; i < plugins.size(); i++)
6972
plugins[i]->StartPlugin();
73+
74+
g_Plugin.m_allpluginsloaded = true;
75+
76+
for (uint32 i = 0; i < plugins.size(); i++)
77+
ExecuteGameEventWithNoReturn(plugins[i], "AllPluginsLoaded");
7078
}
7179

7280
std::map<std::string, Plugin *> FetchPluginsMap()

0 commit comments

Comments
 (0)