All Projects → squeek502 → d2itemreader

squeek502 / d2itemreader

Licence: Unlicense license
C library for parsing items in Diablo II character/stash files

Programming Languages

c
50402 projects - #5 most used programming language
CMake
9771 projects
C++
36643 projects - #6 most used programming language
Batchfile
5799 projects

Projects that are alternatives of or similar to d2itemreader

d2lootfilter
No description or website provided.
Stars: ✭ 30 (+0%)
Mutual labels:  diablo, diablo-ii
d2dx
D2DX is a complete solution to make Diablo II run well on modern PCs, with high fps and better resolutions.
Stars: ✭ 214 (+613.33%)
Mutual labels:  diablo, diablo-ii
d2launcher
Diablo II • Median XL • Mod Launcher for Linux
Stars: ✭ 20 (-33.33%)
Mutual labels:  diablo-ii
d2modmaker
A program that lets you mod Diablo II from a config
Stars: ✭ 82 (+173.33%)
Mutual labels:  diablo
slashdiablo-launcher
A lightweight cross platform Slashdiablo game launcher for Diablo II, written in Go & QML.
Stars: ✭ 29 (-3.33%)
Mutual labels:  diablo-ii
portal
Character Planner for Diablo II
Stars: ✭ 23 (-23.33%)
Mutual labels:  diablo
d2s edit recalc
Simple D2 LoD and D2R char save editor
Stars: ✭ 15 (-50%)
Mutual labels:  diablo-ii
d2client
Client able to write and read data over TCP on a Diablo II server.
Stars: ✭ 15 (-50%)
Mutual labels:  diablo-ii
Opendiablo2
An open source re-implementation of Diablo 2
Stars: ✭ 10,057 (+33423.33%)
Mutual labels:  diablo
Devilution
Diablo devolved - magic behind the 1996 computer game
Stars: ✭ 8,274 (+27480%)
Mutual labels:  diablo
Devilutionx
Diablo build for modern operating systems
Stars: ✭ 5,015 (+16616.67%)
Mutual labels:  diablo
wined3d-diablo
Wine Direct3D DLL patched for Diablo I game
Stars: ✭ 12 (-60%)
Mutual labels:  diablo
bncsutil
The Classic Battle.net™ client library
Stars: ✭ 19 (-36.67%)
Mutual labels:  diablo
d1-graphics-tool
Diablo 1 Graphics Tool
Stars: ✭ 15 (-50%)
Mutual labels:  diablo
equine
Mod manager/launcher for Diablo 1
Stars: ✭ 27 (-10%)
Mutual labels:  diablo
d2s
Diablo II file format binary parser written in Go.
Stars: ✭ 126 (+320%)
Mutual labels:  diablo-ii
gomule-d2r
GoMule enabled for D2R
Stars: ✭ 53 (+76.67%)
Mutual labels:  diablo-ii

d2itemreader

Build status Build status

work in progress, everything is subject to change

d2itemreader is a C library for parsing Diablo II character/stash files (.d2s, .d2x, and .sss) and retrieving data about the items contained inside them. It also tries to avoid any assumptions about the game version or game data, so that it can work with modded files (provided the library is initialized with the relevant modded .txt files on startup).

Usage

Most API functions in d2itemreader.h work in the following way:

  • There is a <struct>_parse function that takes a pointer to a struct and returns a d2err enum.
    • If the function returns D2ERR_OK, then the function succeeded and the struct will need to be cleaned up using the corresponding _destroy function.
    • If the function returns anything other than D2ERR_OK, then the _destroy function does not need to be called; any allocated memory is cleaned up by the _parse or _init function before it returns an error.
    • The out_bytesRead parameter will always be set regardless of the result of the _parse function. On failure, it will contain the number of bytes read before the error occured.

On program startup, you will need to initialize a d2gamedata struct with the data from some of Diablo II's .txt files found in its .mpq archives. For convenience, d2itemreader bundles the relevant data from the latest .txt files (1.14d), which can be loaded by calling:

d2gamedata gameData;
d2err err = d2gamedata_init_default(&gameData);

If the d2gamedata_init function returns D2ERR_OK, the following function should be called on shutdown (or when you're done using the d2itemreader library):

d2gamedata_destroy(&gameData);

After the d2gamedata_init function is called, you can parse files like so:

const char *filename = "path/to/file";

// determine the filetype if it is not known in advance
enum d2filetype filetype = d2filetype_of_file(filename);

if (filetype != D2FILETYPE_D2_CHARACTER)
{
	fprintf(stderr, "File is not a d2 character file: %s\n", filename);
	return;
}

size_t bytesRead;
d2char character;
d2err err = d2char_parse_file(filename, &character, &gameData, &bytesRead);
if (err != D2ERR_OK)
{
	fprintf(stderr, "Failed to parse %s: %s at byte 0x%zx\n", filename, d2err_str(err), bytesRead);
	// don't need to call d2char_destroy, the memory is cleaned up when _parse returns an error
}
else
{
	// do something with the character data
	int numUniques = 0;

	for (int i=0; i<character.items.count; i++)
	{
		d2item* item = &character.items.items[i];
		if (item->rarity == D2RARITY_UNIQUE)
		{
			numUniques++;
		}
	}

	printf("Number of unique items in %s: %d", filename, numUniques);

	// clean up the memory allocated when parsing the character file
	d2char_destroy(&character);
}

Bindings

Acknowledgements

  • nokka/d2s - much of the d2s parsing of d2itemreader is ported from nokka/d2s
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].