Skip to content

Validate tool target compatibility#14

Merged
GT-610 merged 2 commits into
mainfrom
tool-target-validation
Jul 7, 2026
Merged

Validate tool target compatibility#14
GT-610 merged 2 commits into
mainfrom
tool-target-validation

Conversation

@GT-610

@GT-610 GT-610 commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Preserve schema metadata for tool restrictions and target capabilities.
  • Validate key/crate restriction compatibility before opening crates.
  • Validate sticker, patch, and name tag target capabilities before mutating inventory.

Validation

  • Ran git diff --check.
  • Built csgo_gc successfully with cmake --build build --config Release --target csgo_gc.

Manual test notes

  • Correct keys should still open matching crates, while mismatched keys should fail without inventory changes.
  • keyId == 0 container flows should remain compatible.
  • Stickers should apply to sticker-capable weapons, patches to patch-capable agents, and invalid targets should fail.
  • Name tags should apply only to nameable item definitions.

Summary by CodeRabbit

  • Bug Fixes

    • Added stricter validation for opening crates, applying stickers/patches, and naming items so only compatible items can be modified.
    • Improved error reporting when an item action is not allowed, making failures clearer to end-users.
  • New Features

    • Added support for item capability checks, including whether an item can accept stickers, patches, or custom names.
    • Added compatibility checks between keys and crates to prevent invalid use.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@GT-610, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c0cd7365-af86-4aaa-b24b-aa9d7636ba5c

📥 Commits

Reviewing files that changed from the base of the PR and between 96e9463 and 9fc15d6.

📒 Files selected for processing (1)
  • csgo_gc/inventory.cpp
📝 Walkthrough

Walkthrough

Adds capability metadata (m_toolRestriction, m_canSticker, m_canPatch, m_nameable) to ItemInfo, populated during item schema parsing, plus new ItemSchema query methods for key-crate compatibility, sticker/patch application, and naming eligibility. Inventory operations for unlocking crates, applying stickers, and naming items now call these methods and reject incompatible actions with logged messages.

Changes

Item Schema Capability Validation

Layer / File(s) Summary
ItemInfo fields and ItemSchema query methods
csgo_gc/item_schema.h, csgo_gc/item_schema.cpp
ItemInfo gains m_toolRestriction, m_canSticker, m_canPatch, m_nameable fields, populated during ParseItemRecursive from capabilities and tool/restriction subkeys; ItemSchema adds IsKeyCompatibleWithCrate, CanApplyStickerToDefIndex, CanApplyPatchToDefIndex, and CanNameDefIndex methods.
Inventory validation gates using schema methods
csgo_gc/inventory.cpp
UnlockCrate, ApplySticker, NameItem, and NameBaseItem call the new schema methods to check compatibility/eligibility before mutating items, printing a message and returning false on failure.

Sequence Diagram(s)

sequenceDiagram
  participant Inventory
  participant ItemSchema
  Inventory->>ItemSchema: IsKeyCompatibleWithCrate(keyDefIndex, crateDefIndex)
  ItemSchema-->>Inventory: compatibility result
  Inventory->>ItemSchema: CanApplyStickerToDefIndex / CanApplyPatchToDefIndex(targetDefIndex)
  ItemSchema-->>Inventory: eligibility result
  Inventory->>ItemSchema: CanNameDefIndex(defIndex)
  ItemSchema-->>Inventory: nameable result
  Inventory->>Inventory: proceed or reject with logged message
Loading

Estimated code review effort: 🔵🔵🔵⚪⚪ (Medium-High, involves new schema validation logic touching multiple inventory operations)

Related issues: None referenced in the provided summary.

Related PRs: None referenced in the provided summary.

Suggested labels: enhancement, item-schema, inventory

Suggested reviewers: GT-610

🌸 A crate that once popped without a care,
Now checks its key's tool tag first, beware,
Stickers ask "may I?" before they stick,
Names must earn the right, no free-for-all trick,
The schema grew wiser, gatekeeping with flair. 🔑

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding compatibility validation for tool targets and target capabilities.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@GT-610

GT-610 commented Jul 7, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
csgo_gc/inventory.cpp (1)

