From d98cb2d709bd184e07f061f3c90f4b90048a8c45 Mon Sep 17 00:00:00 2001
From: altalk23 <45172705+altalk23@users.noreply.github.com>
Date: Tue, 15 Aug 2023 14:29:44 +0300
Subject: [PATCH] Make missing funcs/members private & fix macos hsv

---
 bindings/Cocos2d.bro       |  1 -
 bindings/GeometryDash.bro  | 30 ++++++++++-----------
 codegen/src/BindingGen.cpp | 35 +++++-------------------
 codegen/src/SourceGen.cpp  | 54 +++++++++++++++++++++++---------------
 4 files changed, 55 insertions(+), 65 deletions(-)

diff --git a/bindings/Cocos2d.bro b/bindings/Cocos2d.bro
index 45be3faf..a96f4e02 100644
--- a/bindings/Cocos2d.bro
+++ b/bindings/Cocos2d.bro
@@ -714,7 +714,6 @@ class cocos2d::CCParticleSystem {
 	CCParticleSystem() = win 0xb6650;
 	virtual ~CCParticleSystem() = win 0xb68e0;
 	virtual auto update(float);
-	virtual auto draw();
 	auto initParticle(cocos2d::tCCParticle*);
 	auto resetSystem() = mac 0x46bd50;
 	auto resumeSystem() = mac 0x46bd40;
diff --git a/bindings/GeometryDash.bro b/bindings/GeometryDash.bro
index ebc5b2a3..e85f2854 100644
--- a/bindings/GeometryDash.bro
+++ b/bindings/GeometryDash.bro
@@ -600,15 +600,15 @@ class CCSpritePart : CCSpritePlus {
 }
 
 class CCSpritePlus : cocos2d::CCSprite {
-    bool initWithSpriteFrameName(const char*) = mac 0x248670, win 0x1c1e0;
-    void setScaleX(float scale) = win 0x1c440;
-    void setScaleY(float scale) = win 0x1c4c0;
-    void setScale(float scale) = win 0x1c540;
-    void setPosition(const cocos2d::CCPoint& pos) = win 0x1c220;
-    void setRotation(float rotation) = win 0x1c280;
-    bool initWithTexture(cocos2d::CCTexture2D* texture) = win 0x1c200;
-    void setFlipX(bool flip) = win 0x1c300;
-    void setFlipY(bool flip) = win 0x1c3a0;
+    virtual bool initWithSpriteFrameName(const char*) = mac 0x248670, win 0x1c1e0;
+    virtual void setScaleX(float scale) = win 0x1c440;
+    virtual void setScaleY(float scale) = win 0x1c4c0;
+    virtual void setScale(float scale) = win 0x1c540;
+    virtual void setPosition(const cocos2d::CCPoint& pos) = win 0x1c220;
+    virtual void setRotation(float rotation) = win 0x1c280;
+    virtual bool initWithTexture(cocos2d::CCTexture2D* texture) = win 0x1c200;
+    virtual void setFlipX(bool flip) = win 0x1c300;
+    virtual void setFlipY(bool flip) = win 0x1c3a0;
     static CCSpritePlus* createWithSpriteFrame(cocos2d::CCSpriteFrame* frame) = win 0x1c130;
 
     cocos2d::CCArray* m_followers;
@@ -1043,7 +1043,7 @@ class CustomizeObjectLayer : FLAlertLayer, TextInputDelegate, HSVWidgetPopupDele
     cocos2d::CCArray* m_colorButtons;
     cocos2d::CCArray* m_colorTabNodes;
     cocos2d::CCArray* m_textTabNodes;
-    PAD = win 0x4;
+    PAD = win 0x4, mac 0x8;
     cocos2d::CCArray* m_detailTabNodes;
     int m_selectedMode;
     int m_customColorChannel;
@@ -1558,10 +1558,10 @@ class EffectGameObject : GameObject {
     bool init(char const*) = win 0x253CD0;
     void getTargetColorIndex() = mac 0xca1f0;
     virtual void triggerObject(GJBaseGameLayer*) = mac 0xc9870, win 0x253d60;
-    gd::string getSaveString() = win 0x257560;
+    virtual gd::string getSaveString() = win 0x257560;
     void updateSpecialColor() = win 0x254980;
-    void spawnXPosition() = win 0x254A00;
-    void triggerActivated(float) = win 0x254A30;
+    virtual void spawnXPosition() = win 0x254A00;
+    virtual void triggerActivated(float) = win 0x254A30;
 
     cocos2d::ccColor3B m_colColor;
     float m_duration;
@@ -5400,8 +5400,8 @@ class SimplePlayer : cocos2d::CCSprite {
     void updatePlayerFrame(int iconID, IconType iconType) = mac 0x1b62f0, win 0x12c650;
     void updateColors() = mac 0x1ba1f0, win 0x12c440, ios 0x224f2c;
     void setFrames(const char* firstLayer, const char* secondLayer, const char* birdDome, const char* outlineSprite, const char* detailSprite) = win 0x12c9e0;
-    void setColor(const cocos2d::ccColor3B& color) = mac 0x1bc9b0, win 0x12c410;
-    void setOpacity(unsigned char opacity) = win 0x12cb90;
+    virtual void setColor(const cocos2d::ccColor3B& color) = mac 0x1bc9b0, win 0x12c410;
+    virtual void setOpacity(unsigned char opacity) = win 0x12cb90;
 
     cocos2d::CCSprite* m_firstLayer;
     cocos2d::CCSprite* m_secondLayer;
diff --git a/codegen/src/BindingGen.cpp b/codegen/src/BindingGen.cpp
index b94f2926..90db47d0 100644
--- a/codegen/src/BindingGen.cpp
+++ b/codegen/src/BindingGen.cpp
@@ -47,31 +47,12 @@ public:
 )GEN";
 
     char const* error_definition = R"GEN(    
-    template <bool Value = false>
-    {static}{return_type} {function_name}({parameters}){const}{{
-        static_assert(Value, "{class_name}::{function_name} not implemented");
-        throw std::runtime_error("Use of undefined function " + GEODE_PRETTY_FUNCTION);
-    }}
-)GEN";
-
-    char const* error_definition_virtual = R"GEN(    
-    #ifdef GEODE_WARN_INCORRECT_MEMBERS
-    [[deprecated("Use of undefined virtual function - will crash at runtime!!!")]]
-    #endif
+private:
+    [[deprecated("{class_name}::{function_name} not implemented")]]
     /**
 {docs}{docs_addresses}     */
-    {virtual}{return_type} {function_name}({parameters}){const}{{
-        #ifdef GEODE_NO_UNDEFINED_VIRTUALS
-        static_assert(false, "Undefined virtual function - implement in GeometryDash.bro");
-        #endif
-        throw std::runtime_error("Use of undefined virtual function " + GEODE_PRETTY_FUNCTION);
-    }}
-)GEN";
-
-    char const* warn_offset_member = R"GEN(
-    #ifdef GEODE_WARN_INCORRECT_MEMBERS
-    [[deprecated("Member placed incorrectly - will crash at runtime!!!")]]
-    #endif
+    {static}{virtual}{return_type} {function_name}({parameters}){const};
+public:
 )GEN";
 
     char const* structor_definition = R"GEN(
