Skip to content

Commit 1e2d28a

Browse files
author
Martin Nielsen
committed
Patch 1.1.3 - Final score detection is much faster now
Also added debug image upload, which is optional
1 parent b184ed2 commit 1e2d28a

6 files changed

Lines changed: 47 additions & 52 deletions

File tree

OverwatchTracker/GameData.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public Game(string currentRating = "")
4848
[JsonIgnore]
4949
public List<int> heroPlayed = new List<int>();
5050
[JsonIgnore]
51+
public Bitmap debugImage = null;
52+
[JsonIgnore]
5153
public Bitmap playerListImage = null;
5254

5355
[JsonProperty("mapInfo")]
@@ -66,6 +68,8 @@ public Game(string currentRating = "")
6668
public string team2Score = "";
6769
[JsonProperty("duration")]
6870
public string duration = "";
71+
[JsonProperty("debugImageBase64")]
72+
public string debugImageBase64 = "";
6973
[JsonProperty("playerListImageBase64")]
7074
public string playerListImageBase64 = "";
7175
[JsonProperty("heroes")]
@@ -115,6 +119,10 @@ public string GetData()
115119
{
116120
this.playerListImageBase64 = Convert.ToBase64String(Functions.ImageToBytes(Functions.ReduceImageSize(this.playerListImage, 70)));
117121
}
122+
if(Vars.settings.uploadScreenshot && this.debugImage != null)
123+
{
124+
this.debugImageBase64 = Convert.ToBase64String(Functions.ImageToBytes(this.debugImage));
125+
}
118126

119127
return JsonConvert.SerializeObject(this, Formatting.Indented);
120128
}

OverwatchTracker/Program.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Program
2020
static void Main()
2121
{
2222
Vars.initalize = new Initalize(
23-
version: "1.1.2",
23+
version: "1.1.3",
2424
host: "betteroverwatch.com",
2525
gitHubHost: "https://api.github.com/repos/MartinNielsenDev/OverwatchTracker/releases/latest"
2626
);
@@ -179,6 +179,7 @@ public static void CaptureDesktop()
179179

180180
if (Functions.CompareStrings(quickPlayText, "PLHY") >= 70)
181181
{
182+
Thread.Sleep(250);
182183
Protocols.CheckPlayMenu(frame.DesktopImage);
183184
}
184185
}
@@ -200,11 +201,12 @@ public static void CaptureDesktop()
200201
{
201202
if (Vars.gameData.playerListImage == null)
202203
{
203-
Thread.Sleep(2000);
204+
Thread.Sleep(Vars.getInfoTimeout.ElapsedMilliseconds >= 4000 ? 0 : 2000);
204205
try
205206
{
206207
frame = desktopDuplicator.GetLatestFrame();
207208
Vars.gameData.playerListImage = new Bitmap(Functions.CaptureRegion(frame.DesktopImage, 0, 110, 1920, 700));
209+
Vars.gameData.debugImage = new Bitmap(frame.DesktopImage);
208210
}
209211
catch { }
210212
}
@@ -242,7 +244,7 @@ public static void CaptureDesktop()
242244
Protocols.CheckFinalScore(frame.DesktopImage);
243245
}
244246

245-
if (Vars.gameData.state == State.Finished)
247+
if (Vars.gameData.state == State.Finished && Vars.getInfoTimeout.ElapsedMilliseconds >= 500)
246248
{
247249
Protocols.CheckGameScore(frame.DesktopImage);
248250
}

OverwatchTracker/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.2.0")]
36-
[assembly: AssemblyFileVersion("1.1.2.0")]
35+
[assembly: AssemblyVersion("1.1.3.0")]
36+
[assembly: AssemblyFileVersion("1.1.3.0")]

OverwatchTracker/Protocols.cs

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,31 @@ public static void CheckPlayMenu(Bitmap frame)
2424
srText = srText.Substring(srText.Length - 4);
2525
}
2626

