Post by Wreyth on Mar 31, 2005 22:13:50 GMT -5
ok i have this synthj script waiting to be run and the only thing it needs is cleaned up, but i am wanting to somehow transfer this and clean it up for use in AutoTerror. here it is please help
$numitems = 2
$imagesupport = 0
$waitforlogin = 0 ; set to 60000 for a 60 second pause
Dim $storestr, $thresh, $margin
Dim $leftside, $topside
;$leftside = 19 ; normal inventory
$leftside = 203 ; synthesis inventory
$topside = 53
$thresh = 20
$margin = 7
$tlog = "synth.txt"
Func trace($theLine)
;FileWriteLine($tlog, @mon & "/" & @mday & "/" & @year & " " & @hour & ":" & @min & ":" & @sec & ": " & $theLine)
FileWriteLine($tlog, $theLine)
EndFunc
Func enteronmultiple()
$color = PixelGetColor(55, 266);
If RGBinRange($color,166,55,72,20) Then
Send("{ENTER}")
EndIf
EndFunc
Func checkimagesupport()
If $imagesupport = 1 Then
;$color = PixelGetColor(TBD, TBD);
;If RGBinRange($color,TBD, TBD, TBD,20) Then
; ; TBD: check that this works
; Send("{F8}{ENTER}{UP 2}{ENTER}{UP}{ENTER}")
;EndIf
EndIf
EndFunc
Func storepixels($i)
$storestr = ""
$top = $topside + 18 * $i
$xmin = $leftside + $margin
$xmax = $leftside + 15 - $margin
$ymin = $top + $margin
$ymax = $top + 15 - $margin
For $x = $xmin To $xmax
For $y = $ymin To $ymax
$pval = PixelGetColor($x, $y);
trace("storing " & $pval)
$storestr = $storestr & $pval & ","
Next
$storestr = $storestr & "|"
Next
EndFunc
Func getsig($i)
$sig = ""
$top = $topside + 18 * $i
$xmin = $leftside + $margin
$xmax = $leftside + 15 - $margin
$ymin = $top + $margin
$ymax = $top + 15 - $margin
For $x = $xmin To $xmax
For $y = $ymin To $ymax
$pval = PixelGetColor($x, $y);
;trace("storing " & $pval)
$sig = $sig & $pval & ","
Next
$sig = $sig & "|"
Next
Return $sig
EndFunc
Func compsig($sig1, $sig2)
$diff = 0
$row1 = StringSplit($sig1,"|");
$row2 = StringSplit($sig2,"|");
$xmin = $margin
$xmax = 15 - $margin
$ymin = $margin
$ymax = 15 - $margin
For $x = $xmin To $xmax
$col1 = StringSplit($row1[$x-$xmin+1],",")
$col2 = StringSplit($row2[$x-$xmin+1],",")
For $y = $ymin To $ymax
$p1 = $col1[$y-$ymin+1]
$p2 = $col2[$y-$ymin+1]
$diff = $diff + PixelDistance($p1,$p2)
Next
Next
$diff = $diff / (($xmax-$xmin+1)*($ymax-$ymin+1))
trace("pixels differ by " + $diff)
Return $diff
EndFunc
Func comppixels($i)
$diff = 0
$storerows = StringSplit($storestr,"|");
$top = $topside + 18 * $i
$xmin = $leftside + $margin
$xmax = $leftside + 15 - $margin
$ymin = $top + $margin
$ymax = $top + 15 - $margin
For $x = $xmin To $xmax
$storecol = StringSplit($storerows[$x-$xmin+1],",")
For $y = $ymin To $ymax
$p1 = PixelGetColor($x, $y)
$r1 = $storecol[$y-$ymin+1]
$diff = $diff + PixelDistance($p1,$r1)
Next
;;;;;;$storestr = $storestr & "|"
Next
$diff = $diff / (($xmax-$xmin+1)*($ymax-$ymin+1))
trace("pixels differ by " + $diff)
Return $diff
EndFunc
Func PixelDistance($p1, $p2)
$hex1 = Hex($p1, 6)
$b1 = Dec(StringRight($hex1, 2))
$g1 = Dec(StringMid($hex1, 3,2))
$r1 = Dec(StringLeft($hex1, 2))
$hex2 = Hex($p2, 6)
$b2 = Dec(StringRight($hex2, 2))
$g2 = Dec(StringMid($hex2, 3,2))
$r2 = Dec(StringLeft($hex2, 2))
trace("comparing " & $r2 & "," & $g2 & "," & $b2 & " to " & $r1 & "," & $g1 & "," & $b1);
Return Abs($r2-$r1) + Abs($g2-$g1) + Abs($b2-$b1)
EndFunc
Func RGBinRange($color, $r, $g, $b, $thresh)
$hex = Hex($color, 6)
$b1 = Dec(StringRight($hex, 2))
$g1 = Dec(StringMid($hex, 3,2))
$r1 = Dec(StringLeft($hex, 2))
trace("comparing " & $r & "," & $g & "," & $b & " to " & $r1 & "," & $g1 & "," & $b1);
Return Abs($r-$r1) < $thresh AND Abs($g-$g1) < $thresh AND Abs($b-$b1) < $thresh
EndFunc
Func dumppixels($i)
$top = $topside + 18 * $i
trace("Dumping " & $i & " [" & $leftside & "," & $top & "]")
For $x = $leftside To $leftside + 15
$linestr = ""
For $y = $top To $top + 15
$pval = PixelGetColor($x, $y);
$linestr = $linestr & Hex($pval, 6) & ", "
Next
trace($linestr)
Next
EndFunc
Func dumpdiff($i,$j)
$top = $topside + 18 * $i
trace("Dumping difference between " & $i & " [" & $leftside & "," & $top & "] and " & $j)
For $x = $leftside To $leftside + 15
$linestr = ""
For $y = $top To $top + 15
$pval = PixelGetColor($x, $y);
$pval2 = PixelGetColor($x, $y+18*($j-$i));
$linestr = $linestr & Hex($pval-$pval2, 6) & ", "
Next
trace($linestr)
Next
EndFunc
AutoItSetOption("SendKeyDelay", 235)
AutoItSetOption("SendKeyDownDelay", 100)
Sleep($waitforlogin);
While 1 = 1
WinWaitActive("FFXiApp")
trace("starting an iteration");
Sleep(2000)
Send("!i")
Send("{LEFT 6}");
Send("{ENTER}");
Send("{ENTER}");
$highlighted = 0
For $foo = 1 To $numitems
If $foo = 5 Then
Send("{LEFT 4}{DOWN}")
EndIf
Send("{ENTER}");
trace("storing pixels for highlighted item " & $highlighted)
;;storepixels($highlighted)
$refsig = getsig($highlighted)
Do
Send("{DOWN}")
If $highlighted < 9 Then
$highlighted = $highlighted + 1
EndIf
$itemnum = $itemnum + 1
If $itemnum > 50 Then
; oops, didn't find enough items so we quit the script
Return 0
EndIf
$thissig = getsig($highlighted);
$pixelcomp = compsig($refsig,$thissig)
Until $pixelcomp > $thresh
Send("{ENTER}");
enteronmultiple();
Send("{RIGHT}");
Next
If $foo < 5 Then
Send("{RIGHT "&(4-$numitems)&"}{ENTER}");
Else
Send("{UP}{RIGHT "&(8-$numitems)&"}{ENTER}");
EndIf
Sleep(25000)
Wend
$numitems = 2
$imagesupport = 0
$waitforlogin = 0 ; set to 60000 for a 60 second pause
Dim $storestr, $thresh, $margin
Dim $leftside, $topside
;$leftside = 19 ; normal inventory
$leftside = 203 ; synthesis inventory
$topside = 53
$thresh = 20
$margin = 7
$tlog = "synth.txt"
Func trace($theLine)
;FileWriteLine($tlog, @mon & "/" & @mday & "/" & @year & " " & @hour & ":" & @min & ":" & @sec & ": " & $theLine)
FileWriteLine($tlog, $theLine)
EndFunc
Func enteronmultiple()
$color = PixelGetColor(55, 266);
If RGBinRange($color,166,55,72,20) Then
Send("{ENTER}")
EndIf
EndFunc
Func checkimagesupport()
If $imagesupport = 1 Then
;$color = PixelGetColor(TBD, TBD);
;If RGBinRange($color,TBD, TBD, TBD,20) Then
; ; TBD: check that this works
; Send("{F8}{ENTER}{UP 2}{ENTER}{UP}{ENTER}")
;EndIf
EndIf
EndFunc
Func storepixels($i)
$storestr = ""
$top = $topside + 18 * $i
$xmin = $leftside + $margin
$xmax = $leftside + 15 - $margin
$ymin = $top + $margin
$ymax = $top + 15 - $margin
For $x = $xmin To $xmax
For $y = $ymin To $ymax
$pval = PixelGetColor($x, $y);
trace("storing " & $pval)
$storestr = $storestr & $pval & ","
Next
$storestr = $storestr & "|"
Next
EndFunc
Func getsig($i)
$sig = ""
$top = $topside + 18 * $i
$xmin = $leftside + $margin
$xmax = $leftside + 15 - $margin
$ymin = $top + $margin
$ymax = $top + 15 - $margin
For $x = $xmin To $xmax
For $y = $ymin To $ymax
$pval = PixelGetColor($x, $y);
;trace("storing " & $pval)
$sig = $sig & $pval & ","
Next
$sig = $sig & "|"
Next
Return $sig
EndFunc
Func compsig($sig1, $sig2)
$diff = 0
$row1 = StringSplit($sig1,"|");
$row2 = StringSplit($sig2,"|");
$xmin = $margin
$xmax = 15 - $margin
$ymin = $margin
$ymax = 15 - $margin
For $x = $xmin To $xmax
$col1 = StringSplit($row1[$x-$xmin+1],",")
$col2 = StringSplit($row2[$x-$xmin+1],",")
For $y = $ymin To $ymax
$p1 = $col1[$y-$ymin+1]
$p2 = $col2[$y-$ymin+1]
$diff = $diff + PixelDistance($p1,$p2)
Next
Next
$diff = $diff / (($xmax-$xmin+1)*($ymax-$ymin+1))
trace("pixels differ by " + $diff)
Return $diff
EndFunc
Func comppixels($i)
$diff = 0
$storerows = StringSplit($storestr,"|");
$top = $topside + 18 * $i
$xmin = $leftside + $margin
$xmax = $leftside + 15 - $margin
$ymin = $top + $margin
$ymax = $top + 15 - $margin
For $x = $xmin To $xmax
$storecol = StringSplit($storerows[$x-$xmin+1],",")
For $y = $ymin To $ymax
$p1 = PixelGetColor($x, $y)
$r1 = $storecol[$y-$ymin+1]
$diff = $diff + PixelDistance($p1,$r1)
Next
;;;;;;$storestr = $storestr & "|"
Next
$diff = $diff / (($xmax-$xmin+1)*($ymax-$ymin+1))
trace("pixels differ by " + $diff)
Return $diff
EndFunc
Func PixelDistance($p1, $p2)
$hex1 = Hex($p1, 6)
$b1 = Dec(StringRight($hex1, 2))
$g1 = Dec(StringMid($hex1, 3,2))
$r1 = Dec(StringLeft($hex1, 2))
$hex2 = Hex($p2, 6)
$b2 = Dec(StringRight($hex2, 2))
$g2 = Dec(StringMid($hex2, 3,2))
$r2 = Dec(StringLeft($hex2, 2))
trace("comparing " & $r2 & "," & $g2 & "," & $b2 & " to " & $r1 & "," & $g1 & "," & $b1);
Return Abs($r2-$r1) + Abs($g2-$g1) + Abs($b2-$b1)
EndFunc
Func RGBinRange($color, $r, $g, $b, $thresh)
$hex = Hex($color, 6)
$b1 = Dec(StringRight($hex, 2))
$g1 = Dec(StringMid($hex, 3,2))
$r1 = Dec(StringLeft($hex, 2))
trace("comparing " & $r & "," & $g & "," & $b & " to " & $r1 & "," & $g1 & "," & $b1);
Return Abs($r-$r1) < $thresh AND Abs($g-$g1) < $thresh AND Abs($b-$b1) < $thresh
EndFunc
Func dumppixels($i)
$top = $topside + 18 * $i
trace("Dumping " & $i & " [" & $leftside & "," & $top & "]")
For $x = $leftside To $leftside + 15
$linestr = ""
For $y = $top To $top + 15
$pval = PixelGetColor($x, $y);
$linestr = $linestr & Hex($pval, 6) & ", "
Next
trace($linestr)
Next
EndFunc
Func dumpdiff($i,$j)
$top = $topside + 18 * $i
trace("Dumping difference between " & $i & " [" & $leftside & "," & $top & "] and " & $j)
For $x = $leftside To $leftside + 15
$linestr = ""
For $y = $top To $top + 15
$pval = PixelGetColor($x, $y);
$pval2 = PixelGetColor($x, $y+18*($j-$i));
$linestr = $linestr & Hex($pval-$pval2, 6) & ", "
Next
trace($linestr)
Next
EndFunc
AutoItSetOption("SendKeyDelay", 235)
AutoItSetOption("SendKeyDownDelay", 100)
Sleep($waitforlogin);
While 1 = 1
WinWaitActive("FFXiApp")
trace("starting an iteration");
Sleep(2000)
Send("!i")
Send("{LEFT 6}");
Send("{ENTER}");
Send("{ENTER}");
$highlighted = 0
For $foo = 1 To $numitems
If $foo = 5 Then
Send("{LEFT 4}{DOWN}")
EndIf
Send("{ENTER}");
trace("storing pixels for highlighted item " & $highlighted)
;;storepixels($highlighted)
$refsig = getsig($highlighted)
Do
Send("{DOWN}")
If $highlighted < 9 Then
$highlighted = $highlighted + 1
EndIf
$itemnum = $itemnum + 1
If $itemnum > 50 Then
; oops, didn't find enough items so we quit the script
Return 0
EndIf
$thissig = getsig($highlighted);
$pixelcomp = compsig($refsig,$thissig)
Until $pixelcomp > $thresh
Send("{ENTER}");
enteronmultiple();
Send("{RIGHT}");
Next
If $foo < 5 Then
Send("{RIGHT "&(4-$numitems)&"}{ENTER}");
Else
Send("{UP}{RIGHT "&(8-$numitems)&"}{ENTER}");
EndIf
Sleep(25000)
Wend