[Scummvm-git-logs] scummvm master -> ffad977bbb93334bbf6217e54f5092239ac383af

sev- noreply at scummvm.org
Sun Jun 15 20:20:25 UTC 2025


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
ffad977bbb SLUDGE: Add an initial Debugger implementation for dumping resources


Commit: ffad977bbb93334bbf6217e54f5092239ac383af
    https://github.com/scummvm/scummvm/commit/ffad977bbb93334bbf6217e54f5092239ac383af
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2025-06-15T22:20:22+02:00

Commit Message:
SLUDGE: Add an initial Debugger implementation for dumping resources

Changed paths:
  A engines/sludge/debugger.cpp
  A engines/sludge/debugger.h
    engines/sludge/fileset.cpp
    engines/sludge/fileset.h
    engines/sludge/module.mk
    engines/sludge/sludge.cpp


diff --git a/engines/sludge/debugger.cpp b/engines/sludge/debugger.cpp
new file mode 100644
index 00000000000..fe7e4337c05
--- /dev/null
+++ b/engines/sludge/debugger.cpp
@@ -0,0 +1,62 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "sludge/debugger.h"
+#include "sludge/sludge.h"
+#include "sludge/fileset.h"
+
+namespace Sludge {
+
+Debugger::Debugger(SludgeEngine *vm) : GUI::Debugger(), _vm(vm) {
+	registerCmd("listResources", WRAP_METHOD(Debugger, Cmd_ListResources));
+	registerCmd("dumpResource", WRAP_METHOD(Debugger, Cmd_DumpResource));
+}
+
+bool Debugger::Cmd_ListResources(int argc, const char **argv) {
+	if (argc != 1 && argc != 2) {
+		debugPrintf("Usage: %s\n", argv[0]);
+		return true;
+	}
+
+	for (int i = 0; i < _vm->_resMan->getResourceNameCount(); i++) {
+		const Common::String name = _vm->_resMan->resourceNameFromNum(i);
+		if (argc == 1 || name.matchString(argv[1]))
+			debugPrintf(" - %s\n", name.c_str());
+	}
+	return true;
+}
+
+bool Debugger::Cmd_DumpResource(int argc, const char **argv) {
+	if (argc != 2) {
+		debugPrintf("Usage: %s\n", argv[0]);
+		return true;
+	}
+
+	if (_vm->_resMan->dumpFileFromName(argv[1])) {
+		debugPrintf("Success\n");
+	} else {
+		debugPrintf("Failure\n");
+	}
+
+	return true;
+}
+
+} // End of namespace Sludge
diff --git a/engines/sludge/debugger.h b/engines/sludge/debugger.h
new file mode 100644
index 00000000000..d9b833cf741
--- /dev/null
+++ b/engines/sludge/debugger.h
@@ -0,0 +1,46 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef SLUDGE_DEBUGGER_H
+#define SLUDGE_DEBUGGER_H
+
+#include "gui/debugger.h"
+
+namespace Sludge {
+
+class SludgeEngine;
+
+class Debugger : public GUI::Debugger {
+private:
+	SludgeEngine *_vm;
+
+public:
+	Debugger(SludgeEngine *vm);
+	~Debugger() override {}
+
+protected:
+	bool Cmd_ListResources(int argc, const char **argv);
+	bool Cmd_DumpResource(int argc, const char **argv);
+};
+
+} // End of namespace Sludge
+
+#endif
diff --git a/engines/sludge/fileset.cpp b/engines/sludge/fileset.cpp
index c1c3bb88312..744bc85ec50 100644
--- a/engines/sludge/fileset.cpp
+++ b/engines/sludge/fileset.cpp
@@ -242,6 +242,38 @@ void ResourceManager::dumpFile(int num, const char *pattern) {
 	_bigDataFile->seek(pos);
 }
 
+bool ResourceManager::dumpFileFromName(const char *name) {
+	int num = -1;
+	for (int i = 0; i < getResourceNameCount(); i++) {
+		if (name != resourceNameFromNum(i))
+			continue;
+		num = i;
+		break;
+	}
+	if (num < 0)
+		return false;
+
+	Common::DumpFile dumpFile;
+	dumpFile.open(Common::Path("dumps/").append(name), true);
+	uint32 pos = _bigDataFile->pos();
+
+	_bigDataFile->seek(_startOfDataIndex + (num << 2), 0);
+	_bigDataFile->seek(_bigDataFile->readUint32LE(), 1);
+
+	uint fsize = _bigDataFile->readUint32LE();
+
+	byte *data = (byte *)malloc(fsize);
+
+	_bigDataFile->read(data, fsize);
+	dumpFile.write(data, fsize);
+	dumpFile.close();
+
+	free(data);
+
+	_bigDataFile->seek(pos);
+	return true;
+}
+
 void ResourceManager::readResourceNames(Common::SeekableReadStream *readStream) {
 	int numResourceNames = readStream->readUint16BE();
 	debugC(2, kSludgeDebugDataLoad, "numResourceNames %i", numResourceNames);
diff --git a/engines/sludge/fileset.h b/engines/sludge/fileset.h
index c4d102ab1c7..f1da82d05e3 100644
--- a/engines/sludge/fileset.h
+++ b/engines/sludge/fileset.h
@@ -50,9 +50,11 @@ public:
 	// Resource names
 	void readResourceNames(Common::SeekableReadStream *readStream);
 	const Common::String resourceNameFromNum(int i);
-	bool hasResourceNames() { return !_allResourceNames.empty(); }
+	bool hasResourceNames() const { return !_allResourceNames.empty(); }
+	int getResourceNameCount() const { return _allResourceNames.size(); }
 
 	void dumpFile(int num, const char *pattern);
+	bool dumpFileFromName(const char *name);
 
 private:
 	bool _sliceBusy;
diff --git a/engines/sludge/module.mk b/engines/sludge/module.mk
index 4c0f2d47ddc..3df34fcd5d6 100644
--- a/engines/sludge/module.mk
+++ b/engines/sludge/module.mk
@@ -5,6 +5,7 @@ MODULE_OBJS := \
 	bg_effects.o \
 	builtin.o \
 	cursors.o \
+	debugger.o \
 	event.o \
 	fileset.o \
 	floor.o \
diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp
index b9e91e55e70..9295e1f1a89 100644
--- a/engines/sludge/sludge.cpp
+++ b/engines/sludge/sludge.cpp
@@ -27,6 +27,7 @@
 #include "engines/metaengine.h"
 
 #include "sludge/cursors.h"
+#include "sludge/debugger.h"
 #include "sludge/event.h"
 #include "sludge/fileset.h"
 #include "sludge/fonttext.h"
@@ -192,6 +193,8 @@ Common::Error SludgeEngine::run() {
 	// set global variable
 	g_sludge = this;
 
+	setDebugger(new Debugger(this));
+
 	// debug log
 	main_loop(getGameFile());
 




More information about the Scummvm-git-logs mailing list