27-
if (!srText.Equals(String.Empty) && srText.Length <= 4) // CHECK SR
27+
if (!srText.Equals(String.Empty) && srText.Length == 4)
2828
{
2929
if (Convert.ToInt32(srText) > 1000 && Convert.ToInt32(srText) < 5000)
3030
{
31-
if (!Vars.srCheck[0].Equals(srText) || !Vars.srCheck[1].Equals(srText))
31+
if (!Vars.gameData.currentRating.Equals(srText) || Vars.gameData.state >= State.Finished)
3232
{
33-
if (Vars.srCheckIndex > Vars.srCheck.Length - 1)
34-
{
35-
Vars.srCheckIndex = 0;
36-
}
37-
Vars.srCheck[Vars.srCheckIndex] = srText;
38-
Vars.srCheckIndex++;
33+
Functions.PlaySound();
34+
Program.trayMenu.currentGame.MenuItems[1].Text = "Skill rating: " + srText;
35+
Functions.DebugMessage("Recognized sr: '" + srText + "'");
3936
}
40-
if (Vars.srCheck[0].Equals(srText) && Vars.srCheck[1].Equals(srText))
41-
{
42-
if (!Vars.gameData.currentRating.Equals(srText) || Vars.gameData.state >= State.Finished)
43-
{
44-
Functions.PlaySound();
45-
Program.trayMenu.currentGame.MenuItems[1].Text = "Skill rating: " + srText;
46-
Functions.DebugMessage("Recognized sr: '" + srText + "'");
47-
}
48-
Vars.gameTimer.Stop();
49-
Vars.srCheck[0] = "";
50-
Vars.srCheck[1] = "";
51-
Vars.srCheckIndex = 0;
52-
Vars.gameData.currentRating = srText;
37+
Vars.gameTimer.Stop();
38+
Vars.gameData.currentRating = srText;
5339

54-
if (Vars.gameData.state == State.Recording ||
55-
Vars.gameData.state == State.Finished ||
56-
Vars.gameData.state == State.WaitForUpload
57-
)
58-
{
59-
if (!IsValidGame()) return;
60-
string game = Vars.gameData.GetData();
61-
Vars.lastGameJSON = JsonConvert.SerializeObject(JsonConvert.DeserializeObject<CleanedGame>(game), Formatting.Indented);
62-
Server.UploadGame(game);
63-
ResetGame();
64-
}
65-
Program.trayMenu.ChangeTray("Ready to record, enter a competitive game to begin", Properties.Resources.IconActive);
40+
if (Vars.gameData.state == State.Recording ||
41+
Vars.gameData.state == State.Finished ||
42+
Vars.gameData.state == State.WaitForUpload
43+
)
44+
{
45+
if (!IsValidGame()) return;
46+
string game = Vars.gameData.GetData();
47+
Vars.lastGameJSON = JsonConvert.SerializeObject(JsonConvert.DeserializeObject<CleanedGame>(game), Formatting.Indented);
48+
Server.UploadGame(game);
49+
ResetGame();
6650
}
51+
Program.trayMenu.ChangeTray("Ready to record, enter a competitive game to begin", Properties.Resources.IconActive);
6752
}
6853
}
6954
}
@@ -103,11 +88,11 @@ public static void CheckStats(Bitmap frame)
10388
{
10489
Vars.gameData.stats.Add(
10590
new Stats(
106-
elimsText,
107-
damageText,
108-
objKillsText,
109-
healingText,
110-
deathsText,
91+
elimsText,
92+
damageText,
93+
objKillsText,
94+
healingText,
95+
deathsText,
11196
Vars.gameTimer.ElapsedMilliseconds - Functions.GetTimeDeduction()
11297
));
11398
Vars.statsTimer.Restart();
@@ -194,7 +179,7 @@ public static void CheckTeamsSkillRating(Bitmap frame)
194179
{
195180
string team1SR = Functions.BitmapToText(frame, 545, 220, 245, 70, contrastFirst: false, radius: 90, network: Network.TeamSkillRating);
196181
team1SR = Regex.Match(team1SR, "[0-9]+").ToString();
197-
182+
198183
if (!team1SR.Equals(String.Empty) && team1SR.Length >= 4) // TEAM 1 SR
199184
{
200185
team1SR = team1SR.Substring(team1SR.Length - 4);
@@ -224,7 +209,7 @@ public static void CheckTeamsSkillRating(Bitmap frame)
224209
{
225210
string team2SR = Functions.BitmapToText(frame, 1135, 220, 245, 70, contrastFirst: false, radius: 90, network: Network.TeamSkillRating);
226211
team2SR = Regex.Match(team2SR, "[0-9]+").ToString();
227-
212+
228213
if (!team2SR.Equals(String.Empty) && team2SR.Length >= 4) // TEAM 1 SR
229214
{
230215
team2SR = team2SR.Substring(team2SR.Length - 4);
@@ -370,20 +355,19 @@ public static void CheckFinalScore(Bitmap frame)
370355
Vars.gameData.state = State.Finished;
371356
Vars.gameTimer.Stop();
372357
Vars.heroTimer.Stop();
358+
Vars.getInfoTimeout.Restart();
373359

374360
for (int i = 0; i < Vars.gameData.heroPlayed.Count; i++)
375361
{
376362
Vars.gameData.heroTimePlayed[i].Stop();
377363
}
378-
Thread.Sleep(500);
379364
}
380365
}
381366
}
382367
public static void CheckGameScore(Bitmap frame)
383368
{
384369
if (Vars.gameData.team1Score.Equals(String.Empty) && Vars.gameData.team1Score.Equals(String.Empty))
385370
{
386-
Thread.Sleep(2000); //prevent big animation from being captured
387371
string scoreTextLeft = Functions.BitmapToText(frame, 800, 560, 95, 135, contrastFirst: false, radius: 45, network: Network.TeamSkillRating);
388372
string scoreTextRight = Functions.BitmapToText(frame, 1000, 560, 95, 135, contrastFirst: false, radius: 45, network: Network.TeamSkillRating);
389373
scoreTextLeft = Regex.Match(scoreTextLeft, "[0-9]+").ToString();
@@ -402,6 +386,7 @@ public static void CheckGameScore(Bitmap frame)
402386
Functions.DebugMessage("Recognized team score Team 1:" + scoreTextLeft + " Team 2:" + scoreTextRight);
403387
Program.trayMenu.currentGame.MenuItems[5].Text = "Final score: " + scoreTextLeft + " | " + scoreTextRight;
404388
Vars.gameData.state = State.WaitForUpload;
389+
Vars.getInfoTimeout.Stop();
405390
}
406391
}
407392
}

OverwatchTracker/TrayMenu.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private void FetchJSON(object sender, EventArgs e)
8686
if (Vars.lastGameJSON.Length > 0)
8787
{
8888
string path = Path.Combine(Path.GetTempPath(), "lastgame.json");
89-
File.AppendAllText(path, Vars.lastGameJSON);
89+
File.WriteAllText(path, Vars.lastGameJSON);
9090
Process.Start("notepad.exe", path);
9191
TrayPopup("Last game successfully fetched", 3000);
9292
}
@@ -192,11 +192,11 @@ class CleanedGame
192192
private readonly string team2Score;
193193
[JsonProperty("duration")]
194194
private readonly string duration;
195+
[JsonProperty("battleTag")]
196+
private readonly string battleTag;
195197
[JsonProperty("heroes")]
196198
private readonly List<HeroPlayed> heroes;
197199
[JsonProperty("statsRecorded")]
198200
private readonly List<Stats> statsRecorded;
199-
[JsonProperty("battleTag")]
200-
private readonly string battleTag;
201201
}
202202
}

