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.7.tar.gz (15.8 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.7-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for addressablestools-0.1.7.tar.gz
Algorithm Hash digest
SHA256 cb4cb27b1718dfe544171fa55e0447d204644da9938b0faa1dbfdc801eeacdf5
MD5 8292ad5a39cc81e2a650ea32f7be9791
BLAKE2b-256 7bfafd86774aed9c819b60aa0a688d52637c3f65594e9578096aebb31148125f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for addressablestools-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 41da2aecea5f076a8d68126fe13e4f04bade5a3379b17e81e36490d959606d0b
MD5 31efb8caf0093de89ab7faebe86d9fea
BLAKE2b-256 9a356fbdd42c19acfea19a85605ada5c513621e9a62be8c42bb83be0083a9f81

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