From 98fe2757833c2ab972bb8519b03826d24190d3c6 Mon Sep 17 00:00:00 2001 From: Marvelco Date: Wed, 11 Mar 2026 06:31:50 +0200 Subject: [PATCH 1/3] fixed Gamemode not saving --- .../Common/UI/UIScene_LoadMenu.cpp | 94 ++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp b/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp index d61a79022..6f2b80c68 100644 --- a/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp @@ -249,13 +249,105 @@ UIScene_LoadMenu::UIScene_LoadMenu(int iPad, void *initData, UILayer *parentLaye #endif #endif #ifdef _WINDOWS64 - if (params->saveDetails != nullptr && params->saveDetails->UTF8SaveName[0] != '\0') + if (params->saveDetails != nullptr && params->saveDetails->UTF8SaveFilename[0] != '\0') { wchar_t wSaveName[128]; ZeroMemory(wSaveName, sizeof(wSaveName)); mbstowcs(wSaveName, params->saveDetails->UTF8SaveName, 127); m_levelName = wstring(wSaveName); m_labelGameName.init(m_levelName); + + wchar_t wFilename[MAX_SAVEFILENAME_LENGTH]; + ZeroMemory(wFilename, sizeof(wFilename)); + mbstowcs(wFilename, params->saveDetails->UTF8SaveFilename, MAX_SAVEFILENAME_LENGTH - 1); + wstring filePath = wstring(L"Windows64\\GameHDD\\") + wstring(wFilename) + wstring(L"\\saveData.ms"); + + HANDLE hFile = CreateFileW(filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr); + if (hFile != INVALID_HANDLE_VALUE) + { + DWORD fileSize = GetFileSize(hFile, nullptr); + unsigned char* rawData = new unsigned char[fileSize]; + DWORD bytesRead = 0; + ReadFile(hFile, rawData, fileSize, &bytesRead, nullptr); + CloseHandle(hFile); + + unsigned char* saveData = rawData; + unsigned int saveSize = fileSize; + bool freeSaveData = false; + + if (*(unsigned int*)rawData == 0) + { + unsigned int decompSize = *(unsigned int*)(rawData + 4); + if (decompSize > 0 && decompSize <= 128 * 1024 * 1024) + { + saveData = new unsigned char[decompSize]; + Compression::getCompression()->Decompress(saveData, &decompSize, rawData + 8, fileSize - 8); + saveSize = decompSize; + freeSaveData = true; + } + } + + if (saveSize >= 12) + { + unsigned int headerOffset = *(unsigned int*)saveData; + unsigned int numEntries = *(unsigned int*)(saveData + 4); + const unsigned int entrySize = sizeof(FileEntrySaveData); + + if (headerOffset < saveSize && numEntries > 0 && numEntries < 10000 && headerOffset + numEntries * entrySize <= saveSize) + { + FileEntrySaveData* table = (FileEntrySaveData*)(saveData + headerOffset); + for (unsigned int i = 0; i < numEntries; i++) + { + if (wcscmp(table[i].filename, L"level.dat") == 0) + { + unsigned int off = table[i].startOffset; + unsigned int len = table[i].length; + if (off >= 12 && off + len <= saveSize && len > 0 && len < 4 * 1024 * 1024) + { + byteArray ba; + ba.data = (byte*)(saveData + off); + ba.length = len; + CompoundTag* root = NbtIo::decompress(ba); + if (root != nullptr) + { + CompoundTag* dataTag = root->getCompound(L"Data"); + if (dataTag != nullptr) + { + int savedGameType = dataTag->getInt(L"GameType"); + switch (savedGameType) + { + case 1: + m_buttonGamemode.setLabel(app.GetString(IDS_GAMEMODE_CREATIVE)); + m_bGameModeCreative = true; + m_iGameModeId = GameType::CREATIVE->getId(); + break; +#ifdef _ADVENTURE_MODE_ENABLED + case 2: + m_buttonGamemode.setLabel(app.GetString(IDS_GAMEMODE_ADVENTURE)); + m_bGameModeCreative = false; + m_iGameModeId = GameType::ADVENTURE->getId(); + break; +#endif + default: + m_buttonGamemode.setLabel(app.GetString(IDS_GAMEMODE_SURVIVAL)); + m_bGameModeCreative = false; + m_iGameModeId = GameType::SURVIVAL->getId(); + break; + } + } + delete root; + } + } + break; + } + } + } + } + + if (freeSaveData) delete[] saveData; + delete[] rawData; + } + m_bRetrievingSaveThumbnail = false; } #endif } From 8f77ffa40de404514bf981a965dc2d44d6381804 Mon Sep 17 00:00:00 2001 From: Marvelco Date: Thu, 12 Mar 2026 03:36:06 +0200 Subject: [PATCH 2/3] Revert "fixed Gamemode not saving" This reverts commit 98fe2757833c2ab972bb8519b03826d24190d3c6. --- .../Common/UI/UIScene_LoadMenu.cpp | 94 +------------------ 1 file changed, 1 insertion(+), 93 deletions(-) diff --git a/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp b/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp index 6f2b80c68..d61a79022 100644 --- a/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp @@ -249,105 +249,13 @@ UIScene_LoadMenu::UIScene_LoadMenu(int iPad, void *initData, UILayer *parentLaye #endif #endif #ifdef _WINDOWS64 - if (params->saveDetails != nullptr && params->saveDetails->UTF8SaveFilename[0] != '\0') + if (params->saveDetails != nullptr && params->saveDetails->UTF8SaveName[0] != '\0') { wchar_t wSaveName[128]; ZeroMemory(wSaveName, sizeof(wSaveName)); mbstowcs(wSaveName, params->saveDetails->UTF8SaveName, 127); m_levelName = wstring(wSaveName); m_labelGameName.init(m_levelName); - - wchar_t wFilename[MAX_SAVEFILENAME_LENGTH]; - ZeroMemory(wFilename, sizeof(wFilename)); - mbstowcs(wFilename, params->saveDetails->UTF8SaveFilename, MAX_SAVEFILENAME_LENGTH - 1); - wstring filePath = wstring(L"Windows64\\GameHDD\\") + wstring(wFilename) + wstring(L"\\saveData.ms"); - - HANDLE hFile = CreateFileW(filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr); - if (hFile != INVALID_HANDLE_VALUE) - { - DWORD fileSize = GetFileSize(hFile, nullptr); - unsigned char* rawData = new unsigned char[fileSize]; - DWORD bytesRead = 0; - ReadFile(hFile, rawData, fileSize, &bytesRead, nullptr); - CloseHandle(hFile); - - unsigned char* saveData = rawData; - unsigned int saveSize = fileSize; - bool freeSaveData = false; - - if (*(unsigned int*)rawData == 0) - { - unsigned int decompSize = *(unsigned int*)(rawData + 4); - if (decompSize > 0 && decompSize <= 128 * 1024 * 1024) - { - saveData = new unsigned char[decompSize]; - Compression::getCompression()->Decompress(saveData, &decompSize, rawData + 8, fileSize - 8); - saveSize = decompSize; - freeSaveData = true; - } - } - - if (saveSize >= 12) - { - unsigned int headerOffset = *(unsigned int*)saveData; - unsigned int numEntries = *(unsigned int*)(saveData + 4); - const unsigned int entrySize = sizeof(FileEntrySaveData); - - if (headerOffset < saveSize && numEntries > 0 && numEntries < 10000 && headerOffset + numEntries * entrySize <= saveSize) - { - FileEntrySaveData* table = (FileEntrySaveData*)(saveData + headerOffset); - for (unsigned int i = 0; i < numEntries; i++) - { - if (wcscmp(table[i].filename, L"level.dat") == 0) - { - unsigned int off = table[i].startOffset; - unsigned int len = table[i].length; - if (off >= 12 && off + len <= saveSize && len > 0 && len < 4 * 1024 * 1024) - { - byteArray ba; - ba.data = (byte*)(saveData + off); - ba.length = len; - CompoundTag* root = NbtIo::decompress(ba); - if (root != nullptr) - { - CompoundTag* dataTag = root->getCompound(L"Data"); - if (dataTag != nullptr) - { - int savedGameType = dataTag->getInt(L"GameType"); - switch (savedGameType) - { - case 1: - m_buttonGamemode.setLabel(app.GetString(IDS_GAMEMODE_CREATIVE)); - m_bGameModeCreative = true; - m_iGameModeId = GameType::CREATIVE->getId(); - break; -#ifdef _ADVENTURE_MODE_ENABLED - case 2: - m_buttonGamemode.setLabel(app.GetString(IDS_GAMEMODE_ADVENTURE)); - m_bGameModeCreative = false; - m_iGameModeId = GameType::ADVENTURE->getId(); - break; -#endif - default: - m_buttonGamemode.setLabel(app.GetString(IDS_GAMEMODE_SURVIVAL)); - m_bGameModeCreative = false; - m_iGameModeId = GameType::SURVIVAL->getId(); - break; - } - } - delete root; - } - } - break; - } - } - } - } - - if (freeSaveData) delete[] saveData; - delete[] rawData; - } - m_bRetrievingSaveThumbnail = false; } #endif } From dd733855069cd214e4ad00aed73455afef245f03 Mon Sep 17 00:00:00 2001 From: Marvelco Date: Thu, 12 Mar 2026 03:36:45 +0200 Subject: [PATCH 3/3] fixed DLC files not saving correctly --- Minecraft.World/RegionFileCache.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Minecraft.World/RegionFileCache.cpp b/Minecraft.World/RegionFileCache.cpp index bd6405fa3..ad9e3095e 100644 --- a/Minecraft.World/RegionFileCache.cpp +++ b/Minecraft.World/RegionFileCache.cpp @@ -11,12 +11,8 @@ bool RegionFileCache::useSplitSaves(ESavePlatform platform) { case SAVE_FILE_PLATFORM_XBONE: case SAVE_FILE_PLATFORM_PS4: - return true; case SAVE_FILE_PLATFORM_WIN64: - { - LevelGenerationOptions* lgo = app.getLevelGenerationOptions(); - return (lgo != nullptr && lgo->isFromDLC()); - } + return true; default: return false; }; @@ -35,7 +31,11 @@ RegionFile *RegionFileCache::_getRegionFile(ConsoleSaveFile *saveFile, const wst File file; if(useSplitSaves(saveFile->getSavePlatform())) { - file = File( prefix + wstring(L"r.") + std::to_wstring(chunkX>>4) + L"." + std::to_wstring(chunkZ>>4) + L".mcr" ); + File oldFile(prefix + wstring(L"r.") + std::to_wstring(chunkX >> 5) + L"." + std::to_wstring(chunkZ >> 5) + L".mcr"); + if (oldFile.exists()) + file = oldFile; + else + file = File(prefix + wstring(L"r.") + std::to_wstring(chunkX >> 4) + L"." + std::to_wstring(chunkZ >> 4) + L".mcr"); } else {