fix Switch texture deswizzling · SNWCreations/UnityPy@fa26e22 · GitHub
Skip to content

Commit fa26e22

Browse files
committed
fix Switch texture deswizzling
1 parent edd1df4 commit fa26e22

6 files changed

Lines changed: 123 additions & 276 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions

‎UnityPy/export/Texture2DConverter.py‎

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,17 @@ def parse_image_data(
150150
f"Not implemented texture format: {texture_format.name}"
151151
)
152152

153-
if texture_format in XBOX_SWAP_FORMATS:
154-
image_data = swap_bytes_for_xbox(image_data, platform)
153+
if platform == BuildTarget.XBOX360 and texture_format in XBOX_SWAP_FORMATS:
154+
image_data = swap_bytes_for_xbox(image_data)
155+
elif platform == BuildTarget.Switch and platform_blob is not None:
156+
gobsPerBlock = TextureSwizzler.get_switch_gobs_per_block(platform_blob)
157+
block_size = TextureSwizzler.TEXTUREFORMAT_BLOCK_SIZE_MAP[texture_format]
158+
padded_size = TextureSwizzler.get_padded_texture_size(
159+
width, height, *block_size, gobsPerBlock
160+
)
161+
image_data = TextureSwizzler.deswizzle(
162+
image_data, *padded_size, *block_size, gobsPerBlock
163+
)
155164

156165
if not isinstance(texture_format, TextureFormat):
157166
texture_format = TextureFormat(texture_format)
@@ -169,33 +178,18 @@ def parse_image_data(
169178

170179
img = selection[0](image_data, width, height, *selection[1:])
171180

172-
if platform == BuildTarget.Switch and platform_blob is not None:
173-
gobsPerBlock = TextureSwizzler.get_switch_gobs_per_block(platform_blob)
174-
blockSize = TextureSwizzler.TEXTUREFORMAT_BLOCK_SIZE_MAP[texture_format]
175-
img = TextureSwizzler.switch_deswizzle(img, blockSize, gobsPerBlock)
176-
177181
if img and flip:
178182
return img.transpose(Image.FLIP_TOP_BOTTOM)
179183

180184
return img
181185

182186

183-
def swap_bytes_for_xbox(image_data: bytes, build_target: BuildTarget) -> bytes:
187+
def swap_bytes_for_xbox(image_data: bytes) -> bytes:
184188
"""swaps the texture bytes
185189
This is required for textures deployed on XBOX360.
186-
187-
:param image_data: texture data
188-
:type image_data: bytes
189-
:param build_target: platform of the asset
190-
:type build_target: BuildTarget
191-
:return: swapped data if platform = XBOX360 else data
192-
:rtype: bytes
193190
"""
194-
if (
195-
build_target == BuildTarget.XBOX360
196-
): # swap bytes for Xbox confirmed,PS3 not encountered
197-
for i in range(0, len(image_data), 2):
198-
image_data[i : i + 2] = image_data[i : i + 2][::-1]
191+
for i in range(0, len(image_data), 2):
192+
image_data[i : i + 2] = image_data[i : i + 2][::-1]
199193
return image_data
200194

201195

‎UnityPy/helpers/TextureSwizzler.py‎

Lines changed: 108 additions & 150 deletions

0 commit comments

Comments
 (0)