Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ CheckOptions:
readability-identifier-naming.NamespaceCase: lower_case
readability-identifier-naming.ParameterCase: lower_case
readability-identifier-naming.VariableCase: lower_case

readability-identifier-length.IgnoredVariableNames: _
---
5 changes: 3 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "[email protected]:bl-sdk/common_dotfiles.git",
"commit": "d03eee713ad436d20033d0598eb88f1529c56ca8",
"commit": "cee5c9dbf5b95f57bb636e5138171aa6a4964cf1",
"checkout": null,
"context": {
"cookiecutter": {
Expand All @@ -15,7 +15,8 @@
"__project_slug": "pyunrealsdk",
"include_cpp": true,
"include_py": true,
"_template": "[email protected]:bl-sdk/common_dotfiles.git"
"_template": "[email protected]:bl-sdk/common_dotfiles.git",
"_commit": "cee5c9dbf5b95f57bb636e5138171aa6a4964cf1"
}
},
"directory": null
Expand Down
6 changes: 6 additions & 0 deletions .devcontainer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore any custom folders outside of our predefined ones, to let you create your own
# One use might be using your own container mapping the install path onto your actual game folder
*/
!clang-cross
!llvm-mingw
!mingw
65 changes: 65 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
FROM alpine:latest AS clang-cross
CMD ["/bin/bash"]
RUN <<EOF
apk add --no-cache \
bash \
clang \
clang-extra-tools \
cmake \
git \
lld \
llvm \
msitools \
ninja \
openssh \
perl \
python3 \
py3-requests
git clone https://github.com/mstorsjo/msvc-wine.git
msvc-wine/vsdownload.py \
--accept-license \
--dest /win-sdk \
Microsoft.VisualStudio.Workload.VCTools \
--arch x86 x64
msvc-wine/install.sh /win-sdk
rm -r msvc-wine
EOF

# llvm-mingw comes with pre-built ubuntu binaries, so using that
FROM ubuntu:latest AS llvm-mingw
CMD ["/bin/bash"]
RUN <<EOF
apt-get update
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC \
apt-get install -y \
cmake \
git \
msitools \
ninja-build \
python-is-python3 \
python3 \
python3-requests \
wget \
xz-utils
wget -nv https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-msvcrt-ubuntu-20.04-x86_64.tar.xz
tar -xf llvm-mingw-20250114-msvcrt-ubuntu-20.04-x86_64.tar.xz
rm llvm-mingw-20250114-msvcrt-ubuntu-20.04-x86_64.tar.xz
mv llvm-mingw-20250114-msvcrt-ubuntu-20.04-x86_64 /llvm-mingw
EOF
ENV PATH="/llvm-mingw/bin:$PATH"

FROM alpine:latest AS mingw
CMD ["/bin/bash"]
RUN <<EOF
apk add --no-cache \
bash \
cmake \
git \
i686-mingw-w64-gcc \
mingw-w64-gcc \
msitools \
ninja \
openssh \
py3-requests \
python3
EOF
7 changes: 7 additions & 0 deletions .devcontainer/clang-cross/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "clang-cross",
"build": {
"dockerfile": "../Dockerfile",
"target": "clang-cross"
}
}
7 changes: 7 additions & 0 deletions .devcontainer/llvm-mingw/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "llvm-mingw",
"build": {
"dockerfile": "../Dockerfile",
"target": "llvm-mingw"
}
}
7 changes: 7 additions & 0 deletions .devcontainer/mingw/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "mingw",
"build": {
"dockerfile": "../Dockerfile",
"target": "mingw"
}
}
100 changes: 31 additions & 69 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ jobs:
submodules: recursive

- name: Configure build
working-directory: ${{ env.GITHUB_WORKSPACE }}
run: |
pip install requests

cmake . --preset ${{ matrix.preset }} -G Ninja

- name: Build
working-directory: ${{ env.GITHUB_WORKSPACE }}
run: cmake --build out/build/${{ matrix.preset }}

