aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/exereader.cpp
diff options
context:
space:
mode:
authorNorbert Lange2009-08-24 17:51:47 +0000
committerNorbert Lange2009-08-24 17:51:47 +0000
commit917d4b78b36d6c5a5c25a03e7ee6a1c1b6a85fd5 (patch)
treee652563203a00f8acecfaafbf93c64dbfbd13f25 /engines/sci/exereader.cpp
parent5f87d5090cfcb34cda3c1f5d430e0865344d7366 (diff)
parentdd7868acc2512c9761d892e67a4837f4dc38bdc0 (diff)
downloadscummvm-rg350-917d4b78b36d6c5a5c25a03e7ee6a1c1b6a85fd5.tar.gz
scummvm-rg350-917d4b78b36d6c5a5c25a03e7ee6a1c1b6a85fd5.tar.bz2
scummvm-rg350-917d4b78b36d6c5a5c25a03e7ee6a1c1b6a85fd5.zip
Merge with trunk
svn-id: r43701
Diffstat (limited to 'engines/sci/exereader.cpp')
-rw-r--r--engines/sci/exereader.cpp172
1 files changed, 0 insertions, 172 deletions
diff --git a/engines/sci/exereader.cpp b/engines/sci/exereader.cpp
index ce6bf184fb..fbeda66b45 100644
--- a/engines/sci/exereader.cpp
+++ b/engines/sci/exereader.cpp
@@ -96,62 +96,6 @@ Common::Platform getGameExePlatform(Common::SeekableReadStream *exeStream) {
return Common::kPlatformUnknown;
}
-bool isLZEXECompressed(Common::SeekableReadStream *exeStream) {
- uint32 filepos = 0;
-
- exeStream->seek(0, SEEK_SET);
-
- // First 2 bytes should be "MZ" (0x5A4D)
- if (exeStream->readUint16LE() != 0x5A4D) // at pos 0, +2
- return false;
-
- exeStream->skip(6);
-
- // Header size should be 2
- filepos = exeStream->readUint16LE();
- if (filepos != 2) // at pos 8, +2
- return false;
-
- exeStream->skip(12);
-
- // Calculate code segment offset in exe file
- filepos += exeStream->readUint16LE(); // at pos 22, +2
- filepos <<= 4;
-
- // First relocation item offset should be 0x1c
- if (exeStream->readUint16LE() != 0x1c) // at pos 24, +2
- return false;
-
- // Number of overlays should be 0
- if (exeStream->readUint16LE() != 0) // at pos 26, +2
- return false;
-
- // Look for LZEXE signature
- byte magic[4];
- exeStream->read(magic, 4);
-
- if (memcmp(magic, "LZ09", 4) && memcmp(magic, "LZ91", 4))
- return false;
-
- // Seek to offset 8 of info table at start of code segment
- exeStream->seek(filepos + 8, SEEK_SET);
- if (exeStream->err())
- return false;
-
- // Read size of compressed data in paragraphs
- uint16 size = exeStream->readUint16LE();
-
- // Move file pointer to start of compressed data
- filepos -= size << 4;
- exeStream->seek(filepos, SEEK_SET);
- if (exeStream->err())
- return false;
-
- // All conditions met, this is an LZEXE packed file
- // We are currently at the start of the compressed file data
- return true;
-}
-
uint getBit(Common::SeekableReadStream *input) {
uint bit = _bits & 1;
_bitCount--;
@@ -172,120 +116,4 @@ uint getBit(Common::SeekableReadStream *input) {
return bit;
}
-Common::String readSciVersionFromExe(Common::SeekableReadStream *exeStream, Common::Platform platform) {
- int len = exeStream->size();
- unsigned char *buffer = NULL;
-
- // Read the executable
- bool isLZEXE = isLZEXECompressed(exeStream);
-
- if (!isLZEXE) {
- buffer = new unsigned char[exeStream->size()];
-
- exeStream->seek(0, SEEK_SET);
- exeStream->read(buffer, exeStream->size());
- } else {
- buffer = new unsigned char[exeStream->size() * 3];
- _bitCount = 0;
-
- // Skip LZEXE header
- exeStream->seek(32, SEEK_SET);
-
- int pos = 0;
- int repeat;
- short offset;
-
- while (1) {
- if (exeStream->ioFailed()) {
- warning("Error reading from input file");
- delete[] buffer;
- return NULL;
- }
-
- if (getBit(exeStream)) {
- buffer[pos++] = exeStream->readByte();
- } else {
- if (getBit(exeStream)) {
- byte tmp[2];
- exeStream->read(tmp, 2);
- repeat = (tmp[1] & 0x07);
- offset = ((tmp[1] & ~0x07) << 5) | tmp[0] | 0xE000;
-
- if (repeat == 0) {
- repeat = exeStream->readByte();
-
- if (repeat == 0) {
- len = pos;
- break;
- }
- else if (repeat == 1)
- continue;
- else
- repeat++;
- } else
- repeat += 2;
- } else {
- repeat = getBit(exeStream) << 1;
- repeat += getBit(exeStream) + 2;
- offset = exeStream->readByte() | 0xFF00;
- }
-
- while (repeat > 0) {
- buffer[pos] = buffer[pos + offset];
- pos++;
- repeat--;
- }
- }
- }
- }
-
- // Find SCI version number
-
- int state = 0;
- /* 'state' encodes how far we have matched the version pattern
- ** "n.nnn.nnn"
- **
- ** n.nnn.nnn
- ** 0123456789
- **
- ** Since we cannot be certain that the pattern does not begin with an
- ** alphanumeric character, some states are ambiguous.
- ** The pattern is expected to be terminated with a non-alphanumeric
- ** character.
- */
-
-
- int accept;
- unsigned char *buf = buffer;
-
- // String-encoded result, copied from buffer
- char currentString[10];
-
- for (int i = 0; i < len; i++) {
- unsigned char ch = *buf++;
- // By default, we don't like this character
- accept = 0;
-
- if (isalnum(ch)) {
- accept = (state != 1 && state != 5 && state != 9);
- } else if (ch == '.') {
- accept = (state == 1 || state == 5);
- } else if (state == 9) {
- // Terminate string
- currentString[9] = 0;
-
- // Return the current string
- return currentString;
- }
-
- if (accept)
- currentString[state++] = ch;
- else
- state = 0;
- }
-
- delete[] buffer;
- return "unknown";
-}
-
} // End of namespace Sci