diff --git a/torappu/core/client.py b/torappu/core/client.py index 266d63e..bdc3d77 100644 --- a/torappu/core/client.py +++ b/torappu/core/client.py @@ -238,7 +238,7 @@ async def load_torappu_index(self): path = await self.fetch_asset_bundle_with_suffix("torappu_index") env = UnityPy.load(path) - torappu_index = env.container["dyn/torappu_index.asset"].read() + torappu_index = env.container["dyn/torappu_index.asset"].parse_as_object() if torappu_index and isinstance(torappu_index, MonoBehaviour): self.asset_to_bundle = { diff --git a/torappu/core/tasks/char_arts.py b/torappu/core/tasks/char_arts.py index bd70fe4..990752d 100644 --- a/torappu/core/tasks/char_arts.py +++ b/torappu/core/tasks/char_arts.py @@ -31,7 +31,7 @@ def unpack(self, env: UnityPy.Environment, unpacking_source: list[str]): if (behaviour := read_obj(MonoBehaviour, obj)) is None: continue - script = behaviour.m_Script.read() + script = behaviour.m_Script.deref_parse_as_object() if script.m_Name != "Image": continue @@ -48,18 +48,20 @@ def unpack(self, env: UnityPy.Environment, unpacking_source: list[str]): if rgb_texture_pptr.path_id == 0 or alpha_texture_pptr.path_id == 0: continue - rgb_texture: Texture2D = rgb_texture_pptr.read() - alpha_texture: Texture2D = alpha_texture_pptr.read() + rgb_texture: Texture2D = rgb_texture_pptr.deref_parse_as_object() + alpha_texture: Texture2D = alpha_texture_pptr.deref_parse_as_object() merged_image, _ = merge_alpha(alpha_texture, rgb_texture) merged_image.save(BASE_DIR.joinpath(f"{rgb_texture.m_Name}.png")) else: if not behaviour.m_Sprite: # type: ignore # No texture or sprite, skip continue - sprite = cast("PPtr[Sprite]", behaviour.m_Sprite).read() + sprite = cast( + "PPtr[Sprite]", behaviour.m_Sprite + ).deref_parse_as_object() if isinstance(behaviour, Sprite) is False: continue - rgb_texture = sprite.m_RD.texture.read() # type:ignore Type "UnityPy.classes.generated.Texture2D" is not assignable to declared type "UnityPy.classes.legacy_patch.Texture2D.Texture2D" + rgb_texture = sprite.m_RD.texture.deref_parse_as_object() # type:ignore rgb_texture.image.save(BASE_DIR.joinpath(f"{rgb_texture.m_Name}.png")) def check(self, diff_list: list[Diff]) -> bool: diff --git a/torappu/core/tasks/char_portrait.py b/torappu/core/tasks/char_portrait.py index 574767f..135e0c9 100644 --- a/torappu/core/tasks/char_portrait.py +++ b/torappu/core/tasks/char_portrait.py @@ -30,7 +30,7 @@ def unpack(self, env: UnityPy.Environment, unpacking_source: list[str]): continue # unpack atlas - texture = cast("Texture2D", sprite.m_RD.texture.read()) + texture = cast("Texture2D", sprite.m_RD.texture.deref_parse_as_object()) if texture: texture.image.save(ATLAS_DEST / f"{sprite.m_Name}.png") diff --git a/torappu/core/tasks/char_spine.py b/torappu/core/tasks/char_spine.py index 41c65ba..6310de6 100644 --- a/torappu/core/tasks/char_spine.py +++ b/torappu/core/tasks/char_spine.py @@ -35,7 +35,7 @@ class SpineConfig(BaseModel): def unpack_asset(data: MonoBehaviour, path: str) -> str: base_dir = STORAGE_DIR / "asset" / "raw" / "char_spine" / path - skel: TextAsset = data.skeletonJSON.read() # type: ignore + skel: TextAsset = data.skeletonJSON.deref_parse_as_object() # type: ignore skel_name: str = skel.m_Name.replace("#", "_") skel_dest_path = base_dir / skel_name @@ -53,15 +53,15 @@ def unpack_asset(data: MonoBehaviour, path: str) -> str: atlas_assets: list[PPtr] = data.atlasAssets # type: ignore for pptr in atlas_assets: - atlas_mono_behaviour: MonoBehaviour = pptr.read() - atlas: TextAsset = atlas_mono_behaviour.atlasFile.read() # type: ignore + atlas_mono_behaviour: MonoBehaviour = pptr.deref_parse_as_object() + atlas: TextAsset = atlas_mono_behaviour.atlasFile.deref_parse_as_object() # type: ignore # 文件名上不能有`#`,都替换成`_` atlas_content = re.sub(r"#([^.]*\.png)", r"_\1", atlas.m_Script) with open(base_dir / atlas.m_Name.replace("#", "_"), "w") as f: f.write(atlas_content) materials: list[PPtr] = atlas_mono_behaviour.materials # type: ignore for mat_pptr in materials: - mat: Material = mat_pptr.read() + mat: Material = mat_pptr.deref_parse_as_object() img, name = material2img(mat) img.save(base_dir / (name.replace("#", "_") + ".png")) @@ -212,7 +212,7 @@ def unpack(self, env: UnityPy.Environment, unpacking_source: list[str]): ) ) is None: break - data: MonoBehaviour = skeleton_data.read() + data: MonoBehaviour = skeleton_data.deref_parse_as_object() if data.m_Name.endswith("_SkeletonData"): if skel_name := unpack_asset(data, f"{name}/{skin}/{side}"): self.update_config(name, skin, side, skel_name) diff --git a/torappu/core/tasks/enemy_spine.py b/torappu/core/tasks/enemy_spine.py index 43948d1..f69e1b5 100644 --- a/torappu/core/tasks/enemy_spine.py +++ b/torappu/core/tasks/enemy_spine.py @@ -49,14 +49,17 @@ def unpack_ab(self, env: UnityPy.Environment, unpacking_source: str): def unpack(data: MonoBehaviour, path: str): dest_dir = STORAGE_DIR / "asset" / "raw" / "enemy_spine" / path dest_dir.mkdir(parents=True, exist_ok=True) - skel = cast("TextAsset", data.skeletonJSON.read()) # type: ignore + skel = cast("TextAsset", data.skeletonJSON.deref_parse_as_object()) # type: ignore skel_path = dest_dir.joinpath(skel.m_Name).with_suffix(".skel") skel_path.write_bytes(m_script_to_bytes(skel.m_Script)) atlas_assets = cast("list[PPtr[MonoBehaviour]]", data.atlasAssets) # type: ignore for pptr in atlas_assets: atlas_mono_behaviour = pptr.deref_parse_as_object() - atlas = cast("TextAsset", atlas_mono_behaviour.atlasFile.read()) # type: ignore + atlas = cast( + "TextAsset", + atlas_mono_behaviour.atlasFile.deref_parse_as_object(), # pyright: ignore[reportAttributeAccessIssue] + ) # type: ignore atlas_path = dest_dir.joinpath(atlas.m_Name).with_suffix(".atlas") atlas_path.write_bytes(m_script_to_bytes(atlas.m_Script)) @@ -84,14 +87,16 @@ def unpack(data: MonoBehaviour, path: str): lambda comp: comp.type.name == "MonoBehaviour", game_obj.m_Components, ): - skeleton_animation = cast("MonoBehaviour", comp.read()) + skeleton_animation = cast( + "MonoBehaviour", comp.deref_parse_as_object() + ) if ( skeleton_data := getattr( skeleton_animation, "skeletonDataAsset", None ) ) is None: continue - data: MonoBehaviour = skeleton_data.read() + data: MonoBehaviour = skeleton_data.deref_parse_as_object() if data.m_Name.endswith("_SkeletonData"): unpack(data, path) break diff --git a/torappu/core/tasks/gamedata.py b/torappu/core/tasks/gamedata.py index 22ab074..e5fff9d 100644 --- a/torappu/core/tasks/gamedata.py +++ b/torappu/core/tasks/gamedata.py @@ -293,7 +293,7 @@ async def unpack(self, ab_path: str): real_path = await self.client.fetch_asset_bundle(ab_path) env = UnityPy.load(real_path) for path, object in env.container.items(): - if isinstance((asset := object.read()), TextAsset): + if isinstance((asset := object.parse_as_object()), TextAsset): await self._unpack_gamedata(path, asset) async def start(self): diff --git a/torappu/core/tasks/uniequip_direction.py b/torappu/core/tasks/uniequip_direction.py index 0165b72..0a4af2f 100644 --- a/torappu/core/tasks/uniequip_direction.py +++ b/torappu/core/tasks/uniequip_direction.py @@ -34,7 +34,7 @@ async def unpack(self, ab_path: str): async def unpack_hub(self, ab_path: str): env = UnityPy.load(ab_path) for obj in filter(lambda obj: obj.type.name == "MonoBehaviour", env.objects): - behaviour = obj.read_typetree() # type: ignore + behaviour = obj.parse_as_dict() # type: ignore # values: Arts/UI/UniEquipDirection/spc-y # keys: spc-y self.hub_config = dict( diff --git a/torappu/core/tasks/utils.py b/torappu/core/tasks/utils.py index e42917d..54d9f5c 100644 --- a/torappu/core/tasks/utils.py +++ b/torappu/core/tasks/utils.py @@ -12,7 +12,7 @@ def read_obj[T](expected_klass: type[T], obj: ObjectReader[T]) -> T | None: if expected_klass == obj.get_class(): - return obj.read() + return obj.parse_as_object() else: return None @@ -66,11 +66,11 @@ def material2img(mat: Material): rgbtexture: Texture2D | None = None for key, tex in mat.m_SavedProperties.m_TexEnvs: if get_name(key) == "_AlphaTex" and tex.m_Texture: - texture = tex.m_Texture.read() + texture = tex.m_Texture.deref_parse_as_object() if isinstance(texture, Texture2D): atexture = texture if key == "_MainTex" and tex.m_Texture: - texture = tex.m_Texture.read() + texture = tex.m_Texture.deref_parse_as_object() if isinstance(texture, Texture2D): rgbtexture = texture @@ -81,7 +81,7 @@ def material2img(mat: Material): def build_container_path(env: Environment) -> dict[int, str]: container_map: dict[int, str] = {} for obj in filter(lambda obj: obj.type.name == "AssetBundle", env.objects): - typetree = obj.read_typetree() + typetree = obj.parse_as_dict() table = typetree["m_PreloadTable"] for path, info in typetree["m_Container"]: for i in range(