Most dat fields are 8 or 16 bits. Weapon damage is u16, so the maximum is 65,535, and past that it wraps with no warning - you get a unit that gets weaker the more you upgrade it, which is about the hardest kind of bug to see.
| weapons.dat damage | u16, max 65,535. If your design multiplies by anything, compute the peak and clamp it yourself. |
|---|---|
| units.dat maxHp | A u32 storing hit points x256 - but the largest usable body is 8,388,607. See the warning below. |
| An eudplib variable | An unsigned 32-bit value. Think about dividing before multiplying when the numbers get large. |
The hit point ceiling is 8,388,607, not 16,777,215. The units.dat field is a u32 holding hit points x256, which is where the larger number comes from - but the engine copies that value into the unit's own hit point field on creation, and that field is signed. Past 0x7FFFFFFF - that is, past 8,388,607 hit points - every piece of damage code reads the body as having negative health and it dies to the first shot that touches it, with a full green health bar. It is also exactly what SCMDraft's unit dialog accepts, which is not a coincidence.
This was measured in game and corrected in October 2026. A tower defence map clamped at 16,000,000 and shipped two builds that way; from round 230 its bosses died to a single shot. In the source it looks clamped, and in game the health bar is full, so nobody suspects it. Anything computing hit points near the ceiling has to bound itself rather than trust the clamp.
There is a way past the hit point ceiling, and it is not a bigger field: a shadow pool kept beside the unit.
- 1Keep the real body at a threshold well under the ceiling - eight million, say.
- 2Hold the rest in a per-unit space of your own. Store whole hit points without the x256 fraction and a u32 carries about 4.2 billion.
- 3Look at the HP every frame. Where it has dropped below the threshold, the difference is the damage taken.
- 4Put the HP back to the threshold and take that much off the shadow pool. If the pool runs short, apply the remainder to the real HP, and kill the unit if even that is exceeded.
Several hits inside one frame read as one difference, which is correct, and means no damage hook is needed. Keep the units in a UnitGroup and the per-frame cost scales with how many have a shadow pool, not with 1,700.
var dmg = (base + upg * step) * (100 + level * perk) / 100;
if (dmg > 65535) { dmg = 65535; } // 래핑보다 제한이 낫다 / clamping beats wrapping
Weapon(w).damage = dmg;It is also worth knowing how to check an offset is real. A dat file is per-field arrays laid end to end, so the sum of every field's (width x entry count) must equal the file size exactly. If it does not, you have the order or a width wrong - and writing with it will clobber a different field.
For example weapons.dat is 130 entries at 42 bytes each - 5,460 - and flingy.dat is 209 at 15, which is 3,135. When that sum lands exactly, it is fairly strong evidence you have the layout right.
