Compare commits

...

237 Commits

Author SHA1 Message Date
Dawid Bepierszcz
726e67865c Merge pull request #163 from daffyyyy/main
1.8c
2024-02-20 12:54:31 +01:00
Dawid Bepierszcz
868e6c8746 Merge branch 'Nereziel:main' into main 2024-02-20 12:52:33 +01:00
Dawid Bepierszcz
a1285bef26 Merge branch 'main' of https://github.com/daffyyyy/cs2-WeaponPaints 2024-02-20 12:51:15 +01:00
Dawid Bepierszcz
b1920f312c 1.8c
- Better gloves operations
- Changed gloves table
2024-02-20 12:51:14 +01:00
Dawid Bepierszcz
5e9850bece Merge pull request #162 from daffyyyy/main
1.8b
2024-02-20 01:57:01 +01:00
Dawid Bepierszcz
e1802fd0f0 Merge branch 'Nereziel:main' into main 2024-02-20 01:55:45 +01:00
Dawid Bepierszcz
267de3c4de 1.8b
- Fixed gloves changing?
2024-02-20 01:54:54 +01:00
Dawid Bepierszcz
9f24fbf3ef test 2024-02-20 01:51:25 +01:00
Dawid Bepierszcz
9c23545173 test 2024-02-20 01:48:41 +01:00
Dawid Bepierszcz
40d1088ee6 test 2024-02-20 01:46:41 +01:00
Dawid Bepierszcz
e7f546ed58 test 2024-02-20 01:43:27 +01:00
Dawid Bepierszcz
beab940ebb test 2024-02-20 01:38:22 +01:00
Dawid Bepierszcz
7dc78e7706 test 2024-02-20 01:30:09 +01:00
Dawid Bepierszcz
02208095f0 test 2024-02-20 01:28:25 +01:00
Dawid Bepierszcz
63f4b4c43d Merge pull request #161 from daffyyyy/main
1.8a
2024-02-19 14:02:02 +01:00
Dawid Bepierszcz
a6821b85b4 Merge branch 'Nereziel:main' into main 2024-02-19 14:00:14 +01:00
Dawid Bepierszcz
a37f4e9e58 1.8a
- Gloves?

Currently only in plugin, website update soon
2024-02-19 13:59:26 +01:00
Dawid Bepierszcz
fb4340cc1d Merge pull request #157 from daffyyyy/main
1.7a
2024-02-16 15:58:14 +01:00
Dawid Bepierszcz
bbbf27a751 Merge branch 'Nereziel:main' into main 2024-02-16 14:05:29 +01:00
Dawid Bepierszcz
c9d8bb9b5f 1.7a
- Fixed hotreloading
- Minor changes
2024-02-16 14:04:36 +01:00
Dawid Bepierszcz
1109c0cf56 Merge pull request #148 from daffyyyy/main
1.6c
2024-02-11 04:00:07 +01:00
Dawid Bepierszcz
63869f4c94 Merge branch 'Nereziel:main' into main 2024-02-11 03:58:49 +01:00
Dawid Bepierszcz
fa284678e8 1.6c
- Fix for invalid players
2024-02-11 03:58:32 +01:00
Dawid Bepierszcz
558f3178f2 Update WeaponAction.cs 2024-02-10 15:34:34 +01:00
Dawid Bepierszcz
c5f9cc6429 Merge pull request #145 from daffyyyy/main
1.6b
2024-02-10 13:00:48 +01:00
Dawid Bepierszcz
4087d3d016 Merge branch 'Nereziel:main' into main 2024-02-10 13:00:04 +01:00
Dawid Bepierszcz
e7919bb468 Merge branch 'main' of https://github.com/daffyyyy/cs2-WeaponPaints 2024-02-10 12:59:45 +01:00
Dawid Bepierszcz
33bd83d0a1 1.6b
- Closing menu
2024-02-10 12:59:41 +01:00
Dawid Bepierszcz
73d989c0ce Merge pull request #144 from daffyyyy/main
1.6b
2024-02-10 12:25:38 +01:00
Dawid Bepierszcz
f1cecfc73e Merge branch 'Nereziel:main' into main 2024-02-10 12:24:35 +01:00
Dawid Bepierszcz
aae6f7e260 1.6b
- Minor changes
- Fixed tables creation
2024-02-10 12:23:56 +01:00
Dawid Bepierszcz
171d520cc0 Merge pull request #136 from daffyyyy/main
1.6a
2024-02-08 19:37:40 +01:00
Dawid Bepierszcz
deac9bab97 Merge branch 'Nereziel:main' into main 2024-02-08 19:35:57 +01:00
Dawid Bepierszcz
8a76530302 Merge branch 'main' of https://github.com/daffyyyy/cs2-WeaponPaints 2024-02-08 19:35:40 +01:00
Dawid Bepierszcz
d1cbecaecb 1.6a
- Major changes
- Better sql stuff
- Temp fix for crashes on skins reload
2024-02-08 19:35:29 +01:00
Dawid Bepierszcz
ebc932e47c Merge pull request #135 from daffyyyy/main
Updated min. css version
2024-02-08 10:53:34 +01:00
Dawid Bepierszcz
e258ed8c92 Merge branch 'Nereziel:main' into main 2024-02-08 10:53:08 +01:00
Dawid Bepierszcz
e44af369bb Merge branch 'main' of https://github.com/daffyyyy/cs2-WeaponPaints 2024-02-08 10:52:32 +01:00
Dawid Bepierszcz
47055ad6f7 Updated min. css version 2024-02-08 10:52:22 +01:00
Dawid Bepierszcz
d9166253b3 Merge pull request #134 from daffyyyy/main
1.5a
2024-02-08 10:51:44 +01:00
Dawid Bepierszcz
4e90506645 Merge branch 'Nereziel:main' into main 2024-02-08 10:50:08 +01:00
Dawid Bepierszcz
bd93936fab 1.5a
- Minor changes
- New skins
2024-02-08 10:49:53 +01:00
Dawid Bepierszcz
63403dfc8e new skins
New skins
2024-02-07 22:08:26 +01:00
Nereziel
b24a2bd04e Update README.md 2024-02-03 20:27:29 +01:00
Dawid Bepierszcz
dbc652a68c Merge pull request #129 from daffyyyy/main
1.4c
2024-02-03 17:26:12 +01:00
Dawid Bepierszcz
a59ce8f1a5 Merge branch 'main' of https://github.com/daffyyyy/cs2-WeaponPaints 2024-02-03 17:24:46 +01:00
Dawid Bepierszcz
baaa47d837 1.4c 2024-02-03 17:24:26 +01:00
Dawid Bepierszcz
7dcfea3e17 Merge branch 'Nereziel:main' into main 2024-02-03 17:23:44 +01:00
Dawid Bepierszcz
4eab8f0a87 Merge branch 'main' of https://github.com/daffyyyy/cs2-WeaponPaints 2024-02-03 17:23:16 +01:00
Dawid Bepierszcz
236c79c4b9 1.4c
- Minor changes
- Better loading skins
2024-02-03 17:23:12 +01:00
Nereziel
83084452df Update README.md 2024-02-03 16:51:13 +01:00
Nereziel
43e7a3183e Update README.md
Before using website, make sure the plugin is correctly loaded in cs2 server!
2024-01-29 19:36:30 +01:00
Dawid Bepierszcz
60c592aa54 Merge pull request #121 from daffyyyy/main
1.4b
2024-01-26 17:54:35 +01:00
Dawid Bepierszcz
2568f263d9 Merge branch 'Nereziel:main' into main 2024-01-26 17:53:45 +01:00
Dawid Bepierszcz
14e285d44f 1.4b
- Probably fixed empty skin
2024-01-26 17:53:11 +01:00
Nereziel
97b8840ac4 Update README.md 2024-01-22 15:07:18 +01:00
Nereziel
f820c7d251 Merge pull request #115 from daffyyyy/main
1.4a
Updated css version
Probably not needed SkinVisibilityFix anymore
2024-01-20 20:20:44 +01:00
Dawid Bepierszcz
6e5d595c0f Merge branch 'Nereziel:main' into main 2024-01-20 18:05:40 +01:00
Dawid Bepierszcz
71d57eb3ad Merge branch 'main' of https://github.com/daffyyyy/cs2-WeaponPaints 2024-01-20 18:04:52 +01:00
Dawid Bepierszcz
620b067991 1.4a
- Probably not needed `SkinsVisibilityFix` anymore
2024-01-20 18:04:50 +01:00
Nereziel
89c425c170 Merge pull request #112 from daffyyyy/main
1.3i, update css, minor changes
2024-01-18 09:55:55 +01:00
Dawid Bepierszcz
c744f2898b Merge branch 'Nereziel:main' into main 2024-01-18 01:36:39 +01:00
Dawid Bepierszcz
d04bc0879a 1.3i
- Updated css
- Minor changes
2024-01-18 01:36:05 +01:00
Nereziel
4417b093dd Update README.md 2024-01-06 17:41:32 +01:00
Nereziel
3f8533ab94 Merge pull request #107 from daffyyyy/main
1.3h
2023-12-25 20:07:56 +01:00
Dawid Bepierszcz
55905ccc33 Update WeaponPaints.cs 2023-12-25 15:47:40 +01:00
Dawid Bepierszcz
24fcfa0222 1.3h
- Changed knife remove method
- Fixed (?) exception with cooldown
2023-12-25 15:45:32 +01:00
Nereziel
cd059c6bfb Merge pull request #104 from daffyyyy/main
Small website optimization
2023-12-18 12:50:52 +01:00
daffyyyy
e338bebaec Small website optimization 2023-12-18 01:51:24 +01:00
Dawid Bepierszcz
efd7f5dbef Merge branch 'Nereziel:main' into main 2023-12-18 00:55:56 +01:00
Nereziel
6bd002cdec Merge pull request #102 from panikajo/main
add Ukraine Language
2023-12-17 12:16:12 +01:00
panikajo
3a1adf8d4a add Ukraine Language
added Ukrainian translation
2023-12-17 13:05:50 +02:00
Nereziel
7c3fa6469b Merge pull request #99 from himenekocn/main
Add zh-cn.json
2023-12-15 20:13:36 +01:00
LynchMus
52962518fe Create zh-cn.json 2023-12-14 12:13:31 +08:00
Nereziel
7e12b89a9e fix logout 2023-12-13 20:02:01 +01:00
Nereziel
ae56b18a3c Merge pull request #97 from daffyyyy/some-changes
Fix for F
2023-12-13 19:52:59 +01:00
daffyyyy
c907911cd1 Fix for F 2023-12-13 19:49:47 +01:00
Nereziel
1aa486cd7d Merge branch 'main' of https://github.com/Nereziel/cs2-WeaponPaints 2023-12-13 19:42:43 +01:00
Nereziel
5e62c7c597 Update preview.png 2023-12-13 19:36:37 +01:00
Nereziel
819ac6233c Update README.md 2023-12-13 19:31:47 +01:00
Nereziel
ed24eb0dfc add config for darkmode
lazy to make toggle for player
2023-12-13 19:25:13 +01:00
Nereziel
1a9f7ad108 Merge pull request #91 from exababy/patch-1
Wear & Seed Support
2023-12-13 19:22:20 +01:00
Nereziel
6f1a29bb39 Merge pull request #96 from snowhp/main
pt-PT and pt-BR translations added
2023-12-13 08:28:33 +01:00
Nereziel
9e64cdcd43 Merge pull request #95 from exababy/patch-2
turkish language
2023-12-13 08:27:23 +01:00
Nereziel
da86756092 Merge pull request #94 from rcon420/patch-2
latvian lang added
2023-12-13 08:26:35 +01:00
Tiago Machado
22880070cd Merge pull request #1 from crashzk/patch-1
Update pt-BR.json
2023-12-12 23:02:44 +00:00
crashzk
208cbe1aef Update pt-BR.json 2023-12-12 19:53:34 -03:00
Tiago Machado
c0cf9210dc Create pt-BR.json 2023-12-12 22:00:51 +00:00
Tiago Machado
5f61254b4e Create pt-PT.json 2023-12-12 22:00:18 +00:00
Nilsu Derinder
6cd1bb3bf5 fix 2 2023-12-12 23:46:11 +03:00
Nilsu Derinder
4f94b831c2 fix 2023-12-12 23:40:53 +03:00
Nilsu Derinder
969d40b970 Button Update
the button will not work if the skin is not selected which fixes possible bugs in the plugin.
2023-12-12 23:33:05 +03:00
Nilsu Derinder
0cd36a7877 turkish language 2023-12-12 23:21:33 +03:00
rcon_password
a3306b5f8f latvian lang added
latvian lang added
2023-12-12 22:13:05 +02:00
Nereziel
379c2f797c Merge pull request #93 from daffyyyy/some-changes
CSS 121, languages and more
2023-12-12 20:55:21 +01:00
Nilsu Derinder
7f41607d54 Update & Fix
now selected wear appears 
and pulls the value from the database.
2023-12-12 22:44:08 +03:00
daffyyyy
fc42190701 CSS 121, languages and more 2023-12-12 20:09:39 +01:00
Nilsu Derinder
928c1e1466 bootstrap update 2023-12-11 18:46:34 +03:00
Nilsu Derinder
78649f5dcf Update
wear has been updated and settings have been moved into modal and added settings button
2023-12-11 11:32:40 +03:00
Nilsu Derinder
4e72f10326 Seed Update
seed was converted to box instead of range and only numbers can be entered.
2023-12-08 17:56:28 +03:00
Nilsu Derinder
3ddbf7e11e Advanced wear 2023-12-06 22:25:19 +03:00
Nilsu Derinder
ee770fd8c2 Seed support 2023-12-06 22:03:52 +03:00
Nilsu Derinder
72c5df53b5 fix 2023-12-06 20:50:39 +03:00
Nilsu Derinder
d0ed0f4c0b Wear Support 2023-12-06 19:42:18 +03:00
Nereziel
643beaad46 Merge pull request #90 from daffyyyy/some-changes
!skins thread-safe and checking version
2023-12-06 17:18:06 +01:00
daffyyyy
6d44e582be !skins thread-safe and checking version 2023-12-06 14:47:26 +01:00
Nereziel
813a9abcc8 Merge pull request #89 from daffyyyy/some-changes
Small fixes cssharp >= 101
2023-12-05 19:32:00 +01:00
daffyyyy
b0790729be Small fixes 2023-12-05 19:30:10 +01:00
Nereziel
74a6dff114 Merge pull request #88 from daffyyyy/some-changes
Update for cssharp 101
2023-12-04 21:03:07 +01:00
daffyyyy
e37f111f1b Update WeaponPaints.csproj 2023-12-04 21:01:36 +01:00
daffyyyy
5e6286b667 Update for cssharp 101 2023-12-04 21:00:24 +01:00
Nereziel
ed4da98a50 edit default fallback
+removed unused php
2023-12-03 21:25:04 +01:00
Nereziel
c825febeac Merge pull request #83 from daffyyyy/some-changes
Fix for !wp and comments cleanup
2023-12-03 13:03:45 +01:00
daffyyyy
1e5c2a439f Fix for !wp and comments cleanup 2023-12-03 13:00:37 +01:00
Nereziel
21eccfb6d9 Merge pull request #82 from daffyyyy/some-changes
CounterStrikeSharp v90
2023-12-02 16:45:01 +01:00
daffyyyy
a6b193cd13 CounterStrikeSharp v90
Adapted for counterstrikesharp v90
2023-12-02 13:52:06 +01:00
Nereziel
b992433d44 Merge pull request #80 from daffyyyy/some-changes
Changes
2023-12-02 12:56:55 +01:00
daffyyyy
06559af230 Changes 2023-12-02 12:54:13 +01:00
Nereziel
dfe6b200d8 Merge pull request #79 from daffyyyy/some-changes
Workaround for long player authorization
2023-11-30 17:43:32 +01:00
daffyyyy
3edcb5e52f Workaround for long player authorization 2023-11-30 17:28:40 +01:00
Nereziel
28936e9bb5 Merge pull request #78 from daffyyyy/some-changes
GlobalShare fix
2023-11-30 14:29:00 +01:00
daffyyyy
2772fb59b9 GlobalShare fix 2023-11-30 14:18:57 +01:00
Nereziel
0f6bb26ac9 Merge pull request #76 from daffyyyy/some-changes
Improved player index
2023-11-30 10:34:07 +01:00
daffyyyy
be51e4d1e9 Improved player index
The latest version of cssharp adds player.Index instead of entityIndex and does not allow to compile
2023-11-30 02:20:16 +01:00
Nereziel
0d521e0cd3 Merge pull request #75 from daffyyyy/some-changes
Some fixes
2023-11-29 20:45:16 +01:00
daffyyyy
00f920713d Some fixes 2023-11-29 19:39:56 +01:00
Nereziel
42d70690eb Merge pull request #74 from daffyyyy/some-changes
Back to onclientauthorized
2023-11-29 13:52:25 +01:00
daffyyyy
73e3a05270 Back to onclientauthorized
Thanks cssharp :D
2023-11-29 12:37:08 +01:00
Nereziel
dd9e01db54 Merge pull request #73 from daffyyyy/some-changes
Major changes
2023-11-29 12:09:42 +01:00
daffyyyy
393281ea12 Maybe, maybe 👍 2023-11-29 11:58:34 +01:00
daffyyyy
a5787d95e0 improved refreshing skins 2023-11-29 11:56:07 +01:00
daffyyyy
6a7b15e942 Update WeaponAction.cs 2023-11-29 00:41:26 +01:00
daffyyyy
8e7a2a2923 fixxx 2023-11-28 23:44:28 +01:00
daffyyyy
93e8af07d2 Changes changes 2023-11-28 00:40:43 +01:00
daffyyyy
7e5485b209 Major changes 2023-11-27 01:52:23 +01:00
Nereziel
414818e314 Merge pull request #69 from daffyyyy/fix-knife-3
TEMP FIX FOR KNIVES
2023-11-26 18:30:24 +01:00
daffyyyy
a42e9a37fc TEMP FIX FOR KNIVES 2023-11-26 18:19:15 +01:00
Nereziel
dcd68aed67 Merge pull request #68 from daffyyyy/fix-knife-3
IMPORTANT KNIVES FIX
2023-11-26 15:25:01 +01:00
daffyyyy
7bb97af619 IMPORTANT KNIVES FIX 2023-11-26 15:16:01 +01:00
Nereziel
cdc58df13c Merge pull request #67 from daffyyyy/fix-knife-3
Fixees
2023-11-25 23:30:31 +01:00
daffyyyy
fe5cc9a82a Update WeaponPaints.cs 2023-11-25 23:17:56 +01:00
daffyyyy
01542a7dc6 Fixees 2023-11-25 23:12:17 +01:00
Dawid Bepierszcz
a8cf33d404 Merge branch 'Nereziel:main' into main 2023-11-25 22:39:40 +01:00
Nereziel
e1f24abd5d removed exception 2023-11-25 13:10:52 +01:00
Nereziel
646050fb72 Merge pull request #64 from daffyyyy/fix-knife-2
Still knife fix :D (Previous sometimes give random knife to player)
2023-11-24 08:11:37 +01:00
daffyyyy
87dadb9c62 Update WeaponPaints.cs 2023-11-23 01:32:07 +01:00
Nereziel
cf421c5614 Merge pull request #63 from daffyyyy/fix-knife-2
Attempting to repair knives when a map or other plugin was giving them
2023-11-23 00:33:16 +01:00
daffyyyy
fc64e1d261 Additional checks 2023-11-23 00:21:04 +01:00
Dawid Bepierszcz
1c026c018e Merge branch 'Nereziel:main' into main 2023-11-22 23:16:15 +01:00
Nereziel
45fc4a86a5 Merge pull request #61 from daffyyyy/feature/random-skins
Random skins and more
2023-11-22 18:28:21 +01:00
daffyyyy
ad105e5cd2 Merge branch 'feature/random-skins' of https://github.com/daffyyyy/cs2-WeaponPaints into feature/random-skins 2023-11-21 23:54:17 +01:00
daffyyyy
f668f56d66 Give knife on spawn 2023-11-21 23:54:12 +01:00
Dawid Bepierszcz
de6672507a Update build.yml 2023-11-21 22:22:54 +01:00
Dawid Bepierszcz
4a410fd0d8 Update build.yml 2023-11-21 22:19:25 +01:00
Dawid Bepierszcz
bb08e88371 Update build.yml 2023-11-21 22:14:51 +01:00
daffyyyy
2855d4e9ae I baked new things
;)
2023-11-21 21:55:57 +01:00
Nereziel
0c05c25e8e messed discord link 2023-11-21 21:00:12 +01:00
Nereziel
8335ede7d7 Update README.md 2023-11-21 20:07:52 +01:00
Nereziel
d79246f161 Update build.yml 2023-11-21 20:06:31 +01:00
Nereziel
a504506129 test gh act 2023-11-21 20:03:53 +01:00
Nereziel
7bada81eb9 Update build.yml 2023-11-21 20:02:15 +01:00
Nereziel
2929735429 fix php min version 2023-11-21 19:51:10 +01:00
Nereziel
04bb7a2575 Merge pull request #56 from crashzk/patch-1
Update README.md
2023-11-21 19:44:51 +01:00
crashzk
f00ba48f60 Merge branch 'main' into patch-1 2023-11-21 15:43:49 -03:00
crashzk
08342e4a99 Update README.md 2023-11-21 15:43:02 -03:00
Nereziel
29a6041d7a fixed discord link 2023-11-21 19:35:52 +01:00
crashzk
c44433766c Update README.md 2023-11-19 19:22:28 -03:00
crashzk
a987ed972a Update README.md 2023-11-19 19:20:33 -03:00
Nereziel
50777661c5 Merge pull request #55 from daffyyyy/patch-1
Fix when player select "Select skin" as skin
2023-11-19 22:52:08 +01:00
Dawid Bepierszcz
31fd014f55 Fix when player select "Select skin" as skin 2023-11-19 22:42:32 +01:00
Nereziel
760429e644 Merge pull request #54 from daffyyyy/update-readme-1
Update README.md
2023-11-19 22:36:28 +01:00
Dawid Bepierszcz
304d8501cc Update README.md 2023-11-19 22:25:38 +01:00
Nereziel
e9f7db5171 Merge pull request #51 from daffyyyy/website-fix-1
Fixed blank page
2023-11-19 21:14:15 +01:00
Dawid Bepierszcz
648b928b4e Update index.php 2023-11-19 21:10:55 +01:00
Nereziel
530a7d64c7 Update README.md 2023-11-19 20:45:12 +01:00
Nereziel
3453f4c505 Merge pull request #47 from daffyyyy/feature/global-share
EXPERIMENTAL (GlobalShare) - Website for all servers
2023-11-19 19:03:05 +01:00
Nereziel
25b466422b Update build.yml 2023-11-19 19:02:26 +01:00
daffyyyy
6baa59dd9b Update WeaponPaints.cs
New version
2023-11-19 12:30:47 +01:00
daffyyyy
10afe7ce1e Update WeaponPaints.cs 2023-11-19 12:24:57 +01:00
daffyyyy
5eeb0c5fec Initial 2023-11-19 02:07:29 +01:00
Nereziel
e53ee27b39 Merge pull request #44 from daffyyyy/fix-knives_finally
Finally fixed knife problem?
2023-11-18 19:26:37 +01:00
Dawid Bepierszcz
75112b02fe Update WeaponPaints.cs 2023-11-18 19:21:28 +01:00
Nereziel
8e92635231 sync paints on plugin reload 2023-11-18 15:20:26 +01:00
Nereziel
6923295cb6 Update build.yml 2023-11-18 15:14:40 +01:00
Nereziel
e5f98077f3 Update build.yml 2023-11-18 15:12:57 +01:00
Nereziel
3296055841 Merge pull request #42 from daffyyyy/enhancement/mysql-wrapper
Creating tables fix
2023-11-18 11:18:15 +01:00
Dawid Bepierszcz
89de192c20 Update WeaponPaints.cs
Additional check
2023-11-18 09:15:20 +01:00
Dawid Bepierszcz
a1297b9cbe Update WeaponPaints.cs
Creating tables fix
2023-11-18 08:54:33 +01:00
Nereziel
99af078b32 Merge pull request #40 from daffyyyy/enhancement/mysql-wrapper
New mysql stuff, and small changes
2023-11-18 01:29:06 +01:00
Dawid Bepierszcz
b0bef746cd Delete website/database.sql 2023-11-17 23:28:33 +01:00
daffyyyy
117a95e99c New mysql stuff, and small changes 2023-11-17 23:27:07 +01:00
Nereziel
a6d4108ca7 Merge pull request #37 from daffyyyy/hotfix-2
Fixed server crashing
2023-11-16 20:51:10 +01:00
Dawid Bepierszcz
7b45169d8d Update WeaponPaints.cs
Typo
2023-11-16 20:42:20 +01:00
Dawid Bepierszcz
42bd45c3f0 Update WeaponPaints.cs
Fixed crashing
2023-11-16 20:38:35 +01:00
Nereziel
5262739c3d Merge pull request #35 from daffyyyy/fix-knife-1
Fix for knife disappearing and more changes


    Fix for knife disappearing
    Possibility to change commands names
    Skin refresh now also works for knife
    Possibility to set a random knife for players who have not set any via GiveRandomKnife in config
    And probably some smaller changes
2023-11-16 11:37:58 +01:00
Dawid Bepierszcz
c82a0c0d26 Update Config.cs
Changed refresh command to wp by default
2023-11-16 11:30:16 +01:00
Dawid Bepierszcz
9ad7f9fc83 Update Config.cs 2023-11-16 11:23:59 +01:00
Dawid Bepierszcz
9e2dac52e5 Update WeaponPaints.cs 2023-11-16 11:23:26 +01:00
Nereziel
118931f44d Merge pull request #34 from daffyyyy/enhancement/website-knife-choosing
Choosing knife on website
2023-11-16 00:39:19 +01:00
Nereziel
843ae34e31 Merge pull request #33 from daffyyyy/enhancement/config-expansion
Added an additional section to the config
2023-11-16 00:38:33 +01:00
Dawid Bepierszcz
46a720ff83 default knife image 2023-11-16 00:10:26 +01:00
Dawid Bepierszcz
63d059b607 Update utils.php 2023-11-16 00:07:27 +01:00
Dawid Bepierszcz
005ef18338 Update index.php 2023-11-16 00:06:16 +01:00
Dawid Bepierszcz
c0c1fe2566 Update WeaponPaints.cs 2023-11-16 00:05:34 +01:00
Dawid Bepierszcz
c4ad17a7ed MinimumApiVersion 2023-11-15 22:46:42 +01:00
Dawid Bepierszcz
99fde6ec52 Update Config.cs 2023-11-15 22:35:57 +01:00
Dawid Bepierszcz
ca2c3eb212 Update WeaponPaints.cs 2023-11-15 22:35:19 +01:00
Nereziel
b5a4577af1 Update README.md 2023-11-15 22:15:38 +01:00
Nereziel
ba93e4a3aa Update build.yml 2023-11-15 21:22:24 +01:00
Nereziel
7d435da9d1 Update build.yml 2023-11-15 21:19:48 +01:00
Nereziel
50008cf74a Merge pull request #32 from daffyyyy/enhancement/website-skins
Website now use json file to load skins
2023-11-15 20:52:20 +01:00
Dawid Bepierszcz
4b9b169483 Update database.sql, remove weapon_paints 2023-11-15 20:47:16 +01:00
Dawid Bepierszcz
25d251deff Skins in json format 2023-11-15 20:45:55 +01:00
Dawid Bepierszcz
d8f7798f9f New utils class 2023-11-15 20:44:46 +01:00
Dawid Bepierszcz
fb023aff5b Update index.php to base on json 2023-11-15 20:44:18 +01:00
Dawid Bepierszcz
6c91e20a4d Delete website/skins.json
Not needed
2023-11-15 20:43:28 +01:00
Nereziel
93dae346d0 Merge pull request #31 from daffyyyy/patch-giving_knife
Improve knife giving
2023-11-15 18:20:48 +01:00
Dawid Bepierszcz
8e0b1cc99a Update WeaponPaints.cs
respecting the team
2023-11-15 18:18:31 +01:00
Dawid Bepierszcz
c99acbcdb3 Update WeaponPaints.cs
Improved knife giving
And small changes to the code
2023-11-15 18:03:37 +01:00
Nereziel
8beaee94da Merge pull request #28 from daffyyyy/improvement-website-2
Weapon paint  images locally
2023-11-15 16:43:59 +01:00
Nereziel
62238b4446 Merge pull request #27 from daffyyyy/fix-visibility_skins
Weird fix of skin visibility, but at the moment it works xD
2023-11-15 15:03:29 +01:00
Nereziel
03f194ac4e Added discord server 2023-11-15 13:14:12 +01:00
Nereziel
d88ce552f6 Merge pull request #30 from daffyyyy/improvement-config_messages
Add messages to config
2023-11-15 13:08:53 +01:00
Dawid Bepierszcz
9f982d1e63 Update Config.cs 2023-11-15 13:03:16 +01:00
Dawid Bepierszcz
f01d4b0bf0 Update WeaponPaints.cs 2023-11-15 12:52:07 +01:00
Dawid Bepierszcz
3a3f186673 Update Config.cs 2023-11-15 12:51:01 +01:00
daffyyyy
e775b05f9f Upload paint images
Added paint images
2023-11-14 23:13:55 +01:00
Dawid Bepierszcz
b09b97bbd5 Update database.sql
Paints image locally
2023-11-14 23:06:10 +01:00
Dawid Bepierszcz
e441ccc601 Update WeaponPaints.cs
Weird fix of skin visibility, but at the moment it works xD
2023-11-14 22:49:59 +01:00
Nereziel
dc7fb183f9 update 2023-11-14 22:17:43 +01:00
Nereziel
5a5b120674 change knife give handling 2023-11-14 19:54:22 +01:00
Nereziel
5a24f3b9fa bots had no knife 2023-11-14 19:08:17 +01:00
Nereziel
1527eea686 Update README.md 2023-11-14 16:56:18 +01:00
Nereziel
953788c327 Update README.md 2023-11-14 16:52:00 +01:00
Nereziel
837b000126 Merge pull request #24 from daffyyyy/hotfix-1
Update WeaponPaints.cs
2023-11-14 16:42:41 +01:00
Nereziel
87a78b01b4 Merge branch 'main' into hotfix-1 2023-11-14 16:41:06 +01:00
Dawid Bepierszcz
2c0fad230d Update WeaponPaints.cs
Temporary fix for player loading
2023-11-14 15:45:50 +01:00
1825 changed files with 14846 additions and 115950 deletions

View File

@@ -3,8 +3,16 @@ name: Build
on:
push:
branches: [ "main" ]
paths-ignore:
- '**/README.md'
- '**/.gitignore'
- '**/LICENSE'
pull_request:
branches: [ "main" ]
paths-ignore:
- '**/README.md'
- '**/.gitignore'
- '**/LICENSE'
env:
BUILD_NUMBER: ${{ github.run_number }}
@@ -12,7 +20,6 @@ env:
PROJECT_NAME: "WeaponPaints"
OUTPUT_PATH: "./WeaponPaints"
jobs:
build:
permissions: write-all
@@ -28,19 +35,38 @@ jobs:
run: dotnet restore
- name: Build
run: dotnet build ${{ env.PROJECT_PATH }} -c WeaponPaints -o ${{ env.OUTPUT_PATH }}
publish:
if: github.event_name == 'push'
permissions: write-all
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build ${{ env.PROJECT_PATH }} -c WeaponPaints -o ${{ env.OUTPUT_PATH }}
- name: Clean files
run: |
rm -f \
${{ env.OUTPUT_PATH }}/CounterStrikeSharp.API.dll \
${{ env.OUTPUT_PATH }}/McMaster.NETCore.Plugins.dll \
${{ env.OUTPUT_PATH }}/Microsoft.DotNet.PlatformAbstractions.dll \
${{ env.OUTPUT_PATH }}/Microsoft.Extensions.DependencyModel.dll
${{ env.OUTPUT_PATH }}/Microsoft.Extensions.DependencyModel.dll \
- name: Copy skins.json
run: cp website/data/skins.json ${{ env.OUTPUT_PATH }}/skins.json
- name: Copy gloves.json
run: cp website/data/gloves.json ${{ env.OUTPUT_PATH }}/gloves.json
- name: Zip
uses: thedoctor0/zip-release@0.7.5
with:
type: 'zip'
filename: '${{ env.PROJECT_NAME }}.zip'
path: ${{ env.OUTPUT_PATH }}
run: zip -r "${{ env.PROJECT_NAME }}.zip" "${{ env.OUTPUT_PATH }}" gamedata/
- name: Clean files Website
run: |
rm -rf website/img/
- name: Zip
uses: thedoctor0/zip-release@0.7.5
with:
@@ -54,4 +80,4 @@ jobs:
name: "Build ${{ env.BUILD_NUMBER }}"
tag: "build-${{ env.BUILD_NUMBER }}"
body: |
Place the plugin in game/csgo/addons/counterstrikesharp/plugins/WeaponPaints
Place the plugin in game/csgo/addons/counterstrikesharp/plugins/WeaponPaints

2
.gitignore vendored
View File

@@ -1,4 +1,4 @@
.vs/
bin/
obj/
website/getskins.php

426
Commands.cs Normal file
View File

