void PackPrince::execute() { Common::Filename mainDir = _inputPaths[0].path; // We always need to setup default output path, since there is no obligation to specify it if (_outputPath.empty()) { _outputPath.setFullPath("./"); } _outputPath.setFullName("prince_translation.dat"); _fFiles.open(_outputPath, "wb"); if (!_fFiles.isOpen()) { error("Unable to create prince_translation.dat"); } // Export names of files _fFiles.print("variatxt_translate.dat\n"); _fFiles.print("invtxt_translate.dat\n"); _fFiles.print("talktxt_translate.dat\n"); _fFiles.print("mob_translate.dat\n"); _fFiles.print("credits_translate.dat\n"); // Export files infomation int posOfFilesInformation = _fFiles.pos(); FileEntry filesInfo[5]; int fileNr = 0; for (int i = 0; i < 5; i++) { _fFiles.writeUint32LE(0); // place for files offsets _fFiles.writeUint32LE(0); // and size of files } printf("Packing The Prince and the Coward text data...\n"); filesInfo[fileNr]._offset = _fFiles.pos(); mainDir.setFullName("variatxt.txt"); _databank.open(mainDir, "rb"); if (!_databank.isOpen()) { error("Unable to open variatxt.txt"); } packVariaTxt(); filesInfo[fileNr]._size = _fFiles.pos() - filesInfo[fileNr]._offset; fileNr++; _databank.close(); printf("variatxt_translate.dat - done\n"); filesInfo[fileNr]._offset = _fFiles.pos(); mainDir.setFullName("invtxt.txt"); _databank.open(mainDir, "rb"); if (!_databank.isOpen()) { error("Unable to open invtxt.txt"); } packInvTxt(); filesInfo[fileNr]._size = _fFiles.pos() - filesInfo[fileNr]._offset; fileNr++; _databank.close(); printf("invtxt_translate.dat - done\n"); filesInfo[fileNr]._offset = _fFiles.pos(); mainDir.setFullName("talktxt.txt"); _databank.open(mainDir, "rb"); if (!_databank.isOpen()) { error("Unable to open talktxt.txt"); } packTalkTxt(); filesInfo[fileNr]._size = _fFiles.pos() - filesInfo[fileNr]._offset; fileNr++; _databank.close(); printf("talktxt_translate.dat - done\n"); filesInfo[fileNr]._offset = _fFiles.pos(); mainDir.setFullName("mob.txt"); _databank.open(mainDir, "rb"); if (!_databank.isOpen()) { error("Unable to open mob.txt"); } packMobs(); filesInfo[fileNr]._size = _fFiles.pos() - filesInfo[fileNr]._offset; fileNr++; _databank.close(); printf("mob_translate.dat - done\n"); filesInfo[fileNr]._offset = _fFiles.pos(); mainDir.setFullName("credits.txt"); _databank.open(mainDir, "rb"); if (!_databank.isOpen()) { error("Unable to open credits.txt"); } packCredits(); filesInfo[fileNr]._size = _fFiles.pos() - filesInfo[fileNr]._offset; fileNr++; _databank.close(); printf("credits_translate.dat - done\n"); // Files offset and size setting _fFiles.seek(posOfFilesInformation, SEEK_SET); for (int i = 0; i < fileNr; i++) { _fFiles.writeUint32LE(filesInfo[i]._offset); _fFiles.writeUint32LE(filesInfo[i]._size); } _fFiles.close(); printf("All done!\n"); printf("File is created in %s\n", _outputPath.getFullPath().c_str()); }
void PackPrince::packTalkTxt() { // IDs array for first 2000 offsets calculation const int kSetStringValues = 2000; int setStringIdArray[kSetStringValues]; Common::Filename mainDir = _inputPaths[0].path; Common::File idsFile; mainDir.setFullName("talktxt_ids.txt"); idsFile.open(mainDir, "rb"); if (!idsFile.isOpen()) { error("Unable to open talktxt_ids.txt"); } // Header test byte c; std::string line; while ((c = idsFile.readByte()) != '\r') { line += c; } if (line.compare("talktxt_ids")) { error("Wrong header in talktxt_ids.txt"); } idsFile.readByte(); // skip '\n' // IDs loading for (int i = 0; i < kSetStringValues; i++) { int value = 0; while ((c = idsFile.readByte()) != '\r') { value *= 10; value += c - 48; } idsFile.readByte(); // skip '\n' setStringIdArray[i] = value; } idsFile.close(); // Main file // File size uint fileSize = _databank.size(); // Header test line.clear(); while ((c = _databank.readByte()) != '\r') { line += c; } if (line.compare("talktxt.dat")) { error("Wrong header in talktxt.txt"); } _databank.readByte(); // skip '\n' // Start pos of talkTxt file for later offset setting int startTalkTxtPos = _fFiles.pos(); // Making space for main offsets for (int i = 0; i < kSetStringValues; i++) { _fFiles.writeUint32LE(0); } int id = 1; int setStringOffsetsArray[kSetStringValues]; for (int i = 0; i < kSetStringValues; i++) { setStringOffsetsArray[i] = 0; } while (1) { line.clear(); while ((c = _databank.readByte()) != '\r') { line += c; } _databank.readByte(); // skip '\n' for (int i = 0; i < kSetStringValues; i++) { if (id == setStringIdArray[i]) { setStringOffsetsArray[i] = _fFiles.pos() - startTalkTxtPos; } } if (!line.compare("@DIALOGBOX_LINES:")) { talkTxtWithDialog(); } else if (!line.compare("@NORMAL_LINES:")) { talkTxtNoDialog(); } id++; if ((uint)_databank.pos() == fileSize) { break; } } // End of talkTxt file int endTalkTxtPos = _fFiles.pos(); // Back to start of talkTxt file for offsets setting _fFiles.seek(startTalkTxtPos, SEEK_SET); for (int i = 0; i < kSetStringValues; i++) { _fFiles.writeUint32LE(setStringOffsetsArray[i]); } // Back to the end of talkTxt file _fFiles.seek(endTalkTxtPos, SEEK_SET); }