-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInitiator.cs
170 lines (142 loc) · 6.16 KB
/
Initiator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using System.Data;
using RadiantConnect.EventHandler;
using RadiantConnect.Services;
using RadiantConnect.Network;
using RadiantConnect.Network.ChatEndpoints;
using RadiantConnect.Network.ContractEndpoints;
using RadiantConnect.Network.CurrentGameEndpoints;
using RadiantConnect.Network.LocalEndpoints;
using RadiantConnect.Network.PartyEndpoints;
using RadiantConnect.Network.PreGameEndpoints;
using RadiantConnect.Network.PVPEndpoints;
using RadiantConnect.Network.StoreEndpoints;
using System.Diagnostics;
using System.Text.Json;
using RadiantConnect.Authentication.DriverRiotAuth.Records;
using System.Text.Json.Serialization;
using Microsoft.IdentityModel.JsonWebTokens;
using RadiantConnect.Utilities;
namespace RadiantConnect
{
public record InternalSystem(
ValorantService ValorantClient,
ValorantNet Net,
LogService LogService,
LogService.ClientData ClientData
);
public record Endpoints(
ChatEndpoints ChatEndpoints,
ContractEndpoints ContractEndpoints,
CurrentGameEndpoints CurrentGameEndpoints,
LocalEndpoints LocalEndpoints,
PartyEndpoints PartyEndpoints,
PreGameEndpoints PreGameEndpoints,
PVPEndpoints PvpEndpoints,
StoreEndpoints StoreEndpoints
);
public record GeoAffinities(
[property: JsonPropertyName("pbe")] string Pbe,
[property: JsonPropertyName("live")] string Live
);
public record GeoRoot(
[property: JsonPropertyName("token")] string Token,
[property: JsonPropertyName("affinities")] GeoAffinities Affinities
);
public class Initiator
{
internal static bool ClientIsReady() =>
InternalValorantMethods.IsValorantProcessRunning() &&
Directory.Exists(Path.GetDirectoryName(LogService.GetLogPath())) &&
File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "AppData",
"Local", "Riot Games", "Riot Client", "Config", "lockfile")) &&
File.Exists(LogService.GetLogPath()) &&
!LogService.GetLogText().Split('\n').Last().Contains("Log file closed");
internal static string IsVpnDetected() => string.Join('|', Process.GetProcesses().Where(process => process.ProcessName.Contains("vpn", StringComparison.CurrentCultureIgnoreCase)));
public InternalSystem ExternalSystem { get; private set; } = null!;
public Endpoints Endpoints { get; private set; } = null!;
public GameEvents GameEvents { get; internal set; } = null!;
public LogService.ClientData Client { get; private set; } = null!;
internal async Task<LogService.ClientData> BuildClientData(ValorantNet net, RSOAuth rsoAuth)
{
if (net == null) throw new RadiantConnectException("Failed to build net data");
GeoRoot? data = await net.PutAsync<GeoRoot>(
"https://riot-geo.pas.si.riotgames.com",
"/pas/v1/product/valorant",
new StringContent($"{{\"id_token\": \"{rsoAuth.IdToken}\"}}")
);
Enum.TryParse(data?.Affinities.Live, true, out LogService.ClientData.ShardType shard);
JsonWebToken token = new (data?.Token);
string userId = token.GetPayloadValue<string>("sub");
return new LogService.ClientData(
Shard: shard,
UserId: userId,
PdUrl: $"https://pd.{shard}.a.pvp.net",
GlzUrl: $"https://glz-{data?.Affinities.Live}-1.{shard}.a.pvp.net",
SharedUrl: $"https://shared.{shard}.a.pvp.net"
);
}
internal void Initialize(ValorantNet net, RSOAuth rsoAuth)
{
Client = BuildClientData(net, rsoAuth).Result;
ExternalSystem = new InternalSystem(
null!,
net,
null!,
Client
);
Endpoints = new Endpoints(
new ChatEndpoints(this),
new ContractEndpoints(this),
new CurrentGameEndpoints(this),
null!,
new PartyEndpoints(this),
new PreGameEndpoints(this),
new PVPEndpoints(this),
new StoreEndpoints(this)
);
}
[Obsolete("Method is no longer supported, move to RSOAuth", true)]
public Initiator(RadiantConnectRSO ssid) => throw new RowNotInTableException("Method is no longer supported, move to RSOAuth");
public Initiator(RSOAuth rsoAuth)
{
ValorantNet net = new(rsoAuth);
Initialize(net, rsoAuth);
}
public Initiator(bool ignoreVpn = true)
{
DateTime startTime = DateTime.Now;
TimeSpan timeout = TimeSpan.FromMinutes(1);
while (!ClientIsReady())
{
if (DateTime.Now - startTime > timeout)
throw new TimeoutException("Client did not become ready within 1 minute.");
Task.Delay(2000);
}
ValorantService client = new();
LogService logService = new();
LogService.ClientData cData = LogService.GetClientData();
ValorantNet net = new(client);
string vpnDetected = IsVpnDetected();
if (!string.IsNullOrEmpty(vpnDetected) && !ignoreVpn)
throw new RadiantConnectException($"Can not run with VPN running, found processes: {vpnDetected}. \n\nTo bypass this check launch Initiator with (true)");
ExternalSystem = new InternalSystem(
client,
net,
logService,
cData
);
Client = cData;
Endpoints = new Endpoints(
new ChatEndpoints(this),
new ContractEndpoints(this),
new CurrentGameEndpoints(this),
new LocalEndpoints(this),
new PartyEndpoints(this),
new PreGameEndpoints(this),
new PVPEndpoints(this),
new StoreEndpoints(this)
);
_ = LogService.InitiateEvents(this);
}
}
}