@@ -0,0 +1,426 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Menu;
namespace WeaponPaints
{
public partial class WeaponPaints
{
private void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
{
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return;
if (!Utility.IsPlayerValid(player)) return;
if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return;
int playerIndex = (int)player!.Index;
PlayerInfo playerInfo = new PlayerInfo
{
UserId = player.UserId,
Index = (int)player.Index,
SteamId = player?.SteamID.ToString(),
Name = player?.PlayerName,
IpAddress = player?.IpAddress?.Split(":")[0]
};
if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return;
try
{
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
{
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
if (weaponSync != null)
{
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
if (Config.Additional.GloveEnabled)
Task.Run(async () => await weaponSync.GetGloveFromDatabase(playerInfo));
if (Config.Additional.KnifeEnabled)
Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo));
RefreshWeapons(player);
RefreshGloves(player);
}
if (!string.IsNullOrEmpty(Localizer["wp_command_refresh_done"]))
{
player!.Print(Localizer["wp_command_refresh_done"]);
}
return;
}
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
{
player!.Print(Localizer["wp_command_cooldown"]);
}
}
catch (Exception) { }
}
private void OnCommandWS(CCSPlayerController? player, CommandInfo command)
{
if (!Config.Additional.SkinEnabled) return;
if (!Utility.IsPlayerValid(player)) return;
if (!string.IsNullOrEmpty(Localizer["wp_info_website"]))
{
player!.Print(Localizer["wp_info_website", Config.Website]);
}
if (!string.IsNullOrEmpty(Localizer["wp_info_refresh"]))
{
player!.Print(Localizer["wp_info_refresh"]);
}
if (Config.Additional.GloveEnabled)
if (!string.IsNullOrEmpty(Localizer["wp_info_glove"]))
{
player!.Print(Localizer["wp_info_glove"]);
}
if (Config.Additional.KnifeEnabled)
if (!string.IsNullOrEmpty(Localizer["wp_info_knife"]))
{
player!.Print(Localizer["wp_info_knife"]);
}
}
private void RegisterCommands()
{
AddCommand($"css_{Config.Additional.CommandSkin}", "Skins info", (player, info) =>
{
if (!Utility.IsPlayerValid(player)) return;
OnCommandWS(player, info);
});
AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) =>
{
if (!Utility.IsPlayerValid(player)) return;
OnCommandRefresh(player, info);
});
if (Config.Additional.CommandKillEnabled)
{
AddCommand($"css_{Config.Additional.CommandKill}", "kill yourself", (player, info) =>
{
if (player == null || !Utility.IsPlayerValid(player) || player.PlayerPawn.Value == null || !player!.PlayerPawn.IsValid) return;
player.PlayerPawn.Value.CommitSuicide(true, false);
});
}
}
private void SetupKnifeMenu()
{
if (!Config.Additional.KnifeEnabled || !g_bCommandsAllowed) return;
var knivesOnly = weaponList
.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet"))
.ToDictionary(pair => pair.Key, pair => pair.Value);
var giveItemMenu = new ChatMenu(Localizer["wp_knife_menu_title"]);
var handleGive = (CCSPlayerController player, ChatMenuOption option) =>
{
if (!Utility.IsPlayerValid(player)) return;
var knifeName = option.Text;
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
if (!string.IsNullOrEmpty(knifeKey))
{
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_select"]))
{
player!.Print(Localizer["wp_knife_menu_select", knifeName]);
}
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_kill"]) && Config.Additional.CommandKillEnabled)
{
player!.Print(Localizer["wp_knife_menu_kill"]);
}
PlayerInfo playerInfo = new PlayerInfo
{
UserId = player.UserId,
Index = (int)player.Index,
SteamId = player.SteamID.ToString(),
Name = player.PlayerName,
IpAddress = player.IpAddress?.Split(":")[0]
};
g_playersKnife[(int)player!.Index] = knifeKey;
if (g_bCommandsAllowed && (LifeState_t)player.LifeState == LifeState_t.LIFE_ALIVE)
AddTimer(0.1f, () => RefreshWeapons(player), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
if (weaponSync != null)
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey));
}
};
foreach (var knifePair in knivesOnly)
{
giveItemMenu.AddMenuOption(knifePair.Value, handleGive);
}
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) =>
{
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
if (player == null || player.UserId == null) return;
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
{
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
giveItemMenu.PostSelectAction = PostSelectAction.Close;
MenuManager.OpenChatMenu(player, giveItemMenu);
return;
}
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
{
player!.Print(Localizer["wp_command_cooldown"]);
}
});
}
private void SetupSkinsMenu()
{
var classNamesByWeapon = weaponList.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
var weaponSelectionMenu = new ChatMenu(Localizer["wp_skin_menu_weapon_title"]);
weaponSelectionMenu.PostSelectAction = PostSelectAction.Close;
// Function to handle skin selection for a specific weapon
var handleWeaponSelection = (CCSPlayerController? player, ChatMenuOption option) =>
{
if (!Utility.IsPlayerValid(player)) return;
int playerIndex = (int)player!.Index;
string selectedWeapon = option.Text;
if (classNamesByWeapon.TryGetValue(selectedWeapon, out string? selectedWeaponClassname))
{
if (selectedWeaponClassname == null) return;
var skinsForSelectedWeapon = skinsList?.Where(skin =>
skin != null &&
skin.TryGetValue("weapon_name", out var weaponName) &&
weaponName?.ToString() == selectedWeaponClassname
)?.ToList();
var skinSubMenu = new ChatMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]);
skinSubMenu.PostSelectAction = PostSelectAction.Close;
// Function to handle skin selection for the chosen weapon
var handleSkinSelection = (CCSPlayerController p, ChatMenuOption opt) =>
{
if (!Utility.IsPlayerValid(p)) return;
playerIndex = (int)p.Index;
string steamId = p.SteamID.ToString();
var firstSkin = skinsList?.FirstOrDefault(skin =>
{
if (skin != null && skin.TryGetValue("weapon_name", out var weaponName))
{
return weaponName?.ToString() == selectedWeaponClassname;
}
return false;
});
string selectedSkin = opt.Text;
string selectedPaintID = selectedSkin.Split('(')[1].Trim(')').Trim();
if (firstSkin != null &&
firstSkin.TryGetValue("weapon_defindex", out var weaponDefIndexObj) &&
weaponDefIndexObj != null &&
int.TryParse(weaponDefIndexObj.ToString(), out var weaponDefIndex) &&
int.TryParse(selectedPaintID, out var paintID))
{
if (Config.Additional.ShowSkinImage && skinsList != null)
{
var foundSkin = skinsList.FirstOrDefault(skin =>
((int?)skin?["weapon_defindex"] ?? 0) == weaponDefIndex &&
((int?)skin?["paint"] ?? 0) == paintID &&
skin?["image"] != null
);
string image = foundSkin?["image"]?.ToString() ?? "";
PlayerWeaponImage[p.Slot] = image;
AddTimer(2.0f, () => PlayerWeaponImage.Remove(p.Slot), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
p.Print(Localizer["wp_skin_menu_select", selectedSkin]);
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
{
gPlayerWeaponsInfo[playerIndex][weaponDefIndex] = new WeaponInfo();
}
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID;
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.01f;
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Seed = 0;
PlayerInfo playerInfo = new PlayerInfo
{
UserId = p.UserId,
Index = (int)p.Index,
SteamId = p.SteamID.ToString(),
Name = p.PlayerName,
IpAddress = p.IpAddress?.Split(":")[0]
};
if (g_bCommandsAllowed && (LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE)
AddTimer(0.15f, () => RefreshWeapons(p), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
};
// Add skin options to the submenu for the selected weapon
if (skinsForSelectedWeapon != null)
{
foreach (var skin in skinsForSelectedWeapon.Where(s => s != null))
{
if (skin.TryGetValue("paint_name", out var paintNameObj) && skin.TryGetValue("paint", out var paintObj))
{
var paintName = paintNameObj?.ToString();
var paint = paintObj?.ToString();
if (!string.IsNullOrEmpty(paintName) && !string.IsNullOrEmpty(paint))
{
skinSubMenu.AddMenuOption($"{paintName} ({paint})", handleSkinSelection);
}
}
}
}
// Open the submenu for skin selection of the chosen weapon
MenuManager.OpenChatMenu(player, skinSubMenu);
}
};
// Add weapon options to the weapon selection menu
foreach (var weaponClass in weaponList.Keys)
{
string weaponName = weaponList[weaponClass];
weaponSelectionMenu.AddMenuOption(weaponName, handleWeaponSelection);
}
// Command to open the weapon selection menu for players
AddCommand($"css_{Config.Additional.CommandSkinSelection}", "Skins selection menu", (player, info) =>
{
if (!Utility.IsPlayerValid(player)) return;
if (player == null || player.UserId == null) return;
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
{
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
MenuManager.OpenChatMenu(player, weaponSelectionMenu);
return;
}
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
{
player!.Print(Localizer["wp_command_cooldown"]);
}
});
}
private void SetupGlovesMenu()
{
var glovesSelectionMenu = new ChatMenu(Localizer["wp_glove_menu_title"]);
glovesSelectionMenu.PostSelectAction = PostSelectAction.Close;
var handleGloveSelection = (CCSPlayerController? player, ChatMenuOption option) =>
{
if (!Utility.IsPlayerValid(player)) return;
uint playerIndex = player!.Index;
string selectedPaintName = option.Text;
var selectedGlove = glovesList.FirstOrDefault(g => g.ContainsKey("paint_name") && g["paint_name"]?.ToString() == selectedPaintName);
if (selectedGlove != null)
{
if (
selectedGlove != null &&
selectedGlove.ContainsKey("weapon_defindex") &&
selectedGlove.ContainsKey("paint") &&
int.TryParse(selectedGlove["weapon_defindex"]?.ToString(), out int weaponDefindex) &&
int.TryParse(selectedGlove["paint"]?.ToString(), out int paint)
)
{
if (Config.Additional.ShowSkinImage)
{
string image = selectedGlove["image"]?.ToString() ?? "";
PlayerWeaponImage[player.Slot] = image;
AddTimer(2.0f, () => PlayerWeaponImage.Remove(player.Slot), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
PlayerInfo playerInfo = new PlayerInfo
{
UserId = player.UserId,
Index = (int)player.Index,
SteamId = player.SteamID.ToString(),
Name = player.PlayerName,
IpAddress = player.IpAddress?.Split(":")[0]
};
if (paint != 0)
{
g_playersGlove[playerIndex] = (ushort)weaponDefindex;
if (!gPlayerWeaponsInfo[(int)playerIndex].ContainsKey(weaponDefindex))
{
WeaponInfo weaponInfo = new();
weaponInfo.Paint = paint;
gPlayerWeaponsInfo[(int)playerIndex][weaponDefindex] = weaponInfo;
}
}
else
{
g_playersGlove.TryRemove(playerIndex, out _);
}
if (!string.IsNullOrEmpty(Localizer["wp_glove_menu_select"]))
{
player!.Print(Localizer["wp_glove_menu_select", selectedPaintName]);
}
Server.NextFrame(() =>
{
RefreshGloves(player);
});
if (weaponSync != null)
{
Task.Run(async () => await weaponSync.SyncGloveToDatabase(playerInfo, (ushort)weaponDefindex));
}
}
};
};
// Add weapon options to the weapon selection menu
foreach (var gloveObject in glovesList)
{
string paintName = gloveObject["paint_name"]?.ToString() ?? "";
if (paintName.Length > 0)
glovesSelectionMenu.AddMenuOption(paintName, handleGloveSelection);
}
// Command to open the weapon selection menu for players
AddCommand($"css_{Config.Additional.CommandGlove}", "Gloves selection menu", (player, info) =>
{
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
if (player == null || player.UserId == null) return;
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
{
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
MenuManager.OpenChatMenu(player, glovesSelectionMenu);
return;
}
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
{
player!.Print(Localizer["wp_command_cooldown"]);
}
});
}
}
}

101
Config.cs
View File

@@ -1,32 +1,91 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core;
using System.Text.Json.Serialization;
namespace WeaponPaints
{
public class WeaponPaintsConfig : BasePluginConfig
{
public override int Version { get; set; } = 1;
public class Additional
{
[JsonPropertyName("SkinVisibilityFix")]
public bool SkinVisibilityFix { get; set; } = true;
[JsonPropertyName("DatabaseHost")]
public string DatabaseHost { get; set; } = "localhost";
[JsonPropertyName("KnifeEnabled")]
public bool KnifeEnabled { get; set; } = true;
[JsonPropertyName("DatabasePort")]
public int DatabasePort { get; set; } = 3306;
[JsonPropertyName("GloveEnabled")]
public bool GloveEnabled { get; set; } = true;
[JsonPropertyName("DatabaseUser")]
public string DatabaseUser { get; set; } = "dbuser";
[JsonPropertyName("SkinEnabled")]
public bool SkinEnabled { get; set; } = true;
[JsonPropertyName("DatabasePassword")]
public string DatabasePassword { get; set; } = "dbuserpw";
[JsonPropertyName("CommandWpEnabled")]
public bool CommandWpEnabled { get; set; } = true;
[JsonPropertyName("DatabaseName")]
public string DatabaseName { get; set; } = "dbname";
[JsonPropertyName("CommandKillEnabled")]
public bool CommandKillEnabled { get; set; } = true;
[JsonPropertyName("CmdRefreshCooldownSeconds")]
public int CmdRefreshCooldownSeconds { get; set; } = 60;
[JsonPropertyName("CommandKnife")]
public string CommandKnife { get; set; } = "knife";
[JsonPropertyName("WebSite")]
public string WebSite { get; set; } = "http://wp.example.com";
}
}
[JsonPropertyName("CommandGlove")]
public string CommandGlove { get; set; } = "gloves";
[JsonPropertyName("CommandSkin")]
public string CommandSkin { get; set; } = "ws";
[JsonPropertyName("CommandSkinSelection")]
public string CommandSkinSelection { get; set; } = "skins";
[JsonPropertyName("CommandRefresh")]
public string CommandRefresh { get; set; } = "wp";
[JsonPropertyName("CommandKill")]
public string CommandKill { get; set; } = "kill";
[JsonPropertyName("GiveRandomKnife")]
public bool GiveRandomKnife { get; set; } = false;
[JsonPropertyName("GiveRandomSkin")]
public bool GiveRandomSkin { get; set; } = false;
[JsonPropertyName("GiveKnifeAfterRemove")]
public bool GiveKnifeAfterRemove { get; set; } = false;
[JsonPropertyName("ShowSkinImage")]
public bool ShowSkinImage { get; set; } = true;
}
public class WeaponPaintsConfig : BasePluginConfig
{
public override int Version { get; set; } = 4;
[JsonPropertyName("DatabaseHost")]
public string DatabaseHost { get; set; } = "";
[JsonPropertyName("DatabasePort")]
public int DatabasePort { get; set; } = 3306;
[JsonPropertyName("DatabaseUser")]
public string DatabaseUser { get; set; } = "";
[JsonPropertyName("DatabasePassword")]
public string DatabasePassword { get; set; } = "";
[JsonPropertyName("DatabaseName")]
public string DatabaseName { get; set; } = "";
[JsonPropertyName("GlobalShare")]
public bool GlobalShare { get; set; } = false;
[JsonPropertyName("CmdRefreshCooldownSeconds")]
public int CmdRefreshCooldownSeconds { get; set; } = 60;
[JsonPropertyName("Prefix")]
public string Prefix { get; set; } = "[WeaponPaints]";
[JsonPropertyName("Website")]
public string Website { get; set; } = "example.com/skins";
[JsonPropertyName("Additional")]
public Additional Additional { get; set; } = new Additional();
}
}

28
Database.cs Normal file
View File

@@ -0,0 +1,28 @@
using MySqlConnector;
namespace WeaponPaints
{
public class Database
{
private readonly string _dbConnectionString;
public Database(string dbConnectionString)
{
_dbConnectionString = dbConnectionString;
}
public async Task<MySqlConnection> GetConnectionAsync()
{
try
{
var connection = new MySqlConnection(_dbConnectionString);
await connection.OpenAsync();
return connection;
}
catch (Exception)
{
throw;
}
}
}
}

285
Events.cs Normal file
View File

@@ -0,0 +1,285 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
namespace WeaponPaints
{
public partial class WeaponPaints
{
[GameEventHandler]
public HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo info)
{
CCSPlayerController? player = @event.Userid;
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17 ||
weaponSync == null || _database == null) return HookResult.Continue;
PlayerInfo playerInfo = new PlayerInfo
{
UserId = player.UserId,
Index = (int)player.Index,
SteamId = player.SteamID.ToString(),
Name = player.PlayerName,
IpAddress = player.IpAddress?.Split(":")[0]
};
Task.Run(async () =>
{
// Run skin, knife, and glove tasks asynchronously
var skinTask = Config.Additional.SkinEnabled ? weaponSync.GetWeaponPaintsFromDatabase(playerInfo) : Task.CompletedTask;
var knifeTask = Config.Additional.KnifeEnabled ? weaponSync.GetKnifeFromDatabase(playerInfo) : Task.CompletedTask;
var gloveTask = Config.Additional.GloveEnabled ? weaponSync.GetGloveFromDatabase(playerInfo) : Task.CompletedTask;
// Await all tasks to complete
await Task.WhenAll(skinTask, knifeTask, gloveTask);
});
return HookResult.Continue;
}
[GameEventHandler]
public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
{
CCSPlayerController player = @event.Userid;
if (player is null || !player.IsValid || !player.UserId.HasValue || player.IsBot ||
player.IsHLTV || player.SteamID.ToString().Length != 17) return HookResult.Continue;
PlayerInfo playerInfo = new PlayerInfo
{
UserId = player.UserId,
Index = (int)player.Index,
SteamId = player.SteamID.ToString(),
Name = player.PlayerName,
IpAddress = player.IpAddress?.Split(":")[0]
};
if (weaponSync != null)
Task.Run(async () => await weaponSync.SyncWeaponPaintsToDatabase(playerInfo));
if (Config.Additional.SkinEnabled)
gPlayerWeaponsInfo.TryRemove((int)player.Index, out _);
if (Config.Additional.KnifeEnabled)
g_playersKnife.TryRemove((int)player.Index, out _);
if (Config.Additional.GloveEnabled)
g_playersGlove.TryRemove(player.Index, out _);
commandsCooldown.Remove((int)player.UserId);
return HookResult.Continue;
}
private void OnEntityCreated(CEntityInstance entity)
{
if (!Config.Additional.SkinEnabled) return;
if (entity == null || !entity.IsValid || string.IsNullOrEmpty(entity.DesignerName)) return;
string designerName = entity.DesignerName;
if (!weaponList.ContainsKey(designerName)) return;
bool isKnife = false;
var weapon = new CBasePlayerWeapon(entity.Handle);
if (designerName.Contains("knife") || designerName.Contains("bayonet"))
{
isKnife = true;
}
Server.NextFrame(() =>
{
try
{
if (!weapon.IsValid) return;
if (weapon.OwnerEntity.Value == null) return;
if (weapon.OwnerEntity.Index <= 0) return;
int weaponOwner = (int)weapon.OwnerEntity.Index;
CBasePlayerPawn? pawn = Utilities.GetEntityFromIndex<CCSPlayerPawn>((int)weaponOwner);
//var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
if (!pawn.IsValid) return;
var playerIndex = (int)pawn.Controller.Index;
var player = Utilities.GetPlayerFromIndex(playerIndex);
if (!Utility.IsPlayerValid(player)) return;
ChangeWeaponAttributes(weapon, player, isKnife);
}
catch (Exception) { }
});
}
public HookResult OnPickup(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay)
{
CCSPlayerController? player = Utilities.GetEntityFromIndex<CCSPlayerPawn>((int)activator.Index).OriginalController.Value;
if (player == null || player.IsBot || player.IsHLTV ||
player.SteamID.ToString().Length != 17 || !g_knifePickupCount.TryGetValue((int)player.Index, out var pickupCount) ||
!g_playersKnife.ContainsKey((int)player.Index))
{
return HookResult.Continue;
}
CBasePlayerWeapon weapon = new(caller.Handle);
if (weapon.AttributeManager.Item.ItemDefinitionIndex != 42 && weapon.AttributeManager.Item.ItemDefinitionIndex != 59)
{
return HookResult.Continue;
}
if (pickupCount >= 2)
{
return HookResult.Continue;
}
if (g_playersKnife[(int)player.Index] != "weapon_knife")
{
pickupCount++;
g_knifePickupCount[(int)player.Index] = pickupCount;
if (Config.Additional.GiveKnifeAfterRemove)
{
AddTimer(0.10f, () =>
{
RefreshWeapons(player);
});
}
}
return HookResult.Continue;
}
private void OnMapStart(string mapName)
{
if (!Config.Additional.KnifeEnabled && !Config.Additional.SkinEnabled && !Config.Additional.GloveEnabled) return;
if (_database != null)
weaponSync = new WeaponSynchronization(_database, Config, GlobalShareApi, GlobalShareServerId);
// TODO
// needed for now
AddTimer(2.0f, () =>
{
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
if (Config.GlobalShare)
GlobalShareConnect();
});
}
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
CCSPlayerController? player = @event.Userid;
if (player is null || !player.IsValid || player.PlayerPawn == null ||
!player.PlayerPawn.IsValid || player.IsHLTV
|| !Config.Additional.KnifeEnabled && !Config.Additional.GloveEnabled)
return HookResult.Continue;
g_knifePickupCount[(int)player.Index] = 0;
GiveKnifeToPlayer(player);
Server.NextFrame(() =>
{
RefreshGloves(player);
});
return HookResult.Continue;
}
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
{
g_bCommandsAllowed = false;
return HookResult.Continue;
}
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
{
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
g_bCommandsAllowed = true;
return HookResult.Continue;
}
private void OnTick()
{
foreach (var player in Utilities.GetPlayers())
{
try
{
if (player is null || !player.IsValid || !player.PawnIsAlive || player.SteamID.ToString().Length != 17
|| player.IsBot || player.IsHLTV || player.Connected != PlayerConnectedState.PlayerConnected)
continue;
if (Config.Additional.ShowSkinImage && PlayerWeaponImage.ContainsKey(player.Slot) && !string.IsNullOrEmpty(PlayerWeaponImage[player.Slot]))
{
player.PrintToCenterHtml("<img src='{PATH}'</img>".Replace("{PATH}", PlayerWeaponImage[player.Slot]));
}
if (player.PlayerPawn?.IsValid != true || player.PlayerPawn?.Value?.IsValid != true)
continue;
var viewModels = GetPlayerViewModels(player);
if (viewModels == null || viewModels.Length == 0)
continue;
var viewModel = viewModels[0];
if (viewModel == null || viewModel.Value == null || viewModel.Value.Weapon == null || viewModel.Value.Weapon.Value == null)
continue;
var weapon = viewModel.Value.Weapon.Value;
if (weapon == null || !weapon.IsValid || weapon.FallbackPaintKit == 0)
continue;
if (viewModel.Value.VMName.Contains("knife"))
continue;
var sceneNode = viewModel.Value.CBodyComponent?.SceneNode;
if (sceneNode == null)
continue;
var skeleton = GetSkeletonInstance(sceneNode);
if (skeleton == null)
continue;
int[] newPaints = { 1171, 1170, 1169, 1164, 1162, 1161, 1159, 1175, 1174, 1167, 1165, 1168, 1163, 1160, 1166, 1173 };
if (newPaints.Contains(weapon.FallbackPaintKit))
{
skeleton.ModelState.MeshGroupMask = 1;
}
else
{
if (skeleton.ModelState.MeshGroupMask != 2)
{
skeleton.ModelState.MeshGroupMask = 2;
}
}
Utilities.SetStateChanged(viewModel.Value, "CBaseEntity", "m_CBodyComponent");
}
catch (Exception)
{
}
}
}
private void RegisterListeners()
{
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);
//RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
//RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterListener<Listeners.OnTick>(OnTick);
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
//RegisterEventHandler<EventItemPickup>(OnItemPickup);
HookEntityOutput("weapon_knife", "OnPlayerPickup", OnPickup);
}
}
}

