Created
December 30, 2019 15:51
-
-
Save pdc4444/a11a92e90e84d307cbe5a5d55c70b863 to your computer and use it in GitHub Desktop.
Creates ark shortcuts on your desktop to quickly join a server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The purpose of this script is to create custom ark shortcuts on your desktop that automatically will connect you to the server of your choosing. | |
* This avoids Wildcard's dumb menu which is currently bugged out and will sometimes crash your game :( | |
* | |
* Another reason for this script's existence is the fact that I can't put a hostname into the shortcut and have it automatically be resolved (it has to be an ip address). | |
* | |
* Code Flow: | |
* - Get the ip address to elephantbox.net | |
* - Generate a custom vbs script for every server | |
* - Create the shortcut for that server on the desktop | |
* - Clean up remaining files | |
* | |
* Things to consider: | |
* - Not all Ark servers have a hostname | |
* - Variables like server name and ports and user folder data are all hardcoded | |
* - This script probably isn't very user friendly to begin with because it's running a php based .vbs wrapper and automation requires | |
* using windows task manager. | |
* - Maybe I should add in a method to add to windows task scheduler? | |
* - Maybe add in a configurable ini file? | |
* | |
* vbs code was used from this source. Thank you fellow developer! | |
* https://www.giannistsakiris.com/2008/12/03/how-to-create-shortcuts-in-windows-from-the-command-line/ | |
*/ | |
$servers = [ | |
'TheIsland' => 60101, | |
'Extinction' => 60105, | |
'Scorched_Earth' => 60109, | |
'The_Center' => 60113, | |
'Ragnarok' => 60117, | |
'Abberation' => 60121, | |
'Dev_VM' => 60125 | |
]; | |
$ip_address = resolveHostnameIP(); | |
$password = ''; //Intentionally left blank for now | |
//Change our working directory to the shortcut folder | |
$shortcut_folder = 'C:' . DIRECTORY_SEPARATOR . 'Users' . DIRECTORY_SEPARATOR . 'Peter' . DIRECTORY_SEPARATOR . 'Desktop'; | |
chdir($shortcut_folder); | |
$ark_binary_location = | |
'E:' . DIRECTORY_SEPARATOR . | |
'SteamLibrary' . DIRECTORY_SEPARATOR . | |
'steamapps' . DIRECTORY_SEPARATOR . | |
'common' . DIRECTORY_SEPARATOR . | |
'ARK' . DIRECTORY_SEPARATOR . | |
'ShooterGame' . DIRECTORY_SEPARATOR . | |
'Binaries' . DIRECTORY_SEPARATOR . | |
'Win64' . DIRECTORY_SEPARATOR . | |
'ShooterGame.exe'; | |
foreach ($servers as $name => $port) { | |
//Generate the raw .vbs script | |
$script_name = 'ark_shortcut.vbs'; | |
$script_loc = $shortcut_folder . DIRECTORY_SEPARATOR . $script_name; | |
//Remove the script if it exists already (should only happen if the script ever fails in the middle of processing) | |
if (file_exists($script_loc) !== FALSE) { | |
unlink($script_loc); | |
} | |
$shortcut_name = 'Ark_' . $name; | |
$shortcut_location = $shortcut_folder . DIRECTORY_SEPARATOR . $shortcut_name . '.lnk'; | |
$script = createShortcutScript($ip_address, $port, $password); | |
file_put_contents($script_loc, $script); | |
//Run the script! | |
$shell_cmd = $script_name . ' /target:"' . $ark_binary_location . '" /shortcut:"' . $shortcut_name; | |
exec($shell_cmd); | |
//Clean up the generated script | |
unlink($script_loc); | |
} | |
function resolveHostnameIP() | |
{ | |
$shell_cmd = 'ping elephantbox.net'; | |
$results = shell_exec($shell_cmd); | |
$result_array = explode("\n", $results); | |
$result_line = null; | |
foreach ($result_array as $result) { | |
if (strpos($result, 'elephantbox.net') !== FALSE) { | |
$result_line = $result; | |
} | |
} | |
if ($result_line !== null) { | |
$result_line_array = explode('[', $result_line); | |
$raw_ip = trim(explode(']', $result_line_array[1])[0]); | |
} else { | |
//Unable to resolve Hostname so leave the shortcuts alone and exit | |
exit(); | |
} | |
return $raw_ip; | |
} | |
function createShortcutScript($ip, $port, $password) | |
{ | |
$line = 'set WshShell = WScript.CreateObject("WScript.Shell")'; | |
$line .= "\n" . 'set oShellLink = WshShell.CreateShortcut(Wscript.Arguments.Named("shortcut") & ".lnk")'; | |
$line .= "\n" . 'oShellLink.Arguments = "+connect ' . $ip . ':' . $port . ' +password " & Chr(34) & "' . $password . '" & Chr(34)'; | |
$line .= "\n" . 'oShellLink.TargetPath = Wscript.Arguments.Named("target")'; | |
$line .= "\n" . 'oShellLink.WindowStyle = 1'; | |
$line .= "\n" . 'oShellLink.Save'; | |
return $line; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment