示例#1
0
        public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext)
        {
            var fileStream = await fileSystem.OpenFileAsync(filePath);

            // Decompress, if necessary
            using var br        = new BinaryReaderX(fileStream, true);
            fileStream.Position = 9;
            if (br.ReadString(4) == "nns_")
            {
                _wasCompressed = true;

                fileStream.Position = 0;

                var decompressedStream = new MemoryStream();
                NintendoCompressor.Decompress(fileStream, decompressedStream);

                fileStream.Close();
                fileStream = decompressedStream;
            }

            fileStream.Position = 0;
            Images = new List <IKanvasImage> {
                new KanvasImage(EncodingDefinition, _img.Load(fileStream))
            };
        }
示例#2
0
        private IList <ChnkSection> ReadSections(BinaryReaderX br)
        {
            // Read raw chunks
            var chunks = new List <ChnkSection>();

            while (br.BaseStream.Position < br.BaseStream.Length)
            {
                chunks.Add(br.ReadType <ChnkSection>());
            }

            // Decompress chunk data
            foreach (var chunk in chunks)
            {
                if (chunk.decompressedSize == 0)
                {
                    continue;
                }

                var ms = new MemoryStream();
                NintendoCompressor.Decompress(new MemoryStream(chunk.data), ms);

                ms.Position = 0;
                chunk.data  = ms.ToArray();
            }

            return(chunks);
        }
示例#3
0
        private Stream Decompress(Stream input)
        {
            using var br = new BinaryReaderX(input, true);

            input.Position = 5;
            var magic = br.ReadString(4);

            if (magic != "F3XT")
            {
                _wasCompressed = false;
                return(input);
            }

            _wasCompressed = true;

            var ms = new MemoryStream();

            input.Position = 0;

            _compMethod = NintendoCompressor.PeekCompressionMethod(input);
            NintendoCompressor.Decompress(input, ms);

            ms.Position = 0;
            return(ms);
        }
示例#4
0
        private Stream Decompress(Stream input)
        {
            var output = new MemoryStream();

            NintendoCompressor.Decompress(input, output);

            output.Position = 0;
            return(output);
        }