static TreeNode BuildInfoNode(uint rawEMsg) { var eMsg = MsgUtil.GetMsg(rawEMsg); var eMsgExplorer = new TreeNodeObjectExplorer("EMsg", eMsg); return(new TreeNode("Info", new[] { eMsgExplorer.TreeNode, new TreeNodeObjectExplorer("Is Protobuf", MsgUtil.IsProtoBuf(rawEMsg)).TreeNode })); }
TreeNode CreateTreeNodeCore(bool displayUnsetFields) { var configuration = new TreeNodeObjectExplorerConfiguration { ShowUnsetFields = displayUnsetFields }; using var stream = item.OpenStream(); var rawEMsg = PeekUInt(stream); var node = BuildInfoNode(rawEMsg); node.Expand(); var header = ReadHeader(rawEMsg, stream); node.Nodes.Add(new TreeNodeObjectExplorer("Header", header, configuration).TreeNode); var body = ReadBody(rawEMsg, stream, header); var bodyNode = new TreeNodeObjectExplorer("Body", body, configuration).TreeNode; node.Nodes.Add(bodyNode); var payload = ReadPayload(stream); if (payload != null && payload.Length > 0) { node.Nodes.Add(new TreeNodeObjectExplorer("Payload", payload, configuration).TreeNode); } if (Specializations != null) { var objectsToSpecialize = new[] { body }; while (objectsToSpecialize.Any()) { var specializations = objectsToSpecialize.SelectMany(o => Specializations.SelectMany(x => x.ReadExtraObjects(o))); if (!specializations.Any()) { break; } bodyNode.Collapse(ignoreChildren: true); var extraNodes = specializations.Select(x => new TreeNodeObjectExplorer(x.Key, x.Value, configuration).TreeNode).ToArray(); node.Nodes.AddRange(extraNodes); // Let the specializers examine any new message objects. objectsToSpecialize = specializations.Select(x => x.Value).ToArray(); } } return(node); }
TreeNode CreateTreeNodeCore() { var node = new TreeNode(); using (var stream = item.OpenStream()) { var rawEMsg = PeekUInt(stream); node.Nodes.Add(BuildInfoNode(rawEMsg)); var header = ReadHeader(rawEMsg, stream); node.Nodes.Add(new TreeNodeObjectExplorer("Header", header).TreeNode); var body = ReadBody(rawEMsg, stream, header); var bodyNode = new TreeNodeObjectExplorer("Body", body).TreeNode; node.Nodes.Add(bodyNode); var payload = ReadPayload(stream); if (payload != null && payload.Length > 0) { node.Nodes.Add(new TreeNodeObjectExplorer("Payload", payload).TreeNode); } if (Specializations != null) { var objectsToSpecialize = new[] { body }; while (objectsToSpecialize.Any()) { var specializations = objectsToSpecialize.SelectMany(o => Specializations.SelectMany(x => x.ReadExtraObjects(o))); if (!specializations.Any()) { break; } bodyNode.Collapse(ignoreChildren: true); var extraNodes = specializations.Select(x => new TreeNodeObjectExplorer(x.Key, x.Value).TreeNode).ToArray(); node.Nodes.AddRange(extraNodes); // Let the specializers examine any new message objects. objectsToSpecialize = specializations.Select(x => x.Value).ToArray(); } } } return node; }
void Initialize() { if (value == null) { SetValueForDisplay("<null>"); return; } var objectType = value.GetType(); if (objectType.IsEnum) { SetValueForDisplay(string.Format("{0:G} ({0:D})", value)); } else if (objectType.IsValueType) { SetValueForDisplay(value.ToString()); } else if (value is string stringValue) { SetValueForDisplay(string.Format("\"{0}\"", value), stringValue); } else if (value is SteamID steamID) { SetValueForDisplay(string.Format("{0} ({1})", steamID.Render(steam3: true), steamID.ConvertToUInt64())); } else if (value is byte[] data) { if (data.Length == 0) { SetValueForDisplay("byte[ 0 ]"); } else if (data.Length > MaxDataLengthForDisplay) { SetValueForDisplay(string.Format("byte[ {0} ]: Length exceeded {1} bytes! Value not shown - right-click to save.", data.Length, MaxDataLengthForDisplay)); } else { var hexadecimalValue = data.Aggregate(new StringBuilder(), (str, val) => str.Append(val.ToString("X2"))).ToString(); SetValueForDisplay(hexadecimalValue); } } else if (value is KeyValue kv) { if (kv.Children.Count > 0) { var children = new List <TreeNode>(); foreach (var child in kv.Children) { children.Add(new TreeNodeObjectExplorer(child.Name, child, configuration).TreeNode); } SetValueForDisplay(null, childNodes: children.ToArray()); } else { SetValueForDisplay(string.Format("\"{0}\"", kv.Value), kv.Value); } } else if (value is CMsgIPAddress msgIpAddr) { if (msgIpAddr.ShouldSerializev4()) { byte[] addrBytes = BitConverter.GetBytes(msgIpAddr.v4); Array.Reverse(addrBytes); SetValueForDisplay(new IPAddress(addrBytes).ToString()); } else if (msgIpAddr.ShouldSerializev6()) { SetValueForDisplay(new IPAddress(msgIpAddr.v6).ToString()); } else { SetValueForDisplay("<null>"); } } else if (objectType.IsDictionaryType()) { var childNodes = new List <TreeNode>(); var dictionary = value as IDictionary; foreach (DictionaryEntry entry in dictionary) { var childName = string.Format("[ {0} ]", entry.Key.ToString()); var childObjectExplorer = new TreeNodeObjectExplorer(childName, entry.Value, configuration); childNodes.Add(childObjectExplorer.TreeNode); } SetValueForDisplay(null, childNodes: childNodes.ToArray()); } else if (objectType.IsEnumerableType()) { Type innerType = null; var index = 0; var childNodes = new List <TreeNode>(); foreach (var childObject in value as IEnumerable) { if (innerType == null) { innerType = childObject.GetType(); } var childName = string.Format("[ {0} ]", index); var childObjectExplorer = new TreeNodeObjectExplorer(childName, childObject, configuration); childNodes.Add(childObjectExplorer.TreeNode); index++; } SetValueForDisplay(string.Format("{0}[ {1} ]", innerType == null ? objectType.Name : innerType.Name, index), childNodes: childNodes.ToArray()); } else { var childNodes = new List <TreeNode>(); var properties = value.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList(); bool valueIsProtobufMsg = value is ProtoBuf.IExtensible; foreach (var property in properties) { var childName = property.Name; var childObject = property.GetValue(value, null); bool valueIsSet = true; if (valueIsProtobufMsg) { if (childObject is IList childObjectList) { // Repeated fields are marshalled as Lists, but aren't "set"/sent if they have no values added. valueIsSet = childObjectList.Count != 0; } else { // For non-repeated fields, look for the "ShouldSerialiez<blah>" method existing and being set to false; var shouldSerializeProp = value.GetType().GetMethod("ShouldSerialize" + property.Name); valueIsSet = shouldSerializeProp == null || (shouldSerializeProp.Invoke(value, null) is bool specified && specified); } } if (valueIsSet || configuration.ShowUnsetFields) { var childConfiguration = configuration; childConfiguration.IsUnsetField = !valueIsSet; var childObjectExplorer = new TreeNodeObjectExplorer(childName, childObject, childConfiguration); childNodes.Add(childObjectExplorer.TreeNode); } } SetValueForDisplay(null, childNodes: childNodes.ToArray()); } }
void Initialize() { if (value == null) { SetValueForDisplay("<null>"); return; } var objectType = value.GetType(); if (objectType.IsEnum) { SetValueForDisplay(string.Format("{0:G} ({0:D})", value)); } else if (objectType.IsValueType) { SetValueForDisplay(value.ToString()); } else if (value is string) { SetValueForDisplay(string.Format("\"{0}\"", value), (string)value); } else if (value is SteamID) { var steamID = (SteamID)value; SetValueForDisplay(string.Format("{0} ({1})", steamID.Render(steam3: true), steamID.ConvertToUInt64())); } else if (value is byte[]) { var data = (byte[])value; if (data.Length == 0) { SetValueForDisplay("byte[ 0 ]"); } else if (data.Length > MaxDataLengthForDisplay) { SetValueForDisplay(string.Format("byte[ {0} ]: Length exceeded {1} bytes! Value not shown - right-click to save.", data.Length, MaxDataLengthForDisplay)); } else { var hexadecimalValue = data.Aggregate(new StringBuilder(), (str, val) => str.Append(val.ToString("X2"))).ToString(); SetValueForDisplay(hexadecimalValue); } } else if (value is KeyValue) { var kv = (KeyValue)value; if (kv.Children.Count > 0) { var children = new List<TreeNode>(); foreach (var child in kv.Children) { children.Add(new TreeNodeObjectExplorer(child.Name, child).TreeNode); } SetValueForDisplay(null, childNodes: children.ToArray()); } else { SetValueForDisplay(string.Format("\"{0}\"", kv.Value), kv.Value); } } else if (objectType.IsDictionaryType()) { var childNodes = new List<TreeNode>(); var dictionary = value as IDictionary; foreach (DictionaryEntry entry in dictionary) { var childName = string.Format("[ {0} ]", entry.Key.ToString()); var childObjectExplorer = new TreeNodeObjectExplorer(childName, entry.Value); childNodes.Add(childObjectExplorer.TreeNode); } SetValueForDisplay(null, childNodes: childNodes.ToArray()); } else if (objectType.IsEnumerableType()) { Type innerType = null; var index = 0; var childNodes = new List<TreeNode>(); foreach (var childObject in value as IEnumerable) { if (innerType == null) { innerType = childObject.GetType(); } var childName = string.Format("[ {0} ]", index); var childObjectExplorer = new TreeNodeObjectExplorer(childName, childObject); childNodes.Add(childObjectExplorer.TreeNode); index++; } SetValueForDisplay(string.Format("{0}[ {1} ]", innerType == null ? objectType.Name : innerType.Name, index), childNodes: childNodes.ToArray()); } else { var childNodes = new List<TreeNode>(); foreach (var property in value.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { var childName = property.Name; var childObject = property.GetValue(value, null); var childObjectExplorer = new TreeNodeObjectExplorer(childName, childObject); childNodes.Add(childObjectExplorer.TreeNode); } SetValueForDisplay(null, childNodes: childNodes.ToArray()); } }
void Initialize() { if (value == null) { SetValueForDisplay("<null>"); return; } var objectType = value.GetType(); if (objectType.IsEnum) { SetValueForDisplay(string.Format("{0:G} ({0:D})", value)); } else if (objectType.IsValueType) { SetValueForDisplay(value.ToString()); } else if (value is string) { SetValueForDisplay(string.Format("\"{0}\"", value), (string)value); } else if (value is SteamID) { var steamID = (SteamID)value; SetValueForDisplay(string.Format("{0} ({1})", steamID.Render(steam3: true), steamID.ConvertToUInt64())); } else if (value is byte[]) { var data = (byte[])value; if (data.Length == 0) { SetValueForDisplay("byte[ 0 ]"); } else if (data.Length > MaxDataLengthForDisplay) { SetValueForDisplay(string.Format("byte[ {0} ]: Length exceeded {1} bytes! Value not shown - right-click to save.", data.Length, MaxDataLengthForDisplay)); } else { var hexadecimalValue = data.Aggregate(new StringBuilder(), (str, val) => str.Append(val.ToString("X2"))).ToString(); SetValueForDisplay(hexadecimalValue); } } else if (value is KeyValue) { var kv = (KeyValue)value; if (kv.Children.Count > 0) { var children = new List <TreeNode>(); foreach (var child in kv.Children) { children.Add(new TreeNodeObjectExplorer(child.Name, child).TreeNode); } SetValueForDisplay(null, childNodes: children.ToArray()); } else { SetValueForDisplay(string.Format("\"{0}\"", kv.Value), kv.Value); } } else if (objectType.IsDictionaryType()) { var childNodes = new List <TreeNode>(); var dictionary = value as IDictionary; foreach (DictionaryEntry entry in dictionary) { var childName = string.Format("[ {0} ]", entry.Key.ToString()); var childObjectExplorer = new TreeNodeObjectExplorer(childName, entry.Value); childNodes.Add(childObjectExplorer.TreeNode); } SetValueForDisplay(null, childNodes: childNodes.ToArray()); } else if (objectType.IsEnumerableType()) { Type innerType = null; var index = 0; var childNodes = new List <TreeNode>(); foreach (var childObject in value as IEnumerable) { if (innerType == null) { innerType = childObject.GetType(); } var childName = string.Format("[ {0} ]", index); var childObjectExplorer = new TreeNodeObjectExplorer(childName, childObject); childNodes.Add(childObjectExplorer.TreeNode); index++; } SetValueForDisplay(string.Format("{0}[ {1} ]", innerType == null ? objectType.Name : innerType.Name, index), childNodes: childNodes.ToArray()); } else { var childNodes = new List <TreeNode>(); foreach (var property in value.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { var childName = property.Name; var childObject = property.GetValue(value, null); var childObjectExplorer = new TreeNodeObjectExplorer(childName, childObject); childNodes.Add(childObjectExplorer.TreeNode); } SetValueForDisplay(null, childNodes: childNodes.ToArray()); } }
void Initialize() { if (value == null) { SetValueForDisplay("<null>"); return; } var objectType = value.GetType(); if (objectType.IsEnum) { SetValueForDisplay(string.Format("{0:G} ({0:D})", value)); } else if (objectType.IsValueType) { SetValueForDisplay(value.ToString()); } else if (value is string) { SetValueForDisplay(string.Format("\"{0}\"", value), (string)value); } else if (value is SteamID) { var steamID = (SteamID)value; SetValueForDisplay(string.Format("{0} ({1})", steamID.Render(steam3: true), steamID.ConvertToUInt64())); } else if (value is byte[]) { var data = (byte[])value; if (data.Length == 0) { SetValueForDisplay("byte[ 0 ]"); } else if (data.Length > MaxDataLengthForDisplay) { SetValueForDisplay(string.Format("byte[ {0} ]: Length exceeded {1} bytes! Value not shown - right-click to save.", data.Length, MaxDataLengthForDisplay)); } else { var hexadecimalValue = data.Aggregate(new StringBuilder(), (str, val) => str.Append(val.ToString("X2"))).ToString(); SetValueForDisplay(hexadecimalValue); } } else if (value is KeyValue) { var kv = (KeyValue)value; if (kv.Children.Count > 0) { var children = new List <TreeNode>(); foreach (var child in kv.Children) { children.Add(new TreeNodeObjectExplorer(child.Name, child, configuration).TreeNode); } SetValueForDisplay(null, childNodes: children.ToArray()); } else { SetValueForDisplay(string.Format("\"{0}\"", kv.Value), kv.Value); } } else if (objectType.IsDictionaryType()) { var childNodes = new List <TreeNode>(); var dictionary = value as IDictionary; foreach (DictionaryEntry entry in dictionary) { var childName = string.Format("[ {0} ]", entry.Key.ToString()); var childObjectExplorer = new TreeNodeObjectExplorer(childName, entry.Value, configuration); childNodes.Add(childObjectExplorer.TreeNode); } SetValueForDisplay(null, childNodes: childNodes.ToArray()); } else if (objectType.IsEnumerableType()) { Type innerType = null; var index = 0; var childNodes = new List <TreeNode>(); foreach (var childObject in value as IEnumerable) { if (innerType == null) { innerType = childObject.GetType(); } var childName = string.Format("[ {0} ]", index); var childObjectExplorer = new TreeNodeObjectExplorer(childName, childObject, configuration); childNodes.Add(childObjectExplorer.TreeNode); index++; } SetValueForDisplay(string.Format("{0}[ {1} ]", innerType == null ? objectType.Name : innerType.Name, index), childNodes: childNodes.ToArray()); } else { var childNodes = new List <TreeNode>(); var properties = value.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList(); bool valueIsProtobufMsg = value is ProtoBuf.IExtensible; if (valueIsProtobufMsg) { // For proto msgs, we want to skip vars where name is "<blah>Specified", unless there's no var named "<blah>" properties = properties.Where(x => { return(!x.Name.EndsWith("Specified") || properties.FirstOrDefault(y => { return y.Name == x.Name.Remove(x.Name.Length - 9); }) == null); }).ToList(); } foreach (var property in properties) { var childName = property.Name; var childObject = property.GetValue(value, null); bool valueIsSet = true; if (valueIsProtobufMsg) { if (childObject is IList) { // Repeated fields are marshalled as Lists, but aren't "set"/sent if they have no values added. valueIsSet = (property.GetValue(value) as IList).Count != 0; } else { // For non-repeated fields, look for the "<blah>Specfied" field existing and being set to false; var propSpecified = value.GetType().GetProperty(property.Name + "Specified"); valueIsSet = propSpecified == null || (bool)propSpecified.GetValue(value); } } if (valueIsSet || configuration.ShowUnsetFields) { var childConfiguration = configuration; childConfiguration.IsUnsetField = !valueIsSet; var childObjectExplorer = new TreeNodeObjectExplorer(childName, childObject, childConfiguration); childNodes.Add(childObjectExplorer.TreeNode); } } SetValueForDisplay(null, childNodes: childNodes.ToArray()); } }
static TreeNode BuildInfoNode(uint rawEMsg) { var eMsg = MsgUtil.GetMsg(rawEMsg); var eMsgExplorer = new TreeNodeObjectExplorer("EMsg", eMsg); return new TreeNode("Info", new[] { eMsgExplorer.TreeNode, new TreeNodeObjectExplorer("Is Protobuf", MsgUtil.IsProtoBuf(rawEMsg)).TreeNode }); }