diff --git a/Unity Studio/Unity Classes/AudioClip.cs b/Unity Studio/Unity Classes/AudioClip.cs index 419c895..16fb1da 100644 --- a/Unity Studio/Unity Classes/AudioClip.cs +++ b/Unity Studio/Unity Classes/AudioClip.cs @@ -88,7 +88,8 @@ namespace Unity_Studio m_3D = m_Legacy3D; m_Source = a_Stream.ReadAlignedString(a_Stream.ReadInt32()); - m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), m_Source.Replace("archive:/", "")); + if (m_Source != "") + m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), m_Source.Replace("archive:/", "")); m_Offset = a_Stream.ReadInt64(); m_Size = a_Stream.ReadInt64(); m_CompressionFormat = a_Stream.ReadInt32(); @@ -96,9 +97,10 @@ namespace Unity_Studio if (readSwitch) { - if (m_Source == null) + if (string.IsNullOrEmpty(m_Source)) { - m_AudioData = a_Stream.ReadBytes((int)m_Size); + if (m_Size > 0) + m_AudioData = a_Stream.ReadBytes((int)m_Size); } else if (File.Exists(m_Source) || File.Exists(m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), Path.GetFileName(m_Source)))) @@ -181,11 +183,9 @@ namespace Unity_Studio } preloadData.InfoText += "\n3D: " + m_3D; - if (m_Name != "") { preloadData.Text = m_Name; } - else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; } + preloadData.Text = m_Name; if (m_Source != null) preloadData.fullSize = preloadData.Size + (int)m_Size; - preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.fullSize.ToString() }); } } } diff --git a/Unity Studio/Unity Classes/Font.cs b/Unity Studio/Unity Classes/Font.cs index 8d2c64e..618d0ce 100644 --- a/Unity Studio/Unity Classes/Font.cs +++ b/Unity Studio/Unity Classes/Font.cs @@ -71,8 +71,7 @@ namespace Unity_Studio int m_FontData_size = a_Stream.ReadInt32(); if (m_FontData_size > 0) { - m_FontData = new byte[m_FontData_size]; - a_Stream.Read(m_FontData, 0, m_FontData_size); + m_FontData = a_Stream.ReadBytes(m_FontData_size); if (m_FontData[0] == 79 && m_FontData[1] == 84 && m_FontData[2] == 84 && m_FontData[3] == 79) { preloadData.extension = ".otf"; } @@ -153,8 +152,7 @@ namespace Unity_Studio int m_FontData_size = a_Stream.ReadInt32(); if (m_FontData_size > 0) { - m_FontData = new byte[m_FontData_size]; - a_Stream.Read(m_FontData, 0, m_FontData_size); + m_FontData = a_Stream.ReadBytes(m_FontData_size); if (m_FontData[0] == 79 && m_FontData[1] == 84 && m_FontData[2] == 84 && m_FontData[3] == 79) { preloadData.extension = ".otf"; } @@ -186,9 +184,7 @@ namespace Unity_Studio } else { - if (m_Name != "") { preloadData.Text = m_Name; } - else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; } - preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() }); + preloadData.Text = m_Name; } } } diff --git a/Unity Studio/Unity Classes/GameObject.cs b/Unity Studio/Unity Classes/GameObject.cs index cbbad0f..2749025 100644 --- a/Unity Studio/Unity Classes/GameObject.cs +++ b/Unity Studio/Unity Classes/GameObject.cs @@ -52,8 +52,7 @@ namespace Unity_Studio } m_Layer = a_Stream.ReadInt32(); - int namesize = a_Stream.ReadInt32(); - m_Name = a_Stream.ReadAlignedString(namesize); + m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32()); if (m_Name == "") { m_Name = "GameObject #" + uniqueID; } m_Tag = a_Stream.ReadUInt16(); m_IsActive = a_Stream.ReadBoolean(); diff --git a/Unity Studio/Unity Classes/Mesh.cs b/Unity Studio/Unity Classes/Mesh.cs index e5a33ff..3ad2399 100644 --- a/Unity Studio/Unity Classes/Mesh.cs +++ b/Unity Studio/Unity Classes/Mesh.cs @@ -333,7 +333,6 @@ namespace Unity_Studio var version = MeshPD.sourceFile.version; a_Stream = MeshPD.sourceFile.a_Stream; a_Stream.Position = MeshPD.Offset; - MeshPD.extension = ".obj"; bool m_Use16BitIndices = true; //3.5.0 and newer always uses 16bit indices uint m_MeshCompression = 0; @@ -1226,9 +1225,8 @@ namespace Unity_Studio } else { - if (m_Name != "") { MeshPD.Text = m_Name; } - else { MeshPD.Text = MeshPD.TypeString + " #" + MeshPD.uniqueID; } - MeshPD.SubItems.AddRange(new[] { MeshPD.TypeString, MeshPD.Size.ToString() }); + MeshPD.extension = ".obj"; + MeshPD.Text = m_Name; } } } diff --git a/Unity Studio/Unity Classes/MonoBehaviour.cs b/Unity Studio/Unity Classes/MonoBehaviour.cs index 38a621c..9bca93f 100644 --- a/Unity Studio/Unity Classes/MonoBehaviour.cs +++ b/Unity Studio/Unity Classes/MonoBehaviour.cs @@ -22,7 +22,6 @@ namespace Unity_Studio var m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32()); if (readSwitch) { - preloadData.extension = ".txt"; if ((serializedText = preloadData.ViewStruct()) == null) { var str = "PPtr m_GameObject\r\n"; @@ -38,15 +37,8 @@ namespace Unity_Studio } else { - if (m_Name != "") - { - preloadData.Text = m_Name; - } - else - { - preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; - } - preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() }); + preloadData.extension = ".txt"; + preloadData.Text = m_Name; } } } diff --git a/Unity Studio/Unity Classes/Shader.cs b/Unity Studio/Unity Classes/Shader.cs index bf7b749..b8fc0c2 100644 --- a/Unity Studio/Unity Classes/Shader.cs +++ b/Unity Studio/Unity Classes/Shader.cs @@ -18,7 +18,6 @@ namespace Unity_Studio var sourceFile = preloadData.sourceFile; var a_Stream = preloadData.sourceFile.a_Stream; a_Stream.Position = preloadData.Offset; - preloadData.extension = ".txt"; if (sourceFile.platform == -2) { @@ -74,9 +73,8 @@ namespace Unity_Studio } else { - if (m_Name != "") { preloadData.Text = m_Name; } - else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; } - preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() }); + preloadData.extension = ".txt"; + preloadData.Text = m_Name; } } diff --git a/Unity Studio/Unity Classes/TextAsset.cs b/Unity Studio/Unity Classes/TextAsset.cs index a3c67ef..cab8af9 100644 --- a/Unity Studio/Unity Classes/TextAsset.cs +++ b/Unity Studio/Unity Classes/TextAsset.cs @@ -16,7 +16,6 @@ namespace Unity_Studio var sourceFile = preloadData.sourceFile; var a_Stream = preloadData.sourceFile.a_Stream; a_Stream.Position = preloadData.Offset; - preloadData.extension = ".txt"; if (sourceFile.platform == -2) { @@ -33,9 +32,8 @@ namespace Unity_Studio } else { - if (m_Name != "") { preloadData.Text = m_Name; } - else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; } - preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() }); + preloadData.extension = ".txt"; + preloadData.Text = m_Name; } } } diff --git a/Unity Studio/Unity Classes/Texture2D.cs b/Unity Studio/Unity Classes/Texture2D.cs index 8e8576d..3b8b198 100644 --- a/Unity Studio/Unity Classes/Texture2D.cs +++ b/Unity Studio/Unity Classes/Texture2D.cs @@ -756,11 +756,9 @@ namespace Unity_Studio case 1: preloadData.InfoText += "\nWrap mode: Clamp"; break; } - if (m_Name != "") { preloadData.Text = m_Name; } - else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; } + preloadData.Text = m_Name; if (!string.IsNullOrEmpty(path)) preloadData.fullSize = preloadData.Size + (int)size; - preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.fullSize.ToString() }); } } diff --git a/Unity Studio/Unity Classes/VideoClip.cs b/Unity Studio/Unity Classes/VideoClip.cs index 0b87f0b..66ac800 100644 --- a/Unity Studio/Unity Classes/VideoClip.cs +++ b/Unity Studio/Unity Classes/VideoClip.cs @@ -24,8 +24,11 @@ namespace Unity_Studio var m_ProxyHeight = a_Stream.ReadUInt32(); var Width = a_Stream.ReadUInt32(); var Height = a_Stream.ReadUInt32(); - var m_PixelAspecRatioNum = a_Stream.ReadUInt32(); - var m_PixelAspecRatioDen = a_Stream.ReadUInt32(); + if (sourceFile.version[0] == 2017)//2017.x + { + var m_PixelAspecRatioNum = a_Stream.ReadUInt32(); + var m_PixelAspecRatioDen = a_Stream.ReadUInt32(); + } var m_FrameRate = a_Stream.ReadDouble(); var m_FrameCount = a_Stream.ReadUInt64(); var m_Format = a_Stream.ReadInt32(); @@ -44,16 +47,18 @@ namespace Unity_Studio } //StreamedResource m_ExternalResources var m_Source = a_Stream.ReadAlignedString(a_Stream.ReadInt32()); - m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), m_Source.Replace("archive:/", "")); + if (m_Source != "") + m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), m_Source.Replace("archive:/", "")); var m_Offset = a_Stream.ReadUInt64(); var m_Size = a_Stream.ReadUInt64(); var m_HasSplitAlpha = a_Stream.ReadBoolean(); if (readSwitch) { - if (m_Source == null) + if (string.IsNullOrEmpty(m_Source)) { - m_VideoData = a_Stream.ReadBytes((int)m_Size); + if (m_Size > 0) + m_VideoData = a_Stream.ReadBytes((int)m_Size); } else if (File.Exists(m_Source) || File.Exists(m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), Path.GetFileName(m_Source)))) { @@ -79,11 +84,9 @@ namespace Unity_Studio else { preloadData.extension = Path.GetExtension(m_OriginalPath); - if (m_Name != "") { preloadData.Text = m_Name; } - else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; } + preloadData.Text = m_Name; if (m_Source != null) preloadData.fullSize = preloadData.Size + (int)m_Size; - preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.fullSize.ToString() }); } } } diff --git a/Unity Studio/Unity Studio Classes/AssetsFile.cs b/Unity Studio/Unity Studio Classes/AssetsFile.cs index cd84b75..dd29c23 100644 --- a/Unity Studio/Unity Studio Classes/AssetsFile.cs +++ b/Unity Studio/Unity Studio Classes/AssetsFile.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Windows.Forms; namespace Unity_Studio { @@ -20,8 +21,6 @@ namespace Unity_Studio public string[] buildType; public int platform = 100663296; public string platformStr = ""; - //public EndianType endianType = EndianType.BigEndian; - //public List preloadTable = new List(); public Dictionary preloadTable = new Dictionary(); public Dictionary GameObjectList = new Dictionary(); public Dictionary TransformList = new Dictionary(); @@ -216,7 +215,6 @@ namespace Unity_Studio byte[] b32 = BitConverter.GetBytes(platform); Array.Reverse(b32); platform = BitConverter.ToInt32(b32, 0); - //endianType = EndianType.LittleEndian; a_Stream.endian = EndianType.LittleEndian; } @@ -344,10 +342,6 @@ namespace Unity_Studio //this is a single byte, not an int32 //the next entry is aligned after this //but not the last! - if (unknownByte != 0) - { - //bool investigate = true; - } } string typeString; @@ -424,7 +418,6 @@ namespace Unity_Studio { string varType = a_Stream.ReadStringToNull(); string varName = a_Stream.ReadStringToNull(); - //a_Stream.Position += 20; int size = a_Stream.ReadInt32(); int index = a_Stream.ReadInt32(); int isArray = a_Stream.ReadInt32(); @@ -432,7 +425,6 @@ namespace Unity_Studio int flag = a_Stream.ReadInt32(); int childrenCount = a_Stream.ReadInt32(); - //Debug.WriteLine(baseFormat + " " + baseName + " " + childrenCount); cb.Add(new ClassMember() { Level = level - 1, @@ -461,7 +453,7 @@ namespace Unity_Studio } classIDs.Add(new[] { type1, classID }); classID = type1; - /*TODO 替换? + /*TODO 用来替换下方的代码 if(classID == 114) { a_Stream.Position += 16; @@ -530,9 +522,6 @@ namespace Unity_Studio Flag = flag }); } - - //for (int t = 0; t < level; t++) { Debug.Write("\t"); } - //Debug.WriteLine(varTypeStr + " " + varNameStr + " " + size); } a_Stream.Position += stringSize; diff --git a/Unity Studio/Unity Studio Classes/BundleFile.cs b/Unity Studio/Unity Studio Classes/BundleFile.cs index 38537a7..b868752 100644 --- a/Unity Studio/Unity Studio Classes/BundleFile.cs +++ b/Unity Studio/Unity Studio Classes/BundleFile.cs @@ -31,9 +31,7 @@ namespace Unity_Studio int compressedSize = lz4Stream.ReadInt32(); int something = lz4Stream.ReadInt32(); //1 - byte[] lz4buffer = new byte[compressedSize]; - lz4Stream.Read(lz4buffer, 0, compressedSize); - + var lz4buffer = lz4Stream.ReadBytes(compressedSize); using (var inputStream = new MemoryStream(lz4buffer)) { var decoder = new Lz4DecoderStream(inputStream); @@ -97,9 +95,7 @@ namespace Unity_Studio case "\xFA\xFA\xFA\xFA\xFA\xFA\xFA\xFA": //.bytes case "UnityWeb": { - byte[] lzmaBuffer = new byte[lzmaSize]; - b_Stream.Read(lzmaBuffer, 0, lzmaSize); - + var lzmaBuffer = b_Stream.ReadBytes(lzmaSize); using (var lzmaStream = new EndianBinaryReader(SevenZipHelper.StreamDecompress(new MemoryStream(lzmaBuffer)))) { getFiles(lzmaStream, 0); @@ -131,16 +127,14 @@ namespace Unity_Studio int fileCount = f_Stream.ReadInt32(); for (int i = 0; i < fileCount; i++) { - MemoryAssetsFile memFile = new MemoryAssetsFile(); + var memFile = new MemoryAssetsFile(); memFile.fileName = f_Stream.ReadStringToNull(); int fileOffset = f_Stream.ReadInt32(); fileOffset += offset; int fileSize = f_Stream.ReadInt32(); long nextFile = f_Stream.Position; f_Stream.Position = fileOffset; - - byte[] buffer = new byte[fileSize]; - f_Stream.Read(buffer, 0, fileSize); + var buffer = f_Stream.ReadBytes(fileSize); memFile.memStream = new MemoryStream(buffer); MemoryAssetsFileList.Add(memFile); f_Stream.Position = nextFile; @@ -252,8 +246,7 @@ namespace Unity_Studio var unknown = blocksInfo.ReadInt32(); memFile.fileName = blocksInfo.ReadStringToNull(); assetsData.Position = entryinfo_offset; - var buffer = new byte[entryinfo_size]; - assetsData.Read(buffer, 0, (int)entryinfo_size); + var buffer = assetsData.ReadBytes((int)entryinfo_size); memFile.memStream = new MemoryStream(buffer); MemoryAssetsFileList.Add(memFile); } diff --git a/Unity Studio/Unity Studio Classes/EndianBinaryReader.cs b/Unity Studio/Unity Studio Classes/EndianBinaryReader.cs index e453e12..f23aae0 100644 --- a/Unity Studio/Unity Studio Classes/EndianBinaryReader.cs +++ b/Unity Studio/Unity Studio Classes/EndianBinaryReader.cs @@ -18,7 +18,9 @@ namespace Unity_Studio private byte[] a32 = new byte[4]; private byte[] a64 = new byte[8]; - public EndianBinaryReader(Stream stream, EndianType endian = EndianType.BigEndian) : base(stream) { this.endian = endian; } + public EndianBinaryReader(Stream stream, EndianType endian = EndianType.BigEndian) + : base(stream) + { this.endian = endian; } public long Position { @@ -121,28 +123,17 @@ namespace Unity_Studio public void AlignStream(int alignment) { - long pos = BaseStream.Position; - //long padding = alignment - pos + (pos / alignment) * alignment; - //if (padding != alignment) { base.BaseStream.Position += padding; } - if ((pos % alignment) != 0) { BaseStream.Position += alignment - (pos % alignment); } + var pos = BaseStream.Position; + var mod = pos % alignment; + if (mod != 0) { BaseStream.Position += alignment - mod; } } public string ReadAlignedString(int length) { - if (length > 0 && length < (BaseStream.Length - BaseStream.Position))//crude failsafe + if (length > 0 && length < (BaseStream.Length - BaseStream.Position)) { - byte[] stringData = new byte[length]; - Read(stringData, 0, length); - var result = Encoding.UTF8.GetString(stringData); //must verify strange characters in PS3 - - /*string result = ""; - char c; - for (int i = 0; i < length; i++) - { - c = (char)base.ReadByte(); - result += c.ToString(); - }*/ - + var stringData = ReadBytes(length); + var result = Encoding.UTF8.GetString(stringData); AlignStream(4); return result; } diff --git a/Unity Studio/Unity Studio Classes/UnityStudio.cs b/Unity Studio/Unity Studio Classes/UnityStudio.cs index b5fbe05..fed1aaa 100644 --- a/Unity Studio/Unity Studio Classes/UnityStudio.cs +++ b/Unity Studio/Unity Studio Classes/UnityStudio.cs @@ -38,17 +38,9 @@ namespace Unity_Studio public static void LoadAssetsFile(string fileName) { - //var loadedAssetsFile = assetsfileList.Find(aFile => aFile.filePath == fileName); - //if (loadedAssetsFile == null) if (!assetsfileListHash.Contains(fileName)) { - //open file here and pass the stream to facilitate loading memory files - //also by keeping the stream as a property of AssetsFile, it can be used later on to read assets AssetsFile assetsFile = new AssetsFile(fileName, new EndianBinaryReader(File.OpenRead(fileName))); - //if (Path.GetFileName(fileName) == "mainData") { mainDataFile = assetsFile; } - - //totalAssetCount += assetsFile.preloadTable.Count; - assetsfileList.Add(assetsFile); assetsfileListHash.Add(fileName); @@ -78,23 +70,8 @@ namespace Unity_Studio { string sharedFilePath = Path.GetDirectoryName(fileName) + "\\" + sharedFile.fileName; string sharedFileName = Path.GetFileName(sharedFile.fileName); - - //var loadedSharedFile = assetsfileList.Find(aFile => aFile.filePath == sharedFilePath); - /*var loadedSharedFile = assetsfileList.Find(aFile => aFile.filePath.EndsWith(Path.GetFileName(sharedFile.fileName))); - if (loadedSharedFile != null) { sharedFile.Index = assetsfileList.IndexOf(loadedSharedFile); } - else if (File.Exists(sharedFilePath)) - { - //progressBar1.Maximum += 1; - sharedFile.Index = assetsfileList.Count; - LoadAssetsFile(sharedFilePath); - }*/ - - //searching in unityFiles would preserve desired order, but... - //var quedSharedFile = unityFiles.Find(uFile => String.Equals(Path.GetFileName(uFile), sharedFileName, StringComparison.OrdinalIgnoreCase)); - //if (quedSharedFile == null) if (!unityFilesHash.Contains(sharedFileName)) { - //if (!File.Exists(sharedFilePath)) { sharedFilePath = Path.GetDirectoryName(fileName) + "\\" + sharedFileName; } if (!File.Exists(sharedFilePath)) { var findFiles = Directory.GetFiles(Path.GetDirectoryName(fileName), sharedFileName, SearchOption.AllDirectories); @@ -107,7 +84,6 @@ namespace Unity_Studio sharedFile.Index = unityFiles.Count; unityFiles.Add(sharedFilePath); unityFilesHash.Add(sharedFileName); - //progressBar1.Maximum++; value++; } } @@ -166,16 +142,17 @@ namespace Unity_Studio { string destFile = Path.GetFileNameWithoutExtension(splitFile); string destPath = Path.GetDirectoryName(splitFile) + "\\"; - if (!File.Exists(destPath + destFile)) + var destFull = destPath + destFile; + if (!File.Exists(destFull)) { string[] splitParts = Directory.GetFiles(destPath, destFile + ".split*"); - using (var destStream = File.Create(destPath + destFile)) + using (var destStream = File.Create(destFull)) { for (int i = 0; i < splitParts.Length; i++) { - string splitPart = destPath + destFile + ".split" + i; + string splitPart = destFull + ".split" + i; using (var sourceStream = File.OpenRead(splitPart)) - sourceStream.CopyTo(destStream); // You can pass the buffer size as second argument. + sourceStream.CopyTo(destStream); } } } @@ -339,20 +316,22 @@ namespace Unity_Studio } if (!exportable && displayAll) { - if (asset.Text == "") - { - asset.Text = asset.TypeString + " #" + asset.uniqueID; - } asset.extension = ".dat"; - asset.SubItems.AddRange(new[] { asset.TypeString, asset.Size.ToString() }); exportable = true; } if (exportable) { + if (asset.Text == "") + { + asset.Text = asset.TypeString + " #" + asset.uniqueID; + } + asset.SubItems.AddRange(new[] { asset.TypeString, asset.fullSize.ToString() }); + //处理同名文件 if (!exportableAssetsHash.Add((asset.TypeString + asset.Text).ToUpper())) { asset.Text += " #" + asset.uniqueID; } + //处理非法文件名 asset.Text = FixFileName(asset.Text); assetsFile.exportableAssets.Add(asset); } @@ -371,14 +350,12 @@ namespace Unity_Studio }); } exportableAssets.AddRange(assetsFile.exportableAssets); - //if (assetGroup.Items.Count > 0) { listView1.Groups.Add(assetGroup); } } visibleAssets = exportableAssets; //will only work if ListView is visible exportableAssetsHash.Clear(); - //assetListView.EndUpdate(); } #endregion @@ -1122,7 +1099,7 @@ namespace Unity_Studio { //TODO check texture type and set path accordingly; eg. CubeMap, Texture3D string texPathName = Path.GetDirectoryName(FBXfile) + "\\Texture2D\\"; - ExportTexture(TexturePD, texPathName, false); + ExportTexture2D(TexturePD, texPathName, false); texPathName = Path.GetFullPath(Path.Combine(texPathName, $"{TexturePD.Text}.png"));//必须是png文件 ob.AppendFormat("\n\tTexture: 7{0}, \"Texture::{1}\", \"\" {{", TexturePD.uniqueID, TexturePD.Text); ob.Append("\n\t\tType: \"TextureVideoClip\""); @@ -1606,14 +1583,7 @@ namespace Unity_Studio return new byte[3] { red, green, blue }; } - public static void ExportRawFile(AssetPreloadData asset, string exportFilepath) - { - asset.sourceFile.a_Stream.Position = asset.Offset; - var bytes = asset.sourceFile.a_Stream.ReadBytes(asset.Size); - File.WriteAllBytes(exportFilepath, bytes); - } - - public static bool ExportTexture(AssetPreloadData asset, string exportPathName, bool flip) + public static bool ExportTexture2D(AssetPreloadData asset, string exportPathName, bool flip) { var m_Texture2D = new Texture2D(asset, true); if (m_Texture2D.image_data == null) @@ -1648,19 +1618,20 @@ namespace Unity_Studio return true; } - public static bool ExportAudioClip(AssetPreloadData asset, string exportFilename, string exportFileextension) + public static bool ExportAudioClip(AssetPreloadData asset, string exportPath) { var m_AudioClip = new AudioClip(asset, true); if (m_AudioClip.m_AudioData == null) return false; - var oldextension = exportFileextension; + var oldextension = asset.extension; + var exportFileExtension = asset.extension; var convertfsb = (bool)Properties.Settings.Default["convertfsb"]; - if (convertfsb && exportFileextension == ".fsb") + if (convertfsb && exportFileExtension == ".fsb") { - exportFileextension = ".wav"; + exportFileExtension = ".wav"; } - var exportFullname = exportFilename + exportFileextension; - if (ExportFileExists(exportFullname)) + var exportFullName = exportPath + asset.Text + exportFileExtension; + if (ExportFileExists(exportFullName)) return false; if (convertfsb && oldextension == ".fsb") { @@ -1713,7 +1684,7 @@ namespace Unity_Studio Encoding.UTF8.GetBytes("data").CopyTo(buffer, 36); BitConverter.GetBytes(len1).CopyTo(buffer, 40); Marshal.Copy(ptr1, buffer, 44, (int)len1); - File.WriteAllBytes(exportFullname, buffer); + File.WriteAllBytes(exportFullName, buffer); result = subsound.unlock(ptr1, ptr2, len1, len2); if (result != FMOD.RESULT.OK) { return false; } @@ -1724,38 +1695,63 @@ namespace Unity_Studio } else { - File.WriteAllBytes(exportFullname, m_AudioClip.m_AudioData); + File.WriteAllBytes(exportFullName, m_AudioClip.m_AudioData); } return true; } - public static void ExportMonoBehaviour(MonoBehaviour m_MonoBehaviour, string exportFilename) + public static bool ExportShader(AssetPreloadData asset, string exportPath) { - File.WriteAllText(exportFilename, m_MonoBehaviour.serializedText); + var m_Shader = new Shader(asset, true); + var exportFullName = exportPath + asset.Text + asset.extension; + if (ExportFileExists(exportFullName)) + return false; + File.WriteAllBytes(exportFullName, m_Shader.m_Script); + return true; } - public static void ExportShader(Shader m_Shader, string exportFilename) + public static bool ExportTextAsset(AssetPreloadData asset, string exportPath) { - File.WriteAllBytes(exportFilename, m_Shader.m_Script); + var m_TextAsset = new TextAsset(asset, true); + var exportFullName = exportPath + asset.Text + asset.extension; + if (ExportFileExists(exportFullName)) + return false; + File.WriteAllBytes(exportFullName, m_TextAsset.m_Script); + return true; } - public static void ExportText(TextAsset m_TextAsset, string exportFilename) + public static bool ExportMonoBehaviour(AssetPreloadData asset, string exportPath) { - File.WriteAllBytes(exportFilename, m_TextAsset.m_Script); + var m_MonoBehaviour = new MonoBehaviour(asset, true); + var exportFullName = exportPath + asset.Text + asset.extension; + if (ExportFileExists(exportFullName)) + return false; + File.WriteAllText(exportFullName, m_MonoBehaviour.serializedText); + return true; } - public static void ExportFont(unityFont m_Font, string exportFilename) + public static bool ExportFont(AssetPreloadData asset, string exportPath) { + var m_Font = new unityFont(asset, true); if (m_Font.m_FontData != null) { - File.WriteAllBytes(exportFilename, m_Font.m_FontData); + var exportFullName = exportPath + asset.Text + asset.extension; + if (ExportFileExists(exportFullName)) + return false; + File.WriteAllBytes(exportFullName, m_Font.m_FontData); + return true; } + return false; } - public static void ExportMesh(Mesh m_Mesh, string exportPath) + public static bool ExportMesh(AssetPreloadData asset, string exportPath) { + var m_Mesh = new Mesh(asset, true); if (m_Mesh.m_VertexCount <= 0) - return; + return false; + var exportFullName = exportPath + asset.Text + asset.extension; + if (ExportFileExists(exportFullName)) + return false; var sb = new StringBuilder(); sb.AppendLine("g " + m_Mesh.m_Name); #region Vertices @@ -1812,15 +1808,33 @@ namespace Unity_Studio } #endregion - File.WriteAllText(exportPath, sb.ToString()); + File.WriteAllText(exportFullName, sb.ToString()); + return true; } - public static void ExportVideo(VideoClip m_VideoClip, string exportFilename) + public static bool ExportVideoClip(AssetPreloadData asset, string exportPath) { + var m_VideoClip = new VideoClip(asset, true); if (m_VideoClip.m_VideoData != null) { - File.WriteAllBytes(exportFilename, m_VideoClip.m_VideoData); + var exportFullName = exportPath + asset.Text + asset.extension; + if (ExportFileExists(exportFullName)) + return false; + File.WriteAllBytes(exportFullName, m_VideoClip.m_VideoData); + return true; } + return false; + } + + public static bool ExportRawFile(AssetPreloadData asset, string exportPath) + { + var exportFullName = exportPath + asset.Text + asset.extension; + if (ExportFileExists(exportFullName)) + return false; + asset.sourceFile.a_Stream.Position = asset.Offset; + var bytes = asset.sourceFile.a_Stream.ReadBytes(asset.Size); + File.WriteAllBytes(exportFullName, bytes); + return true; } public static bool ExportFileExists(string filename) diff --git a/Unity Studio/Unity Studio-x86.csproj b/Unity Studio/Unity Studio-x86.csproj index b270d13..3a862bb 100644 --- a/Unity Studio/Unity Studio-x86.csproj +++ b/Unity Studio/Unity Studio-x86.csproj @@ -168,7 +168,7 @@ - + diff --git a/Unity Studio/Unity Studio.csproj b/Unity Studio/Unity Studio.csproj index 89c852a..0ef88f3 100644 --- a/Unity Studio/Unity Studio.csproj +++ b/Unity Studio/Unity Studio.csproj @@ -168,7 +168,7 @@ - + diff --git a/Unity Studio/UnityStudioForm.cs b/Unity Studio/UnityStudioForm.cs index 17b893c..3227583 100644 --- a/Unity Studio/UnityStudioForm.cs +++ b/Unity Studio/UnityStudioForm.cs @@ -139,7 +139,6 @@ namespace Unity_Studio mainPath = openFolderDialog1.Folder; resetForm(); - //TODO find a way to read data directly instead of merging files MergeSplitAssets(mainPath); for (int t = 0; t < fileTypes.Length; t++) @@ -714,7 +713,6 @@ namespace Unity_Studio { assetListView.BeginUpdate(); assetListView.SelectedIndices.Clear(); - //visibleListAssets = exportableAssets.FindAll(ListAsset => ListAsset.Text.StartsWith(ListSearch.Text, System.StringComparison.CurrentCultureIgnoreCase)); visibleAssets = exportableAssets.FindAll(ListAsset => ListAsset.Text.IndexOf(listSearch.Text, StringComparison.CurrentCultureIgnoreCase) >= 0); assetListView.VirtualListSize = visibleAssets.Count; assetListView.EndUpdate(); @@ -836,7 +834,8 @@ namespace Unity_Studio case 83: //AudioClip { AudioClip m_AudioClip = new AudioClip(asset, true); - + if (m_AudioClip.m_AudioData == null) + break; FMOD.RESULT result; FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO(); @@ -1105,7 +1104,7 @@ namespace Unity_Studio #region VideoClip case 329: { - string str = asset.ViewStruct(); + var str = asset.ViewStruct(); if (str != null) { textPreviewBox.Text = str; @@ -1116,7 +1115,7 @@ namespace Unity_Studio #endregion default: { - string str = asset.ViewStruct(); + var str = asset.ViewStruct(); if (str != null) { textPreviewBox.Text = str; @@ -1150,9 +1149,6 @@ namespace Unity_Studio result = system.init(1, FMOD.INITFLAGS.NORMAL, IntPtr.Zero); if (ERRCHECK(result)) { return; } - //result = system.getMasterChannelGroup(out channelGroup); - //if (ERRCHECK(result)) { return; } - result = system.getMasterSoundGroup(out masterSoundGroup); if (ERRCHECK(result)) { return; } @@ -1204,7 +1200,6 @@ namespace Unity_Studio result = system.playSound(sound, null, false, out channel); if (ERRCHECK(result)) { return; } FMODstatusLabel.Text = "Playing"; - //FMODinfoLabel.Text = FMODfrequency.ToString(); if (FMODprogressBar.Value > 0) { @@ -1243,9 +1238,6 @@ namespace Unity_Studio result = channel.setPaused(!paused); if (ERRCHECK(result)) { return; } - //FMODstatusLabel.Text = (!paused ? "Paused" : playing ? "Playing" : "Stopped"); - //FMODpauseButton.Text = (!paused ? "Resume" : playing ? "Pause" : "Pause"); - if (paused) { FMODstatusLabel.Text = (playing ? "Playing" : "Stopped"); @@ -1409,7 +1401,6 @@ namespace Unity_Studio } } - //statusBar.Text = "Time " + (ms / 1000 / 60) + ":" + (ms / 1000 % 60) + ":" + (ms / 10 % 100) + "/" + (lenms / 1000 / 60) + ":" + (lenms / 1000 % 60) + ":" + (lenms / 10 % 100) + " : " + (paused ? "Paused " : playing ? "Playing" : "Stopped"); FMODtimerLabel.Text = (ms / 1000 / 60) + ":" + (ms / 1000 % 60) + "." + (ms / 10 % 100) + " / " + (FMODlenms / 1000 / 60) + ":" + (FMODlenms / 1000 % 60) + "." + (FMODlenms / 10 % 100); FMODprogressBar.Value = (int)(ms * 1000 / FMODlenms); FMODstatusLabel.Text = (paused ? "Paused " : playing ? "Playing" : "Stopped"); @@ -1424,10 +1415,8 @@ namespace Unity_Studio { if (result != FMOD.RESULT.OK) { - //FMODinit(); FMODreset(); StatusStripUpdate("FMOD error! " + result + " - " + FMOD.Error.String(result)); - //Environment.Exit(-1); return true; } return false; @@ -1580,74 +1569,59 @@ namespace Unity_Studio if (assetGroupSelectedIndex == 1) { exportpath += Path.GetFileNameWithoutExtension(asset.sourceFile.filePath) + "_export\\"; } else if (assetGroupSelectedIndex == 0) { exportpath = savePath + "\\" + asset.TypeString + "\\"; } StatusStripUpdate("Exporting " + asset.TypeString + ": " + asset.Text); - //AudioClip and Texture2D extensions are set when the list is built - //so their overwrite tests can be done without loading them again switch (asset.Type2) { - case 28: - if (ExportTexture(asset, exportpath, true)) + case 28: //Texture2D + if (ExportTexture2D(asset, exportpath, true)) { exportedCount++; } break; - case 83: - if (ExportAudioClip(asset, exportpath + asset.Text, asset.extension)) + case 83: //AudioClip + if (ExportAudioClip(asset, exportpath)) { exportedCount++; } break; - case 48: - Shader m_Shader = new Shader(asset, true); - if (!ExportFileExists(exportpath + asset.Text + asset.extension)) + case 48: //Shader + if (ExportShader(asset, exportpath)) { - ExportShader(m_Shader, exportpath + asset.Text + ".txt"); exportedCount++; } break; - case 49: - TextAsset m_TextAsset = new TextAsset(asset, true); - if (!ExportFileExists(exportpath + asset.Text + asset.extension)) + case 49: //TextAsset + if (ExportTextAsset(asset, exportpath)) { - ExportText(m_TextAsset, exportpath + asset.Text + asset.extension); exportedCount++; } break; - case 114: - MonoBehaviour m_MonoBehaviour = new MonoBehaviour(asset, true); - if (!ExportFileExists(exportpath + asset.Text + asset.extension)) + case 114: //MonoBehaviour + if (ExportMonoBehaviour(asset, exportpath)) { - ExportMonoBehaviour(m_MonoBehaviour, exportpath + asset.Text + asset.extension); exportedCount++; } break; - case 128: - unityFont m_Font = new unityFont(asset, true); - if (!ExportFileExists(exportpath + asset.Text + asset.extension)) + case 128: //Font + if (ExportFont(asset, exportpath)) { - ExportFont(m_Font, exportpath + asset.Text + asset.extension); exportedCount++; } break; case 43: //Mesh - Mesh m_Mesh = new Mesh(asset, true); - if (!ExportFileExists(exportpath + asset.Text + asset.extension)) + if (ExportMesh(asset, exportpath)) { - ExportMesh(m_Mesh, exportpath + asset.Text + asset.extension); exportedCount++; } break; case 329: //VideoClip - var m_VideoClip = new VideoClip(asset, true); - if (!ExportFileExists(exportpath + asset.Text + asset.extension)) + if (ExportVideoClip(asset, exportpath)) { - ExportVideo(m_VideoClip, exportpath + asset.Text + asset.extension); exportedCount++; } break; default: - if (!ExportFileExists(exportpath + asset.Text + asset.extension)) + if (ExportRawFile(asset, exportpath)) { - ExportRawFile(asset, exportpath + asset.Text + asset.extension); exportedCount++; } break; @@ -1910,11 +1884,6 @@ namespace Unity_Studio private void resetForm() { - /*Properties.Settings.Default["uniqueNames"] = uniqueNamesMenuItem.Checked; - Properties.Settings.Default["enablePreview"] = enablePreviewMenuItem.Checked; - Properties.Settings.Default["displayInfo"] = displayAssetInfoMenuItem.Checked; - Properties.Settings.Default.Save();*/ - Text = "Unity Studio"; unityFiles.Clear(); @@ -1927,7 +1896,6 @@ namespace Unity_Studio assetListView.VirtualListSize = 0; assetListView.Items.Clear(); - //assetListView.Groups.Clear(); classesListView.Items.Clear(); classesListView.Groups.Clear();