Skip to content

Commit f331fc3

Browse files
feat(io): use source generator for cast member vlist
1 parent aa9d32a commit f331fc3

File tree

2 files changed

+64
-133
lines changed

2 files changed

+64
-133
lines changed

Shockky/Attributes/HeaderAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ internal sealed class HeaderAttribute : Attribute
99
/// <summary>
1010
/// Expected header size values for validation.
1111
/// </summary>
12-
public int[] ExpectedSizes { get; init; } = [];
12+
public int[] ExpectedSizes { get; set; } = [];
1313
}

Shockky/Resources/Cast/CastMemberMetadata.cs

Lines changed: 63 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,84 @@
1-
using System.Diagnostics;
2-
31
using Shockky.IO;
42

53
namespace Shockky.Resources.Cast;
64

75
// TODO: Generalize VList parsing logic
8-
public sealed class CastMemberMetadata : IResource, IShockwaveItem
6+
[ShockwaveItem]
7+
public sealed partial class CastMemberMetadata : IResource, IShockwaveItem
98
{
109
public OsType Kind => OsType.VWCI;
1110

12-
public MetadataHeader Header { get; set; }
13-
public MetadataEntries Entries { get; set; }
14-
15-
public CastMemberMetadata(ref ShockwaveReader input, ReaderContext context)
11+
[Header]
12+
public sealed partial class MetadataHeader
1613
{
17-
Header = new MetadataHeader(ref input, context);
18-
Entries = new MetadataEntries(ref input, context);
19-
}
14+
[PadBefore(4)] // Skip garbage script pointer
15+
public int LegacyFlags { get; set; }
2016

21-
public sealed class MetadataHeader
22-
{
2317
public CastMemberInfoFlags Flags { get; set; }
2418

2519
/// <summary>
26-
/// The script number of the Lingo script for this cast member in
20+
/// The Lingo script number for this cast member in
2721
/// the cast library’s Lingo environment.
2822
/// </summary>
23+
[Condition("headerSize >= 20")]
2924
public int? ScriptContextNum { get; set; }
30-
31-
public MetadataHeader(ref ShockwaveReader input, ReaderContext context)
32-
{
33-
int headerSize = input.ReadInt32BigEndian();
34-
Debug.Assert(headerSize == 16 || headerSize == 20);
35-
36-
int scriptGarbagePtr = input.ReadInt32BigEndian();
37-
int legacyFlags = input.ReadInt32BigEndian();
38-
Flags = (CastMemberInfoFlags)input.ReadInt32BigEndian();
39-
if (headerSize >= 20)
40-
{
41-
ScriptContextNum = input.ReadInt32BigEndian();
42-
}
43-
}
4425
}
4526

46-
public sealed class MetadataEntries
47-
{
48-
public MetadataEntries(ref ShockwaveReader input, ReaderContext context)
49-
{
50-
int[] propertyOffsets = new int[input.ReadInt16BigEndian() + 1];
51-
for (int i = 0; i < propertyOffsets.Length; i++)
52-
{
53-
propertyOffsets[i] = input.ReadInt32BigEndian();
54-
}
55-
56-
// TODO: Serialize the values
57-
}
58-
59-
public string ScriptText { get; set; }
60-
public string Name { get; set; }
61-
62-
public string FilePath { get; set; }
63-
public string FileName { get; set; }
64-
public string FileType { get; set; }
65-
66-
public Guid XtraGUID { get; set; }
67-
public string XtraName { get; set; }
68-
69-
public int[] RegistrationPoints { get; set; }
70-
71-
public string ClipboardFormat { get; set; }
72-
73-
public int CreationDate { get; set; }
74-
public int ModifiedDate { get; set; }
75-
76-
public string ModifiedBy { get; set; }
77-
public string Comments { get; set; }
78-
79-
public int ImageCompression { get; set; }
80-
public int ImageQuality { get; set; }
81-
82-
private void ReadProperty(ref ShockwaveReader input, int index, int length)
83-
{
84-
switch (index)
85-
{
86-
case 0:
87-
ScriptText = input.ReadString(length);
88-
break;
89-
case 1:
90-
Name = input.ReadPString();
91-
break;
92-
case 2:
93-
FilePath = input.ReadString(length);
94-
break;
95-
case 3:
96-
FileName = input.ReadString(length);
97-
break;
98-
case 4:
99-
FileType = input.ReadString(length);
100-
break;
101-
case 5: // TODO: script rel? - string - prop 44
102-
break;
103-
case 7: // TODO: prop 45 - string
104-
string prop45 = input.ReadString(length);
105-
break;
106-
case 9:
107-
XtraGUID = new Guid(input.ReadBytes(length));
108-
//XtraGUID = input.Read<Guid>();
109-
break;
110-
case 10:
111-
XtraName = input.ReadCString();
112-
break;
113-
case 11: //TODO:
114-
break;
115-
case 12:
116-
//TODO: MoaRect - TLBR
117-
RegistrationPoints = new int[length / 4];
118-
for (int i = 0; i < RegistrationPoints.Length; i++)
119-
{
120-
RegistrationPoints[i] = input.ReadInt32BigEndian();
121-
}
122-
break;
123-
//15 - MoA ID?
124-
case 16:
125-
ClipboardFormat = input.ReadString(length);
126-
break;
127-
case 17:
128-
CreationDate = input.ReadInt32BigEndian() * 1000;
129-
break;
130-
case 18:
131-
ModifiedDate = input.ReadInt32BigEndian() * 1000;
132-
break;
133-
case 19:
134-
ModifiedBy = input.ReadCString();
135-
break;
136-
case 20:
137-
Comments = input.ReadString(length);
138-
break;
139-
case 21:
140-
ReadOnlySpan<byte> imageFlags = input.ReadBytes(length); //4
141-
142-
ImageCompression = imageFlags[0] >> 4;
143-
ImageQuality = imageFlags[1];
144-
break;
145-
default:
146-
ReadOnlySpan<byte> unknown = input.ReadBytes(length);
147-
break;
148-
}
149-
}
150-
}
27+
/// <summary>Header section.</summary>
28+
public MetadataHeader Header { get; set; } = null!;
29+
30+
/// <summary>Offset table for entries.</summary>
31+
[OffsetTable]
32+
private OffsetTable Offsets { get; set; }
33+
34+
[Entry(0), ParseStringAs(StringParseKind.FixedBytes)]
35+
public string? ScriptText { get; set; }
36+
[Entry(1), ParseStringAs(StringParseKind.PString)]
37+
public string? Name { get; set; }
38+
39+
[Entry(2), ParseStringAs(StringParseKind.FixedBytes)]
40+
public string? FilePath { get; set; }
41+
[Entry(3), ParseStringAs(StringParseKind.FixedBytes)]
42+
public string? FileName { get; set; }
43+
[Entry(4), ParseStringAs(StringParseKind.FixedBytes)]
44+
public string? FileType { get; set; }
45+
46+
// TODO: 5 = string, prop 44, script related?
47+
48+
[Entry(7), ParseStringAs(StringParseKind.FixedBytes)]
49+
public string? UnknownProp45 { get; set; }
50+
51+
// TODO: [Entry(9)]
52+
// public Guid? XtraGUID { get; set; }
53+
54+
[Entry(10), ParseStringAs(StringParseKind.CString)]
55+
public string? XtraName { get; set; }
56+
57+
// TODO: [Entry(12)]
58+
// public int[]? RegistrationPoints { get; set; }
59+
60+
// TODO: 15 - MoA ID?
61+
62+
[Entry(16), ParseStringAs(StringParseKind.FixedBytes)]
63+
public string? ClipboardFormat { get; set; }
64+
65+
[Entry(17)]
66+
public int? CreationDate { get; set; }
67+
68+
[Entry(18)]
69+
public int? ModifiedDate { get; set; }
70+
71+
[Entry(19), ParseStringAs(StringParseKind.CString)]
72+
public string? ModifiedBy { get; set; }
73+
74+
[Entry(20), ParseStringAs(StringParseKind.FixedBytes)]
75+
public string? Comments { get; set; }
76+
77+
// TODO: 21
78+
// ReadOnlySpan<byte> imageFlags = input.ReadBytes(length); //4
79+
//
80+
// ImageCompression = imageFlags[0] >> 4;
81+
// ImageQuality = imageFlags[1];
15182

15283
public int GetBodySize(WriterOptions options)
15384
{

0 commit comments

Comments
 (0)