Skip to content

Commit e5b42cb

Browse files
committed
add explicit loco string counts
1 parent 9930f45 commit e5b42cb

33 files changed

+104
-90
lines changed

OpenLocoTool/DatFileParsing/SawyerStreamReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public ILocoObject LoadFull(string filename, bool loadExtra = true)
112112
static (StringTable table, int bytesRead) LoadStringTable(ReadOnlySpan<byte> data, ILocoStruct locoStruct)
113113
{
114114
var stringAttr = locoStruct.GetType().GetCustomAttribute(typeof(LocoStringCountAttribute), inherit: false) as LocoStringCountAttribute;
115-
var stringsInTable = stringAttr?.Count ?? 1;
115+
var stringsInTable = stringAttr?.Count ?? throw new ArgumentException($"Struct {locoStruct.GetType().Name} had no string count attribute");
116116
var strings = new StringTable();
117117

118118
if (data.Length == 0 || stringsInTable == 0)

OpenLocoTool/Objects/AirportObject.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ public record MovementEdge(
4747

4848
[TypeConverter(typeof(ExpandableObjectConverter))]
4949
[LocoStructSize(0xBA)]
50+
[LocoStringCount(1)]
5051
public record AirportObject(
51-
[property: LocoStructOffset(0x00)] string_id Name,
52+
//[property: LocoStructOffset(0x00)] string_id Name,
5253
[property: LocoStructOffset(0x02)] int16_t BuildCostFactor,
5354
[property: LocoStructOffset(0x04)] int16_t SellCostFactor,
5455
[property: LocoStructOffset(0x06)] uint8_t CostIndex,
5556
[property: LocoStructOffset(0x07)] uint8_t var_07,
56-
[property: LocoStructOffset(0x08)] uint32_t Image,
57+
//[property: LocoStructOffset(0x08)] uint32_t Image,
5758
[property: LocoStructOffset(0x0C)] uint32_t var_0C,
5859
[property: LocoStructOffset(0x10)] uint16_t AllowedPlaneTypes,
5960
[property: LocoStructOffset(0x12)] uint8_t NumSpriteSets,

OpenLocoTool/Objects/BridgeObject.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace OpenLocoTool.Objects
88
// it works just the same but has more code.
99
[TypeConverter(typeof(ExpandableObjectConverter))]
1010
[LocoStructSize(0x2C)]
11+
[LocoStringCount(1)]
1112
public class BridgeObject : ILocoStruct, ILocoStructVariableData
1213
{
1314
public const ObjectType ObjType = ObjectType.Bridge;
@@ -16,9 +17,9 @@ public class BridgeObject : ILocoStruct, ILocoStructVariableData
1617
public const int TrackModsLength = 7;
1718
public const int RoadModsLength = 7;
1819

19-
public BridgeObject(ushort name, byte noRoof, byte[] pad_03, ushort var_06, byte spanLength, byte pillarSpacing, short maxSpeed, byte maxHeight, byte costIndex, short baseCostFactor, short heightCostFactor, short sellCostFactor, ushort disabledTrackCfg, uint image, byte trackNumCompatible, byte[] trackMods, byte roadNumCompatible, byte[] roadMods, ushort designedYear)
20+
public BridgeObject(/*ushort name, */ byte noRoof, byte[] pad_03, ushort var_06, byte spanLength, byte pillarSpacing, short maxSpeed, byte maxHeight, byte costIndex, short baseCostFactor, short heightCostFactor, short sellCostFactor, ushort disabledTrackCfg, /*uint image,*/ byte trackNumCompatible, byte[] trackMods, byte roadNumCompatible, byte[] roadMods, ushort designedYear)
2021
{
21-
Name = name;
22+
//Name = name;
2223
NoRoof = noRoof;
2324
this.pad_03 = pad_03;
2425
this.var_06 = var_06;
@@ -31,7 +32,7 @@ public BridgeObject(ushort name, byte noRoof, byte[] pad_03, ushort var_06, byte
3132
HeightCostFactor = heightCostFactor;
3233
SellCostFactor = sellCostFactor;
3334
DisabledTrackCfg = disabledTrackCfg;
34-
Image = image;
35+
//Image = image;
3536
TrackNumCompatible = trackNumCompatible;
3637
TrackMods = trackMods;
3738
RoadNumCompatible = roadNumCompatible;
@@ -46,7 +47,7 @@ public ReadOnlySpan<byte> Load(ReadOnlySpan<byte> remainingData)
4647
return remainingData[bytesRead..];
4748
}
4849

49-
[LocoStructOffset(0x00)] public string_id Name { get; set; }
50+
//[LocoStructOffset(0x00)] public string_id Name { get; set; }
5051
[LocoStructOffset(0x02)] public uint8_t NoRoof { get; set; }
5152
[LocoStructOffset(0x03), LocoArrayLength(0x06 - 0x03)] public uint8_t[] pad_03 { get; set; }
5253
[LocoStructOffset(0x06)] public uint16_t var_06 { get; set; }
@@ -59,7 +60,7 @@ public ReadOnlySpan<byte> Load(ReadOnlySpan<byte> remainingData)
5960
[LocoStructOffset(0x10)] public int16_t HeightCostFactor { get; set; }
6061
[LocoStructOffset(0x12)] public int16_t SellCostFactor { get; set; }
6162
[LocoStructOffset(0x14)] public uint16_t DisabledTrackCfg { get; set; }
62-
[LocoStructOffset(0x16)] public uint32_t Image { get; set; }
63+
//[LocoStructOffset(0x16)] public uint32_t Image { get; set; }
6364
[LocoStructOffset(0x1A)] public uint8_t TrackNumCompatible { get; set; }
6465
[LocoStructOffset(0x1B), LocoArrayLength(BridgeObject.TrackModsLength)] public uint8_t[] TrackMods { get; set; }
6566
[LocoStructOffset(0x22)] public uint8_t RoadNumCompatible { get; set; }

OpenLocoTool/Objects/BuildingObject.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ public enum BuildingObjectFlags : uint8_t
1616

1717
[TypeConverter(typeof(ExpandableObjectConverter))]
1818
[LocoStructSize(0xBE)]
19+
[LocoStringCount(1)]
1920
public record BuildingObject(
20-
[property: LocoStructOffset(0x00)] string_id Name,
21-
[property: LocoStructOffset(0x02)] uint32_t Image,
21+
//[property: LocoStructOffset(0x00)] string_id Name,
22+
//[property: LocoStructOffset(0x02)] uint32_t Image,
2223
[property: LocoStructOffset(0x06)] uint8_t var_06,
2324
[property: LocoStructOffset(0x07)] uint8_t NumVariations,
2425
[property: LocoStructOffset(0x08), LocoArrayLength(4)] uint8_t[] VariationHeights,

OpenLocoTool/Objects/CliffEdgeObject.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ namespace OpenLocoTool.Objects
66
{
77
[TypeConverter(typeof(ExpandableObjectConverter))]
88
[LocoStructSize(0x06)]
9+
[LocoStringCount(1)]
910
public class CliffEdgeObject : ILocoStruct
1011
{
1112
public const ObjectType ObjType = ObjectType.CliffEdge;
1213
public const int StructSize = 0x06;
1314

14-
public CliffEdgeObject(string_id name, uint32_t image)
15+
public CliffEdgeObject(/*string_id name, uint32_t image*/)
1516
{
16-
Name = name;
17-
Image = image;
17+
//Name = name;
18+
//Image = image;
1819
}
1920

20-
[LocoStructOffset(0x00)] public string_id Name { get; set; }
21-
[LocoStructOffset(0x02)] public uint32_t Image { get; set; }
21+
//[LocoStructOffset(0x00)] public string_id Name { get; set; }
22+
//[LocoStructOffset(0x02)] public uint32_t Image { get; set; }
2223
}
2324
}

OpenLocoTool/Objects/ClimateObject.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ namespace OpenLocoTool.Objects
66
{
77
[TypeConverter(typeof(ExpandableObjectConverter))]
88
[LocoStructSize(0x0A)]
9+
[LocoStringCount(1)]
910
public record ClimateObject(
10-
[property: LocoStructOffset(0x00)] string_id Name,
11+
//[property: LocoStructOffset(0x00)] string_id Name,
1112
[property: LocoStructOffset(0x02)] uint8_t FirstSeason,
1213
[property: LocoStructOffset(0x03), LocoArrayLength(ClimateObject.Seasons)] uint8_t[] SeasonLengths,
1314
[property: LocoStructOffset(0x07)] uint8_t WinterSnowLine,

OpenLocoTool/Objects/CompetitorObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace OpenLocoTool.Objects
88
[LocoStructSize(0x38)]
99
[LocoStringCount(2)]
1010
public record CompetitorObject(
11-
[property: LocoStructOffset(0x00)] string_id var_00,
12-
[property: LocoStructOffset(0x02)] string_id var_02,
11+
//[property: LocoStructOffset(0x00)] string_id var_00,
12+
//[property: LocoStructOffset(0x02)] string_id var_02,
1313
[property: LocoStructOffset(0x04)] uint32_t var_04,
1414
[property: LocoStructOffset(0x08)] uint32_t var_08,
1515
[property: LocoStructOffset(0x0C)] uint32_t Emotions,

OpenLocoTool/Objects/CurrencyObject.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace OpenLocoTool.Objects
99
[LocoStringCount(3)]
1010
public record CurrencyObject
1111
(
12-
[property: LocoStructOffset(0x00)] string_id Name,
13-
[property: LocoStructOffset(0x02)] string_id PrefixSymbol,
14-
[property: LocoStructOffset(0x04)] string_id SuffixSymbol,
12+
//[property: LocoStructOffset(0x00)] string_id Name,
13+
//[property: LocoStructOffset(0x02)] string_id PrefixSymbol,
14+
//[property: LocoStructOffset(0x04)] string_id SuffixSymbol,
1515
[property: LocoStructOffset(0x06)] uint32_t ObjectIcon,
1616
[property: LocoStructOffset(0x0A)] uint8_t Separator,
1717
[property: LocoStructOffset(0x0B)] uint8_t Factor

OpenLocoTool/Objects/DockObject.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ public enum DockObjectFlags : uint16_t
1313

1414
[TypeConverter(typeof(ExpandableObjectConverter))]
1515
[LocoStructSize(0x28)]
16+
[LocoStringCount(1)]
1617
public record DockObject(
17-
[property: LocoStructOffset(0x00)] string_id Name,
18+
//[property: LocoStructOffset(0x00)] string_id Name,
1819
[property: LocoStructOffset(0x02)] int16_t BuildCostFactor,
1920
[property: LocoStructOffset(0x04)] int16_t SellCostFactor,
2021
[property: LocoStructOffset(0x06)] uint8_t CostIndex,
2122
[property: LocoStructOffset(0x07)] uint8_t var_07,
22-
[property: LocoStructOffset(0x08)] uint32_t Image,
23+
//[property: LocoStructOffset(0x08)] uint32_t Image,
2324
[property: LocoStructOffset(0x0C)] uint32_t var_0C,
2425
[property: LocoStructOffset(0x10)] DockObjectFlags Flags,
2526
[property: LocoStructOffset(0x12)] uint8_t NumAux01,

OpenLocoTool/Objects/HillShapesObject.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ namespace OpenLocoTool.Objects
66
{
77
[TypeConverter(typeof(ExpandableObjectConverter))]
88
[LocoStructSize(0x0E)]
9+
[LocoStringCount(1)]
910
public record HillShapesObject(
10-
[property: LocoStructOffset(0x00)] string_id Name,
11+
//[property: LocoStructOffset(0x00)] string_id Name,
1112
[property: LocoStructOffset(0x02)] uint8_t HillHeightMapCount,
1213
[property: LocoStructOffset(0x03)] uint8_t MountainHeightMapCount,
13-
[property: LocoStructOffset(0x04)] uint32_t Image,
14+
//[property: LocoStructOffset(0x04)] uint32_t Image,
1415
[property: LocoStructOffset(0x08)] uint32_t var_08,
1516
[property: LocoStructOffset(0x0C), LocoArrayLength(0x0E - 0x0C)] uint8_t[] pad_0C
1617
) : ILocoStruct

0 commit comments

Comments
 (0)