Skip to content
This repository was archived by the owner on Oct 24, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ValorantStreamOverlay
{
public class Game
{
public enum Ranks
{
Unranked = 0,
Unknown1,
Unknown2,
Iron1,
Iron2,
Iron3,
Bronze1,
Bronze2,
Bronze3,
Silver1,
Silver2,
Silver3,
Gold1,
Gold2,
Gold3,
Platinum1,
Platinum2,
Platinum3,
Diamond1,
Diamond2,
Diamond3,
Immortal1,
Immortal2,
Immortal3,
Radiant
}

public enum CompetitiveMovements
{
MovementUnknown = 0,
Stable,
Promoted,
Demoted,
MajorIncrease,
MajorDecrease,
Increase,
Decrease,
MinorIncrease,
MinorDecrease
}

public Ranks TierAfterUpdate { get; set; }
public Ranks TierBeforeUpdate { get; set; }
public int TierProgressAfterUpdate { get; set; }
public int TierProgressBeforeUpdate { get; set; }

public string CompetitiveMovement { get; set; }
public CompetitiveMovements GetCompetitiveMovement
{
get
{
CompetitiveMovements competitiveMovement;
switch (CompetitiveMovement)
{
case "PROMOTED":
competitiveMovement = CompetitiveMovements.Promoted;
break;
case "DEMOTED":
competitiveMovement = CompetitiveMovements.Demoted;
break;
case "MAJOR_INCREASE":
competitiveMovement = CompetitiveMovements.MajorIncrease;
break;
case "MAJOR_DECREASE":
competitiveMovement = CompetitiveMovements.MajorDecrease;
break;
case "INCREASE":
competitiveMovement = CompetitiveMovements.Increase;
break;
case "DECREASE":
competitiveMovement = CompetitiveMovements.Decrease;
break;
case "MINOR_INCREASE":
competitiveMovement = CompetitiveMovements.MinorIncrease;
break;
case "MINOR_DECREASE":
competitiveMovement = CompetitiveMovements.MinorDecrease;
break;
case "STABLE":
competitiveMovement = CompetitiveMovements.Stable;
break;
default:
competitiveMovement = CompetitiveMovements.MovementUnknown;
break;
}
return competitiveMovement;
}
}

public int Points
{
get
{
int diff = 0;
if (GetCompetitiveMovement == CompetitiveMovements.Promoted)
diff = 100;
else if (GetCompetitiveMovement == CompetitiveMovements.Demoted)
diff = -100;

return TierProgressAfterUpdate - TierProgressBeforeUpdate + diff;
}
}
}
}
115 changes: 47 additions & 68 deletions LogicHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ public LogicHandler(ValorantOverStream instance)
ReadSettings();
}

void ReadSettings()
void ReadSettings()
{

if (string.IsNullOrEmpty(Properties.Settings.Default.password) || string.IsNullOrEmpty(Properties.Settings.Default.username))
MessageBox.Show("Welcome, You have to set your username and password in the settings menu");
{
MessageBox.Show("You have to set your username and password in the settings menu", "Welcome", MessageBoxButtons.OK, MessageBoxIcon.Information);
Settings settingsPage = new Settings();
settingsPage.ShowDialog();
}
else
{
username = Properties.Settings.Default.username;
Expand Down Expand Up @@ -122,7 +126,7 @@ void RiotGamesLogin()
}




}
catch (Exception e)
Expand All @@ -131,63 +135,33 @@ void RiotGamesLogin()
}
}



async Task UpdateToLatestGames()
{
Trace.Write("UPDATING");
dynamic response = GetCompApiAsync().GetAwaiter().GetResult();
var response = GetCompApiAsync().GetAwaiter().GetResult();
if (response != null)
{
int[] points = new int[3];
dynamic matches = response["Matches"];
int count = 0, i = 0;
var gameStats = new List<Tuple<int, Game.CompetitiveMovements>>();
var matches = JsonConvert.DeserializeObject<Game[]>(response["Matches"].ToString());
foreach (var game in matches)
{
// not a ranked game
if (game.GetCompetitiveMovement == Game.CompetitiveMovements.MovementUnknown)
continue;

if (game["CompetitiveMovement"] == "MOVEMENT_UNKNOWN")
{
// not a ranked game
}
else if (game["CompetitiveMovement"] == "PROMOTED")
{
// player promoted
int before = game["TierProgressBeforeUpdate"];
int after = game["TierProgressAfterUpdate"];
int differ = (after - before) + 100;
points[i++] = differ;
count++;
}
else if (game["CompetitiveMovement"] == "DEMOTED")
{
// player demoted
int before = game["TierProgressBeforeUpdate"];
int after = game["TierProgressAfterUpdate"];
int differ = (after - before) - 100;
points[i++] = differ;
count++;
}
else
{
int before = game["TierProgressBeforeUpdate"];
int after = game["TierProgressAfterUpdate"];
points[i++] = after - before;
count++;
}
gameStats.Add(Tuple.Create(game.Points, game.GetCompetitiveMovement));

if (count >= 3) // 3 recent matches found
if (gameStats.Count >= 3) // 3 recent matches found
break;
}

//Send Points to Function that changes the UI
SetChangesToOverlay(points).GetAwaiter();
SetChangesToOverlay(gameStats).GetAwaiter();
}

}


