GithubHelp home page GithubHelp logo

d2slib's Introduction

D2SLib

Simple C# library for reading and writing Diablo 2 saves. Supports version 1.10 through Diablo II: Resurrected (1.15). Supports reading both d2s (player saves) and d2i (shared stash) files.

Usage

Use Nuget to add D2SLib to your project.

using D2SLib;
using D2SLib.Model.Save;

....
//read a save
D2S character = Core.ReadD2S(File.ReadAllBytes(@"Resources\D2S\1.15\DannyIsGreat.d2s"));

//outputs: DannyIsGreat
Console.WriteLine(character.Name);

//convert 1.10-1.114d save to d2r 1.15
character.Header.Version = 0x61;

 //set all skills to have 20 points
character.ClassSkills.Skills.ForEach(skill => skill.Points = 20);

//add lvl 31 conviction arua to the first statlist on the first item in your chars inventory
character.PlayerItemList.Items[0].StatLists[0].Stats.Add(new ItemStat { Stat = "item_aura", Param = 123, Value = 31 });

//write save
File.WriteAllBytes(Environment.ExpandEnvironmentVariables($"%userprofile%/Saved Games/Diablo II Resurrected Tech Alpha/{character.Name}.d2s"), Core.WriteD2S(character));

How to seed the library with your own TXT files

TXT txt = new TXT();
txt.ItemStatCostTXT = ItemStatCostTXT.Read(@"ItemStatCost.txt");
txt.ItemsTXT.ArmorTXT = ArmorTXT.Read(@"Armor.txt");
txt.ItemsTXT.WeaponsTXT = WeaponsTXT.Read(@"Weapons.txt");
txt.ItemsTXT.MiscTXT = MiscTXT.Read(@"Misc.txt");
Core.TXT = txt;
D2S character = Core.ReadD2S(File.ReadAllBytes(@"DannyIsGreat.d2s"));
Useful Links:

d2slib's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

d2slib's Issues

Having issues using the Library

Hi,

I am able to open d2i files for example Beserker's Arsenal Armor. Then I have an instance of the Item class. So far so good. I analysed the class properties, fields and method, but I can't manage to get the name of the object. I'm looking for the item's set name, in this case "Berserker's Hauberk".

Can you help me ?

Thanks in advance

Item stat cost resolved failed in DS2Lib C# version but successfully in D2S JS version

Item stat cost resolved failed in DS2Lib C# version but successfully in D2S JS version

JQ.d2s.zip
stats2

Hi master, I found a strange issue when I resolving item stat cost by using your stable C# DS2Lib (Version 2.0 from NUGET).

In the attached JQ.d2s.zip file, I have a wand which has 2 item stat cost. One is ID 37 ( magic resist ) and value is 11, the other one is ID 39 ( fire resist ) and value is 12.

The item stats can be correctly resolved by JS library version, just check the attached picture.

But failed in C# D2SLib version. My program can successfully get 1st item stat cost as ID=37, but a wrong value 211 instead of 11. And then , the next stat cost ID is resolved as a wrong value 78 instead of 39, at last failed in a not existing cost id 507.

I don't know the differences between JS version and C# version , would you please kindly check the C# code?

Thanks!!!

Item count doesn't match

Attached file:
MfBowzon.zip

This file has 56 items, but after parsing 55 items it reached the end of the item section, then trying to parse the 56th one from the corpse section (begins at 0x07F5, which cause an error).

Read binary with struct

`public static class BinaryReaderExt
{
public static T ReadStruct(this BinaryReader reader)
{
byte[] bytes = reader.ReadBytes(Marshal.SizeOf(typeof(T)));

    GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
    T theStructure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
    handle.Free();

    return theStructure;
}

}`

It will fill the struct with binary.

incorrect value in read/write Armor

writer.WriteUInt16((ushort)(item.Armor - itemStatCost.GetByStat("armorclass")?["Save Add"].ToUInt16() ?? 0), 11);

should be:
writer.WriteUInt16((ushort)(item.Armor + itemStatCost.GetByStat("armorclass")?["Save Add"].ToUInt16() ?? 0), 11);

item.Armor = (ushort)(reader.ReadUInt16(11) + itemStatCost.GetByStat("armorclass")?["Save Add"].ToUInt16() ?? 0);
should be:
item.Armor = (ushort)(reader.ReadUInt16(11) - itemStatCost.GetByStat("armorclass")?["Save Add"].ToUInt16() ?? 0);

Same NPCDialogDifficulty data

idx variable should be declared upper then cycle foreach (var npcDialogSectionProperty in typeof(NPCDialogSection).GetProperties())
In this moment every NPCDialogDifficulty in NPCDialogSection have same data

var skippedProperties = new string[] { "Header", "Length" };
foreach (var npcDialogSectionProperty in typeof(NPCDialogSection).GetProperties())
{
if (skippedProperties.Contains(npcDialogSectionProperty.Name)) continue;
NPCDialogDifficulty npcDialogDifficulty = new NPCDialogDifficulty();
int idx = 0;
foreach (var property in typeof(NPCDialogDifficulty).GetProperties())
{
NPCDialogData data = new NPCDialogData();
data.Introduction = bits[idx];
data.Congratulations = bits[idx + (0x18 * 8)];
idx++;
property.SetValue(npcDialogDifficulty, data);
}
npcDialogSectionProperty.SetValue(npcDialogSection, npcDialogDifficulty);
}

Nullreference exception when trying to read a sharedstorage.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.