Skip to content

Commit 826de0c

Browse files
authored
Update D2Loader.ps1
1 parent 8a6ee53 commit 826de0c

File tree

1 file changed

+7
-101
lines changed

1 file changed

+7
-101
lines changed

D2Loader.ps1

Lines changed: 7 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Servers:
2020
2121
Changes since 1.9.0 (next version edits):
2222
Added Token based authentication. There are some setup steps and drawbacks to using this method but this can help when Blizzard Auth servers don't respond to authentication when launching via parameters.
23+
Added capability to configure accounts for Parameter based auth but being able to temporarily force Token authentication (useful for connecting to a region when it's auth is down such as Asia right now).
2324
Added notification capability so if I notice one of the auth servers going down I can advise users directly.
2425
Added a new version of the SetText source code to enable renaming D2r windows based on processID. This prevents issues for people who load an account from Battle.net in addition to using the script.
2526
Changed Current and Next TZ source to D2Emu.com for faster and more accurate results (no more OCR delays or inaccuracies).
@@ -30,9 +31,6 @@ Fixed unhandled DClone errors for timeouts.
3031
Fixed DClone alarm from alarming twice when detecting changes from 6/6 to 1/6 on some sources.
3132
Minor tidy ups.
3233
33-
##########TEST IMMEDIATELY AFTER RELEASE, test if settextv2.bas is downloaded and extracted.
34-
#do before release, delete all .zip files in other releases.
35-
3634
1.10.1+ to do list
3735
To reduce lines, Tidy up all the import/export csv bits for stat updates into a function rather than copy paste the same commands throughout the script.
3836
To reduce lines, add repeated commands into functions
@@ -42,7 +40,7 @@ Fix whatever I broke or poorly implemented in 1.10.0 :)
4240
#>
4341

4442
param($AccountUsername,$PW,$Region,$All,$Batch,$ManualSettingSwitcher) #used to capture parameters sent to the script, if anyone even wants to do that.
45-
$CurrentVersion = "1.9.2"
43+
$CurrentVersion = "1.10.0"
4644

4745
###########################################################################################################################################
4846
# Script itself
@@ -626,7 +624,6 @@ $BooleanConfigs =
626624
"ForceWindowedMode",
627625
"SettingSwitcherEnabled",
628626
"TrackAccountUseTime"
629-
630627
$AvailableConfigs = $AvailableConfigs + $BooleanConfigs
631628

632629
if ($Script:Config.CheckForNextTZ -ne $true -and $Script:Config.CheckForNextTZ -ne $false){#if CheckForNextTZ config is invalid, set to false
@@ -803,8 +800,7 @@ Function ImportCSV {
803800
}
804801
# Export the updated CSV data back to the file
805802
$Script:AccountOptionsCSV | Export-Csv -Path "$Script:WorkingDirectory\Accounts.csv" -NoTypeInformation
806-
}
807-
803+
}
808804
if (-not ($Script:AccountOptionsCSV | Get-Member -Name "CustomLaunchArguments" -MemberType NoteProperty -ErrorAction SilentlyContinue)) {#For update 1.8.0. If CustomLaunchArguments column doesn't exist, add it
809805
# Column does not exist, so add it to the CSV data
810806
$Script:AccountOptionsCSV | ForEach-Object {
@@ -1126,6 +1122,9 @@ Function Inventory {#Info screen
11261122
write-host ("`"$Script:WorkingDirectory`"" -replace "((.{1,52})(?:\\|\s|$)|(.{1,53}))", "`n `$1").trim() #add two spaces before any line breaks for indenting. Add line break for paths that are longer than 53 characters.
11271123
write-host " $X[4mYour Script Version:$X[0m v$CurrentVersion"
11281124
write-host " https://github.com/shupershuff/Diablo2RLoader/releases/v$CurrentVersion"
1125+
if($Script:ForceAuthToken -ne $null){
1126+
write-host " $X[4mForceAuthToken:$X[0m $Script:ForceAuthToken"
1127+
}
11291128
if($Script:LatestVersionCheck -eq $null -or $Script:LatestVersionCheck.tostring() -lt (Get-Date).addhours(-2).ToString('yyyy.MM.dd HH:mm:ss')){ #check for updates. Don't check if this has been checked in the couple of hours.
11301129
try {
11311130
$Releases = Invoke-RestMethod -Uri "https://api.github.com/repos/shupershuff/Diablo2RLoader/releases"
@@ -1170,6 +1169,7 @@ Function Inventory {#Info screen
11701169
Write-Host " AuthenticationMethod column in accounts.csv" -foregroundcolor green
11711170
}
11721171
start-sleep -milliseconds 5400
1172+
Write-Host
11731173
}
11741174
}
11751175

@@ -1659,7 +1659,6 @@ Function DClone {# Display DClone Status.
16591659
[VOID]$DCloneNonLadderTable.Add($DCloneNonLadderInfo)
16601660
}
16611661
if ($True -eq $DisableOutput){
1662-
#$taglist = "SCL-NA, SCL-EU, HC-EU, HC-KR"#"SCL-NA, SCL-EU, SCL-KR, SC-NA, SC-EU, SC-KR, HCL-NA, HCL-EU, HCL-KR, HC-NA, HC-EU, HC-KR"
16631662
if ($taglist -match $Tag ){#if D Dclone region and server matches what's in config, check for changes.
16641663
#Write-Host " Tag $tag in taglist" #debug
16651664
if ($DCloneChangesArray | where-object {$_.Tag -eq $Tag}){
@@ -1900,96 +1899,6 @@ Function TerrorZone {
19001899
PressTheAnyKey
19011900
}
19021901
}
1903-
Function TerrorZoneOld {
1904-
# Get the current time data was pulled
1905-
$TimeDataObtained = (Get-Date -Format 'h:mmtt')
1906-
#Find Current TZ
1907-
Write-Host " Finding Current TZ Name..."
1908-
$FlyURI = "https://d2rapi.fly.dev/" #Get TZ from d2rapi.fly.dev
1909-
$D2FlyTZResponse = Invoke-WebRequest -Uri $FlyURI -Method GET -header $headers
1910-
$CurrentTZ = ($D2FlyTZResponse | Select-String -Pattern '(?<=<\/a> - )(.*?)(?=<br>)' -AllMatches | ForEach-Object { $_.Matches.Value })[0]
1911-
$CurrentTZProvider = "d2rapi.fly.dev"
1912-
1913-
if ($CheckForNextTZ -ne $False){ #Find Next TZ image and convert to Text.
1914-
Write-Host " Finding Next TZ Name..."
1915-
$NextTZProvider = "thegodofpumpkin"
1916-
$75988Pool = @(#choose from pool of various connection details for OCR.Space to reduce chances of the free limit being reached. Helps future proof script if it ever becomes popular.
1917-
"75988770481418K",
1918-
"75988177170718K",
1919-
"75988024702278K",
1920-
"75988372514768K",
1921-
"75988875571688K",
1922-
"75988639433138K",
1923-
"75988074942078K",
1924-
"75988074727148K",
1925-
"75988080905848K",
1926-
"75988156278288K"
1927-
)
1928-
$tokreg = $75988Pool | Get-Random
1929-
$script:D2ROCRref = $Null
1930-
for ($i = $tokreg.Length - 1; $i -ge 0; $i--) {
1931-
$script:D2ROCRref += $tokreg[$i]
1932-
}
1933-
$Script:OCRAttempts = 0
1934-
do { ## Try each OCR engine until success. I've noticed that OCR.Space engines sometimes go down causing the script not being able to detect current TZ. This gives it a bit more reliability, albeit at the cost of time for each additional attempt.
1935-
$Script:OCRAttempts ++
1936-
$Engine = (2,1,3)[$Script:OCRAttempts-1] #try engines in order of the best quality: Engine 2, then 1 then 3.
1937-
$NextTZOCR = WebRequestWithTimeOut -InitiatingFunction "TZ_OCR" -ScriptBlock {
1938-
param ($EngineNumber) #Run the scriptblock with $EngineNumber as a parameter. This way we can insert the variable $Engine into the scriptblock. It's not possible to insert this variable into the script block any other way.
1939-
(((Invoke-WebRequest -Uri ("https://api.ocr.space/parse/imageurl?apikey=" + $Using:D2ROCRref + "&filetype=png&isCreateSearchablePdf=false&OCREngine=" + $EngineNumber + "&scale=true&url=https://thegodofpumpkin.com/terrorzones/terrorzone.png") -ErrorAction Stop).Content | ConvertFrom-Json).ParsedResults.ParsedText)
1940-
} -TimeoutSeconds 13 #allow up to 13 seconds per request. Standard requests are around 3 seconds but as it's a free service it can sometimes be slow. Most of the time when it takes longer than 10 seconds to retrieve OCR it fails. Default timeout from OCR.Space (when an engine is down) is actually 30 seconds before an error is thrown.
1941-
if ($SuccessfulEngine -ne $null){
1942-
$NextTZOCR = $NextTZOCR.replace(": :","::") # Prevents issues if OCR mistakenly reads "::" as ": :" eg: Next TerrorZone(s) : : Barracks / Jail 1 / Jail 2 / Jail 3
1943-
if ($SuccessfulEngine -eq 2){#For Engine 2
1944-
$NextTZ = [regex]::Match($NextTZOCR.Replace("`n", ""), "(?<=Next TerrorZone(?:\s)?(?:\(s\))?(?:\s)?(?:\.|::) ).*").Value #Regex for engine 2
1945-
} Elseif ($SuccessfulEngine -eq 1){#For Engine 1
1946-
$NextTZ = ($NextTZOCR.trim() -split "`n")[-1].replace("Next TerrorZone(s)","").replace(".","").replace(":","").trim() #Regex for engine 1
1947-
} Elseif ($SuccessfulEngine -eq 3) {#For Engine 3
1948-
$NextTZ = $nexttzocr -replace "\r?\n", " " -replace "(?s).*Next TerrorZone\Ss\S\s","" #Regex for engine 3
1949-
}
1950-
}
1951-
$Script:SuccessfulEngine = $Null
1952-
if ($OCRSuccess -eq $False){
1953-
$FailMessage = "Was unable to pull next TZ details :("
1954-
}
1955-
if ($NextTZ -eq ""){#if next tz variable is empty due to OCR not working.
1956-
$FailMessage = "OCR failure, couldn't read next TZ details :("
1957-
$Script:OCRSuccess = $False
1958-
if ($Script:OCRAttempts -ne 3){
1959-
Write-Host " First Crack failed, having attempt number" ($Script:OCRAttempts + 1)
1960-
$TryAgain = $True
1961-
}
1962-
Else {
1963-
$TryAgain = $False
1964-
}
1965-
}
1966-
} until ($true -eq $Script:OCRSuccess -or ($Script:OCRAttempts -eq 3 -and $OCRSuccess -eq $false -and $TryAgain -ne $true))
1967-
}
1968-
if ($Script:OCRSuccess -eq $False -or $CheckForNextTZ -eq $False){# Messages if things are unsuccessful pulling Next TZ
1969-
Write-Host
1970-
Write-Host " Current TZ is: " -nonewline;Write-Host ($CurrentTZ -replace "(.{1,58})(\s+|$)", "`$1`n ").trim() -ForegroundColor magenta #print next tz. The regex code helps format the string into an indented new line for longer TZ's.
1971-
if ($CheckForNextTZ -ne $False){
1972-
$FailMessage += "`n Attempts made: $Script:OCRAttempts`n Token used: $tokreg"
1973-
Write-Host " Next TZ info unavailable: $FailMessage" -ForegroundColor Red
1974-
}
1975-
Write-Host
1976-
Write-Host " Information Retrieved at: " $TimeDataObtained
1977-
Write-Host " Current TZ pulled from: $CurrentTZProvider"
1978-
Write-Host
1979-
PressTheAnyKey
1980-
}
1981-
else {# Messages if things are succesful pulling Next TZ
1982-
Write-Host
1983-
Write-Host " Current TZ is: " -nonewline;Write-Host ($CurrentTZ -replace "(.{1,58})(\s+|$)", "`$1`n ").trim() -ForegroundColor magenta
1984-
Write-Host " Next TZ is: " -nonewline;Write-Host ($NextTZ -replace "(.{1,58})(\s+|$)", "`$1`n ").trim() -ForegroundColor magenta
1985-
Write-Host
1986-
Write-Host " Information Retrieved at: " $TimeDataObtained
1987-
Write-Host " Current TZ pulled from: $CurrentTZProvider"
1988-
Write-Host " Next TZ pulled from: $NextTZProvider"
1989-
Write-Host
1990-
PressTheAnyKey
1991-
}
1992-
}
19931902

