From f4cd529bf80691cb5b6ee80a50205956b8d77981 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 11:06:00 +1100 Subject: [PATCH 01/13] VS update to project --- .../NetHookAnalyzer2/NetHookAnalyzer2.csproj | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookAnalyzer2.csproj b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookAnalyzer2.csproj index 32209f780..bea496fab 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookAnalyzer2.csproj +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookAnalyzer2.csproj @@ -10,4 +10,19 @@ + + + True + True + Settings.settings + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + From cfa8cb12dc067b91772f2488b4f809757bf6e105 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 11:07:54 +1100 Subject: [PATCH 02/13] Syntax fixes, remove dead code, dispose of undisposed dialog --- .../NetHookAnalyzer2/MessageTypeFinder.cs | 10 -------- ...tifactSOMultipleObjectsGCSpecialization.cs | 10 ++++---- .../Dota2SOMultipleObjectsGCSpecialization.cs | 10 ++++---- ...rlordsSOMultipleObjectsGCSpecialization.cs | 10 ++++---- .../TreeNodeObjectExplorer.cs | 23 ++++++++----------- 5 files changed, 21 insertions(+), 42 deletions(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MessageTypeFinder.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MessageTypeFinder.cs index b2cbc4ebc..3bb2c977f 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MessageTypeFinder.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MessageTypeFinder.cs @@ -110,16 +110,6 @@ static bool FilterProtobufMessageBodyType(Type type, EMsg eMsg) return true; } - static bool FilterNonProtobufMessageBodyTypes(Type type, EMsg eMsg) - { - if (type.GetInterfaces().ToList().Find(@interface => @interface == typeof(ISteamSerializableMessage)) == null) - return false; - - var gcMsg = Activator.CreateInstance(type) as ISteamSerializableMessage; - - return gcMsg.GetEMsg() == eMsg; - } - #endregion static IEnumerable GetPossibleGCTypePrefixes(uint appid) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOMultipleObjectsGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOMultipleObjectsGCSpecialization.cs index d946e092f..3c40e48ea 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOMultipleObjectsGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOMultipleObjectsGCSpecialization.cs @@ -54,13 +54,11 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject) { try { - using (var ms = new MemoryStream(sharedObject.object_data)) + using var ms = new MemoryStream( sharedObject.object_data ); + Type t; + if ( ArtifactSOHelper.SOTypes.TryGetValue( sharedObject.type_id, out t ) ) { - Type t; - if (ArtifactSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); } } catch (ProtoException ex) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOMultipleObjectsGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOMultipleObjectsGCSpecialization.cs index 5235c4d32..929e90a0c 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOMultipleObjectsGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOMultipleObjectsGCSpecialization.cs @@ -54,13 +54,11 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject) { try { - using (var ms = new MemoryStream(sharedObject.object_data)) + using var ms = new MemoryStream(sharedObject.object_data); + Type t; + if (Dota2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) { - Type t; - if (Dota2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize(ms, null, t); } } catch (ProtoException ex) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOMultipleObjectsGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOMultipleObjectsGCSpecialization.cs index a531abbea..8702bc88d 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOMultipleObjectsGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOMultipleObjectsGCSpecialization.cs @@ -54,13 +54,11 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject) { try { - using (var ms = new MemoryStream(sharedObject.object_data)) + using var ms = new MemoryStream(sharedObject.object_data); + Type t; + if (UnderlordsSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) { - Type t; - if (UnderlordsSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize(ms, null, t); } } catch (ProtoException ex) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs index efaa7c8bc..8fd65aae0 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs @@ -88,7 +88,7 @@ void SaveDataToFile(object sender, EventArgs e) { var data = (byte[])value; - var dialog = new SaveFileDialog { DefaultExt = "bin", SupportMultiDottedExtensions = true }; + using var dialog = new SaveFileDialog { DefaultExt = "bin", SupportMultiDottedExtensions = true }; var result = dialog.ShowDialog(); if (result == DialogResult.OK) { @@ -154,12 +154,10 @@ void DisplayDataAsProtobuf( object sender, EventArgs e ) try { - using ( MemoryStream ms = new MemoryStream( data ) ) - { - var dictionary = ProtoBufFieldReader.ReadProtobuf( ms ); + using var ms = new MemoryStream( data ); + var dictionary = ProtoBufFieldReader.ReadProtobuf( ms ); - SetValueForDisplay( null, childNodes: new[] { new TreeNodeObjectExplorer( "Protobuf", dictionary, configuration ).TreeNode } ); - } + SetValueForDisplay( null, childNodes: new[] { new TreeNodeObjectExplorer( "Protobuf", dictionary, configuration ).TreeNode } ); } catch { @@ -532,14 +530,12 @@ void Initialize() { SetValueForDisplay(string.Format("\"{0}\"", value), (string)value); } - else if (value is SteamID) + else if (value is SteamID steamID) { - var steamID = (SteamID)value; SetValueForDisplay(string.Format("{0} ({1})", steamID.Render(steam3: true), steamID.ConvertToUInt64())); } - else if (value is byte[]) + else if (value is byte[] data) { - var data = (byte[])value; if (data.Length == 0) { SetValueForDisplay("byte[ 0 ]"); @@ -554,9 +550,8 @@ void Initialize() SetValueForDisplay(hexadecimalValue); } } - else if (value is KeyValue) + else if (value is KeyValue kv) { - var kv = (KeyValue)value; if (kv.Children.Count > 0) { var children = new List(); @@ -633,10 +628,10 @@ void Initialize() bool valueIsSet = true; if (valueIsProtobufMsg) { - if (childObject is IList) + if (childObject is IList childObjectList) { // 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; + valueIsSet = childObjectList.Count != 0; } else { From df8722c85a86cfe25ce6ebb60e06889237e8f347 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 11:10:55 +1100 Subject: [PATCH 03/13] Fix NHA2 showing properties that weren't specified. Compat change for new protobuf-net generator. --- .../NetHookAnalyzer2/TreeNodeObjectExplorer.cs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs index 8fd65aae0..7d63726ba 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs @@ -611,16 +611,6 @@ void Initialize() 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 "Specified", unless there's no var named "" - 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; @@ -635,9 +625,9 @@ void Initialize() } else { - // For non-repeated fields, look for the "Specfied" field existing and being set to false; - var propSpecified = value.GetType().GetProperty(property.Name + "Specified"); - valueIsSet = propSpecified == null || (bool)propSpecified.GetValue(value); + // For non-repeated fields, look for the "ShouldSerialiez" 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; } } From ec1973f143801d4bb9d2eff61fa8558810d32ab1 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 11:11:16 +1100 Subject: [PATCH 04/13] Fix mixed whitespace --- .../NetHookAnalyzer2/TreeNodeObjectExplorer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs index 7d63726ba..8ff71ad0a 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs @@ -636,8 +636,8 @@ void Initialize() var childConfiguration = configuration; childConfiguration.IsUnsetField = !valueIsSet; - var childObjectExplorer = new TreeNodeObjectExplorer(childName, childObject, childConfiguration); - childNodes.Add(childObjectExplorer.TreeNode); + var childObjectExplorer = new TreeNodeObjectExplorer(childName, childObject, childConfiguration); + childNodes.Add(childObjectExplorer.TreeNode); } } From 441d99eab8f2d9e89f5d92eb77fee1ce44547529 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 11:12:52 +1100 Subject: [PATCH 05/13] Clarity --- .../NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs index 8ff71ad0a..ccc3546c0 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs @@ -627,7 +627,7 @@ void Initialize() { // For non-repeated fields, look for the "ShouldSerialiez" 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; + valueIsSet = shouldSerializeProp == null || (shouldSerializeProp.Invoke(value, null) is bool specified && specified); } } From 6f555c0c30b2beac9ba6a853a340dbae4b934067 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 14:15:22 +1100 Subject: [PATCH 06/13] fix whitespace --- Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs index 4d582db12..f7c69e259 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs @@ -49,9 +49,9 @@ static ISpecialization[] LoadMessageObjectSpecializations() new ArtifactCacheSubscribedGCSpecialization(), new ArtifactSOMultipleObjectsGCSpecialization(), new ArtifactSOSingleObjectGCSpecialization(), - new UnderlordsCacheSubscribedGCSpecialization(), - new UnderlordsSOMultipleObjectsGCSpecialization(), - new UnderlordsSOSingleObjectGCSpecialization(), + new UnderlordsCacheSubscribedGCSpecialization(), + new UnderlordsSOMultipleObjectsGCSpecialization(), + new UnderlordsSOSingleObjectGCSpecialization(), } } }; From de02a19f519dfcb1ea56d48200a8eacaa37f0248 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 14:15:28 +1100 Subject: [PATCH 07/13] simplify --- .../NetHookAnalyzer2/ProtoBufFieldReader.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/ProtoBufFieldReader.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/ProtoBufFieldReader.cs index 73197ed8a..2b2a6ebb7 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/ProtoBufFieldReader.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/ProtoBufFieldReader.cs @@ -61,12 +61,15 @@ public static Dictionary> ReadProtobuf(Stream stream) } } - if (!fields.ContainsKey(field)) + if (fields.TryGetValue(field, out var values)) { - fields[field] = new List(); + values.Add( fieldValue ); + } + else + { + values = new List { fieldValue }; + fields[ field ] = values; } - - fields[field].Add(fieldValue); } if (fields.Count > 0) From 41c762e71f3ece175c28803fbc18d624a25c993c Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 14:20:21 +1100 Subject: [PATCH 08/13] our var --- .../NetHookAnalyzer2/NetHookAnalyzer2/NetHookItem.cs | 10 ++++------ .../ArtifactSOCacheSubscribedGCSpecialization.cs | 3 +-- .../ArtifactSOMultipleObjectsGCSpecialization.cs | 3 +-- .../Artifact/ArtifactSOSingleObjectGCSpecialization.cs | 3 +-- .../CSGO/CSGOSOCacheSubscribedGCSpecialization.cs | 3 +-- .../CSGO/CSGOSOMultipleObjectsGCSpecialization.cs | 3 +-- .../CSGO/CSGOSOSingleObjectGCSpecialization.cs | 5 ++--- .../Dota2/Dota2SOCacheSubscribedGCSpecialization.cs | 3 +-- .../Dota2/Dota2SOMultipleObjectsGCSpecialization.cs | 3 +-- .../Dota2/Dota2SOSingleObjectGCSpecialization.cs | 3 +-- .../TF2/TF2SOMultipleObjectsGCSpecialization.cs | 3 +-- .../TF2/TF2SOSingleObjectGCSpecialization.cs | 5 ++--- .../UnderlordsSOCacheSubscribedGCSpecialization.cs | 3 +-- .../UnderlordsSOMultipleObjectsGCSpecialization.cs | 3 +-- .../UnderlordsSOSingleObjectGCSpecialization.cs | 5 ++--- 15 files changed, 21 insertions(+), 37 deletions(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItem.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItem.cs index 3fe8a4112..d809ed248 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItem.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItem.cs @@ -48,8 +48,7 @@ public bool LoadFromFile(FileInfo fileInfo) return false; } - int sequence; - if (!int.TryParse(m.Groups["num"].Value, out sequence)) + if (!int.TryParse(m.Groups["num"].Value, out var sequence)) { return false; } @@ -57,14 +56,13 @@ public bool LoadFromFile(FileInfo fileInfo) Timestamp = fileInfo.LastWriteTime; var direction = m.Groups[ "direction" ].Value; - PacketDirection packetDirection; - if (!Enum.TryParse(direction, ignoreCase: true, result: out packetDirection)) + + if (!Enum.TryParse(direction, ignoreCase: true, result: out var packetDirection)) { return false; } - uint emsg; - if (!uint.TryParse(m.Groups["emsg"].Value, out emsg)) + if (!uint.TryParse(m.Groups["emsg"].Value, out var emsg)) { return false; } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOCacheSubscribedGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOCacheSubscribedGCSpecialization.cs index 65caf554b..239be98e1 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOCacheSubscribedGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOCacheSubscribedGCSpecialization.cs @@ -42,8 +42,7 @@ object ReadExtraObject(byte[] sharedObject, int typeId) { using (var ms = new MemoryStream(sharedObject)) { - Type t; - if (ArtifactSOHelper.SOTypes.TryGetValue(typeId, out t)) + if (ArtifactSOHelper.SOTypes.TryGetValue(typeId, out var t)) { return RuntimeTypeModel.Default.Deserialize(ms, null, t); } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOMultipleObjectsGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOMultipleObjectsGCSpecialization.cs index 3c40e48ea..b376835da 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOMultipleObjectsGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOMultipleObjectsGCSpecialization.cs @@ -55,8 +55,7 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject) try { using var ms = new MemoryStream( sharedObject.object_data ); - Type t; - if ( ArtifactSOHelper.SOTypes.TryGetValue( sharedObject.type_id, out t ) ) + if ( ArtifactSOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) ) { return RuntimeTypeModel.Default.Deserialize( ms, null, t ); } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOSingleObjectGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOSingleObjectGCSpecialization.cs index 60af1ac0d..e892e8353 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOSingleObjectGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOSingleObjectGCSpecialization.cs @@ -35,8 +35,7 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject) { using (var ms = new MemoryStream(sharedObject.object_data)) { - Type t; - if (ArtifactSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) + if (ArtifactSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) { return RuntimeTypeModel.Default.Deserialize(ms, null, t); } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOCacheSubscribedGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOCacheSubscribedGCSpecialization.cs index 354138ca7..2b93d4158 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOCacheSubscribedGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOCacheSubscribedGCSpecialization.cs @@ -41,8 +41,7 @@ object ReadExtraObject(byte[] sharedObject, int typeId) { using (var ms = new MemoryStream(sharedObject)) { - Type t; - if (CSGOSOHelper.SOTypes.TryGetValue(typeId, out t)) + if (CSGOSOHelper.SOTypes.TryGetValue(typeId, out var t)) { return RuntimeTypeModel.Default.Deserialize(ms, null, t); } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOMultipleObjectsGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOMultipleObjectsGCSpecialization.cs index 854b21822..7f860f0bd 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOMultipleObjectsGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOMultipleObjectsGCSpecialization.cs @@ -56,8 +56,7 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject) { using (var ms = new MemoryStream(sharedObject.object_data)) { - Type t; - if (CSGOSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) + if (CSGOSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) { return RuntimeTypeModel.Default.Deserialize(ms, null, t); } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOSingleObjectGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOSingleObjectGCSpecialization.cs index 496848229..a28a03eb8 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOSingleObjectGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOSingleObjectGCSpecialization.cs @@ -35,10 +35,9 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject) { using (var ms = new MemoryStream(sharedObject.object_data)) { - Type t; - if (CSGOSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) + if (CSGOSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); + return RuntimeTypeModel.Default.Deserialize(ms, null, t); } } } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOCacheSubscribedGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOCacheSubscribedGCSpecialization.cs index 063fbe108..24f02dead 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOCacheSubscribedGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOCacheSubscribedGCSpecialization.cs @@ -42,8 +42,7 @@ object ReadExtraObject(byte[] sharedObject, int typeId) { using (var ms = new MemoryStream(sharedObject)) { - Type t; - if (Dota2SOHelper.SOTypes.TryGetValue(typeId, out t)) + if (Dota2SOHelper.SOTypes.TryGetValue(typeId, out var t)) { return RuntimeTypeModel.Default.Deserialize(ms, null, t); } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOMultipleObjectsGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOMultipleObjectsGCSpecialization.cs index 929e90a0c..eef116b0d 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOMultipleObjectsGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOMultipleObjectsGCSpecialization.cs @@ -55,8 +55,7 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject) try { using var ms = new MemoryStream(sharedObject.object_data); - Type t; - if (Dota2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) + if (Dota2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) { return RuntimeTypeModel.Default.Deserialize(ms, null, t); } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOSingleObjectGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOSingleObjectGCSpecialization.cs index 36219843f..ba5aa90ef 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOSingleObjectGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOSingleObjectGCSpecialization.cs @@ -35,8 +35,7 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject) { using (var ms = new MemoryStream(sharedObject.object_data)) { - Type t; - if (Dota2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) + if (Dota2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) { return RuntimeTypeModel.Default.Deserialize(ms, null, t); } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOMultipleObjectsGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOMultipleObjectsGCSpecialization.cs index e9028d969..b4c946b1a 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOMultipleObjectsGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOMultipleObjectsGCSpecialization.cs @@ -38,8 +38,7 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject) { using (var ms = new MemoryStream(sharedObject.object_data)) { - Type t; - if (TF2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) + if (TF2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) { return RuntimeTypeModel.Default.Deserialize(ms, null, t); } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOSingleObjectGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOSingleObjectGCSpecialization.cs index 70f1d5836..0bc69e891 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOSingleObjectGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOSingleObjectGCSpecialization.cs @@ -35,10 +35,9 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject) { using (var ms = new MemoryStream(sharedObject.object_data)) { - Type t; - if (TF2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) + if (TF2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); + return RuntimeTypeModel.Default.Deserialize(ms, null, t); } } } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOCacheSubscribedGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOCacheSubscribedGCSpecialization.cs index f237dadeb..3b1413d07 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOCacheSubscribedGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOCacheSubscribedGCSpecialization.cs @@ -42,8 +42,7 @@ object ReadExtraObject(byte[] sharedObject, int typeId) { using (var ms = new MemoryStream(sharedObject)) { - Type t; - if (UnderlordsSOHelper.SOTypes.TryGetValue(typeId, out t)) + if (UnderlordsSOHelper.SOTypes.TryGetValue(typeId, out var t)) { return RuntimeTypeModel.Default.Deserialize(ms, null, t); } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOMultipleObjectsGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOMultipleObjectsGCSpecialization.cs index 8702bc88d..b1c39ca52 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOMultipleObjectsGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOMultipleObjectsGCSpecialization.cs @@ -55,8 +55,7 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject) try { using var ms = new MemoryStream(sharedObject.object_data); - Type t; - if (UnderlordsSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) + if (UnderlordsSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) { return RuntimeTypeModel.Default.Deserialize(ms, null, t); } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOSingleObjectGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOSingleObjectGCSpecialization.cs index 1ac4e6fae..d5bd3253b 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOSingleObjectGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOSingleObjectGCSpecialization.cs @@ -35,10 +35,9 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject) { using (var ms = new MemoryStream(sharedObject.object_data)) { - Type t; - if (UnderlordsSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t)) + if (UnderlordsSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); + return RuntimeTypeModel.Default.Deserialize(ms, null, t); } } } From 1c5b125e066cadb509bc789300373aa4df260b74 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 14:22:00 +1100 Subject: [PATCH 09/13] simplify more c#8 usings --- ...tifactSOCacheSubscribedGCSpecialization.cs | 8 ++- .../ArtifactSOSingleObjectGCSpecialization.cs | 8 ++- .../CSGOSOCacheSubscribedGCSpecialization.cs | 8 ++- .../CSGOSOMultipleObjectsGCSpecialization.cs | 14 +++-- .../CSGOSOSingleObjectGCSpecialization.cs | 8 ++- .../Dota2SOCacheSubscribedGCSpecialization.cs | 8 ++- .../Dota2SOSingleObjectGCSpecialization.cs | 8 ++- .../GCGenericSpecialization.cs | 54 +++++++++---------- .../TF2SOCacheSubscribedGCSpecialization.cs | 8 ++- .../TF2SOMultipleObjectsGCSpecialization.cs | 14 +++-- .../TF2/TF2SOSingleObjectGCSpecialization.cs | 11 ++-- ...rlordsSOCacheSubscribedGCSpecialization.cs | 8 ++- ...nderlordsSOSingleObjectGCSpecialization.cs | 8 ++- 13 files changed, 69 insertions(+), 96 deletions(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOCacheSubscribedGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOCacheSubscribedGCSpecialization.cs index 239be98e1..9b3d51b64 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOCacheSubscribedGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOCacheSubscribedGCSpecialization.cs @@ -40,12 +40,10 @@ object ReadExtraObject(byte[] sharedObject, int typeId) { try { - using (var ms = new MemoryStream(sharedObject)) + using var ms = new MemoryStream( sharedObject ); + if ( ArtifactSOHelper.SOTypes.TryGetValue( typeId, out var t ) ) { - if (ArtifactSOHelper.SOTypes.TryGetValue(typeId, out var t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); } } catch (ProtoException ex) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOSingleObjectGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOSingleObjectGCSpecialization.cs index e892e8353..17dfa2ca2 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOSingleObjectGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Artifact/ArtifactSOSingleObjectGCSpecialization.cs @@ -33,12 +33,10 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject) { try { - using (var ms = new MemoryStream(sharedObject.object_data)) + using var ms = new MemoryStream( sharedObject.object_data ); + if ( ArtifactSOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) ) { - if (ArtifactSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); } } catch (ProtoException ex) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOCacheSubscribedGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOCacheSubscribedGCSpecialization.cs index 2b93d4158..36a12f9d1 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOCacheSubscribedGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOCacheSubscribedGCSpecialization.cs @@ -39,12 +39,10 @@ object ReadExtraObject(byte[] sharedObject, int typeId) { try { - using (var ms = new MemoryStream(sharedObject)) + using var ms = new MemoryStream( sharedObject ); + if ( CSGOSOHelper.SOTypes.TryGetValue( typeId, out var t ) ) { - if (CSGOSOHelper.SOTypes.TryGetValue(typeId, out var t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); } } catch (ProtoException ex) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOMultipleObjectsGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOMultipleObjectsGCSpecialization.cs index 7f860f0bd..56221340f 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOMultipleObjectsGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOMultipleObjectsGCSpecialization.cs @@ -54,14 +54,12 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject) { try { - using (var ms = new MemoryStream(sharedObject.object_data)) - { - if (CSGOSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } - } - } + using var ms = new MemoryStream( sharedObject.object_data ); + if ( CSGOSOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) ) + { + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); + } + } catch (ProtoException ex) { return "Error parsing SO data: " + ex.Message; diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOSingleObjectGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOSingleObjectGCSpecialization.cs index a28a03eb8..c51b43e3b 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOSingleObjectGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/CSGO/CSGOSOSingleObjectGCSpecialization.cs @@ -33,12 +33,10 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject) { try { - using (var ms = new MemoryStream(sharedObject.object_data)) + using var ms = new MemoryStream( sharedObject.object_data ); + if ( CSGOSOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) ) { - if (CSGOSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); } } catch (ProtoException ex) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOCacheSubscribedGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOCacheSubscribedGCSpecialization.cs index 24f02dead..5868302f3 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOCacheSubscribedGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOCacheSubscribedGCSpecialization.cs @@ -40,12 +40,10 @@ object ReadExtraObject(byte[] sharedObject, int typeId) { try { - using (var ms = new MemoryStream(sharedObject)) + using var ms = new MemoryStream( sharedObject ); + if ( Dota2SOHelper.SOTypes.TryGetValue( typeId, out var t ) ) { - if (Dota2SOHelper.SOTypes.TryGetValue(typeId, out var t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); } } catch (ProtoException ex) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOSingleObjectGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOSingleObjectGCSpecialization.cs index ba5aa90ef..20c2b40f9 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOSingleObjectGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Dota2/Dota2SOSingleObjectGCSpecialization.cs @@ -33,12 +33,10 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject) { try { - using (var ms = new MemoryStream(sharedObject.object_data)) + using var ms = new MemoryStream( sharedObject.object_data ); + if ( Dota2SOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) ) { - if (Dota2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); } } catch (ProtoException ex) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/GCGenericSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/GCGenericSpecialization.cs index 769a56d5c..92c634c2d 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/GCGenericSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/GCGenericSpecialization.cs @@ -21,38 +21,36 @@ public IEnumerable> ReadExtraObjects(object message yield break; } - using (var ms = new MemoryStream(gameCoordinatorMessage.payload)) - { - var header = ReadHeader(gameCoordinatorMessage.msgtype, ms); - var gcBody = ReadMessageBody(gameCoordinatorMessage.msgtype, ms, gameCoordinatorMessage.appid); - if (gcBody == null) - { - yield break; - } + using var ms = new MemoryStream( gameCoordinatorMessage.payload ); + var header = ReadHeader( gameCoordinatorMessage.msgtype, ms ); + var gcBody = ReadMessageBody( gameCoordinatorMessage.msgtype, ms, gameCoordinatorMessage.appid ); + if ( gcBody == null ) + { + yield break; + } - var gc = new - { - emsg = EMsgExtensions.GetGCMessageName(gameCoordinatorMessage.msgtype, gameCoordinatorMessage.appid), - header = header, - body = gcBody, - }; + var gc = new + { + emsg = EMsgExtensions.GetGCMessageName( gameCoordinatorMessage.msgtype, gameCoordinatorMessage.appid ), + header = header, + body = gcBody, + }; - var specializations = new List(); + var specializations = new List(); - yield return new KeyValuePair("Game Coordinator Message", gc); + yield return new KeyValuePair( "Game Coordinator Message", gc ); - if (GameCoordinatorSpecializations != null) - { - foreach (var gameSpecificSpecialization in GameCoordinatorSpecializations) - { - foreach (var specializedObject in gameSpecificSpecialization.GetExtraObjects(gcBody, gameCoordinatorMessage.appid)) - { - yield return specializedObject; - } - } - } - } - } + if ( GameCoordinatorSpecializations != null ) + { + foreach ( var gameSpecificSpecialization in GameCoordinatorSpecializations ) + { + foreach ( var specializedObject in gameSpecificSpecialization.GetExtraObjects( gcBody, gameCoordinatorMessage.appid ) ) + { + yield return specializedObject; + } + } + } + } static IGCSerializableHeader ReadHeader(uint rawEMsg, Stream stream) { diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOCacheSubscribedGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOCacheSubscribedGCSpecialization.cs index 006bf82a1..2010bbedc 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOCacheSubscribedGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOCacheSubscribedGCSpecialization.cs @@ -40,12 +40,10 @@ object ReadExtraObject(byte[] sharedObject, int typeId) { try { - using (var ms = new MemoryStream(sharedObject)) + using var ms = new MemoryStream( sharedObject ); + if ( TF2SOHelper.SOTypes.TryGetValue( typeId, out var t ) ) { - if (TF2SOHelper.SOTypes.TryGetValue(typeId, out var t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); } } catch (ProtoException ex) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOMultipleObjectsGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOMultipleObjectsGCSpecialization.cs index b4c946b1a..ef7593e7f 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOMultipleObjectsGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOMultipleObjectsGCSpecialization.cs @@ -36,14 +36,12 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject) { try { - using (var ms = new MemoryStream(sharedObject.object_data)) - { - if (TF2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } - } - } + using var ms = new MemoryStream( sharedObject.object_data ); + if ( TF2SOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) ) + { + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); + } + } catch (ProtoException ex) { return "Error parsing SO data: " + ex.Message; diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOSingleObjectGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOSingleObjectGCSpecialization.cs index 0bc69e891..fd2f89afc 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOSingleObjectGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/TF2/TF2SOSingleObjectGCSpecialization.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using ProtoBuf; using ProtoBuf.Meta; @@ -33,12 +32,10 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject) { try { - using (var ms = new MemoryStream(sharedObject.object_data)) + using var ms = new MemoryStream( sharedObject.object_data ); + if ( TF2SOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) ) { - if (TF2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); } } catch (ProtoException ex) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOCacheSubscribedGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOCacheSubscribedGCSpecialization.cs index 3b1413d07..50c014804 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOCacheSubscribedGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOCacheSubscribedGCSpecialization.cs @@ -40,12 +40,10 @@ object ReadExtraObject(byte[] sharedObject, int typeId) { try { - using (var ms = new MemoryStream(sharedObject)) + using var ms = new MemoryStream( sharedObject ); + if ( UnderlordsSOHelper.SOTypes.TryGetValue( typeId, out var t ) ) { - if (UnderlordsSOHelper.SOTypes.TryGetValue(typeId, out var t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); } } catch (ProtoException ex) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOSingleObjectGCSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOSingleObjectGCSpecialization.cs index d5bd3253b..ca341cf0b 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOSingleObjectGCSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/Underlords/UnderlordsSOSingleObjectGCSpecialization.cs @@ -33,12 +33,10 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject) { try { - using (var ms = new MemoryStream(sharedObject.object_data)) + using var ms = new MemoryStream( sharedObject.object_data ); + if ( UnderlordsSOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) ) { - if (UnderlordsSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t)) - { - return RuntimeTypeModel.Default.Deserialize(ms, null, t); - } + return RuntimeTypeModel.Default.Deserialize( ms, null, t ); } } catch (ProtoException ex) From 852db30605375e9c2fe7c27212f340540312b970 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 14:22:13 +1100 Subject: [PATCH 10/13] unneccesary --- .../NetHookAnalyzer2/Specializations/GCGenericSpecialization.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/GCGenericSpecialization.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/GCGenericSpecialization.cs index 92c634c2d..8e796a2d3 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/GCGenericSpecialization.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/Specializations/GCGenericSpecialization.cs @@ -54,7 +54,7 @@ public IEnumerable> ReadExtraObjects(object message static IGCSerializableHeader ReadHeader(uint rawEMsg, Stream stream) { - IGCSerializableHeader header = null; + IGCSerializableHeader header; if (MsgUtil.IsProtoBuf(rawEMsg)) { From 7b71ac16d4f32d8505b30124a3ec20e84fe730c9 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 14:23:22 +1100 Subject: [PATCH 11/13] Suppress warning about disposable fields that follow Form events lifecycle --- Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs index f7c69e259..2dcd080a3 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs @@ -23,8 +23,13 @@ public MainForm() specializations = LoadMessageObjectSpecializations(); } +#pragma warning disable IDE0069 // Disposable fields should be disposed + IDisposable itemsListViewFirstColumnHiderDisposable; FileSystemWatcher folderWatcher; + +#pragma warning restore IDE0069 // Disposable fields should be disposed + readonly ISpecialization[] specializations; static ISpecialization[] LoadMessageObjectSpecializations() From d959b049d2d31837eac29e9bf67878de1abb5bb9 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 14:24:54 +1100 Subject: [PATCH 12/13] Dispose of folder browser dialog correctly --- .../NetHookAnalyzer2/MainForm.cs | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs index 2dcd080a3..4c3be52b9 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs @@ -152,21 +152,27 @@ void OnExitToolStripMenuItemClick(object sender, EventArgs e) Application.Exit(); } - void OnOpenToolStripMenuItemClick(object sender, EventArgs e) + void OnOpenToolStripMenuItemClick( object sender, EventArgs e ) { - var dialog = new FolderBrowserDialog { ShowNewFolderButton = false }; - var latestNethookDir = GetLatestNethookDumpDirectory(); - if (latestNethookDir != null) - { - dialog.SelectedPath = GetLatestNethookDumpDirectory(); - } + string dumpDirectory; - if (dialog.ShowDialog() != WinForms.DialogResult.OK) + using ( var dialog = new FolderBrowserDialog() ) { - return; - } + dialog.ShowNewFolderButton = false; - var dumpDirectory = dialog.SelectedPath; + var latestNethookDir = GetLatestNethookDumpDirectory(); + if ( latestNethookDir != null ) + { + dialog.SelectedPath = GetLatestNethookDumpDirectory(); + } + + if ( dialog.ShowDialog() != WinForms.DialogResult.OK ) + { + return; + } + + dumpDirectory = dialog.SelectedPath; + } var dump = new NetHookDump(); dump.LoadFromDirectory(dumpDirectory); From 628e8480ffe1c7e3606bce7510f0349b6026a98c Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 20 Oct 2019 14:25:45 +1100 Subject: [PATCH 13/13] Only create Enum menu item if we're actually going to use it. --- .../NetHookAnalyzer2/TreeNodeObjectExplorer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs index ccc3546c0..d685f1aa6 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/TreeNodeObjectExplorer.cs @@ -367,8 +367,6 @@ void OnContextMenuPopup(object sender, EventArgs e) { // only allow displaying as an enum value if we're not a steamid - var enumMenuItem = new MenuItem("Display as &Enum Value"); - var enumTypesByNamespace = typeof(CMClient).Assembly.ExportedTypes .Where(x => x.IsEnum) .GroupBy(x => x.Namespace) @@ -377,6 +375,8 @@ void OnContextMenuPopup(object sender, EventArgs e) if (enumTypesByNamespace.Length > 0) { + var enumMenuItem = new MenuItem( "Display as &Enum Value" ); + foreach (var enumTypes in enumTypesByNamespace) { var enumNamespaceMenuItem = new MenuItem(enumTypes.Key);