diff --git a/TrafficAnalyzer/Program.cs b/TrafficAnalyzer/Program.cs new file mode 100644 index 0000000..aa4705d --- /dev/null +++ b/TrafficAnalyzer/Program.cs @@ -0,0 +1,54 @@ +using Google.Protobuf; +using Protocol; + +namespace TrafficAnalyzer; + +internal static class Program +{ + private const int StdInSize = 65535; + private const string ProtoAssembly = "Protocol"; + private const string ProtoNamespace = "Protocol"; + private const string MessageParserProperty = "Parser"; + + private static readonly DumpOptions s_objectDumperOpts = new() { DumpStyle = DumpStyle.CSharp, IndentSize = 4, IndentChar = ' ' }; + + private static void Main(string[] args) + { + Console.SetIn(new StreamReader(Console.OpenStandardInput(StdInSize), Console.InputEncoding, false, StdInSize)); + + List> inList = []; + + string? idInput; + string? payloadInput; + + while (!string.IsNullOrEmpty(idInput = Console.ReadLine()) && !string.IsNullOrEmpty(payloadInput = Console.ReadLine())) + { + int messageId = int.Parse(idInput); + byte[] payload = Convert.FromHexString(payloadInput); + + inList.Add(Tuple.Create(messageId, payload)); + } + + Console.Clear(); + + foreach ((int messageId, byte[] payload) in inList) + { + string messageName = ((MessageId)messageId).ToString(); + + Type? type = Type.GetType($"{ProtoNamespace}.{messageName},{ProtoAssembly}"); + if (type is null) + { + Console.WriteLine($"Message with id {messageName} wasn't found in proto definition."); + continue; + } + + MessageParser parser = (MessageParser)type.GetProperty(MessageParserProperty)!.GetValue(null)!; + IMessage message = parser.ParseFrom(payload); + + string outputInitializer = ObjectDumper.Dump(message, s_objectDumperOpts); + + Console.WriteLine($"Message: {messageName}"); + Console.WriteLine(outputInitializer); + } + } +} diff --git a/TrafficAnalyzer/TrafficAnalyzer.csproj b/TrafficAnalyzer/TrafficAnalyzer.csproj new file mode 100644 index 0000000..951fc7a --- /dev/null +++ b/TrafficAnalyzer/TrafficAnalyzer.csproj @@ -0,0 +1,18 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + diff --git a/WutheringWaves.sln b/WutheringWaves.sln index f7e6c30..09f03eb 100644 --- a/WutheringWaves.sln +++ b/WutheringWaves.sln @@ -16,7 +16,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KcpSharp", "KcpSharp\KcpSha EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Protocol", "Protocol\Protocol.csproj", "{9900A88C-7818-4335-84F7-1538ECC8B338}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{C025BDED-6DC7-493D-8D10-05DCCB3072F3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{C025BDED-6DC7-493D-8D10-05DCCB3072F3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrafficAnalyzer", "TrafficAnalyzer\TrafficAnalyzer.csproj", "{7DA57BA1-215F-4DD8-86A9-CAC62908A6F3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -44,6 +46,10 @@ Global {C025BDED-6DC7-493D-8D10-05DCCB3072F3}.Debug|Any CPU.Build.0 = Debug|Any CPU {C025BDED-6DC7-493D-8D10-05DCCB3072F3}.Release|Any CPU.ActiveCfg = Release|Any CPU {C025BDED-6DC7-493D-8D10-05DCCB3072F3}.Release|Any CPU.Build.0 = Release|Any CPU + {7DA57BA1-215F-4DD8-86A9-CAC62908A6F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7DA57BA1-215F-4DD8-86A9-CAC62908A6F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7DA57BA1-215F-4DD8-86A9-CAC62908A6F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7DA57BA1-215F-4DD8-86A9-CAC62908A6F3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE