Change a units.dat or weapons.dat value with EUD and it appears to work, then at some point it is back to the stock value. Before you go hunting for the bug: this is normal. The game re-reads and refills these tables from several paths, so a single write is not guaranteed to survive.
The fix is simple and boring: write it again every cycle. With hyper triggers running that is more than twenty rewrites a second, so whatever puts the stock value back is overwritten on the next pass.
function applyWeapon(w, dmg, cd) {
// 매 사이클 다시 쏀니다 / rewritten every cycle
Weapon(w).damage = dmg;
Weapon(w).cooldown = cd;
}This is not a performance concern. A dat write is a single memory write, and dozens of them every cycle do not add measurable load. What the saving does buy you is a bug that is hard to reproduce.
But there is a separate family of fields where rewriting every cycle changes nothing at all, and it is a different phenomenon. Appearance, elevation, start direction, movement speed and maximum hit points are read once, when the unit is created, and copied into that unit's own struct. Editing the table therefore leaves every unit already on the map exactly as it was - you changed the factory setting, not the units already shipped. Whereas weapon damage, armour and cooldown are looked up in the table every time the game needs them, so a write there reaches every unit at once.
So to change one of those on a living unit you write its struct, not the table. Maximum hit points is the standard example: units.dat decides what new units get, and the value a living unit actually has is CUnit 0x08.
This is not only an obstacle - it is useful. Write the table, create one unit, write the table straight back, and that single unit has a property no other unit of its id has, without spending a unit id on it. The afterimage trail is built exactly this way: change the image's drawing function, create one copy, restore it on the very next line. The restore cannot undo the copy the new unit already holds, so the ghost stays translucent.
There is also an inverse. You can tell a unit that is already alive to re-read the tables now - that is order 41, Zerg Birth. It rebuilds the unit's image from the tables as they are at that moment: the forced re-latch of the graphics chain that is otherwise copied once, at creation, and there is no other way to redo it.
TrgUnit("Marine").graphics = NEW_FLINGY; // 표를 먼저 고치고 / change the table first
SetMemoryXEPD(u + 0x4C/4, SetTo, 41 * 256, 0xFF00); // 명령 41
SetMemoryXEPD(u + 0x4C/4, SetTo, 4 << 24, 0xFF000000); // orderSignal 4
SetMemoryXEPD(u + 0x50/4, SetTo, 0, 0xFF); // orderState 0| It rebuilds the image | It re-reads units.dat, flingy.dat, sprites.dat and images.dat as they are now, so an appearance change lands on a living unit immediately. |
|---|---|
| It wipes everything attached | Shadows, overlays and linked images all go. If you were using an overlay, re-apply it after the order, not before. |
| It faces the production direction | The unit ends up facing that type's startDirection. If facing matters, read it first and write it back. |
| It ignores collision briefly | Being a birth animation it allows a brief overlap, and Zerg flyers get nudged upward. |
There are clear places it does nothing and clear places it crashes. Under Lockdown, Stasis or Maelstrom, or unpowered, nothing happens at all. On a burrowed unit or a Spider Mine it crashes. And the 1Egg2Unit setting has to be off.
In the same family: order 44 with orderState 5 leaves a Terran building functional while it looks unfinished - one line, for when you want a working building that reads as a construction site.
The converse also holds: some things only need writing once. Data you put in memory the game does not refill - button records, for instance - is written once, and only the pointer to it is restated every cycle. Rewriting the records every cycle is what tears the display, because the content changes under the cursor.
And before writing, make sure the address really is that field. Field order in the file and address order in memory are not the same thing. In images.dat alone, GRP File sits in the middle of memory at 0x668AA0, and Draw Function comes before Remapping in the file but at the higher address in memory - 0x669E28 against 0x669A40. "The earlier field has the lower address" is not a valid inference.
Those two were a long-standing muddle. eud_book attaches the descriptions the other way round, while every working map writes the drawing function to 0x669E28 - and the HP-bar code writes 16 there, impossible for a remapping table whose values stop at 5 and whose 6 and 7 crash. EUD Editor 3's own schema gives the same answer. 0x669A40 does nothing on Remastered, which is how it became the 1,000 bytes of free space the wireframe-colour technique uses.
