Skip to content

API Reference

Macka edited this page Nov 29, 2025 · 4 revisions

Table of Contents

MPAPI

MPAPI.Interfaces

MPAPI.Interfaces.Packets

MPAPI.Types

MPAPI.Util



IClient

Namespace: MPAPI.Interfaces

Interface for interacting with Multiplayer mod client instances.

public interface IClient

Properties

PlayerId

Gets Player Id of the local player.

public abstract byte PlayerId { get; }

Property Value

Byte

Remarks:

The local player does not have an IPlayer object.

Players

Gets IPlayer objects for all players connected to the server.

public abstract IReadOnlyCollection<IPlayer> Players { get; }

Property Value

IReadOnlyCollection<IPlayer>

PlayerCount

Gets number of players currently connected to the server.

public abstract int PlayerCount { get; }

Property Value

Int32

IsConnected

Gets connection state for the client.

public abstract bool IsConnected { get; }

Property Value

Boolean

Ping

Gets ping for the client.

public abstract int Ping { get; }

Property Value

Int32

Methods

RegisterReadyBlock(ModInfo)

Registers a block to prevent the client from sending the 'Ready' signal to the server until all mods have called 'CancelReadyBlock'.

void RegisterReadyBlock(ModInfo modInfo)

Parameters

modInfo ModInfo
Mod information.

Remarks:

Only required if the mod needs complete loading prior to receiving game state from the server.

CancelReadyBlock(ModInfo)

Cancels a previously registered ready block.

void CancelReadyBlock(ModInfo modInfo)

Parameters

modInfo ModInfo
Mod information.

Remarks:

All registered blocks must be cancelled prior to the client sending the 'Ready' signal to the server.

GetPlayer(Byte)

Gets the IPlayer for player by Id.

IPlayer GetPlayer(byte playerId)

Parameters

playerId Byte

Returns

IPlayer
IPlayer object if found, otherwise null.

RegisterPacket<T>(ClientPacketHandler<T>)

Register a packet type that uses automatic serialisation.

void RegisterPacket<T>(ClientPacketHandler<T> handler)

Type Parameters

T
Packet type implementing IPacket.

Parameters

handler ClientPacketHandler<T>
Handler to call when packet is received.

RegisterSerializablePacket<T>(ClientPacketHandler<T>)

Register a packet type that uses manual serialisation.

void RegisterSerializablePacket<T>(ClientPacketHandler<T> handler)

Type Parameters

T
Packet type implementing ISerializablePacket.

Parameters

handler ClientPacketHandler<T>
Handler to call when packet is received.

SendPacketToServer<T>(T, Boolean)

Send a packet based on IPacket to the server.

void SendPacketToServer<T>(T packet, bool reliable)

Type Parameters

T
Packet type.

Parameters

packet T
Packet to send.

reliable Boolean
Whether to send reliably.

SendSerializablePacketToServer<T>(T, Boolean)

Send a packet based on ISerializablePacket to the server.

void SendSerializablePacketToServer<T>(T packet, bool reliable)

Type Parameters

T
Packet type.

Parameters

packet T
Packet to send.

reliable Boolean
Whether to send reliably.

Events

OnPlayerConnected

Event fired when a player connects.

public abstract event Action<IPlayer> OnPlayerConnected;

Remarks:

The event handler receives an IPlayer object for the connected player.

OnPlayerDisconnected

Event fired when a player disconnects, but before the IPlayer object is destroyed.

public abstract event Action<IPlayer> OnPlayerDisconnected;

Remarks:

The event handler receives an IPlayer object for the disconnected player.



IMultiplayerAPI

Namespace: MPAPI.Interfaces

Main interface for interacting with the Multiplayer mod.

public interface IMultiplayerAPI

Properties

SupportedApiVersion

Gets the version of the Multiplayer API that the Multiplayer mod supports.

public abstract string SupportedApiVersion { get; }

Property Value

String

MultiplayerVersion

Gets the version of the Multiplayer mod itself.

public abstract string MultiplayerVersion { get; }

Property Value

String

IsMultiplayerLoaded

Gets whether the multiplayer mod is currently loaded and active.

public abstract bool IsMultiplayerLoaded { get; }

Property Value

Boolean

IsConnected

Returns true if either a host or client exist.

public abstract bool IsConnected { get; }

Property Value

Boolean

IsHost

Gets whether this instance is host.

