collinsmith / riiablo

Diablo II remade using Java and LibGDX
http://riiablo.com
Apache License 2.0
872 stars 99 forks source link

Item serialization is not serializing socketed items #92

Closed collinsmith closed 3 years ago

collinsmith commented 3 years ago

Item data should include any socketed items.

D2S is flawed and is not reading item sockets as part of the item data. Instead, an item is read, and then n more items is read equal to the number of populated sockets. This results in the cached data for an item not including any children's data. The cached data is placeholder until proper serialization is implemented, but this fix should be much easier until that's figured out.

collinsmith commented 3 years ago

This issue is a bit tricky. D2S currently slices the input buffer from jm to jm or jm to buffer.length (slices are each an individual item). This is because the original intention was to provide a recovery point to resume item parsing (wasn't implemented, it should just stop parsing items if it encounters an error).

I think the implementation should be changed to wrap the entire input stream in a BitStream which then attempts to read a jm and then item data (and subsequent socketed items). If an error is encountered, that item should be dropped, the BitStream aligned to the nearest byte, and then dump the input until another jm is reached where the jm is not a socketed item. Once jm00 is reached, terminate item data read. Unsure how this will affect the item count/indexes.

In this context, 4A 4D 00 00 indicates the end of the items, but it may be the case that this is interpreted as a new item list where 00 00 means 0 items (i.e., no different than the actual item list).

I need to figure out how to best proceed. This needs to support D2S.ItemData read and ItemSerializer read.

collinsmith commented 3 years ago

Fixed by 2beecb35a8f7ef1d9b5c43c368f63c9dd51bef3f