Skip to content

Latest commit

 

History

History
100 lines (73 loc) · 3.27 KB

README.md

File metadata and controls

100 lines (73 loc) · 3.27 KB

DSP Save Parser

A python based save data parser for Dyson Sphere Program.

Current version: 0.10.32.25699 (Updated on 19 Feb, 2025)

Usage

Parse DSV file (deserialization)

Example:

import dsp_save_parser as s

with open('your_save_data.dsv', 'rb') as f:
    print(s.GameSave.parse(f))

main.py provides a basic skeleton structure for parsing a DSP save file: run python main.py [save_data_path] and it would print something like:

<GameSave [0-73086344] (header=<VFSaveHeader>, file_length=73086344, version=7, is_sandbox_mode=0, is_peace_mode=0, major_game_version=0, minor_game_version=10, release_game_version=32, build_game_version=25699, game_tick=13953330, now_ticks=638757505537597567, size_of_png_file=228663, screen_shot_png_file=<bytes>, account_data=<AccountData>, dyson_sphere_energy_gen_current_tick=49606866, game_data=<GameData>)>

If save_data_path is not specified, the program will use the last exit save data ~\Documents\Dyson Sphere Program\Save\_lastexit_.dsv by default.

A more advanced one -- exporting vein amounts for all explored planets:

from enum import IntEnum
from collections import defaultdict


class EVeinType(IntEnum):
    NONE = 0
    Iron = 1
    Copper = 2
    Silicium = 3
    Titanium = 4
    Stone = 5
    Coal = 6
    Oil = 7
    Fireice = 8
    Diamond = 9
    Fractal = 10
    Crysrub = 11
    Grat = 12
    Bamboo = 13
    Mag = 14
    MAX = 15


with open('xxx.dsv', 'rb') as f:
    data = s.GameSave.parse(f)
    for factory in data.game_data.factories:
        amount_dict = defaultdict(int)
        # from 0.9.27: "factory.planet.vein_amounts" is not used and keeps zero
        for vein_data in factory.vein_pool:
            if vein_data.id == 0:
                continue
            amount_dict[vein_data.type] += vein_data.amount
        amount_dict = {EVeinType(k).name: v for k, v in amount_dict.items()}
        print(factory.planet_id, factory.planet_theme, amount_dict)

Export to DSV file (serialization)

Write access is now supported. Here is an example:

import dsp_save_parser as s

with open('your_save_data.dsv', 'rb') as f:
    data = s.GameSave.parse(f)

# do some modifications, for example:
data.account_data.user_name = 'my_name'  # change player's name
data.game_data.main_player.sand_count = 99999999  # modify sands
# if your changes affect the size of the save data, don't forget to re-calculate the whole file length
data.file_length = len(data)

# save changes
with open('your_modded_save_data.dsv', 'wb') as f:
    data.save(f)

Type casting for basic data types (uints, ints, floats, strings and their arrays) is automatically executed during calling save method.

If you changed the element counts in an array, don't forget to change its length attribute of the array:

data.game_data.game_desc.saved_theme_ids.pop()  # remove element
data.game_data.game_desc.num_saved_theme_ids -= 1  # also decrease the array length manually

Save data file structure

Refers to save_format.txt for detail. It should be quite straightforward and easy-understanding, maybe?

As for the meaning of each field, ask the developers rather than me.