public TypeClass(UnityReader reader, DerPopoClassDatabase database) { _database = database; ClassID = reader.ReadInt32(); BaseClassID = reader.ReadInt32(); _namePointer = reader.ReadInt32(); int fieldCount = reader.ReadInt32(); _fields = new TypeField[fieldCount]; int depth = -1; Stack <TypeField> branchStack = new Stack <TypeField>(); for (int i = 0; i < fieldCount; i++) { var field = new TypeField(reader, database); _fields[i] = field; if (field.Depth > depth) { //New child TypeField parent = branchStack.LastOrDefault(); branchStack.Push(field); } else if (field.Depth < depth) { //End of leaf, merge back to other branch while (branchStack.Count > 0) { var branch = branchStack.Pop(); if (branch.Depth == field.Depth) { break; } if (branch.Depth < field.Depth) { throw new NotImplementedException(); } } branchStack.Push(field); } else { //sibling branchStack.Pop(); var parent = branchStack.Count > 0 ? branchStack.Peek() : null; branchStack.Push(field); } depth = field.Depth; } }
public TypeField(UnityReader reader, DerPopoClassDatabase database) { _database = database; _typeNamePointer = reader.ReadInt32(); _fieldNamePointer = reader.ReadInt32(); Depth = reader.ReadByte(); IsArray = reader.ReadBool(); Size = reader.ReadInt32(); if (_database.Header.Version < 1) { throw new NotImplementedException(); } if (_database.Header.Version >= 3) { Version = reader.ReadInt16(); } Flags = reader.ReadInt32(); }
private static void Main(string[] args) { DerPopoClassDatabase db = new DerPopoClassDatabase(); using (FileStream fs = File.OpenRead("TestData\\DerPopo\\unity-5.5.0f3.dat")) { db.Read(fs); db.Write(); } UnityContext context = new LocalUnityContext("TestData\\Assets"); using (FileStream fs = File.OpenRead("TestData\\typedefs.xml")) { XmlSerializer ser = new XmlSerializer(typeof(TypeDatabase)); var myDatabase = (TypeDatabase)ser.Deserialize(fs); foreach (var type in myDatabase.Tables[0].Types) { context.TypeTable.AddTypeNode(type); } } var file = context.LoadFile("level0"); FindScriptsInFile(file); Console.WriteLine("Loading dependencies"); foreach (var dependency in file.Dependencies) { Console.WriteLine($"Dependency: {dependency.AssetPath}"); var loadedDependency = dependency.Load(context); FindScriptsInFile(loadedDependency); } Console.WriteLine(); FindScriptsInFile(file); Console.ReadLine(); }