build-ubuntu:
Expand All @@ -68,75 +66,39 @@ jobs:
strategy:
fail-fast: false
matrix:
preset: [
"clang-cross-ue3-x86-release",
"clang-cross-ue4-x64-release",
"llvm-mingw-ue3-x86-release",
"llvm-mingw-ue4-x64-release",
"mingw-ue3-x86-release",
"mingw-ue4-x64-release",
]
toolchain:
- preset: clang-cross-ue3-x86-release
container: clang-cross
- preset: clang-cross-ue4-x64-release
container: clang-cross
- preset: llvm-mingw-ue3-x86-release
container: llvm-mingw
- preset: llvm-mingw-ue4-x64-release
container: llvm-mingw
- preset: mingw-ue3-x86-release
container: mingw
- preset: mingw-ue4-x64-release
container: mingw

steps:
- name: Setup CMake and Ninja
uses: lukka/get-cmake@latest

- name: Setup apt packages
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: msitools python3-requests
version: ${{ runner.os }}-apt

- name: Setup LLVM MinGW
if: startswith(matrix.preset, 'llvm-mingw')
run: |
wget -nv ${{ env.LLVM_MINGW_DOWNLOAD }}
tar -xf ${{ env.LLVM_MINGW_VERSION }}.tar.xz -C ~/
echo $(readlink -f ~/${{ env.LLVM_MINGW_VERSION }}/bin) >> $GITHUB_PATH

- name: Setup MinGW
if: startswith(matrix.preset, 'mingw')
uses: egor-tensin/setup-mingw@v2
with:
platform: ${{ fromJSON('["x86", "x64"]')[contains(matrix.preset, 'x64')] }}

- name: Setup Clang
if: startswith(matrix.preset, 'clang-cross')
uses: egor-tensin/setup-clang@v1

- name: Restore win sdk cache
if: startswith(matrix.preset, 'clang-cross')
uses: actions/cache@v4
id: cache-win-sdk
with:
path: ~/win-sdk
key: ${{ runner.os }}-win-sdk

- name: Setup win sdk
if: startswith(matrix.preset, 'clang-cross') && steps.cache-win-sdk.outputs.cache-hit != 'true'
run: |
git clone https://github.com/mstorsjo/msvc-wine.git
msvc-wine/vsdownload.py --accept-license --dest ~/win-sdk Microsoft.VisualStudio.Workload.VCTools
msvc-wine/install.sh ~/win-sdk
rm -r msvc-wine

- name: Checkout repository and submodules
uses: actions/checkout@v4
with:
submodules: recursive

- name: Configure CMake
working-directory: ${{ env.GITHUB_WORKSPACE }}
# The extra msvc wine arg won't do anything if we're not cross compiling
run: >
cmake .
--preset ${{ matrix.preset }}
-G Ninja
-DMSVC_WINE_ENV_SCRIPT=$(readlink -f ~)/win-sdk/bin/${{ fromJSON('["x86", "x64"]')[contains(matrix.preset, 'x64')] }}/msvcenv.sh

- name: Build
working-directory: ${{ env.GITHUB_WORKSPACE }}
run: cmake --build out/build/${{ matrix.preset }}
- name: Checkout repository and submodules
uses: actions/checkout@v4
with:
submodules: recursive

- name: Build
uses: devcontainers/[email protected]
with:
cacheFrom: ghcr.io/bl-sdk/${{ matrix.toolchain.container }}:latest
configFile: .devcontainer/${{ matrix.toolchain.container }}/devcontainer.json
push: never
# The git watcher cmake thinks something's unsafe? Doesn't happen to me locally.
runCmd: |
git config --global --add safe.directory `pwd`
git config --global --add safe.directory `pwd`/libs/unrealsdk

cmake . --preset ${{ matrix.toolchain.preset }} -G Ninja
cmake --build out/build/${{ matrix.toolchain.preset }}

# ==============================================================================

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vs
.vscode
.idea

