Library for interacting with Red Alert 2 Yuri's Revenge game process with protobuf based protocol over TCP. Inspired by s2client-api.
Download the latest release, copy libra2yrcpp.dll to same folder as gamemd.exe or gamemd-spawn.exe. Create configuration file named ra2yrcpp.json in that same folder, for example:
{
"port": 14521,
"allowedHostsRegex": "0.0.0.0|127.0.0.1|172..+",
"logFilename": "ra2yrcpp.log"
}If you are using beta version of CnCNet client, the relevant files are already in the game data folder.
Otherwise get Syringe.exe, CnCNet-Spawner.dll and cncnet.fnt (see Troubleshooting section) here
Note
Syringe expects one space character after the executable name, hence the backtick.
Run the game:
Syringe.exe gamemd.exe\ -SPAWN -CD -LOG(TODO. In theory Syringe should also work with gamemd-spawn.exe without patching)
Get sources from here, or use git (use --depth 1 if you want just the latest commit):
git clone --recurse-submodules https://github.com/shmocz/ra2yrcpp.git
Download the latest release and extract the contents to folder of your choice, e.g. ra2yrcpp. Download spawner and patch it:
python ./scripts/patch_gamemd.py \
--auto-patch \
--build-dir ra2yrcpp \
--input yr-patches/release/cncnet/gamemd-spawn.exe \
--output ra2yrcpp/gamemd-spawn-ra2yrcpp.exe
Warning You cannot use the modified spawner in any online games played over CnCNet. Not only is this against their ToS, but the ra2yrcpp-specific spawner is incompatible with the standard version.
Copy ra2yrcpp/libra2yrcpp.dll and ra2yrcpp/gamemd-spawn-ra2yrcpp.exe to the CnCNet installation folder. If you wish to launch the game via official CnCNet client, then overwrite the original gamemd-spawn.exe with the patched spawner.
ra2yrcpp depends on following software:
- argparse
- asio
- cmake
- fmt
- protobuf
- websocketpp
- wine (Optional: see section about cross-compilation and protoc)
- xbyak
- zlib
All dependencies except cmake, python, zlib and wine are already included as submodules.
For clang-cl, zlib sources might be needed:
git clone -b v1.2.8 https://github.com/madler/zlib.git 3rdparty/zlibFor convenience, a Docker image is provided for both MinGW and clang-cl toolchains with all necessary dependencies to build the application and related components. MinGW toolchain is used by default.
Build the images:
docker compose build builderBuild the library with docker:
./scripts/tools.sh docker-buildWarning Builds of libprotobuf lack compatibility across different compilers. Attempting to link a MinGW compiled library in MSVC/clang-cl toolchain, or vice versa, will result in errors.
If you built the main docker image then protobuf has already been built and you can copy the files from there:
mkdir -p opt/usr
docker compose cp -L builder:/usr/i686-w64-mingw32 opt/usr
docker compose cp -L builder:/usr/bin/protoc opt/binPick a toolchain of your choice, release type and the build script:
export CMAKE_TOOLCHAIN_FILE=<toolchain-path>
export CMAKE_RELEASE_TYPE=Release
./scripts/tools.sh build-cppThis performs the build and installation under cbuild/<toolchain-id>-<release-type>.
Alternatively invoke cmake directly:
mkdir -p build pkg
cmake \
-DCMAKE_INSTALL_PREFIX=pkg \
--toolchain <toolchain-path> \
-S . -B build \
cmake --build build --config Release --target all -j $(nproc) \
cmake --build build --config Release --target installThe following build options are available:
RA2YRCPP_BUILD_MAIN_DLLWhether to build the main YRpp-dependent DLL and related utilities. Default:ONRA2YRCPP_BUILD_TESTSWhether to build test executables. Default:ONRA2YRCPP_DEBUG_LOGEnable debug logging even for non-debug targets. Default:OFFRA2YRCPP_SYSTEM_PROTOBUFUse system protobuf headers instead of the submodule. Useful when working on native builds. Default:OFF
Clang-cl requires MSVC SDK, which will be downloaded when building the clang-cl-msvc.Dockerfile image. Once downloaded, modify the toolchain file at toolchains/clang-cl-msvc.cmake to point to correct SDK paths.
Also get the static zlib library, and adjust ZLIB_LIBRARY in the toolchain file accordingly. On Linux systems the library might be present if MinGW cross compilation toolchain has been installed.
Execute build with:
export CMAKE_TOOLCHAIN_FILE=toolchains/clang-cl-msvc.cmake
./scripts/tools.sh build-cppthe build and install directories will be performed to cbuild/<toolchain-name>-$CMAKE_RELEASE_TYPE, under the names build and pkg respectively.
The instructions are identical to clang-cl, consult the reference toolchain file at mingw-w64-i686.cmake.
export CMAKE_TOOLCHAIN_FILE=toolchains/mingw-w64-i686.cmake
./scripts/tools.sh build-cppThe core component and it's related tests do not depend on Windows, and can be built natively using RA2YRCPP_BUILD_MAIN_DLL=OFF CMake option. This is useful when debugging code of the main service. You can specify additional compile/link options for test executables in the RA2YRCPP_EXTRA_FLAGS variable. For instance, to enable ASan and UBSan on GCC or Clang:
set(RA2YRCPP_EXTRA_FLAGS -fsanitize=address -fsanitize=undefined)Warning Currently supported only for native builds (
RA2YRCPP_BUILD_MAIN_DLL=OFF)
Newer versions of protobuf use abseil library and may require additional linking flags. These can be specified in the toolchain file like this:
set(PROTOBUF_EXTRA_LIBS absl_status absl_log_internal_check_op absl_log_internal_message)Exact list of libraries may vary across systems and protobuf versions.
Warning The uncompressed recording can be very large. Consider downsampling or transforming it into less verbose format for further processing.
A callback is created to save game state at the beginning of each frame. To output these to a file, set the recordFilename setting, e.g. "recordFilename": "record.pb.gz". The states are stored as compressed consecutive serialized protobuf messages. After exiting the game, the recording can be dumped as lines of JSON strings with the tool ra2yrcppcli.exe.
This can happen if ra2yrcpp cannot load zlib DLL. Ensure that zlib1.dll is placed in the same folder as libra2yrcpp.dll.
Anti-cheat mechanism tends to cause this. Use the non-hardened version of the spawner available here.
This happens if debugging on Windows or with winedbg on Linux (regular gdb should work fine). Compile ra2yrcpp with Debug build variant, which causes it to detach from active debugger at initialization.
Make sure cncnet.fnt is in game data folder.
This project has no direct association to Electronic Arts Inc. Command and Conquer, Yuri's Revenge, Red Alert, Westwood Studios, EA GAMES, the EA GAMES logo and Electronic Arts are trademarks or registered trademarks of Electronic Arts Inc. in the U.S. and/or other countries. All rights reserved.