private async Task<JObject> GetCompApiAsync()
{

IRestClient compClient = new RestClient(new Uri($"https://pd.{region}.a.pvp.net/mmr/v1/players/{UserID}/competitiveupdates?startIndex=0&endIndex=20"));
RestRequest compRequest = new RestRequest(Method.GET);

Expand All @@ -199,41 +173,46 @@ private async Task<JObject> GetCompApiAsync()
return rankedResp.IsSuccessful ? JsonConvert.DeserializeObject<JObject>(rankedResp.Content) : null;
}


private async Task SetChangesToOverlay(int[] pointchange)
private async Task SetChangesToOverlay(List<Tuple<int, Game.CompetitiveMovements>> gameStats)
{
Label[] rankChanges = { ValorantOver.recentGame1, ValorantOver.recentGame2, ValorantOver.recentGame3 };
for (int i = 0; i < pointchange.Length; i++)
var asd = Tuple.Create(ValorantOver.recentGame1, ValorantOver.recentGame1_status);
var rankChanges = new[] {
Tuple.Create(ValorantOver.recentGame1, ValorantOver.recentGame1_status),
Tuple.Create(ValorantOver.recentGame2, ValorantOver.recentGame2_status),
Tuple.Create(ValorantOver.recentGame3, ValorantOver.recentGame3_status)
};
for (int i = 0; i < gameStats.Count; i++)
{
// neg num represents decrease in pts
if (pointchange[i] < 0)
{
//In the case of a demotion or a loss
pointchange[i] *= -1;
string change;
change = pointchange[i] <= 9 ? $"0{pointchange[i]}" : pointchange[i].ToString();

rankChanges[i].ForeColor = Color.Red;
rankChanges[i].Text = $"-{change}";
}
else if (pointchange[i] > 0)
{
//int checker = pointchange[i] * -1;
string change;
change = pointchange[i] <= 9 ? $"0{pointchange[i]}" : pointchange[i].ToString();
var points = gameStats[i].Item1;

rankChanges[i].ForeColor = Color.LimeGreen;
rankChanges[i].Text = $"+{change}";
if (points == 0)
{
rankChanges[i].Item1.ForeColor = Color.SlateGray;
rankChanges[i].Item1.Text = "0";
}
else
{
rankChanges[i].ForeColor = Color.SlateGray;
rankChanges[i].Text = "0";
var pointsText = $"{Math.Abs(points).ToString().PadLeft(2, '0')}";
if (points < 0)
{
//In the case of a demotion or a loss
rankChanges[i].Item1.ForeColor = Color.Red;
rankChanges[i].Item1.Text = $"-{pointsText}";
}
else if (points > 0)
{
rankChanges[i].Item1.ForeColor = Color.LimeGreen;
rankChanges[i].Item1.Text = $"+{pointsText}";
}
}

var resource = Properties.Resources.ResourceManager.GetObject($"TX_CompetitiveTierMovement_{Enum.GetName(typeof(Game.CompetitiveMovements), gameStats[i].Item2)}");
Bitmap myImage = (Bitmap)resource;
rankChanges[i].Item2.Image = myImage;
}
}


private void StartPointRefresh()
{
pointTimer = new Timer();
Expand Down Expand Up @@ -262,7 +241,7 @@ private void StartRELOGTimer()
relogTimer.Tick += new EventHandler(relogTimer_Tick);
relogTimer.Interval = 2700 * 1000;
relogTimer.Start();

}

private void relogTimer_Tick(object sender, EventArgs e)
Expand Down
45 changes: 45 additions & 0 deletions Overlay.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading