mirror of
https://github.com/kwsch/NHSE.git
synced 2026-08-27 21:34:15 -05:00
Add trycatch for sysbot read/write, turn off auto-r/w on fail
Closes #156 turning off auto-r/w won't happen if the auto-r/w itself fails. still pops open a message saying error until you turn it off in the other window.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace NHSE.Injection
|
||||
{
|
||||
@@ -29,18 +30,35 @@ public InjectionResult Read(bool force = false)
|
||||
{
|
||||
if ((!AutoInjectEnabled && !force) || !Injector.Connected)
|
||||
return InjectionResult.Skipped;
|
||||
var result = Injector.Read();
|
||||
AfterRead(result);
|
||||
return result;
|
||||
|
||||
try
|
||||
{
|
||||
var result = Injector.Read();
|
||||
AfterRead(result);
|
||||
return result;
|
||||
}
|
||||
catch (IndexOutOfRangeException ex)
|
||||
{
|
||||
Debug.WriteLine(ex.Message);
|
||||
return InjectionResult.FailConnectionError;
|
||||
}
|
||||
}
|
||||
|
||||
public InjectionResult Write(bool force = false)
|
||||
{
|
||||
if ((!AutoInjectEnabled && !force) || !Injector.Connected)
|
||||
return InjectionResult.Skipped;
|
||||
var result = Injector.Write();
|
||||
AfterWrite(result);
|
||||
return result;
|
||||
try
|
||||
{
|
||||
var result = Injector.Write();
|
||||
AfterWrite(result);
|
||||
return result;
|
||||
}
|
||||
catch (IndexOutOfRangeException ex)
|
||||
{
|
||||
Debug.WriteLine(ex.Message);
|
||||
return InjectionResult.FailConnectionError;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetWriteOffset(in uint offset)
|
||||
|
||||
@@ -5,6 +5,7 @@ public enum InjectionResult
|
||||
Skipped,
|
||||
Success,
|
||||
FailValidate,
|
||||
FailConnectionError,
|
||||
Same,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,8 +50,9 @@ private void B_WriteCurrent_Click(object sender, EventArgs e)
|
||||
try
|
||||
{
|
||||
var result = Injector.Write(true);
|
||||
if (result != InjectionResult.Success)
|
||||
WinFormsUtil.Alert(result.ToString());
|
||||
if (result == InjectionResult.Success)
|
||||
return;
|
||||
WinFormsUtil.Alert(result.ToString());
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
@@ -59,6 +60,7 @@ private void B_WriteCurrent_Click(object sender, EventArgs e)
|
||||
{
|
||||
WinFormsUtil.Error(ex.Message);
|
||||
}
|
||||
TurnOffAuto();
|
||||
}
|
||||
|
||||
private void B_ReadCurrent_Click(object sender, EventArgs e)
|
||||
@@ -66,8 +68,9 @@ private void B_ReadCurrent_Click(object sender, EventArgs e)
|
||||
try
|
||||
{
|
||||
var result = Injector.Read(true);
|
||||
if (result != InjectionResult.Success)
|
||||
WinFormsUtil.Alert(result.ToString());
|
||||
if (result == InjectionResult.Success)
|
||||
return;
|
||||
WinFormsUtil.Alert(result.ToString());
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
@@ -75,6 +78,15 @@ private void B_ReadCurrent_Click(object sender, EventArgs e)
|
||||
{
|
||||
WinFormsUtil.Error(ex.Message);
|
||||
}
|
||||
TurnOffAuto();
|
||||
}
|
||||
|
||||
private void TurnOffAuto()
|
||||
{
|
||||
if (CHK_AutoRead.Checked)
|
||||
CHK_AutoRead.Checked = false;
|
||||
if (CHK_AutoWrite.Checked)
|
||||
CHK_AutoWrite.Checked = false;
|
||||
}
|
||||
|
||||
private void CHK_AutoWrite_CheckedChanged(object sender, EventArgs e) => Injector.AutoInjectEnabled = CHK_AutoWrite.Checked;
|
||||
|
||||
Reference in New Issue
Block a user