public abstract bool IsHost { get; }

Property Value

Boolean

IsDedicatedServer

Gets whether this instance is a dedicated server.

public abstract bool IsDedicatedServer { get; }

Property Value

Boolean

IsSinglePlayer

Gets whether this current session is single player.

public abstract bool IsSinglePlayer { get; }

Property Value

Boolean

TICK_RATE

The number of ticks per second (currently 24). Used to calculate the fixed tick interval: TICK_INTERVAL = 1.0f / TICK_RATE.

public abstract uint TICK_RATE { get; }

Property Value

UInt32

CurrentTick

The current game tick.

public abstract uint CurrentTick { get; }

Property Value

UInt32

Methods

SetModCompatibility(String, MultiplayerCompatibility)

Sets the mod's compatibility requirements.

void SetModCompatibility(string modId, MultiplayerCompatibility compatibility)

Parameters

modId String
String representing the your mod's Id (ModEntry.Info.Id).

compatibility MultiplayerCompatibility
ModCompatibility flags representing installation host/client requirements.

TryGetNetId<T>(T, UInt16&)

Gets the NetId for an object.

bool TryGetNetId<T>(T obj, UInt16& netId)

Type Parameters

T

Parameters

obj T
The object you want the NetId for.

netId UInt16&
When this method returns, contains the NetId associated with the specified object, if found; otherwise, 0.

Returns

Boolean
True if a NetId for the object was found; otherwise, false.

TryGetObjectFromNetId<T>(UInt16, T&)

Gets the object for a NetId.

bool TryGetObjectFromNetId<T>(ushort netId, T& obj)

Type Parameters

T

Parameters

netId UInt16
The non-zero NetId for the object.

obj T&
When this method returns, contains the object associated with the NetId, if found; otherwise null.

Returns

Boolean
True if the object was found; otherwise, false.

TryGetNetId<T>(T, UInt32&)

Gets the NetId for an object.

bool TryGetNetId<T>(T obj, UInt32& netId)

Type Parameters

T

Parameters

obj T
The object you want the NetId for.

netId UInt32&
When this method returns, contains the NetId associated with the specified object, if found; otherwise, 0.

Returns

Boolean
True if a NetId for the object was found; otherwise, false.

TryGetObjectFromNetId<T>(UInt32, T&)

Gets the object for a NetId.

bool TryGetObjectFromNetId<T>(uint netId, T& obj)

Type Parameters

T

Parameters

netId UInt32
The non-zero NetId for the object.

obj T&
When this method returns, contains the object associated with the NetId, if found; otherwise null.

Returns

Boolean
True if the object was found; otherwise, false.

RegisterPaintTheme(PaintTheme)

Registers a PaintTheme and returns its netId.

uint RegisterPaintTheme(PaintTheme theme)

Parameters

theme PaintTheme
The DV.Customization.Paint.PaintTheme to be registered.

Returns

UInt32
Non-zero, unique Id if the theme was successfully registered, otherwise 0.

Remarks:

PaintThemes must be registered each time the client or server starts, registration is not persistent across sessions.

UnregisterPaintTheme(PaintTheme)

Unregisters a PaintTheme.

void UnregisterPaintTheme(PaintTheme theme)

Parameters

theme PaintTheme
The DV.Customization.Paint.PaintTheme to be unregistered.

Remarks:

Base game PaintThemes cannot be unregistered.

RegisterTaskType<TCustomTask, TTaskNetworkData>(TaskType)

Registers a TaskNetworkData<T> serialiser/deserialiser for a custom DV.Logic.Job.Task type for multiplayer synchronisation.

bool RegisterTaskType<TCustomTask, TTaskNetworkData>(TaskType taskType)

Type Parameters

TCustomTask
The concrete DV.Logic.Job.Task type to register.

TTaskNetworkData
The TaskNetworkData<T> type that handles serialisation and deserialisation for . Must have a parameterless constructor and implement TaskNetworkData<T>.FromTask(Task) to convert from the task.

Parameters

taskType TaskType
The DV.Logic.Job.TaskType enum value associated with this task type.

Returns

Boolean
true if the task type was successfully registered; false if the task type was already registered or registration failed.

Remarks:

This method automatically handles conversion by instantiating , calling its TaskNetworkData<T>.FromTask(Task) method for serialisation, and creating empty instances for deserialisation.

UnregisterTaskType<TCustomTask>(TaskType)

