summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Tanner <trtanner@btinternet.com>2015-12-05 06:51:57 +0000
committerThomas Tanner <trtanner@btinternet.com>2015-12-05 06:51:57 +0000
commitc07e48075e86c855f147e084a50ee1c7f0c00e40 (patch)
tree56ac9ee364e9a83a6b766487d65d20331ac289ad
parentc236078aa1d3b756aaabd2f2c1d28d7474de3c2d (diff)
Most of work for savegame
-rw-r--r--src/SConscript6
-rw-r--r--src/mainwindow.cpp21
-rw-r--r--src/organizer.pro4
-rw-r--r--src/savegamegamebryo.cpp336
-rw-r--r--src/savegamegamebyro.h42
-rw-r--r--src/shared/fallout3info.h2
-rw-r--r--src/shared/falloutnvinfo.h2
-rw-r--r--src/shared/gameinfo.h12
-rw-r--r--src/shared/oblivioninfo.h2
-rw-r--r--src/shared/skyriminfo.h2
-rw-r--r--src/transfersavesdialog.cpp4
11 files changed, 72 insertions, 361 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 <http://www.gnu.org/licenses/>.
#include "browserdialog.h"
#include "aboutdialog.h"
#include "safewritefile.h"
+//?
+//#include "isavegame.h"
+//#include "savegameinfo.h"
+//?
#include "nxmaccessmanager.h"
#include <archive.h>
#include <appconfig.h>
@@ -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 <http://www.gnu.org/licenses/>.
*/
#include "savegamegamebyro.h"
-#include "gameinfo.h"
-#include <QFile>
-#include <QBuffer>
-#include <set>
-#include <QFileInfo>
-#include <QDateTime>
-#include <limits>
-
-
-using namespace MOShared;
-
-
-template <typename T>
-static void FileRead(QFile &file, T &value)
-{
- int read = file.read(reinterpret_cast<char*>(&value), sizeof(T));
- if (read != sizeof(T)) {
- throw std::runtime_error("unexpected end of file");
- }
-}
-
-
-template <typename T>
-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<char>(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<unsigned long>(saveFile); // header size
- FileSkip<unsigned long>(saveFile); // header version, -> 8
- 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 (i.e. BretonRace)
-
-
- FileSkip<unsigned short>(saveFile); // ???
- FileSkip<float>(saveFile, 2); // ???
- FileSkip<unsigned char>(saveFile, 8); // filetime
+#include "isavegame.h"
+#include "savegameinfo.h"
+#include "iplugingame.h"
+#include "gamebryosavegame.h"
-// FileSkip<unsigned char>(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<unsigned char> buffer(new unsigned char[width * height * 3]);
- saveFile.read(reinterpret_cast<char*>(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<unsigned char>(saveFile); // form version
- FileSkip<unsigned long>(saveFile); // plugin info size
+#include <limits>
+#include <set>
- unsigned char pluginCount;
- FileRead(saveFile, pluginCount);
+using namespace MOBase;
- for (int i = 0; i < pluginCount; ++i) {
- m_Plugins.push_back(ReadFOSString(saveFile, false));
- }
-}
-
-void SaveGameGamebryo::readESSFile(QFile &saveFile)
+SaveGameGamebryo::SaveGameGamebryo(QObject *parent, const QString &fileName, IPluginGame const *game)
+ : SaveGame(parent, fileName)
+ , m_Plugins()
{
- char fileID[13];
- unsigned char versionMinor;
- unsigned long headerVersion, saveHeaderSize;
-// *** format is different for fallout!
- saveFile.read(fileID, 12);
- fileID[12] = '\0';
- FileSkip<unsigned char>(saveFile); FileRead(saveFile, versionMinor);
- FileSkip<SYSTEMTIME>(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);
+ SaveGameInfo const *info = game->feature<SaveGameInfo>();
+ if (info != nullptr) {
+ ISaveGame const *save = info->getSaveGameInfo(fileName);
+ m_Save = save;
- m_PCName = ReadBString(saveFile);
+ //Kludgery
+ GamebryoSaveGame const *s = dynamic_cast<GamebryoSaveGame const *>(save);
+ m_PCName = s->getPCName();
+ m_PCLevel = s->getPCLevel();
+ m_PCLocation = s->getPCLocation();
+ m_SaveNumber = s->getSaveNumber();
- FileRead(saveFile, m_PCLevel);
- m_PCLocation = ReadBString(saveFile);
- FileSkip<float>(saveFile); // game days
- FileSkip<unsigned long>(saveFile); // game ticks
- FileRead(saveFile, m_CreationTime);
+ QDateTime modified = s->getCreationTime();
+ memset(&m_CreationTime, 0, sizeof(SYSTEMTIME));
- unsigned long size;
- FileRead(saveFile, size); // screenshot size
+ m_CreationTime.wDay = static_cast<WORD>(modified.date().day());
+ m_CreationTime.wDayOfWeek = static_cast<WORD>(modified.date().dayOfWeek());
+ m_CreationTime.wMonth = static_cast<WORD>(modified.date().month());
+ m_CreationTime.wYear =static_cast<WORD>( modified.date().year());
- unsigned long width, height;
- FileRead(saveFile, width); FileRead(saveFile, height);
- QScopedArrayPointer<unsigned char> buffer(new unsigned char[width * height * 3]);
- saveFile.read(reinterpret_cast<char*>(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();
+ m_CreationTime.wHour = static_cast<WORD>(modified.time().hour());
+ m_CreationTime.wMinute = static_cast<WORD>(modified.time().minute());
+ m_CreationTime.wSecond = static_cast<WORD>(modified.time().second());
+ m_CreationTime.wMilliseconds = static_cast<WORD>(modified.time().msec());
- unsigned char pluginCount;
- FileRead(saveFile, pluginCount);
-
- for (int i = 0; i < pluginCount; ++i) {
- QString name = ReadBString(saveFile);
- m_Plugins.push_back(name);
- }
-}
+ m_Screenshot = s->getScreenshot();
-
-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<char>(saveFile, ignore); // unknown
- }
- if (newVegas) {
- ignore = 0x00;
- // in new vegas there is another block of uninteresting (?) information
- FileSkip<char>(saveFile); // 0x7c
- while (ignore != 0x7c) {
- FileRead<char>(saveFile, ignore); // unknown
- }
+ m_Plugins = s->getPlugins();
}
-
- unsigned long width, height;
- FileRead(saveFile, width);
- FileSkip<char>(saveFile); // 0x7c
- FileRead(saveFile, height);
- FileSkip<char>(saveFile); // 0x7c
-
- FileRead(saveFile, m_SaveNumber);
- FileSkip<char>(saveFile); // 0x7c
-
- m_PCName = ReadFOSString(saveFile, true);
- FileSkip<char>(saveFile); // 0x7c
-
- ReadFOSString(saveFile, true);
- FileSkip<char>(saveFile); // 0x7c
-
- long Level;
- FileRead(saveFile, Level);
- m_PCLevel = Level;
- FileSkip<char>(saveFile); // 0x7c
-
- m_PCLocation = ReadFOSString(saveFile, true);
- FileSkip<char>(saveFile); // 0x7c
-
- ReadFOSString(saveFile, true); // playtime
-
- FileSkip<char>(saveFile);
-
- QScopedArrayPointer<unsigned char> buffer(new unsigned char[width * height * 3]);
- saveFile.read(reinterpret_cast<char*>(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<char>(saveFile, 5); // unknown
-
- unsigned char pluginCount = 0;
- FileRead(saveFile, pluginCount);
- FileSkip<char>(saveFile); // 0x7c
-
- for (int i = 0; i < pluginCount; ++i) {
- QString name = ReadFOSString(saveFile, true);
- m_Plugins.push_back(name);
- FileSkip<char>(saveFile); // 0x7c
- }
-}
-
-
-void SaveGameGamebryo::setCreationTime(const QString &fileName)
-{
- QFileInfo creationTime(fileName);
- QDateTime modified = creationTime.lastModified();
- memset(&m_CreationTime, 0, sizeof(SYSTEMTIME));
-
- m_CreationTime.wDay = static_cast<WORD>(modified.date().day());
- m_CreationTime.wDayOfWeek = static_cast<WORD>(modified.date().dayOfWeek());
- m_CreationTime.wMonth = static_cast<WORD>(modified.date().month());
- m_CreationTime.wYear =static_cast<WORD>( modified.date().year());
-
- m_CreationTime.wHour = static_cast<WORD>(modified.time().hour());
- m_CreationTime.wMinute = static_cast<WORD>(modified.time().minute());
- m_CreationTime.wSecond = static_cast<WORD>(modified.time().second());
- m_CreationTime.wMilliseconds = static_cast<WORD>(modified.time().msec());
-}
-
-
-void SaveGameGamebryo::readFile(const QString &fileName)
-{
- 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;
- }
-
- 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 <http://www.gnu.org/licenses/>.
#ifndef SAVEGAMEGAMEBRYO_H
#define SAVEGAMEGAMEBRYO_H
-
#include "savegame.h"
-#include <QString>
-#include <QObject>
#include <QMetaType>
-#include <QFile>
-
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
+#include <QObject>
+#include <QString>
+namespace MOBase { class IPluginGame; class ISaveGame; }
/**
* @brief represents a single save game
@@ -42,30 +38,20 @@ 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<QString> 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<std::wstring> 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<std::wstring> 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
@@ -40,24 +40,12 @@ class GameInfo
public:
- enum Type {
- TYPE_OBLIVION,
- TYPE_FALLOUT3,
- TYPE_FALLOUTNV,
- TYPE_SKYRIM
- };
-
-public:
-
virtual ~GameInfo() {}
//**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<std::wstring> 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<std::wstring> 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<std::wstring> 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);
}