mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-12 23:14:34 +01:00
fix namespaces, compiler warnings and messages
This commit is contained in:
@@ -33,10 +33,7 @@ namespace ServerSelector
|
||||
|
||||
}
|
||||
|
||||
if (_settings == null)
|
||||
{
|
||||
_settings = new();
|
||||
}
|
||||
_settings ??= new();
|
||||
|
||||
return _settings;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public static class PatchUtility
|
||||
byte[] searchBytes = HexStringToBytes(searchPatterns[k]);
|
||||
|
||||
// Find the index of the first occurrence of the search pattern in the file data using another helper method
|
||||
var results = FindPatternIndex(fileData, searchBytes);
|
||||
List<int> results = FindPatternIndex(fileData, searchBytes);
|
||||
if (results.Count <= 1) return false;
|
||||
|
||||
Console.WriteLine("offset: " + results[1].ToString("X"));
|
||||
@@ -72,7 +72,7 @@ public static class PatchUtility
|
||||
// Note: game versions 124 - 133 have 2 matches, 2nd one is the correct one
|
||||
// game version 134 - ? has 1 match which is correct
|
||||
int index = -1;
|
||||
var indexes = FindPatternIndex(fileData, searchBytes);
|
||||
List<int> indexes = FindPatternIndex(fileData, searchBytes);
|
||||
if (indexes.Count == 1)
|
||||
index = indexes[0];
|
||||
else index = indexes[1];
|
||||
@@ -125,10 +125,9 @@ public static class PatchUtility
|
||||
private static byte[] HexStringToBytes(string hex)
|
||||
{
|
||||
hex = hex.Replace(" ", "").Replace("??", "FF"); // Replace ?? with FF for wildcards
|
||||
return Enumerable.Range(0, hex.Length)
|
||||
return [.. Enumerable.Range(0, hex.Length)
|
||||
.Where(x => x % 2 == 0) // Take every second character in the string
|
||||
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) // Convert each pair of characters to a byte value in base 16
|
||||
.ToArray(); // Convert the result to an array of bytes
|
||||
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))]; // Convert the result to an array of bytes
|
||||
}
|
||||
|
||||
// This helper method finds the index of the first occurrence of a pattern in a data array
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#define GameAssemblyNeedsPatch // remove if running on versions before v124
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading.Tasks;
|
||||
@@ -8,20 +9,19 @@ namespace ServerSelector
|
||||
public class ServerSwitcher
|
||||
{
|
||||
private static readonly string[] GameAssemblySodiumIntegrityFuncHint = ["40 53 56 57 41 54 41 55 41 56 41 57 48 81 EC C0 00 00 00 80 3d ?? ?? ?? ?? 00 0f 85 ?? 00 00 00 48"];
|
||||
private const bool GameAssemblyNeedsPatch = true; // Set to false if running on versions before v124
|
||||
private static readonly string[] GameAssemblySodiumIntegrityFuncPatch = ["b0 01 c3 90 90"];
|
||||
private const string HostsStartMarker = "# begin ServerSelector entries";
|
||||
private const string HostsEndMarker = "# end ServerSelector entries";
|
||||
|
||||
public static bool IsUsingOfficalServer()
|
||||
{
|
||||
var hostsFile = File.ReadAllText(OperatingSystem.IsWindows() ? "C:\\Windows\\System32\\drivers\\etc\\hosts" : "/etc/hosts");
|
||||
string 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(OperatingSystem.IsWindows() ? "C:\\Windows\\System32\\drivers\\etc\\hosts" : "/etc/hosts");
|
||||
string hostsFile = File.ReadAllText(OperatingSystem.IsWindows() ? "C:\\Windows\\System32\\drivers\\etc\\hosts" : "/etc/hosts");
|
||||
return hostsFile.Contains("cloud.nikke-kr.com");
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace ServerSelector
|
||||
|
||||
if (File.Exists(launcherCertList))
|
||||
{
|
||||
var certList1 = await File.ReadAllTextAsync(launcherCertList);
|
||||
string certList1 = await File.ReadAllTextAsync(launcherCertList);
|
||||
|
||||
if (!certList1.Contains("Good SSL Ca"))
|
||||
return "Patch missing";
|
||||
@@ -73,7 +73,7 @@ namespace ServerSelector
|
||||
|
||||
if (File.Exists(gameCertList))
|
||||
{
|
||||
var certList2 = await File.ReadAllTextAsync(gameCertList);
|
||||
string certList2 = await File.ReadAllTextAsync(gameCertList);
|
||||
|
||||
if (!certList2.Contains("Good SSL Ca"))
|
||||
return "Patch missing";
|
||||
@@ -88,7 +88,7 @@ namespace ServerSelector
|
||||
|
||||
public static async Task RevertHostsFile(string hostsFilePath)
|
||||
{
|
||||
var txt = await File.ReadAllTextAsync(hostsFilePath);
|
||||
string txt = await File.ReadAllTextAsync(hostsFilePath);
|
||||
|
||||
// remove stuff
|
||||
try
|
||||
@@ -107,7 +107,7 @@ namespace ServerSelector
|
||||
// old code, find new line character before start index
|
||||
for (int i = startIdx - 1; i >= 0; i--)
|
||||
{
|
||||
var c = txt[i];
|
||||
char c = txt[i];
|
||||
if (c == '\n')
|
||||
{
|
||||
startIdx = i + 1;
|
||||
@@ -139,8 +139,9 @@ namespace ServerSelector
|
||||
public static bool PatchGameAssembly(string dll, bool install)
|
||||
{
|
||||
// v124 introduced check to ensure that sodium dll is not changed.
|
||||
if (!GameAssemblyNeedsPatch) return true;
|
||||
|
||||
#if GameAssemblyNeedsPatch
|
||||
return true;
|
||||
#else
|
||||
string backupPath = dll + ".bak";
|
||||
bool backupExists = File.Exists(backupPath);
|
||||
|
||||
@@ -186,6 +187,7 @@ namespace ServerSelector
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static async Task<ServerSwitchResult> SaveCfg(bool useOffical, string gamePath, string? launcherPath, string ip, bool offlineMode)
|
||||
@@ -195,7 +197,7 @@ namespace ServerSelector
|
||||
string gameAssembly = gamePath + "/GameAssembly.dll";
|
||||
string sodiumBackup = gameSodium + ".bak";
|
||||
string hostsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers/etc/hosts");
|
||||
var CAcert = await File.ReadAllTextAsync(AppDomain.CurrentDomain.BaseDirectory + "myCA.pem");
|
||||
string CAcert = await File.ReadAllTextAsync(AppDomain.CurrentDomain.BaseDirectory + "myCA.pem");
|
||||
|
||||
string launcherCertList = launcherPath + "/intl_service/cacert.pem";
|
||||
string gameCertList = gamePath + "/nikke_Data/Plugins/x86_64/intl_cacert.pem";
|
||||
@@ -249,7 +251,7 @@ namespace ServerSelector
|
||||
|
||||
if (File.Exists(launcherCertList))
|
||||
{
|
||||
var certList1 = await File.ReadAllTextAsync(launcherCertList);
|
||||
string certList1 = await File.ReadAllTextAsync(launcherCertList);
|
||||
|
||||
int goodSslIndex1 = certList1.IndexOf("Good SSL Ca");
|
||||
if (goodSslIndex1 != -1)
|
||||
@@ -258,7 +260,7 @@ namespace ServerSelector
|
||||
|
||||
if (File.Exists(gameCertList))
|
||||
{
|
||||
var certList2 = await File.ReadAllTextAsync(gameCertList);
|
||||
string certList2 = await File.ReadAllTextAsync(gameCertList);
|
||||
|
||||
int goodSslIndex2 = certList2.IndexOf("Good SSL Ca");
|
||||
if (goodSslIndex2 != -1)
|
||||
@@ -353,7 +355,7 @@ namespace ServerSelector
|
||||
}
|
||||
|
||||
// copy backup if sodium size is correct
|
||||
var sod = await File.ReadAllBytesAsync(gameSodium);
|
||||
byte[] sod = await File.ReadAllBytesAsync(gameSodium);
|
||||
if (sod.Length <= 307200)
|
||||
{
|
||||
// orignal file size, copy backup
|
||||
@@ -370,13 +372,13 @@ namespace ServerSelector
|
||||
|
||||
if (launcherPath != null)
|
||||
{
|
||||
var certList1 = await File.ReadAllTextAsync(launcherCertList);
|
||||
string certList1 = await File.ReadAllTextAsync(launcherCertList);
|
||||
certList1 += "\nGood SSL Ca\n===============================\n";
|
||||
certList1 += CAcert;
|
||||
await File.WriteAllTextAsync(launcherCertList, certList1);
|
||||
}
|
||||
|
||||
var certList2 = await File.ReadAllTextAsync(gameCertList);
|
||||
string certList2 = await File.ReadAllTextAsync(gameCertList);
|
||||
certList2 += "\nGood SSL Ca\n===============================\n";
|
||||
certList2 += CAcert;
|
||||
await File.WriteAllTextAsync(gameCertList, certList2);
|
||||
|
||||
@@ -150,7 +150,7 @@ public partial class MainView : UserControl
|
||||
SetLoadingScreenVisible(true);
|
||||
try
|
||||
{
|
||||
var res = await ServerSwitcher.SaveCfg(CmbServerSelection.SelectedIndex == 0, GamePath, LauncherPath, TxtIpAddress.Text, ChkOffline.IsChecked ?? false);
|
||||
ServerSwitchResult res = await ServerSwitcher.SaveCfg(CmbServerSelection.SelectedIndex == 0, GamePath, LauncherPath, TxtIpAddress.Text, ChkOffline.IsChecked ?? false);
|
||||
|
||||
if (!res.IsSupported)
|
||||
{
|
||||
@@ -183,12 +183,12 @@ public partial class MainView : UserControl
|
||||
|
||||
private async void BtnSelectGamePath_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
TopLevel? topLevel = TopLevel.GetTopLevel(this);
|
||||
|
||||
if (topLevel != null)
|
||||
{
|
||||
// Start async operation to open the dialog.
|
||||
var files = await topLevel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
|
||||
System.Collections.Generic.IReadOnlyList<IStorageFolder> files = await topLevel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
|
||||
{
|
||||
Title = "Select game path, with launcher and game folder",
|
||||
AllowMultiple = false
|
||||
|
||||
Reference in New Issue
Block a user