Skip to content

Commit

Permalink
Fix positionY not reading the full value when gridY is larger than de…
Browse files Browse the repository at this point in the history
…fault

Fixes PlugY positionY values being read incorrectly, as well as any modded D2 saves that change Inventory.txt to increase gridY. In vanilla D2, the Y value never uses the 4th bit since the largest used gridY in Inventory.txt is 8, which lead to the 4th bit erroneously being labeled 'unknown' in previous d2s format guides. Whoops!

Closes #9. Thanks to @oaken-source for finding the problem.
  • Loading branch information
squeek502 committed Sep 25, 2021
1 parent 8c9a1fb commit 026bfad
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
3 changes: 1 addition & 2 deletions docs/formats/d2.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ Bit Offset | Size (bits) | Description
58 | 3 | Item location. See [the `locationID` field of the `d2item` struct](/api.html#structd2item).
61 | 4 | Item equipped location. See [the `equippedID` field of the `d2item` struct](/api.html#structd2item).
65 | 4 | Item position X coordinate
69 | 3 | Item position Y coordinate
72 | 1 | Unknown
69 | 4 | Item position Y coordinate
73 | 3 | Panel containing the item. See [the `panelID` field of the `d2item` struct](/api.html#structd2item).
76 | ... | If the item is an ear (bit offset 32), then see "Ear", otherwise skip to "Non-Ear"
Expand Down
4 changes: 1 addition & 3 deletions src/d2itemreader.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,7 @@ CHECK_RESULT d2err d2item_parse_single(const uint8_t* const data, size_t dataSiz
// offset 65
item->positionX = (uint8_t)d2bitreader_read(&br, 4);
// offset 69
item->positionY = (uint8_t)d2bitreader_read(&br, 3);
// offset 72
d2bitreader_read(&br, 1);
item->positionY = (uint8_t)d2bitreader_read(&br, 4);
// offset 73, if item is neither equipped or in the belt, this tells us where it is.
item->panelID = (uint8_t)d2bitreader_read(&br, 3);

Expand Down

0 comments on commit 026bfad

Please sign in to comment.