mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-12 15:04:36 +01:00
remove unused code in serverselector, update packages
This commit is contained in:
@@ -22,11 +22,11 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ASodium" Version="0.6.2" />
|
<PackageReference Include="ASodium" Version="0.6.4" />
|
||||||
<PackageReference Include="DnsClient" Version="1.8.0" />
|
<PackageReference Include="DnsClient" Version="1.8.0" />
|
||||||
<PackageReference Include="Google.Api.CommonProtos" Version="2.17.0" />
|
<PackageReference Include="Google.Api.CommonProtos" Version="2.17.0" />
|
||||||
<PackageReference Include="Google.Protobuf.Tools" Version="3.31.1" />
|
<PackageReference Include="Google.Protobuf.Tools" Version="3.33.1" />
|
||||||
<PackageReference Include="Grpc.Tools" Version="2.72.0">
|
<PackageReference Include="Grpc.Tools" Version="2.76.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
<PackageReference Include="PeterO.Cbor" Version="4.5.5" />
|
<PackageReference Include="PeterO.Cbor" Version="4.5.5" />
|
||||||
<PackageReference Include="SharpZipLib" Version="1.4.2" />
|
<PackageReference Include="SharpZipLib" Version="1.4.2" />
|
||||||
<PackageReference Include="Sodium.Core" Version="1.4.0" />
|
<PackageReference Include="Sodium.Core" Version="1.4.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||||
<PackageReference Include="log4net" Version="3.2.0" />
|
<PackageReference Include="log4net" Version="3.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,6 @@ namespace ServerSelector
|
|||||||
{
|
{
|
||||||
public class ServerSwitcher
|
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 HostsStartMarker = "# begin ServerSelector entries";
|
||||||
private const string HostsEndMarker = "# end ServerSelector entries";
|
private const string HostsEndMarker = "# end ServerSelector entries";
|
||||||
|
|
||||||
@@ -31,7 +28,6 @@ namespace ServerSelector
|
|||||||
if (IsUsingOfficalServer())
|
if (IsUsingOfficalServer())
|
||||||
return "Official server";
|
return "Official server";
|
||||||
|
|
||||||
|
|
||||||
if (!Directory.Exists(gamePath))
|
if (!Directory.Exists(gamePath))
|
||||||
{
|
{
|
||||||
return "Game path does not exist";
|
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";
|
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 launcherCertList = launcherPath + "/intl_service/cacert.pem";
|
||||||
string gameCertList = gamePath + "/nikke_Data/Plugins/x86_64/intl_cacert.pem";
|
string gameCertList = gamePath + "/nikke_Data/Plugins/x86_64/intl_cacert.pem";
|
||||||
if (!File.Exists(gameCertList))
|
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<ServerSwitchResult> SaveCfg(bool useOffical, string gamePath, string? launcherPath, string ip, bool offlineMode)
|
public static async Task<ServerSwitchResult> SaveCfg(bool useOffical, string gamePath, string? launcherPath, string ip, bool offlineMode)
|
||||||
{
|
{
|
||||||
string sodiumLib = AppDomain.CurrentDomain.BaseDirectory + "sodium.dll";
|
string sodiumLib = AppDomain.CurrentDomain.BaseDirectory + "sodium.dll";
|
||||||
@@ -218,8 +142,6 @@ namespace ServerSelector
|
|||||||
hostsFilePath = gamePath + "/../../../windows/system32/drivers/etc/hosts";
|
hostsFilePath = gamePath + "/../../../windows/system32/drivers/etc/hosts";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: allow changing ip address
|
|
||||||
if (useOffical)
|
if (useOffical)
|
||||||
{
|
{
|
||||||
await RevertHostsFile(hostsFilePath);
|
await RevertHostsFile(hostsFilePath);
|
||||||
@@ -251,27 +173,22 @@ namespace ServerSelector
|
|||||||
}
|
}
|
||||||
File.Copy(sodiumBackup, gameSodium, true);
|
File.Copy(sodiumBackup, gameSodium, true);
|
||||||
|
|
||||||
if (!PatchGameAssembly(gameAssembly, false))
|
|
||||||
{
|
|
||||||
supported = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (File.Exists(launcherCertList))
|
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)
|
if (goodSslIndex1 != -1)
|
||||||
await File.WriteAllTextAsync(launcherCertList, certList1[..goodSslIndex1]);
|
await File.WriteAllTextAsync(launcherCertList, certList[..goodSslIndex1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File.Exists(gameCertList))
|
if (File.Exists(gameCertList))
|
||||||
{
|
{
|
||||||
string certList2 = await File.ReadAllTextAsync(gameCertList);
|
string certList = await File.ReadAllTextAsync(gameCertList);
|
||||||
|
|
||||||
int goodSslIndex2 = certList2.IndexOf("Good SSL Ca");
|
int newCertIndex = certList.IndexOf("Good SSL Ca");
|
||||||
if (goodSslIndex2 != -1)
|
if (newCertIndex != -1)
|
||||||
await File.WriteAllTextAsync(gameCertList, certList2[..goodSslIndex2]);
|
await File.WriteAllTextAsync(gameCertList, certList[..newCertIndex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -349,12 +266,7 @@ namespace ServerSelector
|
|||||||
store.Close();
|
store.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch { }
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// update sodium lib
|
|
||||||
|
|
||||||
if (!File.Exists(gameSodium))
|
if (!File.Exists(gameSodium))
|
||||||
{
|
{
|
||||||
@@ -363,7 +275,7 @@ namespace ServerSelector
|
|||||||
|
|
||||||
// copy backup if sodium size is correct
|
// copy backup if sodium size is correct
|
||||||
byte[] sod = await File.ReadAllBytesAsync(gameSodium);
|
byte[] sod = await File.ReadAllBytesAsync(gameSodium);
|
||||||
if (sod.Length <= 307200)
|
if (sod.Length <= 307200) // TODO this is awful
|
||||||
{
|
{
|
||||||
// orignal file size, copy backup
|
// orignal file size, copy backup
|
||||||
await File.WriteAllBytesAsync(sodiumBackup, sod);
|
await File.WriteAllBytesAsync(sodiumBackup, sod);
|
||||||
@@ -372,23 +284,19 @@ namespace ServerSelector
|
|||||||
// write new sodium library
|
// write new sodium library
|
||||||
await File.WriteAllBytesAsync(gameSodium, await File.ReadAllBytesAsync(sodiumLib));
|
await File.WriteAllBytesAsync(gameSodium, await File.ReadAllBytesAsync(sodiumLib));
|
||||||
|
|
||||||
// patch gameassembly to remove sodium IntegrityUtility Check introduced in v124.6.10
|
// Add generated CA certificate to launcher/game curl certificate list
|
||||||
supported = PatchGameAssembly(gameAssembly, true);
|
|
||||||
|
|
||||||
// update launcher/game ca cert list
|
|
||||||
|
|
||||||
if (launcherPath != null)
|
if (launcherPath != null)
|
||||||
{
|
{
|
||||||
string certList1 = await File.ReadAllTextAsync(launcherCertList);
|
await File.WriteAllTextAsync(launcherCertList,
|
||||||
certList1 += "\nGood SSL Ca\n===============================\n";
|
await File.ReadAllTextAsync(launcherCertList)
|
||||||
certList1 += CAcert;
|
+ "\nGood SSL Ca\n===============================\n"
|
||||||
await File.WriteAllTextAsync(launcherCertList, certList1);
|
+ CAcert);
|
||||||
}
|
}
|
||||||
|
|
||||||
string certList2 = await File.ReadAllTextAsync(gameCertList);
|
await File.WriteAllTextAsync(gameCertList,
|
||||||
certList2 += "\nGood SSL Ca\n===============================\n";
|
await File.ReadAllTextAsync(gameCertList)
|
||||||
certList2 += CAcert;
|
+ "\nGood SSL Ca\n===============================\n"
|
||||||
await File.WriteAllTextAsync(gameCertList, certList2);
|
+ CAcert);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ServerSwitchResult(true, null, supported);
|
return new ServerSwitchResult(true, null, supported);
|
||||||
|
|||||||
Reference in New Issue
Block a user