mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-27 22:00:23 -04:00
new crunch library after Unity 2017.3
This commit is contained in:
parent
b4ce12a9e8
commit
ee6c050330
@ -86,11 +86,14 @@ namespace Unity_Studio
|
|||||||
//texgenpack
|
//texgenpack
|
||||||
private texgenpack_texturetype texturetype;
|
private texgenpack_texturetype texturetype;
|
||||||
|
|
||||||
|
private int[] version;
|
||||||
|
|
||||||
public Texture2D(AssetPreloadData preloadData, bool readSwitch)
|
public Texture2D(AssetPreloadData preloadData, bool readSwitch)
|
||||||
{
|
{
|
||||||
var sourceFile = preloadData.sourceFile;
|
var sourceFile = preloadData.sourceFile;
|
||||||
var a_Stream = preloadData.sourceFile.a_Stream;
|
var a_Stream = preloadData.sourceFile.a_Stream;
|
||||||
a_Stream.Position = preloadData.Offset;
|
a_Stream.Position = preloadData.Offset;
|
||||||
|
version = sourceFile.version;
|
||||||
|
|
||||||
if (sourceFile.platform == -2)
|
if (sourceFile.platform == -2)
|
||||||
{
|
{
|
||||||
@ -100,7 +103,7 @@ namespace Unity_Studio
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
|
m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
|
||||||
if (sourceFile.version[0] > 2017 || (sourceFile.version[0] == 2017 && sourceFile.version[1] >= 3))//2017.3 and up
|
if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 3))//2017.3 and up
|
||||||
{
|
{
|
||||||
var m_ForcedFallbackFormat = a_Stream.ReadInt32();
|
var m_ForcedFallbackFormat = a_Stream.ReadInt32();
|
||||||
var m_DownscaleFallback = a_Stream.ReadBoolean();
|
var m_DownscaleFallback = a_Stream.ReadBoolean();
|
||||||
@ -111,7 +114,7 @@ namespace Unity_Studio
|
|||||||
m_CompleteImageSize = a_Stream.ReadInt32();
|
m_CompleteImageSize = a_Stream.ReadInt32();
|
||||||
m_TextureFormat = (TextureFormat)a_Stream.ReadInt32();
|
m_TextureFormat = (TextureFormat)a_Stream.ReadInt32();
|
||||||
|
|
||||||
if (sourceFile.version[0] < 5 || (sourceFile.version[0] == 5 && sourceFile.version[1] < 2))
|
if (version[0] < 5 || (version[0] == 5 && version[1] < 2))
|
||||||
{ m_MipMap = a_Stream.ReadBoolean(); }
|
{ m_MipMap = a_Stream.ReadBoolean(); }
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -131,15 +134,15 @@ namespace Unity_Studio
|
|||||||
m_Aniso = a_Stream.ReadInt32();
|
m_Aniso = a_Stream.ReadInt32();
|
||||||
m_MipBias = a_Stream.ReadSingle();
|
m_MipBias = a_Stream.ReadSingle();
|
||||||
m_WrapMode = a_Stream.ReadInt32();
|
m_WrapMode = a_Stream.ReadInt32();
|
||||||
if (sourceFile.version[0] >= 2017)//2017.x and up
|
if (version[0] >= 2017)//2017.x and up
|
||||||
{
|
{
|
||||||
int m_WrapV = a_Stream.ReadInt32();
|
int m_WrapV = a_Stream.ReadInt32();
|
||||||
int m_WrapW = a_Stream.ReadInt32();
|
int m_WrapW = a_Stream.ReadInt32();
|
||||||
}
|
}
|
||||||
if (sourceFile.version[0] >= 3)
|
if (version[0] >= 3)
|
||||||
{
|
{
|
||||||
m_LightmapFormat = a_Stream.ReadInt32();
|
m_LightmapFormat = a_Stream.ReadInt32();
|
||||||
if (sourceFile.version[0] >= 4 || sourceFile.version[1] >= 5) { m_ColorSpace = a_Stream.ReadInt32(); } //3.5.0 and up
|
if (version[0] >= 4 || version[1] >= 5) { m_ColorSpace = a_Stream.ReadInt32(); } //3.5.0 and up
|
||||||
}
|
}
|
||||||
|
|
||||||
image_data_size = a_Stream.ReadInt32();
|
image_data_size = a_Stream.ReadInt32();
|
||||||
@ -151,7 +154,7 @@ namespace Unity_Studio
|
|||||||
dwCaps += 0x400008;
|
dwCaps += 0x400008;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (image_data_size == 0 && ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 3) || sourceFile.version[0] > 5))//5.3.0 and up
|
if (image_data_size == 0 && ((version[0] == 5 && version[1] >= 3) || version[0] > 5))//5.3.0 and up
|
||||||
{
|
{
|
||||||
offset = a_Stream.ReadUInt32();
|
offset = a_Stream.ReadUInt32();
|
||||||
size = a_Stream.ReadUInt32();
|
size = a_Stream.ReadUInt32();
|
||||||
|
@ -18,7 +18,10 @@ namespace Unity_Studio
|
|||||||
private static extern bool Ponvert(byte[] buffer, IntPtr bmp, int nWidth, int nHeight, int len, int type, int bmpsize, bool fixAlpha);
|
private static extern bool Ponvert(byte[] buffer, IntPtr bmp, int nWidth, int nHeight, int len, int type, int bmpsize, bool fixAlpha);
|
||||||
|
|
||||||
[DllImport("crunch.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("crunch.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern bool DecompressCRN(byte[] pSrc_file_data, int src_file_size, out IntPtr dxtdata, out int dxtsize);
|
private static extern bool DecompressCRN(byte[] pSrc_file_data, int src_file_size, out IntPtr uncompressedData, out int uncompressedSize);
|
||||||
|
|
||||||
|
[DllImport("crunchunity.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
private static extern bool DecompressUnityCRN(byte[] pSrc_file_data, int src_file_size, out IntPtr uncompressedData, out int uncompressedSize);
|
||||||
|
|
||||||
[DllImport("texgenpack.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("texgenpack.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern void texgenpackdecode(int texturetype, byte[] texturedata, int width, int height, IntPtr bmp, bool fixAlpha);
|
private static extern void texgenpackdecode(int texturetype, byte[] texturedata, int width, int height, IntPtr bmp, bool fixAlpha);
|
||||||
@ -318,13 +321,25 @@ namespace Unity_Studio
|
|||||||
|
|
||||||
private void DecompressCRN()
|
private void DecompressCRN()
|
||||||
{
|
{
|
||||||
if (DecompressCRN(image_data, image_data_size, out IntPtr dxtdata, out int dxtsize))
|
IntPtr uncompressedData;
|
||||||
|
int uncompressedSize;
|
||||||
|
bool result;
|
||||||
|
if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 3)) //2017.3 and up
|
||||||
{
|
{
|
||||||
var dxtbytes = new byte[dxtsize];
|
result = DecompressUnityCRN(image_data, image_data_size, out uncompressedData, out uncompressedSize);
|
||||||
Marshal.Copy(dxtdata, dxtbytes, 0, dxtsize);
|
}
|
||||||
Marshal.FreeHGlobal(dxtdata);
|
else
|
||||||
image_data = dxtbytes;
|
{
|
||||||
image_data_size = dxtsize;
|
result = DecompressCRN(image_data, image_data_size, out uncompressedData, out uncompressedSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
var uncompressedBytes = new byte[uncompressedSize];
|
||||||
|
Marshal.Copy(uncompressedData, uncompressedBytes, 0, uncompressedSize);
|
||||||
|
Marshal.FreeHGlobal(uncompressedData);
|
||||||
|
image_data = uncompressedBytes;
|
||||||
|
image_data_size = uncompressedSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user