aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 14d1907e12db140daefb39fe216623ffbcf86efb
parent 03ea0b6b435e7051cf8e7910ae9150c0da986617
Author: anon <anon@example.com>
Date:   Tue, 27 Oct 2026 17:53:02 +0000

Decode original dungeon tilemaps for server room physics

Diffstat:
MTODO.md | 7+++++++
Mdocs/mission-interiors.md | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/dungeon_tilemap.go | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/dungeon_tilemap_test.go | 175+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 369 insertions(+), 0 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -1532,6 +1532,13 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md). or client patch is needed. Recover automatic-opening/access policy and enforce locked/revoked-key admission authoritatively; test denial, auto-open, forged movement, concurrent use, reconnect and exit instead of relying on native blocking. + The Go server now decodes the original dungeon tile, floor and ceiling grids + and archived tileset heights from all four libraries. Independent decoding + verifies every grid byte; a published-WASM fixture also matches all three + library330 grids byte for byte. Connect transformed room collision, floor + sampling and walkable/ceiling admission before enabling private entry. + Resolve why library330 tileset types0/1 load as zero in WASM despite archived + height words65535; preserve raw data until the producer is established. This is not usable entry, recovered style selection or a private-world boundary. See [mission interiors](docs/mission-interiors.md) and [doors](docs/mission-doors.md). - [ ] [P1] Complete mission-key destination metadata and duplication. Check: diff --git a/docs/mission-interiors.md b/docs/mission-interiors.md @@ -12,6 +12,7 @@ The inspected original 14.9.1 binaries are: - `kkr.dll`, SHA256 `a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`. - `llr.dll`, SHA256 `ebb09047f6ead192388f7ddfb4795da5013a60f7c2d1c3933ec02eef58a10132`. - `hhr.dll`, SHA256 `782a212c2ca8b5b90eab835fae689b40ae0c2bcf1b3d0165b117d4fb1505908e`. +- `bbr.dll`, SHA256 `28f196f650edbb1573fb874ccaf7746453d3e4a183e1d86db1d790c1c32ecc2c`. LLR's proxy reader `0x1004ac70` requires byte `a`, then six uint32 fields: model type/instance, group selector, subgroup, and running playfield type/instance. @@ -253,3 +254,58 @@ Additional complete evidence bundles in the same directory are (connection matching), and `ev_71bd9ed49c16e7a4976985009e92caa6d47a22847fae67061f224d10b6a13600` (door-open query). + +## Server dungeon floor data + +The server's outdoor terrain reader cannot supply dungeon floor heights or +walkable cells. `dungeon_tilemap.go` now decodes original resource1000009's +`GNDA` format for the four room libraries: playfields331/341/346/351 use +maps330/340/345/350. The source tilemaps are100x100,200x200,200x200 and250x250, +respectively, with two-unit tile spacing. This is a decoder dependency; no +private-world admission or movement consumer is enabled by this change. + +BBR's reader `0x100a3dd0` and header parser `0x100a43f0` define the dimensions, +height scale and variable tileset records. Subsequent `DCGA`, `DHGA` and `HCDA` +chunks contain8-bit grayscale PNGs for tile types, floor samples and ceiling +samples. Their declared lengths include12-byte headers and each chunk has +relative four-byte alignment. Optional `TAHA` appears in the Omnilab/Subway +libraries. The final `HSTA` length instead counts only its uint16 height words; +those words are multiplied by the original float32 value0.1. + +`HCDA` decoding (`BBR:0x100a4870`) adds32 to each stored byte with byte +wraparound. `LLR:0x10039f00` subtracts32 after loading, before applying the +height scale. Retaining that intermediate byte conversion matters: adding32 as +an unrestricted integer changes the ceiling values. Tile types preserve their +high wall bit; the lower seven bits select a tileset height. + +Tests compare every byte of all12 grids against independent Pillow decoding, +including the optional chunks and ceiling wraparound. Malformed headers, +dimensions, scales, tileset lists, chunk lengths/versions, PNG data, height +records, unsupported tile indices and trailing bytes must fail without usable +geometry. These checks do not establish room placement, floor triangulation, +liquid handling or authoritative room-transition behavior. + +A headed GPU run of the published WASM client loads the two-room protocol +fixture as owned player289. Read-only guest-memory capture matches all30000 +map330 tile/floor/ceiling bytes, dimensions, spacing and scale. The three +ordinary tileset heights also match. Types0/1 load as zero despite their +archived uint16 height words65535. The live preview serves exactly the original +6032-byte map330 record (SHA256 +`eb749f11b9a0322b9da329b5628cc7739702d7f297ebb2244acb1d9403969e9c`), +so stale asset data does not explain the discrepancy. The decoder retains the +archived values; recover the producer of the runtime zeros before using these +heights for room admission. No client patch or inferred sentinel rule is added. +The owned browser and analysis sessions are closed; the single shared preview +remains running. + +Evidence and reproductions are in `local/mission-interior/`: +`llr-room-surfaces-evidence.json`, `bbr-dungeon-ground-evidence.json`, +`tmp_tilemap_decode.py`, `runtime-dungeon-ground/`, +`dungeon-ground-native-verification.json` and +`live-tilemap-source-verification.json`. The original surface lookup +(`LLR:0x1003edd0`) uses identity1000013/`library<<16|roomOrdinal`; both selected +original room meshes already decode through the server's existing KD-tree +reader. Native room queries select one containing room and transform queries +into its template coordinates (`0x100364c0`/`0x10036780`), rather than combining +all room meshes indiscriminately. These static observations still require a +server integration and native comparison of placed query results. diff --git a/server/dungeon_tilemap.go b/server/dungeon_tilemap.go @@ -0,0 +1,131 @@ +package main + +import ( + "bytes" + "encoding/binary" + "fmt" + "image" + "image/png" + "io" + "math" +) + +type dungeonTilemap struct { + width, depth int + spacing, scale float32 + tiles, floors, ceilings []byte + tilesetHeights []float32 +} + +func decodeDungeonTilemap(data []byte) (*dungeonTilemap, error) { + // BBR 14.9.1 0x100a3dd0/0x100a43f0: dungeon header and tileset records. + if len(data) < 26 || string(data[:4]) != "GNDA" || binary.LittleEndian.Uint32(data[4:8]) != uint32(len(data)) || binary.LittleEndian.Uint32(data[8:12]) != 1 { + return nil, fmt.Errorf("invalid dungeon tilemap header") + } + ground := &dungeonTilemap{ + width: int(binary.LittleEndian.Uint16(data[12:14])), depth: int(binary.LittleEndian.Uint16(data[14:16])), + spacing: math.Float32frombits(binary.LittleEndian.Uint32(data[16:20])), + scale: math.Float32frombits(binary.LittleEndian.Uint32(data[20:24])), + } + count := int(binary.LittleEndian.Uint16(data[24:26])) + if ground.width == 0 || ground.depth == 0 || !(ground.spacing > 0 && ground.spacing < math.MaxFloat32) || !(ground.scale > 0 && ground.scale < math.MaxFloat32) || count == 0 || count > 128 || count*2 > len(data)-26 { + return nil, fmt.Errorf("invalid dungeon tilemap dimensions or tilesets") + } + reader := &surfaceReader{Reader: bytes.NewReader(data[26+count*2:])} + for range count { + var neighbors, extras byte + reader.read(&neighbors) + reader.read(&extras) + length := int(neighbors)*34 + int(extras)*2 + if reader.err != nil || length > reader.Len() { + return nil, fmt.Errorf("truncated dungeon tileset") + } + reader.Seek(int64(length), io.SeekCurrent) + } + + // Chunk lengths include their headers; alignment is relative to each chunk. + chunk := func(magic string, version uint32) []byte { + var header [12]byte + reader.read(&header) + length := int(binary.LittleEndian.Uint32(header[4:8])) + padded := (length + 3) &^ 3 + if reader.err != nil || string(header[:4]) != magic || binary.LittleEndian.Uint32(header[8:]) != version || length < 12 || padded-12 > reader.Len() { + reader.err = fmt.Errorf("invalid dungeon %s chunk", magic) + return nil + } + payload := make([]byte, length-12) + reader.read(payload) + reader.Seek(int64(-length&3), io.SeekCurrent) + return payload + } + for index, magic := range []string{"DCGA", "DHGA", "HCDA"} { + payload := chunk(magic, 1) + if reader.err != nil { + return nil, reader.err + } + grid, err := decodeDungeonGrid(payload, ground.width, ground.depth) + if err != nil { + return nil, fmt.Errorf("dungeon %s: %w", magic, err) + } + switch index { + case 0: + ground.tiles = grid + case 1: + ground.floors = grid + case 2: + // BBR 0x100a4870 adds 32 to every ceiling byte, with byte wraparound. + for index := range grid { + grid[index] += 32 + } + ground.ceilings = grid + } + } + chunk("IRHA", 1) + cursor := len(data) - reader.Len() + if reader.Len() >= 4 && string(data[cursor:cursor+4]) == "TAHA" { + chunk("TAHA", 1) + } + chunk("XTHA", 2) + if reader.err != nil { + return nil, reader.err + } + + // HSTA uses a payload length, unlike the preceding chunks (BBR 0x100a40a9). + var header [12]byte + reader.read(&header) + if reader.err != nil || string(header[:4]) != "HSTA" || binary.LittleEndian.Uint32(header[4:8]) != uint32(count*2) || binary.LittleEndian.Uint32(header[8:]) != 1 || reader.Len() != count*2 { + return nil, fmt.Errorf("invalid dungeon tileset heights") + } + ground.tilesetHeights = make([]float32, count) + for index := range ground.tilesetHeights { + var height uint16 + reader.read(&height) + ground.tilesetHeights[index] = float32(height) * .1 + } + for _, tile := range ground.tiles { + if int(tile&127) >= count { + return nil, fmt.Errorf("invalid dungeon tile type %d", tile&127) + } + } + return ground, nil +} + +func decodeDungeonGrid(data []byte, width, depth int) ([]byte, error) { + // The three dungeon grids are 8-bit grayscale PNGs, not outdoor height archives. + config, err := png.DecodeConfig(bytes.NewReader(data)) + if err != nil { + return nil, err + } + if config.Width != width || config.Height != depth { + return nil, fmt.Errorf("dungeon grid dimensions do not match header") + } + decoded, err := png.Decode(bytes.NewReader(data)) + if err != nil { + return nil, err + } + grid, ok := decoded.(*image.Gray) + if !ok { + return nil, fmt.Errorf("dungeon grid is not 8-bit grayscale") + } + return grid.Pix, nil +} diff --git a/server/dungeon_tilemap_test.go b/server/dungeon_tilemap_test.go @@ -0,0 +1,175 @@ +package main + +import ( + "ao/server/assets" + "bytes" + "crypto/sha256" + "encoding/binary" + "fmt" + "image" + "image/color" + "image/png" + "math" + "reflect" + "testing" +) + +func TestDungeonTilemapsMatchIndependentOriginalGridDecoding(t *testing.T) { + database, err := readGameDatabase(assets.Files) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { database.file.Close() }) + for _, scenario := range []struct { + identity uint32 + side int + scale float32 + hashes [3]string + heights []float32 + }{ + {330, 100, .1, [3]string{ + "2808d528a81b88c3c37808887b6c4712588377696a93239ab3c52dfefd7d2b59", + "95b532cc4381affdff0d956e12520a04129ed49d37e154228368fe5621f0b9a2", + "ef6c81c142f881bd638e52012fd2646242f5885aa9be4ba2b19c5e1d33340715", + }, []float32{6553.5, 6553.5, 6, 4, 5.9}}, + {340, 200, .2, [3]string{ + "344736479714df221c954a06020dfb23d07872fb7be9252b4b87500cef1ef419", + "5952e1620df717806b9af62dad448f29b433d996703085ec51c64c73d30ad7d8", + "fe2e87b2a1956b2f659afc806b6e7b239abefe26fbc15621372bdb11a6f5dc98", + }, []float32{4, 4, 8, 16}}, + {345, 200, .2, [3]string{ + "de4e7bd3ebc2a1a5e8820a37632200bc0132e5ac495f72f3d37653fab43d2eef", + "c81d14ae6216646cd8e84445b5ac7f3196695e61ab91251fdacce9ddbfccf9fa", + "d48c0cc689d415991494248a8cf58c821eda3ba9ac290a4e0e91b4e006c5e57a", + }, []float32{4, 4, 4, 6, 6, 4, 7.9, 15.90000057220459, 31.9, 4, 7.9, 15.90000057220459, 4, 7.9, 7.9}}, + {350, 250, .2, [3]string{ + "13b895b06489b290986d1f9822bf04ec671a54a03c5daf16040f14ccdc31b2c7", + "077a926a70cad20b277fc941b4b7bb0fe5ee473f6f37e55443e633ebf6b6b34c", + "b7191e59909d2c72b2e9c7a281b080cf098e6974d4069f693a2d89194027b7aa", + }, []float32{4, 4, 8, 4, 6, 4, 7.9, 15.90000057220459, 4, 7.9}}, + } { + t.Run(fmt.Sprint(scenario.identity), func(t *testing.T) { + data, _, err := database.read(1000009, scenario.identity) + if err != nil { + t.Fatal(err) + } + + ground, err := decodeDungeonTilemap(data) + + if err != nil { + t.Fatal(err) + } + if ground.width != scenario.side || ground.depth != scenario.side || ground.spacing != 2 || ground.scale != scenario.scale || !reflect.DeepEqual(ground.tilesetHeights, scenario.heights) { + t.Fatal("original dungeon dimensions, scale or tileset heights", ground.width, ground.depth, ground.spacing, ground.scale, ground.tilesetHeights) + } + for index, grid := range [][]byte{ground.tiles, ground.floors, ground.ceilings} { + if len(grid) != scenario.side*scenario.side || fmt.Sprintf("%x", sha256.Sum256(grid)) != scenario.hashes[index] { + t.Fatal("independent grayscale grid mismatch", index) + } + } + }) + } +} + +func TestDungeonTilemapRejectsMalformedOriginalRecords(t *testing.T) { + database, err := readGameDatabase(assets.Files) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { database.file.Close() }) + original, _, err := database.read(1000009, 330) + if err != nil { + t.Fatal(err) + } + for _, scenario := range []struct { + name string + change func([]byte) []byte + }{ + {"short header", func(data []byte) []byte { return data[:25] }}, + {"outdoor format", func(data []byte) []byte { copy(data[:4], "CHGA"); return data }}, + {"length", func(data []byte) []byte { data[4]++; return data }}, + {"version", func(data []byte) []byte { data[8] = 2; return data }}, + {"zero width", func(data []byte) []byte { clear(data[12:14]); return data }}, + {"zero depth", func(data []byte) []byte { clear(data[14:16]); return data }}, + {"infinite spacing", func(data []byte) []byte { + binary.LittleEndian.PutUint32(data[16:20], math.Float32bits(float32(math.Inf(1)))) + return data + }}, + {"NaN spacing", func(data []byte) []byte { + binary.LittleEndian.PutUint32(data[16:20], math.Float32bits(float32(math.NaN()))) + return data + }}, + {"zero scale", func(data []byte) []byte { clear(data[20:24]); return data }}, + {"negative scale", func(data []byte) []byte { + binary.LittleEndian.PutUint32(data[20:24], math.Float32bits(-1)) + return data + }}, + {"no tilesets", func(data []byte) []byte { clear(data[24:26]); return data }}, + {"too many tilesets", func(data []byte) []byte { data[24] = 129; return data }}, + {"truncated neighbors", func(data []byte) []byte { data[36] = 255; return data }}, + {"wrong chunk", func(data []byte) []byte { data[318] = 'X'; return data }}, + {"chunk version", func(data []byte) []byte { data[326] = 2; return data }}, + {"undersized chunk", func(data []byte) []byte { binary.LittleEndian.PutUint32(data[322:326], 11); return data }}, + {"oversized chunk", func(data []byte) []byte { binary.LittleEndian.PutUint32(data[322:326], math.MaxUint32); return data }}, + {"damaged PNG", func(data []byte) []byte { data[340] ^= 255; return data }}, + {"grid dimensions", func(data []byte) []byte { data[12] = 99; return data }}, + {"ceiling chunk", func(data []byte) []byte { data[1022] = 'X'; return data }}, + {"room index chunk", func(data []byte) []byte { data[1134] = 'X'; return data }}, + {"texture chunk", func(data []byte) []byte { data[1514] = 'Z'; return data }}, + {"texture version", func(data []byte) []byte { data[1522] = 1; return data }}, + {"tileset height length", func(data []byte) []byte { data[6014] = 12; return data }}, + {"tileset height version", func(data []byte) []byte { data[6018] = 2; return data }}, + {"truncated heights", func(data []byte) []byte { + data = data[:len(data)-1] + binary.LittleEndian.PutUint32(data[4:8], uint32(len(data))) + return data + }}, + {"trailing bytes", func(data []byte) []byte { + data = append(data, 0) + binary.LittleEndian.PutUint32(data[4:8], uint32(len(data))) + return data + }}, + } { + t.Run(scenario.name, func(t *testing.T) { + data := scenario.change(bytes.Clone(original)) + + ground, err := decodeDungeonTilemap(data) + + if err == nil || ground != nil { + t.Fatal("malformed dungeon must not produce usable geometry", err) + } + }) + } +} + +func TestDungeonTilemapRejectsTileTypesWithoutAnAuthoredHeight(t *testing.T) { + database, err := readGameDatabase(assets.Files) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { database.file.Close() }) + data, _, err := database.read(1000009, 330) + if err != nil { + t.Fatal(err) + } + grid := image.NewGray(image.Rect(0, 0, 100, 100)) + grid.SetGray(50, 50, color.Gray{Y: 5}) + var encoded bytes.Buffer + if err := png.Encode(&encoded, grid); err != nil { + t.Fatal(err) + } + length := encoded.Len() + 12 + replacement := binary.LittleEndian.AppendUint32([]byte("DCGA"), uint32(length)) + replacement = binary.LittleEndian.AppendUint32(replacement, 1) + replacement = append(replacement, encoded.Bytes()...) + replacement = append(replacement, make([]byte, -length&3)...) + modified := append(bytes.Clone(data[:318]), replacement...) + modified = append(modified, data[918:]...) + binary.LittleEndian.PutUint32(modified[4:8], uint32(len(modified))) + + ground, err := decodeDungeonTilemap(modified) + + if err == nil || ground != nil { + t.Fatal("tile type 5 has no height in the five-tileset archive", err) + } +}