From 33d1ee02b2433af44221f07de550c5e946f1c2a3 Mon Sep 17 00:00:00 2001 From: altalk23 Date: Tue, 5 Jul 2022 21:39:33 +0300 Subject: [PATCH] fix destructor crashes --- bindings/Cocos2d.bro | 14 ++++++++++---- bindings/GeometryDash.bro | 19 ++++++++++++++----- codegen/src/SourceGen.cpp | 5 ++++- .../keypad_dispatcher/CCKeypadDelegate.h | 2 ++ .../cocos/cocos2dx/menu_nodes/CCMenuItem.h | 1 + .../keyboard_dispatcher/CCKeyboardDelegate.h | 3 +++ .../robtop/mouse_dispatcher/CCMouseDelegate.h | 3 +++ .../touch_dispatcher/CCTouchHandler.h | 8 ++++++++ .../GUI/CCControlExtension/CCControl.h | 2 ++ .../CCControlColourPicker.h | 3 ++- 10 files changed, 49 insertions(+), 11 deletions(-) diff --git a/bindings/Cocos2d.bro b/bindings/Cocos2d.bro index 92a1f61a..a6e06311 100644 --- a/bindings/Cocos2d.bro +++ b/bindings/Cocos2d.bro @@ -20,7 +20,9 @@ class cocos2d::CCApplication { virtual auto openURL(char const*) = mac 0x1a4550, ios 0x10e7a4; virtual auto setAnimationInterval(double) = mac 0x1a3ee0, ios 0x10e494; static auto sharedApplication() = mac 0x1a3f30; - ~CCApplication() = mac 0x1a3d10, ios 0x10e384; + // ~CCApplication() = mac 0x1a3d10, ios 0x10e384; + inline cocos2d::CCApplication::CCApplication() {} + inline cocos2d::CCApplication::~CCApplication() {} } class cocos2d::CCArray { @@ -94,7 +96,9 @@ class cocos2d::CCDictionary { } class cocos2d::CCDirector { - virtual ~CCDirector() = mac 0x2493a0; + inline cocos2d::CCDirector::CCDirector() {} + inline cocos2d::CCDirector::~CCDirector() {} + // virtual ~CCDirector() = mac 0x2493a0; virtual auto init() = mac 0x248df0; virtual auto getScheduler() = mac 0x24af00; virtual auto setScheduler(cocos2d::CCScheduler*) = mac 0x24aec0; @@ -424,7 +428,7 @@ class cocos2d::CCMouseDispatcher { class cocos2d::CCMouseHandler { static cocos2d::CCMouseHandler* handlerWithDelegate(cocos2d::CCMouseDelegate*) = mac 0x12ef80; virtual auto initWithDelegate(cocos2d::CCMouseDelegate*) = mac 0x12ef40, , ios 0x43798; - ~CCMouseHandler() = mac 0x12ede0, , ios 0x4375c; + ~CCMouseHandler() = mac 0x12ede0, ios 0x4375c; } class cocos2d::CCMoveBy { @@ -744,7 +748,7 @@ class cocos2d::CCSpriteFrameCache { class cocos2d::CCStandardTouchHandler { static cocos2d::CCStandardTouchHandler* handlerWithDelegate(cocos2d::CCTouchDelegate*, int) = mac 0x247f30; virtual auto initWithDelegate(cocos2d::CCTouchDelegate*, int) = mac 0x247ed0, , ios 0x69; // iOS stub - ~CCStandardTouchHandler() = mac 0x2482a0, , ios 0x6d28; + ~CCStandardTouchHandler() = mac 0x2482a0, ios 0x6d28; } class cocos2d::CCString { @@ -843,6 +847,7 @@ class cocos2d::CCTransitionFade { // } class cocos2d::extension::CCControl { + inline cocos2d::extension::CCControl::CCControl() {} virtual bool init() = mac 0x1a71c0; virtual ~CCControl() = mac 0x1a7380; auto sendActionsForControlEvents(cocos2d::extension::CCControlEvent) = mac 0x1a7490; @@ -865,6 +870,7 @@ class cocos2d::extension::CCControl { } class cocos2d::extension::CCControlColourPicker { + inline cocos2d::extension::CCControlColourPicker::CCControlColourPicker() {} ~CCControlColourPicker() = mac 0x1aae30; auto setColorValue(cocos2d::_ccColor3B const&) = mac 0x1aac10; auto ccTouchBegan(cocos2d::CCTouch*, cocos2d::CCEvent*) = mac 0x1aae10; diff --git a/bindings/GeometryDash.bro b/bindings/GeometryDash.bro index 8edb5553..6dea9518 100644 --- a/bindings/GeometryDash.bro +++ b/bindings/GeometryDash.bro @@ -781,7 +781,8 @@ class CreatorLayer : cocos2d::CCLayer { static CreatorLayer* create() = mac 0x0, win 0x4dda0, ios 0x0; } -class CurrencyRewardLayer { +class CurrencyRewardLayer : cocos2d::CCLayer { + inline CurrencyRewardLayer() {} ~CurrencyRewardLayer() = mac 0x447950, win 0x0, ios 0x0; virtual void update(float) = mac 0x44a5c0, win 0x0, ios 0x0; } @@ -918,6 +919,12 @@ class DialogObject : cocos2d::CCObject { class DownloadMessageDelegate {} class DrawGridLayer : cocos2d::CCLayer { + static DrawGridLayer* get() { + auto editorLayer = LevelEditorLayer::get(); + if (!editorLayer) return nullptr; + return editorLayer->m_drawGridLayer; + } + bool init(cocos2d::CCNode* grid, LevelEditorLayer* editor) = mac 0x0, win 0x16c4d0, ios 0x0; void draw() = mac 0x0, win 0x16ce90, ios 0x0; virtual void update(float) = mac 0x0, win 0x16cd80, ios 0x0; @@ -1109,6 +1116,7 @@ class EditorUI : cocos2d::CCLayer, FLAlertLayerProtocol, ColorSelectDelegate, GJ void constrainGameLayerPosition(float x, float y) = mac 0x18890, win 0x8f920, ios 0x0; void moveGameLayer(cocos2d::CCPoint const& pos) = mac 0x1ca90, win 0x79290, ios 0x0; void showUI(bool show) = mac 0x245b0, win 0x87180, ios 0x0; + void resetUI() = mac 0x18520; void editObject2(cocos2d::CCObject* sender) = mac 0x0, win 0x8d1b0, ios 0x0; void editGroup(cocos2d::CCObject* sender) = mac 0x0, win 0x8d720, ios 0x0; void moveObjectCall(cocos2d::CCObject* sender) = mac 0x29830, win 0x8db30, ios 0x0; @@ -1186,7 +1194,7 @@ class EditorUI : cocos2d::CCLayer, FLAlertLayerProtocol, ColorSelectDelegate, GJ CCMenuItemSpriteExtra* m_snapBtn; CCMenuItemSpriteExtra* m_rotateBtn; CCMenuItemSpriteExtra* m_playbackBtn; - CCMenuItemSpriteExtra* m_PlaytestBtn; + CCMenuItemSpriteExtra* m_playtestBtn; CCMenuItemSpriteExtra* m_playtestStopBtn; CCMenuItemSpriteExtra* m_trashBtn; CCMenuItemSpriteExtra* m_linkBtn; @@ -2886,6 +2894,7 @@ class GameObject : CCSpritePlus { return m_detailColor; } + GameObject() = mac 0xdc4c0; // yeah why is this here wtf, seems life ego ctor created this ~GameObject() = mac 0x2f4ca0, win 0x0, ios 0x0; virtual void update(float) = mac 0x2fbb90, win 0x0, ios 0x0; virtual void setScaleX(float) = mac 0x335b00, win 0xe5050, ios 0x0; @@ -3565,12 +3574,12 @@ class LevelEditorLayer : GJBaseGameLayer, LevelSettingsDelegate { int m_coinCount; PAD = mac 0x40, win 0x28, android 0x0; int m_currentLayer; - PAD = mac 0x38, win 0x28, android 0x0; - EditorUI* m_editorUI; + PAD = mac 0x40, win 0x28, android 0x0; + EditorUI* m_editorUI; // 0x5d8 on macos!! cocos2d::CCSprite* m_backgroundLayer; cocos2d::CCArray* m_undoObjects; cocos2d::CCArray* m_someArray; - PAD = mac 0x16, win 0x8, android 0x0; + PAD = mac 0x8, win 0x8, android 0x0; int m_objectsRand1; int m_objectsRand2; int m_objects; diff --git a/codegen/src/SourceGen.cpp b/codegen/src/SourceGen.cpp index 797d157b..9fa0a3a1 100644 --- a/codegen/src/SourceGen.cpp +++ b/codegen/src/SourceGen.cpp @@ -42,9 +42,12 @@ types::ret{index} {class_name}::{function_name}({parameters}){const_whitespace}{ // basically we destruct it once by calling the gd function, // then lock it, so that other gd destructors dont get called if (CCDestructor::lock(this)) return; - CCDestructor::lock(this) = true; auto func = Function({{addresses::address{index}()}}); func(this{argument_comma}{arguments}); + // we need to construct it back so that it uhhh ummm doesnt crash + // while going to the child destructors + auto thing = new (this) {class_name}(std::monostate(), sizeof({class_name})); + CCDestructor::lock(this) = true; }} )GEN"; diff --git a/include/cocos/cocos2dx/keypad_dispatcher/CCKeypadDelegate.h b/include/cocos/cocos2dx/keypad_dispatcher/CCKeypadDelegate.h index 5f790bfc..9c44fd96 100644 --- a/include/cocos/cocos2dx/keypad_dispatcher/CCKeypadDelegate.h +++ b/include/cocos/cocos2dx/keypad_dispatcher/CCKeypadDelegate.h @@ -59,6 +59,8 @@ class CC_DLL CCKeypadHandler : public CCObject { GEODE_FRIEND_MODIFY public: + GEODE_MONOSTATE_CONSTRUCTOR_COCOS(CCKeypadHandler, CCObject) + inline CCKeypadHandler() = default; virtual ~CCKeypadHandler(void); /** delegate */ diff --git a/include/cocos/cocos2dx/menu_nodes/CCMenuItem.h b/include/cocos/cocos2dx/menu_nodes/CCMenuItem.h index ebb49ce5..a65f6a47 100644 --- a/include/cocos/cocos2dx/menu_nodes/CCMenuItem.h +++ b/include/cocos/cocos2dx/menu_nodes/CCMenuItem.h @@ -139,6 +139,7 @@ public: : m_pLabel(NULL) , m_fOriginalScale(0.0) {} + GEODE_MONOSTATE_CONSTRUCTOR_COCOS(CCMenuItemLabel, CCMenuItem) /** * @js NA * @lua NA diff --git a/include/cocos/cocos2dx/robtop/keyboard_dispatcher/CCKeyboardDelegate.h b/include/cocos/cocos2dx/robtop/keyboard_dispatcher/CCKeyboardDelegate.h index f0090ddd..f152ea49 100644 --- a/include/cocos/cocos2dx/robtop/keyboard_dispatcher/CCKeyboardDelegate.h +++ b/include/cocos/cocos2dx/robtop/keyboard_dispatcher/CCKeyboardDelegate.h @@ -207,6 +207,9 @@ RT_ADD( class CC_DLL CCKeyboardHandler : public CCObject { public: + GEODE_MONOSTATE_CONSTRUCTOR_COCOS(CCKeyboardHandler, CCObject) + inline CCKeyboardHandler() = default; + virtual ~CCKeyboardHandler(); CCKeyboardHandler& operator=(const CCKeyboardHandler&); diff --git a/include/cocos/cocos2dx/robtop/mouse_dispatcher/CCMouseDelegate.h b/include/cocos/cocos2dx/robtop/mouse_dispatcher/CCMouseDelegate.h index 7665be1a..db0b3c38 100644 --- a/include/cocos/cocos2dx/robtop/mouse_dispatcher/CCMouseDelegate.h +++ b/include/cocos/cocos2dx/robtop/mouse_dispatcher/CCMouseDelegate.h @@ -22,6 +22,9 @@ RT_ADD( class CC_DLL CCMouseHandler : public CCObject { public: + GEODE_MONOSTATE_CONSTRUCTOR_COCOS(CCMouseHandler, CCObject) + inline CCMouseHandler() = default; + virtual ~CCMouseHandler(); CCMouseHandler& operator=(const CCMouseHandler&); diff --git a/include/cocos/cocos2dx/touch_dispatcher/CCTouchHandler.h b/include/cocos/cocos2dx/touch_dispatcher/CCTouchHandler.h index c851ad1a..77062e98 100644 --- a/include/cocos/cocos2dx/touch_dispatcher/CCTouchHandler.h +++ b/include/cocos/cocos2dx/touch_dispatcher/CCTouchHandler.h @@ -48,6 +48,8 @@ class CC_DLL CCTouchHandler : public CCObject { GEODE_FRIEND_MODIFY public: + GEODE_MONOSTATE_CONSTRUCTOR_COCOS(CCTouchHandler, CCObject) + inline CCTouchHandler() = default; virtual ~CCTouchHandler(void); /** delegate */ @@ -84,6 +86,9 @@ class CC_DLL CCStandardTouchHandler : public CCTouchHandler { GEODE_FRIEND_MODIFY public: + GEODE_MONOSTATE_CONSTRUCTOR_COCOS(CCStandardTouchHandler, CCTouchHandler) + inline CCStandardTouchHandler() = default; + ~CCStandardTouchHandler(void); /** initializes a TouchHandler with a delegate and a priority */ @@ -105,6 +110,9 @@ class CC_DLL CCTargetedTouchHandler : public CCTouchHandler { GEODE_FRIEND_MODIFY public: + GEODE_MONOSTATE_CONSTRUCTOR_COCOS(CCTargetedTouchHandler, CCTouchHandler) + inline CCTargetedTouchHandler() = default; + ~CCTargetedTouchHandler(void); /** whether or not the touches are swallowed */ diff --git a/include/cocos/extensions/GUI/CCControlExtension/CCControl.h b/include/cocos/extensions/GUI/CCControlExtension/CCControl.h index b3f201c0..db8ba834 100644 --- a/include/cocos/extensions/GUI/CCControlExtension/CCControl.h +++ b/include/cocos/extensions/GUI/CCControlExtension/CCControl.h @@ -139,6 +139,8 @@ public: * @js ctor */ CCControl(); + GEODE_MONOSTATE_CONSTRUCTOR_COCOS(CCControl, CCLayerRGBA) + virtual bool init(void); /** * @js NA diff --git a/include/cocos/extensions/GUI/CCControlExtension/CCControlColourPicker.h b/include/cocos/extensions/GUI/CCControlExtension/CCControlColourPicker.h index e64b6f1e..001175ad 100644 --- a/include/cocos/extensions/GUI/CCControlExtension/CCControlColourPicker.h +++ b/include/cocos/extensions/GUI/CCControlExtension/CCControlColourPicker.h @@ -58,6 +58,7 @@ public: virtual void setColorValue(ccColor3B const&); ) + GEODE_MONOSTATE_CONSTRUCTOR_COCOS(CCControlColourPicker, CCControl) CCControlColourPicker(); virtual ~CCControlColourPicker(); @@ -98,4 +99,4 @@ protected: NS_CC_EXT_END -#endif \ No newline at end of file +#endif