Skip to content

Commit ef381b6

Browse files
committed
fix: [lua] paths 改为排他生效,默认目录仅兜底
原来 MergeWatchDirs 无条件把 config/lua 追加到用户配置的目录之后, 用户换目录后内核仍会同时扫描两处,同一批 lua 可能被加载两次、定义互相覆盖。 现在 configured 非空即只扫它,空才回落 default。 - LuaConfig::MergeWatchDirs -> ResolveWatchDirs(旧名描述的正是被否掉的合并语义) - 两个调用点 + 注释口径 + example toml / README / UPSTREAM-SYNC 同步
1 parent 1cf7168 commit ef381b6

8 files changed

Lines changed: 32 additions & 27 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ZSteamTool 是一个注入 Steam 客户端的内核(三个 DLL),用来解
5858
1. 备份 Steam 根目录下现有的 `OpenSteamTool.dll`、`dwmapi.dll`、`xinput1_4.dll`;
5959
2. 从发布包的 `Release\`(日常)或 `Debug\`(排障,日志更全)取三个 DLL,复制到 Steam 根目录覆盖;
6060
3. 配置模板 `opensteamtool.toml` 放到 Steam 根目录(**升级用户不必替换**:缺少 `[denuvo]` 段时默认即 `normal`,覆盖反而会丢掉你已改过的配置);
61-
4. Lua 配置放到 `<Steam>\config\lua\`(内核**只**扫描这一个默认目录;`config\stplug-in` 不再读取,避免两个目录的 lua 定义冲突);
61+
4. Lua 配置放到 `<Steam>\config\lua\`;要换目录就在 OSTGUI 的「Lua 路径」里改,或直接写 `opensteamtool.toml` 的 `[lua] paths`(**内核只扫描一处**,`config\stplug-in` 永不读取);
6262
5. 重启 Steam。
6363

6464
## 配置
@@ -70,7 +70,7 @@ ZSteamTool 是一个注入 Steam 客户端的内核(三个 DLL),用来解
7070
| `[denuvo] mode` | `normal`(默认)= 仅 D 加密授权握手期间使用票据身份,其余时间按**你当前登录的账号**运行 → 游戏存档 / 云存档绑定你自己的账号;`compat` = 整场使用票据账号(严格标题用,**代价是该游戏用户数据绑定出票账号**) |
7171
| `[manifest]` | 请求码源与超时;若 `config/lua/manifest.lua` 定义了 `fetch_manifest_code(_ex)`,Lua 优先 |
7272
| `[log] level` | 日志级别(Debug 版写 `<Steam>\opensteamtool\*.log`) |
73-
| `[lua] paths` | 附加 Lua 配置目录(默认 `<Steam>\config\lua` 最后加载,用户配置优先) |
73+
| `[lua] paths` | Lua 配置目录;**非空时只扫描这里**(GUI 改「Lua 路径」会自动写入本行并热重载),留空则用默认 `<Steam>\config\lua` |
7474
| `[inject]` | 可选的游戏进程注入(默认关) |
7575
| `[cloud]` | 可选云存档重定向(需自备 `cloud_redirect.dll`,默认关) |
7676
| `[remote]` | 自定义元数据镜像(默认走 GitHub + jsDelivr 回退) |

‎docs/dev/UPSTREAM-SYNC.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
## 4. 明确不采用
4141

4242
- **`bst://` 兑换码桥 / 自更新**:依赖外部服务与自动下载,本发行版为手动部署模式;
43-
- **目录迁移 `config\lua` → `config\stplug-in`**:本项目**只读** `config\lua`(即 GUI 写入的位置);`config\stplug-in` 明确不扫描,避免同一批 lua 从两个目录被加载两次而互相冲突;
43+
- **目录迁移 `config\lua` → `config\stplug-in`**:Lua 目录**只有一处生效** —— `[lua] paths` 非空时就是它(GUI 的「Lua 路径」会写这一行),为空时才是 `config\lua`;`config\stplug-in` 明确不扫描,避免同一批 lua 从两个目录被加载两次而互相冲突;
4444
- **`eticket` 在线铸造**:需要后端,默认关闭(编译期 `OST_ETICKET_URL` 为空即禁用)。
4545

4646
## 5. 以后怎么跟上上游

‎opensteamtool.example.toml‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ timeout_recv_ms = 10000
6262
# Priority: setStat > stats API when enabled and valid > hardcoded preset SteamID.
6363
enable_api = true
6464

65-
# Additional Lua config directories (optional).
66-
# The kernel watches exactly ONE default directory: <Steam>/config/lua (where the
67-
# GUI writes its configs). The legacy BST-era config/stplug-in is deliberately NOT
68-
# scanned — loading lua from two directories could apply conflicting definitions.
69-
# Extra directories listed here are loaded first, the default last.
70-
# Example — load a custom directory on another drive:
65+
# Lua config directory. When this list is non-empty the kernel scans EXACTLY these
66+
# directories and nothing else — that is how OSTGUI points the kernel at whatever
67+
# directory you picked in 设置 → 基本设置 → Lua 路径 (the GUI writes this line for you,
68+
# and the kernel hot-reloads it, no Steam restart needed).
69+
# Leave the list empty to use the built-in default <Steam>/config/lua.
70+
# The legacy BST-era config/stplug-in is never scanned.
71+
# Example — keep lua on another drive:
7172
# [lua]
7273
# paths = ["D:/my-steam-config/lua"]
7374
[lua]

‎src/Utils/Config/ConfigFileWatcher.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ bool ContainsConfigChange(
4646
}
4747

