fix field containers for separate modify classes in which one of them is a base of another, causing shared indices

This commit is contained in:
altalk23 2024-04-12 22:56:05 +03:00
parent 318a7f2921
commit 00e971a274
5 changed files with 20 additions and 4 deletions
VERSION
loader
include/Geode
cocos/base_nodes
modify
src

View file

@ -1 +1 @@
2.0.0-beta.23
2.0.0-beta.24

View file

@ -862,7 +862,9 @@ public:
private:
friend class geode::modifier::FieldContainer;
[[deprecated("Will be removed, it's an ABI break")]]
GEODE_DLL geode::modifier::FieldContainer* getFieldContainer();
GEODE_DLL geode::modifier::FieldContainer* getFieldContainer(char const* forClass);
GEODE_DLL void addEventListenerInternal(
std::string const& id,
geode::EventListenerProtocol* protocol

View file

@ -44,8 +44,8 @@ namespace geode::modifier {
return m_containedFields.at(index);
}
static FieldContainer* from(cocos2d::CCNode* node) {
return node->getFieldContainer();
static FieldContainer* from(cocos2d::CCNode* node, char const* forClass) {
return node->getFieldContainer(forClass);
}
};
@ -97,7 +97,7 @@ namespace geode::modifier {
static_assert(sizeof(Base) == offsetof(Parent, m_fields), "offsetof not correct");
// generating the container if it doesn't exist
auto container = FieldContainer::from(node);
auto container = FieldContainer::from(node, typeid(Base).name());
// the index is global across all mods, so the
// function is defined in the loader source

View file

@ -17,6 +17,7 @@ struct ProxyCCNode;
class GeodeNodeMetadata final : public cocos2d::CCObject {
private:
FieldContainer* m_fieldContainer;
std::unordered_map<std::string, FieldContainer*> m_classFieldContainers;
std::string m_id = "";
Ref<Layout> m_layout = nullptr;
Ref<LayoutOptions> m_layoutOptions = nullptr;
@ -62,6 +63,13 @@ public:
FieldContainer* getFieldContainer() {
return m_fieldContainer;
}
FieldContainer* getFieldContainer(char const* forClass) {
if (!m_classFieldContainers.count(forClass)) {
m_classFieldContainers[forClass] = new FieldContainer();
}
return m_classFieldContainers[forClass];
}
};
// proxy forwards
@ -99,6 +107,10 @@ FieldContainer* CCNode::getFieldContainer() {
return GeodeNodeMetadata::set(this)->getFieldContainer();
}
FieldContainer* CCNode::getFieldContainer(char const* forClass) {
return GeodeNodeMetadata::set(this)->getFieldContainer(forClass);
}
std::string CCNode::getID() {
return GeodeNodeMetadata::set(this)->m_id;
}

View file

@ -2,6 +2,8 @@
#include <Geode/binding/LevelTools.hpp>
#include <Geode/binding/LevelInfoLayer.hpp>
#include <Geode/binding/CCContentLayer.hpp>
#include <Geode/binding/GJSearchObject.hpp>
#include <Geode/binding/LevelBrowserLayer.hpp>
#include <Geode/loader/Mod.hpp>
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/Index.hpp>