public void PatchCasFile(string file, Cat katFile, Entry engEnt)
        {
            uint addedByte = 342680, addSize = 0;
            bool passed    = false;
            Kat  engCat    = new Kat();
            uint newOffset = 31797010;

            foreach (var kat  in katFile.katList)
            {
                if (Tools.CompareByteArrays(kat.sha1, engEnt.subTypes["sha1"]))
                {
                    engCat = kat;
                    break;
                }
            }

            using (BinaryReader binred = new BinaryReader(File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                using (BinaryWriter binwr = new BinaryWriter(File.Open(file + ".PATCHED", FileMode.Create)))
                {
                    binwr.Write(binred.ReadBytes(580));
                    for (int i = 0; i < katFile.katList.Count; i++)
                    {
                        Kat    kat  = katFile.katList[i];
                        byte[] sha1 = binred.ReadBytes(20);
                        binwr.Write(sha1);

                        uint   offset = binred.ReadUInt32();
                        UInt64 size   = binred.ReadUInt64();
                        uint   casNo  = binred.ReadUInt32();

                        if (!passed && Tools.CompareByteArrays(sha1, engCat.sha1))
                        {
                            passed = true;
                            binwr.Write(newOffset);
                            binwr.Write(size);
                            binwr.Write(casNo);
                            continue;
                        }

                        if (casNo == engCat.casNo && offset > engCat.offset)
                        {
                            binwr.Write(offset - addedByte);
                        }
                        else
                        {
                            binwr.Write(offset);
                        }

                        binwr.Write(size);
                        binwr.Write(casNo);
                    }
                    long remaining = binred.BaseStream.Length - binred.BaseStream.Position;
                    binwr.Write(binred.ReadBytes((int)remaining));
                }
            }
        }
        public static byte[] GetDataFromKat(Kat katFile)
        {
            byte[] data    = new byte[katFile.size];
            string casPath = Path.Combine(Path.GetDirectoryName(katFile.motherCat.filePath), "cas_0" + katFile.casNo + ".cas");

            using (BinaryReader binred = new BinaryReader(File.Open(casPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                binred.BaseStream.Position = katFile.offset;
                binred.Read(data, 0, data.Length);
            }
            return(data);
        }
        static byte[] ExportChunk(string lang)
        {
            Toc langToc = tocFiles.Where(p => Path.GetFileNameWithoutExtension(p.filePath) == lang).First();

            Entry ent1 = langToc.mainEntry.subTypes["chunks"][0];
            Entry ent2 = langToc.mainEntry.subTypes["chunks"][1];

            Kat kat1   = Tools.GetCatSettings(catFiles, ent1.subTypes["sha1"]);
            Kat kat2   = Tools.GetCatSettings(catFiles, ent2.subTypes["sha1"]);
            Kat bigKat = kat1.size > kat2.size ? kat1 : kat2;

            byte[] datMan = Tools.GetDataFromKat(bigKat);//bigger chunk is subtitle file
            return(datMan);
        }
        public static Kat GetCatSettings(Cat[] catFiles, byte[] sha1)
        {
            Kat katFile = new Kat();

            foreach (Cat kat in catFiles)
            {
                foreach (Kat ka in kat.katList)
                {
                    if (CompareByteArrays(ka.sha1, sha1))
                    {
                        katFile = ka;
                        break;
                    }
                }
            }

            return(katFile);
        }
Esempio n. 5
0
 public void ReadFile(string path)
 {
     using (BinaryReader binred = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
     {
         binred.BaseStream.Position = 572;
         int catCount = binred.ReadInt32();
         int dafak    = binred.ReadInt32();
         for (int i = 0; i < catCount; i++)
         {
             Kat kat = new Kat();
             kat.sha1      = binred.ReadBytes(20);
             kat.offset    = binred.ReadUInt32();
             kat.size      = binred.ReadUInt64();
             kat.casNo     = binred.ReadUInt32();
             kat.motherCat = this;
             katList.Add(kat);
         }
     }
 }
        public static byte[] GetDataFromSha1(Cat[] catFiles, byte[] mySha1)
        {
            Kat    katFile = new Kat();
            string katPath = "";

            foreach (Cat kat in catFiles)
            {
                foreach (Kat ka in kat.katList)
                {
                    if (CompareByteArrays(ka.sha1, mySha1))
                    {
                        katPath = kat.filePath;
                        katFile = ka;
                        break;
                    }
                }
            }

            return(GetDataFromKat(katFile));
        }
        static void ImportLanguage(string lang, string excelPath)
        {
            CompressionThing compressor = new CompressionThing();

            Toc   langToc = tocFiles.Where(p => Path.GetFileNameWithoutExtension(p.filePath) == lang).First();
            Entry ent1    = langToc.mainEntry.subTypes["chunks"][0];
            Entry ent2    = langToc.mainEntry.subTypes["chunks"][1];

            Kat   kat1   = Tools.GetCatSettings(catFiles, ent1.subTypes["sha1"]);
            Kat   kat2   = Tools.GetCatSettings(catFiles, ent2.subTypes["sha1"]);
            Entry bigEnt = kat1.size > kat2.size ? ent1 : ent2;

            //bigger one is subtitle one
            byte[] sha1  = bigEnt.subTypes["sha1"];
            byte[] id    = bigEnt.subTypes["id"];
            string idStr = BitConverter.ToString(id).Replace("-", "");
            Kat    deKat = Tools.GetCatSettings(catFiles, sha1);

            Console.WriteLine("Compressing..");
            byte[] compressedNewBytes;
            if (lang == "de" || lang == "zh" || lang == "ja")
            {
                compressedNewBytes = compressor.compressGermanLZ4(excelPath);
            }
            else
            {
                compressedNewBytes = compressor.compressLZ4(excelPath);
            }

            Console.WriteLine("OK.");


            string cas1path = Path.Combine(GamePath, MainFolder, @"Win32\gameconfigurations\initialinstallpackage\cas_01.cas");

            byte[] cas1 = File.ReadAllBytes(cas1path);
            int    z    = 0;

            if (compressedNewBytes.Length > (uint)deKat.size)
            {
                Console.WriteLine("Yeni dosyanın boyutu (" + compressedNewBytes.Length + ") Orjinal boyuttan (" + deKat.size + ") daha büyük!\nİptal.. ");
                return;
            }

            for (uint i = deKat.offset; i < deKat.offset + deKat.size; i++)
            {
                if (z < compressedNewBytes.Length)
                {
                    cas1[i] = compressedNewBytes[z];
                    z++;
                }
                else
                {
                    cas1[i] = 0;
                }
            }
            Console.WriteLine("Writing to Cas1 File..");
            BackupAndWriteBytes(cas1path, cas1);
            Console.WriteLine("OK.");

            //for new decompressedSize, if not edited game refuses to open -except polish

            int    dataSizeOffset = -1;//454368;//420703;//420813;
            string cas2path       = Path.Combine(GamePath, MainFolder, @"Win32\gameconfigurations\initialinstallpackage\cas_02.cas");

            byte[] cas2 = File.ReadAllBytes(cas2path);
            dataSizeOffset = Tools.SearchIdInCasFile(cas2, id);

            if (dataSizeOffset == -1)
            {
                Console.WriteLine("Skip Cas2..");
                return;
            }

            dataSizeOffset += 16;//size offset comes after id start offset
            byte[] dataLen = BitConverter.GetBytes(compressor.DecompressedDataLength);
            for (int i = 0; i < 4; i++)
            {
                cas2[i + dataSizeOffset] = dataLen[i];
            }

            Console.WriteLine("Writing to Cas2 File..");
            BackupAndWriteBytes(cas2path, cas2);
            Console.WriteLine("OK.");
        }
        static void ImportThing(string aPath, string bPath, byte[] data)
        {
            string tocPath  = "";
            Entry  tocEntry = null;
            Toc    mainToc  = null;

            foreach (Toc ent in tocFiles)
            {
                foreach (Entry en in ent.mainEntry.subTypes["bundles"])
                {
                    if (en.subTypes["id"] == aPath)
                    {
                        mainToc  = ent;
                        tocPath  = ent.filePath;
                        tocPath  = tocPath.Substring(0, tocPath.LastIndexOf('.'));
                        tocEntry = en;
                        break;
                    }
                }
            }

            string sbPath  = Path.Combine(GamePath, MainFolder, tocPath + ".sb");
            Sb     sbFile  = new Sb(sbPath, (long)tocEntry.subTypes["offset"]);
            Entry  sbEntry = null;

            foreach (Entry eb in sbFile.mainEntry.subTypes["res"])
            {
                if (eb.subTypes["name"] == bPath)
                {
                    sbEntry = eb;
                    break;
                }
            }

            Kat    katSettings = Tools.GetCatSettings(catFiles, sbEntry.subTypes["sha1"]);
            string cas1path    = Path.Combine(GamePath, MainFolder, Path.GetDirectoryName(katSettings.motherCat.filePath) + "\\cas_0" + katSettings.casNo + ".cas");

            byte[] cas1 = File.ReadAllBytes(cas1path);
            int    z    = 0;

            /*if (data.Length > (uint)katSettings.size)
             * {
             *  Console.WriteLine("Yeni dosyanın boyutu (" + data.Length + ") Orjinal boyuttan (" + katSettings.size + ") daha büyük!\nİptal.. ");
             *  return;
             * }*/

            for (uint i = katSettings.offset; i < katSettings.offset + katSettings.size; i++)
            {
                if (z < data.Length)
                {
                    cas1[i] = data[z];
                    z++;
                }
                else
                {
                    cas1[i] = 0;
                }
            }
            Console.WriteLine("Writing to Cas1 File..");
            BackupAndWriteBytes(cas1path, cas1);
            Console.WriteLine("OK.");
        }