public KeyHeader(LatinBinaryReader br) { // On passe le type et la version de fichier. br.BaseStream.Seek(FileTypeLength + FileVersionLength, SeekOrigin.Current); BiffCount = br.ReadUInt32(); KeyCount = br.ReadUInt32(); OffsetToFileTable = br.ReadUInt32(); OffsetToKeyTable = br.ReadUInt32(); br.BaseStream.Seek(sizeof(int) * 2 + ReservedSize, SeekOrigin.Current); //BuildYear = br.ReadUInt32(); //BuildDay = br.ReadUInt32(); //Reserved = br.ReadBytes(ReservedSize); }
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."); } }
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)); } }
private void Load(string path) { FilePath = path; if (!File.Exists(path)) { throw new ApplicationException("Le fichier n'existe pas."); } var br = new LatinBinaryReader(File.OpenRead(path)); var hd = new BiffHeader(br); _lVr = new Dictionary <int, BiffResource>((int)hd.VarResCount); br.Stream.Position = hd.VarTableOffset; for (var i = 0; i < hd.VarResCount; i++) { // On dégage l'id qui sert à rien : br.BaseStream.Seek(sizeof(int), SeekOrigin.Current); var bvr = new BiffResource(br.ReadUInt32(), br.ReadUInt32(), (ResType)br.ReadUInt32()); _lVr.Add(i, bvr); } }
public void Parse(GffField fld) { if (fld.Type != GffType.CExoLocString) { throw new ApplicationException("Impossible de parser ce type " + Enum.GetName(typeof(GffType), fld.Type) + " en ExoLocString."); } var br = new LatinBinaryReader(new MemoryStream(fld.Bytes)); _strref = (int)br.ReadUInt32(); var strcount = br.ReadUInt32(); _dic = new Dictionary <int, string>((int)strcount); for (var i = 0; i < strcount; i++) { var id = br.ReadInt32(); var size = br.ReadInt32(); _dic.Add(id, new string(br.ReadChars(size))); } }
public readonly uint VarTableOffset; // DWORD public BiffHeader(LatinBinaryReader br) { var pos = br.Stream.Position; br.Stream.Position = 0; // Inutile : //_fileType = new string(br.ReadChars(FileTypeLength)); //_version = new string(br.ReadChars(VersionLength)); // Remplacé par : br.BaseStream.Seek(FileTypeLength, SeekOrigin.Current); br.BaseStream.Seek(VersionLength, SeekOrigin.Current); // -------------- VarResCount = br.ReadUInt32(); // Inutile : // FixResCount = br.ReadUInt32(); // Remplacé par : br.BaseStream.Seek(sizeof(int), SeekOrigin.Current); // -------------- VarTableOffset = br.ReadUInt32(); br.Stream.Position = pos; }
private GffComponent CreateComponent(uint fIndex) { MemoryStream dataStream; var f = _gbase.FieldArray[(int)fIndex]; var fLblId = f.LabelIndex; var fLbl = _gbase.LabelArray[(int)fLblId]; // if (fLbl == null) { // throw new NotImplementedException(); // } var fType = (GffType)f.Type; if (GffComponent.IsComposite(fType)) { if (fType == GffType.Struct) { // On va chercher la frame qui lui correspond. var sIndex = f.DataOrDataOffset; var s = _gbase.StructArray[(int)sIndex]; var sType = s.Type; var vs = new GffInFieldStruct(fLbl, sType); PopulateStruct(vs, GetStructFieldIndices(s)); return(vs); } if (fType == GffType.List) { var br = new LatinBinaryReader(_gbase.ListIndicesArray) { Stream = { Position = f.DataOrDataOffset } }; var size = (int)br.ReadUInt32(); var vl = new GffList(fLbl); var structIdList = br.GetUInt32List(size); foreach (var structId in structIdList) { var sFrame = _gbase.StructArray[(int)structId]; var vls = new GffInListStruct(sFrame.Type); PopulateStruct(vls, GetStructFieldIndices(sFrame)); vl.Add(vls); } return(vl); } throw new CompositeException(ErrorLabels.UnknownCompositeType); } if (GffComponent.IsSimple(fType)) { dataStream = new MemoryStream(BitConverter.GetBytes(f.DataOrDataOffset)); } else if (GffComponent.IsLarge(fType)) { var br = new LatinBinaryReader(_gbase.FieldDataBlock); var pos = br.Stream.Position; br.Stream.Position = f.DataOrDataOffset; var size = 0; #region Switch de détermination de la taille. switch (fType) { case GffType.Dword64: size = 8; break; case GffType.Int64: size = sizeof(long); break; case GffType.Double: size = sizeof(double); break; case GffType.ResRef: size = br.ReadByte(); break; case GffType.CExoString: case GffType.CExoLocString: case GffType.Void: size = (int)br.ReadUInt32(); break; case GffType.Byte: break; case GffType.Char: break; case GffType.Word: break; case GffType.Short: break; case GffType.Dword: break; case GffType.Int: break; case GffType.Float: break; case GffType.Struct: break; case GffType.List: break; case GffType.Invalid: break; default: throw new FieldException(ErrorLabels.UnknownLargeFieldType); } #endregion dataStream = new MemoryStream(br.ReadBytes(size)); br.Stream.Position = pos; } else { throw new FieldException(ErrorLabels.UnknownFieldType); } return(new GffField(fLbl, fType, dataStream.ToArray())); }