Skip to content

Commit

Permalink
logging errors to ummm debug txt thing
Browse files Browse the repository at this point in the history
  • Loading branch information
TaylorIsBlue committed Aug 13, 2024
1 parent 5a2272e commit 1dbb1b2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
27 changes: 12 additions & 15 deletions Aimmy2/AILogic/AIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ private async Task InitializeModel(SessionOptions sessionOptions, string modelPa
await Application.Current.Dispatcher.BeginInvoke(new Action(() => new NoticeBar($"Error starting the model via CUDA: {ex.Message}\n\nFalling back to DirectML, performance may be poor.", 5000).Show()));
try
{
FileManager.LogError($"Error starting the model via CUDA: {ex}");
await LoadModelAsync(sessionOptions, modelPath, useCUDA: false);
}
catch (Exception e)
{
FileManager.LogError($"Error starting the model via Tensorrt: {e}");
await Application.Current.Dispatcher.BeginInvoke(new Action(() => new NoticeBar($"Error starting the model via Tensorrt: {e.Message}, you won't be able to aim assist at all.", 5000).Show()));
}
}
Expand All @@ -193,6 +195,7 @@ private async Task LoadModelAsync(SessionOptions sessionOptions, string modelPat
}
catch (Exception ex)
{
FileManager.LogError($"Error starting the model: {ex}");
await Application.Current.Dispatcher.BeginInvoke(new Action(() => new NoticeBar($"Error starting the model: {ex.Message}", 5000).Show()));
_onnxModel?.Dispose();
}
Expand All @@ -218,6 +221,8 @@ private void ValidateOnnxShape()
, 15000)
.Show()
));

FileManager.LogError("Output shape does not match the expected shape of 1x5x8400. This model will not work with Aimmy, please use an YOLOv8 model converted to ONNXv8.");
}
}
}
Expand Down Expand Up @@ -276,7 +281,7 @@ private async void AiLoop()
double averageTime = totalTime / 1000.0;
//Debug.WriteLine($"Average loop iteration time: {averageTime} ms");
MessageBox.Show($"Average loop iteration time: {averageTime} ms", "Share this iteration time on our discord!");
LogError($"Average loop iteration time: {averageTime} ms");
FileManager.LogError($"Average loop iteration time: {averageTime} ms");
totalTime = 0;
iterationCount = 0;
}
Expand Down Expand Up @@ -659,7 +664,7 @@ private void HandlePredictions(KalmanPrediction kalmanPrediction, Prediction clo
}
catch (Exception e)
{
LogError("Error capturing screen:" + e);
FileManager.LogError("Error capturing screen:" + e);
return null;
}
return null;
Expand Down Expand Up @@ -695,11 +700,11 @@ private Rectangle ClampRectangle(Rectangle rect, int screenWidth, int screenHeig
{
if (result == Vortice.DXGI.ResultCode.DeviceRemoved) // This usually happens when using closest to mouse
{
LogError("Device removed, reinitializing D3D11.");
FileManager.LogError("Device removed, reinitializing D3D11.");
ReinitializeD3D11();
return null;
}
LogError("Failed to acquire next frame: " + result);
FileManager.LogError("Failed to acquire next frame: " + result);
ReinitializeD3D11();
return null;
}
Expand Down Expand Up @@ -779,24 +784,16 @@ private Rectangle ClampRectangle(Rectangle rect, int screenWidth, int screenHeig
}
catch (SharpGenException ex)
{
LogError("SharpGenException: " + ex);
FileManager.LogError("SharpGenException: " + ex);
return null;
}
catch (Exception e)
{
LogError("Error capturing screen: " + e);
FileManager.LogError("Error capturing screen: " + e);
return null;
}
}
private void LogError(string message)
{
if (Dictionary.toggleState["Debug Mode"])
{
string logFilePath = "debug.txt";
using StreamWriter writer = new StreamWriter(logFilePath, true);
writer.WriteLine($"[{DateTime.Now}]: {message}");
}
}

