Skip to content

Validate consumed tool item types#13

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

Validate consumed tool item types#13
GT-610 merged 2 commits into
mainfrom
tool-consumption-validation

Conversation

@GT-610

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

Copy link
Copy Markdown
Owner

Summary

  • Preserve runtime item schema metadata needed to identify consumed tool items.
  • Validate keys, name tags, stickers/patches, and StatTrak Swap Tools before consuming them.
  • Reject invalid tool usage with diagnostic logs instead of sending uncertain UI error responses.

Validation

  • Built csgo_gc successfully with CMake Release target.
  • Manually tested normal tool flows in game.
  • Manually tested invalid ordinary-item tool IDs and confirmed the operations fail without changing inventory.

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation for crate openings, sticker application, renaming items, and StatTrak counter swaps.
    • Added clearer failure messages when required items are missing or invalid.
    • Prevented invalid sticker slots, unsupported item types, and inconsistent weapon states from being processed.
    • Tightened key and name tag handling so items are only consumed when they are valid and present.

@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: 46 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: dff77195-b269-4eb7-976f-a8a79aaedf1a

📥 Commits

Reviewing files that changed from the base of the PR and between 1a1914c and 1aece15.

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

Walkthrough

Item schema gains item type and prefab metadata plus three def_index classification helpers (key, name tag, StatTrak swap tools). Inventory operations (UnlockCrate, ApplySticker, NameItem, NameBaseItem, PerformCounterSwap) use these helpers to replace assertion-based failures with logged validation, and CounterSwapStatus gains new failure enum values.

Changes

Schema-backed inventory validation

Layer / File(s) Summary
Item schema metadata and classification helpers
csgo_gc/item_schema.h, csgo_gc/item_schema.cpp
ItemInfo gains m_itemType and m_prefabs, populated during parsing; adds IsKeyToolDefIndex, IsNameTagToolDefIndex, IsStatTrakSwapToolDefIndex using case-insensitive keyword matching helpers.
Crate unlock key validation
csgo_gc/inventory.cpp
UnlockCrate validates the key item exists and matches IsKeyToolDefIndex before proceeding, and only destroys the key when the lookup succeeds.
Sticker/patch application validation
csgo_gc/inventory.cpp
ApplySticker rejects invalid sticker slots and non-sticker/patch tools, and logs a message before failing when the sticker kit attribute is missing.
Name tag validation for NameItem/NameBaseItem
csgo_gc/inventory.cpp
NameItem and NameBaseItem replace assertion-based failures with Platform::Print logging and IsNameTagToolDefIndex checks, reusing the validated tag during destruction.
StatTrak counter swap tool and state validation
csgo_gc/inventory.h, csgo_gc/inventory.cpp
CounterSwapStatus adds ToolMissing, InvalidTool, InvalidWeaponState; PerformCounterSwap validates the tool via IsStatTrakSwapToolDefIndex, requires QualityStrange weapons, and detects counters via AttributeKillEaterScoreType.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Inventory
  participant ItemSchema

  Client->>Inventory: PerformCounterSwap(toolId, weaponA, weaponB)
  Inventory->>Inventory: Look up tool item
  alt tool missing
    Inventory-->>Client: ToolMissing
  else tool found
    Inventory->>ItemSchema: IsStatTrakSwapToolDefIndex(defIndex)
    alt invalid tool
      Inventory-->>Client: InvalidTool
    else valid tool
      Inventory->>Inventory: Check both weapons QualityStrange
      alt not Strange
        Inventory-->>Client: InvalidWeaponState
      else Strange
        Inventory->>Inventory: Check AttributeKillEaterScoreType == 0 for both weapons
        alt missing counters
          Inventory-->>Client: CounterAttributeAbsent
        else score type mismatch
          Inventory-->>Client: InvalidWeaponState
        else valid
          Inventory->>Inventory: Swap KillEater attribute values
          Inventory-->>Client: Completed
        end
      end
    end
  end
Loading

Compact metadata: 4 files changed (+225/-17 lines), no public API removals; Inventory::CounterSwapStatus enum extended with new values.

