瀏覽代碼

ver 3.1.0: Fixed issue with incorrect applying patch to files with inactive category

Ivan Arkhipov 6 年之前
父節點
當前提交
0e34be45b0
共有 5 個文件被更改,包括 28 次插入10 次删除
  1. 3 0
      CHANGELOG
  2. 二進制
      lib/libLotroDat.dll.a
  3. 二進制
      lib/libLotroDat_static.a
  4. 24 9
      src/DatFile.cpp
  5. 1 1
      src/Examples/patcher_example.cpp

+ 3 - 0
CHANGELOG

@@ -17,6 +17,9 @@ Version 2.1.0
 Version 3.0.0
     * Added support for dividing files into categories and activating/deactivating them in DatFile
 ----------------------------------------------------------------------
+Version 3.1.0
+    * Fixed issue with incorrect applying patch to files with inactive category
+----------------------------------------------------------------------
 
 
     

二進制
lib/libLotroDat.dll.a


二進制
lib/libLotroDat_static.a


+ 24 - 9
src/DatFile.cpp

@@ -247,10 +247,24 @@ namespace LOTRO_DAT {
             return false;
         }
 
-        if (data.options["cat"].IsDefined())
+        // If file has inactive category, then we should set it to patched state in order to commit patch and
+        // then in ApplyFilePatch(), if new category is still inactive, return dictionary to its original state;
+
+        if (inactive_categories.count(file->category) != 0 && patch_dict_.count(file_id) != 0) {
+            dictionary_[file_id]->file_offset_ = patch_dict_[file_id]->file_offset_;
+            dictionary_[file_id]->file_size_ = patch_dict_[file_id]->file_size_;
+            dictionary_[file_id]->block_size_ = patch_dict_[file_id]->block_size_;
+            dictionary_[file_id]->timestamp_ = patch_dict_[file_id]->timestamp_;
+            dictionary_[file_id]->version_ = patch_dict_[file_id]->version_;
+        }
+
+        if (data.options["cat"].IsDefined()) {
             file->category = data.options["cat"].as<long long>();
-        else
-            fprintf(stderr, "WARNING DatFile::PatchFile() - category option 'cat' was not set in patch subfile with id = %lld\n", file_id);
+        } else {
+            fprintf(stderr, "WARNING DatFile::PatchFile() - category option 'cat' was not "
+                            "set in patch subfile with id = %lld. Setting it to 1\n", file_id);
+            file->category = 1;
+        }
 
         BinaryData old_data = GetFileData(file);
         BinaryData patch_data = file->MakeForImport(old_data, data);
@@ -468,18 +482,20 @@ namespace LOTRO_DAT {
     /// Special functions used by patch process.
     /// Shouldn't be used by any external class.
     void DatFile::ApplyFilePatch(Subfile *file, const BinaryData &data, bool rewrite_original) {
-        if (patched_list.count(file->file_id()) != 0) {
+        auto file_id = file->file_id();
+        if (patched_list.count(file_id) != 0) {
             fprintf(stderr, "Warning: DatFile::ApplyFilePatch - found 2 files in patch with the same file_id = %lld. Passing last...\n", file->file_id());
             return;
         }
+
         if (current_locale() != PATCHED && !rewrite_original) {
             std::cout << "Changing locale to RU in order to patch file" << std::endl;
             SetLocale(PATCHED);
         }
         dat_state_ = UPDATED;
 
-        if (orig_dict_.count(file->file_id()) == 0 && !rewrite_original) {
-            orig_dict_[file->file_id()] = new Subfile(this, file->MakeHeaderData());
+        if (orig_dict_.count(file_id) == 0 && !rewrite_original) {
+            orig_dict_[file_id] = new Subfile(this, file->MakeHeaderData());
         }
 
         auto journal = GetFragmentationJournal();
@@ -489,7 +505,7 @@ namespace LOTRO_DAT {
 
         file->file_size_ = data.size() - 8;
 
-        if ((patch_dict_.count(file->file_id()) == 0 && !rewrite_original) || data.size() > file->block_size()) {
+        if ((patch_dict_.count(file_id) == 0 && !rewrite_original) || data.size() > file->block_size()) {
             file->file_offset_ = journal[0].second;
             file->block_size_ = std::max(data.size(), 256u);
 
@@ -506,13 +522,12 @@ namespace LOTRO_DAT {
 
         BinaryData file_data = fragments_count + data.CutData(4);
 
-        if (file->file_id() != file_data.ToNumber<4>(8))
+        if (file_id != file_data.ToNumber<4>(8))
             throw DatException("Bad DatFile::ApplyFilePatch() - Created data's file_id doesn't match to original! "
                                        "Patch wasn't written to .dat file");
 
         WriteData(file_data, file_data.size(), file->file_offset());
 
-        auto file_id = file->file_id();
         patched_list.insert(file_id);
 
         if (!rewrite_original) {

+ 1 - 1
src/Examples/patcher_example.cpp

@@ -16,7 +16,7 @@ using namespace LOTRO_DAT;
 using namespace std;
 
 int main() {
-    std::cout << "Gi1dor's LotRO .dat patcher ver. 3.0.0" << std::endl;
+    std::cout << "Gi1dor's LotRO .dat patcher ver. 3.1.0" << std::endl;
     freopen("errors.log", "w", stderr);
 
     setbuf(stdout, NULL);