Unregisters a previously registered custom DV.Logic.Job.Task type.

bool UnregisterTaskType<TCustomTask>(TaskType taskType)

Type Parameters

TCustomTask
The concrete DV.Logic.Job.Task type to unregister.

Parameters

taskType TaskType
The DV.Logic.Job.TaskType enum value associated with the task type to unregister.

Returns

Boolean
true if the task type was successfully unregistered; false if the task type was not found or is a base-game task type.

Remarks:

This method allows removal of custom or extended task types from the multiplayer system. Base-game task types cannot be unregistered.

ConvertTasks(IEnumerable<Task>)

Converts an IEnumerable collection of DV.Logic.Job.Task into an array of TaskNetworkData.

TaskNetworkData[] ConvertTasks(IEnumerable<Task> tasks)

Parameters

tasks IEnumerable<Task>
The collection of tasks to convert.

Returns

TaskNetworkData[]
An array of TaskNetworkData representing the tasks.

ConvertTask(Task)

Converts a DV.Logic.Job.Task into a TaskNetworkData.

TaskNetworkData ConvertTask(Task task)

Parameters

task Task
The task to convert.

Returns

TaskNetworkData
A TaskNetworkData representing the task.

ConvertTask(TaskType)

Retrieves a TaskNetworkData for the specified DV.Logic.Job.TaskType.

TaskNetworkData ConvertTask(TaskType taskType)

Parameters

taskType TaskType
The task type to convert.

Returns

TaskNetworkData
A TaskNetworkData representing the task.

Events

OnTick

Event fired when a game/network tick occurs. Ticks occur at a fixed interval (TICK_INTERVAL = 1/TICK_RATE) and are useful for synchronisation, batching, and processing changes.

The tick parameter can be used to determine if non-reliable packets have been dropped and to sequence actions for rollbacks or preventing stale data from being processed.

Example: In Multiplayer's TrainCar simulation sync, small changes are cached when they occur but sent as a single packet per TrainCar when OnTick fires, reducing network overhead.

public abstract event Action<uint> OnTick;

Remarks:

The event handler receives a UInt32 representing the current tick number.



INetIdProvider

Namespace: MPAPI.Interfaces

Provides methods for mapping between built-in game objects and their network identifiers in the Multiplayer system.

public interface INetIdProvider

Remarks:

This interface enables bidirectional lookup between game objects and their corresponding network IDs, which are used to synchronise object references across the network. Only objects that are actively synchronised by Multiplayer mod will have associated network identifiers.

Additional objects from the base-game will be added as Multiplayer features are implemented. If there are specific object types you would like to see supported, please create an issue on the Multiplayer Mod GitHub repository.

Methods

TryGetNetId<T>(T, UInt16&)

Attempts to retrieve the network identifier for the specified object.

bool TryGetNetId<T>(T obj, UInt16& netId)

Type Parameters

T
The type of object to get the network ID for. Must be a reference type.

Parameters

obj T
The object to get the network identifier for.

netId UInt16&
When this method returns, contains the network identifier associated with the object if found; otherwise, the default value for the type.

Returns

Boolean
true if the network identifier was successfully retrieved; otherwise, false.

TryGetObject<T>(UInt16, T&)

Attempts to retrieve the object associated with the specified network identifier.

bool TryGetObject<T>(ushort netId, T& obj)

Type Parameters

T
The type of object to retrieve. Must be a reference type.

Parameters

netId UInt16
The network identifier of the object to retrieve.

obj T&
When this method returns, contains the object associated with the network identifier if found; otherwise, the default value for the type.

Returns

Boolean
true if the object was successfully retrieved; otherwise, false.

TryGetNetId<T>(T, UInt32&)

Attempts to retrieve the network identifier for the specified object.

bool TryGetNetId<T>(T obj, UInt32& netId)

Type Parameters

T
The type of object to get the network ID for. Must be a reference type.

Parameters

obj T
The object to get the network identifier for.

netId UInt32&
When this method returns, contains the network identifier associated with the object if found; otherwise, the default value for the type.

Returns

Boolean
true if the network identifier was successfully retrieved; otherwise, false.

Remarks:

This method is for network identifiers represented as unsigned 32-bit integers, and is typically used where V2 types are involved.

TryGetObject<T>(UInt32, T&)

Attempts to retrieve the object associated with the specified network identifier.

