diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index f843c69a3..13d50b5e5 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -22,6 +22,7 @@ jobs:
env:
BF2_PYTHON_OUT: ${{ github.workspace }}/out/ci-python/${{ matrix.arch }}
CMAKE_BUILD_PARALLEL_LEVEL: 2
+ BF2_RELEASE_RUN: ${{ (github.event_name == 'release' || startsWith(github.ref, 'refs/tags/v')) && 'true' || 'false' }}
defaults:
run:
shell: cmd
@@ -39,7 +40,7 @@ jobs:
run: |
call Code\Build\vsdevcmd.cmd ${{ matrix.arch }}
if errorlevel 1 exit /b 1
- cmake --preset msvc-${{ matrix.arch }} -B out/build/ci-${{ matrix.arch }} -DBF2_GAME_DIR:PATH="%GITHUB_WORKSPACE%/out/no-game-content" -DBF2_DICE_PY_LIB:FILEPATH="%BF2_PYTHON_OUT%/dice_py.lib" -DBF2_DICE_PY_DLL:FILEPATH="%BF2_PYTHON_OUT%/dice_py.dll"
+ cmake --preset msvc-${{ matrix.arch }} -B out/build/ci-${{ matrix.arch }} -DBF2_FRONTIER_DEFAULT_CONTINUE=ON -DBF2_GAME_DIR:PATH="%GITHUB_WORKSPACE%/out/no-game-content" -DBF2_DICE_PY_LIB:FILEPATH="%BF2_PYTHON_OUT%/dice_py.lib" -DBF2_DICE_PY_DLL:FILEPATH="%BF2_PYTHON_OUT%/dice_py.dll"
- name: Run x86 engine and editor framework checks
if: matrix.arch == 'x86'
@@ -54,26 +55,121 @@ jobs:
if errorlevel 1 exit /b 1
cmake --build out/build/ci-${{ matrix.arch }} --target ${{ matrix.server }}
- # Keep the client/plugin and editor builds sequential within this checkout.
- - name: Build the x86 AI library and client with plugins
+ - name: Build the x86 AI library
if: matrix.arch == 'x86'
run: |
call Code\Build\vsdevcmd.cmd x86
if errorlevel 1 exit /b 1
- cmake --build out/build/ci-x86 --target bf2_aidll bf2_client
+ cmake --build out/build/ci-x86 --target bf2_aidll
+
+ # [CHOSEN, not recovered] The x64 server depends on and stages the native AI library.
+ - name: Check the Windows x64 AI exports
+ if: matrix.arch == 'x64'
+ run: |
+ call Code\Build\vsdevcmd.cmd x64
+ if errorlevel 1 exit /b 1
+ dumpbin /exports out\build\ci-x64\bin_client\aidll.dll > out\build\ci-x64\aidll-exports.txt
+ if errorlevel 1 exit /b 1
+ type out\build\ci-x64\aidll-exports.txt
+ python -c "import re; from pathlib import Path; text=Path('out/build/ci-x64/aidll-exports.txt').read_text(); names=re.findall(r'^\s+\d+\s+[0-9A-Fa-f]+\s+[0-9A-Fa-f]+\s+(\w+)(?:\s*=\s*\S+)?\s*$', text, re.M); assert sorted(names)==['deinitDll', 'initDll'], names"
+ if errorlevel 1 exit /b 1
+ fc /b out\build\ci-x64\bin_client\aidll.dll out\build\ci-x64\bin_w64ded\aidll.dll
+
+ # RendDX9.dll and TextureAtlasBuilder.dll, and so the client and the editor, build against the
+ # April 2005 DirectX SDK or, on hosted runners without it, the D3DX fallback (Code/Build/dxsdk.cmd).
+ # When neither is usable, other runs skip the client (and on x86 the editor) with a notice and leave
+ # them out of the packages. Release runs fail here instead: the Windows release package carries
+ # both clients and the editor, and a package without them is no release (docs/ci-releases.md).
+ - name: Locate the D3DX headers and import library
+ id: dxsdk
+ run: |
+ rem The same call renddx9.cmd and textureatlasbuilder.cmd make: the April 2005 SDK, or
+ rem without it the D3DX fallback (BF2_D3DX=auto, Code/Build/dxsdk.cmd).
+ call Code\Build\dxsdk.cmd ${{ matrix.arch }} fallback
+ if errorlevel 1 (
+ if "%BF2_RELEASE_RUN%"=="true" (
+ echo ::error title=No D3DX source::Neither the April 2005 DirectX SDK nor the D3DX fallback is usable; the Windows release package needs the ${{ matrix.arch == 'x86' && 'x86 client and editor' || 'x64 client' }}; see docs/ci-releases.md.
+ exit /b 1
+ )
+ echo ::notice title=No D3DX source::Neither the April 2005 DirectX SDK nor the D3DX fallback is usable; the ${{ matrix.arch == 'x86' && 'x86 client and editor are' || 'x64 client is' }} not built on this runner.
+ echo found=false>> "%GITHUB_OUTPUT%"
+ ) else (
+ echo found=true>> "%GITHUB_OUTPUT%"
+ )
+ exit /b 0
+
+ # Windows ships both clients: x86 (retail's PunkBuster, D3DX and OpenAL from the game folder) and
+ # x64 (no PunkBuster). Keep the client/plugin and editor builds sequential within this checkout.
+ - name: Build the ${{ matrix.arch }} client with plugins
+ if: steps.dxsdk.outputs.found == 'true'
+ run: |
+ call Code\Build\vsdevcmd.cmd ${{ matrix.arch }}
+ if errorlevel 1 exit /b 1
+ cmake --build out/build/ci-${{ matrix.arch }} --target bf2_client
+
+ # [CHOSEN, not recovered] OpenAL Soft as both clients' BF2OpenAL.dll, built from the release
+ # tarball pinned by URL and SHA-256 in Code/Build/build_openal_soft.py (docs/ci-releases.md).
+ # The cache key is the architecture and that script, so a new pin rebuilds.
+ - name: Restore the ${{ matrix.arch }} OpenAL Soft build
+ if: steps.dxsdk.outputs.found == 'true'
+ uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
+ with:
+ path: out/build/ci-${{ matrix.arch }}/openal-soft
+ key: openal-soft-${{ matrix.arch }}-${{ hashFiles('Code/Build/build_openal_soft.py') }}
+
+ - name: Build OpenAL Soft for the ${{ matrix.arch }} client
+ if: steps.dxsdk.outputs.found == 'true'
+ run: |
+ call Code\Build\vsdevcmd.cmd ${{ matrix.arch }}
+ if errorlevel 1 exit /b 1
+ python Code/Build/build_openal_soft.py --arch ${{ matrix.arch }} --stage-dir out/build/ci-${{ matrix.arch }}/openal-soft --work-dir out/openal-soft-work --client-dir out/build/ci-${{ matrix.arch }}/bin_client
- name: Build the x86 editor with its plugins
- if: matrix.arch == 'x86'
+ if: matrix.arch == 'x86' && steps.dxsdk.outputs.found == 'true'
run: |
call Code\Build\vsdevcmd.cmd x86
if errorlevel 1 exit /b 1
cmake --build out/build/ci-x86 --target bf2_editor
+ # The real import lists of the packaged client images (both architectures) and of the x86 editor,
+ # for the job log; no image may import NovintHFX.dll (the Falcon is archived,
+ # Code/Archive/NovintFalcon). Also the executables' embedded manifests: any requestedExecutionLevel
+ # disables UAC file virtualization (retail's BF2.exe has no manifest). Printed only, not changed.
+ - name: List the ${{ matrix.arch }} image imports and manifests
+ if: steps.dxsdk.outputs.found == 'true'
+ run: |
+ call Code\Build\vsdevcmd.cmd ${{ matrix.arch }}
+ if errorlevel 1 exit /b 1
+ set "OUT=out\build\ci-${{ matrix.arch }}"
+ set "IMAGES="%OUT%\bin_client\BF2.exe" "%OUT%\bin_client\RendDX9.dll" "%OUT%\bin_client\TextureAtlasBuilder.dll" "%OUT%\bin_client\BF2OpenAL.dll""
+ set "EXES="%OUT%\bin_client\BF2.exe""
+ if "${{ matrix.arch }}"=="x86" set IMAGES=%IMAGES% "%OUT%\bin_editor\BF2Editor.exe" "%OUT%\bin_editor\RendDX9.dll" "%OUT%\bin_editor\TextureAtlasBuilder.dll"
+ if "${{ matrix.arch }}"=="x86" set EXES=%EXES% "%OUT%\bin_editor\BF2Editor.exe"
+ for %%I in (%IMAGES%) do (
+ echo ===== imports: %%I
+ dumpbin /nologo /dependents /imports %%I > "%%~dpnxI.imports.txt"
+ if errorlevel 1 exit /b 1
+ type "%%~dpnxI.imports.txt"
+ findstr /i /c:"NovintHFX" "%%~dpnxI.imports.txt" >nul && (echo ::error title=NovintHFX import::%%~nxI imports NovintHFX.dll& exit /b 1)
+ if /i "%%~nxI"=="BF2OpenAL.dll" findstr /i /c:"VCRUNTIME" /c:"MSVCP" /c:"api-ms-win-crt-" /c:"ucrtbase" "%%~dpnxI.imports.txt" >nul && (echo ::error title=OpenAL runtime::BF2OpenAL.dll imports the shared MSVC runtime& exit /b 1)
+ )
+ for %%E in (%EXES%) do (
+ echo ===== manifest: %%E
+ mt.exe -nologo "-inputresource:%%~fE;#1" -out:con
+ if errorlevel 1 echo no embedded manifest resource 1, or mt.exe could not read it
+ )
+ exit /b 0
+
# Future Windows signing belongs here, before packaging and checksums.
# No signing credentials or signing step are configured yet.
+ - name: Check packaging fixtures
+ run: python Code/Tests/test_package_release.py
+
- name: Package Windows binaries
- run: python Code/Build/package_release.py --platform windows-${{ matrix.arch }} --build-dir out/build/ci-${{ matrix.arch }} --output-dir out/packages --revision "%GITHUB_SHA%" --repository "%GITHUB_REPOSITORY%"
+ run: python Code/Build/package_release.py --platform windows-${{ matrix.arch }} --build-dir out/build/ci-${{ matrix.arch }} --output-dir out/packages --revision "%GITHUB_SHA%" --repository "%GITHUB_REPOSITORY%" ${{ steps.dxsdk.outputs.found != 'true' && (matrix.arch == 'x86' && '--omit client --omit editor' || '--omit client') || '' }}
+ # The per-role ZIPs (and, with a client, the pinned OpenAL Soft tarball) are CI artifacts; the
+ # windows-package job assembles the release package from both legs' artifacts.
- name: Upload Windows packages
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
@@ -81,6 +177,7 @@ jobs:
path: |
out/packages/*.zip
out/packages/*.sha256
+ out/packages/*.tar.bz2
if-no-files-found: error
compression-level: 0
retention-days: 14
@@ -99,6 +196,54 @@ jobs:
if-no-files-found: ignore
retention-days: 7
+ # [CHOSEN, not recovered] The Windows release package, openbf2-windows.zip: both clients (x64\, x86\),
+ # the x86 dedicated server (server\) and the x86 editor (editor\), assembled from the two legs'
+ # per-role ZIPs after checking their checksums and build-info hashes (Code/Build/package_release.py
+ # --release windows). Release runs need every component; other runs package what was built, so CI
+ # stays green without D3DX, and the README and build-info.json name what is missing.
+ windows-package:
+ name: Windows package
+ needs: windows
+ runs-on: ubuntu-22.04
+ timeout-minutes: 15
+ env:
+ BF2_RELEASE_RUN: ${{ (github.event_name == 'release' || startsWith(github.ref, 'refs/tags/v')) && 'true' || 'false' }}
+ steps:
+ - name: Check out the event commit
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ ref: ${{ github.sha }}
+ persist-credentials: false
+
+ - name: Check packaging fixtures
+ run: python3 Code/Tests/test_package_release.py
+
+ # One folder per artifact: both legs carry the same pinned OpenAL Soft tarball, and the
+ # packager checks that the copies are identical.
+ - name: Download the Windows per-role packages
+ uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
+ with:
+ pattern: packages-windows-*
+ path: out/packages
+
+ - name: Assemble the Windows package
+ run: |
+ allow_missing=--allow-missing
+ if [ "$BF2_RELEASE_RUN" = true ]; then allow_missing=; fi
+ python3 Code/Build/package_release.py --release windows --packages-dir out/packages --output-dir out/release --revision "$GITHUB_SHA" --repository "$GITHUB_REPOSITORY" $allow_missing
+
+ - name: Upload the Windows release package
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: release-windows
+ path: |
+ out/release/*.zip
+ out/release/*.sha256
+ out/release/*.tar.bz2
+ if-no-files-found: error
+ compression-level: 0
+ retention-days: 14
+
linux:
name: Linux x64
runs-on: ubuntu-22.04
@@ -137,6 +282,21 @@ jobs:
compression-level: 0
retention-days: 14
+ # The Linux release package, openbf2-linux.zip: the same files in a platform-named archive.
+ - name: Assemble the Linux package
+ run: python3 Code/Build/package_release.py --release linux --packages-dir out/packages --output-dir out/release --revision "$GITHUB_SHA" --repository "$GITHUB_REPOSITORY"
+
+ - name: Upload the Linux release package
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: release-linux
+ path: |
+ out/release/openbf2-linux.zip
+ out/release/openbf2-linux.zip.sha256
+ if-no-files-found: error
+ compression-level: 0
+ retention-days: 14
+
- name: Upload Linux build diagnostics
if: failure()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
@@ -147,3 +307,271 @@ jobs:
out/build/ci-linux-x64/CMakeFiles/CMake*.log
if-no-files-found: ignore
retention-days: 7
+
+ # [CHOSEN, not recovered] The macOS port: the renderer-on Metal client, the dedicated server and the
+ # AI library, one leg per architecture on the Apple-silicon runner, macos-15 (x86_64 is cross-compiled, as the
+ # local Intel builds cross-compile arm64). The client needs the native effect compiler, built here
+ # from pinned vkd3d-shader 2.1 and MojoShader sources with the repository's patches
+ # (tools/macos/nativefx/build.sh, tools/macos/vkd3d-patches).
+ # Release runs (a published release, or a v* tag) sign the binaries with the Developer ID from
+ # the protected `release` environment; every other run (pull requests, branch pushes, forks)
+ # stays ad-hoc and uses no secrets (docs/ci-releases.md). The per-architecture ZIPs are CI
+ # artifacts only and not notarized: releases ship the notarized disk image (macos-app).
+ macos:
+ name: macOS ${{ matrix.arch }}
+ runs-on: macos-15
+ timeout-minutes: 150
+ environment: ${{ (github.event_name == 'release' || startsWith(github.ref, 'refs/tags/v')) && 'release' || '' }}
+ strategy:
+ fail-fast: false
+ matrix:
+ arch: [arm64, x86_64]
+ env:
+ CMAKE_BUILD_PARALLEL_LEVEL: 3
+ MACOSX_DEPLOYMENT_TARGET: "11.0"
+ BF2_RELEASE_SIGNING: ${{ (github.event_name == 'release' || startsWith(github.ref, 'refs/tags/v')) && 'true' || 'false' }}
+ steps:
+ - name: Check out the event commit
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ ref: ${{ github.sha }}
+ persist-credentials: false
+
+ - name: Install build dependencies
+ run: |
+ brew install flex bison mingw-w64 autoconf automake libtool pkgconf cpanminus vulkan-headers spirv-headers
+ # vkd3d's configure needs the Vulkan and SPIR-V headers; /opt/homebrew/include is not on the
+ # compiler's default search path on Apple silicon.
+ echo "CPPFLAGS=-I$(brew --prefix vulkan-headers)/include -I$(brew --prefix spirv-headers)/include" >> "$GITHUB_ENV"
+ # vkd3d's configure needs Perl's JSON module.
+ cpanm --notest --local-lib "$HOME/perl5" JSON
+ echo "PERL5LIB=$HOME/perl5/lib/perl5" >> "$GITHUB_ENV"
+ echo "$(brew --prefix flex)/bin" >> "$GITHUB_PATH"
+ echo "$(brew --prefix bison)/bin" >> "$GITHUB_PATH"
+ echo "WIDL=$(brew --prefix mingw-w64)/toolchain-x86_64/bin/x86_64-w64-mingw32-widl" >> "$GITHUB_ENV"
+
+ - name: Fetch the native effect sources
+ run: |
+ git clone --depth 1 --branch vkd3d-2.1 https://gitlab.winehq.org/wine/vkd3d.git out/third_party/vkd3d
+ test "$(git -C out/third_party/vkd3d rev-parse HEAD)" = fb7f9ff3c1f8d972ee6f1b8c6a92caf6c8ba1e10
+ (cd out/third_party/vkd3d && ./autogen.sh)
+ git clone https://github.com/icculus/mojoshader.git out/third_party/mojoshader
+ git -C out/third_party/mojoshader checkout --detach ad5dff84830c2863c841f4b1f4e3df78c705b383
+
+ - name: Build the native effect libraries
+ run: sh tools/macos/nativefx/build.sh ${{ matrix.arch }}
+
+ - name: Configure
+ run: |
+ deps=nativefx
+ if [ "${{ matrix.arch }}" = arm64 ]; then deps=nativefx-arm64; fi
+ cmake --preset macos-x64 -B out/build/ci-macos-${{ matrix.arch }} \
+ -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }} -DBF2_MACOS_LINK_RENDDX9=ON \
+ -DBF2_FRONTIER_DEFAULT_CONTINUE=ON \
+ -DBF2_FX_NATIVE_DEPS="$GITHUB_WORKSPACE/out/build/$deps" \
+ -DBF2_GAME_DIR:PATH="$GITHUB_WORKSPACE/out/no-game-content"
+
+ - name: Build the client, the dedicated server and the AI library
+ run: cmake --build out/build/ci-macos-${{ matrix.arch }} --target bf2_client bf2 bf2_aidll
+
+ - name: Check the architecture and the Python runtime
+ run: |
+ for image in bf2_client bf2 libdice_py.dylib libaidll.dylib; do
+ lipo out/build/ci-macos-${{ matrix.arch }}/bin_macos/$image -verify_arch ${{ matrix.arch }}
+ done
+ # The runner is arm64; the cross-compiled x86_64 images are not executed here.
+ if [ "${{ matrix.arch }}" = arm64 ]; then
+ cmake --build out/build/ci-macos-arm64 --target dice_py_check_run
+ fi
+
+ # Release only, after every build step, so the keychain exists only for signing and packaging.
+ # No notary key here: this job notarizes nothing.
+ - name: Import the Developer ID certificate (release)
+ if: env.BF2_RELEASE_SIGNING == 'true'
+ env:
+ MACOS_CERT_P12: ${{ secrets.MACOS_CERT_P12 }}
+ MACOS_CERT_PASSWORD: ${{ secrets.MACOS_CERT_PASSWORD }}
+ run: bash tools/macos/ci/release-signing.sh import
+
+ - name: Sign the macOS binaries (release)
+ if: env.BF2_RELEASE_SIGNING == 'true'
+ run: bash tools/macos/ci/release-signing.sh sign-standalone out/build/ci-macos-${{ matrix.arch }}/bin_macos
+
+ - name: Package macOS binaries
+ run: |
+ signing=adhoc
+ if [ "$BF2_RELEASE_SIGNING" = true ]; then signing=developer-id; fi
+ python3 Code/Build/package_release.py --platform macos-${{ matrix.arch }} --build-dir out/build/ci-macos-${{ matrix.arch }} --output-dir out/packages --revision "$GITHUB_SHA" --repository "$GITHUB_REPOSITORY" --macos-signing "$signing"
+
+ - name: Remove the signing keychain and key (release)
+ if: always() && env.BF2_RELEASE_SIGNING == 'true'
+ run: bash tools/macos/ci/release-signing.sh cleanup
+
+ - name: Upload macOS packages
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: packages-macos-${{ matrix.arch }}
+ path: |
+ out/packages/*.zip
+ out/packages/*.sha256
+ if-no-files-found: error
+ compression-level: 0
+ retention-days: 14
+
+ - name: Upload macOS build diagnostics
+ if: failure()
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: diagnostics-macos-${{ matrix.arch }}
+ path: |
+ out/build/ci-macos-${{ matrix.arch }}/CMakeFiles/CMakeConfigureLog.yaml
+ out/build/nativefx*/logs/*.log
+ if-no-files-found: ignore
+ retention-days: 7
+
+ # [CHOSEN, not recovered] The macOS app: the separate MIT setup app (kr4uzi/openbf2-setup, pinned
+ # below) with the universal client embedded, as a drag-and-drop disk image, openbf2-macos.dmg: the
+ # macOS release package. The two macOS legs are
+ # merged with lipo; the setup app's own release script builds, tests and verifies the image. Its
+ # contract for the client directory is docs/client-artifact.md in that repository.
+ # Release runs sign the app with the Developer ID (hardened runtime, timestamp, entitlements),
+ # sign, notarize and staple the disk image; other runs keep the setup script's ad-hoc signature.
+ macos-app:
+ name: macOS app (universal)
+ needs: macos
+ runs-on: macos-15
+ timeout-minutes: 120
+ environment: ${{ (github.event_name == 'release' || startsWith(github.ref, 'refs/tags/v')) && 'release' || '' }}
+ env:
+ SETUP_REPOSITORY: kr4uzi/openbf2-setup
+ SETUP_REVISION: fb6dc8fe8d7b81e41d0b737925891e92568cb61c # v0.3.1
+ BF2_RELEASE_SIGNING: ${{ (github.event_name == 'release' || startsWith(github.ref, 'refs/tags/v')) && 'true' || 'false' }}
+ steps:
+ # The client entitlements, the signing helper and the packager (for the build-info); the app
+ # is built from the setup repository.
+ - name: Check out the signing files
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ ref: ${{ github.sha }}
+ path: out/openbf2
+ persist-credentials: false
+ sparse-checkout: |
+ Code/Build
+ tools/macos/ci
+ sparse-checkout-cone-mode: true
+
+ - name: Download the macOS client packages
+ uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
+ with:
+ pattern: packages-macos-*
+ path: out/packages
+ merge-multiple: true
+
+ - name: Merge the client legs into a universal client
+ working-directory: out
+ run: |
+ for arch in arm64 x86_64; do
+ (cd packages && shasum -a 256 -c "openbf2-macos-$arch-client.zip.sha256")
+ ditto -x -k "packages/openbf2-macos-$arch-client.zip" "legs/$arch"
+ done
+ mkdir client-universal
+ for item in bf2_client libdice_py.dylib libaidll.dylib; do
+ lipo -create "legs/arm64/openbf2-macos-arm64-client/$item" \
+ "legs/x86_64/openbf2-macos-x86_64-client/$item" \
+ -output "client-universal/$item"
+ lipo "client-universal/$item" -verify_arch arm64 x86_64
+ done
+ chmod +x client-universal/bf2_client
+
+ - name: Check out the setup app
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ repository: ${{ env.SETUP_REPOSITORY }}
+ ref: ${{ env.SETUP_REVISION }}
+ path: out/openbf2-setup
+ persist-credentials: false
+
+ # The setup app uses header-only Boost.Asio (1.86 or newer); find_package(Boost CONFIG) finds
+ # Homebrew's copy, nothing is compiled from Boost.
+ - name: Install the Boost headers
+ run: |
+ brew install boost
+ brew list --versions boost
+
+ - name: Prepare the Rust toolchain
+ run: |
+ rustup target add aarch64-apple-darwin x86_64-apple-darwin
+ cargo fetch --locked --manifest-path out/openbf2-setup/core/rtp-bridge/Cargo.toml
+
+ - name: Import the Developer ID certificate (release)
+ if: env.BF2_RELEASE_SIGNING == 'true'
+ env:
+ MACOS_CERT_P12: ${{ secrets.MACOS_CERT_P12 }}
+ MACOS_CERT_PASSWORD: ${{ secrets.MACOS_CERT_PASSWORD }}
+ NOTARY_KEY_P8: ${{ secrets.NOTARY_KEY_P8 }}
+ NOTARY_KEY_ID: ${{ secrets.NOTARY_KEY_ID }}
+ run: |
+ bash out/openbf2/tools/macos/ci/release-signing.sh import
+ bash out/openbf2/tools/macos/ci/release-signing.sh notary-key
+
+ # SETUP_SIGN_IDENTITY unset means ad-hoc. In release runs the setup scripts sign with the
+ # imported identity, the hardened runtime, a timestamp and the two entitlements files.
+ - name: Build, test and package the app
+ run: |
+ if [ "$BF2_RELEASE_SIGNING" = true ]; then
+ export SETUP_SIGN_IDENTITY="$BF2_SIGN_IDENTITY"
+ export SETUP_ENTITLEMENTS_CLIENT="$GITHUB_WORKSPACE/out/openbf2/Code/Build/macos/bf2_client.entitlements"
+ export SETUP_ENTITLEMENTS_APP="$GITHUB_WORKSPACE/out/openbf2-setup/macos/OpenBF2.entitlements"
+ fi
+ bash out/openbf2-setup/macos/build-release.sh "$GITHUB_WORKSPACE/out/client-universal" "$GITHUB_WORKSPACE/out/packages-app/openbf2-macos.dmg" "$GITHUB_WORKSPACE/out/setup-build"
+
+ - name: Sign, check and notarize the disk image (release)
+ if: env.BF2_RELEASE_SIGNING == 'true'
+ env:
+ NOTARY_KEY_ID: ${{ secrets.NOTARY_KEY_ID }}
+ NOTARY_ISSUER_ID: ${{ secrets.NOTARY_ISSUER_ID }}
+ run: |
+ dmg=out/packages-app/openbf2-macos.dmg
+ bash out/openbf2/tools/macos/ci/release-signing.sh verify-dmg "$dmg"
+ bash out/openbf2/tools/macos/ci/release-signing.sh sign-dmg "$dmg"
+ bash out/openbf2/tools/macos/ci/release-signing.sh notarize "$dmg"
+ bash out/openbf2/tools/macos/ci/release-signing.sh staple "$dmg"
+
+ - name: Remove the signing keychain and key (release)
+ if: always() && env.BF2_RELEASE_SIGNING == 'true'
+ run: bash out/openbf2/tools/macos/ci/release-signing.sh cleanup
+
+ # After stapling: the ticket changes the image, so the checksum is written last.
+ - name: Write the disk image checksum
+ working-directory: out/packages-app
+ run: |
+ rm -f openbf2-macos.dmg.sha256
+ shasum -a 256 openbf2-macos.dmg > openbf2-macos.dmg.sha256
+
+ # The disk image cannot hold it (the setup build copies only the client's three files), so the
+ # build-info is a CI artifact beside the image: revision, setup app revision, the client's
+ # SHA-256s, the image's SHA-256 and the signing and notarization state.
+ - name: Write the disk image build-info
+ run: |
+ signing=adhoc
+ if [ "$BF2_RELEASE_SIGNING" = true ]; then signing=developer-id; fi
+ python3 out/openbf2/Code/Build/package_release.py --release macos --client-dir out/client-universal --dmg out/packages-app/openbf2-macos.dmg --setup-repository "$SETUP_REPOSITORY" --setup-revision "$SETUP_REVISION" --macos-signing "$signing" --output-dir out/build-info --revision "$GITHUB_SHA" --repository "$GITHUB_REPOSITORY"
+
+ - name: Upload the macOS app
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: release-macos
+ path: |
+ out/packages-app/openbf2-macos.dmg
+ out/packages-app/openbf2-macos.dmg.sha256
+ if-no-files-found: error
+ compression-level: 0
+ retention-days: 14
+
+ - name: Upload the disk image build-info
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: build-info-macos
+ path: out/build-info/openbf2-macos.build-info.json
+ if-no-files-found: error
+ retention-days: 14
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b677210d6..8104d3bbb 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -21,3 +21,6 @@ concurrency:
jobs:
build:
uses: ./.github/workflows/build.yml
+ # A reusable workflow only receives the `release` environment's secrets when the caller
+ # passes secrets on; without this they resolve to empty strings.
+ secrets: inherit
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 63c78e6e1..8701d4e29 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -14,6 +14,9 @@ concurrency:
jobs:
build:
uses: ./.github/workflows/build.yml
+ # A reusable workflow only receives the `release` environment's secrets when the caller
+ # passes secrets on; without this they resolve to empty strings.
+ secrets: inherit
upload:
name: Attach packages to the release
@@ -23,10 +26,12 @@ jobs:
permissions:
contents: write
steps:
- - name: Download this run's packages
+ # Only the release-* artifacts: one package per platform. The per-role and per-architecture
+ # packages-* artifacts stay CI artifacts (docs/ci-releases.md).
+ - name: Download this run's release packages
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
- pattern: packages-*
+ pattern: release-*
path: packages
merge-multiple: true
@@ -38,18 +43,37 @@ jobs:
working-directory: packages
shell: bash
run: |
- packages=(
- openbf2-windows-x86-server-diagnostic
- openbf2-windows-x86-client-diagnostic
- openbf2-windows-x86-editor-diagnostic
- openbf2-windows-x64-server
- openbf2-linux-x64-server
- )
+ # Both Windows clients bundle OpenAL Soft (LGPL): the release carries the exact source.
+ shopt -s nullglob
+ sources=(openal-soft-*.tar.bz2)
+ shopt -u nullglob
+ test "${#sources[@]}" -eq 1
+ files=(openbf2-macos.dmg openbf2-windows.zip openbf2-linux.zip "${sources[0]}")
assets=()
- for package in "${packages[@]}"; do
- test -s "$package.zip"
- test -s "$package.zip.sha256"
- sha256sum --check "$package.zip.sha256"
- assets+=("$package.zip" "$package.zip.sha256")
+ for file in "${files[@]}"; do
+ test -s "$file"
+ test -s "$file.sha256"
+ sha256sum --check "$file.sha256"
+ assets+=("$file" "$file.sha256")
done
+ # Exactly these assets: nothing else may reach the release page.
+ expected=$(printf '%s\n' "${assets[@]}" | sort)
+ actual=$(ls -A | sort)
+ if [ "$expected" != "$actual" ]; then
+ echo "::error title=Unexpected release files::expected only: ${assets[*]}"
+ diff <(echo "$expected") <(echo "$actual") || true
+ exit 1
+ fi
+ # build.yml fails release runs without D3DX; check the archive itself as well.
+ python3 - <<'EOF'
+ import json
+ import zipfile
+
+ with zipfile.ZipFile("openbf2-windows.zip") as archive:
+ names = set(archive.namelist())
+ info = json.loads(archive.read("openbf2-windows/build-info.json"))
+ for entry in ("x64/BF2.exe", "x86/BF2.exe", "server/bf2_w32ded.exe", "editor/BF2Editor.exe"):
+ assert "openbf2-windows/" + entry in names, "openbf2-windows.zip lacks " + entry
+ assert not info.get("omitted"), "openbf2-windows.zip omits " + ", ".join(info["omitted"])
+ EOF
gh release upload --repo "$GH_REPO" --clobber -- "$RELEASE_TAG" "${assets[@]}"
diff --git a/.gitignore b/.gitignore
index c77f458a2..3e44e4252 100644
--- a/.gitignore
+++ b/.gitignore
@@ -78,6 +78,7 @@ compile_commands.json
!/Code/Build/bf2audio_diff/
!/Code/Build/bf2audio_smoke/
!/Code/Build/textureatlas_diff/
+!/Code/Build/macos/
!/Code/Build/bin/
/Code/Build/bin/**
!/Code/Build/bin/README.md
diff --git a/.run/bf2_client (game dir).run.xml b/.run/bf2_client (game dir).run.xml
index 97e5a2de4..570273f29 100644
--- a/.run/bf2_client (game dir).run.xml
+++ b/.run/bf2_client (game dir).run.xml
@@ -1,7 +1,7 @@
-
+
-
+
\ No newline at end of file
diff --git a/AGENTS.md b/AGENTS.md
index e192106ca..7a8769ef0 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -4,6 +4,27 @@ This is the canonical policy for every coding agent working in this repository.
instruction files must import or point here instead of copying these rules. If guidance conflicts,
the user's current request wins, followed by this file, then the subsystem documentation.
+## Code Review Rules
+
+For code review and regression investigation, also read [docs/reviewing.md](docs/reviewing.md).
+This file remains the canonical policy. Review alone does not authorize source changes;
+explicit user authorization to implement fixes still applies.
+
+- **Report concrete regressions.** Review the PR diff and affected callers for memory/lifetime
+ errors, initialization and teardown failures, malformed-input handling, and broken builds.
+ Explain the reachable trigger and consequence; distinguish pre-existing defects from changes
+ introduced by the PR. Legacy style, raw pointers, lack of Asio, and opportunities to adopt
+ newer C++ are not defects by themselves.
+- **Preserve the applicable compatibility contract.** Check ABI, protocols, serialized data,
+ and reconstructed behavior for each affected image and architecture. Respect the documented,
+ issue-backed native ABI and editor exceptions; do not restore retired compatibility adapters
+ or infer unknown signatures and layouts. State missing binary evidence and continue checks
+ that do not depend on it.
+- **Account for parallel upstream work.** Where accessible, inspect relevant B2BF/OpenBF2 PRs
+ and branches at their current SHAs. Identify semantic conflicts and existing fixes with
+ evidence; upstream code is not automatically proof of correctness. State unavailable context
+ and continue the scoped review instead of assuming that another branch was checked.
+
## Agent prerequisites and human ownership
- Before implementing behavior as recovered engine code, the agent must have **IDA or Ghidra
@@ -150,6 +171,42 @@ Use the repository's evidence vocabulary consistently:
frontiers because `BF2Log` may not be initialized yet. If the signature/ABI is not known well
enough to define a safe callable body, keep the symbol declaration-only and document the caller
boundary instead of inventing a signature merely to add logging.
+ **Unimplemented-slot exception (owner decision 2026-11-02, libaidll reconstruction):** a
+ virtual slot that is `__cxa_pure_virtual` in every vtable of every class that has it, in
+ every inspected image, has no body anywhere. Reaching it in retail aborts with "pure virtual method
+ called". The same applies to a class member that no instruction reads or writes. Its name and
+ source-level type cannot be recovered, but its behaviour is fully determined.
+ - Such a slot or member may be declared with a `[CHOSEN, not recovered]` name, so that the
+ surrounding recovered code can be completed.
+ - The declaration must reproduce what the instructions prove:
+ - the slot position in both ELF vtables;
+ - the receiver and argument registers or stack slots each call site prepares;
+ - whether any caller reads a result (if none does, declare `void`; if a caller tests `eax`/`al`,
+ declare the narrowest integer type the test proves);
+ - for a member, the size and alignment implied by the neighbouring offsets in each image.
+ - Keep the slot pure (`= 0`); never give it a body. Every call site stays exactly as the listing
+ shows.
+ - Cite the vtable addresses and call-site addresses beside the declaration.
+
+ This covers only slots and members with no body and no access. A slot that has an override
+ anywhere, or a member that is accessed anywhere, keeps the ordinary evidence rules. The matching
+ build (`MATCHING_BUILD_PLAN.md`) re-checks every such declaration at its call sites.
+
+ **Unobservable-type exception (owner decision 2026-11-05, RendDX9 reconstruction):** a body may be
+ recovered with a `[CHOSEN, not recovered]` type or name when all of the following hold:
+ - no inspected image (retail PE, `_r`, editor, Linux ELF) has a caller that reaches it, or every
+ reachable path only ever sees empty data, so its behaviour is fully determined;
+ - the instructions of every image have been read and the body reproduces everything they prove
+ (reads, writes, offsets, call order, slot dispatch, return register);
+ - only a name or a type that no instruction can expose is missing. Examples: the element type of a
+ container that is never filled, or the name of a property pair that nothing calls.
+
+ Mark each chosen piece `[CHOSEN, not recovered]` beside it, with the evidence (addresses in every
+ image, and why the choice cannot be observed). Prefer the choice the instructions point to, such as
+ float for an `st0` return. This replaces a [FRONTIER] stop only in that situation; a body that any
+ path reaches with real data keeps the ordinary evidence rules. First applied to: LightManager +0xBC/+0xC0
+ (PE 0x1015C130/0x1015C140), GeometryTemplateManager +0x2C/+0x30 (PE 0x1015D940/0x1015D430) and
+ ObjectDrawer::flushDeferredGeometry (PE 0x100F8C00).
- Test fixtures belong under `Code/Tests`, must be labeled as scaffolding, and may
only model the specific condition the test needs.
- When a production implementation lands, remove any Probe/harness override that would shadow it.
@@ -191,8 +248,9 @@ Use the repository's evidence vocabulary consistently:
sound it would have driven; each call site keeps its own hit count and is rate-limited, never
silenced; NO value is fabricated, because every shipped call site discards the result, so
continuing returns nothing at all; and the surrounding body is written as far as the evidence
- honestly reaches, so the seam covers only the sound call. The shared implementation and the full
- rule live in `Code/BF2/Core/SoundSeamFrontier.h`; it reports to stderr only, deliberately, because
+ honestly reaches, so the seam covers only the sound call. No sound seam remains (the shared
+ helper `Core/SoundSeamFrontier.h` was removed with its last caller); a future sound seam re-adds
+ that helper with this rule. It reports to stderr only, deliberately, because
`Debug(DebugTypeError, ...)` aborts in this tree and `BF2Log` is not guaranteed to be up on the
HUD paths that reach these seams. The cost is real and is the point: a sound retail would start or
stop keeps doing whatever it was doing. This exception covers sound seams ONLY - every other
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dd83553e6..045a2ad43 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,31 +8,60 @@ if(POLICY CMP0141)
endif()
project(BF2Rebuilt LANGUAGES C CXX)
+# [CHOSEN, not recovered] Header-selection preparation for the G2w forwarding backend.
+option(BF2_GFX_SEAM "Compile the renderer against the D3D9/D3DX subset headers" OFF)
+# [CHOSEN, not recovered] Release packaging (owner decision 2026-11-14): CI's release configure steps
+# turn this ON so the plugin kit's frontier trap (Code/RendDX9Abi/Frontier.cpp) logs and continues
+# when its env var is unset. OFF - dev builds and every gate - keeps the armed (abort) default. An
+# explicit env value (continue / abort) wins in both. Reaches the .cmd image builds as the env var
+# BF2_FRONTIER_DEFAULT_CONTINUE=ON|OFF (always passed, so a stray shell variable cannot flip it).
+option(BF2_FRONTIER_DEFAULT_CONTINUE "Frontier trap defaults to continue (release packages)" OFF)
+if(BF2_FRONTIER_DEFAULT_CONTINUE)
+ set(BF2_FRONTIER_DEFAULT_ENV "${CMAKE_COMMAND}" -E env BF2_FRONTIER_DEFAULT_CONTINUE=ON)
+else()
+ set(BF2_FRONTIER_DEFAULT_ENV "${CMAKE_COMMAND}" -E env BF2_FRONTIER_DEFAULT_CONTINUE=OFF)
+endif()
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+ # [CHOSEN, not recovered] The macOS client's Cocoa host is Objective-C++ (docs/macos-s2-4.md).
+ enable_language(OBJCXX)
+endif()
# =================================================================================================
# TOOLCHAINS (2026-09-29). Three configurations, one source tree:
-# * MSVC x86 - the retail-fidelity reconstruction: bf2_w32ded.exe, /FORCE diagnostic link.
+# * MSVC x86 - the retail-fidelity reconstruction: bf2_w32ded.exe, strict link.
# * MSVC x64 - the native Windows dedicated port: bf2_w64ded.exe, strict link.
# * GCC/Clang, Linux - the native Linux dedicated port: `bf2` + `libdice_py.so`. It is the x64
# x86-64 port's pointer-bearing layouts compiled by the platform family the ELF
# oracle was built for.
-# Everything Linux-specific in this file sits under BF2_BUILD_LINUX; the MSVC configurations are
-# untouched by it. The Linux build is a native port (`[CHOSEN, not recovered]` layouts, like x64),
-# not a reproduction of the shipped 32-bit ELF's object layouts.
+# * AppleClang, macOS - the native macOS dedicated port: `bf2` + `libdice_py.dylib`, the Linux
+# port's sources and layouts built for Darwin (docs/macos-port.md).
+# Linux and macOS form the POSIX family (BF2_BUILD_POSIX); what they share sits under that switch,
+# and only what genuinely differs sits under BF2_BUILD_LINUX or BF2_BUILD_MACOS. The MSVC
+# configurations are untouched by any of them. Both POSIX builds are native ports
+# (`[CHOSEN, not recovered]` layouts, like x64), not reproductions of the shipped 32-bit ELF's
+# object layouts. The macOS configuration is an intentional port change requested by the project
+# owner, `[CHOSEN, not recovered]` throughout.
# =================================================================================================
set(BF2_BUILD_LINUX OFF)
+set(BF2_BUILD_MACOS OFF)
+set(BF2_BUILD_POSIX OFF)
if(MSVC)
# The two Windows configurations, selected by pointer width below.
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(BF2_BUILD_LINUX ON)
+ set(BF2_BUILD_POSIX ON)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ # [CHOSEN, not recovered] AppleClang (or upstream Clang) on macOS: the macos-x64 preset.
+ set(BF2_BUILD_MACOS ON)
+ set(BF2_BUILD_POSIX ON)
else()
message(FATAL_ERROR
- "BF2Rebuilt builds with MSVC on Windows (msvc-x86 / msvc-x64 presets) or with GCC/Clang on "
- "Linux x86-64 (linux-x64 preset). This toolchain is ${CMAKE_CXX_COMPILER_ID} on "
- "${CMAKE_SYSTEM_NAME}.")
+ "BF2Rebuilt builds with MSVC on Windows (msvc-x86 / msvc-x64 presets), with GCC/Clang on "
+ "Linux x86-64 (linux-x64 preset) or with Clang on macOS (macos-x64 preset). This "
+ "toolchain is ${CMAKE_CXX_COMPILER_ID} on ${CMAKE_SYSTEM_NAME}.")
endif()
-if(CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT BF2_BUILD_LINUX)
+if(CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT BF2_BUILD_POSIX)
set(BF2_BUILD_X64 OFF)
set(BF2_NATIVE_ARCH "x86")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
@@ -45,6 +74,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS
"Configuring the native Linux x86-64 dedicated-server port (bf2 + libdice_py.so). "
"See docs/building.md for toolchain and runtime setup.")
+ elseif(BF2_BUILD_MACOS)
+ set(BF2_NATIVE_ARCH "macos-${CMAKE_SYSTEM_PROCESSOR}")
+ message(STATUS
+ "Configuring the native macOS ${CMAKE_SYSTEM_PROCESSOR} dedicated-server port "
+ "(bf2 + libdice_py.dylib). See docs/building.md and docs/macos-port.md.")
else()
set(BF2_NATIVE_ARCH "x64")
message(STATUS
@@ -54,7 +88,7 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
else()
message(FATAL_ERROR
"BF2Rebuilt supports only MSVC x86 (retail-fidelity), MSVC x64 (native dedicated port) "
- "and Linux x86-64 (native dedicated port) configurations; "
+ "and 64-bit Linux/macOS (native dedicated port) configurations; "
"CMAKE_SIZEOF_VOID_P=${CMAKE_SIZEOF_VOID_P}.")
endif()
@@ -113,7 +147,10 @@ set(bf2_engine_sources)
set(bf2_engine_headers)
foreach(component_path IN LISTS bf2_component_paths)
get_filename_component(component_name "${component_path}" NAME)
- if(IS_DIRECTORY "${component_path}" AND NOT component_name STREQUAL "External")
+ # Memory is the recovered Memory.dll, its own image (bf2_memory, Code/BF2/Memory/CMakeLists.txt);
+ # the engine keeps its own memory:: stubs, so its units must not join the engine source list.
+ if(IS_DIRECTORY "${component_path}" AND NOT component_name STREQUAL "External"
+ AND NOT component_name STREQUAL "Memory")
file(GLOB_RECURSE component_sources
CONFIGURE_DEPENDS
"${component_path}/*.cpp"
@@ -129,6 +166,17 @@ foreach(component_path IN LISTS bf2_component_paths)
endif()
endforeach()
list(SORT bf2_engine_sources)
+# [CHOSEN, not recovered] The CPU effect library has its own image and source manifest.
+list(REMOVE_ITEM bf2_engine_sources
+ "${BF2_ROOT}/Platform/Gfx/Effect/Cache.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Effect/Runtime.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Effect/D3DAsm.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Effect/FxBuild.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Effect/FxParser.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Effect/FxStates.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Effect/Native.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Effect/NativeMojo.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Effect/NativeVkd3d.cpp")
list(SORT bf2_engine_headers)
# These translation units belong to AIDLL_w32ded.dll, not bf2_w32ded.exe. The source tree is
@@ -138,89 +186,16 @@ list(SORT bf2_engine_headers)
# Its AIDLL-only half WAS SPLIT OUT on 2026-09-08 into AI/AIDLL/AI/Main/AISingletonServer.cpp, which
# this list excludes - `AISingletonServer` exists only in libaidll.so. The side-DLL target that the
# old note was waiting for is Code/Build/aidll.cmd plus bf2_aidll below.
-set(bf2_aidll_only_sources
+# AIDLL_w32ded.dll / libaidll owns every TU under AI/AIDLL except the shared singleton bridge
+# (the same directory rule as Code/Build/build.cmd), plus three units outside it. This list is an
+# exclusion set for the engine image only, so its order is irrelevant; the DLL's own link order is
+# the explicit bf2_aidll_sources manifest below.
+file(GLOB_RECURSE bf2_aidll_only_sources CONFIGURE_DEPENDS "${BF2_ROOT}/AI/AIDLL/*.cpp")
+list(REMOVE_ITEM bf2_aidll_only_sources "${BF2_ROOT}/AI/AIDLL/AI/Main/CommonSingletonServer.cpp")
+list(APPEND bf2_aidll_only_sources
"${BF2_ROOT}/Core/DllModule.cpp"
"${BF2_ROOT}/Core/DllGlobals.cpp" # the side-DLL image's globals TU
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/BotMain.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/BotNavigation.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/BotSquad.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/SensingAgent.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/CommunicationAgent.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/BotSenses.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIPlanInterpreter/BAPContext.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/InformationManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/Information.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/WeaponInfo.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIArmament.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIArmamentReal.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPICover.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIMobile.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIMobileReal.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIMobileKnown.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIUnit.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/InformationReal.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/WeaponInfoReal.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIPhysicalReal.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIUtils/VehicleOccupancy.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/BFInformationEnvironment.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/AIInformationGrid.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIUtils/DebugRendering/AIRenderUtil.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/WeaponInfoManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/BFInformationCourier.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/InformationFactory.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicMap/BFStrategicEnvironment.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicMap/BotSpawner.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/DrawPrimitives/DPManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AICollisionHandler.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIEventCourier.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIMineManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIPlayerCourier.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/BFPathfindingCourier.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/Material/Material.cpp" # libaidll materialId parser
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/Material/MaterialManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/NavMesh/MapProperties.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/NavMesh/QuadTreeManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/NavMesh/QuadTree.cpp" # libaidll only - chunk 04
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/NavMesh/QuadTreeNode.cpp" # libaidll only - live polygon query
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/Cluster/ClusterGraph.cpp" # libaidll only - chunk 04
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/Cluster/ClusterNodeManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/NavMesh/QTSearchNodeManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicMap/AerialHeightMap.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIPlanInterpreter/BAPEntries.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/SensingAgentPatterns.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/SquadManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/SquadCoordinator.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/SquadFormation.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/SquadMember.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIBotBehaviour/CustomCurve.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/BotMemory.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/BotSubObjects.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBotBehaviour/UrgencyMerger.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIConsole.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIBotBehaviour/UrgeCurve.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/CoverPosition/CPNodeManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/CoverPosition/CoverPositionManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/AIStrategicObjectManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/AILandingZoneManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/AIStrategicObject.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/AIStrategicArea.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/SAWayPoint.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategic/SAI.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/BotBehaviourManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/CommunicationHub.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/StrategyManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIPathfinding.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/IAIPathfinding.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/UserOrderManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIMain.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIModule.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIRandom.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AILODManager.cpp" # libaidll only - chunk 02
- "${BF2_ROOT}/AI/AIDLL/AI/Main/IBotManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AISettings.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AISingletonServer.cpp" # libaidll only - see the split, below
- "${BF2_ROOT}/AI/AIDLL/AI/Main/BF2AI.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/BotManager.cpp"
+ "${BF2_ROOT}/Math/DoubleVec3.cpp"
)
list(REMOVE_ITEM bf2_engine_sources ${bf2_aidll_only_sources})
@@ -246,6 +221,8 @@ list(REMOVE_ITEM bf2_engine_sources "${BF2_ROOT}/VoipServer/BF2VoipServerShell.c
# carries the mirror list). Client-only REGIONS of shared TUs are not a manifest matter: they sit
# under #if !DEDICATED, and bf2_set_image() below is what selects them per target.
set(bf2_client_only_sources
+ "${BF2_ROOT}/Game/PunkBuster/PbClient.cpp" # BF2.exe 0x435900..0x436434; the ELF has only the server half
+ "${BF2_ROOT}/Game/GameLogic/PlayerVOHelp.cpp" # BF2.exe client tutorial owner; placement inferred
"${BF2_ROOT}/Math/Mat4Inverse.cpp" # client PE inverse; explicitly reused by x86 bf2_aidll below
"${BF2_ROOT}/Game/Main/BF2Window.cpp" # the game window (2026-09-02); its body is #if !DEDICATED as well
"${BF2_ROOT}/Game/Main/BF2FrameInterpolator.cpp" # attested client-only TU; ctor recovered 2026-09-03
@@ -274,13 +251,18 @@ set(bf2_client_only_sources
"${BF2_ROOT}/Menu/HudConsoleBindings.cpp"
"${BF2_ROOT}/Menu/ProfileConsoleBindings.cpp"
"${BF2_ROOT}/Menu/ClientUiFrontiers.cpp"
- "${BF2_ROOT}/Game/Main/BF2ClientFrontiers.cpp"
"${BF2_ROOT}/Game/LocalProfileManager.cpp"
"${BF2_ROOT}/Game/LocalProfileManagerInit.cpp"
"${BF2_ROOT}/Game/LocalProfileManagerOperations.cpp"
"${BF2_ROOT}/Game/LocalProfileManagerSelection.cpp"
"${BF2_ROOT}/Game/LocalProfileManagerDiscovery.cpp"
"${BF2_ROOT}/Game/LocalProfileManagerFields.cpp"
+ "${BF2_ROOT}/Game/DistributedLightRenderer/DistributedLightRenderer.cpp"
+ "${BF2_ROOT}/Game/VoipClient/BF2VoipClient.cpp" # BF2.exe 0x4510F0..0x45235C
+ "${BF2_ROOT}/Game/VoipClient/VoipClient.cpp" # BF2.exe 0x736C30..0x737D4E
+ "${BF2_ROOT}/Game/VoipClient/VoipMixer.cpp" # BF2.exe 0x7356B0..0x736BA0
+ "${BF2_ROOT}/Game/VoipClient/VoipMixerCoreAudio.cpp" # [PLATFORM] macOS backend; empty elsewhere
+ "${BF2_ROOT}/Game/VoipClient/VoipFakeDevice.cpp" # [CHOSEN] BF2_VOIP_CAPTURE=fake test device
"${BF2_ROOT}/Game/LocalProfileManagerSuffix.cpp"
"${BF2_ROOT}/Game/ProfileManager.cpp" # native online-profile lifetime/status owner
"${BF2_ROOT}/Game/PasswordCodec.cpp" # inferred path; the profile password's CryptProtectData wrapper
@@ -313,6 +295,7 @@ set(bf2_client_only_sources
"${BF2_ROOT}/Menu/Bf2ButtonNode.cpp"
"${BF2_ROOT}/Menu/Bf2NewListBoxNode.cpp"
"${BF2_ROOT}/Menu/Bf2EditNode.cpp"
+ "${BF2_ROOT}/Menu/Bf2TileNode.cpp"
"${BF2_ROOT}/Menu/Bf2MiniMenuMapNode.cpp"
"${BF2_ROOT}/Menu/Bf2TransformListNode.cpp"
"${BF2_ROOT}/External/BFMeme/SliderNode.cpp"
@@ -345,6 +328,7 @@ set(bf2_client_only_sources
"${BF2_ROOT}/Menu/BfNewListBoxNode.cpp" # recovered list-node storage; publication withheld
"${BF2_ROOT}/Menu/BfListBoxData.cpp" # descriptor-attested shared chat/list data; node hooks open
"${BF2_ROOT}/Menu/Ref2System.cpp" # recovered UI root construction; publication still gated
+ "${BF2_ROOT}/Menu/HudWidescreen.cpp" # issue #33: opt-in native vanilla HUD policy
"${BF2_ROOT}/Menu/Font.cpp"
"${BF2_ROOT}/Menu/DifFontMetadata.cpp"
"${BF2_ROOT}/Menu/FontLoader.cpp"
@@ -356,6 +340,7 @@ set(bf2_client_only_sources
"${BF2_ROOT}/External/BFMeme/Event.cpp"
"${BF2_ROOT}/External/BFMeme/Action.cpp"
"${BF2_ROOT}/External/BFMeme/Function.cpp"
+ "${BF2_ROOT}/External/BFMeme/Tree.cpp"
"${BF2_ROOT}/External/BFMeme/TypeDescriptor.cpp"
"${BF2_ROOT}/External/BFMeme/NamedObjectRegistry.cpp"
"${BF2_ROOT}/External/BFMeme/Data.cpp"
@@ -410,7 +395,6 @@ set(bf2_client_only_sources
"${BF2_ROOT}/IO/Input/KeyboardDevice.cpp"
"${BF2_ROOT}/IO/Input/MouseDevice.cpp"
"${BF2_ROOT}/IO/Input/GameControllerDevice.cpp"
- "${BF2_ROOT}/IO/Input/FalconDevice.cpp"
"${BF2_ROOT}/IO/Input/DX8InputDeviceManager.cpp"
"${BF2_ROOT}/Sound/BfSound/MusicPlayer.cpp" # attested client-only TU (2026-09-02); body #if !DEDICATED as well
"${BF2_ROOT}/Menu/MenuTeamManager.cpp"
@@ -427,12 +411,13 @@ endif()
# Game/Main/StatusMonitorImpl_win32.cpp and IO/File/Win32FileSystem.cpp, the ELF attests
# IO/File/UnixFileSystem.cpp and StatusMonitorImpl_posix. The POSIX pair already compiles to an empty
# TU under MSVC by its own guards; the Win32 pair is whole-file Win32 API with no guard, so it leaves
-# the manifest on Linux instead. Same discipline as the AIDLL and client lists above.
+# the manifest on Linux instead. Same discipline as the AIDLL and client lists above. macOS takes
+# the POSIX pair as well ([CHOSEN, not recovered]: there was no retail macOS server).
set(bf2_win32_only_sources
"${BF2_ROOT}/IO/File/Win32FileSystem.cpp"
"${BF2_ROOT}/Game/Main/StatusMonitorImpl_win32.cpp"
)
-if(BF2_BUILD_LINUX)
+if(BF2_BUILD_POSIX)
list(REMOVE_ITEM bf2_engine_sources ${bf2_win32_only_sources})
endif()
@@ -539,7 +524,12 @@ endfunction()
# own portability layer selects its Linux branch from _LINUX (gsPlatform.h, "Linux: _LINUX + _UNIX").
function(bf2_configure_c_target target)
if(MSVC)
- target_compile_options("${target}" PRIVATE /W3 /wd4996)
+ # The SDK code stays as it ships. C5287: GameSpy compares two different enum types. On x64,
+ # C4244/C4267 are GameSpy's string, packet and buffer lengths (size_t, pointer differences)
+ # held in int or DWORD, and C4311/C4312 are buddy and block indices passed through a
+ # callback's void* user data and back (gpiBuddy.c, gpiProfile.c). Both round-trip losslessly at
+ # the sizes GameSpy handles, with the same 32-bit semantics as the x86 build.
+ target_compile_options("${target}" PRIVATE /W3 /wd4996 /wd5287 /wd4244 /wd4267 /wd4311 /wd4312)
else()
target_compile_options("${target}" PRIVATE
-fno-strict-aliasing
@@ -554,6 +544,9 @@ function(bf2_configure_c_target target)
)
if(BF2_BUILD_LINUX)
target_compile_definitions("${target}" PRIVATE _LINUX _GNU_SOURCE)
+ elseif(BF2_BUILD_MACOS)
+ # [CHOSEN, not recovered] The SDK's own Darwin branch ("MacOSX: _MACOSX + _UNIX").
+ target_compile_definitions("${target}" PRIVATE _MACOSX)
endif()
endif()
bf2_add_compile_debug_info("${target}")
@@ -586,12 +579,18 @@ endfunction()
# The embedded CPython's headers: Include/ plus the platform pyconfig.h directory. Windows uses the
# vendored PC/pyconfig.h; Linux uses the configure-generated pyconfig.h vendored under
-# External/python-embedded/linux/ (a chosen path - see that directory's README).
+# External/python-embedded/linux/ (a chosen path - see that directory's README); macOS uses the
+# Darwin configure output vendored under External/python-embedded/macos/ ([CHOSEN, not recovered]).
if(BF2_BUILD_LINUX)
set(BF2_PYTHON_INCLUDE_DIRS
"${BF2_EXTERNAL_ROOT}/python-embedded/linux"
"${BF2_EXTERNAL_ROOT}/python-embedded/py-src-2.3.4/Include"
)
+elseif(BF2_BUILD_MACOS)
+ set(BF2_PYTHON_INCLUDE_DIRS
+ "${BF2_EXTERNAL_ROOT}/python-embedded/macos"
+ "${BF2_EXTERNAL_ROOT}/python-embedded/py-src-2.3.4/Include"
+ )
else()
set(BF2_PYTHON_INCLUDE_DIRS
"${BF2_EXTERNAL_ROOT}/python-embedded/py-src-2.3.4/Include"
@@ -611,6 +610,12 @@ if(BF2_BUILD_LINUX)
set(CURSES_NEED_NCURSES TRUE)
set(CURSES_NEED_WIDE TRUE)
find_package(Curses REQUIRED)
+elseif(BF2_BUILD_MACOS)
+ # [CHOSEN, not recovered] The macOS SDK's system ncurses (libncurses.tbd) carries the same
+ # entry points; the SDK has no separate libncursesw, so the wide variant is not requested.
+ find_package(Threads REQUIRED)
+ set(CURSES_NEED_NCURSES TRUE)
+ find_package(Curses REQUIRED)
endif()
add_library(bf2_engine_objects OBJECT
@@ -625,12 +630,19 @@ if(BF2_BUILD_X64 AND MSVC)
# build failure. Explicit fixed-width wire conversions remain reviewable in source.
target_compile_options(bf2_engine_objects PRIVATE /Gy /we4244 /we4267 /we4311 /we4312)
endif()
-if(BF2_BUILD_LINUX)
+if(BF2_BUILD_POSIX)
target_include_directories(bf2_engine_objects PRIVATE ${CURSES_INCLUDE_DIRS})
# The engine's own GameSpy-facing TUs (persistence, match-making, HTTP) include the SDK headers,
- # whose platform switch is _LINUX (gsPlatform.h) - the same define bf2_configure_c_target gives
- # the SDK's C objects.
- target_compile_definitions(bf2_engine_objects PRIVATE _LINUX)
+ # whose platform switch is _LINUX or _MACOSX (gsPlatform.h) - the same define
+ # bf2_configure_c_target gives the SDK's C objects. BF2_PLATFORM_POSIX selects the engine's
+ # POSIX implementations (UnixFileSystem, the ncurses status monitor) on every POSIX family
+ # member, including macOS, whose compilers do not define __unix__.
+ target_compile_definitions(bf2_engine_objects PRIVATE BF2_PLATFORM_POSIX)
+ if(BF2_BUILD_LINUX)
+ target_compile_definitions(bf2_engine_objects PRIVATE _LINUX)
+ else()
+ target_compile_definitions(bf2_engine_objects PRIVATE _MACOSX)
+ endif()
endif()
# The client is a second compilation of the shared engine sources, not a relink of
@@ -643,6 +655,16 @@ set(bf2_client_sources
)
list(REMOVE_DUPLICATES bf2_client_sources)
list(SORT bf2_client_sources)
+if(BF2_BUILD_MACOS)
+ # [CHOSEN, not recovered] The macOS client replaces the DirectInput 8 devices with
+ # MacInputDeviceManager and the Mac*Device TUs (docs/macos-s2-4.md). The Linux and MSVC client
+ # manifests are unchanged.
+ list(REMOVE_ITEM bf2_client_sources
+ "${BF2_ROOT}/IO/Input/DX8InputDeviceManager.cpp"
+ "${BF2_ROOT}/IO/Input/KeyboardDevice.cpp"
+ "${BF2_ROOT}/IO/Input/MouseDevice.cpp"
+ "${BF2_ROOT}/IO/Input/GameControllerDevice.cpp")
+endif()
add_library(bf2_client_objects OBJECT EXCLUDE_FROM_ALL
${bf2_client_sources}
${bf2_engine_headers}
@@ -654,14 +676,30 @@ bf2_set_platform_compat(bf2_client_objects)
# same MSVC STL layout even when this CMake tree is configured as Debug; iterator debugging changes
# container layout and cannot cross the image boundary. PluginAbi.h enforces the matching contract.
target_compile_definitions(bf2_client_objects PRIVATE
- BF2_PLUGIN_ABI_NATIVE=1
_ITERATOR_DEBUG_LEVEL=0
)
+# [CHOSEN, not recovered] The native x64 client (https://github.com/B2BF/OpenBF2/issues/7): a pointer
+# truncated into a 32-bit integer fails the build, as in the plugin scripts' x64 mode. The editor's
+# own objects and its second compilation of shared TUs take the same list.
+set(BF2_CLIENT_X64_COMPILE_OPTIONS)
+if(BF2_BUILD_X64 AND MSVC)
+ set(BF2_CLIENT_X64_COMPILE_OPTIONS /Gy /we4311 /we4312)
+endif()
+target_compile_options(bf2_client_objects PRIVATE ${BF2_CLIENT_X64_COMPILE_OPTIONS})
target_include_directories(bf2_client_objects PRIVATE
${BF2_PYTHON_INCLUDE_DIRS}
"${BF2_EXTERNAL_ROOT}/zlib-1.2.3"
"${BF2_EXTERNAL_ROOT}/zlib-1.2.3/contrib/minizip"
)
+if(BF2_BUILD_MACOS)
+ # [CHOSEN, not recovered] The macOS client (docs/macos-port.md, "Client triage") compiles the
+ # shared engine sources with the platform switches the macOS server objects use:
+ # BF2_PLATFORM_POSIX selects the POSIX file system and status monitor, _MACOSX the GameSpy
+ # SDK's Darwin branch, BF2_STATIC_PLUGINS the statically linked plugin images
+ # (Code/StaticPlugins). The Linux and MSVC client objects are unchanged.
+ target_include_directories(bf2_client_objects PRIVATE ${CURSES_INCLUDE_DIRS})
+ target_compile_definitions(bf2_client_objects PRIVATE BF2_PLATFORM_POSIX _MACOSX BF2_STATIC_PLUGINS=1)
+endif()
source_group(TREE "${BF2_ROOT}" PREFIX "BF2" FILES
${bf2_client_sources}
${bf2_engine_headers}
@@ -830,6 +868,46 @@ source_group(TREE "${BF2_EXTERNAL_ROOT}/GameSpy"
FILES ${bf2_gamespy_cdkeyc_sources}
)
+# =================================================================================================
+# bf2_gamespy_voice_objects - GameSpy Voice 2 and its Speex 1.0.5 codec, statically linked in BF2.exe
+# (the client voice client, Game/VoipClient). Stock upstream C, LINKED not reversed: the Voice2 core,
+# the platform's hardware layer (DirectSound on Windows, as retail; the SDK's CoreAudio layer on macOS)
+# and the custom-device file the test device builds on. Speex: only the libspeex files the narrowband
+# and wideband codecs need - no SLOW_TRIG, no tools (External/speex-1.0.5/LOCAL_CHANGES.md).
+# Client images only.
+# =================================================================================================
+set(bf2_gamespy_voice_sources
+ "${BF2_EXTERNAL_ROOT}/GameSpy/Voice2/gvMain.c"
+ "${BF2_EXTERNAL_ROOT}/GameSpy/Voice2/gvSource.c"
+ "${BF2_EXTERNAL_ROOT}/GameSpy/Voice2/gvFrame.c"
+ "${BF2_EXTERNAL_ROOT}/GameSpy/Voice2/gvCodec.c"
+ "${BF2_EXTERNAL_ROOT}/GameSpy/Voice2/gvSpeex.c"
+ "${BF2_EXTERNAL_ROOT}/GameSpy/Voice2/gvDevice.c"
+ "${BF2_EXTERNAL_ROOT}/GameSpy/Voice2/gvUtil.c"
+ "${BF2_EXTERNAL_ROOT}/GameSpy/Voice2/gvCustomDevice.c"
+)
+if(WIN32)
+ list(APPEND bf2_gamespy_voice_sources "${BF2_EXTERNAL_ROOT}/GameSpy/Voice2/gvDirectSound.c")
+elseif(APPLE)
+ list(APPEND bf2_gamespy_voice_sources "${BF2_EXTERNAL_ROOT}/GameSpy/Voice2/gvOSXAudio.c")
+endif()
+foreach(speex_unit bits cb_search exc_10_16_table exc_10_32_table exc_20_32_table exc_5_256_table
+ exc_5_64_table exc_8_128_table filters gain_table gain_table_lbr hexc_10_32_table hexc_table
+ high_lsp_tables lpc lsp lsp_tables_nb ltp misc modes nb_celp quant_lsp sb_celp speex_callbacks
+ vbr vq)
+ list(APPEND bf2_gamespy_voice_sources "${BF2_EXTERNAL_ROOT}/speex-1.0.5/libspeex/${speex_unit}.c")
+endforeach()
+# Client/test dependencies opt in; Linux dedicated builds have no Voice2 hardware backend.
+add_library(bf2_gamespy_voice_objects OBJECT EXCLUDE_FROM_ALL ${bf2_gamespy_voice_sources})
+bf2_configure_c_target(bf2_gamespy_voice_objects)
+target_include_directories(bf2_gamespy_voice_objects PRIVATE
+ "${BF2_EXTERNAL_ROOT}/speex-1.0.5/include"
+ "${BF2_EXTERNAL_ROOT}/speex-1.0.5/include/speex") # gvSpeex.c includes
+source_group(TREE "${BF2_EXTERNAL_ROOT}"
+ PREFIX "External"
+ FILES ${bf2_gamespy_voice_sources}
+)
+
# Client ProfileManager uses the stock presence SDK. Source set follows the
# upstream gp/gptestc project, excluding its sample and already shared common TUs.
set(bf2_gamespy_gp_sources
@@ -899,9 +977,9 @@ set_target_properties(bf2_engine_objects bf2_zlib_objects bf2_tinyxml_objects
# harness (bounded frames, object probes, RVA-printing fault handler) lives in Code/Build/bootmain.cpp
# and is reached only through Code/Build/bootrun.cmd; it is deliberately NOT linked here.
#
-# âš The x86 diagnostic target retains /FORCE: every unwritten function links at RVA 0 and faults
-# when reached. The x64 target DOES NOT use /FORCE. It must not emit a runnable image until every
-# compile, dependency, and strict-link requirement is satisfied.
+# Both Windows executables link strictly: zero unresolved symbols were measured in
+# the x86 companion with MSVC 14.44 and the matching dice_py.lib.
+# Side-DLL link contracts and runtime frontiers remain independent of the executable's link.
#
# OUTPUT: /.exe. The default is inside that architecture's
# build tree, NEVER the game folder: D:/B2BF Launcher/Battlefield2/bf2_w32ded.exe is the ORIGINAL
@@ -930,6 +1008,14 @@ if(BF2_BUILD_LINUX)
set(BF2_DEDICATED_DEFAULT_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin_linux")
set(BF2_DICE_PY_DEFAULT_DIR "")
set(BF2_DICE_PY_BUILD_HINT "libdice_py.so is a CMake target (dice_py) on Linux")
+elseif(BF2_BUILD_MACOS)
+ # [CHOSEN, not recovered] The macOS port keeps the Linux names: `bf2` beside libdice_py.dylib,
+ # found through an @loader_path rpath.
+ set(BF2_DEDICATED_TARGET "bf2")
+ set(BF2_DEDICATED_OUTPUT_NAME "bf2")
+ set(BF2_DEDICATED_DEFAULT_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin_macos")
+ set(BF2_DICE_PY_DEFAULT_DIR "")
+ set(BF2_DICE_PY_BUILD_HINT "libdice_py.dylib is a CMake target (dice_py) on macOS")
elseif(BF2_BUILD_X64)
set(BF2_DEDICATED_TARGET "bf2_w64ded")
set(BF2_DEDICATED_OUTPUT_NAME "bf2_w64ded")
@@ -950,8 +1036,9 @@ else()
endif()
set(BF2_DEDICATED_OUTPUT_DIR "${BF2_DEDICATED_DEFAULT_OUTPUT_DIR}" CACHE PATH
"Where ${BF2_DEDICATED_OUTPUT_NAME}.exe is written (never the retail game directory)")
-if(BF2_BUILD_LINUX)
- # libdice_py.so - the embedded CPython 2.3.4 as a shared library, built beside `bf2`.
+if(BF2_BUILD_POSIX)
+ # libdice_py.so/.dylib - the embedded CPython 2.3.4 as a shared library, built beside `bf2`.
+ # One build description serves both POSIX ports; it selects the platform's pyconfig.h itself.
set(BF2_DICE_PY_OUTPUT_DIR "${BF2_DEDICATED_OUTPUT_DIR}")
if(EXISTS "${BF2_EXTERNAL_ROOT}/python-embedded/linux/CMakeLists.txt")
add_subdirectory("${BF2_EXTERNAL_ROOT}/python-embedded/linux" "${CMAKE_BINARY_DIR}/dice_py")
@@ -989,7 +1076,7 @@ set_target_properties("${BF2_DEDICATED_TARGET}" PROPERTIES
PDB_OUTPUT_DIRECTORY "${BF2_DEDICATED_OUTPUT_DIR}"
FOLDER "BF2"
)
-if(BF2_BUILD_LINUX)
+if(BF2_BUILD_POSIX)
if(TARGET dice_py)
target_link_libraries("${BF2_DEDICATED_TARGET}" PRIVATE dice_py)
endif()
@@ -1005,6 +1092,16 @@ else()
"${BF2_DEDICATED_TARGET}: ${BF2_DICE_PY_LIB} is missing. "
"${BF2_DICE_PY_BUILD_HINT}.")
endif()
+if(BF2_BUILD_X64 AND NOT BF2_BUILD_LINUX)
+ # [CHOSEN, not recovered] The native Windows x64 port links the voice-server module statically,
+ # like the Linux image (which adds the same sources above). The BF2VoipServer_w32ded.dll side
+ # image (bf2_voipserver, below) is x86-only: it is defined under NOT BF2_BUILD_X64 and its .def
+ # pins x86 decorated names. Without these sources the strict x64 link has no CBF2VoipServer
+ # definitions for VoipServerInternal.
+ target_sources("${BF2_DEDICATED_TARGET}" PRIVATE
+ ${bf2_voipserver_only_sources}
+ )
+endif()
# dice_py IS A REAL DLL, so linking dice_py.lib is only half the job - the DLL has to be FOUND at
# run time. Windows searches the executable's own directory before the working directory, and the
# run target deliberately sets the working directory to the GAME folder, so the only place that
@@ -1015,7 +1112,7 @@ endif()
# copy_if_different so a rebuild does not touch the file when nothing changed.
# NOTE: the guard is evaluated at CONFIGURE time, exactly like the .lib check below it. If the DLL
# is built later by Code/Build/python/build_python.cmd, re-run CMake once so this rule appears.
-if(BF2_BUILD_LINUX)
+if(BF2_BUILD_POSIX)
# Nothing to stage: the dice_py target writes libdice_py.so into BF2_DEDICATED_OUTPUT_DIR, and
# the executable carries an $ORIGIN rpath (below) so the pair can be copied anywhere together.
elseif(EXISTS "${BF2_DICE_PY_DLL}")
@@ -1054,6 +1151,22 @@ if(BF2_BUILD_LINUX)
-pthread
"-Wl,-Map=${BF2_DEDICATED_OUTPUT_DIR}/${BF2_DEDICATED_OUTPUT_NAME}.map"
)
+elseif(BF2_BUILD_MACOS)
+ # [CHOSEN, not recovered] The macOS counterparts of the Linux link contract above: libSystem
+ # supplies pthreads, dl and libm; ncurses comes from the SDK. libdice_py.dylib is resolved
+ # beside the executable through @loader_path, the Mach-O spelling of $ORIGIN. ld64 rejects
+ # undefined symbols by default, so this link is strict like the Linux one. There is no
+ # static-runtime option: libc++ is part of the OS on macOS.
+ target_link_libraries("${BF2_DEDICATED_TARGET}" PRIVATE
+ Threads::Threads ${CMAKE_DL_LIBS} ${CURSES_LIBRARIES})
+ set_target_properties("${BF2_DEDICATED_TARGET}" PROPERTIES
+ BUILD_RPATH "@loader_path"
+ INSTALL_RPATH "@loader_path"
+ BUILD_WITH_INSTALL_RPATH TRUE
+ )
+ target_link_options("${BF2_DEDICATED_TARGET}" PRIVATE
+ "-Wl,-map,${BF2_DEDICATED_OUTPUT_DIR}/${BF2_DEDICATED_OUTPUT_NAME}.map"
+ )
else()
target_link_libraries("${BF2_DEDICATED_TARGET}" PRIVATE advapi32 user32 shell32 dbghelp ws2_32)
target_link_options("${BF2_DEDICATED_TARGET}" PRIVATE
@@ -1068,18 +1181,14 @@ target_link_options("${BF2_DEDICATED_TARGET}" PRIVATE
"/MAP:${BF2_DEDICATED_OUTPUT_DIR}/${BF2_DEDICATED_OUTPUT_NAME}.map"
/IGNORE:4006,4088,4098
)
-if(NOT BF2_BUILD_X64)
- target_link_options("${BF2_DEDICATED_TARGET}" PRIVATE /FORCE)
-else()
+if(BF2_BUILD_X64)
target_link_options("${BF2_DEDICATED_TARGET}" PRIVATE /OPT:REF /OPT:ICF /INCREMENTAL:NO)
endif()
-endif() # BF2_BUILD_LINUX / MSVC link contracts
+endif() # BF2_BUILD_LINUX / BF2_BUILD_MACOS / MSVC link contracts
# =================================================================================================
# bf2_aidll - THE BOT-AI SIDE-DLL IMAGE.
-# The native-x64 profile is intentionally dedicated-only. Do not let it emit x64 binaries under
-# the shipped x86 AIDLL/BF2 names; those ports require separate targets and ABI validation.
-if(NOT BF2_BUILD_X64)
+# Native 64-bit ports build the same manifest with their host ABI; they cannot load x86 AI.
#
# AIDLL_w32ded.dll is a THIRD server-side image built from this same tree: bf2_w32ded.exe loads it
# through ai::AIConnection::init -> LoadLibraryBf -> the exported initDll, and reaches it afterwards
@@ -1093,11 +1202,10 @@ if(NOT BF2_BUILD_X64)
# below is therefore its own compilation, and it MIRRORS Code/Build/aidll.cmd. Keep the two lists
# in step; aidll.cmd is the one the harness and every gate use.
#
-# EXCLUDE_FROM_ALL, and /FORCE for the same reason bf2_w32ded is: every unwritten function links at
-# RVA 0 and faults BY NAME on the path that reaches it. The only unresolved symbol today is
-# ai::informationManager, the InformationManager frontier BF2AI.cpp declares and chunk 02 fills.
+# EXCLUDE_FROM_ALL; x86 Windows retains its diagnostic /FORCE link. Native 64-bit images link
+# strictly. The executable's link does not establish the side-DLL's completeness.
#
-# OUTPUT: /AIDLL_w32ded.dll - the build tree's bin/, NEVER the game folder.
+# x86 OUTPUT: /AIDLL_w32ded.dll - the build tree's bin/, NEVER the game folder.
# "D:/B2BF Launcher/Battlefield2/AIDLL_w32ded.dll" is the REFERENCE binary. The server reaches the
# rebuilt DLL through a RELATIVE `AIDLL` setting (LoadLibraryBf builds ".\\" + name against the
# current directory); Code/Tests/aidll/run.py does exactly that and copies nothing.
@@ -1105,109 +1213,99 @@ if(NOT BF2_BUILD_X64)
set(BF2_AIDLL_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin" CACHE PATH
"Where AIDLL_w32ded.dll is written (NOT the game folder - the original lives there)")
-add_library(bf2_aidll SHARED EXCLUDE_FROM_ALL
- # group 1 - the module entry point; engine code compiled into every side-DLL, never into the exe
- "${BF2_ROOT}/Core/DllModule.cpp"
- "${BF2_ROOT}/Core/DllGlobals.cpp"
- # group 2 - the AIDLL-only AI translation units
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/BotMain.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/BotNavigation.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/BotSquad.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/SensingAgent.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/CommunicationAgent.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/BotSenses.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIPlanInterpreter/BAPContext.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/InformationManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/Information.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/WeaponInfo.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIArmament.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIArmamentReal.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPICover.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIMobile.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIMobileReal.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIMobileKnown.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIUnit.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/InformationReal.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/WeaponInfoReal.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/IPIPhysicalReal.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIUtils/VehicleOccupancy.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/BFInformationEnvironment.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/AIInformationGrid.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIUtils/DebugRendering/AIRenderUtil.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/WeaponInfoManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/BFInformationCourier.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIKnowledge/InformationFactory.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicMap/BFStrategicEnvironment.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicMap/BotSpawner.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/DrawPrimitives/DPManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AICollisionHandler.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIEventCourier.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIMineManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIPlayerCourier.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/BFPathfindingCourier.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/Material/Material.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/Material/MaterialManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/NavMesh/MapProperties.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/NavMesh/QuadTreeManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/NavMesh/QuadTree.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/NavMesh/QuadTreeNode.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/Cluster/ClusterGraph.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/Cluster/ClusterNodeManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIPathFinding/NavMesh/QTSearchNodeManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicMap/AerialHeightMap.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIPlanInterpreter/BAPEntries.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/SensingAgentPatterns.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/SquadManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/SquadCoordinator.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/SquadFormation.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/SquadMember.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBotBehaviour/CustomCurve.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/BotMemory.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBot/BotSubObjects.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBotBehaviour/UrgencyMerger.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIConsole.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIBotBehaviour/UrgeCurve.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/CoverPosition/CPNodeManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/CoverPosition/CoverPositionManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/AIStrategicObjectManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/AILandingZoneManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/AIStrategicObject.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/AIStrategicArea.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategicEntity/SAWayPoint.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/AIStrategic/SAI.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/BotBehaviourManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/CommunicationHub.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/StrategyManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIPathfinding.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/IAIPathfinding.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/UserOrderManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIMain.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIModule.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AIRandom.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AILODManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/IBotManager.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AISettings.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/AISingletonServer.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/BF2AI.cpp"
- "${BF2_ROOT}/AI/AIDLL/AI/Main/BotManager.cpp"
- # group 3 - present in BOTH shipped images
- "${BF2_ROOT}/AI/AIDLL/AI/Main/CommonSingletonServer.cpp"
- # group 4 - engine translation units libaidll.so statically links, added as the strict link
- # demands them (census/00_statically_linked_engine_code.tsv confirms each one is really there)
- "${BF2_ROOT}/Core/ConsoleObjects.cpp" # 0x4865C0.. - registerConsoleObjects, AIModule::init
- "${BF2_ROOT}/Core/ConsoleObjectBase.cpp" # the ConsoleClassN base - the ai.init binding
- "${BF2_ROOT}/Math/Frustum.cpp" # a bot sees by frustum - BotSenses
- "${BF2_ROOT}/Math/Mat4Inverse.cpp" # AIDLL PE body matches the recovered client PE body
- "${BF2_ROOT}/AI/AIInterface/BFKnowledge/PlanePolygon.cpp" # physical-cover fallback dependency
- "${BF2_ROOT}/Math/Plane3.cpp" # Frustum pulls Plane3::transform + intersect
- "${BF2_ROOT}/Math/Vec3.cpp" # Vec3::getZero - BotMain's constructor
- "${BF2_ROOT}/Core/Debug.cpp" # 0x487C30.. - Debug ctor/dtor, reached by checkPointer
- "${BF2_ROOT}/Core/StringUtil.cpp" # 0x487AF0 - calcStringHashValueNoCase, for StringHashFunc
- # Kept in step with Code/Build/aidll.cmd (2026-09-28): File.cpp joined that manifest on
- # 2026-09-11 without this list; PlayerInput.cpp joins both for Input::setInput.
- "${BF2_ROOT}/IO/File/File.cpp" # io::File - AerialHeightMap's file paths
- "${BF2_ROOT}/IO/Input/PlayerInput.cpp" # 0x18F020 - setInput(float), the plan executor
-)
+# The AI side-DLL manifest, in link order (= static-initialisation order), shared with aidll.cmd.
+set(bf2_aidll_manifest "${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/aidll_sources.txt")
+set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${bf2_aidll_manifest}")
+file(STRINGS "${bf2_aidll_manifest}" bf2_aidll_manifest_lines)
+set(bf2_aidll_sources)
+foreach(bf2_aidll_line IN LISTS bf2_aidll_manifest_lines)
+ string(STRIP "${bf2_aidll_line}" bf2_aidll_line)
+ if(bf2_aidll_line AND NOT bf2_aidll_line MATCHES "^#")
+ list(APPEND bf2_aidll_sources "${BF2_ROOT}/${bf2_aidll_line}")
+ endif()
+endforeach()
+add_library(bf2_aidll SHARED EXCLUDE_FROM_ALL ${bf2_aidll_sources})
+if(BF2_BUILD_POSIX)
+ # [CHOSEN, not recovered] Native POSIX AI image (Linux libaidll.so, macOS libaidll.dylib; a
+ # native-port design, not retail); same host toolchain and STL ABI as bf2. Never substitute the
+ # retail 32-bit libaidll.so.
+ bf2_configure_cpp_target(bf2_aidll)
+ bf2_set_image(bf2_aidll 1)
+ bf2_set_platform_compat(bf2_aidll)
+ target_compile_definitions(bf2_aidll PRIVATE BF2_IMAGE_AIDLL=1 BF2_PLATFORM_POSIX)
+ target_include_directories(bf2_aidll PRIVATE ${BF2_PYTHON_INCLUDE_DIRS})
+ target_link_libraries(bf2_aidll PRIVATE Threads::Threads ${CMAKE_DL_LIBS})
+ set_target_properties(bf2_aidll PROPERTIES
+ OUTPUT_NAME aidll
+ LIBRARY_OUTPUT_DIRECTORY "${BF2_DEDICATED_OUTPUT_DIR}"
+ FOLDER "BF2")
+ # Keep module globals private, including names also defined by the engine. The only
+ # cross-image entry points are the existing ClassManager handshake exports.
+ if(BF2_BUILD_MACOS)
+ target_link_options(bf2_aidll PRIVATE
+ "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/Code/AidllAbi/aidll-macos.exports")
+ set_property(TARGET bf2_aidll APPEND PROPERTY LINK_DEPENDS
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/AidllAbi/aidll-macos.exports")
+ else()
+ target_link_options(bf2_aidll PRIVATE
+ -Wl,--no-undefined
+ "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/Code/AidllAbi/aidll-posix.map")
+ set_property(TARGET bf2_aidll APPEND PROPERTY LINK_DEPENDS
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/AidllAbi/aidll-posix.map")
+ endif()
+ add_dependencies("${BF2_DEDICATED_TARGET}" bf2_aidll)
+
+ # [CHOSEN, not recovered] Engine-free check of the real loader and export lookup.
+ add_executable(bf2_aidll_loader_check EXCLUDE_FROM_ALL
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/Tests/aidll/posix_loader.cpp"
+ "${BF2_ROOT}/Core/PluginDll.cpp")
+ bf2_configure_cpp_target(bf2_aidll_loader_check)
+ bf2_set_image(bf2_aidll_loader_check 1)
+ bf2_set_platform_compat(bf2_aidll_loader_check)
+ target_link_libraries(bf2_aidll_loader_check PRIVATE ${CMAKE_DL_LIBS})
+ set_target_properties(bf2_aidll_loader_check PROPERTIES
+ RUNTIME_OUTPUT_DIRECTORY "${BF2_DEDICATED_OUTPUT_DIR}")
+ if(BF2_BUILD_MACOS)
+ set_target_properties(bf2_aidll_loader_check PROPERTIES BUILD_RPATH "@loader_path")
+ else()
+ set_target_properties(bf2_aidll_loader_check PROPERTIES BUILD_RPATH "\$ORIGIN")
+ endif()
+ add_dependencies(bf2_aidll_loader_check bf2_aidll)
+elseif(BF2_BUILD_X64)
+ # [CHOSEN, not recovered] Windows x64 AI for the native client and dedicated server.
+ # https://github.com/kr4uzi/OpenBF2/issues/11. Keep the host's /MD, release STL layout,
+ # embedded debug information and pointer-truncation errors. The x64 link is strict.
+ bf2_configure_cpp_target(bf2_aidll)
+ bf2_set_image(bf2_aidll 1)
+ target_compile_definitions(bf2_aidll PRIVATE BF2_IMAGE_AIDLL=1 _ITERATOR_DEBUG_LEVEL=0)
+ target_compile_options(bf2_aidll PRIVATE ${BF2_CLIENT_X64_COMPILE_OPTIONS})
+ target_include_directories(bf2_aidll PRIVATE ${BF2_PYTHON_INCLUDE_DIRS})
+ set(bf2_aidll_x64_def "${CMAKE_CURRENT_SOURCE_DIR}/Code/AidllAbi/aidll-x64.def")
+ set_target_properties(bf2_aidll PROPERTIES
+ OUTPUT_NAME aidll
+ PREFIX ""
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin_client"
+ RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin_client"
+ RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin_client"
+ RUNTIME_OUTPUT_DIRECTORY_RECONSTRUCTION "${CMAKE_BINARY_DIR}/bin_client"
+ PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin_client"
+ FOLDER "BF2")
+ target_link_libraries(bf2_aidll PRIVATE kernel32 user32 advapi32 ws2_32)
+ target_link_options(bf2_aidll PRIVATE
+ /DEBUG /OPT:REF /OPT:ICF /INCREMENTAL:NO /NODEFAULTLIB:python23.lib
+ "/DEF:${bf2_aidll_x64_def}"
+ "/MAP:${CMAKE_BINARY_DIR}/bin_client/aidll.map")
+ set_property(TARGET bf2_aidll APPEND PROPERTY LINK_DEPENDS "${bf2_aidll_x64_def}")
+
+ # Stage on every server build, even if only the DLL changed since the last executable link.
+ add_custom_target(bf2_aidll_server_stage
+ COMMAND "${CMAKE_COMMAND}" -E make_directory "${BF2_DEDICATED_OUTPUT_DIR}"
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different
+ "$" "${BF2_DEDICATED_OUTPUT_DIR}/aidll.dll"
+ DEPENDS bf2_aidll
+ VERBATIM)
+ add_dependencies("${BF2_DEDICATED_TARGET}" bf2_aidll_server_stage)
+else()
set_target_properties(bf2_aidll PROPERTIES
LINKER_LANGUAGE CXX
OUTPUT_NAME AIDLL_w32ded
@@ -1241,6 +1339,10 @@ target_link_options(bf2_aidll PRIVATE
/IGNORE:4006,4088,4098
)
+endif() # POSIX / Windows AIDLL
+
+if(NOT BF2_BUILD_X64)
+
# =================================================================================================
# bf2_voipserver - THE VOICE-SERVER SIDE-DLL IMAGE.
#
@@ -1308,6 +1410,13 @@ if(TARGET bf2_voipserver)
target_link_libraries("${BF2_DEDICATED_TARGET}" PRIVATE bf2_voipserver)
endif()
+# [CHOSEN, not recovered] Compatibility build alias: the production x86 server now links strictly.
+# Like bf2_client_linkcheck, this emits only the production executable, not a second check image.
+if(NOT BF2_BUILD_POSIX AND NOT BF2_BUILD_X64)
+ add_custom_target(bf2_w32ded_linkcheck DEPENDS bf2_w32ded)
+ set_property(TARGET bf2_w32ded_linkcheck PROPERTY FOLDER "BF2")
+endif()
+
# =================================================================================================
# bf2_voipserver_client - THE CLIENT LISTEN-SERVER VOICE DLL.
#
@@ -1366,23 +1475,28 @@ set_target_properties(bf2_voipserver_standalone PROPERTIES
bf2_configure_cpp_target(bf2_voipserver_standalone)
bf2_set_image(bf2_voipserver_standalone 1)
target_link_libraries(bf2_voipserver_standalone PRIVATE bf2_voipserver kernel32 user32 advapi32 ws2_32)
+endif() # Windows x86 voice images
+
+
+# The client and the editor build in both Windows configurations: x86, and the native x64 client
+# ([CHOSEN, not recovered], https://github.com/B2BF/OpenBF2/issues/7). The x64 images keep the
+# shipped file names (BF2.exe and its plugin DLLs, which BF2.exe loads by name) and are written only
+# inside the x64 build tree.
+if(NOT BF2_BUILD_POSIX)
# =================================================================================================
-# bf2_client - THE CLIENT LINK-REACH IMAGE (2026-09-03).
+# bf2_client - THE STRICTLY LINKED WINDOWS CLIENT.
#
-# This is a real /DDEDICATED=0 image. Modern link.exe does
-# not enumerate unresolved symbols when /FORCE is active, so bf2_client_linkcheck below is the
-# deliberately failing strict link whose diagnostics are the client work list. Both targets are
-# EXCLUDE_FROM_ALL. Process startup constructs HUD, then stops before singleton registration (2026-09-05);
-# this is not a runnable-client claim. RendDX9 now has a separately proven
-# native registry/module ABI flavour, but its HWND/display-mode boundary and the exe-side
-# BF2Render bridge are still open; SwiffPlayer's native AS host callbacks remain frontiers. Both plugin
-# builds are staged beside this diagnostic host since 2026-09-08 (the bf2_client_plugins dependency below).
+# This /DDEDICATED=0 image links without /FORCE on x86 and x64 when the matching
+# dice_py import library is supplied (MSVC 14.44 checks, 2026-11-08).
+# Four-way runs and the x64 movie check establish runtime reach; remaining engine
+# frontiers still limit individual paths. The target stays EXCLUDE_FROM_ALL.
+# Native plugins are staged beside the host by bf2_client_plugins below.
# Output stays in this build tree and can never overwrite the retail BF2.exe used as
# reverse-engineering evidence.
# =================================================================================================
# Fixed inside this build tree on purpose: unlike the server's opt-in deployment directory, a
-# diagnostic client target must never be redirected onto the retail BF2.exe (CMake clean would then
+# client target must never be redirected onto the retail BF2.exe (CMake clean would then
# own and could remove it).
set(BF2_CLIENT_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin_client")
@@ -1394,6 +1508,7 @@ add_executable(bf2_client EXCLUDE_FROM_ALL
$
$
$
+ $
)
set_target_properties(bf2_client PROPERTIES
LINKER_LANGUAGE CXX
@@ -1411,7 +1526,10 @@ set_target_properties(bf2_client PROPERTIES
)
bf2_configure_cpp_target(bf2_client)
bf2_set_image(bf2_client 0)
-target_compile_definitions(bf2_client PRIVATE BF2_PLUGIN_ABI_NATIVE=1 _ITERATOR_DEBUG_LEVEL=0)
+if(BF2_BUILD_X64)
+ add_dependencies(bf2_client bf2_aidll)
+endif()
+target_compile_definitions(bf2_client PRIVATE _ITERATOR_DEBUG_LEVEL=0)
set_target_properties(bf2_client PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${BF2_GAME_DIR}"
VS_DEBUGGER_COMMAND_ARGUMENTS "+modPath mods/bf2 +fullscreen 0 +multi 1"
@@ -1419,7 +1537,7 @@ set_target_properties(bf2_client PROPERTIES
# Normal startup includes the movies; +restart remains an optional explicit skip.
set(BF2_CLIENT_RUN_ARGS "+modPath;mods/bf2;+fullscreen;0;+multi;1"
- CACHE STRING "Arguments for the diagnostic bf2_client_run target (a CMake ;-list).")
+ CACHE STRING "Arguments for the bf2_client_run target (a CMake ;-list).")
add_custom_target(bf2_client_run
COMMAND "$" ${BF2_CLIENT_RUN_ARGS}
DEPENDS bf2_client
@@ -1441,34 +1559,13 @@ if(EXISTS "${BF2_DICE_PY_DLL}")
add_custom_command(TARGET bf2_client POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${BF2_DICE_PY_DLL}" "${BF2_CLIENT_OUTPUT_DIR}/dice_py.dll"
- COMMENT "Staging dice_py.dll beside the diagnostic BF2.exe"
+ COMMENT "Staging dice_py.dll beside BF2.exe"
VERBATIM
)
endif()
-# The bounded Novint SDK surface contains no cross-compiler STL objects. Import
-# names and the 32-byte ApplicationData carrier are read from the original client;
-# the matching DLL supplies third-party bodies.
-set(BF2_NOVINT_IMPORT_LIB "${CMAKE_BINARY_DIR}/novint_hfx/NovintHFX.lib")
-add_custom_command(OUTPUT "${BF2_NOVINT_IMPORT_LIB}"
- COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_BINARY_DIR}/novint_hfx"
- COMMAND "${CMAKE_AR}" /nologo /machine:x86
- "/def:${BF2_EXTERNAL_ROOT}/NovintHFX/NovintHFX.def"
- "/out:${BF2_NOVINT_IMPORT_LIB}"
- DEPENDS "${BF2_EXTERNAL_ROOT}/NovintHFX/NovintHFX.def"
- VERBATIM
-)
-add_custom_target(bf2_novint_imports DEPENDS "${BF2_NOVINT_IMPORT_LIB}")
-add_dependencies(bf2_client bf2_novint_imports)
-target_link_libraries(bf2_client PRIVATE "${BF2_NOVINT_IMPORT_LIB}")
-if(EXISTS "${BF2_GAME_DIR}/NovintHFX.dll")
- add_custom_command(TARGET bf2_client POST_BUILD
- COMMAND "${CMAKE_COMMAND}" -E copy_if_different
- "${BF2_GAME_DIR}/NovintHFX.dll" "${BF2_CLIENT_OUTPUT_DIR}/NovintHFX.dll"
- COMMENT "Staging the original Novint SDK companion beside the diagnostic BF2.exe"
- VERBATIM
- )
-endif()
+# [CHOSEN, not recovered] The Novint Falcon is archived (Code/Archive/NovintFalcon, issue #17): no image
+# imports or stages NovintHFX.dll.
# [CHOSEN, not recovered] Build and stage one native client/plugin set:
# https://github.com/B2BF/OpenBF2/issues/7. These DLLs target the rebuilt host only;
@@ -1506,6 +1603,16 @@ endif()
#
# Rebuild and stage plugins on every client build. Their scripts do not emit full include
# dependencies, so a glob over plugin sources would miss changes in shared engine headers.
+#
+# Each script takes the architecture as its flavour argument: `native` builds the x86 DLL into
+# Code/Build/bin__native, `x64` the native x64 DLL into Code/Build/bin__x64. The x64
+# RendDX9.dll has no Bink import: it links the FFmpeg-based Bink stand-in (renddx9.cmd x64,
+# Code/BF2/External/ffmpeg-bink/README.md); the x86 DLL imports binkw32.dll.
+if(BF2_BUILD_X64)
+ set(BF2_PLUGIN_FLAVOUR x64)
+else()
+ set(BF2_PLUGIN_FLAVOUR native)
+endif()
if(TRUE)
# âš EACH SCRIPT IS NAMED BY ITS FULL NATIVE PATH, not bare beside WORKING_DIRECTORY. cmd.exe
# finds a bare script name only by searching the current directory, and that search is OFF
@@ -1522,24 +1629,32 @@ if(TRUE)
file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/swiffplayer.cmd" BF2_SWIFFPLAYER_SCRIPT)
file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/textureatlasbuilder.cmd" BF2_TEXTUREATLAS_SCRIPT)
add_custom_target(bf2_textureatlas_native
- COMMAND cmd.exe /d /c "${BF2_TEXTUREATLAS_SCRIPT}" native
+ COMMAND cmd.exe /d /c "${BF2_TEXTUREATLAS_SCRIPT}" ${BF2_PLUGIN_FLAVOUR}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Code/Build"
- COMMENT "Building the native TextureAtlasBuilder.dll (Code/Build/textureatlasbuilder.cmd native)"
+ COMMENT "Building the ${BF2_PLUGIN_FLAVOUR} TextureAtlasBuilder.dll (Code/Build/textureatlasbuilder.cmd ${BF2_PLUGIN_FLAVOUR})"
VERBATIM
)
set_property(TARGET bf2_textureatlas_native PROPERTY FOLDER "BF2")
+ # [CHOSEN, not recovered] G2w: BF2_GFX_SEAM=ON makes renddx9.cmd compile the renderer against the subset
+ # headers plus the generated forwarding backend (Platform/Gfx/D3D9Forward).
+ set(BF2_RENDDX9_SEAM_ENV)
+ if(BF2_GFX_SEAM)
+ set(BF2_RENDDX9_SEAM_ENV "${CMAKE_COMMAND}" -E env BF2_GFX_SEAM=ON)
+ endif()
add_custom_target(bf2_renddx9_native
- COMMAND cmd.exe /d /c "${BF2_RENDDX9_SCRIPT}" native
+ COMMAND ${BF2_FRONTIER_DEFAULT_ENV} ${BF2_RENDDX9_SEAM_ENV} cmd.exe /d /c "${BF2_RENDDX9_SCRIPT}" ${BF2_PLUGIN_FLAVOUR}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Code/Build"
- COMMENT "Building the native RendDX9.dll (Code/Build/renddx9.cmd native)"
+ COMMENT "Building the ${BF2_PLUGIN_FLAVOUR} RendDX9.dll (Code/Build/renddx9.cmd ${BF2_PLUGIN_FLAVOUR})"
VERBATIM
)
set_property(TARGET bf2_renddx9_native PROPERTY FOLDER "BF2")
- add_dependencies(bf2_renddx9_native bf2_textureatlas_native)
+ if(NOT BF2_GFX_SEAM)
+ add_dependencies(bf2_renddx9_native bf2_textureatlas_native)
+ endif()
add_custom_target(bf2_swiffplayer_native
- COMMAND cmd.exe /d /c "${BF2_SWIFFPLAYER_SCRIPT}" native
+ COMMAND ${BF2_FRONTIER_DEFAULT_ENV} cmd.exe /d /c "${BF2_SWIFFPLAYER_SCRIPT}" ${BF2_PLUGIN_FLAVOUR}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Code/Build"
- COMMENT "Building the native SwiffPlayer.dll (Code/Build/swiffplayer.cmd native)"
+ COMMENT "Building the ${BF2_PLUGIN_FLAVOUR} SwiffPlayer.dll (Code/Build/swiffplayer.cmd ${BF2_PLUGIN_FLAVOUR})"
VERBATIM
)
set_property(TARGET bf2_swiffplayer_native PROPERTY FOLDER "BF2")
@@ -1553,9 +1668,9 @@ if(TRUE)
# ordering rule as the two above: after SwiffPlayer, never concurrently.
file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/bf2audio.cmd" BF2_BF2AUDIO_SCRIPT)
add_custom_target(bf2_bf2audio_native
- COMMAND cmd.exe /d /c "${BF2_BF2AUDIO_SCRIPT}" native
+ COMMAND ${BF2_FRONTIER_DEFAULT_ENV} cmd.exe /d /c "${BF2_BF2AUDIO_SCRIPT}" ${BF2_PLUGIN_FLAVOUR}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Code/Build"
- COMMENT "Building the native BF2Audio.dll (Code/Build/bf2audio.cmd native)"
+ COMMENT "Building the ${BF2_PLUGIN_FLAVOUR} BF2Audio.dll (Code/Build/bf2audio.cmd ${BF2_PLUGIN_FLAVOUR})"
VERBATIM
)
set_property(TARGET bf2_bf2audio_native PROPERTY FOLDER "BF2")
@@ -1565,26 +1680,26 @@ endif()
set(BF2_PLUGIN_STAGE_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/stage_plugin.cmake")
add_custom_target(bf2_client_plugins
COMMAND "${CMAKE_COMMAND}"
- "-DBF2_PLUGIN_SRC=${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/bin_renddx9_native/RendDX9.dll"
+ "-DBF2_PLUGIN_SRC=${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/bin_renddx9_${BF2_PLUGIN_FLAVOUR}/RendDX9.dll"
"-DBF2_PLUGIN_DST_DIR=${BF2_CLIENT_OUTPUT_DIR}"
- "-DBF2_PLUGIN_HINT=build it with Code/Build/renddx9.cmd native"
+ "-DBF2_PLUGIN_HINT=build it with Code/Build/renddx9.cmd ${BF2_PLUGIN_FLAVOUR}"
-P "${BF2_PLUGIN_STAGE_SCRIPT}"
COMMAND "${CMAKE_COMMAND}"
- "-DBF2_PLUGIN_SRC=${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/bin_swiffplayer_native/SwiffPlayer.dll"
+ "-DBF2_PLUGIN_SRC=${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/bin_swiffplayer_${BF2_PLUGIN_FLAVOUR}/SwiffPlayer.dll"
"-DBF2_PLUGIN_DST_DIR=${BF2_CLIENT_OUTPUT_DIR}"
- "-DBF2_PLUGIN_HINT=build it with Code/Build/swiffplayer.cmd native"
+ "-DBF2_PLUGIN_HINT=build it with Code/Build/swiffplayer.cmd ${BF2_PLUGIN_FLAVOUR}"
-P "${BF2_PLUGIN_STAGE_SCRIPT}"
COMMAND "${CMAKE_COMMAND}"
- "-DBF2_PLUGIN_SRC=${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/bin_bf2audio_native/BF2Audio.dll"
+ "-DBF2_PLUGIN_SRC=${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/bin_bf2audio_${BF2_PLUGIN_FLAVOUR}/BF2Audio.dll"
"-DBF2_PLUGIN_DST_DIR=${BF2_CLIENT_OUTPUT_DIR}"
- "-DBF2_PLUGIN_HINT=build it with Code/Build/bf2audio.cmd native"
+ "-DBF2_PLUGIN_HINT=build it with Code/Build/bf2audio.cmd ${BF2_PLUGIN_FLAVOUR}"
-P "${BF2_PLUGIN_STAGE_SCRIPT}"
COMMAND "${CMAKE_COMMAND}"
- "-DBF2_PLUGIN_SRC=${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/bin_textureatlasbuilder_native/TextureAtlasBuilder.dll"
+ "-DBF2_PLUGIN_SRC=${CMAKE_CURRENT_SOURCE_DIR}/Code/Build/bin_textureatlasbuilder_${BF2_PLUGIN_FLAVOUR}/TextureAtlasBuilder.dll"
"-DBF2_PLUGIN_DST_DIR=${BF2_CLIENT_OUTPUT_DIR}"
- "-DBF2_PLUGIN_HINT=build it with Code/Build/textureatlasbuilder.cmd native"
+ "-DBF2_PLUGIN_HINT=build it with Code/Build/textureatlasbuilder.cmd ${BF2_PLUGIN_FLAVOUR}"
-P "${BF2_PLUGIN_STAGE_SCRIPT}"
- COMMENT "Staging the four native plugins beside the diagnostic BF2.exe"
+ COMMENT "Staging the four ${BF2_PLUGIN_FLAVOUR} plugins beside BF2.exe"
VERBATIM
)
# Ordering AND obligation: all four plugin builds complete before anything is copied. This
@@ -1593,6 +1708,13 @@ add_custom_target(bf2_client_plugins
# point where it hurts, which is a live debugging session.
add_dependencies(bf2_client_plugins bf2_textureatlas_native bf2_renddx9_native bf2_swiffplayer_native bf2_bf2audio_native)
add_dependencies(bf2_client bf2_client_plugins)
+# The subsystem version that keeps the classic (pre-6.0) window frame; see the link options below.
+# x64: 5.02, the lowest version link.exe accepts for an x64 image, on the same side of 6.0.
+if(BF2_BUILD_X64)
+ set(BF2_CLIENT_SUBSYSTEM "/SUBSYSTEM:WINDOWS,5.02")
+else()
+ set(BF2_CLIENT_SUBSYSTEM "/SUBSYSTEM:WINDOWS,5.01")
+endif()
# System imports present in the retail BF2.exe.
target_link_libraries(bf2_client PRIVATE
advapi32 crypt32 dbghelp dinput8 dsound dxguid gdi32 ole32 psapi shell32 user32 winmm ws2_32
@@ -1602,8 +1724,20 @@ target_link_libraries(bf2_client PRIVATE
if(TARGET bf2_voipserver_client)
target_link_libraries(bf2_client PRIVATE bf2_voipserver_client)
endif()
+# [CHOSEN, not recovered] x64 (issue #7): BF2VoipServer.dll is x86-only (its .def pins x86 decorated
+# names), so the native x64 client links the voice-server module statically, as the x64 dedicated
+# server and the macOS client do. Client image (/DDEDICATED=0), same sources as bf2_voipserver_client.
+if(BF2_BUILD_X64)
+ add_library(bf2_voipserver_client_objects OBJECT EXCLUDE_FROM_ALL ${bf2_voipserver_only_sources})
+ bf2_configure_cpp_target(bf2_voipserver_client_objects)
+ bf2_set_image(bf2_voipserver_client_objects 0)
+ bf2_set_platform_compat(bf2_voipserver_client_objects)
+ target_compile_definitions(bf2_voipserver_client_objects PRIVATE _ITERATOR_DEBUG_LEVEL=0)
+ target_compile_options(bf2_voipserver_client_objects PRIVATE ${BF2_CLIENT_X64_COMPILE_OPTIONS})
+ set_property(TARGET bf2_voipserver_client_objects PROPERTY FOLDER "BF2")
+ target_sources(bf2_client PRIVATE $)
+endif()
target_link_options(bf2_client PRIVATE
- /FORCE
/INCREMENTAL:NO
/DEBUG
# âš THE ",4.0" IS LOAD-BEARING, AND IT IS A FIDELITY SETTING, NOT A PREFERENCE.
@@ -1626,7 +1760,7 @@ target_link_options(bf2_client PRIVATE
# default subsystem version assumed" and silently falls back to 6.0, which is the bug. 5.01 is
# the lowest value it accepts for x86. What governs the frame is the 6.0 boundary, so 5.01 and
# retail's 4.0 behave identically here; the field itself still differs from the shipped image.
- /SUBSYSTEM:WINDOWS,5.01
+ "${BF2_CLIENT_SUBSYSTEM}"
/NODEFAULTLIB:python23.lib
"/MAP:${BF2_CLIENT_OUTPUT_DIR}/BF2.map"
/IGNORE:4006,4088,4098
@@ -1634,56 +1768,454 @@ target_link_options(bf2_client PRIVATE
set_property(TARGET bf2_client_objects PROPERTY FOLDER "BF2")
-# Strict companion to bf2_client. This target is EXPECTED TO FAIL until every client external is
-# recovered; the final LNK1120 count and the preceding symbol names are the measured whole-image
-# work list (shared engine debt included, not a client-only delta).
-# /FORCE:MULTIPLE tolerates the five known duplicate FileChangeManager constants without tolerating
-# unresolveds. Keeping it separate lets bf2_client emit the RVA-0 PE used for map/import checks.
-add_executable(bf2_client_linkcheck EXCLUDE_FROM_ALL
- $
- $
- $
- $
- $
- $
- $
-)
-set_target_properties(bf2_client_linkcheck PROPERTIES
- LINKER_LANGUAGE CXX
- WIN32_EXECUTABLE TRUE
- OUTPUT_NAME BF2_linkcheck
- RUNTIME_OUTPUT_DIRECTORY "${BF2_CLIENT_OUTPUT_DIR}"
- RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BF2_CLIENT_OUTPUT_DIR}"
- RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BF2_CLIENT_OUTPUT_DIR}"
- RUNTIME_OUTPUT_DIRECTORY_RECONSTRUCTION "${BF2_CLIENT_OUTPUT_DIR}"
- PDB_OUTPUT_DIRECTORY "${BF2_CLIENT_OUTPUT_DIR}"
- PDB_OUTPUT_DIRECTORY_DEBUG "${BF2_CLIENT_OUTPUT_DIR}"
- PDB_OUTPUT_DIRECTORY_RELEASE "${BF2_CLIENT_OUTPUT_DIR}"
- PDB_OUTPUT_DIRECTORY_RECONSTRUCTION "${BF2_CLIENT_OUTPUT_DIR}"
- FOLDER "BF2"
-)
-bf2_configure_cpp_target(bf2_client_linkcheck)
-bf2_set_image(bf2_client_linkcheck 0)
+# Compatibility build alias: bf2_client itself now performs the strict link.
+add_custom_target(bf2_client_linkcheck DEPENDS bf2_client)
+set_property(TARGET bf2_client_linkcheck PROPERTY FOLDER "BF2")
-if(EXISTS "${BF2_DICE_PY_LIB}")
- target_link_libraries(bf2_client_linkcheck PRIVATE "${BF2_DICE_PY_LIB}")
-endif()
-target_link_libraries(bf2_client_linkcheck PRIVATE
- advapi32 crypt32 dbghelp dinput8 dsound dxguid gdi32 ole32 psapi shell32 user32 winmm ws2_32
-)
-add_dependencies(bf2_client_linkcheck bf2_novint_imports)
-target_link_libraries(bf2_client_linkcheck PRIVATE "${BF2_NOVINT_IMPORT_LIB}")
-target_link_options(bf2_client_linkcheck PRIVATE
- /FORCE:MULTIPLE
- /INCREMENTAL:NO
- /DEBUG
- /SUBSYSTEM:WINDOWS
- /NODEFAULTLIB:python23.lib
-)
-
-# The BF2 Editor links the client object
-# set above, so it lives in this Windows-x86-only block. Every editor target is EXCLUDE_FROM_ALL.
+# The BF2 Editor links the client object set above, so it lives in this Windows client block
+# (x86 and native x64). Every editor target is EXCLUDE_FROM_ALL.
add_subdirectory(Code/Tools/BF2Editor)
+endif() # NOT BF2_BUILD_POSIX (client and editor)
+
+# =================================================================================================
+# bf2_client on macOS - THE NATIVE macOS CLIENT IMAGE. [CHOSEN, not recovered]
+#
+# An owner-requested port change (macOSplan.md, package S2.0; docs/macos-port.md, "Client triage").
+# The client objects above are compiled with DEDICATED=0 and the macOS platform switches. The client
+# plugin images are not shared libraries here: retail-DLL swapping is retired
+# (https://github.com/B2BF/OpenBF2/issues/7), so RendDX9, SwiffPlayer and BF2Audio are static
+# libraries, and Code/StaticPlugins/StaticPlugins.cpp answers the engine's LoadLibrary/GetProcAddress
+# lookups for the ones linked in (BF2_STATIC_PLUGINS). RendDX9 is not linked by default; see
+# BF2_MACOS_LINK_RENDDX9 below. Each library compiles its image's manifest
+# from Code/Build/.cmd with that image's define; keep the lists in step with the scripts.
+# Left out of every library: the Windows loader entry (RendDX9Abi/DllMain.cpp) and the engine TUs the
+# host image already compiles (Math/*, Core/ConsoleObjectBase.cpp), because one image holds one copy.
+# The RendDX9Abi kit (heap adapters, vc71 string, frontier log) is compiled once, in
+# bf2_plugin_kit_static, for the same reason. The three plugin entry pairs are renamed per image so
+# they can coexist in one link. TextureAtlasBuilder is embedded in the native renderer.
+#
+# The link is strict (ld64 rejects undefined symbols). It does not complete yet: the compile triage
+# in docs/macos-port.md lists the blocked translation units by blocker class.
+# =================================================================================================
+if(BF2_BUILD_MACOS)
+ set(BF2_RENDDX9_STATIC_SOURCES
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/CrashReport.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/EngineFile.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/PluginEntry.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/NativeConsoleObjects.cpp"
+ # [CHOSEN, not recovered] The binkw32 entry points on the vendored FFmpeg Bink decoders
+ # (bf2_ffmpeg_bink below; Code/BF2/External/ffmpeg-bink/README.md) and their AudioQueue sound output.
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/BinkFFmpeg.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/BinkAudioCoreAudio.cpp"
+ )
+ # Code/Build/renddx9.cmd, STEP 2: SOURCES minus the kit, DllMain.cpp and the shared Math TUs,
+ # then CONSOLE_SOURCES minus Core/ConsoleObjectBase.cpp.
+ foreach(rel
+ RendDX9/BF2Render.cpp RendDX9/PostProductionFrameWork.cpp RendDX9/RendDX9Init.cpp
+ RendDX9/BufferManager.cpp RendDX9/QueryManager.cpp RendDX9/RendDX9Types.cpp
+ RendDX9/Texture.cpp RendDX9/TextureManager.cpp RendDX9/TextureAtlas/TextureAtlas.cpp
+ RendDX9/ResourceManager.cpp RendDX9/ResourceTracer.cpp RendDX9/VideoOptions.cpp
+ RendDX9/Effect.cpp RendDX9/DiceEffect.cpp
+ RendDX9/FXParameter.cpp RendDX9/ShaderManager.cpp RendDX9/StateManager.cpp
+ RendDX9/RendDX9Draw.cpp RendDX9/RenderQueues.cpp RendDX9/Ra/EffectManager.cpp
+ RendDX9/MovieRenderer.cpp
+ RendDX9/Ra/RaShaderPermutator.cpp RendDX9/Ra/RaShader.cpp RendDX9/Ra/RaVertexStreams.cpp
+ RendDX9/Ra/RaStreamDataEditable.cpp RendMisc/RendModule.cpp RendMisc/RenderView.cpp
+ RendMisc/EnvMapSystem/EnvMapManager.cpp RendMisc/EnvMapSystem/EnvMapObject.cpp
+ IO/Tokenizer.cpp Geom/ModuleGeom.cpp Geom/GeometryTemplateManager.cpp
+ Geom/MeshTemplate.cpp Geom/StaticMeshTemplate.cpp Geom/SkinnedMeshTemplate.cpp
+ Geom/SkinnedMesh.cpp Geom/BundledMeshTemplate.cpp Geom/BundledMeshMaterial.cpp
+ Geom/BundledMeshStateManager.cpp Geom/BundledMesh.cpp Geom/BundledMeshDraw.cpp
+ Geom/BundledMeshHeight.cpp Geom/StaticMesh.cpp Geom/StaticMeshLightmapGeneration.cpp
+ Geom/StaticMeshMaterial.cpp Geom/StaticMeshStateManager.cpp Geom/SkyDome.cpp
+ Geom/UndergrowthSystem.cpp Geom/UndergrowthSystemLoad.cpp
+ Geom/LightningManager.cpp Geom/WeatherManager.cpp Geom/Rain/RainManager.cpp
+ Geom/UndergrowthSystemRender.cpp Geom/Terrain.cpp Geom/QuadPatch.cpp
+ Geom/RaQuadPatchAdapter.cpp
+ Geom/SurroundingPatch.cpp Geom/TerrainDraw.cpp Geom/TerrainEditable.cpp
+ Geom/TerrainEditableGetSets.cpp Geom/QuadPatchEditable.cpp
+ Geom/SurroundingPatchEditable.cpp Geom/TerrainLightSampling.cpp
+ Geom/LightmapGeneration/LightmapGeneration.cpp
+ Geom/LightmapGeneration/MeshLightSampling.cpp Geom/ObjectDrawer.cpp
+ Geom/XpLightManager.cpp Geom/LightMerger.cpp Geom/LightGeometry.cpp Geom/MeshOptimizer.cpp
+ Geom/BundledMeshOptimizer.cpp Geom/StaticMeshOptimizer.cpp Geom/NametagManager.cpp Geom/NameTagRenderer.cpp
+ Geom/Overgrowth/OverGrowth.cpp Geom/Overgrowth/OverGrowthLoad.cpp
+ Geom/Overgrowth/OverGrowthCells.cpp Geom/Overgrowth/OverGrowthCellRender.cpp
+ Geom/Overgrowth/OverGrowthRender.cpp Geom/RoadCompiledRenderer.cpp
+ Geom/RoadCompiledTemplate.cpp Geom/RoadCompiled.cpp Geom/RoadTemplate.cpp
+ Geom/RoadEditableRenderer.cpp Geom/RoadEditable.cpp Geom/DecalSystem/DecalManager.cpp
+ Geom/DecalSystem/DecalShadowManager.cpp
+ Geom/DecalSystem/DecalObject.cpp Geom/DecalSystem/DecalTemplate.cpp
+ Geom/DecalSystem/DecalRenderer.cpp Geom/ParticleSystem/ParticleSystemManager.cpp
+ Geom/HemiMapManager/HemiMapManager.cpp Geom/ParticleSystem/ParticleSystemTemplate.cpp
+ Geom/ParticleSystem/ParticleSystemTemplateType1.cpp
+ Geom/ParticleSystem/MeshParticleMesh/MeshParticleMeshTemplate.cpp
+ Geom/ParticleSystem/MeshParticleMesh/MeshParticleMesh.cpp
+ Geom/ParticleSystem/TrailSystemTemplate.cpp
+ Geom/ParticleSystem/ParticleSystemTemplateType3.cpp
+ Geom/ParticleSystem/NSAParticleSystemTemplate.cpp Geom/StaticMeshRenderer.cpp
+ Geom/SkinnedMeshRenderer.cpp Geom/SwiffRender.cpp GeomMisc/ModuleGeomMisc.cpp
+ GeomMisc/FSQuadDrawer.cpp GeomMisc/DebugTextWriter.cpp GeomMisc/Debug.cpp
+ GeomMisc/DebugBoxMesh.cpp
+ GeomMisc/DebugCylinderMesh.cpp
+ GeomMisc/DebugSphereMesh.cpp
+ GeomMisc/DebugPlaneMesh.cpp
+ GeomMisc/DebugPolygonMesh.cpp
+ GeomMisc/DebugTorusMesh.cpp
+ GeomMisc/DebugXMesh.cpp
+ GeomMisc/DebugRenderer.cpp GeomMisc/DebugTextDrawer.cpp
+ GeomMisc/DebugCircleDrawer.cpp
+ GeomMisc/DebugLineDrawer.cpp
+ GeomMisc/FontSystem/FontSystem.cpp GeomMisc/FontSystem/SwiffFont.cpp
+ GeomMisc/OverlayTexture.cpp GeomMisc/DebugLineGraphD3d.cpp GeomMisc/PerlinNoise.cpp
+ GeomMisc/DebugBlockGraphD3D.cpp
+ GeomMisc/LoadingScreen/LoadingScreen.cpp
+ GeomMisc/SplineControlPoint.cpp GeomMisc/EditorSpline.cpp
+ GeomMisc/MenuRend/MemeTexture.cpp GeomMisc/MenuRend/FSMoviePlayer.cpp
+ GeomMisc/MenuRend/Video.cpp GeomMisc/MenuRend/QuadDrawer.cpp
+ GeomMisc/MenuRend/QuadOutputCache.cpp
+ Geom/LightManagerConsole.cpp Geom/HemiMapManager/HemiMapManagerConsole.cpp
+ Geom/SkyDomeConsole.cpp Geom/TerrainConsole.cpp RendDX9/RendererConsole.cpp
+ Geom/TerrainCullerConsole.cpp
+ Geom/NametagManagerConsole.cpp Geom/Overgrowth/OverGrowthConsole.cpp
+ Geom/UndergrowthSystemConsole.cpp Geom/DecalSystem/DecalManagerConsole.cpp
+ Geom/ObjectGeometryConsole.cpp Geom/LightmapGeneration/LightmapGenerationConsole.cpp
+ Geom/StaticMeshRendererConsole.cpp Geom/WeatherManagerConsole.cpp
+ Geom/HeightmapEventNode.cpp)
+ list(APPEND BF2_RENDDX9_STATIC_SOURCES "${BF2_ROOT}/${rel}")
+ endforeach()
+
+ # Code/Build/swiffplayer.cmd, STEP 2, minus the kit and DllMain.cpp.
+ set(BF2_SWIFFPLAYER_STATIC_SOURCES
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/SwiffPlayerAbi/PluginEntry.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/SwiffPlayerAbi/SwiffMemory.cpp"
+ "${BF2_EXTERNAL_ROOT}/gameswf/SwiffPlayer/SwiffPlayer.cpp"
+ "${BF2_EXTERNAL_ROOT}/gameswf/SwiffPlayer/SwiffCrashLog.cpp"
+ "${BF2_EXTERNAL_ROOT}/gameswf/SwiffPlayer/SwiffPlayerModule.cpp"
+ )
+ foreach(rel
+ base/config.cpp base/container.cpp base/file_util.cpp base/image.cpp
+ base/image_filters.cpp base/jpeg.cpp base/membuf.cpp base/tu_file.cpp base/tu_random.cpp
+ base/tu_timer.cpp base/tu_types.cpp base/utf8.cpp base/utility.cpp
+ gameswf/gameswf_action.cpp gameswf/gameswf_button.cpp gameswf/gameswf_dlist.cpp
+ gameswf/gameswf_font.cpp gameswf/gameswf_fontlib.cpp gameswf/gameswf_impl.cpp
+ gameswf/gameswf_log.cpp gameswf/gameswf_morph2.cpp
+ gameswf/gameswf_render.cpp gameswf/gameswf_shape.cpp gameswf/gameswf_sound.cpp
+ gameswf/gameswf_stream.cpp gameswf/gameswf_string.cpp gameswf/gameswf_styles.cpp
+ gameswf/gameswf_tesselate.cpp gameswf/gameswf_text.cpp
+ gameswf/gameswf_timers.cpp gameswf/gameswf_types.cpp gameswf/gameswf_xml.cpp)
+ list(APPEND BF2_SWIFFPLAYER_STATIC_SOURCES "${BF2_EXTERNAL_ROOT}/${rel}")
+ endforeach()
+
+ # Code/Build/bf2audio.cmd, STEP 2, minus the kit. Win32System.cpp is that image's DllMain and
+ # its LoadLibrary wrappers; it stays in the list so the triage reports it (package S2.5).
+ set(BF2_BF2AUDIO_STATIC_SOURCES "${BF2_ROOT}/Sound/NullSound.cpp")
+ foreach(rel
+ Ambient.cpp BfOpenAL.cpp BfSoundEngine.cpp Music.cpp OpenALProvider.cpp
+ OpenALSample.cpp Reverb.cpp Sample.cpp Sound.cpp SoundDefaults.cpp SoundEvaluator.cpp
+ SoundFile.cpp SoundTrigger.cpp WavFileFormat.cpp Win32System.cpp)
+ list(APPEND BF2_BF2AUDIO_STATIC_SOURCES "${BF2_ROOT}/Sound/SoundEngine/${rel}")
+ endforeach()
+ set(BF2_VORBIS_STATIC_SOURCES
+ "${BF2_EXTERNAL_ROOT}/libogg-1.3.6/src/bitwise.c"
+ "${BF2_EXTERNAL_ROOT}/libogg-1.3.6/src/framing.c"
+ )
+ foreach(name
+ analysis bitrate block codebook envelope floor0 floor1 info lookup lpc lsp mapping0
+ mdct psy registry res0 sharedbook smallft synthesis vorbisfile window)
+ list(APPEND BF2_VORBIS_STATIC_SOURCES "${BF2_EXTERNAL_ROOT}/libvorbis-1.3.7/lib/${name}.c")
+ endforeach()
+
+ # The settings every plugin library shares with the client objects.
+ function(bf2_configure_static_plugin target image_define)
+ bf2_configure_cpp_target("${target}")
+ bf2_set_image("${target}" 0)
+ bf2_set_platform_compat("${target}")
+ target_compile_definitions("${target}" PRIVATE
+ _ITERATOR_DEBUG_LEVEL=0 BF2_PLATFORM_POSIX _MACOSX
+ BF2_STATIC_PLUGINS=1 ${image_define})
+ set_property(TARGET "${target}" PROPERTY FOLDER "BF2")
+ endfunction()
+
+ # [CHOSEN, not recovered] Each statically linked plugin image keeps its own host-service globals
+ # (dice::hfe::classManager, settings, g_system, game and the rest that its PluginEntry.cpp
+ # defines and its initDll fills), as the DLL did. The host defines globals of the same names,
+ # often with other types. The image's static library is therefore prelinked into one
+ # relocatable object (ld -r) in which the symbols named in Code/StaticPlugins/
+ # image-private-symbols.txt are bound to the image's own definitions and then made local;
+ # everything else keeps its linkage. See docs/macos-port.md, "Plugin globals".
+ # BF2Audio defines no host-service globals; its own null sound/template pair
+ # (Sound/SoundEngine/BfSoundEngine.cpp, created by getSoundEngine) is image-private in the
+ # same way and is listed in Code/StaticPlugins/bf2audio-private-symbols.txt.
+ set(BF2_STATIC_PLUGIN_PRIVATE_SYMBOLS
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/StaticPlugins/image-private-symbols.txt")
+ function(bf2_prelink_static_plugin consumer library symbols)
+ set(prelinked "${CMAKE_CURRENT_BINARY_DIR}/StaticPlugins/${library}_prelinked.o")
+ set(arch_flags "")
+ foreach(arch IN LISTS CMAKE_OSX_ARCHITECTURES)
+ list(APPEND arch_flags -arch "${arch}")
+ endforeach()
+ add_custom_command(OUTPUT "${prelinked}"
+ COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/StaticPlugins"
+ COMMAND "${CMAKE_CXX_COMPILER}" ${arch_flags} -r -nostdlib -o "${prelinked}"
+ "-Wl,-force_load,$"
+ "-Wl,-unexported_symbols_list,${symbols}"
+ DEPENDS "${library}" "$" "${symbols}"
+ COMMENT "Prelinking ${library} with image-private host-service globals"
+ VERBATIM)
+ target_sources("${consumer}" PRIVATE "${prelinked}")
+ set_source_files_properties("${prelinked}" PROPERTIES EXTERNAL_OBJECT TRUE GENERATED TRUE)
+ endfunction()
+
+ add_library(bf2_plugin_kit_static STATIC EXCLUDE_FROM_ALL
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/BfMemory.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/Frontier.cpp"
+ )
+ bf2_configure_static_plugin(bf2_plugin_kit_static "")
+ if(BF2_FRONTIER_DEFAULT_CONTINUE)
+ target_compile_definitions(bf2_plugin_kit_static PRIVATE BF2_FRONTIER_DEFAULT_CONTINUE=1)
+ endif()
+
+ add_library(bf2_renddx9_static STATIC EXCLUDE_FROM_ALL ${BF2_RENDDX9_STATIC_SOURCES})
+ bf2_configure_static_plugin(bf2_renddx9_static BF2_IMAGE_RENDDX9)
+ # [CHOSEN, not recovered] Native factories/build/save use the renderer's Metal D3D9 seam.
+ set(BF2_TEXTURE_ATLAS_NATIVE_SOURCES
+ "${BF2_ROOT}/RendDX9/TextureAtlas/TextureAtlasBuilder/Packer.cpp"
+ "${BF2_ROOT}/RendDX9/TextureAtlas/TextureAtlasBuilder/TextureAtlas.cpp"
+ "${BF2_ROOT}/RendDX9/TextureAtlas/TextureAtlasBuilder/TextureAtlasConfiguration.cpp"
+ "${BF2_ROOT}/RendDX9/TextureAtlas/TextureAtlasBuilder/TextureAtlasD3D9.cpp"
+ "${BF2_ROOT}/RendDX9/TextureAtlas/TextureAtlasBuilder/TextureFormat.cpp"
+ )
+ target_sources(bf2_renddx9_static PRIVATE ${BF2_TEXTURE_ATLAS_NATIVE_SOURCES})
+ # The host manifests also list these paths; keep their builder image guard inactive.
+ set_source_files_properties(${BF2_TEXTURE_ATLAS_NATIVE_SOURCES}
+ PROPERTIES COMPILE_DEFINITIONS
+ "$<$,bf2_renddx9_static>:BF2_IMAGE_TEXTUREATLASBUILDER=1>")
+ # [CHOSEN, not recovered] One renderer-only prefix selects the subset without TU switches.
+ target_include_directories(bf2_renddx9_static BEFORE PRIVATE
+ "${BF2_ROOT}/Platform/Gfx/MacInclude" "${BF2_ROOT}/Platform/Gfx/Include")
+ target_sources(bf2_renddx9_static PRIVATE
+ "${BF2_ROOT}/Platform/Gfx/Metal/Frontiers.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Metal/Effect.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Metal/D3DXMath.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Metal/D3DXGeometry.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Metal/D3DXLine.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Metal/D3DXPixels.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Metal/D3DXImages.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Metal/D3DXTextures.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Metal/D3DXMesh.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Metal/Device.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Metal/FFVertex.cpp"
+ "${BF2_ROOT}/Platform/Gfx/Metal/MetalBridge.mm"
+ # zeux/meshoptimizer v1.3 (MIT, External/meshoptimizer/LICENSE.md): the stripifier behind
+ # the native D3DXConvertMeshSubsetToSingleStrip in D3DXMesh.cpp.
+ "${BF2_EXTERNAL_ROOT}/meshoptimizer/stripifier.cpp")
+ set_source_files_properties("${BF2_ROOT}/Platform/Gfx/Metal/MetalBridge.mm"
+ PROPERTIES COMPILE_OPTIONS "-fobjc-arc")
+ target_compile_options(bf2_renddx9_static PRIVATE
+ "$<$:-include${BF2_ROOT}/Platform/Gfx/MacSupport.h>")
+ target_compile_definitions(bf2_renddx9_static PRIVATE
+ initDll=bf2_renddx9_initDll deinitDll=bf2_renddx9_deinitDll)
+
+ add_library(bf2_swiffplayer_static STATIC EXCLUDE_FROM_ALL ${BF2_SWIFFPLAYER_STATIC_SOURCES})
+ bf2_configure_static_plugin(bf2_swiffplayer_static BF2_IMAGE_SWIFFPLAYER)
+ target_compile_definitions(bf2_swiffplayer_static PRIVATE
+ initDll=bf2_swiffplayer_initDll deinitDll=bf2_swiffplayer_deinitDll)
+ target_include_directories(bf2_swiffplayer_static PRIVATE
+ "${BF2_EXTERNAL_ROOT}" "${BF2_EXTERNAL_ROOT}/gameswf")
+
+ # [CHOSEN, not recovered] Owner-approved Expat 1.95.0 substitute. The other
+ # xmltok .c files are included fragments, not separate translation units.
+ add_library(bf2_expat_static STATIC EXCLUDE_FROM_ALL
+ "${BF2_EXTERNAL_ROOT}/expat/xmlparse.c"
+ "${BF2_EXTERNAL_ROOT}/expat/xmltok.c"
+ "${BF2_EXTERNAL_ROOT}/expat/xmlrole.c")
+ bf2_configure_c_target(bf2_expat_static)
+ bf2_set_image(bf2_expat_static 0)
+ target_include_directories(bf2_expat_static PRIVATE "${BF2_EXTERNAL_ROOT}/expat")
+ set_property(TARGET bf2_expat_static PROPERTY FOLDER "BF2")
+ target_link_libraries(bf2_swiffplayer_static PUBLIC bf2_expat_static)
+
+ add_library(bf2_vorbis_static STATIC EXCLUDE_FROM_ALL ${BF2_VORBIS_STATIC_SOURCES})
+ bf2_configure_c_target(bf2_vorbis_static)
+ target_include_directories(bf2_vorbis_static PRIVATE
+ "${BF2_EXTERNAL_ROOT}/libogg-1.3.6/include"
+ "${BF2_EXTERNAL_ROOT}/libvorbis-1.3.7/include"
+ "${BF2_EXTERNAL_ROOT}/libvorbis-1.3.7/lib")
+ set_property(TARGET bf2_vorbis_static PROPERTY FOLDER "BF2")
+
+ # [CHOSEN, not recovered] FFmpeg 7.1.1's Bink video/audio decoders, unmodified, over the
+ # OpenBF2 shim (Code/BF2/External/ffmpeg-bink/README.md; LGPL-2.1-or-later). This is the macOS
+ # build; Windows x64 compiles the same files in Code/Build/renddx9.cmd, Windows x86 keeps RAD's
+ # binkw32.dll. Built optimized in every configuration, as FFmpeg is.
+ set(BF2_FFMPEG_BINK_DIR "${BF2_EXTERNAL_ROOT}/ffmpeg-bink")
+ add_library(bf2_ffmpeg_bink STATIC EXCLUDE_FROM_ALL
+ "${BF2_FFMPEG_BINK_DIR}/libavcodec/bink.c"
+ "${BF2_FFMPEG_BINK_DIR}/libavcodec/binkdsp.c"
+ "${BF2_FFMPEG_BINK_DIR}/libavcodec/binkaudio.c"
+ "${BF2_FFMPEG_BINK_DIR}/libavcodec/wma_freqs.c"
+ "${BF2_FFMPEG_BINK_DIR}/shim/ffbink_shim.c")
+ target_include_directories(bf2_ffmpeg_bink PRIVATE "${BF2_FFMPEG_BINK_DIR}/shim")
+ set_target_properties(bf2_ffmpeg_bink PROPERTIES C_STANDARD 11 C_STANDARD_REQUIRED ON
+ C_EXTENSIONS ON)
+ target_compile_options(bf2_ffmpeg_bink PRIVATE -O2 -fno-strict-aliasing -fno-math-errno
+ -Wno-pointer-sign)
+ set_property(TARGET bf2_ffmpeg_bink PROPERTY FOLDER "BF2")
+ # [CHOSEN, not recovered] CPU check of the Bink port against reference frames/samples that
+ # the local ffmpeg CLI produces from the read-only game content (Code/BF2/External/ffmpeg-bink/README.md).
+ add_executable(bf2_bink_decode_test EXCLUDE_FROM_ALL
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/Tests/macos_bink_decode.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/BinkFFmpeg.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/BinkAudioCoreAudio.cpp")
+ target_compile_features(bf2_bink_decode_test PRIVATE cxx_std_17)
+ target_link_libraries(bf2_bink_decode_test PRIVATE bf2_ffmpeg_bink "-framework AudioToolbox")
+ # [TEMP] [CHOSEN, not recovered] The black-box Bink harness, port side: the same source the
+ # retail build runs against binkw32.dll (Code/Tests/movies, Code/BF2/External/ffmpeg-bink/README.md).
+ add_executable(bf2_bink_harness EXCLUDE_FROM_ALL
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/Tests/movies/bink_harness.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/BinkFFmpeg.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/BinkAudioCoreAudio.cpp")
+ target_compile_features(bf2_bink_harness PRIVATE cxx_std_17)
+ target_link_libraries(bf2_bink_harness PRIVATE bf2_ffmpeg_bink "-framework AudioToolbox")
+
+ add_library(bf2_bf2audio_static STATIC EXCLUDE_FROM_ALL ${BF2_BF2AUDIO_STATIC_SOURCES})
+ bf2_configure_static_plugin(bf2_bf2audio_static "BF2_IMAGE_BF2AUDIO")
+ target_include_directories(bf2_bf2audio_static PRIVATE
+ "${BF2_EXTERNAL_ROOT}/libogg-1.3.6/include"
+ "${BF2_EXTERNAL_ROOT}/libvorbis-1.3.7/include")
+
+ # The client-image half of the macOS voice server, statically linked as the Linux server does.
+ add_library(bf2_voipserver_client_objects OBJECT EXCLUDE_FROM_ALL ${bf2_voipserver_only_sources})
+ bf2_configure_cpp_target(bf2_voipserver_client_objects)
+ bf2_set_image(bf2_voipserver_client_objects 0)
+ bf2_set_platform_compat(bf2_voipserver_client_objects)
+ target_compile_definitions(bf2_voipserver_client_objects PRIVATE BF2_PLATFORM_POSIX _MACOSX)
+ set_property(TARGET bf2_voipserver_client_objects PROPERTY FOLDER "BF2")
+
+ add_executable(bf2_client EXCLUDE_FROM_ALL
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/StaticPlugins/StaticPlugins.cpp"
+ $
+ $
+ $
+ $
+ $
+ $
+ $
+ $
+ $
+ )
+ bf2_configure_static_plugin(bf2_client "")
+ # bin_macos already holds the server `bf2`; APFS is case-insensitive, so the client cannot be
+ # `BF2` beside it. It shares the directory, and the @loader_path rpath, with libdice_py.dylib.
+ set_target_properties(bf2_client PROPERTIES
+ LINKER_LANGUAGE CXX
+ OUTPUT_NAME bf2_client
+ RUNTIME_OUTPUT_DIRECTORY "${BF2_DEDICATED_OUTPUT_DIR}"
+ BUILD_RPATH "@loader_path"
+ INSTALL_RPATH "@loader_path"
+ BUILD_WITH_INSTALL_RPATH TRUE
+ )
+ if(TARGET dice_py)
+ target_link_libraries(bf2_client PRIVATE dice_py)
+ endif()
+ # [CHOSEN, not recovered] The renderer uses the G2 subset and G3 Metal device;
+ # unimplemented operations stop. OFF keeps the
+ # renderer-free client: StaticPlugins.cpp has no RendDX9 entry and BF2Render::init takes
+ # its shipped failure return. ON links the image for coordinator device-creation checks.
+ option(BF2_MACOS_LINK_RENDDX9 "Link the RendDX9 static library into the macOS client" OFF)
+ if(BF2_MACOS_LINK_RENDDX9)
+ bf2_prelink_static_plugin(bf2_client bf2_renddx9_static "${BF2_STATIC_PLUGIN_PRIVATE_SYMBOLS}")
+ target_compile_definitions(bf2_client PRIVATE BF2_STATIC_RENDDX9=1)
+ # [CHOSEN, not recovered] The renderer's Bink port (BinkFFmpeg.cpp) and its audio output.
+ target_link_libraries(bf2_client PRIVATE bf2_ffmpeg_bink "-framework AudioToolbox")
+ # [CHOSEN, not recovered] The G4 effect facade (Metal/Effect.cpp) runs the s2 CPU runtime.
+ target_link_libraries(bf2_client PRIVATE bf2_fx_runtime)
+ # [CHOSEN, not recovered] System JPEG decoding in the prelinked renderer image.
+ target_link_libraries(bf2_client PRIVATE "-framework ImageIO" "-framework CoreGraphics")
+ endif()
+ target_compile_definitions(bf2_client PRIVATE BF2_STATIC_SWIFFPLAYER=1 BF2_STATIC_BF2AUDIO=1)
+ bf2_prelink_static_plugin(bf2_client bf2_swiffplayer_static "${BF2_STATIC_PLUGIN_PRIVATE_SYMBOLS}")
+ bf2_prelink_static_plugin(bf2_client bf2_bf2audio_static
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/StaticPlugins/bf2audio-private-symbols.txt")
+ target_link_libraries(bf2_client PRIVATE
+ bf2_vorbis_static bf2_expat_static bf2_plugin_kit_static
+ Threads::Threads ${CMAKE_DL_LIBS} ${CURSES_LIBRARIES})
+ target_link_options(bf2_client PRIVATE
+ "-Wl,-map,${BF2_DEDICATED_OUTPUT_DIR}/bf2_client.map")
+
+ # [CHOSEN, not recovered] The Cocoa host and the GCController poller (package S2.4,
+ # docs/macos-s2-4.md): ARC Objective-C++ with the plain-C++ headers the engine includes.
+ set(BF2_MACOS_HOST_OBJCXX_SOURCES
+ "${BF2_ROOT}/Platform/macOS/CocoaHost.mm"
+ "${BF2_ROOT}/Platform/macOS/MacGamepad.mm"
+ "${BF2_ROOT}/Platform/macOS/MacRawMouse.mm"
+ "${BF2_ROOT}/Platform/macOS/MacInputScript.mm") # [TEMP] BF2_INPUT_SCRIPT
+ target_sources(bf2_client PRIVATE ${BF2_MACOS_HOST_OBJCXX_SOURCES})
+ set_source_files_properties(${BF2_MACOS_HOST_OBJCXX_SOURCES}
+ PROPERTIES COMPILE_OPTIONS "-fobjc-arc")
+ target_link_libraries(bf2_client PRIVATE
+ "-framework AppKit" "-framework QuartzCore" "-framework Metal"
+ "-framework GameController" "-framework Carbon" "-framework IOKit")
+ # [CHOSEN, not recovered] BF2Audio's POSIX arm (Sound/SoundEngine/Win32System.cpp) queries the
+ # default output device through CoreAudio; OpenAL.framework itself is loaded at run time with
+ # dlopen, as the Win32 image loads OpenAL32.dll. MacSystem.cpp's alert uses CoreFoundation.
+ target_link_libraries(bf2_client PRIVATE "-framework CoreAudio" "-framework CoreFoundation")
+ # The SDK's CoreAudio voice layer (gvOSXAudio.c) converts sample rates with AudioConverter.
+ target_link_libraries(bf2_client PRIVATE "-framework AudioToolbox")
+
+ # [CHOSEN, not recovered] Keep all static-image views in native ABI agreement.
+ # This also runs for renderer-OFF builds. The script caches successful probes
+ # against real target flags and transitive headers; a warm gate takes seconds.
+ find_package(Python3 COMPONENTS Interpreter REQUIRED)
+ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+ add_executable(bf2_native_vtable_check EXCLUDE_FROM_ALL
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/Tests/macos_vtable_audit.cpp")
+ bf2_configure_cpp_target(bf2_native_vtable_check)
+ bf2_set_image(bf2_native_vtable_check 0)
+ target_compile_definitions(bf2_native_vtable_check PRIVATE BF2_STATIC_PLUGINS=1)
+ # [CHOSEN, not recovered] Pin captured BFMeme dispatch to native member encodings.
+ add_executable(bf2_meme_dispatch_check EXCLUDE_FROM_ALL
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/Tests/macos_meme_dispatch.cpp")
+ bf2_configure_cpp_target(bf2_meme_dispatch_check)
+ bf2_set_image(bf2_meme_dispatch_check 0)
+ # A cross build (an arm64-only tree on an Intel Mac) cannot execute the native checks:
+ # the static audit still gates the build with the target's own flags, and the linked
+ # checks ship in the M2 bundle (docs/macos-c-arm64-client.md).
+ set(BF2_VTABLE_CHECK_RUNNABLE ON)
+ if(CMAKE_OSX_ARCHITECTURES AND NOT CMAKE_HOST_SYSTEM_PROCESSOR IN_LIST CMAKE_OSX_ARCHITECTURES)
+ set(BF2_VTABLE_CHECK_RUNNABLE OFF)
+ endif()
+ if(BF2_VTABLE_CHECK_RUNNABLE)
+ set(BF2_VTABLE_CHECK_COMMAND COMMAND "$"
+ COMMAND "$")
+ else()
+ set(BF2_VTABLE_CHECK_COMMAND COMMAND "${CMAKE_COMMAND}" -E echo
+ "bf2_native_vtable_check and bf2_meme_dispatch_check are built for ${CMAKE_OSX_ARCHITECTURES} and run in the M2 bundle")
+ endif()
+ add_custom_target(bf2_vtable_audit ALL
+ COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/macos/vtable_audit.py"
+ --build-dir "${CMAKE_BINARY_DIR}"
+ # AI behaviour system (S0): native vtable order against libaidll.so's
+ # (tools/macos/ai_behaviour_vtables.json); clang computes the slots, cached.
+ COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/macos/ai_behaviour_vtables.py"
+ --build-dir "${CMAKE_BINARY_DIR}"
+ ${BF2_VTABLE_CHECK_COMMAND}
+ DEPENDS bf2_native_vtable_check bf2_meme_dispatch_check
+ COMMENT "Auditing native static-plugin vtables"
+ VERBATIM)
+ add_dependencies(bf2_client bf2_vtable_audit)
+ # [CHOSEN, not recovered] A game hosted from the client menu (the welcome page's instant
+ # battle, CREATE LOCAL) runs the server inside bf2_client, and BF2Engine names its AI image
+ # "aidll.dll" (BF2.exe 0x409CBD) - retail ships AIDLL.dll beside BF2.exe. The POSIX loader maps
+ # that to libaidll.dylib, found through the client's @loader_path rpath in bin_macos, where
+ # bf2_aidll is written. Without it AIConnection::init aborts (the shipped load-failure defect).
+ if(TARGET bf2_aidll)
+ add_dependencies(bf2_client bf2_aidll)
+ endif()
+ add_dependencies(bf2 bf2_vtable_audit)
+ add_dependencies(bf2_renddx9_static bf2_vtable_audit)
+ add_dependencies(bf2_swiffplayer_static bf2_vtable_audit)
+ add_dependencies(bf2_bf2audio_static bf2_vtable_audit)
endif()
# =================================================================================================
@@ -1750,8 +2282,464 @@ set_property(TARGET bf2_syntaxcheck PROPERTY FOLDER "Diagnostics")
endif()
include(CTest)
+
+# [TEMP] Issue #33: content-free policy checks, with no renderer or gameplay claim.
+add_executable(bf2_hud_widescreen_check EXCLUDE_FROM_ALL
+ Code/Tests/hud_widescreen_policy.cpp
+ "${BF2_ROOT}/Menu/HudWidescreen.cpp")
+bf2_configure_cpp_target(bf2_hud_widescreen_check)
+bf2_set_platform_compat(bf2_hud_widescreen_check)
+bf2_set_image(bf2_hud_widescreen_check 0)
+if(BUILD_TESTING)
+ add_test(NAME bf2_hud_widescreen_check COMMAND bf2_hud_widescreen_check)
+endif()
+
+if(BF2_BUILD_MACOS AND TARGET bf2_swiffplayer_static)
+ # [TEMP] [CHOSEN, not recovered] Content-free offline popup VM regression.
+ add_executable(bf2_swiff_offline_connect_popup_check EXCLUDE_FROM_ALL
+ Code/Tests/swiff_offline_connect_popup.cpp
+ Code/Tests/gameswf_xml/cocoa_host_unavailable.cpp)
+ bf2_configure_static_plugin(bf2_swiff_offline_connect_popup_check BF2_IMAGE_SWIFFPLAYER)
+ target_include_directories(bf2_swiff_offline_connect_popup_check PRIVATE
+ "${BF2_EXTERNAL_ROOT}" "${BF2_EXTERNAL_ROOT}/gameswf")
+ target_link_libraries(bf2_swiff_offline_connect_popup_check PRIVATE
+ bf2_swiffplayer_static bf2_plugin_kit_static)
+
+ # [TEMP] [CHOSEN, not recovered] The __proto__ probe SWFs (tools/swf/proto_probe.py) in the
+ # native gameswf must show retail 1.50's squares (docs/tracks/game/swf-proto-retail-probe.md).
+ add_executable(bf2_swf_proto_probe_check EXCLUDE_FROM_ALL
+ Code/Tests/swf_proto_probe_runtime.cpp
+ Code/Tests/gameswf_xml/cocoa_host_unavailable.cpp)
+ bf2_configure_static_plugin(bf2_swf_proto_probe_check BF2_IMAGE_SWIFFPLAYER)
+ target_include_directories(bf2_swf_proto_probe_check PRIVATE
+ "${BF2_EXTERNAL_ROOT}" "${BF2_EXTERNAL_ROOT}/gameswf")
+ target_link_libraries(bf2_swf_proto_probe_check PRIVATE bf2_swiffplayer_static bf2_plugin_kit_static)
+ if(BUILD_TESTING)
+ find_package(Python3 COMPONENTS Interpreter QUIET)
+ if(Python3_Interpreter_FOUND)
+ add_test(NAME bf2_swf_proto_probe_generate
+ COMMAND "${Python3_EXECUTABLE}" -I "${CMAKE_CURRENT_SOURCE_DIR}/tools/swf/proto_probe.py"
+ swf --out "${CMAKE_CURRENT_BINARY_DIR}/swf-proto-probe")
+ add_test(NAME bf2_swf_proto_probe_check
+ COMMAND bf2_swf_proto_probe_check "${CMAKE_CURRENT_BINARY_DIR}/swf-proto-probe")
+ set_tests_properties(bf2_swf_proto_probe_check PROPERTIES DEPENDS bf2_swf_proto_probe_generate)
+ endif()
+ endif()
+
+ # [TEMP] [CHOSEN, not recovered] Production gameswf XML/string/file fixture.
+ add_executable(bf2_gameswf_xml_check EXCLUDE_FROM_ALL
+ Code/Tests/gameswf_xml/xml_check.cpp
+ Code/Tests/gameswf_xml/cocoa_host_unavailable.cpp)
+ bf2_configure_static_plugin(bf2_gameswf_xml_check BF2_IMAGE_SWIFFPLAYER)
+ target_include_directories(bf2_gameswf_xml_check PRIVATE "${BF2_EXTERNAL_ROOT}")
+ target_link_libraries(bf2_gameswf_xml_check PRIVATE bf2_swiffplayer_static bf2_plugin_kit_static)
+ if(BUILD_TESTING)
+ add_test(NAME bf2_gameswf_xml_check COMMAND bf2_gameswf_xml_check
+ "${CMAKE_CURRENT_BINARY_DIR}/gameswf-xml-fixture.xml")
+ endif()
+endif()
+
+# [TEMP] Behaviour fixture for the recovered slider bodies (Code/Tests/slider_node_behaviour.cpp, game
+# frontier closure; Code/Tests/slider_node_behaviour.cmd is its Windows twin). The BFMeme families it
+# never calls stay unresolved, as /FORCE:UNRESOLVED leaves them in the Windows fixtures.
+if(APPLE)
+ add_executable(bf2_slider_node_check EXCLUDE_FROM_ALL
+ Code/Tests/slider_node_behaviour.cpp
+ "${BF2_ROOT}/External/BFMeme/SliderNode.cpp"
+ "${BF2_ROOT}/Menu/BfFixedSliderNode.cpp"
+ "${BF2_ROOT}/External/BFMeme/Node.cpp"
+ "${BF2_ROOT}/External/BFMeme/NodeState.cpp"
+ "${BF2_ROOT}/External/BFMeme/Object.cpp"
+ "${BF2_ROOT}/External/BFMeme/TypeDescriptor.cpp"
+ "${BF2_ROOT}/External/BFMeme/System.cpp"
+ "${BF2_ROOT}/External/BFMeme/Data.cpp"
+ "${BF2_ROOT}/External/BFMeme/NamedObjectRegistry.cpp"
+ "${BF2_ROOT}/External/BFMeme/Stream.cpp")
+ bf2_configure_cpp_target(bf2_slider_node_check)
+ bf2_set_platform_compat(bf2_slider_node_check)
+ bf2_set_image(bf2_slider_node_check 0)
+ target_link_options(bf2_slider_node_check PRIVATE "-Wl,-undefined,dynamic_lookup")
+ if(BUILD_TESTING)
+ add_test(NAME bf2_slider_node_check COMMAND bf2_slider_node_check)
+ endif()
+endif()
+
+# [TEMP] [CHOSEN, not recovered] Receive-size limit of DataBlockManager (Code/Tests/datablock_cap_runtime.cpp):
+# the actual DataBlockManager/DataBlockEvent/BitStream with a recording GameEventManager.
+if(APPLE)
+ add_executable(bf2_datablock_cap_check EXCLUDE_FROM_ALL
+ Code/Tests/datablock_cap_runtime.cpp
+ "${BF2_ROOT}/Game/Common/DataBlockManager.cpp"
+ "${BF2_ROOT}/Game/GameEvents/DataBlockEvent.cpp"
+ "${BF2_ROOT}/Game/Common/GameEvent.cpp"
+ "${BF2_ROOT}/Core/EventManager.cpp"
+ "${BF2_ROOT}/IO/BitStream.cpp")
+ bf2_configure_cpp_target(bf2_datablock_cap_check)
+ bf2_set_platform_compat(bf2_datablock_cap_check)
+ bf2_set_image(bf2_datablock_cap_check 0)
+ if(BUILD_TESTING)
+ add_test(NAME bf2_datablock_cap_check COMMAND bf2_datablock_cap_check)
+ endif()
+endif()
+
+# [TEMP] Cumulative fixture for game frontier-closure sites no normal session reaches
+# (Code/Tests/game_frontier_check.cpp; docs/tracks/game/frontier-closure.md). Built on request; the
+# families it never calls stay unresolved, as /FORCE:UNRESOLVED leaves them in the Windows fixtures.
+if(APPLE)
+ add_executable(bf2_game_frontier_check EXCLUDE_FROM_ALL
+ Code/Tests/game_frontier_check.cpp
+ Code/Tests/game_frontier_x87_narrow.cpp
+ "${BF2_ROOT}/Game/LocalProfileManager.cpp"
+ "${BF2_ROOT}/Game/LocalProfileManagerDiscovery.cpp"
+ "${BF2_ROOT}/Game/LocalProfileManagerFields.cpp"
+ "${BF2_ROOT}/Game/LocalProfileManagerInit.cpp"
+ "${BF2_ROOT}/Game/LocalProfileManagerOperations.cpp"
+ "${BF2_ROOT}/Game/LocalProfileManagerSelection.cpp"
+ "${BF2_ROOT}/Game/LocalProfileManagerSuffix.cpp"
+ "${BF2_ROOT}/Physics/MaterialManager.cpp"
+ "${BF2_ROOT}/External/BFMeme/Node.cpp"
+ "${BF2_ROOT}/External/BFMeme/NodeState.cpp"
+ "${BF2_ROOT}/External/BFMeme/Object.cpp"
+ "${BF2_ROOT}/External/BFMeme/TypeDescriptor.cpp"
+ "${BF2_ROOT}/External/BFMeme/System.cpp"
+ "${BF2_ROOT}/External/BFMeme/NamedObjectRegistry.cpp"
+ "${BF2_ROOT}/External/BFMeme/Data.cpp"
+ "${BF2_ROOT}/Menu/BfEditNode.cpp"
+ "${BF2_ROOT}/Menu/Bf2EditNode.cpp"
+ "${BF2_ROOT}/Menu/BfNewListBoxNode.cpp"
+ "${BF2_ROOT}/Menu/BfListBoxData.cpp"
+ "${BF2_ROOT}/External/BFMeme/Action.cpp"
+ "${BF2_ROOT}/External/BFMeme/Tree.cpp"
+ "${BF2_ROOT}/External/BFMeme/Stream.cpp"
+ "${BF2_ROOT}/Menu/ProfileConsoleBindings.cpp"
+ "${BF2_ROOT}/Core/ConsoleObjectBase.cpp"
+ "${BF2_ROOT}/Game/DistributedLightRenderer/DistributedLightRenderer.cpp"
+ "${BF2_ROOT}/Game/Common/GameEvent.cpp"
+ "${BF2_ROOT}/Core/StringUtil.cpp"
+ "${BF2_ROOT}/AI/AIInterface/BFKnowledge/BFGame.cpp")
+ bf2_configure_cpp_target(bf2_game_frontier_check)
+ bf2_set_platform_compat(bf2_game_frontier_check)
+ bf2_set_image(bf2_game_frontier_check 0)
+ set_source_files_properties(Code/Tests/game_frontier_x87_narrow.cpp PROPERTIES
+ COMPILE_OPTIONS "-Wno-builtin-macro-redefined;-U__LDBL_MANT_DIG__;-D__LDBL_MANT_DIG__=53")
+ target_link_options(bf2_game_frontier_check PRIVATE "-Wl,-undefined,dynamic_lookup")
+ if(BUILD_TESTING)
+ add_test(NAME bf2_game_frontier_check COMMAND bf2_game_frontier_check)
+ endif()
+endif()
+
+# [CHOSEN, not recovered] The frontier trap's default (Code/Tests/frontier_default_check.cpp): the kit's
+# Frontier.cpp built as a dev image (default abort) and as a release image
+# (BF2_FRONTIER_DEFAULT_CONTINUE=1, default continue); explicit env values win in both.
+if(APPLE)
+ foreach(bf2_frontier_mode IN ITEMS abort continue)
+ set(bf2_frontier_target bf2_frontier_default_${bf2_frontier_mode}_check)
+ add_executable(${bf2_frontier_target} EXCLUDE_FROM_ALL
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/Tests/frontier_default_check.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/Code/RendDX9Abi/Frontier.cpp")
+ if(bf2_frontier_mode STREQUAL "continue")
+ target_compile_definitions(${bf2_frontier_target} PRIVATE
+ BF2_FRONTIER_DEFAULT_CONTINUE=1 BF2_FRONTIER_CHECK_EXPECT_CONTINUE=1)
+ else()
+ target_compile_definitions(${bf2_frontier_target} PRIVATE BF2_FRONTIER_CHECK_EXPECT_CONTINUE=0)
+ endif()
+ if(BUILD_TESTING)
+ add_test(NAME ${bf2_frontier_target} COMMAND ${bf2_frontier_target})
+ endif()
+ endforeach()
+endif()
+
+# [TEMP] The voice client (Code/Tests/voip_client_runtime.cpp): VoipClient over loopback UDP and
+# BF2VoipClient on fake game objects, with the synthetic capture device (no microphone, no permission
+# prompt). The mixer (Code/Tests/voip_mixer_runtime.cpp) runs on its scripted WINMM table.
+if(APPLE)
+ add_executable(bf2_voip_client_check EXCLUDE_FROM_ALL
+ Code/Tests/voip_client_runtime.cpp
+ "${BF2_ROOT}/Game/VoipClient/VoipClient.cpp"
+ "${BF2_ROOT}/Game/VoipClient/BF2VoipClient.cpp"
+ "${BF2_ROOT}/Game/VoipClient/VoipMixer.cpp"
+ "${BF2_ROOT}/Game/VoipClient/VoipFakeDevice.cpp"
+ $
+ $)
+ bf2_configure_cpp_target(bf2_voip_client_check)
+ bf2_set_platform_compat(bf2_voip_client_check)
+ bf2_set_image(bf2_voip_client_check 0)
+ target_compile_definitions(bf2_voip_client_check PRIVATE BF2_PLATFORM_POSIX _MACOSX
+ BF2_VOIPMIXER_NO_PLATFORM_BACKEND=1)
+ target_link_options(bf2_voip_client_check PRIVATE "-Wl,-undefined,dynamic_lookup")
+ target_link_libraries(bf2_voip_client_check PRIVATE "-framework CoreAudio" "-framework AudioToolbox"
+ "-framework CoreFoundation" Threads::Threads)
+ if(BUILD_TESTING)
+ add_test(NAME bf2_voip_client_check COMMAND bf2_voip_client_check)
+ endif()
+
+ # The retail x86 layout asserts of the voice client, compiled for the MSVC x86 ABI from the Mac
+ # (clang's i686-pc-windows-msvc target, stub STL headers); the real check is the Windows x86 build.
+ if(BUILD_TESTING AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ add_test(NAME bf2_voip_msvc_x86_layout
+ COMMAND "${CMAKE_CXX_COMPILER}" -target i686-pc-windows-msvc -fsyntax-only -std=c++14 -Wno-invalid-offsetof -Wno-unused-command-line-argument
+ -nostdinc -nostdinc++ -I "${CMAKE_CURRENT_SOURCE_DIR}/Code/Tests/msvc_x86_layout/include"
+ -D_M_IX86=600 "${CMAKE_CURRENT_SOURCE_DIR}/Code/Tests/msvc_x86_layout/msvc_x86_layout.cpp")
+ endif()
+
+ add_executable(bf2_voip_mixer_check EXCLUDE_FROM_ALL
+ Code/Tests/voip_mixer_runtime.cpp
+ "${BF2_ROOT}/Game/VoipClient/VoipMixer.cpp")
+ bf2_configure_cpp_target(bf2_voip_mixer_check)
+ bf2_set_platform_compat(bf2_voip_mixer_check)
+ bf2_set_image(bf2_voip_mixer_check 0)
+ target_compile_definitions(bf2_voip_mixer_check PRIVATE BF2_VOIPMIXER_NO_PLATFORM_BACKEND=1)
+ if(BUILD_TESTING)
+ add_test(NAME bf2_voip_mixer_check COMMAND bf2_voip_mixer_check)
+ endif()
+endif()
+
+# [TEMP] The PunkBuster glue objects at the 32-bit x86 ABI (Code/Tests/msvc_x86_layout/punkbuster_x86_layout.cpp).
+if(BUILD_TESTING AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ foreach(pb_abi IN ITEMS msvc elf)
+ if(pb_abi STREQUAL "msvc")
+ set(pb_triple i686-pc-windows-msvc)
+ set(pb_define -D_M_IX86=600)
+ else()
+ set(pb_triple i386-pc-linux-gnu)
+ set(pb_define -D__i386__=1)
+ endif()
+ add_test(NAME bf2_punkbuster_${pb_abi}_x86_layout
+ COMMAND "${CMAKE_CXX_COMPILER}" -target ${pb_triple} -fsyntax-only -std=c++14 -Wno-invalid-offsetof -Wno-unused-command-line-argument -Wno-macro-redefined
+ -nostdinc -nostdinc++ -I "${CMAKE_CURRENT_SOURCE_DIR}/Code/Tests/msvc_x86_layout/include"
+ ${pb_define} "${CMAKE_CURRENT_SOURCE_DIR}/Code/Tests/msvc_x86_layout/punkbuster_x86_layout.cpp")
+ endforeach()
+endif()
+
+# [TEMP] PunkBuster client glue and command hook (Code/Tests/punkbuster_client_runtime.cpp) against a
+# fake pbcl.dll through the glue's library seam, fake PB_* functions and a fake server trap. Built on
+# request; files only under a fresh temporary directory.
+if(APPLE)
+ add_executable(bf2_punkbuster_client_check EXCLUDE_FROM_ALL
+ Code/Tests/punkbuster_client_runtime.cpp
+ "${BF2_ROOT}/Game/PunkBuster/PbClient.cpp"
+ "${BF2_ROOT}/Game/PunkBuster/PbCommandHook.cpp")
+ bf2_configure_cpp_target(bf2_punkbuster_client_check)
+ bf2_set_platform_compat(bf2_punkbuster_client_check)
+ bf2_set_image(bf2_punkbuster_client_check 0)
+ if(BUILD_TESTING)
+ add_test(NAME bf2_punkbuster_client_check COMMAND bf2_punkbuster_client_check)
+ endif()
+endif()
+
+# [TEMP] The BF2-side PunkBuster functions (Code/Tests/punkbuster_game_runtime.cpp) against fake games,
+# console, players, glue entry points and helpers, in the client and the dedicated image. Built on request.
+if(APPLE)
+ add_executable(bf2_punkbuster_game_check EXCLUDE_FROM_ALL
+ Code/Tests/punkbuster_game_runtime.cpp
+ "${BF2_ROOT}/Game/PunkBuster/PbGame.cpp"
+ "${BF2_ROOT}/Game/Objects/IPlayer.cpp")
+ bf2_configure_cpp_target(bf2_punkbuster_game_check)
+ bf2_set_platform_compat(bf2_punkbuster_game_check)
+ bf2_set_image(bf2_punkbuster_game_check 0)
+ target_include_directories(bf2_punkbuster_game_check PRIVATE ${BF2_PYTHON_INCLUDE_DIRS})
+ if(BUILD_TESTING)
+ add_test(NAME bf2_punkbuster_game_check COMMAND bf2_punkbuster_game_check)
+ endif()
+ add_executable(bf2_punkbuster_game_dedicated_check EXCLUDE_FROM_ALL
+ Code/Tests/punkbuster_game_runtime.cpp
+ "${BF2_ROOT}/Game/PunkBuster/PbGame.cpp"
+ "${BF2_ROOT}/Game/Objects/IPlayer.cpp")
+ bf2_configure_cpp_target(bf2_punkbuster_game_dedicated_check)
+ bf2_set_platform_compat(bf2_punkbuster_game_dedicated_check)
+ bf2_set_image(bf2_punkbuster_game_dedicated_check 1)
+ target_include_directories(bf2_punkbuster_game_dedicated_check PRIVATE ${BF2_PYTHON_INCLUDE_DIRS})
+ if(BUILD_TESTING)
+ add_test(NAME bf2_punkbuster_game_dedicated_check COMMAND bf2_punkbuster_game_dedicated_check)
+ endif()
+endif()
+
+# [TEMP] The PunkBuster server glue (Code/Tests/punkbuster_server_runtime.cpp) against a fake pbsv,
+# fake PB_* functions and a scratch pb folder, in both images (the capture buffer's home differs).
+# Built on request.
+if(APPLE OR UNIX)
+ foreach(pbsv_image IN ITEMS dedicated client)
+ if(pbsv_image STREQUAL "dedicated")
+ set(pbsv_target bf2_punkbuster_server_check)
+ set(pbsv_define 1)
+ else()
+ set(pbsv_target bf2_punkbuster_server_client_check)
+ set(pbsv_define 0)
+ endif()
+ add_executable(${pbsv_target} EXCLUDE_FROM_ALL
+ Code/Tests/punkbuster_server_runtime.cpp
+ "${BF2_ROOT}/Game/PunkBuster/PbServer.cpp")
+ bf2_configure_cpp_target(${pbsv_target})
+ bf2_set_platform_compat(${pbsv_target})
+ bf2_set_image(${pbsv_target} ${pbsv_define})
+ if(BUILD_TESTING)
+ add_test(NAME ${pbsv_target} COMMAND ${pbsv_target})
+ endif()
+ endforeach()
+endif()
+
+# [TEMP] Camera::handleUpdate and its shake/recoil helpers (Code/Tests/camera_shake_runtime.cpp): the real
+# Camera.cpp against generated fakes; every other engine symbol it references becomes an aborting stub
+# generated from the objects by tools/macos/link_stubs.py. Built on request.
+if(APPLE)
+ find_package(Python3 COMPONENTS Interpreter REQUIRED)
+ add_library(bf2_camera_shake_objects OBJECT EXCLUDE_FROM_ALL
+ Code/Tests/camera_shake_runtime.cpp
+ "${BF2_ROOT}/Game/Objects/Base/Camera.cpp"
+ "${BF2_ROOT}/Game/Objects/IPlayer.cpp"
+ "${BF2_ROOT}/Scene/Object/ObjectPredicator.cpp")
+ bf2_configure_cpp_target(bf2_camera_shake_objects)
+ bf2_set_platform_compat(bf2_camera_shake_objects)
+ bf2_set_image(bf2_camera_shake_objects 0)
+ target_include_directories(bf2_camera_shake_objects PRIVATE ${BF2_PYTHON_INCLUDE_DIRS})
+ set(bf2_camera_shake_stubs "${CMAKE_CURRENT_BINARY_DIR}/camera_shake_link_stubs.cpp")
+ add_custom_command(OUTPUT "${bf2_camera_shake_stubs}"
+ COMMAND "${Python3_EXECUTABLE}" -I "${CMAKE_CURRENT_SOURCE_DIR}/tools/macos/link_stubs.py"
+ "${bf2_camera_shake_stubs}" $
+ DEPENDS bf2_camera_shake_objects $
+ "${CMAKE_CURRENT_SOURCE_DIR}/tools/macos/link_stubs.py"
+ COMMAND_EXPAND_LISTS
+ COMMENT "Generating the camera shake check's link stubs")
+ add_executable(bf2_camera_shake_check EXCLUDE_FROM_ALL
+ $ "${bf2_camera_shake_stubs}")
+ bf2_configure_cpp_target(bf2_camera_shake_check)
+ bf2_set_platform_compat(bf2_camera_shake_check)
+ bf2_set_image(bf2_camera_shake_check 0)
+ if(BUILD_TESTING)
+ add_test(NAME bf2_camera_shake_check COMMAND bf2_camera_shake_check)
+ endif()
+endif()
+
+# [TEMP] The Soldier's control-box profile switch (Code/Tests/soldier_haptic_profile_runtime.cpp,
+# ledger N2 17a) against a generated fake HapticSettings and fake player-control templates. Built on request.
+if(APPLE OR UNIX)
+ add_executable(bf2_soldier_haptic_profile_check EXCLUDE_FROM_ALL
+ Code/Tests/soldier_haptic_profile_runtime.cpp
+ "${BF2_ROOT}/Game/Objects/Game/SoldierHapticProfile.cpp"
+ "${BF2_ROOT}/Math/Vec3.cpp")
+ bf2_configure_cpp_target(bf2_soldier_haptic_profile_check)
+ bf2_set_platform_compat(bf2_soldier_haptic_profile_check)
+ bf2_set_image(bf2_soldier_haptic_profile_check 0)
+ if(BUILD_TESTING)
+ add_test(NAME bf2_soldier_haptic_profile_check COMMAND bf2_soldier_haptic_profile_check)
+ endif()
+endif()
+
+# [TEMP] dice::hfe::Mutex recursion and exclusion (Code/Tests/mutex_runtime.cpp). Built on request.
+if(APPLE OR UNIX)
+ add_executable(bf2_mutex_check EXCLUDE_FROM_ALL
+ Code/Tests/mutex_runtime.cpp
+ "${BF2_ROOT}/Core/Mutex.cpp")
+ bf2_configure_cpp_target(bf2_mutex_check)
+ bf2_set_platform_compat(bf2_mutex_check)
+ find_package(Threads REQUIRED)
+ target_link_libraries(bf2_mutex_check PRIVATE Threads::Threads)
+ if(BUILD_TESTING)
+ add_test(NAME bf2_mutex_check COMMAND bf2_mutex_check)
+ endif()
+endif()
+
+# [TEMP] CBF2VoipServer::Shutdown under one dice::hfe::Mutex (Code/Tests/voip_server_shutdown_runtime.cpp):
+# the relock through ReleaseAllInstances must not hang. Built on request; UDP port 55197 only.
+if(APPLE)
+ add_executable(bf2_voip_server_shutdown_check EXCLUDE_FROM_ALL
+ Code/Tests/voip_server_shutdown_runtime.cpp
+ "${BF2_ROOT}/IO/Network/SocketManager.cpp"
+ "${BF2_ROOT}/IO/Network/NetworkLayer/Socket/UDPSocket.cpp"
+ "${BF2_ROOT}/VoipServer/VoipServer.cpp"
+ "${BF2_ROOT}/VoipServer/VoipServerInstance.cpp"
+ "${BF2_ROOT}/VoipServer/VoipDebug.cpp"
+ "${BF2_ROOT}/VoipServer/VoipRouter.cpp"
+ "${BF2_ROOT}/VoipServer/VoipClients.cpp"
+ "${BF2_ROOT}/VoipServer/VoipOutgoingChannels.cpp"
+ "${BF2_ROOT}/Core/Mutex.cpp"
+ "${BF2_ROOT}/Core/Timer.cpp"
+ "${BF2_ROOT}/Core/SystemInfo.cpp"
+ "${BF2_ROOT}/Core/StringUtil.cpp")
+ bf2_configure_cpp_target(bf2_voip_server_shutdown_check)
+ bf2_set_platform_compat(bf2_voip_server_shutdown_check)
+ bf2_set_image(bf2_voip_server_shutdown_check 1)
+ target_compile_definitions(bf2_voip_server_shutdown_check PRIVATE BF2_PLATFORM_POSIX _MACOSX)
+ # The challenge hash's MD5 (GameSpy md5c.c) is C; it builds without the C++ compatibility header.
+ add_library(bf2_voip_server_shutdown_md5 OBJECT EXCLUDE_FROM_ALL "${BF2_ROOT}/External/GameSpy/md5c.c")
+ target_sources(bf2_voip_server_shutdown_check PRIVATE $)
+ if(BUILD_TESTING)
+ add_test(NAME bf2_voip_server_shutdown_check COMMAND bf2_voip_server_shutdown_check)
+ endif()
+endif()
+
+# [TEMP] Voice-server debug logs (Code/Tests/voip_debug_runtime.cpp, Windows twin
+# voip_debug_runtime.cmd): HandlePacketDebugRoutingData, the routing dump and the voice trace, read
+# back from the files they write. Built on request; the dedicated image (DEDICATED=1) as in the twin.
+if(APPLE)
+ add_executable(bf2_voip_debug_check EXCLUDE_FROM_ALL
+ Code/Tests/voip_debug_runtime.cpp
+ "${BF2_ROOT}/VoipServer/VoipServerInstance.cpp"
+ "${BF2_ROOT}/VoipServer/VoipDebug.cpp"
+ "${BF2_ROOT}/VoipServer/VoipRouter.cpp"
+ "${BF2_ROOT}/VoipServer/VoipClients.cpp"
+ "${BF2_ROOT}/VoipServer/VoipOutgoingChannels.cpp"
+ "${BF2_ROOT}/Core/Timer.cpp"
+ "${BF2_ROOT}/Core/SystemInfo.cpp"
+ "${BF2_ROOT}/Core/StringUtil.cpp")
+ bf2_configure_cpp_target(bf2_voip_debug_check)
+ bf2_set_platform_compat(bf2_voip_debug_check)
+ bf2_set_image(bf2_voip_debug_check 1)
+ target_compile_definitions(bf2_voip_debug_check PRIVATE BF2_PLATFORM_POSIX _MACOSX)
+ target_link_options(bf2_voip_debug_check PRIVATE "-Wl,-undefined,dynamic_lookup")
+ if(BUILD_TESTING)
+ add_test(NAME bf2_voip_debug_check COMMAND bf2_voip_debug_check)
+ endif()
+endif()
+
+# [TEMP] The online services' domain (Code/Tests/online_provider_runtime.cpp): the host names formed
+# for the retail domain and for a +gamespy value, looked up by the linked GameSpy SDK and by
+# the persistence classes. The fixture replaces the resolver, so no name leaves the process, and
+# listens on the services' own loopback ports. Built on request; the client image (DEDICATED=0),
+# which links every service.
+if(APPLE)
+ add_executable(bf2_online_provider_check EXCLUDE_FROM_ALL
+ Code/Tests/online_provider_runtime.cpp
+ "${BF2_ROOT}/Game/MatchMaking/OnlineProvider.cpp"
+ "${BF2_ROOT}/Game/MatchMaking/OnlineProviderGameSpy.cpp"
+ "${BF2_ROOT}/Game/Persistence/HTTPRequest.cpp"
+ "${BF2_ROOT}/Game/Persistence/StatsManager.cpp"
+ "${BF2_ROOT}/Game/Persistence/PlayerStatsManager.cpp"
+ "${BF2_ROOT}/Core/StringUtil.cpp"
+ $
+ $
+ $)
+ bf2_configure_cpp_target(bf2_online_provider_check)
+ bf2_set_platform_compat(bf2_online_provider_check)
+ bf2_set_image(bf2_online_provider_check 0)
+ target_compile_definitions(bf2_online_provider_check PRIVATE BF2_PLATFORM_POSIX _MACOSX)
+ find_package(Threads REQUIRED)
+ target_link_libraries(bf2_online_provider_check PRIVATE Threads::Threads)
+ if(BUILD_TESTING)
+ add_test(NAME bf2_online_provider_check COMMAND bf2_online_provider_check)
+ endif()
+endif()
+
+# bf2_memory - the rebuilt Memory.dll (Code/BF2/Memory). Built on request only (EXCLUDE_FROM_ALL)
+# and linked into no game image (issue #7). Its tests join CTest when BF2_MEMORY_TESTS is ON.
+add_subdirectory(Code/BF2/Memory)
+
+# [CHOSEN, not recovered] CPU-only effect pipeline for the macOS renderer facade.
+if(BF2_BUILD_MACOS)
+ add_subdirectory(Code/BF2/Platform/Gfx/Effect)
+ add_subdirectory(Code/Tests/macos_gfx_forward)
+ # [CHOSEN, not recovered] Native effect compilation is mandatory; the effect subdirectory
+ # rejects missing dependencies at configure time. No developer oracle is invoked here.
+ if(TARGET bf2_renddx9_static)
+ target_compile_definitions(bf2_renddx9_static PRIVATE BF2_FX_NATIVE=1)
+ endif()
+ if(BF2_MACOS_LINK_RENDDX9 AND TARGET bf2_client AND TARGET bf2_renddx9_static)
+ target_link_libraries(bf2_client PRIVATE bf2_fx_native_compiler)
+ target_include_directories(bf2_renddx9_static PRIVATE "${BF2_ROOT}/Platform/Gfx/Effect")
+ endif()
+endif()
# The focused checks mirror Code/Tests/*.cmd, which are MSVC x86 gates; they are not part of the
-# Linux port (its checks are the dice_py runtime check and the production run).
+# Linux and macOS ports (their checks are the dice_py runtime check and the production run).
if(BUILD_TESTING AND MSVC)
function(bf2_add_check target)
add_executable("${target}" EXCLUDE_FROM_ALL ${ARGN})
@@ -1818,6 +2806,9 @@ if(BUILD_TESTING AND MSVC)
"${BF2_ROOT}/Game/Objects/Visual/LightSource.cpp"
"${BF2_ROOT}/Game/Objects/Visual/LightSourceTemplate.cpp"
"${BF2_ROOT}/Scene/Object/WorldObjTemplPortal/PortalManager.cpp"
+ "${BF2_ROOT}/Scene/Object/WorldObjTemplPortal/PortalPassing.cpp"
+ "${BF2_ROOT}/Scene/Object/WorldObjTemplPortal/Sector.cpp"
+ "${BF2_ROOT}/Scene/Object/WorldObjTemplPortal/PortalEvent.cpp"
"${BF2_ROOT}/Scene/Object/Object.cpp"
"${BF2_ROOT}/Scene/Object/ObjectPredicator.cpp"
"${BF2_ROOT}/Scene/Object/ObjectUtil.cpp"
@@ -1841,6 +2832,8 @@ if(BUILD_TESTING AND MSVC)
"${BF2_ROOT}/Physics/StaticResponsePhysics.cpp"
"${BF2_ROOT}/IO/Network/INetworkable.cpp"
"${BF2_ROOT}/Math/LocalBoundingBox.cpp"
+ "${BF2_ROOT}/Math/Intersect.cpp"
+ "${BF2_ROOT}/IO/Stream/BoundingBox.cpp"
"${BF2_ROOT}/Math/Frustum.cpp"
"${BF2_ROOT}/Math/Mat4.cpp"
"${BF2_ROOT}/Math/Plane3.cpp"
@@ -1853,6 +2846,25 @@ if(BUILD_TESTING AND MSVC)
target_compile_options(bf2_runtime_pair PRIVATE /Gy)
target_link_options(bf2_runtime_pair PRIVATE /OPT:REF)
+ # [CHOSEN, not recovered] The client's Registry.dat (docs/registry-file.md): fake CD keys
+ # round-trip through CryptProtectData and the production reader, and through the dev script.
+ # A client image (DEDICATED=0), so it is not a bf2_add_check.
+ add_executable(bf2_registry_dat_check EXCLUDE_FROM_ALL
+ "${BF2_STUB_ROOT}/registry_dat_check.cpp"
+ "${BF2_ROOT}/Core/Registry.cpp"
+ )
+ target_compile_features(bf2_registry_dat_check PRIVATE cxx_std_14)
+ target_compile_options(bf2_registry_dat_check PRIVATE /EHsc /O2 /permissive)
+ bf2_use_static_msvc_runtime(bf2_registry_dat_check)
+ bf2_set_image(bf2_registry_dat_check 0)
+ set_property(TARGET bf2_registry_dat_check PROPERTY FOLDER "Checks")
+ add_test(NAME bf2_registry_dat_check COMMAND $)
+ add_test(NAME bf2_registry_dat_script
+ COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command
+ "& '${CMAKE_CURRENT_SOURCE_DIR}/tools/windows/new-registry-dat.ps1' -CdKey FAKE-SCRIPT-0000-1111 -Path '${CMAKE_BINARY_DIR}/registry_dat_script/Registry.dat'; if (-not $?) { exit 1 }; & '$' '${CMAKE_BINARY_DIR}/registry_dat_script/Registry.dat' FAKE-SCRIPT-0000-1111; exit $LASTEXITCODE"
+ )
+ set_tests_properties(bf2_registry_dat_check bf2_registry_dat_script PROPERTIES RUN_SERIAL TRUE)
+
add_custom_target(bf2_run_checks
COMMAND "${CMAKE_CTEST_COMMAND}" --output-on-failure -C $
DEPENDS
@@ -1861,6 +2873,7 @@ if(BUILD_TESTING AND MSVC)
bf2_bundle_template_core
bf2_bundle_serialization
bf2_runtime_pair
+ bf2_registry_dat_check
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
USES_TERMINAL
VERBATIM
diff --git a/CMakePresets.json b/CMakePresets.json
index e2b3267df..0a9bde771 100644
--- a/CMakePresets.json
+++ b/CMakePresets.json
@@ -55,6 +55,36 @@
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"BUILD_TESTING": "OFF"
}
+ },
+ {
+ "name": "macos-x64",
+ "displayName": "BF2 native macOS dedicated port",
+ "description": "AppleClang on macOS: x86_64 build with Unix Makefiles. Needs the Command Line Tools and cmake.",
+ "generator": "Unix Makefiles",
+ "binaryDir": "${sourceDir}/out/build/${presetName}",
+ "condition": {
+ "type": "equals",
+ "lhs": "${hostSystemName}",
+ "rhs": "Darwin"
+ },
+ "cacheVariables": {
+ "CMAKE_OSX_SYSROOT": "macosx",
+ "CMAKE_OSX_ARCHITECTURES": "x86_64",
+ "CMAKE_OSX_DEPLOYMENT_TARGET": "11.0",
+ "CMAKE_BUILD_TYPE": "RelWithDebInfo",
+ "CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
+ "BUILD_TESTING": "OFF"
+ }
+ },
+ {
+ "name": "macos-universal",
+ "inherits": "macos-x64",
+ "displayName": "BF2 native macOS universal port",
+ "description": "[CHOSEN, not recovered] AppleClang arm64 and x86_64 slices; arm64 runtime validation requires Apple silicon.",
+ "binaryDir": "${sourceDir}/out/build/${presetName}",
+ "cacheVariables": {
+ "CMAKE_OSX_ARCHITECTURES": "arm64;x86_64"
+ }
}
],
"buildPresets": [
@@ -90,6 +120,25 @@
"bf2",
"dice_py_check"
]
+ },
+ {
+ "name": "macos-x64",
+ "displayName": "Build bf2 and libdice_py.dylib",
+ "configurePreset": "macos-x64",
+ "targets": [
+ "bf2",
+ "dice_py_check"
+ ]
+ },
+ {
+ "name": "macos-universal",
+ "displayName": "Build universal server and runtime checks",
+ "configurePreset": "macos-universal",
+ "targets": [
+ "bf2",
+ "dice_py_check",
+ "bf2_aidll_loader_check"
+ ]
}
],
"testPresets": [
diff --git a/Code/AidllAbi/aidll-macos.exports b/Code/AidllAbi/aidll-macos.exports
new file mode 100644
index 000000000..35046f6f3
--- /dev/null
+++ b/Code/AidllAbi/aidll-macos.exports
@@ -0,0 +1,3 @@
+# [CHOSEN, not recovered] Native macOS AI image boundary; all other symbols are private.
+_initDll
+_deinitDll
diff --git a/Code/AidllAbi/aidll-posix.map b/Code/AidllAbi/aidll-posix.map
new file mode 100644
index 000000000..4d06b9dd2
--- /dev/null
+++ b/Code/AidllAbi/aidll-posix.map
@@ -0,0 +1,5 @@
+/* [CHOSEN, not recovered] Native POSIX AI image boundary; prevent host interposition. */
+{
+ global: initDll; deinitDll;
+ local: *;
+};
diff --git a/Code/AidllAbi/aidll-x64.def b/Code/AidllAbi/aidll-x64.def
new file mode 100644
index 000000000..00cf6846a
--- /dev/null
+++ b/Code/AidllAbi/aidll-x64.def
@@ -0,0 +1,6 @@
+; [CHOSEN, not recovered] Native Windows x64 AI entry points (kr4uzi/OpenBF2 issue #11).
+; LoadLibraryBf resolves these names; retail x86 export ordinals are not an x64 contract.
+; All other interaction uses the native ClassManager/singleton ABI shared with the host.
+EXPORTS
+ deinitDll
+ initDll
diff --git a/Code/Archive/NovintFalcon/External/NovintHFX/NovintHFX.def b/Code/Archive/NovintFalcon/External/NovintHFX/NovintHFX.def
new file mode 100644
index 000000000..ab9a40271
--- /dev/null
+++ b/Code/Archive/NovintFalcon/External/NovintHFX/NovintHFX.def
@@ -0,0 +1,100 @@
+; Exact subset of the original BF2.exe import names, exported by stock NovintHFX.dll.
+; Import library only: lib /nologo /machine:x86 /def:NovintHFX.def /out:/NovintHFX.lib
+LIBRARY NovintHFX.dll
+EXPORTS
+ Haptics DATA
+ ??0mouse_settings@ApplicationData@NovintHFX@@QAE@XZ
+ ?AttachApplication@HapticsSystem@NovintHFX@@QAE_NAAUApplicationData@2@@Z
+ ?RecountConnectedDevices@HapticsSystem@NovintHFX@@QAEXXZ
+ ?ConnectedDeviceCount@HapticsSystem@NovintHFX@@QBEHXZ
+ ?RunDevice@HapticsSystem@NovintHFX@@QAE_NPAPAVDevice@2@H@Z
+ ?StartMouse@HapticsSystem@NovintHFX@@QAEXPAVDevice@2@@Z
+ ?StopRunningDevice@HapticsSystem@NovintHFX@@QAE_NPAPAVDevice@2@@Z
+ ?InputUpdate@HapticsSystem@NovintHFX@@QAEHXZ
+ ?InputUpdate@Device@NovintHFX@@QAEXXZ
+ ?GetButtonData@Device@NovintHFX@@QBEXPAH00@Z
+ ?GetToolPosition@Device@NovintHFX@@QBEXQAN@Z
+ ??0ControlBoxEffectParams@NovintHFX@@QAE@XZ
+ ??1BaseEffectParams@NovintHFX@@UAE@XZ
+ ?CreateNewEffect@Stack@NovintHFX@@QAE_NPBDPAUIHapticEffectParam@@0PAPAVIHapticEffect@@@Z
+ ?CreateStandardEffect@BaseEffectParams@NovintHFX@@UAE_NPAVDevice@2@PBDPAPAVIHapticEffect@@@Z
+ ?CreateStandardEffect@BaseEffectParams@NovintHFX@@UAE_NPAVStack@2@PBDPAPAVIHapticEffect@@@Z
+ ?GetEffectStack@Device@NovintHFX@@QAEPAVStack@2@XZ
+ ?GetStaticInfoClass@ControlBoxEffectParams@NovintHFX@@UAEPAUParamsStaticClass@2@XZ
+ ?GetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDAAH@Z
+ ?GetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDAAM@Z
+ ?GetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDAAN@Z
+ ?GetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDAA_N@Z
+ ?GetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDHAAH@Z
+ ?GetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDHAAM@Z
+ ?GetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDHAAN@Z
+ ?GetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDHAA_N@Z
+ ?GetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDHPAX@Z
+ ?GetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDPAX@Z
+ ?GetVarType@ControlBoxEffectParams@NovintHFX@@UBEDPBDPAH@Z
+ ?RunSetCommand@BaseEffectParams@NovintHFX@@UAE_NPAD@Z
+ ?SetVar@BaseEffectParams@NovintHFX@@UAE_NPBD0@Z
+ ?SetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDH@Z
+ ?SetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDHH@Z
+ ?SetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDHM@Z
+ ?SetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDHN@Z
+ ?SetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDHPAX@Z
+ ?SetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDH_N@Z
+ ?SetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDM@Z
+ ?SetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDN@Z
+ ?SetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBDPAX@Z
+ ?SetVar@ControlBoxEffectParams@NovintHFX@@UAE_NPBD_N@Z
+ ?StandardEffectName@ControlBoxEffectParams@NovintHFX@@UBEPBDXZ
+ ??AVect3@NovintHFX@@QAEAANH@Z
+ ??0Vect3@NovintHFX@@QAE@ABN00@Z
+ ?GetStaticInfoClass@ConstantEffectParams@NovintHFX@@UAEPAUParamsStaticClass@2@XZ
+ ?GetVarType@ConstantEffectParams@NovintHFX@@UBEDPBDPAH@Z
+ ?GetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDAAM@Z
+ ?GetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDAAN@Z
+ ?GetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDAA_N@Z
+ ?GetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDAAH@Z
+ ?GetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDPAX@Z
+ ?GetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDHAAM@Z
+ ?GetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDHAAN@Z
+ ?GetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDHAA_N@Z
+ ?GetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDHAAH@Z
+ ?GetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDHPAX@Z
+ ?SetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDN@Z
+ ?SetVar@ConstantEffectParams@NovintHFX@@UAE_NPBD_N@Z
+ ?SetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDM@Z
+ ?SetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDH@Z
+ ?SetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDPAX@Z
+ ?SetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDHN@Z
+ ?SetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDH_N@Z
+ ?SetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDHM@Z
+ ?SetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDHH@Z
+ ?SetVar@ConstantEffectParams@NovintHFX@@UAE_NPBDHPAX@Z
+ ?StandardEffectName@ConstantEffectParams@NovintHFX@@UBEPBDXZ
+ ??0ConstantEffectParams@NovintHFX@@QAE@XZ
+ ??4Vect3@NovintHFX@@QAEAAU01@ABU01@@Z
+ ?GetStaticInfoClass@EnvelopeEffectParams@NovintHFX@@UAEPAUParamsStaticClass@2@XZ
+ ?GetVarType@EnvelopeEffectParams@NovintHFX@@UBEDPBDPAH@Z
+ ?GetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDAAM@Z
+ ?GetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDAAN@Z
+ ?GetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDAA_N@Z
+ ?GetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDAAH@Z
+ ?GetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDPAX@Z
+ ?GetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDHAAM@Z
+ ?GetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDHAAN@Z
+ ?GetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDHAA_N@Z
+ ?GetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDHAAH@Z
+ ?GetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDHPAX@Z
+ ?SetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDN@Z
+ ?SetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBD_N@Z
+ ?SetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDM@Z
+ ?SetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDH@Z
+ ?SetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDPAX@Z
+ ?SetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDHN@Z
+ ?SetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDH_N@Z
+ ?SetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDHM@Z
+ ?SetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDHH@Z
+ ?SetVar@EnvelopeEffectParams@NovintHFX@@UAE_NPBDHPAX@Z
+ ?StandardEffectName@EnvelopeEffectParams@NovintHFX@@UBEPBDXZ
+ ??0EnvelopeEffectParams@NovintHFX@@QAE@XZ
+ ??DVect3@NovintHFX@@QBE?AU01@ABN@Z
+ ?Normalize@Vect3@NovintHFX@@QBE?AU12@XZ
diff --git a/Code/Archive/NovintFalcon/External/NovintHFX/NovintHFX.h b/Code/Archive/NovintFalcon/External/NovintHFX/NovintHFX.h
new file mode 100644
index 000000000..68c830e48
--- /dev/null
+++ b/Code/Archive/NovintFalcon/External/NovintHFX/NovintHFX.h
@@ -0,0 +1,316 @@
+// [INFERRED] local ABI header; no Novint implementation is reconstructed here.
+// Narrow declarations from BF2.exe's NovintHFX imports and its call-site layouts.
+// See IO/Input/FALCON_DEVICE_STATUS.md. The matching stock DLL supplies all bodies.
+#ifndef EXTERNAL_NOVINTHFX_ABI_H
+#define EXTERNAL_NOVINTHFX_ABI_H
+#include
+#include
+// [CHOSEN, not recovered] Test seam: the Mac fake-SDK check (Code/Tests/falcon_update_runtime.cpp)
+// builds with BF2_NOVINT_FAKE_SDK and supplies every body; product images always import.
+#if defined(BF2_NOVINT_FAKE_SDK)
+#define NOVINTHFX_IMPORT
+#else
+#define NOVINTHFX_IMPORT __declspec(dllimport)
+#endif
+namespace NovintHFX {
+class Stack;
+class Device;
+// Three doubles (24 bytes: BF2.exe 0x4A34BA builds one at ebp-0x54, the next local at ebp-0x3C).
+// Only SDK members touch the components. [UNRESOLVED] member name. A struct:
+// the SDK's own Vect3 imports mangle it U (??4Vect3@NovintHFX@@QAEAAU01@ABU01@@Z).
+struct Vect3 {
+ NOVINTHFX_IMPORT Vect3(const double&, const double&, const double&);
+ NOVINTHFX_IMPORT double& operator[](int);
+ NOVINTHFX_IMPORT Vect3& operator=(const Vect3&);
+ NOVINTHFX_IMPORT Vect3 operator*(const double&) const;
+ NOVINTHFX_IMPORT Vect3 Normalize() const;
+private:
+ double m_unresolved[3];
+};
+}
+class IHapticEffect;
+
+// Effect parameter interface, global namespace (CreateNewEffect's PAUIHapticEffectParam@@).
+// Slot order from BF2.exe's local ControlBoxEffectParams vtable 0x9116E0. MSVC groups overloads
+// of one name at the first one's slot in reverse declaration order, so each group below is
+// declared last slot first.
+struct IHapticEffectParam {
+ virtual bool RunSetCommand(char*) = 0; // +0x00
+ virtual const char* StandardEffectName() const = 0; // +0x04
+ virtual bool SetVar(const char*, double) = 0; // +0x2C
+ virtual bool SetVar(const char*, bool) = 0; // +0x28
+ virtual bool SetVar(const char*, float) = 0; // +0x24
+ virtual bool SetVar(const char*, int) = 0; // +0x20
+ virtual bool SetVar(const char*, void*) = 0; // +0x1C
+ virtual bool SetVar(const char*, int, double) = 0; // +0x18
+ virtual bool SetVar(const char*, int, bool) = 0; // +0x14
+ virtual bool SetVar(const char*, int, float) = 0; // +0x10
+ virtual bool SetVar(const char*, int, int) = 0; // +0x0C
+ virtual bool SetVar(const char*, int, void*) = 0; // +0x08
+ virtual bool GetVar(const char*, float&) = 0; // +0x54
+ virtual bool GetVar(const char*, double&) = 0; // +0x50
+ virtual bool GetVar(const char*, bool&) = 0; // +0x4C
+ virtual bool GetVar(const char*, int&) = 0; // +0x48
+ virtual bool GetVar(const char*, void*) = 0; // +0x44
+ virtual bool GetVar(const char*, int, float&) = 0; // +0x40
+ virtual bool GetVar(const char*, int, double&) = 0; // +0x3C
+ virtual bool GetVar(const char*, int, bool&) = 0; // +0x38
+ virtual bool GetVar(const char*, int, int&) = 0; // +0x34
+ virtual bool GetVar(const char*, int, void*) = 0; // +0x30
+ // +0x58..+0x94: header-inline typed forwarders (BF2.exe 0x5A42D0..0x5A43B0, 0x5D1600,
+ // 0x626BF0, 0x83C790), each a tail call of the slot named. [INFERRED] names: the bodies show
+ // only their targets.
+ virtual bool SetFloatVar(const char* n, float v) { return SetVar(n, v); } // +0x5C -> +0x24
+ virtual bool SetFloatVar(const char* n, int i, float v) { return SetVar(n, i, v); } // +0x58 -> +0x10
+ virtual bool SetDoubleVar(const char* n, double v) { return SetVar(n, v); } // +0x64 -> +0x2C
+ virtual bool SetDoubleVar(const char* n, int i, double v) { return SetVar(n, i, v); } // +0x60 -> +0x18
+ virtual bool SetIntVar(const char* n, int v) { return SetVar(n, v); } // +0x6C -> +0x20
+ virtual bool SetIntVar(const char* n, int i, int v) { return SetVar(n, i, v); } // +0x68 -> +0x0C
+ virtual bool SetBoolVar(const char* n, bool v) { return SetVar(n, v); } // +0x74 -> +0x28
+ virtual bool SetBoolVar(const char* n, int i, bool v) { return SetVar(n, i, v); } // +0x70 -> +0x14
+ virtual bool GetFloatVar(const char* n, float& v) { return GetVar(n, v); } // +0x7C -> +0x54
+ virtual bool GetFloatVar(const char* n, int i, float& v) { return GetVar(n, i, v); } // +0x78 -> +0x40
+ virtual bool GetDoubleVar(const char* n, double& v) { return GetVar(n, v); } // +0x84 -> +0x50
+ virtual bool GetDoubleVar(const char* n, int i, double& v) { return GetVar(n, i, v); } // +0x80 -> +0x3C
+ virtual bool GetIntVar(const char* n, int& v) { return GetVar(n, v); } // +0x8C -> +0x48
+ virtual bool GetIntVar(const char* n, int i, int& v) { return GetVar(n, i, v); } // +0x88 -> +0x34
+ virtual bool GetBoolVar(const char* n, bool& v) { return GetVar(n, v); } // +0x94 -> +0x4C
+ virtual bool GetBoolVar(const char* n, int i, bool& v) { return GetVar(n, i, v); } // +0x90 -> +0x38
+};
+
+// A running effect, owned by the device's effect stack (global namespace, PAPAVIHapticEffect@@).
+// [UNRESOLVED] Only what BF2.exe 0x6A5835/0x6A5995/0x6A599D uses is declared; the haptic-effect
+// sites (ledger N2) name the remaining slots.
+class IHapticEffect {
+public:
+ virtual void unresolvedSlot00() = 0;
+ virtual void unresolvedSlot04() = 0;
+ virtual void unresolvedSlot08() = 0;
+ virtual void unresolvedSlot0C() = 0;
+ virtual void unresolvedSlot10() = 0;
+ virtual void unresolvedSlot14() = 0;
+ virtual void unresolvedSlot18() = 0;
+ virtual void unresolvedSlot1C() = 0;
+ virtual void unresolvedSlot20() = 0;
+ virtual void unresolvedSlot24() = 0;
+ virtual void unresolvedSlot28() = 0;
+ virtual void unresolvedSlot2C() = 0;
+ virtual void unresolvedSlot30() = 0;
+ virtual void unresolvedSlot34() = 0;
+ virtual void unresolvedSlot38() = 0;
+ virtual void unresolvedSlot3C() = 0;
+ virtual void unresolvedSlot40() = 0;
+ virtual bool UpdateParams(IHapticEffectParam*) = 0; // +0x44 [INFERRED] name and result
+ virtual void unresolvedSlot48() = 0;
+ virtual void SetForce(const NovintHFX::Vect3&) = 0; // +0x4C [INFERRED] name and result; 0x4A34C3
+ virtual void unresolvedSlot50() = 0;
+ // +0x54 [INFERRED] name and result: Soldier's CraftPhysics effects pass HapticSettings'
+ // PhysicsSOLDIERSmoothTime* here every tick (0x5AF322), the value also given as params +0x18.
+ virtual void SetSmoothTime(int) = 0;
+ unsigned char m_unresolved04[8];
+ unsigned char m_stateFlags; // +0x0C; bit 0 [INFERRED] suspended, read and written inline
+protected:
+ IHapticEffect(); // DLL-owned; created only by Stack::CreateNewEffect
+};
+
+namespace NovintHFX {
+struct ParamsStaticClass; // [UNRESOLVED] opaque; returned by GetStaticInfoClass
+
+// Shared effect-parameter base. Its own virtuals follow the interface's (+0x98..+0xAC).
+class BaseEffectParams : public IHapticEffectParam {
+public:
+ NOVINTHFX_IMPORT bool RunSetCommand(char*) override;
+ NOVINTHFX_IMPORT virtual ~BaseEffectParams(); // +0x98
+ NOVINTHFX_IMPORT virtual bool SetVar(const char*, const char*); // +0x9C
+ using IHapticEffectParam::SetVar;
+ virtual char GetVarType(const char*, int*) const = 0; // +0xA0
+ virtual ParamsStaticClass* GetStaticInfoClass() = 0; // +0xA4
+ NOVINTHFX_IMPORT virtual bool CreateStandardEffect(Device*, const char*, IHapticEffect**); // +0xAC
+ NOVINTHFX_IMPORT virtual bool CreateStandardEffect(Stack*, const char*, IHapticEffect**); // +0xA8
+protected:
+ BaseEffectParams(); // reached only through the derived SDK constructors
+private:
+ alignas(4) unsigned char m_baseState[20]; // +0x04 [UNRESOLVED] SDK-owned
+};
+
+class ConstantEffectParams : public BaseEffectParams {
+public:
+ // [INFERRED] throw(): BF2.exe's new-expression at 0x5A416E has no unwind state around the
+ // constructor call, so the compiler treated the construction as non-throwing.
+ NOVINTHFX_IMPORT ConstantEffectParams() throw();
+ NOVINTHFX_IMPORT const char* StandardEffectName() const override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, double) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, bool) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, float) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, void*) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, double) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, bool) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, float) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, int) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, void*) override;
+ using BaseEffectParams::SetVar;
+ NOVINTHFX_IMPORT bool GetVar(const char*, float&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, double&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, bool&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, void*) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, float&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, double&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, bool&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, int&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, void*) override;
+ NOVINTHFX_IMPORT char GetVarType(const char*, int*) const override;
+ NOVINTHFX_IMPORT ParamsStaticClass* GetStaticInfoClass() override;
+ int m_unresolved18; // +0x18 [UNRESOLVED] meaning; BF2.exe 0x5A418F writes 0x14 for "ShakeForce"
+ int m_unresolved1C; // +0x1C [UNRESOLVED]
+};
+
+class EnvelopeEffectParams : public BaseEffectParams {
+public:
+ // [INFERRED] throw(): BF2.exe's new-expression at 0x5E65B4 has no unwind state around the
+ // constructor call, so the compiler treated the construction as non-throwing.
+ NOVINTHFX_IMPORT EnvelopeEffectParams() throw();
+ NOVINTHFX_IMPORT const char* StandardEffectName() const override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, double) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, bool) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, float) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, void*) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, double) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, bool) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, float) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, int) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, void*) override;
+ using BaseEffectParams::SetVar;
+ NOVINTHFX_IMPORT bool GetVar(const char*, float&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, double&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, bool&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, void*) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, float&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, double&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, bool&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, int&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, void*) override;
+ NOVINTHFX_IMPORT char GetVarType(const char*, int*) const override;
+ NOVINTHFX_IMPORT ParamsStaticClass* GetStaticInfoClass() override;
+ int m_unresolved18; // +0x18 [UNRESOLVED] meaning; BF2.exe 0x5E65C4 writes 0x64 for "Damage"
+ alignas(4) unsigned char m_unresolved1C[12]; // +0x1C [UNRESOLVED]
+ double m_force[3]; // +0x28 [INFERRED] name; BF2.exe 0x5E665C..0x5E667A write the scaled direction
+};
+
+// The control box BF2 builds in FalconDevice::updateCurrentState (BF2.exe 0x6A587F): 0x120
+// bytes, SDK constructor, every virtual imported except the interface's inline forwarders.
+class ControlBoxEffectParams : public BaseEffectParams {
+public:
+ // [INFERRED] throw(): BF2.exe's new-expression at 0x6A587F has no unwind state around the
+ // constructor call, so the compiler treated the construction as non-throwing.
+ NOVINTHFX_IMPORT ControlBoxEffectParams() throw();
+ NOVINTHFX_IMPORT const char* StandardEffectName() const override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, double) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, bool) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, float) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, void*) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, double) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, bool) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, float) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, int) override;
+ NOVINTHFX_IMPORT bool SetVar(const char*, int, void*) override;
+ using BaseEffectParams::SetVar;
+ NOVINTHFX_IMPORT bool GetVar(const char*, float&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, double&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, bool&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, void*) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, float&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, double&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, bool&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, int&) override;
+ NOVINTHFX_IMPORT bool GetVar(const char*, int, void*) override;
+ NOVINTHFX_IMPORT char GetVarType(const char*, int*) const override;
+ NOVINTHFX_IMPORT ParamsStaticClass* GetStaticInfoClass() override;
+ // Written inline by BF2.exe 0x6A58E4..0x6A593E. [INFERRED] names: the lower and upper box
+ // walls and the spring stiffness on each side, per axis.
+ double m_lower[3]; // +0x18
+ double m_upper[3]; // +0x30
+ double m_unresolved48[6]; // +0x48 [UNRESOLVED]
+ double m_lowerStiffness[3]; // +0x78
+ double m_upperStiffness[3]; // +0x90
+ alignas(4) unsigned char m_unresolvedA8[0x6C]; // +0xA8 [UNRESOLVED]
+ int m_unresolved114; // +0x114; BF2 writes 3000 (ds:0x979010) [UNRESOLVED] meaning
+ alignas(4) unsigned char m_unresolved118[8]; // +0x118 [UNRESOLVED]
+};
+}
+
+namespace NovintHFX {
+struct ApplicationData {
+ struct mouse_settings {
+ NOVINTHFX_IMPORT mouse_settings();
+ private:
+ // Opaque SDK state, 28-byte stack extent at BF2.exe 0x6A4EF0.
+ // Its own SDK constructor owns every field; no fabricated initialization.
+ alignas(4) unsigned char m_sdkState[28];
+ };
+ HWND window; // [INFERRED] name; HWND at byte 0, 0x6A4F23.
+ mouse_settings mouse;
+};
+class Stack {
+public:
+ NOVINTHFX_IMPORT bool CreateNewEffect(const char*, IHapticEffectParam*, const char*, IHapticEffect**);
+#if defined(BF2_NOVINT_FAKE_SDK)
+public: // [CHOSEN, not recovered] test seam: the fake SDK owns its instances
+#else
+private:
+#endif
+ Stack(); // Opaque DLL-owned instance.
+};
+class Device {
+public:
+ NOVINTHFX_IMPORT void InputUpdate();
+ NOVINTHFX_IMPORT void GetButtonData(int*, int*, int*) const;
+ NOVINTHFX_IMPORT void GetToolPosition(double* const) const;
+ NOVINTHFX_IMPORT Stack* GetEffectStack();
+#if defined(BF2_NOVINT_FAKE_SDK)
+public: // [CHOSEN, not recovered] test seam: the fake SDK owns its instances
+#else
+private:
+#endif
+ Device(); // Opaque DLL-owned instance; never allocate from this declaration.
+};
+class HapticsSystem {
+public:
+ NOVINTHFX_IMPORT bool AttachApplication(ApplicationData&);
+ NOVINTHFX_IMPORT void RecountConnectedDevices();
+ NOVINTHFX_IMPORT int ConnectedDeviceCount() const;
+ NOVINTHFX_IMPORT bool RunDevice(Device**, int);
+ NOVINTHFX_IMPORT void StartMouse(Device*);
+ NOVINTHFX_IMPORT bool StopRunningDevice(Device**);
+ NOVINTHFX_IMPORT int InputUpdate();
+#if defined(BF2_NOVINT_FAKE_SDK)
+public: // [CHOSEN, not recovered] test seam: the fake SDK defines Haptics
+#else
+private:
+#endif
+ HapticsSystem(); // Opaque DLL-owned instance; never allocate or copy.
+};
+}
+// PE IAT 0x87F788: a single IAT load supplies this, i.e. the exported object's
+// address. This is neither a pointer variable nor a callable Haptics() function.
+extern "C" NOVINTHFX_IMPORT NovintHFX::HapticsSystem Haptics;
+static_assert(sizeof(NovintHFX::ApplicationData::mouse_settings) == 28, "SDK ABI");
+#if defined(_M_IX86)
+static_assert(sizeof(NovintHFX::ApplicationData) == 32, "x86 SDK ABI");
+static_assert(sizeof(NovintHFX::ControlBoxEffectParams) == 0x120, "BF2.exe 0x6A587F allocation");
+static_assert(offsetof(NovintHFX::ControlBoxEffectParams, m_lower) == 0x18, "x86 SDK ABI");
+static_assert(offsetof(NovintHFX::ControlBoxEffectParams, m_upper) == 0x30, "x86 SDK ABI");
+static_assert(offsetof(NovintHFX::ControlBoxEffectParams, m_lowerStiffness) == 0x78, "x86 SDK ABI");
+static_assert(offsetof(NovintHFX::ControlBoxEffectParams, m_upperStiffness) == 0x90, "x86 SDK ABI");
+static_assert(offsetof(NovintHFX::ControlBoxEffectParams, m_unresolved114) == 0x114, "x86 SDK ABI");
+static_assert(offsetof(IHapticEffect, m_stateFlags) == 0x0C, "x86 SDK ABI");
+static_assert(sizeof(NovintHFX::Vect3) == 24, "BF2.exe 0x4A34BA stack extent");
+#endif
+// [CHOSEN, not recovered] x64 (https://github.com/B2BF/OpenBF2/issues/7): the SDK exists only as a
+// 32-bit DLL, so an x64 image imports nothing from it; FalconDevice reports no device there.
+#endif
diff --git a/Code/Archive/NovintFalcon/Game/Objects/Game/SoldierHapticForces.cpp b/Code/Archive/NovintFalcon/Game/Objects/Game/SoldierHapticForces.cpp
new file mode 100644
index 000000000..d134afb2b
--- /dev/null
+++ b/Code/Archive/NovintFalcon/Game/Objects/Game/SoldierHapticForces.cpp
@@ -0,0 +1,80 @@
+// [CHOSEN, not recovered] Archived with the Novint Falcon (see README.md): the force inputs the Soldier
+// and PlayerControlObject fed to the Falcon effects (ledger N2 17b). They were part of
+// Game/Objects/Game/SoldierHapticProfile.cpp; the control-box profile switch stays there.
+#include "SoldierHapticForces.h"
+#if !DEDICATED
+#include "../GenericFireArmTemplate.h"
+#include "../Weapons/GenericFireArm.h"
+#include "../../../IO/Input/FalconHaptics.h"
+#include "../IObject.h"
+#include "../IPlayer.h"
+#include "../../../Math/Mat4.h"
+#include "../../../Physics/IPhysicsNode.h"
+#include "../ICameraObject.h"
+
+namespace dice { namespace hfe { namespace world {
+
+int HapticWeaponAccess::weaponType(IObject* weapon)
+{
+ return static_cast(weapon)->m_template->m_weaponType;
+}
+
+void updateSoldierRecoilForce(IPlayer* occupant, IPlayer* localPlayer, float yawDelta, float pitchRecoil,
+ IObject* weapon)
+{
+ if (!occupant || occupant != localPlayer)
+ return;
+ int weaponType = -1;
+ if (yawDelta != 0.0f || pitchRecoil != 0.0f)
+ weaponType = HapticWeaponAccess::weaponType(weapon);
+ io::updateRecoilForce(yawDelta, pitchRecoil, weaponType);
+}
+
+void updateSoldierCraftPhysics(IPlayer* occupant, IPlayer* localPlayer, IPlayer* player, const Vec3& velocity,
+ float dt)
+{
+ if (!occupant || occupant != localPlayer)
+ return;
+ const Mat4 inverse = player->getVehicle()->getInvAbsoluteTransformation(); // copied, as shipped
+ // 0x5A1710: v * M, accumulated on the x87 stack in this order.
+ const double vx = velocity.x, vy = velocity.y, vz = velocity.z;
+ Vec3 local;
+ local.x = static_cast(inverse.m[8] * vz + inverse.m[4] * vy + vx * inverse.m[0]);
+ local.y = static_cast(inverse.m[1] * vx + inverse.m[9] * vz + inverse.m[5] * vy);
+ local.z = static_cast(inverse.m[2] * vx + inverse.m[10] * vz + inverse.m[6] * vy);
+ io::updateSoldierCraftPhysicsForce(local, dt);
+}
+
+namespace {
+int s_hapticFrameMode = 3; // ds:0x974BF8, initialized 3; nothing writes it
+// 0x5A1710: v * M, accumulated on the x87 stack in this order.
+Vec3 rotateIntoFrame(const Vec3& v, const Mat4& m)
+{
+ const double vx = v.x, vy = v.y, vz = v.z;
+ Vec3 out;
+ out.x = static_cast(m.m[8] * vz + m.m[4] * vy + vx * m.m[0]);
+ out.y = static_cast(m.m[1] * vx + m.m[9] * vz + m.m[5] * vy);
+ out.z = static_cast(m.m[2] * vx + m.m[10] * vz + m.m[6] * vy);
+ return out;
+}
+} // namespace
+
+void updateVehicleCraftPhysics(IPhysicsNode* physics, IObject* vehicle, ICameraObject* camera, float dt,
+ int vehicleCategory)
+{
+ physics->getPositionalAcceleration(); // +0xA8 PE, dropped
+ Mat4 frame = Mat4::getIdentity();
+ switch (s_hapticFrameMode) { // the jump table at 0x5FBE28
+ case 0: frame = vehicle->getRelativeTransformation(); break;
+ case 1: frame = vehicle->getAbsoluteTransformation(); break;
+ case 2: frame = camera->getTransformation(0.0f); break;
+ case 3: frame = vehicle->getInvAbsoluteTransformation(); break;
+ case 4: frame = vehicle->getVisualAbsoluteTransformation(); break;
+ case 5: frame.setInverse(camera->getTransformation(0.0f)); break;
+ default: break;
+ }
+ io::updateVehicleCraftPhysicsForce(rotateIntoFrame(physics->getPositionalSpeed(), frame), dt, vehicleCategory);
+}
+
+} } }
+#endif
diff --git a/Code/Archive/NovintFalcon/Game/Objects/Game/SoldierHapticForces.h b/Code/Archive/NovintFalcon/Game/Objects/Game/SoldierHapticForces.h
new file mode 100644
index 000000000..2929eb5e3
--- /dev/null
+++ b/Code/Archive/NovintFalcon/Game/Objects/Game/SoldierHapticForces.h
@@ -0,0 +1,50 @@
+// [CHOSEN, not recovered] Archived with the Novint Falcon (see README.md): the force inputs that were
+// declared in Game/Objects/Game/SoldierHapticProfile.h (ledger N2 17b). GenericFireArm declared
+// `friend struct HapticWeaponAccess;` for weaponType.
+#ifndef GAME_OBJECTS_GAME_SOLDIERHAPTICFORCES_H
+#define GAME_OBJECTS_GAME_SOLDIERHAPTICFORCES_H
+#include "../../../Core/BuildConfig.h"
+#if !DEDICATED
+#include "../../../Math/Vec3.h"
+namespace dice { namespace hfe { namespace world {
+class IPlayer;
+class IObject;
+class GenericFireArmTemplate;
+class ICameraObject;
+class IPhysicsNode;
+
+// Friend of GenericFireArm. weaponType is SoldierHapticProfile.cpp's read (0x5E0AC0); setTemplate is
+// defined only by the check.
+struct HapticWeaponAccess {
+ static int weaponType(IObject* weapon);
+ static void setTemplate(IObject* weapon, const GenericFireArmTemplate* weaponTemplate);
+};
+
+// Soldier::handlePlayerInput's "Recoil" decision (0x5AE352..0x5AE463, ledger N2 17b), with a device
+// connected: only for the local occupant; the weapon's type (0x5E0AC0: the firearm's template
+// weaponType, [INFERRED]) is read only when the yaw delta or the raw pitch recoil is non-zero, and
+// the weapon is not checked, as shipped; then io::updateRecoilForce. [CHOSEN, not recovered] The
+// caller looks up the weapon and the local player up front (both lookups have no effects).
+void updateSoldierRecoilForce(IPlayer* occupant, IPlayer* localPlayer, float yawDelta, float pitchRecoil,
+ IObject* weapon);
+
+// Soldier::handlePlayerInput's "CraftPhysics" input (0x5AECF5..0x5AED72, ledger N2 17b), with a device
+// connected: only for the local occupant; the physics node's linear integration velocity rotated into
+// the frame of the controlling player's vehicle (v * getInvAbsoluteTransformation(), 0x5A1710), then
+// io::updateSoldierCraftPhysicsForce. [CHOSEN, not recovered] The caller reads the velocity up front.
+void updateSoldierCraftPhysics(IPlayer* occupant, IPlayer* localPlayer, IPlayer* player, const Vec3& velocity,
+ float dt);
+
+// PlayerControlObject::handleUpdate's "CraftPhysics" input (0x5FAC8C..0x5FADAE, ledger N2 17b), for the
+// local occupant with a device and a root physics node: the node's positional acceleration is read and
+// dropped, as shipped; the positional speed is rotated (0x5A1710) into the frame chosen by ds:0x974BF8
+// (initialized 3 and never written: 0 the vehicle's relative, 1 absolute, 3 inverse absolute,
+// 4 visual absolute transformation, 2 the camera's getTransformation(0), 5 its orthonormal inverse);
+// then io::updateVehicleCraftPhysicsForce with the vehicle category. [CHOSEN, not recovered] The caller
+// reads the vehicle, the camera and the category up front (all without effects).
+void updateVehicleCraftPhysics(IPhysicsNode* physics, IObject* vehicle, ICameraObject* camera, float dt,
+ int vehicleCategory);
+
+} } }
+#endif
+#endif
diff --git a/Code/Archive/NovintFalcon/IO/Input/FalconDevice.cpp b/Code/Archive/NovintFalcon/IO/Input/FalconDevice.cpp
new file mode 100644
index 000000000..796cda966
--- /dev/null
+++ b/Code/Archive/NovintFalcon/IO/Input/FalconDevice.cpp
@@ -0,0 +1,877 @@
+// Path [INFERRED]. Client PE recovery; symbolized ELF supplies names/signatures.
+// [PLATFORM] ELF has no Novint imports and compiled-out init/update/device calls.
+// BF2_NOVINT_FAKE_SDK builds the Windows body against the Mac check's fake SDK.
+#include "FalconDevice.h"
+#if !DEDICATED && !defined(_WIN32) && !defined(BF2_NOVINT_FAKE_SDK)
+namespace dice { namespace hfe { namespace io {
+// [CHOSEN, not recovered] Native POSIX clients have no Falcon (see FalconDevice.h); the menu's
+// mouse-mode global and the control-box flag keep their shipped initial values.
+int g_falconMouseMode = 1; // PE978FC4
+bool g_falconControlBoxDirty = true; // PE978FC8
+// [CHOSEN, not recovered] No Falcon effect is ever created here, so every target stays null and
+// MainMenuLogic's zeroing finds nothing to call.
+void zeroHapticForceTargets() {}
+void updateShakeForce(world::IPlayerControlObject*, float, float, float, float) {}
+bool hapticDeviceConnected() { return false; }
+void updateRecoilForce(float, float, int) {}
+void updateSoldierCraftPhysicsForce(const Vec3&, float) {}
+void updateVehicleCraftPhysicsForce(const Vec3&, float, int) {}
+void soldierRecoilPunch(int, bool, unsigned int, const float*, float, float, float, float) {}
+void fireRecoilPunch(float, float, float) {}
+void weaponRecoilPunch(int, const std::string&, float, float, float) {}
+void kitRecoilPunch(int, const std::string&, float) {}
+void updateDamageForce(world::IPlayer*, world::IPlayer*, const Mat4&, const Mat4&, float) {}
+}
+IHapticEffect* g_hapticForceTargets[6] = { 0, 0, 0, 0, 0, 0 }; // ds:0x9EBEC8.. (BF2ClientSeams.h)
+} }
+#elif !DEDICATED
+#include "../../Core/Ids.h"
+#include "../../Game/ControlSettings.h"
+#include "../../Game/HapticSettings.h"
+#include "../../Platform/X87Compat.h"
+#include "../../Math/Vec3.h"
+#include "../../Game/Objects/IObject.h"
+#include "../../Game/Objects/IObjectTemplate.h"
+#include "../../Scene/Object/ObjectTypes/Game/IPlayerControlObject.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+// [CHOSEN, not recovered] x64 (https://github.com/B2BF/OpenBF2/issues/7): NovintHFX ships only as a
+// 32-bit DLL. The x64 image never calls it: init() reports the device absent through the same
+// `false` retail returns with no device connected, so m_device stays null and every device path
+// below returns at its existing null test. No SDK symbol is referenced there: the frame update and the
+// force zeroing compile to their no-device bodies.
+#if defined(_M_IX86) || defined(BF2_NOVINT_FAKE_SDK)
+#define BF2_FALCON_SDK 1
+#else
+#define BF2_FALCON_SDK 0
+#endif
+namespace dice { namespace hfe {
+IHapticEffect* g_hapticForceTargets[6] = { 0, 0, 0, 0, 0, 0 }; // ds:0x9EBEC8.. (BF2ClientSeams.h)
+extern IBase* g_controlSettings; // ds:0x98738C, Game/Main/BF2ClientSeams.h
+extern IBase* g_hapticSettings; // ds:0x987394, Game/Main/BF2ClientSeams.h
+namespace io {
+extern IBase* inputDeviceManager; // PE 0x9FFCB0, singleton registration 0x698542
+extern IBase* controlMapManager; // PE 0x9FFCB4, Core/Globals.cpp
+extern float inputSampleLatency; // PE 0xA07E4C, IO/Input/InputManager.cpp
+NovintHFX::Device* g_falconDevice = 0;
+int g_falconMouseMode = 1; // PE978FC4
+bool g_falconControlBoxDirty = true; // PE978FC8
+#if BF2_FALCON_SDK
+namespace {
+// Initialized data read only by updateCurrentState. [INFERRED] names.
+double s_falconMouseGain = 1000.0; // ds:0x979018: mouse-mode position gain
+short s_controlBoxForceValue = 3000; // ds:0x979010: control box +0x114 [UNRESOLVED] meaning
+int s_smoothingWindow = 3; // ds:0x979020: samples between the delta's two ends
+int s_smoothingCount = 0; // ds:0xA03948: samples queued in each delta history
+IHapticEffect* s_controlBoxEffect = 0; // ds:0xA03944: created once, then updated in place
+
+// BF2.exe 0x6A589B..0x6A58A1 calls the imported ControlBoxEffectParams constructor and then stores
+// its own vtable (0x9116E0), whose deleting destructor (0x5E2EA0) calls ~BaseEffectParams directly:
+// the object is a BF2-side class derived from the SDK type with implicit members only.
+// [INFERRED] name.
+class FalconControlBoxParams : public NovintHFX::ControlBoxEffectParams {};
+
+// Retail re-stores its own vtable after the SDK constructor: BF2.exe 0x5A4174 stores 0x8E7698,
+// and 0x5E65BA stores 0x8ED440. As above, these BF2-side derived classes have implicit members only.
+// [INFERRED] names.
+class FalconConstantParams : public NovintHFX::ConstantEffectParams {};
+class FalconEnvelopeParams : public NovintHFX::EnvelopeEffectParams {};
+
+// Retail indexes the returned Vec3 as a float array ([eax + 4*esi]).
+float component(const Vec3& v, int axis)
+{
+ return axis == 0 ? v.x : axis == 1 ? v.y : v.z;
+}
+// The three position histories are function-local statics in retail (guards ds:0xA03988, bits
+// 1/2/4; atexit 0x87A040/0x87A030/0x87A020). Dinkumware's pop_front ignores an empty deque.
+void popFrontIfAny(std::deque& history)
+{
+ if (!history.empty()) history.pop_front();
+}
+// One smoothing step at a full window: push, drop the oldest, and return the slope across it.
+double windowDelta(std::deque& history, double value)
+{
+ history.push_back(value);
+ popFrontIfAny(history);
+ return (history.back() - history.front()) / static_cast(s_smoothingWindow * 2);
+}
+// Outside the dead zone the offset past its edge drives the axis at `scale`; inside it, the
+// smoothed delta drives it at `deltaScale`. Each settings read is a fresh call, as in retail.
+double axisValue(IHapticSettings* haptics, int axis, double position, double delta,
+ double scale, double deltaScale)
+{
+ if (component(haptics->getAimSensitivityLength(), axis) < position)
+ return (position - component(haptics->getAimSensitivityLength(), axis))
+ * component(haptics->getTurnSensitivity(), axis) * scale;
+ if (-component(haptics->getAimSensitivityLength(), axis) > position)
+ return (component(haptics->getAimSensitivityLength(), axis) + position)
+ * component(haptics->getTurnSensitivity(), axis) * scale;
+ return delta * deltaScale;
+}
+} // namespace
+#endif // BF2_FALCON_SDK: the frame update's state and helpers
+
+void zeroHapticForceTargets()
+{
+#if !BF2_FALCON_SDK
+ // x64: no Falcon effect is ever created, so every target is null.
+#else
+ const double x = 0.0, y = 0.0, z = 0.0;
+ NovintHFX::Vect3 zero(x, y, z);
+ static const int retailOrder[6] = { 2, 3, 4, 5, 0, 1 }; // 0x9EBF00..0x9EBF0C, then 0x9EBEC8/CC
+ for (int i = 0; i < 6; ++i) {
+ IHapticEffect* target = g_hapticForceTargets[retailOrder[i]];
+ if (target) target->SetForce(zero);
+ }
+#endif
+}
+
+#if BF2_FALCON_SDK
+namespace {
+// BF2.exe 0x5A2790: the sign of a double, 0 for 0 and NaN.
+double hapticSign(double value)
+{
+ if (value > 0.0) return 1.0;
+ if (value < 0.0) return -1.0;
+ return 0.0;
+}
+// BF2.exe 0x5A6280: the same for a float.
+float hapticSignF(float value)
+{
+ if (value > 0.0f) return 1.0f;
+ if (value < 0.0f) return -1.0f;
+ return 0.0f;
+}
+} // namespace
+#endif
+
+void updateShakeForce(world::IPlayerControlObject* pco, float explosionRoll, float speedRoll,
+ float closeVehiclePitch, float recoilY)
+{
+#if !BF2_FALCON_SDK
+ (void) pco; (void) explosionRoll; (void) speedRoll; (void) closeVehiclePitch; (void) recoilY;
+#else
+ if (!g_falconDevice)
+ return;
+ IHapticEffect*& vehicleShake = g_hapticForceTargets[0]; // ds:0x9EBEC8
+ IHapticEffect*& soldierShake = g_hapticForceTargets[1]; // ds:0x9EBECC
+ if (vehicleShake && soldierShake) {
+ IHapticSettings* haptics = static_cast(g_hapticSettings);
+ float x = haptics->getExplosionShakeScale() * explosionRoll;
+ x = haptics->getSpeedShakeScale() * speedRoll + x;
+ x = haptics->getGeneralShakeScale() * closeVehiclePitch + x;
+ x = haptics->getUnresolved48C() * recoilY + x;
+ float shared = haptics->getExplosionShakeScale() * explosionRoll;
+ shared = haptics->getSpeedShakeScale() * speedRoll + shared;
+ shared = haptics->getGeneralShakeScale() * closeVehiclePitch + shared;
+ // Retail keeps this product on the x87 stack and stores the sum straight to a double; the
+ // product of two floats is exact in double.
+ const double y = static_cast(haptics->getUnresolved490()) * recoilY + shared;
+ const double xd = x, z = 0.0;
+ NovintHFX::Vect3 force(xd, y, z);
+ const float absX = static_cast(std::fabs(force[0]));
+ if (haptics->getForceCapX() < absX)
+ force[0] = hapticSign(force[0]) * haptics->getForceCapX();
+ const float absY = static_cast(std::fabs(force[1]));
+ if (haptics->getForceCapY() < absY)
+ force[1] = hapticSign(force[1]) * haptics->getForceCapY();
+ world::IObject* const occupied = static_cast(pco->queryInterface(world::IID_IObject));
+ const bool soldier = occupied->getTemplate()->getClassID() == world::CID_SoldierTemplate;
+ (soldier ? soldierShake : vehicleShake)->SetForce(force);
+ return;
+ }
+ FalconConstantParams* params = new FalconConstantParams;
+ params->m_unresolved18 = 0x14;
+ g_falconDevice->GetEffectStack()->CreateNewEffect("CONSTANT", params, "ShakeForce", &vehicleShake);
+ g_falconDevice->GetEffectStack()->CreateNewEffect("CONSTANT", params, "ShakeForce", &soldierShake);
+ delete params;
+#endif
+}
+
+bool hapticDeviceConnected()
+{
+#if !BF2_FALCON_SDK
+ return false;
+#else
+ return g_falconDevice != 0;
+#endif
+}
+
+void updateRecoilForce(float yawDelta, float pitchRecoil, int weaponType)
+{
+#if !BF2_FALCON_SDK
+ (void) yawDelta; (void) pitchRecoil; (void) weaponType;
+#else
+ IHapticEffect*& recoil = g_hapticForceTargets[2]; // ds:0x9EBF00
+ if (!recoil) {
+ FalconConstantParams* params = new FalconConstantParams;
+ params->m_unresolved18 = 10;
+ g_falconDevice->GetEffectStack()->CreateNewEffect("Constant", params, "Recoil", &recoil);
+ delete params;
+ }
+ const double x0 = 0.0, y0 = 0.0, z0 = 0.0;
+ NovintHFX::Vect3 force(x0, y0, z0);
+ if (yawDelta != 0.0f || pitchRecoil != 0.0f) {
+ IHapticSettings* haptics = static_cast(g_hapticSettings);
+ float yawScale, pitchScale;
+ switch (weaponType) { // the jump table at 0x5AF5DC
+ case 0: yawScale = haptics->getRecoilYawScaleRIFLE(); pitchScale = haptics->getRecoilPitchScaleRIFLE(); break;
+ case 1: yawScale = haptics->getRecoilYawScaleRIFLELAUNCHER(); pitchScale = haptics->getRecoilPitchScaleRIFLELAUNCHER(); break;
+ case 2: yawScale = haptics->getRecoilYawScaleCARBINE(); pitchScale = haptics->getRecoilPitchScaleCARBINE(); break;
+ case 3: yawScale = haptics->getRecoilYawScaleLMG(); pitchScale = haptics->getRecoilPitchScaleLMG(); break;
+ case 4: yawScale = haptics->getRecoilYawScaleSNIPER(); pitchScale = haptics->getRecoilPitchScaleSNIPER(); break;
+ case 5: yawScale = haptics->getRecoilYawScalePISTOL(); pitchScale = haptics->getRecoilPitchScalePISTOL(); break;
+ case 6: yawScale = haptics->getRecoilYawScaleLAUNCHER(); pitchScale = haptics->getRecoilPitchScaleLAUNCHER(); break;
+ case 7: yawScale = haptics->getRecoilYawScaleSMG(); pitchScale = haptics->getRecoilPitchScaleSMG(); break;
+ case 8: yawScale = haptics->getRecoilYawScaleSHOTGUN(); pitchScale = haptics->getRecoilPitchScaleSHOTGUN(); break;
+ case 9: yawScale = haptics->getRecoilYawScaleKNIFE(); pitchScale = haptics->getRecoilPitchScaleKNIFE(); break;
+ case 10: yawScale = haptics->getRecoilYawScaleDROP(); pitchScale = haptics->getRecoilPitchScaleDROP(); break;
+ case 11: yawScale = haptics->getRecoilYawScaleTHROWN(); pitchScale = haptics->getRecoilPitchScaleTHROWN(); break;
+ case 12: yawScale = haptics->getRecoilYawScaleDEFIB(); pitchScale = haptics->getRecoilPitchScaleDEFIB(); break;
+ default: yawScale = 0.0f; pitchScale = 0.0f; break;
+ }
+ float x = yawDelta;
+ if (haptics->getForceCapX() < static_cast(std::fabs(yawDelta)))
+ x = hapticSignF(yawDelta) * haptics->getForceCapX();
+ float y = pitchRecoil;
+ if (haptics->getForceCapY() < static_cast(std::fabs(pitchRecoil)))
+ y = hapticSignF(pitchRecoil) * haptics->getForceCapY();
+ // Retail multiplies on the x87 stack and stores doubles; float products are exact in double.
+ const double fx = static_cast(yawScale) * x;
+ const double fy = -(static_cast(pitchScale) * y);
+ force = NovintHFX::Vect3(fx, fy, z0);
+ }
+ recoil->SetForce(force);
+#endif
+}
+
+#if BF2_FALCON_SDK
+namespace {
+// One CraftPhysics effect: created once with params +0x18 = its smooth time.
+void createCraftPhysicsEffect(IHapticEffect*& effect, const char* name, int smoothTime)
+{
+ if (effect)
+ return;
+ FalconConstantParams* params = new FalconConstantParams;
+ params->m_unresolved18 = smoothTime;
+ g_falconDevice->GetEffectStack()->CreateNewEffect("Constant", params, name, &effect);
+ delete params;
+}
+// An acceleration component capped by the force cap with its sign (0x5AF229..0x5AF2D4).
+float capCraftPhysics(float value, float cap, IHapticSettings* haptics, float (IHapticSettings::*getCap)())
+{
+ if (cap < static_cast(std::fabs(value)))
+ return hapticSignF(value) * (haptics->*getCap)();
+ return value;
+}
+} // namespace
+#endif
+
+#if BF2_FALCON_SDK
+namespace {
+// One HapticSettings physics block (SOLDIER, LAND, SEA, AIR, HELI share the layout, 0xC8 apart).
+struct CraftPhysicsProfile {
+ Vec3 (IHapticSettings::*scale)();
+ float (IHapticSettings::*x[3])(); // Low, Med, High
+ float (IHapticSettings::*y[3])();
+ float (IHapticSettings::*z[3])();
+ float (IHapticSettings::*transitionMed)();
+ float (IHapticSettings::*transitionHigh)();
+ int (IHapticSettings::*smoothX[3])();
+ int (IHapticSettings::*smoothY[3])();
+ int (IHapticSettings::*smoothZ[3])();
+};
+#define BF2_CRAFT_PROFILE(C) { &IHapticSettings::getPhysics##C##Scale, \
+ { &IHapticSettings::getPhysics##C##ScaleXLow, &IHapticSettings::getPhysics##C##ScaleXMed, &IHapticSettings::getPhysics##C##ScaleXHigh }, \
+ { &IHapticSettings::getPhysics##C##ScaleYLow, &IHapticSettings::getPhysics##C##ScaleYMed, &IHapticSettings::getPhysics##C##ScaleYHigh }, \
+ { &IHapticSettings::getPhysics##C##ScaleZLow, &IHapticSettings::getPhysics##C##ScaleZMed, &IHapticSettings::getPhysics##C##ScaleZHigh }, \
+ &IHapticSettings::getPhysics##C##TransitionValueMed, &IHapticSettings::getPhysics##C##TransitionValueHigh, \
+ { &IHapticSettings::getPhysics##C##SmoothTimeXLow, &IHapticSettings::getPhysics##C##SmoothTimeXMed, &IHapticSettings::getPhysics##C##SmoothTimeXHigh }, \
+ { &IHapticSettings::getPhysics##C##SmoothTimeYLow, &IHapticSettings::getPhysics##C##SmoothTimeYMed, &IHapticSettings::getPhysics##C##SmoothTimeYHigh }, \
+ { &IHapticSettings::getPhysics##C##SmoothTimeZLow, &IHapticSettings::getPhysics##C##SmoothTimeZMed, &IHapticSettings::getPhysics##C##SmoothTimeZHigh } }
+const CraftPhysicsProfile kSoldierProfile = BF2_CRAFT_PROFILE(SOLDIER);
+const CraftPhysicsProfile kLandProfile = BF2_CRAFT_PROFILE(LAND);
+const CraftPhysicsProfile kSeaProfile = BF2_CRAFT_PROFILE(SEA);
+const CraftPhysicsProfile kAirProfile = BF2_CRAFT_PROFILE(AIR);
+const CraftPhysicsProfile kHeliProfile = BF2_CRAFT_PROFILE(HELI);
+#undef BF2_CRAFT_PROFILE
+
+// The CraftPhysics core shared by Soldier::handlePlayerInput (0x5AED77..0x5AF3F6) and
+// PlayerControlObject::handleUpdate (0x5FADAE..0x5FBCD8). The soldier's block takes the Low smooth
+// times in every band; the vehicle's takes the band's own.
+void craftPhysicsForce(std::vector& velocities, std::vector& tickTimes, const Vec3& localVelocity,
+ float dt, const CraftPhysicsProfile& profile, bool smoothTimesByBand)
+{
+ Vec3 acceleration;
+ acceleration.x = acceleration.y = acceleration.z = 0.0f;
+ if (velocities.size() < 3) {
+ velocities.push_back(localVelocity);
+ tickTimes.push_back(dt);
+ } else {
+ velocities.erase(velocities.begin());
+ velocities.push_back(localVelocity);
+ tickTimes.erase(tickTimes.begin());
+ tickTimes.push_back(dt);
+ const float span = tickTimes[1] + tickTimes[2];
+ const Vec3& oldest = velocities.front();
+ const Vec3& newest = velocities.back();
+ const float dx = oldest.x - newest.x, dy = oldest.y - newest.y, dz = oldest.z - newest.z;
+ // 0x5A6370 keeps 1 / span on the x87 stack for z and stores it rounded for x and y.
+ const double inverse = 1.0 / static_cast(span);
+ const float inverseRounded = static_cast(inverse);
+ acceleration.x = inverseRounded * dx;
+ acceleration.y = inverseRounded * dy;
+ acceleration.z = static_cast(inverse * dz);
+ }
+ const double ax = acceleration.x, ay = acceleration.y, az = acceleration.z;
+ const float length = static_cast(std::sqrt(ax * ax + ay * ay + az * az));
+
+ IHapticSettings* haptics = static_cast(g_hapticSettings);
+ int band;
+ if ((haptics->*profile.transitionMed)() > length)
+ band = 0;
+ else if ((haptics->*profile.transitionHigh)() > length)
+ band = 1;
+ else
+ band = 2;
+ const float sx = (haptics->*profile.x[band])() * (haptics->*profile.scale)().x;
+ const float sy = (haptics->*profile.y[band])() * (haptics->*profile.scale)().y;
+ const float sz = (haptics->*profile.z[band])() * (haptics->*profile.scale)().z;
+ const int smoothBand = smoothTimesByBand ? band : 0;
+ const int smoothX = (haptics->*profile.smoothX[smoothBand])();
+ const int smoothY = (haptics->*profile.smoothY[smoothBand])();
+ const int smoothZ = (haptics->*profile.smoothZ[smoothBand])();
+
+ IHapticEffect*& effectX = g_hapticForceTargets[3]; // ds:0x9EBF04
+ IHapticEffect*& effectY = g_hapticForceTargets[4]; // ds:0x9EBF08
+ IHapticEffect*& effectZ = g_hapticForceTargets[5]; // ds:0x9EBF0C
+ createCraftPhysicsEffect(effectX, "CraftPhysicsX", smoothX);
+ createCraftPhysicsEffect(effectY, "CraftPhysicsY", smoothY);
+ createCraftPhysicsEffect(effectZ, "CraftPhysicsZ", smoothZ);
+
+ const double zero = 0.0;
+ NovintHFX::Vect3 force(zero, zero, zero);
+ const float cx = capCraftPhysics(acceleration.x, haptics->getForceCapX(), haptics, &IHapticSettings::getForceCapX);
+ const float cy = capCraftPhysics(acceleration.y, haptics->getForceCapY(), haptics, &IHapticSettings::getForceCapY);
+ const float cz = capCraftPhysics(acceleration.z, haptics->getForceCapZ(), haptics, &IHapticSettings::getForceCapZ);
+ // Retail multiplies on the x87 stack and stores doubles; float products are exact in double.
+ const double fx = -(static_cast(sx) * cx);
+ force = NovintHFX::Vect3(fx, zero, zero);
+ effectX->SetSmoothTime(smoothX);
+ effectX->SetForce(force);
+ const double fy = -(static_cast(sy) * cy);
+ force = NovintHFX::Vect3(zero, fy, zero);
+ effectY->SetSmoothTime(smoothY);
+ effectY->SetForce(force);
+ const double fz = static_cast(sz) * cz;
+ force = NovintHFX::Vect3(zero, zero, fz);
+ effectZ->SetSmoothTime(smoothZ);
+ effectZ->SetForce(force);
+}
+} // namespace
+#endif
+
+void updateSoldierCraftPhysicsForce(const Vec3& localVelocity, float dt)
+{
+#if !BF2_FALCON_SDK
+ (void) localVelocity; (void) dt;
+#else
+ static std::vector velocities; // ds:0x9EC550 (guard bit 2 of ds:0x9EC560)
+ static std::vector tickTimes; // ds:0x9EC540 (guard bit 1)
+ craftPhysicsForce(velocities, tickTimes, localVelocity, dt, kSoldierProfile, false);
+#endif
+}
+
+void updateVehicleCraftPhysicsForce(const Vec3& localVelocity, float dt, int vehicleCategory)
+{
+#if !BF2_FALCON_SDK
+ (void) localVelocity; (void) dt; (void) vehicleCategory;
+#else
+ static std::vector velocities; // ds:0x9F06BC (guard bit 1 of ds:0x9F06CC)
+ static std::vector tickTimes; // ds:0x9F06AC (guard bit 2)
+ const CraftPhysicsProfile* profile;
+ switch (vehicleCategory) { // the jump table at 0x5FBE40
+ case 1: profile = &kSeaProfile; break;
+ case 2: profile = &kAirProfile; break;
+ case 3: profile = &kHeliProfile; break;
+ default: profile = &kLandProfile; break; // 0 and every other value (0x5FB75C)
+ }
+ craftPhysicsForce(velocities, tickTimes, localVelocity, dt, *profile, true);
+#endif
+}
+
+void fireRecoilPunch(float punchTime, float punchScale, float fireStrength)
+{
+#if !BF2_FALCON_SDK
+ (void) punchTime; (void) punchScale; (void) fireStrength;
+#else
+ FalconEnvelopeParams* params = new FalconEnvelopeParams;
+ params->m_unresolved18 = static_cast(punchTime); // fistp with truncation
+ IHapticSettings* haptics = static_cast(g_hapticSettings);
+ const float strength = static_cast(std::fabs(fireStrength));
+ if (haptics->getForceCapZ() < strength)
+ params->m_force[2] = static_cast(haptics->getForceCapZ()) * punchScale;
+ else
+ params->m_force[2] = static_cast(punchScale) * fireStrength;
+ g_falconDevice->GetEffectStack()->CreateNewEffect("Envelope", params, "RecoilPunch", 0);
+ delete params;
+#endif
+}
+
+void weaponRecoilPunch(int weaponType, const std::string& templateName, float cameraRecoilSpeed,
+ float cameraRecoilSize, float fireStrength)
+{
+#if !BF2_FALCON_SDK
+ (void) weaponType; (void) templateName; (void) cameraRecoilSpeed; (void) cameraRecoilSize; (void) fireStrength;
+#else
+ IHapticSettings* haptics = static_cast(g_hapticSettings);
+ float punchTime, punchScale;
+ switch (weaponType - 13) { // the jump table at 0x60A5C0
+#define BF2_V_RECOIL(n, type) \
+ case n: \
+ punchTime = haptics->getRecoilPunchTime##type(); \
+ punchScale = haptics->getRecoilPunchScale##type(); \
+ haptics->setUnresolved48C(haptics->getRecoilYawScale##type()); \
+ haptics->setUnresolved490(haptics->getRecoilPitchScale##type()); \
+ break;
+ BF2_V_RECOIL(0, V_LMG)
+ BF2_V_RECOIL(1, V_HMG)
+ BF2_V_RECOIL(2, V_HELIGUN)
+ BF2_V_RECOIL(3, V_AIRGUN)
+ BF2_V_RECOIL(4, V_MISSILE)
+ BF2_V_RECOIL(5, V_ARMORCANNON)
+ BF2_V_RECOIL(6, V_COAXIALGUN)
+#undef BF2_V_RECOIL
+ default: {
+ std::string name(templateName);
+ for (std::size_t i = 0; i < name.size(); ++i)
+ name[i] = static_cast(std::tolower(name[i]));
+ if (name.find("firingport", 0, 10) != std::string::npos) {
+ punchTime = haptics->getRecoilPunchTimeRIFLE();
+ punchScale = haptics->getRecoilPunchScaleRIFLE();
+ haptics->setUnresolved48C(haptics->getRecoilYawScaleRIFLE());
+ haptics->setUnresolved490(haptics->getRecoilPitchScaleRIFLE());
+ } else {
+ punchTime = 1.0f;
+ punchScale = 0.0f;
+ haptics->setUnresolved48C(0.0f);
+ haptics->setUnresolved490(0.0f);
+ }
+ break;
+ }
+ }
+ punchScale = punchScale * cameraRecoilSize;
+ punchTime = punchTime * cameraRecoilSpeed;
+ fireRecoilPunch(punchTime, punchScale, fireStrength);
+#endif
+}
+
+void kitRecoilPunch(int weaponType, const std::string& templateName, float fireStrength)
+{
+#if !BF2_FALCON_SDK
+ (void) weaponType; (void) templateName; (void) fireStrength;
+#else
+ IHapticSettings* haptics = static_cast(g_hapticSettings);
+ float punchTime, punchScale;
+ switch (weaponType - 9) { // the jump table at 0x5E2E90
+ case 0: punchTime = haptics->getRecoilPunchTimeKNIFE(); punchScale = haptics->getRecoilPunchScaleKNIFE(); break;
+ case 1: punchTime = haptics->getRecoilPunchTimeDROP(); punchScale = haptics->getRecoilPunchScaleDROP(); break;
+ case 2: punchTime = haptics->getRecoilPunchTimeTHROWN(); punchScale = haptics->getRecoilPunchScaleTHROWN(); break;
+ case 3: punchTime = haptics->getRecoilPunchTimeDEFIB(); punchScale = haptics->getRecoilPunchScaleDEFIB(); break;
+ default: {
+ std::string name(templateName);
+ for (std::size_t i = 0; i < name.size(); ++i)
+ name[i] = static_cast(std::tolower(name[i]));
+ if (name.find("kit", 0, 3) != std::string::npos || name.find("wrench", 0, 6) != std::string::npos) {
+ punchTime = haptics->getRecoilPunchTimeDROP();
+ punchScale = haptics->getRecoilPunchScaleDROP();
+ } else {
+ punchTime = 1.0f;
+ punchScale = 0.0f;
+ }
+ break;
+ }
+ }
+ fireRecoilPunch(punchTime, punchScale, fireStrength);
+#endif
+}
+
+void soldierRecoilPunch(int weaponType, bool hasRandomRecoilForce, unsigned int recoilSamples, const float* lastSample,
+ float forceUpValue, float forceUpVariation, float forceModifier, float fireStrength)
+{
+#if !BF2_FALCON_SDK
+ (void) weaponType; (void) hasRandomRecoilForce; (void) recoilSamples; (void) lastSample;
+ (void) forceUpValue; (void) forceUpVariation; (void) forceModifier; (void) fireStrength;
+#else
+ IHapticSettings* haptics = static_cast(g_hapticSettings);
+ float punchTime, punchScale;
+ switch (weaponType) { // the jump table at 0x60969C
+ case 0: punchTime = haptics->getRecoilPunchTimeRIFLE(); punchScale = haptics->getRecoilPunchScaleRIFLE(); break;
+ case 1: punchTime = haptics->getRecoilPunchTimeRIFLELAUNCHER(); punchScale = haptics->getRecoilPunchScaleRIFLELAUNCHER(); break;
+ case 2: punchTime = haptics->getRecoilPunchTimeCARBINE(); punchScale = haptics->getRecoilPunchScaleCARBINE(); break;
+ case 3: punchTime = haptics->getRecoilPunchTimeLMG(); punchScale = haptics->getRecoilPunchScaleLMG(); break;
+ case 4: punchTime = haptics->getRecoilPunchTimeSNIPER(); punchScale = haptics->getRecoilPunchScaleSNIPER(); break;
+ case 6: punchTime = haptics->getRecoilPunchTimeLAUNCHER(); punchScale = haptics->getRecoilPunchScaleLAUNCHER(); break;
+ case 7: punchTime = haptics->getRecoilPunchTimeSMG(); punchScale = haptics->getRecoilPunchScaleSMG(); break;
+ case 8: punchTime = haptics->getRecoilPunchTimeSHOTGUN(); punchScale = haptics->getRecoilPunchScaleSHOTGUN(); break;
+ case 9: punchTime = haptics->getRecoilPunchTimeKNIFE(); punchScale = haptics->getRecoilPunchScaleKNIFE(); break;
+ case 10: punchTime = haptics->getRecoilPunchTimeDROP(); punchScale = haptics->getRecoilPunchScaleDROP(); break;
+ case 11: punchTime = haptics->getRecoilPunchTimeTHROWN(); punchScale = haptics->getRecoilPunchScaleTHROWN(); break;
+ case 12: punchTime = haptics->getRecoilPunchTimeDEFIB(); punchScale = haptics->getRecoilPunchScaleDEFIB(); break;
+ default: punchTime = haptics->getRecoilPunchTimePISTOL(); punchScale = haptics->getRecoilPunchScalePISTOL(); break;
+ }
+ if (hasRandomRecoilForce) {
+ punchTime = static_cast(recoilSamples) * punchTime;
+ // x87: ((variation + value) * 0.5) * modifier * last, negated, times the scale; one rounding.
+ punchScale = static_cast(-(((static_cast(forceUpVariation) + forceUpValue) * 0.5)
+ * forceModifier * *lastSample) * punchScale);
+ }
+ fireRecoilPunch(punchTime, punchScale, fireStrength);
+#endif
+}
+
+void updateDamageForce(world::IPlayer* victim, world::IPlayer* localPlayer, const Mat4& lookAt,
+ const Mat4& ownerTransform, float damage)
+{
+#if !BF2_FALCON_SDK
+ (void) victim; (void) localPlayer; (void) lookAt; (void) ownerTransform; (void) damage;
+#else
+ // The forward row in the owner's frame, accumulated on the x87 stack in retail's order.
+ const double fx = lookAt.m[8], fy = lookAt.m[9], fz = lookAt.m[10];
+ const Mat4& o = ownerTransform;
+ const float c = static_cast(fy * o.m[9] + fz * o.m[10] + fx * o.m[8]);
+ const float a = static_cast(fy * o.m[1] + fz * o.m[2] + fx * o.m[0]);
+ const float b = static_cast(fy * o.m[5] + fz * o.m[6] + fx * o.m[4]);
+ if (victim != localPlayer || !g_falconDevice)
+ return;
+ FalconEnvelopeParams* params = new FalconEnvelopeParams;
+ params->m_unresolved18 = 100;
+ IHapticSettings* haptics = static_cast(g_hapticSettings);
+ const double magnitude = static_cast(haptics->getDamageScale()) * damage * 0.5;
+ const double x = -static_cast(a), y = b, z = c;
+ NovintHFX::Vect3 force = NovintHFX::Vect3(x, y, z).Normalize() * magnitude;
+ params->m_force[0] = force[0];
+ params->m_force[1] = force[1];
+ params->m_force[2] = force[2];
+ g_falconDevice->GetEffectStack()->CreateNewEffect("Envelope", params, "Damage", 0);
+ delete params;
+#endif
+}
+
+// PE 0x6A52A0. Consumes the samples update(0) queued that are older than the advanced sample
+// clock: smoothed position deltas, the mouse or control-box mode, then the button state.
+void FalconDevice::updateCurrentState(float dt)
+{
+#if !BF2_FALCON_SDK
+ // x64: unreachable (update() returns while m_device is null, and it always is).
+ (void) dt;
+#else
+ IControlMap* map = static_cast(controlMapManager)->getActive();
+ m_axes[2] = 0.0;
+ m_axes[1] = 0.0;
+ m_axes[0] = 0.0;
+ m_previousButtons = m_buttons;
+ m_sampleTime += bf2x87::toIntTruncate(static_cast(dt) * 1000.0);
+ IHapticSettings* haptics = static_cast(g_hapticSettings);
+ while (!m_samples.empty()) {
+ FalconInputFormat& sample = m_samples.front();
+ if (sample.time >= m_sampleTime) break;
+ inputSampleLatency = static_cast(
+ static_cast(static_cast(m_pollTime - sample.time))
+ * static_cast(0.001f));
+ const double x = sample.position[0];
+ const double y = map && map->getInvertMouse() ? -sample.position[1] : sample.position[1];
+ const double z = map && map->getInvertMouse() ? -sample.position[2] : sample.position[2];
+ static std::deque historyX;
+ static std::deque historyY;
+ static std::deque historyZ;
+ double deltaX = 0.0, deltaY = 0.0, deltaZ = 0.0;
+ if (s_smoothingCount < s_smoothingWindow) {
+ historyX.push_back(x);
+ historyY.push_back(y);
+ historyZ.push_back(z);
+ ++s_smoothingCount;
+ } else if (s_smoothingCount == s_smoothingWindow) {
+ deltaX = windowDelta(historyX, x * component(haptics->getAimSensitivity(), 0));
+ deltaY = windowDelta(historyY, y * component(haptics->getAimSensitivity(), 1));
+ deltaZ = windowDelta(historyZ, z * component(haptics->getAimSensitivity(), 2));
+ } else {
+ popFrontIfAny(historyX);
+ popFrontIfAny(historyY);
+ popFrontIfAny(historyZ);
+ --s_smoothingCount;
+ }
+ // While a binding is being captured the frame ends here: the sample stays queued and
+ // the axis scaling below is skipped (0x6A57CE -> 0x6A5C7B).
+ if (static_cast(g_controlSettings)->isMappingInput()) return;
+ if (g_falconMouseMode > 0 && isActive()) {
+ m_axes[0] = s_falconMouseGain * x;
+ m_axes[1] = -(s_falconMouseGain * y);
+ if (g_falconMouseMode == 1) {
+ m_haptics->StartMouse(m_device);
+ g_falconMouseMode = 2;
+ if (s_controlBoxEffect && !(s_controlBoxEffect->m_stateFlags & 1))
+ s_controlBoxEffect->m_stateFlags |= 1;
+ }
+ }
+ if (g_falconMouseMode < 1 && isActive()) {
+ bool rebuild = false;
+ if (g_falconMouseMode == 0) {
+ g_falconMouseMode = -1;
+ rebuild = true;
+ } else if (g_falconControlBoxDirty) {
+ rebuild = true;
+ }
+ if (rebuild) {
+ g_falconControlBoxDirty = false;
+ FalconControlBoxParams* params = new FalconControlBoxParams;
+ for (int i = 0; i < 3; ++i) {
+ // The vertical walls sit 0.01 lower than the configured length.
+ const float lowerOffset = i == 2 ? 0.01f : 0.0f;
+ params->m_lower[i] = -static_cast(component(haptics->getControlBoxLength(), i))
+ - static_cast(lowerOffset);
+ params->m_lowerStiffness[i] = component(haptics->getControlBoxStiffness(), i);
+ const float upperOffset = i == 2 ? 0.01f : 0.0f;
+ params->m_upper[i] = static_cast(component(haptics->getControlBoxLength(), i))
+ - static_cast(upperOffset);
+ params->m_upperStiffness[i] = component(haptics->getControlBoxStiffness(), i);
+ }
+ params->m_unresolved114 = s_controlBoxForceValue;
+ if (!s_controlBoxEffect)
+ g_falconDevice->GetEffectStack()->CreateNewEffect("BOX", params, "ControlBox",
+ &s_controlBoxEffect);
+ s_controlBoxEffect->UpdateParams(params);
+ if (s_controlBoxEffect->m_stateFlags & 1) s_controlBoxEffect->m_stateFlags &= ~1;
+ delete params;
+ }
+ m_axes[0] = axisValue(haptics, 0, x, deltaX, 2000.0, 2500.0);
+ m_axes[1] = axisValue(haptics, 1, y, deltaY, -2000.0, -2500.0);
+ m_axes[2] = axisValue(haptics, 2, z, deltaZ, -2000.0, -2500.0);
+ }
+ int pressed, released;
+ m_device->GetButtonData(reinterpret_cast(&sample.buttons), &pressed, &released);
+ m_buttons = sample.buttons;
+ m_samples.pop_front();
+ }
+ // Retail scales four doubles from +0x18; the fourth is the bytes of m_axisTravel[0..1].
+ // The active map is not null-tested here.
+ for (int i = 0; i < 3; ++i)
+ m_axes[i] *= map->getAxisScale(static_cast(i));
+ double fourth;
+ std::memcpy(&fourth, m_axisTravel, sizeof(fourth));
+ fourth *= map->getAxisScale(static_cast(3));
+ std::memcpy(m_axisTravel, &fourth, sizeof(fourth));
+#endif
+}
+namespace {
+FalconInputFormat inputBuffer[1]; // PE 0xA03918, static polling buffer
+const float lowerTravel[3] = { -0.0025f, -0.0025f, -0.001f };
+const float upperTravel[3] = { 0.0025f, 0.0025f, 0.001f };
+}
+FalconDevice::FalconDevice()
+ : m_refCount(1), m_active(false), m_pollTime(0),
+#if BF2_FALCON_SDK
+ m_haptics(&Haptics),
+#else
+ m_haptics(0),
+#endif
+ m_device(0)
+{
+#if defined(_M_IX86)
+ static_assert(offsetof(FalconDevice, m_samples) == 0xE4, "x86 scalar prefix");
+#endif
+ static_assert(sizeof(FalconInputFormat) == 40, "x86 input sample alignment");
+ m_field100 = 0;
+ g_falconDevice = 0;
+ m_buttons = 0;
+ m_previousButtons = 0;
+ for (int i = 0; i < 3; ++i) {
+ m_axisScale[i] = 1.0f;
+ m_axes[i] = 0.0;
+ m_invertAxis[i] = false;
+ m_axisTravel[i] = 0;
+ }
+ m_field0fc = false;
+ m_field0f0 = 0;
+ m_field0f4 = 0;
+ m_field0f8 = 0;
+}
+FalconDevice::~FalconDevice()
+{
+#if BF2_FALCON_SDK
+ if (m_device) {
+ m_haptics->StopRunningDevice(&m_device);
+ m_haptics = 0;
+ g_falconDevice = 0;
+ m_device = 0;
+ }
+#endif
+}
+void FalconDevice::addRef() { ++m_refCount; }
+int FalconDevice::getRef() { return m_refCount; }
+int FalconDevice::release()
+{
+ const int refs = --m_refCount;
+ if (!refs) delete this;
+ return refs;
+}
+void* FalconDevice::queryInterface(unsigned int iid) const
+{
+ return iid == IID_IBase || iid == IID_IInputDevice || iid == IID_IAdvancedInputDevice
+ ? const_cast(this) : 0;
+}
+InputDeviceTypes FalconDevice::getType() const { return IDTFalcon; }
+bool FalconDevice::setCooperativeMode(InputDeviceMode mode) { m_mode = mode; return true; }
+InputDeviceMode FalconDevice::getCooperativeMode() const { return m_mode; }
+bool FalconDevice::activate()
+{
+ if (!m_device) return false;
+ if (!m_active) m_active = true;
+ return true;
+}
+bool FalconDevice::deActivate()
+{
+ // Retail intentionally does not clear m_active or stop the device here.
+ return m_device != 0;
+}
+bool FalconDevice::isActive() const { return m_device && m_active; }
+int FalconDevice::getNumAxes() const { return m_numAxes; }
+int FalconDevice::getNumButtons() const { return m_numButtons; }
+float FalconDevice::readAxis(InputDeviceAxes axis, bool) const
+{
+ // The scaling argument and configured scale are ignored by this body.
+ return static_cast(m_invertAxis[axis] ? -m_axes[axis] : m_axes[axis]);
+}
+void FalconDevice::setInvertAxis(InputDeviceAxes axis, bool invert)
+{
+ if (axis <= m_numAxes) m_invertAxis[axis] = invert;
+}
+bool FalconDevice::getInvertAxis(InputDeviceAxes axis) const
+{
+ return axis <= m_numAxes ? m_invertAxis[axis] : false;
+}
+void FalconDevice::setAxisScale(InputDeviceAxes axis, float scale)
+{
+ if (axis <= m_numAxes) m_axisScale[axis] = scale;
+}
+float FalconDevice::getAxisScale(InputDeviceAxes axis) const
+{
+ return axis <= m_numAxes ? m_axisScale[axis] : 0.0f;
+}
+// These no-op/zero bodies are present in both binaries, not frontier substitutes.
+void FalconDevice::setAxisAdd(InputDeviceAxes, float) {}
+float FalconDevice::getAxisAdd(InputDeviceAxes) const { return 0.0f; }
+bool FalconDevice::buttonDown(InputDeviceButtons button) const { return (m_buttons & button) != 0; }
+bool FalconDevice::buttonPressed(InputDeviceButtons button) const
+{
+ return !(m_previousButtons & button) && (m_buttons & button);
+}
+bool FalconDevice::buttonReleased(InputDeviceButtons button) const
+{
+ return (m_previousButtons & button) && !(m_buttons & button);
+}
+float FalconDevice::buttonPressedSampleLatency(InputDeviceButtons button) const
+{
+ for (unsigned int i = 0; i < 32; ++i)
+ if (static_cast(button) & (1u << i)) return m_buttonLatency[i];
+ return 0.0f;
+}
+bool FalconDevice::init()
+{
+ if (!inputDeviceManager) return false;
+#if !BF2_FALCON_SDK
+ std::fprintf(stderr, "[x64] dice::hfe::io::FalconDevice::init: no 64-bit NovintHFX SDK; "
+ "the Falcon is reported as not connected\n");
+ std::fflush(stderr);
+ return false;
+#else
+ const HWND window = GetForegroundWindow();
+ NovintHFX::ApplicationData application;
+ application.window = window;
+ bool active = false;
+ if (m_haptics->AttachApplication(application)) {
+ m_haptics->RecountConnectedDevices();
+ if (m_haptics->ConnectedDeviceCount() < 1) return false;
+ active = m_haptics->RunDevice(&m_device, 0);
+ g_falconDevice = m_device;
+ m_haptics->StartMouse(m_device);
+ }
+ m_active = active;
+ m_numAxes = 3;
+ m_numButtons = 4;
+ // AttachApplication failure still returns true; zero devices returns false.
+ return true;
+#endif
+}
+bool FalconDevice::getNextInput(InputDeviceAxes& axis, InputDeviceButtons& button,
+ InputDeviceKeys& key, bool& negative)
+{
+ if (!m_active) return false;
+ if (!m_device) return false;
+#if BF2_FALCON_SDK
+ m_device->InputUpdate();
+ int buttons, pressed, released;
+ m_device->GetButtonData(&buttons, &pressed, &released);
+ for (unsigned int i = 0; i < m_numButtons; ++i) {
+ if (static_cast(buttons) & (1u << i)) {
+ axis = static_cast(15);
+ button = static_cast(1u << i);
+ key = static_cast(0);
+ return true; // negative output deliberately untouched for buttons
+ }
+ }
+ double position[3];
+ m_device->GetToolPosition(position);
+ for (int i = 0; i < m_numAxes; ++i) {
+ int& travel = m_axisTravel[i];
+ if (lowerTravel[i] > position[i]) {
+ if (!travel) travel = 1;
+ else if (travel == 2) travel = 3;
+ }
+ if (upperTravel[i] < position[i]) {
+ if (!travel) { travel = 2; continue; }
+ if (travel == 1) travel = 3;
+ }
+ if (travel == 3) {
+ for (int j = 0; j < m_numAxes; ++j) m_axisTravel[j] = 0;
+ axis = static_cast(i);
+ button = static_cast(0);
+ key = static_cast(0);
+ negative = m_axes[i] < 0.0;
+ return true;
+ }
+ }
+#endif
+ return false;
+}
+void FalconDevice::update(float dt)
+{
+ if (!m_active || !m_device) return;
+ if (dt > 0.0f) {
+ updateCurrentState(dt);
+ return;
+ }
+#if BF2_FALCON_SDK
+ if (m_samples.size() > 256) m_samples.clear();
+ m_haptics->InputUpdate();
+ double position[3];
+ m_device->GetToolPosition(position);
+ inputBuffer[0].position[0] = position[0];
+ inputBuffer[0].position[1] = position[1];
+ inputBuffer[0].position[2] = position[2];
+ int pressed, released;
+ m_device->GetButtonData(reinterpret_cast(&inputBuffer[0].buttons), &pressed, &released);
+ inputBuffer[0].time = GetTickCount();
+ m_sampleTime = m_pollTime;
+ m_pollTime = GetTickCount();
+ for (unsigned int i = 0; i < 1; ++i) m_samples.push_back(inputBuffer[i]);
+#endif
+}
+} } }
+#endif
diff --git a/Code/BF2/IO/Input/FalconDevice.h b/Code/Archive/NovintFalcon/IO/Input/FalconDevice.h
similarity index 75%
rename from Code/BF2/IO/Input/FalconDevice.h
rename to Code/Archive/NovintFalcon/IO/Input/FalconDevice.h
index eb39cc58f..d12383f6e 100644
--- a/Code/BF2/IO/Input/FalconDevice.h
+++ b/Code/Archive/NovintFalcon/IO/Input/FalconDevice.h
@@ -1,8 +1,21 @@
// Falcon input device. [INFERRED] Header placement. Preserve its 27-slot interface without a destructor slot.
+// BF2_NOVINT_FAKE_SDK: the Mac fake-SDK check compiles the Windows class against fake SDK bodies.
#ifndef IO_INPUT_FALCONDEVICE_H
#define IO_INPUT_FALCONDEVICE_H
#include "../../Core/BuildConfig.h"
#if !DEDICATED
+#include "FalconHaptics.h" // g_falconControlBoxDirty and the haptic-effect helpers (ledger N2)
+class IHapticEffect; // NovintHFX.h (global namespace); the haptic force effects (BF2ClientSeams.h)
+#if !defined(_WIN32) && !defined(BF2_NOVINT_FAKE_SDK)
+// [CHOSEN, not recovered] Native POSIX clients: the Novint HFX SDK is a Windows-only DLL and no
+// Falcon is ever present, so neither the SDK header nor FalconDevice exists there; the device
+// manager reports IDFFalcon as not opened (MacInputDeviceManager). Only the menu's mouse-mode
+// global, which the menu and HUD code write on every platform, is declared. See
+// docs/macos-port.md, "Bink, Novint and VoIP capture (S2.8)".
+namespace dice { namespace hfe { namespace io {
+extern int g_falconMouseMode; // [INFERRED] name, PE978FC4 initialized1; HUD/updateCurrentState writers
+} } }
+#else
#include "Input.h"
#include "../../External/NovintHFX/NovintHFX.h"
#include
@@ -47,9 +60,8 @@ class FalconDevice : public IAdvancedInputDevice {
float buttonPressedSampleLatency(InputDeviceButtons) const override;
virtual bool init();
private:
- // [FRONTIER] PE 0x6A52A0, ELF 0x8499C80; positive-dt frame update.
- // Required HapticSettings/effect interfaces are not yet recovered.
- void updateCurrentState(float); // [TEMP] diagnostic abort; falcon-state-diagnostic
+ // PE 0x6A52A0, ELF 0x8499C80 (whose sample loop is compiled out); positive-dt frame update.
+ void updateCurrentState(float);
int m_refCount; // PE +04
unsigned int m_buttons; // +08
InputDeviceMode m_mode; // +0C; ctor leaves untouched
@@ -71,5 +83,6 @@ class FalconDevice : public IAdvancedInputDevice {
DWORD m_field100; // [UNRESOLVED] initialized zero
};
} } }
+#endif // _WIN32
#endif
#endif
diff --git a/Code/Archive/NovintFalcon/IO/Input/FalconHaptics.h b/Code/Archive/NovintFalcon/IO/Input/FalconHaptics.h
new file mode 100644
index 000000000..9e6208c85
--- /dev/null
+++ b/Code/Archive/NovintFalcon/IO/Input/FalconHaptics.h
@@ -0,0 +1,96 @@
+// The game-facing half of the Falcon device (ledger N2): the control-box flag and the haptic-effect
+// helpers the game code calls. [CHOSEN, not recovered] Split from FalconDevice.h so that game TUs do not
+// see NovintHFX.h, which includes (its min/max macros broke Soldier.cpp's std::min/max on
+// MSVC). The bodies are in FalconDevice.cpp; on POSIX clients and without a device they do nothing.
+#ifndef IO_INPUT_FALCONHAPTICS_H
+#define IO_INPUT_FALCONHAPTICS_H
+#include "../../Core/BuildConfig.h"
+#if !DEDICATED
+#include "../../Math/Vec3.h"
+#include "../../Math/Mat4.h"
+#include
+namespace dice { namespace hfe { namespace world { class IPlayerControlObject; class IPlayer; } } }
+namespace dice { namespace hfe { namespace io {
+// [INFERRED] name, PE978FC8 initialized true. updateCurrentState rebuilds the control-box effect
+// from HapticSettings when it is set and clears it; the haptic-effect sites 0x5AB83A, 0x5AC90B and
+// 0x5ADD98 (ledger N2) set it.
+extern bool g_falconControlBoxDirty;
+// MainMenuLogic::activate 0x4A3490..0x4A3535 (inline in retail): one NovintHFX::Vect3(0, 0, 0), then
+// each non-null haptic force effect's +0x4C in retail's order 0x9EBF00, F04, F08, F0C, EC8, ECC.
+// [CHOSEN, not recovered] Out of line here because MainMenuLogic builds on every platform and the
+// SDK declarations are Windows-only.
+void zeroHapticForceTargets();
+// Camera::handleUpdate's Novint block (BF2.exe 0x5A3F4F..0x5A41D7, ledger N2 17b), for the local
+// occupant's camera. With a device: create the two CONSTANT "ShakeForce" effects (ds:0x9EBEC8/CC) once,
+// then each frame set Vect3(x, y, 0) on the soldier's (CC) or the vehicle's (C8) from the camera's
+// shake terms scaled by HapticSettings (+0x7DC explosion, +0x7E4 speed, +0x7D4 general on the
+// close-vehicle pitch, +0x7C4 / +0x7CC on the recoil), each axis capped by the force cap with its sign.
+// The soldier test is the occupied object's template class id (pco -> IID_IObject -> +0x14 -> +0x10).
+// [CHOSEN, not recovered] Out of line here for the same reason as zeroHapticForceTargets.
+void updateShakeForce(world::IPlayerControlObject* pco, float explosionRoll, float speedRoll,
+ float closeVehiclePitch, float recoilY);
+// g_falconDevice != 0 (false on POSIX clients), for callers that build on every platform.
+// [CHOSEN, not recovered]
+bool hapticDeviceConnected();
+// Soldier::handlePlayerInput's "Recoil" block (BF2.exe 0x5AE335..0x5AE72B, ledger N2 17b), for the
+// local occupant while a device is connected: create the Constant "Recoil" effect (ds:0x9EBF00) once
+// (params +0x18 = 10), then set it every tick. Zero unless the yaw delta (recoil plus look) or the
+// raw pitch recoil is non-zero; otherwise Vect3(yawScale * x, -(pitchScale * y), 0), where x and y are
+// those two values capped by the force caps with their sign (0x5A6280) and the scales are
+// HapticSettings' recoil yaw / pitch scales for the weapon type (0 RIFLE .. 12 DEFIB, else 0).
+// [CHOSEN, not recovered] Out of line, as zeroHapticForceTargets.
+void updateRecoilForce(float yawDelta, float pitchRecoil, int weaponType);
+// Soldier::handlePlayerInput's "CraftPhysics" block (BF2.exe 0x5AECE8..0x5AF3F6, ledger N2 17b), after
+// setRotationalSpeed, for the local occupant while a device is connected. The soldier's velocity in
+// its vehicle's frame goes into static three-entry histories (velocities ds:0x9EC550, tick times
+// ds:0x9EC540); once full, the acceleration is (oldest - newest) * (1 / (the last two tick times)),
+// else zero. Its length against PhysicsSOLDIERTransitionValueMed / High picks the Low, Med or High
+// scales (each times PhysicsSOLDIERScale's component). The three Constant effects "CraftPhysicsX/Y/Z"
+// (ds:0x9EBF04/08/0C) are created once with params +0x18 = PhysicsSOLDIERSmoothTimeX/Y/ZLow (Low in
+// every band, as shipped); each tick each gets SetSmoothTime(that value) and a force along its own
+// axis: -(sx * ax), -(sy * ay), +(sz * az), each acceleration component first capped by the force cap
+// with its sign. [CHOSEN, not recovered] Out of line, as zeroHapticForceTargets.
+void updateSoldierCraftPhysicsForce(const Vec3& localVelocity, float dt);
+// PlayerControlObject::handleUpdate's "CraftPhysics" block (BF2.exe 0x5FADAE..0x5FBCD8, ledger N2 17b):
+// the same core with its own histories (ds:0x9F06BC velocities, ds:0x9F06AC tick times) and the
+// HapticSettings block of the vehicle category (jump table 0x5FBE40: 1 SEA, 2 AIR, 3 HELI, LAND for 0
+// and every other value); unlike the soldier's, each band takes its own smooth times.
+void updateVehicleCraftPhysicsForce(const Vec3& localVelocity, float dt, int vehicleCategory);
+// SoldierBasedRecoilComp::postFire's "RecoilPunch" (BF2.exe 0x609353..0x609690, ledger N2 17b), for the
+// local occupant while a device is connected: punch time and scale from HapticSettings by the soldier's
+// active weapon type (jump table 0x60969C: 0 RIFLE .. 12 DEFIB, but 5 and every type above 12 share the
+// default, PISTOL); with a random recoil force, time *= the recoil graph's sample count and
+// scale = -(((variation + value) * 0.5) * forceModifier * lastSample) * scale; then fireRecoilPunch.
+// The last sample is read unchecked, as shipped.
+void soldierRecoilPunch(int weaponType, bool hasRandomRecoilForce, unsigned int recoilSamples, const float* lastSample,
+ float forceUpValue, float forceUpVariation, float forceModifier, float fireStrength);
+// The shared tail of the RecoilPunch sites (0x6095EF..0x60968A, 0x60A451..0x60A4F8): an Envelope
+// params object (+0x18 = the punch time truncated, m_force[2] = capZ * scale when the fire strength's
+// magnitude is above the Z force cap, as shipped without its sign, else scale * fireStrength), the
+// effect "RecoilPunch" created without keeping it, the params deleted.
+void fireRecoilPunch(float punchTime, float punchScale, float fireStrength);
+// WeaponBasedRecoilComp::postFire's "RecoilPunch" (BF2.exe 0x60A0E7..0x60A4F8, ledger N2 17b), for the
+// local occupant while a device is connected: by the firing weapon's type, 13..19 (jump table 0x60A5C0:
+// V_LMG, V_HMG, V_HELIGUN, V_AIRGUN, V_MISSILE, V_ARMORCANNON, V_COAXIALGUN) take that type's punch time
+// and scale and set HapticSettings +0x48C / +0x490 (the recoil scales the ShakeForce block reads) to its
+// recoil yaw / pitch scale; any other type takes RIFLE's four values when the lower-cased template name
+// contains "firingport", else time 1, scale 0 and both set to 0. Then scale *= cameraRecoilSize,
+// time *= cameraRecoilSpeed, and fireRecoilPunch.
+void weaponRecoilPunch(int weaponType, const std::string& templateName, float cameraRecoilSpeed,
+ float cameraRecoilSize, float fireStrength);
+// GenericFireArm::postFire's "RecoilPunch" for a weapon without a recoil component (BF2.exe
+// 0x5E2A98..0x5E2CDA, the else of m_recoilComp->postFire; ledger N2 17b), when the weapon's player is
+// the local player and a device is connected: weapon types 9..12 (jump table 0x5E2E90: KNIFE, DROP,
+// THROWN, DEFIB) take that type's punch time and scale; any other type takes DROP's when the lower-cased
+// template name contains "kit" or else "wrench", otherwise time 1 and scale 0; then fireRecoilPunch.
+void kitRecoilPunch(int weaponType, const std::string& templateName, float fireStrength);
+// GameLogicDamage::serverGiveDamage's "Damage" envelope (BF2.exe 0x5E6566..0x5E66A2, ledger N2 17b):
+// for the local victim with a device, the look-at frame's forward row (lookAt +0x20) in the damaged
+// owner's frame (dot products with its rows 0, 1, 2) gives Vect3(-a, b, c), normalized and scaled by
+// HapticSettings' damage scale * damage * 0.5, into an Envelope params object (+0x18 = 100,
+// m_force); the effect "Damage" created without keeping it. The victim test is pointer equality.
+void updateDamageForce(world::IPlayer* victim, world::IPlayer* localPlayer, const Mat4& lookAt,
+ const Mat4& ownerTransform, float damage);
+} } }
+#endif // !DEDICATED
+#endif
diff --git a/Code/Archive/NovintFalcon/README.md b/Code/Archive/NovintFalcon/README.md
new file mode 100644
index 000000000..312ea8337
--- /dev/null
+++ b/Code/Archive/NovintFalcon/README.md
@@ -0,0 +1,121 @@
+# Novint Falcon (archived)
+
+`[CHOSEN, not recovered]` This directory keeps the reconstructed Novint Falcon support. No
+image builds it. The owner decided to drop Falcon support
+([issue #17](https://github.com/kr4uzi/OpenBF2/issues/17)). The code is kept as a reference
+here, not deleted. Windows later shipped the x86 client again, for PunkBuster. The Falcon
+stays archived there too, and the x86 client could load the 32-bit DLL again if restored (see
+"Restoring").
+
+## What it was
+
+Retail `BF2.exe` drives a Novint Falcon, a 3-DOF haptic controller, through the vendor SDK
+`NovintHFX.dll`. It imports that DLL statically, so retail needs the DLL even when no Falcon
+is connected. The game uses it in two ways:
+
+- **As an input device.** `FalconDevice` is the `IDFFalcon` device of the DirectInput device
+ manager (`IAdvancedInputDevice`, 27 slots, no destructor slot). It polls position and
+ buttons, and in menus it moves the pointer (`g_falconMouseMode`). In game it holds a
+ "control box" spring effect, rebuilt from `HapticSettings` whenever
+ `g_falconControlBoxDirty` is set.
+- **As force feedback.** About 140 game-side lines create and update HFX effects: the camera
+ `ShakeForce`, the soldier and vehicle `CraftPhysics`, the soldier `Recoil`, the weapon,
+ soldier and kit `RecoilPunch`, and the `Damage` envelope. They also zero the six persistent
+ effects on menu entry, death, the free camera and vehicle enter/exit.
+
+`HapticSettings` (`Haptic.con`, the menu's force-feedback page and the profile files) is
+retail profile data and is **not** archived. It still loads, saves and applies as in retail.
+The Soldier's control-box profile switch (`applyHapticProfile` and `hapticProfileForEntered`
+in `Game/Objects/Game/SoldierHapticProfile.cpp`) also stays, because it writes
+`HapticSettings`.
+
+`NovintHFX.dll` exists only as a 32-bit DLL. The native x64 client
+([issue #7](https://github.com/B2BF/OpenBF2/issues/7)) could never load it. The macOS and
+Linux clients never had a Falcon.
+
+## Retail addresses (BF2.exe 1.50)
+
+| Item | Address |
+| --- | --- |
+| `FalconDevice::~FalconDevice` | `0x6A50D0` |
+| `FalconDevice::updateCurrentState` | `0x6A52A0` (ELF `0x8499C80`, sample loop compiled out) |
+| `g_falconDevice` | `ds:0xA03940` |
+| `g_falconMouseMode` (initialized 1) | `ds:0x978FC4` |
+| `g_falconControlBoxDirty` (initialized true) | `ds:0x978FC8` |
+| the six force effects `g_hapticForceTargets` | `ds:0x9EBEC8`, `0x9EBECC`, `0x9EBF00`, `0x9EBF04`, `0x9EBF08`, `0x9EBF0C` |
+| control-box effect, sample buffer | `ds:0xA03944`, `ds:0xA03918` |
+| `FalconControlBoxParams` vtable store after the SDK constructor | `0x6A58A1` (vtable `0x9116E0`) |
+| `MainMenuLogic::activate` force zeroing | `0x4A3490..0x4A3535` |
+| `Camera::handleUpdate` ShakeForce | `0x5A3F4F..0x5A41D7` |
+| `Soldier` ctor / `onExit` / `onEnter` control-box switch | `0x5AC764..0x5AC90B`, `0x5AB5E6..0x5AB83A`, `0x5ACC99..0x5ADE14` |
+| `Soldier::handlePlayerInput` Recoil / CraftPhysics | `0x5AE335..0x5AE72B`, `0x5AECE8..0x5AF3F6` |
+| `PlayerControlObject::handleUpdate` CraftPhysics | `0x5FAC8C..0x5FBCDB` |
+| `GenericFireArm::postFire` kit RecoilPunch | `0x5E2A98..0x5E2CDA` |
+| `SoldierBasedRecoilComp::postFire` RecoilPunch | `0x609318..0x609690` |
+| `WeaponBasedRecoilComp::postFire` RecoilPunch | `0x60A077..0x60A4FE` |
+| `GameLogicDamage::serverGiveDamage` Damage envelope | `0x5E6566..0x5E66A2` |
+| `GameLogic` kill tail force zeroing | `0x4ED60B..0x4ED6C2` |
+| `FreeCamera::handlePlayerInput` force zeroing | `0x63EC73..0x63ED26` |
+| `BF2Engine::renderMenu` mouse mode | `0x40BD44..0x40BD57` |
+
+More addresses are in the comments of the archived sources.
+
+## Contents
+
+The files keep their paths relative to `Code/BF2` (sources) and `Code/Tests` (checks).
+
+| File | Was |
+| --- | --- |
+| `IO/Input/FalconDevice.h`, `FalconDevice.cpp` | the device, the effect bodies and the globals |
+| `IO/Input/FalconHaptics.h` | the game-facing effect helpers |
+| `External/NovintHFX/NovintHFX.h`, `NovintHFX.def` | the SDK ABI header and the x86 import-library definition |
+| `Game/Objects/Game/SoldierHapticForces.h`, `.cpp` | the force inputs of `SoldierHapticProfile` (`HapticWeaponAccess`, `updateSoldierRecoilForce`, `updateSoldierCraftPhysics`, `updateVehicleCraftPhysics`) |
+| `Tests/falcon_update_runtime.cpp`, `Tests/novint_fake/windows.h` | `bf2_falcon_update_check` (Mac, fake SDK) |
+| `Tests/falcon_device_runtime.cpp`, `.cmd` | the MSVC x86 check against the stock DLL |
+| `Tests/falcon_vtable_restore.cmd` | the MSVC check of the local vtable stores after the SDK constructors |
+| `Tests/msvc_x86_layout/novint_x86_layout.cpp`, `include/windows.h` | `bf2_novint_msvc_x86_layout` (clang, MSVC x86 ABI) |
+| `Tests/soldier_haptic_profile_runtime.cpp` | `bf2_soldier_haptic_profile_check` as it was, with the force-input checks (the live check keeps the profile switch) |
+
+## What replaced it
+
+Each call site now does what retail does with `NovintHFX.dll` present and no Falcon
+connected: `FalconDevice::init` fails, `g_falconDevice` stays null and every effect helper
+returns at its null test. The globals were only read by `FalconDevice`, so their writes are
+gone too. Each site has a comment that points here.
+
+| Site | Now |
+| --- | --- |
+| `IO/Input/DX8InputDeviceManager.cpp` `open` | `IDFFalcon` is never opened; its bit stays clear (as in `MacInputDeviceManager`) |
+| `Menu/MainMenuLogic.cpp` `activate` | no mouse-mode write, no force zeroing |
+| `Menu/BetweenRoundsLogic.cpp` `activate`, `Menu/BF2HudManagerInit.cpp`, `Menu/BF2HudManagerUpdate.cpp` `update`, `Game/Main/BF2Engine.cpp` `renderMenu` | no mouse-mode write |
+| `Game/Objects/Game/Soldier.cpp` ctor, `onExit`, `onEnter` | `applyHapticProfile` only (no dirty flag, no zeroing) |
+| `Game/Objects/Game/Soldier.cpp` `handlePlayerInput` (Recoil, CraftPhysics) | removed |
+| `Game/Objects/Game/PlayerControlObject.cpp` `handleUpdate` (CraftPhysics) | removed |
+| `Game/Objects/Base/Camera.cpp` `handleUpdate` (ShakeForce) | removed, as in the ELF |
+| `Game/Objects/Base/FreeCamera.cpp` `handlePlayerInput` | no force zeroing |
+| `Game/Objects/Weapons/GenericFireArm.cpp`, `RecoilComponents/SoldierBasedRecoilComp.cpp`, `WeaponBasedRecoilComp.cpp` `postFire` (RecoilPunch) | removed |
+| `Game/GameLogic/GameLogicDamage.cpp` (Damage) | the look-at inputs are still computed, as in the ELF; no effect |
+| `Game/GameLogic/GameLogic.cpp` kill tail | no force zeroing |
+| `Game/Main/BF2ClientSeams.h` | no `g_hapticForceTargets` |
+| `Code/Tests/camera_shake_runtime.cpp`, `hud_lifecycle_runtime.cpp`, `client_startup_runtime.cpp`, `input_dx8_module_runtime.cpp` and the DX8 input `.cmd` checks | no Falcon expectations, no `NovintHFX.lib` |
+| `Game/Objects/Weapons/GenericFireArm.h` | no `HapticWeaponAccess` friend |
+
+The generic `IDFFalcon` lookups in `Menu/BF2HudManagerInput.cpp` (absolute pointer) and
+`Game/Main/BF2FrameInterpolator.cpp` (camera interpolation) remain. They now always find no
+device, which is the retail no-Falcon branch. The `IDFFalcon`/`IDTFalcon` enumerators, the
+`CONTROLLER_IDFFalcon` control-settings name and the control-map token stay, because retail
+control maps and profiles name them.
+
+No image imports `NovintHFX.dll`, and no build stages it (client and editor, x86 and x64).
+
+## Restoring
+
+1. Revert the commit "Archive the Novint Falcon integration" (`git revert`). Alternatively,
+ move the files above back to their original paths and add the call sites from the table.
+2. On Windows x86, restore the import library and staging in the root `CMakeLists.txt`
+ (`bf2_novint_imports`, `lib /def:NovintHFX.def /machine:x86`, the `NovintHFX.dll` copy) and
+ in `Code/Tools/BF2Editor/CMakeLists.txt`. Add `FalconDevice.cpp` back to the client source
+ list, `Code/Build/build.cmd` and `Code/Tests/syntaxcheck.cmd`.
+3. Only an x86 client can load the 32-bit DLL. For x64 or macOS, issue #17 describes the
+ way back: a 64-bit `NovintHFX` replacement on top of libnifalcon. It needs a working Falcon
+ to tune.
diff --git a/Code/Tests/falcon_device_runtime.cmd b/Code/Archive/NovintFalcon/Tests/falcon_device_runtime.cmd
similarity index 92%
rename from Code/Tests/falcon_device_runtime.cmd
rename to Code/Archive/NovintFalcon/Tests/falcon_device_runtime.cmd
index 61a3f68ed..a3b836ac7 100644
--- a/Code/Tests/falcon_device_runtime.cmd
+++ b/Code/Archive/NovintFalcon/Tests/falcon_device_runtime.cmd
@@ -15,6 +15,7 @@ if errorlevel 1 exit /b 1
link /nologo /FORCE /OPT:REF /INCREMENTAL:NO /DEBUG /SUBSYSTEM:CONSOLE /OUT:"%BF2_BUILD_OUT%\falcon_device_runtime.exe" /PDB:"%BF2_BUILD_OUT%\falcon_device_runtime.pdb" "%BF2_BUILD_OUT%\FalconDevice.obj" "%BF2_BUILD_OUT%\fixture.obj" "%BF2_BUILD_OUT%\NovintHFX.lib" user32.lib
if errorlevel 1 exit /b 1
rem Loader searches the unchanged original DLL directory through PATH; no original file is written.
-set "PATH=D:\B2BF Launcher\Battlefield2;%PATH%"
+if not defined BF2_GAME_DIR set "BF2_GAME_DIR=D:\B2BF Launcher\Battlefield2"
+set "PATH=%BF2_GAME_DIR%;%PATH%"
"%BF2_BUILD_OUT%\falcon_device_runtime.exe"
exit /b %errorlevel%
diff --git a/Code/Tests/falcon_device_runtime.cpp b/Code/Archive/NovintFalcon/Tests/falcon_device_runtime.cpp
similarity index 86%
rename from Code/Tests/falcon_device_runtime.cpp
rename to Code/Archive/NovintFalcon/Tests/falcon_device_runtime.cpp
index 0f40b5243..3cc72db46 100644
--- a/Code/Tests/falcon_device_runtime.cpp
+++ b/Code/Archive/NovintFalcon/Tests/falcon_device_runtime.cpp
@@ -11,7 +11,12 @@
#include
#include
#include
-namespace dice { namespace hfe { namespace io { IBase* inputDeviceManager = 0; } } }
+namespace dice { namespace hfe {
+// The frame update's collaborators; this fixture never reaches it (no device, update returns first).
+IBase* g_controlSettings = 0;
+IBase* g_hapticSettings = 0;
+namespace io { IBase* inputDeviceManager = 0; IBase* controlMapManager = 0; float inputSampleLatency = 0.0f; }
+} }
using namespace dice::hfe;
using namespace dice::hfe::io;
int main()
@@ -63,8 +68,8 @@ int main()
}
check(!api->getInvertAxis(static_cast(4))
&& api->getAxisScale(static_cast(4)) == 0, "greater-than-count rejection");
- api->setAxisAdd(IDA_X, 12);
- check(api->getAxisAdd(IDA_X) == 0, "recovered axis-add no-op");
+ api->setAxisAdd(IDAxis_0, 12);
+ check(api->getAxisAdd(IDAxis_0) == 0, "recovered axis-add no-op");
float x = 7, y = 9;
api->peakXYAxis(x, y);
check(x == 0 && y == 0, "inherited zero peak");
@@ -77,12 +82,12 @@ int main()
device->m_buttonLatency[31] = 0.75f;
check(api->buttonPressedSampleLatency(static_cast(0x80000001u)) == 0.25f, "lowest latency bit wins");
check(api->buttonPressedSampleLatency(static_cast(0x80000000u)) == 0.75f, "latency high bit");
- check(api->buttonPressedSampleLatency(IDB_NONE) == 0, "zero latency mask");
- InputDeviceAxes axis = IDA_Z;
+ check(api->buttonPressedSampleLatency(static_cast(0)) == 0, "zero latency mask");
+ InputDeviceAxes axis = IDAxis_2;
InputDeviceButtons button = static_cast(7);
InputDeviceKeys key = static_cast(8);
bool negative = true;
- check(!api->getNextInput(axis, button, key, negative) && axis == IDA_Z && button == 7 && key == 8 && negative,
+ check(!api->getNextInput(axis, button, key, negative) && axis == IDAxis_2 && button == 7 && key == 8 && negative,
"inactive mapping leaves outputs untouched");
device->m_active = true;
check(!api->isActive() && !api->getNextInput(axis, button, key, negative), "null device second guard");
@@ -93,6 +98,8 @@ int main()
api->addRef();
check(api->getRef() == 2 && api->release() == 1, "reference increment/decrement");
check(api->release() == 0, "real final release and destructor");
- std::printf("FalconDevice: %d checks, %d failures; native size %u\n", checks, failed, unsigned(sizeof(FalconDevice)));
- return failed != 0;
+ std::printf("falcon device runtime %d/%d checks passed (native size %u)\n", checks - failed, checks,
+ unsigned(sizeof(FalconDevice)));
+ std::fflush(stdout);
+ return failed != 0 ? 1 : 0;
}
diff --git a/Code/Archive/NovintFalcon/Tests/falcon_update_runtime.cpp b/Code/Archive/NovintFalcon/Tests/falcon_update_runtime.cpp
new file mode 100644
index 000000000..62029abe7
--- /dev/null
+++ b/Code/Archive/NovintFalcon/Tests/falcon_update_runtime.cpp
@@ -0,0 +1,1246 @@
+// [TEMP] [CHOSEN, not recovered] Mac fake-SDK check for FalconDevice::updateCurrentState
+// (BF2.exe 0x6A52A0), built as bf2_falcon_update_check. The actual FalconDevice and HapticSettings
+// run; the NovintHFX SDK, the Win32 clock, the active control map and ControlSettings are fakes
+// that record what the device asks of them. No Falcon, DLL or Windows is involved. The Windows twin
+// falcon_device_runtime.cmd links the stock NovintHFX.dll with no device connected.
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#define private public
+#include "../BF2/IO/Input/FalconDevice.h"
+#undef private
+#include "../BF2/Game/ControlSettings.h"
+#include "../BF2/Game/HapticSettings.h"
+#include "../BF2/Game/Main/BF2ClientSeams.h"
+#include "../BF2/Core/ClassManager.h"
+#include "../BF2/Core/EventManager.h"
+
+using namespace dice::hfe;
+using namespace dice::hfe::io;
+
+static unsigned checks, failures;
+static void check(bool value, const char* label)
+{
+ ++checks;
+ if (!value) { ++failures; std::printf("FAIL %s\n", label); }
+}
+static bool same(double a, double b) { return a == b || (std::isnan(a) && std::isnan(b)); }
+
+[[noreturn]] static void unsupported(const char* name)
+{
+ std::fprintf(stderr, "[TEMP] falcon_update check: %s is not modelled\n", name);
+ std::fflush(stderr);
+ std::abort();
+}
+
+// ---- Win32 clock -------------------------------------------------------------------------------
+static DWORD g_tick;
+static int g_foregroundCalls;
+extern "C" DWORD GetTickCount() { return g_tick; }
+extern "C" HWND GetForegroundWindow() { ++g_foregroundCalls; return reinterpret_cast(0x1234); }
+
+// ---- fake NovintHFX SDK ------------------------------------------------------------------------
+namespace fake {
+struct Log { std::vector calls; void add(const std::string& s) { calls.push_back(s); }
+ std::string joined() const { std::string r; for (auto& c : calls) r += c + ";"; return r; }
+ void clear() { calls.clear(); } };
+Log sdk;
+double toolPosition[3];
+int buttonData;
+int deviceCount = 1;
+int liveParams;
+struct Captured { double lower[3], upper[3], lowerStiffness[3], upperStiffness[3]; int value114; };
+std::vector updates;
+const char* createType;
+const char* createName;
+}
+
+NovintHFX::ApplicationData::mouse_settings::mouse_settings() { std::memset(m_sdkState, 0, sizeof(m_sdkState)); }
+NovintHFX::HapticsSystem::HapticsSystem() {}
+static NovintHFX::Device g_deviceObject;
+static NovintHFX::Stack* g_stack;
+extern "C" NovintHFX::HapticsSystem Haptics;
+NovintHFX::HapticsSystem Haptics;
+bool NovintHFX::HapticsSystem::AttachApplication(ApplicationData& a)
+{ fake::sdk.add(a.window == reinterpret_cast(0x1234) ? "attach foreground" : "attach other"); return true; }
+void NovintHFX::HapticsSystem::RecountConnectedDevices() { fake::sdk.add("recount"); }
+int NovintHFX::HapticsSystem::ConnectedDeviceCount() const { return fake::deviceCount; }
+bool NovintHFX::HapticsSystem::RunDevice(Device** d, int index)
+{ fake::sdk.add("run " + std::to_string(index)); *d = &g_deviceObject; return true; }
+void NovintHFX::HapticsSystem::StartMouse(Device* d) { fake::sdk.add(d == &g_deviceObject ? "startMouse device" : "startMouse other"); }
+bool NovintHFX::HapticsSystem::StopRunningDevice(Device** d) { fake::sdk.add("stop"); *d = 0; return true; }
+int NovintHFX::HapticsSystem::InputUpdate() { fake::sdk.add("systemInput"); return 0; }
+NovintHFX::Device::Device() {}
+void NovintHFX::Device::InputUpdate() { fake::sdk.add("deviceInput"); }
+void NovintHFX::Device::GetButtonData(int* down, int* pressed, int* released) const
+{ fake::sdk.add("buttons"); *down = fake::buttonData; *pressed = 0; *released = 0; }
+void NovintHFX::Device::GetToolPosition(double* const p) const
+{ p[0] = fake::toolPosition[0]; p[1] = fake::toolPosition[1]; p[2] = fake::toolPosition[2]; }
+NovintHFX::Stack* NovintHFX::Device::GetEffectStack() { fake::sdk.add("stack"); return g_stack; }
+NovintHFX::Stack::Stack() {}
+
+namespace fake { int vect3Constructions; }
+NovintHFX::Vect3::Vect3(const double& x, const double& y, const double& z)
+{ ++fake::vect3Constructions; m_unresolved[0] = x; m_unresolved[1] = y; m_unresolved[2] = z; }
+double& NovintHFX::Vect3::operator[](int i) { return m_unresolved[i]; }
+NovintHFX::Vect3& NovintHFX::Vect3::operator=(const Vect3& other)
+{
+ for (int i = 0; i < 3; ++i) m_unresolved[i] = other.m_unresolved[i];
+ return *this;
+}
+NovintHFX::Vect3 NovintHFX::Vect3::operator*(const double& scale) const
+{ return Vect3(m_unresolved[0] * scale, m_unresolved[1] * scale, m_unresolved[2] * scale); }
+NovintHFX::Vect3 NovintHFX::Vect3::Normalize() const
+{
+ const double length = std::sqrt(m_unresolved[0] * m_unresolved[0]
+ + m_unresolved[1] * m_unresolved[1] + m_unresolved[2] * m_unresolved[2]);
+ return length == 0.0 ? Vect3(0.0, 0.0, 0.0) : *this * (1.0 / length);
+}
+
+namespace fake { double lastForce[3]; }
+struct FakeEffect final : IHapticEffect {
+ int id = 0;
+ FakeEffect() { std::memset(m_unresolved04, 0, sizeof(m_unresolved04)); m_stateFlags = 0; }
+ explicit FakeEffect(int effectId) : FakeEffect() { id = effectId; }
+ void unresolvedSlot48() override { unsupported("effect slot 48"); }
+ void SetForce(const NovintHFX::Vect3& force) override
+ {
+ NovintHFX::Vect3& v = const_cast(force);
+ char line[96];
+ std::snprintf(line, sizeof(line), "force %d %g %g %g", id, v[0], v[1], v[2]);
+ fake::sdk.add(line);
+ for (int i = 0; i < 3; ++i) fake::lastForce[i] = v[i];
+ }
+ void unresolvedSlot50() override { unsupported("effect slot 50"); }
+ void SetSmoothTime(int value) override { fake::sdk.add("smooth " + std::to_string(id) + " " + std::to_string(value)); }
+ void unresolvedSlot00() override { unsupported("effect slot 00"); }
+ void unresolvedSlot04() override { unsupported("effect slot 04"); }
+ void unresolvedSlot08() override { unsupported("effect slot 08"); }
+ void unresolvedSlot0C() override { unsupported("effect slot 0C"); }
+ void unresolvedSlot10() override { unsupported("effect slot 10"); }
+ void unresolvedSlot14() override { unsupported("effect slot 14"); }
+ void unresolvedSlot18() override { unsupported("effect slot 18"); }
+ void unresolvedSlot1C() override { unsupported("effect slot 1C"); }
+ void unresolvedSlot20() override { unsupported("effect slot 20"); }
+ void unresolvedSlot24() override { unsupported("effect slot 24"); }
+ void unresolvedSlot28() override { unsupported("effect slot 28"); }
+ void unresolvedSlot2C() override { unsupported("effect slot 2C"); }
+ void unresolvedSlot30() override { unsupported("effect slot 30"); }
+ void unresolvedSlot34() override { unsupported("effect slot 34"); }
+ void unresolvedSlot38() override { unsupported("effect slot 38"); }
+ void unresolvedSlot3C() override { unsupported("effect slot 3C"); }
+ void unresolvedSlot40() override { unsupported("effect slot 40"); }
+ bool UpdateParams(IHapticEffectParam* p) override
+ {
+ auto* box = static_cast(p);
+ fake::Captured c;
+ for (int i = 0; i < 3; ++i) {
+ c.lower[i] = box->m_lower[i]; c.upper[i] = box->m_upper[i];
+ c.lowerStiffness[i] = box->m_lowerStiffness[i]; c.upperStiffness[i] = box->m_upperStiffness[i];
+ }
+ c.value114 = box->m_unresolved114;
+ fake::updates.push_back(c);
+ fake::sdk.add(std::string("update flags=") + std::to_string(m_stateFlags & 1));
+ return true;
+ }
+};
+IHapticEffect::IHapticEffect() {}
+static FakeEffect g_effect;
+namespace fake { int constantEffects; int constantParam18 = -1; std::string params18; }
+bool NovintHFX::Stack::CreateNewEffect(const char* type, IHapticEffectParam* params, const char* name, IHapticEffect** out)
+{
+ fake::createType = type; fake::createName = name;
+ fake::sdk.add(std::string("create ") + type + " " + name);
+ if (std::string(type) == "CONSTANT" || std::string(type) == "Constant") {
+ // Each CONSTANT effect is its own object (ids 10, 11, ...); the params' +0x18 is recorded.
+ static FakeEffect constants[8] = { FakeEffect(10), FakeEffect(11), FakeEffect(12), FakeEffect(13),
+ FakeEffect(14), FakeEffect(15), FakeEffect(16), FakeEffect(17) };
+ fake::constantParam18 = static_cast(params)->m_unresolved18;
+ fake::params18 += std::to_string(fake::constantParam18) + ",";
+ *out = &constants[fake::constantEffects++ % 8];
+ return true;
+ }
+ if (std::string(type) == "Envelope") {
+ // Fire-and-forget: the out pointer is null; record what the effect would be built from.
+ auto* envelope = static_cast(params);
+ char line[160];
+ std::snprintf(line, sizeof(line), "envelope %d %.17g %.17g %.17g%s", envelope->m_unresolved18,
+ envelope->m_force[0], envelope->m_force[1], envelope->m_force[2], out ? " out" : "");
+ fake::sdk.add(line);
+ return true;
+ }
+ *out = &g_effect;
+ return true;
+}
+NovintHFX::BaseEffectParams::BaseEffectParams() { std::memset(m_baseState, 0, sizeof(m_baseState)); ++fake::liveParams; }
+NovintHFX::BaseEffectParams::~BaseEffectParams() { --fake::liveParams; fake::sdk.add("params destroyed"); }
+bool NovintHFX::BaseEffectParams::RunSetCommand(char*) { unsupported("RunSetCommand"); }
+bool NovintHFX::BaseEffectParams::SetVar(const char*, const char*) { unsupported("SetVar(cc,cc)"); }
+bool NovintHFX::BaseEffectParams::CreateStandardEffect(Device*, const char*, IHapticEffect**) { unsupported("CreateStandardEffect"); }
+bool NovintHFX::BaseEffectParams::CreateStandardEffect(Stack*, const char*, IHapticEffect**) { unsupported("CreateStandardEffect"); }
+NovintHFX::ControlBoxEffectParams::ControlBoxEffectParams() throw()
+{
+ // Poison every field so the check sees exactly what updateCurrentState writes.
+ for (int i = 0; i < 3; ++i) m_lower[i] = m_upper[i] = m_lowerStiffness[i] = m_upperStiffness[i] = -777.0;
+ m_unresolved114 = -1;
+ fake::sdk.add("params constructed");
+}
+const char* NovintHFX::ControlBoxEffectParams::StandardEffectName() const { return "ControlBox"; }
+#define FAKE_VAR(sig) bool NovintHFX::ControlBoxEffectParams::sig { unsupported(#sig); }
+FAKE_VAR(SetVar(const char*, double)) FAKE_VAR(SetVar(const char*, bool)) FAKE_VAR(SetVar(const char*, float))
+FAKE_VAR(SetVar(const char*, int)) FAKE_VAR(SetVar(const char*, void*)) FAKE_VAR(SetVar(const char*, int, double))
+FAKE_VAR(SetVar(const char*, int, bool)) FAKE_VAR(SetVar(const char*, int, float)) FAKE_VAR(SetVar(const char*, int, int))
+FAKE_VAR(SetVar(const char*, int, void*)) FAKE_VAR(GetVar(const char*, float&)) FAKE_VAR(GetVar(const char*, double&))
+FAKE_VAR(GetVar(const char*, bool&)) FAKE_VAR(GetVar(const char*, int&)) FAKE_VAR(GetVar(const char*, void*))
+FAKE_VAR(GetVar(const char*, int, float&)) FAKE_VAR(GetVar(const char*, int, double&)) FAKE_VAR(GetVar(const char*, int, bool&))
+FAKE_VAR(GetVar(const char*, int, int&)) FAKE_VAR(GetVar(const char*, int, void*))
+#undef FAKE_VAR
+char NovintHFX::ControlBoxEffectParams::GetVarType(const char*, int*) const { unsupported("GetVarType"); }
+NovintHFX::ParamsStaticClass* NovintHFX::ControlBoxEffectParams::GetStaticInfoClass() { unsupported("GetStaticInfoClass"); }
+
+// [TEMP] [CHOSEN, not recovered] Unused effect fixture; SDK state is poisoned, not reconstructed.
+NovintHFX::ConstantEffectParams::ConstantEffectParams() throw()
+{
+ m_unresolved18 = m_unresolved1C = -1;
+ fake::sdk.add("constant params constructed");
+}
+const char* NovintHFX::ConstantEffectParams::StandardEffectName() const { return "Constant"; }
+#define FAKE_VAR(sig) bool NovintHFX::ConstantEffectParams::sig { unsupported(#sig); }
+FAKE_VAR(SetVar(const char*, double)) FAKE_VAR(SetVar(const char*, bool)) FAKE_VAR(SetVar(const char*, float))
+FAKE_VAR(SetVar(const char*, int)) FAKE_VAR(SetVar(const char*, void*)) FAKE_VAR(SetVar(const char*, int, double))
+FAKE_VAR(SetVar(const char*, int, bool)) FAKE_VAR(SetVar(const char*, int, float)) FAKE_VAR(SetVar(const char*, int, int))
+FAKE_VAR(SetVar(const char*, int, void*)) FAKE_VAR(GetVar(const char*, float&)) FAKE_VAR(GetVar(const char*, double&))
+FAKE_VAR(GetVar(const char*, bool&)) FAKE_VAR(GetVar(const char*, int&)) FAKE_VAR(GetVar(const char*, void*))
+FAKE_VAR(GetVar(const char*, int, float&)) FAKE_VAR(GetVar(const char*, int, double&)) FAKE_VAR(GetVar(const char*, int, bool&))
+FAKE_VAR(GetVar(const char*, int, int&)) FAKE_VAR(GetVar(const char*, int, void*))
+#undef FAKE_VAR
+char NovintHFX::ConstantEffectParams::GetVarType(const char*, int*) const { unsupported("GetVarType"); }
+NovintHFX::ParamsStaticClass* NovintHFX::ConstantEffectParams::GetStaticInfoClass() { unsupported("GetStaticInfoClass"); }
+
+// [TEMP] [CHOSEN, not recovered] Unused effect fixture; SDK state is poisoned, not reconstructed.
+NovintHFX::EnvelopeEffectParams::EnvelopeEffectParams() throw()
+{
+ m_unresolved18 = -1;
+ std::memset(m_unresolved1C, 0xCC, sizeof(m_unresolved1C));
+ for (int i = 0; i < 3; ++i) m_force[i] = -777.0;
+ fake::sdk.add("envelope params constructed");
+}
+const char* NovintHFX::EnvelopeEffectParams::StandardEffectName() const { return "Envelope"; }
+#define FAKE_VAR(sig) bool NovintHFX::EnvelopeEffectParams::sig { unsupported(#sig); }
+FAKE_VAR(SetVar(const char*, double)) FAKE_VAR(SetVar(const char*, bool)) FAKE_VAR(SetVar(const char*, float))
+FAKE_VAR(SetVar(const char*, int)) FAKE_VAR(SetVar(const char*, void*)) FAKE_VAR(SetVar(const char*, int, double))
+FAKE_VAR(SetVar(const char*, int, bool)) FAKE_VAR(SetVar(const char*, int, float)) FAKE_VAR(SetVar(const char*, int, int))
+FAKE_VAR(SetVar(const char*, int, void*)) FAKE_VAR(GetVar(const char*, float&)) FAKE_VAR(GetVar(const char*, double&))
+FAKE_VAR(GetVar(const char*, bool&)) FAKE_VAR(GetVar(const char*, int&)) FAKE_VAR(GetVar(const char*, void*))
+FAKE_VAR(GetVar(const char*, int, float&)) FAKE_VAR(GetVar(const char*, int, double&)) FAKE_VAR(GetVar(const char*, int, bool&))
+FAKE_VAR(GetVar(const char*, int, int&)) FAKE_VAR(GetVar(const char*, int, void*))
+#undef FAKE_VAR
+char NovintHFX::EnvelopeEffectParams::GetVarType(const char*, int*) const { unsupported("GetVarType"); }
+NovintHFX::ParamsStaticClass* NovintHFX::EnvelopeEffectParams::GetStaticInfoClass() { unsupported("GetStaticInfoClass"); }
+
+// ---- engine globals and fakes ------------------------------------------------------------------
+namespace dice { namespace hfe {
+ClassManager* classManager = nullptr;
+EventManager* eventManager = nullptr;
+hud::BF2HudManager* hudManager = nullptr;
+IBase* g_controlSettings = nullptr;
+IBase* g_hapticSettings = nullptr;
+namespace io {
+IBase* inputDeviceManager = nullptr;
+IBase* controlMapManager = nullptr;
+float inputSampleLatency = -1.0f;
+}
+} }
+
+struct FakeMap final : IControlMap {
+ bool invert = false;
+ float scale[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
+ int invertReads = 0, scaleReads = 0;
+ void addRef() override {}
+ int getRef() override { return 1; }
+ int release() override { return 1; }
+ void* queryInterface(unsigned int) const override { return 0; }
+ void setName(const std::string&) override { unsupported("setName"); }
+ const std::string& getName() const override { unsupported("getName"); }
+ int getID() const override { unsupported("getID"); }
+ void setID(int) override { unsupported("setID"); }
+ bool axisExists(int) const override { unsupported("axisExists"); }
+ bool triggerExists(int) const override { unsupported("triggerExists"); }
+ bool addAxisMapping(int, int, InputDeviceFlags, InputDeviceAxes, bool, bool) override { unsupported("addAxisMapping"); }
+ bool addAxisMapping(int, InputDeviceFlags, InputDeviceAxes, bool, bool) override { unsupported("addAxisMapping"); }
+ bool addAxisMapping(int, InputDeviceFlags, InputDeviceButtons, InputDeviceButtons, bool) override { unsupported("addAxisMapping"); }
+ bool addAxisMapping(int, InputDeviceFlags, InputDeviceKeys, InputDeviceKeys, bool) override { unsupported("addAxisMapping"); }
+ bool addAxisMapping(int, int, InputDeviceFlags, InputDevicePOVs, bool, bool, bool) override { unsupported("addAxisMapping"); }
+ bool addAxisMapping(int, InputDeviceFlags, InputDeviceButtons, InputDeviceFlags, InputDeviceKeys, bool) override { unsupported("addAxisMapping"); }
+ bool addAxisMapping(int, InputDeviceFlags, InputDeviceKeys, InputDeviceFlags, InputDeviceButtons, bool) override { unsupported("addAxisMapping"); }
+ bool addTriggerMapping(int, InputDeviceFlags, InputDeviceButtons, float, bool) override { unsupported("addTriggerMapping"); }
+ bool addTriggerMapping(int, InputDeviceFlags, InputDeviceKeys, float, bool) override { unsupported("addTriggerMapping"); }
+ bool addTriggerMapping(int, int, InputDeviceFlags, InputDeviceAxes, bool, float, float) override { unsupported("addTriggerMapping"); }
+ void removeMapping(unsigned int) override { unsupported("removeMapping"); }
+ void reset() override { unsupported("reset"); }
+ void reset(int, bool, bool, bool) override { unsupported("reset"); }
+ void setButtonRiseTime(float) override { unsupported("setButtonRiseTime"); }
+ void setButtonFallTime(float) override { unsupported("setButtonFallTime"); }
+ void setDoubleTapTime(float) override { unsupported("setDoubleTapTime"); }
+ float getAxisValue(int) const override { unsupported("getAxisValue"); }
+ bool isAxisValueAnalogue(int) const override { unsupported("isAxisValueAnalogue"); }
+ int getTriggerState(int) const override { unsupported("getTriggerState"); }
+ float getTriggerSampleLatency(int) const override { unsupported("getTriggerSampleLatency"); }
+ bool validate() override { unsupported("validate"); }
+ void update(float) override { unsupported("update"); }
+ void setInvertMouse(bool) override { unsupported("setInvertMouse"); }
+ bool getInvertMouse() override { ++invertReads; return invert; }
+ void setMouseSensitivity(float) override { unsupported("setMouseSensitivity"); }
+ float getMouseSensitivity() override { unsupported("getMouseSensitivity"); }
+ void setKeyboardSensitivity(float) override { unsupported("setKeyboardSensitivity"); }
+ float getKeyboardSensitivity() override { unsupported("getKeyboardSensitivity"); }
+ void setAxisScale(InputDeviceAxes, float) override { unsupported("setAxisScale"); }
+ float getAxisScale(InputDeviceAxes a) const override { ++const_cast(this)->scaleReads; return scale[a]; }
+ void setYawFactor(float) override { unsupported("setYawFactor"); }
+ void setPitchFactor(float) override { unsupported("setPitchFactor"); }
+ float getYawFactor() override { unsupported("getYawFactor"); }
+ float getPitchFactor() override { unsupported("getPitchFactor"); }
+ void save(std::ostream&, bool) override { unsupported("save"); }
+ void dump(bool) override { unsupported("dump"); }
+ bool findDuplicate(InputDeviceFlags&, InputDeviceAxes&, InputDeviceButtons&, InputDeviceKeys&,
+ DuplicateKeyVector&) override { unsupported("findDuplicate"); }
+ bool getInputMappedToMouseButton(bool, PlayerInputMap&) override { unsupported("getInputMappedToMouseButton"); }
+};
+
+struct FakeMaps final : IControlMapManager {
+ FakeMap map;
+ void addRef() override {}
+ int getRef() override { return 1; }
+ int release() override { return 1; }
+ void* queryInterface(unsigned int) const override { return 0; }
+ void update(float) override { unsupported("maps update"); }
+ IControlMap* create(const std::string&) override { unsupported("create"); }
+ IControlMap* getControlMap(const std::string&) const override { unsupported("getControlMap"); }
+ IControlMap* getControlMap(int) const override { unsupported("getControlMap"); }
+ void deleteControlMap(const std::string&) override { unsupported("deleteControlMap"); }
+ void deleteControlMap(int) override { unsupported("deleteControlMap"); }
+ void deleteControlMap(const IControlMap*) override { unsupported("deleteControlMap"); }
+ void setActive(const std::string&) override { unsupported("setActive"); }
+ void setActive(const IControlMap*) override { unsupported("setActive"); }
+ IControlMap* getActive() const override { return const_cast(&map); }
+ int mapNextInput(IControlMap*, int, bool, bool, bool, bool, std::string&) override { unsupported("mapNextInput"); }
+ float getRepeatRate(int, bool) override { unsupported("getRepeatRate"); }
+ void applyActive() override { unsupported("applyActive"); }
+};
+
+struct FakeControlSettings final : IControlSettings {
+ bool mapping = false;
+ void addRef() override {}
+ int getRef() override { return 1; }
+ int release() override { return 1; }
+ void* queryInterface(unsigned int) const override { return 0; }
+ std::string getFileName() override { unsupported("getFileName"); }
+ std::string getSettingsScript() override { unsupported("getSettingsScript"); }
+ bool restoreControlMaps() override { unsupported("restoreControlMaps"); }
+ void backupControlMaps() override { unsupported("backupControlMaps"); }
+ void backupControlMapsByName() override { unsupported("backupControlMapsByName"); }
+ bool setDefaults() override { unsupported("setDefaults"); }
+ void resetControlMaps() override { unsupported("resetControlMaps"); }
+ void updateInputDevices() override { unsupported("updateInputDevices"); }
+ int mapNextInput(int, bool, int, bool, bool) override { unsupported("mapNextInput"); }
+ bool selectControlMap(const std::string&) override { unsupported("selectControlMap"); }
+ bool getBindingDescription(io::IControlMap*, int, bool, bool, bool, std::string&, std::wstring&) override { unsupported("getBindingDescription"); }
+ std::string getActiveControlMapName() override { unsupported("getActiveControlMapName"); }
+ float getMouseSensitivity() override { unsupported("getMouseSensitivity"); }
+ void setMouseSensitivity(float) override { unsupported("setMouseSensitivity"); }
+ float getSlot48() override { unsupported("getSlot48"); }
+ void setSlot4C(float) override { unsupported("setSlot4C"); }
+ float getSlot50() override { unsupported("getSlot50"); }
+ void setSlot54(float) override { unsupported("setSlot54"); }
+ float getYawFactor() override { unsupported("getYawFactor"); }
+ void setYawFactor(float) override { unsupported("setYawFactor"); }
+ float getPitchFactor() override { unsupported("getPitchFactor"); }
+ void setPitchFactor(float) override { unsupported("setPitchFactor"); }
+ bool getInvertMouse() override { unsupported("getInvertMouse"); }
+ void setInvertMouse(bool) override { unsupported("setInvertMouse"); }
+ float getKeyboardSensitivity() override { unsupported("getKeyboardSensitivity"); }
+ void setKeyboardSensitivity(float) override { unsupported("setKeyboardSensitivity"); }
+ bool apply() override { unsupported("apply"); }
+ void deleteControlMapBackups() override { unsupported("deleteControlMapBackups"); }
+ void activateMouse() override { unsupported("activateMouse"); }
+ void deactivateMouse() override { unsupported("deactivateMouse"); }
+ bool isMappingInput() override { return mapping; }
+ void setMappingInput(bool) override { unsupported("setMappingInput"); }
+ std::string getMappedInputName() override { unsupported("getMappedInputName"); }
+};
+
+struct Nothing final : IBase {
+ void addRef() override {}
+ int getRef() override { return 1; }
+ int release() override { return 1; }
+ void* queryInterface(unsigned int) const override { return 0; }
+};
+
+// ---- helpers -----------------------------------------------------------------------------------
+static void poll(FalconDevice& d, DWORD tick, double x, double y, double z, int buttons)
+{
+ g_tick = tick;
+ fake::toolPosition[0] = x; fake::toolPosition[1] = y; fake::toolPosition[2] = z;
+ fake::buttonData = buttons;
+ d.update(0.0f);
+}
+static double fromFloat(float f) { return static_cast(f); }
+
+// ---- updateShakeForce's soldier test: the occupied object's template class id -------------------
+#include "../BF2/Core/Ids.h"
+#include "../BF2/Game/Objects/IObject.h"
+#include "../BF2/Game/Objects/IObjectTemplate.h"
+#include "../BF2/Scene/Object/ObjectTypes/Game/IPlayerControlObject.h"
+namespace {
+using namespace dice::hfe::world;
+[[noreturn]] void unexpected(const char* name) { unsupported(name); }
+struct ShakeTemplate final : IObjectTemplate {
+ unsigned int classId = 0;
+ void addRef() override { unexpected("addRef"); }
+ int getRef() override { unexpected("getRef"); }
+ int release() override { unexpected("release"); }
+ void* queryInterface(unsigned int) const override { unexpected("IObjectTemplate::queryInterface"); }
+ unsigned int getClassID() const override { return classId; }
+ void templateInitialize() override { unexpected("IObjectTemplate::templateInitialize"); }
+ bool writeBinary(io::IStream*) const override { unexpected("IObjectTemplate::writeBinary"); }
+ bool readBinary(io::IStream*) override { unexpected("IObjectTemplate::readBinary"); }
+ void setName(const std::string&) override { unexpected("IObjectTemplate::setName"); }
+ const std::string& getName() const override { unexpected("IObjectTemplate::getName"); }
+ const std::string& getCreator() const override { unexpected("IObjectTemplate::getCreator"); }
+ void setCreator(const std::string&) override { unexpected("IObjectTemplate::setCreator"); }
+ const std::string& getModifiedByUser() const override { unexpected("IObjectTemplate::getModifiedByUser"); }
+ void setModifiedByUser(const std::string&) override { unexpected("IObjectTemplate::setModifiedByUser"); }
+ void setId(unsigned int) override { unexpected("IObjectTemplate::setId"); }
+ unsigned int getId() const override { unexpected("IObjectTemplate::getId"); }
+ unsigned int getFlags() const override { unexpected("IObjectTemplate::getFlags"); }
+ unsigned int updateFlags(unsigned int set, unsigned int clear) override { unexpected("IObjectTemplate::updateFlags"); }
+ void* queryImplementation(unsigned int classId) override { unexpected("IObjectTemplate::queryImplementation"); }
+ IObject* createObject() const override { unexpected("IObjectTemplate::createObject"); }
+ void setComponent(unsigned int classId, IBase* component) override { unexpected("IObjectTemplate::setComponent"); }
+ IObjectTemplateComponent* queryComponent(unsigned int) override { unexpected("IObjectTemplate::queryComponent"); }
+ IObjectTemplateComponent* getComponentFromClassID(unsigned int) const override { unexpected("IObjectTemplate::getComponentFromClassID"); }
+ void objectCreated(IObject*) override { unexpected("IObjectTemplate::objectCreated"); }
+ void objectDestroyed(IObject*) override { unexpected("IObjectTemplate::objectDestroyed"); }
+ void preCache() const override { unexpected("IObjectTemplate::preCache"); }
+ void setCullRadiusScale(float) override { unexpected("IObjectTemplate::setCullRadiusScale"); }
+ float getCullRadiusScale() const override { unexpected("IObjectTemplate::getCullRadiusScale"); }
+ void setPhysicsComponent(IObject*) const override { unexpected("IObjectTemplate::setPhysicsComponent"); }
+ void removePhysicsComponent(IObject*) const override { unexpected("IObjectTemplate::removePhysicsComponent"); }
+ void setPhysicsNodeComponent(IObject*) const override { unexpected("IObjectTemplate::setPhysicsNodeComponent"); }
+ void removePhysicsNodeComponent(IObject*) const override { unexpected("IObjectTemplate::removePhysicsNodeComponent"); }
+ void setResponsePhysicsComponent(IObject*) const override { unexpected("IObjectTemplate::setResponsePhysicsComponent"); }
+ void removeResponsePhysicsComponent(IObject*) const override { unexpected("IObjectTemplate::removeResponsePhysicsComponent"); }
+ void setNetworkableInfo(const std::string&) override { unexpected("IObjectTemplate::setNetworkableInfo"); }
+ const std::string& getNetworkableInfo() const override { unexpected("IObjectTemplate::getNetworkableInfo"); }
+ void setCollisionMesh(const std::string&) override { unexpected("IObjectTemplate::setCollisionMesh"); }
+ const std::string& getCollisionMesh() const override { unexpected("IObjectTemplate::getCollisionMesh"); }
+ const Vec3& getAnchor() const override { unexpected("IObjectTemplate::getAnchor"); }
+ void setAnchor(const Vec3&) override { unexpected("IObjectTemplate::setAnchor"); }
+ const Vec3& getAnchorOffset() const override { unexpected("IObjectTemplate::getAnchorOffset"); }
+ void setAnchorOffset(const Vec3&) override { unexpected("IObjectTemplate::setAnchorOffset"); }
+ Vec3 getAnchorPos() const override { unexpected("IObjectTemplate::getAnchorPos"); }
+ void setIsOvergrowth(bool) override { unexpected("IObjectTemplate::setIsOvergrowth"); }
+ bool getIsOvergrowth() const override { unexpected("IObjectTemplate::getIsOvergrowth"); }
+ std::vector >* getMaterialVector() override { unexpected("IObjectTemplate::getMaterialVector"); }
+ ComponentMap* getComponentMap() override { unexpected("IObjectTemplate::getComponentMap"); }
+ void setMaterial(int) override { unexpected("IObjectTemplate::setMaterial"); }
+ int getMaterial() const override { unexpected("IObjectTemplate::getMaterial"); }
+ void setSpecialMaterials(unsigned int) override { unexpected("IObjectTemplate::setSpecialMaterials"); }
+ unsigned int getSpecialMaterials() const override { unexpected("IObjectTemplate::getSpecialMaterials"); }
+};
+struct ShakePco final : IPlayerControlObject {
+ IObject* occupied = 0;
+ void addRef() override { unexpected("addRef"); }
+ int getRef() override { unexpected("getRef"); }
+ int release() override { unexpected("release"); }
+ void* queryInterface(unsigned int iid) const override
+ {
+ if (iid != IID_IObject) unexpected("IPlayerControlObject::queryInterface(other)");
+ return occupied;
+ }
+ IPlayer* getOccupingPlayer() const override { unexpected("IPlayerControlObject::getOccupingPlayer"); }
+ IObject* getOccupingObject() const override { unexpected("IPlayerControlObject::getOccupingObject"); }
+ bool isOccupied() const override { unexpected("IPlayerControlObject::isOccupied"); }
+ bool enter(IPlayer* player) override { unexpected("IPlayerControlObject::enter"); }
+ void exit() override { unexpected("IPlayerControlObject::exit"); }
+ void exitPlayer() override { unexpected("IPlayerControlObject::exitPlayer"); }
+ void onEnter(IObject*) override { unexpected("IPlayerControlObject::onEnter"); }
+ void onExit() override { unexpected("IPlayerControlObject::onExit"); }
+ int getPcoId() const override { unexpected("IPlayerControlObject::getPcoId"); }
+ void setPcoId(int id) override { unexpected("IPlayerControlObject::setPcoId"); }
+ std::map* getCameras() override { unexpected("IPlayerControlObject::getCameras"); }
+ std::map* getOwnCameras() override { unexpected("IPlayerControlObject::getOwnCameras"); }
+ void nextCamera() override { unexpected("IPlayerControlObject::nextCamera"); }
+ ICameraObject* getActiveCamera() override { unexpected("IPlayerControlObject::getActiveCamera"); }
+ void setActiveCamera(int) override { unexpected("IPlayerControlObject::setActiveCamera"); }
+ bool getExitPosition(Vec3& out) override { unexpected("IPlayerControlObject::getExitPosition"); }
+ bool getAltExitPosition(Vec3& out) override { unexpected("IPlayerControlObject::getAltExitPosition"); }
+ void addExternalCamera(ICameraObject* camera) override { unexpected("IPlayerControlObject::addExternalCamera"); }
+ void removeExternalCamera(ICameraObject* camera) override { unexpected("IPlayerControlObject::removeExternalCamera"); }
+ bool canSpawn(const Mat4& transform) override { unexpected("IPlayerControlObject::canSpawn"); }
+ std::map* getPcos() override { unexpected("IPlayerControlObject::getPcos"); }
+ const std::vector* getPcoPosId() override { unexpected("IPlayerControlObject::getPcoPosId"); }
+ void addWeapon(IObject* weapon) override { unexpected("IPlayerControlObject::addWeapon"); }
+ void* getWeapons() override { unexpected("IPlayerControlObject::getWeapons"); }
+ IObject* getActiveWeapon(int) const override { unexpected("IPlayerControlObject::getActiveWeapon"); }
+ void* getWeapons(int) override { unexpected("IPlayerControlObject::getWeapons"); }
+ void setActiveWeapon(IObject* weapon, int) override { unexpected("IPlayerControlObject::setActiveWeapon"); }
+ void toggleOnWeaponLock(IObject*) override { unexpected("IPlayerControlObject::toggleOnWeaponLock"); }
+ int getArtPos() override { unexpected("IPlayerControlObject::getArtPos"); }
+ bool checkSpecialToggle(io::PlayerInput input) override { unexpected("IPlayerControlObject::checkSpecialToggle"); }
+ bool checkSpecialToggleLastUpdate(io::PlayerInputMap map) override { unexpected("IPlayerControlObject::checkSpecialToggleLastUpdate"); }
+ void setTeam(int team) override { unexpected("IPlayerControlObject::setTeam"); }
+ void setDefaultTeam(int team) override { unexpected("IPlayerControlObject::setDefaultTeam"); }
+ int getDefaultTeam() override { unexpected("IPlayerControlObject::getDefaultTeam"); }
+ int getTeam() override { unexpected("IPlayerControlObject::getTeam"); }
+ float getTimeToLiveUnused() override { unexpected("IPlayerControlObject::getTimeToLiveUnused"); }
+ void setTimeToLiveUnused(float t) override { unexpected("IPlayerControlObject::setTimeToLiveUnused"); }
+ bool isAllowedToExit() override { unexpected("IPlayerControlObject::isAllowedToExit"); }
+ void addPlayerInputObject(IObject*) override { unexpected("IPlayerControlObject::addPlayerInputObject"); }
+ void removePlayerInputObject(IObject*) override { unexpected("IPlayerControlObject::removePlayerInputObject"); }
+ void setTimeSpawned(float t) override { unexpected("IPlayerControlObject::setTimeSpawned"); }
+ float getTimeSpawned() const override { unexpected("IPlayerControlObject::getTimeSpawned"); }
+ void setObjectSpawnerId(int id) override { unexpected("IPlayerControlObject::setObjectSpawnerId"); }
+ int getObjectSpawnerId() const override { unexpected("IPlayerControlObject::getObjectSpawnerId"); }
+ void setObjectSpawnerHolding(bool holding) override { unexpected("IPlayerControlObject::setObjectSpawnerHolding"); }
+ bool getObjectSpawnerHolding() const override { unexpected("IPlayerControlObject::getObjectSpawnerHolding"); }
+ const Vec3& getNameTagOffset() override { unexpected("IPlayerControlObject::getNameTagOffset"); }
+ const Vec3& getRidingWithOffset() override { unexpected("IPlayerControlObject::getRidingWithOffset"); }
+ float getRidingWithDistMod() override { unexpected("IPlayerControlObject::getRidingWithDistMod"); }
+ int getVehicleCameraShake() override { unexpected("IPlayerControlObject::getVehicleCameraShake"); }
+ float getVehicleFov() override { unexpected("IPlayerControlObject::getVehicleFov"); }
+ void addVehicleMod(VehicleMod mod) override { unexpected("IPlayerControlObject::addVehicleMod"); }
+ void removeVehicleMod(VehicleMod mod) override { unexpected("IPlayerControlObject::removeVehicleMod"); }
+ int getVehicleMod(VehicleMod mod) override { unexpected("IPlayerControlObject::getVehicleMod"); }
+ const std::string& getSoundFilter() const override { unexpected("IPlayerControlObject::getSoundFilter"); }
+ int getCockpitLod() override { unexpected("IPlayerControlObject::getCockpitLod"); }
+ int getCockpitSubGeom() override { unexpected("IPlayerControlObject::getCockpitSubGeom"); }
+ float getShakeFactor() const override { unexpected("IPlayerControlObject::getShakeFactor"); }
+ bool getIsSprinting() const override { unexpected("IPlayerControlObject::getIsSprinting"); }
+ void setIsSprinting(bool) override { unexpected("IPlayerControlObject::setIsSprinting"); }
+ float getSprintStamina() const override { unexpected("IPlayerControlObject::getSprintStamina"); }
+ void setSprintStamina(float) override { unexpected("IPlayerControlObject::setSprintStamina"); }
+ void setSprintStaminaDissipationFactor(float) override { unexpected("IPlayerControlObject::setSprintStaminaDissipationFactor"); }
+ float getSprintFactor() override { unexpected("IPlayerControlObject::getSprintFactor"); }
+ bool getIsUnderwater() const override { unexpected("IPlayerControlObject::getIsUnderwater"); }
+ float getNormalizedUnderwaterTime() const override { unexpected("IPlayerControlObject::getNormalizedUnderwaterTime"); }
+ void setDriverDecalObject(IObject*) override { unexpected("IPlayerControlObject::setDriverDecalObject"); }
+ IObject* getDriverDecalObject() const override { unexpected("IPlayerControlObject::getDriverDecalObject"); }
+ void addDriverDecalTransformation(const Mat4&) override { unexpected("IPlayerControlObject::addDriverDecalTransformation"); }
+ std::vector* getDriverDecalTransformations() const override { unexpected("IPlayerControlObject::getDriverDecalTransformations"); }
+ int getSpecialToggleWeaponInput() const override { unexpected("IPlayerControlObject::getSpecialToggleWeaponInput"); }
+ void setIsDucking(bool) override { unexpected("IPlayerControlObject::setIsDucking"); }
+ bool getIsDucking() override { unexpected("IPlayerControlObject::getIsDucking"); }
+ bool getAutoUseAbility() const override { unexpected("IPlayerControlObject::getAutoUseAbility"); }
+ bool applyCameraAnimation(const Mat4& in, Mat4& out) override { unexpected("IPlayerControlObject::applyCameraAnimation"); }
+ bool allowEnterOtherVehicle() override { unexpected("IPlayerControlObject::allowEnterOtherVehicle"); }
+ bool isChildSoldierActive() const override { unexpected("IPlayerControlObject::isChildSoldierActive"); }
+ bool getNeverDrawAs1p() const override { unexpected("IPlayerControlObject::getNeverDrawAs1p"); }
+ void removeChildVehicle(IObject*) override { unexpected("IPlayerControlObject::removeChildVehicle"); }
+ int getAmmoStatus() override { unexpected("IPlayerControlObject::getAmmoStatus"); }
+ void setAmmoStatus(int) override { unexpected("IPlayerControlObject::setAmmoStatus"); }
+ void onFirstGhost() override { unexpected("IPlayerControlObject::onFirstGhost"); }
+ void setGiveUnmannedInput(bool) override { unexpected("IPlayerControlObject::setGiveUnmannedInput"); }
+ void preHandlePlayerInput(io::PlayerInput& input, float dt) const override { unexpected("IPlayerControlObject::preHandlePlayerInput"); }
+};
+// Never constructed: updateShakeForce reads only the template field (IObject::getTemplate, inline).
+struct ObjectFields : IObject {
+ static void setTemplate(IObject* o, const IObjectTemplate* t) { static_cast(o)->m_template = t; }
+};
+} // namespace
+
+int main()
+{
+ FakeMaps maps;
+ FakeControlSettings controls;
+ Nothing deviceManager;
+ io::controlMapManager = &maps;
+ io::inputDeviceManager = &deviceManager;
+ g_controlSettings = &controls;
+ HapticSettings* hapticOwner = new HapticSettings;
+ g_hapticSettings = static_cast(hapticOwner);
+ IHapticSettings* haptics = static_cast(g_hapticSettings);
+ haptics->setAimSensitivity(2.0f, 3.0f, 0.5f);
+ haptics->setAimSensitivityLength(0.25f, 0.5f, 0.125f);
+ haptics->setTurnSensitivity(4.0f, 0.75f, 1.5f);
+ haptics->setControlBoxLength(0.75f, 1.25f, 0.5f);
+ haptics->setControlBoxStiffness(100.0f, 200.0f, 300.0f);
+ static NovintHFX::Stack stackObject;
+ g_stack = &stackObject;
+
+ FalconDevice* device = new FalconDevice;
+ device->m_sampleTime = 0;
+ check(device->init() && device->m_active && device->m_device == &g_deviceObject, "fake device runs");
+ check(fake::sdk.joined() == "attach foreground;recount;run 0;startMouse device;", "init's SDK sequence");
+ check(g_falconMouseMode == 1 && g_falconControlBoxDirty, "shipped initial modes");
+ fake::sdk.clear();
+
+ // --- mouse mode: raw position, gain 1000, StartMouse once, the axis scaling -----------------
+ poll(*device, 1000, 0.5, 0.25, -0.125, 0x5); // sample clock 0 -> poll time 1000
+ poll(*device, 1010, 0.75, -0.5, 0.25, 0x2);
+ check(device->m_samples.size() == 2 && device->m_sampleTime == 1000 && device->m_pollTime == 1010,
+ "update(0) queues samples and lags the sample clock one poll");
+ maps.map.scale[0] = 2.0f; maps.map.scale[1] = 0.5f; maps.map.scale[2] = 4.0f; maps.map.scale[3] = 1.0f;
+ device->m_buttons = 0x40;
+ fake::sdk.clear();
+ device->update(0.0205f); // +20 ms (0.0205*1000 truncates)
+ check(device->m_sampleTime == 1020, "dt*1000 truncates into the sample clock");
+ check(device->m_samples.empty(), "both samples older than the clock are consumed");
+ check(device->m_previousButtons == 0x40 && device->m_buttons == 0x2, "buttons: previous frame kept, last sample wins");
+ check(fake::sdk.joined() == "startMouse device;buttons;buttons;", "StartMouse once, before the first sample's button read");
+ check(g_falconMouseMode == 2, "mode 1 becomes 2 after StartMouse");
+ check(same(device->m_axes[0], 1000.0 * 0.75 * 2.0) && same(device->m_axes[1], -(1000.0 * -0.5) * 0.5)
+ && same(device->m_axes[2], 0.0), "mouse axes: gain, negated y, the map's scale; z stays zero");
+ check(io::inputSampleLatency == 0.0f, "latency (poll time - sample time) * 0.001");
+ check(maps.map.invertReads == 4, "getInvertMouse read twice per sample (y and z)");
+ check(maps.map.scaleReads == 4, "four axis-scale reads (the fourth-axis defect)");
+
+ // --- latency of an older sample ------------------------------------------------------------
+ poll(*device, 1100, 0.0, 0.0, 0.0, 0);
+ poll(*device, 1137, 0.0, 0.0, 0.0, 0);
+ device->m_samples.pop_back(); // keep only the 1100 sample, polled at 1137
+ device->update(0.2f);
+ check(io::inputSampleLatency == static_cast(37.0 * static_cast(0.001f)), "latency 37 ms");
+
+ // --- control-box mode: rebuild on mode 0, params from HapticSettings, effect created once --
+ maps.map.scale[0] = maps.map.scale[1] = maps.map.scale[2] = 1.0f;
+ g_falconMouseMode = 0;
+ g_effect.m_stateFlags = 0;
+ fake::sdk.clear();
+ poll(*device, 2000, 0.1, 0.1, 0.1, 0); // inside every dead zone
+ fake::sdk.clear();
+ device->update(1.0f);
+ check(g_falconMouseMode == -1 && !g_falconControlBoxDirty, "mode 0 becomes -1 and clears the flag");
+ check(fake::sdk.joined() == "params constructed;stack;create BOX ControlBox;update flags=0;params destroyed;buttons;",
+ "rebuild: construct, create once, update, delete");
+ check(fake::liveParams == 0, "params deleted through the virtual destructor");
+ check(fake::updates.size() == 1, "one parameter update");
+ const fake::Captured& c = fake::updates.back();
+ check(same(c.lower[0], -fromFloat(0.75f)) && same(c.lower[1], -fromFloat(1.25f))
+ && same(c.lower[2], -fromFloat(0.5f) - fromFloat(0.01f)), "lower walls: -length, z 0.01 lower");
+ check(same(c.upper[0], fromFloat(0.75f)) && same(c.upper[1], fromFloat(1.25f))
+ && same(c.upper[2], fromFloat(0.5f) - fromFloat(0.01f)), "upper walls: length, z 0.01 lower");
+ check(c.lowerStiffness[0] == 100.0 && c.lowerStiffness[1] == 200.0 && c.lowerStiffness[2] == 300.0
+ && c.upperStiffness[0] == 100.0 && c.upperStiffness[2] == 300.0, "stiffness both sides");
+ check(c.value114 == 3000, "+0x114 = 3000");
+
+ // --- no rebuild without the flag; the flag forces one; the effect is not created again -----
+ fake::sdk.clear();
+ poll(*device, 2100, 0.1, 0.1, 0.1, 0);
+ fake::sdk.clear();
+ device->update(1.0f);
+ check(fake::sdk.joined() == "buttons;", "no rebuild while mode -1 and clean");
+ g_falconControlBoxDirty = true;
+ g_effect.m_stateFlags = 1;
+ poll(*device, 2200, 0.1, 0.1, 0.1, 0);
+ fake::sdk.clear();
+ device->update(1.0f);
+ check(fake::sdk.joined() == "params constructed;update flags=1;params destroyed;buttons;",
+ "the flag rebuilds into the existing effect");
+ check(g_effect.m_stateFlags == 0, "rebuild clears the suspended bit");
+
+ // --- back to mouse mode: StartMouse and the suspended bit ----------------------------------
+ g_falconMouseMode = 1;
+ poll(*device, 2300, 0.1, 0.1, 0.1, 0);
+ fake::sdk.clear();
+ device->update(1.0f);
+ check(fake::sdk.joined() == "startMouse device;buttons;" && g_effect.m_stateFlags == 1 && g_falconMouseMode == 2,
+ "entering mouse mode suspends the existing control-box effect");
+ g_falconMouseMode = -1;
+
+ // --- dead zones, turn sensitivity and the smoothed deltas -----------------------------------
+ // The smoothing history is already full (count == window); feed positions and check the axes.
+ // Each delta is (newest - oldest) / (2 * window) over aim-scaled positions.
+ std::vector hx, hy, hz; // model of the three histories after the earlier samples
+ // Rebuild the model by replaying: earlier samples were (0.5,.25,-.125),(0.75,-.5,.25),(0,0,0),
+ // then (0.1,0.1,0.1) x4; the first three were pushed raw, the rest aim-scaled with a pop.
+ hx = { 0.5, 0.75, 0.0 }; hy = { 0.25, -0.5, 0.0 }; hz = { -0.125, 0.25, 0.0 };
+ auto step = [](std::vector& h, double v) { h.push_back(v); h.erase(h.begin()); return (h.back() - h.front()) / 6.0; };
+ for (int i = 0; i < 4; ++i) { step(hx, 0.1 * 2.0f); step(hy, 0.1 * 3.0f); step(hz, 0.1 * 0.5f); }
+ struct Case { double x, y, z; const char* label; };
+ const Case cases[] = {
+ { 0.5, 0.75, 0.5, "beyond the upper dead-zone edge" },
+ { -0.5, -0.75, -0.5, "beyond the lower dead-zone edge" },
+ { 0.2, 0.25, 0.1, "inside the dead zone: smoothed delta" },
+ { std::numeric_limits::quiet_NaN(), 0.0, 0.0, "NaN takes the delta path" },
+ };
+ for (const Case& k : cases) {
+ poll(*device, g_tick + 100, k.x, k.y, k.z, 0);
+ device->update(1.0f);
+ const double dX = step(hx, k.x * 2.0f), dY = step(hy, k.y * 3.0f), dZ = step(hz, k.z * 0.5f);
+ auto expect = [](double p, float dz, float turn, double scale, double delta, double deltaScale) {
+ if (dz < p) return (p - dz) * turn * scale;
+ if (-dz > p) return (dz + p) * turn * scale;
+ return delta * deltaScale;
+ };
+ const double ex = expect(k.x, 0.25f, 4.0f, 2000.0, dX, 2500.0);
+ const double ey = expect(k.y, 0.5f, 0.75f, -2000.0, dY, -2500.0);
+ const double ez = expect(k.z, 0.125f, 1.5f, -2000.0, dZ, -2500.0);
+ check(same(device->m_axes[0], ex) && same(device->m_axes[1], ey) && same(device->m_axes[2], ez), k.label);
+ }
+
+ // --- inverted mouse negates y and z before everything ---------------------------------------
+ maps.map.invert = true;
+ poll(*device, g_tick + 100, 0.5, 0.75, 0.5, 0);
+ device->update(1.0f);
+ {
+ const double dX = step(hx, 0.5 * 2.0f), dY = step(hy, -0.75 * 3.0f), dZ = step(hz, -0.5 * 0.5f);
+ (void) dX; (void) dY; (void) dZ;
+ check(same(device->m_axes[1], (-0.75 + 0.5f) * 0.75f * -2000.0)
+ && same(device->m_axes[2], (-0.5 + 0.125f) * 1.5f * -2000.0), "inverted y and z");
+ }
+ maps.map.invert = false;
+
+ // --- binding capture ends the frame early ---------------------------------------------------
+ controls.mapping = true;
+ device->m_buttons = 0x9;
+ maps.map.scale[0] = 3.0f;
+ poll(*device, g_tick + 100, 0.5, 0.5, 0.5, 0x4);
+ const int scaleReadsBefore = maps.map.scaleReads;
+ fake::sdk.clear();
+ device->update(1.0f);
+ check(device->m_samples.size() == 1, "capture: the sample stays queued");
+ check(device->m_buttons == 0x9 && device->m_previousButtons == 0x9, "capture: no button read");
+ check(device->m_axes[0] == 0.0 && device->m_axes[1] == 0.0 && device->m_axes[2] == 0.0, "capture: axes zeroed only");
+ check(maps.map.scaleReads == scaleReadsBefore && fake::sdk.calls.empty(), "capture: no scaling, no SDK call");
+ controls.mapping = false;
+ device->m_samples.clear();
+ maps.map.scale[0] = 1.0f;
+
+ // --- the fourth-axis defect: m_axisTravel[0..1] scaled as a double ---------------------------
+ {
+ const double bits = 1.5;
+ std::memcpy(device->m_axisTravel, &bits, sizeof(bits));
+ device->m_axisTravel[2] = 7;
+ maps.map.scale[3] = 2.0f;
+ device->update(1.0f); // empty queue: only the scaling runs
+ double after;
+ std::memcpy(&after, device->m_axisTravel, sizeof(after));
+ check(after == 3.0 && device->m_axisTravel[2] == 7, "fourth scale lands on m_axisTravel[0..1] only");
+ maps.map.scale[3] = 1.0f;
+ std::memset(device->m_axisTravel, 0, sizeof(device->m_axisTravel));
+ }
+
+ // --- empty queue: axes reset, scaling only ------------------------------------------------
+ device->m_axes[0] = 5.0;
+ device->update(1.0f);
+ check(device->m_axes[0] == 0.0 && device->m_axes[1] == 0.0, "every frame starts from zero axes");
+
+ // --- MainMenuLogic's zeroing of the haptic force effects (0x4A3490..0x4A3535) ---------------
+ {
+ fake::sdk.clear();
+ fake::vect3Constructions = 0;
+ io::zeroHapticForceTargets();
+ check(fake::sdk.calls.empty() && fake::vect3Constructions == 1, "no effects: one zero vector, no call");
+ static FakeEffect targets[6] = { FakeEffect(0), FakeEffect(1), FakeEffect(2), FakeEffect(3), FakeEffect(4), FakeEffect(5) };
+ for (int i = 0; i < 6; ++i) g_hapticForceTargets[i] = &targets[i];
+ g_hapticForceTargets[3] = 0; // ds:0x9EBF04 absent
+ fake::sdk.clear();
+ fake::vect3Constructions = 0;
+ io::zeroHapticForceTargets();
+ check(fake::sdk.joined() == "force 2 0 0 0;force 4 0 0 0;force 5 0 0 0;force 0 0 0 0;force 1 0 0 0;",
+ "zero force in retail order 0x9EBF00..0x9EBF0C, 0x9EBEC8, 0x9EBECC; nulls skipped");
+ check(fake::vect3Constructions == 1, "one Vect3 shared by every call");
+ for (int i = 0; i < 6; ++i) g_hapticForceTargets[i] = 0;
+ }
+
+ // --- Camera::handleUpdate's Novint ShakeForce block (0x5A3F4F..0x5A41D7, ledger N2 17b) --------
+ {
+ ShakeTemplate vehicleTemplate, soldierTemplate;
+ vehicleTemplate.classId = 1;
+ soldierTemplate.classId = CID_SoldierTemplate;
+ alignas(16) static unsigned char occupiedStorage[sizeof(IObject)];
+ IObject* occupied = reinterpret_cast(occupiedStorage);
+ ObjectFields::setTemplate(occupied, &vehicleTemplate);
+ ShakePco pco;
+ pco.occupied = occupied;
+ haptics->setExplosionShakeScale(2.0f);
+ haptics->setSpeedShakeScale(3.0f);
+ haptics->setGeneralShakeScale(0.5f);
+ haptics->setUnresolved48C(0.25f);
+ haptics->setUnresolved490(0.75f);
+ haptics->setForceCapX(10.0f);
+ haptics->setForceCapY(10.0f);
+
+ NovintHFX::Device* const saved = io::g_falconDevice;
+ io::g_falconDevice = 0;
+ fake::sdk.clear();
+ io::updateShakeForce(&pco, 0.1f, 0.2f, 0.4f, 0.8f);
+ check(fake::sdk.calls.empty() && !g_hapticForceTargets[0], "shake force: no device, nothing");
+ io::g_falconDevice = saved;
+ check(io::g_falconDevice != 0, "shake force: the fake device is the current one");
+
+ fake::sdk.clear();
+ fake::constantEffects = 0;
+ io::updateShakeForce(&pco, 0.1f, 0.2f, 0.4f, 0.8f);
+ check(fake::sdk.joined() == "constant params constructed;stack;create CONSTANT ShakeForce;stack;create CONSTANT ShakeForce;params destroyed;",
+ "shake force: first call creates the two CONSTANT ShakeForce effects from one params, then deletes it");
+ check(fake::constantParam18 == 0x14 && g_hapticForceTargets[0] && g_hapticForceTargets[1]
+ && g_hapticForceTargets[0] != g_hapticForceTargets[1], "shake force: params +0x18 = 20; two effects stored");
+
+ fake::sdk.clear();
+ io::updateShakeForce(&pco, 0.1f, 0.2f, 0.4f, 0.8f);
+ // x = 2*0.1 + 3*0.2 + 0.5*0.4 + 0.25*0.8 = 1.2; y = 2*0.1 + 3*0.2 + 0.5*0.4 + 0.75*0.8 = 1.6
+ check(fake::sdk.joined() == "force 10 1.2 1.6 0;", "shake force: the vehicle effect gets (x, y, 0) from the scaled terms");
+
+ ObjectFields::setTemplate(occupied, &soldierTemplate);
+ haptics->setForceCapX(1.0f);
+ haptics->setForceCapY(1.6f);
+ fake::sdk.clear();
+ io::updateShakeForce(&pco, 0.1f, 0.2f, 0.4f, 0.8f);
+ check(fake::sdk.joined() == "force 11 1 1.6 0;", "shake force: the soldier effect; x capped at 1");
+ {
+ // y = 1.000000x (float) + 0.75 * 0.8f in double: |y| rounds to 1.6f, the cap, so it is not
+ // above it and keeps its unrounded value (a clamp would store 1.6f itself).
+ const float shared = 2.0f * 0.1f + 3.0f * 0.2f + 0.5f * 0.4f;
+ const double expectedY = static_cast(0.75f) * 0.8f + shared;
+ check(static_cast(expectedY) == 1.6f && expectedY != static_cast(1.6f)
+ && fake::lastForce[1] == expectedY, "shake force: y equal to its cap at float precision is not clamped");
+ }
+ haptics->setForceCapY(1.5f);
+ fake::sdk.clear();
+ io::updateShakeForce(&pco, -0.1f, -0.2f, -0.4f, -0.8f);
+ check(fake::sdk.joined() == "force 11 -1 -1.5 0;", "shake force: both caps keep the sign");
+ // At cap 0 a -0 term is not above it and keeps its sign; a clamp would store sign(-0) * 0 = +0.
+ haptics->setForceCapX(0.0f);
+ haptics->setForceCapY(0.0f);
+ fake::sdk.clear();
+ io::updateShakeForce(&pco, -0.0f, -0.0f, -0.0f, -0.0f);
+ check(fake::sdk.joined() == "force 11 -0 -0 0;", "shake force: -0 at a zero cap is left alone");
+ // A negative cap is below every |v|: a zero term becomes sign(0) * cap = 0 * -1 = -0.
+ haptics->setForceCapX(-1.0f);
+ haptics->setForceCapY(-1.0f);
+ fake::sdk.clear();
+ io::updateShakeForce(&pco, 0.0f, 0.0f, 0.0f, 0.0f);
+ check(fake::sdk.joined() == "force 11 -0 -0 0;", "shake force: a negative cap clamps a zero term with sign 0");
+ for (int i = 0; i < 6; ++i) g_hapticForceTargets[i] = 0;
+ }
+
+ // --- Soldier::handlePlayerInput's Novint "Recoil" block (0x5AE335..0x5AE72B, ledger N2 17b) -----
+ {
+ NovintHFX::Device* const saved = io::g_falconDevice;
+ io::g_falconDevice = 0;
+ check(!io::hapticDeviceConnected(), "recoil force: no device, not connected");
+ io::g_falconDevice = saved;
+ check(io::hapticDeviceConnected(), "recoil force: the fake device is connected");
+
+ fake::sdk.clear();
+ fake::constantEffects = 0;
+ fake::constantParam18 = -1;
+ io::updateRecoilForce(0.0f, 0.0f, 0);
+ check(fake::sdk.joined() == "constant params constructed;stack;create Constant Recoil;params destroyed;force 10 0 0 0;",
+ "recoil force: first call creates the Constant \"Recoil\" effect, then sets a zero force");
+ check(fake::constantParam18 == 10 && g_hapticForceTargets[2], "recoil force: params +0x18 = 10, stored at 0x9EBF00");
+
+ // Distinct scales per weapon type: yaw (t + 1) / 4, pitch (t + 1) / 8.
+ typedef void (IHapticSettings::*Setter)(float);
+ const Setter yawSetters[13] = {
+ &IHapticSettings::setRecoilYawScaleRIFLE, &IHapticSettings::setRecoilYawScaleRIFLELAUNCHER,
+ &IHapticSettings::setRecoilYawScaleCARBINE, &IHapticSettings::setRecoilYawScaleLMG,
+ &IHapticSettings::setRecoilYawScaleSNIPER, &IHapticSettings::setRecoilYawScalePISTOL,
+ &IHapticSettings::setRecoilYawScaleLAUNCHER, &IHapticSettings::setRecoilYawScaleSMG,
+ &IHapticSettings::setRecoilYawScaleSHOTGUN, &IHapticSettings::setRecoilYawScaleKNIFE,
+ &IHapticSettings::setRecoilYawScaleDROP, &IHapticSettings::setRecoilYawScaleTHROWN,
+ &IHapticSettings::setRecoilYawScaleDEFIB };
+ const Setter pitchSetters[13] = {
+ &IHapticSettings::setRecoilPitchScaleRIFLE, &IHapticSettings::setRecoilPitchScaleRIFLELAUNCHER,
+ &IHapticSettings::setRecoilPitchScaleCARBINE, &IHapticSettings::setRecoilPitchScaleLMG,
+ &IHapticSettings::setRecoilPitchScaleSNIPER, &IHapticSettings::setRecoilPitchScalePISTOL,
+ &IHapticSettings::setRecoilPitchScaleLAUNCHER, &IHapticSettings::setRecoilPitchScaleSMG,
+ &IHapticSettings::setRecoilPitchScaleSHOTGUN, &IHapticSettings::setRecoilPitchScaleKNIFE,
+ &IHapticSettings::setRecoilPitchScaleDROP, &IHapticSettings::setRecoilPitchScaleTHROWN,
+ &IHapticSettings::setRecoilPitchScaleDEFIB };
+ for (int t = 0; t < 13; ++t) {
+ (haptics->*yawSetters[t])((t + 1) / 4.0f);
+ (haptics->*pitchSetters[t])((t + 1) / 8.0f);
+ }
+ haptics->setForceCapX(100.0f);
+ haptics->setForceCapY(100.0f);
+
+ fake::sdk.clear();
+ io::updateRecoilForce(0.0f, 0.0f, 3);
+ check(fake::sdk.joined() == "force 10 0 0 0;", "recoil force: created once; both zero gives a zero force");
+
+ bool everyType = true;
+ for (int t = 0; t < 13; ++t) {
+ fake::sdk.clear();
+ io::updateRecoilForce(2.0f, 4.0f, t);
+ const double ex = (t + 1) / 4.0 * 2.0, ey = -((t + 1) / 8.0 * 4.0);
+ everyType = everyType && fake::sdk.calls.size() == 1
+ && fake::lastForce[0] == ex && fake::lastForce[1] == ey && fake::lastForce[2] == 0.0;
+ }
+ check(everyType, "recoil force: weapon types 0..12 select their own yaw and (negated) pitch scale");
+ fake::sdk.clear();
+ io::updateRecoilForce(2.0f, 4.0f, 13);
+ io::updateRecoilForce(2.0f, 4.0f, -1);
+ check(fake::sdk.joined() == "force 10 0 -0 0;force 10 0 -0 0;", "recoil force: other weapon types scale by 0");
+
+ fake::sdk.clear();
+ io::updateRecoilForce(0.5f, 0.0f, 0); // RIFLE: 0.25 / 0.125
+ io::updateRecoilForce(0.0f, 0.5f, 0);
+ check(fake::sdk.joined() == "force 10 0.125 -0 0;force 10 0 -0.0625 0;", "recoil force: either value alone is enough");
+
+ haptics->setForceCapX(1.5f);
+ haptics->setForceCapY(3.0f);
+ fake::sdk.clear();
+ io::updateRecoilForce(2.0f, 3.0f, 0);
+ io::updateRecoilForce(-2.0f, -4.0f, 0);
+ check(fake::sdk.joined() == "force 10 0.375 -0.375 0;force 10 -0.375 0.375 0;",
+ "recoil force: each value capped with its sign; equal to the cap stays");
+ haptics->setForceCapX(-1.0f);
+ fake::sdk.clear();
+ io::updateRecoilForce(0.0f, 1.0f, 0);
+ check(fake::sdk.joined() == "force 10 -0 -0.125 0;", "recoil force: a negative cap clamps a zero term with sign 0");
+ // At cap 0 a -0 pitch is not above it and keeps its sign: -(0.125 * -0) = +0 (a clamp: -0).
+ haptics->setForceCapX(100.0f);
+ haptics->setForceCapY(0.0f);
+ fake::sdk.clear();
+ io::updateRecoilForce(1.0f, -0.0f, 0);
+ check(fake::sdk.joined() == "force 10 0.25 0 0;", "recoil force: -0 pitch at a zero cap is left alone");
+ for (int i = 0; i < 6; ++i) g_hapticForceTargets[i] = 0;
+ }
+
+ // --- Soldier::handlePlayerInput's Novint "CraftPhysics" block (0x5AECE8..0x5AF3F6, ledger N2 17b) --
+ {
+ haptics->setPhysicsSOLDIERScale(2.0f, 3.0f, 4.0f);
+ haptics->setPhysicsSOLDIERScaleXLow(0.5f); haptics->setPhysicsSOLDIERScaleYLow(0.25f); haptics->setPhysicsSOLDIERScaleZLow(0.125f);
+ haptics->setPhysicsSOLDIERScaleXMed(5.0f); haptics->setPhysicsSOLDIERScaleYMed(6.0f); haptics->setPhysicsSOLDIERScaleZMed(7.0f);
+ haptics->setPhysicsSOLDIERScaleXHigh(10.0f); haptics->setPhysicsSOLDIERScaleYHigh(20.0f); haptics->setPhysicsSOLDIERScaleZHigh(30.0f);
+ haptics->setPhysicsSOLDIERTransitionValueMed(1.0f);
+ haptics->setPhysicsSOLDIERTransitionValueHigh(10.0f);
+ haptics->setPhysicsSOLDIERSmoothTimeXLow(11); haptics->setPhysicsSOLDIERSmoothTimeYLow(12); haptics->setPhysicsSOLDIERSmoothTimeZLow(13);
+ haptics->setPhysicsSOLDIERSmoothTimeXMed(97); haptics->setPhysicsSOLDIERSmoothTimeYMed(97); haptics->setPhysicsSOLDIERSmoothTimeZMed(97);
+ haptics->setPhysicsSOLDIERSmoothTimeXHigh(98); haptics->setPhysicsSOLDIERSmoothTimeYHigh(98); haptics->setPhysicsSOLDIERSmoothTimeZHigh(98);
+ haptics->setForceCapX(1000.0f); haptics->setForceCapY(1000.0f); haptics->setForceCapZ(1000.0f);
+ auto v3 = [](float x, float y, float z) { Vec3 v; v.x = x; v.y = y; v.z = z; return v; };
+
+ fake::sdk.clear();
+ fake::constantEffects = 0;
+ fake::params18.clear();
+ io::updateSoldierCraftPhysicsForce(v3(0, 0, 0), 0.1f);
+ check(fake::sdk.joined() ==
+ "constant params constructed;stack;create Constant CraftPhysicsX;params destroyed;"
+ "constant params constructed;stack;create Constant CraftPhysicsY;params destroyed;"
+ "constant params constructed;stack;create Constant CraftPhysicsZ;params destroyed;"
+ "smooth 10 11;force 10 -0 0 0;smooth 11 12;force 11 0 -0 0;smooth 12 13;force 12 0 0 0;",
+ "craft physics: the three Constant effects are created once, then each gets its smooth time and axis");
+ check(fake::params18 == "11,12,13," && g_hapticForceTargets[3] && g_hapticForceTargets[4] && g_hapticForceTargets[5],
+ "craft physics: params +0x18 = the X/Y/Z Low smooth times; stored at 0x9EBF04/08/0C");
+ fake::sdk.clear();
+ io::updateSoldierCraftPhysicsForce(v3(1, 0, 0), 0.2f);
+ io::updateSoldierCraftPhysicsForce(v3(2, 0, 0), 0.25f);
+ const std::string zeroTick = "smooth 10 11;force 10 -0 0 0;smooth 11 12;force 11 0 -0 0;smooth 12 13;force 12 0 0 0;";
+ check(fake::sdk.joined() == zeroTick + zeroTick, "craft physics: no acceleration until three samples are held");
+
+ // History (1,0,0) (2,0,0) (4,8,-2); span 0.25 + 0.25: a = (oldest - newest) * 2 = (-6, -16, 4),
+ // |a| = 17.5 >= 10: High scales (20, 60, 120); Low smooth times still.
+ fake::sdk.clear();
+ io::updateSoldierCraftPhysicsForce(v3(4, 8, -2), 0.25f);
+ check(fake::sdk.joined() == "smooth 10 11;force 10 120 0 0;smooth 11 12;force 11 0 960 0;smooth 12 13;force 12 0 0 480;",
+ "craft physics: oldest minus newest over the last two tick times; High band; -x, -y, +z");
+ // (2,0,0) (4,8,-2) (2.5,1,0): a = (-1, -2, 0), |a| = 2.24: Med scales (10, 18, 28).
+ fake::sdk.clear();
+ io::updateSoldierCraftPhysicsForce(v3(2.5f, 1, 0), 0.25f);
+ check(fake::sdk.joined() == "smooth 10 11;force 10 10 0 0;smooth 11 12;force 11 0 36 0;smooth 12 13;force 12 0 0 0;",
+ "craft physics: Med band");
+ // (4,8,-2) (2.5,1,0) (4,8.25,-2): a = (0, -0.5, 0), |a| = 0.5: Low scales (1, 0.75, 0.5).
+ fake::sdk.clear();
+ io::updateSoldierCraftPhysicsForce(v3(4, 8.25f, -2), 0.25f);
+ check(fake::sdk.joined() == "smooth 10 11;force 10 -0 0 0;smooth 11 12;force 11 0 0.375 0;smooth 12 13;force 12 0 0 0;",
+ "craft physics: Low band");
+ // (2.5,1,0) (4,8.25,-2) (2.5,1.5,0): a = (0, -1, 0), |a| = 1 = Med's value: Med.
+ fake::sdk.clear();
+ io::updateSoldierCraftPhysicsForce(v3(2.5f, 1.5f, 0), 0.25f);
+ check(fake::sdk.joined() == "smooth 10 11;force 10 -0 0 0;smooth 11 12;force 11 0 18 0;smooth 12 13;force 12 0 0 0;",
+ "craft physics: a length equal to the Med value is Med");
+ // (4,8.25,-2) (2.5,1.5,0) (0,0,10): a = (8, 16.5, -24), High; capped to (5, 10, -20) with sign.
+ haptics->setForceCapX(5.0f); haptics->setForceCapY(10.0f); haptics->setForceCapZ(20.0f);
+ fake::sdk.clear();
+ io::updateSoldierCraftPhysicsForce(v3(0, 0, 10), 0.25f);
+ check(fake::sdk.joined() == "smooth 10 11;force 10 -100 0 0;smooth 11 12;force 11 0 -600 0;smooth 12 13;force 12 0 0 -2400;",
+ "craft physics: each acceleration component capped with its sign");
+ // (2.5,1.5,0) (0,0,10) (2.5,-3.5,0): a = (0, 10, 0), |a| = 10 = High's value: High (60); y equal
+ // to its cap is kept.
+ fake::sdk.clear();
+ io::updateSoldierCraftPhysicsForce(v3(2.5f, -3.5f, 0), 0.25f);
+ check(fake::sdk.joined() == "smooth 10 11;force 10 -0 0 0;smooth 11 12;force 11 0 -600 0;smooth 12 13;force 12 0 0 0;",
+ "craft physics: a length equal to the High value is High; a component equal to its cap is kept");
+ // (0,0,9) (0,0,5) (0,0,0) over 0.05 + 0.1: 1 / 0.15 stays unrounded for z (0x5A6370), so
+ // a.z = 59.999996f, not the 60 a rounded reciprocal gives; High: z force 120 * a.z.
+ haptics->setForceCapX(1e6f); haptics->setForceCapY(1e6f); haptics->setForceCapZ(1e6f);
+ io::updateSoldierCraftPhysicsForce(v3(0, 0, 9), 0.25f);
+ io::updateSoldierCraftPhysicsForce(v3(0, 0, 5), 0.05f);
+ io::updateSoldierCraftPhysicsForce(v3(0, 0, 0), 0.1f);
+ const float span = 0.05f + 0.1f;
+ const float unrounded = static_cast((1.0 / span) * 9.0f);
+ check(unrounded != static_cast(1.0 / span) * 9.0f && fake::lastForce[2] == 120.0 * unrounded,
+ "craft physics: z uses the unrounded reciprocal of the span");
+ // (0,0,5) (0,0,0) (0,0,4.8) over 0.1 + 0.25: a.z = 0.2 / 0.35, Low: z force 0.5 * a.z.
+ io::updateSoldierCraftPhysicsForce(v3(0, 0, 4.8f), 0.25f);
+ check(std::fabs(fake::lastForce[2] - 0.5 * (0.2 / 0.35)) < 1e-5, "craft physics: Low band z scale");
+ // (0,-0,0) (0,0,4.8) (0,0,0): a.y = -0; at cap 0 it is not above it and keeps its sign, so
+ // the y force is -(0.75 * -0) = +0 (a clamp would store sign(-0) * 0 = +0, giving -0).
+ io::updateSoldierCraftPhysicsForce(v3(0, -0.0f, 0), 0.25f);
+ io::updateSoldierCraftPhysicsForce(v3(0, 0, 4.8f), 0.25f);
+ haptics->setForceCapY(0.0f);
+ fake::sdk.clear();
+ io::updateSoldierCraftPhysicsForce(v3(0, 0, 0), 0.25f);
+ check(fake::sdk.joined() == "smooth 10 11;force 10 -0 0 0;smooth 11 12;force 11 0 0 0;smooth 12 13;force 12 0 0 0;",
+ "craft physics: -0 at a zero cap is left alone");
+ for (int i = 0; i < 6; ++i) g_hapticForceTargets[i] = 0;
+ }
+
+ // --- PlayerControlObject::handleUpdate's CraftPhysics (0x5FADAE..0x5FBCD8): categories, band smooth times --
+ {
+ auto v3 = [](float x, float y, float z) { Vec3 v; v.x = x; v.y = y; v.z = z; return v; };
+ // c = 0 LAND, 1 SEA, 2 AIR, 3 HELI: Z scale (c+1) / (c+1)*10 / (c+1)*100, smooth (c+1)*100 + 1..9.
+ haptics->setPhysicsLANDScale(1.0f, 1.0f, 1.0f);
+ haptics->setPhysicsLANDScaleXLow(1.0f); haptics->setPhysicsLANDScaleYLow(1.0f); haptics->setPhysicsLANDScaleZLow(1.0f);
+ haptics->setPhysicsLANDScaleXMed(1.0f); haptics->setPhysicsLANDScaleYMed(1.0f); haptics->setPhysicsLANDScaleZMed(10.0f);
+ haptics->setPhysicsLANDScaleXHigh(1.0f); haptics->setPhysicsLANDScaleYHigh(1.0f); haptics->setPhysicsLANDScaleZHigh(100.0f);
+ haptics->setPhysicsLANDTransitionValueMed(1.0f); haptics->setPhysicsLANDTransitionValueHigh(10.0f);
+ haptics->setPhysicsLANDSmoothTimeXLow(101); haptics->setPhysicsLANDSmoothTimeYLow(102); haptics->setPhysicsLANDSmoothTimeZLow(103);
+ haptics->setPhysicsLANDSmoothTimeXMed(104); haptics->setPhysicsLANDSmoothTimeYMed(105); haptics->setPhysicsLANDSmoothTimeZMed(106);
+ haptics->setPhysicsLANDSmoothTimeXHigh(107); haptics->setPhysicsLANDSmoothTimeYHigh(108); haptics->setPhysicsLANDSmoothTimeZHigh(109);
+ haptics->setPhysicsSEAScale(1.0f, 1.0f, 1.0f);
+ haptics->setPhysicsSEAScaleXLow(1.0f); haptics->setPhysicsSEAScaleYLow(1.0f); haptics->setPhysicsSEAScaleZLow(2.0f);
+ haptics->setPhysicsSEAScaleXMed(1.0f); haptics->setPhysicsSEAScaleYMed(1.0f); haptics->setPhysicsSEAScaleZMed(20.0f);
+ haptics->setPhysicsSEAScaleXHigh(1.0f); haptics->setPhysicsSEAScaleYHigh(1.0f); haptics->setPhysicsSEAScaleZHigh(200.0f);
+ haptics->setPhysicsSEATransitionValueMed(1.0f); haptics->setPhysicsSEATransitionValueHigh(10.0f);
+ haptics->setPhysicsSEASmoothTimeXLow(201); haptics->setPhysicsSEASmoothTimeYLow(202); haptics->setPhysicsSEASmoothTimeZLow(203);
+ haptics->setPhysicsSEASmoothTimeXMed(204); haptics->setPhysicsSEASmoothTimeYMed(205); haptics->setPhysicsSEASmoothTimeZMed(206);
+ haptics->setPhysicsSEASmoothTimeXHigh(207); haptics->setPhysicsSEASmoothTimeYHigh(208); haptics->setPhysicsSEASmoothTimeZHigh(209);
+ haptics->setPhysicsAIRScale(1.0f, 1.0f, 1.0f);
+ haptics->setPhysicsAIRScaleXLow(1.0f); haptics->setPhysicsAIRScaleYLow(1.0f); haptics->setPhysicsAIRScaleZLow(3.0f);
+ haptics->setPhysicsAIRScaleXMed(1.0f); haptics->setPhysicsAIRScaleYMed(1.0f); haptics->setPhysicsAIRScaleZMed(30.0f);
+ haptics->setPhysicsAIRScaleXHigh(1.0f); haptics->setPhysicsAIRScaleYHigh(1.0f); haptics->setPhysicsAIRScaleZHigh(300.0f);
+ haptics->setPhysicsAIRTransitionValueMed(1.0f); haptics->setPhysicsAIRTransitionValueHigh(10.0f);
+ haptics->setPhysicsAIRSmoothTimeXLow(301); haptics->setPhysicsAIRSmoothTimeYLow(302); haptics->setPhysicsAIRSmoothTimeZLow(303);
+ haptics->setPhysicsAIRSmoothTimeXMed(304); haptics->setPhysicsAIRSmoothTimeYMed(305); haptics->setPhysicsAIRSmoothTimeZMed(306);
+ haptics->setPhysicsAIRSmoothTimeXHigh(307); haptics->setPhysicsAIRSmoothTimeYHigh(308); haptics->setPhysicsAIRSmoothTimeZHigh(309);
+ haptics->setPhysicsHELIScale(1.0f, 1.0f, 1.0f);
+ haptics->setPhysicsHELIScaleXLow(1.0f); haptics->setPhysicsHELIScaleYLow(1.0f); haptics->setPhysicsHELIScaleZLow(4.0f);
+ haptics->setPhysicsHELIScaleXMed(1.0f); haptics->setPhysicsHELIScaleYMed(1.0f); haptics->setPhysicsHELIScaleZMed(40.0f);
+ haptics->setPhysicsHELIScaleXHigh(1.0f); haptics->setPhysicsHELIScaleYHigh(1.0f); haptics->setPhysicsHELIScaleZHigh(400.0f);
+ haptics->setPhysicsHELITransitionValueMed(1.0f); haptics->setPhysicsHELITransitionValueHigh(10.0f);
+ haptics->setPhysicsHELISmoothTimeXLow(401); haptics->setPhysicsHELISmoothTimeYLow(402); haptics->setPhysicsHELISmoothTimeZLow(403);
+ haptics->setPhysicsHELISmoothTimeXMed(404); haptics->setPhysicsHELISmoothTimeYMed(405); haptics->setPhysicsHELISmoothTimeZMed(406);
+ haptics->setPhysicsHELISmoothTimeXHigh(407); haptics->setPhysicsHELISmoothTimeYHigh(408); haptics->setPhysicsHELISmoothTimeZHigh(409);
+ haptics->setForceCapX(1e6f); haptics->setForceCapY(1e6f); haptics->setForceCapZ(1e6f);
+ for (int i = 0; i < 6; ++i) g_hapticForceTargets[i] = 0;
+ auto tick = [](int x, int y, int z, const char* fz) {
+ return "smooth 10 " + std::to_string(x) + ";force 10 -0 0 0;smooth 11 " + std::to_string(y)
+ + ";force 11 0 -0 0;smooth 12 " + std::to_string(z) + ";force 12 0 0 " + fz + ";";
+ };
+ fake::sdk.clear();
+ fake::constantEffects = 0;
+ fake::params18.clear();
+ io::updateVehicleCraftPhysicsForce(v3(0, 0, 0), 0.25f, 0);
+ check(fake::params18 == "101,102,103," && fake::sdk.calls.size() == 18
+ && fake::sdk.calls[12] == "smooth 10 101" && fake::sdk.calls[17] == "force 12 0 0 0",
+ "vehicle craft physics: its own effects-creation pass; LAND's Low smooth times");
+ fake::sdk.clear();
+ io::updateVehicleCraftPhysicsForce(v3(0, 0, 0), 0.25f, 1);
+ io::updateVehicleCraftPhysicsForce(v3(0, 0, 0), 0.25f, 2);
+ check(fake::sdk.joined() == tick(201, 202, 203, "0") + tick(301, 302, 303, "0"),
+ "vehicle craft physics: SEA and AIR Low smooth times while the history fills");
+ // (0,0,0) (0,0,0) (0,0,-1): a.z = 2, Med: AIR z scale 30, Med smooth times.
+ fake::sdk.clear();
+ io::updateVehicleCraftPhysicsForce(v3(0, 0, -1), 0.25f, 2);
+ check(fake::sdk.joined() == tick(304, 305, 306, "60"), "vehicle craft physics: AIR, Med band and Med smooth times");
+ fake::sdk.clear();
+ io::updateVehicleCraftPhysicsForce(v3(0, 0, -1), 0.25f, 3);
+ check(fake::sdk.joined() == tick(404, 405, 406, "80"), "vehicle craft physics: HELI, Med");
+ fake::sdk.clear();
+ io::updateVehicleCraftPhysicsForce(v3(0, 0, -1), 0.25f, 1);
+ check(fake::sdk.joined() == tick(201, 202, 203, "0"), "vehicle craft physics: SEA, Low (no acceleration)");
+ // (0,0,-1) (0,0,-1) (0,0,-11): a.z = 20, High; category 7 falls back to LAND.
+ fake::sdk.clear();
+ io::updateVehicleCraftPhysicsForce(v3(0, 0, -11), 0.25f, 7);
+ check(fake::sdk.joined() == tick(107, 108, 109, "2000"), "vehicle craft physics: an unknown category is LAND; High band and High smooth times");
+ for (int i = 0; i < 6; ++i) g_hapticForceTargets[i] = 0;
+ }
+
+ // --- The RecoilPunch envelope (0x6095EF..0x60968A) and SoldierBasedRecoilComp's choice (0x609353..) --
+ {
+ haptics->setForceCapZ(5.0f);
+ fake::sdk.clear();
+ io::fireRecoilPunch(2.9f, 0.5f, 3.0f);
+ check(fake::sdk.joined() == "envelope params constructed;stack;create Envelope RecoilPunch;envelope 2 -777 -777 1.5;params destroyed;",
+ "recoil punch: Envelope params, time truncated, z = scale * strength below the cap, not kept, deleted");
+ fake::sdk.clear();
+ io::fireRecoilPunch(-2.9f, 0.5f, 10.0f);
+ io::fireRecoilPunch(1.0f, 0.5f, -10.0f);
+ io::fireRecoilPunch(1.0f, 0.5f, -5.0f);
+ std::string got;
+ for (const std::string& c : fake::sdk.calls) if (c.compare(0, 9, "envelope ") == 0 && c.compare(0, 15, "envelope params") != 0) got += c + ";";
+ check(got == "envelope -2 -777 -777 2.5;envelope 1 -777 -777 2.5;envelope 1 -777 -777 -2.5;",
+ "recoil punch: truncation toward zero; above the Z cap z = cap * scale without the sign; equal stays");
+
+ // Punch time t+1, scale (t+1)*10 per HapticSettings type; PISTOL also takes 5, 13 and -1.
+ typedef void (IHapticSettings::*Setter)(float);
+ const Setter times[13] = {
+ &IHapticSettings::setRecoilPunchTimeRIFLE, &IHapticSettings::setRecoilPunchTimeRIFLELAUNCHER,
+ &IHapticSettings::setRecoilPunchTimeCARBINE, &IHapticSettings::setRecoilPunchTimeLMG,
+ &IHapticSettings::setRecoilPunchTimeSNIPER, &IHapticSettings::setRecoilPunchTimePISTOL,
+ &IHapticSettings::setRecoilPunchTimeLAUNCHER, &IHapticSettings::setRecoilPunchTimeSMG,
+ &IHapticSettings::setRecoilPunchTimeSHOTGUN, &IHapticSettings::setRecoilPunchTimeKNIFE,
+ &IHapticSettings::setRecoilPunchTimeDROP, &IHapticSettings::setRecoilPunchTimeTHROWN,
+ &IHapticSettings::setRecoilPunchTimeDEFIB };
+ const Setter scales[13] = {
+ &IHapticSettings::setRecoilPunchScaleRIFLE, &IHapticSettings::setRecoilPunchScaleRIFLELAUNCHER,
+ &IHapticSettings::setRecoilPunchScaleCARBINE, &IHapticSettings::setRecoilPunchScaleLMG,
+ &IHapticSettings::setRecoilPunchScaleSNIPER, &IHapticSettings::setRecoilPunchScalePISTOL,
+ &IHapticSettings::setRecoilPunchScaleLAUNCHER, &IHapticSettings::setRecoilPunchScaleSMG,
+ &IHapticSettings::setRecoilPunchScaleSHOTGUN, &IHapticSettings::setRecoilPunchScaleKNIFE,
+ &IHapticSettings::setRecoilPunchScaleDROP, &IHapticSettings::setRecoilPunchScaleTHROWN,
+ &IHapticSettings::setRecoilPunchScaleDEFIB };
+ for (int t = 0; t < 13; ++t) { (haptics->*times[t])(t + 1.0f); (haptics->*scales[t])((t + 1) * 10.0f); }
+ haptics->setForceCapZ(1e6f);
+ bool everyType = true;
+ for (int t = 0; t < 13; ++t) {
+ fake::sdk.clear();
+ io::soldierRecoilPunch(t, false, 0, 0, 0.0f, 0.0f, 0.0f, 1.0f);
+ char want[96];
+ std::snprintf(want, sizeof(want), "envelope %d -777 -777 %.17g", t + 1, (t + 1) * 10.0);
+ everyType = everyType && fake::sdk.calls.size() == 5 && fake::sdk.calls[3] == want;
+ }
+ check(everyType, "recoil punch: weapon types 0..12 select their own punch time and scale");
+ fake::sdk.clear();
+ io::soldierRecoilPunch(13, false, 0, 0, 0.0f, 0.0f, 0.0f, 1.0f);
+ io::soldierRecoilPunch(-1, false, 0, 0, 0.0f, 0.0f, 0.0f, 1.0f);
+ got.clear();
+ for (const std::string& c : fake::sdk.calls) if (c.compare(0, 9, "envelope ") == 0 && c.compare(0, 15, "envelope params") != 0) got += c + ";";
+ check(got == "envelope 6 -777 -777 60;envelope 6 -777 -777 60;", "recoil punch: other weapon types use PISTOL's");
+
+ // With a random recoil force: time *= 4 samples; scale = -(((3 + 1) * 0.5) * 2 * 0.5) * 10 = -20.
+ const float graph[4] = { 9.0f, 9.0f, 9.0f, 0.5f };
+ fake::sdk.clear();
+ io::soldierRecoilPunch(0, true, 4, &graph[3], 1.0f, 3.0f, 2.0f, 1.5f);
+ check(fake::sdk.calls.size() == 5 && fake::sdk.calls[3] == "envelope 4 -777 -777 -30",
+ "recoil punch: a random recoil force scales the time by the samples and the scale by the graph's last sample");
+ }
+
+ // --- WeaponBasedRecoilComp's RecoilPunch choice (0x60A0E7..0x60A4F8) ------------------------------
+ {
+ typedef void (IHapticSettings::*Setter)(float);
+ struct V { Setter time, scale, yaw, pitch; };
+ const V types[7] = {
+ { &IHapticSettings::setRecoilPunchTimeV_LMG, &IHapticSettings::setRecoilPunchScaleV_LMG, &IHapticSettings::setRecoilYawScaleV_LMG, &IHapticSettings::setRecoilPitchScaleV_LMG },
+ { &IHapticSettings::setRecoilPunchTimeV_HMG, &IHapticSettings::setRecoilPunchScaleV_HMG, &IHapticSettings::setRecoilYawScaleV_HMG, &IHapticSettings::setRecoilPitchScaleV_HMG },
+ { &IHapticSettings::setRecoilPunchTimeV_HELIGUN, &IHapticSettings::setRecoilPunchScaleV_HELIGUN, &IHapticSettings::setRecoilYawScaleV_HELIGUN, &IHapticSettings::setRecoilPitchScaleV_HELIGUN },
+ { &IHapticSettings::setRecoilPunchTimeV_AIRGUN, &IHapticSettings::setRecoilPunchScaleV_AIRGUN, &IHapticSettings::setRecoilYawScaleV_AIRGUN, &IHapticSettings::setRecoilPitchScaleV_AIRGUN },
+ { &IHapticSettings::setRecoilPunchTimeV_MISSILE, &IHapticSettings::setRecoilPunchScaleV_MISSILE, &IHapticSettings::setRecoilYawScaleV_MISSILE, &IHapticSettings::setRecoilPitchScaleV_MISSILE },
+ { &IHapticSettings::setRecoilPunchTimeV_ARMORCANNON, &IHapticSettings::setRecoilPunchScaleV_ARMORCANNON, &IHapticSettings::setRecoilYawScaleV_ARMORCANNON, &IHapticSettings::setRecoilPitchScaleV_ARMORCANNON },
+ { &IHapticSettings::setRecoilPunchTimeV_COAXIALGUN, &IHapticSettings::setRecoilPunchScaleV_COAXIALGUN, &IHapticSettings::setRecoilYawScaleV_COAXIALGUN, &IHapticSettings::setRecoilPitchScaleV_COAXIALGUN } };
+ for (int k = 0; k < 7; ++k) {
+ (haptics->*types[k].time)(k + 1.0f);
+ (haptics->*types[k].scale)((k + 1) * 10.0f);
+ (haptics->*types[k].yaw)((k + 1) * 0.25f);
+ (haptics->*types[k].pitch)((k + 1) * 0.125f);
+ }
+ haptics->setRecoilPunchTimeRIFLE(3.0f); haptics->setRecoilPunchScaleRIFLE(7.0f);
+ haptics->setRecoilYawScaleRIFLE(0.75f); haptics->setRecoilPitchScaleRIFLE(0.375f);
+ haptics->setForceCapZ(1e6f);
+ auto envelope = [&]() {
+ for (const std::string& c : fake::sdk.calls)
+ if (c.compare(0, 9, "envelope ") == 0 && c.compare(0, 15, "envelope params") != 0) return c;
+ return std::string("(none)");
+ };
+ bool everyType = true;
+ for (int k = 0; k < 7; ++k) {
+ fake::sdk.clear();
+ haptics->setUnresolved48C(-1.0f); haptics->setUnresolved490(-1.0f);
+ io::weaponRecoilPunch(13 + k, "tankgun", 2.0f, 0.5f, 1.0f); // time (k+1)*2, scale (k+1)*10*0.5
+ char want[96];
+ std::snprintf(want, sizeof(want), "envelope %d -777 -777 %.17g", (k + 1) * 2, (k + 1) * 5.0);
+ everyType = everyType && envelope() == want && haptics->getUnresolved48C() == (k + 1) * 0.25f
+ && haptics->getUnresolved490() == (k + 1) * 0.125f;
+ }
+ check(everyType, "weapon recoil punch: types 13..19 take their own time and scale and set +0x48C/+0x490");
+ fake::sdk.clear();
+ io::weaponRecoilPunch(4, "US_FiringPort_M16", 2.0f, 0.5f, 1.0f);
+ check(envelope() == "envelope 6 -777 -777 3.5" && haptics->getUnresolved48C() == 0.75f && haptics->getUnresolved490() == 0.375f,
+ "weapon recoil punch: another type named *firingport* (any case) takes RIFLE's four values");
+ fake::sdk.clear();
+ io::weaponRecoilPunch(20, "tankgun", 2.9f, 0.5f, 1.0f);
+ check(envelope() == "envelope 2 -777 -777 0" && haptics->getUnresolved48C() == 0.0f && haptics->getUnresolved490() == 0.0f,
+ "weapon recoil punch: otherwise time 1 (times the speed), scale 0, and both set to 0");
+ fake::sdk.clear();
+ io::weaponRecoilPunch(12, "firingpor", 1.0f, 1.0f, 1.0f);
+ check(envelope() == "envelope 1 -777 -777 0", "weapon recoil punch: types below 13 are not vehicle types");
+ }
+
+ // --- GenericFireArm::postFire's kit RecoilPunch (0x5E2A98..0x5E2CDA) -------------------------------
+ {
+ haptics->setRecoilPunchTimeKNIFE(2.0f); haptics->setRecoilPunchScaleKNIFE(20.0f);
+ haptics->setRecoilPunchTimeDROP(3.0f); haptics->setRecoilPunchScaleDROP(30.0f);
+ haptics->setRecoilPunchTimeTHROWN(4.0f); haptics->setRecoilPunchScaleTHROWN(40.0f);
+ haptics->setRecoilPunchTimeDEFIB(5.0f); haptics->setRecoilPunchScaleDEFIB(50.0f);
+ haptics->setForceCapZ(1e6f);
+ auto envelopes = [&]() {
+ std::string r;
+ for (const std::string& c : fake::sdk.calls)
+ if (c.compare(0, 9, "envelope ") == 0 && c.compare(0, 15, "envelope params") != 0) r += c + ";";
+ return r;
+ };
+ fake::sdk.clear();
+ for (int t = 9; t <= 12; ++t) io::kitRecoilPunch(t, "rifle", 1.0f);
+ check(envelopes() == "envelope 2 -777 -777 20;envelope 3 -777 -777 30;envelope 4 -777 -777 40;envelope 5 -777 -777 50;",
+ "kit recoil punch: types 9..12 take KNIFE, DROP, THROWN, DEFIB");
+ fake::sdk.clear();
+ io::kitRecoilPunch(0, "US_MedKit", 1.0f);
+ io::kitRecoilPunch(13, "ch_WRENCH_2", 1.0f);
+ io::kitRecoilPunch(8, "knife", 1.0f);
+ io::kitRecoilPunch(8, "ki", 2.0f);
+ check(envelopes() == "envelope 3 -777 -777 30;envelope 3 -777 -777 30;envelope 1 -777 -777 0;envelope 1 -777 -777 0;",
+ "kit recoil punch: other types named *kit* or *wrench* (any case) take DROP's, else time 1 and scale 0");
+ }
+
+ // --- GameLogicDamage::serverGiveDamage's "Damage" envelope (0x5E6566..0x5E66A2) ---------------------
+ {
+ Mat4 lookAt, owner;
+ for (int i = 0; i < 16; ++i) { lookAt.m[i] = 0.0f; owner.m[i] = 0.0f; }
+ lookAt.m[8] = 0.48f; lookAt.m[9] = 0.6f; lookAt.m[10] = 0.64f; // the forward row
+ owner.m[0] = owner.m[5] = owner.m[10] = owner.m[15] = 1.0f;
+ haptics->setDamageScale(2.0f);
+ world::IPlayer* const local = reinterpret_cast(0x1000);
+ world::IPlayer* const other = reinterpret_cast(0x2000);
+ fake::sdk.clear();
+ io::updateDamageForce(other, local, lookAt, owner, 10.0f);
+ check(fake::sdk.calls.empty(), "damage: another victim, nothing");
+ NovintHFX::Device* const saved = io::g_falconDevice;
+ io::g_falconDevice = 0;
+ io::updateDamageForce(local, local, lookAt, owner, 10.0f);
+ io::g_falconDevice = saved;
+ check(fake::sdk.calls.empty(), "damage: no device, nothing");
+ io::updateDamageForce(local, local, lookAt, owner, 10.0f);
+ // identity owner: (a, b, c) = (0.48, 0.6, 0.64); direction (-0.48, 0.6, 0.64) * (2 * 10 * 0.5)
+ const NovintHFX::Vect3 expected = NovintHFX::Vect3(-static_cast(0.48f), static_cast(0.6f), static_cast(0.64f)).Normalize() * 10.0;
+ NovintHFX::Vect3& e = const_cast(expected);
+ char want[160];
+ std::snprintf(want, sizeof(want), "envelope 100 %.17g %.17g %.17g", e[0], e[1], e[2]);
+ check(fake::sdk.joined() == std::string("envelope params constructed;stack;create Envelope Damage;") + want + ";params destroyed;",
+ "damage: Envelope params +0x18 = 100, the normalized (-a, b, c) times scale * damage * 0.5, not kept");
+ // Rotated owner: rows (0,0,1) (1,0,0) (0,1,0): a = 0.64, b = 0.48, c = 0.6.
+ for (int i = 0; i < 16; ++i) owner.m[i] = 0.0f;
+ owner.m[2] = 1.0f; owner.m[4] = 1.0f; owner.m[9] = 1.0f; owner.m[15] = 1.0f;
+ fake::sdk.clear();
+ io::updateDamageForce(local, local, lookAt, owner, 10.0f);
+ const NovintHFX::Vect3 rotated = NovintHFX::Vect3(-static_cast(0.64f), static_cast(0.48f), static_cast(0.6f)).Normalize() * 10.0;
+ NovintHFX::Vect3& r = const_cast(rotated);
+ std::snprintf(want, sizeof(want), "envelope 100 %.17g %.17g %.17g", r[0], r[1], r[2]);
+ check(fake::sdk.calls.size() == 5 && fake::sdk.calls[3] == want, "damage: the forward row dotted with the owner's rows 0, 1, 2");
+ }
+
+ device->release();
+ std::printf("falcon update runtime %u/%u checks passed\n", checks - failures, checks);
+ return failures ? 1 : 0;
+}
diff --git a/Code/Archive/NovintFalcon/Tests/falcon_vtable_restore.cmd b/Code/Archive/NovintFalcon/Tests/falcon_vtable_restore.cmd
new file mode 100644
index 000000000..6bf986b92
--- /dev/null
+++ b/Code/Archive/NovintFalcon/Tests/falcon_vtable_restore.cmd
@@ -0,0 +1,45 @@
+@echo off
+setlocal
+rem [TEMP] MSVC check (game-frontier batch 16 N1): the instruction right after the imported
+rem NovintHFX::ControlBoxEffectParams constructor call must store FalconControlBoxParams' local
+rem vtable, as BF2.exe does at 0x6A58A1 (mov dword ptr [esi], 0x9116E0). Compiles FalconDevice.cpp for x86 /O2,
+rem disassembles FalconDevice::updateCurrentState and prints PASS or FAIL with the lines it saw.
+rem N2 also checks all Constant/Envelope constructor calls for the immediate local-vtable store:
+rem at least three Constant sites are required; Envelope sites are optional until used.
+rem Writes only under BF2_BUILD_OUT; no DLL is loaded and nothing runs.
+call "%~dp0..\Build\vsdevcmd.cmd" x86
+set "TASK_ROOT=%~dp0..\.."
+if not defined BF2_BUILD_OUT set "BF2_BUILD_OUT=%~dp0..\Build\obj_falcon_vtable_restore"
+if not exist "%BF2_BUILD_OUT%" mkdir "%BF2_BUILD_OUT%"
+set "TASK_FLAGS=/nologo /O2 /EHsc /std:c++14 /permissive /MD /Gy /DDEDICATED=0 /DBF2_PLUGIN_ABI_NATIVE=1 /D_ITERATOR_DEBUG_LEVEL=0"
+cl %TASK_FLAGS% /FI"%TASK_ROOT%\Code\BF2\Core\BuildConfig.h" /c "%TASK_ROOT%\Code\BF2\IO\Input\FalconDevice.cpp" /Fo"%BF2_BUILD_OUT%\FalconDevice.obj" >"%BF2_BUILD_OUT%\compile.log" 2>&1
+if errorlevel 1 (type "%BF2_BUILD_OUT%\compile.log" & echo FAIL: compile & exit /b 1)
+dumpbin /nologo /disasm "%BF2_BUILD_OUT%\FalconDevice.obj" >"%BF2_BUILD_OUT%\disasm.txt"
+if errorlevel 1 (echo FAIL: dumpbin & exit /b 1)
+powershell -NoProfile -ExecutionPolicy Bypass -Command ^
+ "$l = Get-Content -LiteralPath '%BF2_BUILD_OUT%\disasm.txt';" ^
+ "$allPass = $true; $s = -1; for ($i = 0; $i -lt $l.Count; $i++) { if ($l[$i] -match '^\?updateCurrentState@FalconDevice@io@hfe@dice@@') { $s = $i; break } }" ^
+ "if ($s -lt 0) { Write-Output 'FAIL: ControlBoxEffectParams: updateCurrentState not found in the disassembly'; $allPass = $false } else {" ^
+ "$e = $l.Count; for ($i = $s + 1; $i -lt $l.Count; $i++) { if ($l[$i] -match '^\?\S+:$' -or $l[$i] -match '^_\S+:$') { $e = $i; break } }" ^
+ "$c = -1; for ($i = $s; $i -lt $e; $i++) { if ($l[$i] -match '__imp_\?\?0ControlBoxEffectParams@NovintHFX@@QAE@XZ') { $c = $i; break } }" ^
+ "if ($c -lt 0) { Write-Output 'FAIL: no call of the imported ControlBoxEffectParams constructor'; $allPass = $false } else {" ^
+ "$hit = $null; if ($l[$c + 1] -match 'mov\s+dword ptr \[\w+\],(offset )?\?\?_7FalconControlBoxParams@') { $hit = $l[$c + 1] }" ^
+ "Write-Output '--- after the constructor call:'; $l[$c..([Math]::Min($c + 8, $e - 1))] | Write-Output;" ^
+ "if ($hit) { Write-Output ('PASS: FalconControlBoxParams vtable stored right after the imported constructor: ' + $hit.Trim()) }" ^
+ "else { Write-Output 'FAIL: the instruction after the ControlBoxEffectParams constructor call is not the store of ??_7FalconControlBoxParams'; $allPass = $false } } }" ^
+ "foreach ($rule in @(@{ Base = 'ConstantEffectParams'; Derived = 'FalconConstantParams'; Minimum = 3 }, @{ Base = 'EnvelopeEffectParams'; Derived = 'FalconEnvelopeParams'; Minimum = 0 })) {" ^
+ "$callPattern = '\bcall\s+.*' + [regex]::Escape('__imp_??0' + $rule.Base + '@NovintHFX@@QAE@XZ');" ^
+ "$storePattern = 'mov\s+dword ptr \[\w+\],(offset )?' + [regex]::Escape('??_7' + $rule.Derived + '@');" ^
+ "$count = 0; $bad = 0; $function = '';" ^
+ "for ($i = 0; $i -lt $l.Count; $i++) {" ^
+ "if ($l[$i] -match '^(\?\S+):$') { $function = $Matches[1] }" ^
+ "if ($l[$i] -notmatch $callPattern) { continue }; $count++;" ^
+ "$next = ''; if ($i + 1 -lt $l.Count) { $next = $l[$i + 1] }" ^
+ "Write-Output ($rule.Base + ' site in ' + $function + ':'); Write-Output $next;" ^
+ "if ($next -notmatch $storePattern) { $bad++ } }" ^
+ "if ($count -eq 0 -and $rule.Base -eq 'EnvelopeEffectParams') { Write-Output 'no EnvelopeEffectParams sites yet' }" ^
+ "if ($count -ge $rule.Minimum -and $bad -eq 0) { Write-Output ('PASS: ' + $rule.Base + ': ' + $count + ' sites, all immediate vtable stores valid') }" ^
+ "else { Write-Output ('FAIL: ' + $rule.Base + ': ' + $count + ' sites (minimum ' + $rule.Minimum + '), ' + $bad + ' invalid immediate vtable stores'); $allPass = $false } }" ^
+ "if ($allPass) { Write-Output 'PASS: all Falcon vtable restore rules'; exit 0 }" ^
+ "Write-Output 'FAIL: Falcon vtable restore rules'; exit 1"
+exit /b %errorlevel%
diff --git a/Code/Archive/NovintFalcon/Tests/msvc_x86_layout/include/windows.h b/Code/Archive/NovintFalcon/Tests/msvc_x86_layout/include/windows.h
new file mode 100644
index 000000000..ba988f0e6
--- /dev/null
+++ b/Code/Archive/NovintFalcon/Tests/msvc_x86_layout/include/windows.h
@@ -0,0 +1,4 @@
+// [TEMP] Stub for the Mac-side MSVC x86 layout checks: the two Win32 names NovintHFX.h uses.
+#pragma once
+typedef unsigned long DWORD;
+typedef struct HWND__* HWND;
diff --git a/Code/Archive/NovintFalcon/Tests/msvc_x86_layout/novint_x86_layout.cpp b/Code/Archive/NovintFalcon/Tests/msvc_x86_layout/novint_x86_layout.cpp
new file mode 100644
index 000000000..799e241ea
--- /dev/null
+++ b/Code/Archive/NovintFalcon/Tests/msvc_x86_layout/novint_x86_layout.cpp
@@ -0,0 +1,14 @@
+// [TEMP] Compiles NovintHFX.h for the MSVC x86 ABI from the Mac (bf2_novint_msvc_x86_layout): the
+// header's own static_asserts check ControlBoxEffectParams (0x120 bytes, BF2.exe 0x6A587F) and its
+// inline-written fields, and IHapticEffect's +0x0C flags. The real check is the Windows x86 build.
+#include "../../BF2/External/NovintHFX/NovintHFX.h"
+static_assert(sizeof(IHapticEffectParam) == 4, "interface: one vfptr");
+static_assert(sizeof(NovintHFX::BaseEffectParams) == 0x18, "base: vfptr + 20 bytes of SDK state");
+static_assert(sizeof(NovintHFX::Vect3) == 24, "three doubles");
+static_assert(sizeof(NovintHFX::ConstantEffectParams) == 0x20, "constant effect: x86 SDK ABI");
+static_assert(offsetof(NovintHFX::ConstantEffectParams, m_unresolved18) == 0x18, "x86 SDK ABI");
+static_assert(offsetof(NovintHFX::ConstantEffectParams, m_unresolved1C) == 0x1C, "x86 SDK ABI");
+static_assert(sizeof(NovintHFX::EnvelopeEffectParams) == 0x40, "envelope effect: x86 SDK ABI");
+static_assert(offsetof(NovintHFX::EnvelopeEffectParams, m_unresolved18) == 0x18, "x86 SDK ABI");
+static_assert(offsetof(NovintHFX::EnvelopeEffectParams, m_unresolved1C) == 0x1C, "x86 SDK ABI");
+static_assert(offsetof(NovintHFX::EnvelopeEffectParams, m_force) == 0x28, "x86 SDK ABI");
diff --git a/Code/Archive/NovintFalcon/Tests/novint_fake/windows.h b/Code/Archive/NovintFalcon/Tests/novint_fake/windows.h
new file mode 100644
index 000000000..8dad68c2d
--- /dev/null
+++ b/Code/Archive/NovintFalcon/Tests/novint_fake/windows.h
@@ -0,0 +1,9 @@
+// [TEMP] [CHOSEN, not recovered] Mac fake-SDK check only (bf2_falcon_update_check): the four
+// Win32 names FalconDevice.cpp and NovintHFX.h use. The check defines the two functions.
+#ifndef BF2_TESTS_NOVINT_FAKE_WINDOWS_H
+#define BF2_TESTS_NOVINT_FAKE_WINDOWS_H
+typedef unsigned int DWORD;
+typedef void* HWND;
+extern "C" DWORD GetTickCount();
+extern "C" HWND GetForegroundWindow();
+#endif
diff --git a/Code/Archive/NovintFalcon/Tests/soldier_haptic_profile_runtime.cpp b/Code/Archive/NovintFalcon/Tests/soldier_haptic_profile_runtime.cpp
new file mode 100644
index 000000000..8b75e73c9
--- /dev/null
+++ b/Code/Archive/NovintFalcon/Tests/soldier_haptic_profile_runtime.cpp
@@ -0,0 +1,1276 @@
+// [TEMP] [CHOSEN, not recovered] The Soldier's Novint control-box profile switch
+// (Game/Objects/Game/SoldierHapticProfile.cpp, ledger N2 17a) against a complete fake HapticSettings and
+// fake player-control templates (CTest bf2_soldier_haptic_profile_check). The fakes are generated from
+// their headers and fail loudly for every call the code under test must not make.
+#include "../BF2/Game/Objects/Game/SoldierHapticProfile.h"
+#include "../BF2/Game/HapticSettings.h"
+#include "../BF2/Game/Objects/IPlayerControlObjectTemplate.h"
+#include "../BF2/Game/Objects/GenericFireArmTemplate.h"
+#include "../BF2/Game/Objects/Weapons/GenericFireArm.h"
+#include "../BF2/IO/Input/FalconHaptics.h"
+#include "../BF2/Game/Objects/IObject.h"
+#include "../BF2/Game/Objects/IPlayer.h"
+#include "../BF2/Math/Mat4.h"
+#include "../BF2/Physics/IPhysicsNode.h"
+#include
+#include
+#include
+#include