Skip to content

Commit 5cce26f

Browse files
author
sourcehold
committed
Merge branch 'main' into reimpl/SHC_3BB0A8C1_0x004CB120
2 parents c5a137a + 24618b4 commit 5cce26f

127 files changed

Lines changed: 3557 additions & 1122 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
11
---
22
BasedOnStyle: WebKit
3-
ColumnLimit: '120'
4-
IndentWidth: '4'
5-
TabWidth: '4'
3+
ColumnLimit: 120
4+
IndentWidth: 4
5+
TabWidth: 4
66
UseTab: Never
77
InsertNewlineAtEOF: true
8-
8+
SpaceInEmptyBraces: Never
9+
PointerAlignment: Left
10+
QualifierAlignment: Custom
11+
QualifierOrder: [inline, static, type, const, volatile]
12+
IncludeBlocks: Regroup
13+
IncludeCategories:
14+
- Regex: ^"\.\./.*\.hpp"$
15+
Priority: 0
16+
SortPriority: 0
17+
- Regex: ^"OpenSHC/.*func\.hpp"$
18+
Priority: 1
19+
SortPriority: 1
20+
- Regex: ^"OpenSHC/Globals/.*"$
21+
Priority: 2
22+
SortPriority: 3
23+
- Regex: ^"OpenSHC/.*"$
24+
Priority: 1
25+
SortPriority: 2
26+
- Regex: ^".*"$
27+
Priority: 3
28+
SortPriority: 4
29+
- Regex: .*
30+
Priority: 3
31+
SortPriority: 5
932
...

.github/workflows/cpp-linter.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
permissions:
1717
pull-requests: write
1818
steps:
19-
- uses: actions/checkout@v5
19+
- uses: actions/checkout@v6
2020

2121
# Detect if any relevant files changed
2222
- name: Detect relevant files
2323
id: filter
24-
uses: dorny/paths-filter@v3
24+
uses: dorny/paths-filter@v4
2525
with:
2626
filters: |
2727
cpp:
@@ -46,7 +46,7 @@ jobs:
4646
env:
4747
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4848
with:
49-
version: 21 # default is 18
49+
version: 22 # default is 18
5050

5151
style: 'file' # Use .clang-format config file.
5252
tidy-checks: '-*' # disable clang-tidy checks.

.github/workflows/docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
jobs:
1212
pages:
13+
if: github.repository == 'sourcehold/OpenSHC'
1314
runs-on: ubuntu-22.04
1415
environment:
1516
name: github-pages

README.md

