Example #1
0
        public static async Task <int> Cache(CacheOptions options)
        {
            if (options.dump || options.extract)
            {
                // initial checks
                var inputFileInfo = new FileInfo(options.path);
                if (!inputFileInfo.Exists)
                {
                    return(0);
                }
                var outDir = inputFileInfo.Directory;
                if (outDir == null)
                {
                    return(0);
                }
                if (!outDir.Exists)
                {
                    Directory.CreateDirectory(outDir.FullName);
                }
                if (inputFileInfo.Extension != ".cache")
                {
                    return(0);
                }
                if (inputFileInfo.Name != "texture.cache")
                {
                    System.Console.WriteLine($@"Only texture.caches are currently suported. {options.path}.");
                    return(0);
                }

                // load texture cache
                // switch chache types
                var txc = new TextureCache(inputFileInfo.FullName);

                if (options.dump)
                {
                    txc.DumpInfo();
                    System.Console.WriteLine($@"Finished dumping {options.path}.");
                }

                if (options.extract)
                {
                    foreach (var x in txc.Files)
                    {
                        string fullpath = Path.Combine(outDir.FullName, x.Name);
                        x.Extract(new BundleFileExtractArgs(fullpath, EUncookExtension.dds));
                        System.Console.WriteLine($@"Finished extracting {x.Name}");
                    }
                    System.Console.WriteLine($@"Finished extracting {options.path}.");
                }
            }

            if (options.create)
            {
                if (!Directory.Exists(options.path))
                {
                    return(0);
                }
                var txc = new TextureCache();
                txc.LoadFiles(options.path);
                txc.Write(Path.Combine(options.path, "texture.cache"));

                System.Console.WriteLine($@"Finished creating {options.path}.");
            }


            return(1);
        }
Example #2
0
        private static async Task <int> RunCache(CacheOptions options)
        {
            bool WHITELIST    = true;
            var  whitelistExt = new[]
            {
                "w2cube",
            };
            bool EXTRACT = true;


            // Texture
            //using (var of = new OpenFileDialog() { Filter = "Texture caches | texture.cache" })
            {
                //if (of.ShowDialog() == DialogResult.OK)
                {
                    var    dt  = DateTime.Now;
                    string idx = RED.CRC32.Crc32Algorithm.Compute(Encoding.ASCII.GetBytes($"{dt.Year}{dt.Month}{dt.Day}{dt.Hour}{dt.Minute}{dt.Second}")).ToString();
                    //var txc = new TextureCache(of.FileName);
                    var txc    = new TextureCache(options.path);
                    var outDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TXTTest", $"ExtractedFiles_{idx}");
                    if (!Directory.Exists(outDir))
                    {
                        Directory.CreateDirectory(outDir);
                    }

                    // Dump
                    using (StreamWriter writer = File.CreateText(Path.Combine(outDir, $"__txtdump_{idx}.txt")))
                    {
                        string head = "Format\t" +
                                      "BPP\t" +
                                      "Width\t" +
                                      "Height\t" +
                                      "Size\t" +
                                      "Mips\t" +
                                      "Slices\t" +
                                      "Cube\t" +
                                      "Unk1\t" +
                                      //"Hash\t" +
                                      "Name";
                        writer.WriteLine(head);

                        foreach (var x in txc.Files)
                        {
                            string ext = x.Name.Split('.').Last();
                            if (!whitelistExt.Contains(ext) && WHITELIST)
                            {
                                continue;
                            }

                            string info = $"{x.Type.ToString("X4")}\t" +
                                          $"{x.BaseAlignment}\t" +
                                          $"{x.BaseWidth}\t" +
                                          $"{x.BaseHeight}\t" +
                                          $"{x.Size}\t" +
                                          $"{x.Mipcount}\t" +
                                          $"{x.SliceCount}\t" +
                                          $"{x.IsCube.ToString("X2")}\t" +
                                          $"{x.Unk1.ToString()}/{x.Unk1.ToString("X2")}\t" +
                                          //$"{x.Hash}\t" +
                                          $"{x.Name}\t"
                            ;

                            info += "<";
                            foreach (var y in x.MipMapInfo)
                            {
                                info += $"<{y.Item1},{y.Item2}>";
                            }
                            info += ">";

                            //Console.WriteLine(info);
                            writer.WriteLine(info);

                            if (EXTRACT)
                            {
                                string fullpath = Path.Combine(outDir, x.Name);
                                string filename = Path.GetFileName(fullpath);
                                string newpath  = Path.Combine(outDir, filename);
                                x.Extract(newpath);
                                System.Console.WriteLine($"Finished extracting {x.Name}");
                            }
                        }
                        System.Console.WriteLine($"Finished dumping texture cache. {options.path}");
                    }
                    System.Console.WriteLine($"Finished extracting.");
                    System.Console.ReadLine();
                }
            }


            // Collision

            /*
             * using (var of = new OpenFileDialog(){Filter = "Collision caches | collision.cache"})
             * {
             *  if (of.ShowDialog() == DialogResult.OK)
             *  {
             *      var ccf = new CollisionCache(of.FileName);
             *      var fd = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"CCTest");
             *      ccf.Files.ForEach(x=> x.Extract(Path.Combine(fd,x.Name)));
             *      CollisionCache.Write(Directory.GetFiles(fd,"*",SearchOption.AllDirectories).ToList().OrderByDescending(x=> new FileInfo(x).CreationTime).ToList(),of.FileName + "_regenerated");
             *      //IntenseTest(of.FileNames.ToList());
             *      Console.ReadLine();
             *  }
             * }
             */

            return(1);
        }