@@ -81,7 +62,7 @@ public:
 )GEN";
     
     // requires: type, member_name, array
-    char const* member_definition = R"GEN(    {type} {member_name};
+    char const* member_definition = R"GEN({private}    {type} {member_name};{public}
 )GEN";
 
     char const* pad_definition = R"GEN(    GEODE_PAD({hardcode});
@@ -196,8 +177,9 @@ std::string generateBindingHeader(Root& root, ghc::filesystem::path const& singl
                 single_output += "\t" + i->inner + "\n";
                 continue;
             } else if (auto m = field.get_as<MemberField>()) {
-                if (unimplementedField) single_output += format_strings::warn_offset_member;
                 single_output += fmt::format(format_strings::member_definition,
+                    fmt::arg("private", unimplementedField ? "private:\n" : ""),
+                    fmt::arg("public", unimplementedField ? "\npublic:" : ""),
                     fmt::arg("type", m->type.name),
                     fmt::arg("member_name", m->name + str_if(fmt::format("[{}]", m->count), m->count))
                 );
@@ -221,9 +203,6 @@ std::string generateBindingHeader(Root& root, ghc::filesystem::path const& singl
                 if (!codegen::platformNumber(fn->binds)) {
                     used_format = format_strings::error_definition;
 
-                    if (fb->is_virtual)
-                        used_format = format_strings::error_definition_virtual;
-
                     if (fb->type != FunctionType::Normal)
                         continue;
                 }
diff --git a/codegen/src/SourceGen.cpp b/codegen/src/SourceGen.cpp
index bf220b57..3f6a1f9b 100644
--- a/codegen/src/SourceGen.cpp
+++ b/codegen/src/SourceGen.cpp
@@ -103,6 +103,12 @@ auto {class_name}::{function_name}({parameters}){const} -> decltype({function_na
 	}});
 	reinterpret_cast<FunctionType>(func)(this{parameter_comma}{arguments});
 }}
