Skip to content
This repository was archived by the owner on Jun 15, 2025. It is now read-only.

Commit 96a0aa6

Browse files
committed
Rewriting screen capture method ...
Refactor Direct3D11, improve error handling, and cleanup Refactored Direct3D11 initialization and context handling, including renaming methods and improving error handling and resource management. Removed GDI+ screen capture method and streamlined Direct3D11 screen capture methods. Improved error handling in keybind management and Razer support. Cleaned up unused and commented-out code. Enhanced logging for better error tracking and debug information.
1 parent 5228fca commit 96a0aa6

File tree

7 files changed

+185
-293
lines changed

7 files changed

+185
-293
lines changed

Aimmy2/AILogic/AIManager.cs

Lines changed: 80 additions & 235 deletions
Large diffs are not rendered by default.

Aimmy2/MainWindow.xaml.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Aimmy2.AILogic;
21
using Aimmy2.Class;
32
using Aimmy2.MouseMovementLibraries.GHubSupport;
43
using Aimmy2.Other;
@@ -262,6 +261,18 @@ private void LoadDropdownStates()
262261
"Razer Synapse (Require Razer Peripheral)" => 3,
263262
_ => 0 // Default case if none of the above matches
264263
};
264+
//if (Dictionary.dropdownState.TryGetValue("Monitor Selection", out var monitorSelection) && monitorSelection != null)
265+
//{
266+
// var monitorIndex = Array.FindIndex(System.Windows.Forms.Screen.AllScreens,
267+
// screen => monitorSelection.Contains($"{screen.Bounds.Width}x{screen.Bounds.Height}"));
268+
269+
// uiManager.D_MonitorSelection!.DropdownBox.SelectedIndex = monitorIndex >= 0 ? monitorIndex : 0;
270+
//}
271+
//else
272+
//{
273+
// uiManager.D_MonitorSelection!.DropdownBox.SelectedIndex = 0;
274+
//}
275+
265276
}
266277

267278
private AToggle AddToggle(StackPanel panel, string title)
@@ -598,9 +609,9 @@ private void LoadAimMenu()
598609
{
599610
await Task.Delay(100);
600611
await System.Windows.Application.Current.Dispatcher.BeginInvoke(() =>
601-
FOVWindow.FOVStrictEnclosure.Margin = new Thickness(
602-
Convert.ToInt16((WinAPICaller.ScreenWidth / 2) / WinAPICaller.scalingFactorX) - 320,
603-
Convert.ToInt16((WinAPICaller.ScreenHeight / 2) / WinAPICaller.scalingFactorY) - 320,
612+
FOVWindow.FOVStrictEnclosure.Margin = new Thickness(
613+
Convert.ToInt16((WinAPICaller.ScreenWidth / 2) / WinAPICaller.scalingFactorX) - 320,
614+
Convert.ToInt16((WinAPICaller.ScreenHeight / 2) / WinAPICaller.scalingFactorY) - 320,
604615
0, 0));
605616
};
606617

@@ -798,7 +809,7 @@ private void LoadSettingsMenu()
798809
};
799810

800811
//uiManager.D_MonitorSelection = AddDropdown(SettingsConfig, "Monitor Selection");
801-
812+
802813
//var monitors = System.Windows.Forms.Screen.AllScreens;
803814
//try
804815
//{
@@ -809,12 +820,12 @@ private void LoadSettingsMenu()
809820
// AddDropdownItem(uiManager.D_MonitorSelection, monitorName);
810821
// }
811822
//}
812-
//catch(Exception e)
823+
//catch (Exception e)
813824
//{
814825
// FileManager.LogError("Error grabbing monitor list: " + e);
815826
//}
816827

817-
//if(uiManager.D_MonitorSelection.DropdownBox.Items.Count > 0)
828+
//if (uiManager.D_MonitorSelection.DropdownBox.Items.Count > 0)
818829
//{
819830
// uiManager.D_MonitorSelection.DropdownBox.SelectedIndex = 0;
820831
//}

