Cleanup and unification. Merged decryptinit3() inside decrypt3()

svn-id: r39155
This commit is contained in:
Filippos Karapetis 2009-03-06 13:09:10 +00:00
parent b8a2b38e41
commit c4a09af0af
3 changed files with 8 additions and 14 deletions

View File

@ -238,19 +238,20 @@ int decompress0(Resource *result, Common::ReadStream &stream, int sci_version) {
uint16 compressedLength;
uint16 compressionMethod;
uint8 *buffer;
uint8 type;
result->id = stream.readUint16LE();
if (stream.err())
return SCI_ERROR_IO_ERROR;
result->number = result->id & 0x07ff;
uint8 type = result->id >> 11;
type = result->id >> 11;
result->type = (ResourceType)type;
if ((result->number > sci_max_resource_nr[sci_version]) || (type > kResourceTypeInvalid))
return SCI_ERROR_DECOMPRESSION_INSANE;
result->type = (ResourceType)type;
compressedLength = stream.readUint16LE();
result->size = stream.readUint16LE();
compressionMethod = stream.readUint16LE();
@ -259,7 +260,6 @@ int decompress0(Resource *result, Common::ReadStream &stream, int sci_version) {
if (result->size > SCI_MAX_RESOURCE_SIZE)
return SCI_ERROR_RESOURCE_TOO_BIG;
// With SCI0, this simply cannot happen.
if (compressedLength > 4)
compressedLength -= 4;

View File

@ -51,7 +51,8 @@ static int16 curtoken, endtoken;
uint32 gbits(int numbits, uint8 * data, int dlen);
void decryptinit3() {
int decrypt3(uint8 *dest, uint8 *src, int length, int complength) {
// Init
int i;
lastchar = lastbits = s_bitstring = stakptr = 0;
@ -65,9 +66,9 @@ void decryptinit3() {
tokens[i].next = 0;
tokens[i].data = 0;
}
}
int decrypt3(uint8 *dest, uint8 *src, int length, int complength) {
// Start decrypting
static int16 token;
while (length != 0) {
switch (decryptstart) {
@ -514,10 +515,6 @@ int decompress01(Resource *result, Common::ReadStream &stream, int sci_version)
if (stream.err())
return SCI_ERROR_IO_ERROR;
//if ((result->size < 0) || (compressedLength < 0))
// return SCI_ERROR_DECOMPRESSION_INSANE;
// This return will never happen in SCI0 or SCI1 (does it have any use?)
if (result->size > SCI_MAX_RESOURCE_SIZE)
return SCI_ERROR_RESOURCE_TOO_BIG;
@ -566,7 +563,6 @@ int decompress01(Resource *result, Common::ReadStream &stream, int sci_version)
case 2:
case 3:
case 4:
decryptinit3();
if (decrypt3(result->data, buffer, result->size, compressedLength)) {
overflow = true;
} else {

View File

@ -249,7 +249,6 @@ int unpackDCL(uint8* dest, uint8* src, int length, int complength) {
return 0;
}
void decryptinit3();
int decrypt3(uint8* dest, uint8* src, int length, int complength);
int decompress1(Resource *result, Common::ReadStream &stream, int sci_version) {
@ -349,7 +348,6 @@ int decompress1(Resource *result, Common::ReadStream &stream, int sci_version) {
case 2: // ???
case 3:
case 4:
decryptinit3();
if (decrypt3(result->data, buffer, result->size, compressedLength)) {
free(result->data);
result->data = 0; // So that we know that it didn't work