{"record":{"id":"c45b38a86649d64b","repo":"babalae/better-genshin-impact","slug":"frame-payloadtype","errorCode":null,"errorMessage":"预期相对鼠标帧，实际为 {frame.PayloadType}。","messagePattern":"预期相对鼠标帧，实际为 (.+?)。","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/Instance/InstanceIpcProtocol.cs","lineNumber":197,"sourceCode":"        var offset = RelativeMouseBatchHeaderLength;\n        foreach (var sample in samples)\n        {\n            BinaryPrimitives.WriteInt32LittleEndian(span[offset..], sample.DeltaX);\n            BinaryPrimitives.WriteInt32LittleEndian(span[(offset + sizeof(int))..], sample.DeltaY);\n            var offsetMicroseconds = checked((int)((sample.Timestamp.ToUniversalTime().Ticks - baseTicks) / 10));\n            BinaryPrimitives.WriteInt32LittleEndian(span[(offset + sizeof(int) * 2)..], offsetMicroseconds);\n            offset += RelativeMouseSampleLength;\n        }\n\n        return payload;\n    }\n\n    internal static (ulong FirstSequence, RelativeMouseSample[] Samples) ReadRelativeMouseBatch(\n        InstanceIpcFrame frame)\n    {\n        if (frame.PayloadType != InstanceIpcPayloadType.RelativeMouseBatch)\n        {\n            throw new InvalidDataException($\"预期相对鼠标帧，实际为 {frame.PayloadType}。\");\n        }\n\n        var span = frame.Payload.AsSpan();\n        if (span.Length < RelativeMouseBatchHeaderLength)\n        {\n            throw new InvalidDataException(\"相对鼠标帧头不完整。\");\n        }\n\n        var count = BinaryPrimitives.ReadUInt16LittleEndian(span);\n        if (count is 0 or > 64\n            || span.Length != RelativeMouseBatchHeaderLength + RelativeMouseSampleLength * count)\n        {\n            throw new InvalidDataException(\"相对鼠标帧长度无效。\");\n        }\n\n        var firstSequence = BinaryPrimitives.ReadUInt64LittleEndian(span[sizeof(ushort)..]);\n        var baseTicks = BinaryPrimitives.ReadInt64LittleEndian(span[(sizeof(ushort) + sizeof(ulong))..]);\n        var samples = new RelativeMouseSample[count];","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Instance/InstanceIpcProtocol.cs#L179-L215","documentation":"Thrown by InstanceIpcProtocol.ReadRelativeMouseBatch when the frame's PayloadType is not RelativeMouseBatch. The mouse-batch reader was invoked on a frame carrying a different payload type (JSON or RelativeMouseResult), indicating the receive-loop dispatch routed the frame to the wrong reader.","triggerScenarios":"The receive loop in InstanceConnection checked PayloadType == RelativeMouseBatch and called ReadRelativeMouseBatch, but the frame's actual type differs — a dispatch contradiction, typically from protocol version skew or a peer that mutates the type byte.","commonSituations":"Mixed-version root/child instances with different mouse-frame dispatch logic; stream corruption flipping the payload-type byte; a peer implementation error.","solutions":["Restart both instances to reset the pipe session.","Ensure both instances are the same build so mouse-frame dispatch matches.","If reproducing, log the raw payload-type byte to confirm whether it is corruption or a logic mismatch."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (frame.PayloadType != InstanceIpcPayloadType.RelativeMouseBatch)\n{\n    throw new InvalidDataException($\"预期相对鼠标帧，实际为 {frame.PayloadType}。\");\n}","typeGuard":"static bool IsRelativeMouseBatchFrame(InstanceIpcFrame frame) => frame.PayloadType == InstanceIpcPayloadType.RelativeMouseBatch;","tryCatchPattern":"try\n{\n    var batch = InstanceIpcProtocol.ReadRelativeMouseBatch(frame.Value);\n}\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"预期相对鼠标帧\"))\n{\n    logger.LogError(ex, \"Frame type mismatch in mouse-batch reader; restart instances\");\n}","preventionTips":["Run matching builds so mouse-frame dispatch logic is identical on both ends.","Restart instances on a frame-type mismatch to reset the pipe.","Trace raw payload-type bytes if the error reproduces to find corruption vs. logic bugs."],"tags":["ipc","protocol","mouse","named-pipe"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}