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
  • Select an option

  • Save Sniffx/ee5ae43d42894a6499c24b66586cc10c to your computer and use it in GitHub Desktop.

Select an option

Save Sniffx/ee5ae43d42894a6499c24b66586cc10c to your computer and use it in GitHub Desktop.

Revisions

  1. Sniffx revised this gist Jun 8, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -60,8 +60,8 @@ F5:: ;Start fishing when pressing F5
    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
    yToolTipPos:= yWindowPos + hWindowHeight
    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,
  2. Sniffx revised this gist Jun 8, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@

    SendMode Input
    SetWorkingDir, %A_ScriptDir%
    CoordMode, ToolTip, Screen
    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)
  3. Sniffx revised this gist Jun 8, 2023. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,16 @@
    ;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
  4. Sniffx revised this gist Jun 8, 2023. No changes.
  5. Sniffx revised this gist Jun 8, 2023. No changes.
  6. Sniffx revised this gist Jun 8, 2023. No changes.
  7. Sniffx revised this gist Jun 8, 2023. No changes.
  8. Sniffx revised this gist Jun 8, 2023. No changes.
  9. Sniffx revised this gist Jun 8, 2023. No changes.
  10. Sniffx revised this gist Jun 8, 2023. 1 changed file with 156 additions and 65 deletions.
    221 changes: 156 additions & 65 deletions auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -1,78 +1,169 @@
    #SingleInstance, Force
    #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

    global 1080p := 0
    MsgBox, ***READ BEFORE USING***`nMake sure you are on 7 brightness, chromatic abberation is off, and hud opacity is max. Make sure you have interact bound to "E". Press F3 to start and F4 to stop. Does NOT work on Nessus.

    InputBox, 1080p, Resolution, If your computer monitor resolution is 1440p enter 0`nIf your computer monitor is 1080p enter 1

    pToken := Gdip_Startup()
    controller := new ViGEmDS4() ;Create a new virtual PS4 controller
    pToken := Gdip_Startup() ;Initialize capture image zone script (Gdip_all.ahk)

    F3::
    F5:: ;Start fishing when pressing F5
    {
    coords := "1243|971|37|21"
    width := 37
    height := 21
    threshold := 0.16
    if (1080p)
    {
    coords := "932|728|27|16"
    width := 27
    height := 16
    threshold := 0.12
    }
    Loop,
    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
    yToolTipPos:= yWindowPos + hWindowHeight
    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)
    pWhite := simpleColorCheck(pBitmap, width, height)
    Gdip_DisposeImage(pBitmap)
    if (pWhite >= threshold)
    Break
    }
    Send, {e down}
    Sleep, 800
    Send, {e Up}
    DllCall("mouse_event",uint,1,int,-300,int,0,uint,0,int,0)
    Sleep, 200
    DllCall("mouse_event",uint,1,int,300,int,0,uint,0,int,0)
    Send, {d Down}
    Sleep, 100
    Send, {d Up}
    Sleep, 100
    Send, {a Down}
    Sleep, 100
    Send, {a Up}
    }
    }
    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
    }

    simpleColorCheck(pBitmap, w, h)
    {
    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

    F4::Reload
    F8::ExitApp ;Stop fishing AND exit "auto_fishing.ahk"

    #Include %A_ScriptDir%\Gdip_all.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)
    }
  11. @A2TC-YT A2TC-YT revised this gist May 24, 2023. 1 changed file with 20 additions and 6 deletions.
    26 changes: 20 additions & 6 deletions auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,35 @@
    #SingleInstance, Force
    SendMode Input
    SetWorkingDir, %A_ScriptDir%

    MsgBox, ***READ BEFORE USING***`nYou must have a 1440p screen for this to work. Make sure you are on 7 brightness, chromatic abberation is off, and hud opacity is max. Make sure you have interact bound to "E". Press F3 to start and F4 to stop. Does NOT work on Nessus.


    global 1080p := 0
    MsgBox, ***READ BEFORE USING***`nMake sure you are on 7 brightness, chromatic abberation is off, and hud opacity is max. Make sure you have interact bound to "E". Press F3 to start and F4 to stop. Does NOT work on Nessus.

    InputBox, 1080p, Resolution, If your computer monitor resolution is 1440p enter 0`nIf your computer monitor is 1080p enter 1

    pToken := Gdip_Startup()

    F3::
    {
    coords := "1243|971|37|21"
    width := 37
    height := 21
    threshold := 0.16
    if (1080p)
    {
    coords := "932|728|27|16"
    width := 27
    height := 16
    threshold := 0.12
    }
    Loop,
    {
    loop,
    {
    pBitmap := Gdip_BitmapFromScreen("1243|971|37|21")
    pWhite := simpleColorCheck(pBitmap, 37, 21)
    pBitmap := Gdip_BitmapFromScreen(coords)
    pWhite := simpleColorCheck(pBitmap, width, height)
    Gdip_DisposeImage(pBitmap)
    if (pWhite >= 0.15)
    if (pWhite >= threshold)
    Break
    }
    Send, {e down}
  12. @A2TC-YT A2TC-YT revised this gist May 24, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -61,4 +61,4 @@ simpleColorCheck(pBitmap, w, h)

    F4::Reload

    #Include <Gdip_all>
    #Include %A_ScriptDir%\Gdip_all.ahk
  13. @A2TC-YT A2TC-YT revised this gist May 24, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -21,9 +21,9 @@ F3::
    Send, {e down}
    Sleep, 800
    Send, {e Up}
    DllCall("mouse_event",uint,1,int,-1870,int,0,uint,0,int,0)
    DllCall("mouse_event",uint,1,int,-300,int,0,uint,0,int,0)
    Sleep, 200
    DllCall("mouse_event",uint,1,int,1870,int,0,uint,0,int,0)
    DllCall("mouse_event",uint,1,int,300,int,0,uint,0,int,0)
    Send, {d Down}
    Sleep, 100
    Send, {d Up}
  14. @A2TC-YT A2TC-YT revised this gist May 24, 2023. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,16 @@ F3::
    Send, {e down}
    Sleep, 800
    Send, {e Up}
    DllCall("mouse_event",uint,1,int,-1870,int,0,uint,0,int,0)
    Sleep, 200
    DllCall("mouse_event",uint,1,int,1870,int,0,uint,0,int,0)
    Send, {d Down}
    Sleep, 100
    Send, {d Up}
    Sleep, 100
    Send, {a Down}
    Sleep, 100
    Send, {a Up}
    }
    }

  15. @A2TC-YT A2TC-YT revised this gist May 24, 2023. 1 changed file with 1 addition and 11 deletions.
    12 changes: 1 addition & 11 deletions auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -15,17 +15,7 @@ F3::
    pBitmap := Gdip_BitmapFromScreen("1243|971|37|21")
    pWhite := simpleColorCheck(pBitmap, 37, 21)
    Gdip_DisposeImage(pBitmap)
    if (pWhite >= 0.25)
    Break
    }
    Send, e
    Sleep, 300
    loop,
    {
    pBitmap := Gdip_BitmapFromScreen("1243|971|37|21")
    pWhite := simpleColorCheck(pBitmap, 37, 21)
    Gdip_DisposeImage(pBitmap)
    if (pWhite >= 0.18)
    if (pWhite >= 0.15)
    Break
    }
    Send, {e down}
  16. @A2TC-YT A2TC-YT revised this gist May 24, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ F3::
    pBitmap := Gdip_BitmapFromScreen("1243|971|37|21")
    pWhite := simpleColorCheck(pBitmap, 37, 21)
    Gdip_DisposeImage(pBitmap)
    if (pWhite >= 0.20)
    if (pWhite >= 0.18)
    Break
    }
    Send, {e down}
  17. @A2TC-YT A2TC-YT revised this gist May 24, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    SendMode Input
    SetWorkingDir, %A_ScriptDir%

    MsgBox, ***READ BEFORE USING***`nYou must have a 1440p screen for this to work. Make sure you are on 7 brightness, chromatic abberation is off, and hud opacity is max. Press F3 to start and F4 to stop. Does NOT work on Nessus.
    MsgBox, ***READ BEFORE USING***`nYou must have a 1440p screen for this to work. Make sure you are on 7 brightness, chromatic abberation is off, and hud opacity is max. Make sure you have interact bound to "E". Press F3 to start and F4 to stop. Does NOT work on Nessus.

    pToken := Gdip_Startup()

  18. @A2TC-YT A2TC-YT revised this gist May 24, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    SendMode Input
    SetWorkingDir, %A_ScriptDir%

    MsgBox, ***READ BEFORE USING***`nYou must have a 1440p screen for this to work. Make sure you are on 7 brightness, chromatic abberation is off, and hud opacity is max. Press F3 to start and F4 to stop.
    MsgBox, ***READ BEFORE USING***`nYou must have a 1440p screen for this to work. Make sure you are on 7 brightness, chromatic abberation is off, and hud opacity is max. Press F3 to start and F4 to stop. Does NOT work on Nessus.

    pToken := Gdip_Startup()

  19. @A2TC-YT A2TC-YT created this gist May 24, 2023.
    64 changes: 64 additions & 0 deletions auto_fishing.ahk
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    #SingleInstance, Force
    SendMode Input
    SetWorkingDir, %A_ScriptDir%

    MsgBox, ***READ BEFORE USING***`nYou must have a 1440p screen for this to work. Make sure you are on 7 brightness, chromatic abberation is off, and hud opacity is max. Press F3 to start and F4 to stop.

    pToken := Gdip_Startup()

    F3::
    {
    Loop,
    {
    loop,
    {
    pBitmap := Gdip_BitmapFromScreen("1243|971|37|21")
    pWhite := simpleColorCheck(pBitmap, 37, 21)
    Gdip_DisposeImage(pBitmap)
    if (pWhite >= 0.25)
    Break
    }
    Send, e
    Sleep, 300
    loop,
    {
    pBitmap := Gdip_BitmapFromScreen("1243|971|37|21")
    pWhite := simpleColorCheck(pBitmap, 37, 21)
    Gdip_DisposeImage(pBitmap)
    if (pWhite >= 0.20)
    Break
    }
    Send, {e down}
    Sleep, 800
    Send, {e Up}
    }
    }

    Return

    simpleColorCheck(pBitmap, w, h)
    {
    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
    }

    F4::Reload

    #Include <Gdip_all>