public static VLTBaseType CloneValue(Database database, VLTBaseType originalValue, VltClass vltClass, VltClassField vltClassField, VltCollection vltCollection) { var newValue = (originalValue is VLTArrayType) ? TypeRegistry.CreateInstance(database.Options.GameId, vltClass, vltClassField, vltCollection) : TypeRegistry.ConstructInstance(TypeRegistry.ResolveType(database.Options.GameId, vltClassField.TypeName), vltClass, vltClassField, vltCollection); if (originalValue is VLTArrayType array) { var newArray = (VLTArrayType)newValue; newArray.Capacity = array.Capacity; newArray.ItemAlignment = vltClassField.Alignment; newArray.FieldSize = vltClassField.Size; newArray.Items = array.Items.Select(i => CloneValue(database, i, vltClass, vltClassField, vltCollection)).ToList(); return(newArray); } switch (originalValue) { case PrimitiveTypeBase primitiveTypeBase: var convertible = primitiveTypeBase.GetValue(); if (convertible != null) { ((PrimitiveTypeBase)newValue).SetValue(convertible); } return(newValue); default: return(CloneObjectWithReflection(originalValue, newValue, vltClass, vltClassField, vltCollection)); } }
private static VLTBaseType CloneObjectWithReflection(VLTBaseType originalValue, VLTBaseType newValue, VltClass vltClass, VltClassField vltClassField, VltCollection vltCollection) { PropertyInfo[] properties = originalValue.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(p => p.SetMethod?.IsPublic ?? false) .ToArray(); foreach (var propertyInfo in properties) { if (propertyInfo.PropertyType.IsSubclassOf(typeof(VLTBaseType))) { propertyInfo.SetValue(newValue, CloneObjectWithReflection( propertyInfo.GetValue(originalValue) as VLTBaseType, Activator.CreateInstance(propertyInfo.PropertyType, vltClass, vltClassField, vltCollection) as VLTBaseType, vltClass, vltClassField, vltCollection)); } else if (propertyInfo.PropertyType == typeof(string)) { propertyInfo.SetValue(newValue, new string(propertyInfo.GetValue(originalValue) as string)); } else if (propertyInfo.PropertyType.IsPrimitive || propertyInfo.PropertyType.IsEnum) { propertyInfo.SetValue(newValue, propertyInfo.GetValue(originalValue)); } else if (propertyInfo.PropertyType.IsArray && propertyInfo.GetValue(originalValue) != null) { propertyInfo.SetValue(newValue, ((Array)propertyInfo.GetValue(originalValue)).Clone()); } } return(newValue); }
public override void SetValue(object component, object value) { //if (value != GetEffectiveValue()) //{ // Messenger.Default.Send(new SetChangeStatusMessage(true)); //} switch (_value) { case PrimitiveTypeBase ptb: ptb.SetValue((IConvertible)value); break; case IStringValue sv: sv.SetString((string)value); break; case VLTArrayType at: at.Items = (VLTBaseType[])value; break; default: _value = (VLTBaseType)value; break; } _collection.DataRow[_classField.Key] = _value; }
public ArrayItemProperty(VLTCollection collection, VLTClassField field, VLTArrayType array, VLTBaseType item) : base(array.GetType(), $"[{Array.IndexOf(array.Items, item)}]", array.ItemType) { _collection = collection; _field = field; _array = array; _item = item; }
public override void ReadPointerData(Vault vault, BinaryReader br) { br.BaseStream.Position = _definitionsPtr; for (int i = 0; i < NumDefinitions; i++) { AttribDefinition64 definition = new AttribDefinition64(); definition.Read(vault, br); VltClassField field = new VltClassField( definition.Key, HashManager.ResolveVLT(definition.Key), HashManager.ResolveVLT(definition.Type), definition.Flags, definition.Alignment, definition.Size, definition.MaxCount, definition.Offset); Class.Fields.Add(definition.Key, field); //VltClassField field = new VltClassField(); //field.Key = definition.Key; //field.Name = HashManager.ResolveVLT(definition.Key); //field.TypeName = HashManager.ResolveVLT(definition.Type); //field.Flags = definition.Flags; //field.Size = definition.Size; //field.MaxCount = definition.MaxCount; //field.Offset = definition.Offset; //field.Alignment = definition.Alignment; //Class.Fields.Add(definition.Key, field); } if (_staticDataPtr != 0) { br.BaseStream.Position = _staticDataPtr; foreach (VltClassField staticField in Class.StaticFields) { br.AlignReader(staticField.Alignment); VLTBaseType staticData = TypeRegistry.CreateInstance(vault.Database.Options.GameId, Class, staticField, null); staticData.Read(vault, br); staticField.StaticValue = staticData; } } foreach (var staticField in Class.StaticFields) { if (staticField.StaticValue is IPointerObject pointerObject) { pointerObject.ReadPointerData(vault, br); } } vault.Database.AddClass(Class); }
public override void ReadPointerData(Vault vault, BinaryReader br) { if (_layoutPointer != 0) { br.BaseStream.Position = _layoutPointer; foreach (var baseField in Collection.Class.BaseFields) { br.AlignReader(baseField.Alignment); VLTBaseType data = TypeRegistry.CreateInstance(vault.Database.Options.GameId, Collection.Class, baseField, Collection); long startPos = br.BaseStream.Position; data.Read(vault, br); long endPos = br.BaseStream.Position; if (!(data is VLTArrayType)) { Debug.Assert(endPos - startPos == baseField.Size); } //Collection.Data[baseField.Name] = data; Collection.SetRawValue(baseField.Name, data); } } foreach (var entry in _entries) { var optionalField = Collection.Class[entry.Key]; if ((optionalField.Flags & DefinitionFlags.IsStatic) != 0) { throw new Exception("Congratulations. You have successfully broken this library. Please consult with your doctor for further instructions."); } if (entry.InlineData is VLTAttribType attribType) { attribType.ReadPointerData(vault, br); Collection.SetRawValue(optionalField.Name, attribType.Data); //Collection.Data[optionalField.Name] = attribType.Data; } else { Collection.SetRawValue(optionalField.Name, entry.InlineData); //Collection.Data[optionalField.Name] = entry.InlineData; } } foreach (var dataEntry in Collection.GetData()) { if (dataEntry.Value is IPointerObject pointerObject) { pointerObject.ReadPointerData(vault, br); } } }
/// <summary> /// Updates or creates a mapping in the data dictionary between <paramref name="key"/> and <paramref name="data"/>. /// </summary> /// <param name="key">The mapping key. (Typically the VLT field name.)</param> /// <param name="data">The mapping value.</param> public void SetRawValue(string key, VLTBaseType data) { if (Class.HasField(key)) { Data[key] = data; } else { throw new KeyNotFoundException($"Class '{Class.Name}' does not have field '{key}'"); } }
private void f(object A_0, EventArgs A_1) { if (this.tvFields.SelectedNode != null) { TreeNode selectedNode = this.tvFields.SelectedNode; if (selectedNode.Tag is VLTBaseType && !(selectedNode.Tag is VLTArrayType)) { VLTBaseType bb = selectedNode.Tag as VLTBaseType; Clipboard.SetDataObject(string.Format("{0}:0x{1}", bb.isVltOffset ? "vlt" : "bin", bb.ui1)); } } }
private object BaseTypeToData(VLTBaseType baseType) { // if we have a primitive or string value, return that // if we have an array, return a list where each item in the array has been converted (recursion FTW) // otherwise, just return the original data return(baseType switch { PrimitiveTypeBase ptb => ptb.GetValue(), IStringValue sv => sv.GetString(), VLTArrayType array => array.Items.Select(BaseTypeToData).ToList(), _ => baseType });
/// <summary> /// Updates or creates a mapping in the data dictionary between <paramref name="key"/> and <paramref name="data"/>. /// </summary> /// <param name="key">The mapping key. (Typically the VLT field name.)</param> /// <param name="data">The mapping value.</param> public void SetDataValue <T>(string key, T data) { if (Class.HasField(key)) { if (HasEntry(key)) { SetRawValue(key, DataToBaseType(Class[key], GetRawValue(key), data)); } else { VLTBaseType rawValue = TypeRegistry.CreateInstance(Vault.Database.Options.GameId, Class, Class[key], this); SetRawValue(key, DataToBaseType(Class[key], rawValue, data)); } } else { throw new KeyNotFoundException($"Class '{Class.Name}' does not have field '{key}'"); } }
/* * private void i( object A_0, EventArgs A_1 ) * { * if( this.tv.SelectedNode != null ) * { * TreeNode selectedNode = this.tv.SelectedNode; * if( selectedNode.Tag is UnknownDE ) * { * // Right-clicked "Database", selected "Copy Node Path" * Clipboard.SetDataObject( "" ); * } * else if( selectedNode.Tag is VLTClass ) * { * VLTClass dq = selectedNode.Tag as VLTClass; * Clipboard.SetDataObject( HashTracker.getValueForHash( dq.hash ) ); * } * else * { * UnknownDR dr = selectedNode.Tag as UnknownDR; * VLTClass dq2 = dr.dq1; * Clipboard.SetDataObject( HashTracker.getValueForHash( dq2.hash ) + "/" + this.a( dr ) ); * } * } * } */ private void h(object A_0, EventArgs A_1) { if (this.tvFields.SelectedNode != null) { TreeNode selectedNode = this.tvFields.SelectedNode; VLTBaseType bb = selectedNode.Tag as VLTBaseType; if (selectedNode.Parent != null) { VLTBaseType bb2 = selectedNode.Parent.Tag as VLTArrayType; Clipboard.SetDataObject(string.Concat(new object[] { HashTracker.getValueForHash(bb2.ui3), "[", bb.arrayIndex, "]" })); return; } Clipboard.SetDataObject(HashTracker.getValueForHash(bb.ui3)); } }
public VLTFieldProxy(/*EditorSchemaField schemaField, */ VLTCollection collection, VLTClassField classField) : base( classField.Name, null) { //_schemaField = schemaField; _collection = collection; _classField = classField; _value = _collection.DataRow[classField.Key]; object effectiveValue = GetEffectiveValue(); Debug.Assert(effectiveValue != null); if (_classField.IsArray) { PropertyType = ((VLTArrayType)_value).ItemType.MakeArrayType(); } else { PropertyType = effectiveValue.GetType(); } //PropertyType = effectiveValue.GetType(); }
public override void ReadPointerData(Vault vault, BinaryReader br) { if (LayoutPointer != 0) { br.BaseStream.Position = LayoutPointer; foreach (var baseField in Collection.Class.BaseFields) { br.AlignReader(baseField.Alignment); if (br.BaseStream.Position - LayoutPointer != baseField.Offset) { throw new Exception($"trying to read field {baseField.Name} at offset {br.BaseStream.Position - LayoutPointer:X}, need to be at {baseField.Offset:X}"); } VLTBaseType data = TypeRegistry.CreateInstance(vault.Database.Options.GameId, Collection.Class, baseField, Collection); long startPos = br.BaseStream.Position; data.Read(vault, br); long endPos = br.BaseStream.Position; if (data is PrimitiveTypeBase) { br.BaseStream.Position = startPos + baseField.Size; } if (!(data is VLTArrayType) && !(data is PrimitiveTypeBase)) { if (endPos - startPos != baseField.Size) { throw new Exception($"read {endPos - startPos} bytes, needed to read {baseField.Size}"); } } Collection.SetRawValue(baseField.Name, data); } } foreach (var entry in Entries) { var optionalField = Collection.Class[entry.Key]; if ((optionalField.Flags & DefinitionFlags.IsStatic) != 0) { throw new Exception("Encountered static field as an entry. Processing will not continue."); } if ((optionalField.Flags & DefinitionFlags.HasHandler) != 0) { Debug.Assert((entry.NodeFlags & NodeFlagsEnum.HasHandler) == NodeFlagsEnum.HasHandler); } else { Debug.Assert((entry.NodeFlags & NodeFlagsEnum.HasHandler) == 0); } if ((optionalField.Flags & DefinitionFlags.Array) != 0) { Debug.Assert((entry.NodeFlags & NodeFlagsEnum.IsArray) == NodeFlagsEnum.IsArray); } else { Debug.Assert((entry.NodeFlags & NodeFlagsEnum.IsArray) == 0); } if (entry.InlineData is VLTAttribType attribType) { Debug.Assert((entry.NodeFlags & NodeFlagsEnum.IsInline) == 0); attribType.ReadPointerData(vault, br); Collection.SetRawValue(optionalField.Name, attribType.Data); } else { Debug.Assert((entry.NodeFlags & NodeFlagsEnum.IsInline) == NodeFlagsEnum.IsInline); Collection.SetRawValue(optionalField.Name, entry.InlineData); } } foreach (var dataEntry in Collection.GetData()) { if (dataEntry.Value is IPointerObject pointerObject) { pointerObject.ReadPointerData(vault, br); } } }
// This is where our problems with Carbon and up appear to stem from. public void a(RowRecord A_0, UnknownB0 A_1) { BinaryReader binaryReader = new BinaryReader(A_1.ms1); BinaryReader binaryReader2 = new BinaryReader(A_1.ms2); UnknownDR dr = new UnknownDR(this.vltClass.classRecord.i2); UnknownA8 a = A_1.a(VLTOtherValue.TABLE_END) as UnknownA8; int num; if (a.genht1.ContainsKey(A_0.position)) { num = a.genht1[A_0.position].i2; } else { // NOTE: THIS IS A BUG, IT SHOULD NOT HAPPEN. // The ONLY reason I'm checking ContainsKey instead of using exception handling, // is because exception handling causes huge slowdowns in Visual Studio debugging. if (BuildConfig.DEBUG) { ++numFails; Console.WriteLine("VLTClass.a(): num fail (num" + numFails + ",b" + b8Fails + ")"); } return; } dr.b01 = A_1; dr.dq1 = this.vltClass; dr.c1 = A_0; for (int i = 0; i < this.vltClass.classRecord.i2; ++i) { VLTClass.aclz1 a2 = this.vltClass.fields[i]; BinaryReader binaryReader3; if (!a2.c()) { binaryReader3 = binaryReader; binaryReader3.BaseStream.Seek(num + a2.us1, SeekOrigin.Begin); } else { binaryReader3 = null; for (int j = 0; j < A_0.i1; ++j) { if (A_0.caa1[j].hash == a2.hash) { if (A_0.caa1[j].a()) { binaryReader3 = binaryReader2; binaryReader3.BaseStream.Seek(A_0.caa1[j].position, SeekOrigin.Begin); } else { binaryReader3 = binaryReader; binaryReader3.BaseStream.Seek(a.genht1[A_0.caa1[j].position].i2, SeekOrigin.Begin); } } } if (binaryReader3 == null) { continue; } } Type type = TypeMap.instance.getTypeForKey(a2.ui2); if (type == null) { type = typeof(VLTRawType); } VLTBaseType bb; if (a2.isArray()) { bb = new VLTArrayType(a2, type); } else { bb = VLTBaseType.a(type); bb.size = a2.len; if (bb is VLTRawType) { (bb as VLTRawType).len = a2.len; } } bb.ui1 = (uint)binaryReader3.BaseStream.Position; bb.isVltOffset = (binaryReader3 == binaryReader2); bb.typeHash = a2.ui2; bb.ui3 = a2.hash; bb.dr1 = dr; bb.read(binaryReader3); dr.a(i, bb); } this.drList.Add(dr); }
/* * private void e( object A_0, EventArgs A_1 ) * { * if( this.tvFields.SelectedNode != null ) * { * TreeNode treeNode = this.tvFields.SelectedNode; * if( treeNode.Parent != null ) * { * treeNode = treeNode.Parent; * } * VLTBaseType bb = treeNode.Tag as VLTBaseType; * this.a( bb.dr1, bb.ui3 ); * } * } */ // TODO: opt private void tv_AfterSelect(object A_0, TreeViewEventArgs A_1) { object tag = A_1.Node.Tag; if (tag is VLTClass) { this.classGrid.Visible = true; this.pnlData.Visible = false; VLTClass dq = tag as VLTClass; DataSet dataSet = new DataSet("VLT"); DataTable dataTable = dataSet.Tables.Add("Fields"); dataTable.Columns.Add("Name", typeof(string)); dataTable.Columns.Add("Type", typeof(string)); dataTable.Columns.Add("Length", typeof(ushort)); dataTable.Columns.Add("Count", typeof(short)); foreach (VLTClass.aclz1 a in dq) { DataRow dataRow = dataTable.NewRow(); dataRow[0] = HashTracker.getValueForHash(a.hash); dataRow[1] = HashTracker.getValueForHash(a.ui2); dataRow[2] = a.len; dataRow[3] = a.count; dataTable.Rows.Add(dataRow); } this.classGrid.DataSource = dataSet; this.classGrid.DataMember = "Fields"; // This gets rid of the extra row in the table that appears when viewing a root node (e.x. junkman, pvehicle) CurrencyManager currencyManager = (CurrencyManager)this.BindingContext[dataSet, "Fields"]; ((DataView)currencyManager.List).AllowNew = false; ((DataView)currencyManager.List).AllowEdit = false; ((DataView)currencyManager.List).AllowDelete = false; UnknownA8 a2 = dq.b01.a(VLTOtherValue.TABLE_END) as UnknownA8; this.classGrid.Update(); } else if (tag is UnknownDR) { this.lblFieldType.Text = ""; this.lblFieldOffset.Text = ""; this.dataGrid.DataSource = null; this.dataGrid.Update(); this.classGrid.Visible = false; this.pnlData.Visible = true; string text = ""; string text2 = ""; TreeNode treeNode = null; if (this.tvFields.SelectedNode != null) { if (this.tvFields.SelectedNode.Parent != null && this.tvFields.SelectedNode.Parent.Tag == null) { text = this.tvFields.SelectedNode.Parent.Text; text2 = this.tvFields.SelectedNode.Text; } else { text = this.tvFields.SelectedNode.Text; } } UnknownDR dr = tag as UnknownDR; VLTClass dq2 = dr.dq1; this.tvFields.BeginUpdate(); this.tvFields.Nodes.Clear(); int num = 0; foreach (VLTClass.aclz1 a3 in dq2) { VLTBaseType bb = dr.bba1[num++]; if (!a3.c() || dr.booa1[num - 1]) { if (a3.isArray()) { VLTArrayType m = bb as VLTArrayType; string text3 = string.Concat(new object[] { HashTracker.getValueForHash(a3.hash), " [", m.getMaxEntryCount(), "/", m.getCurrentEntryCount(), "]" }); TreeNode treeNode2 = this.tvFields.Nodes.Add(text3); treeNode2.Tag = bb; for (int i = 0; i < m.getMaxEntryCount(); ++i) { TreeNode treeNode3 = treeNode2.Nodes.Add("[" + i + "]"); treeNode3.Tag = m.genlist[i]; if (treeNode2.Text == text && treeNode3.Text == text2) { treeNode = treeNode3; } } if (treeNode2.Text == text && treeNode == null) { treeNode = treeNode2; } } else { TreeNode treeNode4 = this.tvFields.Nodes.Add(HashTracker.getValueForHash(a3.hash)); treeNode4.Tag = bb; if (treeNode4.Text == text) { treeNode = treeNode4; } } } } if (this.tvFields.Nodes.Count > 0) { if (treeNode == null) { this.tvFields.SelectedNode = this.tvFields.Nodes[0]; } else { this.tvFields.SelectedNode = treeNode; } } this.tvFields.EndUpdate(); UnknownA8 a4 = dr.b01.a(VLTOtherValue.TABLE_END) as UnknownA8; } else { this.classGrid.Visible = false; this.pnlData.Visible = false; } }
private void tv_AfterSelect(object sender, TreeViewEventArgs e) { object tag = e.Node.Tag; if (tag is VLTClass) { this.classGrid.Visible = true; this.pnlData.Visible = false; VLTClass dq = tag as VLTClass; if (!this.classGridDataSet.Tables.Contains(dq.classHash.ToString())) { DataTable dataTable = this.classGridDataSet.Tables.Add(dq.classHash.ToString()); dataTable.Columns.Add("Name", typeof(string)); dataTable.Columns.Add("Type", typeof(string)); dataTable.Columns.Add("Length", typeof(ushort)); dataTable.Columns.Add("Count", typeof(short)); foreach (VLTClass.aclz1 a in dq) { /* * object[] rowData = * { * HashTracker.getValueForHash( a.hash ), * HashTracker.getValueForHash( a.ui2 ), * a.len, * a.count * }; * dataTable.Rows.Add( rowData );*/ dataTable.Rows.Add(new object[] { HashTracker.getValueForHash(a.hash), HashTracker.getValueForHash(a.ui2), a.len, a.count }); /* * DataRow dataRow = dataTable.NewRow(); * dataRow[0] = HashTracker.getValueForHash( a.hash ); * dataRow[1] = HashTracker.getValueForHash( a.ui2 ); * dataRow[2] = a.len; * dataRow[3] = a.count; * dataTable.Rows.Add( dataRow );*/ } } this.classGrid.DataMember = dq.classHash.ToString(); //this.classGrid.Columns["Name"].Width = 80; //this.classGrid.Columns["Type"].Width = 150; //this.classGrid.Columns["Length"].Width = 60; //this.classGrid.Columns["Count"].Width = 60; this.classGrid.Update(); } else if (tag is UnknownDR) // TODO { this.lblFieldType.Text = ""; this.lblFieldOffset.Text = ""; this.dataGrid.DataSource = null; this.dataGrid.Update(); this.classGrid.Visible = false; this.pnlData.Visible = true; string text = ""; string text2 = ""; TreeNode treeNode = null; if (this.tvFields.SelectedNode != null) { if (this.tvFields.SelectedNode.Parent != null && this.tvFields.SelectedNode.Parent.Tag == null) { text = this.tvFields.SelectedNode.Parent.Text; text2 = this.tvFields.SelectedNode.Text; } else { text = this.tvFields.SelectedNode.Text; } } UnknownDR dr = tag as UnknownDR; VLTClass dq2 = dr.dq1; this.tvFields.BeginUpdate(); this.tvFields.Nodes.Clear(); int num = 0; foreach (VLTClass.aclz1 a3 in dq2) { VLTBaseType bb = dr.bba1[num++]; if (!a3.c() || dr.booa1[num - 1]) { if (a3.isArray()) { VLTArrayType m = bb as VLTArrayType; string text3 = string.Concat(new object[] { HashTracker.getValueForHash(a3.hash), " [", m.getMaxEntryCount(), "/", m.getCurrentEntryCount(), "]" }); TreeNode treeNode2 = this.tvFields.Nodes.Add(text3); treeNode2.Tag = bb; for (int i = 0; i < m.getMaxEntryCount(); ++i) { TreeNode treeNode3 = treeNode2.Nodes.Add("[" + i + "]"); treeNode3.Tag = m.genlist[i]; if (treeNode2.Text == text && treeNode3.Text == text2) { treeNode = treeNode3; } } if (treeNode2.Text == text && treeNode == null) { treeNode = treeNode2; } } else { TreeNode treeNode4 = this.tvFields.Nodes.Add(HashTracker.getValueForHash(a3.hash)); treeNode4.Tag = bb; if (treeNode4.Text == text) { treeNode = treeNode4; } } } } if (this.tvFields.Nodes.Count > 0) { if (treeNode == null) { this.tvFields.SelectedNode = this.tvFields.Nodes[0]; } else { this.tvFields.SelectedNode = treeNode; } } this.tvFields.EndUpdate(); } else { this.classGrid.Visible = false; this.pnlData.Visible = false; } }
private void tvFields_AfterSelect(object sender, TreeViewEventArgs e) { object tag = e.Node.Tag; if (tag is VLTBaseType && !(tag is VLTArrayType)) { VLTBaseType bb = tag as VLTBaseType; //bb.l(); // MW: TODO: What is l() supposed to be? DataSet dataSet = new DataSet("DataItem"); DataTable dataTable = dataSet.Tables.Add("Values"); dataTable.Columns.Add("Name", typeof(string)); dataTable.Columns.Add("Value", typeof(string)); Type type = bb.GetType(); FieldInfo[] fields = type.GetFields(); foreach (FieldInfo fieldInfo in fields) { object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(DataValueAttribute), false); if (customAttributes != null && customAttributes.Length == 1 && customAttributes[0] is DataValueAttribute) { DataValueAttribute dataValueAttribute = customAttributes[0] as DataValueAttribute; DataRow dataRow = dataTable.NewRow(); dataRow[0] = dataValueAttribute.Name; object value = fieldInfo.GetValue(bb); if (value == null) { dataRow[1] = "(null)"; } else { if (dataValueAttribute.Hex) { dataRow[1] = string.Format("0x{0:x}", value); } else { dataRow[1] = value.ToString(); } } dataTable.Rows.Add(dataRow); } } this.dataGrid.DataSource = dataSet; this.dataGrid.DataMember = "Values"; this.lblFieldType.Text = "Type: " + HashTracker.getValueForHash(bb.typeHash); /* * if( BuildConfig.DEBUG ) * { * this.writeToConsole( "bb.GetType(): " + type.ToString() ); // Here, we're getting the proper type! Great! * this.writeToConsole( "bb.j(): " + string.Format( "0x{0:x}", bb.ui2 ) ); // Here, we're derping! OMG! * }*/ UnknownBA ba = bb.dr1.b01.a(VLTOtherValue.VLTMAGIC) as UnknownBA; string text = ba.sa1[0]; this.lblFieldOffset.Text = string.Format("Offset: {0}:0x{1:x} ({2})", bb.isVltOffset ? "vlt" : "bin", bb.ui1, text); this.dataGrid.Update(); } else { this.lblFieldType.Text = ""; this.lblFieldOffset.Text = ""; this.dataGrid.DataSource = null; this.dataGrid.Update(); } }
public T GetDataValue <T>(string key) { VLTBaseType originalData = GetRawValue(key); return((T)BaseTypeToData(originalData)); }
private object ConvertDataValueToSerializedValue(string directory, VltCollection collection, VltClassField field, VLTBaseType dataPairValue) { switch (dataPairValue) { case IStringValue stringValue: return(stringValue.GetString()); case PrimitiveTypeBase ptb: return(ptb.GetValue()); case BaseBlob blob: return(ProcessBlob(directory, collection, field, blob)); case VLTArrayType array: { var listType = typeof(List <>); var listGenericType = ResolveType(array.ItemType); var constructedListType = listType.MakeGenericType(listGenericType); var instance = (IList)Activator.CreateInstance(constructedListType); foreach (var arrayItem in array.Items) { instance.Add(listGenericType.IsPrimitive || listGenericType.IsEnum || listGenericType == typeof(string) ? ConvertDataValueToSerializedValue(directory, collection, field, arrayItem) : arrayItem); } return(new SerializedArrayWrapper { Capacity = array.Capacity, Data = instance }); } default: return(dataPairValue); } }
private void tvFields_AfterSelect(object A_0, TreeViewEventArgs A_1) { object tag = A_1.Node.Tag; if (tag is VLTBaseType && !(tag is VLTArrayType)) { VLTBaseType bb = tag as VLTBaseType; //bb.l(); // MW: TODO: What is l() supposed to be? DataSet dataSet = new DataSet("DataItem"); DataTable dataTable = dataSet.Tables.Add("Values"); dataTable.Columns.Add("Name", typeof(string)); dataTable.Columns.Add("Value", typeof(string)); Type type = bb.GetType(); FieldInfo[] fields = type.GetFields(); foreach (FieldInfo fieldInfo in fields) { object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(DataValueAttribute), false); if (customAttributes != null && customAttributes.Length == 1 && customAttributes[0] is DataValueAttribute) { DataValueAttribute dataValueAttribute = customAttributes[0] as DataValueAttribute; DataRow dataRow = dataTable.NewRow(); dataRow[0] = dataValueAttribute.Name; object value = fieldInfo.GetValue(bb); if (value == null) { dataRow[1] = "(null)"; } else { if (dataValueAttribute.Hex) { dataRow[1] = string.Format("0x{0:x}", value); } else { dataRow[1] = value.ToString(); } } dataTable.Rows.Add(dataRow); } } this.dataGrid.DataSource = dataSet; this.dataGrid.DataMember = "Values"; // This gets rid of the extra row in the table that appears when viewing a sub-node (e.x. junkman --> default) CurrencyManager currencyManager = (CurrencyManager)this.BindingContext[dataSet, "Values"]; ((DataView)currencyManager.List).AllowNew = false; ((DataView)currencyManager.List).AllowEdit = false; ((DataView)currencyManager.List).AllowDelete = false; this.lblFieldType.Text = "Type: " + HashTracker.getValueForHash(bb.typeHash); if (BuildConfig.DEBUG) { this.writeToConsole("bb.GetType(): " + type.ToString()); // Here, we're getting the proper type! Great! this.writeToConsole("bb.j(): " + string.Format("0x{0:x}", bb.typeHash)); // Here, we're derping! OMG! } UnknownBA ba = bb.dr1.b01.a(VLTOtherValue.VLTMAGIC) as UnknownBA; string text = ba.sa1[0]; this.lblFieldOffset.Text = string.Format("Offset: {0}:0x{1:x} ({2})", bb.isVltOffset ? "vlt" : "bin", bb.ui1, text); this.dataGrid.Update(); } else { this.lblFieldType.Text = ""; this.lblFieldOffset.Text = ""; this.dataGrid.DataSource = null; this.dataGrid.Update(); } }
private void classdump() { using (StreamWriter streamWriter = new StreamWriter((new FileInfo(Application.ExecutablePath)).Directory.FullName + "\\temp.cs", false, Encoding.ASCII)) { streamWriter.WriteLine("using System;"); streamWriter.WriteLine("using mwperf;"); streamWriter.WriteLine("namespace mwperf.VLTTables {"); foreach (VLTClass dq in this.av) { string text = this.bThree(HashTracker.getValueForHash(dq.classHash)); if (this.c(text)) { streamWriter.WriteLine("\tnamespace " + text + " {"); streamWriter.WriteLine("\t\tpublic abstract class " + this.bThree(text + "_base") + " {"); foreach (VLTClass.aclz1 a in dq) { string text2 = this.bThree(HashTracker.getValueForHash(a.hash)); if (this.c(text2)) { streamWriter.WriteLine(string.Concat(new string[] { "\t\t\tpublic static VLTOffsetData", a.isArray() ? "[]" : "", " ", text2, ";" })); } } streamWriter.WriteLine("\t\t}"); foreach (UnknownDR dr in dq.dqb1) { int num = 0; string text3 = this.bThree(HashTracker.getValueForHash(dr.c1.hash)); if (this.c(text3)) { streamWriter.WriteLine(string.Concat(new string[] { "\t\tpublic class ", text3, " : ", text, "_base {" })); streamWriter.WriteLine("\t\t\tstatic " + text3 + "() {"); foreach (VLTClass.aclz1 a2 in dq) { VLTBaseType bb = dr.bba1[num++]; if (!a2.c() || dr.booa1[num - 1]) { string text4 = this.bThree(HashTracker.getValueForHash(a2.hash)); if (this.c(text4)) { streamWriter.Write("\t\t\t\t" + text4 + " = "); if (a2.isArray()) { VLTArrayType m = bb as VLTArrayType; streamWriter.WriteLine("new VLTOffsetData[] {"); for (int i = 0; i < m.getMaxEntryCount(); ++i) { bb = m.genlist[i]; streamWriter.WriteLine(string.Concat(new string[] { "\t\t\t\t\tnew VLTOffsetData(VLTOffsetType.", bb.isVltOffset ? "Vlt" : "Bin", ", ", string.Format("0x{0:x}", bb.ui1), ")", (i != (int)(m.getMaxEntryCount() - 1)) ? "," : "" })); } streamWriter.WriteLine("\t\t\t\t};"); } else { streamWriter.WriteLine(string.Concat(new string[] { "new VLTOffsetData(VLTOffsetType.", bb.isVltOffset ? "Vlt" : "Bin", ", ", string.Format("0x{0:x}", bb.ui1), ");" })); } } } } streamWriter.WriteLine("\t\t\t}"); streamWriter.WriteLine("\t\t}"); } } streamWriter.WriteLine("\t}"); } } streamWriter.WriteLine("}"); } }
public CollectionReferenceInfo(VLTBaseType source, VltCollection destination) { Source = source; Destination = destination; }
public void a(int A_0, VLTBaseType A_1) { this.booa1[A_0] = true; this.bba1[A_0] = A_1; }