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

ValueError: This cab already exists and isn't an EndianBinaryWriter #49

Closed
Thuya1980 opened this issue May 30, 2021 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@Thuya1980
Copy link

Code
from PIL import Image
import io
import UnityPy

all of the following would work

src = "D:\ZTA\Test2\UI_FirstLoading.unity3d"

env = UnityPy.load(src)
print(env)

for obj in env.objects:
if obj.type in ["Texture2D"]:
# export texture
data = obj.read()
if data.name == "Atlas_Menu02":
data.image.save(data.name+"_bak.png")
# edit texture
with Image.open("Atlas_Menu02.png") as pi_img:
data.image = pi_img
data.save()

with open("UI_FirstLoading_REPLACE.unity3d", "wb") as f:
f.write(env.file.save())

Error
Traceback (most recent call last):
File "C:\Users\Thuya\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "C:\Users\Thuya\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "c:\Users\Thuya.vscode\extensions\ms-python.python-2021.2.633441544\pythonFiles\lib\python\debugpy_main
.py", line 45, in
cli.main()
File "c:\Users\Thuya.vscode\extensions\ms-python.python-2021.2.633441544\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\Thuya.vscode\extensions\ms-python.python-2021.2.633441544\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("main"))
File "C:\Users\Thuya\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\Thuya\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\Thuya\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "d:\ZTA\Test2\Edit.py", line 20, in
data.image = pi_img
File "C:\Users\Thuya\AppData\Local\Programs\Python\Python36\lib\site-packages\UnityPy\classes\Texture2D.py", line 21, in image
self.image_data = img_data
File "C:\Users\Thuya\AppData\Local\Programs\Python\Python36\lib\site-packages\UnityPy\classes\Texture2D.py", line 35, in image_data
cab = self.assets_file.get_writeable_cab()
File "C:\Users\Thuya\AppData\Local\Programs\Python\Python36\lib\site-packages\UnityPy\files\SerializedFile.py", line 378, in get_writeable_cab
cab = self.parent.get_writeable_cab(name)
File "C:\Users\Thuya\AppData\Local\Programs\Python\Python36\lib\site-packages\UnityPy\files\File.py", line 81, in get_writeable_cab
"This cab already exists and isn't an EndianBinaryWriter")
ValueError: This cab already exists and isn't an EndianBinaryWriter

Bug
First time it's ok!
But second time it come with that error.

@Thuya1980 Thuya1980 added the bug Something isn't working label May 30, 2021
@K0lb3
Copy link
Owner

K0lb3 commented May 31, 2021

The error shows up when one tries to edit a Unity file that was already edited once before.
I strongly advice against doing so, as UnityPy doesn't clean up the external file data,
doing all modifications at once on the original file is the way to go, for now.

@Thuya1980
Copy link
Author

Thanks.

@K0lb3 K0lb3 closed this as completed Jul 8, 2021
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

2 participants