-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLCU.cs
114 lines (99 loc) · 3.72 KB
/
LCU.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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LeaguePW5
{
public class LCU
{
public string address { get; set; }
public int port { get; set; }
public string username { get; set; }
public string password { get; set; }
public string protocol { get; set; }
public string process_name { get; set; }
public int process_id { get; set; }
public string baseURL => string.Format("{0}://{1}:{2}", this.protocol, this.address, this.port);
public LCU()
{
LoadLCU();
}
public void LoadLCU()
{
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate (
object sender,
X509Certificate cert,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
};
Process[] process = Process.GetProcessesByName("LeagueClientUx");
if (process.Length != 0)
{
try
{
string lockFile;
using (FileStream stream = File.Open(Path.Combine(Path.GetDirectoryName(process[0].MainModule.FileName), "lockfile"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
lockFile = new StreamReader(stream).ReadToEnd();
}
string[] parameters = lockFile.Split(new string[] { ":" }, StringSplitOptions.None);
this.username = "riot";
this.address = "127.0.0.1";
this.process_name = parameters[0];
this.process_id = Convert.ToInt32(parameters[1]);
this.port = Convert.ToInt32(parameters[2]);
this.password = parameters[3];
this.protocol = parameters[4];
}
catch(Exception ex)
{
MessageBox.Show("client not found");
}
}
}
public HttpClient http_client
{
get
{
HttpClientHandler httpClientHandler = new HttpClientHandler();
//httpClientHandler.ClientCertificateOptions = ClientCertificateOption.Manual;
//httpClientHandler.ServerCertificateCustomValidationCallback = ((HttpRequestMessage httpRequestMessage, X509Certificate2 cert, X509Chain cetChain, SslPolicyErrors policyErrors) => true);
return new HttpClient(httpClientHandler)
{
DefaultRequestHeaders =
{
Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes("riot:" + this.password)))
}
};
}
set
{
}
}
public async Task<HttpResponseMessage> PostData(string url, ByteArrayContent content)
{
try
{
return await http_client.PostAsync(url, content);
}
catch (Exception ex)
{
throw;
//MessageBox.Show("LCU Failed Restart Please");
}
return null;
}
}
}