Related issues: None referenced in provided summaries.

Related PRs: None referenced in provided summaries.

Suggested labels: enhancement, validation, inventory

Suggested reviewers: Maintainers familiar with csgo_gc/inventory.cpp and csgo_gc/item_schema.cpp

Poem

A key, a tag, a sticker slot,
Now schema-checked before the shot.
No more asserts to crash the game,
Just logged returns and status name.
StatTrak counters swap with care—
A rabbit's code review, laid bare. 🐇

🚥 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 matches the main change: stricter validation of consumed tool item types before inventory actions proceed.
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.

@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.

Actionable comments posted: 1

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

1761-1797: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate counter-detection logic for weaponA/weaponB.

The AttributeKillEater lookup and the AttributeKillEaterScoreType == 0 lookup are each written twice (once per weapon), as two separate loops over the same attribute list. Consider extracting a helper, e.g. FindKillEaterAttribute(CSOEconItem &weapon, CSOEconItemAttribute *&attr, bool &hasScoreTypeZero), called once per weapon to combine both scans into a single pass and remove the duplication.

♻️ Sketch of consolidated helper
+static bool FindKillEaterCounter(const CSOEconItem &weapon, const ItemSchema &schema,
+    CSOEconItemAttribute **outAttr)
+{
+    bool scoreTypeOk = false;
+    *outAttr = nullptr;
+    for (int i = 0; i < weapon.attribute_size(); ++i)
+    {
+        const auto &attr = weapon.attribute(i);
+        if (attr.def_index() == ItemSchema::AttributeKillEater)
+            *outAttr = const_cast<CSOEconItemAttribute *>(&attr);
+        else if (attr.def_index() == ItemSchema::AttributeKillEaterScoreType
+            && schema.AttributeUint32(&attr) == 0)
+            scoreTypeOk = true;
+    }
+    return scoreTypeOk;
+}
🤖 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 1761 - 1797, The KillEater attribute
lookup logic is duplicated for weaponA and weaponB, with separate passes over
each weapon’s attributes for `AttributeKillEater` and
`AttributeKillEaterScoreType == 0`. Refactor the repeated scanning in
`inventory.cpp` into a shared helper around the existing `weaponA`, `weaponB`,
`attrA`, `attrB`, `weaponAScoreType`, and `weaponBScoreType` logic so each
weapon is processed once and both checks happen in a single loop. Call that
helper for each weapon instead of keeping two near-identical blocks.
🤖 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.

Inline comments:
In `@csgo_gc/item_schema.cpp`:
- Around line 1341-1393: The key-tool check in ItemSchema::IsKeyToolDefIndex is
too broad because ItemInfoContains matches any substring containing “key”,
including unrelated prefabs like keychains. Update ItemInfoContains or
IsKeyToolDefIndex to use an exact match against the key tool’s prefab/type/name
identifier instead of substring matching, and keep the existing
ItemInfoByDefIndex lookup flow unchanged.

---

Nitpick comments:
In `@csgo_gc/inventory.cpp`:
- Around line 1761-1797: The KillEater attribute lookup logic is duplicated for
weaponA and weaponB, with separate passes over each weapon’s attributes for
`AttributeKillEater` and `AttributeKillEaterScoreType == 0`. Refactor the
repeated scanning in `inventory.cpp` into a shared helper around the existing
`weaponA`, `weaponB`, `attrA`, `attrB`, `weaponAScoreType`, and
`weaponBScoreType` logic so each weapon is processed once and both checks happen
in a single loop. Call that helper for each weapon instead of keeping two
near-identical blocks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 801cb8c4-210c-42e1-96a8-22b6d698ed10

📥 Commits

Reviewing files that changed from the base of the PR and between 3ab803d and 1a1914c.

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

Comment thread csgo_gc/item_schema.cpp
@GT-610
GT-610 merged commit d0345aa into main Jul 7, 2026
5 checks passed
@GT-610
GT-610 deleted the tool-consumption-validation branch July 7, 2026 09:46
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