public void Load(string path) { var br = new LatinBinaryReader(File.OpenRead(path)); var h = new ErfHeader(br); _lDesc = new Dictionary <uint, string>(); var keys = new List <ErfKeyFrame>(); var values = new List <ErfResFrame>(); br.Stream.Position = h.OffsetToLocalizedString; for (var i = 0; i < h.LanguageCount; i++) { var langId = br.ReadUInt32(); var strSize = br.ReadUInt32(); var str = new string(br.ReadChars((int)strSize)).TrimEnd('\0'); _lDesc.Add(langId, str); } br.Stream.Position = h.OffsetToKeyList; for (var i = 0; i < h.EntryCount; i++) { var resref = new ResRef(br.ReadChars(ResRef.Length)); br.ReadUInt32(); // ResId var restype = (ResType)br.ReadUInt16(); br.ReadUInt16(); // Unused keys.Add(new ErfKeyFrame(resref, restype)); } br.Stream.Position = h.OffsetToResourceList; for (var i = 0; i < h.EntryCount; i++) { values.Add(new ErfResFrame(br.ReadUInt32(), br.ReadUInt32())); } for (var i = 0; i < h.EntryCount; i++) { Add(new ContentObject(path, keys[i].ResRef, keys[i].ResType, values[i].OffsetToResource, values[i].ResourceSize)); } }
public void Load(string path) { if (File.Exists(path)) { if (Path.GetExtension(path) == Ext) { var lBf = new List <BiffFile>(); var br = new LatinBinaryReader(File.OpenRead(path)); var kh = new KeyHeader(br); br.Stream.Position = kh.OffsetToFileTable; for (var i = 0; i < kh.BiffCount; i++) { br.Stream.Seek(sizeof(uint), SeekOrigin.Current); var nameOffset = br.ReadUInt32(); var nameSize = br.ReadUInt16(); br.Stream.Seek(sizeof(ushort), SeekOrigin.Current); var pos = br.Stream.Position; br.Stream.Position = nameOffset; var name = new string(br.ReadChars(nameSize)).TrimEnd('\0').ToLower(); br.Stream.Position = pos; lBf.Add(new BiffFile(Path.GetDirectoryName(path) + "/" + name)); } br.Stream.Position = kh.OffsetToKeyTable; for (var i = 0; i < kh.KeyCount; i++) { var resref = new ResRef(br.ReadChars(ResRef.Length)); br.Stream.Seek(sizeof(ushort), SeekOrigin.Current); var rawid = br.ReadUInt32(); var biffId = (int)(rawid >> BitShift); var resId = (int)(rawid - (biffId << BitShift)); var res = lBf[biffId][resId]; Add(new ContentObject(lBf[biffId].FilePath, resref, res.ResType, res.Offset, res.Size)); } } else { throw new ApplicationException("Le fichier n'est pas un fichier .key valide."); } } else { throw new ApplicationException("Le fichier n'existe pas."); } }