Open hebjor opened 1 month ago
Can you reopen script, try again and let me know if it still happens?
Yes, same issue
`Friday, September 13, 2024 9:30:45 PM
PS D:\games\D2RLoader> .\D2Loader.ps1 Couldn't get D2Emu connection Token. Press any key to continue...`
Are you able to get to the d2emu website? https://d2emu.com/
If so, can you run these two commands in PowerShell and screenshot what you get:
(invoke-webrequest https://d2emu.com/api/v1/shupertoken/aes).content | convertfrom-json
((invoke-webrequest https://d2emu.com/api/v1/shupertoken/token).content | convertfrom-json).token
Yes, website works fine. I use it for checking TZ and never had any issues with it.
The first command returns a blank line, the 2nd seem to return nothing.
That's really odd. What do you get when you simply run the following:
invoke-webrequest https://d2emu.com/api/v1/shupertoken/aes
invoke-webrequest https://d2emu.com/api/v1/shupertoken/token
Are you using your own internet connection? Wondering if the connection is being blocked via a proxy or firewall.
Yes, it is my own internet. It is 1000/1000 fiber and as far as I know there are no restrictions (firewall or proxy). As far as I can tell this is just normal https traffic. Could it be d2emu.com is using some kind of Cloudflare caching that causes this?
I tried to remote desktop into my computer back in Europe and get different results that seem to make more sense. I will install a VPN and do some more testing from Thailand. It seems the Thailand internet connection is the issue.
It's definitely an internet connection / firewall issue as there aren't any issues with D2Emu's API. That said, I'll reach out to them to see if there's any geo blocking going on.
Yeah, this is very strange. I installed NordVPN and tried from both Singapore and US but get the same empty results. It makes me wonder if it could be something local on my computer. It's kinda weird since it is fresh Windows 11 install. I have disabled Windows Defender and Windows Firewall. I will do some more testing in my end, and see if I can install it on an old Windows laptop.
What about another URL, does this return no content?
Invoke-webrequest -uri https://v2.jokeapi.dev/joke/miscellaneous
Also, try this command
Invoke-WebRequest -Uri "https://d2emu.com/api/v1/shupertoken/aes" -Proxy $null
It worked! So there must be some sort of proxy somewhere. I also tried the previous commands on a Windows 10 laptop I have and it also works. So this must be some local problem on my new pc.
The jokeapi works without the proxy parameter
Clearly a local problem on this Windows 11 pc, but I have no idea where that proxy comes from. When I run some commands to check it does not report any proxy.
You can also use this to check proxy
Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'
Or open "internet options" from start menu (the old menu you might recognise from Internet Explorer back in the day):
This is very weird, now it actually works without the -Proxy too.
Also D2Rloader starts and works just fine.
I have no idea what is going on here, but I'm very happy it works! Thanks so much for the help
Glad to hear :)
Not understanding what was wrong drove me crazy so I did some more testing, and it seems to be the version of PS that caused the issue.
Powershell 7.4.5 fails
Powershell 5.1.22621.4111 works
also the -Proxy parameter does not seem to make any difference, it was just a random thing I started PS via CMD I got the older version. I normally start it via Windows Terminal which starts the latest version.
Not understanding what was wrong drove me crazy so I did some more testing, and it seems to be the version of PS that caused the issue.
Powershell 7.4.5 fails
Powershell 5.1.22621.4111 works
also the -Proxy parameter does not seem to make any difference, it was just a random thing I started PS via CMD I got the older version. I normally start it via Windows Terminal which starts the latest version.
Thanks for the details mate. I will have a think about how I can prevent this happening going forward.
I've not been able to figure out the connection problems. It also happens with curl and invoke-restmethod when connecting to that site. It's likely an issue with cloudflare or the webserver. As a workaround, try replacing the GetEmuToken Function with the below and let me know if it works. This will force PS 7.x to run those commands in PS 5.1:
Function GetEmuToken { #For connecting to D2Emu for tz and/or dclone data
Try {
if ($PSVersionTable.psversion.major -ge 7){# Run a PowerShell 5.1 script from within PowerShell 7.x, for whatever reason no content is returned on PS 7.x. Identified in https://github.com/shupershuff/Diablo2RLoader/issues/51
$AES = & "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -Command {(invoke-webrequest https://d2emu.com/api/v1/shupertoken/aes).content | convertfrom-json}
$EncryptedToken = & "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -Command {((invoke-webrequest https://d2emu.com/api/v1/shupertoken/token).content | convertfrom-json).token}
}
Else {
$AES = (invoke-webrequest https://d2emu.com/api/v1/shupertoken/aes).content | convertfrom-json
$EncryptedToken = ((invoke-webrequest https://d2emu.com/api/v1/shupertoken/token).content | convertfrom-json).token
}
$Key = $AES.key
$IV = $AES.iv
$bytes = [System.Convert]::FromBase64String($EncryptedToken);
$aes = [System.Security.Cryptography.Aes]::Create();
$utf8 = [System.Text.Encoding]::Utf8;
$aes.Key = $utf8.GetBytes($key);
$aes.IV = $utf8.GetBytes($iv);
$decryptor = $aes.CreateDecryptor();
$unencryptedData = $decryptor.TransformFinalBlock($bytes, 0, $bytes.Length);
$aes.Dispose();
$Script:EmuToken = [System.Text.Encoding]::UTF8.GetString($unencryptedData); #Decrypted token
}
Catch {
write-output " Couldn't get D2Emu connection Token." | red
PressTheAnyKey
}
}
I can confirm the GetEmuToken function above works on latest Powershell version.
Hi & thanks for a great tool,
I'm using version 1.13.2
Recently I started to get this message when I start
I tried all 3 different sites (d2emu.com, D2runewizard.com and diablo2.io) but get same error message with all of them.
When I do a "r" to refresh I keep getting "Unable to check for DClone status via d2emu.com." When I do a "d" to check DClone status I get these error messages
Connecting to d2emu.com website works fine in a browser. I'm connecting from Thailand/Asia.