iw4x-sp/src/client/loader/binary_loader.cpp
6arelyFuture eb318d32c5
All checks were successful
check-formatting / check-formatting (push) Successful in 4m8s
fix many issues with this repo
2025-04-11 10:41:28 +02:00

43 lines
1.3 KiB
C++

#include <std_include.hpp>
#include <utils/io.hpp>
#include <utils/cryptography.hpp>
#include "binary_loader.hpp"
#define SP_HASH \
"39E9C4FACEA4B19017BB8C2FC64E4149708927AC40C7C3DEACC25BDD25E93D32"
#define SP_XLABS_HASH \
"05D499D77028859D4BA30C852DA85CCA5F02678B22AEA9E27D7C56973B14A0BC"
#define SP_ALTER_HASH \
"9480909B18CF5A4EC483C989AAFCE929D2172C5F9448F8C23B723683D1A43565"
namespace binary_loader {
namespace {
std::string load_base() {
std::string path = "iw4sp.exe";
if (utils::io::file_exists("data/iw4sp.exe")) {
path = "data/iw4sp.exe";
}
std::string data;
if (!utils::io::read_file(path, &data)) {
throw std::runtime_error("Failed to read game binary (iw4sp.exe)!");
}
const auto hash = utils::cryptography::sha256::compute(data, true);
if ((hash != SP_ALTER_HASH) && (hash != SP_HASH)) {
throw std::runtime_error(
"Your iw4sp.exe is incompatible with this client. Please use the "
"AlterWare launcher to install IW4x-SP");
}
return data;
}
} // namespace
std::string load() { return load_base(); }
} // namespace binary_loader