mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 16:38:37 +00:00
Fix match deserialization not reading 7-digit hex values
This commit is contained in:
parent
777ba3ef59
commit
be7200aaf0
2 changed files with 11 additions and 4 deletions
|
@ -6,6 +6,7 @@ using System.Text.Json;
|
|||
using System.Threading.Tasks;
|
||||
using Kettu;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Match;
|
||||
|
@ -53,8 +54,10 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Logger.Log("Exception while parsing MatchData: " + e, LoggerLevelMatch.Instance);
|
||||
Logger.Log("Data: " + bodyString, LoggerLevelMatch.Instance);
|
||||
Logger.Log("Exception while parsing matchData: ", LoggerLevelMatch.Instance);
|
||||
string[] lines = e.ToDetailedException().Split("\n");
|
||||
foreach (string line in lines) Logger.Log(line, LoggerLevelMatch.Instance);
|
||||
Logger.Log("Associated matchData: " + bodyString, LoggerLevelMatch.Instance);
|
||||
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
@ -62,7 +65,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
if (matchData == null)
|
||||
{
|
||||
Logger.Log("Could not parse match data: matchData is null", LoggerLevelMatch.Instance);
|
||||
Logger.Log("Data: " + bodyString, LoggerLevelMatch.Instance);
|
||||
Logger.Log("Associated matchData: " + bodyString, LoggerLevelMatch.Instance);
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
|||
return recentlyDivedIn.Contains(otherUserId);
|
||||
}
|
||||
|
||||
// This is the function used to show people how laughably awful LBP's protocol is. Beware.
|
||||
public static IMatchData? Deserialize(string data)
|
||||
{
|
||||
string matchType = "";
|
||||
|
@ -49,10 +50,13 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
|||
i++;
|
||||
}
|
||||
|
||||
string matchData = $"{{{string.Concat(data.Skip(matchType.Length + 3).SkipLast(2))}}}";
|
||||
string matchData = $"{{{string.Concat(data.Skip(matchType.Length + 3).SkipLast(2))}}}"; // unfuck formatting so we can parse it as json
|
||||
|
||||
// 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());
|
||||
// oh, but it gets better than that! LBP also likes to send hex values with an uneven amount of digits (0xa000064, 7 digits). in any case, we handle it here:
|
||||
matchData = Regex.Replace(matchData, @"0x[a-fA-F0-9]{7}", m => Convert.ToInt32(m.Value, 16).ToString());
|
||||
// i'm actually crying about it.
|
||||
|
||||
return Deserialize(matchType, matchData);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue