From 1fddc2a79565d18f6dba263ec25671d0aed7eb50 Mon Sep 17 00:00:00 2001 From: OpenSteam001 <248184252+OpenSteam001@users.noreply.github.com> Date: Thu, 28 May 2026 18:38:52 +0800 Subject: [PATCH] improve: Add checkOwned parameter to LuaConfig::HasDepot --- src/Hook/Hooks_Misc.cpp | 2 +- src/Utils/LuaConfig.cpp | 148 ++++++++++++++++++++-------------------- src/Utils/LuaConfig.h | 2 +- 3 files changed, 76 insertions(+), 76 deletions(-) diff --git a/src/Hook/Hooks_Misc.cpp b/src/Hook/Hooks_Misc.cpp index 7f5b7e6..b7bb057 100644 --- a/src/Hook/Hooks_Misc.cpp +++ b/src/Hook/Hooks_Misc.cpp @@ -88,7 +88,7 @@ namespace { { CAppData* pData = oGetOrAddAppData(pCache, appId, bCreate); // LOG_MISC_TRACE("GetOrAddAppData: appId={} bCreate={} -> pData={}", appId, bCreate, pData ? pData->DebugString() : "null"); - if (LuaConfig::HasDepot(appId) && pData && !bCreate && pData->IsUnresolvedAppInfo()) { + if (LuaConfig::HasDepot(appId, false) && pData && !bCreate && pData->IsUnresolvedAppInfo()) { LOG_MISC_DEBUG("GetOrAddAppData: Marking appId {} as skip_flag=true to bypass license update blocking", appId); pData->bSkipFlag = true; } diff --git a/src/Utils/LuaConfig.cpp b/src/Utils/LuaConfig.cpp index dc1e26d..3345097 100644 --- a/src/Utils/LuaConfig.cpp +++ b/src/Utils/LuaConfig.cpp @@ -32,24 +32,24 @@ namespace LuaConfig{ static std::vector g_pendingAdditions; constexpr uint64_t kDefaultStatSteamId = 76561198028121353ULL; - // Case-insensitive function registry: lowercase name → C function - static std::unordered_map g_func_registry; - - static bool ParseUInt64Decimal(const char* text, uint64_t* out) { - if (!text || !*text || !out) return false; - if (!std::all_of(text, text + strlen(text), - [](unsigned char c) { return std::isdigit(c) != 0; })) { - return false; - } - try { - *out = std::stoull(text); - return true; - } catch (...) { - return false; - } - } - - // ── Lua HTTP helpers ────────────────────────────────────────── + // Case-insensitive function registry: lowercase name → C function + static std::unordered_map g_func_registry; + + static bool ParseUInt64Decimal(const char* text, uint64_t* out) { + if (!text || !*text || !out) return false; + if (!std::all_of(text, text + strlen(text), + [](unsigned char c) { return std::isdigit(c) != 0; })) { + return false; + } + try { + *out = std::stoull(text); + return true; + } catch (...) { + return false; + } + } + + // ── Lua HTTP helpers ────────────────────────────────────────── // http_get(url [, headers]) → body, status_code // headers: optional table, e.g. {["Accept"]="application/json"} // @@ -198,16 +198,16 @@ namespace LuaConfig{ return luaL_error(L, ""); AppId_t AppId = (uint32_t)value; // Read the second argument as a token. - if (argc > 1) { - if (!lua_isstring(L, 2)) - return luaL_error(L, ""); - const char* token = lua_tostring(L, 2); - uint64_t parsedToken = 0; - if (!ParseUInt64Decimal(token, &parsedToken)) { - return luaL_error(L, ""); - } - AccessTokenSet[AppId] = parsedToken; - } + if (argc > 1) { + if (!lua_isstring(L, 2)) + return luaL_error(L, ""); + const char* token = lua_tostring(L, 2); + uint64_t parsedToken = 0; + if (!ParseUInt64Decimal(token, &parsedToken)) { + return luaL_error(L, ""); + } + AccessTokenSet[AppId] = parsedToken; + } return 0; } @@ -252,15 +252,15 @@ namespace LuaConfig{ if (val < 0 || val > UINT32_MAX) return luaL_error(L, "setManifestid: depotId out of range"); - uint64_t depotId = (uint64_t)(uint32_t)val; - const char* gidStr = lua_tostring(L, 2); - - uint64_t gid = 0; - if (!ParseUInt64Decimal(gidStr, &gid)) - return luaL_error(L, "setManifestid: gid must be all digits"); - - ManifestOverrides[depotId] = { gid, 0 }; - return 0; + uint64_t depotId = (uint64_t)(uint32_t)val; + const char* gidStr = lua_tostring(L, 2); + + uint64_t gid = 0; + if (!ParseUInt64Decimal(gidStr, &gid)) + return luaL_error(L, "setManifestid: gid must be all digits"); + + ManifestOverrides[depotId] = { gid, 0 }; + return 0; } // ── Lua: setAppTicket / setETicket ────────────────────────── @@ -347,15 +347,15 @@ namespace LuaConfig{ lua_Integer val = lua_tointeger(L, 1); if (val < 0 || val > UINT32_MAX) return luaL_error(L, "setStat: appId out of range"); - AppId_t appId = static_cast(val); - - const char* sidStr = lua_tostring(L, 2); - uint64_t steamId = 0; - if (!ParseUInt64Decimal(sidStr, &steamId)) - return luaL_error(L, "setStat: steamId must be all digits"); - - StatSteamIdSet[appId] = steamId; - return 0; + AppId_t appId = static_cast(val); + + const char* sidStr = lua_tostring(L, 2); + uint64_t steamId = 0; + if (!ParseUInt64Decimal(sidStr, &steamId)) + return luaL_error(L, "setStat: steamId must be all digits"); + + StatSteamIdSet[appId] = steamId; + return 0; } // ── init / cleanup ─────────────────────────────────────────── @@ -403,8 +403,8 @@ namespace LuaConfig{ } // ── public query API ───────────────────────────────────────── - bool HasDepot(AppId_t DepotId) { - return DepotKeySet.count(DepotId) && !OwnedAppIdSet.count(DepotId); + bool HasDepot(AppId_t DepotId,bool checkOwned) { + return DepotKeySet.count(DepotId) && (!checkOwned || !OwnedAppIdSet.count(DepotId)); } void MarkOwned(AppId_t AppId) { @@ -484,19 +484,19 @@ namespace LuaConfig{ // The function must return a digit string (uint64 as decimal). // tonumber() loses precision for values > 2^53; string is safe. - if (lua_isinteger(g_lua_state, -1)) { - *outCode = static_cast(lua_tointeger(g_lua_state, -1)); - } else if (lua_isstring(g_lua_state, -1)) { - const char* s = lua_tostring(g_lua_state, -1); - uint64_t parsed = 0; - if (!ParseUInt64Decimal(s, &parsed)) { - LOG_MANIFEST_WARN("fetch_manifest_code({}) returned invalid numeric string '{}'", - gid, s); - lua_pop(g_lua_state, 1); - return false; - } - *outCode = parsed; - } else { + if (lua_isinteger(g_lua_state, -1)) { + *outCode = static_cast(lua_tointeger(g_lua_state, -1)); + } else if (lua_isstring(g_lua_state, -1)) { + const char* s = lua_tostring(g_lua_state, -1); + uint64_t parsed = 0; + if (!ParseUInt64Decimal(s, &parsed)) { + LOG_MANIFEST_WARN("fetch_manifest_code({}) returned invalid numeric string '{}'", + gid, s); + lua_pop(g_lua_state, 1); + return false; + } + *outCode = parsed; + } else { LOG_MANIFEST_WARN("fetch_manifest_code({}) unexpected type (expected digit-string)", gid); lua_pop(g_lua_state, 1); @@ -534,19 +534,19 @@ namespace LuaConfig{ return false; } - if (lua_isinteger(g_lua_state, -1)) { - *outCode = static_cast(lua_tointeger(g_lua_state, -1)); - } else if (lua_isstring(g_lua_state, -1)) { - const char* s = lua_tostring(g_lua_state, -1); - uint64_t parsed = 0; - if (!ParseUInt64Decimal(s, &parsed)) { - LOG_MANIFEST_WARN("fetch_manifest_code_ex({}, {}, {}) returned invalid numeric string '{}'", - app_id, depot_id, gid, s); - lua_pop(g_lua_state, 1); - return false; - } - *outCode = parsed; - } else { + if (lua_isinteger(g_lua_state, -1)) { + *outCode = static_cast(lua_tointeger(g_lua_state, -1)); + } else if (lua_isstring(g_lua_state, -1)) { + const char* s = lua_tostring(g_lua_state, -1); + uint64_t parsed = 0; + if (!ParseUInt64Decimal(s, &parsed)) { + LOG_MANIFEST_WARN("fetch_manifest_code_ex({}, {}, {}) returned invalid numeric string '{}'", + app_id, depot_id, gid, s); + lua_pop(g_lua_state, 1); + return false; + } + *outCode = parsed; + } else { LOG_MANIFEST_WARN("fetch_manifest_code_ex({}, {}, {}) unexpected type (expected digit-string)", app_id, depot_id, gid); lua_pop(g_lua_state, 1); diff --git a/src/Utils/LuaConfig.h b/src/Utils/LuaConfig.h index ee4e5a6..ae00478 100644 --- a/src/Utils/LuaConfig.h +++ b/src/Utils/LuaConfig.h @@ -7,7 +7,7 @@ #include namespace LuaConfig{ - bool HasDepot(AppId_t appId); + bool HasDepot(AppId_t appId, bool checkOwned=true); void MarkOwned(AppId_t appId); std::vector GetAllDepotIds(); std::vector GetDecryptionKey(AppId_t appId);