private void PacketListView_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (PacketListView.SelectedIndex == -1) { return; } var item = (PacketEntry)PacketListView.Items[PacketListView.SelectedIndex]; var data = item.Data; if (Properties.Settings.Default.HideHexBoxActorId) { byte[] noIdData = new byte[data.Length]; Array.Copy(data, 0, noIdData, 0, 3); Array.Copy(data, 12, noIdData, 12, data.Length - 12); data = noIdData; } _currentPacketStream = new MemoryStream(data); try { HexEditor.ByteProvider = new DynamicByteProvider(data); } catch (Exception exception) { new ExtendedErrorView("Failed to load packet.", exception.ToString(), "Error").ShowDialog(); } StructListView.Items.Clear(); try { string structText = null; structText = item.Direction == "S" ? _db.GetServerZoneStruct(int.Parse(item.Message, NumberStyles.HexNumber)) : _db.GetClientZoneStruct(int.Parse(item.Message, NumberStyles.HexNumber)); if (structText == null) { StructListItem infoItem = new StructListItem { NameCol = "No Struct found" }; StructListView.Items.Add(infoItem); return; } var structProvider = new Struct(); var structEntries = structProvider.Parse(structText, item.Data); var colours = Struct.TypeColours; int i = 0; // Highlight the IPC header lightly grey HexEditor.HighlightBytes(0, 0x20, System.Drawing.Color.Black, System.Drawing.Color.LightGray); foreach (var entry in structEntries.Item1) { System.Drawing.Color colour = Struct.TypeColours.ElementAt(i).Value; StructListView.Items.Add(entry); HexEditor.HighlightBytes(entry.offset, entry.typeLength, System.Drawing.Color.Black, colour); ++i; if (i == colours.Count) { i = 1; } } if (_mainWindow.ShowObjectMapCheckBox.IsChecked) { new ExtendedErrorView("Object map for " + item.Name, structEntries.Item2.Print(), "FFXIVMon Reborn").ShowDialog(); } } catch (Exception exc) { #if !DEBUG if (_erroredOpcodes.Contains(item.Message)) { #endif new ExtendedErrorView($"Struct error! Could not get struct for {item.Name} - {item.Message}", exc.ToString(), "Error").ShowDialog(); #if !DEBUG _erroredOpcodes.Add(item.Message); } #endif StructListItem infoItem = new StructListItem { NameCol = "Parsing failed" } ; StructListView.Items.Add(infoItem); return; } UpdateInfoLabel(); }
private void PacketListView_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (PacketListView.SelectedIndex == -1) { return; } var item = (PacketEntry)PacketListView.Items[PacketListView.SelectedIndex]; var data = item.Data; if (Properties.Settings.Default.HideHexBoxActorId) { byte[] noIdData = new byte[data.Length]; Array.Copy(data, 0, noIdData, 0, 3); Array.Copy(data, 12, noIdData, 12, data.Length - 12); data = noIdData; } _currentPacketStream = new MemoryStream(data); try { HexEditor.ByteProvider = new DynamicByteProvider(data); } catch (Exception exception) { new ExtendedErrorView("Failed to load packet.", exception.ToString(), "Error").ShowDialog(); } StructListView.Items.Clear(); try { if (item.Direction == "S") { var structText = _db.GetServerZoneStruct(int.Parse(item.Message, NumberStyles.HexNumber)); if (structText == null) { StructListItem infoItem = new StructListItem(); infoItem.NameCol = "No Struct found"; StructListView.Items.Add(infoItem); return; } var structProvider = new Struct(); var structEntries = structProvider.Parse(structText, item.Data); var colours = Struct.TypeColours; var i = 0; foreach (var entry in structEntries.Item1) { System.Drawing.Color colour; if (!colours.TryGetValue(string.IsNullOrEmpty(entry.DataTypeCol) ? "unknown" : entry.DataTypeCol, out colour)) { colour = System.Drawing.Color.White; } StructListView.Items.Add(entry); HexEditor.HighlightBytes(entry.offset, entry.typeLength, System.Drawing.Color.Black, colour); } if (_mainWindow.ShowObjectMapCheckBox.IsChecked) { new ExtendedErrorView("Object map for " + item.Name, structEntries.Item2.Print(), "FFXIVMon Reborn").ShowDialog(); } } else { StructListItem infoItem = new StructListItem(); infoItem.NameCol = "Client Packet"; StructListView.Items.Add(infoItem); return; } } catch (Exception exc) { new ExtendedErrorView($"[XivMonTab] Struct error! Could not get struct for {item.Name} - {item.Message}", exc.ToString(), "Error").ShowDialog(); } UpdateInfoLabel(); }