bool TryGetObject<T>(uint netId, T& obj)

Type Parameters

T
The type of object to retrieve. Must be a reference type.

Parameters

netId UInt32
The network identifier of the object to retrieve.

obj T&
When this method returns, contains the object associated with the network identifier if found; otherwise, the default value for the type.

Returns

Boolean
true if the object was successfully retrieved; otherwise, false.

Remarks:

This method is for network identifiers represented as unsigned 32-bit integers, and is typically used where V2 types are involved.



IPlayer

Namespace: MPAPI.Interfaces

Represents a player in the multiplayer session, providing access to player state and information.

public interface IPlayer

Properties

PlayerId

Gets the identifier for the player within the session.

public abstract byte PlayerId { get; }

Property Value

Byte

Remarks:

This identifier can be used as a network ID for referencing the player across the network. If the player leaves the session the Id will be reassigned to the next player to join.

Username

Gets the username/display name of the player.

public abstract string Username { get; }

Property Value

String

Position

Gets the current world position of the player.

public abstract Vector3 Position { get; }

Property Value

Vector3

RotationY

Gets the current Y-axis rotation of the player.

public abstract float RotationY { get; }

Property Value

Single

IsLoaded

Gets a value indicating whether the player has finished loading the game world.

public abstract bool IsLoaded { get; }

Property Value

Boolean
true if the player has completed world loading and is ready to receive game state updates; otherwise, false.

IsHost

Gets a value indicating whether this player is the host of the multiplayer session.

public abstract bool IsHost { get; }

Property Value

Boolean
true if the player is the session host; otherwise, false.

Ping

Gets the current network ping/latency for this player.

public abstract int Ping { get; }

Property Value

Int32
The one-way time in milliseconds between the server and this player.

IsOnCar

Gets a value indicating whether this player is on a car.

public abstract bool IsOnCar { get; }

Property Value

Boolean
true if the player is on a car; otherwise, false.

OccupiedCar

Gets the train car that the player is currently occupying.

public abstract TrainCar OccupiedCar { get; }

Property Value

TrainCar
The TrainCar instance the player is on, or null if the player is not on any car.



IServer

Namespace: MPAPI.Interfaces

Interface for interacting with Multiplayer mod server instances.

public interface IServer

Properties

PlayerCount

Gets number of players currently connected to the server.

public abstract int PlayerCount { get; }

Property Value

Int32

Players

Gets IPlayer objects for all players connected to the server.

public abstract IReadOnlyCollection<IPlayer> Players { get; }

Property Value

IReadOnlyCollection<IPlayer>

Methods

GetPlayer(Byte)

Gets IPlayer for player by Id.

IPlayer GetPlayer(byte id)

Parameters

id Byte
Id for the player.

Returns

IPlayer
IPlayer object if found, otherwise null.

RegisterPacket<T>(ServerPacketHandler<T>)

Register a packet type that uses automatic serialisation.

void RegisterPacket<T>(ServerPacketHandler<T> handler)

Type Parameters

T
Packet type implementing IPacket.

Parameters

handler ServerPacketHandler<T>
Handler to call when packet is received.

RegisterSerializablePacket<T>(ServerPacketHandler<T>)

Register a packet type that uses manual serialisation.

void RegisterSerializablePacket<T>(ServerPacketHandler<T> handler)

Type Parameters

T
Packet type implementing ISerializablePacket.

Parameters

handler ServerPacketHandler<T>
Handler to call when packet is received.

SendPacketToAll<T>(T, Boolean, Boolean, IPlayer)

Send a packet based on IPacket to all connected players.

void SendPacketToAll<T>(T packet, bool reliable, bool excludeSelf, IPlayer excludePlayer)

Type Parameters

T
Packet type.

Parameters

packet T
Packet to send.

reliable Boolean
Whether to send reliably.

excludeSelf Boolean
Sends the packet to the local client when false, skips sending to the local client when true.

excludePlayer IPlayer
IPlayer To be excluded from this broadcast.

SendSerializablePacketToAll<T>(T, Boolean, Boolean, IPlayer)

Send a packet based on ISerializablePacket to all connected players.

void SendSerializablePacketToAll<T>(T packet, bool reliable, bool excludeSelf, IPlayer excludePlayer)

Type Parameters

T
Packet type.

Parameters

packet T
Packet to send.

reliable Boolean
Whether to send reliably.

