mirror of
https://github.com/geode-sdk/geode.git
synced 2025-02-17 00:30:26 -05:00
Fix field index, allow Parent* conversion of field
This commit is contained in:
parent
7c242a56b3
commit
7710fa91b8
3 changed files with 15 additions and 9 deletions
|
@ -32,8 +32,8 @@ namespace geode::modifier {
|
|||
|
||||
void* getField(size_t index) {
|
||||
if (m_containedFields.size() <= index) {
|
||||
m_containedFields.resize(index + 1);
|
||||
m_destructorFunctions.resize(index + 1);
|
||||
m_containedFields.push_back(nullptr);
|
||||
m_destructorFunctions.push_back(nullptr);
|
||||
}
|
||||
return m_containedFields.at(index);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ namespace geode::modifier {
|
|||
}
|
||||
};
|
||||
|
||||
GEODE_DLL size_t getFieldIndexForClass(size_t hash);
|
||||
GEODE_DLL size_t getFieldIndexForClass(char const* name);
|
||||
|
||||
template <class Parent, class Base>
|
||||
class FieldIntermediate {
|
||||
|
@ -90,7 +90,7 @@ namespace geode::modifier {
|
|||
}
|
||||
|
||||
template <class = std::enable_if_t<true>>
|
||||
Parent* operator->() {
|
||||
operator Parent*() {
|
||||
// get the this pointer of the base
|
||||
// field intermediate is the first member of Modify
|
||||
// meaning we canget the base from ourself
|
||||
|
@ -102,7 +102,7 @@ namespace geode::modifier {
|
|||
|
||||
// the index is global across all mods, so the
|
||||
// function is defined in the loader source
|
||||
static size_t index = getFieldIndexForClass(typeid(Base).hash_code());
|
||||
static size_t index = getFieldIndexForClass(typeid(Base).name());
|
||||
|
||||
// the fields are actually offset from their original
|
||||
// offset, this is done to save on allocation and space
|
||||
|
@ -119,6 +119,12 @@ namespace geode::modifier {
|
|||
reinterpret_cast<std::byte*>(offsetField) - sizeof(Intermediate)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
template <class = std::enable_if_t<true>>
|
||||
Parent* operator->() {
|
||||
return this->operator Parent*();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -79,9 +79,9 @@ struct ProxyCCNode : Modify<ProxyCCNode, CCNode> {
|
|||
}
|
||||
};
|
||||
|
||||
static inline std::unordered_map<size_t, size_t> s_nextIndex;
|
||||
size_t modifier::getFieldIndexForClass(size_t hash) {
|
||||
return s_nextIndex[hash]++;
|
||||
static inline std::unordered_map<std::string, size_t> s_nextIndex;
|
||||
size_t modifier::getFieldIndexForClass(char const* name) {
|
||||
return s_nextIndex[name]++;
|
||||
}
|
||||
|
||||
// not const because might modify contents
|
||||
|
|
|
@ -251,7 +251,7 @@ $register_ids(EditorPauseLayer) {
|
|||
);
|
||||
}
|
||||
menu->setContentSize({ 165.f, 100.f });
|
||||
menu->setPosition(75.f, winSize.height - 55.f);
|
||||
menu->setPosition(70.f, winSize.height - 55.f);
|
||||
menu->updateLayout();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue