SeriousCache / UABE

Asset Bundle Extractor
3.62k stars 467 forks source link

Edited AssetBundle Wrong Build Version #230

Closed dastrdly6585 closed 5 years ago

dastrdly6585 commented 6 years ago

After uncompressing an asset bundle, I've tried exporting a text dump of a Monobehaviour, editing it, reimporting it, and then saving the edited bundle. Unfortunately, the game throws this error in its log file: "ERROR: The AssetBundle 'gamedatabase.unity3d' can't be loaded because it was not built with the right version or build target."

The version of the asset bundle produced by UABE after uncompression can be loaded fine by the game as long as no edits are made. In contrast, saving after simply reimporting an unedited version of the exported text dump of a Monobehaviour asset results in a bundle which the game can't load. Edited bundles can be opened fine by UABE and modifications that were made are correctly saved.

Is this a fixable issue with UABE where the edited bundle can be set to be "built" by the right version and with the right build target?

The Unity AssetBundle type is 2018.1.0f2. The game uses IL2CPP. The OS is Windows 10 x64. I am using UABE 2.2beta4.

As an addendum that may or may not be useful: each AssetBundle file for this game has an associated .manifest file. Each .manifest file has a CRC and two hashes (AssetFileHash & TypeTreeHash). I am unsure if the game actually does a checksum comparison using these files.

I can provide a link to the AssetBundle if you need a copy to troubleshoot this issue.

Edit: I found this forum post which indicates that if a game is compiled using IL2CPP (rather than .NET), its asset bundle is built using a different serialization. Perhaps this is the issue, since I'm not sure UABE currently accounts for this difference.

Edit 2: Since renaming the associated manifest file did not prevent the game from starting up with the original AssetBundle file, the game almost certainly does not make use of the manifest file in a checksum comparison. I also determined something else that might help: the game also has a resources.assets file that can have TextAssets replaced without problem with UABE. The AssetBundles which currently can't be edited correctly are under the subdirectory "StreamingAssets/ResourceBundles" of the game's data folder.

Edit 3: Here are screenshots of the first few bytes of the AssetBundle in question. It can be clearly seen that the Original version (unedited & uncompressed) is vastly different from the UABE saved version (unedited & uncompressed).

Original (unedited & compressed): gamedatabase_header_original

Original (unedited & uncompressed): gamedatabase_header_uncompressed

UABE Saved (unedited & uncompressed): gamedatabase_header_uabe-saved

DerPopo commented 5 years ago

Sorry for the late response. I'm looking into this and seemingly related issues ( #237 #239 ). It'd be great if you could give me a link to an affected file.

dastrdly6585 commented 5 years ago

Sure, here's the link to the bundle in question:

https://drive.google.com/open?id=1Sld8krPhbeZpBehOBiu0Bc5yoDdElVyS

If you'd prefer a file uploading website other than Google Drive, please let me know.

As a potential clue to point you towards the issue - the last version of the game which I was able to successfully mod was when the game used .NET code assemblies. After the game changed to IL2CPP, it became only possible to extract and not resave StreamingAssets asset bundles for modding. I have confirmed by downgrading the game to an earlier version that UABE edits to this older version's gamedatabase file work fine.

DerPopo commented 5 years ago

I suspect it's related to UABE not taking the preload list (inside the serialized CAB file) into account when saving the file, so the assets are stored in a different order.

There are a few other differences between the modified and the unmodified files, which I suspect are not the reason for the problem, since the only relevant change in the files from #237 is the asset order as mentioned above. The other differences are (i) the data block descriptors of the bundle (all those 10-byte entries of 02 00 00 00 02 ...), because the compressed file had lots of smaller compressed chunks to speed up random access in the file, (ii) the stream flags of the blocks which I also should take a look at for other reasons and (iii) the order of the bundle entries (which was not intended and will be fixed, but it still shouldn't invalidate the file).

On a related note, when I experimented with such small compressed chunks that also end/start in the middle of assets, the Unity Player randomly read corrupted data out of nowhere at some of these borders. Obviously, they have fixed that issue since they are now generating such bundles themselves.

DerPopo commented 5 years ago

Does it work with 2.2 stable?

dastrdly6585 commented 5 years ago

Just did a simple test modifying one MonoBehaviour asset and the saved asset bundle was successfully loaded by the game. Since that suggests the issue has been solved, I'll go ahead and close it. Thanks for your hard work on UABE!