diff --git a/loader/include/Geode/loader/ModEvent.hpp b/loader/include/Geode/loader/ModEvent.hpp index e77f11e2..e8b66f51 100644 --- a/loader/include/Geode/loader/ModEvent.hpp +++ b/loader/include/Geode/loader/ModEvent.hpp @@ -17,6 +17,9 @@ namespace geode { DataSaved, }; + /** + * Event that is fired when a mod is loaded / unloaded / enabled / disabled + */ class GEODE_DLL ModStateEvent : public Event { protected: ModEventType m_type; @@ -28,6 +31,9 @@ namespace geode { Mod* getMod() const; }; + /** + * Listener for mod load/enable/disable/unload/data save events + */ class GEODE_DLL ModStateFilter : public EventFilter { public: using Callback = void(ModStateEvent*); @@ -38,6 +44,13 @@ namespace geode { public: ListenerResult handle(utils::MiniFunction fn, ModStateEvent* event); + + /** + * Create a mod state listener + * @param mod The mod whose events to listen to, or nullptr to listen to + * all mods' all state events + * @param type Type of event to listen to. Ignored if mod is nullptr + */ ModStateFilter(Mod* mod, ModEventType type); }; } diff --git a/loader/src/loader/ModEvent.cpp b/loader/src/loader/ModEvent.cpp index 3f063eba..606cc625 100644 --- a/loader/src/loader/ModEvent.cpp +++ b/loader/src/loader/ModEvent.cpp @@ -13,7 +13,7 @@ Mod* ModStateEvent::getMod() const { } ListenerResult ModStateFilter::handle(utils::MiniFunction fn, ModStateEvent* event) { - if (event->getMod() == m_mod && event->getType() == m_type) { + if (!m_mod || (event->getMod() == m_mod && event->getType() == m_type)) { fn(event); } return ListenerResult::Propagate;