Remove internal dependencies on opcodes (#1464)

- Removes the opcode lists from internal API entirely
- Move NetworkHandlers to use packet handler sigs
- Remove opcode data from NetworkMonitorWidget
This commit is contained in:
KazWolfe 2023-10-05 10:01:03 -07:00 committed by GitHub
parent 59606ff854
commit 2083ccda00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 417 additions and 221 deletions

View file

@ -30,7 +30,6 @@ internal class NetworkMonitorWidget : IDataWindowWidget
}
private readonly ConcurrentQueue<NetworkPacketData> packets = new();
private readonly Dictionary<ushort, (string Name, int Size)> opCodeDict = new();
private bool trackNetwork;
private int trackedPackets;
@ -71,9 +70,6 @@ internal class NetworkMonitorWidget : IDataWindowWidget
this.filterString = string.Empty;
this.packets.Clear();
this.Ready = true;
var dataManager = Service<DataManager>.Get();
foreach (var (name, code) in dataManager.ClientOpCodes.Concat(dataManager.ServerOpCodes))
this.opCodeDict.TryAdd(code, (name, this.GetSizeFromName(name)));
}
/// <inheritdoc/>
@ -106,7 +102,7 @@ internal class NetworkMonitorWidget : IDataWindowWidget
this.DrawFilterInput();
this.DrawNegativeFilterInput();
ImGuiTable.DrawTable(string.Empty, this.packets, this.DrawNetworkPacket, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.RowBg, "Direction", "Known Name", "OpCode", "Hex", "Target", "Source", "Data");
ImGuiTable.DrawTable(string.Empty, this.packets, this.DrawNetworkPacket, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.RowBg, "Direction", "OpCode", "Hex", "Target", "Source", "Data");
}
private void DrawNetworkPacket(NetworkPacketData data)
@ -114,16 +110,6 @@ internal class NetworkMonitorWidget : IDataWindowWidget
ImGui.TableNextColumn();
ImGui.TextUnformatted(data.Direction.ToString());
ImGui.TableNextColumn();
if (this.opCodeDict.TryGetValue(data.OpCode, out var pair))
{
ImGui.TextUnformatted(pair.Name);
}
else
{
ImGui.Dummy(new Vector2(150 * ImGuiHelpers.GlobalScale, 0));
}
ImGui.TableNextColumn();
ImGui.TextUnformatted(data.OpCode.ToString());
@ -217,7 +203,7 @@ internal class NetworkMonitorWidget : IDataWindowWidget
}
private int GetSizeFromOpCode(ushort opCode)
=> this.opCodeDict.TryGetValue(opCode, out var pair) ? pair.Size : 0;
=> 0;
/// <remarks> Add known packet-name -> packet struct size associations here to copy the byte data for such packets. </remarks>>
private int GetSizeFromName(string name)
@ -228,5 +214,5 @@ internal class NetworkMonitorWidget : IDataWindowWidget
/// <remarks> The filter should find opCodes by number (decimal and hex) and name, if existing. </remarks>
private string OpCodeToString(ushort opCode)
=> this.opCodeDict.TryGetValue(opCode, out var pair) ? $"{opCode}\0{opCode:X}\0{pair.Name}" : $"{opCode}\0{opCode:X}";
=> $"{opCode}\0{opCode:X}";
}