Last active
August 13, 2023 16:47
-
-
Save Sniffx/da7b3eb0e13211eb15a9114c89674ebe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;afk fishing macro for destiny 2. You will need to install ShinsImageScanClass.ahk from here: https://github.com/Spawnova/ShinsImageScanClass | |
;The virtual controller from the instructions here: https://github.com/A2TC-YT/Tabbed-Out-AFK | |
;Based on this fishing script: https://gist.github.com/AmJustS/d1eff6b0f78a48d99868c224e5dbbaaf | |
;F5 Starts the script | |
;F6 Stops the script | |
;F8 Completely exits the script | |
;Destiny 2 "Window Mode" must be set to "Windowed" | |
;Destiny 2 "Resolution" must be set to "1280x720" | |
;Destiny 2 "Brightness" to level to 7 | |
;Disable Steam Controller config to avoid phantom keypresses in other windows app while the script is running: | |
;https://i.imgur.com/ovFV898.jpg | |
;You can put Destiny 2 window anywhere but it must be visible. It must not be covered by any other window (at least not the center of the window where we check for fish). | |
;You can do anything else while you fish. | |
;Note:Don't move the mouse while Destiny 2 window has the focus or it disables the virtual gamepad | |
;Lines that start with ";" are disabled or they are comments. | |
#SingleInstance, Force ;Only 1 "auto_fishing.ahk" can run at the same time | |
#Persistent | |
#include <AHK-ViGEm-Bus> ;Needed for PS4 controller support | |
#Include %A_ScriptDir%\ShinsImageScanClass.ahk ;Needed for image comparation support | |
SendMode Input | |
SetWorkingDir, %A_ScriptDir% | |
CoordMode, ToolTip, Screen ;for tooltip position | |
controller := new ViGEmDS4() ;Create a new virtual PS4 controller | |
Scan := new ShinsImageScanClass ;Initialize capture image zone script | |
CounterTooltip:=0 | |
gosub ActivarDestiny ;Focus Destiny 2 window | |
Pause | |
F5:: ;Start fishing when pressing F5 | |
;;Using the mouse while inside Destiny2 window disables the virtual gamepad | |
;;To avoid that, we should focus another window as soon as we press F5. | |
WinActivate, ahk_class MozillaWindowClass ;Focus Firefox browser | |
sleep, 250 | |
WinActivate, ahk_class MozillaWindowClass ;Focus Firefox brower for real | |
sleep, 250 | |
StartTime := A_TickCount ;measures how much time it takes to do 1 loop | |
timeloop:=A_TickCount ;measures how much time it takes to do 1 loop ;Time every loop | |
WinGetPos, xWindowPos, yWindowPos, wWindowWidth, hWindowHeight, ahk_exe destiny2.exe ;Get the position and size of "Destiny 2" | |
xOriginalWindowPos:=6 ;my Destiny 2 1280x720 window location on my screen | |
yOriginalWindowPos:=1400 | |
xOriginalCaptureZone:=603 ;my capture zone | |
yOriginalCaptureZone:=1926 | |
xCaptureZone:= xOriginalCaptureZone + xWindowPos - xOriginalWindowPos ;Capture zone based on a 1280x720 Destiny 2 window placed anywhere on the screen. | |
yCaptureZone:= yOriginalCaptureZone + yWindowPos - yOriginalWindowPos | |
controller.Buttons.Square.SetState(true) ;Cast the 1st fishing rod | |
Sleep, 800 | |
controller.Buttons.Square.SetState(false) | |
Pause | |
Toggle := !Toggle | |
if (Toggle) | |
{ | |
SetTimer, PressE, 100 | |
} else | |
{ | |
SetTimer, PressE, Off | |
SetTimer, Scan, Off | |
} | |
Return | |
F6::Reload ;Stop fishing when pressing F6 | |
F8::ExitApp ;Stop fishing AND exit "auto_fishing.ahk" | |
PressE: | |
SetTimer, PressE, Off | |
Sleep, 2000 | |
controller.Buttons.Square.SetState(true) ;Cast the fishing rod | |
Sleep, 2500 | |
controller.Buttons.Square.SetState(false) | |
SetTimer, Scan, 30 | |
return | |
Scan: | |
PixelCount:=scan.PixelCountregion(0xE098C6,xCaptureZone,yCaptureZone,15,15) ;0xE098C6 =magenta = Square icon from ps4 | |
If ( PixelCount> 5) | |
{ | |
controller.Buttons.Square.SetState(true) ;Cast the fishing rod | |
Sleep, 800 | |
controller.Buttons.Square.SetState(false) | |
SetTimer, Scan, Off | |
CountAFK += 1 | |
CounterTooltip += 1 | |
ElapsedSeconds := round((A_TickCount - StartTime) / 1000) ;measures how much time it takes to do 1 loop ;Time every loop | |
ElapsedMinutes := round(elapsedseconds /60) ;measures how much time it takes to do 1 loop ;Time every loop | |
ElapsedTime := FormatSeconds(ElapsedSeconds) ;measures how much time it takes to do 1 loop ;Time every loop | |
AvgSecondsLoop:= round(ElapsedSeconds / CounterTooltip) ;#[Destiny Fishing] | |
xToolTipPos:= xWindowPos + 16 | |
yToolTipPos:= yWindowPos + hWindowHeight -42 | |
ToolTip, Enabled: %ElapsedTime% - Loop: %CounterTooltip% - AVG: %AvgSecondsLoop%s, xToolTipPos, yToolTipPos ;Tooltip at the botton-left of the Destiny 2 window where it shows the script is active and during how much time. | |
; Anti AFK measures | |
If CountAFK = 10 | |
{ | |
Sleep, 5000 | |
controller.Buttons.Square.SetState(true) ;Slightly press a virtual controller button so the game recognized there is controller connected. | |
Sleep, 100 | |
controller.Buttons.Square.SetState(false) ;Release slightly pressed button | |
sleep, 150 ;Note: If we don't do this, Destiny 2 doesnt recognize the below lines that we use to move left or right, at least on my machine. Super weird OoO | |
controller.Axes.LX.SetState(100) ; Slightly move left | |
sleep 100 | |
controller.Axes.LX.SetState(50) ; Stop moving | |
sleep 150 | |
controller.Axes.LX.SetState(0) ; Slightly move Right | |
sleep 100 | |
controller.Axes.LX.SetState(50) ; Stop moving | |
CountAFK = 0 | |
} | |
ElapsedMS := A_TickCount - timeloop ;Time every loop | |
timeloop := A_TickCount ;Time every | |
SetTimer, PressE, 100 | |
} | |
Return | |
;================================================== | |
;Helper Functions | |
;================================================== | |
ActivarDestiny: | |
WinActivate, Destiny 2 | |
sleep, 250 | |
return | |
;================================================== | |
FormatSeconds(NumberOfSeconds) ; Convert the specified number of seconds to hh:mm:ss format. | |
{ | |
time = 19990101 ; *Midnight* of an arbitrary date. | |
time += %NumberOfSeconds%, seconds | |
FormatTime, mmss, %time%, mm:ss | |
return NumberOfSeconds//3600 ":" mmss ; This method is used to support more than 24 hours worth of sections. | |
} | |
I didn't try it but I bet game's native screenshot would be too slow so we would miss all fish.
Yes, I have brightness level to 7. Forgot to put it in the requirement notes, oops :p
Btw, if weird things happens while the script is running like phantom keypresses, disable Steam Controller config like here:
https://i.imgur.com/ovFV898.jpg
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to set my brightness to max (7) for it to work well (in nessus)