{"record":{"id":"f624259d9fc14427","repo":"egametang/ET","slug":"invalid-magic-f62425","errorCode":null,"errorMessage":"Invalid magic","messagePattern":"Invalid magic","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.recast/Scripts/Core/Share/Detour.TileCache/Io/DtTileCacheLayerHeaderReader.cs","lineNumber":35,"sourceCode":" misrepresented as being the original software.\n3. This notice may not be removed or altered from any source distribution.\n*/\n\nusing System.IO;\nusing DotRecast.Core;\n\nnamespace DotRecast.Detour.TileCache.Io\n{\n    public class DtTileCacheLayerHeaderReader\n    {\n        public DtTileCacheLayerHeader Read(RcByteBuffer data, bool cCompatibility)\n        {\n            DtTileCacheLayerHeader header = new DtTileCacheLayerHeader();\n            header.magic = data.GetInt();\n            header.version = data.GetInt();\n\n            if (header.magic != DtTileCacheLayerHeader.DT_TILECACHE_MAGIC)\n                throw new IOException(\"Invalid magic\");\n            if (header.version != DtTileCacheLayerHeader.DT_TILECACHE_VERSION)\n                throw new IOException(\"Invalid version\");\n\n            header.tx = data.GetInt();\n            header.ty = data.GetInt();\n            header.tlayer = data.GetInt();\n            \n            header.bmin.x = data.GetFloat();\n            header.bmin.y = data.GetFloat();\n            header.bmin.z = data.GetFloat();\n            header.bmax.x = data.GetFloat();\n            header.bmax.y = data.GetFloat();\n            header.bmax.z = data.GetFloat();\n\n            header.hmin = data.GetShort() & 0xFFFF;\n            header.hmax = data.GetShort() & 0xFFFF;\n            header.width = data.Get() & 0xFF;\n            header.height = data.Get() & 0xFF;","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Core/Share/Detour.TileCache/Io/DtTileCacheLayerHeaderReader.cs#L17-L53","documentation":"DtTileCacheLayerHeaderReader.Read parses the first two ints of a layer blob as magic and version. The magic must equal DT_TILECACHE_MAGIC ('D','T','L','R' = 0x44544C52). A mismatch means the bytes are not a tile-cache layer, or were byte-swapped relative to the reader's endianness. Thrown as IOException, so callers see it as an IO/deserialization error.","triggerScenarios":"DecompressTileCacheLayer (or direct header read) on bytes whose first int isn't DT_TILECACHE_MAGIC: wrong file type, truncated header, or endianness swapped (the reader does not auto-swap, unlike the set reader).","commonSituations":"Feeding a navmesh tile or a tile-cache *set* where a single layer is expected; data produced by a different tool/version; reading little-endian bytes with a big-endian RcByteBuffer.","solutions":["Confirm the source is a single compressed tile-cache layer (not a set or navmesh tile).","Make the RcByteBuffer order match the byte order used at write time; the layer reader does not auto-detect endianness.","Re-export the layer with the current DotRecast version if it came from an incompatible producer."],"exampleFix":"// before: wrong endianness / wrong blob type\nvar buf = new RcByteBuffer(bytes) { Order = RcByteOrder.BIG_ENDIAN };\nvar header = reader.Read(buf, cCompatibility: true);\n\n// after: match writer order, and feed a single layer blob\nvar buf = new RcByteBuffer(layerBytes) { Order = writerOrder };\nvar header = reader.Read(buf, cCompatibility: cCompatAtWriteTime);","handlingStrategy":"validation","validationCode":"// Peek magic in the buffer's byte order before reading\nint magic = buf.GetInt();\nif (magic != DtTileCacheLayerHeader.DT_TILECACHE_MAGIC)\n    throw new InvalidDataException($\"not a tile-cache layer (magic=0x{magic:X8})\");\nbuf.Position -= 4; // rewind for the reader","typeGuard":null,"tryCatchPattern":"try { header = reader.Read(buf, cCompat); }\ncatch (IOException e) when (e.Message == \"Invalid magic\")\n{ /* wrong blob type or wrong endianness; do not retry unchanged */ }","preventionTips":["Ensure the source is a single tile-cache layer, not a set or navmesh tile.","Set the RcByteBuffer order to the writer's order; the layer reader does not auto-swap.","Re-export layers with the current version if provenance is unclear."],"tags":["io","detour-tilecache","serialization","magic"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}