Skip to main content

Diablo II: Resurrected Loot Tooltip Reader

Project description

D2R Loot Reader

A Python library for parsing Diablo II: Resurrected item tooltips into structured JSON data.

License: GPL v3 Python 3.8+

D2R Loot Reader is a technical tool designed for developers, modders, and enthusiasts building applications for the Diablo II: Resurrected community. It uses advanced OCR (Optical Character Recognition) and fuzzy string matching to convert in-game item tooltips into machine-readable JSON format.

🎯 Use Cases

  • Loot Tracking Applications: Build tools to track valuable drops and analyze loot statistics
  • Trading Platforms: Create automated item cataloging for trading websites
  • Game Enhancement Tools: Develop overlays or assistants that provide item information
  • Data Analysis: Extract item data for statistical analysis and game research

🚀 Quick Start

Prerequisites

  • Python 3.8+
  • Tesseract OCR

Installation

pip install d2r-loot-reader

CLI Command

# Interactive screen capture, OCR and JSON parsing
d2rlootreader capture

Basic Usage

from d2rlootreader.item_parser import ItemParser

# Parse tooltip text lines into structured JSON
lines = [
    "Rare Ring",
    "Required Level: 15", 
    "+25 to Life",
    "+15% Faster Cast Rate"
]

parser = ItemParser(lines)
item_data = parser.parse_item_lines_to_json()
print(item_data)

📊 Output Format

The parser produces structured JSON following this schema:

{
  "quality": "Unique|Set|Rare|Magic|Runeword|Base",
  "name": "Fortitude",
  "base": "Great Hauberk",
  "slot": "Body",
  "tier": "Elite",
  "requirements": {"strength": 118, "level": 59},
  "stats": {"defense": [1596]},
  "affixes": [
    ["#% Chance to cast level # [Skill] when struck", [20, 15, "Chilling Armor"]],
    ["+#% Faster Cast Rate", [25]],
    ["+#% Enhanced Damage", [300]],
    ["+#% Enhanced Defense", [215]],
    ["+# Defense", [15]],
    ["+# to Life (Based on Character Level)", [101]],
    ["Replenish Life +#", [7]],
    ["+#% to Maximum Lightning Resist", [5]],
    ["All Resistances +#", [29]],
    ["Damage Reduced by #", [7]],
    ["+#% Damage Taken Goes To Mana", [12]],
    ["+# to Light Radius", [1]],
    ["Increase Maximum Durability #%", [13]],
    ["Socketed (#)", [4]]
  ],
  "tooltip": ["Fortitude", "Great Hauberk", "'ElSolDolLo'", "Defense: 1596", ...]
}

🔧 Technical Architecture

Core Components

  • OCR Engine: Custom-trained Tesseract model optimized for D2R fonts
  • Fuzzy Matching: RapidFuzz-powered intelligent text matching with typo tolerance
  • Image Processing: OpenCV-based preprocessing for optimal OCR accuracy
  • Data Repository: Comprehensive JSON databases of all D2R items, affixes, and skills

Repository Files

The library includes extensive game data mappings:

  • affixes.json - All possible item modifiers and their templates
  • bases.json - Base item types with slots and tiers
  • uniques.json, set.json, runewords.json - Named item databases
  • magic.json, rares.json - Prefix/suffix combinations
  • skills.json, classes.json - Character abilities and class restrictions
  • requirements.json, stats.json - Item requirements and base statistics

Intelligent Parsing Features

  • Template Matching: Supports complex affix patterns like "+# to # [Skill] ([Class] Only)"
  • OCR Error Correction: Handles common misreads (0→O, 1→l, 5→S, etc.)
  • Context-Aware Classification: Distinguishes between item types using multiple signals
  • Fuzzy Thresholds: Configurable matching sensitivity for various game data types

📸 Image Requirements

For optimal results, captured tooltip images should:

  • Start with item name as the first line (crop out shop prices/vendor info)
  • Have clear, unobstructed text
  • Include the complete tooltip from name to last affix
  • Use game's default UI scaling when possible

See example tooltip images in the tests/tooltips/ directory.

🛠️ Advanced Usage

Custom OCR Configuration

from d2rlootreader.screen import capture_screen, preprocess
from d2rlootreader.item_parser import ItemParser
import pytesseract

# Capture and process with custom settings
image = capture_screen()
processed = preprocess(image, mode="adaptive")

# Extract text with custom OCR config
text = pytesseract.image_to_string(processed, lang="d2r", config="--psm 6")
lines = [line.strip() for line in text.splitlines() if line.strip()]

# Parse with debugging
parser = ItemParser(lines)
result = parser.parse_item_lines_to_json()

Interactive Region Selection

from d2rlootreader.region_selector import select_region

# Full-screen overlay for precise tooltip selection
selected_image = select_region()

Batch Processing

import glob
from pathlib import Path

# Process multiple tooltip images
for image_path in glob.glob("tooltips/*.png"):
    # Your processing logic here
    pass

⚠️ Current Limitations

This is an early-stage tool with known limitations:

  • Special Characters: Some Unicode symbols may not parse correctly
  • Font Variations: Works best with Large Font Mode enable in game settings
  • Supported languages: English language only

Contributions and bug reports are welcome to improve parsing accuracy.

🧪 Development

Setup Development Environment

git clone https://github.com/lucekdudek/d2r-loot-reader.git
cd d2r-loot-reader
pip install -e .[dev]

Code Quality Tools

# Format code
black .
isort .

# Run tests
pytest tests/

Testing with Sample Data

# Test with included tooltip samples
python -m pytest tests/test_item_parser.py -v

📝 Contributing

This project welcomes contributions from the D2R community:

  • Item Database Updates: Add missing items, affixes, or skills
  • OCR Improvements: Enhance text recognition accuracy
  • Parser Logic: Handle edge cases and special item types
  • Documentation: Improve guides and examples

📄 License

This project is licensed under the GPL-3.0-or-later license. See the LICENSE file for details.

Third-Party Components

This project includes the custom Tesseract training data from the "horadricapp" project by stephaistos, licensed under the MIT License. The component is located in third_party/horadricapp/ with full attribution and license details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

d2r_loot_reader-0.1.0.tar.gz (12.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

d2r_loot_reader-0.1.0-py3-none-any.whl (12.9 MB view details)

Uploaded Python 3

File details

Details for the file d2r_loot_reader-0.1.0.tar.gz.

File metadata

  • Download URL: d2r_loot_reader-0.1.0.tar.gz
  • Upload date:
  • Size: 12.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for d2r_loot_reader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9a6602e00c1474e3fd2a91b51aaeaf9394fab2ba46001d558393585cde04b0b7
MD5 2796b9113fa7963366c6ab95fe6fa12a
BLAKE2b-256 3b06b9aba5c3fd35f6634505c8624bd0033a4569ac02daf2edc26b3b6e817e57

See more details on using hashes here.

Provenance

The following attestation bundles were made for d2r_loot_reader-0.1.0.tar.gz:

Publisher: python-publish.yml on lucekdudek/d2r-loot-reader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file d2r_loot_reader-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for d2r_loot_reader-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3cac38d26a1a7bd79e2800576f7dd9bbd451053568e78c6d5bf6ce0556012256
MD5 7529b67b299cccfc6c7ff981b872b67d
BLAKE2b-256 b7420c6d152098778197b09b3aaa51aa2f33a816ec0e716bf6460b05762eaa49

See more details on using hashes here.

Provenance

The following attestation bundles were made for d2r_loot_reader-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on lucekdudek/d2r-loot-reader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page