-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
1311 lines (1114 loc) · 48.3 KB
/
MainWindow.xaml.cs
File metadata and controls
1311 lines (1114 loc) · 48.3 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
using Aimmy2.Class;
using Aimmy2.Controls;
using Aimmy2.MouseMovementLibraries.GHubSupport;
using Aimmy2.Other;
using Aimmy2.Theme;
using Aimmy2.UILibrary;
using AimmyWPF.Class;
using Class;
using InputLogic;
using Other;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using UILibrary;
using Visuality;
namespace Aimmy2
{
public partial class MainWindow : Window
{
#region Managers and Windows
// Core managers (lazy-loaded)
private readonly Lazy<InputBindingManager> _bindingManager = new(() => new InputBindingManager());
private static readonly Lazy<GithubManager> _githubManager = new(() => new GithubManager());
private readonly Lazy<UI> _uiManager = new(() => new UI());
private readonly Lazy<AntiRecoilManager> _arManager = new(() => new AntiRecoilManager());
private Lazy<FileManager>? _fileManager;
// Windows
private static readonly Lazy<FOV> _fovWindow = new(() =>
{
var window = new FOV();
// Force immediate reposition to current display
window.ForceReposition();
return window;
});
private static readonly Lazy<DetectedPlayerWindow> _dpWindow = new(() =>
{
var window = new DetectedPlayerWindow();
// Force immediate reposition to current display
window.ForceReposition();
return window;
});
// Public accessors
internal InputBindingManager bindingManager => _bindingManager.Value;
internal FileManager fileManager => _fileManager?.Value ?? throw new InvalidOperationException("FileManager not initialized");
public static FOV FOVWindow => _fovWindow.Value;
public static DetectedPlayerWindow DPWindow => _dpWindow.Value;
public static GithubManager githubManager => _githubManager.Value;
public UI uiManager => _uiManager.Value;
public AntiRecoilManager arManager => _arManager.Value;
#endregion
#region UI State
public SettingsMenuControl? SettingsMenuControlInstance { get; set; }
internal Dictionary<string, AToggle> toggleInstances = new();
private readonly Dictionary<string, UserControl?> _menuControls = new();
private readonly Dictionary<string, bool> _menuInitialized = new();
private UserControl? _currentControl;
private string _currentMenu = "AimMenu";
private bool _currentlySwitching;
private ScrollViewer? CurrentScrollViewer;
public double ActualFOV { get; set; } = 640;
private double _currentGradientAngle;
// FPS monitoring
private System.Windows.Threading.DispatcherTimer? _fpsUpdateTimer;
// Menu names constant
private static readonly string[] MenuNames = { "AimMenu", "ModelMenu", "SettingsMenu", "AboutMenu" };
#endregion
#region Initialization
public MainWindow()
{
InitializeComponent();
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
SaveDictionary.EnsureDirectoriesExist();
InitializeMenus();
InitializeFileManagerEarly();
// Load configurations BEFORE loading any menus
// This ensures minimize states are loaded from file before menu initialization
await LoadConfigurationsAsync();
// Now load the initial menu - it will use the loaded minimize states
LoadInitialMenu();
// Continue with the rest of initialization
await InitializeApplicationAsync();
UpdateAboutSpecs();
ApplyThemeGradients();
ThemeManager.LoadMediaSettings();
// Initialize FPS monitoring
InitializeFPSMonitoring();
}
catch (Exception ex)
{
ShowError($"Error during startup: {ex.Message}", ex);
}
}
private void InitializeMenus()
{
foreach (var menu in MenuNames)
{
_menuControls[menu] = null;
_menuInitialized[menu] = false;
}
}
private void InitializeFileManagerEarly()
{
var modelMenu = new ModelMenuControl();
modelMenu.Initialize(this);
_menuControls["ModelMenu"] = modelMenu;
InitializeFileManager(modelMenu);
}
private void LoadInitialMenu()
{
LoadMenu("AimMenu");
UpdateSliderVisibility(uiManager);
_currentMenu = "AimMenu";
}
private async Task InitializeApplicationAsync()
{
CheckRunningFromTemp();
// Initialize DisplayManager FIRST before anything else that depends on display info
DisplayManager.Initialize();
// Now that DisplayManager is initialized, we can create windows
InitializeWindows();
EnsureRequiredFiles();
// Configuration loading has been moved to Window_Loaded before menu initialization
// Only load specific configurations that aren't related to UI state
await Task.Run(() =>
{
arManager.HoldDownLoad();
});
SetupKeybindings();
ConfigurePropertyChangers();
ApplyInitialSettings();
ListenForKeybinds();
// Subscribe to display changes after everything is initialized
DisplayManager.DisplayChanged += OnDisplayChanged;
}
private void OnDisplayChanged(object? sender, DisplayChangedEventArgs e)
{
// Force update all windows to new display
DisplayManager.ForceUpdateWindows();
}
private void CheckRunningFromTemp()
{
if (Directory.GetCurrentDirectory().Contains("Temp"))
{
MessageBox.Show(
"Hi, it is made aware that you are running Aimmy without extracting it from the zip file. " +
"Please extract Aimmy from the zip file or Aimmy will not be able to run properly.\n\nThank you.",
"Aimmy V2");
}
}
private void InitializeWindows()
{
// Create windows but don't show them yet
var fov = FOVWindow; // This triggers lazy initialization
var dpw = DPWindow; // This triggers lazy initialization
// Ensure they're positioned on the current display
fov.ForceReposition();
dpw.ForceReposition();
// Set references in Dictionary
Dictionary.DetectedPlayerOverlay = dpw;
Dictionary.FOVWindow = fov;
}
private void EnsureRequiredFiles()
{
var labelsPath = "bin\\labels\\labels.txt";
var labelsDir = Path.GetDirectoryName(labelsPath);
// Ensure the directory exists
if (!string.IsNullOrEmpty(labelsDir) && !Directory.Exists(labelsDir))
{
Directory.CreateDirectory(labelsDir);
}
// Create the file if it doesn't exist
if (!File.Exists(labelsPath))
{
File.WriteAllText(labelsPath, "Enemy");
}
}
private async Task LoadConfigurationsAsync()
{
// Run non-UI operations in background
await Task.Run(() =>
{
// Load configurations that don't create UI
var configs = new[]
{
(Dictionary.minimizeState, "bin\\minimize.cfg"),
(Dictionary.bindingSettings, "bin\\binding.cfg"),
(Dictionary.colorState, "bin\\colors.cfg"),
(Dictionary.filelocationState, "bin\\filelocations.cfg"),
(Dictionary.dropdownState, "bin\\dropdown.cfg")
};
foreach (var (dict, path) in configs)
{
SaveDictionary.LoadJSON(dict, path);
}
});
// Load these on UI thread since they might show notifications
LoadConfig();
LoadAntiRecoilConfig();
arManager.HoldDownLoad(); // needs to be ran on ui thread or just cant be run via Task.Run -whip
ApplyThemeColorFromConfig();
}
private void ApplyThemeColorFromConfig()
{
if (Dictionary.colorState.TryGetValue("Theme Color", out var themeColor))
{
var colorString = themeColor?.ToString();
if (!string.IsNullOrEmpty(colorString))
{
try
{
ThemeManager.SetThemeColor(colorString);
}
catch (Exception ex)
{
}
}
}
}
private void SetupKeybindings()
{
var keybinds = new[]
{
"Aim Keybind", "Second Aim Keybind", "Dynamic FOV Keybind",
"Emergency Stop Keybind", "Model Switch Keybind",
"Anti Recoil Keybind", "Disable Anti Recoil Keybind",
"Gun 1 Key", "Gun 2 Key"
};
foreach (var keybind in keybinds)
{
bindingManager.SetupDefault(keybind, Dictionary.bindingSettings[keybind].ToString());
}
}
private void ConfigurePropertyChangers()
{
PropertyChanger.ReceiveNewConfig = LoadConfig;
}
private void ApplyInitialSettings()
{
// FOV settings
ActualFOV = Convert.ToDouble(Dictionary.sliderSettings["FOV Size"]);
PropertyChanger.PostNewFOVSize(ActualFOV);
PropertyChanger.PostColor((Color)ColorConverter.ConvertFromString(Dictionary.colorState["FOV Color"].ToString()));
// Detected player window settings
var dpSettings = new[]
{
("Detected Player Color", (Action<object>)(c => PropertyChanger.PostDPColor((Color)c))),
("AI Confidence Font Size", (Action<object>)(s => PropertyChanger.PostDPFontSize((int)(double)s))),
("Corner Radius", (Action<object>)(r => PropertyChanger.PostDPWCornerRadius((int)(double)r))),
("Border Thickness", (Action<object>)(t => PropertyChanger.PostDPWBorderThickness((double)t))),
("Opacity", (Action<object>)(o => PropertyChanger.PostDPWOpacity((double)o)))
};
foreach (var (key, action) in dpSettings)
{
if (key.Contains("Color"))
{
action(ColorConverter.ConvertFromString(Dictionary.colorState[key].ToString()));
}
else
{
action(Convert.ToDouble(Dictionary.sliderSettings[key]));
}
}
}
private void UpdateAboutSpecs()
{
if (_menuControls["AboutMenu"] is AboutMenuControl aboutMenu)
{
aboutMenu.AboutSpecsControl.Content = "Loading system specs...";
Task.Run(() =>
{
var specs = $"{GetProcessorName()} • {GetVideoControllerName()} • {GetFormattedMemorySize()}GB RAM";
Dispatcher.Invoke(() => aboutMenu.AboutSpecsControl.Content = specs);
});
}
}
private void ShowError(string message, Exception ex)
{
MessageBox.Show($"{message}\n\nStack trace: {ex.StackTrace}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
private void ApplyThemeGradients()
{
if (!Dictionary.colorState.TryGetValue("Theme Color", out var themeColor)) return;
var colorString = themeColor?.ToString();
if (string.IsNullOrEmpty(colorString)) return;
try
{
var color = (Color)ColorConverter.ConvertFromString(colorString);
var gradientMappings = new Dictionary<string, Func<Color, Color>>
{
["GradientThemeStop"] = c => Color.FromRgb((byte)(c.R * 0.3), (byte)(c.G * 0.3), (byte)(c.B * 0.3)),
["HighlighterGradient1"] = c => c,
["HighlighterGradient2"] = c => Color.FromArgb(102, c.R, c.G, c.B)
};
foreach (var (elementName, colorTransform) in gradientMappings)
{
if (FindName(elementName) is GradientStop gradientStop)
{
gradientStop.Color = colorTransform(color);
}
}
}
catch (Exception ex)
{
}
}
private void InitializeFileManager(ModelMenuControl modelMenu)
{
if (_fileManager == null)
{
_fileManager = new Lazy<FileManager>(() => new FileManager(
modelMenu.ModelListBoxControl,
modelMenu.SelectedModelNotifierControl,
modelMenu.ConfigsListBoxControl,
modelMenu.SelectedConfigNotifierControl));
try
{
var fm = _fileManager.Value;
}
catch (Exception ex)
{
}
}
}
#endregion
#region Window Events
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) => DragMove();
private void Minimize_Click(object sender, RoutedEventArgs e) => WindowState = WindowState.Minimized;
private void Exit_Click(object sender, RoutedEventArgs e) => Application.Current.Shutdown();
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (_fileManager?.IsValueCreated == true)
{
fileManager.InQuittingState = true;
}
DisableAllFeatures();
CloseWindows();
CleanupDrivers();
// Dispose menu controls to save their states
if (_menuControls["AimMenu"] is AimMenuControl aimMenu)
aimMenu.Dispose();
if (_menuControls["SettingsMenu"] is SettingsMenuControl settingsMenu)
settingsMenu.Dispose();
SaveAllConfigurations();
FileManager.AIManager?.Dispose();
// Clean up display manager
DisplayManager.DisplayChanged -= OnDisplayChanged;
DisplayManager.Dispose();
Application.Current.Shutdown();
}
private void DisableAllFeatures()
{
var features = new[] { "Aim Assist", "FOV", "Show Detected Player" };
foreach (var feature in features)
{
Dictionary.toggleState[feature] = false;
}
}
private void CloseWindows()
{
FOVWindow.Close();
DPWindow.Close();
}
private void CleanupDrivers()
{
if (Dictionary.dropdownState.TryGetValue("Mouse Movement Method", out var method) &&
method?.ToString() == "LG HUB")
{
LGMouse.Close();
}
}
private void SaveAllConfigurations()
{
Dictionary.colorState["Theme Color"] = ThemeManager.GetThemeColorHex();
SaveDictionary.WriteJSON(Dictionary.sliderSettings
.Concat(Dictionary.dropdownState)
//.Where(kvp => kvp.Key != "Screen Capture Method")
.GroupBy(kvp => kvp.Key)
.ToDictionary(g => g.Key, g => g
.First().Value));
SaveDictionary.WriteJSON(Dictionary.minimizeState, "bin\\minimize.cfg");
SaveDictionary.WriteJSON(Dictionary.bindingSettings, "bin\\binding.cfg");
SaveDictionary.WriteJSON(Dictionary.dropdownState, "bin\\dropdown.cfg");
SaveDictionary.WriteJSON(Dictionary.colorState, "bin\\colors.cfg");
SaveDictionary.WriteJSON(Dictionary.filelocationState, "bin\\filelocations.cfg");
SaveDictionary.WriteJSON(Dictionary.AntiRecoilSettings, "bin\\anti_recoil_configs\\Default.cfg");
}
#endregion
#region Menu Management
private UserControl GetOrCreateMenuControl(string menuName)
{
if (_menuControls[menuName] != null)
return _menuControls[menuName]!;
var newControl = menuName == "ModelMenu" && _menuControls["ModelMenu"] != null
? _menuControls["ModelMenu"]!
: CreateMenuControl(menuName);
_menuControls[menuName] = newControl;
if (!_menuInitialized[menuName])
{
InitializeMenuControl(menuName, newControl);
_menuInitialized[menuName] = true;
}
return newControl;
}
private UserControl CreateMenuControl(string menuName) => menuName switch
{
"AimMenu" => new AimMenuControl(),
"ModelMenu" => new ModelMenuControl(),
"SettingsMenu" => new SettingsMenuControl(),
"AboutMenu" => new AboutMenuControl(),
_ => throw new ArgumentException($"Unknown menu: {menuName}")
};
private void InitializeMenuControl(string menuName, UserControl control)
{
try
{
switch (control)
{
case AimMenuControl aimMenu:
aimMenu.Initialize(this);
CurrentScrollViewer = aimMenu.AimMenuScrollViewer;
LoadDropdownStates();
break;
case ModelMenuControl modelMenu:
if (!_menuInitialized["ModelMenu"])
modelMenu.Initialize(this);
break;
case SettingsMenuControl settingsMenu:
settingsMenu.Initialize(this);
LoadDropdownStates();
SettingsMenuControlInstance = settingsMenu;
break;
case AboutMenuControl aboutMenu:
aboutMenu.Initialize(this);
UpdateAboutSpecs();
break;
}
}
catch (Exception ex)
{
}
}
private void LoadMenu(string menuName)
{
var control = GetOrCreateMenuControl(menuName);
ContentArea.Children.Clear();
ContentArea.Children.Add(control);
_currentControl = control;
UpdateCurrentScrollViewer(menuName, control);
}
private void UpdateCurrentScrollViewer(string menuName, UserControl control)
{
CurrentScrollViewer = control switch
{
AimMenuControl aim => aim.AimMenuScrollViewer,
ModelMenuControl model => model.ModelMenuScrollViewer,
SettingsMenuControl settings => settings.SettingsMenuScrollViewer,
AboutMenuControl about => about.AboutMenuScrollViewer,
_ => CurrentScrollViewer
};
}
private async void MenuSwitch(object sender, RoutedEventArgs e)
{
if (sender is not Button { Tag: string newMenuName } ||
!IsValidMenu(newMenuName) ||
_currentlySwitching ||
_currentMenu == newMenuName) return;
_currentlySwitching = true;
try
{
Animator.ObjectShift(
TimeSpan.FromMilliseconds(150), // Fade between menu buttons
MenuHighlighter,
MenuHighlighter.Margin,
((Button)sender).Margin);
await SwitchToMenu(newMenuName);
_currentMenu = newMenuName;
}
catch (Exception ex)
{
}
finally
{
_currentlySwitching = false;
}
}
private bool IsValidMenu(string? menuName) =>
!string.IsNullOrEmpty(menuName) && _menuControls.ContainsKey(menuName!);
private async Task SwitchToMenu(string menuName)
{
if (_currentControl != null)
{
Animator.FadeOut(_currentControl);
await Task.Delay(150); // Fade between menu content
}
LoadMenu(menuName);
Animator.Fade(_currentControl!);
}
#endregion
#region Toggle Actions
internal void Toggle_Action(string title)
{
var actions = new Dictionary<string, Action>
{
["FOV"] = () =>
{
FOVWindow.Visibility = GetToggleVisibility(title);
// Force reposition when showing the window
if (Dictionary.toggleState[title])
{
FOVWindow.ForceReposition();
}
},
["Sticky Aim"] = () => UpdateSliderVisibility(uiManager),
["Show Detected Player"] = () =>
{
ShowHideDPWindow();
DPWindow.DetectedPlayerFocus.Visibility = GetToggleVisibility(title, true);
// Force reposition when showing the window
if (Dictionary.toggleState[title])
{
DPWindow.ForceReposition();
}
},
["Show AI Confidence"] = () => DPWindow.DetectedPlayerConfidence.Visibility = GetToggleVisibility(title, true),
["Mouse Background Effect"] = () => { if (!Dictionary.toggleState[title]) RotaryGradient.Angle = 0; },
["UI TopMost"] = () => Topmost = Dictionary.toggleState[title],
["StreamGuard"] = () =>
{
StreamGuardHelper.ApplyStreamGuardToAllWindows(Dictionary.toggleState[title]);
},
["EMA Smoothening"] = () =>
{
MouseManager.IsEMASmoothingEnabled = Dictionary.toggleState[title];
},
["X Axis Percentage Adjustment"] = () => UpdateSliderVisibility(uiManager),
["Y Axis Percentage Adjustment"] = () => UpdateSliderVisibility(uiManager)
};
if (actions.TryGetValue(title, out var action))
{
action();
}
}
private static void UpdateSliderVisibility(UI uiManager)
{
bool useYPercent = Dictionary.toggleState["Y Axis Percentage Adjustment"];
bool useXPercent = Dictionary.toggleState["X Axis Percentage Adjustment"];
bool thresholdEnabled = Dictionary.toggleState["Sticky Aim"];
uiManager.S_StickyAimThreshold.Visibility = thresholdEnabled ? Visibility.Visible : Visibility.Collapsed;
uiManager.S_YOffset.Visibility = useYPercent ? Visibility.Collapsed : Visibility.Visible;
uiManager.S_YOffsetPercent.Visibility = useYPercent ? Visibility.Visible : Visibility.Collapsed;
uiManager.S_XOffset.Visibility = useXPercent ? Visibility.Collapsed : Visibility.Visible;
uiManager.S_XOffsetPercent.Visibility = useXPercent ? Visibility.Visible : Visibility.Collapsed;
}
private Visibility GetToggleVisibility(string title, bool collapsed = false) =>
Dictionary.toggleState[title]
? Visibility.Visible
: (collapsed ? Visibility.Collapsed : Visibility.Hidden);
private static void ShowHideDPWindow()
{
if (Dictionary.toggleState["Show Detected Player"])
{
DPWindow.Show();
// Force reposition when showing
DPWindow.ForceReposition();
}
else
{
DPWindow.Hide();
}
}
#endregion
#region UI Helper Methods
public void UpdateToggleUI(AToggle toggle, bool isEnabled)
{
Application.Current.Dispatcher.Invoke(() =>
{
if (isEnabled)
toggle.EnableSwitch();
else
toggle.DisableSwitch();
});
}
public ComboBoxItem AddDropdownItem(ADropdown dropdown, string title)
{
var dropdownitem = new ComboBoxItem
{
Content = title,
Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)),
FontFamily = TryFindResource("Atkinson Hyperlegible") as FontFamily
};
dropdownitem.Selected += (s, e) =>
{
var key = dropdown.DropdownTitle.Content?.ToString()
?? throw new NullReferenceException("dropdown.DropdownTitle.Content.ToString() is null");
Dictionary.dropdownState[key] = title;
};
dropdown.DropdownBox.Items.Add(dropdownitem);
return dropdownitem;
}
#endregion
#region Keybind Handling
private void ListenForKeybinds()
{
bindingManager.OnBindingPressed += HandleKeybindPressed;
bindingManager.OnBindingReleased += HandleKeybindReleased;
}
private void HandleKeybindPressed(string bindingId)
{
var handlers = new Dictionary<string, Action>
{
["Model Switch Keybind"] = HandleModelSwitch,
["Dynamic FOV Keybind"] = () => ApplyDynamicFOV(true),
["Emergency Stop Keybind"] = HandleEmergencyStop,
["Anti Recoil Keybind"] = () => HandleAntiRecoil(true),
["Disable Anti Recoil Keybind"] = DisableAntiRecoil,
["Gun 1 Key"] = () => LoadGunConfig("Gun 1 Config"),
["Gun 2 Key"] = () => LoadGunConfig("Gun 2 Config"),
// Keybinds for toggles
["Aim Assist TKB"] = () => uiManager.T_AimAligner.Reader.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)),
["Constant AI Tracking TKB"] = () => uiManager.T_ConstantAITracking.Reader.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)),
["Predictions TKB"] = () => uiManager.T_Predictions.Reader.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)),
["EMA Smoothening TKB"] = () => uiManager.T_EMASmoothing.Reader.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)),
["Sticky Aim TKB"] = () => uiManager.T_StickyAim.Reader.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)),
["Enable StreamGuard TKB"] = () => uiManager.T_StreamGuard.Reader.RaiseEvent(new RoutedEventArgs(Button.ClickEvent))
};
handlers.GetValueOrDefault(bindingId)?.Invoke();
}
private void HandleKeybindReleased(string bindingId)
{
var handlers = new Dictionary<string, Action>
{
["Dynamic FOV Keybind"] = () => ApplyDynamicFOV(false),
["Anti Recoil Keybind"] = () => HandleAntiRecoil(false)
};
handlers.GetValueOrDefault(bindingId)?.Invoke();
}
private void HandleModelSwitch()
{
if (!Dictionary.toggleState["Enable Model Switch Keybind"] || FileManager.CurrentlyLoadingModel)
return;
if (_menuControls["ModelMenu"] is ModelMenuControl modelMenu)
{
var modelListBox = modelMenu.ModelListBoxControl;
modelListBox.SelectedIndex = (modelListBox.SelectedIndex >= 0 &&
modelListBox.SelectedIndex < modelListBox.Items.Count - 1)
? modelListBox.SelectedIndex + 1
: 0;
}
}
private void ApplyDynamicFOV(bool apply)
{
if (!Dictionary.toggleState["Dynamic FOV"])
{
FOVWindow.Circle.BeginAnimation(FrameworkElement.WidthProperty, null);
FOVWindow.Circle.BeginAnimation(FrameworkElement.HeightProperty, null);
FOVWindow.RectangleShape.BeginAnimation(FrameworkElement.WidthProperty, null);
FOVWindow.RectangleShape.BeginAnimation(FrameworkElement.HeightProperty, null);
FOVWindow.UpdateFOVSize(ActualFOV);
return;
}
var targetSize = apply ? Convert.ToDouble(Dictionary.sliderSettings["Dynamic FOV Size"]) : ActualFOV;
Dictionary.sliderSettings["FOV Size"] = targetSize;
AnimateFOVSize(targetSize);
}
/* Old
private void ApplyDynamicFOV(bool apply)
{
if (!Dictionary.toggleState["Dynamic FOV"]) return;
var targetSize = apply ? Convert.ToDouble(Dictionary.sliderSettings["Dynamic FOV Size"]) : ActualFOV;
Dictionary.sliderSettings["FOV Size"] = targetSize;
AnimateFOVSize(targetSize);
}
*/
private void AnimateFOVSize(double targetSize)
{
var duration = TimeSpan.FromMilliseconds(500);
Animator.WidthShift(duration, FOVWindow.Circle, FOVWindow.Circle.ActualWidth, targetSize);
Animator.HeightShift(duration, FOVWindow.Circle, FOVWindow.Circle.ActualHeight, targetSize);
Animator.WidthShift(duration, FOVWindow.RectangleShape, FOVWindow.RectangleShape.ActualWidth, targetSize);
Animator.HeightShift(duration, FOVWindow.RectangleShape, FOVWindow.RectangleShape.ActualHeight, targetSize);
}
/* Old
private void AnimateFOVSize(double targetSize)
{
var duration = TimeSpan.FromMilliseconds(500);
Animator.WidthShift(duration, FOVWindow.Circle, FOVWindow.Circle.ActualWidth, targetSize);
Animator.HeightShift(duration, FOVWindow.Circle, FOVWindow.Circle.ActualHeight, targetSize);
}
*/
private void HandleEmergencyStop()
{
var features = new[] { "Aim Assist", "Constant AI Tracking", "Auto Trigger" };
var toggles = new[] { uiManager.T_AimAligner, uiManager.T_ConstantAITracking, uiManager.T_AutoTrigger };
for (int i = 0; i < features.Length; i++)
{
Dictionary.toggleState[features[i]] = false;
if (toggles[i] != null)
UpdateToggleUI(toggles[i], false);
}
LogManager.Log(LogManager.LogLevel.Info, "[Emergency Stop Keybind] Disabled all AI features.", true);
}
private void HandleAntiRecoil(bool start)
{
if (!Dictionary.toggleState["Anti Recoil"]) return;
if (start)
{
arManager.IndependentMousePress = 0;
arManager.HoldDownTimer.Start();
}
else
{
arManager.HoldDownTimer.Stop();
arManager.IndependentMousePress = 0;
}
}
private void DisableAntiRecoil()
{
if (!Dictionary.toggleState["Anti Recoil"]) return;
Dictionary.toggleState["Anti Recoil"] = false;
UpdateToggleUI(uiManager.T_AntiRecoil!, false);
LogManager.Log(LogManager.LogLevel.Info, "[Disable Anti Recoil Keybind] Disabled Anti-Recoil.", true);
}
private void LoadGunConfig(string configKey)
{
if (Dictionary.toggleState["Enable Gun Switching Keybind"])
{
if (Dictionary.filelocationState.TryGetValue(configKey, out var configPath))
{
LoadAntiRecoilConfig(configPath.ToString(), true);
}
}
}
#endregion
#region UI Effects
private void Main_Background_Gradient(object sender, MouseEventArgs e)
{
if (!Dictionary.toggleState["Mouse Background Effect"]) return;
var mousePosition = WinAPICaller.GetCursorPosition();
var translatedMousePos = PointFromScreen(new Point(mousePosition.X, mousePosition.Y));
var targetAngle = Math.Atan2(
translatedMousePos.Y - (MainBorder.ActualHeight * 0.5),
translatedMousePos.X - (MainBorder.ActualWidth * 0.5)) * (180 / Math.PI);
_currentGradientAngle = CalculateSmoothedAngle(targetAngle);
RotaryGradient.Angle = _currentGradientAngle;
}
private double CalculateSmoothedAngle(double targetAngle)
{
const double fullCircle = 360;
const double halfCircle = 180;
const double clamp = 1;
var angleDifference = (targetAngle - _currentGradientAngle + fullCircle) % fullCircle;
if (angleDifference > halfCircle)
angleDifference -= fullCircle;
var clampedDifference = Math.Max(Math.Min(angleDifference, clamp), -clamp);
return (_currentGradientAngle + clampedDifference + fullCircle) % fullCircle;
}
#endregion
#region Configuration Management
private void LoadDropdownStates()
{
var dropdownConfigs = new[]
{
// AimMenu dropdowns
(uiManager.D_PredictionMethod, "Prediction Method", new Dictionary<string, int>
{
["Kalman Filter"] = 0,
["Shall0e's Prediction"] = 1,
["wisethef0x's EMA Prediction"] = 2
}),
(uiManager.D_DetectionAreaType, "Detection Area Type", new Dictionary<string, int>
{
["Closest to Center Screen"] = 0,
["Closest to Mouse"] = 1
}),
(uiManager.D_AimingBoundariesAlignment, "Aiming Boundaries Alignment", new Dictionary<string, int>
{
["Center"] = 0,
["Top"] = 1,
["Bottom"] = 2
}),
// SettingsMenu dropdowns
(uiManager.D_MouseMovementMethod, "Mouse Movement Method", new Dictionary<string, int>
{
["Mouse Event"] = 0,
["SendInput"] = 1,
["LG HUB"] = 2,
["Razer Synapse (Require Razer Peripheral)"] = 3,
["ddxoft Virtual Input Driver"] = 4
}),
(uiManager.D_ScreenCaptureMethod, "Screen Capture Method", new Dictionary<string, int>
{
["DirectX"] = 0,
["GDI+"] = 1
}),
(uiManager.D_ImageSize, "Image Size", new Dictionary<string, int>
{
["640"] = 0,
["512"] = 1,
["416"] = 2,
["320"] = 3,
["256"] = 4,
["160"] = 5
}),
};
foreach (var (dropdown, key, mappings) in dropdownConfigs)
{
if (dropdown == null)
{
continue;
}
if (Dictionary.dropdownState.TryGetValue(key, out var value))
{
var stringValue = value?.ToString() ?? "";
if (mappings.TryGetValue(stringValue, out int index))
{
dropdown.DropdownBox.SelectedIndex = index;
}
else
{
LogManager.Log(LogManager.LogLevel.Warning, $"No mapping found for '{stringValue}' in '{key}' dropdown.");
}
}
}
}
private void LoadConfig(string path = "bin\\configs\\Default.cfg", bool loading_from_configlist = false)
{
SaveDictionary.LoadJSON(Dictionary.sliderSettings, path);
SaveDictionary.LoadJSON(Dictionary.dropdownState, path);
if (!loading_from_configlist || _menuControls["AimMenu"] == null || !_menuInitialized["AimMenu"])
return;
try
{
ShowSuggestedModelIfSpecified();
ApplyConfigToSliders();
ApplyConfigToDropdowns();
}
catch (Exception e)
{
MessageBox.Show($"Error loading config, possibly outdated\n{e}");
}
}
private void ShowSuggestedModelIfSpecified()
{
if (Dictionary.sliderSettings.TryGetValue("Suggested Model", out var model))