All pastes #274803 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-12-10 23:48 UTC
rendered paste body
Opt ( "CaretCoordMode" , 2 )
opt ( "ColorMode" , 1 )
opt ( "MouseCoordMode" , 2 )
opt ( "PixelCoordMode" , 2 )
HotKeySet( "{END}", "End" )
func end()
	Exit
EndFunc
#region variables declaration and loading
;global user defined variables
global $MouseDropSleep = 50
global $DropAllInvHotkey = "{PGDN}", $StashHotkey = "{PGUP}"
HotKeySet( $DropAllInvHotkey, "DropInventory" )
HotKeySet( $StashHotkey, "Stash" )
; Globals buffer array's
;===================================
global $InvRef[10][4], $StaRef[6][8], $NpcRef[10][10], $CubeRef[3][4], $Belt4[4][4], $Belt3[4][3], $Belt2[4][2] , $Belt1[4][1]
global $UsedInvSpaces[10][4]
Global Const $XDiff = -3, $YDiff = -22 
LoadBoxesRef()

;===============================================================
; function LoadBoxesRef()
; Load Empty Inventory, Stash, VendorTrade, And belt references 
; stored in  $InvRef[x][y] , $StaRef[x][y] , $NpcRef[x][y] , $CubeRef[x][y]
;===============================================================
Func LoadBoxesRef()
For $i = 0 To 9
	For $j = 0 To 3
		$InvRef[$i][$j] = IniRead( "mm.Boxes.Ref.ini", "Empty Inventory reference", "X" & $i & "Y" & $j, "ERROR")
	Next
Next
For $i = 0 To 5
	For $j = 0 To 7
		$StaRef[$i][$j] = IniRead( "mm.Boxes.Ref.ini", "Empty Stash reference", "X" & $i & "Y" & $j, "ERROR")
	Next
Next
For $i = 0 To 9
	For $j = 0 To 9
		$NpcRef[$i][$j] = IniRead( "mm.Boxes.Ref.ini", "Empty Npc reference", "X" & $i & "Y" & $j, "ERROR")
	Next
Next
For $i = 0 To 2
	For $j = 0 To 3
		$CubeRef[$i][$j] = IniRead( "mm.Boxes.Ref.ini", "Empty Cube reference", "X" & $i & "Y" & $j, "ERROR")
	Next
Next
For $i = 0 To 3
	For $j = 0 To 3
		$Belt4[$i][$j] = IniRead( "mm.Boxes.Ref.ini", "Empty Belt 4 rows reference", "X" & $i & "Y" & $j, "ERROR")
	Next
Next
For $i = 0 To 3
	For $j = 0 To 2
		$Belt3[$i][$j] = IniRead( "mm.Boxes.Ref.ini", "Empty Belt 3 rows reference", "X" & $i & "Y" & $j, "ERROR")
	Next
Next
For $i = 0 To 3
	For $j = 0 To 1
		$Belt2[$i][$j] = IniRead( "mm.Boxes.Ref.ini", "Empty Belt 2 rows reference", "X" & $i & "Y" & $j, "ERROR")
	Next
Next
For $i = 0 To 3
	For $j = 0 To 0
		$Belt1[$i][$j] = IniRead( "mm.Boxes.Ref.ini", "Empty Belt 1 rows reference", "X" & $i & "Y" & $j, "ERROR" )
	Next
Next
EndFunc
#endregion 
#region test
while 1
	Sleep(100)
WEnd
#endregion 
#region Inv stuff
func Stash()
	if PixelChecksum( 50, 450, 140, 500, 10 ) <> 1015225423 Then 
		return 0
	EndIf
	MouseMove( 30, 40 , 0 )
	local $tmpInvRef = GetInventoryArray(), $tmpStaRef = GetStashArray(), $tmpFreeStashSpace = 0, $tmpUsedInvSpace = 0 _
	,$ItemsToStash = 0, $itemsStashed = 0
	for $x = 0 to 9
		for $y = 0 to 3
			if $tmpInvRef[ $x ] [ $y ] == "+" then $tmpUsedInvSpace += 1
		Next
	Next
	for $x = 0 to 5
		for $y = 0 to 7
			if $tmpStaRef[ $x ] [ $y ] == "o" then $tmpFreeStashSpace += 1
		Next
	Next
	if $tmpFreeStashSpace < $tmpUsedInvSpace then
		$ItemsToStash = $tmpFreeStashSpace
	Else
		$ItemsToStash = $tmpUsedInvSpace
	EndIf
	for $x = 0 to 9
		for $y = 0 to 3
			if $itemsStashed == $ItemsToStash then return 1
			if $tmpInvRef[ $x ] [ $y ] == "+" then 
				;stash the item at the current index
				;find the a free inv spot
				for $x2 = 0 to 5
					for $y2 = 0 to 7
						if $tmpStaRef[ $x2 ] [ $y2 ] == "o" then 
							;free space here
							if not PickInInv( $x, $y ) then 
								MsgBox( 0, "", "PickInInv failed" ) 
								Exit
							EndIf
							if not PlaceInStash( $x2, $y2 ) then 
								MsgBox( 0, "", "PlaceInStash failed" )
								Exit
							EndIf
							;reset that space as used
							$tmpStaRef[ $x2 ] [ $y2 ] = "+"
							ExitLoop 2
						EndIf
					Next
				Next
			EndIf
		Next
	Next
	return 1
