99 lines
2.1 KiB
C++
99 lines
2.1 KiB
C++
#include <std_include.hpp>
|
|
#include "loader/component_loader.hpp"
|
|
#include "system_check.hpp"
|
|
|
|
#include "game/game.hpp"
|
|
|
|
#include <utils/io.hpp>
|
|
#include <utils/cryptography.hpp>
|
|
|
|
namespace system_check
|
|
{
|
|
namespace
|
|
{
|
|
std::string read_zone(const std::string& name)
|
|
{
|
|
std::string data{};
|
|
if (utils::io::read_file(name, &data))
|
|
{
|
|
return data;
|
|
}
|
|
|
|
if (utils::io::read_file("zone/" + name, &data))
|
|
{
|
|
return data;
|
|
}
|
|
|
|
return {};
|
|
}
|
|
|
|
std::string hash_zone(const std::string& name)
|
|
{
|
|
const auto data = read_zone(name);
|
|
return utils::cryptography::sha256::compute(data, true);
|
|
}
|
|
|
|
bool verify_hashes(const std::unordered_map<std::string, std::string>& zone_hashes)
|
|
{
|
|
for (const auto& zone_hash : zone_hashes)
|
|
{
|
|
const auto hash = hash_zone(zone_hash.first);
|
|
if (hash != zone_hash.second)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool is_system_valid()
|
|
{
|
|
static std::unordered_map<std::string, std::string> mp_zone_hashes =
|
|
{
|
|
{"patch_common_mp.ff", "1731093802719CFD4F35FE1D16373D9F97BBB4E75E72D1AE4A84996CF51C6870"},
|
|
};
|
|
|
|
static std::unordered_map<std::string, std::string> sp_zone_hashes =
|
|
{
|
|
{"patch_common_alien_mp.ff", "22F0CE99DD26376F44AE896FF8307CB38E14B65C805548E00A6251465CB6666A"},
|
|
};
|
|
|
|
return verify_hashes(mp_zone_hashes) && (game::environment::is_dedi() || verify_hashes(sp_zone_hashes));
|
|
}
|
|
|
|
void verify_binary_version()
|
|
{
|
|
const auto value = *reinterpret_cast<DWORD*>(0x140001337);
|
|
if (value != 0xDB0A33E7 && value != 0xA6D147E7)
|
|
{
|
|
throw std::runtime_error("Unsupported Call of Duty: Ghosts version");
|
|
}
|
|
}
|
|
}
|
|
|
|
bool is_valid()
|
|
{
|
|
static auto valid = is_system_valid();
|
|
return valid;
|
|
}
|
|
|
|
class component final : public component_interface
|
|
{
|
|
public:
|
|
void post_load() override
|
|
{
|
|
verify_binary_version();
|
|
|
|
if (!is_valid())
|
|
{
|
|
game::show_error("Your game files are outdated or unsupported.\n"
|
|
"Please get the latest officially supported Call of Duty: Ghosts files, or you will get random crashes and issues.",
|
|
"Invalid game files!");
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
REGISTER_COMPONENT(system_check::component)
|