Skip to content

Instantly share code, notes, and snippets.

@BOLL7708
Last active November 30, 2022 21:44
Show Gist options
  • Save BOLL7708/47428e0a7f45e5ca50708081f918dafb to your computer and use it in GitHub Desktop.
Save BOLL7708/47428e0a7f45e5ca50708081f918dafb to your computer and use it in GitHub Desktop.
Change your SteamVR world scale by showing this page as a browser source in OBS
<?php
/* Read Me!
*
* 1. This requires a server with PHP to run, I recommend XAMPP: https://www.apachefriends.org/download.html
* 2. This requires OpenVR2WS, find the latest release here: https://github.com/BOLL7708/OpenVR2WS/releases
* 3. Fill in the missing values in the Config section below, follow the links if necessary!
* 4. With all of this and a SteamVR game running, open this page in a browser to see if it works.
* 5. If it did, you can flip the output to be hidden, and then add this as a browser source to OBS.
* 6. Then use whatever bot or solution you want to show/hide this source.
* 6a. Make sure to not hide the source again before the scale has been reset.
* 6b. Make sure the browser source reloads when shown, so it executes each time.
* 7. An advanced option is to also modify the url, append the URL with ?scale=# where # is the world scale in percent.
*/
/* Config */
$steamUserID64 = ''; // Get yours here: https://steamid.io/
$steamWebAPIKey = ''; // Get one here: https://steamcommunity.com/dev/apikey
$openVR2WSPort = 7708; // Default port
$openVR2WSPassword = ''; // Set it in the application and also here
$worldScaleDurationSeconds = 30; // Scale will be reset to 100% after this time
$worldScaleDefaultPercent = 50; // The default value to use when input is missing or invalid, range is 10-1000%.
$worldScaleMinPercent = 10; // The minimum SteamVR takes, set this up to limit input range.
$worldScaleMaxPercent = 1000; // The maximum SteamVR takes, reduce this to limit input range.
$showStatusOutput = true; // Flip this to false if you have gotten it working
/* Steam */
$ch = curl_init();
$url = "https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002?key=$steamWebAPIKey&steamids=$steamUserID64";
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$json = curl_exec($ch);
if(!$json) exit($showStatusOutput ? 'Could not load Steam Player data' : '');
$data = json_decode($json);
if(!$data) exit($showStatusOutput ? 'Could not parse Steam Player data' : '');
$gameId = $data->response->players[0]->gameid ?? null;
if(!$gameId) exit($showStatusOutput ? 'Could not retrieve Game ID' : '');
/* OpenVR2WS */
$incomingScale = preg_replace('/\D/', '', $_REQUEST['scale'] ?? '');
$worldScale = strlen($incomingScale) > 0 ? intval($incomingScale) : $worldScaleDefaultPercent;
if($worldScale == 0) $worldScale = $worldScaleDefaultPercent;
$worldScale = min(max($worldScale, $worldScaleMinPercent), $worldScaleMaxPercent);
$hash = base64_encode(hash('sha256', $openVR2WSPassword, true));
?>
<html lang="en">
<head><title>Scale Reward Page</title></head>
<body>
<div id="status"></div>
</body>
<script>
const status = document.querySelector('#status')
function printStatus(message) {
const show = <?=$showStatusOutput?'true':'false'?>;
if(show) status.innerHTML += `<p>${message}</p>`
}
const socket = new WebSocket('ws://localhost:<?=$openVR2WSPort?>')
socket.onopen = ()=>{
printStatus('Websocket connected.\n')
const payload = {
key:'RemoteSetting',
value:'<?=$hash?>',
value2:"steam.app.<?=$gameId?>",
value3:"worldScale",
value4:<?=$worldScale/100?>
}
const payloadStr = JSON.stringify(payload)
printStatus('Sending first payload.')
socket.send(payloadStr)
printStatus('Waiting to send second payload...')
setTimeout(()=>{
printStatus('Sending second payload.')
payload.value4 = 1 // Default world scale
const payloadStr2 = JSON.stringify(payload)
socket.send(payloadStr2)
setTimeout(()=>{
socket.close()
}, 1000)
}, <?=$worldScaleDurationSeconds?>*1000)
}
socket.onmessage = (event)=>{
try {
const response = JSON.parse(event.data)
if(response?.key === 'RemoteSetting') {
printStatus(`Response: ${response?.data?.message}`)
}
} catch(e) {
console.error(e.message)
}
}
socket.onclose = ()=>{
printStatus('Websocket closed.')
}
socket.onerror = (e)=>{
printStatus('Websocket error: '+e.message)
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment