Merge branch 'main' into auth
This commit is contained in:
@@ -113,10 +113,18 @@ Public Module ModLaunch
|
||||
New LoaderTask(Of Process, Integer)("等待游戏窗口出现", AddressOf McLaunchWait) With {.ProgressWeight = 1},
|
||||
New LoaderTask(Of Integer, Integer)("结束处理", AddressOf McLaunchEnd) With {.ProgressWeight = 1}
|
||||
}
|
||||
If Setup.Get("LaunchArgumentRam") Then
|
||||
CType(Loaders(2), LoaderCombo(Of String)).Block = False
|
||||
Loaders.Insert(3, New LoaderTask(Of Integer, Integer)("内存优化", AddressOf McLaunchMemoryOptimize) With {.ProgressWeight = 30})
|
||||
End If
|
||||
'内存优化
|
||||
Select Case Setup.Get("VersionRamOptimize", Version:=McVersionCurrent)
|
||||
Case 0 '全局
|
||||
If Setup.Get("LaunchArgumentRam") Then '使用全局设置
|
||||
CType(Loaders(2), LoaderCombo(Of String)).Block = False
|
||||
Loaders.Insert(3, New LoaderTask(Of Integer, Integer)("内存优化", AddressOf McLaunchMemoryOptimize) With {.ProgressWeight = 30})
|
||||
End If
|
||||
Case 1 '开启
|
||||
CType(Loaders(2), LoaderCombo(Of String)).Block = False
|
||||
Loaders.Insert(3, New LoaderTask(Of Integer, Integer)("内存优化", AddressOf McLaunchMemoryOptimize) With {.ProgressWeight = 30})
|
||||
Case 2 '关闭
|
||||
End Select
|
||||
Dim LaunchLoader As New LoaderCombo(Of Object)("Minecraft 启动", Loaders) With {.Show = False}
|
||||
If McLoginLoader.State = LoadState.Finished Then McLoginLoader.State = LoadState.Waiting '要求重启登录主加载器,它会自行决定是否启动副加载器
|
||||
'等待加载器执行并更新 UI
|
||||
@@ -217,7 +225,7 @@ NextInner:
|
||||
"如果觉得 PCL 还算好用的话,也可以考虑赞助一下作者……一点心意也行……" & vbCrLf &
|
||||
"毕竟一个人开发也不容易(悲)……",
|
||||
"求赞助啦……", "这就赞助!", "但是我拒绝") = 1 Then
|
||||
OpenWebsite("https://afdian.net/a/LTCat")
|
||||
OpenWebsite("https://afdian.com/a/LTCat")
|
||||
End If
|
||||
End Select
|
||||
End Sub, "Donate")
|
||||
@@ -502,10 +510,8 @@ NextInner:
|
||||
If Input.OAuthRefreshToken = "" Then
|
||||
'无 RefreshToken
|
||||
Relogin:
|
||||
Dim OAuthCode As String = MsLoginStep1(Data, ClientId)
|
||||
If OAuthCode = "Cancel" Then
|
||||
Exit Sub
|
||||
End If
|
||||
Dim OAuthCode As String = MsLoginStep1(Data)
|
||||
If OAuthCode = "Cancel" Then Exit Sub
|
||||
If Data.IsAborted Then Throw New ThreadInterruptedException
|
||||
Data.Progress = 0.2
|
||||
OAuthTokens = MsLoginStep2(OAuthCode, False, ClientId)
|
||||
@@ -802,43 +808,21 @@ LoginFinish:
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'微软登录步骤 1:获取 DeviceCode 并显示验证提示
|
||||
Private Function MsLoginStep1(Data As LoaderTask(Of McLoginMs, McLoginResult), ClientId As String) As String
|
||||
If MyMsgBox("请在打开的网页里输入 PCL2 提供的设备代码(会自动复制到剪贴板)并登录微软账户,然后允许 PCL2 访问相关信息。" & vbCrLf & "设备代码有时效性,若操作时间过长需要重新进行登录流程。", "正版验证确认", "继续", "取消") = 1 Then
|
||||
McLaunchLog("开始微软登录步骤 1")
|
||||
|
||||
Dim DeviceCode As String
|
||||
Dim UserCode As String
|
||||
Dim VerifyUri As String
|
||||
Dim ExpiresIn As String
|
||||
Dim Request As String = "client_id=" & ClientId & "&" & "scope=XboxLive.signin%20offline_access"
|
||||
Dim Result As String = NetRequestMulty("https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode", "POST", Request, "application/x-www-form-urlencoded", 2)
|
||||
|
||||
Dim ResultJson As JObject = GetJson(Result)
|
||||
DeviceCode = ResultJson("device_code")
|
||||
UserCode = ResultJson("user_code")
|
||||
VerifyUri = ResultJson("verification_uri")
|
||||
ExpiresIn = ResultJson("expires_in")
|
||||
ClipboardSet(UserCode)
|
||||
OpenWebsite(VerifyUri)
|
||||
|
||||
Dim MsgBoxValue As String = ""
|
||||
While MsgBoxValue IsNot "1"
|
||||
MsgBoxValue = MyMsgBox("本次验证的设备代码为:" & UserCode & vbCrLf & vbCrLf & "你也可以在任意设备上打开下列网址进行验证:" & vbCrLf & VerifyUri & vbCrLf & vbCrLf & "在验证完成后,你可以直接关闭这个弹窗,PCL2 会自动完成接下来的流程。", "正版验证", "关闭", "复制网址", "复制设备代码").ToString
|
||||
If MsgBoxValue = "2" Then
|
||||
ClipboardSet(VerifyUri)
|
||||
Continue While
|
||||
ElseIf MsgBoxValue = "3" Then
|
||||
ClipboardSet(UserCode)
|
||||
Continue While
|
||||
ElseIf MsgBoxValue = "1" Then
|
||||
Exit While
|
||||
End If
|
||||
End While
|
||||
|
||||
Return DeviceCode
|
||||
'微软登录步骤 1:打开网页认证,获取 OAuth Code
|
||||
Private Function MsLoginStep1(Data As LoaderTask(Of McLoginMs, McLoginResult)) As String
|
||||
McLaunchLog("开始微软登录步骤 1")
|
||||
OpenWebsite(FormLoginOAuth.LoginUrl1)
|
||||
Dim Result As String =
|
||||
MyMsgBoxInput("等待网页登录",
|
||||
"登录完成后,网页会变得完全空白。把那个空白网页的网址复制到下面的框中就行!" & vbCrLf &
|
||||
"如果网络环境不佳,它可能一直加载不出来,那就只能试试用 VPN 或加速器了。",
|
||||
ValidateRules:=New ObjectModel.Collection(Of Validate) From {New ValidateRegex("(?<=code\=)[^&]+", "返回网址应以 https://login.live.com/oauth20_desktop.srf?code= 开头")},
|
||||
HintText:="https://login.live.com/oauth20_desktop.srf?code=XXXXXX")
|
||||
If Result Is Nothing Then
|
||||
McLaunchLog("微软登录已在步骤 1 被取消")
|
||||
Throw New ThreadInterruptedException("$$")
|
||||
Else
|
||||
Return "Cancel"
|
||||
Return RegexSeek(Result, "(?<=code\=)[^&]+")
|
||||
End If
|
||||
End Function
|
||||
|
||||
@@ -895,19 +879,112 @@ LoginFinish:
|
||||
Return {"Cancel", ""}
|
||||
|
||||
End Function
|
||||
|
||||
''微软登录步骤 1:获取 DeviceCode 并显示验证提示
|
||||
''https://learn.microsoft.com/zh-cn/entra/identity-platform/v2-oauth2-device-code
|
||||
'Private Function MsLoginStep1(Data As LoaderTask(Of McLoginMs, McLoginResult)) As String
|
||||
' McLaunchLog("开始微软登录步骤 1:获取验证信息")
|
||||
' Dim PrepareJson As JObject = GetJson(NetRequestMulty("https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode", "POST",
|
||||
' $"client_id={OAuthClientId}&scope=XboxLive.signin%20offline_access", "application/x-www-form-urlencoded", 2))
|
||||
|
||||
' '从这里开始直到步骤 2 结束都没有 Review
|
||||
' '参考:https://learn.microsoft.com/zh-cn/entra/identity-platform/v2-oauth2-device-code
|
||||
' If MyMsgBox("请在打开的网页里输入 PCL2 提供的设备代码(会自动复制到剪贴板)。" & vbCrLf &
|
||||
' "设备代码有时效性,若操作时间过长需要重新进行登录流程。", "正版验证确认", "继续", "取消") <> 1 Then
|
||||
' Return "Cancel"
|
||||
' End If
|
||||
|
||||
' Dim DeviceCode As String = PrepareJson("device_code")
|
||||
' Dim UserCode As String = PrepareJson("user_code")
|
||||
' Dim VerifyUri As String = PrepareJson("verification_uri")
|
||||
' 'ResultJson("expires_in")
|
||||
' ClipboardSet(UserCode)
|
||||
' OpenWebsite(VerifyUri)
|
||||
|
||||
' Dim MsgBoxValue As String = ""
|
||||
' While MsgBoxValue IsNot "1"
|
||||
' MsgBoxValue = MyMsgBox("本次验证的设备代码为:" & UserCode & vbCrLf & vbCrLf & "你也可以在任意设备上打开下列网址进行验证:" & vbCrLf & VerifyUri & vbCrLf & vbCrLf & "在验证完成后,你可以直接关闭这个弹窗,PCL2 会自动完成接下来的流程。", "正版验证", "关闭", "复制网址", "复制设备代码").ToString
|
||||
' If MsgBoxValue = "2" Then
|
||||
' ClipboardSet(VerifyUri)
|
||||
' Continue While
|
||||
' ElseIf MsgBoxValue = "3" Then
|
||||
' ClipboardSet(UserCode)
|
||||
' Continue While
|
||||
' ElseIf MsgBoxValue = "1" Then
|
||||
' Exit While
|
||||
' End If
|
||||
' End While
|
||||
|
||||
' Return DeviceCode
|
||||
'End Function
|
||||
|
||||
''微软登录步骤 2:从 OAuth Code 或 OAuth RefreshToken 获取 {OAuth AccessToken, OAuth RefreshToken}
|
||||
'Private Function MsLoginStep2(Code As String, IsRefresh As Boolean, Optional ExpiresIn As String = "900") As String()
|
||||
' McLaunchLog("开始微软登录步骤 2(" & If(IsRefresh, "", "非") & "刷新登录)")
|
||||
|
||||
' Dim Request As String
|
||||
' If IsRefresh Then
|
||||
' Request = "grant_type=refresh_token" & "&" &
|
||||
' "client_id=" & OAuthClientId & "&" &
|
||||
' "device_code=" & Code & "&" &
|
||||
' "refresh_token=" & Uri.EscapeDataString(Code) & "&" &
|
||||
' "scope=XboxLive.signin%20offline_access"
|
||||
' Else
|
||||
' Request = "grant_type=urn:ietf:params:oauth:grant-type:device_code" & "&" &
|
||||
' "client_id=" & OAuthClientId & "&" &
|
||||
' "device_code=" & Code & "&" &
|
||||
' "scope=XboxLive.signin%20offline_access"
|
||||
' End If
|
||||
' Dim Result As String
|
||||
' Dim stopwatch As Stopwatch = Stopwatch.StartNew()
|
||||
|
||||
' While stopwatch.Elapsed < TimeSpan.FromSeconds(ExpiresIn)
|
||||
' Try
|
||||
' Result = NetRequestMulty("https://login.microsoftonline.com/consumers/oauth2/v2.0/token", "POST", Request, "application/x-www-form-urlencoded", 2)
|
||||
' Catch ex As Exception
|
||||
' If ex.Message.Contains("must sign in again") OrElse ex.Message.Contains("invalid_grant") Then '#269
|
||||
' Return {"Relogin", ""}
|
||||
' ElseIf ex.Message.Contains("authorization_declined") Then
|
||||
' Hint("你拒绝了 PCL2 的访问权限申请,验证过程被中断!")
|
||||
' Return {"Cancel", ""}
|
||||
' ElseIf ex.Message.Contains("expired_token") Then
|
||||
' Hint("Token 已过期,请尝试重新验证!")
|
||||
' Exit While
|
||||
' ElseIf ex.Message.Contains("AADSTS70016") Then
|
||||
' Continue While
|
||||
' Else
|
||||
' Throw
|
||||
' End If
|
||||
' End Try
|
||||
|
||||
' If Result IsNot Nothing Then
|
||||
' Dim ResultJson As JObject = GetJson(Result)
|
||||
' Dim AccessToken As String = ResultJson("access_token").ToString
|
||||
' Dim RefreshToken As String = ResultJson("refresh_token").ToString
|
||||
' Return {AccessToken, RefreshToken}
|
||||
' End If
|
||||
|
||||
' Thread.Sleep(1000)
|
||||
' End While
|
||||
|
||||
' Hint("验证超时,请尝试重新验证!")
|
||||
' Return {"Cancel", ""}
|
||||
|
||||
'End Function
|
||||
|
||||
'微软登录步骤 3:从 OAuth AccessToken 获取 XBLToken
|
||||
Private Function MsLoginStep3(AccessToken As String) As String
|
||||
McLaunchLog("开始微软登录步骤 3")
|
||||
|
||||
Dim Request As String = "{
|
||||
""Properties"": {
|
||||
""AuthMethod"": ""RPS"",
|
||||
""SiteName"": ""user.auth.xboxlive.com"",
|
||||
""RpsTicket"": ""d=" & AccessToken & """
|
||||
},
|
||||
""RelyingParty"": ""http://auth.xboxlive.com"",
|
||||
""TokenType"": ""JWT""
|
||||
}"
|
||||
""Properties"": {
|
||||
""AuthMethod"": ""RPS"",
|
||||
""SiteName"": ""user.auth.xboxlive.com"",
|
||||
""RpsTicket"": """ & AccessToken & """
|
||||
},
|
||||
""RelyingParty"": ""http://auth.xboxlive.com"",
|
||||
""TokenType"": ""JWT""
|
||||
}" 'TODO: 新版登录改为 ""RpsTicket"": ""d=" & AccessToken & """
|
||||
Dim Result As String = NetRequestMulty("https://user.auth.xboxlive.com/user/authenticate", "POST", Request, "application/json", 3)
|
||||
|
||||
Dim ResultJson As JObject = GetJson(Result)
|
||||
@@ -1064,7 +1141,7 @@ LoginFinish:
|
||||
Case 3
|
||||
'使用正版用户名
|
||||
Try
|
||||
If Not SkinName = "" Then
|
||||
If SkinName <> "" AndAlso McVersionCurrent.Version.McCodeMain < 20 Then '1.20+ 或快照版不能使用该项(#3746)
|
||||
Log("[Skin] 由于离线皮肤设置,使用正版 UUID:" & SkinName)
|
||||
Uuid = McLoginMojangUuid(SkinName, False)
|
||||
End If
|
||||
@@ -1075,8 +1152,8 @@ LoginFinish:
|
||||
Case 4
|
||||
'自定义
|
||||
Do Until McSkinSex(Uuid) = If(Setup.Get("LaunchSkinSlim"), "Alex", "Steve")
|
||||
If Uuid.EndsWithF("FFFFF") Then Uuid = Mid(Uuid, 1, 32 - 5) & "00000"
|
||||
Uuid = Mid(Uuid, 1, 32 - 5) & (Long.Parse(Right(Uuid, 5), Globalization.NumberStyles.AllowHexSpecifier) + 1).ToString("X").PadLeft(5, "0")
|
||||
If Uuid.EndsWithF("FFFFF") Then Uuid = Uuid.Substring(0, 27) & "00000"
|
||||
Uuid = Uuid.Substring(0, 27) & (Long.Parse(Uuid.Substring(27), Globalization.NumberStyles.AllowHexSpecifier) + 1).ToString("X").PadLeft(5, "0")
|
||||
Loop
|
||||
End Select
|
||||
Return Uuid
|
||||
@@ -1194,7 +1271,7 @@ LoginFinish:
|
||||
'统一通行证检测
|
||||
If Setup.Get("LoginType") = McLoginType.Nide Then
|
||||
'至少 Java 8u101
|
||||
MinVer = If(New Version(1, 8, 0, 101) > MinVer, New Version(1, 8, 0, 101), MinVer)
|
||||
MinVer = If(New Version(1, 8, 0, 141) > MinVer, New Version(1, 8, 0, 141), MinVer)
|
||||
End If
|
||||
|
||||
SyncLock JavaLock
|
||||
@@ -1221,12 +1298,12 @@ LoginFinish:
|
||||
ElseIf MaxVer < New Version(1, 8, 0, 0) Then
|
||||
JavaCode = 7
|
||||
If Not JavaDownloadConfirm("Java 7", True) Then Throw New Exception("$$")
|
||||
ElseIf MinVer > New Version(1, 8, 0, 100) AndAlso MaxVer < New Version(1, 8, 0, 321) Then
|
||||
JavaCode = "8u101"
|
||||
If Not JavaDownloadConfirm("Java 8.0.101 ~ 8.0.320", True) Then Throw New Exception("$$")
|
||||
ElseIf MinVer > New Version(1, 8, 0, 100) Then
|
||||
JavaCode = "8u101"
|
||||
If Not JavaDownloadConfirm("Java 8.0.101 或更高版本的 Java 8", True) Then Throw New Exception("$$")
|
||||
ElseIf MinVer > New Version(1, 8, 0, 140) AndAlso MaxVer < New Version(1, 8, 0, 321) Then
|
||||
JavaCode = "8u141"
|
||||
If Not JavaDownloadConfirm("Java 8.0.141 ~ 8.0.320", True) Then Throw New Exception("$$")
|
||||
ElseIf MinVer > New Version(1, 8, 0, 140) Then
|
||||
JavaCode = "8u141"
|
||||
If Not JavaDownloadConfirm("Java 8.0.141 或更高版本的 Java 8", True) Then Throw New Exception("$$")
|
||||
ElseIf MaxVer < New Version(1, 8, 0, 321) Then
|
||||
JavaCode = 8
|
||||
If Not JavaDownloadConfirm("Java 8.0.320 或更低版本的 Java 8") Then Throw New Exception("$$")
|
||||
@@ -1271,25 +1348,40 @@ LoginFinish:
|
||||
''' 释放 Java Wrapper 并返回完整文件路径。
|
||||
''' </summary>
|
||||
Public Function ExtractJavaWrapper() As String
|
||||
Dim WrapperPath As String = GetJavaWrapperDir() & "\JavaWrapper.jar"
|
||||
Dim BaseDir As String = GetJavaWrapperDir()
|
||||
Dim WrapperPath As String = BaseDir & "\JavaWrapper.jar"
|
||||
Log("[Java] 选定的 Java Wrapper 路径:" & WrapperPath)
|
||||
SyncLock ExtractJavaWrapperLock '避免 OptiFine 和 Forge 安装时同时释放 Java Wrapper 导致冲突
|
||||
WriteFile(WrapperPath, GetResources("JavaWrapper"))
|
||||
Dim IsWrapperWritten As Boolean = WriteFile(WrapperPath, GetResources("JavaWrapper"))
|
||||
If Not IsWrapperWritten AndAlso File.Exists(WrapperPath) Then
|
||||
'以下为 #4243 的修复,因为未知原因 Java Wrapper 可能变为只读文件
|
||||
Log("[Java] Java Wrapper 文件释放失败,但文件已存在,将在删除后尝试重新生成", LogLevel.Debug)
|
||||
Try
|
||||
File.Delete(WrapperPath)
|
||||
IsWrapperWritten = WriteFile(WrapperPath, GetResources("JavaWrapper"))
|
||||
Catch ex As Exception
|
||||
Log(ex, "Java Wrapper 文件重新释放失败,将尝试更换文件名重新生成")
|
||||
WrapperPath = BaseDir & "\JavaWrapper2.jar"
|
||||
IsWrapperWritten = WriteFile(WrapperPath, GetResources("JavaWrapper"))
|
||||
End Try
|
||||
End If
|
||||
If Not IsWrapperWritten Then Throw New FileNotFoundException("释放 Java Wrapper 失败,请查看 PCL 日志查找详细信息")
|
||||
End SyncLock
|
||||
Log("[Java] 已释放 Java Wrapper:" & WrapperPath)
|
||||
Return WrapperPath
|
||||
End Function
|
||||
Private ExtractJavaWrapperLock As New Object
|
||||
|
||||
''' <summary>
|
||||
''' 获取 Java Wrapper 所在的文件夹,不以 \ 结尾。
|
||||
''' </summary>
|
||||
Public Function GetJavaWrapperDir() As String
|
||||
If PathAppdata.IsASCII() Then
|
||||
If (Path & "PCL").IsASCII() Then
|
||||
Return Path & "PCL"
|
||||
ElseIf PathAppdata.IsASCII() Then
|
||||
Return PathAppdata.TrimEnd("\")
|
||||
ElseIf PathTemp.IsASCII() Then
|
||||
Log("[Java] Wrapper:AppData 路径中包含非 ASCII 字符,换用 Temp 目录")
|
||||
Return PathTemp.TrimEnd("\")
|
||||
Else
|
||||
Log("[Java] Wrapper:AppData 路径与 Temp 路径中均包含非 ASCII 字符,换用 ProgramData 目录")
|
||||
Return OsDrive & "ProgramData\PCL"
|
||||
End If
|
||||
End Function
|
||||
@@ -1765,7 +1857,6 @@ NextVersion:
|
||||
{
|
||||
""authenticationDatabase"": {
|
||||
""00000111112222233333444445555566"": {
|
||||
""accessToken"": """ & McLoginLoader.Output.AccessToken & """,
|
||||
""username"": """ & McLoginLoader.Output.Name.Replace("""", "-") & """,
|
||||
""profiles"": {
|
||||
""66666555554444433333222221111100"": {
|
||||
@@ -1796,7 +1887,6 @@ NextVersion:
|
||||
{
|
||||
""authenticationDatabase"": {
|
||||
""00000111112222233333444445555566"": {
|
||||
""accessToken"": """ & McLoginLoader.Output.AccessToken & """,
|
||||
""username"": """ & McLoginLoader.Output.Name.Replace("""", "-") & """,
|
||||
""profiles"": {
|
||||
""66666555554444433333222221111100"": {
|
||||
@@ -1872,16 +1962,12 @@ NextVersion:
|
||||
End Try
|
||||
|
||||
'离线皮肤 Alex 警告
|
||||
Try
|
||||
If McVersionCurrent.Version.McCodeMain <= 7 AndAlso McVersionCurrent.Version.McCodeMain >= 2 AndAlso '1.7 ~ 1.2
|
||||
If McVersionCurrent.Version.McCodeMain <= 7 AndAlso McVersionCurrent.Version.McCodeMain >= 2 AndAlso '1.2 ~ 1.7
|
||||
McLoginLoader.Input.Type = McLoginType.Legacy AndAlso '离线登录
|
||||
(Setup.Get("LaunchSkinType") = 2 OrElse '强制 Alex
|
||||
(Setup.Get("LaunchSkinType") = 4 AndAlso Setup.Get("LaunchSkinSlim"))) Then '或选用 Alex 皮肤
|
||||
Hint("此 Minecraft 版本尚不支持 Alex 皮肤,你的皮肤可能会显示为 Steve!", HintType.Critical)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Log(ex, "检查离线皮肤失效失败")
|
||||
End Try
|
||||
Hint("此 Minecraft 版本尚不支持 Alex 皮肤,你的皮肤可能会显示为 Steve!", HintType.Critical)
|
||||
End If
|
||||
|
||||
'离线皮肤资源包
|
||||
Try
|
||||
@@ -2123,6 +2209,8 @@ IgnoreCustomSkin:
|
||||
StartInfo.EnvironmentVariables("Path") = Join(Paths.Distinct.ToList, ";")
|
||||
|
||||
'设置其他参数
|
||||
StartInfo.StandardErrorEncoding = Encoding.UTF8
|
||||
StartInfo.StandardOutputEncoding = Encoding.UTF8
|
||||
StartInfo.WorkingDirectory = McVersionCurrent.PathIndie
|
||||
StartInfo.UseShellExecute = False
|
||||
StartInfo.RedirectStandardOutput = True
|
||||
|
||||
Reference in New Issue
Block a user