Skip to content

Commit

Permalink
PRINCE: Update of extracting and packing tool for credits file
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Oct 25, 2014
1 parent 4e1ad68 commit 00f618f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
36 changes: 36 additions & 0 deletions engines/prince/extract_prince.cpp
Expand Up @@ -68,6 +68,9 @@ void ExtractPrince::execute() {
if (!scumm_stricmp(_items[i]._name.c_str(), "talktxt.dat")) {
exportTalkTxt(loadFile(i));
}
if (!scumm_stricmp(_items[i]._name.c_str(), "credits.dat")) {
exportCredits(loadFile(i));
}
}
free(fileTable);
_databank.close();
Expand Down Expand Up @@ -329,6 +332,39 @@ void ExtractPrince::exportInvTxt(FileData fileData) {
}
}

void ExtractPrince::exportCredits(FileData fileData) {
if (fileData._fileTable != nullptr) {
_outputPath.setFullName("credits.txt");
_fFiles.open(_outputPath, "w");
if (!_fFiles.isOpen()) {
error("Unable to create credits.txt");
}
_fFiles.print("credits.dat\n");
byte c;
byte lastC = 10;
byte *creditsTxt = fileData._fileTable;
byte *end = fileData._fileTable + fileData._size;
while (creditsTxt != end) {
c = *creditsTxt;
if (c == 10) {
_fFiles.print("@\n");
}
if (c != 13 && c != 10) {
c = correctPolishLetter(c);
_fFiles.print("%c", c);
}
if (lastC != 10 && c == 13) {
_fFiles.print("\n");
}
lastC = c;
creditsTxt++;
}
free(fileData._fileTable);
_fFiles.close();
printf("credits.txt - done\n");
}
}

void ExtractPrince::exportTalkTxt(FileData fileData) {
if (fileData._fileTable != nullptr) {
_outputPath.setFullName("talktxt.txt");
Expand Down
1 change: 1 addition & 0 deletions engines/prince/extract_prince.h
Expand Up @@ -54,6 +54,7 @@ class ExtractPrince : public Tool {
void exportMobs(FileData fileData);
void exportVariaTxt(FileData fileData);
void exportInvTxt(FileData fileData);
void exportCredits(FileData fileData);
void exportTalkTxt(FileData fileData);
byte *talkTxtWithDialog(byte *talkTxt);
byte *talkTxtNoDialog(byte *talkTxt);
Expand Down
47 changes: 47 additions & 0 deletions engines/prince/pack_prince.cpp
Expand Up @@ -74,6 +74,14 @@ void PackPrince::execute() {
}
packMobs();
_databank.close();

mainDir.setFullName("credits.txt");
_databank.open(mainDir, "rb");
if (!_databank.isOpen()) {
error("Unable to open credits.txt");
}
packCredits();
_databank.close();
}

// TODO
Expand Down Expand Up @@ -271,6 +279,45 @@ void PackPrince::packInvTxt() {
_fFiles.close();
}

void PackPrince::packCredits() {
_outputPath.setFullName("credits_translate.dat");
_fFiles.open(_outputPath, "wb");
if (!_fFiles.isOpen()) {
error("Unable to create credits_translate.dat");
}

// File size
uint32 fileSize = _databank.size();

// Header test
byte c;
std::string line;
while ((c = _databank.readByte()) != '\r') {
line += c;
}
if (line.compare("credits.dat")) {
error("Wrong header in credits.txt");
}
_databank.readByte(); // skip '\n'

while (1) {
c = _databank.readByte();
if (c != 13 && c != 10) {
if (c == '@') {
_fFiles.writeByte(13);
_fFiles.writeByte(10);
} else {
c = correctPolishLetter(c);
_fFiles.writeByte(c);
}
}
if (_databank.pos() == fileSize) {
break;
}
}
_fFiles.close();
}

void PackPrince::packTalkTxt() {
_outputPath.setFullName("talktxt_translate.dat");
_fFiles.open(_outputPath, "wb");
Expand Down
1 change: 1 addition & 0 deletions engines/prince/pack_prince.h
Expand Up @@ -56,6 +56,7 @@ class PackPrince : public Tool {
void packMobs();
void packVariaTxt();
void packInvTxt();
void packCredits();
void packTalkTxt();
char correctPolishLetter(char c);
void talkTxtWithDialog();
Expand Down

0 comments on commit 00f618f

Please sign in to comment.