Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Fixed an issue that deserialized guids in SpriteAtlas and Sprite don'… #1034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AssetStudio/Classes/Sprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public Sprite(ObjectReader reader) : base(reader)

if (version[0] >= 2017) //2017 and up
{
var first = new Guid(reader.ReadBytes(16));
var first = UnityGuidHelper.UnityGuidToGuid(reader.ReadBytes(16));
var second = reader.ReadInt64();
m_RenderDataKey = new KeyValuePair<Guid, long>(first, second);

Expand Down
2 changes: 1 addition & 1 deletion AssetStudio/Classes/SpriteAtlas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public SpriteAtlas(ObjectReader reader) : base(reader)
m_RenderDataMap = new Dictionary<KeyValuePair<Guid, long>, SpriteAtlasData>(m_RenderDataMapSize);
for (int i = 0; i < m_RenderDataMapSize; i++)
{
var first = new Guid(reader.ReadBytes(16));
var first = UnityGuidHelper.UnityGuidToGuid(reader.ReadBytes(16));
var second = reader.ReadInt64();
var value = new SpriteAtlasData(reader);
m_RenderDataMap.Add(new KeyValuePair<Guid, long>(first, second), value);
Expand Down
28 changes: 28 additions & 0 deletions AssetStudio/UnityGuidHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AssetStudio
{
class UnityGuidHelper
{
public static Guid UnityGuidToGuid(byte[] data, int offset = 0)
{
for (int i = 0; i < 16; ++i)
{
data[i + offset] = (byte)(((data[i + offset] & 0xF0) >> 4) | ((data[i + offset] & 0x0F) << 4));
}

int d1 = BinaryPrimitives.ReadInt32BigEndian(new ReadOnlySpan<byte>(data, offset, 4));
short d2 = BinaryPrimitives.ReadInt16BigEndian(new ReadOnlySpan<byte>(data, offset + 4, 2));
short d3 = BinaryPrimitives.ReadInt16BigEndian(new ReadOnlySpan<byte>(data, offset + 6, 2));

return new Guid(d1, d2, d3,
data[offset + 8], data[offset + 9], data[offset + 10], data[offset + 11],
data[offset + 12], data[offset + 13], data[offset + 14], data[offset + 15]);
}
}
}