From eb9b8fc62e63368091b446a818f260ebb72724e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Wed, 25 May 2022 00:18:21 +0200 Subject: [PATCH] More work on LauncherProcess protocol handling, and fill out GameEvent enum. Based on research in #36. Part of #5. --- src/client/Client/GameEvent.cs | 32 +++++++++++------------ src/client/Client/LauncherProcess.cs | 29 +++++++++----------- src/tools/run/Commands/LauncherCommand.cs | 10 ++++--- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/client/Client/GameEvent.cs b/src/client/Client/GameEvent.cs index c4a02bb..56a721e 100644 --- a/src/client/Client/GameEvent.cs +++ b/src/client/Client/GameEvent.cs @@ -3,20 +3,20 @@ namespace Vezel.Novadrop.Client; [SuppressMessage("", "CA1008")] public enum GameEvent { - Unknown1001 = 1001, - Unknown1002 = 1002, - Unknown1003 = 1003, - Unknown1004 = 1004, - Unknown1005 = 1005, - Unknown1006 = 1006, - Unknown1007 = 1007, - Unknown1008 = 1008, - Unknown1009 = 1009, - Unknown1010 = 1010, - Unknown1011 = 1011, - Unknown1012 = 1012, - PegasusOn = 1014, - PegasusOff = 1015, - Unknown1013 = 1013, - Unknown1016 = 1016, + RequestedServerList = 1001, + ReceivedServerList = 1002, + LoggedIn = 1003, + EnteredLobby = 1004, + EnteringCharacterCreation = 1005, + LoggedOut = 1006, + DeletedCharacter = 1007, + CanceledCharacterCreation = 1008, + EnteredCharacterCreation = 1009, + CreatedCharacter = 1010, + EnteredWorld = 1011, + FinishedLoadingScreen = 1012, + LeftWorld = 1013, + MountedPegasus = 1014, + DismountedPegasus = 1015, + ChangedChannel = 1016, } diff --git a/src/client/Client/LauncherProcess.cs b/src/client/Client/LauncherProcess.cs index 433c0ef..978d1a6 100644 --- a/src/client/Client/LauncherProcess.cs +++ b/src/client/Client/LauncherProcess.cs @@ -18,6 +18,8 @@ public sealed class LauncherProcess : GameProcess static readonly Regex _endPopup = new(@"endPopup\((\d+)\)"); + static readonly Regex _getWebLinkUrl = new(@"getWebLinkUrl\((\d+),(.*)\)"); + public LauncherProcess(LauncherProcessOptions options) { ArgumentNullException.ThrowIfNull(options); @@ -42,15 +44,13 @@ protected override (nuint Id, ReadOnlyMemory Payload)? HandleWindowMessage var opts = Options; var utf8 = Encoding.UTF8; - string? HandleGameEventOrExit(ReadOnlySpan payload) + string? HandleGameEventOrExit(string value) { - // gameEvent(%d), endPopup(%d), csPopup(), promoPopup(%d) - - var text = utf8.GetString(payload); + // csPopup(), endPopup(%d), gameEvent(%d), promoPopup(%d) - if (_gameEvent.Match(text) is { Success: true } m1) + if (_gameEvent.Match(value) is { Success: true } m1) GameEventOccurred?.Invoke((GameEvent)int.Parse(m1.Captures[0].ValueSpan)); - else if (_endPopup.Match(text) is { Success: true } m2) + else if (_endPopup.Match(value) is { Success: true } m2) GameExited?.Invoke((int)uint.Parse(m2.Captures[0].ValueSpan)); return null; @@ -77,18 +77,13 @@ string HandleWebUriRequest() return string.Empty; } - var replyPayload = id switch + var replyPayload = (id, utf8.GetString(payload)) switch { - 0x0dbadb0a => "Hello!!", // Hello!! - 0 => HandleGameEventOrExit(payload), - 2 => HandleServerListUriRequest(), // slsurl - 3 => HandleGameInfoRequest(), // gamestr - 4 => null, // ticket - 5 => null, // last_svr - 6 => null, // char_cnt - 7 => null, - 8 => null, // ticket - 10 => HandleWebUriRequest(), // getWebLinkUrl(%d,%s) + (0x0dbadb0a, "Hello!!\0") => "Hello!!", + (0, var value) => HandleGameEventOrExit(value), + (_, "slsurl\0") => HandleServerListUriRequest(), + (_, "gamestr\0" or "ticket\0" or "last_svr\0" or "char_cnt\0") => HandleGameInfoRequest(), + (_, var value) when _getWebLinkUrl.IsMatch(value) => HandleWebUriRequest(), _ => null, }; diff --git a/src/tools/run/Commands/LauncherCommand.cs b/src/tools/run/Commands/LauncherCommand.cs index 01c7fb8..37249b8 100644 --- a/src/tools/run/Commands/LauncherCommand.cs +++ b/src/tools/run/Commands/LauncherCommand.cs @@ -41,10 +41,12 @@ public LauncherCommand() { Console.WriteLine("Running launcher and connecting to '{0}'...", url); - context.ExitCode = await new LauncherProcess( - new LauncherProcessOptions(executable.FullName, account, ticket, url) - .WithLastServerId(serverId)) - .RunAsync(cancellationToken); + var opts = new LauncherProcessOptions(executable.FullName, account, ticket, url); + + if (serverId != 0) + opts = opts.WithLastServerId(serverId); + + context.ExitCode = await new LauncherProcess(opts).RunAsync(cancellationToken); }, executableArg, accountArg,