diff -ruN scummvm-20090214-orig/engines/sword1/objectman.cpp scummvm-20090214/engines/sword1/objectman.cpp
old
|
new
|
|
101 | 101 | |
102 | 102 | char *ObjectMan::lockText(uint32 textId) { |
103 | 103 | uint8 lang = SwordEngine::_systemVars.language; |
104 | | char *addr = (char*)_resMan->openFetchRes(_textList[textId / ITM_PER_SEC][lang]) + sizeof(Header); |
| 104 | char *addr = (char*)_resMan->openFetchRes(_textList[textId / ITM_PER_SEC][lang]); |
| 105 | if (addr == 0) |
| 106 | return _errorStr; |
| 107 | addr += sizeof(Header); |
105 | 108 | if ((textId & ITM_ID) >= _resMan->readUint32(addr)) { |
106 | 109 | warning("ObjectMan::lockText(%d): only %d texts in file", textId & ITM_ID, _resMan->readUint32(addr)); |
107 | 110 | textId = 0; // get first line instead |
diff -ruN scummvm-20090214-orig/engines/sword1/resman.cpp scummvm-20090214/engines/sword1/resman.cpp
old
|
new
|
|
199 | 199 | |
200 | 200 | void *ResMan::fetchRes(uint32 id) { |
201 | 201 | MemHandle *memHandle = resHandle(id); |
| 202 | if (!memHandle) { |
| 203 | warning("fetchRes:: resource %d out of bounds!", id); |
| 204 | return NULL; |
| 205 | } |
202 | 206 | if (!memHandle->data) |
203 | 207 | error("fetchRes:: resource %d is not open!", id); |
204 | 208 | return memHandle->data; |
… |
… |
|
216 | 220 | if (outf.open(outn)) { |
217 | 221 | resOpen(id); |
218 | 222 | MemHandle *memHandle = resHandle(id); |
219 | | outf.write(memHandle->data, memHandle->size); |
220 | | outf.close(); |
| 223 | if (memHandle) { |
| 224 | outf.write(memHandle->data, memHandle->size); |
| 225 | outf.close(); |
| 226 | } |
221 | 227 | resClose(id); |
222 | 228 | } |
223 | 229 | } |
… |
… |
|
244 | 250 | #else |
245 | 251 | openCptResourceLittleEndian(id); |
246 | 252 | #endif |
247 | | return resHandle(id)->data; |
| 253 | MemHandle *handle = resHandle(id); |
| 254 | return handle != NULL ? handle->data : NULL; |
248 | 255 | } |
249 | 256 | |
250 | 257 | void ResMan::resOpen(uint32 id) { // load resource ID into memory |
251 | 258 | MemHandle *memHandle = resHandle(id); |
| 259 | if (!memHandle) |
| 260 | return; |
252 | 261 | if (memHandle->cond == MEM_FREED) { // memory has been freed |
253 | 262 | uint32 size = resLength(id); |
254 | 263 | _memMan->alloc(memHandle, size); |
… |
… |
|
270 | 279 | |
271 | 280 | void ResMan::resClose(uint32 id) { |
272 | 281 | MemHandle *handle = resHandle(id); |
| 282 | if (!handle) |
| 283 | return; |
273 | 284 | if (!handle->refCount) { |
274 | 285 | warning("Resource Manager fail: unlocking object with refCount 0. Id: %d\n", id); |
275 | 286 | } else { |
… |
… |
|
313 | 324 | else |
314 | 325 | sprintf(fileName, "%s.CLU", _prj.clu[(id >> 24)-1].label); |
315 | 326 | cluster->file->open(fileName); |
316 | | |
317 | 327 | if (!cluster->file->isOpen()) { |
318 | 328 | char msg[512]; |
319 | 329 | sprintf(msg, "Couldn't open game cluster file '%s'\n\nIf you are running from CD, please ensure you have read the ScummVM documentation regarding multi-cd games.", fileName); |
… |
… |
|
340 | 350 | uint8 cluster = (uint8)((id >> 24) - 1); |
341 | 351 | uint8 group = (uint8)(id >> 16); |
342 | 352 | |
| 353 | // There is a know case of reading beyond array boundaries when trying to use |
| 354 | // portuguese subtitles (cluster file 2, group 6) with a version that do not |
| 355 | // contain subtitles for this languages (i.e. has only 6 languages and not 7). |
| 356 | if (cluster >= _prj.noClu || group >= _prj.clu[cluster].noGrp) |
| 357 | return NULL; |
| 358 | |
343 | 359 | return &(_prj.clu[cluster].grp[group].resHandle[id & 0xFFFF]); |
344 | 360 | } |
345 | 361 | |
… |
… |
|
349 | 365 | uint8 cluster = (uint8)((id >> 24) - 1); |
350 | 366 | uint8 group = (uint8)(id >> 16); |
351 | 367 | |
| 368 | if (cluster >= _prj.noClu || group >= _prj.clu[cluster].noGrp) |
| 369 | return 0; |
| 370 | |
352 | 371 | return _prj.clu[cluster].grp[group].length[id & 0xFFFF]; |
353 | 372 | } |
354 | 373 | |
… |
… |
|
357 | 376 | id = _srIdList[id & 0xFFFF]; |
358 | 377 | uint8 cluster = (uint8)((id >> 24) - 1); |
359 | 378 | uint8 group = (uint8)(id >> 16); |
| 379 | |
| 380 | if (cluster >= _prj.noClu || group >= _prj.clu[cluster].noGrp) |
| 381 | return 0; |
360 | 382 | |
361 | 383 | return _prj.clu[cluster].grp[group].offset[id & 0xFFFF]; |
362 | 384 | } |
… |
… |
|
368 | 390 | // If the resource are not in memory anymore, and therefore will be read |
369 | 391 | // from disk, they will need to be byte swaped. |
370 | 392 | MemHandle *memHandle = resHandle(id); |
371 | | needByteSwap = (memHandle->cond == MEM_FREED); |
| 393 | if (memHandle) |
| 394 | needByteSwap = (memHandle->cond == MEM_FREED); |
372 | 395 | } |
373 | 396 | resOpen(id); |
374 | 397 | if (needByteSwap) { |
375 | 398 | MemHandle *handle = resHandle(id); |
| 399 | if (!handle) |
| 400 | return; |
376 | 401 | uint32 totSize = handle->size; |
377 | 402 | uint32 *data = (uint32*)((uint8*)handle->data + sizeof(Header)); |
378 | 403 | totSize -= sizeof(Header); |
… |
… |
|
393 | 418 | // If the resource are not in memory anymore, and therefore will be read |
394 | 419 | // from disk, they will need to be byte swaped. |
395 | 420 | MemHandle *memHandle = resHandle(id); |
396 | | needByteSwap = (memHandle->cond == MEM_FREED); |
| 421 | if (memHandle) |
| 422 | needByteSwap = (memHandle->cond == MEM_FREED); |
397 | 423 | } |
398 | 424 | resOpen(id); |
399 | 425 | if (needByteSwap) { |
400 | 426 | MemHandle *handle = resHandle(id); |
| 427 | if (!handle) |
| 428 | return; |
401 | 429 | uint32 totSize = handle->size; |
402 | 430 | uint32 *data = (uint32*)((uint8*)handle->data + sizeof(Header)); |
403 | 431 | totSize -= sizeof(Header); |
… |
… |
|
418 | 446 | // If the resource are not in memory anymore, and therefore will be read |
419 | 447 | // from disk, they will need to be byte swaped. |
420 | 448 | MemHandle *memHandle = resHandle(id); |
421 | | needByteSwap = (memHandle->cond == MEM_FREED); |
| 449 | if (memHandle) |
| 450 | needByteSwap = (memHandle->cond == MEM_FREED); |
422 | 451 | } |
423 | 452 | resOpen(id); |
424 | 453 | if (needByteSwap) { |
425 | 454 | MemHandle *handle = resHandle(id); |
| 455 | if (!handle) |
| 456 | return; |
426 | 457 | // uint32 totSize = handle->size; |
427 | 458 | Header *head = (Header*)handle->data; |
428 | 459 | head->comp_length = FROM_LE_32(head->comp_length); |
… |
… |
|
447 | 478 | // If the resource are not in memory anymore, and therefore will be read |
448 | 479 | // from disk, they will need to be byte swaped. |
449 | 480 | MemHandle *memHandle = resHandle(id); |
450 | | needByteSwap = (memHandle->cond == MEM_FREED); |
| 481 | if (memHandle) |
| 482 | needByteSwap = (memHandle->cond == MEM_FREED); |
451 | 483 | } |
452 | 484 | resOpen(id); |
453 | 485 | if (needByteSwap) { |
454 | 486 | MemHandle *handle = resHandle(id); |
| 487 | if (!handle) |
| 488 | return; |
455 | 489 | // uint32 totSize = handle->size; |
456 | 490 | Header *head = (Header*)handle->data; |
457 | 491 | head->comp_length = FROM_BE_32(head->comp_length); |