D2SLib icon indicating copy to clipboard operation
D2SLib copied to clipboard

Nullreference exception when trying to read a sharedstorage.

Open Salepate opened this issue 2 years ago • 2 comments

Hello,

I tried accessing a d2i file (created through a offline playthrough in D2R). But I get a nullreference exception when trying to read the data

    byte[] bytes = File.ReadAllBytes("test.d2i");
    D2I save = Core.ReadD2I(bytes, 0x61);

The project is a .netcore 3.1 (lts) console application. My diablo 2 R installation is up to date.

Any idea what could cause this?

I tried running the unit test using my shared storage file :

Message: 
    Test method D2SLibTests.D2ITest.VerifyCanReadSharedStash115 threw exception: 
    System.NullReferenceException: Object reference not set to an instance of an object.
  Stack Trace: 
    Item.ReadComplete(BitReader reader, Item item, UInt32 version) line 313
    Item.Read(BitReader reader, UInt32 version) line 152
    ItemList.Read(BitReader reader, UInt32 version) line 62
    D2I.Read(Byte[] bytes, UInt32 version) line 18
    Core.ReadD2I(Byte[] bytes, UInt32 version) line 49
    D2ITest.VerifyCanReadSharedStash115() line 19`

Taking a look at the callstack the itemList received strange values but I still don't know why

        public static ItemList Read(BitReader reader, UInt32 version)
        {
            ItemList itemList = new ItemList();
            itemList.Header = reader.ReadUInt16(); // <====== yield 43605
            itemList.Count = reader.ReadUInt16(); // <====== yield 43605
            // ...

After further analysis, I've come to realize that the serializer may have been outdated? I've tried several operations on the storage and each storage page begins with 55 AA 55 AA (43605 43605)

Regards

I shared my storage file in case you want to test it: https://mega.nz/file/t1sRCKoR#UaGEkK6jIfLLHBtwaIhMob0atSE_AVajSSuVgqFdNDo

Salepate avatar Oct 28 '21 08:10 Salepate