Skip to content

fix: fixes UOP map chunking issue, increases map loading perf - #2794

Merged
kamronbatman merged 2 commits into
modernuo:mainfrom
DatMoshu:fix/uop-map-chunk-order
Nov 22, 2026
Merged

kamronbatman merged 2 commits into
modernuo:mainfrom
DatMoshu:fix/uop-map-chunk-order

Conversation

@DatMoshu

@DatMoshu DatMoshu commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

TileMatrix loads map#LegacyMUL.uop by copying the entries out of UOPFiles.ReadUOPIndexes, sorting them by offset, reading the first int32 of every chunk, and sorting again on that value (ConvertToMapEntries).

That int32 is not an order field. It is the header of the chunk's first map block. EA's files happen to store the block number there (chunk * 4096), so the sort works on stock data. UOP maps written by other tools need not do that. When the value repeats, the chunks come out in storage order, not map order, and the server's terrain no longer matches the client's: the map draws correctly, but movement is refused because the server is reading other blocks.

We hit this with a custom 6144x4096 map0LegacyMUL.uop whose 96 chunks all start with 1.

Fix

Address map UOPs the way the client does. ClassicUO places each chunk by the index in its hashed name (build/map#legacymul/########.dat) and finds a land block at chunk block >> 12, offset (block & 0xFFF) * 196. TileMatrix now does the same:

  • BuildMapChunks places entries in an array indexed by chunk number; lookup in ReadLandBlock is O(1) instead of a linear scan per block read.
  • A missing or compressed chunk reads as invalid land (with a load-time warning) instead of shifting every later block.
  • The per-chunk seek/read at load is gone. FindOffset (public, no callers) is removed.

UOPFiles.ReadUOPIndexes reads the table first, then hashes candidate names in place until every entry is placed, instead of allocating a string and hash for all 81,920 possible names up front. File lengths over 2 GB no longer truncate to int.

Also fixed while here:

  • ReadStaticBlock read length bytes into a buffer sized for length / 7 tiles, overrunning it when a staidx length is not a multiple of 7. It now reads whole tiles only.
  • Land and static reads use ReadExactly, so a short read hits the existing error path instead of reusing stale bytes.
  • The EOS warnings go through the logger instead of Console.WriteLine.

Tests

TileMatrixUopOrderTests (Server.Tests):

  • BuildMapChunks_IgnoresRepeatedChunkHeaders (3 and 40 chunks): a synthetic map UOP whose chunks all start with the same int32, stored in reverse; every chunk resolves to its own data.
  • BuildMapChunks_MissingChunkLeavesHole: a gap in chunk indexes leaves an empty slot and later chunks keep their place.
  • ReadUOPIndexes_FindsAdditionalHashes: named extras (as MultiData uses for housing.bin) still resolve.

Verification

  • Against two real client installs (stock EA and a custom shard), every land block of maps 0–5 resolves to the same byte offset as before, and the art and multi indexes are identical entry for entry.
  • Index load: ~14 ms → ~0.2 ms per map file, 38 → 17 ms for art, 13 → 0.9 ms for multis.
  • Server.Tests 1113/1113, UOContent.Tests 1370/1370.

DatMoshu and others added 2 commits November 21, 2026 22:39
TileMatrix re-sorted map#LegacyMUL.uop chunks by the first int32 of each chunk. That value is the header of the chunk's first block; EA's files happen to store the block number there, but UOPs written by other tools can repeat it, and the map then loads scrambled on the server while clients (which order by the hashed entry name) draw it correctly. ReadUOPIndexes already keys entries by the index decoded from the name, so use that order. This also drops a seek per chunk at load.
Clients locate a land block in a map UOP as chunk (block >> 12) at
(block & 0xFFF) * 196, with chunks placed by the index in their hashed
name. Packing chunks by size only agreed with that when every chunk is
present and full; a missing chunk shifted the rest of the map. Chunks
are now indexed by number, so lookup is O(1) and a missing or
compressed chunk reads as invalid land instead of another block's.

ReadUOPIndexes reads the table first and hashes names in place until
every entry is placed: ~0.2ms per map file instead of ~14ms, with no
per-name string allocation. Checked against two client installs (stock EA and a custom shard):
every block of maps 0-5 resolves to the same offset, and art and multi
indexes are identical.

ReadStaticBlock read `length` bytes into a buffer sized length / 7
tiles, overrunning it when a staidx length is not a multiple of 7. It
now reads whole tiles with ReadExactly, as does ReadLandBlock, so a
short read fails instead of reusing stale bytes. Warnings go through
the logger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kamronbatman
kamronbatman force-pushed the fix/uop-map-chunk-order branch from 7fea079 to 8578654 Compare November 22, 2026 19:29
@kamronbatman kamronbatman changed the title fix: order map UOP chunks by index, not by their first int32 fix: fixes UOP map chunking issue, increases map loading perf Nov 22, 2026
@kamronbatman
kamronbatman merged commit 4d9e2b6 into modernuo:main Nov 22, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants