Table of Contents

Class SimDataModel

Namespace
LlamaLogic.Packages.Models.SimData
Assembly
LlamaLogic.Packages.dll

Represents a SimData resource (🔓)

public sealed class SimDataModel : Model, IModel<SimDataModel>, IModel
Inheritance
SimDataModel
Implements
Inherited Members

Remarks

A SimData resource is a set of named Instances, each an object described by a SimDataSchema whose values may refer to further objects, strings, vectors and variants. Decode(ReadOnlyMemory<byte>) reads any well-formed layout, including those written by community tools, and reads a reference whose offset is zero (which could only refer to itself, and which some community tools write) as null. It rejects a resource in which a row is referred to more than once, which Maxis never writes and which the model, being a tree, cannot represent. Encode() always lays the resource out the way Maxis does, so decoding and encoding a resource Maxis wrote reproduces it byte for byte.

Properties

Instances

Gets the named, top-level objects of the resource

public Collection<SimDataInstance> Instances { get; }

Property Value

Collection<SimDataInstance>

Pack

Gets/sets the pack to which the resource belongs, which is the mUnused field of the resource's header (ignored for SmartSimOriginalEdition)

public uint Pack { get; set; }

Property Value

uint

Remarks

The value is that of the game's sims4.common.Pack enumeration, such as 0 for the base game and 3 for EP01.

ResourceName

Gets the name of this resource if it has one

public override string? ResourceName { get; }

Property Value

string

Schemas

Gets the schemas of the objects in the resource, in the order Encode() writes them

public IReadOnlyList<SimDataSchema> Schemas { get; }

Property Value

IReadOnlyList<SimDataSchema>

Exceptions

InvalidOperationException

Two different schemas have the same hash, or an object contains itself

SupportedTypes

Gets a list of resource types that this model supports

public static ISet<ResourceType> SupportedTypes { get; }

Property Value

ISet<ResourceType>

Version

Gets/sets the version of the format of the resource

public SimDataVersion Version { get; set; }

Property Value

SimDataVersion

Methods

Decode(ReadOnlyMemory<byte>)

Decodes the resource in raw format to produce an operable model (🔄️🏃)

public static SimDataModel Decode(ReadOnlyMemory<byte> data)

Parameters

data ReadOnlyMemory<byte>

Returns

SimDataModel

Exceptions

InvalidDataException

The data is not a well-formed SimData resource

Encode()

Encodes the resource model into raw format (🔄️🏃)

public override ReadOnlyMemory<byte> Encode()

Returns

ReadOnlyMemory<byte>

Exceptions

InvalidOperationException

The resource cannot be encoded: Version is not supported or does not support a value used, two different schemas have the same hash, two instances of the same schema have different names, or an object or vector contains itself

FromXml(XDocument)

Creates a SimDataModel from the XML representation of a SimData resource that Sims 4 Studio exports and imports

public static SimDataModel FromXml(XDocument document)

Parameters

document XDocument

Returns

SimDataModel

Remarks

Fields are matched to columns by exact name, and every column of an object must have exactly one field. A string field written as an empty element (<T name="..." />) is read as null. Type names written by Sims4Toolkit (Int8 and UInt8) are accepted along with Sims 4 Studio's. A schema without a schema_hash attribute gets its ComputedHash.

Exceptions

InvalidDataException

document is not a valid representation of a SimData resource

GetName(Stream)

Gets the name of a resource from its raw data, if it has one (🔄️💤)

public static string? GetName(Stream stream)

Parameters

stream Stream

Returns

string

GetNameAsync(Stream, CancellationToken)

Gets the name of a resource from its raw data, if it has one, asynchronously (🔄️💤)

public static Task<string?> GetNameAsync(Stream stream, CancellationToken cancellationToken = default)

Parameters

stream Stream
cancellationToken CancellationToken

Returns

Task<string>

ToXml()

Gets the XML representation of the resource that Sims 4 Studio exports and imports

public XDocument ToXml()

Returns

XDocument

Remarks

A null string is written as an empty element (<T name="..." />) and an empty string as an element with empty content (<T name="..."></T>), which FromXml(XDocument) tells apart (Sims 4 Studio reads both as empty strings). An empty vector is written the same way as a null one, which Encode() also writes the same way.

Exceptions

InvalidOperationException

Two different schemas have the same hash or the same name, a name or string contains characters XML cannot represent, or an object or vector contains itself