Ver Fonte

Implemented patching .ogg and .dds (uncompressed)

Ivan Arkhipov há 7 anos atrás
pai
commit
80e18dfde1

+ 6 - 3
Source/Subfiles/DdsSubfile.cpp

@@ -148,11 +148,14 @@ namespace LOTRO_DAT {
             !data.options["fid"] || data.options["fid"].as<long long>() != file_id()) {
             throw DatException("Bad DdsSubfile::MakeForImport() - invalid options data!", IMPORT_EXCEPTION);
         }
-
+        // TODO: COMPRESSED TEXTURES
         if (old_data.CheckCompression())
             return old_data.CutData(0, 4) +
                    (old_data.DecompressData(12).CutData(12, 16) + data.binary_data.CutData(128)).CompressData();
-        else
-            return old_data.CutData(0, 8) + data.binary_data.CutData(128);
+        else {
+            BinaryData file_size;
+            file_size.FromNumber<4>(data.binary_data.size() - 128);
+            return old_data.CutData(0, 28) + file_size + data.binary_data.CutData(128);
+        }
     }
 };

+ 5 - 1
Source/Subfiles/OggSubfile.cpp

@@ -39,6 +39,10 @@ namespace LOTRO_DAT {
             !data.options["fid"] || data.options["fid"].as<long long>() != file_id()) {
             throw DatException("Bad DdsSubfile::MakeForImport() - invalid options data!", IMPORT_EXCEPTION);
         }
-        return old_data.CutData(0, 24) + data.binary_data;
+        BinaryData file_size;
+        file_size.FromNumber<4>(data.binary_data.size() - 8);
+        BinaryData file_id;
+        file_id.FromNumber<4>(this->file_id());
+        return old_data.CutData(0, 8) + file_id + file_size + data.binary_data;
     }
 };

+ 7 - 7
Source/Tests/extract_test.cpp

@@ -20,18 +20,18 @@ const std::string path = "";//"E:\\SteamLibrary\\steamapps\\common\\";//Lord Of
 const std::string filename = "client_local_English.dat";
 
 // Change these variables to true if you want export catecory to files.
-const bool exportImagesToFiles = true;
+const bool exportImagesToFiles = false;
 const bool exportFontsToFiles = false;
-const bool exportSoundsToFiles = false;
-const bool exportTexturesToFiles = true;
+const bool exportSoundsToFiles = true;
+const bool exportTexturesToFiles = false;
 const bool exportUnknownToFiles = false;
 
 // Change these variables to true if you want export catecory to databases.
-const bool exportTextsToDb = true;
-const bool exportImagesToDb = true;
+const bool exportTextsToDb = false;
+const bool exportImagesToDb = false;
 const bool exportFontsToDb = false;
-const bool exportSoundsToDb = false;
-const bool exportTexturesToDb = true;
+const bool exportSoundsToDb = true;
+const bool exportTexturesToDb = false;
 const bool exportUnknownToDb = false;
 // There is no need to change anything else
 

+ 16 - 11
Source/Tests/patch_test.cpp

@@ -12,23 +12,20 @@
 #endif
 
 #include "../LotroDatPatcher.h"
-
+#include "../Subfile.h"
 using namespace LOTRO_DAT;
 
 // Change these 2 variables to your path and name of .dat file
 const std::string path = "";//"E:\\SteamLibrary\\steamapps\\common\\";//Lord Of The Rings Online\\";
 const std::string filename = "client_local_English.dat";
 
-const std::string patch_filename = "image.jpg";
-const int file_id = 0;
-
 int main() {
     const clock_t begin_time = clock();
 
     freopen("errors.log", "w", stderr);
 
     Database db;
-    db.InitDatabase("images.db");
+    db.InitDatabase("sounds.db");
 
     DatFile *a;
 
@@ -38,15 +35,22 @@ int main() {
         std::cout << "Files number: " << a->files_number() << std::endl;
         a->WriteUnorderedDictionary("");
 
-        SubfileData data = db.GetNextFile();
-        while (data != SubfileData()) {
+        SubfileData data;
+//        data.binary_data.ReadFromFile("167855806.ogg");
+//        data.options["fid"] = "167855806";
+//        data.options["ext"] = ".ogg";
+//
+//        auto i = a->dictionary_[167855806];
+//        BinaryData new_data = i->MakeForImport(a->GetFileData(i), data);
+//        new_data.WriteToFile("test_new_file");
+//
+//        BinaryData old_data = a->GetFileData(i);
+//        old_data.WriteToFile("test_old_file");
 
-            //binary_data.ReadFromFile("1090552107.jpg");
-            //options["fid"] = "1090552107";
-            //options["ext"] = ".jpg";
+        data = db.GetNextFile();
+        while (data != SubfileData()) {
             a->PatchFile(data);
             data = db.GetNextFile();
-            //delete a;
         }
     } catch (std::exception &e) {
         fprintf(stderr, "Caught %s exception.", e.what());
@@ -56,6 +60,7 @@ int main() {
         printf("Some critical errors occured. Need to stop execution. See information in errors.log file");
         fprintf(stderr, "Some critical errors occured. Need to stop execution now...");
     }
+
     delete a;
     fprintf(stdout, "Spent %f seconds on performing magic! Thank you for your patience!\n",
             float(clock() - begin_time) / CLOCKS_PER_SEC);