mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-25 05:40:21 -04:00
Show/Export object dump if typetree dump is not available
This commit is contained in:
parent
f90c0ecc00
commit
8460ecef8d
@ -17,4 +17,8 @@
|
|||||||
<PackageReference Include="K4os.Compression.LZ4" Version="1.1.11" />
|
<PackageReference Include="K4os.Compression.LZ4" Version="1.1.11" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
using System.Collections.Specialized;
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace AssetStudio
|
namespace AssetStudio
|
||||||
{
|
{
|
||||||
@ -51,6 +55,25 @@ namespace AssetStudio
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string DumpObject()
|
||||||
|
{
|
||||||
|
string str = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
str = JsonConvert.SerializeObject(this, new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
Formatting = Formatting.Indented,
|
||||||
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||||
|
ContractResolver = new IgnorePropertiesResolver()
|
||||||
|
}).Replace(" ", " ");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
//ignore
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
public OrderedDictionary ToType()
|
public OrderedDictionary ToType()
|
||||||
{
|
{
|
||||||
if (serializedType?.m_Type != null)
|
if (serializedType?.m_Type != null)
|
||||||
@ -74,5 +97,25 @@ namespace AssetStudio
|
|||||||
reader.Reset();
|
reader.Reset();
|
||||||
return reader.ReadBytes((int)byteSize);
|
return reader.ReadBytes((int)byteSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class IgnorePropertiesResolver : DefaultContractResolver
|
||||||
|
{
|
||||||
|
private static readonly HashSet<string> _ignoreProps;
|
||||||
|
|
||||||
|
static IgnorePropertiesResolver()
|
||||||
|
{
|
||||||
|
_ignoreProps = new HashSet<string> { "assetsFile", "reader", "version", "platform", "serializedType" };
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
|
||||||
|
{
|
||||||
|
JsonProperty property = base.CreateProperty(member, memberSerialization);
|
||||||
|
if (_ignoreProps.Contains(property.PropertyName))
|
||||||
|
{
|
||||||
|
property.ShouldSerialize = _ => false;
|
||||||
|
}
|
||||||
|
return property;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ namespace AssetStudio
|
|||||||
{
|
{
|
||||||
append = false;
|
append = false;
|
||||||
var size = reader.ReadInt32();
|
var size = reader.ReadInt32();
|
||||||
reader.ReadBytes(size);
|
reader.BaseStream.Position += size;
|
||||||
i += 2;
|
i += 2;
|
||||||
sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
|
sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
|
||||||
sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), "int", "size", size);
|
sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), "int", "size", size);
|
||||||
|
@ -303,6 +303,10 @@ namespace AssetStudioCLI
|
|||||||
var m_Type = m_MonoBehaviour.ConvertToTypeTree(Studio.assemblyLoader);
|
var m_Type = m_MonoBehaviour.ConvertToTypeTree(Studio.assemblyLoader);
|
||||||
str = m_MonoBehaviour.Dump(m_Type);
|
str = m_MonoBehaviour.Dump(m_Type);
|
||||||
}
|
}
|
||||||
|
if (string.IsNullOrEmpty(str))
|
||||||
|
{
|
||||||
|
str = item.Asset.DumpObject();
|
||||||
|
}
|
||||||
if (str != null)
|
if (str != null)
|
||||||
{
|
{
|
||||||
File.WriteAllText(exportFullPath, str);
|
File.WriteAllText(exportFullPath, str);
|
||||||
|
@ -286,7 +286,7 @@ namespace AssetStudioGUI
|
|||||||
filterTypeToolStripMenuItem.DropDownItems.Add(typeItem);
|
filterTypeToolStripMenuItem.DropDownItems.Add(typeItem);
|
||||||
}
|
}
|
||||||
allToolStripMenuItem.Checked = true;
|
allToolStripMenuItem.Checked = true;
|
||||||
var log = $"Finished loading {assetsManager.assetsFileList.Count} files with {assetListView.Items.Count} exportable assets";
|
var log = $"Finished loading {assetsManager.assetsFileList.Count} file(s) with {assetListView.Items.Count} exportable assets";
|
||||||
var unityVer = assetsManager.assetsFileList[0].version;
|
var unityVer = assetsManager.assetsFileList[0].version;
|
||||||
var m_ObjectsCount = unityVer[0] > 2020 ?
|
var m_ObjectsCount = unityVer[0] > 2020 ?
|
||||||
assetsManager.assetsFileList.Sum(x => x.m_Objects.LongCount(y => y.classID != (int)ClassIDType.Shader)) :
|
assetsManager.assetsFileList.Sum(x => x.m_Objects.LongCount(y => y.classID != (int)ClassIDType.Shader)) :
|
||||||
|
@ -359,6 +359,10 @@ namespace AssetStudioGUI
|
|||||||
var m_Type = Studio.MonoBehaviourToTypeTree(m_MonoBehaviour);
|
var m_Type = Studio.MonoBehaviourToTypeTree(m_MonoBehaviour);
|
||||||
str = m_MonoBehaviour.Dump(m_Type);
|
str = m_MonoBehaviour.Dump(m_Type);
|
||||||
}
|
}
|
||||||
|
if (string.IsNullOrEmpty(str))
|
||||||
|
{
|
||||||
|
str = item.Asset.DumpObject();
|
||||||
|
}
|
||||||
if (str != null)
|
if (str != null)
|
||||||
{
|
{
|
||||||
File.WriteAllText(exportFullPath, str);
|
File.WriteAllText(exportFullPath, str);
|
||||||
|
@ -486,7 +486,8 @@ namespace AssetStudioGUI
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
exportPath += Path.DirectorySeparatorChar;
|
exportPath += Path.DirectorySeparatorChar;
|
||||||
Logger.Info($"[{exportedCount + 1}/{toExportCount}] Exporting {asset.TypeString}: {asset.Text}");
|
var mode = exportType == ExportType.Dump ? "Dumping" : "Exporting";
|
||||||
|
Logger.Info($"[{exportedCount + 1}/{toExportCount}] {mode} {asset.TypeString}: {asset.Text}");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
switch (exportType)
|
switch (exportType)
|
||||||
@ -785,6 +786,10 @@ namespace AssetStudioGUI
|
|||||||
var type = MonoBehaviourToTypeTree(m_MonoBehaviour);
|
var type = MonoBehaviourToTypeTree(m_MonoBehaviour);
|
||||||
str = m_MonoBehaviour.Dump(type);
|
str = m_MonoBehaviour.Dump(type);
|
||||||
}
|
}
|
||||||
|
if (string.IsNullOrEmpty(str))
|
||||||
|
{
|
||||||
|
str = obj.DumpObject();
|
||||||
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user