From fcaf15aa504c6902921d7a9342e34daa2003ae2d Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Tue, 7 Mar 2017 12:34:31 -0600 Subject: SCI: Add alloc_list command to debugger This command lists all resources that are currently loaded into memory, plus the number of locks that exist on each loaded resource. --- engines/sci/console.cpp | 32 ++++++++++++++++++++++++++++++++ engines/sci/console.h | 1 + engines/sci/resource.h | 2 ++ 3 files changed, 35 insertions(+) diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index cbb1a0ef2e..c81d086241 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -112,6 +112,7 @@ Console::Console(SciEngine *engine) : GUI::Debugger(), registerCmd("resource_info", WRAP_METHOD(Console, cmdResourceInfo)); registerCmd("resource_types", WRAP_METHOD(Console, cmdResourceTypes)); registerCmd("list", WRAP_METHOD(Console, cmdList)); + registerCmd("alloc_list", WRAP_METHOD(Console, cmdAllocList)); registerCmd("hexgrep", WRAP_METHOD(Console, cmdHexgrep)); registerCmd("verify_scripts", WRAP_METHOD(Console, cmdVerifyScripts)); // Game @@ -364,6 +365,7 @@ bool Console::cmdHelp(int argc, const char **argv) { debugPrintf(" resource_info - Shows info about a resource\n"); debugPrintf(" resource_types - Shows the valid resource types\n"); debugPrintf(" list - Lists all the resources of a given type\n"); + debugPrintf(" alloc_list - Lists all allocated resources\n"); debugPrintf(" hexgrep - Searches some resources for a particular sequence of bytes, represented as hexadecimal numbers\n"); debugPrintf(" verify_scripts - Performs sanity checks on SCI1.1-SCI2.1 game scripts (e.g. if they're up to 64KB in total)\n"); debugPrintf("\n"); @@ -910,6 +912,36 @@ bool Console::cmdList(int argc, const char **argv) { return true; } +bool Console::cmdAllocList(int argc, const char **argv) { + ResourceManager *resMan = _engine->getResMan(); + + for (int i = 0; i < kResourceTypeInvalid; ++i) { + Common::List resources = _engine->getResMan()->listResources((ResourceType)i); + if (resources.size()) { + Common::sort(resources.begin(), resources.end()); + bool hasAlloc = false; + Common::List::const_iterator it; + for (it = resources.begin(); it != resources.end(); ++it) { + Resource *resource = resMan->testResource(*it); + if (resource != nullptr && resource->data() != nullptr) { + if (hasAlloc) { + debugPrintf(", "); + } else { + debugPrintf("%s: ", getResourceTypeName((ResourceType)i)); + } + hasAlloc = true; + debugPrintf("%u (%u locks)", resource->getNumber(), resource->getNumLockers()); + } + } + if (hasAlloc) { + debugPrintf("\n"); + } + } + } + + return true; +} + bool Console::cmdDissectScript(int argc, const char **argv) { if (argc != 2) { debugPrintf("Examines a script\n"); diff --git a/engines/sci/console.h b/engines/sci/console.h index 4b630da25b..366f959273 100644 --- a/engines/sci/console.h +++ b/engines/sci/console.h @@ -78,6 +78,7 @@ private: bool cmdResourceInfo(int argc, const char **argv); bool cmdResourceTypes(int argc, const char **argv); bool cmdList(int argc, const char **argv); + bool cmdAllocList(int argc, const char **argv); bool cmdHexgrep(int argc, const char **argv); bool cmdVerifyScripts(int argc, const char **argv); // Game diff --git a/engines/sci/resource.h b/engines/sci/resource.h index c0c969ab88..6a67bf7414 100644 --- a/engines/sci/resource.h +++ b/engines/sci/resource.h @@ -277,6 +277,8 @@ public: // eases transition. uint32 getAudioCompressionType() const; + uint16 getNumLockers() const { return _lockers; } + protected: ResourceId _id; // TODO: _id could almost be made const, only readResourceInfo() modifies it... int32 _fileOffset; /**< Offset in file */ -- cgit v1.2.3