# C/C++ excludes
.cache/clangd
Expand Down
6 changes: 6 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"environment": {
"MSVC_WINE_ENV_SCRIPT": "/win-sdk/bin/x86/msvcenv.sh"
},
"toolchainFile": "common_cmake/clang-cross-x86.cmake"
},
{
Expand All @@ -50,6 +53,9 @@
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"environment": {
"MSVC_WINE_ENV_SCRIPT": "/win-sdk/bin/x64/msvcenv.sh"
},
"toolchainFile": "common_cmake/clang-cross-x64.cmake"
},
{
Expand Down
74 changes: 37 additions & 37 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,54 +98,54 @@ To use it:
Note that the sdk disables the integration if it's unable to import debugpy on first use, meaning
you may not get away with manipulating `sys.path`. Instead, consider using [`._pth` files](https://docs.python.org/3/library/sys_path_init.html).

# Installation
1. Download the relevant [release](https://github.com/bl-sdk/pyunrealsdk/releases).

If you don't know which compiler's version to get, we recommend MSVC (so functions log messages
include namespaces).

2. Install some game specific plugin loader. The released dlls are not set up to alias any system
dlls, you can't just call it `d3d9.dll` and assume your game will load fine.

If you know a specific dll name is fine to use without aliasing, rename `pyunrealsdk.dll`.

3. Extract all files to somewhere in your game's dll search path. Your plugin loader's plugins
folder may work, otherwise you can fall back to the same directory as the executable.

# Development
To build:
The sdk can be built with one of five different toolchains, each of which have a few different
configurations:

- MSVC
- Clang (Windows)
- Clang (Cross Compile) <sup>*</sup>
- MinGW <sup>*</sup>
- LLVM MinGW <sup>*</sup>

The toolchains with an asterix are all cross compiling toolchains. These all also have an associated
dev container, which is the recommended way of building them. The `clang-cross-*` presets in
particular hardcode a path assuming they're running in the container.

The sdk is always built as a Windows dll. To allow the cross compiling toolchains to link against a
Windows copy of Python, rather than using CMake's normal `FindPython` helpers, when configuring we
download a copy from Python's site. When integrating the sdk into your own projects, exactly which
version can be specified using the `EXPLICIT_PYTHON_ARCH` and `EXPLICIT_PYTHON_VERSION` variables.
The CMake presets already have these set if building locally.

To download the relevant python version, you need a copy of Python with requests on your path. When
cross compiling you also need `msiextract`, which is typically part of an `msitools` package. The
dev containers already have these set up.
```sh
pip install requests
python -c 'import requests'

# Linux only
apt install msitools # Or equivalent
msiextract --version
```

Once you've got this all set up, to build the sdk:

1. Clone the repo (including submodules).
```sh
git clone --recursive https://github.com/bl-sdk/pyunrealsdk.git
```

2. Make sure you have Python with requests on your PATH. This doesn't need to be the same version
as what the SDK uses, it's just used by the script which downloads the correct one.
```sh
pip install requests
python -c 'import requests'
```

If not running on Windows, make sure `msiextract` is also on your PATH. This is typically part
of an `msitools` package.
```sh
apt install msitools # Or equivalent
msiextract --version
```

See the explicit python [readme](https://github.com/bl-sdk/common_cmake/blob/master/explicit_python/Readme.md)
for a few extra details.

3. (OPTIONAL) Copy `postbuild.template`, and edit it to copy files to your game install directories.
2. (OPTIONAL) Copy `postbuild.template`, and edit it to copy files to your game install directories.

4. Choose a preset, and run CMake. Most IDEs will be able to do this for you,
3. Choose a preset, and run CMake. Most IDEs will be able to do this for you,
```
cmake . --preset msvc-ue4-x64-debug
cmake --build out/build/msvc-ue4-x64-debug
```

5. (OPTIONAL) Copy the python runtime files to the game's directory. At a minimum, you probably
4. (OPTIONAL) Copy the python runtime files to the game's directory. At a minimum, you probably
want these:
```
python3.dll
Expand All @@ -159,10 +159,10 @@ To build:
cmake --build out/build/msvc-ue4-x64-debug --target install
```

As an alternative to this and step 3, you could point the CMake install dir directly at your
As an alternative to this and step 2, you could point the CMake install dir directly at your
game, so everything's automatically copied. This however will only work with one game at a time.

6. (OPTIONAL) If you're debugging a game on Steam, add a `steam_appid.txt` in the same folder as the
5. (OPTIONAL) If you're debugging a game on Steam, add a `steam_appid.txt` in the same folder as the
executable, containing the game's Steam App Id.

Normally, games compiled with Steamworks will call
Expand Down
Loading
Loading