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
enum class CCObjectType {
// please someone tell we why in higher being(s)'s name rob did this
enum class CCObjectType {
PlayLayer = 5,
LevelEditorLayer = 6,
GameObject = 13,
MenuLayer = 15,
};
)
};
class CCZone;
class CCObject;

View file

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