diff --git a/.clang-format b/.clang-format index a61ba30..258d9a2 100755 --- a/.clang-format +++ b/.clang-format @@ -1,102 +1,150 @@ --- -Language: Cpp -# BasedOnStyle: Chromium -AccessModifierOffset: -4 -IndentAccessModifiers: true +Language: Cpp +# BasedOnStyle: Chromium +AccessModifierOffset: -1 AlignAfterOpenBracket: Align -AlignConsecutiveMacros: false -AlignConsecutiveAssignments: false -AlignConsecutiveBitFields: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlines: DontAlign -AlignOperands: DontAlign -AlignTrailingComments: false +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 AllowAllArgumentsOnNextLine: true -AllowAllConstructorInitializersOnNextLine: false -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortEnumsOnASingleLine: false -AllowShortBlocksOnASingleLine: Empty +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: true AllowShortFunctionsOnASingleLine: Inline -AllowShortLambdasOnASingleLine: All AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: Yes -BinPackArguments: false +AttributeMacros: + - __capability +BinPackArguments: true BinPackParameters: false +BitFieldColonSpacing: Both BraceWrapping: - AfterCaseLabel: false - AfterClass: true - AfterControlStatement: MultiLine - AfterEnum: true - AfterFunction: true - AfterNamespace: true + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: false + AfterNamespace: false AfterObjCDeclaration: false - AfterStruct: true - AfterUnion: true - AfterExternBlock: true - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: true - BeforeWhile: false - IndentBraces: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true -BreakBeforeBinaryOperators: NonAssignment -BreakBeforeBraces: Custom -# BreakBeforeInheritanceComma: true -BreakInheritanceList: BeforeComma +BreakAfterAttributes: Never +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Attach +BreakBeforeInlineASMColon: OnlyMultiline BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: true -BreakConstructorInitializers: BeforeComma -BreakAfterJavaFieldAnnotations: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon BreakStringLiterals: true -ColumnLimit: 150 -CommentPragmas: '^ IWYU pragma:' +ColumnLimit: 144 +CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true -DeriveLineEnding: false DerivePointerAlignment: false -DisableFormat: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock ExperimentalAutoDetectBinPacking: false FixNamespaceComments: true ForEachMacros: - foreach - Q_FOREACH - BOOST_FOREACH -IncludeBlocks: Regroup +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve IncludeCategories: - # Standard library headers come before anything else - - Regex: '^<[a-z_]+>' - Priority: -1 - - Regex: '^<.+\.h(pp)?>' - Priority: 1 - - Regex: '^<.*' - Priority: 2 - - Regex: '.*' - Priority: 3 -IncludeIsMainRegex: '' + - Regex: '^' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*\.h>' + Priority: 1 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 3 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '([-_](test|unittest))?$' IncludeIsMainSourceRegex: '' -IndentCaseLabels: true +IndentAccessModifiers: false IndentCaseBlocks: false +IndentCaseLabels: true +IndentExternBlock: AfterExternBlock IndentGotoLabels: true -IndentPPDirectives: AfterHash -IndentExternBlock: NoIndent -IndentWidth: 4 +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 4 IndentWrappedFunctionNames: false -InsertTrailingCommas: Wrapped -JavaScriptQuotes: Double +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF MacroBlockBegin: '' -MacroBlockEnd: '' +MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 NamespaceIndentation: None ObjCBinPackProtocolList: Never @@ -104,17 +152,22 @@ ObjCBlockIndentWidth: 2 ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: NextLine PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 1 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 PenaltyBreakString: 1000 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 PenaltyReturnTypeOnItsOwnLine: 200 PointerAlignment: Left +PPIndentWidth: -1 +QualifierAlignment: Leave RawStringFormats: - - Language: Cpp + - Language: Cpp Delimiters: - cc - CC @@ -124,8 +177,8 @@ RawStringFormats: - 'c++' - 'C++' CanonicalDelimiter: '' - BasedOnStyle: google - - Language: TextProto + BasedOnStyle: google + - Language: TextProto Delimiters: - pb - PB @@ -141,39 +194,66 @@ RawStringFormats: - ParseTextProtoOrDie - ParseTestProto - ParsePartialTestProto - CanonicalDelimiter: '' - BasedOnStyle: google -ReflowComments: true -SortIncludes: true -SortUsingDeclarations: true + CanonicalDelimiter: pb + BasedOnStyle: google +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default SpaceBeforeAssignmentOperators: true -SpaceBeforeCpp11BracedList: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatementsExceptForEachMacros +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 -SpacesInAngles: false +SpacesInAngles: Never SpacesInConditionalStatement: false -SpacesInContainerLiterals: false +SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 SpacesInParentheses: false SpacesInSquareBrackets: false -SpaceBeforeSquareBrackets: false -Standard: Auto +Standard: Auto +StatementAttributeLikeMacros: + - Q_EMIT StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION -TabWidth: 4 -UseCRLF: false -UseTab: Never +TabWidth: 8 +UseTab: Never WhitespaceSensitiveMacros: - - STRINGIZE - - PP_STRINGIZE - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE ... + diff --git a/.gitignore b/.gitignore index ae33e6c..f341865 100755 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ cmake/open-cpp-coverage.cmake cmake-build-*/ prefix/ CMakeLists.txt.user -CMakeUserPresets.json dockcross-* tools/bench.json tools/benchmark.png diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.gitmodules @@ -0,0 +1 @@ + diff --git a/CMakeLists.txt b/CMakeLists.txt index c431bb1..100e778 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,14 +29,11 @@ set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +# set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/qml) -# ---- Declare deps ---- - -find_package(Qt6 6.4 COMPONENTS Quick QuickControls2 Gui Core Qml Charts Multimedia Widgets Concurrent SerialPort REQUIRED) -#qt_standard_project_setup() +find_package(QT NAMES Qt6 REQUIRED COMPONENTS Quick QuickControls2 Gui Core Qml Charts Multimedia Widgets Concurrent SerialPort) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Quick QuickControls2 Gui Core Qml Charts Multimedia Widgets Concurrent SerialPort) +qt_standard_project_setup(REQUIRES 6.5) find_package(OpenMP 2.0) @@ -47,115 +44,87 @@ find_package(CUDAToolkit 11.0) # Download ThreadPool include(cmake/lib/threadpool.cmake) -if (CUDAToolkit_FOUND) - add_subdirectory(source/cuda) -endif() - -add_subdirectory(source/utils) +add_subdirectory(source/gta_cheat_finder) -if (Qt6_FOUND) - add_subdirectory(source/qt-utils) - endif() +# ---- Declare executable ---- -# ---- Declare library ---- +#add_executable(GTA_SA_cheat_finder_exe source/main.cpp) +#add_executable(GTA_SA_cheat_finder::exe ALIAS GTA_SA_cheat_finder_exe) -if (Qt6_FOUND) -message(STATUS "Qt6_FOUND") -add_library( - GTA_SA_cheat_finder_lib OBJECT - source/GTA_SA_cheat_finder.cpp - source/GTA_SA_cheat_finder.hpp +qt_add_executable(GTA_SA_cheat_finder_exe + source/main.cpp source/gta_sa_ui.cpp - source/gta_sa_ui.h - source/about_compilation.cpp - source/about_compilation.h -) -else() -message(STATUS "Qt6_NOT_FOUND") -add_library( - GTA_SA_cheat_finder_lib OBJECT - source/GTA_SA_cheat_finder.cpp - source/GTA_SA_cheat_finder.hpp + source/gta_sa_ui.hpp + source/imageprovider.h source/imageprovider.cpp + source/asyncimageprovider.h + source/application.h source/application.cpp + source/lineseries.h source/lineseries.cpp + source/tablemodel.h source/tablemodel.cpp + source/customlabel.h source/customlabel.cpp + source/utils/about_compilation.h + source/utils/utils.h ) -endif() +add_executable(GTA_SA_cheat_finder::exe ALIAS GTA_SA_cheat_finder_exe) -target_include_directories( - GTA_SA_cheat_finder_lib ${warning_guard} - PUBLIC - "$" -) - -target_include_directories( - GTA_SA_cheat_finder_lib ${warning_guard} - PUBLIC - "$" +qt_add_qml_module(GTA_SA_cheat_finder_exe + URI bensuperpc + RESOURCE_PREFIX /bensuperpc.fr + VERSION 1.0 + QML_FILES + qml/responsive.qml + qml/responsiveOrg.qml + qml/GTA_SA.qml + qml/main.qml + qml/home.qml qml/image.qml + qml/about.qml qml/graphic.qml + qml/table.qml + qml/settings.qml + qml/swipe.qml + qml/custom/ProportionalRect.qml + qml/custom/CustomMenuSeparator.qml + qml/custom/HorizontalLabelDelegateMenu.qml + qml/custom/VerticalLabelDelegateMenu.qml + IMPORT_PATH qml + RESOURCES + image/cat_sticking_out_its_tongue.jpg ) -target_include_directories( - GTA_SA_cheat_finder_lib ${warning_guard} - PUBLIC - "$" +set_target_properties(GTA_SA_cheat_finder_exe PROPERTIES + MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE ) -if (Qt6_FOUND) -target_include_directories( - GTA_SA_cheat_finder_lib ${warning_guard} - PUBLIC - "$" -) -endif() - -target_compile_features(GTA_SA_cheat_finder_lib PUBLIC cxx_std_20) +target_compile_features(GTA_SA_cheat_finder_exe PUBLIC cxx_std_20) if (OpenMP_FOUND OR OpenMP_CXX_FOUND) - target_link_libraries(GTA_SA_cheat_finder_lib PUBLIC OpenMP::OpenMP_CXX) + target_link_libraries(GTA_SA_cheat_finder_exe PUBLIC OpenMP::OpenMP_CXX) endif() if (CUDAToolkit_FOUND) - target_include_directories(GTA_SA_cheat_finder_lib PUBLIC ${CUDAToolkit_INCLUDE_DIRS}) - target_link_libraries(GTA_SA_cheat_finder_lib PUBLIC CUDA::cudart) - target_link_libraries(GTA_SA_cheat_finder_lib PUBLIC cuda_lib) - # target_include_directories(GTA_SA_cheat_finder_lib PUBLIC "${PROJECT_SOURCE_DIR}/source/cuda") + target_include_directories(GTA_SA_cheat_finder_exe PUBLIC ${CUDAToolkit_INCLUDE_DIRS}) endif() -if (Qt6_FOUND) - target_link_libraries(GTA_SA_cheat_finder_lib PUBLIC Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::QuickControls2 Qt${QT_VERSION_MAJOR}::Widgets - Qt${QT_VERSION_MAJOR}::Charts Qt${QT_VERSION_MAJOR}::Concurrent Qt${QT_VERSION_MAJOR}::SerialPort) - target_link_libraries(GTA_SA_cheat_finder_lib PUBLIC qt_utils_lib) -endif() +target_link_libraries(GTA_SA_cheat_finder_exe PUBLIC GTA_SA_cheat_finder_lib) -target_link_libraries(GTA_SA_cheat_finder_lib PUBLIC utils_lib) +set_property(TARGET GTA_SA_cheat_finder_exe PROPERTY OUTPUT_NAME GTA_SA_cheat_finder) -# ---- Declare executable ---- -if (Qt6_FOUND) - qt_add_executable(GTA_SA_cheat_finder_exe source/main.cpp) - add_executable(GTA_SA_cheat_finder::exe ALIAS GTA_SA_cheat_finder_exe) -else() - add_executable(GTA_SA_cheat_finder_exe source/main.cpp) - add_executable(GTA_SA_cheat_finder::exe ALIAS GTA_SA_cheat_finder_exe) -endif() +target_compile_features(GTA_SA_cheat_finder_exe PRIVATE cxx_std_20) -if (Qt6_FOUND) -# Resources: -qt_add_qml_module(GTA_SA_cheat_finder_exe - URI qml_files - RESOURCE_PREFIX /bensuperpc.com - VERSION 1.0 - QML_FILES - source/qml/main.qml - source/qml/AboutPage.qml - source/qml/GTA_SA.qml - RESOURCES - img/Profile_400x400.jpg -) -endif() +target_link_libraries(GTA_SA_cheat_finder_exe + PRIVATE Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::QuickControls2 Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Charts Qt${QT_VERSION_MAJOR}::Concurrent Qt${QT_VERSION_MAJOR}::SerialPort) -set_property(TARGET GTA_SA_cheat_finder_exe PROPERTY OUTPUT_NAME GTA_SA_cheat_finder) +target_compile_definitions(GTA_SA_cheat_finder_exe PUBLIC PROJECT_VERSION="${PROJECT_VERSION}") +target_compile_definitions(GTA_SA_cheat_finder_exe PUBLIC CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}") +target_compile_definitions(GTA_SA_cheat_finder_exe PUBLIC CMAKE_CXX_COMPILER_ID="${CMAKE_CXX_COMPILER_ID}") +target_compile_definitions(GTA_SA_cheat_finder_exe PUBLIC CMAKE_C_COMPILER_ID="${CMAKE_C_COMPILER_ID}") +target_compile_definitions(GTA_SA_cheat_finder_exe PUBLIC CMAKE_VERSION="${CMAKE_VERSION}") -target_compile_features(GTA_SA_cheat_finder_exe PRIVATE cxx_std_20) +configure_file(image/cat_sticking_out_its_tongue.jpg ${CMAKE_BINARY_DIR}/image/cat_sticking_out_its_tongue.jpg COPYONLY) -target_link_libraries(GTA_SA_cheat_finder_exe PRIVATE GTA_SA_cheat_finder_lib) # ---- Install rules ---- diff --git a/CMakePresets.json b/CMakePresets.json index e3579c0..49db98f 100755 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -51,36 +51,37 @@ "hidden": true, "cacheVariables": { "CMAKE_CXX_EXTENSIONS": "ON", - "CMAKE_CXX_STANDARD": "17", + "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" } }, { - "name": "flags-linux", + "name": "flags-gcc-clang", "hidden": true, "cacheVariables": { - "CMAKE_CXX_FLAGS": "-fstack-protector-strong -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast", - "CMAKE_C_FLAGS": "-fstack-protector-strong -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wpedantic", + "CMAKE_CXX_FLAGS": "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -pipe -fstack-protector-strong -fstack-clash-protection -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast -Wformat-security", + "CMAKE_C_FLAGS": "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -pipe -fstack-protector-strong -fstack-clash-protection -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wformat-security", "CMAKE_EXE_LINKER_FLAGS": "-Wl,--allow-shlib-undefined,--as-needed,-z,noexecstack,-z,relro,-z,now", "CMAKE_SHARED_LINKER_FLAGS": "-Wl,--allow-shlib-undefined,--as-needed,-z,noexecstack,-z,relro,-z,now" } }, { - "name": "flags-darwin", + "name": "flags-appleclang", "hidden": true, "cacheVariables": { - "CMAKE_CXX_FLAGS": "-fstack-protector-strong -fcf-protection=full -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast" + "CMAKE_CXX_FLAGS": "-pipe -fstack-protector-strong -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast", + "CMAKE_C_FLAGS": "-pipe -fstack-protector-strong -Wall -Wextra -Wpedantic" } }, { - "name": "flags-windows", + "name": "flags-msvc", "description": "Note that all the flags after /W4 are required for MSVC to conform to the language standard", "hidden": true, "cacheVariables": { - "CMAKE_CXX_FLAGS": "/sdl /analyze /analyze:external- /guard:cf /utf-8 /w14165 /w44242 /w44254 /w44263 /w34265 /w34287 /w44296 /w44365 /w44388 /w44464 /w14545 /w14546 /w14547 /w14549 /w14555 /w34619 /w34640 /w24826 /w14905 /w14906 /w14928 /w45038 /W4 /permissive- /volatile:iso /Zc:preprocessor /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew /EHsc", + "CMAKE_CXX_FLAGS": "/sdl /guard:cf /utf-8 /diagnostics:caret /w14165 /w44242 /w44254 /w44263 /w34265 /w34287 /w44296 /w44365 /w44388 /w44464 /w14545 /w14546 /w14547 /w14549 /w14555 /w34619 /w34640 /w24826 /w14905 /w14906 /w14928 /w45038 /W4 /permissive- /volatile:iso /Zc:inline /Zc:preprocessor /Zc:enumTypes /Zc:lambda /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew /EHsc", "CMAKE_EXE_LINKER_FLAGS": "/machine:x64 /guard:cf" } }, @@ -88,17 +89,18 @@ "name": "flags-cuda", "hidden": true, "cacheVariables": { - "CUDA_NVCC_FLAGS": "--default-stream per-thread -arch=all-major", + "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" } }, { - "name": "flags-gprof", + "name": "flags-debugger", "hidden": true, "cacheVariables": { - "CMAKE_CXX_FLAGS": "-Og -g3 -Wall -Wextra -Wpedantic -pg", - "CMAKE_C_FLAGS": "-Og -g3 -Wall -Wextra -Wpedantic -pg" + "CMAKE_CXX_FLAGS": "-O0 -g3 -ggdb3 -Wall -Wextra -Wpedantic -pg", + "CMAKE_C_FLAGS": "-O0 -g3 -ggdb3 -Wall -Wextra -Wpedantic -pg" } }, { @@ -115,7 +117,7 @@ "name": "ci-linux", "generator": "Unix Makefiles", "hidden": true, - "inherits": ["flags-linux", "ci-std"], + "inherits": ["flags-gcc-clang", "ci-std", "ci-cuda", "flags-cuda"], "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } @@ -124,7 +126,7 @@ "name": "ci-darwin", "generator": "Unix Makefiles", "hidden": true, - "inherits": ["flags-darwin", "ci-std"], + "inherits": ["flags-appleclang", "ci-std"], "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } @@ -133,11 +135,11 @@ "name": "ci-base", "generator": "Unix Makefiles", "hidden": true, - "inherits": ["ci-std", "flags-linux", "dev-mode"] + "inherits": ["ci-std", "flags-gcc-clang", "dev-mode", "flags-cuda", "ci-cuda"] }, { "name": "ci-win64", - "inherits": ["flags-windows", "ci-std"], + "inherits": ["flags-msvc", "ci-std"], "generator": "Visual Studio 17 2022", "architecture": "x64", "hidden": true @@ -150,7 +152,7 @@ "cacheVariables": { "ENABLE_COVERAGE": "ON", "CMAKE_BUILD_TYPE": "Coverage", - "CMAKE_CXX_FLAGS_COVERAGE": "-Og -g3 --coverage -fkeep-inline-functions -fkeep-static-functions", + "CMAKE_CXX_FLAGS_COVERAGE": "-O0 -g3 --coverage -fkeep-inline-functions -fkeep-static-functions", "CMAKE_EXE_LINKER_FLAGS_COVERAGE": "--coverage", "CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage" } @@ -168,8 +170,8 @@ "inherits": ["ci-linux", "dev-mode"], "cacheVariables": { "CMAKE_BUILD_TYPE": "Sanitize", - "CMAKE_CXX_FLAGS_SANITIZE": "-Og -g3 -fsanitize=address,undefined,leak -fno-omit-frame-pointer -fno-common", - "CMAKE_C_FLAGS_SANITIZE": "-Og -g3" + "CMAKE_CXX_FLAGS_SANITIZE": "-Og -U_FORTIFY_SOURCE -g3 -fsanitize=address,undefined,leak -fno-omit-frame-pointer -fno-common", + "CMAKE_C_FLAGS_SANITIZE": "-Og -U_FORTIFY_SOURCE -g3" }, "environment": { "ASAN_OPTIONS": "strict_string_checks=1 detect_stack_use_after_return=1 check_initialization_order=1 strict_init_order=1 detect_leaks=1", @@ -205,19 +207,37 @@ "name": "gprof", "generator": "Unix Makefiles", "binaryDir": "${sourceDir}/build/gprof", - "inherits": ["ci-std", "flags-gprof", "dev-mode", "ci-cuda"], + "inherits": ["ci-std", "flags-debugger", "dev-mode"], "hidden": false, "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } }, + { + "name": "debugger", + "generator": "Unix Makefiles", + "binaryDir": "${sourceDir}/build/debugger", + "inherits": ["ci-std", "flags-debugger", "dev-mode"], + "hidden": false, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "dev-common", + "hidden": true, + "inherits": ["dev-mode", "clang-tidy", "cppcheck"], + "cacheVariables": { + "BUILD_MCSS_DOCS": "ON" + } + }, { "name": "ci-macos", "inherits": ["ci-build", "ci-darwin", "dev-mode"] }, { "name": "ci-ubuntu", - "inherits": ["ci-build", "ci-linux", "clang-tidy", "cppcheck", "dev-mode"] + "inherits": ["ci-build", "ci-linux", "dev-common"] }, { "name": "ci-windows", diff --git a/CMakeUserPresets.json b/CMakeUserPresets.json new file mode 100644 index 0000000..d7ceeb6 --- /dev/null +++ b/CMakeUserPresets.json @@ -0,0 +1,69 @@ +{ + "version": 2, + "cmakeMinimumRequired": { + "major": 3, + "minor": 14, + "patch": 0 + }, + "configurePresets": [ + { + "name": "dev-linux", + "binaryDir": "${sourceDir}/build/dev-linux", + "inherits": ["dev-common", "ci-linux"], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "dev-darwin", + "binaryDir": "${sourceDir}/build/dev-darwin", + "inherits": ["dev-common", "ci-darwin"], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "dev-win64", + "binaryDir": "${sourceDir}/build/dev-win64", + "inherits": ["dev-common", "ci-win64"], + "environment": { + "UseMultiToolTask": "true", + "EnforceProcessCountAcrossBuilds": "true" + } + }, + { + "name": "dev", + "binaryDir": "${sourceDir}/build/dev", + "inherits": "dev-linux" + }, + { + "name": "dev-coverage", + "binaryDir": "${sourceDir}/build/coverage", + "inherits": ["dev-mode", "coverage-linux"] + } + ], + "buildPresets": [ + { + "name": "dev", + "configurePreset": "dev", + "configuration": "Debug", + "jobs": 16 + } + ], + "testPresets": [ + { + "name": "dev", + "configurePreset": "dev", + "configuration": "Debug", + "output": { + "outputOnFailure": true + }, + "execution": { + "jobs": 16, + "noTestsAction": "error" + } + } + ] +} diff --git a/Dockerfile_dev b/Dockerfile_dev new file mode 100644 index 0000000..aeb64d1 --- /dev/null +++ b/Dockerfile_dev @@ -0,0 +1,43 @@ +ARG DOCKER_IMAGE=debian:bookworm +FROM $DOCKER_IMAGE + +ENV LANG=en_US.utf8 +ENV DEBIAN_FRONTEND=noninteractive + +#SHELL ["/bin/bash", "-c", "-l"] + +RUN apt-get update && apt-get install -y \ + python3-dev python3-pip python3-setuptools \ + pybind11-dev \ + libssl-dev \ + libboost-all-dev \ + libopencv-dev \ + libfmt-dev \ + libbenchmark-dev \ + libgtest-dev \ + llvm-dev \ + nlohmann-json3-dev \ + libpoco-dev \ + libspdlog-dev \ + libjsoncpp-dev \ + uuid-dev \ + openssl libssl-dev \ + zlib1g-dev \ + libx11-dev libxrandr-dev xinput libxcb-xinput-dev \ + libxcursor-dev libxi-dev libxinerama-dev libxkbcommon-dev \ + libvulkan-dev freeglut3-dev \ + ninja-build cmake build-essential \ + valgrind git gdb ffmpeg \ + ccache distcc icecc \ + parallel cloc \ + qt6-tools-dev \ + qt6-tools-dev-tools \ + && apt-get -y autoremove --purge \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +ENV TERM xterm-256color +ENTRYPOINT ["/bin/bash", "-l"] + +#CMD [ "make" ] diff --git a/Makefile b/Makefile index 38ee7d6..7904015 100755 --- a/Makefile +++ b/Makefile @@ -7,9 +7,9 @@ #// |_| |_| // #////////////////////////////////////////////////////////////// #// // -#// new_app, 2023 // -#// Created: 19, April, 2022 // -#// Modified: 04, July, 2022 // +#// GTA_SA_cheat_finder, 2023 // +#// Created: 04, June, 2021 // +#// Modified: 18, November, 2023 // #// file: - // #// - // #// Source: // @@ -23,109 +23,90 @@ PROJECT_NAME := GTA_SA_cheat_finder PARALLEL := 1 GENERATOR := Ninja +PROJECT_ROOT := . CTEST_TIMEOUT := 1500 -CTEST_OPTIONS := --output-on-failure --verbose +CTEST_OPTIONS := --output-on-failure --timeout $(CTEST_TIMEOUT) --parallel $(PARALLEL) --verbose # LANG := en # LANG=$(LANG) - -DOCKCROSS_IMAGE := android-arm android-arm64 android-x86 android-x86_64 \ - linux-x86 linux-x64 linux-x64-clang \ - linux-arm64 linux-arm64-musl linux-arm64-full \ - linux-armv5 linux-armv5-musl linux-armv5-uclibc \ - linux-m68k-uclibc linux-s390x linux-x64-tinycc \ - linux-armv6 linux-armv6-lts linux-armv6-musl linux-arm64-lts linux-mipsel-lts \ - linux-armv7l-musl linux-armv7 linux-armv7a linux-armv7-lts linux-armv7a-lts linux-x86_64-full linux-mips linux-mips-lts linux-ppc64le \ - linux-riscv64 linux-riscv32 linux-xtensa-uclibc web-wasi \ - windows-static-x86 windows-static-x64 windows-static-x64-posix windows-armv7 windows-shared-x86 windows-shared-x64 windows-shared-x64-posix windows-arm64 \ - manylinux_2_28-x64 manylinux2014-x64 manylinux2014-x86 manylinux2014-aarch64 web-wasm +# -Werror=float-equal .PHONY: build build: base -.PHONY: $(DOCKCROSS_IMAGE) -$(DOCKCROSS_IMAGE): - docker run --rm dockcross/$@ > ./dockcross-$@ - chmod +x ./dockcross-$@ - ./dockcross-$@ cmake -B build/$@ -S . -G $(GENERATOR) - ./dockcross-$@ ninja -C build/$@ - -.PHONY: docker -docker: $(DOCKCROSS_IMAGE) - .PHONY: all all: release debug minsizerel coverage relwithdebinfo minsizerel relwithdebinfo release-clang \ debug-clang base base-clang sanitize sanitize-clang gprof $(DOCKCROSS_IMAGE) docker valgrind gdb .PHONY: base base: - cmake -B build/$@ -S . -G $(GENERATOR) --preset=$@ + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=$@ cmake --build build/$@ - ctest $(CTEST_OPTIONS) --timeout $(CTEST_TIMEOUT) --parallel $(PARALLEL) --test-dir build/$@ + ctest $(CTEST_OPTIONS) --test-dir build/$@ .PHONY: base-clang base-clang: - cmake --preset=$@ -S . -G $(GENERATOR) + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=$@ cmake --build build/$@ - ctest $(CTEST_OPTIONS) --timeout $(CTEST_TIMEOUT) --parallel $(PARALLEL) --test-dir build/$@ + ctest $(CTEST_OPTIONS) --test-dir build/$@ .PHONY: release release: - cmake -B build/$@ -S . -G $(GENERATOR) --preset=base -DCMAKE_BUILD_TYPE=Release + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=base -DCMAKE_BUILD_TYPE=Release cmake --build build/$@ - ctest $(CTEST_OPTIONS) --timeout $(CTEST_TIMEOUT) --parallel $(PARALLEL) --test-dir build/$@ + ctest $(CTEST_OPTIONS) --test-dir build/$@ .PHONY: release-clang release-clang: - cmake -B build/$@ -S . -G $(GENERATOR) --preset=base -DCMAKE_BUILD_TYPE=Release \ + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=base -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ cmake --build build/$@ - ctest $(CTEST_OPTIONS) --timeout $(CTEST_TIMEOUT) --parallel $(PARALLEL) --test-dir build/$@ + ctest $(CTEST_OPTIONS) --test-dir build/$@ .PHONY: debug debug: - cmake -B build/$@ -S . -G $(GENERATOR) --preset=dev -DCMAKE_BUILD_TYPE=Debug + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=dev -DCMAKE_BUILD_TYPE=Debug cmake --build build/$@ - ctest $(CTEST_OPTIONS) --timeout $(CTEST_TIMEOUT) --parallel $(PARALLEL) --test-dir build/$@ + ctest $(CTEST_OPTIONS) --test-dir build/$@ .PHONY: debug-clang debug-clang: - cmake -B build/$@ -S . -G $(GENERATOR) --preset=dev -DCMAKE_BUILD_TYPE=Debug \ + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=dev -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ cmake --build build/$@ - ctest $(CTEST_OPTIONS) --timeout $(CTEST_TIMEOUT) --parallel $(PARALLEL) --test-dir build/$@ + ctest $(CTEST_OPTIONS) --test-dir build/$@ .PHONY: coverage coverage: - cmake -B build/$@ -S . -G $(GENERATOR) --preset=dev-coverage -DCMAKE_BUILD_TYPE=Coverage + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=dev-coverage -DCMAKE_BUILD_TYPE=Coverage cmake --build build/$@ - ctest $(CTEST_OPTIONS) --timeout $(CTEST_TIMEOUT) --parallel $(PARALLEL) --test-dir build/$@ - cmake --build build/$@ --target coverage + ctest $(CTEST_OPTIONS) --test-dir build/$@ + cmake --build build/$@ --target $@ .PHONY: sanitize sanitize: - cmake -B build/$@ -S . -G $(GENERATOR) --preset=ci-sanitize + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=ci-sanitize cmake --build build/$@ - ctest $(CTEST_OPTIONS) --timeout $(CTEST_TIMEOUT) --parallel $(PARALLEL) --test-dir build/$@ + ctest $(CTEST_OPTIONS) --test-dir build/$@ sanitize-clang: - cmake -B build/$@ -S . -G $(GENERATOR) --preset=ci-sanitize \ + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=ci-sanitize \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ cmake --build build/$@ - ctest $(CTEST_OPTIONS) --timeout $(CTEST_TIMEOUT) --parallel $(PARALLEL) --test-dir build/$@ + ctest $(CTEST_OPTIONS) --test-dir build/$@ .PHONY: minsizerel minsizerel: - cmake -B build/$@ -S . -G $(GENERATOR) --preset=dev -DCMAKE_BUILD_TYPE=MinSizeRel + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=dev -DCMAKE_BUILD_TYPE=MinSizeRel cmake --build build/$@ - ctest $(CTEST_OPTIONS) --timeout $(CTEST_TIMEOUT) --parallel $(PARALLEL) --test-dir build/$@ + ctest $(CTEST_OPTIONS) --test-dir build/$@ .PHONY: relwithdebinfo relwithdebinfo: - cmake -B build/$@ -S . -G $(GENERATOR) --preset=dev -DCMAKE_BUILD_TYPE=RelWithDebInfo + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=dev -DCMAKE_BUILD_TYPE=RelWithDebInfo cmake --build build/$@ - ctest $(CTEST_OPTIONS) --timeout $(CTEST_TIMEOUT) --parallel $(PARALLEL) --test-dir build/$@ + ctest $(CTEST_OPTIONS) --test-dir build/$@ .PHONY: gprof gprof: @@ -133,21 +114,27 @@ gprof: cmake --build build/$@ @echo "Run executable and after gprof gmon.out | less" +.PHONY: perf +perf: + cmake --preset=base -G $(GENERATOR) + cmake --build build/base + perf record --all-user -e branch-misses ./build/base/bin/$(PROJECT_NAME) + .PHONY: graph graph: - cmake -B build/$@ -S . -G $(GENERATOR) --graphviz=build/$@/graph.dot + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --graphviz=build/$@/graph.dot cmake --build build/base dot -Tpng -o build/$@/graph.png build/$@/graph.dot .PHONY: valgrind valgrind: - cmake -B build/$@ -S . -G $(GENERATOR) --preset=dev -DCMAKE_BUILD_TYPE=Debug + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=debugger cmake --build build/$@ - valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=build/$@/valgrind.log build/$@/bin/$(PROJECT_NAME) + valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=build/$@/valgrind.log ./build/$@/bin/$(PROJECT_NAME) .PHONY: gdb gdb: - cmake -B build/$@ -S . -G $(GENERATOR) --preset=dev -DCMAKE_BUILD_TYPE=Debug + cmake -B build/$@ -S $(PROJECT_ROOT) -G $(GENERATOR) --preset=debugger cmake --build build/$@ gdb build/$@/bin/$(PROJECT_NAME) @@ -158,7 +145,7 @@ lint: .PHONY: format format: - time find . -regex '.*\.\(cpp\|cxx\|hpp\|hxx\|c\|h\|cu\|cuh\|cuhpp\|tpp\)' -not -path '*/build/*' | parallel clang-format -style=file -i {} \; + time find . -regex '.*\.\(cpp\|cxx\|hpp\|hxx\|c\|h\|cu\|cuh\|cuhpp\|tpp\)' -not -path '*/build/*' -not -path '.git/*' | parallel clang-format -style=file -i {} \; .PHONY: cloc cloc: @@ -166,8 +153,10 @@ cloc: .PHONY: update update: +# git submodule update --recursive --remote --force --rebase + git submodule update --init --recursive git pull --recurse-submodules --all --progress -.PHONY: clean -clean: +.PHONY: clear +clear: rm -rf build/* diff --git a/cmake/lib/backward-cpp.cmake b/cmake/lib/backward-cpp.cmake index fcbee5c..8bfd065 100644 --- a/cmake/lib/backward-cpp.cmake +++ b/cmake/lib/backward-cpp.cmake @@ -5,9 +5,9 @@ include(FetchContent) FetchContent_Declare( backward-cpp GIT_REPOSITORY https://github.com/bombela/backward-cpp.git - GIT_TAG 0ddfadc4b0f5c53e63259fe804ee595e6f01f4df) # 23-10-2022 + GIT_TAG 65a769ffe77cf9d759d801bc792ac56af8e911a3) # 2023-10-12 FetchContent_MakeAvailable(backward-cpp) -# TODO: target_include_directories instead of include_directories +# Add ${BACKWARD_ENABLE} to your executable and add add_backward() to your CMakeLists.txt include_directories(${backward-cpp_SOURCE_DIR}) \ No newline at end of file diff --git a/cmake/lib/benchmark.cmake b/cmake/lib/benchmark.cmake index 93dc8bf..75b03da 100755 --- a/cmake/lib/benchmark.cmake +++ b/cmake/lib/benchmark.cmake @@ -1,37 +1,70 @@ cmake_minimum_required(VERSION 3.14.0) -include(FetchContent) - -set(CMAKE_CXX_CLANG_TIDY_TMP "${CMAKE_CXX_CLANG_TIDY}") -set(CMAKE_CXX_CLANG_TIDY "") - -FetchContent_Declare( - googlebenchmark - GIT_REPOSITORY https://github.com/google/benchmark.git - GIT_TAG 9885aefb96effeb60c4e8c005e7b52c455458c10 - #GIT_SHALLOW TRUE - ) # 09-03-2023 - -# Disable tests on google benchmark -set(BENCHMARK_ENABLE_TESTING - OFF - CACHE BOOL "" FORCE) -set(BENCHMARK_ENABLE_WERROR - OFF - CACHE BOOL "" FORCE) -set(BENCHMARK_FORCE_WERROR - OFF - CACHE BOOL "" FORCE) - -set(BENCHMARK_ENABLE_INSTALL - OFF - CACHE BOOL "" FORCE) - -set(BENCHMARK_DOWNLOAD_DEPENDENCIES - ON - CACHE BOOL "" FORCE) - -FetchContent_MakeAvailable(googlebenchmark) -# Lib: benchmark::benchmark benchmark::benchmark_main - -set(CMAKE_CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY_TMP}") +find_package(benchmark QUIET) + +if (NOT benchmark_FOUND) + message(STATUS "benchmark not found on system, downloading...") + include(FetchContent) + + set(CMAKE_CXX_CLANG_TIDY_TMP "${CMAKE_CXX_CLANG_TIDY}") + set(CMAKE_CXX_CLANG_TIDY "") + + FetchContent_Declare( + googlebenchmark + GIT_REPOSITORY https://github.com/google/benchmark.git + GIT_TAG ca8d0f7b613ac915cd6b161ab01b7be449d1e1cd + #GIT_SHALLOW TRUE + ) # 12-10-2023 + + # Disable tests on google benchmark + set(BENCHMARK_ENABLE_TESTING + OFF + CACHE BOOL "" FORCE) + set(BENCHMARK_ENABLE_WERROR + OFF + CACHE BOOL "" FORCE) + set(BENCHMARK_FORCE_WERROR + OFF + CACHE BOOL "" FORCE) + + set(BENCHMARK_ENABLE_INSTALL + OFF + CACHE BOOL "" FORCE) + + set(BENCHMARK_DOWNLOAD_DEPENDENCIES + ON + CACHE BOOL "" FORCE) + + set(BENCHMARK_CXX_LINKER_FLAGS + "" + CACHE STRING "" FORCE) + + set(BENCHMARK_CXX_LIBRARIES + "" + CACHE STRING "" FORCE) + + set(BENCHMARK_CXX_FLAGS + "" + CACHE STRING "" FORCE) + + set(CMAKE_CXX_FLAGS_COVERAGE + "" + CACHE STRING "" FORCE) + + set(CMAKE_REQUIRED_FLAGS + "" + CACHE STRING "" FORCE) + + FetchContent_MakeAvailable(googlebenchmark) + # Lib: benchmark::benchmark benchmark::benchmark_main + + set(CMAKE_CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY_TMP}") + + set_target_properties(benchmark + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + ) +endif() diff --git a/cmake/lib/drogon.cmake b/cmake/lib/drogon.cmake new file mode 100644 index 0000000..b242f57 --- /dev/null +++ b/cmake/lib/drogon.cmake @@ -0,0 +1,15 @@ + + +# https://github.com/drogonframework/drogon/issues/1288#issuecomment-1163902139 +FetchContent_Declare(drogon + GIT_REPOSITORY https://github.com/drogonframework/drogon.git + GIT_TAG v1.8.4 # 08-04-2023 +) + +# Reset CXX_FLAGS to avoid warnings from drogon +set(CMAKE_CXX_FLAGS_OLD "${CMAKE_CXX_FLAGS}") +set(CMAKE_CXX_FLAGS "-std=c++17 -O3") + +FetchContent_MakeAvailable(drogon) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_OLD}") \ No newline at end of file diff --git a/cmake/lib/fast_noise2.cmake b/cmake/lib/fast_noise2.cmake new file mode 100644 index 0000000..925c474 --- /dev/null +++ b/cmake/lib/fast_noise2.cmake @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.14.0) + +include(FetchContent) + +set(FASTNOISE2_NOISETOOL OFF CACHE BOOL "Build Noise Tool" FORCE) + +FetchContent_Declare(FastNoise2 + GIT_REPOSITORY https://github.com/Auburn/FastNoise2.git + GIT_TAG 0928ca22cd4cfd50e9b17cec4fe9d867b59c3943 # 2023-06-07 +) +FetchContent_MakeAvailable(FastNoise2) diff --git a/cmake/lib/gtest.cmake b/cmake/lib/gtest.cmake index c791577..72b3bd3 100755 --- a/cmake/lib/gtest.cmake +++ b/cmake/lib/gtest.cmake @@ -1,19 +1,32 @@ cmake_minimum_required(VERSION 3.14.0) -include(FetchContent) +find_package(GTest QUIET) -FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG 50e07d1c92875e66138d5d5ee3bb46ef237115bb) # 07-03-2023 +if (NOT GTEST_FOUND) + message(STATUS "GTest not found on system, downloading...") + include(FetchContent) -# Disable tests on gtest -set(gtest_build_tests - OFF - CACHE BOOL "" FORCE) -set(gtest_build_samples - OFF - CACHE BOOL "" FORCE) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG 2dd1c131950043a8ad5ab0d2dda0e0970596586a) # 12-10-2023 -FetchContent_MakeAvailable(googletest) -# Lib: gtest gtest_main + # Disable tests on gtest + set(gtest_build_tests + OFF + CACHE BOOL "" FORCE) + set(gtest_build_samples + OFF + CACHE BOOL "" FORCE) + + FetchContent_MakeAvailable(googletest) + # Lib: gtest gtest_main + + set_target_properties(gtest + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + ) +endif() diff --git a/cmake/lib/json.cmake b/cmake/lib/json.cmake index 295f960..5d563e8 100755 --- a/cmake/lib/json.cmake +++ b/cmake/lib/json.cmake @@ -1,14 +1,31 @@ cmake_minimum_required(VERSION 3.14.0) -include(FetchContent) +find_package(nlohmann_json QUIET) -#find_package(json QUIET) +if (NOT nlohmann_json_FOUND) + message(STATUS "nlohmann_json not found on system, downloading...") + include(FetchContent) -if (NOT json_FOUND) - FetchContent_Declare(json + #set(CMAKE_MODULE_PATH + # "" + # CACHE STRING "" FORCE) + + #set(NLOHMANN_JSON_SYSTEM_INCLUDE + # "" + # CACHE STRING "" FORCE) + + FetchContent_Declare(nlohmann_json GIT_REPOSITORY https://github.com/nlohmann/json.git - GIT_TAG b2306145e1789368e6f261680e8dc007e91cc986 # 2023-02-24 + GIT_TAG f56c6e2e30241b9245161a86ae9fecf6543bf411 # 2023-11-26 ) - FetchContent_MakeAvailable(json) + FetchContent_MakeAvailable(nlohmann_json) # nlohmann_json::nlohmann_json + set_target_properties(nlohmann_json + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + ) + include_directories(${nlohmann_json_SOURCE_DIR}/include) endif() diff --git a/cmake/lib/opencv.cmake b/cmake/lib/opencv.cmake index 04d53b3..9e5005b 100644 --- a/cmake/lib/opencv.cmake +++ b/cmake/lib/opencv.cmake @@ -19,7 +19,7 @@ if (NOT OpenCV_FOUND) FetchContent_Declare( OpenCV GIT_REPOSITORY https://github.com/opencv/opencv.git - GIT_TAG 4.6.0 + GIT_TAG 4.7.0 #GIT_SHALLOW TRUE GIT_PROGRESS TRUE ) diff --git a/cmake/lib/raylib-cpp.cmake b/cmake/lib/raylib-cpp.cmake index 821acab..241a455 100755 --- a/cmake/lib/raylib-cpp.cmake +++ b/cmake/lib/raylib-cpp.cmake @@ -7,7 +7,7 @@ include(FetchContent) if (NOT raylib_cpp_FOUND) FetchContent_Declare(raylib_cpp GIT_REPOSITORY https://github.com/RobLoach/raylib-cpp.git - GIT_TAG df0cbb4204fd34fa644f1eb43914abce987a79c7 # 24-02-2023 + GIT_TAG v5.0.0 # 08-12-2023 ) FetchContent_MakeAvailable(raylib_cpp) endif() \ No newline at end of file diff --git a/cmake/lib/raylib.cmake b/cmake/lib/raylib.cmake index cca3191..0626d5b 100755 --- a/cmake/lib/raylib.cmake +++ b/cmake/lib/raylib.cmake @@ -1,28 +1,47 @@ cmake_minimum_required(VERSION 3.14.0) -include(FetchContent) +find_package(raylib QUIET) -if(NOT DEFINED BUILD_EXAMPLES) - set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) -endif() +if (NOT raylib_FOUND AND NOT FETCHCONTENT_FULLY_DISCONNECTED) + message(STATUS "raylib not found on system, downloading...") -if(NOT DEFINED BUILD_GAMES) - set(BUILD_GAMES OFF CACHE BOOL "" FORCE) -endif() + include(FetchContent) -if(NOT DEFINED INCLUDE_EVERYTHING) - set(INCLUDE_EVERYTHING ON CACHE BOOL "" FORCE) -endif() + if(NOT DEFINED BUILD_EXAMPLES) + set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + endif() -if(NOT DEFINED OPENGL_VERSION) - #set(OPENGL_VERSION OFF CACHE STRING "4.3" FORCE) -endif() + if(NOT DEFINED BUILD_GAMES) + set(BUILD_GAMES OFF CACHE BOOL "" FORCE) + endif() -#find_package(raylib QUIET) -if (NOT raylib_FOUND) + if(NOT DEFINED INCLUDE_EVERYTHING) + set(INCLUDE_EVERYTHING ON CACHE BOOL "" FORCE) + endif() + + if(NOT DEFINED OPENGL_VERSION) + #set(OPENGL_VERSION OFF CACHE STRING "4.3" FORCE) + endif() + + #set (CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/install CACHE PATH "default install path" FORCE) + #set (CMAKE_INSTALL_LIBDIR ${CMAKE_BINARY_DIR}/lib CACHE PATH "default install path" FORCE) + + #message(STATUS "CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_LIBDIR}") FetchContent_Declare(raylib GIT_REPOSITORY https://github.com/raysan5/raylib.git - GIT_TAG 4.2.0 + GIT_TAG 5.0 # 08-12-2023 ) FetchContent_MakeAvailable(raylib) -endif() + + set_target_properties(raylib + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + ) + + set(raylib_FOUND TRUE) +else() + find_package(raylib 4.2.0 REQUIRED) +endif() \ No newline at end of file diff --git a/cmake/lib/spdlog.cmake b/cmake/lib/spdlog.cmake new file mode 100644 index 0000000..3787c4c --- /dev/null +++ b/cmake/lib/spdlog.cmake @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.14.0) + +include(FetchContent) + +FetchContent_Declare( + spdlog + GIT_REPOSITORY https://github.com/gabime/spdlog.git + GIT_TAG 7e635fca68d014934b4af8a1cf874f63989352b7) # 2023-07-09 + +FetchContent_MakeAvailable(spdlog) +include_directories("${spdlog_SOURCE_DIR}") \ No newline at end of file diff --git a/cmake/lib/threadpool.cmake b/cmake/lib/threadpool.cmake index 3cf61b2..96044b9 100644 --- a/cmake/lib/threadpool.cmake +++ b/cmake/lib/threadpool.cmake @@ -4,11 +4,11 @@ include(FetchContent) FetchContent_Declare(bs-thread-pool GIT_REPOSITORY https://github.com/bshoshany/thread-pool.git - GIT_TAG 67fad04348b91cf93bdfad7495d298f54825602c # 2022-10-23 + GIT_TAG cabb3df5876c9a6824b07fcb0ff73d4a0e506ca0 # 2023-07-14 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "" ) FetchContent_MakeAvailable(bs-thread-pool) -include_directories("${bs-thread-pool_SOURCE_DIR}") +include_directories("${bs-thread-pool_SOURCE_DIR}/include") diff --git a/cmake/open-cpp-coverage.cmake.example b/cmake/open-cpp-coverage.cmake.example new file mode 100644 index 0000000..b00f086 --- /dev/null +++ b/cmake/open-cpp-coverage.cmake.example @@ -0,0 +1,31 @@ +# Example file to run OpenCppCoverage on Windows + +include(ProcessorCount) +ProcessorCount(N) + +file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/opencppcoverage") + +# Convert delimiters to Windows ones +string(REPLACE "/" "\\" binary_dir "${PROJECT_BINARY_DIR}") +string(REPLACE "/" "\\" source_dir "${PROJECT_SOURCE_DIR}") +string(REPLACE "/" "\\" ctest "${CMAKE_CTEST_COMMAND}") + +add_custom_target( + win-cov + COMMAND OpenCppCoverage -q + # We want coverage from the child processes of CTest + --cover_children + # Subdirectory where the tests reside in the binary directory + --modules "${binary_dir}\\test" + # This command is for the developer, so export as html instead of cobertura + --export_type "html:${binary_dir}\\opencppcoverage" + # Source (not header) file locations + --sources "${source_dir}\\source" + --sources "${source_dir}\\test\\source" + # Working directory for CTest, which should be the binary directory + --working_dir "${binary_dir}" + # OpenCppCoverage should be run only with the Debug configuration tests + -- "${ctest}" -C Debug --output-on-failure -j "${N}" + WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" + VERBATIM +) diff --git a/cmake/utile/ccache.cmake b/cmake/utile/ccache.cmake index 76fe85c..a337e40 100755 --- a/cmake/utile/ccache.cmake +++ b/cmake/utile/ccache.cmake @@ -1,9 +1,9 @@ find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) - message(NOTICE "ccache is enabled (found here: ${CCACHE_PROGRAM})") + message(NOTICE "-- ccache is enabled (found here: ${CCACHE_PROGRAM})") set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "\"${CCACHE_PROGRAM}\"") set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "\"${CCACHE_PROGRAM}\"") else() - message(NOTICE "ccache has not been found") + message(WARNING "-- ccache has not been found") endif() diff --git a/img/Profile_400x400.jpg b/image/cat_sticking_out_its_tongue.jpg similarity index 100% rename from img/Profile_400x400.jpg rename to image/cat_sticking_out_its_tongue.jpg diff --git a/main_en.ts b/main_en.ts new file mode 100644 index 0000000..d0620c6 --- /dev/null +++ b/main_en.ts @@ -0,0 +1,52 @@ + + + + + home + + + Home + + + + + QML/C++ binding + + + + + All + + + + + uint64_t + + + + + uint32_t + + + + + uint16_t + + + + + uint8_t + + + + + Hello World from QML! + + + + + Listview from C++ + + + + diff --git a/source/qml/GTA_SA.qml b/qml/GTA_SA.qml similarity index 91% rename from source/qml/GTA_SA.qml rename to qml/GTA_SA.qml index 3d6a7ed..5c2ab77 100644 --- a/source/qml/GTA_SA.qml +++ b/qml/GTA_SA.qml @@ -6,42 +6,37 @@ import QtQuick.Controls.Material import org.bensuperpc.GTA_SAObjectType 1.0 import org.bensuperpc.GTA_SAObjects 1.0 -import org.bensuperpc.TableModelObjects 1.0 +//import org.bensuperpc.TableModelObjects 1.0 + +import "custom/" Page { title: qsTr("BruteForce GTA SA") id: page Flickable { - // anchors.fill: parent + anchors.fill: parent anchors.centerIn: parent width: parent.width height: parent.height 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 rows: 12 - component ProportionalRect: Rectangle { - Layout.fillHeight: true - Layout.fillWidth: true - Layout.preferredWidth: Layout.columnSpan - Layout.preferredHeight: Layout.rowSpan - color: "transparent" - } - ProportionalRect { Layout.columnSpan: 12 Layout.rowSpan: 3 + implicitWidth: 100 GridLayout { anchors.fill: parent anchors.margins: 5 @@ -53,9 +48,13 @@ Page { GroupBox { title: qsTr("BruteForce GTA SA") anchors.fill: parent + implicitHeight: rightBoxLayout2.implicitHeight + implicitWidth: rightBoxLayout2.implicitWidth ColumnLayout { + id: rightBoxLayout2 RowLayout { TextField { + Layout.fillWidth: true id: minRangeValue placeholderText: qsTr("Enter minimal range value") text: GTA_SASingleton.minRangeValue.toLocaleString( @@ -76,6 +75,7 @@ Page { RowLayout { TextField { id: maxRangeValue + Layout.fillWidth: true placeholderText: qsTr("Enter maximum range value") text: GTA_SASingleton.maxRangeValue.toLocaleString( 'fullwide', { @@ -95,7 +95,8 @@ Page { RowLayout { Button { id: launchRunner - Layout.alignment: Qt.AlignHCenter + //Layout.alignment: Qt.AlignHCenter + Layout.fillWidth: true // text: qsTr("Launch Bruteforce") text: GTA_SASingleton.buttonValue onClicked: GTA_SASingleton.runOp() @@ -209,6 +210,7 @@ Page { GroupBox { title: qsTr("Result") anchors.fill: parent + /* TableView { anchors.fill: parent columnSpacing: 1 @@ -231,6 +233,7 @@ Page { } } } + */ } } } diff --git a/qml/about.qml b/qml/about.qml new file mode 100644 index 0000000..67ba910 --- /dev/null +++ b/qml/about.qml @@ -0,0 +1,94 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Material +import QtQuick.Layouts +import QtQuick.Window + +import org.bensuperpc.application 1.0 + +import "custom/" + +Page { + title: qsTr("About") + id: page + + Flickable { + anchors.fill: parent + contentWidth: width + contentHeight: flow.implicitHeight + Flow { + id: flow + width: parent.width + spacing: 0 + + ColumnLayout { + width: parent.width + clip: true + spacing: 0 + HorizontalLabelDelegateMenu { + leftText: "App version" + rightText: AppSingleton.appVersion() + } + HorizontalLabelDelegateMenu { + leftText: "Author(s)" + rightText: AppSingleton.appAuthor() + } + HorizontalLabelDelegateMenu { + leftText: "Copyright" + rightText: AppSingleton.appBusiness() + } + CustomMenuSeparator { + color: window.Material.dividerColor + } + HorizontalLabelDelegateMenu { + leftText: "Build date" + rightText: AppSingleton.buildDate() + } + HorizontalLabelDelegateMenu { + leftText: "Build type" + rightText: AppSingleton.buildType() + } + CustomMenuSeparator { + color: window.Material.dividerColor + } + HorizontalLabelDelegateMenu { + leftText: "Compiler" + rightText: AppSingleton.compilerName() + } + HorizontalLabelDelegateMenu { + leftText: "Compiler arch" + rightText: AppSingleton.compilerArch() + } + HorizontalLabelDelegateMenu { + leftText: "Compiler version" + rightText: AppSingleton.compilerVersion() + } + CustomMenuSeparator { + color: window.Material.dividerColor + } + HorizontalLabelDelegateMenu { + leftText: "C++ version" + rightText: AppSingleton.cxxVersion() + } + CustomMenuSeparator { + color: window.Material.dividerColor + } + HorizontalLabelDelegateMenu { + leftText: "C version" + rightText: AppSingleton.cVersion() + } + CustomMenuSeparator { + color: window.Material.dividerColor + } + HorizontalLabelDelegateMenu { + leftText: "Qt version" + rightText: AppSingleton.qtVersion() + } + VerticalLabelDelegateMenu { + upText: "Qt version" + downText: AppSingleton.qtVersion() + } + } + } + } +} diff --git a/qml/custom/CustomMenuSeparator.qml b/qml/custom/CustomMenuSeparator.qml new file mode 100644 index 0000000..cf75b06 --- /dev/null +++ b/qml/custom/CustomMenuSeparator.qml @@ -0,0 +1,8 @@ +import QtQuick +import QtQuick.Layouts + +Rectangle { + implicitWidth: 200 + implicitHeight: 1 + Layout.fillWidth: true +} diff --git a/qml/custom/HorizontalLabelDelegateMenu.qml b/qml/custom/HorizontalLabelDelegateMenu.qml new file mode 100644 index 0000000..8b67354 --- /dev/null +++ b/qml/custom/HorizontalLabelDelegateMenu.qml @@ -0,0 +1,26 @@ +import QtQuick +import QtQuick.Layouts +import QtQuick.Controls + +ItemDelegate { + Layout.fillWidth: true + spacing: 0 + padding: 0 + property string leftText: "" + property string rightText: "" + + contentItem: RowLayout { + spacing: 0 + Layout.fillWidth: true + Label { + text: leftText + Layout.fillWidth: true + leftPadding: 48 + } + + Label { + text: rightText + rightPadding: 24 + } + } +} diff --git a/qml/custom/ProportionalRect.qml b/qml/custom/ProportionalRect.qml new file mode 100644 index 0000000..5d5cf5d --- /dev/null +++ b/qml/custom/ProportionalRect.qml @@ -0,0 +1,10 @@ +import QtQuick +import QtQuick.Layouts + +Rectangle { + Layout.fillHeight: true + Layout.fillWidth: true + Layout.preferredWidth: Layout.columnSpan + Layout.preferredHeight: Layout.rowSpan + color: "transparent" +} diff --git a/qml/custom/VerticalLabelDelegateMenu.qml b/qml/custom/VerticalLabelDelegateMenu.qml new file mode 100644 index 0000000..48e78f6 --- /dev/null +++ b/qml/custom/VerticalLabelDelegateMenu.qml @@ -0,0 +1,42 @@ +import QtQuick +import QtQuick.Layouts +import QtQuick.Controls + +ItemDelegate { + Layout.fillWidth: true + spacing: 0 + padding: 0 + property string upText: "" + property string downText: "" + + contentItem: ColumnLayout { + spacing: 0 + Layout.fillWidth: true + // Up left text + Label { + text: upText + Layout.fillWidth: true + leftPadding: 48 + } + + // Down left text + Label { + text: downText + Layout.fillWidth: true + leftPadding: 48 + font.pixelSize: 12 + font.weight: Font.Light + } + + // Middle right text + /* + Label { + text: "Right" + Layout.alignment: Qt.AlignRight + // Layout.verticalAlignment: Qt.AlignVCenter + Layout.fillWidth: true + rightPadding: 32 + } + */ + } +} diff --git a/qml/graphic.qml b/qml/graphic.qml new file mode 100644 index 0000000..4601844 --- /dev/null +++ b/qml/graphic.qml @@ -0,0 +1,107 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Material +import QtQuick.Layouts +import QtQuick.Window +import QtCharts + +import org.bensuperpc.lineseries 1.0 +import org.bensuperpc.application 1.0 + +import "custom/" + +Page { + title: qsTr("About") + id: page + + Flickable { + id: flickable + anchors.fill: parent + + anchors.leftMargin: 5 + anchors.rightMargin: 5 + anchors.topMargin: 5 + anchors.bottomMargin: 5 + + //contentHeight: gridLayout.height + //contentWidth: gridLayout.width + flickableDirection: Flickable.AutoFlickIfNeeded + + GridLayout { + id: gridLayout + anchors.fill: parent + anchors.margins: 1 + + columnSpacing: 1 + rowSpacing: 1 + columns: 12 + rows: 12 + + ProportionalRect { + Layout.columnSpan: 12 + Layout.rowSpan: 12 + + //Layout.row: 0 + //Layout.column: 0 + //color: "red" + GroupBox { + title: qsTr("Graphic (From C++)") + anchors.fill: parent + padding: 2 + + ChartView { + id: chartView + animationOptions: ChartView.NoAnimation + anchors.fill: parent + theme: window.Material.theme === Material.Dark ? ChartView.ChartThemeDark : ChartView.ChartThemeLight + ValueAxis { + id: axisY1 + min: -1 + max: 4 + } + + ValueAxis { + id: axisY2 + min: -10 + max: 5 + } + + ValueAxis { + id: axisX + min: 0 + max: 1024 + } + + LineSeries { + id: lineSeries1 + name: "signal 1" + axisX: axisX + axisY: axisY1 + } + LineSeries { + id: lineSeries2 + name: "signal 2" + axisX: axisX + axisYRight: axisY2 + } + Timer { + id: refreshTimer + interval: 1 / 30 * 1000 // 30 Hz + running: true + repeat: true + onTriggered: { + UIData.update(chartView.series(0)) + UIData.update(chartView.series(1)) + } + } + } + } + } + } + + ScrollIndicator.vertical: ScrollIndicator {} + ScrollIndicator.horizontal: ScrollIndicator {} + ScrollBar.vertical: ScrollBar {} + ScrollBar.horizontal: ScrollBar {} + } +} diff --git a/qml/home.qml b/qml/home.qml new file mode 100644 index 0000000..0b80c67 --- /dev/null +++ b/qml/home.qml @@ -0,0 +1,264 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Material +import QtQuick.Layouts +import QtQuick.Window +import QtCharts + +import org.bensuperpc.application 1.0 +import org.bensuperpc.MyLabelLib 1.0 + +import "custom/" + +Page { + title: qsTr("Home") + id: page + + Flickable { + id: flickable + anchors.fill: parent + + anchors.leftMargin: 5 + anchors.rightMargin: 5 + anchors.topMargin: 5 + anchors.bottomMargin: 5 + + // contentHeight: gridLayout.height + // contentWidth: gridLayout.width + // contentWidth: Math.max(gridLayout.width, 540) + // contentHeight: Math.max(gridLayout.height, 960) + contentHeight: height + contentWidth: width + flickableDirection: Flickable.AutoFlickIfNeeded + + GridLayout { + id: gridLayout + anchors.fill: parent + anchors.margins: 1 + + columnSpacing: 1 + rowSpacing: 1 + columns: 12 + rows: 12 + + ProportionalRect { + Layout.columnSpan: 12 + Layout.rowSpan: 12 + //Layout.row: 0 + //Layout.column: 0 + GroupBox { + title: qsTr("QML/C++ binding") + anchors.fill: parent + padding: 6 + + ColumnLayout { + anchors.left: parent.left + anchors.right: parent.right + clip: true + RowLayout { + Layout.alignment: Qt.AlignHCenter + Layout.fillWidth: true + //Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter + ComboBox { + id: comboBox + model: AppSingleton.bencTypeList + currentIndex: AppSingleton.getBencTypeIndex() + implicitContentWidthPolicy: ComboBox.WidestTextWhenCompleted + + onActivated: { + AppSingleton.setBencTypeIndex( + this.currentIndex) + } + } + + //Binding { + // target: AppSingleton + // property: "bencTypeList" + // value: comboBox.model + // delayed: true + //} + Button { + text: "Run" + onClicked: AppSingleton.run() + } + } + + RowLayout { + Layout.alignment: Qt.AlignHCenter + Layout.fillWidth: true + TextField { + id: textField_test + text: AppSingleton.textBoxValue + inputMethodHints: Qt.ImhNoPredictiveText + } + Binding { + target: AppSingleton + property: "textBoxValue" + value: textField_test.text + delayed: true + } + TextField { + id: textField_test2 + text: AppSingleton.textBoxValue + inputMethodHints: Qt.ImhNoPredictiveText + } + Binding { + target: AppSingleton + property: "textBoxValue" + value: textField_test2.text + delayed: true + } + } + RowLayout { + Layout.alignment: Qt.AlignHCenter + Layout.fillWidth: true + ColumnLayout { + Layout.fillWidth: true + RowLayout { + Layout.fillWidth: true + ButtonGroup { + id: childGroup + exclusive: false + checkState: parentBox.checkState + } + + CheckBox { + id: parentBox + text: qsTr("All") + checkState: childGroup.checkState + onToggled: { + AppSingleton.setBenchUnsignedInteger64( + this.checked) + AppSingleton.setBenchUnsignedInteger32( + this.checked) + } + } + + CheckBox { + text: qsTr("uint64_t") + ButtonGroup.group: childGroup + checked: AppSingleton.getBenchUnsignedInteger64() + onToggled: { + AppSingleton.setBenchUnsignedInteger64( + this.checked) + } + } + + CheckBox { + text: qsTr("uint32_t") + ButtonGroup.group: childGroup + checked: AppSingleton.getBenchUnsignedInteger32() + onToggled: { + AppSingleton.setBenchUnsignedInteger32( + this.checked) + } + } + } + RowLayout { + CheckBox { + text: qsTr("uint16_t") + ButtonGroup.group: childGroup + checked: AppSingleton.getBenchUnsignedInteger16() + onToggled: { + AppSingleton.setBenchUnsignedInteger16( + this.checked) + } + } + CheckBox { + text: qsTr("uint8_t") + ButtonGroup.group: childGroup + checked: AppSingleton.getBenchUnsignedInteger8() + onToggled: { + AppSingleton.setBenchUnsignedInteger8( + this.checked) + } + } + } + } + } + + RowLayout { + Layout.alignment: Qt.AlignHCenter + Layout.fillWidth: true + MyLabel { + id: mylabel + } + Label { + id: helloWorldLabel + text: qsTr("Hello World from QML!") + Component.onCompleted: { + mylabel.setMyObject(helloWorldLabel) + } + + function myQMLFunction(message) { + return message + message + } + } + } + } + } + } + + ProportionalRect { + Layout.columnSpan: 12 + Layout.rowSpan: 4 + + GroupBox { + title: qsTr("Listview from C++") + anchors.fill: parent + padding: 2 + + ColumnLayout { + width: parent.width + clip: true + RowLayout { + Layout.alignment: Qt.AlignHCenter + ListView { + Layout.minimumWidth: 200 + Layout.preferredHeight: 100 + Layout.alignment: Qt.AlignHCenter + //boundsBehavior: Flickable.DragOverBounds + snapMode: ListView.SnapToItem + model: monModele + delegate: Component { + Switch { + text: modelData + height: 35 + hoverEnabled: false + } + } + } + Item { + Layout.minimumWidth: 200 + Layout.preferredHeight: 75 + Component { + id: monDelegue + Rectangle { + width: 250 + height: 25 + anchors.horizontalCenter: parent.horizontalCenter + color: "darkgrey" + Text { + text: "From C++ : " + modelData + } + } + } + ListView { + id: maVue + model: monModele + delegate: monDelegue + anchors.fill: parent + } + } + } + } + } + } + } + + ScrollIndicator.vertical: ScrollIndicator {} + ScrollIndicator.horizontal: ScrollIndicator {} + ScrollBar.vertical: ScrollBar {} + ScrollBar.horizontal: ScrollBar {} + } +} diff --git a/qml/image.qml b/qml/image.qml new file mode 100644 index 0000000..f46387a --- /dev/null +++ b/qml/image.qml @@ -0,0 +1,154 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Material +import QtQuick.Layouts +import QtQuick.Window +import QtCharts + +import org.bensuperpc.application 1.0 + +import "custom/" + +Page { + title: qsTr("Home") + id: page + + Flickable { + id: flickable + anchors.fill: parent + + anchors.leftMargin: 5 + anchors.rightMargin: 5 + anchors.topMargin: 5 + anchors.bottomMargin: 5 + + // contentHeight: gridLayout.height + // contentWidth: gridLayout.width + // contentWidth: Math.max(gridLayout.width, 540) + // contentHeight: Math.max(gridLayout.height, 960) + flickableDirection: Flickable.AutoFlickIfNeeded + + GridLayout { + id: gridLayout + anchors.fill: parent + anchors.margins: 1 + + columnSpacing: 1 + rowSpacing: 1 + columns: 12 + rows: 12 + + ProportionalRect { + Layout.columnSpan: 12 + Layout.rowSpan: 10 + //Layout.row: 0 + //Layout.column: 0 + GroupBox { + title: qsTr("Image (From QML and C++)") + anchors.fill: parent + padding: 2 + + Flickable { + anchors.fill: parent + contentWidth: width + contentHeight: flow.implicitHeight + clip: true + flickableDirection: Flickable.AutoFlickIfNeeded + Flow { + width: parent.width + anchors.margins: 1 + spacing: 1 + id: flow + Repeater { + model: enableCppImages.checked ? cppImageCount.value : 0 + Image { + source: "image://async/cat_sticking_out_its_tongue.jpg" + // Layout.fillHeight: true + // Layout.preferredWidth: parent.width * 0.5 + fillMode: Image.PreserveAspectFit + width: 64 + height: 64 + asynchronous: true + smooth: false + } + } + Repeater { + model: enableQMLImages.checked ? qmlImageCount.value : 0 + + Image { + source: Qt.resolvedUrl( + "/bensuperpc.fr/bensuperpc/image/cat_sticking_out_its_tongue.jpg") + width: 64 + height: 64 + fillMode: Image.PreserveAspectFit + asynchronous: true + smooth: false + } + } + } + ScrollIndicator.vertical: ScrollIndicator {} + ScrollBar.vertical: ScrollBar {} + } + } + } + ProportionalRect { + Layout.columnSpan: 12 + Layout.rowSpan: 2 + GroupBox { + title: qsTr("Settings") + anchors.fill: parent + padding: 2 + + ColumnLayout { + anchors.fill: parent + RowLayout { + Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter + Switch { + id: enableCppImages + text: qsTr("C++ Image") + checked: true + } + Slider { + id: cppImageCount + value: 16 + stepSize: 16 + from: 0 + to: 128 + snapMode: Slider.SnapAlways + } + Label { + text: qsTr("C++ image: %1").arg( + cppImageCount.value) + } + } + RowLayout { + Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter + Switch { + id: enableQMLImages + text: qsTr("QML Image") + checked: true + } + Slider { + id: qmlImageCount + value: 16 + stepSize: 16 + from: 0 + to: 128 + snapMode: Slider.SnapAlways + } + Label { + text: qsTr("C++ image: %1").arg( + qmlImageCount.value) + } + } + } + } + } + } + + ScrollIndicator.vertical: ScrollIndicator {} + ScrollIndicator.horizontal: ScrollIndicator {} + ScrollBar.vertical: ScrollBar {} + ScrollBar.horizontal: ScrollBar {} + } +} diff --git a/qml/main.qml b/qml/main.qml new file mode 100644 index 0000000..f278a8e --- /dev/null +++ b/qml/main.qml @@ -0,0 +1,292 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Material +import QtQuick.Layouts +import QtQuick.Window + +ApplicationWindow { + width: 720 + height: 1280 + + minimumWidth: 400 + minimumHeight: 480 + + visible: true + title: qsTr("main") + + id: window + + // Default theme + Material.theme: Material.Dark + Material.primary: Material.BlueGrey + Material.accent: Material.Teal + + //Material.foreground: "White" + //Material.background: "Grey" + //property bool inPortrait: window.width < window.height + + // List all pages and names + property var drawerPageFile: ["responsive.qml", "responsiveOrg.qml", "home.qml", "graphic.qml", "table.qml", "image.qml", "swipe.qml", "GTA_SA.qml", "settings.qml"] + property var drawerPageName: ["Responsive", "responsiveOrg", "Home", "Graphic", "Table", "Image", "Swipe", "GTA_SA", "Settings"] + property int currentPageIndex: 0 + + header: ToolBar { + id: toolbar + RowLayout { + anchors.fill: parent + ToolButton { + id: toolButton1 + text: qsTr("=") + font.pixelSize: 22 + font.bold: true + onClicked: { + drawer.open() + } + } + Label { + id: title_label + text: stackView.currentItem.title + font.bold: true + horizontalAlignment: Qt.AlignHCenter + verticalAlignment: Qt.AlignVCenter + Layout.fillWidth: true + clip: true + } + ToolButton { + text: qsTr("⋮") + font.bold: true + antialiasing: true + onClicked: menu.open() + } + } + } + + Menu { + id: menu + x: window.width + width: window.width * 0.37 + + // transformOrigin: Menu.TopRight + MenuItem { + text: qsTr("Quit") + onTriggered: { + Qt.quit() + } + } + MenuSeparator {} + + MenuItem { + text: qsTr("Help") + onTriggered: { + aPropos.open() + } + } + MenuItem { + text: qsTr("About") + onTriggered: { + currentPageIndex = drawerPageFile.length + 1 + stackView.push("about.qml") + } + } + } + + Dialog { + id: aPropos + focus: true + title: "About" + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + Label { + id: message + width: aPropos.availableWidth + text: qsTr("Application built with Qt quick.") + wrapMode: Label.Wrap + font.pixelSize: 12 + } + } + + Drawer { + id: drawer + width: window.width * 0.75 + height: window.height + + dragMargin: window.height * 0.03 + onOpened: { + console.log("drawer onOpened") + } + onClosed: { + console.log("drawer onClosed") + } + + ListView { + id: listView + anchors.fill: parent + + headerPositioning: ListView.OverlayHeader + header: Pane { + id: header + z: 2 + width: listView.width + padding: 6 + clip: true + + //contentHeight: logo.height + RowLayout { + anchors.left: parent.left + anchors.right: parent.right + Image { + id: logo + source: Qt.resolvedUrl( + "/bensuperpc.fr/bensuperpc/image/cat_sticking_out_its_tongue.jpg") + fillMode: Image.Stretch + Layout.preferredWidth: 64 + Layout.preferredHeight: 64 + asynchronous: true + } + ColumnLayout { + Layout.fillWidth: true + clip: true + Label { + id: labelUserName + text: qsTr("Luz") + horizontalAlignment: Qt.AlignHCenter + //verticalAlignment: Qt.AlignVCenter + Layout.fillWidth: true + font.bold: true + } + Label { + id: labelUserLastName + text: qsTr("Noceda") + horizontalAlignment: Qt.AlignHCenter + Layout.fillWidth: true + font.pixelSize: 15 + font.weight: Font.Light + } + } + ComboBox { + model: ["Luz", "Amity", "Willow", "Gus", "Hunter"] + implicitContentWidthPolicy: ComboBox.WidestText + + onActivated: { + switch (currentIndex) { + case 0: + labelUserName.text = "Luz" + labelUserLastName.text = "Noceda" + break + case 1: + labelUserName.text = "Amity" + labelUserLastName.text = "Blight" + break + case 2: + labelUserName.text = "Willow" + labelUserLastName.text = "Park" + break + case 3: + labelUserName.text = "Gus" + labelUserLastName.text = "Porter" + break + case 4: + labelUserName.text = "Hunter" + labelUserLastName.text = "Gray" + break + default: + console.warn("User not found!") + break + } + } + } + } + MenuSeparator { + parent: header + width: listView.width + anchors.verticalCenter: parent.bottom + } + } + + footer: ItemDelegate { + id: footer + text: qsTr("About") + font.bold: true + width: listView.width + + onClicked: { + currentPageIndex = drawerPageFile.length + 1 + stackView.push("about.qml") + drawer.close() + } + + MenuSeparator { + parent: footer + width: listView.width + anchors.verticalCenter: parent.top + } + } + + model: drawerPageFile.length + delegate: ItemDelegate { + text: drawerPageName[index] + width: listView.width + + highlighted: currentPageIndex === index ? true : false + font.bold: index === 0 ? true : false + + onClicked: { + if (currentPageIndex !== index) { + currentPageIndex = index + stackView.push(drawerPageFile[index]) + } + drawer.close() + } + } + + ScrollIndicator.vertical: ScrollIndicator {} + } + } + + StackView { + id: stackView + initialItem: drawerPageFile[currentPageIndex] + anchors.fill: parent + + pushEnter: Transition { + PropertyAnimation { + property: "opacity" + from: 0 + to: 1 + duration: 200 + } + } + pushExit: Transition { + PropertyAnimation { + property: "opacity" + from: 1 + to: 0 + duration: 200 + } + } + popEnter: Transition { + PropertyAnimation { + property: "opacity" + from: 0 + to: 1 + duration: 200 + } + } + popExit: Transition { + PropertyAnimation { + property: "opacity" + from: 1 + to: 0 + duration: 200 + } + } + } + + Component.onCompleted: { + + } + + Component.onDestruction: { + + } +} diff --git a/qml/responsive.qml b/qml/responsive.qml new file mode 100644 index 0000000..9f41043 --- /dev/null +++ b/qml/responsive.qml @@ -0,0 +1,348 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Material +import QtQuick.Layouts +import QtQuick.Window + +import org.bensuperpc.GTA_SAObjectType 1.0 +import org.bensuperpc.GTA_SAObjects 1.0 +//import org.bensuperpc.TableModelObjects 1.0 + +import org.bensuperpc.TableData 1.0 + +Page { + title: qsTr("About") + id: page + component Box : Rectangle { + property string text + property int fontSize: 30 + property int alignment: Text.AlignHCenter + color: "#33b5e5" + implicitHeight: txt.implicitHeight + 10 + implicitWidth: txt.implicitWidth + 10 + Layout.fillWidth: true + Layout.minimumWidth: implicitWidth + Text { + id: txt + text: parent.text + color: "white" + anchors.fill: parent + anchors.margins: 5 + font.pixelSize: parent.fontSize + horizontalAlignment: parent.alignment + } + } + + Flickable { + anchors.fill: parent + contentHeight: Math.max(grid.implicitHeight, parent.height) + contentWidth: Math.max(grid.Layout.minimumWidth, parent.width) + + GridLayout { + id: grid + anchors.left: parent.left + anchors.right: parent.right + columns: (window.width > 900) ? 3 : (window.width > 660) ? 2 : 1; + + ColumnLayout { + id: leftBox + 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") + id: rightBoxLayout + anchors.fill: parent + ColumnLayout { + anchors.fill: parent + RowLayout { + TextField { + id: minRangeValue + Layout.fillWidth: true + placeholderText: qsTr("Enter minimal range value") + text: GTA_SASingleton.minRangeValue.toLocaleString( + 'fullwide', { + "useGrouping": false + }) + selectByMouse: true + validator: RegularExpressionValidator { + regularExpression: /[0-9]+/ + } + } + Binding { + target: GTA_SASingleton + property: "minRangeValue" + value: minRangeValue.text + } + } + RowLayout { + TextField { + id: maxRangeValue + Layout.fillWidth: true + placeholderText: qsTr("Enter maximum range value") + text: GTA_SASingleton.maxRangeValue.toLocaleString( + 'fullwide', { + "useGrouping": false + }) + selectByMouse: true + validator: RegularExpressionValidator { + regularExpression: /[0-9]+/ + } + } + Binding { + target: GTA_SASingleton + property: "maxRangeValue" + value: maxRangeValue.text + } + } + RowLayout { + Button { + id: launchRunner + //Layout.alignment: Qt.AlignHCenter + Layout.fillWidth: true + // text: qsTr("Launch Bruteforce") + text: GTA_SASingleton.buttonValue + onClicked: GTA_SASingleton.runOp() + } + } + } + } + } + } + + ColumnLayout { + id: leftBox2 + 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 + anchors.fill: parent + ColumnLayout { + anchors.fill: parent + RowLayout { + RadioButton { + id: enableSTDTHREAD + enabled: true + checked: (GTA_SASingleton.calc_mode == 0 ? true : false) + text: qsTr("std::thread") + onToggled: { + GTA_SASingleton.set_calc_mode(0) + } + } + RadioButton { + id: enableOpenMP + checked: (GTA_SASingleton.calc_mode == 1 ? true : false) + enabled: GTA_SASingleton.builtWithOpenMP + text: qsTr("OpenMP") + onToggled: { + GTA_SASingleton.set_calc_mode(1) + } + } + RadioButton { + id: enableCUDA + enabled: GTA_SASingleton.builtWithCUDA + checked: (GTA_SASingleton.calc_mode == 2 ? true : false) + text: qsTr("CUDA") + onToggled: { + GTA_SASingleton.set_calc_mode(2) + } + } + } + RowLayout { + // enabled: (GTA_SASingleton.builtWithOpenMP ? enableOpenMP.checkState: false) + Label { + text: qsTr("CPU core: ") + } + Slider { + id: nbr_thread_value + value: GTA_SASingleton.nbrThreadValue + stepSize: 1 + from: 1 + to: GTA_SASingleton.max_thread_support() + snapMode: Slider.SnapAlways + } + + Binding { + target: GTA_SASingleton + property: "nbrThreadValue" + value: nbr_thread_value.value + } + Label { + text: (GTA_SASingleton.nbrThreadValue + >= 10) ? GTA_SASingleton.nbrThreadValue : " " + + GTA_SASingleton.nbrThreadValue + } + } + RowLayout { + Label { + text: qsTr("Block size: ") + } + Slider { + id: cuda_block_size_slider + enabled: GTA_SASingleton.builtWithCUDA + // value: 1024 + stepSize: 64 + from: 64 + to: 1024 + snapMode: Slider.SnapAlways + } + Binding { + target: GTA_SASingleton + property: "cuda_block_size" + value: cuda_block_size_slider.value + } + Label { + text: (GTA_SASingleton.cuda_block_size + >= 100) ? GTA_SASingleton.cuda_block_size : " " + + GTA_SASingleton.cuda_block_size + } + } + } + } + } + } + + ColumnLayout { + id: leftBox4 + Layout.fillHeight: true + Layout.margins: 10 + Layout.alignment: Qt.AlignTop + Box { + implicitHeight: rightBoxLayout3.implicitHeight + implicitWidth: rightBoxLayout3.implicitWidth + color: "darkorange" + GroupBox { + title: qsTr("Settings") + id: rightBoxLayout3 + anchors.fill: parent + ColumnLayout { + anchors.fill: parent + RowLayout { + ComboBox { + model: ["JSON", "CSV", "TXT"] + } + Button { + text: qsTr("Export data") + enabled: false + } + } + } + } + } + } + + Box { + id: result + color: "red" + Layout.columnSpan: grid.columns + Layout.margins: 10 + implicitHeight: tableResult.implicitHeight + implicitWidth: tableResult.implicitWidth + GroupBox { + title: qsTr("Result") + id: tableResult + anchors.fill: parent + ColumnLayout { + anchors.fill: parent + RowLayout { + TableView { + clip: true + id: tableViewData + + selectionModel: ItemSelectionModel {} + + ScrollIndicator.horizontal: ScrollIndicator {} + ScrollIndicator.vertical: ScrollIndicator {} + + model: TableDataModel + delegate: Component { + Rectangle { + implicitWidth: { + var caseWidth = (tableViewData.width - 2) + / TableDataModel.columnCount() + if (caseWidth > 80 && caseWidth < 200) { + return caseWidth + } else { + return 80 + } + } + + implicitHeight: 20 + border.color: window.Material.theme + === Material.Dark ? "black" : "black" + border.width: 2 + color: heading ? "antiquewhite" : "aliceblue" + Text { + text: tabledata + font.pointSize: 10 + font.bold: heading ? true : false + anchors.centerIn: parent + } + + MouseArea { + anchors.fill: parent + onClicked: { + console.log("Clicked on " + tabledata) + } + } + } + } + } + } + } + } + } + + /* + Box { + id: result2 + color: "transparent" + Layout.columnSpan: grid.columns + GridLayout { + anchors.fill: parent + anchors.margins: 5 + GroupBox { + title: qsTr("Export to JSON") + Layout.fillWidth: true + Button { + text: qsTr("Export data") + enabled: false + } + } + + GroupBox { + title: qsTr("Export to CSV") + Layout.fillWidth: true + Button { + text: qsTr("Export data") + enabled: false + } + } + + GroupBox { + title: qsTr("Export to TXT") + Layout.fillWidth: true + Button { + text: qsTr("Export data") + enabled: false + } + } + } + } + */ + } + } + +} diff --git a/qml/responsiveOrg.qml b/qml/responsiveOrg.qml new file mode 100644 index 0000000..449ff07 --- /dev/null +++ b/qml/responsiveOrg.qml @@ -0,0 +1,106 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Material +import QtQuick.Layouts +import QtQuick.Window + + +import org.bensuperpc.TableData 1.0 + +import "custom/" + +Page { + title: qsTr("About") + id: page + component Box : Rectangle { + property string text + property int fontSize: 30 + property int alignment: Text.AlignHCenter + color: "#33b5e5" + implicitHeight: txt.implicitHeight + 10 + implicitWidth: txt.implicitWidth + 10 + Layout.fillWidth: true + Layout.minimumWidth: implicitWidth + Text { + id: txt + text: parent.text + color: "white" + anchors.fill: parent + anchors.margins: 5 + font.pixelSize: parent.fontSize + horizontalAlignment: parent.alignment + } + } + + Flickable { + anchors.fill: parent + contentHeight: Math.max(grid.implicitHeight, parent.height) + contentWidth: Math.max(grid.Layout.minimumWidth, parent.width) + + GridLayout { + id: grid + anchors.left: parent.left + anchors.right: parent.right + columns: (window.width > 768) ? 3 : (window.width > 600) ? 2 : 1; + + Box { + id: header + text: "Chania" + fontSize: 50 + color: "#9933cc" + Layout.columnSpan: grid.columns + } + ColumnLayout { + id: leftBox + Layout.fillHeight: false + Layout.margins: 15 + Layout.alignment: Qt.AlignTop + Box { text: "The Flight"; alignment: Text.AlignLeft } + Box { text: "The City"; alignment: Text.AlignLeft } + Box { text: "The Island"; alignment: Text.AlignLeft } + Box { text: "The Food"; alignment: Text.AlignLeft } + } + ColumnLayout { + id: contentBox + Layout.fillHeight: false + Layout.margins: 15 + Layout.preferredWidth: 800 + Text { id: text3; text: "The city"; font.pixelSize: 30} + TextArea { + Layout.fillWidth: true + Layout.fillHeight: true + implicitWidth: 100 + id: text4 + text: "Chania is the capital of the Chania region on the island of Crete. The city can be divided in two parts, the old town and the modern city." + font.pixelSize: 14 + wrapMode: Text.WordWrap + } + } + + Box { + id: rightBox + implicitHeight: rightBoxLayout.implicitHeight + implicitWidth: rightBoxLayout.implicitWidth + Layout.margins: 15 + ColumnLayout { + id: rightBoxLayout + Box { width: rightBox.width; text: "What?"; } + Box { width: rightBox.width; text: "Chania is a city on the island of Crete."; fontSize: 14} + Box { width: rightBox.width; text: "Where?" } + Box { width: rightBox.width; text: "Crete is a Greek island in the Mediterranean Sea."; fontSize: 14} + Box { width: rightBox.width; text: "How?" } + Box { width: rightBox.width; text: "You can reach Chania airport from all over Europe."; fontSize: 14} + } + } + + Box { + id: footer + text: "Resize the browser window to see how the content respond to the resizing." + fontSize: 12 + color: "#0099cc" + Layout.columnSpan: grid.columns + } + } + } + +} diff --git a/qml/settings.qml b/qml/settings.qml new file mode 100644 index 0000000..f3043da --- /dev/null +++ b/qml/settings.qml @@ -0,0 +1,123 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Material +import QtQuick.Layouts +import QtQuick.Window + +import org.bensuperpc.application 1.0 + +import "custom/" + +Page { + title: qsTr("Settings") + id: page + + Flickable { + anchors.fill: parent + contentWidth: width + contentHeight: flow.implicitHeight + Flow { + id: flow + width: parent.width + spacing: 0 + + ColumnLayout { + width: parent.width + clip: true + spacing: 0 + + RowLayout { + Layout.fillWidth: true + SwitchDelegate { + Layout.fillWidth: true + leftPadding: 48 + rightPadding: 32 + text: "Dark Theme" + checked: window.Material.theme === Material.Dark ? true : false + + onClicked: { + window.Material.theme = this.checked ? Material.Dark : Material.Light + } + } + } + RowLayout { + Layout.fillWidth: true + SwitchDelegate { + Layout.fillWidth: true + leftPadding: 48 + rightPadding: 32 + text: "Color primary" + checked: window.Material.primary === Material.color( + Material.BlueGrey) ? true : false + + onClicked: { + window.Material.primary + = this.checked ? Material.BlueGrey : Material.Indigo + } + } + } + RowLayout { + Layout.fillWidth: true + SwitchDelegate { + Layout.fillWidth: true + leftPadding: 48 + rightPadding: 32 + text: "Color accent" + checked: true + onClicked: { + window.Material.accent = this.checked ? Material.Teal : Material.Orange + } + } + } + + CustomMenuSeparator { + color: window.Material.dividerColor + } + RowLayout { + Layout.fillWidth: true + SwitchDelegate { + Layout.fillWidth: true + leftPadding: 48 + rightPadding: 32 + text: "Debug mode" + checked: false + enabled: false + } + } + + RowLayout { + Layout.fillWidth: true + spacing: 0 + enabled: false + ButtonGroup { + id: buttonGroupLanguage + } + ItemDelegate { + Layout.fillWidth: true + leftPadding: 48 + text: "Language" + } + + RadioDelegate { + checked: true + text: "en" + ButtonGroup.group: buttonGroupLanguage + } + RadioDelegate { + checked: true + text: "es" + ButtonGroup.group: buttonGroupLanguage + } + RadioDelegate { + rightPadding: 24 + text: "fr" + ButtonGroup.group: buttonGroupLanguage + } + } + CustomMenuSeparator { + color: window.Material.dividerColor + } + } + } + } +} diff --git a/qml/swipe.qml b/qml/swipe.qml new file mode 100644 index 0000000..2ba4ebb --- /dev/null +++ b/qml/swipe.qml @@ -0,0 +1,126 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Material +import QtQuick.Layouts +import QtQuick.Window + +import org.bensuperpc.application 1.0 + +import "custom/" + +Page { + title: qsTr("Swipe") + id: page + + SwipeView { + id: view + + currentIndex: 0 + anchors.fill: parent + Repeater { + model: 3 + Pane { + id: pagePane + GroupBox { + title: qsTr("Page N°%1").arg(view.currentIndex + 1) + anchors.fill: parent + anchors.bottomMargin: 6 + padding: 2 + + Flickable { + anchors.fill: parent + contentWidth: width + contentHeight: flickablePage.implicitHeight + clip: true + Flow { + id: flickablePage + width: parent.width + spacing: 0 + + ColumnLayout { + width: parent.width + spacing: 0 + ItemDelegate { + Layout.fillWidth: true + spacing: 0 + padding: 0 + + contentItem: RowLayout { + spacing: 0 + Layout.fillWidth: true + Label { + text: qsTr("Test %1a").arg( + view.currentIndex + 1) + Layout.fillWidth: true + leftPadding: 32 + } + + Label { + text: "OK" + rightPadding: 16 + color: "Green" + } + } + } + ItemDelegate { + Layout.fillWidth: true + spacing: 0 + padding: 0 + + contentItem: RowLayout { + spacing: 0 + Layout.fillWidth: true + Label { + text: qsTr("Test %1b").arg( + view.currentIndex + 1) + Layout.fillWidth: true + leftPadding: 32 + } + + Label { + text: "WARNING" + rightPadding: 16 + color: "Orange" + } + } + } + ItemDelegate { + Layout.fillWidth: true + spacing: 0 + padding: 0 + + contentItem: RowLayout { + spacing: 0 + Layout.fillWidth: true + Label { + text: qsTr("Test %1c").arg( + view.currentIndex + 1) + Layout.fillWidth: true + leftPadding: 32 + } + + Label { + text: "ERROR" + rightPadding: 16 + color: "Red" + } + } + } + } + } + } + } + } + } + } + + PageIndicator { + id: indicator + + count: view.count + currentIndex: view.currentIndex + + anchors.bottom: view.bottom + anchors.horizontalCenter: parent.horizontalCenter + } +} diff --git a/qml/table.qml b/qml/table.qml new file mode 100644 index 0000000..c2e7c9f --- /dev/null +++ b/qml/table.qml @@ -0,0 +1,104 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Material +import QtQuick.Layouts +import QtQuick.Window + +import org.bensuperpc.TableData 1.0 + +import "custom/" + +Page { + title: qsTr("About") + id: page + + Flickable { + id: flickable + anchors.fill: parent + width: parent.width + height: parent.height + + anchors.leftMargin: 5 + anchors.rightMargin: 4 + anchors.topMargin: 5 + anchors.bottomMargin: 5 + + //contentHeight: gridLayout.height + //contentWidth: gridLayout.width + flickableDirection: Flickable.AutoFlickIfNeeded + + GridLayout { + id: gridLayout + anchors.fill: parent + anchors.margins: 1 + + columnSpacing: 1 + rowSpacing: 1 + columns: 12 + rows: 12 + + ProportionalRect { + Layout.columnSpan: 12 + Layout.rowSpan: 12 + + GroupBox { + title: qsTr("Table (From C++)") + anchors.fill: parent + padding: 2 + + TableView { + anchors.fill: parent + columnSpacing: 1 + rowSpacing: 1 + clip: true + id: tableViewData + + selectionModel: ItemSelectionModel {} + + ScrollIndicator.horizontal: ScrollIndicator {} + ScrollIndicator.vertical: ScrollIndicator {} + + model: TableDataModel + delegate: Component { + Rectangle { + implicitWidth: { + var caseWidth = (tableViewData.width - 2) + / TableDataModel.columnCount() + if (caseWidth > 80 && caseWidth < 200) { + return caseWidth + } else { + return 80 + } + } + + implicitHeight: 20 + border.color: window.Material.theme + === Material.Dark ? "black" : "black" + border.width: 2 + color: heading ? "antiquewhite" : "aliceblue" + Text { + text: tabledata + font.pointSize: 10 + font.bold: heading ? true : false + anchors.centerIn: parent + } + + MouseArea { + anchors.fill: parent + onClicked: { + console.log("Clicked on " + tabledata) + } + } + } + } + } + } + } + } + + ScrollIndicator.vertical: ScrollIndicator {} + ScrollIndicator.horizontal: ScrollIndicator {} + ScrollBar.vertical: ScrollBar {} + ScrollBar.horizontal: ScrollBar {} + } +} diff --git a/source/GTA_SA_cheat_finder.cpp b/source/GTA_SA_cheat_finder.cpp deleted file mode 100755 index a236df8..0000000 --- a/source/GTA_SA_cheat_finder.cpp +++ /dev/null @@ -1,254 +0,0 @@ -#include "GTA_SA_cheat_finder.hpp" - -GTA_SA::GTA_SA() {} - -GTA_SA::~GTA_SA() {} - -GTA_SA& GTA_SA::operator=(const GTA_SA& other) -{ - if (this != &other) { - this->min_range = other.min_range; - this->max_range = other.max_range; - this->num_thread = other.num_thread; - this->cuda_block_size = other.cuda_block_size; - this->calc_mode = other.calc_mode; - } - return *this; -} - -void GTA_SA::clear() -{ - results.clear(); - results.shrink_to_fit(); -} - -void GTA_SA::run() -{ -#if !defined(_OPENMP) - if (calc_mode == 1) { - std::cout << "OpenMP is not enabled, please compile with -fopenmp flag" - "or select another calculation mode (CUDA or std::thread), " - "fall back to std::thread." - "Doesn't impact performance most of the time." - << std::endl; - calc_mode = 0; - } -#endif - -#if !defined(BUILD_WITH_CUDA) - if (calc_mode == 2) { - std::cout << "CUDA is not enabled, please compile with CUDA" - "or select another calculation mode (OpenMP or std::thread), " - "fall back to std::thread." - "Less performant than CUDA." - << std::endl; - calc_mode = 0; - } -#endif - if (calc_mode == 3) { - std::cout << "OpenCL is not ready, please select another calculation mode " - "(OpenMP, std::thread), fall back to std::thread." - << std::endl; - calc_mode = 0; - } - - if (calc_mode > 3) { - std::cout << "Invalid calculation mode, fall back to std::thread." << std::endl; - calc_mode = 0; - } - - switch (calc_mode) { - case 0: - std::cout << "Running with std::thread mode" << std::endl; - break; - case 1: - std::cout << "Running with OpenMP mode" << std::endl; - break; - case 2: - std::cout << "Running with CUDA mode" << std::endl; - break; - case 3: - std::cout << "Running with OpenCL mode" << std::endl; - break; - default: - std::cout << "Unknown calculation mode" << std::endl; - break; - } - - std::cout << "Max thread support: " << max_thread_support() << std::endl; - std::cout << "Running with: " << num_thread << " threads" << std::endl; - - std::array tmp1 = {0}; - std::array 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; - } - - if ((max_range - min_range) < 1) { - std::cout << "Search range is too small." << std::endl; - return; - } - - results.reserve((max_range - min_range) / 20000000 + 1); - - std::cout << "Number of calculations: " << (max_range - min_range) << std::endl; - - GTA_SA::find_string_inv(tmp1.data(), min_range); - GTA_SA::find_string_inv(tmp2.data(), max_range); - std::cout << "From: " << tmp1.data() << " to: " << tmp2.data() << " Alphabetic sequence" << std::endl; - begin_time = std::chrono::high_resolution_clock::now(); - if (calc_mode == 0) { - BS::thread_pool pool(num_thread); - pool.parallelize_loop(min_range, - max_range, - [&](const std::uint64_t& _min_range, const std::uint64_t& _max_range) - { - for (std::uint64_t i = _min_range; i <= _max_range; i++) { - cpu_runner(i); - } - }); - } else if (calc_mode == 1) { -#if defined(_OPENMP) - omp_set_num_threads(static_cast(num_thread)); -#endif - -#if defined(_OPENMP) -# ifdef _MSC_VER - static std::int64_t i = 0; // OpenMP (2.0) on Windows doesn't support unsigned variable -# pragma omp parallel for shared(results) schedule(dynamic) - for (i = static_cast(min_range); i <= static_cast(max_range); i++) { - cpu_runner(static_cast(i)); - } -# else - std::uint64_t i = 0; -# pragma omp parallel for schedule(auto) shared(results) - for (i = min_range; i <= max_range; i++) { - cpu_runner(i); - } -# endif -#else - std::cout << "OpenMP is not supported" << std::endl; -#endif - } else if (calc_mode == 2) { -#if defined(BUILD_WITH_CUDA) - cuda_runner(); -#else - std::cout << "CUDA is not supported." << std::endl; -#endif - } else if (calc_mode == 3) { - std::cout << "OpenCL is not supported." << std::endl; - } else { - std::cout << "Unknown calculation mode." << std::endl; - } - - end_time = std::chrono::high_resolution_clock::now(); - std::cout << "" << std::endl; - - std::sort(results.begin(), results.end()); // Sort results - - 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; - - for (auto& result : results) { - std::cout << std::setw(display_val + 3) << std::get<0>(result) << std::setw(display_val) << std::get<1>(result) - << std::setw(display_val) << "0x" << std::hex << std::get<2>(result) << std::dec << std::endl; - } - std::cout << "Time: " << std::chrono::duration_cast>(end_time - begin_time).count() - << " sec" << std::endl; // Display time - - std::cout << "This program execute: " << std::fixed - << (static_cast(max_range - min_range) - / std::chrono::duration_cast>(end_time - begin_time).count()) - / 1000000 - << " MOps/sec" << std::endl; // Display perf - std::cout << "" << std::endl; -} - -#if defined(BUILD_WITH_CUDA) -void GTA_SA::cuda_runner() -{ - if ((max_range - min_range) < cuda_block_size) { - std::cout << "Number of calculations is less than cuda_block_size" << std::endl; - } - - std::vector jamcrc_results; - std::vector index_results; - - my::cuda::launch_kernel(jamcrc_results, index_results, min_range, max_range, cuda_block_size); - - for (uint64_t i = 0; i < jamcrc_results.size(); ++i) { - std::array tmpCUDA = {0}; - - GTA_SA::find_string_inv(tmpCUDA.data(), index_results[i]); - std::reverse(tmpCUDA.data(), - tmpCUDA.data() + strlen(tmpCUDA.data())); // Invert char array - - const auto&& it = std::find(std::begin(GTA_SA::cheat_list), std::end(GTA_SA::cheat_list), jamcrc_results[i]); - - const uint64_t index = static_cast(it - std::begin(GTA_SA::cheat_list)); - results.emplace_back( - std::make_tuple(index_results[i], std::string(tmpCUDA.data()), jamcrc_results[i], cheat_list_name.at(index))); - } -} -#endif - -void GTA_SA::cpu_runner(const std::uint64_t i) -{ - std::array tmp = {0}; - GTA_SA::find_string_inv(tmp.data(), - i); // Generate Alphabetic sequence from uint64_t - // value, A=1, Z=27, AA = 28, AB = 29 - const uint32_t crc = GTA_SA::jamcrc(tmp.data()); // JAMCRC - const auto it = std::find(std::begin(GTA_SA::cheat_list), std::end(GTA_SA::cheat_list), crc); - - // If crc is present in Array - if (it != std::end(GTA_SA::cheat_list)) { - std::reverse(tmp.data(), - tmp.data() + strlen(tmp.data())); // Invert char array - - const uint64_t index = static_cast(it - std::begin(GTA_SA::cheat_list)); - results.emplace_back( - std::make_tuple(i, - std::string(tmp.data()), - crc, - cheat_list_name.at(static_cast(index)))); // Save result: calculation position, - // Alphabetic sequence, CRC, - } -} - -auto GTA_SA::jamcrc(std::string_view my_string, const uint32_t previousCrc32) -> std::uint32_t -{ - auto crc = ~previousCrc32; - const uint8_t* current = reinterpret_cast(my_string.data()); - uint64_t length = my_string.length(); - // process eight bytes at once - while (static_cast(length--)) { - crc = (crc >> 8) ^ crc32_lookup[(crc & 0xFF) ^ *current++]; - } - return crc; -} - -/** - * \brief Generate Alphabetic sequence from uint64_t value, A=0, Z=26, AA = 27, - * T \param n index in base 26 \param array return array - */ -void GTA_SA::find_string_inv(char* array, uint64_t n) -{ - // If n < 27 - if (n < 26) { - array[0] = alpha[static_cast(n)]; - return; - } - // If n > 27 - std::uint64_t i = 0; - while (n > 0) { - array[i] = alpha[(--n) % 26]; - n /= 26; - ++i; - } -} diff --git a/source/GTA_SA_cheat_finder.hpp b/source/GTA_SA_cheat_finder.hpp deleted file mode 100755 index 013a45f..0000000 --- a/source/GTA_SA_cheat_finder.hpp +++ /dev/null @@ -1,266 +0,0 @@ -#ifndef GTA_SA_HPP -#define GTA_SA_HPP - -#include // std::find -#include // std::array -#include // std::chrono -#include // std::ceil -#include // strlen -#include // std::setw -#include // std::cout -#include // std::string -#include // std::string_view -#include // std::pair -#include // std::make_pair -#include // std::vector - -#include "BS_thread_pool.hpp" - -#if __has_include("omp.h") -# include -#endif - -#if !defined(_OPENMP) -# if _MSC_VER && !__INTEL_COMPILER -# pragma message("No openMP ! Use std::thread.") -# else -# warning No openMP ! Use std::thread. -# endif -#endif - -#if __has_include("cuda.h") -# ifndef BUILD_WITH_CUDA -# define BUILD_WITH_CUDA -# endif -#endif - -#if defined(BUILD_WITH_CUDA) -# include "cuda/wrapper.hpp" -#endif - -class GTA_SA -{ -public: - GTA_SA(); - ~GTA_SA(); - - GTA_SA& operator=(const GTA_SA& other); - - void cpu_runner(const std::uint64_t i); -#if defined(BUILD_WITH_CUDA) - void cuda_runner(); -#endif - void run(); - void clear(); - /** - * @brief To get JAMCRC with boost libs - * @param my_string String input - * @return uint32_t with JAMCRC value - */ - static auto jamcrc(std::string_view my_string, const uint32_t previousCrc32 = 0) -> std::uint32_t; - - /** - * \brief Generate Alphabetic sequence from uint64_t value, A=1, Z=27, AA = - * 28, AB = 29 \param n index in base 26 \param array return array - */ - static void find_string_inv(char* array, uint64_t n); - - /** - * \brief Source: - * https://create.stephan-brumme.com/crc32/#slicing-by-8-overview - */ -#if defined(_MSC_VER) - inline static std::vector> results = {}; -#else - std::vector> results = {}; -#endif - - uint32_t max_thread_support() - { -#if defined(_OPENMP) - auto max_threads = static_cast(omp_get_max_threads()); - if (max_threads == 0) { - max_threads = 1; - } - return max_threads; -#else - auto max_threads = static_cast(std::thread::hardware_concurrency()); - if (max_threads == 0) { - max_threads = 1; - } - return max_threads; -#endif - } - - uint32_t num_thread = max_thread_support(); - - // Max 1024 threads per block with CUDA 2.0 and above - uint64_t cuda_block_size = 64; - - uint64_t min_range = 0; // Alphabetic sequence range min - uint64_t max_range = 0; - -#if defined(BUILD_WITH_CUDA) - uint64_t calc_mode = 2; // 0 = std::thread, 1 = OpenMP, 2 = CUDA, 3 = OpenCL -#elif defined(_OPENMP) - uint64_t calc_mode = 1; // 0 = std::thread, 1 = OpenMP, 2 = CUDA, 3 = OpenCL -#else - uint64_t calc_mode = 0; // 0 = std::thread, 1 = OpenMP, 2 = CUDA, 3 = OpenCL -#endif - -#if defined(_OPENMP) - static constexpr bool builtWithOpenMP = true; -#else - static constexpr bool builtWithOpenMP = false; -#endif - -#if defined(BUILD_WITH_CUDA) - static constexpr bool builtWithCUDA = true; -#else - static constexpr bool builtWithCUDA = false; -#endif - - std::chrono::high_resolution_clock::time_point begin_time = std::chrono::high_resolution_clock::now(); - - std::chrono::high_resolution_clock::time_point end_time = std::chrono::high_resolution_clock::now(); - - static constexpr std::uint32_t string_size_alphabet {27}; - static constexpr std::array alpha {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; - - static constexpr std::array cheat_list { - 0xDE4B237D, 0xB22A28D1, 0x5A783FAE, 0xEECCEA2B, 0x42AF1E28, 0x555FC201, 0x2A845345, 0xE1EF01EA, 0x771B83FC, - 0x5BF12848, 0x44453A17, 0xFCFF1D08, 0xB69E8532, 0x8B828076, 0xDD6ED9E9, 0xA290FD8C, 0x3484B5A7, 0x43DB914E, - 0xDBC0DD65, 0xD08A30FE, 0x37BF1B4E, 0xB5D40866, 0xE63B0D99, 0x675B8945, 0x4987D5EE, 0x2E8F84E8, 0x1A9AA3D6, - 0xE842F3BC, 0x0D5C6A4E, 0x74D4FCB1, 0xB01D13B8, 0x66516EBC, 0x4B137E45, 0x78520E33, 0x3A577325, 0xD4966D59, - 0x5FD1B49D, 0xA7613F99, 0x1792D871, 0xCBC579DF, 0x4FEDCCFF, 0x44B34866, 0x2EF877DB, 0x2781E797, 0x2BC1A045, - 0xB2AFE368, 0xFA8DD45B, 0x8DED75BD, 0x1A5526BC, 0xA48A770B, 0xB07D3B32, 0x80C1E54B, 0x5DAD0087, 0x7F80B950, - 0x6C0FA650, 0xF46F2FA4, 0x70164385, 0x885D0B50, 0x151BDCB3, 0xADFA640A, 0xE57F96CE, 0x040CF761, 0xE1B33EB9, - 0xFEDA77F7, 0x8CA870DD, 0x9A629401, 0xF53EF5A5, 0xF2AA0C1D, 0xF36345A8, 0x8990D5E1, 0xB7013B1B, 0xCAEC94EE, - 0x31F0C3CC, 0xB3B3E72A, 0xC25CDBFF, 0xD5CF4EFF, 0x680416B1, 0xCF5FDA18, 0xF01286E9, 0xA841CC0A, 0x31EA09CF, - 0xE958788A, 0x02C83A7C, 0xE49C3ED4, 0x171BA8CC, 0x86988DAE, 0x2BDD2FA1}; - /// List of cheats codes names - const std::array cheat_list_name {"Weapon Set 1", - "Weapon Set 2", - "Weapon Set 3", - "Health, Armor, $250k, Repairs car", - "Increase Wanted Level +2", - "Clear Wanted Level", - "Sunny Weather", - "Very Sunny Weather", - "Overcast Weather", - "Rainy Weather", - "Foggy Weather", - "Faster Clock", - "N°12", - "N°13", - "People attack each other with golf clubs", - "Have a bounty on your head", - "Everyone is armed", - "Spawn Rhino", - "Spawn Bloodring Banger", - "Spawn Rancher", - "Spawn Racecar", - "Spawn Racecar", - "Spawn Romero", - "Spawn Stretch", - "Spawn Trashmaster", - "Spawn Caddy", - "Blow Up All Cars", - "Invisible car", - "All green lights", - "Aggressive Drivers", - "Pink CArs", - "Black Cars", - "Fat Body", - "Muscular Body", - "Skinny Body", - "People attack with Rocket Launchers", - "N°41", - "N°42", - "Gangs Control the Streets", - "N°44", - "Slut Magnet", - "N°46", - "N°47", - "Cars Fly", - "N°49", - "N°50", - "Spawn Vortex Hovercraft", - "Smash n' Boom", - "N°53", - "N°54", - "N°55", - "Orange Sky", - "Thunderstorm", - "Sandstorm", - "N°59", - "N°60", - "Infinite Health", - "Infinite Oxygen", - "Have Parachute", - "N°64", - "Never Wanted", - "N°66", - "Mega Punch", - "Never Get Hungry", - "N°69", - "N°70", - "N°71", - "N°72", - "Full Weapon Aiming While Driving", - "N°74", - "Traffic is Country Vehicles", - "Recruit Anyone (9mm)", - "Get Born 2 Truck Outfit", - "N°78", - "N°79", - "N°80", - "L3 Bunny Hop", - "N°82", - "N°83", - "N°84", - "Spawn Quad", - "Spawn Tanker Truck", - "Spawn Dozer", - "pawn Stunt Plane", - "Spawn Monster"}; - - /** - * \brief Source: - * https://create.stephan-brumme.com/crc32/#slicing-by-8-overview - */ - - static constexpr std::array crc32_lookup = { - 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, - 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, - 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, - 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, - 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, - 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, - 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, - 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, - 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, - 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, - 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, - 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, - 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, - 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, - 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, - 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, - 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, - 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, - 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, - 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, - 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, - 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, - 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, - 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, - 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, - 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, - 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, - 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, - 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, - }; -}; - -#endif // GTA_SA_H diff --git a/source/about_compilation.cpp b/source/about_compilation.cpp deleted file mode 100644 index 582bfe2..0000000 --- a/source/about_compilation.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "about_compilation.h" - -about_compilation::about_compilation(QObject* parent) - : QObject(parent) -{ -} - -string about_compilation::ver_string(int a, int b, int c) -{ - std::ostringstream ss; - ss << a << '.' << b << '.' << c; - return ss.str(); -} diff --git a/source/about_compilation.h b/source/about_compilation.h deleted file mode 100644 index 88aa24c..0000000 --- a/source/about_compilation.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef ABOUT_COMPILATION_H -#define ABOUT_COMPILATION_H - -#include -#include -#include -#include -#include -#include - -#include "utils/compilation.hpp" - -#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) -# if __has_include("cuda.h") -# include -# ifndef BUILD_WITH_CUDA -# define BUILD_WITH_CUDA -# define BUILD_WITH_CUDA -# endif -# else -# if _MSC_VER && !__INTEL_COMPILER -# pragma message("Can t find cuda.h, disable CUDA module") -# else -# warning Can t find cuda.h, disable CUDA module. -# endif -# endif -#endif - -using namespace std; - -class about_compilation : public QObject -{ - Q_OBJECT -public: - explicit about_compilation(QObject* parent = nullptr); - - std::string ver_string(int a, int b, int c); - - Q_INVOKABLE - QString return_Compiler_version() { return QString::fromStdString(my::compile::compiler_ver()); } - - Q_INVOKABLE - QString return_Compiler_name() { return QString::fromStdString(my::compile::compiler()); } - - Q_INVOKABLE - QString return_Cplusplus_used() { return QString::fromStdString(my::compile::cxx()); } - - Q_INVOKABLE - QString return_BuildDate() { return QString::fromStdString(my::compile::build_date()); } - Q_INVOKABLE - QString openmpIsEnable() - { -#if !defined(_OPENMP) - return QString::fromStdString("false"); -#else - return QString::fromStdString("true"); -#endif - } - Q_INVOKABLE - QString cudaIsEnable() - { -#if !defined(BUILD_WITH_CUDA) - return QString::fromStdString("false"); -#else - return QString::fromStdString("true"); -#endif - } - Q_INVOKABLE - QString openclIsEnable() - { - return QString::fromStdString("false"); - } - -signals: - -public slots: -}; - -#endif // ABOUT_COMPILATION_H diff --git a/source/application.cpp b/source/application.cpp new file mode 100644 index 0000000..0c3aaab --- /dev/null +++ b/source/application.cpp @@ -0,0 +1,208 @@ +#include "application.h" + +application::application(QObject *parent) : QObject{parent} {} + +QString application::textBoxValue() const { return _textBoxValue; } + +QStringList application::getbencTypeList() const { return _bencTypeList; } + +void application::setTextBoxValue(QString value) { + qDebug() << "setTextBoxValue" + << ": " << value; + if (value == _textBoxValue) + return; + _textBoxValue = value; + emit textBoxValueChanged(value); +} + +bool application::getBenchUnsignedInteger64() const { return _benchUnsignedInteger64; } + +void application::setBenchUnsignedInteger64(bool value) { + qDebug() << "setBenchUnsignedInteger64" + << ": " << value; + if (value == _benchUnsignedInteger64) { + return; + } + _benchUnsignedInteger64 = value; + emit benchUnsignedInteger64Changed(value); +} + +bool application::getBenchUnsignedInteger32() const { return _benchUnsignedInteger32; } + +void application::setBenchUnsignedInteger32(bool value) { + qDebug() << "setBenchUnsignedInteger32" + << ": " << value; + if (value == _benchUnsignedInteger32) { + return; + } + _benchUnsignedInteger32 = value; + emit benchUnsignedInteger32Changed(value); +} + +bool application::getBenchUnsignedInteger16() const { return _benchUnsignedInteger16; } + +void application::setBenchUnsignedInteger16(bool value) { + qDebug() << "setBenchUnsignedInteger16" + << ": " << value; + if (value == _benchUnsignedInteger16) { + return; + } + _benchUnsignedInteger16 = value; + emit benchUnsignedInteger16Changed(value); +} + +bool application::getBenchUnsignedInteger8() const { return _benchUnsignedInteger8; } + +void application::setBenchUnsignedInteger8(bool value) { + qDebug() << "setBenchUnsignedInteger8" + << ": " << value; + if (value == _benchUnsignedInteger8) { + return; + } + _benchUnsignedInteger8 = value; + emit benchUnsignedInteger8Changed(value); +} + +int application::getBencTypeIndex() const { return _bencTypeIndex; } + +void application::setBencTypeIndex(int value) { + qDebug() << "setBencTypeIndex" + << ": " << value; + if (value == _bencTypeIndex) { + return; + } + _bencTypeIndex = value; + emit bencTypeIndexChanged(value); +} + +QString application::getInfo() { return "Made with Qt 6 !"; } + +template T application::rand(const T min, const T max) { + std::random_device rd; + std::seed_seq seed{rd()}; + G rng(seed); + + using dist_type = typename std::conditional::value, std::uniform_int_distribution, std::uniform_real_distribution>::type; + + dist_type uni(min, max); + return uni(rng); +} + +template void application::bench_operation(const size_t count, F lambda) { + // volatile T x1 = this->rand(); + + const auto start_rdtsc = rdtsc(); + const auto start = std::chrono::high_resolution_clock::now(); + + lambda(); + + const auto finish = std::chrono::high_resolution_clock::now(); + const auto finish_rdtsc = rdtsc(); + + const std::chrono::duration elapsed = finish - start; + const double elapsed_rdtsc = static_cast(finish_rdtsc - start_rdtsc) / count; + + qDebug() << "Elapsed rdtsc: " << elapsed_rdtsc << " cycles/ops"; + qDebug() << "Elapsed Time: " << static_cast(elapsed.count() / count) << " nano seconds per operation"; + qDebug() << static_cast(count / elapsed.count()) << " GOps/sec"; +} + +void application::run() { + // auto future = QtConcurrent::task(&application::add_operation).withArguments(this).spawn(); + + const size_t count = 1000000000; + /* + if (getBenchUnsignedInteger8()) { + qDebug() << "Bench type: uint8_t"; + using bench_type = uint8_t; + auto future = QtConcurrent::run(&application::add_operation, this, count); + future.waitForFinished(); + } + if (getBenchUnsignedInteger16()) { + qDebug() << "Bench type: uint16_t"; + using bench_type = uint16_t; + auto future = QtConcurrent::run(&application::add_operation, this, count); + future.waitForFinished(); + } + */ + if (getBenchUnsignedInteger32()) { + qDebug() << "Bench type: uint32_t"; + using bench_type = uint32_t; + + constexpr auto lambda = [&]() { + const size_t count = 1000000000; + volatile T x0 = 0; + const volatile T x1 = 1; + const volatile T x2 = 2; + for (size_t i = 0; i < count; i++) { + x0 = x1 + x2; + } + }; + auto future = QtConcurrent::run(&application::bench_operation, this, count, lambda); + future.waitForFinished(); + } + if (getBenchUnsignedInteger64()) { + qDebug() << "Bench type: uint64_t"; + using bench_type = uint64_t; + + constexpr auto lambda = []() { + const size_t count = 1000000000; + volatile T x0 = 0; + const volatile T x1 = 1; + const volatile T x2 = 2; + for (size_t i = 0; i < count; i++) { + x0 = x1 + x2; + } + }; + auto future = QtConcurrent::run(&application::bench_operation, this, count, lambda); + future.waitForFinished(); + } + // qDebug() << "Elapsed Time (sub_operation): " << this->sub_operation() << " nano seconds per + // operation" qDebug() << "Elapsed Time (mul_operation): " << this->mul_operation() << " nano seconds + // per operation" qDebug() << "Elapsed Time (div_operation): " << this->div_operation() << " nano + // seconds per operation" +} + +void application::print_result(QStringView value) { qDebug() << value; } + +#if defined(__x86_64__) || defined(__i386__) || defined(_M_AMD64) +uint64_t application::rdtsc() { return __rdtsc(); } +#else +uint64_t application::rdtsc() { return 0; } + +#warning "Unsupport rdtsc" +#endif + +QString application::compilerArch() { return QString::fromStdString(compile::arch()); } + +QString application::compilerName() { return QString::fromStdString(compile::compiler()); } + +QString application::compilerVersion() { return QString::fromStdString(compile::compiler_ver()); } + +QString application::cxxVersion() { return QString::fromStdString(compile::cxx()); } + +QString application::cVersion() { return QString::fromStdString(compile::c()); } + +QString application::buildDate() { return QString::fromStdString(compile::build_date()); } + +QString application::buildType() { +#ifdef CMAKE_BUILD_TYPE + return QString(CMAKE_BUILD_TYPE); +#else + return QString("Unknown"); +#endif +} + +QString application::qtVersion() { return QString::fromStdString(compile::qt_version()); } + +QString application::appVersion() { +#ifdef PROJECT_VERSION + return QString(PROJECT_VERSION); +#else + return QString("Unknown"); +#endif +} + +QString application::appAuthor() { return QString("Bensuperpc"); } + +QString application::appBusiness() { return QString("bensuperpc (bensuperpc.org)"); } diff --git a/source/application.h b/source/application.h new file mode 100644 index 0000000..e495ca1 --- /dev/null +++ b/source/application.h @@ -0,0 +1,98 @@ +#ifndef APPLICATION_H +#define APPLICATION_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(__x86_64__) || defined(__i386__) || defined(_M_AMD64) +#if __has_include("x86intrin.h") +#include +#endif +#endif + +#include "utils/about_compilation.h" + +class application final : public QObject { + Q_OBJECT + Q_DISABLE_COPY(application) + + Q_PROPERTY(QString textBoxValue READ textBoxValue WRITE setTextBoxValue NOTIFY textBoxValueChanged) + Q_PROPERTY(QStringList bencTypeList READ getbencTypeList CONSTANT FINAL) + Q_PROPERTY(int bencTypeIndex READ getBencTypeIndex WRITE setBencTypeIndex NOTIFY bencTypeIndexChanged FINAL) + + // multiple type + Q_PROPERTY(bool benchUnsignedInteger64 READ getBenchUnsignedInteger64 WRITE setBenchUnsignedInteger64 NOTIFY benchUnsignedInteger64Changed FINAL) + Q_PROPERTY(bool benchUnsignedInteger32 READ getBenchUnsignedInteger32 WRITE setBenchUnsignedInteger32 NOTIFY benchUnsignedInteger32Changed FINAL) + Q_PROPERTY(bool benchUnsignedInteger16 READ getBenchUnsignedInteger16 WRITE setBenchUnsignedInteger16 NOTIFY benchUnsignedInteger16Changed FINAL) + Q_PROPERTY(bool benchUnsignedInteger8 READ getBenchUnsignedInteger8 WRITE setBenchUnsignedInteger8 NOTIFY benchUnsignedInteger8Changed FINAL) + +public: + explicit application(QObject *parent = nullptr); + + QString textBoxValue() const; + QStringList getbencTypeList() const; + + Q_INVOKABLE QString getInfo(); + + Q_INVOKABLE void run(); + void print_result(QStringView value); + + template + inline T rand(const T min = std::numeric_limits::min(), const T max = std::numeric_limits::max()); + + template inline void bench_operation(const size_t count, F lambda); + uint64_t rdtsc(); + + // Compiler Info + Q_INVOKABLE QString compilerArch(); + Q_INVOKABLE QString compilerName(); + Q_INVOKABLE QString compilerVersion(); + Q_INVOKABLE QString cxxVersion(); + Q_INVOKABLE QString cVersion(); + Q_INVOKABLE QString buildDate(); + Q_INVOKABLE QString buildType(); + Q_INVOKABLE QString qtVersion(); + Q_INVOKABLE QString appAuthor(); + Q_INVOKABLE QString appBusiness(); + Q_INVOKABLE QString appVersion(); + +private: + QString _textBoxValue = "Hello, world!"; + QStringList _bencTypeList = {"Addition", "Substraction", "Multiplication", "Division"}; + bool _benchUnsignedInteger64 = true; + bool _benchUnsignedInteger32 = true; + bool _benchUnsignedInteger16 = true; + bool _benchUnsignedInteger8 = true; + int _bencTypeIndex = 0; + +public slots: + void setTextBoxValue(QString value); + void setBenchUnsignedInteger64(bool value); + bool getBenchUnsignedInteger64() const; + void setBenchUnsignedInteger32(bool value); + bool getBenchUnsignedInteger32() const; + void setBenchUnsignedInteger16(bool value); + bool getBenchUnsignedInteger16() const; + void setBenchUnsignedInteger8(bool value); + bool getBenchUnsignedInteger8() const; + void setBencTypeIndex(int value); + int getBencTypeIndex() const; +signals: + void textBoxValueChanged(QString value); + void benchUnsignedInteger64Changed(bool value); + void benchUnsignedInteger32Changed(bool value); + void benchUnsignedInteger16Changed(bool value); + void benchUnsignedInteger8Changed(bool value); + void bencTypeIndexChanged(int value); +}; + +#endif // APPLICATION_H diff --git a/source/asyncimageprovider.h b/source/asyncimageprovider.h new file mode 100644 index 0000000..9042eb5 --- /dev/null +++ b/source/asyncimageprovider.h @@ -0,0 +1,76 @@ +#ifndef ASYNCIMAGEPROVIDER_H +#define ASYNCIMAGEPROVIDER_H + +#include +#include +#include +#include + +#include +#include + +class AsyncImageResponseRunnable : public QObject, public QRunnable { + Q_OBJECT + +signals: + void done(QImage image); + +public: + AsyncImageResponseRunnable(const QString &id, const QSize &requestedSize) : m_id(id), m_requestedSize(requestedSize) {} + + void run() override { + qDebug() << "Load image ID: " << m_id; + // QThread::sleep(5); + + const QString file = "image/" + m_id; + QImage image; + if (QFile::exists(file)) { + image.load(file); + } else { + // image = QImage(50, 50, QImage::Format_RGB32); + // image.fill(Qt::white); + qWarning() << "Image: " << file << " not found!"; + } + + if (m_requestedSize.isValid()) { + image = image.scaled(m_requestedSize); + } + + emit done(image); + } + +private: + QString m_id; + QSize m_requestedSize; +}; + +class AsyncImageResponse : public QQuickImageResponse { +public: + AsyncImageResponse(const QString &id, const QSize &requestedSize, QThreadPool *pool) { + auto runnable = new AsyncImageResponseRunnable(id, requestedSize); + connect(runnable, &AsyncImageResponseRunnable::done, this, &AsyncImageResponse::handleDone); + pool->start(runnable); + } + + void handleDone(QImage image) { + m_image = image; + emit finished(); + } + + QQuickTextureFactory *textureFactory() const override { return QQuickTextureFactory::textureFactoryForImage(m_image); } + + QImage m_image; +}; + +class AsyncImageProvider : public QQuickAsyncImageProvider { +public: + QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override { + AsyncImageResponse *response = new AsyncImageResponse(id, requestedSize, &pool); + return response; + } + +private: + QThreadPool pool; +}; + +#endif // ASYNCIMAGEPROVIDER_H diff --git a/source/cuda/kernel.cu b/source/cuda/kernel.cu deleted file mode 100755 index 665f014..0000000 --- a/source/cuda/kernel.cu +++ /dev/null @@ -1,119 +0,0 @@ -////////////////////////////////////////////////////////////// -// ____ // -// | __ ) ___ _ __ ___ _ _ _ __ ___ _ __ _ __ ___ // -// | _ \ / _ \ '_ \/ __| | | | '_ \ / _ \ '__| '_ \ / __| // -// | |_) | __/ | | \__ \ |_| | |_) | __/ | | |_) | (__ // -// |____/ \___|_| |_|___/\__,_| .__/ \___|_| | .__/ \___| // -// |_| |_| // -////////////////////////////////////////////////////////////// -// // -// BenLib, 2021 // -// Created: 21, March, 2021 // -// Modified: 29, April, 2022 // -// file: kernel.cu // -// Crypto // -// Source: -// https://stackoverflow.com/questions/13553015/cuda-c-linker-error-undefined-reference -// // -// https://www.olcf.ornl.gov/tutorials/cuda-vector-addition/ // -// https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/index.html#asynchronous-transfers-and-overlapping-transfers-with-computation__concurrent-copy-and-execute -// https://www.ce.jhu.edu/dalrymple/classes/602/Class12.pdf // -// https://create.stephan-brumme.com/crc32/ -// CPU: ALL // -// // -////////////////////////////////////////////////////////////// - -#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; - - 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; -} - -__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; - - 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}; - - uint64_t size = 0; - // Generate the array from index (id) - find_string_inv_kernel(array, id, &size); - - // 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); - - bool found = false; - for (uint8_t i = 0; i < 87; i++) { - if (result == cheat_list[i]) { - found = true; - break; - } - } - - if (!found) { - return; - } - - // Todo: Avoid datarace - //__syncthreads(); - - 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; - } - } - } -} - -__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; -} diff --git a/source/cuda/kernel.cuh b/source/cuda/kernel.cuh deleted file mode 100755 index a795f20..0000000 --- a/source/cuda/kernel.cuh +++ /dev/null @@ -1,86 +0,0 @@ - - -////////////////////////////////////////////////////////////// -// ____ // -// | __ ) ___ _ __ ___ _ _ _ __ ___ _ __ _ __ ___ // -// | _ \ / _ \ '_ \/ __| | | | '_ \ / _ \ '__| '_ \ / __| // -// | |_) | __/ | | \__ \ |_| | |_) | __/ | | |_) | (__ // -// |____/ \___|_| |_|___/\__,_| .__/ \___|_| | .__/ \___| // -// |_| |_| // -////////////////////////////////////////////////////////////// -// // -// BenLib, 2021 // -// Created: 21, March, 2021 // -// Modified: 29, April, 2022 // -// file: kernel.cuh // -// Crypto // -// Source: -// https://stackoverflow.com/questions/13553015/cuda-c-linker-error-undefined-reference -// // -// https://www.olcf.ornl.gov/tutorials/cuda-vector-addition/ // -// CPU: ALL // -// // -////////////////////////////////////////////////////////////// - -#ifndef CUDA_KERNEL_CUH -#define CUDA_KERNEL_CUH - -#include -#include -#include - -__device__ uint32_t jamcrc_kernel(const void* data, uint64_t length, const uint32_t previousCrc32); - -__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); - -__device__ const uint32_t crc32_lookup[256] = { - 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, - 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, - 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, - 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, - 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, - 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, - 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, - 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, - 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, - 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, - 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, - 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, - 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, - 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, - 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, - 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, - 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, - 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, - 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, - 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, - 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, - 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, - 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, - 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, - 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, - 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, - 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, - 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, - 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D}; - -__device__ const uint32_t cheat_list[87] = { - 0xDE4B237D, 0xB22A28D1, 0x5A783FAE, 0xEECCEA2B, 0x42AF1E28, 0x555FC201, 0x2A845345, 0xE1EF01EA, 0x771B83FC, - 0x5BF12848, 0x44453A17, 0xFCFF1D08, 0xB69E8532, 0x8B828076, 0xDD6ED9E9, 0xA290FD8C, 0x3484B5A7, 0x43DB914E, - 0xDBC0DD65, 0xD08A30FE, 0x37BF1B4E, 0xB5D40866, 0xE63B0D99, 0x675B8945, 0x4987D5EE, 0x2E8F84E8, 0x1A9AA3D6, - 0xE842F3BC, 0x0D5C6A4E, 0x74D4FCB1, 0xB01D13B8, 0x66516EBC, 0x4B137E45, 0x78520E33, 0x3A577325, 0xD4966D59, - 0x5FD1B49D, 0xA7613F99, 0x1792D871, 0xCBC579DF, 0x4FEDCCFF, 0x44B34866, 0x2EF877DB, 0x2781E797, 0x2BC1A045, - 0xB2AFE368, 0xFA8DD45B, 0x8DED75BD, 0x1A5526BC, 0xA48A770B, 0xB07D3B32, 0x80C1E54B, 0x5DAD0087, 0x7F80B950, - 0x6C0FA650, 0xF46F2FA4, 0x70164385, 0x885D0B50, 0x151BDCB3, 0xADFA640A, 0xE57F96CE, 0x040CF761, 0xE1B33EB9, - 0xFEDA77F7, 0x8CA870DD, 0x9A629401, 0xF53EF5A5, 0xF2AA0C1D, 0xF36345A8, 0x8990D5E1, 0xB7013B1B, 0xCAEC94EE, - 0x31F0C3CC, 0xB3B3E72A, 0xC25CDBFF, 0xD5CF4EFF, 0x680416B1, 0xCF5FDA18, 0xF01286E9, 0xA841CC0A, 0x31EA09CF, - 0xE958788A, 0x02C83A7C, 0xE49C3ED4, 0x171BA8CC, 0x86988DAE, 0x2BDD2FA1}; - -#endif diff --git a/source/cuda/wrapper.cu b/source/cuda/wrapper.cu deleted file mode 100755 index 175c62c..0000000 --- a/source/cuda/wrapper.cu +++ /dev/null @@ -1,167 +0,0 @@ -////////////////////////////////////////////////////////////// -// ____ // -// | __ ) ___ _ __ ___ _ _ _ __ ___ _ __ _ __ ___ // -// | _ \ / _ \ '_ \/ __| | | | '_ \ / _ \ '__| '_ \ / __| // -// | |_) | __/ | | \__ \ |_| | |_) | __/ | | |_) | (__ // -// |____/ \___|_| |_|___/\__,_| .__/ \___|_| | .__/ \___| // -// |_| |_| // -////////////////////////////////////////////////////////////// -// // -// BenLib, 2021 // -// Created: 21, March, 2021 // -// Modified: 29, April, 2022 // -// file: kernel.cu // -// Crypto // -// Source: -// https://stackoverflow.com/questions/13553015/cuda-c-linker-error-undefined-reference -// // -// https://www.olcf.ornl.gov/tutorials/cuda-vector-addition/ // -// https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/index.html#asynchronous-transfers-and-overlapping-transfers-with-computation__concurrent-copy-and-execute -// https://www.ce.jhu.edu/dalrymple/classes/602/Class12.pdf // -// https://create.stephan-brumme.com/crc32/ -// CPU: ALL // -// // -////////////////////////////////////////////////////////////// - -#include "wrapper.hpp" - -__host__ void jamcrc_wrapper(dim3* grid, - dim3* threads, - cudaStream_t* stream, - const int device, - const void* data, - const uint64_t length, - uint32_t* result, - const uint32_t previousCrc32) -{ - jamcrc_kernel_wrapper<<<*grid, *threads, device, *stream>>>(data, result, length, previousCrc32); -} - -__host__ uint32_t my::cuda::jamcrc(const void* data, - const uint64_t length, - const uint32_t previousCrc32, - const uint32_t cuda_block_size) -{ - int device = 0; - cudaGetDevice(&device); - - cudaStream_t stream; - cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking); - - // Calculate length of the array with max_range and min_range - uint64_t data_size = (length) * sizeof(char); - uint32_t* data_cuda = nullptr; - - uint64_t result_size = 1 * sizeof(uint32_t); - uint32_t* result_cuda = nullptr; - - cudaMallocManaged(&data_cuda, data_size, cudaMemAttachGlobal); - cudaMallocManaged(&result_cuda, result_size, cudaMemAttachGlobal); - - cudaStreamAttachMemAsync(stream, &data_cuda); - cudaStreamAttachMemAsync(stream, &result_cuda); - - cudaMemPrefetchAsync(data_cuda, data_size, device, stream); - cudaMemPrefetchAsync(result_cuda, result_size, device, stream); - - memcpy(data_cuda, data, data_size); - *result_cuda = 0; - - uint64_t grid_size = static_cast(ceil(static_cast(1) / cuda_block_size)); - - dim3 threads(static_cast(cuda_block_size), 1, 1); - dim3 grid(static_cast(grid_size), 1, 1); - - jamcrc_kernel_wrapper<<>>(data_cuda, result_cuda, length, previousCrc32); - - cudaStreamSynchronize(stream); - cudaDeviceSynchronize(); - - // std::cout << "result_cuda: " << *result_cuda << std::endl; - - cudaFree(data_cuda); - cudaStreamDestroy(stream); - - return *result_cuda; -} - -__host__ void my::cuda::launch_kernel(std::vector& jamcrc_results, - std::vector& index_results, - const uint64_t min_range, - const uint64_t max_range, - const uint64_t cuda_block_size) -{ - std::cout << "Launching kernel..." << std::endl; - std::cout << "min_range: " << min_range << std::endl; - std::cout << "max_range: " << max_range << std::endl; - // int device = -1; - // cudaGetDevice(&device); - - int device = 0; - cudaGetDevice(&device); - - /* - int priority_high, priority_low; - cudaDeviceGetStreamPriorityRange(&priority_low, &priority_high); - cudaStream_t st_high, st_low; - cudaStreamCreateWithPriority(&st_high, cudaStreamNonBlocking, priority_high); - cudaStreamCreateWithPriority(&st_low, cudaStreamNonBlocking, priority_low); - */ - - cudaStream_t stream; - cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking); - - // cudaDeviceSetLimit(cudaLimitMallocHeapSize, 128 * 1024 * 1024); - - // Calculate length of the array with max_range and min_range (Estimate size of the array) - uint64_t array_length = static_cast((max_range - min_range) / 20000000); - uint64_t jamcrc_results_size = array_length * sizeof(uint32_t); - uint64_t index_results_size = array_length * sizeof(uint64_t); - - uint32_t* jamcrc_results_ptr = nullptr; - uint64_t* index_results_ptr = nullptr; - - cudaMallocManaged(&jamcrc_results_ptr, jamcrc_results_size, cudaMemAttachGlobal); - cudaMallocManaged(&index_results_ptr, index_results_size, cudaMemAttachGlobal); - - cudaStreamAttachMemAsync(stream, &jamcrc_results_ptr); - cudaStreamAttachMemAsync(stream, &index_results_size); - - cudaMemPrefetchAsync(jamcrc_results_ptr, jamcrc_results_size, device, stream); - cudaMemPrefetchAsync(index_results_ptr, index_results_size, device, stream); - - for (uint64_t i = 0; i < array_length; ++i) { - jamcrc_results_ptr[i] = 0; - index_results_ptr[i] = 0; - } - - uint64_t grid_size = static_cast(ceil(static_cast(max_range - min_range) / cuda_block_size)); - std::cout << "CUDA Grid size: " << grid_size << std::endl; - std::cout << "CUDA Block size: " << cuda_block_size << std::endl; - - dim3 threads(static_cast(cuda_block_size), 1, 1); - dim3 grid(static_cast(grid_size), 1, 1); - - runner_kernel<<>>( - jamcrc_results_ptr, index_results_ptr, array_length, min_range, max_range); - - jamcrc_results.reserve(array_length); - index_results.reserve(array_length); - - cudaStreamSynchronize(stream); - - for (uint64_t i = 0; i < array_length; ++i) { - if (jamcrc_results_ptr[i] != index_results_ptr[i]) { - jamcrc_results.emplace_back(jamcrc_results_ptr[i]); - index_results.emplace_back(index_results_ptr[i]); - } - } - - cudaDeviceSynchronize(); - cudaFree(jamcrc_results_ptr); - cudaFree(index_results_ptr); - - cudaStreamDestroy(stream); - // cudaStreamDestroy(st_high); - // cudaStreamDestroy(st_low); -} diff --git a/source/customlabel.cpp b/source/customlabel.cpp new file mode 100644 index 0000000..75da65e --- /dev/null +++ b/source/customlabel.cpp @@ -0,0 +1,24 @@ +#include "customlabel.h" + +MyLabel::MyLabel(QObject *parent) : QObject{parent} {} + +void MyLabel::setMyObject(QObject *obj) { + if (!obj) { + return; + } + + myObject = obj; + myObject->setProperty("visible", QVariant(true)); + myObject->setProperty("text", QVariant("Hello world from C++ !")); + + QFont &&font = myObject->property("font").value(); + font.setPointSize(18); + myObject->setProperty("font", font); + + QVariant returnedValue; + QVariant message = "Hello world!"; + + QMetaObject::invokeMethod(myObject, "myQMLFunction", Q_RETURN_ARG(QVariant, returnedValue), Q_ARG(QVariant, message)); + + qDebug() << "QML function returned:" << returnedValue.toString(); +} diff --git a/source/customlabel.h b/source/customlabel.h new file mode 100644 index 0000000..6868512 --- /dev/null +++ b/source/customlabel.h @@ -0,0 +1,20 @@ +#ifndef MYLABEL_H +#define MYLABEL_H + +#include +#include +#include + +class MyLabel : public QObject { + Q_OBJECT +public: + explicit MyLabel(QObject *parent = nullptr); + + Q_INVOKABLE void setMyObject(QObject *obj); +signals: + +private: + QObject *myObject; +}; + +#endif // MYLABEL_H diff --git a/source/qt-utils/CMakeLists.txt b/source/gta_cheat_finder/CMakeLists.txt similarity index 51% rename from source/qt-utils/CMakeLists.txt rename to source/gta_cheat_finder/CMakeLists.txt index 879c34d..6fa1edf 100644 --- a/source/qt-utils/CMakeLists.txt +++ b/source/gta_cheat_finder/CMakeLists.txt @@ -20,38 +20,71 @@ cmake_minimum_required(VERSION 3.14) project( - qt_utils_lib + GTA_SA_cheat_finder_lib VERSION 0.1.0 - DESCRIPTION "utils library with Qt" + DESCRIPTION "GTA_SA_cheat_finder lib" HOMEPAGE_URL "https://github.com/bensuperpc" - LANGUAGES C CXX + LANGUAGES CXX ) -find_package(Qt6 6.4 COMPONENTS Quick Gui Core Qml Charts Multimedia REQUIRED) -qt_standard_project_setup() +find_package(OpenMP 2.0) + +find_package(CUDAToolkit 11.0) + +#find_package(OpenCL 2.0) + +# Download ThreadPool +include(../../cmake/lib/threadpool.cmake) + +if (CUDAToolkit_FOUND) + add_subdirectory(cuda) +endif() set(SRCS - imageprovider/imageprovider.cpp - TableModel.cpp + state/GTA_SA_cheat_finder_openmp.cpp + state/GTA_SA_cheat_finder_stdthread.cpp + state/GTA_SA_cheat_finder_virtual.cpp + GTA_SA_cheat_finder_result.cpp ) set(HEADERS - imageprovider/imageprovider.h - TableModel.h - asyncimageprovider/asyncimageprovider.h - asyncimageprovider/async_image_response_runnable.h - asyncimageprovider/async_image_response.h + state/GTA_SA_cheat_finder_openmp.hpp + state/GTA_SA_cheat_finder_stdthread.hpp + state/GTA_SA_cheat_finder_virtual.hpp + GTA_SA_cheat_finder_result.hpp ) -add_library(qt_utils_lib ${SRCS} ${HEADERS}) -target_include_directories(qt_utils_lib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(qt_utils_lib PRIVATE Qt6::Quick Qt6::Gui Qt6::Core Qt6::Qml Qt6::Charts Qt6::Multimedia) -target_compile_features(qt_utils_lib PUBLIC cxx_std_20) +if (CUDAToolkit_FOUND) + list(APPEND SRCS state/GTA_SA_cheat_finder_cuda.cpp) + list(APPEND HEADERS state/GTA_SA_cheat_finder_cuda.hpp) +endif() + +add_library(GTA_SA_cheat_finder_lib ${SRCS} ${HEADERS}) + +target_compile_features(GTA_SA_cheat_finder_lib PUBLIC cxx_std_20) -set_target_properties(qt_utils_lib +target_include_directories( + GTA_SA_cheat_finder_lib ${warning_guard} + PUBLIC + "$" + "$" +) + +if (OpenMP_FOUND OR OpenMP_CXX_FOUND) + target_link_libraries(GTA_SA_cheat_finder_lib PUBLIC OpenMP::OpenMP_CXX) +endif() + +if (CUDAToolkit_FOUND) + target_include_directories(GTA_SA_cheat_finder_lib PUBLIC ${CUDAToolkit_INCLUDE_DIRS}) + target_link_libraries(GTA_SA_cheat_finder_lib PUBLIC CUDA::cudart) + target_link_libraries(GTA_SA_cheat_finder_lib PUBLIC cuda_lib) +endif() + +set_target_properties(GTA_SA_cheat_finder_lib PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" ) + diff --git a/source/gta_cheat_finder/GTA_SA_cheat_finder_result.cpp b/source/gta_cheat_finder/GTA_SA_cheat_finder_result.cpp new file mode 100644 index 0000000..2f71e2d --- /dev/null +++ b/source/gta_cheat_finder/GTA_SA_cheat_finder_result.cpp @@ -0,0 +1,19 @@ +#include "GTA_SA_cheat_finder_result.hpp" + +result::result(std::uint64_t _index, std::string _code, std::uint32_t _jamcrc, std::string _associated_code) + : index(_index), code(_code), jamcrc(_jamcrc), associated_code(_associated_code) {} + +result::~result() {} + +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); +} \ No newline at end of file diff --git a/source/gta_cheat_finder/GTA_SA_cheat_finder_result.hpp b/source/gta_cheat_finder/GTA_SA_cheat_finder_result.hpp new file mode 100644 index 0000000..76f9afa --- /dev/null +++ b/source/gta_cheat_finder/GTA_SA_cheat_finder_result.hpp @@ -0,0 +1,21 @@ +#ifndef GTA_SA_RESULT_HPP +#define GTA_SA_RESULT_HPP + +#include // std::uint64_t, std::uint32_t +#include // std::string + +class result { + public: + explicit result(std::uint64_t, std::string, std::uint32_t, std::string); + ~result(); + + result& operator=(const result&) noexcept; + bool operator==(const result& other) const noexcept; + + std::uint64_t index = 0; + std::string code = ""; + std::uint32_t jamcrc = 0; + std::string associated_code; +}; + +#endif // GTA_SA_RESULT_HPP diff --git a/source/cuda/CMakeLists.txt b/source/gta_cheat_finder/cuda/CMakeLists.txt old mode 100755 new mode 100644 similarity index 97% rename from source/cuda/CMakeLists.txt rename to source/gta_cheat_finder/cuda/CMakeLists.txt index a50f6b0..1d98998 --- a/source/cuda/CMakeLists.txt +++ b/source/gta_cheat_finder/cuda/CMakeLists.txt @@ -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 diff --git a/source/gta_cheat_finder/cuda/kernel.cu b/source/gta_cheat_finder/cuda/kernel.cu new file mode 100644 index 0000000..8808e42 --- /dev/null +++ b/source/gta_cheat_finder/cuda/kernel.cu @@ -0,0 +1,105 @@ +////////////////////////////////////////////////////////////// +// ____ // +// | __ ) ___ _ __ ___ _ _ _ __ ___ _ __ _ __ ___ // +// | _ \ / _ \ '_ \/ __| | | | '_ \ / _ \ '__| '_ \ / __| // +// | |_) | __/ | | \__ \ |_| | |_) | __/ | | |_) | (__ // +// |____/ \___|_| |_|___/\__,_| .__/ \___|_| | .__/ \___| // +// |_| |_| // +////////////////////////////////////////////////////////////// +// // +// BenLib, 2021 // +// Created: 21, March, 2021 // +// Modified: 29, April, 2022 // +// file: kernel.cu // +// Crypto // +// Source: +// https://stackoverflow.com/questions/13553015/cuda-c-linker-error-undefined-reference +// // +// https://www.olcf.ornl.gov/tutorials/cuda-vector-addition/ // +// https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/index.html#asynchronous-transfers-and-overlapping-transfers-with-computation__concurrent-copy-and-execute +// https://www.ce.jhu.edu/dalrymple/classes/602/Class12.pdf // +// https://create.stephan-brumme.com/crc32/ +// CPU: ALL // +// // +////////////////////////////////////////////////////////////// + +#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; + + 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; +} + +__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; + + id = id + a; + + 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}; + + uint64_t size = 0; + // Generate the array from index (id) + find_string_inv_kernel(array, id, &size); + + // 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); + + bool found = false; + for (uint8_t i = 0; i < 87; i++) { + if (result == cheat_list[i]) { + found = true; + break; + } + } + + if (!found) { + return; + } + + //__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) { + // 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; +} diff --git a/source/gta_cheat_finder/cuda/kernel.cuh b/source/gta_cheat_finder/cuda/kernel.cuh new file mode 100644 index 0000000..2ff0757 --- /dev/null +++ b/source/gta_cheat_finder/cuda/kernel.cuh @@ -0,0 +1,74 @@ + + +////////////////////////////////////////////////////////////// +// ____ // +// | __ ) ___ _ __ ___ _ _ _ __ ___ _ __ _ __ ___ // +// | _ \ / _ \ '_ \/ __| | | | '_ \ / _ \ '__| '_ \ / __| // +// | |_) | __/ | | \__ \ |_| | |_) | __/ | | |_) | (__ // +// |____/ \___|_| |_|___/\__,_| .__/ \___|_| | .__/ \___| // +// |_| |_| // +////////////////////////////////////////////////////////////// +// // +// BenLib, 2021 // +// Created: 21, March, 2021 // +// Modified: 29, April, 2022 // +// file: kernel.cuh // +// Crypto // +// Source: +// https://stackoverflow.com/questions/13553015/cuda-c-linker-error-undefined-reference +// // +// https://www.olcf.ornl.gov/tutorials/cuda-vector-addition/ // +// CPU: ALL // +// // +////////////////////////////////////////////////////////////// + +#ifndef CUDA_KERNEL_CUH +#define CUDA_KERNEL_CUH + +#include +#include +#include + +__device__ uint32_t jamcrc_kernel(const void *data, uint64_t length, const uint32_t previousCrc32); + +__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, 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, + 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, + 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, + 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, + 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, + 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, + 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, + 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, + 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, + 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, + 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, + 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, + 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, + 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, + 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, + 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, + 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, + 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, + 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D}; + +__device__ const uint32_t cheat_list[87] = { + 0xDE4B237D, 0xB22A28D1, 0x5A783FAE, 0xEECCEA2B, 0x42AF1E28, 0x555FC201, 0x2A845345, 0xE1EF01EA, 0x771B83FC, 0x5BF12848, 0x44453A17, 0xFCFF1D08, 0xB69E8532, + 0x8B828076, 0xDD6ED9E9, 0xA290FD8C, 0x3484B5A7, 0x43DB914E, 0xDBC0DD65, 0xD08A30FE, 0x37BF1B4E, 0xB5D40866, 0xE63B0D99, 0x675B8945, 0x4987D5EE, 0x2E8F84E8, + 0x1A9AA3D6, 0xE842F3BC, 0x0D5C6A4E, 0x74D4FCB1, 0xB01D13B8, 0x66516EBC, 0x4B137E45, 0x78520E33, 0x3A577325, 0xD4966D59, 0x5FD1B49D, 0xA7613F99, 0x1792D871, + 0xCBC579DF, 0x4FEDCCFF, 0x44B34866, 0x2EF877DB, 0x2781E797, 0x2BC1A045, 0xB2AFE368, 0xFA8DD45B, 0x8DED75BD, 0x1A5526BC, 0xA48A770B, 0xB07D3B32, 0x80C1E54B, + 0x5DAD0087, 0x7F80B950, 0x6C0FA650, 0xF46F2FA4, 0x70164385, 0x885D0B50, 0x151BDCB3, 0xADFA640A, 0xE57F96CE, 0x040CF761, 0xE1B33EB9, 0xFEDA77F7, 0x8CA870DD, + 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 diff --git a/source/gta_cheat_finder/cuda/wrapper.cu b/source/gta_cheat_finder/cuda/wrapper.cu new file mode 100644 index 0000000..3c69696 --- /dev/null +++ b/source/gta_cheat_finder/cuda/wrapper.cu @@ -0,0 +1,158 @@ +////////////////////////////////////////////////////////////// +// ____ // +// | __ ) ___ _ __ ___ _ _ _ __ ___ _ __ _ __ ___ // +// | _ \ / _ \ '_ \/ __| | | | '_ \ / _ \ '__| '_ \ / __| // +// | |_) | __/ | | \__ \ |_| | |_) | __/ | | |_) | (__ // +// |____/ \___|_| |_|___/\__,_| .__/ \___|_| | .__/ \___| // +// |_| |_| // +////////////////////////////////////////////////////////////// +// // +// BenLib, 2021 // +// Created: 21, March, 2021 // +// Modified: 29, April, 2022 // +// file: kernel.cu // +// Crypto // +// Source: +// https://stackoverflow.com/questions/13553015/cuda-c-linker-error-undefined-reference +// // +// https://www.olcf.ornl.gov/tutorials/cuda-vector-addition/ // +// https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/index.html#asynchronous-transfers-and-overlapping-transfers-with-computation__concurrent-copy-and-execute +// https://www.ce.jhu.edu/dalrymple/classes/602/Class12.pdf // +// https://create.stephan-brumme.com/crc32/ +// CPU: ALL // +// // +////////////////////////////////////////////////////////////// + +#include "wrapper.hpp" + +__host__ void jamcrc_wrapper(dim3 *grid, dim3 *threads, cudaStream_t *stream, const int device, const void *data, const uint64_t length, uint32_t *result, + const uint32_t previousCrc32) { + jamcrc_kernel_wrapper<<<*grid, *threads, device, *stream>>>(data, result, length, previousCrc32); +} + +__host__ uint32_t my::cuda::jamcrc(const void *data, const uint64_t length, const uint32_t previousCrc32, const uint32_t cuda_block_size) { + int device = 0; + cudaGetDevice(&device); + + cudaStream_t stream; + cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking); + + // Calculate length of the array with max_range and min_range + uint64_t data_size = (length) * sizeof(char); + uint32_t *data_cuda = nullptr; + + uint64_t result_size = 1 * sizeof(uint32_t); + uint32_t *result_cuda = nullptr; + + cudaMallocManaged(&data_cuda, data_size, cudaMemAttachGlobal); + cudaMallocManaged(&result_cuda, result_size, cudaMemAttachGlobal); + + cudaStreamAttachMemAsync(stream, &data_cuda); + cudaStreamAttachMemAsync(stream, &result_cuda); + + cudaMemPrefetchAsync(data_cuda, data_size, device, stream); + cudaMemPrefetchAsync(result_cuda, result_size, device, stream); + + memcpy(data_cuda, data, data_size); + *result_cuda = 0; + + uint64_t grid_size = static_cast(ceil(static_cast(1) / cuda_block_size)); + + dim3 threads(static_cast(cuda_block_size), 1, 1); + dim3 grid(static_cast(grid_size), 1, 1); + + jamcrc_kernel_wrapper<<>>(data_cuda, result_cuda, length, previousCrc32); + + cudaStreamSynchronize(stream); + cudaDeviceSynchronize(); + + // std::cout << "result_cuda: " << *result_cuda << std::endl; + + cudaFree(data_cuda); + cudaStreamDestroy(stream); + + return *result_cuda; +} + +__host__ void my::cuda::launch_kernel(std::vector &jamcrc_results, std::vector &index_results, const uint64_t min_range, + const uint64_t max_range, const uint64_t cuda_block_size) { + std::cout << "Launching kernel..." << std::endl; + std::cout << "min_range: " << std::dec << min_range << std::endl; + std::cout << "max_range: " << std::dec << max_range << std::endl; + // int device = -1; + // cudaGetDevice(&device); + + int device = 0; + cudaGetDevice(&device); + + /* + int priority_high, priority_low; + cudaDeviceGetStreamPriorityRange(&priority_low, &priority_high); + cudaStream_t st_high, st_low; + cudaStreamCreateWithPriority(&st_high, cudaStreamNonBlocking, priority_high); + cudaStreamCreateWithPriority(&st_low, cudaStreamNonBlocking, priority_low); + */ + + cudaStream_t stream; + cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking); + + // cudaDeviceSetLimit(cudaLimitMallocHeapSize, 128 * 1024 * 1024); + + // Calculate length of the array with max_range and min_range (Estimate size of the array) + uint64_t array_length = static_cast(((max_range - min_range) / 20'000'000) + 100); + uint64_t jamcrc_results_size = array_length * sizeof(uint32_t); + uint64_t index_results_size = array_length * sizeof(uint64_t); + + uint32_t *jamcrc_results_ptr = nullptr; + uint64_t *index_results_ptr = nullptr; + + uint32_t *array_index = nullptr; + + cudaMallocManaged(&jamcrc_results_ptr, jamcrc_results_size, cudaMemAttachGlobal); + cudaMallocManaged(&index_results_ptr, index_results_size, cudaMemAttachGlobal); + cudaMallocManaged(&array_index, 1 * sizeof(uint32_t), cudaMemAttachGlobal); + + cudaStreamAttachMemAsync(stream, &jamcrc_results_ptr); + cudaStreamAttachMemAsync(stream, &index_results_size); + cudaStreamAttachMemAsync(stream, &array_index); + + cudaMemPrefetchAsync(jamcrc_results_ptr, jamcrc_results_size, device, stream); + cudaMemPrefetchAsync(index_results_ptr, index_results_size, device, stream); + cudaMemPrefetchAsync(array_index, 1 * sizeof(uint32_t), device, stream); + + for (uint64_t i = 0; i < array_length; ++i) { + jamcrc_results_ptr[i] = 0; + index_results_ptr[i] = 0; + } + *array_index = 0; + + uint64_t grid_size = static_cast(ceil(static_cast(max_range - min_range) / cuda_block_size)); + std::cout << "CUDA Grid size: " << grid_size << std::endl; + std::cout << "CUDA Block size: " << cuda_block_size << std::endl; + + dim3 threads(static_cast(cuda_block_size), 1, 1); + dim3 grid(static_cast(grid_size), 1, 1); + + runner_kernel<<>>(jamcrc_results_ptr, index_results_ptr, array_length, array_index, min_range, max_range); + + jamcrc_results.reserve(array_length); + index_results.reserve(array_length); + + cudaStreamSynchronize(stream); + + for (uint64_t i = 0; i < *array_index; ++i) { + jamcrc_results.emplace_back(jamcrc_results_ptr[i]); + index_results.emplace_back(index_results_ptr[i]); + } + + cudaDeviceSynchronize(); + cudaFree(jamcrc_results_ptr); + cudaFree(index_results_ptr); + cudaFree(array_index); + + cudaStreamDestroy(stream); + // cudaStreamDestroy(st_high); + // cudaStreamDestroy(st_low); + + std::cout << "CUDA Kernel finished" << std::endl; +} diff --git a/source/cuda/wrapper.hpp b/source/gta_cheat_finder/cuda/wrapper.hpp old mode 100755 new mode 100644 similarity index 71% rename from source/cuda/wrapper.hpp rename to source/gta_cheat_finder/cuda/wrapper.hpp index f2e3c41..07f11fb --- a/source/cuda/wrapper.hpp +++ b/source/gta_cheat_finder/cuda/wrapper.hpp @@ -31,9 +31,9 @@ #define CUDA_KERNEL_HPP #if __has_include("cuda.h") -# ifndef BUILD_WITH_CUDA -# define BUILD_WITH_CUDA -# endif +#ifndef BUILD_WITH_CUDA +#define BUILD_WITH_CUDA +#endif #endif #include @@ -46,26 +46,13 @@ #include "kernel.cuh" -__host__ void jamcrc_wrapper(dim3& grid, - dim3& threads, - cudaStream_t& stream, - const int device, - const void* data, - const uint64_t length, - uint32_t* result, +__host__ void jamcrc_wrapper(dim3 &grid, dim3 &threads, cudaStream_t &stream, const int device, const void *data, const uint64_t length, uint32_t *result, const uint32_t previousCrc32); -namespace my::cuda -{ -__host__ uint32_t jamcrc(const void* data, - const uint64_t length, - const uint32_t previousCrc32, - const uint32_t cuda_block_size = 32); +namespace my::cuda { +__host__ uint32_t jamcrc(const void *data, const uint64_t length, const uint32_t previousCrc32, const uint32_t cuda_block_size = 32); -__host__ void launch_kernel(std::vector& jamcrc_results, - std::vector& index_results, - const uint64_t min_range, - const uint64_t max_range, +__host__ void launch_kernel(std::vector &jamcrc_results, std::vector &index_results, const uint64_t min_range, const uint64_t max_range, const uint64_t cuda_block_size); -} // namespace my::cuda +} // namespace my::cuda #endif \ No newline at end of file diff --git a/source/gta_cheat_finder/state/GTA_SA_cheat_finder_cuda.cpp b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_cuda.cpp new file mode 100644 index 0000000..fc68c71 --- /dev/null +++ b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_cuda.cpp @@ -0,0 +1,81 @@ +#include "GTA_SA_cheat_finder_cuda.hpp" + +GTA_SA_CUDA::GTA_SA_CUDA() {} + +GTA_SA_CUDA::~GTA_SA_CUDA() {} + +GTA_SA_CUDA >A_SA_CUDA::operator=(const GTA_SA_CUDA &other) { + if (this != &other) { + this->min_range = other.min_range; + this->max_range = other.max_range; + this->num_thread = other.num_thread; + this->cuda_block_size = other.cuda_block_size; + } + return *this; +} + +void GTA_SA_CUDA::run() { + std::cout << "Running with CUDA mode" << std::endl; + + std::cout << "Max thread support: " << GTA_SA_Virtual::max_thread_support() << std::endl; + std::cout << "Running with: " << num_thread << " threads" << std::endl; + + 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; + } + + if ((max_range - min_range) < 1) { + std::cout << "Search range is too small." << std::endl; + std::cout << "Min range value: '" << min_range << "' Max range value: '" << max_range << "'" << std::endl; + return; + } + + IsRunning = true; + + std::array tmp1 = {0}; + std::array tmp2 = {0}; + + results.reserve((max_range - min_range) / 20000000 + 1); + + std::cout << "Number of calculations: " << (max_range - min_range) << std::endl; + + this->find_string_inv(tmp1.data(), min_range); + this->find_string_inv(tmp2.data(), max_range); + std::cout << "From: " << tmp1.data() << " to: " << tmp2.data() << " Alphabetic sequence" << std::endl; + begin_time = std::chrono::high_resolution_clock::now(); + + runner(0); + end_time = std::chrono::high_resolution_clock::now(); + + 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) { + if ((max_range - min_range) < cuda_block_size) { + std::cout << "Number of calculations is less than cuda_block_size" << std::endl; + } + + std::vector jamcrc_results; + std::vector index_results; + + my::cuda::launch_kernel(jamcrc_results, index_results, min_range, max_range, cuda_block_size); + + for (uint64_t i = 0; i < jamcrc_results.size(); ++i) { + std::array tmpCUDA = {0}; + + this->find_string_inv(tmpCUDA.data(), index_results[i]); + std::reverse(tmpCUDA.data(), + tmpCUDA.data() + strlen(tmpCUDA.data())); // Invert char array + + const auto &&it = std::find(std::begin(GTA_SA_CUDA::cheat_list), std::end(GTA_SA_CUDA::cheat_list), jamcrc_results[i]); + + const uint64_t index = static_cast(it - std::begin(GTA_SA_CUDA::cheat_list)); + results.emplace_back(index_results[i], std::string(tmpCUDA.data()), jamcrc_results[i], + GTA_SA_Virtual::cheat_list_name.at(static_cast(index))); // Save result: calculation position, + // Alphabetic sequence, CRC, Cheat name + } +} diff --git a/source/gta_cheat_finder/state/GTA_SA_cheat_finder_cuda.hpp b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_cuda.hpp new file mode 100644 index 0000000..71ea2f1 --- /dev/null +++ b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_cuda.hpp @@ -0,0 +1,31 @@ +#ifndef GTA_SA_CUDA_HPP +#define GTA_SA_CUDA_HPP + +#include // std::find +#include // std::array +#include // std::chrono +#include // std::ceil +#include // strlen +#include // std::setw +#include // std::cout +#include // std::string +#include // std::string_view +#include // std::pair +#include // std::make_pair +#include // std::vector + +#include "GTA_SA_cheat_finder_virtual.hpp" + +class GTA_SA_CUDA final : public GTA_SA_Virtual { +public: + explicit GTA_SA_CUDA(); + ~GTA_SA_CUDA(); + + GTA_SA_CUDA &operator=(const GTA_SA_CUDA &other); + + void inline runner(const std::uint64_t i) override; + + void run() override; +}; + +#endif // GTA_SA_CUDA_HPP diff --git a/source/gta_cheat_finder/state/GTA_SA_cheat_finder_openmp.cpp b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_openmp.cpp new file mode 100644 index 0000000..02aa7e1 --- /dev/null +++ b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_openmp.cpp @@ -0,0 +1,89 @@ +#include "GTA_SA_cheat_finder_openmp.hpp" + +GTA_SA_OPENMP::GTA_SA_OPENMP() {} + +GTA_SA_OPENMP::~GTA_SA_OPENMP() {} + +GTA_SA_OPENMP >A_SA_OPENMP::operator=(const GTA_SA_OPENMP &other) { + if (this != &other) { + this->min_range = other.min_range; + this->max_range = other.max_range; + this->num_thread = other.num_thread; + this->cuda_block_size = other.cuda_block_size; + } + return *this; +} + +void GTA_SA_OPENMP::run() { + std::cout << "Running with OpenMP mode" << std::endl; + + std::cout << "Max thread support: " << GTA_SA_Virtual::max_thread_support() << std::endl; + std::cout << "Running with: " << num_thread << " threads" << std::endl; + + 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; + } + + if ((max_range - min_range) < 1) { + std::cout << "Search range is too small." << std::endl; + 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; + + IsRunning = true; + + std::array tmp1 = {0}; + std::array 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); + std::cout << "From: " << tmp1.data() << " to: " << tmp2.data() << " Alphabetic sequence" << std::endl; + begin_time = std::chrono::high_resolution_clock::now(); + + omp_set_num_threads(static_cast(num_thread)); + +#ifdef _MSC_VER + static std::int64_t i = 0; // OpenMP (2.0) on Windows doesn't support unsigned variable +#pragma omp parallel for shared(results) schedule(dynamic) + for (i = static_cast(min_range); i <= static_cast(max_range); i++) { + cpu_runner(static_cast(i)); + } +#else + std::uint64_t i = 0; +#pragma omp parallel for schedule(auto) shared(results) + for (i = min_range; i <= max_range; i++) { + runner(i); + } +#endif + + end_time = std::chrono::high_resolution_clock::now(); + + 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) { + std::array tmp = {0}; + this->find_string_inv(tmp.data(), + i); // Generate Alphabetic sequence from uint64_t + // value, A=1, Z=27, AA = 28, AB = 29 + const uint32_t crc = this->jamcrc(tmp.data()); // JAMCRC + const auto it = std::find(std::begin(GTA_SA_OPENMP::cheat_list), std::end(GTA_SA_OPENMP::cheat_list), crc); + + // If crc is present in Array + if (it != std::end(GTA_SA_OPENMP::cheat_list)) { + std::reverse(tmp.data(), + tmp.data() + strlen(tmp.data())); // Invert char array + + const uint64_t index = static_cast(it - std::begin(GTA_SA_OPENMP::cheat_list)); + results.emplace_back(i, std::string(tmp.data()), crc, + GTA_SA_Virtual::cheat_list_name.at(static_cast(index))); // Save result: calculation position, + // Alphabetic sequence, CRC, Cheat name + } +} diff --git a/source/gta_cheat_finder/state/GTA_SA_cheat_finder_openmp.hpp b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_openmp.hpp new file mode 100644 index 0000000..53d5ebd --- /dev/null +++ b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_openmp.hpp @@ -0,0 +1,36 @@ +#ifndef GTA_SA_OPENMP_HPP +#define GTA_SA_OPENMP_HPP + +#include // std::find +#include // std::array +#include // std::chrono +#include // std::ceil +#include // strlen +#include // std::setw +#include // std::cout +#include // std::string +#include // std::string_view +#include // std::pair +#include // std::make_pair +#include // std::vector + +#include "BS_thread_pool.hpp" +#include "GTA_SA_cheat_finder_virtual.hpp" + +#if __has_include("omp.h") +#include +#endif + +class GTA_SA_OPENMP final : public GTA_SA_Virtual { +public: + explicit GTA_SA_OPENMP(); + ~GTA_SA_OPENMP(); + + GTA_SA_OPENMP &operator=(const GTA_SA_OPENMP &other); + + void inline runner(const std::uint64_t i) override; + + void run() override; +}; + +#endif // GTA_SA_OPENMP_HPP diff --git a/source/gta_cheat_finder/state/GTA_SA_cheat_finder_stdthread.cpp b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_stdthread.cpp new file mode 100644 index 0000000..2a3beed --- /dev/null +++ b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_stdthread.cpp @@ -0,0 +1,81 @@ +#include "GTA_SA_cheat_finder_stdthread.hpp" + +GTA_SA_STDTHREAD::GTA_SA_STDTHREAD() {} + +GTA_SA_STDTHREAD::~GTA_SA_STDTHREAD() {} + +GTA_SA_STDTHREAD >A_SA_STDTHREAD::operator=(const GTA_SA_STDTHREAD &other) { + if (this != &other) { + this->min_range = other.min_range; + this->max_range = other.max_range; + this->num_thread = other.num_thread; + this->cuda_block_size = other.cuda_block_size; + } + return *this; +} + +void GTA_SA_STDTHREAD::run() { + std::cout << "Running with std::thread mode" << std::endl; + + std::cout << "Max thread support: " << GTA_SA_Virtual::max_thread_support() << std::endl; + std::cout << "Running with: " << num_thread << " threads" << std::endl; + + 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; + } + + if ((max_range - min_range) < 1) { + std::cout << "Search range is too small." << std::endl; + 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; + + IsRunning = true; + + std::array tmp1 = {0}; + std::array 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); + std::cout << "From: " << tmp1.data() << " to: " << tmp2.data() << " Alphabetic sequence" << std::endl; + begin_time = std::chrono::high_resolution_clock::now(); + + BS::thread_pool pool(num_thread); + + auto future = pool.parallelize_loop(min_range, max_range, [&](const std::uint64_t &_min_range, const std::uint64_t &_max_range) { + for (std::uint64_t i = _min_range; i <= _max_range; i++) { + runner(i); + } + }); + + future.wait(); + end_time = std::chrono::high_resolution_clock::now(); + + std::sort(results.begin(), results.end(), [](const result &a, const result &b) { return a.index < b.index; }); + + printResult(); + IsRunning = false; +} + +void GTA_SA_STDTHREAD::runner(const std::uint64_t i) { + std::array tmp = {0}; + this->find_string_inv(tmp.data(), i); // Generate Alphabetic sequence from uint64_t + // value, A=1, Z=27, AA = 28, AB = 29 + const uint32_t crc = this->jamcrc(tmp.data()); // JAMCRC + const auto it = std::find(std::begin(GTA_SA_STDTHREAD::cheat_list), std::end(GTA_SA_STDTHREAD::cheat_list), crc); + + // If crc is present in Array + if (it != std::end(GTA_SA_STDTHREAD::cheat_list)) { + std::reverse(tmp.data(), + tmp.data() + strlen(tmp.data())); // Invert char array + + const uint64_t index = static_cast(it - std::begin(GTA_SA_STDTHREAD::cheat_list)); + results.emplace_back(i, std::string(tmp.data()), crc, + GTA_SA_Virtual::cheat_list_name.at(static_cast(index))); // Save result: calculation position, + // Alphabetic sequence, CRC, Cheat name + } +} diff --git a/source/gta_cheat_finder/state/GTA_SA_cheat_finder_stdthread.hpp b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_stdthread.hpp new file mode 100644 index 0000000..8dd0d32 --- /dev/null +++ b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_stdthread.hpp @@ -0,0 +1,32 @@ +#ifndef GTA_SA_STDTHREAD_HPP +#define GTA_SA_STDTHREAD_HPP + +#include // std::find +#include // std::array +#include // std::chrono +#include // std::ceil +#include // strlen +#include // std::setw +#include // std::cout +#include // std::string +#include // std::string_view +#include // std::pair +#include // std::make_pair +#include // std::vector + +#include "BS_thread_pool.hpp" +#include "GTA_SA_cheat_finder_virtual.hpp" + +class GTA_SA_STDTHREAD final : public GTA_SA_Virtual { +public: + explicit GTA_SA_STDTHREAD(); + ~GTA_SA_STDTHREAD(); + + GTA_SA_STDTHREAD &operator=(const GTA_SA_STDTHREAD &other); + + void inline runner(const std::uint64_t i) override; + + void run() override; +}; + +#endif // GTA_SA_STDTHREAD_HPP diff --git a/source/gta_cheat_finder/state/GTA_SA_cheat_finder_virtual.cpp b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_virtual.cpp new file mode 100644 index 0000000..6b179f7 --- /dev/null +++ b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_virtual.cpp @@ -0,0 +1,71 @@ +#include "GTA_SA_cheat_finder_virtual.hpp" + +GTA_SA_Virtual::GTA_SA_Virtual() {} + +GTA_SA_Virtual::~GTA_SA_Virtual() {} + +/** + * @brief To get JAMCRC with boost libs + * @param my_string String input + * @return uint32_t with JAMCRC value + */ +auto GTA_SA_Virtual::jamcrc(std::string_view my_string, const uint32_t previousCrc32) const noexcept -> std::uint32_t { + auto crc = ~previousCrc32; + const uint8_t *current = reinterpret_cast(my_string.data()); + uint64_t length = my_string.length(); + // process eight bytes at once + while (static_cast(length--)) { + crc = (crc >> 8) ^ crc32_lookup[(crc & 0xFF) ^ *current++]; + } + return crc; +} + +/** + * \brief Generate Alphabetic sequence from uint64_t value, A=1, Z=27, AA = + * 28, AB = 29 \param n index in base 26 \param array return array + */ +void GTA_SA_Virtual::find_string_inv(char *array, uint64_t n) const noexcept { + // If n < 27 + if (n < 26) [[unlikely]] { + array[0] = alpha[static_cast(n)]; + return; + } + // If n > 27 + std::uint64_t i = 0; + while (n) { + array[i] = alpha[(--n) % 26]; + n /= 26; + ++i; + } +} + +void GTA_SA_Virtual::clear() { results.clear(); } + +uint32_t GTA_SA_Virtual::max_thread_support() { +#if defined(_OPENMP) + return static_cast(omp_get_max_threads()); +#else + return static_cast(std::thread::hardware_concurrency()); +#endif +} + +void GTA_SA_Virtual::printResult() const { + std::cout << "" << std::endl; + + constexpr auto display_val = 18; + + std::cout << std::setw(display_val + 3) << "Iter. N°" << std::setw(display_val) << "Code" << std::setw(display_val + 10) << "JAMCRC value" << std::setw(display_val + 5) + << "Associated code" << std::endl; + + for (auto &result : results) { + std::cout << std::setw(display_val + 2) << std::dec << result.index << std::setw(display_val + 5) << result.code << std::setw(display_val) << "0x" << std::hex + << result.jamcrc << std::setw(display_val) << result.associated_code << std::endl; + } + std::cout << "Time: " << std::chrono::duration_cast>(end_time - begin_time).count() << " sec" << std::endl; // Display time + + std::cout << "This program execute: " << std::fixed + << (static_cast(max_range - min_range) / std::chrono::duration_cast>(end_time - begin_time).count()) / 1000000 + << " MOps/sec" << std::endl; // Display perf + std::cout << "" << std::endl; + std::cout << "Number of results: " << std::dec << results.size() << std::endl; +} diff --git a/source/gta_cheat_finder/state/GTA_SA_cheat_finder_virtual.hpp b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_virtual.hpp new file mode 100644 index 0000000..a483242 --- /dev/null +++ b/source/gta_cheat_finder/state/GTA_SA_cheat_finder_virtual.hpp @@ -0,0 +1,234 @@ +#ifndef GTA_SA_VIRTUAL_HPP +#define GTA_SA_VIRTUAL_HPP + +#include // std::find +#include // std::array +#include // std::chrono +#include // std::ceil +#include // strlen +#include // std::setw +#include // std::cout +#include // std::string +#include // std::string_view +#include // std::pair +#include // std::make_pair +#include // std::vector + +#include "BS_thread_pool.hpp" + +#if __has_include("omp.h") +#include +#endif + +#if !defined(_OPENMP) +#if _MSC_VER && !__INTEL_COMPILER +#pragma message("No openMP ! Use std::thread.") +#else +#warning No openMP ! Use std::thread. +#endif +#endif + +#if __has_include("cuda.h") || __has_include("cuda_runtime.h") +#ifndef BUILD_WITH_CUDA +#define BUILD_WITH_CUDA +#endif +#endif + +#if defined(BUILD_WITH_CUDA) +#include "cuda/wrapper.hpp" +#endif + +#include "GTA_SA_cheat_finder_result.hpp" + +enum class COMPUTE_TYPE { STD_THREAD, OPENMP, CUDA, OPENCL }; + +class GTA_SA_Virtual { +protected: + explicit GTA_SA_Virtual(); + +public: + virtual ~GTA_SA_Virtual(); + + virtual void runner(const std::uint64_t i) = 0; + + virtual void run() = 0; + + virtual void clear(); + + virtual void printResult() const; + + /** + * @brief To get JAMCRC with boost libs + * @param my_string String input + * @return uint32_t with JAMCRC value + */ + auto jamcrc(std::string_view my_string, const uint32_t previousCrc32 = 0) const noexcept -> std::uint32_t; + + /** + * \brief Generate Alphabetic sequence from uint64_t value, A=1, Z=27, AA = + * 28, AB = 29 \param n index in base 26 \param array return array + */ + void find_string_inv(char *array, uint64_t n) const noexcept; + + static uint32_t max_thread_support(); + + uint32_t num_thread = GTA_SA_Virtual::max_thread_support(); + + static constexpr std::uint32_t string_size_alphabet{27}; + static constexpr std::array alpha{"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; + + std::array cheat_list{ + 0xDE4B237D, 0xB22A28D1, 0x5A783FAE, 0xEECCEA2B, 0x42AF1E28, 0x555FC201, 0x2A845345, 0xE1EF01EA, 0x771B83FC, 0x5BF12848, 0x44453A17, + 0xFCFF1D08, 0xB69E8532, 0x8B828076, 0xDD6ED9E9, 0xA290FD8C, 0x3484B5A7, 0x43DB914E, 0xDBC0DD65, 0xD08A30FE, 0x37BF1B4E, 0xB5D40866, + 0xE63B0D99, 0x675B8945, 0x4987D5EE, 0x2E8F84E8, 0x1A9AA3D6, 0xE842F3BC, 0x0D5C6A4E, 0x74D4FCB1, 0xB01D13B8, 0x66516EBC, 0x4B137E45, + 0x78520E33, 0x3A577325, 0xD4966D59, 0x5FD1B49D, 0xA7613F99, 0x1792D871, 0xCBC579DF, 0x4FEDCCFF, 0x44B34866, 0x2EF877DB, 0x2781E797, + 0x2BC1A045, 0xB2AFE368, 0xFA8DD45B, 0x8DED75BD, 0x1A5526BC, 0xA48A770B, 0xB07D3B32, 0x80C1E54B, 0x5DAD0087, 0x7F80B950, 0x6C0FA650, + 0xF46F2FA4, 0x70164385, 0x885D0B50, 0x151BDCB3, 0xADFA640A, 0xE57F96CE, 0x040CF761, 0xE1B33EB9, 0xFEDA77F7, 0x8CA870DD, 0x9A629401, + 0xF53EF5A5, 0xF2AA0C1D, 0xF36345A8, 0x8990D5E1, 0xB7013B1B, 0xCAEC94EE, 0x31F0C3CC, 0xB3B3E72A, 0xC25CDBFF, 0xD5CF4EFF, 0x680416B1, + 0xCF5FDA18, 0xF01286E9, 0xA841CC0A, 0x31EA09CF, 0xE958788A, 0x02C83A7C, 0xE49C3ED4, 0x171BA8CC, 0x86988DAE, 0x2BDD2FA1}; + + /// List of cheats codes names + std::array cheat_list_name{"Weapon Set 1", + "Weapon Set 2", + "Weapon Set 3", + "Health, Armor, $250k, Repairs car", + "Increase Wanted Level +2", + "Clear Wanted Level", + "Sunny Weather", + "Very Sunny Weather", + "Overcast Weather", + "Rainy Weather", + "Foggy Weather", + "Faster Clock", + "N°12", + "N°13", + "People attack each other with golf clubs", + "Have a bounty on your head", + "Everyone is armed", + "Spawn Rhino", + "Spawn Bloodring Banger", + "Spawn Rancher", + "Spawn Racecar", + "Spawn Racecar", + "Spawn Romero", + "Spawn Stretch", + "Spawn Trashmaster", + "Spawn Caddy", + "Blow Up All Cars", + "Invisible car", + "All green lights", + "Aggressive Drivers", + "Pink CArs", + "Black Cars", + "Fat Body", + "Muscular Body", + "Skinny Body", + "People attack with Rocket Launchers", + "N°41", + "N°42", + "Gangs Control the Streets", + "N°44", + "Slut Magnet", + "N°46", + "N°47", + "Cars Fly", + "N°49", + "N°50", + "Spawn Vortex Hovercraft", + "Smash n' Boom", + "N°53", + "N°54", + "N°55", + "Orange Sky", + "Thunderstorm", + "Sandstorm", + "N°59", + "N°60", + "Infinite Health", + "Infinite Oxygen", + "Have Parachute", + "N°64", + "Never Wanted", + "N°66", + "Mega Punch", + "Never Get Hungry", + "N°69", + "N°70", + "N°71", + "N°72", + "Full Weapon Aiming While Driving", + "N°74", + "Traffic is Country Vehicles", + "Recruit Anyone (9mm)", + "Get Born 2 Truck Outfit", + "N°78", + "N°79", + "N°80", + "L3 Bunny Hop", + "N°82", + "N°83", + "N°84", + "Spawn Quad", + "Spawn Tanker Truck", + "Spawn Dozer", + "pawn Stunt Plane", + "Spawn Monster"}; + + /** + * \brief Source: + * https://create.stephan-brumme.com/crc32/#slicing-by-8-overview + */ + + std::array crc32_lookup = { + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, + 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, + 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, + 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, + 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, + 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, + }; + + std::vector results = {}; + + std::chrono::high_resolution_clock::time_point begin_time = std::chrono::high_resolution_clock::now(); + + std::chrono::high_resolution_clock::time_point end_time = std::chrono::high_resolution_clock::now(); + + // Max 1024 threads per block with CUDA 2.0 and above + uint64_t cuda_block_size = 64; + +#if defined(_OPENMP) + static constexpr bool builtWithOpenMP = true; +#else + static constexpr bool builtWithOpenMP = false; +#endif + +#if defined(BUILD_WITH_CUDA) + static constexpr bool builtWithCUDA = true; +#else + static constexpr bool builtWithCUDA = false; +#endif + + uint64_t min_range = 0; // Alphabetic sequence range min + uint64_t max_range = 0; + + bool IsRunning = false; +}; + +#endif // GTA_SA_H diff --git a/source/gta_sa_ui.cpp b/source/gta_sa_ui.cpp index ab62ed1..738bcab 100644 --- a/source/gta_sa_ui.cpp +++ b/source/gta_sa_ui.cpp @@ -1,94 +1,168 @@ -#include "gta_sa_ui.h" +#include "gta_sa_ui.hpp" -GTA_SA_UI::GTA_SA_UI(QObject* parent) - : QObject {parent} -{ +GTA_SA_UI::GTA_SA_UI(std::unique_ptr& _gta_sa, QObject* parent) : QObject{parent}, selected_gta_sa{std::move(_gta_sa)} {} + +GTA_SA_UI::~GTA_SA_UI() { + for (auto& thread : threads) { + if (thread.joinable()) { + thread.join(); + } + } } +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; + } + -void GTA_SA_UI::setMinRangeValue(uint64_t value) -{ - std::cout << __FUNCTION_NAME__ << ": " << value << std::endl; - if (value == _minRangeValue) - return; - _minRangeValue = value; - // gta_sa.min_range = value; - emit minRangeValueChanged(value); + 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 (value == _maxRangeValue) - return; - _maxRangeValue = value; - // gta_sa.max_range = value; - emit maxRangeValueChanged(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 (value == _nbrThreadValue) - return; - _nbrThreadValue = value; - // gta_sa.num_thread = value; - emit nbrThreadValueChanged(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); } -void GTA_SA_UI::set_cuda_block_size(uint64_t value) -{ - std::cout << __FUNCTION_NAME__ << ": " << value << std::endl; - if (value == _cuda_block_size) - return; - _cuda_block_size = value; - // gta_sa.cuda_block_size = value; - emit cuda_block_size_changed(value); +void GTA_SA_UI::setButtonValue(QString value) { + std::cout << __FUNCTION_NAME__ << ": " << value.toStdString() << std::endl; + if (value == _buttonValue) + return; + _buttonValue = value; + emit buttonValueChanged(value); } -void GTA_SA_UI::setButtonValue(QString value) -{ - std::cout << __FUNCTION_NAME__ << ": " << value.toStdString() << std::endl; - if (value == _buttonValue) - return; - _buttonValue = value; - emit buttonValueChanged(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 tmp = nullptr; + + switch (value) { + case 0: { + std::cout << "Switching to STD_THREAD" << std::endl; + tmp = std::move(std::make_unique()); + break; + } + case 1: { + std::cout << "Switching to OPEN_MP" << std::endl; + tmp = std::move(std::make_unique()); + break; + } + case 2: { + std::cout << "Switching to CUDA" << std::endl; +#if defined(BUILD_WITH_CUDA) + tmp = std::move(std::make_unique()); +#else + std::cout << "CUDA not supported" << std::endl; +#endif + break; + } + case 3: { + std::cout << "Switching to OPENCL" << std::endl; + // tmp = std::move(std::make_unique()); + break; + } + default: { + std::cout << "Switching to STD_THREAD" << std::endl; + tmp = std::move(std::make_unique()); + break; + } + } + + if (tmp == nullptr) { + std::cout << "Error: Invalid or not implemented compute type:" << value << std::endl; + 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; + tmp->cuda_block_size = selected_gta_sa->cuda_block_size; + + this->selected_gta_sa = std::move(tmp); + + emit calc_mode_changed(value); } -void GTA_SA_UI::set_calc_mode(uint64_t value) -{ - std::cout << __FUNCTION_NAME__ << ": " << value << std::endl; - if (value == _calc_mode) - return; - _calc_mode = value; - // gta_sa.calc_mode = value; - emit calc_mode_changed(value); +uint64_t GTA_SA_UI::calc_mode() const { + if (typeid(*selected_gta_sa).hash_code() == typeid(GTA_SA_STDTHREAD).hash_code()) { + return 0; + } else if (typeid(*selected_gta_sa).hash_code() == typeid(GTA_SA_OPENMP).hash_code()) { + return 1; +#if defined(BUILD_WITH_CUDA) + } else if (typeid(*selected_gta_sa).hash_code() == typeid(GTA_SA_CUDA).hash_code()) { + return 2; +#endif + } else { + return 0; + } } -void GTA_SA_UI::runOpThread() -{ - std::cout << __FUNCTION_NAME__ << std::endl; - // Clear old data - this->gta_sa.clear(); - this->tableModel.clear(); - - // Launch operation - this->gta_sa.run(); - - // Store results in TableView Data - for (const auto& result : this->gta_sa.results) { - QVector vect = {QString::number(std::get<0>(result)), - QString::fromStdString(std::get<1>(result)), - QString("0x") + QString::number(std::get<2>(result), 16), - QString::fromStdString(std::get<3>(result))}; - this->tableModel.addPerson(vect); - } - this->setButtonValue(" Launch Bruteforce "); +void GTA_SA_UI::runOpThread() { + std::lock_guard lock(_mtx); + std::cout << __FUNCTION_NAME__ << std::endl; + // Clear old data + selected_gta_sa->clear(); + this->tableModel.clear(); + + // Launch operation + selected_gta_sa->run(); + + // Store results in TableView Data + for (const auto& result : selected_gta_sa->results) { + QVector vect = {QString::number(result.index), QString::fromStdString(result.code), + QString("0x") + QString::number(result.jamcrc, 16), QString::fromStdString(result.associated_code)}; + this->tableModel.addData(vect); + } + + this->setButtonValue(" Launch Bruteforce "); } -void GTA_SA_UI::runOp() -{ - this->setButtonValue("Bruteforce in progress"); - std::thread runner_thread(>A_SA_UI::runOpThread, this); - runner_thread.detach(); - // runner_thread.join(); +void GTA_SA_UI::runOp() { + this->setButtonValue("Bruteforce in progress"); + threads.emplace_back(>A_SA_UI::runOpThread, this); } diff --git a/source/gta_sa_ui.h b/source/gta_sa_ui.hpp similarity index 57% rename from source/gta_sa_ui.h rename to source/gta_sa_ui.hpp index fe70837..d70effd 100644 --- a/source/gta_sa_ui.h +++ b/source/gta_sa_ui.hpp @@ -5,15 +5,24 @@ #include #include #include +#include #include +#include #include -#include "GTA_SA_cheat_finder.hpp" -#include "qt-utils/TableModel.h" +#include "GTA_SA_cheat_finder_virtual.hpp" + +#ifdef BUILD_WITH_CUDA +#include "GTA_SA_cheat_finder_cuda.hpp" +#endif // BUILD_WITH_CUDA + +#include "GTA_SA_cheat_finder_openmp.hpp" +#include "GTA_SA_cheat_finder_stdthread.hpp" + +#include "tablemodel.h" #include "utils/utils.h" -class GTA_SA_UI : public QObject -{ +class GTA_SA_UI final : public QObject { Q_OBJECT Q_PROPERTY(uint64_t minRangeValue READ minRangeValue WRITE setMinRangeValue NOTIFY minRangeValueChanged) Q_PROPERTY(uint64_t maxRangeValue READ maxRangeValue WRITE setMaxRangeValue NOTIFY maxRangeValueChanged) @@ -29,34 +38,37 @@ class GTA_SA_UI : public QObject Q_PROPERTY(bool builtWithCUDA READ builtWithCUDA CONSTANT) public: - explicit GTA_SA_UI(QObject* parent = nullptr); + GTA_SA_UI(QObject *parent = nullptr) = delete; + explicit GTA_SA_UI(std::unique_ptr &_gta_sa, QObject *parent = nullptr); - GTA_SA gta_sa; - TableModel tableModel; + ~GTA_SA_UI(); - GETTERSETTER(GTA_SA, gta_sa, this->gta_sa) + std::unique_ptr selected_gta_sa; + TableModel tableModel; - uint64_t minRangeValue() const { return _minRangeValue; } - uint64_t maxRangeValue() const { return _maxRangeValue; } + uint64_t minRangeValue() const { return selected_gta_sa->min_range; } + uint64_t maxRangeValue() const { return selected_gta_sa->max_range; } - uint32_t nbrThreadValue() const { return _nbrThreadValue; } + uint32_t nbrThreadValue() const { return selected_gta_sa->num_thread; } - uint64_t cuda_block_size() const { return _cuda_block_size; } + uint64_t cuda_block_size() const { return selected_gta_sa->cuda_block_size; } - uint64_t calc_mode() const { return _calc_mode; } + uint64_t calc_mode() const; QString buttonValue() const { return _buttonValue; } + void set_gta_sa(std::unique_ptr &_gta_sa) { this->selected_gta_sa = std::move(_gta_sa); } + Q_INVOKABLE void runOp(); void runOpThread(); Q_INVOKABLE - uint64_t max_thread_support() { return gta_sa.max_thread_support(); } + uint64_t max_thread_support() { return GTA_SA_Virtual::max_thread_support(); } - bool builtWithOpenMP() const { return GTA_SA::builtWithOpenMP; } + bool builtWithOpenMP() const { return GTA_SA_Virtual::builtWithOpenMP; } - bool builtWithCUDA() const { return GTA_SA::builtWithCUDA; } + bool builtWithCUDA() const { return GTA_SA_Virtual::builtWithCUDA; } public slots: void setMinRangeValue(uint64_t value); @@ -80,12 +92,9 @@ public slots: void buttonValueChanged(QString value); private: - uint64_t& _minRangeValue = gta_sa.min_range; - uint64_t& _maxRangeValue = gta_sa.max_range; QString _buttonValue = "Launch Bruteforce"; - uint32_t& _nbrThreadValue = gta_sa.num_thread; - uint64_t& _cuda_block_size = gta_sa.cuda_block_size; - uint64_t& _calc_mode = gta_sa.calc_mode; + std::vector threads; + std::mutex _mtx; }; -#endif // GTA_SA_UI_H +#endif // GTA_SA_UI_H diff --git a/source/qt-utils/imageprovider/imageprovider.cpp b/source/imageprovider.cpp similarity index 53% rename from source/qt-utils/imageprovider/imageprovider.cpp rename to source/imageprovider.cpp index 88db5f8..dd57fa7 100644 --- a/source/qt-utils/imageprovider/imageprovider.cpp +++ b/source/imageprovider.cpp @@ -1,18 +1,15 @@ #include "imageprovider.h" -ImageProvider::ImageProvider() : QQuickImageProvider(QQuickImageProvider::Image, QQmlImageProviderBase::ForceAsynchronousImageLoading) -{ +ImageProvider::ImageProvider() : QQuickImageProvider(QQuickImageProvider::Image, QQmlImageProviderBase::ForceAsynchronousImageLoading) {} +QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) { + const QString file = "image/" + id; + QPixmap pixmap = QPixmap(file); + return pixmap; } -QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) -{ - QPixmap pixmap = QPixmap("/home/bensuperpc/Profile_400x400.jpg"); - return pixmap; -} - -QImage ImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) -{ - QImage image = QImage("/home/bensuperpc/Profile_400x400.jpg"); - return image; +QImage ImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { + const QString file = "image/" + id; + QImage image = QImage(file); + return image; } diff --git a/source/imageprovider.h b/source/imageprovider.h new file mode 100644 index 0000000..8a3a5aa --- /dev/null +++ b/source/imageprovider.h @@ -0,0 +1,15 @@ +#ifndef IMAGEPROVIDER_H +#define IMAGEPROVIDER_H + +#include +#include + +class ImageProvider final : public QQuickImageProvider { +public: + explicit ImageProvider(); + + QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override; + QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override; +}; + +#endif // IMAGEPROVIDER_H diff --git a/source/lineseries.cpp b/source/lineseries.cpp new file mode 100644 index 0000000..f07a37f --- /dev/null +++ b/source/lineseries.cpp @@ -0,0 +1,43 @@ +// Base on: https://code.qt.io/cgit/qt/qtcharts.git/tree/examples/charts/qmloscilloscope?h=6.4 + +#include "lineseries.h" + +LineSeries::LineSeries(QObject *parent) : QObject{parent}, m_index(-1) { generateData(16, 1024); } + +void LineSeries::update(QAbstractSeries *series) { + if (!series) { + return; + } + + m_index++; + + if (m_index > m_data.count() - 1) { + m_index = 0; + } + + QXYSeries *xySeries = static_cast(series); + + QList points = m_data.at(m_index); + + xySeries->replace(points); +} + +void LineSeries::generateData(const int rowCount, const int colCount) { + m_data.clear(); + + std::random_device rd; + std::seed_seq seed{rd(), rd()}; + std::mt19937_64 rng(seed); + std::uniform_real_distribution uni(0.0, 1.0); + + for (int i = 0; i < rowCount; i++) { + QList points; + points.reserve(colCount); + for (int i = 0; i < colCount; i++) { + const qreal x = i; + const qreal y = qSin(M_PI / 50 * i) + 0.5 + uni(rng); + points.append(QPointF(x, y)); + } + m_data.append(points); + } +} diff --git a/source/lineseries.h b/source/lineseries.h new file mode 100644 index 0000000..2b3c58a --- /dev/null +++ b/source/lineseries.h @@ -0,0 +1,33 @@ +// Base on: https://code.qt.io/cgit/qt/qtcharts.git/tree/examples/charts/qmloscilloscope?h=6.4 + +#ifndef LINESERIES_H +#define LINESERIES_H + +#include +#include +#include +#include +#include +#include + +#include + +class LineSeries : public QObject { + Q_OBJECT +public: + explicit LineSeries(QObject *parent = nullptr); + +signals: + +public slots: + // Q_INVOKABLE + void generateData(const int rowCount, const int colCount); + // Q_INVOKABLE + void update(QAbstractSeries *series); + +private: + QList> m_data; + int m_index; +}; + +#endif // LINESERIES_H diff --git a/source/main.cpp b/source/main.cpp index bd282b4..1b3a199 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,36 +1,37 @@ -#if __has_include() -# include -# include -# include -# include -# include -#endif - -#include -#include -#include -#include -#include - -#include "GTA_SA_cheat_finder.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "application.h" +#include "asyncimageprovider.h" +#include "customlabel.h" +#include "imageprovider.h" +#include "lineseries.h" +#include "tablemodel.h" +#include "utils/utils.h" #if __has_include() -# include "about_compilation.h" -# include "gta_sa_ui.h" -# include "TableModel.h" -#include "imageprovider/imageprovider.h" -#include "asyncimageprovider/asyncimageprovider.h" +#include "gta_sa_ui.hpp" #endif -auto main(int argc, char* argv[]) -> int -{ +int main(int argc, char *argv[]) { bool cli_only = false; - GTA_SA gta_sa; - std::ios_base::sync_with_stdio(false); // Improve std::cout speed + std::ios_base::sync_with_stdio(false); // Improve std::cout speed std::vector args(argv + 1, argv + argc); + uint64_t calc_mode = 0; + uint64_t min_range = 0; + uint64_t max_range = 0; + for (auto i = args.begin(); i != args.end(); ++i) { if (*i == "-h" || *i == "--help") { std::cout << "Syntax: GTA_SA_cheat_finder --min --max " @@ -41,19 +42,19 @@ auto main(int argc, char* argv[]) -> int } if (*i == "--min") { std::istringstream iss(*++i); - if (!(iss >> gta_sa.min_range)) { + if (!(iss >> min_range)) { std::cout << "Error, non-numeric character !" << std::endl; return EXIT_FAILURE; } } else if (*i == "--max") { std::istringstream iss(*++i); - if (!(iss >> gta_sa.max_range)) { + if (!(iss >> max_range)) { std::cout << "Error, non-numeric character !" << std::endl; return EXIT_FAILURE; } } else if (*i == "--calc-mode") { std::istringstream iss(*++i); - if (!(iss >> gta_sa.calc_mode)) { + if (!(iss >> calc_mode)) { std::cout << "Error, non-numeric character !" << std::endl; return EXIT_FAILURE; } @@ -64,69 +65,98 @@ auto main(int argc, char* argv[]) -> int } } - // gta_sa.num_thread - // gta_sa.min_range - // gta_sa.max_range - // gta_sa.num_thread - // gta_sa.cuda_block_size - // gta_sa.calc_mode + std::unique_ptr gta_sa; + + switch (calc_mode) { + case 0: { + gta_sa = std::move(std::make_unique()); + break; + } + case 1: { + gta_sa = std::move(std::make_unique()); + break; + } + case 2: { +#ifdef BUILD_WITH_CUDA + gta_sa = std::move(std::make_unique()); +#else + std::cout << "CUDA not supported" << std::endl; +#endif + break; + } + default: { + gta_sa = std::move(std::make_unique()); + break; + } + } + + if (gta_sa == nullptr) { + std::cout << "Error, gta_sa == nullptr" << std::endl; + return EXIT_FAILURE; + } + + // gta_sa->num_thread + // gta_sa->cuda_block_size #if __has_include() if (cli_only == false) { /* - QDirIterator it(":", QDirIterator::Subdirectories); - while (it.hasNext()) { - qDebug() << it.next(); + QString home = qEnvironmentVariable("HOME"); + + if (!home.isNull()) { + qDebug() << "HOME: " << home; + } + + for (auto& item : QSerialPortInfo::availablePorts()) { + qDebug() << item.portName(); } */ - QGuiApplication app(argc, argv); + // QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL); + QApplication app(argc, argv); app.setOrganizationName("GTA_SA_Cheat_Finder"); app.setOrganizationDomain("GTA_SA_Cheat_Finder"); app.setApplicationName("GTA_SA_Cheat_Finder"); app.setApplicationVersion("0.1.0"); - /* - const QStringList args = QCoreApplication::arguments(); - - for (auto i = 0; i < args.size(); ++i) { - std::cout << args[i].toStdString() << std::endl; - } - */ - - // Initialize BEFORE class instance + QQuickStyle::setStyle("Material"); + QQuickStyle::setFallbackStyle("Material"); QQmlApplicationEngine engine; - about_compilation ab; - GTA_SA_UI gta_sa_ui; - gta_sa_ui.set_gta_sa(gta_sa); + GTA_SA_UI gta_sa_ui(gta_sa); - qmlRegisterSingletonType("org.bensuperpc.GTA_SAObjects", - 1, - 0, - "GTA_SASingleton", - [&](QQmlEngine*, QJSEngine*) -> QObject* { return >a_sa_ui; }); + qmlRegisterSingletonType("org.bensuperpc.GTA_SAObjects", 1, 0, "GTA_SASingleton", + [&](QQmlEngine *, QJSEngine *) -> QObject * { return >a_sa_ui; }); // import org.bensuperpc.GTA_SAObjects 1.0 qmlRegisterType("org.bensuperpc.GTA_SAObjectType", 1, 0, "GTA_SAType"); // import org.bensuperpc.GTA_SAObjectType 1.0 - qmlRegisterSingletonType("org.bensuperpc.TableModelObjects", - 1, - 0, - "TableModelObjects", - [&](QQmlEngine*, QJSEngine*) -> QObject* { return >a_sa_ui.tableModel; }); - // import org.bensuperpc.TableModelObjects 1.0 + application app_ui; + QMLREGISTERSINGLETONTYPE(app_ui, "org.bensuperpc.application", 1, 0, "AppSingleton") - qmlRegisterSingletonInstance("org.bensuperpc.ABCObjects", 1, 0, "ABCObjects", &ab); + TableModel tablemodel; + QMLREGISTERSINGLETONTYPE(tablemodel, "org.bensuperpc.TableData", 1, 0, "TableDataModel") + + engine.addImageProvider(QLatin1String("sync"), new ImageProvider); + engine.addImageProvider("async", new AsyncImageProvider); + + LineSeries uiData; + QMLREGISTERSINGLETONTYPE(uiData, "org.bensuperpc.lineseries", 1, 0, "UIData") + + QStringList monModele; + for (int i = 0; i < 10; i++) { + monModele.append("Data " + QString::number(i)); + } + engine.rootContext()->setContextProperty("monModele", QVariant::fromValue(monModele)); + + qmlRegisterType("org.bensuperpc.MyLabelLib", 1, 0, "MyLabel"); + + const QUrl url(u"qrc:/bensuperpc.fr/bensuperpc/qml/main.qml"_qs); - const QUrl url(u"qrc:/bensuperpc.com/qml_files/source/qml/main.qml"_qs); QObject::connect( - &engine, - &QQmlApplicationEngine::objectCreated, - &app, - [url](QObject* obj, const QUrl& objUrl) - { + &engine, &QQmlApplicationEngine::objectCreated, &app, + [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, @@ -137,12 +167,10 @@ auto main(int argc, char* argv[]) -> int } #endif - // CLI only or no Qt - // Launch operation - gta_sa.run(); + gta_sa->run(); // Clear old data - // gta_sa.clear(); + // gta_sa->clear(); return 0; } diff --git a/source/qml/AboutPage.qml b/source/qml/AboutPage.qml deleted file mode 100644 index f83d806..0000000 --- a/source/qml/AboutPage.qml +++ /dev/null @@ -1,290 +0,0 @@ -import QtQuick -import QtQuick.Window -import QtQuick.Layouts -import QtQuick.Controls -import QtQuick.Controls.Material - -import org.bensuperpc.ABCObjects 1.0 - -Page { - title: qsTr("About Page") - id: page - - GridLayout { - anchors.fill: parent - anchors.margins: 5 - columns: 12 - rows: 12 - - component ProportionalRect: Rectangle { - Layout.fillHeight: true - Layout.fillWidth: true - Layout.preferredWidth: Layout.columnSpan - Layout.preferredHeight: Layout.rowSpan - color: "transparent" - } - - ProportionalRect { - Layout.columnSpan: 12 - Layout.rowSpan: 3 - - GridLayout { - anchors.fill: parent - anchors.margins: 5 - columns: 3 - rows: 1 - - ProportionalRect { - Layout.columnSpan: 1 - Layout.rowSpan: 1 - - GroupBox { - title: qsTr("App and Compiler") - anchors.fill: parent - Column { - Text { - text: qsTr("Compiler: " + ABCObjects.return_Compiler_name( - )) - color: "white" - font.bold: true - fontSizeMode: Text.Fit - minimumPixelSize: 5 - font.pixelSize: 12 - } - - Text { - text: qsTr("Compiler vers: " + ABCObjects.return_Compiler_version( - )) - color: "white" - font.bold: true - fontSizeMode: Text.Fit - minimumPixelSize: 5 - font.pixelSize: 12 - } - - Text { - text: qsTr("C++ version: " + ABCObjects.return_Cplusplus_used( - )) - color: "white" - font.bold: true - fontSizeMode: Text.Fit - minimumPixelSize: 5 - font.pixelSize: 12 - } - Text { - text: qsTr("Build: " + ABCObjects.return_BuildDate()) - color: "white" - font.bold: true - fontSizeMode: Text.Fit - minimumPixelSize: 5 - font.pixelSize: 12 - } - } - } - } - - ProportionalRect { - Layout.columnSpan: 1 - Layout.rowSpan: 1 - - GroupBox { - title: qsTr("Libs") - anchors.fill: parent - Column { - Text { - text: qsTr("Qt version: " + qtversion) - color: "white" - font.bold: true - fontSizeMode: Text.Fit - minimumPixelSize: 5 - font.pixelSize: 12 - } - - Text { - text: qsTr("OpenMP: " + ABCObjects.openmpIsEnable()) - color: "white" - font.bold: true - fontSizeMode: Text.Fit - minimumPixelSize: 5 - font.pixelSize: 12 - } - - Text { - text: qsTr("Nvidia CUDA: " + ABCObjects.cudaIsEnable()) - color: "white" - font.bold: true - fontSizeMode: Text.Fit - minimumPixelSize: 5 - font.pixelSize: 12 - } - - Text { - text: qsTr("OpenCL: " + ABCObjects.openclIsEnable()) - color: "white" - font.bold: true - fontSizeMode: Text.Fit - minimumPixelSize: 5 - font.pixelSize: 12 - } - } - } - } - - ProportionalRect { - Layout.columnSpan: 1 - Layout.rowSpan: 1 - - GroupBox { - title: qsTr("About this app") - anchors.fill: parent - - Column { - Text { - text: qsTr("Created by: Bensuperpc") - color: "white" - font.bold: true - fontSizeMode: Text.Fit - minimumPixelSize: 5 - font.pixelSize: 12 - wrapMode: Text.WordWrap - onLinkActivated: Qt.openUrlExternally(link) - - MouseArea { - anchors.fill: parent - acceptedButtons: Qt.NoButton - cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor - } - } - Text { - text: "Source: Click here" - color: "white" - font.bold: true - fontSizeMode: Text.Fit - minimumPixelSize: 5 - font.pixelSize: 12 - wrapMode: Text.WordWrap - onLinkActivated: Qt.openUrlExternally(link) - - MouseArea { - anchors.fill: parent - acceptedButtons: Qt.NoButton - cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor - } - } - } - } - } - } - } - - ProportionalRect { - Layout.columnSpan: 12 - Layout.rowSpan: 3 - - // 2 columns inside second row - GridLayout { - anchors.fill: parent - anchors.margins: 5 - columns: 2 - rows: 1 - - ProportionalRect { - Layout.columnSpan: 1 - Layout.rowSpan: 1 - Image { - source: Qt.resolvedUrl( - "/bensuperpc.com/qml_files/img/Profile_400x400.jpg") - anchors.fill: parent - sourceSize.width: parent.width - sourceSize.height: parent.height - } - } - - ProportionalRect { - Layout.columnSpan: 1 - Layout.rowSpan: 1 - Text { - color: "white" - font.bold: true - fontSizeMode: Text.Fit - minimumPixelSize: 5 - font.pixelSize: 12 - wrapMode: Text.WordWrap - text: "I'm Bensuperpc" - } - } - } - } - - ProportionalRect { - Layout.columnSpan: 12 - Layout.rowSpan: 3 - color: "blue" - - // 1 column inside third row - GridLayout { - anchors.fill: parent - anchors.margins: 5 - columns: 1 - rows: 1 - - ProportionalRect { - Layout.columnSpan: 1 - Layout.rowSpan: 1 - color: "red" - } - } - } - - ProportionalRect { - Layout.columnSpan: 12 - Layout.rowSpan: 3 - color: "yellow" - - // 3 columns inside fourth row - GridLayout { - anchors.fill: parent - anchors.margins: 5 - columns: 3 - rows: 1 - - ProportionalRect { - Layout.columnSpan: 1 - Layout.rowSpan: 1 - color: "red" - } - - ProportionalRect { - Layout.columnSpan: 1 - Layout.rowSpan: 1 - color: "green" - } - - ProportionalRect { - Layout.columnSpan: 1 - Layout.rowSpan: 1 - color: "blue" - } - } - } - - /* - ProportionalRect { - Layout.columnSpan: 5 - Layout.rowSpan: 5 - GroupBox { - title: qsTr("Test") - // Layout.alignment: Qt.AlignHCenter - anchors.fill: parent - Image { - source: Qt.resolvedUrl( - "/bensuperpc.com/qml_files/img/Profile_400x400.jpg") - anchors.fill: parent - sourceSize.width: parent.width - sourceSize.height: parent.height - } - } - } - */ - } -} diff --git a/source/qml/main.qml b/source/qml/main.qml deleted file mode 100644 index 7276517..0000000 --- a/source/qml/main.qml +++ /dev/null @@ -1,261 +0,0 @@ -import QtQuick -import QtQuick.Controls -import QtQuick.Controls.Material -import QtQuick.Layouts -import QtQuick.Window - -ApplicationWindow { - property bool isOpened: false - property bool inPortrait: window.width < window.height - - //Material.theme: Material.Dark - //Material.primary: Material.Amber - Material.theme: "Dark" - Material.primary: "Amber" - Material.accent: "Teal" - - id: window - - visible: true - width: 720 - height: 1280 - //minimumWidth: 720 - //minimumHeight: 1280 - - // title: qsTr("GTA SA alt. cheats finder") - - header: ToolBar { - id: toolbar - RowLayout { - anchors.fill: parent - ToolButton { - id: toolButton1 - text: { - qsTr(stackView.depth > 1 ? "<" : "\u2630") - } - font.bold: true - antialiasing: true - onClicked: { - if (stackView.depth > 1) { - stackView.pop() - } else { - drawer.open() - } - } - } - Label { - id: title_label - text: stackView.currentItem.title - elide: Label.ElideRight - horizontalAlignment: Qt.AlignHCenter - verticalAlignment: Qt.AlignVCenter - Layout.fillWidth: true - } - ToolButton { - text: qsTr("⋮") - font.bold: true - antialiasing: true - onClicked: menu.open() - } - } - } - - Menu { - id: menu - x: window.width - width: window.width * 0.37 - // transformOrigin: Menu.TopRight - MenuItem { - id: quit - text: "Quit" - onTriggered: { - console.log("onTriggered " + quit.text) - Qt.quit() - } - } - MenuItem { - width: parent.width - height: children[0].height - enabled: false - MenuSeparator { - width: parent.width - } - } - - MenuItem { - id: help - text: "Help" - onTriggered: { - console.log("onTriggered " + help.text) - aPropos.open() - } - } - MenuItem { - id: about - text: "About" - onTriggered: { - console.log("onTriggered " + about.text) - stackView.push("AboutPage.qml") - } - } - } - - - - Dialog { - id: aPropos - modal: true - focus: true - title: "About" - x: (window.width - width) / 2 - y: window.height / 6 - width: Math.min(window.width, window.height) / 3 * 2 - contentHeight: message.height - Label { - id: message - width: aPropos.availableWidth - text: "Application built with Qt quick." - wrapMode: Label.Wrap - font.pixelSize: 12 - } - } - - Drawer { - id: drawer - - //In portrait mode - //y: toolbar.height - - //!inPortrait ? idContentColumn.height : idContentColumn.width - //y: inPortrait ? toolbar.height : toolbar.width - - // width: window.width * 0.66 - // height: window.height - - //dragMargin: window.height * 0.1 - width: window.width * 0.6 - height: window.height - - // dragMargin: window.height * 0.03 - onOpened: { - console.log("drawer onOpened") - isOpened = true - } - onClosed: { - console.log("drawer onClosed") - isOpened = false - } - - Flickable { - //Fix issue with wrong Flickable size in !inPortrait - // contentHeight: !inPortrait ? idContentColumn.height : idContentColumn.width - anchors.fill: parent - clip: true - Column { - width: parent.width - height: parent.height - id: idContentColumn - ItemDelegate { - text: qsTr("MainPage") - width: parent.width - onClicked: { - if (stackView.depth > 1) { - stackView.push("GTA_SA.qml") - drawer.close() - } else { - drawer.close() - // To remove later - stackView.push("GTA_SA.qml") - } - } - } - ItemDelegate { - width: parent.width - height: menu_separator.height - anchors.horizontalCenter: parent.horizontalCenter - enabled: false - MenuSeparator { - id: menu_separator - width: parent.width - anchors.horizontalCenter: parent.horizontalCenter - } - } - ItemDelegate { - text: qsTr("GTA_SA") - width: parent.width - onClicked: { - stackView.push("GTA_SA.qml") - drawer.close() - } - } - ItemDelegate { - width: parent.width - height: menu_separator1.height - anchors.horizontalCenter: parent.horizontalCenter - enabled: false - MenuSeparator { - id: menu_separator1 - width: parent.width - anchors.horizontalCenter: parent.horizontalCenter - } - } - ItemDelegate { - id: choix4 - text: qsTr("About") - width: parent.width - onClicked: { - console.log("onClicked " + choix4.text) - stackView.push("AboutPage.qml") - drawer.close() - } - } - } - } - } - - StackView { - id: stackView - initialItem: "GTA_SA.qml" - anchors.fill: parent - //width: parent.width - //height: parent.height - - // anchors.centerIn: parent - pushEnter: Transition { - PropertyAnimation { - property: "opacity" - from: 0 - to: 1 - duration: 200 - } - } - pushExit: Transition { - PropertyAnimation { - property: "opacity" - from: 1 - to: 0 - duration: 200 - } - } - popEnter: Transition { - PropertyAnimation { - property: "opacity" - from: 0 - to: 1 - duration: 200 - } - } - popExit: Transition { - PropertyAnimation { - property: "opacity" - from: 1 - to: 0 - duration: 200 - } - } - } - - Component.onDestruction: { - console.log("Closing app...") - } -} diff --git a/source/qt-utils/TableModel.cpp b/source/qt-utils/TableModel.cpp deleted file mode 100644 index 89f2948..0000000 --- a/source/qt-utils/TableModel.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "TableModel.h" - -TableModel::TableModel(QObject* parent) - : QAbstractTableModel(parent) -{ - this->init(); -} - -void TableModel::clear() -{ - this->table.clear(); - this->table.shrink_to_fit(); - this->init(); -} - -void TableModel::init() -{ - QVector vect = {"Iter. N°", "Code", "JAMCRC value", "GTA Code"}; - this->addPerson(vect); -} - -QVariant TableModel::data(const QModelIndex& index, int role) const -{ - switch (role) { - case TableDataRole: { - return table.at(index.row()).at(index.column()); - } - case HeadingRole: { - return index.row() == 0; - } - default: - break; - } - return QVariant(); -} - -QHash TableModel::roleNames() const -{ - QHash roles; - roles[TableDataRole] = "tabledata"; - roles[HeadingRole] = "heading"; - return roles; -} - -void TableModel::addPerson(const QVector& vect) -{ - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - table.append(vect); - endInsertRows(); -} - -void TableModel::addPerson(const std::vector& vect) -{ - beginInsertRows(QModelIndex(), rowCount(), rowCount()); -#if QT_VERSION <= QT_VERSION_CHECK(5, 14, 0) - table.append(QVector::fromStdVector(vect)); -#else - table.append(QVector(vect.begin(), vect.end())); -#endif - endInsertRows(); -} \ No newline at end of file diff --git a/source/qt-utils/TableModel.h b/source/qt-utils/TableModel.h deleted file mode 100644 index 0eea8ce..0000000 --- a/source/qt-utils/TableModel.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include - -class TableModel : public QAbstractTableModel -{ - Q_OBJECT - enum TableRoles - { - TableDataRole = Qt::UserRole + 1, - HeadingRole - }; - -public: - explicit TableModel(QObject* parent = nullptr); - - void clear(); - - void init(); - - int rowCount(const QModelIndex& = QModelIndex()) const override { return static_cast(table.size()); } - - int columnCount(const QModelIndex& = QModelIndex()) const override { return static_cast(table.at(0).size()); } - - QVariant data(const QModelIndex& index, int role) const override; - - QHash roleNames() const override; - - Q_INVOKABLE void addPerson(const QVector& vect); - - Q_INVOKABLE void addPerson(const std::vector& vect); - -private: - QVector> table; -}; diff --git a/source/qt-utils/asyncimageprovider/async_image_response.h b/source/qt-utils/asyncimageprovider/async_image_response.h deleted file mode 100644 index 04979f9..0000000 --- a/source/qt-utils/asyncimageprovider/async_image_response.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef ASYNCIMAGEPROVIDER_ASYNC_IMAGE_RESPONSE_H -#define ASYNCIMAGEPROVIDER_ASYNC_IMAGE_RESPONSE_H - -#include -#include -#include -#include -#include - -#include "async_image_response_runnable.h" - -class AsyncImageResponse : public QQuickImageResponse -{ -public: - AsyncImageResponse(const QString &id, const QSize &requestedSize, QThreadPool *pool) - { - auto runnable = new AsyncImageResponseRunnable(id, requestedSize); - connect(runnable, &AsyncImageResponseRunnable::done, this, &AsyncImageResponse::handleDone); - pool->start(runnable); - } - - void handleDone(QImage image) { - m_image = image; - emit finished(); - } - - QQuickTextureFactory *textureFactory() const override - { - return QQuickTextureFactory::textureFactoryForImage(m_image); - } - - QImage m_image; -}; - -#endif // ASYNCIMAGEPROVIDER_ASYNC_IMAGE_RESPONSE_RUNNABLE_H \ No newline at end of file diff --git a/source/qt-utils/asyncimageprovider/async_image_response_runnable.h b/source/qt-utils/asyncimageprovider/async_image_response_runnable.h deleted file mode 100644 index 85b1ad2..0000000 --- a/source/qt-utils/asyncimageprovider/async_image_response_runnable.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef ASYNCIMAGEPROVIDER_ASYNC_IMAGE_RESPONSE_RUNNABLE_H -#define ASYNCIMAGEPROVIDER_ASYNC_IMAGE_RESPONSE_RUNNABLE_H - -#include -#include -#include -#include -#include - -class AsyncImageResponseRunnable : public QObject, public QRunnable -{ - Q_OBJECT - -signals: - void done(QImage image); - -public: - AsyncImageResponseRunnable(const QString &id, const QSize &requestedSize) - : m_id(id), m_requestedSize(requestedSize) {} - - void run() override - { - if (m_id == QLatin1String("slow")) { - qDebug() << "Slow, red, sleeping for 5 seconds"; - QThread::sleep(5); - } else { - qDebug() << "Fast, blue, sleeping for 1 second"; - QThread::sleep(1); - } - QImage image = QImage("/home/bedem/Profile_400x400.jpg"); - - if (m_requestedSize.isValid()) - image = image.scaled(m_requestedSize); - - emit done(image); - } - -private: - QString m_id; - QSize m_requestedSize; -}; - -#endif // ASYNCIMAGEPROVIDER_H \ No newline at end of file diff --git a/source/qt-utils/asyncimageprovider/asyncimageprovider.h b/source/qt-utils/asyncimageprovider/asyncimageprovider.h deleted file mode 100644 index 701908b..0000000 --- a/source/qt-utils/asyncimageprovider/asyncimageprovider.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef ASYNCIMAGEPROVIDER_H -#define ASYNCIMAGEPROVIDER_H - -#include -#include -#include -#include -#include - -#include "async_image_response_runnable.h" -#include "async_image_response.h" - -class AsyncImageProvider : public QQuickAsyncImageProvider -{ -public: - QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override - { - AsyncImageResponse *response = new AsyncImageResponse(id, requestedSize, &pool); - return response; - } - -private: - QThreadPool pool; -}; - - -#endif // ASYNCIMAGEPROVIDER_H diff --git a/source/qt-utils/imageprovider/imageprovider.h b/source/qt-utils/imageprovider/imageprovider.h deleted file mode 100644 index e22b557..0000000 --- a/source/qt-utils/imageprovider/imageprovider.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef IMAGEPROVIDER_H -#define IMAGEPROVIDER_H - -#include - -#include - -class ImageProvider : public QQuickImageProvider -{ -public: - ImageProvider(); - - QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override; - QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override; -}; - -#endif // IMAGEPROVIDER_H diff --git a/source/tablemodel.cpp b/source/tablemodel.cpp new file mode 100644 index 0000000..549b35e --- /dev/null +++ b/source/tablemodel.cpp @@ -0,0 +1,52 @@ +#include "tablemodel.h" + +TableModel::TableModel(QObject *parent) : QAbstractTableModel(parent) { + QVector header = {"col0", "col1", "col2", "col3"}; + this->init(header); + QVector data = {"data0", "data1", "data2", "data3"}; + this->addData(data); + data = {"data4", "data5", "data6", "data7"}; + this->addData(data); +} + +void TableModel::clear() { + this->table.clear(); + this->table.shrink_to_fit(); +} + +void TableModel::init(const QVector &vect) { this->addData(vect); } + +QVariant TableModel::data(const QModelIndex &index, int role) const { + switch (role) { + [[likely]] case TableDataRole : { return table.at(index.row()).at(index.column()); } + case HeadingRole: { + return index.row() == 0; + } + [[unlikely]] default : break; + } + return QVariant(); +} + +QHash TableModel::roleNames() const { + QHash roles; + roles[TableDataRole] = "tabledata"; + roles[HeadingRole] = "heading"; + return roles; +} + +void TableModel::addData(const QVector &vect) { + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + // if (vect.size() != table + table.append(vect); + endInsertRows(); +} + +void TableModel::addData(const std::vector &vect) { + beginInsertRows(QModelIndex(), rowCount(), rowCount()); +#if QT_VERSION <= QT_VERSION_CHECK(5, 14, 0) + table.append(QVector::fromStdVector(vect)); +#else + table.append(QVector(vect.begin(), vect.end())); +#endif + endInsertRows(); +} diff --git a/source/tablemodel.h b/source/tablemodel.h new file mode 100644 index 0000000..38a4d5c --- /dev/null +++ b/source/tablemodel.h @@ -0,0 +1,36 @@ +#ifndef TABLEMODEL_H +#define TABLEMODEL_H + +#include +#include + +class TableModel : public QAbstractTableModel { + Q_OBJECT + enum TableRoles { TableDataRole = Qt::UserRole + 1, HeadingRole }; + +public: + explicit TableModel(QObject *parent = nullptr); + + void clear(); + + void init(const QVector &vect); + + Q_INVOKABLE + int rowCount(const QModelIndex & = QModelIndex()) const override { return static_cast(table.size()); } + + Q_INVOKABLE + int columnCount(const QModelIndex & = QModelIndex()) const override { return static_cast(table.at(0).size()); } + + QVariant data(const QModelIndex &index, int role) const override; + + QHash roleNames() const override; + + Q_INVOKABLE void addData(const QVector &vect); + + Q_INVOKABLE void addData(const std::vector &vect); + +private: + QVector> table; +}; + +#endif diff --git a/source/utils/CMakeLists.txt b/source/utils/CMakeLists.txt deleted file mode 100644 index dd6ea57..0000000 --- a/source/utils/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -############################################################## -# ____ # -# | __ ) ___ _ __ ___ _ _ _ __ ___ _ __ _ __ ___ # -# | _ \ / _ \ '_ \/ __| | | | '_ \ / _ \ '__| '_ \ / __| # -# | |_) | __/ | | \__ \ |_| | |_) | __/ | | |_) | (__ # -# |____/ \___|_| |_|___/\__,_| .__/ \___|_| | .__/ \___| # -# |_| |_| # -############################################################## -# # -# BenLib, 2021 # -# Created: 16, March, 2021 # -# Modified: 17, March, 2021 # -# file: CMakeLists.txt # -# CMake # -# Source: # -# OS: ALL # -# CPU: ALL # -# # -############################################################## - -cmake_minimum_required(VERSION 3.14) -project( - utils_lib - VERSION 0.1.0 - DESCRIPTION "utils library" - HOMEPAGE_URL "https://github.com/bensuperpc" - LANGUAGES C CXX -) - -set(SRCS - compilation.cpp - ) - -set(HEADERS - compilation.hpp - utils.h - type.h - ) - -add_library(utils_lib ${SRCS} ${HEADERS}) -target_include_directories(utils_lib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - -set_target_properties(utils_lib - PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" - ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" - PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" -) diff --git a/source/utils/compilation.cpp b/source/utils/about_compilation.h similarity index 65% rename from source/utils/compilation.cpp rename to source/utils/about_compilation.h index 12a2763..cdf8a28 100644 --- a/source/utils/compilation.cpp +++ b/source/utils/about_compilation.h @@ -9,17 +9,23 @@ * */ -// More info: https://sourceforge.net/p/predef/wiki/Compilers/ +#ifndef COMPILER_H +#define COMPILER_H -#include "compilation.hpp" +#include +#include -namespace my -{ -namespace compile -{ +#if __has_include() +#include +#endif + +namespace compile { + +#if __has_include() +inline const std::string qt_version() { return std::string(QT_VERSION_STR); } +#endif -const std::string arch() -{ +inline const std::string arch() { #if defined(__i386__) || defined(_M_IX86) return std::string("i386"); #elif defined(__x86_64__) || defined(_M_X64) @@ -43,8 +49,7 @@ const std::string arch() #endif } -const std::string compiler() -{ +inline const std::string compiler() { #if defined(__GNUC__) && !defined(__MINGW64__) && !defined(__MINGW32__) return std::string("GCC"); #elif defined(__clang__) @@ -112,13 +117,11 @@ const std::string compiler() #endif } -const std::string compiler_ver() -{ -#if defined(__GNUC__) +inline const std::string compiler_ver() { +#if defined(__GNUC__) || defined(__MINGW64__) || defined(__MINGW32__) return std::to_string(__GNUC__) + "." + std::to_string(__GNUC_MINOR__) + "." + std::to_string(__GNUC_PATCHLEVEL__); #elif defined(__clang__) - return std::to_string(__clang_major__) + "." + std::to_string(__clang_minor__) + "." - + std::to_string(__clang_patchlevel__); + return std::to_string(__clang_major__) + "." + std::to_string(__clang_minor__) + "." + std::to_string(__clang_patchlevel__); #elif defined(_MSC_VER) || defined(_MSC_FULL_VER) return std::to_string(_MSC_FULL_VER); #elif defined(__INTEL_COMPILER) @@ -144,42 +147,40 @@ const std::string compiler_ver() #endif } -const std::string os() -{ +inline const std::string os() { // https://stackoverflow.com/a/5920028/10152334 -#if defined(_WIN32) - return std::string("win"); -#elif defined(__APPLE__) +#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) + return std::string("windows"); +#elif defined(__APPLE__) || defined(__MACH__) return std::string("mac"); -#elif defined(__unix__) +#elif defined(__unix__) || defined(__unix) || defined(unix) || defined(__linux__) return std::string("unix"); #else return std::string("unknown"); #endif } -const std::string os_adv() -{ +inline const std::string os_adv() { #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) -# ifdef defined(_WIN64) +#ifdef defined(_WIN64) return std::string("win64"); -# else +#else return std::string("win32"); -# endif +#endif #elif defined(__APPLE__) -# include -# if defined(TARGET_IPHONE_SIMULATOR) +#include +#if defined(TARGET_IPHONE_SIMULATOR) return std::string("ios_sim"); -# elif defined(TARGET_OS_MACCATALYST) +#elif defined(TARGET_OS_MACCATALYST) return std::string("mac_catalyst"); -# elif defined(TARGET_OS_IPHONE) +#elif defined(TARGET_OS_IPHONE) return std::string("ios"); -# elif defined(TARGET_OS_MAC) +#elif defined(TARGET_OS_MAC) return std::string("mac"); -# else -# error "Unknown Apple platform" +#else +#error "Unknown Apple platform" return std::string("unknown"); -# endif +#endif #elif defined(__ANDROID__) return std::string("android"); #elif defined(__linux__) @@ -193,96 +194,98 @@ const std::string os_adv() #endif } -const std::string cxx() -{ - return std::to_string(__cplusplus); +inline const std::string cxx() { +#if defined(__cplusplus) + return std::to_string(__cplusplus); +#else + return std::string("unknown"); +#endif } -const std::string c() -{ - // return std::to_string(__STDC_VERSION__); - return "0"; +inline const std::string c() { +#if defined(__STDC_VERSION__) + return std::to_string(__STDC_VERSION__); +#else + return std::string("unknown"); +#endif } -const std::string build_date() -{ - return std::string(__DATE__) + " : " + std::string(__TIME__); -} +inline const std::string build_date() { return std::string(__DATE__) + " : " + std::string(__TIME__); } -const std::string arduino() -{ +inline const std::string arduino() { #if defined(TEENSYDUINO) -# if defined(__AVR_ATmega32U4__) +#if defined(__AVR_ATmega32U4__) return std::string("Teensy 2.0"); -# elif defined(__AVR_AT90USB1286__) +#elif defined(__AVR_AT90USB1286__) return std::string("Teensy++ 2.0"); -# elif defined(__MK20DX128__) +#elif defined(__MK20DX128__) return std::string("Teensy 3.0"); -# elif defined(__MK20DX256__) - return std::string("Teensy 3.2"); // and Teensy 3.1 (obsolete) -# elif defined(__MKL26Z64__) +#elif defined(__MK20DX256__) + return std::string("Teensy 3.2"); // and Teensy 3.1 (obsolete) +#elif defined(__MKL26Z64__) return std::string("Teensy LC"); -# elif defined(__MK64FX512__) +#elif defined(__MK64FX512__) return std::string("Teensy 3.5"); -# elif defined(__MK66FX1M0__) +#elif defined(__MK66FX1M0__) return std::string("Teensy 3.6"); -# else +#else return std::string("Unknown board"); -# endif +#endif #else -# if defined(ARDUINO_AVR_ADK) +#if defined(ARDUINO_AVR_ADK) return std::string("Mega Adk"); -# elif defined(ARDUINO_AVR_BT) // Bluetooth +#elif defined(ARDUINO_AVR_BT) // Bluetooth return std::string("Bt"); -# elif defined(ARDUINO_AVR_DUEMILANOVE) +#elif defined(ARDUINO_AVR_DUEMILANOVE) return std::string("Duemilanove"); -# elif defined(ARDUINO_AVR_ESPLORA) +#elif defined(ARDUINO_AVR_ESPLORA) return std::string("Esplora"); -# elif defined(ARDUINO_AVR_ETHERNET) +#elif defined(ARDUINO_AVR_ETHERNET) return std::string("Ethernet"); -# elif defined(ARDUINO_AVR_FIO) +#elif defined(ARDUINO_AVR_FIO) return std::string("Fio"); -# elif defined(ARDUINO_AVR_GEMMA) +#elif defined(ARDUINO_AVR_GEMMA) return std::string("Gemma"); -# elif defined(ARDUINO_AVR_LEONARDO) || defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) +#elif defined(ARDUINO_AVR_LEONARDO) || defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) return std::string("Leonardo"); -# elif defined(ARDUINO_AVR_LILYPAD) +#elif defined(ARDUINO_AVR_LILYPAD) return std::string("Lilypad"); -# elif defined(ARDUINO_AVR_LILYPAD_USB) +#elif defined(ARDUINO_AVR_LILYPAD_USB) return std::string("Lilypad Usb"); -# elif defined(ARDUINO_AVR_MEGA) || defined(__AVR_ATmega1280__) +#elif defined(ARDUINO_AVR_MEGA) || defined(__AVR_ATmega1280__) return std::string("Mega"); -# elif defined(ARDUINO_AVR_MEGA2560) || defined(__AVR_ATmega2560__) +#elif defined(ARDUINO_AVR_MEGA2560) || defined(__AVR_ATmega2560__) return std::string("Mega 2560"); -# elif defined(ARDUINO_AVR_MICRO) +#elif defined(ARDUINO_AVR_MICRO) return std::string("Micro"); -# elif defined(ARDUINO_AVR_MINI) +#elif defined(ARDUINO_AVR_MINI) return std::string("Mini"); -# elif defined(ARDUINO_AVR_NANO) +#elif defined(ARDUINO_AVR_NANO) return std::string("Nano"); -# elif defined(ARDUINO_AVR_NG) +#elif defined(ARDUINO_AVR_NG) return std::string("NG"); -# elif defined(ARDUINO_AVR_PRO) +#elif defined(ARDUINO_AVR_PRO) return std::string("Pro"); -# elif defined(ARDUINO_AVR_ROBOT_CONTROL) +#elif defined(ARDUINO_AVR_ROBOT_CONTROL) return std::string("Robot Ctrl"); -# elif defined(ARDUINO_AVR_ROBOT_MOTOR) +#elif defined(ARDUINO_AVR_ROBOT_MOTOR) return std::string("Robot Motor"); -# elif defined(ARDUINO_AVR_UNO) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) +#elif defined(ARDUINO_AVR_UNO) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) return std::string("Uno"); -# elif defined(ARDUINO_AVR_YUN) +#elif defined(ARDUINO_AVR_YUN) return std::string("Yun"); -# elif defined(ARDUINO_SAM_DUE) +#elif defined(ARDUINO_SAM_DUE) return std::string("Due"); -# elif defined(ARDUINO_SAMD_ZERO) +#elif defined(ARDUINO_SAMD_ZERO) return std::string("Zero"); -# elif defined(ARDUINO_ARC32_TOOLS) -# define BOARD "101"); -# else +#elif defined(ARDUINO_ARC32_TOOLS) +#define BOARD "101"); +#else return std::string("Unknown board"); -# endif +#endif #endif } -} // namespace compile -} // namespace my +} // namespace compile + +#endif // COMPILER_H diff --git a/source/utils/compilation.hpp b/source/utils/compilation.hpp deleted file mode 100644 index d258090..0000000 --- a/source/utils/compilation.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/** - * @file about_compilation.hpp - * @author Bensuperpc (bensuperpc@gmail.com) - * @brief - * @version 1.0.0 - * @date 2022-04-25 - * - * MIT License - * - */ - -// More info: https://sourceforge.net/p/predef/wiki/Compilers/ - -#ifndef COMPILATION_HPP -#define COMPILATION_HPP - -#include - -namespace my::compile -{ - -const std::string arch(); - -const std::string compiler(); - -const std::string compiler_ver(); - -const std::string os(); - -const std::string os_adv(); - -const std::string cxx(); - -const std::string c(); - -const std::string build_date(); - -const std::string arduino(); - -} // namespace my::compile -#endif diff --git a/source/utils/type.h b/source/utils/type.h deleted file mode 100644 index cad595e..0000000 --- a/source/utils/type.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef BENLIB_UTILS_TYPE_HPP_ -#define BENLIB_UTILS_TYPE_HPP_ - -#include // std::size_t - -#ifdef defined(__cplusplus) || defined(c_plusplus) - -constexpr uint64_t KB = 1024u; -constexpr uint64_t MB = 1024u * 1024u; -constexpr uint64_t GB = 1024u * 1024u * 1024u; - -constexpr std::size_t operator""_KB(const unsigned long long v) -{ - return 1024u * v; -} - -constexpr std::size_t operator""_MB(const unsigned long long v) -{ - return 1024u * 1024u * v; -} - -constexpr std::size_t operator""_GB(const unsigned long long v) -{ - return 1024u * 1024u * 1024u * v; -} - -#else - -#define KB 1024u -#define MB 1024u * 1024u -#define GB 1024u * 1024u * 1024u - -#define _KB(v) 1024u * v -#define _MB(v) 1024u * 1024u * v -#define _GB(v) 1024u * 1024u * 1024u * v - -#endif - -#endif // UTILS_H diff --git a/source/utils/utils.h b/source/utils/utils.h index 82246ba..e9ce16e 100644 --- a/source/utils/utils.h +++ b/source/utils/utils.h @@ -1,49 +1,21 @@ #ifndef UTILS_H #define UTILS_H -// In C++20: https://en.cppreference.com/w/cpp/utility/source_location -#ifndef __FUNCTION_NAME__ -# ifdef WIN32 // WINDOWS -# define __FUNCTION_NAME__ __FUNCTION__ -# else // UNIX -# define __FUNCTION_NAME__ __func__ -# endif -#endif +#define KB 1024u +#define MB 1024u * 1024u +#define GB 1024u * 1024u * 1024u +#define TB 1024u * 1024u * 1024u * 1024u -#define MIN(a, b) (((a) < (b)) ? a : b) -#define MAX(a, b) (((a) > (b)) ? a : b) +#define QMLREGISTERSINGLETONTYPE(variable, uri, versionMajor, versionMinor, typeName) \ + qmlRegisterSingletonType(uri, versionMajor, versionMinor, typeName, [&](QQmlEngine *, QJSEngine *) -> QObject * { return &variable; }); -#define ABS(a) (((a) < 0) ? -(a) : (a)) - -// From https://github.com/RobLoach/raylib-cpp/blob/master/include/raylib-cpp-utils.hpp -#ifndef GETTERSETTER -/** - * A utility to build get and set methods on top of a property. - * - * @param type The type of the property. - * @param method The human-readable name for the method. - * @param name The machine-readable name of the property. - */ -# define GETTERSETTER(type, method, name) \ - /** Retrieves the name value for the object. @return The name value of the object. */ \ - inline type get_##method() const \ - { \ - return name; \ - } \ - /** Sets the name value for the object. @param value The value of which to set name to. */ \ - inline void set_##method(type value) \ - { \ - name = value; \ - } -#endif - -#ifdef __cplusplus -extern "C" -{ +// In C++20: https://en.cppreference.com/w/cpp/utility/source_location +#ifndef __FUNCTION_NAME__ +#ifdef WIN32 // WINDOWS +#define __FUNCTION_NAME__ __FUNCTION__ +#else // UNIX +#define __FUNCTION_NAME__ __func__ #endif - -#ifdef __cplusplus -} #endif -#endif // UTILS_H +#endif // UTILS_H diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fdef5fd..482eb0d 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,72 +1,74 @@ -# Parent project does not export its library target, so this CML implicitly -# depends on being added from it, i.e. the testing is done only from the build -# tree and is not feasible from an install location - -project(GTA_SA_cheat_finderTests LANGUAGES C CXX) - -include(CheckLanguage) -check_language(CUDA) -if(CMAKE_CUDA_COMPILER) - enable_language(CUDA) -endif() - -# ---- Tests ---- - -function(add_test_fn TEST_NAME) - add_executable("${TEST_NAME}" "source/${TEST_NAME}.cpp") - target_link_libraries("${TEST_NAME}" PRIVATE GTA_SA_cheat_finder_lib gtest_main) - - if (OpenMP_FOUND OR OpenMP_CXX_FOUND) - target_link_libraries("${TEST_NAME}" PRIVATE OpenMP::OpenMP_CXX) - endif() - - if (CUDAToolkit_FOUND) - target_include_directories("${TEST_NAME}" PRIVATE ${CUDAToolkit_INCLUDE_DIRS}) - target_link_libraries("${TEST_NAME}" PRIVATE CUDA::cudart) - target_link_libraries("${TEST_NAME}" PRIVATE cuda_lib) - endif() - - - add_test(NAME "${TEST_NAME}" COMMAND $) - #target_compile_features("${TEST_NAME}" PRIVATE cxx_std_20) -endfunction() - -function(add_bench_fn BENCH_NAME) - add_executable("${BENCH_NAME}" "source/${BENCH_NAME}.cpp") - target_link_libraries("${BENCH_NAME}" PRIVATE GTA_SA_cheat_finder_lib benchmark::benchmark_main) - - if (OpenMP_FOUND OR OpenMP_CXX_FOUND) - target_link_libraries("${BENCH_NAME}" PRIVATE OpenMP::OpenMP_CXX) - endif() - - if (CUDAToolkit_FOUND) - target_include_directories("${BENCH_NAME}" PRIVATE ${CUDAToolkit_INCLUDE_DIRS}) - target_link_libraries("${BENCH_NAME}" PRIVATE CUDA::cudart) - target_link_libraries("${BENCH_NAME}" PRIVATE cuda_lib) - endif() - - if(NOT CMAKE_BUILD_TYPE MATCHES Debug AND NOT CMAKE_BUILD_TYPE MATCHES Coverage) - add_test(NAME "${BENCH_NAME}" COMMAND $) - elseif() - message(STATUS "Disable ${BENCH_NAME}, Performance benchmark test only run on Release/RelWithDebInfo/MinSizeRel") - endif() - #target_compile_features("${TEST_NAME}" PRIVATE cxx_std_20) +cmake_minimum_required(VERSION 3.14) + +project(world_of_blocksTests LANGUAGES CXX) + +include(../cmake/project-is-top-level.cmake) +include(../cmake/folders.cmake) +include(../cmake/windows-set-path.cmake) + +function(test_bench_generator TEST_BENCH_NAME IS_TEST ADD_TO_TEST) + if (IS_TEST) + add_executable("${TEST_BENCH_NAME}" "source/test/${TEST_BENCH_NAME}.cpp") + else() + add_executable("${TEST_BENCH_NAME}" "source/benchmark/${TEST_BENCH_NAME}.cpp") + endif() + + if (IS_TEST) + target_link_libraries("${TEST_BENCH_NAME}" PRIVATE gtest) + else() + target_link_libraries("${TEST_BENCH_NAME}" PRIVATE benchmark::benchmark) + endif() + + target_link_libraries("${TEST_BENCH_NAME}" PRIVATE GTA_SA_cheat_finder_lib) + + if (OpenMP_FOUND OR OpenMP_CXX_FOUND) + target_link_libraries("${TEST_BENCH_NAME}" PRIVATE OpenMP::OpenMP_CXX OpenMP::OpenMP_C) + endif() + + if (CUDAToolkit_FOUND) + target_include_directories("${TEST_BENCH_NAME}" PRIVATE ${CUDAToolkit_INCLUDE_DIRS}) + target_link_libraries("${TEST_BENCH_NAME}" PRIVATE CUDA::cudart) + target_link_libraries("${TEST_BENCH_NAME}" PRIVATE cuda_lib) + endif() + + set_target_properties("${TEST_BENCH_NAME}" + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + ) + target_compile_features("${TEST_BENCH_NAME}" PRIVATE cxx_std_17) + + #if(NOT CMAKE_BUILD_TYPE MATCHES Debug AND NOT CMAKE_BUILD_TYPE MATCHES Coverage) + # add_test(NAME "${TEST_BENCH_NAME}" COMMAND $) + #elseif() + # message(STATUS "Disable ${BENCH_NAME}, Performance benchmark test only run on Release/RelWithDebInfo/MinSizeRel") + #endif() + + if (ADD_TO_TEST) + add_test(NAME "${TEST_BENCH_NAME}" COMMAND $) + endif() + endfunction() if(NOT WIN32) -include(../cmake/lib/gtest.cmake) -include(../cmake/lib/benchmark.cmake) + include(../cmake/lib/gtest.cmake) + include(../cmake/lib/benchmark.cmake) + include(../cmake/lib/openmp.cmake) + include(../cmake/utile/ccache.cmake) + # Add tests - add_test_fn(find_string_inv_test) - add_test_fn(jamcrc_test) - add_test_fn(gta_sa_test) + test_bench_generator(find_string_inv_test true true) + test_bench_generator(jamcrc_test true true) + test_bench_generator(gta_sa_test true true) # Add bench - add_bench_fn(find_string_inv_bench) - add_bench_fn(jamcrc_bench) + test_bench_generator(find_string_inv_bench false false) + test_bench_generator(jamcrc_bench false false) + endif() - # ---- End-of-file commands ---- add_folders(Test) diff --git a/test/sCMakeLists.txt b/test/sCMakeLists.txt new file mode 100644 index 0000000..9be41db --- /dev/null +++ b/test/sCMakeLists.txt @@ -0,0 +1,73 @@ +# Parent project does not export its library target, so this CML implicitly +# depends on being added from it, i.e. the testing is done only from the build +# tree and is not feasible from an install location + +project(GTA_SA_cheat_finderTests LANGUAGES C CXX) + +include(CheckLanguage) +check_language(CUDA) +if(CMAKE_CUDA_COMPILER) + enable_language(CUDA) +endif() + +# ---- Tests ---- + +function(add_test_fn TEST_NAME) + add_executable("${TEST_NAME}" "source/${TEST_NAME}.cpp") + target_link_libraries("${TEST_NAME}" PRIVATE GTA_SA_cheat_finder_lib gtest_main) + #target_include_directories("${TEST_NAME}" PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/source) + + if (OpenMP_FOUND OR OpenMP_CXX_FOUND) + target_link_libraries("${TEST_NAME}" PRIVATE OpenMP::OpenMP_CXX) + endif() + + if (CUDAToolkit_FOUND) + target_include_directories("${TEST_NAME}" PRIVATE ${CUDAToolkit_INCLUDE_DIRS}) + target_link_libraries("${TEST_NAME}" PRIVATE CUDA::cudart) + target_link_libraries("${TEST_NAME}" PRIVATE cuda_lib) + endif() + + + add_test(NAME "${TEST_NAME}" COMMAND $) + #target_compile_features("${TEST_NAME}" PRIVATE cxx_std_20) +endfunction() + +function(add_bench_fn BENCH_NAME) + add_executable("${BENCH_NAME}" "source/${BENCH_NAME}.cpp") + target_link_libraries("${BENCH_NAME}" PRIVATE GTA_SA_cheat_finder_lib benchmark::benchmark_main) + + if (OpenMP_FOUND OR OpenMP_CXX_FOUND) + target_link_libraries("${BENCH_NAME}" PRIVATE OpenMP::OpenMP_CXX) + endif() + + if (CUDAToolkit_FOUND) + target_include_directories("${BENCH_NAME}" PRIVATE ${CUDAToolkit_INCLUDE_DIRS}) + target_link_libraries("${BENCH_NAME}" PRIVATE CUDA::cudart) + target_link_libraries("${BENCH_NAME}" PRIVATE cuda_lib) + endif() + + if(NOT CMAKE_BUILD_TYPE MATCHES Debug AND NOT CMAKE_BUILD_TYPE MATCHES Coverage) + add_test(NAME "${BENCH_NAME}" COMMAND $) + elseif() + message(STATUS "Disable ${BENCH_NAME}, Performance benchmark test only run on Release/RelWithDebInfo/MinSizeRel") + endif() + #target_compile_features("${TEST_NAME}" PRIVATE cxx_std_20) +endfunction() + +if(NOT WIN32) +include(../cmake/lib/gtest.cmake) +include(../cmake/lib/benchmark.cmake) + # Add tests + add_test_fn(find_string_inv_test) + add_test_fn(jamcrc_test) + #add_test_fn(gta_sa_test) + + # Add bench + #add_bench_fn(find_string_inv_bench) + #add_bench_fn(jamcrc_bench) +endif() + + +# ---- End-of-file commands ---- + +add_folders(Test) diff --git a/test/source/benchmark/find_string_inv_bench.cpp b/test/source/benchmark/find_string_inv_bench.cpp new file mode 100644 index 0000000..ccf1b74 --- /dev/null +++ b/test/source/benchmark/find_string_inv_bench.cpp @@ -0,0 +1,95 @@ +#include +#include +#include +#include + +#include + +#include "GTA_SA_cheat_finder_openmp.hpp" +#include "GTA_SA_cheat_finder_stdthread.hpp" +#if defined(BUILD_WITH_CUDA) +#include "GTA_SA_cheat_finder_cuda.hpp" +#endif // BUILD_WITH_CUDA + +static constexpr int64_t multiplier = 16; +static constexpr int64_t minRange = 1; +static constexpr int64_t maxRange = 1048576; +static constexpr int64_t minThreadRange = 1; +static constexpr int64_t maxThreadRange = 1; +static constexpr int64_t repetitions = 1; + +static void DoSetup([[maybe_unused]] const benchmark::State& state) {} + +static void DoTeardown([[maybe_unused]] const benchmark::State& state) {} + + +static void find_string_inv_bench(benchmark::State &state) { + auto range = state.range(0); + + const auto array_size = 29; + std::array tmp = {0}; + GTA_SA_STDTHREAD gta_sa = GTA_SA_STDTHREAD(); + benchmark::DoNotOptimize(tmp); + benchmark::DoNotOptimize(gta_sa); + for (auto _ : state) { + gta_sa.find_string_inv(tmp.data(), range); + benchmark::ClobberMemory(); + } + state.SetItemsProcessed(state.iterations() * 1); + state.SetBytesProcessed(state.iterations() * 1 * sizeof(uint64_t)); +} + +BENCHMARK(find_string_inv_bench) + ->Name("find_string_inv_bench") + ->RangeMultiplier(multiplier) + ->Range(minRange, maxRange) + ->ThreadRange(minThreadRange, maxThreadRange) + ->Unit(benchmark::kNanosecond) + ->Setup(DoSetup) + ->Teardown(DoTeardown) + ->MeasureProcessCPUTime() + ->UseRealTime() + ->Repetitions(repetitions); + +// Run the benchmark +// BENCHMARK_MAIN(); + +/* +template +static void BasicBench(benchmark::State& state) { + const auto range = state.range(0); + std::string str; + benchmark::DoNotOptimize(str); + + for (auto _ : state) { + str = std::to_string(range); + benchmark::ClobberMemory(); + //state.PauseTiming(); + //state.SkipWithError("No path found"); + //state.ResumeTiming(); + } + // state.counters["range"] = range; + state.SetItemsProcessed(state.iterations() * range * range); + state.SetBytesProcessed(state.iterations() * range * range * sizeof(uint64_t)); +} +BENCHMARK(BasicBench) + ->Name("BasicBench") + ->RangeMultiplier(4) + ->Range(16, 256) + ->ThreadRange(1, 1) + ->Unit(benchmark::kNanosecond) + ->Setup(DoSetup) + ->Teardown(DoTeardown) + ->MeasureProcessCPUTime() + ->UseRealTime(); + +int main(int argc, char** argv) { + ::benchmark::Initialize(&argc, argv); + ::benchmark::RunSpecifiedBenchmarks(); +} +*/ + +int main(int argc, char** argv) { + ::benchmark::Initialize(&argc, argv); + ::benchmark::RunSpecifiedBenchmarks(); +} diff --git a/test/source/gta_sa_bench.cpp b/test/source/benchmark/gta_sa_bench.cpp similarity index 92% rename from test/source/gta_sa_bench.cpp rename to test/source/benchmark/gta_sa_bench.cpp index a50f833..adde904 100644 --- a/test/source/gta_sa_bench.cpp +++ b/test/source/benchmark/gta_sa_bench.cpp @@ -7,8 +7,7 @@ #include "GTA_SA_cheat_finder.hpp" -static void find_string_inv_bench(benchmark::State& state) -{ +static void find_string_inv_bench(benchmark::State &state) { // Code inside this loop is measured repeatedly auto range = state.range(0); diff --git a/test/source/benchmark/jamcrc_bench.cpp b/test/source/benchmark/jamcrc_bench.cpp new file mode 100644 index 0000000..b8fcd24 --- /dev/null +++ b/test/source/benchmark/jamcrc_bench.cpp @@ -0,0 +1,110 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "GTA_SA_cheat_finder_openmp.hpp" +#include "GTA_SA_cheat_finder_stdthread.hpp" +#if defined(BUILD_WITH_CUDA) +#include "GTA_SA_cheat_finder_cuda.hpp" +#endif // BUILD_WITH_CUDA + +static constexpr int64_t multiplier = 16; +static constexpr int64_t minRange = 1; +static constexpr int64_t maxRange = 1048576; +static constexpr int64_t minThreadRange = 1; +static constexpr int64_t maxThreadRange = 1; +static constexpr int64_t repetitions = 1; + +static void DoSetup([[maybe_unused]] const benchmark::State& state) {} + +static void DoTeardown([[maybe_unused]] const benchmark::State& state) {} + +// https://stackoverflow.com/questions/440133/how-do-i-create-a-random-alpha-numeric-string-in-c/444614#444614 +template +auto random_generator() -> T { + auto constexpr seed_bytes = sizeof(typename T::result_type) * T::state_size; + auto constexpr seed_len = seed_bytes / sizeof(std::seed_seq::result_type); + auto seed = std::array(); + auto dev = std::random_device(); + std::generate_n(std::begin(seed), seed_len, std::ref(dev)); + auto seed_seq = std::seed_seq(std::begin(seed), std::end(seed)); + return T{seed_seq}; +} + +std::string generate_string(const size_t size) { + thread_local auto rng = random_generator(); + std::uniform_int_distribution distribution(std::numeric_limits::lowest(), std::numeric_limits::max()); + std::string str(size, '\0'); + std::generate_n(str.begin(), size, [&]() { return distribution(rng); }); + + return str; +} + +static void jamcrc_bench(benchmark::State &state) { + auto size = state.range(0); + std::string str = generate_string(size); + benchmark::DoNotOptimize(str); + GTA_SA_STDTHREAD gta_sa = GTA_SA_STDTHREAD(); + for (auto _ : state) { + auto res = gta_sa.jamcrc(str); + benchmark::DoNotOptimize(res); + benchmark::ClobberMemory(); + // state.PauseTiming(); + // state.SkipWithError("No path found"); + // state.ResumeTiming(); + } + state.SetBytesProcessed(state.iterations() * state.range(0) * sizeof(std::string::value_type)); + state.SetItemsProcessed(state.iterations() * state.range(0)); +} +BENCHMARK(jamcrc_bench) + ->Name("jamcrc_bench") + ->RangeMultiplier(multiplier) + ->Range(minRange, maxRange) + ->ThreadRange(minThreadRange, maxThreadRange) + ->Unit(benchmark::kNanosecond) + ->Setup(DoSetup) + ->Teardown(DoTeardown) + ->MeasureProcessCPUTime() + ->UseRealTime() + ->Repetitions(repetitions); + +/* +#if defined(BUILD_WITH_CUDA) +static void cuda_jamcrc_bench(benchmark::State &state) { + // Code inside this loop is measured repeatedly + auto size = state.range(0); + std::string str = generate_array(size); + GTA_SA_CUDA gta_sa = GTA_SA_CUDA(); + for (auto _ : state) { + benchmark::DoNotOptimize(str); + //gta_sa.jamcrc(str); + my::cuda::jamcrc(str.c_str(), size, 0, 64); + benchmark::ClobberMemory(); + } + state.SetBytesProcessed(state.iterations() * state.range(0) * sizeof(std::string::value_type)); + state.SetItemsProcessed(state.iterations() * state.range(0)); +} +BENCHMARK(cuda_jamcrc_bench) + ->Name("cuda_jamcrc_bench") + ->RangeMultiplier(multiplier) + ->Range(minRange, maxRange) + ->ThreadRange(minThreadRange, maxThreadRange) + ->Unit(benchmark::kNanosecond) + ->Setup(DoSetup) + ->Teardown(DoTeardown) + ->MeasureProcessCPUTime() + ->UseRealTime() + ->Repetitions(repetitions); +#endif +*/ + +int main(int argc, char** argv) { + ::benchmark::Initialize(&argc, argv); + ::benchmark::RunSpecifiedBenchmarks(); +} diff --git a/test/source/find_string_inv_bench.cpp b/test/source/find_string_inv_bench.cpp deleted file mode 100755 index 4735d9f..0000000 --- a/test/source/find_string_inv_bench.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include -#include - -#include - -#include "GTA_SA_cheat_finder.hpp" - -static void find_string_inv_bench(benchmark::State& state) -{ - // Code inside this loop is measured repeatedly - auto range = state.range(0); - - const auto array_size = 29; - std::array tmp = {0}; - - for (auto _ : state) { - GTA_SA::find_string_inv(tmp.data(), range); - benchmark::DoNotOptimize(tmp); - // benchmark::ClobberMemory(); - } - state.SetItemsProcessed(state.iterations()); - state.SetBytesProcessed(state.iterations() * sizeof(uint64_t)); -} -// Register the function as a benchmark -BENCHMARK(find_string_inv_bench)->Name("find_string_inv_bench")->RangeMultiplier(100)->Range(1, 1000000000000000); - -// Run the benchmark -// BENCHMARK_MAIN(); diff --git a/test/source/gta_sa_test.cpp b/test/source/gta_sa_test.cpp deleted file mode 100644 index 81a5335..0000000 --- a/test/source/gta_sa_test.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include - -#include "GTA_SA_cheat_finder.hpp" -#include "gtest/gtest.h" - -TEST(GTA_SA, basic_calc_base_1) -{ - GTA_SA gta_sa; - gta_sa.min_range = 0; - gta_sa.max_range = 60000; - gta_sa.calc_mode = 0; - - gta_sa.run(); - - EXPECT_EQ(gta_sa.results.size(), 0); -} - -#if defined(_OPENMP) -TEST(GTA_SA, basic_calc_mode_openmp) -{ - GTA_SA gta_sa; - gta_sa.min_range = 0; - gta_sa.max_range = 60000; - gta_sa.calc_mode = 1; - - gta_sa.run(); - - EXPECT_EQ(gta_sa.results.size(), 0); -} -#endif - -#if defined(BUILD_WITH_CUDA) -TEST(GTA_SA, basic_calc_cuda_1) -{ - GTA_SA gta_sa; - gta_sa.min_range = 0; - gta_sa.max_range = 6000000; - gta_sa.calc_mode = 2; - - gta_sa.run(); - - EXPECT_EQ(gta_sa.results.size(), 0); -} -#endif diff --git a/test/source/jamcrc_bench.cpp b/test/source/jamcrc_bench.cpp deleted file mode 100755 index 8be380b..0000000 --- a/test/source/jamcrc_bench.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include -#include - -#include - -#include "GTA_SA_cheat_finder.hpp" - -// Source: https://github.com/stbrumme/crc32 -static std::unique_ptr generate_string(const std::uint64_t length) -{ - uint32_t randomNumber = 0x27121978; - // initialize - std::unique_ptr data(new char[length]); - for (size_t i = 0; i < length; i++) { - data[i] = char(randomNumber & 0xFF); - // simple LCG, see - // http://en.wikipedia.org/wiki/Linear_congruential_generator - randomNumber = 1664525 * randomNumber + 1013904223; - } - return data; -} - -static char* generate_array(const std::uint64_t length) -{ - uint32_t randomNumber = 0x27121978; - // initialize - char* data = new char[length]; - for (size_t i = 0; i < length; i++) { - data[i] = char(randomNumber & 0xFF); - // simple LCG, see - // http://en.wikipedia.org/wiki/Linear_congruential_generator - randomNumber = 1664525 * randomNumber + 1013904223; - } - return data; -} - -static void jamcrc_bench(benchmark::State& state) -{ - // Code inside this loop is measured repeatedly - auto size = state.range(0); - auto c_str = generate_string(size); - - std::string str; - std::reverse(str.begin(), str.end()); - for (auto i = 0; i < size; i++) { - str.push_back(c_str[i] + '0'); - } - - for (auto _ : state) { - benchmark::DoNotOptimize(str); - GTA_SA::jamcrc(str); - benchmark::ClobberMemory(); - } - state.SetItemsProcessed(state.iterations()); - state.SetBytesProcessed(state.iterations() * state.range(0) * sizeof(char)); - - // auto c = c_str.release(); - // delete[] c; -} -BENCHMARK(jamcrc_bench)->Name("jamcrc_bench")->RangeMultiplier(16)->Range(1, 1048576); - -#if defined(BUILD_WITH_CUDA) -static void cuda_jamcrc_bench(benchmark::State& state) -{ - // Code inside this loop is measured repeatedly - auto size = state.range(0); - auto c_str = generate_array(size); - - for (auto _ : state) { - benchmark::DoNotOptimize(c_str); - my::cuda::jamcrc(c_str, size, 0, 64); - benchmark::ClobberMemory(); - } - state.SetItemsProcessed(state.iterations()); - state.SetBytesProcessed(state.iterations() * state.range(0) * sizeof(char)); -} -BENCHMARK(cuda_jamcrc_bench)->Name("cuda_jamcrc_bench")->RangeMultiplier(16)->Range(256, 1048576); - -#endif diff --git a/test/source/find_string_inv_test.cpp b/test/source/test/find_string_inv_test.cpp old mode 100755 new mode 100644 similarity index 70% rename from test/source/find_string_inv_test.cpp rename to test/source/test/find_string_inv_test.cpp index 901f244..45ec5f1 --- a/test/source/find_string_inv_test.cpp +++ b/test/source/test/find_string_inv_test.cpp @@ -1,16 +1,22 @@ #include #include -#include "GTA_SA_cheat_finder.hpp" +#include "GTA_SA_cheat_finder_openmp.hpp" +#include "GTA_SA_cheat_finder_stdthread.hpp" +#if defined(BUILD_WITH_CUDA) +#include "GTA_SA_cheat_finder_cuda.hpp" +#endif // BUILD_WITH_CUDA + #include "gtest/gtest.h" static const auto array_size = 29; -TEST(jamcrc, basic1) -{ +TEST(jamcrc, basic1) { std::array tmp1 = {0}; - GTA_SA::find_string_inv(tmp1.data(), 0); + GTA_SA_OPENMP gta_sa = GTA_SA_OPENMP(); + + gta_sa.find_string_inv(tmp1.data(), 0); EXPECT_NE("", static_cast(tmp1.data())); EXPECT_NE("", static_cast(tmp1.data())); @@ -21,11 +27,12 @@ TEST(jamcrc, basic1) EXPECT_EQ("A", static_cast(tmp1.data())); } -TEST(jamcrc, basic2) -{ +TEST(jamcrc, basic2) { std::array tmp1 = {0}; - GTA_SA::find_string_inv(tmp1.data(), 255); + GTA_SA_OPENMP gta_sa = GTA_SA_OPENMP(); + + gta_sa.find_string_inv(tmp1.data(), 255); EXPECT_NE("", static_cast(tmp1.data())); EXPECT_NE("A", static_cast(tmp1.data())); @@ -36,11 +43,12 @@ TEST(jamcrc, basic2) EXPECT_EQ("UI", static_cast(tmp1.data())); } -TEST(jamcrc, basic3) -{ +TEST(jamcrc, basic3) { std::array tmp1 = {0}; - GTA_SA::find_string_inv(tmp1.data(), 40000); + GTA_SA_OPENMP gta_sa = GTA_SA_OPENMP(); + + gta_sa.find_string_inv(tmp1.data(), 40000); EXPECT_NE("", static_cast(tmp1.data())); EXPECT_NE("A", static_cast(tmp1.data())); @@ -51,11 +59,12 @@ TEST(jamcrc, basic3) EXPECT_EQ("LDGB", static_cast(tmp1.data())); } -TEST(jamcrc, basic4) -{ +TEST(jamcrc, basic4) { std::array tmp1 = {0}; - GTA_SA::find_string_inv(tmp1.data(), 1000000000); + GTA_SA_OPENMP gta_sa = GTA_SA_OPENMP(); + + gta_sa.find_string_inv(tmp1.data(), 1000000000); EXPECT_NE("", static_cast(tmp1.data())); EXPECT_NE("A", static_cast(tmp1.data())); @@ -66,11 +75,12 @@ TEST(jamcrc, basic4) EXPECT_EQ("LXSGDFC", static_cast(tmp1.data())); } -TEST(jamcrc, basic5) -{ +TEST(jamcrc, basic5) { std::array tmp1 = {0}; - GTA_SA::find_string_inv(tmp1.data(), 1000000000000); + GTA_SA_OPENMP gta_sa = GTA_SA_OPENMP(); + + gta_sa.find_string_inv(tmp1.data(), 1000000000000); EXPECT_NE("", static_cast(tmp1.data())); EXPECT_NE("A", static_cast(tmp1.data())); @@ -80,3 +90,8 @@ TEST(jamcrc, basic5) EXPECT_EQ("NUXRHCMTD", static_cast(tmp1.data())); } + +auto main(int argc, char **argv) -> int { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/source/test/gta_sa_test.cpp b/test/source/test/gta_sa_test.cpp new file mode 100644 index 0000000..100613c --- /dev/null +++ b/test/source/test/gta_sa_test.cpp @@ -0,0 +1,164 @@ +#include +#include "GTA_SA_cheat_finder_openmp.hpp" +#include "GTA_SA_cheat_finder_stdthread.hpp" +#if defined(BUILD_WITH_CUDA) +#include "GTA_SA_cheat_finder_cuda.hpp" +#endif // BUILD_WITH_CUDA + +#include "gtest/gtest.h" + +/* +20810792 ASNAEB 0x555fc201 +75396850 FHYSTV 0x44b34866 +147491485 LJSPQK 0xfeda77f7 +181355281 OFVIAC 0x6c0fa650 +181961057 OHDUDE 0xe958788a +198489210 PRIEBJ 0xf2aa0c1d +241414872 THGLOJ 0xcaec94ee +289334426 XICWMD 0x1a9aa3d6 +299376767 YECGAA 0x40cf761 +311365503 ZEIIVG 0x74d4fcb1 +370535590 AEDUWNV 0x9a629401 +380229391 AEZAKMI 0xe1b33eb9 +535721682 ASBHGRB 0xa7613f99 +*/ + +TEST(GTA_SA_STDTHREAD, basic_calc_base_1) { + GTA_SA_STDTHREAD gta_sa; + gta_sa.min_range = 0; + gta_sa.max_range = 60000; + + gta_sa.run(); + + EXPECT_EQ(gta_sa.results.size(), 0); +} + +TEST(GTA_SA_STDTHREAD, basic_calc_base_2) { + GTA_SA_STDTHREAD gta_sa; + gta_sa.min_range = 20810700; + gta_sa.max_range = 20810800; + + gta_sa.run(); + + EXPECT_EQ(gta_sa.results.size(), 1); + EXPECT_EQ(gta_sa.results[0].index, 20810792); + EXPECT_EQ(gta_sa.results[0].code, "ASNAEB"); + EXPECT_EQ(gta_sa.results[0].jamcrc, 0x555fc201); +} + +TEST(GTA_SA_STDTHREAD, basic_calc_base_3) { + GTA_SA_STDTHREAD gta_sa; + gta_sa.min_range = 181961000; + gta_sa.max_range = 181961100; + + gta_sa.run(); + + EXPECT_EQ(gta_sa.results.size(), 1); + EXPECT_EQ(gta_sa.results[0].index, 181961057); + EXPECT_EQ(gta_sa.results[0].code, "OHDUDE"); + EXPECT_EQ(gta_sa.results[0].jamcrc, 0xe958788a); +} + +TEST(GTA_SA_STDTHREAD, basic_calc_base_4) { + GTA_SA_STDTHREAD gta_sa; + gta_sa.min_range = 299376700; + gta_sa.max_range = 299376800; + + gta_sa.run(); + + EXPECT_EQ(gta_sa.results.size(), 1); + EXPECT_EQ(gta_sa.results[0].index, 299376767); + EXPECT_EQ(gta_sa.results[0].code, "YECGAA"); + EXPECT_EQ(gta_sa.results[0].jamcrc, 0x40cf761); +} + +TEST(GTA_SA_STDTHREAD, basic_calc_base_5) { + GTA_SA_STDTHREAD gta_sa; + gta_sa.min_range = 20810700; + gta_sa.max_range = 147491500; + + gta_sa.run(); + + EXPECT_EQ(gta_sa.results.size(), 3); + EXPECT_EQ(gta_sa.results[0].index, 20810792); + EXPECT_EQ(gta_sa.results[0].code, "ASNAEB"); + EXPECT_EQ(gta_sa.results[0].jamcrc, 0x555fc201); + + EXPECT_EQ(gta_sa.results[1].index, 75396850); + EXPECT_EQ(gta_sa.results[1].code, "FHYSTV"); + EXPECT_EQ(gta_sa.results[1].jamcrc, 0x44b34866); + + EXPECT_EQ(gta_sa.results[2].index, 147491485); + EXPECT_EQ(gta_sa.results[2].code, "LJSPQK"); + EXPECT_EQ(gta_sa.results[2].jamcrc, 0xfeda77f7); +} + +#if defined(_OPENMP) +TEST(GTA_SA_OPENMP, basic_calc_mode_openmp) { + GTA_SA_OPENMP gta_sa; + gta_sa.min_range = 0; + gta_sa.max_range = 60000; + + gta_sa.run(); + + EXPECT_EQ(gta_sa.results.size(), 0); +} +#endif + +#if defined(BUILD_WITH_CUDA) + +TEST(GTA_SA_CUDA, basic_calc_cuda_1) { + GTA_SA_CUDA gta_sa; + gta_sa.min_range = 0; + gta_sa.max_range = 6000000; + + gta_sa.run(); + + EXPECT_EQ(gta_sa.results.size(), 0); +} + +TEST(GTA_SA_CUDA, basic_calc_cuda_2) { + GTA_SA_CUDA gta_sa; + gta_sa.min_range = 20810700; + gta_sa.max_range = 20810800; + + gta_sa.run(); + + EXPECT_EQ(gta_sa.results.size(), 1); + EXPECT_EQ(gta_sa.results[0].index, 20810792); + EXPECT_EQ(gta_sa.results[0].code, "ASNAEB"); + EXPECT_EQ(gta_sa.results[0].jamcrc, 0x555fc201); +} + +TEST(GTA_SA_CUDA, basic_calc_cuda_3) { + GTA_SA_CUDA gta_sa; + gta_sa.min_range = 181961000; + gta_sa.max_range = 181961100; + + gta_sa.run(); + + EXPECT_EQ(gta_sa.results.size(), 1); + EXPECT_EQ(gta_sa.results[0].index, 181961057); + EXPECT_EQ(gta_sa.results[0].code, "OHDUDE"); + EXPECT_EQ(gta_sa.results[0].jamcrc, 0xe958788a); +} + +TEST(GTA_SA_CUDA, basic_calc_cuda_4) { + GTA_SA_CUDA gta_sa; + gta_sa.min_range = 299376700; + gta_sa.max_range = 299376800; + + gta_sa.run(); + + EXPECT_EQ(gta_sa.results.size(), 1); + EXPECT_EQ(gta_sa.results[0].index, 299376767); + EXPECT_EQ(gta_sa.results[0].code, "YECGAA"); + EXPECT_EQ(gta_sa.results[0].jamcrc, 0x40cf761); +} + +#endif + +auto main(int argc, char **argv) -> int { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/source/jamcrc_test.cpp b/test/source/test/jamcrc_test.cpp old mode 100755 new mode 100644 similarity index 58% rename from test/source/jamcrc_test.cpp rename to test/source/test/jamcrc_test.cpp index c5de9f5..a5127da --- a/test/source/jamcrc_test.cpp +++ b/test/source/test/jamcrc_test.cpp @@ -1,81 +1,85 @@ #include +#include "GTA_SA_cheat_finder_openmp.hpp" +#include "GTA_SA_cheat_finder_stdthread.hpp" +#if defined(BUILD_WITH_CUDA) +#include "GTA_SA_cheat_finder_cuda.hpp" +#endif // BUILD_WITH_CUDA -#include "GTA_SA_cheat_finder.hpp" #include "gtest/gtest.h" -TEST(jamcrc, basic1) -{ +TEST(jamcrc, basic1) { std::string str = ""; uint32_t expected_crc = 0xffffffff; std::reverse(str.begin(), str.end()); + GTA_SA_OPENMP gta_sa = GTA_SA_OPENMP(); - EXPECT_NE(0x0, GTA_SA::jamcrc(str)); - EXPECT_EQ(expected_crc, GTA_SA::jamcrc(str)); + EXPECT_NE(0x0, gta_sa.jamcrc(str)); + EXPECT_EQ(expected_crc, gta_sa.jamcrc(str)); } -TEST(jamcrc, basic2) -{ +TEST(jamcrc, basic2) { std::string str = "ASNAEB"; uint32_t expected_crc = 0x555fc201; std::reverse(str.begin(), str.end()); + GTA_SA_OPENMP gta_sa = GTA_SA_OPENMP(); - EXPECT_NE(0x0, GTA_SA::jamcrc(str)); - EXPECT_EQ(expected_crc, GTA_SA::jamcrc(str)); + EXPECT_NE(0x0, gta_sa.jamcrc(str)); + EXPECT_EQ(expected_crc, gta_sa.jamcrc(str)); } -TEST(jamcrc, basic3) -{ +TEST(jamcrc, basic3) { std::string str = "ASBHGRB"; uint32_t expected_crc = 0xa7613f99; std::reverse(str.begin(), str.end()); + GTA_SA_OPENMP gta_sa = GTA_SA_OPENMP(); - EXPECT_NE(0x0, GTA_SA::jamcrc(str)); - EXPECT_EQ(expected_crc, GTA_SA::jamcrc(str)); + EXPECT_NE(0x0, gta_sa.jamcrc(str)); + EXPECT_EQ(expected_crc, gta_sa.jamcrc(str)); } -TEST(jamcrc, basic4) -{ +TEST(jamcrc, basic4) { std::string str = "XICWMD"; uint32_t expected_crc = 0x1a9aa3d6; std::reverse(str.begin(), str.end()); + GTA_SA_OPENMP gta_sa = GTA_SA_OPENMP(); - EXPECT_NE(0x0, GTA_SA::jamcrc(str)); - EXPECT_EQ(expected_crc, GTA_SA::jamcrc(str)); + EXPECT_NE(0x0, gta_sa.jamcrc(str)); + EXPECT_EQ(expected_crc, gta_sa.jamcrc(str)); } -TEST(jamcrc, basic5) -{ +TEST(jamcrc, basic5) { std::string str = "LGBTQIA+"; uint32_t expected_crc = 0x6ba88a6; std::reverse(str.begin(), str.end()); + GTA_SA_OPENMP gta_sa = GTA_SA_OPENMP(); - EXPECT_NE(0x0, GTA_SA::jamcrc(str)); - EXPECT_EQ(expected_crc, GTA_SA::jamcrc(str)); + EXPECT_NE(0x0, gta_sa.jamcrc(str)); + EXPECT_EQ(expected_crc, gta_sa.jamcrc(str)); } -TEST(jamcrc, basic6) -{ +TEST(jamcrc, basic6) { std::string str = "intergouvernementalisations"; uint32_t expected_crc = 0x1a384955; std::reverse(str.begin(), str.end()); + GTA_SA_OPENMP gta_sa = GTA_SA_OPENMP(); - EXPECT_NE(0x0, GTA_SA::jamcrc(str)); - EXPECT_EQ(expected_crc, GTA_SA::jamcrc(str)); + EXPECT_NE(0x0, gta_sa.jamcrc(str)); + EXPECT_EQ(expected_crc, gta_sa.jamcrc(str)); } #if defined(BUILD_WITH_CUDA) -TEST(jamcrc, cuda_basic1) -{ +TEST(jamcrc, cuda_basic1) { std::string str = ""; uint32_t expected_crc = 0xffffffff; std::reverse(str.begin(), str.end()); + GTA_SA_CUDA gta_sa = GTA_SA_CUDA(); auto const crc = my::cuda::jamcrc(str.data(), str.size(), 0, 64); @@ -83,12 +87,12 @@ TEST(jamcrc, cuda_basic1) EXPECT_EQ(expected_crc, crc); } -TEST(jamcrc, cuda_basic2) -{ +TEST(jamcrc, cuda_basic2) { std::string str = "ASNAEB"; uint32_t expected_crc = 0x555fc201; std::reverse(str.begin(), str.end()); + GTA_SA_CUDA gta_sa = GTA_SA_CUDA(); auto const crc = my::cuda::jamcrc(str.data(), str.size(), 0, 64); @@ -96,12 +100,12 @@ TEST(jamcrc, cuda_basic2) EXPECT_EQ(expected_crc, crc); } -TEST(jamcrc, cuda_basic3) -{ +TEST(jamcrc, cuda_basic3) { std::string str = "ASBHGRB"; uint32_t expected_crc = 0xa7613f99; std::reverse(str.begin(), str.end()); + GTA_SA_CUDA gta_sa = GTA_SA_CUDA(); auto const crc = my::cuda::jamcrc(str.data(), str.size(), 0, 64); @@ -109,12 +113,12 @@ TEST(jamcrc, cuda_basic3) EXPECT_EQ(expected_crc, crc); } -TEST(jamcrc, cuda_basic4) -{ +TEST(jamcrc, cuda_basic4) { std::string str = "XICWMD"; uint32_t expected_crc = 0x1a9aa3d6; std::reverse(str.begin(), str.end()); + GTA_SA_CUDA gta_sa = GTA_SA_CUDA(); auto const crc = my::cuda::jamcrc(str.data(), str.size(), 0, 64); @@ -122,12 +126,12 @@ TEST(jamcrc, cuda_basic4) EXPECT_EQ(expected_crc, crc); } -TEST(jamcrc, cuda_basic5) -{ +TEST(jamcrc, cuda_basic5) { std::string str = "LGBTQIA+"; uint32_t expected_crc = 0x6ba88a6; std::reverse(str.begin(), str.end()); + GTA_SA_CUDA gta_sa = GTA_SA_CUDA(); auto const crc = my::cuda::jamcrc(str.data(), str.size(), 0, 64); @@ -135,12 +139,12 @@ TEST(jamcrc, cuda_basic5) EXPECT_EQ(expected_crc, crc); } -TEST(jamcrc, cuda_basic6) -{ +TEST(jamcrc, cuda_basic6) { std::string str = "intergouvernementalisations"; uint32_t expected_crc = 0x1a384955; std::reverse(str.begin(), str.end()); + GTA_SA_CUDA gta_sa = GTA_SA_CUDA(); auto const crc = my::cuda::jamcrc(str.data(), str.size(), 0, 64); @@ -148,4 +152,9 @@ TEST(jamcrc, cuda_basic6) EXPECT_EQ(expected_crc, crc); } -#endif \ No newline at end of file +#endif + +auto main(int argc, char **argv) -> int { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tools/graphic.py b/tools/graphic.py index 0915cfd..b19b082 100755 --- a/tools/graphic.py +++ b/tools/graphic.py @@ -1,4 +1,5 @@ # Based on work: https://int-i.github.io/python/2021-11-07/matplotlib-google-benchmark-visualization/ +# Modified by: Bensuperpc from argparse import ArgumentParser from itertools import groupby @@ -24,6 +25,7 @@ def extract_size_from_benchmark(benchmark): return bench_name.split('/')[1] # Remove all before / if __name__ == "__main__": + # ./prog_name --benchmark_format=json --benchmark_out=result.json parser = ArgumentParser() parser.add_argument('path', help='benchmark result json file') args = parser.parse_args() @@ -52,18 +54,26 @@ def extract_size_from_benchmark(benchmark): else: data2[key] = y2 - df1 = pd.melt(data1, id_vars=['size'], var_name='algorithm', value_name='bytes_per_second') - df2 = pd.melt(data2, id_vars=['size'], var_name='algorithm', value_name='items_per_second') + df1 = pd.melt(data1, id_vars=['size'], var_name='Benchmark', value_name='bytes_per_second') + df1_max_indices = df1.groupby(['size', 'Benchmark'])['bytes_per_second'].transform(max) == df1['bytes_per_second'] + df1 = df1.loc[df1_max_indices] + df1.reset_index(drop=True, inplace=True) + + + df2 = pd.melt(data2, id_vars=['size'], var_name='Benchmark', value_name='items_per_second') + df2_max_indices = df2.groupby(['size', 'Benchmark'])['items_per_second'].transform(max) == df2['items_per_second'] + df2 = df2.loc[df2_max_indices] + df2.reset_index(drop=True, inplace=True) sns.set_theme() fig, ax = plt.subplots(2, 1) fig.set_size_inches(16, 9) - fig.set_dpi(160) + fig.set_dpi(96) - sns.lineplot(data=df1, x='size', y='bytes_per_second', hue='algorithm', ax=ax[0]) - sns.lineplot(data=df2, x='size', y='items_per_second', hue='algorithm', ax=ax[1]) + sns.lineplot(data=df1, x='size', y='bytes_per_second', hue='Benchmark', ax=ax[0]) + sns.lineplot(data=df2, x='size', y='items_per_second', hue='Benchmark', ax=ax[1]) ax[0].set_title('Bytes per second') ax[1].set_title('Items per second')