public string ParamListToString() { Uarray arr = (Uarray)((UClass)Parser.type.Members[4]).Members[0]; UType[] GenericMono = arr.Value; StringBuilder sb = new StringBuilder(); for (int i = 0; i < GenericMono.Length; i++) { UClass vectorList = (UClass)GenericMono[i].Members[0]; arr = (Uarray)vectorList.Members[0]; UType[] Strings = arr.Value; for (int j = 0; j < Strings.Length; j++) { sb.Append("<"); int wordStart = sb.Length; string word = ((UClass)Strings[j]).GetString(); sb.Append(word); sb.Replace("\\", "\\\\", wordStart, sb.Length - wordStart); sb.Replace("<", "\\<", wordStart, sb.Length - wordStart); sb.Replace(">", "\\>", wordStart, sb.Length - wordStart); sb.Append(">"); } sb.Append("\r\n"); } return(sb.ToString()); }
UClass GenerateType(AssetCabinet.TypeDefinition typeDef) { UClass cls = new UClass(typeDef.definitions.type, typeDef.definitions.identifier); for (int i = 0; i < typeDef.definitions.children.Length; i++) { AssetCabinet.TypeDefinitionString memberDef = typeDef.definitions.children[i]; UType member = GetMember(memberDef); cls.Members.Add(member); } return cls; }
UClass GenerateType(AssetCabinet.TypeDefinition typeDef) { UClass cls = new UClass(typeDef.definitions.type, typeDef.definitions.identifier); for (int i = 0; i < typeDef.definitions.children.Length; i++) { AssetCabinet.TypeDefinitionString memberDef = typeDef.definitions.children[i]; UType member = GetMember(memberDef); cls.Members.Add(member); } return(cls); }
static void MovePointersUClass(UClass c, Component old, Component replacement, AssetCabinet destFile) { string s = c.GetString(); if (s == null) { for (int i = 0; i < c.Members.Count; i++) { MovePointersUType(c.Members[i], old, replacement, destFile); } } }
static void UpdatePointersUClass(UClass c) { string s = c.GetString(); if (s == null) { for (int i = 0; i < c.Members.Count; i++) { UpdatePointersUType(c.Members[i]); } } }
public UClass(UClass cls) { ClassName = cls.ClassName; Name = cls.Name; for (int i = 0; i < cls.Members.Count; i++) { Type t = cls.Members[i].GetType(); ConstructorInfo info = t.GetConstructor(new Type[] { t }); Members.Add((UType)info.Invoke(new object[] { cls.Members[i] })); } }
public void Export(string path) { DirectoryInfo dirInfo = new DirectoryInfo(path); if (!dirInfo.Exists) { dirInfo.Create(); } if (Parser.type.Members.Count > 4 && Parser.type.Members[4] is UClass && ((UClass)Parser.type.Members[4]).ClassName == "Param" && ((UClass)Parser.type.Members[4]).Name == "list") { Uarray arr = (Uarray)((UClass)Parser.type.Members[4]).Members[0]; UType[] GenericMono = arr.Value; using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(path + "\\" + m_Name + "." + UnityClassID.MonoBehaviour), System.Text.Encoding.UTF8)) { for (int i = 0; i < GenericMono.Length; i++) { UClass vectorList = (UClass)GenericMono[i].Members[0]; arr = (Uarray)vectorList.Members[0]; UType[] Strings = arr.Value; for (int j = 0; j < Strings.Length; j++) { string word = ((UClass)Strings[j]).GetString(); for (int k = 0; k < word.Length; k++) { if (word[k] == '<' || word[k] == '>' || word[k] == '\\') { word = word.Substring(0, k) + "\\" + word.Substring(k); } } writer.Write(System.Text.Encoding.UTF8.GetBytes("<" + word + ">")); } writer.Write(System.Text.Encoding.UTF8.GetBytes("\r\n")); } writer.BaseStream.SetLength(writer.BaseStream.Position); } } else { string name = m_GameObject.instance != null ? m_GameObject.instance.m_Name : m_Name; using (FileStream stream = File.OpenWrite(path + "\\" + name + "." + UnityClassID.MonoBehaviour)) { Parser.type.WriteTo(stream); stream.SetLength(stream.Position); } } }
UType GetMember(AssetCabinet.TypeDefinitionString member) { switch (member.type) { case "char": return(new Uchar(member.identifier)); case "bool": case "UInt8": return(new Uint8(member.identifier)); case "int": return(new Uint32(member.identifier)); case "unsigned int": return(new Uuint32(member.identifier)); case "float": return(new Ufloat(member.identifier)); } UType cls; if (member.type.StartsWith("PPtr<") && member.type.EndsWith(">")) { cls = new UPPtr(file, member.identifier); } else if (member.type == "Array") { cls = new Uarray(); } else { cls = new UClass(member.type, member.identifier); } for (int i = 0; i < member.children.Length; i++) { AssetCabinet.TypeDefinitionString memberDef = member.children[i]; UType submember = GetMember(memberDef); cls.Members.Add(submember); } return(cls); }
public static MonoBehaviour Import(string filePath, AssetCabinet file) { foreach (var typeDef in file.Types) { if (typeDef.definitions.type == UnityClassID.MonoBehaviour.ToString() && typeDef.definitions.children.Length > 4) { var member = typeDef.definitions.children[4]; if (member.type == "Param" && member.identifier == "list") { MonoBehaviour m = new MonoBehaviour(null, 0, (UnityClassID)typeDef.typeId, UnityClassID.MonoBehaviour); m.Parser = new TypeParser(file, typeDef); m.m_Name = Path.GetFileNameWithoutExtension(filePath); Uarray ParamListArr = (Uarray)m.Parser.type.Members[4].Members[0]; List <Line> lines = LoadLines(filePath); ParamListArr.Value = new UType[lines.Count]; Type genericMonoType = ParamListArr.Members[1].GetType(); ConstructorInfo genericMonoCtrInfo = genericMonoType.GetConstructor(new Type[] { genericMonoType }); for (int i = 0; i < lines.Count; i++) { ParamListArr.Value[i] = (UType)genericMonoCtrInfo.Invoke(new object[] { ParamListArr.Members[1] }); UClass GenericMonoData = (UClass)ParamListArr.Value[i]; Uarray vectorListArr = (Uarray)GenericMonoData.Members[0].Members[0]; UClass[] Strings = new UClass[lines[i].m_Words.Count]; vectorListArr.Value = Strings; Type stringType = vectorListArr.Members[1].GetType(); ConstructorInfo stringCtrInfo = genericMonoType.GetConstructor(new Type[] { stringType }); for (int j = 0; j < lines[i].m_Words.Count; j++) { Strings[j] = (UClass)stringCtrInfo.Invoke(new object[] { vectorListArr.Members[1] }); Strings[j].SetString(lines[i].m_Words[j]); } } return(m); } } } Report.ReportLog("Warning! No definition of required type found!"); return(null); }
UType GetMember(AssetCabinet.TypeDefinitionString member) { switch (member.type) { case "char": return new Uchar(member.identifier); case "bool": case "UInt8": return new Uint8(member.identifier); case "int": return new Uint32(member.identifier); case "unsigned int": return new Uuint32(member.identifier); case "float": return new Ufloat(member.identifier); } UType cls; if (member.type.StartsWith("PPtr<") && member.type.EndsWith(">")) { cls = new UPPtr(file, member.identifier); } else if (member.type == "Array") { cls = new Uarray(); } else { cls = new UClass(member.type, member.identifier); } for (int i = 0; i < member.children.Length; i++) { AssetCabinet.TypeDefinitionString memberDef = member.children[i]; UType submember = GetMember(memberDef); cls.Members.Add(submember); } return cls; }
public static void StringToParamList(MonoBehaviour m, List <Line> lines) { Uarray ParamListArr = (Uarray)m.Parser.type.Members[4].Members[0]; ParamListArr.Value = new UType[lines.Count]; Type genericMonoType = ParamListArr.Members[1].GetType(); ConstructorInfo genericMonoCtrInfo = genericMonoType.GetConstructor(new Type[] { genericMonoType }); for (int i = 0; i < lines.Count; i++) { ParamListArr.Value[i] = (UType)genericMonoCtrInfo.Invoke(new object[] { ParamListArr.Members[1] }); UClass GenericMonoData = (UClass)ParamListArr.Value[i]; Uarray vectorListArr = (Uarray)GenericMonoData.Members[0].Members[0]; UClass[] Strings = new UClass[lines[i].m_Words.Count]; vectorListArr.Value = Strings; Type stringType = vectorListArr.Members[1].GetType(); ConstructorInfo stringCtrInfo = genericMonoType.GetConstructor(new Type[] { stringType }); for (int j = 0; j < lines[i].m_Words.Count; j++) { Strings[j] = (UClass)stringCtrInfo.Invoke(new object[] { vectorListArr.Members[1] }); Strings[j].SetString(lines[i].m_Words[j]); } } }
public TypeParser(AssetCabinet file, AssetCabinet.TypeDefinition typeDef) { this.file = file; type = GenerateType(typeDef); }
UType GetMember(AssetCabinet.TypeDefinitionString member) { switch (member.type) { case "char": return(new Uchar(member.identifier, member.align())); case "bool": case "SInt8": case "UInt8": return(new Uint8(member.identifier, member.align())); case "SInt16": return(new Uint16(member.identifier, member.align())); case "UInt16": return(new Uuint16(member.identifier, member.align())); case "int": return(new Uint32(member.identifier, member.align())); case "unsigned int": return(new Uuint32(member.identifier, member.align())); case "int64": return(new Uint64(member.identifier, member.align())); case "UInt64": return(new Uuint64(member.identifier, member.align())); case "float": return(new Ufloat(member.identifier, member.align())); case "double": return(new Udouble(member.identifier, member.align())); } UType cls; if (member.type.StartsWith("PPtr<") && member.type.EndsWith(">")) { cls = new UPPtr(file, member.identifier, member.type, member.align()); } else if (member.type == "Array") { cls = new Uarray(member.align()); } else { if (member.type == "StreamedResource") { cls = new UStreamedResource(member.type, member.identifier, member.align(), file); } else { cls = new UClass(member.type, member.identifier, member.align()); } if (member.children.Length == 0) { Report.ReportLog("Warning! " + member.identifier + " has no members!"); } } for (int i = 0; i < member.children.Length; i++) { AssetCabinet.TypeDefinitionString memberDef = member.children[i]; UType submember = GetMember(memberDef); cls.Members.Add(submember); } return(cls); }
void LoadContents() { dataGridViewContents.Visible = false; dataGridViewContents.Rows.Clear(); dataGridViewContents.Columns.Clear(); TextAsset textAsset = Gui.Scripting.Variables[ParserVar] as TextAsset; if (textAsset != null) { if (textAsset.m_ScriptBuffer != null && textAsset.m_Script == null) { using (BinaryReader reader = new BinaryReader(new MemoryStream(textAsset.m_ScriptBuffer))) { if (textAsset.file.VersionNumber < AssetCabinet.VERSION_5_6_2) { StringBuilder decoded = new StringBuilder(512 * 1024); int numTracks = reader.ReadInt32(); if (numTracks < textAsset.m_ScriptBuffer.Length) { TextAssetMode = TextAssetContents.HONEYSELECT; for (int i = 0; i < numTracks; i++) { decoded.Append(reader.ReadShortName()); int numKeyframes = reader.ReadInt32(); for (int j = 0; j < numKeyframes; j++) { int id = reader.ReadInt32(); float[] fArr = reader.ReadSingleArray(9); decoded.Append('\t').Append(id.ToString()); for (int k = 0; k < fArr.Length; k++) { decoded.Append('\t').Append(fArr[k].ToFloatString()); } } decoded.Append("\r\n"); } checkBoxJoin.CheckedChanged -= checkBoxJoin_CheckedChanged; checkBoxJoin.Checked = true; checkBoxJoin.CheckedChanged += checkBoxJoin_CheckedChanged; } textAsset.m_Script = decoded.ToString(); } else { int numRecords = reader.ReadInt32(); if (numRecords < textAsset.m_ScriptBuffer.Length) { TextAssetMode = TextAssetContents.KOIKATSU_POSES; textAsset.m_Script = KoikatsuPosesTextAsset.ToString(reader); editTextBoxJoinedContent.ReadOnly = true; dataGridViewContents.ReadOnly = true; checkBoxJoin.CheckedChanged -= checkBoxJoin_CheckedChanged; checkBoxJoin.Checked = true; checkBoxJoin.CheckedChanged += checkBoxJoin_CheckedChanged; } else { TextAssetMode = TextAssetContents.KIOKATSU_LIST; kList = new KoikatsuListTextAsset(reader); textAsset.m_Script = kList.ToString(); Text += " [" + kList.GetCategory() + "]"; } } if (reader.BaseStream.Position != textAsset.m_ScriptBuffer.Length) { Report.ReportLog("Warning! Read only x" + reader.BaseStream.Position.ToString("X") + " of x" + textAsset.m_ScriptBuffer.Length.ToString("X") + " bytes"); } } } if (!checkBoxJoin.Checked) { string[] lines = textAsset.m_Script.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); int numColumns = 1; for (int i = 0; i < lines.Length; i++) { string[] words = lines[i].Split('\t'); if (numColumns < words.Length) { numColumns = words.Length; } } for (int i = 0; i < numColumns; i++) { DataGridViewColumn col = new DataGridViewTextBoxColumn(); col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; col.FillWeight = 100; col.HeaderText = i.ToString(); col.MinimumWidth = 10; col.Name = "dataGridViewTextBoxColumn" + i; col.SortMode = DataGridViewColumnSortMode.NotSortable; if (i == 0) { col.Frozen = true; } dataGridViewContents.Columns.Add(col); } int numLines = lines.Length; if (numLines > 0) { if (lines[numLines - 1].Length == 0) { numLines--; } } for (int i = 0; i < numLines; i++) { string[] words = lines[i].Split('\t'); DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dataGridViewContents, words); dataGridViewContents.Rows.Add(row); } if (TextAssetMode == TextAssetContents.KIOKATSU_LIST) { dataGridViewContents.Rows[0].ReadOnly = true; dataGridViewContents.Rows[0].DefaultCellStyle.BackColor = Color.LightSkyBlue; dataGridViewContents.Rows[0].Cells[0].Selected = false; } dataGridViewContents.BringToFront(); } else { string s = textAsset.m_Script; if (s.IndexOf('\r') == -1) { s = s.Replace("\n", "\r\n"); } editTextBoxJoinedContent.Text = s; editTextBoxJoinedContent.BringToFront(); } } else { MonoBehaviour textMB = Gui.Scripting.Variables[ParserVar] as MonoBehaviour; if (textMB != null && textMB.Parser.type.Members.Count > 4 && textMB.Parser.type.Members[4] is UClass && ((UClass)textMB.Parser.type.Members[4]).ClassName == "Param" && ((UClass)textMB.Parser.type.Members[4]).Name == "list") { Uarray arr = (Uarray)((UClass)textMB.Parser.type.Members[4]).Members[0]; UType[] GenericMono = arr.Value; int numColumns = 1; for (int i = 0; i < GenericMono.Length; i++) { UClass vectorList = (UClass)GenericMono[i].Members[0]; arr = (Uarray)vectorList.Members[0]; UType[] Strings = arr.Value; if (numColumns < Strings.Length) { numColumns = Strings.Length; } } for (int i = 0; i < numColumns; i++) { DataGridViewColumn col = new DataGridViewTextBoxColumn(); col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; col.FillWeight = 100; col.HeaderText = i.ToString(); col.MinimumWidth = 10; col.Name = "dataGridViewTextBoxColumn" + i; col.SortMode = DataGridViewColumnSortMode.NotSortable; if (i == 0) { col.Frozen = true; } dataGridViewContents.Columns.Add(col); } for (int i = 0; i < GenericMono.Length; i++) { DataGridViewRow row = new DataGridViewRow(); UClass vectorList = (UClass)GenericMono[i].Members[0]; arr = (Uarray)vectorList.Members[0]; UType[] Strings = arr.Value; string[] words = new string[Strings.Length]; for (int j = 0; j < Strings.Length; j++) { words[j] = ((UClass)Strings[j]).GetString(); } row.CreateCells(dataGridViewContents, words); for (int j = words.Length; j < numColumns; j++) { row.Cells[j].Style.BackColor = Color.Red; row.Cells[j].ReadOnly = true; } dataGridViewContents.Rows.Add(row); } } } dataGridViewContents.Visible = true; }
public static MonoBehaviour Import(string filePath, AssetCabinet file) { foreach (var typeDef in file.Types) { if (typeDef.definitions.type == UnityClassID.MonoBehaviour.ToString() && typeDef.definitions.children.Length > 4) { var member = typeDef.definitions.children[4]; if (member.type == "Param" && member.identifier == "list") { MonoBehaviour m = new MonoBehaviour(null, 0, (UnityClassID)typeDef.typeId, UnityClassID.MonoBehaviour); m.Parser = new TypeParser(file, typeDef); m.m_Name = Path.GetFileNameWithoutExtension(filePath); Uarray ParamListArr = (Uarray)m.Parser.type.Members[4].Members[0]; List<Line> lines = LoadLines(filePath); ParamListArr.Value = new UType[lines.Count]; Type genericMonoType = ParamListArr.Members[1].GetType(); ConstructorInfo genericMonoCtrInfo = genericMonoType.GetConstructor(new Type[] { genericMonoType }); for (int i = 0; i < lines.Count; i++) { ParamListArr.Value[i] = (UType)genericMonoCtrInfo.Invoke(new object[] { ParamListArr.Members[1] }); UClass GenericMonoData = (UClass)ParamListArr.Value[i]; Uarray vectorListArr = (Uarray)GenericMonoData.Members[0].Members[0]; UClass[] Strings = new UClass[lines[i].m_Words.Count]; vectorListArr.Value = Strings; Type stringType = vectorListArr.Members[1].GetType(); ConstructorInfo stringCtrInfo = genericMonoType.GetConstructor(new Type[] { stringType }); for (int j = 0; j < lines[i].m_Words.Count; j++) { Strings[j] = (UClass)stringCtrInfo.Invoke(new object[] { vectorListArr.Members[1] }); Strings[j].SetString(lines[i].m_Words[j]); } } return m; } } } Report.ReportLog("Warning! No definition of required type found!"); return null; }