UnityPy
UnityPy copied to clipboard
Saving files bigger than 4GB
Code
env = UnityPy.load(datafile)
for obj in env.objects:
if obj.type.name == "MonoBehaviour":
if not obj.serialized_type.nodes:
data = obj.read()
if data.name == "DataBaseCompiled":
data = obj.read()
with open(inputfile, "rb") as f:
data.save(raw_data = f.read())
with open("data.unity3d", "wb") as f:
f.write(env.file.save())
Error
Traceback (most recent call last):
File "replace_database.py", line 24, in <module>
unpack_monobehaviour(sys.argv[1], sys.argv[2])
File "replace_database.py", line 21, in unpack_monobehaviour
f.write(env.file.save())
^^^^^^^^^^^^^^^
File "/python3.11/site-packages/UnityPy/files/BundleFile.py", line 224, in save
self.save_fs(writer, 64, 64)
File "/python3.11/site-packages/UnityPy/files/BundleFile.py", line 325, in save_fs
block_writer.write_u_int(uncompressed_data_size)
File "/python3.11/site-packages/UnityPy/streams/EndianBinaryWriter.py", line 70, in write_u_int
self.write(pack(self.endian + "I", value))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: 'I' format requires 0 <= number <= 4294967295
Bug The file gets saved without an error.
To Reproduce I think the problem is saving a unity3d file that is uncompressed bigger than 4GB, considering the file size overflows?
If I print the size, it is 0x21b5da210.
- Python 3.11
- UnityPy 1.10.7
I cannot upload the file for copyright reasons, however it is from the game "Broken Arrow" https://store.steampowered.com/app/1604270/Broken_Arrow/
A possible fix for this is pretty straight forward - replicating what Unity does, splitting the data into blocks and compressing these. As this would require some testing I'm not sure when I will come around to implementing it tho.