-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
617 lines (482 loc) · 23.9 KB
/
Form1.cs
File metadata and controls
617 lines (482 loc) · 23.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
namespace DBDMatchmakingTracker {
public partial class DBDQueueAnalyzer : Form {
DataTable dt;
int counter;
RegionList regions;
bool recordingGlobal = false;
string prevIntervalText = "";
bool queueSurvivor = true;
string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\DBDMatchmakingLogger\";
string regionPath;
string configPath;
ConfigHandler config;
bool dragging = false;
Point dragOffset;
public DBDQueueAnalyzer() {
InitializeComponent();
}
public bool ValidateRequiredSettings() {
return (bhvrSessionToken.TextLength > 0) && (regionType.Text.Length > 0);
}
private void button1_Click(object sender, EventArgs e) {
if (!ValidateRequiredSettings()) {
liveOutputBox.Text = "Cannot validate settings!\r\n" +
"Please make sure you have the following fields filled out:\r\n" +
"* Fill out the BHVR Session field with your bhvrSession ID (Found in response headers) \r\n" +
"* Select a region to analyze from the region dropdown field.\r\n" +
"* Make sure a role is selected to queue as.";
return;
}
Label button = (Label)sender;
if (QueueDataTimer.Enabled) { button.ForeColor = Color.FromArgb(0, 191, 0); button.Text = "Begin Recording Values"; QueueDataTimer.Stop(); return; }
ResetDataTable();
button.ForeColor = Color.FromArgb(255, 64, 64);
button.Text = "Stop Recording Values";
counter = 0;
QueueDataTimer.Start();
counter -= (int)Math.Round((double)(QueueDataTimer.Interval / 1000));
UpdateRequests();
}
public void ResetDataTable() {
dt = new DataTable();
dt.Columns.Add("Time", typeof(int));
dt.Columns.Add("KLRs", typeof(int));
dt.Columns.Add("SRVs", typeof(int));
dt.Columns.Add("ETAs", typeof(double));
}
public void UpdateChart() {
KLRCHRT.DataSource = dt;
SRVCHRT.DataSource = dt;
ETACHRT.DataSource = dt;
KLRCHRT.Series["Killer Pool"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
SRVCHRT.Series["Survivor Pool"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
ETACHRT.Series["Estimated Wait Times"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
KLRCHRT.Series["Killer Pool"].XValueMember = "Time";
KLRCHRT.Series["Killer Pool"].YValueMembers = "KLRs";
SRVCHRT.Series["Survivor Pool"].XValueMember = "Time";
SRVCHRT.Series["Survivor Pool"].YValueMembers = "SRVs";
ETACHRT.Series["Estimated Wait Times"].XValueMember = "Time";
ETACHRT.Series["Estimated Wait Times"].YValueMembers = "ETAs";
KLRCHRT.ChartAreas[0].AxisY.LabelStyle.Format = "";
SRVCHRT.ChartAreas[0].AxisY.LabelStyle.Format = "";
ETACHRT.ChartAreas[0].AxisY.LabelStyle.Format = "";
}
/// <summary>
/// Gets the queue data from the Dead by Daylight backend. Spoofs a BHVR account with a unique BHVR session ID
/// and then pretends to queue - thus receiving the server data.
/// </summary>
/// <param name="regionIndex">
/// The index of the region you'd like to request queue data from.
/// </param>
/// <param name="recordMode">
/// The way the program handles recording data to the data table and files.
/// <para/>
/// 0 = Don't record information
/// <para/>
/// 1 = Record to same file (SurvivorPool.csv, KillerPool.csv, EstimatedWaitTimes.csv)
/// <para/>
/// 2 = Record to folders based on region
/// </param>
public async Task<QueueData> GetQueueData(int regionIndex, bool recordData, bool recordToTable) {
HttpClientHandler handler = new HttpClientHandler();
handler.UseCookies = false;
HttpClient client = new HttpClient(handler);
string url = "https://brill.live.bhvrdbd.com/api/v1/queue";
string data = File.ReadAllText("requestData.json");
dynamic requestData = JsonConvert.DeserializeObject(data);
requestData = ConfigureRequestToUserSettings(requestData);
data = JsonConvert.SerializeObject(requestData);
client.DefaultRequestHeaders.Add("Cookie", "bhvrSession=" + bhvrSessionToken.Text);
client.DefaultRequestHeaders.Add("x-kraken-client-platform", platformChoice.Text);
client.DefaultRequestHeaders.ConnectionClose = true;
var response = await client.PostAsync(url, new StringContent(data, Encoding.UTF8, "application/json"));
string strResponse = await response.Content.ReadAsStringAsync();
Console.WriteLine(strResponse);
try {
dynamic results = JsonConvert.DeserializeObject(strResponse);
QueueData dataSample = new QueueData(int.Parse((string)results["queueData"]["sizeB"]), int.Parse((string)results["queueData"]["sizeA"]), double.Parse((string)results["queueData"]["ETA"]));
if (recordData) {
RecordQueueData(dataSample, recordToTable);
}
return dataSample;
} catch (Exception ex) {
liveOutputBox.Text = "Exception at: " + DateTime.Now.ToShortDateString() + " - " + DateTime.Now.ToLongTimeString() + "\n" + ex.Source + "\n" + ex.Message + "\n" + ex.StackTrace;
Console.WriteLine(liveOutputBox.Text);
return null;
}
}
public void RecordQueueData(QueueData queueData, bool recordToTable) {
string currentRegion = regionType.Text.ToUpper();
string regionString = "REGION " + currentRegion;
if (allRegions.Checked) { regionString = "GLOBAL VALUES"; }
if (recordingGlobal) { currentRegion = "GLOBAL"; }
string resultsText = "TIME: " + DateTime.Now.ToShortDateString() + " - " + DateTime.Now.ToLongTimeString() + "\n" +
"REGION: " + regionString + "\n\n" +
"KILLERS IN QUEUE: " + queueData.GetKlrPool() + "\r\n" +
"SURVIVORS IN QUEUE: " + queueData.GetSurvPool() + "\r\n" +
"CURRENT ESTIMATED WAIT TIME: " + (queueData.GetETA() / 1000).ToString("0.00") + " seconds";
if (recordToTable) { dt.Rows.Add(counter, queueData.GetKlrPool(), queueData.GetSurvPool(), queueData.GetETA() / 1000); }
using (StreamWriter sw = new StreamWriter(regionPath + currentRegion + @"\KillerPool.csv", true)) {
sw.WriteLine(DateTime.Now.ToShortDateString() + " - " + DateTime.Now.ToLongTimeString() + "," + queueData.GetKlrPool());
}
using (StreamWriter sw = new StreamWriter(regionPath + currentRegion + @"\SurvivorPool.csv", true)) {
sw.WriteLine(DateTime.Now.ToShortDateString() + " - " + DateTime.Now.ToLongTimeString() + "," + queueData.GetSurvPool());
}
using (StreamWriter sw = new StreamWriter(regionPath + currentRegion + @"\EstimatedWaitTimes.csv", true)) {
sw.WriteLine(DateTime.Now.ToShortDateString() + " - " + DateTime.Now.ToLongTimeString() + "," + (queueData.GetETA()).ToString("0.00"));
}
liveOutputBox.Text = resultsText;
}
public dynamic ConfigureRequestToUserSettings(dynamic request) {
int i = 0;
foreach (Region region in regions.GetRegionList()) {
//Console.WriteLine("Examining Region \"" + request["latencies"][i]["regionName"] + "\" - Latency: " + request["latencies"][i]["latency"]);
request["latencies"][i]["latency"] = region.GetLatency();
request["latencies"][i]["regionName"] = region.GetRegionName();
//Console.WriteLine("\tChanged Region \"" + request["latencies"][i]["regionName"] + "\" - Latency: " + request["latencies"][i]["latency"]);
i++;
}
request["props"]["CrossplayOptOut"] = !crossplayEnabled.Checked;
if (queueSurvivor) { request["side"] = "B"; }
else { request["side"] = "A"; }
return request;
}
private void Form1_Load(object sender, EventArgs e) {
dragBar.Text = "Dead by Daylight Queue Pool Analyzer - Version " + Application.ProductVersion + " - Made by @SHADERSOP";
regionPath = path + @"REGIONS\";
configPath = path + @"config.json";
rawTable.Columns.Clear();
dt = new DataTable();
dt.Columns.Add("Time", typeof(int));
dt.Columns.Add("KLRs", typeof(int));
dt.Columns.Add("SRVs", typeof(int));
dt.Columns.Add("ETAs", typeof(double));
regionType.Region = new System.Drawing.Region(new Rectangle(3, 3, regionType.Width - 3, regionType.Height - 7));
platformChoice.Region = new System.Drawing.Region(new Rectangle(3, 3, regionType.Width - 3, regionType.Height - 7));
SetupRegions();
SetupFiles();
SetupConfig();
CheckQueueAsStatus();
}
public void SetupFiles() {
List<Region> regionList = regions.GetRegionList();
foreach(Region region in regionList) {
string directoryPath = regionPath + region.GetRegionName().ToUpper();
if (!Directory.Exists(directoryPath)) {
Directory.CreateDirectory(directoryPath);
}
ValidateFiles(directoryPath);
}
if (!Directory.Exists(regionPath + "GLOBAL")) {
Directory.CreateDirectory(regionPath + "GLOBAL");
}
ValidateFiles(regionPath + "GLOBAL");
}
public void ValidateFiles(string directoryPath) {
if (!File.Exists(directoryPath + @"\KillerPool.csv")) {
using (StreamWriter sw = new StreamWriter(directoryPath + @"\KillerPool.csv", true)) {
sw.WriteLine("Time,Size");
}
}
if (!File.Exists(directoryPath + @"\SurvivorPool.csv")) {
using (StreamWriter sw = new StreamWriter(directoryPath + @"\SurvivorPool.csv", true)) {
sw.WriteLine("Time,Size");
}
}
if (!File.Exists(directoryPath + @"\EstimatedWaitTimes.csv")) {
using (StreamWriter sw = new StreamWriter(directoryPath + @"\EstimatedWaitTimes.csv", true)) {
sw.WriteLine("Time,ETAs");
}
}
}
public void SetupConfig() {
if (!File.Exists(configPath)) {
CreateNewConfig();
}
try {
config = JsonConvert.DeserializeObject<ConfigHandler>(File.ReadAllText(configPath));
regionType.SelectedIndex = config.RegionPreference;
platformChoice.SelectedIndex = config.PlatformPreference;
allRegions.Checked = config.SniffAllRegions;
queueSurvivor = config.QueueAsSurvivor;
CheckQueueAsStatus();
} catch (Exception ex) {
CreateNewConfig();
Console.WriteLine("Exception: " + ex.Message + "\n" + ex.StackTrace + "\n" + ex.Source);
}
}
public void CreateNewConfig() {
config = new ConfigHandler(true, 0, 0, false, true, Application.ProductVersion);
string jsonConfig = JsonConvert.SerializeObject(config);
File.WriteAllText(configPath, jsonConfig);
}
public void SaveConfig() {
File.WriteAllText(configPath, JsonConvert.SerializeObject(config));
}
public void SetupRegions() {
List<Region> regionList = new List<Region>();
IntRange unselectedRegionRange = new IntRange(150, 251);
Random rand = new Random();
foreach(string region in regionType.Items.OfType<string>()) {
regionList.Add(new Region(rand.Next(unselectedRegionRange.GetMin(), unselectedRegionRange.GetMax()), region));
Console.WriteLine("Added " + region);
}
regions = new RegionList(
regionList,
(regionType.SelectedIndex == 0),
0
);
regionType.SelectedIndex = regions.GetSelectedRegion();
}
private void QueueDataTimer_Tick(object sender, EventArgs e) {
UpdateRequests();
}
public async void UpdateRequests() {
counter += (int)Math.Round((double)(QueueDataTimer.Interval / 1000));
if (allRegions.Checked) {
int sumSurv = 0, sumKlr = 0;
List<double> regionEtas = new List<double>();
List<Region> regionList = regions.GetRegionList();
bool exceptionFound = false;
for (int i = 0; i < regionList.Count; i++) {
try {
regionType.SelectedIndex = i;
QueueData queueData = await GetQueueData(regionType.SelectedIndex, true, false);
sumSurv += queueData.GetSurvPool();
sumKlr += queueData.GetKlrPool();
regionEtas.Add(queueData.GetETA());
Console.WriteLine("Analyzing Region " + regions.GetRegionList()[regionType.SelectedIndex].GetRegionName().ToUpper() + ":\n" +
"\tSurvs in queue: " + queueData.GetSurvPool() + "\n" +
"\tKlrs in queue: " + queueData.GetKlrPool() + "\n" +
"\tETA for region: " + queueData.GetETA());
} catch (Exception ex) {
exceptionFound = true;
break;
}
}
if (!exceptionFound) {
double sumEtas = 0;
foreach (double eta in regionEtas) {
sumEtas += eta;
}
double avgEta = sumEtas / regionEtas.Count;
QueueData summedData = new QueueData(sumSurv, sumKlr, avgEta);
recordingGlobal = true;
RecordQueueData(summedData, true);
recordingGlobal = false;
}
} else {
try {
QueueData queueData = await GetQueueData(regionType.SelectedIndex, true, true);
Console.WriteLine("Current Queue Data Shows: " + queueData.GetSurvPool() + " survivors are in queue!");
}
catch (Exception ex) {
liveOutputBox.Text = "Exception at: " + DateTime.Now.ToShortDateString() + " - " + DateTime.Now.ToLongTimeString() + "\n" + ex.Source + "\n" + ex.Message + "\n" + ex.StackTrace;
Console.WriteLine(liveOutputBox.Text);
}
}
UpdateChart();
if (dt.Rows.Count > 100) {
dt.Rows.RemoveAt(0);
}
rawTable.DataSource = dt;
//rawTable.FirstDisplayedScrollingRowIndex = rawTable.Rows.Count - 1;
}
private void regionType_SelectedIndexChanged(object sender, EventArgs e) {
IntRange unselectedRegionRange = new IntRange(150, 251);
Random rand = new Random();
regions.SetSelectedRegion(regionType.SelectedIndex);
for (int i = 0; i < regions.GetRegionList().Count; i++) {
regions.SetRegionLatency(i, rand.Next(unselectedRegionRange.GetMin(), unselectedRegionRange.GetMax()));
}
regions.SetRegionLatency(regionType.SelectedIndex, 50);
Console.WriteLine("Selected Region is " + regions.GetRegion(regions.GetSelectedRegion()).GetRegionName());
try {
config.RegionPreference = regionType.SelectedIndex;
SaveConfig();
} catch (Exception) {
Console.WriteLine("Config is null");
}
}
private void allRegions_CheckedChanged(object sender, EventArgs e) {
config.SniffAllRegions = allRegions.Checked;
SaveConfig();
CheckBox checkBox = (CheckBox)sender;
if (checkBox.Checked) {
regionType.Enabled = false;
regions.SetRegionPreference(false);
blockPanel.Enabled = true;
blockPanel.Visible = true;
if (int.Parse(intervalBox.Text) < 15) {
intervalBox.Text = "15";
}
return;
}
blockPanel.Enabled = false;
blockPanel.Visible = false;
regionType.Enabled = true;
regions.SetRegionPreference(true);
}
private void label1_Click(object sender, EventArgs e) {
}
private void textBox1_TextChanged(object sender, EventArgs e) {
TextBox intervalBox = (TextBox)sender;
int interval;
bool isNumber = int.TryParse(intervalBox.Text, out interval);
if (isNumber == false || (isNumber && (interval * 1000) < 0)) {
intervalBox.Text = prevIntervalText;
return;
}
QueueDataTimer.Interval = interval * 1000;
prevIntervalText = intervalBox.Text;
}
private void LabelHoverStart(object sender, EventArgs e) {
Label label = (Label)sender;
short r = (short)(label.BackColor.R + 20);
short g = (short)(label.BackColor.G + 20);
short b = (short)(label.BackColor.B + 20);
if (r > 255) { r = 255; }
if (g > 255) { g = 255; }
if (b > 255) { b = 255; }
label.BackColor = Color.FromArgb(r, g, b);
}
private void LabelHoverEnd(object sender, EventArgs e) {
Label label = (Label)sender;
short r = (short)(label.BackColor.R - 20);
short g = (short)(label.BackColor.G - 20);
short b = (short)(label.BackColor.B - 20);
if (r < 0) { r = 0; }
if (g < 0) { g = 0; }
if (b < 0) { b = 0; }
label.BackColor = Color.FromArgb(r, g, b);
}
private void LabelClickStart(object sender, MouseEventArgs e) {
LabelHoverStart(sender, null);
}
private void LabelClickEnd(object sender, MouseEventArgs e) {
LabelHoverEnd(sender, null);
}
private void label8_Click(object sender, EventArgs e) {
Application.Exit();
}
private void label7_Click(object sender, EventArgs e) {
this.WindowState = FormWindowState.Minimized;
}
private void TextboxFocusEnter(object sender, EventArgs e) {
TextBox textBox = (TextBox)sender;
short r = (short)(textBox.BackColor.R + 20);
short g = (short)(textBox.BackColor.G + 20);
short b = (short)(textBox.BackColor.B + 20);
if (r > 255) { r = 255; }
if (g > 255) { g = 255; }
if (b > 255) { b = 255; }
textBox.BackColor = Color.FromArgb(r, g, b);
}
private void TextboxFocusLeave(object sender, EventArgs e) {
TextBox textBox = (TextBox)sender;
short r = (short)(textBox.BackColor.R - 20);
short g = (short)(textBox.BackColor.G - 20);
short b = (short)(textBox.BackColor.B - 20);
if (r > 255) { r = 255; }
if (g > 255) { g = 255; }
if (b > 255) { b = 255; }
textBox.BackColor = Color.FromArgb(r, g, b);
}
private void TextboxHoverStart(object sender, EventArgs e) {
TextboxFocusEnter(sender, e);
}
private void TextboxHoverLeave(object sender, EventArgs e) {
TextboxFocusLeave(sender, e);
}
private void ComboBoxFocusEnter(object sender, EventArgs e) {
ComboBox comboBox = (ComboBox)sender;
short r = (short)(comboBox.BackColor.R + 20);
short g = (short)(comboBox.BackColor.G + 20);
short b = (short)(comboBox.BackColor.B + 20);
if (r > 255) { r = 255; }
if (g > 255) { g = 255; }
if (b > 255) { b = 255; }
comboBox.BackColor = Color.FromArgb(r, g, b);
}
private void ComboBoxFocusLeave(object sender, EventArgs e) {
ComboBox comboBox = (ComboBox)sender;
short r = (short)(comboBox.BackColor.R - 20);
short g = (short)(comboBox.BackColor.G - 20);
short b = (short)(comboBox.BackColor.B - 20);
if (r > 255) { r = 255; }
if (g > 255) { g = 255; }
if (b > 255) { b = 255; }
comboBox.BackColor = Color.FromArgb(r, g, b);
}
public void CheckQueueAsStatus() {
config.QueueAsSurvivor = queueSurvivor;
SaveConfig();
if (queueSurvivor) {
queueAsSurvivor.BackColor = Color.FromArgb(0, 0, 255);
queueAsSurvivor.ForeColor = Color.White;
queueAsKiller.BackColor = Color.FromArgb(159, 16, 16);
queueAsKiller.ForeColor = Color.FromArgb(159, 159, 159);
return;
}
queueAsSurvivor.BackColor = Color.FromArgb(16, 16, 159);
queueAsSurvivor.ForeColor = Color.FromArgb(159, 159, 159);
queueAsKiller.BackColor = Color.FromArgb(255, 0, 0);
queueAsKiller.ForeColor = Color.White;
}
private void queueAsSurvivor_Click(object sender, EventArgs e) {
queueSurvivor = true;
CheckQueueAsStatus();
}
private void queueAsKiller_Click(object sender, EventArgs e) {
queueSurvivor = false;
CheckQueueAsStatus();
}
private void DragStart(object sender, MouseEventArgs e) {
LabelClickStart(sender, e);
dragging = true;
dragOffset = new Point(Cursor.Position.X - this.Location.X, Cursor.Position.Y - this.Location.Y);
}
private void DragEnd(object sender, MouseEventArgs e) {
LabelClickEnd(sender, e);
dragging = false;
}
private void DragMove(object sender, MouseEventArgs e) {
if (dragging) {
this.Location = new Point(Cursor.Position.X - dragOffset.X, Cursor.Position.Y - dragOffset.Y);
}
}
private void clearGraphData_MouseClick(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Right) {
string[] directories = Directory.GetDirectories(path);
foreach (string directory in directories) {
Directory.Delete(directory, true);
}
Application.Restart();
}
}
private void viewGraphFolder_Click(object sender, EventArgs e) {
Process.Start(path);
}
private void kofi_Click(object sender, EventArgs e) {
Process.Start("https://ko-fi.com/shadersop");
}
private void platformChoice_SelectedIndexChanged(object sender, EventArgs e) {
config.PlatformPreference = platformChoice.SelectedIndex;
SaveConfig();
}
}
}