OverwatchTracker/Vars.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class Vars
2020
public static string[] heroNames = { "GGGMFIST", "GENJI", "MCCREE", "PHARAH", "REAPER", "SOLDIERZS", "SOMBRA", "TRACER", "BASTION", "HANZG", "JUHKRAT", "MEI", "TDRBJGRN", "WIDOWMAKER", "DVA", "ORISA", "REINHARDT", "RGADHOG", "WINSTON", "ZARYA", "AHA", "BRIGITTE", "LUCIO", "MERCY", "MOIRA", "SYMMETRA", "ZENYATTA", "WRECKIHGBAL", "ASHE" };
2121
public static string[] heroNamesReal = { "Doomfist", "Genji", "McCree", "Pharah", "Reaper", "Soldier: 76", "Sombra", "Tracer", "Bastion", "Hanzo", "Junkrat", "Mei", "Torbjörn", "Widowmaker", "D.va", "Orisa", "Reinhardt", "Roadhog", "Winston", "Zarya", "Ana", "Brigitte", "Lúcio", "Mercy", "Moira", "Symmetra", "Zenyatta", "Wrecking Ball", "Ashe" };
2222
public static int loopDelay = 250;
23-
public static string[] srCheck = { "", "" }, team1Check = { "", "" }, team2Check = { "", "" }, statsCheck = { "", "", "", "", "" };
24-
public static int srCheckIndex = 0, team1CheckIndex = 0, team2CheckIndex = 0, statsCheckIndex = 0, roundsCompleted = 0;
23+
public static string[] team1Check = { "", "" }, team2Check = { "", "" }, statsCheck = { "", "", "", "", "" };
24+
public static int team1CheckIndex = 0, team2CheckIndex = 0, statsCheckIndex = 0, roundsCompleted = 0;
2525
public static Stopwatch frameTimer = new Stopwatch(), gameTimer = new Stopwatch(), roundTimer = new Stopwatch(), heroTimer = new Stopwatch(), getInfoTimeout = new Stopwatch(), statsTimer = new Stopwatch();
2626
}
2727
enum State

0 commit comments

Comments
 (0)