+)GEN";
+
+	char const* declare_virtual_error = R"GEN(
+auto {class_name}::{function_name}({parameters}){const} -> decltype({function_name}({arguments})) {{
+	throw std::runtime_error("{class_name}::{function_name} not implemented");
+}}
 )GEN";
 
 	char const* ool_function_definition = R"GEN(
@@ -158,32 +164,38 @@ std::string generateBindingSource(Root& root) {
 				}
 				
 			} else if (auto fn = f.get_as<FunctionBindField>()) {
-				if (codegen::getStatus(f) != BindStatus::NeedsBinding)
-					continue;
-				
-				// no cocos2d definitions on windows
+				char const* used_declare_format = nullptr;
+
 				if (codegen::platform == Platform::Windows && is_cocos_class(f.parent)) {
+					// no cocos2d definitions on windows
 					continue;
 				}
-
-				char const* used_declare_format;
-
-				switch (fn->prototype.type) {
-					case FunctionType::Normal:
-						used_declare_format = format_strings::declare_member;
-						break;
-					case FunctionType::Ctor:
-						used_declare_format = format_strings::declare_constructor;
-						break;
-					case FunctionType::Dtor:
-						used_declare_format = format_strings::declare_destructor;
-						break;
+				else if (!codegen::platformNumber(fn->binds) && fn->prototype.is_virtual && fn->prototype.type != FunctionType::Dtor) {
+					used_declare_format = format_strings::declare_virtual_error;
 				}
+				else if (codegen::getStatus(f) != BindStatus::NeedsBinding) {
+					continue;
+				}
+				
 
-				if (fn->prototype.is_static)
-					used_declare_format = format_strings::declare_static;
-				if (fn->prototype.is_virtual && fn->prototype.type != FunctionType::Dtor)
-					used_declare_format = format_strings::declare_virtual;
+				if (!used_declare_format) {
+					switch (fn->prototype.type) {
+						case FunctionType::Normal:
+							used_declare_format = format_strings::declare_member;
+							break;
+						case FunctionType::Ctor:
+							used_declare_format = format_strings::declare_constructor;
+							break;
+						case FunctionType::Dtor:
+							used_declare_format = format_strings::declare_destructor;
+							break;
+					}
+
+					if (fn->prototype.is_static)
+						used_declare_format = format_strings::declare_static;
+					if (fn->prototype.is_virtual && fn->prototype.type != FunctionType::Dtor)
+						used_declare_format = format_strings::declare_virtual;
+				}
 
 				output += fmt::format(used_declare_format,
 					fmt::arg("class_name", c.name),