From efca0a2ac81607f29e0dd9711d4d8fb161207696 Mon Sep 17 00:00:00 2001 From: Sean Du Date: Mon, 22 Jun 2026 12:37:04 +0800 Subject: [PATCH] Require api_url before startup Signed-off-by: Sean Du --- README.md | 6 +++--- config.json.example | 2 +- src/config.cpp | 31 ++++++++++++++++++++++++------- src/config.hpp | 2 +- src/proxy.cpp | 6 +++++- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 409cce1..2bec831 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ make ```json { "force_http": true, - "api_url": "apis.game.starlight-stage.jp/", + "api_url": "", "asset_url": "asset-starlight-stage.akamaized.net/", "launch_borderless_helper": true } @@ -51,8 +51,8 @@ make 字段说明: - `force_http`:是否强制将 scheme 改成 `http`。默认 `true` -- `api_url`:API 主机名,按原始字段格式填写,不带 scheme -- `asset_url`:资源主机名,按原始字段格式填写,不带 scheme +- `api_url`:必填。API 主机名,按原始字段格式填写,不带 scheme;留空时程序会弹窗提示 +- `asset_url`:资源主机名,按原始字段格式填写,不带 scheme;留空时回落到 `asset-starlight-stage.akamaized.net/` - `launch_borderless_helper`:是否自动启动 `cgss-borderless-helper.exe`。默认 `true` **使用方法** diff --git a/config.json.example b/config.json.example index 0e05996..c803f9b 100644 --- a/config.json.example +++ b/config.json.example @@ -1,6 +1,6 @@ { "force_http": true, - "api_url": "apis.game.starlight-stage.jp/", + "api_url": "", "asset_url": "asset-starlight-stage.akamaized.net/", "launch_borderless_helper": true } diff --git a/src/config.cpp b/src/config.cpp index 87870a9..67c4775 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -6,6 +6,10 @@ namespace config { namespace { OverrideUrls g_urls; 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() { char path[MAX_PATH] = {}; @@ -58,7 +62,7 @@ namespace config { return "{\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" " \"launch_borderless_helper\": true\r\n" "}\r\n"; @@ -79,16 +83,16 @@ namespace config { } } - void load() { + bool load() { if (g_loaded) { - return; + return !g_urls.api_url.empty(); } g_loaded = true; const auto config_path = get_config_path(); if (config_path.empty()) { hook_log("[cgss-dmm-hook] failed to resolve config.json path"); - return; + return false; } std::ifstream config_stream(config_path); @@ -101,7 +105,7 @@ namespace config { } else { hook_log("[cgss-dmm-hook] config.json not found, failed to generate default config.json"); } - return; + return false; } rapidjson::IStreamWrapper wrapper(config_stream); @@ -109,7 +113,7 @@ namespace config { document.ParseStream(wrapper); if (document.HasParseError() || !document.IsObject()) { hook_log("[cgss-dmm-hook] failed to parse config.json"); - return; + return false; } read_bool(document, "force_http", g_urls.force_http); @@ -125,10 +129,23 @@ namespace config { if (!g_urls.api_url.empty()) { 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()); } + return true; } const OverrideUrls& get() { diff --git a/src/config.hpp b/src/config.hpp index 0b057da..4921435 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -8,6 +8,6 @@ namespace config { bool launch_borderless_helper = true; }; - void load(); + bool load(); const OverrideUrls& get(); } diff --git a/src/proxy.cpp b/src/proxy.cpp index 9db6990..1863d2a 100644 --- a/src/proxy.cpp +++ b/src/proxy.cpp @@ -343,7 +343,11 @@ namespace { hook_log("[cgss-dmm-hook] non-game process detected, skipping hook/helper startup"); 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_hook_thread(); return 0;