pyctr.type.config.save module

exception pyctr.type.config.save.ConfigSaveError[source]

Bases: PyCTRError

Generic error for Config Save operations.

exception pyctr.type.config.save.InvalidConfigSaveError[source]

Bases: ConfigSaveError

Config Save is corrupted.

exception pyctr.type.config.save.OutOfSpaceConfigSaveError[source]

Bases: ConfigSaveError

Config Save generation ran out of space for data.

exception pyctr.type.config.save.BlockFlagsNotAllowed(flags)[source]

Bases: ConfigSaveError

Flags not allowed. Must be 8, 12, 10, or 14 (0x8, 0xC, 0xA, or 0xE).

Parameters:

flags (int)

exception pyctr.type.config.save.BlockIDNotFoundError(block_id)[source]

Bases: ConfigSaveError

Block ID not found.

Parameters:

block_id (int)

exception pyctr.type.config.save.InvalidBlockDataError[source]

Bases: ConfigSaveError

Block data was invalid (like flags or size)

class pyctr.type.config.save.BlockInfo(flags, data)[source]

Bases: NamedTuple

Parameters:
flags: int

Alias for field number 0

data: bytes

Alias for field number 1

class pyctr.type.config.save.ConfigSaveReader[source]

Bases: object

Class for 3DS Config Save.

https://www.3dbrew.org/wiki/Config_Savegame

blocks: dict[int, BlockInfo]
to_bytes()[source]

Converts the object to a raw config save file.

CFG adds new block from end to start of file for any block > 4 bytes. Any block <= 4 bytes only get a block entry.

Note that this may not result in bit-for-bit the same as the input file due to garbage in unused parts of the file that this doesn’t load.

Returns:

Raw config save data.

Return type:

bytes

save(fn)[source]

Save the config save to a file.

Parameters:

fn (FilePath) – File path to write to.

set_block(block_id, data, flags=None, *, strict=True)[source]

Sets or adds a config block.

Parameters:
  • block_id (int) – Block ID.

  • data (bytes) – Block data.

  • flags (int) – Block flags, determining access permissions. Must be 8, 12, 10, or 14 (0x8, 0xC, 0xA, or 0xE). Defaults to the known flags for the Block ID if it doesn’t exist.

  • strict (bool) – Only allow known Block IDs and their sizes and flags. This list is in KNOWN_BLOCKS. Setting this to False will allow using any Block ID with any data size, but flags must still be of the four allowed.

get_block(block_id)[source]

Gets a config block.

Parameters:

block_id (int) – Block ID.

Returns:

Block info.

Return type:

BlockInfo

remove_block(block_id)[source]

Removes a config block.

Parameters:

block_id (int) – Block ID.

classmethod load(fp)[source]
Parameters:

fp (BinaryIO)

classmethod from_file(fn, *, fs)[source]
Parameters:
  • fn (FilePath)

  • fs (FS | None)