Require api_url before startup
Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
@@ -43,7 +43,7 @@ make
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"force_http": true,
|
"force_http": true,
|
||||||
"api_url": "apis.game.starlight-stage.jp/",
|
"api_url": "",
|
||||||
"asset_url": "asset-starlight-stage.akamaized.net/",
|
"asset_url": "asset-starlight-stage.akamaized.net/",
|
||||||
"launch_borderless_helper": true
|
"launch_borderless_helper": true
|
||||||
}
|
}
|
||||||
@@ -51,8 +51,8 @@ make
|
|||||||
|
|
||||||
字段说明:
|
字段说明:
|
||||||
- `force_http`:是否强制将 scheme 改成 `http`。默认 `true`
|
- `force_http`:是否强制将 scheme 改成 `http`。默认 `true`
|
||||||
- `api_url`:API 主机名,按原始字段格式填写,不带 scheme
|
- `api_url`:必填。API 主机名,按原始字段格式填写,不带 scheme;留空时程序会弹窗提示
|
||||||
- `asset_url`:资源主机名,按原始字段格式填写,不带 scheme
|
- `asset_url`:资源主机名,按原始字段格式填写,不带 scheme;留空时回落到 `asset-starlight-stage.akamaized.net/`
|
||||||
- `launch_borderless_helper`:是否自动启动 `cgss-borderless-helper.exe`。默认 `true`
|
- `launch_borderless_helper`:是否自动启动 `cgss-borderless-helper.exe`。默认 `true`
|
||||||
|
|
||||||
**使用方法**
|
**使用方法**
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"force_http": true,
|
"force_http": true,
|
||||||
"api_url": "apis.game.starlight-stage.jp/",
|
"api_url": "",
|
||||||
"asset_url": "asset-starlight-stage.akamaized.net/",
|
"asset_url": "asset-starlight-stage.akamaized.net/",
|
||||||
"launch_borderless_helper": true
|
"launch_borderless_helper": true
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-7
@@ -6,6 +6,10 @@ namespace config {
|
|||||||
namespace {
|
namespace {
|
||||||
OverrideUrls g_urls;
|
OverrideUrls g_urls;
|
||||||
bool g_loaded = false;
|
bool g_loaded = false;
|
||||||
|
constexpr const wchar_t* kConfigErrorTitleW = L"cgss-dmm-hook";
|
||||||
|
constexpr const wchar_t* kApiUrlRequiredMessageW =
|
||||||
|
L"config.json \u4E2D\u5FC5\u987B\u8BBE\u7F6E\u975E\u7A7A api_url\u3002";
|
||||||
|
constexpr const char* kDefaultAssetUrl = "asset-starlight-stage.akamaized.net/";
|
||||||
|
|
||||||
std::string get_config_path() {
|
std::string get_config_path() {
|
||||||
char path[MAX_PATH] = {};
|
char path[MAX_PATH] = {};
|
||||||
@@ -58,7 +62,7 @@ namespace config {
|
|||||||
return
|
return
|
||||||
"{\r\n"
|
"{\r\n"
|
||||||
" \"force_http\": true,\r\n"
|
" \"force_http\": true,\r\n"
|
||||||
" \"api_url\": \"apis.game.starlight-stage.jp/\",\r\n"
|
" \"api_url\": \"\",\r\n"
|
||||||
" \"asset_url\": \"asset-starlight-stage.akamaized.net/\",\r\n"
|
" \"asset_url\": \"asset-starlight-stage.akamaized.net/\",\r\n"
|
||||||
" \"launch_borderless_helper\": true\r\n"
|
" \"launch_borderless_helper\": true\r\n"
|
||||||
"}\r\n";
|
"}\r\n";
|
||||||
@@ -79,16 +83,16 @@ namespace config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void load() {
|
bool load() {
|
||||||
if (g_loaded) {
|
if (g_loaded) {
|
||||||
return;
|
return !g_urls.api_url.empty();
|
||||||
}
|
}
|
||||||
g_loaded = true;
|
g_loaded = true;
|
||||||
|
|
||||||
const auto config_path = get_config_path();
|
const auto config_path = get_config_path();
|
||||||
if (config_path.empty()) {
|
if (config_path.empty()) {
|
||||||
hook_log("[cgss-dmm-hook] failed to resolve config.json path");
|
hook_log("[cgss-dmm-hook] failed to resolve config.json path");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ifstream config_stream(config_path);
|
std::ifstream config_stream(config_path);
|
||||||
@@ -101,7 +105,7 @@ namespace config {
|
|||||||
} else {
|
} else {
|
||||||
hook_log("[cgss-dmm-hook] config.json not found, failed to generate default config.json");
|
hook_log("[cgss-dmm-hook] config.json not found, failed to generate default config.json");
|
||||||
}
|
}
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rapidjson::IStreamWrapper wrapper(config_stream);
|
rapidjson::IStreamWrapper wrapper(config_stream);
|
||||||
@@ -109,7 +113,7 @@ namespace config {
|
|||||||
document.ParseStream(wrapper);
|
document.ParseStream(wrapper);
|
||||||
if (document.HasParseError() || !document.IsObject()) {
|
if (document.HasParseError() || !document.IsObject()) {
|
||||||
hook_log("[cgss-dmm-hook] failed to parse config.json");
|
hook_log("[cgss-dmm-hook] failed to parse config.json");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_bool(document, "force_http", g_urls.force_http);
|
read_bool(document, "force_http", g_urls.force_http);
|
||||||
@@ -125,10 +129,23 @@ namespace config {
|
|||||||
|
|
||||||
if (!g_urls.api_url.empty()) {
|
if (!g_urls.api_url.empty()) {
|
||||||
hook_logf("[cgss-dmm-hook] normalized api_url=%s", g_urls.api_url.c_str());
|
hook_logf("[cgss-dmm-hook] normalized api_url=%s", g_urls.api_url.c_str());
|
||||||
|
} else {
|
||||||
|
hook_log("[cgss-dmm-hook] api_url is empty");
|
||||||
|
MessageBoxW(
|
||||||
|
nullptr,
|
||||||
|
kApiUrlRequiredMessageW,
|
||||||
|
kConfigErrorTitleW,
|
||||||
|
MB_OK | MB_ICONERROR | MB_TOPMOST
|
||||||
|
);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (!g_urls.asset_url.empty()) {
|
if (g_urls.asset_url.empty()) {
|
||||||
|
g_urls.asset_url = kDefaultAssetUrl;
|
||||||
|
hook_logf("[cgss-dmm-hook] asset_url is empty, fallback to %s", g_urls.asset_url.c_str());
|
||||||
|
} else {
|
||||||
hook_logf("[cgss-dmm-hook] normalized asset_url=%s", g_urls.asset_url.c_str());
|
hook_logf("[cgss-dmm-hook] normalized asset_url=%s", g_urls.asset_url.c_str());
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const OverrideUrls& get() {
|
const OverrideUrls& get() {
|
||||||
|
|||||||
+1
-1
@@ -8,6 +8,6 @@ namespace config {
|
|||||||
bool launch_borderless_helper = true;
|
bool launch_borderless_helper = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
void load();
|
bool load();
|
||||||
const OverrideUrls& get();
|
const OverrideUrls& get();
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -343,7 +343,11 @@ namespace {
|
|||||||
hook_log("[cgss-dmm-hook] non-game process detected, skipping hook/helper startup");
|
hook_log("[cgss-dmm-hook] non-game process detected, skipping hook/helper startup");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
config::load();
|
if (!config::load()) {
|
||||||
|
hook_log("[cgss-dmm-hook] config validation failed, terminating process");
|
||||||
|
TerminateProcess(GetCurrentProcess(), 1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
start_borderless_helper();
|
start_borderless_helper();
|
||||||
start_hook_thread();
|
start_hook_thread();
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user