15
PlayerExtensions.cs Normal file
View File

@@ -0,0 +1,15 @@
using CounterStrikeSharp.API.Core;
using System.Text;
namespace WeaponPaints;
public static class PlayerExtensions
{
public static void Print(this CCSPlayerController controller, string message)
{
if (WeaponPaints._localizer == null) return;
StringBuilder _message = new(WeaponPaints._localizer["wp_prefix"]);
_message.Append(message);
controller.PrintToChat(_message.ToString());
}
}

11
PlayerInfo.cs Normal file
View File

@@ -0,0 +1,11 @@
namespace WeaponPaints
{
public class PlayerInfo
{
public int Index { get; set; }
public int? UserId { get; set; }
public string? SteamId { get; set; }
public string? Name { get; set; }
public string? IpAddress { get; set; }
}
}

133
README.md
View File

@@ -1,30 +1,113 @@
# cs2-WeaponPaints
# CS2 Weapon Paints
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E2G0P2O) or [Donate on Steam](https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE)
## Description
Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for **[CSSharp](https://docs.cssharp.dev/docs/guides/getting-started.html)**.
## Created [Discord server](https://discord.gg/d9CvaYPSFe) where you can discuss about plugin.
### Consider to donate instead of buying from unknown sources.
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E2G0P2O) or [![Donate on Steam](https://github.com/Nereziel/cs2-WeaponPaints/assets/32937653/a0d53822-4ca7-4caf-83b4-e1a9b5f8c94e)](https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE)
## Features
- Changes only paint, seed and wear on weapons and knives
- MySQL based or global website, so you dont need MySQL/Website
- Data syncs on player connect
- Added command **`!wp`** to refresh skins ***(with cooldown in seconds can be configured)***
- Added command **`!ws`** to show website
- Added command **`!knife`** to show menu with knives
- Knife change is now limited to have these cvars empty **`mp_t_default_melee ""`** and **`mp_ct_default_melee ""`**
- Translations support, submit a PR if you want to share your translation
**GlobalShare** - global website accessible at [weaponpaints.fun](https://weaponpaints.fun/)
## CS2 Server
- Have working CounterStrikeSharp (**with RUNTIME!**)
- Download from Release and copy plugin to plugins
- Run server with plugin, **it will generate config if installed correctly!**
- Edit `addons/counterstrikesharp/configs/`**`plugins/WeaponPaints/WeaponPaints.json`** set **`GlobalShare`** to **`true`** for global, or include database credentials
- In `addons/counterstrikesharp/configs/`**`core.json`** set **FollowCS2ServerGuidelines** to **`false`**
## Plugin Configuration
<details>
<summary>Click to expand</summary>
<code><pre>{
"Version": 4, // Don't touch
"DatabaseHost": "", // MySQL host (required if GlobalShare = false)
"DatabasePort": 3306, // MySQL port (required if GlobalShare = false)
"DatabaseUser": "", // MySQL username (required if GlobalShare = false)
"DatabasePassword": "", // MySQL user password (required if GlobalShare = false)
"DatabaseName": "", // MySQL database name (required if GlobalShare = false)
"GlobalShare": false, // Enable or disable GlobalShare, plugin can work without mysql credentials but with shared website at weaponpaints.fun
"CmdRefreshCooldownSeconds": 60, // Cooldown time in refreshing skins (!wp command)
"Prefix": "[WeaponPaints]", // Prefix every chat message
"Website": "example.com/skins", // Website used in WebsiteMessageCommand (!ws command)
"Messages": {
"WebsiteMessageCommand": "Visit {WEBSITE} where you can change skins.", // Information about website where player can change skins (!ws command) Set to empty to disable
"SynchronizeMessageCommand": "Type !wp to synchronize chosen skins.", // Information about skins refreshing (!ws command) Set to empty to disable
"KnifeMessageCommand": "Type !knife to open knife menu.", // Information about knife menu (!ws command) Set to empty to disable
"CooldownRefreshCommand": "You can\u0027t refresh weapon paints right now.", // Cooldown information (!wp command) Set to empty to disable
"SuccessRefreshCommand": "Refreshing weapon paints.", // Information about refreshing skins (!wp command) Set to empty to disable
"ChosenKnifeMenu": "You have chosen {KNIFE} as your knife.", // Information about choosen knife (!knife command) Set to empty to disable
"ChosenSkinMenu": "You have chosen {SKIN} as your skin.", // Information about choosen skin (!skins command) Set to empty to disable
"ChosenKnifeMenuKill": "To correctly apply skin for knife, you need to type !kill.", // Information about suicide after knife selection (!knife command) Set to empty to disable
"KnifeMenuTitle": "Knife Menu.", // Menu title (!knife menu)
"WeaponMenuTitle": "Weapon Menu.", // Menu title (!skins menu)
"SkinMenuTitle": "Select skin for {WEAPON}" // Menu title (!skins menu, after weapon select)
},
"Additional": {
"SkinVisibilityFix": true, // Enable or disable fix for skin visibility
"KnifeEnabled": true, // Enable or disable knife feature
"SkinEnabled": true, // Enable or disable skin feature
"CommandWpEnabled": true, // Enable or disable refreshing command
"CommandKillEnabled": true, // Enable or disable kill command
"CommandKnife": "knife", // Name of knife menu command, u can change to for e.g, knives
"CommandSkin": "ws", // Name of skin information command, u can change to for e.g, skins
"CommandSkinSelection": "skins", // Name of skins menu command, u can change to for e.g, weapons
"CommandRefresh": "wp", // Name of skin refreshing command, u can change to for e.g, refreshskins
"CommandKill": "kill", // Name of kill command, u can change to for e.g, suicide
"GiveRandomKnife": false, // Give random knife to players if they didn't choose
"GiveRandomSkins": false // Give random skins to players if they didn't choose
},
"ConfigVersion": 4 // Don't touch
}</pre></code>
</details>
## Web install
Disregard if the config is **`GlobalShare = true`**
- Requires PHP >= 7.4 ***(Tested on php ver **`8.2.3`** and nginx webserver)***
- **Before using website, make sure the plugin is correctly loaded in cs2 server!** Mysql tables are created by plugin not by website.
- Copy website to web server ***(Folder `img` not needed)***
- Get [Steam API Key](https://steamcommunity.com/dev/apikey)
- Fill in database credentials and api key in `class/config.php`
- Visit website and login via steam
## Web Features
- Basic website
- Steam login/logout
- Change knife, paint, seed and wear
## Known issues
- Issue on Windows servers, no knives are given.
- You can't change knife if it's equpied in cs2 inventory
- Can cause incompatibility with plugins/maps which manipulates weapons and knives
## Troubleshooting
<details>
**Skins are not changing:**
Set FollowCSGOGuidelines to false in cssharps core.jcon config
**Database error table does not exists:**
Plugin is not loaded or configured with mysql credentials. Tables are auto-created by plugin.
**Knives are disappearing:**
Set in config GiveKnifeAfterRemove to true
**Knives are not changing for players:**
You can't change knife if you have your own equipped
</details>
### Use this plugin at your own risk! Using this may lead to GSLT ban or something else Valve come with. [Valve Server guidelines](https://blog.counter-strike.net/index.php/server_guidelines/)
### Description
Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for [CSSharp](https://docs.cssharp.dev/).
### Features
- changes only paint, seed, wear on weapons
- mysql based
- data sync on player connect or playe
- Added command `!wp` to refresh skins (with cooldown in second can be configured)
- Added command `!ws` to show website
### CS2 server:
- compile and copy plugin to plugins. Info here [https://docs.cssharp.dev/guides/hello-world-plugin/](https://docs.cssharp.dev/guides/hello-world-plugin/)
- setup `addons/counterstrikesharp/configs/plugins/WeaponPaints/WeaponPaints.json` with database credentials
- in `addons/counterstrikesharp/configs/core.json` set **FollowCS2ServerGuidelines** to **false**
### Web install:
- copy website to web server
- import `database.sql` to mysql
- get steam api key [https://steamcommunity.com/dev/apikey](https://steamcommunity.com/dev/apikey)
- fill in database credentials and api key in `class/config.php`
- visit website and login via steam
### Preview
## Preview
![preview](https://github.com/Nereziel/cs2-WeaponPaints/blob/main/website/preview.png?raw=true)

24
SchemaString.cs Normal file
View File

@@ -0,0 +1,24 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Modules.Memory;
using System.Runtime.CompilerServices;
using System.Text;
namespace WeaponPaints;
public class SchemaString<TSchemaClass> : NativeObject where TSchemaClass : NativeObject
{
internal SchemaString(TSchemaClass instance, string member) : base(Schema.GetSchemaValue<nint>(instance.Handle, typeof(TSchemaClass).Name!, member))
{ }
internal unsafe void Set(string str)
{
var bytes = Encoding.UTF8.GetBytes(str);
for (var i = 0; i < bytes.Length; i++)
{
Unsafe.Write((void*)(Handle.ToInt64() + i), bytes[i]);
}
Unsafe.Write((void*)(Handle.ToInt64() + bytes.Length), 0);
}
}

231
Utility.cs Normal file
View File

@@ -0,0 +1,231 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Dapper;
using Microsoft.Extensions.Logging;
using MySqlConnector;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Reflection;
namespace WeaponPaints
{
internal static class Utility
{
internal static WeaponPaintsConfig? Config { get; set; }
internal static string BuildDatabaseConnectionString()
{
if (Config == null) return string.Empty;
var builder = new MySqlConnectionStringBuilder
{
Server = Config.DatabaseHost,
UserID = Config.DatabaseUser,
Password = Config.DatabasePassword,
Database = Config.DatabaseName,
Port = (uint)Config.DatabasePort,
Pooling = true
};
return builder.ConnectionString;
}
internal static async Task CheckDatabaseTables()
{
if (WeaponPaints._database is null) return;
try
{
await using var connection = await WeaponPaints._database.GetConnectionAsync();
await using var transaction = await connection.BeginTransactionAsync();
try
{
string[] createTableQueries = new[]
{
@"CREATE TABLE IF NOT EXISTS `wp_player_skins` (
`steamid` varchar(64) NOT NULL,
`weapon_defindex` int(6) NOT NULL,
`weapon_paint_id` int(6) NOT NULL,
`weapon_wear` float NOT NULL DEFAULT 0.000001,
`weapon_seed` int(16) NOT NULL DEFAULT 0
) ENGINE=InnoDB",
@"CREATE TABLE IF NOT EXISTS `wp_player_knife` (
`steamid` varchar(64) NOT NULL,
`knife` varchar(64) NOT NULL,
UNIQUE (`steamid`)
) ENGINE = InnoDB",
@"CREATE TABLE IF NOT EXISTS `wp_player_gloves` (
`steamid` varchar(64) NOT NULL,
`weapon_defindex` int(11) NOT NULL,
UNIQUE (`steamid`)
) ENGINE=InnoDB"
};
foreach (var query in createTableQueries)
{
await connection.ExecuteAsync(query, transaction: transaction);
}
await transaction.CommitAsync();
}
catch (Exception)
{
await transaction.RollbackAsync();
throw new Exception("[WeaponPaints] Unable to create tables!");
}
}
catch (Exception ex)
{
throw new Exception("[WeaponPaints] Unknown MySQL exception! " + ex.Message);
}
}
internal static bool IsPlayerValid(CCSPlayerController? player)
{
if (player is null) return false;
return (player is not null && player.IsValid && !player.IsBot && !player.IsHLTV
&& WeaponPaints.weaponSync != null && player.Connected == PlayerConnectedState.PlayerConnected && player.SteamID.ToString().Length == 17);
}
internal static void LoadSkinsFromFile(string filePath)
{
try
{
string json = File.ReadAllText(filePath);
var deserializedSkins = JsonConvert.DeserializeObject<List<JObject>>(json);
WeaponPaints.skinsList = deserializedSkins ?? new List<JObject>();
}
catch (FileNotFoundException)
{
throw;
}
}
internal static void LoadGlovesFromFile(string filePath)
{
try
{
string json = File.ReadAllText(filePath);
var deserializedSkins = JsonConvert.DeserializeObject<List<JObject>>(json);
WeaponPaints.glovesList = deserializedSkins ?? new List<JObject>();
}
catch (FileNotFoundException)
{
throw;
}
}
internal static void Log(string message)
{
Console.BackgroundColor = ConsoleColor.DarkGray;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("[WeaponPaints] " + message);
Console.ResetColor();
}
internal static string ReplaceTags(string message)
{
if (message.Contains('{'))
{
string modifiedValue = message;
if (Config != null)
{
modifiedValue = modifiedValue.Replace("{WEBSITE}", Config.Website);
}
foreach (FieldInfo field in typeof(ChatColors).GetFields())
{
string pattern = $"{{{field.Name}}}";
if (message.Contains(pattern, StringComparison.OrdinalIgnoreCase))
{
modifiedValue = modifiedValue.Replace(pattern, field.GetValue(null)!.ToString(), StringComparison.OrdinalIgnoreCase);
}
}
return modifiedValue;
}
return message;
}
internal static async Task CheckVersion(string version, ILogger logger)
{
using (HttpClient client = new HttpClient())
{
try
{
HttpResponseMessage response = await client.GetAsync("https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/VERSION").ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
string remoteVersion = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
remoteVersion = remoteVersion.Trim();
int comparisonResult = string.Compare(version, remoteVersion);
if (comparisonResult < 0)
{
logger.LogWarning("Plugin is outdated! Check https://github.com/Nereziel/cs2-WeaponPaints");
}
else if (comparisonResult > 0)
{
logger.LogInformation("Probably dev version detected");
}
else
{
logger.LogInformation("Plugin is up to date");
}
}
else
{
logger.LogWarning("Failed to check version");
}
}
catch (HttpRequestException ex)
{
logger.LogError(ex, "Failed to connect to the version server.");
}
catch (Exception ex)
{
logger.LogError(ex, "An error occurred while checking version.");
}
}
}
internal static void ShowAd(string moduleVersion)
{
Console.WriteLine(" ");
Console.WriteLine(" _ _ _______ _______ _______ _______ __ _ _______ _______ ___ __ _ _______ _______ ");
Console.WriteLine("| | _ | || || _ || || || | | || || _ || | | | | || || |");
Console.WriteLine("| || || || ___|| |_| || _ || _ || |_| || _ || |_| || | | |_| ||_ _|| _____|");
Console.WriteLine("| || |___ | || |_| || | | || || |_| || || | | | | | | |_____ ");
Console.WriteLine("| || ___|| || ___|| |_| || _ || ___|| || | | _ | | | |_____ |");
Console.WriteLine("| _ || |___ | _ || | | || | | || | | _ || | | | | | | | _____| |");
Console.WriteLine("|__| |__||_______||__| |__||___| |_______||_| |__||___| |__| |__||___| |_| |__| |___| |_______|");
Console.WriteLine(" >> Version: " + moduleVersion);
Console.WriteLine(" >> GitHub: https://github.com/Nereziel/cs2-WeaponPaints");
Console.WriteLine(" ");
}
/*(
internal static void TestDatabaseConnection()
{
try
{
using var connection = new MySqlConnection(BuildDatabaseConnectionString());
connection.Open();
if (connection.State != System.Data.ConnectionState.Open)
{
throw new Exception("[WeaponPaints] Unable connect to database!");
}
}
catch (Exception ex)
{
throw new Exception("[WeaponPaints] Unknown mysql exception! " + ex.Message);
}
CheckDatabaseTables();
}
*/
}
}

1
VERSION Normal file
View File

@@ -0,0 +1 @@
1.8c

448
WeaponAction.cs Normal file
View File

@@ -0,0 +1,448 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Timers;
using CounterStrikeSharp.API.Modules.Utils;
using Microsoft.Extensions.Logging;
using System.Runtime.InteropServices;
namespace WeaponPaints
{
public partial class WeaponPaints
{
internal static void ChangeWeaponAttributes(CBasePlayerWeapon? weapon, CCSPlayerController? player, bool isKnife = false)
{
if (player is null || weapon is null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;
int playerIndex = (int)player.Index;
if (!gPlayerWeaponsInfo.ContainsKey(playerIndex)) return;
if (isKnife && !g_playersKnife.ContainsKey(playerIndex) || isKnife && g_playersKnife[playerIndex] == "weapon_knife") return;
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
if (isKnife)
{
weapon.AttributeManager.Item.EntityQuality = 3;
}
int fallbackPaintKit = weapon.FallbackPaintKit;
if (_config.Additional.GiveRandomSkin &&
!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
{
// Random skins
weapon.AttributeManager.Item.ItemID = 16384;
weapon.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
weapon.FallbackPaintKit = GetRandomPaint(weaponDefIndex);
weapon.FallbackSeed = 0;
weapon.FallbackWear = 0.000001f;
fallbackPaintKit = weapon.FallbackPaintKit;
if (fallbackPaintKit == 0)
return;
var foundSkin = skinsList.FirstOrDefault(skin =>
((int?)skin?["weapon_defindex"] ?? 0) == weaponDefIndex &&
((int?)skin?["paint"] ?? 0) == fallbackPaintKit &&
skin?["paint_name"] != null
);
string skinName = foundSkin?["paint_name"]?.ToString() ?? "";
if (!string.IsNullOrEmpty(skinName))
new SchemaString<CEconItemView>(weapon.AttributeManager.Item, "m_szCustomName").Set(skinName);
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
{
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
int[] newPaints = { 1171, 1170, 1169, 1164, 1162, 1161, 1159, 1175, 1174, 1167, 1165, 1168, 1163, 1160, 1166, 1173 };
if (newPaints.Contains(fallbackPaintKit))
{
skeleton.ModelState.MeshGroupMask = 1;
}
else
{
if (skeleton.ModelState.MeshGroupMask != 2)
{
skeleton.ModelState.MeshGroupMask = 2;
}
}
}
var viewModels = GetPlayerViewModels(player);
if (viewModels == null || viewModels.Length == 0)
return;
var viewModel = viewModels[0];
if (viewModel == null || viewModel.Value == null || viewModel.Value.Weapon == null || viewModel.Value.Weapon.Value == null)
return;
Utilities.SetStateChanged(viewModel.Value, "CBaseEntity", "m_CBodyComponent");
return;
}
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex)) return;
WeaponInfo weaponInfo = gPlayerWeaponsInfo[playerIndex][weaponDefIndex];
//Log($"Apply on {weapon.DesignerName}({weapon.AttributeManager.Item.ItemDefinitionIndex}) paint {gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} seed {gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} wear {gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]}");
weapon.AttributeManager.Item.ItemID = 16384;
weapon.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
weapon.FallbackPaintKit = weaponInfo.Paint;
weapon.FallbackSeed = weaponInfo.Seed;
weapon.FallbackWear = weaponInfo.Wear;
fallbackPaintKit = weapon.FallbackPaintKit;
if (fallbackPaintKit == 0)
return;
var foundSkin1 = skinsList.FirstOrDefault(skin =>
((int?)skin?["weapon_defindex"] ?? 0) == weaponDefIndex &&
((int?)skin?["paint"] ?? 0) == fallbackPaintKit &&
skin?["paint_name"] != null
);
var skinName1 = foundSkin1?["paint_name"]?.ToString() ?? "";
if (!string.IsNullOrEmpty(skinName1))
new SchemaString<CEconItemView>(weapon.AttributeManager.Item, "m_szCustomName").Set(skinName1);
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
{
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
int[] newPaints = { 1171, 1170, 1169, 1164, 1162, 1161, 1159, 1175, 1174, 1167, 1165, 1168, 1163, 1160, 1166, 1173 };
if (newPaints.Contains(fallbackPaintKit))
{
skeleton.ModelState.MeshGroupMask = 1;
}
else
{
if (skeleton.ModelState.MeshGroupMask != 2)
{
skeleton.ModelState.MeshGroupMask = 2;
}
}
}
var viewModels1 = GetPlayerViewModels(player);
if (viewModels1 == null || viewModels1.Length == 0)
return;
var viewModel1 = viewModels1[0];
if (viewModel1 == null || viewModel1.Value == null || viewModel1.Value.Weapon == null || viewModel1.Value.Weapon.Value == null)
return;
Utilities.SetStateChanged(viewModel1.Value, "CBaseEntity", "m_CBodyComponent");
}
internal static void GiveKnifeToPlayer(CCSPlayerController? player)
{
if (!_config.Additional.KnifeEnabled || player == null || !player.IsValid) return;
string knifeToGive;
if (g_playersKnife.TryGetValue((int)player.Index, out var knife))
{
knifeToGive = knife;
}
else if (_config.Additional.GiveRandomKnife)
{
var knifeTypes = weaponList.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet")).ToList();
if (knifeTypes.Count == 0)
{
Utility.Log("No valid knife types found.");
return;
}
Random random = new();
int index = random.Next(knifeTypes.Count);
knifeToGive = knifeTypes[index].Key;
}
else
{
knifeToGive = (CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife";
}
player.GiveNamedItem(knifeToGive);
}
internal static bool PlayerHasKnife(CCSPlayerController? player)
{
if (!_config.Additional.KnifeEnabled) return false;
if (player == null || !player.IsValid || player.PlayerPawn == null || !player.PlayerPawn.IsValid || !player.PawnIsAlive)
{
return false;
}
if (player.PlayerPawn?.Value == null || player.PlayerPawn?.Value.WeaponServices == null || player.PlayerPawn?.Value.ItemServices == null)
return false;
var weapons = player.PlayerPawn.Value.WeaponServices?.MyWeapons;
if (weapons == null) return false;
foreach (var weapon in weapons)
{
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
{
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
{
return true;
}
}
}
return false;
}
internal void RefreshWeapons(CCSPlayerController? player)
{
if (player == null || !player.IsValid || player.PlayerPawn?.Value == null || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE)
return;
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
return;
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
if (weapons == null || weapons.Count == 0)
return;
if (weapons != null && weapons.Count > 0)
{
//Dictionary<string, (int, int)> weaponsWithAmmo = new Dictionary<string, (int, int)>();
Dictionary<string, List<(int, int)>> weaponsWithAmmo = new Dictionary<string, List<(int, int)>>();
bool bomb = false;
bool defuser = player.PawnHasDefuser;
bool healthshot = false;
// Iterate through each weapon
foreach (var weapon in weapons)
{
if (weapon == null || !weapon.IsValid || weapon.Value == null ||
!weapon.Value.IsValid || !weapon.Value.DesignerName.Contains("weapon_"))
continue;
try
{
string? weaponByDefindex = null;
CCSWeaponBaseVData? weaponData = weapon.Value.As<CCSWeaponBase>().VData;
if (weaponData != null)
{
if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_C4)
bomb = true;
if (weaponData.Name.Equals("weapon_healtshot"))
healthshot = true;
if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_GRENADES || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_UTILITY || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_BOOSTS)
{
int clip1 = weapon.Value.Clip1;
int reservedAmmo = weapon.Value.ReserveAmmo[0];
weaponsWithAmmo.Add(weapon.Value.DesignerName, new List<(int, int)>() { (clip1, reservedAmmo) });
}
}
if (!weapon.Value.DesignerName.Contains("knife") && WeaponDefindex.TryGetValue(weapon.Value.AttributeManager.Item.ItemDefinitionIndex, out weaponByDefindex) && weaponByDefindex != null)
{
int clip1 = weapon.Value.Clip1;
int reservedAmmo = weapon.Value.ReserveAmmo[0];
if (!weaponsWithAmmo.ContainsKey(weaponByDefindex))
{
weaponsWithAmmo.Add(weaponByDefindex, new List<(int, int)>());
}
weaponsWithAmmo[weaponByDefindex].Add((clip1, reservedAmmo));
}
}
catch (Exception ex)
{
Logger.LogWarning(ex.Message);
continue;
}
}
player.RemoveWeapons();
AddTimer(0.1f, () =>
{
GiveKnifeToPlayer(player);
if (bomb)
player.GiveNamedItem("weapon_c4");
if (defuser)
{
var itemServ = player.PlayerPawn?.Value?.ItemServices;
if (itemServ != null)
{
var items = new CCSPlayer_ItemServices(itemServ.Handle);
items.HasDefuser = true;
}
}
if (healthshot)
player.GiveNamedItem("weapon_healtshot");
foreach (var entry in weaponsWithAmmo)
{
foreach (var ammo in entry.Value)
{
var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(entry.Key));
Server.NextFrame(() =>
{
try
{
if (newWeapon != null)
{
newWeapon.Clip1 = ammo.Item1;
newWeapon.ReserveAmmo[0] = ammo.Item2;
}
}
catch (Exception ex)
{
Logger.LogWarning("Error setting weapon properties: " + ex.Message);
}
});
}
}
}, TimerFlags.STOP_ON_MAPCHANGE);
}
}
internal void RefreshKnife(CCSPlayerController? player)
{
if (player == null || !player.IsValid || player.PlayerPawn?.Value == null || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE)
return;
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
return;
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
if (weapons != null && weapons.Count > 0)
{
foreach (var weapon in weapons)
{
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid && weapon.Index > 0)
{
try
{
CCSWeaponBaseVData? weaponData = weapon.Value.As<CCSWeaponBase>().VData;
if (weapon.Value.DesignerName.Contains("knife") || weaponData?.GearSlot == gear_slot_t.GEAR_SLOT_KNIFE)
{
RefreshWeapons(player);
break;
}
}
catch (Exception ex)
{
Logger.LogWarning($"Cannot remove knife: {ex.Message}");
}
}
}
}
}
private static void RefreshGloves(CCSPlayerController player)
{
if (!Utility.IsPlayerValid(player) || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE) return;
CCSPlayerPawn? pawn = player.PlayerPawn.Value;
if (pawn == null || !pawn.IsValid || pawn.LifeState != (byte)LifeState_t.LIFE_ALIVE)
return;
string model = pawn.CBodyComponent?.SceneNode?.GetSkeletonInstance()?.ModelState.ModelName ?? string.Empty;
if (!string.IsNullOrEmpty(model))
{
pawn.SetModel("characters/models/tm_jumpsuit/tm_jumpsuit_varianta.vmdl");
pawn.SetModel(model);
}
Instance.AddTimer(0.06f, () =>
{
try
{
if (!player.IsValid)
return;
if (g_playersGlove.TryGetValue(player.Index, out var gloveInfo) && gloveInfo != 0)
{
CCSPlayerPawn? pawn = player.PlayerPawn.Value;
if (pawn == null || !pawn.IsValid || pawn.LifeState != (byte)LifeState_t.LIFE_ALIVE)
return;
WeaponInfo weaponInfo = gPlayerWeaponsInfo[(int)player.Index][gloveInfo];
CEconItemView item = pawn.EconGloves;
item.ItemDefinitionIndex = gloveInfo;
item.ItemIDLow = 16384 & 0xFFFFFFFF;
item.ItemIDHigh = 16384;
CAttributeList_SetOrAddAttributeValueByName.Invoke(item.NetworkedDynamicAttributes.Handle, "set item texture prefab", weaponInfo.Paint);
CAttributeList_SetOrAddAttributeValueByName.Invoke(item.NetworkedDynamicAttributes.Handle, "set item texture seed", weaponInfo.Seed);
CAttributeList_SetOrAddAttributeValueByName.Invoke(item.NetworkedDynamicAttributes.Handle, "set item texture wear", weaponInfo.Wear);
item.Initialized = true;
CBaseModelEntity_SetBodygroup.Invoke(pawn, "default_gloves", 1);
}
}
catch (Exception) { }
}, TimerFlags.STOP_ON_MAPCHANGE);
}
private static int GetRandomPaint(int defindex)
{
if (skinsList == null || skinsList.Count == 0)
return 0;
Random rnd = new Random();
// Filter weapons by the provided defindex
var filteredWeapons = skinsList.Where(w => w["weapon_defindex"]?.ToString() == defindex.ToString()).ToList();
if (filteredWeapons.Count == 0)
return 0;
var randomWeapon = filteredWeapons[rnd.Next(filteredWeapons.Count)];
if (int.TryParse(randomWeapon["paint"]?.ToString(), out int paintValue))
return paintValue;
return 0;
}
private static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
{
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
}
private static unsafe CHandle<CBaseViewModel>[]? GetPlayerViewModels(CCSPlayerController player)
{
if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.ViewModelServices == null) return null;
CCSPlayer_ViewModelServices viewModelServices = new CCSPlayer_ViewModelServices(player.PlayerPawn.Value.ViewModelServices!.Handle);
return GetFixedArray<CHandle<CBaseViewModel>>(viewModelServices.Handle, "CCSPlayer_ViewModelServices", "m_hViewModel", 3);
}
public static unsafe T[] GetFixedArray<T>(nint pointer, string @class, string member, int length) where T : CHandle<CBaseViewModel>
{
nint ptr = pointer + Schema.GetSchemaOffset(@class, member);
Span<nint> references = MemoryMarshal.CreateSpan<nint>(ref ptr, length);
T[] values = new T[length];
for (int i = 0; i < length; i++)
{
values[i] = (T)Activator.CreateInstance(typeof(T), references[i])!;
}
return values;
}
}
}

