bool Debugger::Cmd_DumpVocab(int argc, const char **argv) { Common::DumpFile outFile; outFile.open("vocab.txt"); for (uint32 i = 0; i < _vm->_game->_scene.getVocabStringsCount(); i++) { Common::String curId = Common::String::format("%x", i + 1); Common::String curVocab = _vm->_game->_scene.getVocab(i + 1); curVocab.toUppercase(); for (uint j = 0; j < curVocab.size(); j++) { if (curVocab[j] == ' ' || curVocab[j] == '-') curVocab.setChar('_', j); } Common::String cur = "\tNOUN_" + curVocab + " = 0x" + curId + ",\n"; outFile.writeString(cur.c_str()); } outFile.flush(); outFile.close(); debugPrintf("Game vocab dumped\n"); return true; }
bool Debugger::Cmd_DumpItems(int argc, const char **argv) { InventoryObjects &objects = _vm->_game->_objects; Common::DumpFile outFile; outFile.open("items.txt"); for (uint32 i = 0; i < objects.size(); i++) { Common::String curId = Common::String::format("%d", i); Common::String desc = _vm->_game->_scene.getVocab(objects[i]._descId); desc.toUppercase(); for (uint j = 0; j < desc.size(); j++) { if (desc[j] == ' ' || desc[j] == '-') desc.setChar('_', j); } Common::String cur = "\tOBJ_" + desc + " = " + curId + ",\n"; outFile.writeString(cur.c_str()); } outFile.flush(); outFile.close(); debugPrintf("Game items dumped\n"); return true; }
bool Debugger::cmdDumpFile(int argc, const char **argv) { if (argc != 2) { debugPrintf("Format: dumpfile <resource name>\n"); return true; } Common::SeekableReadStream *s = _vm->_res->load(argv[1]); if (!s) { debugPrintf("Invalid resource.\n"); return true; } byte *buffer = new byte[s->size()]; s->read(buffer, s->size()); Common::DumpFile dumpFile; dumpFile.open(argv[1]); dumpFile.write(buffer, s->size()); dumpFile.flush(); dumpFile.close(); delete[] buffer; debugPrintf("Resource %s has been dumped to disk.\n", argv[1]); return true; }
bool Debugger::Cmd_DumpFile(int argc, const char **argv) { if (argc != 2) { debugPrintf("Usage: %s <resource>\n", argv[0]); } else { Common::DumpFile outFile; Common::File inFile; if (!inFile.open(argv[1])) { debugPrintf("Specified resource does not exist\n"); } else { outFile.open(argv[1]); byte *data = new byte[inFile.size()]; inFile.read(data, inFile.size()); outFile.write(data, inFile.size()); outFile.flush(); delete[] data; inFile.close(); outFile.close(); debugPrintf("File written successfully.\n"); } } return true; }
void ResourceManager::dumpResourcesList(const Common::UString &fileName) const { Common::DumpFile file; if (!file.open(fileName)) throw Common::Exception(Common::kOpenError); file.writeString(" Name | Size \n"); file.writeString("-------------------------------------|-------------\n"); for (ResourceMap::const_iterator itName = _resources.begin(); itName != _resources.end(); ++itName) { for (ResourceTypeMap::const_iterator itType = itName->second.begin(); itType != itName->second.end(); ++itType) { if (itType->second.empty()) continue; const Resource &resource = itType->second.back(); const Common::UString &name = itName->first; const Common::UString ext = setFileType("", resource.type); const uint32 size = getResourceSize(resource); const Common::UString line = Common::UString::sprintf("%32s%4s | %12d\n", name.c_str(), ext.c_str(), size); file.writeString(line); } } file.flush(); if (file.err()) throw Common::Exception("Write error"); file.close(); }
void ResourceManager::dumpResourcesList(const Common::UString &fileName) const { Common::DumpFile file; if (!file.open(fileName)) throw Common::Exception(Common::kOpenError); file.writeString(" Name | Hash | Size \n"); file.writeString("-------------------------------------|--------------------|-------------\n"); for (ResourceMap::const_iterator r = _resources.begin(); r != _resources.end(); ++r) { if (r->second.empty()) continue; const Resource &res = r->second.back(); const Common::UString &name = res.name; const Common::UString ext = TypeMan.setFileType("", res.type); const uint64 hash = r->first; const uint32 size = getResourceSize(res); const Common::UString line = Common::UString::sprintf("%32s%4s | 0x%016llX | %12d\n", name.c_str(), ext.c_str(), (unsigned long long) hash, size); file.writeString(line); } file.flush(); if (file.err()) throw Common::Exception("Write error"); file.close(); }
static bool writeBMP(const Common::UString &filename, const byte *data, int width, int height) { if ((width <= 0) || (height <= 0) || !data) return false; Common::DumpFile file; if (!file.open(filename)) return false; // The pitch of the output has to be divisible by 4, so // we output zeroes to make the pitch that far. int extraDataSize = width & 3; int imageSize = height * (width + extraDataSize) * 3; // Main bitmap header file.writeByte('B'); file.writeByte('M'); file.writeUint32LE(14 + 40 + imageSize); // Size file.writeUint32LE(0); // reserved file.writeUint32LE(14 + 40); // Image offset after both headers // v3 header file.writeUint32LE(40); file.writeUint32LE(width); file.writeUint32LE(height); file.writeUint16LE(1); file.writeUint16LE(24); file.writeUint32LE(0); file.writeUint32LE(imageSize); file.writeUint32LE(72); file.writeUint32LE(72); file.writeUint32LE(0); file.writeUint32LE(0); if (extraDataSize != 0) { // Dump, making sure the pitch is correct while (height--) { file.write(data, width * 3); // Ensure we're on a 4-byte boundary for (int i = 0; i < extraDataSize; i++) file.writeByte(0); data += width * 3; } } else { // Dump directly (can do all at once here because the data // is already good for BMP output) file.write(data, width * height * 3); } if (!file.flush() || file.err()) return false; file.close(); return true; }
bool Console::cmdDumpImage(int argc, const char **argv) { if (argc != 2) { debugPrintf("Use %s <TGA/TGZ name> to dump a Z-Vision TGA/TGZ image into a regular BMP image\n", argv[0]); return true; } Common::String fileName = argv[1]; if (!fileName.hasSuffix(".tga")) { debugPrintf("%s is not an image file", argv[1]); } Common::File f; if (!_engine->getSearchManager()->openFile(f, argv[1])) { warning("File not found: %s", argv[1]); return true; } Graphics::Surface surface; _engine->getRenderManager()->readImageToSurface(argv[1], surface, false); // Open file Common::DumpFile out; fileName.setChar('b', fileName.size() - 3); fileName.setChar('m', fileName.size() - 2); fileName.setChar('p', fileName.size() - 1); out.open(fileName); // Write BMP header out.writeByte('B'); out.writeByte('M'); out.writeUint32LE(surface.h * surface.pitch + 54); out.writeUint32LE(0); out.writeUint32LE(54); out.writeUint32LE(40); out.writeUint32LE(surface.w); out.writeUint32LE(surface.h); out.writeUint16LE(1); out.writeUint16LE(16); out.writeUint32LE(0); out.writeUint32LE(0); out.writeUint32LE(0); out.writeUint32LE(0); out.writeUint32LE(0); out.writeUint32LE(0); // Write pixel data to BMP out.write(surface.getPixels(), surface.pitch * surface.h); out.flush(); out.close(); surface.free(); return true; }
void dumpStream(Common::SeekableReadStream &stream, const Common::UString &fileName) { Common::DumpFile file; if (!file.open(fileName)) throw Common::Exception(Common::kOpenError); file.writeStream(stream); file.flush(); if (file.err()) throw Common::Exception(Common::kWriteError); file.close(); }
void dumpFile(Common::SeekableReadStream *s, const char *outName) { byte *buffer = new byte[s->size()]; s->read(buffer, s->size()); Common::DumpFile dumpFile; dumpFile.open(outName); dumpFile.write(buffer, s->size()); dumpFile.flush(); dumpFile.close(); delete[] buffer; }
bool Debugger::Cmd_DumpFile(int argc, const char **argv) { if (argc < 2) { debugPrintf("Usage: %s <resource> <unpack>\n", argv[0]); debugPrintf(" resource: the resource name\n"); debugPrintf(" unpack: optional, when specified, the FAB/MADSPACK compressed resource is unpacked\n"); } else { Common::DumpFile outFile; Common::File inFile; if (!inFile.open(argv[1])) { debugPrintf("Specified resource does not exist\n"); } else { outFile.open(argv[1]); bool unpack = ((argc >= 3) && !scumm_stricmp(argv[2], "unpack")); byte *data; int totalSize = 0; if (!unpack) { totalSize = inFile.size(); data = new byte[totalSize]; inFile.read(data, totalSize); } else { MadsPack dataPack(&inFile); int count = dataPack.getCount(); for (int i = 0; i < count; i++) { totalSize += dataPack.getItem(i)._size; } data = new byte[totalSize]; byte *ptr = data; for (int i = 0; i < count; i++) { Common::SeekableReadStream *readStream = dataPack.getItemStream(i); readStream->read(ptr, readStream->size()); ptr += readStream->size(); } } outFile.write(data, totalSize); outFile.flush(); delete[] data; inFile.close(); outFile.close(); debugPrintf("File written successfully.\n"); } } return true; }
bool TwoDAFile::dumpASCII(const Common::UString &fileName) const { Common::DumpFile file; if (!file.open(fileName)) return false; // Write header file.writeString("2DA V2.0\n"); file.writeString(_defaultString); file.writeByte('\n'); // Calculate column lengths std::vector<uint32> colLength; colLength.resize(_headers.size() + 1); const Common::UString maxRow = Common::UString::sprintf("%d", (int)_rows.size() - 1); colLength[0] = maxRow.size(); for (uint32 i = 0; i < _headers.size(); i++) colLength[i + 1] = _headers[i].size(); for (uint32 i = 0; i < _rows.size(); i++) for (uint32 j = 0; j < _rows[i]->_data.size(); j++) colLength[j + 1] = MAX<uint32>(colLength[j + 1], _rows[i]->_data[j].size()); // Write column headers file.writeString(Common::UString::sprintf("%-*s", colLength[0], "")); for (uint32 i = 0; i < _headers.size(); i++) file.writeString(Common::UString::sprintf(" %-*s", colLength[i + 1], _headers[i].c_str())); file.writeByte('\n'); // Write array for (uint32 i = 0; i < _rows.size(); i++) { file.writeString(Common::UString::sprintf("%*d", colLength[0], i)); for (uint32 j = 0; j < _rows[i]->_data.size(); j++) file.writeString(Common::UString::sprintf(" %-*s", colLength[j + 1], _rows[i]->_data[j].c_str())); file.writeByte('\n'); } file.flush(); file.close(); return true; }
void writeFileContentsToFile(const Common::String &sourceFile, const Common::String &destFile) { Common::File f; if (!f.open(sourceFile)) { return; } byte* buffer = new byte[f.size()]; f.read(buffer, f.size()); Common::DumpFile dumpFile; dumpFile.open(destFile); dumpFile.write(buffer, f.size()); dumpFile.flush(); dumpFile.close(); delete[] buffer; }
bool dumpStream(Common::SeekableReadStream &stream, const Common::UString &fileName) { Common::DumpFile file; if (!file.open(fileName)) return false; uint32 pos = stream.pos(); stream.seek(0); file.writeStream(stream); file.flush(); bool error = file.err(); stream.seek(pos); file.close(); return !error; }
void DefaultSaveFileManager::saveTimestamps(Common::HashMap<Common::String, uint32> ×tamps) { Common::DumpFile f; Common::String filename = concatWithSavesPath(TIMESTAMPS_FILENAME); if (!f.open(filename, true)) { warning("DefaultSaveFileManager: failed to open '%s' file to save timestamps", filename.c_str()); return; } for (Common::HashMap<Common::String, uint32>::iterator i = timestamps.begin(); i != timestamps.end(); ++i) { Common::String data = i->_key + Common::String::format(" %u\n", i->_value); if (f.write(data.c_str(), data.size()) != data.size()) { warning("DefaultSaveFileManager: failed to write timestamps data into '%s'", filename.c_str()); return; } } f.flush(); f.finalize(); f.close(); }