/// <summary> /// Appends a new KFile to the end of the <see cref="RIM"/>. /// </summary> /// <param name="file">The <see cref="KFile"/> to be added.</param> /// <param name="filename">The name of the file.</param> public void Append_File(KFile file, string filename) { rFile RF = new rFile(); RF.Label = filename; RF.TypeID = Reference_Tables.TypeCodes[file.FileType]; using (MemoryStream ms = new MemoryStream()) { file.Write(ms); RF.File_Data = ms.ToArray(); } File_Table.Add(RF); }
/// <summary> /// Reads Bioware "RIM" Files. /// </summary> /// <param name="s">The Stream from which the File will be Read</param> protected RIM(Stream s) { using (BinaryReader br = new BinaryReader(s)) { FileType = new string(br.ReadChars(4)); Version = new string(br.ReadChars(4)); Unknown = br.ReadBytes(4); int FileCount = br.ReadInt32(); int File_Table_Offset = br.ReadInt32(); IsExtension = br.ReadBoolean(); Reserved = br.ReadBytes(99); List <unordered_rFile> unordered_File_Table = new List <unordered_rFile>(); br.BaseStream.Seek(File_Table_Offset, 0); //File Table for (int i = 0; i < FileCount; i++) { unordered_rFile URF = new unordered_rFile(); rFile RF = new rFile(); RF.Label = new string(br.ReadChars(16)).TrimEnd('\0'); RF.TypeID = br.ReadInt32(); URF.Index = br.ReadInt32(); URF.DataOffset = br.ReadInt32(); URF.DataSize = br.ReadInt32(); URF.rf = RF; unordered_File_Table.Add(URF); } //populate FileData and File_Table foreach (unordered_rFile URF in unordered_File_Table.OrderBy(x => x.Index)) //Deals with rare non-linear index case { br.BaseStream.Seek(URF.DataOffset, SeekOrigin.Begin); URF.rf.File_Data = br.ReadBytes(URF.DataSize); File_Table.Add(URF.rf); } } }