From 506bb05c4c7693a276bc6c0b0e3250da984a952e Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Sun, 1 Oct 2023 15:42:54 +0300 Subject: [PATCH] Implement the new broma codege --- bindings/GeometryDash.bro | 9 --------- codegen/CMakeLists.txt | 2 +- codegen/src/AddressGen.cpp | 6 +++++- codegen/src/BindingGen.cpp | 14 +++++++++++--- codegen/src/ModifyGen.cpp | 8 ++++++-- codegen/src/Shared.hpp | 17 +++++++++++------ codegen/src/SourceGen.cpp | 6 +++++- loader/test/members/Android.cpp | 10 +++++----- 8 files changed, 44 insertions(+), 28 deletions(-) diff --git a/bindings/GeometryDash.bro b/bindings/GeometryDash.bro index 64d3b151..3df5611d 100644 --- a/bindings/GeometryDash.bro +++ b/bindings/GeometryDash.bro @@ -4264,15 +4264,6 @@ class LevelSettingsDelegate { virtual void levelSettingsUpdated() {} } -class SecretLayer2 : cocos2d::CCLayer, TextInputDelegate, FLAlertLayerProtocol, DialogDelegate { - static SecretLayer2* create() = win 0x21FD70; - - bool init() = win 0x21FE10, mac 0x25fe70; - bool onSubmit(cocos2d::CCObject*) = win 0x221ac0, mac 0x2611a0; - void updateSearchLabel(const char* text) = win 0x222FC0, mac 0x260e10; - void showCompletedLevel() = win 0x220C10; -} - [[link(android)]] class SecretLayer2 : cocos2d::CCLayer, TextInputDelegate, FLAlertLayerProtocol, DialogDelegate { static SecretLayer2* create() = win 0x21FD70; diff --git a/codegen/CMakeLists.txt b/codegen/CMakeLists.txt index 2e3833a5..35ee9b31 100644 --- a/codegen/CMakeLists.txt +++ b/codegen/CMakeLists.txt @@ -4,7 +4,7 @@ project(Codegen LANGUAGES C CXX) include(../cmake/CPM.cmake) CPMAddPackage("gh:fmtlib/fmt#9.1.0") -CPMAddPackage("gh:geode-sdk/Broma#460f82d") +CPMAddPackage("gh:geode-sdk/Broma#93f401a") file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp diff --git a/codegen/src/AddressGen.cpp b/codegen/src/AddressGen.cpp index 9acb8c78..7adc690b 100644 --- a/codegen/src/AddressGen.cpp +++ b/codegen/src/AddressGen.cpp @@ -79,6 +79,8 @@ std::string generateAddressHeader(Root const& root) { output += format_strings::address_begin; for (auto& f : root.functions) { + if (codegen::getStatus(f) == BindStatus::Missing) continue; + std::string address_str; if (codegen::getStatus(f) == BindStatus::Binded) { @@ -104,6 +106,8 @@ std::string generateAddressHeader(Root const& root) { for (auto& c : root.classes) { for (auto& field : c.fields) { + if (codegen::getStatus(field) == BindStatus::Missing) continue; + std::string address_str; auto fn = field.get_as(); @@ -112,7 +116,7 @@ std::string generateAddressHeader(Root const& root) { continue; } - if (codegen::getStatus(field) == BindStatus::NeedsBinding || codegen::platformNumber(field)) { + if (codegen::getStatus(field) == BindStatus::NeedsBinding || codegen::platformNumber(field) != -1) { if (is_cocos_class(field.parent) && codegen::platform == Platform::Windows) { address_str = fmt::format("base::getCocos() + 0x{:x}", codegen::platformNumber(fn->binds)); } diff --git a/codegen/src/BindingGen.cpp b/codegen/src/BindingGen.cpp index 5d8f7c8e..2fe4d5f9 100644 --- a/codegen/src/BindingGen.cpp +++ b/codegen/src/BindingGen.cpp @@ -131,6 +131,8 @@ std::string generateBindingHeader(Root const& root, ghc::filesystem::path const& single_output += format_strings::class_includes; for (auto& f : root.functions) { + if (codegen::getStatus(f) == BindStatus::Missing) continue; + FunctionProto const* fb = &f.prototype; char const* used_format = format_strings::function_definition; @@ -202,6 +204,8 @@ std::string generateBindingHeader(Root const& root, ghc::filesystem::path const& bool unimplementedField = false; for (auto field : cls.fields) { + if (codegen::getStatus(field) == BindStatus::Missing) continue; + MemberFunctionProto* fb; char const* used_format = format_strings::function_definition; @@ -221,9 +225,13 @@ std::string generateBindingHeader(Root const& root, ghc::filesystem::path const& } else if (auto p = field.get_as()) { auto hardcode = codegen::platformNumber(p->amount); - if (hardcode) { + if (hardcode > 0) { single_output += fmt::format(format_strings::pad_definition, fmt::arg("hardcode", hardcode)); - } else { + } + else if (hardcode == 0) { + single_output += " // no padding\n"; + } + else { unimplementedField = true; } continue; @@ -234,7 +242,7 @@ std::string generateBindingHeader(Root const& root, ghc::filesystem::path const& } else if (auto fn = field.get_as()) { fb = &fn->prototype; - if (!codegen::platformNumber(fn->binds) && codegen::getStatus(field) != BindStatus::Binded) { + if (codegen::platformNumber(fn->binds) == -1 && codegen::getStatus(field) != BindStatus::Binded) { used_format = format_strings::error_definition; if (fb->type != FunctionType::Normal) diff --git a/codegen/src/ModifyGen.cpp b/codegen/src/ModifyGen.cpp index 937cd527..9bf5ea16 100644 --- a/codegen/src/ModifyGen.cpp +++ b/codegen/src/ModifyGen.cpp @@ -57,7 +57,7 @@ namespace geode::modifier {{ std::string generateModifyHeader(Root const& root, ghc::filesystem::path const& singleFolder) { std::string output; - for (auto& c : root.classes) { + for (auto& c : root.classes) { if (c.name == "cocos2d") continue; std::string filename = (codegen::getUnqualifiedClassName(c.name) + ".hpp"); @@ -83,6 +83,8 @@ std::string generateModifyHeader(Root const& root, ghc::filesystem::path const& std::string statics; std::set used; for (auto& f : c.fields) { + if (codegen::getStatus(f) == BindStatus::Missing) continue; + if (auto fn = f.get_as()) { if (fn->prototype.type == FunctionType::Normal && !used.count(fn->prototype.name)) { used.insert(fn->prototype.name); @@ -102,13 +104,15 @@ std::string generateModifyHeader(Root const& root, ghc::filesystem::path const& // modify for (auto& f : c.fields) { + if (codegen::getStatus(f) == BindStatus::Missing) continue; + auto fn = f.get_as(); if (!fn) { continue; } - if (codegen::getStatus(f) == BindStatus::NeedsBinding || codegen::platformNumber(f)) { + if (codegen::getStatus(f) == BindStatus::NeedsBinding || codegen::platformNumber(f) != -1) { } else if (codegen::getStatus(f) == BindStatus::Binded && fn->prototype.type == FunctionType::Normal) { diff --git a/codegen/src/Shared.hpp b/codegen/src/Shared.hpp index a2a69443..ef0e41a0 100644 --- a/codegen/src/Shared.hpp +++ b/codegen/src/Shared.hpp @@ -51,7 +51,8 @@ inline bool is_cocos_class(std::string const& str) { enum class BindStatus { Binded, NeedsBinding, - Unbindable + Unbindable, + Missing, }; struct codegen_error : std::runtime_error { @@ -91,7 +92,7 @@ namespace codegen { inline Platform platform; - inline uintptr_t platformNumberWithPlatform(Platform p, PlatformNumber const& pn) { + inline ptrdiff_t platformNumberWithPlatform(Platform p, PlatformNumber const& pn) { switch (p) { case Platform::Mac: return pn.mac; case Platform::Windows: return pn.win; @@ -102,7 +103,7 @@ namespace codegen { } } - inline uintptr_t platformNumber(PlatformNumber const& p) { + inline ptrdiff_t platformNumber(PlatformNumber const& p) { return platformNumberWithPlatform(codegen::platform, p); } @@ -114,17 +115,21 @@ namespace codegen { } inline BindStatus getStatusWithPlatform(Platform p, Field const& field) { + if ((field.missing & p) != Platform::None) return BindStatus::Missing; + if (auto fn = field.get_as()) { - if ((fn->links & p) != Platform::None) return BindStatus::Binded; - if (platformNumberWithPlatform(p, fn->binds)) return BindStatus::NeedsBinding; + if ((field.links & p) != Platform::None) return BindStatus::Binded; + if (platformNumberWithPlatform(p, fn->binds) != -1) return BindStatus::NeedsBinding; } return BindStatus::Unbindable; } inline BindStatus getStatusWithPlatform(Platform p, Function const& f) { + if ((f.missing & p) != Platform::None) return BindStatus::Missing; + if ((f.links & p) != Platform::None) return BindStatus::Binded; - if (platformNumberWithPlatform(p, f.binds)) return BindStatus::NeedsBinding; + if (platformNumberWithPlatform(p, f.binds) != -1) return BindStatus::NeedsBinding; return BindStatus::Unbindable; } diff --git a/codegen/src/SourceGen.cpp b/codegen/src/SourceGen.cpp index 230a31fc..ddba3630 100644 --- a/codegen/src/SourceGen.cpp +++ b/codegen/src/SourceGen.cpp @@ -135,6 +135,8 @@ std::string generateBindingSource(Root const& root) { std::string output(format_strings::source_start); for (auto& f : root.functions) { + if (codegen::getStatus(f) == BindStatus::Missing) continue; + if (codegen::getStatus(f) != BindStatus::NeedsBinding) { continue; } @@ -153,6 +155,8 @@ std::string generateBindingSource(Root const& root) { for (auto& c : root.classes) { for (auto& f : c.fields) { + if (codegen::getStatus(f) == BindStatus::Missing) continue; + if (auto i = f.get_as()) { // yeah there are no inlines on cocos } @@ -193,7 +197,7 @@ std::string generateBindingSource(Root const& root) { if ( codegen::getStatus(f) == BindStatus::Unbindable && - !codegen::platformNumber(fn->binds) && + codegen::platformNumber(fn->binds) == -1 && fn->prototype.is_virtual && fn->prototype.type != FunctionType::Dtor ) { used_declare_format = format_strings::declare_virtual_error; diff --git a/loader/test/members/Android.cpp b/loader/test/members/Android.cpp index ed8129cb..47871bc7 100644 --- a/loader/test/members/Android.cpp +++ b/loader/test/members/Android.cpp @@ -11,10 +11,10 @@ GEODE_MEMBER_CHECK(GameManager, m_levelEditorLayer, 0x13c); static_assert(sizeof(GJBaseGameLayer) == 0x2cc); -// GEODE_MEMBER_CHECK(PlayLayer, unknown4e8, 0x2e8); -// GEODE_MEMBER_CHECK(PlayLayer, m_endPortal, 0x324); -// GEODE_MEMBER_CHECK(PlayLayer, m_bottomGround, 0x37c); -// GEODE_MEMBER_CHECK(PlayLayer, m_topGround, 0x380); -// GEODE_MEMBER_CHECK(PlayLayer, m_level, 0x470); +GEODE_MEMBER_CHECK(PlayLayer, unknown4e8, 0x2e8); +GEODE_MEMBER_CHECK(PlayLayer, m_endPortal, 0x324); +GEODE_MEMBER_CHECK(PlayLayer, m_bottomGround, 0x37c); +GEODE_MEMBER_CHECK(PlayLayer, m_topGround, 0x380); +GEODE_MEMBER_CHECK(PlayLayer, m_level, 0x470); #endif \ No newline at end of file