9
WeaponInfo.cs Normal file
View File

@@ -0,0 +1,9 @@
namespace WeaponPaints
{
public class WeaponInfo
{
public int Paint { get; set; }
public int Seed { get; set; } = 0;
public float Wear { get; set; } = 0f;
}
}

View File

@@ -1,362 +1,293 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Menu;
using CounterStrikeSharp.API.Modules.Utils;
using Nexd.MySQL;
using System.Runtime.ExceptionServices;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using MySqlConnector;
using Newtonsoft.Json.Linq;
using System.Collections.Concurrent;
namespace WeaponPaints;
public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
[MinimumApiVersion(168)]
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
{
public override string ModuleName => "WeaponPaints";
public override string ModuleDescription => "Connector for web-based player chosen wepaon paints.";
public override string ModuleAuthor => "Nereziel";
public override string ModuleVersion => "0.8";
internal static WeaponPaints Instance { get; private set; } = new();
internal static readonly Dictionary<string, string> weaponList = new()
{
{"weapon_deagle", "Desert Eagle"},
{"weapon_elite", "Dual Berettas"},
{"weapon_fiveseven", "Five-SeveN"},
{"weapon_glock", "Glock-18"},
{"weapon_ak47", "AK-47"},
{"weapon_aug", "AUG"},
{"weapon_awp", "AWP"},
{"weapon_famas", "FAMAS"},
{"weapon_g3sg1", "G3SG1"},
{"weapon_galilar", "Galil AR"},
{"weapon_m249", "M249"},
{"weapon_m4a1", "M4A1"},
{"weapon_mac10", "MAC-10"},
{"weapon_p90", "P90"},
{"weapon_mp5sd", "MP5-SD"},
{"weapon_ump45", "UMP-45"},
{"weapon_xm1014", "XM1014"},
{"weapon_bizon", "PP-Bizon"},
{"weapon_mag7", "MAG-7"},
{"weapon_negev", "Negev"},
{"weapon_sawedoff", "Sawed-Off"},
{"weapon_tec9", "Tec-9"},
{"weapon_taser", "Zeus x27"},
{"weapon_hkp2000", "P2000"},
{"weapon_mp7", "MP7"},
{"weapon_mp9", "MP9"},
{"weapon_nova", "Nova"},
{"weapon_p250", "P250"},
{"weapon_scar20", "SCAR-20"},
{"weapon_sg556", "SG 553"},
{"weapon_ssg08", "SSG 08"},
{"weapon_m4a1_silencer", "M4A1-S"},
{"weapon_usp_silencer", "USP-S"},
{"weapon_cz75a", "CZ75-Auto"},
{"weapon_revolver", "R8 Revolver"},
{ "weapon_knife", "Default Knife" },
{ "weapon_knife_m9_bayonet", "M9 Bayonet" },
{ "weapon_knife_karambit", "Karambit" },
{ "weapon_bayonet", "Bayonet" },
{ "weapon_knife_survival_bowie", "Bowie Knife" },
{ "weapon_knife_butterfly", "Butterfly Knife" },
{ "weapon_knife_falchion", "Falchion Knife" },
{ "weapon_knife_flip", "Flip Knife" },
{ "weapon_knife_gut", "Gut Knife" },
{ "weapon_knife_tactical", "Huntsman Knife" },
{ "weapon_knife_push", "Shadow Daggers" },
{ "weapon_knife_gypsy_jackknife", "Navaja Knife" },
{ "weapon_knife_stiletto", "Stiletto Knife" },
{ "weapon_knife_widowmaker", "Talon Knife" },
{ "weapon_knife_ursus", "Ursus Knife" },
{ "weapon_knife_css", "Classic Knife" },
{ "weapon_knife_cord", "Paracord Knife" },
{ "weapon_knife_canis", "Survival Knife" },
{ "weapon_knife_outdoor", "Nomad Knife" },
{ "weapon_knife_skeleton", "Skeleton Knife" },
{ "weapon_knife_kukri", "Kukri Knife" }
};
public WeaponPaintsConfig Config { get; set; } = new();
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
internal static IStringLocalizer? _localizer;
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
internal static ConcurrentDictionary<int, string> g_playersKnife = new ConcurrentDictionary<int, string>();
internal static ConcurrentDictionary<uint, ushort> g_playersGlove = new ConcurrentDictionary<uint, ushort>();
internal static ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>>();
internal static List<JObject> skinsList = new List<JObject>();
internal static List<JObject> glovesList = new List<JObject>();
internal static WeaponSynchronization? weaponSync;
public static bool g_bCommandsAllowed = true;
internal Dictionary<int, string> PlayerWeaponImage = new();
MySqlDb? MySql = null;
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
private static string PluginPrefix = $" {ChatColors.Green}[WeaponPaints]{ChatColors.White}";
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponPaints = new();
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponSeed = new();
private Dictionary<ulong, Dictionary<nint, float>> gPlayerWeaponWear = new();
private Dictionary<int, string> g_playersKife = new();
private static readonly Dictionary<string, string> knifeTypes = new()
{
{ "m9", "weapon_knife_m9_bayonet" },
{ "karambit", "weapon_knife_karambit" },
{ "bayonet", "weapon_bayonet" },
{ "bowie", "weapon_knife_survival_bowie" },
{ "butterfly", "weapon_knife_butterfly" },
{ "falchion", "weapon_knife_falchion" },
{ "flip", "weapon_knife_flip" },
{ "gut", "weapon_knife_gut" },
{ "tactical", "weapon_knife_tactical" },
{ "shadow", "weapon_knife_push" },
{ "navaja", "weapon_knife_gypsy_jackknife" },
{ "stiletto", "weapon_knife_stiletto" },
{ "talon", "weapon_knife_widowmaker" },
{ "ursus", "weapon_knife_ursus" },
{ "css", "weapon_knife_css" },
{ "paracord", "weapon_knife_cord" },
{ "survival", "weapon_knife_canis" },
{ "nomad", "weapon_knife_outdoor" },
{ "skeleton", "weapon_knife_skeleton" },
{ "default", "weapon_knife" }
};
private static readonly List<string> weaponList = new()
{
"weapon_deagle", "weapon_elite", "weapon_fiveseven", "weapon_glock",
"weapon_ak47", "weapon_aug", "weapon_awp", "weapon_famas",
"weapon_g3sg1", "weapon_galilar", "weapon_m249", "weapon_m4a1",
"weapon_mac10", "weapon_p90", "weapon_mp5sd", "weapon_ump45",
"weapon_xm1014", "weapon_bizon", "weapon_mag7", "weapon_negev",
"weapon_sawedoff", "weapon_tec9", "weapon_hkp2000", "weapon_mp7",
"weapon_mp9", "weapon_nova", "weapon_p250", "weapon_scar20",
"weapon_sg556", "weapon_ssg08", "weapon_m4a1_silencer", "weapon_usp_silencer",
"weapon_cz75a", "weapon_revolver", "weapon_bayonet", "weapon_knife"
};
public override void Load(bool hotReload)
{
base.Load(hotReload);
SetGlobalExceptionHandler();
MySql = new MySqlDb(Config.DatabaseHost, Config.DatabaseUser, Config.DatabasePassword, Config.DatabaseName!, Config.DatabasePort);
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
//RegisterEventHandler<EventRoundPrestart>(OnRoundPreStart);
SetupMenus();
}
public void OnConfigParsed(WeaponPaintsConfig config)
{
Config = config;
}
// TODO: fix for map which change mp_t_default_melee
/*private HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
{
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
return HookResult.Continue;
}
*/
public override void Unload(bool hotReload)
{
RemoveGlobalExceptionHandler();
base.Unload(hotReload);
}
private void GlobalExceptionHandler(object? sender, FirstChanceExceptionEventArgs @event)
{
Log(@event.Exception.ToString());
}
private void SetGlobalExceptionHandler()
{
AppDomain.CurrentDomain.FirstChanceException += this.GlobalExceptionHandler;
}
private void RemoveGlobalExceptionHandler()
{
AppDomain.CurrentDomain.FirstChanceException -= this.GlobalExceptionHandler;
}
private void OnMapStart(string mapName)
{
// TODO
// needed for now
base.AddTimer(2.0f, () => {
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
});
}
internal Uri GlobalShareApi = new("https://weaponpaints.fun/api.php");
internal int GlobalShareServerId = 0;
internal static Dictionary<int, DateTime> commandsCooldown = new Dictionary<int, DateTime>();
internal static Database? _database;
private void OnClientAuthorized(int playerSlot, SteamID steamId)
{
int playerIndex = playerSlot + 1;
Task.Run(async () =>
{
await GetKnifeFromDatabase(playerIndex);
await GetWeaponPaintsFromDatabase(playerIndex);
});
}
private void OnClientDisconnect(int playerSlot)
{
// TODO: Clean up after player
}
internal static MemoryFunctionVoid<nint, string, float> CAttributeList_SetOrAddAttributeValueByName = new(GameData.GetSignature("CAttributeList_SetOrAddAttributeValueByName"));
internal static MemoryFunctionVoid<CBaseModelEntity, string, UInt64> CBaseModelEntity_SetBodygroup = new(GameData.GetSignature("CBaseModelEntity_SetBodygroup"));
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
var player = @event.Userid;
if (!player.IsValid || !player.PlayerPawn.IsValid || player.IsBot)
{
return HookResult.Continue;
}
if (!PlayerHasKnife(player)) player.GiveNamedItem(g_playersKife[(int)player.EntityIndex!.Value.Value]);
public static Dictionary<int, string> WeaponDefindex { get; } = new Dictionary<int, string>
{
{ 1, "weapon_deagle" },
{ 2, "weapon_elite" },
{ 3, "weapon_fiveseven" },
{ 4, "weapon_glock" },
{ 7, "weapon_ak47" },
{ 8, "weapon_aug" },
{ 9, "weapon_awp" },
{ 10, "weapon_famas" },
{ 11, "weapon_g3sg1" },
{ 13, "weapon_galilar" },
{ 14, "weapon_m249" },
{ 16, "weapon_m4a1" },
{ 17, "weapon_mac10" },
{ 19, "weapon_p90" },
{ 23, "weapon_mp5sd" },
{ 24, "weapon_ump45" },
{ 25, "weapon_xm1014" },
{ 26, "weapon_bizon" },
{ 27, "weapon_mag7" },
{ 28, "weapon_negev" },
{ 29, "weapon_sawedoff" },
{ 30, "weapon_tec9" },
{ 31, "weapon_taser" },
{ 32, "weapon_hkp2000" },
{ 33, "weapon_mp7" },
{ 34, "weapon_mp9" },
{ 35, "weapon_nova" },
{ 36, "weapon_p250" },
{ 38, "weapon_scar20" },
{ 39, "weapon_sg556" },
{ 40, "weapon_ssg08" },
{ 60, "weapon_m4a1_silencer" },
{ 61, "weapon_usp_silencer" },
{ 63, "weapon_cz75a" },
{ 64, "weapon_revolver" },
{ 500, "weapon_bayonet" },
{ 503, "weapon_knife_css" },
{ 505, "weapon_knife_flip" },
{ 506, "weapon_knife_gut" },
{ 507, "weapon_knife_karambit" },
{ 508, "weapon_knife_m9_bayonet" },
{ 509, "weapon_knife_tactical" },
{ 512, "weapon_knife_falchion" },
{ 514, "weapon_knife_survival_bowie" },
{ 515, "weapon_knife_butterfly" },
{ 516, "weapon_knife_push" },
{ 517, "weapon_knife_cord" },
{ 518, "weapon_knife_canis" },
{ 519, "weapon_knife_ursus" },
{ 520, "weapon_knife_gypsy_jackknife" },
{ 521, "weapon_knife_outdoor" },
{ 522, "weapon_knife_stiletto" },
{ 523, "weapon_knife_widowmaker" },
{ 525, "weapon_knife_skeleton" },
{ 526, "weapon_knife_kukri" }
};
return HookResult.Continue;
}
private void OnEntitySpawned(CEntityInstance entity)
{
var designerName = entity.DesignerName;
if (!weaponList.Contains(designerName)) return;
bool isKnife = false;
var weapon = new CBasePlayerWeapon(entity.Handle);
public WeaponPaintsConfig Config { get; set; } = new();
public override string ModuleAuthor => "Nereziel & daffyy";
public override string ModuleDescription => "Skin, gloves and knife selector, standalone and web-based";
public override string ModuleName => "WeaponPaints";
public override string ModuleVersion => "1.8c";
if (designerName.Contains("knife") || designerName.Contains("bayonet"))
{
isKnife = true;
}
Server.NextFrame(() =>
{
if (!weapon.IsValid) return;
if (weapon.OwnerEntity.Value == null) return;
if (!weapon.OwnerEntity.Value.EntityIndex.HasValue) return;
int weaponOwner = (int)weapon.OwnerEntity.Value.EntityIndex.Value.Value;
var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
if (!pawn.IsValid) return;
var playerIndex = (int)pawn.Controller.Value.EntityIndex!.Value.Value;
var player = Utilities.GetPlayerFromIndex(playerIndex);
if (player == null || !player.IsValid || player.IsBot) return;
// TODO: Remove knife crashes here, needs another solution
/*if (isKnife && g_playersKife[(int)player.EntityIndex!.Value.Value] != "weapon_knife" && (weapon.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.AttributeManager.Item.ItemDefinitionIndex == 59))
{
RemoveKnifeFromPlayer(player);
return;
}*/
var steamId = new SteamID(player.SteamID);
if (!gPlayerWeaponPaints.ContainsKey(steamId.SteamId64)) return;
if (!gPlayerWeaponPaints[steamId.SteamId64].ContainsKey(weapon.AttributeManager.Item.ItemDefinitionIndex)) return;
//Log($"Apply on {weapon.DesignerName}({weapon.AttributeManager.Item.ItemDefinitionIndex}) paint {gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} seed {gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} wear {gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]}");
weapon.AttributeManager.Item.ItemID = 16384;
weapon.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
weapon.FallbackPaintKit = gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
weapon.FallbackSeed = gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
weapon.FallbackWear = gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
{
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
skeleton.ModelState.MeshGroupMask = 2;
}
});
}
public void RemoveKnifeFromPlayer(CCSPlayerController player)
{
if (!player.PawnIsAlive) return;
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
foreach (var weapon in weapons)
{
if (weapon.IsValid && weapon.Value.IsValid)
{
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
if (weapon.Value.DesignerName.Contains("knife"))
{
weapon.Value.Remove();
player.GiveNamedItem(g_playersKife[(int)player.EntityIndex!.Value.Value]);
break;
}
}
}
}
public static bool PlayerHasKnife(CCSPlayerController player)
{
if (!player.PawnIsAlive) return false;
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
foreach (var weapon in weapons)
{
if (weapon.IsValid && weapon.Value.IsValid)
{
if (weapon.Value.DesignerName.Contains("knife"))
{
return true;
}
}
}
return false;
}
private void SetupMenus()
{
var giveItemMenu = new ChatMenu("Knife Menu");
var handleGive = (CCSPlayerController player, ChatMenuOption option) =>
{
if (knifeTypes.TryGetValue(option.Text, out var knife))
{
Task.Run(() => SyncKnifeToDatabase((int)player.EntityIndex!.Value.Value, knife));
g_playersKife[(int)player.EntityIndex!.Value.Value] = knifeTypes[option.Text];
player.PrintToChat($"You have chosen {option.Text} as your knife.");
RemoveKnifeFromPlayer(player);
}
};
foreach (var knife in knifeTypes)
{
giveItemMenu.AddMenuOption(knife.Key, handleGive);
}
AddCommand("css_knife", "Knife Menu", (player, info) => { if (player == null) return; ChatMenus.OpenMenu(player, giveItemMenu); });
}
[ConsoleCommand("css_wp", "refreshskins")]
public void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
{
if (player == null) return;
int playerIndex = (int)player.EntityIndex!.Value.Value;
if (DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
{
commandCooldown[playerIndex] = DateTime.UtcNow;
Task.Run(async () => await GetWeaponPaintsFromDatabase(playerIndex));
player.PrintToChat($"{PluginPrefix} Refreshing weapon paints.");
return;
}
player.PrintToChat($"{PluginPrefix} You can't refresh weapon paints right now.");
}
[ConsoleCommand("css_ws", "weaponskins")]
public void OnCommandWS(CCSPlayerController? player, CommandInfo command)
{
if (player == null) return;
player.PrintToChat($"{PluginPrefix} Visit {ChatColors.Purple}{Config.WebSite} {ChatColors.White}where you can change skins.");
player.PrintToChat($"{PluginPrefix} Type {ChatColors.Purple}!wp {ChatColors.White}in chat to synchronize chosen skins.");
player.PrintToChat($"{PluginPrefix} Type {ChatColors.Purple}!knife {ChatColors.White}in chat to open knife menu.");
}
public static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
{
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
}
private async Task GetWeaponPaintsFromDatabase(int playerIndex)
{
try
{
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
if (player == null || !player.IsValid) return;
var steamId = new SteamID(player.SteamID);
public static WeaponPaintsConfig GetWeaponPaintsConfig()
{
return _config;
}
MySqlQueryCondition conditions = new MySqlQueryCondition()
.Add("steamid", "=", steamId.SteamId64.ToString());
public override void Load(bool hotReload)
{
Instance = this;
MySqlQueryResult result = await MySql!.Table("wp_player_skins").Where(conditions).SelectAsync();
if (hotReload)
{
OnMapStart(string.Empty);
result.ToList().ForEach(pair =>
{
int WeaponDefIndex = result.Get<int>(pair.Key, "weapon_defindex");
int PaintId = result.Get<int>(pair.Key, "weapon_paint_id");
float Wear = result.Get<float>(pair.Key, "weapon_wear");
int Seed = result.Get<int>(pair.Key, "weapon_seed");
foreach (var player in Utilities.GetPlayers())
{
if (weaponSync == null || player is null || !player.IsValid || player.SteamID.ToString().Length != 17 || !player.PawnIsAlive || player.IsBot ||
player.IsHLTV || player.Connected != PlayerConnectedState.PlayerConnected)
continue;
if (!gPlayerWeaponPaints.ContainsKey(steamId.SteamId64))
{
gPlayerWeaponPaints[steamId.SteamId64] = new Dictionary<nint, int>();
}
if (!gPlayerWeaponWear.ContainsKey(steamId.SteamId64))
{
gPlayerWeaponWear[steamId.SteamId64] = new Dictionary<nint, float>();
}
if (!gPlayerWeaponSeed.ContainsKey(steamId.SteamId64))
{
gPlayerWeaponSeed[steamId.SteamId64] = new Dictionary<nint, int>();
}
g_knifePickupCount[(int)player.Index] = 0;
gPlayerWeaponsInfo.TryRemove((int)player.Index, out _);
g_playersKnife.TryRemove((int)player.Index, out _);
gPlayerWeaponPaints[steamId.SteamId64][WeaponDefIndex] = PaintId;
gPlayerWeaponWear[steamId.SteamId64][WeaponDefIndex] = Wear;
gPlayerWeaponSeed[steamId.SteamId64][WeaponDefIndex] = Seed;
});
}
catch (Exception e)
{
Log(e.Message);
return;
}
}
private async Task GetKnifeFromDatabase(int playerIndex)
{
try
{
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
if (player == null || !player.IsValid) return;
var steamId = new SteamID(player.SteamID);
MySqlQueryCondition conditions = new MySqlQueryCondition()
.Add("steamid", "=", steamId.SteamId64.ToString());
PlayerInfo playerInfo = new PlayerInfo
{
UserId = player.UserId,
Index = (int)player.Index,
SteamId = player?.SteamID.ToString(),
Name = player?.PlayerName,
IpAddress = player?.IpAddress?.Split(":")[0]
};
MySqlQueryResult result = await MySql!.Table("wp_player_knife").Where(conditions).SelectAsync();
if (Config.Additional.SkinEnabled)
_ = weaponSync.GetWeaponPaintsFromDatabase(playerInfo);
if (Config.Additional.KnifeEnabled)
_ = weaponSync.GetKnifeFromDatabase(playerInfo);
if (Config.Additional.GloveEnabled)
_ = weaponSync.GetGloveFromDatabase(playerInfo);
}
}
string knife = result.Get<string>(0, "knife");
if (knife != null)
{
g_playersKife[playerIndex] = knife;
}
else
{
g_playersKife[playerIndex] = "weapon_knife";
}
//Log($"{player.PlayerName} has this knife -> {g_playersKife[playerIndex]}");
}
catch (Exception e)
{
Log(e.Message);
return;
}
}
private async Task SyncKnifeToDatabase(int playerIndex, string knife)
{
try
{
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
if (player == null || !player.IsValid) return;
var steamId = new SteamID(player.SteamID);
await MySql!.ExecuteNonQueryAsync($"INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES('{steamId.SteamId64}', '{knife}') ON DUPLICATE KEY UPDATE `knife` = '{knife}';");
}
catch (Exception e)
{
Log(e.Message);
return;
}
}
Utility.LoadSkinsFromFile(ModuleDirectory + "/skins.json");
Utility.LoadGlovesFromFile(ModuleDirectory + "/gloves.json");
private static void Log(string message)
{
Console.BackgroundColor = ConsoleColor.DarkGray;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(message);
Console.ResetColor();
}
if (Config.Additional.KnifeEnabled)
SetupKnifeMenu();
if (Config.Additional.SkinEnabled)
SetupSkinsMenu();
if (Config.Additional.GloveEnabled)
SetupGlovesMenu();
RegisterListeners();
RegisterCommands();
}
public void OnConfigParsed(WeaponPaintsConfig config)
{
if (!config.GlobalShare)
{
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
{
Logger.LogError("You need to setup Database credentials in config!");
throw new Exception("[WeaponPaints] You need to setup Database credentials in config!");
}
var builder = new MySqlConnectionStringBuilder
{
Server = config.DatabaseHost,
UserID = config.DatabaseUser,
Password = config.DatabasePassword,
Database = config.DatabaseName,
Port = (uint)config.DatabasePort,
Pooling = true
};
_database = new(builder.ConnectionString);
_ = Utility.CheckDatabaseTables();
}
Config = config;
_config = config;
_localizer = Localizer;
Utility.Config = config;
Utility.ShowAd(ModuleVersion);
Task.Run(async () => await Utility.CheckVersion(ModuleVersion, Logger));
}
public override void Unload(bool hotReload)
{
base.Unload(hotReload);
}
private void GlobalShareConnect()
{
if (!Config.GlobalShare) return;
var values = new Dictionary<string, string>
{
{ "server_address", $"{ConVar.Find("ip")!.StringValue}:{ConVar.Find("hostport")!.GetPrimitiveValue<int>().ToString()}" },
{ "server_hostname", ConVar.Find("hostname")!.StringValue }
};
using (var httpClient = new HttpClient())
{
httpClient.BaseAddress = GlobalShareApi;
var formContent = new FormUrlEncodedContent(values);
Task<HttpResponseMessage> responseTask = httpClient.PostAsync("", formContent);
responseTask.Wait();
HttpResponseMessage response = responseTask.Result;
if (response.IsSuccessStatusCode)
{
Task<string> responseBodyTask = response.Content.ReadAsStringAsync();
responseBodyTask.Wait();
string responseBody = responseBodyTask.Result;
GlobalShareServerId = int.Parse(responseBody);
}
else
{
Logger.LogError("Unable to retrieve serverid from GlobalShare!");
throw new Exception("[WeaponPaints] Unable to retrieve serverid from GlobalShare!");
}
}
Logger.LogInformation("GlobalShare ONLINE!");
Console.WriteLine("[WeaponPaints] GlobalShare ONLINE");
}
}

