Skip to content

Commit 39a11f2

Browse files
committed
fix crash when reiniting textures on android (thanks jasmine and km7)
1 parent 595dc35 commit 39a11f2

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/hooks/CCFileUtils.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@ using namespace geode::prelude;
1010

1111
static std::mutex mutex;
1212

13-
unsigned char* getFileDataHook(CCFileUtilsAndroid* fileUtils, const char* pszFileName, const char* pszMode, unsigned long* pSize) {
13+
using Func_t = unsigned char* (*)(CCFileUtilsAndroid*, const char*, const char*, unsigned long*, bool);
14+
static Func_t g_funcAddr;
15+
16+
unsigned char* getFileDataHook(CCFileUtilsAndroid* fileUtils, const char* pszFileName, const char* pszMode, unsigned long* pSize, bool async) {
1417
std::lock_guard lock(mutex);
15-
return fileUtils->getFileData(pszFileName, pszMode, pSize);
18+
return g_funcAddr(fileUtils, pszFileName, pszMode, pSize, false);
1619
}
1720

1821
$execute {
1922
void* handle = dlopen("libcocos2dcpp.so", RTLD_LAZY | RTLD_NOLOAD);
20-
void* addr = dlsym(handle, "_ZN7cocos2d18CCFileUtilsAndroid11getFileDataEPKcS2_Pm");
23+
g_funcAddr = (Func_t) dlsym(handle, "_ZN7cocos2d18CCFileUtilsAndroid13doGetFileDataEPKcS2_Pmb");
2124

22-
if (!addr) {
23-
log::error("Failed to hook CCFileUtilsAndroid::getFileData, address is nullptr");
25+
if (!g_funcAddr) {
26+
log::error("Failed to hook CCFileUtilsAndroid::doGetFileData, address is nullptr");
2427
return;
2528
}
2629

2730
auto hook = Mod::get()->hook(
28-
addr,
31+
(void*)g_funcAddr,
2932
&getFileDataHook,
30-
"cocos2d::CCFileUtilsAndroid::getFileData",
33+
"cocos2d::CCFileUtilsAndroid::doGetFileData",
3134
tulip::hook::TulipConvention::Default
3235
).unwrap();
3336
hook->setPriority(-199999999);

src/hooks/ZipUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class $modify(ZipUtils) {
145145

146146
std::vector<uint8_t> rawData = blaze::base64::decode(reinterpret_cast<char*>(data), size, true);
147147
if (rawData.empty()) {
148-
log::debug("decompressString2 fail 1");
148+
log::warn("decompressString2 fail 1");
149149
// if failed, try to fall back to original implementation
150150
if (encrypted) {
151151
encryptDecryptImpl(data, size, key);

src/hooks/load/spriteframes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ std::optional<T> parseNode(pugi::xml_node node) {
151151
if (auto _res = (val)) { \
152152
var = std::move(_res).value(); \
153153
} else { \
154-
log::debug("Failed to parse {} ({}:{})", #var, __FILE__, __LINE__); \
154+
log::warn("Failed to parse {} ({}:{})", #var, __FILE__, __LINE__); \
155155
return false; \
156156
} \
157157

0 commit comments

Comments
 (0)