Skip to content

Commit

Permalink
added support for fallout 4 savegames
Browse files Browse the repository at this point in the history
  • Loading branch information
TanninOne committed Nov 23, 2015
1 parent dbbd0c4 commit 9945b5e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
59 changes: 56 additions & 3 deletions src/savegamegamebryo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ SaveGameGamebryo::~SaveGameGamebryo()
}





void SaveGameGamebryo::readSkyrimFile(QFile &saveFile)
{
char fileID[14];
Expand Down Expand Up @@ -172,6 +169,58 @@ void SaveGameGamebryo::readSkyrimFile(QFile &saveFile)
}
}

void SaveGameGamebryo::readFO4File(QFile &saveFile)
{
char fileID[13];

saveFile.read(fileID, 12);
fileID[12] = '\0';
if (strncmp(fileID, "FO4_SAVEGAME", 12) != 0) {
throw std::runtime_error(QObject::tr("wrong file format").toUtf8().constData());
}

FileSkip<unsigned long>(saveFile); // header size
FileSkip<unsigned long>(saveFile); // header version, -> 11
FileRead(saveFile, m_SaveNumber);

m_PCName = ReadFOSString(saveFile, false);

unsigned long temp;
FileRead(saveFile, temp); // player level
m_PCLevel = static_cast<unsigned short>(temp);

m_PCLocation = ReadFOSString(saveFile, false);
ReadFOSString(saveFile, false); // playtime as ascii hhh.mm.ss
ReadFOSString(saveFile, false); // race name (HumanRace)


FileSkip<unsigned short>(saveFile); // ???
FileSkip<float>(saveFile, 2); // ???
FileSkip<unsigned char>(saveFile, 8); // filetime

// FileSkip<unsigned char>(saveFile, 18); // ??? 18 bytes of data. not completely random, maybe a time stamp? maybe

unsigned long width, height;
FileRead(saveFile, width); // 640
FileRead(saveFile, height); // 384

QScopedArrayPointer<unsigned char> buffer(new unsigned char[width * height * 4]);
saveFile.read(reinterpret_cast<char*>(buffer.data()), width * height * 4);
// 640x384 is a bit large
m_Screenshot = QImage(buffer.data(), width, height, QImage::Format_RGBA8888).scaledToWidth(320);

FileSkip<unsigned char>(saveFile); // form version (?)
ReadFOSString(saveFile, false); // game version
FileSkip<unsigned long>(saveFile); // plugin info size (?)

unsigned char pluginCount;
FileRead(saveFile, pluginCount);

for (int i = 0; i < pluginCount; ++i) {
m_Plugins.push_back(ReadFOSString(saveFile, false));
}
}


void SaveGameGamebryo::readESSFile(QFile &saveFile)
{
Expand Down Expand Up @@ -332,6 +381,10 @@ void SaveGameGamebryo::readFile(const QString &fileName)
setCreationTime(fileName);
readSkyrimFile(saveFile);
} break;
case GameInfo::TYPE_FALLOUT4: {
setCreationTime(fileName);
readFO4File(saveFile);
} break;
}

saveFile.close();
Expand Down
1 change: 1 addition & 0 deletions src/savegamegamebyro.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Q_OBJECT

void readESSFile(QFile &saveFile);
void readFOSFile(QFile &saveFile, bool newVegas);
void readFO4File(QFile &saveFile);
void readSkyrimFile(QFile &saveFile);

void setCreationTime(const QString &fileName);
Expand Down
2 changes: 1 addition & 1 deletion src/transfersavesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void TransferSavesDialog::refreshLocalSaves()

QStringList files = savesDir.entryList(QDir::Files, QDir::Time);

foreach (const QString &filename, files) {
for (const QString &filename : files) {
SaveGameGamebryo *save = new SaveGameGamebryo(this, savesDir.absoluteFilePath(filename));
save->setParent(this);
m_LocalSaves.push_back(save);
Expand Down

0 comments on commit 9945b5e

Please sign in to comment.