Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add game resolution change in UrlProtocolService.cs #960

Closed
wants to merge 10 commits into from
35 changes: 25 additions & 10 deletions docs/UrlProtocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| ----------------- | ----- | --------------------------------------- |
Expand All @@ -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. |
43 changes: 43 additions & 0 deletions src/Starward/Services/UrlProtocolService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,6 +114,48 @@ public static async Task<bool> 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<GameSettingService>();
var gameResourceService = AppConfig.GetService<GameResourceService>();
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)
Expand Down
Loading