From ce7136b8aa9687a266475a95c2fc746d38293a3f Mon Sep 17 00:00:00 2001 From: Tedy <53588129+TedyonGit@users.noreply.github.com> Date: Fri, 22 May 2026 15:44:45 +0300 Subject: [PATCH] Checking for python version for the open_binary and files calls --- UnityPy/helpers/Tpk.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/UnityPy/helpers/Tpk.py b/UnityPy/helpers/Tpk.py index 2f2f8965..c614ca02 100644 --- a/UnityPy/helpers/Tpk.py +++ b/UnityPy/helpers/Tpk.py @@ -1,7 +1,6 @@ from __future__ import annotations 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 @@ -18,8 +17,19 @@ def init(): - with open_binary("UnityPy.resources", "lzma.tpk") as f: - data = f.read() + try: + from importlib.resources import files + + def open_resource(package, resource): + return files(package).joinpath(resource).open("rb").read() + + except ImportError: + from importlib.resources import open_binary + + def open_resource(package, resource): + return open_binary(package, resource).read() + + data = open_resource("UnityPy.resources", "lzma.tpk") global TPKTYPETREE with BytesIO(data) as stream: