From 84db34b24bcf61a44b4da2a9b7f2ccd87ad2a7cc Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 24 May 2020 19:53:31 +0200 Subject: [PATCH] add explicit binary mode data path support The next cathook-gui update will automatically set some systems (mainly ubuntu 18.04 and not officially supported distros) to binary mode. The old method would have preferred the out of date /opt/cathook/data directory. enable binary mode --- .gitlab-ci.yml | 2 +- CMakeLists.txt | 24 ++++++++++++++++++++---- include/config.h.in | 1 + report-crash | 2 +- src/pathio.cpp | 16 +++++++--------- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1f9e6f84..11317317 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ stages: pages: script: # Build cathook - - mkdir build_cathook && pushd build_cathook && cmake .. && make && popd + - mkdir build_cathook && pushd build_cathook && cmake -DInternal_Binarymode=true .. && make && popd # Create the "package" containing everything needed - mkdir package && mv ./bin/libcathook.so ./package/libcathook.so && mv ./data ./package/data && mv ./config_data ./package/config_data && mv ./scripts/binarypackage/install ./package/install && mv ./scripts/binarypackage/attach ./package/attach # Build a static gdb diff --git a/CMakeLists.txt b/CMakeLists.txt index 48e8bec1..c4e25dab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,10 @@ if (EnableCotire) set(ignore_files ${ignore_files} CACHE INTERNAL "") endif() +# +# Config stuff +# + if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type") endif() @@ -90,11 +94,23 @@ set(EnableNullNexus 1 CACHE BOOL "Enable NullNexus chat and other features") set(EnableLogging 1 CACHE BOOL "Enable logging to /tmp/") set(EnableClip 1 CACHE BOOL "Enable anti electron/chromium freezing") set(Unity_ZeroKernel 1 CACHE BOOL "Use a unity build for zerokernel files") - if(NOT EnableVisuals) set(EnableGUI 0) endif() +# Internal variables +# INTERNAL implies "FORCE" by default, so don't set if already set +if (NOT DEFINED Internal_Binarymode) + set(Internal_Binarymode 0 CACHE INTERNAL "Build cathook to be used in 'binary mode'") +endif() +if (NOT DEFINED Internal_Symbolized) + set(Internal_Symbolized 0 CACHE INTERNAL "Build cathook with symbols so crashes can be sent") +endif() + +# +# End of config stuff +# + if (EnableVisuals) set(OpenGL_GL_PREFERENCE "LEGACY") if (EnableImGuiDrawing) @@ -167,7 +183,7 @@ configure_file(include/version.h.in ${CMAKE_SOURCE_DIR}/include/version.h @ONLY) set(CMAKE_CXX_FLAGS "-m32 -march=native -fexceptions -fno-gnu-unique -DNDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "-rdynamic -ggdb -Og") -if (symbolize) +if (Internal_Symbolized) set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ggdb -fvisibility=hidden -fvisibility-inlines-hidden") else() set(CMAKE_CXX_FLAGS_RELEASE "-O3 -s -fvisibility=hidden -fvisibility-inlines-hidden") @@ -231,12 +247,12 @@ elseif(EnablePrecompiledHeaders AND NativePrecompiledHeaders) target_precompile_headers(cathook PRIVATE "${CMAKE_SOURCE_DIR}/include/common.hpp") endif() -if (NOT symbolize) +if (NOT Internal_Symbolized) add_custom_command(TARGET cathook POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_SOURCE_DIR}/bin/$") else() message("Symbolized build") - unset(symbolize CACHE) + set(Internal_Symbolized 0 CACHE INTERNAL "Build cathook with symbols so crashes can be sent" FORCE) endif() if (EnableCotire) add_custom_command(TARGET cathook_unity POST_BUILD diff --git a/include/config.h.in b/include/config.h.in index 20c0ace1..d7f3dddf 100755 --- a/include/config.h.in +++ b/include/config.h.in @@ -11,6 +11,7 @@ #define ENABLE_VAC_BYPASS @VACBypass@ #define ENABLE_TEXTMODE_STDIN @EnableTextmodeStdin@ #define ENABLE_TEXTMODE @Textmode@ +#define ENABLE_BINARYMODE @Internal_Binarymode@ #define ENABLE_PROFILER @EnableProfiler@ #define ENABLE_NULLNEXUS @EnableNullNexus@ #define ENABLE_LOGGING @EnableLogging@ diff --git a/report-crash b/report-crash index 8c83865f..1cfa57e3 100755 --- a/report-crash +++ b/report-crash @@ -80,7 +80,7 @@ if [ $SYMBOLS == false ]; then proccount=$(grep -c '^processor' /proc/cpuinfo) \cp ./build/CMakeCache.txt ./scripts/CMakeCacheBackup.txt pushd build - cmake -Dsymbolize=true .. && cmake --build . --target cathook -- -j$proccount + cmake -DInternal_Symbolized=true .. && cmake --build . --target cathook -- -j$proccount popd fi diff --git a/src/pathio.cpp b/src/pathio.cpp index 219627a2..4991a4af 100755 --- a/src/pathio.cpp +++ b/src/pathio.cpp @@ -19,27 +19,25 @@ std::string getDataPath(std::string subpath) { if (!cached_data_path) { - DIR *dir; if (std::getenv("CH_DATA_PATH")) { cached_data_path = std::getenv("CH_DATA_PATH"); } - else if ((dir = opendir(DATA_PATH))) - { - cached_data_path = DATA_PATH; - closedir(dir); - } else { +#if ENABLE_BINARYMODE std::string xdg_data_dir; if (std::getenv("XDG_DATA_HOME")) xdg_data_dir = std::getenv("XDG_DATA_HOME"); else if (std::getenv("HOME")) xdg_data_dir = std::string(std::getenv("HOME")) + "/.local/share"; + if (xdg_data_dir.empty()) + cached_data_path = DATA_PATH; else - xdg_data_dir = DATA_PATH; - cached_data_path = xdg_data_dir + "/cathook/data"; - logging::Info("Data path: %s", cached_data_path->c_str()); + cached_data_path = xdg_data_dir + "/cathook/data"; +#else + cached_data_path = DATA_PATH; +#endif } } return *cached_data_path + subpath;