Compare commits

...

21 Commits

Author SHA1 Message Date
Michael Wilson
169d43e31d release: 1.0.315 2025-04-01 02:05:37 +00:00
schwarper
0ce4a2903c Update CCSPlayer_ItemServices_CanAcquire signature (#832) 2025-04-01 11:24:21 +10:00
Pawel Bartusiak
33b46eb214 docs: add automatic build and deploy guide (#831) 2025-03-31 11:45:43 +10:00
Michael Wilson
a27ba3b005 fix: move EventPlayerChat to dedicated file and exclude from generator
- Created a separate EventPlayerChat since this is being fired manually
- Updated event generator to exclude player_chat event from GameEvents.g.cs
2025-03-31 11:44:15 +10:00
Michael Wilson
57286c9990 chore(changelog): cleanup whitespace once and for all 2025-03-28 06:53:49 +00:00
Michael Wilson
ae808c05c8 [no ci] chore: fix commit links in release changelog 2025-03-27 14:46:17 +10:00
Michael Wilson
c9f8e477d3 release: 1.0.314 2025-03-27 04:06:33 +00:00
Michael Wilson
2398ba0a5d fix: manually revert EventPlayerChat to old value (#827) 2025-03-27 13:56:15 +10:00
roflmuffin
e45c20481d ci: hide release commits in changelog 2025-03-25 20:56:03 +10:00
roflmuffin
fe321ee93d ci: include full changelog link in discord message 2025-03-25 20:31:42 +10:00
roflmuffin
be19103556 chore: remove footer from cliff changelog 2025-03-25 20:29:16 +10:00
roflmuffin
64cb26b86d chore: fix newlines in changelog 2025-03-25 20:24:26 +10:00
roflmuffin
637224dc55 ci: fix cliff generation 2025-03-25 20:18:15 +10:00
roflmuffin
3aca7c37f1 ci: add changelog to release & webhook 2025-03-25 20:07:02 +10:00
roflmuffin
87f38d72ee release: v1.0.313 2025-03-25 19:28:06 +10:00
roflmuffin
5daf94791f chore(changelog): update cliff.toml 2025-03-25 19:18:19 +10:00
Michael Wilson
c50213c442 feat(config): add toml loading support (#804) 2025-03-25 19:12:29 +10:00
roflmuffin
c02d31cb2e chore: add links to contributors github page 2025-03-24 19:49:53 +10:00
roflmuffin
98cbca44d4 chore: update changelog to use semantic tags 2025-03-24 19:44:22 +10:00
Michael Wilson
4cf88fc03e fix(gameevents): promote core.gameevents to have higher priority (#819) 2025-03-24 19:32:47 +10:00
Michael Wilson
f1dff6d4d3 chrore: Implement SemVer instead of build numbers (#816) 2025-03-24 19:15:46 +10:00
18 changed files with 4646 additions and 2034 deletions

View File

@@ -1,30 +1,45 @@
name: Build & Publish
env:
BUILD_TYPE: Release
# Remove default permissions of GITHUB_TOKEN for security
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
permissions: {}
on:
push:
paths-ignore:
- "docfx/**"
branches: ["main", "dev"]
branches: ["main"]
tags:
- "v*"
pull_request:
branches: ["main", "dev"]
env:
BUILD_TYPE: Release
branches: ["main"]
jobs:
setup:
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
buildnumber: ${{ steps.buildnumber.outputs.build_number }}
gitversion_semver: ${{ steps.gitversion.outputs.semVer }}
gitversion_fullsemver: ${{ steps.gitversion.outputs.fullSemVer }}
gitversion_assemblysemver: ${{ steps.gitversion.outputs.assemblySemVer }}
gitversion_informationalversion: ${{ steps.gitversion.outputs.informationalVersion }}
steps:
- name: Generate build number
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
id: buildnumber
uses: onyxmueller/build-tag-number@v1
with:
token: ${{secrets.github_token}}
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v1
with:
versionSpec: 6.0.x
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Execute GitVersion
id: gitversion
uses: gittools/actions/gitversion/execute@v1
with:
useConfigFile: true
build_windows:
needs: setup
@@ -32,16 +47,9 @@ jobs:
steps:
- name: Prepare env
shell: bash
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
- name: Fallback build number
if: ${{ github.event_name == 'pull_request' || github.ref != 'refs/heads/main' }}
shell: bash
run: echo "BUILD_NUMBER=0" >> $GITHUB_ENV
- name: Main build number
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: echo "BUILD_NUMBER=${{ needs.setup.outputs.buildnumber }}" >> $GITHUB_ENV
run: |
echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
echo "SEMVER=${{ needs.setup.outputs.gitversion_semver }}" >> $GITHUB_ENV
- name: Visual Studio environment
shell: cmd
@@ -56,7 +64,7 @@ jobs:
echo>>"%GITHUB_ENV%" %%a=%%b
)
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: "recursive"
@@ -76,7 +84,7 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: counterstrikesharp-build-windows-${{ env.GITHUB_SHA_SHORT }}
name: counterstrikesharp-windows-${{ needs.setup.outputs.gitversion_semver }}
path: build/output/
build_linux:
@@ -88,18 +96,11 @@ jobs:
steps:
- name: Prepare env
shell: bash
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
run: |
echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
echo "SEMVER=${{ needs.setup.outputs.gitversion_semver }}" >> $GITHUB_ENV
- name: Fallback build number
if: ${{ github.event_name == 'pull_request' || github.ref != 'refs/heads/main' }}
shell: bash
run: echo "BUILD_NUMBER=0" >> $GITHUB_ENV
- name: Main build number
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: echo "BUILD_NUMBER=${{ needs.setup.outputs.buildnumber }}" >> $GITHUB_ENV
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: "recursive"
@@ -117,7 +118,7 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: counterstrikesharp-build-linux-${{ env.GITHUB_SHA_SHORT }}
name: counterstrikesharp-linux-${{ needs.setup.outputs.gitversion_semver }}
path: build/output/
build_managed:
@@ -130,20 +131,11 @@ jobs:
shell: bash
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
- name: Fallback build number
if: ${{ github.event_name == 'pull_request' || github.ref != 'refs/heads/main' }}
shell: bash
run: echo "BUILD_NUMBER=0" >> $GITHUB_ENV
- name: Main build number
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: echo "BUILD_NUMBER=${{ needs.setup.outputs.buildnumber }}" >> $GITHUB_ENV
# We don't need expensive submodules for the managed side.
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build runtime v${{ env.BUILD_NUMBER }}
uses: actions/setup-dotnet@v3
- name: Build runtime v${{ needs.setup.outputs.gitversion_semver }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
@@ -151,27 +143,36 @@ jobs:
run: dotnet restore managed/CounterStrikeSharp.sln
- name: Run tests
run: dotnet test --logger trx --results-directory "TestResults-${{ env.GITHUB_SHA_SHORT }}" managed/CounterStrikeSharp.API.Tests/CounterStrikeSharp.API.Tests.csproj
run: dotnet test --logger trx --results-directory "TestResults-${{ needs.setup.outputs.gitversion_semver }}" managed/CounterStrikeSharp.API.Tests/CounterStrikeSharp.API.Tests.csproj
- name: Upload dotnet test results
uses: actions/upload-artifact@v4
with:
name: test-results-${{ env.GITHUB_SHA_SHORT }}
path: TestResults-${{ env.GITHUB_SHA_SHORT }}
name: test-results-${{ needs.setup.outputs.gitversion_semver }}
path: TestResults-${{ needs.setup.outputs.gitversion_semver }}
if: ${{ always() }}
- name: Publish artifacts
run: |
dotnet publish -c Release /p:Version=1.0.${{ env.BUILD_NUMBER }} managed/CounterStrikeSharp.API
dotnet pack -c Release /p:Version=1.0.${{ env.BUILD_NUMBER }} managed/CounterStrikeSharp.API
dotnet publish -c Release \
/p:Version=${{ needs.setup.outputs.gitversion_semver }} \
/p:AssemblyVersion=${{ needs.setup.outputs.gitversion_assemblySemver }} \
/p:InformationalVersion=${{ needs.setup.outputs.gitversion_informationalversion }} \
managed/CounterStrikeSharp.API
dotnet pack -c Release \
/p:Version=${{ needs.setup.outputs.gitversion_semver }} \
/p:AssemblyVersion=${{ needs.setup.outputs.gitversion_assemblySemver }} \
/p:InformationalVersion=${{ needs.setup.outputs.gitversion_informationalversion }} \
managed/CounterStrikeSharp.API
- uses: actions/upload-artifact@v4
with:
name: counterstrikesharp-build-api-${{ env.GITHUB_SHA_SHORT }}
name: counterstrikesharp-api-${{ needs.setup.outputs.gitversion_semver }}
path: managed/CounterStrikeSharp.API/bin/Release
publish:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && github.repository == 'roflmuffin/CounterStrikeSharp' }}
permissions:
contents: write
needs: ["setup", "build_linux", "build_windows", "build_managed"]
@@ -181,19 +182,24 @@ jobs:
shell: bash
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: counterstrikesharp-build-windows-${{ env.GITHUB_SHA_SHORT }}
name: counterstrikesharp-windows-${{ needs.setup.outputs.gitversion_semver }}
path: build/windows
- uses: actions/download-artifact@v4
with:
name: counterstrikesharp-build-linux-${{ env.GITHUB_SHA_SHORT }}
name: counterstrikesharp-linux-${{ needs.setup.outputs.gitversion_semver }}
path: build/linux
- uses: actions/download-artifact@v4
with:
name: counterstrikesharp-build-api-${{ env.GITHUB_SHA_SHORT }}
name: counterstrikesharp-api-${{ needs.setup.outputs.gitversion_semver }}
path: build/api
# TODO: This stuff should really be in a matrix
@@ -206,8 +212,8 @@ jobs:
- name: Zip Builds
run: |
(cd build/linux && zip -qq -r ../../counterstrikesharp-build-${{ needs.setup.outputs.buildnumber }}-linux-${{ env.GITHUB_SHA_SHORT }}.zip *)
(cd build/windows && zip -qq -r ../../counterstrikesharp-build-${{ needs.setup.outputs.buildnumber }}-windows-${{ env.GITHUB_SHA_SHORT }}.zip *)
(cd build/linux && zip -qq -r ../../counterstrikesharp-linux-${{ needs.setup.outputs.gitversion_semver }}.zip *)
(cd build/windows && zip -qq -r ../../counterstrikesharp-windows-${{ needs.setup.outputs.gitversion_semver }}.zip *)
- name: Add dotnet runtime
run: |
@@ -221,28 +227,44 @@ jobs:
- name: Zip Builds
run: |
(cd build/linux && zip -qq -r ../../counterstrikesharp-with-runtime-build-${{ needs.setup.outputs.buildnumber }}-linux-${{ env.GITHUB_SHA_SHORT }}.zip *)
(cd build/windows && zip -qq -r ../../counterstrikesharp-with-runtime-build-${{ needs.setup.outputs.buildnumber }}-windows-${{ env.GITHUB_SHA_SHORT }}.zip *)
(cd build/linux && zip -qq -r ../../counterstrikesharp-with-runtime-linux-${{ needs.setup.outputs.gitversion_semver }}.zip *)
(cd build/windows && zip -qq -r ../../counterstrikesharp-with-runtime-windows-${{ needs.setup.outputs.gitversion_semver }}.zip *)
- name: Generate a changelog
uses: orhun/git-cliff-action@v4
id: git-cliff
with:
config: cliff.toml
args: --current -s footer
- name: Release
id: release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.setup.outputs.buildnumber }}
append_body: true
body: |
${{ steps.git-cliff.outputs.content }}
Please refer to [CHANGELOG.md](https://github.com/roflmuffin/CounterStrikeSharp/blob/${{ github.ref_name }}/CHANGELOG.md) for details.
files: |
counterstrikesharp-build-${{ needs.setup.outputs.buildnumber }}-windows-${{ env.GITHUB_SHA_SHORT }}.zip
counterstrikesharp-with-runtime-build-${{ needs.setup.outputs.buildnumber }}-windows-${{ env.GITHUB_SHA_SHORT }}.zip
counterstrikesharp-build-${{ needs.setup.outputs.buildnumber }}-linux-${{ env.GITHUB_SHA_SHORT }}.zip
counterstrikesharp-with-runtime-build-${{ needs.setup.outputs.buildnumber }}-linux-${{ env.GITHUB_SHA_SHORT }}.zip
counterstrikesharp-windows-${{ needs.setup.outputs.gitversion_semver }}.zip
counterstrikesharp-with-runtime-windows-${{ needs.setup.outputs.gitversion_semver }}.zip
counterstrikesharp-linux-${{ needs.setup.outputs.gitversion_semver }}.zip
counterstrikesharp-with-runtime-linux-${{ needs.setup.outputs.gitversion_semver }}.zip
- name: Publish NuGet package
run: |
dotnet nuget push build/api/CounterStrikeSharp.API.1.0.${{ needs.setup.outputs.buildnumber }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push build/api/CounterStrikeSharp.API.1.0.${{ needs.setup.outputs.buildnumber }}.snupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push build/api/CounterStrikeSharp.API.${{ needs.setup.outputs.gitversion_semver }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push build/api/CounterStrikeSharp.API.${{ needs.setup.outputs.gitversion_semver }}.snupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
- name: Send Notification to Discord
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@0.3.2
with:
args: "A new release of CS# has been tagged (v${{ needs.setup.outputs.buildnumber }}) at ${{ steps.release.outputs.url }}"
args: |
A new release of CS# has been tagged [v${{ needs.setup.outputs.gitversion_semver }}](${{ steps.release.outputs.url }})
${{ steps.git-cliff.outputs.content }}
Please refer to [CHANGELOG.md](https://github.com/roflmuffin/CounterStrikeSharp/blob/${{ github.ref_name }}/CHANGELOG.md) for details.

File diff suppressed because it is too large Load Diff

1
GitVersion.yml Normal file
View File

@@ -0,0 +1 @@
workflow: GitHubFlow/v1

View File

@@ -2,8 +2,8 @@
# https://git-cliff.org/docs/configuration
# [remote.github]
# owner = "roflmuffin"
# repo = "CounterStrikeSharp"
owner = "roflmuffin"
repo = "CounterStrikeSharp"
# token = ""
[changelog]
@@ -14,17 +14,15 @@ body = """
{%- if version %} in {{ version }}{%- endif -%}
{% for commit in commits %}
{% if commit.remote.pr_title -%}
{%- set commit_message = commit.remote.pr_title -%}
{%- else -%}
{%- set commit_message = commit.message -%}
{%- endif -%}
* {{ commit_message | split(pat="\n") | first | trim }}\
{% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif -%}
* {{ commit.message | split(pat="\n") | first | trim }}\
{% if commit.remote.username and commit.remote.username != remote.github.owner %} by \
[@{{ commit.remote.username }}](https://github.com/{{ commit.remote.username }}) \
{%- endif -%}
{% if commit.remote.pr_number %} in \
[#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}) \
[#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }})\
{%- endif %}
([{{ commit.id | truncate(length=7, end="") }}]({{ commit.id }}))
{%- if commit.id %} ([{{ commit.id | truncate(length=7, end="") }}]({{ self::remote_url()}}/commit/{{ commit.id }})){%- endif -%}
{%- endfor -%}
{%- if github -%}
@@ -33,7 +31,7 @@ body = """
## New Contributors
{%- endif %}\
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}
* @{{ contributor.username }} made their first contribution
* [@{{ contributor.username }}](https://github.com/{{ contributor.username }}) made their first contribution
{%- if contributor.pr_number %} in \
[#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \
{%- endif %}
@@ -70,11 +68,18 @@ filter_unconventional = true
# Split commits on newlines, treating each line as an individual commit.
split_commits = false
# An array of regex based parsers to modify commit messages prior to further processing.
commit_preprocessors = [{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" }]
commit_preprocessors = [
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" },
{ pattern = '\[no ci\]', replace = "" }
]
commit_parsers = [
{ message = "^release:", skip = true }
]
# Exclude commits that are not matched by any commit parser.
filter_commits = false
# Order releases topologically instead of chronologically.
topo_order = false
# Order of commits in each group/release within the changelog.
# Allowed values: newest, oldest
sort_commits = "newest"
sort_commits = "newest"
tag_pattern = "v[0-9]+\\.[0-9]+\\.[0-9]+"

View File

@@ -92,7 +92,7 @@
"signatures": {
"library": "server",
"windows": "44 89 44 24 ? 48 89 54 24 ? 48 89 4C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8B EC",
"linux": "55 48 89 E5 41 57 41 56 41 55 49 89 CD 41 54 53 48 83 EC"
"linux": "55 48 89 E5 41 57 41 56 48 8D 45 ? 41 55 41 54 53 48 89 CB"
}
},
"GetCSWeaponDataFromKey": {
@@ -273,4 +273,4 @@
"linux": 584
}
}
}
}

View File

@@ -0,0 +1,99 @@
---
title: Automatically build/deploy your changes
description: Automatically build and deploy plugin changes to a remote development server as you work.
---
# Automatically build and deploy your changes
<sup>Adapted from the
[original guide](https://github.com/uFloppyDisk/create-cssharp-plugin/blob/c8fca43f86a61a5e874624f2f3ed39c5271c9a55/templates/standard-plugin/docs/auto-live-hot-reloading.md).
</sup>
During development of your plugin, you may find yourself repeating a workflow
similar to the following:
1. Make a change to your plugin
2. Run your build task (ex. `dotnet build`)
3. Upload plugin DLLs to your server using an FTP client
4. Alt-tab to the game
5. Test your changes
6. Repeat
Iterating on your plugin this way is painfully slow and impacts your productivity.
Below, you will find a guide and recommendations on how to setup your dev environment
to watch for file changes and automatically update plugin files on your server as you work.
By following this guide, your new workflow should look like this:
1. Make a change to your plugin
2. Alt-tab to the game
3. Test your changes
4. Repeat
> [!CAUTION]
> Exercise caution when developing your plugin while using this workflow.
> Build time errors are mostly caught by .NET SDK before files are committed
> but incomplete implementation may lead to issues such as server crashes.
> Avoid using this workflow on a production server meant for players.
## Setup
#### 1. Build plugin on file changes
The `dotnet` CLI, included with the .NET SDK, offers a convenient command for
automatically watching for source file changes. If you have access to the `dotnet`
CLI, run the following command to start watching your source code.
```shell
dotnet watch build --project path/to/projectName.csproj
```
<sup>By default, `dotnet watch` executes the `dotnet run` command on file changes
so specifying `build` as the first argument is required.</sup>
Your plugin will now build automatically on file change. By default, your builds
should be placed in `bin/<config>/<framework>` in the same directory as your `.csproj`.
```txt
projectDirectory
├── projectName.csproj
├── bin
│   └── Debug
│   └── net8.0
│      └── PLUGIN BUILDS HERE
```
> [!TIP]
> You can have your plugin build to a more convenient location by setting the
> `<OutDir>` build property in your `.csproj` file.
> Example: `<OutDir>./build/$(MSBuildProjectName)</OutDir>`
#### 2. Setup automatic uploads
##### Using WinSCP (Windows only)
Once connected to your server:
1. Go to the `Commands` tab at the top of the WinSCP window
and click `Keep Remote Directory up to Date`.
2. Select the plugin build directory containing your DLLs.
3. Select the plugin destination.
(`csgo/addons/counterstrikesharp/plugins/<projectName>`)
4. Click `Start`
> [!IMPORTANT]
> **For WSL users:**
> Applications running on Windows, such as WinSCP, cannot watch your Linux subsystem for file
> changes. Try using [this workaround](#using-winscp-while-developing-in-wsl) or consider
> moving development to Windows.
##### Using `lsyncd` (Linux)
> **TODO:** in-depth guide for setting up lsyncd
Learn more about `lsyncd`: https://github.com/lsyncd/lsyncd
___
#### Using WinSCP while developing in WSL
Run the following watch command in place of the one mentioned in
[Step 1](#1-build-plugin-on-file-changes) to build to a directory in your Windows filesystem
```shell
dotnet watch build --project path/to/<projectName>.csproj --property:OutDir=/mnt/<drive-letter>/some/path/<projectName>`
```
and have [WinSCP in Step 2](#2-setup-automatic-uploads) watch that path instead.
[Learn about Windows filesystem mounts in WSL](https://blogs.windows.com/windowsdeveloper/2016/07/22/fun-with-the-windows-subsystem-for-linux/#Working%20with%20Windows%20files:~:text=Working%20with%20Windows%20files)

View File

@@ -8,4 +8,7 @@
href: dependency-injection.md
- name: Referencing Players
href: referencing-players.md
href: referencing-players.md
- name: Automatically build and deploy your changes
href: auto-build-and-deploy.md

View File

@@ -1,38 +1,60 @@
using System.Text.Json.Serialization;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
namespace WithConfig;
public class SampleConfig : BasePluginConfig
{
[JsonPropertyName("ChatPrefix")] public string ChatPrefix { get; set; } = "My Cool Plugin";
[JsonPropertyName("ChatInterval")] public float ChatInterval { get; set; } = 60;
}
[MinimumApiVersion(80)]
public class WithConfigPlugin : BasePlugin, IPluginConfig<SampleConfig>
{
public override string ModuleName => "Example: With Config";
public override string ModuleVersion => "1.0.0";
public SampleConfig Config { get; set; }
public void OnConfigParsed(SampleConfig config)
{
// Do manual verification of the config and override any invalid values
if (config.ChatInterval > 60)
{
config.ChatInterval = 60;
}
if (config.ChatPrefix.Length > 25)
{
throw new Exception($"Invalid value has been set to config value 'ChatPrefix': {config.ChatPrefix}");
}
// Once we've validated the config, we can set it to the instance
Config = config;
}
}
using System.Text.Json.Serialization;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Config;
using CounterStrikeSharp.API.Modules.Extensions;
namespace WithConfig;
public class SampleConfig : BasePluginConfig
{
[JsonPropertyName("ChatPrefix")] public string ChatPrefix { get; set; } = "My Cool Plugin";
[JsonPropertyName("ChatInterval")] public float ChatInterval { get; set; } = 60;
}
[MinimumApiVersion(80)]
public class WithConfigPlugin : BasePlugin, IPluginConfig<SampleConfig>
{
public override string ModuleName => "Example: With Config";
public override string ModuleVersion => "1.0.0";
public SampleConfig Config { get; set; }
public void OnConfigParsed(SampleConfig config)
{
// Do manual verification of the config and override any invalid values
if (config.ChatInterval > 60)
{
config.ChatInterval = 60;
}
if (config.ChatPrefix.Length > 25)
{
throw new Exception($"Invalid value has been set to config value 'ChatPrefix': {config.ChatPrefix}");
}
// Once we've validated the config, we can set it to the instance
Config = config;
}
[ConsoleCommand("css_reload_config", "Reloads the plugin config")]
public void OnReloadConfig(CCSPlayerController? player, CommandInfo commandInfo)
{
commandInfo.ReplyToCommand("Chat Interval before reload: " + Config.ChatInterval);
Config.Reload();
commandInfo.ReplyToCommand("Chat Interval after reload: " + Config.ChatInterval);
}
[ConsoleCommand("css_reset_config", "Resets the plugin config")]
public void OnResetConfig(CCSPlayerController? player, CommandInfo commandInfo)
{
commandInfo.ReplyToCommand("Chat Interval before reset: " + Config.ChatInterval);
Config.ChatInterval = 60;
Config.Update();
commandInfo.ReplyToCommand("Chat Interval after reset: " + Config.ChatInterval);
}
}

View File

@@ -35,10 +35,10 @@ else()
add_definitions(-DGITHUB_SHA="Local")
endif()
if(DEFINED ENV{BUILD_NUMBER})
add_definitions(-DBUILD_NUMBER="$ENV{BUILD_NUMBER}")
if(DEFINED ENV{SEMVER})
add_definitions(-DSEMVER="$ENV{SEMVER}")
else()
add_definitions(-DBUILD_NUMBER="0")
add_definitions(-DSEMVER="Local")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")

File diff suppressed because it is too large Load Diff

View File

@@ -682,6 +682,30 @@ namespace CounterStrikeSharp.API.Core
get => GetPlayer("userid");
set => SetPlayer("userid", value);
}
public bool PlayerHeld
{
get => Get<bool>("player_held");
set => Set<bool>("player_held", value);
}
public bool PlayerThrown
{
get => Get<bool>("player_thrown");
set => Set<bool>("player_thrown", value);
}
public bool PlayerDropped
{
get => Get<bool>("player_dropped");
set => Set<bool>("player_dropped", value);
}
}
[EventName("broken_breakable")]
@@ -2053,10 +2077,10 @@ namespace CounterStrikeSharp.API.Core
// Entindex of the entity they see
public int Subject
public long Subject
{
get => Get<int>("subject");
set => Set<int>("subject", value);
get => Get<long>("subject");
set => Set<long>("subject", value);
}
@@ -2334,6 +2358,14 @@ namespace CounterStrikeSharp.API.Core
get => Get<string>("mapname");
set => Set<string>("mapname", value);
}
// true if this is a transition from one map to another
public bool Transition
{
get => Get<bool>("transition");
set => Set<bool>("transition", value);
}
}
[EventName("game_phase_changed")]
@@ -3318,6 +3350,14 @@ namespace CounterStrikeSharp.API.Core
}
// entity id of the env_instructor_hint that fired the event
public long HintEntindex
{
get => Get<long>("hint_entindex");
set => Set<long>("hint_entindex", value);
}
// what to name the hint. For referencing it again later (e.g. a kill command for the hint instead of a timeout)
public string HintName
{
@@ -3342,7 +3382,7 @@ namespace CounterStrikeSharp.API.Core
}
// userid id of the activator
// playerslot of the activator
public CCSPlayerController? HintActivatorUserid
{
get => GetPlayer("hint_activator_userid");
@@ -3430,14 +3470,6 @@ namespace CounterStrikeSharp.API.Core
}
// gamepad bindings to use when use_binding is the onscreen icon
public string HintGamepadBinding
{
get => Get<string>("hint_gamepad_binding");
set => Set<string>("hint_gamepad_binding", value);
}
// if false, the hint will dissappear if the target entity is invisible
public bool HintAllowNodrawTarget
{
@@ -3468,6 +3500,62 @@ namespace CounterStrikeSharp.API.Core
get => Get<bool>("hint_local_player_only");
set => Set<bool>("hint_local_player_only", value);
}
// Game sound to play
public string HintStartSound
{
get => Get<string>("hint_start_sound");
set => Set<string>("hint_start_sound", value);
}
// Path for Panorama layout file
public string HintLayoutfile
{
get => Get<string>("hint_layoutfile");
set => Set<string>("hint_layoutfile", value);
}
// Attachment type for the Panorama panel
public int HintVrPanelType
{
get => Get<int>("hint_vr_panel_type");
set => Set<int>("hint_vr_panel_type", value);
}
// Height offset for attached panels
public float HintVrHeightOffset
{
get => Get<float>("hint_vr_height_offset");
set => Set<float>("hint_vr_height_offset", value);
}
// offset for attached panels
public float HintVrOffsetX
{
get => Get<float>("hint_vr_offset_x");
set => Set<float>("hint_vr_offset_x", value);
}
// offset for attached panels
public float HintVrOffsetY
{
get => Get<float>("hint_vr_offset_y");
set => Set<float>("hint_vr_offset_y", value);
}
// offset for attached panels
public float HintVrOffsetZ
{
get => Get<float>("hint_vr_offset_z");
set => Set<float>("hint_vr_offset_z", value);
}
}
[EventName("instructor_server_hint_stop")]
@@ -3484,6 +3572,14 @@ namespace CounterStrikeSharp.API.Core
get => Get<string>("hint_name");
set => Set<string>("hint_name", value);
}
// entity id of the env_instructor_hint that fired the event
public long HintEntindex
{
get => Get<long>("hint_entindex");
set => Set<long>("hint_entindex", value);
}
}
[EventName("instructor_start_lesson")]
@@ -3549,6 +3645,21 @@ namespace CounterStrikeSharp.API.Core
public EventInventoryUpdated(bool force) : base("inventory_updated", force){}
public int Itemdef
{
get => Get<int>("itemdef");
set => Set<int>("itemdef", value);
}
public long Itemid
{
get => Get<long>("itemid");
set => Set<long>("itemid", value);
}
}
[EventName("item_equip")]
@@ -4417,38 +4528,6 @@ namespace CounterStrikeSharp.API.Core
}
}
[EventName("player_chat")]
public class EventPlayerChat : GameEvent
{
public EventPlayerChat(IntPtr pointer) : base(pointer){}
public EventPlayerChat(bool force) : base("player_chat", force){}
// true if team only chat
public bool Teamonly
{
get => Get<bool>("teamonly");
set => Set<bool>("teamonly", value);
}
// chatting player
public int Userid
{
get => Get<int>("userid");
set => Set<int>("userid", value);
}
// chat text
public string Text
{
get => Get<string>("text");
set => Set<string>("text", value);
}
}
[EventName("player_connect")]
public class EventPlayerConnect : GameEvent
{
@@ -5289,7 +5368,7 @@ namespace CounterStrikeSharp.API.Core
// player
public CCSPlayerController? Userid
{
get => GetPlayer("userid");
@@ -5329,7 +5408,15 @@ namespace CounterStrikeSharp.API.Core
}
// true if player is a bot
public string Name
{
get => Get<string>("name");
set => Set<string>("name", value);
}
public bool Isbot
{
get => Get<bool>("isbot");
@@ -6877,42 +6964,18 @@ namespace CounterStrikeSharp.API.Core
public int VoteOption1
public int Yesvotes
{
get => Get<int>("vote_option1");
set => Set<int>("vote_option1", value);
get => Get<int>("yesVotes");
set => Set<int>("yesVotes", value);
}
public int VoteOption2
public int Novotes
{
get => Get<int>("vote_option2");
set => Set<int>("vote_option2", value);
}
public int VoteOption3
{
get => Get<int>("vote_option3");
set => Set<int>("vote_option3", value);
}
public int VoteOption4
{
get => Get<int>("vote_option4");
set => Set<int>("vote_option4", value);
}
public int VoteOption5
{
get => Get<int>("vote_option5");
set => Set<int>("vote_option5", value);
get => Get<int>("noVotes");
set => Set<int>("noVotes", value);
}
@@ -7078,6 +7141,14 @@ namespace CounterStrikeSharp.API.Core
public string Votedata
{
get => Get<string>("votedata");
set => Set<string>("votedata", value);
}
public int Team
{
get => Get<int>("team");
@@ -7091,6 +7162,14 @@ namespace CounterStrikeSharp.API.Core
get => Get<long>("initiator");
set => Set<long>("initiator", value);
}
// this event is reliable
public int Reliable
{
get => Get<int>("reliable");
set => Set<int>("reliable", value);
}
}
[EventName("warmup_end")]

View File

@@ -39,6 +39,7 @@
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0"/>
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0"/>
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0"/>
<PackageReference Include="Tomlyn" Version="0.19.0"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Core\Schema\"/>
@@ -59,9 +60,9 @@
</PropertyGroup>
<Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
<Exec
Command="git describe --long --always --exclude=* --abbrev=7"
ConsoleToMSBuild="True"
IgnoreExitCode="False"
Command="git describe --long --always --exclude=* --abbrev=7"
ConsoleToMSBuild="True"
IgnoreExitCode="False"
>
<Output PropertyName="SourceRevisionId" TaskParameter="ConsoleOutput"/>
</Exec>

View File

@@ -14,18 +14,21 @@
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/
using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Text.Json;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Logging;
using Microsoft.Extensions.Logging;
using Tomlyn;
namespace CounterStrikeSharp.API.Modules.Config
{
enum ConfigType
{
Json,
Toml
}
public static class ConfigManager
{
private static readonly DirectoryInfo? _rootDir;
@@ -33,47 +36,59 @@ namespace CounterStrikeSharp.API.Modules.Config
private static readonly string _pluginConfigsFolderPath;
private static ILogger _logger = CoreLogging.Factory.CreateLogger("ConfigManager");
internal static JsonSerializerOptions JsonSerializerOptions { get; } = new()
{
WriteIndented = true,
ReadCommentHandling = JsonCommentHandling.Skip
};
internal static TomlModelOptions TomlModelOptions { get; } = new()
{
ConvertPropertyName = name => name
};
static ConfigManager()
{
_rootDir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.Parent;
_pluginConfigsFolderPath = Path.Combine(_rootDir.FullName, "configs", "plugins");
}
public static T Load<T>(string pluginName) where T : IBasePluginConfig, new()
public static T Load<T>(string pluginName) where T : class, IBasePluginConfig, new()
{
string directoryPath = Path.Combine(_pluginConfigsFolderPath, pluginName);
string configPath = Path.Combine(directoryPath, $"{pluginName}.json");
string exampleConfigPath = Path.Combine(directoryPath, $"{pluginName}.example.json");
string configPath = Path.Combine(directoryPath, $"{pluginName}");
string exampleConfigPath = Path.Combine(directoryPath, $"{pluginName}.example");
T config = (T)Activator.CreateInstance(typeof(T))!;
string[] configFilePaths =
[
$"{configPath}.toml",
$"{configPath}.json",
];
if (!File.Exists(configPath) && !File.Exists(exampleConfigPath))
foreach (var path in configFilePaths)
{
try
if (File.Exists(path))
{
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
return Deserialize<T>(path);
}
}
StringBuilder builder = new StringBuilder();
builder.Append(
$"// This configuration was automatically generated by CounterStrikeSharp for plugin '{pluginName}', at {DateTimeOffset.Now:yyyy/MM/dd hh:mm:ss}\n");
builder.Append(JsonSerializer.Serialize<T>(config,
new JsonSerializerOptions { WriteIndented = true }));
File.WriteAllText(configPath, builder.ToString());
return config;
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to generate configuration file for {PluginName}", pluginName);
}
} else if (File.Exists(exampleConfigPath) && !File.Exists(configPath))
string[] exampleFilePaths =
[
$"{exampleConfigPath}.toml",
$"{exampleConfigPath}.json"
];
foreach (var path in exampleFilePaths)
{
if (!File.Exists(path)) continue;
try
{
_logger.LogInformation("Copying example configuration file for {PluginName}", pluginName);
File.Copy(exampleConfigPath, configPath);
var destPath = Path.Combine(directoryPath, Path.GetFileName(path).Replace(".example", ""));
File.Copy(path, destPath);
return Deserialize<T>(destPath);
}
catch (Exception ex)
{
@@ -83,14 +98,58 @@ namespace CounterStrikeSharp.API.Modules.Config
try
{
config = JsonSerializer.Deserialize<T>(File.ReadAllText(configPath), new JsonSerializerOptions() { ReadCommentHandling = JsonCommentHandling.Skip })!;
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
var config = new T();
var output = Serialize(config, ConfigType.Json, pluginName);
File.WriteAllText(Path.Combine(directoryPath, $"{pluginName}.json"), output);
return config;
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to parse configuration file for {PluginName}", pluginName);
_logger.LogError(ex, "Failed to generate configuration file for {PluginName}", pluginName);
return new T();
}
}
private static T Deserialize<T>(string path) where T : class, IBasePluginConfig, new()
{
switch (Path.GetExtension(path))
{
case ".toml":
return Toml.ToModel<T>(File.ReadAllText(path), options: TomlModelOptions);
case ".json":
return JsonSerializer.Deserialize<T>(File.ReadAllText(path), JsonSerializerOptions)!;
}
return config;
throw new NotSupportedException("Unsupported configuration file format");
}
private static string Serialize<T>(T config, ConfigType configType, string pluginName) where T : class, IBasePluginConfig, new()
{
StringBuilder builder = new StringBuilder();
string comment =
$"This configuration was automatically generated by CounterStrikeSharp for plugin '{pluginName}', at {DateTimeOffset.Now:yyyy/MM/dd hh:mm:ss}\n";
switch (configType)
{
case ConfigType.Json:
builder.Append($"// {comment}");
builder.Append(JsonSerializer.Serialize<T>(config, JsonSerializerOptions));
break;
case ConfigType.Toml:
builder.Append($"# {comment}");
builder.Append(Toml.FromModel(config, options: TomlModelOptions));
break;
default:
throw new NotSupportedException("Unsupported configuration file format");
}
return builder.ToString();
}
}
}
}

View File

@@ -0,0 +1,41 @@
using System;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Modules.Entities;
namespace CounterStrikeSharp.API.Modules.Events
{
[EventName("player_chat")]
public class EventPlayerChat : GameEvent
{
public EventPlayerChat(IntPtr pointer) : base(pointer){}
public EventPlayerChat(bool force) : base("player_chat", force){}
/// <summary>
/// If this chat message was sent to team only
/// </summary>
public bool Teamonly
{
get => Get<bool>("teamonly");
set => Set<bool>("teamonly", value);
}
/// <summary>
/// The user ID of the player who sent the chat message
/// </summary>
public int Userid
{
get => Get<int>("userid");
set => Set<int>("userid", value);
}
/// <summary>
/// The text content of the chat message
/// </summary>
public string Text
{
get => Get<string>("text");
set => Set<string>("text", value);
}
}
}

View File

@@ -1,17 +1,14 @@
using System.Text.Json;
using System.Reflection;
using System.Runtime.Serialization;
using CounterStrikeSharp.API.Modules.Config;
using Tomlyn;
namespace CounterStrikeSharp.API.Modules.Extensions;
public static class PluginConfigExtensions
{
private static readonly JsonSerializerOptions _jsonSerializerOptions = new()
{
WriteIndented = true,
ReadCommentHandling = JsonCommentHandling.Skip
};
public static JsonSerializerOptions JsonSerializerOptions => _jsonSerializerOptions;
public static JsonSerializerOptions JsonSerializerOptions => ConfigManager.JsonSerializerOptions;
/// <summary>
/// Gets the configuration file path
@@ -21,7 +18,24 @@ public static class PluginConfigExtensions
public static string GetConfigPath<T>(this T _) where T : BasePluginConfig, new()
{
string assemblyName = typeof(T).Assembly.GetName().Name ?? string.Empty;
return Path.Combine(Server.GameDirectory, "csgo", "addons", "counterstrikesharp", "configs", "plugins", assemblyName, $"{assemblyName}.json");
string[] configFilePaths =
[
Path.Combine(Server.GameDirectory, "csgo", "addons", "counterstrikesharp", "configs", "plugins", assemblyName,
$"{assemblyName}.json"),
Path.Combine(Server.GameDirectory, "csgo", "addons", "counterstrikesharp", "configs", "plugins", assemblyName,
$"{assemblyName}.toml"),
];
foreach (var path in configFilePaths)
{
if (File.Exists(path))
{
return path;
}
}
return configFilePaths[0];
}
/// <summary>
@@ -37,7 +51,22 @@ public static class PluginConfigExtensions
{
using var stream = new FileStream(configPath, FileMode.Create, FileAccess.Write, FileShare.None);
using var writer = new StreamWriter(stream);
writer.Write(JsonSerializer.Serialize(config, JsonSerializerOptions));
switch (Path.GetExtension(configPath))
{
case ".json":
{
writer.Write(JsonSerializer.Serialize(config, ConfigManager.JsonSerializerOptions));
break;
}
case ".toml":
writer.Write(Toml.FromModel(config, ConfigManager.TomlModelOptions));
break;
default:
throw new NotSupportedException($"Configuration file type '{Path.GetExtension(configPath)}' is not supported.");
}
}
catch (Exception ex)
{
@@ -63,8 +92,22 @@ public static class PluginConfigExtensions
var configContent = File.ReadAllText(configPath);
var newConfig = JsonSerializer.Deserialize<T>(configContent, JsonSerializerOptions)
?? throw new JsonException($"Deserialization failed for configuration file '{configPath}'.");
T? newConfig = null;
switch (Path.GetExtension(configPath))
{
case ".json":
newConfig = JsonSerializer.Deserialize<T>(configContent, ConfigManager.JsonSerializerOptions)
?? throw new JsonException($"Deserialization failed for configuration file '{configPath}'.");
break;
case ".toml":
newConfig = Toml.ToModel<T>(configContent, options: ConfigManager.TomlModelOptions);
break;
}
if (newConfig is null)
{
throw new SerializationException($"Deserialization failed for configuration file '{configPath}'.");
}
foreach (var property in typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public))
{

View File

@@ -146,7 +146,7 @@ namespace TestPlugin
// Mirrors a chat message back to the player
RegisterEventHandler<EventPlayerChat>(((@event, _) =>
{
var player = Utilities.GetPlayerFromIndex(@event.Userid);
var player = @event.Userid;
if (player == null) return HookResult.Continue;
player.PrintToChat($"You said {@event.Text}");

View File

@@ -34,7 +34,7 @@
#include "scripting/script_engine.h"
#include "tier0/vprof.h"
#define VERSION_STRING "v" BUILD_NUMBER " @ " GITHUB_SHA
#define VERSION_STRING "v" SEMVER " @ " GITHUB_SHA
#define BUILD_TIMESTAMP __DATE__ " " __TIME__
counterstrikesharp::GlobalClass* counterstrikesharp::GlobalClass::head = nullptr;

View File

@@ -61,8 +61,8 @@ public partial class Generators
private static List<string> GameEventFiles = new List<string>()
{
"game/core/pak01_dir/resource/core.gameevents",
"game/csgo/pak01_dir/resource/game.gameevents",
"game/core/pak01_dir/resource/core.gameevents",
"game/csgo/pak01_dir/resource/mod.gameevents"
};
@@ -119,6 +119,9 @@ public partial class Generators
public static async Task GenerateGameEvents()
{
var allGameEvents = await GetGameEvents();
// Remove the player_chat event as it's manually implemented
allGameEvents.RemoveAll(e => e.Name == "player_chat");
var gameEventsString = string.Join("\n", allGameEvents.OrderBy(x => x.NamePascalCase).Select(gameEvent =>
{