diff --git a/CMakeLists.txt b/CMakeLists.txt index 43d1b9f..a743559 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,3 +79,12 @@ if(STUDIOEVENTS_SYNC_GAMEDATA) add_dependencies(StudioEvents StudioEventsGameDataValidate) endif() install(DIRECTORY "${STUDIOEVENTS_GAMEDATA_DIR}/" DESTINATION svencoop/metahook/gamedata/studioevents 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 c1312f1..a3b28e9 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,20 @@ Use `-DSTUDIOEVENTS_SYNC_GAMEDATA=OFF` to skip downloading gamedata during a bui python scripts\validate-gamedata.py install\x86\Release\svencoop\metahook\gamedata\studioevents --manifest scripts\manifests\studioevents.json ``` +## 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. + ## License Licensed under the [MIT License](LICENSE). MurmurHash2 retains Austin Appleby's public-domain notice; each SDK dependency retains its own license. diff --git a/README.zh-CN.md b/README.zh-CN.md index 4c0f201..6d607f5 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -46,6 +46,20 @@ Manifest 包含 11 个引擎快照。无法识别引擎或缺少必要符号时 python scripts\validate-gamedata.py install\x86\Release\svencoop\metahook\gamedata\studioevents --manifest scripts\manifests\studioevents.json ``` +## 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,关闭时不新增下载。 + ## 许可证 采用 [MIT License](LICENSE)。MurmurHash2 保留 Austin Appleby 的公有领域声明,各 SDK 依赖保留其原有许可证。 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)