Skip to content

Bug for import image #4

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

Open
masagrator opened this issue Aug 3, 2022 · 2 comments
Open

Bug for import image #4

masagrator opened this issue Aug 3, 2022 · 2 comments

Comments

@masagrator
Copy link

masagrator commented Aug 3, 2022

When converting to CZ3, tool is using compressed size from source as some kind of limitation of how big 1 compressed image can be, which is not always correct. For Summer Pockets max size per each layer is 0xFEFD, and for some reason images converted by this tool with more than 1 layer are rendered as garbage by game except for first layer.

@masagrator masagrator changed the title Few bugs for import image Bug for import image Aug 3, 2022
@masagrator
Copy link
Author

masagrator commented Aug 11, 2022

Next issue - importing CZ1 is broken.
it doesn't output full header. After fixing header image is broken when converting it back to PNG.
example
of original file, just convert it to PNG and convert it back.
RB_TABLE_TENNIS_PAUSE.zip

If i see correctly, some informations are written as big endian instead of little endian, in indexes RGB (transparency is fine) is written too in wrong order.

@masagrator
Copy link
Author

masagrator commented Aug 14, 2022

Fixed the issue with CZ3 layers.

If there is more than one layer, uncompressed size of first layer is 1 byte too high, and of last layer 1 byte too low.

After fixing this all images are rendered correctly in Summer Pockets.
Using this simple Python script that is getting file path as first argument

import sys

file = open(sys.argv[1], "rb+")
if (file.read(4) != b"CZ3\x00"):
    print("Wrong FILE!")
    sys.exit()

header_size = int.from_bytes(file.read(4), byteorder="little")
file.seek(header_size-8, 1)
layer_count = int.from_bytes(file.read(4), byteorder="little")
if (layer_count == 1):
    print("File doesn't need correction!")
    sys.exit()
next_pointer = file.tell() + (8 * (layer_count-1))

file.seek(4, 1)
unc_size1 = int.from_bytes(file.read(4), byteorder="little", signed=False)
file.seek(-4, 1)
unc_size1 -= 1
file.write(unc_size1.to_bytes(4, "little", signed=False))

file.seek(next_pointer)
file.seek(4, 1)
unc_size2 = int.from_bytes(file.read(4), byteorder="little", signed=False)
file.seek(-4, 1)
unc_size2 += 1
file.write(unc_size2.to_bytes(4, "little", signed=False))

file.close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant