mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-12 23:14:34 +01:00
update server selector
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sty="using:FluentAvalonia.Styling"
|
||||
x:Class="ServerSelector.App"
|
||||
RequestedThemeVariant="Default">
|
||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme />
|
||||
<sty:FluentAvaloniaTheme />
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
|
||||
@@ -11,12 +11,13 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.1.0-rc2" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0-rc2" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0-rc2" />
|
||||
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.0-rc2" />
|
||||
<PackageReference Include="Avalonia" Version="11.1.3" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.3" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.3" />
|
||||
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.3" />
|
||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0-rc2" />
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3" />
|
||||
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,25 +1,39 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServerSelector
|
||||
{
|
||||
public class ServerSwitcher
|
||||
{
|
||||
private static int GameAssemblySodiumIntegrityFuncHint = 0x5877FFB;
|
||||
private static byte[] GameAssemblySodiumIntegrityFuncOrg = [0xE8, 0xF0, 0x9D, 0x43, 0xFB];
|
||||
private static byte[] GameAssemblySodiumIntegrityFuncPatch = [0xb0, 0x01, 0x90, 0x90, 0x90];
|
||||
|
||||
public static bool IsUsingOfficalServer()
|
||||
{
|
||||
var hostsFile = File.ReadAllText("C:\\Windows\\System32\\drivers\\etc\\hosts");
|
||||
return !hostsFile.Contains("cloud.nikke-kr.com");
|
||||
}
|
||||
|
||||
public static void SaveCfg(bool useOffical, string gamePath, string launcherPath, string ip)
|
||||
public static string CheckIntegrity()
|
||||
{
|
||||
if (IsUsingOfficalServer())
|
||||
return "Official server";
|
||||
|
||||
// TODO
|
||||
return "OK";
|
||||
}
|
||||
|
||||
public static async Task SaveCfg(bool useOffical, string gamePath, string launcherPath, string ip)
|
||||
{
|
||||
string sodiumLib = AppDomain.CurrentDomain.BaseDirectory + "sodium.dll";
|
||||
string gameSodium = gamePath + "/nikke_Data/Plugins/x86_64/sodium.dll";
|
||||
string gameAssembly = gamePath + "/GameAssembly.dll";
|
||||
string sodiumBackup = gameSodium + ".bak";
|
||||
string hostsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers/etc/hosts");
|
||||
var CAcert = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "myCA.pem");
|
||||
var CAcert = await File.ReadAllTextAsync(AppDomain.CurrentDomain.BaseDirectory + "myCA.pem");
|
||||
|
||||
string launcherCertList = launcherPath + "/intl_service/cacert.pem";
|
||||
string gameCertList = gamePath + "/nikke_Data/Plugins/x86_64/cacert.pem";
|
||||
@@ -28,7 +42,7 @@ namespace ServerSelector
|
||||
// TODO: allow changing ip address
|
||||
if (useOffical)
|
||||
{
|
||||
var txt = File.ReadAllText(hostsFilePath);
|
||||
var txt = await File.ReadAllTextAsync(hostsFilePath);
|
||||
|
||||
// remove stuff
|
||||
try
|
||||
@@ -50,7 +64,7 @@ namespace ServerSelector
|
||||
int endIdx = txt.IndexOf("y.io") + 4;
|
||||
txt = txt.Substring(0, startIdx) + txt.Substring(endIdx);
|
||||
|
||||
File.WriteAllText(hostsFilePath, txt);
|
||||
await File.WriteAllTextAsync(hostsFilePath, txt);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -72,41 +86,41 @@ namespace ServerSelector
|
||||
File.Copy(sodiumBackup, gameSodium, true);
|
||||
|
||||
// revert gameassembly changes
|
||||
var gameAssemblyBytes = File.ReadAllBytes(gameAssembly);
|
||||
var gameAssemblyBytes = await File.ReadAllBytesAsync(gameAssembly);
|
||||
for (int i = 0x5877FFB; i < gameAssemblyBytes.Length; i++)
|
||||
{
|
||||
if (gameAssemblyBytes[i] == 0xE8 &&
|
||||
gameAssemblyBytes[i + 1] == 0xF0 &&
|
||||
gameAssemblyBytes[i + 2] == 0x9D &&
|
||||
gameAssemblyBytes[i + 3] == 0x43 &&
|
||||
gameAssemblyBytes[i + 4] == 0xFB)
|
||||
if (gameAssemblyBytes[i] == GameAssemblySodiumIntegrityFuncOrg[0] &&
|
||||
gameAssemblyBytes[i + 1] == GameAssemblySodiumIntegrityFuncOrg[1] &&
|
||||
gameAssemblyBytes[i + 2] == GameAssemblySodiumIntegrityFuncOrg[2] &&
|
||||
gameAssemblyBytes[i + 3] == GameAssemblySodiumIntegrityFuncOrg[3] &&
|
||||
gameAssemblyBytes[i + 4] == GameAssemblySodiumIntegrityFuncOrg[4])
|
||||
{
|
||||
// was not patched
|
||||
break;
|
||||
}
|
||||
|
||||
if (gameAssemblyBytes[i] == 0xb0 &&
|
||||
gameAssemblyBytes[i + 1] == 1 &&
|
||||
gameAssemblyBytes[i + 2] == 0x90 &&
|
||||
gameAssemblyBytes[i + 3] == 0x90 &&
|
||||
gameAssemblyBytes[i + 4] == 0x90)
|
||||
if (gameAssemblyBytes[i] == GameAssemblySodiumIntegrityFuncPatch[0] &&
|
||||
gameAssemblyBytes[i + 1] == GameAssemblySodiumIntegrityFuncPatch[1] &&
|
||||
gameAssemblyBytes[i + 2] == GameAssemblySodiumIntegrityFuncPatch[2] &&
|
||||
gameAssemblyBytes[i + 3] == GameAssemblySodiumIntegrityFuncPatch[3] &&
|
||||
gameAssemblyBytes[i + 4] == GameAssemblySodiumIntegrityFuncPatch[4])
|
||||
{
|
||||
gameAssemblyBytes[i] = 0xE8;
|
||||
gameAssemblyBytes[i + 1] = 0xF0;
|
||||
gameAssemblyBytes[i + 2] = 0x9D;
|
||||
gameAssemblyBytes[i + 3] = 0x43;
|
||||
gameAssemblyBytes[i + 4] = 0xFB;
|
||||
gameAssemblyBytes[i] = GameAssemblySodiumIntegrityFuncOrg[0];
|
||||
gameAssemblyBytes[i + 1] = GameAssemblySodiumIntegrityFuncOrg[1];
|
||||
gameAssemblyBytes[i + 2] = GameAssemblySodiumIntegrityFuncOrg[2];
|
||||
gameAssemblyBytes[i + 3] = GameAssemblySodiumIntegrityFuncOrg[3];
|
||||
gameAssemblyBytes[i + 4] = GameAssemblySodiumIntegrityFuncOrg[4];
|
||||
|
||||
File.WriteAllBytes(gameAssembly, gameAssemblyBytes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var certList1 = File.ReadAllText(launcherCertList);
|
||||
File.WriteAllText(launcherCertList, certList1.Substring(0, certList1.IndexOf("Good SSL Ca")));
|
||||
var certList1 = await File.ReadAllTextAsync(launcherCertList);
|
||||
await File.WriteAllTextAsync(launcherCertList, certList1.Substring(0, certList1.IndexOf("Good SSL Ca")));
|
||||
|
||||
var certList2 = File.ReadAllText(gameCertList);
|
||||
File.WriteAllText(gameCertList, certList2.Substring(0, certList2.IndexOf("Good SSL Ca")));
|
||||
var certList2 = await File.ReadAllTextAsync(gameCertList);
|
||||
await File.WriteAllTextAsync(gameCertList, certList2.Substring(0, certList2.IndexOf("Good SSL Ca")));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -129,7 +143,7 @@ namespace ServerSelector
|
||||
{ip} data-aws-na.intlgame.com
|
||||
255.255.221.21 sentry.io";
|
||||
|
||||
if (!File.ReadAllText(hostsFilePath).Contains("global-lobby.nikke-kr.com"))
|
||||
if (!(await File.ReadAllTextAsync(hostsFilePath)).Contains("global-lobby.nikke-kr.com"))
|
||||
{
|
||||
using StreamWriter w = File.AppendText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers/etc/hosts"));
|
||||
w.WriteLine();
|
||||
@@ -151,41 +165,41 @@ namespace ServerSelector
|
||||
}
|
||||
|
||||
// copy backup if sodium size is correct
|
||||
var sod = File.ReadAllBytes(gameSodium);
|
||||
var sod = await File.ReadAllBytesAsync(gameSodium);
|
||||
if (sod.Length <= 307200)
|
||||
{
|
||||
// orignal file size, copy backup
|
||||
File.WriteAllBytes(sodiumBackup, sod);
|
||||
await File.WriteAllBytesAsync(sodiumBackup, sod);
|
||||
}
|
||||
|
||||
// write new sodium library
|
||||
File.WriteAllBytes(gameSodium, File.ReadAllBytes(sodiumLib));
|
||||
await File.WriteAllBytesAsync(gameSodium, await File.ReadAllBytesAsync(sodiumLib));
|
||||
|
||||
// patch gameassembly to remove sodium IntegrityUtility Check. Was added in v124, note that this will need to be updated each game version! Thanks TenCent or ShiftDown!
|
||||
var gameAssemblyBytes = File.ReadAllBytes(gameAssembly);
|
||||
// patch gameassembly to remove sodium IntegrityUtility Check introduced in v124.6.10
|
||||
var gameAssemblyBytes = await File.ReadAllBytesAsync(gameAssembly);
|
||||
for (int i = 0x5877FFB; i < gameAssemblyBytes.Length; i++)
|
||||
{
|
||||
if (gameAssemblyBytes[i] == 0xE8 &&
|
||||
gameAssemblyBytes[i + 1] == 0xF0 &&
|
||||
gameAssemblyBytes[i + 2] == 0x9D &&
|
||||
gameAssemblyBytes[i + 3] == 0x43 &&
|
||||
gameAssemblyBytes[i + 4] == 0xFB)
|
||||
if (gameAssemblyBytes[i] == GameAssemblySodiumIntegrityFuncOrg[0] &&
|
||||
gameAssemblyBytes[i + 1] == GameAssemblySodiumIntegrityFuncOrg[1] &&
|
||||
gameAssemblyBytes[i + 2] == GameAssemblySodiumIntegrityFuncOrg[2] &&
|
||||
gameAssemblyBytes[i + 3] == GameAssemblySodiumIntegrityFuncOrg[3] &&
|
||||
gameAssemblyBytes[i + 4] == GameAssemblySodiumIntegrityFuncOrg[4])
|
||||
{
|
||||
gameAssemblyBytes[i] = 0xb0; // MOV ax, 1
|
||||
gameAssemblyBytes[i + 1] = 0x01;
|
||||
gameAssemblyBytes[i + 2] = 0x90; // NOP
|
||||
gameAssemblyBytes[i + 3] = 0x90; // NOP
|
||||
gameAssemblyBytes[i + 4] = 0x90; // NOP
|
||||
gameAssemblyBytes[i] = GameAssemblySodiumIntegrityFuncPatch[0]; // MOV ax, 1
|
||||
gameAssemblyBytes[i + 1] = GameAssemblySodiumIntegrityFuncPatch[1];
|
||||
gameAssemblyBytes[i + 2] = GameAssemblySodiumIntegrityFuncPatch[2]; // NOP
|
||||
gameAssemblyBytes[i + 3] = GameAssemblySodiumIntegrityFuncPatch[3]; // NOP
|
||||
gameAssemblyBytes[i + 4] = GameAssemblySodiumIntegrityFuncPatch[4]; // NOP
|
||||
|
||||
File.WriteAllBytes(gameAssembly, gameAssemblyBytes);
|
||||
await File.WriteAllBytesAsync(gameAssembly, gameAssemblyBytes);
|
||||
break;
|
||||
}
|
||||
|
||||
if (gameAssemblyBytes[i] == 0xb0 &&
|
||||
gameAssemblyBytes[i + 1] == 1 &&
|
||||
gameAssemblyBytes[i + 2] == 0x90 &&
|
||||
gameAssemblyBytes[i + 3] == 0x90 &&
|
||||
gameAssemblyBytes[i + 4] == 0x90)
|
||||
if (gameAssemblyBytes[i] == GameAssemblySodiumIntegrityFuncPatch[0] &&
|
||||
gameAssemblyBytes[i + 1] == GameAssemblySodiumIntegrityFuncPatch[1] &&
|
||||
gameAssemblyBytes[i + 2] == GameAssemblySodiumIntegrityFuncPatch[2] &&
|
||||
gameAssemblyBytes[i + 3] == GameAssemblySodiumIntegrityFuncPatch[3] &&
|
||||
gameAssemblyBytes[i + 4] == GameAssemblySodiumIntegrityFuncPatch[4])
|
||||
{
|
||||
// was already patched
|
||||
break;
|
||||
@@ -196,15 +210,15 @@ namespace ServerSelector
|
||||
|
||||
// update launcher/game ca cert list
|
||||
|
||||
var certList1 = File.ReadAllText(launcherCertList);
|
||||
var certList1 = await File.ReadAllTextAsync(launcherCertList);
|
||||
certList1 += "\nGood SSL Ca\n===============================\n";
|
||||
certList1 += CAcert;
|
||||
File.WriteAllText(launcherCertList, certList1);
|
||||
await File.WriteAllTextAsync(launcherCertList, certList1);
|
||||
|
||||
var certList2 = File.ReadAllText(gameCertList);
|
||||
var certList2 = await File.ReadAllTextAsync(gameCertList);
|
||||
certList2 += "\nGood SSL Ca\n===============================\n";
|
||||
certList2 += CAcert;
|
||||
File.WriteAllText(gameCertList, certList2);
|
||||
await File.WriteAllTextAsync(gameCertList, certList2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="clr-namespace:ServerSelector.ViewModels"
|
||||
mc:Ignorable="d" d:DesignWidth="370" d:DesignHeight="200"
|
||||
mc:Ignorable="d" d:DesignWidth="370" d:DesignHeight="250"
|
||||
x:Class="ServerSelector.Views.MainView"
|
||||
x:DataType="vm:MainViewModel"
|
||||
xmlns:ui="using:FluentAvalonia.UI.Controls"
|
||||
>
|
||||
<Design.DataContext>
|
||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||
@@ -13,46 +14,93 @@
|
||||
<vm:MainViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<Grid Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"></ColumnDefinition>
|
||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid>
|
||||
<TabControl x:Name="MainUI">
|
||||
<TabItem Header="PC" x:Name="TabPc">
|
||||
<Grid Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"></ColumnDefinition>
|
||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||
<ColumnDefinition Width="auto"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="0" Grid.Column="0">Game path: </TextBlock>
|
||||
<TextBox x:Name="txtGamePath" Grid.Row="0" Grid.Column="1">C:\NIKKE\NIKKE\game</TextBox>
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="0" Grid.Column="0">Game path: </TextBlock>
|
||||
<TextBox x:Name="txtGamePath" Grid.Row="0" Grid.Column="1">C:\NIKKE\NIKKE\game</TextBox>
|
||||
<Button x:Name="btnSelectGamePath" Grid.Row="0" Grid.Column="2" Content="..." Click="BtnSelectGamePath_Click"></Button>
|
||||
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="2" Grid.Column="0">Launcher path: </TextBlock>
|
||||
<TextBox x:Name="txtLauncherPath" Grid.Row="2" Grid.Column="1">C:\NIKKE\Launcher</TextBox>
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="2" Grid.Column="0">Launcher path: </TextBlock>
|
||||
<TextBox x:Name="txtLauncherPath" Grid.Row="2" Grid.Column="1">C:\NIKKE\Launcher</TextBox>
|
||||
<Button x:Name="btnSelectLauncherPath" Grid.Row="2" Grid.Column="2" Content="..." Click="BtnSelectLauncherPath_Click"></Button>
|
||||
|
||||
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="4" Grid.Column="0">Server: </TextBlock>
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="4" Grid.Column="0">Server: </TextBlock>
|
||||
|
||||
<ComboBox SelectedIndex="0" x:Name="CmbServerSelection" Grid.Row="4" Grid.Column="1" SelectionChanged="CmbServerSelection_SelectionChanged">
|
||||
<ComboBox.Items>
|
||||
<ComboBoxItem>Official</ComboBoxItem>
|
||||
<ComboBoxItem>Local</ComboBoxItem>
|
||||
</ComboBox.Items>
|
||||
</ComboBox>
|
||||
<ComboBox SelectedIndex="0" x:Name="CmbServerSelection" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" SelectionChanged="CmbServerSelection_SelectionChanged" HorizontalAlignment="Stretch">
|
||||
<ComboBox.Items>
|
||||
<ComboBoxItem>Official</ComboBoxItem>
|
||||
<ComboBoxItem>Local</ComboBoxItem>
|
||||
</ComboBox.Items>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="6" Grid.Column="0">IP: </TextBlock>
|
||||
<TextBox x:Name="TxtIpAddress" Grid.Row="6" Grid.Column="1">127.0.0.1</TextBox>
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="6" Grid.Column="0">IP: </TextBlock>
|
||||
<TextBox x:Name="TxtIpAddress" Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2">127.0.0.1</TextBox>
|
||||
|
||||
|
||||
<Button HorizontalAlignment="Right" Margin="5" Click="Save_Click" Grid.Row="8" Grid.Column="1">Save</Button>
|
||||
<TextBlock Grid.Row="8" Grid.Column="0" VerticalAlignment="Center" Margin="5" x:Name="LblStatus">Status: OK</TextBlock>
|
||||
<Button HorizontalAlignment="Right" Margin="5" Click="Save_Click" Grid.Row="8" Grid.Column="1" Grid.ColumnSpan="2" Classes="accent">Save</Button>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="Android">
|
||||
<Grid Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"></ColumnDefinition>
|
||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||
<ColumnDefinition Width="auto"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="5">APK path: </TextBlock>
|
||||
<TextBox x:Name="txtApkPath" Grid.Row="0" Grid.Column="1"></TextBox>
|
||||
<Button x:Name="btnSelectApkPath" Grid.Row="0" Grid.Column="2" Content="..."></Button>
|
||||
|
||||
|
||||
<TextBlock VerticalAlignment="Center" Grid.Row="2" Grid.Column="0" Margin="5">IP: </TextBlock>
|
||||
<TextBox x:Name="TxtAndroidIpAddress" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2">127.0.0.1</TextBox>
|
||||
|
||||
<Button HorizontalAlignment="Right" Margin="5" Click="Save_Click" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Classes="accent" IsEnabled="False">Coming soon!</Button>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="LoadingUI" IsVisible="False">
|
||||
<ui:ProgressRing Height="48" Width="48"></ui:ProgressRing>
|
||||
<TextBlock>Please wait...</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace ServerSelector.Views;
|
||||
|
||||
@@ -14,6 +17,18 @@ public partial class MainView : UserControl
|
||||
CmbServerSelection.SelectedIndex = ServerSwitcher.IsUsingOfficalServer() ? 0 : 1;
|
||||
|
||||
TxtIpAddress.IsEnabled = !ServerSwitcher.IsUsingOfficalServer();
|
||||
|
||||
if (OperatingSystem.IsWindows() && !new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator))
|
||||
{
|
||||
TabPc.Content = new TextBlock()
|
||||
{
|
||||
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
|
||||
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
|
||||
Text = "Administrator privileges are required to change servers."
|
||||
};
|
||||
}
|
||||
|
||||
LblStatus.Text = "Status: " + ServerSwitcher.CheckIntegrity();
|
||||
}
|
||||
|
||||
private void Save_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
@@ -58,6 +73,8 @@ public partial class MainView : UserControl
|
||||
}
|
||||
if (TxtIpAddress.Text == null) TxtIpAddress.Text = "";
|
||||
|
||||
MainUI.IsVisible = false;
|
||||
LoadingUI.IsVisible = true;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -67,6 +84,9 @@ public partial class MainView : UserControl
|
||||
{
|
||||
ShowWarningMsg("Failed to save configuration: " + ex.ToString(), "Error");
|
||||
}
|
||||
|
||||
LoadingUI.IsVisible = false;
|
||||
MainUI.IsVisible = true;
|
||||
}
|
||||
|
||||
private void CmbServerSelection_SelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
@@ -75,13 +95,69 @@ public partial class MainView : UserControl
|
||||
TxtIpAddress.IsEnabled = CmbServerSelection.SelectedIndex == 1;
|
||||
}
|
||||
|
||||
// for some stupid reason avalonia does not support message boxes.
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);
|
||||
|
||||
public static void ShowWarningMsg(string text, string title)
|
||||
{
|
||||
MessageBox(IntPtr.Zero, text, title, 0x00000030);
|
||||
ContentDialog dlg = new ContentDialog() { Title = title, Content = text, PrimaryButtonText = "OK" };
|
||||
dlg.ShowAsync();
|
||||
}
|
||||
|
||||
private async void BtnSelectGamePath_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
|
||||
if (topLevel != null)
|
||||
{
|
||||
// Start async operation to open the dialog.
|
||||
var files = await topLevel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
|
||||
{
|
||||
Title = "Select game path (with game executable)",
|
||||
AllowMultiple = false
|
||||
});
|
||||
|
||||
if (files.Count >= 1)
|
||||
{
|
||||
txtGamePath.Text = files[0].TryGetLocalPath();
|
||||
|
||||
// validate if the folder has game exe
|
||||
if (!string.IsNullOrEmpty(txtGamePath.Text))
|
||||
{
|
||||
if (!File.Exists(Path.Combine(txtGamePath.Text, "nikke.exe")))
|
||||
{
|
||||
ShowWarningMsg("Game path is invalid. Make sure that nikke.exe exists in the launcher folder", "Error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private async void BtnSelectLauncherPath_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
|
||||
if (topLevel != null)
|
||||
{
|
||||
// Start async operation to open the dialog.
|
||||
var files = await topLevel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
|
||||
{
|
||||
Title = "Select launcher path",
|
||||
AllowMultiple = false
|
||||
});
|
||||
|
||||
if (files.Count >= 1)
|
||||
{
|
||||
txtLauncherPath.Text = files[0].TryGetLocalPath();
|
||||
|
||||
// validate if the folder has game exe
|
||||
if (!string.IsNullOrEmpty(txtLauncherPath.Text))
|
||||
{
|
||||
if (!File.Exists(Path.Combine(txtLauncherPath.Text, "nikke_launcher.exe")))
|
||||
{
|
||||
ShowWarningMsg("Launcher path is invalid. Make sure that the game executable exists in the launcher folder", "Error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:views="clr-namespace:ServerSelector.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="370" d:DesignHeight="200"
|
||||
mc:Ignorable="d" d:DesignWidth="370" d:DesignHeight="250"
|
||||
x:Class="ServerSelector.Views.MainWindow"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
Title="Server Switcher Utility" Width="370" Height="210" CanResize="False">
|
||||
Title="Server Switcher" Width="370" Height="260" CanResize="False">
|
||||
<views:MainView />
|
||||
</Window>
|
||||
|
||||
Reference in New Issue
Block a user