Skip to content

Read the game-mode and teammate cvars through the typed ConVar<T> API [patch] - #86

Open
matt-edmondson wants to merge 4 commits into
mainfrom
fix/83-typed-convar
Open

matt-edmondson wants to merge 4 commits into
mainfrom
fix/83-typed-convar

Conversation

@matt-edmondson

@matt-edmondson matt-edmondson commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #83

What was wrong

CounterStrikeSharp 1.0.379 (bumped in #69) marks the untyped ConVar [Obsolete("Use ConVar<T> instead")]. Debug builds treat warnings as errors, so the plugin's documented dotnet build CounterStrikeProgression/CounterStrikeProgression.csproj failed with 6 × CS0618 in GameState.cs and Site/SiteReporter.cs.

Change

  • GameState.TeammatesAreEnemies uses ConVar<bool>.Find("mp_teammates_are_enemies") and reads .Value.
  • SiteReporter.CollectBatch uses ConVar<int>.Find("game_type") / ConVar<int>.Find("game_mode") and reads .Value.
  • The caching and the ?? false / ?? 0 fallbacks for a missing cvar are unchanged. ConVar<T>.Find returns null when the name isn't registered, as ConVar.Find did.

No [SuppressMessage] was needed.

Reviewer note: unlike GetPrimitiveValue<T>, ConVar<T>.Value checks T against the cvar's native type. It throws InvalidOperationException on a mismatch (I read this from the 1.0.379 assembly). The types used here are those cvars' CS2 types: mp_teammates_are_enemies is Bool, and game_type / game_mode are Int32. They are also the types the old code already read them as. I couldn't run this against a live CS2 server, so the in-game read is unverified.

Also carries #85

main's Site doesn't build until #82 is fixed (KTSU0006). That kept this PR's CI from reaching the tests, so this branch also carries #85's commit. After merging main (MySqlConnector 3.0.0, #92), Directory.Packages.props here is identical to #85's: MySqlConnector 3.0.0 and Logging.Abstractions 10.0.15, the floor MySqlConnector 3.0.0 needs. So whichever PR merges first, the other still merges cleanly.

Verification

  • On main (2a7d412), the Debug plugin build fails with 6 × CS0618. On this branch, after merging main, it builds with 0 warnings and 0 errors, and the Release solution build has 0 errors.
  • This change has no unit test, because the plugin layer needs the CounterStrikeSharp host. The Debug build is the check.
  • dotnet test --project CounterStrikeProgression.Test -c Release: 748 total, 741 passed, 7 MySQL skipped, 0 failed.

🤖 Generated with Claude Code

https://claude.ai/code/session_017vfJW55E1qd6SA7hhzHqoF

… [patch]

CounterStrikeSharp 1.0.379 marks the untyped ConVar obsolete, so a Debug
build of the plugin failed with 6 x CS0618. Look up mp_teammates_are_enemies
as ConVar<bool> and game_type / game_mode as ConVar<int>, the cvars' native
types in CS2, and read them through Value.

Fixes #83

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4d7dbQrUhkrt4JoGT
…s again [patch]

Dependabot #81 bumped Microsoft.Extensions.Logging.Abstractions to 11.0.0 and
added a direct reference to it in Core, which doesn't use it. The reference
flowed into the Site and replaced the ASP.NET Core 10 shared-framework copy,
so ktsu.Sdk failed the Site build with KTSU0006. Remove the reference, put the
central version back to 10.0.0 to match the host and the framework, and keep
Dependabot from proposing major bumps of Microsoft.Extensions.* on their own.

Fixes #82

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4d7dbQrUhkrt4JoGT

Copy link
Copy Markdown
Contributor Author

Test on ubuntu-latest failed at 5bbc051 with KTSU0006 in CounterStrikeProgression.Site (MetricsEndpoints.cs(22,38), Live/LiveState.cs(28,97)). This PR didn't cause it. It's the main breakage from #82, and main fails the same way.

#85 already fixes it, so I've cherry-picked that commit here (fdf43ba) and CI can now build the Site and run the tests on this PR. The changes are identical, so whichever of #85 and #86 merges first, the other still merges cleanly and that commit's diff drops out.


Generated by Claude Code

claude and others added 2 commits November 11, 2026 20:22
Resolve Directory.Packages.props: take main's ktsu.Semantics.Strings 6.0.0
and keep Microsoft.Extensions.Logging.Abstractions 10.0.0 from #85.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5B3W6WRadY4oRm8a7
Takes main's MySqlConnector 3.0.0 and the 10.0.15 Logging.Abstractions pin from #85, the floor MySqlConnector 3.0.0 needs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW55E1qd6SA7hhzHqoF
@sonarqubecloud

Copy link
Copy Markdown

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.

Plugin fails a Debug build with 6 × CS0618 since CounterStrikeSharp 1.0.379 made ConVar obsolete

2 participants