mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-12 23:14:34 +01:00
server selector remove launcher textbox
This commit is contained in:
@@ -15,13 +15,13 @@ namespace ServerSelector
|
||||
|
||||
public static bool IsUsingOfficalServer()
|
||||
{
|
||||
var hostsFile = File.ReadAllText("C:\\Windows\\System32\\drivers\\etc\\hosts");
|
||||
var hostsFile = File.ReadAllText(OperatingSystem.IsWindows() ? "C:\\Windows\\System32\\drivers\\etc\\hosts" : "/etc/hosts");
|
||||
return !hostsFile.Contains("global-lobby.nikke-kr.com");
|
||||
}
|
||||
|
||||
public static bool IsOffline()
|
||||
{
|
||||
var hostsFile = File.ReadAllText("C:\\Windows\\System32\\drivers\\etc\\hosts");
|
||||
var hostsFile = File.ReadAllText(OperatingSystem.IsWindows() ? "C:\\Windows\\System32\\drivers\\etc\\hosts" : "/etc/hosts");
|
||||
return hostsFile.Contains("cloud.nikke-kr.com");
|
||||
}
|
||||
|
||||
@@ -51,6 +51,13 @@ namespace ServerSelector
|
||||
string gameAssembly = gamePath + "/GameAssembly.dll";
|
||||
string sodiumBackup = gameSodium + ".bak";
|
||||
string hostsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers/etc/hosts");
|
||||
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
// for wine
|
||||
hostsFilePath = gamePath + "/../../../windows/system32/drivers/etc/hosts";
|
||||
}
|
||||
|
||||
var CAcert = await File.ReadAllTextAsync(AppDomain.CurrentDomain.BaseDirectory + "myCA.pem");
|
||||
|
||||
string launcherCertList = launcherPath + "/intl_service/cacert.pem";
|
||||
@@ -75,9 +82,8 @@ namespace ServerSelector
|
||||
return "OK";
|
||||
}
|
||||
|
||||
public static async Task RevertHostsFile()
|
||||
public static async Task RevertHostsFile(string hostsFilePath)
|
||||
{
|
||||
string hostsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers/etc/hosts");
|
||||
var txt = await File.ReadAllTextAsync(hostsFilePath);
|
||||
|
||||
// remove stuff
|
||||
@@ -139,16 +145,30 @@ namespace ServerSelector
|
||||
string gameCertList = gamePath + "/nikke_Data/Plugins/x86_64/cacert.pem";
|
||||
|
||||
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
// for wine
|
||||
hostsFilePath = gamePath + "/../../../windows/system32/drivers/etc/hosts";
|
||||
}
|
||||
|
||||
|
||||
// TODO: allow changing ip address
|
||||
if (useOffical)
|
||||
{
|
||||
await RevertHostsFile();
|
||||
await RevertHostsFile(hostsFilePath);
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
await RevertHostsFile("/etc/hosts");
|
||||
}
|
||||
|
||||
// remove cert
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
|
||||
store.Open(OpenFlags.ReadWrite);
|
||||
store.Remove(new X509Certificate2(X509Certificate.CreateFromCertFile(AppDomain.CurrentDomain.BaseDirectory + "myCA.pfx")));
|
||||
store.Close();
|
||||
}
|
||||
|
||||
// restore sodium
|
||||
if (!File.Exists(sodiumBackup))
|
||||
@@ -228,20 +248,35 @@ namespace ServerSelector
|
||||
255.255.221.21 sentry.io
|
||||
{HostsEndMarker}";
|
||||
|
||||
await RevertHostsFile();
|
||||
await RevertHostsFile(hostsFilePath);
|
||||
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"));
|
||||
using StreamWriter w = File.AppendText(hostsFilePath);
|
||||
w.WriteLine();
|
||||
w.Write(hosts);
|
||||
}
|
||||
|
||||
// Also change /etc/hosts if running on linux
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
hostsFilePath = "/etc/hosts";
|
||||
await RevertHostsFile(hostsFilePath);
|
||||
if (!(await File.ReadAllTextAsync(hostsFilePath)).Contains("global-lobby.nikke-kr.com"))
|
||||
{
|
||||
using StreamWriter w = File.AppendText(hostsFilePath);
|
||||
w.WriteLine();
|
||||
w.Write(hosts);
|
||||
}
|
||||
}
|
||||
|
||||
// trust CA
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
|
||||
store.Open(OpenFlags.ReadWrite);
|
||||
store.Add(new X509Certificate2(X509Certificate2.CreateFromCertFile(AppDomain.CurrentDomain.BaseDirectory + "myCA.pfx")));
|
||||
store.Close();
|
||||
}
|
||||
|
||||
// update sodium lib
|
||||
|
||||
|
||||
@@ -33,14 +33,9 @@
|
||||
|
||||
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="0" Grid.Column="0">Game path: </TextBlock>
|
||||
<TextBox x:Name="txtGamePath" Grid.Row="0" Grid.Column="1" TextChanged="GamePath_TextChanged">C:\NIKKE\NIKKE\game</TextBox>
|
||||
<TextBox x:Name="txtGamePath" Grid.Row="0" Grid.Column="1" TextChanged="GamePath_TextChanged">C:\NIKKE\NIKKE\</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" TextChanged="LauncherPath_TextChanged">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>
|
||||
|
||||
<ComboBox SelectedIndex="0" x:Name="CmbServerSelection" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" SelectionChanged="CmbServerSelection_SelectionChanged" HorizontalAlignment="Stretch">
|
||||
@@ -55,7 +50,7 @@
|
||||
|
||||
<CheckBox x:Name="ChkOffline" VerticalAlignment="Center" Margin="5" Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="3" ToolTip.Tip="Enables the ability to run the game offline by making the game download the assets from the server, and not the official server. This only works if enableOffline is enabled on the server. Please note that this should not be enabled on public servers due to copyright issues, as assets are downloaded through said server. This is required if you want to use an older version of the game.">Enable offline mode</CheckBox>
|
||||
|
||||
<TextBlock Grid.Row="10" Grid.Column="0" VerticalAlignment="Center" Margin="5" x:Name="LblStatus" ToolTip.Tip="Shows the status of the patches to the game. All patches are reverted when server is set to official.">Status: OK</TextBlock>
|
||||
<TextBlock Grid.Row="10" Grid.Column="0" TextWrapping="WrapWithOverflow" VerticalAlignment="Center" Margin="5" x:Name="LblStatus" ToolTip.Tip="Shows the status of the patches to the game. All patches are reverted when server is set to official.">Status: OK</TextBlock>
|
||||
<Button HorizontalAlignment="Right" Margin="5" Click="Save_Click" Grid.Row="10" Grid.Column="1" Grid.ColumnSpan="2" Classes="accent">Save</Button>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
@@ -29,6 +29,15 @@ public partial class MainView : UserControl
|
||||
Text = "Administrator privileges are required to change servers."
|
||||
};
|
||||
}
|
||||
if (OperatingSystem.IsLinux() && Environment.UserName != "root")
|
||||
{
|
||||
TabPc.Content = new TextBlock()
|
||||
{
|
||||
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
|
||||
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
|
||||
Text = "Root is required to change servers."
|
||||
};
|
||||
}
|
||||
|
||||
UpdateIntegrityLabel();
|
||||
}
|
||||
@@ -41,39 +50,37 @@ public partial class MainView : UserControl
|
||||
}
|
||||
else
|
||||
{
|
||||
txtGamePath.BorderBrush = new SolidColorBrush(Color.FromRgb(255,0,0));
|
||||
}
|
||||
}
|
||||
private void SetLauncherPathValid(bool isValid)
|
||||
{
|
||||
if (isValid)
|
||||
{
|
||||
txtLauncherPath.BorderBrush = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
txtLauncherPath.BorderBrush = new SolidColorBrush(Color.FromRgb(255, 0, 0));
|
||||
txtGamePath.BorderBrush = new SolidColorBrush(Color.FromRgb(255, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
private string? GamePath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (txtGamePath.Text == null) return null;
|
||||
return Path.Combine(txtGamePath.Text, "NIKKE", "game");
|
||||
}
|
||||
}
|
||||
private string? LauncherPath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (txtGamePath.Text == null) return null;
|
||||
return Path.Combine(txtGamePath.Text, "Launcher");
|
||||
}
|
||||
}
|
||||
private bool ValidatePaths(bool showMessage)
|
||||
{
|
||||
if (string.IsNullOrEmpty(txtGamePath.Text))
|
||||
if (string.IsNullOrEmpty(txtGamePath.Text) || LauncherPath == null)
|
||||
{
|
||||
SetGamePathValid(false);
|
||||
if (showMessage)
|
||||
ShowWarningMsg("Game path is blank", "Error");
|
||||
return false;
|
||||
}
|
||||
if (string.IsNullOrEmpty(txtLauncherPath.Text))
|
||||
{
|
||||
SetLauncherPathValid(false);
|
||||
if (showMessage)
|
||||
ShowWarningMsg("Launcher path is blank", "Error");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Directory.Exists(txtGamePath.Text))
|
||||
if (!Directory.Exists(GamePath))
|
||||
{
|
||||
SetGamePathValid(false);
|
||||
if (showMessage)
|
||||
@@ -81,36 +88,27 @@ public partial class MainView : UserControl
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Directory.Exists(txtLauncherPath.Text))
|
||||
{
|
||||
SetLauncherPathValid(false);
|
||||
if (showMessage)
|
||||
ShowWarningMsg("Launcher path does not exist", "Error");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!File.Exists(Path.Combine(txtLauncherPath.Text, "nikke_launcher.exe")))
|
||||
if (!File.Exists(Path.Combine(LauncherPath, "nikke_launcher.exe")))
|
||||
{
|
||||
SetGamePathValid(false);
|
||||
if (showMessage)
|
||||
ShowWarningMsg("Launcher path is invalid. Make sure that the game executable exists in the launcher folder", "Error");
|
||||
ShowWarningMsg("Launcher path is invalid. Make sure that nikke_launcher.exe exists in the launcher folder", "Error");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SetGamePathValid(true);
|
||||
SetLauncherPathValid(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async void UpdateIntegrityLabel()
|
||||
{
|
||||
if (!ValidatePaths(false) || txtGamePath.Text == null || txtLauncherPath.Text == null)
|
||||
if (!ValidatePaths(false) || txtGamePath.Text == null || GamePath == null || LauncherPath == null)
|
||||
return;
|
||||
|
||||
SetLoadingScreenVisible(true);
|
||||
LblStatus.Text = "Status: " + await ServerSwitcher.CheckIntegrity(txtGamePath.Text, txtLauncherPath.Text);
|
||||
LblStatus.Text = "Status: " + await ServerSwitcher.CheckIntegrity(GamePath, LauncherPath);
|
||||
SetLoadingScreenVisible(false);
|
||||
}
|
||||
|
||||
@@ -130,7 +128,7 @@ public partial class MainView : UserControl
|
||||
|
||||
private async void Save_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
if (!ValidatePaths(true) || txtGamePath.Text == null || txtLauncherPath.Text == null)
|
||||
if (!ValidatePaths(true) || txtGamePath.Text == null || GamePath == null || LauncherPath == null)
|
||||
return;
|
||||
|
||||
if (CmbServerSelection.SelectedIndex == 1)
|
||||
@@ -146,7 +144,7 @@ public partial class MainView : UserControl
|
||||
SetLoadingScreenVisible(true);
|
||||
try
|
||||
{
|
||||
await ServerSwitcher.SaveCfg(CmbServerSelection.SelectedIndex == 0, txtGamePath.Text, txtLauncherPath.Text, TxtIpAddress.Text, ChkOffline.IsChecked ?? false);
|
||||
await ServerSwitcher.SaveCfg(CmbServerSelection.SelectedIndex == 0, GamePath, LauncherPath, TxtIpAddress.Text, ChkOffline.IsChecked ?? false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -192,9 +190,14 @@ public partial class MainView : UserControl
|
||||
// validate if the folder has game exe
|
||||
if (!string.IsNullOrEmpty(txtGamePath.Text))
|
||||
{
|
||||
if (!File.Exists(Path.Combine(txtGamePath.Text, "nikke.exe")))
|
||||
if (!File.Exists(Path.Combine(txtGamePath.Text, "game", "nikke.exe")))
|
||||
{
|
||||
ShowWarningMsg("Game path is invalid. Make sure that nikke.exe exists in the launcher folder", "Error");
|
||||
ShowWarningMsg("Game path is invalid. Make sure that nikke.exe exists in the game folder", "Error");
|
||||
return;
|
||||
}
|
||||
if (!File.Exists(Path.Combine(txtGamePath.Text, "Launcher", "nikke_launcher.exe")))
|
||||
{
|
||||
ShowWarningMsg("Game path is invalid. Make sure that nikke_launcher.exe exists in the Launcher folder", "Error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -202,36 +205,7 @@ public partial class MainView : UserControl
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
UpdateIntegrityLabel();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void GamePath_TextChanged(object? sender, Avalonia.Controls.TextChangedEventArgs e)
|
||||
{
|
||||
UpdateIntegrityLabel();
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
xmlns:views="clr-namespace:ServerSelector.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="370" d:DesignHeight="300"
|
||||
x:Class="ServerSelector.Views.MainWindow"
|
||||
Title="Server Switcher" Width="370" Height="300" CanResize="False">
|
||||
Title="Server Switcher" Width="370" Height="300" CanResize="True">
|
||||
<views:MainView />
|
||||
</Window>
|
||||
|
||||
Reference in New Issue
Block a user