From fbfcaca66b3a237d1c141f0b853bf75daec31252 Mon Sep 17 00:00:00 2001 From: Dethrace Labs <78985374+dethrace-labs@users.noreply.github.com> Date: Mon, 28 Jul 2025 12:06:09 +1200 Subject: [PATCH] adds docker container msvc 420 files --- CONTRIBUTING.md | 21 ++++++++++++------- docker/Dockerfile | 42 +++++++++++++++++++++++++++++++++++++ docker/README.md | 32 ++++++++++++++++++++++++++++ docker/entrypoint.sh | 22 +++++++++++++++++++ docker/set-env.reg | 8 +++++++ reccmp-project.yml | 3 +-- src/DETHRACE/CMakeLists.txt | 3 ++- 7 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 docker/Dockerfile create mode 100644 docker/README.md create mode 100755 docker/entrypoint.sh create mode 100644 docker/set-env.reg diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 05a68ad0..c8034f58 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,13 +5,18 @@ questions or concerns, please ask in #dethrace channel on our [Discord chat](htt ## Reporting bugs To report a bug, ensure you have a GitHub account. Search the issues page to see if the bug has already been reported. -If not, create a new issue and write the steps to reproduce. A screenshot or a video can often be useful. +If not, create a new issue and write the steps to reproduce. A screenshot or a video can often be useful. Please state which architecture and version of the game you are running, e.g. ``` Harness_Init version: v0.4.0-15-g31afabc Windows (x86-64) ``` +## Binary accuracy +We aims to be as accurate as possible, matching the recompiled instructions to the original machine code as much as possible. The goal is to provide a workable codebase that can be modified, improved, and ported to other platforms later on. We are using [reccmp](https://github.com/isledecomp/reccmp?tab=readme-ov-file) to diff the recompiled code with the original Windows 95 code. + +See: [docker](https://github.com/dethrace-labs/dethrace/blob/main/docker/README.md) + ## Project goals - Faithfully reproduce the original gameplay from Carmageddon 1 @@ -42,7 +47,7 @@ By contributing your code, you agree to license your contribution under [GPL v3] Join us in the #dethrace channel on our [Discord chat](https://discord.gg/f5StsuP). We'd love to talk! ## Code style -We expect code to be formatted with our [clang-format](https://github.com/dethrace-labs/dethrace/blob/main/.clang-format) style. +We expect code to be formatted with our [clang-format](https://github.com/dethrace-labs/dethrace/blob/main/.clang-format) style. We recommend to configure your IDE to run clang-format on save. Heres how to enable it in Visual Studio Code for example: ![image](https://user-images.githubusercontent.com/78985374/200776372-8d5ec29d-8f39-4970-be69-7cc2abaf724d.png) @@ -66,7 +71,7 @@ float velocity; ``` ## Inline BRender functions -Please use the [inline BRender functions](https://github.com/dethrace-labs/dethrace/blob/main/src/BRSRC13/include/brender/br_inline_funcs.h) where possible. +Please use the [inline BRender functions](https://github.com/dethrace-labs/dethrace/blob/main/src/BRSRC13/include/brender/br_inline_funcs.h) where possible. Instead of ```c @@ -75,13 +80,13 @@ vector_a->v[1] = vector_b->v[1] * 6.0f; vector_a->v[2] = vector_b->v[2] * 6.0f; ``` -it should look like +it should look like ```c BrVector3Scale(&vector_a, &vector_b, 6.0f); ``` ## Magic values -Many "magic" values are already defined as enums from the code-gen. +Many "magic" values are already defined as enums from the code-gen. Before adding something like `#define DEPTH_EFFECT_WATER 1`, look at [dr_types.h](https://github.com/dethrace-labs/dethrace/blob/main/src/DETHRACE/dr_types.h) and try to find the existing enum. For example: @@ -98,7 +103,7 @@ typedef enum tSpec_vol_depth_effect { In this case, can just replace the "1" with `eSpec_dep_water`. ## Modern platform code -If you need to add new code to interface with modern platforms or cross-platform (for example, audio, rendering, get system time), please add this code into `src/harness`. `harness` contains only new code written by the dethrace project, and its goal is to provide a simple cross-platform interface to `BRSRC13` and `DETHRACE`. We want to keep the code in `BRSRC13` and `DETHRACE` as faithful to the original as possible, and not be polluted with extra modern code or dependencies. Instead, that code goes into `harness`. +If you need to add new code to interface with modern platforms or cross-platform (for example, audio, rendering, get system time), please add this code into `src/harness`. `harness` contains only new code written by the dethrace project, and its goal is to provide a simple cross-platform interface to `BRSRC13` and `DETHRACE`. We want to keep the code in `BRSRC13` and `DETHRACE` as faithful to the original as possible, and not be polluted with extra modern code or dependencies. Instead, that code goes into `harness`. Why is it called `harness`? Good question! It contains the _real_ `main` function, so harness starts up first, reads the command line, configures a few things, then calls into the _original_ main function in `src/DETHRACE`. The original game calls harness functions for platform services like audio and display. In this way, it acts like a harness for the original game engine. @@ -111,7 +116,7 @@ Tests were written to cover some basic functionality at the start of the project A subset of tests do not require `DETHRACE_ROOT_DIR`. They run via Github actions when code is committed to this repo. This allows us to keep nice and clean and avoid storing any potentially legally problematic resouces in our repo. -The majority of tests _do_ require `DETHRACE_ROOT_DIR`. +The majority of tests _do_ require `DETHRACE_ROOT_DIR`. To run the full test suite, you must have a copy of the original *Splat Pack* data. @@ -119,7 +124,7 @@ To run the full test suite, you must have a copy of the original *Splat Pack* da export DETHRACE_ROOT_DIR=/path/to/carmageddon_splat_pack ``` -To run +To run ```sh ./dethrace_test diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..8fddf851 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,42 @@ +FROM docker.io/library/debian:stable-slim + +# Gather dependencies +RUN dpkg --add-architecture i386 +RUN apt-get update -y +RUN apt-get install git wine wine64 wine32 wget unzip pip -y + +ENV WINEPREFIX=/wineprefix +# Silence debug warnings in wine (creates noise during compile) +ENV WINEDEBUG="-all" + +COPY set-env.reg /tmp/set-env.reg + +# Create and initialize Wine prefix +RUN mkdir -p $WINEPREFIX && \ + wineboot --init && \ + # wait for wineboot to finish + wineserver -w && \ + wine regedit /S /tmp/set-env.reg && \ + # wait for regedit to finish + wineserver -w + +# Install MSVC 4.20 and CMake for Windows +RUN git clone https://github.com/itsmattkc/MSVC420 $WINEPREFIX/drive_c/msvc + +# Install CMake for Windows +RUN wget --quiet https://github.com/Kitware/CMake/releases/download/v3.26.6/cmake-3.26.6-windows-i386.zip +RUN unzip -q cmake-3.26.6-windows-i386.zip -d $WINEPREFIX/drive_c +RUN mv $WINEPREFIX/drive_c/cmake-3.26.6-windows-i386 $WINEPREFIX/drive_c/cmake +RUN rm cmake-3.26.6-windows-i386.zip + +# Install Ninja for Windows +RUN wget --quiet https://github.com/ninja-build/ninja/releases/download/v1.13.1/ninja-win.zip +RUN unzip -q ninja-win.zip -d $WINEPREFIX/drive_c/ninja +RUN rm ninja-win.zip + +# Install reccmp +RUN pip install --break-system-packages git+https://github.com/isledecomp/reccmp + +# Set up entrypoint script to perform the build +COPY entrypoint.sh entrypoint.sh +ENTRYPOINT [ "./entrypoint.sh" ] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..fe448817 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,32 @@ +# Docker container for running cross-platform MSVC 4.20 + +To run MSVC 4.20 outside of a non-Windows environment, you can use a Docker image and [Wine](https://www.winehq.org/) + +## Build container image +```sh +docker buildx build --platform linux/amd64 -t msvc420-wine . +``` + +## Running the container + +When running this container, you must pass +1. `CMAKE_FLAGS="-G Ninja -DCMAKE_BUILD_TYPE=Debug -DMSVC_42_FOR_RECCMP=on". +2. Path to the top-level dethrace directory (for example `/code/dethrace`). +3. Path to a msvc420-specific build directory (for example `/code/dethrace/build-msvc420`). This directory must exist but can start off empty. Note that this build directory _cannot be_ the same as your "regular" build directory. +4. Path to a directory with a copy of the original CARM95.EXE file (for example `/games/carma`). CARM95.EXE must match sha256 `c6040203856b71e6a22d2a29053a1eadd1a2ab41bce97b6031d745079bc07bdf`. + +### Generating an HTML diff + +This is the primary flow for making a change to the code, recompiling it with MSVC, then viewing the diff. + +After running, a `diff.html` file will be created in the build-msvc420 directory. + +```sh +docker run --platform linux/amd64 \ + -e CMAKE_FLAGS="-G Ninja -DCMAKE_BUILD_TYPE=Debug -DMSVC_42_FOR_RECCMP=on" \ + -v :/source \ + -v :/build \ + -v :/orginal:ro \ + msvc420-wine -- \ + reccmp-reccmp --target CARM95 --silent --html diff.html +``` diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 00000000..3b001875 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -e + +export WINEPREFIX=/wineprefix + +# Configure build with CMake +wine cmake -B build source $CMAKE_FLAGS + +# Build +wine cmake --build build -- -j1 + +# Update path to original binary +cd /source +reccmp-project detect --search-path /original + +# Fix up wine paths to underlying linux paths so we can run reccmp outside of wine +cd /build +sed -i 's/Z://g' reccmp-build.yml + +if [ "$#" -gt 0 ]; then + exec "$@" +fi diff --git a/docker/set-env.reg b/docker/set-env.reg new file mode 100644 index 00000000..916afd1c --- /dev/null +++ b/docker/set-env.reg @@ -0,0 +1,8 @@ +Windows Registry Editor Version 5.00 + +[HKEY_CURRENT_USER\Environment] +"INCLUDE"="C:\\msvc\\include;C:\\msvc\\mfc\\include" +"LIB"="C:\\msvc\\lib;C:\\msvc\\mfc\\lib" +"TMP"="Z:\\build" +"TEMP"="Z:\\build" +"PATH"="C:\\msvc\\bin;C:\\msvc\\bin\\winnt;C:\\cmake\\bin;C:\\windows\\system32;C:\\ninja" diff --git a/reccmp-project.yml b/reccmp-project.yml index e96a870b..795e9952 100644 --- a/reccmp-project.yml +++ b/reccmp-project.yml @@ -1,6 +1,6 @@ targets: CARM95: - filename: carm95.exe + filename: CARM95.EXE source_root: src hash: sha256: c6040203856b71e6a22d2a29053a1eadd1a2ab41bce97b6031d745079bc07bdf @@ -147,4 +147,3 @@ targets: "BrQsort", "BrFileRead", ] - diff --git a/src/DETHRACE/CMakeLists.txt b/src/DETHRACE/CMakeLists.txt index ac394b0b..8efea780 100644 --- a/src/DETHRACE/CMakeLists.txt +++ b/src/DETHRACE/CMakeLists.txt @@ -185,8 +185,9 @@ else() endif() # Create our main game binary. -if (MSVC_42_FOR_RECCMP) +if(MSVC_42_FOR_RECCMP) add_executable(dethrace WIN32) + set_target_properties(dethrace PROPERTIES OUTPUT_NAME "CARM95") target_link_options(dethrace PRIVATE /INCREMENTAL:NO /subsystem:windows /ENTRY:mainCRTStartup) reccmp_add_target(dethrace ID CARM95) reccmp_configure()