EndFunc
func DropInventory()
	if PixelChecksum( 50, 450, 140, 500, 10 ) == 1015225423 Then ;stash is open
		MouseMove( 20, 30, 0 )
		local $tmpInvRef = GetInventoryArray(), $tmpStaRef = GetStashArray(), $tmpFreeInvSpace = 0, $tmpUsedStaSpace = 0 _
		,$ItemsToMove = 0, $itemsMoved = 0
		
		for $x = 0 to 9
			for $y = 0 to 3
				if $tmpInvRef[ $x ] [ $y ] == "o" then $tmpFreeInvSpace += 1
			Next
		Next
		for $x = 0 to 5
			for $y = 0 to 7
				if $tmpStaRef[ $x ] [ $y ] == "+" then $tmpUsedStaSpace += 1
			Next
		Next
		
		if $tmpFreeInvSpace < $tmpUsedStaSpace then 
			$ItemsToMove = $tmpFreeInvSpace
		Else
			$ItemsToMove = $tmpUsedStaSpace
		EndIf
		
		for $x = 0 to 5
			for $y = 0 to 7
				if $itemsMoved == $ItemsToMove then return 1
				if $tmpStaRef[ $x ] [ $y ] == "+" then 
					;stash item here
					for $x2 = 0 to 9
						for $y2 = 0 to 3
							if $tmpInvRef[ $x2 ] [ $y2 ] == "o" then 
								;free place in inv here.
								if not PickInStash( $x, $y ) then 
									MsgBox( 0, "", "PickInStash failed" ) 
									Exit
								EndIf
								if not PlaceInInv( $x2, $y2 ) then 
									MsgBox( 0, "", "PlaceInInv failed" )
									Exit
								EndIf								
								$tmpInvRef[ $x2 ] [ $y2 ] = "+"
								ExitLoop 2
							EndIf							
						Next
					Next
					$itemsMoved += 1
				EndIf
			Next
		Next
		
	ElseIf AreaShotCheckSum(740, 275, 780, 325, 6) == 199944749 then ;inv is open
		MouseMove( 30, 40 , 0 )
		$tmpInvRef = GetInventoryArray()
		for $x = 0 to 9
			for $y = 0 to 3
				if $tmpInvRef[ $x ] [ $y ] == "+" then
					;something is there drop it
					if not PickInInv( $x, $y ) then 
						MsgBox( 0, "", "PickInInv failed" ) 
						Exit
					EndIf
					;Sleep( $MouseDropSleep )
					if not FreeMouseBuffer() then 
						MsgBox( 0, "", "FreeMouseBuffer failed" )
						Exit
					EndIf
				EndIf
			Next
		Next
	Else
		return 0
		;MsgBox( 0, "", "Drop inv function: Inventory is not open" )
		;Exit
	EndIf
	return 1
EndFunc

func FreeMouseBuffer()
	for $i = 0 to 8
		MouseMove( 375, 300, 0 )
		Sleep( 50 )
		MouseDown( "Left" )
		Sleep( 10 )
		MouseUp( "Left" )
		Sleep( $MouseDropSleep )
		for $i = 0 to 1000 / $MouseDropSleep
			if FreeCursor() then 
				return 1
			EndIf
			Sleep( $MouseDropSleep )
		Next
	Next
	return 0	
