Skip to content

Instantly share code, notes, and snippets.

@erorus
Last active June 23, 2017 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erorus/2d3aea42f600f71b1e59dd4f05f46f8e to your computer and use it in GitHub Desktop.
Save erorus/2d3aea42f600f71b1e59dd4f05f46f8e to your computer and use it in GitHub Desktop.
Scripting WoW patches via Blizzard app
* 2017-06-23 14:17:56 Starting!
D 2017-06-23 14:18:00.481112 [ProductState] {Main} InstallState (wow): currentOperation=Update currentOperationStatus=Paused installed=1 installPath=C:/Program Files/World of Warcraft selectedRegion=us supports_multibox=1 localVersion=7.2.5.24367
* 2017-06-23 14:18:00 No regionalVersions yet
D 2017-06-23 14:18:06.253858 [ProductState] {Main} InstallState (wow): currentOperationStatus=Waiting
* 2017-06-23 14:18:06 Current status: Waiting
D 2017-06-23 14:18:06.289211 [ProductState] {Main} InstallState (wow): activeConfigKey=d6dac68c6d2ab1a385a41c552ce38cf7 regionalVersions=(cn: {playable:false config_key:c0fb29eec6312fab2774f8642fb98028}, eu: {playable:false config_key:c0fb29eec6312fab2774f8642fb98028}, kr: {playable:false config_key:c0fb29eec6312fab2774f8642fb98028}, sg: {playable:false config_key:c0fb29eec6312fab2774f8642fb98028}, tw: {playable:false config_key:c0fb29eec6312fab2774f8642fb98028}, us: {playable:false config_key:c0fb29eec6312fab2774f8642fb98028}, xx: {playable:false config_key:c0fb29eec6312fab2774f8642fb98028}) latestVersion=24415
* 2017-06-23 14:18:06 Current status: Waiting
D 2017-06-23 14:18:07.003432 [ProductState] {Main} InstallState (wow): currentOperationStatus=Initializing downloadRemainingExists=1
* 2017-06-23 14:18:06 Current status: Initializing
D 2017-06-23 14:19:01.866791 [ProductState] {Main} InstallState (wow): currentOperationStatus=Running bytesToDownload=17871015 downloadRemaining=17871015 thresholds=(1,1)
* 2017-06-23 14:19:01 Current status: Running
D 2017-06-23 14:19:12.122904 [ProductState] {Main} InstallState (wow): currentOperationStatus=Finalizing bytesToDownload=0 downloadRate=83237 downloadRemaining=0 progress=1 playableProgress=1
* 2017-06-23 14:19:12 Current status: Finalizing
D 2017-06-23 14:19:15.318758 [ProductState] {Main} InstallState (wow): playable=1 activeConfigKey=c0fb29eec6312fab2774f8642fb98028 regionalVersions=(cn: {playable:true config_key:c0fb29eec6312fab2774f8642fb98028}, eu: {playable:true config_key:c0fb29eec6312fab2774f8642fb98028}, kr: {playable:true config_key:c0fb29eec6312fab2774f8642fb98028}, sg: {playable:true config_key:c0fb29eec6312fab2774f8642fb98028}, tw: {playable:true config_key:c0fb29eec6312fab2774f8642fb98028}, us: {playable:true config_key:c0fb29eec6312fab2774f8642fb98028}, xx: {playable:true config_key:c0fb29eec6312fab2774f8642fb98028}) localVersion=7.2.5.24415 currentStage=Optimal
* 2017-06-23 14:19:15 Current status: Finalizing
D 2017-06-23 14:19:47.184550 [ProductState] {Main} InstallState (wow): currentOperationStatus=Waiting downloadRate=0 thresholds=() currentStage=Setup
* 2017-06-23 14:19:47 Current status: Waiting
D 2017-06-23 14:19:47.197126 [ProductState] {Main} InstallState (wow): currentStage=Complete
* 2017-06-23 14:19:47 Current status: Waiting
D 2017-06-23 14:19:47.203532 [ProductState] {Main} InstallState (wow): currentOperation=UpToDate currentOperationStatus=Paused
* 2017-06-23 14:19:47 All conditions satisfied! Exiting!
#!/bin/bash
export WINEARCH="win32"
export WINEPREFIX="$HOME/warcraft/wine.battle.net"
export DISPLAY=:0.0
gconftool -s -t string /apps/metacity/general/focus_new_windows "strict"
killall -q "WowError.exe" "Wow.exe" "wow-64.exe" "winedbg" "BlizzardError.exe" "Agent.exe" "Battle.net.exe" 'Battle.net Helper.exe'
mkfifo /tmp/battle.net.$$.fifo
php $HOME/warcraft/bnetStreamRead.php < /tmp/battle.net.$$.fifo &
phpProc=$!
launcherdir=`find $WINEPREFIX/drive_c/Program\ Files\/Blizzard\ App -maxdepth 1 -iname 'battle.net.*' -type d -printf "'%p'\n" | sort | tail -n 1 | xargs -n 1 basename`
wine "$WINEPREFIX/drive_c/Program Files/Blizzard App/$launcherdir/Battle.net.exe" --game=wow_enus >/tmp/battle.net.$$.fifo 2>/dev/null &
bnetProc=$!
wait $phpProc
waitRec=$?
kill $bnetProc
killall -q "WowError.exe" "Wow.exe" "wow-64.exe" "winedbg" "BlizzardError.exe" "Agent.exe" "Battle.net.exe" 'Battle.net Helper.exe'
rm /tmp/battle.net.$$.fifo
exit $waitRec
<?php
define('CHUNK_START', '[ProductState] {Main} InstallState (wow): ');
define('TIMEOUT_SIGNAL_SECONDS', 300);
$status = [];
$lastUpdate = time();
logPrint("Starting!");
while (!feof(STDIN)) {
$streams = [STDIN];
$empty = null;
$ready = stream_select($streams, $empty, $empty, TIMEOUT_SIGNAL_SECONDS);
if ($ready) {
$chunk = stream_get_line(STDIN, 131072, "\r\n");
if (checkChunk($chunk, $lastUpdate)) {
exit(0);
}
if (time() - $lastUpdate >= TIMEOUT_SIGNAL_SECONDS) {
logPrint("No useful lines seen in timeout period. Exiting.");
exit(1);
}
} else {
logPrint("Stream is quiet. Exiting.");
exit(1);
}
}
logPrint("Stream ended!");
exit(1);
function checkChunk($chunk, &$updateTime) {
global $status;
$chunk = trim($chunk);
if (($idx = strpos($chunk, CHUNK_START)) === false) {
return false;
}
$updateTime = time();
$parts = substr($chunk, $idx + strlen(CHUNK_START));
preg_match_all('/([^=]+)=([^=]+)(?: |$)/', $parts, $partsArray);
$map = array_combine($partsArray[1], $partsArray[2]);
echo "$chunk\n";
$status = array_merge($status, $map);
if (isset($status['currentOperationStatus']) && $status['currentOperationStatus'] != 'Paused') {
logPrint("Current status: " . $status['currentOperationStatus']);
} else if (!isset($status['regionalVersions'])) {
logPrint("No regionalVersions yet");
} else if (!(strpos($status['regionalVersions'], 'us: {playable:true') !== false)) {
logPrint("No us playable yet");
} else if (!isset($status['latestVersion'])) {
logPrint("No latestVersion yet");
} else if (!isset($status['localVersion'])) {
logPrint("No localVersion yet");
} else if (!(substr($status['localVersion'], -1 * strlen($status['latestVersion']) - 1) == ('.' . $status['latestVersion']))) {
logPrint("Bad version: '" . substr($status['localVersion'], -1 * strlen($status['latestVersion']) - 1) . '\' != \'' . ('.' . $status['latestVersion']) . "'");
} else {
logPrint("All conditions satisfied! Exiting!");
return true;
}
return false;
}
function logPrint($m) {
echo sprintf("* %s %s\n", date('Y-m-d H:i:s'), $m);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment