Update README.md
Updated project Support 2017.4
This commit is contained in:
51
UnityStudio/Classes/AssetBundle.cs
Normal file
51
UnityStudio/Classes/AssetBundle.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
|
||||
class AssetBundle
|
||||
{
|
||||
public class AssetInfo
|
||||
{
|
||||
public int preloadIndex;
|
||||
public int preloadSize;
|
||||
public PPtr asset;
|
||||
}
|
||||
|
||||
public class ContainerData
|
||||
{
|
||||
public string first;
|
||||
public AssetInfo second;
|
||||
}
|
||||
|
||||
|
||||
public List<ContainerData> m_Container = new List<ContainerData>();
|
||||
|
||||
public AssetBundle(AssetPreloadData preloadData)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
var m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
var size = reader.ReadInt32();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
sourceFile.ReadPPtr();
|
||||
}
|
||||
size = reader.ReadInt32();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var temp = new ContainerData();
|
||||
temp.first = reader.ReadAlignedString(reader.ReadInt32());
|
||||
temp.second = new AssetInfo();
|
||||
temp.second.preloadIndex = reader.ReadInt32();
|
||||
temp.second.preloadSize = reader.ReadInt32();
|
||||
temp.second.asset = sourceFile.ReadPPtr();
|
||||
m_Container.Add(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
303
UnityStudio/Classes/AudioClip.cs
Normal file
303
UnityStudio/Classes/AudioClip.cs
Normal file
@@ -0,0 +1,303 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
class AudioClip
|
||||
{
|
||||
public string m_Name;
|
||||
public int m_Format;
|
||||
public AudioType m_Type;
|
||||
public bool m_3D;
|
||||
public bool m_UseHardware;
|
||||
|
||||
//Unity 5
|
||||
public int m_LoadType;
|
||||
public int m_Channels;
|
||||
public int m_Frequency;
|
||||
public int m_BitsPerSample;
|
||||
public float m_Length;
|
||||
public bool m_IsTrackerFormat;
|
||||
public int m_SubsoundIndex;
|
||||
public bool m_PreloadAudioData;
|
||||
public bool m_LoadInBackground;
|
||||
public bool m_Legacy3D;
|
||||
public AudioCompressionFormat m_CompressionFormat;
|
||||
|
||||
public string m_Source;
|
||||
public long m_Offset;
|
||||
public long m_Size;
|
||||
public byte[] m_AudioData;
|
||||
|
||||
public bool version5;
|
||||
|
||||
public AudioClip(AssetPreloadData preloadData, bool readSwitch)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
if (sourceFile.platform == -2)
|
||||
{
|
||||
uint m_ObjectHideFlags = reader.ReadUInt32();
|
||||
PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
|
||||
PPtr m_PrefabInternal = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
version5 = sourceFile.version[0] >= 5;
|
||||
if (sourceFile.version[0] < 5)
|
||||
{
|
||||
|
||||
m_Format = reader.ReadInt32(); //channels?
|
||||
m_Type = (AudioType)reader.ReadInt32();
|
||||
m_3D = reader.ReadBoolean();
|
||||
m_UseHardware = reader.ReadBoolean();
|
||||
reader.Position += 2; //4 byte alignment
|
||||
|
||||
if (sourceFile.version[0] >= 4 || (sourceFile.version[0] == 3 && sourceFile.version[1] >= 2)) //3.2.0 to 5
|
||||
{
|
||||
int m_Stream = reader.ReadInt32();
|
||||
m_Size = reader.ReadInt32();
|
||||
var tsize = m_Size % 4 != 0 ? m_Size + 4 - m_Size % 4 : m_Size;
|
||||
//TODO: Need more test
|
||||
if (preloadData.Size + preloadData.Offset - reader.Position != tsize)
|
||||
{
|
||||
m_Offset = reader.ReadInt32();
|
||||
m_Source = sourceFile.filePath + ".resS";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Size = reader.ReadInt32();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_LoadType = reader.ReadInt32(); //Decompress on load, Compressed in memory, Streaming
|
||||
m_Channels = reader.ReadInt32();
|
||||
m_Frequency = reader.ReadInt32();
|
||||
m_BitsPerSample = reader.ReadInt32();
|
||||
m_Length = reader.ReadSingle();
|
||||
m_IsTrackerFormat = reader.ReadBoolean();
|
||||
reader.Position += 3;
|
||||
m_SubsoundIndex = reader.ReadInt32();
|
||||
m_PreloadAudioData = reader.ReadBoolean();
|
||||
m_LoadInBackground = reader.ReadBoolean();
|
||||
m_Legacy3D = reader.ReadBoolean();
|
||||
reader.Position += 1;
|
||||
m_3D = m_Legacy3D;
|
||||
|
||||
m_Source = reader.ReadAlignedString(reader.ReadInt32());
|
||||
m_Offset = reader.ReadInt64();
|
||||
m_Size = reader.ReadInt64();
|
||||
m_CompressionFormat = (AudioCompressionFormat)reader.ReadInt32();
|
||||
}
|
||||
|
||||
if (readSwitch)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(m_Source))
|
||||
{
|
||||
var resourceFileName = Path.GetFileName(m_Source);
|
||||
var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
|
||||
if (!File.Exists(resourceFilePath))
|
||||
{
|
||||
var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
|
||||
if (findFiles.Length > 0)
|
||||
{
|
||||
resourceFilePath = findFiles[0];
|
||||
}
|
||||
}
|
||||
if (File.Exists(resourceFilePath))
|
||||
{
|
||||
using (var resourceReader = new BinaryReader(File.OpenRead(resourceFilePath)))
|
||||
{
|
||||
resourceReader.BaseStream.Position = m_Offset;
|
||||
m_AudioData = resourceReader.ReadBytes((int)m_Size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Studio.resourceFileReaders.TryGetValue(resourceFileName.ToUpper(), out var resourceReader))
|
||||
{
|
||||
resourceReader.Position = m_Offset;
|
||||
m_AudioData = resourceReader.ReadBytes((int)m_Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show($"can't find the resource file {resourceFileName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_Size > 0)
|
||||
m_AudioData = reader.ReadBytes((int)m_Size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
preloadData.InfoText = "Compression format: ";
|
||||
|
||||
if (sourceFile.version[0] < 5)
|
||||
{
|
||||
switch (m_Type)
|
||||
{
|
||||
case AudioType.ACC:
|
||||
preloadData.extension = ".m4a";
|
||||
preloadData.InfoText += "Acc";
|
||||
break;
|
||||
case AudioType.AIFF:
|
||||
preloadData.extension = ".aif";
|
||||
preloadData.InfoText += "AIFF";
|
||||
break;
|
||||
case AudioType.IT:
|
||||
preloadData.extension = ".it";
|
||||
preloadData.InfoText += "Impulse tracker";
|
||||
break;
|
||||
case AudioType.MOD:
|
||||
preloadData.extension = ".mod";
|
||||
preloadData.InfoText += "Protracker / Fasttracker MOD";
|
||||
break;
|
||||
case AudioType.MPEG:
|
||||
preloadData.extension = ".mp3";
|
||||
preloadData.InfoText += "MP2/MP3 MPEG";
|
||||
break;
|
||||
case AudioType.OGGVORBIS:
|
||||
preloadData.extension = ".ogg";
|
||||
preloadData.InfoText += "Ogg vorbis";
|
||||
break;
|
||||
case AudioType.S3M:
|
||||
preloadData.extension = ".s3m";
|
||||
preloadData.InfoText += "ScreamTracker 3";
|
||||
break;
|
||||
case AudioType.WAV:
|
||||
preloadData.extension = ".wav";
|
||||
preloadData.InfoText += "Microsoft WAV";
|
||||
break;
|
||||
case AudioType.XM:
|
||||
preloadData.extension = ".xm";
|
||||
preloadData.InfoText += "FastTracker 2 XM";
|
||||
break;
|
||||
case AudioType.XMA:
|
||||
preloadData.extension = ".wav";
|
||||
preloadData.InfoText += "Xbox360 XMA";
|
||||
break;
|
||||
case AudioType.VAG:
|
||||
preloadData.extension = ".vag";
|
||||
preloadData.InfoText += "PlayStation Portable ADPCM";
|
||||
break;
|
||||
case AudioType.AUDIOQUEUE:
|
||||
preloadData.extension = ".fsb";
|
||||
preloadData.InfoText += "iPhone";
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (m_CompressionFormat)
|
||||
{
|
||||
case AudioCompressionFormat.PCM:
|
||||
preloadData.extension = ".fsb";
|
||||
preloadData.InfoText += "PCM";
|
||||
break;
|
||||
case AudioCompressionFormat.Vorbis:
|
||||
preloadData.extension = ".fsb";
|
||||
preloadData.InfoText += "Vorbis";
|
||||
break;
|
||||
case AudioCompressionFormat.ADPCM:
|
||||
preloadData.extension = ".fsb";
|
||||
preloadData.InfoText += "ADPCM";
|
||||
break;
|
||||
case AudioCompressionFormat.MP3:
|
||||
preloadData.extension = ".fsb";
|
||||
preloadData.InfoText += "MP3";
|
||||
break;
|
||||
case AudioCompressionFormat.VAG:
|
||||
preloadData.extension = ".vag";
|
||||
preloadData.InfoText += "PlayStation Portable ADPCM";
|
||||
break;
|
||||
case AudioCompressionFormat.HEVAG:
|
||||
preloadData.extension = ".vag";
|
||||
preloadData.InfoText += "PSVita ADPCM";
|
||||
break;
|
||||
case AudioCompressionFormat.XMA:
|
||||
preloadData.extension = ".wav";
|
||||
preloadData.InfoText += "Xbox360 XMA";
|
||||
break;
|
||||
case AudioCompressionFormat.AAC:
|
||||
preloadData.extension = ".m4a";
|
||||
preloadData.InfoText += "AAC";
|
||||
break;
|
||||
case AudioCompressionFormat.GCADPCM:
|
||||
preloadData.extension = ".fsb";
|
||||
preloadData.InfoText += "Nintendo 3DS/Wii DSP";
|
||||
break;
|
||||
case AudioCompressionFormat.ATRAC9:
|
||||
preloadData.extension = ".at9";
|
||||
preloadData.InfoText += "PSVita ATRAC9";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (preloadData.extension == null)
|
||||
{
|
||||
preloadData.extension = ".AudioClip";
|
||||
preloadData.InfoText += "Unknown";
|
||||
}
|
||||
|
||||
preloadData.InfoText += "\n3D: " + m_3D;
|
||||
|
||||
preloadData.Text = m_Name;
|
||||
if (m_Source != null)
|
||||
preloadData.fullSize = preloadData.Size + (int)m_Size;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsFMODSupport
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!version5)
|
||||
{
|
||||
switch (m_Type)
|
||||
{
|
||||
case AudioType.AIFF:
|
||||
case AudioType.IT:
|
||||
case AudioType.MOD:
|
||||
case AudioType.S3M:
|
||||
case AudioType.XM:
|
||||
case AudioType.XMA:
|
||||
case AudioType.VAG:
|
||||
case AudioType.AUDIOQUEUE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (m_CompressionFormat)
|
||||
{
|
||||
case AudioCompressionFormat.PCM:
|
||||
case AudioCompressionFormat.Vorbis:
|
||||
case AudioCompressionFormat.ADPCM:
|
||||
case AudioCompressionFormat.MP3:
|
||||
case AudioCompressionFormat.VAG:
|
||||
case AudioCompressionFormat.HEVAG:
|
||||
case AudioCompressionFormat.XMA:
|
||||
case AudioCompressionFormat.GCADPCM:
|
||||
case AudioCompressionFormat.ATRAC9:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
37
UnityStudio/Classes/BuildSettings.cs
Normal file
37
UnityStudio/Classes/BuildSettings.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
public class BuildSettings
|
||||
{
|
||||
public string m_Version;
|
||||
|
||||
public BuildSettings(AssetPreloadData preloadData)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
int levels = reader.ReadInt32();
|
||||
for (int l = 0; l < levels; l++) { string level = reader.ReadAlignedString(reader.ReadInt32()); }
|
||||
|
||||
if (sourceFile.version[0] == 5)
|
||||
{
|
||||
int preloadedPlugins = reader.ReadInt32();
|
||||
for (int l = 0; l < preloadedPlugins; l++) { string preloadedPlugin = reader.ReadAlignedString(reader.ReadInt32()); }
|
||||
}
|
||||
|
||||
reader.Position += 4; //bool flags
|
||||
if (sourceFile.fileGen >= 8) { reader.Position += 4; } //bool flags
|
||||
if (sourceFile.fileGen >= 9) { reader.Position += 4; } //bool flags
|
||||
if (sourceFile.version[0] == 5 ||
|
||||
(sourceFile.version[0] == 4 && (sourceFile.version[1] >= 3 ||
|
||||
(sourceFile.version[1] == 2 && sourceFile.buildType[0] != "a"))))
|
||||
{ reader.Position += 4; } //bool flags
|
||||
|
||||
m_Version = reader.ReadAlignedString(reader.ReadInt32());
|
||||
}
|
||||
}
|
||||
}
|
||||
190
UnityStudio/Classes/Font.cs
Normal file
190
UnityStudio/Classes/Font.cs
Normal file
@@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
class UnityFont
|
||||
{
|
||||
public string m_Name;
|
||||
public byte[] m_FontData;
|
||||
|
||||
public UnityFont(AssetPreloadData preloadData, bool readSwitch)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
if (sourceFile.platform == -2)
|
||||
{
|
||||
uint m_ObjectHideFlags = reader.ReadUInt32();
|
||||
PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
|
||||
PPtr m_PrefabInternal = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
|
||||
if (readSwitch)
|
||||
{
|
||||
if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 5) || sourceFile.version[0] > 5)
|
||||
{
|
||||
var m_LineSpacing = reader.ReadSingle();
|
||||
var m_DefaultMaterial = sourceFile.ReadPPtr();
|
||||
var m_FontSize = reader.ReadSingle();
|
||||
var m_Texture = sourceFile.ReadPPtr();
|
||||
int m_AsciiStartOffset = reader.ReadInt32();
|
||||
var m_Tracking = reader.ReadSingle();
|
||||
var m_CharacterSpacing = reader.ReadInt32();
|
||||
var m_CharacterPadding = reader.ReadInt32();
|
||||
var m_ConvertCase = reader.ReadInt32();
|
||||
int m_CharacterRects_size = reader.ReadInt32();
|
||||
for (int i = 0; i < m_CharacterRects_size; i++)
|
||||
{
|
||||
int index = reader.ReadInt32();
|
||||
//Rectf uv
|
||||
float uvx = reader.ReadSingle();
|
||||
float uvy = reader.ReadSingle();
|
||||
float uvwidth = reader.ReadSingle();
|
||||
float uvheight = reader.ReadSingle();
|
||||
//Rectf vert
|
||||
float vertx = reader.ReadSingle();
|
||||
float verty = reader.ReadSingle();
|
||||
float vertwidth = reader.ReadSingle();
|
||||
float vertheight = reader.ReadSingle();
|
||||
float width = reader.ReadSingle();
|
||||
|
||||
if (sourceFile.version[0] >= 4)
|
||||
{
|
||||
bool flipped = reader.ReadBoolean();
|
||||
reader.Position += 3;
|
||||
}
|
||||
}
|
||||
int m_KerningValues_size = reader.ReadInt32();
|
||||
for (int i = 0; i < m_KerningValues_size; i++)
|
||||
{
|
||||
int pairfirst = reader.ReadInt16();
|
||||
int pairsecond = reader.ReadInt16();
|
||||
float second = reader.ReadSingle();
|
||||
}
|
||||
var m_PixelScale = reader.ReadSingle();
|
||||
int m_FontData_size = reader.ReadInt32();
|
||||
if (m_FontData_size > 0)
|
||||
{
|
||||
m_FontData = reader.ReadBytes(m_FontData_size);
|
||||
|
||||
if (m_FontData[0] == 79 && m_FontData[1] == 84 && m_FontData[2] == 84 && m_FontData[3] == 79)
|
||||
{ preloadData.extension = ".otf"; }
|
||||
else { preloadData.extension = ".ttf"; }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int m_AsciiStartOffset = reader.ReadInt32();
|
||||
|
||||
if (sourceFile.version[0] <= 3)
|
||||
{
|
||||
int m_FontCountX = reader.ReadInt32();
|
||||
int m_FontCountY = reader.ReadInt32();
|
||||
}
|
||||
|
||||
float m_Kerning = reader.ReadSingle();
|
||||
float m_LineSpacing = reader.ReadSingle();
|
||||
|
||||
if (sourceFile.version[0] <= 3)
|
||||
{
|
||||
int m_PerCharacterKerning_size = reader.ReadInt32();
|
||||
for (int i = 0; i < m_PerCharacterKerning_size; i++)
|
||||
{
|
||||
int first = reader.ReadInt32();
|
||||
float second = reader.ReadSingle();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int m_CharacterSpacing = reader.ReadInt32();
|
||||
int m_CharacterPadding = reader.ReadInt32();
|
||||
}
|
||||
|
||||
int m_ConvertCase = reader.ReadInt32();
|
||||
PPtr m_DefaultMaterial = sourceFile.ReadPPtr();
|
||||
|
||||
int m_CharacterRects_size = reader.ReadInt32();
|
||||
for (int i = 0; i < m_CharacterRects_size; i++)
|
||||
{
|
||||
int index = reader.ReadInt32();
|
||||
//Rectf uv
|
||||
float uvx = reader.ReadSingle();
|
||||
float uvy = reader.ReadSingle();
|
||||
float uvwidth = reader.ReadSingle();
|
||||
float uvheight = reader.ReadSingle();
|
||||
//Rectf vert
|
||||
float vertx = reader.ReadSingle();
|
||||
float verty = reader.ReadSingle();
|
||||
float vertwidth = reader.ReadSingle();
|
||||
float vertheight = reader.ReadSingle();
|
||||
float width = reader.ReadSingle();
|
||||
|
||||
if (sourceFile.version[0] >= 4)
|
||||
{
|
||||
bool flipped = reader.ReadBoolean();
|
||||
reader.Position += 3;
|
||||
}
|
||||
}
|
||||
|
||||
PPtr m_Texture = sourceFile.ReadPPtr();
|
||||
|
||||
int m_KerningValues_size = reader.ReadInt32();
|
||||
for (int i = 0; i < m_KerningValues_size; i++)
|
||||
{
|
||||
int pairfirst = reader.ReadInt16();
|
||||
int pairsecond = reader.ReadInt16();
|
||||
float second = reader.ReadSingle();
|
||||
}
|
||||
|
||||
if (sourceFile.version[0] <= 3)
|
||||
{
|
||||
bool m_GridFont = reader.ReadBoolean();
|
||||
reader.Position += 3; //4 byte alignment
|
||||
}
|
||||
else { float m_PixelScale = reader.ReadSingle(); }
|
||||
|
||||
int m_FontData_size = reader.ReadInt32();
|
||||
if (m_FontData_size > 0)
|
||||
{
|
||||
m_FontData = reader.ReadBytes(m_FontData_size);
|
||||
|
||||
if (m_FontData[0] == 79 && m_FontData[1] == 84 && m_FontData[2] == 84 && m_FontData[3] == 79)
|
||||
{ preloadData.extension = ".otf"; }
|
||||
else { preloadData.extension = ".ttf"; }
|
||||
|
||||
}
|
||||
|
||||
float m_FontSize = reader.ReadSingle();//problem here in minifootball
|
||||
float m_Ascent = reader.ReadSingle();
|
||||
uint m_DefaultStyle = reader.ReadUInt32();
|
||||
|
||||
int m_FontNames = reader.ReadInt32();
|
||||
for (int i = 0; i < m_FontNames; i++)
|
||||
{
|
||||
string m_FontName = reader.ReadAlignedString(reader.ReadInt32());
|
||||
}
|
||||
|
||||
if (sourceFile.version[0] >= 4)
|
||||
{
|
||||
int m_FallbackFonts = reader.ReadInt32();
|
||||
for (int i = 0; i < m_FallbackFonts; i++)
|
||||
{
|
||||
PPtr m_FallbackFont = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
int m_FontRenderingMode = reader.ReadInt32();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
preloadData.Text = m_Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
66
UnityStudio/Classes/GameObject.cs
Normal file
66
UnityStudio/Classes/GameObject.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
public class GameObject : TreeNode
|
||||
{
|
||||
public List<PPtr> m_Components = new List<PPtr>();
|
||||
public PPtr m_Transform;
|
||||
public PPtr m_MeshRenderer;
|
||||
public PPtr m_MeshFilter;
|
||||
public PPtr m_SkinnedMeshRenderer;
|
||||
public int m_Layer;
|
||||
public string m_Name;
|
||||
public ushort m_Tag;
|
||||
public bool m_IsActive;
|
||||
|
||||
public string uniqueID = "0";//this way file and folder TreeNodes will be treated as FBX scene
|
||||
|
||||
public GameObject(AssetPreloadData preloadData)
|
||||
{
|
||||
if (preloadData != null)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
uniqueID = preloadData.uniqueID;
|
||||
|
||||
if (sourceFile.platform == -2)
|
||||
{
|
||||
uint m_ObjectHideFlags = reader.ReadUInt32();
|
||||
PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
|
||||
PPtr m_PrefabInternal = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
int m_Component_size = reader.ReadInt32();
|
||||
for (int j = 0; j < m_Component_size; j++)
|
||||
{
|
||||
if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 5) || sourceFile.version[0] > 5)//5.5.0 and up
|
||||
{
|
||||
m_Components.Add(sourceFile.ReadPPtr());
|
||||
}
|
||||
else
|
||||
{
|
||||
int first = reader.ReadInt32();
|
||||
m_Components.Add(sourceFile.ReadPPtr());
|
||||
}
|
||||
}
|
||||
|
||||
m_Layer = reader.ReadInt32();
|
||||
m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
if (m_Name == "") { m_Name = "GameObject #" + uniqueID; }
|
||||
m_Tag = reader.ReadUInt16();
|
||||
m_IsActive = reader.ReadBoolean();
|
||||
|
||||
Text = m_Name;
|
||||
preloadData.Text = m_Name;
|
||||
//name should be unique
|
||||
Name = uniqueID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
129
UnityStudio/Classes/Material.cs
Normal file
129
UnityStudio/Classes/Material.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
class TexEnv
|
||||
{
|
||||
public string name;
|
||||
public PPtr m_Texture;
|
||||
public float[] m_Scale;
|
||||
public float[] m_Offset;
|
||||
}
|
||||
|
||||
class strFloatPair
|
||||
{
|
||||
public string first;
|
||||
public float second;
|
||||
}
|
||||
|
||||
class strColorPair
|
||||
{
|
||||
public string first;
|
||||
public float[] second;
|
||||
}
|
||||
|
||||
class Material
|
||||
{
|
||||
public string m_Name;
|
||||
public PPtr m_Shader;
|
||||
public string[] m_ShaderKeywords;
|
||||
public int m_CustomRenderQueue;
|
||||
public TexEnv[] m_TexEnvs;
|
||||
public strFloatPair[] m_Floats;
|
||||
public strColorPair[] m_Colors;
|
||||
|
||||
public Material(AssetPreloadData preloadData)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
if (sourceFile.platform == -2)
|
||||
{
|
||||
uint m_ObjectHideFlags = reader.ReadUInt32();
|
||||
PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
|
||||
PPtr m_PrefabInternal = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
m_Shader = sourceFile.ReadPPtr();
|
||||
|
||||
if (sourceFile.version[0] == 4 && (sourceFile.version[1] >= 2 || (sourceFile.version[1] == 1 && sourceFile.buildType[0] != "a")))
|
||||
{
|
||||
m_ShaderKeywords = new string[reader.ReadInt32()];
|
||||
for (int i = 0; i < m_ShaderKeywords.Length; i++)
|
||||
{
|
||||
m_ShaderKeywords[i] = reader.ReadAlignedString(reader.ReadInt32());
|
||||
}
|
||||
}
|
||||
else if (sourceFile.version[0] >= 5)//5.0 and up
|
||||
{
|
||||
m_ShaderKeywords = new[] { reader.ReadAlignedString(reader.ReadInt32()) };
|
||||
uint m_LightmapFlags = reader.ReadUInt32();
|
||||
if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 6 || sourceFile.version[0] > 5)//5.6.0 and up
|
||||
{
|
||||
var m_EnableInstancingVariants = reader.ReadBoolean();
|
||||
//var m_DoubleSidedGI = a_Stream.ReadBoolean();//2017.x
|
||||
reader.AlignStream(4);
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceFile.version[0] > 4 || sourceFile.version[0] == 4 && sourceFile.version[1] >= 3) { m_CustomRenderQueue = reader.ReadInt32(); }
|
||||
|
||||
if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 1 || sourceFile.version[0] > 5)//5.1 and up
|
||||
{
|
||||
string[][] stringTagMap = new string[reader.ReadInt32()][];
|
||||
for (int i = 0; i < stringTagMap.Length; i++)
|
||||
{
|
||||
stringTagMap[i] = new[] { reader.ReadAlignedString(reader.ReadInt32()), reader.ReadAlignedString(reader.ReadInt32()) };
|
||||
}
|
||||
}
|
||||
//disabledShaderPasses
|
||||
if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 6) || sourceFile.version[0] > 5)//5.6.0 and up
|
||||
{
|
||||
var size = reader.ReadInt32();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
reader.ReadAlignedString(reader.ReadInt32());
|
||||
}
|
||||
}
|
||||
//m_SavedProperties
|
||||
m_TexEnvs = new TexEnv[reader.ReadInt32()];
|
||||
for (int i = 0; i < m_TexEnvs.Length; i++)
|
||||
{
|
||||
TexEnv m_TexEnv = new TexEnv()
|
||||
{
|
||||
name = reader.ReadAlignedString(reader.ReadInt32()),
|
||||
m_Texture = sourceFile.ReadPPtr(),
|
||||
m_Scale = new[] { reader.ReadSingle(), reader.ReadSingle() },
|
||||
m_Offset = new[] { reader.ReadSingle(), reader.ReadSingle() }
|
||||
};
|
||||
m_TexEnvs[i] = m_TexEnv;
|
||||
}
|
||||
|
||||
m_Floats = new strFloatPair[reader.ReadInt32()];
|
||||
for (int i = 0; i < m_Floats.Length; i++)
|
||||
{
|
||||
strFloatPair m_Float = new strFloatPair()
|
||||
{
|
||||
first = reader.ReadAlignedString(reader.ReadInt32()),
|
||||
second = reader.ReadSingle()
|
||||
};
|
||||
m_Floats[i] = m_Float;
|
||||
}
|
||||
|
||||
m_Colors = new strColorPair[reader.ReadInt32()];
|
||||
for (int i = 0; i < m_Colors.Length; i++)
|
||||
{
|
||||
strColorPair m_Color = new strColorPair()
|
||||
{
|
||||
first = reader.ReadAlignedString(reader.ReadInt32()),
|
||||
second = new[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }
|
||||
};
|
||||
m_Colors[i] = m_Color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1295
UnityStudio/Classes/Mesh.cs
Normal file
1295
UnityStudio/Classes/Mesh.cs
Normal file
File diff suppressed because it is too large
Load Diff
30
UnityStudio/Classes/MeshFilter.cs
Normal file
30
UnityStudio/Classes/MeshFilter.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
public class MeshFilter
|
||||
{
|
||||
public long preloadIndex;
|
||||
public PPtr m_GameObject = new PPtr();
|
||||
public PPtr m_Mesh = new PPtr();
|
||||
|
||||
public MeshFilter(AssetPreloadData preloadData)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
if (sourceFile.platform == -2)
|
||||
{
|
||||
uint m_ObjectHideFlags = reader.ReadUInt32();
|
||||
PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
|
||||
PPtr m_PrefabInternal = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
m_GameObject = sourceFile.ReadPPtr();
|
||||
m_Mesh = sourceFile.ReadPPtr();
|
||||
}
|
||||
}
|
||||
}
|
||||
62
UnityStudio/Classes/MeshRenderer.cs
Normal file
62
UnityStudio/Classes/MeshRenderer.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
class MeshRenderer
|
||||
{
|
||||
public PPtr m_GameObject;
|
||||
public bool m_Enabled;
|
||||
public byte m_CastShadows; //bool prior to Unity 5
|
||||
public bool m_ReceiveShadows;
|
||||
public ushort m_LightmapIndex;
|
||||
public ushort m_LightmapIndexDynamic;
|
||||
public PPtr[] m_Materials;
|
||||
|
||||
public MeshRenderer(AssetPreloadData preloadData)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
if (sourceFile.platform == -2)
|
||||
{
|
||||
uint m_ObjectHideFlags = reader.ReadUInt32();
|
||||
PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
|
||||
PPtr m_PrefabInternal = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
m_GameObject = sourceFile.ReadPPtr();
|
||||
|
||||
if (sourceFile.version[0] < 5)
|
||||
{
|
||||
m_Enabled = reader.ReadBoolean();
|
||||
m_CastShadows = reader.ReadByte();
|
||||
m_ReceiveShadows = reader.ReadBoolean();
|
||||
m_LightmapIndex = reader.ReadByte();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Enabled = reader.ReadBoolean();
|
||||
reader.AlignStream(4);
|
||||
m_CastShadows = reader.ReadByte();
|
||||
m_ReceiveShadows = reader.ReadBoolean();
|
||||
reader.AlignStream(4);
|
||||
|
||||
m_LightmapIndex = reader.ReadUInt16();
|
||||
m_LightmapIndexDynamic = reader.ReadUInt16();
|
||||
}
|
||||
|
||||
if (sourceFile.version[0] >= 3) { reader.Position += 16; } //Vector4f m_LightmapTilingOffset
|
||||
if (sourceFile.version[0] >= 5) { reader.Position += 16; } //Vector4f m_LightmapTilingOffsetDynamic
|
||||
|
||||
m_Materials = new PPtr[reader.ReadInt32()];
|
||||
for (int m = 0; m < m_Materials.Length; m++)
|
||||
{
|
||||
m_Materials[m] = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
44
UnityStudio/Classes/MonoBehaviour.cs
Normal file
44
UnityStudio/Classes/MonoBehaviour.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
class MonoBehaviour
|
||||
{
|
||||
public string serializedText;
|
||||
|
||||
public MonoBehaviour(AssetPreloadData preloadData, bool readSwitch)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
var m_GameObject = sourceFile.ReadPPtr();
|
||||
var m_Enabled = reader.ReadByte();
|
||||
reader.AlignStream(4);
|
||||
var m_Script = sourceFile.ReadPPtr();
|
||||
var m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
if (readSwitch)
|
||||
{
|
||||
if ((serializedText = preloadData.ViewStruct()) == null)
|
||||
{
|
||||
var str = "PPtr<GameObject> m_GameObject\r\n";
|
||||
str += "\tint m_FileID = " + m_GameObject.m_FileID + "\r\n";
|
||||
str += "\tint64 m_PathID = " + m_GameObject.m_PathID + "\r\n";
|
||||
str += "UInt8 m_Enabled = " + m_Enabled + "\r\n";
|
||||
str += "PPtr<MonoScript> m_Script\r\n";
|
||||
str += "\tint m_FileID = " + m_Script.m_FileID + "\r\n";
|
||||
str += "\tint64 m_PathID = " + m_Script.m_PathID + "\r\n";
|
||||
str += "string m_Name = \"" + m_Name + "\"\r\n";
|
||||
serializedText = str;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
preloadData.extension = ".txt";
|
||||
preloadData.Text = m_Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
UnityStudio/Classes/MovieTexture.cs
Normal file
36
UnityStudio/Classes/MovieTexture.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
class MovieTexture
|
||||
{
|
||||
public string m_Name;
|
||||
public byte[] m_MovieData;
|
||||
|
||||
public MovieTexture(AssetPreloadData preloadData, bool readSwitch)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
if (readSwitch)
|
||||
{
|
||||
var m_Loop = reader.ReadBoolean();
|
||||
reader.AlignStream(4);
|
||||
//PPtr<AudioClip>
|
||||
sourceFile.ReadPPtr();
|
||||
var size = reader.ReadInt32();
|
||||
m_MovieData = reader.ReadBytes(size);
|
||||
var m_ColorSpace = reader.ReadInt32();
|
||||
}
|
||||
else
|
||||
{
|
||||
preloadData.extension = ".ogv";
|
||||
preloadData.Text = m_Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
56
UnityStudio/Classes/PlayerSettings.cs
Normal file
56
UnityStudio/Classes/PlayerSettings.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
public class PlayerSettings
|
||||
{
|
||||
public string companyName;
|
||||
public string productName;
|
||||
|
||||
public PlayerSettings(AssetPreloadData preloadData)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
|
||||
if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 4) || sourceFile.version[0] > 5)//5.4.0 nad up
|
||||
{
|
||||
//productGUID
|
||||
reader.ReadInt32();
|
||||
reader.ReadInt32();
|
||||
reader.ReadInt32();
|
||||
reader.ReadInt32();
|
||||
}
|
||||
if (sourceFile.version[0] >= 3)
|
||||
{
|
||||
if (sourceFile.version[0] == 3 && sourceFile.version[1] < 2) { string AndroidLicensePublicKey = reader.ReadAlignedString(reader.ReadInt32()); }
|
||||
else { bool AndroidProfiler = reader.ReadBoolean(); reader.AlignStream(4); }
|
||||
|
||||
int defaultScreenOrientation = reader.ReadInt32();
|
||||
int targetDevice = reader.ReadInt32();
|
||||
|
||||
if (sourceFile.version[0] < 5 || (sourceFile.version[0] == 5 && sourceFile.version[1] < 1))
|
||||
{ int targetGlesGraphics = reader.ReadInt32(); }
|
||||
|
||||
if ((sourceFile.version[0] == 5 && sourceFile.version[1] < 1) || (sourceFile.version[0] == 4 && sourceFile.version[1] == 6 && sourceFile.version[2] >= 3))
|
||||
{ int targetIOSGraphics = reader.ReadInt32(); }
|
||||
|
||||
if (sourceFile.version[0] >= 5 || sourceFile.version[0] == 5 && (sourceFile.version[1] > 2 || (sourceFile.version[1] == 2 && sourceFile.version[2] >= 1)))
|
||||
{ bool useOnDemandResources = reader.ReadBoolean(); reader.AlignStream(4); }
|
||||
|
||||
if (sourceFile.version[0] < 5 || (sourceFile.version[0] == 5 && sourceFile.version[1] < 3))
|
||||
{ int targetResolution = reader.ReadInt32(); }
|
||||
|
||||
if (sourceFile.version[0] == 3 && sourceFile.version[1] <= 1) { bool OverrideIPodMusic = reader.ReadBoolean(); reader.AlignStream(4); }
|
||||
else if (sourceFile.version[0] == 3 && sourceFile.version[1] <= 4) { }
|
||||
else { int accelerometerFrequency = reader.ReadInt32(); }//3.5.0 and up
|
||||
}
|
||||
//fail in Unity 5 beta
|
||||
companyName = reader.ReadAlignedString(reader.ReadInt32());
|
||||
productName = reader.ReadAlignedString(reader.ReadInt32());
|
||||
}
|
||||
}
|
||||
}
|
||||
30
UnityStudio/Classes/RectTransform.cs
Normal file
30
UnityStudio/Classes/RectTransform.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
public class RectTransform
|
||||
{
|
||||
public Transform m_Transform;
|
||||
|
||||
public RectTransform(AssetPreloadData preloadData)
|
||||
{
|
||||
m_Transform = new Transform(preloadData);
|
||||
|
||||
//var sourceFile = preloadData.sourceFile;
|
||||
//var a_Stream = preloadData.sourceFile.a_Stream;
|
||||
|
||||
/*
|
||||
float[2] AnchorsMin
|
||||
float[2] AnchorsMax
|
||||
float[2] Pivod
|
||||
float Width
|
||||
float Height
|
||||
float[2] ?
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
201
UnityStudio/Classes/Shader.cs
Normal file
201
UnityStudio/Classes/Shader.cs
Normal file
@@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Script.Serialization;
|
||||
using Lz4;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
class Shader
|
||||
{
|
||||
public string m_Name;
|
||||
public byte[] m_Script;
|
||||
|
||||
public Shader(AssetPreloadData preloadData, bool readSwitch)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
if (sourceFile.platform == -2)
|
||||
{
|
||||
uint m_ObjectHideFlags = reader.ReadUInt32();
|
||||
PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
|
||||
PPtr m_PrefabInternal = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
|
||||
if (readSwitch)
|
||||
{
|
||||
if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 5 || sourceFile.version[0] > 5)//5.5.0 and up
|
||||
{
|
||||
var str = (string)ShaderResource.ResourceManager.GetObject($"Shader{sourceFile.version[0]}{sourceFile.version[1]}");
|
||||
if (str == null)
|
||||
{
|
||||
str = preloadData.ViewStruct();
|
||||
if (str == null)
|
||||
m_Script = Encoding.UTF8.GetBytes("Serialized Shader can't be read");
|
||||
else
|
||||
m_Script = Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
reader.Position = preloadData.Offset;
|
||||
var sb = new StringBuilder();
|
||||
var members = new JavaScriptSerializer().Deserialize<List<ClassMember>>(str);
|
||||
ClassStructHelper.ReadClassStruct(sb, members, reader);
|
||||
m_Script = Encoding.UTF8.GetBytes(sb.ToString());
|
||||
//m_Script = ReadSerializedShader(members, a_Stream);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Script = reader.ReadBytes(reader.ReadInt32());
|
||||
if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 3) //5.3 - 5.4
|
||||
{
|
||||
reader.AlignStream(4);
|
||||
reader.ReadAlignedString(reader.ReadInt32());//m_PathName
|
||||
var decompressedSize = reader.ReadUInt32();
|
||||
var m_SubProgramBlob = reader.ReadBytes(reader.ReadInt32());
|
||||
var decompressedBytes = new byte[decompressedSize];
|
||||
using (var decoder = new Lz4DecoderStream(new MemoryStream(m_SubProgramBlob)))
|
||||
{
|
||||
decoder.Read(decompressedBytes, 0, (int)decompressedSize);
|
||||
}
|
||||
m_Script = m_Script.Concat(decompressedBytes.ToArray()).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
preloadData.extension = ".txt";
|
||||
preloadData.Text = m_Name;
|
||||
}
|
||||
}
|
||||
|
||||
/*private static byte[] ReadSerializedShader(List<ClassMember> members, EndianBinaryReader a_Stream)
|
||||
{
|
||||
var offsets = new List<uint>();
|
||||
var compressedLengths = new List<uint>();
|
||||
var decompressedLengths = new List<uint>();
|
||||
for (int i = 0; i < members.Count; i++)
|
||||
{
|
||||
var member = members[i];
|
||||
var level = member.Level;
|
||||
var varTypeStr = member.Type;
|
||||
if (member.Name == "offsets")
|
||||
{
|
||||
var offsets_size = a_Stream.ReadInt32();
|
||||
for (int j = 0; j < offsets_size; j++)
|
||||
{
|
||||
offsets.Add(a_Stream.ReadUInt32());
|
||||
}
|
||||
var compressedLengths_size = a_Stream.ReadInt32();
|
||||
for (int j = 0; j < compressedLengths_size; j++)
|
||||
{
|
||||
compressedLengths.Add(a_Stream.ReadUInt32());
|
||||
}
|
||||
var decompressedLengths_size = a_Stream.ReadInt32();
|
||||
for (int j = 0; j < decompressedLengths_size; j++)
|
||||
{
|
||||
decompressedLengths.Add(a_Stream.ReadUInt32());
|
||||
}
|
||||
var compressedBlob = a_Stream.ReadBytes(a_Stream.ReadInt32());
|
||||
var decompressedStream = new MemoryStream();
|
||||
for (int j = 0; j < offsets.Count; j++)
|
||||
{
|
||||
var compressedBytes = new byte[compressedLengths[j]];
|
||||
Array.Copy(compressedBlob, offsets[j], compressedBytes, 0, compressedLengths[j]);
|
||||
var decompressedBytes = new byte[decompressedLengths[j]];
|
||||
using (var mstream = new MemoryStream(compressedBytes))
|
||||
{
|
||||
var decoder = new Lz4DecoderStream(mstream);
|
||||
decoder.Read(decompressedBytes, 0, (int)decompressedLengths[j]);
|
||||
decoder.Dispose();
|
||||
}
|
||||
decompressedStream.Write(decompressedBytes, 0, decompressedBytes.Length);
|
||||
}
|
||||
var decompressedBlob = decompressedStream.ToArray();
|
||||
return decompressedBlob;
|
||||
}
|
||||
var align = (member.Flag & 0x4000) != 0;
|
||||
if (member.alignBefore)
|
||||
a_Stream.AlignStream(4);
|
||||
if (varTypeStr == "SInt8")//sbyte
|
||||
{
|
||||
a_Stream.ReadSByte();
|
||||
}
|
||||
else if (varTypeStr == "UInt8")//byte
|
||||
{
|
||||
a_Stream.ReadByte();
|
||||
}
|
||||
else if (varTypeStr == "short" || varTypeStr == "SInt16")//Int16
|
||||
{
|
||||
a_Stream.ReadInt16();
|
||||
}
|
||||
else if (varTypeStr == "UInt16" || varTypeStr == "unsigned short")//UInt16
|
||||
{
|
||||
a_Stream.ReadUInt16();
|
||||
}
|
||||
else if (varTypeStr == "int" || varTypeStr == "SInt32")//Int32
|
||||
{
|
||||
a_Stream.ReadInt32();
|
||||
}
|
||||
else if (varTypeStr == "UInt32" || varTypeStr == "unsigned int" || varTypeStr == "Type*")//UInt32
|
||||
{
|
||||
a_Stream.ReadUInt32();
|
||||
}
|
||||
else if (varTypeStr == "long long" || varTypeStr == "SInt64")//Int64
|
||||
{
|
||||
a_Stream.ReadInt64();
|
||||
}
|
||||
else if (varTypeStr == "UInt64" || varTypeStr == "unsigned long long")//UInt64
|
||||
{
|
||||
a_Stream.ReadUInt64();
|
||||
}
|
||||
else if (varTypeStr == "float")//float
|
||||
{
|
||||
a_Stream.ReadSingle();
|
||||
}
|
||||
else if (varTypeStr == "double")//double
|
||||
{
|
||||
a_Stream.ReadDouble();
|
||||
}
|
||||
else if (varTypeStr == "bool")//bool
|
||||
{
|
||||
a_Stream.ReadBoolean();
|
||||
}
|
||||
else if (varTypeStr == "string")//string
|
||||
{
|
||||
a_Stream.ReadAlignedString(a_Stream.ReadInt32());
|
||||
i += 3;//skip
|
||||
}
|
||||
else if (varTypeStr == "Array")//Array
|
||||
{
|
||||
if ((members[i - 1].Flag & 0x4000) != 0)
|
||||
align = true;
|
||||
var size = a_Stream.ReadInt32();
|
||||
var array = ClassStructHelper.ReadArray(members, level, i);
|
||||
for (int j = 0; j < size; j++)
|
||||
{
|
||||
ReadSerializedShader(array, a_Stream);
|
||||
}
|
||||
i += array.Count + 1;//skip
|
||||
}
|
||||
else
|
||||
{
|
||||
if (align)
|
||||
{
|
||||
align = false;
|
||||
ClassStructHelper.SetAlignBefore(members, level, i + 1);
|
||||
}
|
||||
}
|
||||
if (align)
|
||||
a_Stream.AlignStream(4);
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
150
UnityStudio/Classes/SkinnedMeshRenderer.cs
Normal file
150
UnityStudio/Classes/SkinnedMeshRenderer.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
public class SkinnedMeshRenderer
|
||||
{
|
||||
public PPtr m_GameObject;
|
||||
public bool m_Enabled;
|
||||
public byte m_CastShadows;
|
||||
public bool m_ReceiveShadows;
|
||||
public ushort m_LightmapIndex;
|
||||
public ushort m_LightmapIndexDynamic;
|
||||
public PPtr[] m_Materials;
|
||||
public PPtr m_Mesh;
|
||||
public PPtr[] m_Bones;
|
||||
|
||||
public SkinnedMeshRenderer(AssetPreloadData preloadData)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var version = preloadData.sourceFile.version;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
if (sourceFile.platform == -2)
|
||||
{
|
||||
uint m_ObjectHideFlags = reader.ReadUInt32();
|
||||
PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
|
||||
PPtr m_PrefabInternal = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
m_GameObject = sourceFile.ReadPPtr();
|
||||
if (sourceFile.version[0] < 5)
|
||||
{
|
||||
m_Enabled = reader.ReadBoolean();
|
||||
m_CastShadows = reader.ReadByte();//bool
|
||||
m_ReceiveShadows = reader.ReadBoolean();
|
||||
m_LightmapIndex = reader.ReadByte();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Enabled = reader.ReadBoolean();
|
||||
reader.AlignStream(4);
|
||||
m_CastShadows = reader.ReadByte();
|
||||
m_ReceiveShadows = reader.ReadBoolean();
|
||||
reader.AlignStream(4);
|
||||
|
||||
m_LightmapIndex = reader.ReadUInt16();
|
||||
m_LightmapIndexDynamic = reader.ReadUInt16();
|
||||
}
|
||||
|
||||
if (version[0] >= 3) { reader.Position += 16; } //m_LightmapTilingOffset vector4d
|
||||
if (sourceFile.version[0] >= 5) { reader.Position += 16; } //Vector4f m_LightmapTilingOffsetDynamic
|
||||
|
||||
m_Materials = new PPtr[reader.ReadInt32()];
|
||||
for (int m = 0; m < m_Materials.Length; m++)
|
||||
{
|
||||
m_Materials[m] = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
if (version[0] < 3)
|
||||
{
|
||||
reader.Position += 16;//m_LightmapTilingOffset vector4d
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 5) || sourceFile.version[0] > 5)//5.5.0 and up
|
||||
{
|
||||
reader.Position += 4;//m_StaticBatchInfo
|
||||
}
|
||||
else
|
||||
{
|
||||
int m_SubsetIndices_size = reader.ReadInt32();
|
||||
reader.Position += m_SubsetIndices_size * 4;
|
||||
}
|
||||
PPtr m_StaticBatchRoot = sourceFile.ReadPPtr();
|
||||
|
||||
if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 4) || sourceFile.version[0] > 5)//5.4.0 and up
|
||||
{
|
||||
PPtr m_ProbeAnchor = sourceFile.ReadPPtr();
|
||||
PPtr m_LightProbeVolumeOverride = sourceFile.ReadPPtr();
|
||||
}
|
||||
else if (version[0] >= 4 || (version[0] == 3 && version[1] >= 5))
|
||||
{
|
||||
bool m_UseLightProbes = reader.ReadBoolean();
|
||||
reader.Position += 3; //alignment
|
||||
if (version[0] == 5) { int m_ReflectionProbeUsage = reader.ReadInt32(); }
|
||||
//did I ever check if the anchor is conditioned by the bool?
|
||||
PPtr m_LightProbeAnchor = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
if (version[0] >= 5 || (version[0] == 4 && version[1] >= 3))
|
||||
{
|
||||
if (version[0] == 4 && version[1] <= 3) { int m_SortingLayer = reader.ReadInt16(); }
|
||||
else { int m_SortingLayer = reader.ReadInt32(); }
|
||||
|
||||
int m_SortingOrder = reader.ReadInt16();
|
||||
reader.AlignStream(4);
|
||||
}
|
||||
}
|
||||
|
||||
int m_Quality = reader.ReadInt32();
|
||||
bool m_UpdateWhenOffscreen = reader.ReadBoolean();
|
||||
bool m_SkinNormals = reader.ReadBoolean(); //3.1.0 and below
|
||||
reader.Position += 2;
|
||||
|
||||
if (version[0] == 2 && version[1] < 6)
|
||||
{
|
||||
//this would be the only error if mainVersion is not read in time for a unity 2.x game
|
||||
PPtr m_DisableAnimationWhenOffscreen = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
m_Mesh = sourceFile.ReadPPtr();
|
||||
|
||||
m_Bones = new PPtr[reader.ReadInt32()];
|
||||
for (int b = 0; b < m_Bones.Length; b++)
|
||||
{
|
||||
m_Bones[b] = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
if (version[0] < 3)
|
||||
{
|
||||
int m_BindPose = reader.ReadInt32();
|
||||
reader.Position += m_BindPose * 16 * 4;//Matrix4x4f
|
||||
}
|
||||
else
|
||||
{
|
||||
if (version[0] > 4 || (version[0] == 4 && version[1] >= 3))
|
||||
{
|
||||
int m_BlendShapeWeights = reader.ReadInt32();
|
||||
reader.Position += m_BlendShapeWeights * 4; //floats
|
||||
}
|
||||
|
||||
if (version[0] > 4 || (version[0] >= 3 && version[1] >= 5))
|
||||
{
|
||||
PPtr m_RootBone = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
if (version[0] > 4 || (version[0] == 3 && version[1] >= 4))
|
||||
{
|
||||
//AABB
|
||||
float[] m_Center = { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() };
|
||||
float[] m_Extent = { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() };
|
||||
bool m_DirtyAABB = reader.ReadBoolean();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
169
UnityStudio/Classes/Sprite.cs
Normal file
169
UnityStudio/Classes/Sprite.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
class Sprite
|
||||
{
|
||||
public string m_Name;
|
||||
public RectangleF m_Rect;
|
||||
public float m_PixelsToUnits;
|
||||
public PointF m_Pivot;
|
||||
public Guid first;
|
||||
public PPtr texture;
|
||||
public PPtr m_SpriteAtlas;
|
||||
public RectangleF textureRect;
|
||||
public PointF[][] m_PhysicsShape;
|
||||
|
||||
public Sprite(AssetPreloadData preloadData, bool readSwitch)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
var version = sourceFile.version;
|
||||
|
||||
m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
if (readSwitch)
|
||||
{
|
||||
//Rectf m_Rect
|
||||
m_Rect = new RectangleF(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
|
||||
//Vector2f m_Offset
|
||||
reader.Position += 8;
|
||||
if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
|
||||
{
|
||||
//Vector4f m_Border
|
||||
reader.Position += 16;
|
||||
}
|
||||
|
||||
m_PixelsToUnits = reader.ReadSingle();
|
||||
if (version[0] > 5
|
||||
|| (version[0] == 5 && version[1] > 4)
|
||||
|| (version[0] == 5 && version[1] == 4 && version[2] >= 2)) //5.4.2 and up
|
||||
{
|
||||
//Vector2f m_Pivot
|
||||
m_Pivot = new PointF(reader.ReadSingle(), reader.ReadSingle());
|
||||
}
|
||||
|
||||
var m_Extrude = reader.ReadUInt32();
|
||||
if (version[0] > 5 || (version[0] == 5 && version[1] >= 3)) //5.3 and up TODO need more test
|
||||
{
|
||||
var m_IsPolygon = reader.ReadBoolean();
|
||||
reader.AlignStream(4);
|
||||
}
|
||||
|
||||
if (version[0] >= 2017) //2017 and up
|
||||
{
|
||||
//pair m_RenderDataKey
|
||||
first = new Guid(reader.ReadBytes(16));
|
||||
var second = reader.ReadInt64();
|
||||
//vector m_AtlasTags
|
||||
var size = reader.ReadInt32();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var data = reader.ReadAlignedString(reader.ReadInt32());
|
||||
}
|
||||
|
||||
//PPtr<SpriteAtlas> m_SpriteAtlas
|
||||
m_SpriteAtlas = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
//SpriteRenderData m_RD
|
||||
// PPtr<Texture2D> texture
|
||||
texture = sourceFile.ReadPPtr();
|
||||
// PPtr<Texture2D> alphaTexture
|
||||
if (version[0] >= 5) //5.0 and up
|
||||
{
|
||||
var alphaTexture = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up
|
||||
{
|
||||
// vector m_SubMeshes
|
||||
var size = reader.ReadInt32();
|
||||
// SubMesh data
|
||||
if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 3)) //2017.3 and up
|
||||
{
|
||||
reader.Position += 48 * size;
|
||||
}
|
||||
else
|
||||
{
|
||||
reader.Position += 44 * size;
|
||||
}
|
||||
|
||||
// vector m_IndexBuffer
|
||||
size = reader.ReadInt32();
|
||||
reader.Position += size; //UInt8 data
|
||||
reader.AlignStream(4);
|
||||
// VertexData m_VertexData
|
||||
var m_CurrentChannels = reader.ReadInt32();
|
||||
var m_VertexCount = reader.ReadUInt32();
|
||||
// vector m_Channels
|
||||
size = reader.ReadInt32();
|
||||
reader.Position += size * 4; //ChannelInfo data
|
||||
// TypelessData m_DataSize
|
||||
size = reader.ReadInt32();
|
||||
reader.Position += size; //UInt8 data
|
||||
reader.AlignStream(4);
|
||||
}
|
||||
else
|
||||
{
|
||||
// vector vertices
|
||||
var size = reader.ReadInt32();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
//SpriteVertex data
|
||||
reader.Position += 12; //Vector3f pos
|
||||
if (version[0] < 4 || (version[0] == 4 && version[1] <= 3)) //4.3 and down
|
||||
reader.Position += 8; //Vector2f uv
|
||||
}
|
||||
|
||||
// vector indices
|
||||
size = reader.ReadInt32();
|
||||
reader.Position += 2 * size; //UInt16 data
|
||||
reader.AlignStream(4);
|
||||
}
|
||||
|
||||
// Rectf textureRect
|
||||
textureRect = new RectangleF(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
|
||||
// Vector2f textureRectOffset
|
||||
reader.Position += 8;
|
||||
// Vector2f atlasRectOffset - 5.6 and up
|
||||
if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up
|
||||
{
|
||||
reader.Position += 8;
|
||||
}
|
||||
// unsigned int settingsRaw
|
||||
reader.Position += 4;
|
||||
// Vector4f uvTransform - 4.5 and up
|
||||
if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
|
||||
{
|
||||
reader.Position += 16;
|
||||
}
|
||||
if (version[0] >= 2017) //2017 and up
|
||||
{
|
||||
// float downscaleMultiplier - 2017 and up
|
||||
reader.Position += 4;
|
||||
//vector m_PhysicsShape - 2017 and up
|
||||
var m_PhysicsShape_size = reader.ReadInt32();
|
||||
m_PhysicsShape = new PointF[m_PhysicsShape_size][];
|
||||
for (int i = 0; i < m_PhysicsShape_size; i++)
|
||||
{
|
||||
var data_size = reader.ReadInt32();
|
||||
//Vector2f
|
||||
m_PhysicsShape[i] = new PointF[data_size];
|
||||
for (int j = 0; j < data_size; j++)
|
||||
{
|
||||
m_PhysicsShape[i][j] = new PointF(reader.ReadSingle(), reader.ReadSingle());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
preloadData.Text = m_Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
65
UnityStudio/Classes/SpriteAtlas.cs
Normal file
65
UnityStudio/Classes/SpriteAtlas.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
class SpriteAtlas
|
||||
{
|
||||
public List<PPtr> textures = new List<PPtr>();
|
||||
public List<RectangleF> textureRects = new List<RectangleF>();
|
||||
public List<Guid> guids = new List<Guid>();
|
||||
|
||||
|
||||
public SpriteAtlas(AssetPreloadData preloadData)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
var m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
//vector m_PackedSprites
|
||||
var size = reader.ReadInt32();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
//PPtr<Sprite> data
|
||||
sourceFile.ReadPPtr();
|
||||
}
|
||||
//vector m_PackedSpriteNamesToIndex
|
||||
size = reader.ReadInt32();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var data = reader.ReadAlignedString(reader.ReadInt32());
|
||||
}
|
||||
//map m_RenderDataMap
|
||||
size = reader.ReadInt32();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
//pair first
|
||||
guids.Add(new Guid(reader.ReadBytes(16)));
|
||||
var second = reader.ReadInt64();
|
||||
//SpriteAtlasData second
|
||||
// PPtr<Texture2D> texture
|
||||
textures.Add(sourceFile.ReadPPtr());
|
||||
// PPtr<Texture2D> alphaTexture
|
||||
var alphaTexture = sourceFile.ReadPPtr();
|
||||
// Rectf textureRect
|
||||
textureRects.Add(new RectangleF(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
|
||||
// Vector2f textureRectOffset
|
||||
reader.Position += 8;
|
||||
if (sourceFile.version[0] > 2017 || (sourceFile.version[0] == 2017 && sourceFile.version[1] >= 2))//2017.2 and up
|
||||
{
|
||||
// Vector2f atlasRectOffset
|
||||
reader.Position += 8;
|
||||
}
|
||||
// Vector4f uvTransform
|
||||
// float downscaleMultiplier
|
||||
// unsigned int settingsRaw
|
||||
reader.Position += 24;
|
||||
}
|
||||
//string m_Tag
|
||||
//bool m_IsVariant
|
||||
}
|
||||
}
|
||||
}
|
||||
39
UnityStudio/Classes/TextAsset.cs
Normal file
39
UnityStudio/Classes/TextAsset.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
class TextAsset
|
||||
{
|
||||
public string m_Name;
|
||||
public byte[] m_Script;
|
||||
|
||||
public TextAsset(AssetPreloadData preloadData, bool readSwitch)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
if (sourceFile.platform == -2)
|
||||
{
|
||||
uint m_ObjectHideFlags = reader.ReadUInt32();
|
||||
PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
|
||||
PPtr m_PrefabInternal = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
|
||||
if (readSwitch)
|
||||
{
|
||||
m_Script = reader.ReadBytes(reader.ReadInt32());
|
||||
}
|
||||
else
|
||||
{
|
||||
preloadData.extension = ".txt";
|
||||
preloadData.Text = m_Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
778
UnityStudio/Classes/Texture2D.cs
Normal file
778
UnityStudio/Classes/Texture2D.cs
Normal file
@@ -0,0 +1,778 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
partial class Texture2D
|
||||
{
|
||||
public string m_Name;
|
||||
public int m_Width;
|
||||
public int m_Height;
|
||||
public int m_CompleteImageSize;
|
||||
public TextureFormat m_TextureFormat;
|
||||
public bool m_MipMap;
|
||||
public bool m_IsReadable;
|
||||
public bool m_ReadAllowed;
|
||||
public int m_ImageCount;
|
||||
public int m_TextureDimension;
|
||||
//m_TextureSettings
|
||||
public int m_FilterMode;
|
||||
public int m_Aniso;
|
||||
public float m_MipBias;
|
||||
public int m_WrapMode;
|
||||
public int m_LightmapFormat;
|
||||
public int m_ColorSpace;
|
||||
//image dataa
|
||||
public int image_data_size;
|
||||
public byte[] image_data;
|
||||
//m_StreamData
|
||||
public uint offset;
|
||||
public uint size;
|
||||
public string path;
|
||||
|
||||
//DDS Start
|
||||
private byte[] dwMagic = { 0x44, 0x44, 0x53, 0x20, 0x7c };
|
||||
private int dwFlags = 0x1 + 0x2 + 0x4 + 0x1000;
|
||||
//public int dwHeight; m_Height
|
||||
//public int dwWidth; m_Width
|
||||
private int dwPitchOrLinearSize;
|
||||
private int dwMipMapCount = 0x1;
|
||||
private int dwSize = 0x20;
|
||||
private int dwFlags2;
|
||||
private int dwFourCC;
|
||||
private int dwRGBBitCount;
|
||||
private int dwRBitMask;
|
||||
private int dwGBitMask;
|
||||
private int dwBBitMask;
|
||||
private int dwABitMask;
|
||||
private int dwCaps = 0x1000;
|
||||
private int dwCaps2 = 0x0;
|
||||
//DDS End
|
||||
//PVR Start
|
||||
private int pvrVersion = 0x03525650;
|
||||
private int pvrFlags = 0x0;
|
||||
private long pvrPixelFormat;
|
||||
private int pvrColourSpace = 0x0;
|
||||
private int pvrChannelType = 0x0;
|
||||
//public int pvrHeight; m_Height
|
||||
//public int pvrWidth; m_Width
|
||||
private int pvrDepth = 0x1;
|
||||
private int pvrNumSurfaces = 0x1; //For texture arrays
|
||||
private int pvrNumFaces = 0x1; //For cube maps
|
||||
//public int pvrMIPMapCount; dwMipMapCount
|
||||
private int pvrMetaDataSize = 0x0;
|
||||
//PVR End
|
||||
//KTX Start
|
||||
private int glType = 0;
|
||||
private int glTypeSize = 1;
|
||||
private int glFormat = 0;
|
||||
private int glInternalFormat;
|
||||
private int glBaseInternalFormat;
|
||||
//public int pixelWidth; m_Width
|
||||
//public int pixelHeight; m_Height
|
||||
private int pixelDepth = 0;
|
||||
private int numberOfArrayElements = 0;
|
||||
private int numberOfFaces = 1;
|
||||
private int numberOfMipmapLevels = 1;
|
||||
private int bytesOfKeyValueData = 0;
|
||||
//KTX End
|
||||
//TextureConverter
|
||||
private QFORMAT q_format;
|
||||
//texgenpack
|
||||
private texgenpack_texturetype texturetype;
|
||||
|
||||
private int[] version;
|
||||
|
||||
public Texture2D(AssetPreloadData preloadData, bool readSwitch)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
version = sourceFile.version;
|
||||
|
||||
if (sourceFile.platform == -2)
|
||||
{
|
||||
uint m_ObjectHideFlags = reader.ReadUInt32();
|
||||
PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
|
||||
PPtr m_PrefabInternal = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 3))//2017.3 and up
|
||||
{
|
||||
var m_ForcedFallbackFormat = reader.ReadInt32();
|
||||
var m_DownscaleFallback = reader.ReadBoolean();
|
||||
reader.AlignStream(4);
|
||||
}
|
||||
m_Width = reader.ReadInt32();
|
||||
m_Height = reader.ReadInt32();
|
||||
m_CompleteImageSize = reader.ReadInt32();
|
||||
m_TextureFormat = (TextureFormat)reader.ReadInt32();
|
||||
|
||||
if (version[0] < 5 || (version[0] == 5 && version[1] < 2))
|
||||
{ m_MipMap = reader.ReadBoolean(); }
|
||||
else
|
||||
{
|
||||
dwFlags += 0x20000;
|
||||
dwMipMapCount = reader.ReadInt32();//is this with or without main image?
|
||||
dwCaps += 0x400008;
|
||||
}
|
||||
|
||||
m_IsReadable = reader.ReadBoolean(); //2.6.0 and up
|
||||
m_ReadAllowed = reader.ReadBoolean(); //3.0.0 - 5.4
|
||||
reader.AlignStream(4);
|
||||
|
||||
m_ImageCount = reader.ReadInt32();
|
||||
m_TextureDimension = reader.ReadInt32();
|
||||
//m_TextureSettings
|
||||
m_FilterMode = reader.ReadInt32();
|
||||
m_Aniso = reader.ReadInt32();
|
||||
m_MipBias = reader.ReadSingle();
|
||||
m_WrapMode = reader.ReadInt32();
|
||||
if (version[0] >= 2017)//2017.x and up
|
||||
{
|
||||
int m_WrapV = reader.ReadInt32();
|
||||
int m_WrapW = reader.ReadInt32();
|
||||
}
|
||||
if (version[0] >= 3)
|
||||
{
|
||||
m_LightmapFormat = reader.ReadInt32();
|
||||
if (version[0] >= 4 || version[1] >= 5) { m_ColorSpace = reader.ReadInt32(); } //3.5.0 and up
|
||||
}
|
||||
|
||||
image_data_size = reader.ReadInt32();
|
||||
|
||||
if (m_MipMap)
|
||||
{
|
||||
dwFlags += 0x20000;
|
||||
dwMipMapCount = Convert.ToInt32(Math.Log(Math.Max(m_Width, m_Height)) / Math.Log(2));
|
||||
dwCaps += 0x400008;
|
||||
}
|
||||
|
||||
if (image_data_size == 0 && ((version[0] == 5 && version[1] >= 3) || version[0] > 5))//5.3.0 and up
|
||||
{
|
||||
offset = reader.ReadUInt32();
|
||||
size = reader.ReadUInt32();
|
||||
image_data_size = (int)size;
|
||||
path = reader.ReadAlignedString(reader.ReadInt32());
|
||||
}
|
||||
|
||||
if (readSwitch)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
var resourceFileName = Path.GetFileName(path);
|
||||
var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
|
||||
if (!File.Exists(resourceFilePath))
|
||||
{
|
||||
var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
|
||||
if (findFiles.Length > 0)
|
||||
{
|
||||
resourceFilePath = findFiles[0];
|
||||
}
|
||||
}
|
||||
if (File.Exists(resourceFilePath))
|
||||
{
|
||||
using (var resourceReader = new BinaryReader(File.OpenRead(resourceFilePath)))
|
||||
{
|
||||
resourceReader.BaseStream.Position = offset;
|
||||
image_data = resourceReader.ReadBytes(image_data_size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Studio.resourceFileReaders.TryGetValue(resourceFileName.ToUpper(), out var resourceReader))
|
||||
{
|
||||
resourceReader.Position = offset;
|
||||
image_data = resourceReader.ReadBytes(image_data_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show($"can't find the resource file {resourceFileName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
image_data = reader.ReadBytes(image_data_size);
|
||||
}
|
||||
|
||||
switch (m_TextureFormat)
|
||||
{
|
||||
//TODO 导出到DDS容器时应该用原像素还是转换以后的像素?
|
||||
case TextureFormat.Alpha8: //test pass
|
||||
{
|
||||
/*dwFlags2 = 0x2;
|
||||
dwRGBBitCount = 0x8;
|
||||
dwRBitMask = 0x0;
|
||||
dwGBitMask = 0x0;
|
||||
dwBBitMask = 0x0;
|
||||
dwABitMask = 0xFF; */
|
||||
|
||||
//转BGRA32
|
||||
var BGRA32 = Enumerable.Repeat<byte>(0xFF, image_data_size * 4).ToArray();
|
||||
for (var i = 0; i < image_data_size; i++)
|
||||
{
|
||||
BGRA32[i * 4 + 3] = image_data[i];
|
||||
}
|
||||
SetBGRA32Info(BGRA32);
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ARGB4444: //test pass
|
||||
{
|
||||
SwapBytesForXbox(sourceFile.platform);
|
||||
|
||||
/*dwFlags2 = 0x41;
|
||||
dwRGBBitCount = 0x10;
|
||||
dwRBitMask = 0xF00;
|
||||
dwGBitMask = 0xF0;
|
||||
dwBBitMask = 0xF;
|
||||
dwABitMask = 0xF000;*/
|
||||
|
||||
//转BGRA32
|
||||
var BGRA32 = new byte[image_data_size * 2];
|
||||
for (var i = 0; i < image_data_size / 2; i++)
|
||||
{
|
||||
var pixelNew = new byte[4];
|
||||
var pixelOldShort = BitConverter.ToUInt16(image_data, i * 2);
|
||||
pixelNew[0] = (byte)(pixelOldShort & 0x000f);
|
||||
pixelNew[1] = (byte)((pixelOldShort & 0x00f0) >> 4);
|
||||
pixelNew[2] = (byte)((pixelOldShort & 0x0f00) >> 8);
|
||||
pixelNew[3] = (byte)((pixelOldShort & 0xf000) >> 12);
|
||||
// convert range
|
||||
for (var j = 0; j < 4; j++)
|
||||
pixelNew[j] = (byte)((pixelNew[j] << 4) | pixelNew[j]);
|
||||
pixelNew.CopyTo(BGRA32, i * 4);
|
||||
}
|
||||
SetBGRA32Info(BGRA32);
|
||||
break;
|
||||
}
|
||||
case TextureFormat.RGB24: //test pass
|
||||
{
|
||||
/*dwFlags2 = 0x40;
|
||||
dwRGBBitCount = 0x18;
|
||||
dwRBitMask = 0xFF;
|
||||
dwGBitMask = 0xFF00;
|
||||
dwBBitMask = 0xFF0000;
|
||||
dwABitMask = 0x0;*/
|
||||
|
||||
//转BGRA32
|
||||
var BGRA32 = new byte[image_data_size / 3 * 4];
|
||||
for (var i = 0; i < image_data_size / 3; i++)
|
||||
{
|
||||
BGRA32[i * 4] = image_data[i * 3 + 2];
|
||||
BGRA32[i * 4 + 1] = image_data[i * 3 + 1];
|
||||
BGRA32[i * 4 + 2] = image_data[i * 3 + 0];
|
||||
BGRA32[i * 4 + 3] = 255;
|
||||
}
|
||||
SetBGRA32Info(BGRA32);
|
||||
break;
|
||||
}
|
||||
case TextureFormat.RGBA32: //test pass
|
||||
{
|
||||
/*dwFlags2 = 0x41;
|
||||
dwRGBBitCount = 0x20;
|
||||
dwRBitMask = 0xFF;
|
||||
dwGBitMask = 0xFF00;
|
||||
dwBBitMask = 0xFF0000;
|
||||
dwABitMask = -16777216;*/
|
||||
|
||||
//转BGRA32
|
||||
var BGRA32 = new byte[image_data_size];
|
||||
for (var i = 0; i < image_data_size; i += 4)
|
||||
{
|
||||
BGRA32[i] = image_data[i + 2];
|
||||
BGRA32[i + 1] = image_data[i + 1];
|
||||
BGRA32[i + 2] = image_data[i + 0];
|
||||
BGRA32[i + 3] = image_data[i + 3];
|
||||
}
|
||||
SetBGRA32Info(BGRA32);
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ARGB32://test pass
|
||||
{
|
||||
/*dwFlags2 = 0x41;
|
||||
dwRGBBitCount = 0x20;
|
||||
dwRBitMask = 0xFF00;
|
||||
dwGBitMask = 0xFF0000;
|
||||
dwBBitMask = -16777216;
|
||||
dwABitMask = 0xFF;*/
|
||||
|
||||
//转BGRA32
|
||||
var BGRA32 = new byte[image_data_size];
|
||||
for (var i = 0; i < image_data_size; i += 4)
|
||||
{
|
||||
BGRA32[i] = image_data[i + 3];
|
||||
BGRA32[i + 1] = image_data[i + 2];
|
||||
BGRA32[i + 2] = image_data[i + 1];
|
||||
BGRA32[i + 3] = image_data[i + 0];
|
||||
}
|
||||
SetBGRA32Info(BGRA32);
|
||||
break;
|
||||
}
|
||||
case TextureFormat.RGB565: //test pass
|
||||
{
|
||||
SwapBytesForXbox(sourceFile.platform);
|
||||
|
||||
dwFlags2 = 0x40;
|
||||
dwRGBBitCount = 0x10;
|
||||
dwRBitMask = 0xF800;
|
||||
dwGBitMask = 0x7E0;
|
||||
dwBBitMask = 0x1F;
|
||||
dwABitMask = 0x0;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.R16: //test pass
|
||||
{
|
||||
//转BGRA32
|
||||
var BGRA32 = new byte[image_data_size * 2];
|
||||
for (var i = 0; i < image_data_size; i += 2)
|
||||
{
|
||||
float f = Half.ToHalf(image_data, i);
|
||||
BGRA32[i * 2 + 2] = (byte)Math.Ceiling(f * 255);//R
|
||||
BGRA32[i * 2 + 3] = 255;//A
|
||||
}
|
||||
SetBGRA32Info(BGRA32);
|
||||
break;
|
||||
}
|
||||
case TextureFormat.DXT1: //test pass
|
||||
case TextureFormat.DXT1Crunched: //test pass
|
||||
{
|
||||
SwapBytesForXbox(sourceFile.platform);
|
||||
|
||||
if (m_MipMap) { dwPitchOrLinearSize = m_Height * m_Width / 2; }
|
||||
dwFlags2 = 0x4;
|
||||
dwFourCC = 0x31545844;
|
||||
dwRGBBitCount = 0x0;
|
||||
dwRBitMask = 0x0;
|
||||
dwGBitMask = 0x0;
|
||||
dwBBitMask = 0x0;
|
||||
dwABitMask = 0x0;
|
||||
|
||||
q_format = QFORMAT.Q_FORMAT_S3TC_DXT1_RGB;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.DXT5: //test pass
|
||||
case TextureFormat.DXT5Crunched: //test pass
|
||||
{
|
||||
SwapBytesForXbox(sourceFile.platform);
|
||||
|
||||
if (m_MipMap) { dwPitchOrLinearSize = m_Height * m_Width / 2; }
|
||||
dwFlags2 = 0x4;
|
||||
dwFourCC = 0x35545844;
|
||||
dwRGBBitCount = 0x0;
|
||||
dwRBitMask = 0x0;
|
||||
dwGBitMask = 0x0;
|
||||
dwBBitMask = 0x0;
|
||||
dwABitMask = 0x0;
|
||||
|
||||
q_format = QFORMAT.Q_FORMAT_S3TC_DXT5_RGBA;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.RGBA4444: //test pass
|
||||
{
|
||||
/*dwFlags2 = 0x41;
|
||||
dwRGBBitCount = 0x10;
|
||||
dwRBitMask = 0xF000;
|
||||
dwGBitMask = 0xF00;
|
||||
dwBBitMask = 0xF0;
|
||||
dwABitMask = 0xF;*/
|
||||
|
||||
//转BGRA32
|
||||
var BGRA32 = new byte[image_data_size * 2];
|
||||
for (var i = 0; i < image_data_size / 2; i++)
|
||||
{
|
||||
var pixelNew = new byte[4];
|
||||
var pixelOldShort = BitConverter.ToUInt16(image_data, i * 2);
|
||||
pixelNew[0] = (byte)((pixelOldShort & 0x00f0) >> 4);
|
||||
pixelNew[1] = (byte)((pixelOldShort & 0x0f00) >> 8);
|
||||
pixelNew[2] = (byte)((pixelOldShort & 0xf000) >> 12);
|
||||
pixelNew[3] = (byte)(pixelOldShort & 0x000f);
|
||||
// convert range
|
||||
for (var j = 0; j < 4; j++)
|
||||
pixelNew[j] = (byte)((pixelNew[j] << 4) | pixelNew[j]);
|
||||
pixelNew.CopyTo(BGRA32, i * 4);
|
||||
}
|
||||
SetBGRA32Info(BGRA32);
|
||||
break;
|
||||
}
|
||||
case TextureFormat.BGRA32: //test pass
|
||||
{
|
||||
dwFlags2 = 0x41;
|
||||
dwRGBBitCount = 0x20;
|
||||
dwRBitMask = 0xFF0000;
|
||||
dwGBitMask = 0xFF00;
|
||||
dwBBitMask = 0xFF;
|
||||
dwABitMask = -16777216;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.RHalf: //test pass
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_R_16F;
|
||||
glInternalFormat = KTXHeader.GL_R16F;
|
||||
glBaseInternalFormat = KTXHeader.GL_RED;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.RGHalf: //test pass
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_RG_HF;
|
||||
glInternalFormat = KTXHeader.GL_RG16F;
|
||||
glBaseInternalFormat = KTXHeader.GL_RG;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.RGBAHalf: //test pass
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_RGBA_HF;
|
||||
glInternalFormat = KTXHeader.GL_RGBA16F;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGBA;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.RFloat: //test pass
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_R_F;
|
||||
glInternalFormat = KTXHeader.GL_R32F;
|
||||
glBaseInternalFormat = KTXHeader.GL_RED;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.RGFloat: //test pass
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_RG_F;
|
||||
glInternalFormat = KTXHeader.GL_RG32F;
|
||||
glBaseInternalFormat = KTXHeader.GL_RG;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.RGBAFloat: //test pass
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_RGBA_F;
|
||||
glInternalFormat = KTXHeader.GL_RGBA32F;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGBA;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.YUY2: //test pass
|
||||
{
|
||||
pvrPixelFormat = 17;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.RGB9e5Float:
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_RGB9_E5;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.BC4: //test pass
|
||||
{
|
||||
texturetype = texgenpack_texturetype.RGTC1;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RED_RGTC1;
|
||||
glBaseInternalFormat = KTXHeader.GL_RED;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.BC5: //test pass
|
||||
{
|
||||
texturetype = texgenpack_texturetype.RGTC2;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RG_RGTC2;
|
||||
glBaseInternalFormat = KTXHeader.GL_RG;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.BC6H: //test pass
|
||||
{
|
||||
texturetype = texgenpack_texturetype.BPTC_FLOAT;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGB;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.BC7: //test pass
|
||||
{
|
||||
texturetype = texgenpack_texturetype.BPTC;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RGBA_BPTC_UNORM;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGBA;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.PVRTC_RGB2: //test pass
|
||||
{
|
||||
pvrPixelFormat = 0;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGB;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.PVRTC_RGBA2: //test pass
|
||||
{
|
||||
pvrPixelFormat = 1;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGBA;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.PVRTC_RGB4: //test pass
|
||||
{
|
||||
pvrPixelFormat = 2;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGB;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.PVRTC_RGBA4: //test pass
|
||||
{
|
||||
pvrPixelFormat = 3;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGBA;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ETC_RGB4Crunched:
|
||||
case TextureFormat.ETC_RGB4_3DS: //test pass
|
||||
case TextureFormat.ETC_RGB4: //test pass
|
||||
{
|
||||
pvrPixelFormat = 6;
|
||||
glInternalFormat = KTXHeader.GL_ETC1_RGB8_OES;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGB;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ATC_RGB4: //test pass
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_ATITC_RGB;
|
||||
glInternalFormat = KTXHeader.GL_ATC_RGB_AMD;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGB;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ATC_RGBA8: //test pass
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_ATC_RGBA_INTERPOLATED_ALPHA;
|
||||
glInternalFormat = KTXHeader.GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGBA;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.EAC_R: //test pass
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_EAC_R_UNSIGNED;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_R11_EAC;
|
||||
glBaseInternalFormat = KTXHeader.GL_RED;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.EAC_R_SIGNED: //test pass
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_EAC_R_SIGNED;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_SIGNED_R11_EAC;
|
||||
glBaseInternalFormat = KTXHeader.GL_RED;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.EAC_RG: //test pass
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_EAC_RG_UNSIGNED;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RG11_EAC;
|
||||
glBaseInternalFormat = KTXHeader.GL_RG;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.EAC_RG_SIGNED: //test pass
|
||||
{
|
||||
q_format = QFORMAT.Q_FORMAT_EAC_RG_SIGNED;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_SIGNED_RG11_EAC;
|
||||
glBaseInternalFormat = KTXHeader.GL_RG;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ETC2_RGB: //test pass
|
||||
{
|
||||
pvrPixelFormat = 22;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RGB8_ETC2;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGB;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ETC2_RGBA1: //test pass
|
||||
{
|
||||
pvrPixelFormat = 24;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGBA;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ETC2_RGBA8Crunched:
|
||||
case TextureFormat.ETC_RGBA8_3DS: //test pass
|
||||
case TextureFormat.ETC2_RGBA8: //test pass
|
||||
{
|
||||
pvrPixelFormat = 23;
|
||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RGBA8_ETC2_EAC;
|
||||
glBaseInternalFormat = KTXHeader.GL_RGBA;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ASTC_RGB_4x4: //test pass
|
||||
case TextureFormat.ASTC_RGBA_4x4: //test pass
|
||||
{
|
||||
pvrPixelFormat = 27;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ASTC_RGB_5x5: //test pass
|
||||
case TextureFormat.ASTC_RGBA_5x5: //test pass
|
||||
{
|
||||
pvrPixelFormat = 29;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ASTC_RGB_6x6: //test pass
|
||||
case TextureFormat.ASTC_RGBA_6x6: //test pass
|
||||
{
|
||||
pvrPixelFormat = 31;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ASTC_RGB_8x8: //test pass
|
||||
case TextureFormat.ASTC_RGBA_8x8: //test pass
|
||||
{
|
||||
pvrPixelFormat = 34;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ASTC_RGB_10x10: //test pass
|
||||
case TextureFormat.ASTC_RGBA_10x10: //test pass
|
||||
{
|
||||
pvrPixelFormat = 38;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.ASTC_RGB_12x12: //test pass
|
||||
case TextureFormat.ASTC_RGBA_12x12: //test pass
|
||||
{
|
||||
pvrPixelFormat = 40;
|
||||
break;
|
||||
}
|
||||
case TextureFormat.RG16: //test pass
|
||||
{
|
||||
//转BGRA32
|
||||
var BGRA32 = new byte[image_data_size * 2];
|
||||
for (var i = 0; i < image_data_size; i += 2)
|
||||
{
|
||||
BGRA32[i * 2 + 1] = image_data[i + 1];//G
|
||||
BGRA32[i * 2 + 2] = image_data[i];//R
|
||||
BGRA32[i * 2 + 3] = 255;//A
|
||||
}
|
||||
SetBGRA32Info(BGRA32);
|
||||
break;
|
||||
}
|
||||
case TextureFormat.R8: //test pass
|
||||
{
|
||||
//转BGRA32
|
||||
var BGRA32 = new byte[image_data_size * 4];
|
||||
for (var i = 0; i < image_data_size; i++)
|
||||
{
|
||||
BGRA32[i * 4 + 2] = image_data[i];//R
|
||||
BGRA32[i * 4 + 3] = 255;//A
|
||||
}
|
||||
SetBGRA32Info(BGRA32);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
preloadData.InfoText = $"Width: {m_Width}\nHeight: {m_Height}\nFormat: ";
|
||||
|
||||
string type = m_TextureFormat.ToString();
|
||||
preloadData.InfoText += type;
|
||||
|
||||
switch (m_TextureFormat)
|
||||
{
|
||||
case TextureFormat.Alpha8:
|
||||
case TextureFormat.ARGB4444:
|
||||
case TextureFormat.RGB24:
|
||||
case TextureFormat.RGBA32:
|
||||
case TextureFormat.ARGB32:
|
||||
case TextureFormat.RGB565:
|
||||
case TextureFormat.R16:
|
||||
case TextureFormat.DXT1:
|
||||
case TextureFormat.DXT5:
|
||||
case TextureFormat.RGBA4444:
|
||||
case TextureFormat.BGRA32:
|
||||
case TextureFormat.RG16:
|
||||
case TextureFormat.R8:
|
||||
preloadData.extension = ".dds"; break;
|
||||
case TextureFormat.DXT1Crunched:
|
||||
case TextureFormat.DXT5Crunched:
|
||||
case TextureFormat.ETC_RGB4Crunched:
|
||||
case TextureFormat.ETC2_RGBA8Crunched:
|
||||
preloadData.extension = ".crn"; break;
|
||||
case TextureFormat.YUY2:
|
||||
case TextureFormat.PVRTC_RGB2:
|
||||
case TextureFormat.PVRTC_RGBA2:
|
||||
case TextureFormat.PVRTC_RGB4:
|
||||
case TextureFormat.PVRTC_RGBA4:
|
||||
case TextureFormat.ETC_RGB4:
|
||||
case TextureFormat.ETC2_RGB:
|
||||
case TextureFormat.ETC2_RGBA1:
|
||||
case TextureFormat.ETC2_RGBA8:
|
||||
case TextureFormat.ASTC_RGB_4x4:
|
||||
case TextureFormat.ASTC_RGB_5x5:
|
||||
case TextureFormat.ASTC_RGB_6x6:
|
||||
case TextureFormat.ASTC_RGB_8x8:
|
||||
case TextureFormat.ASTC_RGB_10x10:
|
||||
case TextureFormat.ASTC_RGB_12x12:
|
||||
case TextureFormat.ASTC_RGBA_4x4:
|
||||
case TextureFormat.ASTC_RGBA_5x5:
|
||||
case TextureFormat.ASTC_RGBA_6x6:
|
||||
case TextureFormat.ASTC_RGBA_8x8:
|
||||
case TextureFormat.ASTC_RGBA_10x10:
|
||||
case TextureFormat.ASTC_RGBA_12x12:
|
||||
case TextureFormat.ETC_RGB4_3DS:
|
||||
case TextureFormat.ETC_RGBA8_3DS:
|
||||
preloadData.extension = ".pvr"; break;
|
||||
case TextureFormat.RHalf:
|
||||
case TextureFormat.RGHalf:
|
||||
case TextureFormat.RGBAHalf:
|
||||
case TextureFormat.RFloat:
|
||||
case TextureFormat.RGFloat:
|
||||
case TextureFormat.RGBAFloat:
|
||||
case TextureFormat.BC4:
|
||||
case TextureFormat.BC5:
|
||||
case TextureFormat.BC6H:
|
||||
case TextureFormat.BC7:
|
||||
case TextureFormat.ATC_RGB4:
|
||||
case TextureFormat.ATC_RGBA8:
|
||||
case TextureFormat.EAC_R:
|
||||
case TextureFormat.EAC_R_SIGNED:
|
||||
case TextureFormat.EAC_RG:
|
||||
case TextureFormat.EAC_RG_SIGNED:
|
||||
preloadData.extension = ".ktx"; break;
|
||||
default:
|
||||
preloadData.extension = ".tex"; break;
|
||||
}
|
||||
|
||||
switch (m_FilterMode)
|
||||
{
|
||||
case 0: preloadData.InfoText += "\nFilter Mode: Point "; break;
|
||||
case 1: preloadData.InfoText += "\nFilter Mode: Bilinear "; break;
|
||||
case 2: preloadData.InfoText += "\nFilter Mode: Trilinear "; break;
|
||||
|
||||
}
|
||||
|
||||
preloadData.InfoText += $"\nAnisotropic level: {m_Aniso}\nMip map bias: {m_MipBias}";
|
||||
|
||||
switch (m_WrapMode)
|
||||
{
|
||||
case 0: preloadData.InfoText += "\nWrap mode: Repeat"; break;
|
||||
case 1: preloadData.InfoText += "\nWrap mode: Clamp"; break;
|
||||
}
|
||||
|
||||
preloadData.Text = m_Name;
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
preloadData.fullSize = preloadData.Size + (int)size;
|
||||
}
|
||||
}
|
||||
|
||||
private void SwapBytesForXbox(int platform)
|
||||
{
|
||||
if (platform == 11) //swap bytes for Xbox confirmed, PS3 not encountered
|
||||
{
|
||||
for (var i = 0; i < image_data_size / 2; i++)
|
||||
{
|
||||
var b0 = image_data[i * 2];
|
||||
image_data[i * 2] = image_data[i * 2 + 1];
|
||||
image_data[i * 2 + 1] = b0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetBGRA32Info(byte[] BGRA32)
|
||||
{
|
||||
image_data = BGRA32;
|
||||
image_data_size = BGRA32.Length;
|
||||
dwFlags2 = 0x41;
|
||||
dwRGBBitCount = 0x20;
|
||||
dwRBitMask = 0xFF0000;
|
||||
dwGBitMask = 0xFF00;
|
||||
dwBBitMask = 0xFF;
|
||||
dwABitMask = -16777216;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
UnityStudio/Classes/Transform.cs
Normal file
41
UnityStudio/Classes/Transform.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
public class Transform
|
||||
{
|
||||
public PPtr m_GameObject = new PPtr();
|
||||
public float[] m_LocalRotation;
|
||||
public float[] m_LocalPosition;
|
||||
public float[] m_LocalScale;
|
||||
public List<PPtr> m_Children = new List<PPtr>();
|
||||
public PPtr m_Father = new PPtr();//can be transform or type 224 (as seen in Minions)
|
||||
|
||||
public Transform(AssetPreloadData preloadData)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
if (sourceFile.platform == -2)
|
||||
{
|
||||
uint m_ObjectHideFlags = reader.ReadUInt32();
|
||||
PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
|
||||
PPtr m_PrefabInternal = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
m_GameObject = sourceFile.ReadPPtr();
|
||||
m_LocalRotation = new[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() };
|
||||
m_LocalPosition = new[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() };
|
||||
m_LocalScale = new[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() };
|
||||
int m_ChildrenCount = reader.ReadInt32();
|
||||
for (int j = 0; j < m_ChildrenCount; j++)
|
||||
{
|
||||
m_Children.Add(sourceFile.ReadPPtr());
|
||||
}
|
||||
m_Father = sourceFile.ReadPPtr();
|
||||
}
|
||||
}
|
||||
}
|
||||
102
UnityStudio/Classes/VideoClip.cs
Normal file
102
UnityStudio/Classes/VideoClip.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace UnityStudio
|
||||
{
|
||||
class VideoClip
|
||||
{
|
||||
public string m_Name;
|
||||
public byte[] m_VideoData;
|
||||
|
||||
public VideoClip(AssetPreloadData preloadData, bool readSwitch)
|
||||
{
|
||||
var sourceFile = preloadData.sourceFile;
|
||||
var reader = preloadData.Reader;
|
||||
|
||||
m_Name = reader.ReadAlignedString(reader.ReadInt32());
|
||||
var m_OriginalPath = reader.ReadAlignedString(reader.ReadInt32());
|
||||
var m_ProxyWidth = reader.ReadUInt32();
|
||||
var m_ProxyHeight = reader.ReadUInt32();
|
||||
var Width = reader.ReadUInt32();
|
||||
var Height = reader.ReadUInt32();
|
||||
if (sourceFile.version[0] >= 2017)//2017.x and up
|
||||
{
|
||||
var m_PixelAspecRatioNum = reader.ReadUInt32();
|
||||
var m_PixelAspecRatioDen = reader.ReadUInt32();
|
||||
}
|
||||
var m_FrameRate = reader.ReadDouble();
|
||||
var m_FrameCount = reader.ReadUInt64();
|
||||
var m_Format = reader.ReadInt32();
|
||||
//m_AudioChannelCount
|
||||
var size = reader.ReadInt32();
|
||||
reader.Position += size * 2;
|
||||
reader.AlignStream(4);
|
||||
//m_AudioSampleRate
|
||||
size = reader.ReadInt32();
|
||||
reader.Position += size * 4;
|
||||
//m_AudioLanguage
|
||||
size = reader.ReadInt32();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
reader.ReadAlignedString(reader.ReadInt32());
|
||||
}
|
||||
//StreamedResource m_ExternalResources
|
||||
var m_Source = reader.ReadAlignedString(reader.ReadInt32());
|
||||
var m_Offset = reader.ReadUInt64();
|
||||
var m_Size = reader.ReadUInt64();
|
||||
var m_HasSplitAlpha = reader.ReadBoolean();
|
||||
|
||||
if (readSwitch)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(m_Source))
|
||||
{
|
||||
var resourceFileName = Path.GetFileName(m_Source);
|
||||
var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
|
||||
if (!File.Exists(resourceFilePath))
|
||||
{
|
||||
var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
|
||||
if (findFiles.Length > 0)
|
||||
{
|
||||
resourceFilePath = findFiles[0];
|
||||
}
|
||||
}
|
||||
if (File.Exists(resourceFilePath))
|
||||
{
|
||||
using (var resourceReader = new BinaryReader(File.OpenRead(resourceFilePath)))
|
||||
{
|
||||
resourceReader.BaseStream.Position = (long)m_Offset;
|
||||
m_VideoData = resourceReader.ReadBytes((int)m_Size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Studio.resourceFileReaders.TryGetValue(resourceFileName.ToUpper(), out var resourceReader))
|
||||
{
|
||||
resourceReader.Position = (long)m_Offset;
|
||||
m_VideoData = resourceReader.ReadBytes((int)m_Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show($"can't find the resource file {resourceFileName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_Size > 0)
|
||||
m_VideoData = reader.ReadBytes((int)m_Size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
preloadData.extension = Path.GetExtension(m_OriginalPath);
|
||||
preloadData.Text = m_Name;
|
||||
preloadData.fullSize = preloadData.Size + (int)m_Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user