diff --git a/src/games/cclcc/savesystem.cpp b/src/games/cclcc/savesystem.cpp index 952ee6a8..5b00fa47 100644 --- a/src/games/cclcc/savesystem.cpp +++ b/src/games/cclcc/savesystem.cpp @@ -89,7 +89,7 @@ SaveError SaveSystem::MountSaveFile() { entryArray[i] = new SaveFileEntry(); entryArray[i]->Status = Io::ReadLE(stream); - if(entryArray[i]->Status == 1 && entryArray == QuickSaveEntries) { + if (entryArray[i]->Status == 1 && entryArray == QuickSaveEntries) { QuickSaveCount++; } // Not sure about these two @@ -279,7 +279,7 @@ void SaveSystem::WriteSaveFile() { Io::WriteArrayLE(GameExtraData, stream, 1024); stream->Seek(0x387c, SEEK_SET); // TODO: Actually save system data - + std::vector thumbnailData(SaveThumbnailWidth * SaveThumbnailHeight * 4); for (auto* entryArray : {FullSaveEntries, QuickSaveEntries}) { int64_t saveDataPos = stream->Position; for (int i = 0; i < MaxSaveEntries; i++) { @@ -343,23 +343,24 @@ void SaveSystem::WriteSaveFile() { assert(stream->Position - startPos == 0x3ec0); Io::WriteArrayLE(entry->MapLoadData, stream, 0x6ac8); Io::WriteArrayLE(entry->YesNoData, stream, 0x54); - + // CCLCC PS4 Save thumbnails are 240x135 RGB16 - std::vector thumbnailData = Renderer->GetImageFromTexture( - entry->SaveThumbnail.Sheet.Texture, entry->SaveThumbnail.Bounds); - - - - int thumbnailPadding = 0xA14; - stream->Seek(thumbnailPadding, SEEK_CUR); - - for (int i = 0; i < thumbnailData.size(); i+=4) { - uint8_t r = thumbnailData[i]; - uint8_t g = thumbnailData[i + 1]; - uint8_t b = thumbnailData[i + 2]; - uint16_t pixel = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3); - Io::WriteLE(stream, pixel); - } + Renderer->GetImageFromTexture( + entry->SaveThumbnail.Sheet.Texture, entry->SaveThumbnail.Bounds, thumbnailData); + + int thumbnailPadding = 0xA14; + stream->Seek(thumbnailPadding, SEEK_CUR); + + for (int i = 0; i < thumbnailData.size(); i += 4) { + uint8_t r = thumbnailData[i]; + uint8_t g = thumbnailData[i + 1]; + uint8_t b = thumbnailData[i + 2]; + uint16_t pixel = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3); + pixel = SDL_SwapBE16(pixel); + thumbnailData[i/2] = pixel >> 8; + thumbnailData[i/2 + 1] = pixel & 0xFF; + } + Io::WriteArrayLE(thumbnailData.data(), stream, thumbnailData.size() / 2); } } } diff --git a/src/io/physicalfilestream.cpp b/src/io/physicalfilestream.cpp index d3f544f1..cc4bfa3c 100644 --- a/src/io/physicalfilestream.cpp +++ b/src/io/physicalfilestream.cpp @@ -98,6 +98,7 @@ IoError PhysicalFileStream::Duplicate(Stream** outStream) { } int64_t PhysicalFileStream::Write(void* buffer, int64_t sz, int cnt) { + // Todo: buffered write (SDL_RWwrite doesn't buffer system calls) int64_t written = SDL_RWwrite(RW, buffer, sz, cnt); Seek(sz * cnt, SEEK_CUR); return written; diff --git a/src/util.h b/src/util.h index 983274db..3b742520 100644 --- a/src/util.h +++ b/src/util.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "../vendor/span/span.hpp" // TODO own _malloca for gcc