Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions UnityPy/helpers/Tpk.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import sys
from enum import IntEnum, IntFlag
from importlib.resources import open_binary
from io import BytesIO
from struct import Struct
from typing import Any, Dict, List, Optional, Tuple, TypeVar
Expand All @@ -18,11 +18,22 @@


def init():
with open_binary("UnityPy.resources", "lzma.tpk") as f:
data = f.read()
package = "UnityPy.resources"
resource = "lzma.tpk"

tpk_data: bytes
if sys.version_info >= (3, 9):
from importlib.resources import files

tpk_data = files(package).joinpath(resource).read_bytes()

else:
from importlib.resources import open_binary

tpk_data = open_binary(package, resource).read()

global TPKTYPETREE
with BytesIO(data) as stream:
with BytesIO(tpk_data) as stream:
blob = TpkFile(stream).GetDataBlob()
assert isinstance(blob, TpkTypeTreeBlob)
TPKTYPETREE = blob
Expand Down
Loading