nesrak1 / UABEA

c# uabe for newer versions of unity
MIT License
1.13k stars 144 forks source link

Suggestion: Texture swizzling/unswizzling #185

Closed Nazosan closed 1 year ago

Nazosan commented 2 years ago

This has been becoming more and more of a problem. Many console games -- especially on the Switch which doesn't have the most powerful GPU in the world -- are, more and more frequently starting to use swizzled textures even in Unity games. There seems to be absolutely no official way for users to handle this either. The only semi-reproducible way I could ever find to unswizzle textures from something like a Switch Unity game is to extract raw and then use a tool called "rawtex" posted a long time ago on the Zenhax forum meant to convert raw textures to standard DDS files which happens to have an unswizzle option -- and this only seems to work sometimes (probably requiring textures to be stored in certain fairly specific formats and settings and not supporting anything newer than when they made the tool. I notice most that don't work say "channels: BGRA" in Unity Asset Studio, so I wonder if they're stored in BGRA order instead of RGBA or something, but I don't really know what the deal is.) More and more frequently I get broken textures from it when I try to use it to unswizzle stuff from Unity games. Reswizzling textures is even harder. No one seems to have provided any single tool for this express purpose of swizzling at all (the only guides or anything I ever found were for Unreal games. You have to pack the files into Unreal uassets and use Noesis to swizzle which may or may not even import right into a Unity game.) There do seem to be open source implementations for this that seem to be part of various things, but no one seems to have made actual tools implementing them for any purpose like this.

With more and more Unity games going this route, it would really be helpful if tools like this could actually handle swizzled textures both ways. It's extremely hard to deal with them at all as it is, but more and more often it's starting to not work at all (I presume as newer formats for compressing, color formats, etc are being used, but I'm not really sure what it is.) After all, it defeats the purpose of having tools to do things like replacing textures if... you can't actually do that... I think since Unity seems to offer this as an option now more games will use it rather than less since, at least in theory, it offers better performance.

I don't know if it helps any to have an example, but "Potato Flowers in Full Bloom" (yeah, crazy name for a fairly straightfoward dungeon crawler) is a good example of a simple, small game available on PC and Switch where the Switch version uses swizzled textures. (I had initially hoped I could make the walls look a bit nicer, but this insane game actually only has a few textures for individual bricks and builds every single wall one brick at a time instead of having actual wall textures.)

nesrak1 commented 2 years ago

Do you have Discord? I think it would be easier to discuss there.

nesrak1 commented 2 years ago

I'm not sure what indicates whether a texture should be like this (maybe m_PlatformBlob or a setting in globalgamemanagers?) so I think either having a checkbox in the main texture plugin or a forked plugin just for switch textures should be made. For now though, if you need an easy drag and drop converter for textures exported from UABEA, try this: FixSwitchTextures.zip. It should be doing the same thing rawtex does.

Nazosan commented 2 years ago

Sorry, I'll have to get back to you on the Discord. I do have it but have been away from my own computer and the phone with the authenticator (long story, but it's separate.) I see the link on the main page, so I'll use that when I'm able.

I'm not sure how to use that drag and drop plugin. Do I have to compile it myself? I'm afraid I'm not really sure how to do that (and don't have the necessary stuff installed right now anyway.) I'd love an alternative to rawtex because it seems to fail on most newer games for me for whatever reason. (I don't have any it fails on handy to tell you exactly what it does, but it seems to produce a gibberish texture with squares that is exactly the same for every single input.) I've forgotten what games did it, so I'll get back to you on that if you need an example, but I seem to recall each said "BGRA" for the channels in Unity Asset Studio instead of "RGBA" (which may or may not even mean anything, I'm just grasping at straws.)

I'm not sure how to tell what to look for. The games themselves must know because they often have a mixture of swizzled and unswizzled textures almost randomly (I've seen some unswizzled in the same group as others of the same type that were! That's just silly...) Of course, games sometimes have some details about assets separately (for example, Rune Factory 5 lists its assets inside a gigantic .json file because the game itself couldn't possibly load the > 40,000 separate seemingly completely randomized files they created all at once for some reason.) I'll dump a bunch of stuff from my Switch later when I have time and try to find you a better example. (I'm not a real modder -- mostly just stuff like sharpening a few textures or making a UI darker or something, so most of those that I couldn't do I just gave up on, but I think a lot of real modders would surely appreciate it a lot.) I'll try to provide more info on Discord later when I find something.

EDIT: Found an example of a game with mixed textures sooner than I thought I would. Dungeons of Dreadrock, a fun little puzzle game (looks like a roguelike, but isn't.) Also, it too fails to unswizzle correctly in rawtex. I'll hop on Discord once I'm able to and discuss it more there.

nesrak1 commented 2 years ago

Do I have to compile it myself?

Here's a build I just made (had to double zip because of github upload size limits): win-x64_2.zip

nesrak1 commented 1 year ago

Completed. Thanks for helping.

nesrak1 commented 8 months ago

I keep getting asked about the program in this issue, but it was replaced long ago and you shouldn't use it because it only supports PO2 textures of certain formats.

If you want to script with AssetsTools.NET, you can do that soon since I will be moving the swizzle code to the AssetsTools.NET.Texture library soon.