Skip to content

Commit

Permalink
message for a bug i cant recreate
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Dec 18, 2023
1 parent c7a4716 commit 0787b8f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.9
1.3.10
21 changes: 18 additions & 3 deletions loader/src/hooks/SaveFileFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
using namespace geode::prelude;

#include <Geode/cocos/support/base64.h>
#include "../loader/LoaderImpl.hpp"

void panic(std::string reason) {
LoaderImpl::get()->platformMessageBox("Critical", fmt::format(
"Your save file failed to load (reason: {})\n"
"As to not lose all of your data, the game will now abort.\n"
"Please backup your save files and try opening the game again, it might work.\n"
"Please contact the Geode Team about this", reason
));
std::abort();
}

// This function is well known for crashing on certain save files,
// causing the game to crash at startup, known as the infamous save file bug.
Expand All @@ -14,23 +25,26 @@ using namespace geode::prelude;
//
// To fix this, we just rewrite the function.
gd::string decompressString2(unsigned char* data, bool decrypt, int size, int decryptionKey) {
if (data == nullptr || size == 0 || *data == 0) {
log::debug("decompressString2 data={} size={}", reinterpret_cast<const void*>(data), size);
if (data == nullptr || size == 0) {
return {};
}

std::vector<unsigned char> copiedData(data, data + size);
if (decrypt) {
for (int i = 0; i < size; i++) {
data[i] ^= decryptionKey;
copiedData[i] ^= decryptionKey;
}
}

// TODO: maybe not use cocos's base64 and inflateMemory..

unsigned char* out = nullptr;
auto const decodedSize = cocos2d::base64Decode(data, size, &out);
auto const decodedSize = cocos2d::base64Decode(copiedData.data(), size, &out);
std::unique_ptr<unsigned char> b64decoded { out };

if (decodedSize <= 0) {
panic(fmt::format("base64 (size={}) (data={} size={})", decodedSize, reinterpret_cast<const void*>(data), size));
return {};
}

Expand All @@ -40,6 +54,7 @@ gd::string decompressString2(unsigned char* data, bool decrypt, int size, int de
std::unique_ptr<unsigned char> inflated { out };

if (inflatedSize <= 0) {
panic(fmt::format("inflate (size={}) (data={} size={})", inflatedSize, reinterpret_cast<const void*>(data), size));
return {};
}

Expand Down

0 comments on commit 0787b8f

Please sign in to comment.