Skip to content

Instantly share code, notes, and snippets.

@Sniffx
Forked from A2TC-YT/auto_fishing.ahk
Last active January 27, 2024 20:11
Show Gist options
  • Save Sniffx/ee5ae43d42894a6499c24b66586cc10c to your computer and use it in GitHub Desktop.
Save Sniffx/ee5ae43d42894a6499c24b66586cc10c to your computer and use it in GitHub Desktop.
afk fishing macro for destiny 2. You will need to install the Gdip_all library which you can find here: https://www.autohotkey.com/boards/viewtopic.php?t=6517 and the virtual controller from here: https://github.com/A2TC-YT/Tabbed-Out-AFK
;afk fishing macro for destiny 2. You will need to install the Gdip_all library which you can find here: https://www.autohotkey.com/boards/viewtopic.php?t=6517
;The virtual controller from the instructions here: https://github.com/A2TC-YT/Tabbed-Out-AFK
;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"
;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, like use the browser.
#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%\Gdip_all.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
pToken := Gdip_Startup() ;Initialize capture image zone script (Gdip_all.ahk)
F5:: ;Start fishing when pressing F5
{
WinGetPos, xWindowPos, yWindowPos, wWindowWidth, hWindowHeight, ahk_exe destiny2.exe ;Get the position and size of "Destiny 2"
xOriginalWindowPos:=6
yOriginalWindowPos:=1400
xOriginalCaptureZone:=638
yOriginalCaptureZone:=1924
xCaptureZone:= xOriginalCaptureZone + xWindowPos - xOriginalWindowPos
yCaptureZone:= yOriginalCaptureZone + yWindowPos - yOriginalWindowPos
coords:= xCaptureZone "|" yCaptureZone "|24|12" ;Coordinates and size of the image we will use to check if we must cast or recover the fishing line.
width := 24
height := 13
threshold := 0.03 ; We look for White stuff to determine if we can cast or recover the fishing line like the words "Go fishing" or "Perfect catch"
; a higher threshold like 0.12 helps with false positives like identifying the white "vex milk" as the white words.
; a lower threshold like 0.03 is useful in Nexus
Gosub, CheckCapsState ; If keyboard "Capslock" is enabled, disable it. Don't know why but when it is enabled AHK scripts behave weird in Destiny 2
controller.Buttons.Square.SetState(true) ;Initial fishing cast using the virtual gamepad. Equivalent to pressing the button "E" on the keyboard.
Sleep, 800 ; DO NOT CHANGE
controller.Buttons.Square.SetState(false) ;We release the button. Equivalent to stop touching the "E" key on the keyboard.
Sleep, 250
StartTime := A_TickCount ;measures how much time it takes to do 1 loop ;Time every loop
timeloop:=A_TickCount ;measures how much time it takes to do 1 loop ;Time every loop
Loop,
{
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
ElapsedTime2 := FormatSeconds2(ElapsedSeconds) ;measures how much time it takes to do 1 loop ;Time every loop
xToolTipPos:= xWindowPos + 16
yToolTipPos:= yWindowPos + hWindowHeight -42
ToolTip, Enabled: %ElapsedTime% - Loop: %A_Index% , xToolTipPos, yToolTipPos ;Tooltip at the botton-left of the Destiny 2 window where it shows the script is active and during how much time.
loop,
{
pBitmap := Gdip_BitmapFromScreen(coords) ;Capture a region of the screen
pWhite := simpleColorCheck(pBitmap, width, height) ;Check for White on that captured region
Gdip_DisposeImage(pBitmap) ;release the memory used for the captured region
if (pWhite >= threshold) ;Check if we found enough whiteness
Break ;YES! We found whiteness so we interrupt this loop to cast or recover the fishing line
}
controller.Buttons.Square.SetState(true) ;Cast or recover the fishing line
Sleep, 800
controller.Buttons.Square.SetState(false) ;Cast or recover the fishing line
ElapsedMS := A_TickCount - timeloop ;Time every loop
timeloop := A_TickCount ;Time every loop
if (Mod(A_Index,5)=0 ){ ;ANTI AFK stuff. Every few iterations we slightly move left or right to avoid being kicked AND getting fish nearby us. There is a limit of fish on the ground.
sleep, 2500 ;That limit is around 60? If more fish is on the ground, old fish gets despawned .
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. 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
}
}
}
Return
simpleColorCheck(pBitmap, w, h) ;Function to check for white stuff
{
x := 0
y := 0
white := 0
total := 0
loop %h%
{
loop %w%
{
color := (Gdip_GetPixel(pBitmap, x, y) & 0x00F0F0F0)
if (color == 0xF0F0F0)
white += 1
total += 1
x+= 1
}
x := 0
y += 1
}
pWhite := white/total
return pWhite
}
F6::Reload ;Stop fishing when pressing F6
F8::ExitApp ;Stop fishing AND exit "auto_fishing.ahk"
;==================================================
;Helper Functions
CheckCapsState:
bCapsLockState := GetKeyState("Capslock", "T") ; 1 if CapsLock is ON, 0 otherwise.
IF (bCapsLockState== 1) {
SetCapsLockState OFF
sleep, 500
send, {Esc}
sleep 500
}
return
;==================================================
RemoveToolTip:
ToolTip
return
;==================================================
;==================================================
CreateToolTip(sMsg,delay:=0,xCoord:=1,yCoord:=720){
Tooltip, %sMsg%, xCoord,yCoord
SetTimer, RemoveToolTip, -1500
sleep, %delay%
}
;==================================================
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.
}
;==================================================
FormatSeconds2(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
return NumberOfSeconds//3600 "h" mmss ; This method is used to support more than 24 hours worth of sections.
}
;==================================================
CommaAdd(num)
{
VarSetCapacity(fNum,32)
DllCall("GetNumberFormat",UInt,0x0409,UInt,0,Str,Num,UInt,0,Str,fNum,Int,32)
return SubStr(fNum,1,StrLen(fNum) - 3)
}
@Revadike
Copy link

