Skip to main content

Decoding of Heroes Might of Magic III files

Project description

homm3data

Decoding of Heroes Might of Magic III files

Installation

Library can be installed with PIP: pip install homm3data

Examples

Saving all frames from def file as png files:

from homm3data import deffile

with deffile.open('path/to/deffile.def') as d:
    for group in d.get_groups():
        for frame in range(d.get_frame_count(group)):
            img = d.read_image('combined', group, frame)
            img.save('path/to/image_group%d_frame%d.png' % (group, frame))

Extracting image from pcx inside lod file:

from homm3data import pcxfile, lodfile

with lodfile.open('path/to/h3bitmap.lod') as lod:
    data = lod.get_file("aishield.pcx")
    if pcxfile.is_pcx(data):
        pcxfile.read_pcx(data).save('path/to/image.png')

Extracting image from pak file (Heroes III HD):

from homm3data import pakfile

with pakfile.open("path/to/sprite_DXT_com_x3.pak") as pak:
    img = pak.get_image("AVWIMPX0", "AVWIMPX1")
    img.save('path/to/image.png')

Extracting text from H3 demo:

import urllib.request
import tarfile
from io import BytesIO
from homm3data import lodfile

url = "http://updates.lokigames.com/loki_demos/heroes3-demo.run"
contents = urllib.request.urlopen(url).read()
data = contents.split(b"END_OF_STUB\n", 1)[1]
with tarfile.open(fileobj=BytesIO(data), mode="r:gz") as tar:
    with lodfile.open(tar.extractfile("data/demos/heroes3_demo/data/h3bitmap.lod")) as lod:
        data = lod.get_file("GENRLTXT.TXT")
        print(data.decode())

Tests

The tests needs innoextract installed on system (may needs to be inside PATH variable).

API

The API for the library is described here.

License

Library is released under MIT license.

Some parts of code are based on lodextract from josch. Originally published under GPL. Josch kindly gave me permission (via e-mail) to use the code under MIT as well. Thanks a lot!

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

homm3data-0.1.9.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

homm3data-0.1.9-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file homm3data-0.1.9.tar.gz.

File metadata

  • Download URL: homm3data-0.1.9.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for homm3data-0.1.9.tar.gz
Algorithm Hash digest
SHA256 aafa165504fe09c246fe0e44fd5abd6fd12643636edcd057d95701cb0135b6d8
MD5 914afa3c7a6348761d94cc2220bdab62
BLAKE2b-256 8c6ce12390cb2a7ceb6a82187dee51b2119cf94110b30b016aed3ec35ebf07ce

See more details on using hashes here.

File details

Details for the file homm3data-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: homm3data-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for homm3data-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 11c6e2328aec2fe768f0f3a81c44cc473e75dbe0aa3e6d5d1eeccbf3d5df61a9
MD5 1137f16a78ef3c5a37e75c7bd245e6c9
BLAKE2b-256 e7edfb5e21112c78efb22316b22ef09da4a202373fb19f9b370b653a3c8eb9e1

See more details on using hashes here.

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