예제 #1
0
        private static CpkRow ReadRow(BinaryReaderX tableBr, BinaryReaderX stringBr, BinaryReaderX dataBr,
                                      IList <CpkColumnInfo> columns)
        {
            var row = new CpkRow();

            foreach (var column in columns)
            {
                if (column.Storage == CpkColumnStorage.Row)
                {
                    row.Add(column.Name, CpkValue.Read(column.Type, tableBr, stringBr, dataBr));
                    continue;
                }

                row.Add(column.Name, column.Value);
            }

            return(row);
        }
예제 #2
0
        public static CpkTable Create(Stream utfStream, string tableMagic)
        {
            // Read table info
            using var utfBr = new BinaryReaderX(utfStream, ByteOrder.BigEndian);
            var tableInfo = utfBr.ReadType <CpkTableInfo>();

            // Create readers
            var tableStream  = new SubStream(utfStream, 0x8, tableInfo.tableSize);
            var stringStream = new SubStream(tableStream, tableInfo.stringsOffset,
                                             tableInfo.binaryOffset - tableInfo.stringsOffset);
            var dataStream = new SubStream(tableStream, tableInfo.binaryOffset,
                                           tableInfo.tableSize - tableInfo.binaryOffset);

            using var tableBr  = new BinaryReaderX(tableStream, ByteOrder.BigEndian);
            using var stringBr = new BinaryReaderX(stringStream, ByteOrder.BigEndian);
            using var dataBr   = new BinaryReaderX(dataStream, ByteOrder.BigEndian);

            // Read table name
            var name = CpkSupport.ReadString(stringBr, tableInfo.nameOffset);

            // Read columns
            tableStream.Position = 0x18;

            var columns = new CpkColumnInfo[tableInfo.columnCount];

            for (var i = 0; i < tableInfo.columnCount; i++)
            {
                columns[i] = ReadColumn(tableBr, stringBr, dataBr);
            }

            // Read rows
            tableStream.Position = tableInfo.valuesOffset;

            var rows = new CpkRow[tableInfo.rowCount];

            for (var i = 0; i < tableInfo.rowCount; i++)
            {
                rows[i] = ReadRow(tableBr, stringBr, dataBr, columns);
            }

            return(new CpkTable(tableMagic, name, rows));
        }