mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-27 07:34:00 +08:00
(Unity): adjusted texture entries deserialization.
This commit is contained in:
parent
7bbaa26051
commit
1392dc61d3
@ -79,27 +79,29 @@ namespace GameRes.Formats.Unity
|
|||||||
return base.OpenImage (arc, entry);
|
return base.OpenImage (arc, entry);
|
||||||
|
|
||||||
var obj = aent.AssetObject;
|
var obj = aent.AssetObject;
|
||||||
using (var stream = arc.File.CreateStream (obj.Offset, obj.Size))
|
var stream = arc.File.CreateStream (obj.Offset, obj.Size);
|
||||||
using (var reader = new AssetReader (stream))
|
var reader = new AssetReader (stream);
|
||||||
|
try
|
||||||
{
|
{
|
||||||
reader.SetupReaders (obj.Asset);
|
reader.SetupReaders (obj.Asset);
|
||||||
var tex = new Texture2D();
|
var tex = new Texture2D();
|
||||||
tex.Load (reader);
|
tex.Load (reader);
|
||||||
|
if (0 == tex.m_DataLength)
|
||||||
var input = OpenEntry (arc, entry);
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
tex.m_Data = new byte[entry.Size];
|
reader.Dispose();
|
||||||
input.Read (tex.m_Data, 0, tex.m_Data.Length);
|
var input = OpenEntry (arc, entry);
|
||||||
var tex_reader = new AssetReader (input, entry.Name);
|
reader = new AssetReader (input, entry.Name);
|
||||||
tex_reader.SetupReaders (obj.Asset);
|
reader.SetupReaders (obj.Asset);
|
||||||
return new Texture2DDecoder (tex, tex_reader);
|
tex.m_DataLength = (int)entry.Size;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
input.Dispose();
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
|
var decoder = new Texture2DDecoder (tex, reader);
|
||||||
|
reader = null;
|
||||||
|
return decoder;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (reader != null)
|
||||||
|
reader.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,7 +167,7 @@ namespace GameRes.Formats.Unity
|
|||||||
{
|
{
|
||||||
var tex = new Texture2D();
|
var tex = new Texture2D();
|
||||||
tex.Load (input);
|
tex.Load (input);
|
||||||
if (null == tex.m_Data || 0 == tex.m_Data.Length)
|
if (0 == tex.m_DataLength)
|
||||||
{
|
{
|
||||||
if (asset.Tree.Version == "2017.2.0f3")
|
if (asset.Tree.Version == "2017.2.0f3")
|
||||||
input.ReadInt64();
|
input.ReadInt64();
|
||||||
@ -182,6 +184,15 @@ namespace GameRes.Formats.Unity
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entry = new AssetEntry {
|
||||||
|
Name = tex.m_Name,
|
||||||
|
Type = "image",
|
||||||
|
Offset = obj.Offset,
|
||||||
|
Size = obj.Size,
|
||||||
|
};
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 83: // AudioClip
|
case 83: // AudioClip
|
||||||
|
@ -130,7 +130,9 @@ namespace GameRes.Formats.Unity
|
|||||||
input = new StreamRegion (input, obj.Offset, obj.Size);
|
input = new StreamRegion (input, obj.Offset, obj.Size);
|
||||||
var reader = new AssetReader (input, entry.Name);
|
var reader = new AssetReader (input, entry.Name);
|
||||||
reader.SetupReaders (obj.Asset);
|
reader.SetupReaders (obj.Asset);
|
||||||
return new Texture2DDecoder (reader);
|
var tex = new Texture2D();
|
||||||
|
tex.Load (reader);
|
||||||
|
return new Texture2DDecoder (tex, reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static byte[] UnpackLzma (byte[] input, int unpacked_size)
|
internal static byte[] UnpackLzma (byte[] input, int unpacked_size)
|
||||||
|
@ -120,7 +120,7 @@ namespace GameRes.Formats.Unity
|
|||||||
else
|
else
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
Trace.WriteLine ("Unknown type id", obj.ClassId.ToString());
|
Trace.WriteLine (string.Format ("Unknown type id {0}", obj.ClassId.ToString()), "[Unity.Asset]");
|
||||||
m_types[obj.TypeId] = null;
|
m_types[obj.TypeId] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ namespace GameRes.Formats.Unity
|
|||||||
public int m_WrapMode;
|
public int m_WrapMode;
|
||||||
public int m_LightFormat;
|
public int m_LightFormat;
|
||||||
public int m_ColorSpace;
|
public int m_ColorSpace;
|
||||||
|
public int m_DataLength;
|
||||||
public byte[] m_Data;
|
public byte[] m_Data;
|
||||||
|
|
||||||
public void Load (AssetReader reader)
|
public void Load (AssetReader reader)
|
||||||
@ -89,8 +90,12 @@ namespace GameRes.Formats.Unity
|
|||||||
m_WrapMode = reader.ReadInt32();
|
m_WrapMode = reader.ReadInt32();
|
||||||
m_LightFormat = reader.ReadInt32();
|
m_LightFormat = reader.ReadInt32();
|
||||||
m_ColorSpace = reader.ReadInt32();
|
m_ColorSpace = reader.ReadInt32();
|
||||||
int length = reader.ReadInt32();
|
m_DataLength = reader.ReadInt32();
|
||||||
m_Data = reader.ReadBytes (length);
|
}
|
||||||
|
|
||||||
|
public void LoadData (AssetReader reader)
|
||||||
|
{
|
||||||
|
m_Data = reader.ReadBytes (m_DataLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +105,7 @@ namespace GameRes.Formats.Unity
|
|||||||
Texture2D m_texture;
|
Texture2D m_texture;
|
||||||
ImageData m_image;
|
ImageData m_image;
|
||||||
|
|
||||||
public Stream Source { get { return m_reader.Source; } }
|
public Stream Source { get { m_reader.Position = 0; return m_reader.Source; } }
|
||||||
public ImageFormat SourceFormat { get { return null; } }
|
public ImageFormat SourceFormat { get { return null; } }
|
||||||
public PixelFormat Format { get; private set; }
|
public PixelFormat Format { get; private set; }
|
||||||
public ImageMetaData Info { get; private set; }
|
public ImageMetaData Info { get; private set; }
|
||||||
@ -114,19 +119,6 @@ namespace GameRes.Formats.Unity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Texture2DDecoder (AssetReader input)
|
|
||||||
{
|
|
||||||
m_reader = input;
|
|
||||||
m_texture = new Texture2D();
|
|
||||||
m_texture.Load (m_reader);
|
|
||||||
Info = new ImageMetaData {
|
|
||||||
Width = (uint)m_texture.m_Width,
|
|
||||||
Height = (uint)m_texture.m_Height,
|
|
||||||
};
|
|
||||||
SetFormat (m_texture.m_TextureFormat);
|
|
||||||
m_reader.Position = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Texture2DDecoder (Texture2D texture, AssetReader input)
|
public Texture2DDecoder (Texture2D texture, AssetReader input)
|
||||||
{
|
{
|
||||||
m_reader = input;
|
m_reader = input;
|
||||||
@ -171,6 +163,7 @@ namespace GameRes.Formats.Unity
|
|||||||
|
|
||||||
ImageData Unpack ()
|
ImageData Unpack ()
|
||||||
{
|
{
|
||||||
|
m_texture.LoadData (m_reader);
|
||||||
byte[] pixels;
|
byte[] pixels;
|
||||||
switch (m_texture.m_TextureFormat)
|
switch (m_texture.m_TextureFormat)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user