sourcehold / sourcehold-maps

Reverse engineering the map file format of Stronghold
GNU General Public License v3.0
20 stars 3 forks source link

sourcehold-maps Discord

Reverse engineering the map file format of the 2D Stronghold Games.

Project Goal

The goal is to understand the map file format of Stronghold, Stronghold Crusader and Stronghold Crusader Extreme and to be able to manipulate it.

Table of Contents

Map File Format

The current knowledge of the map file format (*.map, *.sav and *.msv) is documented in a human-readable form in the wiki and in a machine-readable form in here.

Tools

Online Map Unpacking, Repacking and Exploring

If you don't want to install the python library and jump directly into action, there is an online tool to unpack, repack and visualize map sections.

Python Library

The python library contains multiple useful tools to interact with map files. The most important tools are directly accessible using the command line (CL), but most of the stuff is access

Unpacking (CL)

Unpack map files to a folder:

python -m sourcehold --in "mymap.map" "mymap2.map" "mysav.sav" --unpack

Unpack single sections:

python -m sourcehold --in "mymap.map" "mysave.sav" --unpack --what 1107

(Re-) Packing (CL)

Repack map folder to a file:

python -m sourcehold --in "mymap/" "mymap2/" "mysav/" --pack

Generate Images of Map Sections (CL)

python examples/map_section_imaging.py "mymap.map" "mymap_images"

Map Preview Image (CL)

Extract an image:

python examples/map_preview_image.py extract "mymap.map" "mymap.png"

Substitute an image:

python examples/map_preview_image.py replace "mymap.map" --replacement "mymap.png" "mymap_modified.map"

Modify Map Properties

Disable buildings:

from sourcehold import load_map, expand_var_path, save_map
# You can configure your installation folder (where shcmap points to) in /config.json
map = load_map(expand_var_path('shcmap~/mymap.map'))
map.directory["building_availability"].granary = False
save_map(map, expand_var_path('shcusermap~/mymap_modified.map'))

Set starting popularity and goods:

from sourcehold import load_map, expand_var_path, save_map
map = load_map(expand_var_path('shcmap~/mymap.map'))
map.directory['STARTING_GOODS'].wood = 0
save_map(map, expand_var_path('shcusermap~/mymap_modified.map'))

Installation

Find the right wheel file for your OS and (python) architecture here (download the artifacts of the latest successful build). Then install using pip:

python -m pip install sourcehold.whl

Contribute

There are multiple ways to contribute to this project, see Contributing.md for more information.