Skip to content

Commit

Permalink
Rewriting screen capture method ...
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TaylorIsBlue committed Aug 16, 2024
1 parent 5228fca commit 96a0aa6
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 293 deletions.
315 changes: 80 additions & 235 deletions Aimmy2/AILogic/AIManager.cs

Large diffs are not rendered by default.

25 changes: 18 additions & 7 deletions Aimmy2/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Aimmy2.AILogic;
using Aimmy2.Class;
using Aimmy2.MouseMovementLibraries.GHubSupport;
using Aimmy2.Other;
Expand Down Expand Up @@ -262,6 +261,18 @@ private void LoadDropdownStates()
"Razer Synapse (Require Razer Peripheral)" => 3,
_ => 0 // Default case if none of the above matches
};
//if (Dictionary.dropdownState.TryGetValue("Monitor Selection", out var monitorSelection) && monitorSelection != null)
//{
// var monitorIndex = Array.FindIndex(System.Windows.Forms.Screen.AllScreens,
// screen => monitorSelection.Contains($"{screen.Bounds.Width}x{screen.Bounds.Height}"));

// uiManager.D_MonitorSelection!.DropdownBox.SelectedIndex = monitorIndex >= 0 ? monitorIndex : 0;
//}
//else
//{
// uiManager.D_MonitorSelection!.DropdownBox.SelectedIndex = 0;
//}

}

private AToggle AddToggle(StackPanel panel, string title)
Expand Down Expand Up @@ -598,9 +609,9 @@ private void LoadAimMenu()
{
await Task.Delay(100);
await System.Windows.Application.Current.Dispatcher.BeginInvoke(() =>
FOVWindow.FOVStrictEnclosure.Margin = new Thickness(
Convert.ToInt16((WinAPICaller.ScreenWidth / 2) / WinAPICaller.scalingFactorX) - 320,
Convert.ToInt16((WinAPICaller.ScreenHeight / 2) / WinAPICaller.scalingFactorY) - 320,
FOVWindow.FOVStrictEnclosure.Margin = new Thickness(
Convert.ToInt16((WinAPICaller.ScreenWidth / 2) / WinAPICaller.scalingFactorX) - 320,
Convert.ToInt16((WinAPICaller.ScreenHeight / 2) / WinAPICaller.scalingFactorY) - 320,
0, 0));
};

Expand Down Expand Up @@ -798,7 +809,7 @@ private void LoadSettingsMenu()
};

//uiManager.D_MonitorSelection = AddDropdown(SettingsConfig, "Monitor Selection");

//var monitors = System.Windows.Forms.Screen.AllScreens;
//try
//{
Expand All @@ -809,12 +820,12 @@ private void LoadSettingsMenu()
// AddDropdownItem(uiManager.D_MonitorSelection, monitorName);
// }
//}
//catch(Exception e)
//catch (Exception e)
//{
// FileManager.LogError("Error grabbing monitor list: " + e);
//}

