From 78be7dd85d6badd25e60e110417b5a3aac4d97e8 Mon Sep 17 00:00:00 2001 From: TheRedDaemon <66257843+TheRedDaemon@users.noreply.github.com> Date: Sun, 1 Mar 2026 19:02:28 +0100 Subject: [PATCH 1/4] [PROJECT] restructure build flows --- .vscode/launch.json | 3 +- .vscode/tasks.json | 15 +++++++++ CMakeLists.txt | 54 ++++++++++++++++++--------------- README.md | 10 ++---- reccmp/reccmp-build.yml | 5 +++ src/core/MainImplementation.cpp | 2 +- 6 files changed, 55 insertions(+), 34 deletions(-) create mode 100644 .vscode/tasks.json create mode 100644 reccmp/reccmp-build.yml diff --git a/.vscode/launch.json b/.vscode/launch.json index 602c7aa..eebea8c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,8 +14,7 @@ ], "stopAtEntry": false, "cwd": "${workspaceFolder}/_original", - // Note: build currently set target, so if this is the exe, nothing will change - "preLaunchTask": "CMake: build", + "preLaunchTask": "CMake: Prepare OpenSHC.dll Debug", } ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..d4dbe24 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cmake", + "label": "CMake: Prepare OpenSHC.dll Debug", + "command": "build", + "targets": [ + "OpenSHC.dll.deploy" + ], + "preset": "Debug", + "group": "build" + } + ] +} diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bae275..4ff9f77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,11 +3,19 @@ cmake_minimum_required (VERSION 3.21) function(file_add_depends FILE) - message(STATUS "Add file system dependency: ${FILE}") - if(EXISTS "${FILE}") - set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${FILE}) # generally watches for changes + cmake_parse_arguments(ADDITIONAL_ARGS "EXISTENCE_ONLY" "" "" ${ARGN}) + + if(ADDITIONAL_ARGS_EXISTENCE_ONLY) + message(STATUS "Add file system dependency on existence: ${FILE}") + file(GLOB _ CONFIGURE_DEPENDS "${FILE}") else() - file(GLOB _ CONFIGURE_DEPENDS ${FILE}) # trick to trigger reconfigure if the file comes into existence + message(STATUS "Add file system dependency: ${FILE}") + if(EXISTS "${FILE}") + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${FILE}") + else() + # Trigger reconfigure if the file comes into existence + file(GLOB _ CONFIGURE_DEPENDS "${FILE}") + endif() endif() endfunction() @@ -126,6 +134,7 @@ endif() # Add source to this project's executable. add_executable(OpenSHC.exe WIN32 src/entry.cpp ${CORE_SOURCES} ${OPENSHC_SOURCES}) set_target_properties(OpenSHC.exe PROPERTIES OUTPUT_NAME ${OPEN_SHC_NAME}) +set_target_properties(OpenSHC.exe PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/EXE") target_compile_definitions(OpenSHC.exe PRIVATE OPEN_SHC_EXE) target_precompile_headers(OpenSHC.exe PRIVATE $<$:${PCH_FILE}>) @@ -145,42 +154,39 @@ target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/shfolder.dll" "$:${PCH_FILE}>) -# Using module folder as runtime output to properly place the dll and other libs -set_target_properties(OpenSHC.dll PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OPEN_SHC_DLL_DEST}) -# Ensure the module folder exists -file(MAKE_DIRECTORY ${OPEN_SHC_DLL_DEST}) -file_add_depends("${OPEN_SHC_DLL_DEST}") -# This strange workaround does ensure that the module folder is generated and that a config change regenerates the dll. -# It "only" costs a file creation and a compare minimum while not changing the actual source. Found no other way. -set(BUILD_TRIGGER_FILE "${OPEN_SHC_DLL_DEST}/buildtrigger.c") add_custom_target( - OpenSHC.dll.trigger - BYPRODUCTS ${BUILD_TRIGGER_FILE} - COMMAND ${CMAKE_COMMAND} -E echo "// $" > ${BUILD_TRIGGER_FILE}.tmp - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUILD_TRIGGER_FILE}.tmp ${BUILD_TRIGGER_FILE} - COMMAND ${CMAKE_COMMAND} -E remove ${BUILD_TRIGGER_FILE}.tmp - VERBATIM + OpenSHC.dll.deploy + DEPENDS OpenSHC.dll +) + +# Ensure the module folder exists +add_custom_command(TARGET OpenSHC.dll.deploy POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "${OPEN_SHC_DLL_DEST}" ) -target_sources(OpenSHC.dll PRIVATE ${BUILD_TRIGGER_FILE}) -add_dependencies(OpenSHC.dll OpenSHC.dll.trigger) + +# Copy exe and pdb is possible +target_file_copy_if_different(OpenSHC.dll.deploy "$" "${OPEN_SHC_DLL_DEST}/$") +target_file_copy_if_different(OpenSHC.dll.deploy "$" "${OPEN_SHC_DLL_DEST}/$") # Copy ucp definition files file_dependent_read_list("${CMAKE_SOURCE_DIR}/cmake/ucp-definition.txt" UCP_DEFINITION) foreach(FILE IN LISTS UCP_DEFINITION) get_filename_component(DIR "${FILE}" DIRECTORY) if (DIR) - add_custom_command(TARGET OpenSHC.dll POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory "${OPEN_SHC_DLL_DEST}/${DIR}" + set(DEST_FILE_DIR "${OPEN_SHC_DLL_DEST}/${DIR}") + add_custom_command(TARGET OpenSHC.dll.deploy POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "${DEST_FILE_DIR}" ) endif() - target_file_copy_if_different(OpenSHC.dll "${CMAKE_SOURCE_DIR}/ucp/${FILE}" "${OPEN_SHC_DLL_DEST}/${FILE}") + target_file_copy_if_different(OpenSHC.dll.deploy "${CMAKE_SOURCE_DIR}/ucp/${FILE}" "${DEST_FILE_DIR}/${FILE}") endforeach() diff --git a/README.md b/README.md index 1b87e89..2e67b01 100644 --- a/README.md +++ b/README.md @@ -97,12 +97,8 @@ Extending this files name in any way, like `openshc-sources.txt.local.bak`, will The file `build.bat` exists for convenience. If you want more control, you can specify the following cmake options. -##### Output folder of dll - -Use `cmake --preset RelWithDebInfo -D OPEN_SHC_DLL_DEST=.\build-RelWithDebInfo\dll` to specify the destination folder for the .dll and .pdb files in favor of the default. - -Note this setting will remain present even if you remove the `-D` option later from the command. To actually clear this configuration, use `cmake --preset RelWithDebInfo --fresh`. - ##### Building -Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.dll` +Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.dll` will create the dll in `build-RelWithDebInfo/DLL`. +Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.exe` will create the exe in `build-RelWithDebInfo/EXE`. +Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.exe.deploy` will prepare the modules folder in the UCP setup of the bound SHC. diff --git a/reccmp/reccmp-build.yml b/reccmp/reccmp-build.yml new file mode 100644 index 0000000..654abea --- /dev/null +++ b/reccmp/reccmp-build.yml @@ -0,0 +1,5 @@ +project: . +targets: + STRONGHOLDCRUSADER: + path: ../build-RelWithDebInfo/EXE/OpenSHC.exe + pdb: ../build-RelWithDebInfo/EXE/OpenSHC.pdb diff --git a/src/core/MainImplementation.cpp b/src/core/MainImplementation.cpp index 8f74307..70f2378 100644 --- a/src/core/MainImplementation.cpp +++ b/src/core/MainImplementation.cpp @@ -42,7 +42,7 @@ int WINAPI Main::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCm MACRO_CALL_MEMBER(ViewportRenderState_Func::setupMouseTileXY2, ViewportRenderState_Struct::ptr)(); MACRO_CALL_MEMBER(ViewportRenderState_Func::meth_0x4e5a90, ViewportRenderState_Struct::ptr)(); - const HBINK bink = BinkOpen("..\\_original\\binks\\abbot_angry.bik", BINKNOSKIP); + const HBINK bink = BinkOpen("..\\..\\_original\\binks\\abbot_angry.bik", BINKNOSKIP); std::cout << bink->Width << " " << bink->Height << " " << bink->Frames << " " << bink->FrameNum << std::endl; BinkClose(bink); From 3fa689604d99e7a9221bc770ce9329b994a5a015 Mon Sep 17 00:00:00 2001 From: TheRedDaemon <66257843+TheRedDaemon@users.noreply.github.com> Date: Sun, 1 Mar 2026 21:27:44 +0100 Subject: [PATCH 2/4] [PROJECT] split copy of SHC sources for exe to extra target --- .vscode/settings.json | 2 ++ CMakeLists.txt | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 855bbb2..da2495f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,8 @@ "editor.rulers": [ 120 ], + //"cmake.automaticReconfigure": false, + //"cmake.configureOnEdit": false, "files.associations": { "*.inl": "cpp", "iostream": "cpp", diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ff9f77..4310070 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,30 +131,34 @@ else() endif() -# Add source to this project's executable. +# Create the OpenSHC.exe target, should not require the game add_executable(OpenSHC.exe WIN32 src/entry.cpp ${CORE_SOURCES} ${OPENSHC_SOURCES}) set_target_properties(OpenSHC.exe PROPERTIES OUTPUT_NAME ${OPEN_SHC_NAME}) set_target_properties(OpenSHC.exe PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/EXE") target_compile_definitions(OpenSHC.exe PRIVATE OPEN_SHC_EXE) target_precompile_headers(OpenSHC.exe PRIVATE $<$:${PCH_FILE}>) + + +# Create custom target that pulls in the required dependencies to run the exe +# NOTE: There seems to be an issue with our naming here, causing the depends to look for "OpenSHC.exe.exe" instead +add_custom_target(OpenSHC.exe.runnable DEPENDS OpenSHC.exe.exe) + # Checks if a binkw32_real is present and uses this instead file_add_depends("${CRUSADER_DIR}/binkw32_real.dll") if(EXISTS "${CRUSADER_DIR}/binkw32_real.dll") - target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/binkw32_real.dll" "$/binkw32.dll") + target_file_copy_if_different(OpenSHC.exe.runnable "${CRUSADER_DIR}/binkw32_real.dll" "$/binkw32.dll") else() - target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/binkw32.dll" "$/binkw32.dll") + target_file_copy_if_different(OpenSHC.exe.runnable "${CRUSADER_DIR}/binkw32.dll" "$/binkw32.dll") endif() -target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/Mss32.dll" "$/Mss32.dll") +target_file_copy_if_different(OpenSHC.exe.runnable "${CRUSADER_DIR}/Mss32.dll" "$/Mss32.dll") # shfolder is a normal windows lib, however, the game needs to work with the games version, so we still copy it # it should be checked later if the compiler emits a shfolder.dll on its own or if it statically links, which we do not want -target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/shfolder.dll" "$/shfolder.dll") +target_file_copy_if_different(OpenSHC.exe.runnable "${CRUSADER_DIR}/shfolder.dll" "$/shfolder.dll") -# Place the dll and its pdb in the OpenSHC module folder for live testing -set(OPEN_SHC_DLL_DEST "${CRUSADER_DIR}/ucp/modules/${OPEN_SHC_NAME}-${OPEN_SHC_VERSION}") add_library(OpenSHC.dll SHARED src/entry.cpp ${CORE_SOURCES} ${OPENSHC_SOURCES}) set_target_properties(OpenSHC.dll PROPERTIES OUTPUT_NAME ${OPEN_SHC_NAME}) @@ -164,10 +168,9 @@ target_precompile_headers(OpenSHC.dll PRIVATE $<$:${PCH_FI -add_custom_target( - OpenSHC.dll.deploy - DEPENDS OpenSHC.dll -) +# Create custom target that deploys the DLL and the required UCP files to the modules folder +add_custom_target(OpenSHC.dll.deploy DEPENDS OpenSHC.dll) +set(OPEN_SHC_DLL_DEST "${CRUSADER_DIR}/ucp/modules/${OPEN_SHC_NAME}-${OPEN_SHC_VERSION}") # Ensure the module folder exists add_custom_command(TARGET OpenSHC.dll.deploy POST_BUILD From 240ac00aab145e6e7c41aee0589e22cda5b64543 Mon Sep 17 00:00:00 2001 From: TheRedDaemon <66257843+TheRedDaemon@users.noreply.github.com> Date: Sun, 1 Mar 2026 22:53:24 +0100 Subject: [PATCH 3/4] [PROJECT] kept VSCode env cleaner --- .vscode/settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index da2495f..5714977 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,8 +7,8 @@ "editor.rulers": [ 120 ], - //"cmake.automaticReconfigure": false, - //"cmake.configureOnEdit": false, + "cmake.useCMakePresets": "always", + "cmake.useVsDeveloperEnvironment": "never", "files.associations": { "*.inl": "cpp", "iostream": "cpp", From a8a8e162e4fa8547d63b28fe7ddee82f5e51034d Mon Sep 17 00:00:00 2001 From: sourcehold Date: Wed, 4 Mar 2026 09:54:53 +0100 Subject: [PATCH 4/4] fix typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e67b01..a8cf2cc 100644 --- a/README.md +++ b/README.md @@ -101,4 +101,4 @@ The file `build.bat` exists for convenience. If you want more control, you can s Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.dll` will create the dll in `build-RelWithDebInfo/DLL`. Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.exe` will create the exe in `build-RelWithDebInfo/EXE`. -Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.exe.deploy` will prepare the modules folder in the UCP setup of the bound SHC. +Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.dll.deploy` will prepare the modules folder in the UCP setup of the bound SHC.