You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
GTA_SA_cheat/main.cpp

234 lines
4.2 KiB

#include <iostream>
#include <array>
#include <boost/crc.hpp>
#include <omp.h>
#include <frozen/unordered_map.h>
/**
* \brief
* \param myString
* \return
*/
boost::crc_32_type::value_type getCrc32(const char *__restrict__ const myString, const std::size_t size) {
boost::crc_32_type result;
result.process_bytes(myString, size);
return result.checksum();
}
/**
* \brief
* \tparam T
* \param n
* \return
*/
template<typename T>
constexpr std::size_t maxDigits(T n) {
std::size_t num_digit = 1;
while (n != 0) {
n /= 26;
++num_digit;
}
return num_digit;
}
template<std::size_t ArraySize>
struct NumberBase26 final {
std::array<char, ArraySize> data{};
static constexpr std::uint32_t val_max{ 26 };
const std::array<char, val_max> &alphabet{};
[[maybe_unused]] static constexpr frozen::unordered_map<char, std::uint32_t, val_max> lut = {
{ 'A', 0 },
{ 'B', 1 },
{ 'C', 2 },
{ 'D', 3 },
{ 'E', 4 },
{ 'F', 5 },
{ 'G', 6 },
{ 'H', 7 },
{ 'I', 8 },
{ 'J', 9 },
{ 'K', 10 },
{ 'L', 11 },
{ 'M', 12 },
{ 'N', 13 },
{ 'O', 14 },
{ 'P', 15 },
{ 'Q', 16 },
{ 'R', 17 },
{ 'S', 18 },
{ 'T', 19 },
{ 'U', 20 },
{ 'V', 21 },
{ 'W', 22 },
{ 'X', 23 },
{ 'Y', 24 },
{ 'Z', 25 },
};
NumberBase26() = delete;
explicit NumberBase26(const std::array<char, val_max> &alphabet) : alphabet(alphabet) {
data.fill('A');
}
~NumberBase26() noexcept = default;
void operator()(std::size_t n) noexcept {
for (size_t i = data.size() - 1; 0 <= i; --i) {
if (n == 0)
return;
data[i] = alphabet[n % val_max];
n /= val_max;
}
}
friend std::ostream &operator<<(std::ostream &os, const NumberBase26 &numberBase26) {
(void) std::for_each(numberBase26.data.cbegin(), numberBase26.data.cend(), [&](const auto &number) -> void { os << number; });
return os;
}
};
int main() {
// I love deduction guides :D
constexpr std::array cheat_list{
0xDE4B237DU,
0xB22A28D1U,
0x5A783FAEU,
0xEECCEA2BU,
0x42AF1E28U,
0x555FC201U,
0x2A845345U,
0xE1EF01EAU,
0x771B83FCU,
0x5BF12848U,
0x44453A17U,
0xFCFF1D08U,
0xB69E8532U,
0x8B828076U,
0xDD6ED9E9U,
0xA290FD8CU,
0x3484B5A7U,
0x43DB914EU,
0xDBC0DD65U,
0xD08A30FEU,
0x37BF1B4EU,
0xB5D40866U,
0xE63B0D99U,
0x675B8945U,
0x4987D5EEU,
0x2E8F84E8U,
0x1A9AA3D6U,
0xE842F3BCU,
0x0D5C6A4EU,
0x74D4FCB1U,
0xB01D13B8U,
0x66516EBCU,
0x4B137E45U,
0x78520E33U,
0x3A577325U,
0xD4966D59U,
0x5FD1B49DU,
0xA7613F99U,
0x1792D871U,
0xCBC579DFU,
0x4FEDCCFFU,
0x44B34866U,
0x2EF877DBU,
0x2781E797U,
0x2BC1A045U,
0xB2AFE368U,
0xFA8DD45BU,
0x8DED75BDU,
0x1A5526BCU,
0xA48A770BU,
0xB07D3B32U,
0x80C1E54BU,
0x5DAD0087U,
0x7F80B950U,
0x6C0FA650U,
0xF46F2FA4U,
0x70164385U,
0x885D0B50U,
0x151BDCB3U,
0xADFA640AU,
0xE57F96CEU,
0x040CF761U,
0xE1B33EB9U,
0xFEDA77F7U,
0x8CA870DDU,
0x9A629401U,
0xF53EF5A5U,
0xF2AA0C1DU,
0xF36345A8U,
0x8990D5E1U,
0xB7013B1BU,
0xCAEC94EEU,
0x31F0C3CCU,
0xB3B3E72AU,
0xC25CDBFFU,
0xD5CF4EFFU,
0x680416B1U,
0xCF5FDA18U,
0xF01286E9U,
0xA841CC0AU,
0x31EA09CFU,
0xE958788AU,
0x02C83A7CU,
0xE49C3ED4U,
0x171BA8CCU,
0x86988DAEU,
0x2BDD2FA1U };
constexpr std::array alphabet{
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z' }; // taille = 26
constexpr std::size_t max_compute = 308915776;
constexpr std::size_t max_dig = maxDigits(max_compute);
NumberBase26<max_dig> number_base_26{ alphabet };
const double start = omp_get_wtime();
#pragma omp parallel for firstprivate(number_base_26) schedule(guided)
for (size_t i = 0; i < max_compute; ++i) {
number_base_26(i);
const auto crc = ~(getCrc32(number_base_26.data.data(), number_base_26.data.size()));
if (std::find(cheat_list.cbegin(), cheat_list.cend(), crc) != cheat_list.cend()) {
#pragma omp critical
{
std::cout << number_base_26 << " : 0x" << std::hex << crc << '\n';
}
}
}
const double stop = omp_get_wtime();
std::cout << "Temps : " << stop - start << 's' << std::endl;
return EXIT_SUCCESS;
}