Lines changed: 104 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,144 @@
1-
# OpenSHC
1+
# OpenSHC [![sourcehold](https://discordapp.com/api/guilds/1259903348077756527/widget.png?style=shield)](https://discord.gg/SKJGEGgPTv)
2+
[Join our Discord Server!](http://discord.gg/SKJGEGgPTv)
23

3-
An open source re-implementation of Stronghold Crusader 1. The beloved Castle Building, Real Time Strategy, and Simulation game remastered.
4+
An open source re-implementation of Stronghold Crusader 1. The beloved Castle Building, Real Time Strategy, and Simulation game reimplemented.
5+
6+
For running and developing this re-implementation, you need to own Stronghold Crusader 1.41 (Latin version), preferably from Steam or GOG.
7+
8+
## Motivation
9+
10+
The original game is a masterpiece, seeing new reignited popularity since the release of the Definitive Edition.
11+
However, the Definitive Edition does not address various shortcomings in the original game.
12+
Furthermore, the new Definitive Edition requires modern hardware to run, which isn't something all fans can afford.
13+
14+
This reimplementation seeks to cater to the wishes of the dedicated community by providing an
15+
open source reimplementation that benefits modding to those that own the original Stronghold Crusader (available from Steam and GOG).
416

517
## Usage
618

7-
### Download and Install
19+
OpenSHC builds as a DLL that is loaded at game start. Functions that have a functionally identical reimplementation are hooked, such that the reimplemented versions are run instead of the original. This enables easy modding, although modding itself is currently beyond the scope of the OpenSHC project.
820

9-
This reimplementation requires you to own a legal copy of the original Stronghold Crusader game from Firefly Studios.
21+
## Contribute
1022

11-
The current method of installation is via the [Unofficial Crusader Patch](https://github.com/UnofficialCrusaderPatch/UnofficialCrusaderPatch). Make sure to set that up first.
23+
The development of this reimplementation is a stepwise process in which we aim to achieve a functionally identical reimplementation. We track progress using various tools.
1224

13-
0. Set up the Unofficial Crusader Patch.
14-
1. Download the latest release of the reimplementation from the Releases page of this repo.
15-
2. Launch the GUI from the Unofficial Crusader Patch.
16-
3. Drag and drop the zip file unto your open UCP3 GUI, or manually move the zip file into the `ucp/modules` folder inside your game folder.
17-
4. Reload the UCP3 GUI and activate the module.
18-
5. Disable Security in the Launch tab of the GUI.
19-
6. Launch the game!
25+
All developers are welcome to contribute.
2026

21-
Note that the goal is to recreate the game. So if there are no changes compared to vanilla, then it is exactly like intended.
27+
### Requirements
2228

23-
### Help
29+
Before you begin, install the following:
2430

25-
Raise an issue here on GitHub to receive support. Or visit the [Discord](https://discord.gg/27W68ZaFT4) server.
31+
* **Stronghold Crusader 1.41 (Latin version)**
32+
33+
The Steam release is the easiest version to obtain. Make sure the game installation uses a Latin-language version such as English or German.
2634

27-
## Contribute
35+
* **CMake 3.24 or later**
36+
37+
You can install it from:
38+
39+
* [https://cmake.org/download/](https://cmake.org/download/)
40+
* [https://github.com/Kitware/CMake/releases/](https://github.com/Kitware/CMake/releases/)
41+
42+
If you already installed the Microsoft Visual C++ Development Tools, you can also install CMake through Visual Studio.
43+
44+
* **Python 3**
45+
46+
* **clang-format 22 or later**
47+
48+
Install it with:
49+
50+
```bash
51+
python -m pip install clang-format
52+
```
53+
54+
* **An IDE with CMake support (recommended)**
55+
56+
The repository is optimized for Visual Studio Code with the Microsoft C/C++ Extension Pack.
57+
58+
To automatically format and style new C++ files, install the clang-format Extension Pack.
59+
60+
---
2861

29-
The development of this reimplementation is a stepwise process. All developers are welcome to contribute.
62+
### Setup
3063

31-
### Approach
64+
#### 1. Clone the repository
3265

33-
The development of this reimplementation primarily focuses on reimplementing functions and data structures of the original game.
34-
The game 1.41 Latin version of the Stronghold Crusader executable serves as the reference point (SHA hash: 012E9D55DAC04B23ED9A334C975D3A5B6287020B).
35-
To achieve this, a combination approach is used. The code has mechanisms in place to allow a compilation to both and executable and a DLL.
36-
The DLL is meant to be loaded by the UCP and only replace certain functions, while other calls would call into the games executable. This allows to reimplement one function after the other while still maintaining a runnable game.
66+
Clone the repository with submodules included:
3767

38-
We use [reccmp](https://github.com/isledecomp/reccmp) to verify compatibility of reimplemented code and the original game.
68+
```bash
69+
git clone --recursive https://github.com/sourcehold/OpenSHC.git
70+
```
3971

40-
Because the original game was compiled using an old compiler, you have to compile it using [this compiler](https://github.com/sourcehold/MSVC1400), which is included in the repository via a submodule.
72+
Then enter the project directory:
4173

42-
If you made any advances or noticed something while implementing, please also add or update the status in [addresses-SHC-3BB0A8C1.txt](status/addresses-SHC-3BB0A8C1.txt).
43-
The structure is simply `<address-enum> | <matching-percent> | <comment>`.
44-
Should the address list change, please run the following command to recreate the file:
45-
```sh
46-
python .\status\extract_header_and_update.py .\src\precomp\addresses-SHC-3BB0A8C1.hpp
74+
```bash
75+
cd OpenSHC
4776
```
48-
Percentages and comments should be kept, but always check the difference.
4977

78+
> The `--recursive` flag is required because the repository depends on submodules, including the compiler.
5079
51-
### Prerequisites
80+
---
5281

53-
1. Stronghold Crusader 1.41 Latin. The Steam version is the easiest one to get, but any patched version will do. Make sure the installation uses a Latin version (English, German, etc).
54-
2. CMake with the minimum version 3.24.
55-
3. [Python3](https://www.python.org/)
56-
4. A way to execute `clang-format`
57-
5. (Recommended) An IDE with CMake integration. The repository has been optimized for Visual Studio Code using the [Microsoft C/C++ Extension Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack).
82+
#### 2. Create a symbolic link to the original game
5883

59-
### Setup
84+
Run the following command:
6085

61-
1. Clone the repository. Make sure to also pull the submodules to have the compiler included:
86+
```bash
87+
softlink.bat
88+
```
6289

63-
```sh
64-
git clone --recursive https://github.com/sourcehold/OpenSHC.git
65-
```
90+
The script will ask for the full path to your Stronghold Crusader installation directory.
6691

67-
- 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.
92+
After the link is created, a folder named `_original` will appear in the repository root.
6893

69-
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.
70-
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)
94+
> This script may require administrator privileges to be able to create the symbolic link
7195
72-
### Development
96+
---
7397

74-
The build can be run using the dev tools of the preferred IDE or via the build scripts. Regardless, a CMake installation is required.
98+
#### 3. Set up the Python environment for binary comparison
99+
100+
To set up the binary comparison tools, run:
101+
102+
```bash
103+
reccmp\dll\setup.bat
104+
```
75105

76-
Visual Studio Code with the proper extensions only needs to open the folder and the targets can be chosen in the "CMake" menu.
77-
Additionally, it configures format-on-save and a debug target for the UCP3.
106+
> In the future, if you want to setup comparison of the reimplemented executable instead of the DLL, use:
107+
> ```bash
108+
> reccmp\exe\setup.bat
109+
> ```
78110
79-
If the scripts are preferred, the following triggers a build using the scripts:
111+
---
80112
81-
1. Open a terminal.
82-
2. Navigate to this project folder
83-
3. Execute build.bat:
84-
```sh
85-
build.bat RelWithDebInfo
86-
```
87-
4. Compare a function byte by byte to the OpenSHC.dll to check compilation:
88-
```sh
89-
reccmp/dll/run reccmp-reccmp --target STRONGHOLDCRUSADER --verbose 0x401000
90-
```
113+
### Verifying the Setup
91114
92-
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.
115+
If **both** commands complete successfully, your development environment is ready and you can start working on OpenSHC.
93116
94-
Note that any code needs to be formatted properly using the provided `clang-format`. The way to do so it up to the developer. Many IDEs support it out of the box.
117+
#### 1. Build the project
95118
96-
If any `.cpp` or `.c` files are added to the source code, they should be listed in one of the txt files in `cmake/`:
119+
From the `OpenSHC` directory, run:
97120
98-
- `cmake/core-sources.txt` containing the core sources to compile the project.
99-
- `cmake/pklib-sources.txt` containing the source files for compiling the pklib dependency.
100-
- `cmake/openshc-sources.txt` containing the files with reimplementations of the original game's functions.
121+
```bash
122+
build.bat RelWithDebInfo OpenSHC.dll
123+
```
124+
125+
---
126+
127+
#### 2. Run binary comparison
128+
129+
This verifies byte-level accuracy between the reimplementation and the original binary:
130+
131+
```bash
132+
reccmp/dll/run reccmp-reccmp --target STRONGHOLDCRUSADER
133+
```
101134

102-
You can also create a local only `cmake/openshc-sources.txt.local` file, which will be used instead of `cmake/openshc-sources.txt` if it exists, to allow faster tests.
103-
Extending this files name in any way, like `openshc-sources.txt.local.bak`, will prevent it from being used, but it is still ignored by git. This allows to keep small local file lists.
135+
> Tip: use `reccmp/dll/run reccmp-reccmp --target STRONGHOLDCRUSADER --verbose <hex address of function>` to investigate code byte mismatches.
104136
105-
#### Manual configuration
137+
---
106138

107-
The file `build.bat` exists for convenience. If you want more control, you can specify the following cmake options.
139+
## Tutorials
140+
When you are set up, follow any of the [tutorials](https://sourcehold.github.io/OpenSHC/wiki/tutorials/reimplementation-tutorial-1.html) to get you started!
108141

109-
##### Building
110142

111-
Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.dll` will create the dll in `build-RelWithDebInfo/DLL`.
112-
Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.exe` will create the exe in `build-RelWithDebInfo/EXE`.
113-
Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.dll.deploy` will prepare the modules folder in the UCP setup of the bound SHC.
114-
Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.exe.runnable` will prepare the runtime folder of the exe to make it runnable.
143+
## Help
144+
Raise an issue here on GitHub to receive support. Or visit the [Discord](https://discord.gg/SKJGEGgPTv) server.

0 commit comments

Comments
 (0)