From e89c01713b85bcfe22ca7da08d2cee7cc7aaf143 Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Mon, 22 Oct 2012 19:42:00 +0200 Subject: [PATCH] NANCY: Add getting chunks with the same name by index --- engines/nancy/console.cpp | 12 ++++++++---- engines/nancy/iff.cpp | 10 +++++++--- engines/nancy/iff.h | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/engines/nancy/console.cpp b/engines/nancy/console.cpp index f0afbb2e49b..02010318b7f 100644 --- a/engines/nancy/console.cpp +++ b/engines/nancy/console.cpp @@ -146,9 +146,9 @@ bool NancyConsole::Cmd_cifInfo(int argc, const char **argv) { } bool NancyConsole::Cmd_chunkHexDump(int argc, const char **argv) { - if (argc != 3) { + if (argc < 3 || argc > 4) { debugPrintf("Hexdumps an IFF chunk\n"); - debugPrintf("Usage: %s iffname chunkname\n", argv[0]); + debugPrintf("Usage: %s iffname chunkname [index]\n", argv[0]); return true; } @@ -165,10 +165,14 @@ bool NancyConsole::Cmd_chunkHexDump(int argc, const char **argv) { uint len = strlen(argv[2]); memcpy(idStr, argv[2], (len <= 4 ? len : 4)); uint32 id = READ_BE_UINT32(idStr); + uint index = 0; - buf = iff.getChunk(id, size); + if (argc == 4) + index = atoi(argv[3]); + + buf = iff.getChunk(id, size, index); if (!buf) { - debugPrintf("Failed to find chunk '%s' in IFF '%s'\n", argv[2], argv[1]); + debugPrintf("Failed to find chunk '%s' (index %d) in IFF '%s'\n", argv[2], index, argv[1]); return true; } diff --git a/engines/nancy/iff.cpp b/engines/nancy/iff.cpp index e13dce2e259..4218d522b25 100644 --- a/engines/nancy/iff.cpp +++ b/engines/nancy/iff.cpp @@ -95,12 +95,16 @@ bool IFF::load() { return true; } -const byte *IFF::getChunk(uint32 id, uint &size) const { +const byte *IFF::getChunk(uint32 id, uint &size, uint index) const { + uint found = 0; for (uint i = 0; i < _chunks.size(); ++i) { const Chunk &chunk = _chunks[i]; if (chunk.id == id) { - size = chunk.size; - return chunk.buf; + if (found == index) { + size = chunk.size; + return chunk.buf; + } + ++found; } } diff --git a/engines/nancy/iff.h b/engines/nancy/iff.h index 363237b932f..a23e0e27da7 100644 --- a/engines/nancy/iff.h +++ b/engines/nancy/iff.h @@ -43,7 +43,7 @@ public: ~IFF(); bool load(); - const byte *getChunk(uint32 id, uint &size) const; + const byte *getChunk(uint32 id, uint &size, uint index = 0) const; // Debugger functions void list(Common::Array &nameList);