Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion torappu/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
12 changes: 7 additions & 5 deletions torappu/core/tasks/char_arts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion torappu/core/tasks/char_portrait.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
10 changes: 5 additions & 5 deletions torappu/core/tasks/char_spine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"))

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions torappu/core/tasks/enemy_spine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion torappu/core/tasks/gamedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion torappu/core/tasks/uniequip_direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions torappu/core/tasks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand All @@ -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(
Expand Down