diff --git a/CS2-AutoAccept/CS2-AutoAccept.csproj b/CS2-AutoAccept/CS2-AutoAccept.csproj
index c391dca..de52a63 100644
--- a/CS2-AutoAccept/CS2-AutoAccept.csproj
+++ b/CS2-AutoAccept/CS2-AutoAccept.csproj
@@ -3,6 +3,7 @@
WinExe
net6.0-windows10.0.17763.0
+ 10.0.17763.46
CS2_AutoAccept
enable
true
@@ -11,15 +12,15 @@
True
A program to automatically find and press "ACCEPT" for you, when entering a competitive match in CS2.
©️ tsgsOFFICIAL - 2024
- 5.1.4.5
+ 5.1.5.0
CS2-AutoAccept
-
-
-
-
+
+
+
+
@@ -159,6 +160,7 @@
+
@@ -225,7 +227,7 @@
-
+
@@ -555,6 +557,7 @@
+
@@ -582,4 +585,9 @@
+
+
+ PreserveNewest
+
+
diff --git a/CS2-AutoAccept/MainWindow.xaml b/CS2-AutoAccept/MainWindow.xaml
index 026e59b..876c6cc 100644
--- a/CS2-AutoAccept/MainWindow.xaml
+++ b/CS2-AutoAccept/MainWindow.xaml
@@ -1,6 +1,7 @@
-
+
@@ -165,17 +166,27 @@
-
-
-
\ No newline at end of file
diff --git a/CS2-AutoAccept/MainWindow.xaml.cs b/CS2-AutoAccept/MainWindow.xaml.cs
index 75fc4f5..ce01074 100644
--- a/CS2-AutoAccept/MainWindow.xaml.cs
+++ b/CS2-AutoAccept/MainWindow.xaml.cs
@@ -16,7 +16,6 @@
using System.Windows.Media;
using CS2_AutoAccept.Models;
using System.Threading.Tasks;
-using System.Windows.Interop;
using System.Net.Http.Headers;
using System.Collections.Generic;
using System.Runtime.InteropServices;
@@ -39,25 +38,13 @@ public partial class MainWindow : Window
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
#endregion
- #region DLL Imports For Keybinds
- private const int WM_HOTKEY = 0x0312;
-
- [DllImport("user32.dll")]
- private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
-
- [DllImport("user32.dll")]
- private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
-
- private HwndSource _source;
- private int _hotkeyPlusId;
- private int _hotkeyMinusId;
- #endregion
#endregion
private Updater? updater;
private Screen? _activeScreen;
private Thread? _scannerThread;
private CancellationTokenSource? cts;
+ private bool _scannerIsActive = false;
private bool _run_Continuously = false;
private bool _updateAvailable = false;
private bool _updateFailed = false;
@@ -75,11 +62,30 @@ public partial class MainWindow : Window
private string _basePath;
private string _updatePath;
private readonly bool debugMode = false;
+ public ICommand ToggleWindowCommand { get; }
+ public ICommand CloseCommand { get; }
+ private bool _isTrayIconVisible;
+
+ public bool IsTrayIconVisible
+ {
+ get => _isTrayIconVisible;
+ set
+ {
+ _isTrayIconVisible = value;
+ UpdateTrayIconVisibility();
+ }
+ }
public MainWindow()
{
InitializeComponent();
- Loaded += MainWindow_Loaded;
- Closed += MainWindow_Closed!;
+ IsTrayIconVisible = true;
+ DataContext = this;
+
+ ToggleWindowCommand = new RelayCommand(o => ToggleWindowState());
+ CloseCommand = new RelayCommand(o => CloseApplication());
+
+ // Event handler for double-click on TaskbarIcon
+ MyNotifyIcon.TrayMouseDoubleClick += OnTrayIconDoubleClick;
// Access command line arguments
string[] args = Environment.GetCommandLineArgs();
@@ -214,7 +220,59 @@ public MainWindow()
#endregion
}
+ private void ToggleWindowState()
+ {
+ if (WindowState == WindowState.Minimized)
+ {
+ Show();
+ WindowState = WindowState.Normal;
+ }
+ else
+ {
+ WindowState = WindowState.Minimized;
+ Hide();
+ }
+ }
+
+ private void CloseApplication()
+ {
+ Close();
+ }
+ private void UpdateTrayIconVisibility()
+ {
+ // Show or hide the tray icon based on IsTrayIconVisible
+ MyNotifyIcon.Visibility = IsTrayIconVisible ? Visibility.Visible : Visibility.Collapsed;
+ }
#region EventHandlers
+ protected override void OnStateChanged(EventArgs e)
+ {
+ base.OnStateChanged(e);
+
+ // Find context menu items and update texts based on WindowState
+ var menu = (System.Windows.Controls.ContextMenu)MyNotifyIcon.ContextMenu;
+ var toggleMenuItem = (System.Windows.Controls.MenuItem)menu.Items[0];
+
+ if (WindowState == WindowState.Minimized)
+ {
+ string toolTipText = _scannerIsActive == true ? "AutoAccept is running in the background" : "CS2 AutoAccept is minimized";
+
+ Hide();
+ ShowNotification("CS2 AutoAccept", toolTipText);
+ toggleMenuItem.Header = "Restore";
+ MyNotifyIcon.ToolTipText = toolTipText;
+ }
+ else
+ {
+ toggleMenuItem.Header = "Minimize";
+ MyNotifyIcon.ToolTipText = "CS2 AutoAccept by tsgsOFFICIAL";
+ }
+ }
+ private void OnTrayIconDoubleClick(object sender, RoutedEventArgs e)
+ {
+ // Show the window and restore it to normal state
+ Show();
+ WindowState = WindowState.Normal;
+ }
///
/// Event handler for download progress
///
@@ -282,7 +340,7 @@ public void Button_Click_Maximize(object sender, RoutedEventArgs e)
///
private void Button_Click_Close(object sender, RoutedEventArgs e)
{
- this.Close();
+ Close();
}
///
/// Open Github to download the newest version
@@ -352,6 +410,7 @@ private void Program_state_Checked(object sender, RoutedEventArgs e)
_scannerThread = new Thread(new ParameterizedThreadStart(Scanner)) { IsBackground = true };
cts = new CancellationTokenSource();
_scannerThread.Start(cts!.Token);
+ _scannerIsActive = true;
// Change to a brighter color
Program_state.Foreground = new SolidColorBrush(Colors.LawnGreen);
Program_state.Content = "AutoAccept (ON)";
@@ -366,6 +425,7 @@ private void Program_state_Unchecked(object sender, RoutedEventArgs e)
// PrintToLog("{Program_state_Unchecked}");
cts!.Cancel();
Program_state_continuously.IsChecked = false;
+ _scannerIsActive = false;
// Change to a darker color
Program_state.Foreground = new SolidColorBrush(Colors.Red);
@@ -478,98 +538,6 @@ private void WindowSizeChangedEventHandler(object sender, SizeChangedEventArgs e
}
#endregion
///
- /// Listens for keybinds
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
- {
- // Keybinds available are:
- // NumPad + = Start AutoAccept
- // Numpad ++ = Start AutoAccept 24/7
- // NumPad - = Stop AutoAccept
- if (msg == WM_HOTKEY)
- {
- int id = wParam.ToInt32();
-
- if (id == _hotkeyPlusId)
- {
- Dispatcher.Invoke(() =>
- {
- if (Program_state.IsEnabled)
- {
- // If the program is already running
- if (Program_state.IsChecked ?? false)
- {
- Program_state_continuously.IsChecked = true;
- ShowNotification("AutoAccept 24/7 activated!", "AutoAccept 24/7 has been activated!");
- }
- else
- {
- Program_state.IsChecked = true;
- ShowNotification("AutoAccept activated!", "AutoAccept has been activated!");
- }
- }
- });
- }
- else if (id == _hotkeyMinusId)
- {
- Dispatcher.Invoke(() =>
- {
- if (Program_state.IsEnabled)
- {
- if (Program_state.IsChecked ?? false)
- {
- Program_state.IsChecked = false;
- ShowNotification("AutoAccept canceled!", "AutoAccept has been canceled!");
- }
- }
- });
- }
- }
-
- return IntPtr.Zero;
- }
- private void MainWindow_Loaded(object sender, RoutedEventArgs e)
- {
- IntPtr hWnd = new WindowInteropHelper(this).Handle;
- _source = HwndSource.FromHwnd(hWnd);
- _source.AddHook(WndProc);
-
- // Register '+' hotkey
- const uint MOD_NONE = 0x0000;
- const uint VK_PLUS = 0xBB; // OEM '+'
- const uint VK_NUMPAD_PLUS = 0x6B; // Numpad '+'
-
- _hotkeyPlusId = GetHashCode();
- RegisterHotKey(hWnd, _hotkeyPlusId, MOD_NONE, VK_PLUS);
- RegisterHotKey(hWnd, _hotkeyPlusId, MOD_NONE, VK_NUMPAD_PLUS);
-
- // Register '-' hotkey
- const uint VK_MINUS = 0xBD; // OEM '-'
- const uint VK_NUMPAD_MINUS = 0x6D; // Numpad '-'
-
- _hotkeyMinusId = GetHashCode() + 1; // Use a different id for '-' hotkey
- RegisterHotKey(hWnd, _hotkeyMinusId, MOD_NONE, VK_MINUS);
- RegisterHotKey(hWnd, _hotkeyMinusId, MOD_NONE, VK_NUMPAD_MINUS);
- }
-
- private void MainWindow_Closed(object sender, EventArgs e)
- {
- if (_source != null)
- {
- _source.RemoveHook(WndProc);
- _source = null!;
- }
-
- UnregisterHotKey(new WindowInteropHelper(this).Handle, _hotkeyPlusId);
- UnregisterHotKey(new WindowInteropHelper(this).Handle, _hotkeyMinusId);
- }
- ///
/// Restore the window size, if it was previously opened & changed
///
private void RestoreSizeIfSaved()
@@ -1306,4 +1274,23 @@ private void ShowNotification(string title, string message)
});
}
}
-}
+
+ public class RelayCommand : ICommand
+ {
+ private readonly Action