wiithon.formats.bcsv module
- class wiithon.formats.bcsv.BCSVKey[source]
Bases:
ABCAbstract Base Class for all BCSV Keys.
- class wiithon.formats.bcsv.BCSVNameKey(name)[source]
Bases:
BCSVKeyBCSVKey that uses the field name directly as an input string.
- Parameters:
name (
str)
- class wiithon.formats.bcsv.BCSVHashKey(hash_val)[source]
Bases:
BCSVKeyBCSVKey that uses the field hash as the key string.
- Parameters:
hash_val (
int)
- class wiithon.formats.bcsv.BCSVFieldKey(field)[source]
Bases:
BCSVKeyBCSVKey that uses the entire directly to get the key string.
- Parameters:
field (
BCSVField)
- wiithon.formats.bcsv.calculate_field_hash(field_name)[source]
Field names are stored internally in RAM for GC/Wii games as hashes, as they are faster lookup tables. So, we will calculate the hast and the resulting hash is a 32-bit value. Breaks on first null byte (if any)
- class wiithon.formats.bcsv.BCSVType(*values)[source]
Bases:
IntEnumIndicates the type of data stored in each field.
Strings are deprecated, use
STRING_OFFSETinstead.LONG,SHORTandBYTEvalues must be ANDed with the field’s bitmask, then shifted by the field’s shift amount.LONG/UNSIGNED_LONG— 32-bit integers (signedness unspecified, can be both)FLOAT— 32-bit, read and written as isSHORT— 16-bit integer (signedness unspecified)BYTE— single char / 8-bit integer (signedness unspecified)STRING_OFFSET— offset from the start of the string pool table
- LONG = 0
- STRING = 1
- FLOAT = 2
- UNSIGNED_LONG = 3
- SHORT = 4
- BYTE = 5
- STRING_OFFSET = 6
- class wiithon.formats.bcsv.BCSVTypeSize(*values)[source]
Bases:
IntEnumReturns the size of the field based on its BCSVType.
- WORD = 4
- HALF_WORD = 2
- BYTE = 1
- STRING = 32
- class wiithon.formats.bcsv.StringPoolElement(value, offset)[source]
Bases:
NamedTupleContains a single element when writing to the output string pool table.
- class wiithon.formats.bcsv.BCSVField(field_hash, field_bitmask, field_offset, data_shift, data_type)[source]
Bases:
objectRepresents a single field of data in a BCSV file, similar to a column in a data table.
Fields are indexed by hash and their name defaults to the stringified hash. A
field_hash -> nameconverter function is provided.A BCSV file header is 12 bytes:
Offset
Meaning
0x00Field hash (how a name becomes a hash is unknown)
0x04Field bitmask
0x08Starting byte of the field within a data line
0x0AShift amount applied to the field’s value
0x0BData type, see
BCSVType- Parameters:
- classmethod import_field(raw_bytes)[source]
Creates a given field/header from the raw BytesIO (should be 12 bytes)
- Parameters:
raw_bytes (
BytesIO) – Field bytes
- export_field()[source]
Exports a given field back to bytes (size: 0xC)
- Returns:
The field object back in its bytes format.
- Return type:
- get_value_from_bytes(reader)[source]
Gets the field’s value from a given BCSV entry’s bytes.
- Parameters:
reader (
BinaryReader) – The reader- Returns:
Converted object from bytes into its field_type format.
- Return type:
- set_value_in_buffer(reader, writer, entry_value, string_pool)[source]
Sets the field’s value into a given BCSV entry’s bytes.
- Parameters:
reader (
BinaryReader) – The Binary readerwriter (
BinaryWriter) – The Binary writerentry_value (
int|str|float) – Value to transwer back to bytes.string_pool (
list[StringPoolElement]) – List of strings to write back into the string pool
- class wiithon.formats.bcsv.BCSVEntry[source]
Bases:
dict[str,int|str|float]BCSV entry class which allows for lookup as a string, int (field hash), or as a field directly.
- class wiithon.formats.bcsv.BCSV(fields=None, entries=None)[source]
Bases:
objectBCSV files are table-structured: a header block followed by a data entry block. The structure resembles a modern data table, with one key difference:
The header block defines all field headers (columns) and field data. The order of these definitions does not matter.
The data block contains the rows, one at a time. Each row is a single list index where a dictionary maps the key (column) to the value.
All strings live in a string table appended at the end of the data.
BCSV files start with 16 bytes describing the rest of the file structure.
- classmethod import_bcsv(raw_data, field_names=None, str_fmt='utf-8')[source]
Takes an input stream of BCSV data and converts it into a BCSV object.
- Parameters:
raw_data (
BytesIO) – raw stream of a filefield_names (
dict[int,str], default:None) – Contains the field_hash -> name quick lookup reference. By default, a field’s name is the same as the hash, this allows for human-readable names to be used instead.str_fmt (
str, default:'utf-8') – Output decoding format.
- calculate_data_entry_size()[source]
Calculates the size of the entry based on the field’s data type.
Order of the entry size calculation is:
STRING < FLOAT < LONG < LONG_2 < SHORT < BYTE < STRING_OFFSET
- Returns:
Max field size required when writing.
- Return type:
- add_bcsv_field(bcsv_field, default_value)[source]
Adds a new BCSVField and a default value to all existing data entries.
- remove_bcsv_field(key)[source]
Removes a new BCSVField and a default value to all existing data entries.
- add_bcsv_entry(bcsv_entry)[source]
Adds a new data entry using field names or hashes as keys with complete field validation.
- Parameters:
bcsv_entry (
BCSVEntry) – entry to add into the BCSV
- remove_bcsv_entry(bcsv_entry)[source]
Deletes a BCSVEntry by either the Entry itself or the index number.