Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CompileFlags:
CompilationDatabase: .
Add:
- --target=i686-pc-windows-msvc
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
.vs/*
!.vs/launch.vs.json

.vscode/
.vscode/*
!.vscode/c_cpp_properties.json
.idea/

# Build directories

/out/
/compile_commands.json

# Build files

Expand All @@ -16,4 +18,4 @@

# CMake user config

CMakeUserConfigPresets.json
CMakeUserConfigPresets.json
38 changes: 38 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"WIN32",
"_WIN32",
"_M_IX86=600"
],
"compilerPath": "/usr/bin/clang-cl",
"compilerArgs": [
"--target=i686-pc-windows-msvc"
],
"intelliSenseMode": "windows-clang-x86",
"compileCommands": "${workspaceFolder}/compile_commands.json",
"browse": {
"limitSymbolsToIncludedHeaders": true
}
},
{
"name": "Win32",
"configurationProvider": "ms-vscode.cmake-tools",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"WIN32",
"_WIN32",
"_M_IX86=600"
],
"intelliSenseMode": "windows-msvc-x86"
}
],
"version": 4
}
31 changes: 22 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(PROJECT_VERSION "1.0.0.0" CACHE STRING "Project version")

include(target_add_versioninfo)
include(generate_ipp_translation_units)
include(configure_msvc_wine_intellisense)

project(UnionPlugin
DESCRIPTION "Union plugin for Gothic Games"
Expand Down Expand Up @@ -43,12 +44,14 @@ target_sources(${CMAKE_PROJECT_NAME}

target_include_directories(${CMAKE_PROJECT_NAME}
INTERFACE
"include/"
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)

PRIVATE
BEFORE "userapi/"
"src/"
"signatures/"
target_include_directories(${CMAKE_PROJECT_NAME}
BEFORE PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/userapi"
"${CMAKE_CURRENT_SOURCE_DIR}/src"
"${CMAKE_CURRENT_SOURCE_DIR}/signatures"
)

target_add_versioninfo(${CMAKE_PROJECT_NAME}
Expand All @@ -66,8 +69,7 @@ if (GENERATE_VDF)

set(VDF_BUILD_VM_FILE "${VDF_BUILD_DIR}build.vm")
configure_file("${VDF_DIR}build.vm" "${VDF_BUILD_VM_FILE}")

string(REPLACE "/" "\\" VDF_BUILD_VM_FILE "${VDF_BUILD_VM_FILE}")
set(VDF_OUTPUT_FILE "${VDF_BUILD_DIR}${CMAKE_PROJECT_NAME}.vdf")

if (GENERATE_UNION_API_DLL)
add_custom_target(copy_union_api_dll
Expand All @@ -88,11 +90,22 @@ if (GENERATE_VDF)
add_custom_target(build_vdf
ALL
COMMAND ${CMAKE_COMMAND} -E echo "[VDF] Building ${CMAKE_PROJECT_NAME}.vdf ..."
COMMAND "${VDF_BUILD_DIR}/GothicVDFS.exe" /B "${VDF_BUILD_VM_FILE}"
COMMAND ${CMAKE_COMMAND}
"-DVDF_EXECUTABLE=${VDF_BUILD_DIR}/GothicVDFS.exe"
"-DVDF_SCRIPT=${VDF_BUILD_VM_FILE}"
"-DVDF_OUTPUT=${VDF_OUTPUT_FILE}"
"-DVDF_WORKING_DIRECTORY=${VDF_BUILD_DIR}"
-P "${CMAKE_SOURCE_DIR}/cmake/run_gothic_vdfs.cmake"
COMMAND ${CMAKE_COMMAND} -E echo "[VDF] ${CMAKE_PROJECT_NAME}.vdf build successfully!"
WORKING_DIRECTORY "${VDF_BUILD_DIR}"
DEPENDS ${CMAKE_PROJECT_NAME}
)

if(GENERATE_UNION_API_DLL)
add_dependencies(build_vdf copy_union_api_dll)
endif()
endif()

add_subdirectory(dependencies)
add_subdirectory(dependencies)

configure_msvc_wine_intellisense(${CMAKE_PROJECT_NAME} union)
41 changes: 38 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
"CMAKE_CXX_COMPILER": "cl.exe"
}
},
{
"name": "msvc-wine",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/msvc-wine-x86.cmake",
"CMAKE_EXPORT_COMPILE_COMMANDS": true
}
},
{
"name": "x86",
"hidden": true,
Expand Down Expand Up @@ -81,7 +96,17 @@
{ "name": "G2A-Debug", "inherits": [ "windows", "x86", "debug", "g2a", "config" ] },
{ "name": "G2A-Release", "inherits": [ "windows", "x86", "release", "g2a", "config" ] },
{ "name": "MP-Debug", "inherits": [ "windows", "x86", "debug", "mp", "config" ] },
{ "name": "MP-Release", "inherits": [ "windows", "x86", "release", "mp", "config" ] }
{ "name": "MP-Release", "inherits": [ "windows", "x86", "release", "mp", "config" ] },
{ "name": "G1-Debug-msvc-wine", "inherits": [ "msvc-wine", "x86", "debug", "g1", "msvc-wine-config" ] },
{ "name": "G1-Release-msvc-wine", "inherits": [ "msvc-wine", "x86", "release", "g1", "msvc-wine-config" ] },
{ "name": "G1A-Debug-msvc-wine", "inherits": [ "msvc-wine", "x86", "debug", "g1a", "msvc-wine-config" ] },
{ "name": "G1A-Release-msvc-wine", "inherits": [ "msvc-wine", "x86", "release", "g1a", "msvc-wine-config" ] },
{ "name": "G2-Debug-msvc-wine", "inherits": [ "msvc-wine", "x86", "debug", "g2", "msvc-wine-config" ] },
{ "name": "G2-Release-msvc-wine", "inherits": [ "msvc-wine", "x86", "release", "g2", "msvc-wine-config" ] },
{ "name": "G2A-Debug-msvc-wine", "inherits": [ "msvc-wine", "x86", "debug", "g2a", "msvc-wine-config" ] },
{ "name": "G2A-Release-msvc-wine", "inherits": [ "msvc-wine", "x86", "release", "g2a", "msvc-wine-config" ] },
{ "name": "MP-Debug-msvc-wine", "inherits": [ "msvc-wine", "x86", "debug", "mp", "msvc-wine-config" ] },
{ "name": "MP-Release-msvc-wine", "inherits": [ "msvc-wine", "x86", "release", "mp", "msvc-wine-config" ] }
],
"buildPresets": [
{ "name": "G1-Debug", "configurePreset": "G1-Debug" },
Expand All @@ -93,6 +118,16 @@
{ "name": "G2A-Debug", "configurePreset": "G2A-Debug" },
{ "name": "G2A-Release", "configurePreset": "G2A-Release" },
{ "name": "MP-Debug", "configurePreset": "MP-Debug" },
{ "name": "MP-Release", "configurePreset": "MP-Release" }
{ "name": "MP-Release", "configurePreset": "MP-Release" },
{ "name": "G1-Debug-msvc-wine", "configurePreset": "G1-Debug-msvc-wine" },
{ "name": "G1-Release-msvc-wine", "configurePreset": "G1-Release-msvc-wine" },
{ "name": "G1A-Debug-msvc-wine", "configurePreset": "G1A-Debug-msvc-wine" },
{ "name": "G1A-Release-msvc-wine", "configurePreset": "G1A-Release-msvc-wine" },
{ "name": "G2-Debug-msvc-wine", "configurePreset": "G2-Debug-msvc-wine" },
{ "name": "G2-Release-msvc-wine", "configurePreset": "G2-Release-msvc-wine" },
{ "name": "G2A-Debug-msvc-wine", "configurePreset": "G2A-Debug-msvc-wine" },
{ "name": "G2A-Release-msvc-wine", "configurePreset": "G2A-Release-msvc-wine" },
{ "name": "MP-Debug-msvc-wine", "configurePreset": "MP-Debug-msvc-wine" },
{ "name": "MP-Release-msvc-wine", "configurePreset": "MP-Release-msvc-wine" }
]
}
}
9 changes: 8 additions & 1 deletion CMakeUserConfigPresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
"cacheVariables": {
"GAME_PATH": "C:\\Program Files (x86)\\JoWood\\Gothic II\\System\\Gothic2.exe"
}
},
{
"name": "msvc-wine-config",
"hidden": true,
"cacheVariables": {
"MSVC_WINE_ROOT": "$env{HOME}/my_msvc/opt/msvc"
}
}
]
}
}
77 changes: 73 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ It provides a preconfigured base code designed to simplify the development proce
Before you start making your own plugin, you need to install some software first, here's a full list of things that you'll need to install to be able to build the union plugin:
- [git](https://git-scm.com/) **Required** for version control and to clone the project repository
- [git lfs](https://git-lfs.com/) **Required** to clone the project repository binary files (e.g: `GothicVDFS.exe`)
- [CMake](https://cmake.org/) **Optional** if you plan to use Visual Studio
- [Visual Studio](https://visualstudio.microsoft.com/pl/) **Essential** for compiling the plugin using the MSVC toolset
- [CMake](https://cmake.org/) **Required** for command-line and Linux builds; optional when using Visual Studio's bundled CMake
- [Visual Studio](https://visualstudio.microsoft.com/pl/) **Required on Windows** for compiling the plugin using the MSVC toolset
(make sure to install **C++ Workload** and **CMake Tools for Visual Studio**)

The Union plugin requires the MSVC toolset for compatibility, so alternative toolchains like MinGW are not supported.
Linux builds additionally require:
- [mstorsjo/msvc-wine](https://github.com/mstorsjo/msvc-wine) with the x86 MSVC and Windows SDK files installed
- [Ninja](https://ninja-build.org/)
- [Wine](https://www.winehq.org/)
- Clang/`clang-cl` for VS Code IntelliSense

The Union plugin still uses the real MSVC toolset on Linux through msvc-wine.
Alternative toolchains such as MinGW are not used.

# Fetching the source code

Expand All @@ -32,6 +39,23 @@ git clone --recursive URL_TO_YOUR_REPO
The plugin template contains special file called `CMakeUserConfigPresets.json`
in which you can manully specify the variables for your own needs.

Linux users should set the root of their msvc-wine installation in the
`msvc-wine-config` preset:

```json
{
"name": "msvc-wine-config",
"hidden": true,
"cacheVariables": {
"MSVC_WINE_ROOT": "$env{HOME}/my_msvc/opt/msvc"
}
}
```

Change only the value when msvc-wine is installed elsewhere. Use an absolute
path or `$env{HOME}`; CMake presets do not expand `~`. The selected directory
must contain `bin/x86`, `VC/Tools/MSVC`, and `Windows Kits/10`.

**NOTE!** By default this file is tracked via git, but it shouldn't be, to not track it,
type this command in root repo dir:
```bash
Expand All @@ -45,7 +69,7 @@ Some of the common things that you should propably change are:
- **project version**
default value is **1.0.0.0**

# Building
# Building on Windows

Follow the steps below to compile the plugin:

Expand All @@ -70,6 +94,51 @@ Follow the steps below to compile the plugin:
1. Once everything is configured, click **Build Solution** (or press **Ctrl+Shift+B**).
2. If you've configured everything correctly, the build process should complete successfully.

# Building on Linux

After installing msvc-wine and setting `MSVC_WINE_ROOT`, configure and build
the preset matching the desired game and build type:

```bash
cmake --fresh --preset G2A-Release-msvc-wine
cmake --build --preset G2A-Release-msvc-wine
```

Available Linux presets follow the same `G1`, `G1A`, `G2`, `G2A`, and `MP`
plus `Debug` or `Release` naming as the Windows presets, with
`-msvc-wine` appended. For example:

```text
G1-Debug-msvc-wine
G1-Release-msvc-wine
G2A-Release-msvc-wine
MP-Release-msvc-wine
```

Use MP only when the plugin supports all four engines. The Linux build creates
a 32-bit Windows DLL and packages the VDF in `out/build/PRESET_NAME/vdf/`.
`GothicVDFS.exe` runs through Wine automatically on Linux.

## VS Code IntelliSense on Linux

The repository includes configurations for Microsoft C/C++ and clangd.
Configuring a Linux preset generates `compile_commands.json` and selects that
preset for IntelliSense automatically. The current `.ipp` sources receive
editor-only compilation entries with the matching Gothic engine context;
these entries do not add objects to normal plugin builds.

The C/C++ extension automatically selects the `Linux` configuration on Linux
and the `Win32` configuration on Windows. Windows uses the CMake Tools
configuration provider instead of the Linux compilation database. A root
symlink left by Linux is harmless on Windows and remains available when the
workspace is opened on Linux again.

After configuring for the first time or changing presets, run
**C/C++: Reset IntelliSense Database** and **Developer: Reload Window** in VS
Code. Open `src/Plugin.ipp` and run **C/C++: Log Diagnostics** to verify that
the active translation unit contains the MSVC, Windows SDK, Gothic API, and
Union API include paths.

# Plugin installation

Once the plugin has been compiled successfully, you can tell the game to load it during startup by placing it in `Game/System/autorun` subdirectory.
Expand Down
Loading