Skip to content

Commit

Permalink
Merge pull request #13 from mdnpascual/settings-gui
Browse files Browse the repository at this point in the history
Settings GUI
  • Loading branch information
mdnpascual committed Apr 26, 2023
2 parents 7ac0aa2 + ad36b56 commit 7d999d2
Show file tree
Hide file tree
Showing 17 changed files with 800 additions and 157 deletions.
70 changes: 15 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Download and Install: https://dotnet.microsoft.com/en-us/download/dotnet/6.0 (.N

- Run the game first OR again, run the tool as Administrator

### When setting up the points, the zoom in the circle only shows white pixels.

- The game needs to be run on the main monitor.

### Status stuck at NotFishing after setup and clicking Start Fishing. I can see it moving the cursor but doesn't catch the fish

- Make sure the lowest point of the Fish and Player stamina are properly selected (See tutorial).
Expand All @@ -53,55 +57,25 @@ Download and Install: https://dotnet.microsoft.com/en-us/download/dotnet/6.0 (.N

- Some other programs are interfering with the mouse/keyboard detection. I cannot help with this one unfortunately as I'm just using an external package to send/detect the mouse position.

# Advanced Customization

### This section explains how you can customize certain aspectos or behaviour of the tool.

After setting up the tool for the first time, you should see a `settings.json` file on the same folder of the executable. Open it, and add and entry if needed

## Button for Fish Capture
#### `"KeyCode_FishCapture": <keycode_intval>`
Example: ``` "KeyCode_FishCapture": "49"``` (default)

Where `keycode_intval` is the value of the keycode in integer. To set your custom hotkey to capture the fish, Please refer to: http://www.foreui.com/articles/Key_Code_Table.htm
In the example above, the value of 49 represent the Keyboard Input "1".

## Button to dismiss Fish Capture Dialogue
#### `"KeyCode_DismissFishDialogue": <keycode_intval>`
Example: ``` "KeyCode_DismissFishDialogue": "27"``` (default)
# Discord Notification

Where `keycode_intval` is the value of the keycode in integer. To set your custom hotkey to dismiss the fish capture dialogue, Please refer to: http://www.foreui.com/articles/Key_Code_Table.htm
In the example above, the value of 27 represent the Keyboard Input "Escape".
### The tool can notify you via Discord when you run out of bait. You need to setup two things on the settings for this to work

## Delay for Lag Compensation at start of fishing
#### `"Delay_LagCompensation": <delay_in_ms>`
Example: ``` "Delay_LagCompensation": "5000"``` (default)
#### `Discord Webhook URL`

