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
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.
The text was updated successfully, but these errors were encountered:
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.
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.
The text was updated successfully, but these errors were encountered: