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); }
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; QbItemType floatsType; uint floatsValue; bool is3d; for (int i = 0; i < base.ItemCount; i++) { if (base.StreamPos(br) != base.Pointers[i]) //pointer test throw new ApplicationException(QbFile.FormatBadPointerExceptionMessage(this, base.StreamPos(br), base.Pointers[i])); floatsValue = br.ReadUInt32(this.Root.PakFormat.EndianType); floatsType = this.Root.PakFormat.GetQbItemType(floatsValue); is3d = (type == QbItemType.SectionFloatsX3 || type == QbItemType.StructItemFloatsX3 || type == QbItemType.ArrayFloatsX3); switch (floatsType) { case QbItemType.Floats: qib = new QbItemFloats(this.Root, is3d); break; default: throw new ApplicationException(string.Format("Location 0x{0}: Not a float type 0x{1}", (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0'), floatsValue.ToString("X").PadLeft(8, '0'))); } qib.Construct(br, floatsType); AddItem(qib); base.ConstructEnd(br); } }
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; }
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(); } } } }