NANCY: Add getting chunks with the same name by index
This commit is contained in:
parent
b393b234be
commit
e89c01713b
3 changed files with 16 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Common::String> &nameList);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue