Skip to content

This Python script decompresses a base64-encoded and zlib-compressed SVG file. It reads the encoded data from a .txt file, decodes and decompresses it, and then saves the resulting XML content into a .json file.

License

Notifications You must be signed in to change notification settings

AxelBcr/PoB-SVG-Decompressor

Repository files navigation

SVG Decompressor

SVG Decompressor is a Python tool designed to decode, decompress, and parse SVG-encoded files generated by Path of Building (PoE2). It converts compressed SVG data into a structured JSON format, enabling further analysis and integration into other systems. Additionally, the project includes Lua scripts for processing node mappings and passive tree data with provided files.

Overview

  1. Decode and Decompress:

    • Reads a base64-encoded and zlib-compressed SVG string.
    • Applies different decompression strategies (with varying wbits parameters) for robustness.
  2. Parse XML:

    • Converts the decompressed SVG string into an XML structure.
  3. Data Extraction:

    • Extracts critical information including:

      • Player Info: Level, Class, and Ascendancy.
      • Player Stats: A set of key-value pairs.
      • Passive Skill Tree: Extracts node data from a comma-separated list.
      • Skills: Retrieves skills and details of socketed gems.
      • Items: Parses item details (name, type, rarity, level, quality, sockets, rune, and modifiers).
  4. Data Cleaning and Output:

    • Recursively removes None values from the data.
    • Saves the structured data into a JSON file (decompressed_build.json).
  5. Lua Integration:

    • Provides Lua scripts (NodeIndexMapping.lua and tree.lua) to further process or map passive tree node data.
    • Includes a function to extract node details from Lua-based node definitions.

Project Structure

PoB-SVG-Decompressor-main/
├── .gitignore                   # Git ignore file
├── Example/
│   ├── build.txt                # Example file with base64-encoded, compressed SVG data
│   └── structured_build.json    # Sample output JSON from the decompression process
├── LICENSE                      # MIT License file
├── NodeIndexMapping.lua         # Lua script for mapping passive tree node indices
├── README.md                    # This README file
├── svg_decompressor.py          # Main Python script handling decompression, parsing, and JSON output
└── tree.lua                     # Additional Lua script likely related to passive tree processing

Features

  • Robust Decoding & Decompression:
    Uses multiple wbits configurations (15, -15, and 31) to handle a variety of compressed data formats reliably.

  • Comprehensive XML Parsing:
    Extracts detailed game-related data:

    • Player Info: Automatically determines player level, class, and ascendancy from the XML.
    • Player Stats: Compiles player statistics into a dictionary.
    • Passive Skill Tree: Retrieves node IDs from a comma-separated string.
    • Skills and Gems: Captures skills along with the details of socketed gems (e.g., name, level, quality, and enabled status).
    • Items: Parses multi-line text to extract item attributes such as name, type, rarity, item level, quality, and other modifiers.
  • Data Cleaning:
    Implements a recursive function to remove None values from nested dictionaries and lists while preserving empty structures.

  • Lua Node Extraction:
    Includes functions to extract node definitions from Lua files. The Lua scripts help map node indices to skill names and associated stats, enabling enhanced processing of the passive tree.

Installation

  1. Prerequisites:
    Ensure you have Python 3 installed.

  2. Run the .exe
    Just download the svg_decompressor.exe

  3. Or Clone the Repository:

    git clone https://github.com/your-username/PoB-SVG-Decompressor.git
    cd PoB-SVG-Decompressor

Usage

  1. Prepare Your Data:
    Place your base64-encoded and compressed SVG data into a .txt file. An example (build.txt) is provided in the Example/ directory.

  2. Run the .exe file
    You will need the file path to your build.txt.

  3. Or Run the Decompression Script:

    python svg_decompressor.py
    • The script reads the SVG data, decompresses and decodes it, and then parses the XML structure.
    • It extracts player information, stats, passive tree data, skills (and gems), and items.
    • The final structured output is saved as structured_build.json.
  4. Lua Scripts:
    The Lua scripts (NodeIndexMapping.lua and tree.lua) are provided for additional processing.

Dependencies

This project uses only Python's built-in libraries:

  • base64
  • os
  • zlib
  • json
  • xml.etree.ElementTree
  • re

No third-party packages are required.

Code Details

  • Decoding & Decompression:
    The function decompress_svg(encoded) handles base64 decoding and attempts decompression using three different wbits values.

  • XML Data Extraction:
    Several helper functions are defined:

    • extract_player_info(xml_root)
    • extract_player_stats(xml_root)
    • extract_passive_tree(xml_root)
    • extract_skills(xml_root)
    • extract_items(xml_root)

    Each function targets specific sections of the XML to pull out game-related data.

  • Data Cleaning:
    The remove_nulls(d) function ensures that the final JSON output is free of None values.

  • Output:
    The structured data is saved as structured_build.json using the save_json(data, output_file) function.

  • Lua Node Extraction:
    The function extract_nodes_as_list(filename) in the Python script reads and processes Lua files to extract passive tree node definitions, utilizing regular expressions to parse node details.

License

This project is licensed under the MIT License – see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue to discuss major changes before submitting a pull request.

Contact

For questions, suggestions, or further information, please open an issue on GitHub or contact the creator:

Axel Bouchaud--Roche
GitHub Profile

About

This Python script decompresses a base64-encoded and zlib-compressed SVG file. It reads the encoded data from a .txt file, decodes and decompresses it, and then saves the resulting XML content into a .json file.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published