Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ jobs:
- name: Build
run: |
uv sync --locked --group build
uv run --locked pyinstaller --onefile --windowed --name getthefish-gui src/getthefish/gui/main_window.py
uv run --locked python -m getthefish.gui.icon build/getthefish.ico
uv run --locked pyinstaller --onefile --windowed --name getthefish-gui --icon build/getthefish.ico src/getthefish/gui/main_window.py
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: exe
Expand Down
49 changes: 44 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
[![CI](../../actions/workflows/ci.yml/badge.svg)](../../actions/workflows/ci.yml)

An automated fishing tool. It casts the line, finds the bobber by its colour,
watches it for a bite and reels the fish in. A small PySide6 GUI lets you pick
the bobber colour and the search area directly on screen.
watches it for a bite and reels the fish in. A PySide6 GUI lets you pick the
bobber colour and the search area directly on screen, shows each round live and
keeps statistics. A compact view fits beside the game in windowed mode.

> **Note:** The tool moves the mouse and reads the screen. Only use it where
> automation is allowed by the game's terms of service.
Expand Down Expand Up @@ -53,12 +54,32 @@ getthefish --help # options: --config PATH, --verbose
In the GUI:

- **Set Area** – drag a rectangle over the water where the bobber lands. Esc or right-click cancels.
- **Select Color** – click on the bobber in the frozen screenshot. Esc cancels.
- **Pick Color** – click on the bobber in the frozen screenshot; a magnifier next to the cursor
shows the exact pixel and its value. Esc cancels.
- **Cast Key** – the key the *Fishing* spell is on in your action bar (default `0`).
Names follow pyautogui: `0`–`9`, `a`–`z`, `f1`–`f12`, `num0`–`num9`, …
- **Threshold Bobber / Threshold Catch** – per-channel RGB tolerance for finding the bobber and for detecting a bite.
- **Jump to Bobber** – keep the cursor on the bobber while waiting; otherwise it returns to where it was after reeling in.
- **Start / Stop** – run the fishing loop in the background.
- **Status LED** – next to the title: Casting, Searching bobber, Waiting for bite, Bite! Reeling
in, then the result of the round (Caught, Missed, No bobber).
- **Last rounds** – the last 30 rounds as dots: green caught, orange missed, red no bobber.
Many orange dots usually mean *Threshold Catch* is too high, many red ones that the colour,
*Threshold Bobber* or the area does not fit.
- **Bite Meter** – live graph of how much the watched pixel changes. The dashed line is
*Threshold Catch*; click or drag in the graph to move it. Thresholds stay editable while
fishing so you can tune them live.
- **Statistics** – casts, catches, misses, catch rate, fish per hour and fishing time for the
*Session* (since the program started, over all Start/Stop runs), *Today* and *Total*.
Daily numbers are kept in `stats.json` next to `config.json`.
- **Log** – the latest messages; enable *Verbose Log* for every search and bite detail.
- **Compact / Expand** – a small view with Start/Stop, stats and the bite meter, meant to sit
beside the game in windowed mode. Start switches to it automatically and the previous view
returns when the session ends. Each view remembers its own window position.
- **Dark / Light** – switches the colour theme (the first start follows the system setting).

Keep this window out of the fishing area: the cast clicks into the area to focus the game, so
a window covering it swallows the click. Start refuses to run while the window overlaps it.

To stop the headless version press **Ctrl+C**. In both modes moving the mouse
into a screen corner triggers the emergency stop.
Expand All @@ -73,6 +94,10 @@ Settings are saved automatically to a per-user file:
| macOS | `~/Library/Application Support/getthefish/config.json` |
| Linux | `$XDG_CONFIG_HOME/getthefish/config.json` (default `~/.config/...`) |

The same folder holds `getthefish.log`, the daily statistics (`stats.json`) and
the window preferences (`window.ini`: theme, view, window positions). The
*Open Config/Logs Folder* button opens it.

Set `GETTHEFISH_CONFIG` or pass `--config` to use another file. A
`config.json` from older versions in the current directory is imported
automatically on first start. See [`config.example.json`](config.example.json).
Expand Down Expand Up @@ -104,7 +129,7 @@ by the right-click.

## Troubleshooting

Enable **verbose** in the GUI (or run `getthefish -v`) and check the log file
Enable **Verbose Log** in the GUI (or run `getthefish -v`) and check the log file
`getthefish.log` in the same folder as `config.json`. Each cast logs, for example:

```
Expand All @@ -113,6 +138,10 @@ Watching pixel 643, 217 with colour (74, 40, 13)
No bite within 20s: largest colour change was 41, threshold_catch is 60
```

