public void Serialize(UndertaleWriter writer) { try { Debug.Assert(Name != null); writer.Write(Name.ToCharArray()); var lenWriter = writer.WriteLengthHere(); writer.SubmitMessage("Writing chunk " + Name); lenWriter.FromHere(); SerializeChunk(writer); if (Name != "FORM" && Name != writer.LastChunkName) { UndertaleGeneralInfo generalInfo = Name == "GEN8" ? ((UndertaleChunkGEN8)this).Object : writer.undertaleData?.GeneralInfo; // These versions introduced new padding // all chunks now start on 16-byte boundaries // (but the padding is included with length of previous chunk) // TODO: what about the debug data?? if (generalInfo != null && (generalInfo.Major >= 2 || (generalInfo.Major == 1 && generalInfo.Build >= 9999))) { int e = writer.undertaleData.PaddingAlignException; uint pad = (e == -1 ? 16 : (uint)e); while (writer.Position % pad != 0) { writer.Write((byte)0); } } } Length = lenWriter.ToHere(); } catch (UndertaleSerializationException e) { throw new UndertaleSerializationException(e.Message + " in chunk " + Name, e); } catch (Exception e) { throw new UndertaleSerializationException(e.Message + "\nat " + writer.Position.ToString("X8") + " while reading chunk " + Name, e); } }