.genome file

Genomes are stored in the device in the form of **.genome files**.

## Format

A .genome file consists of 12,673 bytes. 12,600 of these bytes are used for encoding the genome modes,

The first four bytes are `AC ED 00 05`, which indicates the start of a Java stream format. Then, the next 5 bytes are `7A 00 00 04 00`, where `7A` indicates that it is the beginning of a data block, and `00 00 04 00` indicates the block's length (1024). Following that, after every 1024 bytes, there would be another data block marker with the same 5 bytes, except the last one, which instead reads `7A 00 00 01 3C`, where `00 00 01 3C` means 316. This corresponds with the fact that there are only 316 bytes to be written after this marker.

Following the first data block marker, there is the genome version file, which is currently 95, which translates into `00 00 00 5F`. After that, the modes will start to be written in the format below. If a mode cannot be written into the remaining space in a data block, the rest of it will be written in the next block.

Each mode consists of 315 bytes, which can be divided into the following segments:

* **4 bytes - Version number** (95)
* **63 bytes - Basic settings**
	+ **4 bytes (float)** - Red color
	+ **4 bytes (float)** - Green color
	+ **4 bytes (float)** - Blue color
	+ **4 bytes (float)** - Split mass
	+ **4 bytes (float)** - Split ratio
	+ **4 bytes (float)** - Split angle
	+ **4 bytes (float)** - Child 1 angle
	+ **4 bytes (float)** - Child 2 angle
	+ **4 bytes (float)** - Nutrient priority
	+ **4 bytes (int)** - Child 1 mode
	+ **4 bytes (int)** - Child 2 mode
	+ **1 byte (boolean)** - Make adhesin
	+ **1 byte (boolean)** - Keep adhesin (child 1)
	+ **1 byte (boolean)** - Keep adhesin (child 2)
	+ **4 bytes (int)** - Cell type
	+ **4 bytes (int)** - The number zero (`00 00 00 00`)
	+ **1 byte (boolean)** - Prioritize / Stay alive
	+ **1 byte (boolean)** - Initial
	+ **1 byte (boolean)** - Mirror (child 1)
	+ **1 byte (boolean)** - Mirror (child 2)
	+ **4 bytes (float)** - Adhesin stiffness
* **11 × 16 bytes - Programmable values**

Each of the sub-segments of this segment consists of the following values:

* **2 bytes (short)** - Input cell state.
* **2 bytes (short)** - Equation type.
* **4 bytes (float)** - Variable a.
* **4 bytes (float)** - Variable b.
* **4 bytes (float)** - Variable c.

This segment consists of the following sub-segments:

* Flagellocyte swim force
* Buoyocyte density
* Myocyte muscle bending / Ciliocyte left movement
* Myocyte muscle contraction
* Myocyte muscle lift / Ciliocyte right movement
* Stemocyte path 1 signal
* Stemocyte path 2 signal
* Neurocyte channel 1 output value
* Neurocyte channel 2 output value
* Neurocyte channel 3 output value
* Neurocyte channel 4 output value

* **7 × 4 bytes - Other float values**
	+ Senseo/Stereocyte output value
	+ Red color (smell)
	+ Green color (smell)
	+ Blue color (smell)
	+ Smell color threshold
	+ Adhesin length
	+ Cytoskeleton
* **11 × 4 bytes - Other int values**
	+ Virus copy from / Gamete mode after fertilization
	+ Gamete compatible mode
	+ Senseo/Stereocyte smell output signal type
	+ Senseo/Stereocyte smell type
	+ Secrocyte secretion type
	+ Neurocyte channel 1 signal type
	+ Neurocyte channel 2 signal type
	+ Neurocyte channel 3 signal type
	+ Neurocyte channel 4 signal type
	+ Max connections
	+ Telomeres

## Trivia

* Most players prefer sharing and receiving .substrate files rather than .genome files, for the following reasons:
	+ Most genomes have one kind of suitable substrate conditions, and sending only a .genome file makes it hard for players to find the right substrate conditions.
	+ Some genomes require special preparation steps, and these can be complicated to understand.
	+ Some players are bad at naming genomes, making it hard for other players to find it in their genome bank. In addition, if a genome has the same name as a genome already in the bank, e.g. a very popular name, the game would not allow the player to open it.

## External links

* https://github.com/kpws/Cell-Lab-open-utilities/blob/master/Gene.java - a genome reader made by Petter. Helped a lot in making the list above.
* https://docs.oracle.com/javase/8/docs/platform/serialization/spec/protocol.html