diff --git a/incrementInstanceNumber.ps1 b/incrementInstanceNumber.ps1 new file mode 100644 index 0000000..ba42571 --- /dev/null +++ b/incrementInstanceNumber.ps1 @@ -0,0 +1,4 @@ +[int]$number = (get-content -path "c:\ldplayer\ldplayer9\index_count.txt") +$number=$number + 1 +if($number -gt 21){ $number=0} +$number | Out-File -FilePath "c:\ldplayer\ldplayer9\index_count.txt" \ No newline at end of file diff --git a/ldlaunchd.ps1 b/ldlaunchd.ps1 new file mode 100644 index 0000000..9f0287f --- /dev/null +++ b/ldlaunchd.ps1 @@ -0,0 +1,105 @@ +$global:LDPlayerPath ="C:\Ldplayer\LDplayer9" + +function logger($logMessage) { + [int]$number = (get-content -path "$global:LDPlayerPath\index_count.txt") + if($number -gt 21){ $number=0} + $instanceList = Get-Content -Path "$global:LDPlayerPath\instanceList.txt" + #$instanceNumber = $instanceList[$number] + #$instanceData = (cat C:\Ldplayer\LDplayer9\vms\config\leidian${instanceNumber}.config) + #$convertedData = $instanceData | ConvertFrom-Json + foreach ( $inst in $instanceList) { + $instanceData = (cat C:\Ldplayer\LDplayer9\vms\config\leidian${inst}.config) + $convertedData = $instanceData | ConvertFrom-Json + $name = $convertedData."statusSettings.playerName" + if ($global:instanceNameglobal -eq $name){ + $count = $inst + break + } + } + #if(-not $instanceName){$name = $convertedData."statusSettings.playerName"} + #$count = $number+1 + + $scriptName = Split-Path -Leaf $PSCommandPath + $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff" + $timestampedLogMessage = $timestamp + " ${global:instanceNameglobal} -instanceID: ${count} -${scriptName} -PID: ${PID}-:" + $logMessage + #$timestampedLogMessage + $logFilePath = "$global:LDPlayerPath\LDAutoLog.txt" + $fs = New-Object System.IO.FileStream($logFilePath, [System.IO.FileMode]::Append, [System.IO.FileAccess]::Write, [System.IO.FileShare]::Read) + $sw = New-Object System.IO.StreamWriter($fs) + try { + $sw.WriteLine($timestampedLogMessage) + } finally { + $sw.Close() + $fs.Close() + } + } + + +while($true) +{ + if(Test-Path "C:\Ldplayer\Ldplayer9\launchNow.txt"){ + $shouldLaunch = cat C:\Ldplayer\Ldplayer9\launchNow.txt + rm C:\Ldplayer\Ldplayer9\launchNow.txt + $out = cmd /c "$shouldLaunch" + logger("Received and ran launch command $shouldLaunch") + logger("$out") + + } + if(Test-Path "C:\Ldplayer\Ldplayer9\launchName.txt"){ + $shouldLaunchName = cat C:\Ldplayer\Ldplayer9\launchName.txt + rm C:\Ldplayer\Ldplayer9\launchName.txt + $out = cmd /c "$shouldLaunchName" + logger("Received and ran launch command $shouldLaunchName") + logger("$out") + + #$shouldLaunchName | Out-File -FilePath "C:\Ldplayer\Ldplayer9\runningName.txt" + } + + if(Test-Path "C:\Ldplayer\Ldplayer9\CloseNow.txt") { + $shouldClose = cat C:\Ldplayer\Ldplayer9\CloseNow.txt + rm C:\Ldplayer\Ldplayer9\CloseNow.txt + cmd /c "$shouldClose" + logger("Closed $shouldClose") + + } + + if(Test-Path "C:\Ldplayer\Ldplayer9\restartADB.txt") { + $restartADB = cat C:\Ldplayer\Ldplayer9\restartADB.txt + rm C:\Ldplayer\Ldplayer9\restartADB.txt + tskill adb *> $null + Start-Sleep -Milliseconds 1000 + adb connect $restartADB *> $null + logger("Closed $restartADB") + + } + + + if(Test-Path "C:\Ldplayer\Ldplayer9\CloseName.txt") { + $shouldCloseName = cat C:\Ldplayer\Ldplayer9\CloseName.txt + $instanceName=$shouldCloseName.Split(' ')[-1] + start-sleep -seconds 30 + rm C:\Ldplayer\Ldplayer9\CloseName.txt + cmd /c "$shouldCloseName" + logger("Closed $shouldCloseName") + + $instanceList = Get-Content -Path "$global:LDPlayerPath\instanceList.txt" +foreach ( $inst in $instanceList) { + $filename = "C:\Ldplayer\LDplayer9\vms\config\leidian${inst}.config" + $instanceData = (cat C:\Ldplayer\LDplayer9\vms\config\leidian${inst}.config) + $convertedData = $instanceData | ConvertFrom-Json + $name = $convertedData."statusSettings.playerName" + if ($instanceName -eq $name){ + $count = $inst + $c=$instanceData + if($instanceData -match 'networkSettings\.networkAddress\s+10\.0\.211\.125'){ + $newData = $instanceData -replace 'networkSettings\.networkAddress\s+10\.0\.211\.125', 'networkSettings\.networkAddress\s+10\.0\.211\.121' + Set-Content -Path $filename -Value $filename -Value $newData -Encoding UTF8 + } + break + } + } + #rm C:\Ldplayer\Ldplayer9\runningName.txt + } + + start-sleep -Milliseconds 500 +} \ No newline at end of file diff --git a/new.ps1 b/new.ps1 new file mode 100644 index 0000000..5d24999 --- /dev/null +++ b/new.ps1 @@ -0,0 +1,86 @@ +$global:LDPlayerPath ="C:\Ldplayer\LDplayer9" + +function logger($logMessage) { + [int]$number = (get-content -path "$global:LDPlayerPath\index_count.txt") + if($number -gt 21){ $number=0} + $instanceList = Get-Content -Path "$global:LDPlayerPath\instanceList.txt" + #$instanceNumber = $instanceList[$number] + #$instanceData = (cat C:\Ldplayer\LDplayer9\vms\config\leidian${instanceNumber}.config) + #$convertedData = $instanceData | ConvertFrom-Json + foreach ( $inst in $instanceList) { + $instanceData = (cat C:\Ldplayer\LDplayer9\vms\config\leidian${inst}.config) + $convertedData = $instanceData | ConvertFrom-Json + $name = $convertedData."statusSettings.playerName" + if ($global:instanceNameglobal -eq $name){ + $count = $inst + break + } + } + #if(-not $instanceName){$name = $convertedData."statusSettings.playerName"} + #$count = $number+1 + + $scriptName = Split-Path -Leaf $PSCommandPath + $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff" + $timestampedLogMessage = $timestamp + " ${global:instanceNameglobal} -instanceID: ${count} -${scriptName} -PID: ${PID}-:" + $logMessage + #$timestampedLogMessage + $logFilePath = "$global:LDPlayerPath\LDAutoLog.txt" + $fs = New-Object System.IO.FileStream($logFilePath, [System.IO.FileMode]::Append, [System.IO.FileAccess]::Write, [System.IO.FileShare]::Read) + $sw = New-Object System.IO.StreamWriter($fs) + try { + $sw.WriteLine($timestampedLogMessage) + } finally { + $sw.Close() + $fs.Close() + } + } + + +while($true) +{ + if(Test-Path "C:\Ldplayer\Ldplayer9\launchNow.txt"){ + $shouldLaunch = cat C:\Ldplayer\Ldplayer9\launchNow.txt + $out = cmd /c "$shouldLaunch" + logger("Received and ran launch command $shouldLaunch") + logger("$out") + rm C:\Ldplayer\Ldplayer9\launchNow.txt + } + if(Test-Path "C:\Ldplayer\Ldplayer9\launchName.txt"){ + $shouldLaunchName = cat C:\Ldplayer\Ldplayer9\launchName.txt + $out = cmd /c "$shouldLaunchName" + logger("Received and ran launch command $shouldLaunchName") + logger("$out") + rm C:\Ldplayer\Ldplayer9\launchName.txt + } + if(Test-Path "C:\Ldplayer\Ldplayer9\CloseNow.txt") { + $shouldClose = cat C:\Ldplayer\Ldplayer9\CloseNow.txt + cmd /c "$shouldClose" + logger("Closed $shouldClose") + rm C:\Ldplayer\Ldplayer9\CloseNow.txt + } + if(Test-Path "C:\Ldplayer\Ldplayer9\CloseName.txt") { + $shouldCloseName = cat C:\Ldplayer\Ldplayer9\CloseName.txt + $instanceName=$shouldCloseName.Split(' ')[-1] + cmd /c "$shouldCloseName" + logger("Closed $shouldCloseName") + rm C:\Ldplayer\Ldplayer9\CloseName.txt + $instanceList = Get-Content -Path "$global:LDPlayerPath\instanceList.txt" +foreach ( $inst in $instanceList) { + $filename = "C:\Ldplayer\LDplayer9\vms\config\leidian${inst}.config" + $instanceData = (cat C:\Ldplayer\LDplayer9\vms\config\leidian${inst}.config) + $convertedData = $instanceData | ConvertFrom-Json + $name = $convertedData."statusSettings.playerName" + if ($instanceName -eq $name){ + $count = $inst + $c=$instanceData + if (($newC=$c -replace '"networkSettings.networkAddress": "10.0.211.125",', '"networkSettings.networkAddress": "10.0.211.121",') -ne $c) { + $newC | Set-Content $filename + logger("changed IP back to 10.0.211.121 for $name") + logger(cat $filename | Select-String -Pattern "10.0.211.121") + } + break + } + } + } + + start-sleep -Milliseconds 500 +} \ No newline at end of file diff --git a/press_button.ps1 b/press_button.ps1 new file mode 100644 index 0000000..8e2ded3 --- /dev/null +++ b/press_button.ps1 @@ -0,0 +1,34 @@ +# Dump and pull UI hierarchy +adb shell uiautomator dump +$dumpPath = $(adb shell uiautomator dump) -match '[^ ]+.xml' | % { $Matches[0] } +adb pull $dumpPath view.xml + +# Parse XML +$xml = [xml](Get-Content view.xml) + +# Recursive search for node with "AGREE" +function Find-Node($node) { + if ($node.text -like "*AGREE*") { $node } + foreach ($child in $node.node) { + Find-Node $child + } +} +$node = Find-Node $xml.hierarchy +$node = $node | Where-Object {$_.text -eq "More options"} + +$bounds = $node.bounds +$bounds -match '\[(.*?)\]\[(.*?)\]' +$p1 = $Matches[1] -split ',' +$p2 = $Matches[2] -split ',' +$xMid = ([int]$p1[0] + [int]$p2[0]) / 2 +$yMid = ([int]$p1[1] + [int]$p2[1]) / 2 +$coords = "$xMid $yMid" + + + +# Output coords +$coords = "$xMid $yMid" +Write-Host "Coords of 'AGREE AND CONTINUE': $coords" + +# Tap the element (uncomment to use) +# adb shell input tap $coords diff --git a/readScreenshot.ps1 b/readScreenshot.ps1 new file mode 100644 index 0000000..f7fa181 --- /dev/null +++ b/readScreenshot.ps1 @@ -0,0 +1,60 @@ +$global:LDPlayerPath ="C:\Ldplayer\LDplayer9" + +function logger($logMessage) { + $scriptName = Split-Path -Leaf $PSCommandPath + $timestamp = date + $timestampedLogMessage = $timestamp + "--$scriptName--:" + $logMessage + $logFilePath = "$global:LDPlayerPath\LDAutoLog.txt" + $fs = New-Object System.IO.FileStream($logFilePath, [System.IO.FileMode]::Append, [System.IO.FileAccess]::Write, [System.IO.FileShare]::Read) + $sw = New-Object System.IO.StreamWriter($fs) + try { + $sw.WriteLine($timestampedLogMessage) + } finally { + $sw.Close() + $fs.Close() + } + } + + +#$adbOut= adb -s 10.0.211.121 shell screencap -p /sdcard/screenshot.png 2>$null +#$adbPull= adb -s 10.0.211.121 pull /sdcard/screenshot.png +adb connect 10.0.211.121 *>$null +adb -s 10.0.211.121 exec-out screencap -p > $global:LDPlayerPath\screenshot.png + + & "C:\Program Files\Tesseract-OCR\tesseract.exe" "$global:LDPlayerPath\screenshot.png" "$global:LDPlayerPath\tesseract" -l eng tsv + +$tsvFile = "$global:LDPlayerPath\tesseract.tsv" + +$wordCoords = Get-Content $tsvFile | ConvertFrom-Csv -Delimiter "`t" +$wordCoords | Where-Object ($_.level -eq 5) | Select-Object text, left, top, width, height + + +$Data=$wordCoords | ForEach-Object { + $x1 =[int]$_._left + $y1 =[int]$_.top + $x2 = $x1 + [int]$_.width + $y2 = $y1 + [int]$_.height + + $midX =[math]::Round(($x1+$x2)/2) + $midY =[math]::Round(($y1+$y2)/2) + + [PSCustomObject]@{ + Text = $_.text + X1 = $x1 + Y1 = $y1 + X2 = $x2 + Y2 = $y2 + MidX = $midX + MidY = $midY + Coords = "$midX $midY" + } +} + +$wordCoords | Format-Table +$Data | Format-Table +$coordsForText = $Data["Show"].Coords +$cordsForText + +$showCoords = $Data | Where-Object {$_.Text -and $_.Text.ToLower() -eq 'show'} + +$showCoords.Coords