public void Open(System.IO.Stream s) { if (s.ReadInt() != SIG) throw new IrosArcException("Signature mismatch"); Version = s.ReadInt(); Flags = (ArchiveFlags)s.ReadInt(); Directory = s.ReadInt(); if (Version < MIN_VERSION) throw new IrosArcException("Invalid header version " + Version.ToString()); if (Version > MAX_VERSION) throw new IrosArcException("Invalid header version " + Version.ToString()); }
public void Open(System.IO.Stream s, int version) { long pos = s.Position; ushort len = s.ReadUShort(); ushort flen = s.ReadUShort(); byte[] fn = new byte[flen]; s.Read(fn, 0, flen); Filename = System.Text.Encoding.Unicode.GetString(fn); Flags = (FileFlags)s.ReadInt(); if (version < 0x10001) Offset = s.ReadInt(); else Offset = s.ReadLong(); Length = s.ReadInt(); s.Position = pos + len; }
public static DataFile LoadLGP(System.IO.Stream fs, string file) { DataFile df = new DataFile() { Filename = file }; if (fs.ReadUShort() != 0) { throw new Exception(file + " - not a valid LGP archive"); } byte[] header = new byte[10]; fs.Read(header, 0, 10); if (!Encoding.ASCII.GetString(header).Equals("SQUARESOFT")) { throw new Exception(file + " - not a valid LGP archive"); } int count = fs.ReadInt(); byte[] fname = new byte[20]; List <Tuple <string, uint, ushort, int> > files = new List <Tuple <string, uint, ushort, int> >(); for (int i = 0; i < count; i++) { fs.Read(fname, 0, 20); uint offset = fs.ReadUInt(); fs.ReadByte(); ushort dupe = fs.ReadUShort(); string lgpFile = Encoding.ASCII.GetString(fname); int nPos = lgpFile.IndexOf('\0'); if (nPos >= 0) { lgpFile = lgpFile.Substring(0, nPos); } files.Add(new Tuple <string, uint, ushort, int>(lgpFile, offset, dupe, i)); } if (files.Any(t => t.Item3 != 0)) { fs.Seek(3600, System.IO.SeekOrigin.Current); //skip lookup table ushort entries = fs.ReadUShort(); byte[] pname = new byte[128]; foreach (int i in Enumerable.Range(0, entries)) { foreach (int j in Enumerable.Range(0, fs.ReadUShort())) { fs.Read(pname, 0, 128); ushort toc = fs.ReadUShort(); string ppname = Encoding.ASCII.GetString(pname); ppname = ppname.Substring(0, ppname.IndexOf('\0')); files[toc] = new Tuple <string, uint, ushort, int>( ppname.Replace("/", "\\") + "\\" + files[toc].Item1, files[toc].Item2, files[toc].Item3, files[toc].Item4 ); } } } df.Items = files.Select(t => new DataItem() { Name = t.Item1, Start = t.Item2, Index = t.Item4 }).ToList(); foreach (var item in df.Items) { fs.Position = item.Start + 20; item.Length = fs.ReadInt() + 24; //item.Start = item.Start; } df.Freeze(); return(df); }
// Loads an LGP archive into a stream public static DataFile LoadLGP(System.IO.Stream fs, string file) { DataFile df = new DataFile() { Filename = file }; // Checks that LGP starts with 00 then that SQUARESOFT is stated if (fs.ReadUShort() != 0) { throw new Exception(file + " - not a valid LGP archive"); } byte[] header = new byte[10]; fs.Read(header, 0, 10); if (!Encoding.ASCII.GetString(header).Equals("SQUARESOFT")) { throw new Exception(file + " - not a valid LGP archive"); } // Takes the field name (20 bytes) // The offset it points to (4 byte integer) // Check code (1 byte) // Appended if file name is duplicate (2 byte short) int count = fs.ReadInt(); byte[] fname = new byte[20]; List <Tuple <string, uint, ushort, int> > files = new List <Tuple <string, uint, ushort, int> >(); for (int i = 0; i < count; i++) { fs.Read(fname, 0, 20); // Field Name uint offset = fs.ReadUInt(); // Offset fs.ReadByte(); // Check Code ushort dupe = fs.ReadUShort(); // Dupe Name ID string lgpFile = Encoding.ASCII.GetString(fname); int nPos = lgpFile.IndexOf('\0'); if (nPos >= 0) { lgpFile = lgpFile.Substring(0, nPos); } files.Add(new Tuple <string, uint, ushort, int>(lgpFile, offset, dupe, i)); } if (files.Any(t => t.Item3 != 0)) { // Skip lookup table fs.Seek(3600, System.IO.SeekOrigin.Current); ushort entries = fs.ReadUShort(); byte[] pname = new byte[128]; foreach (int i in Enumerable.Range(0, entries)) { foreach (int j in Enumerable.Range(0, fs.ReadUShort())) { fs.Read(pname, 0, 128); ushort toc = fs.ReadUShort(); string ppname = Encoding.ASCII.GetString(pname); ppname = ppname.Substring(0, ppname.IndexOf('\0')); files[toc] = new Tuple <string, uint, ushort, int>( ppname.Replace("/", "\\") + "\\" + files[toc].Item1, files[toc].Item2, files[toc].Item3, files[toc].Item4 ); } } } // Derives start position and length for each field file df.Items = files.Select(t => new DataItem() { Name = t.Item1, Start = t.Item2, Index = t.Item4 }).ToList(); foreach (var item in df.Items) { fs.Position = item.Start + 20; // Skips the name of the file on the field item.Length = fs.ReadInt() + 24; // Takes the file length header on the field } df.Freeze(); return(df); }