├── .github
└── workflows
│ └── build.yml
├── .gitignore
├── LICENSE
├── README.md
├── TagsApi
├── ITagsApi.cs
├── TagsApi.cs
└── TagsApi.csproj
├── cs2-tags-api-test
├── cs2-tags-api-test.cs
└── cs2-tags-api-test.csproj
├── cs2-tags-example.toml
├── cs2-tags.sln
└── cs2-tags
├── cs2-tags.csproj
├── lang
├── en.json
├── pl.json
├── tr.json
└── zh-Hans.json
└── src
├── api
└── api.cs
├── config
└── config.cs
├── cs2-tag.cs
├── database
└── database.cs
├── library
└── library.cs
└── menu
└── menu.cs
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build & Publish cs2-tags
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | paths-ignore:
8 | - 'README.md'
9 | - '.github/workflows/**'
10 | - 'cs2-tags-example.toml'
11 | - 'cs2-tags-api-test/**'
12 |
13 | jobs:
14 | setup:
15 | permissions:
16 | contents: write
17 | runs-on: ubuntu-latest
18 | outputs:
19 | buildnumber: ${{ steps.buildnumber.outputs.build_number }}
20 | steps:
21 | - name: Generate build number
22 | id: buildnumber
23 | uses: onyxmueller/build-tag-number@v1
24 | with:
25 | token: ${{ secrets.GITHUB_TOKEN }}
26 |
27 | build:
28 | needs: setup
29 | runs-on: ubuntu-latest
30 | permissions:
31 | contents: write
32 | steps:
33 | - name: Prepare Environment Variables
34 | shell: bash
35 | run: |
36 | echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
37 | echo "BUILD_NUMBER=${{ needs.setup.outputs.buildnumber }}" >> $GITHUB_ENV
38 |
39 | - name: Checkout Repository
40 | uses: actions/checkout@v3
41 |
42 | - name: Setup .NET
43 | uses: actions/setup-dotnet@v3
44 | with:
45 | dotnet-version: '8.0.x'
46 |
47 | - name: Restore Dependencies
48 | run: dotnet restore
49 |
50 | - name: Build
51 | run: |
52 | dotnet build cs2-tags.sln -c Release --no-restore /p:Version=1.${{ env.BUILD_NUMBER }}
53 |
54 | - name: Create Release Artifact (ZIP) from BuildOutput
55 | run: |
56 | mkdir -p release
57 | cd BuildOutput
58 | zip -r ../cs2-tags-v1.${{ env.BUILD_NUMBER }}.zip .
59 |
60 | - name: Create GitHub Release
61 | id: create_release
62 | uses: actions/create-release@v1
63 | env:
64 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65 | with:
66 | tag_name: v1.${{ env.BUILD_NUMBER }}
67 | release_name: v1.${{ env.BUILD_NUMBER }}
68 | draft: false
69 | prerelease: false
70 | body: |
71 | ## Release Notes for v1.${{ env.BUILD_NUMBER }}
72 |
73 | ### Changes:
74 | - ${{ github.event.head_commit.message }}
75 |
76 | ### Feedback:
77 | - If you encounter any issues, please report them [here](https://github.com/${{ github.repository }}/issues).
78 |
79 | - name: Upload Release Asset
80 | uses: actions/upload-release-asset@v1
81 | env:
82 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83 | with:
84 | upload_url: ${{ steps.create_release.outputs.upload_url }}
85 | asset_path: ./cs2-tags-v1.${{ env.BUILD_NUMBER }}.zip
86 | asset_name: cs2-tags-v1.${{ env.BUILD_NUMBER }}.zip
87 | asset_content_type: application/zip
88 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vs/
2 | **/obj
3 | **/bin
4 | .idea/
5 |
6 | # Ignore everything in BuildOutput directory
7 | BuildOutput/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # cs2-tags
2 |
3 | A tag plugin designed to enhance your CS2 experience with a dynamic tagging system. Customise and manage player tags effortlessly for a more interactive and engaging game environment.
4 |
5 | If you want to donate or need a help about plugin, you can contact me in discord private/server
6 |
7 | Discord nickname: schwarper
8 |
9 | Discord link : [Discord server](https://discord.gg/4zQfUzjk36)
10 |
11 | ## Credits
12 |
13 | [Hextags plugin for CSGO](https://github.com/Hexer10/HexTags)
14 |
15 | [@daffyyyy](https://github.com/daffyyyy/)
16 |
17 | [@Yarukon](https://github.com/Yarukon)
18 |
19 | ## Colors
20 | **Please do not use Default, use White instead**.
21 | ```
22 | White
23 | TeamColor
24 | DarkRed
25 | Green
26 | LightYellow
27 | LightBlue
28 | Olive
29 | Lime
30 | Red
31 | LightPurple
32 | Purple
33 | Grey
34 | Yellow
35 | Gold
36 | Silver
37 | Blue
38 | DarkBlue
39 | BlueGrey
40 | Magenta
41 | LightRed
42 | Orange
43 | ```
44 |
45 | ## Screenshots
46 | 
47 |
48 | 
49 |
--------------------------------------------------------------------------------
/TagsApi/ITagsApi.cs:
--------------------------------------------------------------------------------
1 | using CounterStrikeSharp.API.Core;
2 | using CounterStrikeSharp.API.Core.Capabilities;
3 | using static TagsApi.Tags;
4 |
5 | namespace TagsApi;
6 |
7 | public interface ITagApi
8 | {
9 | public static readonly PluginCapability Capability = new("tags:api");
10 |
11 | public event Func? OnMessageProcessPre;
12 | public event Func? OnMessageProcess;
13 | public event Action? OnMessageProcessPost;
14 | public event Action? OnTagsUpdatedPre;
15 | public event Action? OnTagsUpdatedPost;
16 |
17 | public void AddAttribute(CCSPlayerController player, TagType types, TagPrePost prePost, string newValue);
18 | public void SetAttribute(CCSPlayerController player, TagType types, string newValue);
19 | public string? GetAttribute(CCSPlayerController player, TagType type);
20 | public void ResetAttribute(CCSPlayerController player, TagType types);
21 | public bool GetPlayerChatSound(CCSPlayerController player);
22 | public void SetPlayerChatSound(CCSPlayerController controller, bool value);
23 | public bool GetPlayerVisibility(CCSPlayerController player);
24 | public void SetPlayerVisibility(CCSPlayerController player, bool value);
25 | public void ReloadTags();
26 |
27 | void SetExternalTag(CCSPlayerController player, TagType types, string newValue, bool persistent = true);
28 | void SetPlayerTagExternal(CCSPlayerController player, bool isExternal);
29 | bool IsPlayerTagExternal(CCSPlayerController player);
30 | void ClearExternalTag(CCSPlayerController player, bool resetToDefaultPermission = true);
31 | }
--------------------------------------------------------------------------------
/TagsApi/TagsApi.cs:
--------------------------------------------------------------------------------
1 | using CounterStrikeSharp.API.Core;
2 |
3 | namespace TagsApi;
4 |
5 | public abstract class Tags
6 | {
7 | public class Tag
8 | {
9 | public string? Role { get; set; }
10 | public string? ScoreTag { get; set; }
11 | public string? ChatTag { get; set; }
12 | public string? ChatColor { get; set; }
13 | public string? NameColor { get; set; }
14 | public bool Visibility { get; set; } = true;
15 | public bool ChatSound { get; set; } = true;
16 | public bool IsExternal { get; set; } = false;
17 |
18 | public Tag Clone()
19 | {
20 | return new Tag
21 | {
22 | ScoreTag = ScoreTag,
23 | ChatTag = ChatTag,
24 | ChatColor = ChatColor,
25 | NameColor = NameColor,
26 | Visibility = Visibility,
27 | ChatSound = ChatSound,
28 | IsExternal = IsExternal
29 | };
30 | }
31 | }
32 |
33 | public class MessageProcess
34 | {
35 | public required CCSPlayerController Player { get; set; }
36 | public required Tag Tag { get; set; }
37 | public string PlayerName { get; set; } = string.Empty;
38 | public string Message { get; set; } = string.Empty;
39 | public bool ChatSound { get; set; } = true;
40 | public bool TeamMessage { get; set; } = false;
41 | }
42 |
43 | [Flags]
44 | public enum TagType
45 | {
46 | None = 0,
47 | ScoreTag = 1 << 0,
48 | ChatTag = 1 << 1,
49 | NameColor = 1 << 2,
50 | ChatColor = 1 << 3
51 | }
52 |
53 | public enum TagPrePost
54 | {
55 | Pre,
56 | Post
57 | }
58 | }
--------------------------------------------------------------------------------
/TagsApi/TagsApi.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | enable
6 | enable
7 | $(ProjectDir)..\BuildOutput\shared\TagsApi\
8 | false
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/cs2-tags-api-test/cs2-tags-api-test.cs:
--------------------------------------------------------------------------------
1 | using CounterStrikeSharp.API.Core;
2 | using CounterStrikeSharp.API.Core.Attributes.Registration;
3 | using CounterStrikeSharp.API.Modules.Commands;
4 | using TagsApi;
5 | using static TagsApi.Tags;
6 |
7 | namespace TagsApiTest;
8 |
9 | public class TagsApiTest : BasePlugin
10 | {
11 | public override string ModuleName => "Tags Api Test";
12 | public override string ModuleVersion => "1.1";
13 | public override string ModuleAuthor => "schwarper";
14 |
15 | public ITagApi tagApi = null!;
16 |
17 | public override void OnAllPluginsLoaded(bool hotReload)
18 | {
19 | tagApi = ITagApi.Capability.Get() ?? throw new Exception("Tags Api not found!");
20 | }
21 |
22 | [ConsoleCommand("css_testgettag")]
23 | public void Command_TestGetTag(CCSPlayerController? player, CommandInfo info)
24 | {
25 | if (player == null) return;
26 |
27 | info.ReplyToCommand(@$"
28 | ScoreTag => {tagApi.GetAttribute(player, TagType.ScoreTag)},
29 | ChatTag => {tagApi.GetAttribute(player, TagType.ChatTag)},
30 | ChatColor => {tagApi.GetAttribute(player, TagType.ChatColor)},
31 | NameColor => {tagApi.GetAttribute(player, TagType.NameColor)},
32 | ChatSound => {tagApi.GetPlayerChatSound(player)},
33 | Visibility => {tagApi.GetPlayerVisibility(player)}
34 | ");
35 | }
36 |
37 | [ConsoleCommand("css_testsettag")]
38 | public void Command_TestSetTag(CCSPlayerController? player, CommandInfo info)
39 | {
40 | if (player == null) return;
41 |
42 | tagApi.SetAttribute(player, TagType.ScoreTag | TagType.ChatTag, "[Test]");
43 | tagApi.SetAttribute(player, TagType.ChatColor, "{red}");
44 | tagApi.SetAttribute(player, TagType.NameColor, "{blue}");
45 | tagApi.SetPlayerChatSound(player, false);
46 |
47 | tagApi.AddAttribute(player, TagType.ScoreTag, TagPrePost.Pre, "[Test3]");
48 | tagApi.AddAttribute(player, TagType.ChatTag, TagPrePost.Post, "[Test4]");
49 |
50 | info.ReplyToCommand("Tags set!");
51 | }
52 |
53 | [ConsoleCommand("css_testresettag")]
54 | public void Command_TestResetTag(CCSPlayerController? player, CommandInfo info)
55 | {
56 | if (player == null) return;
57 |
58 | tagApi.ResetAttribute(player, TagType.ScoreTag | TagType.ChatTag | TagType.ChatColor | TagType.NameColor);
59 | info.ReplyToCommand("Tags reset!");
60 | }
61 |
62 | [ConsoleCommand("css_testvisibility")]
63 | public void Command_TestVisibility(CCSPlayerController? player, CommandInfo info)
64 | {
65 | if (player == null) return;
66 |
67 | bool currentVisibility = tagApi.GetPlayerVisibility(player);
68 | tagApi.SetPlayerVisibility(player, !currentVisibility);
69 |
70 | info.ReplyToCommand($"Tags are now {(currentVisibility ? "hidden" : "visible")}");
71 | }
72 |
73 | [ConsoleCommand("css_testreloadtags")]
74 | public void Command_TestReloadTags(CCSPlayerController? player, CommandInfo info)
75 | {
76 | tagApi.ReloadTags();
77 | info.ReplyToCommand("Tags reloaded!");
78 | }
79 |
80 | [ConsoleCommand("css_testmessageprocesspre")]
81 | public void Command_TestMessageProcessPre(CCSPlayerController? player, CommandInfo info)
82 | {
83 | tagApi!.OnMessageProcessPre += (messageProcess) =>
84 | {
85 | Console.WriteLine($@"
86 | OnMessageProcessPre
87 | Player => {messageProcess.Player.PlayerName},
88 | Message => {messageProcess.Message},
89 | PlayerName => {messageProcess.PlayerName},
90 | ChatSound => {messageProcess.ChatSound},
91 | TeamMessage => {messageProcess.TeamMessage}
92 | ");
93 | return HookResult.Continue;
94 | };
95 |
96 | tagApi!.OnMessageProcess += (messageProcess) =>
97 | {
98 | messageProcess.PlayerName = "{red}" + $"[OMP] {messageProcess.PlayerName}";
99 | Console.WriteLine($@"
100 | OnMessageProcess
101 | Player => {messageProcess.Player.PlayerName},
102 | Message => {messageProcess.Message},
103 | PlayerName => {messageProcess.PlayerName},
104 | ChatSound => {messageProcess.ChatSound},
105 | TeamMessage => {messageProcess.TeamMessage}
106 | ");
107 | return HookResult.Continue;
108 | };
109 |
110 | tagApi!.OnMessageProcessPost += (messageProcess) =>
111 | {
112 | Console.WriteLine($@"
113 | OnMessageProcessPost
114 | Player => {messageProcess.Player.PlayerName},
115 | Message => {messageProcess.Message},
116 | PlayerName => {messageProcess.PlayerName},
117 | ChatSound => {messageProcess.ChatSound},
118 | TeamMessage => {messageProcess.TeamMessage}
119 | ");
120 | };
121 |
122 | tagApi!.OnTagsUpdatedPre += (controller, tag) =>
123 | {
124 | info.ReplyToCommand($@"
125 | OnTagsUpdatedPre
126 | Player => {controller.PlayerName},
127 | ScoreTag => {tag.ScoreTag},
128 | ChatTag => {tag.ChatTag},
129 | ChatColor => {tag.ChatColor},
130 | NameColor => {tag.NameColor},
131 | ");
132 | };
133 |
134 | tagApi!.OnTagsUpdatedPost += (controller, tag) =>
135 | {
136 | info.ReplyToCommand($@"
137 | OnTagsUpdatedPost
138 | Player => {controller.PlayerName},
139 | ScoreTag => {tag.ScoreTag},
140 | ChatTag => {tag.ChatTag},
141 | ChatColor => {tag.ChatColor},
142 | NameColor => {tag.NameColor},
143 | ");
144 | };
145 | }
146 | }
--------------------------------------------------------------------------------
/cs2-tags-api-test/cs2-tags-api-test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | enable
6 | enable
7 | false
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/cs2-tags-example.toml:
--------------------------------------------------------------------------------
1 | [Settings]
2 | Tag = "{red}[CSS] "
3 | MenuType = "CenterHtmlMenu" # Supported MenuTypes => ConsoleMenu, ChatMenu, CenterHtmlMenu, WasdMenu, ScreenMenu
4 | DeadName = "☠"
5 | NoneName = "{White}(NONE)"
6 | SpecName = "{Purple}(SPEC)"
7 | TName = "{Yellow}(T)"
8 | CTName = "{Blue}(CT)"
9 |
10 | [DatabaseConnection]
11 | MySQL = true
12 | Host = ""
13 | Port = 3306
14 | User = ""
15 | Password = ""
16 | Name = ""
17 |
18 | [Commands]
19 | TagsReload = [ "css_tags_reload" ]
20 | Visibility = [ "css_toggletags", "css_visibility" ]
21 | TagsMenu = [ "css_tags" ]
22 |
23 | [Default]
24 | ScoreTag = ""
25 | ChatTag = "{Grey}[Player]"
26 | ChatColor = "{White}"
27 | NameColor = "{TeamColor}"
28 | ChatSound = true
29 |
30 | [[Tags]]
31 | Role = "76561199165718810"
32 | ScoreTag = ""
33 | ChatTag = "{Red}[schwarper] "
34 | ChatColor = "{green}"
35 | NameColor = "{TeamColor}"
36 | ChatSound = false
37 |
38 | [[Tags]]
39 | Role = "#OWNER"
40 | ScoreTag = ""
41 | ChatTag = "{Red}[OWNER] "
42 | ChatColor = "{green}"
43 | NameColor = "{TeamColor}"
--------------------------------------------------------------------------------
/cs2-tags.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.13.35825.156 d17.13
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "cs2-tags", "cs2-tags\cs2-tags.csproj", "{8F7EF308-8867-4802-B12F-5E27A2AF9995}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TagsApi", "TagsApi\TagsApi.csproj", "{A4E0FE20-CD3C-4E3D-95CE-AE48F7A77DF7}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cs2-tags-api-test", "cs2-tags-api-test\cs2-tags-api-test.csproj", "{C5D0F7AE-D2E4-EC93-ABCC-3511E1A97C36}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {8F7EF308-8867-4802-B12F-5E27A2AF9995}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {8F7EF308-8867-4802-B12F-5E27A2AF9995}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {8F7EF308-8867-4802-B12F-5E27A2AF9995}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {8F7EF308-8867-4802-B12F-5E27A2AF9995}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {A4E0FE20-CD3C-4E3D-95CE-AE48F7A77DF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {A4E0FE20-CD3C-4E3D-95CE-AE48F7A77DF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {A4E0FE20-CD3C-4E3D-95CE-AE48F7A77DF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {A4E0FE20-CD3C-4E3D-95CE-AE48F7A77DF7}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {C5D0F7AE-D2E4-EC93-ABCC-3511E1A97C36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {C5D0F7AE-D2E4-EC93-ABCC-3511E1A97C36}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {C5D0F7AE-D2E4-EC93-ABCC-3511E1A97C36}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {C5D0F7AE-D2E4-EC93-ABCC-3511E1A97C36}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {9061A6F9-8330-43EE-A1A0-6DBC08696E5D}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/cs2-tags/cs2-tags.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net8.0
4 | enable
5 | enable
6 | $(ProjectDir)..\BuildOutput\plugins\cs2-tags\
7 | false
8 | true
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/cs2-tags/lang/en.json:
--------------------------------------------------------------------------------
1 | {
2 | "Tags are now visible": "{white}Tags are now visible.",
3 | "Tags are now hidden": "{white}Tags are now hidden",
4 |
5 | "Main Menu": "Tags Main Menu",
6 | "Score Tag": "Score Tag",
7 | "Chat Tag": "Chat Tag",
8 | "Chat Color": "Chat Color",
9 | "Name Color": "Name Color",
10 | "Visibility": "Visibility",
11 | "Selection": "Selection",
12 | "Current": "Current: ",
13 | "Modify": "Modify: ",
14 | "Selected": "Selected: ",
15 | "Select": "Select",
16 | "Selected option": "{white}You have selected {green}{0} {white}as {blue}{1}"
17 | }
--------------------------------------------------------------------------------
/cs2-tags/lang/pl.json:
--------------------------------------------------------------------------------
1 | {
2 | "Tags are now visible": "{white}Tagi są teraz widoczne.",
3 | "Tags are now hidden": "{white}Tagi są teraz ukryte",
4 |
5 | "Main Menu": "Menu Tagów",
6 | "Score Tag": "Tag w tabeli",
7 | "Chat Tag": "Tag na czat",
8 | "Chat Color": "Kolor wiadomości",
9 | "Name Color": "Kolor nicku",
10 | "Visibility": "Widoczność",
11 | "Selection": "Wybór",
12 | "Current": "Obecny: ",
13 | "Modify": "Zmień: ",
14 | "Selected": "Wybrano: ",
15 | "Select": "Wybierz",
16 | "Selected option": "{white}Wybrałeś {green}{0} {white}jako {blue}{1}"
17 | }
18 |
--------------------------------------------------------------------------------
/cs2-tags/lang/tr.json:
--------------------------------------------------------------------------------
1 | {
2 | "Tags are now visible": "{white}Etiketleriniz artık görünür.",
3 | "Tags are now hidden": "{white}Etiketleriniz artık gizli.",
4 |
5 | "Main Menu": "Taglar Ana Menü",
6 | "Score Tag": "Skorbord Etiketi",
7 | "Chat Tag": "Sohbet Etiketi",
8 | "Chat Color": "Sohbet Rengi",
9 | "Name Color": "İsim Rengi",
10 | "Visibility": "Görünürlük",
11 | "Selection": "Seçim",
12 | "Current": "Şuanki: ",
13 | "Modify": "Değiştir: ",
14 | "Selected": "Seçilen: ",
15 | "Select": "Seç",
16 | "Selected option": "{green}{0}ni {blue}{1} {white}olarak seçtin."
17 | }
--------------------------------------------------------------------------------
/cs2-tags/lang/zh-Hans.json:
--------------------------------------------------------------------------------
1 | {
2 | "Tags are now visible": "{white}标签显示{green}已开启",
3 | "Tags are now hidden": "{white}标签显示{red}已关闭",
4 |
5 | "Main Menu": "标签菜单",
6 | "Score Tag": "计分板标签",
7 | "Chat Tag": "聊天标签",
8 | "Chat Color": "聊天颜色",
9 | "Name Color": "名字颜色",
10 | "Visibility": "标签显示",
11 | "Selection": "标签选项",
12 | "Current": "当前显示: ",
13 | "Modify": "自定义: ",
14 | "Selected": "已选择: ",
15 | "Select": "选择",
16 | "Selected option": "{white}你选择了{green}{0}{white}作为{blue}{1}"
17 | }
--------------------------------------------------------------------------------
/cs2-tags/src/api/api.cs:
--------------------------------------------------------------------------------
1 | // Modified TagsAPI with recursion protection
2 | using CounterStrikeSharp.API.Core;
3 | using CounterStrikeSharp.API.Modules.Extensions;
4 | using TagsApi;
5 | using static Tags.Tags;
6 | using static TagsApi.Tags;
7 |
8 | namespace Tags;
9 |
10 | public class TagsAPI : ITagApi
11 | {
12 | private bool _isProcessingTagsUpdatedPre = false;
13 | private bool _isProcessingTagsUpdatedPost = false;
14 | private bool _isProcessingMessagePre = false;
15 | private bool _isProcessingMessage = false;
16 | private bool _isProcessingMessagePost = false;
17 |
18 | public event Func? OnMessageProcessPre;
19 | public event Func? OnMessageProcess;
20 | public event Action? OnMessageProcessPost;
21 | public event Action? OnTagsUpdatedPre;
22 | public event Action? OnTagsUpdatedPost;
23 |
24 | public HookResult MessageProcessPre(MessageProcess messageProcess)
25 | {
26 | if (_isProcessingMessagePre)
27 | return HookResult.Continue;
28 |
29 | try
30 | {
31 | _isProcessingMessagePre = true;
32 | return OnMessageProcessPre?.Invoke(messageProcess) ?? HookResult.Continue;
33 | }
34 | finally
35 | {
36 | _isProcessingMessagePre = false;
37 | }
38 | }
39 |
40 | public HookResult MessageProcess(MessageProcess messageProcess)
41 | {
42 | if (_isProcessingMessage)
43 | return HookResult.Continue;
44 |
45 | try
46 | {
47 | _isProcessingMessage = true;
48 | return OnMessageProcess?.Invoke(messageProcess) ?? HookResult.Continue;
49 | }
50 | finally
51 | {
52 | _isProcessingMessage = false;
53 | }
54 | }
55 |
56 | public void MessageProcessPost(MessageProcess messageProcess)
57 | {
58 | if (_isProcessingMessagePost)
59 | return;
60 |
61 | try
62 | {
63 | _isProcessingMessagePost = true;
64 | OnMessageProcessPost?.Invoke(messageProcess);
65 | }
66 | finally
67 | {
68 | _isProcessingMessagePost = false;
69 | }
70 | }
71 |
72 | public void TagsUpdatedPre(CCSPlayerController player, Tag tag)
73 | {
74 |
75 | if (_isProcessingTagsUpdatedPre)
76 | return;
77 |
78 | try
79 | {
80 | _isProcessingTagsUpdatedPre = true;
81 | OnTagsUpdatedPre?.Invoke(player, tag);
82 | }
83 | finally
84 | {
85 | _isProcessingTagsUpdatedPre = false;
86 | }
87 | }
88 |
89 | public void TagsUpdatedPost(CCSPlayerController player, Tag tag)
90 | {
91 | if (_isProcessingTagsUpdatedPost)
92 | return;
93 |
94 | try
95 | {
96 | _isProcessingTagsUpdatedPost = true;
97 | OnTagsUpdatedPost?.Invoke(player, tag);
98 | }
99 | finally
100 | {
101 | _isProcessingTagsUpdatedPost = false;
102 | }
103 | }
104 |
105 | public void AddAttribute(CCSPlayerController player, TagType types, TagPrePost prePost, string newValue)
106 | {
107 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
108 | {
109 | playerData = player.GetTag();
110 | PlayerTagsList[player.SteamID] = playerData;
111 | }
112 |
113 | if ((types & TagType.ScoreTag) != 0)
114 | {
115 | string value = GetPrePostValue(prePost, playerData.ScoreTag, newValue);
116 | playerData.ScoreTag = value;
117 | player.SetScoreTag(value);
118 | }
119 | if ((types & TagType.ChatTag) != 0)
120 | {
121 | string value = GetPrePostValue(prePost, playerData.ChatTag, newValue);
122 | playerData.ChatTag = value;
123 | }
124 | if ((types & TagType.NameColor) != 0)
125 | {
126 | string value = GetPrePostValue(prePost, playerData.NameColor, newValue);
127 | playerData.NameColor = value;
128 | }
129 | if ((types & TagType.ChatColor) != 0)
130 | {
131 | string value = GetPrePostValue(prePost, playerData.ChatColor, newValue);
132 | playerData.ChatColor = value;
133 | }
134 | }
135 |
136 | private static string GetPrePostValue(TagPrePost prePost, string? oldValue, string newValue)
137 | {
138 | return prePost switch
139 | {
140 | TagPrePost.Pre => newValue + oldValue,
141 | TagPrePost.Post => oldValue + newValue,
142 | _ => newValue
143 | };
144 | }
145 |
146 | public void SetAttribute(CCSPlayerController player, TagType types, string newValue)
147 | {
148 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
149 | {
150 | playerData = player.GetTag();
151 | PlayerTagsList[player.SteamID] = playerData;
152 | }
153 |
154 | if ((types & TagType.ScoreTag) != 0)
155 | {
156 | playerData.ScoreTag = newValue;
157 | player.SetScoreTag(newValue);
158 | }
159 | if ((types & TagType.ChatTag) != 0)
160 | {
161 | playerData.ChatTag = newValue;
162 | }
163 | if ((types & TagType.NameColor) != 0)
164 | {
165 | playerData.NameColor = newValue;
166 | }
167 | if ((types & TagType.ChatColor) != 0)
168 | {
169 | playerData.ChatColor = newValue;
170 | }
171 | }
172 |
173 | public string? GetAttribute(CCSPlayerController player, TagType type)
174 | {
175 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
176 | {
177 | playerData = player.GetTag();
178 | PlayerTagsList[player.SteamID] = playerData;
179 | }
180 |
181 | return type switch
182 | {
183 | TagType.ScoreTag => playerData.ScoreTag,
184 | TagType.ChatTag => playerData.ChatTag,
185 | TagType.NameColor => playerData.NameColor,
186 | TagType.ChatColor => playerData.ChatColor,
187 | _ => null
188 | };
189 | }
190 |
191 | public void ResetAttribute(CCSPlayerController player, TagType types)
192 | {
193 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
194 | {
195 | playerData = player.GetTag();
196 | PlayerTagsList[player.SteamID] = playerData;
197 | return;
198 | }
199 |
200 | Tag defaultTag = player.GetTag();
201 |
202 | if ((types & TagType.ScoreTag) != 0)
203 | {
204 | playerData.ScoreTag = defaultTag.ScoreTag;
205 | player.SetScoreTag(defaultTag.ScoreTag);
206 | }
207 | if ((types & TagType.ChatTag) != 0)
208 | {
209 | playerData.ChatTag = defaultTag.ChatTag;
210 | }
211 | if ((types & TagType.NameColor) != 0)
212 | {
213 | playerData.NameColor = defaultTag.NameColor;
214 | }
215 | if ((types & TagType.ChatColor) != 0)
216 | {
217 | playerData.ChatColor = defaultTag.ChatColor;
218 | }
219 | }
220 |
221 | public bool GetPlayerChatSound(CCSPlayerController player)
222 | {
223 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
224 | {
225 | playerData = player.GetTag();
226 | PlayerTagsList[player.SteamID] = playerData;
227 | }
228 | return playerData.ChatSound;
229 | }
230 |
231 | public void SetPlayerChatSound(CCSPlayerController player, bool value)
232 | {
233 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
234 | {
235 | playerData = player.GetTag();
236 | PlayerTagsList[player.SteamID] = playerData;
237 | }
238 | playerData.ChatSound = value;
239 | }
240 |
241 | public bool GetPlayerVisibility(CCSPlayerController player)
242 | {
243 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
244 | {
245 | playerData = player.GetTag();
246 | PlayerTagsList[player.SteamID] = playerData;
247 | }
248 | return playerData.Visibility;
249 | }
250 |
251 | public void SetPlayerVisibility(CCSPlayerController player, bool value)
252 | {
253 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
254 | {
255 | playerData = player.GetTag();
256 | PlayerTagsList[player.SteamID] = playerData;
257 | }
258 | playerData.Visibility = value;
259 | player.SetScoreTag(value ? playerData.ScoreTag : Instance.Config.Default.ScoreTag);
260 | }
261 |
262 | public void ReloadTags()
263 | {
264 | Instance.Config.Reload();
265 | UpdateConfig(Instance.Config, true);
266 | }
267 |
268 | public void SetExternalTag(CCSPlayerController player, TagType types, string newValue, bool persistent = true)
269 | {
270 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
271 | {
272 | playerData = player.GetTag();
273 | PlayerTagsList[player.SteamID] = playerData;
274 | }
275 |
276 | playerData.IsExternal = true;
277 |
278 | if ((types & TagType.ScoreTag) != 0)
279 | {
280 | playerData.ScoreTag = newValue;
281 | player.SetScoreTag(newValue);
282 | }
283 | if ((types & TagType.ChatTag) != 0)
284 | {
285 | playerData.ChatTag = newValue;
286 | }
287 | if ((types & TagType.NameColor) != 0)
288 | {
289 | playerData.NameColor = newValue;
290 | }
291 | if ((types & TagType.ChatColor) != 0)
292 | {
293 | playerData.ChatColor = newValue;
294 | }
295 |
296 | if (persistent)
297 | {
298 | Database.SavePlayer(player);
299 | }
300 | }
301 |
302 | public void SetPlayerTagExternal(CCSPlayerController player, bool isExternal)
303 | {
304 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
305 | {
306 | playerData = player.GetTag();
307 | PlayerTagsList[player.SteamID] = playerData;
308 | }
309 |
310 | playerData.IsExternal = isExternal;
311 |
312 | Database.SavePlayer(player);
313 | }
314 |
315 | public bool IsPlayerTagExternal(CCSPlayerController player)
316 | {
317 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
318 | {
319 | return false;
320 | }
321 |
322 | return playerData.IsExternal;
323 | }
324 |
325 | public void ClearExternalTag(CCSPlayerController player, bool resetToDefaultPermission = true)
326 | {
327 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
328 | {
329 | playerData = player.GetTag();
330 | PlayerTagsList[player.SteamID] = playerData;
331 | }
332 |
333 | playerData.IsExternal = false;
334 |
335 | if (resetToDefaultPermission)
336 | {
337 | Tag permissionTag = player.GetTag();
338 |
339 | permissionTag.Visibility = playerData.Visibility;
340 | permissionTag.ChatSound = playerData.ChatSound;
341 | permissionTag.IsExternal = false;
342 |
343 | PlayerTagsList[player.SteamID] = permissionTag;
344 | player.SetScoreTag(permissionTag.ScoreTag);
345 | }
346 |
347 | Database.SavePlayer(player);
348 | }
349 | }
--------------------------------------------------------------------------------
/cs2-tags/src/config/config.cs:
--------------------------------------------------------------------------------
1 | using CounterStrikeSharp.API.Core;
2 | using CounterStrikeSharp.API.Modules.Utils;
3 | using static TagsApi.Tags;
4 |
5 | namespace Tags;
6 |
7 | public class Config : BasePluginConfig
8 | {
9 | public class Config_Settings
10 | {
11 | public string Tag { get; set; } = string.Empty;
12 | public string MenuType { get; set; } = "ScreenMenu";
13 | public string DeadName { get; set; } = string.Empty;
14 | public string NoneName { get; set; } = string.Empty;
15 | public string SpecName { get; set; } = string.Empty;
16 | public string TName { get; set; } = string.Empty;
17 | public string CTName { get; set; } = string.Empty;
18 | public Dictionary TeamNames = [];
19 | }
20 | public class Config_DatabaseConnection
21 | {
22 | public bool MySQL { get; set; } = true;
23 | public string Host { get; set; } = string.Empty;
24 | public uint Port { get; set; } = 3306;
25 | public string User { get; set; } = string.Empty;
26 | public string Password { get; set; } = string.Empty;
27 | public string Name { get; set; } = string.Empty;
28 | }
29 | public class Config_Commands
30 | {
31 | public string[] TagsReload { get; set; } = [];
32 | public string[] Visibility { get; set; } = [];
33 | public string[] TagsMenu { get; set; } = [];
34 | }
35 |
36 | public Config_Settings Settings { get; set; } = new();
37 | public Config_DatabaseConnection DatabaseConnection { get; set; } = new();
38 | public Config_Commands Commands { get; set; } = new();
39 | public Tag Default { get; set; } = new();
40 | public List Tags { get; set; } = [];
41 | }
--------------------------------------------------------------------------------
/cs2-tags/src/cs2-tag.cs:
--------------------------------------------------------------------------------
1 | using CounterStrikeSharp.API;
2 | using CounterStrikeSharp.API.Core;
3 | using CounterStrikeSharp.API.Core.Attributes.Registration;
4 | using CounterStrikeSharp.API.Core.Capabilities;
5 | using CounterStrikeSharp.API.Core.Translations;
6 | using CounterStrikeSharp.API.Modules.Admin;
7 | using CounterStrikeSharp.API.Modules.Commands;
8 | using CounterStrikeSharp.API.Modules.Extensions;
9 | using CounterStrikeSharp.API.Modules.UserMessages;
10 | using CounterStrikeSharp.API.Modules.Utils;
11 | using TagsApi;
12 | using static Tags.Menu;
13 | using static Tags.TagsLibrary;
14 | using static TagsApi.Tags;
15 |
16 | namespace Tags;
17 |
18 | public class Tags : BasePlugin, IPluginConfig
19 | {
20 | public override string ModuleName => "Tags";
21 | public override string ModuleVersion => "1.11";
22 | public override string ModuleAuthor => "schwarper";
23 |
24 | public Config Config { get; set; } = new();
25 | public static readonly Dictionary PlayerTagsList = [];
26 | public static readonly TagsAPI Api = new();
27 | public static Tags Instance { get; set; } = new();
28 |
29 | public override void Load(bool hotReload)
30 | {
31 | Instance = this;
32 | Capabilities.RegisterPluginCapability(ITagApi.Capability, () => Api);
33 | HookUserMessage(118, OnMessage, HookMode.Pre);
34 |
35 | foreach (string command in Config.Commands.TagsReload)
36 | AddCommand(command, "Tags Reload", Command_Tags_Reload);
37 |
38 | foreach (string command in Config.Commands.Visibility)
39 | AddCommand(command, "Visibility", Command_Visibility);
40 |
41 | foreach (string command in Config.Commands.TagsMenu)
42 | AddCommand(command, "Tags Menu", Command_Tags);
43 |
44 | AddCommandListener("css_admins_reload", Command_Admins_Reloads, HookMode.Pre);
45 | UpdateConfig(Config, hotReload);
46 | }
47 |
48 | public override void Unload(bool hotReload)
49 | {
50 | UnhookUserMessage(118, OnMessage, HookMode.Pre);
51 | RemoveCommandListener("css_admins_reload", Command_Admins_Reloads, HookMode.Pre);
52 |
53 | List players = Utilities.GetPlayers();
54 | foreach (CCSPlayerController player in players)
55 | {
56 | if (player.IsBot)
57 | continue;
58 |
59 | Database.SavePlayer(player);
60 | }
61 | }
62 |
63 | public void OnConfigParsed(Config config)
64 | {
65 | Config = config;
66 | }
67 |
68 | public static void UpdateConfig(Config config, bool hotReload)
69 | {
70 | if (config.DatabaseConnection.MySQL)
71 | {
72 | HashSet keys =
73 | [
74 | config.DatabaseConnection.Host,
75 | config.DatabaseConnection.Name,
76 | config.DatabaseConnection.Password,
77 | config.DatabaseConnection.User
78 | ];
79 |
80 | foreach (string key in keys)
81 | {
82 | if (string.IsNullOrEmpty(key))
83 | throw new Exception($"Database credentials are missing");
84 | }
85 | }
86 |
87 | Database.CreateDatabase(config);
88 |
89 | config.Settings.Tag = config.Settings.Tag.ReplaceColorTags();
90 |
91 | config.Settings.TeamNames[CsTeam.None] = config.Settings.NoneName.ReplaceTags(CsTeam.None);
92 | config.Settings.TeamNames[CsTeam.Spectator] = config.Settings.SpecName.ReplaceTags(CsTeam.Spectator);
93 | config.Settings.TeamNames[CsTeam.Terrorist] = config.Settings.TName.ReplaceTags(CsTeam.Terrorist);
94 | config.Settings.TeamNames[CsTeam.CounterTerrorist] = config.Settings.CTName.ReplaceTags(CsTeam.CounterTerrorist);
95 |
96 | if (hotReload)
97 | {
98 | List players = Utilities.GetPlayers();
99 | foreach (CCSPlayerController player in players)
100 | {
101 | if (player.IsBot)
102 | continue;
103 |
104 | if (!PlayerTagsList.ContainsKey(player.SteamID))
105 | {
106 | Tag defaultTag = player.GetTag();
107 | PlayerTagsList[player.SteamID] = defaultTag;
108 | }
109 |
110 | Database.LoadPlayer(player);
111 | }
112 | }
113 | }
114 |
115 | public HookResult Command_Admins_Reloads(CCSPlayerController? player, CommandInfo info)
116 | {
117 | Config.Reload();
118 | UpdateConfig(Config, true);
119 | return HookResult.Continue;
120 | }
121 |
122 | [RequiresPermissions("@css/root")]
123 | public void Command_Tags_Reload(CCSPlayerController? player, CommandInfo info)
124 | {
125 | Config.Reload();
126 | UpdateConfig(Config, true);
127 | }
128 |
129 | [RequiresPermissions("@css/admin")]
130 | [CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
131 | public void Command_Visibility(CCSPlayerController? player, CommandInfo info)
132 | {
133 | if (player == null)
134 | {
135 | return;
136 | }
137 |
138 | if (player.GetVisibility())
139 | {
140 | player.SetVisibility(false);
141 | info.ReplyToCommand(Config.Settings.Tag + Localizer.ForPlayer(player, "Tags are now hidden"));
142 | }
143 | else
144 | {
145 | player.SetVisibility(true);
146 | info.ReplyToCommand(Config.Settings.Tag + Localizer.ForPlayer(player, "Tags are now visible"));
147 | }
148 | }
149 |
150 | [CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
151 | public void Command_Tags(CCSPlayerController? player, CommandInfo info)
152 | {
153 | if (player == null) return;
154 |
155 | MainMenu(player).Display(player, 0);
156 | }
157 |
158 | [GameEventHandler]
159 | public HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo info)
160 | {
161 | if (@event.Userid is not CCSPlayerController player || player.IsBot)
162 | return HookResult.Continue;
163 |
164 | Database.LoadPlayer(player);
165 | return HookResult.Continue;
166 | }
167 |
168 | [GameEventHandler]
169 | public HookResult OnMapStart(EventGameStart @event, GameEventInfo info)
170 | {
171 | Task.Delay(1000).ContinueWith(_ =>
172 | {
173 | Server.NextFrame(() =>
174 | {
175 | foreach (var player in Utilities.GetPlayers())
176 | {
177 | if (player == null || !player.IsValid || player.IsBot)
178 | continue;
179 |
180 | if (PlayerTagsList.TryGetValue(player.SteamID, out Tag? tag))
181 | {
182 | Console.WriteLine($"Reapplying tags for player {player.PlayerName} (SteamID: {player.SteamID})");
183 |
184 | Tags.Api.TagsUpdatedPre(player, tag);
185 | if (tag.Visibility)
186 | {
187 | player.SetScoreTag(tag.ScoreTag);
188 | }
189 | Tags.Api.TagsUpdatedPost(player, tag);
190 | }
191 | }
192 | });
193 | });
194 | return HookResult.Continue;
195 | }
196 |
197 | [GameEventHandler]
198 | public HookResult OnMapEnd(EventGameEnd @event, GameEventInfo info)
199 | {
200 | foreach (var player in Utilities.GetPlayers())
201 | {
202 | if (player == null || !player.IsValid || player.IsBot)
203 | continue;
204 |
205 | Database.SavePlayer(player);
206 | }
207 | return HookResult.Continue;
208 | }
209 |
210 |
211 |
212 | [GameEventHandler(HookMode.Pre)]
213 | public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
214 | {
215 | if (@event.Userid is not CCSPlayerController player || player.IsBot)
216 | return HookResult.Continue;
217 |
218 | Database.SavePlayer(player);
219 | return HookResult.Continue;
220 | }
221 |
222 | public HookResult OnMessage(UserMessage um)
223 | {
224 | if (Utilities.GetPlayerFromIndex(um.ReadInt("entityindex")) is not CCSPlayerController player || player.IsBot)
225 | return HookResult.Continue;
226 |
227 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? tag))
228 | {
229 | tag = player.GetTag();
230 | PlayerTagsList[player.SteamID] = tag;
231 |
232 | Database.LoadPlayer(player);
233 | }
234 |
235 | MessageProcess messageProcess = new()
236 | {
237 | Player = player,
238 | Tag = !player.GetVisibility() ? Config.Default.Clone() : tag.Clone(),
239 | Message = um.ReadString("param2").RemoveCurlyBraceContent(),
240 | PlayerName = um.ReadString("param1"),
241 | ChatSound = um.ReadBool("chat"),
242 | TeamMessage = !um.ReadString("messagename").Contains("All")
243 | };
244 |
245 | if (string.IsNullOrEmpty(messageProcess.Message))
246 | return HookResult.Handled;
247 |
248 | HookResult hookResult = Api.MessageProcessPre(messageProcess);
249 |
250 | if (hookResult >= HookResult.Handled)
251 | return hookResult;
252 |
253 | string deadname = player.PawnIsAlive ? string.Empty : Config.Settings.DeadName;
254 | string teamname = messageProcess.TeamMessage ? player.Team.Name() : string.Empty;
255 |
256 | Tag playerData = messageProcess.Tag;
257 |
258 | CsTeam team = player.Team;
259 | messageProcess.PlayerName = FormatMessage(team, deadname, teamname, playerData.ChatTag ?? string.Empty, playerData.NameColor ?? string.Empty, messageProcess.PlayerName);
260 | messageProcess.Message = FormatMessage(team, playerData.ChatColor ?? string.Empty, messageProcess.Message);
261 |
262 | hookResult = Api.MessageProcess(messageProcess);
263 |
264 | if (hookResult >= HookResult.Handled)
265 | return hookResult;
266 |
267 | um.SetString("messagename", $"{messageProcess.PlayerName}{ChatColors.White}: {messageProcess.Message}");
268 | um.SetBool("chat", playerData.ChatSound);
269 |
270 | Api.MessageProcessPost(messageProcess);
271 |
272 | return HookResult.Changed;
273 | }
274 |
275 | internal static string? GetTagValue(Tag tag, TagType type)
276 | {
277 | return type switch
278 | {
279 | TagType.ScoreTag => tag.ScoreTag,
280 | TagType.ChatTag => tag.ChatTag,
281 | TagType.ChatColor => tag.ChatColor,
282 | TagType.NameColor => tag.NameColor,
283 | _ => null
284 | };
285 | }
286 |
287 | internal static void SetPlayerTagValue(CCSPlayerController player, Tag playerData, TagType type, object value)
288 | {
289 | switch (type)
290 | {
291 | case TagType.ScoreTag:
292 | playerData.ScoreTag = (string)value;
293 | player.SetScoreTag(playerData.ScoreTag);
294 | break;
295 | case TagType.ChatTag:
296 | playerData.ChatTag = (string)value;
297 | break;
298 | case TagType.ChatColor:
299 | playerData.ChatColor = (string)value;
300 | break;
301 | case TagType.NameColor:
302 | playerData.NameColor = (string)value;
303 | break;
304 | }
305 | }
306 | }
307 |
--------------------------------------------------------------------------------
/cs2-tags/src/database/database.cs:
--------------------------------------------------------------------------------
1 | using CounterStrikeSharp.API;
2 | using CounterStrikeSharp.API.Core;
3 | using Dapper;
4 | using Microsoft.Data.Sqlite;
5 | using MySqlConnector;
6 | using System.Data.Common;
7 | using System.Reflection;
8 | using static Tags.Tags;
9 | using static TagsApi.Tags;
10 |
11 | namespace Tags;
12 |
13 | public static class Database
14 | {
15 | private static bool UseMySQL;
16 | private static string GlobalDatabaseConnectionString = string.Empty;
17 |
18 | internal static void SetDatabase(Config config)
19 | {
20 | UseMySQL = config.DatabaseConnection.MySQL;
21 |
22 | string assemblyName = Assembly.GetExecutingAssembly().GetName().Name ?? string.Empty;
23 |
24 | if (!UseMySQL)
25 | {
26 | string configDir = Path.Combine(Server.GameDirectory, "csgo", "addons", "counterstrikesharp", "configs", "plugins", assemblyName);
27 | string dbFile = Path.Combine(configDir, $"{assemblyName}.db");
28 |
29 | try
30 | {
31 | if (!Directory.Exists(configDir))
32 | {
33 | Directory.CreateDirectory(configDir);
34 | Console.WriteLine($"Created directory: {configDir}");
35 | }
36 |
37 | string testFile = Path.Combine(configDir, ".write_test");
38 | try
39 | {
40 | File.WriteAllText(testFile, "test");
41 | File.Delete(testFile);
42 | Console.WriteLine("Directory is writable");
43 | }
44 | catch (Exception ex)
45 | {
46 | Console.WriteLine($"WARNING: Directory is not writable: {ex.Message}");
47 | }
48 |
49 | if (File.Exists(dbFile))
50 | {
51 | try
52 | {
53 | FileStream fs = File.Open(dbFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
54 | fs.Close();
55 | Console.WriteLine("Database file is writable");
56 | }
57 | catch (Exception ex)
58 | {
59 | Console.WriteLine($"WARNING: Database file is not writable: {ex.Message}");
60 |
61 | try
62 | {
63 | File.SetAttributes(dbFile, File.GetAttributes(dbFile) & ~FileAttributes.ReadOnly);
64 | Console.WriteLine("Attempted to make database file writable");
65 | }
66 | catch (Exception permEx)
67 | {
68 | Console.WriteLine($"Failed to update file permissions: {permEx.Message}");
69 | }
70 | }
71 | }
72 | }
73 | catch (Exception ex)
74 | {
75 | Console.WriteLine($"Error checking/creating database directory: {ex.Message}");
76 | }
77 |
78 | GlobalDatabaseConnectionString = $"Data Source={dbFile}";
79 | }
80 | else
81 | {
82 | GlobalDatabaseConnectionString = new MySqlConnectionStringBuilder
83 | {
84 | Server = config.DatabaseConnection.Host,
85 | Database = config.DatabaseConnection.Name,
86 | UserID = config.DatabaseConnection.User,
87 | Password = config.DatabaseConnection.Password,
88 | Port = config.DatabaseConnection.Port,
89 | Pooling = true,
90 | MinimumPoolSize = 0,
91 | MaximumPoolSize = 640,
92 | ConnectionIdleTimeout = 30,
93 | AllowZeroDateTime = true
94 | }.ConnectionString;
95 | }
96 |
97 | Console.WriteLine($"Database initialized: {(UseMySQL ? "MySQL" : "SQLite")}");
98 | }
99 |
100 | public static async Task ConnectAsync()
101 | {
102 | DbConnection connection;
103 |
104 | if (UseMySQL)
105 | {
106 | connection = new MySqlConnection(GlobalDatabaseConnectionString);
107 | }
108 | else
109 | {
110 | SQLitePCL.Batteries.Init();
111 | connection = new SqliteConnection(GlobalDatabaseConnectionString);
112 | }
113 |
114 | await connection.OpenAsync();
115 | return connection;
116 | }
117 |
118 | public static void CreateDatabase(Config config)
119 | {
120 | SetDatabase(config);
121 |
122 | Task.Run(CreateDatabaseAsync);
123 | }
124 |
125 | public static async Task CreateDatabaseAsync()
126 | {
127 | try
128 | {
129 | using DbConnection connection = await ConnectAsync();
130 |
131 | if (UseMySQL)
132 | {
133 | await connection.ExecuteAsync(@"
134 | CREATE TABLE IF NOT EXISTS tags (
135 | id INT AUTO_INCREMENT PRIMARY KEY,
136 | SteamID BIGINT UNSIGNED NOT NULL,
137 | ScoreTag VARCHAR(255),
138 | ChatTag VARCHAR(255),
139 | ChatColor VARCHAR(255),
140 | NameColor VARCHAR(255),
141 | Visibility BOOLEAN NOT NULL DEFAULT TRUE
142 | );
143 | ");
144 |
145 | bool columnExists = false;
146 | try
147 | {
148 | var columns = await connection.QueryAsync(@"
149 | SELECT COLUMN_NAME
150 | FROM INFORMATION_SCHEMA.COLUMNS
151 | WHERE TABLE_NAME = 'tags' AND COLUMN_NAME = 'IsExternal'
152 | ");
153 |
154 | columnExists = columns.Any();
155 | Console.WriteLine($"Checking for IsExternal column: {(columnExists ? "exists" : "does not exist")}");
156 | }
157 | catch (Exception ex)
158 | {
159 | Console.WriteLine($"Error checking for IsExternal column: {ex.Message}");
160 | }
161 |
162 | if (!columnExists)
163 | {
164 | try
165 | {
166 | await connection.ExecuteAsync(@"
167 | ALTER TABLE tags ADD COLUMN IsExternal BOOLEAN NOT NULL DEFAULT FALSE
168 | ");
169 | Console.WriteLine("Added IsExternal column to tags table.");
170 | }
171 | catch (Exception ex)
172 | {
173 | Console.WriteLine($"Error adding IsExternal column: {ex.Message}");
174 | }
175 | }
176 | }
177 | else
178 | {
179 | await connection.ExecuteAsync(@"
180 | CREATE TABLE IF NOT EXISTS tags (
181 | id INTEGER PRIMARY KEY AUTOINCREMENT,
182 | SteamID BIGINT NOT NULL,
183 | ScoreTag TEXT,
184 | ChatTag TEXT,
185 | ChatColor TEXT,
186 | NameColor TEXT,
187 | Visibility BOOLEAN NOT NULL DEFAULT 1
188 | );
189 | ");
190 |
191 | bool columnExists = false;
192 | try
193 | {
194 | var tableInfo = await connection.QueryAsync("PRAGMA table_info(tags)");
195 |
196 | foreach (var column in tableInfo)
197 | {
198 | string name = column.name?.ToString() ?? "";
199 | if (name.Equals("IsExternal", StringComparison.OrdinalIgnoreCase))
200 | {
201 | columnExists = true;
202 | break;
203 | }
204 | }
205 | Console.WriteLine($"Checking for SQLite IsExternal column: {(columnExists ? "exists" : "does not exist")}");
206 | }
207 | catch (Exception ex)
208 | {
209 | Console.WriteLine($"Error checking SQLite column existence: {ex.Message}");
210 | }
211 |
212 | if (!columnExists)
213 | {
214 | try
215 | {
216 | await connection.ExecuteAsync(@"
217 | ALTER TABLE tags ADD COLUMN IsExternal BOOLEAN NOT NULL DEFAULT 0
218 | ");
219 | Console.WriteLine("Added IsExternal column to SQLite tags table.");
220 | }
221 | catch (Exception ex)
222 | {
223 | Console.WriteLine($"Error adding SQLite IsExternal column: {ex.Message}");
224 | }
225 | }
226 | }
227 | }
228 | catch (Exception ex)
229 | {
230 | Console.WriteLine($"Database initialization error: {ex.Message}");
231 | }
232 | }
233 |
234 | public static void LoadPlayer(CCSPlayerController player)
235 | {
236 | if (player == null || !player.IsValid)
237 | {
238 | Console.WriteLine("Attempted to load an invalid player");
239 | return;
240 | }
241 |
242 | try
243 | {
244 | ulong steamId = player.SteamID;
245 | Tag playerDefaultTag = player.GetTag();
246 | string playerName = player.PlayerName;
247 |
248 | Server.NextFrame(async () =>
249 | {
250 | try
251 | {
252 | using DbConnection connection = await ConnectAsync();
253 |
254 | Tag? result = (await connection.QueryAsync(@"
255 | SELECT * FROM tags WHERE SteamID = @SteamID;",
256 | new { SteamID = steamId }
257 | )).SingleOrDefault();
258 |
259 | if (result == null)
260 | {
261 | await InsertNewPlayerAsync(connection, steamId, playerDefaultTag);
262 |
263 | Server.NextFrame(() =>
264 | {
265 | if (player != null && player.IsValid)
266 | {
267 | PlayerTagsList[steamId] = playerDefaultTag;
268 | Tags.Api.TagsUpdatedPre(player, playerDefaultTag);
269 | player.SetScoreTag(playerDefaultTag.ScoreTag);
270 | Tags.Api.TagsUpdatedPost(player, playerDefaultTag);
271 | }
272 | });
273 | return;
274 | }
275 |
276 | Tag finalTag = new()
277 | {
278 | ScoreTag = result.ScoreTag,
279 | ChatTag = result.ChatTag,
280 | ChatColor = result.ChatColor,
281 | NameColor = result.NameColor,
282 | Visibility = result.Visibility,
283 | ChatSound = playerDefaultTag.ChatSound,
284 | IsExternal = result.IsExternal
285 | };
286 |
287 | if (result.IsExternal)
288 | {
289 | finalTag.ScoreTag = playerDefaultTag.ScoreTag;
290 | finalTag.ChatTag = playerDefaultTag.ChatTag;
291 | finalTag.ChatColor = playerDefaultTag.ChatColor;
292 | finalTag.NameColor = playerDefaultTag.NameColor;
293 | }
294 |
295 | Server.NextFrame(() =>
296 | {
297 | if (player != null && player.IsValid)
298 | {
299 | PlayerTagsList[steamId] = finalTag;
300 | if (finalTag.Visibility)
301 | {
302 | Tags.Api.TagsUpdatedPre(player, finalTag);
303 | player.SetScoreTag(finalTag.ScoreTag);
304 | Tags.Api.TagsUpdatedPost(player, finalTag);
305 | }
306 | }
307 | });
308 | }
309 | catch (Exception ex)
310 | {
311 | Console.WriteLine($"Error loading player tags (SteamID: {steamId}): {ex.Message}");
312 | }
313 | });
314 | }
315 | catch (Exception ex)
316 | {
317 | Console.WriteLine($"Error preparing to load player: {ex.Message}");
318 | }
319 | }
320 |
321 | private static async Task InsertNewPlayerAsync(DbConnection connection, ulong steamId, Tag playerData)
322 | {
323 | try
324 | {
325 | await connection.ExecuteAsync(@"
326 | INSERT INTO tags (SteamID, ScoreTag, ChatTag, ChatColor, NameColor, Visibility, IsExternal)
327 | VALUES (@SteamID, @ScoreTag, @ChatTag, @ChatColor, @NameColor, @Visibility, @IsExternal);
328 | ", new
329 | {
330 | SteamID = steamId,
331 | playerData.ScoreTag,
332 | playerData.ChatTag,
333 | playerData.ChatColor,
334 | playerData.NameColor,
335 | playerData.Visibility,
336 | playerData.IsExternal
337 | });
338 |
339 | Console.WriteLine($"Successfully inserted new player (SteamID: {steamId})");
340 | }
341 | catch (Exception ex)
342 | {
343 | Console.WriteLine($"Error inserting new player (SteamID: {steamId}): {ex.Message}");
344 | }
345 | }
346 |
347 | public static async Task InsertNewPlayer(DbConnection connection, ulong steamId, CCSPlayerController player)
348 | {
349 | try
350 | {
351 | if (player == null || !player.IsValid)
352 | {
353 | Console.WriteLine($"Player became invalid during InsertNewPlayer (SteamID: {steamId})");
354 | return;
355 | }
356 |
357 | Tag playerData = player.GetTag();
358 |
359 | playerData.IsExternal = false;
360 |
361 | PlayerTagsList[steamId] = playerData;
362 | player.SetScoreTag(playerData.ScoreTag);
363 |
364 | await connection.ExecuteAsync(@"
365 | INSERT INTO tags (SteamID, ScoreTag, ChatTag, ChatColor, NameColor, Visibility, IsExternal)
366 | VALUES (@SteamID, @ScoreTag, @ChatTag, @ChatColor, @NameColor, @Visibility, @IsExternal);
367 | ", new
368 | {
369 | SteamID = steamId,
370 | playerData.ScoreTag,
371 | playerData.ChatTag,
372 | playerData.ChatColor,
373 | playerData.NameColor,
374 | playerData.Visibility,
375 | playerData.IsExternal
376 | });
377 | }
378 | catch (Exception ex)
379 | {
380 | Console.WriteLine($"Error inserting new player (SteamID: {steamId}): {ex.Message}");
381 | }
382 | }
383 |
384 | public static void SavePlayer(CCSPlayerController player)
385 | {
386 | if (player == null || !player.IsValid)
387 | return;
388 |
389 | try
390 | {
391 | ulong steamId = player.SteamID;
392 |
393 | if (PlayerTagsList.TryGetValue(steamId, out Tag? tags))
394 | {
395 | Tag tagsCopy = new()
396 | {
397 | ScoreTag = tags.IsExternal ? null : tags.ScoreTag,
398 | ChatTag = tags.IsExternal ? null : tags.ChatTag,
399 | ChatColor = tags.IsExternal ? null : tags.ChatColor,
400 | NameColor = tags.IsExternal ? null : tags.NameColor,
401 | Visibility = tags.Visibility,
402 | ChatSound = tags.ChatSound,
403 | IsExternal = tags.IsExternal
404 | };
405 |
406 | Server.NextFrame(async () =>
407 | {
408 | try
409 | {
410 | using DbConnection connection = await ConnectAsync();
411 |
412 | await connection.ExecuteAsync(@"
413 | UPDATE tags SET
414 | ScoreTag = @ScoreTag,
415 | ChatTag = @ChatTag,
416 | ChatColor = @ChatColor,
417 | NameColor = @NameColor,
418 | Visibility = @Visibility,
419 | IsExternal = @IsExternal
420 | WHERE SteamID = @SteamID;
421 | ", new
422 | {
423 | tagsCopy.ScoreTag,
424 | tagsCopy.ChatTag,
425 | tagsCopy.ChatColor,
426 | tagsCopy.NameColor,
427 | tagsCopy.Visibility,
428 | tagsCopy.IsExternal,
429 | SteamID = steamId
430 | });
431 |
432 | Server.NextFrame(() => PlayerTagsList.Remove(steamId));
433 | }
434 | catch (Exception ex)
435 | {
436 | Console.WriteLine($"Error saving player data (SteamID: {steamId}): {ex.Message}");
437 | }
438 | });
439 | }
440 | }
441 | catch (Exception ex)
442 | {
443 | Console.WriteLine($"Error preparing to save player: {ex.Message}");
444 | }
445 | }
446 | }
--------------------------------------------------------------------------------
/cs2-tags/src/library/library.cs:
--------------------------------------------------------------------------------
1 | using CounterStrikeSharp.API;
2 | using CounterStrikeSharp.API.Core;
3 | using CounterStrikeSharp.API.Core.Translations;
4 | using CounterStrikeSharp.API.Modules.Admin;
5 | using CounterStrikeSharp.API.Modules.Entities;
6 | using CounterStrikeSharp.API.Modules.Utils;
7 | using System.Text;
8 | using System.Text.RegularExpressions;
9 | using static Tags.Tags;
10 | using static TagsApi.Tags;
11 |
12 | namespace Tags;
13 |
14 | public static partial class TagsLibrary
15 | {
16 | private static readonly Dictionary HtmlColorList = new(StringComparer.OrdinalIgnoreCase)
17 | {
18 | { "White", "#FFFFFF" },
19 | { "DarkRed", "#8B0000" },
20 | { "Green", "#008000" },
21 | { "LightYellow", "#FFFFE0" },
22 | { "LightBlue", "#ADD8E6" },
23 | { "Olive", "#808000" },
24 | { "Lime", "#00FF00" },
25 | { "Red", "#FF0000" },
26 | { "LightPurple", "#9370DB" },
27 | { "Purple", "#800080" },
28 | { "Grey", "#808080" },
29 | { "Yellow", "#FFFF00" },
30 | { "Gold", "#FFD700" },
31 | { "Silver", "#C0C0C0" },
32 | { "Blue", "#0000FF" },
33 | { "DarkBlue", "#00008B" },
34 | { "BlueGrey", "#7393B3" },
35 | { "Magenta", "#FF00FF" },
36 | { "LightRed", "#FF6347" },
37 | { "Orange", "#FFA500" }
38 | };
39 |
40 | [GeneratedRegex(@"\{.*?\}|\p{C}")]
41 | private static partial Regex MyRegex();
42 |
43 | public static string Name(this CsTeam team)
44 | {
45 | return Instance.Config.Settings.TeamNames[team];
46 | }
47 |
48 | public static string RemoveCurlyBraceContent(this string message)
49 | {
50 | return MyRegex().Replace(message, string.Empty);
51 | }
52 |
53 | public static string ReplaceTags(this string message, CsTeam team)
54 | {
55 | return message.ReplaceColorTags()
56 | .Replace("{TeamColor}", ChatColors.ForTeam(team).ToString());
57 | }
58 |
59 | public static string FormatMessage(CsTeam team, params string[] args)
60 | {
61 | return ReplaceTags(string.Concat(args), team);
62 | }
63 |
64 | public static Tag GetTag(this CCSPlayerController player)
65 | {
66 | string steamId = player.SteamID.ToString();
67 |
68 | Tag? steamIdTag = Instance.Config.Tags.FirstOrDefault(tag => steamId == tag.Role)?.Clone();
69 | if (steamIdTag != null)
70 | return steamIdTag;
71 |
72 | SteamID steamID = new(player.SteamID);
73 |
74 | List matchingGroupTags = [.. Instance.Config.Tags
75 | .Where(tag => tag.Role != null && tag.Role[0] == '#' && AdminManager.PlayerInGroup(steamID, tag.Role))
76 | .Select(tag => tag.Clone())];
77 |
78 | if (matchingGroupTags.Count > 0)
79 | return matchingGroupTags[0];
80 |
81 | List matchingPermissionTags = [.. Instance.Config.Tags
82 | .Where(tag => tag.Role != null && tag.Role[0] == '@' && AdminManager.PlayerHasPermissions(steamID, tag.Role))
83 | .Select(tag => tag.Clone())];
84 |
85 | return matchingPermissionTags.Count > 0 ? matchingPermissionTags[0] : Instance.Config.Default.Clone();
86 | }
87 |
88 | public static List GetTags(this CCSPlayerController player)
89 | {
90 | string steamId = player.SteamID.ToString();
91 | SteamID steamID = new(player.SteamID);
92 |
93 | return
94 | [
95 | Instance.Config.Default.Clone(),
96 | .. Instance.Config.Tags
97 | .Where(tag =>
98 | tag.Role == steamId ||
99 | (tag.Role ?[0] == '#' && AdminManager.PlayerInGroup(steamID, tag.Role)) ||
100 | (tag.Role ?[0] == '@' && AdminManager.PlayerHasPermissions(steamID, tag.Role))
101 | )
102 | .Select(tag => tag.Clone()),
103 | ];
104 | }
105 |
106 | public static void UpdateTag(this CCSPlayerController player, Tag tag)
107 | {
108 | PlayerTagsList[player.SteamID] = tag;
109 | player.SetScoreTag(tag.ScoreTag);
110 | Tags.Api.TagsUpdatedPost(player, tag);
111 | }
112 |
113 | private static string GetPrePostValue(TagPrePost prePost, string? oldValue, string newValue)
114 | {
115 | return prePost switch
116 | {
117 | TagPrePost.Pre => newValue + oldValue,
118 | TagPrePost.Post => oldValue + newValue,
119 | _ => newValue
120 | };
121 | }
122 |
123 | public static void AddAttribute(this CCSPlayerController player, TagType types, TagPrePost prePost, string newValue)
124 | {
125 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
126 | {
127 | playerData = player.GetTag();
128 | PlayerTagsList[player.SteamID] = playerData;
129 | }
130 |
131 | try
132 | {
133 | Tags.Api.TagsUpdatedPre(player, playerData);
134 | }
135 | catch (Exception ex)
136 | {
137 | Console.WriteLine($"Error in TagsUpdatedPre event: {ex.Message}");
138 | }
139 |
140 | if ((types & TagType.ScoreTag) != 0)
141 | {
142 | string value = GetPrePostValue(prePost, playerData.ScoreTag, newValue);
143 | playerData.ScoreTag = value;
144 | player.SetScoreTag(value);
145 | }
146 | if ((types & TagType.ChatTag) != 0)
147 | {
148 | string value = GetPrePostValue(prePost, playerData.ChatTag, newValue);
149 | playerData.ChatTag = value;
150 | }
151 | if ((types & TagType.NameColor) != 0)
152 | {
153 | string value = GetPrePostValue(prePost, playerData.NameColor, newValue);
154 | playerData.NameColor = value;
155 | }
156 | if ((types & TagType.ChatColor) != 0)
157 | {
158 | string value = GetPrePostValue(prePost, playerData.ChatColor, newValue);
159 | playerData.ChatColor = value;
160 | }
161 |
162 | try
163 | {
164 | Tags.Api.TagsUpdatedPost(player, playerData);
165 | }
166 | catch (Exception ex)
167 | {
168 | Console.WriteLine($"Error in TagsUpdatedPost event: {ex.Message}");
169 | }
170 | }
171 |
172 | public static void SetAttribute(this CCSPlayerController player, TagType types, string newValue)
173 | {
174 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
175 | {
176 | playerData = player.GetTag();
177 | PlayerTagsList[player.SteamID] = playerData;
178 | }
179 |
180 | try
181 | {
182 | Tags.Api.TagsUpdatedPre(player, playerData);
183 | }
184 | catch (Exception ex)
185 | {
186 | Console.WriteLine($"Error in TagsUpdatedPre event: {ex.Message}");
187 | }
188 |
189 | if ((types & TagType.ScoreTag) != 0)
190 | {
191 | playerData.ScoreTag = newValue;
192 | player.SetScoreTag(newValue);
193 | }
194 | if ((types & TagType.ChatTag) != 0)
195 | {
196 | playerData.ChatTag = newValue;
197 | }
198 | if ((types & TagType.NameColor) != 0)
199 | {
200 | playerData.NameColor = newValue;
201 | }
202 | if ((types & TagType.ChatColor) != 0)
203 | {
204 | playerData.ChatColor = newValue;
205 | }
206 |
207 | try
208 | {
209 | Tags.Api.TagsUpdatedPost(player, playerData);
210 | }
211 | catch (Exception ex)
212 | {
213 | Console.WriteLine($"Error in TagsUpdatedPost event: {ex.Message}");
214 | }
215 | }
216 |
217 | public static string? GetAttribute(this CCSPlayerController player, TagType type)
218 | {
219 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
220 | {
221 | playerData = player.GetTag();
222 | PlayerTagsList[player.SteamID] = playerData;
223 | }
224 |
225 | return type switch
226 | {
227 | TagType.ScoreTag => playerData.ScoreTag,
228 | TagType.ChatTag => playerData.ChatTag,
229 | TagType.NameColor => playerData.NameColor,
230 | TagType.ChatColor => playerData.ChatColor,
231 | _ => null
232 | };
233 | }
234 |
235 | public static void ResetAttribute(this CCSPlayerController player, TagType types)
236 | {
237 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
238 | {
239 | playerData = player.GetTag();
240 | PlayerTagsList[player.SteamID] = playerData;
241 | return;
242 | }
243 |
244 | try
245 | {
246 | Tags.Api.TagsUpdatedPre(player, playerData);
247 | }
248 | catch (Exception ex)
249 | {
250 | Console.WriteLine($"Error in TagsUpdatedPre event: {ex.Message}");
251 | }
252 |
253 | Tag defaultTag = GetTag(player);
254 |
255 | if ((types & TagType.ScoreTag) != 0)
256 | {
257 | playerData.ScoreTag = defaultTag.ScoreTag;
258 | player.SetScoreTag(defaultTag.ScoreTag);
259 | }
260 | if ((types & TagType.ChatTag) != 0)
261 | {
262 | playerData.ChatTag = defaultTag.ChatTag;
263 | }
264 | if ((types & TagType.NameColor) != 0)
265 | {
266 | playerData.NameColor = defaultTag.NameColor;
267 | }
268 | if ((types & TagType.ChatColor) != 0)
269 | {
270 | playerData.ChatColor = defaultTag.ChatColor;
271 | }
272 |
273 | try
274 | {
275 | Tags.Api.TagsUpdatedPost(player, playerData);
276 | }
277 | catch (Exception ex)
278 | {
279 | Console.WriteLine($"Error in TagsUpdatedPost event: {ex.Message}");
280 | }
281 | }
282 |
283 | public static bool GetChatSound(this CCSPlayerController player)
284 | {
285 | if (PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
286 | return playerData.ChatSound;
287 |
288 | Tag defaultTag = player.GetTag();
289 | PlayerTagsList[player.SteamID] = defaultTag;
290 | return defaultTag.ChatSound;
291 | }
292 |
293 | public static void SetChatSound(this CCSPlayerController player, bool value)
294 | {
295 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
296 | {
297 | playerData = player.GetTag();
298 | PlayerTagsList[player.SteamID] = playerData;
299 | }
300 |
301 | Tags.Api.TagsUpdatedPre(player, playerData);
302 | playerData.ChatSound = value;
303 | Tags.Api.TagsUpdatedPost(player, playerData);
304 | }
305 |
306 | public static bool GetVisibility(this CCSPlayerController player)
307 | {
308 | if (PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
309 | return playerData.Visibility;
310 |
311 | Tag defaultTag = player.GetTag();
312 | PlayerTagsList[player.SteamID] = defaultTag;
313 | return defaultTag.Visibility;
314 | }
315 |
316 | public static void SetVisibility(this CCSPlayerController player, bool value)
317 | {
318 | if (!PlayerTagsList.TryGetValue(player.SteamID, out Tag? playerData))
319 | {
320 | playerData = player.GetTag();
321 | PlayerTagsList[player.SteamID] = playerData;
322 | }
323 |
324 | Tags.Api.TagsUpdatedPre(player, playerData);
325 | playerData.Visibility = value;
326 | player.SetScoreTag(value ? player.GetAttribute(TagType.ScoreTag) : Instance.Config.Default.ScoreTag);
327 | Tags.Api.TagsUpdatedPost(player, playerData);
328 | }
329 |
330 | public static void SetScoreTag(this CCSPlayerController player, string? tag)
331 | {
332 | if (tag != null && player.Clan != tag)
333 | {
334 | player.Clan = tag;
335 | Utilities.SetStateChanged(player, "CCSPlayerController", "m_szClan");
336 | new EventNextlevelChanged(false).FireEventToClient(player);
337 | }
338 | }
339 |
340 | public static string ConvertToHtml(this string message, CsTeam team, bool htmlmenu)
341 | {
342 | if (!htmlmenu)
343 | return message;
344 |
345 | string modifiedValue = message.Replace("{TeamColor}", ForTeamHtml(team));
346 | StringBuilder result = new();
347 | string[] parts = modifiedValue.Split(['{', '}'], StringSplitOptions.None);
348 |
349 | for (int i = 0; i < parts.Length; i++)
350 | {
351 | if (i % 2 == 0)
352 | {
353 | result.Append(parts[i]);
354 | }
355 | else
356 | {
357 | string fieldName = parts[i];
358 | if (HtmlColorList.TryGetValue(fieldName, out string? value))
359 | {
360 | result.Append($"");
361 |
362 | if (parts.Length == 3 && string.IsNullOrEmpty(parts[0]) && string.IsNullOrEmpty(parts[2]))
363 | {
364 | result.Append(fieldName);
365 | }
366 | else
367 | {
368 | if (i + 1 < parts.Length)
369 | {
370 | result.Append(parts[i + 1]);
371 | }
372 | }
373 |
374 | result.Append("");
375 | i++;
376 | }
377 | else
378 | {
379 | result.Append($"{{{parts[i]}}}");
380 | }
381 | }
382 | }
383 | return result.ToString();
384 | }
385 |
386 | public static string ForTeamHtml(this CsTeam team)
387 | {
388 | return team switch
389 | {
390 | CsTeam.Spectator => "{LightPurple}",
391 | CsTeam.CounterTerrorist => "{LightBlue}",
392 | CsTeam.Terrorist => "{LightYellow}",
393 | _ => "{White}"
394 | };
395 | }
396 |
397 | }
--------------------------------------------------------------------------------
/cs2-tags/src/menu/menu.cs:
--------------------------------------------------------------------------------
1 | using CounterStrikeSharp.API.Core;
2 | using CounterStrikeSharp.API.Core.Translations;
3 | using CounterStrikeSharp.API.Modules.Admin;
4 | using CounterStrikeSharp.API.Modules.Entities;
5 | using CS2MenuManager.API.Class;
6 | using CS2MenuManager.API.Enum;
7 | using CS2MenuManager.API.Interface;
8 | using CS2MenuManager.API.Menu;
9 | using static Tags.Tags;
10 | using static TagsApi.Tags;
11 |
12 | namespace Tags;
13 |
14 | public static class Menu
15 | {
16 | private readonly static Type _menuType;
17 |
18 | static Menu()
19 | {
20 | _menuType = MenuManager.MenuTypesList.TryGetValue(Instance.Config.Settings.MenuType, out Type? menuType) ? menuType : typeof(CenterHtmlMenu);
21 | }
22 |
23 | public static IMenu MenuByType(string title)
24 | {
25 | return MenuManager.MenuByType(_menuType, title, Instance);
26 | }
27 |
28 | public static IMenu MainMenu(CCSPlayerController player)
29 | {
30 | Tag playerData = PlayerTagsList[player.SteamID];
31 |
32 | IMenu menu = MenuByType(Instance.Localizer.ForPlayer(player, "Main Menu"));
33 |
34 | menu.AddItem(Instance.Localizer.ForPlayer(player, "Score Tag"), (p, o) => SubMenuFirst(p, playerData, TagType.ScoreTag, o.Text).Display(p, 0));
35 | menu.AddItem(Instance.Localizer.ForPlayer(player, "Chat Tag"), (p, o) => SubMenuFirst(p, playerData, TagType.ChatTag, o.Text).Display(p, 0));
36 | menu.AddItem(Instance.Localizer.ForPlayer(player, "Chat Color"), (p, o) => SubMenuFirst(p, playerData, TagType.ChatColor, o.Text).Display(p, 0));
37 | menu.AddItem(Instance.Localizer.ForPlayer(player, "Name Color"), (p, o) => SubMenuFirst(p, playerData, TagType.NameColor, o.Text).Display(p, 0));
38 |
39 | if (AdminManager.PlayerHasPermissions(new SteamID(player.SteamID), "@css/admin"))
40 | {
41 | bool visibility = playerData.Visibility;
42 | string visibilityText = $"{Instance.Localizer.ForPlayer(player, "Visibility")} [{(visibility ? "✔️" : "❌")}]";
43 |
44 | menu.AddItem(visibilityText, (p, o) =>
45 | {
46 | player.SetVisibility(!visibility);
47 | player.PrintToChat(Instance.Config.Settings.Tag + Instance.Localizer.ForPlayer(player, visibility ? "Tags are now hidden" : "Tags are now visible"));
48 | MainMenu(p).Display(p, 0);
49 | });
50 | }
51 |
52 | return menu;
53 | }
54 |
55 | public static IMenu SubMenuFirst(CCSPlayerController player, Tag playerData, TagType type, string title)
56 | {
57 | IMenu menu = MenuByType($"{title} {Instance.Localizer.ForPlayer(player, "Selection")}");
58 |
59 | string currentValue = GetTagValue(playerData, type)?.ToString() ?? string.Empty;
60 | menu.AddItem($"{Instance.Localizer.ForPlayer(player, "Current")} {currentValue.ConvertToHtml(player.Team, _menuType == typeof(CenterHtmlMenu))}", DisableOption.DisableHideNumber);
61 |
62 | List tags = player.GetTags();
63 | HashSet tagsHash = [];
64 |
65 | foreach (Tag tag in tags)
66 | {
67 | if (GetTagValue(tag, type) is not string tagValue || string.IsNullOrEmpty(tagValue))
68 | continue;
69 |
70 | if (!tagsHash.Add(tagValue))
71 | continue;
72 |
73 | string tagValueHtml = tagValue.ConvertToHtml(player.Team, _menuType == typeof(CenterHtmlMenu));
74 | DisableOption option = tagValue == currentValue ? DisableOption.DisableHideNumber : DisableOption.None;
75 | menu.AddItem(tagValueHtml, (p, o) => SubMenuSecond(p, playerData, type, tagValue, tagValueHtml, title).Display(p, 0), option);
76 | }
77 |
78 | menu.PrevMenu = MainMenu(player);
79 | return menu;
80 | }
81 |
82 | public static IMenu SubMenuSecond(CCSPlayerController player, Tag playerData, TagType type, string selected, string selectedhtml, string title)
83 | {
84 | IMenu menu = MenuByType($"{Instance.Localizer.ForPlayer(player, "Modify")} {title}");
85 |
86 | menu.AddItem($"{Instance.Localizer.ForPlayer(player, "Selected")} {selectedhtml}", DisableOption.DisableHideNumber);
87 | menu.AddItem(Instance.Localizer.ForPlayer(player, "Select"), (p, o) =>
88 | {
89 | SetPlayerTagValue(p, playerData, type, selected);
90 |
91 | string value = type == TagType.NameColor || type == TagType.ChatColor ?
92 | $"{selected.ReplaceTags(player.Team)}{selected.Split(['{', '}'], StringSplitOptions.None)[1]}" :
93 | selected.ReplaceTags(player.Team);
94 |
95 | player.PrintToChat(Instance.Config.Settings.Tag + Instance.Localizer.ForPlayer(player, "Selected option", title, value));
96 | MainMenu(p).Display(p, 0);
97 | });
98 |
99 | menu.PrevMenu = MainMenu(player);
100 | return menu;
101 | }
102 | }
--------------------------------------------------------------------------------