2020-06-04 20:40:39 +09:00
Stdout ( output := " " , sciteCheck := true ) { ;output to console - sciteCheck reduces Stdout/Stdin performance,so where performance is necessary disable it accordingly
Global ___console___
If ( sciteCheck & & ProcessExist ( " SciTE.exe " ) & & GetScriptParentProcess ( ) = " SciTE.exe " ) { ;if script parent is scite,output to scite console & return
FileAppend , %output% `n , *
Return
} ;CONOUT$ is a special file windows uses to expose attached console output
( o u t p u t ? ( ! _ _ _ c o n s o l e _ _ _ ? ( D l l C a l l ( " A t t a c h C o n s o l e " , " i n t " , - 1 ) | | D l l C a l l ( " A l l o c C o n s o l e " ) ) & ( _ _ _ c o n s o l e _ _ _ : = t r u e ) : " " ) & F i l e A p p e n d ( o u t p u t . " ` n " , " C O N O U T $ " ) : D l l C a l l ( " F r e e C o n s o l e " ) & ( _ _ _ c o n s o l e _ _ _ : = f a l s e ) & S t d E x i t ( ) )
}
Stdin ( output := " " , sciteCheck := true ) { ;output to console & wait for input & return input
Global ___console___
If ( sciteCheck & & ProcessExist ( " SciTE.exe " ) & & GetScriptParentProcess ( ) = " SciTE.exe " ) { ;if script parent is scite,output to scite console & return
FileAppend , %output% `n , *
Return
}
( o u t p u t ? ( ! _ _ _ c o n s o l e _ _ _ ? ( D l l C a l l ( " A t t a c h C o n s o l e " , " i n t " , - 1 ) | | D l l C a l l ( " A l l o c C o n s o l e " ) ) & ( _ _ _ c o n s o l e _ _ _ : = t r u e ) : " " ) & F i l e A p p e n d ( o u t p u t . " ` n " , " C O N O U T $ " ) & ( S t d i n : = F i l e R e a d L i n e ( " C O N I N $ " , 1 ) ) : D l l C a l l ( " F r e e C o n s o l e " ) & ( _ _ _ c o n s o l e _ _ _ : = f a l s e ) & S t d E x i t ( ) )
Return Stdin
}
StdExit ( ) {
If GetScriptParentProcess ( ) = " cmd.exe " ;couldn't get this: 'DllCall("GenerateConsoleCtrlEvent", CTRL_C_EVENT, 0)' to work so...
ControlSend , , { Enter } , % " ahk_pid " . GetParentProcess ( GetCurrentProcess ( ) )
}
FileAppend ( str , file ) {
FileAppend , %str% , %file%
}
FileReadLine ( file , lineNum ) {
FileReadLine , retVal , %file% , %lineNum%
return retVal
}
ProcessExist ( procName ) {
Process , Exist , % procName
Return ErrorLevel
}
GetScriptParentProcess ( ) {
return GetProcessName ( GetParentProcess ( GetCurrentProcess ( ) ) )
}
GetParentProcess ( PID )
{
static function := DllCall ( " GetProcAddress " , " ptr " , DllCall ( " GetModuleHandle " , " str " , " kernel32.dll " , " ptr " ) , " astr " , " Process32Next " ( A_IsUnicode ? " W " : " " ) , " ptr " )
if ! ( h := DllCall ( " CreateToolhelp32Snapshot " , " uint " , 2 , " uint " , 0 ) )
return
VarSetCapacity ( pEntry , sz := ( A_PtrSize = 8 ? 48 : 36 ) + ( A_IsUnicode ? 520 : 260 ) )
Numput ( sz , pEntry , 0 , " uint " )
DllCall ( " Process32First " ( A_IsUnicode ? " W " : " " ) , " ptr " , h , " ptr " , & pEntry )
loop
{
if ( pid = NumGet ( pEntry , 8 , " uint " ) | | ! DllCall ( function , " ptr " , h , " ptr " , & pEntry ) )
break
}
DllCall ( " CloseHandle " , " ptr " , h )
return Numget ( pEntry , 16 + 2 * A_PtrSize , " uint " )
}
GetProcessName ( PID )
{
static function := DllCall ( " GetProcAddress " , " ptr " , DllCall ( " GetModuleHandle " , " str " , " kernel32.dll " , " ptr " ) , " astr " , " Process32Next " ( A_IsUnicode ? " W " : " " ) , " ptr " )
if ! ( h := DllCall ( " CreateToolhelp32Snapshot " , " uint " , 2 , " uint " , 0 ) )
return
VarSetCapacity ( pEntry , sz := ( A_PtrSize = 8 ? 48 : 36 ) + 260 * ( A_IsUnicode ? 2 : 1 ) )
Numput ( sz , pEntry , 0 , " uint " )
DllCall ( " Process32First " ( A_IsUnicode ? " W " : " " ) , " ptr " , h , " ptr " , & pEntry )
loop
{
if ( pid = NumGet ( pEntry , 8 , " uint " ) | | ! DllCall ( function , " ptr " , h , " ptr " , & pEntry ) )
break
}
DllCall ( " CloseHandle " , " ptr " , h )
return StrGet ( & pEntry + 28 + 2 * A_PtrSize , A_IsUnicode ? " utf-16 " : " utf-8 " )
}
GetCurrentProcess ( )
{
return DllCall ( " GetCurrentProcessId " )
}
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#MaxThreadsPerHotkey , 2 ;with this each hotkey can have more than 1 "thread" allowing us to execute "space::" again
;even though it's still stuck in the loop.
;space::
;toggle:=!toggle
;loop {
; send, {Numpad0} ;send the Enter key, which needs to be in brackets, then text "/oos" followed by another enter.
; sleep, 100
; send, {Numpad0}
; sleep, 100
; send, {Numpad0}
; sleep, 2000
; send, {Z}
; sleep, 27500 ;sleep for 5000 milliseconds/5 seconds
;} until !toggle
;return
WinActivate , FINAL FANTASY XIV
;Normal - 0xAAAAAA
;Good - 0xB569FF 160 284
;Excellent - 0xEEEEEE 233 282
;BGR
;Crafting Window - 0xFFFFFF 1283 655
;Action Ready - 0x636663
;Action Not Ready - 3E3F3E
;100% Quality - 0x60DC97 336 269
WaitForCraftingWindow ( ) {
2020-06-05 15:18:13 +09:00
global toggle
2020-06-04 20:40:39 +09:00
Stdout ( " Waiting for Crafting Window... " )
sleep , 500
loop {
MouseGetPos , MouseX , MouseY
PixelGetColor , color , %MouseX% , %MouseY%
Stdout ( color . " " . MouseX . " " . MouseY )
sleep , 50
2020-06-05 15:18:13 +09:00
} until ( CraftingWindowOpen ( ) or ! toggle )
2020-06-04 20:40:39 +09:00
send , { Numpad0 }
sleep , 50
send , { Numpad0 }
sleep , 50
send , { Numpad0 }
sleep , 150
if ( ! CraftingWindowOpen ( ) ) {
return true
} else {
return false
}
}
2020-06-05 15:18:13 +09:00
ChooseBestProgressStep ( ByRef step , ByRef cp ) {
if ( cp > = 32 ) {
PressKeyWithModifier ( " Shift " , " 2 " )
ProgressStep ( step , cp , 32 )
} else
if ( cp > = 18 ) {
send , { 2 }
ProgressStep ( step , cp , 16 )
} else
{
PressKeyWithModifier ( " Ctrl " , " 3 " )
ProgressStep ( step , cp , 0 )
}
}
2020-06-04 20:40:39 +09:00
ProgressStep ( ByRef step , ByRef cp , cpcost , stepamt = 1 ) {
cp - = cpcost
step + = stepamt
}
2020-06-05 15:18:13 +09:00
2020-06-04 20:40:39 +09:00
WaitForReady ( ) {
global toggle
loop {
Stdout ( " Waiting for Ready... " )
sleep , 250
} until ( ActionReady ( ) )
if ( ! toggle ) {
return false
} else {
return true
}
}
2020-06-05 15:18:13 +09:00
CraftingRotationTemplate ( ByRef STEP ) {
global toggle
CP = 252
FINALSTEP = 13
if ( ! WaitForReady ( ) ) {
return
}
loop {
if ( IsMaxQuality ( ) ) {
STEP := FINALSTEP
}
Switch STEP
{
Case 1 :
send , { 5 }
ProgressStep ( STEP , CP , 18 )
Case 2 :
if ( IsExcellent ( ) ) {
send , { 2 }
ProgressStep ( STEP , CP , 18 , 2 )
WaitForReady ( )
PressKeyWithModifier ( " Ctrl " , " 1 " )
ProgressStep ( STEP , CP , 56 , 0 )
}
TricksOfTheTrade ( CP )
PressKeyWithModifier ( " Ctrl " , " 1 " )
ProgressStep ( STEP , CP , 56 )
Case 3 , 4 , 5 , 6 , 7 :
if ( ( IsGood ( ) or IsExcellent ( ) ) and CP > 160 ) {
send , { 2 }
ProgressStep ( STEP , CP , 18 )
} else {
PressKeyWithModifier ( " Ctrl " , " 3 " )
ProgressStep ( STEP , CP , 0 )
}
}
loop {
Stdout ( " Waiting for Ready... " )
sleep , 250
} until ( ActionReady ( ) or STEP > = FINALSTEP + 1 )
Stdout ( " STEP " . STEP . " : " . CP )
} until ( STEP > = FINALSTEP + 1 or ! toggle )
}
QuickCraftRotation ( ByRef STEP ) {
global toggle
CP = 252
FINALSTEP = 3
GREATSTRIDES = 0
INNOVATION = 0
DURABILITY := 40
SIDESTEPS = 0
ACTIVATESIDESTEP := false
if ( ! WaitForReady ( ) ) {
return
}
loop {
if ( IsMaxQuality ( ) ) {
STEP := FINALSTEP
}
if ( INNOVATION > 0 ) {
INNOVATION := INNOVATION - 1
}
if ( GREATSTRIDES > 0 ) {
GREATSTRIDES := GREATSTRIDES - 1
}
Switch STEP
{
Case 1 :
send , { 5 }
ProgressStep ( STEP , CP , 18 )
Case 2 :
if ( DURABILITY = 10 ) {
STEP := 99
send , { 1 }
ProgressStep ( STEP , CP , 0 )
} else {
STEP := 1
}
if ( GREATSTRIDES = 0 ) {
TricksOfTheTrade ( CP )
PressKeyWithModifier ( " Ctrl " , " 5 " )
ProgressStep ( STEP , CP , 32 )
GREATSTRIDES := 4
} else
if ( ! IsGood ( ) and ! IsExcellent ( ) and INNOVATION = 0 ) {
send , { 4 }
ProgressStep ( STEP , CP , 18 )
INNOVATION := 4
} else
if ( IsGood ( ) or IsExcellent ( ) ) {
ChooseBestProgressStep ( STEP , CP )
DURABILITY := DURABILITY - 10
GREATSTRIDES := 0
} else {
send , { 2 }
ProgressStep ( STEP , CP , 18 )
DURABILITY := DURABILITY - 10
GREATSTRIDES := 0
}
Case 3 :
send , { 1 }
ProgressStep ( STEP , CP , 0 )
}
loop {
Stdout ( " Waiting for Ready... " )
sleep , 250
} until ( ActionReady ( ) or STEP > = FINALSTEP + 1 )
Stdout ( " STEP " . STEP . " : " . CP )
} until ( STEP > = FINALSTEP + 1 or ! toggle )
}
2020-06-04 20:40:39 +09:00
CraftingRotation ( ByRef STEP ) {
global toggle
CP = 252
FINALSTEP = 13
2020-06-05 15:18:13 +09:00
SIDESTEPS = 0
ACTIVATESIDESTEP := false
2020-06-04 20:40:39 +09:00
if ( ! WaitForReady ( ) ) {
return
}
loop {
if ( IsMaxQuality ( ) ) {
2020-06-05 15:18:13 +09:00
STEP := FINALSTEP
2020-06-04 20:40:39 +09:00
}
Switch STEP
{
Case 1 :
send , { 5 }
ProgressStep ( STEP , CP , 18 )
Case 2 :
if ( IsExcellent ( ) ) {
send , { 2 }
ProgressStep ( STEP , CP , 18 , 2 )
WaitForReady ( )
PressKeyWithModifier ( " Ctrl " , " 1 " )
ProgressStep ( STEP , CP , 56 , 0 )
}
TricksOfTheTrade ( CP )
PressKeyWithModifier ( " Ctrl " , " 1 " )
ProgressStep ( STEP , CP , 56 )
Case 3 , 4 , 5 , 6 , 7 :
if ( ( IsGood ( ) or IsExcellent ( ) ) and CP > 160 ) {
send , { 2 }
ProgressStep ( STEP , CP , 18 )
} else {
PressKeyWithModifier ( " Ctrl " , " 3 " )
ProgressStep ( STEP , CP , 0 )
}
Case 8 :
2020-06-05 15:18:13 +09:00
if ( CP > = 176 ) {
ACTIVATESIDESTEP := true
SIDESTEPS = 0
}
2020-06-04 20:40:39 +09:00
TricksOfTheTrade ( CP )
send , { 3 }
ProgressStep ( STEP , CP , 88 )
2020-06-05 15:18:13 +09:00
sleep , 2000
2020-06-04 20:40:39 +09:00
Case 9 :
TricksOfTheTrade ( CP )
2020-06-05 15:18:13 +09:00
if ( ACTIVATESIDESTEP ) {
Stdout ( " SIDESTEP " . SIDESTEPS )
SIDESTEPS := SIDESTEPS + 1 ;1
PressKeyWithModifier ( " Ctrl " , " 3 " )
ProgressStep ( STEP , CP , 0 )
2020-06-04 20:40:39 +09:00
} else {
2020-06-05 15:18:13 +09:00
send , { 4 }
2020-06-04 20:40:39 +09:00
ProgressStep ( STEP , CP , 18 )
}
2020-06-05 15:18:13 +09:00
Case 10 , 11 , 12 :
if ( ACTIVATESIDESTEP ) {
Stdout ( " SIDESTEP " . SIDESTEPS )
if ( SIDESTEPS > = 2 ) {
ACTIVATESIDESTEP := false
if ( CP > = 194 ) {
send , { 2 }
ProgressStep ( STEP , CP , 18 )
} else {
PressKeyWithModifier ( " Ctrl " , " 3 " )
ProgressStep ( STEP , CP , 0 )
}
STEP = 8
} else {
SIDESTEPS := SIDESTEPS + 1 ;2,3
PressKeyWithModifier ( " Ctrl " , " 3 " )
ProgressStep ( STEP , CP , 0 )
}
} else
{
if ( CP > 54 ) {
PressKeyWithModifier ( " Shift " , " 2 " )
ProgressStep ( STEP , CP , 32 )
} else
if ( CP > = 18 ) {
send , { 2 }
ProgressStep ( STEP , CP , 18 )
} else
{
PressKeyWithModifier ( " Ctrl " , " 3 " )
ProgressStep ( STEP , CP , 0 )
}
}
2020-06-04 20:40:39 +09:00
Case 13 :
send , { 1 }
ProgressStep ( STEP , CP , 0 )
}
loop {
Stdout ( " Waiting for Ready... " )
sleep , 250
} until ( ActionReady ( ) or STEP > = FINALSTEP + 1 )
Stdout ( " STEP " . STEP . " : " . CP )
} until ( STEP > = FINALSTEP + 1 or ! toggle )
}
PressKeyWithModifier ( modifier , key ) {
Send , { %modifier% down }
sleep , 50
Send , %key%
sleep , 50
Send , { %modifier% up }
}
TricksOfTheTrade ( ByRef cp ) {
if IsGood ( ) {
PressKeyWithModifier ( " Ctrl " , " 2 " )
cp + = 20
loop {
sleep , 250
} until ActionReady ( )
}
}
ActionReady ( ) {
PixelGetColor , ScreenCol , 1912 , 700
if ( SubStr ( ScreenCol , 3 , 6 ) = " 636663 " ) {
return true
} else {
return false
}
}
CraftingWindowOpen ( ) {
PixelGetColor , ScreenCol , 1283 , 655
if ( SubStr ( ScreenCol , 3 , 6 ) = " FFFFFF " ) {
return true
} else {
return false
}
}
IsMaxQuality ( ) {
PixelGetColor , ScreenCol , 336 , 269
if ( SubStr ( ScreenCol , 3 , 6 ) = " 60DC97 " ) {
return true
} else {
return false
}
}
IsGood ( ) {
PixelGetColor , ScreenCol , 160 , 284
if ( SubStr ( ScreenCol , 7 , 2 ) = " FF " ) {
return true
} else {
return false
}
}
IsExcellent ( ) {
PixelGetColor , ScreenCol , 233 , 282
if ( SubStr ( ScreenCol , 3 , 6 ) = " EEEEEE " ) {
return true
} else {
return false
}
}
STEP = - 9999
toggle := false
;Stdout("Toggle1: " . toggle)
F11::
{
toggle := ! toggle
Stdout ( " Toggle1: " . toggle )
}
return
F12::
loop {
if ! toggle {
Stdout ( " Toggle was false. Toggle is now " . toggle )
toggle = true
break
}
Stdout ( " Crafting is on. Starting craft... " )
STEP = 1
if ( WaitForCraftingWindow ( ) ) {
2020-06-05 15:18:13 +09:00
;CraftingRotation(STEP)
QuickCraftRotation ( STEP )
2020-06-04 20:40:39 +09:00
} else {
toggle = false
Stdout ( " Toggle4: " . toggle )
}
sleep , 250
}
return