Skip to content

Commit ae181e0

Browse files
committed
TOOLS: Cleanup compress_sci.cpp
This commit removes unneeded memory allocation checks, It replaces hexadecimal file sizes with decimal file sizes. It cleans up the previous patch which added raw audio support
1 parent 12846bc commit ae181e0

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

engines/sci/compress_sci.cpp

+9-23
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ SciResourceDataType CompressSci::detectData(byte *header, bool compressMode) {
110110
_input.read_throwsOnError(&buffer[6], 8);
111111
dataSize = READ_LE_UINT32(buffer + 9);
112112
// HACK: LSL6 resource.aud has a SOL that specifies incorrect dataSize, we fix it here
113-
if ((_inputOffset == 0x619bf07) && (dataSize == 0x1dd78))
113+
if ((_inputOffset == 102350599) && (dataSize == 122232))
114114
dataSize--;
115-
if ((_inputOffset == 0x101DFBC5) && (dataSize == 0x1cfc1))
115+
if ((_inputOffset == 270400453) && (dataSize == 118721))
116116
dataSize--;
117117
_inputEndOffset = _inputOffset + 14 + dataSize;
118118
return kSciResourceDataTypeSOL;
@@ -249,8 +249,6 @@ void CompressSci::compressData(SciResourceDataType dataType) {
249249
error("Unable to read WAV at offset %lx", _inputOffset);
250250

251251
sampleData = new byte[sampleDataSize];
252-
if (!sampleData)
253-
error("malloc error");
254252
_input.read_throwsOnError(sampleData, sampleDataSize);
255253
if (sampleFlags & Audio::Mixer::FLAG_16BITS)
256254
sampleBits = 16;
@@ -268,8 +266,6 @@ void CompressSci::compressData(SciResourceDataType dataType) {
268266
_input.readByte();
269267
// Now we read SOL datastream
270268
sampleData = new byte[sampleDataSize];
271-
if (!sampleData)
272-
error("malloc error");
273269
_input.read_throwsOnError(sampleData, sampleDataSize);
274270

275271
bool dataUnsigned = false;
@@ -295,17 +291,13 @@ void CompressSci::compressData(SciResourceDataType dataType) {
295291
// No headers so just use the original data as sample data
296292
sampleDataSize = orgDataSize;
297293
sampleData = new byte[sampleDataSize];
298-
if (!sampleData)
299-
error("malloc error");
300294
_input.read_throwsOnError(sampleData, sampleDataSize);
301295
break;
302296
case kSciResourceTypeTypeSync:
303297
print("SYNC found at %lx\n", _inputOffset);
304298
// Simply copy original data over
305299
newDataSize = orgDataSize;
306300
newData = new byte[newDataSize];
307-
if (!newData)
308-
error("malloc error");
309301
_input.read_throwsOnError(newData, newDataSize);
310302
break;
311303
default:
@@ -325,8 +317,6 @@ void CompressSci::compressData(SciResourceDataType dataType) {
325317
Common::File tempfileEnc(TEMP_ENC, "rb");
326318
newDataSize = tempfileEnc.size();
327319
newData = new byte[newDataSize];
328-
if (!newData)
329-
error("malloc error");
330320
tempfileEnc.read_throwsOnError(newData, newDataSize);
331321
tempfileEnc.close();
332322
}
@@ -340,16 +330,12 @@ uint CompressSci::parseRawAudioMap() {
340330
// Assume the map is in the same dir as the resource file
341331
// and is called AUDIO001.MAP
342332
mapFileName.setFullName("AUDIO001.MAP");
343-
warning("Trying %s as resource map\n", mapFileName.getFullPath().data());
333+
print("Trying %s as resource map\n", mapFileName.getFullPath().data());
344334
Common::File mapFile;
345335
mapFile.open(mapFileName, "rb");
346-
// Ten byte entries, the last one is fake
347-
uint32 numEntries = (mapFile.size() / 10) - 1;
348336
uint32 offset = 0;
349-
for (uint32 i = 0; i < numEntries; i++) {
350-
// shouldn't reach the fake entry but break if we do
351-
if (mapFile.readUint16LE() == 0xffff)
352-
break;
337+
// Ten byte entries, the last is fake, stop when it's reached
338+
while (mapFile.readUint16LE() != 0xffff) {
353339
// mask out the resource volume number
354340
offset = mapFile.readUint32LE() & 0x0fffffff;
355341
_rawAudioMap[offset] = mapFile.readUint32LE();
@@ -382,8 +368,8 @@ void CompressSci::execute() {
382368
error("This resource file is already FLAC-compressed, aborting...\n");
383369

384370
int resourceCount = 0;
385-
if (_input.size() == 0x05C9B000 or _input.size() == 0x0160E000) {
386-
warning("Size matches KQ5 or Jones in the Fast Lane audio file, assuming raw audio\n");
371+
if (_input.size() == 97103872 || _input.size() == 23126016) {
372+
print("Size matches KQ5 or Jones in the Fast Lane audio file, assuming raw audio\n");
387373
_rawAudio = true;
388374
resourceCount = parseRawAudioMap();
389375
} else {
@@ -440,8 +426,8 @@ void CompressSci::execute() {
440426
compressData(recognizedDataType);
441427

442428
// raw files are 0-padded to 2048 bytes
443-
if (_rawAudio and _inputEndOffset % 2048)
444-
_inputEndOffset = (((_inputEndOffset >> 11) + 1) << 11) & 0xffffffff;
429+
if (_rawAudio)
430+
_inputEndOffset = (((_inputEndOffset - 1) >> 11) + 1) << 11;
445431

446432
// Seek inputfile to the end of the data
447433
_input.seek(_inputEndOffset, SEEK_SET);

0 commit comments

Comments
 (0)