From c07e48075e86c855f147e084a50ee1c7f0c00e40 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Sat, 5 Dec 2015 06:51:57 +0000 Subject: Most of work for savegame --- src/SConscript | 6 + src/mainwindow.cpp | 21 ++- src/organizer.pro | 4 + src/savegamegamebryo.cpp | 348 +++++--------------------------------------- src/savegamegamebyro.h | 42 ++---- src/shared/fallout3info.h | 2 - src/shared/falloutnvinfo.h | 2 - src/shared/gameinfo.h | 12 -- src/shared/oblivioninfo.h | 2 - src/shared/skyriminfo.h | 2 - src/transfersavesdialog.cpp | 4 +- 11 files changed, 78 insertions(+), 367 deletions(-) diff --git a/src/SConscript b/src/SConscript index f09db093..8e0280ef 100644 --- a/src/SConscript +++ b/src/SConscript @@ -96,6 +96,12 @@ env['CPPPATH'] += [ '${BOOSTPATH}', ] +#########################FUDGE############################### +env['CPPPATH'] += [ + '../plugins/gameGamebryo', + ] +############################################################# + env.AppendUnique(CPPDEFINES = [ '_UNICODE', '_CRT_SECURE_NO_WARNINGS', diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 152baee7..1101f3fa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -59,6 +59,10 @@ along with Mod Organizer. If not, see . #include "browserdialog.h" #include "aboutdialog.h" #include "safewritefile.h" +//? +//#include "isavegame.h" +//#include "savegameinfo.h" +//? #include "nxmaccessmanager.h" #include #include @@ -826,9 +830,22 @@ void MainWindow::setBrowserGeometry(const QByteArray &geometry) } -SaveGameGamebryo *MainWindow::getSaveGame(const QString &name) +SaveGameGamebryo *MainWindow::getSaveGame(const QString &name__) { - return new SaveGameGamebryo(this, name); + IPluginGame const *game = m_OrganizerCore.managedGame(); + QString name(name__); + + //fudge with me +// game = m_PluginContainer.managedGame("Fallout 3"); +// name = "C:\\Users\\Dad\\Downloads\\Games\\Both good and evil saves -10416\\Save 106 - New Start Good, Vault 101 Entrance, 00.33.34.fos"; + +// game = m_PluginContainer.managedGame("New Vegas"); +// name = "C:\\Users\\Dad\\Downloads\\Games\\Crossroads - Clean Save-44883-1-0\\Crossroads.fos"; + +// game = m_PluginContainer.managedGame("Oblivion"); +// name = "C:\\Users\\Dad\\Saved Games\\Oblivion\\Saves\\Save 1537 - Hilary - Xirethard, Level 45, Playing Time 458.48.17.ess"; + + return new SaveGameGamebryo(this, name, game); } diff --git a/src/organizer.pro b/src/organizer.pro index 2869fda5..f472bd80 100644 --- a/src/organizer.pro +++ b/src/organizer.pro @@ -232,6 +232,10 @@ INCLUDEPATH += "E:/Visual Leak Detector/include" LIBS += -L"E:/Visual Leak Detector/lib/Win32" #DEFINES += LEAK_CHECK_WITH_VLD +#########################FUDGE############################### +INCLUDEPATH += ../plugins/gameGamebro +############################################################# + # custom leak detection #LIBS += -lDbgHelp diff --git a/src/savegamegamebryo.cpp b/src/savegamegamebryo.cpp index 7b012e22..457cbdf2 100644 --- a/src/savegamegamebryo.cpp +++ b/src/savegamegamebryo.cpp @@ -18,321 +18,49 @@ along with Mod Organizer. If not, see . */ #include "savegamegamebyro.h" -#include "gameinfo.h" -#include -#include -#include -#include -#include -#include - - -using namespace MOShared; - - -template -static void FileRead(QFile &file, T &value) -{ - int read = file.read(reinterpret_cast(&value), sizeof(T)); - if (read != sizeof(T)) { - throw std::runtime_error("unexpected end of file"); - } -} - - -template -static void FileSkip(QFile &file, int count = 1) -{ - char ignore[sizeof(T)]; - for (int i = 0; i < count; ++i) { - if (file.read(ignore, sizeof(T)) != sizeof(T)) { - throw std::runtime_error("unexpected end of file"); - } - } -} - - -static QString ReadBString(QFile &file) -{ - char buffer[256]; - file.read(buffer, 1); // size including zero termination - unsigned char size = buffer[0]; - file.read(buffer, size); - return QString::fromLatin1(buffer, size); -} - - -static QString ReadFOSString(QFile &file, bool delimiter) -{ - union { - char lengthBuffer[2]; - unsigned short length; - }; - - file.read(lengthBuffer, 2); - if (delimiter) { - FileSkip(file); // 0x7c - } - char *buffer = new char[length]; - file.read(buffer, length); - - QString result = QString::fromLatin1(buffer, length); - delete [] buffer; - - return result; -} - - -SaveGameGamebryo::SaveGameGamebryo(QObject *parent) - : SaveGame(parent), m_Plugins() -{ -} - - -SaveGameGamebryo::SaveGameGamebryo(QObject *parent, const QString &fileName) - : SaveGame(parent, fileName), m_Plugins() -{ - readFile(fileName); -} - - -SaveGameGamebryo::SaveGameGamebryo(const SaveGameGamebryo& reference) - : SaveGame(reference), m_Plugins(reference.m_Plugins) -{ -} - - -SaveGameGamebryo& SaveGameGamebryo::operator=(const SaveGameGamebryo &reference) -{ - if (&reference != this) { - SaveGame::operator =(reference); - m_Plugins = reference.m_Plugins; - } - return *this; -} - - -SaveGameGamebryo::~SaveGameGamebryo() -{ -} - - - - - -void SaveGameGamebryo::readSkyrimFile(QFile &saveFile) -{ - char fileID[14]; - - saveFile.read(fileID, 13); - fileID[13] = '\0'; - if (strncmp(fileID, "TESV_SAVEGAME", 13) != 0) { - throw std::runtime_error(QObject::tr("wrong file format").toUtf8().constData()); - } - - FileSkip(saveFile); // header size - FileSkip(saveFile); // header version, -> 8 - FileRead(saveFile, m_SaveNumber); - m_PCName = ReadFOSString(saveFile, false); +#include "isavegame.h" +#include "savegameinfo.h" +#include "iplugingame.h" +#include "gamebryosavegame.h" - unsigned long temp; - FileRead(saveFile, temp); // player level - m_PCLevel = static_cast(temp); - - m_PCLocation = ReadFOSString(saveFile, false); - ReadFOSString(saveFile, false); // playtime as ascii hhh.mm.ss - ReadFOSString(saveFile, false); // race name (i.e. BretonRace) - - - FileSkip(saveFile); // ??? - FileSkip(saveFile, 2); // ??? - FileSkip(saveFile, 8); // filetime - -// FileSkip(saveFile, 18); // ??? 18 bytes of data. not completely random, maybe a time stamp? maybe - - unsigned long width, height; - FileRead(saveFile, width); // 320 - FileRead(saveFile, height); // 192 - - QScopedArrayPointer buffer(new unsigned char[width * height * 3]); - saveFile.read(reinterpret_cast(buffer.data()), width * height * 3); - // why do I have to copy here? without the copy, the buffer seems to get deleted after the - // temporary vanishes, but Qts implicit sharing should handle that? - m_Screenshot = QImage(buffer.data(), width, height, QImage::Format_RGB888).copy(); - - FileSkip(saveFile); // form version - FileSkip(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) -{ - char fileID[13]; - unsigned char versionMinor; - unsigned long headerVersion, saveHeaderSize; -// *** format is different for fallout! - saveFile.read(fileID, 12); - fileID[12] = '\0'; - FileSkip(saveFile); FileRead(saveFile, versionMinor); - FileSkip(saveFile); // modified time - FileRead(saveFile, headerVersion); FileRead(saveFile, saveHeaderSize); - - if (strncmp(fileID, "TES4SAVEGAME", 12) != 0) { - throw std::runtime_error(QObject::tr("wrong file format").toUtf8().constData()); - } - - FileRead(saveFile, m_SaveNumber); - - m_PCName = ReadBString(saveFile); - - FileRead(saveFile, m_PCLevel); - m_PCLocation = ReadBString(saveFile); - FileSkip(saveFile); // game days - FileSkip(saveFile); // game ticks - FileRead(saveFile, m_CreationTime); - - unsigned long size; - FileRead(saveFile, size); // screenshot size - - unsigned long width, height; - FileRead(saveFile, width); FileRead(saveFile, height); - QScopedArrayPointer buffer(new unsigned char[width * height * 3]); - saveFile.read(reinterpret_cast(buffer.data()), width * height * 3); - // why do I have to copy here? without the copy, the buffer seems to get deleted after the - // temporary vanishes, but Qts implicit sharing should handle that? - m_Screenshot = QImage(buffer.data(), width, height, QImage::Format_RGB888).copy(); - - unsigned char pluginCount; - FileRead(saveFile, pluginCount); - - for (int i = 0; i < pluginCount; ++i) { - QString name = ReadBString(saveFile); - m_Plugins.push_back(name); - } -} - - -void SaveGameGamebryo::readFOSFile(QFile &saveFile, bool newVegas) -{ - char fileID[13]; - saveFile.read(fileID, 12); - // the signature is only 11 characters, the 12th is random? - fileID[11] = '\0'; - - if (strncmp(fileID, "FO3SAVEGAME", 11) != 0) { - throw std::runtime_error(QObject::tr("wrong file format").toUtf8().constData()); - } - - char ignore = 0x00; - while (ignore != 0x7c) { - FileRead(saveFile, ignore); // unknown - } - if (newVegas) { - ignore = 0x00; - // in new vegas there is another block of uninteresting (?) information - FileSkip(saveFile); // 0x7c - while (ignore != 0x7c) { - FileRead(saveFile, ignore); // unknown - } - } - - unsigned long width, height; - FileRead(saveFile, width); - FileSkip(saveFile); // 0x7c - FileRead(saveFile, height); - FileSkip(saveFile); // 0x7c - - FileRead(saveFile, m_SaveNumber); - FileSkip(saveFile); // 0x7c - - m_PCName = ReadFOSString(saveFile, true); - FileSkip(saveFile); // 0x7c - - ReadFOSString(saveFile, true); - FileSkip(saveFile); // 0x7c - - long Level; - FileRead(saveFile, Level); - m_PCLevel = Level; - FileSkip(saveFile); // 0x7c - - m_PCLocation = ReadFOSString(saveFile, true); - FileSkip(saveFile); // 0x7c - - ReadFOSString(saveFile, true); // playtime - - FileSkip(saveFile); - - QScopedArrayPointer buffer(new unsigned char[width * height * 3]); - saveFile.read(reinterpret_cast(buffer.data()), width * height * 3); - // why do I have to copy here? without the copy, the buffer seems to get deleted after the - // temporary vanishes, but Qts implicit sharing should handle that? - m_Screenshot = QImage(buffer.data(), width, height, QImage::Format_RGB888).scaledToWidth(256); - - FileSkip(saveFile, 5); // unknown - - unsigned char pluginCount = 0; - FileRead(saveFile, pluginCount); - FileSkip(saveFile); // 0x7c - - for (int i = 0; i < pluginCount; ++i) { - QString name = ReadFOSString(saveFile, true); - m_Plugins.push_back(name); - FileSkip(saveFile); // 0x7c - } -} - - -void SaveGameGamebryo::setCreationTime(const QString &fileName) -{ - QFileInfo creationTime(fileName); - QDateTime modified = creationTime.lastModified(); - memset(&m_CreationTime, 0, sizeof(SYSTEMTIME)); +#include +#include - m_CreationTime.wDay = static_cast(modified.date().day()); - m_CreationTime.wDayOfWeek = static_cast(modified.date().dayOfWeek()); - m_CreationTime.wMonth = static_cast(modified.date().month()); - m_CreationTime.wYear =static_cast( modified.date().year()); +using namespace MOBase; - m_CreationTime.wHour = static_cast(modified.time().hour()); - m_CreationTime.wMinute = static_cast(modified.time().minute()); - m_CreationTime.wSecond = static_cast(modified.time().second()); - m_CreationTime.wMilliseconds = static_cast(modified.time().msec()); -} - -void SaveGameGamebryo::readFile(const QString &fileName) +SaveGameGamebryo::SaveGameGamebryo(QObject *parent, const QString &fileName, IPluginGame const *game) + : SaveGame(parent, fileName) + , m_Plugins() { - m_FileName = fileName; - QFile saveFile(fileName); - if (!saveFile.open(QIODevice::ReadOnly)) { - throw std::runtime_error(QObject::tr("failed to open %1").arg(fileName).toUtf8().constData()); - } - switch (GameInfo::instance().getType()) { - case GameInfo::TYPE_FALLOUT3: { - setCreationTime(fileName); - readFOSFile(saveFile, false); - } break; - case GameInfo::TYPE_FALLOUTNV: { - setCreationTime(fileName); - readFOSFile(saveFile, true); - } break; - case GameInfo::TYPE_OBLIVION: { - readESSFile(saveFile); - } break; - case GameInfo::TYPE_SKYRIM: { - setCreationTime(fileName); - readSkyrimFile(saveFile); - } break; + SaveGameInfo const *info = game->feature(); + if (info != nullptr) { + ISaveGame const *save = info->getSaveGameInfo(fileName); + m_Save = save; + + //Kludgery + GamebryoSaveGame const *s = dynamic_cast(save); + m_PCName = s->getPCName(); + m_PCLevel = s->getPCLevel(); + m_PCLocation = s->getPCLocation(); + m_SaveNumber = s->getSaveNumber(); + + QDateTime modified = s->getCreationTime(); + memset(&m_CreationTime, 0, sizeof(SYSTEMTIME)); + + m_CreationTime.wDay = static_cast(modified.date().day()); + m_CreationTime.wDayOfWeek = static_cast(modified.date().dayOfWeek()); + m_CreationTime.wMonth = static_cast(modified.date().month()); + m_CreationTime.wYear =static_cast( modified.date().year()); + + m_CreationTime.wHour = static_cast(modified.time().hour()); + m_CreationTime.wMinute = static_cast(modified.time().minute()); + m_CreationTime.wSecond = static_cast(modified.time().second()); + m_CreationTime.wMilliseconds = static_cast(modified.time().msec()); + + m_Screenshot = s->getScreenshot(); + + m_Plugins = s->getPlugins(); } - - saveFile.close(); } diff --git a/src/savegamegamebyro.h b/src/savegamegamebyro.h index e08e1044..bce08018 100644 --- a/src/savegamegamebyro.h +++ b/src/savegamegamebyro.h @@ -20,17 +20,13 @@ along with Mod Organizer. If not, see . #ifndef SAVEGAMEGAMEBRYO_H #define SAVEGAMEGAMEBRYO_H - #include "savegame.h" -#include -#include #include -#include - -#define WIN32_LEAN_AND_MEAN -#include +#include +#include +namespace MOBase { class IPluginGame; class ISaveGame; } /** * @brief represents a single save game @@ -41,31 +37,21 @@ Q_OBJECT public: - /** - * @brief construct an empty object - **/ - SaveGameGamebryo(QObject *parent = 0); - /** * @brief construct a save game and immediately read out information from the file * * @param filename absolute path of the save game file **/ - SaveGameGamebryo(QObject *parent, const QString &filename); + SaveGameGamebryo(QObject *parent, const QString &filename, MOBase::IPluginGame const *game); + /* SaveGameGamebryo(const SaveGameGamebryo &reference); SaveGameGamebryo &operator=(const SaveGameGamebryo &reference); ~SaveGameGamebryo(); - - /** - * @brief read out information from a savegame - * - * @param fileName absolute path of the save game file - **/ - virtual void readFile(const QString &fileName); + */ /** * @return number of plugins that were enabled when the save game was created @@ -80,22 +66,12 @@ public: **/ const QString &plugin(int index) const { return m_Plugins.at(index); } - private: - void readESSFile(QFile &saveFile); - void readFOSFile(QFile &saveFile, bool newVegas); - void readSkyrimFile(QFile &saveFile); - - void setCreationTime(const QString &fileName); - -private: - - std::vector m_Plugins; + QStringList m_Plugins; + //Note: This isn't owned by us so safe to copy + MOBase::ISaveGame const *m_Save; }; -Q_DECLARE_METATYPE(SaveGameGamebryo) -Q_DECLARE_METATYPE(SaveGameGamebryo*) - #endif // SAVEGAMEGAMEBRYO_H diff --git a/src/shared/fallout3info.h b/src/shared/fallout3info.h index 69eb9c45..489ac038 100644 --- a/src/shared/fallout3info.h +++ b/src/shared/fallout3info.h @@ -38,8 +38,6 @@ public: static std::wstring getRegPathStatic(); virtual std::wstring getRegPath() { return getRegPathStatic(); } - virtual GameInfo::Type getType() { return TYPE_FALLOUT3; } - virtual std::vector getSavegameAttachmentExtensions(); // file name of this games ini (no path) diff --git a/src/shared/falloutnvinfo.h b/src/shared/falloutnvinfo.h index a7ee089e..a0bc5bd4 100644 --- a/src/shared/falloutnvinfo.h +++ b/src/shared/falloutnvinfo.h @@ -38,8 +38,6 @@ public: static std::wstring getRegPathStatic(); virtual std::wstring getRegPath() { return getRegPathStatic(); } - virtual GameInfo::Type getType() { return TYPE_FALLOUTNV; } - virtual std::vector getSavegameAttachmentExtensions(); // file name of this games ini (no path) diff --git a/src/shared/gameinfo.h b/src/shared/gameinfo.h index 01d51f8a..9e6a35ef 100644 --- a/src/shared/gameinfo.h +++ b/src/shared/gameinfo.h @@ -38,15 +38,6 @@ namespace MOShared { class GameInfo { -public: - - enum Type { - TYPE_OBLIVION, - TYPE_FALLOUT3, - TYPE_FALLOUTNV, - TYPE_SKYRIM - }; - public: virtual ~GameInfo() {} @@ -54,9 +45,6 @@ public: //**USED IN HOOKDLL and savegame code static GameInfo& instance(); - //**Used only in savegame which needs refactoring a lot. - virtual GameInfo::Type getType() = 0; - //**Used only in savegame which needs refactoring a lot. // get a list of file extensions for additional files belonging to a save game virtual std::vector getSavegameAttachmentExtensions() = 0; diff --git a/src/shared/oblivioninfo.h b/src/shared/oblivioninfo.h index e0a861bf..1e48b742 100644 --- a/src/shared/oblivioninfo.h +++ b/src/shared/oblivioninfo.h @@ -36,8 +36,6 @@ public: static std::wstring getRegPathStatic(); virtual std::wstring getRegPath() { return getRegPathStatic(); } - virtual GameInfo::Type getType() { return TYPE_OBLIVION; } - virtual std::vector getSavegameAttachmentExtensions(); // file name of this games ini (no path) diff --git a/src/shared/skyriminfo.h b/src/shared/skyriminfo.h index 17b542ab..ce2510f1 100644 --- a/src/shared/skyriminfo.h +++ b/src/shared/skyriminfo.h @@ -38,8 +38,6 @@ public: static std::wstring getRegPathStatic(); virtual std::wstring getRegPath() { return getRegPathStatic(); } - virtual GameInfo::Type getType() { return TYPE_SKYRIM; } - virtual std::vector getSavegameAttachmentExtensions(); // file name of this games ini (no path) diff --git a/src/transfersavesdialog.cpp b/src/transfersavesdialog.cpp index 4cb20944..48fc4548 100644 --- a/src/transfersavesdialog.cpp +++ b/src/transfersavesdialog.cpp @@ -63,7 +63,7 @@ void TransferSavesDialog::refreshGlobalSaves() QStringList files = savesDir.entryList(QDir::Files, QDir::Time); for (const QString &filename : files) { - SaveGameGamebryo *save = new SaveGameGamebryo(this, savesDir.absoluteFilePath(filename)); + SaveGameGamebryo *save = new SaveGameGamebryo(this, savesDir.absoluteFilePath(filename), m_GamePlugin); save->setParent(this); m_GlobalSaves.push_back(save); } @@ -81,7 +81,7 @@ void TransferSavesDialog::refreshLocalSaves() QStringList files = savesDir.entryList(QDir::Files, QDir::Time); foreach (const QString &filename, files) { - SaveGameGamebryo *save = new SaveGameGamebryo(this, savesDir.absoluteFilePath(filename)); + SaveGameGamebryo *save = new SaveGameGamebryo(this, savesDir.absoluteFilePath(filename), m_GamePlugin); save->setParent(this); m_LocalSaves.push_back(save); } -- cgit v1.3.1