EndFunc
func PickInStash( $x, $y )
	$x = $x * 29 + 160
	$y = $y * 29 + 160	
	;MouseMove( 20, 30 )
	if not WaitFreeCursor()  Then
		MsgBox( 0, "", "Item is already on cursor while trying to pick an item from inv. ERROR. Closing script" )
		Exit
	EndIf
	for $i = 0 to 8
		MouseMove( $x, $y, 1 )
		Sleep( $MouseDropSleep * 2 )
		MouseDown( "Left" )
		Sleep( 20 )
		MouseDown( "Left" )
		Sleep( 20 )
		MouseUp( "Left" )
		if WaitNotFreeCursor() then return 1
	Next
	return 0	
EndFunc
func PlaceInStash( $x, $y )
	if not WaitNotFreeCursor() then 
		MsgBox( 0, "", "We want to stash but there is no item in the cursor buffer. ERROR. closing script" )
		Exit
	EndIf
	$x = $x * 29 + 160
	$y = $y * 29 + 160
	for $i = 0 to 8
		MouseMove( $x, $y, 0 )
		Sleep( $MouseDropSleep * 2)
		MouseDown( "Left" )
		Sleep( 20 )
		MouseDown( "Left" )
		Sleep( 20 )
		MouseUp( "Left" )
		if WaitFreeCursor() then return 1
	Next
	return 0
EndFunc
func PlaceInInv( $x, $y )
	if not WaitNotFreeCursor() then 
		MsgBox( 0, "", "We want to stash but there is no item in the cursor buffer. ERROR. closing script" )
		Exit
	EndIf
	$x = $x * 29 + 426
	$y = $y * 29 + 341
	for $i = 0 to 8
		MouseMove( $x, $y, 1 )
		Sleep( $MouseDropSleep * 2)
		MouseDown( "Left" )
		Sleep( 20 )
		MouseDown( "Left" )
		Sleep( 20 )
		MouseUp( "Left" )
		Sleep( $MouseDropSleep )
		if WaitFreeCursor() then return 1
		Sleep( Random( 200, 300 ) )
	Next
	return 0
EndFunc
Func PickInInv($x, $y)
	;MouseMove( 20, 30 )
	if not WaitFreeCursor()  Then
		MsgBox( 0, "", "Item is already on cursor while trying to pick an item from inv. ERROR. Closing script" )
		Exit
	EndIf
	$x = $x * 29 + 426
	$y = $y * 29 + 341
	for $i = 0 to 8
		MouseMove( $x, $y, 0 )
		Sleep( $MouseDropSleep * 2 )
		MouseDown( "Left" )
		Sleep( 20 )
		MouseDown( "Left" )
		Sleep( 20 )
		MouseUp( "Left" )
		if WaitNotFreeCursor() then return 1
	Next
	return 0	
EndFunc

;===============================================================================================
; WAIT UNTIL the cursor is NOT free: return 1 if NOT free, 0 if yes, but with 5 seconds timout
;===============================================================================================
Func WaitNotFreeCursor()
$CursTimeOut = 0
Do
	If NotFreeCursor()==1 Then
		Return 1
	Else	
		Sleep ($MouseDropSleep * 2)
		$CursTimeOut = $CursTimeOut + 1
	EndIf
Until ($CursTimeOut > 5)
Return 0
EndFunc

;===============================================================================================
; WAIT UNTIL the cursor is free: return 1 if free, 0 if not, but with 5 seconds timout
;===============================================================================================
Func WaitFreeCursor()
$CursTimeOut = 0
Do
	If FreeCursor()==1 Then
		Return 1
	Else	
		Sleep ($MouseDropSleep * 2)
		$CursTimeOut = $CursTimeOut + 1
	EndIf
Until ($CursTimeOut > 5)
Return 0
EndFunc

;===============================================================================================
; VALIDATE if the cursor is Free: return 1 if free, 0 if not
;===============================================================================================
Func FreeCursor()
$MCoords = MouseGetPos()  
$XM = $MCoords[0]
$YM = $MCoords[1]
$MPixel1 = PixelGetColor ($XM + 18, $YM + 24)
$MPixel2 = PixelGetColor ($XM + 9, $YM + 13)
$MPixel3 = PixelGetColor ($XM + 17, $YM + 16)
$MPixel4 = PixelGetColor ($XM + 27, $YM + 13)
$MPixel5 = PixelGetColor ($XM + 23, $YM + 19)
$MPixel6 = PixelGetColor ($XM + 23, $YM + 18)
$MPixel7 = PixelGetColor ($XM + 23, $YM + 16)
If ( $MPixel1 == 527368 AND $MPixel2 == 1580056 AND $MPixel3 == 1582121 AND $MPixel4 == 2698281 AND $MPixel5 == 3749945 AND $MPixel6 == 4868426 AND $MPixel7 == 6514019 ) Then
	Return 1
