Ejemplo n.º 1
0
        public static IExtractedFile ExtractFromFSys(FSys fSys, int index)
        {
            var fileDetails   = fSys.GetDetailsForFile(index);
            var noExtFsysName = fSys.FileName.RemoveFileExtensions();
            var extractDir    = $"{fSys.Path}/{noExtFsysName}";

            var fileName = fileDetails.FileName.ToString();

            if (!fSys.UsesFileExtensions || fileName == fileName.RemoveFileExtensions())
            {
                fileName = $"{fileName.RemoveFileExtensions()}{fileDetails.Filetype.FileTypeName()}";
            }

            if (fSys.ExtractedEntries.ContainsKey(fileName))
            {
                return(fSys.ExtractedEntries[fileName]);
            }

            if (Configuration.Verbose)
            {
                Console.WriteLine($"Extracting {fileName}");
            }

            var extractedFile = $"{extractDir}/{fileName}".GetNewStream();

            fSys.ExtractedFile.CopySubStream(extractedFile, fileDetails.StartOffset, fileDetails.IsCompressed ? fileDetails.CompressedSize : fileDetails.UncompressedSize);
            extractedFile.Flush();

            if (fileDetails.IsCompressed)
            {
                if (Configuration.Verbose)
                {
                    Console.WriteLine($"Decoding {fileName}");
                }
                extractedFile.Seek(kSizeOfLZSSHeader, SeekOrigin.Begin);
                extractedFile = LZSSEncoder.Decode(extractedFile);
            }

            return(CreateExtractedFile(extractDir, fileName, fileDetails.Filetype, extractedFile));
        }
Ejemplo n.º 2
0
        public static void ExtractFSys(FSys sys, bool decode)
        {
            if (sys.NumberOfEntries <= 0)
            {
                return;
            }

            for (int i = 0; i < sys.NumberOfEntries; i++)
            {
                var entry = FSysFileEntry.ExtractFromFSys(sys, i);
                if (!sys.ExtractedEntries.TryAdd(entry.FileName, entry))
                {
                    continue;
                }

                switch (entry.FileType)
                {
                case FileTypes.GSW:
                {
                    var gswTex  = (GSWTexture)entry;
                    var texData = gswTex.ExtractTextureData();
                    foreach (var tex in texData)
                    {
                        sys.ExtractedEntries.Add(tex.FileName, tex);
                    }
                }
                break;
                }
            }

            if (decode)
            {
                var extraData = new List <IExtractedFile>();
                for (int i = 0; i < sys.ExtractedEntries.Count; i++)
                {
                    var entry = sys.ExtractedEntries.Values.ElementAt(i);
                    if (entry is Texture tex)
                    {
                        tex.WritePNGData();
                    }
                    else if (entry is PKX pk)
                    {
                        sys.ExtractedEntries.Add($"{pk.FileName.RemoveFileExtensions()}.dat", pk.ExtractDat());
                    }
                    else if (entry is StringTable tbl)
                    {
                    }
                    else if (entry is SCD scr)
                    {
                        scr.WriteScriptData(sys);
                    }
                    else if (entry.FileType == FileTypes.THH)
                    {
                        var thdData = sys.ExtractedEntries.Values.First(f =>
                        {
                            var entryFileName = f.FileName.Split(".")[0];
                            return(f.FileType == FileTypes.THD && f.FileName.Contains(entryFileName));
                        });
                        var thp = new THP();
                        sys.ExtractedEntries.Add($"{entry.FileName}.thp", thp);
                    }
                }
            }
        }