Aimmy2/MouseMovementLibraries/RazerSupport/RZMouse.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ public static async Task<bool> Load()
159159
{
160160
return init();
161161
}
162+
catch (DllNotFoundException dllEx)
163+
{
164+
MessageBox.Show($"DLL loading error: {dllEx}\nEnsure {rzctlpath} is present and correctly loaded.", "Aimmy");
165+
return false;
166+
}
162167
catch (Exception ex)
163168
{
164169
MessageBox.Show($"Unfortunately, Razer Synapse mode cannot be ran sufficiently.\n{ex}", "Aimmy");

Aimmy2/Other/FileManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Windows;
88
using System.Windows.Controls;
99
using Visuality;
10-
using static Aimmy2.Other.GithubManager;
1110

1211
namespace Other
1312
{
@@ -208,7 +207,7 @@ public static void LogError(string message)
208207
{
209208
if (Dictionary.toggleState["Debug Mode"])
210209
{
211-
// Debug.WriteLine(message);
210+
//Debug.WriteLine(message);
212211
string logFilePath = "debug.txt";
213212
using StreamWriter writer = new StreamWriter(logFilePath, true);
214213
writer.WriteLine($"[{DateTime.Now}]: {message}");

Aimmy2/Other/KeybindNameManager.cs

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
using System.Windows.Input;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Windows.Input;
24

35
namespace Other
46
{
57
internal class KeybindNameManager
68
{
7-
public static Dictionary<string, string> KeybindNames = new()
9+
public static readonly Dictionary<string, string> KeybindNames = new()
810
{
9-
{ "D1", "1"},
10-
{ "D2", "2"},
11-
{ "D3", "3"},
12-
{ "D4", "4"},
13-
{ "D5", "5"},
14-
{ "D6", "6"},
15-
{ "D7", "7"},
16-
{ "D8", "8"},
17-
{ "D9", "9"},
18-
{ "D0", "0"},
19-
20-
{ "OemMinus", "-"},
21-
{ "OemPlus", "+"},
22-
{ "Back", "Backspace"},
23-
{ "Oem5", "Backslash (\\)"},
24-
{ "LMenu", "Left Alt"},
25-
{ "RMenu", "Right Alt"},
11+
{ "D1", "1" },
12+
{ "D2", "2" },
13+
{ "D3", "3" },
14+
{ "D4", "4" },
15+
{ "D5", "5" },
16+
{ "D6", "6" },
17+
{ "D7", "7" },
18+
{ "D8", "8" },
19+
{ "D9", "9" },
20+
{ "D0", "0" },
21+
{ "OemMinus", "-" },
22+
{ "OemPlus", "+" },
23+
{ "Back", "Backspace" },
24+
{ "Oem5", "Backslash (\\)" },
25+
{ "LMenu", "Left Alt" },
26+
{ "RMenu", "Right Alt" },
2627
{ "RShiftKey", "Right Shift" },
2728
{ "LShiftKey", "Left Shift" },
28-
29-
{ "Oem4", "Left Bracket"},
30-
{ "OemOpenBrackets", "Left Bracket"},
31-
{ "Oem6", "Right Bracket"},
32-
{ "Oem1", ";"},
29+
{ "Oem4", "Left Bracket" },
30+
{ "OemOpenBrackets", "Left Bracket" },
31+
{ "Oem6", "Right Bracket" },
32+
{ "Oem1", ";" },
3333
{ "Oem3", "`" },
34-
{ "OemQuotes", "'"},
35-
{ "OemQuestion", "/"},
36-
{ "OemPeriod", "."},
37-
{ "OemComma", ","},
34+
{ "OemQuotes", "'" },
35+
{ "OemQuestion", "/" },
36+
{ "OemPeriod", "." },
37+
{ "OemComma", "," },
3838
{ "Return", "Enter" },
3939
};
4040

@@ -43,8 +43,18 @@ public static string ConvertToRegularKey(string keyName)
4343
try
4444
{
4545
KeyConverter kc = new();
46-
var key = (Key)kc.ConvertFromString(keyName)!;
47-
return KeybindNames.TryGetValue(key.ToString(), out var displayName) ? displayName : key.ToString();
46+
// Convert the keyName to Key enum
47+
if (Enum.TryParse(keyName, true, out Key key))
48+
{
49+
// Get the display name from the dictionary
50+
return KeybindNames.TryGetValue(key.ToString(), out var displayName) ? displayName : key.ToString();
51+
}
52+
else
53+
{
54+
// Key name is invalid
55+
FileManager.LogError($"Invalid key name: {keyName}");
56+
return keyName;
57+
}
4858
}
4959
catch (Exception ex)
5060
{

Aimmy2/Visuality/DetectedPlayerWindow.xaml.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,27 @@ private void UpdateDPColor(Color NewColor)
4141
DetectedPlayerConfidence.Foreground = new SolidColorBrush(NewColor);
4242
DetectedTracers.Stroke = new SolidColorBrush(NewColor);
4343
}
44-
//public void MoveToMonitor(Screen selectedMonitor)
45-
//{
46-
// this.Left = selectedMonitor.Bounds.Left;
47-
// this.Top = selectedMonitor.Bounds.Top;
48-
// this.Width = selectedMonitor.Bounds.Width;
49-
// this.Height = selectedMonitor.Bounds.Height;
44+
public void MoveToMonitor(Screen selectedMonitor)
45+
{
46+
// Set position and size before maximizing
47+
this.Left = selectedMonitor.Bounds.Left;
48+
this.Top = selectedMonitor.Bounds.Top;
49+
this.Width = selectedMonitor.Bounds.Width;
50+
this.Height = selectedMonitor.Bounds.Height;
51+
52+
// Ensure the window is visible
53+
if (this.WindowState == WindowState.Minimized)
54+
{
55+
this.WindowState = WindowState.Normal;
56+
}
5057

51-
// this.WindowState = WindowState.Maximized;
52-
// this.Topmost = true;
53-
//}
58+
// Maximize the window after setting the position and size
59+
this.WindowState = WindowState.Maximized;
60+
this.Topmost = true;
61+
62+
// Bring the window to the front
63+
this.Activate();
64+
}
5465
private void UpdateDPFontSize(int newint) => DetectedPlayerConfidence.FontSize = newint;
5566

5667
private void ChangeCornerRadius(int newint) => DetectedPlayerFocus.CornerRadius = new CornerRadius(newint);

Aimmy2/Visuality/FOV.xaml.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,27 @@ public FOV()
3333
PropertyChanger.ReceiveColor = UpdateFOVColor;
3434
PropertyChanger.ReceiveFOVSize = UpdateFOVSize;
3535
}
36-
//public void MoveToMonitor(Screen selectedMonitor)
37-
//{
38-
// this.Left = selectedMonitor.Bounds.Left;
39-
// this.Top = selectedMonitor.Bounds.Top;
40-
// this.Width = selectedMonitor.Bounds.Width;
41-
// this.Height = selectedMonitor.Bounds.Height;
42-
43-
// this.WindowState = WindowState.Maximized;
44-
// this.Topmost = true;
45-
//}
36+
public void MoveToMonitor(Screen selectedMonitor)
37+
{
38+
// Set position and size before maximizing
39+
this.Left = selectedMonitor.Bounds.Left;
40+
this.Top = selectedMonitor.Bounds.Top;
41+
this.Width = selectedMonitor.Bounds.Width;
42+
this.Height = selectedMonitor.Bounds.Height;
43+
44+
// Ensure the window is visible
45+
if (this.WindowState == WindowState.Minimized)
46+
{
47+
this.WindowState = WindowState.Normal;
48+
}
49+
50+
// Maximize the window after setting the position and size
51+
this.WindowState = WindowState.Maximized;
52+
this.Topmost = true;
53+
54+
// Bring the window to the front
55+
this.Activate();
56+
}
4657
private void UpdateFOVColor(Color NewColor) => Circle.Stroke = new SolidColorBrush(NewColor);
4758

4859
private void UpdateFOVSize(double newdouble)

0 commit comments

Comments
 (0)