- **Nothing is cast, then "Bobber not found" three times** – something covers
the top-left corner of the area, where the cast clicks to focus the game
(often this window). Move it beside the game; Start checks this for its own
window.
- **Set the area over water only.** Dark wood (boat), the character and UI
bars contain the same dark red/brown as the bobber; if they are inside the
area the bot locks onto them and never sees a bite.
Expand All @@ -137,8 +166,12 @@ src/getthefish/
├── detection.py # pure numpy colour detection
├── devices.py # screen capture (mss) and mouse (pyautogui) adapters
├── logs.py # console + log file setup
├── tally.py # statistics and the per-day history (stats.json)
└── gui/
├── main_window.py # PySide6 GUI
├── main_window.py # main window, colour picker and area selector
├── widgets.py # status LED, bite meter, round history, log bridge
├── theme.py # light and dark theme
├── icon.py # application icon (also writes the .ico for the exe)
├── main.ui # Qt Designer source
└── ui_main.py # generated from main.ui
tests/ # pytest suite (no real screen or mouse needed)
Expand All @@ -161,6 +194,12 @@ CI runs them on Windows for every push and pull request. Pushing a tag like

`uv.lock` is the committed, cross-platform dependency lockfile.

After editing `main.ui` in Qt Designer, regenerate the Python code:

```bash
uv run pyside6-uic src/getthefish/gui/main.ui -o src/getthefish/gui/ui_main.py
```

## License

MIT – see [LICENSE](LICENSE).
59 changes: 58 additions & 1 deletion src/getthefish/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import threading
import time
from collections.abc import Callable
from dataclasses import dataclass
from dataclasses import dataclass, replace
from enum import StrEnum

from getthefish.config import FishConfig, Point
from getthefish.detection import find_color
Expand Down Expand Up @@ -44,6 +45,47 @@ class Stats:
misses: int = 0


class Phase(StrEnum):
"""The step of a round the fishing loop is in."""

CASTING = "casting"
SEARCHING = "searching"
WAITING = "waiting"
REELING = "reeling"


@dataclass(frozen=True)
class PhaseChanged:
phase: Phase


@dataclass(frozen=True)
class BobberFound:
"""The bobber landed at ``position``; ``watch`` is the pixel observed for a bite."""

position: Point
watch: Point


@dataclass(frozen=True)
class BiteSample:
"""Largest per-channel change of the watched pixel since the bobber landed."""

change: int


@dataclass(frozen=True)
class RoundFinished:
"""One round is over: True (caught), False (missed) or None (no bobber / error)."""

result: bool | None
stats: Stats


Event = PhaseChanged | BobberFound | BiteSample | RoundFinished
"""Live data for a UI; sent from the fishing thread."""


class GetTheFish:
"""Runs the fishing loop until :meth:`stop` is called or it gives up.

Expand All @@ -58,13 +100,15 @@ def __init__(
timing: Timing | None = None,
on_status: Callable[[str], None] | None = None,
rng: random.Random | None = None,
on_event: Callable[[Event], None] | None = None,
) -> None:
self.config = config
self.screen = screen
self.mouse = mouse
self.timing = timing or Timing()
self.stats = Stats()
self._on_status = on_status
self.on_event = on_event
self._rng = rng or random.Random() # noqa: S311 - timing jitter, not crypto
self._stop = threading.Event()

Expand All @@ -83,6 +127,10 @@ def _status(self, text: str, *, verbose_only: bool = False) -> None:
if self._on_status is not None:
self._on_status(text)

def _emit(self, event: Event) -> None:
if self.on_event is not None:
self.on_event(event)

def _sleep(self, delay: Range | float) -> bool:
"""Interruptible sleep. Returns False if stop was requested."""
seconds = self._rng.uniform(*delay) if isinstance(delay, tuple) else delay
Expand All @@ -95,13 +143,15 @@ def cast(self) -> None:
is the GUI right after clicking Start. Left-click on water is harmless in
the game (right-click could trigger click-to-move).
"""
self._emit(PhaseChanged(Phase.CASTING))
self.mouse.move_to(self.config.start_pos)
self.mouse.left_click()
self.mouse.press(self.config.cast_key)
self.stats.casts += 1

