mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-27 22:00:23 -04:00
clean up code
This commit is contained in:
parent
9d505c8900
commit
3a6ebf7ce6
@ -110,7 +110,7 @@ namespace Unity_Studio
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EndianStream estream;
|
EndianBinaryReader estream;
|
||||||
if (UnityStudio.assetsfileandstream.TryGetValue(Path.GetFileName(m_Source), out estream))
|
if (UnityStudio.assetsfileandstream.TryGetValue(Path.GetFileName(m_Source), out estream))
|
||||||
{
|
{
|
||||||
estream.Position = m_Offset;
|
estream.Position = m_Offset;
|
||||||
|
@ -102,7 +102,7 @@ namespace Unity_Studio
|
|||||||
{
|
{
|
||||||
public class Mesh
|
public class Mesh
|
||||||
{
|
{
|
||||||
private EndianStream a_Stream;
|
private EndianBinaryReader a_Stream;
|
||||||
public string m_Name;
|
public string m_Name;
|
||||||
public List<SubMesh> m_SubMeshes = new List<SubMesh>();
|
public List<SubMesh> m_SubMeshes = new List<SubMesh>();
|
||||||
public List<uint> m_Indices = new List<uint>(); //use a list because I don't always know the facecount for triangle strips
|
public List<uint> m_Indices = new List<uint>(); //use a list because I don't always know the facecount for triangle strips
|
||||||
|
@ -66,7 +66,7 @@ namespace Unity_Studio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] ReadSerializedShader(List<ClassMember> members, EndianStream a_Stream)
|
private static byte[] ReadSerializedShader(List<ClassMember> members, EndianBinaryReader a_Stream)
|
||||||
{
|
{
|
||||||
var offsets = new List<uint>();
|
var offsets = new List<uint>();
|
||||||
var compressedLengths = new List<uint>();
|
var compressedLengths = new List<uint>();
|
||||||
|
@ -180,7 +180,7 @@ namespace Unity_Studio
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EndianStream estream;
|
EndianBinaryReader estream;
|
||||||
if (UnityStudio.assetsfileandstream.TryGetValue(Path.GetFileName(path), out estream))
|
if (UnityStudio.assetsfileandstream.TryGetValue(Path.GetFileName(path), out estream))
|
||||||
{
|
{
|
||||||
estream.Position = offset;
|
estream.Position = offset;
|
||||||
|
@ -9,7 +9,7 @@ namespace Unity_Studio
|
|||||||
{
|
{
|
||||||
public class AssetsFile
|
public class AssetsFile
|
||||||
{
|
{
|
||||||
public EndianStream a_Stream;
|
public EndianBinaryReader a_Stream;
|
||||||
public string filePath;
|
public string filePath;
|
||||||
public string bundlePath;
|
public string bundlePath;
|
||||||
public string fileName;
|
public string fileName;
|
||||||
@ -150,7 +150,7 @@ namespace Unity_Studio
|
|||||||
public string fileName = "";
|
public string fileName = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public AssetsFile(string fullName, EndianStream fileStream)
|
public AssetsFile(string fullName, EndianBinaryReader fileStream)
|
||||||
{
|
{
|
||||||
a_Stream = fileStream;
|
a_Stream = fileStream;
|
||||||
filePath = fullName;
|
filePath = fullName;
|
||||||
|
@ -42,25 +42,28 @@ namespace Unity_Studio
|
|||||||
decoder.Dispose();
|
decoder.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
using (var b_Stream = new EndianStream(new MemoryStream(filebuffer), EndianType.BigEndian))
|
using (var b_Stream = new EndianBinaryReader(new MemoryStream(filebuffer)))
|
||||||
{
|
{
|
||||||
readBundle(b_Stream);
|
readBundle(b_Stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
using (var b_Stream = new EndianStream(File.OpenRead(fileName), EndianType.BigEndian))
|
using (var b_Stream = new EndianBinaryReader(File.OpenRead(fileName)))
|
||||||
{
|
{
|
||||||
readBundle(b_Stream);
|
readBundle(b_Stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readBundle(EndianStream b_Stream)
|
private void readBundle(EndianBinaryReader b_Stream)
|
||||||
{
|
{
|
||||||
var signature = b_Stream.ReadStringToNull();
|
var signature = b_Stream.ReadStringToNull();
|
||||||
|
switch (signature)
|
||||||
if (signature == "UnityWeb" || signature == "UnityRaw" || signature == "\xFA\xFA\xFA\xFA\xFA\xFA\xFA\xFA")
|
{
|
||||||
|
case "UnityWeb":
|
||||||
|
case "UnityRaw":
|
||||||
|
case "\xFA\xFA\xFA\xFA\xFA\xFA\xFA\xFA":
|
||||||
{
|
{
|
||||||
format = b_Stream.ReadInt32();
|
format = b_Stream.ReadInt32();
|
||||||
versionPlayer = b_Stream.ReadStringToNull();
|
versionPlayer = b_Stream.ReadStringToNull();
|
||||||
@ -97,7 +100,7 @@ namespace Unity_Studio
|
|||||||
byte[] lzmaBuffer = new byte[lzmaSize];
|
byte[] lzmaBuffer = new byte[lzmaSize];
|
||||||
b_Stream.Read(lzmaBuffer, 0, lzmaSize);
|
b_Stream.Read(lzmaBuffer, 0, lzmaSize);
|
||||||
|
|
||||||
using (var lzmaStream = new EndianStream(SevenZipHelper.StreamDecompress(new MemoryStream(lzmaBuffer)), EndianType.BigEndian))
|
using (var lzmaStream = new EndianBinaryReader(SevenZipHelper.StreamDecompress(new MemoryStream(lzmaBuffer))))
|
||||||
{
|
{
|
||||||
getFiles(lzmaStream, 0);
|
getFiles(lzmaStream, 0);
|
||||||
}
|
}
|
||||||
@ -109,9 +112,9 @@ namespace Unity_Studio
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (signature == "UnityFS")
|
case "UnityFS":
|
||||||
{
|
|
||||||
format = b_Stream.ReadInt32();
|
format = b_Stream.ReadInt32();
|
||||||
versionPlayer = b_Stream.ReadStringToNull();
|
versionPlayer = b_Stream.ReadStringToNull();
|
||||||
versionEngine = b_Stream.ReadStringToNull();
|
versionEngine = b_Stream.ReadStringToNull();
|
||||||
@ -119,10 +122,11 @@ namespace Unity_Studio
|
|||||||
{
|
{
|
||||||
ReadFormat6(b_Stream);
|
ReadFormat6(b_Stream);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getFiles(EndianStream f_Stream, int offset)
|
private void getFiles(EndianBinaryReader f_Stream, int offset)
|
||||||
{
|
{
|
||||||
int fileCount = f_Stream.ReadInt32();
|
int fileCount = f_Stream.ReadInt32();
|
||||||
for (int i = 0; i < fileCount; i++)
|
for (int i = 0; i < fileCount; i++)
|
||||||
@ -143,7 +147,7 @@ namespace Unity_Studio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReadFormat6(EndianStream b_Stream, bool padding = false)
|
private void ReadFormat6(EndianBinaryReader b_Stream, bool padding = false)
|
||||||
{
|
{
|
||||||
var bundleSize = b_Stream.ReadInt64();
|
var bundleSize = b_Stream.ReadInt64();
|
||||||
int compressedSize = b_Stream.ReadInt32();
|
int compressedSize = b_Stream.ReadInt32();
|
||||||
@ -163,17 +167,17 @@ namespace Unity_Studio
|
|||||||
{
|
{
|
||||||
blocksInfoBytes = b_Stream.ReadBytes(compressedSize);
|
blocksInfoBytes = b_Stream.ReadBytes(compressedSize);
|
||||||
}
|
}
|
||||||
EndianStream blocksInfo;
|
MemoryStream blocksInfoStream;
|
||||||
switch (flag & 0x3F)
|
switch (flag & 0x3F)
|
||||||
{
|
{
|
||||||
default://None
|
default://None
|
||||||
{
|
{
|
||||||
blocksInfo = new EndianStream(new MemoryStream(blocksInfoBytes), EndianType.BigEndian);
|
blocksInfoStream = new MemoryStream(blocksInfoBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1://LZMA
|
case 1://LZMA
|
||||||
{
|
{
|
||||||
blocksInfo = new EndianStream(SevenZipHelper.StreamDecompress(new MemoryStream(blocksInfoBytes)), EndianType.BigEndian);
|
blocksInfoStream = SevenZipHelper.StreamDecompress(new MemoryStream(blocksInfoBytes));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2://LZ4
|
case 2://LZ4
|
||||||
@ -186,16 +190,15 @@ namespace Unity_Studio
|
|||||||
decoder.Read(uncompressedBytes, 0, uncompressedSize);
|
decoder.Read(uncompressedBytes, 0, uncompressedSize);
|
||||||
decoder.Dispose();
|
decoder.Dispose();
|
||||||
}
|
}
|
||||||
blocksInfo = new EndianStream(new MemoryStream(uncompressedBytes), EndianType.BigEndian);
|
blocksInfoStream = new MemoryStream(uncompressedBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//case 4:LZHAM?
|
//case 4:LZHAM?
|
||||||
}
|
}
|
||||||
using (blocksInfo)
|
using (var blocksInfo = new EndianBinaryReader(blocksInfoStream))
|
||||||
{
|
{
|
||||||
blocksInfo.Position = 0x10;
|
blocksInfo.Position = 0x10;
|
||||||
int blockcount = blocksInfo.ReadInt32();
|
int blockcount = blocksInfo.ReadInt32();
|
||||||
EndianStream assetsData;
|
|
||||||
var assetsDataStream = new MemoryStream();
|
var assetsDataStream = new MemoryStream();
|
||||||
for (int i = 0; i < blockcount; i++)
|
for (int i = 0; i < blockcount; i++)
|
||||||
{
|
{
|
||||||
@ -238,8 +241,7 @@ namespace Unity_Studio
|
|||||||
//case 4:LZHAM?
|
//case 4:LZHAM?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assetsData = new EndianStream(assetsDataStream, EndianType.BigEndian);
|
using (var assetsData = new EndianBinaryReader(assetsDataStream))
|
||||||
using (assetsData)
|
|
||||||
{
|
{
|
||||||
var entryinfo_count = blocksInfo.ReadInt32();
|
var entryinfo_count = blocksInfo.ReadInt32();
|
||||||
for (int i = 0; i < entryinfo_count; i++)
|
for (int i = 0; i < entryinfo_count; i++)
|
||||||
|
@ -53,7 +53,7 @@ namespace Unity_Studio
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ReadClassStruct(StringBuilder sb, List<ClassMember> members, EndianStream a_Stream)
|
private static void ReadClassStruct(StringBuilder sb, List<ClassMember> members, EndianBinaryReader a_Stream)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < members.Count; i++)
|
for (int i = 0; i < members.Count; i++)
|
||||||
{
|
{
|
||||||
|
@ -11,16 +11,20 @@ namespace Unity_Studio
|
|||||||
LittleEndian
|
LittleEndian
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EndianStream : BinaryReader
|
public class EndianBinaryReader : BinaryReader
|
||||||
{
|
{
|
||||||
public EndianType endian;
|
public EndianType endian;
|
||||||
private byte[] a16 = new byte[2];
|
private byte[] a16 = new byte[2];
|
||||||
private byte[] a32 = new byte[4];
|
private byte[] a32 = new byte[4];
|
||||||
private byte[] a64 = new byte[8];
|
private byte[] a64 = new byte[8];
|
||||||
|
|
||||||
public EndianStream(Stream stream, EndianType endian) : base(stream) { }
|
public EndianBinaryReader(Stream stream, EndianType endian = EndianType.BigEndian) : base(stream) { this.endian = endian; }
|
||||||
|
|
||||||
public long Position { get { return BaseStream.Position; } set { BaseStream.Position = value; } }
|
public long Position
|
||||||
|
{
|
||||||
|
get => BaseStream.Position;
|
||||||
|
set => BaseStream.Position = value;
|
||||||
|
}
|
||||||
|
|
||||||
public override short ReadInt16()
|
public override short ReadInt16()
|
||||||
{
|
{
|
@ -17,7 +17,7 @@ namespace Unity_Studio
|
|||||||
public static HashSet<string> unityFilesHash = new HashSet<string>(); //improve performance
|
public static HashSet<string> unityFilesHash = new HashSet<string>(); //improve performance
|
||||||
public static List<AssetsFile> assetsfileList = new List<AssetsFile>(); //loaded files
|
public static List<AssetsFile> assetsfileList = new List<AssetsFile>(); //loaded files
|
||||||
public static HashSet<string> assetsfileListHash = new HashSet<string>(); //improve performance
|
public static HashSet<string> assetsfileListHash = new HashSet<string>(); //improve performance
|
||||||
public static Dictionary<string, EndianStream> assetsfileandstream = new Dictionary<string, EndianStream>(); //use for read res files
|
public static Dictionary<string, EndianBinaryReader> assetsfileandstream = new Dictionary<string, EndianBinaryReader>(); //use for read res files
|
||||||
public static List<AssetPreloadData> exportableAssets = new List<AssetPreloadData>(); //used to hold all assets while the ListView is filtered
|
public static List<AssetPreloadData> exportableAssets = new List<AssetPreloadData>(); //used to hold all assets while the ListView is filtered
|
||||||
private static HashSet<string> exportableAssetsHash = new HashSet<string>(); //improve performance
|
private static HashSet<string> exportableAssetsHash = new HashSet<string>(); //improve performance
|
||||||
public static List<AssetPreloadData> visibleAssets = new List<AssetPreloadData>(); //used to build the ListView from all or filtered assets
|
public static List<AssetPreloadData> visibleAssets = new List<AssetPreloadData>(); //used to build the ListView from all or filtered assets
|
||||||
@ -44,7 +44,7 @@ namespace Unity_Studio
|
|||||||
{
|
{
|
||||||
//open file here and pass the stream to facilitate loading memory files
|
//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
|
//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 EndianStream(File.OpenRead(fileName), EndianType.BigEndian));
|
AssetsFile assetsFile = new AssetsFile(fileName, new EndianBinaryReader(File.OpenRead(fileName)));
|
||||||
//if (Path.GetFileName(fileName) == "mainData") { mainDataFile = assetsFile; }
|
//if (Path.GetFileName(fileName) == "mainData") { mainDataFile = assetsFile; }
|
||||||
|
|
||||||
//totalAssetCount += assetsFile.preloadTable.Count;
|
//totalAssetCount += assetsFile.preloadTable.Count;
|
||||||
@ -64,7 +64,7 @@ namespace Unity_Studio
|
|||||||
}
|
}
|
||||||
else if (File.Exists(Path.GetDirectoryName(fileName) + "\\mainData"))
|
else if (File.Exists(Path.GetDirectoryName(fileName) + "\\mainData"))
|
||||||
{
|
{
|
||||||
mainDataFile = new AssetsFile(Path.GetDirectoryName(fileName) + "\\mainData", new EndianStream(File.OpenRead(Path.GetDirectoryName(fileName) + "\\mainData"), EndianType.BigEndian));
|
mainDataFile = new AssetsFile(Path.GetDirectoryName(fileName) + "\\mainData", new EndianBinaryReader(File.OpenRead(Path.GetDirectoryName(fileName) + "\\mainData")));
|
||||||
|
|
||||||
assetsFile.m_Version = mainDataFile.m_Version;
|
assetsFile.m_Version = mainDataFile.m_Version;
|
||||||
assetsFile.version = mainDataFile.version;
|
assetsFile.version = mainDataFile.version;
|
||||||
@ -131,7 +131,7 @@ namespace Unity_Studio
|
|||||||
StatusStripUpdate("Loading " + memFile.fileName);
|
StatusStripUpdate("Loading " + memFile.fileName);
|
||||||
//create dummy path to be used for asset extraction
|
//create dummy path to be used for asset extraction
|
||||||
memFile.fileName = Path.GetDirectoryName(bundleFileName) + "\\" + memFile.fileName;
|
memFile.fileName = Path.GetDirectoryName(bundleFileName) + "\\" + memFile.fileName;
|
||||||
AssetsFile assetsFile = new AssetsFile(memFile.fileName, new EndianStream(memFile.memStream, EndianType.BigEndian));
|
AssetsFile assetsFile = new AssetsFile(memFile.fileName, new EndianBinaryReader(memFile.memStream));
|
||||||
if (assetsFile.valid)
|
if (assetsFile.valid)
|
||||||
{
|
{
|
||||||
assetsFile.bundlePath = bundleFileName;
|
assetsFile.bundlePath = bundleFileName;
|
||||||
@ -186,7 +186,7 @@ namespace Unity_Studio
|
|||||||
{
|
{
|
||||||
int extractedCount = 0;
|
int extractedCount = 0;
|
||||||
|
|
||||||
StatusStripUpdate("Decompressing " + Path.GetFileName(bundleFileName) + " ,,,");
|
StatusStripUpdate("Decompressing " + Path.GetFileName(bundleFileName) + " ...");
|
||||||
|
|
||||||
string extractPath = bundleFileName + "_unpacked\\";
|
string extractPath = bundleFileName + "_unpacked\\";
|
||||||
Directory.CreateDirectory(extractPath);
|
Directory.CreateDirectory(extractPath);
|
||||||
@ -1822,5 +1822,23 @@ namespace Unity_Studio
|
|||||||
if (str.Length >= 260) return Path.GetRandomFileName();
|
if (str.Length >= 260) return Path.GetRandomFileName();
|
||||||
return Path.GetInvalidFileNameChars().Aggregate(str, (current, c) => current.Replace(c, '_'));
|
return Path.GetInvalidFileNameChars().Aggregate(str, (current, c) => current.Replace(c, '_'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool CheckBundleFile(string fileName)
|
||||||
|
{
|
||||||
|
using (var stream = new EndianBinaryReader(File.OpenRead(fileName)))
|
||||||
|
{
|
||||||
|
var signature = stream.ReadStringToNull();
|
||||||
|
switch (signature)
|
||||||
|
{
|
||||||
|
case "UnityWeb":
|
||||||
|
case "UnityRaw":
|
||||||
|
case "\xFA\xFA\xFA\xFA\xFA\xFA\xFA\xFA":
|
||||||
|
case "UnityFS":
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@
|
|||||||
<Compile Include="Unity Studio Classes\ClassStruct.cs" />
|
<Compile Include="Unity Studio Classes\ClassStruct.cs" />
|
||||||
<Compile Include="Unity Studio Classes\UnityStudio.cs" />
|
<Compile Include="Unity Studio Classes\UnityStudio.cs" />
|
||||||
<Compile Include="Unity Studio Classes\ClassIDReference.cs" />
|
<Compile Include="Unity Studio Classes\ClassIDReference.cs" />
|
||||||
<Compile Include="Unity Studio Classes\EndianStream.cs" />
|
<Compile Include="Unity Studio Classes\EndianBinaryReader.cs" />
|
||||||
<Compile Include="ExportOptions.cs">
|
<Compile Include="ExportOptions.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -91,7 +91,13 @@ namespace Unity_Studio
|
|||||||
{
|
{
|
||||||
MergeSplitAssets(mainPath);
|
MergeSplitAssets(mainPath);
|
||||||
|
|
||||||
//unityFiles.AddRange(openFileDialog1.FileNames);
|
//Only verify whether the first file is bundle file
|
||||||
|
if (CheckBundleFile(openFileDialog1.FileNames[0]))
|
||||||
|
{
|
||||||
|
MessageBox.Show($"{Path.GetFileName(openFileDialog1.FileNames[0])} is bundle file, please select bundle file type to load this file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var i in openFileDialog1.FileNames)
|
foreach (var i in openFileDialog1.FileNames)
|
||||||
{
|
{
|
||||||
unityFiles.Add(i);
|
unityFiles.Add(i);
|
||||||
@ -197,7 +203,7 @@ namespace Unity_Studio
|
|||||||
private void extractBundleToolStripMenuItem_Click(object sender, EventArgs e)
|
private void extractBundleToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
OpenFileDialog openBundleDialog = new OpenFileDialog();
|
OpenFileDialog openBundleDialog = new OpenFileDialog();
|
||||||
openBundleDialog.Filter = "Unity bundle files|*.unity3d; *.unity3d.lz4; *.assetbundle; *.bundle; *.bytes|All files (use at your own risk!)|*.*";
|
openBundleDialog.Filter = "Unity bundle files|*.*";
|
||||||
openBundleDialog.FilterIndex = 1;
|
openBundleDialog.FilterIndex = 1;
|
||||||
openBundleDialog.RestoreDirectory = true;
|
openBundleDialog.RestoreDirectory = true;
|
||||||
openBundleDialog.Multiselect = true;
|
openBundleDialog.Multiselect = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user