diff options
author | Strangerke | 2016-12-06 23:08:32 -0800 |
---|---|---|
committer | Eugene Sandulenko | 2017-01-25 22:42:12 +0100 |
commit | 550d62b25afe533c1258442ac2ec41a8c8e2d1e6 (patch) | |
tree | 4f1f4e9ec10348be42cde65fd81fde939c528eff /engines/cryo | |
parent | e76e4c813685c50f38068332139ded34cb6a181f (diff) | |
download | scummvm-rg350-550d62b25afe533c1258442ac2ec41a8c8e2d1e6.tar.gz scummvm-rg350-550d62b25afe533c1258442ac2ec41a8c8e2d1e6.tar.bz2 scummvm-rg350-550d62b25afe533c1258442ac2ec41a8c8e2d1e6.zip |
CRYO: rewrite the loading of pak file header
Diffstat (limited to 'engines/cryo')
-rw-r--r-- | engines/cryo/cryolib.cpp | 10 | ||||
-rw-r--r-- | engines/cryo/defs.h | 23 | ||||
-rw-r--r-- | engines/cryo/eden.cpp | 65 | ||||
-rw-r--r-- | engines/cryo/eden.h | 2 |
4 files changed, 61 insertions, 39 deletions
diff --git a/engines/cryo/cryolib.cpp b/engines/cryo/cryolib.cpp index dd7afe9fd1..afbadb31ae 100644 --- a/engines/cryo/cryolib.cpp +++ b/engines/cryo/cryolib.cpp @@ -438,4 +438,14 @@ void CRYOLib_ManagersDone() { g_system->getTimerManager()->removeTimerProc(CLTimer_Action); } +PakHeaderNode::PakHeaderNode(int count) { + _count = count; + _files = new PakHeaderItem[count]; +}; + +PakHeaderNode::~PakHeaderNode() { + _count = 0; + delete[] _files; +}; + } // End of namespace Cryo diff --git a/engines/cryo/defs.h b/engines/cryo/defs.h index 6e8d9fa53f..76e9cae25e 100644 --- a/engines/cryo/defs.h +++ b/engines/cryo/defs.h @@ -762,19 +762,22 @@ struct global_t { }; typedef struct global_t global_t; -struct pakfile_t { - char name[16]; - int32 size; - int32 offs; - char flag; +struct PakHeaderItem { + Common::String _name; //[16]; + int32 _size; + int32 _offs; + char _flag; }; -typedef struct pakfile_t pakfile_t; +typedef struct PakHeaderItem PakHeaderItem; -struct pak_t { - uint16 count; - pakfile_t files[10]; +class PakHeaderNode { +public: + PakHeaderNode(int count); + ~PakHeaderNode(); + + uint16 _count; + PakHeaderItem* _files; }; -typedef struct pak_t pak_t; #pragma pack(pop) struct cita_t { diff --git a/engines/cryo/eden.cpp b/engines/cryo/eden.cpp index 32c9e73c58..3e93bbf54c 100644 --- a/engines/cryo/eden.cpp +++ b/engines/cryo/eden.cpp @@ -101,7 +101,6 @@ EdenGame::EdenGame(CryoEngine *vm) : _vm(vm) { bank_data_buf = nullptr; _gameIcons = nullptr; gameRooms = nullptr; - bigfile_header = nullptr; glow_buffer = nullptr; gameFont = nullptr; p_global = nullptr; @@ -4662,10 +4661,19 @@ void EdenGame::verifh(void *ptr) { } void EdenGame::openbigfile() { - assert(sizeof(pakfile_t) == 25); - int32 size = 0x10000; h_bigfile.open("EDEN.DAT"); - h_bigfile.read(bigfile_header, size); + + char buf[16]; + int count = h_bigfile.readUint16LE(); + bigfile_header = new PakHeaderNode(count); + for (int j = 0; j < count; j++) { + for (int k = 0; k < 16; k++) + buf[k] = h_bigfile.readByte(); + bigfile_header->_files[j]._name = Common::String(buf); + bigfile_header->_files[j]._size = h_bigfile.readUint32LE(); + bigfile_header->_files[j]._offs = h_bigfile.readUint32LE(); + bigfile_header->_files[j]._flag = h_bigfile.readByte(); + } _hnmContext = _vm->_video->resetInternals(); _vm->_video->setFile(_hnmContext, &h_bigfile); @@ -4681,32 +4689,32 @@ void EdenGame::loadFile(uint16 num, void *buffer) { error("Trying to read invalid game resource"); } - assert(num < bigfile_header->count); - pakfile_t *file = &bigfile_header->files[num]; - int32 size = READ_LE_UINT32(&file->size); - int32 offs = READ_LE_UINT32(&file->offs); - debug("* Loading resource %d (%s) at 0x%X, %d bytes", num, file->name, offs, size); + assert(num < bigfile_header->_count); + PakHeaderItem *file = &bigfile_header->_files[num]; + int32 size = READ_LE_UINT32(&file->_size); + int32 offs = READ_LE_UINT32(&file->_offs); + debug("* Loading resource %d (%s) at 0x%X, %d bytes", num, file->_name.c_str(), offs, size); h_bigfile.seek(offs, SEEK_SET); h_bigfile.read(buffer, size); } void EdenGame::shnmfl(uint16 num) { unsigned int resNum = num - 1 + 485; - assert(resNum < bigfile_header->count); - pakfile_t *file = &bigfile_header->files[resNum]; - int size = READ_LE_UINT32(&file->size); - int offs = READ_LE_UINT32(&file->offs); - debug("* Loading movie %d (%s) at 0x%X, %d bytes", num, file->name, (uint)offs, size); + assert(resNum < bigfile_header->_count); + PakHeaderItem *file = &bigfile_header->_files[resNum]; + int size = READ_LE_UINT32(&file->_size); + int offs = READ_LE_UINT32(&file->_offs); + debug("* Loading movie %d (%s) at 0x%X, %d bytes", num, file->_name.c_str(), (uint)offs, size); _hnmContext->_file->seek(offs, SEEK_SET); } int EdenGame::ssndfl(uint16 num) { unsigned int resNum = num - 1 + ((_vm->getPlatform() == Common::kPlatformDOS && _vm->isDemo()) ? 656 : 661); - assert(resNum < bigfile_header->count); - pakfile_t *file = &bigfile_header->files[resNum]; - int32 size = READ_LE_UINT32(&file->size); - int32 offs = READ_LE_UINT32(&file->offs); - debug("* Loading sound %d (%s) at 0x%X, %d bytes", num, file->name, (uint)offs, size); + assert(resNum < bigfile_header->_count); + PakHeaderItem *file = &bigfile_header->_files[resNum]; + int32 size = READ_LE_UINT32(&file->_size); + int32 offs = READ_LE_UINT32(&file->_offs); + debug("* Loading sound %d (%s) at 0x%X, %d bytes", num, file->_name.c_str(), (uint)offs, size); if (_soundAllocated) { free(voiceSamplesBuffer); voiceSamplesBuffer = nullptr; @@ -4850,10 +4858,10 @@ bool EdenGame::ReadDataSync(uint16 num) { } void EdenGame::loadpartoffile(uint16 num, void *buffer, int32 pos, int32 len) { - assert(num < bigfile_header->count); - pakfile_t *file = &bigfile_header->files[num]; - int32 offs = READ_LE_UINT32(&file->offs); - debug("* Loading partial resource %d (%s) at 0x%X(+0x%X), %d bytes", num, file->name, offs, pos, len); + assert(num < bigfile_header->_count); + PakHeaderItem *file = &bigfile_header->_files[num]; + int32 offs = READ_LE_UINT32(&file->_offs); + debug("* Loading partial resource %d (%s) at 0x%X(+0x%X), %d bytes", num, file->_name.c_str(), offs, pos, len); h_bigfile.seek(offs + pos, SEEK_SET); h_bigfile.read(buffer, len); } @@ -5509,7 +5517,6 @@ void EdenGame::maj_salle(uint16 roomNum) { // Original name: initbuf void EdenGame::allocateBuffers() { #define ALLOC(ptr, size, typ) if (!((ptr) = (typ*)malloc(size))) bufferAllocationErrorFl = true; - ALLOC(bigfile_header, 0x10000, pak_t); ALLOC(gameRooms, 0x4000, room_t); ALLOC(_gameIcons, 0x4000, icon_t); ALLOC(bank_data_buf, 0x10000, byte); @@ -5527,7 +5534,9 @@ void EdenGame::allocateBuffers() { } void EdenGame::freebuf() { - free(bigfile_header); + delete(bigfile_header); + bigfile_header = nullptr; + free(gameRooms); free(_gameIcons); free(bank_data_buf); @@ -6467,9 +6476,9 @@ void EdenGame::musicspy() { } int EdenGame::loadmusicfile(int16 num) { - pakfile_t *file = &bigfile_header->files[num + 435]; - int32 size = READ_LE_UINT32(&file->size); - int32 offs = READ_LE_UINT32(&file->offs); + PakHeaderItem *file = &bigfile_header->_files[num + 435]; + int32 size = READ_LE_UINT32(&file->_size); + int32 offs = READ_LE_UINT32(&file->_offs); h_bigfile.seek(offs, SEEK_SET); int32 numread = size; if (numread > 0x140000) //TODO: const diff --git a/engines/cryo/eden.h b/engines/cryo/eden.h index a3059c3f31..62d0989f1d 100644 --- a/engines/cryo/eden.h +++ b/engines/cryo/eden.h @@ -627,7 +627,7 @@ private: byte *bank_data_buf; icon_t *_gameIcons; room_t *gameRooms; - pak_t *bigfile_header; + PakHeaderNode *bigfile_header; byte *glow_buffer; byte *p_mainview_buf; byte *p_view2_buf; |