public static partial void WriteBinaryTeachesCustom(MutagenWriter writer, IBookGetter item) { switch (item.Teaches) { case BookSpell spell: FormLinkBinaryTranslation.Instance.Write(writer, spell.Spell); break; case BookSkill skill: var skillVal = skill.Skill; if (skillVal == null) { writer.Write(-1); } else { writer.Write((int)skillVal); } break; case BookTeachesNothing nothing: writer.Write(nothing.RawContent); break; default: writer.WriteZeros(4); break; } }
public static partial void WriteBinaryResponseCountCustom(MutagenWriter writer, IDialogTopicGetter item) { if (!item.Responses.TryGet(out var resp) || resp.Count == 0) { using (HeaderExport.Subrecord(writer, RecordTypes.TIFC)) { writer.WriteZeros(4); } }
public static void WriteString(MutagenWriter writer, string str, ReadOnlyMemorySlice <byte>?bytes) { if (str.Length >= LodBinaryCreateTranslation.TotalLen) { throw new ArgumentException($"String was too long to fit. {str.Length} > {LodBinaryCreateTranslation.TotalLen - 1}"); } writer.Write(str, StringBinaryType.NullTerminate, writer.MetaData.Encodings.NonTranslated); if (bytes == null) { writer.WriteZeros((uint)(LodBinaryCreateTranslation.TotalLen - str.Length - 1)); } else { writer.Write(bytes.Value); } }
public void Dispose() { _tributary.Position = 0; if (_tributary.Length <= ushort.MaxValue) { using (HeaderExport.Subrecord(_writer, _mainRecord)) { _tributary.CopyTo(_writer.BaseStream); } } else { using (HeaderExport.Subrecord(_writer, _overflowRecord)) { _writer.Write(checked ((uint)_tributary.Length)); } _writer.Write(_mainRecord.TypeInt); _writer.WriteZeros(2); _tributary.CopyTo(_writer.BaseStream); } }
public static partial void WriteBinaryCloudsCustom(MutagenWriter writer, IWeatherGetter item) { bool HasAny(Span <float?> span) { for (int i = 0; i < span.Length; i++) { if (span[i].HasValue) { return(true); } } return(false); } var version = item.FormVersion; Span <float?> xSpeeds = stackalloc float?[WeatherBinaryCreateTranslation.NumLayers]; Span <float?> ySpeeds = stackalloc float?[WeatherBinaryCreateTranslation.NumLayers]; var alphas = new IWeatherAlphaGetter?[WeatherBinaryCreateTranslation.NumLayers]; var colors = new IWeatherColorGetter?[WeatherBinaryCreateTranslation.NumLayers]; foreach (var cloud in item.Clouds.WithIndex()) { xSpeeds[cloud.Index] = cloud.Item.XSpeed; ySpeeds[cloud.Index] = cloud.Item.YSpeed; alphas[cloud.Index] = cloud.Item.Alphas; colors[cloud.Index] = cloud.Item.Colors; } if (HasAny(ySpeeds) || HasAny(xSpeeds)) { // Write YSpeeds using (HeaderExport.Subrecord(writer, RecordTypes.RNAM)) { for (int i = 0; i < ySpeeds.Length; i++) { writer.Write(ConvertFromSpeed(ySpeeds[i] ?? default(byte))); } } // Write XSpeeds using (HeaderExport.Subrecord(writer, RecordTypes.QNAM)) { for (int i = 0; i < xSpeeds.Length; i++) { writer.Write(ConvertFromSpeed(xSpeeds[i] ?? default(byte))); } } } // Write colors if (colors.Any(a => a != null)) { using (HeaderExport.Subrecord(writer, RecordTypes.PNAM)) { for (int i = 0; i < colors.Length; i++) { var color = colors[i]; if (color == null) { writer.WriteZeros(16); } else { ColorBinaryTranslation.Instance.Write(writer, color.Sunrise); ColorBinaryTranslation.Instance.Write(writer, color.Day); ColorBinaryTranslation.Instance.Write(writer, color.Sunset); ColorBinaryTranslation.Instance.Write(writer, color.Night); } // Special case for older version if (version == 31 && i == 3) { break; } } } } // Write alphas if (alphas.Any(a => a != null)) { using (HeaderExport.Subrecord(writer, RecordTypes.JNAM)) { for (int i = 0; i < alphas.Length; i++) { var alpha = alphas[i]; if (alpha == null) { writer.WriteZeros(16); } else { writer.Write(alpha.Sunrise); writer.Write(alpha.Day); writer.Write(alpha.Sunset); writer.Write(alpha.Night); } } } } }