diff options
-rw-r--r-- | engines/sword25/gfx/image/b25sloader.cpp | 42 | ||||
-rw-r--r-- | engines/sword25/package/packagemanager.cpp | 25 |
2 files changed, 49 insertions, 18 deletions
diff --git a/engines/sword25/gfx/image/b25sloader.cpp b/engines/sword25/gfx/image/b25sloader.cpp index 3be6374e67..513e74ccea 100644 --- a/engines/sword25/gfx/image/b25sloader.cpp +++ b/engines/sword25/gfx/image/b25sloader.cpp @@ -46,30 +46,36 @@ namespace Sword25 { // ----------------------------------------------------------------------------- namespace { +static Common::String LoadString(Common::ReadStream &In, uint MaxSize = 999) { + Common::String Result; + + char ch = (char)In.readByte(); + while ((ch != '\0') && (ch != ' ')) { + Result += ch; + if (Result.size() >= MaxSize) break; + ch = (char)In.readByte(); + } + + return Result; +} + uint FindEmbeddedPNG(const byte *FileDataPtr, uint FileSize) { if (memcmp(FileDataPtr, "BS25SAVEGAME", 12)) return 0; -#if 0 - // Einen Stringstream mit dem Anfang der Datei intialisieren. 512 Byte sollten hierfür genügen. - istringstream StringStream(string(FileDataPtr, FileDataPtr + min(static_cast<uint>(512), FileSize))); + // Read in the header + Common::MemoryReadStream stream(FileDataPtr, FileSize); // Headerinformationen der Spielstandes einlesen. - string Marker, VersionID; - uint CompressedGamedataSize, UncompressedGamedataSize; - StringStream >> Marker >> VersionID >> CompressedGamedataSize >> UncompressedGamedataSize; - if (!StringStream.good()) return 0; - - // Testen, ob wir tatsächlich einen Spielstand haben. - if (Marker == "BS25SAVEGAME") { - // Offset zum PNG innerhalb des Spielstandes berechnen und zurückgeben. - return static_cast<uint>(StringStream.tellg()) + CompressedGamedataSize + 1; - } -#else - warning("STUB:FindEmbeddedPNG()"); -#endif - - return 0; + uint compressedGamedataSize; + LoadString(stream); + LoadString(stream); + Common::String gameSize = LoadString(stream); + compressedGamedataSize = atoi(gameSize.c_str()); + LoadString(stream); + + // Return the offset of where the thumbnail starts + return static_cast<uint>(stream.pos() + compressedGamedataSize); } } diff --git a/engines/sword25/package/packagemanager.cpp b/engines/sword25/package/packagemanager.cpp index 1b49eda5a4..4cea4f578d 100644 --- a/engines/sword25/package/packagemanager.cpp +++ b/engines/sword25/package/packagemanager.cpp @@ -36,8 +36,11 @@ #include "common/archive.h" #include "common/config-manager.h" +#include "common/savefile.h" #include "common/str-array.h" +#include "common/system.h" #include "common/unzip.h" +#include "sword25/kernel/filesystemutil.h" #include "sword25/package/packagemanager.h" namespace Sword25 { @@ -142,7 +145,29 @@ bool PackageManager::LoadDirectoryAsPackage(const Common::String &directoryName, } byte *PackageManager::GetFile(const Common::String &fileName, uint *fileSizePtr) { + const Common::String B25S_EXTENSION(".b25s"); Common::SeekableReadStream *in; + + if (fileName.hasSuffix(B25S_EXTENSION)) { + // Savegame loading logic + Common::SaveFileManager *sfm = g_system->getSavefileManager(); + Common::InSaveFile *file = sfm->openForLoading( + FileSystemUtil::GetInstance().GetPathFilename(fileName)); + if (!file) { + BS_LOG_ERRORLN("Could not load savegame \"%s\".", fileName.c_str()); + return 0; + } + + if (*fileSizePtr) + *fileSizePtr = file->size(); + + byte *buffer = new byte[file->size()]; + file->read(buffer, file->size()); + + delete file; + return buffer; + } + Common::ArchiveMemberPtr fileNode = GetArchiveMember(normalizePath(fileName, _currentDirectory)); if (!fileNode) return 0; |