DerPopo
New member
Texture assets have a field that specifies which compression type/pixel format is used.Hey DerPopo, nice utility here, thanks. I have some questions regarding a situation I have where I regularly acquire new assets and need to convert them to PNG when I do.
- The assets seem to mostly be dxt5, but I'm unsure. I assume the utility can determine this from the asset itself and doesn't rely on filename extension?
- Apparently batch extraction can be done through the command line, with a list of file names (or a file, with a list of filenames). Similarly, can batch conversion to PNG be done?
- Ideally I'd like to be able to do the conversion straight from asset file to PNG directly in my program. Do you have any shareable code for this? I'd be doing it in Java, but I know C/C++ as well, so I can easily translate if necessary.
Currently, the command line is only able to export/import .assets files from/to bundles. Enhanced command line support is planned, but it won't be in UABE 2.2.
You can take a look at the API (Visual C++ 2010 Release mode only). You need to open a FILE* using fopen or similar functions, create an AssetsFile instance with AssetsReaderFromFile and (LPARAM)pFile, create an AssetsFileTable, locate the asset you want with curFileType==28 (you'll need absolutePos and curFileSize members of AssetFileInfoEx), create an AssetTypeInstance and then call ReadTextureFile and GetTextureData.
For the AssetTypeInstance, you'll either need a class database (for most separate .assets files) or just the type tree inside (for most bundled .assets files).
You can use the menu entry Options->Edit Type Package in UABE and export the type database you need from the classdata.tpk file. Then use the ClassDatabaseFile class to read it, locate the class you need using the classId, and then create an AssetTypeTemplateField and call FromClassDatabase with fieldIndex 0. Create an array of AssetTypeTemplateField* (or just pass a pointer to a AssetTypeTemplateField* and set baseFieldCount to 1) and use that on the AssetTypeInstance constructor.
If the .assets file has a proper TypeTree (hasTypeTree == true), you can enumerate through AssetsFile::typeTree.pTypes_Unity5 or 4 (header.format >= 0x0D for 5) with fieldCount entries. If an entry exists for classId==28, you can create an AssetTypeTemplateField with From0D (pass the type pointer and fieldIndex 0) or From07 (pass a pointer to the Type_07::base field), and use it the same way as explained above to create an AssetTypeInstance.
If you're reading bundles, create an Asset(s)BundleFile instance with the FILE*, locate the entry or entries you're looking for and call MakeAssetsFileReader, which you can then use to create an AssetsFile. To find out whether you have to look in assetsLists3 or bundleInf6 (different type pointers stored in the same union), just check if bundleHeader3.fileVersion is 3 or 6.
Note that if TextureFile::m_StreamData.size is not 0, you probably have a reference to a streamed asset. If it's in a bundle file, the m_StreamData.path string should start with "archive:/". The first part of the archive path is a bundle file name, derived from one of the bundle entry names. The second part (separated with a "/") is the actual bundle entry name you're looking for. You can open a reader through Asset(s)BundleFile::MakeAssetsFileReader as above.
Otherwise, the m_StreamData.path string is just a file name relative to the .assets file.
The texture data starts at m_StreamData.offset and has m_StreamData.size bytes. Read it into a memory buffer, set TextureFile:

GetTextureData converts any supported texture format to RGBA32, so make sure your output buffer has m_Width*m_Height*4 bytes. Also make sure you have TexToolWrap.dll and PVRTexLib.dll next to the AssetsTools.dll if you want to decompress EAC, ETC, ETC2, PVRTC and/or ASTC textures.
I'm using lodepng (lodepng_encode32 function) to create a PNG out of the uncompressed data.
If you want to use Java for your main programm, I recommend creating a wrapper library in C++ that can only export textures using this procedure since it'd be quite a lot work to make a full wrapper of AssetsTools.dll.
In 2.2, the file callback/LPARAM parameter pairs will be replaced by proper virtual classes.