From 34a2b496ad76901f087de3e23480726fb9e6584b Mon Sep 17 00:00:00 2001 From: Rudolf Kolbe Date: Wed, 27 Nov 2024 14:42:59 +0100 Subject: [PATCH] don't rename ObjectReader (yet) --- UnityPy/files/File.py | 23 ++++++++++++----------- UnityPy/files/ObjectReader.py | 12 ++++++++++-- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/UnityPy/files/File.py b/UnityPy/files/File.py index be804a35..213b5d04 100644 --- a/UnityPy/files/File.py +++ b/UnityPy/files/File.py @@ -20,7 +20,8 @@ from ..streams import EndianBinaryReader, EndianBinaryWriter if TYPE_CHECKING: - from .ObjectInfo import ObjectInfo + from ..classes import Object, PPtr + from .ObjectReader import ObjectReader PARSEABLE_FILETYPES: List[Type[File]] = [] @@ -37,7 +38,7 @@ def parseable_filetype(cls: Type[T]) -> Type[T]: def parse_file( reader: EndianBinaryReader, name: str, - path: str, + path: Optional[str] = None, parent: Optional[ContainerFile] = None, is_dependency: bool = False, ) -> Optional[File]: @@ -72,7 +73,7 @@ def __init__( reader: Optional[EndianBinaryReader] = None, ): self.name = name - self.path = path + self.path = path or name self.parent = parent self.is_dependency = is_dependency self.reader = reader @@ -115,7 +116,7 @@ def __exit__(self): pass @abstractmethod - def get_objects(self) -> List[ObjectInfo[Any]]: + def get_objects(self) -> List[ObjectReader[Any]]: """Get all objects contained in this file and its childs. Returns: @@ -124,7 +125,7 @@ def get_objects(self) -> List[ObjectInfo[Any]]: pass @abstractmethod - def get_containers(self) -> Dict[str, List[ObjectInfo[Any]]]: + def get_containers(self) -> Dict[str, List[PPtr[Object]]]: """Get all containers contained in this file and its childs. Returns: @@ -160,10 +161,10 @@ def dump(self, writer: Optional[EndianBinaryWriter] = None) -> EndianBinaryWrite writer.write_bytes(self.reader.get_bytes()) return writer - def get_objects(self) -> List[ObjectInfo[Any]]: + def get_objects(self) -> List[ObjectReader[Any]]: raise ValueError("ResourceFile does not contain objects") - def get_containers(self) -> Dict[str, List[ObjectInfo[Any]]]: + def get_containers(self) -> Dict[str, List[ObjectReader[Any]]]: raise ValueError("ResourceFile does not contain containers") @@ -234,13 +235,13 @@ def traverse(self) -> Iterator[File]: continue yield child - def get_objects(self) -> List[ObjectInfo[Any]]: + def get_objects(self) -> List[ObjectReader[Any]]: return [obj for child in self.traverse() for obj in child.get_objects()] - def get_containers(self) -> Dict[str, List[ObjectInfo[Any]]]: - containers: Dict[str, List[ObjectInfo[Any]]] = defaultdict(list) + def get_containers(self) -> Dict[str, List[ObjectReader[Any]]]: + containers: Dict[str, List[ObjectReader[Any]]] = defaultdict(list) for child in self.traverse(): for container_path, obj in child.get_containers().items(): containers[container_path].extend(obj) - return cast(Dict[str, List[ObjectInfo[Any]]], containers) + return cast(Dict[str, List[ObjectReader[Any]]], containers) diff --git a/UnityPy/files/ObjectReader.py b/UnityPy/files/ObjectReader.py index 4b9f7d62..87e8a542 100644 --- a/UnityPy/files/ObjectReader.py +++ b/UnityPy/files/ObjectReader.py @@ -11,7 +11,12 @@ if TYPE_CHECKING: from ..enums import BuildTarget - from ..files.SerializedFile import BuildType, SerializedFile, SerializedType + from ..files.SerializedFile import ( + BuildType, + SerializedFile, + SerializedFileHeader, + SerializedType, + ) T = TypeVar("T") @@ -103,7 +108,10 @@ def __init__(self, assets_file: SerializedFile, reader: EndianBinaryReader): self.stripped = reader.read_byte() def write( - self, header, writer: EndianBinaryWriter, data_writer: EndianBinaryWriter + self, + header: SerializedFileHeader, + writer: EndianBinaryWriter, + data_writer: EndianBinaryWriter, ): if self.assets_file.big_id_enabled: writer.write_long(self.path_id)