forked from molenzwiebel/Mimic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeagueUtils.cs
67 lines (63 loc) · 2.72 KB
/
LeagueUtils.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
using System;
using System.Diagnostics;
using System.Linq;
using System.Management;
using System.Text.RegularExpressions;
namespace Conduit
{
/**
* Some static utilities used to interact/query the state of the league client process.
*/
static class LeagueUtils
{
private static Regex AUTH_TOKEN_REGEX = new Regex("\"--remoting-auth-token=(.+?)\"");
private static Regex PORT_REGEX = new Regex("\"--app-port=(\\d+?)\"");
/**
* Returns a tuple with the process, remoting auth token and port of the current league client.
* Returns null if the current league client is not running.
*/
public static Tuple<Process, string, string> GetLeagueStatus()
{
// Find the LeagueClientUx process.
foreach (var p in Process.GetProcessesByName("LeagueClientUx"))
{
// Use WMI to figure out its command line.
using (var mos = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + p.Id.ToString()))
using (var moc = mos.Get())
{
var commandLine = (string)moc.OfType<ManagementObject>().First()["CommandLine"];
if (commandLine == null) // We can't get the commandline sometimes without admin access, so let's elevate
{
if (Administrator.IsAdmin())
{
DebugLogger.Global.WriteError("We cannot determine why the commandline is null! Cannot get the League of Legends information from this process!");
continue;
}
else
{
Administrator.Elevate();
}
}
try
{
var authToken = AUTH_TOKEN_REGEX.Match(commandLine).Groups[1].Value;
var port = PORT_REGEX.Match(commandLine).Groups[1].Value;
// Use regex to extract data, return it.
return new Tuple<Process, string, string>
(
p,
authToken,
port
);
}
catch (Exception e)
{
DebugLogger.Global.WriteError($"Error while trying to get the status for LeagueClientUx: {e.ToString()}\n\n(CommandLine = {commandLine})");
}
}
}
// LeagueClientUx process was not found. Return null.
return null;
}
}
}