AAMP

  • Only version 2, little endian and UTF-8 binary parameter archives are supported.

  • All parameter types including buffers are supported.

  • The YAML output is compatible with the pure Python aamp library.

#include <oead/aamp.h>

Parameters

class Parameter

Parameter.

Note that unlike agl::utl::Parameter the name is not stored as part of the parameter class in order to make the parameter logic simpler and more efficient.

Public Types

enum Type

Values:

Bool = 0
F32
Int
Vec2
Vec3
Vec4
Color
String32
String64
Curve1
Curve2
Curve3
Curve4
BufferInt
BufferF32
String256
Quat
U32
BufferU32
BufferBinary
StringRef
using Value = util::Variant<Type, bool, float, int, Vector2f, Vector3f, Vector4f, Color4f, std::unique_ptr<FixedSafeString<32>>, std::unique_ptr<FixedSafeString<64>>, std::unique_ptr<std::array<Curve, 1>>, std::unique_ptr<std::array<Curve, 2>>, std::unique_ptr<std::array<Curve, 3>>, std::unique_ptr<std::array<Curve, 4>>, std::unique_ptr<std::vector<int>>, std::unique_ptr<std::vector<float>>, std::unique_ptr<FixedSafeString<256>>, Quatf, U32, std::unique_ptr<std::vector<u32>>, std::unique_ptr<std::vector<u8>>, std::unique_ptr<std::string>>

Public Functions

Parameter()
Parameter(const Parameter &other)
Parameter(Parameter &&other)
template<typename T, std::enable_if_t<std::is_constructible_v<Value, T>> * = nullptr>
Parameter(T value)
Parameter(F32 value)
Parameter &operator=(const Parameter &other)
Parameter &operator=(Parameter &&other)
OEAD_DEFINE_FIELDS(Parameter, m_value)
Type GetType() const
template<Type type>
const auto &Get() const
template<Type type>
auto &Get()
std::string_view GetStringView() const

Get the value as a string view. Throws a TypeError if the parameter is not a string.

auto &GetVariant()
const auto &GetVariant() const
struct Name

Parameter structure name. This is a wrapper around a CRC32 hash.

Public Functions

constexpr Name(std::string_view name)
constexpr Name(const char *name)
constexpr Name(u32 name_crc32)
operator u32() const
OEAD_DEFINE_FIELDS(Name, hash)

Public Members

u32 hash

The CRC32 hash of the name.

using oead::aamp::ParameterMap = tsl::ordered_map<Name, Parameter, absl::Hash<Name>, std::equal_to<Name>, std::allocator<std::pair<Name, Parameter>>, std::vector<std::pair<Name, Parameter>>>
using oead::aamp::ParameterObjectMap = tsl::ordered_map<Name, ParameterObject, absl::Hash<Name>, std::equal_to<Name>, std::allocator<std::pair<Name, ParameterObject>>, std::vector<std::pair<Name, ParameterObject>>>
using oead::aamp::ParameterListMap = tsl::ordered_map<Name, ParameterList, absl::Hash<Name>, std::equal_to<Name>, std::allocator<std::pair<Name, ParameterList>>, std::vector<std::pair<Name, ParameterList>>>

Note

oead::aamp::Name can be constructed from either a hash or a string, so it is possible to access elements in a map by name rather than by hash. Both object.params[crc32_hash] and object.params["NameString"] will work.

struct ParameterObject

Parameter object. This is essentially a dictionary of parameters.

Public Functions

OEAD_DEFINE_FIELDS(ParameterObject, params)

Public Members

ParameterMap params
struct ParameterList

Parameter list. This is essentially a dictionary of parameter objects and a dictionary of parameter lists.

Subclassed by oead::aamp::ParameterIO

Public Functions

OEAD_DEFINE_FIELDS(ParameterList, objects, lists)

Public Members

ParameterObjectMap objects
tsl::ordered_map<Name, ParameterList, absl::Hash<Name>, std::equal_to<Name>, std::allocator<std::pair<Name, ParameterList>>, std::vector<std::pair<Name, ParameterList>>> lists

Parameter IO

struct ParameterIO : public oead::aamp::ParameterList

Parameter IO. This is the root parameter list and the only structure that can be serialized to or deserialized from a binary parameter archive.

Public Functions

OEAD_DEFINE_FIELDS(ParameterIO, objects, lists, version, type)
std::vector<u8> ToBinary() const

Serialize the ParameterIO to a binary parameter archive.

std::string ToText() const

Serialize the ParameterIO to a YAML representation.

Public Members

u32 version = 0

Data version (not the AAMP format version). Typically 0.

std::string type

Data type identifier. Typically “xml”.

Public Static Functions

static ParameterIO FromBinary(tcb::span<const u8> data)

Load a ParameterIO from a binary parameter archive.

static ParameterIO FromText(std::string_view yml_text)

Load a ParameterIO from a YAML representation.

Public Static Attributes

constexpr Name ParamRootKey = Name("param_root")

Name utilities

Because binary parameter archives only store CRC32 hashes of structure names, recovering the original names – which is useful for converting archives to a human-readable format – requires the use of a name table.

When serializing to YAML, by default oead will use a table that contains strings from Breath of the Wild’s executable.

struct NameTable

A table of names that is used to recover original names in binary parameter archives which store only name hashes.

Public Functions

NameTable(bool with_botw_strings = false)
std::optional<std::string_view> GetName(u32 hash, int index, u32 parent_name_hash)

Tries to guess the name that is associated with the given hash and index (of the parameter / object / list in its parent).

The table is automatically updated with any newly found names if an indice-based guess was necessary.

std::string_view AddName(std::string name)

Add a known string to the name table.

Return

a view to the added string.

std::string_view AddName(u32 hash, std::string name)

Add a known string to the name table. This should be used if the string’s hash has already been computed in order to avoid recomputing it.

Return

a view to the added string.

void AddNameReference(std::string_view name)

Add a known string to the name table.

Warning

Since this is taking a string view, the actual string data must outlive this table.

Public Members

absl::flat_hash_map<u32, std::string_view> names

Hash to name map. The strings are only references.

absl::flat_hash_map<u32, std::string> owned_names

Hash to name map. The strings are owned.

std::vector<std::string_view> numbered_names

List of numbered names (i.e. names that contain a printf specifier for the index).

NameTable &oead::aamp::GetDefaultNameTable()

Returns the default instance of the name table, which is automatically populated with Breath of the Wild strings. Initialised on first use.