From fc58ab79efea50babce4f5cafc5113fd31c3c277 Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Sun, 1 Oct 2023 17:36:44 +0300 Subject: [PATCH] c++ abi can go burn in gaseous tungsten --- bindings/GeometryDash.bro | 14 ++++++------- codegen/src/AndroidSymbol.hpp | 18 +++++++++++++--- codegen/src/Shared.hpp | 1 + loader/include/Geode/DefaultInclude.hpp | 10 ++++----- .../Geode/cocos/platform/android/CCEGLView.h | 2 ++ loader/include/Geode/modify/Field.hpp | 2 +- loader/src/hooks/LoadingLayer.cpp | 21 +++++++++++++++++++ loader/src/platform/android/main.cpp | 4 ++++ loader/test/members/Android.cpp | 2 ++ 9 files changed, 58 insertions(+), 16 deletions(-) diff --git a/bindings/GeometryDash.bro b/bindings/GeometryDash.bro index abf408c7..edaa7047 100644 --- a/bindings/GeometryDash.bro +++ b/bindings/GeometryDash.bro @@ -3611,7 +3611,7 @@ class GameObject : CCSpritePlus { bool m_unk3D9; bool m_isSelected; int m_globalClickCounter; - PAD = mac 0x8, win 0x8; + PAD = mac 0x8, win 0x8, android 0x8; bool m_shouldUpdateColorSprite; float m_multiScaleMultiplier; bool m_isGroupParent; @@ -3624,20 +3624,20 @@ class GameObject : CCSpritePlus { int m_editorLayer; int m_editorLayer2; int m_unk414; - PAD = mac 0xc, win 0xc; + PAD = mac 0xc, win 0xc, android 0xc; cocos2d::CCPoint m_firstPosition; bool m_unk42C; bool m_unk42D; - PAD = mac 0x6, win 0x6; + PAD = mac 0x6, win 0x6, android 0x6; bool m_isAnimated; - PAD = mac 0x7, win 0x7; + PAD = mac 0x7, win 0x7, android 0x7; bool m_hasEffectLine; bool m_specialUnk43d; - PAD = mac 0x1, win 0x1; + PAD = mac 0x1, win 0x1, android 0x1; bool m_hasDurationLine; bool m_isTriggerable; bool m_triggeredInEditor; - PAD = mac 0x6, win 0x6; + PAD = mac 0x6, win 0x6, android 0x6; bool m_highDetail; ColorActionSprite* m_colorActionSpriteBase; ColorActionSprite* m_colorActionSpriteDetail; @@ -3646,7 +3646,7 @@ class GameObject : CCSpritePlus { bool m_unk459; bool m_unk45A; bool m_wasForcedRotatedPositionUpdateIdk; - PAD = mac 0x8, win 0x8; + PAD = mac 0x8, win 0x8, android 0x8; bool m_orbMultiActivate; } diff --git a/codegen/src/AndroidSymbol.hpp b/codegen/src/AndroidSymbol.hpp index dbb936e5..3917fd1b 100644 --- a/codegen/src/AndroidSymbol.hpp +++ b/codegen/src/AndroidSymbol.hpp @@ -7,9 +7,9 @@ #include #include -std::string mangleIdent(std::string_view str) { +std::string mangleIdent(std::string_view str, bool ne = true) { if (str.find("::") != -1) { - std::string result = "N"; + std::string result = ne ? "N" : ""; auto s = str; do { const auto i = s.find("::"); @@ -19,7 +19,7 @@ std::string mangleIdent(std::string_view str) { else s = s.substr(i + 2); } while(s.size()); - return result + "E"; + return result + (ne ? "E" : ""); } else { return std::to_string(str.size()) + std::string(str); } @@ -125,6 +125,18 @@ std::string mangleType(std::vector& seen, std::string name, bool su std::string generateAndroidSymbol(const Class& clazz, const FunctionBindField* fn) { auto& decl = fn->prototype; + if (decl.type != FunctionType::Normal) { + // ctor and dtor + switch (decl.type) { + case FunctionType::Ctor: + return "_ZN" + mangleIdent(clazz.name, false) + "C2Ev"; + case FunctionType::Dtor: + return "_ZN" + mangleIdent(clazz.name, false) + "D2Ev"; + default: + throw std::runtime_error("Unknown function type"); + } + } + std::string mangledSymbol = "_Z" + mangleIdent(clazz.name + "::" + decl.name); if (decl.args.empty()) { mangledSymbol += "v"; diff --git a/codegen/src/Shared.hpp b/codegen/src/Shared.hpp index ef0e41a0..c4e57278 100644 --- a/codegen/src/Shared.hpp +++ b/codegen/src/Shared.hpp @@ -136,6 +136,7 @@ namespace codegen { inline bool shouldAndroidBind(const FunctionBindField* fn) { if (codegen::platform == Platform::Android) { + if (fn->prototype.type != FunctionType::Normal) return true; for (auto& [type, name] : fn->prototype.args) { if (can_find(type.name, "gd::")) return true; } diff --git a/loader/include/Geode/DefaultInclude.hpp b/loader/include/Geode/DefaultInclude.hpp index 523aa876..87d7b1a6 100644 --- a/loader/include/Geode/DefaultInclude.hpp +++ b/loader/include/Geode/DefaultInclude.hpp @@ -81,8 +81,7 @@ namespace geode { GEODE_IOS(GEODE_FILL_CONSTRUCTOR(Class_, 0){}) \ GEODE_WINDOWS(Class_(geode::CutoffConstructorType, size_t fill) \ : Class_() {}) \ - GEODE_ANDROID(Class_(geode::CutoffConstructorType, size_t fill) \ - : Class_() {}) + GEODE_ANDROID(GEODE_FILL_CONSTRUCTOR(Class_, 0){}) #define GEODE_CUTOFF_CONSTRUCTOR_COCOS(Class_, Base_) \ GEODE_MACOS(Class_(geode::CutoffConstructorType, size_t fill) \ @@ -91,8 +90,8 @@ namespace geode { : Base_(geode::CutoffConstructor, fill){}) \ GEODE_WINDOWS(Class_(geode::CutoffConstructorType, size_t fill) \ : Class_() {}) \ - GEODE_ANDROID(Class_(geode::CutoffConstructorType, size_t fill) \ - : Class_() {}) + GEODE_ANDROID(Class_(geode::CutoffConstructorType, size_t fill) \ + : Base_(geode::CutoffConstructor, fill){}) #define GEODE_CUTOFF_CONSTRUCTOR_GD(Class_, Base_) \ GEODE_WINDOWS(Class_(geode::CutoffConstructorType, size_t fill) \ @@ -106,7 +105,8 @@ namespace geode { #define GEODE_CUTOFF_CONSTRUCTOR_CUTOFF(Class_, Base_) \ GEODE_WINDOWS(GEODE_FILL_CONSTRUCTOR(Class_, sizeof(Base_)) : Base_(){}) \ - GEODE_ANDROID(GEODE_FILL_CONSTRUCTOR(Class_, sizeof(Base_)) : Base_(){}) \ + GEODE_ANDROID(Class_(geode::CutoffConstructorType, size_t fill) \ + : Base_(geode::CutoffConstructor, fill){}) \ GEODE_MACOS(Class_(geode::CutoffConstructorType, size_t fill) \ : Base_(geode::CutoffConstructor, fill){}) \ GEODE_IOS(Class_(geode::CutoffConstructorType, size_t fill) \ diff --git a/loader/include/Geode/cocos/platform/android/CCEGLView.h b/loader/include/Geode/cocos/platform/android/CCEGLView.h index a45d16ad..eed2465d 100644 --- a/loader/include/Geode/cocos/platform/android/CCEGLView.h +++ b/loader/include/Geode/cocos/platform/android/CCEGLView.h @@ -34,6 +34,8 @@ class CC_DLL CCEGLView : public CCEGLViewProtocol { GEODE_FRIEND_MODIFY public: + GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCEGLView, CCEGLViewProtocol) + CCEGLView(); virtual ~CCEGLView(); diff --git a/loader/include/Geode/modify/Field.hpp b/loader/include/Geode/modify/Field.hpp index 7a140f7d..8cf95add 100644 --- a/loader/include/Geode/modify/Field.hpp +++ b/loader/include/Geode/modify/Field.hpp @@ -58,7 +58,7 @@ namespace geode::modifier { using Intermediate = Modify; // Padding used for guaranteeing any member of parents // will be in between sizeof(Intermediate) and sizeof(Parent) - uintptr_t m_padding; + alignas(Base) uintptr_t m_padding; public: // the constructor that constructs the fields. diff --git a/loader/src/hooks/LoadingLayer.cpp b/loader/src/hooks/LoadingLayer.cpp index 00c5e80e..c8d24680 100644 --- a/loader/src/hooks/LoadingLayer.cpp +++ b/loader/src/hooks/LoadingLayer.cpp @@ -156,4 +156,25 @@ struct CustomLoadingLayer : Modify { } this->updateLoadingBar(); } +}; + +#include +struct FieldTest : Modify { + int field = 0x10101010; + + bool init(GJGameLevel* level) { + if (!PlayLayer::init(level)) return false; + log::debug("GameManager 1 {}", GameManager::sharedState()); + log::debug("PlayLayer 1 {}", PlayLayer::get()); + m_fields->field += 0x20202020; + log::debug("GameManager 2 {}", GameManager::sharedState()); + log::debug("PlayLayer 2 {}", PlayLayer::get()); + return true; + } + + void update(float dt) { + log::debug("GameManager {}", GameManager::sharedState()); + log::debug("PlayLayer {}", PlayLayer::get()); + PlayLayer::update(dt); + } }; \ No newline at end of file diff --git a/loader/src/platform/android/main.cpp b/loader/src/platform/android/main.cpp index 3fd948b8..471b162e 100644 --- a/loader/src/platform/android/main.cpp +++ b/loader/src/platform/android/main.cpp @@ -20,4 +20,8 @@ extern "C" [[gnu::visibility("default")]] jint JNI_OnLoad(JavaVM* vm, void* rese return JNI_VERSION_1_1; } +extern "C" [[gnu::visibility("default")]] void emptyFunction(void*) { + // empty +} + #endif \ No newline at end of file diff --git a/loader/test/members/Android.cpp b/loader/test/members/Android.cpp index 47871bc7..56373556 100644 --- a/loader/test/members/Android.cpp +++ b/loader/test/members/Android.cpp @@ -17,4 +17,6 @@ GEODE_MEMBER_CHECK(PlayLayer, m_bottomGround, 0x37c); GEODE_MEMBER_CHECK(PlayLayer, m_topGround, 0x380); GEODE_MEMBER_CHECK(PlayLayer, m_level, 0x470); +static_assert(sizeof(GameObject) == 0x42c); + #endif \ No newline at end of file