mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-13 07:24:52 +01:00
fix issue requiring game reinstall after game updates
This commit is contained in:
@@ -5,8 +5,38 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace ServerSelector;
|
||||
|
||||
public static class PatchUtility
|
||||
{
|
||||
public static bool CanFindOffset(string filePath, string[] searchPatterns)
|
||||
{
|
||||
// Check if the file exists
|
||||
if (!File.Exists(filePath)) { Console.WriteLine("[ERROR] File not found: " + filePath); return false; }
|
||||
|
||||
// Read the binary data from the file as an array of bytes
|
||||
byte[] fileData = File.ReadAllBytes(filePath);
|
||||
|
||||
for (int k = 0; k < searchPatterns.Length; k++)
|
||||
{
|
||||
// Convert the hexadecimal strings to byte arrays using a helper method
|
||||
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);
|
||||
if (results.Count <= 1) return false;
|
||||
|
||||
Console.WriteLine("offset: " + results[1].ToString("X"));
|
||||
|
||||
// If the index is -1, it means the pattern was not found, so we return false and log an error message
|
||||
if (results[1] == -1)
|
||||
{
|
||||
Console.WriteLine("[ERROR] Search pattern not found: " + searchPatterns[k]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// This method searches and replaces binary patterns in a given file
|
||||
// It takes three parameters:
|
||||
// - filePath: the path of the file to be patched
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace ServerSelector
|
||||
{
|
||||
public class ServerSwitcher
|
||||
{
|
||||
private static 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"];
|
||||
public static bool GameAssemblyNeedsPatch = true; // Set to false if running on versions before v124
|
||||
private static string[] GameAssemblySodiumIntegrityFuncPatch = ["b0 01 c3 90 90"];
|
||||
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";
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace ServerSelector
|
||||
{
|
||||
return PatchUtility.SearchAndReplace(dll, GameAssemblySodiumIntegrityFuncHint, GameAssemblySodiumIntegrityFuncPatch);
|
||||
}
|
||||
else if (backupExists)
|
||||
else if (backupExists && !PatchUtility.CanFindOffset(dll, GameAssemblySodiumIntegrityFuncHint))
|
||||
{
|
||||
File.Move(dll + ".bak", dll, true);
|
||||
}
|
||||
@@ -210,7 +210,7 @@ namespace ServerSelector
|
||||
|
||||
if (!PatchGameAssembly(gameAssembly, false))
|
||||
{
|
||||
throw new Exception("Failed to restore GameAssembly.dll. Please repair the game in the launcher.");
|
||||
supported = false;
|
||||
}
|
||||
|
||||
if (File.Exists(launcherCertList))
|
||||
|
||||
@@ -34,6 +34,7 @@ public partial class MainView : UserControl
|
||||
{
|
||||
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
|
||||
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
|
||||
TextWrapping = TextWrapping.Wrap,
|
||||
Text = "Root is required to change servers in order to modify /etc/hosts."
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user