using System; using System.Data; using System.IO; using NIFLib.Enums; namespace NIFLib.Core { public class NiHeader { public string VersionString; public NifVersion Version; public uint UserVersion; public uint UserVersion2; public NiString[] BlockTypes; public ushort[] BlockTypeIndex; public ushort[] BlockSizes; public uint NumBlocks; public uint UnknownUInt; public NiHeader(NiFile file, BinaryReader reader) { var num = 0; var position = reader.BaseStream.Position; while (reader.ReadByte() != 10) { num++; } reader.BaseStream.Position = position; VersionString = new string(reader.ReadChars(num)); reader.ReadByte(); var version = reader.ReadUInt32(); Version = (NifVersion)version; // TODO: determine versions needed by any fiesta client and support only those if (Version >= NifVersion.VER_20_0_0_4) { // TODO: support this version! fiesta uses it throw new Exception($"NIF Version not supported yet: {version}"); } if (Version >= NifVersion.VER_10_1_0_0) { UserVersion = reader.ReadUInt32(); } if (Version >= NifVersion.VER_3_3_0_13) { NumBlocks = reader.ReadUInt32(); } if (Version >= NifVersion.VER_10_1_0_0 && (UserVersion == 10u || UserVersion == 11u)) { UserVersion2 = reader.ReadUInt32(); } if (Version == NifVersion.VER_20_0_0_5) { throw new VersionNotFoundException("Version 20.0.0.5 not supported!"); } if (Version == NifVersion.VER_10_0_1_2) { throw new Exception("NIF Version not supported yet!"); } if (Version >= NifVersion.VER_10_1_0_0 && (UserVersion == 10u || UserVersion == 11u)) { throw new Exception("NIF Version not supported yet!"); } if (Version >= NifVersion.VER_10_0_1_0) { var num2 = reader.ReadUInt16(); BlockTypes = new NiString[num2]; for (var i = 0; i < (int)num2; i++) { BlockTypes[i] = new NiString(file, reader); } BlockTypeIndex = new ushort[NumBlocks]; var num3 = 0; while (num3 < NumBlocks) { BlockTypeIndex[num3] = reader.ReadUInt16(); num3++; } } if (Version >= NifVersion.VER_10_0_1_0) { UnknownUInt = reader.ReadUInt32(); } } } }