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
This commit is contained in:
TotallyNotElite 2020-05-24 19:53:31 +02:00
parent 1d5c30b2df
commit 84db34b24b
5 changed files with 30 additions and 15 deletions

View File

@ -10,7 +10,7 @@ stages:
pages: pages:
script: script:
# Build cathook # 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 # 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 - 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 # Build a static gdb

View File

@ -32,6 +32,10 @@ if (EnableCotire)
set(ignore_files ${ignore_files} CACHE INTERNAL "") set(ignore_files ${ignore_files} CACHE INTERNAL "")
endif() endif()
#
# Config stuff
#
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type") set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type")
endif() 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(EnableLogging 1 CACHE BOOL "Enable logging to /tmp/")
set(EnableClip 1 CACHE BOOL "Enable anti electron/chromium freezing") set(EnableClip 1 CACHE BOOL "Enable anti electron/chromium freezing")
set(Unity_ZeroKernel 1 CACHE BOOL "Use a unity build for zerokernel files") set(Unity_ZeroKernel 1 CACHE BOOL "Use a unity build for zerokernel files")
if(NOT EnableVisuals) if(NOT EnableVisuals)
set(EnableGUI 0) set(EnableGUI 0)
endif() 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) if (EnableVisuals)
set(OpenGL_GL_PREFERENCE "LEGACY") set(OpenGL_GL_PREFERENCE "LEGACY")
if (EnableImGuiDrawing) 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 "-m32 -march=native -fexceptions -fno-gnu-unique -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-rdynamic -ggdb -Og") 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") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ggdb -fvisibility=hidden -fvisibility-inlines-hidden")
else() else()
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -s -fvisibility=hidden -fvisibility-inlines-hidden") 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") target_precompile_headers(cathook PRIVATE "${CMAKE_SOURCE_DIR}/include/common.hpp")
endif() endif()
if (NOT symbolize) if (NOT Internal_Symbolized)
add_custom_command(TARGET cathook POST_BUILD add_custom_command(TARGET cathook POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:cathook> "${CMAKE_SOURCE_DIR}/bin/$<TARGET_FILE_NAME:cathook>") COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:cathook> "${CMAKE_SOURCE_DIR}/bin/$<TARGET_FILE_NAME:cathook>")
else() else()
message("Symbolized build") message("Symbolized build")
unset(symbolize CACHE) set(Internal_Symbolized 0 CACHE INTERNAL "Build cathook with symbols so crashes can be sent" FORCE)
endif() endif()
if (EnableCotire) if (EnableCotire)
add_custom_command(TARGET cathook_unity POST_BUILD add_custom_command(TARGET cathook_unity POST_BUILD

View File

@ -11,6 +11,7 @@
#define ENABLE_VAC_BYPASS @VACBypass@ #define ENABLE_VAC_BYPASS @VACBypass@
#define ENABLE_TEXTMODE_STDIN @EnableTextmodeStdin@ #define ENABLE_TEXTMODE_STDIN @EnableTextmodeStdin@
#define ENABLE_TEXTMODE @Textmode@ #define ENABLE_TEXTMODE @Textmode@
#define ENABLE_BINARYMODE @Internal_Binarymode@
#define ENABLE_PROFILER @EnableProfiler@ #define ENABLE_PROFILER @EnableProfiler@
#define ENABLE_NULLNEXUS @EnableNullNexus@ #define ENABLE_NULLNEXUS @EnableNullNexus@
#define ENABLE_LOGGING @EnableLogging@ #define ENABLE_LOGGING @EnableLogging@

View File

@ -80,7 +80,7 @@ if [ $SYMBOLS == false ]; then
proccount=$(grep -c '^processor' /proc/cpuinfo) proccount=$(grep -c '^processor' /proc/cpuinfo)
\cp ./build/CMakeCache.txt ./scripts/CMakeCacheBackup.txt \cp ./build/CMakeCache.txt ./scripts/CMakeCacheBackup.txt
pushd build pushd build
cmake -Dsymbolize=true .. && cmake --build . --target cathook -- -j$proccount cmake -DInternal_Symbolized=true .. && cmake --build . --target cathook -- -j$proccount
popd popd
fi fi

View File

@ -19,27 +19,25 @@ std::string getDataPath(std::string subpath)
{ {
if (!cached_data_path) if (!cached_data_path)
{ {
DIR *dir;
if (std::getenv("CH_DATA_PATH")) if (std::getenv("CH_DATA_PATH"))
{ {
cached_data_path = 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 else
{ {
#if ENABLE_BINARYMODE
std::string xdg_data_dir; std::string xdg_data_dir;
if (std::getenv("XDG_DATA_HOME")) if (std::getenv("XDG_DATA_HOME"))
xdg_data_dir = std::getenv("XDG_DATA_HOME"); xdg_data_dir = std::getenv("XDG_DATA_HOME");
else if (std::getenv("HOME")) else if (std::getenv("HOME"))
xdg_data_dir = std::string(std::getenv("HOME")) + "/.local/share"; xdg_data_dir = std::string(std::getenv("HOME")) + "/.local/share";
if (xdg_data_dir.empty())
cached_data_path = DATA_PATH;
else else
xdg_data_dir = DATA_PATH;
cached_data_path = xdg_data_dir + "/cathook/data"; cached_data_path = xdg_data_dir + "/cathook/data";
logging::Info("Data path: %s", cached_data_path->c_str()); #else
cached_data_path = DATA_PATH;
#endif
} }
} }
return *cached_data_path + subpath; return *cached_data_path + subpath;