Ejemplo n.º 1
0
        public static void Load(string path, bool dump = false)
        {
            byte[] buff = new byte[134217728];
            int    size = 0;

            using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(path)))
                using (BinaryReader br = new BinaryReader(ms))
                {
                    if (!IsValid(br, Path.GetExtension(path).Substring(1).ToLower()))
                    {
                        return;
                    }

                    while (br.BaseStream.Position < br.BaseStream.Length)
                    {
                        int length = (int)br.ReadUInt32();

                        using (MemoryStream lzs = new MemoryStream(br.ReadBytes(length)))
                            using (LZ4Decompress lz4 = new LZ4Decompress(lzs))
                            {
                                size += lz4.Read(buff, size, buff.Length);
                            }
                    }
                }

            if (dump)
            {
                using (BinaryWriter bw = new BinaryWriter(new FileStream($"{path}.raw", FileMode.Create)))
                {
                    bw.Write(buff, 0, size);
                }
            }
        }
Ejemplo n.º 2
0
        public static void Load(string path, bool bDump = false)
        {
            byte[] buff = new byte[134217728];
            int size = 0;

            using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(path)))
            using (BinaryReader br = new BinaryReader(ms))
            {
                if (!IsValid(br, Path.GetExtension(path).Substring(1).ToLower())) { return; }

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    int length = (int)br.ReadUInt32();

                    using (var lzs = new MemoryStream(br.ReadBytes(length)))
                    using (var lz4 = new LZ4Decompress(lzs))
                    {
                        size += lz4.Read(buff, size, buff.Length);
                    }
                }
            }

            if (bDump)
            {
                using (BinaryWriter bw = new BinaryWriter(new FileStream(path + ".raw", FileMode.Create)))
                {
                    bw.Write(buff, 0, size);
                }
            }
        }
Ejemplo n.º 3
0
        public static BMAP Load(string path, bool bDump = false)
        {
            FileInfo fi = new FileInfo(path);
            BMAP bmap = new BMAP();

            byte[] buff = new byte[134217728];
            int size = 0;

            using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(path)))
            using (BinaryReader br = new BinaryReader(ms))
            {
                if (!IsBMAP(br)) { return null; }

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    int length = (int)br.ReadUInt32();

                    using (var lzs = new MemoryStream(br.ReadBytes(length)))
                    using (var lz4 = new LZ4Decompress(lzs))
                    {
                        size += lz4.Read(buff, size, buff.Length);
                    }
                }
            }

            if (bDump)
            {
                using (BinaryWriter bw = new BinaryWriter(new FileStream(path.Replace(".bmap", ".raw"), FileMode.Create)))
                {
                    bw.Write(buff, 0, size);
                }
            }

            using (MemoryStream ms = new MemoryStream(buff, 0, size))
            using (BinaryReader br = new BinaryReader(ms))
            {
                bmap.mode = (int)br.ReadUInt32();
                bmap.path = br.ReadString((int)br.ReadUInt32());
                int dataSize = (int)br.ReadUInt32();

                switch (bmap.mode)
                {
                    case 0:
                        bmap.dds = DDS.Load(br.ReadBytes(dataSize));
                        break;

                    case 1:
                        br.ReadUInt16();
                        br.ReadUInt16();
                        br.ReadUInt32();
                        br.ReadUInt32();
                        bmap.raw = new Bitmap(br.ReadUInt16(), br.ReadUInt16(), PixelFormat.Format32bppArgb);
                        br.ReadNullTerminatedString();

                        BitmapData bmpdata = bmap.raw.LockBits(new Rectangle(0, 0, bmap.raw.Width, bmap.raw.Height), ImageLockMode.ReadWrite, bmap.raw.PixelFormat);
                        dataSize = (int)(br.BaseStream.Length - br.BaseStream.Position);
                        Marshal.Copy(br.ReadBytes(dataSize), 0, bmpdata.Scan0, dataSize);
                        break;
                }
            }

            return bmap;
        }
Ejemplo n.º 4
0
        public static BMAP Load(string path, bool dump = false)
        {
            BMAP bmap = new BMAP();

            byte[] buff = new byte[536870912];
            int    size = 0;

            using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(path)))
                using (BinaryReader br = new BinaryReader(ms))
                {
                    if (!IsBMAP(br))
                    {
                        return(null);
                    }

                    while (br.BaseStream.Position < br.BaseStream.Length)
                    {
                        int length = (int)br.ReadUInt32();

                        using (MemoryStream lzs = new MemoryStream(br.ReadBytes(length)))
                            using (LZ4Decompress lz4 = new LZ4Decompress(lzs))
                            {
                                size += lz4.Read(buff, size, buff.Length);
                            }
                    }
                }

            if (dump)
            {
                using (BinaryWriter bw = new BinaryWriter(new FileStream(path.Replace(".bmap", ".raw"), FileMode.Create)))
                {
                    bw.Write(buff, 0, size);
                }
            }

            using (MemoryStream ms = new MemoryStream(buff, 0, size))
                using (BinaryReader br = new BinaryReader(ms))
                {
                    bmap.Mode = (int)br.ReadUInt32();
                    bmap.Path = br.ReadString((int)br.ReadUInt32());
                    int dataSize = (int)br.ReadUInt32();

                    switch (bmap.Mode)
                    {
                    case 0:
                        bmap.DDS = DDS.Load(br.ReadBytes(dataSize));
                        break;

                    case 1:
                        br.ReadUInt16();
                        br.ReadUInt16();
                        br.ReadUInt32();
                        br.ReadUInt32();
                        bmap.Raw = new Bitmap(br.ReadUInt16(), br.ReadUInt16(), PixelFormat.Format32bppArgb);
                        br.ReadNullTerminatedString();

                        BitmapData bmpdata = bmap.Raw.LockBits(new Rectangle(0, 0, bmap.Raw.Width, bmap.Raw.Height), ImageLockMode.ReadWrite, bmap.Raw.PixelFormat);
                        dataSize = (int)(br.BaseStream.Length - br.BaseStream.Position);
                        Marshal.Copy(br.ReadBytes(dataSize), 0, bmpdata.Scan0, dataSize);
                        break;
                    }
                }

            return(bmap);
        }