CRYO: rewrite the loading of pak file header

This commit is contained in:
Strangerke 2016-12-06 23:08:32 -08:00 committed by Eugene Sandulenko
parent e76e4c8136
commit 550d62b25a
4 changed files with 61 additions and 39 deletions

View File

@ -438,4 +438,14 @@ void CRYOLib_ManagersDone() {
g_system->getTimerManager()->removeTimerProc(CLTimer_Action); 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 } // End of namespace Cryo

View File

@ -762,19 +762,22 @@ struct global_t {
}; };
typedef struct global_t global_t; typedef struct global_t global_t;
struct pakfile_t { struct PakHeaderItem {
char name[16]; Common::String _name; //[16];
int32 size; int32 _size;
int32 offs; int32 _offs;
char flag; char _flag;
}; };
typedef struct pakfile_t pakfile_t; typedef struct PakHeaderItem PakHeaderItem;
struct pak_t { class PakHeaderNode {
uint16 count; public:
pakfile_t files[10]; PakHeaderNode(int count);
~PakHeaderNode();
uint16 _count;
PakHeaderItem* _files;
}; };
typedef struct pak_t pak_t;
#pragma pack(pop) #pragma pack(pop)
struct cita_t { struct cita_t {

View File

@ -101,7 +101,6 @@ EdenGame::EdenGame(CryoEngine *vm) : _vm(vm) {
bank_data_buf = nullptr; bank_data_buf = nullptr;
_gameIcons = nullptr; _gameIcons = nullptr;
gameRooms = nullptr; gameRooms = nullptr;
bigfile_header = nullptr;
glow_buffer = nullptr; glow_buffer = nullptr;
gameFont = nullptr; gameFont = nullptr;
p_global = nullptr; p_global = nullptr;
@ -4662,10 +4661,19 @@ void EdenGame::verifh(void *ptr) {
} }
void EdenGame::openbigfile() { void EdenGame::openbigfile() {
assert(sizeof(pakfile_t) == 25);
int32 size = 0x10000;
h_bigfile.open("EDEN.DAT"); 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(); _hnmContext = _vm->_video->resetInternals();
_vm->_video->setFile(_hnmContext, &h_bigfile); _vm->_video->setFile(_hnmContext, &h_bigfile);
@ -4681,32 +4689,32 @@ void EdenGame::loadFile(uint16 num, void *buffer) {
error("Trying to read invalid game resource"); error("Trying to read invalid game resource");
} }
assert(num < bigfile_header->count); assert(num < bigfile_header->_count);
pakfile_t *file = &bigfile_header->files[num]; PakHeaderItem *file = &bigfile_header->_files[num];
int32 size = READ_LE_UINT32(&file->size); int32 size = READ_LE_UINT32(&file->_size);
int32 offs = READ_LE_UINT32(&file->offs); int32 offs = READ_LE_UINT32(&file->_offs);
debug("* Loading resource %d (%s) at 0x%X, %d bytes", num, file->name, offs, size); 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.seek(offs, SEEK_SET);
h_bigfile.read(buffer, size); h_bigfile.read(buffer, size);
} }
void EdenGame::shnmfl(uint16 num) { void EdenGame::shnmfl(uint16 num) {
unsigned int resNum = num - 1 + 485; unsigned int resNum = num - 1 + 485;
assert(resNum < bigfile_header->count); assert(resNum < bigfile_header->_count);
pakfile_t *file = &bigfile_header->files[resNum]; PakHeaderItem *file = &bigfile_header->_files[resNum];
int size = READ_LE_UINT32(&file->size); int size = READ_LE_UINT32(&file->_size);
int offs = READ_LE_UINT32(&file->offs); int offs = READ_LE_UINT32(&file->_offs);
debug("* Loading movie %d (%s) at 0x%X, %d bytes", num, file->name, (uint)offs, size); debug("* Loading movie %d (%s) at 0x%X, %d bytes", num, file->_name.c_str(), (uint)offs, size);
_hnmContext->_file->seek(offs, SEEK_SET); _hnmContext->_file->seek(offs, SEEK_SET);
} }
int EdenGame::ssndfl(uint16 num) { int EdenGame::ssndfl(uint16 num) {
unsigned int resNum = num - 1 + ((_vm->getPlatform() == Common::kPlatformDOS && _vm->isDemo()) ? 656 : 661); unsigned int resNum = num - 1 + ((_vm->getPlatform() == Common::kPlatformDOS && _vm->isDemo()) ? 656 : 661);
assert(resNum < bigfile_header->count); assert(resNum < bigfile_header->_count);
pakfile_t *file = &bigfile_header->files[resNum]; PakHeaderItem *file = &bigfile_header->_files[resNum];
int32 size = READ_LE_UINT32(&file->size); int32 size = READ_LE_UINT32(&file->_size);
int32 offs = READ_LE_UINT32(&file->offs); int32 offs = READ_LE_UINT32(&file->_offs);
debug("* Loading sound %d (%s) at 0x%X, %d bytes", num, file->name, (uint)offs, size); debug("* Loading sound %d (%s) at 0x%X, %d bytes", num, file->_name.c_str(), (uint)offs, size);
if (_soundAllocated) { if (_soundAllocated) {
free(voiceSamplesBuffer); free(voiceSamplesBuffer);
voiceSamplesBuffer = nullptr; voiceSamplesBuffer = nullptr;
@ -4850,10 +4858,10 @@ bool EdenGame::ReadDataSync(uint16 num) {
} }
void EdenGame::loadpartoffile(uint16 num, void *buffer, int32 pos, int32 len) { void EdenGame::loadpartoffile(uint16 num, void *buffer, int32 pos, int32 len) {
assert(num < bigfile_header->count); assert(num < bigfile_header->_count);
pakfile_t *file = &bigfile_header->files[num]; PakHeaderItem *file = &bigfile_header->_files[num];
int32 offs = READ_LE_UINT32(&file->offs); 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); 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.seek(offs + pos, SEEK_SET);
h_bigfile.read(buffer, len); h_bigfile.read(buffer, len);
} }
@ -5509,7 +5517,6 @@ void EdenGame::maj_salle(uint16 roomNum) {
// Original name: initbuf // Original name: initbuf
void EdenGame::allocateBuffers() { void EdenGame::allocateBuffers() {
#define ALLOC(ptr, size, typ) if (!((ptr) = (typ*)malloc(size))) bufferAllocationErrorFl = true; #define ALLOC(ptr, size, typ) if (!((ptr) = (typ*)malloc(size))) bufferAllocationErrorFl = true;
ALLOC(bigfile_header, 0x10000, pak_t);
ALLOC(gameRooms, 0x4000, room_t); ALLOC(gameRooms, 0x4000, room_t);
ALLOC(_gameIcons, 0x4000, icon_t); ALLOC(_gameIcons, 0x4000, icon_t);
ALLOC(bank_data_buf, 0x10000, byte); ALLOC(bank_data_buf, 0x10000, byte);
@ -5527,7 +5534,9 @@ void EdenGame::allocateBuffers() {
} }
void EdenGame::freebuf() { void EdenGame::freebuf() {
free(bigfile_header); delete(bigfile_header);
bigfile_header = nullptr;
free(gameRooms); free(gameRooms);
free(_gameIcons); free(_gameIcons);
free(bank_data_buf); free(bank_data_buf);
@ -6467,9 +6476,9 @@ void EdenGame::musicspy() {
} }
int EdenGame::loadmusicfile(int16 num) { int EdenGame::loadmusicfile(int16 num) {
pakfile_t *file = &bigfile_header->files[num + 435]; PakHeaderItem *file = &bigfile_header->_files[num + 435];
int32 size = READ_LE_UINT32(&file->size); int32 size = READ_LE_UINT32(&file->_size);
int32 offs = READ_LE_UINT32(&file->offs); int32 offs = READ_LE_UINT32(&file->_offs);
h_bigfile.seek(offs, SEEK_SET); h_bigfile.seek(offs, SEEK_SET);
int32 numread = size; int32 numread = size;
if (numread > 0x140000) //TODO: const if (numread > 0x140000) //TODO: const

View File

@ -627,7 +627,7 @@ private:
byte *bank_data_buf; byte *bank_data_buf;
icon_t *_gameIcons; icon_t *_gameIcons;
room_t *gameRooms; room_t *gameRooms;
pak_t *bigfile_header; PakHeaderNode *bigfile_header;
byte *glow_buffer; byte *glow_buffer;
byte *p_mainview_buf; byte *p_mainview_buf;
byte *p_view2_buf; byte *p_view2_buf;