0
0
mirror of https://github.com/sp-tarkov/launcher.git synced 2025-02-13 02:50:44 -05:00

Feature - Add file version comparison check for bepinex/plugins/spt-core.dll to ensure it matches same value as server on game start

This commit is contained in:
Dev 2024-06-05 17:23:27 +01:00
parent 1e30609baf
commit 9880d2ad18
4 changed files with 67 additions and 3 deletions

View File

@ -20,6 +20,7 @@ using System.Threading.Tasks;
using SPT.Launcher.Controllers; using SPT.Launcher.Controllers;
using SPT.Launcher.Interfaces; using SPT.Launcher.Interfaces;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SPT.Launcher.Models.SPT;
namespace SPT.Launcher namespace SPT.Launcher
{ {
@ -66,6 +67,13 @@ namespace SPT.Launcher
return GameStarterResult.FromError(-1); return GameStarterResult.FromError(-1);
} }
// Confirm core.dll version matches version server is running
if (IsCoreDllVersionMismatched(gamePath))
{
LogManager.Instance.Error("[LaunchGame] Core dll mismatch :: FAILED");
return GameStarterResult.FromError(-8);
}
LogManager.Instance.Info("[LaunchGame] Installed in Live :: NO"); LogManager.Instance.Info("[LaunchGame] Installed in Live :: NO");
LogManager.Instance.Info("[LaunchGame] Setup Game Files ..."); LogManager.Instance.Info("[LaunchGame] Setup Game Files ...");
@ -204,6 +212,39 @@ namespace SPT.Launcher
return isInstalledInLive; return isInstalledInLive;
} }
static bool IsCoreDllVersionMismatched(string gamePath)
{
try
{
var serverVersion = new SPTVersion(ServerManager.GetVersion());
var coreDllVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine($"{gamePath}/BepinEx/plugins/spt", "spt-core.dll"));
var dllVersion = new SPTVersion(coreDllVersionInfo.FileVersion);
LogManager.Instance.Info($"[LaunchGame] spt-core.dll version: {dllVersion}");
// Edge case, running on locally built modules dlls, ignore check and return ok
if (dllVersion.Major == 0) return false;
// check 'X'.x.x
if (serverVersion.Major != dllVersion.Major) return true;
// check x.'X'.x
if (serverVersion.Minor != dllVersion.Minor) return true;
// check x.x.'X'
if (serverVersion.Tag != dllVersion.Tag) return true;
return false; // Versions match, hooray
}
catch (Exception ex)
{
LogManager.Instance.Exception(ex);
}
return true;
}
void SetupGameFiles(string gamePath) void SetupGameFiles(string gamePath)
{ {
var files = new [] var files = new []

View File

@ -1793,6 +1793,24 @@ namespace SPT.Launcher.Helpers
} }
#endregion #endregion
#region core_dll_file_version_mismatch
private string _core_dll_file_version_mismatch;
public string core_dll_file_version_mismatch
{
get => _core_dll_file_version_mismatch;
set
{
if (_core_dll_file_version_mismatch != value)
{
_core_dll_file_version_mismatch = value;
RaisePropertyChanged(nameof(core_dll_file_version_mismatch));
}
}
}
#endregion
#endregion #endregion
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;

View File

@ -48,6 +48,10 @@ namespace SPT.Launcher.Models.Launcher
Message = ":("; Message = ":(";
break; break;
case -8:
Message = LocalizationProvider.Instance.core_dll_file_version_mismatch;
break;
default: default:
Message = LocalizationProvider.Instance.login_failed; Message = LocalizationProvider.Instance.login_failed;
break; break;

View File

@ -95,5 +95,6 @@
"open_link_question_format_1": "Are you sure you want to open the following link: \n{0}", "open_link_question_format_1": "Are you sure you want to open the following link: \n{0}",
"open_link": "Open Link", "open_link": "Open Link",
"dev_mode": "Developer Mode", "dev_mode": "Developer Mode",
"failed_to_save_settings": "Failed to save settings" "failed_to_save_settings": "Failed to save settings",
"core_dll_file_version_mismatch": "Your BepinEx/plugins/spt/spt-core.dll file version doesn't match what was expected and is unable to start. Try reinstalling SPT"
} }