Skip to content

Patch Expressions

Patch expressions begin with ~ and are resolved by Star Rod during compilation. Availability may depend on the structure and overlay being compiled.

ExpressionResult
~String:StringNameID assigned to a named custom message.
~SizeOf:TypeSize of a fixed-size structure type.
~Index:VariableNameNumeric index of a named script variable.
~Func:FunctionNameAddress of a known engine function from a .lib file.
~FX:EffectNameNumeric arguments identifying an effect used by PlayEffect.
~Short:ConstNameConstant written as a 16-bit short.
~Byte:ConstNameConstant written as an 8-bit byte.

~Flags combines names from a .flags file, with an optional raw value ORed into the result:

~Flags:FlagType:FlagValues
~Flags:FlagType:FlagValues:Constant
~Flags:FlagType::Constant

Flag names are separated with |. For example:

~Flags:DamageType:NoContact|Fire
~Anim:SpriteName:AnimationName
~Anim:SpriteName:AnimationName:PaletteName
~PlayerAnim:SpriteName:AnimationName
~PlayerAnim:SpriteName:AnimationName:PaletteName

These produce NPC or player animation IDs. When the palette is omitted, its field is zero. Animation and palette names come from the indexed sprite sources and may be changed in Sprite Editor.

~RasterFile:Format:Filename
~PaletteFile:Format:Filename

These copy image or palette data from $mod/res/. Supported formats are I-4, I-8, IA-4, IA-8, IA-16, CI-4, CI-8, RGBA-16, and RGBA-32.

~TileFormat:Format
~TileDepth:Format

These produce the format or bit-depth field for one of the supported image formats.

~BinaryFile:Filename copies a file from $mod/res/ as byte tokens without padding.

Map expressions refer to objects indexed from an editable map. In an .mpat file, MapName may be omitted when the expression refers to the current map.

~Model:MapName:ModelName
~ModelShort:MapName:ModelName
~Collider:MapName:ColliderName
~ColliderShort:MapName:ColliderName
~Zone:MapName:ZoneName
~ZoneShort:MapName:ZoneName
~Entry:MapName:EntryName
~EntryShort:MapName:EntryName

The normal forms return 32-bit IDs; the Short forms return 16-bit IDs. Model lookup uses the first matching name in a breadth-first traversal, so model names should be unique.

The general form is ~Type:MapName:MarkerName:

TypeResult
Vec2d, Vec2fTwo-dimensional planar position.
VecXZd, VecXZfAlias for the two-dimensional planar position.
Vec3d, Vec3fThree-dimensional position.
PosXd, PosXfX coordinate.
PosYd, PosYfY coordinate.
PosZd, PosZfZ coordinate.
Angle, AngleFYaw.
Vec4d, Vec4fThree-dimensional position followed by yaw.

Names ending in f produce floating-point values. Names ending in d produce 32-bit integers.

~PathXZd:MapName:MarkerName:PointIndex
~PathXZf:MapName:MarkerName:PointIndex
~Path3d:MapName:MarkerName
~Path3f:MapName:MarkerName

Path3d and Path3f produce an array of three-dimensional path points. PathXZd and PathXZf produce the X and Z coordinates of one point.

~PushGrid:MapName:MarkerName produces the grid data consumed by CreatePushBlockGrid.

Pointers may be offset by a number or constant:

$MyPointer[offset]
$MyPointer[.Constant]

Function labels may be used as internal offsets:

$MyFunction[.o150]

Offsets may be nested and applied to constants:

#define .ConstA 10
#define .ConstB 3
.ConstA[.ConstB] % 0x13
$MyPointer[.ConstA[.ConstB[2]]] % pointer plus 0x15