Skip to content

Instantly share code, notes, and snippets.

@knightli
Last active February 26, 2026 01:33
Show Gist options
  • Select an option

  • Save knightli/05ea5f3e92de7a3213eeb7a0d26ba110 to your computer and use it in GitHub Desktop.

Select an option

Save knightli/05ea5f3e92de7a3213eeb7a0d26ba110 to your computer and use it in GitHub Desktop.
### D2RTokenStart ######
# 一个简单的D2R令牌启动脚本
# 作者: 萌爸奈特李
# 说明: 这个脚本可以让你使用令牌的方式启动国服D2R
#
# 用法:
# 重点关注下面【包裹的文字部分】,修改①②③三个地方即可
# 然后将本文件放置在任何地方,右键,使用Powershell启动
# 如果好用,请关注 B站 萌爸奈特李 https://space.bilibili.com/34371318
# 欢迎关注/投币/点赞
#######################
### !必读 !############
# 注意: 使用令牌可以登录你的账号,因此务必保密
# 一旦泄露,请立即在战网上修改密码,这样所有令牌会失效
#
### 令牌方式登录的好处 ###
# 1. 无需多浏览器实例:可以同时认证多个账号
# 2. 不受30天限制:(对比国服网易游戏网页授权)令牌长期有效,除非修改战网密码
# 3. 安全性高:(对比国服网易游戏方式授权登录)网易游戏一旦给人授权,30天始终有效,无法撤回,改密码都没用(令牌若泄露,修改密码后可使令牌失效)
#
###########################
### 以下为启动脚本正文 ###
# 以管理员启动
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
$Region = "CN"
# 【修改下面的 Token 和 GamePath】
#### 获取 Token 的方法 ####
# 建议使用Edge浏览器,开隐私模式
# 访问这个地址 https://account.battlenet.com.cn/login/cn/?externalChallenge=login&app=OSI
# 需要用【战网账号密码】(注意,不是网易游戏账号)登录(请注意域名,这是网易国服战网的官方域名,不是钓鱼网站 )
# 登录后会打开的貌似错误的页面,页面中间显示了一些文字 里面就有令牌
# 令牌的格式为:服务器标识-32位16进制字符串-9位数字
######################
$Token = "CN-d12ab21123abcdefabcdefabcdef1231-123123123" # 【①改为自己的Token】
### 我只知道网易游戏账号,不知道战网账号密码怎么办? ###
# 如果用网易游戏账号创建的战网号,账号就是手机号,但密码是后台默认生成的密码,谁都不知道默认密码是什么
# 因此密码需要访问 https://account.battlenet.com.cn/recovery/?ref=&theme=bnet-next&app=oauth&hostingApp=oauth
# 点忘记密码,用手机号接收验证码后,可重设密码。
# 如此,你便知道了战网号的账号(手机号)和密码(你刚才重设的)
# 之后再去获取Token即可
###############
# 【②改为国服的D2R游戏目录】
$GamePath = "C:\Program Files (x86)\Diablo II Resurrected"
$Entropy = @(0xc8, 0x76, 0xf4, 0xae, 0x4c, 0x95, 0x2e, 0xfe, 0xf2, 0xfa, 0x0f, 0x54, 0x19, 0xc0, 0x9c, 0x43)
$TokenBytes = [System.Text.Encoding]::UTF8.GetBytes($Token)
$EntropyBytes = [byte[]] $Entropy
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Security")
$ProtectedData = [System.Security.Cryptography.ProtectedData]::Protect($TokenBytes, $EntropyBytes, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)
$Path = "HKCU:\SOFTWARE\Blizzard Entertainment\Battle.net\Launch Options\OSI"
Set-ItemProperty -Path $Path -Name "REGION" -Value $Region
Set-ItemProperty -Path $Path -Name "WEB_TOKEN" -Value $ProtectedData -Type Binary
### 【③如果用Mod则需要改一下下面的ModArgs】
# - 如果用了Mod,则修改这里的-mod这部分的参数内容
# - 如果没用Mod,则将下面这个字符串改为空字符串,就像下面这行这样
# $ModArgs = ""
###########
$ModArgs = "-mod MDK -txt"
if ($ModArgs) {
Start-Process "$Gamepath\D2R.exe" -ArgumentList "-uid", "OSI", $ModArgs
} else {
Start-Process "$Gamepath\D2R.exe" -ArgumentList "-uid", "OSI"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment