-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMainForm.cs
980 lines (880 loc) · 34.5 KB
/
MainForm.cs
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
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
using Tesseract;
using static TarkovPriceViewer.TarkovAPI;
namespace TarkovPriceViewer
{
public partial class MainForm : Form
{
[DllImport("user32.dll")]
private static extern bool PrintWindow(IntPtr hWnd, IntPtr hdcBlt, int nFlags);
[DllImport("user32.dll")]
private static extern bool GetWindowPlacement(int hWnd, ref WINDOWPLACEMENT lpwndpl);
[DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("user32.dll")]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelProc callback, IntPtr hInstance, uint threadId);
[DllImport("user32.dll")]
private static extern bool UnhookWindowsHookEx(IntPtr hInstance);
[DllImport("user32.dll")]
private static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, int wParam, IntPtr lParam);
private delegate IntPtr LowLevelProc(int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("User32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO Dummy);
private const int GWL_EXSTYLE = -20;
private const int WS_EX_LAYERED = 0x80000;
private static int repeatCount = 0;
public static System.Timers.Timer timer = new System.Timers.Timer(250);
private struct WINDOWPLACEMENT
{
public int length;
public int flags;
public ShowWindowCommands showCmd;
public System.Drawing.Point ptMinPosition;
public System.Drawing.Point ptMaxPosition;
public System.Drawing.Rectangle rcNormalPosition;
}
private enum ShowWindowCommands : int
{
Hide = 0,
Normal = 1,
Minimized = 2,
Maximized = 3,
}
internal struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
private static readonly int WH_KEYBOARD_LL = 13;
private static readonly int WM_KEYUP = 0x101;
private static readonly int WH_MOUSE_LL = 14;
private static readonly int WM_MOUSEMOVE = 0x200;
private static bool isinfoclosed = true;
private static bool iscompareclosed = true;
private static LowLevelProc _proc_keyboard = null;
private static LowLevelProc _proc_mouse = null;
private static IntPtr hhook_keyboard = IntPtr.Zero;
private static IntPtr hhook_mouse = IntPtr.Zero;
private static IntPtr h_instance = LoadLibrary("User32");
private static System.Drawing.Point point = new System.Drawing.Point(0, 0);
private static int nFlags = 0x0;
private static Overlay overlay_info = new Overlay(true);
private static Overlay overlay_compare = new Overlay(false);
private static CancellationTokenSource cts_info = new CancellationTokenSource();
private static CancellationTokenSource cts_compare = new CancellationTokenSource();
private static Control press_key_control = null;
private static Scalar linecolor = new Scalar(90, 89, 82);
private static long idle_time = 3600000;
public static DateTime KeyPressedTime;
private static DateTime presstime;
public static bool WaitingForTooltip = false;
public static bool GettingItemInfo = false;
public MainForm()
{
int style = GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, style | WS_EX_LAYERED);
if (Environment.OSVersion.Version.Major >= 6)
{
nFlags = 0x2;
}
InitializeComponent();
SettingUI();
SetHook();
overlay_info.Owner = this;
overlay_info.Show();
overlay_compare.Owner = this;
overlay_compare.Show();
timer.Elapsed += Timer_Elapsed;
timer.AutoReset = true;
}
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (!GettingItemInfo)
{
if (repeatCount >= 0)//why was 12?
{
timer.Stop(); WaitingForTooltip = false;
repeatCount = 0;
}
else
{
repeatCount++;
point = Control.MousePosition;
LoadingItemInfo();
}
}
}
private void SettingUI()
{
MinimizeBox = false;
MaximizeBox = false;
Version.Text = Program.settings["Version"];
MinimizetoTrayWhenStartup.Checked = Convert.ToBoolean(Program.settings["MinimizetoTrayWhenStartup"]);
CloseOverlayWhenMouseMoved.Checked = Convert.ToBoolean(Program.settings["CloseOverlayWhenMouseMoved"]);
RandomItem.Checked = Convert.ToBoolean(Program.settings["RandomItem"]);
last_price_box.Checked = Convert.ToBoolean(Program.settings["Show_Last_Price"]);
day_price_box.Checked = Convert.ToBoolean(Program.settings["Show_Day_Price"]);
week_price_box.Checked = Convert.ToBoolean(Program.settings["Show_Week_Price"]);
sell_to_trader_box.Checked = Convert.ToBoolean(Program.settings["Sell_to_Trader"]);
buy_from_trader_box.Checked = Convert.ToBoolean(Program.settings["Buy_From_Trader"]);
needs_box.Checked = Convert.ToBoolean(Program.settings["Needs"]);
barters_and_crafts_box.Checked = Convert.ToBoolean(Program.settings["Barters_and_Crafts"]);
ShowOverlay_Button.Text = ((Keys)Int32.Parse(Program.settings["ShowOverlay_Key"])).ToString();
HideOverlay_Button.Text = ((Keys)Int32.Parse(Program.settings["HideOverlay_Key"])).ToString();
CompareOverlay_Button.Text = ((Keys)Int32.Parse(Program.settings["CompareOverlay_Key"])).ToString();
TransParent_Bar.Value = Int32.Parse(Program.settings["Overlay_Transparent"]);
TransParent_Text.Text = Program.settings["Overlay_Transparent"];
TarkovTrackerCheckBox.Checked = Convert.ToBoolean(Program.settings["useTarkovTrackerAPI"]);
hideoutUpgrades_checkBox.Checked = Convert.ToBoolean(Program.settings["showHideoutUpgrades"]);
tarkovTrackerApiKey_textbox.Text = Program.settings["TarkovTrackerAPIKey"];
TrayIcon.Visible = true;
check_idle_time.Start();
}
private void MainForm_load(object sender, EventArgs e)
{
//not use
}
private void SetHook()
{
SetHook(false);
}
private void SetHook(bool force)
{
try
{
if (force)
{
Debug.WriteLine("force unhook.");
UnHook();
}
if (hhook_keyboard == IntPtr.Zero)
{
_proc_keyboard = hookKeyboardProc;
hhook_keyboard = SetWindowsHookEx(WH_KEYBOARD_LL, _proc_keyboard, h_instance, 0);
}
if (Convert.ToBoolean(Program.settings["CloseOverlayWhenMouseMoved"]))
{
setMouseHook();
}
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
private void setMouseHook()
{
if (hhook_mouse == IntPtr.Zero)
{
_proc_mouse = hookMouseProc;
hhook_mouse = SetWindowsHookEx(WH_MOUSE_LL, _proc_mouse, h_instance, 0);
}
}
private void unsetMouseHook()
{
if (hhook_mouse != IntPtr.Zero)
{
UnhookWindowsHookEx(hhook_mouse);
hhook_mouse = IntPtr.Zero;
_proc_mouse = null;
}
}
private void UnHook()
{
try
{
if (hhook_keyboard != IntPtr.Zero)
{
UnhookWindowsHookEx(hhook_keyboard);
hhook_keyboard = IntPtr.Zero;
_proc_keyboard = null;
}
unsetMouseHook();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
private IntPtr hookKeyboardProc(int code, IntPtr wParam, IntPtr lParam)
{
try
{
if (code >= 0 && wParam == (IntPtr)WM_KEYUP)
{
if (press_key_control == null)
{
if (Program.finishloadingballistics)
{
if ((Program.finishloadingTarkovTrackerAPI && Convert.ToBoolean(Program.settings["useTarkovTrackerAPI"])) || !Convert.ToBoolean(Program.settings["useTarkovTrackerAPI"]))
{
int vkCode = Marshal.ReadInt32(lParam);
if (vkCode == Int32.Parse(Program.settings["ShowOverlay_Key"]))
{
KeyPressedTime = DateTime.Now;
Debug.WriteLine("\n\n----------------" + Program.settings["ShowOverlay_Key"] + " Key Pressed -----------------");
if ((!timer.Enabled || !WaitingForTooltip) && (KeyPressedTime - presstime).TotalMilliseconds >= 200)
{
point = Control.MousePosition;
WaitingForTooltip = true; timer.Start();
LoadingItemInfo();
}
else if ((KeyPressedTime - presstime).TotalMilliseconds < 200)
{
Debug.WriteLine("Key pressed in less than 200 milliseconds.");
}
presstime = KeyPressedTime;
}
else if (vkCode == Int32.Parse(Program.settings["CompareOverlay_Key"]))
{
point = Control.MousePosition;
LoadingItemCompare();
}
else if (vkCode == Int32.Parse(Program.settings["HideOverlay_Key"])
|| vkCode == 9 //tab
|| vkCode == 27 //esc
)
{
CloseItemInfo();
CloseItemCompare();
}
}
else
{
point = Control.MousePosition;
overlay_info.ShowWaitAPI(point);
}
}
else
{
point = Control.MousePosition;
overlay_info.ShowWaitBallistics(point);
}
}
}
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
return CallNextHookEx(hhook_keyboard, code, (int)wParam, lParam);
}
private IntPtr hookMouseProc(int code, IntPtr wParam, IntPtr lParam)
{
try
{
if (!isinfoclosed && code >= 0
&& wParam == (IntPtr)WM_MOUSEMOVE
&& (Math.Abs(Control.MousePosition.X - point.X) > 60 || Math.Abs(Control.MousePosition.Y - point.Y) > 60))
{
timer.Stop(); WaitingForTooltip = false; repeatCount = 0;
CloseItemInfo();
Task UpdateAPI = Task.Factory.StartNew(() => Program.UpdateItemListAPI());
Task UpdateTarkovTrackerAPI = Task.Factory.StartNew(() => Program.UpdateTarkovTrackerAPI());
}
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
return CallNextHookEx(hhook_mouse, code, (int)wParam, lParam);
}
private uint GetIdleTime()
{
LASTINPUTINFO LastUserAction = new LASTINPUTINFO();
LastUserAction.cbSize = (uint)Marshal.SizeOf(LastUserAction);
GetLastInputInfo(ref LastUserAction);
return ((uint)Environment.TickCount - LastUserAction.dwTime);
}
public long GetTickCount()
{
return Environment.TickCount;
}
private void CloseApp()
{
if (TarkovTrackerCheckBox.Checked)
Program.settings["TarkovTrackerAPIKey"] = tarkovTrackerApiKey_textbox.Text;
UnHook();
TrayIcon.Dispose();
CloseItemInfo();
CloseItemCompare();
Program.SaveSettings();
System.Windows.Forms.Application.Exit();
}
public void LoadingItemInfo()
{
isinfoclosed = false;
cts_info.Cancel();
cts_info = new CancellationTokenSource();
if (timer.Enabled || WaitingForTooltip)
overlay_info.ShowWaitinfForTooltipInfo(point, cts_info.Token);
else
overlay_info.ShowLoadingInfo(point, cts_info.Token);
Task task = Task.Factory.StartNew(() => FindItemTask(true, cts_info.Token));
}
public void LoadingItemCompare()
{
if (iscompareclosed)
{
iscompareclosed = false;
cts_compare.Cancel();
cts_compare = new CancellationTokenSource();
}
overlay_compare.ShowLoadingCompare(point, cts_compare.Token);
Task task = Task.Factory.StartNew(() => FindItemTask(false, cts_compare.Token));
}
public void CloseItemInfo()
{
isinfoclosed = true;
cts_info.Cancel();
overlay_info.HideInfo();
}
public void CloseItemCompare()
{
iscompareclosed = true;
cts_compare.Cancel();
overlay_compare.HideCompare();
}
private int FindItemTask(bool isiteminfo, CancellationToken cts_one)
{
if (Convert.ToBoolean(Program.settings["RandomItem"]))
{
if (!cts_one.IsCancellationRequested)
{
try
{
Item item = Program.tarkovAPI.items[new Random().Next(Program.tarkovAPI.items.Count - 1)];
//item = MatchItemName("7.62x54r_7n37".ToLower().Trim().ToCharArray());
FindItemInfoAPI(item, isiteminfo, cts_one);
}
catch
{
Debug.WriteLine("itemlist null");
}
}
}
else
{
Bitmap fullimage = CaptureScreen(CheckisTarkov());
if (fullimage != null)
{
if (!cts_one.IsCancellationRequested)
{
FindItemAPI(fullimage, isiteminfo, cts_one);
}
}
else
{
Debug.WriteLine("image null");
}
}
return 0;
}
private IntPtr CheckisTarkov()
{
IntPtr hWnd = GetForegroundWindow();
if (hWnd != IntPtr.Zero)
{
StringBuilder sbWinText = new StringBuilder(260);
GetWindowText(hWnd, sbWinText, 260);
if (sbWinText.ToString() == Program.appname)
{
return hWnd;
}
}
Debug.WriteLine("error - no app");
return IntPtr.Zero;
}
private Bitmap CaptureScreen(IntPtr hWnd)
{
if (hWnd != IntPtr.Zero)
{
using (Graphics Graphicsdata = Graphics.FromHwnd(hWnd))
{
Rectangle rect = Rectangle.Round(Graphicsdata.VisibleClipBounds);
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
IntPtr hdc = g.GetHdc();
PrintWindow(hWnd, hdc, nFlags);
g.ReleaseHdc(hdc);
}
return bmp;
}
}
else
{
#if DEBUG
try
{
return new Bitmap(@"img\test.png");
}
catch (Exception e)
{
Debug.WriteLine("no test img" + e.Message);
}
#endif
Debug.WriteLine("error - no window");
return null;
}
}
private void ShowtestImage(Mat mat)
{
ShowtestImage("test", mat);
}
private void ShowtestImage(String name, Mat mat)
{
Action show = delegate ()
{
Cv2.ImShow(name, mat);
};
Invoke(show);
}
private String getTesseract(Mat textmat)
{
GettingItemInfo = true;
String text = "";
try
{
using (TesseractEngine ocr = new TesseractEngine(@"./Resources/tessdata", "eng", EngineMode.Default))//should use once
using (Bitmap temp = BitmapConverter.ToBitmap(textmat))
using (Page texts = ocr.Process(temp))
{
text = texts.GetText().Replace("\n", " ").Split(Program.splitcur)[0].Trim();
if (text == "GELLER")
text = "Hand drill";
else if (text == "[ZEULELED")
text = "Bandana";
Debug.WriteLine("Tesseract Text : " + text);
}
}
catch (Exception e)
{
Debug.WriteLine("Tesseract error: " + e.Message);
GettingItemInfo = false;
}
GettingItemInfo = false;
return text;
}
private void FindItemAPI(Bitmap fullimage, bool isiteminfo, CancellationToken cts_one)
{
Item item = new Item();
using (Mat ScreenMat_original = BitmapConverter.ToMat(fullimage))
using (Mat ScreenMat = ScreenMat_original.CvtColor(ColorConversionCodes.BGRA2BGR))
using (Mat rac_img = ScreenMat.InRange(linecolor, linecolor))
{
OpenCvSharp.Point[][] contours;
rac_img.FindContours(out contours, out HierarchyIndex[] hierarchy, RetrievalModes.List, ContourApproximationModes.ApproxSimple);
foreach (OpenCvSharp.Point[] contour in contours)
{
if (!cts_one.IsCancellationRequested)
{
OpenCvSharp.Rect rect2 = Cv2.BoundingRect(contour);
if (rect2.Width > 5 && rect2.Height > 10)
{
ScreenMat.Rectangle(rect2, Scalar.Black, 2);
using (Mat temp = ScreenMat.SubMat(rect2))
using (Mat temp2 = temp.Threshold(0, 255, ThresholdTypes.BinaryInv))
{
String text = getTesseract(temp);
String text2 = getTesseract(temp2);
if (!text.Equals("") || !text2.Equals("")) //If tooltip text found
{
item = MatchItemNameAPI(text, text2);
break;
}
}
}
/*else
timer.Start(); WaitingForTooltip = true;*/
}
}
if (!cts_one.IsCancellationRequested)
{
FindItemInfoAPI(item, isiteminfo, cts_one);
}
}
fullimage.Dispose();
}
private Item MatchItemNameAPI(string name, string name2)
{
char[] itemname = name.ToLower().Trim().ToCharArray();
char[] itemname2 = name2.ToLower().Trim().ToCharArray();
var result = new Item();
int d = 999;
foreach (var item in Program.tarkovAPI.items)
{
int d2;
if (itemname.Length > 0)
{
d2 = levenshteinDistance(itemname, item.name.ToLower().ToCharArray());
if (d2 < d)
{
result = item;
d = d2;
if (d == 0)
{
break;
}
}
}
if (itemname2.Length > 0)
{
d2 = levenshteinDistance(itemname2, item.name.ToLower().ToCharArray());
if (d2 < d)
{
result = item;
d = d2;
if (d == 0)
{
break;
}
}
}
}
if (result.name != null)
{
timer.Stop(); WaitingForTooltip = false; repeatCount = 0;
}
if (name == "Encrypted message" || name2 == "Encrypted message")
{
result = new Item();
result.name = "Encrypted Message";
}
Debug.WriteLine(d + " text match : " + result.name);
return result;
}
private int getMinimum(int val1, int val2, int val3)
{
int minNumber = val1;
if (minNumber > val2) minNumber = val2;
if (minNumber > val3) minNumber = val3;
return minNumber;
}
private int levenshteinDistance(char[] s, char[] t)
{
int m = s.Length;
int n = t.Length;
int[,] d = new int[m + 1, n + 1];
for (int i = 1; i < m; i++)
{
d[i, 0] = i;
}
for (int j = 1; j < n; j++)
{
d[0, j] = j;
}
for (int j = 1; j < n; j++)
{
for (int i = 1; i < m; i++)
{
if (s[i] == t[j])
{
d[i, j] = d[i - 1, j - 1];
}
else
{
d[i, j] = getMinimum(d[i - 1, j], d[i, j - 1], d[i - 1, j - 1]) + 1;
}
}
}
return d[m - 1, n - 1];
}
private void FindItemInfoAPI(Item item, bool isiteminfo, CancellationToken cts_one)
{
if (item.link != null) //Market link
{
try
{
if (item.types.Exists(e => e.Equals("ammo")) && !item.types.Exists(e => e.Equals("grenade"))) // "Round", "Slug", "Buckshot", "Grenade launcher cartridge" / ("gun" and not "preset" = weapons)
{
Program.blist.TryGetValue(item.name, out item.ballistic);
}
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
if (isiteminfo)
{
overlay_info.ShowInfoAPI(item, cts_one);
}
else
{
overlay_compare.ShowCompareAPI(item, cts_one);
}
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
CloseApp();
}
private void TrayExit_Click(object sender, EventArgs e)
{
CloseApp();
}
private void TrayShow_Click(object sender, EventArgs e)
{
this.Show();
}
private void TrayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)//must be checked
{
TrayIcon.Visible = true;
this.Hide();
e.Cancel = true;
}
}
private void MinimizetoTrayWhenStartup_CheckedChanged(object sender, EventArgs e)
{
Program.settings["MinimizetoTrayWhenStartup"] = (sender as CheckBox).Checked.ToString();
}
private void Tarkov_Official_Click(object sender, EventArgs e)
{
Process.Start(Program.official);
}
private void TarkovWiki_Click(object sender, EventArgs e)
{
Process.Start(Program.wiki);
}
private void TarkovMarket_Click(object sender, EventArgs e)
{
Process.Start(Program.tarkovmarket);
}
private void CloseOverlayWhenMouseMoved_CheckedChanged(object sender, EventArgs e)
{
Program.settings["CloseOverlayWhenMouseMoved"] = (sender as CheckBox).Checked.ToString();
if ((sender as CheckBox).Checked)
{
setMouseHook();
}
else
{
unsetMouseHook();
}
}
public void ChangePressKeyData(Keys? keycode)
{
if (press_key_control != null)
{
if (keycode != null)
{
press_key_control.Text = keycode.ToString();
}
press_key_control = null;
}
}
private void Overlay_Button_Click(object sender, EventArgs e)
{
press_key_control = (sender as Control);
int selected = 0;
if (press_key_control == ShowOverlay_Button)
{
selected = 1;
}
else if (press_key_control == HideOverlay_Button)
{
selected = 2;
}
else if (press_key_control == CompareOverlay_Button)
{
selected = 3;
}
if (selected != 0)
{
KeyPressCheck kpc = new KeyPressCheck(selected);
kpc.ShowDialog(this);
}
}
private void TransParent_Bar_Scroll(object sender, EventArgs e)
{
TrackBar tb = (sender as TrackBar);
Program.settings["Overlay_Transparent"] = tb.Value.ToString();
TransParent_Text.Text = Program.settings["Overlay_Transparent"] + "%";
overlay_info.ChangeTransparent(tb.Value);
}
private void Github1_Click(object sender, EventArgs e)
{
Process.Start(Program.github[0]);
}
private void Github2_Click(object sender, EventArgs e)
{
Process.Start(Program.github[1]);
}
private void CheckUpdate_Click(object sender, EventArgs e)
{
(sender as Control).Enabled = false;
Task task = Task.Factory.StartNew(() => UpdateTask(sender as Control));
}
private int UpdateTask(Control control)
{
try
{
using (TPVWebClient wc = new TPVWebClient())
{
string highgithub = "";
float highv = 0;
foreach (var github in Program.github)
{
String check = wc.DownloadString(github + Program.checkupdate);
if (!check.Equals(""))
{
String sp = check.Split('\n')[0];
if (sp.Contains("Tarkov Price Viewer"))
{
String[] sp2 = sp.Split(' ');
sp = sp2[sp2.Length - 1].Trim();
float v;
if (float.TryParse(sp.Replace("v", ""), out v))
{
if (highv < v)
{
highgithub = github;
highv = v;
}
}
}
}
}
if (!string.IsNullOrEmpty(highgithub))
{
string vs = "v" + highv;
if (!Program.settings["Version"].Equals(vs))
{
MessageBox.Show("New version (" + vs + ") found. \nCurrent Version is " + Program.settings["Version"]);
Process.Start(highgithub);
}
else
{
MessageBox.Show("You already have the latest version.");
}
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
MessageBox.Show("Can not check update. Please check your network.");
}
Action show = delegate ()
{
control.Enabled = true;
};
Invoke(show);
return 0;
}
private void last_price_box_CheckedChanged(object sender, EventArgs e)
{
Program.settings["Show_Last_Price"] = (sender as CheckBox).Checked.ToString();
}
private void day_price_box_CheckedChanged(object sender, EventArgs e)
{
Program.settings["Show_Day_Price"] = (sender as CheckBox).Checked.ToString();
}
private void week_price_box_CheckedChanged(object sender, EventArgs e)
{
Program.settings["Show_Week_Price"] = (sender as CheckBox).Checked.ToString();
}
private void sell_to_trader_box_CheckedChanged(object sender, EventArgs e)
{
Program.settings["Sell_to_Trader"] = (sender as CheckBox).Checked.ToString();
}
private void buy_from_trader_box_CheckedChanged(object sender, EventArgs e)
{
Program.settings["Buy_From_Trader"] = (sender as CheckBox).Checked.ToString();
}
private void needs_box_CheckedChanged(object sender, EventArgs e)
{
Program.settings["Needs"] = (sender as CheckBox).Checked.ToString();
}
private void barters_and_crafts_box_CheckedChanged(object sender, EventArgs e)
{
Program.settings["Barters_and_Crafts"] = (sender as CheckBox).Checked.ToString();
}
private void Exit_Button_Click(object sender, EventArgs e)
{
CloseApp();
}
private void RandomItem_CheckedChanged(object sender, EventArgs e)
{
Program.settings["RandomItem"] = (sender as CheckBox).Checked.ToString();
}
private void check_idle_time_Tick(object sender, EventArgs e)
{
if (GetIdleTime() >= idle_time)
{
idle_time += 3600000;
SetHook(true);
}
else
{
if (idle_time > 3600000)
{
idle_time = 3600000;
}
SetHook();
}
}
private void refreshAPI_b_Click(object sender, EventArgs e)
{
if (TarkovTrackerCheckBox.Checked)
Program.settings["TarkovTrackerAPIKey"] = tarkovTrackerApiKey_textbox.Text;
SetHook(true);
}
private void Tarkov_Dev_Click(object sender, EventArgs e)
{
Process.Start(Program.tarkov_dev);
}
private void TarkovTrackerCheckBox_CheckedChanged(object sender, EventArgs e)
{
Program.settings["useTarkovTrackerAPI"] = (sender as CheckBox).Checked.ToString();
}
private void label1_MouseHover(object sender, EventArgs e)
{
TarkovTrackerAPI_tooltip.SetToolTip(label1, "Use TarkovTracker.io to show only your active tasks and hideout upgrades. And hide completed.");
}
private void TarkovTrackerCheckBox_MouseHover(object sender, EventArgs e)
{
TarkovTrackerAPI_tooltip.SetToolTip(TarkovTrackerCheckBox, "Use TarkovTracker.io to show only your active tasks and hideout upgrades. And hide completed.");
}
private void label2_MouseHover(object sender, EventArgs e)
{
TarkovTrackerAPI_tooltip.SetToolTip(label2, "Go to \"https://tarkovtracker.io/settings\" to get your API key.");
}
private void tarkovTrackerApiKey_textbox_MouseHover(object sender, EventArgs e)
{
TarkovTrackerAPI_tooltip.SetToolTip(tarkovTrackerApiKey_textbox, "Go to \"https://tarkovtracker.io/settings\" to get your API key.");
}
private void TarkovTracker_button_Click(object sender, EventArgs e)
{
Process.Start(Program.tarkovtracker);
}
private void hideoutUpgrades_checkBox_CheckedChanged(object sender, EventArgs e)
{
Program.settings["showHideoutUpgrades"] = (sender as CheckBox).Checked.ToString();
}
}
}