Else
	Return 0
EndIf
EndFunc

;===============================================================================================
; VALIDATE if the cursor is NOT free: return 1 if free, 0 if not
;===============================================================================================
Func NotFreeCursor()
$MCoords = MouseGetPos()  
$XM = $MCoords[0]
$YM = $MCoords[1]
$MPixel1 = PixelGetColor ($XM + 18, $YM + 24)
$MPixel2 = PixelGetColor ($XM + 9, $YM + 13)
$MPixel3 = PixelGetColor ($XM + 17, $YM + 16)
$MPixel4 = PixelGetColor ($XM + 27, $YM + 13)
$MPixel5 = PixelGetColor ($XM + 23, $YM + 19)
$MPixel6 = PixelGetColor ($XM + 23, $YM + 18)
$MPixel7 = PixelGetColor ($XM + 23, $YM + 16)
If ( NOT ( $MPixel1 == 527368 AND $MPixel2 == 1580056 AND $MPixel3 == 1582121 AND $MPixel4 == 2698281 AND $MPixel5 == 3749945 AND $MPixel6 == 4868426 AND $MPixel7 == 6514019 ) ) Then
	Return 1
Else
	Return 0
EndIf
EndFunc

;return an array of xy stash.  "+" == something is there "o" = nothing is there
func GetStashArray()
	return ShotDiff( $StaRef, BoxesAreaShot( "Stash" ) , "Stash" )
EndFunc
;return an array of xy inventory. "+" == something is there "o" = nothing is there
Func GetInventoryArray()
	return  ShotDiff( $InvRef, BoxesAreaShot( "Inventory" ), "Inventory"  )
EndFunc

Func ShotDiff($ShotA, $ShotB, $ShotRefName)
Select
	Case $ShotRefName = "Inventory"
		$EmptyShotRef = $InvRef
		$Xboxes = 10
		$Yboxes = 4
	Case $ShotRefName = "Stash"
		$EmptyShotRef = $StaRef
		$Xboxes = 6
		$Yboxes = 8
	Case $ShotRefName = "Npc"
		$EmptyShotRef = $NpcRef
		$Xboxes = 10
		$Yboxes = 10
	Case $ShotRefName = "Cube"
		$EmptyShotRef = $CubeRef
		$Xboxes = 3
		$Yboxes = 4
	Case $ShotRefName = "Belt4"
		$EmptyShotRef = $Belt4
		$Xboxes = 4
		$Yboxes = 4
	Case $ShotRefName = "Belt3"
		$EmptyShotRef = $Belt3
		$Xboxes = 4
		$Yboxes = 3
	Case $ShotRefName = "Belt2"
		$EmptyShotRef = $Belt2
		$Xboxes = 4
		$Yboxes = 2
	Case $ShotRefName = "Belt1"
		$EmptyShotRef = $Belt1
		$Xboxes = 4
		$Yboxes = 1
EndSelect
Dim $AShotDiff[$Xboxes][$Yboxes]
For $ib = 0 To ($Xboxes - 1)
	For $jb = 0 To ($Yboxes - 1)
		If ($ShotA[$ib][$jb] <> $ShotB[$ib][$jb]) Then
			$AShotDiff[$ib][$jb] = "+"
			If ($ShotB[$ib][$jb] == $EmptyShotRef[$ib][$jb]) Then
				$AShotDiff[$ib][$jb] = "o"
			EndIf
		Else
			$AShotDiff[$ib][$jb] = "o"
		EndIf
	Next
Next
Return $AShotDiff
EndFunc

