This project is archived and no longer works with current Agar.io servers.
Agar.io was much more than a browser game during the years when this project was built. Around the official client, a large community of developers, reverse engineers and players created custom clients, browser extensions and mods. Custom skins, improved HUDs, macros, automation, bots and protocol tools expanded the game beyond what the official client provided.
For many of us, that community was also a place to learn. People shared packet formats, experimented with the JavaScript client, built their own tools and tried to understand how the game communicated with its servers. It was an informal but very practical introduction to programming, networking and reverse engineering.
As Miniclip moved Agar.io to an Emscripten-based implementation, the client and server protocol changed. The old extensions and custom clients were still available, but they could no longer communicate with the updated server. A large part of the modding ecosystem was left behind by that transition.
AgarRepacker was a personal experiment to understand the new protocol and determine whether the old ecosystem could be connected to it again.
flowchart LR
A[Legacy Agar.io client] <--> B[AgarRepacker] <--> C[Agar.io server]
AgarRepacker connected both sides and translated their protocols in real time:
- fetched the current
agario.jsandagario.core.jsbundles; - extracted the current client and protocol versions from obfuscated JavaScript;
- processed encrypted and compressed server data;
- rebuilt game state for legacy clients; and
- translated player input into the format expected by the server.
The two protocols did not represent game state in the same way, so this was not just forwarding bytes from one socket to another. The proxy had to parse and reconstruct cells, positions, sizes, colors, skins, nicknames, viruses, leaderboard data and removed nodes.
The two sides of the bridge are documented in the following references:
- Newer protocol / protocol 18 side: NuclearC/agar.io-protocol, packet structures, world updates (
0x10), compressed packets (0xff) and the newer client/server messages. - Old protocol 5 side: dollthing/Agar.io-Protocol, protocols 4 through 8 and the packet layouts used by the old clients.
The conversion operated at the data level:
- the server sent encrypted data, while the handshake provided the movement key and version information used to derive the encryption keys;
0xffcompressed envelopes were decompressed with LZ4, exposing packets such as world updates (0x10) and border updates (0x40);- the
0x10world update was parsed into an in-memory representation of cells, including IDs, positions, sizes, colors, skins, names, flags and removals; repacker.jsmapped those fields and serialized them into a legacy protocol 50x10packet for the old client;- modern leaderboard packets (
0x35/0x36) were converted to the legacy leaderboard packet (0x31); and - legacy client input (
0x00spawn,0x10movement,0x11split and0x15eject) was parsed and sent to the modern server in its encrypted format.
The project had to make two incompatible binary protocols look identical to both sides of the connection.
The proxy did not hard-code the version information. It downloaded agario.js and agario.core.js, extracted the current client version and protocol version from the obfuscated JavaScript, and sent both values during the connection handshake.
The client version string was converted into an integer using the same compact representation as the game:
versionInt = major * 10000 + minor * 100 + patch
The server then returned packet 241. That packet contained a movement key and the server version string. AgarRepacker derived the decryption key by XORing the movement key with the numeric client version:
decryptionKey = movementKey XOR versionInt
The encryption key was derived separately with a custom MurmurHash2 implementation:
encryptionKey = MurmurHash2(serverHost + serverVersion, 255)
The hash processes the input in four-byte blocks, mixes each block with the constant 0x5bd1e995, applies XOR and bit shifts, then performs a final avalanche step. It was used for protocol key derivation, not as a general-purpose encryption algorithm.
Packets were obfuscated with a rolling 32-bit XOR key. The key was represented as four little-endian bytes and repeated over the packet:
packet[i] = packet[i] XOR keyBytes[i % 4]
After each encrypted client packet, the key was passed through a custom 32-bit mixing function. That function used integer multiplication, XOR and right shifts to produce the next key. The server response was decrypted before its opcode was read, so the proxy could inspect the packet type and decide how to process it.
This was not modern authenticated encryption. It was a protocol-specific obfuscation scheme, but reproducing the exact byte order, integer arithmetic and key updates was necessary for the connection to work.
The historical source for this part of the project can still be inspected in the archived February 2017 agario.core.js. The complete XOR routine is present in the generated Emscripten output as function sc(b,d,e):
function sc(b, d, e) {
b = b | 0;
d = d | 0;
e = e | 0;
var f = 0;
var g = 0;
var h = 0;
var j = 0;
j = i;
i = i + 16 | 0;
h = j;
f = c[b + 12 >> 2] | 0;
if (!f) {
i = j;
return;
}
if ((a[b + 28 >> 0] | 0) != 0
? (e | 0) > 0 & (a[14204] | 0) != 0
: 0) {
g = Zg((e | 0) > -1 ? e : -1) | 0;
es(g | 0, d | 0, e | 0) | 0;
b = b + 32 | 0;
d = c[b >> 2] | 0;
c[h >> 2] = d;
d = _(d, 1540483477) | 0;
d = (_(d >>> 24 ^ d, 1540483477) | 0) ^ 114296087;
d = _(d >>> 13 ^ d, 1540483477) | 0;
c[b >> 2] = d >>> 15 ^ d;
if (e) {
d = 0;
do {
b = g + d | 0;
a[b >> 0] = a[b >> 0] ^ a[(h + (d & 3)) >> 0];
d = d + 1 | 0;
} while ((d | 0) != (e | 0));
}
lb(22, c[f >> 2] | 0, g | 0, e | 0) | 0;
$g(g);
i = j;
return;
}
lb(22, c[f >> 2] | 0, d | 0, e | 0) | 0;
i = j;
return;
}The important part of the generated function is the byte loop:
for (offset = 0; offset < length; offset++) {
buffer[offset] ^= keyBytes[offset & 3];
}In the Emscripten memory model, a is the byte heap, c is the 32-bit heap, g is the working packet buffer and h stores the four key bytes. The routine first copies the packet, derives the next key with the 1540483477 multiplier, XORs every byte against the repeating four-byte key and then passes the transformed buffer to the socket layer through lb(...).
This is the original implementation behind the encryption logic reproduced by AgarRepacker. The project followed the same protocol boundary in reverse: decrypt the modern buffer, interpret its packets, translate the data and rebuild packets that legacy clients could understand.
The newer server wrapped compressed payloads in packet 0xff. The proxy removed the packet header and used a small LZ4 block decoder implemented in protocol.js rather than relying on a compression library.
The decoder follows the standard LZ4 token structure:
- the high four bits describe the number of literal bytes;
- literal bytes are copied directly to the output;
- a two-byte little-endian offset points back into the already decoded output; and
- the low four bits describe the match length, with the LZ4 minimum match length of four bytes.
When either length nibble reaches its extension value, additional bytes are read until the complete length is known. The decoder then copies the referenced sequence, allowing repeated data to be reconstructed from a compact representation. Once decompressed, the inner packet is parsed as a normal world update (0x10) or border update (0x40).
World updates were not forwarded unchanged. The proxy parsed each cell and stored its ID, coordinates, size, color, skin, name and flags in memory. It also tracked the player's cells, leaderboard entries and removed nodes.
The legacy packet was then rebuilt field by field. Flags determined whether color, skin and name data had to be written, and the data types and string encodings expected by protocol 5 were different from those used by the newer protocol. This state reconstruction was the core of the repacking process: without it, the old client could not understand the newer server's representation of the game world.
Agar.io was more than a game for me. A significant part of my youth and adolescence was shaped by this community, and it was where I learned how to program, reverse engineer software, understand networking and build things that other people could use.
Much of what I do today traces back to this community. The people, the projects, the packet dumps, the early experiments and the .io research and development group had a much bigger impact on me than I understood at the time.
Much of my success in technology comes from the skills I learned here first: reverse engineering, networking, binary formats, independent learning and building tools from scratch. Much of what I do today is a more advanced version of the things I started experimenting with in this community.
This project would not have been possible without the Agar.io modding and reverse-engineering community. The newer protocol / protocol 18 reference and the old protocol 5 reference were important resources for understanding how the packets were structured and converted between the two sides.
Special thanks to Nel, MrSonic Master, Henopied and the other reverse-engineering friends whose names I no longer remember. Thanks also to the .io research and development group, a community of people who worked to understand the protocol and keep the old ecosystem alive before everything changed.
See LICENSE.