Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Hook/Hooks_Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
148 changes: 74 additions & 74 deletions src/Utils/LuaConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ namespace LuaConfig{
static std::vector<AppId_t> g_pendingAdditions;
constexpr uint64_t kDefaultStatSteamId = 76561198028121353ULL;

// Case-insensitive function registry: lowercase name → C function
static std::unordered_map<std::string, lua_CFunction> 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<std::string, lua_CFunction> 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"}
//
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ──────────────────────────
Expand Down Expand Up @@ -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<uint32_t>(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<uint32_t>(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 ───────────────────────────────────────────
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<uint64_t>(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<uint64_t>(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);
Expand Down Expand Up @@ -534,19 +534,19 @@ namespace LuaConfig{
return false;
}

if (lua_isinteger(g_lua_state, -1)) {
*outCode = static_cast<uint64_t>(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<uint64_t>(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);
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/LuaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <vector>

namespace LuaConfig{
bool HasDepot(AppId_t appId);
bool HasDepot(AppId_t appId, bool checkOwned=true);
void MarkOwned(AppId_t appId);
std::vector<AppId_t> GetAllDepotIds();
std::vector<uint8> GetDecryptionKey(AppId_t appId);
Expand Down
Loading