Skip to content

Commit

Permalink
don't rename ObjectReader (yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
K0lb3 committed Nov 27, 2024
1 parent e3b3475 commit 34a2b49
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
23 changes: 12 additions & 11 deletions UnityPy/files/File.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = []

Expand All @@ -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]:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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")


Expand Down Expand Up @@ -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)
12 changes: 10 additions & 2 deletions UnityPy/files/ObjectReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 34a2b49

Please sign in to comment.