If you have a mod, it might be of interest to create custom protocol messages to communicate additional information between your client and the server.
See Receiving Protocol Messages for information on actaully receiving your messages from the client. This page is just to declare them.
As per how the Among Us protocol is structured, messages can be declared on certain levels and as children of certain parent messages. For example, messages that are identified by the first byte are called option packets, although you most likely won't be using these as they're part of Hazel itself.
With that in mind, you can declare messages by extending the relevant class:
Type | Description | Identifier | Parent message | Base class |
---|---|---|---|---|
Root | Used for reliable/unreliable messages, related to stateless communication between the client and the server. | root |
ReliablePacket/UnreliablePacket | BaseRootMessage |
GameData | Used for messages that are related to the game, and communicate with a little bit of state involved. | gamedata |
GameDataMessage | BaseGameDataMessage |
Rpc | (Remote Procedure Call) Used for messages in games that communicate directly to objects, and are heavily based on recording state. | rpc |
RpcMessage | BaseRpcMessage |
Check out the SkeldJS source for full, proper examples.
Check the table above to know which base class your message class should extend.
export class SayHelloMessage extends BaseRootMessage {
static messageTag = 60 as const;
messageTag = 60 as const;
constructor(public readonly message: string) {
super();
}
static Deserialize(reader: HazelReader) {
const message = reader.string();
return new MyRootMessage(message);
}
Serialize(writer: HazelWriter) {
writer.string(this.message);
}
clone() {
return new MyRootMessage(this.message);
}
}
The messageTag
property should be any unused integer, as long as it's the same as the tag that the client sends. This is just used to identfiy your message and decode it when it's encountered.
The
messageTag
should generally be between0-255
, especially for official Among Us message types.
Note that other mods may have their own message tags, so make sure that other mods that you use don't conflict with your message tags.
Use the RegisterMessage decorator to register your custom message to be recognised by Hindenburg:
@RegisterMessage(SayHelloMessage)
@HindenburgPlugin("hbplugin-mouse-messager-plugin")
export class MouseMessagerPlugin extends WorkerPlugin {
}
Note that custom messages can only be instantiated and used on a worker plugin.
Check out Receiving Protocol Messages to learn how to handle your custom messages sent by clients.
Sending custom messages in Hindenburg is just as simple as instantiating the class, for example:
connection.sendPacket(
new ReliablePacket(
connection.getNextNonce(),
[
new SayHelloMessage("there's a mouse! where? there on the stair, right there!")
]
)
);
Generated using TypeDoc