浏览代码

Added functions - checkers if patched by legacy v1 and if updated by game

Ivan Arkhipov 3 年之前
父节点
当前提交
725e4f5927
共有 2 个文件被更改,包括 28 次插入1 次删除
  1. 5 1
      include/datfile.h
  2. 23 0
      src/datfile.cpp

+ 5 - 1
include/datfile.h

@@ -29,9 +29,13 @@ class DatFile {
   	bool Init(const std::string& filename);
 	void LoadAllFilesInfo();
   	void Deinit();
-
+	
+	static bool checkIfPatchedByLegacyV1(const std::string& filename);
+	
 	bool Initialized() const;
 	const std::string& GetFilename() const;
+	
+	int GetDatFileMaxIteration() const;
 	SubfileInfo getSubfileInfo(int file_id) const;
 
 	size_t GetFilesNumInDatFile();

+ 23 - 0
src/datfile.cpp

@@ -76,6 +76,29 @@ void DatFile::Deinit() {
     }
 }
 
+bool DatFile::checkIfPatchedByLegacyV1(const std::string& filename) {
+    FILE* file_handler = fopen(filename.c_str(), "r+b");
+    if (file_handler == nullptr) {
+        return false;
+    }
+    BinaryData data(1024);
+    fread(data.data(), 1024, 1, file_handler);
+    fclose(file_handler);
+    return (data.ToNumber<4>(0x128) != 0 || data.ToNumber<4>(0x12C) != 0);
+}
+
+int DatFile::GetDatFileMaxIteration() const {
+    int subfiles_num = api_.GetNumSubfiles(file_handle_);
+    int max_iteration = -1;
+    for (int i = 0; i < subfiles_num; ++i) {
+        SubfileInfo file_info;
+        api_.GetSubfileSizes(file_handle_, &file_info.file_id, &file_info.size, &file_info.iteration, i, 1);
+        max_iteration = std::max(max_iteration, file_info.iteration);
+    }
+
+    return max_iteration;
+}
+
 bool DatFile::Initialized() const{
     return initialized_;
 }