BinCodec
BinCodec private
The BinCodec class handles the serialization and deserialization of game data into a compact binary format using ByteBuffer.
Properties
| Name | Type | Description |
|---|---|---|
attributeMaps | Record<number, ATTRIBUTE_MAP_ENTRY[]> | Maps entity type IDs to their attribute definitions. Populated during decodeEnterWorldResponse. |
entityTypeNames | Record<number, string> | Maps entity type IDs to their string names. Populated during decodeEnterWorldResponse. |
rpcMaps | RPC_MAP_ENTRY[] | Array of all registered RPC definitions, indexed by RPC index. Populated during decodeEnterWorldResponse. |
rpcMapsByName | Record<string, RPC_MAP_ENTRY> | Maps RPC names to their definitions. Populated during decodeEnterWorldResponse. |
sortedUidsByType | Record<number, number[]> | Tracks sorted entity UIDs per entity type for delta encoding. Updated during entity updates. |
removedEntities | Record<number, number> | Tracks entities removed in the current tick. Cleared each decodeEntityUpdate call. |
absentEntitiesFlags | number[] | Reusable buffer for bitflags indicating which entities are absent in the current update. |
updatedEntityFlags | number[] | Reusable buffer for bitflags indicating which attributes were updated for an entity. |
Methods
encode()
function encode(name: number, item: object): ArrayBufferEncodes a packet into an ArrayBuffer.
decode()
function decode(data: ArrayBuffer): objectDecodes a packet from an ArrayBuffer.
safeReadVString()
function safeReadVString(buffer: ByteBuffer): stringSafely reads a variable-length string from the buffer.
decodePreEnterWorldResponse()
function decodePreEnterWorldResponse(buffer: ByteBuffer): objectDecodes the pre-entry packet, which calls decodeBlendInternal internally.
decodeEnterWorldResponse()
function decodeEnterWorldResponse(buffer: ByteBuffer): objectDecodes the world entry response, including world dimensions, tick rates, and the full attribute/RPC maps.
decodeEntityUpdate()
function decodeEntityUpdate(buffer: ByteBuffer): objectDecodes an entity update packet. This handles removed entities, newly created entities, and updated attributes for existing entities.
decodePing()
function decodePing(buffer: ByteBuffer): objectDecodes a ping packet (returns empty object).
encodeRpc()
function encodeRpc(buffer: ByteBuffer, item: object): voidEncodes an RPC call based on its registered parameter types.
decodeBlend()
function decodeBlend(buffer: ByteBuffer): objectDecodes the occasional blend packet, which calls decodeBlendInternal internally.
decodeBlendInternal()
function decodeBlendInternal(buffer: ByteBuffer): objectSolves the PoW challenge that is part of the anti-bot mechanism of the game. The output of this function contains a PoW answer that is 64-byte long. See _MakeBlendField for more info.
decodeRpcObject()
function decodeRpcObject(buffer: ByteBuffer, parameters: Array): objectDecodes a single RPC response object based on its parameter definitions.
decodeRpc()
function decodeRpc(buffer: ByteBuffer): objectDecodes an RPC response, handling both single objects and arrays of objects.
encodeBlend()
function encodeBlend(buffer: ByteBuffer, item: {extra: Uint8Array}): voidEncodes a blend packet.
encodeEnterWorld2()
function encodeEnterWorld2(buffer: ByteBuffer): voidEncodes the secondary world entry packet. This packet is part of the anti-bot mechanism and in reality is a 17-byte long packet. See _MakeBlendField for more info.
encodeEnterWorld()
function encodeEnterWorld(buffer: ByteBuffer, item: {displayName: string, extra: Uint8Array}): voidEncodes the primary world entry packet.
encodeInput()
function encodeInput(buffer: ByteBuffer, item: object): voidEncodes player input as a JSON string.
encodePing()
function encodePing(buffer: ByteBuffer): voidEncodes a ping packet.
Enumerations
e_AttributeType private
| Constant | Value | Notes |
|---|---|---|
Uninitialized | 0 | |
Uint32 | 1 | |
Int32 | 2 | |
Float | 3 | Stored as Int32 / 100 |
String | 4 | |
Vector2 | 5 | Two Floats |
EntityType | 6 | |
ArrayVector2 | 7 | |
ArrayUint32 | 8 | |
Uint16 | 9 | |
Uint8 | 10 | |
Int16 | 11 | |
Int8 | 12 | |
Uint64 | 13 | |
Int64 | 14 | |
Double | 15 |
e_ParameterType private
| Constant | Value |
|---|---|
Uint32 | 0 |
Int32 | 1 |
Float | 2 |
String | 3 |
Uint64 | 4 |
Int64 | 5 |
Data Interfaces
Packet Interfaces
ATTRIBUTE_MAP_ENTRY
Internal structure populated during decodeEnterWorldResponse. One entry per attribute on an entity type.
interface ATTRIBUTE_MAP_ENTRY {
name: string,
type: e_AttributeType
}RPC_MAP_ENTRY
Internal structure populated during decodeEnterWorldResponse. One entry per registered RPC.
interface RPC_MAP_ENTRY {
name: string,
parameters: RPC_PARAMETER_ENTRY[],
isArray: boolean,
index: number
}RPC_PARAMETER_ENTRY
interface RPC_PARAMETER_ENTRY {
name: string,
type: e_ParameterType
}Attribute Interfaces
Vector2
interface Vector2 {
x: number,
y: number
}Schemas
attributeMaps, entityTypeNames and rpcMaps
These variables are defined directly by server data (PACKET_ENTER_WORLD) and stored as variables in BinCodec.
attributeMaps
attributeMaps defines all of the attributes that can be present on an entity and the type they are encoded as. A complete attribute map can be found here.
entityTypeNames
| ID | Entity Type |
|---|---|
667546015 | Pet |
742594995 | GoldMine |
1059671174 | Zombie |
1372600389 | Stone |
1496910567 | Neutral |
1566069472 | PlayerObject |
1672634632 | NeutralCamp |
1816895259 | GameProjectile |
2092990061 | Trap |
2093252446 | Tree |
2347737811 | GamePlayer |
2402467733 | GoldStash |
2462472648 | Spell |
2464630638 | Door |
2899981078 | Harvester |
2969697641 | Tower |
rpcMaps
There are a total of 40 RPCs in the game for both server and client RPCs. A complete RPC map can be found here.