gsheet

#include <oead/gsheet.h>

For more information about Grezzo datasheets, refer to the wiki article.

Read-only API and binary format structs

This API is used to read binary datasheets efficiently.

In line with Nintendo’s naming conventions, structs that are directly used in the binary format have a Res prefix in their name.

struct ResHeader

Public Members

std::array<char, 4> magic = Magic
int version = 1
u32 hash = 0

Unknown - probably some kind of hash or ID?

u8 bool_size = 1
u8 pointer_size = 8
u8 alignment = 8
const char *name
u32 num_root_fields
u32 num_fields
void *values
u32 num_values
u32 value_size
struct ResField

Grezzo datasheet field (serialized).

Public Types

using Type = Field::Type
using Flag = Field::Flag

Public Functions

ResField()
tcb::span<ResField> GetFields() const

Public Members

const char *name

Name (guaranteed to be non-null).

const char *type_name

Type name.

Type type

Field type.

u8 x11

Unknown; depth level?

util::Flags<Flag> flags

Flags.

u16 offset_in_value

Offset of this field in the value structure.

u16 inline_size

Size of this field in the value structure. For strings and arrays, this is always 0x10.

u16 data_size

Size of the field data. For strings and inline types (inline structs, ints, floats, bools), this is the same as the size in the value structure.

u16 num_fields

[For structs] Number of fields

ResField *fields

[For structs] Fields

ResField *parent

[For structs] Parent field (filled in during parsing; always 0xdeadbeefdeadbeef when serialized)

class Sheet

Grezzo datasheet.

To actually access values that are stored in a binary datasheet, users are intended to define C++ structures and cast value pointers to the appropriate structure type.

See also SheetRw for a version of this class that allows for reflection and modifications.

Public Types

using IntMap = absl::flat_hash_map<int, void *>
using StringMap = absl::flat_hash_map<std::string_view, void *>

Public Functions

Sheet(tcb::span<u8> data)
ResHeader &GetHeader() const
std::string_view GetName() const
tcb::span<ResField> GetRootFields() const

Get the datasheet root fields.

tcb::span<ResField> GetAllFields() const

Get every single datasheet field (including nested fields).

auto GetValues() const

Get the datasheet values (as an iterable).

const IntMap &GetIntMap() const
const StringMap &GetStringMap() const
FieldMap MakeFieldMap() const
SheetRw MakeRw() const
using oead::gsheet::FieldMap = absl::flat_hash_map<std::string_view, ResField *>
FieldMap oead::gsheet::MakeFieldMap(tcb::span<ResField> fields)

Utilities for defining datasheet structures

These are useful to define structures which datasheet values can be casted to.

template<typename T>
struct Nullable

For defining datasheet structures.

Public Members

T *data = nullptr

Nullptr if no value.

template<typename T>
struct Array

For defining datasheet structures.

Public Functions

tcb::span<T> Span() const
operator tcb::span<T>() const

Public Members

T *data = nullptr
u32 size = 0
struct String

For defining datasheet structures.

Public Functions

std::string_view Str() const
operator std::string_view() const

Public Members

const char *data = nullptr
u32 size = 0

Read-write API

This API is used to read, modify and write binary datasheets. Datasheets can also be constructed from scratch.

struct Field

Grezzo datasheet field.

Public Types

enum Type

Values:

Struct = 0

C/C++ style structure.

Bool = 1

Boolean.

Int = 2

Signed 32-bit integer.

Float = 3

Single-precision floating point number (binary32).

String = 4

Null-terminated string.

enum Flag

Values:

IsNullable = 1 << 0
IsArray = 1 << 1
IsKey = 1 << 2
Unknown3 = 1 << 3
IsEnum = 1 << 4
Unknown5 = 1 << 5

Public Functions

Field()
Field(const ResField &raw)
constexpr auto ReflectionFields() const

Public Members

std::string name

Name (must not be empty).

std::string type_name

Type name.

Type type

Field type.

u8 x11

Unknown; depth level?

util::Flags<Flag> flags

Flags.

u16 offset_in_value

Offset of this field in the value structure.

u16 inline_size

Size of this field in the value structure. For strings and arrays, this is always 0x10.

u16 data_size

Size of the field data. For strings and inline types (inline structs, ints, floats, bools), this is the same as the size in the value structure.

std::vector<Field> fields

[For structs] Fields

Friends

bool operator==(const Field &a, const Field &b)
struct Data

Represents a piece of field data in a datasheet.

Public Types

enum Type

Values:

Struct
Bool
Int
Float
String
StructArray
BoolArray
IntArray
FloatArray
StringArray
Null
using Null = std::nullptr_t
using Struct = absl::flat_hash_map<std::string, Data>

A struct is represented as a string to Value map, with the field names as keys.

using Variant = util::Variant<Type, std::unique_ptr<Struct>, bool, int, float, std::unique_ptr<std::string>, std::unique_ptr<std::vector<Struct>>, std::unique_ptr<std::vector<bool>>, std::unique_ptr<std::vector<int>>, std::unique_ptr<std::vector<float>>, std::unique_ptr<std::vector<std::string>>, Null>

Public Functions

Data()
Data(const void *raw, const Field &field, bool ignore_array_flag = false, bool ignore_nullable_flag = false)
template<typename T, std::enable_if_t<std::is_constructible_v<Variant, T>> * = nullptr>
Data(T value)
Data(const Data &other)
Data(Data &&other)
Data &operator=(const Data &other)
Data &operator=(Data &&other)
constexpr bool IsNull() const
constexpr bool IsArray() const
template<typename Callable>
auto VisitArray(Callable &&fn) const

Public Members

Variant v
struct SheetRw

Grezzo datasheet.

This allows reading and writing binary datasheets and data modifications. For a readonly parser, see the Sheet class.

Public Functions

std::vector<u8> ToBinary() const

Serialize the datasheet to the v1 binary format.

Public Members

u8 alignment = 8
u32 hash = 0
std::string name
std::vector<Field> root_fields
std::vector<Data::Struct> values