Class BarricadeUtility
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
CountBarricades(IAssetLink<ItemBarricadeAsset>, int)
Count the number of barricades in the given radius matching an asset.
[Pure]
public static int CountBarricades(IAssetLink<ItemBarricadeAsset> asset, int max = -1)
Parameters
assetIAssetLink<ItemBarricadeAsset>maxint
Returns
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
Returns
Exceptions
- GameThreadException
Not on main thread.
CountBarricadesInRange(Vector3, float, IAssetLink<ItemBarricadeAsset>, int, bool)
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
positionVector3radiusfloatassetIAssetLink<ItemBarricadeAsset>maxinthorizontalDistanceOnlybool
Returns
Remarks
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
Returns
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
positionVector3radiusfloatbarricadeSelectorPredicate<BarricadeDrop>maxinthorizontalDistanceOnlybool
Returns
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
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
regionRegionCoord
Returns
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
regionRegionCoordmaxRegionDistancebyte
Returns
Remarks
The square enumerated will have a size of regions.maxRegionDistance * 2 + 1
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
Returns
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
Returns
Remarks
The square enumerated will have a size of regions.maxRegionDistance * 2 + 1
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
centerVector3
Returns
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
centerVector3maxRegionDistancebyte
Returns
Remarks
The square enumerated will have a size of regions.maxRegionDistance * 2 + 1
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
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
regionRegionCoord
Returns
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
regionRegionCoordmaxRegionDistancebyte
Returns
Remarks
The square enumerated will have a size of regions.maxRegionDistance * 2 + 1
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
Returns
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
Returns
Remarks
The square enumerated will have a size of regions.maxRegionDistance * 2 + 1
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
centerVector3
Returns
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
centerVector3maxRegionDistancebyte
Returns
Remarks
The square enumerated will have a size of regions.maxRegionDistance * 2 + 1
Exceptions
- GameThreadException
Not on main thread.
EnumeratePlantedBarricades()
Enumerate through planted barricades (barricades on a vehicle).
[Pure]
public static BarricadeIterator EnumeratePlantedBarricades()
Returns
Exceptions
- GameThreadException
Not on main thread.
FindBarricade(uint)
Find a barricade by it's instance ID.
[Pure]
public static BarricadeInfo FindBarricade(uint instanceId)
Parameters
instanceIduint
Returns
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
Returns
Remarks
All regions will be searched if it's not found in the expected region.
Exceptions
- GameThreadException
Not on main thread.
FindBarricade(uint, IAssetLink<ItemBarricadeAsset>, Vector3)
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
instanceIduintexpectedAssetIAssetLink<ItemBarricadeAsset>expectedPositionVector3
Returns
Remarks
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
instanceIduintexpectedPositionVector3
Returns
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
storageInteractableStorage
Returns
GetClosestBarricade(Vector3, bool)
Find the closest barricade to position.
[Pure]
public static BarricadeInfo GetClosestBarricade(Vector3 position, bool horizontalDistanceOnly = false)
Parameters
positionVector3horizontalDistanceOnlybool
Returns
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
Returns
Remarks
Planted barricades are ignored.
Exceptions
- GameThreadException
Not on main thread.
GetClosestBarricade(Vector3, ulong, IAssetLink<ItemBarricadeAsset>, bool)
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
positionVector3groupulongassetIAssetLink<ItemBarricadeAsset>horizontalDistanceOnlybool
Returns
Remarks
Planted barricades are ignored.
Exceptions
- ArgumentNullException
- GameThreadException
Not on main thread.
GetClosestBarricade(Vector3, IAssetLink<ItemBarricadeAsset>, bool)
Find the closest barricade with the given asset to position.
[Pure]
public static BarricadeInfo GetClosestBarricade(Vector3 position, IAssetLink<ItemBarricadeAsset> asset, bool horizontalDistanceOnly = false)
Parameters
positionVector3assetIAssetLink<ItemBarricadeAsset>horizontalDistanceOnlybool
Returns
Remarks
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
Returns
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
Returns
Remarks
Planted barricades are ignored.
Exceptions
- GameThreadException
Not on main thread.
GetClosestBarricadeInRange(Vector3, float, ulong, IAssetLink<ItemBarricadeAsset>, bool)
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
positionVector3radiusfloatgroupulongassetIAssetLink<ItemBarricadeAsset>horizontalDistanceOnlybool
Returns
Remarks
Planted barricades are ignored.
Exceptions
- ArgumentNullException
- GameThreadException
Not on main thread.
GetClosestBarricadeInRange(Vector3, float, IAssetLink<ItemBarricadeAsset>, bool)
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
positionVector3radiusfloatassetIAssetLink<ItemBarricadeAsset>horizontalDistanceOnlybool
Returns
Remarks
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
Returns
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
positionVector3radiusfloatbarricadeSelectorPredicate<BarricadeDrop>horizontalDistanceOnlybool
Returns
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
positionVector3radiusfloatgroupulongbarricadeSelectorPredicate<BarricadeDrop>horizontalDistanceOnlybool
Returns
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
Returns
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
Returns
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
positionVector3radiusfloatbarricadeSelectorPredicate<BarricadeDrop>horizontalDistanceOnlybool
Returns
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
Returns
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
positionVector3radiusfloatgroupulongbarricadeSelectorPredicate<BarricadeDrop>horizontalDistanceOnlybool
Returns
Remarks
Planted barricades are ignored.
Exceptions
- ArgumentNullException
- GameThreadException
Not on main thread.
IsBarricadeInRange(Vector3, float, ulong, IAssetLink<ItemBarricadeAsset>, bool)
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
positionVector3radiusfloatgroupulongassetIAssetLink<ItemBarricadeAsset>horizontalDistanceOnlybool
Returns
Remarks
Planted barricades are ignored.
Exceptions
- ArgumentNullException
- GameThreadException
Not on main thread.
IsBarricadeInRange(Vector3, float, IAssetLink<ItemBarricadeAsset>, bool)
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
positionVector3radiusfloatassetIAssetLink<ItemBarricadeAsset>horizontalDistanceOnlybool
Returns
Remarks
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
dropBarricadeDrop
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
dropBarricadeDropserviceProviderIServiceProviderstateToReplicatebyte[]
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
dropBarricadeDropplayerServiceIPlayerServicesignsSignInstancerstateToReplicatebyte[]
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
dropBarricadeDropserviceProviderIServiceProviderownerCSteamID?groupCSteamID?
Returns
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
dropBarricadeDropplayerServiceIPlayerServicesignsSignInstancerownerCSteamID?groupCSteamID?
Returns
SetServersideSignText(BarricadeDrop, ReadOnlySpan<char>)
Sets the sign text without replicating to clients.
public static void SetServersideSignText(BarricadeDrop barricade, ReadOnlySpan<char> text)
Parameters
barricadeBarricadeDroptextReadOnlySpan<char>
Exceptions
- GameThreadException
Not on main thread.
- ArgumentException
barricadeis 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
barricadeBarricadeDropstatebyte[]
Exceptions
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
stateReadOnlySpan<byte>barricadeItemBarricadeAsset
Remarks
Note that states that are too long will not throw exceptions, only states that are too short or are structually invalid somehow.
Exceptions
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
Returns
Remarks
Use GetClientsideStorageStateLength(InteractableStorage) to pre-calculate the length.
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)