Code fonctionnel mais résultat mauvais, je comprends pas pourquoi o_o

This commit is contained in:
Pcornat 2021-03-04 23:04:43 +01:00
parent 76badc46a0
commit f38226609f
No known key found for this signature in database
GPG Key ID: 873C3ACCF970C74E
2 changed files with 51 additions and 5 deletions

View File

@ -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) add_executable(GTA_SA_cheat main.cpp)
target_compile_definitions(GTA_SA_cheat PRIVATE ${COMPILE_DEFINITIONS}) target_compile_definitions(GTA_SA_cheat PRIVATE ${COMPILE_DEFINITIONS})
target_compile_options(GTA_SA_cheat PRIVATE ${COMPILE_FLAGS}) target_compile_options(GTA_SA_cheat PRIVATE ${COMPILE_FLAGS})
target_link_options(GTA_SA_cheat PRIVATE ${LINKER_OPTIONS}) target_link_options(GTA_SA_cheat PRIVATE ${LINKER_OPTIONS})
target_link_libraries(GTA_SA_cheat ${Boost_LIBRARIES}) target_link_libraries(GTA_SA_cheat ${Boost_LIBRARIES} frozen)

View File

@ -1,13 +1,14 @@
#include <iostream> #include <iostream>
#include <array> #include <array>
#include <boost/crc.hpp> #include <boost/crc.hpp>
#include <frozen/unordered_map.h>
/** /**
* \brief * \brief
* \param my_string * \param my_string
* \return * \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; boost::crc_32_type result;
result.process_bytes(my_string.data(), my_string.length()); result.process_bytes(my_string.data(), my_string.length());
return result.checksum(); return result.checksum();
@ -60,6 +61,35 @@ struct NumberBase26 final {
const std::array<char, 26> &alphabet{}; const std::array<char, 26> &alphabet{};
static constexpr frozen::unordered_map<char, std::uint32_t, 26> 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; NumberBase26() = delete;
explicit NumberBase26(const std::array<char, 26> &_alphabet) : alphabet(_alphabet) { explicit NumberBase26(const std::array<char, 26> &_alphabet) : alphabet(_alphabet) {
@ -71,7 +101,14 @@ struct NumberBase26 final {
NumberBase26 &operator++() { NumberBase26 &operator++() {
if (whichDigit > 0 && data[whichDigit] == 'Z') if (whichDigit > 0 && data[whichDigit] == 'Z')
--whichDigit; --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: private:
@ -199,9 +236,12 @@ int main() {
constexpr std::size_t maxDig = maxDigits(maxCompute); constexpr std::size_t maxDig = maxDigits(maxCompute);
std::array<char, maxDig> tmp{}; std::array<char, maxDig> tmp{};
tmp.fill('\0'); tmp.fill('\0');
for (size_t i = 0; i < maxCompute; ++i) { NumberBase26<maxDig> 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; return EXIT_SUCCESS;
} }