Skip to main content

CustomizationWrapperSerializer

A static class in Root.Township, Alta.Customization.

Static helpers that write and read a player's cosmetics as a bit stream (item hashes plus their colour arguments), for saving presets and syncing to other players.

Fields​

1 private and internal field
MemberWhat it is
private static readonly Logger loggerLogger for this class.

Methods​

MemberWhat it is
static async Task<bool> LoadAsync(ICustomizationWrapper wrapper, CosmeticPresetData data)Loads cosmetics from saved data into the wrapper. Returns false on bad data, an error or a cancelled load.
static async Task<bool> LoadAsync(ICustomizationWrapper wrapper, uint[] data, int bytes)Loads cosmetics from saved data into the wrapper. Returns false on bad data, an error or a cancelled load.
static async Task ReadStreamAsync(ICustomizationWrapper wrapper, StreamReader stream, bool isApplying = true, CancellationToken cancellation = null)Reads item hashes and arguments from a stream; when applying, fills in missing defaults and applies the items to the wrapper. Throws on an unknown hash.
static void Save(ICustomizationWrapper wrapper, out int bytes, out uint[] data)Writes the wrapper's cosmetics to a new buffer and returns its byte count and data.
static void SerializeArguments(Stream stream, uint definitionHash, CustomizationArguments[] arguments)Writes or reads an item's arguments with a size prefix. On a size mismatch it skips the bits, except for two hashes it converts from an older format.
static async Task SerializeStreamAsync(ICustomizationWrapper wrapper, Stream stream, bool isApplying = true, CancellationToken cancellation = null)Writes the wrapper, or reads into it inside an addressable loading session (clearing it first when applying).
static void WriteStream(ICustomizationWrapper wrapper, StreamWriter stream)Writes every item and its arguments, or only whitelisted categories if UseCategoryWhitelistWhenSaving is on.
5 private and internal methods
MemberWhat it is
private static void AddDefaultItem(ICollection<CustomizationItemAndArguments> results, ICustomizationDefinition definition, CustomizationArguments[] arguments = null)Adds a default item to the results unless something in its category (or the item itself) is already there.
private static void ForceBasicBodyParts(ICustomizationWrapper wrapper, List<CustomizationItemAndArguments> results)Adds any required default body parts missing from the loaded items.
private static Dictionary<ItemCategory, DefaultCosmeticInfo> GetDefaults(ICustomizationWrapper wrapper)Gets the required defaults per category from CustomizationSettings, swapped for the wrapper's override items where they match.
private static IEnumerable<DefaultCosmeticInfo> GetMissingDefaults(IReadOnlyCollection<CustomizationItemAndArguments> loadedItems, IReadOnlyDictionary<ItemCategory, DefaultCosmeticInfo> defaults)Lists required defaults whose category has no loaded item.
private static void WriteStreamRestricted(ICustomizationWrapper wrapper, StreamWriter stream)Writes only items in the debug category whitelist.