4848
std::vector<std::string> BuildLuaWatchDirs() {
49-
// Single fixed default directory (config\lua) plus the user's [lua] paths.
50-
// The legacy BST-era config\stplug-in is intentionally NOT scanned: loading
51-
// lua from two directories could apply conflicting definitions.
52-
return LuaConfig::MergeWatchDirs(Config::GetLuaPaths(), g_defaultLuaDir);
49+
// The user's [lua] paths win outright; config\lua is only the fallback when the
50+
// list is empty. Exactly one source of lua — the GUI keeps that entry pointed at
51+
// the directory it writes, so two directories never contribute conflicting
52+
// definitions (the legacy BST-era config\stplug-in is not scanned at all).
53+
return LuaConfig::ResolveWatchDirs(Config::GetLuaPaths(), g_defaultLuaDir);
5354
}
5455

5556
void RestartLuaWatcher() {

‎src/Utils/Config/LuaConfig.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,8 @@ namespace LuaConfig{
876876
}
877877

878878
// ── directory scanner ────────────────────────────────────────
879-
std::vector<std::string> MergeWatchDirs(const std::vector<std::string>& configured,
880-
const std::string& defaultDir) {
879+
std::vector<std::string> ResolveWatchDirs(const std::vector<std::string>& configured,
880+
const std::string& defaultDir) {
881881
namespace fs = std::filesystem;
882882

883883
// Canonical, case-folded key for a directory so relative and absolute spellings
@@ -906,7 +906,7 @@ namespace LuaConfig{
906906
};
907907

908908
for (const auto& d : configured) add(d);
909-
add(defaultDir); // appended only if it isn't already covered above
909+
if (out.empty()) add(defaultDir); // configured paths win; default only as fallback
910910
return out;
911911
}
912912

‎src/Utils/Config/LuaConfig.h‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ namespace LuaConfig{
3737
void ParseDirectory(const std::string& directory);
3838
void ReloadDirectories(const std::vector<std::string>& directories, bool clearPendingAdditions = false);
3939

40-
// Merge the user-configured Lua directories with the built-in default, dropping any
41-
// entry that resolves to the same filesystem location (so a relative config entry
42-
// like "config/stplug-in" that equals the absolute default folder is not loaded
43-
// twice). Configured paths keep their order; the default is appended only if new.
44-
std::vector<std::string> MergeWatchDirs(const std::vector<std::string>& configured,
45-
const std::string& defaultDir);
40+
// Resolve the Lua directories to watch. When the user configured any [lua] paths
41+
// they are authoritative (the GUI points the kernel at the directory it writes to)
42+
// and the built-in default is NOT added on top — only one source of lua, so two
43+
// directories can never contribute conflicting definitions. The default is the
44+
// fallback for an empty list. Duplicates by resolved location are dropped, keeping
45+
// the order of `configured`.
46+
std::vector<std::string> ResolveWatchDirs(const std::vector<std::string>& configured,
47+
const std::string& defaultDir);
4648

4749
bool HasManifestCodeFunc();
4850
bool CallManifestFetchCode(uint64_t gid, uint64_t* outCode);

‎src/dllmain.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ bool InitializeSteamComponents()
2626
sprintf_s(SteamclientPath, kRuntimePathCapacity, "%s\\steamclient64.dll", SteamInstallPath);
2727
sprintf_s(SteamUIPath, kRuntimePathCapacity, "%s\\steamui.dll", SteamInstallPath);
2828
sprintf_s(DiversionPath, kRuntimePathCapacity, "%s\\bin\\diversion.dll", SteamInstallPath);
29-
// Fixed default Lua directory: <Steam>\config\lua (what the GUI writes to).
30-
// Deliberately the ONLY default — the old BST-era config\stplug-in directory
31-
// is NOT scanned, so lua files can never be loaded twice from two locations.
29+
// Fallback Lua directory: <Steam>\config\lua (what the GUI writes to). Used only
30+
// while [lua] paths in opensteamtool.toml is empty — the GUI writes that entry
31+
// whenever the user picks a different directory, so exactly one directory is
32+
// scanned and lua files can never be loaded twice from two locations.
3233
sprintf_s(LuaDir, kRuntimePathCapacity, "%s\\config\\lua", SteamInstallPath);
3334
sprintf_s(ConfigPath, kRuntimePathCapacity, "%s\\opensteamtool.toml", SteamInstallPath);
3435

@@ -76,7 +77,7 @@ static uint32_t InitThread(OSTPlatform::DynamicLibrary::ModuleHandle selfModule)
7677
IPCLoader::Load(SteamclientPath);
7778

7879
std::vector<std::string> watchDirs =
79-
LuaConfig::MergeWatchDirs(Config::GetLuaPaths(), std::string(LuaDir));
80+
LuaConfig::ResolveWatchDirs(Config::GetLuaPaths(), std::string(LuaDir));
8081
for (const auto& dir : watchDirs)
8182
LuaConfig::ParseDirectory(dir);
8283

‎src/dllmain.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ inline char SteamInstallPath[kRuntimePathCapacity] = {};
3333
inline char SteamclientPath[kRuntimePathCapacity] = {};
3434
inline char SteamUIPath[kRuntimePathCapacity] = {};
3535
inline char DiversionPath[kRuntimePathCapacity] = {};
36-
inline char LuaDir[kRuntimePathCapacity] = {}; // fixed default: <Steam>\config\lua
36+
inline char LuaDir[kRuntimePathCapacity] = {}; // fallback lua dir: <Steam>\config\lua
3737
inline char ConfigPath[kRuntimePathCapacity] = {};
3838

3939
// The default session AppId used by -onlinefix (SpaceWar). Overridable per

0 commit comments

Comments
 (0)