public static TNN_File Parse(string path, bool writeXml) { TNN_File file = Parse(File.ReadAllBytes(path)); if (writeXml) { YAXSerializer serializer = new YAXSerializer(typeof(TNN_File)); serializer.SerializeToFile(file, path + ".xml"); } return(file); }
public static TNN_File Parse(byte[] bytes) { TNN_File tnn = new TNN_File(); int numEntries = BitConverter.ToInt32(bytes, 0); int offset = 4; int totalSub = 0; for (int i = 0; i < numEntries; i++) { TNN_Entry entry = new TNN_Entry(); entry.I_00 = BitConverter.ToInt32(bytes, offset + 0); entry.I_04 = BitConverter.ToInt32(bytes, offset + 4); int numSubEntires = BitConverter.ToInt32(bytes, offset + 8); offset += 12; for (int a = 0; a < numSubEntires; a++) { TNN_SubEntry subEntry = new TNN_SubEntry(); subEntry.I_00 = BitConverter.ToInt32(bytes, offset + 0); subEntry.I_04 = BitConverter.ToInt32(bytes, offset + 4); subEntry.I_08 = BitConverter.ToInt32(bytes, offset + 8); entry.SubEntries.Add(subEntry); offset += 12; totalSub++; } tnn.Entries.Add(entry); } //strings List <string> strings = new List <string>(); while (offset < bytes.Length) { string str = StringEx.GetString(bytes, offset, false, StringEx.EncodingType.Unicode); int estSize = str.Length * 2; try { while (bytes[estSize + offset] == 0) { estSize++; } } catch (IndexOutOfRangeException ex) { } offset += estSize; strings.Add(str); } tnn.Strings = strings; //Check //if (strings.Count != (totalSub * 7) + numEntries) // throw new Exception("nope"); return(tnn); }