View File

@@ -5,17 +5,17 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="*" />
<PackageReference Include="Nexd.MySQL" Version="1.0.1" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.168" />
<PackageReference Include="Dapper" Version="2.1.28" />
<PackageReference Include="MySqlConnector" Version="2.3.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<Reference Include="CounterStrikeSharp.API">
<HintPath>deps\CounterStrikeSharp.API.dll</HintPath>
</Reference>
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>

260
WeaponSynchronization.cs Normal file
View File

@@ -0,0 +1,260 @@
using Dapper;
using Newtonsoft.Json.Linq;
using System.Collections.Concurrent;
namespace WeaponPaints
{
internal class WeaponSynchronization
{
private readonly WeaponPaintsConfig _config;
private readonly Database _database;
private readonly Uri _globalShareApi;
private readonly int _globalShareServerId;
internal WeaponSynchronization(Database database, WeaponPaintsConfig config, Uri globalShareApi, int globalShareServerId)
{
_database = database;
_config = config;
_globalShareApi = globalShareApi;
_globalShareServerId = globalShareServerId;
}
internal async Task GetKnifeFromDatabase(PlayerInfo player)
{
if (!_config.Additional.KnifeEnabled) return;
if (player.SteamId == null || player.Index == 0) return;
try
{
if (_config.GlobalShare)
{
var values = new Dictionary<string, string>
{
{ "server_id", _globalShareServerId.ToString() },
{ "steamid", player.SteamId },
{ "knife", "1" }
};
UriBuilder builder = new UriBuilder(_globalShareApi);
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
using (var httpClient = new HttpClient())
{
httpClient.BaseAddress = _globalShareApi;
var formContent = new FormUrlEncodedContent(values);
HttpResponseMessage response = await httpClient.GetAsync(builder.Uri);
if (response.IsSuccessStatusCode)
{
string result = await response.Content.ReadAsStringAsync();
if (!string.IsNullOrEmpty(result))
{
WeaponPaints.g_playersKnife[player.Index] = result;
}
else
{
return;
}
}
else
{
return;
}
}
return;
}
await using var connection = await _database.GetConnectionAsync();
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
string? playerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { steamid = player.SteamId });
if (!string.IsNullOrEmpty(playerKnife))
{
WeaponPaints.g_playersKnife[player.Index] = playerKnife;
}
}
catch (Exception e)
{
Utility.Log(e.Message);
return;
}
}
internal async Task GetGloveFromDatabase(PlayerInfo player)
{
if (!_config.Additional.GloveEnabled) return;
try
{
// Ensure proper disposal of resources using "using" statement
await using var connection = await _database.GetConnectionAsync();
// Construct the SQL query with specific columns for better performance
string query = "SELECT `weapon_defindex` FROM `wp_player_gloves` WHERE `steamid` = @steamid";
// Execute the query and retrieve glove data
ushort? gloveData = await connection.QueryFirstOrDefaultAsync<ushort?>(query, new { steamid = player.SteamId });
// Check if glove data is retrieved successfully
if (gloveData != null)
{
// Update g_playersGlove dictionary with glove data
WeaponPaints.g_playersGlove[(uint)player.Index] = gloveData.Value;
}
}
catch (Exception e)
{
// Log any exceptions occurred during database operation
Utility.Log("An error occurred while fetching glove data: " + e.Message);
}
}
internal async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
{
if (!_config.Additional.SkinEnabled) return;
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out _))
{
WeaponPaints.gPlayerWeaponsInfo[player.Index] = new ConcurrentDictionary<int, WeaponInfo>();
}
try
{
if (_config.GlobalShare)
{
var values = new Dictionary<string, string>
{
{ "server_id", _globalShareServerId.ToString() },
{ "steamid", player.SteamId },
{ "skins", "1" }
};
UriBuilder builder = new UriBuilder(_globalShareApi);
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
using (var httpClient = new HttpClient())
{
httpClient.BaseAddress = _globalShareApi;
var formContent = new FormUrlEncodedContent(values);
HttpResponseMessage response = await httpClient.GetAsync(builder.Uri);
if (response.IsSuccessStatusCode)
{
string responseBody = await response.Content.ReadAsStringAsync();
JArray jsonArray = JArray.Parse(responseBody);
if (jsonArray != null && jsonArray.Count > 0)
{
foreach (var weapon in jsonArray)
{
int? weaponDefIndex = weapon["weapon_defindex"]?.Value<int>();
int? weaponPaintId = weapon["weapon_paint_id"]?.Value<int>();
float? weaponWear = weapon["weapon_wear"]?.Value<float>();
int? weaponSeed = weapon["weapon_seed"]?.Value<int>();
if (weaponDefIndex != null && weaponPaintId != null && weaponWear != null && weaponSeed != null)
{
WeaponInfo weaponInfo = new WeaponInfo
{
Paint = weaponPaintId.Value,
Seed = weaponSeed.Value,
Wear = weaponWear.Value
};
WeaponPaints.gPlayerWeaponsInfo[player.Index][weaponDefIndex.Value] = weaponInfo;
}
}
}
return;
}
else
{
return;
}
}
}
await using var connection = await _database.GetConnectionAsync();
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
var playerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = player.SteamId });
foreach (var row in playerSkins)
{
int? weaponDefIndex = row.weapon_defindex;
int? weaponPaintId = row.weapon_paint_id;
float? weaponWear = row.weapon_wear;
int? weaponSeed = row.weapon_seed;
WeaponInfo weaponInfo = new WeaponInfo
{
Paint = weaponPaintId.HasValue ? weaponPaintId.Value : 0,
Seed = weaponSeed.HasValue ? weaponSeed.Value : 0,
Wear = weaponWear.HasValue ? weaponWear.Value : 0f
};
WeaponPaints.gPlayerWeaponsInfo[player.Index][weaponDefIndex.GetValueOrDefault()] = weaponInfo;
}
}
catch (Exception e)
{
Utility.Log(e.Message);
return;
}
}
internal async Task SyncKnifeToDatabase(PlayerInfo player, string knife)
{
if (!_config.Additional.KnifeEnabled) return;
try
{
await using var connection = await _database.GetConnectionAsync();
string query = "INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(@steamid, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
await connection.ExecuteAsync(query, new { steamid = player.SteamId, newKnife = knife });
}
catch (Exception e)
{
Utility.Log(e.Message);
}
}
internal async Task SyncGloveToDatabase(PlayerInfo player, ushort defindex)
{
if (!_config.Additional.GloveEnabled) return;
try
{
await using var connection = await _database.GetConnectionAsync();
string query = "INSERT INTO `wp_player_gloves` (`steamid`, `weapon_defindex`) VALUES(@steamid, @weapon_defindex, @paint) ON DUPLICATE KEY UPDATE `weapon_defindex` = @weapon_defindex";
await connection.ExecuteAsync(query, new { steamid = player.SteamId, weapon_defindex = defindex });
}
catch (Exception e)
{
Utility.Log(e.Message);
}
}
internal async Task SyncWeaponPaintsToDatabase(PlayerInfo player)
{
if (player == null || player.Index <= 0 || player.SteamId == null) return;
await using var connection = await _database.GetConnectionAsync();
if (!WeaponPaints.gPlayerWeaponsInfo.ContainsKey(player.Index))
return;
foreach (var weaponInfoPair in WeaponPaints.gPlayerWeaponsInfo[player.Index])
{
int weaponDefIndex = weaponInfoPair.Key;
WeaponInfo weaponInfo = weaponInfoPair.Value;
int paintId = weaponInfo.Paint;
float wear = weaponInfo.Wear;
int seed = weaponInfo.Seed;
string updateSql = "INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, " +
"`weapon_paint_id`, `weapon_wear`, `weapon_seed`) " +
"VALUES (@steamid, @weaponDefIndex, @paintId, @wear, @seed) " +
"ON DUPLICATE KEY UPDATE `weapon_paint_id` = @paintId, " +
"`weapon_wear` = @wear, `weapon_seed` = @seed";
var updateParams = new { steamid = player.SteamId, weaponDefIndex, paintId, wear, seed };
await connection.ExecuteAsync(updateSql, updateParams);
}
}
}
}

