public void addFile(string filename, Stream toImport) { MiniAfsFileEntry temp = new MiniAfsFileEntry(); temp.fileName = filename; BinaryReader beta = new BinaryReader(toImport); toImport.Seek(0, SeekOrigin.Begin); temp.rawContents = beta.ReadBytes((int)toImport.Length); if (ASCIIEncoding.GetEncoding("ASCII").GetString(temp.rawContents, 0, 3) == "AFS") { temp.fileContents = new AfsLoader(new MemoryStream(temp.rawContents)); } else if (ASCIIEncoding.GetEncoding("ASCII").GetString(temp.rawContents, 0, 4) == "NMLL") { temp.fileContents = new NblLoader(new MemoryStream(temp.rawContents)); } afsList.Add(temp); }
public MiniAfsLoader(Stream fileToLoad) { BinaryReader fileLoader = new BinaryReader(fileToLoad); fileToLoad.Seek(0, SeekOrigin.Begin); if (fileLoader.ReadInt16() != 0x50AF) { Console.Out.WriteLine("Invalid file."); } int fileCount = fileLoader.ReadInt16(); fileLoader.ReadInt32(); //Discarding the unknown. afsList = new List <MiniAfsFileEntry>(fileCount); for (int i = 0; i < fileCount; i++) { MiniAfsFileEntry temp = new MiniAfsFileEntry(); temp.location = fileLoader.ReadUInt16() * 0x800; afsList.Add(temp); } int headerLoc = fileLoader.ReadUInt16() * 0x800; fileToLoad.Seek(headerLoc, SeekOrigin.Begin); for (int i = 0; i < fileCount; i++) { afsList[i].fileName = new string(fileLoader.ReadChars(0x20)).TrimEnd('\0'); afsList[i].year = fileLoader.ReadUInt16(); afsList[i].month = fileLoader.ReadUInt16(); afsList[i].day = fileLoader.ReadUInt16(); afsList[i].hour = fileLoader.ReadUInt16(); afsList[i].minute = fileLoader.ReadUInt16(); afsList[i].second = fileLoader.ReadUInt16(); afsList[i].garbageInt = fileLoader.ReadUInt32(); } for (int i = 0; i < fileCount; i++) { fileToLoad.Seek(afsList[i].location, SeekOrigin.Begin); int nextLocation = (i + 1) < fileCount ? afsList[i + 1].location : headerLoc; int fileLength = nextLocation - afsList[i].location; afsList[i].rawContents = fileLoader.ReadBytes(fileLength); } for (int i = 0; i < fileCount; i++) { if (afsList[i].rawContents.Length > 3) { string headerName = ASCIIEncoding.GetEncoding("ASCII").GetString(afsList[i].rawContents, 0, 4); if (headerName.StartsWith("AFS")) { afsList[i].fileContents = new AfsLoader(new MemoryStream(afsList[i].rawContents)); } else if (headerName == "NMLL" || headerName == "NMLB") { afsList[i].fileContents = new NblLoader(new MemoryStream(afsList[i].rawContents)); } } } fileLoader.Close(); fileLoader.Dispose(); return; }