Beispiel #1
0
        private static int UncookSingleInner(this Archive.Archive ar, ulong hash, DirectoryInfo outDir, EUncookExtension uncookext = EUncookExtension.tga, bool flip = false)
        {
            // checks
            if (!ar.Files.ContainsKey(hash))
            {
                return(-1);
            }
            var name    = ar.Files[hash].FileName;
            var outfile = new FileInfo(Path.Combine(outDir.FullName,
                                                    $"{name}"));

            if (outfile.Directory == null)
            {
                return(-1);
            }

            var uncooksuccess = false;

            var(file, buffers) = ar.GetFileData(hash, true);

            var cr2w = new CR2WFile();

            using var ms = new MemoryStream(file);
            using var br = new BinaryReader(ms);
            cr2w.ReadImportsAndBuffers(br);

            var ext = Path.GetExtension(name)[1..];
Beispiel #2
0
        private static int ExtractSingleInner(this Archive.Archive ar, ulong hash, DirectoryInfo outDir)
        {
            var extractsuccess = false;

            var(file, buffers) = ar.GetFileData(hash, false);

            if (!ar.Files.ContainsKey(hash))
            {
                return(-1);
            }
            string name = ar.Files[hash].FileName;

            if (string.IsNullOrEmpty(Path.GetExtension(name)))
            {
                name += ".bin";
            }

            var outfile = new FileInfo(Path.Combine(outDir.FullName,
                                                    $"{name}"));

            if (outfile.Directory == null)
            {
                return(-1);
            }

            // write main file
            Directory.CreateDirectory(outfile.Directory.FullName);
            using var fs = new FileStream(outfile.FullName, FileMode.Create, FileAccess.Write);
            using var bw = new BinaryWriter(fs);
            bw.Write(file);
            extractsuccess = true;

            // write buffers
            // buffers are usually(?) appended to the main file
            // TODO: dump all buffered files and check this
            for (int j = 0; j < buffers.Count; j++)
            {
                var buffer = buffers[j];
                bw.Write(buffer);
                extractsuccess = true;
            }

            return(extractsuccess ? 1 : 0);
        }
Beispiel #3
0
 public (byte[], List <byte[]>) GetFileData()
 {
     return(_parentArchive.GetFileData(NameHash64, true));
 }