diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/scicore/decompressor.cpp | 114 | ||||
-rw-r--r-- | engines/sci/scicore/decompressor.h | 28 | ||||
-rw-r--r-- | engines/sci/scicore/resource.cpp | 173 | ||||
-rw-r--r-- | engines/sci/scicore/resource.h | 14 |
4 files changed, 169 insertions, 160 deletions
diff --git a/engines/sci/scicore/decompressor.cpp b/engines/sci/scicore/decompressor.cpp index 62ccd0ffbd..1bb83bf1d2 100644 --- a/engines/sci/scicore/decompressor.cpp +++ b/engines/sci/scicore/decompressor.cpp @@ -34,7 +34,7 @@ namespace Sci { int Decompressor::unpack(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked) { + uint32 nUnpacked) { return copyBytes(src, dest, nPacked); } @@ -50,7 +50,7 @@ int Decompressor::copyBytes(Common::ReadStream *src, Common::WriteStream *dest, return src->ioFailed() || dest->ioFailed() ? 1 : 0; } void Decompressor::init(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked) { + uint32 nUnpacked) { _src = src; _dest = dest; _szPacked = nPacked; @@ -62,7 +62,7 @@ void Decompressor::init(Common::ReadStream *src, Common::WriteStream *dest, uint void Decompressor::fetchBits() { while (_nBits <= 24) { - _dwBits |= ((uint32)_src->readByte()) << (24-_nBits); + _dwBits |= ((uint32)_src->readByte()) << (24 - _nBits); _nBits += 8; _dwRead++; } @@ -70,7 +70,7 @@ void Decompressor::fetchBits() { bool Decompressor::getBit() { // fetching more bits to _dwBits buffer - if (_nBits == 0) + if (_nBits == 0) fetchBits(); bool b = _dwBits & 0x80000000; _dwBits <<= 1; @@ -80,9 +80,9 @@ bool Decompressor::getBit() { uint32 Decompressor::getBits(int n) { // fetching more data to buffer if needed - if(_nBits < n) + if (_nBits < n) fetchBits(); - uint32 ret = _dwBits >> (32-n); + uint32 ret = _dwBits >> (32 - n); _dwBits <<= n; _nBits -= n; return ret; @@ -96,7 +96,7 @@ void Decompressor::putByte(byte b) { // Huffman decompressor //------------------------------- int DecompressorHuffman::unpack(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked) { + uint32 nUnpacked) { init(src, dest, nPacked, nUnpacked); byte numnodes; @@ -110,7 +110,7 @@ int DecompressorHuffman::unpack(Common::ReadStream *src, Common::WriteStream *de while ((c = getc2()) != terminator && (c >= 0) && (_szUnpacked-- > 0)) putByte(c); - + free(_nodes); return _dwWrote ? 0 : 1; } @@ -121,7 +121,7 @@ int16 DecompressorHuffman::getc2() { while (node[1]) { if (getBit()) { next = node[1] & 0x0F; // use lower 4 bits - if (next == 0) + if (next == 0) return getBits(8) | 0x100; } else next = node[1] >> 4; // use higher 4 bits @@ -136,7 +136,7 @@ int16 DecompressorHuffman::getc2() { //------------------------------- void DecompressorComp3::init(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, uint32 nUnpacked) { Decompressor::init(src, dest, nPacked, nUnpacked); - + _lastchar = _lastbits = _stakptr = 0; _numbits = 9; _curtoken = 0x102; @@ -145,7 +145,7 @@ void DecompressorComp3::init(Common::ReadStream *src, Common::WriteStream *dest, } int DecompressorComp3::unpack(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked) { + uint32 nUnpacked) { byte *buffer = NULL; byte *buffer2 = NULL; Common::MemoryWriteStream *pBuff = NULL; @@ -155,8 +155,8 @@ int DecompressorComp3::unpack(Common::ReadStream *src, Common::WriteStream *dest case kComp3: // Comp3 compression return doUnpack(src, dest, nPacked, nUnpacked); break; - case kComp3View: - case kComp3Pic: + case kComp3View: + case kComp3Pic: buffer = new byte[nUnpacked]; pBuff = new Common::MemoryWriteStream(buffer, nUnpacked); doUnpack(src, pBuff, nPacked, nUnpacked); @@ -164,8 +164,7 @@ int DecompressorComp3::unpack(Common::ReadStream *src, Common::WriteStream *dest buffer2 = new byte[nUnpacked]; view_reorder(buffer, buffer2); dest->write(buffer2, nUnpacked); - } - else { + } else { pBuffIn = new Common::MemoryReadStream(buffer, nUnpacked); reorderPic(pBuffIn, dest, nUnpacked); } @@ -173,13 +172,13 @@ int DecompressorComp3::unpack(Common::ReadStream *src, Common::WriteStream *dest delete[] buffer; delete pBuff; delete pBuffIn; - break; + break; } return 0; } int DecompressorComp3::doUnpack(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked) { + uint32 nUnpacked) { init(src, dest, nPacked, nUnpacked); byte decryptstart = 0; @@ -227,7 +226,7 @@ int DecompressorComp3::doUnpack(Common::ReadStream *src, Common::WriteStream *de } _lastchar = _stak[_stakptr++] = token & 0xff; // put stack in buffer - while (_stakptr > 0) { + while (_stakptr > 0) { putByte(_stak[--_stakptr]); if (--_szUnpacked == 0) { bExit = true; @@ -235,7 +234,7 @@ int DecompressorComp3::doUnpack(Common::ReadStream *src, Common::WriteStream *de } } // put token into record - if (_curtoken <= _endtoken) { + if (_curtoken <= _endtoken) { _tokens[_curtoken].data = _lastchar; _tokens[_curtoken].next = _lastbits; _curtoken++; @@ -321,12 +320,12 @@ int DecompressorComp3::rle_size(byte *rledata, int dsize) { int pos = 0; char nextbyte; int size = 0; - + while (pos < dsize) { nextbyte = *(rledata++); pos++; size++; - + switch (nextbyte & 0xC0) { case 0x40 : case 0x00 : @@ -348,7 +347,7 @@ void DecompressorComp3::reorderPic(Common::ReadStream *src, Common::WriteStream byte viewdata[7]; byte *cdata = NULL; byte *extra = NULL; - + // Setting palette dest->writeByte(PIC_OP_OPX); dest->writeByte(PIC_OPX_SET_PALETTE); @@ -362,7 +361,7 @@ void DecompressorComp3::reorderPic(Common::ReadStream *src, Common::WriteStream cdata_size = src->readUint16LE(); src->read(viewdata, sizeof(viewdata)); // Copy palette colors - copyBytes(src, dest, 1024); + copyBytes(src, dest, 1024); // copy drawing opcodes if (view_start != PAL_SIZE + 2) copyBytes(src, dest, view_start - PAL_SIZE - 2); @@ -371,7 +370,7 @@ void DecompressorComp3::reorderPic(Common::ReadStream *src, Common::WriteStream extra = new byte[dsize - view_size - view_start - EXTRA_MAGIC_SIZE]; src->read(extra, dsize - view_size - view_start - EXTRA_MAGIC_SIZE); } - // Writing picture cel opcode and header + // Writing picture cel opcode and header dest->writeByte(PIC_OP_OPX); dest->writeByte(PIC_OPX_EMBEDDED_VIEW); dest->writeByte(0); @@ -383,7 +382,7 @@ void DecompressorComp3::reorderPic(Common::ReadStream *src, Common::WriteStream cdata = new byte[cdata_size]; src->read(cdata, cdata_size); decodeRLE(src, dest, cdata, view_size); - // writing stored extra opcodes + // writing stored extra opcodes if (extra) dest->write(extra, dsize - view_size - view_start - EXTRA_MAGIC_SIZE); delete[] extra; @@ -393,7 +392,8 @@ void DecompressorComp3::reorderPic(Common::ReadStream *src, Common::WriteStream void DecompressorComp3::build_cel_headers(byte **seeker, byte **writer, int celindex, int *cc_lengths, int max) { for (int c = 0; c < max; c++) { memcpy(*writer, *seeker, 6); - *seeker += 6; *writer += 6; + *seeker += 6; + *writer += 6; int w = *((*seeker)++); WRITE_LE_UINT16(*writer, w); /* Zero extension */ *writer += 2; @@ -415,15 +415,15 @@ void DecompressorComp3::view_reorder(byte *inbuffer, byte *outbuffer) { char celcounts[100]; byte *writer = outbuffer; byte *lh_ptr; - byte *rle_ptr,*pix_ptr; + byte *rle_ptr, *pix_ptr; int l, lb, c, celindex, lh_last = -1; int chptr; int w; int *cc_lengths; byte **cc_pos; - + /* Parse the main header */ - cellengths = inbuffer+READ_LE_UINT16(seeker)+2; + cellengths = inbuffer + READ_LE_UINT16(seeker) + 2; seeker += 2; loopheaders = *(seeker++); lh_present = *(seeker++); @@ -436,12 +436,12 @@ void DecompressorComp3::view_reorder(byte *inbuffer, byte *outbuffer) { cel_total = READ_LE_UINT16(seeker); seeker += 2; - cc_pos = (byte **) malloc(sizeof(byte *)*cel_total); - cc_lengths = (int *) malloc(sizeof(int)*cel_total); - + cc_pos = (byte **) malloc(sizeof(byte *) * cel_total); + cc_lengths = (int *) malloc(sizeof(int) * cel_total); + for (c = 0; c < cel_total; c++) - cc_lengths[c] = READ_LE_UINT16(cellengths+2*c); - + cc_lengths[c] = READ_LE_UINT16(cellengths + 2 * c); + *writer++ = loopheaders; *writer++ = VIEW_HEADER_COLORS_8BIT; WRITE_LE_UINT16(writer, lh_mask); @@ -452,19 +452,19 @@ void DecompressorComp3::view_reorder(byte *inbuffer, byte *outbuffer) { writer += 2; lh_ptr = writer; - writer += 2*loopheaders; /* Make room for the loop offset table */ + writer += 2 * loopheaders; /* Make room for the loop offset table */ pix_ptr = writer; - + memcpy(celcounts, seeker, lh_present); seeker += lh_present; lb = 1; celindex = 0; - rle_ptr = pix_ptr = cellengths + (2*cel_total); + rle_ptr = pix_ptr = cellengths + (2 * cel_total); w = 0; - + for (l = 0; l < loopheaders; l++) { if (lh_mask & lb) { /* The loop is _not_ present */ if (lh_last == -1) { @@ -474,7 +474,7 @@ void DecompressorComp3::view_reorder(byte *inbuffer, byte *outbuffer) { WRITE_LE_UINT16(lh_ptr, lh_last); lh_ptr += 2; } else { - lh_last = writer-outbuffer; + lh_last = writer - outbuffer; WRITE_LE_UINT16(lh_ptr, lh_last); lh_ptr += 2; WRITE_LE_UINT16(writer, celcounts[w]); @@ -483,47 +483,47 @@ void DecompressorComp3::view_reorder(byte *inbuffer, byte *outbuffer) { writer += 2; /* Now, build the cel offset table */ - chptr = (writer - outbuffer) + (2*celcounts[w]); + chptr = (writer - outbuffer) + (2 * celcounts[w]); for (c = 0; c < celcounts[w]; c++) { WRITE_LE_UINT16(writer, chptr); writer += 2; cc_pos[celindex+c] = outbuffer + chptr; - chptr += 8 + READ_LE_UINT16(cellengths+2*(celindex+c)); + chptr += 8 + READ_LE_UINT16(cellengths + 2 * (celindex + c)); } build_cel_headers(&seeker, &writer, celindex, cc_lengths, celcounts[w]); - + celindex += celcounts[w]; w++; } - lb = lb << 1; - } + lb = lb << 1; + } if (celindex < cel_total) { warning("View decompression generated too few (%d / %d) headers", celindex, cel_total); return; } - + /* Figure out where the pixel data begins. */ for (c = 0; c < cel_total; c++) pix_ptr += rle_size(pix_ptr, cc_lengths[c]); - rle_ptr = cellengths + (2*cel_total); + rle_ptr = cellengths + (2 * cel_total); for (c = 0; c < cel_total; c++) - decode_rle(&rle_ptr, &pix_ptr, cc_pos[c]+8, cc_lengths[c]); + decode_rle(&rle_ptr, &pix_ptr, cc_pos[c] + 8, cc_lengths[c]); *writer++ = 'P'; *writer++ = 'A'; *writer++ = 'L'; - + for (c = 0; c < 256; c++) *writer++ = c; seeker -= 4; /* The missing four. Don't ask why. */ - memcpy(writer, seeker, 4*256+4); - + memcpy(writer, seeker, 4*256 + 4); + free(cc_pos); free(cc_lengths); } @@ -532,14 +532,14 @@ void DecompressorComp3::view_reorder(byte *inbuffer, byte *outbuffer) { // LZW 9-12 bits decompressor for SCI0 //---------------------------------------------- int DecompressorLZW::unpack(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked) { + uint32 nUnpacked) { init(src, dest, nPacked, nUnpacked); byte *buffin = new byte[nPacked]; byte *buffout = new byte[nUnpacked]; src->read(buffin, nPacked); - + doUnpack(buffin, buffout, nUnpacked, nPacked); - + dest->write(buffout, nUnpacked); delete[] buffin; delete[] buffout; @@ -603,7 +603,7 @@ int DecompressorLZW::doUnpack(byte *src, byte *dest, int length, int complength) #ifdef _SCI_DECOMPRESS_DEBUG // For me this seems a normal situation, It's necessary to handle it warning("unpackLZW: Trying to write beyond the end of array(len=%d, destctr=%d, tok_len=%d)", - length, destctr, tokenlastlength); + length, destctr, tokenlastlength); #endif i = 0; for (; destctr < length; destctr++) { @@ -680,14 +680,14 @@ static int ascii_tree[] = { #define CALLC(x) { if ((x) == -SCI_ERROR_DECOMPRESSION_OVERFLOW) return -SCI_ERROR_DECOMPRESSION_OVERFLOW; } int DecompressorDCL::unpack(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked) { + uint32 nUnpacked) { init(src, dest, nPacked, nUnpacked); byte *buffin = new byte[nPacked]; byte *buffout = new byte[nUnpacked]; src->read(buffin, nPacked); - + unpackDCL(buffin, buffout, nUnpacked, nPacked); - + dest->write(buffout, nUnpacked); delete[] buffin; delete[] buffout; diff --git a/engines/sci/scicore/decompressor.h b/engines/sci/scicore/decompressor.h index bf2822a48c..b5493d2630 100644 --- a/engines/sci/scicore/decompressor.h +++ b/engines/sci/scicore/decompressor.h @@ -34,7 +34,7 @@ enum ResourceCompression { kCompNone = 0, kCompLZW, kCompHuffman, - kComp3, // LZW-like compression used in SCI01 and SCI1 + kComp3, // LZW-like compression used in SCI01 and SCI1 kComp3View, // Comp3 + view Post-processing kComp3Pic, // Comp3 + pic Post-processing kCompDCL, @@ -42,19 +42,19 @@ enum ResourceCompression { }; //---------------------------------------------- // Base class for decompressors -// Simply copies nPacked bytes from src to dest +// Simply copies nPacked bytes from src to dest //---------------------------------------------- class Decompressor { public: - Decompressor(){} - virtual ~Decompressor(){} + Decompressor() {} + virtual ~Decompressor() {} //! get a number of bits from _src stream /** @param n - number of bits to get @return (uint32) n-bits number */ virtual int unpack(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked); + uint32 nUnpacked); protected: //! Initialize decompressor @@ -65,7 +65,7 @@ protected: @return (int) 0 on success, non-zero on error */ virtual void init(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked); //! get one bit from _src stream + uint32 nUnpacked); //! get one bit from _src stream /** @return (bool) bit; */ virtual bool getBit(); @@ -99,7 +99,7 @@ protected: class DecompressorHuffman : public Decompressor { public: int unpack(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked); + uint32 nUnpacked); protected: int16 getc2(); @@ -118,7 +118,7 @@ public: } void init(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, uint32 nUnpacked); int unpack(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked); + uint32 nUnpacked); protected: enum { @@ -128,11 +128,11 @@ protected: }; // actual unpacking procedure int doUnpack(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked); - // functions to post-process view and pic resources + uint32 nUnpacked); + // functions to post-process view and pic resources void decodeRLE(Common::ReadStream *src, Common::WriteStream *dest, byte *pixeldata, uint16 size); void reorderPic(Common::ReadStream *src, Common::WriteStream *dest, int dsize); - // + // void decode_rle(byte **rledata, byte **pixeldata, byte *outbuffer, int size); int rle_size(byte *rledata, int dsize); void build_cel_headers(byte **seeker, byte **writer, int celindex, int *cc_lengths, int max); @@ -141,7 +141,7 @@ protected: struct tokenlist { byte data; uint16 next; - } _tokens[0x1004]; + } _tokens[0x1004]; byte _stak[0x1014]; byte _lastchar; uint16 _stakptr; @@ -158,7 +158,7 @@ class DecompressorLZW : public Decompressor { public: // void init(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, uint32 nUnpacked); int unpack(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked); + uint32 nUnpacked); protected: int doUnpack(byte *src, byte *dest, int length, int complength); @@ -173,7 +173,7 @@ class DecompressorDCL : public Decompressor { public: // void init(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, uint32 nUnpacked); int unpack(Common::ReadStream *src, Common::WriteStream *dest, uint32 nPacked, - uint32 nUnpacked); + uint32 nUnpacked); protected: int unpackDCL(byte *src, byte *dest, int length, int complength); diff --git a/engines/sci/scicore/resource.cpp b/engines/sci/scicore/resource.cpp index b027fb39e8..2658648d5e 100644 --- a/engines/sci/scicore/resource.cpp +++ b/engines/sci/scicore/resource.cpp @@ -109,7 +109,7 @@ Resource::Resource() { Resource::~Resource() { delete[] data; - if(source && source->source_type == kSourcePatch) + if (source && source->source_type == kSourcePatch) delete source; } @@ -185,7 +185,7 @@ ResourceSource *ResourceManager::getVolume(ResourceSource *map, int volume_nr) { bool ResourceManager::loadFromPatchFile(Resource *res) { Common::File file; - const char *filename=res->source->location_name.c_str(); + const char *filename = res->source->location_name.c_str(); if (file.open(filename) == false) { warning("Failed to open patch file %s", filename); res->unalloc(); @@ -225,7 +225,7 @@ void ResourceManager::loadResource(Resource *res) { int error = decompress(res, &file); if (error) { warning("Error %d occured while reading %s.%03d from resource file: %s\n", - error, getResourceTypeName(res->type), res->number, sci_error_types[error]); + error, getResourceTypeName(res->type), res->number, sci_error_types[error]); res->unalloc(); } @@ -345,7 +345,7 @@ int ResourceManager::scanNewSources(ResourceSource *source) { case kSourceExtMap: if (_mapVersion < SCI_VERSION_1) resource_error = readResourceMapSCI0(source); - else + else resource_error = readResourceMapSCI1(source, getVolume(source, 0)); if (resource_error == SCI_ERROR_RESMAP_NOT_FOUND) { // FIXME: Try reading w/o resource.map @@ -409,7 +409,7 @@ ResourceManager::ResourceManager(int version, int maxMemory) { } break; case SCI_VERSION_01_VGA_ODD: - version = _mapVersion; + version = _mapVersion; break; case SCI_VERSION_1: { Resource *res = testResource(kResourceTypeScript, 0); @@ -433,23 +433,32 @@ ResourceManager::ResourceManager(int version, int maxMemory) { // temporary version printout - should be reworked later switch (_sciVersion) { case SCI_VERSION_0: - debug("Resmgr: Detected SCI0"); break; + debug("Resmgr: Detected SCI0"); + break; case SCI_VERSION_01: - debug("Resmgr: Detected SCI01"); break; + debug("Resmgr: Detected SCI01"); + break; case SCI_VERSION_01_VGA: - debug("Resmgr: Detected SCI01VGA - KQ5 or similar"); break; + debug("Resmgr: Detected SCI01VGA - KQ5 or similar"); + break; case SCI_VERSION_01_VGA_ODD: - debug("Resmgr: Detected SCI01VGA - Jones/CD or similar"); break; + debug("Resmgr: Detected SCI01VGA - Jones/CD or similar"); + break; case SCI_VERSION_1_EARLY: - debug("Resmgr: Detected SCI1 Early"); break; + debug("Resmgr: Detected SCI1 Early"); + break; case SCI_VERSION_1_LATE: - debug("Resmgr: Detected SCI1 Late"); break; + debug("Resmgr: Detected SCI1 Late"); + break; case SCI_VERSION_1_1: - debug("Resmgr: Detected SCI1.1"); break; + debug("Resmgr: Detected SCI1.1"); + break; case SCI_VERSION_32: - debug("Resmgr: Couldn't determine SCI version"); break; + debug("Resmgr: Couldn't determine SCI version"); + break; default: - debug("Resmgr: Couldn't determine SCI version"); break; + debug("Resmgr: Couldn't determine SCI version"); + break; } } @@ -483,8 +492,8 @@ void ResourceManager::addToLRU(Resource *res) { _memoryLRU += res->size; #if (SCI_VERBOSE_RESMGR > 1) debug("Adding %s.%03d (%d bytes) to lru control: %d bytes total", - getResourceTypeName(res->type), res->number, res->size, - mgr->_memoryLRU); + getResourceTypeName(res->type), res->number, res->size, + mgr->_memoryLRU); #endif res->status = kResStatusEnqueued; @@ -499,7 +508,7 @@ void ResourceManager::printLRU() { while (it != _LRU.end()) { res = *it; debug("\t%s.%03d: %d bytes", getResourceTypeName(res->type), - res->number, res->size); + res->number, res->size); mem += res->size; entries ++; it ++; @@ -609,7 +618,7 @@ int ResourceManager::detectMapVersion() { rsrc = rsrc->next; } if (file.isOpen() == false) { - warning("Failed to open resource map file"); + warning("Failed to open resource map file"); return SCI_VERSION_AUTODETECT; } // detection @@ -625,7 +634,7 @@ int ResourceManager::detectMapVersion() { } return SCI_VERSION_0; } - // SCI1E/L and some SCI1.1 maps have last directory entry set to 0xFF + // SCI1E/L and some SCI1.1 maps have last directory entry set to 0xFF // and offset set to filesize // SCI1 have 6-bytes entries, while SCI1.1 have 5-byte entries file.seek(1, SEEK_SET); @@ -668,7 +677,7 @@ int ResourceManager::detectVolVersion() { rsrc = rsrc->next; } if (file.isOpen() == false) { - warning("Failed to open volume file"); + warning("Failed to open volume file"); return SCI_VERSION_AUTODETECT; } // SCI0 volume format: {wResId wPacked+4 wUnpacked wCompression} = 8 bytes @@ -680,15 +689,15 @@ int ResourceManager::detectVolVersion() { uint16 resId, wCompression; uint32 dwPacked, dwUnpacked; bool bFailed = false; - while(!file.eos() && !bFailed && file.pos() < 0x100000) { + while (!file.eos() && !bFailed && file.pos() < 0x100000) { resId = file.readUint16LE(); dwPacked = file.readUint16LE(); dwUnpacked = file.readUint16LE(); wCompression = file.readUint16LE(); - if(file.eos()) + if (file.eos()) break; - if ((wCompression > 4) || (wCompression == 0 && dwPacked != dwUnpacked + 4) - || (dwUnpacked < dwPacked - 4)) { + if ((wCompression > 4) || (wCompression == 0 && dwPacked != dwUnpacked + 4) + || (dwUnpacked < dwPacked - 4)) { bFailed = true; break; } @@ -700,17 +709,17 @@ int ResourceManager::detectVolVersion() { // Check for SCI1 format bFailed = false; file.seek(0, SEEK_SET); - while(!file.eos() && !bFailed && file.pos() < 0x100000) { + while (!file.eos() && !bFailed && file.pos() < 0x100000) { pos = file.pos(); - file.seek(1, SEEK_CUR); + file.seek(1, SEEK_CUR); resId = file.readUint16LE(); dwPacked = file.readUint16LE(); dwUnpacked = file.readUint16LE(); wCompression = file.readUint16LE(); - if(file.eos()) + if (file.eos()) break; - if ((wCompression > 20) || (wCompression == 0 && dwPacked != dwUnpacked + 4) - || (dwUnpacked < dwPacked - 4)) { + if ((wCompression > 20) || (wCompression == 0 && dwPacked != dwUnpacked + 4) + || (dwUnpacked < dwPacked - 4)) { bFailed = true; break; } @@ -722,17 +731,17 @@ int ResourceManager::detectVolVersion() { // Check for SCI1.1 format bFailed = false; file.seek(0, SEEK_SET); - while(!file.eos() && !bFailed && file.pos() < 0x100000) { + while (!file.eos() && !bFailed && file.pos() < 0x100000) { pos = file.pos(); - file.seek(1, SEEK_CUR); + file.seek(1, SEEK_CUR); resId = file.readUint16LE(); dwPacked = file.readUint16LE(); dwUnpacked = file.readUint16LE(); wCompression = file.readUint16LE(); - if(file.eos()) + if (file.eos()) break; - if ((wCompression > 20) || (wCompression == 0 && dwPacked != dwUnpacked) - || (dwUnpacked < dwPacked)) { + if ((wCompression > 20) || (wCompression == 0 && dwPacked != dwUnpacked) + || (dwUnpacked < dwPacked)) { bFailed = true; break; } @@ -744,18 +753,18 @@ int ResourceManager::detectVolVersion() { // Check for SCI32 v2 format (Gabriel Knight 1 CD) bFailed = false; file.seek(0, SEEK_SET); - while(!file.eos() && !bFailed && file.pos() < 0x100000) { + while (!file.eos() && !bFailed && file.pos() < 0x100000) { pos = file.pos(); - file.seek(1, SEEK_CUR); + file.seek(1, SEEK_CUR); resId = file.readUint16LE(); dwPacked = file.readUint32LE(); dwUnpacked = file.readUint32LE(); wCompression = file.readUint16LE(); - if(file.eos()) + if (file.eos()) break; - if ((wCompression != 0 && wCompression != 32) - || (wCompression == 0 && dwPacked != dwUnpacked) - || (dwUnpacked < dwPacked)) { + if ((wCompression != 0 && wCompression != 32) + || (wCompression == 0 && dwPacked != dwUnpacked) + || (dwUnpacked < dwPacked)) { bFailed = true; break; } @@ -770,7 +779,7 @@ int ResourceManager::detectVolVersion() { // version-agnostic patch application void ResourceManager::processPatch(ResourceSource *source, - const char *filename, ResourceType restype, int resnumber) { + const char *filename, ResourceType restype, int resnumber) { Common::File file; Resource *newrsc; uint32 resId = RESOURCE_HASH(restype, resnumber); @@ -788,7 +797,7 @@ void ResourceManager::processPatch(ResourceSource *source, debug("Patching %s failed - file too small", filename); return; } - + patchtype = file.readByte() & 0x7F; patch_data_offset = file.readByte(); @@ -798,14 +807,14 @@ void ResourceManager::processPatch(ResourceSource *source, } if (patch_data_offset + 2 >= fsize) { debug("Patching %s failed - patch starting at offset %d can't be in file of size %d", - filename, patch_data_offset + 2, fsize); + filename, patch_data_offset + 2, fsize); return; } // Prepare destination, if neccessary if (_resMap.contains(resId) == false) { newrsc = new Resource; _resMap.setVal(resId, newrsc); - } else + } else newrsc = _resMap.getVal(resId); // Overwrite everything, because we're patching newrsc->id = resId; @@ -874,7 +883,7 @@ int ResourceManager::readResourceMapSCI0(ResourceSource *map) { file.seek(0, SEEK_SET); - byte bMask = _mapVersion == SCI_VERSION_01_VGA_ODD ? 0xF0: 0xFC; + byte bMask = _mapVersion == SCI_VERSION_01_VGA_ODD ? 0xF0 : 0xFC; byte bShift = _mapVersion == SCI_VERSION_01_VGA_ODD ? 28 : 26; do { @@ -886,7 +895,7 @@ int ResourceManager::readResourceMapSCI0(ResourceSource *map) { perror(""); return SCI_ERROR_RESMAP_NOT_FOUND; } - if(offset == 0xFFFFFFFF) + if (offset == 0xFFFFFFFF) break; type = (ResourceType)(id >> 11); @@ -924,7 +933,7 @@ int ResourceManager::readResourceMapSCI1(ResourceSource *map, ResourceSource *vo type = file.readByte() & 0x1F; resMap[type].wOffset = file.readUint16LE(); resMap[prevtype].wSize = (resMap[type].wOffset - - resMap[prevtype].wOffset) / nEntrySize; + - resMap[prevtype].wOffset) / nEntrySize; prevtype = type; } while (type != 0x1F); // the last entry is FF @@ -961,8 +970,8 @@ int ResourceManager::readResourceMapSCI1(ResourceSource *map, ResourceSource *vo return 0; } -int ResourceManager::readResourceInfo(Resource *res, Common::File *file, - uint32&szPacked, ResourceCompression &compression) { +int ResourceManager::readResourceInfo(Resource *res, Common::File *file, + uint32&szPacked, ResourceCompression &compression) { // SCI0 volume format: {wResId wPacked+4 wUnpacked wCompression} = 8 bytes // SCI1 volume format: {bResType wResNumber wPacked+4 wUnpacked wCompression} = 9 bytes // SCI1.1 volume format: {bResType wResNumber wPacked wUnpacked wCompression} = 9 bytes @@ -1015,36 +1024,36 @@ int ResourceManager::readResourceInfo(Resource *res, Common::File *file, if (wCompression == 0) compression = kCompNone; switch (_sciVersion) { - case SCI_VERSION_0: - if (wCompression == 1) - compression = kCompLZW; - else if (wCompression == 2) - compression = kCompHuffman; - break; - case SCI_VERSION_01: - case SCI_VERSION_01_VGA: - case SCI_VERSION_01_VGA_ODD: - case SCI_VERSION_1_EARLY: - case SCI_VERSION_1_LATE: - if (wCompression == 1) - compression = kCompHuffman; - else if (wCompression == 2) - compression = kComp3; - else if (wCompression == 3) - compression = kComp3View; - else if (wCompression == 4) - compression = kComp3Pic; - break; - case SCI_VERSION_1_1: - if (wCompression >= 18 && wCompression <= 20) - compression = kCompDCL; - break; - case SCI_VERSION_32: - if (wCompression == 32) - compression = kCompSTACpack; - break; - default: - compression = kCompUnknown; + case SCI_VERSION_0: + if (wCompression == 1) + compression = kCompLZW; + else if (wCompression == 2) + compression = kCompHuffman; + break; + case SCI_VERSION_01: + case SCI_VERSION_01_VGA: + case SCI_VERSION_01_VGA_ODD: + case SCI_VERSION_1_EARLY: + case SCI_VERSION_1_LATE: + if (wCompression == 1) + compression = kCompHuffman; + else if (wCompression == 2) + compression = kComp3; + else if (wCompression == 3) + compression = kComp3View; + else if (wCompression == 4) + compression = kComp3Pic; + break; + case SCI_VERSION_1_1: + if (wCompression >= 18 && wCompression <= 20) + compression = kCompDCL; + break; + case SCI_VERSION_32: + if (wCompression == 32) + compression = kCompSTACpack; + break; + default: + compression = kCompUnknown; } return compression == kCompUnknown ? SCI_ERROR_UNKNOWN_COMPRESSION : 0; @@ -1085,14 +1094,14 @@ int ResourceManager::decompress(Resource *res, Common::File *file) { getResourceTypeName(res->type), res->number, compression); break; } - + if (dec) { res->data = new byte[res->size]; pDest = new Common::MemoryWriteStream(res->data , res->size); error = dec->unpack(file, pDest, szPacked, res->size); - } else + } else error = SCI_ERROR_UNKNOWN_COMPRESSION; - + if (!error) res->status = kResStatusAllocated; else { diff --git a/engines/sci/scicore/resource.h b/engines/sci/scicore/resource.h index 4cf0de3ad3..a88b7358a8 100644 --- a/engines/sci/scicore/resource.h +++ b/engines/sci/scicore/resource.h @@ -33,7 +33,7 @@ #include "sci/scicore/decompressor.h" namespace Common { - class ReadStream; +class ReadStream; } namespace Sci { @@ -43,7 +43,7 @@ namespace Sci { /*** RESOURCE STATUS TYPES ***/ enum ResourceStatus { - kResStatusNoMalloc=0, + kResStatusNoMalloc = 0, kResStatusAllocated, kResStatusEnqueued, /* In the LRU queue */ kResStatusLocked /* Allocated and in use */ @@ -97,7 +97,7 @@ enum ResSourceType { #define RESSOURCE_ADDRESSING_EXTENDED 128 #define RESSOURCE_ADDRESSING_MASK 128 -#define RESOURCE_HASH(type, number) (uint32)((type<<16) | number) +#define RESOURCE_HASH(type, number) (uint32)((type<<16) | number) #define SCI0_RESMAP_ENTRIES_SIZE 6 #define SCI1_RESMAP_ENTRIES_SIZE 6 #define SCI11_RESMAP_ENTRIES_SIZE 5 @@ -167,9 +167,9 @@ public: byte *data; uint16 number; ResourceType type; - uint32 id; // contains number and type. - // TODO: maybe use uint32 and set id = RESOURCE_HASH() - // for all SCI versions + uint32 id; // contains number and type. + // TODO: maybe use uint32 and set id = RESOURCE_HASH() + // for all SCI versions unsigned int size; unsigned int file_offset; /* Offset in file */ ResourceStatus status; @@ -212,7 +212,7 @@ public: * @return A pointer to the added source structure, or NULL if an error occurred. */ ResourceSource *addVolume(ResourceSource *map, const char *filename, - int number, int extended_addressing); + int number, int extended_addressing); //! Add an external (i.e. separate file) map resource to the resource manager's list of sources. /** @param file_name The name of the volume to add |