Repository navigation
fix: fixes UOP map chunking issue, increases map loading perf - #2794
Merged
Merged
Conversation
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
force-pushed
the
fix/uop-map-chunk-order
branch
from
November 22, 2026 19:29
7fea079 to
8578654
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
TileMatrixloadsmap#LegacyMUL.uopby copying the entries out ofUOPFiles.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.uopwhose 96 chunks all start with1.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 chunkblock >> 12, offset(block & 0xFFF) * 196.TileMatrixnow does the same:BuildMapChunksplaces entries in an array indexed by chunk number; lookup inReadLandBlockis O(1) instead of a linear scan per block read.FindOffset(public, no callers) is removed.UOPFiles.ReadUOPIndexesreads 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 toint.Also fixed while here:
ReadStaticBlockreadlengthbytes into a buffer sized forlength / 7tiles, overrunning it when a staidx length is not a multiple of 7. It now reads whole tiles only.ReadExactly, so a short read hits the existing error path instead of reusing stale bytes.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 (asMultiDatauses forhousing.bin) still resolve.Verification