Skip to content

Commit a2fdcfe

Browse files
committed
Set up a new method for reading GX opcodes and made gracefully handling Dat errors an option.
1 parent 6568a60 commit a2fdcfe

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

FinModelUtility/Libraries/Gx/src/GxDisplayListReader.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ namespace gx;
1111
public class GxDisplayListReader {
1212
public GxPrimitive? Read(IBinaryReader br,
1313
IVertexDescriptor vertexDescriptor) {
14+
this.ReadOpcode(br, vertexDescriptor, out var primitive);
15+
return primitive;
16+
}
17+
18+
public GxOpcode ReadOpcode(IBinaryReader br,
19+
IVertexDescriptor vertexDescriptor,
20+
out GxPrimitive? primitive) {
1421
var opcode = (GxOpcode) br.ReadByte();
22+
primitive = null;
1523

1624
switch (opcode) {
1725
case GxOpcode.NOP: break;
@@ -53,7 +61,8 @@ public class GxDisplayListReader {
5361
for (var i = 0; i < vertices.Length; ++i) {
5462
var vertex = vertices[i] = new GxVertex();
5563

56-
foreach (var (vertexAttribute, vertexFormat, colorComponentType) in vertexDescriptor) {
64+
foreach (var (vertexAttribute, vertexFormat, colorComponentType) in
65+
vertexDescriptor) {
5766
if (vertexAttribute == GxVertexAttribute.Color0 &&
5867
vertexFormat == GxAttributeType.DIRECT) {
5968
Asserts.True(colorComponentType.HasValue);
@@ -141,13 +150,15 @@ public class GxDisplayListReader {
141150
}
142151
}
143152

144-
return new GxPrimitive((GxPrimitiveType) opcode, vertices);
153+
primitive = new GxPrimitive((GxPrimitiveType) opcode, vertices);
154+
break;
145155
}
156+
146157
default: {
147158
throw new NotImplementedException();
148159
}
149160
}
150161

151-
return null;
162+
return opcode;
152163
}
153164
}

FinModelUtility/Libraries/Sysdolphin/Sysdolphin/src/schema/Dat.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,36 @@
33
namespace sysdolphin.schema;
44

55
public class Dat : IBinaryDeserializable {
6+
private const bool IGNORE_ERRORS = false;
7+
68
public LinkedList<DatSubfile> Subfiles { get; } = [];
79

810
public void Read(IBinaryReader br) {
911
do {
10-
var offset = br.Position;
11-
try {
12+
if (!IGNORE_ERRORS) {
13+
var offset = br.Position;
1214
br.PushLocalSpace();
1315
var subfile = br.ReadNew<DatSubfile>();
1416
br.PopLocalSpace();
1517

1618
this.Subfiles.AddLast(subfile);
1719
br.Position = offset + subfile.FileSize;
1820
br.Align(0x20);
19-
} catch (Exception e) {
20-
br.PopLocalSpace();
21-
br.Position = offset;
22-
break;
21+
} else {
22+
var offset = br.Position;
23+
try {
24+
br.PushLocalSpace();
25+
var subfile = br.ReadNew<DatSubfile>();
26+
br.PopLocalSpace();
27+
28+
this.Subfiles.AddLast(subfile);
29+
br.Position = offset + subfile.FileSize;
30+
br.Align(0x20);
31+
} catch (Exception e) {
32+
br.PopLocalSpace();
33+
br.Position = offset;
34+
break;
35+
}
2336
}
2437
} while (!br.Eof);
2538
}

0 commit comments

Comments
 (0)