nesrak1 / UABEA

c# uabe for newer versions of unity
MIT License
1.22k stars 153 forks source link

Is it possible to remove some assets and rebuild the assetbundle? #271

Closed BLKTower closed 1 year ago

BLKTower commented 1 year ago

Instead of replacing assets, is it possible to just remove some assets (guarantee no dependency issue), then rebuild the asset bundle? I tried to remove some assets and save, but the assetbundle asset in the assetbundle doesn't change. Also tried to edit the assetbundle asset's raw data and save, which causes the assetbundle corrupted.

BLKTower commented 1 year ago

Ok, seems I missed something when editing assetbundle asset's raw data. After fixing that, the rebuild assetbundle can be loaded in AssetStudio, and the removed assets are gone. However, the rebuild assetbundle size doesn't change. Shouldn't it get smaller since I removed assets?

nesrak1 commented 1 year ago

I tried to remove some assets and save, but the assetbundle asset in the assetbundle doesn't change

That's normal, UABEA doesn't edit that asset unless you explicitly edit it yourself.

However, the rebuild assetbundle size doesn't change. Shouldn't it get smaller since I removed assets?

It does get smaller. What you're probably seeing is the decompressed bundle size offsetting the size of the assets you removed.

BLKTower commented 1 year ago

Thanks for your reply.

It does get smaller. What you're probably seeing is the decompressed bundle size offsetting the size of the assets you removed.

Is there a way I can remove this offset?

nesrak1 commented 1 year ago

What I meant was that when you opened the file, it became decompressed (therefore, larger size.) You then removed some assets which made the size go down and be about the same as the compressed bundle. What you want to do is compress the bundle again so that it's smaller.

BLKTower commented 1 year ago

What I meant was that when you opened the file, it became decompressed (therefore, larger size.) You then removed some assets which made the size go down and be about the same as the compressed bundle. What you want to do is compress the bundle again so that it's smaller.

I've already tried, but it only decreases the size to the original compressed assetbundle size. See the original assetbundle is LZ4 compressed (Image 1/2, 320kb); after I load the bundle (decompressed), remove the assets and save, the new assetbundle is (Image 3/4, 612kb); then re-compress the new asset bundle with LZ4, still 320kb (Image 5/6).

image image image image image image

nesrak1 commented 1 year ago

AssetStudio is slightly misleading here. The size in the Texture2D includes the resS size which is never modified by UABEA (rebuilding this every time would be slow). In reality, by removing the other assets, you probably only save 700-800 bytes by removing the other two. The reason why the resulting bundle is bigger could be that Unity's LZ4 compression settings are higher than mine are set for.

BLKTower commented 1 year ago

Sorry, I don't quite get it, could you please explain more? That would be a great help. I know the size display in AssetStudio is misleading and confusing, so I'm not counting on it. But the file size on disk the OS telling me is that the size is not changed. This assetbundle only contains 2 images (bundle_centaurarcher and bundle_wolfhuntress, size of each image are very close), how could it only saves 700-800 bytes by removing one of the two? Shouldn't it reduce the size by nearly half?

nesrak1 commented 1 year ago

As I said before, the resS is not modified by UABEA and the resS probably contains the bulk of the data in the bundle. Feel free to click export raw on the Texture2Ds in UABEA and you can see their true asset size in a hex editor.

BLKTower commented 1 year ago

As I said before, the resS is not modified by UABEA and the resS probably contains the bulk of the data in the bundle. Feel free to click export raw on the Texture2Ds in UABEA and you can see their true asset size in a hex editor.

Oh ok, I got what you mean, thanks for your patient explanation. So there is no way to actually remove the asset data from resS file?

nesrak1 commented 1 year ago

Besides manual edits, UABEA (nor any other tool like UABE or UnityPy) have no way to automatically remove resS data and edit all Texture2Ds to point towards the new offsets.

BLKTower commented 1 year ago

Besides manual edits, UABEA (nor any other tool like UABE or UnityPy) have no way to automatically remove resS data and edit all Texture2Ds to point towards the new offsets.

Got it. Issue closed.