Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
### OpenSHC
# Ignore build artifacts
build-*/
build/
_build/
build.bat
build.ps1
build.py
dist/
# Ignore scratch files
tmp/
# Ignore binary files and export files created from reverse engineering programs
/*.7z
/*.sarif
/*.bin
# Ignore the reccmp results overview
/reccmp/**/*.json

# Softlink to game installation
_original
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/shfolder.dll" "$<TARG



# Place the dll and its pdb in the OpenSHC module folder for live testing
set(OPEN_SHC_DLL_DEST "${CRUSADER_DIR}/ucp/modules/${OPEN_SHC_NAME}-${OPEN_SHC_VERSION}" CACHE PATH "Path for OpenSHC.dll and OpenSHC.pdb")

add_library(OpenSHC.dll SHARED src/entry.cpp ${CORE_SOURCES} ${OPENSHC_SOURCES})
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ Because the original game was compiled using an old compiler, you have to compil
### Setup

1. Clone the repository. Make sure to also pull the submodules to have the compiler included:

```sh
git clone --recursive https://github.com/sourcehold/OpenSHC.git
```

- Should NET Framework 3.5 be required, it can be easily installed on Windows 11 by running `mt.exe` (from the MSVC1400 repo), Windows 11 will ask to install the right version.

2. Create a softlink to the original game executable with the name `_original` by running [softlink.bat](softlink.bat). It will request the full path to the game folder.
3. Setup the needed Python environment to run `reccmp` for binary comparison by running [setup.bat](reccmp/setup.bat) in the reccmp folder.
3. Setup the needed Python environment to run `reccmp` for binary comparison by running [setup.bat](reccmp/dll/setup.bat) in the reccmp/dll folder (or the `setup.bat` in the reccmp/exe folder if binary comparison on the reimplemented .exe file is preferred)

### Development

Expand All @@ -72,9 +75,9 @@ If the scripts are preferred, the following triggers a build using the scripts:
```sh
build.bat RelWithDebInfo
```
4. Compare a function byte by byte to check compilation:
4. Compare a function byte by byte to the OpenSHC.dll to check compilation:
```sh
reccmp/run reccmp-reccmp --target STRONGHOLDCRUSADER --verbose 0x401000
reccmp/dll/run reccmp-reccmp --target STRONGHOLDCRUSADER --verbose 0x401000
```

If CMake is installed and not in PATH, for example if installed via Visual Studio, `cmakew.bat` can be used instead. It tries to detect a CMake installation and uses it.
Expand Down
5 changes: 5 additions & 0 deletions reccmp/dll/reccmp-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
project: .
targets:
STRONGHOLDCRUSADER:
path: ../../_original/ucp/modules/OpenSHC-1.41.0/OpenSHC.dll
pdb: ../../_original/ucp/modules/OpenSHC-1.41.0/OpenSHC.pdb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
targets:
STRONGHOLDCRUSADER:
filename: Stronghold Crusader.exe
source_root: ../src
source_root: ../../src
hash:
sha256: 3bb0a8c1e72331b3a30a5aa93ed94beca0081b476b04c1960e26d5b45387ac5a
data_sources: []
Expand Down
3 changes: 3 additions & 0 deletions reccmp/dll/reccmp-user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
targets:
STRONGHOLDCRUSADER:
path: ../../_original/Stronghold Crusader.exe
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions reccmp/exe/reccmp-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
project: .
targets:
STRONGHOLDCRUSADER:
path: ../../build-RelWithDebInfo/OpenSHC.exe
pdb: ../../build-RelWithDebInfo/OpenSHC.pdb
14 changes: 14 additions & 0 deletions reccmp/exe/reccmp-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
targets:
STRONGHOLDCRUSADER:
filename: Stronghold Crusader.exe
source_root: ../../src
hash:
sha256: 3bb0a8c1e72331b3a30a5aa93ed94beca0081b476b04c1960e26d5b45387ac5a
data_sources: []
ghidra:
ignore_types: []
ignore_functions: []
name_substitutions: []
allow_hash_mismatch: false
report:
ignore_functions: []
3 changes: 3 additions & 0 deletions reccmp/exe/reccmp-user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
targets:
STRONGHOLDCRUSADER:
path: ../../_original/Stronghold Crusader.exe
1 change: 1 addition & 0 deletions reccmp/exe/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git+https://github.com/isledecomp/reccmp
89 changes: 89 additions & 0 deletions reccmp/exe/run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
@echo off
setlocal

:: === Configuration ===
set "VENV_DIR=.venv"
set "ENV_ACTIVE=0"
set "CMD_EXIT_CODE=0"

:: --------------------------------------------
:: Change working directory to script location
:: --------------------------------------------
cd /d "%~dp0" || (
echo [ERROR] Failed to set working directory to script location.
call :Cleanup
exit /b 1
)