16
gamedata/gloves.json Normal file
View File

@@ -0,0 +1,16 @@
{
"CAttributeList_SetOrAddAttributeValueByName": {
"signatures": {
"library": "server",
"windows": "\\x40\\x53\\x41\\x56\\x41\\x57\\x48\\x81\\xEC\\x90\\x00\\x00\\x00\\x0F\\x29\\x74\\x24\\x70",
"linux": "\\x55\\x48\\x89\\xE5\\x41\\x57\\x41\\x56\\x49\\x89\\xFE\\x41\\x55\\x41\\x54\\x49\\x89\\xF4\\x53\\x48\\x83\\xEC\\x78"
}
},
"CBaseModelEntity_SetBodygroup": {
"signatures": {
"library": "server",
"windows": "\\x48\\x89\\x5C\\x24\\x08\\x48\\x89\\x74\\x24\\x10\\x57\\x48\\x83\\xEC\\x20\\x41\\x8B\\xF8\\x48\\x8B\\xF2\\x48\\x8B\\xD9\\xE8\\x2A\\x2A\\x2A\\x2A",
"linux": "\\x55\\x48\\x89\\xE5\\x41\\x56\\x49\\x89\\xF6\\x41\\x55\\x41\\x89\\xD5\\x41\\x54\\x49\\x89\\xFC\\x48\\x83\\xEC\\x08"
}
}
}