;============================================================
; function  BoxesAreaShot($Area)
; Generic shot with parameters: 6 pixels sum formula / box.
; "Inventory" = inventory, "Stash" = stash,
; "Npc" = npc, "Cube" = cube, "Beltx" = where x= 1,2,3 or 4
; ( depends of belt rows...) Return the array  $AreaShot
; note: rejuv OR full potions rejuv alway return 42123954
; returns Dim $AreaShot[$NRows][$NCols] with a checksum of all item
;============================================================
Func BoxesAreaShot($Area)
$BoxesXOffset = 29
$BoxesYOffset = 29
$InBoxXOffset_1 = 0
$InBoxYOffset_1 = 0
$InBoxXOffset_2 = 20
$InBoxYOffset_2 = 0
$InBoxXOffset_3 = 20
$InBoxYOffset_3 = 20
$InBoxXOffset_4 = 00
$InBoxYOffset_4 = 20
$InBoxXOffset_5 = 5
$InBoxYOffset_5 = 10
$InBoxXOffset_6 = 10
$InBoxYOffset_6 = 15
Select
	Case $Area == "Inventory"
		$NRows = 10
		$NCols = 4
		$X0 = 426
		$Y0 = 341
	Case $Area == "Stash"
		$NRows = 6
		$NCols = 8
		$X0 = 160
		$Y0 = 168 
	Case $Area == "Cube"
		$NRows = 3
		$NCols = 4
		$X0 = 204
		$Y0 = 224
	Case $Area == "Npc"
		$NRows = 10
		$NCols = 10
		$X0 = 101
		$Y0 = 149
EndSelect
	If StringInStr ($Area, "Belt") Then
		$BoxesXOffset = 31
		$BoxesYOffset = 32
		$InBoxXOffset_1 = 0
		$InBoxYOffset_1 = 1
		$InBoxXOffset_2 = 0
		$InBoxYOffset_2 = 1
		$InBoxXOffset_3 = 0
		$InBoxYOffset_3 = 1
		$InBoxXOffset_4 = 0
		$InBoxYOffset_4 = 1
		$InBoxXOffset_5 = 0
		$InBoxYOffset_5 = 1
		$InBoxXOffset_6 = 0
		$InBoxYOffset_6 = 1
		$NRows = 4
		$X0 = 442
		Select
			Case $Area == "Belt4"
				$NCols = 4
				$Y0 = 513
			Case $Area == "Belt3"
				$NCols = 3
				$Y0 = 545	
			Case $Area == "Belt2"
				$NCols = 2
				$Y0 = 577		
			Case $Area == "Belt1"
				$NCols = 1
				$Y0 = 609
		EndSelect
	EndIf
Dim $X[$NRows]
Dim $Y[$NCols]
$X[0] = $X0 + $XDiff
$Y[0] = $Y0 + $YDiff
For $i = 1 To ($NRows - 1)
$X[$i] = ($X[($i-1)] + $BoxesXOffset)
Next
For $j = 1 To ($NCols - 1)
$Y[$j] = ($Y[($j-1)] + $BoxesYOffset)
Next
Dim $AreaShot[$NRows][$NCols]
For $i = 0 To ($NRows - 1)
	For $j = 0 To ($NCols - 1)
	$Apix_1 = (Int(PixelGetColor($X[$i] + $InBoxXOffset_1,$Y[$j] + $InBoxYOffset_1)))
	$Apix_2 = (Int(PixelGetColor($X[$i] + $InBoxXOffset_2,$Y[$j] + $InBoxYOffset_2)))
	$Apix_3 = (Int(PixelGetColor($X[$i] + $InBoxXOffset_3,$Y[$j] + $InBoxYOffset_3)))
	$Apix_4 = (Int(PixelGetColor($X[$i] + $InBoxXOffset_4,$Y[$j] + $InBoxYOffset_4)))
	$Apix_5 = (Int(PixelGetColor($X[$i] + $InBoxXOffset_5,$Y[$j] + $InBoxYOffset_5)))
	$Apix_6 = (Int(PixelGetColor($X[$i] + $InBoxXOffset_6,$Y[$j] + $InBoxYOffset_6)))
	$AreaShot[$i][$j] = ($Apix_1 + $Apix_2 + $Apix_3 + $Apix_4 + $Apix_5 + $Apix_6)
	Next
Next
Return $AreaShot
EndFunc

;============================================================\
; Function AreaShotCheckSum ($XStart, $YStart, $XStop, $YStop, $Step)
; Area checkSum, can be used to check BNet Screens.
;============================================================
Func AreaShotCheckSum ($XStart, $YStart, $XStop, $YStop, $Step)
$XStart = $XStart + $XDiff
$YStart = $YStart + $YDiff
$XStop = $XStop + $XDiff
$YStop = $YStop + $YDiff
$CheckSum = 0
	For $X = $XStart To $XStop Step $Step
		For $Y = $YStart To $YStop Step $Step
			$Apix = PixelGetColor($X,$Y)
			$CheckSum = $CheckSum + $Apix
		Next
	Next
Return $CheckSum
EndFunc
#endregion 
#region autolag

#endregion