diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4a33e2b9ea..327fc704ae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,6 +59,70 @@ jobs: -Werror=dev cmake --build build -- -k0 + build-with-entropy: + name: 'MSVC 4.20 with entropy' + runs-on: windows-latest + strategy: + matrix: + instance: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + + steps: + - uses: actions/checkout@v4 + + - uses: actions/checkout@v4 + with: + repository: itsmattkc/msvc420 + path: msvc420 + + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v2 + with: + # Use minimum supported version + cmake-version: '3.15.x' + + - name: Patch MSVC 4.2 + run: | + tools/patch_c2.py msvc420/bin/C2.EXE + + - name: Generate Entropy + shell: bash + run: | + # Get the first 8 characters of the SHA (enough for a decent seed) + SHA_PREFIX=$(echo "${{ github.sha }}" | cut -c 1-8) + + tools/entropy.sh $((16#$SHA_PREFIX + ${{ matrix.instance }})) + + - name: Build + shell: cmd + run: | + call .\msvc420\bin\VCVARS32.BAT x86 + cmake -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DISLE_INCLUDE_ENTROPY=ON -G "NMake Makefiles" + cmake --build build + + - name: Upload Artifact + uses: actions/upload-artifact@main + with: + name: Win32-Entropy-${{ matrix.instance }} + path: | + build/CONFIG.EXE + build/CONFIG.PDB + build/ISLE.EXE + build/ISLE.PDB + build/LEGO1.DLL + build/LEGO1.PDB + + merge-entropy-artifacts: + name: 'Merge entropy artifacts' + runs-on: ubuntu-latest + needs: build-with-entropy + steps: + - name: Merge Artifacts + uses: actions/upload-artifact/merge@v4 + with: + name: Win32-Entropy + pattern: Win32-Entropy-* + separate-directories: true + build: name: 'MSVC 4.20' runs-on: windows-latest @@ -102,7 +166,7 @@ jobs: compare: name: Compare with master - needs: [build, fetch-deps] + needs: [build, merge-entropy-artifacts, fetch-deps] runs-on: windows-latest steps: - uses: actions/checkout@main @@ -116,6 +180,11 @@ jobs: name: Win32 path: build + - uses: actions/download-artifact@main + with: + name: Win32-Entropy + path: build-entropy + - name: Restore cached original binaries id: cache-original-binaries uses: actions/cache/restore@v4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 76bdb406cc..c4742403ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,7 @@ option(ISLE_DECOMP_ASSERT "Assert struct size" ${MSVC_FOR_DECOMP}) cmake_dependent_option(ISLE_USE_DX5_LIBS "Build with internal DirectX 5 SDK Libraries" ON ISLE_USE_DX5 OFF) option(ISLE_BUILD_LEGO1 "Build LEGO1.DLL library" ON) option(ISLE_BUILD_BETA10 "Build BETA10.DLL library" OFF) +option(ISLE_INCLUDE_ENTROPY "Build with entropy.h" OFF) if(NOT (ISLE_BUILD_LEGO1 OR ISLE_BUILD_BETA10)) message(FATAL_ERROR "ISLE_BUILD_LEGO1 AND ISLE_BUILD_BETA10 cannot be both disabled") @@ -585,6 +586,12 @@ if (MSVC_FOR_DECOMP) set_property(TARGET isle ${lego1_targets} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endif() + if (ISLE_INCLUDE_ENTROPY) + foreach(tgt IN LISTS lego1_targets beta10_targets) + target_compile_options(${tgt} PRIVATE /FI${PROJECT_SOURCE_DIR}/entropy.h) + endforeach() + endif() + if(TARGET lego1) target_link_options(lego1 PRIVATE "/OPT:REF") # Equivalent to target_compile_options(... PRIVATE "/MT$<$:d>") diff --git a/tools/entropy.sh b/tools/entropy.sh new file mode 100644 index 0000000000..140b6839cc --- /dev/null +++ b/tools/entropy.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# Output file +OUTPUT_FILE="entropy.h" + +# Function to generate a CamelCase string of given length +generate_name() { + local seed="$1" + local length="$2" + local char_count=0 + local random_bytes="" + + while [ "$char_count" -lt "$length" ]; do + random_bytes+=$(od -vAn -N4 -tu4 < /dev/urandom | tr -d '[:space:]') + char_count=$((char_count + 1)) + done + + # Use the provided seed for the random number generation. Crucially, re-seed bash's + # RANDOM for each name. + RANDOM="$seed" + + local result="" + for ((i=0; i" + exit 1 +fi + +SEED="$1" +# Initialize the random number generator with the seed +RANDOM="$SEED" + +# Generate a random number of classes (between 1 and 10) +NUM_CLASSES=$((RANDOM % 10 + 1)) + +> "$OUTPUT_FILE" # Clear or create the output file + +echo "// Seed: $SEED" > "$OUTPUT_FILE" +echo >> "$OUTPUT_FILE" + +for ((i=0; i> "$OUTPUT_FILE" + + # Generate a random number of methods (between 1 and 10) + NUM_METHODS=$((RANDOM % 10 + 1)) + for ((j=0; j> "$OUTPUT_FILE" + done + + echo "};" >> "$OUTPUT_FILE" + echo >> "$OUTPUT_FILE" +done + +echo "Generated $NUM_CLASSES classes in $OUTPUT_FILE using seed $SEED"