17
lang/en.json Normal file
View File

@@ -0,0 +1,17 @@
{
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
"wp_info_website": "Visit {lime}{0}{default} where you can change skins",
"wp_info_refresh": "Type {lime}!wp{default} to synchronize chosen skins",
"wp_info_knife": "Type {lime}!knife{default} to open knife menu",
"wp_info_glove": "Type {lime}!gloves{default} to open gloves menu",
"wp_command_cooldown": "{lightred}You can't refresh weapon paints right now",
"wp_command_refresh_done": "{lime}Refreshing weapon paints",
"wp_knife_menu_select": "You have chosen {lime}{0}{default} as your knife",
"wp_knife_menu_kill": "",
"wp_knife_menu_title": "Knife Menu",
"wp_glove_menu_select": "You have chosen {lime}{0}{default} as your glove",
"wp_glove_menu_title": "Gloves Menu",
"wp_skin_menu_weapon_title": "Weapon Menu",
"wp_skin_menu_skin_title": "Select skin for {lime}{0}{default}",
"wp_skin_menu_select": "You have chosen {lime}{0}{default} as your skin"
}

17
lang/lv.json Normal file
View File

@@ -0,0 +1,17 @@
{
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
"wp_info_website": "Apmeklējiet {lime}{0}{default}, kur varat mainīt ādas",
"wp_info_refresh": "Ievadiet {lime}!wp{default}, lai sinhronizētu izvēlētās ādas",
"wp_info_knife": "Ievadiet {lime}!knife{default}, lai atvērtu nazis izvēlni",
"wp_info_glove": "Ievadiet {lime}!gloves{default}, lai atvērtu cimdi izvēlni",
"wp_command_cooldown": "{lightred}Šobrīd jūs nevarat atjaunot ieroču ādas",
"wp_command_refresh_done": "{lime}Atjauno ieroču ādas",
"wp_knife_menu_select": "Jūs esat izvēlējies {lime}{0}{default} kā savu nazi",
"wp_knife_menu_kill": "",
"wp_knife_menu_title": "Nazis Izvēlne",
"wp_glove_menu_select": "Jūs esat izvēlējies {lime}{0}{default} kā savus cimdus",
"wp_glove_menu_title": "Cimdu Izvēlne",
"wp_skin_menu_weapon_title": "Ieroču Izvēlne",
"wp_skin_menu_skin_title": "Izvēlieties ādu {lime}{0}{default}",
"wp_skin_menu_select": "Jūs esat izvēlējies {lime}{0}{default} kā savu ādu"
}

17
lang/pl.json Normal file
View File

@@ -0,0 +1,17 @@
{
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
"wp_info_website": "Odwiedź {lime}{0}{default}, gdzie możesz zmieniać skórki",
"wp_info_refresh": "Wpisz {lime}!wp{default}, aby zsynchronizować wybrane skórki",
"wp_info_knife": "Wpisz {lime}!knife{default}, aby otworzyć menu noży",
"wp_info_glove": "Wpisz {lime}!gloves{default}, aby otworzyć menu rękawiczek",
"wp_command_cooldown": "{lightred}Nie możesz teraz odświeżyć skórek broni",
"wp_command_refresh_done": "{lime}Odświeżanie skórek broni",
"wp_knife_menu_select": "Wybrałeś {lime}{0}{default} jako swój nóż",
"wp_knife_menu_kill": "",
"wp_knife_menu_title": "Menu Noży",
"wp_glove_menu_select": "Wybrałeś {lime}{0}{default} jako swoje rękawiczki",
"wp_glove_menu_title": "Menu Rękawiczek",
"wp_skin_menu_weapon_title": "Menu Broni",
"wp_skin_menu_skin_title": "Wybierz skórkę dla {lime}{0}{default}",
"wp_skin_menu_select": "Wybrałeś {lime}{0}{default} jako swoją skórkę"
}

17
lang/pt-BR.json Normal file
View File

@@ -0,0 +1,17 @@
{
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
"wp_info_website": "Visite {lime}{0}{default}, onde você pode alterar skins",
"wp_info_refresh": "Digite {lime}!wp{default} para sincronizar as skins selecionadas",
"wp_info_knife": "Digite {lime}!knife{default} para abrir o menu de facas",
"wp_info_glove": "Digite {lime}!gloves{default} para abrir o menu de luvas",
"wp_command_cooldown": "{lightred}Você não pode atualizar as skins de arma agora",
"wp_command_refresh_done": "{lime}Atualizando as skins de arma",
"wp_knife_menu_select": "Você escolheu {lime}{0}{default} como sua faca",
"wp_knife_menu_kill": "",
"wp_knife_menu_title": "Menu de Facas",
"wp_glove_menu_select": "Você escolheu {lime}{0}{default} como suas luvas",
"wp_glove_menu_title": "Menu de Luvas",
"wp_skin_menu_weapon_title": "Menu de Armas",
"wp_skin_menu_skin_title": "Selecione uma skin para {lime}{0}{default}",
"wp_skin_menu_select": "Você escolheu {lime}{0}{default} como sua skin"
}

17
lang/pt-PT.json Normal file
View File

@@ -0,0 +1,17 @@
{
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
"wp_info_website": "Visite {lime}{0}{default}, onde pode alterar skins",
"wp_info_refresh": "Digite {lime}!wp{default} para sincronizar as skins selecionadas",
"wp_info_knife": "Digite {lime}!knife{default} para abrir o menu de facas",
"wp_info_glove": "Digite {lime}!gloves{default} para abrir o menu de luvas",
"wp_command_cooldown": "{lightred}Você não pode atualizar as skins de arma agora",
"wp_command_refresh_done": "{lime}Atualizando as skins de arma",
"wp_knife_menu_select": "Você escolheu {lime}{0}{default} como sua faca",
"wp_knife_menu_kill": "",
"wp_knife_menu_title": "Menu de Facas",
"wp_glove_menu_select": "Você escolheu {lime}{0}{default} como suas luvas",
"wp_glove_menu_title": "Menu de Luvas",
"wp_skin_menu_weapon_title": "Menu de Armas",
"wp_skin_menu_skin_title": "Selecione uma skin para {lime}{0}{default}",
"wp_skin_menu_select": "Você escolheu {lime}{0}{default} como sua skin"
}

17
lang/ru.json Normal file
View File

@@ -0,0 +1,17 @@
{
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
"wp_info_website": "Посетите {lime}{0}{default}, где вы можете изменить скины",
"wp_info_refresh": "Введите {lime}!wp{default}, чтобы синхронизировать выбранные скины",
"wp_info_knife": "Введите {lime}!knife{default}, чтобы открыть меню ножей",
"wp_info_glove": "Введите {lime}!gloves{default}, чтобы открыть меню перчаток",
"wp_command_cooldown": "{lightred}Вы не можете обновить скины оружия сейчас",
"wp_command_refresh_done": "{lime}Обновление скинов оружия",
"wp_knife_menu_select": "Вы выбрали {lime}{0}{default} в качестве вашего ножа",
"wp_knife_menu_kill": "",
"wp_knife_menu_title": "Меню Ножей",
"wp_glove_menu_select": "Вы выбрали {lime}{0}{default} в качестве ваших перчаток",
"wp_glove_menu_title": "Меню Перчаток",
"wp_skin_menu_weapon_title": "Меню Оружия",
"wp_skin_menu_skin_title": "Выберите скин для {lime}{0}{default}",
"wp_skin_menu_select": "Вы выбрали {lime}{0}{default} в качестве вашего скина"
}

17
lang/tr.json Normal file
View File

@@ -0,0 +1,17 @@
{
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
"wp_info_website": "Ziyaret edin {lime}{0}{default}, burada skinleri değiştirebilirsiniz",
"wp_info_refresh": "Senkronize edilen skinleri görmek için {lime}!wp{default} yazın",
"wp_info_knife": "Bıçak menüsünü açmak için {lime}!knife{default} yazın",
"wp_info_glove": "Eldiven menüsünü açmak için {lime}!gloves{default} yazın",
"wp_command_cooldown": "{lightred}Şu anda silah skinlerini yenileyemezsiniz",
"wp_command_refresh_done": "{lime}Silah skinleri yenileniyor",
"wp_knife_menu_select": "{lime}{0}{default} olarak bıçağınızı seçtiniz",
"wp_knife_menu_kill": "",
"wp_knife_menu_title": "Bıçak Menüsü",
"wp_glove_menu_select": "{lime}{0}{default} olarak eldiveninizi seçtiniz",
"wp_glove_menu_title": "Eldiven Menüsü",
"wp_skin_menu_weapon_title": "Silah Menüsü",
"wp_skin_menu_skin_title": "{lime}{0}{default} için bir skin seçin",
"wp_skin_menu_select": "{lime}{0}{default} olarak bir skin seçtiniz"
}

17
lang/ua.json Normal file
View File

@@ -0,0 +1,17 @@
{
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
"wp_info_website": "Відвідайте {lime}{0}{default}, де ви можете змінити шкури",
"wp_info_refresh": "Введіть {lime}!wp{default}, щоб синхронізувати обрані шкури",
"wp_info_knife": "Введіть {lime}!knife{default}, щоб відкрити меню ножів",
"wp_info_glove": "Введіть {lime}!gloves{default}, щоб відкрити меню рукавичок",
"wp_command_cooldown": "{lightred}Наразі ви не можете оновлювати шкіри зброї",
"wp_command_refresh_done": "{lime}Оновлення шкірок зброї",
"wp_knife_menu_select": "Ви вибрали {lime}{0}{default} як ваш ніж",
"wp_knife_menu_kill": "",
"wp_knife_menu_title": "Меню Ножів",
"wp_glove_menu_select": "Ви вибрали {lime}{0}{default} як ваші рукавички",
"wp_glove_menu_title": "Меню Рукавичок",
"wp_skin_menu_weapon_title": "Меню Зброї",
"wp_skin_menu_skin_title": "Виберіть шкіру для {lime}{0}{default}",
"wp_skin_menu_select": "Ви вибрали {lime}{0}{default} як вашу шкіру"
}

17
lang/zh-cn.json Normal file
View File

@@ -0,0 +1,17 @@
{
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
"wp_info_website": "访问 {lime}{0}{default},您可以更改皮肤",
"wp_info_refresh": "输入 {lime}!wp{default} 同步已选择的皮肤",
"wp_info_knife": "输入 {lime}!knife{default} 打开刀具菜单",
"wp_info_glove": "输入 {lime}!gloves{default} 打开手套菜单",
"wp_command_cooldown": "{lightred}您现在无法刷新武器皮肤",
"wp_command_refresh_done": "{lime}刷新武器皮肤",
"wp_knife_menu_select": "您已选择 {lime}{0}{default} 作为您的刀具",
"wp_knife_menu_kill": "",
"wp_knife_menu_title": "刀具菜单",
"wp_glove_menu_select": "您已选择 {lime}{0}{default} 作为您的手套",
"wp_glove_menu_title": "手套菜单",
"wp_skin_menu_weapon_title": "武器菜单",
"wp_skin_menu_skin_title": "为 {lime}{0}{default} 选择皮肤",
"wp_skin_menu_select": "您已选择 {lime}{0}{default} 作为您的皮肤"
}

View File

@@ -5,6 +5,8 @@ define('DB_NAME', '');
define('DB_USER', '');
define('DB_PASS', '');
define('WEB_STYLE_DARK', true);
define('STEAM_API_KEY', '');
define('STEAM_DOMAIN_NAME', '');
define('STEAM_LOGOUT_PAGE', '');

View File

@@ -4,7 +4,14 @@ class DataBase {
private $PDO;
public function __construct() {
$this->PDO = new PDO("mysql:host=".DB_HOST."; port=".DB_PORT."; dbname=".DB_NAME, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
try {
$this->PDO = new PDO("mysql:host=".DB_HOST."; port=".DB_PORT."; dbname=".DB_NAME, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}
catch(PDOException $ex)
{
echo "<div style='display: flex; flex-direction: column;align-items: center;justify-content: center;text-align: center;'><h2>Problem with database!</h2>";
die("<pre style='padding: 10px;text-wrap: balance; border: 2px solid #ed6bd3;background: #252525; color: #ed6bd3; width: 50%;'>" . $ex . "</pre>");
}
}
public function select($query, $bindings = []) {
$STH = $this->PDO->prepare($query);

101
website/class/utils.php Normal file
View File

@@ -0,0 +1,101 @@
<?php
class UtilsClass
{
public static function skinsFromJson(): array
{
$skins = [];
$json = json_decode(file_get_contents(__DIR__ . "/../data/skins.json"), true);
foreach ($json as $skin) {
$skins[(int) $skin['weapon_defindex']][(int) $skin['paint']] = [
'weapon_name' => $skin['weapon_name'],
'paint_name' => $skin['paint_name'],
'image_url' => $skin['image'],
];
}
return $skins;
}
public static function getWeaponsFromArray()
{
$weapons = [];
$temp = self::skinsFromJson();
foreach ($temp as $key => $value) {
if (key_exists($key, $weapons))
continue;
$weapons[$key] = [
'weapon_name' => $value[0]['weapon_name'],
'paint_name' => $value[0]['paint_name'],
'image_url' => $value[0]['image_url'],
];
}
return $weapons;
}
public static function getKnifeTypes()
{
$knifes = [];
$temp = self::getWeaponsFromArray();
foreach ($temp as $key => $weapon) {
if (
!in_array($key, [
500,
503,
505,
506,
507,
508,
509,
512,
514,
515,
516,
517,
518,
519,
520,
521,
522,
523,
525,
526
])
)
continue;
$knifes[$key] = [
'weapon_name' => $weapon['weapon_name'],
'paint_name' => rtrim(explode("|", $weapon['paint_name'])[0]),
'image_url' => $weapon['image_url'],
];
$knifes[0] = [
'weapon_name' => "weapon_knife",
'paint_name' => "Default knife",
'image_url' => "https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/website/img/skins/weapon_knife.png",
];
}
ksort($knifes);
return $knifes;
}
public static function getSelectedSkins(array $temp)
{
$selected = [];
foreach ($temp as $weapon) {
$selected[$weapon['weapon_defindex']] = [
'weapon_paint_id' => $weapon['weapon_paint_id'],
'weapon_seed' => $weapon['weapon_seed'],
'weapon_wear' => $weapon['weapon_wear'],
];
}
return $selected;
}
}

1
website/data/gloves.json Normal file

File diff suppressed because one or more lines are too long

12077
website/data/skins.json Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@ $weapons = array (
"weapon_aug" => 8,
"weapon_awp" => 9,
"weapon_famas" => 10,
"weapon_g3sg1" => 10,
"weapon_g3sg1" => 11,
"weapon_galilar" => 13,
"weapon_m249" => 14,
"weapon_m4a1" => 16,
@@ -53,7 +53,14 @@ $weapons = array (
"weapon_knife_stiletto" => 522,
"weapon_knife_widowmaker" => 523,
"weapon_knife_skeleton" => 525);
$json = json_decode(file_get_contents('skins.json'));
$
$json = json_decode(file_get_contents('https://bymykel.github.io/CSGO-API/api/en/skins.json'));
die(var_dump($json));
echo "<pre>";
foreach($json as $skin)
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 KiB

Some files were not shown because too many files have changed in this diff Show More