Implement the new broma codege

This commit is contained in:
altalk23 2023-10-01 15:42:54 +03:00
parent fed73fefd6
commit 506bb05c4c
8 changed files with 44 additions and 28 deletions

View file

@ -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;

View file

@ -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

View file

@ -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<FunctionBindField>();
@ -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));
}

View file

@ -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<PadField>()) {
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<FunctionBindField>()) {
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)

View file

@ -83,6 +83,8 @@ std::string generateModifyHeader(Root const& root, ghc::filesystem::path const&
std::string statics;
std::set<std::string> used;
for (auto& f : c.fields) {
if (codegen::getStatus(f) == BindStatus::Missing) continue;
if (auto fn = f.get_as<FunctionBindField>()) {
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<FunctionBindField>();
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) {

View file

@ -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<FunctionBindField>()) {
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;
}

View file

@ -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<InlineField>()) {
// 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;

View file

@ -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