From e492b8ea3bd2e02b178827cb6a937768bc0bc924 Mon Sep 17 00:00:00 2001 From: neru Date: Fri, 20 Mar 2026 20:33:55 -0300 Subject: [PATCH] fix: improve id handling, filter out bloodweb --- src/unlocker/main.cpp | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/unlocker/main.cpp b/src/unlocker/main.cpp index 2924257..936f3fc 100644 --- a/src/unlocker/main.cpp +++ b/src/unlocker/main.cpp @@ -301,45 +301,49 @@ int main() std::lock_guard lock(g_dataMutex); if (!g_allObjectIds.empty()) { - Log::info("Merging catalog items into real inventory response"); + Log::info("Merging catalog and dumped items into real inventory response"); size_t closePos = data.rfind("]}"); if (closePos != std::string::npos) { uint64_t now = time(nullptr); std::string injected; - injected.reserve(g_allObjectIds.size() * 60); + injected.reserve((g_allObjectIds.size() + g_stackableItems.size()) * 80); - std::unordered_set handledIds; - auto injectItem = [&](const std::string& id, int qty) { - if (id.empty()) return; - if (handledIds.count(id)) return; - - std::string searchPat = "\"objectId\":\"" + id + "\""; - if (data.find(searchPat) != std::string::npos) + std::unordered_set seenIds; + size_t pos = 0; + while ((pos = data.find("\"objectId\":\"", pos)) != std::string::npos) + { + pos += 12; + size_t end = data.find("\"", pos); + if (end != std::string::npos) { - handledIds.insert(id); - return; + seenIds.insert(data.substr(pos, end - pos)); + pos = end; } + } - injected += ",{\"lastUpdateAt\":" + std::to_string(now) + - ",\"quantity\":" + std::to_string(qty) + ",\"objectId\":\"" + id + "\"}"; - handledIds.insert(id); + auto injectItem = [&](const std::string& id, int qty) { + if (id.empty() || seenIds.count(id)) return; + injected += std::format(",{{\"lastUpdateAt\":{},\"quantity\":{},\"objectId\":\"{}\"}}", now, qty, id); + seenIds.insert(id); }; - for (const auto& id : g_allObjectIds) - injectItem(id, 1); + for (const auto& id : g_allObjectIds) injectItem(id, 1); + for (const auto& id : g_stackableItems) injectItem(id, 100); + for (const auto& id : g_uniqueItems) injectItem(id, 1); + for (const auto& id : g_perks) injectItem(id, 3); if (!injected.empty()) data.insert(closePos, injected); - Log::info("Injected {} catalog items into global inventory", - injected.empty() ? 0 : std::count(injected.begin(), injected.end(), '{')); + Log::info("Injected {} items into global inventory", + std::count(injected.begin(), injected.end(), '{')); } } else Log::warning("No catalog data available to inject into global inventory yet!"); } - else if (url.find("api/v1/dbd-character-data/get-all") != std::string::npos) + else if (url.find("api/v1/dbd-character-data/") != std::string::npos && url.find("/bloodweb") == std::string::npos) { std::vector localStackable; std::vector localUnique;