Skip to content

Commit

Permalink
Exposed some settings in settings.json
Browse files Browse the repository at this point in the history
  • Loading branch information
mdnpascual committed Apr 8, 2023
1 parent 01df54a commit 6c63291
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
32 changes: 17 additions & 15 deletions ToF_Fishing_Bot/FishingThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class FishingThread
private IAppSettings settings;
public bool isRunning = false;
private InputSimulator InputSimulator;
public int counter = 0;

private System.Windows.Shapes.Rectangle left;
private System.Windows.Shapes.Rectangle right;
Expand All @@ -45,8 +44,8 @@ class FishingThread
private MemoryStream ms1;
private MemoryStream ms2;

private double colorThreshold = 40.0;
private double middleBarCenterThreshold = 10.0;
private double colorThreshold;
private double middleBarCenterThreshold;

private ScreenStateLogger screenStateLogger;

Expand Down Expand Up @@ -94,6 +93,9 @@ public FishingThread(
GameHandle = _gameHandle.Value;
}

colorThreshold = settings.StaminaColorDetectionThreshold;
middleBarCenterThreshold = settings.MiddlebarColorDetectionThreshold;

screenStateLogger = new ScreenStateLogger();
}

Expand Down Expand Up @@ -141,7 +143,7 @@ public void Start()
ClickFishCaptureButton();
break;
case FishingState.Captured:
ClickTapToCloseButton();
CloseFishCaptureDialog();
ResetKeys();
break;
case FishingState.Reset:
Expand All @@ -157,7 +159,7 @@ public void Start()
state = FishingState.Fishing;
PlayerStamina_lagCompensationDone = false;
LagCompensationDelay = new DispatcherTimer(DispatcherPriority.Send, dis);
LagCompensationDelay.Interval = new TimeSpan(0,0,0,5);
LagCompensationDelay.Interval = new TimeSpan(0, 0, 0, 0, settings.Delay_LagCompensation);
LagCompensationDelay.Tick += (o, e) =>
{
PlayerStamina_lagCompensationDone = true;
Expand All @@ -171,7 +173,7 @@ public void Start()
{
state = FishingState.ReelingStart;
ReelDelay = new DispatcherTimer(DispatcherPriority.Send, dis);
ReelDelay.Interval = new TimeSpan(0,0,0,2);
ReelDelay.Interval = new TimeSpan(0, 0, 0, 0, settings.Delay_FishCapture);
ReelDelay.Tick += (o, e) =>
{
state = FishingState.Reeling;
Expand All @@ -187,7 +189,7 @@ public void Start()
case FishingState.Reeling:
state = FishingState.CaptureStart;
CaptureDelay = new DispatcherTimer(DispatcherPriority.Send, dis);
CaptureDelay.Interval = new TimeSpan(0, 0, 0, 2);
CaptureDelay.Interval = new TimeSpan(0, 0, 0, 0, settings.Delay_DismissFishCaptureDialogue);
CaptureDelay.Tick += (o, e) =>
{
state = FishingState.Captured;
Expand All @@ -201,7 +203,7 @@ public void Start()
case FishingState.Captured:
state = FishingState.ResetStart;
ResetDelay = new DispatcherTimer(DispatcherPriority.Send, dis);
ResetDelay.Interval = new TimeSpan(0, 0, 0, 2);
ResetDelay.Interval = new TimeSpan(0, 0, 0, 0, settings.Delay_Restart);
ResetDelay.Tick += (o, e) =>
{
state = FishingState.Reset;
Expand Down Expand Up @@ -364,7 +366,7 @@ public double GetMiddleBarAveragePos(Mat frame)
Cv2.InRange(frame, lowerBoundsColor, upperBoundsColor, masked);
/*Cv2.ImShow("masked", masked);*/

var lineDetect = FastLineDetector.Create(lengthThreshold: 4);
var lineDetect = FastLineDetector.Create(lengthThreshold: settings.MinimumMiddleBarHeight - 1);
try
{
var lines = lineDetect.Detect(masked);
Expand Down Expand Up @@ -408,7 +410,7 @@ public double GetFishingCursorPos(Mat frame)
var masked = new Mat();
Cv2.InRange(frame, lowerBoundsColor, upperBoundsColor, masked);
/*Cv2.ImShow("masked", masked);*/
var lineDetect = FastLineDetector.Create(lengthThreshold: 4);
var lineDetect = FastLineDetector.Create(lengthThreshold: settings.MinimumMiddleBarHeight - 1);

try
{
Expand Down Expand Up @@ -452,20 +454,20 @@ public void ClickFishCaptureButton()
{
if (GameHandle != null)
{
InputSimulator.Keyboard.KeyDownBackground(GameHandle.Value, WindowsInput.Native.VirtualKeyCode.VK_1);
InputSimulator.Keyboard.KeyDownBackground(GameHandle.Value, (WindowsInput.Native.VirtualKeyCode) settings.KeyCode_FishCapture);
InputSimulator.Mouse.Sleep(25);
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, WindowsInput.Native.VirtualKeyCode.VK_1);
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, (WindowsInput.Native.VirtualKeyCode)settings.KeyCode_FishCapture);
InputSimulator.Mouse.Sleep(25);
}
}

public void ClickTapToCloseButton()
public void CloseFishCaptureDialog()
{
if (GameHandle != null)
{
InputSimulator.Keyboard.KeyDownBackground(GameHandle.Value, WindowsInput.Native.VirtualKeyCode.ESCAPE);
InputSimulator.Keyboard.KeyDownBackground(GameHandle.Value, (WindowsInput.Native.VirtualKeyCode)settings.KeyCode_DismissFishDialogue);
InputSimulator.Mouse.Sleep(25);
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, WindowsInput.Native.VirtualKeyCode.ESCAPE);
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, (WindowsInput.Native.VirtualKeyCode)settings.KeyCode_DismissFishDialogue);
InputSimulator.Mouse.Sleep(25);
}
}
Expand Down
26 changes: 26 additions & 0 deletions ToF_Fishing_Bot/IAppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,31 @@ public interface IAppSettings
int LowerRightBarPoint_Y { get; set; }
[DefaultValue(0)]
int IsDarkMode { get; set; }
[DefaultValue(300)]
int ZoomSize_X { get; set; }
[DefaultValue(300)]
int ZoomSize_Y { get; set; }
[DefaultValue(4)]
int ZoomFactor { get; set; }
[DefaultValue("QRSL")]
string GameProcessName { get; set; }
[DefaultValue(40.0)]
double StaminaColorDetectionThreshold { get; set; }
[DefaultValue(10.0)]
double MiddlebarColorDetectionThreshold { get; set; }
[DefaultValue(5000)]
int Delay_LagCompensation { get; set; }
[DefaultValue(2000)]
int Delay_FishCapture { get; set; }
[DefaultValue(2000)]
int Delay_DismissFishCaptureDialogue { get; set; }
[DefaultValue(2000)]
int Delay_Restart { get; set; }
[DefaultValue(5)]
int MinimumMiddleBarHeight { get; set; }
[DefaultValue(49)]
int KeyCode_FishCapture { get; set; }
[DefaultValue(27)]
int KeyCode_DismissFishDialogue{ get; set; }
}
}
6 changes: 3 additions & 3 deletions ToF_Fishing_Bot/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ private void HandleButtonClick(

lens_form = new Lens_Form()
{
Size = new System.Drawing.Size(300, 300),
Size = new System.Drawing.Size(settings.ZoomSize_X, settings.ZoomSize_Y),
AutoClose = true,
HideCursor = false,
ZoomFactor = 4,
ZoomFactor = settings.ZoomFactor,
NearestNeighborInterpolation = false
};
lens_form.Show();
Expand Down Expand Up @@ -350,7 +350,7 @@ private void StartBtn_Click(object sender, RoutedEventArgs e)
var message = String.Empty;
var noErrors = true;

Process[] processes = Process.GetProcessesByName("QRSL");
Process[] processes = Process.GetProcessesByName(settings.GameProcessName);

if (processes.Length == 0)
{
Expand Down

0 comments on commit 6c63291

Please sign in to comment.