nesrak1 / UABEA

c# uabe for newer versions of unity
MIT License
1.1k stars 143 forks source link

WebGL Unity 5.4.0f2 unable to properly recompress/repack data file #223

Closed Shaggythecat closed 1 year ago

Shaggythecat commented 1 year ago

I'm trying to modify a WebGL game's assets to change some text displayed. I have been able to unpack the game's assets and modify them but when the the data file is repacked and compressed it ends up being about 4mb smaller than the original and it doesn't work with the game. webgl.data.zip This is the unmodified file. Any help would be appreciated. Thanks!

nesrak1 commented 1 year ago

when the the data file is repacked and compressed it ends up being about 4mb smaller than the original

This is just the compression settings for UABEA being higher than the ones for Unity. That doesn't mean data magically disappeared or anything.

and it doesn't work with the game.

You should try changing the file bit by bit until it breaks to see where the real issue is. If you just recompress the file as is, does it break? Does changing the asset without compression break? Does reimporting the text without changing break? Etc. Also, I don't know if WebGL prints to the console or not, but if it does you might want to check it for other errors as well.

Shaggythecat commented 1 year ago

If you just recompress the file as is, does it break?

Yes, decompressing and recompressing the file as is without any changes will cause it to no longer work. recompressed webgl no changes.zip

Also, I don't know if WebGL prints to the console or not, but if it does you might want to check it for other errors as well.

This is the error it will give with that file. I did remove the site info from it.

Uncaught Assertion failed: s_GlobalMetadataHeader->sanity == 0xFAB11BAF, at: C:\Program Files\Unity\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp,154,Initialize at Error
    at jsStackTrace
    at stackTrace 
    at ___assert_fail
    at gdm
    at Ahm
    at Pfm 
    at RJa 
    at Svb 
    at Object.callMain 
    at doRun
nesrak1 commented 1 year ago

That error seems to be referring to global-metadata which is not stored in bundles. Still, what if you use the bundle decompressed without recompressing it? Also, does the original UABE work when compressing it? I'm trying to make sure this isn't a problem with your method of getting the new bundle into the game.

Shaggythecat commented 1 year ago

Still, what if you use the bundle decompressed without recompressing it?

I'm getting the same error when using it uncompressed.

Also, does the original UABE work when compressing it?

Nope, making any modification to webgl.data seems to break the game.

nesrak1 commented 1 year ago

Then that would appear to be something wrong with how you're putting the file back into the game. I don't know specifically how it works for older games like 5.4, but usually there is a unityweb file (iirc) you need to unpack and repack to. It's possible that you're not doing that part correctly because just uncompressing the bundle still appears to make a valid bundle. On top of that, your error message is about something completely unrelated. I'm pretty sure this is not a problem here with UABEA.

Shaggythecat commented 1 year ago

usually there is a unityweb file

This game does not contain a unityweb file. Instead it consists of 4 files, UnityLoader.js webgl.js webgl.mem and webgl.data.

your error message is about something completely unrelated.

I think it could be related because there is some metadata check for the webgl.data file at a specific offset. So when the file is uncompressed/recompressed the metadata offset is changed or is lost entirely. I did find one comment from a unity dev related to the issue I'm having.

Issues related to the s_GlobalMetadataHeader->sanity normally occur when you have .data and UnityLoader.js coming from different versions (means the metadata is just being read from a wrong offset, which is taken from the mismatching loader). This normally happens when .js and .data files have different lifetime in the intermediate cache. So, when you update the build in the same server folder, you might end up with the old .js file and the new .data file returned from the server.

Do you think there is a program or if it's possible to replace the .assets file I'm trying to change in webgl.data without modifying the rest of the the file?

nesrak1 commented 1 year ago

I took a second look and it's true that there are other files bundled together in this file, including the global-metadata. I don't know much about the format of webgl games like this, but I'm guessing the pointers to the files in this file are somewhere else, either in the js file or the mem file you were referring to since I don't see any header or any kind of thing that points to global-metadata.dat at all. Anyways, it's a bit out of scope for UABEA at the moment since this is a totally different format outside of bundles. But hopefully you can figure it out.

Shaggythecat commented 1 year ago

there are other files bundled together in this file, including the global-metadata.

Is it possible to pull those files out of webgl.data? I'm not sure how to get those files out of the bundle myself. If you can't no worries.

Either way, Thank you for trying to help, I really appreciate it. :) Sorry if this issue was beyond the scope of the project.

nesrak1 commented 1 year ago

Sorry, I don't know this format so you're on your own for this one.