HearthSim / UnityPack

Python deserialization library for Unity3D Asset format
https://hearthsim.info/
MIT License
720 stars 153 forks source link

Processing RGBA4444 #68

Open moesoha opened 6 years ago

moesoha commented 6 years ago

I met a problem when i'm unpacking textures formatted with RGBA4444. The unpacked images have a color problem obviously.

When I swapping the color channels from RGBA to ABGR, the problem solved.

snipaste_2018-02-02_13-56-41

I don't know the definition of RGBA4444. I don't know the swapping channel just appears in the game I unpacked or Unity defines it in this way. So I prefer to open an issue rather than open a pr.

I fix the problem in my fork moesoha/UnityPack:fix-rgba4444.

jleclanche commented 6 years ago

Thanks for the heads up.

@andburn or @Mischanix might correct me on this but I think there's a couple of RGBA4444 textures in Hearthstone which work the way it's implemented right now. Would have to compare to see...

Which game did you try? Can you link the raw texture binary somehow?

moesoha commented 6 years ago

The game is a hot RPG game in China. It's Chinese name is “恋与制作人”, and it has no English name.

The Android package name is com.papegames.evol.

And here is the Unity Asset file i used above. 10050.zip

jleclanche commented 6 years ago

@moesoha What's the texture name/address in question?

moesoha commented 6 years ago

@jleclanche Just 10050, assets/i6/icon_s/10050.png in apk file.

UlyssesWu commented 6 years ago

It's about big endian and little endian. Apparently here it uses little endian so the RGBA became ABGR.

moesoha commented 6 years ago

@UlyssesWu Oops, seems right. But how to judge which endian it is? This should be a property in the bundle.

UlyssesWu commented 6 years ago

I don't really know about Unity's implementation. In my case (Kirikiri PSB / FreeMote), you can only identify big/little endian by platform - in a Windows game, RGBA8 uses little endian; while in a WebGL game, the same description RGBA8 uses big endian instead.

moesoha commented 6 years ago

@UlyssesWu That's really annoying... Do you have any big endian bundle files?

UlyssesWu commented 6 years ago

I think there's a couple of RGBA4444 textures in Hearthstone which work the way it's implemented right now. Would have to compare to see...

moesoha commented 6 years ago

Same problem appears when unpacking Hearthstone. So there must be something about the environment.

snipaste_2018-02-02_17-11-43

w/o swapping channels

snipaste_2018-02-02_17-12-43

w/ swapping channels

jleclanche commented 6 years ago

Unity3d files have multiple places where they declare endianness. At the file/bundle level, and at the asset level. It's a bit of a mess and not always consistent. But afaik unitypack handles all that.

moesoha commented 6 years ago

@jleclanche I read the codes and did some test. I believe UnityPack parsed endianess properly of assets, but the image unpacked still have a wrong channel order. You said UnityPack works with Hearthstone's RGBA4444 texture, but i failed in the last comment.