diff --git a/EpinelPS/EpinelPS.csproj b/EpinelPS/EpinelPS.csproj index e776ff3..cbb068c 100644 --- a/EpinelPS/EpinelPS.csproj +++ b/EpinelPS/EpinelPS.csproj @@ -22,11 +22,11 @@ - + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -36,7 +36,7 @@ - + diff --git a/ServerSelector/ServerSwitcher.cs b/ServerSelector/ServerSwitcher.cs index 64e425d..a6e47ce 100644 --- a/ServerSelector/ServerSwitcher.cs +++ b/ServerSelector/ServerSwitcher.cs @@ -8,9 +8,6 @@ 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 static readonly string[] GameAssemblySodiumIntegrityFuncPatched = ["b0 01 c3 90 90 54 41 55 41 56 41 57 48 81 EC C0 00 00 00 80 3d ?? ?? ?? ?? 00 0f 85 ?? 00 00 00 48"]; - private static readonly string[] GameAssemblySodiumIntegrityFuncPatch = ["b0 01 c3 90 90"]; private const string HostsStartMarker = "# begin ServerSelector entries"; private const string HostsEndMarker = "# end ServerSelector entries"; @@ -31,7 +28,6 @@ namespace ServerSelector if (IsUsingOfficalServer()) return "Official server"; - if (!Directory.Exists(gamePath)) { return "Game path does not exist"; @@ -47,18 +43,6 @@ namespace ServerSelector return "Launcher path is invalid. Make sure that the game executable exists in the launcher folder"; } - 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"); - - if (OperatingSystem.IsLinux()) - { - // for wine - hostsFilePath = gamePath + "/../../../windows/system32/drivers/etc/hosts"; - } - string launcherCertList = launcherPath + "/intl_service/cacert.pem"; string gameCertList = gamePath + "/nikke_Data/Plugins/x86_64/intl_cacert.pem"; if (!File.Exists(gameCertList)) @@ -137,66 +121,6 @@ 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; -#else - string backupPath = dll + ".bak"; - bool backupExists = File.Exists(backupPath); - - /* - Official->Local (Install): - - Check if backup file exists: - - Game was updated, delete backup file - - Check if game assembly is not patched: - - Patch game assembly - Local->Official (Uninstall): - - Check if game assembly is not patched: - - Game updated, delete backup and return - - Check if backup exists - - Restore DLL - */ - - if (install) - { - // todo reuse offset value - if (backupExists && PatchUtility.CanFindOffset(dll, GameAssemblySodiumIntegrityFuncHint)) - { - // game was likely updated, delete backup - File.Delete(backupPath); - } - - if (PatchUtility.CanFindOffset(dll, GameAssemblySodiumIntegrityFuncPatched)) - { - // already patched - return true; - } - - // patch assembly - return PatchUtility.SearchAndReplace(dll, GameAssemblySodiumIntegrityFuncHint, GameAssemblySodiumIntegrityFuncPatch); - } - else - { - if (PatchUtility.CanFindOffset(dll, GameAssemblySodiumIntegrityFuncHint)) - { - // game was updated, delete backup - if (backupExists) File.Delete(backupPath); - return true; - } - - // restore backup if it exists - if (backupExists) - { - File.Move(backupPath, dll, true); - } - } - - return true; -#endif - } - public static async Task SaveCfg(bool useOffical, string gamePath, string? launcherPath, string ip, bool offlineMode) { string sodiumLib = AppDomain.CurrentDomain.BaseDirectory + "sodium.dll"; @@ -218,8 +142,6 @@ namespace ServerSelector hostsFilePath = gamePath + "/../../../windows/system32/drivers/etc/hosts"; } - - // TODO: allow changing ip address if (useOffical) { await RevertHostsFile(hostsFilePath); @@ -251,27 +173,22 @@ namespace ServerSelector } File.Copy(sodiumBackup, gameSodium, true); - if (!PatchGameAssembly(gameAssembly, false)) - { - supported = false; - } - if (File.Exists(launcherCertList)) { - string certList1 = await File.ReadAllTextAsync(launcherCertList); + string certList = await File.ReadAllTextAsync(launcherCertList); - int goodSslIndex1 = certList1.IndexOf("Good SSL Ca"); + int goodSslIndex1 = certList.IndexOf("Good SSL Ca"); if (goodSslIndex1 != -1) - await File.WriteAllTextAsync(launcherCertList, certList1[..goodSslIndex1]); + await File.WriteAllTextAsync(launcherCertList, certList[..goodSslIndex1]); } if (File.Exists(gameCertList)) { - string certList2 = await File.ReadAllTextAsync(gameCertList); + string certList = await File.ReadAllTextAsync(gameCertList); - int goodSslIndex2 = certList2.IndexOf("Good SSL Ca"); - if (goodSslIndex2 != -1) - await File.WriteAllTextAsync(gameCertList, certList2[..goodSslIndex2]); + int newCertIndex = certList.IndexOf("Good SSL Ca"); + if (newCertIndex != -1) + await File.WriteAllTextAsync(gameCertList, certList[..newCertIndex]); } } else @@ -349,12 +266,7 @@ namespace ServerSelector store.Close(); } } - catch - { - - } - - // update sodium lib + catch { } if (!File.Exists(gameSodium)) { @@ -363,7 +275,7 @@ namespace ServerSelector // copy backup if sodium size is correct byte[] sod = await File.ReadAllBytesAsync(gameSodium); - if (sod.Length <= 307200) + if (sod.Length <= 307200) // TODO this is awful { // orignal file size, copy backup await File.WriteAllBytesAsync(sodiumBackup, sod); @@ -372,23 +284,19 @@ namespace ServerSelector // write new sodium library await File.WriteAllBytesAsync(gameSodium, await File.ReadAllBytesAsync(sodiumLib)); - // patch gameassembly to remove sodium IntegrityUtility Check introduced in v124.6.10 - supported = PatchGameAssembly(gameAssembly, true); - - // update launcher/game ca cert list - + // Add generated CA certificate to launcher/game curl certificate list if (launcherPath != null) { - string certList1 = await File.ReadAllTextAsync(launcherCertList); - certList1 += "\nGood SSL Ca\n===============================\n"; - certList1 += CAcert; - await File.WriteAllTextAsync(launcherCertList, certList1); + await File.WriteAllTextAsync(launcherCertList, + await File.ReadAllTextAsync(launcherCertList) + + "\nGood SSL Ca\n===============================\n" + + CAcert); } - string certList2 = await File.ReadAllTextAsync(gameCertList); - certList2 += "\nGood SSL Ca\n===============================\n"; - certList2 += CAcert; - await File.WriteAllTextAsync(gameCertList, certList2); + await File.WriteAllTextAsync(gameCertList, + await File.ReadAllTextAsync(gameCertList) + + "\nGood SSL Ca\n===============================\n" + + CAcert); } return new ServerSwitchResult(true, null, supported);