Skip to content

Commit d950a6f

Browse files
Android Save Fix (#1270)
* Android Save Fix * I don't think that should be a variable * Clean up code
1 parent 575c982 commit d950a6f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

loader/src/hooks/AndroidSaveFix.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <Geode/platform/cplatform.h>
2+
3+
#ifdef GEODE_IS_ANDROID
4+
#include <Geode/loader/Mod.hpp>
5+
6+
using namespace geode::prelude;
7+
8+
void* g_decodeAddress = nullptr;
9+
10+
int base64DecodeHook(uint8_t* input, uint32_t length, uint8_t** output, bool urlSafe) {
11+
*output = new uint8_t[(size_t)(length * 3) / 4 + 4];
12+
13+
uint32_t outLength = 0;
14+
int ret = reinterpret_cast<int(*)(uint8_t*, uint32_t, uint8_t*, uint32_t*, bool)>(g_decodeAddress)(input, length, *output, &outLength, urlSafe);
15+
if (ret > 0) {
16+
delete[] *output;
17+
*output = nullptr;
18+
outLength = 0;
19+
}
20+
21+
return outLength;
22+
}
23+
24+
$execute {
25+
// This fixes a crash when using the base64Decode function in cocos2d-x, due to
26+
// floating-point precision errors causing the output buffer to be too small.
27+
// This issue can cause large save files to crash the game.
28+
29+
auto handle = dlopen("libcocos2dcpp.so", RTLD_LAZY | RTLD_NOLOAD);
30+
g_decodeAddress = dlsym(handle, "_ZN7cocos2d13_base64DecodeEPKhjPhPjb");
31+
auto decodeAddress = dlsym(handle, "base64Decode");
32+
33+
if (g_decodeAddress && decodeAddress) (void)Mod::get()->hook(decodeAddress, &base64DecodeHook, "base64Decode");
34+
}
35+
#endif

0 commit comments

Comments
 (0)