-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.vb
More file actions
1753 lines (1406 loc) · 79.6 KB
/
Form1.vb
File metadata and controls
1753 lines (1406 loc) · 79.6 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
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
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.IO
Imports System.Threading
Imports Newtonsoft.Json.Linq
Imports System.Net.Http
Imports Emgu.CV
Imports Emgu.CV.CvEnum
Imports Emgu.CV.Structure
Imports System.Reflection
Public Class Form1
Private Declare Function EnumWindows Lib "user32.dll" (lpEnumFunc As EnumWindowCallback, lParam As IntPtr) As Boolean
<DllImport("user32.dll", CharSet:=CharSet.Unicode, EntryPoint:="GetWindowTextW")>
Private Shared Function GetWindowText(hWnd As IntPtr, lpString As StringBuilder, nMaxCount As Integer) As Integer
End Function
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (hWnd As IntPtr) As Integer
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (hWnd As IntPtr, ByRef processId As Integer) As Integer
Private Declare Function ShowWindow Lib "user32.dll" (hWnd As IntPtr, nCmdShow As Integer) As Integer
Private Declare Function SetForegroundWindow Lib "user32.dll" (hWnd As IntPtr) As Integer
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (hWnd As IntPtr, nIndex As Integer) As Integer
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (hWnd As IntPtr, nIndex As Integer, dwNewLong As Integer) As Integer
Private Declare Function SetWindowPos Lib "user32.dll" (hWnd As IntPtr, hWndInsertAfter As IntPtr, X As Integer, Y As Integer, cx As Integer, cy As Integer, uFlags As UInteger) As Boolean
<DllImport("user32.dll", CharSet:=CharSet.Unicode, EntryPoint:="GetClassNameW")>
Private Shared Function GetClassName(hWnd As IntPtr, lpClassName As StringBuilder, nMaxCount As Integer) As Integer
End Function
Private Delegate Function EnumWindowCallback(ByVal hWnd As IntPtr, ByVal lParam As IntPtr) As Boolean
Private Const GWL_STYLE As Integer = -16
Private Const WS_BORDER As Integer = &H800000
Private Const SWP_FRAMECHANGED As UInteger = &H20
Private Const SWP_SHOWWINDOW As UInteger = &H40
Private Const SWP_NOZORDER As UInteger = &H4
Private Const SWP_NOSIZE As UInteger = &H1
Private Const SW_MAXIMIZE As Integer = 3
Private Const SW_MINIMIZE As Integer = 6
Private Const SW_SHOWMINNOACTIVE As Integer = 7
Dim Game As String = My.Settings.SelectedGame
Dim GPU As String = My.Settings.MainGPU
Dim StretchedEnabled As Boolean = False
Dim ApexMenuMatchFound As Boolean = False
Dim AutoCloseCounter As Integer = 5
Dim AutoMinimizeCounter As Integer = 5
Dim RightClickedGame As String = ""
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Check if the LastLocation is set in My.Settings and the form is fully visible on any screen
Dim fixedFormSize As New Size(316, 572) ' Fixed size of the form
Dim formRectangle As New Rectangle(My.Settings.LastLocation, fixedFormSize)
Dim isFormFullyVisible As Boolean = False
If Not My.Settings.LastLocation.IsEmpty Then
' Iterate through all screens to check if the form is fully visible on any screen
For Each scr In Screen.AllScreens
' Check if the formRectangle is within the screen's bounds considering the fixed size
If scr.Bounds.IntersectsWith(formRectangle) Then
' Further check if the form's entire size is within the screen's working area
If scr.WorkingArea.Contains(formRectangle) Then
isFormFullyVisible = True
Exit For
End If
End If
Next
' If the form is fully visible on a screen, load its last location; otherwise, use WindowsDefaultLocation
If isFormFullyVisible Then
Me.Location = My.Settings.LastLocation
Else
Me.StartPosition = FormStartPosition.WindowsDefaultLocation
End If
Else
' Set a default location for the form
Me.StartPosition = FormStartPosition.WindowsDefaultLocation
End If
'Check If It's A Dev Build
If DevBuild = True Then
DevMenu.Show()
Me.Text = "True Stretched (Dev)"
ElseIf My.Settings.BetaBuild = True Then
Me.Text = "True Stretched (Beta " + My.Settings.BetaLetter.ToUpper() + ")"
End If
'Only Check for Saved Monitor Information if program has completed first run
If My.Settings.FirstRun = False Then
' Ensure Native & Stretched Resolutions Don't match (Fixes "Disable True Stretched" being the only option)
If GetGameMonitor("Resolution") = My.Settings.StretchedResolution Then
My.Settings.StretchedResolution = "1440x1080"
My.Settings.Save()
Else
End If
'Check to see if opening long already enabled
If GetMonitorResolution(, GetGameMonitor("DeviceName")) = My.Settings.StretchedResolution Then
StretchedEnabled = True
Button1.Text = "Disable True Stretched"
End If
End If
'Load Last Selected Game & Guide
Label4.Location = My.Settings.GameLabelLocation
Label4.Text = Game
If Game = "Apex Legends" Then 'Settings For Apex
Me.BackgroundImage = My.Resources.Apex_Background
GroupBox1.Text = "Apex Guide"
LinkLabel1.Location = New Point(0, 65)
LinkLabel1.Text = "https://TrueStretched.com/ApexLegends"
ElseIf Game = "Farlight 84" Then 'Settings For Farlight 84
Me.BackgroundImage = My.Resources.Farlight84_Background
GroupBox1.Text = "Farlight 84 Guide"
LinkLabel1.Location = New Point(6, 65)
LinkLabel1.Text = "https://TrueStretched.com/Farlight84"
ElseIf Game = "Fortnite" Then 'Settings For Fortnite
Me.BackgroundImage = My.Resources.Fortnight_Background
GroupBox1.Text = "Fortnite Guide"
LinkLabel1.Location = New Point(6, 65)
LinkLabel1.Text = "https://TrueStretched.com/Fortnite"
ElseIf Game = "Valorant" Then 'Settings For Valorant
Me.BackgroundImage = My.Resources.Valorant_Background
GroupBox1.Text = "Valorant Guide"
LinkLabel1.Location = New Point(6, 65)
LinkLabel1.Text = "https://TrueStretched.com/Valorant"
GroupBox3.Visible = True
'-Valorant Widescreen Fix
If My.Settings.ValorantWidescreenFix = True Then
WidescreenFixCheckBox.Checked = True
Button1.Text = "Enable Widescreen Fix"
End If
'-End of Valorant Widescreen Fix
ElseIf Game = "XDefiant" Then 'Settings For XDefiant
Me.BackgroundImage = My.Resources.XDefiant_Background
GroupBox1.Text = "XDefiant Guide"
LinkLabel1.Location = New Point(6, 65)
LinkLabel1.Text = "https://TrueStretched.com/XDefiant"
End If
' Set the groupbox backgrounds color to black with translucency
Dim translucentBlack As Color = Color.FromArgb(128, 29, 29, 29)
GroupBox1.BackColor = translucentBlack
GroupBox3.BackColor = translucentBlack
Label5.BackColor = Color.Transparent
LinkLabel1.BackColor = Color.Transparent
WidescreenFixCheckBox.BackColor = Color.Transparent
'Tooltips Settings
Dim toolTip1 As New System.Windows.Forms.ToolTip With {
.AutoPopDelay = 10000,
.InitialDelay = 500,
.ReshowDelay = 500,
.ShowAlways = True
}
'Tooltips for Game Icons
toolTip1.SetToolTip(Me.ApexPictureBox, "Apex Legends")
toolTip1.SetToolTip(Me.Farlight84PictureBox, "Farlight 84")
toolTip1.SetToolTip(Me.FortnitePictureBox, "Fortnite")
toolTip1.SetToolTip(Me.ValorantPictureBox, "Valorant")
toolTip1.SetToolTip(Me.XDefiantPictureBox, "XDefiant")
'General Tooltips
toolTip1.SetToolTip(Me.PictureBox2, "Settings")
toolTip1.SetToolTip(Me.WidescreenFixCheckBox, "Enabling This Options **DISABLES** Stretching The Resolution!!!")
'Check for Updates on Startup (Make Sure Application Has Network Access)
If My.Settings.CheckForUpdateOnStart = True Then
If DevBuild = False Then
If InternetConnection() = True Then
CheckForUpdates()
End If
End If
End If
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown ' Code to run after Form1 has loaded fully
' Check For First Run
If My.Settings.FirstRun = True Then
' Save Form1 Location Before Showing First Run
My.Settings.LastLocation = Me.Location
My.Settings.Save()
' Show First Run Dialog
FirstRun.Show()
End If
' Auto Disable True Stretched if command line argument exists
If AutoDisable = True AndAlso StretchedEnabled = True Then
Button1.PerformClick()
End If
' Auto Launch Stretched Game is command line argument exists
If AutoStretch = True Then
If StretchedEnabled Then
' If Stretched is already enabled check for AutoDisable Argument
If StretchedEnabled AndAlso AutoDisable Then
' Do nothing
End If
Else
' Auto Enable Stretched from specified game in argument
Button1.PerformClick()
End If
End If
End Sub
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
' Check if the form is being minimized
If Me.WindowState = FormWindowState.Minimized Then
' Use ShowWindow to minimize without focus
ShowWindow(Me.Handle, SW_SHOWMINNOACTIVE)
End If
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
' Check if the Form1 Location is fully visible on any screen
Dim fixedFormSize As New Size(316, 572) ' Fixed size of the form
Dim formRectangle As New Rectangle(Me.Location, fixedFormSize)
Dim isFormFullyVisible As Boolean = False
' Iterate through all screens to check if the form is fully visible on any screen
For Each scr In Screen.AllScreens
' Check if the formRectangle is within the screen's bounds considering the fixed size
If scr.Bounds.IntersectsWith(formRectangle) Then
' Further check if the form's entire size is within the screen's working area
If scr.WorkingArea.Contains(formRectangle) Then
isFormFullyVisible = True
Exit For
End If
End If
Next
' If the form is fully visible on a screen, save its location; otherwise, don't save
If isFormFullyVisible Then
My.Settings.LastLocation = Me.Location
My.Settings.Save()
End If
' Send Closing Log Message
TrueLog("Close", "--True Stretched Closing--")
End Sub
Private Async Sub CheckForUpdates()
Dim httpClient As New HttpClient()
Dim json As String = Await httpClient.GetStringAsync("https://download.truestretched.com/latestversion.json")
Dim jsonObject As JObject = JObject.Parse(json)
Dim serverVersionString As String = jsonObject("Version").ToString()
Dim serverVersion As New Version(serverVersionString)
Dim currentVersionLong As Version = Assembly.GetExecutingAssembly().GetName().Version
Dim currentVersion As New Version(String.Format("{0}.{1}.{2}", currentVersionLong.Major, currentVersionLong.Minor, currentVersionLong.Build))
Dim currentVersionString As String = String.Format("{0}.{1}.{2}", currentVersionLong.Major, currentVersionLong.Minor, currentVersionLong.Build)
If My.Settings.BetaBuild Then
currentVersionString &= My.Settings.BetaLetter
End If
Dim serverBeta As Boolean = jsonObject("Beta").ToObject(Of Boolean)()
Dim serverBetaLetter As String = jsonObject("BetaLetter").ToString()
Dim skippedVersion As String = My.Settings.SkippedVersion
If serverBeta Then
If My.Settings.BetaBuild Then ' If user has opted in for beta updates
serverVersionString &= serverBetaLetter ' Append beta letter to the server version
Else ' If user has not opted in for beta updates
Return ' Do not prompt for update
End If
End If
' Check if the server version (with or without beta letter) is the same as the skipped version
If serverVersionString.Equals(skippedVersion) Then
Return ' Do not prompt for update
End If
' If server version is greater than the current version, prompt for update
If serverVersion > currentVersion Then
UpdateAvailable.Show()
ElseIf serverVersion = currentVersion AndAlso serverBeta AndAlso serverVersionString > currentVersionString Then
UpdateAvailable.Show()
End If
End Sub
Private Async Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
' Get Stretched in format needed
Dim StretchedResolution = ParseResolution(My.Settings.StretchedResolution)
' Get Native Resoultion in format needed (Allow Global Variable Override)
Dim NativeResolution As (Width As Integer, Height As Integer)
If (OverrideNative) Then
NativeResolution = ParseResolution(OverrideNativeRes)
Else
NativeResolution = ParseResolution(GetGameMonitor("MaxResolution"))
End If
'---Apex Legends Mode Code Starts---
If Game = "Apex Legends" Then
If Button1.Text = "Enable True Stretched" Then 'Enable True Stretched
If Not CheckForWindow("Apex Legends") Then
Dim url As String = "steam://rungameid/1172470"
Dim psi As New ProcessStartInfo(url) With {
.UseShellExecute = True
}
If My.Settings.SetDisplayResolution = True Then
' Change the resolution of the screen
Label3.Text = "Changing Screen Resolution"
SetMonitorResolution(GetGameMonitor("DeviceName"), StretchedResolution.Width, StretchedResolution.Height)
End If
StretchedEnabled = True
EnableApexStretched()
Process.Start(psi)
Label3.Text = "Waiting For Continue Menu"
ApexMenuMatchFound = False
ApexMenuMatchWait()
Else
MessageBox.Show("Please Close Apex Legends Before Enabling", "True Stretched - Error")
End If
Else 'Disable True Stretched
Button1.Text = "Enable True Stretched"
If My.Settings.RevertDisplayResolution = True Then
SetMonitorResolution(GetGameMonitor("DeviceName"), NativeResolution.Width, NativeResolution.Height)
End If
DisableApexStretched()
ApexMenuMatchFound = True
Label3.ForeColor = Color.Green
Label3.Text = "Successfully disabled True Stretched Res"
StretchedEnabled = False
End If
'---Apex Legends Mode Code Ends---
'---Farlight 84 Mode Code Starts---
ElseIf Game = "Farlight 84" Then
If Button1.Text = "Enable True Stretched" Then 'Enable True Stretched
If Not CheckForWindow("Farlight 84") Then
Dim url As String = "steam://rungameid/1928420"
Dim psi As New ProcessStartInfo(url) With {
.UseShellExecute = True
}
If My.Settings.SetDisplayResolution = True Then
' Change the resolution of the screen
Label3.Text = "Changing Screen Resolution"
SetMonitorResolution(GetGameMonitor("DeviceName"), StretchedResolution.Width, StretchedResolution.Height)
End If
StretchedEnabled = True
EnableFarlight84Stretched()
Process.Start(psi)
If Label3.Text = "Game is not running!" Then
SetMonitorResolution(GetGameMonitor("DeviceName"), NativeResolution.Width, NativeResolution.Height)
DisableFarlight84Stretched()
Label3.ForeColor = Color.Red
Label3.Text = "Game is not running!"
Else
Label3.ForeColor = Color.Green
Label3.Text = "Successfully enabled True Stretched Res"
If My.Settings.AutoClose = True Then
AutoCloseTimer.Start()
ElseIf My.Settings.AutoMinimize = True Then
AutoMinimizeTimer.Start()
End If
End If
Else
MessageBox.Show("Please Close Farlight 84 Before Enabling", "True Stretched - Error")
End If
Else 'Disable True Stretched
Button1.Text = "Enable True Stretched"
If My.Settings.RevertDisplayResolution = True Then
SetMonitorResolution(GetGameMonitor("DeviceName"), NativeResolution.Width, NativeResolution.Height)
End If
DisableFarlight84Stretched()
Label3.ForeColor = Color.Green
Label3.Text = "Successfully disabled True Stretched Res"
StretchedEnabled = False
End If
'---Farlight 84 Mode Code Ends---
'---Fortnite Mode Code Starts---
ElseIf Game = "Fortnite" Then
If Button1.Text = "Enable True Stretched" Then 'Enable True Stretched
If Not CheckForWindow("Fortnite") Then
Dim url As String = "com.epicgames.launcher://apps/fn%3A4fe75bbc5a674f4f9b356b5c90567da5%3AFortnite?action=launch&silent=true"
Dim psi As New ProcessStartInfo(url) With {
.UseShellExecute = True
}
If My.Settings.SetDisplayResolution = True Then
' Change the resolution of the screen
Label3.Text = "Changing Screen Resolution"
SetMonitorResolution(GetGameMonitor("DeviceName"), StretchedResolution.Width, StretchedResolution.Height)
End If
StretchedEnabled = True
EnableFortniteStretched()
Process.Start(psi)
If Label3.Text = "Game is not running!" Then
SetMonitorResolution(GetGameMonitor("DeviceName"), NativeResolution.Width, NativeResolution.Height)
DisableFortniteStretched()
Label3.ForeColor = Color.Red
Label3.Text = "Game is not running!"
Else
Label3.ForeColor = Color.Green
Label3.Text = "Successfully enabled True Stretched Res"
If My.Settings.AutoClose = True Then
AutoCloseTimer.Start()
ElseIf My.Settings.AutoMinimize = True Then
AutoMinimizeTimer.Start()
End If
End If
Else
MessageBox.Show("Please Close Fortnite Before Enabling", "True Stretched - Error")
End If
Else 'Disable True Stretched
Button1.Text = "Enable True Stretched"
If My.Settings.RevertDisplayResolution = True Then
SetMonitorResolution(GetGameMonitor("DeviceName"), NativeResolution.Width, NativeResolution.Height)
End If
DisableFortniteStretched()
Label3.ForeColor = Color.Green
Label3.Text = "Successfully disabled True Stretched Res"
StretchedEnabled = False
End If
'---Fortnite Mode Code Ends---
'---Valorant Mode Code Starts---
ElseIf Game = "Valorant" Then
If Button1.Text = "Enable True Stretched" Then 'Enable True Stretched
' Disable Enable Button Long Starting Valorant
Button1.Text = "Enabling True Stretched"
Button1.Enabled = False
If Await EnableValorantStretched() Then
' Update Status Label
Label3.ForeColor = Color.Green
Label3.Text = "Valorant True Stretched Enabled!"
' Update Button1
Button1.Text = "Disable True Stretched"
' Auto Minimize or Auto Close is User has the option enabled
If My.Settings.AutoClose = True Then
AutoCloseTimer.Start()
ElseIf My.Settings.AutoMinimize = True Then
AutoMinimizeTimer.Start()
End If
Else
' Update Status Label
Label3.ForeColor = Color.Red
Label3.Text = "Error Stretching Valorant!"
End If
Else 'Disable True Stretched
' Disable Enable Button Long Starting Valorant
Button1.Text = "Enable True Stretched"
Button1.Enabled = False
If (DisableValorantStretched()) Then
' Update Status Label
Label3.ForeColor = Color.Green
Label3.Text = "Valorant True Stretched Disabled!"
End If
End If
'---Valorant Mode Code Ends---
'---XDefiant Mode Code Starts---
ElseIf Game = "XDefiant" Then
If Button1.Text = "Enable True Stretched" Then 'Enable True Stretched
' Log XDefiant Start of Enabling Stretched to File
TrueLog("Info", "Enabling XDefiant Stretched...")
If Not CheckForWindow("XDefiant") Then
Dim url As String = "uplay://launch/15657/0"
Dim psi As New ProcessStartInfo(url) With {
.UseShellExecute = True
}
If My.Settings.SetDisplayResolution = True Then
' Change the resolution of the screen
Label3.Text = "Changing Screen Resolution"
' Log Screen Res Changing
TrueLog("Info", "Changing Monitor Resolution...")
' Change Screen res
SetMonitorResolution(GetGameMonitor("DeviceName"), StretchedResolution.Width, StretchedResolution.Height)
End If
StretchedEnabled = True
Process.Start(psi)
Await CountdownTimer(30, True, True)
If Label3.Text = "Game is not running!" Then
SetMonitorResolution(GetGameMonitor("DeviceName"), NativeResolution.Width, NativeResolution.Height)
Label3.ForeColor = Color.Red
Label3.Text = "Game is not running!"
' Log Error
TrueLog("Error", "Stretching XDefiant Failed - Game is not running!")
Else
Label3.ForeColor = Color.Green
Label3.Text = "Successfully enabled True Stretched Res"
' Log Stretch Success
TrueLog("Info", "Successfully enabled True Stretched Res - Stretching Complete!")
If My.Settings.AutoClose = True Then
AutoCloseTimer.Start()
ElseIf My.Settings.AutoMinimize = True Then
AutoMinimizeTimer.Start()
End If
End If
Else
MessageBox.Show("Please Close XDefiant Before Enabling", "True Stretched - Error")
End If
Else 'Disable True Stretched
' Log Disabling XDefiant Stretched to File
TrueLog("Info", "Disabling XDefiant True Stretched Res...")
Button1.Text = "Enable True Stretched"
If My.Settings.RevertDisplayResolution = True Then
SetMonitorResolution(GetGameMonitor("DeviceName"), NativeResolution.Width, NativeResolution.Height)
' Log Reverting Monitor Resolution to File
TrueLog("Info", "Reverting Monitor Resolution Completed")
End If
Label3.ForeColor = Color.Green
Label3.Text = "Successfully disabled True Stretched Res"
StretchedEnabled = False
' Log Disable Success
TrueLog("Info", "Successfully Disabled XDefiant True Stretched Res!")
End If
'---XDefiant Mode Code Ends---
End If
' Renable Main Button
Button1.Enabled = True
End Sub
Public Sub ApexMenuMatchWait()
Task.Run(Sub()
While Not ApexMenuMatchFound
' Capture the screen
Dim screenSize As New Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
Dim screenImage As New Bitmap(screenSize.Width, screenSize.Height)
Using g As Graphics = Graphics.FromImage(screenImage)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenSize)
End Using
' Convert the Bitmap to a BitmapData object
Dim bmpData As System.Drawing.Imaging.BitmapData = screenImage.LockBits(New Rectangle(0, 0, screenImage.Width, screenImage.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, screenImage.PixelFormat)
' Create an Emgu.CV.Image from the BitmapData
Dim sourceImage As New Image(Of Bgr, Byte)(screenImage.Width, screenImage.Height, bmpData.Stride, bmpData.Scan0)
' Unlock the bits of the original Bitmap
screenImage.UnlockBits(bmpData)
' Convert the template image to a BitmapData object
If Screen.PrimaryScreen.Bounds.Width = "1440" AndAlso Screen.PrimaryScreen.Bounds.Height = "1080" Then ' For 1440x1080
Dim templateBitmap As Bitmap = My.Resources.Apex_Continue_Screen_Button_Template_1440x1080
Dim templateData As System.Drawing.Imaging.BitmapData = templateBitmap.LockBits(New Rectangle(0, 0, templateBitmap.Width, templateBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, templateBitmap.PixelFormat)
' Create an Emgu.CV.Image from the BitmapData
Dim templateImage As New Image(Of Bgr, Byte)(templateBitmap.Width, templateBitmap.Height, templateData.Stride, templateData.Scan0)
' Unlock the bits of the template Bitmap
templateBitmap.UnlockBits(templateData)
' Convert the images to grayscale
Dim sourceGray As Image(Of Gray, Byte) = sourceImage.Convert(Of Gray, Byte)()
Dim templateGray As Image(Of Gray, Byte) = templateImage.Convert(Of Gray, Byte)()
' Dispose of the Bitmap objects
screenImage.Dispose()
templateBitmap.Dispose()
' Create the result matrix
Dim result As New Mat()
' Perform template matching
CvInvoke.MatchTemplate(sourceGray, templateGray, result, TemplateMatchingType.CcoeffNormed)
' Find the minimum and maximum values and their locations
Dim minVal As Double, maxVal As Double
Dim minLoc As Point, maxLoc As Point
CvInvoke.MinMaxLoc(result, minVal, maxVal, minLoc, maxLoc)
' If Match is found
If maxVal > 0.45 Then
' Set ApexMenuMatchFound to True to exit the loop
ApexMenuMatchFound = True
Label3.Invoke(Sub() Label3.Text = "On Continue Menu - Fixing Bars")
FullToWinToFullScreenApex()
If My.Settings.AutoClose = True Then
Me.Invoke(Sub() AutoCloseTimer.Start())
ElseIf My.Settings.AutoMinimize = True Then
Me.Invoke(Sub() AutoMinimizeTimer.Start())
End If
End If
' Add a delay to prevent high CPU usage
Thread.Sleep(100) ' Sleep for 100 milliseconds
' Dispose of the images and the result matrix to free up memory
sourceImage.Dispose()
templateImage.Dispose()
sourceGray.Dispose()
templateGray.Dispose()
result.Dispose()
ElseIf Screen.PrimaryScreen.Bounds.Width = "1280" AndAlso Screen.PrimaryScreen.Bounds.Height = "1024" Then ' For 1280x1024
Dim templateBitmap As Bitmap = My.Resources.Apex_Continue_Screen_Button_Template_1280x1024
Dim templateData As System.Drawing.Imaging.BitmapData = templateBitmap.LockBits(New Rectangle(0, 0, templateBitmap.Width, templateBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, templateBitmap.PixelFormat)
' Create an Emgu.CV.Image from the BitmapData
Dim templateImage As New Image(Of Bgr, Byte)(templateBitmap.Width, templateBitmap.Height, templateData.Stride, templateData.Scan0)
' Unlock the bits of the template Bitmap
templateBitmap.UnlockBits(templateData)
' Convert the images to grayscale
Dim sourceGray As Image(Of Gray, Byte) = sourceImage.Convert(Of Gray, Byte)()
Dim templateGray As Image(Of Gray, Byte) = templateImage.Convert(Of Gray, Byte)()
' Dispose of the Bitmap objects
screenImage.Dispose()
templateBitmap.Dispose()
' Create the result matrix
Dim result As New Mat()
' Perform template matching
CvInvoke.MatchTemplate(sourceGray, templateGray, result, TemplateMatchingType.CcoeffNormed)
' Find the minimum and maximum values and their locations
Dim minVal As Double, maxVal As Double
Dim minLoc As Point, maxLoc As Point
CvInvoke.MinMaxLoc(result, minVal, maxVal, minLoc, maxLoc)
' If Match is found
If maxVal > 0.45 Then
' Set ApexMenuMatchFound to True to exit the loop
ApexMenuMatchFound = True
Label3.Invoke(Sub() Label3.Text = "On Continue Menu - Fixing Bars")
FullToWinToFullScreenApex()
If My.Settings.AutoClose = True Then
Me.Invoke(Sub() AutoCloseTimer.Start())
ElseIf My.Settings.AutoMinimize = True Then
Me.Invoke(Sub() AutoMinimizeTimer.Start())
End If
End If
' Add a delay to prevent high CPU usage
Thread.Sleep(100) ' Sleep for 100 milliseconds
' Dispose of the images and the result matrix to free up memory
sourceImage.Dispose()
templateImage.Dispose()
sourceGray.Dispose()
templateGray.Dispose()
result.Dispose()
ElseIf Screen.PrimaryScreen.Bounds.Width = "1280" AndAlso Screen.PrimaryScreen.Bounds.Height = "960" Then ' For 1280x960
Dim templateBitmap As Bitmap = My.Resources.Apex_Continue_Screen_Button_Template_1280x960
Dim templateData As System.Drawing.Imaging.BitmapData = templateBitmap.LockBits(New Rectangle(0, 0, templateBitmap.Width, templateBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, templateBitmap.PixelFormat)
' Create an Emgu.CV.Image from the BitmapData
Dim templateImage As New Image(Of Bgr, Byte)(templateBitmap.Width, templateBitmap.Height, templateData.Stride, templateData.Scan0)
' Unlock the bits of the template Bitmap
templateBitmap.UnlockBits(templateData)
' Convert the images to grayscale
Dim sourceGray As Image(Of Gray, Byte) = sourceImage.Convert(Of Gray, Byte)()
Dim templateGray As Image(Of Gray, Byte) = templateImage.Convert(Of Gray, Byte)()
' Dispose of the Bitmap objects
screenImage.Dispose()
templateBitmap.Dispose()
' Create the result matrix
Dim result As New Mat()
' Perform template matching
CvInvoke.MatchTemplate(sourceGray, templateGray, result, TemplateMatchingType.CcoeffNormed)
' Find the minimum and maximum values and their locations
Dim minVal As Double, maxVal As Double
Dim minLoc As Point, maxLoc As Point
CvInvoke.MinMaxLoc(result, minVal, maxVal, minLoc, maxLoc)
' If Match is found
If maxVal > 0.45 Then
' Set ApexMenuMatchFound to True to exit the loop
ApexMenuMatchFound = True
Label3.Invoke(Sub() Label3.Text = "On Continue Menu - Fixing Bars")
FullToWinToFullScreenApex()
If My.Settings.AutoClose = True Then
Me.Invoke(Sub() AutoCloseTimer.Start())
ElseIf My.Settings.AutoMinimize = True Then
Me.Invoke(Sub() AutoMinimizeTimer.Start())
End If
End If
' Add a delay to prevent high CPU usage
Thread.Sleep(100) ' Sleep for 100 milliseconds
' Dispose of the images and the result matrix to free up memory
sourceImage.Dispose()
templateImage.Dispose()
sourceGray.Dispose()
templateGray.Dispose()
result.Dispose()
ElseIf Screen.PrimaryScreen.Bounds.Width = "1024" AndAlso Screen.PrimaryScreen.Bounds.Height = "768" Then ' For 1024x768
Dim templateBitmap As Bitmap = My.Resources.Apex_Continue_Screen_Button_Template_1024x768
Dim templateData As System.Drawing.Imaging.BitmapData = templateBitmap.LockBits(New Rectangle(0, 0, templateBitmap.Width, templateBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, templateBitmap.PixelFormat)
' Create an Emgu.CV.Image from the BitmapData
Dim templateImage As New Image(Of Bgr, Byte)(templateBitmap.Width, templateBitmap.Height, templateData.Stride, templateData.Scan0)
' Unlock the bits of the template Bitmap
templateBitmap.UnlockBits(templateData)
' Convert the images to grayscale
Dim sourceGray As Image(Of Gray, Byte) = sourceImage.Convert(Of Gray, Byte)()
Dim templateGray As Image(Of Gray, Byte) = templateImage.Convert(Of Gray, Byte)()
' Dispose of the Bitmap objects
screenImage.Dispose()
templateBitmap.Dispose()
' Create the result matrix
Dim result As New Mat()
' Perform template matching
CvInvoke.MatchTemplate(sourceGray, templateGray, result, TemplateMatchingType.CcoeffNormed)
' Find the minimum and maximum values and their locations
Dim minVal As Double, maxVal As Double
Dim minLoc As Point, maxLoc As Point
CvInvoke.MinMaxLoc(result, minVal, maxVal, minLoc, maxLoc)
' If Match is found
If maxVal > 0.45 Then
' Set ApexMenuMatchFound to True to exit the loop
ApexMenuMatchFound = True
Label3.Invoke(Sub() Label3.Text = "On Continue Menu - Fixing Bars")
FullToWinToFullScreenApex()
If My.Settings.AutoClose = True Then
Me.Invoke(Sub() AutoCloseTimer.Start())
ElseIf My.Settings.AutoMinimize = True Then
Me.Invoke(Sub() AutoMinimizeTimer.Start())
End If
End If
' Add a delay to prevent high CPU usage
Thread.Sleep(100) ' Sleep for 100 milliseconds
' Dispose of the images and the result matrix to free up memory
sourceImage.Dispose()
templateImage.Dispose()
sourceGray.Dispose()
templateGray.Dispose()
result.Dispose()
ElseIf Screen.PrimaryScreen.Bounds.Width = "800" AndAlso Screen.PrimaryScreen.Bounds.Height = "600" Then ' For 800x600
Dim templateBitmap As Bitmap = My.Resources.Apex_Continue_Screen_Button_Template_800x600
Dim templateData As System.Drawing.Imaging.BitmapData = templateBitmap.LockBits(New Rectangle(0, 0, templateBitmap.Width, templateBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, templateBitmap.PixelFormat)
' Create an Emgu.CV.Image from the BitmapData
Dim templateImage As New Image(Of Bgr, Byte)(templateBitmap.Width, templateBitmap.Height, templateData.Stride, templateData.Scan0)
' Unlock the bits of the template Bitmap
templateBitmap.UnlockBits(templateData)
' Convert the images to grayscale
Dim sourceGray As Image(Of Gray, Byte) = sourceImage.Convert(Of Gray, Byte)()
Dim templateGray As Image(Of Gray, Byte) = templateImage.Convert(Of Gray, Byte)()
' Dispose of the Bitmap objects
screenImage.Dispose()
templateBitmap.Dispose()
' Create the result matrix
Dim result As New Mat()
' Perform template matching
CvInvoke.MatchTemplate(sourceGray, templateGray, result, TemplateMatchingType.CcoeffNormed)
' Find the minimum and maximum values and their locations
Dim minVal As Double, maxVal As Double
Dim minLoc As Point, maxLoc As Point
CvInvoke.MinMaxLoc(result, minVal, maxVal, minLoc, maxLoc)
' If Match is found
If maxVal > 0.45 Then
' Set ApexMenuMatchFound to True to exit the loop
ApexMenuMatchFound = True
Label3.Invoke(Sub() Label3.Text = "On Continue Menu - Fixing Bars")
FullToWinToFullScreenApex()
If My.Settings.AutoClose = True Then
Me.Invoke(Sub() AutoCloseTimer.Start())
ElseIf My.Settings.AutoMinimize = True Then
Me.Invoke(Sub() AutoMinimizeTimer.Start())
End If
End If
' Add a delay to prevent high CPU usage
Thread.Sleep(100) ' Sleep for 100 milliseconds
' Dispose of the images and the result matrix to free up memory
sourceImage.Dispose()
templateImage.Dispose()
sourceGray.Dispose()
templateGray.Dispose()
result.Dispose()
Else 'Backup to 1920x1080
Dim templateBitmap As Bitmap = My.Resources.Apex_Continue_Screen_Button_Template
Dim templateData As System.Drawing.Imaging.BitmapData = templateBitmap.LockBits(New Rectangle(0, 0, templateBitmap.Width, templateBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, templateBitmap.PixelFormat)
' Create an Emgu.CV.Image from the BitmapData
Dim templateImage As New Image(Of Bgr, Byte)(templateBitmap.Width, templateBitmap.Height, templateData.Stride, templateData.Scan0)
' Unlock the bits of the template Bitmap
templateBitmap.UnlockBits(templateData)
' Convert the images to grayscale
Dim sourceGray As Image(Of Gray, Byte) = sourceImage.Convert(Of Gray, Byte)()
Dim templateGray As Image(Of Gray, Byte) = templateImage.Convert(Of Gray, Byte)()
' Dispose of the Bitmap objects
screenImage.Dispose()
templateBitmap.Dispose()
' Create the result matrix
Dim result As New Mat()
' Perform template matching
CvInvoke.MatchTemplate(sourceGray, templateGray, result, TemplateMatchingType.CcoeffNormed)
' Find the minimum and maximum values and their locations
Dim minVal As Double, maxVal As Double
Dim minLoc As Point, maxLoc As Point
CvInvoke.MinMaxLoc(result, minVal, maxVal, minLoc, maxLoc)
' If Match is found
If maxVal > 0.45 Then
' Set ApexMenuMatchFound to True to exit the loop
ApexMenuMatchFound = True
Label3.Invoke(Sub() Label3.Text = "On Continue Menu - Fixing Bars")
FullToWinToFullScreenApex()
If My.Settings.AutoClose = True Then
Me.Invoke(Sub() AutoCloseTimer.Start())
ElseIf My.Settings.AutoMinimize = True Then
Me.Invoke(Sub() AutoMinimizeTimer.Start())
End If
End If
' Add a delay to prevent high CPU usage
Thread.Sleep(100) ' Sleep for 100 milliseconds
' Dispose of the images and the result matrix to free up memory
sourceImage.Dispose()
templateImage.Dispose()
sourceGray.Dispose()
templateGray.Dispose()
result.Dispose()
End If
End While
End Sub)
End Sub
Public Sub EnableFarlight84Stretched()
Dim Farlight84ConfigFilePath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\Solarland\Saved\Config\WindowsClient\GameUserSettings.ini"
' Set the desired screen resolution
Dim resolution As String = My.Settings.StretchedResolution
Dim dimensions() As String = resolution.Split("x"c)
Dim width As Integer = Integer.Parse(dimensions(0))
Dim height As Integer = Integer.Parse(dimensions(1))
If File.Exists(Farlight84ConfigFilePath) Then
' Create a FileInfo object
' Turn off read-only
Dim fileInfo As New FileInfo(Farlight84ConfigFilePath) With {
.IsReadOnly = False
}
Dim lines As List(Of String) = File.ReadAllLines(Farlight84ConfigFilePath).ToList()
For i As Integer = 0 To lines.Count - 1
If lines(i).StartsWith("FullscreenMode=") Then
lines(i) = "FullscreenMode=0"
ElseIf lines(i).StartsWith("LastConfirmedFullscreenMode=") Then
lines(i) = "LastConfirmedFullscreenMode=0"
ElseIf lines(i).StartsWith("PreferredFullscreenMode=") Then
lines(i) = "PreferredFullscreenMode=1"
ElseIf lines(i).StartsWith("ResolutionSizeX=") Then
lines(i) = "ResolutionSizeX=" & width
ElseIf lines(i).StartsWith("ResolutionSizeY=") Then
lines(i) = "ResolutionSizeY=" & height
ElseIf lines(i).StartsWith("LastUserConfirmedResolutionSizeX=") Then
lines(i) = "LastUserConfirmedResolutionSizeX=" & width
ElseIf lines(i).StartsWith("LastUserConfirmedResolutionSizeY=") Then
lines(i) = "LastUserConfirmedResolutionSizeY=" & height
ElseIf lines(i).StartsWith("DesiredScreenWidth=") Then
lines(i) = "DesiredScreenWidth=" & width
ElseIf lines(i).StartsWith("DesiredScreenHeight=") Then
lines(i) = "DesiredScreenHeight=" & height
ElseIf lines(i).StartsWith("LastUserConfirmedDesiredScreenWidth=") Then
lines(i) = "LastUserConfirmedDesiredScreenWidth=" & width
ElseIf lines(i).StartsWith("LastUserConfirmedDesiredScreenHeight=") Then
lines(i) = "LastUserConfirmedDesiredScreenHeight=" & height
End If
Next
File.WriteAllLines(Farlight84ConfigFilePath, lines.ToArray())
' Set the file back to read-only
fileInfo.IsReadOnly = True
End If
Button1.Text = "Disable True Stretched"
End Sub
Public Shared Sub DisableFarlight84Stretched()
Dim Farlight84ConfigFilePath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\Solarland\Saved\Config\WindowsClient\GameUserSettings.ini"
' Set the desired screen resolution
Dim resolution As String = GetGameMonitor("Resolution")
Dim dimensions() As String = resolution.Split("x"c)
Dim width As Integer = Integer.Parse(dimensions(0))
Dim height As Integer = Integer.Parse(dimensions(1))