//private Bitmap? DeprecatedScreen(Rectangle detectionBox) // if for some reason they want to use the old method...
//{
// if (_screenCaptureBitmap == null || _screenCaptureBitmap.Width != detectionBox.Width || _screenCaptureBitmap.Height != detectionBox.Height)
Expand Down
6 changes: 5 additions & 1 deletion Aimmy2/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ public async Task LoadStoreMenu()
}
catch (Exception e)
{
FileManager.LogError("Error loading store menu: " + e);
new NoticeBar(e.Message, 10000).Show();
return;
}
Expand Down Expand Up @@ -1080,8 +1081,10 @@ private void LoadConfig(string path = "bin\\configs\\Default.cfg", bool loading_
uiManager.S_AIMinimumConfidence!.Slider.Value = MainWindow.GetValueOrDefault(Dictionary.sliderSettings, "AI Minimum Confidence", 50);
}
}
catch (Exception e)

catch(Exception e)
{
FileManager.LogError("Error loading config " + e);
MessageBox.Show($"Error loading config, possibly outdated\n{e}");
}
}
Expand Down Expand Up @@ -1110,6 +1113,7 @@ private void LoadAntiRecoilConfig(string path = "bin\\anti_recoil_configs\\Defau
}
catch (Exception e)
{
FileManager.LogError("Error loading anti-recoil config: " + e);
throw new Exception($"Error loading config, possibly outdated\n{e}");
}
}
Expand Down
7 changes: 5 additions & 2 deletions Aimmy2/MouseMovementLibraries/ddxoftSupport/ddxoftMain.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using Other;
using System.IO;
using System.Net.Http;
using System.Security.Principal;
using System.Windows;
Expand Down Expand Up @@ -28,8 +29,9 @@ private static async Task DownloadDdxoft()
new NoticeBar($"{ddxoftpath} has downloaded successfully, please re-select ddxoft Virtual Input Driver to load the DLL.", 4000).Show();
}
}
catch
catch(Exception e)
{
FileManager.LogError("Failed to download ddxoft.dll: " + e);
new NoticeBar($"{ddxoftpath} has failed to install, please try a different Mouse Movement Method.", 4000).Show();
}
}
Expand Down Expand Up @@ -60,6 +62,7 @@ public static async Task<bool> DLLLoading()
}
catch (Exception ex)
{
FileManager.LogError("Failed to load ddxoft: " + ex);
MessageBox.Show("Failed to load ddxoft virtual input driver.\n\n" + ex.ToString(), "Aimmy");
return false;
}
Expand Down
12 changes: 11 additions & 1 deletion Aimmy2/Other/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private void CheckForRequiredFolders()
}
catch (Exception ex)
{
LogError("Error creating a required directory: " + ex);
MessageBox.Show($"Error creating a required directory: {ex}");
Application.Current.Shutdown();
}
Expand Down Expand Up @@ -202,7 +203,15 @@ public void LoadConfigsIntoListBox(object? sender, FileSystemEventArgs? e)
});
}
}

public static void LogError(string message)
{
if (Dictionary.toggleState["Debug Mode"])
{
string logFilePath = "debug.txt";
using StreamWriter writer = new StreamWriter(logFilePath, true);
writer.WriteLine($"[{DateTime.Now}]: {message}");
}
}
public static async Task<HashSet<string>> RetrieveAndAddFiles(string repoLink, string localPath, HashSet<string> allFiles)
{
try
Expand All @@ -227,6 +236,7 @@ public static async Task<HashSet<string>> RetrieveAndAddFiles(string repoLink, s
}
catch (Exception ex)
{
LogError(ex.ToString());
throw new Exception(ex.ToString());
}
}
Expand Down
5 changes: 4 additions & 1 deletion Aimmy2/Other/GetSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Management;
using Other;
using System.Management;
using Visuality;

namespace Aimmy2.Class
Expand All @@ -20,6 +21,8 @@ internal class GetSpecs
}
catch (Exception e)
{

FileManager.LogError("Failed to get specs: " + e);
new NoticeBar(e.Message, 10000).Show();
return "Not Found";
}
Expand Down
3 changes: 2 additions & 1 deletion Aimmy2/Other/KeybindNameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public static string ConvertToRegularKey(string keyName)
var key = (Key)kc.ConvertFromString(keyName)!;
return KeybindNames.TryGetValue(key.ToString(), out var displayName) ? displayName : key.ToString();
}
catch (Exception)
catch (Exception ex)
{
FileManager.LogError("Failed to grab keybind (most likely a missing keybind from dictionary) " + ex);
return keyName;
}
}
Expand Down

0 comments on commit 1dbb1b2

Please sign in to comment.