Skip to content

Refactor golf features, improve UI handling, and enhance capture reliability - #101

Merged
primetime43 merged 7 commits into
mainfrom
develop
Jul 31, 2026
Merged

primetime43 merged 7 commits into
mainfrom
develop

Conversation

@primetime43

Copy link
Copy Markdown
Owner

This pull request introduces several improvements and fixes to the Toontown Rewritten Bot, focusing on more robust handling of custom golf actions, improved coordinate management, and general code quality. It also updates the version to 2.7.0.0 and adds a warning about bot usage risks.

Golf Actions and File Handling Improvements:

  • Added stricter validation and error handling when loading custom golf action files, ensuring files are valid and contain required actions. Errors are now surfaced to the user more clearly, and the golf action loader no longer uses Newtonsoft.Json directly, relying on a utility for loading and validation. [1] [2] [3]
  • Custom golf actions now always use foreground input (disabling background input temporarily) for reliability, and key up events are always sent, even if actions are interrupted. [1] [2] [3]

Coordinate and UI Element Management:

  • Improved synchronization and validation of manual coordinates for UI elements, preventing stale or invalid data from causing incorrect behavior. Now, manual coordinates are cleared if not found, and out-of-window coordinates are rejected and prompt for recapture.
  • Updated the default Red Fishing Button entry in UIElementCoordinates.json to have null manual and cached coordinates, reflecting the new handling.

General Enhancements and Housekeeping:

  • Changed the app's DPI mode to PerMonitorV2 for better high-DPI support.
  • Added a prominent warning to the README.md about the risks of bot usage and Toontown Rewritten's policies.
  • Updated the version to 2.7.0.0 in both the project and assembly info files. [1] [2]
  • Simplified and improved duration formatting to always use up to three decimals and invariant culture. [1] [2]

Other Code Quality Improvements:

  • Removed unnecessary Newtonsoft.Json usings from several files. [1] [2]
  • Improved status reporting for auto-golf overlays and main status labels. [1] [2]

These changes collectively improve reliability, user feedback, and maintainability of the bot.

Replace manual character-by-character numeric extraction with Regex-based parsing for robustness. FormatSeconds now uses up to 3 decimal places instead of conditionally rounding. ParseToMilliseconds uses word-boundary regex for ms/s unit detection, validates range/NaN/Infinity, and uses MidpointRounding.AwayFromZero. CustomFishingActions now correctly converts the display value back to milliseconds when populating the time input.
- Replace hardcoded CTRL swing key references with the user-configured Jump key, shown dynamically in all golf dialogs and the instructions label
- Refresh golf instructions label when game controls are changed in Settings
- Switch key simulation from raw InputSimulator calls to CoreFunctionality.SendKeyDown/Up so remapped keys are used correctly
- Temporarily disable background input mode during golf actions (foreground SendInput required)
- Wrap async key holds in try/finally to guarantee key release on cancellation
- Add pre-flight validation before starting golf: checks for TTR window, empty/invalid action files, and missing SWING POWER action
- Route golf action file loading through CustomGolfActionFileManager in both GolfService and CustomActionsGolf
- Remove swallowed exception catch in GolfService.StartGolfAsync so errors surface properly
Refactor IsReadyToSwing to search only the top-right region instead of the full window, reducing false positives from orange course graphics. Add multi-variant template support, require two consecutive detections before confirming a turn, and restrict color fallback to timer-only region when no template is saved. Improve PromptForTurnTimerTemplate to support recapture with a Yes/No dialog and return whether a template was saved. Propagate detector status changes to the main status label in GolfService.
Keep UIElementManager's manual fallback data in sync with the legacy coordinate file so Reset State actually clears stale positions. Manual element coordinates are now treated as absolute screen points, invalid manual values outside the game window are discarded and re-searched, and failures now direct the user to recapture the template instead of silently falling back.
Introduces a dedicated `WindowCaptureException` and hardens screenshot capture when `PrintWindow` returns unusable black frames. `ImageRecognition` now retries `PrintWindow` with alternate flags, detects effectively black captures via grid sampling, falls back to visible screen capture when needed, and emits a one-time warning when background capture is unavailable. It also adds explicit minimized-window and invalid-bounds failure messages. Fish and golf detectors were updated to rethrow `WindowCaptureException` instead of swallowing it in generic handlers, so capture failures surface correctly.
- Switch DPI mode to PerMonitorV2 for sharper rendering on high-DPI displays
- GlobalKeyboardHook.Start() now returns bool and exposes LastErrorCode; callers show actionable error dialogs on failure
- Custom fishing recorders show warnings when nothing was recorded and restore the window before showing dialogs
- Key-to-action mapping delegates to GameControls.GetMovementAction() so custom bindings are respected instead of hardcoding arrow keys
- Add GetMovementBindingSummary() helper and update recorder UI labels to show the active bindings
- Update Random Variance tooltip to clarify it does not provide ban protection
- Add README warning about automation policy risks
- Fix 'black frame' log messages to say 'blank frame'; add uniform-frame detection to PrintWindow fallback logic
Update to version 2.7.0
@primetime43
primetime43 merged commit f928bf3 into main Jul 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant