From 36a136a309502eb6fc19b664969c0c5cb1c7851c Mon Sep 17 00:00:00 2001 From: hzqst <113660872@qq.com> Date: Sun, 4 Oct 2026 18:30:15 +0800 Subject: [PATCH] feat(build): add shared LaunchGame deployment and F5 debugging Co-Authored-By: Codex --- CMakeLists.txt | 9 +++++++++ README.md | 14 ++++++++++++++ README.zh-CN.md | 14 ++++++++++++++ cmake/LaunchGame.cmake | 24 ++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 cmake/LaunchGame.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c50e6d4..611f062 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,3 +85,12 @@ if(PRECACHEMANAGER_SYNC_GAMEDATA) add_dependencies(PrecacheManager PrecacheManagerGameDataValidate) endif() install(DIRECTORY "${PRECACHEMANAGER_GAMEDATA_DIR}/" DESTINATION svencoop/metahook/gamedata/precachemanager OPTIONAL) + +# The aggregate solution owns its single LaunchGame target. +if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + option(METAHOOKSV_ENABLE_LAUNCH_GAME "Add the Visual Studio build/deploy/debug target" OFF) + if(METAHOOKSV_ENABLE_LAUNCH_GAME) + include(cmake/LaunchGame.cmake) + metahooksv_add_launch_game() + endif() +endif() diff --git a/README.md b/README.md index a27ae7b..b2580ee 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,20 @@ The engine tracks every resource the current map has precached in the `cl_resour |---|---| |fs_dump_precaches|Write every precached resource of the current map into `.dump.res`. Run it while connected to a map.| +## F5 debugging (optional) + +Install MetaHook and enable this plugin in the game's `plugins.lst` first. Configure a standalone Visual Studio Win32 solution: + +```powershell +cmake -S . -B build/launch -G "Visual Studio 17 2022" -A Win32 -DMETAHOOKSV_ENABLE_LAUNCH_GAME=ON +``` + +Open the solution, select **LaunchGame** and press **F5**. **DeployGame** builds this plugin and its dependencies, stages Install, and copies plugin DLLs/PDBs/resources before the native debugger starts the existing game launcher. Root launchers/runtime files and plugin lists remain unchanged. Set VS to build before running and **Do not launch** on build errors; stop the game before redeploying. Ordinary builds do not deploy. + +`METAHOOKSV_GAME_DIRECTORY` defaults to Steam discovery; `METAHOOKSV_GAME_APPID` defaults to `225840`. Set `METAHOOKSV_GAME_MOD` for a custom mod and `METAHOOKSV_GAME_ARGUMENTS` for extra arguments. Debug and Release are supported. + +The shared module uses `METAHOOKSV_LAUNCH_GAME_MODULE_DIR`, the surrounding MetaHookSv checkout, or a pinned source archive. Without Installer sources, it downloads the self-contained CLI from GitHub `latest` (no .NET required); `METAHOOKSV_INSTALLER_RELEASE` selects a fixed tag, and `METAHOOKSV_INSTALLER_CLI_EXECUTABLE` supplies an offline EXE. Plugin mode requires v20261004c or later. Valid caches under `build/launch/launch-game/installer/` are reused without update checks; select another tag or clear that private cache to upgrade. `GH_TOKEN`/`GITHUB_TOKEN` may be supplied through the environment if GitHub API rate limits prevent the first download. The feature defaults OFF and performs no extra downloads when disabled. + # Build Requirements: Windows, Visual Studio 2022, CMake 3.21 or newer, Python 3.8 or newer. The first configure downloads VC-LTL 5.3.1 into `thirdparty/cache` and synchronizes the gamedata catalog. diff --git a/README.zh-CN.md b/README.zh-CN.md index 3bc2499..72efc7f 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -26,6 +26,20 @@ |---|---| |fs_dump_precaches|把当前地图的所有预缓存资源写入 `.dump.res`。请在地图内执行该命令。| +## F5 调试(可选) + +先安装 MetaHook,并在游戏的 `plugins.lst` 中启用本插件,然后配置独立的 Visual Studio Win32 解决方案: + +```powershell +cmake -S . -B build/launch -G "Visual Studio 17 2022" -A Win32 -DMETAHOOKSV_ENABLE_LAUNCH_GAME=ON +``` + +打开解决方案,选择 **LaunchGame** 后按 **F5**。**DeployGame** 编译本插件及依赖,暂存 Install,再复制插件 DLL、PDB 和资源,最后由原生调试器启动已有游戏 launcher。不会修改根目录启动器/运行库或插件列表。VS 应开启运行前构建,并将构建失败策略设为 **不启动**;重新部署前请退出游戏。普通构建不会部署。 + +`METAHOOKSV_GAME_DIRECTORY` 默认通过 Steam 自动查找,`METAHOOKSV_GAME_APPID` 默认为 `225840`。自定义 mod 使用 `METAHOOKSV_GAME_MOD`,附加参数使用 `METAHOOKSV_GAME_ARGUMENTS`;支持 Debug 和 Release。 + +共享模块依次从 `METAHOOKSV_LAUNCH_GAME_MODULE_DIR`、所在 MetaHookSv 聚合仓库或固定提交的源码包获取。缺少 Installer 源码时自动下载 GitHub `latest` 的自包含 CLI,无需安装 .NET;可用 `METAHOOKSV_INSTALLER_RELEASE` 固定 tag,或用 `METAHOOKSV_INSTALLER_CLI_EXECUTABLE` 指定离线 EXE。插件模式要求 v20261004c 或之后版本。`build/launch/launch-game/installer/` 下的有效缓存直接复用,不自动升级;切换 tag 或清理该私有缓存后重新下载。首次下载若触发 GitHub API 限流,可通过环境变量 `GH_TOKEN`/`GITHUB_TOKEN` 提供凭据。功能默认 OFF,关闭时不新增下载。 + ## 构建 要求:Windows、Visual Studio 2022、CMake 3.21 或更新版本、Python 3.8 或更新版本。 diff --git a/cmake/LaunchGame.cmake b/cmake/LaunchGame.cmake new file mode 100644 index 0000000..8bd22ab --- /dev/null +++ b/cmake/LaunchGame.cmake @@ -0,0 +1,24 @@ +# Shared implementation: explicit override, surrounding aggregator, pinned archive. +set(METAHOOKSV_LAUNCH_GAME_MODULE_DIR "" CACHE PATH "Directory containing the shared LaunchGame.cmake module") +if(METAHOOKSV_LAUNCH_GAME_MODULE_DIR) + set(_launch_module_dir "${METAHOOKSV_LAUNCH_GAME_MODULE_DIR}") +elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../../cmake/LaunchGame.cmake") + get_filename_component(_launch_module_dir "${CMAKE_CURRENT_LIST_DIR}/../../../cmake" ABSOLUTE) +else() + include(FetchContent) + if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) + endif() + FetchContent_Declare(metahooksv_launch_module + URL https://github.com/hzqst/MetaHookSv/archive/5fec6043b590ce10cbdfd6d5416c7274be531117.tar.gz + TLS_VERIFY ON + # Populate only the modules; never configure the aggregate native project. + SOURCE_SUBDIR cmake) + FetchContent_MakeAvailable(metahooksv_launch_module) + set(_launch_module_dir "${metahooksv_launch_module_SOURCE_DIR}/cmake") +endif() +if(NOT EXISTS "${_launch_module_dir}/LaunchGame.cmake") + message(FATAL_ERROR "METAHOOKSV_LAUNCH_GAME_MODULE_DIR must contain LaunchGame.cmake: ${_launch_module_dir}") +endif() +include("${_launch_module_dir}/LaunchGame.cmake") +unset(_launch_module_dir)