From 5aacdae4cb0b1bbe40c37520fd0d40a06b8b3593 Mon Sep 17 00:00:00 2001 From: LumaLivy Date: Sun, 7 Nov 2021 21:35:27 -0500 Subject: [PATCH] Fix bug with hex not deserializing in JSON, add CreateRoom matchType --- ProjectLighthouse/Helpers/MatchHelper.cs | 6 ++++++ ProjectLighthouse/Types/Match/CreateRoom.cs | 22 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ProjectLighthouse/Types/Match/CreateRoom.cs diff --git a/ProjectLighthouse/Helpers/MatchHelper.cs b/ProjectLighthouse/Helpers/MatchHelper.cs index e7e66895..b60a3891 100644 --- a/ProjectLighthouse/Helpers/MatchHelper.cs +++ b/ProjectLighthouse/Helpers/MatchHelper.cs @@ -1,6 +1,8 @@ #nullable enable +using System; using System.Linq; using System.Text.Json; +using System.Text.RegularExpressions; using LBPUnion.ProjectLighthouse.Types.Match; namespace LBPUnion.ProjectLighthouse.Helpers @@ -22,6 +24,9 @@ namespace LBPUnion.ProjectLighthouse.Helpers string matchData = $"{{{string.Concat(data.Skip(matchType.Length + 3).SkipLast(2))}}}"; + // JSON does not like the hex value that location comes in (0x7f000001) so, convert it to int + matchData = Regex.Replace(matchData, @"0x[a-fA-F0-9]{8}", m => Convert.ToInt32(m.Value, 16).ToString()); + return Deserialize(matchType, matchData); } @@ -31,6 +36,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers { "UpdateMyPlayerData" => JsonSerializer.Deserialize(matchData), "UpdatePlayersInRoom" => JsonSerializer.Deserialize(matchData), + "CreateRoom" => JsonSerializer.Deserialize(matchData), _ => null, }; } diff --git a/ProjectLighthouse/Types/Match/CreateRoom.cs b/ProjectLighthouse/Types/Match/CreateRoom.cs new file mode 100644 index 00000000..2a649c18 --- /dev/null +++ b/ProjectLighthouse/Types/Match/CreateRoom.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace LBPUnion.ProjectLighthouse.Types.Match +{ + [SuppressMessage("ReSharper", "CollectionNeverUpdated.Global")] + public class CreateRoom : IMatchData + { + //[CreateRoom,["Players":["LumaLivy"],"Reservations":["0"],"NAT":[2],"Slots":[[1,3]],"RoomState":0,"HostMood":1,"PassedNoJoinPoint":0,"Location":[0x7f000001],"Language":1,"BuildVersion":289,"Search":""]] + public List Players; + public List Reservations; + public List NAT; + public List> Slots; + public int RoomState; + public int HostMood; + public int PassedNoJoinPoint; + public List Location; + public int Language; + public int BuildVersion; + public string Search; + } +} \ No newline at end of file