:: --------------------------------------------
:: Check arguments
:: --------------------------------------------
if "%~1"=="" (
echo [ERROR] No command provided.
echo Usage: %~nx0 command [args...]
call :Cleanup
exit /b 1
)

:: --------------------------------------------
:: Check virtual environment exists
:: --------------------------------------------
if not exist "%VENV_DIR%\Scripts\activate.bat" (
echo [ERROR] Virtual environment not found: %VENV_DIR%
echo Please run the setup script first.
call :Cleanup
exit /b 1
)

:: --------------------------------------------
:: Prevent double-activation
:: --------------------------------------------
if /i "%VIRTUAL_ENV%"=="%CD%\%VENV_DIR%" (
echo [ERROR] Already running inside the target virtual environment.
call :Cleanup
exit /b 1
)

:: --------------------------------------------
:: Activate virtual environment
:: --------------------------------------------
call "%VENV_DIR%\Scripts\activate.bat"
if /i not "%VIRTUAL_ENV%"=="%CD%\%VENV_DIR%" (
echo [ERROR] Failed to activate virtual environment.
call :Cleanup
exit /b 1
)

set "ENV_ACTIVE=1"
echo [OK] Virtual environment activated.

:: --------------------------------------------
:: Run provided command
:: --------------------------------------------
echo [INFO] Running command: %*
cmd /c %*
set "CMD_EXIT_CODE=%ERRORLEVEL%"
if %CMD_EXIT_CODE% neq 0 (
echo [ERROR] Command failed with exit code %CMD_EXIT_CODE%.
call :Cleanup
exit /b %CMD_EXIT_CODE%
)

:: --------------------------------------------
:: Cleanup
:: --------------------------------------------
call :Cleanup

echo [SUCCESS] Command completed successfully.
exit /b 0

:: --------------------------------------------
:: Cleanup function
:: --------------------------------------------
:Cleanup
if "%ENV_ACTIVE%"=="1" (
deactivate
set "ENV_ACTIVE=0"
echo [OK] Virtual environment deactivated.
)
exit /b 0
94 changes: 94 additions & 0 deletions reccmp/exe/setup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
@echo off
setlocal

:: === Configuration ===
set "VENV_DIR=.venv"
set "REQ_FILE=requirements.txt"
set "ENV_ACTIVE=0"

:: --- Change working directory to the folder where the script is located ---
cd /d "%~dp0" || (
echo [ERROR] Failed to set working directory to script location: %~dp0
call :Cleanup
exit /b 1
)

:: --------------------------------------------
:: Check if not running in own env
:: --------------------------------------------
if /i "%VIRTUAL_ENV%"=="%CD%\%VENV_DIR%" (
echo [ERROR] This script is already running inside the target virtual environment.
exit /b 1
)

:: --------------------------------------------
:: Check for Python installation
:: --------------------------------------------
python --version >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Python is not installed or not in PATH.
call :Cleanup
exit /b 1
)
echo [OK] Python is available.

:: --------------------------------------------
:: Create virtual environment
:: --------------------------------------------
echo Creating virtual environment in "%VENV_DIR%"...
python -m venv "%VENV_DIR%"
if %errorlevel% neq 0 (
echo [ERROR] Failed to create virtual environment.
call :Cleanup
exit /b 1
)

:: --------------------------------------------
:: Activate virtual environment
:: --------------------------------------------
call "%VENV_DIR%\Scripts\activate.bat"
if /i not "%VIRTUAL_ENV%"=="%CD%\%VENV_DIR%" (
echo [ERROR] Failed to activate virtual environment.
call :Cleanup
exit /b 1
)
set "ENV_ACTIVE=1"
echo [OK] Virtual environment activated.

:: --------------------------------------------
:: Install requirements
:: --------------------------------------------
if not exist "%REQ_FILE%" (
echo [ERROR] Requirements file not found: %REQ_FILE%
call :Cleanup
exit /b 1
)

echo Installing packages from "%REQ_FILE%"...
pip install -r "%REQ_FILE%"
if %errorlevel% neq 0 (
echo [ERROR] Failed to install packages.
call :Cleanup
exit /b 1
)
echo [OK] All packages installed successfully.

:: --------------------------------------------
:: Normal cleanup
:: --------------------------------------------
call :Cleanup

echo [SUCCESS] Setup complete.
endlocal
exit /b 0

:: --------------------------------------------
:: Cleanup function
:: --------------------------------------------
:Cleanup
if "%ENV_ACTIVE%"=="1" (
deactivate
set "ENV_ACTIVE=0"
echo [OK] Virtual environment deactivated.
)
exit /b 0
5 changes: 0 additions & 5 deletions reccmp/reccmp-build.yml

This file was deleted.

3 changes: 0 additions & 3 deletions reccmp/reccmp-user.yml

This file was deleted.

Loading