excludeSelf Boolean
Sends the packet to the local client when false, skips sending to the local client when true.

excludePlayer IPlayer
IPlayer To be excluded from this broadcast.

SendPacketToPlayer<T>(T, IPlayer, Boolean)

Send a packet based on IPacket to a specific player.

void SendPacketToPlayer<T>(T packet, IPlayer player, bool reliable)

Type Parameters

T
Packet type.

Parameters

packet T
Packet to send.

player IPlayer
Target player.

reliable Boolean
Whether to send reliably.

SendSerializablePacketToPlayer<T>(T, IPlayer, Boolean)

Send a packet based on ISerializablePacket to a specific player.

void SendSerializablePacketToPlayer<T>(T packet, IPlayer player, bool reliable)

Type Parameters

T
Packet type.

Parameters

packet T
Packet to send.

player IPlayer
Target player.

reliable Boolean
Whether to send reliably.

AnyPlayerSqrMag(GameObject)

Returns the distance (Square Magnitude) of the closest player to a given GameObject.

float AnyPlayerSqrMag(GameObject gameObject)

Parameters

gameObject GameObject
GameObject to compare players against.

Returns

Single
Returns the distance (Square Magnitude) of the closest player, or float.MaxValue if no player is nearby.

AnyPlayerSqrMag(Vector3)

Returns the distance (Square Magnitude) of the closest player to a given point.

float AnyPlayerSqrMag(Vector3 anchor)

Parameters

anchor Vector3
Anchor point to compare players against.

Returns

Single
Returns the distance (Square Magnitude) of the closest player, or float.MaxValue if no player is nearby.

SendServerChatMessage(String, IPlayer)

Sends a server chat message.

void SendServerChatMessage(string message, IPlayer excludePlayer)

Parameters

message String
Message to be sent.

excludePlayer IPlayer
Player to exclude. If null, message will go to all players.

Remarks:

Server chat messages are messsages sent from the server, not from a specific player and will be stylised as such.

SendWhisperChatMessage(String, IPlayer)

Sends a chat message to a specific player.

void SendWhisperChatMessage(string message, IPlayer player)

Parameters

message String
Message to be sent.

player IPlayer
Recipient player.

RegisterChatCommand(String, String, Func<String>, ChatCommandCallback)

Registers a chat command e.g. /server and optional short command '/s'.

bool RegisterChatCommand(string commandLong, string commandShort, Func<string> helpMessage, ChatCommandCallback callback)

Parameters

commandLong String
Command to be filtered for, without a leading '/' e.g. 'server'.

commandShort String
Optional short command to be filtered for, without a leading '/' e.g. 's'.

helpMessage Func<String>
Optional callback for a help message e.g. \r\n\t\t/s "]]>. It is recommended to provide localisation/translation for this string.

callback ChatCommandCallback
Action to execute when the command is triggered. First parameter contains message without the command e.g. '/command parameter1 parameter2' will become 'parameter1 parameter2', second parameter is the player who executed the command.

Returns

Boolean
True if the command was successfully registered, false if registration failed (e.g. command already exists).

RegisterChatFilter(ChatFilterDelegate)

Registers a chat filter that processes non-command messages in registration order. Filters form a chain where each filter can either allow the message to continue to the next filter or block further processing. If all filters return true, the message will be sent to all players (default action). This filter also applies to whispered messages, regardless of source (player or server).

void RegisterChatFilter(ChatFilterDelegate callback)

Parameters

callback ChatFilterDelegate
Filter function type ChatFilterDelegate that processes the message. First delegate parameter is the message content, second parameter is the player who sent the message. Return true to pass the message to the next filter/default action, false to block propagation.

Events

OnPlayerConnected

Event fired when a player connects and is authenticated, but before the player receives game state information.

public abstract event Action<IPlayer> OnPlayerConnected;

Remarks:

The event handler receives an IPlayer object for the connected player. This event is not triggered for the local-client player on the host.

OnPlayerDisconnected

Event fired when a player disconnects, but before the IPlayer object is destroyed.

public abstract event Action<IPlayer> OnPlayerDisconnected;

Remarks:

The event handler receives an IPlayer object for the connected player.

OnPlayerReady

Event fired when a player has signalled they are ready for game state information.

public abstract event Action<IPlayer> OnPlayerReady;

Remarks:

This event occurs after the server has sent the game state, it does not guarantee the player has finished generating all cars, jobs, etc.



