Inheritance: QbItemBase
示例#1
0
        /// <summary>
        /// Deep clones this item and all children.  Positions and lengths are not cloned.  When inserted in to another item they should be calculated.
        /// </summary>
        /// <returns></returns>
        public override QbItemBase Clone()
        {
            QbItemArray a = new QbItemArray(this.Root);
            a.Create(this.QbItemType);

            if (this.ItemQbKey != null)
                a.ItemQbKey = this.ItemQbKey.Clone();

            foreach (QbItemBase qib in this.Items)
                a.Items.Add(qib.Clone());

            a.ItemCount = this.ItemCount;

            return a;
        }
示例#2
0
        /// <summary>
        /// Deep clones this item and all children.  Positions and lengths are not cloned.  When inserted in to another item they should be calculated.
        /// </summary>
        /// <returns></returns>
        public override QbItemBase Clone()
        {
            QbItemArray a = new QbItemArray(this.Root);

            a.Create(this.QbItemType);

            if (this.ItemQbKey != null)
            {
                a.ItemQbKey = this.ItemQbKey.Clone();
            }

            foreach (QbItemBase qib in this.Items)
            {
                a.Items.Add(qib.Clone());
            }

            a.ItemCount = this.ItemCount;

            return(a);
        }
示例#3
0
        public override void Construct(BinaryEndianReader br, QbItemType type)
        {
            //System.Diagnostics.Debug.WriteLine(string.Format("{0} - 0x{1}", type.ToString(), (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0')));

            base.Construct(br, type);

            uint pointer;

            if (type != QbItemType.StructHeader)
                _headerValue = br.ReadUInt32(base.Root.PakFormat.EndianType);
            else
                _headerValue = base.Root.PakFormat.GetQbItemValue(type, this.Root);

             _headerType = base.Root.PakFormat.GetQbItemType(_headerValue);

            QbItemBase qib = null;
            QbItemType structType;
            uint structValue;

            if (_headerType == QbItemType.StructHeader)
            {
                pointer = br.ReadUInt32(base.Root.PakFormat.EndianType); //Should be the current stream position after reading

                _iniNextItemPointer = pointer;

                if (pointer != 0 && base.StreamPos(br) != pointer) //pointer test
                    throw new ApplicationException(QbFile.FormatBadPointerExceptionMessage(this, base.StreamPos(br), pointer));

                while (pointer != 0)
                {
                    structValue = br.ReadUInt32(this.Root.PakFormat.EndianType);
                    structType = this.Root.PakFormat.GetQbItemType(structValue);

                    switch (structType)
                    {
                        case QbItemType.StructItemStruct:
                            this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                            qib = new QbItemStruct(this.Root);
                            break;
                        case QbItemType.StructItemStringPointer:
                        case QbItemType.StructItemInteger:
                            this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                            qib = new QbItemInteger(this.Root);
                            break;
                        case QbItemType.StructItemQbKeyString:
                        case QbItemType.StructItemQbKeyStringQs:
                        case QbItemType.StructItemQbKey:
                            this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                            qib = new QbItemQbKey(this.Root);
                            break;
                        case QbItemType.StructItemString:
                        case QbItemType.StructItemStringW:
                            this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                            qib = new QbItemString(this.Root);
                            break;
                        case QbItemType.StructItemFloat:
                            this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                            qib = new QbItemFloat(this.Root);
                            break;
                        case QbItemType.StructItemFloatsX2:
                        case QbItemType.StructItemFloatsX3:
                            this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                            qib = new QbItemFloatsArray(this.Root);
                            break;
                        case QbItemType.StructItemArray:
                            this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                            qib = new QbItemArray(this.Root);
                            break;

                        //Convert array types to structitems to fit in with this parser (if QbFile.HasStructItems is false then internal type will be swapped back to array)
                        case QbItemType.ArrayStruct:
                            structType = QbItemType.StructItemStruct;
                            qib = new QbItemArray(this.Root);
                            break;
                        case QbItemType.ArrayInteger:
                            structType = QbItemType.StructItemInteger;
                            qib = new QbItemInteger(this.Root);
                            break;
                        case QbItemType.ArrayQbKeyString:
                            structType = QbItemType.StructItemQbKeyString;
                            qib = new QbItemQbKey(this.Root);
                            break;
                        case QbItemType.ArrayStringPointer:
                            structType = QbItemType.StructItemStringPointer;
                            qib = new QbItemInteger(this.Root);
                            break;
                        case QbItemType.ArrayQbKeyStringQs:
                            structType = QbItemType.StructItemQbKeyStringQs;
                            qib = new QbItemQbKey(this.Root);
                            break;
                        case QbItemType.ArrayQbKey:
                            structType = QbItemType.StructItemQbKey;
                            qib = new QbItemQbKey(this.Root);
                            break;
                        case QbItemType.ArrayString:
                            structType = QbItemType.StructItemString;
                            qib = new QbItemString(this.Root);
                            break;
                        case QbItemType.ArrayStringW:
                            structType = QbItemType.StructItemStringW;
                            qib = new QbItemString(this.Root);
                            break;
                        case QbItemType.ArrayFloat:
                            structType = QbItemType.StructItemFloat;
                            qib = new QbItemFloat(this.Root);
                            break;
                        case QbItemType.ArrayFloatsX2:
                            structType = QbItemType.StructItemFloatsX2;
                            qib = new QbItemFloatsArray(this.Root);
                            break;
                        case QbItemType.ArrayFloatsX3:
                            structType = QbItemType.StructItemFloatsX3;
                            qib = new QbItemFloatsArray(this.Root);
                            break;
                        case QbItemType.ArrayArray:
                            structType = QbItemType.StructItemArray;
                            qib = new QbItemArray(this.Root);
                            break;
                        default:
                            qib = null;
                            break;
                    }

                    if (qib != null)
                    {
                        if (this.Root.PakFormat.StructItemChildrenType == StructItemChildrenType.NotSet) //will have been set to structItem if qib is not null)
                            this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.ArrayItems;

                        qib.Construct(br, structType);
                        AddItem(qib);
                        pointer = qib.NextItemPointer;
                    }
                    else
                        throw new ApplicationException(string.Format("Location 0x{0}: Unknown item type 0x{1} in struct ", (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0'), structValue.ToString("X").PadLeft(8, '0')));

                }
            }
            else
                throw new ApplicationException(string.Format("Location 0x{0}: Struct without header type", (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0')));

            base.ConstructEnd(br);
        }
示例#4
0
        public override void Construct(BinaryEndianReader br, QbItemType type)
        {
            //System.Diagnostics.Debug.WriteLine(string.Format("{0} - 0x{1}", type.ToString(), (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0')));

            base.Construct(br, type);

            uint pointer;

            if (type != QbItemType.StructHeader)
            {
                _headerValue = br.ReadUInt32(base.Root.PakFormat.EndianType);
            }
            else
            {
                _headerValue = base.Root.PakFormat.GetQbItemValue(type, this.Root);
            }

            _headerType = base.Root.PakFormat.GetQbItemType(_headerValue);

            QbItemBase qib = null;
            QbItemType structType;
            uint       structValue;

            if (_headerType == QbItemType.StructHeader)
            {
                pointer = br.ReadUInt32(base.Root.PakFormat.EndianType); //Should be the current stream position after reading

                _iniNextItemPointer = pointer;

                if (pointer != 0 && base.StreamPos(br) != pointer) //pointer test
                {
                    throw new ApplicationException(QbFile.FormatBadPointerExceptionMessage(this, base.StreamPos(br), pointer));
                }

                while (pointer != 0)
                {
                    structValue = br.ReadUInt32(this.Root.PakFormat.EndianType);
                    structType  = this.Root.PakFormat.GetQbItemType(structValue);

                    switch (structType)
                    {
                    case QbItemType.StructItemStruct:
                        this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                        qib = new QbItemStruct(this.Root);
                        break;

                    case QbItemType.StructItemStringPointer:
                    case QbItemType.StructItemInteger:
                        this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                        qib = new QbItemInteger(this.Root);
                        break;

                    case QbItemType.StructItemQbKeyString:
                    case QbItemType.StructItemQbKeyStringQs:
                    case QbItemType.StructItemQbKey:
                        this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                        qib = new QbItemQbKey(this.Root);
                        break;

                    case QbItemType.StructItemString:
                    case QbItemType.StructItemStringW:
                        this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                        qib = new QbItemString(this.Root);
                        break;

                    case QbItemType.StructItemFloat:
                        this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                        qib = new QbItemFloat(this.Root);
                        break;

                    case QbItemType.StructItemFloatsX2:
                    case QbItemType.StructItemFloatsX3:
                        this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                        qib = new QbItemFloatsArray(this.Root);
                        break;

                    case QbItemType.StructItemArray:
                        this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.StructItems;
                        qib = new QbItemArray(this.Root);
                        break;

                    //Convert array types to structitems to fit in with this parser (if QbFile.HasStructItems is false then internal type will be swapped back to array)
                    case QbItemType.ArrayStruct:
                        structType = QbItemType.StructItemStruct;
                        qib        = new QbItemArray(this.Root);
                        break;

                    case QbItemType.ArrayInteger:
                        structType = QbItemType.StructItemInteger;
                        qib        = new QbItemInteger(this.Root);
                        break;

                    case QbItemType.ArrayQbKeyString:
                        structType = QbItemType.StructItemQbKeyString;
                        qib        = new QbItemQbKey(this.Root);
                        break;

                    case QbItemType.ArrayStringPointer:
                        structType = QbItemType.StructItemStringPointer;
                        qib        = new QbItemInteger(this.Root);
                        break;

                    case QbItemType.ArrayQbKeyStringQs:
                        structType = QbItemType.StructItemQbKeyStringQs;
                        qib        = new QbItemQbKey(this.Root);
                        break;

                    case QbItemType.ArrayQbKey:
                        structType = QbItemType.StructItemQbKey;
                        qib        = new QbItemQbKey(this.Root);
                        break;

                    case QbItemType.ArrayString:
                        structType = QbItemType.StructItemString;
                        qib        = new QbItemString(this.Root);
                        break;

                    case QbItemType.ArrayStringW:
                        structType = QbItemType.StructItemStringW;
                        qib        = new QbItemString(this.Root);
                        break;

                    case QbItemType.ArrayFloat:
                        structType = QbItemType.StructItemFloat;
                        qib        = new QbItemFloat(this.Root);
                        break;

                    case QbItemType.ArrayFloatsX2:
                        structType = QbItemType.StructItemFloatsX2;
                        qib        = new QbItemFloatsArray(this.Root);
                        break;

                    case QbItemType.ArrayFloatsX3:
                        structType = QbItemType.StructItemFloatsX3;
                        qib        = new QbItemFloatsArray(this.Root);
                        break;

                    case QbItemType.ArrayArray:
                        structType = QbItemType.StructItemArray;
                        qib        = new QbItemArray(this.Root);
                        break;

                    default:
                        qib = null;
                        break;
                    }

                    if (qib != null)
                    {
                        if (this.Root.PakFormat.StructItemChildrenType == StructItemChildrenType.NotSet) //will have been set to structItem if qib is not null)
                        {
                            this.Root.PakFormat.StructItemChildrenType = StructItemChildrenType.ArrayItems;
                        }

                        qib.Construct(br, structType);
                        AddItem(qib);
                        pointer = qib.NextItemPointer;
                    }
                    else
                    {
                        throw new ApplicationException(string.Format("Location 0x{0}: Unknown item type 0x{1} in struct ", (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0'), structValue.ToString("X").PadLeft(8, '0')));
                    }
                }
            }
            else
            {
                throw new ApplicationException(string.Format("Location 0x{0}: Struct without header type", (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0')));
            }

            base.ConstructEnd(br);
        }
示例#5
0
        private QbItemStruct findTierProgStruct(QbKey firstChild, QbItemArray careerProgressionStruct)
        {
            QbKey tname = QbKey.Create("name");

            return careerProgressionStruct.FindItem(true, delegate(QbItemBase qib)
            {
                QbItemStruct qs = (qib as QbItemStruct);
                if (qs != null && qs.Items.Count != 0 && qs.Items[0] is QbItemQbKey)
                {
                    QbItemQbKey qk = (QbItemQbKey)qs.Items[0];
                    if (qk.ItemQbKey.Crc == tname.Crc && qk.Values[0].Crc == firstChild.Crc)
                        return true;
                }
                return false;
            }) as QbItemStruct;
        }
示例#6
0
        private static QbItemBase createQbItemType(QbFile qbFile, QbItemType type, QbFormat qbFormat, bool hasQbFormat)
        {
            QbItemBase qib = null;

            if (qbFile.PakFormat.GetQbItemValue(type, qbFile) == 0xFFFFFFFF)
                throw new ApplicationException(string.Format("'{0}' data value not known for {1}", type.ToString(), qbFile.PakFormat.FriendlyName));

            switch (type)
            {
                //case QbItemType.Unknown:
                //    break;

                case QbItemType.SectionString:
                case QbItemType.SectionStringW:
                case QbItemType.ArrayString:
                case QbItemType.ArrayStringW:
                case QbItemType.StructItemString:
                case QbItemType.StructItemStringW:
                    qib = new QbItemString(qbFile);
                    break;
                case QbItemType.SectionArray:
                case QbItemType.ArrayArray:
                case QbItemType.StructItemArray:
                    qib = new QbItemArray(qbFile);
                    break;
                case QbItemType.SectionStruct:
                case QbItemType.StructItemStruct:
                case QbItemType.StructHeader:
                    qib = new QbItemStruct(qbFile);
                    break;
                case QbItemType.SectionScript:
                    qib = new QbItemScript(qbFile);
                    break;
                case QbItemType.SectionFloat:
                case QbItemType.ArrayFloat:
                case QbItemType.StructItemFloat:
                    qib = new QbItemFloat(qbFile);
                    break;
                case QbItemType.SectionFloatsX2:
                case QbItemType.SectionFloatsX3:
                case QbItemType.ArrayFloatsX2:
                case QbItemType.ArrayFloatsX3:
                case QbItemType.StructItemFloatsX2:
                case QbItemType.StructItemFloatsX3:
                    qib = new QbItemFloatsArray(qbFile);
                    break;
                case QbItemType.SectionInteger:
                case QbItemType.SectionStringPointer:
                case QbItemType.ArrayInteger:
                case QbItemType.ArrayStringPointer: //GH:GH
                case QbItemType.StructItemStringPointer:
                case QbItemType.StructItemInteger:
                    qib = new QbItemInteger(qbFile);
                    break;
                case QbItemType.SectionQbKey:
                case QbItemType.SectionQbKeyString:
                case QbItemType.SectionQbKeyStringQs: //GH:GH
                case QbItemType.ArrayQbKey:
                case QbItemType.ArrayQbKeyString:
                case QbItemType.ArrayQbKeyStringQs: //GH:GH
                case QbItemType.StructItemQbKey:
                case QbItemType.StructItemQbKeyString:
                case QbItemType.StructItemQbKeyStringQs:
                    qib = new QbItemQbKey(qbFile);
                    break;
                case QbItemType.Floats:
                    qib = new QbItemFloats(qbFile);
                    break;
                case QbItemType.ArrayStruct:
                    qib = new QbItemStructArray(qbFile);
                    break;

                default:
                    throw new ApplicationException(string.Format("'{0}' is not recognised by CreateQbItemType.", type.ToString()));
            }
            if (qib != null)
                qib.Create(type);

            return qib;
        }
示例#7
0
        private void parse(Stream stream)
        {
            _streamStartPosition = stream.Position;

            _items = new List<QbItemBase>();

            //if (stream.Position != 0)
            //    throw new ApplicationException("The stream must start at position 0 as this parser uses the position to validate pointers.");

            using (BinaryEndianReader br = new BinaryEndianReader(stream))
            {
                _magic = br.ReadUInt32(this.PakFormat.EndianType);
                _fileSize = br.ReadUInt32(this.PakFormat.EndianType);

                uint sectionValue;

                QbItemBase qib = new QbItemUnknown(20, this);
                qib.Construct(br, QbItemType.Unknown);
                AddItem(qib);

                while (this.StreamPos(br.BaseStream) < _fileSize)
                {
                    sectionValue = br.ReadUInt32(this.PakFormat.EndianType);
                    QbItemType sectionType = this.PakFormat.GetQbItemType(sectionValue);

                    switch (sectionType)
                    {
                        case QbItemType.SectionString:
                        case QbItemType.SectionStringW:
                            qib = new QbItemString(this);
                            break;
                        case QbItemType.SectionArray:
                            qib = new QbItemArray(this);
                            break;
                        case QbItemType.SectionStruct:
                            qib = new QbItemStruct(this);
                            break;
                        case QbItemType.SectionScript:
                            qib = new QbItemScript(this);
                            break;
                        case QbItemType.SectionFloat:
                            qib = new QbItemFloat(this);
                            break;
                        case QbItemType.SectionFloatsX2:
                        case QbItemType.SectionFloatsX3:
                            qib = new QbItemFloatsArray(this);
                            break;
                        case QbItemType.SectionInteger:
                        case QbItemType.SectionStringPointer:
                            qib = new QbItemInteger(this);
                            break;
                        case QbItemType.SectionQbKey:
                        case QbItemType.SectionQbKeyString:
                        case QbItemType.SectionQbKeyStringQs: //GH:GH
                            qib = new QbItemQbKey(this);
                            break;
                        default:
                            throw new ApplicationException(string.Format("Location 0x{0}: Unknown section type 0x{1}", (this.StreamPos(br.BaseStream) - 4).ToString("X").PadLeft(8, '0'), sectionValue.ToString("X").PadLeft(8, '0')));
                    }
                    qib.Construct(br, sectionType);

                    AddItem(qib);
                }
            }

            uint f = this.FileId; //gettin this sets the file id
        }
示例#8
0
        private static QbItemBase createQbItemType(QbFile qbFile, QbItemType type, QbFormat qbFormat, bool hasQbFormat)
        {
            QbItemBase qib = null;

            if (qbFile.PakFormat.GetQbItemValue(type, qbFile) == 0xFFFFFFFF)
            {
                throw new ApplicationException(string.Format("'{0}' data value not known for {1}", type.ToString(), qbFile.PakFormat.FriendlyName));
            }

            switch (type)
            {
            //case QbItemType.Unknown:
            //    break;

            case QbItemType.SectionString:
            case QbItemType.SectionStringW:
            case QbItemType.ArrayString:
            case QbItemType.ArrayStringW:
            case QbItemType.StructItemString:
            case QbItemType.StructItemStringW:
                qib = new QbItemString(qbFile);
                break;

            case QbItemType.SectionArray:
            case QbItemType.ArrayArray:
            case QbItemType.StructItemArray:
                qib = new QbItemArray(qbFile);
                break;

            case QbItemType.SectionStruct:
            case QbItemType.StructItemStruct:
            case QbItemType.StructHeader:
                qib = new QbItemStruct(qbFile);
                break;

            case QbItemType.SectionScript:
                qib = new QbItemScript(qbFile);
                break;

            case QbItemType.SectionFloat:
            case QbItemType.ArrayFloat:
            case QbItemType.StructItemFloat:
                qib = new QbItemFloat(qbFile);
                break;

            case QbItemType.SectionFloatsX2:
            case QbItemType.SectionFloatsX3:
            case QbItemType.ArrayFloatsX2:
            case QbItemType.ArrayFloatsX3:
            case QbItemType.StructItemFloatsX2:
            case QbItemType.StructItemFloatsX3:
                qib = new QbItemFloatsArray(qbFile);
                break;

            case QbItemType.SectionInteger:
            case QbItemType.SectionStringPointer:
            case QbItemType.ArrayInteger:
            case QbItemType.ArrayStringPointer:     //GH:GH
            case QbItemType.StructItemStringPointer:
            case QbItemType.StructItemInteger:
                qib = new QbItemInteger(qbFile);
                break;

            case QbItemType.SectionQbKey:
            case QbItemType.SectionQbKeyString:
            case QbItemType.SectionQbKeyStringQs:     //GH:GH
            case QbItemType.ArrayQbKey:
            case QbItemType.ArrayQbKeyString:
            case QbItemType.ArrayQbKeyStringQs:     //GH:GH
            case QbItemType.StructItemQbKey:
            case QbItemType.StructItemQbKeyString:
            case QbItemType.StructItemQbKeyStringQs:
                qib = new QbItemQbKey(qbFile);
                break;

            case QbItemType.Floats:
                qib = new QbItemFloats(qbFile);
                break;

            case QbItemType.ArrayStruct:
                qib = new QbItemStructArray(qbFile);
                break;

            default:
                throw new ApplicationException(string.Format("'{0}' is not recognised by CreateQbItemType.", type.ToString()));
            }
            if (qib != null)
            {
                qib.Create(type);
            }

            return(qib);
        }
示例#9
0
        private void parse(Stream stream)
        {
            _streamStartPosition = stream.Position;

            _items = new List <QbItemBase>();

            //if (stream.Position != 0)
            //    throw new ApplicationException("The stream must start at position 0 as this parser uses the position to validate pointers.");

            using (BinaryEndianReader br = new BinaryEndianReader(stream))
            {
                _magic    = br.ReadUInt32(this.PakFormat.EndianType);
                _fileSize = br.ReadUInt32(this.PakFormat.EndianType);

                uint sectionValue;

                QbItemBase qib = new QbItemUnknown(20, this);
                qib.Construct(br, QbItemType.Unknown);
                AddItem(qib);

                while (this.StreamPos(br.BaseStream) < _fileSize)
                {
                    sectionValue = br.ReadUInt32(this.PakFormat.EndianType);
                    QbItemType sectionType = this.PakFormat.GetQbItemType(sectionValue);

                    switch (sectionType)
                    {
                    case QbItemType.SectionString:
                    case QbItemType.SectionStringW:
                        qib = new QbItemString(this);
                        break;

                    case QbItemType.SectionArray:
                        qib = new QbItemArray(this);
                        break;

                    case QbItemType.SectionStruct:
                        qib = new QbItemStruct(this);
                        break;

                    case QbItemType.SectionScript:
                        qib = new QbItemScript(this);
                        break;

                    case QbItemType.SectionFloat:
                        qib = new QbItemFloat(this);
                        break;

                    case QbItemType.SectionFloatsX2:
                    case QbItemType.SectionFloatsX3:
                        qib = new QbItemFloatsArray(this);
                        break;

                    case QbItemType.SectionInteger:
                    case QbItemType.SectionStringPointer:
                        qib = new QbItemInteger(this);
                        break;

                    case QbItemType.SectionQbKey:
                    case QbItemType.SectionQbKeyString:
                    case QbItemType.SectionQbKeyStringQs:     //GH:GH
                        qib = new QbItemQbKey(this);
                        break;

                    default:
                        throw new ApplicationException(string.Format("Location 0x{0}: Unknown section type 0x{1}", (this.StreamPos(br.BaseStream) - 4).ToString("X").PadLeft(8, '0'), sectionValue.ToString("X").PadLeft(8, '0')));
                    }
                    qib.Construct(br, sectionType);

                    AddItem(qib);
                }
            }

            uint f = this.FileId; //gettin this sets the file id
        }
示例#10
0
        public override void Construct(BinaryEndianReader br, QbItemType type)
        {
            //System.Diagnostics.Debug.WriteLine(string.Format("{0} - 0x{1}", type.ToString(), (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0')));

            base.Construct(br, type);

            QbItemBase qib = null;
            QbItemType arrayType;
            uint       arrayValue;

            for (int i = 0; i < base.ItemCount; i++)
            {
                arrayValue = br.ReadUInt32(this.Root.PakFormat.EndianType);
                arrayType  = this.Root.PakFormat.GetQbItemType(arrayValue);

                switch (arrayType)
                {
                case QbItemType.Floats:
                    qib = new QbItemFloats(this.Root);
                    break;

                case QbItemType.ArrayStruct:
                    qib = new QbItemStructArray(this.Root);
                    break;

                case QbItemType.ArrayFloat:
                    qib = new QbItemFloat(this.Root);
                    break;

                case QbItemType.ArrayString:
                case QbItemType.ArrayStringW:
                    qib = new QbItemString(this.Root);
                    break;

                case QbItemType.ArrayFloatsX2:
                case QbItemType.ArrayFloatsX3:
                    qib = new QbItemFloatsArray(this.Root);
                    break;

                case QbItemType.ArrayStringPointer:
                case QbItemType.ArrayInteger:
                    qib = new QbItemInteger(this.Root);
                    break;

                case QbItemType.ArrayArray:
                    qib = new QbItemArray(this.Root);
                    break;

                case QbItemType.ArrayQbKey:
                case QbItemType.ArrayQbKeyString:
                case QbItemType.ArrayQbKeyStringQs:     //GH:GH
                    qib = new QbItemQbKey(this.Root);
                    break;

                case QbItemType.StructHeader:
                    qib = new QbItemStruct(this.Root);
                    break;

                default:
                    throw new ApplicationException(string.Format("Location 0x{0}: Unknown array type 0x{1}", (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0'), arrayValue.ToString("X").PadLeft(8, '0')));
                }
                qib.Construct(br, arrayType);
                AddItem(qib);
            }
            base.ConstructEnd(br);
        }
示例#11
0
        public override void Construct(BinaryEndianReader br, QbItemType type)
        {
            //System.Diagnostics.Debug.WriteLine(string.Format("{0} - 0x{1}", type.ToString(), (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0')));

            base.Construct(br, type);

            QbItemBase qib = null;
            QbItemType arrayType;
            uint arrayValue;

            for (int i = 0; i < base.ItemCount; i++)
            {
                arrayValue = br.ReadUInt32(this.Root.PakFormat.EndianType);
                arrayType = this.Root.PakFormat.GetQbItemType(arrayValue);

                switch (arrayType)
                {
                    case QbItemType.Floats:
                        qib = new QbItemFloats(this.Root);
                        break;
                    case QbItemType.ArrayStruct:
                        qib = new QbItemStructArray(this.Root);
                        break;
                    case QbItemType.ArrayFloat:
                        qib = new QbItemFloat(this.Root);
                        break;
                    case QbItemType.ArrayString:
                    case QbItemType.ArrayStringW:
                        qib = new QbItemString(this.Root);
                        break;
                    case QbItemType.ArrayFloatsX2:
                    case QbItemType.ArrayFloatsX3:
                        qib = new QbItemFloatsArray(this.Root);
                        break;
                    case QbItemType.ArrayStringPointer:
                    case QbItemType.ArrayInteger:
                        qib = new QbItemInteger(this.Root);
                        break;
                    case QbItemType.ArrayArray:
                        qib = new QbItemArray(this.Root);
                        break;
                    case QbItemType.ArrayQbKey:
                    case QbItemType.ArrayQbKeyString:
                    case QbItemType.ArrayQbKeyStringQs: //GH:GH
                        qib = new QbItemQbKey(this.Root);
                        break;
                    case QbItemType.StructHeader:
                        qib = new QbItemStruct(this.Root);
                        break;
                    default:
                        throw new ApplicationException(string.Format("Location 0x{0}: Unknown array type 0x{1}", (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0'), arrayValue.ToString("X").PadLeft(8, '0')));
                }
                qib.Construct(br, arrayType);
                AddItem(qib);

            }
            base.ConstructEnd(br);
        }
示例#12
0
        private void calculateMarkers(int[] frets, QbItemArray arr, QbFile text)
        {
            int minNote = this.Notes.MinNoteOffsetSynced + _startPaddingMs + _fretPadding;
            int maxNote = this.Notes.MaxNoteOffsetSynced + _startPaddingMs + _fretPadding;

            int pos = minNote;

            int sectionSecs = 20000;
            int sections = (maxNote - minNote) / sectionSecs; //every x seconds

            for (int c = text.Items.Count - 1; c > 0; c--)
                text.RemoveItem(text.Items[c]);

            QbItemStructArray sa = new QbItemStructArray(arr.Root);
            sa.Create(QbItemType.ArrayStruct);

            arr.Items.Clear();
            arr.AddItem(sa);

            QbItemStruct s;
            QbItemInteger i;
            QbItemQbKey q;
            string sectionTitle;
            QbKey qbKey;
            QbItemString txt;

            for (int c = 0; c < sections; c++)
            {
                if (pos + 3000 > this.Length)
                    break; //don't create a section less than 3 seconds long

                sectionTitle = string.Format("Section {0}", (c + 1).ToString());
                qbKey = QbKey.Create(string.Format("{0}_markers_text_{1}", this.SongQb.Id, QbKey.Create(sectionTitle).Crc.ToString("x").ToLower()));

                txt = new QbItemString(text);
                txt.Create(QbItemType.SectionString);
                txt.ItemQbKey = qbKey;
                txt.Strings = new string[] { sectionTitle };
                text.AddItem(txt);

                s = new QbItemStruct(arr.Root);
                s.Create(QbItemType.StructHeader);
                sa.AddItem(s);

                i = new QbItemInteger(arr.Root);
                i.Create(QbItemType.StructItemInteger);
                i.ItemQbKey = QbKey.Create("time");
                i.Values = new uint[] { findNearestFret((uint)pos, frets) };
                s.AddItem(i);

                pos += sectionSecs;

                q = new QbItemQbKey(arr.Root);
                q.Create(QbItemType.StructItemQbKeyString);
                q.ItemQbKey = QbKey.Create("marker");
                q.Values = new QbKey[] { qbKey };
                s.AddItem(q);
            }

            text.AlignPointers();
            arr.Root.AlignPointers();
        }
示例#13
0
 private void clearQbItems(QbItemArray a)
 {
     replaceQbItems(a, new int[0], false);
 }
示例#14
0
        private void setMarkers(int[] frets, QbItemArray arr, QbFile text, NotesMarker[] markers)
        {
            int minNote = this.Notes.MinNoteOffsetSynced + _startPaddingMs + _fretPadding;
            QbItemStruct s;
            QbItemInteger i;
            QbItemQbKey q;
            QbKey qbKey;
            QbItemString txt;

            for (int c = text.Items.Count - 1; c > 0; c--)
                text.RemoveItem(text.Items[c]);

            if (arr.Items[0] is QbItemFloats)
            {
                QbItemStructArray newArr = new QbItemStructArray(arr.Root);
                newArr.Create(QbItemType.ArrayStruct);
                arr.AddItem(newArr);
                arr.RemoveItem(arr.Items[0]);
            }

            QbItemStructArray sa = (QbItemStructArray)arr.Items[0];
            sa.Items.Clear();

            NotesMarker marker;

            List<NotesMarker> mrk = new List<NotesMarker>(markers);

            if (mrk.Count > 0 && mrk[0].Offset > minNote)  //some charts don't have sections at the start so you can't practice the start notes :-(
            {
                if (mrk[0].Offset > minNote + 5000) // if > 5secs then add new
                    mrk.Insert(0, new NotesMarker("Start", minNote));
                else //else move first marker back to start
                    mrk[0].Offset = minNote;
            }

            for (int c = 0; c < mrk.Count; c++)
            {
                marker = mrk[c];
                if (c < mrk.Count - 1 && mrk[c + 1].Offset < minNote)
                    continue; //don't add sections at the start that would have no notes (crashes song??)

                qbKey = QbKey.Create(string.Format("{0}_markers_text_{1}", this.SongQb.Id, QbKey.Create(marker.Title).Crc.ToString("x").ToLower()));

                txt = new QbItemString(text);
                txt.Create(QbItemType.SectionString);
                txt.ItemQbKey = qbKey;
                txt.Strings = new string[] { marker.Title };
                text.AddItem(txt);

                s = new QbItemStruct(arr.Root);
                s.Create(QbItemType.StructHeader);
                sa.AddItem(s);

                i = new QbItemInteger(arr.Root);
                i.Create(QbItemType.StructItemInteger);
                i.ItemQbKey = QbKey.Create("time");
                i.Values = new uint[] { findNearestFret((uint)marker.Offset, frets) };
                s.AddItem(i);

                q = new QbItemQbKey(arr.Root);
                q.Create(QbItemType.StructItemQbKeyString);
                q.ItemQbKey = QbKey.Create("marker");
                q.Values = new QbKey[] { qbKey };
                s.AddItem(q);
            }
            text.AlignPointers();
            arr.Root.AlignPointers();
        }
示例#15
0
        private void setLength(QbItemArray a, int msSongLength, int blockSize, int[] frets, bool bindToFret)
        {
            uint val;
            uint lastVal = uint.MaxValue;

            if (a.ItemCount != 0)
            {
                if (a.Items[0].QbItemType == QbItemType.Floats)
                {
                    //nothing to edit
                }
                else if (a.Items[0].QbItemType == QbItemType.ArrayArray)
                {
                    QbItemArray arr = (QbItemArray)a.Items[0];
                    int idx = arr.Items.Count - 1;
                    while (idx >= 0)
                    {
                        val = ((QbItemInteger)arr.Items[idx]).Values[0];
                        if (bindToFret)
                            val = findNearestFret(val, frets);

                        if (val == lastVal || val < 0 || val > msSongLength)
                            arr.RemoveItem(arr.Items[idx]);
                        else if (bindToFret)
                            ((QbItemInteger)arr.Items[idx]).Values[0] = val;

                        if (bindToFret)
                            lastVal = val;

                        idx--;
                    }
                }
                else if (a.Items[0].QbItemType == QbItemType.ArrayStruct)
                {
                    QbItemStructArray arr = (QbItemStructArray)a.Items[0];
                    int idx = arr.Items.Count - 1;
                    while (idx >= 0)
                    {
                        val = ((QbItemInteger)((QbItemStruct)arr.Items[idx]).Items[0]).Values[0];
                        if (bindToFret)
                            val = findNearestFret(val, frets);

                        if (val == lastVal || val < 0 || val > msSongLength)
                            arr.RemoveItem(arr.Items[idx]);
                        else if (bindToFret)
                            ((QbItemInteger)((QbItemStruct)arr.Items[idx]).Items[0]).Values[0] = val;

                        if (bindToFret)
                            lastVal = val;
                        idx--;
                    }
                }
                else
                {
                    int start = 0;
                    uint[] arr = ((QbItemInteger)a.Items[0]).Values;
                    int idx = arr.Length - blockSize;
                    while (start < arr.Length)
                    {
                        if (arr[start] >= 0)
                            break;
                        idx += blockSize;
                    }

                    while (idx >= 0)
                    {
                        if (arr[idx] < msSongLength)
                            break;
                        idx -= blockSize;
                    }
                    uint[] arr2 = new uint[(idx + blockSize) - start];
                    Array.Copy(arr, start, arr2, 0, arr2.Length - start);
                    ((QbItemInteger)a.Items[0]).Values = arr2;
                }
            }

            a.Root.AlignPointers();
        }
示例#16
0
 private void setDeathDrain(QbItemArray ar, NotesMarker[] markers)
 {
     if (ar.Items.Count != 0 && ar.Items[0].QbItemType == QbItemType.ArrayStruct)
     {
         foreach (QbItemBase qib in ar.Items[0].Items)
         {
             QbItemStruct hdr = qib as QbItemStruct;
             if (qib != null && hdr.ItemCount == 2 && hdr.Items[0].QbItemType == QbItemType.StructItemInteger && hdr.Items[1].QbItemType == QbItemType.StructItemQbKey)
             {
                 if (((QbItemQbKey)hdr.Items[1]).Values[0] == QbKey.Create("boss_battle_begin_deathlick"))
                     ((QbItemInteger)hdr.Items[0]).Values[0] = Math.Max((uint)this.Length - 11000, (uint)0); //10000 can be read from DeathLick in guitar_battle.qb
             }
         }
     }
 }
示例#17
0
        private void replaceQbItems(QbItemArray a, int[] items, bool split, int splitBy)
        {
            a.Items.Clear();

            //no items to add
            if (items.Length == 0)
            {
                QbItemFloats f = new QbItemFloats(a.Root);
                f.Create(QbItemType.Floats);
                a.AddItem(f);
                a.Root.AlignPointers();
            }
            else
            {
                if (!split)
                {
                    //add array to parent as one large array
                    QbItemInteger qi = new QbItemInteger(a.Root);
                    qi.Create(QbItemType.ArrayInteger);
                    qi.Values = convertIntArrayToUIntArray(items);
                    a.AddItem(qi);
                    a.Root.AlignPointers();
                }
                else
                {
                    //split array down in to blocks of <splitBy>
                    QbItemInteger qi;
                    QbItemArray aa = new QbItemArray(a.Root);
                    aa.Create(QbItemType.ArrayArray);
                    uint[] uints;
                    a.AddItem(aa);
                    a.Root.AlignPointers();

                    for (int i = 0; i < items.Length; i += splitBy)
                    {
                        qi = new QbItemInteger(a.Root);
                        qi.Create(QbItemType.ArrayInteger);
                        uints = new uint[splitBy];
                        for (int j = 0; j < splitBy; j++)
                            uints[j] = (uint)items[i + j];
                        qi.Values = uints;
                        aa.AddItem(qi);
                        a.Root.AlignPointers();
                    }

                }
            }
        }
示例#18
0
 private void replaceQbItems(QbItemArray a, int[] items, bool split)
 {
     replaceQbItems(a, items, split, 3);
 }