22
33#include < Geode/Geode.hpp>
44#include < Geode/modify/CCObject.hpp>
5+ #include < Geode/modify/CCPoolManager.hpp>
56#include " UIModding.hpp"
67#include " nodes/CCNode.hpp"
78#include " Utils.hpp"
89#include " Macros.hpp"
910
1011using namespace geode ::prelude;
1112
13+ class LateQueue {
14+ protected:
15+ static LateQueue* instance;
16+ public:
17+ std::vector<std::function<void (void )>> m_mainThreadQueue;
18+ mutable std::mutex m_mainThreadMutex;
19+
20+ void queue (ScheduledFunction&& func) {
21+ std::lock_guard<std::mutex> lock (m_mainThreadMutex);
22+ m_mainThreadQueue.push_back (std::forward<ScheduledFunction>(func));
23+ }
24+
25+ void executeQueue () {
26+ m_mainThreadMutex.lock ();
27+ auto queue = m_mainThreadQueue;
28+ m_mainThreadQueue.clear ();
29+ m_mainThreadMutex.unlock ();
30+
31+ for (auto const & func : queue) {
32+ func ();
33+ }
34+ }
35+
36+ static LateQueue* get () {
37+ if (!instance) {
38+ instance = new LateQueue ();
39+ };
40+ return instance;
41+ }
42+ };
43+ LateQueue* LateQueue::instance = nullptr ;
44+
1245class $modify(CCObject) {
1346
1447 CCObject* autorelease () {
1548 auto modding = UIModding::get ();
16- if (modding->doModify ) {
17- if (MyCCNode* node = static_cast <MyCCNode*>(typeinfo_cast<CCNode*>(this ))) {
49+ if (!modding->doModify ) return CCObject::autorelease ();
50+
51+ if (MyCCNode* node = static_cast <MyCCNode*>(typeinfo_cast<CCNode*>(this ))) {
52+ if (modding->finishedLoad && !node->isModified ()) {
1853 const std::string& className = Utils::getNodeName (node);
19- if (modding->finishedLoad && !node->isModified ()) {
54+ node->retain ();
55+ LateQueue::get ()->queue ([modding, node, className] {
2056 modding->doUICheckForType (className, node);
2157 node->setModified ();
22- }
58+ node->release ();
59+ });
2360 }
2461 }
62+
2563 return CCObject::autorelease ();
2664 }
2765};
66+
67+ class $modify(CCPoolManager) {
68+ void pop () {
69+ LateQueue::get ()->executeQueue ();
70+ CCPoolManager::pop ();
71+ }
72+ };
0 commit comments