From 3231638ce71113f9fe2089f79bfb8b391ab14cc0 Mon Sep 17 00:00:00 2001 From: neru Date: Fri, 20 Mar 2026 18:46:53 -0300 Subject: [PATCH] fix: wrong checks and wrong quantities --- src/unlocker/main.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/unlocker/main.cpp b/src/unlocker/main.cpp index b4aab04..3a1f60b 100644 --- a/src/unlocker/main.cpp +++ b/src/unlocker/main.cpp @@ -371,6 +371,7 @@ int main() std::string currentItems = data.substr(pos, endPos - pos); std::unordered_set seenIds; + std::unordered_set stackableSet(localStackable.begin(), localStackable.end()); size_t itemPos = 0; while ((itemPos = currentItems.find("\"itemId\":\"", itemPos)) != std::string::npos) @@ -382,25 +383,31 @@ int main() std::string id = currentItems.substr(idStart, idEnd - idStart); seenIds.insert(id); - int qty = 100; + int qty = -1; if (perkSet.count(id)) qty = 3; else if (uniqueSet.count(id)) qty = 1; + else if (stackableSet.count(id)) + qty = 100; - size_t objStart = currentItems.rfind("{", itemPos); - size_t objEnd = currentItems.find("}", itemPos); - if (objStart != std::string::npos && objEnd != std::string::npos && objStart < objEnd) + if (qty != -1) { - std::string objStr = currentItems.substr(objStart, objEnd - objStart + 1); - if (std::regex_search(objStr, qtyRegex)) - objStr = - std::regex_replace(objStr, qtyRegex, "\"quantity\":" + std::to_string(qty)); - else - objStr.insert(objStr.length() - 1, ",\"quantity\":" + std::to_string(qty)); + size_t objStart = currentItems.rfind("{", itemPos); + size_t objEnd = currentItems.find("}", itemPos); + if (objStart != std::string::npos && objEnd != std::string::npos && objStart < objEnd) + { + std::string objStr = currentItems.substr(objStart, objEnd - objStart + 1); + if (std::regex_search(objStr, qtyRegex)) + objStr = std::regex_replace(objStr, qtyRegex, "\"quantity\":" + std::to_string(qty)); + else + objStr.insert(objStr.length() - 1, ",\"quantity\":" + std::to_string(qty)); - currentItems.replace(objStart, objEnd - objStart + 1, objStr); - itemPos = objStart + objStr.length(); + currentItems.replace(objStart, objEnd - objStart + 1, objStr); + itemPos = objStart + objStr.length(); + } + else + itemPos = idEnd; } else itemPos = idEnd; @@ -412,8 +419,7 @@ int main() if (seenIds.find(id) == seenIds.end()) { if (!currentItems.empty() && currentItems.back() != ',') currentItems += ","; - currentItems += - "{\"itemId\":\"" + id + "\",\"quantity\":" + std::to_string(qty) + "}"; + currentItems += "{\"itemId\":\"" + id + "\",\"quantity\":" + std::to_string(qty) + "}"; seenIds.insert(id); } }