Skip to content

Commit 0ef9a8d

Browse files
authored
Update D2Loader.ps1
1 parent adf9164 commit 0ef9a8d

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

D2Loader.ps1

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ if ($Script:AccountOptionsCSV -ne $null){
168168
}
169169
if ($Entry.PW.length -eq 0){#if csv has account details but password field has been left blank
170170
write-host
171-
write-host ("The account " + $Entry.AccountLabel + "Does not currently have a password defined.") -foregroundcolor yellow
171+
write-host ("The account " + $Entry.AccountLabel + " doesn't yet have a password defined.") -foregroundcolor yellow
172172
write-host
173173
$Entry.pw = read-host -AsSecureString "Enter the Battle.net password for"$Entry.AccountLabel
174174
$Entry.pw = $Entry.pw | ConvertFrom-SecureString
@@ -524,14 +524,15 @@ Function ChooseRegion {#AKA Realm. Not to be confused with the actual Diablo ser
524524
}
525525

526526
Function Processing {
527+
527528
if (($script:pw -eq "" -or $script:pw -eq $null) -and $script:pwmanualset -eq 0 ){
528529
$script:pw = $Script:AccountChoice.pw.tostring()
529530
}
530531
if ($script:ParamsUsed -ne $true -and $ConvertPlainTextPasswords -ne $false){
531532
$script:acct = $Script:AccountChoice.acct.tostring()
532533
$encryptedPassword = $pw | ConvertTo-SecureString
533-
$pw = New-Object System.Management.Automation.PsCredential("N/A", $encryptedPassword)
534-
$script:pw = $pw.GetNetworkCredential().Password
534+
$pwobject = New-Object System.Management.Automation.PsCredential("N/A", $encryptedPassword)
535+
$script:pw = $pwobject.GetNetworkCredential().Password
535536
}
536537
else {
537538
$script:acct = $script:AccountUsername
@@ -548,25 +549,32 @@ Function Processing {
548549
#Open diablo with parameters
549550
# IE, this is essentially just opening D2r like you would with a shortcut target of "C:\Program Files (x86)\Battle.net\Games\Diablo II Resurrected\D2R.exe" -username <yourusername -password <yourPW> -address <SERVERaddress>
550551
$arguments = (" -username " + $script:acct + " -password " + $script:PW +" -address " + $Script:Region).tostring()
552+
$script:pw = $null
551553
#write-output $arguments #debug
552554
Start-Process "$Gamepath\D2R.exe" -ArgumentList "$arguments"
553-
start-sleep -milliseconds 1500
554-
555+
start-sleep -milliseconds 1250 #give D2r a bit of a chance to start up before trying to kill handle
555556
#Close the 'Check for other instances' handle
556557
Write-host "Attempting to close `"Check for other instances`" handle..."
557-
$maxattempts = 5 #try closing 20 times.
558+
$attempt = 0
559+
$maxattempts = 10 #try closing x amount of times.
558560
do {#wait for d2r process to start
561+
#$output = "test" #debug
562+
#$handlekilled = $true #debug
563+
$attempt = $attempt + 1
564+
write-host ("Attempt " + $attempt + " of $maxattempts" +"....")
559565
$output = killhandle | out-string
560-
start-sleep -milliseconds 1000
561566
if(($output.contains("DiabloII Check For Other Instances")) -eq $true){
562567
$handlekilled = $true
563-
$attempt = $attempt + 1
564-
write-host ("Attempt " + $attempt + "....")
565568
write-host "Check for Other Instances Handle closed." -foregroundcolor green
566-
}
569+
}
570+
else {
571+
start-sleep -milliseconds 1000 #if handle couldn't be closed give it another second before trying again.
572+
}
567573
} until ($handlekilled -eq $True -or $attempt -eq $maxattempts)
568574
if ($attempt -eq $maxattempts){
569575
Write-Host " Couldn't find any handles to kill." -foregroundcolor red
576+
Write-Host " Game may not have launched as expected." -foregroundcolor red
577+
pause
570578
}
571579
#Rename the Diablo Game window for easier identification of which account and region the game is.
572580
$rename = ($Script:AccountID + " - Diablo II: Resurrected - " + $Script:AccountFriendlyName + " (" + $Script:Region + ")")
@@ -579,6 +587,7 @@ Function Processing {
579587
}
580588
catch {
581589
write-host "Couldn't rename window :(" -foregroundcolor red
590+
pause
582591
}
583592
start-sleep -milliseconds 100
584593
$Script:ScriptHasBeenRun = $true

0 commit comments

Comments
 (0)