コード例 #1
0
ファイル: NativeTests.cs プロジェクト: woydmw/repkg
        public unsafe void TestWriteAndRead(string name)
        {
            var headerReader       = new TexHeaderReader();
            var mipmapDecompressor = new TexMipmapDecompressor();
            var mipmapReader       = new TexImageReader(mipmapDecompressor);
            var containerReader    = new TexImageContainerReader(mipmapReader);
            var frameInfoReader    = new TexFrameInfoContainerReader();

            mipmapReader.DecompressMipmapBytes = false;

            Native.RePKG.SetTexReader(new TexReader(headerReader, containerReader, frameInfoReader));

            // Load file
            var path         = $"{TestHelper.BasePath}\\{TexDecompressingTests.InputDirectoryName}\\{name}.tex";
            var inputBytes   = File.ReadAllBytes(path);
            var pin          = GCHandle.Alloc(inputBytes, GCHandleType.Pinned);
            var bytesPointer = (byte *)pin.AddrOfPinnedObject().ToPointer();

            // Read tex
            var ctex = Native.RePKG.tex_load(bytesPointer, inputBytes.Length);

            if (ctex == null)
            {
                throw new Exception(Marshal.PtrToStringAnsi(new IntPtr(Native.RePKG.get_last_error())));
            }

            using (var environment = Native.RePKG.GetEnvironmentFor(ctex))
            {
                var wrappedCTex = new WCTex(ctex, environment);

                // Write tex
                var memoryStream = new MemoryStream(inputBytes.Length);
                var writer       = new BinaryWriter(memoryStream, Encoding.UTF8);
                TexWriter.Default.WriteTo(writer, wrappedCTex);
                var outputBytes = memoryStream.ToArray();

                // Verify
                Assert.AreEqual(inputBytes.Length, outputBytes.Length, "Written tex size doesn't match input size");

                for (var i = 0; i < inputBytes.Length; i++)
                {
                    if (inputBytes[i] == outputBytes[i])
                    {
                        continue;
                    }

                    throw new Exception(
                              $"Rewritten tex bytes are not the same at index: {i}\r\n" +
                              $"Expected: {inputBytes[i]}\r\n" +
                              $"Actual: {outputBytes[i]}");
                }
            }
        }
コード例 #2
0
        static Extract()
        {
            var texHeaderReader          = new TexHeaderReader();
            var texMipmapDecompressor    = new TexMipmapDecompressor();
            var texMipmapReader          = new TexMipmapReader(texMipmapDecompressor);
            var texMipmapContainerReader = new TexMipmapContainerReader(texMipmapReader);

            _texReader            = new TexReader(texHeaderReader, texMipmapContainerReader);
            _texJsonInfoGenerator = new TexJsonInfoGenerator();

            _packageReader = new PackageReader();
        }
コード例 #3
0
        protected void SetUp()
        {
            BasePath =
                AppContext.BaseDirectory.Split(new[] { "RePKG.Tests" }, StringSplitOptions.RemoveEmptyEntries)[0] +
                "RePKG.Tests";

            Directory.CreateDirectory($"{BasePath}\\{OutputDirectoryName}\\");
            Directory.CreateDirectory($"{BasePath}\\{ValidatedDirectoryName}\\");

            var headerReader       = new TexHeaderReader();
            var mipmapDecompressor = new TexMipmapDecompressor();
            var mipmapReader       = new TexMipmapReader(mipmapDecompressor);
            var containerReader    = new TexMipmapContainerReader(mipmapReader);

            _reader = new TexReader(headerReader, containerReader);
        }
コード例 #4
0
ファイル: TexWriterTests.cs プロジェクト: notscuffed/repkg
        public void Setup()
        {
            // Reader
            var headerReader       = new TexHeaderReader();
            var mipmapDecompressor = new TexMipmapDecompressor();
            var mipmapReader       = new TexImageReader(mipmapDecompressor);
            var containerReader    = new TexImageContainerReader(mipmapReader);
            var frameInfoReader    = new TexFrameInfoContainerReader();

            mipmapReader.DecompressMipmapBytes = false;
            mipmapReader.ReadMipmapBytes       = true;

            _reader = new TexReader(headerReader, containerReader, frameInfoReader);

            // Writer
            _writer = TexWriter.Default;
        }