Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Array.au3>
- #include <GUIConstantsEx.au3>
- #include <WindowsConstants.au3>
- #include <ColorConstants.au3>
- #include <GDIPlus.au3>
- #include <StaticConstants.au3>
- #include <WindowsConstants.au3>
- #include <WinAPIProc.au3>
- #include <ScreenCapture.au3>
- #include <Misc.au3>
- #include <TrayConstants.au3>
- #include <ColorConstants.au3>
- #include <GDIPlus.au3>
- HotKeySet("^{SPACE}", "Terminate")
- Global $hBitmap
- Global $hHBitmap
- Global $BSpos[2]
- Global $user32 = DllOpen("user32.dll")
- Global $HWnD = WinGetHandle(WinGetTitle("BlueStacks App Player"))
- Global $sMatch = False
- Global $gi_ChildProcParent = 0
- Global $gs_ChildProcReciverFunction = ""
- Global $gv_ChildProcReviverParameter = 0
- Global $_ChildProc_pid[1], $_ChildProc_num_children = 0
- Global $Top[2] = [430, 20]
- Global $Bottom[2] = [430, 600]
- Global $Left[2] = [60, 310]
- Global $Right[2] = [780, 310]
- Global $Area = (($Top[0] * $Right[1] - $Right[0] * $Top[1]) + ($Right[0] * $Bottom[1] - $Bottom[0] * $Right[1]) + ($Bottom[0] * $Left[1] - $Left[0] * $Bottom[1]) + ($Left[0] * $Top[1] - $Top[0] * $Left[1])) / 2
- Global $a = Floor(($Top[0] + $Bottom[0] + $Left[0] + $Right[0]) / 4)
- Global $b = Floor(($Top[1] + $Bottom[1] + $Left[1] + $Right[1]) / 4)
- Global $sChildResult, $sResults = ""
- _GDIPlus_Startup()
- getBSPos()
- WinActivate($HWnD)
- Global $sStart, $sStop
- HotKeySet("+{SPACE}","Terminate")
- Func Terminate()
- Exit
- EndFunc
- ;$Mouse = MsgBox(4,"Weak Base Search","Show mouse pointers?",$HWnD)
- #Region ##### MAIN CODE #####
- ;========== Use this if you want to use parallel search ==========
- _CaptureRegion()
- __ChildProcStartup()
- $sStart = TimerInit()
- _ChildProc_Start("SearchTH8")
- _ChildProc_Start("SearchTH9")
- _ChildProc_Start("SearchTH10")
- _ChildProc_Start("SearchWall7")
- _ChildProc_Start("SearchWall8")
- While _ChildProc_GetChildCount() > 0
- Sleep(50)
- WEnd
- $sStop = Round(TimerDiff($sStart)/1000, 2)
- $sChildResult = _ChildProc_ReadFromAllFiles()
- If $sChildResult = "" Then $sChildResult = "Not Found"
- MsgBox(0,"",$sChildResult & ". Time: " & $sStop & "s")
- Func SearchTH8()
- If BaseSearch(0x815933, 10, -7, -2, 0xAE7643, 1, 14, 0x886C58) Then _ChildProc_WriteToFile("", "TH8, ")
- EndFunc
- Func SearchTH9()
- If BaseSearch(0x404450, 10, 9, 1, 0x494C58, 11, -2, 0x414753) Then _ChildProc_WriteToFile("", "TH9, ")
- EndFunc
- Func SearchTH10()
- If BaseSearch(0x484646, 10, 8, -12, 0x705858, -5, -20, 0x382F2F) Then _ChildProc_WriteToFile("", "TH10, ")
- EndFunc
- Func SearchWall7()
- If BaseSearch(0x331450, 5, 4, 4, 0x3D2949, 3, 1, 0x473357) Then _ChildProc_WriteToFile("", "Wall7, ")
- EndFunc
- Func SearchWall8()
- If BaseSearch(0x605850, 5, 5, -5, 0x282828, -3, 4, 0x202428) Then _ChildProc_WriteToFile("", "Wall8")
- EndFunc
- ;========== Use this if you want to use parallel search ==========
- ;========== Use this if you want to use normal (single-threaded) search ==========
- ;~ $sStart = TimerInit()
- ;~ _CaptureRegion()
- ;~ $sStart8 = TimerInit()
- ;~ If WeakBase(8) Then
- ;~ $sStop = Round(TimerDiff($sStart8) / 1000, 2)
- ;~ ;TrayTip("", "TH8 Found (" & $sStop & " seconds)", "", 0)
- ;~ $sResults &= "TH8 Found (" & $sStop & " seconds)" & @CRLF
- ;~ Else
- ;~ $sStop = Round(TimerDiff($sStart8) / 1000, 2)
- ;~ $sResults &= "TH8 Not Found (" & $sStop & " seconds)" & @CRLF
- ;~ EndIf
- ;~ $sStart9 = TimerInit()
- ;~ If WeakBase(9) Then
- ;~ $sStop = Round(TimerDiff($sStart9) / 1000, 2)
- ;~ ;TrayTip("","TH9 Found (" & $sStop & " seconds)","",0)
- ;~ $sResults &= "TH9 Found (" & $sStop & " seconds)" & @CRLF
- ;~ Else
- ;~ $sStop = Round(TimerDiff($sStart9) / 1000, 2)
- ;~ $sResults &= "TH9 Not Found (" & $sStop & " seconds)" & @CRLF
- ;~ EndIf
- ;~ $sStart10 = TimerInit()
- ;~ If WeakBase(10) Then
- ;~ $sStop = Round(TimerDiff($sStart10) / 1000, 2)
- ;~ ;TrayTip("","TH10 Found (" & $sStop & " seconds)","",0)
- ;~ $sResults &= "TH10 Found (" & $sStop & " seconds)" & @CRLF
- ;~ Else
- ;~ $sStop = Round(TimerDiff($sStart10) / 1000, 2)
- ;~ $sResults &= "TH10 Not Found (" & $sStop & " seconds)" & @CRLF
- ;~ EndIf
- ;~ $sStartw7 = TimerInit()
- ;~ If BaseCheck("Wall 7") Then
- ;~ $sStop = Round(TimerDiff($sStartw7) / 1000, 2)
- ;~ ;TrayTip("","Wall 7 Found (" & $sStop & " seconds)","",0)
- ;~ $sResults &= "Wall 7 Found (" & $sStop & " seconds)" & @CRLF
- ;~ Else
- ;~ $sStop = Round(TimerDiff($sStartw7) / 1000, 2)
- ;~ $sResults &= "Wall 7 Not Found (" & $sStop & " seconds)" & @CRLF
- ;~ EndIf
- ;~ $sStartw8 = TimerInit()
- ;~ If BaseCheck("Wall 8") Then
- ;~ $sStop = Round(TimerDiff($sStartw8) / 1000, 2)
- ;~ ;TrayTip("","Wall 8 Found (" & $sStop & " seconds)","",0)
- ;~ $sResults &= "Wall 8 Found (" & $sStop & " seconds)" & @CRLF
- ;~ Else
- ;~ $sStop = Round(TimerDiff($sStartw8) / 1000, 2)
- ;~ $sResults &= "Wall 8 Not Found (" & $sStop & " seconds)" & @CRLF
- ;~ EndIf
- ;~ $sStop = Round(TimerDiff($sStart) / 1000, 2)
- ;~ $sResults &= "Total time: " & $sStop & " seconds"
- ;~ MsgBox(0, "", $sResults)
- ;========== Use this if you want to use normal (single-threaded) search ==========
- #EndRegion ##### MAIN CODE #####
- #Region ##### WEAK BASE SEARCH #####
- ;~ Func SnipeAlgorithm($pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx = 3, $Stepy = 3, $Width = 100)
- ;~ If LinearSearchAlgorithm(310, 240, 10, 15, $pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, -$Stepx, -$Stepy, False) Then Return True;top left
- ;~ EndFunc ;==>SnipeAlgorithm
- Func WeakBase($TH)
- Switch $TH
- Case 8
- If BaseCheck("TownHall 8") Then Return True
- Case 9
- If BaseCheck("TownHall 9") Then Return True
- Case 10
- If BaseCheck("TownHall 10") Then Return True
- EndSwitch
- Return False
- EndFunc ;==>WeakBase
- Func BaseCheck($item)
- Switch $item
- Case "TownHall 9"
- If BaseSearch(0x404450, 9, 9, 1, 0x494C58, 11, -2, 0x414753) Then Return True
- Case "TownHall 8"
- If BaseSearch(0x815933, 6, -7, -2, 0xAE7643, 1, 14, 0x886C58) Then Return True
- Case "TownHall 10"
- ;If BaseSearch(0xA52015, 10, 8, 7, 0xEC5114, 5, 11, 0x7F3928) Then Return True
- If BaseSearch(0x484646, 9, 8, -12, 0x705858, -5, -20, 0x382F2F) Then Return True
- Case "Wall 7"
- If BaseSearch(0x331450, 4, 4, 4, 0x3D2949, 3, 1, 0x473357) Then Return True
- Case "Wall 8"
- ;If BaseSearch(0x202124, 10, 3, 2, 0x4A4A4D, -1, -3, 0x796C5C) Then Return True
- ;If BaseSearch(0x8A7D75, 10, -1, 3, 0x24282B, -4, 2, 0x121516) Then Return True
- If BaseSearch(0x605850, 4, 5, -5, 0x282828, -3, 4, 0x202428) Then Return True
- EndSwitch
- Return False
- EndFunc ;==>BaseCheck
- Func BaseSearch($pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx = 15, $Stepy = 15)
- If LinearSearchAlgorithm($pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx, $Stepy) Then Return True
- ;If SpiralSearchAlgorithm($a, $b, $pixel1, $colorvariation1, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx) Then Return True
- Return False
- EndFunc ;==>BaseSearch
- Func LinearSearchAlgorithm($pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx = 10, $Stepy = 10)
- If LinearSearchSingle($a + 5, $b + 5, 10, 15, $pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, -$Stepx, -$Stepy) Then Return True;top left
- If LinearSearchSingle($a - 5, $b - 5, 835, 625, $pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx, $Stepy) Then Return True ;bottom right
- If LinearSearchSingle($a + 5, $b - 5, 10, 625, $pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, -$Stepx, $Stepy) Then Return True ;bottom left
- If LinearSearchSingle($a - 5, $b + 5, 835, 15, $pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx, -$Stepy) Then Return True ;top right
- Return False
- EndFunc
- Func SpiralSearchAlgorithm($x, $y, $1c, $1v, $2x, $2y, $2c, $3x, $3y, $3c, $sStep = 20, $sSingle = False)
- If SpiralSearchSingleV($x, $y, $1c, $1v, $2x, $2y, $2c, $3x, $3y, $3c, $sStep) Then Return True
- If SpiralSearchSingleH($x, $y, $1c, $1v, $2x, $2y, $2c, $3x, $3y, $3c, $sStep) Then Return True
- Return False
- EndFunc
- Func LinearSearchSingle($x1, $y1, $x2, $y2, $1c, $1v, $2x, $2y, $2c, $3x, $3y, $3c, $sStepx, $sStepy, $sSingle = False)
- For $m = $x1 To $x2 + $sStepx Step $sStepx
- For $n = $y1 To $y2 + $sStepy Step $sStepy
- ;If $Mouse = 6 Then MouseMove($BSpos[0] + $m, $BSpos[1] + $n,1)
- If OutofBound($m, $n) Then ExitLoop
- If _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($1c, 6), $1v) _
- Or _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($2c, 6), $1v) _
- Or _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($3c, 6), $1v) Then
- For $o = $m - $sStepx + 1 To $m + $sStepx - 1 Step $sStepx/Abs($sStepx)
- For $p = $n - $sStepy + 1 To $n + $sStepy - 1 Step $sStepy/Abs($sStepy)
- ;If $Mouse = 6 Then MouseMove($BSpos[0] + $o, $BSpos[1] + $p,0.9)
- If _ColorCheckVariation(_PixelGetColor_GetPixel($o, $p), Hex($1c, 6), 2) Then
- If CheckColorVariPos($o + $2x, $p + $2y, $2c, 1, 3) Then
- If CheckColorVariPos($o + $3x, $p + $3y, $3c, 1, 3) Then
- ;MouseMove($BSpos[0] + $o, $BSpos[1] + $p)
- ;ControlClick("BlueStacks App Player", "", "", "left", "1", $o, $p)
- ;Sleep(500)
- Return True
- EndIf
- EndIf
- EndIf
- Next
- Next
- EndIf
- Next
- Next
- Return False
- EndFunc ;==>LinearSearchAlgorithm
- Func SpiralSearchSingleV($x, $y, $1c, $1v, $2x, $2y, $2c, $3x, $3y, $3c, $sStep, $sSingle = False) ; first pixel (x,y), second pixel (x offset, y offset, color), third pixel (x offset, y offset, color)
- While 1
- ;If $Mouse = 6 Then MouseMove($BSpos[0] + $x, $BSpos[1] + $y,1)
- If _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($1c, 6), $1v) _
- Or _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($2c, 6), $1v) _
- Or _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($3c, 6), $1v) Then
- For $m = $x - $sStep-3 To $x + $sStep+3
- For $n = $y - $sStep-3 To $y + $sStep+3
- ;If $Mouse = 6 Then MouseMove($BSpos[0] + $m, $BSpos[1] + $n,0.9)
- If _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($1c, 6), 1) Then
- If CheckColorVariPos($m + $2x, $n + $2y, $2c, 2, 3) Then
- If CheckColorVariPos($m + $3x, $n + $3y, $3c, 2, 3) Then Return True
- EndIf
- EndIf
- Next
- Next
- EndIf
- If OutofBound($x, $y) Then ExitLoop
- If Not $sSingle Then ;algorithm for spriral out search (fast but still not covering all pixels on screen, need work)
- If $x = $a And $y <= $b Then $x += $sStep
- If $x >= $a And $y < $b Then
- $x += $sStep-3
- $y += $sStep+3
- ElseIf $x > $a And $y >= $b Then
- $x -= $sStep-3
- $y += $sStep+3
- ElseIf $x <= $a And $y > $b Then
- $x -= $sStep-3
- $y -= $sStep+3
- ElseIf $x < $a And $y <= $b Then
- $x += $sStep-3
- $y -= $sStep+3
- EndIf
- EndIf
- WEnd
- Return False
- EndFunc ;==>SpiralSearchAlgorithm
- Func SpiralSearchSingleH($x, $y, $1c, $1v, $2x, $2y, $2c, $3x, $3y, $3c, $sStep, $sSingle = False) ; first pixel (x,y), second pixel (x offset, y offset, color), third pixel (x offset, y offset, color)
- While 1
- ;MouseMove($BSpos[0] + $x, $BSpos[1] + $y,1)
- If _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($1c, 6), $1v) _
- Or _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($2c, 6), $1v) _
- Or _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($3c, 6), $1v) Then
- For $m = $x - $sStep-3 To $x + $sStep+3
- For $n = $y - $sStep-3 To $y + $sStep+3
- ;MouseMove($BSpos[0] + $m, $BSpos[1] + $n,0.9)
- If _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($1c, 6), 1) Then
- If CheckColorVariPos($m + $2x, $n + $2y, $2c, 3, 5) Then
- If CheckColorVariPos($m + $3x, $n + $3y, $3c, 3, 5) Then Return True
- EndIf
- EndIf
- Next
- Next
- EndIf
- If OutofBound($x, $y) Then ExitLoop
- If Not $sSingle Then ;algorithm for spriral out search (fast but still not covering all pixels on screen, need work)
- If $x = $a And $y <= $b Then $x += $sStep
- If $x >= $a And $y < $b Then
- $x += $sStep+3
- $y += $sStep-3
- ElseIf $x > $a And $y >= $b Then
- $x -= $sStep+3
- $y += $sStep-3
- ElseIf $x <= $a And $y > $b Then
- $x -= $sStep+3
- $y -= $sStep-3
- ElseIf $x < $a And $y <= $b Then
- $x += $sStep+3
- $y -= $sStep-3
- EndIf
- EndIf
- WEnd
- Return False
- EndFunc ;==>SpiralSearchAlgorithm
- Func OutofBound($x, $y)
- $chkArea = TriArea($x, $y, $Top, $Left) + TriArea($x, $y, $Top, $Right) + TriArea($x, $y, $Right, $Bottom) + TriArea($x, $y, $Left, $Bottom)
- If $chkArea - $Area > 100 Then
- Return True
- Else
- Return False
- EndIf
- EndFunc ;==>OutofBound
- Func TriArea($dx, $dy, $e, $f)
- $tArea = Abs(($dx * ($e[1] - $f[1]) + $e[0] * ($f[1] - $dy) + $f[0] * ($dy - $e[1])) / 2)
- Return $tArea
- EndFunc ;==>TriArea
- Func CheckColorVariPos($x, $y, $c, $vp = 0, $vc = 10)
- For $a = $x - $vp To $x + $vp
- For $b = $y - $vp To $y + $vp
- If _ColorCheckVariation(_PixelGetColor_GetPixel($a, $b), Hex($c, 6), $vc) Then
- Return True
- EndIf
- Next
- Next
- Return False
- EndFunc ;==>CheckColorVariPos
- #EndRegion ##### WEAK BASE SEARCH #####
- Func _CaptureRegion($iLeft = 0, $iTop = 0, $iRight = 860, $iBottom = 720, $ReturnBMP = False)
- _GDIPlus_BitmapDispose($hBitmap)
- _WinAPI_DeleteObject($hHBitmap)
- Local $iW = Number($iRight) - Number($iLeft), $iH = Number($iBottom) - Number($iTop)
- Local $hDC_Capture = _WinAPI_GetWindowDC(ControlGetHandle("BlueStacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]"))
- Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
- $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $iW, $iH)
- Local $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
- DllCall($user32, "int", "PrintWindow", "hwnd", $HWnD, "handle", $hMemDC, "int", 0)
- _WinAPI_SelectObject($hMemDC, $hHBitmap)
- _WinAPI_BitBlt($hMemDC, 0, 0, $iW, $iH, $hDC_Capture, $iLeft, $iTop, 0x00CC0020)
- $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
- _WinAPI_DeleteDC($hMemDC)
- _WinAPI_SelectObject($hMemDC, $hObjectOld)
- _WinAPI_ReleaseDC($HWnD, $hDC_Capture)
- EndFunc ;==>_CaptureRegion
- Func _PixelGetColor_GetPixel($iX, $iY)
- Local $aPixelColor = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
- Return Hex($aPixelColor, 6)
- EndFunc ;==>_PixelGetColor_GetPixel
- Func _PixelSearch($iLeft, $iTop, $iRight, $iBottom, $iColor, $ColorVariation)
- _CaptureRegion($iLeft, $iTop, $iRight, $iBottom)
- For $x = $iRight - $iLeft To 0 Step -1
- For $y = $iBottom - $iTop To 0 Step -1
- Local $nColor1 = $iColor
- Local $nColor2 = _PixelGetColor_GetPixel($x, $y)
- If _ColorCheckVariation($nColor1, $nColor2, $ColorVariation) Then
- Local $Pos[2] = [$iLeft + $x, $iTop + $y]
- Return $Pos
- EndIf
- Next
- Next
- Return 0
- EndFunc ;==>_PixelSearch
- Func _ColorCheckVariation($nColor1, $nColor2, $sVari = 5)
- Local $Red1, $Red2, $Blue1, $Blue2, $Green1, $Green2
- $Red1 = Dec(StringMid(String($nColor1), 1, 2))
- $Blue1 = Dec(StringMid(String($nColor1), 3, 2))
- $Green1 = Dec(StringMid(String($nColor1), 5, 2))
- $Red2 = Dec(StringMid(String($nColor2), 1, 2))
- $Blue2 = Dec(StringMid(String($nColor2), 3, 2))
- $Green2 = Dec(StringMid(String($nColor2), 5, 2))
- If Abs($Blue1 - $Blue2) > $sVari Then Return False
- If Abs($Green1 - $Green2) > $sVari Then Return False
- If Abs($Red1 - $Red2) > $sVari Then Return False
- Return True
- EndFunc ;==>_ColorCheckVariation
- Func getBSPos()
- $aPos = ControlGetPos("BlueStacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]")
- $tPoint = DllStructCreate("int X;int Y")
- DllStructSetData($tPoint, "X", $aPos[0])
- DllStructSetData($tPoint, "Y", $aPos[1])
- _WinAPI_ClientToScreen(WinGetHandle(WinGetTitle("BlueStacks App Player")), $tPoint)
- $BSpos[0] = DllStructGetData($tPoint, "X")
- $BSpos[1] = DllStructGetData($tPoint, "Y")
- $CtrlHandle = ControlGetHandle("BlueStacks App Player", "", "BlueStacksApp1")
- EndFunc ;==>getBSPos
- #Region ##### CHILD PROCESS #####
- Func _ChildProc_Start($sFunction = Default, $vParameter = Default, $max_children = 0)
- Local $iPid
- If IsKeyword($sFunction) Or $sFunction = "" Then $sFunction = "__ChildProcDummy"
- EnvSet("ChildProc", "0x" & Hex(StringToBinary($sFunction)))
- EnvSet("ChildProcParent", @AutoItPID)
- If Not IsKeyword($vParameter) Then
- EnvSet("ChildProcParameterPresent", "True")
- EnvSet("ChildProcParameter", StringToBinary($vParameter))
- Else
- EnvSet("ChildProcParameterPresent", "False")
- EndIf
- If $max_children > 0 And $_ChildProc_num_children >= $max_children Then
- While _ChildProc_GetChildCount() >= $max_children
- Sleep(250)
- WEnd
- EndIf
- If @Compiled Then
- $iPid = Run(FileGetShortName(@AutoItExe), @WorkingDir, @SW_HIDE, 1 + 2 + 4)
- Else
- $iPid = Run(FileGetShortName(@AutoItExe) & ' "' & @ScriptFullPath & '"', @WorkingDir, @SW_HIDE, 1 + 2 + 4)
- EndIf
- If @error Then SetError(1)
- If $_ChildProc_pid[0] = "" Then
- $_ChildProc_pid[0] = $iPid
- Else
- _ArrayAdd($_ChildProc_pid, $iPid)
- EndIf
- $_ChildProc_num_children = $_ChildProc_num_children + 1
- Return $iPid
- EndFunc ;==>_ChildProc_Start
- Func _ChildProc_WriteToFile($name, $text = Default, $pid = @AutoItPID)
- $file_fullpath = @TempDir & "\_ChildProc_" & $pid & "_" & $name & ".txt"
- If $text = "" Or $text = Default Then
- FileDelete($file_fullpath)
- Return True
- EndIf
- FileDelete($file_fullpath)
- FileWrite($file_fullpath, $text)
- Return True
- EndFunc ;==>_ChildProc_WriteToFile
- Func _ChildProc_WriteToEnvVar($sName, $vValue = Default)
- Local $vTmp
- $sName = "_CP_" & $sName
- If $vValue = "" Or $vValue = Default Then
- EnvSet($sName)
- Return True
- EndIf
- EnvSet($sName, $vValue)
- Return True
- EndFunc ;==>_ChildProc_WriteToEnvVar
- Func _ChildProc_ReadFromEnvVar($sName, $fOption = 1)
- $sName = "_CP_" & $sName
- If $fOption = "" Or $fOption = Default Then $fOption = False
- $value = EnvGet($sName)
- If $fOption Then
- EnvSet($sName)
- EndIf
- Return $value
- EndFunc ;==>_ChildProc_ReadFromEnvVar
- Func _ChildProc_ReadFromFile($pid, $name, $fOption = 1)
- $file_fullpath = @TempDir & "\_ChildProc_" & $pid & "_" & $name & ".txt"
- If $fOption = "" Or $fOption = Default Then $fOption = False
- $text = FileRead($file_fullpath)
- If $fOption Then
- FileDelete($file_fullpath)
- EndIf
- Return $text
- EndFunc ;==>_ChildProc_ReadFromFile
- Func _ChildProc_ReadFromAllFiles()
- $text = ""
- For $pid In $_ChildProc_pid
- $text = $text & _ChildProc_ReadFromFile($pid, "")
- Next
- Return $text
- EndFunc ;==>_ChildProc_ReadFromAllFiles
- Func _ChildProc_GetChildCount()
- $num_children = 0
- For $pid_num = 0 To (UBound($_ChildProc_pid) - 1)
- If ProcessExists($_ChildProc_pid[$pid_num]) = True Then $num_children = $num_children + 1
- Next
- Return $num_children
- EndFunc ;==>_ChildProc_GetChildCount
- Func __ChildProcDummy($vPar = Default)
- If Not IsKeyword($vPar) Then _ChildProcReciver($vPar)
- While ProcessExists($gi_ChildProcParent)
- Sleep(500)
- WEnd
- EndFunc ;==>__ChildProcDummy
- Func __ChildProcStartup()
- Local $sCmd = EnvGet("ChildProc")
- If StringLeft($sCmd, 2) = "0x" Then
- $sCmd = BinaryToString($sCmd)
- $gi_ChildProcParent = Number(EnvGet("ChildProcParent"))
- If StringInStr($sCmd, "(") And StringInStr($sCmd, ")") Then
- Execute($sCmd)
- If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Execute: " & $sCmd)
- Exit
- EndIf
- If EnvGet("ChildProcParameterPresent") = "True" Then
- Call($sCmd, BinaryToString(EnvGet("ChildProcParameter")))
- If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Call: " & $sCmd & @LF & "Parameter: " & BinaryToString(EnvGet("ChildProcParameter")))
- Else
- Call($sCmd)
- If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Call: " & $sCmd)
- EndIf
- Exit
- EndIf
- EndFunc ;==>__ChildProcStartup
- #EndRegion ##### CHILD PROCESS #####
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement