From b9ac21dc3facf21608f0caaafe4c5fc97bb75db7 Mon Sep 17 00:00:00 2001 From: Soneliem Date: Tue, 17 Aug 2021 13:00:31 +0930 Subject: [PATCH 1/5] Test1 --- WAIUA/Commands/APIConnection.cs | 98 +++++++++++++++++---------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/WAIUA/Commands/APIConnection.cs b/WAIUA/Commands/APIConnection.cs index 87b8901..4f8c658 100644 --- a/WAIUA/Commands/APIConnection.cs +++ b/WAIUA/Commands/APIConnection.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json.Linq; using RestSharp; using System; +using System.Collections.Concurrent; using System.IO; using System.Net; using System.Text; @@ -45,6 +46,41 @@ public static class APIConnection public static string[] PPGList { get; set; } = new string[10]; public static string[] PPPGList { get; set; } = new string[10]; + private static ConcurrentDictionary url_to_body = new(); + + public static string DoCachedRequest(Method method, String url, bool add_riot_auth, CookieContainer cookie_container = null, bool bypass_cache = false) // Thank you MitchC for this, I am always touched when random people go out of the way to help others even though they know that we would be clueless and need to ask alot of followup questions + { + var tsk = DoCachedRequestAsync(method, url, add_riot_auth, cookie_container, bypass_cache); + return tsk.Result; + } + + public static async Task DoCachedRequestAsync(Method method, String url, bool add_riot_auth, CookieContainer cookie_container = null, bool bypass_cache = false) + { + var attempt_cache = method == Method.GET && !bypass_cache; + if (attempt_cache) + { + if (url_to_body.TryGetValue(url, out var res)) + { + return res; + } + } + RestClient client = new RestClient(url); + if (cookie_container != null) + client.CookieContainer = cookie_container; + RestRequest request = new RestRequest(method); + if (add_riot_auth) + { + request.AddHeader("X-Riot-Entitlements-JWT", $"{EntitlementToken}"); + request.AddHeader("Authorization", $"Bearer {AccessToken}"); + request.AddHeader("X-Riot-ClientPlatform", "ew0KCSJwbGF0Zm9ybVR5cGUiOiAiUEMiLA0KCSJwbGF0Zm9ybU9TIjogIldpbmRvd3MiLA0KCSJwbGF0Zm9ybU9TVmVyc2lvbiI6ICIxMC4wLjE5MDQyLjEuMjU2LjY0Yml0IiwNCgkicGxhdGZvcm1DaGlwc2V0IjogIlVua25vd24iDQp9"); + request.AddHeader("X-Riot-ClientVersion", $"{Version}"); + } + var cont = (await client.ExecuteAsync(request)).Content; + if (attempt_cache) + url_to_body.TryAdd(url, cont); + return cont; + } + public static void Login(CookieContainer cookie, string username, string password) { try @@ -161,7 +197,7 @@ public static void LocalRegion() RestClient client = new RestClient(new Uri($"https://127.0.0.1:{Port}/product-session/v1/external-sessions")); RestRequest request = new RestRequest(Method.GET); client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; - request.AddHeader("Authorization", $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes($"riot:{LPassword}"))}"); + request.AddHeader("Authorization", $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes($"riot:{LPassword}"))}"); request.AddHeader("X-Riot-ClientPlatform", "ew0KCSJwbGF0Zm9ybVR5cGUiOiAiUEMiLA0KCSJwbGF0Zm9ybU9TIjogIldpbmRvd3MiLA0KCSJwbGF0Zm9ybU9TVmVyc2lvbiI6ICIxMC4wLjE5MDQyLjEuMjU2LjY0Yml0IiwNCgkicGxhdGZvcm1DaGlwc2V0IjogIlVua25vd24iDQp9"); request.AddHeader("X-Riot-ClientVersion", $"{Version}"); request.RequestFormat = RestSharp.DataFormat.Json; @@ -333,12 +369,8 @@ public static void GetAgentInfo(string agent, int playerno) { try { - string url = $"https://valorant-api.com/v1/agents/{agent}"; - RestClient client = new RestClient(url); - RestRequest request = new RestRequest(Method.GET); - - string response = client.Execute(request).Content; - var agentinfo = JsonConvert.DeserializeObject(response); + string content = DoCachedRequest(Method.GET, $"https://valorant-api.com/v1/agents/{agent}", false, null, false); + var agentinfo = JsonConvert.DeserializeObject(content); JToken agentinfoObj = JObject.FromObject(agentinfo); AgentPList[playerno] = agentinfoObj["data"]["killfeedPortrait"].Value(); AgentList[playerno] = agentinfoObj["data"]["displayName"].Value(); @@ -353,12 +385,8 @@ public static void GetCardInfo(string card, int playerno) { try { - string url = $"https://valorant-api.com/v1/playercards/{card}"; - RestClient client = new RestClient(url); - RestRequest request = new RestRequest(Method.GET); - - string response = client.Execute(request).Content; - var agentinfo = JsonConvert.DeserializeObject(response); + string content = DoCachedRequest(Method.GET, $"https://valorant-api.com/v1/playercards/{card}", false, null, false); + var agentinfo = JsonConvert.DeserializeObject(content); JToken agentinfoObj = JObject.FromObject(agentinfo); CardList[playerno] = agentinfoObj["data"]["smallArt"].Value(); } @@ -372,14 +400,8 @@ public static void GetCompHistory(string puuid, int playerno) { try { - string url = $"https://pd.{Region}.a.pvp.net/mmr/v1/players/{puuid}/competitiveupdates?queue=competitive"; - RestClient client = new RestClient(url); - RestRequest request = new RestRequest(Method.GET); - request.AddHeader("X-Riot-Entitlements-JWT", $"{EntitlementToken}"); - request.AddHeader("Authorization", $"Bearer {AccessToken}"); - request.AddHeader("X-Riot-ClientPlatform", "ew0KCSJwbGF0Zm9ybVR5cGUiOiAiUEMiLA0KCSJwbGF0Zm9ybU9TIjogIldpbmRvd3MiLA0KCSJwbGF0Zm9ybU9TVmVyc2lvbiI6ICIxMC4wLjE5MDQyLjEuMjU2LjY0Yml0IiwNCgkicGxhdGZvcm1DaGlwc2V0IjogIlVua25vd24iDQp9"); - string response = client.Execute(request).Content; - var historyinfo = JsonConvert.DeserializeObject(response); + string content = DoCachedRequest(Method.GET, $"https://pd.{Region}.a.pvp.net/mmr/v1/players/{puuid}/competitiveupdates?queue=competitive", true, null, true); + var historyinfo = JsonConvert.DeserializeObject(content); JToken historyinfoObj = JObject.FromObject(historyinfo); RankProgList[playerno] = historyinfoObj["Matches"][0]["RankedRatingAfterUpdate"].Value(); if (historyinfoObj["Matches"][0]["RankedRatingEarned"].Value() >= 0) @@ -418,14 +440,7 @@ public static void GetPlayerHistory(string puuid, int playerno) try { string rank, prank, pprank, ppprank = ""; - string url = $"https://pd.{Region}.a.pvp.net/mmr/v1/players/{puuid}"; - RestClient client = new RestClient(url); - RestRequest request = new RestRequest(Method.GET); - request.AddHeader("X-Riot-Entitlements-JWT", $"{EntitlementToken}"); - request.AddHeader("Authorization", $"Bearer {AccessToken}"); - request.AddHeader("X-Riot-ClientPlatform", "ew0KCSJwbGF0Zm9ybVR5cGUiOiAiUEMiLA0KCSJwbGF0Zm9ybU9TIjogIldpbmRvd3MiLA0KCSJwbGF0Zm9ybU9TVmVyc2lvbiI6ICIxMC4wLjE5MDQyLjEuMjU2LjY0Yml0IiwNCgkicGxhdGZvcm1DaGlwc2V0IjogIlVua25vd24iDQp9"); - request.AddHeader("X-Riot-ClientVersion", $"{Version}"); - string content = client.Execute(request).Content; + string content = DoCachedRequest(Method.GET, $"https://pd.{Region}.a.pvp.net/mmr/v1/players/{puuid}", true, null, true); dynamic contentobj = JObject.Parse(content); /*try @@ -475,14 +490,7 @@ private static void GetSeasons() { try { - string url = $"https://shared.{Region}.a.pvp.net/content-service/v2/content"; - RestClient client = new RestClient(url); - RestRequest request = new RestRequest(Method.GET); - request.AddHeader("X-Riot-Entitlements-JWT", $"{EntitlementToken}"); - request.AddHeader("Authorization", $"Bearer {AccessToken}"); - request.AddHeader("X-Riot-ClientPlatform", "ew0KCSJwbGF0Zm9ybVR5cGUiOiAiUEMiLA0KCSJwbGF0Zm9ybU9TIjogIldpbmRvd3MiLA0KCSJwbGF0Zm9ybU9TVmVyc2lvbiI6ICIxMC4wLjE5MDQyLjEuMjU2LjY0Yml0IiwNCgkicGxhdGZvcm1DaGlwc2V0IjogIlVua25vd24iDQp9"); - request.AddHeader("X-Riot-ClientVersion", $"{Version}"); - string response = client.Execute(request).Content; + string response = DoCachedRequest(Method.GET, $"https://shared.{Region}.a.pvp.net/content-service/v2/content", true); dynamic content = JsonConvert.DeserializeObject(response); int index = 0; @@ -536,11 +544,8 @@ private static void GetSeasons() public static string GetLRankIcon(string rank) { - string url = $"https://valorant-api.com/v1/competitivetiers"; - RestClient client = new RestClient(url); - RestRequest request = new RestRequest(Method.GET); - string response = client.Execute(request).Content; - dynamic agentinfo = JsonConvert.DeserializeObject(response); + string content = DoCachedRequest(Method.GET, "https://valorant-api.com/v1/competitivetiers", false); + dynamic agentinfo = JsonConvert.DeserializeObject(content); string output = ""; foreach (var tiers in agentinfo.data[2].tiers) { @@ -553,13 +558,10 @@ public static string GetLRankIcon(string rank) return output; } - public static string GetRankIcon(string rank) + private static string GetRankIcon(string rank) { - string url = $"https://valorant-api.com/v1/competitivetiers"; - RestClient client = new RestClient(url); - RestRequest request = new RestRequest(Method.GET); - string response = client.Execute(request).Content; - dynamic agentinfo = JsonConvert.DeserializeObject(response); + string content = DoCachedRequest(Method.GET, "https://valorant-api.com/v1/competitivetiers", false); + dynamic agentinfo = JsonConvert.DeserializeObject(content); string output = ""; foreach (var tiers in agentinfo.data[2].tiers) { From 1596597de5d47c551d31fd8b10cf06be422c1a0c Mon Sep 17 00:00:00 2001 From: Soneliem Date: Tue, 17 Aug 2021 13:15:00 +0930 Subject: [PATCH 2/5] Not working --- WAIUA/Commands/APIConnection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WAIUA/Commands/APIConnection.cs b/WAIUA/Commands/APIConnection.cs index 4f8c658..e364488 100644 --- a/WAIUA/Commands/APIConnection.cs +++ b/WAIUA/Commands/APIConnection.cs @@ -197,7 +197,7 @@ public static void LocalRegion() RestClient client = new RestClient(new Uri($"https://127.0.0.1:{Port}/product-session/v1/external-sessions")); RestRequest request = new RestRequest(Method.GET); client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; - request.AddHeader("Authorization", $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes($"riot:{LPassword}"))}"); + request.AddHeader("Authorization", $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes($"riot:{LPassword}"))}"); request.AddHeader("X-Riot-ClientPlatform", "ew0KCSJwbGF0Zm9ybVR5cGUiOiAiUEMiLA0KCSJwbGF0Zm9ybU9TIjogIldpbmRvd3MiLA0KCSJwbGF0Zm9ybU9TVmVyc2lvbiI6ICIxMC4wLjE5MDQyLjEuMjU2LjY0Yml0IiwNCgkicGxhdGZvcm1DaGlwc2V0IjogIlVua25vd24iDQp9"); request.AddHeader("X-Riot-ClientVersion", $"{Version}"); request.RequestFormat = RestSharp.DataFormat.Json; @@ -558,7 +558,7 @@ public static string GetLRankIcon(string rank) return output; } - private static string GetRankIcon(string rank) + public static string GetRankIcon(string rank) { string content = DoCachedRequest(Method.GET, "https://valorant-api.com/v1/competitivetiers", false); dynamic agentinfo = JsonConvert.DeserializeObject(content); From f8844cf4786c3192bda108b8cd022345658f0064 Mon Sep 17 00:00:00 2001 From: Soneliem Date: Mon, 23 Aug 2021 15:53:25 +0930 Subject: [PATCH 3/5] Added incognito detection and fix deathmax --- WAIUA/App.xaml.cs | 2 +- WAIUA/Commands/APIConnection.cs | 35 ++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/WAIUA/App.xaml.cs b/WAIUA/App.xaml.cs index 6da2b2c..3487ad8 100644 --- a/WAIUA/App.xaml.cs +++ b/WAIUA/App.xaml.cs @@ -6,7 +6,7 @@ public partial class App : Application { private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { - MessageBox.Show("An unhandled exception just occurred: " + e.Exception.Message, "Exception Sample", MessageBoxButton.OK, MessageBoxImage.Warning); + MessageBox.Show("An unhandled exception just occurred: " + e.Exception.Message, e.Exception.Source, MessageBoxButton.OK, MessageBoxImage.Warning); e.Handled = true; } } diff --git a/WAIUA/Commands/APIConnection.cs b/WAIUA/Commands/APIConnection.cs index 22eab56..057cf68 100644 --- a/WAIUA/Commands/APIConnection.cs +++ b/WAIUA/Commands/APIConnection.cs @@ -46,6 +46,7 @@ public static class APIConnection public static string[] PPGList { get; set; } = new string[10]; public static string[] PPPGList { get; set; } = new string[10]; public static string[] TitleList { get; set; } = new string[10]; + public static bool[] IsIncognito { get; set; } = new bool[10]; private static ConcurrentDictionary url_to_body = new(); public static string DoCachedRequest(Method method, String url, bool add_riot_auth, CookieContainer cookie_container = null, bool bypass_cache = false) // Thank you MitchC for this, I am always touched when random people go out of the way to help others even though they know that we would be clueless and need to ask alot of followup questions @@ -90,8 +91,8 @@ public static void Login(CookieContainer cookie, string username, string passwor JToken authObj = JObject.FromObject(authJson); string authURL = authObj["response"]["parameters"]["uri"].Value(); - var access_tokenVar = Regex.Match(authURL, @"access_token=(.+?)&scope=").Groups[1].Value; - AccessToken = $"{access_tokenVar}"; + var accessTokenVar = Regex.Match(authURL, @"access_token=(.+?)&scope=").Groups[1].Value; + AccessToken = $"{accessTokenVar}"; RestClient client = new RestClient(new Uri("https://entitlements.auth.riotgames.com/api/token/v1")); RestRequest request = new RestRequest(Method.POST); @@ -154,7 +155,7 @@ public static string Authenticate(CookieContainer cookie, string user, string pa return client.Execute(request).Content; } - public static Boolean CheckLocal() + public static bool CheckLocal() { var lockfileLocation = $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\Riot Games\Riot Client\Config\lockfile"; @@ -318,16 +319,25 @@ public static void LiveMatchSetup() string[] card = new string[10]; string[] level = new string[10]; string[] title = new string[10]; + bool[] incognito = new bool[10]; int index = 0; foreach (var entry in matchinfo.Players) { - playerno[index] = index; - puuid[index] = entry.Subject; - agent[index] = entry.CharacterID; - card[index] = entry.PlayerIdentity.PlayerCardID; - level[index] = entry.PlayerIdentity.AccountLevel; - title[index] = entry.PlayerIdentity.PlayerTitleID; - index++; + if (entry.IsCoach == false) + { + playerno[index] = index; + puuid[index] = entry.Subject; + agent[index] = entry.CharacterID; + card[index] = entry.PlayerIdentity.PlayerCardID; + level[index] = entry.PlayerIdentity.AccountLevel; + title[index] = entry.PlayerIdentity.PlayerTitleID; + if (entry.PlayerIdentity.Incognito == true) + { + incognito[index] = true; + } + index++; + if (index == 10){ break; } + } } PlayerNo = playerno; PUUIDList = puuid; @@ -335,10 +345,13 @@ public static void LiveMatchSetup() CardList = card; LevelList = level; TitleList = title; + IsIncognito = incognito; + System.Diagnostics.Debug.WriteLine(IsIncognito); } } - catch (Exception) + catch (Exception e) { + System.Diagnostics.Debug.WriteLine(e); } } From fd5138243059418923ba83be03f00336176b5719 Mon Sep 17 00:00:00 2001 From: Soneliem Date: Mon, 23 Aug 2021 16:20:30 +0930 Subject: [PATCH 4/5] Streamer thing completed --- WAIUA/Commands/APIConnection.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/WAIUA/Commands/APIConnection.cs b/WAIUA/Commands/APIConnection.cs index 057cf68..fa99df5 100644 --- a/WAIUA/Commands/APIConnection.cs +++ b/WAIUA/Commands/APIConnection.cs @@ -357,9 +357,9 @@ public static void LiveMatchSetup() public static string[] LiveMatchOutput(int playerno) { - CookieContainer cookie = new CookieContainer(); + Parallel.Invoke( - () => PlayerList[playerno] = GetIGUsername(cookie, PUUIDList[playerno]), + () => GetIGCUsername(playerno), () => GetAgentInfo(AgentList[playerno], playerno), () => GetCardInfo(CardList[playerno], playerno), () => GetTitleInfo(TitleList[playerno], playerno), @@ -385,6 +385,19 @@ public static string[] LiveMatchOutput(int playerno) return output; } + public static void GetIGCUsername(int playerno) + { + CookieContainer cookie = new CookieContainer(); + if (IsIncognito[playerno]) + { + PlayerList[playerno] = "----"; + } + else + { + PlayerList[playerno] = GetIGUsername(cookie, PUUIDList[playerno]); + } + } + public static void GetAgentInfo(string agent, int playerno) { try From 082e5097c415b501378d876664e15595a1463541 Mon Sep 17 00:00:00 2001 From: Soneliem Date: Mon, 23 Aug 2021 16:24:15 +0930 Subject: [PATCH 5/5] Remove unnecessary code --- WAIUA/Commands/APIConnection.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/WAIUA/Commands/APIConnection.cs b/WAIUA/Commands/APIConnection.cs index fa99df5..0e64d7e 100644 --- a/WAIUA/Commands/APIConnection.cs +++ b/WAIUA/Commands/APIConnection.cs @@ -21,8 +21,6 @@ public static class APIConnection public static string PUUID { get; set; } public static string Matchid { get; set; } public static string IGN { get; set; } - public static string INusername { get; set; } - public static string INpassword { get; set; } public static string Port { get; set; } public static string LPassword { get; set; } public static string Protocol { get; set; } @@ -336,7 +334,7 @@ public static void LiveMatchSetup() incognito[index] = true; } index++; - if (index == 10){ break; } + if (index == 10) { break; } } } PlayerNo = playerno; @@ -346,7 +344,6 @@ public static void LiveMatchSetup() LevelList = level; TitleList = title; IsIncognito = incognito; - System.Diagnostics.Debug.WriteLine(IsIncognito); } } catch (Exception e) @@ -357,7 +354,6 @@ public static void LiveMatchSetup() public static string[] LiveMatchOutput(int playerno) { - Parallel.Invoke( () => GetIGCUsername(playerno), () => GetAgentInfo(AgentList[playerno], playerno),