IPacket

Namespace: MPAPI.Interfaces.Packets

Base interface for packets using automatic serialisation.

public interface IPacket


ISerializablePacket

Namespace: MPAPI.Interfaces.Packets

Base interface for packets using manual serialisation. Implementing classes must handle their own serialisation/deserialisation.

public interface ISerializablePacket

Methods

Serialize(BinaryWriter)

Serialise the packet data to the provided BinaryWriter.

void Serialize(BinaryWriter writer)

Parameters

writer BinaryWriter
BinaryWriter to serialise data to.

Deserialize(BinaryReader)

Deserialise the packet data from the provided BinaryReader.

void Deserialize(BinaryReader reader)

Parameters

reader BinaryReader
BinaryReader to deserialise data from.



MultiplayerAPI

Namespace: MPAPI

Provides an API interface for accessing Multiplayer Mod functionality and managing server/client instances.

public static class MultiplayerAPI

Inheritance ObjectMultiplayerAPI

Remarks:

This class serves as the main entry point for the Multiplayer API, providing events for server and client lifecycle management, and access to the current server, client, and API instances.

Properties

LoadedApiVersion

Gets the version of the Multiplayer API DLL that is currently loaded.

public static string LoadedApiVersion { get; }

Property Value

String
The version string of the API DLL.

SupportedApiVersion

Gets the version of the Multiplayer API that the Multiplayer mod supports.

public static string SupportedApiVersion { get; }

Property Value

String
The supported API version string, or null if multiplayer is not loaded.

Remarks:

This indicates the API version that the Multiplayer mod was built against and is compatible with. If this differs from MultiplayerAPI.LoadedApiVersion, there may be compatibility issues.

MultiplayerVersion

Gets the version of the Multiplayer mod itself.

public static string MultiplayerVersion { get; }

Property Value

String
The Multiplayer mod version string, or null if multiplayer is not loaded.

IsMultiplayerLoaded

Gets whether the Multiplayer mod is available.

public static bool IsMultiplayerLoaded { get; }

Property Value

Boolean

Instance

Gets the current API instance (null if Multiplayer mod is not loaded).

public static IMultiplayerAPI Instance { get; }

Property Value

IMultiplayerAPI

Server

Gets the current Server API instance (null if Multiplayer mod is not loaded or server not running).

public static IServer Server { get; }

Property Value

IServer

Client

Gets the current Client API instance (null if Multiplayer mod is not loaded or client not running).

public static IClient Client { get; }

Property Value

IClient

Events

ServerStarted

Event fired when a server instance has been created.

public static event Action<IServer> ServerStarted;

Remarks:

This event provides access to the IServer instance that was started.

ClientStarted

Event fired when a client instance has been created.

public static event Action<IClient> ClientStarted;

Remarks:

This event provides access to the IClient instance that was started.

ServerStopped

Event fired when a server instance is stopped.

public static event Action ServerStopped;

ClientStopped

Event fired when a client instance is stopped.

public static event Action ClientStopped;


MultiplayerCompatibility

Namespace: MPAPI.Types

Defines how a mod works with multiplayer functionality.

public enum MultiplayerCompatibility

Inheritance ObjectValueTypeEnumMultiplayerCompatibility
Implements IComparable, ISpanFormattable, IFormattable, IConvertible

Fields

Name Value Description
Undefined 0 Mod has not defined compatibility. If the host is using this mod all clients must also have it. If a client is using this mod and the host is not, the client will be unable to join the game.
Incompatible 1 Mod is incompatible with multiplayer. The mod must be disabled if Multiplayer Mod is enabled.
All 2 Mod must be installed on the host and all clients. Players without this mod will be unable to join the game. Mods are responsible for disabling behaviour when connecting to a host without the mod.
Host 3 Mod must be installed on the host. Mods are responsible for disabling their behaviour if the player is not the host.
Client 4 Mod has no effect on the game play and can be ignored. This should be used for client-only mods e.g. GUI enhancements, controller mods, RUE, etc.


TaskNetworkData

Namespace: MPAPI.Types

Base class for serialising and deserialising job task data for transmission by Multiplayer mod. Not intended for direct use; inherit via TaskNetworkData<T>.

public abstract class TaskNetworkData

Inheritance ObjectTaskNetworkData

Properties

TaskNetId

Gets or sets the unique network identifier for this task within its job.

