Fixed some bugs

This commit is contained in:
Perfare 2017-02-16 15:30:11 +08:00
parent 16ed347a30
commit 332e4cc6e2
5 changed files with 208 additions and 194 deletions

View File

@ -95,7 +95,7 @@ namespace Unity_Studio
private static extern bool DecompressCRN(byte[] pSrc_file_data, int src_file_size, out IntPtr dxtdata, out int dxtsize);
[DllImport("texgenpack.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern bool texgenpackdecode(int texturetype, byte[] texturedata, int width, int height, IntPtr bmp, bool fixAlpha);
private static extern void texgenpackdecode(int texturetype, byte[] texturedata, int width, int height, IntPtr bmp, bool fixAlpha);
public Texture2D(AssetPreloadData preloadData, bool readSwitch)
{

View File

@ -273,14 +273,13 @@ namespace Unity_Studio
private void readBase5()
{
int classID = a_Stream.ReadInt32();
if (fileGen > 15)
if (fileGen > 15)//5.5.0 and up
{
a_Stream.ReadByte();
int type1;
if ((type1 = a_Stream.ReadInt16()) >= 0)
{
type1 = -1 - type1;
a_Stream.Position += 16;
}
else
{
@ -288,13 +287,21 @@ namespace Unity_Studio
}
classIDs.Add(new[] { type1, classID });
classID = type1;
//TODO 某些文件出现type1=-1时还需要跳过16字节的情况
/*TODO
if(classID == 114)
{
a_Stream.Position += 16;
}*/
var temp = a_Stream.ReadInt32();
if (temp == 0)
{
a_Stream.Position += 16;
}
a_Stream.Position -= 4;
if (type1 < 0)
{
a_Stream.Position += 16;
}
}
else if (classID < 0)
{

View File

@ -69,9 +69,9 @@ namespace Unity_Studio
{
int bundleSize = b_Stream.ReadInt32();
}
else
else if (format == 6)
{
long bundleSize = b_Stream.ReadInt64();
ReadFormat6(b_Stream, true);
return;
}
short dummy2 = b_Stream.ReadInt16();
@ -116,11 +116,41 @@ namespace Unity_Studio
versionPlayer = b_Stream.ReadStringToNull();
versionEngine = b_Stream.ReadStringToNull();
if (format == 6)
{
ReadFormat6(b_Stream);
}
}
}
private void getFiles(EndianStream f_Stream, int offset)
{
int fileCount = f_Stream.ReadInt32();
for (int i = 0; i < fileCount; i++)
{
MemoryAssetsFile 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);
memFile.memStream = new MemoryStream(buffer);
MemoryAssetsFileList.Add(memFile);
f_Stream.Position = nextFile;
}
}
private void ReadFormat6(EndianStream b_Stream, bool padding = false)
{
var bundleSize = b_Stream.ReadInt64();
int compressedSize = b_Stream.ReadInt32();
int uncompressedSize = b_Stream.ReadInt32();
int flag = b_Stream.ReadInt32();
if (padding)
b_Stream.ReadByte();
byte[] blocksInfoBytes;
if ((flag & 0x80) != 0)//at end of file
{
@ -231,27 +261,4 @@ namespace Unity_Studio
}
}
}
}
private void getFiles(EndianStream f_Stream, int offset)
{
int fileCount = f_Stream.ReadInt32();
for (int i = 0; i < fileCount; i++)
{
MemoryAssetsFile 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);
memFile.memStream = new MemoryStream(buffer);
MemoryAssetsFileList.Add(memFile);
f_Stream.Position = nextFile;
}
}
}
}

View File

@ -228,7 +228,7 @@ namespace Unity_Studio
StatusStripUpdate("Extracting " + Path.GetFileName(memFile.fileName));
extractedCount += 1;
using (FileStream file = new FileStream(filePath, FileMode.Create, System.IO.FileAccess.Write))
using (FileStream file = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
memFile.memStream.WriteTo(file);
memFile.memStream.Close();
@ -351,7 +351,7 @@ namespace Unity_Studio
asset.Text = asset.TypeString + " #" + asset.uniqueID;
}
asset.extension = ".dat";
asset.SubItems.AddRange(new[] {asset.TypeString, asset.Size.ToString()});
asset.SubItems.AddRange(new[] { asset.TypeString, asset.Size.ToString() });
exportable = true;
}
if (exportable)
@ -1612,7 +1612,7 @@ namespace Unity_Studio
else if (ext == "JPEG")
format = ImageFormat.Jpeg;
var exportFullName = exportPathName + asset.Text + "." + ext.ToLower();
if (ExportFileExists(exportFullName, asset.TypeString))
if (ExportFileExists(exportFullName))
return false;
var bitmap = m_Texture2D.ConvertToBitmap(flip);
if (bitmap != null)
@ -1623,7 +1623,7 @@ namespace Unity_Studio
}
}
var exportFullName2 = exportPathName + asset.Text + asset.extension;
if (ExportFileExists(exportFullName2, asset.TypeString))
if (ExportFileExists(exportFullName2))
return false;
File.WriteAllBytes(exportFullName2, m_Texture2D.ConvertToContainer());
return true;
@ -1637,7 +1637,7 @@ namespace Unity_Studio
exportFileextension = ".wav";
}
var exportFullname = exportFilename + exportFileextension;
if (ExportFileExists(exportFullname, "AudioClip"))
if (ExportFileExists(exportFullname))
return false;
var m_AudioClip = new AudioClip(asset, true);
if ((bool)Properties.Settings.Default["convertfsb"] && oldextension == ".fsb")
@ -1733,7 +1733,7 @@ namespace Unity_Studio
}
}
public static bool ExportFileExists(string filename, string assetType)
public static bool ExportFileExists(string filename)
{
if (File.Exists(filename))
{

View File

@ -1336,7 +1336,7 @@ namespace Unity_Studio
}
break;
case 48:
if (!ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString))
if (!ExportFileExists(exportpath + asset.Text + asset.extension))
{
ExportShader(new Shader(asset, true), exportpath + asset.Text + ".txt");
exportedCount++;
@ -1344,7 +1344,7 @@ namespace Unity_Studio
break;
case 49:
TextAsset m_TextAsset = new TextAsset(asset, true);
if (!ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString))
if (!ExportFileExists(exportpath + asset.Text + asset.extension))
{
ExportText(m_TextAsset, exportpath + asset.Text + asset.extension);
exportedCount++;
@ -1352,7 +1352,7 @@ namespace Unity_Studio
break;
case 114:
MonoBehaviour m_MonoBehaviour = new MonoBehaviour(asset, true);
if (!ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString))
if (!ExportFileExists(exportpath + asset.Text + asset.extension))
{
ExportMonoBehaviour(m_MonoBehaviour, exportpath + asset.Text + asset.extension);
exportedCount++;
@ -1360,14 +1360,14 @@ namespace Unity_Studio
break;
case 128:
unityFont m_Font = new unityFont(asset, true);
if (!ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString))
if (!ExportFileExists(exportpath + asset.Text + asset.extension))
{
ExportFont(m_Font, exportpath + asset.Text + asset.extension);
exportedCount++;
}
break;
default:
if (!ExportFileExists(exportpath + asset.Text + asset.extension, asset.TypeString))
if (!ExportFileExists(exportpath + asset.Text + asset.extension))
{
ExportRawFile(asset, exportpath + asset.Text + asset.extension);
exportedCount++;