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);
}