public ushort TaskNetId { get; set; }

Property Value

UInt16

State

Gets or sets the current state of the task. See DV.Logic.Job.TaskState for possible values.

public TaskState State { get; set; }

Property Value

TaskState

TaskStartTime

Gets or sets the time at which the task started, in seconds since the job began.

public float TaskStartTime { get; set; }

Property Value

Single

TaskFinishTime

Gets or sets the time at which the task finished, in seconds since the job began.

public float TaskFinishTime { get; set; }

Property Value

Single

IsLastTask

Gets or sets a value indicating whether this is the last task in the job sequence.

public bool IsLastTask { get; set; }

Property Value

Boolean

TimeLimit

Gets or sets the time limit for completing the task, in seconds.

public float TimeLimit { get; set; }

Property Value

Single

TaskType

Gets or sets the type of the task. See DV.Logic.Job.TaskType for possible values.

public TaskType TaskType { get; set; }

Property Value

TaskType

Constructors

TaskNetworkData()

protected TaskNetworkData()

Methods

Serialize(BinaryWriter)

Serialises the task network data to the specified BinaryWriter. Implementations should write all relevant fields for network transmission.

public abstract void Serialize(BinaryWriter writer)

Parameters

writer BinaryWriter
The BinaryWriter to write data to.

Remarks:

The first line of the implementation should call MPAPI.Types.TaskNetworkData1.SerializeCommon(System.IO.BinaryWriter)`.

Deserialize(BinaryReader)

Deserialises the task network data from the specified BinaryReader. Implementations should read all relevant fields in the same order and size as written by TaskNetworkData.Serialize(BinaryWriter).

public abstract void Deserialize(BinaryReader reader)

Parameters

reader BinaryReader
The BinaryReader to read data from.

Remarks:

The first line of the implementation should call MPAPI.Types.TaskNetworkData1.DeserializeCommon(System.IO.BinaryReader)`.

ToTask(Dictionary`2&)

Converts this TaskNetworkData instance into a DV.Logic.Job.Task object compatible with the job/task system, and adds them to the provided dictionary.

public abstract Task ToTask(Dictionary`2& netIdToTask)

Parameters