19941903
Function Killhandle {#kudos the info in this post to save me from figuring it out: https://forums.d2jsp.org/topic.php?t=90563264&f=87
19951904
& "$PSScriptRoot\handle\handle64.exe" -accepteula -a -p D2R.exe > $PSScriptRoot\d2r_handles.txt
@@ -2800,8 +2709,6 @@ Function Processing {
28002709
}
28012710
#Rename the Diablo Game window for easier identification of which account and region the game is.
28022711
$rename = ($Script:AccountID + " - " + $Script:AccountFriendlyName + " (" + $Script:Region + ")" +" - Diablo II: Resurrected")
2803-
#$Command = ('"'+ $WorkingDirectory + '\SetText\SetText.exe" "Diablo II: Resurrected" "' + $rename +'"')
2804-
#$Command = ('"'+ $WorkingDirectory + '\SetText\SetTextv2.exe" /WindowToRename "Diablo II: Resurrected" "' + $rename +'"')
28052712
$Command = ('"'+ $WorkingDirectory + '\SetText\SetTextv2.exe" /PID ' + $process.id + ' "' + $rename + '"')
28062713
try {
28072714
cmd.exe /c $Command
@@ -2838,7 +2745,6 @@ Function Processing {
28382745
}
28392746
Start-Sleep -milliseconds 1000
28402747
$Script:ScriptHasBeenRun = $true
2841-
cls
28422748
}
28432749
}
28442750
}

0 commit comments

Comments
 (0)