Table of Contents

Class BarricadeUtility

Namespace
Uncreated.Warfare.Util
Assembly
Uncreated.Warfare.dll

Helper functions for barricades.

public static class BarricadeUtility
Inheritance
BarricadeUtility
Inherited Members

Fields

DefaultBarricadeRotation

All buildables should be rotated by this amount when placed relative to any other objects.

public static readonly Quaternion DefaultBarricadeRotation

Field Value

Quaternion

InverseDefaultBarricadeRotation

All transformations using a buildable as reference should rotate the barricade by this first.

public static readonly Quaternion InverseDefaultBarricadeRotation

Field Value

Quaternion

Methods

Count the number of barricades in the given radius matching an asset.

[Pure]
public static int CountBarricades(IAssetLink<ItemBarricadeAsset> asset, int max = -1)

Parameters

asset IAssetLink<ItemBarricadeAsset>
max int

Returns

int

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

CountBarricadesInRange(Vector3, float, int, bool)

Count the number of barricades in the given radius.

[Pure]
public static int CountBarricadesInRange(Vector3 position, float radius, int max = -1, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
max int
horizontalDistanceOnly bool

Returns

int

Exceptions

GameThreadException

Not on main thread.

Count the number of barricades in the given radius matching an asset.

[Pure]
public static int CountBarricadesInRange(Vector3 position, float radius, IAssetLink<ItemBarricadeAsset> asset, int max = -1, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
asset IAssetLink<ItemBarricadeAsset>
max int
horizontalDistanceOnly bool

Returns

int

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

CountBarricadesWhere(Predicate<BarricadeDrop>, int)

Count the number of barricades in the given radius matching a predicate.

[Pure]
public static int CountBarricadesWhere(Predicate<BarricadeDrop> barricadeSelector, int max = -1)

Parameters

barricadeSelector Predicate<BarricadeDrop>
max int

Returns

int

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

CountBarricadesWhere(Vector3, float, Predicate<BarricadeDrop>, int, bool)

Count the number of barricades in the given radius matching a predicate.

[Pure]
public static int CountBarricadesWhere(Vector3 position, float radius, Predicate<BarricadeDrop> barricadeSelector, int max = -1, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
barricadeSelector Predicate<BarricadeDrop>
max int
horizontalDistanceOnly bool

Returns

int

Remarks

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

EnumerateBarricades()

Enumerate through non-planted barricades (barricades not on a vehicle) around the center of the level, then planted barricades (barricades on a vehicle).

[Pure]
public static BarricadeIterator EnumerateBarricades()

Returns

BarricadeIterator

Exceptions

GameThreadException

Not on main thread.

EnumerateBarricades(RegionCoord)

Enumerate through non-planted barricades (barricades not on a vehicle) around region, then planted barricades (barricades on a vehicle).

[Pure]
public static BarricadeIterator EnumerateBarricades(RegionCoord region)

Parameters

region RegionCoord

Returns

BarricadeIterator

Exceptions

GameThreadException

Not on main thread.

EnumerateBarricades(RegionCoord, byte)

Enumerate through non-planted barricades (barricades not on a vehicle) around region, then planted barricades (barricades on a vehicle).

[Pure]
public static BarricadeIterator EnumerateBarricades(RegionCoord region, byte maxRegionDistance)

Parameters

region RegionCoord
maxRegionDistance byte

Returns

BarricadeIterator

Remarks

The square enumerated will have a size of maxRegionDistance * 2 + 1 regions.

Exceptions

GameThreadException

Not on main thread.

EnumerateBarricades(byte, byte)

Enumerate through non-planted barricades (barricades not on a vehicle) around region x, y, then planted barricades (barricades on a vehicle).

[Pure]
public static BarricadeIterator EnumerateBarricades(byte x, byte y)

Parameters

x byte
y byte

Returns

BarricadeIterator

Exceptions

GameThreadException

Not on main thread.

EnumerateBarricades(byte, byte, byte)

Enumerate through non-planted barricades (barricades not on a vehicle) around region x, y, then planted barricades (barricades on a vehicle).

[Pure]
public static BarricadeIterator EnumerateBarricades(byte x, byte y, byte maxRegionDistance)

Parameters

x byte
y byte
maxRegionDistance byte

Returns

BarricadeIterator

Remarks

The square enumerated will have a size of maxRegionDistance * 2 + 1 regions.

Exceptions

GameThreadException

Not on main thread.

EnumerateBarricades(Vector3)

Enumerate through non-planted barricades (barricades not on a vehicle) around center, then planted barricades (barricades on a vehicle).

[Pure]
public static BarricadeIterator EnumerateBarricades(Vector3 center)

Parameters

center Vector3

Returns

BarricadeIterator

Exceptions

GameThreadException

Not on main thread.

EnumerateBarricades(Vector3, byte)

Enumerate through non-planted barricades (barricades not on a vehicle) around center, then planted barricades (barricades on a vehicle).

[Pure]
public static BarricadeIterator EnumerateBarricades(Vector3 center, byte maxRegionDistance)

Parameters

center Vector3
maxRegionDistance byte

Returns

BarricadeIterator

Remarks

The square enumerated will have a size of maxRegionDistance * 2 + 1 regions.

Exceptions

GameThreadException

Not on main thread.

EnumerateNonPlantedBarricades()

Enumerate through non-planted barricades (barricades not on a vehicle) around the center of the level.

[Pure]
public static BarricadeIterator EnumerateNonPlantedBarricades()

Returns

BarricadeIterator

Exceptions

GameThreadException

Not on main thread.

EnumerateNonPlantedBarricades(RegionCoord)

Enumerate through non-planted barricades (barricades not on a vehicle) around region.

[Pure]
public static BarricadeIterator EnumerateNonPlantedBarricades(RegionCoord region)

Parameters

region RegionCoord

Returns

BarricadeIterator

Exceptions

GameThreadException

Not on main thread.

EnumerateNonPlantedBarricades(RegionCoord, byte)

Enumerate through non-planted barricades (barricades not on a vehicle) around region.

[Pure]
public static BarricadeIterator EnumerateNonPlantedBarricades(RegionCoord region, byte maxRegionDistance)

Parameters

region RegionCoord
maxRegionDistance byte

Returns

BarricadeIterator

Remarks

The square enumerated will have a size of maxRegionDistance * 2 + 1 regions.

Exceptions

GameThreadException

Not on main thread.

EnumerateNonPlantedBarricades(byte, byte)

Enumerate through non-planted barricades (barricades not on a vehicle) around region x, y.

[Pure]
public static BarricadeIterator EnumerateNonPlantedBarricades(byte x, byte y)

Parameters

x byte
y byte

Returns

BarricadeIterator

Exceptions

GameThreadException

Not on main thread.

EnumerateNonPlantedBarricades(byte, byte, byte)

Enumerate through non-planted barricades (barricades not on a vehicle) around region x, y.

[Pure]
public static BarricadeIterator EnumerateNonPlantedBarricades(byte x, byte y, byte maxRegionDistance)

Parameters

x byte
y byte
maxRegionDistance byte

Returns

BarricadeIterator

Remarks

The square enumerated will have a size of maxRegionDistance * 2 + 1 regions.

Exceptions

GameThreadException

Not on main thread.

EnumerateNonPlantedBarricades(Vector3)

Enumerate through non-planted barricades (barricades not on a vehicle) around center.

[Pure]
public static BarricadeIterator EnumerateNonPlantedBarricades(Vector3 center)

Parameters

center Vector3

Returns

BarricadeIterator

Exceptions

GameThreadException

Not on main thread.

EnumerateNonPlantedBarricades(Vector3, byte)

Enumerate through non-planted barricades (barricades not on a vehicle) around center.

[Pure]
public static BarricadeIterator EnumerateNonPlantedBarricades(Vector3 center, byte maxRegionDistance)

Parameters

center Vector3
maxRegionDistance byte

Returns

BarricadeIterator

Remarks

The square enumerated will have a size of maxRegionDistance * 2 + 1 regions.

Exceptions

GameThreadException

Not on main thread.

EnumeratePlantedBarricades()

Enumerate through planted barricades (barricades on a vehicle).

[Pure]
public static BarricadeIterator EnumeratePlantedBarricades()

Returns

BarricadeIterator

Exceptions

GameThreadException

Not on main thread.

FindBarricade(uint)

Find a barricade by it's instance ID.

[Pure]
public static BarricadeInfo FindBarricade(uint instanceId)

Parameters

instanceId uint

Returns

BarricadeInfo

Exceptions

GameThreadException

Not on main thread.

FindBarricade(uint, byte, byte)

Find a barricade by it's instance ID, with help from an expected region to prevent having to search every region.

[Pure]
public static BarricadeInfo FindBarricade(uint instanceId, byte expectedRegionX, byte expectedRegionY)

Parameters

instanceId uint
expectedRegionX byte
expectedRegionY byte

Returns

BarricadeInfo

Remarks

All regions will be searched if it's not found in the expected region.

Exceptions

GameThreadException

Not on main thread.

Find a barricade by it's instance ID, with help from an expected region to prevent having to search every region.

[Pure]
public static BarricadeInfo FindBarricade(uint instanceId, IAssetLink<ItemBarricadeAsset> expectedAsset, Vector3 expectedPosition)

Parameters

instanceId uint
expectedAsset IAssetLink<ItemBarricadeAsset>
expectedPosition Vector3

Returns

BarricadeInfo

All regions will be searched if it's not found in the expected region. Only instance ID is checked on planted barricades.

Exceptions

GameThreadException

Not on main thread.

FindBarricade(uint, Vector3)

Find a barricade by it's instance ID, with help from a position to prevent having to search every region.

[Pure]
public static BarricadeInfo FindBarricade(uint instanceId, Vector3 expectedPosition)

Parameters

instanceId uint
expectedPosition Vector3

Returns

BarricadeInfo

Remarks

All regions will be searched if it's not found near the expected position.

Exceptions

GameThreadException

Not on main thread.

GetClientsideStorageStateLength(InteractableStorage)

Get the exact length in bytes of the client-side state for a storage.

public static int GetClientsideStorageStateLength(InteractableStorage storage)

Parameters

storage InteractableStorage

Returns

int

GetClosestBarricade(Vector3, bool)

Find the closest barricade to position.

[Pure]
public static BarricadeInfo GetClosestBarricade(Vector3 position, bool horizontalDistanceOnly = false)

Parameters

position Vector3
horizontalDistanceOnly bool

Returns

BarricadeInfo

Remarks

Planted barricades are ignored.

Exceptions

GameThreadException

Not on main thread.

GetClosestBarricade(Vector3, ulong, bool)

Find the closest barricade to position with the given group.

[Pure]
public static BarricadeInfo GetClosestBarricade(Vector3 position, ulong group, bool horizontalDistanceOnly = false)

Parameters

position Vector3
group ulong
horizontalDistanceOnly bool

Returns

BarricadeInfo

Remarks

Planted barricades are ignored.

Exceptions

GameThreadException

Not on main thread.

Find the closest barricade with the given asset to position with the given group.

[Pure]
public static BarricadeInfo GetClosestBarricade(Vector3 position, ulong group, IAssetLink<ItemBarricadeAsset> asset, bool horizontalDistanceOnly = false)

Parameters

position Vector3
group ulong
asset IAssetLink<ItemBarricadeAsset>
horizontalDistanceOnly bool

Returns

BarricadeInfo

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

Find the closest barricade with the given asset to position.

[Pure]
public static BarricadeInfo GetClosestBarricade(Vector3 position, IAssetLink<ItemBarricadeAsset> asset, bool horizontalDistanceOnly = false)

Parameters

position Vector3
asset IAssetLink<ItemBarricadeAsset>
horizontalDistanceOnly bool

Returns

BarricadeInfo

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

GetClosestBarricadeInRange(Vector3, float, bool)

Find the closest barricade to position within the given radius.

[Pure]
public static BarricadeInfo GetClosestBarricadeInRange(Vector3 position, float radius, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
horizontalDistanceOnly bool

Returns

BarricadeInfo

Remarks

Planted barricades are ignored.

Exceptions

GameThreadException

Not on main thread.

GetClosestBarricadeInRange(Vector3, float, ulong, bool)

Find the closest barricade to position within the given radius and group.

[Pure]
public static BarricadeInfo GetClosestBarricadeInRange(Vector3 position, float radius, ulong group, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
group ulong
horizontalDistanceOnly bool

Returns

BarricadeInfo

Remarks

Planted barricades are ignored.

Exceptions

GameThreadException

Not on main thread.

Find the closest barricade with the given asset to position within the given radius and group.

[Pure]
public static BarricadeInfo GetClosestBarricadeInRange(Vector3 position, float radius, ulong group, IAssetLink<ItemBarricadeAsset> asset, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
group ulong
asset IAssetLink<ItemBarricadeAsset>
horizontalDistanceOnly bool

Returns

BarricadeInfo

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

Find the closest barricade with the given asset to position within the given radius.

[Pure]
public static BarricadeInfo GetClosestBarricadeInRange(Vector3 position, float radius, IAssetLink<ItemBarricadeAsset> asset, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
asset IAssetLink<ItemBarricadeAsset>
horizontalDistanceOnly bool

Returns

BarricadeInfo

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

GetClosestBarricadeWhere(Vector3, Predicate<BarricadeDrop>, bool)

Find the closest barricade matching a predicate to position.

[Pure]
public static BarricadeInfo GetClosestBarricadeWhere(Vector3 position, Predicate<BarricadeDrop> barricadeSelector, bool horizontalDistanceOnly = false)

Parameters

position Vector3
barricadeSelector Predicate<BarricadeDrop>
horizontalDistanceOnly bool

Returns

BarricadeInfo

Remarks

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

GetClosestBarricadeWhere(Vector3, float, Predicate<BarricadeDrop>, bool)

Find the closest barricade matching a predicate to position within a given radius.

[Pure]
public static BarricadeInfo GetClosestBarricadeWhere(Vector3 position, float radius, Predicate<BarricadeDrop> barricadeSelector, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
barricadeSelector Predicate<BarricadeDrop>
horizontalDistanceOnly bool

Returns

BarricadeInfo

Remarks

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

GetClosestBarricadeWhere(Vector3, float, ulong, Predicate<BarricadeDrop>, bool)

Find the closest barricade matching a predicate to position within a given radius and group.

[Pure]
public static BarricadeInfo GetClosestBarricadeWhere(Vector3 position, float radius, ulong group, Predicate<BarricadeDrop> barricadeSelector, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
group ulong
barricadeSelector Predicate<BarricadeDrop>
horizontalDistanceOnly bool

Returns

BarricadeInfo

Remarks

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

GetClosestBarricadeWhere(Vector3, ulong, Predicate<BarricadeDrop>, bool)

Find the closest barricade matching a predicate to position with the given group.

[Pure]
public static BarricadeInfo GetClosestBarricadeWhere(Vector3 position, ulong group, Predicate<BarricadeDrop> barricadeSelector, bool horizontalDistanceOnly = false)

Parameters

position Vector3
group ulong
barricadeSelector Predicate<BarricadeDrop>
horizontalDistanceOnly bool

Returns

BarricadeInfo

Remarks

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

IsBarricadeInRange(Vector3, float, bool)

Check for a nearby barricade to position within the given radius.

[Pure]
public static bool IsBarricadeInRange(Vector3 position, float radius, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
horizontalDistanceOnly bool

Returns

bool

Remarks

Planted barricades are ignored.

Exceptions

GameThreadException

Not on main thread.

IsBarricadeInRange(Vector3, float, Predicate<BarricadeDrop>, bool)

Check for a nearby barricade matching a predicate to position within the given radius.

[Pure]
public static bool IsBarricadeInRange(Vector3 position, float radius, Predicate<BarricadeDrop> barricadeSelector, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
barricadeSelector Predicate<BarricadeDrop>
horizontalDistanceOnly bool

Returns

bool

Remarks

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

IsBarricadeInRange(Vector3, float, ulong, bool)

Check for a nearby barricade to position within the given radius and group.

[Pure]
public static bool IsBarricadeInRange(Vector3 position, float radius, ulong group, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
group ulong
horizontalDistanceOnly bool

Returns

bool

Remarks

Planted barricades are ignored.

Exceptions

GameThreadException

Not on main thread.

IsBarricadeInRange(Vector3, float, ulong, Predicate<BarricadeDrop>, bool)

Check for a nearby barricade matching a predicate to position within the given radius and group.

[Pure]
public static bool IsBarricadeInRange(Vector3 position, float radius, ulong group, Predicate<BarricadeDrop> barricadeSelector, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
group ulong
barricadeSelector Predicate<BarricadeDrop>
horizontalDistanceOnly bool

Returns

bool

Remarks

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

Check for a nearby barricade with the given asset to position within the given radius and group.

[Pure]
public static bool IsBarricadeInRange(Vector3 position, float radius, ulong group, IAssetLink<ItemBarricadeAsset> asset, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
group ulong
asset IAssetLink<ItemBarricadeAsset>
horizontalDistanceOnly bool

Returns

bool

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

Check for a nearby barricade with the given asset to position within the given radius.

[Pure]
public static bool IsBarricadeInRange(Vector3 position, float radius, IAssetLink<ItemBarricadeAsset> asset, bool horizontalDistanceOnly = false)

Parameters

position Vector3
radius float
asset IAssetLink<ItemBarricadeAsset>
horizontalDistanceOnly bool

Returns

bool

Planted barricades are ignored.

Exceptions

ArgumentNullException
GameThreadException

Not on main thread.

PreventItemDrops(BarricadeDrop)

Prevent this barricade from dropping it's items if its about to be destroyed.

public static void PreventItemDrops(BarricadeDrop drop)

Parameters

drop BarricadeDrop

Exceptions

GameThreadException

Not on main thread.

ReplicateBarricadeState(BarricadeDrop, IServiceProvider, byte[]?)

Sends the given stateToReplicate, which defaults to the barricade's state if null to all relevant clients.

public static bool ReplicateBarricadeState(BarricadeDrop drop, IServiceProvider serviceProvider, byte[]? stateToReplicate = null)

Parameters

drop BarricadeDrop
serviceProvider IServiceProvider
stateToReplicate byte[]

Returns

bool

true if the barricade state was replicated, otherwise false (due to reflection failure or out of bounds barricade).

ReplicateBarricadeState(BarricadeDrop, IPlayerService, SignInstancer?, byte[]?)

Sends the given stateToReplicate, which defaults to the barricade's state if null to all relevant clients.

public static bool ReplicateBarricadeState(BarricadeDrop drop, IPlayerService playerService, SignInstancer? signs, byte[]? stateToReplicate = null)

Parameters

drop BarricadeDrop
playerService IPlayerService
signs SignInstancer
stateToReplicate byte[]

Returns

bool

true if the barricade state was replicated, otherwise false (due to reflection failure or out of bounds barricade).

SetOwnerOrGroup(BarricadeDrop, IServiceProvider, CSteamID?, CSteamID?)

Set the owner and/or group of a barricade.

public static bool SetOwnerOrGroup(BarricadeDrop drop, IServiceProvider serviceProvider, CSteamID? owner = null, CSteamID? group = null)

Parameters

drop BarricadeDrop
serviceProvider IServiceProvider
owner CSteamID?
group CSteamID?

Returns

bool

true if the barricade state was replicated, otherwise false.

SetOwnerOrGroup(BarricadeDrop, IPlayerService, SignInstancer?, CSteamID?, CSteamID?)

Set the owner and/or group of a barricade.

public static bool SetOwnerOrGroup(BarricadeDrop drop, IPlayerService playerService, SignInstancer? signs, CSteamID? owner = null, CSteamID? group = null)

Parameters

drop BarricadeDrop
playerService IPlayerService
signs SignInstancer
owner CSteamID?
group CSteamID?

Returns

bool

true if the barricade state was replicated, otherwise false.

SetServersideSignText(BarricadeDrop, ReadOnlySpan<char>)

Sets the sign text without replicating to clients.

public static void SetServersideSignText(BarricadeDrop barricade, ReadOnlySpan<char> text)

Parameters

barricade BarricadeDrop
text ReadOnlySpan<char>

Exceptions

GameThreadException

Not on main thread.

ArgumentException

barricade is not a sign.

SetState(BarricadeDrop, byte[])

Set the state of any barricade and properly update it for the client.

public static void SetState(BarricadeDrop barricade, byte[] state)

Parameters

barricade BarricadeDrop
state byte[]

Exceptions

GameThreadException
InvalidBarricadeStateException

VerifyState(ReadOnlySpan<byte>, ItemBarricadeAsset)

Throw an exception if the state isn't valid for this barricade type.

public static void VerifyState(ReadOnlySpan<byte> state, ItemBarricadeAsset barricade)

Parameters

state ReadOnlySpan<byte>
barricade ItemBarricadeAsset

Remarks

Note that states that are too long will not throw exceptions, only states that are too short or are structually invalid somehow.

Exceptions

InvalidBarricadeStateException

WriteClientsideStorageState(Span<byte>, InteractableStorage, CSteamID, CSteamID)

Write the bytes of the client-side state for a storage.

public static int WriteClientsideStorageState(Span<byte> output, InteractableStorage storage, CSteamID owner, CSteamID group)

Parameters

output Span<byte>
storage InteractableStorage
owner CSteamID
group CSteamID

Returns

int

Remarks

Exceptions

ArgumentException

Output is not long enough for the full state.

OverflowException

Displayed item's state or display metadata is longer than 255 elements.

WriteOwnerAndGroup(Span<byte>, BarricadeDrop, ulong, ulong)

Write the group and owner to a span of bytes to prepare it for a new barricade.

public static void WriteOwnerAndGroup(Span<byte> state, BarricadeDrop drop, ulong owner, ulong group)

Parameters

state Span<byte>
drop BarricadeDrop
owner ulong
group ulong

Exceptions

InvalidBarricadeStateException