Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to handle images with width or height that aren't multiples of 4 #286

Open
hostytoasty opened this issue Nov 23, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@hostytoasty
Copy link

hostytoasty commented Nov 23, 2024

I ran into this issue while trying to replace texture2d assets with modified versions of the same image. Obviously, this seems to be an etcpak error which I understand is a dependency issue. I just wanted to ask if I'm missing something obvious that would easily fix this, or if there's not much that can be done without fixing the dependency. Maintaining the image's dimension is key so resizing is not really great.

Code

        env = UnityPy.load(f)
        for obj in env.objects:
            if obj.type.name == 'Texture2D':
                data = obj.read()
                # getting file from somewhere
                texture_path = file.absolute()
                new_texture = Image.open(texture_path)
                # Fails at this line
                data.image = new_texture
                data.save()

Error

Traceback (most recent call last):
  File "...\asset_replace.py", line 63, in main
    data.image = new_texture
  File "Python\Python310\lib\site-packages\UnityPy\classes\legacy_patch\Texture2D.py", line 28, in _Texture2d_set_image
    img_data, tex_format = Texture2DConverter.image_to_texture2d(img, target_format)
  File "Python\Python310\lib\site-packages\UnityPy\export\Texture2DConverter.py", line 68, in image_to_texture2d
    enc_img = etcpak.compress_etc2_rgba(raw_img, img.width, img.height)
ValueError: width or height not multiple of 4

Bug
UnityPy unable to work with images of height or width that aren't multiples of 4

To Reproduce

  • Test Image is 506 x 434
  • following data:
    • Python 3.10
    • UnityPy 1.20.16
@hostytoasty hostytoasty added the bug Something isn't working label Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant