Fix bug with hex not deserializing in JSON, add CreateRoom matchType

This commit is contained in:
LumaLivy 2021-11-07 21:35:27 -05:00
commit 5aacdae4cb
2 changed files with 28 additions and 0 deletions

View file

@ -1,6 +1,8 @@
#nullable enable #nullable enable
using System;
using System.Linq; using System.Linq;
using System.Text.Json; using System.Text.Json;
using System.Text.RegularExpressions;
using LBPUnion.ProjectLighthouse.Types.Match; using LBPUnion.ProjectLighthouse.Types.Match;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers
@ -22,6 +24,9 @@ namespace LBPUnion.ProjectLighthouse.Helpers
string matchData = $"{{{string.Concat(data.Skip(matchType.Length + 3).SkipLast(2))}}}"; 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); return Deserialize(matchType, matchData);
} }
@ -31,6 +36,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
{ {
"UpdateMyPlayerData" => JsonSerializer.Deserialize<UpdateMyPlayerData>(matchData), "UpdateMyPlayerData" => JsonSerializer.Deserialize<UpdateMyPlayerData>(matchData),
"UpdatePlayersInRoom" => JsonSerializer.Deserialize<UpdatePlayersInRoom>(matchData), "UpdatePlayersInRoom" => JsonSerializer.Deserialize<UpdatePlayersInRoom>(matchData),
"CreateRoom" => JsonSerializer.Deserialize<CreateRoom>(matchData),
_ => null, _ => null,
}; };
} }

View file

@ -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<string> Players;
public List<string> Reservations;
public List<int> NAT;
public List<List<int>> Slots;
public int RoomState;
public int HostMood;
public int PassedNoJoinPoint;
public List<int> Location;
public int Language;
public int BuildVersion;
public string Search;
}
}