Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Plain Craft Launcher 2/Modules/Base/ModNet.vb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ Public Module ModNet

#Region "网络请求"

''' <summary>
''' 确定是否使用代理。
''' </summary>
''' <returns>返回 WebProxy 或者 Nothing</returns>
Public Function GetProxy() As WebProxy
Dim ProxyServer As String = Setup.Get("ToolDownloadProxy")
If Not String.IsNullOrWhiteSpace(ProxyServer) Then
Log("[Net] 当前代理状态:自定义")
Dim ProxyUri As New Uri(ProxyServer)
If Not ProxyUri.Scheme.StartsWithF("http") Then Return Nothing '只允许 http/https 协议
Try
If ProxyUri.IsLoopback OrElse
ProxyUri.Host.StartsWithF("192.168.") OrElse
ProxyUri.Host.StartsWithF("10.") OrElse
ProxyUri.Host.StartsWithF("fe80") OrElse
(ProxyUri.Host.Split(".")(1) > 16 AndAlso ProxyUri.Host.Split(".")(1) < 31 AndAlso ProxyUri.Host.StartsWithF("172.")) Then Log($"[Net] 使用 {ProxyUri} 作为网络代理")
'视作非本地地址
Catch
End Try
Return New WebProxy(ProxyServer, True)
End If
Log("[Net] 当前代理状态:跟随系统代理设置")
Return Nothing
End Function
''' <summary>
''' 发送一次网络请求并获取返回内容。
''' </summary>
Expand Down Expand Up @@ -256,6 +280,7 @@ RequestFinished:
'延迟初始化,以避免在程序启动前加载 CacheCow 导致 DLL 加载失败
If RequestClient Is Nothing Then
RequestClient = CacheCow.Client.ClientExtensions.CreateClient(New CacheCow.Client.FileCacheStore.FileStore(PathTemp & "Cache/Http/"), New HttpClientHandler With {
.Proxy = GetProxy(),
.AutomaticDecompression = DecompressionMethods.Deflate Or DecompressionMethods.GZip,
.UseCookies = False '不设为 False 就不能从 Header 手动传入 Cookies
})
Expand Down Expand Up @@ -393,6 +418,7 @@ RequestFinished:
#Region "多线程下载引擎"

Private ThreadClient As New HttpClient(New HttpClientHandler With {
.Proxy = GetProxy(),
.AutomaticDecompression = DecompressionMethods.Deflate Or DecompressionMethods.GZip
})

Expand Down
14 changes: 14 additions & 0 deletions Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,13 @@ Retry:
End Try
End If

'设置代理
If Setup.Get("VersionAdvanceUseProxy", McInstanceSelected) AndAlso Not String.IsNullOrWhiteSpace(Setup.Get("ToolDownloadProxy")) Then
Dim ProxyAddress As New Uri(Setup.Get("ToolDownloadProxy"))
DataList.Add($"-D{If(ProxyAddress.Scheme.StartsWithF("https"), "https", "http")}.proxyHost={ProxyAddress.Host}")
DataList.Add($"-D{If(ProxyAddress.Scheme.StartsWithF("https"), "https", "http")}.proxyPort={ProxyAddress.Port}")
End If

'添加 Java Wrapper 作为主 Jar
If Not Setup.Get("LaunchAdvanceDisableJLW") AndAlso Not Setup.Get("VersionAdvanceDisableJLW", McInstanceSelected) Then
If McLaunchJavaSelected.MajorVersion >= 9 Then DataList.Add("--add-exports cpw.mods.bootstraplauncher/cpw.mods.bootstraplauncher=ALL-UNNAMED")
Expand Down Expand Up @@ -1510,6 +1517,13 @@ NextInstance:
End Try
End If

'设置代理
If Setup.Get("VersionAdvanceUseProxy", McInstanceSelected) AndAlso Not String.IsNullOrWhiteSpace(Setup.Get("ToolDownloadProxy")) Then
Dim ProxyAddress As New Uri(Setup.Get("ToolDownloadProxy"))
DataList.Add($"-D{If(ProxyAddress.Scheme.StartsWithF("https"), "https", "http")}.proxyHost={ProxyAddress.Host}")
DataList.Add($"-D{If(ProxyAddress.Scheme.StartsWithF("https"), "https", "http")}.proxyPort={ProxyAddress.Port}")
End If

'添加 Java Wrapper 作为主 Jar
If Not Setup.Get("LaunchAdvanceDisableJLW") AndAlso Not Setup.Get("VersionAdvanceDisableJLW", McInstanceSelected) Then
If McLaunchJavaSelected.MajorVersion >= 9 Then DataList.Add("--add-exports cpw.mods.bootstraplauncher/cpw.mods.bootstraplauncher=ALL-UNNAMED")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@
<local:MyCheckBox Height="28" Text="禁用 Java Launch Wrapper" x:Name="CheckAdvanceDisableJLW" Tag="VersionAdvanceDisableJLW"
ToolTipService.Placement="Right"
ToolTip="PCL 会使用 Java Launch Wrapper 来修复老版本 Java 在中文路径下无法启动的问题。&#xa;如果这被反作弊拦截,或遇到其他问题,也可以将其关闭。" />
<local:MyCheckBox Height="28" Text="使用代理" x:Name="CheckAdvanceUseProxy" Tag="VersionAdvanceUseProxy"
ToolTipService.Placement="Right"
ToolTip="PCL 会使用 设置 → 其他 → 下载 → HTTP 代理 中填写的代理来启动游戏。" />
</StackPanel>
</Grid>
</local:MyCard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
CheckAdvanceJava.Checked = Setup.Get("VersionAdvanceJava", Instance:=PageInstanceLeft.Instance)
CheckAdvanceDisableJLW.Checked = Setup.Get("VersionAdvanceDisableJLW", Instance:=PageInstanceLeft.Instance)
CheckAdvanceDisableModUpdate.Checked = Setup.Get("VersionAdvanceDisableModUpdate", Instance:=PageInstanceLeft.Instance)
CheckAdvanceUseProxy.Checked = Setup.Get("VersionAdvanceUseProxy", Instance:=PageInstanceLeft.Instance)

Catch ex As Exception
Log(ex, "重载版本独立设置时出错", LogLevel.Feedback)
Expand Down Expand Up @@ -95,6 +96,7 @@
Setup.Reset("VersionAdvanceRunWait", Instance:=PageInstanceLeft.Instance)
Setup.Reset("VersionAdvanceDisableJLW", Instance:=PageInstanceLeft.Instance)
Setup.Reset("VersionAdvanceDisableModUpdate", Instance:=PageInstanceLeft.Instance)
Setup.Reset("VersionAdvanceUseProxy", Instance:=PageInstanceLeft.Instance)
Setup.Reset("VersionArgumentJavaSelect", Instance:=PageInstanceLeft.Instance)
JavaSearchLoader.Start(IsForceRestart:=True)

Expand Down Expand Up @@ -128,7 +130,7 @@
Private Shared Sub CheckBoxLikeComboChange(sender As MyComboBox, e As Object) Handles ComboArgumentIndieV2.SelectionChanged
If AniControlEnabled = 0 Then Setup.Set(sender.Tag, sender.SelectedIndex = 0, Instance:=PageInstanceLeft.Instance)
End Sub
Private Shared Sub CheckBoxChange(sender As MyCheckBox, e As Object) Handles CheckAdvanceRunWait.Change, CheckAdvanceAssetsV2.Change, CheckAdvanceJava.Change, CheckAdvanceDisableJLW.Change, CheckAdvanceDisableModUpdate.Change
Private Shared Sub CheckBoxChange(sender As MyCheckBox, e As Object) Handles CheckAdvanceRunWait.Change, CheckAdvanceAssetsV2.Change, CheckAdvanceJava.Change, CheckAdvanceDisableJLW.Change, CheckAdvanceDisableModUpdate.Change, CheckAdvanceUseProxy.Change
If AniControlEnabled = 0 Then Setup.Set(sender.Tag, sender.Checked, Instance:=PageInstanceLeft.Instance)
End Sub

Expand Down
2 changes: 2 additions & 0 deletions Plain Craft Launcher 2/Pages/PageSetup/ModSetup.vb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
{"ToolDownloadIgnoreQuilt", New SetupEntry(True, Source:=SetupSource.Registry)},
{"ToolDownloadCert", New SetupEntry(False, Source:=SetupSource.Registry)},
{"ToolDownloadMod", New SetupEntry(2, Source:=SetupSource.Registry)},
{"ToolDownloadProxy", New SetupEntry("", Source:=SetupSource.Registry)},
{"ToolModLocalNameStyle", New SetupEntry(0, Source:=SetupSource.Registry)},
{"ToolUpdateAlpha", New SetupEntry(0, Source:=SetupSource.Registry, Encoded:=True)},
{"ToolUpdateRelease", New SetupEntry(False, Source:=SetupSource.Registry)},
Expand Down Expand Up @@ -182,6 +183,7 @@
{"VersionAdvanceDisableJLW", New SetupEntry(False, Source:=SetupSource.Instance)},
{"VersionAdvanceDisableModUpdate", New SetupEntry(False, Source:=SetupSource.Instance)},
{"VersionAdvanceGC", New SetupEntry(0, Source:=SetupSource.Instance)},
{"VersionAdvanceUseProxy", New SetupEntry(False, Source:=SetupSource.Instance)},
{"VersionRamType", New SetupEntry(2, Source:=SetupSource.Instance)},
{"VersionRamCustom", New SetupEntry(15, Source:=SetupSource.Instance)},
{"VersionRamOptimize", New SetupEntry(0, Source:=SetupSource.Instance)},
Expand Down
5 changes: 4 additions & 1 deletion Plain Craft Launcher 2/Pages/PageSetup/PageSetupSystem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<RowDefinition Height="27" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="文件下载源" Margin="0,0,25,0" />
<local:MyComboBox x:Name="ComboDownloadSource" Grid.ColumnSpan="2" Tag="ToolDownloadSource" Grid.Column="1">
Expand All @@ -44,7 +45,9 @@
ToolTip="设置下载的速度上限,以避免在下载时导致其他需要联网的程序卡死" />
<TextBlock VerticalAlignment="Top" Grid.Row="6" HorizontalAlignment="Left" Text="目标文件夹" Margin="0,5,25,5" />
<TextBlock Margin="0,5" HorizontalAlignment="Left" Text="请在 启动 → 版本选择 → 文件夹列表 中更改下载目标文件夹。&#xa;在某个文件夹或游戏版本上右键,即可选择打开对应文件夹。" Grid.Row="6" Grid.Column="1" VerticalAlignment="Center" Opacity="0.5" />
<local:MyCheckBox Margin="0,2,0,4" Text="在正版登录时验证 SSL 证书" Grid.Row="7" Height="22" Grid.ColumnSpan="2"
<TextBlock VerticalAlignment="Center" Grid.Row="7" HorizontalAlignment="Left" Text="HTTP 代理" Margin="0,0,25,0" />
<local:MyTextBox x:Name="TextToolDownloadProxy" Grid.Row="7" Tag="ToolDownloadProxy" Grid.Column="1" HintText="比如 http://127.0.0.1:1080/" ToolTip="不正确的代理服务器地址会导致无法连接网络,因使用代理导致的网络问题不予处理。&#xa;请勿填写不信任的代理服务器地址,这可能会导致你的账号信息泄露,甚至账号被盗。"/>
<local:MyCheckBox Margin="0,2,0,4" Text="在正版登录时验证 SSL 证书" Grid.Row="8" Height="22"
x:Name="CheckDownloadCert" Tag="ToolDownloadCert"
ToolTip="开启验证可以提高安全性,但可能会导致正版登录失败(见 #3018)。&#xa;若登录因为 “未能为 SSL/TLS 安全通道建立信任关系” 失败,请考虑关闭此选项。" />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
ComboDownloadSource.SelectedIndex = Setup.Get("ToolDownloadSource")
ComboDownloadVersion.SelectedIndex = Setup.Get("ToolDownloadVersion")
CheckDownloadCert.Checked = Setup.Get("ToolDownloadCert")
TextToolDownloadProxy.Text = Setup.Get("ToolDownloadProxy")

'Mod 与整合包
ComboDownloadTranslateV2.SelectedIndex = Setup.Get("ToolDownloadTranslateV2")
Expand Down Expand Up @@ -70,6 +71,7 @@
Setup.Reset("ToolDownloadTranslateV2")
Setup.Reset("ToolDownloadIgnoreQuilt")
Setup.Reset("ToolDownloadCert")
Setup.Reset("ToolDownloadProxy")
Setup.Reset("ToolDownloadMod")
Setup.Reset("ToolModLocalNameStyle")
Setup.Reset("ToolUpdateRelease")
Expand Down Expand Up @@ -103,7 +105,7 @@
Private Shared Sub ComboChange(sender As MyComboBox, e As Object) Handles ComboDownloadVersion.SelectionChanged, ComboModLocalNameStyle.SelectionChanged, ComboDownloadTranslateV2.SelectionChanged, ComboSystemUpdate.SelectionChanged, ComboSystemActivity.SelectionChanged, ComboDownloadSource.SelectionChanged, ComboDownloadMod.SelectionChanged
If AniControlEnabled = 0 Then Setup.Set(sender.Tag, sender.SelectedIndex)
End Sub
Private Shared Sub TextBoxChange(sender As MyTextBox, e As Object) Handles TextSystemCache.ValidatedTextChanged
Private Shared Sub TextBoxChange(sender As MyTextBox, e As Object) Handles TextSystemCache.ValidatedTextChanged, TextToolDownloadProxy.TextChanged
If AniControlEnabled = 0 Then Setup.Set(sender.Tag, sender.Text)
End Sub

Expand Down
Loading