/// <summary> /// Read a Boolean from the Stream Depending on Nif Version /// </summary> /// <param name="reader">Reader</param> /// <param name="version">Nif Object Version</param> /// <returns>bool from Int or Byte</returns> public static bool ReadBoolean(this BinaryReader reader, eNifVersion version) { if (version < eNifVersion.VER_4_1_0_1) return reader.ReadUInt32() != 0; return reader.ReadBoolean(); }
/// <summary> /// Read a Boolean from the Stream Depending on Nif Version /// </summary> /// <param name="reader">Reader</param> /// <param name="version">Nif Object Version</param> /// <returns>bool from Int or Byte</returns> public static bool ReadBoolean(this BinaryReader reader, eNifVersion version) { if (version < eNifVersion.VER_4_1_0_1) { return(reader.ReadUInt32() != 0); } return(reader.ReadBoolean()); }
/// <summary> /// Write a Boolean from the Stream Depending on Nif Version /// </summary> /// <param name="writer">Writer</param> /// <param name="version">Nif Object Version</param> /// <param name="value">Bool value to write.</param> public static void WriteBoolean(this BinaryWriter writer, bool value, eNifVersion version) { if (version < eNifVersion.VER_4_1_0_1) { writer.Write(Convert.ToUInt32(value)); } else { writer.Write(value); } }
/// <summary> /// Writes TexDesc to binary stream. /// </summary> /// <param name="writer">The writer.</param> public void WriteTexDesc(BinaryWriter writer, eNifVersion version) { this.Source.WriteNiRef(writer); if (version <= eNifVersion.VER_20_0_0_5) { writer.Write((uint)this.ClampMode); writer.Write((uint)this.FilterMode); } if (version >= eNifVersion.VER_20_1_0_3) { writer.Write((ushort)this.Flags); } if (version <= eNifVersion.VER_20_0_0_5) { writer.Write((uint)this.UVSetIndex); } if (version <= eNifVersion.VER_10_4_0_1) { writer.Write((short)this.PS2L); writer.Write((short)this.PS2K); } if (version <= eNifVersion.VER_4_1_0_12) { //reader.ReadUInt16(); writer.Write((ushort)0); } if (version >= eNifVersion.VER_10_1_0_0) { writer.WriteBoolean(this.HasTextureTransform, version); if (this.HasTextureTransform) { writer.WriteVector2(this.Translation); writer.WriteVector2(this.Tiling); writer.Write((float)this.WRotation); writer.Write((uint)this.TransformType); writer.WriteVector2(this.CenterOffset); } } }
/// <summary> /// Initializes a new instance of the <see cref="NiHeader"/> class. /// </summary> /// <param name="file">The file.</param> /// <param name="reader">The reader.</param> /// <exception cref="Exception"> /// NIF Version not supported yet! /// or /// NIF Version not supported yet! /// or /// NIF Version not supported yet! /// or /// NIF Version not supported yet! /// or /// NIF Version not supported yet! /// </exception> /// <exception cref="VersionNotFoundException">Version 20.0.0.5 not supported!</exception> public NiHeader(NiFile file, BinaryReader reader) { int num = 0; long position = reader.BaseStream.Position; while (reader.ReadByte() != 10) { num++; } reader.BaseStream.Position = position; this.VersionString = new string(reader.ReadChars(num)); reader.ReadByte(); uint version = reader.ReadUInt32(); this.Version = (eNifVersion)version; if (this.Version >= eNifVersion.VER_20_0_0_4) { throw new Exception("NIF Version not supported yet!"); } if (this.Version >= eNifVersion.VER_10_1_0_0) { this.UserVersion = reader.ReadUInt32(); } if (this.Version >= eNifVersion.VER_3_3_0_13) { this.NumBlocks = reader.ReadUInt32(); } if (this.Version >= eNifVersion.VER_10_1_0_0 && (this.UserVersion == 10u || this.UserVersion == 11u)) { this.UserVersion2 = reader.ReadUInt32(); } if (this.Version == eNifVersion.VER_20_0_0_5) { throw new VersionNotFoundException("Version 20.0.0.5 not supported!"); } if (this.Version == eNifVersion.VER_10_0_1_2) { throw new Exception("NIF Version not supported yet!"); } if (this.Version >= eNifVersion.VER_10_1_0_0 && (this.UserVersion == 10u || this.UserVersion == 11u)) { throw new Exception("NIF Version not supported yet!"); } if (this.Version >= eNifVersion.VER_10_0_1_0) { ushort num2 = reader.ReadUInt16(); this.BlockTypes = new NiString[(int)num2]; for (int i = 0; i < (int)num2; i++) { this.BlockTypes[i] = new NiString(file, reader); } this.BlockTypeIndex = new ushort[this.NumBlocks]; int num3 = 0; while ((long)num3 < (long)((ulong)this.NumBlocks)) { this.BlockTypeIndex[num3] = reader.ReadUInt16(); num3++; } } if (this.Version >= eNifVersion.VER_20_2_0_7) { throw new Exception("NIF Version not supported yet!"); } if (this.Version >= eNifVersion.VER_20_1_0_3) { throw new Exception("NIF Version not supported yet!"); } if (this.Version >= eNifVersion.VER_10_0_1_0) { this.UnkownInt = reader.ReadUInt32(); } }
public NiHeader(NiFile file, BinaryReader reader) { var strLen = 0; var startOffset = reader.BaseStream.Position; while (reader.ReadByte() != 0x0A) { strLen++; } reader.BaseStream.Position = startOffset; VersionString = new string(reader.ReadChars(strLen)); reader.ReadByte(); //skip 0x0A var ver = reader.ReadUInt32(); Version = (eNifVersion)ver; if (Version >= eNifVersion.VER_20_0_0_4) { throw new Exception("NIF Version not supported yet!"); } if (Version >= eNifVersion.VER_10_1_0_0) { UserVersion = reader.ReadUInt32(); } if (Version >= eNifVersion.VER_3_3_0_13) { NumBlocks = reader.ReadUInt32(); } if (Version >= eNifVersion.VER_10_1_0_0 && (UserVersion == 10 || UserVersion == 11)) { UserVersion2 = reader.ReadUInt32(); } if (Version == eNifVersion.VER_20_0_0_5) { throw new VersionNotFoundException("Version 20.0.0.5 not supported!"); } if (Version == eNifVersion.VER_10_0_1_2) { throw new Exception("NIF Version not supported yet!"); } if (Version >= eNifVersion.VER_10_1_0_0 && (UserVersion == 10 || UserVersion == 11)) { throw new Exception("NIF Version not supported yet!"); } if (Version >= eNifVersion.VER_10_0_1_0) { var numBlockTypes = reader.ReadUInt16(); BlockTypes = new NiString[numBlockTypes]; for (var i = 0; i < numBlockTypes; i++) { BlockTypes[i] = new NiString(file, reader); } BlockTypeIndex = new ushort[NumBlocks]; for (var i = 0; i < NumBlocks; i++) { BlockTypeIndex[i] = reader.ReadUInt16(); } } if (Version >= eNifVersion.VER_20_2_0_7) { throw new Exception("NIF Version not supported yet!"); } if (Version >= eNifVersion.VER_20_1_0_3) { throw new Exception("NIF Version not supported yet!"); } if (Version >= eNifVersion.VER_10_0_1_0) { UnkownInt = reader.ReadUInt32(); } }