diff --git a/AutoTrackR2/App.xaml.cs b/AutoTrackR2/App.xaml.cs index 7441812..55a1e85 100644 --- a/AutoTrackR2/App.xaml.cs +++ b/AutoTrackR2/App.xaml.cs @@ -20,13 +20,6 @@ namespace AutoTrackR2 "crash.log" ); private StreamlinkHandler? _streamlinkHandler; - private KillStreakManager? _killStreakManager; - - private void HandleException(Exception ex) - { - MessageBox.Show($"Failed to start AutoTrackR2: {ex.Message}", "AutoTrackR2 Error", MessageBoxButton.OK, MessageBoxImage.Error); - Current.Shutdown(); - } protected override void OnStartup(StartupEventArgs e) { @@ -56,10 +49,6 @@ namespace AutoTrackR2 // Initialize StreamlinkHandler before creating the main window _streamlinkHandler = new StreamlinkHandler(); - // Initialize KillStreakManager - var soundsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sounds"); - _killStreakManager = new KillStreakManager(soundsPath); - // Create and show the main window var mainWindow = new MainWindow(); mainWindow.Show(); @@ -68,7 +57,8 @@ namespace AutoTrackR2 } catch (Exception ex) { - HandleException(ex); + MessageBox.Show($"Failed to start AutoTrackR2: {ex.Message}", "AutoTrackR2 Error", MessageBoxButton.OK, MessageBoxImage.Error); + Current.Shutdown(); } } @@ -120,10 +110,24 @@ namespace AutoTrackR2 protected override void OnExit(ExitEventArgs e) { - // Clean up resources - _killStreakManager?.Cleanup(); - _mutex?.Dispose(); - base.OnExit(e); + try + { + if (_mutex != null && _mutexOwned) + { + _mutex.ReleaseMutex(); + _mutex.Close(); + _mutex = null; + } + } + catch (Exception ex) + { + // Log the error but don't prevent shutdown + File.AppendAllText(CrashLogPath, $"[{DateTime.Now}] Error during shutdown: {ex.Message}\n"); + } + finally + { + base.OnExit(e); + } } } } diff --git a/AutoTrackR2/AutoTrackR2.csproj b/AutoTrackR2/AutoTrackR2.csproj index 6e88f61..b9db3ce 100644 --- a/AutoTrackR2/AutoTrackR2.csproj +++ b/AutoTrackR2/AutoTrackR2.csproj @@ -38,14 +38,4 @@ </Resource> </ItemGroup> - <ItemGroup> - <None Include="sounds\*.mp3"> - <CopyToOutputDirectory>Always</CopyToOutputDirectory> - </None> - </ItemGroup> - - <ItemGroup> - <PackageReference Include="NAudio" Version="2.2.1" /> - </ItemGroup> - </Project> diff --git a/AutoTrackR2/ConfigPage.xaml b/AutoTrackR2/ConfigPage.xaml index 55374eb..5fb0510 100644 --- a/AutoTrackR2/ConfigPage.xaml +++ b/AutoTrackR2/ConfigPage.xaml @@ -156,19 +156,6 @@ <RowDefinition Height="Auto"/> </Grid.RowDefinitions> - <!-- Kill Streak Test Button --> - <!-- - <Button Grid.Column="0" - Grid.Row="0" - Grid.ColumnSpan="2" - Content="Test Kill Streak Sounds" - Height="30" - FontFamily="{StaticResource Orbitron}" - Margin="0,0,0,10" - Style="{StaticResource ButtonStyle}" - Click="TestKillStreakButton_Click"/> - --> - <!-- Left Column Controls --> <!-- Visor Wipe Toggle --> diff --git a/AutoTrackR2/ConfigPage.xaml.cs b/AutoTrackR2/ConfigPage.xaml.cs index e7cd94b..e4c1772 100644 --- a/AutoTrackR2/ConfigPage.xaml.cs +++ b/AutoTrackR2/ConfigPage.xaml.cs @@ -12,7 +12,6 @@ using System.Windows.Media.Effects; using System.Windows.Threading; using Microsoft.Win32; using System.Threading.Tasks; -using AutoTrackR2.Constants; namespace AutoTrackR2; @@ -25,10 +24,6 @@ public partial class ConfigPage : UserControl Dictionary<string, Theme>? _themes = null; - private KillStreakManager? _testKillStreakManager; - private bool _isTestRunning = false; - private int _currentTestStep = 0; - public ConfigPage(MainWindow mainWindow) { InitializeComponent(); @@ -220,7 +215,7 @@ public partial class ConfigPage : UserControl dialog.CheckFileExists = false; dialog.CheckPathExists = true; dialog.FileName = "Folder Selection"; - + if (dialog.ShowDialog() == true) { string? selectedFolder = Path.GetDirectoryName(dialog.FileName); @@ -343,7 +338,7 @@ public partial class ConfigPage : UserControl ConfigManager.VideoRecord = (int)VideoRecordSlider.Value; ConfigManager.OfflineMode = (int)OfflineModeSlider.Value; ConfigManager.Theme = (int)ThemeSlider.Value; - + // Save the current config values ConfigManager.SaveConfig(); // Start the flashing effect @@ -419,7 +414,7 @@ public partial class ConfigPage : UserControl client.DefaultRequestHeaders.UserAgent.ParseAdd("AutoTrackR2"); // Create JSON body with version - var jsonBody = new { version = AppConstants.Version }; + var jsonBody = new { version = "2.10" }; var content = new StringContent(JsonSerializer.Serialize(jsonBody), Encoding.UTF8, "application/json"); // Send POST @@ -507,7 +502,7 @@ public partial class ConfigPage : UserControl client.DefaultRequestHeaders.UserAgent.ParseAdd("AutoTrackR2"); // Create JSON body with version - var jsonBody = new { version = AppConstants.Version }; + var jsonBody = new { version = "2.10" }; var content = new StringContent(JsonSerializer.Serialize(jsonBody), Encoding.UTF8, "application/json"); // Send POST to test endpoint @@ -567,26 +562,6 @@ public partial class ConfigPage : UserControl MessageBox.Show("Directory does not exist.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } - - private async void TestKillStreakButton_Click(object sender, RoutedEventArgs e) - { - // Create a single KillStreakManager instance if it doesn't exist - if (_testKillStreakManager == null) - { - var soundsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sounds"); - _testKillStreakManager = new KillStreakManager(soundsPath); - } - - // Simulate 5 quick kills - for (int i = 0; i < 5; i++) - { - _testKillStreakManager.OnKill(); - } - - // Reset the streak after all sounds have played - await Task.Delay(1000); - _testKillStreakManager.OnDeath(); - } } public class Theme diff --git a/AutoTrackR2/Constants.cs b/AutoTrackR2/Constants.cs deleted file mode 100644 index 14a8c8a..0000000 --- a/AutoTrackR2/Constants.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace AutoTrackR2.Constants; - -public static class AppConstants -{ - public const string Version = "2.11"; -} \ No newline at end of file diff --git a/AutoTrackR2/HomePage.xaml.cs b/AutoTrackR2/HomePage.xaml.cs index b202b55..80bbd06 100644 --- a/AutoTrackR2/HomePage.xaml.cs +++ b/AutoTrackR2/HomePage.xaml.cs @@ -11,7 +11,7 @@ using System.Windows.Media.Imaging; using AutoTrackR2.LogEventHandlers; using System.Timers; using System.Linq; -using AutoTrackR2.Constants; + namespace AutoTrackR2; @@ -37,7 +37,7 @@ public partial class HomePage : UserControl { throw new InvalidOperationException("KillHistoryFile path is not configured."); } - _killHistoryManager = new KillHistoryManager(ConfigManager.KillHistoryFile, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sounds")); + _killHistoryManager = new KillHistoryManager(ConfigManager.KillHistoryFile); // Set the TextBlock text KillTallyTitle.Text = $"Kill Tally - {DateTime.Now.ToString("MMMM")}"; @@ -231,7 +231,7 @@ public partial class HomePage : UserControl Method = actorDeathData.DamageType, RecordNumber = playerData?.UEERecord, GameVersion = LocalPlayerData.GameVersion ?? "Unknown", - TrackRver = AppConstants.Version, + TrackRver = "2.10", Enlisted = playerData?.JoinDate, KillTime = ((DateTimeOffset)DateTime.ParseExact(actorDeathData.Timestamp, "yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal)).ToUnixTimeSeconds().ToString(), PFP = playerData?.PFPURL ?? "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg", @@ -279,11 +279,6 @@ public partial class HomePage : UserControl }); } } - else - { - // Player died, reset kill streak - _killHistoryManager.ResetKillStreak(); - } }; // Vehicle Destruction diff --git a/AutoTrackR2/KillHistoryManager.cs b/AutoTrackR2/KillHistoryManager.cs index fd8fa1a..65f33ad 100644 --- a/AutoTrackR2/KillHistoryManager.cs +++ b/AutoTrackR2/KillHistoryManager.cs @@ -8,13 +8,11 @@ public class KillHistoryManager { private string _killHistoryPath; private readonly string _headers = "KillTime,EnemyPilot,EnemyShip,Enlisted,RecordNumber,OrgAffiliation,Player,Weapon,Ship,Method,Mode,GameVersion,TrackRver,Logged,PFP,Hash\n"; - private readonly KillStreakManager _killStreakManager; - public KillHistoryManager(string logPath, string soundsPath) + public KillHistoryManager(string logPath) { _killHistoryPath = logPath; - _killStreakManager = new KillStreakManager(soundsPath); - + if (!File.Exists(_killHistoryPath)) { File.WriteAllText(_killHistoryPath, _headers); @@ -99,9 +97,6 @@ public class KillHistoryManager using var fileStream = new FileStream(_killHistoryPath, FileMode.Append, FileAccess.Write, FileShare.None); using var writer = new StreamWriter(fileStream); writer.Write(csv.ToString()); - - // Trigger kill streak sound - _killStreakManager.OnKill(); } catch (IOException ex) { @@ -109,12 +104,7 @@ public class KillHistoryManager Console.WriteLine($"Error writing to file: {ex.Message}"); } } - - public void ResetKillStreak() - { - _killStreakManager.OnDeath(); - } - + public List<KillData> GetKills() { var kills = new List<KillData>(); diff --git a/AutoTrackR2/KillStreakManager.cs b/AutoTrackR2/KillStreakManager.cs deleted file mode 100644 index 6d4fb28..0000000 --- a/AutoTrackR2/KillStreakManager.cs +++ /dev/null @@ -1,176 +0,0 @@ -using System.Media; -using System.Timers; -using System.IO; -using NAudio.Wave; - -namespace AutoTrackR2; - -public class KillStreakManager -{ - private readonly Queue<string> _soundQueue = new(); - private readonly System.Timers.Timer _killStreakTimer = new(5000); // 5 seconds between kills for streak - private int _currentKills = 0; - private int _totalKills = 0; - private readonly string _soundsPath; - private readonly object _lock = new(); - private WaveOutEvent? _waveOut; - private bool _isPlaying = false; - - public KillStreakManager(string soundsPath) - { - _soundsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sounds"); - _killStreakTimer.Elapsed += OnKillStreakTimerElapsed; - Console.WriteLine($"KillStreakManager initialized with sounds path: {_soundsPath}"); - } - - public void OnKill() - { - lock (_lock) - { - _currentKills++; - _totalKills++; - _killStreakTimer.Stop(); - _killStreakTimer.Start(); - - // Handle multi-kill announcements - string multiKillSound = _currentKills switch - { - 2 => "double_kill.mp3", - 3 => "triple_kill.mp3", - 4 => "overkill.mp3", - 5 => "killtacular.mp3", - 6 => "killtrocity.mp3", - 7 => "killimanjaro.mp3", - 8 => "killtastrophe.mp3", - 9 => "killpocalypse.mp3", - 10 => "killionaire.mp3", - _ => null - }; - - // Handle spree announcements - string spreeSound = _totalKills switch - { - 5 => "killing_spree.mp3", - 10 => "killing_frenzy.mp3", - 15 => "running_riot.mp3", - 20 => "rampage.mp3", - 25 => "untouchable.mp3", - 30 => "invincible.mp3", - 35 => "unstoppable.mp3", - 40 => "hells_janitor.mp3", - 45 => "perfection.mp3", - _ => null - }; - - // Queue up the sounds if they exist - if (multiKillSound != null) - { - string soundPath = Path.Combine(_soundsPath, multiKillSound); - Console.WriteLine($"Queueing multi-kill sound: {soundPath}"); - _soundQueue.Enqueue(soundPath); - } - if (spreeSound != null) - { - string soundPath = Path.Combine(_soundsPath, spreeSound); - Console.WriteLine($"Queueing spree sound: {soundPath}"); - _soundQueue.Enqueue(soundPath); - } - - // Only start playing if not already playing - if (!_isPlaying && _soundQueue.Count > 0) - { - PlayNextSound(); - } - } - } - - public void OnDeath() - { - lock (_lock) - { - _totalKills = 0; - _currentKills = 0; - _killStreakTimer.Stop(); - Console.WriteLine("Kill streak reset due to death"); - } - } - - private void OnKillStreakTimerElapsed(object? sender, ElapsedEventArgs e) - { - lock (_lock) - { - _currentKills = 0; - _killStreakTimer.Stop(); - Console.WriteLine("Kill streak reset due to timeout"); - } - } - - public void Cleanup() - { - lock (_lock) - { - _killStreakTimer.Stop(); - _killStreakTimer.Dispose(); - _waveOut?.Dispose(); - _waveOut = null; - } - } - - private void PlayNextSound() - { - if (_soundQueue.Count > 0) - { - string soundPath = _soundQueue.Dequeue(); - Console.WriteLine($"Attempting to play sound: {soundPath}"); - try - { - if (File.Exists(soundPath)) - { - // Stop any currently playing sound - _waveOut?.Stop(); - _waveOut?.Dispose(); - - // Create a new WaveOutEvent - _waveOut = new WaveOutEvent(); - - // Create a new AudioFileReader for the MP3 file - using var audioFile = new AudioFileReader(soundPath); - _waveOut.Init(audioFile); - - // Set up event handler for when playback finishes - _waveOut.PlaybackStopped += (sender, e) => - { - _isPlaying = false; - if (_soundQueue.Count > 0) - { - PlayNextSound(); - } - }; - - _isPlaying = true; - _waveOut.Play(); - - Console.WriteLine($"Successfully played sound: {soundPath}"); - } - else - { - Console.WriteLine($"Sound file not found: {soundPath}"); - _isPlaying = false; - if (_soundQueue.Count > 0) - { - PlayNextSound(); - } - } - } - catch (Exception ex) - { - Console.WriteLine($"Error playing sound {soundPath}: {ex.Message}"); - _isPlaying = false; - if (_soundQueue.Count > 0) - { - PlayNextSound(); - } - } - } - } -} \ No newline at end of file diff --git a/AutoTrackR2/LogHandler.cs b/AutoTrackR2/LogHandler.cs index d919078..73c0f7f 100644 --- a/AutoTrackR2/LogHandler.cs +++ b/AutoTrackR2/LogHandler.cs @@ -181,7 +181,7 @@ public class LogHandler { // Wait for new lines to be written to the log file - Thread.Sleep(500); + Thread.Sleep(1000); } } Console.WriteLine("Monitor thread stopped"); diff --git a/AutoTrackR2/sounds/double_kill.mp3 b/AutoTrackR2/sounds/double_kill.mp3 deleted file mode 100644 index bf4a0c3..0000000 Binary files a/AutoTrackR2/sounds/double_kill.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/hells_janitor.mp3 b/AutoTrackR2/sounds/hells_janitor.mp3 deleted file mode 100644 index 30d0c04..0000000 Binary files a/AutoTrackR2/sounds/hells_janitor.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/invincible.mp3 b/AutoTrackR2/sounds/invincible.mp3 deleted file mode 100644 index 7acbf3e..0000000 Binary files a/AutoTrackR2/sounds/invincible.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/killimanjaro.mp3 b/AutoTrackR2/sounds/killimanjaro.mp3 deleted file mode 100644 index edbb2a6..0000000 Binary files a/AutoTrackR2/sounds/killimanjaro.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/killing_frenzy.mp3 b/AutoTrackR2/sounds/killing_frenzy.mp3 deleted file mode 100644 index 6d64adf..0000000 Binary files a/AutoTrackR2/sounds/killing_frenzy.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/killing_spree.mp3 b/AutoTrackR2/sounds/killing_spree.mp3 deleted file mode 100644 index 5f2504a..0000000 Binary files a/AutoTrackR2/sounds/killing_spree.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/killionaire.mp3 b/AutoTrackR2/sounds/killionaire.mp3 deleted file mode 100644 index 0224b43..0000000 Binary files a/AutoTrackR2/sounds/killionaire.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/killpocalypse.mp3 b/AutoTrackR2/sounds/killpocalypse.mp3 deleted file mode 100644 index c1ce534..0000000 Binary files a/AutoTrackR2/sounds/killpocalypse.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/killtacular.mp3 b/AutoTrackR2/sounds/killtacular.mp3 deleted file mode 100644 index b0cc69a..0000000 Binary files a/AutoTrackR2/sounds/killtacular.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/killtastrophe.mp3 b/AutoTrackR2/sounds/killtastrophe.mp3 deleted file mode 100644 index e4267cb..0000000 Binary files a/AutoTrackR2/sounds/killtastrophe.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/killtrocity.mp3 b/AutoTrackR2/sounds/killtrocity.mp3 deleted file mode 100644 index 5bd5f33..0000000 Binary files a/AutoTrackR2/sounds/killtrocity.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/overkill.mp3 b/AutoTrackR2/sounds/overkill.mp3 deleted file mode 100644 index 83fb2bb..0000000 Binary files a/AutoTrackR2/sounds/overkill.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/perfection.mp3 b/AutoTrackR2/sounds/perfection.mp3 deleted file mode 100644 index c0b7f74..0000000 Binary files a/AutoTrackR2/sounds/perfection.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/rampage.mp3 b/AutoTrackR2/sounds/rampage.mp3 deleted file mode 100644 index 37d9bc9..0000000 Binary files a/AutoTrackR2/sounds/rampage.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/running_riot.mp3 b/AutoTrackR2/sounds/running_riot.mp3 deleted file mode 100644 index 5eec17b..0000000 Binary files a/AutoTrackR2/sounds/running_riot.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/triple_kill.mp3 b/AutoTrackR2/sounds/triple_kill.mp3 deleted file mode 100644 index b489151..0000000 Binary files a/AutoTrackR2/sounds/triple_kill.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/unstoppable.mp3 b/AutoTrackR2/sounds/unstoppable.mp3 deleted file mode 100644 index 7c8a342..0000000 Binary files a/AutoTrackR2/sounds/unstoppable.mp3 and /dev/null differ diff --git a/AutoTrackR2/sounds/untouchable.mp3 b/AutoTrackR2/sounds/untouchable.mp3 deleted file mode 100644 index 4763213..0000000 Binary files a/AutoTrackR2/sounds/untouchable.mp3 and /dev/null differ