From 93ecc9901cf18f48601089c3c923667fe488cbbc Mon Sep 17 00:00:00 2001 From: MurkyYT Date: Fri, 12 Apr 2024 16:01:59 +0300 Subject: [PATCH 1/6] feat(auto-buy): added global toggle for auto buy --- src/CSAuto/App.config | 3 + src/CSAuto/CSAuto.csproj | 2 +- src/CSAuto/GUIWindow.xaml | 11 ++-- src/CSAuto/MainApp.xaml.cs | 16 ++++- src/CSAuto/Properties/Settings.Designer.cs | 12 ++++ src/CSAuto/Properties/Settings.settings | 3 + src/CSAuto/Utils/CSGO/ConDump.cs | 77 ++++++++++------------ 7 files changed, 72 insertions(+), 52 deletions(-) diff --git a/src/CSAuto/App.config b/src/CSAuto/App.config index d85fa6a..709f256 100644 --- a/src/CSAuto/App.config +++ b/src/CSAuto/App.config @@ -115,6 +115,9 @@ True + + True + diff --git a/src/CSAuto/CSAuto.csproj b/src/CSAuto/CSAuto.csproj index 1367a43..1423312 100644 --- a/src/CSAuto/CSAuto.csproj +++ b/src/CSAuto/CSAuto.csproj @@ -237,7 +237,7 @@ 2.4.10 - 1.25.0 + 1.27.0 4.5.1 diff --git a/src/CSAuto/GUIWindow.xaml b/src/CSAuto/GUIWindow.xaml index 2bb0108..17f825e 100644 --- a/src/CSAuto/GUIWindow.xaml +++ b/src/CSAuto/GUIWindow.xaml @@ -299,10 +299,13 @@ - - - - + + + + + + + diff --git a/src/CSAuto/MainApp.xaml.cs b/src/CSAuto/MainApp.xaml.cs index 3bf44b3..72b3d1b 100644 --- a/src/CSAuto/MainApp.xaml.cs +++ b/src/CSAuto/MainApp.xaml.cs @@ -39,9 +39,9 @@ namespace CSAuto public partial class MainApp : Window { #region Constants - public const string VER = "2.1.0"; + public const string VER = "2.1.1"; public const string FULL_VER = VER + (DEBUG_REVISION == "" ? "" : " REV "+ DEBUG_REVISION); - const string DEBUG_REVISION = ""; + const string DEBUG_REVISION = "1"; const string GAME_PROCCES_NAME = "cs2"; const string GAME_WINDOW_NAME = "Counter-Strike 2"; const string GAME_CLASS_NAME = "SDL_app"; @@ -186,6 +186,12 @@ public MainApp() Application.Current.Shutdown(); } } + + //private void ConDump_OnChange(object sender, EventArgs e) + //{ + // Log.WriteLine(sender); + //} + static Color[] LoadButtonColors() { try @@ -380,7 +386,7 @@ private void GameStateListener_OnReceive(object sender, EventArgs e) { if (Properties.Settings.Default.autoReload && lastActivity != Activity.Menu && csActive) TryToAutoReload(); - if (lastActivity == Activity.Playing && csActive) + if (lastActivity == Activity.Playing && csActive && Properties.Settings.Default.autoBuyEnabled) AutoBuy(); if (Properties.Settings.Default.autoPausePlaySpotify) AutoPauseResumeSpotify(); @@ -903,6 +909,8 @@ private void TimerCallback(object sender, EventArgs e) steamAPIServer = null; } } + //ConDump.StartListening(); + //ConDump.OnChange += ConDump_OnChange; hCursorOriginal = IntPtr.Zero; NativeMethods.OptimizeMemory(); } @@ -1024,6 +1032,8 @@ private void CsProcess_Exited(object sender, EventArgs e) } if (Properties.Settings.Default.autoCloseCSAuto) Dispatcher.Invoke(() => { Application.Current.Shutdown(); }); + //ConDump.StopListening(); + //ConDump.OnChange -= ConDump_OnChange; NativeMethods.OptimizeMemory(); } private void TryToAutoReload() diff --git a/src/CSAuto/Properties/Settings.Designer.cs b/src/CSAuto/Properties/Settings.Designer.cs index 1418059..e1540fe 100644 --- a/src/CSAuto/Properties/Settings.Designer.cs +++ b/src/CSAuto/Properties/Settings.Designer.cs @@ -464,5 +464,17 @@ public bool focusBackOnOriginalWindow { this["focusBackOnOriginalWindow"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool autoBuyEnabled { + get { + return ((bool)(this["autoBuyEnabled"])); + } + set { + this["autoBuyEnabled"] = value; + } + } } } diff --git a/src/CSAuto/Properties/Settings.settings b/src/CSAuto/Properties/Settings.settings index e1d71b3..69ace80 100644 --- a/src/CSAuto/Properties/Settings.settings +++ b/src/CSAuto/Properties/Settings.settings @@ -132,5 +132,8 @@ True + + True + \ No newline at end of file diff --git a/src/CSAuto/Utils/CSGO/ConDump.cs b/src/CSAuto/Utils/CSGO/ConDump.cs index 8d4b6e2..1c277cc 100644 --- a/src/CSAuto/Utils/CSGO/ConDump.cs +++ b/src/CSAuto/Utils/CSGO/ConDump.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using System.Threading; namespace Murky.Utils.CSGO @@ -9,66 +10,54 @@ namespace Murky.Utils.CSGO public static class ConDump { //public static event EventHandler SearchStarted; - //public static event EventHandler OnChange; - public static int Delay = 500; - private static IEnumerable oldFile = Enumerable.Empty(); + public static event EventHandler OnChange; + private static FileSystemWatcher fileWathcer = new FileSystemWatcher(); + private static int lastLineIndex = 0; private static readonly string path; - private static readonly Thread workThread; + private static readonly string fileName = "console.log"; static ConDump() { string csgoDir = Steam.GetGameDir("Counter-Strike Global Offensive"); if (csgoDir != null) - path = csgoDir + "\\game\\csgo\\"; - workThread = new Thread(CheckForChange); + path = csgoDir + "\\game\\csgo"; + fileWathcer.Path = path; + fileWathcer.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.LastAccess | NotifyFilters.Size; + fileWathcer.Filter = fileName; + fileWathcer.Changed += FileWathcer_Changed; } public static void StartListening() - { - if (workThread != null && workThread.ThreadState == ThreadState.Unstarted) - workThread.Start(); - if (workThread != null && workThread.ThreadState == ThreadState.Suspended) - workThread.Resume(); - } - public static void StopListening() - { - if (workThread != null && workThread.ThreadState == ThreadState.Running) - workThread.Suspend(); - } - private static void CheckForChange() - { - while (true) - { - IEnumerable newFile = ReadFile(path + "console.log"); - IEnumerable diff = newFile.Except(oldFile); - if (diff.Count() > 0) - OnChanged(diff); - oldFile = newFile.ToList(); - Thread.Sleep(Delay); - } + { + fileWathcer.EnableRaisingEvents = true; } - private static IEnumerable ReadFile(string path) + + private static void FileWathcer_Changed(object sender, FileSystemEventArgs e) { - using (FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + try { - string line = ""; - using (StreamReader reader = new StreamReader(stream)) + byte[] buffer; + using (FileStream file = File.Open(path + "\\" + fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { - while ((line = reader.ReadLine()) != null) - { - yield return line; - } + buffer = new byte[file.Length]; + file.Read(buffer, 0, buffer.Length); } - } - } - private static void OnChanged(IEnumerable diff) - { - try - { - foreach (string str in diff) + string result = UTF8Encoding.UTF8.GetString(buffer); + char[] fileArr = result.ToCharArray(); + int index = fileArr.Length - 1; + string resultChanged = ""; + while (index >= lastLineIndex) { - Log.WriteLine(str); + resultChanged = fileArr[index] + resultChanged; + index--; } + lastLineIndex = fileArr.Length; + OnChange?.Invoke(resultChanged, null); } catch { } } + + public static void StopListening() + { + fileWathcer.EnableRaisingEvents = false; + } } } From e0d172cc5028ba7d09c783c064d12b4e89cdd4fa Mon Sep 17 00:00:00 2001 From: MurkyYT Date: Fri, 12 Apr 2024 19:35:37 +0300 Subject: [PATCH 2/6] fix(gui): fix binding for auto buy enabled --- src/CSAuto/GUIWindow.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CSAuto/GUIWindow.xaml b/src/CSAuto/GUIWindow.xaml index 17f825e..8520b89 100644 --- a/src/CSAuto/GUIWindow.xaml +++ b/src/CSAuto/GUIWindow.xaml @@ -299,7 +299,7 @@ - + From b68cb055881e9bab949d316587a004c22bd1df2d Mon Sep 17 00:00:00 2001 From: MurkyYT Date: Fri, 26 Apr 2024 12:25:47 +0300 Subject: [PATCH 3/6] feat(debug): added debug settings --- src/CSAuto/App.config | 6 ++ src/CSAuto/CSAuto.csproj | 16 ++++ src/CSAuto/DebugSettings.xaml | 49 +++++++++++++ src/CSAuto/DebugSettings.xaml.cs | 73 +++++++++++++++++++ src/CSAuto/GUIWindow.xaml | 3 +- src/CSAuto/GUIWindow.xaml.cs | 9 ++- src/CSAuto/MainApp.xaml.cs | 58 ++++++++------- .../Properties/DebugSettings.Designer.cs | 38 ++++++++++ src/CSAuto/Properties/DebugSettings.settings | 9 +++ 9 files changed, 234 insertions(+), 27 deletions(-) create mode 100644 src/CSAuto/DebugSettings.xaml create mode 100644 src/CSAuto/DebugSettings.xaml.cs create mode 100644 src/CSAuto/Properties/DebugSettings.Designer.cs create mode 100644 src/CSAuto/Properties/DebugSettings.settings diff --git a/src/CSAuto/App.config b/src/CSAuto/App.config index 709f256..017e34c 100644 --- a/src/CSAuto/App.config +++ b/src/CSAuto/App.config @@ -2,6 +2,7 @@ +
@@ -12,6 +13,11 @@ + + + True + + False diff --git a/src/CSAuto/CSAuto.csproj b/src/CSAuto/CSAuto.csproj index 1423312..5891e9b 100644 --- a/src/CSAuto/CSAuto.csproj +++ b/src/CSAuto/CSAuto.csproj @@ -101,6 +101,9 @@ APIKeys.resx + + DebugSettings.xaml + @@ -116,6 +119,11 @@ True Strings.ru.resx + + True + True + DebugSettings.settings + @@ -137,6 +145,10 @@ + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -200,6 +212,10 @@ Strings.ru.Designer.cs + + SettingsSingleFileGenerator + DebugSettings.Designer.cs + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/src/CSAuto/DebugSettings.xaml b/src/CSAuto/DebugSettings.xaml new file mode 100644 index 0000000..a4eed6f --- /dev/null +++ b/src/CSAuto/DebugSettings.xaml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +