/// <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() { QbItemScript sc = new QbItemScript(this.Root); sc.Create(this.QbItemType); if (this.ItemQbKey != null) { sc.ItemQbKey = this.ItemQbKey.Clone(); } byte[] bi = new byte[this.ScriptData.Length]; for (int i = 0; i < bi.Length; i++) { bi[i] = this.ScriptData[i]; } sc.ScriptData = bi; sc.ItemCount = this.ItemCount; sc.Unknown = this.Unknown; return(sc); }
private void ScriptEditor_Load(object sender, EventArgs e) { if (this.DesignMode) return; try { _qbItem = (base.QbItem as QbItemScript); if (_qbItem == null) throw new Exception("Error"); eiItemQbKey.SetData(new GenericQbItem("Item QB Key", _qbItem.ItemQbKey, typeof(string), false, false, QbItemType.SectionScript, "ItemQbKey")); eiUnknown.SetData(new GenericQbItem("Unknown", _qbItem.Unknown, typeof(byte[]), false, false, QbItemType.SectionScript, "Unknown")); int w = (eiItemQbKey.LabelWidth > eiUnknown.LabelWidth ? eiItemQbKey.LabelWidth : eiUnknown.LabelWidth) + 6; eiItemQbKey.TextBoxLeft = w; eiUnknown.TextBoxLeft = w; txtScript.Text = bytesToHexAsciiString(_qbItem.ScriptData); _preventUpdate = false; loadStringList(); } catch (Exception ex) { base.ShowException("Script Load Item Error", ex); } }
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 }
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 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 }
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); }
/// <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() { QbItemScript sc = new QbItemScript(this.Root); sc.Create(this.QbItemType); if (this.ItemQbKey != null) sc.ItemQbKey = this.ItemQbKey.Clone(); byte[] bi = new byte[this.ScriptData.Length]; for (int i = 0; i < bi.Length; i++) bi[i] = this.ScriptData[i]; sc.ScriptData = bi; sc.ItemCount = this.ItemCount; sc.Unknown = this.Unknown; return sc; }