Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: Bensuperpc <[email protected]>
  • Loading branch information
bensuperpc committed Dec 16, 2023
1 parent bb04584 commit d825187
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 187 deletions.
12 changes: 6 additions & 6 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"CMAKE_CXX_STANDARD": "20",
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
"CMAKE_C_EXTENSIONS": "ON",
"CMAKE_C_STANDARD": "11",
"CMAKE_C_STANDARD": "17",
"CMAKE_C_STANDARD_REQUIRED": "ON"
}
},
Expand Down Expand Up @@ -89,10 +89,10 @@
"name": "flags-cuda",
"hidden": true,
"cacheVariables": {
"CUDA_NVCC_FLAGS": "--default-stream per-thread -arch=all-major",
"CUDA_ARCHITECTURES": "50;52;53;60;61;62;70;72;75;80;86;87",
"CMAKE_CUDA_FLAGS": "--default-stream per-thread -arch=all-major",
"CMAKE_CUDA_ARCHITECTURES": "50;52;53;60;61;62;70;72;75;80;86;87",
"CUDA_PROPAGATE_HOST_FLAGS": "ON",
"CUDA_SEPARABLE_COMPILATION": "ON"
"CMAKE_CUDA_SEPARABLE_COMPILATION": "ON"
}
},
{
Expand All @@ -117,7 +117,7 @@
"name": "ci-linux",
"generator": "Unix Makefiles",
"hidden": true,
"inherits": ["flags-gcc-clang", "ci-std"],
"inherits": ["flags-gcc-clang", "ci-std", "ci-cuda", "flags-cuda"],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
Expand All @@ -135,7 +135,7 @@
"name": "ci-base",
"generator": "Unix Makefiles",
"hidden": true,
"inherits": ["ci-std", "flags-gcc-clang", "dev-mode"]
"inherits": ["ci-std", "flags-gcc-clang", "dev-mode", "flags-cuda", "ci-cuda"]
},
{
"name": "ci-win64",
Expand Down
2 changes: 1 addition & 1 deletion qml/responsive.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Page {
id: grid
anchors.left: parent.left
anchors.right: parent.right
columns: (window.width > 1000) ? 3 : (window.width > 680) ? 2 : 1;
columns: (window.width > 900) ? 3 : (window.width > 660) ? 2 : 1;

ColumnLayout {
id: leftBox
Expand Down
2 changes: 1 addition & 1 deletion source/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,6 @@ QString application::appVersion() {
#endif
}

QString application::appAuthor() { return QString("Benoît"); }
QString application::appAuthor() { return QString("Bensuperpc"); }

QString application::appBusiness() { return QString("bensuperpc (bensuperpc.org)"); }
2 changes: 1 addition & 1 deletion source/gta_cheat_finder/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ add_library(cuda_lib ${SRCS} ${HEADERS})
target_include_directories(cuda_lib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(cuda_lib PRIVATE ${CUDAToolkit_INCLUDE_DIRS})
target_link_libraries(cuda_lib PRIVATE CUDA::cudart)
target_compile_features(cuda_lib PUBLIC cuda_std_17)
#target_compile_features(cuda_lib PUBLIC cuda_std_17)
#endif()

set_target_properties(cuda_lib
Expand Down
125 changes: 59 additions & 66 deletions source/gta_cheat_finder/cuda/kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -26,87 +26,80 @@
#include "kernel.cuh"

__global__ void jamcrc_kernel_wrapper(const void *data, uint32_t *result, const uint64_t length, const uint32_t previousCrc32) {
const uint64_t blockId = blockIdx.z * gridDim.x * gridDim.y + blockIdx.y * gridDim.x + blockIdx.x;
const uint64_t threadsPerBlock = blockDim.x;
uint64_t id = blockId * threadsPerBlock + threadIdx.x;
const uint64_t blockId = blockIdx.z * gridDim.x * gridDim.y + blockIdx.y * gridDim.x + blockIdx.x;
const uint64_t threadsPerBlock = blockDim.x;
uint64_t id = blockId * threadsPerBlock + threadIdx.x;

if (id == 0) {
*result = jamcrc_kernel(data, length, previousCrc32);
}
if (id == 0) {
*result = jamcrc_kernel(data, length, previousCrc32);
}
}

__device__ uint32_t jamcrc_kernel(const void *data, uint64_t length, const uint32_t previousCrc32) {
uint32_t crc = ~previousCrc32;
uint8_t *current = (uint8_t *)data;
while (length--)
crc = (crc >> 8) ^ crc32_lookup[(crc & 0xFF) ^ *current++];
return crc;
uint32_t crc = ~previousCrc32;
uint8_t *current = (uint8_t *)data;
while (length--)
crc = (crc >> 8) ^ crc32_lookup[(crc & 0xFF) ^ *current++];
return crc;
}

__global__ void runner_kernel(uint32_t *crc_result, uint64_t *index_result, uint64_t array_size, uint64_t a, uint64_t b) {
const uint64_t blockId = blockIdx.z * gridDim.x * gridDim.y + blockIdx.y * gridDim.x + blockIdx.x;
const uint64_t threadsPerBlock = blockDim.x;
uint64_t id = blockId * threadsPerBlock + threadIdx.x;

id = id + a;
__global__ void runner_kernel(uint32_t *crc_result, uint64_t *index_result, uint64_t array_size, uint32_t* array_index, uint64_t a, uint64_t b) {
const uint64_t blockId = blockIdx.z * gridDim.x * gridDim.y + blockIdx.y * gridDim.x + blockIdx.x;
const uint64_t threadsPerBlock = blockDim.x;
uint64_t id = blockId * threadsPerBlock + threadIdx.x;

if (id >= a && id <= b) {
// printf("id: %llu a: %llu b: %llu\n", id, a, b);
// Allocate memory for the array
uint8_t array[29] = {0};
id = id + a;

uint64_t size = 0;
// Generate the array from index (id)
find_string_inv_kernel(array, id, &size);
if (id >= a && id <= b) {
// printf("id: %llu a: %llu b: %llu\n", id, a, b);
// Allocate memory for the array
uint8_t array[29] = {0};

// Calculate the JAMCRC
const uint32_t result = jamcrc_kernel(array, size, 0);
// printf("id: %llu, size: %llu, array: %s, crc: 0x%x\n", id, size, array, result);
uint64_t size = 0;
// Generate the array from index (id)
find_string_inv_kernel(array, id, &size);

bool found = false;
for (uint8_t i = 0; i < 87; i++) {
if (result == cheat_list[i]) {
found = true;
break;
}
}
// Calculate the JAMCRC
const uint32_t result = jamcrc_kernel(array, size, 0);
// printf("id: %llu, size: %llu, array: %s, crc: 0x%x\n", id, size, array, result);

if (!found) {
return;
}
bool found = false;
for (uint8_t i = 0; i < 87; i++) {
if (result == cheat_list[i]) {
found = true;
break;
}
}

// Todo: Avoid datarace
//__syncthreads();
if (!found) {
return;
}

for (uint64_t i = 0; i < array_size; i++) {
if (crc_result[i] == 0 && index_result[i] == 0) {
crc_result[i] = result;
index_result[i] = id;
// printf("Found %d at %d\n", result, id);
break;
}
//__syncthreads();
uint32_t local_array_index = atomicAdd(array_index, 1);
if (local_array_index >= array_size) {
return;
}
crc_result[local_array_index] = result;
index_result[local_array_index] = id;
}
}
}

__device__ void find_string_inv_kernel(uint8_t *array, uint64_t n, uint64_t *terminator_index) {
const uint32_t string_size_alphabet = 27;

const uint8_t alpha[string_size_alphabet] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
// If n < 27
if (n < 26) {
array[0] = alpha[n];
array[1] = '\0';
*terminator_index = 1;
return;
}
// If n > 27
uint64_t i = 0;
while (n > 0) {
array[i] = alpha[(--n) % 26];
n /= 26;
++i;
}
array[i] = '\0';
*terminator_index = i;
// If n < 27
if (n < 26) {
array[0] = alpha[n];
array[1] = '\0';
*terminator_index = 1;
return;
}
// If n > 27
uint64_t i = 0;
while (n > 0) {
array[i] = alpha[(--n) % 26];
n /= 26;
++i;
}
array[i] = '\0';
*terminator_index = i;
}
6 changes: 5 additions & 1 deletion source/gta_cheat_finder/cuda/kernel.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ __device__ uint32_t jamcrc_kernel(const void *data, uint64_t length, const uint3
__global__ void jamcrc_kernel_wrapper(const void *data, uint32_t *result, uint64_t length, const uint32_t previousCrc32);

__device__ void find_string_inv_kernel(uint8_t *array, uint64_t n, uint64_t *terminator_index);
__global__ void runner_kernel(uint32_t *crc_result, uint64_t *index_result, uint64_t array_size, uint64_t a, uint64_t b);
__global__ void runner_kernel(uint32_t *crc_result, uint64_t *index_result, uint64_t array_size, uint32_t* array_index, uint64_t a, uint64_t b);

__device__ const uint32_t crc32_lookup[256] = {
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B,
Expand Down Expand Up @@ -67,4 +67,8 @@ __device__ const uint32_t cheat_list[87] = {
0x9A629401, 0xF53EF5A5, 0xF2AA0C1D, 0xF36345A8, 0x8990D5E1, 0xB7013B1B, 0xCAEC94EE, 0x31F0C3CC, 0xB3B3E72A, 0xC25CDBFF, 0xD5CF4EFF, 0x680416B1, 0xCF5FDA18,
0xF01286E9, 0xA841CC0A, 0x31EA09CF, 0xE958788A, 0x02C83A7C, 0xE49C3ED4, 0x171BA8CC, 0x86988DAE, 0x2BDD2FA1};

__device__ const uint32_t string_size_alphabet = 27;

__device__ const uint8_t alpha[string_size_alphabet] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};

#endif
Loading

0 comments on commit d825187

Please sign in to comment.