improved script dump

This commit is contained in:
Perfare 2018-12-23 15:51:00 +08:00
parent 761579ab1a
commit f449d7a8ab
2 changed files with 28 additions and 3 deletions

View File

@ -26,7 +26,7 @@ namespace AssetStudio
public static string ReadAlignedString(this BinaryReader reader) public static string ReadAlignedString(this BinaryReader reader)
{ {
var length = reader.ReadInt32(); var length = reader.ReadInt32();
if (length > 0 && length < (reader.BaseStream.Length - reader.BaseStream.Position)) if (length > 0 && length <= reader.BaseStream.Length - reader.BaseStream.Position)
{ {
var stringData = reader.ReadBytes(length); var stringData = reader.ReadBytes(length);
var result = Encoding.UTF8.GetString(stringData); var result = Encoding.UTF8.GetString(stringData);

View File

@ -7,8 +7,7 @@ using dnlib.DotNet;
namespace AssetStudio namespace AssetStudio
{ {
//TODO unfinished //TODO to json file
//Separate EngineType read
public sealed class ScriptDumper : IDisposable public sealed class ScriptDumper : IDisposable
{ {
private Dictionary<string, ModuleDef> moduleDic = new Dictionary<string, ModuleDef>(); private Dictionary<string, ModuleDef> moduleDic = new Dictionary<string, ModuleDef>();
@ -359,6 +358,32 @@ namespace AssetStudio
} }
} }
} }
else if (fieldDef.FieldType is GenericInstSig genericSig && genericSig.GenericArguments.Count == 1 && genericSig.GenericArguments[0].IsGenericParameter)
{
for (var i = 0; i < typeDef.GenericParameters.Count; i++)
{
var g = typeDef.GenericParameters[i];
if (g.FullName == genericSig.GenericArguments[0].FullName)
{
var type = ((GenericInstSig)typeSig).GenericArguments[i];
var fieldTypeDef = fieldDef.FieldType.ToTypeDefOrRef().ResolveTypeDefThrow();
if (fieldTypeDef.Interfaces.Any(x => x.Interface.FullName == "System.Collections.Generic.ICollection`1<T>")) //System.Collections.Generic.IEnumerable`1<T>
{
var size = reader.ReadInt32();
sb.AppendLine($"{new string('\t', indent + 1)}int size = {size}");
for (int j = 0; j < size; j++)
{
sb.AppendLine($"{new string('\t', indent + 2)}[{i}]");
DumpType(type, sb, reader, "data", indent + 2, false, false);
}
}
else
{
DumpType(fieldDef.FieldType, sb, reader, fieldDef.Name, indent + 1);
}
}
}
}
else else
{ {
DumpType(fieldDef.FieldType, sb, reader, fieldDef.Name, indent + 1); DumpType(fieldDef.FieldType, sb, reader, fieldDef.Name, indent + 1);