# Internals

## Experience

This was figured out by QuixoticTocsin and originally posted on Reddit [1]

Using Cheat Engine to explore the internals of Cube World: Character Experience

To keep a long story short, I've found the code responsible for the experience scaling at Cube.exe+4847F

*(This code is only triggered if you level legitimately by killing a mob and gaining its experience):*

Cube.exe+4847F - movd xmm1,[esi+00000190]

Cube.exe+48487 - movss xmm2,[Cube.exe+344D68] (1.00)

Cube.exe+4848F - movss xmm3,[Cube.exe+2FBDB4] (0.05)

Cube.exe+48497 - cvtdq2ps xmm1,xmm1

Cube.exe+4849A - movaps xmm0,xmm2

Cube.exe+4849D - subss xmm1,xmm2

Cube.exe+484A1 - movss xmm4,[Cube.exe+2FC8F4] (1000.0)

Cube.exe+484A9 - movss xmm5,[Cube.exe+2FBD7C] (50.0)

Cube.exe+484B1 - mulss xmm1,xmm3

Cube.exe+484B5 - addss xmm1,xmm2

Cube.exe+484B9 - divss xmm0,xmm1

Cube.exe+484BD - movaps xmm1,xmm2

Cube.exe+484C0 - subss xmm1,xmm0

Cube.exe+484C4 - mulss xmm1,xmm4

Cube.exe+484C8 - addss xmm1,xmm5

Cube.exe+484CC - cvttss2si eax,xmm1

If we translate the code into a human readable format, we get:

**experience = 50 + 1000 * ( 1 - 1/((level - 1)*0.05 + 1) )**

Or simplified:

**experience = (1050 * level - 50)/(level + 19)**

The truncated result of that formula at the decimal point (ignore everything after the decimal point), is the experience needed to get to the next level!

We can use this function to make the following graphs for the levels 1 to 200:

Experience needed to level up, in function of the level[2]

Total experience needed to reach a certain level[3]

Using the power of calculus, we can find a formula for the total amount of experience needed to reach a certain level, starting from level 1:

**total_experience = 50 (21 * (level - 1) + 400 * log(20) - 400 * log(19 + level))**

Sadly enough, this formula is not accurate. The discrete nature and the truncation of the experience introduces an error in our results.

The graph above was created by summing all the previous truncated results, if we overlay our function:

Discrete total experience vs. continuous total experience[4]

We see that our function slightly overestimates the total experience needed. However, it is certainly acceptable!

We can go a little bit further and give a formula for the estimate for the amount of experience needed to go from level_a to level_b:

**experience_from_a_to_b = 50 * (21 * (level_b - level_a) + 400 * log(19 + level_a) - 400 * log(19 + level_b))**

## Character Health

This was figured out by QuixoticTocsin and originally posted on Reddit [5]

Using Cheat Engine to explore the internals of Cube World: Character Health

### Base Health

This is base health, without any armor/weapons equipped that change your health stat.

Turtles, or in general other mobs/bosses, are also not included in this formula. This only applies to your character with empty equipment slots.

*Because of the size of the code, I can't paste it here without taking up too much of the allotted space. *

- You can find the relevant piece of code yourself at :
**Cube.exe+45620**if you're curious.

The formula that defines your maximum health is as follows:

base_health = scaling_factor * class_coefficient * 2^(3 * (level - 1)/(level + 19) + 1)

Where scaling factor is always 100.0 and class_coefficient one of the following:

- class_coefficient = 1.00 for mages

- class_coefficient = 1.10 for rangers

- class_coefficient = 1.20 for rogues

- class_coefficient = 1.30 for warriors

Keep in mind that guardians get an extra 25% health!

Full disclosure: this expression is already simplified, it isn't a carbon copy of the formula as found in the Cube World binary.

Now to the fun part: plots! If we plot the above function for all the classes, we get the following curves for levels 1-500:[6]

Health in function of the level, for different classes. The topmost curve is the health of a warrior character with the guardian bonus, followed by (in descending order) a warrior, a rogue, a ranger and a mage character.

If you want to change your health without touching your level, you can try to find the scaling_factor and change that! It is stored near to where your current xp is stored, but isn't saved to the disk when switching your character or exiting the game.