netIdToTask [Dictionary2&](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2&)<br> A reference to a [Dictionary&lt;TKey, TValue&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2) that will be populated with deserialized DV.Logic.Job.Task instances. Each key is a netTaskId (ushort), and each value is the corresponding DV.Logic.Job.Task` object.

Returns

Task
A DV.Logic.Job.Task instance representing the deserialized data.

Remarks:

Implementations should add all relevant DV.Logic.Job.Task instances to netIdToTask. This allows aggregation of multiple tasks from different TaskNetworkData objects into a single dictionary.

GetCars()

Gets a list of car IDs (UInt16) associated with this task.

public abstract List<ushort> GetCars()

Returns

List<UInt16>
A list of car IDs relevant to the task.



TaskNetworkData<T>

Namespace: MPAPI.Types

Generic abstract base class providing type-safe conversion for serialising and deserialising job task data. Inherit from this class to implement serialisers for custom DV.Logic.Job.Task types.

public abstract class TaskNetworkData<T> : TaskNetworkData

Type Parameters

T
The concrete type that inherits from this class.

Inheritance ObjectTaskNetworkDataTaskNetworkData<T>

Properties

TaskNetId

Gets or sets the unique network identifier for this task within its job.

public ushort TaskNetId { get; set; }

Property Value

UInt16

State

Gets or sets the current state of the task. See DV.Logic.Job.TaskState for possible values.

public TaskState State { get; set; }

Property Value

TaskState

TaskStartTime

Gets or sets the time at which the task started, in seconds since the job began.

public float TaskStartTime { get; set; }

Property Value

Single

TaskFinishTime

Gets or sets the time at which the task finished, in seconds since the job began.

public float TaskFinishTime { get; set; }

Property Value

Single

IsLastTask

Gets or sets a value indicating whether this is the last task in the job sequence.

public bool IsLastTask { get; set; }

Property Value

Boolean

TimeLimit

Gets or sets the time limit for completing the task, in seconds.

public float TimeLimit { get; set; }

Property Value

Single

TaskType

Gets or sets the type of the task. See DV.Logic.Job.TaskType for possible values.

public TaskType TaskType { get; set; }

Property Value

TaskType

Constructors

TaskNetworkData()

protected TaskNetworkData()

Methods

FromTask(Task)

Populates this TaskNetworkData instance from the specified DV.Logic.Job.Task object.

public abstract T FromTask(Task task)

Parameters

task Task
The DV.Logic.Job.Task to extract data from.

Returns

T
This instance, populated with data from the provided task.

Remarks:

This method is called by Multiplayer mod when serialising a job.

FromTaskCommon(Task)

Extracts and populates the common task data fields from the specified DV.Logic.Job.Task object. Should be called as the first step in the FromTask implementation of derived classes.

protected void FromTaskCommon(Task task)

Parameters

task Task
The DV.Logic.Job.Task to extract data from.

ToTaskCommon(Task)

Populates common task data fields to the specified DV.Logic.Job.Task object. Should be called after the new task has been instantiated ToTask implementation of derived classes.

protected void ToTaskCommon(Task task)

Parameters

task Task
The DV.Logic.Job.Task to populate.

SerializeCommon(BinaryWriter)

Serialises the common task data fields to the specified BinaryWriter. Should be called as the first step in the Serialize implementation of derived classes.

protected void SerializeCommon(BinaryWriter writer)

Parameters

writer BinaryWriter
The BinaryWriter to write data to.

DeserializeCommon(BinaryReader)

Deserialises the common task data fields from the specified BinaryReader. Should be called as the first step in the Deserialize implementation of derived classes.

protected void DeserializeCommon(BinaryReader reader)

Parameters

reader BinaryReader
The BinaryReader to read data from.



BinaryReaderWriterExtensions

Namespace: MPAPI.Util

Provides extension methods for BinaryWriter and BinaryReader to handle arrays and Unity types.

public static class BinaryReaderWriterExtensions

Inheritance ObjectBinaryReaderWriterExtensions
Attributes ExtensionAttribute

Methods

WriteUShortArray(BinaryWriter, UInt16[])

Serialises a UInt16 array.

public static void WriteUShortArray(BinaryWriter writer, UInt16[] array)

Parameters

writer BinaryWriter
The BinaryWriter to write to.

array UInt16[]
The UInt16 array to write. If null, writes 0 as the length.

WriteInt32Array(BinaryWriter, Int32[])

Serialises an Int32 array.

public static void WriteInt32Array(BinaryWriter writer, Int32[] array)

Parameters

writer BinaryWriter
The BinaryWriter to write to.

array Int32[]
The Int32 array to serialise. If null, serialises 0 as the length.

WriteVector3(BinaryWriter, Vector3)

Serialises a UnityEngine.Vector3.

public static void WriteVector3(BinaryWriter writer, Vector3 vector)

Parameters

writer BinaryWriter
The BinaryWriter to write to.

vector Vector3
The UnityEngine.Vector3 to serialise.

WriteQuaternion(BinaryWriter, Quaternion)

Serialises a UnityEngine.Quaternion.

public static void WriteQuaternion(BinaryWriter writer, Quaternion quaternion)

Parameters

writer BinaryWriter
The BinaryWriter to write to.

quaternion Quaternion
The UnityEngine.Quaternion to serialise.

ReadUShortArray(BinaryReader)

Deserialises a UInt16 array.

public static UInt16[] ReadUShortArray(BinaryReader reader)

Parameters

reader BinaryReader
The BinaryReader to deserialise from.

Returns

UInt16[]
The deserialised UInt16 array.

ReadInt32Array(BinaryReader)

Deserialises an Int32 array.

public static Int32[] ReadInt32Array(BinaryReader reader)

Parameters

reader BinaryReader
The BinaryReader to deserialise from.

Returns

Int32[]
The deserialised Int32 array.

ReadVector3(BinaryReader)

Deserialises a UnityEngine.Vector3.

public static Vector3 ReadVector3(BinaryReader reader)

Parameters

reader BinaryReader
The BinaryReader to deserialise from.

Returns

Vector3
The deserialised UnityEngine.Vector3.

ReadQuaternion(BinaryReader)

Deserialises a UnityEngine.Quaternion.

public static Quaternion ReadQuaternion(BinaryReader reader)

Parameters

reader BinaryReader
The BinaryReader to deserialise from.

Returns

Quaternion
The deserialised UnityEngine.Quaternion.



Installing
Hosting
Joining a Game
Mod Compatibility

API Overview
Getting Started
Guides
API Reference

Clone this wiki locally