863-911: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consolidate the duplicate item_item_id lookup.

m_items.find(message.item_item_id()) is performed twice — once to compute targetDefIndex (lines 870-878) and again to resolve item (lines 903-911). Both rely on the same message.baseitem_defidx() condition to stay consistent; merging them removes the redundant lookup and the risk of the eligibility-check target and the mutated item diverging if either branch is edited independently in the future.

♻️ Proposed consolidation
-    uint32_t targetDefIndex = 0;
-    if (message.baseitem_defidx())
-    {
-        targetDefIndex = message.baseitem_defidx();
-    }
-    else
-    {
-        auto it = m_items.find(message.item_item_id());
-        if (it == m_items.end())
-        {
-            assert(false);
-            return false;
-        }
-
-        targetDefIndex = it->second.def_index();
-    }
+    CSOEconItem *targetItem = nullptr;
+    uint32_t targetDefIndex = 0;
+    if (message.baseitem_defidx())
+    {
+        targetDefIndex = message.baseitem_defidx();
+    }
+    else
+    {
+        auto it = m_items.find(message.item_item_id());
+        if (it == m_items.end())
+        {
+            assert(false);
+            return false;
+        }
+
+        targetItem = &it->second;
+        targetDefIndex = targetItem->def_index();
+    }

     if (sticker->second.def_index() == ItemSchema::ItemPatch)
     {
         if (!m_itemSchema.CanApplyPatchToDefIndex(targetDefIndex))
         {
             Platform::Print("ApplySticker: patch item %llu cannot be applied to target def %u (target item %llu)\n",
                 message.sticker_item_id(), targetDefIndex, message.item_item_id());
             return false;
         }
     }
     else if (!m_itemSchema.CanApplyStickerToDefIndex(targetDefIndex))
     {
         Platform::Print("ApplySticker: sticker item %llu cannot be applied to target def %u (target item %llu)\n",
             message.sticker_item_id(), targetDefIndex, message.item_item_id());
         return false;
     }

-    CSOEconItem *item = nullptr;
-    if (message.baseitem_defidx())
-    {
-        item = &CreateItem(message.baseitem_defidx(), ItemOriginBaseItem, UnacknowledgedInvalid);
-    }
-    else
-    {
-        auto it = m_items.find(message.item_item_id());
-        if (it == m_items.end())
-        {
-            assert(false);
-            return false;
-        }
-
-        item = &it->second;
-    }
-
-    assert(item);
+    CSOEconItem *item = message.baseitem_defidx()
+        ? &CreateItem(message.baseitem_defidx(), ItemOriginBaseItem, UnacknowledgedInvalid)
+        : targetItem;
+
+    assert(item);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@csgo_gc/inventory.cpp` around lines 863 - 911, The ApplySticker flow in
inventory.cpp repeats the same message.item_item_id() lookup in two branches,
once to derive targetDefIndex and again to resolve item, which can drift if
edited separately. Refactor the logic around the ApplySticker handling so the
baseitem_defidx() / m_items.find(message.item_item_id()) decision is made once
and the resulting item or target data is reused for both the eligibility check
and the item mutation, keeping the target-def validation and resolved item
consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@csgo_gc/inventory.cpp`:
- Around line 863-911: The ApplySticker flow in inventory.cpp repeats the same
message.item_item_id() lookup in two branches, once to derive targetDefIndex and
again to resolve item, which can drift if edited separately. Refactor the logic
around the ApplySticker handling so the baseitem_defidx() /
m_items.find(message.item_item_id()) decision is made once and the resulting
item or target data is reused for both the eligibility check and the item
mutation, keeping the target-def validation and resolved item consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: caa8fc3e-aa47-4d62-9ec3-bbcd03f08682

📥 Commits

Reviewing files that changed from the base of the PR and between d0345aa and 96e9463.

📒 Files selected for processing (3)
  • csgo_gc/inventory.cpp
  • csgo_gc/item_schema.cpp
  • csgo_gc/item_schema.h

@GT-610
GT-610 merged commit a19c463 into main Jul 7, 2026
4 checks passed
@GT-610
GT-610 deleted the tool-target-validation branch July 7, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant