From f38226609f51b5bd48e2a80b9df3755efa102d98 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Thu, 4 Mar 2021 23:04:43 +0100 Subject: [PATCH] =?UTF-8?q?Code=20fonctionnel=20mais=20r=C3=A9sultat=20mau?= =?UTF-8?q?vais,=20je=20comprends=20pas=20pourquoi=20o=5Fo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 8 +++++++- main.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 601236c..4e75c24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,8 +50,14 @@ set(LINKER_FLAGS ) +add_subdirectory(external/frozen EXCLUDE_FROM_ALL) +target_compile_definitions(frozen INTERFACE ${COMPILE_DEFINITIONS}) +target_compile_options(frozen INTERFACE ${COMPILE_FLAGS}) +target_link_options(frozen INTERFACE ${LINKER_OPTIONS}) +target_link_libraries(frozen ${Boost_LIBRARIES}) + add_executable(GTA_SA_cheat main.cpp) target_compile_definitions(GTA_SA_cheat PRIVATE ${COMPILE_DEFINITIONS}) target_compile_options(GTA_SA_cheat PRIVATE ${COMPILE_FLAGS}) target_link_options(GTA_SA_cheat PRIVATE ${LINKER_OPTIONS}) -target_link_libraries(GTA_SA_cheat ${Boost_LIBRARIES}) \ No newline at end of file +target_link_libraries(GTA_SA_cheat ${Boost_LIBRARIES} frozen) \ No newline at end of file diff --git a/main.cpp b/main.cpp index 0914536..4e99e80 100644 --- a/main.cpp +++ b/main.cpp @@ -1,13 +1,14 @@ #include #include #include +#include /** * \brief * \param my_string * \return */ -std::uint32_t getCrc32(const std::string_view my_string) { +boost::crc_32_type::value_type getCrc32(const std::string_view my_string) { boost::crc_32_type result; result.process_bytes(my_string.data(), my_string.length()); return result.checksum(); @@ -60,6 +61,35 @@ struct NumberBase26 final { const std::array &alphabet{}; + static constexpr frozen::unordered_map 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 &_alphabet) : alphabet(_alphabet) { @@ -71,7 +101,14 @@ struct NumberBase26 final { NumberBase26 &operator++() { if (whichDigit > 0 && data[whichDigit] == 'Z') --whichDigit; + const std::uint32_t number{ lut.at(data[whichDigit]) + 1 }; // C'est là où se trouve l'incrémentation + data[whichDigit] = number == 26 ? alphabet[0] : alphabet[number]; + return *this; + } + friend std::ostream &operator<<(std::ostream &os, const NumberBase26 &number_base_26) { + std::for_each(number_base_26.data.cbegin(), number_base_26.data.cend(), [&](const auto &number) -> void { os << number; }); + return os; } private: @@ -199,9 +236,12 @@ int main() { constexpr std::size_t maxDig = maxDigits(maxCompute); std::array tmp{}; tmp.fill('\0'); - for (size_t i = 0; i < maxCompute; ++i) { - + NumberBase26 number_base_26{ alphabet }; + for (size_t i = 0; i < maxCompute; ++i, ++number_base_26) { + const auto crc = ~(getCrc32(std::string_view{ number_base_26.data.data(), maxDig })); + if (std::find(cheat_list.cbegin(), cheat_list.cend(), crc) != cheat_list.cend()) { + std::cout << number_base_26 << ":0x" << std::hex << crc << '\n'; + } } - std::cout << "Hello, World!" << std::endl; return EXIT_SUCCESS; }