소스 검색

Fixed locales saving

Ivan Arkhipov 5 년 전
부모
커밋
784c257cf3
3개의 변경된 파일22개의 추가작업 그리고 44개의 파일을 삭제
  1. 1 1
      include/DatSubsystems/DatFileSystem.h
  2. 1 1
      src/DatSubsystems/DatFileSystem.cpp
  3. 20 42
      src/DatSubsystems/DatLocaleManager.cpp

+ 1 - 1
include/DatSubsystems/DatFileSystem.h

@@ -84,7 +84,7 @@ namespace LOTRO_DAT {
         std::unordered_map<long long, SubFile> subfile_init_map_;
         std::set<SubFile, SubFile::SubFileOffsetComparator> subfile_init_queue_;
     public:
-        long long patched_file_end;
+        unsigned patched_file_end;
     };
 }
 };

+ 1 - 1
src/DatSubsystems/DatFileSystem.cpp

@@ -257,7 +257,7 @@ namespace LOTRO_DAT {
         fprintf(file, "Files in dictionary number: %d\n", dictionary_.size());
         fprintf(file, "Files visited: %d\n", visited_subfiles_ids_.size());
         fprintf(file, "Folders visited: %d\n", visited_subdirectories_offsets_.size());
-        fprintf(file, "File patched size: %lld\n", patched_file_end);
+        fprintf(file, "File patched size: %u\n", patched_file_end);
 
         std::map<FILE_TYPE, size_t> filetypes_count{{TEXT, 0},
                                                     {JPG, 0},

+ 20 - 42
src/DatSubsystems/DatLocaleManager.cpp

@@ -69,9 +69,9 @@ namespace LOTRO_DAT {
         }
 
         dict_size_ = locale_info.ToNumber<4>(0);
-        long long dict_version = locale_info.ToNumber<4>(4);
-        long long patched_file_end = locale_info.ToNumber<4>(8);
-        long long dat_file_header_hash = locale_info.ToNumber<4>(12);
+        unsigned dict_version = locale_info.ToNumber<4>(4);
+        unsigned patched_file_end = locale_info.ToNumber<4>(8);
+        unsigned dat_file_header_hash = locale_info.ToNumber<4>(12);
 
         if (dict_version != DAT_LOCALE_DICT_VERSION) {
             ClearData();
@@ -531,51 +531,29 @@ namespace LOTRO_DAT {
             current_size += 4;
         }
 
+        // Updating dict offset, if current does not match prerequisites
         if (binary_data.size() > dict_size_ || dict_offset_ == 0) {
-            long long new_dict_offset = dat->GetFileSystem().patched_file_end + 16;
-
-            // Updating first 16 bytes
-            binary_data.Append(BinaryData::FromNumber<4>(std::max(binary_data.size() + 4, 20u * 1024u * 1024u)), 0);
-            binary_data.Append(BinaryData::FromNumber<4>(DAT_LOCALE_DICT_VERSION), 4);
-            binary_data.Append(
-                    BinaryData::FromNumber<4>(dat->GetFileSystem().patched_file_end + binary_data.size() + 20 * 1024 * 1024), 8);
-            binary_data.Append(BinaryData::FromNumber<4>(dat->GetIO().GetHeaderHash()), 12);
-            auto operation = dat->GetIO().WriteData(binary_data, binary_data.size(), new_dict_offset);
-            if (operation.result != SUCCESS) {
-                return DatOperationResult<>(ERROR, "LOCALEDEINIT: Cannot write locales");
-            }
-
-            dat->GetIO().WriteData(BinaryData::FromNumber<4>(new_dict_offset), 4, 300);
-
-            if (current_locale_ == ORIGINAL) {
-                dat->GetIO().WriteData(BinaryData::FromNumber<4>(1), 4, 296);
-            } else {
-                dat->GetIO().WriteData(BinaryData::FromNumber<4>(2), 4, 296);
-            }
-            dat->GetFileSystem().patched_file_end += binary_data.size();
-
-            LOG(INFO) << "Writing 20 mbytes to " << dat->GetFileSystem().patched_file_end;
+            dict_offset_ = dat->GetFileSystem().patched_file_end;
+            dict_size_ = std::max(binary_data.size() + 4, 20u * 1024u * 1024u);
 
-            BinaryData nulls(unsigned(20 * 1024 * 1024));
+            BinaryData nulls(dict_size_);
             dat->GetIO().WriteData(nulls, nulls.size(), dat->GetFileSystem().patched_file_end);
             dat->GetFileSystem().patched_file_end += nulls.size();
-        } else {
-            binary_data.Append(BinaryData::FromNumber<4>(std::max(binary_data.size() + 4, 20u * 1024u * 1024u)), 0);
-            binary_data.Append(BinaryData::FromNumber<4>(DAT_LOCALE_DICT_VERSION), 4);
-            binary_data.Append(BinaryData::FromNumber<4>(dat->GetFileSystem().patched_file_end), 8);
-            binary_data.Append(BinaryData::FromNumber<4>(dat->GetIO().GetHeaderHash()), 12);
-
-            if (current_locale_ == ORIGINAL) {
-                dat->GetIO().WriteData(BinaryData::FromNumber<4>(1), 4, 296);
-            } else {
-                dat->GetIO().WriteData(BinaryData::FromNumber<4>(2), 4, 296);
-            }
+            
+            dat->GetIO().WriteData(BinaryData::FromNumber<4>(dict_offset_), 4, 0x12C);
+        }
 
-            auto operation = dat->GetIO().WriteData(binary_data, binary_data.size(), dict_offset_);
+        // Updating first 16 bytes
+        binary_data.Append(BinaryData::FromNumber<4>(dict_size_), 0);
+        binary_data.Append(BinaryData::FromNumber<4>(DAT_LOCALE_DICT_VERSION), 4);
+        binary_data.Append(BinaryData::FromNumber<4>(dat->GetFileSystem().patched_file_end), 8);
+        binary_data.Append(BinaryData::FromNumber<4>(dat->GetIO().GetHeaderHash()), 12);
+        auto operation = dat->GetIO().WriteData(binary_data, binary_data.size(), dict_offset_);
 
-            if (operation.result != SUCCESS) {
-                return DatOperationResult<>(ERROR, "LOCALEDEINIT: Cannot write locales. ERRMSG: " + operation.msg);
-            }
+        if (current_locale_ == ORIGINAL) {
+            dat->GetIO().WriteData(BinaryData::FromNumber<4>(1), 4, 296);
+        } else {
+            dat->GetIO().WriteData(BinaryData::FromNumber<4>(2), 4, 296);
         }
 
         dat->GetStatusModule().SetDefaultStatus();