Wednesday, October 08, 2008

Silkroad Online Automated Login

I play Silkroad Online. They aren't exactly the best of MMORPGs around, but I'm in nonetheless. This post is about a (semi-) auto login script I came up with for my own convenience. Nothing special, it's just a combination of mouse clicks and keystrokes that the script can do on your behalf.

This is not a hack, and I don't believe there is anything illegal about it. The script stops after clicking on the "Connect" button in the login page.

Firstly download the AutoIt3 scripting utility here.

Next, copy the following codes for sro_login.au3 into a text file named sro_login.au3 (duh) and if it can't find sro_login.ini in the same folder when you run it for the first time, you will be prompted for your username and password. Your credentials will then be stored (unencrypted!) in the said .ini file for subsequent use.

Then create a shortcut to trigger the .au3 script instead of using your usual SRO shortcut. You may also want to choose the SRO icon for this shortcut too.

Here's what it does in summary:
  1. Run Silkroad.exe (the launcher)
  2. Waits until the "News" gets loaded
  3. Clicks on the Start button
  4. Waits for 10.5s so that the cinematics start playing
  5. Fills in your username and password to login
  6. Quit

sro_login.ini (the main script will prompt you to create this on first run)

[SRO_Client]
username=enter_your_own_username
password=enter_your_own_password


sro_login.au3


;Author: Ken Kum, 2008.
;Email: shiver.me.timbers.sg@gmail.com
;License: LGPL.
;Version: 1.0


$ini_filename = StringReplace(@ScriptName, "au3", "ini")
$sro_client_var = "SRO_Client"

$launcher_title = "Silkroad Online Launcher"
$client_filename = "sro_client.exe"
$USERNAME_KEY = "username"

$PASSWORD_KEY = "password"
$username = IniRead($ini_filename, $sro_client_var, $USERNAME_KEY, "")

$pwd = IniRead($ini_filename, $sro_client_var, $PASSWORD_KEY, "")

$exe_filename = @ProgramFilesDir & "\Silkroad\Silkroad.exe"

;Create ini file if not found
if FileExists($ini_filename) = 0 Then

$username = InputBox("Creating ini file...", "Username:", "", "", 150, 120)

if @error = 1 Then
MsgBox(0, "Create failed!", "Unable to proceed without ini file. Quitting.")

Exit
EndIf

$pwd = InputBox("Creating ini file...", "Password (Stored unencrypted!):", "", "*", 200, 120)

if @error = 1 Then
MsgBox(0, "Create failed!", "Unable to proceed without ini file. Quitting.")

Exit
EndIf

if not $username = "" and not $pwd = "" Then

IniWrite($ini_filename, $sro_client_var, $USERNAME_KEY, $username)

IniWrite($ini_filename, $sro_client_var, $PASSWORD_KEY, $pwd)

EndIf
EndIf

;Validate credentials
if $username = "" or $pwd = "" Then

MsgBox(0, "Unable to continue", "Error reading INI file {" & $ini_filename & "} !")

Exit
EndIf

;Run launcher
Run($exe_filename)
if WinWaitActive($launcher_title) = 0 Then

Exit
EndIf
if WinActivate("Silkroad") = 0 Then

Exit
EndIf

;Wait for News to be ready
$dimensions = WinGetPos($launcher_title)

if $dimensions = 0 Then
Exit
EndIf
$timeout = TimerInit()

$checksum = PixelChecksum($dimensions[0], $dimensions[1], $dimensions[0] + 300, $dimensions[1] + 100)

while $checksum = PixelChecksum($dimensions[0], $dimensions[1], $dimensions[0] + 300, $dimensions[1] + 100)

Sleep(1000)
if TimerDiff($timeout) > 15000 Then

Exit
EndIf
WEnd

;Click on Start button in launcher
MouseClick("left", $dimensions[0] + 615, $dimensions[1] + 355)

if ProcessWait($client_filename, 60) = 0 Then
Exit

MsgBox(0, "Login Process", "Failed. Quitting!")
EndIf

;Wait for cinematics to load

Sleep(11000)

;Enter credentials
if WinActivate($sro_client_var) Then

if WinActive($sro_client_var) Then
Send("{SPACE}")

sleep(500)
Send($username)

sleep(500)
Send("{TAB}")

sleep(500)
Send($pwd)

sleep(500)
Send("{ENTER}")

;Pass control back to user for Captcha image
EndIf
EndIf

Exit


And that's it, you're good to go. I know it's somewhat primitive, but hey it works for me. Give it a spin and let me know if you like it!

4 comments:

Anonymous said...

Hey, thanks! Works for me. I was getting tired of typing my username/pass every time just to be kicked off because of a crowded server.
I can live with just typing the captcha!

ken said...

thanks! it's nice to hear!

Anonymous said...

hay man i make the ini file and i make the sro_login.au3 then i do exctly what u said after i file my password i quit prss strat it do no thing

ken said...

Hi, you may want to try deleting the ini file and let my program create one instead?

Also, I had this running on Vista, so I don't suppose the 10.5s delay for the cinematics might have to be extended a little more on older OS's.