Skip to content

Commit dfbe216

Browse files
authored
Merge pull request #199 from BigBang1112/dev
2.4.1
2 parents 7ed798a + 5a481e7 commit dfbe216

9 files changed

Lines changed: 105 additions & 14 deletions

File tree

Src/GBX.NET/Engines/Control/CControlList.chunkl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
CControlList 0x0700F000
22
- inherits: CControlContainer
33

4-
0x007 (ignore)
4+
0x007
5+
int
6+
int
7+
int
8+
int
9+
int
10+
int
11+
int
12+
Unknown[]
513

614
0x00A
715
float
@@ -15,3 +23,10 @@ CControlList 0x0700F000
1523
float
1624
float
1725
bool
26+
27+
archive Unknown
28+
string
29+
float
30+
CMwNod
31+
id
32+
bool

Src/GBX.NET/Engines/Game/CGameGhost.Data.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,12 @@ private void ReadNew(GbxReader r)
160160
}
161161
}
162162

163-
// CGameGhostTMData::ArchiveStateTimes
164-
stateTimes = r.ReadArray<int>();
163+
// guessed. there's some difference between TM1 and TM2 here, pls investigate soon
164+
if (Version >= 10 || !IsFixedTimeStep)
165+
{
166+
// CGameGhostTMData::ArchiveStateTimes
167+
stateTimes = r.ReadArray<int>();
168+
}
165169

166170
if (r.BaseStream.Position != r.BaseStream.Length)
167171
{
@@ -264,8 +268,11 @@ private void WriteNew(GbxWriter w)
264268
}
265269
}
266270

267-
// CGameGhostTMData::ArchiveStateTimes
268-
w.WriteArray(stateTimes);
271+
if (Version >= 10 || !IsFixedTimeStep)
272+
{
273+
// CGameGhostTMData::ArchiveStateTimes
274+
w.WriteArray(stateTimes);
275+
}
269276
}
270277

271278
private Sample ReadSample(TimeInt32 time, byte[] sampleData)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace GBX.NET.Engines.Hms;
2+
3+
public partial class CHmsItem
4+
{
5+
protected override bool OnRawChunkIdRead(uint rawChunkId)
6+
{
7+
return rawChunkId != 0;
8+
}
9+
}

Src/GBX.NET/Engines/MwFoundations/CMwNod.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ internal virtual void Read(GbxReaderWriter rw)
3434
{
3535
var rawChunkId = r.ReadHexUInt32();
3636

37+
if (!OnRawChunkIdRead(rawChunkId))
38+
{
39+
return;
40+
}
41+
3742
if (rawChunkId == FACADE)
3843
{
3944
r.Logger?.LogDebug("- FACADE -");
@@ -388,6 +393,11 @@ public virtual void ReadWrite(GbxReaderWriter rw)
388393
}
389394
}
390395

396+
protected virtual bool OnRawChunkIdRead(uint rawChunkId)
397+
{
398+
return true;
399+
}
400+
391401
#if NET8_0_OR_GREATER
392402
[Experimental("GBXNET10001")]
393403
#endif
@@ -518,6 +528,11 @@ public void Save(string fileName, GbxWriteSettings settings = default)
518528
return Chunks.Create<T>();
519529
}
520530

