Skip to content

Commit

Permalink
PATCH v3.1.5 (Added better auth checking+Crash when saving while clie…
Browse files Browse the repository at this point in the history
…nt is closed fix)
  • Loading branch information
weedeej committed Mar 7, 2022
1 parent 3b3ccaf commit cc9f1d3
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 22 deletions.
1 change: 0 additions & 1 deletion ValorantCC/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ private async void btnSave_Click(object sender, RoutedEventArgs e)

if (await DataProcessor.SaveNewColor(SelectedColors, profiles.SelectedIndex, profiles.Text))
{
await DataProcessor.Construct();
profiles.Items.Refresh();
profiles.SelectedIndex = DataProcessor.CurrentProfile;
Utilities.Utils.MessageText("Saved! Restart Valorant.", Brushes.Lime);
Expand Down
2 changes: 1 addition & 1 deletion ValorantCC/ValorantCC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<AssemblyVersion></AssemblyVersion>
<FileVersion></FileVersion>
<Version>3.1.4</Version>
<Version>3.1.5</Version>
<SignAssembly>true</SignAssembly>
</PropertyGroup>

Expand Down
45 changes: 29 additions & 16 deletions ValorantCC/src/BackgroundAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using RestSharp;
using Newtonsoft.Json;

namespace ValorantCC
{
public partial class FlagObject
{
public string errorCode { get; init; }
public int httpStatus { get; init; }
public string message { get; init; }
}
class BackgroundAuth
{
MainWindow main = (MainWindow)Application.Current.MainWindow;
Processor processor;
LockfileData _lockfileData;
public BackgroundAuth(Processor processor1)
{
processor = processor1;
Expand All @@ -31,6 +40,7 @@ public async void LoopCheck()
{
main.StatusTxt.Foreground = Brushes.Yellow;
main.StatusTxt.Text = "Waiting for session. . .";
_lockfileData = AuthObj.ObtainLockfileData(LockfilePath);
lockfilexists = true;
}
if (!await LoginFlagExists() && !main.PressedForceLogin)
Expand All @@ -41,7 +51,7 @@ public async void LoopCheck()
main.ForceLoginBtn.Visibility = Visibility.Visible;
continue;
}
if (lockfilexists && AuthObj.ObtainLockfileData(LockfilePath).Success)
if (lockfilexists && _lockfileData.Success)
{
main.StatusTxt.Text = "Logging in. . .";
AuthResponse AuthResponse = await processor.Login();
Expand Down Expand Up @@ -85,22 +95,25 @@ public async void LoopCheck()
}
}

public async static Task<bool> LoginFlagExists()
public async Task<bool> LoginFlagExists()
{
DirectoryInfo LogDir = new DirectoryInfo(Environment.GetEnvironmentVariable("LocalAppData") + "\\Riot Games\\Riot Client\\Logs\\Riot Client Logs");
var log = LogDir.GetFiles().OrderByDescending(f => f.LastWriteTime).First();

string content;
using (FileStream fileStream = File.Open(log.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (StreamReader sr = new StreamReader(fileStream))
content = (String)sr.ReadToEnd().Clone();

bool t = false;
if (content.Contains("riot-messaging-service: State is now Connected"))
t = true;

await Task.Delay(1);
return t;
RestClient wsClient = new RestClient(new RestClientOptions() { RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true });
wsClient.Authenticator = new RestSharp.Authenticators.HttpBasicAuthenticator("riot",_lockfileData.Key);
RestRequest entitlementsReq = new RestRequest($"{_lockfileData.Protocol}://127.0.0.1:{_lockfileData.Port}/entitlements/v1/token");
var resp = await wsClient.ExecuteAsync(entitlementsReq);
if (!resp.IsSuccessful)
{
try
{
var err = JsonConvert.DeserializeObject<FlagObject>(resp.Content.ToString());
Utilities.Utils.Log($"FETCH AUTH - {err.errorCode}: {err.message}");
}catch (NullReferenceException)
{
Utilities.Utils.Log("User exited the client");
}
return false;
}
return true;
}
}
}
49 changes: 45 additions & 4 deletions ValorantCC/src/Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Processor
public List<string> ProfileNames;
private ProfileList FetchedProfiles;
public int CurrentProfile;
private Dictionary<string, string> _headers;
//Haruki's "bug" fix
private Color[] DefaultColors = new Color[8];

Expand Down Expand Up @@ -49,6 +50,7 @@ public async Task<bool> Construct()
{
Utilities.Utils.Log("Constructing Properties -->");
client.Authenticator = new RestSharp.Authenticators.HttpBasicAuthenticator("riot", AuthResponse.LockfileData.Key);
_headers = Utilities.Utils.ConstructHeaders(AuthResponse);
UserSettings = await FetchUserSettings();
if (UserSettings.settingsProfiles == null) return false;

Expand Down Expand Up @@ -135,9 +137,34 @@ private async Task<Data> FetchUserSettings()
RestRequest request = new RestRequest($"{AuthResponse.LockfileData.Protocol}://127.0.0.1:{AuthResponse.LockfileData.Port}/player-preferences/v1/data-json/Ares.PlayerSettings", Method.Get);

RestResponse resp = await client.ExecuteAsync(request);
if (!resp.IsSuccessful) return new Data();
string responseContent = resp.Content;
FetchResponseData response;
if (!resp.IsSuccessful)
{
try
{
Utilities.Utils.Log("Fetch User Settings failed for WS. Trying playerpref: "+resp.Content.ToString());
} catch (NullReferenceException ex)
{
Utilities.Utils.Log("WS Failed to fetch settings error: " + ex.StackTrace.ToString());
request = new RestRequest("https://playerpreferences.riotgames.com/playerPref/v3/getPreference/Ares.PlayerSettings", Method.Get);
request.AddHeaders(_headers);
resp = await (new RestClient().ExecuteAsync(request));
if (!resp.IsSuccessful) return new Data();
var responseData = JsonConvert.DeserializeObject<Dictionary<string, object>>(resp.Content);
Data settings;
try
{
settings = Utilities.Utils.Decompress(Convert.ToString(responseData["data"]));
}catch (KeyNotFoundException)
{
Utilities.Utils.Log("Player pref failed to fetch settings");
return new Data();
}
return settings;

}
}
string responseContent = resp.Content;
try
{
response = JsonConvert.DeserializeObject<FetchResponseData>(responseContent);
Expand All @@ -159,8 +186,22 @@ private async Task<bool> putUserSettings(Data newData)
RestResponse response = await client.ExecuteAsync(request);
if (!response.IsSuccessful)
{
Utilities.Utils.Log("savePreference Unsuccessfull: " + response.Content.ToString());
return false;
try
{
Utilities.Utils.Log("savePreference Unsuccessfull: " + response.Content.ToString());
return false;
} catch (NullReferenceException)
{
request = new RestRequest("https://playerpreferences.riotgames.com/playerPref/v3/savePreference", Method.Put);
request.AddJsonBody(new { type = "Ares.PlayerSettings", data = Utilities.Utils.Compress(newData) });
request.AddHeaders(_headers);
response = await (new RestClient().ExecuteAsync(request));
if (!response.IsSuccessful)
{
Utilities.Utils.Log("savePreference Unsuccessfull: " + response.Content.ToString());
return false;
}
}
}

Dictionary<string, object> responseDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(response.Content);
Expand Down
2 changes: 2 additions & 0 deletions ValorantCC/src/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
Expand Down Expand Up @@ -97,6 +98,7 @@ public static Dictionary<string, string> ConstructHeaders(AuthResponse auth)
public static void Log(string Text)
{
StringBuilder.Append($"{DateTimeOffset.Now} | {Text}\n");
Trace.WriteLine(StringBuilder.ToString());
File.AppendAllText(LoggingFile, StringBuilder.ToString());
StringBuilder.Clear();
}
Expand Down

0 comments on commit cc9f1d3

Please # to comment.