Browse Source

Added precompiled libraries, updated LotroDat headers and finished implementation of Lotro class in Legacy-advanced

Ivan Arkhipov 5 years ago
parent
commit
e8fce45fbe

+ 1 - 0
.gitignore

@@ -65,6 +65,7 @@ Makefile*
 *-build-*
 build/*
 bin/*
+!lib.win32/*
 
 # QtCreator
 

+ 8 - 7
import/LotroDat/DatFile.h

@@ -26,13 +26,14 @@ extern "C++"
 {
 namespace LOTRO_DAT {
     enum FILE_TYPE : int {
-        TEXT = 0,
-        JPG = 1,
-        DDS = 2,
-        WAV = 3,
-        OGG = 4,
-        FONT = 5,
-        UNKNOWN = 6
+        NO_TYPE = 0,
+        TEXT = 1,
+        JPG = 2,
+        DDS = 4,
+        WAV = 8,
+        OGG = 16,
+        FONT = 32,
+        UNKNOWN = 64
     };
 
     class DatFile {

+ 4 - 2
import/LotroDat/DatSubsystems/DatFileSystem.h

@@ -48,14 +48,16 @@ namespace LOTRO_DAT {
 
         DatOperationResult<> InitAllFiles();
 
-        DatOperationResult<BinaryData> GetFileData(long long file_id, long long int offset);
+        DatOperationResult<BinaryData> GetFileData(const SubFile& file, long long int offset);
 
         DatOperationResult<std::shared_ptr<SubFile>> GetFile(long long file_id);
 
-        DatOperationResult<bool> CheckCorrectSubfile(const std::shared_ptr<SubFile> &file);
+        DatOperationResult<bool> CheckCorrectSubfile(const SubFile& file);
 
         DatOperationResult<> UpdateFileInfo(const SubFile& file);
 
+        int GetInitialisedFilesNumber() const;
+
         void PrintInformaion(FILE* file);
 
         DatOperationResult<> DeInit();

+ 3 - 1
import/LotroDat/DatSubsystems/DatLocaleManager.h

@@ -3,9 +3,10 @@
 
 #include <memory>
 #include <map>
-#include "../DatOperationResult.h"
 #include <set>
 
+#include "../DatOperationResult.h"
+
 extern "C++" {
 namespace LOTRO_DAT {
     class DatFile;
@@ -64,6 +65,7 @@ namespace LOTRO_DAT {
 
         void UpdateCategory(long long file_id, long long category);
 
+        const std::set<long long>& GetInactiveCategories();
     private:
         std::map<long long, SubFile> &GetLocaleDictReference(LOCALE locale);
 

+ 1 - 1
import/LotroDat/DatSubsystems/DatPatcher.h

@@ -35,7 +35,7 @@ namespace LOTRO_DAT {
 
         explicit DatPatcher(DatFile *datFilePtr);
 
-        DatOperationResult<> PatchFile(const SubfileData &data);
+        DatOperationResult<> PatchFile(const SubfileData &data, bool single_file = true);
 
         DatOperationResult<int> PatchAllDatabase(Database *db);
 

+ 21 - 12
import/LotroDat/DatSubsystems/DatStatus.h

@@ -19,6 +19,18 @@ namespace LOTRO_DAT {
 
     class DatStatus {
     public:
+        enum DAT_STATUS: int {
+            E_INITIALISING,
+            E_EXTRACTING,
+            E_PATCHING,
+            E_COMMITING,
+            E_BACKUP_CREATING,
+            E_BACKUP_RESTORING,
+            E_BACKUP_REMOVING,
+            E_GATHERING_INFO,
+            E_FREE
+        };
+
         DatStatus() = delete;
 
         DatStatus(const DatStatus &other) = delete;
@@ -29,21 +41,17 @@ namespace LOTRO_DAT {
 
         explicit DatStatus(DatFile *datFilePtr);
 
-        void UpdatePercentage(unsigned percent);
+        void SetPercentage(unsigned percent);
 
         unsigned GetPercentage();
 
-        void UpdateStatusText(const std::string &message);
-
-        void RemoveStatusText();
+        void SetDebugMessage(const std::string &message);
 
-        std::string GetStatusText();
+        std::string GetDebugMessage();
 
-        void UpdateAdditionalMessage(const std::string &message);
+        void SetStatus(DAT_STATUS status);
 
-        void RemoveAdditionalMessage();
-
-        std::string GetAdditionalMessage();
+        DAT_STATUS GetStatus();
 
         bool CheckIfNotPatched();
 
@@ -51,9 +59,10 @@ namespace LOTRO_DAT {
 
     private:
         DatFile *dat;
-        unsigned percentage;
-        std::string status_text;
-        std::string additional_message;
+        unsigned percentage_;
+        DAT_STATUS status_;
+
+        std::string debug_message;
     };
 }
 

+ 2 - 2
import/LotroDat/LotroDat.h

@@ -7,5 +7,5 @@
 #include "SubfileData.h"
 #include "DatOperationResult.h"
 
-#include "yaml-cpp/yaml.h"
-#include "ZLib/zlib.h"
+#include <yaml-cpp/yaml.h>
+#include <ZLib/zlib.h>

+ 128 - 13
src/Legacy-advanced/models/lotro.cpp

@@ -70,8 +70,8 @@ void Lotro::getLocaleFileContents(long long file_id, int locale) {
 
     auto getfile_op = file.GetLocaleManager().GetLocaleFile(file_id, locale);
     if (!getfile_op.result) {
-        emit caughtError("getOriginalFileContents", {"Файл не найден!", QString("Не удаётся найти файл с id ") + QString::number(file_id)});
-        emit processFinished("getOriginalFileContents", {"Error"});
+        emit caughtError("getFileContents", {"Файл не найден!", QString("Не удаётся найти файл с id ") + QString::number(file_id)});
+        emit processFinished("getFileContents", {"Error"});
         busy = false;
         return;
     }
@@ -81,8 +81,8 @@ void Lotro::getLocaleFileContents(long long file_id, int locale) {
     auto getfiledata_op = file.GetFileSystem().GetFileData(subfile, 8);
 
     if (getfile_op.result == LOTRO_DAT::ERROR) {
-        emit caughtError("getOriginalFileContents", {"Ошибка извлечения!", QString("Обнаружены некорректные данные файла в словаре! Файл ресурсов мог быть повреждён!\nid = ") + QString::number(file_id) + ", locale_id = " + QString::number(locale)});
-        emit processFinished("getOriginalFileContents", {"Error"});
+        emit caughtError("getFileContents", {"Ошибка извлечения!", QString("Обнаружены некорректные данные файла в словаре! Файл ресурсов мог быть повреждён!\nid = ") + QString::number(file_id) + ", locale_id = " + QString::number(locale)});
+        emit processFinished("getFileContents", {"Error"});
         busy = false;
         return;
     }
@@ -334,10 +334,10 @@ void Lotro::createCoreStatusFile(QString output_filename) {
     busy = false;
 
     if (gatherinfo_op.result == LOTRO_DAT::SUCCESS) {
-        emit processFinished("createCoreStatusFile", {"Success", {output_filename}});
+        emit processFinished("createCoreStatusFile", {"Success", output_filename});
     } else {
         emit caughtError("createCoreStatusFile", {"Ошибка сбора информации!", QString("Не удаётся создать файл информации ядра")});
-        emit processFinished("createCoreStatusFile", {"Error", {output_filename}});
+        emit processFinished("createCoreStatusFile", {"Error", output_filename});
     }
 }
 
@@ -374,10 +374,10 @@ void Lotro::extractSingleFileToDatabase(QString database_path, long long file_id
     busy = false;
 
     if (extractfile_op.result == LOTRO_DAT::SUCCESS) {
-        emit processFinished("extractSingleFileToDatabase", {"Success", {database_path, file_id}});
+        emit processFinished("extractSingleFileToDatabase", {"Success", database_path, file_id});
     } else {
         emit caughtError("extractSingleFileToDatabase", {"Ошибка экспорта!", QString("Не удаётся экспортировать файл " + QString::number(file_id) + " в базу данных " + database_path)});
-        emit processFinished("extractSingleFileToDatabase", {"Error", {database_path}});
+        emit processFinished("extractSingleFileToDatabase", {"Error", database_path});
     }
 }
 
@@ -414,33 +414,148 @@ void Lotro::extractGrouppedFilesToDatabase(QString database_path, LOTRO_DAT::FIL
     busy = false;
 
     if (extractfile_op.result == LOTRO_DAT::SUCCESS) {
-        emit processFinished("extractGrouppedFilesToDatabase", {"Success", {database_path, type}});
+        emit processFinished("extractGrouppedFilesToDatabase", {"Success", database_path, type});
     } else {
         emit caughtError("extractGrouppedFilesToDatabase", {"Ошибка экспорта!", QString("Не удаётся экспортировать файлы с типом " + QString::number(type) + " в базу данных " + database_path)});
-        emit processFinished("extractGrouppedFilesToDatabase", {"Error", {output_foldername}});
+        emit processFinished("extractGrouppedFilesToDatabase", {"Error", output_foldername});
     }
 }
 
 void Lotro::getUnactiveCategories() {
+    if (!tryToBlockFile())
+        return;
+
+    emit processStarted("getUnactiveCategories", {});
+
+    const std::set<long long>& categories = file.GetLocaleManager().GetInactiveCategories();
+
+    QStringList result;
+    for (long long category : categories) {
+        result << QString::number(category);
+    }
 
+    busy = false;
+    emit unactiveCategoriesReceived(result);
+    emit processFinished("getUnactiveCategories", {"Success"});
 }
 
 void Lotro::startGame() {
+    if (!tryToBlockFile())
+        return;
+    emit processStarted("startGame", {});
+
+    QStringList args;
+    args << "-skiprawdownload" << "-nosplash";
+    if (file.GetLocaleManager().GetCurrentLocale() == LOTRO_DAT::DatLocaleManager::PATCHED)
+        args << "-disablePatch";
+
+    file.Deinitialize();
+
+    if(FileSystem::fileExists(QApplication::applicationDirPath() + "/user.ini")){
+        QSettings login(QApplication::applicationDirPath() + "/user.ini", QSettings::IniFormat );
+        login.beginGroup("Account");
+        QString username = login.value("username", "").toString();
+        QString password = login.value("password", "").toString();
+        login.endGroup();
+        args << "-username" << username << "-password" << password;
+    }
+
+    qDebug() << "Запускаем игру со следующими аргументами: " << args;
+
+    QFile f(app_settings("Local", "folder") + "/LotroLauncher.exe");
+    QProcess process;
 
+    if (FileSystem::fileExists(f.fileName())) {
+        if(f.fileName().contains(" ")) f.setFileName("\"" + f.fileName() + "\"");
+        process.startDetached(f.fileName(), args);
+        process.waitForFinished(-1);
+        emit processFinished("startGame", {});
+    } else {
+        emit caughtError("startGame", {"Ошибка запуска игры!", QString("Не удалось найти файл LotroLauncher в папке: ") + app_settings("Local", "folder")});
+        emit processFinished("startGame", {"Error"});
+    }
+    busy = false;
 }
 
-bool Lotro::initialised() {
 
+void Lotro::getLocaleFileInfo(long long file_id, int locale) {
+    if (!tryToBlockFile())
+        return;
+
+    emit processStarted("getLocaleFileInfo", {file_id, locale});
+
+    auto getfile_op = file.GetLocaleManager().GetLocaleFile(file_id, locale);
+    if (!getfile_op.result) {
+        emit caughtError("getLocaleFileInfo", {"Файл не найден!", QString("Не удаётся найти в ресурсах файл с id ") + QString::number(file_id)});
+        emit processFinished("getLocaleFileInfo", {"Error"});
+        busy = false;
+        return;
+    }
+
+    LOTRO_DAT::SubFile subfile = getfile_op.value;
+
+    QString result = "Locale file info:\n "
+                     "dictionary_offset: " + QString::number(subfile.dictionary_offset()) + "\n"
+                     "unknown1: " + QString::number(subfile.unknown1()) + "\n"
+                     "file_id: " + QString::number(subfile.file_id()) + "\n"
+                     "file_offset: " + QString::number(subfile.file_offset()) + "\n"
+                     "file_size: " + QString::number(subfile.file_size()) + "\n"
+                     "timestamp: " + QString::number(subfile.timestamp()) + "\n"
+                     "version: " + QString::number(subfile.version()) + "\n"
+                     "block_size: " + QString::number(subfile.block_size()) + "\n"
+                     "unknown2: " + QString::number(subfile.file_id()) + "\n";
+
+    busy = false;
+    emit localeFileInfoReceived(result);
+    emit processFinished("getLocaleFileInfo", {"Success"});
 }
 
-int Lotro::currentLocale() {
+void Lotro::getFileInfo(long long file_id) {
+    if (!tryToBlockFile())
+        return;
+
+    emit processStarted("getFileInfo", {file_id, locale});
 
+    auto getfile_op = file.GetFileSystem().GetFile(file_id);
+    if (!getfile_op.result) {
+        emit caughtError("getFileInfo", {"Файл не найден!", QString("Не удаётся найти файл с id ") + QString::number(file_id)});
+        emit processFinished("getFileInfo", {"Error"});
+        busy = false;
+        return;
+    }
+
+    LOTRO_DAT::SubFile subfile = *getfile_op.value;
+
+    QString result = "Locale file info:\n "
+                     "dictionary_offset: " + QString::number(subfile.dictionary_offset()) + "\n"
+                     "unknown1: " + QString::number(subfile.unknown1()) + "\n"
+                     "file_id: " + QString::number(subfile.file_id()) + "\n"
+                     "file_offset: " + QString::number(subfile.file_offset()) + "\n"
+                     "file_size: " + QString::number(subfile.file_size()) + "\n"
+                     "timestamp: " + QString::number(subfile.timestamp()) + "\n"
+                     "version: " + QString::number(subfile.version()) + "\n"
+                     "block_size: " + QString::number(subfile.block_size()) + "\n"
+                     "unknown2: " + QString::number(subfile.file_id()) + "\n";
+
+    busy = false;
+    emit localeFileInfoReceived(result);
+    emit processFinished("getFileInfo", {"Success"});
+}
+
+
+bool Lotro::initialised() {
+    return file.Initialized();
 }
 
-bool Lotro::patched() {
+int Lotro::currentLocale() {
+    return file.GetLocaleManager().GetCurrentLocale();
+}
 
+bool Lotro::notPatched() {
+    return file.GetStatusModule().CheckIfNotPatched();
 }
 
+
 bool Lotro::tryToBlockFile()
 {
     if (busy) {

+ 4 - 2
src/Legacy-advanced/models/lotro.h

@@ -18,7 +18,7 @@ public:
 
     int currentLocale();
 
-    bool patched();
+    bool notPatched();
 
 public slots:
     void initialiseDatFile(QString file_name);
@@ -49,7 +49,9 @@ public slots:
 
     void startGame();
 
-    void showFileInfo();
+    void getLocaleFileInfo(long long file_id, int locale);
+
+    void getFileInfo(long long file_id);
 
 private:
     bool tryToBlockFile();