ensure mod events are only posted in gd thread

This commit is contained in:
HJfod 2023-03-21 22:01:10 +02:00
parent da691652cf
commit 93fd396ed9
2 changed files with 23 additions and 13 deletions

View file

@ -47,14 +47,13 @@ NS_CC_BEGIN
* @{ * @{
*/ */
RT_ADD( // please someone tell we why in higher being(s)'s name rob did this
// please someone tell we why in higher being(s)'s name rob did this enum class CCObjectType {
enum class CCObjectType { PlayLayer = 5,
PlayLayer = 5, LevelEditorLayer = 6,
LevelEditorLayer = 6, GameObject = 13,
MenuLayer = 15, MenuLayer = 15,
}; };
)
class CCZone; class CCZone;
class CCObject; class CCObject;

View file

@ -116,7 +116,9 @@ std::vector<Hook*> Mod::Impl::getHooks() const {
// Settings and saved values // Settings and saved values
Result<> Mod::Impl::loadData() { Result<> Mod::Impl::loadData() {
ModStateEvent(m_self, ModEventType::DataLoaded).post(); Loader::get()->queueInGDThread([&]() {
ModStateEvent(m_self, ModEventType::DataLoaded).post();
});
// Settings // Settings
// Check if settings exist // Check if settings exist
@ -182,6 +184,7 @@ Result<> Mod::Impl::loadData() {
} }
Result<> Mod::Impl::saveData() { Result<> Mod::Impl::saveData() {
// saveData is expected to be synchronous, and always called from GD thread
ModStateEvent(m_self, ModEventType::DataSaved).post(); ModStateEvent(m_self, ModEventType::DataSaved).post();
// Data saving should be fully fail-safe // Data saving should be fully fail-safe
@ -308,7 +311,9 @@ Result<> Mod::Impl::loadBinary() {
LoaderImpl::get()->releaseNextMod(); LoaderImpl::get()->releaseNextMod();
ModStateEvent(m_self, ModEventType::Loaded).post(); Loader::get()->queueInGDThread([&]() {
ModStateEvent(m_self, ModEventType::Loaded).post();
});
Loader::get()->updateAllDependencies(); Loader::get()->updateAllDependencies();
@ -329,7 +334,9 @@ Result<> Mod::Impl::unloadBinary() {
GEODE_UNWRAP(this->saveData()); GEODE_UNWRAP(this->saveData());
GEODE_UNWRAP(this->disable()); GEODE_UNWRAP(this->disable());
ModStateEvent(m_self, ModEventType::Unloaded).post(); Loader::get()->queueInGDThread([&]() {
ModStateEvent(m_self, ModEventType::Unloaded).post();
});
// Disabling unhooks and unpatches already // Disabling unhooks and unpatches already
for (auto const& hook : m_hooks) { for (auto const& hook : m_hooks) {
@ -367,7 +374,9 @@ Result<> Mod::Impl::enable() {
} }
} }
ModStateEvent(m_self, ModEventType::Enabled).post(); Loader::get()->queueInGDThread([&]() {
ModStateEvent(m_self, ModEventType::Enabled).post();
});
m_enabled = true; m_enabled = true;
return Ok(); return Ok();
@ -381,7 +390,9 @@ Result<> Mod::Impl::disable() {
return Err("Mod does not support disabling"); return Err("Mod does not support disabling");
} }
ModStateEvent(m_self, ModEventType::Disabled).post(); Loader::get()->queueInGDThread([&]() {
ModStateEvent(m_self, ModEventType::Disabled).post();
});
for (auto const& hook : m_hooks) { for (auto const& hook : m_hooks) {
GEODE_UNWRAP(this->disableHook(hook)); GEODE_UNWRAP(this->disableHook(hook));