public RtlvTextFile LoadRtlvFile(string path, string category) { RtlvTextFile file = null; using (var inFile = File.Open(path, FileMode.Open)) using (var reader = new GlacierRtlvBinaryReader(inFile, _version)) { file = reader.ReadFile(); file.Name = Path.GetFileName(path); file.Extra = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); file.Category = category; } return(file); }
public void Write(RtlvTextFile file) { Write(file.Header); this.WriteUInt32BE((UInt32)(file.FileSize - 16)); Write(file.StaticContext); Write(file.Identifier); Write(file.StaticContext2); Write(file.Sections.Count); for (var i = 0; i < file.Sections.Count; i++) { Write(file.Sections[i].SectionLength); Write(file.Sections[i].Unknown); Write(file.Sections[i].Zeros); Write(file.Sections[i].StartingOffset); Write(file.Sections[i].Zeros2); } }
public RtlvTextFile ReadFile() { var file = new RtlvTextFile(); var cypherStrategy = new CypherStrategyTEA(); BaseStream.Seek(24, SeekOrigin.Begin); var staticContext1Size = 0; var check = ReadInt32(); if (check == 136) { staticContext1Size = 168; } else if (check == 120) { staticContext1Size = 140; } else { throw new Exception(); } BaseStream.Seek(88, SeekOrigin.Begin); var startOfLanguageSections = ReadInt32() + 12; BaseStream.Seek(0, SeekOrigin.Begin); file.Header = ReadBytes(8); file.FileSize = this.ReadUInt32BE(); file.StaticContext = ReadBytes(staticContext1Size); file.Identifier = ReadUInt32(); file.StaticContext2 = ReadBytes(startOfLanguageSections - (int)BaseStream.Position); var numberOfLanguages = ReadUInt32(); for (var i = 0; i < numberOfLanguages; i++) { var section = new RtvlLanguageSection(); section.SectionLength = ReadInt16(); section.Unknown = ReadInt16(); section.Zeros = ReadInt32(); section.StartingOffset = ReadInt32(); section.Zeros2 = ReadInt32(); file.Sections.Add(section); } for (var i = 0; i < numberOfLanguages; i++) { var length = ReadInt32(); byte[] bytes = ReadBytes(length); if (length == 0) { ReadInt32(); } file.Sections[i].Lines.Add(cypherStrategy.Decypher(bytes)); } return(file); }