Skip to content

Commit ee8643e

Browse files
committed
SerializedFile - ContainerHelper typing fix and if no assetbundle
1 parent e544bf3 commit ee8643e

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

‎UnityPy/files/SerializedFile.py‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from . import BundleFile, File, ObjectReader
1414

1515
if TYPE_CHECKING:
16-
from ..classes import AssetBundle, AssetInfo, Object
16+
from ..classes import AssetBundle, AssetInfo, Object, PPtr
1717
from ..files import ObjectReader
1818
from ..streams.EndianBinaryReader import EndianBinaryReader
1919

@@ -331,7 +331,7 @@ def __init__(self, reader: EndianBinaryReader, parent=None, name=None, **kwargs)
331331
break
332332
else:
333333
self.assetbundle = None
334-
self._container = ContainerHelper({})
334+
self._container = ContainerHelper()
335335

336336
@property
337337
def container(self):
@@ -517,26 +517,29 @@ class ContainerHelper:
517517
"""Helper class to allow multidict containers
518518
without breaking compatibility with old versions"""
519519

520-
container: Tuple[str, AssetInfo]
521-
container_dict: Dict[str, ObjectReader]
520+
container: List[Tuple[str, AssetInfo]]
521+
container_dict: Dict[str, PPtr[Object]]
522522
path_dict: Dict[int, str]
523523

524-
def __init__(self, assetbundle: AssetBundle) -> None:
525-
self.container = assetbundle.m_Container
524+
def __init__(self, assetbundle: Optional[AssetBundle] = None) -> None:
525+
if assetbundle is None:
526+
self.container = []
527+
else:
528+
self.container = assetbundle.m_Container
526529
# support for getitem
527530
self.container_dict = {key: value.asset for key, value in self.container}
528531
self.path_dict = {value.asset.m_PathID: key for key, value in self.container}
529532

530-
def items(self) -> Generator[Tuple[str, ObjectReader], None, None]:
533+
def items(self) -> Generator[Tuple[str, PPtr[Object]], None, None]:
531534
return ((key, value.asset) for key, value in self.container)
532535

533536
def keys(self) -> list[str]:
534537
return list({key for key, value in self.container})
535538

536-
def values(self) -> list[ObjectReader]:
539+
def values(self) -> list[PPtr[Object]]:
537540
return list({value.asset for key, value in self.container})
538541

539-
def __getitem__(self, key) -> ObjectReader:
542+
def __getitem__(self, key) -> PPtr[Object]:
540543
return self.container_dict[key]
541544

542545
def __setitem__(self, key, value) -> None:
@@ -551,7 +554,7 @@ def __iter__(self) -> Generator[str, None, None]:
551554
def __len__(self) -> int:
552555
return len(self.container)
553556

554-
def __getattr__(self, name: str) -> ObjectReader:
557+
def __getattr__(self, name: str) -> PPtr[Object]:
555558
return self.container_dict[name]
556559

557560
def __or__(self, other: ContainerHelper):
@@ -560,5 +563,5 @@ def __or__(self, other: ContainerHelper):
560563
def __str__(self) -> str:
561564
return f'{{{", ".join(f"{key}: {value}" for key, value in self.items())}}}'
562565

563-
def __dict__(self) -> Dict[str, ObjectReader]:
566+
def __dict__(self) -> Dict[str, PPtr[Object]]:
564567
return self.container_dict

0 commit comments

Comments
 (0)