//if(uiManager.D_MonitorSelection.DropdownBox.Items.Count > 0)
//if (uiManager.D_MonitorSelection.DropdownBox.Items.Count > 0)
//{
// uiManager.D_MonitorSelection.DropdownBox.SelectedIndex = 0;
//}
Expand Down
5 changes: 5 additions & 0 deletions Aimmy2/MouseMovementLibraries/RazerSupport/RZMouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public static async Task<bool> Load()
{
return init();
}
catch (DllNotFoundException dllEx)
{
MessageBox.Show($"DLL loading error: {dllEx}\nEnsure {rzctlpath} is present and correctly loaded.", "Aimmy");
return false;
}
catch (Exception ex)
{
MessageBox.Show($"Unfortunately, Razer Synapse mode cannot be ran sufficiently.\n{ex}", "Aimmy");
Expand Down
3 changes: 1 addition & 2 deletions Aimmy2/Other/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Windows;
using System.Windows.Controls;
using Visuality;
using static Aimmy2.Other.GithubManager;

namespace Other
{
Expand Down Expand Up @@ -208,7 +207,7 @@ public static void LogError(string message)
{
if (Dictionary.toggleState["Debug Mode"])
{
// Debug.WriteLine(message);
//Debug.WriteLine(message);
string logFilePath = "debug.txt";
using StreamWriter writer = new StreamWriter(logFilePath, true);
writer.WriteLine($"[{DateTime.Now}]: {message}");
Expand Down
70 changes: 40 additions & 30 deletions Aimmy2/Other/KeybindNameManager.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
using System.Windows.Input;
using System;
using System.Collections.Generic;
using System.Windows.Input;

namespace Other
{
internal class KeybindNameManager
{
public static Dictionary<string, string> KeybindNames = new()
public static readonly Dictionary<string, string> KeybindNames = new()
{
{ "D1", "1"},
{ "D2", "2"},
{ "D3", "3"},
{ "D4", "4"},
{ "D5", "5"},
{ "D6", "6"},
{ "D7", "7"},
{ "D8", "8"},
{ "D9", "9"},
{ "D0", "0"},

{ "OemMinus", "-"},
{ "OemPlus", "+"},
{ "Back", "Backspace"},
{ "Oem5", "Backslash (\\)"},
{ "LMenu", "Left Alt"},
{ "RMenu", "Right Alt"},
{ "D1", "1" },
{ "D2", "2" },
{ "D3", "3" },
{ "D4", "4" },
{ "D5", "5" },
{ "D6", "6" },
{ "D7", "7" },
{ "D8", "8" },
{ "D9", "9" },
{ "D0", "0" },
{ "OemMinus", "-" },
{ "OemPlus", "+" },
{ "Back", "Backspace" },
{ "Oem5", "Backslash (\\)" },
{ "LMenu", "Left Alt" },
{ "RMenu", "Right Alt" },
{ "RShiftKey", "Right Shift" },
{ "LShiftKey", "Left Shift" },

{ "Oem4", "Left Bracket"},
{ "OemOpenBrackets", "Left Bracket"},
{ "Oem6", "Right Bracket"},
{ "Oem1", ";"},
{ "Oem4", "Left Bracket" },
{ "OemOpenBrackets", "Left Bracket" },
{ "Oem6", "Right Bracket" },
{ "Oem1", ";" },
{ "Oem3", "`" },
{ "OemQuotes", "'"},
{ "OemQuestion", "/"},
{ "OemPeriod", "."},
{ "OemComma", ","},
{ "OemQuotes", "'" },
{ "OemQuestion", "/" },
{ "OemPeriod", "." },
{ "OemComma", "," },
{ "Return", "Enter" },
};

Expand All @@ -43,8 +43,18 @@ public static string ConvertToRegularKey(string keyName)
try
{
KeyConverter kc = new();
var key = (Key)kc.ConvertFromString(keyName)!;
return KeybindNames.TryGetValue(key.ToString(), out var displayName) ? displayName : key.ToString();
// Convert the keyName to Key enum
if (Enum.TryParse(keyName, true, out Key key))
{
// Get the display name from the dictionary
return KeybindNames.TryGetValue(key.ToString(), out var displayName) ? displayName : key.ToString();
}
else
{
// Key name is invalid
FileManager.LogError($"Invalid key name: {keyName}");
return keyName;
}
}
catch (Exception ex)
{
Expand Down
29 changes: 20 additions & 9 deletions Aimmy2/Visuality/DetectedPlayerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,27 @@ private void UpdateDPColor(Color NewColor)
DetectedPlayerConfidence.Foreground = new SolidColorBrush(NewColor);
DetectedTracers.Stroke = new SolidColorBrush(NewColor);
}
//public void MoveToMonitor(Screen selectedMonitor)
//{
// this.Left = selectedMonitor.Bounds.Left;
// this.Top = selectedMonitor.Bounds.Top;
// this.Width = selectedMonitor.Bounds.Width;
// this.Height = selectedMonitor.Bounds.Height;
public void MoveToMonitor(Screen selectedMonitor)
{
// Set position and size before maximizing
this.Left = selectedMonitor.Bounds.Left;
this.Top = selectedMonitor.Bounds.Top;
this.Width = selectedMonitor.Bounds.Width;
this.Height = selectedMonitor.Bounds.Height;

// Ensure the window is visible
if (this.WindowState == WindowState.Minimized)
{
this.WindowState = WindowState.Normal;
}

// this.WindowState = WindowState.Maximized;
// this.Topmost = true;
//}
// Maximize the window after setting the position and size
this.WindowState = WindowState.Maximized;
this.Topmost = true;

// Bring the window to the front
this.Activate();
}
private void UpdateDPFontSize(int newint) => DetectedPlayerConfidence.FontSize = newint;

private void ChangeCornerRadius(int newint) => DetectedPlayerFocus.CornerRadius = new CornerRadius(newint);
Expand Down
31 changes: 21 additions & 10 deletions Aimmy2/Visuality/FOV.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,27 @@ public FOV()
PropertyChanger.ReceiveColor = UpdateFOVColor;
PropertyChanger.ReceiveFOVSize = UpdateFOVSize;
}
//public void MoveToMonitor(Screen selectedMonitor)
//{
// this.Left = selectedMonitor.Bounds.Left;
// this.Top = selectedMonitor.Bounds.Top;
// this.Width = selectedMonitor.Bounds.Width;
// this.Height = selectedMonitor.Bounds.Height;

// this.WindowState = WindowState.Maximized;
// this.Topmost = true;
//}
public void MoveToMonitor(Screen selectedMonitor)
{
// Set position and size before maximizing
this.Left = selectedMonitor.Bounds.Left;
this.Top = selectedMonitor.Bounds.Top;
this.Width = selectedMonitor.Bounds.Width;
this.Height = selectedMonitor.Bounds.Height;

// Ensure the window is visible
if (this.WindowState == WindowState.Minimized)
{
this.WindowState = WindowState.Normal;
}

// Maximize the window after setting the position and size
this.WindowState = WindowState.Maximized;
this.Topmost = true;

// Bring the window to the front
this.Activate();
}
private void UpdateFOVColor(Color NewColor) => Circle.Stroke = new SolidColorBrush(NewColor);

private void UpdateFOVSize(double newdouble)
Expand Down

0 comments on commit 96a0aa6

Please sign in to comment.