Procházet zdrojové kódy

Small fixes, fixed bug with rewriting incorrect data marks

Ivan Arkhipov před 5 roky
rodič
revize
fb92495f2a

+ 1 - 1
CMakeLists.txt

@@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD 14)
 set(PROJECT_BINARY_DIR bin)
 set(PROJECT_VERSION 7.1.0)
 
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} -O3 -Wall -Wextra")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} -Wall -Wextra")
 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
 
 if (MSVS)

+ 2 - 0
include/DatSubsystems/DatIO.h

@@ -53,6 +53,8 @@ namespace LOTRO_DAT {
         unsigned int getHeaderHash();
     private:
 
+        void ClearData();
+
         //------------------------------------------------//
         // PRIVATE INIT SECTION
         //------------------------------------------------//

+ 2 - 0
include/DatSubsystems/DatLocaleManager.h

@@ -72,6 +72,8 @@ namespace LOTRO_DAT {
     private:
         std::map<long long, SubFile> &GetLocaleDictReference(LOCALE locale);
 
+        void ClearData();
+
     private:
         DatFile *dat;
         std::map<long long, SubFile> orig_dict_;

+ 1 - 2
include/Subfiles/TextSubFile.h

@@ -29,8 +29,7 @@ namespace LOTRO_DAT {
         explicit TextSubFile(const TextSubFile &other) = delete;
         SubFile &operator =(const TextSubFile &other) = delete;
 
-
-        TextSubFile(SubFile preinit_file);
+        explicit TextSubFile(SubFile preinit_file);
 
         FILE_TYPE FileType() const override;
 

+ 3 - 4
src/DatFile.cpp

@@ -99,7 +99,7 @@ namespace LOTRO_DAT {
         if (initialized_ && io_->GetFilename().result == SUCCESS && io_->GetFilename().value == filename)
             return DatOperationResult<>();
 
-        initialized_ = true;
+        initialized_ = false;
 
         auto operation = io_->Init(filename);
         if (operation.result != SUCCESS) {
@@ -122,6 +122,8 @@ namespace LOTRO_DAT {
             return DatOperationResult<>(ERROR, "DATINIT: Error, cannot initialize dat due to locale manager initialisation error");
         }
 
+        initialized_ = true;
+
         status_->ClearAll();
         return DatOperationResult<>();
     }
@@ -151,9 +153,6 @@ namespace LOTRO_DAT {
     }
 
     DatOperationResult<> DatFile::Deinitialize() {
-        if (!initialized_)
-            return DatOperationResult<>();
-
         status_->SetStatus(DatStatus::E_COMMITING);
 
         auto operation = localeManager_->DeInit();

+ 19 - 0
src/DatSubsystems/DatIO.cpp

@@ -264,6 +264,11 @@ namespace LOTRO_DAT {
      */
 
     DatOperationResult<> DatIO::DeInit() {
+        if (!dat->Initialized()) {
+            ClearData();
+            return DatOperationResult<>(SUCCESS);
+        }
+
         if (file_handler_ != nullptr)
             fclose(file_handler_);
 
@@ -396,5 +401,19 @@ namespace LOTRO_DAT {
         return RSHash(values);
     }
 
+    void DatIO::ClearData() {
+        constant1 = -1;
+        constant2 = -1;
+        file_size = -1;
+        version1 = -1;
+        version2 = -1;
+        fragmentation_journal_size = -1;
+        fragmentation_journal_end = -1;
+        root_directory_offset = -1;
+        fragmentation_journal_offset = -1;
+        free_dat_size = -1;
+        actual_dat_size_ = -1;
+    }
+
 }
 }

+ 24 - 4
src/DatSubsystems/DatLocaleManager.cpp

@@ -339,7 +339,7 @@ namespace LOTRO_DAT {
             return false;
         }
 
-        if (locale_status != 0 &&  locale_status != dat->GetIO().getHeaderHash()){
+        if (locale_status != 0 && locale_status != dat->GetIO().getHeaderHash()){
             LOG(ERROR) << "CHCKLOCALECORRECT: Locale hash doesn't match!";
             return false;
         }
@@ -407,14 +407,21 @@ namespace LOTRO_DAT {
      * ========================================
      * Помимо этого:
      * 0x128-0x12C - 0, если выбрана локаль ORIGINAL и обновление клиентом игры не испортит .dat file
-     *               значение переменной-размера .dat файла (оффсет 0x148), в противном случае.
+     *               хэш хедера файла в противном случае.
      *               Отличие значения в 0x128 от 0 и значения в 0x148 => файл ресурсов мог быть повреждён
      *
      * 0x12C-0x130 - Офсет начала словаря локализации
      */
 
     DatOperationResult<> DatLocaleManager::CommitLocales() {
+        if (!dat->Initialized()) {
+            ClearData();
+            return DatOperationResult<>(SUCCESS);
+        }
+
         if (patch_dict_.empty()) {
+            ClearData();
+            dat->GetIO().WriteData(BinaryData::FromNumber<4>(0), 4, 296);
             dat->GetIO().WriteData(BinaryData::FromNumber<4>(0), 4, 300);
             return DatOperationResult<>(SUCCESS);
         }
@@ -477,8 +484,10 @@ namespace LOTRO_DAT {
                     BinaryData::FromNumber<4>(dat->GetFileSystem().patched_file_end + binary_data.size() + 20 * 1024 * 1024), 8);
 
             auto operation = dat->GetIO().WriteData(binary_data, binary_data.size(), new_dict_offset);
-            if (operation.result != SUCCESS)
+            if (operation.result != SUCCESS) {
+                ClearData();
                 return DatOperationResult<>(ERROR, "LOCALEDEINIT: Cannot write locales");
+            }
 
             dat->GetIO().WriteData(BinaryData::FromNumber<4>(new_dict_offset), 4, 300);
 
@@ -507,11 +516,22 @@ namespace LOTRO_DAT {
 
             auto operation = dat->GetIO().WriteData(binary_data, binary_data.size(), dict_offset);
 
-            if (operation.result != SUCCESS)
+            if (operation.result != SUCCESS) {
+                ClearData();
                 return DatOperationResult<>(ERROR, "LOCALEDEINIT: Cannot write locales. ERRMSG: " + operation.msg);
+            }
         }
 
+
         LOG(INFO) << "Locales committed successfully";
+        ClearData();
         return DatOperationResult<>(SUCCESS);
     }
+
+    void DatLocaleManager::ClearData() {
+        orig_dict_.clear();
+        patch_dict_.clear();
+        inactive_categories.clear();
+        current_locale_ = LOCALE(-1);
+    }
 }