Where `delay_in_ms` is the delay in millisecond to prevent the tool by reeling in immediatly after starting.
After starting to fish, there is a delay/lag associated before the fish stamina is filled. This is the delay to compensate for that.
You need to have your own Discord Server OR have a permission on a Discord Server to set up Integrations for this to work.
Create a webhook but following this [tutorial](https://support.discord.com/hc/en-us/articles/228383668).
After creating your webhook, Click on `Copy Webhook URL` and paste the value to the setting.

## Delay before capturing fish after fish stamina detected has been depleted
#### `Discord User Id`

#### `"Delay_FishCapture": <delay_in_ms>`
Example: ``` "Delay_FishCapture": "2000"``` (default)
Is the user id that you want to be pinged/mentioned. Follow this [tutorial](https://support.discord.com/hc/vi/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-) on how to get your user id. **Note: Make sure the Id you having is User Id, not Message Id or Channel Id**

Where `delay_in_ms` is the delay in millisecond before the tool presses the reel-in hotkey.
When the tool detects that the fish stamina is depleted, it will wait for this delay before capturing the fish.
If you notice that the tool sometimes pre-emptively catches a fish on higher stamina fish or alphas, then increasing this delay will force the tool to wait longer before capturing the fish.

## Delay before dismissing the Fish Capture screen
#### `"Delay_DismissFishCaptureDialogue": <delay_in_ms>`
Example: ``` "Delay_DismissFishCaptureDialogue": "4000"``` (default)

Where `delay_in_ms` is the delay in millisecond before the tool presses the ESC Key after capturing the fish.
This is needed when you don't have all the alphas caught.
If you have all the alphas caught and want to speed up the fishing loop a bit, you can change this down to 2000
# Advanced Customization

## Delay before restarting the process again
#### `"Delay_Restart": <delay_in_ms>`
Example: ``` "Delay_Restart": "2000"``` (default)
### This section explains how you can customize certain aspectos or behaviour of the tool.

Where `delay_in_ms` is the delay in millisecond before the tool restarts the fishing process again after pressing the ESC Key.
After setting up the tool for the first time, you should see a `settings.json` file on the same folder of the executable. Open it, and add and entry if needed

## Minimum height on middle bar
#### `"MinimumMiddleBarHeight": <pixel_difference>`
Expand Down Expand Up @@ -148,17 +122,3 @@ Example: ``` "MiddlebarColorDetectionThreshold": "10.0"``` (default)

Where `double_val` is a the amount of variance that the game will accept as the correct color for the middle bar.
Lower values means a stricter check but more false positives. Higher values means less strict but more false negatives.

## Discord Notification
#### `"DiscordHookUrl": "<Discord_webhook_URL>"`
Example: ```"DiscordHookUrl": "https://discordapp.com/api/webhooks/xxxx"```
Default value: ""

Where `Discord_webhook_URL` is a link of discord webhook, which can use to send a notification when bait is running out. How to get a `Discord_webhook_URL` you can see at [here](https://support.discord.com/hc/en-us/articles/228383668). After create a webhook, just simple click on `Copy Webhook URL` and paste the value to the setting.

### If you want the hook mention you when send message
#### `"DiscordUserId": "<Discord_User_Id>"`
Example: ```"DiscordUserId": "123456789"```
Default value: ""

Where `Discord_User_Id` is user id that you want to be mentioned. How to get a `Discord_User_Id` you can see at [here](https://support.discord.com/hc/vi/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-). After getting user id, just simple paste the value to the setting. **Note: Make sure the Id you having is User Id, not Message Id or Channel Id**
18 changes: 16 additions & 2 deletions ToF_Fishing_Bot/Addon/DiscordInteractive/DiscordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ public Task<HookContent> BuildOutOfBaitNotification(DateTime fishingStartAt)
var strBuild = new StringBuilder("Hello");
if (!string.IsNullOrEmpty(_mentionId))
{
strBuild.Append($"<@!{_mentionId}>");
strBuild.Append($"<@!{_mentionId}>.");
}
strBuild.AppendLine(". Thank for using fishing bot.");
strBuild.AppendLine("This program is open source and free to use [here](https://github.com/mdnpascual/ToF-Fishing-Bot).");
var hookContent = new HookContent()
{
Expand All @@ -102,4 +101,19 @@ public Task<HookContent> BuildOutOfBaitNotification(DateTime fishingStartAt)
};
return Task.FromResult(hookContent);
}

public Task<HookContent> BuildGenericNotification(string message)
{
var strBuild = new StringBuilder("Hello");
if (!string.IsNullOrEmpty(_mentionId))
{
strBuild.AppendLine($"<@!{_mentionId}>.");
}
strBuild.AppendLine(message);
var hookContent = new HookContent()
{
Content = strBuild.ToString()
};
return Task.FromResult(hookContent);
}
}
26 changes: 10 additions & 16 deletions ToF_Fishing_Bot/FishingThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class FishingThread
private bool PlayerStamina_lagCompensationDone = false;
private DispatcherTimer LagCompensationDelay = new();

private readonly SolidColorBrush GreenColor = new(System.Windows.Media.Color.FromArgb(255, 0, 255, 0));
private readonly SolidColorBrush ColorAccent2 = new(System.Windows.Media.Color.FromArgb(255, 0, 138, 205));

private Bitmap bmp = new(1, 1);
private BitmapImage bi1;
private BitmapImage bi2;
Expand Down Expand Up @@ -323,15 +320,15 @@ private void CenterCursor(double middleBarPos, double fishingCursorPos)
{
if (GameHandle != null)
{
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, WindowsInput.Native.VirtualKeyCode.VK_A);
InputSimulator.Keyboard.KeyDownBackground(GameHandle.Value, WindowsInput.Native.VirtualKeyCode.VK_D);
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, (WindowsInput.Native.VirtualKeyCode)settings.KeyCode_MoveLeft);
InputSimulator.Keyboard.KeyDownBackground(GameHandle.Value, (WindowsInput.Native.VirtualKeyCode)settings.KeyCode_MoveRight);
}
DPressed = true;
APressed = false;

right.Dispatcher.Invoke(() =>
{
right.Fill = settings.IsDarkMode > 0 ? ColorAccent2 : GreenColor;
right.Fill = settings.IsDarkMode > 0 ? Theme.ColorAccent2 : Theme.GreenColor;
});
left.Dispatcher.Invoke(() =>
{
Expand All @@ -345,15 +342,15 @@ private void CenterCursor(double middleBarPos, double fishingCursorPos)
{
if (GameHandle != null)
{
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, WindowsInput.Native.VirtualKeyCode.VK_D);
InputSimulator.Keyboard.KeyDownBackground(GameHandle.Value, WindowsInput.Native.VirtualKeyCode.VK_A);
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, (WindowsInput.Native.VirtualKeyCode)settings.KeyCode_MoveRight);
InputSimulator.Keyboard.KeyDownBackground(GameHandle.Value, (WindowsInput.Native.VirtualKeyCode)settings.KeyCode_MoveLeft);
}
DPressed = false;
APressed = true;

left.Dispatcher.Invoke(() =>
{
left.Fill = settings.IsDarkMode > 0 ? ColorAccent2 : GreenColor;
left.Fill = settings.IsDarkMode > 0 ? Theme.ColorAccent2 : Theme.GreenColor;
});
right.Dispatcher.Invoke(() =>
{
Expand All @@ -367,7 +364,7 @@ private void CenterCursor(double middleBarPos, double fishingCursorPos)
{
if (GameHandle != null)
{
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, WindowsInput.Native.VirtualKeyCode.VK_A);
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, (WindowsInput.Native.VirtualKeyCode)settings.KeyCode_MoveLeft);
}
APressed = false;
left.Dispatcher.Invoke(() =>
Expand All @@ -379,7 +376,7 @@ private void CenterCursor(double middleBarPos, double fishingCursorPos)
{
if (GameHandle != null)
{
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, WindowsInput.Native.VirtualKeyCode.VK_D);
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, (WindowsInput.Native.VirtualKeyCode)settings.KeyCode_MoveRight);
}
DPressed = false;
right.Dispatcher.Invoke(() =>
Expand Down Expand Up @@ -526,7 +523,7 @@ public void ResetKeys()
{
if (GameHandle != null)
{
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, WindowsInput.Native.VirtualKeyCode.VK_A);
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, (WindowsInput.Native.VirtualKeyCode)settings.KeyCode_MoveLeft);
}
APressed = false;
left.Dispatcher.Invoke(() =>
Expand All @@ -536,7 +533,7 @@ public void ResetKeys()

if (GameHandle != null)
{
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, WindowsInput.Native.VirtualKeyCode.VK_D);
InputSimulator.Keyboard.KeyUpBackground(GameHandle.Value, (WindowsInput.Native.VirtualKeyCode)settings.KeyCode_MoveRight);
}
DPressed = false;
right.Dispatcher.Invoke(() =>
Expand All @@ -545,9 +542,6 @@ public void ResetKeys()
});
}

[DllImport("user32.dll", EntryPoint = "SetCursorPos")]
private static extern int SetCursorPos(int x, int y);

enum FishingState
{
NotFishing,
Expand Down
6 changes: 5 additions & 1 deletion ToF_Fishing_Bot/IAppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public interface IAppSettings
double MiddlebarColorDetectionThreshold { get; set; }
[DefaultValue(5000)]
int Delay_LagCompensation { get; set; }
[DefaultValue(2000)]
[DefaultValue(3000)]
int Delay_FishCapture { get; set; }
[DefaultValue(4000)]
int Delay_DismissFishCaptureDialogue { get; set; }
Expand All @@ -72,6 +72,10 @@ public interface IAppSettings
int KeyCode_FishCapture { get; set; }
[DefaultValue(27)]
int KeyCode_DismissFishDialogue{ get; set; }
[DefaultValue(65)]
int KeyCode_MoveLeft { get; set; }
[DefaultValue(68)]
int KeyCode_MoveRight { get; set; }

[DefaultValue("")]
string DiscordHookUrl { get; set; }
Expand Down
15 changes: 15 additions & 0 deletions ToF_Fishing_Bot/KeycodeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Windows.Forms;

namespace ToF_Fishing_Bot
{
public class KeycodeHelper
{
private static readonly KeysConverter kc = new();

public static string KeycodeToString(int keyCode)
{
var buttonName = kc.ConvertToString(keyCode) ?? "???";
return buttonName.ToUpper();
}
}
}
7 changes: 5 additions & 2 deletions ToF_Fishing_Bot/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
<StackPanel Height="100" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,5,0,0">
<Grid Width="100">
<Rectangle x:Name="LeftBox" Stroke="Black" RadiusX="20" RadiusY="20" Fill="#00000000"/>
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="A" VerticalAlignment="Center" FontSize="36"/>
<TextBlock x:Name="MoveLeftLabel" HorizontalAlignment="Center" TextWrapping="Wrap" Text="A" VerticalAlignment="Center" FontSize="36"/>
</Grid>
<Grid Width="100" Margin="35,0,0,0">
<Rectangle x:Name="RightBox" Stroke="Black" RadiusX="20" RadiusY="20" Fill="#00000000"/>
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="D" VerticalAlignment="Center" FontSize="36"/>
<TextBlock x:Name="MoveRightLabel" HorizontalAlignment="Center" TextWrapping="Wrap" Text="D" VerticalAlignment="Center" FontSize="36"/>
</Grid>
</StackPanel>
<StackPanel Height="100" HorizontalAlignment="Center">
Expand Down Expand Up @@ -104,5 +104,8 @@
<Button x:Name="ThemeModeBtn" HorizontalAlignment="Left" Margin="228,275,0,0" VerticalAlignment="Top" Width="30" Height="30" Click="ThemeModeBtn_Click" Grid.Column="2">
<Image x:Name="ThemeModeImg" Height="25" Width="25" Source="/img/night.png" Stretch="Fill"/>
</Button>
<Button x:Name="SettingBtn" HorizontalAlignment="Left" Margin="86,275,0,0" VerticalAlignment="Top" Width="30" Height="30" Click="SettingBtn_Click" Grid.Column="2">
<Image x:Name="SettingImg" Height="25" Width="25" Source="/img/setting_day.png" Stretch="Fill"/>
</Button>
</Grid>
</Window>

0 comments on commit 7d999d2

Please sign in to comment.