{"record":{"id":"b089feee383a4c43","repo":"babalae/better-genshin-impact","slug":"16-9","errorCode":null,"errorMessage":"游戏分辨率必须是16:9的分辨率","messagePattern":"游戏分辨率必须是16:9的分辨率","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Script/Dependence/GlobalMethod.cs","lineNumber":162,"sourceCode":"        {\n            throw new ArgumentException($\"键盘编码必须是VirtualKeyCodes枚举中的值，当前传入的 {key} 不合法\");\n        }\n    }\n\n    #endregion 键盘操作\n\n    #region 鼠标操作\n\n    private static int _gameWidth = 1920;\n    private static int _gameHeight = 1080;\n    private static double _dpi = 1;\n\n    public static void SetGameMetrics(int width, int height, double dpi = 1)\n    {\n        // 必须16:9 的分辨率\n        if (width * 9 != height * 16)\n        {\n            throw new ArgumentException(\"游戏分辨率必须是16:9的分辨率\");\n        }\n\n        _gameWidth = width;\n        _gameHeight = height;\n        _dpi = dpi;\n    }\n\n    public static double[] GetGameMetrics()\n    {\n        return [_gameWidth, _gameHeight, _dpi];\n    }\n\n    public static void MoveMouseBy(int x, int y)\n    {\n        var realDpi = TaskContext.Instance().DpiScale;\n        x = (int)(x * realDpi / _dpi);\n        y = (int)(y * realDpi / _dpi);\n        Simulation.SendInput.Mouse.MoveMouseBy(x, y);","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/Dependence/GlobalMethod.cs#L144-L180","documentation":"Thrown by GlobalMethod.SetGameMetrics when the provided width and height do not form a 16:9 aspect ratio (checked via width * 9 != height * 16). All coordinate calculations, mouse movement scaling, and UI element matching in this project assume a 16:9 game resolution because Genshin Impact only renders at that aspect ratio.","triggerScenarios":"Calling GlobalMethod.SetGameMetrics(width, height) with a non-16:9 resolution such as 1920x1080 (valid) vs 2560x1080 (21:9, invalid) vs 1920x1200 (16:10, invalid).","commonSituations":"User has an ultrawide monitor and the game is windowed at a non-16:9 size. Script hardcodes resolution from the system display instead of the game capture region. Custom DPI or scaling settings produce non-standard dimensions.","solutions":["Ensure the game runs at a 16:9 resolution (1920x1080, 2560x1440, 3840x2160, 1600x900, 1280x720).","Derive width/height from the actual game capture region rather than the display resolution.","Validate the aspect ratio before calling: if (width * 9 != height * 16) adjust or warn.","If the game is running in borderless/windowed mode, set the window to a 16:9 size."],"exampleFix":"// before\nGlobalMethod.SetGameMetrics(displayWidth, displayHeight);\n\n// after\n// ensure 16:9 by deriving height from width\nvar gameHeight = gameWidth * 9 / 16;\nGlobalMethod.SetGameMetrics(gameWidth, gameHeight, dpi);","handlingStrategy":"validation","validationCode":"// Validate 16:9 aspect ratio before calling SetGameMetrics\nif (width * 9 != height * 16)\n    throw new ArgumentException($\"Resolution {width}x{height} is not 16:9. Use e.g. 1920x1080, 2560x1440.\");\nGlobalMethod.SetGameMetrics(width, height, dpi);","typeGuard":"static bool Is16by9(int width, int height) => width * 9 == height * 16;","tryCatchPattern":null,"preventionTips":["Only use 16:9 resolutions: 1280x720, 1600x900, 1920x1080, 2560x1440, 3840x2160.","Derive dimensions from the game capture region, not the system display.","Ensure the game runs in a 16:9 window or fullscreen mode."],"tags":["validation","resolution","aspect-ratio","game-capture"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}