Skip to content

Commit

Permalink
More work on LauncherProcess protocol handling, and fill out GameEven…
Browse files Browse the repository at this point in the history
…t enum.

Based on research in #36.

Part of #5.
  • Loading branch information
alexrp committed May 24, 2022
1 parent 697c942 commit eb9b8fc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 37 deletions.
32 changes: 16 additions & 16 deletions src/client/Client/GameEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
29 changes: 12 additions & 17 deletions src/client/Client/LauncherProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -42,15 +44,13 @@ protected override (nuint Id, ReadOnlyMemory<byte> Payload)? HandleWindowMessage
var opts = Options;
var utf8 = Encoding.UTF8;

string? HandleGameEventOrExit(ReadOnlySpan<byte> 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;
Expand All @@ -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,
};

Expand Down
10 changes: 6 additions & 4 deletions src/tools/run/Commands/LauncherCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit eb9b8fc

Please sign in to comment.