private void Ttr_list_SelectedIndexChanged(object sender, EventArgs e) { Type_0D type = file.typeTree.pTypes_Unity5[ttr_list.SelectedIndex]; if (type.typeFieldsExCount == 0) { ClassDatabaseType cldt = cldb.classes.First(c => c.classId == type.classId); ttr_type.Text = cldt.name.GetString(cldb); } else { TypeField_0D baseField = type.pTypeFieldsEx[0]; ttr_type.Text = baseField.GetTypeString(type.pStringTable); } ttr_typeid.Text = type.classId.ToString(); ttr_scriptid.Text = type.scriptIndex.ToString(); if (type.unknown5 != 0 || type.unknown6 != 0 || type.unknown7 != 0 || type.unknown8 != 0) { ttr_hash.Text = $"{type.unknown5.ToString("x8")}{type.unknown6.ToString("x8")}{type.unknown7.ToString("x8")}{type.unknown8.ToString("x8")}"; } else { ttr_hash.Text = ""; } if (type.unknown1 != 0 || type.unknown2 != 0 || type.unknown3 != 0 || type.unknown4 != 0) { ttr_monohash.Text = $"{type.unknown1.ToString("x8")}{type.unknown2.ToString("x8")}{type.unknown3.ToString("x8")}{type.unknown4.ToString("x8")}"; } else { ttr_monohash.Text = ""; } }
///////////////////////////////////////////////////////// private static Type_0D CreateEditDifferTypeTree(ClassDatabaseFile cldb) { Type_0D type = C2T5.Cldb2TypeTree(cldb, 0x72); type.scriptIndex = 0x0000; type.unknown1 = Constants.editDifferScriptNEHash[0]; type.unknown2 = Constants.editDifferScriptNEHash[1]; type.unknown3 = Constants.editDifferScriptNEHash[2]; type.unknown4 = Constants.editDifferScriptNEHash[3]; TypeTreeEditor editor = new TypeTreeEditor(type); TypeField_0D baseField = type.pTypeFieldsEx[0]; editor.AddField(baseField, editor.CreateTypeField("unsigned int", "fileId", 1, 4, 0, false)); editor.AddField(baseField, editor.CreateTypeField("UInt64", "pathId", 1, 8, 0, false)); editor.AddField(baseField, editor.CreateTypeField("UInt64", "origPathId", 1, 8, 0, false)); editor.AddField(baseField, editor.CreateTypeField("UInt8", "newAsset", 1, 1, 0, true)); uint componentIds = editor.AddField(baseField, editor.CreateTypeField("vector", "componentIds", 1, uint.MaxValue, 0, false, false, Flags.AnyChildUsesAlignBytesFlag)); uint Array = editor.AddField(editor.type.pTypeFieldsEx[componentIds], editor.CreateTypeField("Array", "Array", 2, uint.MaxValue, 0, true, true)); editor.AddField(editor.type.pTypeFieldsEx[Array], editor.CreateTypeField("int", "size", 3, 4, 0, false)); editor.AddField(editor.type.pTypeFieldsEx[Array], editor.CreateTypeField("SInt64", "data", 3, 8, 0, false)); editor.AddField(baseField, editor.CreateTypeField("int", "instanceId", 1, 4, 0, false)); type = editor.SaveType(); return(type); }
private static void CreateSceneMetadataTypeTree(ClassDatabaseFile cldb, AssetsFileInstance inst) { Type_0D type = C2T5.Cldb2TypeTree(cldb, 0x72); type.scriptIndex = 0x0001; type.unknown1 = Constants.sceneMetadataScriptNEHash[0]; type.unknown2 = Constants.sceneMetadataScriptNEHash[1]; type.unknown3 = Constants.sceneMetadataScriptNEHash[2]; type.unknown4 = Constants.sceneMetadataScriptNEHash[3]; TypeTreeEditor editor = new TypeTreeEditor(type); TypeField_0D baseField = type.pTypeFieldsEx[0]; uint sceneName = editor.AddField(baseField, editor.CreateTypeField("string", "sceneName", 1, uint.MaxValue, 0, false, false, Flags.AnyChildUsesAlignBytesFlag)); uint Array = editor.AddField(editor.type.pTypeFieldsEx[sceneName], editor.CreateTypeField("Array", "Array", 2, uint.MaxValue, 0, true, true, Flags.HideInEditorMask)); editor.AddField(editor.type.pTypeFieldsEx[Array], editor.CreateTypeField("int", "size", 3, 4, 0, false, false, Flags.HideInEditorMask)); editor.AddField(editor.type.pTypeFieldsEx[Array], editor.CreateTypeField("char", "data", 3, 1, 0, false, false, Flags.HideInEditorMask)); uint usedIds = editor.AddField(baseField, editor.CreateTypeField("vector", "usedIds", 1, uint.MaxValue, 0, false, false, Flags.AnyChildUsesAlignBytesFlag)); uint Array2 = editor.AddField(editor.type.pTypeFieldsEx[usedIds], editor.CreateTypeField("Array", "Array", 2, uint.MaxValue, 0, true, true)); editor.AddField(editor.type.pTypeFieldsEx[Array2], editor.CreateTypeField("int", "size", 3, 4, 0, false)); editor.AddField(editor.type.pTypeFieldsEx[Array2], editor.CreateTypeField("SInt64", "data", 3, 8, 0, false)); editor.AddField(baseField, editor.CreateTypeField("int", "hkweVersion", 1, 4, 0, false)); type = editor.SaveType(); inst.file.typeTree.pTypes_Unity5 = inst.file.typeTree.pTypes_Unity5.Concat(new Type_0D[] { type }).ToArray(); inst.file.typeTree.fieldCount++; }
private void GenerateTtrTree(Type_0D type) { ttr_tree.Nodes.Clear(); List <TreeNode> treeNodeStack = new List <TreeNode>(); TypeField_0D baseField = type.typeFieldsEx[0]; TreeNode rootNode = ttr_tree.Nodes.Add(TypeFieldToString(baseField, type)); rootNode.Tag = baseField; treeNodeStack.Add(rootNode); for (int i = 1; i < type.typeFieldsEx.Length; i++) { TypeField_0D field = type.typeFieldsEx[i]; TreeNode parentNode = treeNodeStack[field.depth - 1]; TreeNode node = parentNode.Nodes.Add(TypeFieldToString(field, type)); node.Tag = field; if (treeNodeStack.Count > field.depth) { treeNodeStack[field.depth] = node; } else { treeNodeStack.Add(node); } } }
private void AssetInfo_Load(object sender, EventArgs e) { AssetsFileHeader header = file.header; TypeTree typeTree = file.typeTree; //header hdr_mds.Text = header.metadataSize.ToString(); hdr_fs.Text = header.fileSize.ToString(); hdr_fmt.Text = $"{header.format.ToString()} (0x{header.format.ToString("x")})"; hdr_ffo.Text = $"{header.firstFileOffset.ToString()} (0x{header.firstFileOffset.ToString("x")})"; hdr_en.Text = header.endianness == 1 ? "big endian" : "little endian"; hdr_uvr.Text = typeTree.unityVersion; hdr_ver.Text = $"{typeTree.version.ToString()} (0x{typeTree.version.ToString("x")})"; hdr_htt.Text = typeTree.hasTypeTree == true ? "true" : "false"; //type tree if (!typeTree.hasTypeTree) { ttr_tree.Nodes.Add("There is no type tree data available."); } else { ttr_tree.Nodes.Add("Select a type to show the type tree data."); } foreach (Type_0D type in typeTree.unity5Types) { if (type.typeFieldsExCount == 0) { ClassDatabaseType cldt = cldb.classes.First(c => c.classId == type.classId); ttr_list.Items.Add($"[{cldt.name.GetString(cldb)}] (0x{type.classId.ToString("x")})"); } else { TypeField_0D baseField = type.typeFieldsEx[0]; ttr_list.Items.Add($"{baseField.GetTypeString(type.stringTable)} (0x{type.classId.ToString("x")})"); } } //preload list foreach (AssetPPtr pptr in file.preloadTable.items) { string pptrFileName = "[self]"; if (pptr.fileID != 0) { pptrFileName = file.dependencies.dependencies[pptr.fileID - 1].assetPath; } plt_list.Items.Add(new ListViewItem(new[] { pptrFileName, pptr.pathID.ToString() })); } plt_list.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); //dependencies foreach (AssetsFileDependency dep in file.dependencies.dependencies) { string guid = string.Empty; if (dep.guid.mostSignificant != 0 || dep.guid.leastSignificant != 0) { guid = $"{dep.guid.mostSignificant.ToString("x8")}{dep.guid.leastSignificant.ToString("x8")}"; } dep_list.Items.Add(new ListViewItem(new[] { dep.assetPath, "0x" + dep.type.ToString(), guid })); } dep_list.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); }
public TypeField_0D Get(TypeField_0D parent, string field) { byte depth = parent.depth; uint curIndex = parent.index + 1; //assuming index is correct uint curDepth; do { TypeField_0D curField = type.typeFieldsEx[curIndex]; curDepth = curField.depth; if (curDepth == depth + 1 && GetString(curField.nameStringOffset) == field) { return(curField); } curIndex++; } while (curDepth > depth); return(new TypeField_0D()); }
public List <TypeField_0D> GetChildren(TypeField_0D parent) { List <TypeField_0D> fields = new List <TypeField_0D>(); byte depth = parent.depth; uint curIndex = parent.index + 1; //assuming index is correct uint curDepth; do { TypeField_0D curField = type.typeFieldsEx[curIndex]; curDepth = curField.depth; if (curDepth == depth + 1) { fields.Add(curField); } curIndex++; } while (curDepth > depth); return(fields); }
public uint AddField(TypeField_0D parent, TypeField_0D field) { byte depth = parent.depth; uint curIndex = parent.index + 1; //assuming index is correct uint curDepth; if (curIndex < type.pTypeFieldsEx.Length) { do { curDepth = type.pTypeFieldsEx[curIndex].depth; curIndex++; } while (curDepth > depth && curIndex < type.pTypeFieldsEx.Length); } field.index = curIndex; UnityEngine.Debug.Log("inserting " + GetString(field.typeStringOffset) + " " + GetString(field.nameStringOffset) + " into " + field.index); //TypeField_0D[] before = new TypeField_0D[curIndex]; //TypeField_0D[] after = new TypeField_0D[type.pTypeFieldsEx.Length - curIndex]; //Array.Copy(type.pTypeFieldsEx, 0, before, 0, before.Length); //Array.Copy(type.pTypeFieldsEx, before.Length, after, 0, after.Length); //type.pTypeFieldsEx = before.Concat(new[] { field }).Concat(after).ToArray(); uint insertIndex = curIndex; TypeField_0D[] dest = new TypeField_0D[type.pTypeFieldsEx.Length + 1]; Array.Copy(type.pTypeFieldsEx, 0, dest, 0, curIndex); dest[curIndex] = field; Array.Copy(type.pTypeFieldsEx, curIndex, dest, curIndex + 1, type.pTypeFieldsEx.Length - curIndex); type.pTypeFieldsEx = dest; type.typeFieldsExCount++; curIndex++; while (curIndex < type.pTypeFieldsEx.Length) { type.pTypeFieldsEx[curIndex].index++; curIndex++; } return(insertIndex); }
private void Ttr_list_SelectedIndexChanged(object sender, EventArgs e) { TypeTree typeTree = file.typeTree; Type_0D type = typeTree.unity5Types[ttr_list.SelectedIndex]; if (type.typeFieldsExCount == 0) { ClassDatabaseType cldt = cldb.classes.First(c => c.classId == type.classId); ttr_type.Text = cldt.name.GetString(cldb); } else { TypeField_0D baseField = type.typeFieldsEx[0]; ttr_type.Text = baseField.GetTypeString(type.stringTable); } ttr_typeid.Text = type.classId.ToString(); ttr_scriptid.Text = type.scriptIndex.ToString(); if (type.typeHash1 != 0 || type.typeHash2 != 0 || type.typeHash3 != 0 || type.typeHash4 != 0) { ttr_hash.Text = $"{type.typeHash1.ToString("x8")}{type.typeHash2.ToString("x8")}{type.typeHash3.ToString("x8")}{type.typeHash4.ToString("x8")}"; } else { ttr_hash.Text = ""; } if (type.scriptHash1 != 0 || type.scriptHash2 != 0 || type.scriptHash3 != 0 || type.scriptHash4 != 0) { ttr_monohash.Text = $"{type.scriptHash1.ToString("x8")}{type.scriptHash2.ToString("x8")}{type.scriptHash3.ToString("x8")}{type.scriptHash4.ToString("x8")}"; } else { ttr_monohash.Text = ""; } if (typeTree.hasTypeTree) { GenerateTtrTree(type); } }
private static Type_0D CreateTk2dEmuTypeTree(ClassDatabaseFile cldb) { Type_0D type = C2T5.Cldb2TypeTree(cldb, 0x72); type.scriptIndex = 0x0001; type.scriptHash1 = Constants.tk2dEmuScriptNEHash[0]; type.scriptHash2 = Constants.tk2dEmuScriptNEHash[1]; type.scriptHash3 = Constants.tk2dEmuScriptNEHash[2]; type.scriptHash4 = Constants.tk2dEmuScriptNEHash[3]; TypeTreeEditor editor = new TypeTreeEditor(type); TypeField_0D baseField = type.typeFieldsEx[0]; uint vertices = editor.AddField(baseField, editor.CreateTypeField("vector", "vertices", 1, -1, 0, false, false, Flags.AnyChildUsesAlignBytesFlag)); uint Array = editor.AddField(editor.type.typeFieldsEx[vertices], editor.CreateTypeField("Array", "Array", 2, -1, 0, true, true)); editor.AddField(editor.type.typeFieldsEx[Array], editor.CreateTypeField("int", "size", 3, 4, 0, false)); uint data = editor.AddField(editor.type.typeFieldsEx[Array], editor.CreateTypeField("Vector3", "data", 3, -1, 0, false)); editor.AddField(editor.type.typeFieldsEx[data], editor.CreateTypeField("float", "x", 4, 4, 0, false)); editor.AddField(editor.type.typeFieldsEx[data], editor.CreateTypeField("float", "y", 4, 4, 0, false)); editor.AddField(editor.type.typeFieldsEx[data], editor.CreateTypeField("float", "z", 4, 4, 0, false)); uint uvs = editor.AddField(baseField, editor.CreateTypeField("vector", "uvs", 1, -1, 0, false, false, Flags.AnyChildUsesAlignBytesFlag)); Array = editor.AddField(editor.type.typeFieldsEx[uvs], editor.CreateTypeField("Array", "Array", 2, -1, 0, true, true)); editor.AddField(editor.type.typeFieldsEx[Array], editor.CreateTypeField("int", "size", 3, 4, 0, false)); data = editor.AddField(editor.type.typeFieldsEx[Array], editor.CreateTypeField("Vector2", "data", 3, -1, 0, false)); editor.AddField(editor.type.typeFieldsEx[data], editor.CreateTypeField("float", "x", 4, 4, 0, false)); editor.AddField(editor.type.typeFieldsEx[data], editor.CreateTypeField("float", "y", 4, 4, 0, false)); uint indices = editor.AddField(baseField, editor.CreateTypeField("vector", "indices", 1, -1, 0, false, false, Flags.AnyChildUsesAlignBytesFlag)); Array = editor.AddField(editor.type.typeFieldsEx[indices], editor.CreateTypeField("Array", "Array", 2, -1, 0, true, true)); editor.AddField(editor.type.typeFieldsEx[Array], editor.CreateTypeField("int", "size", 3, 4, 0, false)); editor.AddField(editor.type.typeFieldsEx[Array], editor.CreateTypeField("int", "data", 3, 4, 0, false)); type = editor.SaveType(); return(type); }
///////////////////////////////////////////////////////// private static void CreateEditDifferTypeTree(ClassDatabaseFile cldb, AssetsFileInstance inst) { Type_0D type = C2T5.Cldb2TypeTree(cldb, 0x72); type.scriptIndex = 0x0000; type.unknown1 = Constants.editDifferScriptNEHash[0]; type.unknown2 = Constants.editDifferScriptNEHash[1]; type.unknown3 = Constants.editDifferScriptNEHash[2]; type.unknown4 = Constants.editDifferScriptNEHash[3]; TypeTreeEditor editor = new TypeTreeEditor(type); TypeField_0D baseField = type.pTypeFieldsEx[0]; editor.AddField(baseField, editor.CreateTypeField("unsigned int", "fileId", 1, 4, 0, false)); editor.AddField(baseField, editor.CreateTypeField("UInt64", "pathId", 1, 8, 0, false)); editor.AddField(baseField, editor.CreateTypeField("UInt64", "origPathId", 1, 8, 0, false)); editor.AddField(baseField, editor.CreateTypeField("UInt8", "newAsset", 1, 1, 0, true)); editor.AddField(baseField, editor.CreateTypeField("int", "instanceId", 1, 4, 0, false)); type = editor.SaveType(); inst.file.typeTree.pTypes_Unity5 = inst.file.typeTree.pTypes_Unity5.Concat(new Type_0D[] { type }).ToArray(); inst.file.typeTree.fieldCount++; }
private void ReadTemplateFields(List <TypeField_0D> typeFields, AssetTypeTemplateField templateField, int depth, bool inString, out bool aligned) { TypeField_0D tf = new TypeField_0D(); int tfPos = typeFields.Count; typeFields.Add(tf); tf.version = 1; tf.depth = (byte)depth; tf.isArray = (byte)(templateField.isArray ? 1 : 0); tf.typeStringOffset = GetStringOffset(templateField.type); tf.nameStringOffset = GetStringOffset(templateField.name); tf.index = (uint)index++; tf.size = GetFieldSize(templateField.valueType); bool anyChildAligned = false; bool currentlyInString = inString | templateField.valueType == EnumValueTypes.ValueType_String; if (templateField.childrenCount > 0) { foreach (AssetTypeTemplateField child in templateField.children) { bool childAligned; ReadTemplateFields(typeFields, child, depth + 1, currentlyInString, out childAligned); anyChildAligned |= childAligned; } } Flags flags = Flags.None; flags |= templateField.align ? Flags.AlignBytesFlag : Flags.None; flags |= inString ? Flags.HideInEditorMask : Flags.None; flags |= anyChildAligned ? Flags.AnyChildUsesAlignBytesFlag : Flags.None; tf.flags = (uint)flags; typeFields[tfPos] = tf; aligned = templateField.align; }
private void ttr_tree_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode node = e.Node; if (node.Tag != null) { TypeField_0D field = (TypeField_0D)node.Tag; ttr_version.Text = field.version.ToString(); ttr_depth.Text = field.depth.ToString(); ttr_isarray.Text = (field.isArray == 1).ToString().ToLower(); ttr_size.Text = field.size.ToString(); ttr_index.Text = field.index.ToString(); ttr_flags.Text = "0x" + field.flags.ToString("X4"); } else { ttr_version.Text = string.Empty; ttr_depth.Text = string.Empty; ttr_isarray.Text = string.Empty; ttr_size.Text = string.Empty; ttr_index.Text = string.Empty; ttr_flags.Text = string.Empty; } }
public uint AddField(TypeField_0D parent, TypeField_0D field) { byte depth = parent.depth; uint curIndex = parent.index + 1; //assuming index is correct uint curDepth; if (curIndex < type.typeFieldsEx.Length) { do { curDepth = type.typeFieldsEx[curIndex].depth; curIndex++; } while (curDepth > depth && curIndex < type.typeFieldsEx.Length); } field.index = curIndex; uint insertIndex = curIndex; TypeField_0D[] dest = new TypeField_0D[type.typeFieldsEx.Length + 1]; Array.Copy(type.typeFieldsEx, 0, dest, 0, curIndex); dest[curIndex] = field; Array.Copy(type.typeFieldsEx, curIndex, dest, curIndex + 1, type.typeFieldsEx.Length - curIndex); type.typeFieldsEx = dest; type.typeFieldsExCount++; curIndex++; while (curIndex < type.typeFieldsEx.Length) { type.typeFieldsEx[curIndex].index++; curIndex++; } return(insertIndex); }
private string TypeFieldToString(TypeField_0D field, Type_0D type) { string stringTable = type.stringTable; return($"{field.GetTypeString(stringTable)} {field.GetNameString(stringTable)}"); }