Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: Bensuperpc <bensuperpc@gmail.com>
  • Loading branch information
bensuperpc committed Dec 16, 2023
1 parent f52e938 commit bb04584
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 36 deletions.
9 changes: 6 additions & 3 deletions qml/GTA_SA.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ Page {
anchors.margins: 5
id: flickable

contentHeight: gridLayout.height
contentWidth: gridLayout.width
contentHeight: Math.max(grid.implicitHeight, parent.height)
contentWidth: Math.max(grid.Layout.minimumWidth, parent.width)
flickableDirection: Flickable.AutoFlickIfNeeded

GridLayout {
id: gridLayout
id: grid
anchors.fill: parent
anchors.margins: 5
columns: 12
Expand All @@ -48,7 +48,10 @@ Page {
GroupBox {
title: qsTr("BruteForce GTA SA")
anchors.fill: parent
implicitHeight: rightBoxLayout2.implicitHeight
implicitWidth: rightBoxLayout2.implicitWidth
ColumnLayout {
id: rightBoxLayout2
RowLayout {
TextField {
Layout.fillWidth: true
Expand Down
21 changes: 12 additions & 9 deletions qml/responsive.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ Page {
id: grid
anchors.left: parent.left
anchors.right: parent.right
columns: (window.width > 900) ? 3 : (window.width > 675) ? 2 : 1;
columns: (window.width > 1000) ? 3 : (window.width > 680) ? 2 : 1;

ColumnLayout {
id: leftBox
Layout.fillHeight: false
Layout.margins: 15
Layout.fillHeight: true
Layout.margins: 10
Layout.alignment: Qt.AlignTop
Box {
implicitHeight: rightBoxLayout.implicitHeight
implicitWidth: rightBoxLayout.implicitWidth
Layout.fillHeight: true
color: "blue"
GroupBox {
title: qsTr("BruteForce GTA SA")
Expand Down Expand Up @@ -115,13 +117,14 @@ Page {

ColumnLayout {
id: leftBox2
Layout.fillHeight: false
Layout.margins: 15
Layout.fillHeight: true
Layout.margins: 10
Layout.alignment: Qt.AlignTop
Box {
implicitHeight: rightBoxLayout2.implicitHeight
implicitWidth: rightBoxLayout2.implicitWidth
color: "green"
Layout.fillHeight: true
GroupBox {
title: qsTr("Settings")
id: rightBoxLayout2
Expand Down Expand Up @@ -213,13 +216,13 @@ Page {

ColumnLayout {
id: leftBox4
Layout.fillHeight: false
Layout.margins: 15
Layout.fillHeight: true
Layout.margins: 10
Layout.alignment: Qt.AlignTop
Box {
implicitHeight: rightBoxLayout3.implicitHeight
implicitWidth: rightBoxLayout3.implicitWidth
color: "green"
color: "darkorange"
GroupBox {
title: qsTr("Settings")
id: rightBoxLayout3
Expand All @@ -244,7 +247,7 @@ Page {
id: result
color: "red"
Layout.columnSpan: grid.columns
Layout.margins: 15
Layout.margins: 10
implicitHeight: tableResult.implicitHeight
implicitWidth: tableResult.implicitWidth
GroupBox {
Expand Down
7 changes: 6 additions & 1 deletion source/gta_cheat_finder/GTA_SA_cheat_finder_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ result::result(std::uint64_t _index, std::string _code, std::uint32_t _jamcrc, s

result::~result() {}

result& result::operator=(const result& other) {
result& result::operator=(const result& other) noexcept {
this->index = other.index;
this->code = other.code;
this->jamcrc = other.jamcrc;
this->associated_code = other.associated_code;

return *this;
}

bool result::operator==(const result& other) const noexcept {
return (this->index == other.index && this->code == other.code && this->jamcrc == other.jamcrc);
}
3 changes: 2 additions & 1 deletion source/gta_cheat_finder/GTA_SA_cheat_finder_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class result {
explicit result(std::uint64_t, std::string, std::uint32_t, std::string);
~result();

result& operator=(const result&);
result& operator=(const result&) noexcept;
bool operator==(const result& other) const noexcept;

std::uint64_t index = 0;
std::string code = "";
Expand Down
15 changes: 10 additions & 5 deletions source/gta_cheat_finder/state/GTA_SA_cheat_finder_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ void GTA_SA_CUDA::run() {
std::cout << "Max thread support: " << GTA_SA_Virtual::max_thread_support() << std::endl;
std::cout << "Running with: " << num_thread << " threads" << std::endl;

std::array<char, 29> tmp1 = {0};
std::array<char, 29> tmp2 = {0};

if (min_range > max_range) {
std::cout << "Min range value: '" << min_range << "' can't be greater than Max range value: '" << max_range << "'" << std::endl;
return;
Expand All @@ -34,6 +31,11 @@ void GTA_SA_CUDA::run() {
return;
}

IsRunning = true;

std::array<char, 29> tmp1 = {0};
std::array<char, 29> tmp2 = {0};

results.reserve((max_range - min_range) / 20000000 + 1);

std::cout << "Number of calculations: " << (max_range - min_range) << std::endl;
Expand All @@ -44,9 +46,12 @@ void GTA_SA_CUDA::run() {
begin_time = std::chrono::high_resolution_clock::now();

runner(0);
end_time = std::chrono::high_resolution_clock::now();

begin_time = std::chrono::high_resolution_clock::now();
print();
std::sort(results.begin(), results.end(), [](const result &a, const result &b) { return a.index < b.index; });

printResult();
IsRunning = false;
}

void GTA_SA_CUDA::runner(const std::uint64_t) {
Expand Down
17 changes: 11 additions & 6 deletions source/gta_cheat_finder/state/GTA_SA_cheat_finder_openmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ void GTA_SA_OPENMP::run() {
std::cout << "Max thread support: " << GTA_SA_Virtual::max_thread_support() << std::endl;
std::cout << "Running with: " << num_thread << " threads" << std::endl;

std::array<char, 29> tmp1 = {0};
std::array<char, 29> tmp2 = {0};

if (min_range > max_range) {
std::cout << "Min range value: '" << min_range << "' can't be greater than Max range value: '" << max_range << "'" << std::endl;
return;
Expand All @@ -33,10 +30,14 @@ void GTA_SA_OPENMP::run() {
std::cout << "Min range value: '" << min_range << "' Max range value: '" << max_range << "'" << std::endl;
return;
}
std::cout << "Number of calculations: " << (max_range - min_range) << std::endl;

results.reserve((max_range - min_range) / 20000000 + 1);
IsRunning = true;

std::cout << "Number of calculations: " << (max_range - min_range) << std::endl;
std::array<char, 29> tmp1 = {0};
std::array<char, 29> tmp2 = {0};

results.reserve((max_range - min_range) / 20000000 + 1);

this->find_string_inv(tmp1.data(), min_range);
this->find_string_inv(tmp2.data(), max_range);
Expand All @@ -60,7 +61,11 @@ void GTA_SA_OPENMP::run() {
#endif

end_time = std::chrono::high_resolution_clock::now();
print();

std::sort(results.begin(), results.end(), [](const result &a, const result &b) { return a.index < b.index; });

printResult();
IsRunning = false;
}

void GTA_SA_OPENMP::runner(const std::uint64_t i) {
Expand Down
16 changes: 9 additions & 7 deletions source/gta_cheat_finder/state/GTA_SA_cheat_finder_stdthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ void GTA_SA_STDTHREAD::run() {
std::cout << "Max thread support: " << GTA_SA_Virtual::max_thread_support() << std::endl;
std::cout << "Running with: " << num_thread << " threads" << std::endl;

std::array<char, 29> tmp1 = {0};
std::array<char, 29> tmp2 = {0};

if (min_range > max_range) {
std::cout << "Min range value: '" << min_range << "' can't be greater than Max range value: '" << max_range << "'" << std::endl;
return;
Expand All @@ -33,10 +30,14 @@ void GTA_SA_STDTHREAD::run() {
std::cout << "Min range value: '" << min_range << "' Max range value: '" << max_range << "'" << std::endl;
return;
}
std::cout << "Number of calculations: " << (max_range - min_range) << std::endl;

results.reserve((max_range - min_range) / 20000000 + 1);
IsRunning = true;

std::cout << "Number of calculations: " << (max_range - min_range) << std::endl;
std::array<char, 29> tmp1 = {0};
std::array<char, 29> tmp2 = {0};

results.reserve((max_range - min_range) / 20000000 + 1);

this->find_string_inv(tmp1.data(), min_range);
this->find_string_inv(tmp2.data(), max_range);
Expand All @@ -54,9 +55,10 @@ void GTA_SA_STDTHREAD::run() {
future.wait();
end_time = std::chrono::high_resolution_clock::now();

std::sort(results.begin(), results.end(), [](const auto &lhs, const auto &rhs) { return lhs.jamcrc < rhs.jamcrc; });
std::sort(results.begin(), results.end(), [](const result &a, const result &b) { return a.index < b.index; });

print();
printResult();
IsRunning = false;
}

void GTA_SA_STDTHREAD::runner(const std::uint64_t i) {
Expand Down
7 changes: 4 additions & 3 deletions source/gta_cheat_finder/state/GTA_SA_cheat_finder_virtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ uint32_t GTA_SA_Virtual::max_thread_support() {
#endif
}

void GTA_SA_Virtual::print() const {
void GTA_SA_Virtual::printResult() const {
std::cout << "" << std::endl;

// std::sort(results.begin(), results.end(), [](const result &a, const result &b) { return a.index < b.index; });

constexpr auto display_val = 18;

std::cout << std::setw(display_val + 3) << "Iter. N°" << std::setw(display_val) << "Code" << std::setw(display_val + 8) << "JAMCRC value" << std::endl;
std::cout << std::setw(display_val + 3) << "Iter. N°" << std::setw(display_val) << "Code" << std::setw(display_val + 5) << "JAMCRC value" << std::setw(display_val + 5)
<< "Associated code" << std::endl;

for (auto &result : results) {
std::cout << std::setw(display_val + 3) << result.index << std::setw(display_val) << result.code << std::setw(display_val) << "0x" << std::hex
<< result.associated_code << std::dec << std::endl;
<< result.jamcrc << std::setw(display_val) << result.associated_code << std::endl;
}
std::cout << "Time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end_time - begin_time).count() << " sec" << std::endl; // Display time

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class GTA_SA_Virtual {

virtual void clear();

virtual void print() const;
virtual void printResult() const;

/**
* @brief To get JAMCRC with boost libs
Expand Down Expand Up @@ -227,6 +227,8 @@ class GTA_SA_Virtual {

uint64_t min_range = 0; // Alphabetic sequence range min
uint64_t max_range = 0;

bool IsRunning = false;
};

#endif // GTA_SA_H
35 changes: 35 additions & 0 deletions source/gta_sa_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,49 @@ GTA_SA_UI::~GTA_SA_UI() {
}
void GTA_SA_UI::setMinRangeValue(uint64_t value) {
std::cout << __FUNCTION_NAME__ << ": " << value << std::endl;

if (selected_gta_sa->IsRunning) {
std::cout << "Error: Can't change min range while running" << std::endl;
return;
}


selected_gta_sa->min_range = value;
emit minRangeValueChanged(value);
}

void GTA_SA_UI::setMaxRangeValue(uint64_t value) {
std::cout << __FUNCTION_NAME__ << ": " << value << std::endl;

if (selected_gta_sa->IsRunning) {
std::cout << "Error: Can't change max range while running" << std::endl;
return;
}

selected_gta_sa->max_range = value;
emit maxRangeValueChanged(value);
}

void GTA_SA_UI::setNbrThreadValue(uint32_t value) {
std::cout << __FUNCTION_NAME__ << ": " << value << std::endl;

if (selected_gta_sa->IsRunning) {
std::cout << "Error: Can't change number of thread while running" << std::endl;
return;
}

selected_gta_sa->num_thread = value;
emit nbrThreadValueChanged(value);
}

void GTA_SA_UI::set_cuda_block_size(uint64_t value) {
std::cout << __FUNCTION_NAME__ << ": " << value << std::endl;

if (selected_gta_sa->IsRunning) {
std::cout << "Error: Can't change cuda block size while running" << std::endl;
return;
}

selected_gta_sa->cuda_block_size = value;
emit cuda_block_size_changed(value);
}
Expand All @@ -44,6 +69,11 @@ void GTA_SA_UI::setButtonValue(QString value) {
void GTA_SA_UI::set_calc_mode(uint64_t value) {
std::cout << __FUNCTION_NAME__ << ": " << value << std::endl;

if (selected_gta_sa->IsRunning) {
std::cout << "Error: Can't change compute type while running" << std::endl;
return;
}

std::unique_ptr<GTA_SA_Virtual> tmp = nullptr;

switch (value) {
Expand Down Expand Up @@ -83,6 +113,11 @@ void GTA_SA_UI::set_calc_mode(uint64_t value) {
return;
}

if (typeid(*selected_gta_sa).hash_code() == typeid(*tmp).hash_code()) {
std::cout << "Error: Already using this compute type:" << value << std::endl;
return;
}

tmp->min_range = selected_gta_sa->min_range;
tmp->max_range = selected_gta_sa->max_range;
tmp->num_thread = selected_gta_sa->num_thread;
Expand Down

0 comments on commit bb04584

Please sign in to comment.