Skip to main content

Python copy of AddressablesTools

Project description

AddressablesToolsPy

Python copy of AddressablesTools

Only reading is implemented

Usage

pip install addressablestools
from pathlib import Path
from AddressablesTools import parse


def main():
    data = Path("tests/samples/catalog.json").read_text("utf-8")
    catalog = parse(data)
    for key, locs in catalog.Resources.items():
        if not isinstance(key, str):
            continue
        if not key.endswith(".bundle"):
            continue
        res_loc = locs[0]
        print(
            f"Bundle {key}, Crc: {res_loc.Data.Object.Crc}, Hash: {res_loc.Data.Object.Hash}"
        )

    print("-" * 50)

    asset_locs = catalog.Resources[
        "Assets/Paripari/AddressableAssets/VFX Texture Assets/ParticleTextures/sparkle.png"
    ]
    dep_key = asset_locs[0].DependencyKey
    print(f"Dependency of {asset_locs[0].PrimaryKey}: {dep_key}")
    dep_bundle = catalog.Resources[dep_key][0]
    print(f"ProviderId of {dep_bundle.PrimaryKey}: {dep_bundle.ProviderId}")
    print(f"InternalId of {dep_bundle.PrimaryKey}: {dep_bundle.InternalId}")


if __name__ == "__main__":
    main()

Custom object parsing

This is just used for binary reading.

There may be some custom assemblies and classes uesd to load AssetBundles.

In gerneral, tool will not be able to parse these objects and raise an error.

For example, if you encounter an error like:

Unsupported object type: 0; System.String

You can provide a patcher and a handler (optional) to try to parse the custom object type.

Patcher and Handler

A patcher is a function that takes a matchName: str and returns a new matchName or None which is used to decide how the object should be parsed.

There is a default patcher that returns the original matchName.

A handler is a function that takes 3 arguments: reader: CatalogBinaryReader, objectOffset: int, and isDefault: bool and returns Any (the parsed object).

When the patcher returns None, your custom handler will be used.

Followings are some examples:

from pathlib import Path
import AddressablesTools
from AddressablesTools.classes import SerializedObjectDecoder


def patcher(matchName: str) -> str:
    # just try to parse custom AssetBundleRequestOptions in default way
    if matchName == "GeePlus.GPUL.AddressablesManager; GeePlus.GPUL.AddressablesManager.ResourceProviders.EncryptedAssetBundleRequestOptions" # custom AssetBundleRequestOptions class
        return SerializedObjectDecoder.ABRO_MATCHNAME # default matchName for AssetBundleRequestOptions
    return matchName

data = Path("catalog.bin").read_bytes()

catalog = AddressablesTools.parse_binary(data, patcher=patcher)
from typing import Any
from pathlib import Path
import AddressablesTools
from AddressablesTools.classes import CatalogBinaryReader


def patcher(matchName: str) -> str:
    if matchName == "Custom; System.Int32"
        return None
    return matchName

def handler(reader: CatalogBinaryReader, offset: int, is_default: bool) -> Any:
    if is_default:
        return 0
    reader.seek(offset)
    return reader.read_int32()

data = Path("catalog.bin").read_bytes()

catalog = AddressablesTools.parse_binary(data, patcher=patcher, handler=handler)

I havn't tested the above code, it may not work.

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

addressablestools-0.1.6.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

addressablestools-0.1.6-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file addressablestools-0.1.6.tar.gz.

File metadata

  • Download URL: addressablestools-0.1.6.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for addressablestools-0.1.6.tar.gz
Algorithm Hash digest
SHA256 376ed2b266ec67dc72049bb9f778c879ef8fba960a111c8c1666c5497a4d82f4
MD5 383f8000e3b9c5f0884c0d639f90041f
BLAKE2b-256 07bd816f28c8eb865dd63cb06afb16bc0cf21eab9c4c91b508ba7bdc9cbc4392

See more details on using hashes here.

File details

Details for the file addressablestools-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for addressablestools-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 dbfa26092a647f36ef55791c4726046b527aff12e43dc89f5f3a8d81a6f43e85
MD5 186b5b9bc71f9481e10baee0f71f7d9b
BLAKE2b-256 210878afa538a871b0e7261214d5afb22c86500db8100a31755849be0202e350

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