fix(saves): read and write DOS Beta champions with the Beta layout #341

Merged
jqueuniet merged 2 commits from fix/beta-champion-layout into main 2026-10-24 18:19:58 +02:00
Owner

Closes #340

Champion picked offsets from byte order alone, so DOS Beta champions used the retail layout. New ChampionLayout { DosRetail, Mac, DosBeta } selects mask and field offsets; Beta decode paths and the JSON rebuild (GameplayJson::to_wire now takes the save variant) use it.

Field Retail Beta
abilities 0x4A [7][2] + eability 0x58 0x48 [7][3]
herotype / ench_aura 0x101 / 0x102 0xFF / 0x100

API changes

  • enhanced_ability → Option<u8> (None on Beta); set_enhanced_ability → bool.
  • decode_champions_with_mask replaced by decode_champions_with_layout.
  • JSON abilities.*.enhanced is null on Beta; a value there is rejected (FieldNotInVariant). dm2 save champion --set <a>.enh errors on Beta.

Tests

  • Beta fixture: abilities and herotype read the expected values at the Beta offsets.
  • Beta edits (abilities, herotype, ench_aura) survive re-encode; herotype was dropped before.
  • JSON-vs-CLI ability edit test now also checks the decoded value.

Not done

  • The third ability byte on Beta (0x1E on every fixture) stays unidentified; it is preserved through raw.
  • Beta ench_aura is 2 bits; the setter does not reject wider values (same as retail's 4-bit mask today).
Closes #340 `Champion` picked offsets from byte order alone, so DOS Beta champions used the retail layout. New `ChampionLayout { DosRetail, Mac, DosBeta }` selects mask and field offsets; Beta decode paths and the JSON rebuild (`GameplayJson::to_wire` now takes the save variant) use it. | Field | Retail | Beta | | --- | --- | --- | | abilities | 0x4A `[7][2]` + `eability` 0x58 | 0x48 `[7][3]` | | `herotype` / `ench_aura` | 0x101 / 0x102 | 0xFF / 0x100 | ## API changes - `enhanced_ability` → `Option<u8>` (`None` on Beta); `set_enhanced_ability` → `bool`. - `decode_champions_with_mask` replaced by `decode_champions_with_layout`. - JSON `abilities.*.enhanced` is `null` on Beta; a value there is rejected (`FieldNotInVariant`). `dm2 save champion --set <a>.enh` errors on Beta. ## Tests - Beta fixture: abilities and `herotype` read the expected values at the Beta offsets. - Beta edits (abilities, `herotype`, `ench_aura`) survive re-encode; `herotype` was dropped before. - JSON-vs-CLI ability edit test now also checks the decoded value. ## Not done - The third ability byte on Beta (0x1E on every fixture) stays unidentified; it is preserved through `raw`. - Beta `ench_aura` is 2 bits; the setter does not reject wider values (same as retail's 4-bit mask today).
fix(saves): read and write DOS Beta champions with the Beta layout
Some checks failed
CI / msrv (1.90) (pull_request) Successful in 44s
CI / audit (pull_request) Successful in 20s
CI / stable (pull_request) Failing after 1m45s
CI / python bindings (3.11) (pull_request) Successful in 47s
c4e9801f7d
Champion offsets came from byte order alone, so Beta (little-endian)
champions used the retail layout. Beta drops the poison u16 and stores
abilities as [7][3] triples with no eability array: abilities,
herotype and ench_aura hit the wrong bytes, and herotype edits landed
on a mask-0 byte and were dropped. ChampionLayout now selects mask and
offsets; the JSON rebuild threads the save variant through.

Closes #340
docs(saves): point encode_champions_with_mask at decode_champions_with_layout
All checks were successful
CI / stable (pull_request) Successful in 1m48s
CI / python bindings (3.11) (pull_request) Successful in 46s
CI / python bindings (3.11) (push) Successful in 44s
CI / msrv (1.90) (pull_request) Successful in 43s
CI / audit (pull_request) Successful in 20s
CI / msrv (1.90) (push) Successful in 43s
CI / audit (push) Successful in 23s
CI / stable (push) Successful in 1m46s
1547d415ba
jqueuniet deleted branch fix/beta-champion-layout 2026-10-24 18:19:58 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jqueuniet/dm2-tools!341
No description provided.