From fcd8b531a1361649bc1999694ffbdc858963e30c Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Sat, 4 Sep 2021 04:41:38 +0700 Subject: [PATCH] =?UTF-8?q?N=C3=B3=20ch=E1=BA=A1y=20=C4=91=C6=B0=E1=BB=A3c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + const.au3 | 62 ++++++++++++++++++++ debugBox.au3 | 14 +++++ generateInput.au3 | 85 ++++++++++++++++++++++++++++ helper.au3 | 141 ++++++++++++++++++++++++++++++++++++++++++++++ index.au3 | 108 +++++++++++++++++++++++++++++++++++ 6 files changed, 412 insertions(+) create mode 100644 .gitignore create mode 100644 const.au3 create mode 100644 debugBox.au3 create mode 100644 generateInput.au3 create mode 100644 helper.au3 create mode 100644 index.au3 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b328595 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +temp** +*.ini \ No newline at end of file diff --git a/const.au3 b/const.au3 new file mode 100644 index 0000000..12d76b1 --- /dev/null +++ b/const.au3 @@ -0,0 +1,62 @@ +$inputPath = './input.ini' + +$bagCloseButtonColorRed = dec('C33222') +$bagCloseButtonColorWhite = dec('FFFFFF') + +$screenscale = @DesktopWidth/1920 + +$buttonUseRodX = $screenscale * 1532 +$buttonUseRodY = $screenscale * 653 + +$buttonWithdrawRodX = $screenscale * 1670 +$buttonWithdrawRodY = $screenscale * 850 + +$buttonOpenBagX = $screenscale * 1818 +$buttonOpenBagY = $screenscale * 553 +$buttonOpenBagColor = dec('E44142') + +$buttonStoreFishX = $screenscale * 1267 +$buttonStoreFishY = $screenscale * 853 +$buttonStoreFishColor = dec('41C5F3') + +$buttonStoreTrashX = $screenscale * 1546 +$buttonStoreTrashY = $screenscale * 894 +$buttonStoreTrashColor = dec('41C5F3') + +$bagOpenedX = $screenscale * 1317 +$bagOpenedY = $screenscale * 549 +$bagOpenedColor = dec('E85D3C') + +$buttonCloseBag1X = $screenscale * 1838 +$buttonCloseBag1Y = $screenscale * 91 +$buttonCloseBag1Color = dec('FFFFFF') + +$buttonCloseBag2X = $screenscale * 1859 +$buttonCloseBag2Y = $screenscale * 109 +$buttonCloseBag2Color = dec('C33222') + +$buttonCloseBag3X = $screenscale * 245 +$buttonCloseBag3Y = $screenscale * 158 + +$buttonTabTool1X = $screenscale * 1367 +$buttonTabTool1Y = $screenscale * 120 +$buttonTabTool1Color = dec('F46644') + +$buttonTabTool2X = $screenscale * 1385 +$buttonTabTool2Y = $screenscale * 117 +$buttonTabTool2Color = dec('FFB3A2') + +$buttonTabTool3X = $screenscale * 1407 +$buttonTabTool3Y = $screenscale * 134 +$buttonTabTool3Color = dec('FFFFFF') + +global $rodCheckMarkX = [1086, 1377, 1672, 1086, 1377, 1672] +global $rodCheckMarkY = [326, 326, 326, 705, 705, 705] +$rodCheckMarkColor = dec('82FB28') + +global $bagItemX = [1163, 1456, 1757, 1163, 1456, 1757] +global $bagItemY = [382, 382, 382, 764, 764, 764] + +global $buttonFixRodX = [1162, 1461, 1755, 1162, 1456, 1755] +global $buttonFixRodY = [525, 525, 525, 903, 903, 903] +$buttonFixRodColor = dec('F15E4E') diff --git a/debugBox.au3 b/debugBox.au3 new file mode 100644 index 0000000..246d0cc --- /dev/null +++ b/debugBox.au3 @@ -0,0 +1,14 @@ +AutoItSetOption('GUIOnEventMode', 1) + +local const $title="randomtitleabcxyzakdsjhfdfailgherw9ioutnbroi" + +SplashTextOn($title, 'aaa',"350","35","0","0",37,"","","") + +func _log($msg) + ControlSetText($title, '', 'Static1', $msg) + $currentmsg = $msg +EndFunc + +func clickClose() + Exit +EndFunc \ No newline at end of file diff --git a/generateInput.au3 b/generateInput.au3 new file mode 100644 index 0000000..4492306 --- /dev/null +++ b/generateInput.au3 @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include + +#include + +AutoItSetOption('GUIOnEventMode', 1) + +local $X1 = 0 +local $Y1 = 0 +local $X2 = 0 +local $Y2 = 0 +local $labelUpdated = false +local $isdone = false +local $isexit = false + +func genLabel() + return 'Current position:' & @CRLF & _ + 'X = ' & $X1 & @CRLF & _ + 'Y = ' & $Y1 & @CRLF & _ + @CRLF & _ + "Press F2 to capture current position:" & @CRLF & _ + "X = " & $X2 & @CRLF & _ + "Y = " & $Y2 +endfunc + +func Capture() + $X2 = $X1 + $Y2 = $Y1 + $labelUpdated = true +EndFunc + +Func _Cancel() + $isexit = true +EndFunc + +Func _Generate() + IniWrite($inputPath, "Exclaimation Mark", "exclaimationX", $X2) + IniWrite($inputPath, "Exclaimation Mark", "exclaimationY", $Y2) + IniWrite($inputPath, "General", "RodPosition", 1) + $isdone = true +EndFunc + +func generateInput() + local const $Form1 = GUICreate("Capture ! position", 280, 208) + local const $Label1 = GUICtrlCreateLabel(genLabel(), 12, 12, 255, 150) + GUICtrlSetFont($Label1, 12) + GUISetOnEvent($GUI_EVENT_CLOSE, "_Cancel", $Form1) + + + local const $ButtonGenerate = GUICtrlCreateButton("Generate", 48, 168, 75, 25) + local const $ButtonCancel = GUICtrlCreateButton("Cancel", 144, 168, 75, 25) + GUICtrlSetOnEvent($ButtonGenerate, '_Generate') + GUICtrlSetOnEvent($ButtonCancel, '_Cancel') + HotKeySet("{F2}", "Capture") + + GUISetState(@SW_SHOW) + + While not $isdone and not $isexit + $mousepos = _WinAPI_GetMousePos() + $X1_new = DllStructGetData($mousepos, "X") + $Y1_new = DllStructGetData($mousepos, "Y") + if $X1_new <> $X1 or $Y1_new <> $Y1 then + $X1 = $X1_new + $Y1 = $Y1_new + $labelUpdated = true + endif + if $labelUpdated then + GUICtrlSetData($Label1, genLabel()) + $labelUpdated = false + endif + $nMsg = GUIGetMsg() + Switch $nMsg + Case $GUI_EVENT_CLOSE + isexit = true + + EndSwitch + ;~ GUICtrlSetData($Label1, 'a') + WEnd + GUIDelete($Form1) + if $isexit then exit +EndFunc + diff --git a/helper.au3 b/helper.au3 new file mode 100644 index 0000000..f7293c7 --- /dev/null +++ b/helper.au3 @@ -0,0 +1,141 @@ +#include +;~ #include +;~ #include +;~ #include +;~ #include +;~ #include + +#include +#include + +global $exclaimationX +global $exclaimationY +global $rodPosition + +func getInput() + _log('Reading exclaimation position') + if FileExists($inputPath) then + $exclaimationX = IniRead($inputPath, "Exclaimation Mark", "exclaimationX", "") + $exclaimationY = IniRead($inputPath, "Exclaimation Mark", "exclaimationY", "") + $rodPosition = IniRead($inputPath, "General", "RodPosition", 1) + else + _log('Capturing exclaimation position') + generateInput() + getInput() + endif +endfunc + +func getCurrentExclaimationColor() + return PixelGetColor($exclaimationX, $exclaimationY) +EndFunc + +func alert($msg) + MsgBox($MB_SYSTEMMODAL, "Alert", $msg) +EndFunc + +;~ $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) +;~ $hPen = _WinAPI_CreatePen($PS_SOLID, 5, 0) +;~ $o_Orig = _WinAPI_SelectObject($hDC, $hPen) + +func drawCross() + $length=30 + _WinAPI_DrawLine($hDC, $exclaimationX - $length/2, $exclaimationY, $exclaimationX + $length/2, $exclaimationY) + _WinAPI_DrawLine($hDC, $exclaimationX, $exclaimationY - $length/2, $exclaimationX, $exclaimationY + $length/2) + _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0) + _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_ERASE) + _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN) + +EndFunc + +#region Button clicking +func click($x, $y, $clicks = 1, $speed = 100, $clickspeed = 2) + MouseClick ($MOUSE_CLICK_LEFT, $x, $y, $clicks, $clickspeed) + sleep($speed) +EndFunc + +func clickUseRod() + click($buttonUseRodX, $buttonUseRodY, 1, 200) +EndFunc + +func clickWithdrawRod() + click($buttonWithdrawRodX, $buttonWithdrawRodY, 10, 10, 0) +EndFunc + +func clickOpenBag() + click($buttonOpenBagX, $buttonOpenBagY, 1, 0) ;100 trở lên thì sleep vô tận cmnl, wtf? +EndFunc + +func clickTabTool() + click($buttonTabTool1X, $buttonTabTool1Y, 1, 200) +EndFunc + +func clickCloseBag() + click($buttonCloseBag3X, $buttonCloseBag3Y, 1, 200) +EndFunc + +func clickStoreFish() + click($buttonStoreFishX, $buttonStoreFishY, 1, 200) +EndFunc + +func clickStoreTrash() + click($buttonStoreTrashX, $buttonStoreTrashY, 1, 200) +EndFunc + +func clickSelectRod() + click($bagItemX[$rodPosition - 1] * $screenscale, $bagItemY[$rodPosition - 1] * $screenscale, 1, 200) +EndFunc +#endregion + +#region Detecting +func isOpenBagButtonShown() + return PixelGetColor($buttonOpenBagX, $buttonOpenBagY) == $buttonOpenBagColor +EndFunc + +func isBagOpened() + return not isOpenBagButtonShown() _ + And isCloseBagButtonShown() _ + And PixelGetColor($bagOpenedX, $bagOpenedY) == $bagOpenedColor +EndFunc + +func isTabToolNotSelected() + return isBagOpened() _ + And PixelGetColor($buttonTabTool1X, $buttonTabTool1Y) == $buttonTabTool1Color _ + And PixelGetColor($buttonTabTool2X, $buttonTabTool2Y) == $buttonTabTool2Color _ + And PixelGetColor($buttonTabTool3X, $buttonTabTool3Y) <> $buttonTabTool3Color +EndFunc + +func isCloseBagButtonShown() + return PixelGetColor($buttonCloseBag1X, $buttonCloseBag1Y) == $buttonCloseBag1Color _ + And PixelGetColor($buttonCloseBag2X, $buttonCloseBag2Y) == $buttonCloseBag2Color +EndFunc + +func isStoreFishButtonShown() + return PixelGetColor($buttonStoreFishX, $buttonStoreFishY) == $buttonStoreFishColor +EndFunc + +func isStoreTrashButtonShown() + return PixelGetColor($buttonStoreTrashX, $buttonStoreTrashY) == $buttonStoreTrashColor +EndFunc + +func rodCheckMarkExits() + return PixelGetColor($rodCheckMarkX[$rodPosition - 1] * $screenscale, $rodCheckMarkY[$rodPosition - 1] * $screenscale) == $rodCheckMarkColor +endfunc +#endregion + +#region complex select +func doBagStuff() + while isTabToolNotSelected() + clickTabTool() + wend + + while isBagOpened() and not isOpenBagButtonShown() + if rodCheckMarkExits() then + clickCloseBag() + Else + clickSelectRod() + endif + wend + Sleep(200) +endfunc + +#endregion \ No newline at end of file diff --git a/index.au3 b/index.au3 new file mode 100644 index 0000000..4141f6e --- /dev/null +++ b/index.au3 @@ -0,0 +1,108 @@ +#include + +#include +#include +#include + +_Singleton ('PlayTogetherAuto', 0) + +If @DesktopHeight / @DesktopWidth <> 0.5625 Then + MsgBox($MB_OK, "Screen resolution not support", "This PC using not supported screen resolution ratio. Please use the screen with ratio 16:9 (1920:1080 is recommended)") + + Exit 1 +EndIf + +getInput() + +HotKeySet("{esc}", "ExitToggle") +HotKeySet('`', "ExitToggle") +func ExitToggle() + Exit +EndFunc + +While True + + _log('Open bag') + local $startUsedRodTime + While isOpenBagButtonShown() + $startUsedRodTime = TimerInit() + clickUseRod() + clickOpenBag() + WEnd + + _log('Detecting is bag opened') + local $beginLoopTime = TimerInit() + while TimerDiff($beginLoopTime) < 5000 + if isBagOpened() then + _log('Doing bag stuff') + doBagStuff() + _log('Clicking use rod') + While isOpenBagButtonShown() + $startUsedRodTime = TimerInit() + clickUseRod() + WEnd + ExitLoop + endif + wend + + do ;sleep 13s and detect for is missed rod? + local $currentTimeDiff = TimerDiff($startUsedRodTime) + _log('Sleep 13s: ' & Round($currentTimeDiff/100)/10 & 's') + if isOpenBagButtonShown() Then + alert('Missed rod') + $missedRod = true + EndIf + until $currentTimeDiff >= 13000 + + Local $initColor = getCurrentExclaimationColor() + Local $beginLoopTime = TimerInit() + + _log('Detecting exclamimation') + Local $currentColor + local $missedRod = false + Do ;detecting exclaimation and detect for is missed rod? + $currentTimeDiff = TimerDiff($beginLoopTime) + _log('Detecting exclamimation ' & String($currentTimeDiff > 50000) & ' ' & Round($currentTimeDiff/100)/10 & 's') + $currentColor = getCurrentExclaimationColor() + if isOpenBagButtonShown() Then + alert('Missed rod') + $missedRod = true + EndIf + Until ($initColor <> $currentColor Or $currentTimeDiff > 50000) and not $missedRod + + if $missedRod then + ContinueLoop + endif + + _log('Withdrawing rod') + clickWithdrawRod() + + _log('Detecting store fish') + + Local $initTime = TimerInit() + Do + if isStoreFishButtonShown() then + _log('Storing fish') + while isStoreFishButtonShown() + clickStoreFish() + wend + ExitLoop + Else + if isStoreTrashButtonShown() Then + _log('Storing trash') + while isStoreTrashButtonShown() + clickStoreTrash() + wend + ExitLoop + Else + if isOpenBagButtonShown() Then + _log('Rod snapped') + ExitLoop + EndIf + EndIf + endif + Until TimerDiff($initTime) > 10000 + + _log('End loop') + sleep(500) +WEnd \ No newline at end of file