From a49da76fc5c42f02469668fc8eb996ce3937f08d Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Sat, 12 Apr 2025 14:51:29 +0400 Subject: [PATCH] Added support for PS Vita platform --- .github/workflows/build.yml | 46 ++++++++++++++++++++++++++++++++- CMakeLists.txt | 29 ++++++++++++++++++--- CMakePresets.json | 26 +++++++++++++++++++ cl_dll/CMakeLists.txt | 10 ++++--- cl_dll/cdll_int.cpp | 5 +++- cl_dll/hud_benchtrace.cpp | 4 ++- common/mathlib.h | 10 +++++++ dlls/extdll.h | 2 +- pm_shared/pm_math.c | 6 ++--- public/build.h | 1 + public/interface.cpp | 6 +++++ public/interface.h | 7 ++--- scripts/setup_psvita_sdk.sh | 25 ++++++++++++++++++ scripts/write_psvita_configs.sh | 27 +++++++++++++++++++ 14 files changed, 187 insertions(+), 17 deletions(-) create mode 100644 scripts/setup_psvita_sdk.sh create mode 100644 scripts/write_psvita_configs.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a1ba3576..3bfdf39f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -104,10 +104,54 @@ jobs: with: name: ${{ runner.os }}-${{ matrix.arch }} path: build/*.tar.gz + psvita: + name: PS Vita + runs-on: ubuntu-latest + continue-on-error: true + steps: + - name: Checkout sources + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + - name: Install dependencies + run: | + sudo dpkg --add-architecture i386 + sudo apt-get update + sudo apt-get install libatomic1 libgcc-s1 \ + libstdc++6 gcc-multilib g++-multilib cmake \ + ninja-build libfontconfig-dev + sudo apt-get install cmake=3.28.3-1build7 + sudo ln -sf /usr/bin/cmake /usr/local/bin/cmake + - name: Setup VitaSDK + run: | + chmod +x scripts/setup_psvita_sdk.sh + scripts/setup_psvita_sdk.sh + echo "VITASDK=/usr/local/vitasdk" >> $GITHUB_ENV + echo "$VITASDK/bin" >> $GITHUB_PATH + - name: Configure project + run: cmake --preset "psvita-debug" + - name: Build + run: cmake --build . + working-directory: build + - name: Write configuration files + run: | + pushd build + chmod +x ${{ github.workspace }}/scripts/write_psvita_configs.sh + ${{ github.workspace }}/scripts/write_psvita_configs.sh + popd + - name: Package + run: cpack --config CPackConfig.cmake + working-directory: build + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: PSVita + path: build/*.zip release: name: Release runs-on: ubuntu-latest - needs: [android, windows, linux] + needs: [android, windows, linux, psvita] steps: - name: Fetch artifacts uses: actions/download-artifact@v4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 316551cd..41e18192 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,11 @@ else() add_definitions(-D_CRT_SILENCE_NONCONFORMING_TGMATH_H -D_CRT_SECURE_NO_WARNINGS) endif() +if(VITA) + message(STATUS "Building for PS Vita") + add_compile_options(-fno-use-cxa-atexit) +endif() + if(BUILD_CLIENT) add_subdirectory(cl_dll) endif() @@ -104,12 +109,18 @@ if(BUILD_MENU) add_subdirectory(3rdparty/mainui_cpp) endif() -if(ANDROID OR CMAKE_SIZEOF_VOID_P EQUAL 8) - set(VGUI_STATIC ON CACHE BOOL "" FORCE) - add_subdirectory(3rdparty/vgui_dll) +# check for platforms that aren't natively supported by VGUI +if(ANDROID OR CMAKE_SIZEOF_VOID_P EQUAL 8 OR VITA) + set(VGUI_STATIC ON CACHE BOOL "" FORCE) + add_subdirectory(3rdparty/vgui_dll) set(XASH_SDK ${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(3rdparty/vgui_support) + + if(VITA) + target_compile_options(vgui PRIVATE -fPIC) + target_compile_options(vgui_support PRIVATE -fPIC) + endif() elseif(BUILD_VGUI) add_subdirectory(3rdparty/vgui_dll) endif() @@ -144,9 +155,21 @@ install( DESTINATION ${GAME_DIR} ) +# copy pre-generated config files to psvita bundle +if(VITA) + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/config.cfg" + "${CMAKE_CURRENT_BINARY_DIR}/video.cfg" + "${CMAKE_CURRENT_BINARY_DIR}/opengl.cfg" + DESTINATION "${GAME_DIR}/") +endif() + if(WIN32) set(CPACK_GENERATOR "ZIP") set(CPACK_PACKAGE_FILE_NAME "TF15Client-${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}") +elseif(VITA) + set(CPACK_GENERATOR "ZIP") + set(CPACK_PACKAGE_FILE_NAME "TF15Client-PSVita") else() set(CPACK_GENERATOR "TGZ") set(CPACK_PACKAGE_FILE_NAME "TF15Client-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") diff --git a/CMakePresets.json b/CMakePresets.json index 3916557e..9f377209 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -79,6 +79,32 @@ }, "binaryDir": "${sourceDir}/build", "toolchainFile": "${sourceDir}/toolchains/i386-linux-gnu.cmake" + }, + { + "name": "psvita-debug", + "displayName": "PS Vita Debug", + "generator": "Unix Makefiles", + "toolchainFile": "$env{VITASDK}/share/vita.toolchain.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "BUILD_SERVER": "OFF", + "MAINUI_USE_STB": "ON", + "CMAKE_PROJECT_tf15-client_INCLUDE": "$env{VITASDK}/share/vrtld_shim.cmake" + }, + "binaryDir": "${sourceDir}/build" + }, + { + "name": "psvita-release", + "displayName": "PS Vita Release", + "generator": "Unix Makefiles", + "toolchainFile": "$env{VITASDK}/share/vita.toolchain.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "BUILD_SERVER": "OFF", + "MAINUI_USE_STB": "ON", + "CMAKE_PROJECT_tf15-client_INCLUDE": "$env{VITASDK}/share/vrtld_shim.cmake" + }, + "binaryDir": "${sourceDir}/build" } ] } \ No newline at end of file diff --git a/cl_dll/CMakeLists.txt b/cl_dll/CMakeLists.txt index c745de26..80e82579 100644 --- a/cl_dll/CMakeLists.txt +++ b/cl_dll/CMakeLists.txt @@ -146,7 +146,7 @@ set(CLDLL_SOURCES include_directories(. hl/ ../dlls ../dlls/tfc ../common ../engine ../pm_shared ../game_shared ../public) -if(ANDROID OR CMAKE_SIZEOF_VOID_P EQUAL 8) +if(ANDROID OR CMAKE_SIZEOF_VOID_P EQUAL 8 OR VITA) include_directories(../3rdparty/vgui_dll/include) elseif(NOT BUILD_VGUI) SET(CMAKE_SKIP_RPATH TRUE) @@ -164,9 +164,13 @@ if(WIN32) target_link_libraries(${CLDLL_LIBRARY} user32.lib winmm.lib ws2_32.lib) endif() -if(ANDROID OR CMAKE_SIZEOF_VOID_P EQUAL 8) +if(ANDROID OR CMAKE_SIZEOF_VOID_P EQUAL 8 OR VITA) target_link_libraries(${CLDLL_LIBRARY} vgui_support) - target_link_libraries(${CLDLL_LIBRARY} vgui) + if(VITA) + target_link_libraries(${CLDLL_LIBRARY} -Wl,--whole-archive vgui -Wl,--no-whole-archive) + else() + target_link_libraries(${CLDLL_LIBRARY} vgui) + endif() elseif(NOT BUILD_VGUI) if (WIN32) add_library(vgui SHARED IMPORTED) diff --git a/cl_dll/cdll_int.cpp b/cl_dll/cdll_int.cpp index 6ad5d312..4b0db2cc 100644 --- a/cl_dll/cdll_int.cpp +++ b/cl_dll/cdll_int.cpp @@ -23,8 +23,11 @@ #include "windows.h" #undef HSPRITE #else -#define MAX_PATH PATH_MAX #include +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif +#define MAX_PATH PATH_MAX #endif #include "hud.h" diff --git a/cl_dll/hud_benchtrace.cpp b/cl_dll/hud_benchtrace.cpp index 7e968ebb..10d48126 100644 --- a/cl_dll/hud_benchtrace.cpp +++ b/cl_dll/hud_benchtrace.cpp @@ -2,11 +2,13 @@ // Functions for spawning a thread to get a hopcount to a particular ip address and returning the result in a specified // variable +#include "build.h" + #ifdef _WIN32 #define HSPRITE HSPRITE_win32 #include #undef HSPRITE -#else +#elif XASH_LINUX == 1 #include #endif diff --git a/common/mathlib.h b/common/mathlib.h index 62f04d93..abf9726c 100644 --- a/common/mathlib.h +++ b/common/mathlib.h @@ -16,17 +16,27 @@ #pragma once #ifndef MATHLIB_H #define MATHLIB_H + +#include "build.h" + #ifndef __cplusplus #include #ifdef HAVE_TGMATH_H + +#if XASH_PSVITA != 1 #include +#endif + #endif // HAVE_TGMATH_H + #else // __cplusplus + #if HAVE_CMATH #include #else #include #endif + #endif // __cplusplus typedef float vec_t; diff --git a/dlls/extdll.h b/dlls/extdll.h index 1f932dc7..3deccbb4 100644 --- a/dlls/extdll.h +++ b/dlls/extdll.h @@ -56,10 +56,10 @@ typedef unsigned int ULONG; typedef unsigned char BYTE; typedef int BOOL; -#define MAX_PATH PATH_MAX #ifndef PATH_MAX #define PATH_MAX 4096 #endif +#define MAX_PATH PATH_MAX #endif //_WIN32 // Misc C-runtime library headers diff --git a/pm_shared/pm_math.c b/pm_shared/pm_math.c index 4f113770..8de22d85 100644 --- a/pm_shared/pm_math.c +++ b/pm_shared/pm_math.c @@ -13,11 +13,9 @@ * ****/ // pm_math.c -- math primitives -#include + #include "mathlib.h" -#ifdef HAVE_TGMATH_H -#include -#endif +#include "build.h" #include "const.h" // up / down diff --git a/public/build.h b/public/build.h index a7829342..20060722 100644 --- a/public/build.h +++ b/public/build.h @@ -69,6 +69,7 @@ Then you can use another oneliner to query all variables: #undef XASH_IRIX #undef XASH_JS #undef XASH_LINUX +#undef XASH_LINUX_UNKNOWN #undef XASH_LITTLE_ENDIAN #undef XASH_MIPS #undef XASH_MOBILE_PLATFORM diff --git a/public/interface.cpp b/public/interface.cpp index b4b48044..7bf9ba31 100644 --- a/public/interface.cpp +++ b/public/interface.cpp @@ -3,6 +3,12 @@ #include #include "interface.h" +#if XASH_PSVITA == 1 +#include +#define VRTLD_LIBDL_COMPAT +#include +#endif + #if !defined( _WIN32 ) // Linux doesn't have this function so this emulates its functionality // diff --git a/public/interface.h b/public/interface.h index df72e939..4055b37f 100644 --- a/public/interface.h +++ b/public/interface.h @@ -21,16 +21,17 @@ #ifndef __INTERFACE_H__ #define __INTERFACE_H__ -#if !defined( _WIN32 ) +#include "build.h" +#if XASH_LINUX == 1 #include // dlopen,dlclose, et al #include +#endif +#if !defined( _WIN32 ) #define HMODULE void * #define GetProcAddress dlsym - #define _snprintf snprintf - #endif void *Sys_GetProcAddress( void *pModuleHandle, const char *pName ); diff --git a/scripts/setup_psvita_sdk.sh b/scripts/setup_psvita_sdk.sh new file mode 100644 index 00000000..859b8dfe --- /dev/null +++ b/scripts/setup_psvita_sdk.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +cd $GITHUB_WORKSPACE + +export VITASDK=/usr/local/vitasdk + +echo "Downloading vitasdk..." +git clone https://github.com/vitasdk/vdpm.git --depth=1 || exit 1 +pushd vdpm +./bootstrap-vitasdk.sh || exit 1 +./vdpm taihen || exit 1 +./vdpm kubridge || exit 1 +./vdpm zlib || exit 1 +./vdpm SceShaccCgExt || exit 1 +./vdpm vitaShaRK || exit 1 +./vdpm libmathneon || exit 1 +popd + +echo "Building vrtld..." +git clone https://github.com/fgsfdsfgs/vita-rtld.git --depth=1 || exit 1 +pushd vita-rtld || die +cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release || die_configure +cmake --build build -- -j$JOBS || die +cmake --install build || die +popd diff --git a/scripts/write_psvita_configs.sh b/scripts/write_psvita_configs.sh new file mode 100644 index 00000000..723adbd6 --- /dev/null +++ b/scripts/write_psvita_configs.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +touch config.cfg +echo 'unbindall' >> config.cfg +echo 'bind A_BUTTON "+use"' >> config.cfg +echo 'bind B_BUTTON "+jump"' >> config.cfg +echo 'bind X_BUTTON "+reload"' >> config.cfg +echo 'bind Y_BUTTON "+duck"' >> config.cfg +echo 'bind L1_BUTTON "+attack2"' >> config.cfg +echo 'bind R1_BUTTON "+attack"' >> config.cfg +echo 'bind START "escape"' >> config.cfg +echo 'bind DPAD_UP "lastinv"' >> config.cfg +echo 'bind DPAD_DOWN "impulse 100"' >> config.cfg +echo 'bind DPAD_LEFT "invprev"' >> config.cfg +echo 'bind DPAD_RIGHT "invnext"' >> config.cfg +echo 'bind BACK "chooseteam"' >> config.cfg +echo 'gl_vsync "1"' >> config.cfg +echo 'sv_autosave "0"' >> config.cfg + +touch video.cfg +echo 'fullscreen "1"' >> video.cfg +echo 'width "960"' >> video.cfg +echo 'height "544"' >> video.cfg +echo 'r_refdll "gl"' >> video.cfg + +touch opengl.cfg +echo 'gl_nosort "1"' >> opengl.cfg