diff --git a/docs/UrlProtocol.md b/docs/UrlProtocol.md index ad8236ca8..fc915bb1c 100644 --- a/docs/UrlProtocol.md +++ b/docs/UrlProtocol.md @@ -4,10 +4,9 @@ Other software even website could use url protocol `starward` to call some featu ![URL Protocol](https://user-images.githubusercontent.com/61003590/278273851-7c614cde-d8c4-403b-876e-cecc3570f684.png) - ## Available features -The parameter `game_biz` in the following is game region identifier and can be viewed in [GameBiz.cs](https://github.com/Scighost/Starward/blob/main/src/Starward.Core/GameBiz.cs). +The parameter `game_biz` in the following is game region identifier and can be viewed in [GameBiz.cs](https://github.com/Scighost/Starward/blob/main/src/Starward.Core/GameBiz.cs). | game_biz | Value | Description | | ----------------- | ----- | --------------------------------------- | @@ -29,24 +28,40 @@ The parameter `game_biz` in the following is game region identifier and can be | bh3_kr | 34 | Honkai 3rd (Korea) | | bh3_overseas | 35 | Honkai 3rd (Southeast Asia) | | bh3_tw | 36 | Honkai 3rd (Traditional Chinese) | - +| **ZZZ** | 40 | Zenless Zone Zero | +| nap_cn | 41 | Zenless Zone Zero (Mainland China) | +| nap_global | 42 | Zenless Zone Zero (Global) | +| nap_bilibili | 44 | Zenless Zone Zero (Bilibili) | ### Start game -``` +```url starward://startgame/{game_biz} ``` **Acceptable query arguments** -|Key|Type|Description| -|---|---|---| -|uid| `number` | Switch to specific account before startup. | -|install_path| `string` | Full folder of game executable. | - +| Key | Type | Description | +| ------------ | -------- | ------------------------------------------ | +| uid | `number` | Switch to specific account before startup. | +| install_path | `string` | Full folder of game executable. | ### Record playtime -``` +```url starward://playtime/{game_biz} ``` + +### Game Config Change + +```url +starward://gameconfig/{game_biz} +``` + +**Acceptable query arguments** + +| Key | Type | Description | +| ------------ | --------- | -------------------------- | +| width | `number` | Width of game resolution. | +| height | `number` | Height of game resolution. | +| isfullscreen | `boolean` | Fullscreen mode. | diff --git a/src/Starward/Services/UrlProtocolService.cs b/src/Starward/Services/UrlProtocolService.cs index f90f91154..71ac5ce26 100644 --- a/src/Starward/Services/UrlProtocolService.cs +++ b/src/Starward/Services/UrlProtocolService.cs @@ -2,6 +2,7 @@ using Microsoft.Win32; using Starward.Core; using Starward.Models; +using Starward.Models.GameSetting; using System; using System.IO; using System.Linq; @@ -113,6 +114,48 @@ public static async Task HandleUrlProtocolAsync(string url) } return true; } + if (uri.Host is "gameconfig") + { + if(Enum.TryParse(uri.AbsolutePath.Trim('/'), out GameBiz biz)) + { + var kvs = HttpUtility.ParseQueryString(uri.Query); + string? widthStr = kvs["width"]; + string? heightStr = kvs["height"]; + string? isfullscreenStr = kvs["isfullscreen"]; + var gameSettingService = AppConfig.GetService(); + var gameResourceService = AppConfig.GetService(); + if (!gameResourceService.IsGameExeExists(biz)) + { + log.LogWarning("Game {biz} is not installed.", biz); + return false; + } + else + { + GraphicsSettings_PCResolution_h431323223? graphicsSettings = gameSettingService.GetGameResolutionSetting(biz); + log.LogDebug("{biz} GraphicsSettings: {graphicsSettings}", biz, graphicsSettings); + if (graphicsSettings != null) + { + if (int.TryParse(widthStr, out int width)) + { + graphicsSettings.Width = width; + log.LogInformation("{biz} Width change to {width}.", biz, width); + } + if (int.TryParse(heightStr, out int height)) + { + graphicsSettings.Height = height; + log.LogInformation("{biz} Height change to {height}.", biz, height); + } + if (bool.TryParse(isfullscreenStr, out bool isfullscreen)) + { + graphicsSettings.IsFullScreen = isfullscreen; + log.LogInformation("{biz} isfullscreen change to {isfullscreen}.", biz, isfullscreen); + } + gameSettingService.SetGameResolutionSetting(biz, graphicsSettings); + } + } + return true; + } + } } } catch (Exception ex)