Skip to content

Commit 728bdfe

Browse files
committed
add a skipread attribute because we need to know the offsets to write 0 to for saving
1 parent 8e54b89 commit 728bdfe

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

OpenLocoTool/DatFileParsing/ByteReader.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ public static ILocoStruct ReadLocoStruct(ReadOnlySpan<byte> data, Type t)
109109
continue;
110110
}
111111

112+
// ignore skipped properties (usually image ids and string ids which are only used in loco itself, not this tool
113+
var skip = AttributeHelper.Get<LocoStructSkipReadAttribute>(p);
114+
if (offsetAttr == null)
115+
{
116+
continue;
117+
}
118+
112119
// special array handling
113120
var arrLength = 0;
114121
if (p.PropertyType.IsArray)

OpenLocoTool/DatFileParsing/ByteWriter.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ public static ReadOnlySpan<byte> WriteLocoStruct(ILocoStruct obj)
106106
continue;
107107
}
108108

109+
// write 0s to properties that need it
110+
var skip = AttributeHelper.Get<LocoStructSkipReadAttribute>(p);
111+
if (skip != null)
112+
{
113+
WriteT(buf, p.PropertyType, offsetAttr.Offset, 0);
114+
continue;
115+
}
116+
109117
// special array handling
110118
var arrLength = 0;
111119
if (p.PropertyType.IsArray)

OpenLocoTool/DatFileParsing/LocoAttributes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public class LocoStringTableAttribute(params string[] names) : Attribute
3030
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false)]
3131
public class LocoStructVariableLoadAttribute : Attribute
3232
{ }
33-
33+
3434
// basically a 'skip' attribute to allow deferred loading for variable data, and writing of this property will be 0
3535
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false)]
36-
public class LocoStructZeroAttribute : Attribute
36+
public class LocoStructSkipReadAttribute : Attribute
3737
{ }
3838
}

OpenLocoTool/Objects/StreetLightObject.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace OpenLocoTool.Objects
88
[LocoStructSize(0xC)]
99
[LocoStringTable("Name")]
1010
public record StreetLightObject(
11-
//[property: LocoStructOffset(0x00)] string_id Name,
12-
[property: LocoStructOffset(0x02), LocoArrayLength(StreetLightObject.DesignedYearLength)] uint16_t[] DesignedYear // 0x2
13-
//[property: LocoStructOffset(0x08)] uint32_t Image
11+
[property: LocoStructOffset(0x00), LocoStructSkipRead, Browsable(false)] string_id Name,
12+
[property: LocoStructOffset(0x02), LocoArrayLength(StreetLightObject.DesignedYearLength)] uint16_t[] DesignedYear,
13+
[property: LocoStructOffset(0x08), LocoStructSkipRead, Browsable(false)] uint32_t Image
1414
) : ILocoStruct
1515
{
1616
public static ObjectType ObjectType => ObjectType.StreetLight;

0 commit comments

Comments
 (0)