Skip to content

Commit

Permalink
Unignore lightmap chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBang1112 committed Jul 16, 2024
1 parent 770e0e6 commit 45a77c3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Src/GBX.NET/Engines/Game/CGameCtnChallenge.chunkl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ CGameCtnChallenge 0x03043000 // A map.

0x03A (skippable, ignore)

0x03D (skippable, ignore) [MP3, TMT, MP4] // lightmaps
0x03D (skippable) [MP3, TMT, MP4] // lightmaps

0x03E (skippable) [MP3, TMT, MP4, TM2020] // CarMarksBuffer
version
Expand Down Expand Up @@ -318,7 +318,7 @@ CGameCtnChallenge 0x03043000 // A map.
int
int

0x05B (skippable, ignore) [TM2020] // lightmaps
0x05B (skippable) [TM2020] // lightmaps TM2020

0x05C (skippable, ignore) [TM2020]

Expand Down
71 changes: 61 additions & 10 deletions Src/GBX.NET/Engines/Game/CGameCtnChallenge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,22 @@ public UInt128? HashedPassword
[AppliedWithChunk<Chunk0304303D>]
public bool HasLightmaps { get; set; }

[AppliedWithChunk<HeaderChunk03043003>(sinceVersion: 9)]
[AppliedWithChunk<Chunk0304303D>]
[AppliedWithChunk<Chunk0304305F>]
public int? LightmapVersion { get; set; }

[AppliedWithChunk<Chunk0304303D>]
[AppliedWithChunk<Chunk0304305F>]
public CHmsLightMapCache? LightmapCache { get; set; }

[AppliedWithChunk<Chunk0304303D>]
[AppliedWithChunk<Chunk0304305F>]
public LightmapFrame[]? LightmapFrames { get; set; }

[ZLibData]
[AppliedWithChunk<Chunk0304303D>]
[AppliedWithChunk<Chunk0304305F>]
public CompressedData? LightmapCacheData { get; set; }

private IList<CGameCtnAnchoredObject>? anchoredObjects;
Expand Down Expand Up @@ -798,13 +803,43 @@ public partial class Chunk0304303D
{
public override void Read(CGameCtnChallenge n, GbxReader r)
{
n.HasLightmaps = r.ReadBoolean(); // true is SHmsLightMapCacheSmall is not empty
n.HasLightmaps = r.ReadBoolean(); // true if SHmsLightMapCacheSmall is not empty

if (!n.HasLightmaps)
{
return;
}

ReadLightMapCacheSmall(n, r);
}

public override void Write(CGameCtnChallenge n, GbxWriter w)
{
w.Write(n.HasLightmaps);

if (!n.HasLightmaps)
{
return;
}

WriteLightMapCacheSmall(n, w);
}

internal static void ReadWriteLightMapCacheSmall(CGameCtnChallenge n, GbxReaderWriter rw)
{
if (rw.Reader is not null)
{
ReadLightMapCacheSmall(n, rw.Reader);
}

if (rw.Writer is not null)
{
WriteLightMapCacheSmall(n, rw.Writer);
}
}

private static void ReadLightMapCacheSmall(CGameCtnChallenge n, GbxReader r)
{
n.LightmapVersion = r.ReadInt32();

if (n.LightmapVersion < 2)
Expand All @@ -831,15 +866,8 @@ public override void Read(CGameCtnChallenge n, GbxReader r)
n.LightmapCache = rBuffer.ReadNode<CHmsLightMapCache>();
}

public override void Write(CGameCtnChallenge n, GbxWriter w)
private static void WriteLightMapCacheSmall(CGameCtnChallenge n, GbxWriter w)
{
w.Write(n.HasLightmaps);

if (!n.HasLightmaps)
{
return;
}

w.Write(n.LightmapVersion.GetValueOrDefault());

if (n.LightmapVersion < 2)
Expand Down Expand Up @@ -870,7 +898,6 @@ public override void Write(CGameCtnChallenge n, GbxWriter w)

ms.Position = 0;
using var compressedMs = new MemoryStream();

Gbx.ZLib.Compress(ms, compressedMs);

w.Write(compressedMs.Length);
Expand Down Expand Up @@ -1417,6 +1444,30 @@ public override void ReadWrite(CGameCtnChallenge n, GbxReaderWriter rw)
}
}

public partial class Chunk0304305B : IVersionable
{
public int Version { get; set; }

public bool U01;
public bool U02;

public override void ReadWrite(CGameCtnChallenge n, GbxReaderWriter rw)
{
rw.VersionInt32(this);

n.HasLightmaps = rw.Boolean(n.HasLightmaps);
rw.Boolean(ref U01);
rw.Boolean(ref U02);

if (!n.HasLightmaps)
{
return;
}

Chunk0304303D.ReadWriteLightMapCacheSmall(n, rw);
}
}

public partial class Chunk0304305F : IVersionable
{
/// <summary>
Expand Down

0 comments on commit 45a77c3

Please sign in to comment.