Various tools for StarCraft 2 map making.
- Download and install Python 3.14.3 or a higher version of Python 3.14.
- Open terminal in the root directory of this repository.
- Initialize virtual environment in directory
.venvand activate it according to the tutorial. - Run
python -m pip install -U pip plyto install necessary packages.
Extracts StarCraft 2 maps from Battle.net cache. Requires MPQ Editor for the work.
fromsc2.map_extractorimportMapExtractorextractor=MapExtractor('E:\\Software\\MPQ Editor\\MPQEditor.exe', '.data')
forpath, nameinextractor.get_map_paths_with_names().items():
print(f'{path.stem}: {name!r}')Given the path to the map file in Battle.net cache or just map's hash, extractor can extract map's contents to the working directory.
fromsc2.map_extractorimportMapExtractormpq_editor_work_dir='.data'extractor=MapExtractor('E:\\Software\\MPQ Editor\\MPQEditor.exe', mpq_editor_work_dir)
map_hash='78b514b5abcc568c7e94cd78c55a02c9fee93d05ae86694bf488c40949d926e5'extractor.extract_map_by_hash(map_hash)For more control over where and what to extract use method extract_map_contents.
Almost complete Galaxy compiler that checks syntax, performs type checking and generates AST.
Syntax errors and errors with include statements (file not found or circular reference)
raise sc2.galaxy.parser.GalaxyParsingError.
All other errors are logged using standard Python logging with error severity.
There are a couple of warnings as well.
Once AST is formed, the code can be formatted using sc2.galaxy.formatter.GalaxyFormatter.
Note: because Galaxy parser ignores comments, spaces and newlines,
all of them are lost after reformatting.
fromsc2.galaxy.parserimportparse_filefromsc2.galaxy.formatterimportGalaxyFormatter, FormattingRuleslookup_dirs= [
'.data/mods',
'.data/campaigns',
]
script_path='.data/78b514b5abcc568c7e94cd78c55a02c9fee93d05ae86694bf488c40949d926e5/MapScript.galaxy'ast=parse_file(script_path, lookup_directories=lookup_dirs)
rules=FormattingRules(empty_lines_between_multiline_globals=2)
formatter=GalaxyFormatter(rules)
formatted_code=formatter.format_ast(ast)
withopen(script_path, 'w') asf:
f.write(formatted_code)A simple interface for loading strings from files, updating string and then saving them back with full support of comments.
Here's an example of loading game strings in English, updating map's name and saving strings back.
fromsc2.stringsimport*game_string_file= (
'.data/78b514b5abcc568c7e94cd78c55a02c9fee93d05ae86694bf488c40949d926e5''/enUS.SC2Data/LocalizedData/GameStrings.txt'
)
game_strings=create_strings_mapping_from_files(game_string_file)
map_name=game_strings['DocInfo/Name']
map_name.value='New cool name'map_name.comment='New cool comment'save_strings_mapping_to_file(game_strings, game_string_file)