531+
public bool TryCreateChunk<T>(out T chunk) where T : IChunk, new()
532+
{
533+
return Chunks.TryCreate<T>(out chunk);
534+
}
535+
521536
public T? GetChunk<T>() where T : IChunk
522537
{
523538
return Chunks.Get<T>();

Src/GBX.NET/Engines/TrackMania/CCtnMediaBlockUiTMSimpleEvtsDisplay.chunkl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CCtnMediaBlockUiTMSimpleEvtsDisplay 0x24092000
2-
- inherits: CGameCtnMediaBlock
2+
- inherits: CGameCtnMediaBlockUi
33

44
0x000
55

Src/GBX.NET/GBX.NET.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<PackageId>GBX.NET</PackageId>
5-
<VersionPrefix>2.4.0</VersionPrefix>
5+
<VersionPrefix>2.4.1</VersionPrefix>
66
<Authors>BigBang1112</Authors>
77
<Description>General purpose library for Gbx files - data from Nadeo games like Trackmania or Shootmania. It supports high performance serialization and deserialization of 400+ Gbx classes.</Description>
88
<Copyright>Copyright (c) 2026 Petr Pivoňka</Copyright>

Src/GBX.NET/Serialization/BoundedStream.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
internal sealed partial class BoundedStream : Stream
44
{
55
private readonly Stream baseStream;
6-
private readonly long length;
7-
private readonly long startPosition;
6+
private readonly int length;
7+
private readonly int startPosition;
88

9-
private long remaining;
9+
private int remaining;
1010
private MemoryStream? memoryStream;
1111

1212
public override bool CanRead => true;
@@ -22,14 +22,14 @@ public override long Position
2222

2323
public long Remaining => remaining;
2424

25-
public BoundedStream(Stream baseStream, long length)
25+
public BoundedStream(Stream baseStream, int length)
2626
{
2727
this.baseStream = baseStream ?? throw new ArgumentNullException(nameof(baseStream));
2828
if (!baseStream.CanRead) throw new ArgumentException("Base stream must be readable.");
2929
if (length < 0) throw new ArgumentOutOfRangeException(nameof(length));
3030

3131
this.length = length;
32-
startPosition = baseStream.CanSeek ? baseStream.Position : 0;
32+
startPosition = baseStream.CanSeek ? (int)baseStream.Position : 0;
3333
remaining = length;
3434
}
3535

@@ -173,7 +173,7 @@ public override long Seek(long offset, SeekOrigin origin)
173173
memoryStream.Seek(newPosition, SeekOrigin.Begin);
174174
}
175175

176-
remaining = length - newPosition;
176+
remaining = length - (int)newPosition;
177177
return newPosition;
178178
}
179179

Src/GBX.NET/Serialization/Chunking/ChunkSetOfT.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ public interface IChunkSet<TKind> : ICollection<TKind>, IEnumerable<TKind>, IEnu
2525
/// <returns>A new chunk instance.</returns>
2626
T Create<T>() where T : TKind, new();
2727

28+
/// <summary>
29+
/// Tries to create a new chunk using the ID. Returns false if the same chunk ID already exists.
30+
/// </summary>
31+
/// <param name="chunkId">ID of the chunk.</param>
32+
/// <param name="preferHeaderChunks">Whether to prefer creating header chunks if available.</param>
33+
/// <param name="chunk">The created chunk if successful.</param>
34+
/// <returns>True if a new chunk was successfully created, otherwise false.</returns>
35+
bool TryCreate(uint chunkId, bool preferHeaderChunks, out TKind chunk);
36+
37+
/// <summary>
38+
/// Tries to create a new chunk using the chunk type. Returns false if the same chunk already exists.
39+
/// </summary>
40+
/// <typeparam name="T">Type of the chunk.</typeparam>
41+
/// <param name="chunk">The created chunk if successful.</param>
42+
/// <returns>True if a new chunk was successfully created, otherwise false.</returns>
43+
bool TryCreate<T>(out T chunk) where T : TKind, new();
44+
2845
/// <summary>
2946
/// Gets a chunk using the ID.
3047
/// </summary>
@@ -165,6 +182,34 @@ public TKind Create(uint chunkId, bool preferHeaderChunks = false)
165182
return newChunk;
166183
}
167184

185+
public bool TryCreate(uint chunkId, bool preferHeaderChunks, out TKind chunk)
186+
{
187+
if (chunksById.TryGetValue(chunkId, out chunk))
188+
{
189+
return false;
190+
}
191+
192+
chunk = New(chunkId, preferHeaderChunks);
193+
194+
Add(chunk);
195+
196+
return true;
197+
}
198+
199+
public bool TryCreate<T>(out T chunk) where T : TKind, new()
200+
{
201+
if (chunksByType.TryGetValue(typeof(T), out var chunkBase))
202+
{
203+
chunk = (T)chunkBase;
204+
return false;
205+
}
206+
207+
chunk = new T();
208+
Add(chunk);
209+
210+
return true;
211+
}
212+
168213
public TKind? Get(uint chunkId)
169214
{
170215
return chunksById.TryGetValue(chunkId, out var chunk) ? chunk : default;

Tools/ParseRepeater/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"ParseRepeater": {
44
"commandName": "Project",
5-
"commandLineArgs": "\"D:\\GbxTools\\Dataset\\TM10\\Alpine\\Media\\Texture\\AlpineBark.Texture.gbx\""
5+
"commandLineArgs": "\"E:\\Games\\TrackMania Nations ESWC\\GameData\\Tracks\\Replays\\Bench.Replay.Gbx\""
66
}
77
}
88
}

0 commit comments

Comments
 (0)