Exemplo n.º 1
0
        public XPCK(Stream input)
        {
            _stream = input;
            using (var br = new BinaryReaderX(input, true))
            {
                //Header
                header = br.ReadStruct <Header>();

                //Entries
                br.BaseStream.Position = header.fileInfoOffset;
                entries.AddRange(br.ReadMultiple <FileInfoEntry>(header.fileCount));

                //Filenames
                br.BaseStream.Position = header.filenameTableOffset;
                compNameTable          = br.ReadBytes(header.filenameTableSize);
                var decNames = new MemoryStream(Level5.Decompress(new MemoryStream(compNameTable)));

                //Files
                using (var nameList = new BinaryReaderX(decNames))
                    for (int i = 0; i < entries.Count; i++)
                    {
                        nameList.BaseStream.Position = entries[i].nameOffset;
                        Files.Add(new XPCKFileInfo
                        {
                            State    = ArchiveFileState.Archived,
                            FileName = nameList.ReadCStringA(),
                            FileData = new SubStream(br.BaseStream, header.dataOffset + entries[i].fileOffset, entries[i].fileSize),
                            Entry    = entries[i]
                        });
                    }
            }
        }
Exemplo n.º 2
0
        public void extractXpck(BinaryReaderX br)
        {
            var header = br.ReadStruct <XpckHeader>();

            header.correctHeader();

            long bk = br.BaseStream.Position;

            br.BaseStream.Position = header.filenameTableOffset;
            byte[] filenameTable = Level5.Decompress(new MemoryStream(br.ReadBytes((int)br.BaseStream.Length)));
            br.BaseStream.Position = bk;
            int count = 0;

            using (BinaryReaderX br2 = new BinaryReaderX(new MemoryStream(filenameTable)))
            {
                List <XpckEntry> xpckEntries = new List <XpckEntry>();
                for (int i = 0; i < header.fileCount; i++)
                {
                    xpckEntries.Add(br.ReadStruct <XpckEntry>());
                    bk = br.BaseStream.Position;
                    string name = getFileName(br2);

                    if (name.Contains("cfg.bin"))
                    {
                        br.BaseStream.Position = xpckEntries[i].offset + header.dataOffset;
                        byte[] cont = br.ReadBytes(xpckEntries[i].fileSize);
                        //extractCfgBin(new BinaryReaderX(new MemoryStream(cont)), "XPCK" + count.ToString());
                        count += xpckEntries[i].fileSize;
                        br.BaseStream.Position = bk;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public XI(Stream input)
        {
            using (var br = new BinaryReaderX(input))
            {
                var header = br.ReadStruct <Header>();
                Settings = new ImageSettings {
                    Width = header.width, Height = header.height, Format = ImageSettings.ConvertFormat(header.imageFormat), Orientation = header.orientation, PadToPowerOf2 = false
                };
                CombineFormat = header.combineFormat;

                if (CombineFormat != 1)
                {
                    throw new Exception($"Unknown combine format {header.combineFormat}");
                }

                var buf1 = Level5.Decompress(input);
                while (input.Position % 4 != 0)
                {
                    input.ReadByte();
                }
                var buf2 = Level5.Decompress(input);

                var ms = new MemoryStream();
                for (int i = 0; i < buf1.Length / 2; i++)
                {
                    int index = BitConverter.ToInt16(buf1, 2 * i);
                    ms.Write(buf2, index * header.bytesPerTile, header.bytesPerTile);
                }
                Image = Common.Load(ms.ToArray(), Settings);
            }
        }
Exemplo n.º 4
0
        public static Bitmap Load(Stream input)
        {
            using (var br = new BinaryReaderX(input))
            {
                //Header
                header = br.ReadStruct <Header>();
                header.checkFormat();

                //get tile table
                br.BaseStream.Position = header.tableDataOffset;
                byte[] table = Level5.Decompress(new MemoryStream(br.ReadBytes(header.tableSize1)));

                //get image data
                br.BaseStream.Position = header.tableDataOffset + header.tableSize2;
                byte[] tex = Level5.Decompress(new MemoryStream(br.ReadBytes(header.imgDataSize)));

                //order pic blocks by table
                byte[] pic = Order(new MemoryStream(table), new MemoryStream(tex));

                //return finished image
                var settings = new ImageSettings
                {
                    Width         = header.width,
                    Height        = header.height,
                    Format        = ImageSettings.ConvertFormat(header.imageFormat),
                    PadToPowerOf2 = false,
                    ZOrder        = false
                };
                return(Common.Load(pic, settings));
            }
        }
Exemplo n.º 5
0
        static void Test(byte[] bytes, Method method)
        {
            var bytes2 = new byte[bytes.Length];

            switch (method)
            {
            case Method.Ninty:
                bytes2 = Nintendo.Decompress(new MemoryStream(Nintendo.Compress(new MemoryStream(bytes), Nintendo.Method.LZ10)));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                bytes2 = Nintendo.Decompress(new MemoryStream(Nintendo.Compress(new MemoryStream(bytes), Nintendo.Method.LZ11)));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                bytes2 = Nintendo.Decompress(new MemoryStream(Nintendo.Compress(new MemoryStream(bytes), Nintendo.Method.Huff4)));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                bytes2 = Nintendo.Decompress(new MemoryStream(Nintendo.Compress(new MemoryStream(bytes), Nintendo.Method.Huff8)));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                bytes2 = Nintendo.Decompress(new MemoryStream(Nintendo.Compress(new MemoryStream(bytes), Nintendo.Method.RLE)));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.L5:
                bytes2 = Level5.Decompress(new MemoryStream(Level5.Compress(new MemoryStream(bytes), Level5.Method.NoCompression)));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                bytes2 = Level5.Decompress(new MemoryStream(Level5.Compress(new MemoryStream(bytes), Level5.Method.LZ10)));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                bytes2 = Level5.Decompress(new MemoryStream(Level5.Compress(new MemoryStream(bytes), Level5.Method.Huffman4Bit)));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                bytes2 = Level5.Decompress(new MemoryStream(Level5.Compress(new MemoryStream(bytes), Level5.Method.Huffman8Bit)));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                bytes2 = Level5.Decompress(new MemoryStream(Level5.Compress(new MemoryStream(bytes), Level5.Method.RLE)));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;
            }
        }
Exemplo n.º 6
0
        // הוספת השינויים האותומטיים לכל אדם
        private void InsertCalculationForPerson5()
        {
            //var l = ListLevel5;
            //foreach (var item in ListLevel5)
            //{
            //    if (!(item.Chrom.Equals("GAL_5.5DEL_0190U-MUT") && item.Pos == 270) &&
            //        !(item.Pos == 92 &&item.Chrom.Equals("GAL_5.5DEL_0190U-WT_Merged_197798417") && item.Pos == 80) &&
            //        !(item.Pos == 92 &&item.Chrom.Equals("GEN_MALE_0177I_chrX_197798296") && item.Pos == 56) &&
            //        !(item.Pos == 92 &&item.Chrom.Equals("GEN_MALE_0177I_chrY_197798298") && item.Pos == 92) &&
            //        !(item.Pos == 92 &&item.Chrom.Equals("ML_EX1-7_0080U-MUT") && item.Pos == 83 )&&
            //        !(item.Pos == 92 &&item.Chrom.Equals("ML_EX1-7_0080U-WT_197798301") && item.Pos == 74) &&
            //        !(item.Pos == 92 &&item.Chrom.Equals("NM_R2478_0161U-MUT") && item.Pos == 433 )&&
            //        !(item.Pos == 92 &&item.Chrom.Equals("NM_R2478_0161U-WT_197798302")&& item.Pos == 131 )&&
            //        !(item.Pos == 92 &&item.Chrom.Equals("POL_EX2120_0247I-MUT") && item.Pos == 344 )&&
            //        !(item.Pos == 92 &&item.Chrom.Equals("POL_EX2120_0247I-WT_197798303") && item.Pos == 140) &&
            //        !(item.Pos == 92 &&item.Chrom.Equals("TRM_EXON2-7DEL_0240I-MUT") && item.Pos == 186) &&
            //        !(item.Chrom.Equals("TRM_EXON2-7DEL_0240I-WT_197798300") && item.Pos == 114))
            //        ListLevel5.Remove(item);
            //}
            //ListLevel5.Sort(s => { if (s.MutWt == "chrX") return 0;
            //else return x.PartName.CompareTo(y.PartName)
            //});


            foreach (var person in ListLevel5)
            {
                switch (person.DyDis)
                {
                case "GAL":
                    person.ColorDyName = "Green";
                    break;

                case "GEN":
                    person.ColorDyName = "Orange";
                    break;

                case "ML":
                    person.ColorDyName = "Yellow";
                    break;

                case "NM":
                    person.ColorDyName = "Bordeaux";
                    break;

                case "POL":
                    person.ColorDyName = "Blue";
                    break;

                case "TRM":
                    person.ColorDyName = "LigthGreen";
                    break;

                default:
                    break;
                }
                Level5 p       = person;
                Thread thread1 = new Thread(() => new CalculationLevel5(p));
                thread1.Start();
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            l1 = new Level1();
            l2 = new Level2();
            l3 = new Level3();
            l4 = new Level4();
            l5 = new Level5();
            l6 = new Level6();

            LEVELNUMBER = 6;
            switch(LEVELNUMBER)
            {
                case 1:
                    Console.WriteLine(l1.MainMethod(GetPuzzleInput()));
                    break;
                case 2:
                    Console.WriteLine(l2.MainMethod(GetPuzzleInput()));
                    break;
                case 3:
                    Console.WriteLine(l3.MainMethod(368078));
                    break;
                case 4:
                    Console.WriteLine(l4.MainMethod(GetPuzzleInput()));
                    break;
                case 5:
                    Console.WriteLine(l5.MainMethod(GetPuzzleInput()));
                    break;
                case 6:
                    Console.WriteLine(l6.MainMethod(GetPuzzleInput()));
                    break;
            }
            Console.ReadLine();
        }
Exemplo n.º 8
0
        public static Bitmap Load(Stream input)
        {
            using (var br = new BinaryReaderX(input))
            {
                //check header
                header = br.ReadStruct <Header>();
                header.checkConst();

                //decompress table
                br.BaseStream.Position = header.tableDataOffset;
                tableComp = (Compression)(br.ReadUInt32() % 8);
                br.BaseStream.Position = header.tableDataOffset;
                byte[] table = Level5.Decompress(new MemoryStream(br.ReadBytes(header.tableSize1)));

                //get decompressed picture data
                br.BaseStream.Position = header.tableDataOffset + header.tableSize2;
                picComp = (Compression)(br.ReadUInt32() % 8);
                br.BaseStream.Position = header.tableDataOffset + header.tableSize2;
                byte[] tex = Level5.Decompress(new MemoryStream(br.ReadBytes(header.imgDataSize)));

                //order pic blocks by table
                byte[] pic = Order(new BinaryReaderX(new MemoryStream(table)), table.Length, new BinaryReaderX(new MemoryStream(tex)), header.width, header.height, header.bitDepth);

                //return decompressed picture data
                var settings = new ImageSettings
                {
                    Width         = header.width,
                    Height        = header.height,
                    Orientation   = Orientation.TransposeTile,
                    Format        = ImageSettings.ConvertFormat(header.imageFormat),
                    PadToPowerOf2 = false
                };
                return(Common.Load(pic, settings));
            }
        }
Exemplo n.º 9
0
        private void ReadStream(Stream stream)
        {
            using (var reader = new ImprovedBinaryReader(stream))
            {
                // header
                header = reader.ReadStruct <Header>();

                // table 0
                reader.BaseStream.Position = header.T0 << 2;
                using (var table0 = new ImprovedBinaryReader(new MemoryStream(Level5.Decompress(reader.BaseStream))))
                {
                    while (table0.BaseStream.Position < table0.BaseStream.Length)
                    {
                        t0_list.Add(table0.ReadStruct <T0Entry>());
                    }
                }

                // table 1
                reader.BaseStream.Position = header.T1 << 2;
                using (var table1 = new ImprovedBinaryReader(new MemoryStream(Level5.Decompress(reader.BaseStream))))
                {
                    while (table1.BaseStream.Position < table1.BaseStream.Length)
                    {
                        t1_list.Add(table1.ReadStruct <T1Entry>());
                    }
                }

                // table 2
                reader.BaseStream.Position = header.T2 << 2;
                using (var table2 = new ImprovedBinaryReader(new MemoryStream(Level5.Decompress(reader.BaseStream))))
                {
                    while (table2.BaseStream.Position < table2.BaseStream.Length)
                    {
                        t2_list.Add(table2.ReadStruct <T2Entry>());
                    }
                }

                // table 3
                reader.BaseStream.Position = header.T3 << 2;
                using (var table3 = new ImprovedBinaryReader(new MemoryStream(Level5.Decompress(reader.BaseStream))))
                {
                    while (table3.BaseStream.Position < table3.BaseStream.Length)
                    {
                        t3_list.Add(table3.ReadStruct <T3Entry>());
                    }
                }

                // table 4
                reader.BaseStream.Position = header.T4 << 2;
                using (var table4 = new ImprovedBinaryReader(new MemoryStream(Level5.Decompress(reader.BaseStream))))
                {
                    while (table4.BaseStream.Position < table4.BaseStream.Length)
                    {
                        t4_data.Add(table4.ReadByte());
                    }
                }
            }
        }
Exemplo n.º 10
0
        private byte[] CompressTable <T>(List <T> table, Level5.Method method)
        {
            var ms = new MemoryStream();

            using (var bw = new BinaryWriterX(ms, true))
                bw.WriteMultiple(table);
            ms.Position = 0;
            return(Level5.Compress(ms, method));
        }
Exemplo n.º 11
0
        // Begin level 5
        public override void Next()
        {
            Hide();
            Level5 level5 = new Level5(GetScore(), GetLives(), SplashHold);

            level5.Closed += (s, args) => SplashHold.Close();
            level5.Show();
            Dispose();
        }
Exemplo n.º 12
0
        public void Save(string filename)
        {
            //Save available after finding out the comp table Size or if changes work without this comp table Size
            var sjis = Encoding.GetEncoding("SJIS");

            using (BinaryWriterX bw = new BinaryWriterX(File.OpenWrite(filename)))
            {
                //Header
                bw.WriteStruct(header);

                //Table 1
                bw.Write(table1);

                //Table2
                uint relOffset = 0;
                var  count     = 1;
                foreach (var label in Labels)
                {
                    if (count == offsets.Count)
                    {
                        var byteCount = (uint)sjis.GetByteCount(label.Text) + 1;

                        foreach (var entry in entries)
                        {
                            if (entry.ident == 0x18 && entry.textOffset == offsets[count])
                            {
                                entry.textOffset = relOffset + byteCount;
                            }
                        }

                        relOffset += byteCount;
                        count++;
                    }
                }

                var ms = new MemoryStream();
                using (var bw2 = new BinaryWriterX(ms, true))
                    foreach (var entry in entries)
                    {
                        bw2.WriteStruct(entry);
                    }
                bw.Write(Level5.Compress(ms, Level5.Method.NoCompression));
                bw.BaseStream.Position = (bw.BaseStream.Position + 0x3) & ~0x3;

                //Text
                ms = new MemoryStream();
                using (var bw2 = new BinaryWriterX(ms, true))
                    foreach (var label in Labels)
                    {
                        bw2.Write(sjis.GetBytes(label.Text));
                        bw2.Write((byte)0);
                    }
                bw.Write(Level5.Compress(ms, Level5.Method.NoCompression));
            }
        }
Exemplo n.º 13
0
        public static void WriteMultipleCompressed <T>(this BinaryWriterX bw, IEnumerable <T> list, Level5.Method comp)
        {
            var ms = new MemoryStream();

            using (var bwIntern = new BinaryWriterX(ms, true))
                foreach (var t in list)
                {
                    bwIntern.WriteStruct(t);
                }
            bw.Write(Level5.Compress(ms, comp));
        }
Exemplo n.º 14
0
        public XFSA(Stream input)
        {
            _stream = input;
            using (var br = new BinaryReaderX(input, true))
            {
                //Header
                header = br.ReadStruct <Header>();

                //Table 0
                br.BaseStream.Position = header.table0Offset;
                table0Comp             = GetCompressionMethod(br.BaseStream);
                table0 = new BinaryReaderX(new MemoryStream(Level5.Decompress(br.BaseStream))).ReadMultiple <Table0Entry>(header.table0EntryCount);

                //Table 1
                br.BaseStream.Position = header.table1Offset;
                table1Comp             = GetCompressionMethod(br.BaseStream);
                table1 = new BinaryReaderX(new MemoryStream(Level5.Decompress(br.BaseStream))).ReadMultiple <Table1Entry>(header.table1EntryCount);

                //File Entry Table
                br.BaseStream.Position = header.fileEntryTableOffset;
                entriesComp            = GetCompressionMethod(br.BaseStream);
                entries = new BinaryReaderX(new MemoryStream(Level5.Decompress(br.BaseStream))).ReadMultiple <FileEntry>(header.fileEntryCount);

                //String Table
                br.BaseStream.Position = header.nameTableOffset;
                stringComp             = GetCompressionMethod(br.BaseStream);
                stringTable            = Level5.Decompress(br.BaseStream);

                //Add Files
                using (var stringReader = new BinaryReaderX(new MemoryStream(stringTable)))
                {
                    foreach (var dir in table0)
                    {
                        stringReader.BaseStream.Position = dir.dirNameOffset;
                        var dirName        = stringReader.ReadCStringSJIS();
                        var fileCountInDir = 0;
                        foreach (var file in entries.Where((e, i) => i >= dir.fileEntryOffset && i < dir.fileEntryOffset + dir.fileCountInDir))
                        {
                            stringReader.BaseStream.Position = dir.firstFileNameInDir + file.nameOffset;
                            var fileName = stringReader.ReadCStringSJIS();
                            Files.Add(new XFSAFileInfo
                            {
                                State          = ArchiveFileState.Archived,
                                FileName       = Path.Combine(dirName, fileName),
                                FileData       = new SubStream(br.BaseStream, header.dataOffset + (file.offset << 4), file.size),
                                fileEntry      = file,
                                fileCountInDir = fileCountInDir++,
                                dirEntry       = dir
                            });
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
        public void Ce_Insert_LowLevel()
        {
            long ms = 0;

            using (new MetricTracker("Starting complex object", t => ms = t))
            {
                Level1 level1 = new Level1();
                level1.Value  = "test";
                level1.levels = new List <Level2>();

                for (int i = 0; i < 5; i++)
                {
                    Level2 curLevel2 = new Level2();
                    level1.levels.Add(curLevel2);
                    curLevel2.Value  = "test" + i.ToString();
                    curLevel2.levels = new List <Level3>();

                    for (int j = 0; j < 5; j++)
                    {
                        Level3 curLevel3 = new Level3();
                        curLevel2.levels.Add(curLevel3);
                        curLevel3.Value  = "test" + j.ToString();
                        curLevel3.levels = new List <Level4>();

                        for (int k = 0; k < 10; k++)
                        {
                            Level4 curLevel4 = new Level4();
                            curLevel3.levels.Add(curLevel4);
                            curLevel4.Value  = "test" + k.ToString();
                            curLevel4.levels = new List <Level5>();

                            for (int l = 0; l < 10; l++)
                            {
                                Level5 curLevel5 = new Level5();
                                curLevel4.levels.Add(curLevel5);
                                curLevel5.Value = "test" + l.ToString();
                            }
                        }
                    }
                }

                SqlCeConnectionFactory cf = new SqlCeConnectionFactory("System.Data.SqlServerCE.4.0");
                using (SqlCeConnection conn = (SqlCeConnection)cf.CreateConnection(@"c:\temp\myDataPoor.sdf"))
                {
                    conn.Open();

                    // Level1
                    int parentId = SqlCeInsertAdapterLevels.Write_Level1(level1, conn);
                }
            }

            ms.Should().BeLessThan(775);
        }
Exemplo n.º 16
0
 // Animation sprite; //animation
 public Game1()
 {
     graphics = new GraphicsDeviceManager(this);
     Content.RootDirectory              = "Content";
     graphics.PreferredBackBufferWidth  = 1280;
     graphics.PreferredBackBufferHeight = 720;
     lvl_1 = new Level1();
     lvl_2 = new Level2();
     lvl_3 = new Level3();
     lvl_4 = new Level4();
     lvl_5 = new Level5();
 }
Exemplo n.º 17
0
        public static void WriteStringsCompressed(this BinaryWriterX bw, IEnumerable <string> list, Level5.Method comp, Encoding enc)
        {
            var ms = new MemoryStream();

            using (var bwIntern = new BinaryWriterX(ms, true))
                foreach (var t in list)
                {
                    bwIntern.Write(enc.GetBytes(t));
                    bwIntern.Write((byte)0);
                }
            bw.Write(Level5.Compress(ms, comp));
        }
Exemplo n.º 18
0
        public XFSA(Stream input)
        {
            _stream = input;
            using (var br = new BinaryReaderX(input, true))
            {
                //Header
                header = br.ReadStruct <Header>();

                //1st table
                br.BaseStream.Position = header.offset1;
                table1Comp             = (byte)(br.ReadByte() & 7);
                br.BaseStream.Position--;
                var tmpT1 = br.ReadBytes((int)(header.offset2 - header.offset1));
                table1 = new BinaryReaderX(Support.DecompressToStream(tmpT1)).ReadMultiple <Table1Entry>(header.table1EntryCount);

                //2nd table
                br.BaseStream.Position = header.offset2;
                table2Comp             = (byte)(br.ReadByte() & 7);
                br.BaseStream.Position--;
                var tmpT2 = br.ReadBytes((int)(header.fileEntryTableOffset - header.offset2));
                table2 = new BinaryReaderX(Support.DecompressToStream(tmpT2)).ReadMultiple <Table2Entry>(header.table2EntryCount);

                //File Entry Table
                br.BaseStream.Position = header.fileEntryTableOffset;
                entriesComp            = (byte)(br.ReadByte() & 7);
                br.BaseStream.Position--;
                entries = new BinaryReaderX(Support.DecompressToStream(br.ReadBytes((int)(header.nameTableOffset - header.fileEntryTableOffset))))
                          .ReadMultipleEntriesInc((int)header.fileEntryCount).ToList();

                //Name Table
                br.BaseStream.Position = header.nameTableOffset;
                nameC     = br.ReadBytes((int)(header.dataOffset - header.nameTableOffset));
                fileNames = GetFileNames(Level5.Decompress(new MemoryStream(nameC)));

                //Add Files
                List <uint> combs = new List <uint>();
                foreach (var name in fileNames)
                {
                    var crc32 = Crc32.Create(name.Split('/').Last(), Encoding.GetEncoding("SJIS"));
                    var entry = entries.Find(c => c.entry.crc32 == crc32 && !combs.Contains(c.entry.comb1));
                    combs.Add(entry.entry.comb1);
                    Files.Add(new XFSAFileInfo
                    {
                        State    = ArchiveFileState.Archived,
                        FileName = name,
                        FileData = new SubStream(br.BaseStream, header.dataOffset + ((entry.entry.comb1 & 0x01ffffff) << 4), entry.entry.comb2 & 0x000fffff),
                        entry    = entry
                    });
                }
            }
        }
Exemplo n.º 19
0
        public bool Identify(string filename)
        {
            using (var br = new BinaryReaderX(File.OpenRead(filename)))
            {
                try
                {
                    //possible identifications: PCK, cfg.bin, XPCK-Archive
                    //if cfg.bin
                    br.BaseStream.Position = 0x18;
                    uint t1 = br.ReadUInt32();
                    br.BaseStream.Position = 0x24;
                    uint t2 = br.ReadUInt32();
                    if (t1 == 0x0 && t2 == 0x14)
                    {
                        return(true);
                    }
                    br.BaseStream.Position = 0;

                    //if PCK
                    int entryCount = br.ReadInt32();
                    br.BaseStream.Position = 0x8;
                    if (entryCount * 3 * 4 + 4 == br.ReadInt32())
                    {
                        return(true);
                    }
                    br.BaseStream.Position = 0;

                    //if XPCK
                    if (br.ReadString(4) == "XPCK")
                    {
                        return(true);
                    }
                    else
                    {
                        br.BaseStream.Position = 0;
                        byte[] result = Level5.Decompress(new MemoryStream(br.ReadBytes((int)br.BaseStream.Length)));
                        using (BinaryReaderX br2 = new BinaryReaderX(new MemoryStream(result)))
                        {
                            if (br2.ReadString(4) == "XPCK")
                            {
                                br2.BaseStream.Position = 0;
                                return(true);
                            }
                        }
                    }
                }
                catch (Exception) { }

                return(false);
            }
        }
Exemplo n.º 20
0
        public byte[] Identify(BinaryReaderX br)
        {
            //possible identifications: PCK, cfg.bin, XPCK-Archive
            //if cfg.bin
            br.BaseStream.Position = 0x18;
            uint t1 = br.ReadUInt32();

            br.BaseStream.Position = 0x24;
            uint t2 = br.ReadUInt32();

            br.BaseStream.Position = 0;
            if (t1 == 0x0 && t2 == 0x14)
            {
                type = 1;
                return(null);
            }

            //if PCK
            int entryCount = br.ReadInt32();

            br.BaseStream.Position = 0x8;
            if (entryCount * 3 * 4 + 4 == br.ReadInt32())
            {
                type = 2;
                return(null);
            }
            br.BaseStream.Position = 0;

            //if XPCK
            if (br.ReadString(4) == "XPCK")
            {
                type = 3;
                return(null);
            }
            else
            {
                br.BaseStream.Position = 0;
                byte[] result = Level5.Decompress(new MemoryStream(br.ReadBytes((int)br.BaseStream.Length)));
                using (BinaryReaderX br2 = new BinaryReaderX(new MemoryStream(result)))
                {
                    if (br2.ReadString(4) == "XPCK")
                    {
                        type = 3;
                        return(result);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 21
0
        public XPCK(string filename)
        {
            using (BinaryReaderX xpckBr = new BinaryReaderX(File.OpenRead(filename)))
            {
                if (xpckBr.ReadString(4) == "XPCK")
                {
                    xpckBr.BaseStream.Position = 0;
                    _stream = new MemoryStream(xpckBr.ReadBytes((int)xpckBr.BaseStream.Length));
                }
                else
                {
                    xpckBr.BaseStream.Position = 0;
                    byte[] decomp = Level5.Decompress(xpckBr.BaseStream);
                    _stream = new MemoryStream(decomp);
                }
            }

            using (BinaryReaderX xpckBr = new BinaryReaderX(_stream))
            {
                //Header
                var header    = xpckBr.ReadStruct <Header>();
                int fileCount = header.fileInfoSize / 0xc;

                //fileInfo
                var entries = new List <Entry>();
                entries.AddRange(xpckBr.ReadMultiple <Entry>(fileCount).OrderBy(e => e.fileOffset));

                //nameList
                var    nameList             = new List <string>();
                byte[] uncompressedNameList = Level5.Decompress(new MemoryStream(xpckBr.ReadBytes(header.filenameTableSize)));
                using (BinaryReaderX nlBr = new BinaryReaderX(new MemoryStream(uncompressedNameList)))
                    for (int i = 0; i < fileCount; i++)
                    {
                        nameList.Add(nlBr.ReadCStringA());
                    }

                for (int i = 0; i < fileCount; i++)
                {
                    xpckBr.BaseStream.Position = header.dataOffset + entries[i].fileOffset;
                    Files.Add(new XPCKFileInfo()
                    {
                        Entry    = entries[i],
                        FileName = nameList[i],
                        FileData = new MemoryStream(xpckBr.ReadBytes(entries[i].fileSize)),
                        State    = ArchiveFileState.Archived
                    });
                }
            }
        }
Exemplo n.º 22
0
        public XS(string filename)
        {
            using (BinaryReaderX br = new BinaryReaderX(File.OpenRead(filename)))
            {
                //Header
                header = br.ReadStruct <Header>();

                //Table0
                br.BaseStream.Position  = header.table0Offset << 2;
                table0Comp              = (Level5.Method)(br.ReadInt32() & 0x7);
                br.BaseStream.Position -= 4;
                entries = new BinaryReaderX(new MemoryStream(Level5.Decompress(br.BaseStream))).ReadMultiple <Entry>(header.table0EntryCount);

                //Table2
                br.BaseStream.Position  = header.table1Offset << 2;
                table1Comp              = (Level5.Method)(br.ReadInt32() & 0x7);
                br.BaseStream.Position -= 4;
                subEntries              = new BinaryReaderX(new MemoryStream(Level5.Decompress(br.BaseStream))).ReadMultiple <SubEntry>(header.table1EntryCount);

                //Text
                br.BaseStream.Position  = header.stringTableOffset << 2;
                stringComp              = (Level5.Method)(br.ReadInt32() & 0x7);
                br.BaseStream.Position -= 4;
                using (var text = new BinaryReaderX(new MemoryStream(Level5.Decompress(br.BaseStream))))
                {
                    var entryCount = 0;
                    foreach (var entry in entries)
                    {
                        for (int i = entry.subEntryOffset; i < entry.subEntryOffset + entry.subEntryCount; i++)
                        {
                            var subEntry = subEntries[i];
                            if (subEntry.ident == 0x18 && !offsets.Contains(subEntry.value))
                            {
                                text.BaseStream.Position = subEntry.value;
                                offsets.Add(subEntry.value);
                                Labels.Add(new Label
                                {
                                    Name   = $"{entryCount}:{i-entry.subEntryOffset}",
                                    TextID = i,
                                    Text   = text.ReadCStringSJIS()
                                });
                            }
                        }
                        entryCount++;
                    }
                }
            }
        }
Exemplo n.º 23
0
        public XF(Stream input)
        {
            using (var br = new BinaryReaderX(input))
            {
                //parse Header
                var header = br.ReadStruct <XpckHeader>();
                header.CorrectHeader();

                //parse FileEntries
                fileEntries = new List <FileEntry>();
                for (int i = 0; i < header.fileEntries; i++)
                {
                    fileEntries.Add(br.ReadStruct <FileEntry>());
                }

                //get xi image
                BinaryWriterX xi = new BinaryWriterX(new MemoryStream());
                br.BaseStream.Position = header.dataOffset + fileEntries[0].offset;
                xi.Write(br.ReadBytes(fileEntries[0].fileSize));
                xi.BaseStream.Position = 0;

                //convert xi image to bmp
                bmp = new IMGC(xi.BaseStream).Image;

                //get fnt.bin
                BinaryWriterX fnt = new BinaryWriterX(new MemoryStream());
                br.BaseStream.Position = header.dataOffset + fileEntries[0].fileSize + 4;
                fnt.Write(br.ReadBytes(fileEntries[1].fileSize));
                fnt.BaseStream.Position = 0;

                //decompress fnt.bin
                BinaryReaderX fntR = new BinaryReaderX(fnt.BaseStream);
                fntR.BaseStream.Position = 0x28;

                byte[] buf1 = Level5.Decompress(fntR.BaseStream);
                fntR.BaseStream.Position = (fntR.BaseStream.Position + 3) & ~3;
                byte[] buf2 = Level5.Decompress(fntR.BaseStream);
                fntR.BaseStream.Position = (fntR.BaseStream.Position + 3) & ~3;
                byte[] buf3 = Level5.Decompress(fntR.BaseStream);

                using (BinaryReaderX br2 = new BinaryReaderX(new MemoryStream(buf1)))
                    lstCharSizeInfo = Enumerable.Range(0, buf1.Length / 4).Select(_ => br2.ReadStruct <CharSizeInfo>()).ToList();
                using (BinaryReaderX br2 = new BinaryReaderX(new MemoryStream(buf2)))
                    dicGlyphLarge = Enumerable.Range(0, buf2.Length / 8).Select(i => br2.ReadStruct <CharacterMap>()).ToDictionary(x => x.code_point);
                using (BinaryReaderX br2 = new BinaryReaderX(new MemoryStream(buf3)))
                    dicGlyphSmall = Enumerable.Range(0, buf3.Length / 8).Select(i => br2.ReadStruct <CharacterMap>()).ToDictionary(x => x.code_point);
            }
        }
Exemplo n.º 24
0
        private void SaveComplexObject(Levels context, int[] levelIds)
        {
            // Protected Read
            Level1 level1 = new Level1();

            level1.Value  = "test";
            level1.Id     = levelIds[0]++;
            level1.levels = new List <Level2>();

            for (int i = 0; i < 5; i++)
            {
                Level2 curLevel2 = new Level2();
                level1.levels.Add(curLevel2);
                curLevel2.Id     = levelIds[1]++;
                curLevel2.Value  = "test" + i.ToString();
                curLevel2.levels = new List <Level3>();

                for (int j = 0; j < 5; j++)
                {
                    Level3 curLevel3 = new Level3();
                    curLevel2.levels.Add(curLevel3);
                    curLevel3.Id     = levelIds[2]++;
                    curLevel3.Value  = "test" + j.ToString();
                    curLevel3.levels = new List <Level4>();

                    for (int k = 0; k < 10; k++)
                    {
                        Level4 curLevel4 = new Level4();
                        curLevel3.levels.Add(curLevel4);
                        curLevel4.Id     = levelIds[3]++;
                        curLevel4.Value  = "test" + k.ToString();
                        curLevel4.levels = new List <Level5>();

                        for (int l = 0; l < 10; l++)
                        {
                            Level5 curLevel5 = new Level5();
                            curLevel4.levels.Add(curLevel5);
                            curLevel5.Id    = levelIds[4]++;
                            curLevel5.Value = "test" + l.ToString();
                        }
                    }
                }
            }

            context.Level1.Add(level1);
            context.SaveChanges();
        }
Exemplo n.º 25
0
        public static void Save(string filename, Bitmap bitmap)
        {
            int width  = (bitmap.Width + 0x7) & ~0x7;
            int height = (bitmap.Height + 0x7) & ~0x7;

            var settings = new ImageSettings
            {
                Width         = width,
                Height        = height,
                Orientation   = Orientation.TransposeTile,
                Format        = ImageSettings.ConvertFormat(header.imageFormat),
                PadToPowerOf2 = false
            };

            byte[] pic = Common.Save(bitmap, settings);

            using (var bw = new BinaryWriterX(File.Create(filename)))
            {
                //Header
                header.width  = (short)bitmap.Width;
                header.height = (short)bitmap.Height;

                //tile table
                var    table     = new MemoryStream();
                byte[] importPic = Deflate(pic, ImageSettings.ConvertFormat(header.imageFormat), out table);

                //Table
                bw.BaseStream.Position = 0x48;
                var comp = Level5.Compress(table, tableComp);
                bw.Write(comp);
                header.tableSize1 = comp.Length + 4;
                header.tableSize2 = (header.tableSize1 + 3) & ~3;

                //Image
                bw.BaseStream.Position = 0x48 + header.tableSize2;
                header.imageFormat     = (editMode) ? Format.ETC1 : header.imageFormat;
                comp = Level5.Compress(new MemoryStream(importPic), picComp);
                bw.Write(comp);
                header.imgDataSize = comp.Length;

                //Header
                bw.BaseStream.Position = 0;
                bw.WriteStruct(header);
            }
        }
Exemplo n.º 26
0
        public XS(string filename)
        {
            using (BinaryReaderX br = new BinaryReaderX(File.OpenRead(filename)))
            {
                //Header
                header = br.ReadStruct <Header>();

                //Table1
                table1 = br.ReadBytes((header.table2Offset << 2) - (header.table1Offset << 2));

                //Table2
                br.BaseStream.Position = header.table2Offset << 2;
                using (var table2 = new BinaryReaderX(new MemoryStream(Level5.Decompress(br.BaseStream))))
                {
                    while (table2.BaseStream.Position < table2.BaseStream.Length)
                    {
                        entries.Add(table2.ReadStruct <T2Entry>());
                    }
                }
                br.BaseStream.Position = (br.BaseStream.Position + 3) & ~3;

                //Text
                if (br.BaseStream.Position < br.BaseStream.Length)
                {
                    using (var text = new BinaryReaderX(new MemoryStream(Level5.Decompress(br.BaseStream))))
                    {
                        var count = 0;
                        foreach (var entry in entries)
                        {
                            if (entry.ident == 0x18 && !offsets.Contains(entry.textOffset))
                            {
                                offsets.Add(entry.textOffset);
                                text.BaseStream.Position = entry.textOffset;
                                Labels.Add(new Label
                                {
                                    Name   = $"text{count:000000}",
                                    TextID = count++,
                                    Text   = text.ReadCStringSJIS()
                                });
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 27
0
        public void Save(Stream file)
        {
            int width    = (Image.Width + 0x7) & ~0x7;
            int height   = (Image.Height + 0x7) & ~0x7;
            var settings = new ImageSettings
            {
                Width   = width,
                Height  = height,
                Format  = Support.Format[header.imageFormat],
                Swizzle = new ImgcSwizzle(width, height)
            };

            byte[] pic = L5XFEditor.Image.Common.Save(Image, settings);

            using (var bw = new BinaryWriterX(file, true))
            {
                //Header
                header.width  = (short)Image.Width;
                header.height = (short)Image.Height;

                //tile table
                var    table     = new MemoryStream();
                byte[] importPic = Deflate(pic, Support.Format[header.imageFormat].BitDepth, out table);

                //Table
                bw.BaseStream.Position = 0x48;
                var comp = Level5.Compress(table, tableComp);
                bw.Write(comp);
                header.tableSize1 = comp.Length;
                header.tableSize2 = (header.tableSize1 + 3) & ~3;

                //Image
                bw.BaseStream.Position = 0x48 + header.tableSize2;
                header.imageFormat     = (editMode) ? (byte)28 : header.imageFormat;
                comp = Level5.Compress(new MemoryStream(importPic), picComp);
                bw.Write(comp);
                bw.WriteAlignment(4);
                header.imgDataSize = comp.Length;

                //Header
                bw.BaseStream.Position = 0;
                bw.WriteStruct(header);
            }
        }
Exemplo n.º 28
0
        public void Save(string filename)
        {
            int width              = (Image.Width + 0x7) & ~0x7;
            int height             = (Image.Height + 0x7) & ~0x7;
            var isBlockCompression = Support.Format[header.imageFormat].FormatName.Contains("DXT");
            var settings           = new ImageSettings
            {
                Width   = width,
                Height  = height,
                Format  = Support.Format[header.imageFormat],
                Swizzle = isBlockCompression ? new Support.BlockSwizzle(header.width, header.height) : null
            };

            byte[] pic = Kontract.Image.Common.Save(Image, settings);

            using (var bw = new BinaryWriterX(File.Create(filename)))
            {
                //Header
                header.width  = (short)Image.Width;
                header.height = (short)Image.Height;

                //tile table
                var    table     = new MemoryStream();
                byte[] importPic = Deflate(pic, Support.Format[header.imageFormat].BitDepth, out table);

                //Table
                bw.BaseStream.Position = 0x48;
                var comp = Level5.Compress(table, tableComp);
                bw.Write(comp);
                header.tableSize1 = comp.Length;
                header.tableSize2 = (header.tableSize1 + 3) & ~3;

                //Image
                bw.BaseStream.Position = 0x48 + header.tableSize2;
                comp = Level5.Compress(new MemoryStream(importPic), picComp);
                bw.Write(comp);
                bw.WriteAlignment(4);
                header.imgDataSize = comp.Length;

                //Header
                bw.BaseStream.Position = 0;
                bw.WriteStruct(header);
            }
        }
Exemplo n.º 29
0
        public ARC0(Stream input)
        {
            _stream = input;
            using (BinaryReaderX br = new BinaryReaderX(input, true))
            {
                //Header
                header = br.ReadStruct <Header>();

                //Table 1
                br.BaseStream.Position = header.offset1;
                table1 = br.ReadBytes((int)(header.offset2 - header.offset1));

                //Table 2
                br.BaseStream.Position = header.offset2;
                table2 = br.ReadBytes((int)(header.fileEntriesOffset - header.offset2));

                //File Entry Table
                br.BaseStream.Position = header.fileEntriesOffset;
                entries = new BinaryReaderX(new MemoryStream(Level5.Decompress(new MemoryStream(br.ReadBytes((int)(header.nameOffset - header.fileEntriesOffset))))))
                          .ReadMultiple <FileEntry>(header.fileEntriesCount);

                //NameTable
                br.BaseStream.Position = header.nameOffset;
                nameC     = br.ReadBytes((int)(header.dataOffset - header.nameOffset));
                fileNames = GetFileNames(Level5.Decompress(new MemoryStream(nameC)));

                //Add Files
                List <uint> offsets = new List <uint>();
                foreach (var name in fileNames)
                {
                    var crc32 = Crc32.Create(name.Split('/').Last(), Encoding.GetEncoding("SJIS"));
                    var entry = entries.Find(c => c.crc32 == crc32 && !offsets.Contains(c.fileOffset));
                    offsets.Add(entry.fileOffset);
                    Files.Add(new ARC0FileInfo
                    {
                        State    = ArchiveFileState.Archived,
                        FileName = name,
                        FileData = new SubStream(br.BaseStream, header.dataOffset + entry.fileOffset, entry.fileSize),
                        entry    = entry
                    });
                }
            }
        }
Exemplo n.º 30
0
        public XS(string filename)
        {
            using (BinaryReaderX br = new BinaryReaderX(File.OpenRead(filename)))
            {
                //Header
                header = br.ReadStruct <Header>();

                //Table0
                br.BaseStream.Position  = header.table0Offset << 2;
                table0Comp              = (Level5.Method)(br.ReadInt32() & 0x7);
                br.BaseStream.Position -= 4;
                table0 = new BinaryReaderX(new MemoryStream(Level5.Decompress(br.BaseStream))).ReadMultiple <T0Entry>(header.table0EntryCount);

                //Table2
                br.BaseStream.Position  = header.table1Offset << 2;
                table1Comp              = (Level5.Method)(br.ReadInt32() & 0x7);
                br.BaseStream.Position -= 4;
                entries = new BinaryReaderX(new MemoryStream(Level5.Decompress(br.BaseStream))).ReadMultiple <VarStruct>(header.table1EntryCount);

                //Text
                br.BaseStream.Position  = header.stringTableOffset << 2;
                stringComp              = (Level5.Method)(br.ReadInt32() & 0x7);
                br.BaseStream.Position -= 4;
                using (var text = new BinaryReaderX(new MemoryStream(Level5.Decompress(br.BaseStream))))
                {
                    var count = 0;
                    foreach (var entry in entries)
                    {
                        if (entry.ident == 0x18 && !offsets.Contains(entry.value))
                        {
                            offsets.Add(entry.value);
                            text.BaseStream.Position = entry.value;
                            Labels.Add(new Label
                            {
                                Name   = $"text{count:000000}",
                                TextID = count++,
                                Text   = text.ReadCStringSJIS()
                            });
                        }
                    }
                }
            }
        }