Anyway, I wonder if it's possible to take a screenshot using the controller and analyze that instead. I know the game on PC lets u take screenshots using any key you want by editing cvars.xml (in appdata). Not sure about the controller.

@SBP1213
Copy link

SBP1213 commented Jun 23, 2023

Few things that may answer peoples problems here...

  1. You will need AHK v1.xxx
  2. If you have multiple AHK versions installed, Open AHK, Select launch settings, select run all scripts with a specific interpreter and use C:\Program Files\AutoHotkey**v1.(YOURVERSIONHERE)**\AutoHotkeyU64.exe
  3. Tabbed-Out-AFK comes with 3 main files in a LIB folder you care about, AHK-ViGEM-BUS.ahk, CLR,ahk, and ViGEmWrapper.dll, right click each and go to properties. Depending on version of windows you may see at the bottom of the general tab something about the file being downloaded from the internet, select unblock and apply/ok.
  4. Navigate to C:\Program Files\AutoHotkey**v1.(YOURVERSIONHERE)**\ and copy the entire LIB folder here
  5. If youre having issues where nothing is happening, there is a chance PS4 Emulator isnt launching try replacing the following lines in auto_fishing.ahk

controller := new ViGEmDS4()
to
controller := new ViGEmXb360()

and

controller.Buttons.Square.SetState(true) ;Initial fishing cast using the virtual gamepad. Equivalent to pressing the button "E" on the keyboard.
Sleep, 800 ; DO NOT CHANGE
controller.Buttons.Square.SetState(false) ;We release the button. Equivalent to stop touching the "E" key on the keyboard.
Sleep, 250 

to

`controller.Buttons.X.SetState(true) ;Initial fishing cast using the virtual gamepad. Equivalent to pressing the button "E" on the keyboard.
Sleep, 800 ; DO NOT CHANGE
controller.Buttons.X.SetState(false) ;We release the button. Equivalent to stop touching the "E" key on the keyboard.
Sleep, 250 `

@Sniffx
Copy link
Author

Sniffx commented Jun 23, 2023

I adapted AmJustS (https://gist.github.com/AmJustS/d1eff6b0f78a48d99868c224e5dbbaaf) fishing script to be used in window mode and virtual gamepad.
Original A2TC-YT script is good enough (1000fish captured with it) but new AmJustS script is better imo (3000 fish captured). It almost never fails to catch a fish (maybe 1 fail per hour fishing), they are always "perfect catch!":
https://gist.github.com/Sniffx/da7b3eb0e13211eb15a9114c89674ebe

@Revadike
Copy link

I adapted AmJustS (AmJustS/d1eff6b0f78a48d99868c224e5dbbaaf) fishing script to be used in window mode and virtual gamepad. Original A2TC-YT script is good enough (1000fish captured with it) but new AmJustS script is better imo (3000 fish captured). It almost never fails to catch a fish (maybe 1 fail per hour fishing), they are always "perfect catch!": Sniffx/da7b3eb0e13211eb15a9114c89674ebe

Can you use it in a virtual desktop?

@mrIncoder
Copy link

#MaxThreadsPerHotKey, 2
Toggle := 0

F1::
Toggle := !Toggle

While (Toggle) {

Click

Sleep, 3000

Click

Sleep, 100

PixelSearch, tap, tapy, 1497, 233, 1430, 842, 0x000000, 1, fast, RGB

If (tapX) {
                        
    While (tapX && Toggle) {
          
        Click
                       
        Sleep, 10
         
        PixelSearch, tapX, tapY, 1497, 233, 1430, 842, 0x000000, 1, fast, RGB
    }
}

}

@mrIncoder
Copy link

your welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment