diff --git a/ValorantCC/MainWindow.xaml.cs b/ValorantCC/MainWindow.xaml.cs index e4a8d21..fc4d07c 100644 --- a/ValorantCC/MainWindow.xaml.cs +++ b/ValorantCC/MainWindow.xaml.cs @@ -11,6 +11,8 @@ using System.Windows.Shapes; using Utilities; using ValorantCC.src; +using System.Threading; +using System.Threading.Tasks; namespace ValorantCC { @@ -97,7 +99,7 @@ private void btnLogin_Click(object sender, RoutedEventArgs e) profiles.IsReadOnly = false; MessageBox.Show(Utils.LoginResponse(DataProcessor)); btnLogin.IsEnabled = false; - ValCCAPI = new API(AuthResponse.AuthTokens, SelectedProfile, 2, (bool)chkbxShareable.IsChecked); + ValCCAPI = new API(AuthResponse.AuthTokens, SelectedProfile, 2, (chkbxShareable.IsChecked ?? false)); } private void profiles_SelectionChanged(object sender, SelectionChangedEventArgs e) @@ -334,10 +336,11 @@ private void chkbxShareable_Click(object sender, RoutedEventArgs e) if (!LoggedIn) { MessageBox.Show("You are not logged in!"); + ((CheckBox)sender).IsChecked = !((CheckBox)sender).IsChecked; return; } ValCCAPI.Shareable = (bool)chkbxShareable.IsChecked; - ValCCAPI.Set(); + _ = ValCCAPI.Set(); } } } diff --git a/ValorantCC/SubWindow/ProfilesWindow.xaml b/ValorantCC/SubWindow/ProfilesWindow.xaml index b0881b3..e05c547 100644 --- a/ValorantCC/SubWindow/ProfilesWindow.xaml +++ b/ValorantCC/SubWindow/ProfilesWindow.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:ValorantCC" mc:Ignorable="d" Title="ProfilesWindow" Height="Auto" Width="Auto" ResizeMode="NoResize" SizeToContent="WidthAndHeight"> - + diff --git a/ValorantCC/SubWindow/ProfilesWindow.xaml.cs b/ValorantCC/SubWindow/ProfilesWindow.xaml.cs index b1eca3c..ded97e5 100644 --- a/ValorantCC/SubWindow/ProfilesWindow.xaml.cs +++ b/ValorantCC/SubWindow/ProfilesWindow.xaml.cs @@ -60,9 +60,14 @@ private static async Task InitialFetch(String sharecode = null) if (sharecode != null) { ValCCApi.Action = 3; - Shareables = ValCCApi.Fetch(sharecode).data; + Shareables = (await ValCCApi.Fetch(sharecode)).data; + } + else + { + ValCCApi.Action = 2; + Shareables = (await ValCCApi.Fetch()).data; + } - else Shareables = ValCCApi.Fetch().data; if (Shareables.Count == 0) return true; for (int i = 0; i < Shareables.Count; i++) @@ -208,7 +213,7 @@ private async Task CreateRender(PublicProfile profile) Grid0.Children.Add(applyButton); Crosshair_Parser.Generate(0, Grid0, profile.settings.Primary); - + Crosshair_Parser.Generate(2, Grid0, profile.settings.aDS); template.Child = Grid0; await Task.Delay(1); return template; diff --git a/ValorantCC/src/API.cs b/ValorantCC/src/API.cs index 352853c..5c1800d 100644 --- a/ValorantCC/src/API.cs +++ b/ValorantCC/src/API.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json; using System.Text.RegularExpressions; using System.Diagnostics; +using RestSharp.Authenticators; namespace ValorantCC { @@ -54,7 +55,7 @@ public API(AuthTokens Tokens, CrosshairProfile TargetProfile ,int ActionInt, boo Shareable = isShareable; } - public FetchResponse Fetch(String sharecode = null) + public async Task Fetch(String sharecode = null) { PostPayload payload = new PostPayload() { @@ -70,26 +71,29 @@ public FetchResponse Fetch(String sharecode = null) } RestRequest request = new RestRequest() { Method = Method.POST}; request.AddJsonBody(payload); - RestResponse response = (RestResponse)client.Execute(request); + RestResponse response = (RestResponse)await client.ExecuteAsync(request); + if (response.StatusCode != System.Net.HttpStatusCode.OK) return new FetchResponse() { success = false }; - return JsonConvert.DeserializeObject(Regex.Unescape(response.Content)); + return JsonConvert.DeserializeObject(response.Content); } - public VoidCallResponse Set() + public async Task Set() { PostPayload payload = new PostPayload() { subject = AuthTokens.Subject, settings = JsonConvert.SerializeObject(profile), shareable = Shareable, - action = Action + action = 1 }; RestRequest request = new RestRequest() { Method = Method.POST }; + //client.Authenticator = new JwtAuthenticator(AuthTokens.AccessToken); + request.RequestFormat = DataFormat.Json; request.AddJsonBody(payload); - request.AddHeader("Authorization", $"Bearer {AuthTokens.AccessToken}"); // Pass to server so nobody can set somebody's saved profile. - RestResponse response = (RestResponse)client.Execute(request); + request.AddOrUpdateHeader("Authorization", $"Bearer {AuthTokens.AccessToken}"); // Pass to server so nobody can set somebody's saved profile. + RestResponse response = (RestResponse)await client.ExecuteAsync(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) return new VoidCallResponse() { success = false }; - return JsonConvert.DeserializeObject(Regex.Unescape(response.Content)); + return JsonConvert.DeserializeObject(response.Content); } } diff --git a/ValorantCC/src/Crosshair_Parser.cs b/ValorantCC/src/Crosshair_Parser.cs index 53f9bfb..4bfe620 100644 --- a/ValorantCC/src/Crosshair_Parser.cs +++ b/ValorantCC/src/Crosshair_Parser.cs @@ -20,42 +20,6 @@ public static void Generate(int column, Grid grid, ProfileSettings settings) { Rectangle[] rectangles = new Rectangle[16]; int recindex = 0; - /*for (int i = 1; i <= 4; i++) - { - string name = $"prime{}"; - switch (i) - { - case 0: - name += "X"; - break; - case 1: - name += "Y"; - break; - case 2: - name += "OLX"; - break; - case 3: - name += "OLY"; - break; - } - - for (int j = 1; j <= 4; j++) - { - string subname = name; - if (j % 2 != 0) - subname += "OT"; - - Rectangle rectangle = new Rectangle() - { - Name = subname, - Width = 3, - Height = 3 - }; - rectangles[recindex] = rectangle; - recindex++; - } - }*/ - for (int i = 0; i < rectangles.Length; i++) { Rectangle rectangle = new Rectangle()