You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defget_texture_atlas(env):
forobjinenv.objects:
ifobj.type.name=="Texture2D":
tree=obj.read_typetree()
if (tree['m_Name'] =='sactx-0-8192x8192-BC7-GlobalAtlas-243fa2cc'):
returnobj.read()
returnNonedefimport_magnus_images(env):
atlas_data=get_texture_atlas(env)
atlas_img=atlas_data.imageinput_magnus=get_input_magnus()
print('Reading input files:')
print(input_magnus)
forobjinenv.objects:
ifobj.type.name=="Sprite":
tree=obj.read_typetree()
if((tree['m_Name'], obj.path_id) ininput_magnus):
print('Copying '+tree['m_Name'] +' '+str(obj.path_id))
# Read the texture atlas data from the bundlesprite_data=obj.read()
atlas=sprite_data.m_SpriteAtlas.read()
# Find the data for the sprite (in this case an individial magnus image) in the texture atlassprite_atlas_data=Noneforrender_datainatlas.m_RenderDataMap:
ifrender_data[0] ==sprite_data.m_RenderDataKey:
sprite_atlas_data=render_data[1]
breakifsprite_atlas_data==None:
print('Error: Could not find Sprite Atlas Data matching this magnu\'s Render Data Key')
continue#sprite_atlas_data = atlas.m_RenderDataMap[sprite_data.m_RenderDataKey]texture=sprite_atlas_data.texture.read()
texture_rect=sprite_atlas_data.textureRect# Get the coordinates in the texture atlas for the magnus we want to editcoords=get_atlas_coords(texture_rect, atlas_img.size)
# Read and paste the new image file that we want to insert into the texture atlasnew_img=read_img(create_img_name(tree['m_Name'], obj.path_id))
atlas_img.paste(new_img, coords)
# Save the change to the texture atlastexture.image=atlas_imgtexture.save()
save_env_to_bundle(env)
Error
File "C:\Users\jkayi\OneDrive\Documents\Baten Kaitos\mods\Baten Kaitos Modding Tools\BK1MagnusImgEditor\magnus_img_edit.py", line 101, in import_magnus_images
texture.image = atlas_img
^^^^^^^^^^^^^
File "C:\Users\jkayi\AppData\Local\Programs\Python\Python313\Lib\site-packages\UnityPy\classes\legacy_patch\Texture2D.py", line 29, in _Texture2d_set_image
img_data, tex_format = Texture2DConverter.image_to_texture2d(img, target_format, platform, self.m_PlatformBlob)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jkayi\AppData\Local\Programs\Python\Python313\Lib\site-packages\UnityPy\export\Texture2DConverter.py", line 223, in image_to_texture2d
enc_img = compress_func(img.tobytes("raw", "RGBA"), width, height, tex_format)
File "C:\Users\jkayi\AppData\Local\Programs\Python\Python313\Lib\site-packages\UnityPy\export\Texture2DConverter.py", line 94, in compress_etcpak
return etcpak.compress_bc7(data, width, height, None)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: params must be an instance of BC7CompressBlockParams
Bug
Trying to save a modified (or even unmodified, if I comment out that atlas_img.paste() line) PIL image to a Texture2D object results in this exception being thrown.
Activity
Cavydude commentedon Jul 8, 2025
Just replicated this on a much simpler script:
Let me know if you need a copy of that bundle file.
isHarryh commentedon Jul 8, 2025
Yes, a sample file is expected.
Cavydude commentedon Jul 8, 2025
Ok, GitHub isn't letting me upload .bundle files so here's a link to it.
isHarryh commentedon Jul 8, 2025
This is a bug of etcpak that UnityPy depends on.
In https://github.com/K0lb3/etcpak/blob/master/src/pylink.cpp#L91-L109 :
A possible fix is:
// compress bc7enc_compress_block_init(); - if (params == nullptr) + if (params == Py_None || params == nullptr) { bc7enc_compress_block_params bc7params; bc7enc_compress_block_params_init(&bc7params); CompressBc7(data, buf, width * height / 16, width, &bc7params); }@K0lb3
K0lb3 commentedon Jul 12, 2025
It's something I should fix in etcpak.
Thanks for investigating the issue.
isHarryh commentedon Aug 12, 2025
etcpak has updated to 0.9.15 and this issue was solved.
Shall we pin
etcpak>=0.9.15in UnityPy's dependency?UnityPy/pyproject.toml
Line 46 in a52f70d