diff --git a/Shockky/IO/ShockwaveReader.cs b/Shockky/IO/ShockwaveReader.cs index 2289220..80ef1fc 100644 --- a/Shockky/IO/ShockwaveReader.cs +++ b/Shockky/IO/ShockwaveReader.cs @@ -215,11 +215,11 @@ public Color ReadColor() Advance(6); return Color.FromArgb(r, g, b); } - public Point ReadPoint() + public Point ReadPointLittleEndian() { return new(ReadInt16LittleEndian(), ReadInt16LittleEndian()); } - public Rectangle ReadRect() + public Rectangle ReadRectLittleEndian() { short top = ReadInt16LittleEndian(); short left = ReadInt16LittleEndian(); @@ -228,6 +228,20 @@ public Rectangle ReadRect() return Rectangle.FromLTRB(left, top, right, bottom); } + + public Point ReadPointBigEndian() + { + return new(ReadInt16BigEndian(), ReadInt16BigEndian()); + } + public Rectangle ReadRectBigEndian() + { + short top = ReadInt16BigEndian(); + short left = ReadInt16BigEndian(); + short bottom = ReadInt16BigEndian(); + short right = ReadInt16BigEndian(); + + return Rectangle.FromLTRB(left, top, right, bottom); + } public unsafe IResource ReadCompressedResource(AfterburnerMapEntry entry, ReaderContext context) { diff --git a/Shockky/IO/ShockwaveWriter.cs b/Shockky/IO/ShockwaveWriter.cs index c62cfcb..beac6f0 100644 --- a/Shockky/IO/ShockwaveWriter.cs +++ b/Shockky/IO/ShockwaveWriter.cs @@ -234,9 +234,14 @@ public void WriteRect(Rectangle value) WriteInt16LittleEndian((short)value.Bottom); WriteInt16LittleEndian((short)value.Right); } - public void WriteMemberId(CastMemberId memberId) + public void WriteMemberIdLittleEndian(CastMemberId memberId) { WriteInt16LittleEndian(memberId.CastLib); WriteInt16LittleEndian(memberId.MemberNum); } + public void WriteMemberIdBigEndian(CastMemberId memberId) + { + WriteInt16BigEndian(memberId.CastLib); + WriteInt16BigEndian(memberId.MemberNum); + } } diff --git a/Shockky/Resources/Cast/CastMap.cs b/Shockky/Resources/Cast/CastMap.cs index a096095..fa3ae32 100644 --- a/Shockky/Resources/Cast/CastMap.cs +++ b/Shockky/Resources/Cast/CastMap.cs @@ -12,12 +12,12 @@ public CastMap() { } public CastMap(ref ShockwaveReader input, ReaderContext context) { - input.ReverseEndianness = true; + input.ReverseEndianness = false; Members = new int[input.Length / sizeof(int)]; for (int i = 0; i < Members.Length; i++) { - Members[i] = input.ReadInt32LittleEndian(); + Members[i] = input.ReadInt32BigEndian(); } } diff --git a/Shockky/Resources/Cast/CastMemberMetadata.cs b/Shockky/Resources/Cast/CastMemberMetadata.cs index b2041cc..d765083 100644 --- a/Shockky/Resources/Cast/CastMemberMetadata.cs +++ b/Shockky/Resources/Cast/CastMemberMetadata.cs @@ -31,15 +31,15 @@ public sealed class MetadataHeader public MetadataHeader(ref ShockwaveReader input, ReaderContext context) { - int headerSize = input.ReadInt32LittleEndian(); + int headerSize = input.ReadInt32BigEndian(); Debug.Assert(headerSize == 16 || headerSize == 20); - int scriptGarbagePtr = input.ReadInt32LittleEndian(); - int legacyFlags = input.ReadInt32LittleEndian(); - Flags = (CastMemberInfoFlags)input.ReadInt32LittleEndian(); + int scriptGarbagePtr = input.ReadInt32BigEndian(); + int legacyFlags = input.ReadInt32BigEndian(); + Flags = (CastMemberInfoFlags)input.ReadInt32BigEndian(); if (headerSize >= 20) { - ScriptContextNum = input.ReadInt32LittleEndian(); + ScriptContextNum = input.ReadInt32BigEndian(); } } } @@ -48,10 +48,10 @@ public sealed class MetadataEntries { public MetadataEntries(ref ShockwaveReader input, ReaderContext context) { - int[] propertyOffsets = new int[input.ReadInt16LittleEndian() + 1]; + int[] propertyOffsets = new int[input.ReadInt16BigEndian() + 1]; for (int i = 0; i < propertyOffsets.Length; i++) { - propertyOffsets[i] = input.ReadInt32LittleEndian(); + propertyOffsets[i] = input.ReadInt32BigEndian(); } // TODO: Serialize the values @@ -118,7 +118,7 @@ private void ReadProperty(ref ShockwaveReader input, int index, int length) RegistrationPoints = new int[length / 4]; for (int i = 0; i < RegistrationPoints.Length; i++) { - RegistrationPoints[i] = input.ReadInt32LittleEndian(); + RegistrationPoints[i] = input.ReadInt32BigEndian(); } break; //15 - MoA ID? @@ -126,10 +126,10 @@ private void ReadProperty(ref ShockwaveReader input, int index, int length) ClipboardFormat = input.ReadString(length); break; case 17: - CreationDate = input.ReadInt32LittleEndian() * 1000; + CreationDate = input.ReadInt32BigEndian() * 1000; break; case 18: - ModifiedDate = input.ReadInt32LittleEndian() * 1000; + ModifiedDate = input.ReadInt32BigEndian() * 1000; break; case 19: ModifiedBy = input.ReadNullString(); @@ -145,14 +145,11 @@ private void ReadProperty(ref ShockwaveReader input, int index, int length) break; default: ReadOnlySpan unknown = input.ReadBytes(length); - string test = Encoding.UTF8.GetString(unknown); break; } } } - - - + public int GetBodySize(WriterOptions options) { throw new NotImplementedException(); diff --git a/Shockky/Resources/Cast/CastMemberProperties.cs b/Shockky/Resources/Cast/CastMemberProperties.cs index 827bdd5..74a87a6 100644 --- a/Shockky/Resources/Cast/CastMemberProperties.cs +++ b/Shockky/Resources/Cast/CastMemberProperties.cs @@ -14,11 +14,11 @@ public sealed class CastMemberProperties : IResource, IShockwaveItem public CastMemberProperties(ref ShockwaveReader input, ReaderContext context) { - input.ReverseEndianness = true; + input.ReverseEndianness = false; - Type = (MemberKind)input.ReadInt32LittleEndian(); - int metadataLength = input.ReadInt32LittleEndian(); - int propetiesLength = input.ReadInt32LittleEndian(); + Type = (MemberKind)input.ReadInt32BigEndian(); + int metadataLength = input.ReadInt32BigEndian(); + int propetiesLength = input.ReadInt32BigEndian(); Metadata = new CastMemberMetadata(ref input, context); Properties = ReadTypeProperties(ref input, context, propetiesLength); diff --git a/Shockky/Resources/Cast/Properties/BitmapCastProperties.cs b/Shockky/Resources/Cast/Properties/BitmapCastProperties.cs index 6ab3b58..5a7fdd5 100644 --- a/Shockky/Resources/Cast/Properties/BitmapCastProperties.cs +++ b/Shockky/Resources/Cast/Properties/BitmapCastProperties.cs @@ -18,13 +18,13 @@ public sealed class BitmapCastProperties : IMemberProperties public BitmapCastProperties(ref ShockwaveReader input, ReaderContext context) { - Stride = input.ReadUInt16LittleEndian(); - Rectangle = input.ReadRect(); + Stride = input.ReadUInt16BigEndian(); + Rectangle = input.ReadRectBigEndian(); //TODO: if version < 0x700 ? i16 : i8 i8 AlphaThreshold = input.ReadByte(); input.ReadByte(); OLE = input.ReadBytes(6).ToArray(); - RegistrationPoint = input.ReadPoint(); + RegistrationPoint = input.ReadPointBigEndian(); Flags = (BitmapFlags)input.ReadByte(); if ((Stride & 0x8000u) != 0) @@ -32,7 +32,7 @@ public BitmapCastProperties(ref ShockwaveReader input, ReaderContext context) Stride &= 0x3FFF; BitDepth = input.ReadByte(); //if size == 26: i16 to u8 else u8 - src: eq-rs - PaletteRef = new CastMemberId(input.ReadInt16LittleEndian(), input.ReadInt16LittleEndian()); //is_v5 ? new CastMemberId(input.ReadInt16(), input.ReadInt16()); : new CastMemberId(-1, input.ReadInt16()); + PaletteRef = new CastMemberId(input.ReadInt16BigEndian(), input.ReadInt16BigEndian()); //is_v5 ? new CastMemberId(input.ReadInt16(), input.ReadInt16()); : new CastMemberId(-1, input.ReadInt16()); } } @@ -61,17 +61,17 @@ public void WriteTo(ShockwaveWriter output, WriterOptions options) if (BitDepth != 1) Stride |= 0x8000; - output.WriteUInt16LittleEndian(Stride); + output.WriteUInt16BigEndian(Stride); output.WriteRect(Rectangle); output.WriteByte(AlphaThreshold); - output.WriteByte((byte)0); + output.WriteByte(0); output.WriteBytes(OLE); output.WritePoint(RegistrationPoint); output.WriteByte((byte)Flags); if (BitDepth == 1) return; output.WriteByte(BitDepth); - output.WriteMemberId(PaletteRef); + output.WriteMemberIdBigEndian(PaletteRef); } } diff --git a/Shockky/Resources/Cast/Properties/ButtonCastProperties.cs b/Shockky/Resources/Cast/Properties/ButtonCastProperties.cs index 3ea33be..93198ca 100644 --- a/Shockky/Resources/Cast/Properties/ButtonCastProperties.cs +++ b/Shockky/Resources/Cast/Properties/ButtonCastProperties.cs @@ -11,7 +11,7 @@ public ButtonCastProperties() public ButtonCastProperties(ref ShockwaveReader input, ReaderContext context) : base(ref input, context) { - ButtonType = (ButtonType)input.ReadInt16LittleEndian(); + ButtonType = (ButtonType)input.ReadInt16BigEndian(); } public new int GetBodySize(WriterOptions options) @@ -25,6 +25,6 @@ public ButtonCastProperties(ref ShockwaveReader input, ReaderContext context) public new void WriteTo(ShockwaveWriter output, WriterOptions options) { base.WriteTo(output, options); - output.WriteInt16LittleEndian((short)ButtonType); + output.WriteInt16BigEndian((short)ButtonType); } } diff --git a/Shockky/Resources/Cast/Properties/FilmLoopCastProperties.cs b/Shockky/Resources/Cast/Properties/FilmLoopCastProperties.cs index 6027d3c..f5fe79c 100644 --- a/Shockky/Resources/Cast/Properties/FilmLoopCastProperties.cs +++ b/Shockky/Resources/Cast/Properties/FilmLoopCastProperties.cs @@ -13,9 +13,9 @@ public FilmLoopCastProperties() { } public FilmLoopCastProperties(ref ShockwaveReader input) { - Rectangle = input.ReadRect(); - Flags = (FilmLoopFlags)input.ReadInt32LittleEndian(); - short unk14 = input.ReadInt16LittleEndian(); + Rectangle = input.ReadRectBigEndian(); + Flags = (FilmLoopFlags)input.ReadInt32BigEndian(); + short unk14 = input.ReadInt16BigEndian(); } public int GetBodySize(WriterOptions options) @@ -30,6 +30,6 @@ public int GetBodySize(WriterOptions options) public void WriteTo(ShockwaveWriter output, WriterOptions options) { output.WriteRect(Rectangle); - output.WriteInt32LittleEndian((int)Flags); + output.WriteInt32BigEndian((int)Flags); } } diff --git a/Shockky/Resources/Cast/Properties/RichTextCastProperties.cs b/Shockky/Resources/Cast/Properties/RichTextCastProperties.cs index 759c009..c8e2385 100644 --- a/Shockky/Resources/Cast/Properties/RichTextCastProperties.cs +++ b/Shockky/Resources/Cast/Properties/RichTextCastProperties.cs @@ -20,18 +20,18 @@ public class RichTextCastProperties : IMemberProperties public RichTextCastProperties(ref ShockwaveReader input) { - Rectangle = input.ReadRect(); - Rect2 = input.ReadRect(); + Rectangle = input.ReadRectBigEndian(); + Rect2 = input.ReadRectBigEndian(); AntiAlias = input.ReadBoolean(); BoxType = (RichTextBoxType)input.ReadByte(); - Unk12 = input.ReadInt16LittleEndian(); + Unk12 = input.ReadInt16BigEndian(); AntiAliasMinFontSize = (SizeType)input.ReadByte(); Height = (SizeType)input.ReadByte(); //TODO: Rgb24 - ForegroundColor = Color.FromArgb(input.ReadInt32LittleEndian()); - BackgroundColor = Color.FromArgb(input.ReadInt16LittleEndian(), input.ReadInt16LittleEndian(), input.ReadInt16LittleEndian()); + ForegroundColor = Color.FromArgb(input.ReadInt32BigEndian()); + BackgroundColor = Color.FromArgb(input.ReadInt16BigEndian(), input.ReadInt16BigEndian(), input.ReadInt16BigEndian()); } public int GetBodySize(WriterOptions options) { diff --git a/Shockky/Resources/Cast/Properties/ScriptCastProperties.cs b/Shockky/Resources/Cast/Properties/ScriptCastProperties.cs index ac0f1c9..e8aeedb 100644 --- a/Shockky/Resources/Cast/Properties/ScriptCastProperties.cs +++ b/Shockky/Resources/Cast/Properties/ScriptCastProperties.cs @@ -10,7 +10,7 @@ public ScriptCastProperties() { } public ScriptCastProperties(ref ShockwaveReader input, ReaderContext context) { - Kind = (ScriptKind)input.ReadInt16LittleEndian(); + Kind = (ScriptKind)input.ReadInt16BigEndian(); } public int GetBodySize(WriterOptions options) @@ -22,6 +22,6 @@ public int GetBodySize(WriterOptions options) public void WriteTo(ShockwaveWriter output, WriterOptions options) { - output.WriteInt16LittleEndian((short)Kind); + output.WriteInt16BigEndian((short)Kind); } } diff --git a/Shockky/Resources/Cast/Properties/ShapeCastProperties.cs b/Shockky/Resources/Cast/Properties/ShapeCastProperties.cs index 86dadf5..04f46ed 100644 --- a/Shockky/Resources/Cast/Properties/ShapeCastProperties.cs +++ b/Shockky/Resources/Cast/Properties/ShapeCastProperties.cs @@ -20,10 +20,10 @@ public ShapeCastProperties() { } public ShapeCastProperties(ref ShockwaveReader input, ReaderContext context) { - Type = (ShapeType)input.ReadInt16LittleEndian(); - Rectangle = input.ReadRect(); + Type = (ShapeType)input.ReadInt16BigEndian(); + Rectangle = input.ReadRectBigEndian(); - Pattern = input.ReadInt16LittleEndian(); + Pattern = input.ReadInt16BigEndian(); ForegroundColor = input.ReadByte(); BackgroundColor = input.ReadByte(); @@ -55,10 +55,10 @@ public int GetBodySize(WriterOptions options) public void WriteTo(ShockwaveWriter output, WriterOptions options) { - output.WriteInt16LittleEndian((short)Type); + output.WriteInt16BigEndian((short)Type); output.WriteRect(Rectangle); - output.WriteInt16LittleEndian(Pattern); + output.WriteInt16BigEndian(Pattern); output.WriteByte(ForegroundColor); output.WriteByte(BackgroundColor); diff --git a/Shockky/Resources/Cast/Properties/TextCastProperties.cs b/Shockky/Resources/Cast/Properties/TextCastProperties.cs index cc031c6..02454fe 100644 --- a/Shockky/Resources/Cast/Properties/TextCastProperties.cs +++ b/Shockky/Resources/Cast/Properties/TextCastProperties.cs @@ -30,11 +30,11 @@ public TextCastProperties(ref ShockwaveReader input, ReaderContext context) BoxShadowSize = (SizeType)input.ReadByte(); BoxType = (TextBoxType)input.ReadByte(); - Alignment = (TextAlignment)input.ReadInt16LittleEndian(); + Alignment = (TextAlignment)input.ReadInt16BigEndian(); BackgroundColor = input.ReadColor(); - Font = input.ReadInt16LittleEndian(); - Rectangle = input.ReadRect(); - LineHeight = input.ReadInt16LittleEndian(); + Font = input.ReadInt16BigEndian(); + Rectangle = input.ReadRectBigEndian(); + LineHeight = input.ReadInt16BigEndian(); TextShadowSize = (SizeType)input.ReadByte(); Flags = (TextFlags)input.ReadByte(); @@ -66,12 +66,12 @@ public void WriteTo(ShockwaveWriter output, WriterOptions options) output.WriteByte((byte)BoxShadowSize); output.WriteByte((byte)BoxType); - output.WriteInt16LittleEndian((short)Alignment); + output.WriteInt16BigEndian((short)Alignment); output.WriteColor(BackgroundColor); - output.WriteInt16LittleEndian(Font); + output.WriteInt16BigEndian(Font); output.WriteRect(Rectangle); - output.WriteInt16LittleEndian(LineHeight); + output.WriteInt16BigEndian(LineHeight); output.WriteByte((byte)TextShadowSize); output.WriteByte((byte)Flags); diff --git a/Shockky/Resources/Cast/Properties/TransitionCastProperties.cs b/Shockky/Resources/Cast/Properties/TransitionCastProperties.cs index d620cf7..9c850df 100644 --- a/Shockky/Resources/Cast/Properties/TransitionCastProperties.cs +++ b/Shockky/Resources/Cast/Properties/TransitionCastProperties.cs @@ -20,7 +20,7 @@ public TransitionCastProperties(ref ShockwaveReader input, ReaderContext context ChunkSize = input.ReadByte(); Type = (TransitionType)input.ReadByte(); Flags = (TransitionFlags)input.ReadByte(); - DurationInMilliseconds = input.ReadInt16LittleEndian(); //TODO: Not in < D5 + DurationInMilliseconds = input.ReadInt16BigEndian(); //TODO: Not in < D5 if (!Flags.HasFlag(TransitionFlags.Standard)) Xtra = new XtraCastProperties(ref input, context); diff --git a/Shockky/Resources/Cast/Properties/VideoCastProperties.cs b/Shockky/Resources/Cast/Properties/VideoCastProperties.cs index c282fe3..df3d4a6 100644 --- a/Shockky/Resources/Cast/Properties/VideoCastProperties.cs +++ b/Shockky/Resources/Cast/Properties/VideoCastProperties.cs @@ -33,7 +33,7 @@ public VideoCastProperties(ref ShockwaveReader input, ReaderContext context) input.Advance(3); Framerate = input.ReadByte(); input.Advance(32); - Rectangle = input.ReadRect(); + Rectangle = input.ReadRectLittleEndian(); } public int GetBodySize(WriterOptions options) diff --git a/Shockky/Resources/Cast/Properties/XtraCastProperties.cs b/Shockky/Resources/Cast/Properties/XtraCastProperties.cs index 5a1735f..101d2a9 100644 --- a/Shockky/Resources/Cast/Properties/XtraCastProperties.cs +++ b/Shockky/Resources/Cast/Properties/XtraCastProperties.cs @@ -27,8 +27,8 @@ public int GetBodySize(WriterOptions options) public void WriteTo(ShockwaveWriter output, WriterOptions options) { throw new NotImplementedException(nameof(XtraCastProperties)); - output.WriteInt32LittleEndian(SymbolName.Length); - output.WriteInt32LittleEndian(Data.Length); + output.WriteInt32BigEndian(SymbolName.Length); + output.WriteInt32BigEndian(Data.Length); output.WriteBytes(Data); } } diff --git a/Shockky/Resources/Config.cs b/Shockky/Resources/Config.cs index f2f93e4..cc21ca6 100644 --- a/Shockky/Resources/Config.cs +++ b/Shockky/Resources/Config.cs @@ -65,67 +65,67 @@ public sealed class Config : IShockwaveItem, IResource public Config(ref ShockwaveReader input, ReaderContext context) { - input.ReverseEndianness = true; + input.ReverseEndianness = false; - input.ReadInt16LittleEndian(); - Version = (DirectorVersion)input.ReadInt16LittleEndian(); + input.ReadInt16BigEndian(); + Version = (DirectorVersion)input.ReadInt16BigEndian(); - Rect = input.ReadRect(); + Rect = input.ReadRectLittleEndian(); - MinMemberNum = input.ReadInt16LittleEndian(); - MaxMemberNum = input.ReadInt16LittleEndian(); + MinMemberNum = input.ReadInt16BigEndian(); + MaxMemberNum = input.ReadInt16BigEndian(); LegacyTempo = input.ReadByte(); LightSwitch = input.ReadBoolean(); - Field12 = input.ReadInt16LittleEndian(); + Field12 = input.ReadInt16BigEndian(); - CommentFont = input.ReadInt16LittleEndian(); - CommentSize = input.ReadInt16LittleEndian(); - CommentStyle = input.ReadInt16LittleEndian(); + CommentFont = input.ReadInt16BigEndian(); + CommentSize = input.ReadInt16BigEndian(); + CommentStyle = input.ReadInt16BigEndian(); // v >= 1025 - StagePalette = input.ReadInt16LittleEndian(); - DefaultColorDepth = input.ReadInt16LittleEndian(); + StagePalette = input.ReadInt16BigEndian(); + DefaultColorDepth = input.ReadInt16BigEndian(); Field1E = input.ReadByte(); Field1F = input.ReadByte(); - DataSize = input.ReadInt32LittleEndian(); + DataSize = input.ReadInt32BigEndian(); - OriginalVersion = (DirectorVersion)input.ReadInt16LittleEndian(); - MaxCastColorDepth = input.ReadInt16LittleEndian(); - Flags = (ConfigFlags)input.ReadInt32LittleEndian(); - ScoreUsedChannelsMask = input.ReadUInt64LittleEndian(); + OriginalVersion = (DirectorVersion)input.ReadInt16BigEndian(); + MaxCastColorDepth = input.ReadInt16BigEndian(); + Flags = (ConfigFlags)input.ReadInt32BigEndian(); + ScoreUsedChannelsMask = input.ReadUInt64BigEndian(); Trial = input.ReadBoolean(); Field34 = input.ReadByte(); - Tempo = input.ReadInt16LittleEndian(); - Platform = (Platform)input.ReadInt16LittleEndian(); + Tempo = input.ReadInt16BigEndian(); + Platform = (Platform)input.ReadInt16BigEndian(); // v >= 1113 - SaveSeed = input.ReadInt16LittleEndian(); - Field3C = input.ReadInt32LittleEndian(); - Checksum = input.ReadUInt32LittleEndian(); + SaveSeed = input.ReadInt16BigEndian(); + Field3C = input.ReadInt32BigEndian(); + Checksum = input.ReadUInt32BigEndian(); // v >= 1114 - OldDefaultPalette = input.ReadInt16LittleEndian(); + OldDefaultPalette = input.ReadInt16BigEndian(); // v >= 1115 - Field46 = input.ReadInt16LittleEndian(); + Field46 = input.ReadInt16BigEndian(); - MaxCastResourceNum = input.ReadInt32LittleEndian(); - DefaultPalette = new CastMemberId(input.ReadInt16LittleEndian(), input.ReadInt16LittleEndian()); + MaxCastResourceNum = input.ReadInt32BigEndian(); + DefaultPalette = new CastMemberId(input.ReadInt16BigEndian(), input.ReadInt16BigEndian()); Field50 = input.ReadByte(); Field51 = input.ReadByte(); - Field52 = input.ReadInt16LittleEndian(); + Field52 = input.ReadInt16BigEndian(); if (!input.IsDataAvailable) return; - DownloadFramesBeforePlaying = input.ReadInt32LittleEndian(); - Field58 = input.ReadInt16LittleEndian(); - Field5A = input.ReadInt16LittleEndian(); - Field5C = input.ReadInt16LittleEndian(); - Field5E = input.ReadInt16LittleEndian(); - Field60 = input.ReadInt16LittleEndian(); - Field62 = input.ReadInt16LittleEndian(); + DownloadFramesBeforePlaying = input.ReadInt32BigEndian(); + Field58 = input.ReadInt16BigEndian(); + Field5A = input.ReadInt16BigEndian(); + Field5C = input.ReadInt16BigEndian(); + Field5E = input.ReadInt16BigEndian(); + Field60 = input.ReadInt16BigEndian(); + Field62 = input.ReadInt16BigEndian(); } public uint CalculateChecksum() @@ -169,52 +169,52 @@ public uint CalculateChecksum() public void WriteTo(ShockwaveWriter output, WriterOptions options) { - output.WriteInt16LittleEndian(LENGTH); - output.WriteInt16LittleEndian((short)Version); + output.WriteInt16BigEndian(LENGTH); + output.WriteInt16BigEndian((short)Version); output.WriteRect(Rect); - output.WriteInt16LittleEndian(MinMemberNum); - output.WriteInt16LittleEndian(MaxMemberNum); + output.WriteInt16BigEndian(MinMemberNum); + output.WriteInt16BigEndian(MaxMemberNum); output.WriteByte(LegacyTempo); output.WriteBoolean(LightSwitch); - output.WriteInt16LittleEndian(Field12); - output.WriteInt16LittleEndian(CommentFont); - output.WriteInt16LittleEndian(CommentSize); - output.WriteInt16LittleEndian(CommentStyle); + output.WriteInt16BigEndian(Field12); + output.WriteInt16BigEndian(CommentFont); + output.WriteInt16BigEndian(CommentSize); + output.WriteInt16BigEndian(CommentStyle); - output.WriteInt16LittleEndian(StagePalette); - output.WriteInt16LittleEndian(DefaultColorDepth); + output.WriteInt16BigEndian(StagePalette); + output.WriteInt16BigEndian(DefaultColorDepth); output.WriteByte(Field1E); output.WriteByte(Field1F); - output.WriteInt32LittleEndian(DataSize); + output.WriteInt32BigEndian(DataSize); - output.WriteInt16LittleEndian((short)OriginalVersion); - output.WriteInt16LittleEndian(MaxCastColorDepth); - output.WriteInt32LittleEndian((int)Flags); - output.WriteUInt64LittleEndian(ScoreUsedChannelsMask); + output.WriteInt16BigEndian((short)OriginalVersion); + output.WriteInt16BigEndian(MaxCastColorDepth); + output.WriteInt32BigEndian((int)Flags); + output.WriteUInt64BigEndian(ScoreUsedChannelsMask); output.WriteBoolean(Trial); output.WriteByte(Field34); - output.WriteInt16LittleEndian(Tempo); - output.WriteInt16LittleEndian((short)Platform); - output.WriteInt16LittleEndian(SaveSeed); - output.WriteInt32LittleEndian(Field3C); - output.WriteUInt32LittleEndian(Checksum); // TODO: CalculateChecksum() - output.WriteInt16LittleEndian(OldDefaultPalette); - - output.WriteInt16LittleEndian(Field46); - output.WriteInt32LittleEndian(MaxCastResourceNum); - output.WriteMemberId(DefaultPalette); + output.WriteInt16BigEndian(Tempo); + output.WriteInt16BigEndian((short)Platform); + output.WriteInt16BigEndian(SaveSeed); + output.WriteInt32BigEndian(Field3C); + output.WriteUInt32BigEndian(Checksum); // TODO: CalculateChecksum() + output.WriteInt16BigEndian(OldDefaultPalette); + + output.WriteInt16BigEndian(Field46); + output.WriteInt32BigEndian(MaxCastResourceNum); + output.WriteMemberIdBigEndian(DefaultPalette); output.WriteByte(Field50); output.WriteByte(Field51); - output.WriteInt16LittleEndian(Field52); - - output.WriteInt32LittleEndian(DownloadFramesBeforePlaying); - output.WriteInt16LittleEndian(Field58); - output.WriteInt16LittleEndian(Field5A); - output.WriteInt16LittleEndian(Field5C); - output.WriteInt16LittleEndian(Field5E); - output.WriteInt16LittleEndian(Field60); - output.WriteInt16LittleEndian(Field62); + output.WriteInt16BigEndian(Field52); + + output.WriteInt32BigEndian(DownloadFramesBeforePlaying); + output.WriteInt16BigEndian(Field58); + output.WriteInt16BigEndian(Field5A); + output.WriteInt16BigEndian(Field5C); + output.WriteInt16BigEndian(Field5E); + output.WriteInt16BigEndian(Field60); + output.WriteInt16BigEndian(Field62); } } diff --git a/Shockky/Resources/Enum/LingoContextFlags.cs b/Shockky/Resources/Enum/LingoContextFlags.cs index d29aae3..97e7f7f 100644 --- a/Shockky/Resources/Enum/LingoContextFlags.cs +++ b/Shockky/Resources/Enum/LingoContextFlags.cs @@ -6,8 +6,8 @@ public enum LingoContextFlags : short None = 0, NotEmptyMaybe = 1 << 0, RemoveFromEnvironment = 1 << 1, - RIFF_CHUNK_INDEXES_CHANGED_MAYBE = 1 << 2, - EVENT_HANDLERS_CHANGED_MAYBE = 1 << 3, + RiffChunkIndicesChangedMaybe = 1 << 2, + EventHandlersChangedMaybe = 1 << 3, AllowOutdatedLingo = 1 << 5, UpdateMovieEnabled = 1 << 6 } diff --git a/Shockky/Resources/IResource.cs b/Shockky/Resources/IResource.cs index 5e6c3cd..43dec4f 100644 --- a/Shockky/Resources/IResource.cs +++ b/Shockky/Resources/IResource.cs @@ -14,45 +14,45 @@ public static IResource Read(scoped ref ShockwaveReader input, ReaderContext con public static IResource Read(scoped ref ShockwaveReader input, ReaderContext context, OsType kind, int length) { ReadOnlySpan chunkSpan = input.ReadBytes(length); - var chunkInput = new ShockwaveReader(chunkSpan, input.ReverseEndianness); + var bodyInput = new ShockwaveReader(chunkSpan, input.ReverseEndianness); return kind switch { - OsType.Fver => new FileVersion(ref chunkInput, context), - OsType.Fcdr => new FileCompressionTypes(ref chunkInput, context), - OsType.ABMP => new AfterburnerMap(ref chunkInput, context), + OsType.Fver => new FileVersion(ref bodyInput, context), + OsType.Fcdr => new FileCompressionTypes(ref bodyInput, context), + OsType.ABMP => new AfterburnerMap(ref bodyInput, context), - OsType.imap => new IndexMap(ref chunkInput, context), - OsType.mmap => new MemoryMap(ref chunkInput, context), - OsType.KEYPtr => new KeyMap(ref chunkInput, context), - OsType.VWCF or OsType.DRCF => new Config(ref chunkInput, context), + OsType.imap => new IndexMap(ref bodyInput, context), + OsType.mmap => new MemoryMap(ref bodyInput, context), + OsType.KEYPtr => new KeyMap(ref bodyInput, context), + OsType.VWCF or OsType.DRCF => new Config(ref bodyInput, context), // TODO: handle V1850 //OsType.VWLB => new ScoreLabels(ref chunkInput, context), - OsType.VWFI => new FileInfo(ref chunkInput, context), + OsType.VWFI => new FileInfo(ref bodyInput, context), - OsType.Lnam => new LingoNames(ref chunkInput, context), - OsType.Lscr => new LingoScript(ref chunkInput), - OsType.Lctx or OsType.LctX => new LingoContext(ref chunkInput, context), + OsType.Lnam => new LingoNames(ref bodyInput, context), + OsType.Lscr => new LingoScript(ref bodyInput), + OsType.Lctx or OsType.LctX => new LingoContext(ref bodyInput, context), - OsType.CASPtr => new CastMap(ref chunkInput, context), - OsType.CASt => new CastMemberProperties(ref chunkInput, context), + OsType.CASPtr => new CastMap(ref bodyInput, context), + OsType.CASt => new CastMemberProperties(ref bodyInput, context), - OsType.SCRF => new ScoreReference(ref chunkInput, context), - OsType.Sord => new ScoreOrder(ref chunkInput, context), - OsType.CLUT => new Palette(ref chunkInput, context), - OsType.STXT => new StyledText(ref chunkInput, context), + OsType.SCRF => new ScoreReference(ref bodyInput, context), + OsType.Sord => new ScoreOrder(ref bodyInput, context), + OsType.CLUT => new Palette(ref bodyInput, context), + OsType.STXT => new StyledText(ref bodyInput, context), - OsType.snd => new SoundData(ref chunkInput), + OsType.snd => new SoundData(ref bodyInput), - OsType.Fmap => new FontMap(ref chunkInput, context), + OsType.Fmap => new FontMap(ref bodyInput, context), - OsType.GRID => new Grid(ref chunkInput, context), - OsType.FCOL => FavoriteColors.Read(ref chunkInput, context), + OsType.GRID => new Grid(ref bodyInput, context), + OsType.FCOL => FavoriteColors.Read(ref bodyInput, context), - OsType.BITD => new BitmapData(ref chunkInput, context), + OsType.BITD => new BitmapData(ref bodyInput, context), - _ => new UnknownResource(ref chunkInput, context, kind) + _ => new UnknownResource(ref bodyInput, context, kind) }; } } diff --git a/Shockky/Resources/KeyMap.cs b/Shockky/Resources/KeyMap.cs index be2c8f4..8f8d495 100644 --- a/Shockky/Resources/KeyMap.cs +++ b/Shockky/Resources/KeyMap.cs @@ -12,12 +12,14 @@ public sealed class KeyMap : IShockwaveItem, IResource public Dictionary ResourceMap { get; set; } public KeyMap() - { } + { + ResourceMap = new Dictionary(); + } public KeyMap(ref ShockwaveReader input, ReaderContext context) { - input.ReadInt16LittleEndian(); - input.ReadInt16LittleEndian(); - input.ReadInt32LittleEndian(); + input.ReadInt16BigEndian(); + input.ReadInt16BigEndian(); + input.ReadInt32BigEndian(); int count = input.ReadInt32BigEndian(); ResourceMap = new Dictionary(count); @@ -47,8 +49,8 @@ public void WriteTo(ShockwaveWriter output, WriterOptions options) { output.WriteInt16BigEndian(ENTRY_SIZE); output.WriteInt16BigEndian(ENTRY_SIZE); - output.WriteInt32BigEndian(ResourceMap?.Count ?? 0); - output.WriteInt32BigEndian(ResourceMap?.Count ?? 0); + output.WriteInt32BigEndian(ResourceMap.Count); + output.WriteInt32BigEndian(ResourceMap.Count); foreach ((ResourceId resourceId, int index) in ResourceMap) { output.WriteInt32BigEndian(index); diff --git a/Shockky/Resources/Lingo/LingoContext.cs b/Shockky/Resources/Lingo/LingoContext.cs index d74b158..ceb7264 100644 --- a/Shockky/Resources/Lingo/LingoContext.cs +++ b/Shockky/Resources/Lingo/LingoContext.cs @@ -120,9 +120,4 @@ public void WriteTo(ShockwaveWriter output, WriterOptions options) section.WriteTo(output, options); } } - - public static LingoContext Read(ref ShockwaveReader input, ReaderContext context) - { - throw new NotImplementedException(); - } } diff --git a/Shockky/Resources/Score/Score.cs b/Shockky/Resources/Score/Score.cs index 8ac83ad..cb5e8eb 100644 --- a/Shockky/Resources/Score/Score.cs +++ b/Shockky/Resources/Score/Score.cs @@ -10,10 +10,10 @@ public Score() { } public Score(ref ShockwaveReader input) { - input.ReverseEndianness = true; + input.ReverseEndianness = false; - int totalLength = input.ReadInt32LittleEndian(); - int headerType = input.ReadInt32LittleEndian(); //-3 + int totalLength = input.ReadInt32BigEndian(); + int headerType = input.ReadInt32BigEndian(); //-3 throw new NotImplementedException(); } diff --git a/Shockky/Resources/Score/ScoreLabels.cs b/Shockky/Resources/Score/ScoreLabels.cs index 3648725..dcd2cfd 100644 --- a/Shockky/Resources/Score/ScoreLabels.cs +++ b/Shockky/Resources/Score/ScoreLabels.cs @@ -12,17 +12,17 @@ public sealed class ScoreLabels : IShockwaveItem, IResource public ScoreLabels(ref ShockwaveReader input, ReaderContext context) { - input.ReverseEndianness = true; + input.ReverseEndianness = false; - var offsetMap = new (short frame, int offset)[input.ReadInt16LittleEndian()]; + var offsetMap = new (short frame, int offset)[input.ReadInt16BigEndian()]; Labels = new Dictionary(offsetMap.Length); for (int i = 0; i < offsetMap.Length; i++) { - offsetMap[i] = (input.ReadInt16LittleEndian(), input.ReadInt16LittleEndian()); + offsetMap[i] = (input.ReadInt16BigEndian(), input.ReadInt16BigEndian()); } - int length = input.ReadInt32LittleEndian(); + int length = input.ReadInt32BigEndian(); string labels = input.ReadString(); @@ -52,17 +52,17 @@ public void WriteTo(ShockwaveWriter output, WriterOptions options) int offset = 0; var builder = new StringBuilder(); - output.WriteInt32LittleEndian(Labels.Count); + output.WriteInt32BigEndian(Labels.Count); foreach ((short frame, string label) in Labels) { - output.WriteInt16LittleEndian(frame); - output.WriteInt16LittleEndian((short)offset); + output.WriteInt16BigEndian(frame); + output.WriteInt16BigEndian((short)offset); offset += label.Length; builder.Append(label); } - output.WriteInt32LittleEndian(builder.Length); + output.WriteInt32BigEndian(builder.Length); output.WriteBytes(Encoding.UTF8.GetBytes(builder.ToString())); } } \ No newline at end of file diff --git a/Shockky/Resources/ScoreOrder.cs b/Shockky/Resources/ScoreOrder.cs index 19e76d7..a40fc60 100644 --- a/Shockky/Resources/ScoreOrder.cs +++ b/Shockky/Resources/ScoreOrder.cs @@ -13,23 +13,25 @@ public sealed class ScoreOrder : IShockwaveItem, IResource public CastMemberId[] Entries { get; set; } public ScoreOrder() - { } + { + Entries = []; + } public ScoreOrder(ref ShockwaveReader input, ReaderContext context) { - input.ReverseEndianness = true; + input.ReverseEndianness = false; - input.ReadInt32LittleEndian(); - input.ReadInt32LittleEndian(); + input.ReadInt32BigEndian(); + input.ReadInt32BigEndian(); - Entries = new CastMemberId[input.ReadInt32LittleEndian()]; - input.ReadInt32LittleEndian(); + Entries = new CastMemberId[input.ReadInt32BigEndian()]; + input.ReadInt32BigEndian(); - input.ReadInt16LittleEndian(); - input.ReadInt16LittleEndian(); //TODO: dir <= 0x500 ? sizeof(short) : sizeof(short) * 2. + input.ReadInt16BigEndian(); + input.ReadInt16BigEndian(); //TODO: dir <= 0x500 ? sizeof(short) : sizeof(short) * 2. for (int i = 0; i < Entries.Length; i++) { - Entries[i] = new(input.ReadInt16LittleEndian(), input.ReadInt16LittleEndian()); + Entries[i] = new(input.ReadInt16BigEndian(), input.ReadInt16BigEndian()); } } @@ -37,6 +39,7 @@ public int GetBodySize(WriterOptions options) { int size = 0; size += sizeof(int); + size += sizeof(int); size += sizeof(int); @@ -52,18 +55,18 @@ public void WriteTo(ShockwaveWriter output, WriterOptions options) const short ENTRIES_OFFSET = 20; const short ENTRY_SIZE = sizeof(short) + sizeof(short); - output.WriteInt32LittleEndian(0); - output.WriteInt32LittleEndian(0); + output.WriteInt32BigEndian(0); + output.WriteInt32BigEndian(0); - output.WriteInt32LittleEndian(Entries.Length); - output.WriteInt32LittleEndian(Entries.Length); + output.WriteInt32BigEndian(Entries.Length); + output.WriteInt32BigEndian(Entries.Length); - output.WriteInt16LittleEndian(ENTRIES_OFFSET); - output.WriteInt16LittleEndian(ENTRY_SIZE); + output.WriteInt16BigEndian(ENTRIES_OFFSET); + output.WriteInt16BigEndian(ENTRY_SIZE); foreach (CastMemberId memberId in Entries) { - output.WriteMemberId(memberId); + output.WriteMemberIdBigEndian(memberId); } } } diff --git a/Shockky/Resources/Tiles.cs b/Shockky/Resources/Tiles.cs index f2aa649..d480bee 100644 --- a/Shockky/Resources/Tiles.cs +++ b/Shockky/Resources/Tiles.cs @@ -9,7 +9,7 @@ namespace Shockky.Resources; public record Tile(CastMemberId Id, Rectangle Rect) : IShockwaveItem { public Tile(ref ShockwaveReader input, ReaderContext context) - : this(new CastMemberId(input.ReadInt16LittleEndian(), input.ReadInt16LittleEndian()), input.ReadRect()) + : this(new CastMemberId(input.ReadInt16LittleEndian(), input.ReadInt16LittleEndian()), input.ReadRectLittleEndian()) { } public int GetBodySize(WriterOptions options)