def find_bobber(self) -> Point | None:
"""Search the configured area; returns absolute screen coordinates."""
self._emit(PhaseChanged(Phase.SEARCHING))
left, top, right, bottom = self.config.search_area
for attempt in range(1, self.config.max_attempts + 1):
self._status(
Expand Down Expand Up @@ -135,6 +185,7 @@ def wait_for_bite(self, watch: Point) -> bool:
while time.monotonic() < deadline:
current = self._pixel(watch)
change = max(abs(a - b) for a, b in zip(current, initial, strict=True))
self._emit(BiteSample(change))
if change > self.config.threshold_catch:
self._status(
f"Bite: colour {initial} -> {current} (change {change} > "
Expand Down Expand Up @@ -168,12 +219,17 @@ def fish_once(self) -> bool | None:
if bobber is None:
return None
watch = Point(bobber.x + BITE_WATCH_OFFSET.x, bobber.y + BITE_WATCH_OFFSET.y)
self._emit(BobberFound(bobber, watch))
self._emit(PhaseChanged(Phase.WAITING))
if self.config.jump_to_bobber:
self.mouse.move_to(watch)
if not self.wait_for_bite(watch):
if not self.is_running:
return False
self.stats.misses += 1
self._status("No bite, recasting", verbose_only=True)
return False
self._emit(PhaseChanged(Phase.REELING))
if not self._sleep(self.timing.before_catch):
return False
self.reel_in(watch)
Expand All @@ -198,6 +254,7 @@ def run(self) -> None:
except Exception as e:
logger.exception("Unexpected error in fishing round")
result, problem = None, f"Error: {e}"
self._emit(RoundFinished(result, replace(self.stats)))
if result is not None:
failures = 0
self._sleep(self.timing.after_round)
Expand Down
89 changes: 89 additions & 0 deletions src/getthefish/gui/icon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""The application icon, drawn in code so the window, the taskbar and the exe share one source.

``python -m getthefish.gui.icon OUT.ico`` writes it as a multi-size Windows icon (used by the
release build for the exe).
"""

from __future__ import annotations

import struct
import sys
from pathlib import Path

from PySide6.QtCore import QBuffer, QByteArray, QIODevice, QPointF, QRectF, Qt
from PySide6.QtGui import QColor, QGuiApplication, QIcon, QImage, QLinearGradient, QPainter, QPixmap

SIZES = (16, 24, 32, 48, 64, 128, 256)


def render(size: int) -> QImage:
"""The icon at ``size`` x ``size`` pixels, drawn on a 64-unit grid."""
image = QImage(size, size, QImage.Format.Format_ARGB32_Premultiplied)
image.fill(Qt.GlobalColor.transparent)
p = QPainter(image)
p.setRenderHint(QPainter.RenderHint.Antialiasing)
p.scale(size / 64, size / 64)

background = QLinearGradient(0, 2, 0, 62)
background.setColorAt(0, QColor("#4f8cff"))
background.setColorAt(1, QColor("#1d4ed8"))
p.setPen(Qt.PenStyle.NoPen)
p.setBrush(background)
p.drawRoundedRect(QRectF(2, 2, 60, 60), 14, 14)

white = QColor("white")
p.setBrush(white)
p.drawEllipse(QRectF(10, 25, 34, 20)) # body
p.drawPolygon([QPointF(40, 35), QPointF(54, 25), QPointF(51, 35), QPointF(54, 45)]) # tail
p.setBrush(QColor("#1d4ed8"))
p.drawEllipse(QPointF(19, 33), 2.4, 2.4) # eye
bubble = QColor(255, 255, 255, 170)
p.setBrush(bubble)
p.drawEllipse(QPointF(15, 18), 2.6, 2.6)
p.drawEllipse(QPointF(21, 12), 1.7, 1.7)
p.end()
return image


def app_icon() -> QIcon:
icon = QIcon()
for size in SIZES:
icon.addPixmap(QPixmap.fromImage(render(size)))
return icon


def _png(image: QImage) -> bytes:
data = QByteArray()
buffer = QBuffer(data)
buffer.open(QIODevice.OpenModeFlag.WriteOnly)
image.save(buffer, "PNG") # type: ignore[call-overload] # stubs say bytes, runtime wants str
return bytes(data.data())


def ico_bytes(sizes: tuple[int, ...] = SIZES) -> bytes:
"""A Windows .ico with one PNG-compressed image per size."""
images = [_png(render(size)) for size in sizes]
header = struct.pack("<HHH", 0, 1, len(images))
offset = len(header) + 16 * len(images)
entries = b""
for size, png in zip(sizes, images, strict=True):
dim = 0 if size >= 256 else size # 0 means 256 in the ICO directory
entries += struct.pack("<BBBBHHII", dim, dim, 0, 0, 1, 32, len(png), offset)
offset += len(png)
return header + entries + b"".join(images)


def main(argv: list[str]) -> int:
if len(argv) != 2:
print("usage: python -m getthefish.gui.icon OUT.ico", file=sys.stderr)
return 2
app = QGuiApplication.instance() or QGuiApplication([argv[0], "-platform", "offscreen"])
assert app is not None
out = Path(argv[1])
out.parent.mkdir(parents=True, exist_ok=True)
out.write_bytes(ico_bytes())
return 0


if __name__ == "__main__":
sys.exit(main(sys.argv))
Loading