Skip to content

Commit

Permalink
Fix encoding of tile IDs from lower mip levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbyte committed Dec 5, 2023
1 parent 1e690df commit 1e1df6e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions LSLib/VirtualTextures/VirtualTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,12 @@ public void LoadFromStream(Stream fs, BinaryReader reader, bool loadThumbnails)
TileSetLevels = new GTSTileSetLevel[Header.NumLevels];
BinUtils.ReadStructs<GTSTileSetLevel>(reader, TileSetLevels);

PerLevelFlatTileIndices = new List<Int32[]>();
PerLevelFlatTileIndices = new List<UInt32[]>();
foreach (var level in TileSetLevels)
{
fs.Position = (uint)level.FlatTileIndicesOffset;
var tileIndices = new Int32[level.Height * level.Width * Header.NumLayers];
BinUtils.ReadStructs<Int32>(reader, tileIndices);
var tileIndices = new UInt32[level.Height * level.Width * Header.NumLayers];
BinUtils.ReadStructs<UInt32>(reader, tileIndices);
PerLevelFlatTileIndices.Add(tileIndices);
}

Expand Down Expand Up @@ -485,7 +485,7 @@ public void SaveToStream(Stream fs, BinaryWriter writer)
var tileIndices = PerLevelFlatTileIndices[i];
Debug.Assert(tileIndices.Length == level.Height * level.Width * Header.NumLayers);

BinUtils.WriteStructs<Int32>(writer, tileIndices);
BinUtils.WriteStructs<UInt32>(writer, tileIndices);
}

Header.LevelsOffset = (ulong)fs.Position;
Expand Down Expand Up @@ -568,7 +568,7 @@ public bool GetTileInfo(int level, int layer, int x, int y, ref GTSFlatTileInfo
{
var tileIndices = PerLevelFlatTileIndices[level];
var tileIndex = tileIndices[layer + Header.NumLayers * (x + y * TileSetLevels[level].Width)];
if (tileIndex >= 0)
if ((tileIndex & 0x80000000) == 0)
{
tile = FlatTileInfos[tileIndex];
return true;
Expand Down

0 comments on commit 1e1df6e

Please sign in to comment.