2023-09-14 08:49:24 -04:00
|
|
|
#include <Geode/c++stl/gdstdlib.hpp>
|
2023-12-23 07:44:29 -05:00
|
|
|
#include "../../c++stl/string-impl.hpp"
|
2023-09-14 08:49:24 -04:00
|
|
|
|
2023-12-23 10:02:13 -05:00
|
|
|
#ifdef GEODE_IS_ANDROID
|
|
|
|
|
|
|
|
#if defined(GEODE_IS_ANDROID32)
|
|
|
|
|
|
|
|
static constexpr ptrdiff_t MENULAYER_SCENE = 0x309068 - 0x10000;
|
2024-01-01 09:55:45 -05:00
|
|
|
static constexpr ptrdiff_t STRING_EMPTY = 0xaa1c48 - 0x10000 - 0xc; // the internal struct size
|
2023-12-24 23:11:17 -05:00
|
|
|
static constexpr ptrdiff_t STRING_DTOR = 0x7514c8 - 0x10000 + 1;
|
2023-12-23 10:02:13 -05:00
|
|
|
static constexpr ptrdiff_t STRING_COPY = 0x753a44 - 0x10000 + 1;
|
|
|
|
|
|
|
|
#elif defined(GEODE_IS_ANDROID64)
|
|
|
|
|
|
|
|
static constexpr ptrdiff_t MENULAYER_SCENE = 0x6a62ec - 0x100000;
|
2024-01-01 09:55:45 -05:00
|
|
|
static constexpr ptrdiff_t STRING_EMPTY = 0x12d8568 - 0x100000 - 0x18; // the internal struct size
|
2023-12-24 23:11:17 -05:00
|
|
|
static constexpr ptrdiff_t STRING_DTOR = 0xdb9778 - 0x100000; // it's inlined but it exists !!!!
|
2023-12-23 10:02:13 -05:00
|
|
|
static constexpr ptrdiff_t STRING_COPY = 0xdb5fdc - 0x100000;
|
|
|
|
|
|
|
|
#endif
|
2023-09-14 08:49:24 -04:00
|
|
|
|
2023-12-20 11:58:47 -05:00
|
|
|
// 2.2 addition
|
|
|
|
// zmx please fix this
|
|
|
|
|
2023-09-15 16:37:18 -04:00
|
|
|
namespace geode::base {
|
|
|
|
uintptr_t get() {
|
2023-12-23 10:02:13 -05:00
|
|
|
static uintptr_t base = (reinterpret_cast<uintptr_t>(&MenuLayer::scene) - MENULAYER_SCENE) & (~0x1);
|
2023-09-15 16:37:18 -04:00
|
|
|
// static uintptr_t base = reinterpret_cast<uintptr_t>(dlopen("libcocos2dcpp.so", RTLD_NOW));
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-22 16:09:58 -05:00
|
|
|
namespace geode::stl {
|
|
|
|
static inline auto emptyInternalString() {
|
2023-12-23 08:36:24 -05:00
|
|
|
return reinterpret_cast<StringData::Internal*>(
|
2023-12-23 10:02:13 -05:00
|
|
|
geode::base::get() + STRING_EMPTY + sizeof(StringData::Internal)
|
2023-12-22 16:09:58 -05:00
|
|
|
);
|
2023-09-14 08:49:24 -04:00
|
|
|
}
|
|
|
|
|
2023-12-23 08:36:24 -05:00
|
|
|
void StringImpl::setEmpty() {
|
|
|
|
data.m_data = emptyInternalString();
|
2023-09-14 08:49:24 -04:00
|
|
|
}
|
|
|
|
|
2023-12-23 08:36:24 -05:00
|
|
|
void StringImpl::free() {
|
|
|
|
if (data.m_data == nullptr || data.m_data == emptyInternalString()) return;
|
2023-12-22 16:09:58 -05:00
|
|
|
// TODO: reimplement this
|
2023-12-24 23:11:17 -05:00
|
|
|
reinterpret_cast<void (*)(StringData*)>(geode::base::get() + STRING_DTOR)(&data);
|
2023-09-14 08:49:24 -04:00
|
|
|
}
|
|
|
|
|
2023-12-23 08:36:24 -05:00
|
|
|
char* StringImpl::getStorage() {
|
|
|
|
return reinterpret_cast<char*>(data.m_data);
|
2023-09-14 08:49:24 -04:00
|
|
|
}
|
2023-12-23 09:10:36 -05:00
|
|
|
// TODO: add a copyFrom(string const&) to take advantage
|
|
|
|
// of gnustl refcounted strings
|
2023-12-23 08:36:24 -05:00
|
|
|
void StringImpl::setStorage(const std::string_view str) {
|
2023-12-22 16:09:58 -05:00
|
|
|
this->free();
|
2023-12-23 00:59:45 -05:00
|
|
|
|
|
|
|
if (str.size() == 0) {
|
|
|
|
this->setEmpty();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: should be using (char*, size_t) at the very least, or yknow, just reimplement it :-)
|
2023-12-23 10:02:13 -05:00
|
|
|
reinterpret_cast<void (*)(StringData*, char const*)>(geode::base::get() + STRING_COPY)(&data, str.data());
|
2023-12-23 00:59:45 -05:00
|
|
|
return;
|
|
|
|
|
2023-12-23 09:10:36 -05:00
|
|
|
// TODO: this crashes because we need to use gd's operator new...
|
|
|
|
#if 0
|
2023-12-23 08:36:24 -05:00
|
|
|
StringData::Internal internal;
|
2023-12-23 00:59:45 -05:00
|
|
|
internal.m_size = str.size();
|
|
|
|
internal.m_capacity = str.size();
|
|
|
|
internal.m_refcount = 0;
|
|
|
|
|
2023-12-23 08:36:24 -05:00
|
|
|
auto* buffer = static_cast<char*>(operator new(str.size() + 1 + sizeof(internal)));
|
|
|
|
std::memcpy(buffer, &internal, sizeof(internal));
|
|
|
|
std::memcpy(buffer + sizeof(internal), str.data(), str.size());
|
|
|
|
buffer[sizeof(internal) + str.size()] = 0;
|
2023-12-23 00:59:45 -05:00
|
|
|
|
2023-12-23 08:36:24 -05:00
|
|
|
data.m_data = reinterpret_cast<StringData::Internal*>(buffer + sizeof(internal));
|
2023-12-23 09:10:36 -05:00
|
|
|
#endif
|
2023-09-14 08:49:24 -04:00
|
|
|
}
|
|
|
|
|
2023-12-23 08:36:24 -05:00
|
|
|
size_t StringImpl::getSize() {
|
|
|
|
return data.m_data[-1].m_size;
|
2023-09-14 08:49:24 -04:00
|
|
|
}
|
2023-12-23 08:36:24 -05:00
|
|
|
void StringImpl::setSize(size_t size) {
|
2023-12-22 16:09:58 -05:00
|
|
|
// TODO: implement this, remember its copy-on-write...
|
2023-09-14 08:49:24 -04:00
|
|
|
}
|
|
|
|
|
2023-12-23 08:36:24 -05:00
|
|
|
size_t StringImpl::getCapacity() {
|
|
|
|
return data.m_data[-1].m_capacity;
|
2023-09-14 08:49:24 -04:00
|
|
|
}
|
2023-12-23 08:36:24 -05:00
|
|
|
void StringImpl::setCapacity(size_t cap) {
|
2023-12-22 16:09:58 -05:00
|
|
|
// TODO: implement this, remember its copy-on-write...
|
2023-09-14 08:49:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|