Compare commits
1272
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
842410e773 | ||
|
|
da3223bf41 | ||
|
|
292273002b | ||
|
|
1fa24557e3 | ||
|
|
38edc91857 | ||
|
|
faec98dc2c | ||
|
|
5eb6a120af | ||
|
|
510f82d908 | ||
|
|
b2d11a55de | ||
|
|
a5fc8c041e | ||
|
|
e47e196d81 | ||
|
|
c98574c426 | ||
|
|
3240285ed2 | ||
|
|
b41188c7c9 | ||
|
|
e7ac9b013d | ||
|
|
8ba0672cd9 | ||
|
|
b34de51b8c | ||
|
|
ce7dccfffb | ||
|
|
ae0585df42 | ||
|
|
2ed5b865e3 | ||
|
|
b9c639620c | ||
|
|
c8d4fab7d9 | ||
|
|
6eb5f8fa38 | ||
|
|
82cd96aef6 | ||
|
|
3723860af3 | ||
|
|
3069350df4 | ||
|
|
3523db0314 | ||
|
|
f2f10bc196 | ||
|
|
97801196df | ||
|
|
7b013d5097 | ||
|
|
42237ddc03 | ||
|
|
6182c33318 | ||
|
|
421c39bb6a | ||
|
|
809392d1dc | ||
|
|
73fd660ff4 | ||
|
|
36339c22ca | ||
|
|
65d0d1380e | ||
|
|
d75d410100 | ||
|
|
4ab75cc19c | ||
|
|
f7fd4fe4a7 | ||
|
|
bea10f0fb1 | ||
|
|
e078b2b542 | ||
|
|
0205f5988d | ||
|
|
b1ac6f9a80 | ||
|
|
001ea29ee8 | ||
|
|
704f64f467 | ||
|
|
65ce00763a | ||
|
|
8033a8e134 | ||
|
|
7d3f8117a0 | ||
|
|
35d2a648cf | ||
|
|
02c56a6a42 | ||
|
|
17eb8c2652 | ||
|
|
f3f696f16e | ||
|
|
42ce2ce4d5 | ||
|
|
f4a047d3d1 | ||
|
|
a36a449983 | ||
|
|
df6d637e13 | ||
|
|
a6a181a4e4 | ||
|
|
61dea382c9 | ||
|
|
8c0aa36bbd | ||
|
|
7b2eaa5a6e | ||
|
|
a99a7a3d54 | ||
|
|
f158621572 | ||
|
|
97861312a2 | ||
|
|
f63ee4d937 | ||
|
|
e4e49e0623 | ||
|
|
261dd2c126 | ||
|
|
b68a60976c | ||
|
|
6156b61949 | ||
|
|
d22e6ae8da | ||
|
|
5a00b8c9d4 | ||
|
|
be74c9f23e | ||
|
|
bf0f9986f4 | ||
|
|
84c633c4da | ||
|
|
83521ba442 | ||
|
|
1033441f22 | ||
|
|
9faf4aaa85 | ||
|
|
3407d52723 | ||
|
|
d2eedc0e31 | ||
|
|
2c8fe40610 | ||
|
|
8bc615f29b | ||
|
|
e851097670 | ||
|
|
cfa6193bb8 | ||
|
|
bc69fc9f8e | ||
|
|
1a59e55723 | ||
|
|
38e88b5dcc | ||
|
|
ce2e55c40d | ||
|
|
19d21bc2d3 | ||
|
|
29594aeb0b | ||
|
|
470fda6af4 | ||
|
|
cdedec7606 | ||
|
|
a2d2875fc9 | ||
|
|
f881c5e343 | ||
|
|
e90c1db855 | ||
|
|
c7fb295eab | ||
|
|
d49ed86a1d | ||
|
|
da192501d1 | ||
|
|
d7d969774e | ||
|
|
575aa6ab4a | ||
|
|
0732992c4f | ||
|
|
bd1bde7def | ||
|
|
d9128d874b | ||
|
|
35f8289ef7 | ||
|
|
c9465bc4e1 | ||
|
|
cd5f7a61c2 | ||
|
|
fc47482dd3 | ||
|
|
aba1ecf738 | ||
|
|
3db7e85dff | ||
|
|
119d4b83c9 | ||
|
|
18975ff48f | ||
|
|
0cdcc3b08d | ||
|
|
5497e0dcf2 | ||
|
|
3070a1c26f | ||
|
|
0cc33d4bad | ||
|
|
731b9689bd | ||
|
|
c5dd056c84 | ||
|
|
e1f7d25603 | ||
|
|
1ed87af40c | ||
|
|
f5cea78b45 | ||
|
|
87a325f68e | ||
|
|
0cca99ea86 | ||
|
|
be89b25d96 | ||
|
|
434cb93dce | ||
|
|
46458cdbfe | ||
|
|
518f1f6f51 | ||
|
|
2c782ef842 | ||
|
|
e6886ba565 | ||
|
|
98236c5fca | ||
|
|
0002aa228c | ||
|
|
0e017393d5 | ||
|
|
be192f9807 | ||
|
|
6cec5c95aa | ||
|
|
1df5897c1a | ||
|
|
b8e7d0e373 | ||
|
|
a06f902ee1 | ||
|
|
e87291362b | ||
|
|
483cd9f5a8 | ||
|
|
05878c1e83 | ||
|
|
e4bdde6475 | ||
|
|
7c5da6a658 | ||
|
|
3fd0fc0a5c | ||
|
|
047dd0dec1 | ||
|
|
5acd8c77c9 | ||
|
|
468760c902 | ||
|
|
e70cddfe3e | ||
|
|
890c7119fe | ||
|
|
fba9d713b7 | ||
|
|
5288927964 | ||
|
|
07735c1fe2 | ||
|
|
6739b0c280 | ||
|
|
b1189479ed | ||
|
|
87d668afce | ||
|
|
707a6f5a00 | ||
|
|
f51522d2c9 | ||
|
|
c11164c4d9 | ||
|
|
9569066b6e | ||
|
|
c6038c76a6 | ||
|
|
3258ad0781 | ||
|
|
f0cb2ed5c2 | ||
|
|
5d28ea6162 | ||
|
|
af4bb473e7 | ||
|
|
94adc98ef5 | ||
|
|
7f2528d0fa | ||
|
|
817696358b | ||
|
|
81ebd8cf8d | ||
|
|
1bc536fdfa | ||
|
|
80ca6f8cd4 | ||
|
|
feaeb6a0ea | ||
|
|
a3fb4dfe5e | ||
|
|
337b755f34 | ||
|
|
a3f0b99d67 | ||
|
|
4f7b26f73b | ||
|
|
067ee97d99 | ||
|
|
98079197a0 | ||
|
|
c3a8b0e127 | ||
|
|
5d0a208e34 | ||
|
|
92db2a1987 | ||
|
|
16dc3daa8a | ||
|
|
d5cc622227 | ||
|
|
59ecab555b | ||
|
|
b697537378 | ||
|
|
eb323b7fa5 | ||
|
|
a327a80fcd | ||
|
|
6bb0b3aaa6 | ||
|
|
e359863e10 | ||
|
|
6162312fb7 | ||
|
|
0ecab49059 | ||
|
|
acaa301eda | ||
|
|
8d3bec0ca0 | ||
|
|
1b32e25d20 | ||
|
|
0c9a476851 | ||
|
|
ce8125b896 | ||
|
|
155cdc318c | ||
|
|
b492426a79 | ||
|
|
2b5554a21d | ||
|
|
2e395c6787 | ||
|
|
c8a9ae2f81 | ||
|
|
61d7e53cca | ||
|
|
465a3ff10b | ||
|
|
617ee1c98e | ||
|
|
a5a8e03d2d | ||
|
|
0d299402b9 | ||
|
|
eddc83054c | ||
|
|
ea1e3ac8d6 | ||
|
|
86fde36542 | ||
|
|
29386a72f6 | ||
|
|
8907569dd8 | ||
|
|
22d740ef61 | ||
|
|
6baf01ac3b | ||
|
|
c310db4b95 | ||
|
|
733e33e82a | ||
|
|
6e6f6e7479 | ||
|
|
865dd3ecd6 | ||
|
|
69f694d47c | ||
|
|
1819f491b5 | ||
|
|
c4d5235217 | ||
|
|
6439769d50 | ||
|
|
0c900be7fc | ||
|
|
bc8d02c998 | ||
|
|
1fc841713e | ||
|
|
84f67fcd2d | ||
|
|
eb3b4d9822 | ||
|
|
a401d97b09 | ||
|
|
74e9cdd709 | ||
|
|
2ae0d05a23 | ||
|
|
22cc68808c | ||
|
|
9952f62a33 | ||
|
|
f382c3fb5b | ||
|
|
4374cb2168 | ||
|
|
98831a8667 | ||
|
|
66d3f5e60e | ||
|
|
0ccf21ecb6 | ||
|
|
c9ee066a1d | ||
|
|
42c5444a10 | ||
|
|
e4fda1bd78 | ||
|
|
e55747a9e4 | ||
|
|
351917be35 | ||
|
|
063734607f | ||
|
|
19dce02a9c | ||
|
|
e56a1ac2ef | ||
|
|
9b6e36f6cd | ||
|
|
5615db767f | ||
|
|
0242508c19 | ||
|
|
512e7c37c1 | ||
|
|
5c1a5e35b9 | ||
|
|
392f0a92c7 | ||
|
|
92fb9f62dd | ||
|
|
e978992ba2 | ||
|
|
8c8dcdbe66 | ||
|
|
4afbf9d573 | ||
|
|
6f0fde48f3 | ||
|
|
20642a8518 | ||
|
|
64a8c20243 | ||
|
|
f9929ef9ac | ||
|
|
381198137f | ||
|
|
53e3331f0b | ||
|
|
ec7aadc431 | ||
|
|
7e784d5453 | ||
|
|
6d13a70b99 | ||
|
|
7f4c5512a9 | ||
|
|
b0cf46521b | ||
|
|
ecf33e313f | ||
|
|
3b9d03e015 | ||
|
|
cf1c95e42e | ||
|
|
4d1e265a5c | ||
|
|
34a204be59 | ||
|
|
ed2bb90ca5 | ||
|
|
c7410e3a35 | ||
|
|
f7e51b6110 | ||
|
|
2a25025d2e | ||
|
|
a35e22c76e | ||
|
|
30da01763d | ||
|
|
f896c4a24d | ||
|
|
5e3dc6c6c4 | ||
|
|
7cb61fe7c3 | ||
|
|
7fc48b8efe | ||
|
|
87653bf780 | ||
|
|
d5e05fae59 | ||
|
|
221732682b | ||
|
|
a7e206a24e | ||
|
|
b71d3c0174 | ||
|
|
75f4fdac40 | ||
|
|
636a3d7b37 | ||
|
|
e24d494467 | ||
|
|
63b0586c0f | ||
|
|
1e85181f0a | ||
|
|
950f949a51 | ||
|
|
6faaefdc69 | ||
|
|
f1721409c9 | ||
|
|
c730598960 | ||
|
|
5d468dd2c0 | ||
|
|
2382453d50 | ||
|
|
3b9c74ce96 | ||
|
|
6cd5bf87d8 | ||
|
|
25faf18760 | ||
|
|
f6737a4760 | ||
|
|
b5e077c6f7 | ||
|
|
2a3964a861 | ||
|
|
9a03d1227f | ||
|
|
60d7f605cb | ||
|
|
8fc2f39d37 | ||
|
|
03ac4d728d | ||
|
|
755fa4d5f3 | ||
|
|
24679be81a | ||
|
|
cb0f8f0eaa | ||
|
|
a8c91db585 | ||
|
|
74f1f8f6bb | ||
|
|
a44cfe134a | ||
|
|
57bdd9fdb0 | ||
|
|
d8d1a06ee4 | ||
|
|
3cd6ce9bb0 | ||
|
|
52211de8e9 | ||
|
|
4004471d8d | ||
|
|
d2296e463b | ||
|
|
f586bc2f07 | ||
|
|
699f876473 | ||
|
|
0fcbe934ff | ||
|
|
bd157080dc | ||
|
|
f086c0a638 | ||
|
|
c30f033022 | ||
|
|
a16ba7ca7b | ||
|
|
932010e63c | ||
|
|
34ddf6d2c8 | ||
|
|
29bff12b23 | ||
|
|
2be15ff629 | ||
|
|
34e9605519 | ||
|
|
6c3486d732 | ||
|
|
1d8e90cdda | ||
|
|
600f493e69 | ||
|
|
8acb60947c | ||
|
|
6b6dbc6c06 | ||
|
|
0a6fa1052a | ||
|
|
3bc55e6890 | ||
|
|
80dfa1cc77 | ||
|
|
b9f85c8e74 | ||
|
|
1fbe066328 | ||
|
|
4e15a92984 | ||
|
|
4e6d66b721 | ||
|
|
dd3409bb9b | ||
|
|
96727a7610 | ||
|
|
4cc214e1a6 | ||
|
|
b7feeef350 | ||
|
|
b18c8cbfd6 | ||
|
|
ae789148b1 | ||
|
|
ef9d2fda9d | ||
|
|
09bde65dfc | ||
|
|
02e85b3d98 | ||
|
|
fccf275194 | ||
|
|
5edfa79543 | ||
|
|
b6d98c762c | ||
|
|
d42a8c7c1e | ||
|
|
11d3cf94f7 | ||
|
|
0e4b1ca4cf | ||
|
|
1bcc5b8a44 | ||
|
|
7df2f8e045 | ||
|
|
9f3584a056 | ||
|
|
4e73713fab | ||
|
|
e07c120cab | ||
|
|
e3734803f0 | ||
|
|
7c757ac119 | ||
|
|
c5425def7f | ||
|
|
e60c672485 | ||
|
|
908ffdb523 | ||
|
|
d56dc62e03 | ||
|
|
f08f1ef0d6 | ||
|
|
5cb2d68fd7 | ||
|
|
96d0959db1 | ||
|
|
5a6b2c8ebf | ||
|
|
343f64f6b7 | ||
|
|
f9ad35badf | ||
|
|
60b6a8dfb0 | ||
|
|
00f3970036 | ||
|
|
7d78c141e7 | ||
|
|
123ad7aab1 | ||
|
|
ee51162c3f | ||
|
|
af93d819c6 | ||
|
|
d426d1f04f | ||
|
|
6cac489fce | ||
|
|
5c507cc35c | ||
|
|
dbec0b165c | ||
|
|
4e8b66bf99 | ||
|
|
8dcbe14ea0 | ||
|
|
06dcb991e8 | ||
|
|
e262064fd8 | ||
|
|
a80b9c5c0f | ||
|
|
638aae0040 | ||
|
|
35ac74c7a7 | ||
|
|
7bb9da2a26 | ||
|
|
b5b9b8388c | ||
|
|
e7e92d4e40 | ||
|
|
33e869a4e5 | ||
|
|
0bc9aa46e6 | ||
|
|
80ad76a563 | ||
|
|
7e29f22f8f | ||
|
|
a9eb3a0d45 | ||
|
|
ab6b45b81c | ||
|
|
385eae892c | ||
|
|
5f309f45f8 | ||
|
|
a2e5e2a442 | ||
|
|
b42e5ac922 | ||
|
|
544204654d | ||
|
|
5c971fd51b | ||
|
|
6507d947cc | ||
|
|
30415e299e | ||
|
|
8eeea2aba1 | ||
|
|
bb1431cd3b | ||
|
|
a2aec9b42e | ||
|
|
ef74b51c8b | ||
|
|
e74aa099bc | ||
|
|
8140cb2d6b | ||
|
|
d981e252d2 | ||
|
|
e6a04abc9e | ||
|
|
c90477a720 | ||
|
|
11c8084ccd | ||
|
|
7747beb4cf | ||
|
|
9fa7421122 | ||
|
|
f2ca671d1f | ||
|
|
d4da21b07f | ||
|
|
4b2d8b53fa | ||
|
|
7bfd5e521e | ||
|
|
060c832f89 | ||
|
|
8c9fd3746b | ||
|
|
314184beea | ||
|
|
17462cbe5a | ||
|
|
ae4e043c3e | ||
|
|
6def79ff23 | ||
|
|
1ba7024a3a | ||
|
|
44aaaf8b10 | ||
|
|
62754333cd | ||
|
|
8938a29904 | ||
|
|
2c6ef5825f | ||
|
|
b090aa36bf | ||
|
|
cb1dae5aab | ||
|
|
c9e824632f | ||
|
|
0436fb0ab3 | ||
|
|
767c5cf468 | ||
|
|
f01ad5317a | ||
|
|
fac3138ff5 | ||
|
|
ab9e86910c | ||
|
|
e88e9342ef | ||
|
|
e3a01b0e1a | ||
|
|
07d928dbad | ||
|
|
a402b3cceb | ||
|
|
99dbe06d8a | ||
|
|
29694ec13b | ||
|
|
1e8db957bf | ||
|
|
0656696251 | ||
|
|
af04c964fe | ||
|
|
bc81361319 | ||
|
|
853bcf703a | ||
|
|
c81248004a | ||
|
|
79787cb868 | ||
|
|
20aae06f12 | ||
|
|
a20eb08dc6 | ||
|
|
8d60a46358 | ||
|
|
4c376cbcb7 | ||
|
|
d83c498a8f | ||
|
|
531b053096 | ||
|
|
0dafe04899 | ||
|
|
7170a8f11c | ||
|
|
2ef874dbc9 | ||
|
|
cb8541548b | ||
|
|
46e3de8d24 | ||
|
|
5addaffa56 | ||
|
|
f40ae82df4 | ||
|
|
6ebf04b75d | ||
|
|
e93dd7af3f | ||
|
|
4dc2383fe3 | ||
|
|
5f827089d3 | ||
|
|
8a7f8c5cbd | ||
|
|
dae8aba554 | ||
|
|
b9029dedff | ||
|
|
1a375bcc17 | ||
|
|
eaccec3e4a | ||
|
|
5fff988a8f | ||
|
|
1a1bb54c4f | ||
|
|
97f2fc9d7f | ||
|
|
2e1235a585 | ||
|
|
426c1a090f | ||
|
|
50b4ad4e11 | ||
|
|
a330d0a1bf | ||
|
|
4e6774befb | ||
|
|
b1b993989a | ||
|
|
2e59202ea4 | ||
|
|
4a6d29c9e2 | ||
|
|
e746fdf1fb | ||
|
|
cac7793f15 | ||
|
|
e0c95674c8 | ||
|
|
bc42cef765 | ||
|
|
680a198fa2 | ||
|
|
38f7be7664 | ||
|
|
94f5b5d06c | ||
|
|
f66a904c31 | ||
|
|
8e0039aaec | ||
|
|
dd1e5997f3 | ||
|
|
bc6e920213 | ||
|
|
a28c3cac9b | ||
|
|
6670b93cc6 | ||
|
|
8826663186 | ||
|
|
c5087d7a39 | ||
|
|
5ba9816377 | ||
|
|
4eecc80b9a | ||
|
|
008fbf78a5 | ||
|
|
48150e0c7a | ||
|
|
d8fd60b562 | ||
|
|
178658912e | ||
|
|
5539484f92 | ||
|
|
a9a1939f75 | ||
|
|
850f96b986 | ||
|
|
693e584dcd | ||
|
|
397b70add0 | ||
|
|
a0eb6a9550 | ||
|
|
6bd49ff415 | ||
|
|
43cdc65708 | ||
|
|
cd6886319c | ||
|
|
6e839a95c6 | ||
|
|
2dcee81f22 | ||
|
|
a253d35bcd | ||
|
|
02e9d214b4 | ||
|
|
30a2160839 | ||
|
|
d57d7e7401 | ||
|
|
1f5b735dbd | ||
|
|
d5a26adc49 | ||
|
|
221d34f809 | ||
|
|
8922ed0c5d | ||
|
|
27b1817b10 | ||
|
|
3a488f7041 | ||
|
|
8f7a1641fc | ||
|
|
b0799d3336 | ||
|
|
2130c60fd9 | ||
|
|
ecb707e38d | ||
|
|
7e94bfb307 | ||
|
|
51bba0b894 | ||
|
|
775d4f04f2 | ||
|
|
4320d7b17a | ||
|
|
174bf307a2 | ||
|
|
f8349e846a | ||
|
|
ef7d3abefd | ||
|
|
b77e8c50ac | ||
|
|
0d6179299c | ||
|
|
515df38b72 | ||
|
|
c5e69900f9 | ||
|
|
2d5bc4007f | ||
|
|
3a315e88c2 | ||
|
|
6c5a3fdaf2 | ||
|
|
02f188899e | ||
|
|
aab8c6ac9f | ||
|
|
5d391fda07 | ||
|
|
8538233985 | ||
|
|
3b4a343274 | ||
|
|
f90b7ade76 | ||
|
|
83a29cf82b | ||
|
|
89bd4d7329 | ||
|
|
ed662dc8cf | ||
|
|
6574dd8273 | ||
|
|
63f8ea89ca | ||
|
|
34c8220e5d | ||
|
|
3595525f12 | ||
|
|
4989666d72 | ||
|
|
f7fda0023c | ||
|
|
13be211e9a | ||
|
|
f6b39720ec | ||
|
|
764e38a58f | ||
|
|
e34e9b9869 | ||
|
|
721f348684 | ||
|
|
9ddcd335af | ||
|
|
eda9a42ee2 | ||
|
|
22a964d89a | ||
|
|
855ece1d3b | ||
|
|
568da23c96 | ||
|
|
4015f9c1c9 | ||
|
|
21740d9a26 | ||
|
|
05aa3fd39d | ||
|
|
b1c8ad8412 | ||
|
|
3100e23b87 | ||
|
|
da3e868df5 | ||
|
|
63e0e2bc82 | ||
|
|
a35ecde538 | ||
|
|
81ad870def | ||
|
|
24f1c89b96 | ||
|
|
a761194917 | ||
|
|
9321229321 | ||
|
|
e5ebd65176 | ||
|
|
5f7b22d2a4 | ||
|
|
52da989762 | ||
|
|
625c7a98f2 | ||
|
|
278998f7d0 | ||
|
|
c29e185d2a | ||
|
|
5c66a78763 | ||
|
|
5e3a189642 | ||
|
|
7b89f5fab3 | ||
|
|
b0e7407552 | ||
|
|
407c24cb14 | ||
|
|
65cb76e2f6 | ||
|
|
678ad74bf4 | ||
|
|
12e20eecf7 | ||
|
|
a5ae01a2f4 | ||
|
|
614c7d8332 | ||
|
|
9121472061 | ||
|
|
54fd778830 | ||
|
|
37c2a83523 | ||
|
|
28a5d4b342 | ||
|
|
0dcfdf3d7e | ||
|
|
0f7f9dad97 | ||
|
|
4276301499 | ||
|
|
d41ffaad7e | ||
|
|
5c0ae11a46 | ||
|
|
7424deefb9 | ||
|
|
c92354debb | ||
|
|
50eca8e60c | ||
|
|
c570150318 | ||
|
|
3bafc1e2f4 | ||
|
|
e28bf30b7d | ||
|
|
7becdc48d3 | ||
|
|
7a3d4e70bf | ||
|
|
6e73aba250 | ||
|
|
5797411b2b | ||
|
|
d2c4257c36 | ||
|
|
b057580a62 | ||
|
|
a1ad9e1acf | ||
|
|
a877a4475b | ||
|
|
441259e36a | ||
|
|
ab8bbbd118 | ||
|
|
39d604ae6c | ||
|
|
a7cb35c2af | ||
|
|
ff558b32e5 | ||
|
|
6b588fff61 | ||
|
|
3f3f1b8914 | ||
|
|
05e48ef866 | ||
|
|
6e1f095186 | ||
|
|
852703ccca | ||
|
|
01203a5a44 | ||
|
|
96ae65a96c | ||
|
|
9df93b0708 | ||
|
|
f307e44b79 | ||
|
|
dc8a22a76a | ||
|
|
8579e873ca | ||
|
|
addfb3c8a1 | ||
|
|
358bcca3a2 | ||
|
|
b209279589 | ||
|
|
5479084039 | ||
|
|
95ab60c4eb | ||
|
|
2111e90540 | ||
|
|
dc9c52bfd6 | ||
|
|
f5461df28c | ||
|
|
e5afdb4181 | ||
|
|
250dc1b206 | ||
|
|
f5f26e2dfe | ||
|
|
f7c54e9027 | ||
|
|
1ce828b6c8 | ||
|
|
c471e41dc7 | ||
|
|
afc9310704 | ||
|
|
bf898dd45f | ||
|
|
7d6eb2bd81 | ||
|
|
547ac5b026 | ||
|
|
7328ce657b | ||
|
|
14c9ac8fdb | ||
|
|
93cd78a6c5 | ||
|
|
b62f332611 | ||
|
|
47f135534d | ||
|
|
bb095097a2 | ||
|
|
c873e1aafb | ||
|
|
455bb14589 | ||
|
|
e786ff54f7 | ||
|
|
af3c10b173 | ||
|
|
351ac171d2 | ||
|
|
96c74651db | ||
|
|
329d587214 | ||
|
|
4e3df76358 | ||
|
|
161084e6f8 | ||
|
|
b38c9824fe | ||
|
|
4e4c2a7bb0 | ||
|
|
1c30b88069 | ||
|
|
31f6c0cb18 | ||
|
|
9cb693d8a3 | ||
|
|
896e92264f | ||
|
|
f32b210ec9 | ||
|
|
8f7ecf66a4 | ||
|
|
581068c09b | ||
|
|
0f5f1a814e | ||
|
|
18f9d65938 | ||
|
|
589fc96bc9 | ||
|
|
5787fca029 | ||
|
|
09ea982bbd | ||
|
|
e3569edb65 | ||
|
|
3db7116620 | ||
|
|
83672a6ce0 | ||
|
|
90fec5c6df | ||
|
|
257535daf2 | ||
|
|
eb0878be2b | ||
|
|
f229badbfc | ||
|
|
9a6866d14a | ||
|
|
8991b557ab | ||
|
|
be60a55aa3 | ||
|
|
10795fbed5 | ||
|
|
9d7e720f33 | ||
|
|
7605940994 | ||
|
|
94ff26bdf1 | ||
|
|
2a06680252 | ||
|
|
38a069b97a | ||
|
|
4b58b9f673 | ||
|
|
ffc23a1a1e | ||
|
|
cab60f7385 | ||
|
|
92ce0fe814 | ||
|
|
79d594aca3 | ||
|
|
a343410793 | ||
|
|
3332da3489 | ||
|
|
1a65b308d1 | ||
|
|
f9309c83d2 | ||
|
|
636161e183 | ||
|
|
897878f8ae | ||
|
|
7650cee459 | ||
|
|
30c764e4b3 | ||
|
|
dc92335fbe | ||
|
|
8c625ca87d | ||
|
|
536750b428 | ||
|
|
11e7bb10f1 | ||
|
|
f7cd28cfd3 | ||
|
|
83c7bdf872 | ||
|
|
97383028e5 | ||
|
|
4a6d263dad | ||
|
|
549e881ba4 | ||
|
|
c72ea03a86 | ||
|
|
9fed0724f7 | ||
|
|
ed96da1afc | ||
|
|
da3146e294 | ||
|
|
5aa0cdfd45 | ||
|
|
0be7813398 | ||
|
|
de84f47503 | ||
|
|
115e3d4392 | ||
|
|
9f101ce67f | ||
|
|
9295bc4fbb | ||
|
|
9e083ec668 | ||
|
|
68c8857410 | ||
|
|
9323d1094f | ||
|
|
dc2967b2e7 | ||
|
|
6d85c09e69 | ||
|
|
6a8177145d | ||
|
|
baf686c6c4 | ||
|
|
34c5eed867 | ||
|
|
59840685a4 | ||
|
|
c4e33cab8c | ||
|
|
bf0741e48a | ||
|
|
51b5bbac0d | ||
|
|
03699a4a9e | ||
|
|
57a38636fc | ||
|
|
a5f99c57e1 | ||
|
|
1b0c7bc1b8 | ||
|
|
d84fd76070 | ||
|
|
677697a168 | ||
|
|
0fd4fa7066 | ||
|
|
0932d78d26 | ||
|
|
106f807b68 | ||
|
|
c3e6428ff7 | ||
|
|
78cb89938d | ||
|
|
f503139fae | ||
|
|
5ea096e61e | ||
|
|
f4ff2ad45a | ||
|
|
4fb57dc4e3 | ||
|
|
b8c5303b05 | ||
|
|
3c79701208 | ||
|
|
e82f88dfa9 | ||
|
|
296deb95e6 | ||
|
|
c6917296d3 | ||
|
|
b3672916de | ||
|
|
7c3cb49dfa | ||
|
|
b383302128 | ||
|
|
32d951e312 | ||
|
|
f8f5a18d67 | ||
|
|
2d241316c7 | ||
|
|
6a2ac9800b | ||
|
|
39aa75436e | ||
|
|
f708842e09 | ||
|
|
86af9601bd | ||
|
|
5b7c9c5845 | ||
|
|
7f2fdf3fe1 | ||
|
|
70c9a6528a | ||
|
|
54364d213d | ||
|
|
4d6b9895d3 | ||
|
|
f927455778 | ||
|
|
6928d21bcf | ||
|
|
38eecd5ece | ||
|
|
5aedb73aae | ||
|
|
387b85406e | ||
|
|
823b55c22a | ||
|
|
fdfb8837d1 | ||
|
|
d7c359c412 | ||
|
|
82c51dbe75 | ||
|
|
77259acf9e | ||
|
|
7816379aae | ||
|
|
d192527707 | ||
|
|
b0563a493c | ||
|
|
c38d45b9e7 | ||
|
|
f603b7aec3 | ||
|
|
a9d3cf4574 | ||
|
|
3b2fa89926 | ||
|
|
0d956b229f | ||
|
|
d73f4e7eca | ||
|
|
2778b132f0 | ||
|
|
1eae765dc3 | ||
|
|
267eb90da5 | ||
|
|
8075ce8371 | ||
|
|
d01c72f79b | ||
|
|
8f73e5e5a1 | ||
|
|
62142197c1 | ||
|
|
ff43e60831 | ||
|
|
6b9037790a | ||
|
|
babc6abc64 | ||
|
|
66d932c79f | ||
|
|
7be2f50a98 | ||
|
|
499f7160a4 | ||
|
|
7aca0cc77f | ||
|
|
c874703136 | ||
|
|
e6129ab2d9 | ||
|
|
4a43ac1bdd | ||
|
|
6b7fd8c3dc | ||
|
|
845c20ad93 | ||
|
|
47c050d5b6 | ||
|
|
1fbe5e1daa | ||
|
|
2b1cc43355 | ||
|
|
62cb6a0458 | ||
|
|
ca1dcc9bed | ||
|
|
5a72644486 | ||
|
|
e552466886 | ||
|
|
65043baf5d | ||
|
|
46c54f829c | ||
|
|
4dd5ab7576 | ||
|
|
ee27a48714 | ||
|
|
e5342afe2a | ||
|
|
3c30f7b971 | ||
|
|
99c39b1d57 | ||
|
|
ae485c3115 | ||
|
|
6c2be9bdcc | ||
|
|
1a11d92fd9 | ||
|
|
52c4d08e15 | ||
|
|
6ea1e39ee4 | ||
|
|
f9633a5f6f | ||
|
|
5bc48b2ab3 | ||
|
|
70b6e96f95 | ||
|
|
91a1fd074b | ||
|
|
a615c139e6 | ||
|
|
978fa6b252 | ||
|
|
24f90449ad | ||
|
|
ba8753836e | ||
|
|
e59fd9de96 | ||
|
|
6c4079cb94 | ||
|
|
c2b806563e | ||
|
|
15d912df38 | ||
|
|
a191a907e9 | ||
|
|
0caa349f6a | ||
|
|
1cd0efad41 | ||
|
|
9d49bbfaf0 | ||
|
|
3eb2cd2971 | ||
|
|
8e7d41ec02 | ||
|
|
94ea925152 | ||
|
|
18d93ff677 | ||
|
|
d48cf93a94 | ||
|
|
104b6b878a | ||
|
|
90b68f095f | ||
|
|
6a4364d404 | ||
|
|
5e819f6596 | ||
|
|
eef96da641 | ||
|
|
c38b392fdf | ||
|
|
e0d9dfb68e | ||
|
|
589d6df75d | ||
|
|
6fd9d1ce11 | ||
|
|
ef36604666 | ||
|
|
db56b14637 | ||
|
|
b14c18ee64 | ||
|
|
2c94ab3b1c | ||
|
|
f12b3a2e13 | ||
|
|
ea3f55f030 | ||
|
|
6e2c5a66b3 | ||
|
|
0bed34e0c7 | ||
|
|
f0d8a70b38 | ||
|
|
9acf2b5cda | ||
|
|
d49b92603a | ||
|
|
aa01a22416 | ||
|
|
50e43a9f98 | ||
|
|
ed325c7208 | ||
|
|
aac2c4a080 | ||
|
|
785c6aa1cf | ||
|
|
1b86c8564d | ||
|
|
031f80f6e1 | ||
|
|
6f21138489 | ||
|
|
7bab9cc344 | ||
|
|
510bd261f8 | ||
|
|
c5619f887d | ||
|
|
bb25b03884 | ||
|
|
9bbbf60268 | ||
|
|
37355f9c57 | ||
|
|
af76f757b5 | ||
|
|
b7650b11d6 | ||
|
|
a0d06b3209 | ||
|
|
c52edbd863 | ||
|
|
7355e34946 | ||
|
|
5fa25e70ad | ||
|
|
b8ae4e617b | ||
|
|
353ced0e41 | ||
|
|
ed9f214256 | ||
|
|
939bdaf669 | ||
|
|
2d2ba818e7 | ||
|
|
2653a450fc | ||
|
|
a065773b6d | ||
|
|
4e0ae0cb5e | ||
|
|
611bad4036 | ||
|
|
4a4b9ce7f0 | ||
|
|
100f1e56ca | ||
|
|
69ae224938 | ||
|
|
287628bfee | ||
|
|
f27dc2f4f4 | ||
|
|
1282f13442 | ||
|
|
47514c7708 | ||
|
|
b364bf8b06 | ||
|
|
dea3ef70a2 | ||
|
|
1cc7d37189 | ||
|
|
3164af7e34 | ||
|
|
4c8103a4e1 | ||
|
|
2ebbf2774b | ||
|
|
15450a6d0c | ||
|
|
832519ab64 | ||
|
|
4e2806c951 | ||
|
|
7e0dd1fd41 | ||
|
|
2d971a9fb7 | ||
|
|
3b386379dd | ||
|
|
7b887ee9f6 | ||
|
|
67f0e4be60 | ||
|
|
80acff8d7d | ||
|
|
d5d4d78023 | ||
|
|
5d94f0bea8 | ||
|
|
e5ddbd9886 | ||
|
|
d525b466ec | ||
|
|
333227fad8 | ||
|
|
288a781555 | ||
|
|
979e410efc | ||
|
|
75fa198321 | ||
|
|
49669f6585 | ||
|
|
acf8782786 | ||
|
|
6d2e0aa684 | ||
|
|
032a30f676 | ||
|
|
c9f574c27b | ||
|
|
b725196a26 | ||
|
|
301bafa3f5 | ||
|
|
7a3e4054c7 | ||
|
|
7d7253c9cc | ||
|
|
c2df49ee33 | ||
|
|
a253e175bb | ||
|
|
15023777f4 | ||
|
|
ff018a9a5d | ||
|
|
f76cb94511 | ||
|
|
87cc42d348 | ||
|
|
5177cfdf97 | ||
|
|
13621a1274 | ||
|
|
bc89e54f6d | ||
|
|
5ed2f79217 | ||
|
|
3696a4cd9e | ||
|
|
8259bd316a | ||
|
|
6717f45469 | ||
|
|
44615b7ade | ||
|
|
f3200b2232 | ||
|
|
881cbcd45d | ||
|
|
30a4032067 | ||
|
|
5597fc56d3 | ||
|
|
adcc0efda6 | ||
|
|
d044b13ce4 | ||
|
|
d42c304a55 | ||
|
|
d876f04baf | ||
|
|
593552f8d6 | ||
|
|
25462071df | ||
|
|
1d98c3a782 | ||
|
|
7f239bb931 | ||
|
|
23efe26655 | ||
|
|
ece447182f | ||
|
|
6465bd83a4 | ||
|
|
e941c1acea | ||
|
|
ecad8f25a8 | ||
|
|
48c3a9f2fa | ||
|
|
d59edc5d0a | ||
|
|
17440fc4be | ||
|
|
bff8585411 | ||
|
|
6a307bfcee | ||
|
|
604942f0e7 | ||
|
|
22eeb2f3a5 | ||
|
|
cc6059a4b7 | ||
|
|
91480b6b91 | ||
|
|
4a8e0799bd | ||
|
|
bcd5e40842 | ||
|
|
9fb6430313 | ||
|
|
68e45f3583 | ||
|
|
a1ed47be87 | ||
|
|
ded3867605 | ||
|
|
2b6833f65d | ||
|
|
4d38f11367 | ||
|
|
a3dd25f354 | ||
|
|
4b0e73ca5a | ||
|
|
cd37354634 | ||
|
|
8a5d0a58e4 | ||
|
|
1a71f4fbde | ||
|
|
1534f8749b | ||
|
|
4ea85a9291 | ||
|
|
739c07ca9b | ||
|
|
452338dc11 | ||
|
|
b6a6387f16 | ||
|
|
4a8c869b7e | ||
|
|
c052eb3969 | ||
|
|
48ed38a8c1 | ||
|
|
fba71ed24d | ||
|
|
625650c160 | ||
|
|
9f4c6c61d9 | ||
|
|
9d978f5581 | ||
|
|
664b352559 | ||
|
|
cfa4998ac1 | ||
|
|
5efe6d0a42 | ||
|
|
e34fbcce0d | ||
|
|
8746b2fd7f | ||
|
|
4328627326 | ||
|
|
fc6925fa0a | ||
|
|
b5de3eb588 | ||
|
|
26422fd425 | ||
|
|
cd1a296e4f | ||
|
|
3ddf9f8a0d | ||
|
|
82df6087af | ||
|
|
bef8562de5 | ||
|
|
1000d419fc | ||
|
|
2a9deb6a64 | ||
|
|
351e406f85 | ||
|
|
d6e518838f | ||
|
|
9e39f18230 | ||
|
|
3dd1e5a318 | ||
|
|
23e1c0b71e | ||
|
|
a1436cd205 | ||
|
|
0d320b7922 | ||
|
|
b2a0d0e4da | ||
|
|
273f058da9 | ||
|
|
c6f751bb67 | ||
|
|
00b7ac5a39 | ||
|
|
c0686dc4f9 | ||
|
|
7ab3a3cfd9 | ||
|
|
c3102c7e9f | ||
|
|
77f4ddf2c2 | ||
|
|
06d327e76c | ||
|
|
2e28b036f8 | ||
|
|
024ae2b9ed | ||
|
|
8a4295d699 | ||
|
|
f05e39afe1 | ||
|
|
3b1fb85bb8 | ||
|
|
a405f85eee | ||
|
|
78511afa4c | ||
|
|
c37c4f830f | ||
|
|
4fe2ae780b | ||
|
|
e02e6bcb4f | ||
|
|
c7392aeded | ||
|
|
14247af323 | ||
|
|
32cb00a4c6 | ||
|
|
d93f6984cc | ||
|
|
207584818f | ||
|
|
7a42d6b564 | ||
|
|
94b3ca08a2 | ||
|
|
ab5f00b65b | ||
|
|
b8fd7db58d | ||
|
|
22635d8d35 | ||
|
|
fb9b284bcf | ||
|
|
5293815bf6 | ||
|
|
5868ffd04e | ||
|
|
8ce99e0540 | ||
|
|
efb02755bc | ||
|
|
fcafd0784c | ||
|
|
199802150b | ||
|
|
e47c1a840a | ||
|
|
14227c04b8 | ||
|
|
cf0a49881e | ||
|
|
527a998740 | ||
|
|
352f078b07 | ||
|
|
4f3c3175e6 | ||
|
|
81dc80fbd1 | ||
|
|
28036966a6 | ||
|
|
2164f5191e | ||
|
|
216ba8b4e9 | ||
|
|
9c55eed549 | ||
|
|
f9ce25a7fe | ||
|
|
7e418933e7 | ||
|
|
05b3fc0fb9 | ||
|
|
d7990596f9 | ||
|
|
86f974f242 | ||
|
|
6addc5c8dd | ||
|
|
15a7faeafd | ||
|
|
626963fc49 | ||
|
|
2e72fc115d | ||
|
|
26462f2848 | ||
|
|
9cd2a74271 | ||
|
|
e1648ba8f9 | ||
|
|
dae6d13f06 | ||
|
|
ccf1d7abbd | ||
|
|
b92381505a | ||
|
|
5ba6b1426b | ||
|
|
fc7453a6c7 | ||
|
|
ae00144e84 | ||
|
|
59baaf1123 | ||
|
|
e2eac382c0 | ||
|
|
dd81d7c78f | ||
|
|
e3f4d239f1 | ||
|
|
8f0527487f | ||
|
|
318b36cdcf | ||
|
|
f4b9dfb2e7 | ||
|
|
2e11d3400e | ||
|
|
364cd094d9 | ||
|
|
2af7600057 | ||
|
|
8031e42bda | ||
|
|
7f9ceaac06 | ||
|
|
ae0a03d438 | ||
|
|
d105ce778d | ||
|
|
653e9325fc | ||
|
|
5d7d7c122e | ||
|
|
45fb26d282 | ||
|
|
c501c837d0 | ||
|
|
590f71436f | ||
|
|
b7e252dfd6 | ||
|
|
a2246af121 | ||
|
|
3e454db2d8 | ||
|
|
b88e0d7875 | ||
|
|
821251b176 | ||
|
|
1b3599c189 | ||
|
|
5e7596dea6 | ||
|
|
ab7519530e | ||
|
|
faa10f52a8 | ||
|
|
53df09fbb7 | ||
|
|
c8f3035cb0 | ||
|
|
f465985370 | ||
|
|
470486ba7e | ||
|
|
9a4fe1c475 | ||
|
|
dd61223c0b | ||
|
|
c196082988 | ||
|
|
9e58476631 | ||
|
|
4bebdc18a2 | ||
|
|
a01529b210 | ||
|
|
0b35c84bf0 | ||
|
|
846a99e57f | ||
|
|
c28f957fb3 | ||
|
|
f0aec6b0b6 | ||
|
|
d79c5e0dfa | ||
|
|
cb8d92edeb | ||
|
|
db9925493a | ||
|
|
1b795a70b0 | ||
|
|
ccfd2ffe38 | ||
|
|
c1d235a59c | ||
|
|
b5320a4f8a | ||
|
|
a1271ec3a8 | ||
|
|
a659896f8a | ||
|
|
a4e169aa8f | ||
|
|
7dd733cf46 | ||
|
|
6eb319f46e | ||
|
|
3add38f665 | ||
|
|
34e91fbd81 | ||
|
|
a9ca1a2fd6 | ||
|
|
a21c7564c1 | ||
|
|
1ca4517f46 | ||
|
|
22b43e3869 | ||
|
|
fc14e37d0f | ||
|
|
7ed329c11f | ||
|
|
6ad6abd319 | ||
|
|
bece74491d | ||
|
|
990a02dbe0 | ||
|
|
75193e9ee9 | ||
|
|
a5b22498ce | ||
|
|
398522712e | ||
|
|
caf0914289 | ||
|
|
17700e45b0 | ||
|
|
ba8b42ef1b | ||
|
|
144fb907f1 | ||
|
|
e7c6b23439 | ||
|
|
a65c215217 | ||
|
|
7e3b1c395b | ||
|
|
3511d2a44d | ||
|
|
beaf812909 | ||
|
|
7068c3e865 | ||
|
|
255b9323cc | ||
|
|
d14c94c353 | ||
|
|
11abe77eed | ||
|
|
7d8dfb09d8 | ||
|
|
3baa703256 | ||
|
|
2b3159f418 | ||
|
|
72acca4b9e | ||
|
|
32d12ea4a6 | ||
|
|
e4862dade8 | ||
|
|
ed908b6545 | ||
|
|
a81b52a787 | ||
|
|
52cdbb4fc1 | ||
|
|
d0bf26135c | ||
|
|
4f2bb62ff9 | ||
|
|
28f1ea82b6 | ||
|
|
aaac0b9eb2 | ||
|
|
daee19d502 | ||
|
|
70145dfd74 | ||
|
|
c09b32010f | ||
|
|
85a1d3e78a | ||
|
|
a9c9da1066 | ||
|
|
2860f31cb0 | ||
|
|
54cf1337c1 | ||
|
|
dcde5927b1 | ||
|
|
c458d1e600 | ||
|
|
aae7161273 | ||
|
|
6287774d69 | ||
|
|
dc4d597fb9 | ||
|
|
9ceb1af4fe | ||
|
|
b9b6832a11 | ||
|
|
53c63def07 | ||
|
|
4f70185aef | ||
|
|
6fcb411fe4 | ||
|
|
9cc518e408 | ||
|
|
ddebc2a075 | ||
|
|
fe6abb0c48 | ||
|
|
90e66cbeef | ||
|
|
487e01e4ed | ||
|
|
25b3d8f354 | ||
|
|
d430bd2f5c | ||
|
|
e2767a3c80 | ||
|
|
7f552e4d75 | ||
|
|
cbcda61135 | ||
|
|
2904c87b62 | ||
|
|
cfdedce362 | ||
|
|
467d57059a | ||
|
|
c993712438 | ||
|
|
a69d18ae1c | ||
|
|
95dae67d5b | ||
|
|
f6a64da672 | ||
|
|
11b23a6d07 | ||
|
|
82f1c5a20b | ||
|
|
7e080d259e | ||
|
|
1ab6ab1e5c | ||
|
|
b0e7bab980 | ||
|
|
9b8d28de56 | ||
|
|
5611ec54a2 | ||
|
|
6c7e29cbdb | ||
|
|
118d6dc9b1 | ||
|
|
08fe840bfd | ||
|
|
4637cf9221 | ||
|
|
4fd68939d3 | ||
|
|
be6a930e82 | ||
|
|
956f264b85 | ||
|
|
0a91b1f5b1 | ||
|
|
a17b47a2dc | ||
|
|
2a8c390498 | ||
|
|
41ffe975fd | ||
|
|
5ac3390656 | ||
|
|
f9faf9e48c | ||
|
|
e57dce76e1 | ||
|
|
64a6972757 | ||
|
|
1293d15f72 | ||
|
|
12fca79006 | ||
|
|
55b8371fa8 | ||
|
|
a8080c0bbb | ||
|
|
8c61fdc99d | ||
|
|
9374620b8b | ||
|
|
5a35760215 | ||
|
|
6b257de75a | ||
|
|
40356fc9db | ||
|
|
de108cca44 | ||
|
|
5f5a6b3a16 | ||
|
|
29b1926432 | ||
|
|
e0a154faa0 | ||
|
|
1706fdfed9 | ||
|
|
945df342d8 | ||
|
|
bfb11c7712 | ||
|
|
fa7d8757dc | ||
|
|
3c7978153b | ||
|
|
7cb3d4d8ff | ||
|
|
870e118150 | ||
|
|
e27f8fba1a | ||
|
|
ce1a4dcac0 | ||
|
|
057a5790e2 | ||
|
|
87858ef264 | ||
|
|
98fea02eaa |
@@ -0,0 +1,12 @@
|
||||
# GitHub views all .h files as C, let's assume it's C++
|
||||
*.h linguist-language=c++
|
||||
|
||||
# Internal tools overriding
|
||||
tools/* linguist-vendored
|
||||
editor/* linguist-vendored
|
||||
|
||||
# Third-party overriding
|
||||
extensions/curl/curl-src/* linguist-vendored
|
||||
extensions/geoip/GeoIP.c linguist-vendored
|
||||
extensions/geoip/GeoIP.h linguist-vendored
|
||||
extensions/sqlite/sqlite-source/* linguist-vendored
|
||||
@@ -7,17 +7,17 @@ Please consider the following guidelines when reporting an issue.
|
||||
#### Not for general support
|
||||
This is not the right place to get help with using or installing SourceMod, or for issues with specific, third-party SourceMod plugins or extensions.
|
||||
|
||||
For help with SourceMod, please consult the [AlliedModders forums](https://forums.alliedmods.net/forumdisplay.php?f=52). Similary, for assistance with, or to report issues with third-party SourceMod plugins or extension, you should post in the existing thread for the plugin or extension at the [AlliedModders forums](https://forums.alliedmods.net/forumdisplay.php?f=52).
|
||||
For help with SourceMod, please consult the [AlliedModders forums](https://forums.alliedmods.net/forumdisplay.php?f=52). Similarly, for assistance with, or to report issues with, third-party SourceMod plugins or extensions, you should post in the existing thread for that plugin or extension on the [AlliedModders forums](https://forums.alliedmods.net/forumdisplay.php?f=52).
|
||||
|
||||
#### Details, details, details
|
||||
Provide as much detail as possible when reporting an issue.
|
||||
|
||||
For bugs or other undesired behavior, answers to the follow questions are a great start.
|
||||
For bugs or other undesired behavior, answers to the following questions are a great start:
|
||||
* What is the issue?
|
||||
* What behavior are you expecting instead?
|
||||
* On what operating system is the game server running?
|
||||
* What game is the game server running?
|
||||
* What exact (full x.y.z.a version number) version of Metamod:Source and SourceMod are installed on the game server?
|
||||
* What exact version (full x.y.z.a version number) of Metamod:Source and SourceMod are installed on the game server?
|
||||
* What is the specific, shortest path to reproducing this issue? If this issue can be reproduced with plugin code, please try to shorten it to the minimum required to trigger the problem.
|
||||
|
||||
If this is a feature request, the following are helpful. Generally, not all will apply, but whatever you can answer ahead of time will shorten back and forth conversation.
|
||||
@@ -29,18 +29,18 @@ If this is a feature request, the following are helpful. Generally, not all will
|
||||
Please report any security bugs to [[email protected]](mailto:[email protected]) rather than to this public issue tracker.
|
||||
|
||||
#### We're only human
|
||||
Please keep in mind that we maintain the project in our spare time, at no cost. There is no SLA, and you are not owed a response or fix.
|
||||
Please keep in mind that we maintain this project in our spare time, at no cost. There is no SLA, and you are not owed a response or a fix.
|
||||
|
||||
#### Conduct
|
||||
Please refer to the [AlliedModders forum rules.](https://forums.alliedmods.net/misc.php?do=showrules)
|
||||
|
||||
## Pull Requests
|
||||
|
||||
Firstly, thank you for considering to contribute changes to the project!
|
||||
Firstly, thank you for considering contributing changes to the project!
|
||||
|
||||
However, if this is anything more than a small fix such an a gamedata update, a glaring code flaw, or a simple typo in a file like this one, please file an issue first so that it can be discussed, unless you have already spoken to multiple members of the development team about it on IRC or the AlliedModders forums.
|
||||
However, if this is anything more than a small fix such as a gamedata update, a glaring code flaw, or a simple typo in a file like this one, please file an issue first so that it can be discussed, unless you have already spoken to multiple members of the development team about it on IRC or the AlliedModders forums.
|
||||
|
||||
We don't like to have to reject pull requests, so we want to avoid those scenarios. We wouldn't want you to feel that you wasted your time writing something only for us to have it then be shot down.
|
||||
We don't like to have to reject pull requests, so we want to avoid those scenarios. We wouldn't want you to feel like you wasted your time writing something only for us to shoot it down.
|
||||
|
||||
#### Rejection
|
||||
*Copied from Phabricator's [Contributing Code guidelines](https://secure.phabricator.com/book/phabcontrib/article/contributing_code/#rejecting-patches), as we largely feel the same way about this.*
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
custom: https://www.sourcemod.net/donate.php
|
||||
@@ -0,0 +1,116 @@
|
||||
name: Bug Report
|
||||
description: Create a report to help us improve
|
||||
title: "[Bug]: "
|
||||
labels: ["Bug"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this bug report! Please make sure you provide all the requested information to help us address the issue efficiently.
|
||||
|
||||
- type: checkboxes
|
||||
id: prerequisites
|
||||
attributes:
|
||||
label: Prerequisites
|
||||
description: Please confirm these before submitting your issue
|
||||
options:
|
||||
- label: I have checked that my issue doesn't exist yet in the [issue tracker](https://github.com/alliedmodders/sourcemod/issues)
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: os-version
|
||||
attributes:
|
||||
label: Operating System and Version
|
||||
description: What operating system and version are you using?
|
||||
placeholder: "e.g., Windows 10 21H2, Ubuntu 22.04"
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: game-version
|
||||
attributes:
|
||||
label: Game / AppID and Version
|
||||
description: Which game and version are you using?
|
||||
placeholder: "e.g., CS:GO (730) version 1.38.2.5"
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: sourcemod-version
|
||||
attributes:
|
||||
label: SourceMod Version
|
||||
description: On which version of SourceMod did you first observe this?
|
||||
placeholder: "e.g., 1.11.0.6936"
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: metamod-version
|
||||
attributes:
|
||||
label: Metamod:Source Version
|
||||
description: On which version of Metamod:Source did you first observe this?
|
||||
placeholder: "e.g., 1.11.0-git1145"
|
||||
|
||||
- type: checkboxes
|
||||
id: version-checks
|
||||
attributes:
|
||||
label: Version Verification
|
||||
description: Please confirm you've tested with the latest versions
|
||||
options:
|
||||
- label: I have updated SourceMod to the [latest version](https://www.sourcemod.net/downloads.php) and the issue persists
|
||||
- label: I have updated SourceMod to the [latest snapshot](https://www.sourcemod.net/downloads.php?branch=dev) and the issue persists
|
||||
- label: I have updated Metamod:Source to the [latest snapshot](https://sourcemm.net/downloads.php?branch=dev) and the issue persists
|
||||
|
||||
- type: input
|
||||
id: sourcemod-version-latest
|
||||
attributes:
|
||||
label: Updated SourceMod Version
|
||||
description: If you updated SourceMod to the latest version to confirm the issue persisted, which version was that?
|
||||
placeholder: "e.g., 1.11.0.6936"
|
||||
|
||||
- type: input
|
||||
id: metamod-version-latest
|
||||
attributes:
|
||||
label: Updated Metamod:Source Version
|
||||
description: If you updated Metamod:Source to the latest version to confirm the issue persisted, which version was that?
|
||||
placeholder: "e.g., 1.11.0-git1145"
|
||||
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Description
|
||||
description: Please provide a clear and concise description of the bug
|
||||
placeholder: What happened? What did you expect to happen?
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: reproduction
|
||||
attributes:
|
||||
label: Steps to Reproduce
|
||||
description: Please provide the code or steps needed to reproduce the issue
|
||||
placeholder: |
|
||||
*If possible, please include the smallest possible test-case to reproduce the issue.*
|
||||
|
||||
*Also, please make it clear whether or not you can consistently reproduce this issue with the provided description*
|
||||
|
||||
1. First step...
|
||||
2. Second step...
|
||||
3. ...
|
||||
|
||||
```sourcepawn
|
||||
// Add your code here if applicable
|
||||
```
|
||||
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Relevant Log Output
|
||||
description: |
|
||||
Please provide any relevant log output. This will be automatically formatted into code, so no need for backticks.
|
||||
Include:
|
||||
- Game output
|
||||
- Library logs
|
||||
- Kernel logs
|
||||
- Minidump or dump analyze output (in case of crashes)
|
||||
render: shell
|
||||
@@ -0,0 +1,8 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Get Help on Discord
|
||||
url: https://discord.gg/HUc67zN
|
||||
about: For general help or assistance, join the AlliedModders Discord or Forums instead of filing a bug
|
||||
- name: Get Help on the Forums
|
||||
url: https://forums.alliedmods.net
|
||||
about: For general help or assistance, join the AlliedModders Discord or Forums instead of filing a bug
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: Feature Request
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
## Help us help you
|
||||
- [ ] I have checked that my issue [doesn't exist yet](https://github.com/alliedmodders/sourcemod/issues).
|
||||
|
||||
## Is your feature request related to a problem? Please describe.
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
## Describe the solution you'd like
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
## Describe alternatives you've considered
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
## Additional context
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -0,0 +1,8 @@
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
# Check for updates to GitHub Actions every week
|
||||
interval: "weekly"
|
||||
@@ -0,0 +1,249 @@
|
||||
name: Build Release
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- '[0-9]+.[0-9]+-dev'
|
||||
env:
|
||||
ARCH: x86,x86_64
|
||||
DUMP_SYMS_VERSION: '2.3.7'
|
||||
# Used for caching
|
||||
# TODO: Handle this better so that we don't have to update this in lockstep with checkout-deps
|
||||
MARIADB_CONNECTOR_C_VERSION: '3.4.9'
|
||||
MARIADB_CONNECTOR_C_RELEASE: '3.4.9-sm.5'
|
||||
MMSOURCE_VERSION: '1.12'
|
||||
jobs:
|
||||
build:
|
||||
permissions:
|
||||
contents: write
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- platform: windows
|
||||
os: windows-latest
|
||||
os_short: win
|
||||
- platform: linux
|
||||
os: ubuntu-latest
|
||||
os_short: linux
|
||||
container_image: ghcr.io/alliedmodders/build-containers/debian11-clang22:latest
|
||||
fail-fast: false
|
||||
name: ${{ matrix.platform }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
container:
|
||||
image: ${{ matrix.container_image }}
|
||||
steps:
|
||||
- name: Checkout SourceMod
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
path: sourcemod
|
||||
fetch-depth: 0
|
||||
submodules: recursive
|
||||
|
||||
- name: Install Windows dependencies
|
||||
if: startsWith(matrix.os, 'windows')
|
||||
shell: pwsh
|
||||
run: |
|
||||
# Add DIA SDK bin directory to PATH for dump_syms
|
||||
# vswhere.exe is pre-installed on GitHub Windows runners
|
||||
$vsRoot = & vswhere -latest -property installationPath
|
||||
$diaDir = Join-Path $vsRoot 'DIA SDK\bin'
|
||||
$diaDir | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||
|
||||
$toolsDir = New-Item -Path '_tools' -ItemType Directory -Force
|
||||
$toolsDir.FullName | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||
Push-Location $toolsDir
|
||||
$dumpsymsUrl = "https://github.com/mozilla/dump_syms/releases/download/v${{ env.DUMP_SYMS_VERSION }}/dump_syms-x86_64-pc-windows-msvc.zip"
|
||||
curl -sSL -o dump_syms.zip $dumpsymsUrl
|
||||
Expand-Archive -Path dump_syms.zip -DestinationPath .
|
||||
Remove-Item dump_syms.zip
|
||||
# Flatten if extracted into a subdirectory
|
||||
Get-ChildItem -Recurse -Filter 'dump_syms.exe' | Move-Item -Destination . -ErrorAction SilentlyContinue
|
||||
Pop-Location
|
||||
|
||||
# Largely a workaround for issue where github.workspace doesn't match $GITHUB_WORKSPACE
|
||||
# in containerized jobs. See https://github.com/actions/runner/issues/2058
|
||||
- name: Resolve paths
|
||||
id: path_helper
|
||||
shell: bash
|
||||
run: |
|
||||
echo "dependencies=$GITHUB_WORKSPACE/dependencies" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Generate SDK list
|
||||
id: sdk_list
|
||||
shell: bash
|
||||
run: |
|
||||
sdk_list=()
|
||||
for file in sourcemod/hl2sdk-manifests/manifests/*.json; do
|
||||
sdk=$(basename "$file" .json)
|
||||
if [[ $sdk == "mock" ]]; then
|
||||
# We don't need to ship a build for the mock SDK
|
||||
continue
|
||||
fi
|
||||
|
||||
platform=$(jq -r '.platforms.${{ matrix.platform }}' "$file")
|
||||
if [[ -z $platform || $platform == "null" || ${#platform[@]} -eq 0 ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
source2=$(jq -r '.source2' "$file")
|
||||
if [[ $source2 == "null" || $source2 == "true" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
sdk_list+=("$sdk")
|
||||
done
|
||||
echo "sdk_list=$(printf '%s\n' "${sdk_list[@]}" | jq --raw-input . | jq --slurp --compact-output .)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v6
|
||||
env:
|
||||
cache-name: hl2sdk-mariadb-connector-c-mmsource
|
||||
with:
|
||||
path: ${{ steps.path_helper.outputs.dependencies }}
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-mmsource${{ env.MMSOURCE_VERSION }}-${{ join(fromJson(steps.sdk_list.outputs.sdk_list), '') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-mmsource${{ env.MMSOURCE_VERSION }}-
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-
|
||||
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
env:
|
||||
MAXMIND_LICENSE_KEY: ${{ secrets.MAXMIND_LICENSE_KEY }}
|
||||
run: |
|
||||
mkdir -p '${{ steps.path_helper.outputs.dependencies }}'
|
||||
cd '${{ steps.path_helper.outputs.dependencies }}'
|
||||
|
||||
# Satisfy checkout-deps requirement for a "sourcemod" folder.
|
||||
mkdir -p sourcemod
|
||||
../sourcemod/tools/checkout-deps.sh -s ${{ join(fromJson(steps.sdk_list.outputs.sdk_list), ',') }}
|
||||
|
||||
if [ -z "$MAXMIND_LICENSE_KEY" ]; then
|
||||
echo "::error::MAXMIND_LICENSE_KEY secret is not configured."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
geotmpdir=$(mktemp -d)
|
||||
geotar="$geotmpdir/GeoLite2-City.tar.gz"
|
||||
curl -fsSL "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=$MAXMIND_LICENSE_KEY&suffix=tar.gz" -o "$geotar"
|
||||
tar -xzf "$geotar" -C "$geotmpdir"
|
||||
geommdb=$(find "$geotmpdir" -type f -name 'GeoLite2-City.mmdb' | head -n 1)
|
||||
if [ -z "$geommdb" ]; then
|
||||
echo "::error::GeoLite2-City.mmdb not found in downloaded MaxMind archive."
|
||||
exit 1
|
||||
fi
|
||||
cp "$geommdb" '${{ steps.path_helper.outputs.dependencies }}/GeoLite2-City.mmdb'
|
||||
rm -rf "$geotmpdir"
|
||||
|
||||
- name: Build
|
||||
working-directory: sourcemod
|
||||
shell: bash
|
||||
env:
|
||||
BREAKPAD_SYMBOL_SERVER: ${{ vars.BREAKPAD_SYMBOL_SERVER }}
|
||||
BREAKPAD_SYMBOL_SERVER_TOKEN: ${{ secrets.BREAKPAD_SYMBOL_SERVER_TOKEN }}
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
python3 ../configure.py \
|
||||
--enable-optimize \
|
||||
--breakpad-dump \
|
||||
--symbol-files \
|
||||
--sdks=${{ join(fromJson(steps.sdk_list.outputs.sdk_list), ',') }} \
|
||||
--targets=${{ env.ARCH }} \
|
||||
'--mms-path=${{ steps.path_helper.outputs.dependencies }}/mmsource-${{ env.MMSOURCE_VERSION }}' \
|
||||
'--hl2sdk-root=${{ steps.path_helper.outputs.dependencies }}' \
|
||||
'--mariadb-path=${{ steps.path_helper.outputs.dependencies }}/mariadb-connector-c-${{ env.MARIADB_CONNECTOR_C_VERSION }}-x86' \
|
||||
'--mariadb64-path=${{ steps.path_helper.outputs.dependencies }}/mariadb-connector-c-${{ env.MARIADB_CONNECTOR_C_VERSION }}-x86_64'
|
||||
ambuild
|
||||
|
||||
mkdir -p package/addons/sourcemod/configs/geoip
|
||||
cp '${{ steps.path_helper.outputs.dependencies }}/GeoLite2-City.mmdb' package/addons/sourcemod/configs/geoip/GeoLite2-City.mmdb
|
||||
|
||||
- name: Package
|
||||
id: package
|
||||
working-directory: sourcemod/build/package
|
||||
shell: bash
|
||||
run: |
|
||||
version_base=$(cat ../../product.version)
|
||||
version_base=${version_base%-dev} # Ex. 1.12.0
|
||||
version_rev=$(git rev-list --count HEAD)
|
||||
version="${version_base}.${version_rev}"
|
||||
expanded_version="${version_base}-git${version_rev}"
|
||||
|
||||
if [ "${{ matrix.platform}}" == "windows" ]; then
|
||||
filename="sourcemod-${expanded_version}-${{ matrix.platform }}.zip"
|
||||
7z a "$filename" addons cfg
|
||||
content_type="application/zip"
|
||||
else
|
||||
filename="sourcemod-${expanded_version}-${{ matrix.platform }}.tar.gz"
|
||||
tar zcf "$filename" addons cfg
|
||||
content_type="application/gzip"
|
||||
fi
|
||||
echo "version=$version" >> $GITHUB_OUTPUT
|
||||
echo "expanded_version=$expanded_version" >> $GITHUB_OUTPUT
|
||||
echo "filename=$filename" >> $GITHUB_OUTPUT
|
||||
echo "content_type=$content_type" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
uses: ncipollo/[email protected]
|
||||
with:
|
||||
# Windows and Linux packages will need to upload to the same release
|
||||
allowUpdates: true
|
||||
replacesArtifacts: false
|
||||
omitBodyDuringUpdate: true
|
||||
omitDraftDuringUpdate: true
|
||||
omitNameDuringUpdate: true
|
||||
omitPrereleaseDuringUpdate: true
|
||||
|
||||
# This gets overly large and meaningless with our existing release patterns
|
||||
omitBody: true
|
||||
|
||||
artifacts: sourcemod/build/package/${{ steps.package.outputs.filename }}
|
||||
artifactContentType: ${{ steps.package.outputs.content_type }}
|
||||
artifactErrorsFailBuild: true
|
||||
|
||||
tag: ${{ steps.package.outputs.version }}
|
||||
commit: ${{ github.sha }}
|
||||
generateReleaseNotes: true
|
||||
|
||||
draft: false
|
||||
prerelease: ${{ github.ref == 'refs/heads/master' }}
|
||||
makeLatest: ${{ github.ref != 'refs/heads/master' }}
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Output PDBs
|
||||
if: startsWith(matrix.os, 'windows')
|
||||
shell: pwsh
|
||||
id: output_pdbs
|
||||
working-directory: sourcemod/build
|
||||
run: |
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$buildDir = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'sourcemod/build'
|
||||
$outDir = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'pdbs'
|
||||
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
|
||||
|
||||
Get-Content -LiteralPath (Join-Path -Path $buildDir -ChildPath 'pdblog.txt') |
|
||||
ForEach-Object -Process {
|
||||
$fullPdbPathInfo = (Get-Item -Path (Join-Path -Path $buildDir -ChildPath $_))
|
||||
$baseName = $fullPdbPathInfo.BaseName
|
||||
$dir = $fullPdbPathInfo.DirectoryName
|
||||
|
||||
$relDir = [System.IO.Path]::GetRelativePath($buildDir, $dir)
|
||||
$destDir = Join-Path $outDir $relDir
|
||||
New-Item -ItemType Directory -Force -Path $destDir | Out-Null
|
||||
|
||||
'.pdb', '.exe', '.dll' | ForEach-Object -Process {
|
||||
$binPath = Join-Path $dir ($baseName + $_)
|
||||
if (Test-Path $binPath) {
|
||||
Copy-Item -Path $binPath -Destination $destDir
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- name: Upload PDBs
|
||||
if: startsWith(matrix.os, 'windows')
|
||||
id: upload_pdbs
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: pdbs
|
||||
path: pdbs/*
|
||||
@@ -0,0 +1,61 @@
|
||||
name: Build and Push spcomp Container
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- '[0-9]+.[0-9]+-dev'
|
||||
tags:
|
||||
- '*'
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: ${{ github.ref != 'refs/heads/master' && !contains(github.ref, '-dev') }}
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}-spcomp
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Log in to the Container registry
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v6
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
file: ./containers/Containerfile.spcomp
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
@@ -0,0 +1,106 @@
|
||||
name: hl2sdk-mock tests
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- '[0-9]+.[0-9]+-dev'
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- '[0-9]+.[0-9]+-dev'
|
||||
jobs:
|
||||
mock:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/alliedmodders/build-containers/debian11-clang22:latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
name: Clone sourcemod
|
||||
with:
|
||||
submodules: recursive
|
||||
path: sourcemod
|
||||
|
||||
- uses: actions/checkout@v7
|
||||
name: Clone metamod-source
|
||||
with:
|
||||
repository: alliedmodders/metamod-source
|
||||
ref: 1.12-dev
|
||||
submodules: recursive
|
||||
path: metamod-source
|
||||
|
||||
- uses: actions/checkout@v7
|
||||
name: Clone hl2sdk-mock
|
||||
with:
|
||||
repository: alliedmodders/hl2sdk-mock
|
||||
submodules: recursive
|
||||
path: hl2sdk-mock
|
||||
|
||||
- name: Build MetaMod:Source
|
||||
working-directory: metamod-source
|
||||
run: |
|
||||
python3 configure.py --enable-optimize --sdks=mock --targets=x86,x86_64
|
||||
ambuild objdir
|
||||
|
||||
- name: Build SourceMod
|
||||
working-directory: sourcemod
|
||||
run: |
|
||||
python3 configure.py --no-mysql --enable-optimize --sdks=mock --targets=x86,x86_64
|
||||
ambuild objdir
|
||||
|
||||
- name: Build hl2sdk-mock
|
||||
working-directory: hl2sdk-mock
|
||||
run: |
|
||||
python3 configure.py --enable-optimize --targets=x86,x86_64
|
||||
ambuild objdir
|
||||
|
||||
- name: Setup gamedir
|
||||
working-directory: hl2sdk-mock
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir ../gamedir
|
||||
./build_gamedir.sh ../gamedir ../metamod-source/objdir/package
|
||||
./build_gamedir.sh ../gamedir ../sourcemod/objdir/package
|
||||
|
||||
- name: Compile testsuite
|
||||
working-directory: hl2sdk-mock
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir ../gamedir/addons/sourcemod/plugins/optional
|
||||
|
||||
for f in ../sourcemod/plugins/testsuite/mock/*.sp; do
|
||||
echo "Compiling $(basename $f)"
|
||||
../gamedir/addons/sourcemod/scripting/spcomp64 -i ../gamedir/addons/sourcemod/scripting/include -o "../gamedir/addons/sourcemod/plugins/optional/$(basename $f .sp).smx" -E "$f"
|
||||
done
|
||||
|
||||
- name: Test
|
||||
working-directory: hl2sdk-mock
|
||||
shell: bash
|
||||
run: |
|
||||
for arch in x86 x86_64; do
|
||||
echo "==================================="
|
||||
echo "Testing $arch..."
|
||||
echo "==================================="
|
||||
for f in ../gamedir/addons/sourcemod/plugins/optional/*.smx; do
|
||||
echo "==================================="
|
||||
echo "Running $(basename $f)..."
|
||||
echo "==================================="
|
||||
timeout 60 ./objdir/dist/$arch/srcds -game_dir ../gamedir +map de_thunder -command "sm plugins load optional/$(basename $f)" -run -run-ticks 20 |
|
||||
{
|
||||
failed=0
|
||||
succeeded=0
|
||||
while IFS= read -r line; do
|
||||
echo "$line"
|
||||
if [[ "$line" == *"FAIL"* || "$line" == *"Exception reported"* ]]; then
|
||||
failed=1
|
||||
fi
|
||||
if [[ "$line" == *" OK"* ]]; then
|
||||
succeeded=1
|
||||
fi
|
||||
done
|
||||
if [ "$failed" = "1" ] || [ "$succeeded" = "0" ]; then
|
||||
echo "$(basename $f) failed."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
done
|
||||
done
|
||||
@@ -0,0 +1,84 @@
|
||||
name: PR Checks
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- '[0-9]+.[0-9]+-dev'
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- platform: windows
|
||||
os: windows-latest
|
||||
os_short: win
|
||||
- platform: linux
|
||||
os: ubuntu-latest
|
||||
os_short: linux
|
||||
container_image: ghcr.io/alliedmodders/build-containers/debian11-clang22:latest
|
||||
fail-fast: false
|
||||
runs-on: ${{ matrix.os }}
|
||||
container:
|
||||
image: ${{ matrix.container_image }}
|
||||
name: ${{ matrix.os_short }}
|
||||
env:
|
||||
SDKS: '["episode1","css","tf2","l4d2","csgo","dods"]'
|
||||
ARCH: x86,x86_64
|
||||
MARIADB_CONNECTOR_C_VERSION: '3.4.9'
|
||||
MARIADB_CONNECTOR_C_RELEASE: '3.4.9-sm.5'
|
||||
MMSOURCE_VERSION: '1.12'
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: recursive
|
||||
path: sourcemod
|
||||
|
||||
# Largely a workaround for issue where github.workspace doesn't match $GITHUB_WORKSPACE
|
||||
# in containerized jobs. See https://github.com/actions/runner/issues/2058
|
||||
- name: Resolve paths
|
||||
id: path_helper
|
||||
shell: bash
|
||||
run: |
|
||||
echo "dependencies=$GITHUB_WORKSPACE/dependencies" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v6
|
||||
env:
|
||||
cache-name: hl2sdk-mariadb-connector-c-mmsource
|
||||
with:
|
||||
path: ${{ steps.path_helper.outputs.dependencies }}
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-mmsource${{ env.MMSOURCE_VERSION }}-${{ join(fromJSON(env.SDKS), '') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-mmsource${{ env.MMSOURCE_VERSION }}-
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-
|
||||
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p '${{ steps.path_helper.outputs.dependencies }}'
|
||||
cd '${{ steps.path_helper.outputs.dependencies }}'
|
||||
|
||||
# Satisfy checkout-deps requirement for a "sourcemod" folder.
|
||||
mkdir -p sourcemod
|
||||
../sourcemod/tools/checkout-deps.sh -s ${{ join(fromJSON(env.SDKS), ',') }}
|
||||
|
||||
- name: Build
|
||||
working-directory: sourcemod
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
python3 ../configure.py \
|
||||
--enable-optimize \
|
||||
--sdks=${{ join(fromJSON(env.SDKS), ',') }} \
|
||||
--targets=${{ env.ARCH }} \
|
||||
'--mms-path=${{ steps.path_helper.outputs.dependencies }}/mmsource-${{ env.MMSOURCE_VERSION }}' \
|
||||
'--hl2sdk-root=${{ steps.path_helper.outputs.dependencies }}' \
|
||||
'--mariadb-path=${{ steps.path_helper.outputs.dependencies }}/mariadb-connector-c-${{ env.MARIADB_CONNECTOR_C_VERSION }}-x86' \
|
||||
'--mariadb64-path=${{ steps.path_helper.outputs.dependencies }}/mariadb-connector-c-${{ env.MARIADB_CONNECTOR_C_VERSION }}-x86_64'
|
||||
ambuild
|
||||
@@ -0,0 +1,73 @@
|
||||
name: SourcePawn scripting
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- '[0-9]+.[0-9]+-dev'
|
||||
paths:
|
||||
- 'plugins/include/*'
|
||||
- 'sourcepawn/**'
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '53 05 01 */3 *' # Artifacts expire every 3 months
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
os_short: linux
|
||||
- os: windows-latest
|
||||
os_short: win
|
||||
fail-fast: false
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
ARCH: x86,x86_64
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
# Setup Python for AMBuild
|
||||
- uses: actions/setup-python@v7
|
||||
name: Setup Python 3.12
|
||||
with:
|
||||
python-version: 3.12
|
||||
- name: Install AMBuild
|
||||
run: |
|
||||
python -m pip install --upgrade pip setuptools wheel
|
||||
pip install git+https://github.com/alliedmodders/ambuild
|
||||
|
||||
- name: Install Linux dependencies
|
||||
if: startsWith(runner.os, 'Linux')
|
||||
run: |
|
||||
sudo dpkg --add-architecture i386
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --no-install-recommends \
|
||||
gcc-multilib g++-multilib libstdc++6 lib32stdc++6 \
|
||||
libc6-dev libc6-dev-i386 linux-libc-dev \
|
||||
linux-libc-dev:i386 lib32z1-dev ${{ matrix.compiler_cc }}
|
||||
|
||||
- name: Select clang compiler
|
||||
if: startsWith(runner.os, 'Linux')
|
||||
run: |
|
||||
echo "CC=clang" >> $GITHUB_ENV
|
||||
echo "CXX=clang++" >> $GITHUB_ENV
|
||||
clang --version
|
||||
clang++ --version
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
python ../configure.py --enable-optimize --scripting-only --targets=${{ env.ARCH }}
|
||||
ambuild
|
||||
echo "SM_VERSION=$(cat ../product.version)" >> $GITHUB_ENV
|
||||
|
||||
- name: Archive tooling
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: sourcemod-tooling-${{ env.SM_VERSION }}-${{ matrix.os_short }}
|
||||
path: build/package
|
||||
@@ -0,0 +1,115 @@
|
||||
# srcdslab only (not in alliedmodders/sourcemod): build the patched 1.13-<rev> branches
|
||||
# (upstream SourceMod at <rev> plus our x86_64 DHooks/BinTools fixes) and publish them as a
|
||||
# GitHub release. build-release.yml only runs on master and X.Y-dev and needs secrets this
|
||||
# fork does not have (MAXMIND_LICENSE_KEY, breakpad symbol server), so it is left untouched
|
||||
# to keep upstream merges clean.
|
||||
name: srcdslab build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '1.13-[0-9]+'
|
||||
pull_request:
|
||||
branches:
|
||||
- '1.13-[0-9]+'
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
ARCH: x86,x86_64
|
||||
# NiDE only runs CS:S on Linux (checked on 2026-11-13), so only that SDK is built.
|
||||
SDKS: css
|
||||
MARIADB_CONNECTOR_C_VERSION: '3.4.9'
|
||||
MARIADB_CONNECTOR_C_RELEASE: '3.4.9-sm.5'
|
||||
# srcdslab MM:S 1.12-dev carries the Linux x86_64 SourceHook work (srcdslab/metamod-source#4)
|
||||
# that the x86_64 DHooks needs (x64JitWriter::leave). checkout-deps.sh keeps an existing
|
||||
# mmsource-1.12 folder and pulls from its own origin, so it stays on this repository.
|
||||
MMSOURCE_REPO: https://github.com/srcdslab/metamod-source
|
||||
MMSOURCE_BRANCH: 1.12-dev
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: linux
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/alliedmodders/build-containers/debian11-clang22:latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout SourceMod
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
path: sourcemod
|
||||
fetch-depth: 0
|
||||
submodules: recursive
|
||||
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p "$GITHUB_WORKSPACE/dependencies"
|
||||
cd "$GITHUB_WORKSPACE/dependencies"
|
||||
# Satisfy checkout-deps requirement for a "sourcemod" folder.
|
||||
mkdir -p sourcemod
|
||||
git clone --recursive -b "$MMSOURCE_BRANCH" "$MMSOURCE_REPO" mmsource-1.12
|
||||
../sourcemod/tools/checkout-deps.sh -s "$SDKS"
|
||||
|
||||
- name: Build
|
||||
working-directory: sourcemod
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
deps="$GITHUB_WORKSPACE/dependencies"
|
||||
mkdir build
|
||||
cd build
|
||||
python3 ../configure.py \
|
||||
--enable-optimize \
|
||||
--sdks="$SDKS" \
|
||||
--targets="$ARCH" \
|
||||
--mms-path="$deps/mmsource-1.12" \
|
||||
--hl2sdk-root="$deps" \
|
||||
--mariadb-path="$deps/mariadb-connector-c-$MARIADB_CONNECTOR_C_VERSION-x86" \
|
||||
--mariadb64-path="$deps/mariadb-connector-c-$MARIADB_CONNECTOR_C_VERSION-x86_64"
|
||||
ambuild
|
||||
|
||||
- name: Package
|
||||
id: package
|
||||
working-directory: sourcemod/build/package
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
version_base=$(cat ../../product.version)
|
||||
version_base=${version_base%-dev}
|
||||
version_rev=$(git rev-list --count HEAD)
|
||||
version="${version_base}.${version_rev}"
|
||||
filename="sourcemod-${version_base}-git${version_rev}-srcdslab-linux.tar.gz"
|
||||
# Fail early if the x86_64 DHooks or BinTools did not build.
|
||||
for ext in dhooks bintools; do
|
||||
test -f "addons/sourcemod/extensions/x64/$ext.ext.so"
|
||||
done
|
||||
tar zcf "$filename" addons cfg
|
||||
echo "version=$version" >> "$GITHUB_OUTPUT"
|
||||
echo "filename=$filename" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Upload package
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: sourcemod-${{ steps.package.outputs.version }}-linux
|
||||
path: sourcemod/build/package/${{ steps.package.outputs.filename }}
|
||||
|
||||
- name: Create release
|
||||
if: github.event_name == 'push'
|
||||
uses: ncipollo/[email protected]
|
||||
with:
|
||||
allowUpdates: true
|
||||
replacesArtifacts: true
|
||||
artifacts: sourcemod/build/package/${{ steps.package.outputs.filename }}
|
||||
artifactContentType: application/gzip
|
||||
artifactErrorsFailBuild: true
|
||||
tag: ${{ steps.package.outputs.version }}-srcdslab
|
||||
name: SourceMod ${{ steps.package.outputs.version }} (srcdslab ${{ github.ref_name }})
|
||||
body: |
|
||||
SourceMod built from the srcdslab `${{ github.ref_name }}` branch: upstream SourceMod plus the srcdslab x86_64 DHooks and BinTools fixes, against srcdslab/metamod-source `${{ env.MMSOURCE_BRANCH }}`.
|
||||
CS:S only, Linux x86 and x86_64. No GeoLite2 database is included.
|
||||
commit: ${{ github.sha }}
|
||||
makeLatest: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -0,0 +1,42 @@
|
||||
name: Update translation project
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- 'translations/**'
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
update_translations:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- uses: actions/setup-python@v7
|
||||
name: Setup Python 3.10
|
||||
with:
|
||||
python-version: "3.10"
|
||||
|
||||
- name: Install Python dependencies
|
||||
working-directory: tools/language_check
|
||||
run: |
|
||||
python -m pip install --upgrade -r requirements.txt
|
||||
|
||||
- name: Generate token
|
||||
id: generate_token
|
||||
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
|
||||
with:
|
||||
app_id: ${{ secrets.APP_ID }}
|
||||
private_key: ${{ secrets.APP_PEM }}
|
||||
|
||||
- name: Update translation project
|
||||
working-directory: tools/language_check
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
|
||||
ORGANIZATION: alliedmodders
|
||||
PROJECT_NUMBER: 1
|
||||
run: |
|
||||
python ./compare_translation_phrases.py
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
name: Sanity check translation phrases
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- 'translations/**'
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- 'translations/**'
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
check_translations:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- uses: actions/setup-python@v7
|
||||
name: Setup Python 3.10
|
||||
with:
|
||||
python-version: "3.10"
|
||||
|
||||
- name: Check translation phrases syntax
|
||||
working-directory: tools/language_check
|
||||
run: |
|
||||
python ./sanity_check.py
|
||||
|
||||
+6
-1
@@ -28,7 +28,6 @@ LIB-Debug/
|
||||
[Tt]humbs.db
|
||||
|
||||
# AMBuild build directories
|
||||
build/
|
||||
obj-*/
|
||||
*~
|
||||
*.rej
|
||||
@@ -36,3 +35,9 @@ obj-*/
|
||||
*.smx
|
||||
*.swp
|
||||
*.gdb_history
|
||||
objdir
|
||||
# Not standardized, but common name for build directories
|
||||
/build*/
|
||||
|
||||
.vs/*
|
||||
.vscode/*
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
[submodule "public/amtl"]
|
||||
path = public/amtl
|
||||
url = https://github.com/alliedmodders/amtl
|
||||
shallow = true
|
||||
[submodule "sourcepawn"]
|
||||
path = sourcepawn
|
||||
url = https://github.com/alliedmodders/sourcepawn
|
||||
shallow = true
|
||||
[submodule "hl2sdk-manifests"]
|
||||
path = hl2sdk-manifests
|
||||
url = https://github.com/alliedmodders/hl2sdk-manifests.git
|
||||
[submodule "public/safetyhook"]
|
||||
path = public/safetyhook
|
||||
url = https://github.com/alliedmodders/safetyhook
|
||||
|
||||
+57
-87
@@ -1,116 +1,86 @@
|
||||
git:
|
||||
depth: 3
|
||||
|
||||
sudo: false
|
||||
language: cpp
|
||||
os: linux
|
||||
dist: trusty
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-4.0
|
||||
- llvm-toolchain-trusty-5.0
|
||||
packages:
|
||||
- lib32stdc++6
|
||||
- lib32z1-dev
|
||||
- libc6-dev-i386
|
||||
- linux-libc-dev
|
||||
- g++-multilib
|
||||
# - clang-3.6
|
||||
# - clang-3.8
|
||||
# - clang-4.0
|
||||
# - clang-5.0
|
||||
# - g++-6
|
||||
# - g++-6-multilib
|
||||
- g++-4.8-multilib
|
||||
- g++-4.8
|
||||
- g++-4.9-multilib
|
||||
- g++-4.9
|
||||
- g++-5-multilib
|
||||
- g++-5
|
||||
- g++-7-multilib
|
||||
- g++-7
|
||||
cache:
|
||||
directories:
|
||||
- ../mysql-5.0
|
||||
env:
|
||||
- MATRIX_EVAL="CC=clang-3.9 && CXX=clang++-3.9"
|
||||
- MATRIX_EVAL="CC=gcc-4.8 && CXX=g++-4.8"
|
||||
- MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9"
|
||||
- MATRIX_EVAL="CC=gcc-5 && CXX=g++-5"
|
||||
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
|
||||
dist: xenial
|
||||
|
||||
matrix:
|
||||
jobs:
|
||||
fast_finish: true
|
||||
include:
|
||||
- os: linux
|
||||
sudo: false
|
||||
dist: trusty
|
||||
language: cpp
|
||||
addons:
|
||||
apt:
|
||||
packages: ['clang-3.6', 'lib32stdc++6', 'lib32z1-dev', 'libc6-dev-i386', 'linux-libc-dev', 'g++-multilib']
|
||||
cache:
|
||||
directories: ['../mysql-5.0']
|
||||
env: ['MATRIX_EVAL="CC=clang-3.6 && CXX=clang++-3.6"']
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages: ['clang-3.8', 'lib32stdc++6', 'lib32z1-dev', 'libc6-dev-i386', 'linux-libc-dev:i386', 'g++-4.9-multilib', 'python3-pip']
|
||||
env:
|
||||
- MATRIX_EVAL="CC=clang-3.8 && CXX=clang++-3.8"
|
||||
- SDKS=episode1,css,tf2,l4d2,csgo
|
||||
- MODE=optimize
|
||||
- ARCH=x86,x86_64
|
||||
|
||||
- os: linux
|
||||
sudo: false
|
||||
dist: trusty
|
||||
language: cpp
|
||||
addons:
|
||||
apt:
|
||||
packages: ['clang-3.8', 'lib32stdc++6', 'lib32z1-dev', 'libc6-dev-i386', 'linux-libc-dev', 'g++-multilib']
|
||||
cache:
|
||||
directories: ['../mysql-5.0']
|
||||
env: ['MATRIX_EVAL="CC=clang-3.8 && CXX=clang++-3.8"']
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages: ['clang-3.4', 'lib32stdc++6', 'lib32z1-dev', 'libc6-dev-i386', 'linux-libc-dev:i386', 'g++-4.9-multilib', 'python3-pip']
|
||||
env:
|
||||
- MATRIX_EVAL="CC=clang && CXX=clang++"
|
||||
- SDKS=episode1,css,tf2,l4d2,csgo
|
||||
- MODE=optimize
|
||||
- ARCH=x86,x86_64
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode7.2
|
||||
language: cpp
|
||||
env:
|
||||
- MATRIX_EVAL="CC=clang && CXX=clang++"
|
||||
- SDKS=episode1,css,tf2,l4d2,csgo
|
||||
- MODE=optimize
|
||||
- ARCH=x86_64,x86
|
||||
|
||||
# # This is a faster test for the latest g++.
|
||||
# - os: linux
|
||||
# dist: bionic
|
||||
# sudo: false
|
||||
# language: cpp
|
||||
# addons:
|
||||
# apt:
|
||||
# packages: ['lib32stdc++6', 'lib32z1-dev', 'libc6-dev-i386', 'linux-libc-dev:i386', 'g++-multilib', 'g++']
|
||||
# cache:
|
||||
# directories: ['../mysql-5.0']
|
||||
# env:
|
||||
# - MATRIX_EVAL="CC=gcc && CXX=g++"
|
||||
# - SDKS=csgo
|
||||
# # GCC currently fails in opt builds trying to inline stuff in sqlite3.c.
|
||||
# - MODE=debug
|
||||
|
||||
# This is a faster test for the latest clang.
|
||||
- os: linux
|
||||
sudo: false
|
||||
dist: bionic
|
||||
language: cpp
|
||||
addons:
|
||||
apt:
|
||||
sources: ['llvm-toolchain-trusty-4.0']
|
||||
packages: ['clang-4.0', 'lib32stdc++6', 'lib32z1-dev', 'libc6-dev-i386', 'linux-libc-dev', 'g++-multilib']
|
||||
cache:
|
||||
directories: ['../mysql-5.0']
|
||||
env: ['MATRIX_EVAL="CC=clang-4.0 && CXX=clang++-4.0"']
|
||||
|
||||
- os: linux
|
||||
sudo: false
|
||||
language: cpp
|
||||
addons:
|
||||
apt:
|
||||
sources: ['llvm-toolchain-trusty-5.0']
|
||||
packages: ['clang-5.0', 'lib32stdc++6', 'lib32z1-dev', 'libc6-dev-i386', 'linux-libc-dev', 'g++-multilib']
|
||||
cache:
|
||||
directories: ['../mysql-5.0']
|
||||
env: ['MATRIX_EVAL="CC=clang-5.0 && CXX=clang++-5.0"']
|
||||
|
||||
- os: linux
|
||||
sudo: false
|
||||
language: cpp
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test']
|
||||
packages: ['g++-6', 'g++-6-multilib', 'lib32stdc++6', 'lib32z1-dev', 'libc6-dev-i386', 'linux-libc-dev', 'g++-multilib']
|
||||
cache:
|
||||
directories: ['../mysql-5.0']
|
||||
env: ['MATRIX_EVAL="CC=gcc-6 && CXX=g++-6"']
|
||||
|
||||
allow_failures:
|
||||
- env: MATRIX_EVAL="CC=clang-3.7 && CXX=clang++-3.7"
|
||||
- env: MATRIX_EVAL="CC=clang-3.9 && CXX=clang++-3.9"
|
||||
- env: MATRIX_EVAL="CC=gcc-4.8 && CXX=g++-4.8"
|
||||
- env: MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9"
|
||||
- env: MATRIX_EVAL="CC=gcc-5 && CXX=g++-5"
|
||||
- env: MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
|
||||
|
||||
packages: ['lib32stdc++6', 'lib32z1-dev', 'libc6-dev-i386', 'linux-libc-dev:i386', 'g++-multilib', 'clang']
|
||||
env:
|
||||
- MATRIX_EVAL="CC=clang && CXX=clang++"
|
||||
- SDKS=csgo
|
||||
- MODE=optimize
|
||||
- ARCH=x86
|
||||
|
||||
before_script:
|
||||
- CHECKOUT_DIR=$PWD && cd .. && $CHECKOUT_DIR/tools/checkout-deps.sh && cd $CHECKOUT_DIR
|
||||
- CHECKOUT_DIR=$PWD && cd .. && $CHECKOUT_DIR/tools/checkout-deps.sh -s ${SDKS} && cd $CHECKOUT_DIR
|
||||
script:
|
||||
- mkdir build && cd build
|
||||
- PATH="~/.local/bin:$PATH"
|
||||
- eval "${MATRIX_EVAL}"
|
||||
- python ../configure.py --enable-optimize --sdks=episode1,tf2,l4d2,csgo,dota
|
||||
- eval "${CC} --version"
|
||||
- eval "${CXX} --version"
|
||||
- python3 ../configure.py --enable-${MODE} --sdks=${SDKS} --targets=${ARCH}
|
||||
- ambuild
|
||||
|
||||
+419
-271
@@ -1,44 +1,7 @@
|
||||
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
|
||||
import collections
|
||||
import os, sys
|
||||
|
||||
class SDK(object):
|
||||
def __init__(self, sdk, ext, aDef, name, platform, dir):
|
||||
self.folder = 'hl2sdk-' + dir
|
||||
self.envvar = sdk
|
||||
self.ext = ext
|
||||
self.code = aDef
|
||||
self.define = name
|
||||
self.platform = platform
|
||||
self.name = dir
|
||||
self.path = None # Actual path
|
||||
|
||||
WinOnly = ['windows']
|
||||
WinLinux = ['windows', 'linux']
|
||||
WinLinuxMac = ['windows', 'linux', 'mac']
|
||||
|
||||
PossibleSDKs = {
|
||||
'episode1': SDK('HL2SDK', '2.ep1', '1', 'EPISODEONE', WinLinux, 'episode1'),
|
||||
'ep2': SDK('HL2SDKOB', '2.ep2', '3', 'ORANGEBOX', WinLinux, 'orangebox'),
|
||||
'css': SDK('HL2SDKCSS', '2.css', '6', 'CSS', WinLinuxMac, 'css'),
|
||||
'hl2dm': SDK('HL2SDKHL2DM', '2.hl2dm', '7', 'HL2DM', WinLinuxMac, 'hl2dm'),
|
||||
'dods': SDK('HL2SDKDODS', '2.dods', '8', 'DODS', WinLinuxMac, 'dods'),
|
||||
'sdk2013': SDK('HL2SDK2013', '2.sdk2013', '9', 'SDK2013', WinLinuxMac, 'sdk2013'),
|
||||
'tf2': SDK('HL2SDKTF2', '2.tf2', '11', 'TF2', WinLinuxMac, 'tf2'),
|
||||
'l4d': SDK('HL2SDKL4D', '2.l4d', '12', 'LEFT4DEAD', WinLinuxMac, 'l4d'),
|
||||
'nucleardawn': SDK('HL2SDKND', '2.nd', '13', 'NUCLEARDAWN', WinLinuxMac, 'nucleardawn'),
|
||||
'l4d2': SDK('HL2SDKL4D2', '2.l4d2', '15', 'LEFT4DEAD2', WinLinuxMac, 'l4d2'),
|
||||
'darkm': SDK('HL2SDK-DARKM', '2.darkm', '2', 'DARKMESSIAH', WinOnly, 'darkm'),
|
||||
'swarm': SDK('HL2SDK-SWARM', '2.swarm', '16', 'ALIENSWARM', WinOnly, 'swarm'),
|
||||
'bgt': SDK('HL2SDK-BGT', '2.bgt', '4', 'BLOODYGOODTIME', WinOnly, 'bgt'),
|
||||
'eye': SDK('HL2SDK-EYE', '2.eye', '5', 'EYE', WinOnly, 'eye'),
|
||||
'csgo': SDK('HL2SDKCSGO', '2.csgo', '21', 'CSGO', WinLinux, 'csgo'),
|
||||
'portal2': SDK('HL2SDKPORTAL2', '2.portal2', '17', 'PORTAL2', [], 'portal2'),
|
||||
'blade': SDK('HL2SDKBLADE', '2.blade', '18', 'BLADE', WinLinux, 'blade'),
|
||||
'insurgency': SDK('HL2SDKINSURGENCY', '2.insurgency', '19', 'INSURGENCY', WinLinuxMac, 'insurgency'),
|
||||
'contagion': SDK('HL2SDKCONTAGION', '2.contagion', '14', 'CONTAGION', WinOnly, 'contagion'),
|
||||
'bms': SDK('HL2SDKBMS', '2.bms', '10', 'BMS', WinLinux, 'bms'),
|
||||
'doi': SDK('HL2SDKDOI', '2.doi', '20', 'DOI', WinLinuxMac, 'doi'),
|
||||
}
|
||||
import subprocess
|
||||
|
||||
def ResolveEnvPath(env, folder):
|
||||
if env in os.environ:
|
||||
@@ -60,18 +23,60 @@ def ResolveEnvPath(env, folder):
|
||||
|
||||
def Normalize(path):
|
||||
return os.path.abspath(os.path.normpath(path))
|
||||
|
||||
def SetArchFlags(compiler):
|
||||
if compiler.behavior == 'gcc':
|
||||
if compiler.target.arch == 'x86_64':
|
||||
compiler.cflags += ['-fPIC']
|
||||
elif compiler.like('msvc'):
|
||||
if compiler.target.arch == 'x86_64':
|
||||
compiler.defines += ['WIN64']
|
||||
|
||||
SdkHelpers = builder.Eval('hl2sdk-manifests/SdkHelpers.ambuild', {
|
||||
'Project': 'sourcemod'
|
||||
})
|
||||
|
||||
class SMConfig(object):
|
||||
def __init__(self):
|
||||
self.sdk_manifests = []
|
||||
self.sdks = {}
|
||||
self.sdk_targets = []
|
||||
self.binaries = []
|
||||
self.extensions = []
|
||||
self.generated_headers = None
|
||||
self.mms_root = None
|
||||
self.mysql_root = None
|
||||
self.mariadb_root = {}
|
||||
self.spcomp = None
|
||||
self.spcomp_bins = []
|
||||
self.smx_files = {}
|
||||
self.versionlib = None
|
||||
self.all_targets = []
|
||||
self.target_archs = set()
|
||||
self.enable_asan = getattr(builder.options, 'enable_asan', False)
|
||||
self.asan_libs = {}
|
||||
self.libsafetyhook = {}
|
||||
|
||||
if builder.options.targets:
|
||||
target_archs = builder.options.targets.split(',')
|
||||
else:
|
||||
target_archs = ['x86']
|
||||
if builder.backend != 'amb2':
|
||||
target_archs.append('x86_64')
|
||||
|
||||
for arch in target_archs:
|
||||
try:
|
||||
cxx = builder.DetectCxx(target_arch = arch)
|
||||
self.target_archs.add(cxx.target.arch)
|
||||
except Exception as e:
|
||||
# Error if archs were manually overridden.
|
||||
if builder.options.targets:
|
||||
raise
|
||||
print('Skipping target {}: {}'.format(arch, e))
|
||||
continue
|
||||
self.all_targets.append(cxx)
|
||||
|
||||
if not self.all_targets:
|
||||
raise Exception('No suitable C/C++ compiler was found.')
|
||||
|
||||
def use_auto_versioning(self):
|
||||
if builder.backend != 'amb2':
|
||||
@@ -91,40 +96,40 @@ class SMConfig(object):
|
||||
import re
|
||||
with open(os.path.join(builder.sourcePath, 'product.version'), 'r') as fp:
|
||||
productContents = fp.read()
|
||||
m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
|
||||
m = re.match(r'(\d+)\.(\d+)\.(\d+).*', productContents)
|
||||
if m == None:
|
||||
self.productVersion = '1.0.0'
|
||||
else:
|
||||
major, minor, release = m.groups()
|
||||
self.productVersion = '{0}.{1}.{2}'.format(major, minor, release)
|
||||
|
||||
def findSdkPath(self, sdk_name):
|
||||
dir_name = 'hl2sdk-{}'.format(sdk_name)
|
||||
if builder.options.hl2sdk_root:
|
||||
sdk_path = os.path.join(builder.options.hl2sdk_root, dir_name)
|
||||
if os.path.exists(sdk_path):
|
||||
return sdk_path
|
||||
return ResolveEnvPath('HL2SDK{}'.format(sdk_name.upper()), dir_name)
|
||||
|
||||
def shouldIncludeSdk(self, sdk):
|
||||
return not sdk.get('source2', False)
|
||||
|
||||
def detectSDKs(self):
|
||||
sdk_list = builder.options.sdks.split(',')
|
||||
use_all = sdk_list[0] == 'all'
|
||||
use_present = sdk_list[0] == 'present'
|
||||
sdk_list = [s for s in builder.options.sdks.split(',') if s]
|
||||
SdkHelpers.sdk_filter = self.shouldIncludeSdk
|
||||
SdkHelpers.find_sdk_path = self.findSdkPath
|
||||
SdkHelpers.findSdks(builder, self.all_targets, sdk_list)
|
||||
|
||||
for sdk_name in PossibleSDKs:
|
||||
sdk = PossibleSDKs[sdk_name]
|
||||
if builder.target.platform in sdk.platform:
|
||||
if builder.options.hl2sdk_root:
|
||||
sdk_path = os.path.join(builder.options.hl2sdk_root, sdk.folder)
|
||||
else:
|
||||
sdk_path = ResolveEnvPath(sdk.envvar, sdk.folder)
|
||||
if sdk_path is None or not os.path.isdir(sdk_path):
|
||||
if use_all or sdk_name in sdk_list:
|
||||
raise Exception('Could not find a valid path for {0}'.format(sdk.envvar))
|
||||
continue
|
||||
if use_all or use_present or sdk_name in sdk_list:
|
||||
sdk.path = Normalize(sdk_path)
|
||||
self.sdks[sdk_name] = sdk
|
||||
|
||||
if len(self.sdks) < 1:
|
||||
raise Exception('At least one SDK must be available.')
|
||||
self.sdks = SdkHelpers.sdks
|
||||
self.sdk_manifests = SdkHelpers.sdk_manifests
|
||||
self.sdk_targets = SdkHelpers.sdk_targets
|
||||
|
||||
if builder.options.mms_path:
|
||||
self.mms_root = builder.options.mms_path
|
||||
else:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE110', 'mmsource-1.10')
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE112', 'mmsource-1.12')
|
||||
if not self.mms_root:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source')
|
||||
if not self.mms_root:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'metamod-source')
|
||||
if not self.mms_root:
|
||||
@@ -135,41 +140,72 @@ class SMConfig(object):
|
||||
self.mms_root = Normalize(self.mms_root)
|
||||
|
||||
if builder.options.hasMySql:
|
||||
if builder.options.mysql_path:
|
||||
self.mysql_root = builder.options.mysql_path
|
||||
else:
|
||||
for i in range(7):
|
||||
self.mysql_root = ResolveEnvPath('MYSQL5', 'mysql-5.' + str(i))
|
||||
if self.mysql_root:
|
||||
break
|
||||
if not self.mysql_root or not os.path.isdir(self.mysql_root):
|
||||
raise Exception('Could not find a path to MySQL!')
|
||||
self.mysql_root = Normalize(self.mysql_root)
|
||||
if 'x86' in self.target_archs:
|
||||
mariadb_path = getattr(builder.options, 'mariadb_path',
|
||||
getattr(builder.options, 'mysql_path', None))
|
||||
if mariadb_path:
|
||||
self.mariadb_root['x86'] = mariadb_path
|
||||
else:
|
||||
self.mariadb_root['x86'] = ResolveEnvPath('MARIADB_CONNECTOR_C', 'mariadb-connector-c-x86')
|
||||
if not self.mariadb_root['x86'] or not os.path.isdir(self.mariadb_root['x86']):
|
||||
raise Exception('Could not find an x86 MariaDB Connector/C path. Configure with --no-mysql to disable it.')
|
||||
self.mariadb_root['x86'] = Normalize(self.mariadb_root['x86'])
|
||||
|
||||
if 'x86_64' in self.target_archs:
|
||||
mariadb64_path = getattr(builder.options, 'mariadb64_path',
|
||||
getattr(builder.options, 'mysql64_path', None))
|
||||
if mariadb64_path:
|
||||
self.mariadb_root['x86_64'] = mariadb64_path
|
||||
else:
|
||||
self.mariadb_root['x86_64'] = ResolveEnvPath('MARIADB_CONNECTOR_C_64', 'mariadb-connector-c-x86_64')
|
||||
if not self.mariadb_root['x86_64'] or not os.path.isdir(self.mariadb_root['x86_64']):
|
||||
raise Exception('Could not find an x86_64 MariaDB Connector/C path.')
|
||||
self.mariadb_root['x86_64'] = Normalize(self.mariadb_root['x86_64'])
|
||||
|
||||
def configure(self):
|
||||
builder.AddConfigureFile('pushbuild.txt')
|
||||
|
||||
allowed_archs = ['x86_64']
|
||||
if builder.host.platform == 'mac':
|
||||
if getattr(builder.options, 'scripting_only', False):
|
||||
allowed_archs += ['arm64']
|
||||
else:
|
||||
allowed_archs += ['x86']
|
||||
|
||||
cxx = builder.DetectCxx()
|
||||
if not set(self.target_archs).issubset(allowed_archs):
|
||||
raise Exception('Unknown target architecture: {0}'.format(self.target_archs))
|
||||
|
||||
for cxx in self.all_targets:
|
||||
self.configure_cxx(cxx)
|
||||
|
||||
def configure_cxx(self, cxx):
|
||||
if cxx.family == 'msvc':
|
||||
if cxx.version < 1914 and builder.options.generator != 'vs':
|
||||
raise Exception(f'Only MSVC 2017 15.7 and later are supported, full C++17 support is required. ({str(cxx.version)} < 1914)')
|
||||
elif cxx.family == 'gcc':
|
||||
if cxx.version < 'gcc-9':
|
||||
raise Exception('Only GCC versions 9 or later are supported, full C++17 support is required.')
|
||||
elif cxx.family == 'clang':
|
||||
if cxx.version < 'clang-5':
|
||||
raise Exception('Only clang versions 5 or later are supported, full C++17 support is required.')
|
||||
|
||||
if cxx.like('gcc'):
|
||||
self.configure_gcc(cxx)
|
||||
elif cxx.family == 'msvc':
|
||||
self.configure_msvc(cxx)
|
||||
|
||||
# Optimizaiton
|
||||
if builder.options.opt == '1':
|
||||
cxx.defines += ['NDEBUG']
|
||||
# Optimization flags are applied separately, earlier in configure_optimize so that the SDK static libs inherit them.
|
||||
|
||||
# Debugging
|
||||
if builder.options.debug == '1':
|
||||
cxx.defines += ['DEBUG', '_DEBUG']
|
||||
|
||||
# Platform-specifics
|
||||
if builder.target.platform == 'linux':
|
||||
if cxx.target.platform == 'linux':
|
||||
self.configure_linux(cxx)
|
||||
elif builder.target.platform == 'mac':
|
||||
elif cxx.target.platform == 'mac':
|
||||
self.configure_mac(cxx)
|
||||
elif builder.target.platform == 'windows':
|
||||
elif cxx.target.platform == 'windows':
|
||||
self.configure_windows(cxx)
|
||||
|
||||
# Finish up.
|
||||
@@ -187,6 +223,32 @@ class SMConfig(object):
|
||||
os.path.join(builder.sourcePath, 'versionlib'),
|
||||
]
|
||||
|
||||
def configure_optimize(self, cxx):
|
||||
if builder.options.opt != '1':
|
||||
return
|
||||
cxx.defines += ['NDEBUG']
|
||||
if cxx.like('gcc'):
|
||||
if self.enable_asan:
|
||||
cxx.cflags += ['-O1']
|
||||
else:
|
||||
cxx.cflags += ['-O3']
|
||||
elif cxx.family == 'msvc':
|
||||
cxx.cflags += ['/Ox', '/Zo']
|
||||
cxx.linkflags += ['/OPT:ICF', '/OPT:REF']
|
||||
|
||||
def configure_pre_sdk(self, cxx):
|
||||
self.configure_optimize(cxx)
|
||||
|
||||
if not cxx.like('gcc'):
|
||||
return
|
||||
|
||||
if cxx.target.arch in ['x86', 'x86_64']:
|
||||
cxx.cflags += ['-msse']
|
||||
if cxx.family == 'gcc':
|
||||
cxx.cflags += ['-mfpmath=sse']
|
||||
if cxx.target.platform == 'linux' and cxx.target.arch == 'x86':
|
||||
cxx.cflags += ['-mstackrealign']
|
||||
|
||||
def configure_gcc(self, cxx):
|
||||
cxx.defines += [
|
||||
'stricmp=strcasecmp',
|
||||
@@ -204,27 +266,28 @@ class SMConfig(object):
|
||||
'-Wno-unused',
|
||||
'-Wno-switch',
|
||||
'-Wno-array-bounds',
|
||||
'-msse',
|
||||
'-m32',
|
||||
'-Wno-unknown-pragmas',
|
||||
'-Wno-dangling-else',
|
||||
'-fvisibility=hidden',
|
||||
]
|
||||
|
||||
cxx.cxxflags += ['-std=c++20']
|
||||
|
||||
cxx.cxxflags += [
|
||||
'-std=c++11',
|
||||
'-fno-exceptions',
|
||||
'-fno-threadsafe-statics',
|
||||
'-Wno-non-virtual-dtor',
|
||||
'-Wno-overloaded-virtual',
|
||||
'-Wno-register',
|
||||
'-fvisibility-inlines-hidden',
|
||||
]
|
||||
cxx.linkflags += ['-m32']
|
||||
|
||||
have_gcc = cxx.family == 'gcc'
|
||||
have_clang = cxx.family == 'clang'
|
||||
if cxx.version >= 'clang-3.9':
|
||||
if cxx.version >= 'clang-3.9' or cxx.version == 'clang-3.4' or cxx.version > 'apple-clang-6.0':
|
||||
cxx.cxxflags += ['-Wno-expansion-to-defined']
|
||||
if cxx.version == 'clang-3.9' or cxx.version == 'apple-clang-8.0':
|
||||
cxx.cflags += ['-Wno-varargs']
|
||||
if cxx.version >= 'clang-3.6' or cxx.version >= 'apple-clang-7.0':
|
||||
if cxx.version >= 'clang-3.4' or cxx.version >= 'apple-clang-7.0':
|
||||
cxx.cxxflags += ['-Wno-inconsistent-missing-override']
|
||||
if cxx.version >= 'clang-2.9' or cxx.version >= 'apple-clang-3.0':
|
||||
cxx.cxxflags += ['-Wno-null-dereference']
|
||||
@@ -234,7 +297,8 @@ class SMConfig(object):
|
||||
cxx.cxxflags += ['-Wno-delete-non-virtual-dtor']
|
||||
if cxx.version >= 'gcc-4.8':
|
||||
cxx.cflags += ['-Wno-unused-result']
|
||||
|
||||
if cxx.version >= 'gcc-9.0':
|
||||
cxx.cxxflags += ['-Wno-class-memaccess', '-Wno-packed-not-aligned']
|
||||
if have_clang:
|
||||
cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch']
|
||||
if cxx.version >= 'apple-clang-5.1' or cxx.version >= 'clang-3.4':
|
||||
@@ -243,14 +307,44 @@ class SMConfig(object):
|
||||
cxx.cxxflags += ['-Wno-deprecated']
|
||||
cxx.cflags += ['-Wno-sometimes-uninitialized']
|
||||
|
||||
if self.enable_asan:
|
||||
if not have_clang:
|
||||
raise Exception('--enable-asan only supported when using Clang')
|
||||
self.configure_asan(cxx)
|
||||
|
||||
# AMTL uses std::bind
|
||||
if (have_gcc and cxx.version >= 'gcc-10.0') or (have_clang and cxx.version >= 'clang-12.0'):
|
||||
cxx.cxxflags += ['-Wno-deprecated-declarations']
|
||||
|
||||
# Work around SDK warnings.
|
||||
if cxx.version >= 'clang-10.0' or cxx.version >= 'apple-clang-12.0':
|
||||
cxx.cflags += [
|
||||
'-Wno-implicit-int-float-conversion',
|
||||
'-Wno-tautological-overlap-compare',
|
||||
]
|
||||
|
||||
if cxx.version >= 'clang-21.0':
|
||||
cxx.cflags += ['-Wno-uninitialized-const-pointer']
|
||||
|
||||
if cxx.version >= 'clang-16.0' or cxx.version >= 'apple-clang-15.0':
|
||||
cxx.cxxflags += ['-Wno-deprecated-anon-enum-enum-conversion']
|
||||
|
||||
# C++20 deprecates volatile ++/-- and compound assignment (P1152R4).
|
||||
if cxx.version >= 'clang-12.0' or cxx.version >= 'apple-clang-13.0':
|
||||
cxx.cxxflags += ['-Wno-deprecated-volatile']
|
||||
|
||||
if have_gcc:
|
||||
cxx.cflags += ['-mfpmath=sse']
|
||||
cxx.cflags += ['-Wno-maybe-uninitialized']
|
||||
|
||||
if builder.options.opt == '1':
|
||||
cxx.cflags += ['-O3']
|
||||
# Optimization flags are applied separately, earlier in configure_optimize so that the SDK static libs inherit them.
|
||||
|
||||
# Don't omit the frame pointer.
|
||||
cxx.cflags += ['-fno-omit-frame-pointer']
|
||||
|
||||
def configure_msvc(self, cxx):
|
||||
if self.enable_asan:
|
||||
raise Exception('--enable-asan only supported when using Clang')
|
||||
|
||||
if builder.options.debug == '1':
|
||||
cxx.cflags += ['/MTd']
|
||||
cxx.linkflags += ['/NODEFAULTLIB:libcmt']
|
||||
@@ -269,9 +363,9 @@ class SMConfig(object):
|
||||
'/EHsc',
|
||||
'/GR-',
|
||||
'/TP',
|
||||
'/std:c++20',
|
||||
]
|
||||
cxx.linkflags += [
|
||||
'/MACHINE:X86',
|
||||
'kernel32.lib',
|
||||
'user32.lib',
|
||||
'gdi32.lib',
|
||||
@@ -286,9 +380,7 @@ class SMConfig(object):
|
||||
'odbccp32.lib',
|
||||
]
|
||||
|
||||
if builder.options.opt == '1':
|
||||
cxx.cflags += ['/Ox', '/Zo']
|
||||
cxx.linkflags += ['/OPT:ICF', '/OPT:REF']
|
||||
# Optimization flags are applied separately, earlier in configure_optimize so that the SDK static libs inherit them.
|
||||
|
||||
if builder.options.debug == '1':
|
||||
cxx.cflags += ['/Od', '/RTC1']
|
||||
@@ -297,82 +389,143 @@ class SMConfig(object):
|
||||
# Don't omit the frame pointer.
|
||||
cxx.cflags += ['/Oy-']
|
||||
|
||||
def configure_asan(self, cxx):
|
||||
if cxx.target.platform != 'linux':
|
||||
raise Exception('--enable-asan only supported on Linux')
|
||||
cxx.cflags += ['-fsanitize=address']
|
||||
cxx.linkflags += ['-fsanitize=address']
|
||||
if cxx.target.arch == 'x86':
|
||||
libclang_rt = 'libclang_rt.asan-i386.so'
|
||||
else:
|
||||
libclang_rt = 'libclang_rt.asan-x86_64.so'
|
||||
|
||||
try:
|
||||
argv = cxx.cxx_argv + ['--print-file-name', libclang_rt]
|
||||
output = subprocess.check_output(argv)
|
||||
output = output.decode('utf-8')
|
||||
output = output.strip()
|
||||
except:
|
||||
raise Exception('Could not find {}'.format(libclang_rt))
|
||||
|
||||
print('ASAN library for {}: {}'.format(cxx.target.arch, output))
|
||||
print('You will need to LD_PRELOAD this into srcds.')
|
||||
|
||||
self.asan_libs[cxx.target.arch] = os.path.dirname(output)
|
||||
|
||||
def configure_linux(self, cxx):
|
||||
cxx.defines += ['_LINUX', 'POSIX', '_FILE_OFFSET_BITS=64']
|
||||
cxx.defines += ['LINUX', '_LINUX', 'POSIX', '_FILE_OFFSET_BITS=64']
|
||||
cxx.linkflags += ['-lm']
|
||||
if cxx.family == 'gcc':
|
||||
cxx.linkflags += ['-static-libgcc']
|
||||
elif cxx.family == 'clang':
|
||||
cxx.linkflags += ['-lgcc_eh']
|
||||
cxx.linkflags += ['-static-libstdc++']
|
||||
cxx.linkflags += ['-Wl,--exclude-libs=libstdc++.a']
|
||||
|
||||
def configure_mac(self, cxx):
|
||||
cxx.defines += ['OSX', '_OSX', 'POSIX', 'KE_ABSOLUTELY_NO_STL']
|
||||
cxx.cflags += ['-mmacosx-version-min=10.5']
|
||||
cxx.cflags += ['-mmacosx-version-min=10.15']
|
||||
cxx.linkflags += [
|
||||
'-mmacosx-version-min=10.5',
|
||||
'-arch', 'i386',
|
||||
'-lstdc++',
|
||||
'-stdlib=libstdc++',
|
||||
'-mmacosx-version-min=10.15',
|
||||
'-stdlib=libc++',
|
||||
'-lc++',
|
||||
]
|
||||
cxx.cxxflags += ['-stdlib=libstdc++']
|
||||
cxx.cxxflags += ['-stdlib=libc++']
|
||||
|
||||
def configure_windows(self, cxx):
|
||||
cxx.defines += ['WIN32', '_WINDOWS']
|
||||
|
||||
def AddVersioning(self, binary):
|
||||
if builder.target.platform == 'windows':
|
||||
def add_libamtl(self):
|
||||
# Add libamtl.
|
||||
self.libamtl = {}
|
||||
for cxx in self.all_targets:
|
||||
def get_configure_fn(cxx):
|
||||
return lambda builder, name: self.StaticLibrary(builder, cxx, name)
|
||||
extra_vars = {'Configure': get_configure_fn(cxx)}
|
||||
libamtl = builder.Build('public/amtl/amtl/AMBuilder', extra_vars)
|
||||
self.libamtl[cxx.target] = libamtl.binary
|
||||
|
||||
def BinaryOutputName(self, binary, binary_type):
|
||||
target = binary.compiler.target
|
||||
if binary_type == 'program':
|
||||
name_fn = binary.compiler.vendor.nameForExecutable
|
||||
elif binary_type == 'library':
|
||||
name_fn = binary.compiler.vendor.nameForSharedLibrary
|
||||
else:
|
||||
raise Exception('Unsupported binary type: {}'.format(binary_type))
|
||||
|
||||
try:
|
||||
return name_fn(binary.name_, target)
|
||||
except TypeError:
|
||||
# Older AMBuild versions did not require the target argument.
|
||||
return name_fn(binary.name_)
|
||||
|
||||
def AddVersioning(self, binary, binary_type):
|
||||
if binary.compiler.target.platform == 'windows':
|
||||
binary.sources += ['version.rc']
|
||||
binary.compiler.rcdefines += [
|
||||
'BINARY_NAME="{0}"'.format(binary.outputFile),
|
||||
'BINARY_NAME="{0}"'.format(self.BinaryOutputName(binary, binary_type)),
|
||||
'RC_COMPILE',
|
||||
]
|
||||
if self.use_auto_versioning():
|
||||
binary.compiler.rcdefines += ['SM_GENERATED_BUILD']
|
||||
elif builder.target.platform == 'mac':
|
||||
if binary.type == 'library':
|
||||
elif binary.compiler.target.platform == 'mac':
|
||||
if binary_type == 'library':
|
||||
binary.compiler.postlink += [
|
||||
'-compatibility_version', '1.0.0',
|
||||
'-current_version', self.productVersion
|
||||
]
|
||||
if self.use_auto_versioning():
|
||||
binary.compiler.linkflags += [self.versionlib]
|
||||
binary.compiler.postlink += [self.versionlib[binary.compiler.target.arch]]
|
||||
binary.compiler.sourcedeps += SM.generated_headers
|
||||
return binary
|
||||
|
||||
def LibraryBuilder(self, compiler, name):
|
||||
binary = compiler.Library(name)
|
||||
self.AddVersioning(binary)
|
||||
self.AddVersioning(binary, 'library')
|
||||
if binary.compiler.like('msvc'):
|
||||
binary.compiler.linkflags += ['/SUBSYSTEM:WINDOWS']
|
||||
self.AddCxxCompat(binary)
|
||||
|
||||
# Dumb clang behavior means we have to manually find libclang_rt.
|
||||
if self.enable_asan:
|
||||
binary.compiler.linkflags += [
|
||||
'-shared-libsan',
|
||||
'-Wl,-rpath={}'.format(self.asan_libs[binary.compiler.target.arch]),
|
||||
]
|
||||
return binary
|
||||
|
||||
def ProgramBuilder(self, compiler, name):
|
||||
binary = compiler.Program(name)
|
||||
self.AddVersioning(binary)
|
||||
self.AddVersioning(binary, 'program')
|
||||
if '-static-libgcc' in binary.compiler.linkflags:
|
||||
binary.compiler.linkflags.remove('-static-libgcc')
|
||||
if self.enable_asan:
|
||||
binary.compiler.linkflags.append('-static-libsan')
|
||||
if '-lgcc_eh' in binary.compiler.linkflags:
|
||||
binary.compiler.linkflags.remove('-lgcc_eh')
|
||||
if binary.compiler.like('gcc'):
|
||||
binary.compiler.linkflags += ['-lstdc++']
|
||||
binary.compiler.linkflags += ['-lstdc++', '-lpthread']
|
||||
if binary.compiler.like('msvc'):
|
||||
binary.compiler.linkflags += ['/SUBSYSTEM:CONSOLE']
|
||||
return binary
|
||||
|
||||
def StaticLibraryBuilder(self, compiler, name):
|
||||
binary = compiler.StaticLibrary(name)
|
||||
return binary;
|
||||
return compiler.StaticLibrary(name)
|
||||
|
||||
def Library(self, context, name):
|
||||
compiler = context.cxx.clone()
|
||||
def Library(self, context, compiler, name):
|
||||
compiler = compiler.clone()
|
||||
SetArchFlags(compiler)
|
||||
return self.LibraryBuilder(compiler, name)
|
||||
|
||||
def Program(self, context, name):
|
||||
compiler = context.cxx.clone()
|
||||
def Program(self, context, compiler, name):
|
||||
compiler = compiler.clone()
|
||||
SetArchFlags(compiler)
|
||||
return self.ProgramBuilder(compiler, name)
|
||||
|
||||
def StaticLibrary(self, context, name):
|
||||
compiler = context.cxx.clone()
|
||||
def StaticLibrary(self, context, compiler, name):
|
||||
compiler = compiler.clone()
|
||||
SetArchFlags(compiler)
|
||||
return self.StaticLibraryBuilder(compiler, name)
|
||||
|
||||
def ConfigureForExtension(self, context, compiler):
|
||||
@@ -386,151 +539,86 @@ class SMConfig(object):
|
||||
]
|
||||
return compiler
|
||||
|
||||
def ExtLibrary(self, context, name):
|
||||
binary = self.Library(context, name)
|
||||
def ExtLibrary(self, context, compiler, name):
|
||||
binary = self.Library(context, compiler, name)
|
||||
SetArchFlags(compiler)
|
||||
self.ConfigureForExtension(context, binary.compiler)
|
||||
return binary
|
||||
|
||||
def ConfigureForHL2(self, binary, sdk):
|
||||
def AddCxxCompat(self, binary):
|
||||
if binary.compiler.target.platform == 'linux':
|
||||
binary.sources += [
|
||||
os.path.join(builder.sourcePath, 'public', 'amtl', 'compat', 'stdcxx.cpp'),
|
||||
]
|
||||
|
||||
def ConfigureForHL2(self, context, binary, sdk):
|
||||
compiler = binary.compiler
|
||||
SetArchFlags(compiler)
|
||||
|
||||
compiler.cxxincludes += [
|
||||
os.path.join(self.mms_root, 'core'),
|
||||
os.path.join(self.mms_root, 'core', 'sourcehook'),
|
||||
]
|
||||
|
||||
defines = ['SE_' + PossibleSDKs[i].define + '=' + PossibleSDKs[i].code for i in PossibleSDKs]
|
||||
compiler.defines += defines
|
||||
for other_sdk in self.sdk_manifests:
|
||||
compiler.defines += ['SE_{}={}'.format(other_sdk['define'], other_sdk['code'])]
|
||||
|
||||
paths = [
|
||||
['public'],
|
||||
['public', 'engine'],
|
||||
['public', 'mathlib'],
|
||||
['public', 'vstdlib'],
|
||||
['public', 'tier0'],
|
||||
['public', 'tier1']
|
||||
]
|
||||
if sdk.name == 'episode1' or sdk.name == 'darkm':
|
||||
paths.append(['public', 'dlls'])
|
||||
paths.append(['game_shared'])
|
||||
else:
|
||||
paths.append(['public', 'game', 'server'])
|
||||
paths.append(['public', 'toolframework'])
|
||||
paths.append(['game', 'shared'])
|
||||
paths.append(['common'])
|
||||
|
||||
compiler.defines += ['SOURCE_ENGINE=' + sdk.code]
|
||||
|
||||
if sdk.name in ['sdk2013', 'bms'] and compiler.like('gcc'):
|
||||
# The 2013 SDK already has these in public/tier0/basetypes.h
|
||||
compiler.defines.remove('stricmp=strcasecmp')
|
||||
compiler.defines.remove('_stricmp=strcasecmp')
|
||||
compiler.defines.remove('_snprintf=snprintf')
|
||||
compiler.defines.remove('_vsnprintf=vsnprintf')
|
||||
|
||||
if compiler.like('msvc'):
|
||||
compiler.defines += ['COMPILER_MSVC', 'COMPILER_MSVC32']
|
||||
if compiler.version >= 1900:
|
||||
compiler.linkflags += ['legacy_stdio_definitions.lib']
|
||||
else:
|
||||
compiler.defines += ['COMPILER_GCC']
|
||||
|
||||
# For everything after Swarm, this needs to be defined for entity networking
|
||||
# to work properly with sendprop value changes.
|
||||
if sdk.name in ['blade', 'insurgency', 'doi', 'csgo']:
|
||||
compiler.defines += ['NETWORK_VARS_ENABLED']
|
||||
|
||||
if sdk.name in ['css', 'hl2dm', 'dods', 'sdk2013', 'bms', 'tf2', 'l4d', 'nucleardawn', 'l4d2']:
|
||||
if builder.target.platform in ['linux', 'mac']:
|
||||
compiler.defines += ['NO_HOOK_MALLOC', 'NO_MALLOC_OVERRIDE']
|
||||
|
||||
if sdk.name == 'csgo' and builder.target.platform == 'linux':
|
||||
compiler.linkflags += ['-lstdc++']
|
||||
|
||||
for path in paths:
|
||||
compiler.cxxincludes += [os.path.join(sdk.path, *path)]
|
||||
|
||||
if builder.target.platform == 'linux':
|
||||
if sdk.name == 'episode1':
|
||||
lib_folder = os.path.join(sdk.path, 'linux_sdk')
|
||||
elif sdk.name in ['sdk2013', 'bms']:
|
||||
lib_folder = os.path.join(sdk.path, 'lib', 'public', 'linux32')
|
||||
else:
|
||||
lib_folder = os.path.join(sdk.path, 'lib', 'linux')
|
||||
elif builder.target.platform == 'mac':
|
||||
if sdk.name in ['sdk2013', 'bms']:
|
||||
lib_folder = os.path.join(sdk.path, 'lib', 'public', 'osx32')
|
||||
else:
|
||||
lib_folder = os.path.join(sdk.path, 'lib', 'mac')
|
||||
|
||||
if builder.target.platform in ['linux', 'mac']:
|
||||
if sdk.name in ['sdk2013', 'bms']:
|
||||
compiler.postlink += [
|
||||
compiler.Dep(os.path.join(lib_folder, 'tier1.a')),
|
||||
compiler.Dep(os.path.join(lib_folder, 'mathlib.a'))
|
||||
]
|
||||
else:
|
||||
compiler.postlink += [
|
||||
compiler.Dep(os.path.join(lib_folder, 'tier1_i486.a')),
|
||||
compiler.Dep(os.path.join(lib_folder, 'mathlib_i486.a'))
|
||||
]
|
||||
|
||||
if sdk.name in ['blade', 'insurgency', 'doi', 'csgo']:
|
||||
compiler.postlink += [compiler.Dep(os.path.join(lib_folder, 'interfaces_i486.a'))]
|
||||
|
||||
dynamic_libs = []
|
||||
if builder.target.platform == 'linux':
|
||||
if sdk.name in ['css', 'hl2dm', 'dods', 'tf2', 'sdk2013', 'bms', 'nucleardawn', 'l4d2', 'insurgency', 'doi']:
|
||||
dynamic_libs = ['libtier0_srv.so', 'libvstdlib_srv.so']
|
||||
elif sdk.name in ['l4d', 'blade', 'insurgency', 'doi', 'csgo']:
|
||||
dynamic_libs = ['libtier0.so', 'libvstdlib.so']
|
||||
else:
|
||||
dynamic_libs = ['tier0_i486.so', 'vstdlib_i486.so']
|
||||
elif builder.target.platform == 'mac':
|
||||
compiler.linkflags.append('-liconv')
|
||||
dynamic_libs = ['libtier0.dylib', 'libvstdlib.dylib']
|
||||
elif builder.target.platform == 'windows':
|
||||
libs = ['tier0', 'tier1', 'vstdlib', 'mathlib']
|
||||
if sdk.name in ['swarm', 'blade', 'insurgency', 'doi', 'csgo']:
|
||||
libs.append('interfaces')
|
||||
for lib in libs:
|
||||
lib_path = os.path.join(sdk.path, 'lib', 'public', lib) + '.lib'
|
||||
compiler.linkflags.append(compiler.Dep(lib_path))
|
||||
|
||||
for library in dynamic_libs:
|
||||
source_path = os.path.join(lib_folder, library)
|
||||
output_path = os.path.join(binary.localFolder, library)
|
||||
|
||||
def make_linker(source_path, output_path):
|
||||
def link(context, binary):
|
||||
cmd_node, (output,) = context.AddSymlink(source_path, output_path)
|
||||
return output
|
||||
return link
|
||||
|
||||
linker = make_linker(source_path, output_path)
|
||||
compiler.linkflags[0:0] = [compiler.Dep(library, linker)]
|
||||
SdkHelpers.configureCxx(context, binary, sdk)
|
||||
|
||||
return binary
|
||||
|
||||
def HL2Library(self, context, name, sdk):
|
||||
binary = self.Library(context, name)
|
||||
def AddCDetour(self, binary):
|
||||
public_path = os.path.join(builder.sourcePath, 'public')
|
||||
binary.sources += [ os.path.join(public_path, 'CDetour', 'detours.cpp') ]
|
||||
binary.compiler.cxxincludes += [ os.path.join(public_path, 'safetyhook', 'include') ]
|
||||
|
||||
for task in self.libsafetyhook:
|
||||
if task.target.arch == binary.compiler.target.arch:
|
||||
binary.compiler.linkflags += [task.binary]
|
||||
return
|
||||
raise Exception('No suitable build of safetyhook was found.')
|
||||
|
||||
def HL2Library(self, context, compiler, name, sdk):
|
||||
binary = self.Library(context, compiler, name)
|
||||
self.ConfigureForExtension(context, binary.compiler)
|
||||
return self.ConfigureForHL2(binary, sdk)
|
||||
return self.ConfigureForHL2(context, binary, sdk)
|
||||
|
||||
def HL2Project(self, context, name):
|
||||
project = context.cxx.LibraryProject(name)
|
||||
self.ConfigureForExtension(context, project.compiler)
|
||||
return project
|
||||
def HL2Config(self, project, context, compiler, name, sdk):
|
||||
binary = project.Configure(compiler, name,
|
||||
'{0} - {1} {2}'.format(self.tag, sdk['name'], compiler.target.arch))
|
||||
self.AddCxxCompat(binary)
|
||||
self.AddVersioning(binary, 'library')
|
||||
return self.ConfigureForHL2(context, binary, sdk)
|
||||
|
||||
def HL2Config(self, project, name, sdk):
|
||||
binary = project.Configure(name, '{0} - {1}'.format(self.tag, sdk.name))
|
||||
self.AddVersioning(binary)
|
||||
return self.ConfigureForHL2(binary, sdk)
|
||||
def HL2ExtConfig(self, project, context, compiler, name, sdk):
|
||||
binary = project.Configure(compiler, name,
|
||||
'{0} - {1} {2}'.format(self.tag, sdk['name'], compiler.target.arch))
|
||||
self.AddCxxCompat(binary)
|
||||
self.AddVersioning(binary, 'library')
|
||||
self.ConfigureForHL2(context, binary, sdk)
|
||||
self.ConfigureForExtension(context, binary.compiler)
|
||||
return binary
|
||||
|
||||
if getattr(builder, 'target', None) is not None:
|
||||
sys.stderr.write("Your output folder was configured for AMBuild 2.1, and SourceMod is now\n")
|
||||
sys.stderr.write("configured to use AMBuild 2.2. Please remove your output folder and\n")
|
||||
sys.stderr.write("reconfigure to continue.\n")
|
||||
os._exit(1)
|
||||
|
||||
SM = SMConfig()
|
||||
SM.detectProductVersion()
|
||||
SM.detectSDKs()
|
||||
# Apply settings that SDK static libraries must inherit to the base compilers
|
||||
# before detectSDKs() clones them.
|
||||
for cxx in SM.all_targets:
|
||||
SM.configure_pre_sdk(cxx)
|
||||
if not getattr(builder.options, 'scripting_only', False):
|
||||
SM.detectSDKs()
|
||||
SM.configure()
|
||||
SM.add_libamtl()
|
||||
|
||||
# This will clone the list and each cxx object as we recurse, preventing child
|
||||
# scripts from messing up global state.
|
||||
builder.targets = builder.CloneableList(SM.all_targets)
|
||||
|
||||
if SM.use_auto_versioning():
|
||||
SM.generated_headers = builder.Build(
|
||||
@@ -542,43 +630,103 @@ if SM.use_auto_versioning():
|
||||
{ 'SM': SM }
|
||||
)
|
||||
|
||||
class SafetyHookShim(object):
|
||||
def __init__(self):
|
||||
self.all_targets = {}
|
||||
self.libsafetyhook = {}
|
||||
|
||||
SafetyHook = SafetyHookShim()
|
||||
SafetyHook.all_targets = SM.all_targets
|
||||
builder.Build('public/safetyhook/AMBuilder', {'SafetyHook': SafetyHook })
|
||||
SM.libsafetyhook = SafetyHook.libsafetyhook
|
||||
|
||||
class SPRoot(object):
|
||||
def __init__(self):
|
||||
self.generated_headers = SM.generated_headers
|
||||
# SourcePawn's build scripts are always one-offs, and attach the current target
|
||||
# to the builder, so we have to provide a shim to our StaticLibrary() method.
|
||||
def StaticLibrary(self, builder, name):
|
||||
return SM.StaticLibrary(builder, builder.cxx, name)
|
||||
def Program(self, builder, name):
|
||||
return SM.Program(builder, builder.cxx, name)
|
||||
def Library(self, builder, name):
|
||||
return SM.Library(builder, builder.cxx, name)
|
||||
|
||||
@property
|
||||
def targets(self):
|
||||
return SM.all_targets
|
||||
|
||||
@property
|
||||
def libamtl(self):
|
||||
return SM.libamtl
|
||||
|
||||
SP_build_parts = ['core']
|
||||
if getattr(builder.options, 'scripting_only', False):
|
||||
SP_build_parts = ['spcomp']
|
||||
|
||||
# Build SourcePawn externally.
|
||||
SP = builder.Build('sourcepawn/AMBuildScript', {
|
||||
'external_root': SM,
|
||||
'external_root': SPRoot(),
|
||||
'external_amtl': os.path.join(builder.sourcePath, 'public', 'amtl'),
|
||||
'external_build': ['core'],
|
||||
'external_build': SP_build_parts,
|
||||
})
|
||||
SM.spcomp = SP.spcomp
|
||||
SM.binaries += [
|
||||
SP.libsourcepawn
|
||||
]
|
||||
|
||||
BuildScripts = [
|
||||
'loader/AMBuilder',
|
||||
'core/AMBuilder',
|
||||
'core/logic/AMBuilder',
|
||||
'extensions/bintools/AMBuilder',
|
||||
'extensions/clientprefs/AMBuilder',
|
||||
'extensions/curl/AMBuilder',
|
||||
'extensions/cstrike/AMBuilder',
|
||||
'extensions/geoip/AMBuilder',
|
||||
'extensions/mysql/AMBuilder',
|
||||
'extensions/regex/AMBuilder',
|
||||
'extensions/sdkhooks/AMBuilder',
|
||||
'extensions/sdktools/AMBuilder',
|
||||
'extensions/sqlite/AMBuilder',
|
||||
'extensions/tf2/AMBuilder',
|
||||
'extensions/topmenus/AMBuilder',
|
||||
'extensions/updater/AMBuilder',
|
||||
]
|
||||
def IsBetterDefaultSpcomp(spcomp, other):
|
||||
if other is None:
|
||||
return True
|
||||
if spcomp.target.arch == 'universal':
|
||||
return True
|
||||
if other.target.arch == 'universal':
|
||||
return False
|
||||
return spcomp.target.arch == 'x86'
|
||||
|
||||
if builder.backend == 'amb2':
|
||||
BuildScripts += [
|
||||
'plugins/AMBuilder',
|
||||
'tools/buildbot/PackageScript',
|
||||
for spcomp in SP.spcomp:
|
||||
if IsBetterDefaultSpcomp(spcomp, SM.spcomp):
|
||||
SM.spcomp = spcomp
|
||||
SM.spcomp_bins.append(spcomp)
|
||||
|
||||
for spcomp in SP.oldspcomp:
|
||||
SM.spcomp_bins.append(spcomp)
|
||||
|
||||
# If we have a universal binary, ignore all other spcomps.
|
||||
if SM.spcomp.target.arch == 'universal':
|
||||
SM.spcomp_bins = [SM.spcomp]
|
||||
|
||||
if getattr(builder.options, 'scripting_only', False):
|
||||
BuildScripts = [
|
||||
'tools/buildbot/PackageHelpers',
|
||||
'tools/buildbot/ToolsPackageScript',
|
||||
]
|
||||
else:
|
||||
BuildScripts = [
|
||||
'loader/AMBuilder',
|
||||
'core/AMBuilder',
|
||||
'core/logic/AMBuilder',
|
||||
'extensions/bintools/AMBuilder',
|
||||
'extensions/clientprefs/AMBuilder',
|
||||
'extensions/curl/AMBuilder',
|
||||
'extensions/cstrike/AMBuilder',
|
||||
'extensions/dhooks/AMBuilder',
|
||||
'extensions/geoip/AMBuilder',
|
||||
'extensions/mysql/AMBuilder',
|
||||
'extensions/pgsql/AMBuilder',
|
||||
'extensions/regex/AMBuilder',
|
||||
'extensions/sdkhooks/AMBuilder',
|
||||
'extensions/sdktools/AMBuilder',
|
||||
'extensions/sqlite/AMBuilder',
|
||||
'extensions/tf2/AMBuilder',
|
||||
'extensions/topmenus/AMBuilder',
|
||||
'extensions/updater/AMBuilder',
|
||||
]
|
||||
|
||||
builder.Build(BuildScripts, { 'SM': SM })
|
||||
if builder.backend == 'amb2':
|
||||
BuildScripts += [
|
||||
'plugins/AMBuilder',
|
||||
'tools/buildbot/PackageHelpers',
|
||||
'tools/buildbot/PackageScript',
|
||||
]
|
||||
|
||||
builder.Build(BuildScripts, { 'SM': SM, 'SP': SP })
|
||||
|
||||
if builder.options.breakpad_dump:
|
||||
builder.Build('tools/buildbot/BreakpadSymbols', { 'SM': SM })
|
||||
|
||||
@@ -14,4 +14,15 @@ Development
|
||||
- [Issue tracker](https://github.com/alliedmodders/sourcemod/issues): Issues that require back and forth communication
|
||||
- [Building SourceMod](https://wiki.alliedmods.net/Building_SourceMod): Instructions on how to build SourceMod itself using [AMBuild](https://github.com/alliedmodders/ambuild)
|
||||
- [SourcePawn scripting](https://wiki.alliedmods.net/Category:SourceMod_Scripting): SourcePawn examples and introduction to the language
|
||||
- [SourceMod plugin API](https://sm.alliedmods.net/new-api): Online SourceMod plugin API reference generated from the include files
|
||||
- [SourceMod extension development](https://wiki.alliedmods.net/Category:SourceMod_Development): C++ examples and introduction to various extension interfaces
|
||||
- [Translation project](https://github.com/orgs/alliedmodders/projects/1): Help [translate SourceMod](https://wiki.alliedmods.net/Translations_(SourceMod_Scripting)) into your language
|
||||
|
||||
Contact
|
||||
-------
|
||||
- Connect with us on [GameSurge](https://gamesurge.net) IRC in #sourcemod
|
||||
- Alternatively feel free to join our [Discord](https://discord.gg/HgZctSS) server
|
||||
|
||||
License
|
||||
-------
|
||||
SourceMod is licensed under the GNU General Public License version 3. Special exceptions are outlined in the LICENSE.txt file inside of the licenses folder.
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
version: 1.0.{build}
|
||||
image: Visual Studio 2015
|
||||
clone_folder: c:/projects/sourcemod
|
||||
clone_depth: 1
|
||||
install:
|
||||
- cmd: set PATH=C:\Python38;C:\Python38\Scripts;%PATH%
|
||||
- cmd: git submodule update --init --recursive
|
||||
- cmd: git pull --recurse-submodules
|
||||
- cmd: cd ..
|
||||
- ps: sourcemod/tools/checkout-deps.ps1 -SDKs episode1,css,tf2,l4d2,csgo
|
||||
- cmd: cd sourcemod
|
||||
build_script:
|
||||
- cmd: call "%VS140COMNTOOLS%/vsvars32.bat"
|
||||
- cmd: mkdir build
|
||||
- cmd: cd build
|
||||
- cmd: python.exe ../configure.py --enable-optimize --no-mysql --sdks=episode1,css,tf2,l4d2,csgo
|
||||
- cmd: ambuild
|
||||
@@ -35,7 +35,7 @@ namespace SourceMod {
|
||||
|
||||
// Add 1 to the RHS of this expression to bump the intercom file
|
||||
// This is to prevent mismatching core/logic binaries
|
||||
static const uint32_t SM_LOGIC_MAGIC = 0x0F47C0DE - 55;
|
||||
static const uint32_t SM_LOGIC_MAGIC = 0x0F47C0DE - 58;
|
||||
|
||||
} // namespace SourceMod
|
||||
|
||||
|
||||
@@ -30,12 +30,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <IAdminSystem.h>
|
||||
#include <amtl/am-function.h>
|
||||
|
||||
namespace SourcePawn {
|
||||
class ISourcePawnEngine;
|
||||
class ISourcePawnEngine2;
|
||||
} // namespace SourcePawn
|
||||
#include <functional>
|
||||
|
||||
// SDK types.
|
||||
#if defined(SM_LOGIC)
|
||||
@@ -67,7 +62,7 @@ struct DatabaseInfo;
|
||||
class IPlayerInfoBridge;
|
||||
class ICommandArgs;
|
||||
|
||||
typedef ke::Lambda<bool(int client, const ICommandArgs*)> CommandFunc;
|
||||
typedef std::function<bool(int client, const ICommandArgs*)> CommandFunc;
|
||||
|
||||
class CoreProvider
|
||||
{
|
||||
@@ -83,12 +78,10 @@ public:
|
||||
IMenuManager *menus;
|
||||
SourcePawn::ISourcePawnEngine **spe1;
|
||||
SourcePawn::ISourcePawnEngine2 **spe2;
|
||||
SourcePawn::ISourcePawnEnvironment **spe_env;
|
||||
const char *gamesuffix;
|
||||
/* Data */
|
||||
ServerGlobals *serverGlobals;
|
||||
void * serverFactory;
|
||||
void * engineFactory;
|
||||
void * matchmakingDSFactory;
|
||||
SMGlobalClass * listeners;
|
||||
|
||||
// ConVar functions.
|
||||
@@ -109,12 +102,14 @@ public:
|
||||
virtual bool IsMapLoading() = 0;
|
||||
virtual bool IsMapRunning() = 0;
|
||||
virtual int MaxClients() = 0;
|
||||
virtual bool DescribePlayer(int index, const char **namep, const char **authp, int *useridp) = 0;
|
||||
virtual bool DescribePlayer(int entRef, const char **namep, const char **authp, int *useridp) = 0;
|
||||
virtual void LogToGame(const char *message) = 0;
|
||||
virtual void ConPrint(const char *message) = 0;
|
||||
virtual void ConsolePrint(const char *fmt, ...) = 0;
|
||||
virtual void ConsolePrintVa(const char *fmt, va_list ap) = 0;
|
||||
|
||||
virtual void FormatSourceBinaryName(const char *basename, char *buffer, size_t maxlength) = 0;
|
||||
|
||||
// Game engine helper functions.
|
||||
virtual bool IsClientConVarQueryingSupported() = 0;
|
||||
virtual int QueryClientConVar(int client, const char *cvar) = 0;
|
||||
|
||||
@@ -29,13 +29,12 @@
|
||||
|
||||
#include <sp_vm_api.h>
|
||||
#include <IExtensionSys.h>
|
||||
#include <sh_vector.h>
|
||||
#include <vector>
|
||||
|
||||
struct edict_t;
|
||||
|
||||
namespace SourceMod {
|
||||
|
||||
using namespace SourceHook;
|
||||
using namespace SourcePawn;
|
||||
class SMPlugin;
|
||||
|
||||
@@ -51,8 +50,8 @@ public:
|
||||
virtual IExtension *GetExtensionFromIdent(IdentityToken_t *token) = 0;
|
||||
virtual void BindChildPlugin(IExtension *ext, SMPlugin *plugin) = 0;
|
||||
virtual void AddRawDependency(IExtension *myself, IdentityToken_t *token, void *iface) = 0;
|
||||
virtual const CVector<IExtension *> *ListExtensions() = 0;
|
||||
virtual void FreeExtensionList(const CVector<IExtension *> *list) = 0;
|
||||
virtual const std::vector<IExtension *> *ListExtensions() = 0;
|
||||
virtual void FreeExtensionList(const std::vector<IExtension *> *list) = 0;
|
||||
virtual void CallOnCoreMapEnd() = 0;
|
||||
};
|
||||
|
||||
@@ -67,13 +66,13 @@ public:
|
||||
{
|
||||
extensions_->FreeExtensionList(list_);
|
||||
}
|
||||
const CVector<IExtension *> *operator ->()
|
||||
const std::vector<IExtension *> *operator ->()
|
||||
{
|
||||
return list_;
|
||||
}
|
||||
private:
|
||||
IExtensionSys *extensions_;
|
||||
const CVector<IExtension *> *list_;
|
||||
const std::vector<IExtension *> *list_;
|
||||
};
|
||||
|
||||
} // namespace SourceMod
|
||||
|
||||
@@ -32,6 +32,18 @@ typedef int FileFindHandle_t;
|
||||
|
||||
namespace SourceMod {
|
||||
|
||||
typedef void *AsyncControl_t;
|
||||
|
||||
enum AsyncStatus
|
||||
{
|
||||
AsyncStatus_FileOpenError = -1,
|
||||
AsyncStatus_Ok = 0,
|
||||
AsyncStatus_Pending,
|
||||
AsyncStatus_InProgress,
|
||||
AsyncStatus_Aborted,
|
||||
AsyncStatus_Unserviced,
|
||||
};
|
||||
|
||||
class IFileSystemBridge
|
||||
{
|
||||
public:
|
||||
@@ -44,6 +56,7 @@ public:
|
||||
virtual char *ReadLine(char *pOutput, int maxChars, FileHandle_t file) = 0;
|
||||
virtual bool EndOfFile(FileHandle_t file) = 0;
|
||||
virtual bool FileExists(const char *pFileName, const char *pPathID = 0) = 0;
|
||||
virtual unsigned int Size(FileHandle_t file) = 0;
|
||||
virtual unsigned int Size(const char *pFileName, const char *pPathID = 0) = 0;
|
||||
virtual int Read(void* pOutput, int size, FileHandle_t file) = 0;
|
||||
virtual int Write(void const* pInput, int size, FileHandle_t file) = 0;
|
||||
@@ -56,6 +69,16 @@ public:
|
||||
virtual void RenameFile(char const *pOldPath, char const *pNewPath, const char *pathID = 0) = 0;
|
||||
virtual bool IsDirectory(const char *pFileName, const char *pathID = 0) = 0;
|
||||
virtual void CreateDirHierarchy(const char *path, const char *pathID = 0) = 0;
|
||||
virtual int GetSearchPath(const char* pathID, bool bGetPackFiles, char* pPath, int nMaxLen) = 0;
|
||||
virtual const char * GetGameBinArchSubdirectory() = 0;
|
||||
virtual bool SupportsAsync() = 0;
|
||||
virtual int AsyncRead(const char *filename, const char *pathID, AsyncControl_t *control) = 0;
|
||||
virtual int AsyncWrite(const char *filename, const void *data, int size, bool append,
|
||||
AsyncControl_t *control) = 0;
|
||||
virtual int AsyncStatus(AsyncControl_t control) = 0;
|
||||
virtual int AsyncGetResult(AsyncControl_t control, void **data, int *size) = 0;
|
||||
virtual void AsyncAbort(AsyncControl_t control) = 0;
|
||||
virtual void AsyncRelease(AsyncControl_t control) = 0;
|
||||
};
|
||||
|
||||
} // namespace SourceMod
|
||||
|
||||
@@ -29,12 +29,11 @@
|
||||
|
||||
#include <sp_vm_api.h>
|
||||
#include <IPluginSys.h>
|
||||
#include <sh_vector.h>
|
||||
#include <sh_string.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace SourceMod {
|
||||
|
||||
using namespace SourceHook;
|
||||
using namespace SourcePawn;
|
||||
|
||||
class IChangeableForward;
|
||||
@@ -47,8 +46,8 @@ enum LibraryAction
|
||||
|
||||
struct AutoConfig
|
||||
{
|
||||
SourceHook::String autocfg;
|
||||
SourceHook::String folder;
|
||||
std::string autocfg;
|
||||
std::string folder;
|
||||
bool create;
|
||||
};
|
||||
|
||||
@@ -78,12 +77,11 @@ public:
|
||||
virtual SMPlugin *FindPluginByOrder(unsigned num) = 0;
|
||||
virtual SMPlugin *FindPluginByIdentity(IdentityToken_t *ident) = 0;
|
||||
virtual SMPlugin *FindPluginByContext(IPluginContext *ctx) = 0;
|
||||
virtual SMPlugin *FindPluginByContext(sp_context_t *ctx) = 0;
|
||||
virtual SMPlugin *FindPluginByConsoleArg(const char *text) = 0;
|
||||
virtual SMPlugin *FindPluginByHandle(Handle_t hndl, HandleError *errp) = 0;
|
||||
virtual bool UnloadPlugin(IPlugin *plugin) = 0;
|
||||
virtual const CVector<SMPlugin *> *ListPlugins() = 0;
|
||||
virtual void FreePluginList(const CVector<SMPlugin *> *list) = 0;
|
||||
virtual const std::vector<SMPlugin *> *ListPlugins() = 0;
|
||||
virtual void FreePluginList(const std::vector<SMPlugin *> *list) = 0;
|
||||
virtual void AddFunctionsToForward(const char *name, IChangeableForward *fwd) = 0;
|
||||
};
|
||||
|
||||
@@ -98,13 +96,13 @@ public:
|
||||
{
|
||||
scripts_->FreePluginList(list_);
|
||||
}
|
||||
const CVector<SMPlugin *> *operator ->()
|
||||
const std::vector<SMPlugin *> *operator ->()
|
||||
{
|
||||
return list_;
|
||||
}
|
||||
private:
|
||||
IScriptManager *scripts_;
|
||||
const CVector<SMPlugin *> *list_;
|
||||
const std::vector<SMPlugin *> *list_;
|
||||
};
|
||||
|
||||
} // namespace SourceMod
|
||||
|
||||
@@ -50,9 +50,16 @@ class IProviderCallbacks;
|
||||
class IExtensionSys;
|
||||
class ITextParsers;
|
||||
class ILogger;
|
||||
class IDataPack;
|
||||
class ICellArray;
|
||||
|
||||
class IEntityLumpWriter
|
||||
{
|
||||
public:
|
||||
virtual void Reset() = 0;
|
||||
virtual bool AppendEntity() = 0;
|
||||
virtual bool AppendPair(const char *key, const char *value) = 0;
|
||||
};
|
||||
|
||||
struct sm_logic_t
|
||||
{
|
||||
SMGlobalClass *head;
|
||||
@@ -70,10 +77,16 @@ struct sm_logic_t
|
||||
void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...);
|
||||
void (*AddNatives)(sp_nativeinfo_t *natives);
|
||||
void (*RegisterProfiler)(IProfilingTool *tool);
|
||||
IDataPack * (*CreateDataPack)();
|
||||
void (*FreeDataPack)(IDataPack *pack);
|
||||
ICellArray * (*CreateCellArray)(size_t blocksize);
|
||||
void (*FreeCellArray)(ICellArray *arr);
|
||||
void (*SetEntityLumpWritable)(bool writable);
|
||||
bool (*ParseEntityLumpString)(const char *entityString, int &status, size_t &position);
|
||||
const char * (*GetEntityLumpString)();
|
||||
IEntityLumpWriter *(*GetEntityLumpWriter)();
|
||||
bool (*CopyEntityLump)(IEntityLumpWriter *writer);
|
||||
void (*Shutdown)();
|
||||
void (*SetJitEnabled)(bool enabled);
|
||||
void (*SetDebugMetadataFlags)(int flags);
|
||||
IScriptManager *scripts;
|
||||
IShareSys *sharesys;
|
||||
IExtensionSys *extsys;
|
||||
|
||||
+37
-19
@@ -21,6 +21,15 @@
|
||||
*/
|
||||
"LogMode" "daily"
|
||||
|
||||
/**
|
||||
* This option determines the time format SourceMod logging should use.
|
||||
*
|
||||
* "default" - Uses SourceMod's default time format. (%m/%d/%Y - %H:%M:%S)
|
||||
* You can specify any time format you want. See https://cplusplus.com/reference/ctime/strftime/ for a list of format parameters.
|
||||
* Example: "%d/%m/%Y - %H:%M:%S"
|
||||
*/
|
||||
"LogTimeFormat" "default"
|
||||
|
||||
/**
|
||||
* Language that multilingual enabled plugins and extensions will use to print messages.
|
||||
* Only languages listed in languages.cfg are valid.
|
||||
@@ -53,24 +62,6 @@
|
||||
* passwords to work, for security reasons.
|
||||
*/
|
||||
"PassInfoVar" "_password"
|
||||
|
||||
/**
|
||||
* Specifies the sound that gets played when an item is selected from a menu.
|
||||
*/
|
||||
"MenuItemSound" "buttons/button14.wav"
|
||||
|
||||
/**
|
||||
* Specifies the sound that gets played when an "Exit" button is selected
|
||||
* from a menu.
|
||||
*/
|
||||
"MenuExitSound" "buttons/combine_button7.wav"
|
||||
|
||||
/**
|
||||
* Specifies the sound that gets played when an "Exit Back" button is selected
|
||||
* from a menu. This is the special "Back" button that is intended to roll back
|
||||
* to a previous menu.
|
||||
*/
|
||||
"MenuExitBackSound" "buttons/combine_button7.wav"
|
||||
|
||||
/**
|
||||
* Enables or disables whether SourceMod reads a client's cl_language cvar to set
|
||||
@@ -126,6 +117,16 @@
|
||||
*/
|
||||
"BlockBadPlugins" "yes"
|
||||
|
||||
/**
|
||||
* Controls how plugin unloads handle outstanding threaded database operations.
|
||||
*
|
||||
* "discard" - Immediately discard the plugin's outstanding database operations.
|
||||
* This is the default and keeps the server responsive.
|
||||
* "wait" - Wait for outstanding operations and run their callbacks before unload.
|
||||
* Warning: This can stall the server.
|
||||
*/
|
||||
"DatabasePluginUnload" "discard"
|
||||
|
||||
/**
|
||||
* If a plugin takes too long to execute, hanging or freezing the game server in the process,
|
||||
* SourceMod will attempt to terminate that plugin after the specified timeout length has
|
||||
@@ -145,5 +146,22 @@
|
||||
* Disable this option at your own risk.
|
||||
*/
|
||||
"FollowCSGOServerGuidelines" "yes"
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls whether the SourcePawn runtime will generate additional metadata about
|
||||
* JIT-compiled functions for performance profiling or debugging purposes.
|
||||
*
|
||||
* "none" - Don't generate any additional JIT metadata
|
||||
* "default" - Generate basic perf metadata (on Linux) and delete it automatically on quit
|
||||
* "perf" - Generate basic perf metadata (Linux only - function names)
|
||||
* "jitdump" - Generate extended perf metadata (Linux only - function names, bytecode, and source information)
|
||||
*/
|
||||
"JITMetadata" "default"
|
||||
|
||||
/**
|
||||
* Setup the SourcePawn VM to enable extensions to use a debugging API to step through
|
||||
* plugins line by line. This heavily decreases server performance and should NEVER be
|
||||
* used on a production server, but ONLY during plugin development.
|
||||
*/
|
||||
"EnableLineDebugging" "no"
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"pass" ""
|
||||
//"timeout" "0"
|
||||
//"port" "0"
|
||||
//"schema" "public" // PostgreSQL only
|
||||
}
|
||||
|
||||
"storage-local"
|
||||
|
||||
Binary file not shown.
+35
-1
@@ -1,4 +1,38 @@
|
||||
"Languages"
|
||||
{
|
||||
"en" "English"
|
||||
"ar" "Arabic" // Arabic
|
||||
"bg" "Bulgarian" // Bulgarian
|
||||
"chi" "SChinese" // Chinese (Simplified)
|
||||
"cze" "Czech" // Czech
|
||||
"da" "Danish" // Danish
|
||||
"de" "German" // German
|
||||
"el" "Greek" // Greek
|
||||
"en" "English" // English
|
||||
"es" "Spanish" // Spanish
|
||||
"fi" "Finnish" // Finnish
|
||||
"fr" "French" // French
|
||||
"he" "Hebrew" // Hebrew
|
||||
"hu" "Hungarian" // Hungarian
|
||||
"it" "Italian" // Italian
|
||||
"jp" "Japanese" // Japanese
|
||||
"ko" "Korean" // Korean
|
||||
"ko" "KoreanA" // Korean (https://bugs.alliedmods.net/show_bug.cgi?id=4667)
|
||||
"las" "LatAm" // Latin American Spanish
|
||||
"lt" "Lithuanian" // Lithuanian
|
||||
"lv" "Latvian" // Latvian
|
||||
"nl" "Dutch" // Dutch
|
||||
"no" "Norwegian" // Norwegian
|
||||
"pl" "Polish" // Polish
|
||||
"pt" "Brazilian" // Brazilian Portuguese
|
||||
"pt_p" "Portuguese" // Portuguese
|
||||
"ro" "Romanian" // Romanian
|
||||
"ru" "Russian" // Russian
|
||||
"sk" "Slovak" // Slovak
|
||||
"sv" "Swedish" // Swedish
|
||||
"th" "Thai" // Thai
|
||||
"tr" "Turkish" // Turkish
|
||||
"ua" "Ukrainian" // Ukrainian
|
||||
"vi" "Vietnamese" // Vietnamese
|
||||
"zho" "TChinese" // Chinese (Traditional)
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
CREATE TABLE IF NOT EXISTS sm_cookies
|
||||
(
|
||||
id serial,
|
||||
name varchar(30) NOT NULL UNIQUE,
|
||||
description varchar(255),
|
||||
access INTEGER,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sm_cookie_cache
|
||||
(
|
||||
player varchar(65) NOT NULL,
|
||||
cookie_id int NOT NULL,
|
||||
value varchar(100),
|
||||
timestamp int NOT NULL,
|
||||
PRIMARY KEY (player, cookie_id)
|
||||
);
|
||||
|
||||
CREATE OR REPLACE LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION add_or_update_cookie(in_player VARCHAR(65), in_cookie INT, in_value VARCHAR(100), in_time INT) RETURNS VOID AS
|
||||
$$
|
||||
BEGIN
|
||||
LOOP
|
||||
-- first try to update the it.
|
||||
UPDATE sm_cookie_cache SET value = in_value, timestamp = in_time WHERE player = in_player AND cookie_id = in_cookie;
|
||||
IF found THEN
|
||||
RETURN;
|
||||
END IF;
|
||||
-- not there, so try to insert.
|
||||
-- if someone else inserts the same key concurrently, we could get a unique-key failure.
|
||||
BEGIN
|
||||
INSERT INTO sm_cookie_cache (player, cookie_id, value, timestamp) VALUES (in_player, in_cookie, in_value, in_time);
|
||||
RETURN;
|
||||
EXCEPTION WHEN unique_violation THEN
|
||||
-- do nothing... loop again, and we'll update.
|
||||
END;
|
||||
END LOOP;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE plpgsql;
|
||||
@@ -0,0 +1,65 @@
|
||||
CREATE TABLE IF NOT EXISTS sm_admins (
|
||||
id serial,
|
||||
authtype varchar(6) NOT NULL,
|
||||
CHECK (authtype in ('steam', 'name', 'ip')),
|
||||
identity varchar(65) NOT NULL,
|
||||
password varchar(65),
|
||||
flags varchar(30) NOT NULL,
|
||||
name varchar(65) NOT NULL,
|
||||
immunity int NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sm_groups (
|
||||
id serial,
|
||||
flags varchar(30) NOT NULL,
|
||||
name varchar(120) NOT NULL,
|
||||
immunity_level int NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sm_group_immunity (
|
||||
group_id int NOT NULL,
|
||||
other_id int NOT NULL,
|
||||
FOREIGN KEY (group_id) REFERENCES sm_groups(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (other_id) REFERENCES sm_groups(id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (group_id, other_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sm_group_overrides (
|
||||
group_id int NOT NULL,
|
||||
FOREIGN KEY (group_id) REFERENCES sm_groups(id) ON DELETE CASCADE,
|
||||
type varchar(10) NOT NULL,
|
||||
CHECK (type in ('command', 'group')),
|
||||
name varchar(32) NOT NULL,
|
||||
access varchar(5) NOT NULL,
|
||||
CHECK (access in ('allow', 'deny')),
|
||||
PRIMARY KEY (group_id, type, name)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sm_overrides (
|
||||
type varchar(10) NOT NULL,
|
||||
CHECK (type in ('command', 'group')),
|
||||
name varchar(32) NOT NULL,
|
||||
flags varchar(30) NOT NULL,
|
||||
PRIMARY KEY (type,name)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sm_admins_groups (
|
||||
admin_id int NOT NULL,
|
||||
group_id int NOT NULL,
|
||||
FOREIGN KEY (admin_id) REFERENCES sm_admins(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (group_id) REFERENCES sm_groups(id) ON DELETE CASCADE,
|
||||
inherit_order int NOT NULL,
|
||||
PRIMARY KEY (admin_id, group_id)
|
||||
);
|
||||
|
||||
-- side note, this is pgsql module, sm_config will not exist if the above stuff exists... and it's being left to the admin
|
||||
-- to figure out if it exists.
|
||||
CREATE TABLE IF NOT EXISTS sm_config (
|
||||
cfg_key varchar(32) NOT NULL,
|
||||
cfg_value varchar(255) NOT NULL,
|
||||
PRIMARY KEY (cfg_key)
|
||||
);
|
||||
|
||||
INSERT INTO sm_config (cfg_key, cfg_value) VALUES ('admin_version', '1.0.0.1409') ON CONFLICT (cfg_key) DO UPDATE SET cfg_value = EXCLUDED.cfg_value;
|
||||
+37
-28
@@ -1,40 +1,49 @@
|
||||
# vim: set ts=2 sw=2 tw=99 noet:
|
||||
import sys
|
||||
try:
|
||||
from ambuild2 import run, util
|
||||
from ambuild2 import run, util
|
||||
except:
|
||||
try:
|
||||
import ambuild
|
||||
sys.stderr.write('It looks like you have AMBuild 1 installed, but this project uses AMBuild 2.\n')
|
||||
sys.stderr.write('Upgrade to the latest version of AMBuild to continue.\n')
|
||||
except:
|
||||
sys.stderr.write('AMBuild must be installed to build this project.\n')
|
||||
sys.stderr.write('http://www.alliedmods.net/ambuild\n')
|
||||
sys.exit(1)
|
||||
try:
|
||||
import ambuild
|
||||
sys.stderr.write('It looks like you have AMBuild 1 installed, but this project uses AMBuild 2.\n')
|
||||
sys.stderr.write('Upgrade to the latest version of AMBuild to continue.\n')
|
||||
except:
|
||||
sys.stderr.write('AMBuild must be installed to build this project.\n')
|
||||
sys.stderr.write('http://www.alliedmods.net/ambuild\n')
|
||||
sys.exit(1)
|
||||
|
||||
def make_objdir_name(p):
|
||||
return 'obj-' + util.Platform() + '-' + p.target_arch
|
||||
# Hack to show a decent upgrade message, which wasn't done until 2.2.
|
||||
ambuild_version = getattr(run, 'CURRENT_API', '2.1')
|
||||
if ambuild_version.startswith('2.1'):
|
||||
sys.stderr.write("AMBuild 2.2 or higher is required; please update\n")
|
||||
sys.exit(1)
|
||||
|
||||
parser = run.BuildParser(sourcePath=sys.path[0], api='2.1')
|
||||
parser.default_arch = 'x86'
|
||||
parser.default_build_folder = make_objdir_name
|
||||
parser.options.add_option('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None,
|
||||
help='Root search folder for HL2SDKs')
|
||||
parser.options.add_option('--mysql-path', type=str, dest='mysql_path', default=None,
|
||||
help='Path to MySQL 5')
|
||||
parser.options.add_option('--mms-path', type=str, dest='mms_path', default=None,
|
||||
parser = run.BuildParser(sourcePath=sys.path[0], api='2.2')
|
||||
parser.options.add_argument('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None,
|
||||
help='Root search folder for HL2SDKs')
|
||||
parser.options.add_argument('--mariadb-path', type=str, dest='mariadb_path', default=None,
|
||||
help='Path to x86 MariaDB Connector/C')
|
||||
parser.options.add_argument('--mariadb64-path', type=str, dest='mariadb64_path', default=None,
|
||||
help='Path to x86_64 MariaDB Connector/C')
|
||||
parser.options.add_argument('--mms-path', type=str, dest='mms_path', default=None,
|
||||
help='Path to Metamod:Source')
|
||||
parser.options.add_option('--enable-debug', action='store_const', const='1', dest='debug',
|
||||
parser.options.add_argument('--enable-debug', action='store_const', const='1', dest='debug',
|
||||
help='Enable debugging symbols')
|
||||
parser.options.add_option('--enable-optimize', action='store_const', const='1', dest='opt',
|
||||
parser.options.add_argument('--enable-optimize', action='store_const', const='1', dest='opt',
|
||||
help='Enable optimization')
|
||||
parser.options.add_option('--no-mysql', action='store_false', default=True, dest='hasMySql',
|
||||
parser.options.add_argument('--no-mysql', action='store_false', default=True, dest='hasMySql',
|
||||
help='Disable building MySQL extension')
|
||||
parser.options.add_option('-s', '--sdks', default='all', dest='sdks',
|
||||
help='Build against specified SDKs; valid args are "all", "present", or '
|
||||
'comma-delimited list of engine names (default: %default)')
|
||||
parser.options.add_option('--breakpad-dump', action='store_true', dest='breakpad_dump',
|
||||
default=False, help='Dump and upload breakpad symbols')
|
||||
parser.options.add_option('--disable-auto-versioning', action='store_true', dest='disable_auto_versioning',
|
||||
parser.options.add_argument('-s', '--sdks', default='present', dest='sdks',
|
||||
help='Build against specified SDKs; valid args are "none", "all", "present",'
|
||||
' or comma-delimited list of engine names')
|
||||
parser.options.add_argument('--breakpad-dump', action='store_true', dest='breakpad_dump',
|
||||
default=False, help='Dump and upload breakpad symbols')
|
||||
parser.options.add_argument('--disable-auto-versioning', action='store_true', dest='disable_auto_versioning',
|
||||
default=False, help='Disable the auto versioning script')
|
||||
parser.options.add_argument('--targets', type=str, dest='targets', default=None,
|
||||
help="Override the target architecture (use commas to separate multiple targets).")
|
||||
parser.options.add_argument('--scripting-only', action='store_true', dest='scripting_only', default=False,
|
||||
help="Only build and package the files required for scripting in SourcePawn.")
|
||||
parser.options.add_argument('--enable-asan', action='store_true', dest='enable_asan',
|
||||
default=False, help='Enable ASAN (clang only)')
|
||||
parser.Configure()
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Build stage - use the same image as sourcemod CI builds
|
||||
FROM ghcr.io/alliedmodders/build-containers/debian11:latest AS builder
|
||||
|
||||
COPY sourcepawn/ /build/sourcepawn/
|
||||
|
||||
WORKDIR /build/sourcepawn
|
||||
RUN mkdir build && cd build && \
|
||||
python3 ../configure.py --enable-optimize --targets=x86_64 && \
|
||||
ambuild
|
||||
|
||||
# Runtime stage
|
||||
FROM debian:bullseye-slim
|
||||
|
||||
# AMBuild names the per-target output folder <platform>-<arch>; since this stage
|
||||
# always builds linux/x86_64, that's deterministically "linux-x86_64".
|
||||
COPY --from=builder --chmod=0755 /build/sourcepawn/build/spcomp/linux-x86_64/spcomp /usr/local/bin/spcomp
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/spcomp"]
|
||||
+92
-34
@@ -1,7 +1,8 @@
|
||||
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
|
||||
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
|
||||
import os
|
||||
|
||||
project = SM.HL2Project(builder, 'sourcemod')
|
||||
project = builder.LibraryProject('sourcemod')
|
||||
|
||||
project.sources += [
|
||||
'MenuStyle_Valve.cpp',
|
||||
'logic_bridge.cpp',
|
||||
@@ -37,67 +38,124 @@ project.sources += [
|
||||
'MenuStyle_Radio.cpp',
|
||||
'sm_autonatives.cpp',
|
||||
'ConsoleDetours.cpp',
|
||||
'vprof_tool.cpp',
|
||||
'smn_commandline.cpp',
|
||||
'GameHooks.cpp',
|
||||
]
|
||||
|
||||
for sdk_name in SM.sdks:
|
||||
sdk = SM.sdks[sdk_name]
|
||||
binary_name = 'sourcemod.' + sdk.ext
|
||||
# SDK name to shipping gamedir, mostly
|
||||
pb_gamedir_map = {
|
||||
'csgo': 'csgo',
|
||||
'blade': 'berimbau',
|
||||
'mcv': 'vietnam',
|
||||
'outbreak': 'terror'
|
||||
}
|
||||
|
||||
# SDK name to source code gamedir
|
||||
pb_gamesrcdir_map = {
|
||||
'csgo': 'cstrike15',
|
||||
'blade': 'berimbau',
|
||||
'mcv': 'vietnam',
|
||||
'outbreak': 'terror',
|
||||
}
|
||||
|
||||
for sdk_target in SM.sdk_targets:
|
||||
sdk = sdk_target.sdk
|
||||
cxx = sdk_target.cxx
|
||||
|
||||
binary_name = 'sourcemod.' + sdk['extension']
|
||||
needs_protobuf = sdk['name'] in ['csgo', 'blade', 'mcv', 'outbreak']
|
||||
|
||||
binary = SM.HL2Config(project, builder, cxx, binary_name, sdk)
|
||||
SM.ConfigureForExtension(builder, binary.compiler)
|
||||
|
||||
binary = SM.HL2Config(project, binary_name, sdk)
|
||||
compiler = binary.compiler
|
||||
|
||||
compiler.cxxincludes += [
|
||||
builder.sourcePath
|
||||
]
|
||||
|
||||
if sdk.name == 'csgo':
|
||||
if needs_protobuf:
|
||||
compiler.cxxincludes += [
|
||||
os.path.join(sdk.path, 'common', 'protobuf-2.5.0', 'src'),
|
||||
os.path.join(sdk.path, 'public', 'engine', 'protobuf'),
|
||||
os.path.join(sdk.path, 'public', 'game', 'shared', 'csgo', 'protobuf')
|
||||
os.path.join(sdk['path'], 'public', 'engine', 'protobuf'),
|
||||
os.path.join(sdk['path'], 'public', 'game', 'shared', pb_gamedir_map[sdk['name']], 'protobuf')
|
||||
]
|
||||
|
||||
if builder.target.platform == 'linux':
|
||||
if sdk['name'] == 'outbreak':
|
||||
compiler.cxxincludes += [
|
||||
# Outbreak has "base" usermessages split from the game-specific ones
|
||||
os.path.join(sdk['path'], 'public', 'game', 'shared', 'protobuf')
|
||||
]
|
||||
protobuf_version = "2.5.0"
|
||||
if sdk['name'] == 'mcv':
|
||||
protobuf_version = "3.2.0"
|
||||
elif sdk['name'] == 'outbreak':
|
||||
protobuf_version = "3.17.3"
|
||||
compiler.cxxincludes += [
|
||||
os.path.join(sdk['path'], 'common', 'protobuf-' + protobuf_version, 'src')
|
||||
]
|
||||
|
||||
if compiler.like('msvc'):
|
||||
compiler.defines += ['_ALLOW_KEYWORD_MACROS']
|
||||
if cxx.target.platform == 'linux':
|
||||
compiler.postlink += ['-lpthread', '-lrt']
|
||||
|
||||
if sdk.name == 'csgo':
|
||||
if builder.target.platform == 'linux':
|
||||
lib_path = os.path.join(sdk.path, 'lib', 'linux32', 'release', 'libprotobuf.a')
|
||||
if needs_protobuf:
|
||||
if compiler.target.platform == 'linux':
|
||||
if compiler.target.arch == 'x86':
|
||||
lib_path = os.path.join(sdk['path'], 'lib', 'linux32', 'release', 'libprotobuf.a')
|
||||
elif compiler.target.arch == 'x86_64':
|
||||
lib_path = os.path.join(sdk['path'], 'lib', 'linux64', 'release', 'libprotobuf.a')
|
||||
compiler.linkflags += ['-Wl,--exclude-libs=libprotobuf.a']
|
||||
elif builder.target.platform == 'mac':
|
||||
lib_path = os.path.join(sdk.path, 'lib', 'osx32', 'release', 'libprotobuf.a')
|
||||
elif builder.target.platform == 'windows':
|
||||
elif compiler.target.platform == 'mac':
|
||||
if compiler.target.arch == 'x86':
|
||||
lib_path = os.path.join(sdk['path'], 'lib', 'osx32', 'release', 'libprotobuf.a')
|
||||
elif compiler.target.arch == 'x86_64':
|
||||
lib_path = os.path.join(sdk['path'], 'lib', 'osx64', 'release', 'libprotobuf.a')
|
||||
elif compiler.target.platform == 'windows':
|
||||
msvc_ver = compiler.version
|
||||
vs_year = ''
|
||||
if msvc_ver == 1800:
|
||||
vs_year = '2013'
|
||||
elif msvc_ver == 1900:
|
||||
platform = ''
|
||||
if compiler.target.arch == 'x86':
|
||||
platform = 'win32'
|
||||
elif compiler.target.arch == 'x86_64':
|
||||
platform = 'win64'
|
||||
|
||||
if 1900 <= msvc_ver < 2000:
|
||||
vs_year = '2015'
|
||||
elif msvc_ver == 1910:
|
||||
vs_year = '2017'
|
||||
else:
|
||||
raise Exception('Cannot find libprotobuf for MSVC version "' + str(compiler.version) + '"')
|
||||
|
||||
if 'DEBUG' in compiler.defines:
|
||||
lib_path = os.path.join(sdk.path, 'lib', 'win32', 'debug', 'vs' + vs_year, 'libprotobuf.lib')
|
||||
lib_path = os.path.join(sdk['path'], 'lib', platform, 'debug', 'vs' + vs_year, 'libprotobuf.lib')
|
||||
else:
|
||||
lib_path = os.path.join(sdk.path, 'lib', 'win32', 'release', 'vs' + vs_year, 'libprotobuf.lib')
|
||||
compiler.linkflags.insert(0, binary.Dep(lib_path))
|
||||
|
||||
if sdk.name == 'csgo':
|
||||
lib_path = os.path.join(sdk['path'], 'lib', platform, 'release', 'vs' + vs_year, 'libprotobuf.lib')
|
||||
compiler.linkflags.insert(0, lib_path)
|
||||
|
||||
if needs_protobuf:
|
||||
binary.sources += ['smn_protobuf.cpp']
|
||||
else:
|
||||
binary.sources += ['smn_bitbuffer.cpp']
|
||||
|
||||
if sdk.name == 'csgo':
|
||||
if sdk['name'] != 'blade':
|
||||
binary.sources += [
|
||||
os.path.join(sdk.path, 'public', 'engine', 'protobuf', 'netmessages.pb.cc'),
|
||||
os.path.join(sdk.path, 'public', 'game', 'shared', 'csgo', 'protobuf', 'cstrike15_usermessages.pb.cc'),
|
||||
os.path.join(sdk.path, 'public', 'game', 'shared', 'csgo', 'protobuf', 'cstrike15_usermessage_helpers.cpp'),
|
||||
'vprof_tool.cpp',
|
||||
]
|
||||
|
||||
if needs_protobuf:
|
||||
binary.sources += [
|
||||
os.path.join(sdk['path'], 'public', 'engine', 'protobuf', 'netmessages.pb.cc'),
|
||||
os.path.join(sdk['path'], 'public', 'game', 'shared', pb_gamedir_map[sdk['name']], 'protobuf', pb_gamesrcdir_map[sdk['name']] + '_usermessages.pb.cc'),
|
||||
os.path.join(sdk['path'], 'public', 'game', 'shared', pb_gamedir_map[sdk['name']], 'protobuf', pb_gamesrcdir_map[sdk['name']] + '_usermessage_helpers.cpp'),
|
||||
]
|
||||
if sdk['name'] == 'mcv':
|
||||
binary.sources += [
|
||||
os.path.join(sdk['path'], 'public', 'game', 'shared', pb_gamedir_map[sdk['name']], 'protobuf', pb_gamesrcdir_map[sdk['name']] + '_gcmessages.pb.cc'),
|
||||
os.path.join(sdk['path'], 'public', 'engine', 'protobuf', 'engine_gcmessages.pb.cc'),
|
||||
]
|
||||
if sdk['name'] == 'outbreak':
|
||||
binary.sources += [
|
||||
os.path.join(sdk['path'], 'public', 'engine', 'protobuf', 'network_connection.pb.cc'),
|
||||
os.path.join(sdk['path'], 'public', 'game', 'shared', 'protobuf', 'base_usermessages.pb.cc'),
|
||||
os.path.join(sdk['path'], 'public', 'game', 'shared', 'protobuf', 'base_usermessage_helpers.cpp'),
|
||||
]
|
||||
|
||||
SM.binaries += builder.Add(project)
|
||||
|
||||
|
||||
+35
-21
@@ -29,6 +29,8 @@
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <ITextParsers.h>
|
||||
#include "ChatTriggers.h"
|
||||
#include "sm_stringutil.h"
|
||||
@@ -64,7 +66,7 @@ ChatTriggers::~ChatTriggers()
|
||||
|
||||
void ChatTriggers::SetChatTrigger(ChatTriggerType type, const char *value)
|
||||
{
|
||||
ke::AutoPtr<char[]> filtered(new char[strlen(value) + 1]);
|
||||
std::unique_ptr<char[]> filtered(new char[strlen(value) + 1]);
|
||||
|
||||
const char *src = value;
|
||||
char *dest = filtered.get();
|
||||
@@ -135,26 +137,26 @@ void ChatTriggers::OnSourceModGameInitialized()
|
||||
};
|
||||
|
||||
if (ConCommand *say = FindCommand("say")) {
|
||||
hooks_.append(sCoreProviderImpl.AddCommandHook(say, pre_hook));
|
||||
hooks_.append(sCoreProviderImpl.AddPostCommandHook(say, post_hook));
|
||||
hooks_.push_back(sCoreProviderImpl.AddCommandHook(say, pre_hook));
|
||||
hooks_.push_back(sCoreProviderImpl.AddPostCommandHook(say, post_hook));
|
||||
}
|
||||
if (ConCommand *say_team = FindCommand("say_team")) {
|
||||
hooks_.append(sCoreProviderImpl.AddCommandHook(say_team, pre_hook));
|
||||
hooks_.append(sCoreProviderImpl.AddPostCommandHook(say_team, post_hook));
|
||||
hooks_.push_back(sCoreProviderImpl.AddCommandHook(say_team, pre_hook));
|
||||
hooks_.push_back(sCoreProviderImpl.AddPostCommandHook(say_team, post_hook));
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_EPISODEONE
|
||||
m_bIsINS = (strcmp(g_SourceMod.GetGameFolderName(), "insurgency") == 0);
|
||||
if (m_bIsINS) {
|
||||
if (ConCommand *say2 = FindCommand("say2")) {
|
||||
hooks_.append(sCoreProviderImpl.AddCommandHook(say2, pre_hook));
|
||||
hooks_.append(sCoreProviderImpl.AddPostCommandHook(say2, post_hook));
|
||||
hooks_.push_back(sCoreProviderImpl.AddCommandHook(say2, pre_hook));
|
||||
hooks_.push_back(sCoreProviderImpl.AddPostCommandHook(say2, post_hook));
|
||||
}
|
||||
}
|
||||
#elif SOURCE_ENGINE == SE_NUCLEARDAWN
|
||||
if (ConCommand *say_squad = FindCommand("say_squad")) {
|
||||
hooks_.append(sCoreProviderImpl.AddCommandHook(say_squad, pre_hook));
|
||||
hooks_.append(sCoreProviderImpl.AddPostCommandHook(say_squad, post_hook));
|
||||
hooks_.push_back(sCoreProviderImpl.AddCommandHook(say_squad, pre_hook));
|
||||
hooks_.push_back(sCoreProviderImpl.AddPostCommandHook(say_squad, post_hook));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -275,10 +277,10 @@ bool ChatTriggers::OnSayCommand_Pre(int client, const ICommandArgs *command)
|
||||
bool is_silent = false;
|
||||
|
||||
// Prefer the silent trigger in case of clashes.
|
||||
if (strchr(m_PrivTrigger.chars(), m_ArgSBackup[0])) {
|
||||
if (strchr(m_PrivTrigger.c_str(), m_ArgSBackup[0])) {
|
||||
is_trigger = true;
|
||||
is_silent = true;
|
||||
} else if (strchr(m_PubTrigger.chars(), m_ArgSBackup[0])) {
|
||||
} else if (strchr(m_PubTrigger.c_str(), m_ArgSBackup[0])) {
|
||||
is_trigger = true;
|
||||
}
|
||||
|
||||
@@ -361,7 +363,7 @@ bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args)
|
||||
if (!g_ConCmds.LookForSourceModCommand(cmd_buf))
|
||||
{
|
||||
/* Check if we had an "sm_" prefix */
|
||||
if (strncmp(cmd_buf, "sm_", 3) == 0)
|
||||
if (strncasecmp(cmd_buf, "sm_", 3) == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -385,15 +387,7 @@ bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args)
|
||||
/* See if we need to do extra string manipulation */
|
||||
if (prepended)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
/* Check if we need to prepend sm_ */
|
||||
if (prepended)
|
||||
{
|
||||
len = ke::SafeSprintf(m_ToExecute, sizeof(m_ToExecute), "sm_%s", args);
|
||||
} else {
|
||||
len = ke::SafeStrcpy(m_ToExecute, sizeof(m_ToExecute), args);
|
||||
}
|
||||
ke::SafeSprintf(m_ToExecute, sizeof(m_ToExecute), "sm_%s", args);
|
||||
} else {
|
||||
ke::SafeStrcpy(m_ToExecute, sizeof(m_ToExecute), args);
|
||||
}
|
||||
@@ -467,3 +461,23 @@ bool ChatTriggers::WasFloodedMessage()
|
||||
{
|
||||
return m_bWasFloodedMessage;
|
||||
}
|
||||
|
||||
const char *ChatTriggers::GetPublicChatTrigger()
|
||||
{
|
||||
if (!m_PubTrigger.length())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return m_PubTrigger.c_str();
|
||||
}
|
||||
|
||||
const char *ChatTriggers::GetPrivateChatTrigger()
|
||||
{
|
||||
if (!m_PrivTrigger.length())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return m_PrivTrigger.c_str();
|
||||
}
|
||||
|
||||
+5
-3
@@ -63,6 +63,8 @@ public:
|
||||
unsigned int SetReplyTo(unsigned int reply);
|
||||
bool IsChatTrigger();
|
||||
bool WasFloodedMessage();
|
||||
const char *GetPublicChatTrigger();
|
||||
const char *GetPrivateChatTrigger();
|
||||
private:
|
||||
enum ChatTriggerType {
|
||||
ChatTrigger_Public,
|
||||
@@ -73,9 +75,9 @@ private:
|
||||
bool ClientIsFlooding(int client);
|
||||
cell_t CallOnClientSayCommand(int client);
|
||||
private:
|
||||
ke::Vector<ke::RefPtr<CommandHook>> hooks_;
|
||||
ke::AString m_PubTrigger;
|
||||
ke::AString m_PrivTrigger;
|
||||
std::vector<ke::RefPtr<CommandHook>> hooks_;
|
||||
std::string m_PubTrigger;
|
||||
std::string m_PrivTrigger;
|
||||
bool m_bWillProcessInPost;
|
||||
bool m_bIsChatTrigger;
|
||||
bool m_bWasFloodedMessage;
|
||||
|
||||
+50
-72
@@ -30,21 +30,22 @@
|
||||
*/
|
||||
|
||||
#include "ConCmdManager.h"
|
||||
#include "sm_stringutil.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "HalfLife2.h"
|
||||
#include "ChatTriggers.h"
|
||||
#include "logic_bridge.h"
|
||||
#include "sourcemod.h"
|
||||
#include "provider.h"
|
||||
#include "command_args.h"
|
||||
|
||||
#include <bridge/include/IScriptManager.h>
|
||||
#include "ChatTriggers.h"
|
||||
#include "HalfLife2.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "command_args.h"
|
||||
#include "logic_bridge.h"
|
||||
#include "provider.h"
|
||||
#include "sm_stringutil.h"
|
||||
#include "sourcemod.h"
|
||||
|
||||
using namespace ke;
|
||||
|
||||
ConCmdManager g_ConCmds;
|
||||
|
||||
typedef ke::LinkedList<CmdHook *> PluginHookList;
|
||||
typedef std::list<CmdHook *> PluginHookList;
|
||||
void RegisterInPlugin(CmdHook *hook);
|
||||
|
||||
ConCmdManager::ConCmdManager()
|
||||
@@ -75,18 +76,18 @@ void ConCmdManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *na
|
||||
if (!m_Cmds.retrieve(name, &pInfo))
|
||||
return;
|
||||
|
||||
CmdHookList::iterator iter = pInfo->hooks.begin();
|
||||
auto iter = pInfo->hooks.begin();
|
||||
while (iter != pInfo->hooks.end())
|
||||
{
|
||||
CmdHook *hook = *iter;
|
||||
|
||||
IPluginContext *pContext = hook->pf->GetParentContext();
|
||||
IPlugin *pPlugin = scripts->FindPluginByContext(pContext->GetContext());
|
||||
IPlugin *pPlugin = scripts->FindPluginByContext(pContext);
|
||||
|
||||
// The list is guaranteed to exist.
|
||||
PluginHookList *list;
|
||||
pPlugin->GetProperty("CommandList", (void **)&list, false);
|
||||
for (PluginHookList::iterator hiter = list->begin(); hiter != list->end(); hiter++)
|
||||
for (auto hiter = list->begin(); hiter != list->end(); hiter++)
|
||||
{
|
||||
if (*hiter == hook)
|
||||
{
|
||||
@@ -111,7 +112,7 @@ void ConCmdManager::OnPluginDestroyed(IPlugin *plugin)
|
||||
if (!plugin->GetProperty("CommandList", (void **)&pList, true))
|
||||
return;
|
||||
|
||||
PluginHookList::iterator iter = pList->begin();
|
||||
auto iter = pList->begin();
|
||||
while (iter != pList->end())
|
||||
{
|
||||
CmdHook *hook = *iter;
|
||||
@@ -120,8 +121,13 @@ void ConCmdManager::OnPluginDestroyed(IPlugin *plugin)
|
||||
if (hook->admin)
|
||||
hook->admin->group->hooks.remove(hook);
|
||||
|
||||
if (hook->info->hooks.empty())
|
||||
if (hook->info->hooks.empty()) {
|
||||
RemoveConCmd(hook->info, hook->info->pCmd->GetName(), true);
|
||||
}
|
||||
else { // update plugin reference to next hook in line
|
||||
auto next = *hook->info->hooks.begin();
|
||||
next->info->pPlugin = next->plugin;
|
||||
}
|
||||
|
||||
iter = pList->erase(iter);
|
||||
delete hook;
|
||||
@@ -147,41 +153,24 @@ ConCmdInfo *ConCmdManager::FindInTrie(const char *name)
|
||||
return pInfo;
|
||||
}
|
||||
|
||||
ConCmdList::iterator ConCmdManager::FindInList(const char *cmd)
|
||||
{
|
||||
List<ConCmdInfo *>::iterator iter = m_CmdList.begin();
|
||||
|
||||
while (iter != m_CmdList.end())
|
||||
{
|
||||
if (strcasecmp((*iter)->pCmd->GetName(), cmd) == 0)
|
||||
break;
|
||||
iter++;
|
||||
}
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
ResultType ConCmdManager::DispatchClientCommand(int client, const char *cmd, int args, ResultType type)
|
||||
{
|
||||
ConCmdInfo *pInfo;
|
||||
ConCmdInfo *pInfo = FindInTrie(cmd);
|
||||
|
||||
if ((pInfo = FindInTrie(cmd)) == NULL)
|
||||
if (pInfo == NULL)
|
||||
{
|
||||
ConCmdList::iterator item = FindInList(cmd);
|
||||
if (item == m_CmdList.end())
|
||||
return type;
|
||||
pInfo = *item;
|
||||
return type;
|
||||
}
|
||||
|
||||
cell_t result = type;
|
||||
for (CmdHookList::iterator iter = pInfo->hooks.begin(); iter != pInfo->hooks.end(); iter++)
|
||||
for (auto iter = pInfo->hooks.begin(); iter != pInfo->hooks.end(); iter++)
|
||||
{
|
||||
CmdHook *hook = *iter;
|
||||
|
||||
if (hook->type == CmdHook::Server || !hook->pf->IsRunnable())
|
||||
continue;
|
||||
|
||||
if (hook->admin && !CheckAccess(client, cmd, hook->admin))
|
||||
if (hook->admin && !CheckAccess(client, cmd, hook->admin.get()))
|
||||
{
|
||||
if (result < Pl_Handled)
|
||||
result = Pl_Handled;
|
||||
@@ -225,17 +214,7 @@ bool ConCmdManager::InternalDispatch(int client, const ICommandArgs *args)
|
||||
ConCmdInfo *pInfo = FindInTrie(cmd);
|
||||
if (pInfo == NULL)
|
||||
{
|
||||
/* Unfortunately, we now have to do a slow lookup because Valve made client commands
|
||||
* case-insensitive. We can't even use our sortedness.
|
||||
*/
|
||||
if (client == 0 && !engine->IsDedicatedServer())
|
||||
return false;
|
||||
|
||||
ConCmdList::iterator item = FindInList(cmd);
|
||||
if (item == m_CmdList.end())
|
||||
return false;
|
||||
|
||||
pInfo = *item;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* This is a hack to prevent say triggers from firing on messages that were
|
||||
@@ -256,7 +235,7 @@ bool ConCmdManager::InternalDispatch(int client, const ICommandArgs *args)
|
||||
: client;
|
||||
int dedicatedClient = engine->IsDedicatedServer() ? 0 : g_Players.ListenClient();
|
||||
|
||||
for (CmdHookList::iterator iter = pInfo->hooks.begin(); iter != pInfo->hooks.end(); iter++)
|
||||
for (auto iter = pInfo->hooks.begin(); iter != pInfo->hooks.end(); iter++)
|
||||
{
|
||||
CmdHook *hook = *iter;
|
||||
|
||||
@@ -271,7 +250,7 @@ bool ConCmdManager::InternalDispatch(int client, const ICommandArgs *args)
|
||||
} else {
|
||||
// Check admin rights if needed. realClient isn't needed since we
|
||||
// should bypass admin checks if client == 0 anyway.
|
||||
if (client && hook->admin && !CheckAccess(client, cmd, hook->admin))
|
||||
if (client && hook->admin && !CheckAccess(client, cmd, hook->admin.get()))
|
||||
{
|
||||
if (result < Pl_Handled)
|
||||
result = Pl_Handled;
|
||||
@@ -317,7 +296,7 @@ bool ConCmdManager::CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmi
|
||||
char buffer[128];
|
||||
if (!logicore.CoreTranslate(buffer, sizeof(buffer), "%T", 2, NULL, "No Access", &client))
|
||||
{
|
||||
ke::SafeSprintf(buffer, sizeof(buffer), "You do not have access to this command");
|
||||
ke::SafeStrcpy(buffer, sizeof(buffer), "You do not have access to this command");
|
||||
}
|
||||
|
||||
unsigned int replyto = g_ChatTriggers.GetReplyTo();
|
||||
@@ -342,9 +321,10 @@ bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
|
||||
const char *group,
|
||||
int adminflags,
|
||||
const char *description,
|
||||
int flags)
|
||||
int flags,
|
||||
IPlugin *pPlugin)
|
||||
{
|
||||
ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags);
|
||||
ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags, pPlugin);
|
||||
|
||||
if (!pInfo)
|
||||
return false;
|
||||
@@ -358,8 +338,8 @@ bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
|
||||
}
|
||||
RefPtr<CommandGroup> cmdgroup = i->value;
|
||||
|
||||
CmdHook *pHook = new CmdHook(CmdHook::Client, pInfo, pFunction, description);
|
||||
pHook->admin = new AdminCmdInfo(cmdgroup, adminflags);
|
||||
CmdHook *pHook = new CmdHook(CmdHook::Client, pInfo, pFunction, description, pPlugin);
|
||||
pHook->admin = std::make_unique<AdminCmdInfo>(cmdgroup, adminflags);
|
||||
|
||||
/* First get the command group override, if any */
|
||||
bool override = adminsys->GetCommandOverride(group,
|
||||
@@ -379,7 +359,7 @@ bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
|
||||
pHook->admin->eflags = pHook->admin->flags;
|
||||
pInfo->eflags = pHook->admin->eflags;
|
||||
|
||||
cmdgroup->hooks.append(pHook);
|
||||
cmdgroup->hooks.push_back(pHook);
|
||||
pInfo->hooks.append(pHook);
|
||||
RegisterInPlugin(pHook);
|
||||
return true;
|
||||
@@ -388,15 +368,16 @@ bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
|
||||
bool ConCmdManager::AddServerCommand(IPluginFunction *pFunction,
|
||||
const char *name,
|
||||
const char *description,
|
||||
int flags)
|
||||
int flags,
|
||||
IPlugin *pPlugin)
|
||||
|
||||
{
|
||||
ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags);
|
||||
ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags, pPlugin);
|
||||
|
||||
if (!pInfo)
|
||||
return false;
|
||||
|
||||
CmdHook *pHook = new CmdHook(CmdHook::Server, pInfo, pFunction, description);
|
||||
CmdHook *pHook = new CmdHook(CmdHook::Server, pInfo, pFunction, description, pPlugin);
|
||||
|
||||
pInfo->hooks.append(pHook);
|
||||
RegisterInPlugin(pHook);
|
||||
@@ -417,24 +398,24 @@ void RegisterInPlugin(CmdHook *hook)
|
||||
const char *orig = hook->info->pCmd->GetName();
|
||||
|
||||
/* Insert this into the help list, SORTED alphabetically. */
|
||||
PluginHookList::iterator iter = pList->begin();
|
||||
auto iter = pList->begin();
|
||||
while (iter != pList->end())
|
||||
{
|
||||
const char *cmd = (*iter)->info->pCmd->GetName();
|
||||
if (strcmp(orig, cmd) < 0)
|
||||
{
|
||||
pList->insertBefore(iter, hook);
|
||||
pList->emplace(iter, hook);
|
||||
return;
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
|
||||
pList->append(hook);
|
||||
pList->emplace_back(hook);
|
||||
}
|
||||
|
||||
void ConCmdManager::AddToCmdList(ConCmdInfo *info)
|
||||
{
|
||||
List<ConCmdInfo *>::iterator iter = m_CmdList.begin();
|
||||
auto iter = m_CmdList.begin();
|
||||
ConCmdInfo *pInfo;
|
||||
bool inserted = false;
|
||||
const char *orig = NULL;
|
||||
@@ -470,7 +451,7 @@ void ConCmdManager::UpdateAdminCmdFlags(const char *cmd, OverrideType type, Flag
|
||||
if (!m_Cmds.retrieve(cmd, &pInfo))
|
||||
return;
|
||||
|
||||
for (CmdHookList::iterator iter = pInfo->hooks.begin(); iter != pInfo->hooks.end(); iter++)
|
||||
for (auto iter = pInfo->hooks.begin(); iter != pInfo->hooks.end(); iter++)
|
||||
{
|
||||
if (!iter->admin)
|
||||
continue;
|
||||
@@ -490,10 +471,10 @@ void ConCmdManager::UpdateAdminCmdFlags(const char *cmd, OverrideType type, Flag
|
||||
|
||||
RefPtr<CommandGroup> group(r->value);
|
||||
|
||||
for (PluginHookList::iterator iter = group->hooks.begin(); iter != group->hooks.end(); iter++)
|
||||
for (auto iter = group->hooks.begin(); iter != group->hooks.end(); iter++)
|
||||
{
|
||||
CmdHook *hook = *iter;
|
||||
if (remove)
|
||||
if (!remove)
|
||||
hook->admin->eflags = bits;
|
||||
else
|
||||
hook->admin->eflags = hook->admin->flags;
|
||||
@@ -555,15 +536,11 @@ bool ConCmdManager::LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags)
|
||||
return true;
|
||||
}
|
||||
|
||||
ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *description, int flags)
|
||||
ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *description, int flags, IPlugin *pPlugin)
|
||||
{
|
||||
ConCmdInfo *pInfo;
|
||||
if (!m_Cmds.retrieve(name, &pInfo))
|
||||
{
|
||||
ConCmdList::iterator item = FindInList(name);
|
||||
if (item != m_CmdList.end())
|
||||
return *item;
|
||||
|
||||
pInfo = new ConCmdInfo();
|
||||
/* Find the commandopan */
|
||||
ConCommand *pCmd = FindCommand(name);
|
||||
@@ -580,6 +557,7 @@ ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *descri
|
||||
char *new_name = sm_strdup(name);
|
||||
char *new_help = sm_strdup(description);
|
||||
pCmd = new ConCommand(new_name, CommandCallback, new_help, flags);
|
||||
pInfo->pPlugin = pPlugin;
|
||||
pInfo->sourceMod = true;
|
||||
}
|
||||
else
|
||||
@@ -635,7 +613,7 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
|
||||
const char *help;
|
||||
UTIL_ConsolePrint("[SM] Listing commands for: %s", plname);
|
||||
UTIL_ConsolePrint(" %-17.16s %-8.7s %s", "[Name]", "[Type]", "[Help]");
|
||||
for (PluginHookList::iterator iter = pList->begin(); iter != pList->end(); iter++)
|
||||
for (auto iter = pList->begin(); iter != pList->end(); iter++)
|
||||
{
|
||||
CmdHook *hook = *iter;
|
||||
if (hook->type == CmdHook::Server)
|
||||
@@ -645,7 +623,7 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
|
||||
|
||||
name = hook->info->pCmd->GetName();
|
||||
if (hook->helptext.length())
|
||||
help = hook->helptext.chars();
|
||||
help = hook->helptext.c_str();
|
||||
else
|
||||
help = hook->info->pCmd->GetHelpText();
|
||||
UTIL_ConsolePrint(" %-17.16s %-12.11s %s", name, type, help);
|
||||
|
||||
+47
-25
@@ -32,29 +32,31 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
|
||||
#define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#include <am-inlinelist.h>
|
||||
#include <am-refcounting.h>
|
||||
#include <am-utility.h>
|
||||
#include <sm_hashmap.h>
|
||||
|
||||
#include "sm_globals.h"
|
||||
#include "sourcemm_api.h"
|
||||
#include <IForwardSys.h>
|
||||
#include <sh_list.h>
|
||||
#include <sh_string.h>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <IRootConsoleMenu.h>
|
||||
#include <IAdminSystem.h>
|
||||
#include "concmd_cleaner.h"
|
||||
#include "GameHooks.h"
|
||||
#include <sm_stringhashmap.h>
|
||||
#include <am-utility.h>
|
||||
#include <am-inlinelist.h>
|
||||
#include <am-linkedlist.h>
|
||||
#include <am-refcounting.h>
|
||||
|
||||
using namespace SourceHook;
|
||||
#include <sm_namehashset.h>
|
||||
|
||||
struct CmdHook;
|
||||
struct ConCmdInfo;
|
||||
|
||||
struct CommandGroup : public ke::Refcounted<CommandGroup>
|
||||
{
|
||||
ke::LinkedList<CmdHook *> hooks;
|
||||
std::list<CmdHook *> hooks;
|
||||
};
|
||||
|
||||
struct AdminCmdInfo
|
||||
@@ -77,10 +79,11 @@ struct CmdHook : public ke::InlineListNode<CmdHook>
|
||||
Client
|
||||
};
|
||||
|
||||
CmdHook(Type type, ConCmdInfo *cmd, IPluginFunction *fun, const char *description)
|
||||
CmdHook(Type type, ConCmdInfo *cmd, IPluginFunction *fun, const char *description, IPlugin *plugin)
|
||||
: type(type),
|
||||
info(cmd),
|
||||
pf(fun),
|
||||
plugin(plugin),
|
||||
helptext(description)
|
||||
{
|
||||
}
|
||||
@@ -88,8 +91,9 @@ struct CmdHook : public ke::InlineListNode<CmdHook>
|
||||
Type type;
|
||||
ConCmdInfo *info;
|
||||
IPluginFunction *pf; /* function hook */
|
||||
ke::AString helptext; /* help text */
|
||||
ke::AutoPtr<AdminCmdInfo> admin; /* admin requirements, if any */
|
||||
IPlugin *plugin; /* owning plugin */
|
||||
std::string helptext; /* help text */
|
||||
std::unique_ptr<AdminCmdInfo> admin; /* admin requirements, if any */
|
||||
};
|
||||
|
||||
typedef ke::InlineList<CmdHook> CmdHookList;
|
||||
@@ -98,18 +102,40 @@ struct ConCmdInfo
|
||||
{
|
||||
ConCmdInfo()
|
||||
{
|
||||
pPlugin = nullptr;
|
||||
sourceMod = false;
|
||||
pCmd = NULL;
|
||||
pCmd = nullptr;
|
||||
eflags = 0;
|
||||
}
|
||||
|
||||
bool sourceMod; /**< Determines whether or not concmd was created by a SourceMod plugin */
|
||||
ConCommand *pCmd; /**< Pointer to the command itself */
|
||||
CmdHookList hooks; /**< Hook list */
|
||||
FlagBits eflags; /**< Effective admin flags */
|
||||
ke::RefPtr<CommandHook> sh_hook; /**< SourceHook hook, if any. */
|
||||
IPlugin *pPlugin; /**< Owning plugin handle. */
|
||||
|
||||
struct ConCmdPolicy
|
||||
{
|
||||
static inline bool matches(const char *name, ConCmdInfo *info)
|
||||
{
|
||||
const char *conCmdChars = info->pCmd->GetName();
|
||||
|
||||
std::string concmdName = ke::Lowercase(conCmdChars);
|
||||
std::string input = ke::Lowercase(name);
|
||||
|
||||
return concmdName == input;
|
||||
}
|
||||
|
||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
||||
{
|
||||
std::string lower = ke::Lowercase(key.c_str());
|
||||
return detail::CharsAndLength(lower.c_str()).hash();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
typedef List<ConCmdInfo *> ConCmdList;
|
||||
typedef std::list<ConCmdInfo *> ConCmdList;
|
||||
|
||||
class ConCmdManager :
|
||||
public SMGlobalClass,
|
||||
@@ -131,13 +157,14 @@ public: //IRootConsoleCommand
|
||||
public: //IConCommandTracker
|
||||
void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name) override;
|
||||
public:
|
||||
bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
|
||||
bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags, IPlugin *pPlugin);
|
||||
bool AddAdminCommand(IPluginFunction *pFunction,
|
||||
const char *name,
|
||||
const char *group,
|
||||
int adminflags,
|
||||
const char *description,
|
||||
int flags);
|
||||
int flags,
|
||||
IPlugin *pPlugin);
|
||||
ResultType DispatchClientCommand(int client, const char *cmd, int args, ResultType type);
|
||||
void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits, bool remove);
|
||||
bool LookForSourceModCommand(const char *cmd);
|
||||
@@ -145,25 +172,20 @@ public:
|
||||
private:
|
||||
bool InternalDispatch(int client, const ICommandArgs *args);
|
||||
ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
|
||||
ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags);
|
||||
ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags, IPlugin *pPlugin);
|
||||
void AddToCmdList(ConCmdInfo *info);
|
||||
void RemoveConCmd(ConCmdInfo *info, const char *cmd, bool untrack);
|
||||
bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin);
|
||||
|
||||
// Case insensitive
|
||||
ConCmdList::iterator FindInList(const char *name);
|
||||
|
||||
// Case sensitive
|
||||
ConCmdInfo *FindInTrie(const char *name);
|
||||
public:
|
||||
inline const List<ConCmdInfo *> & GetCommandList()
|
||||
inline const std::list<ConCmdInfo *> & GetCommandList()
|
||||
{
|
||||
return m_CmdList;
|
||||
}
|
||||
private:
|
||||
typedef StringHashMap<ke::RefPtr<CommandGroup> > GroupMap;
|
||||
|
||||
StringHashMap<ConCmdInfo *> m_Cmds; /* command lookup */
|
||||
NameHashSet<ConCmdInfo *, ConCmdInfo::ConCmdPolicy> m_Cmds; /* command lookup */
|
||||
GroupMap m_CmdGrps; /* command group map */
|
||||
ConCmdList m_CmdList; /* command list */
|
||||
};
|
||||
|
||||
+64
-23
@@ -30,7 +30,7 @@
|
||||
#include "ConVarManager.h"
|
||||
#include "HalfLife2.h"
|
||||
#include "sm_stringutil.h"
|
||||
#include <sh_vector.h>
|
||||
#include <vector>
|
||||
#include <sm_namehashset.h>
|
||||
#include "logic_bridge.h"
|
||||
#include "sourcemod.h"
|
||||
@@ -40,8 +40,12 @@
|
||||
ConVarManager g_ConVarManager;
|
||||
|
||||
const ParamType CONVARCHANGE_PARAMS[] = {Param_Cell, Param_String, Param_String};
|
||||
typedef List<const ConVar *> ConVarList;
|
||||
NameHashSet<ConVarInfo *> convar_cache;
|
||||
typedef std::list<const ConVar *> ConVarList;
|
||||
NameHashSet<ConVarInfo *, ConVarInfo::ConVarPolicy> convar_cache;
|
||||
|
||||
enum {
|
||||
eQueryCvarValueStatus_Cancelled = -1,
|
||||
};
|
||||
|
||||
class ConVarReentrancyGuard
|
||||
{
|
||||
@@ -110,7 +114,7 @@ void ConVarManager::OnSourceModAllInitialized()
|
||||
|
||||
void ConVarManager::OnSourceModShutdown()
|
||||
{
|
||||
List<ConVarInfo *>::iterator iter = m_ConVars.begin();
|
||||
auto iter = m_ConVars.begin();
|
||||
HandleSecurity sec(NULL, g_pCoreIdent);
|
||||
|
||||
/* Iterate list of ConVarInfo structures, remove every one of them */
|
||||
@@ -206,18 +210,27 @@ void ConVarManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *na
|
||||
void ConVarManager::OnPluginUnloaded(IPlugin *plugin)
|
||||
{
|
||||
ConVarList *pConVarList;
|
||||
List<ConVarQuery>::iterator iter;
|
||||
|
||||
/* If plugin has a convar list, free its memory */
|
||||
if (plugin->GetProperty("ConVarList", (void **)&pConVarList, true))
|
||||
{
|
||||
delete pConVarList;
|
||||
}
|
||||
|
||||
/* Clear any references to this plugin as the convar creator */
|
||||
for (auto iter = m_ConVars.begin(); iter != m_ConVars.end(); ++iter)
|
||||
{
|
||||
ConVarInfo *pInfo = (*iter);
|
||||
|
||||
if (pInfo->pPlugin == plugin)
|
||||
{
|
||||
pInfo->pPlugin = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
const IPluginRuntime * pRuntime = plugin->GetRuntime();
|
||||
|
||||
/* Remove convar queries for this plugin that haven't returned results yet */
|
||||
for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end();)
|
||||
for (auto iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end();)
|
||||
{
|
||||
ConVarQuery &query = (*iter);
|
||||
if (query.pCallback->GetParentRuntime() == pRuntime)
|
||||
@@ -233,11 +246,24 @@ void ConVarManager::OnPluginUnloaded(IPlugin *plugin)
|
||||
void ConVarManager::OnClientDisconnected(int client)
|
||||
{
|
||||
/* Remove convar queries for this client that haven't returned results yet */
|
||||
for (List<ConVarQuery>::iterator iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end();)
|
||||
for (auto iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end();)
|
||||
{
|
||||
ConVarQuery &query = (*iter);
|
||||
if (query.client == client)
|
||||
{
|
||||
IPluginFunction *pCallback = query.pCallback;
|
||||
if (pCallback)
|
||||
{
|
||||
cell_t ret;
|
||||
|
||||
pCallback->PushCell(query.cookie);
|
||||
pCallback->PushCell(client);
|
||||
pCallback->PushCell(eQueryCvarValueStatus_Cancelled);
|
||||
pCallback->PushString("");
|
||||
pCallback->PushString("");
|
||||
pCallback->PushCell(query.value);
|
||||
pCallback->Execute(&ret);
|
||||
}
|
||||
iter = m_ConVarQueries.erase(iter);
|
||||
continue;
|
||||
}
|
||||
@@ -285,7 +311,6 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
|
||||
const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : plugin->GetFilename();
|
||||
|
||||
ConVarList *pConVarList;
|
||||
ConVarList::iterator iter;
|
||||
|
||||
/* If no convar list... */
|
||||
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList))
|
||||
@@ -301,7 +326,7 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
|
||||
}
|
||||
|
||||
/* Iterate convar list and display/reset each one */
|
||||
for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++)
|
||||
for (auto iter = pConVarList->begin(); iter != pConVarList->end(); iter++)
|
||||
{
|
||||
/*const */ConVar *pConVar = const_cast<ConVar *>(*iter);
|
||||
if (!wantReset)
|
||||
@@ -330,6 +355,8 @@ Handle_t ConVarManager::CreateConVar(IPluginContext *pContext, const char *name,
|
||||
ConVarInfo *pInfo = NULL;
|
||||
Handle_t hndl = 0;
|
||||
|
||||
IPlugin *plugin = scripts->FindPluginByContext(pContext);
|
||||
|
||||
/* Find out if the convar exists already */
|
||||
pConVar = icvar->FindVar(name);
|
||||
|
||||
@@ -337,11 +364,16 @@ Handle_t ConVarManager::CreateConVar(IPluginContext *pContext, const char *name,
|
||||
if (pConVar)
|
||||
{
|
||||
/* Add convar to plugin's list */
|
||||
AddConVarToPluginList(pContext, pConVar);
|
||||
AddConVarToPluginList(plugin, pConVar);
|
||||
|
||||
/* First find out if we already have a handle to it */
|
||||
if (convar_cache_lookup(name, &pInfo))
|
||||
{
|
||||
/* If the convar doesn't have an owning plugin, but SM created it, adopt it */
|
||||
if (pInfo->sourceMod && pInfo->pPlugin == nullptr) {
|
||||
pInfo->pPlugin = plugin;
|
||||
}
|
||||
|
||||
return pInfo->handle;
|
||||
}
|
||||
else
|
||||
@@ -382,6 +414,7 @@ Handle_t ConVarManager::CreateConVar(IPluginContext *pContext, const char *name,
|
||||
pInfo->handle = hndl;
|
||||
pInfo->sourceMod = true;
|
||||
pInfo->pChangeForward = NULL;
|
||||
pInfo->pPlugin = plugin;
|
||||
|
||||
/* Create a handle from the new convar */
|
||||
hndl = handlesys->CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL);
|
||||
@@ -398,7 +431,7 @@ Handle_t ConVarManager::CreateConVar(IPluginContext *pContext, const char *name,
|
||||
pInfo->pVar = pConVar;
|
||||
|
||||
/* Add convar to plugin's list */
|
||||
AddConVarToPluginList(pContext, pConVar);
|
||||
AddConVarToPluginList(plugin, pConVar);
|
||||
|
||||
/* Insert struct into caches */
|
||||
m_ConVars.push_back(pInfo);
|
||||
@@ -552,29 +585,26 @@ QueryCvarCookie_t ConVarManager::QueryClientConVar(edict_t *pPlayer, const char
|
||||
return cookie;
|
||||
}
|
||||
|
||||
void ConVarManager::AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar)
|
||||
void ConVarManager::AddConVarToPluginList(IPlugin *plugin, const ConVar *pConVar)
|
||||
{
|
||||
ConVarList *pConVarList;
|
||||
ConVarList::iterator iter;
|
||||
bool inserted = false;
|
||||
const char *orig = pConVar->GetName();
|
||||
|
||||
IPlugin *plugin = scripts->FindPluginByContext(pContext->GetContext());
|
||||
|
||||
/* Check plugin for an existing convar list */
|
||||
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList))
|
||||
{
|
||||
pConVarList = new ConVarList();
|
||||
plugin->SetProperty("ConVarList", pConVarList);
|
||||
}
|
||||
else if (pConVarList->find(pConVar) != pConVarList->end())
|
||||
else if (std::find(pConVarList->begin(), pConVarList->end(), pConVar) != pConVarList->end())
|
||||
{
|
||||
/* If convar is already in list, then don't add it */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Insert convar into list which is sorted alphabetically */
|
||||
for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++)
|
||||
for (auto iter = pConVarList->begin(); iter != pConVarList->end(); iter++)
|
||||
{
|
||||
if (strcmp(orig, (*iter)->GetName()) < 0)
|
||||
{
|
||||
@@ -618,10 +648,16 @@ void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue, float
|
||||
{
|
||||
ConVarReentrancyGuard guard(pConVar);
|
||||
|
||||
/* Copy the new value to a local buffer so it survives reentrant
|
||||
* ChangeStringValue calls that may delete[] + reallocate m_pszString
|
||||
* while the forward is still iterating plugin callbacks. */
|
||||
char newValue[512];
|
||||
ke::SafeStrcpy(newValue, sizeof(newValue), pConVar->GetString());
|
||||
|
||||
/* Now call forwards in plugins that have hooked this */
|
||||
pForward->PushCell(pInfo->handle);
|
||||
pForward->PushString(oldValue);
|
||||
pForward->PushString(pConVar->GetString());
|
||||
pForward->PushString(newValue);
|
||||
pForward->Execute(NULL);
|
||||
}
|
||||
}
|
||||
@@ -640,9 +676,9 @@ void ConVarManager::OnClientQueryFinished(QueryCvarCookie_t cookie,
|
||||
{
|
||||
IPluginFunction *pCallback = NULL;
|
||||
cell_t value = 0;
|
||||
List<ConVarQuery>::iterator iter;
|
||||
|
||||
for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end(); iter++)
|
||||
auto iter = m_ConVarQueries.begin();
|
||||
for (; iter != m_ConVarQueries.end(); iter++)
|
||||
{
|
||||
ConVarQuery &query = (*iter);
|
||||
if (query.cookie == cookie)
|
||||
@@ -653,7 +689,7 @@ void ConVarManager::OnClientQueryFinished(QueryCvarCookie_t cookie,
|
||||
}
|
||||
}
|
||||
|
||||
if (pCallback)
|
||||
if (pCallback && iter != m_ConVarQueries.end())
|
||||
{
|
||||
cell_t ret;
|
||||
|
||||
@@ -679,7 +715,7 @@ void ConVarManager::OnClientQueryFinished(QueryCvarCookie_t cookie,
|
||||
}
|
||||
#endif
|
||||
|
||||
HandleError ConVarManager::ReadConVarHandle(Handle_t hndl, ConVar **pVar)
|
||||
HandleError ConVarManager::ReadConVarHandle(Handle_t hndl, ConVar **pVar, IPlugin **ppPlugin)
|
||||
{
|
||||
ConVarInfo *pInfo;
|
||||
HandleError error;
|
||||
@@ -694,5 +730,10 @@ HandleError ConVarManager::ReadConVarHandle(Handle_t hndl, ConVar **pVar)
|
||||
*pVar = pInfo->pVar;
|
||||
}
|
||||
|
||||
if (ppPlugin)
|
||||
{
|
||||
*ppPlugin = pInfo->pPlugin;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
+25
-11
@@ -34,7 +34,7 @@
|
||||
|
||||
#include "sm_globals.h"
|
||||
#include "sourcemm_api.h"
|
||||
#include <sh_list.h>
|
||||
#include <list>
|
||||
#include <IPluginSys.h>
|
||||
#include <IForwardSys.h>
|
||||
#include <IHandleSys.h>
|
||||
@@ -43,8 +43,7 @@
|
||||
#include <compat_wrappers.h>
|
||||
#include "concmd_cleaner.h"
|
||||
#include "PlayerManager.h"
|
||||
|
||||
using namespace SourceHook;
|
||||
#include <sm_hashmap.h>
|
||||
|
||||
class IConVarChangeListener
|
||||
{
|
||||
@@ -61,12 +60,27 @@ struct ConVarInfo
|
||||
bool sourceMod; /**< Determines whether or not convar was created by a SourceMod plugin */
|
||||
IChangeableForward *pChangeForward; /**< Forward associated with convar */
|
||||
ConVar *pVar; /**< The actual convar */
|
||||
List<IConVarChangeListener *> changeListeners;
|
||||
IPlugin *pPlugin; /**< Originally owning plugin */
|
||||
std::list<IConVarChangeListener *> changeListeners;
|
||||
|
||||
static inline bool matches(const char *name, const ConVarInfo *info)
|
||||
struct ConVarPolicy
|
||||
{
|
||||
return strcmp(name, info->pVar->GetName()) == 0;
|
||||
}
|
||||
static inline bool matches(const char *name, ConVarInfo *info)
|
||||
{
|
||||
const char *conVarChars = info->pVar->GetName();
|
||||
|
||||
std::string convarName = ke::Lowercase(conVarChars);
|
||||
std::string input = ke::Lowercase(name);
|
||||
|
||||
return convarName == input;
|
||||
}
|
||||
|
||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
||||
{
|
||||
std::string lower = ke::Lowercase(key.c_str());
|
||||
return detail::CharsAndLength(lower.c_str()).hash();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -139,7 +153,7 @@ public:
|
||||
|
||||
bool IsQueryingSupported();
|
||||
|
||||
HandleError ReadConVarHandle(Handle_t hndl, ConVar **pVar);
|
||||
HandleError ReadConVarHandle(Handle_t hndl, ConVar **pVar, IPlugin **ppPlugin = nullptr);
|
||||
|
||||
// Called via game hooks.
|
||||
void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue);
|
||||
@@ -156,11 +170,11 @@ private:
|
||||
/**
|
||||
* Adds a convar to a plugin's list.
|
||||
*/
|
||||
static void AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar);
|
||||
static void AddConVarToPluginList(IPlugin *plugin, const ConVar *pConVar);
|
||||
private:
|
||||
HandleType_t m_ConVarType;
|
||||
List<ConVarInfo *> m_ConVars;
|
||||
List<ConVarQuery> m_ConVarQueries;
|
||||
std::list<ConVarInfo *> m_ConVars;
|
||||
std::list<ConVarQuery> m_ConVarQueries;
|
||||
};
|
||||
|
||||
extern ConVarManager g_ConVarManager;
|
||||
|
||||
@@ -76,7 +76,7 @@ class GenericCommandHooker : public IConCommandLinkListener
|
||||
int hook;
|
||||
unsigned int refcount;
|
||||
};
|
||||
CVector<HackInfo> vtables;
|
||||
std::vector<HackInfo> vtables;
|
||||
bool enabled;
|
||||
SourceHook::MemFuncInfo dispatch;
|
||||
|
||||
@@ -144,7 +144,7 @@ class GenericCommandHooker : public IConCommandLinkListener
|
||||
vtables[i].refcount = 0;
|
||||
for (ConCommandBaseIterator iter; iter.IsValid(); iter.Next())
|
||||
MakeHookable(iter.Get());
|
||||
CVector<HackInfo>::iterator iter = vtables.begin();
|
||||
auto iter = vtables.begin();
|
||||
while (iter != vtables.end())
|
||||
{
|
||||
if ((*iter).refcount)
|
||||
@@ -191,7 +191,7 @@ class GenericCommandHooker : public IConCommandLinkListener
|
||||
if (vtables[index].refcount == 0)
|
||||
{
|
||||
SH_REMOVE_HOOK_ID(vtables[index].hook);
|
||||
vtables.erase(vtables.iterAt(index));
|
||||
vtables.erase(vtables.begin() + index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ bool ConsoleDetours::AddListener(IPluginFunction *fun, const char *command)
|
||||
}
|
||||
else
|
||||
{
|
||||
ke::AutoPtr<char[]> str(UTIL_ToLowerCase(command));
|
||||
std::unique_ptr<char[]> str(UTIL_ToLowerCase(command));
|
||||
IChangeableForward *forward;
|
||||
if (!m_Listeners.retrieve(str.get(), &forward))
|
||||
{
|
||||
@@ -329,7 +329,7 @@ bool ConsoleDetours::RemoveListener(IPluginFunction *fun, const char *command)
|
||||
}
|
||||
else
|
||||
{
|
||||
ke::AutoPtr<char[]> str(UTIL_ToLowerCase(command));
|
||||
std::unique_ptr<char[]> str(UTIL_ToLowerCase(command));
|
||||
IChangeableForward *forward;
|
||||
if (!m_Listeners.retrieve(str.get(), &forward))
|
||||
return false;
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "sm_globals.h"
|
||||
#include "sourcemm_api.h"
|
||||
#include <IForwardSys.h>
|
||||
#include <sm_stringhashmap.h>
|
||||
#include <sm_hashmap.h>
|
||||
|
||||
namespace SourceMod {
|
||||
class ICommandArgs;
|
||||
|
||||
+332
-81
@@ -41,13 +41,11 @@
|
||||
#include <sourcemod_version.h>
|
||||
#include <amtl/os/am-path.h>
|
||||
#include <amtl/os/am-fsutil.h>
|
||||
#include <sh_list.h>
|
||||
#include <list>
|
||||
#include <IForwardSys.h>
|
||||
#include <bridge/include/IScriptManager.h>
|
||||
#include <bridge/include/ILogger.h>
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file");
|
||||
#elif defined PLATFORM_LINUX || defined PLATFORM_APPLE
|
||||
@@ -290,18 +288,18 @@ ConfigResult CoreConfig::SetConfigOption(const char *option, const char *value,
|
||||
pBase = pBase->m_pGlobalClassNext;
|
||||
}
|
||||
|
||||
ke::AString vstr(value);
|
||||
m_KeyValues.replace(option, ke::Move(vstr));
|
||||
std::string vstr(value);
|
||||
m_KeyValues.replace(option, std::move(vstr));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const char *CoreConfig::GetCoreConfigValue(const char *key)
|
||||
{
|
||||
StringHashMap<ke::AString>::Result r = m_KeyValues.find(key);
|
||||
StringHashMap<std::string>::Result r = m_KeyValues.find(key);
|
||||
if (!r.found())
|
||||
return NULL;
|
||||
return r->value.chars();
|
||||
return r->value.c_str();
|
||||
}
|
||||
|
||||
bool SM_AreConfigsExecuted()
|
||||
@@ -318,6 +316,284 @@ inline bool IsPathSepChar(char c)
|
||||
#endif
|
||||
}
|
||||
|
||||
void SM_ParseConfig(FILE *fp, ke::HashMap<std::string, std::string, StringPolicy> &cvars_list)
|
||||
{
|
||||
char line[4096];
|
||||
char cvar_name[256];
|
||||
|
||||
while (fgets(line, sizeof(line), fp))
|
||||
{
|
||||
char *ptr = line;
|
||||
|
||||
// Ignore whitespaces and tabs
|
||||
while (*ptr == ' ' || *ptr == '\t')
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
|
||||
// Ignore empty lines if found
|
||||
if (*ptr == '\0' || *ptr == '\n' || *ptr == '\r')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore comments
|
||||
if (*ptr == '/' && *(ptr + 1) == '/')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t i = 0;
|
||||
while (*ptr != '\0' && *ptr != '\n' && *ptr != '\r' && *ptr != ' ' && *ptr != '\t' && i < (sizeof(cvar_name) - 1))
|
||||
{
|
||||
cvar_name[i++] = *ptr++;
|
||||
}
|
||||
|
||||
cvar_name[i] = '\0';
|
||||
|
||||
if (!i)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto p = cvars_list.findForAdd(cvar_name);
|
||||
if (p.found())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove spaces and tabs before the value
|
||||
while (*ptr == ' ' || *ptr == '\t')
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
|
||||
char *value_start = ptr;
|
||||
char *value_end = value_start + strlen(value_start);
|
||||
|
||||
while (value_end > value_start &&
|
||||
(*(value_end - 1) == '\n' ||
|
||||
*(value_end - 1) == '\r' ||
|
||||
*(value_end - 1) == ' ' ||
|
||||
*(value_end - 1) == '\t' ||
|
||||
*(value_end - 1) == '"'))
|
||||
{
|
||||
value_end--;
|
||||
}
|
||||
|
||||
*value_end = '\0';
|
||||
|
||||
if (*value_start == '"')
|
||||
{
|
||||
value_start++;
|
||||
}
|
||||
|
||||
cvars_list.add(p, cvar_name, value_start);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool SM_CvarExistsInConfig(ke::HashMap<std::string, std::string, StringPolicy> &cvars, const char *cvar_name)
|
||||
{
|
||||
return cvars.find(cvar_name).found();
|
||||
}
|
||||
|
||||
bool SM_CvarExistsInPlugin(std::list<const ConVar *> &convars, const char *cvar_name)
|
||||
{
|
||||
for (auto iter = convars.begin(); iter != convars.end(); iter++)
|
||||
{
|
||||
const ConVar *cvar = (*iter);
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
if (cvar->IsFlagSet(FCVAR_DONTRECORD))
|
||||
#else
|
||||
if (cvar->IsBitSet(FCVAR_DONTRECORD))
|
||||
#endif
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strcasecmp(cvar_name, cvar->GetName()) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SM_ConfigCheckRegeneration(
|
||||
const char *file,
|
||||
ke::HashMap<std::string, std::string, StringPolicy> &existing_cvars,
|
||||
std::list<const ConVar *> &convars)
|
||||
{
|
||||
FILE *fp = fopen(file, "rt");
|
||||
if (!fp)
|
||||
{
|
||||
logger->LogError("Failed to read config for checking regeneration, make sure the directory has read permission.");
|
||||
return true;
|
||||
}
|
||||
|
||||
SM_ParseConfig(fp, existing_cvars);
|
||||
fclose(fp);
|
||||
|
||||
/* #1. Check if the plugin's cvar list has a cvar that doesn't exist in the config file. */
|
||||
for (auto iter = convars.begin(); iter != convars.end(); iter++)
|
||||
{
|
||||
const ConVar *cvar = (*iter);
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
if (cvar->IsFlagSet(FCVAR_DONTRECORD))
|
||||
#else
|
||||
if (cvar->IsBitSet(FCVAR_DONTRECORD))
|
||||
#endif
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!SM_CvarExistsInConfig(existing_cvars, cvar->GetName()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* #2. Check if the config file has a cvar that doesn't exist in the plugin's cvar list. */
|
||||
for (auto it = existing_cvars.iter(); !it.empty(); it.next())
|
||||
{
|
||||
if (!SM_CvarExistsInPlugin(convars, it->key.c_str()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void SM_ExecuteConfigFile(const char *file)
|
||||
{
|
||||
char cmd[255];
|
||||
ke::SafeSprintf(cmd, sizeof(cmd), "exec %s\n", file);
|
||||
engine->ServerCommand(cmd);
|
||||
}
|
||||
|
||||
bool SM_GenerateConfigFile(
|
||||
IPlugin *pl,
|
||||
const char *file,
|
||||
std::list<const ConVar *> &convars,
|
||||
bool needs_regeneration = false,
|
||||
ke::HashMap<std::string, std::string, StringPolicy> *existing_cvars = NULL)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
char tmp_file[PLATFORM_MAX_PATH];
|
||||
if (!needs_regeneration)
|
||||
{
|
||||
fp = fopen(file, "wt");
|
||||
if (!fp)
|
||||
{
|
||||
logger->LogError("Failed to auto generate config for %s, make sure the directory has write permission.", pl->GetFilename());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Create a .tmp file with the new contents of the new config file and then override it to the existing file */
|
||||
ke::path::Format(tmp_file, sizeof(tmp_file), "%s.tmp", file);
|
||||
fp = fopen(tmp_file, "wt");
|
||||
if (!fp)
|
||||
{
|
||||
logger->LogError("Failed to create temp config file for %s, make sure the directory has write permission.", pl->GetFilename());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(fp, "// This file was auto-generated by SourceMod (v%s)\n", SOURCEMOD_VERSION);
|
||||
fprintf(fp, "// ConVars for plugin \"%s\"\n", pl->GetFilename());
|
||||
fprintf(fp, "\n\n");
|
||||
|
||||
float x;
|
||||
for (auto iter = convars.begin(); iter != convars.end(); iter++)
|
||||
{
|
||||
const ConVar *cvar = (*iter);
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
if (cvar->IsFlagSet(FCVAR_DONTRECORD))
|
||||
#else
|
||||
if (cvar->IsBitSet(FCVAR_DONTRECORD))
|
||||
#endif
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
char descr[255];
|
||||
char *dptr = descr;
|
||||
|
||||
/* Print comments until there is no more */
|
||||
ke::SafeStrcpy(descr, sizeof(descr), cvar->GetHelpText());
|
||||
while (*dptr != '\0')
|
||||
{
|
||||
/* Find the next line */
|
||||
char *next_ptr = dptr;
|
||||
while (*next_ptr != '\0')
|
||||
{
|
||||
if (*next_ptr == '\n')
|
||||
{
|
||||
*next_ptr = '\0';
|
||||
next_ptr++;
|
||||
break;
|
||||
}
|
||||
next_ptr++;
|
||||
}
|
||||
fprintf(fp, "// %s\n", dptr);
|
||||
dptr = next_ptr;
|
||||
}
|
||||
|
||||
fprintf(fp, "// -\n");
|
||||
fprintf(fp, "// Default: \"%s\"\n", cvar->GetDefault());
|
||||
if (cvar->GetMin(x))
|
||||
{
|
||||
fprintf(fp, "// Minimum: \"%02f\"\n", x);
|
||||
}
|
||||
if (cvar->GetMax(x))
|
||||
{
|
||||
fprintf(fp, "// Maximum: \"%02f\"\n", x);
|
||||
}
|
||||
|
||||
const char *value = cvar->GetDefault();
|
||||
|
||||
if (needs_regeneration && existing_cvars)
|
||||
{
|
||||
auto p = existing_cvars->find(cvar->GetName());
|
||||
if (p.found())
|
||||
{
|
||||
value = p->value.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(fp, "%s \"%s\"\n", cvar->GetName(), value);
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
fprintf(fp, "\n");
|
||||
|
||||
fclose(fp);
|
||||
|
||||
if (needs_regeneration)
|
||||
{
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
if (!MoveFileEx(tmp_file, file, MOVEFILE_REPLACE_EXISTING))
|
||||
#else
|
||||
if (rename(tmp_file, file) != 0)
|
||||
#endif
|
||||
{
|
||||
/* Replacing the temp config file with the existing one failed, remove it and notify the user about it */
|
||||
logger->LogError("Failed to replace temp config file for %s, make sure the directory has write permission.", pl->GetFilename());
|
||||
if (remove(tmp_file) != 0)
|
||||
{
|
||||
logger->LogError("Failed to remove temp config file for %s.", pl->GetFilename());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create)
|
||||
{
|
||||
bool will_create = false;
|
||||
@@ -394,87 +670,62 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create)
|
||||
g_SourceMod.BuildPath(Path_Game, file, sizeof(file), "cfg/%s", local);
|
||||
|
||||
bool file_exists = ke::file::IsFile(file);
|
||||
if (!file_exists && will_create)
|
||||
|
||||
if (!will_create)
|
||||
{
|
||||
List<const ConVar *> *convars = NULL;
|
||||
if (pl->GetProperty("ConVarList", (void **)&convars, false) && convars)
|
||||
if (file_exists)
|
||||
{
|
||||
/* Attempt to create it */
|
||||
FILE *fp = fopen(file, "wt");
|
||||
if (fp)
|
||||
{
|
||||
fprintf(fp, "// This file was auto-generated by SourceMod (v%s)\n", SOURCEMOD_VERSION);
|
||||
fprintf(fp, "// ConVars for plugin \"%s\"\n", pl->GetFilename());
|
||||
fprintf(fp, "\n\n");
|
||||
|
||||
List<const ConVar *>::iterator iter;
|
||||
float x;
|
||||
for (iter = convars->begin(); iter != convars->end(); iter++)
|
||||
{
|
||||
const ConVar *cvar = (*iter);
|
||||
|
||||
if ((cvar->GetFlags() & FCVAR_DONTRECORD) == FCVAR_DONTRECORD)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
char descr[255];
|
||||
char *dptr = descr;
|
||||
|
||||
/* Print comments until there is no more */
|
||||
ke::SafeStrcpy(descr, sizeof(descr), cvar->GetHelpText());
|
||||
while (*dptr != '\0')
|
||||
{
|
||||
/* Find the next line */
|
||||
char *next_ptr = dptr;
|
||||
while (*next_ptr != '\0')
|
||||
{
|
||||
if (*next_ptr == '\n')
|
||||
{
|
||||
*next_ptr = '\0';
|
||||
next_ptr++;
|
||||
break;
|
||||
}
|
||||
next_ptr++;
|
||||
}
|
||||
fprintf(fp, "// %s\n", dptr);
|
||||
dptr = next_ptr;
|
||||
}
|
||||
|
||||
fprintf(fp, "// -\n");
|
||||
fprintf(fp, "// Default: \"%s\"\n", cvar->GetDefault());
|
||||
if (cvar->GetMin(x))
|
||||
{
|
||||
fprintf(fp, "// Minimum: \"%02f\"\n", x);
|
||||
}
|
||||
if (cvar->GetMax(x))
|
||||
{
|
||||
fprintf(fp, "// Maximum: \"%02f\"\n", x);
|
||||
}
|
||||
fprintf(fp, "%s \"%s\"\n", cvar->GetName(), cvar->GetDefault());
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
fprintf(fp, "\n");
|
||||
|
||||
file_exists = true;
|
||||
can_create = false;
|
||||
fclose(fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger->LogError("Failed to auto generate config for %s, make sure the directory has write permission.", pl->GetFilename());
|
||||
return can_create;
|
||||
}
|
||||
SM_ExecuteConfigFile(local);
|
||||
}
|
||||
|
||||
return can_create;
|
||||
}
|
||||
|
||||
if (file_exists)
|
||||
std::list<const ConVar *> *convars = NULL;
|
||||
if (!pl->GetProperty("ConVarList", (void **)&convars, false) || !convars)
|
||||
{
|
||||
char cmd[255];
|
||||
ke::SafeSprintf(cmd, sizeof(cmd), "exec %s\n", local);
|
||||
engine->ServerCommand(cmd);
|
||||
if (file_exists)
|
||||
{
|
||||
SM_ExecuteConfigFile(local);
|
||||
}
|
||||
|
||||
return can_create;
|
||||
}
|
||||
|
||||
if (!file_exists)
|
||||
{
|
||||
/* If file doesn't exist, then automatically generate the config file and execute it. */
|
||||
/* If sourcemod somehow failed to generate the config file, then stop. */
|
||||
if (!SM_GenerateConfigFile(pl, file, *convars))
|
||||
{
|
||||
return can_create;
|
||||
}
|
||||
|
||||
SM_ExecuteConfigFile(local);
|
||||
can_create = false;
|
||||
return can_create;
|
||||
}
|
||||
|
||||
/* Now if the file exists, read the content of it to see if we need to regenerate it or not. */
|
||||
ke::HashMap<std::string, std::string, StringPolicy> existing_cvars;
|
||||
existing_cvars.init();
|
||||
if (!SM_ConfigCheckRegeneration(file, existing_cvars, *convars))
|
||||
{
|
||||
SM_ExecuteConfigFile(local);
|
||||
return can_create;
|
||||
}
|
||||
|
||||
/* File exists and misses cvars between the config file and the plugin's convars list
|
||||
* Create a temporary config file with the new contents and then override it to the existing file.
|
||||
* If sourcemod somehow failed to override the new contents to the existing config file, then execute the existing config file.
|
||||
*/
|
||||
can_create = false;
|
||||
if (!SM_GenerateConfigFile(pl, file, *convars, true, &existing_cvars))
|
||||
{
|
||||
logger->LogError("An error occurred while regenerating config file for %s, executing the existing file instead.", pl->GetFilename());
|
||||
}
|
||||
|
||||
SM_ExecuteConfigFile(local);
|
||||
return can_create;
|
||||
}
|
||||
|
||||
@@ -511,7 +762,7 @@ void SM_ConfigsExecuted_Plugin(unsigned int serial)
|
||||
|
||||
void SM_ExecuteForPlugin(IPluginContext *ctx)
|
||||
{
|
||||
SMPlugin *plugin = scripts->FindPluginByContext(ctx->GetContext());
|
||||
SMPlugin *plugin = scripts->FindPluginByContext(ctx);
|
||||
|
||||
unsigned int num = plugin->GetConfigCount();
|
||||
if (!num)
|
||||
|
||||
+15
-2
@@ -36,7 +36,7 @@
|
||||
#include <ITextParsers.h>
|
||||
#include <IRootConsoleMenu.h>
|
||||
#include <am-string.h>
|
||||
#include <sm_stringhashmap.h>
|
||||
#include <sm_hashmap.h>
|
||||
|
||||
using namespace SourceMod;
|
||||
|
||||
@@ -68,7 +68,20 @@ private:
|
||||
*/
|
||||
ConfigResult SetConfigOption(const char *option, const char *value, ConfigSource, char *Error, size_t maxlength);
|
||||
private:
|
||||
StringHashMap<ke::AString> m_KeyValues;
|
||||
StringHashMap<std::string> m_KeyValues;
|
||||
};
|
||||
|
||||
struct StringPolicy
|
||||
{
|
||||
static inline uint32_t hash(const std::string &key)
|
||||
{
|
||||
std::string lower = ke::Lowercase(key.c_str());
|
||||
return ke::FastHashCharSequence(lower.c_str(), lower.length());
|
||||
}
|
||||
static inline bool matches(const char *find, const std::string &key)
|
||||
{
|
||||
return strcasecmp(find, key.c_str()) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
extern bool SM_AreConfigsExecuted();
|
||||
|
||||
+14
-17
@@ -41,7 +41,7 @@ EventManager g_EventManager;
|
||||
SH_DECL_HOOK2(IGameEventManager2, FireEvent, SH_NOATTRIB, 0, bool, IGameEvent *, bool);
|
||||
|
||||
const ParamType GAMEEVENT_PARAMS[] = {Param_Cell, Param_String, Param_Cell};
|
||||
typedef List<EventHook *> EventHookList;
|
||||
typedef std::list<EventHook *> EventHookList;
|
||||
|
||||
class EventForwardFilter : public IForwardFilter
|
||||
{
|
||||
@@ -64,13 +64,10 @@ EventManager::EventManager() : m_EventType(0)
|
||||
EventManager::~EventManager()
|
||||
{
|
||||
/* Free memory used by EventInfo structs if any */
|
||||
CStack<EventInfo *>::iterator iter;
|
||||
for (iter = m_FreeEvents.begin(); iter != m_FreeEvents.end(); iter++)
|
||||
{
|
||||
delete (*iter);
|
||||
while (!m_FreeEvents.empty()) {
|
||||
delete m_FreeEvents.top();
|
||||
m_FreeEvents.pop();
|
||||
}
|
||||
|
||||
m_FreeEvents.popall();
|
||||
}
|
||||
|
||||
void EventManager::OnSourceModAllInitialized()
|
||||
@@ -184,7 +181,7 @@ EventHookError EventManager::HookEvent(const char *name, IPluginFunction *pFunct
|
||||
if (!m_EventHooks.retrieve(name, &pHook))
|
||||
{
|
||||
EventHookList *pHookList;
|
||||
IPlugin *plugin = scripts->FindPluginByContext(pFunction->GetParentContext()->GetContext());
|
||||
IPlugin *plugin = scripts->FindPluginByContext(pFunction->GetParentContext());
|
||||
|
||||
/* Check plugin for an existing EventHook list */
|
||||
if (!plugin->GetProperty("EventHooks", (void **)&pHookList))
|
||||
@@ -297,7 +294,7 @@ EventHookError EventManager::UnhookEvent(const char *name, IPluginFunction *pFun
|
||||
/* If reference count is now 0, free hook structure */
|
||||
|
||||
EventHookList *pHookList;
|
||||
IPlugin *plugin = scripts->FindPluginByContext(pFunction->GetParentContext()->GetContext());
|
||||
IPlugin *plugin = scripts->FindPluginByContext(pFunction->GetParentContext());
|
||||
|
||||
/* Get plugin's event hook list */
|
||||
if (!plugin->GetProperty("EventHooks", (void**)&pHookList))
|
||||
@@ -306,7 +303,7 @@ EventHookError EventManager::UnhookEvent(const char *name, IPluginFunction *pFun
|
||||
}
|
||||
|
||||
/* Make sure the event was actually being hooked */
|
||||
if (pHookList->find(pHook) == pHookList->end())
|
||||
if (std::find(pHookList->begin(), pHookList->end(), pHook) == pHookList->end())
|
||||
{
|
||||
return EventHookErr_NotActive;
|
||||
}
|
||||
@@ -335,7 +332,7 @@ EventInfo *EventManager::CreateEvent(IPluginContext *pContext, const char *name,
|
||||
{
|
||||
pInfo = new EventInfo();
|
||||
} else {
|
||||
pInfo = m_FreeEvents.front();
|
||||
pInfo = m_FreeEvents.top();
|
||||
m_FreeEvents.pop();
|
||||
}
|
||||
|
||||
@@ -364,8 +361,8 @@ void EventManager::FireEvent(EventInfo *pInfo, bool bDontBroadcast)
|
||||
|
||||
void EventManager::FireEventToClient(EventInfo *pInfo, IClient *pClient)
|
||||
{
|
||||
// The IClient vtable is +4 from the IGameEventListener2 (CBaseClient) vtable due to multiple inheritance.
|
||||
IGameEventListener2 *pGameClient = (IGameEventListener2 *)((intptr_t)pClient - 4);
|
||||
// The IClient vtable is +sizeof(void *) from the IGameEventListener2 (CBaseClient) vtable due to multiple inheritance.
|
||||
IGameEventListener2 *pGameClient = (IGameEventListener2 *)((intptr_t)pClient - sizeof(void *));
|
||||
pGameClient->FireGameEvent(pInfo->pEvent);
|
||||
}
|
||||
|
||||
@@ -464,7 +461,7 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast)
|
||||
RETURN_META_VALUE(MRES_IGNORED, false);
|
||||
}
|
||||
|
||||
pHook = m_EventStack.front();
|
||||
pHook = m_EventStack.top();
|
||||
|
||||
if (pHook != NULL)
|
||||
{
|
||||
@@ -475,7 +472,7 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast)
|
||||
if (pHook->postCopy)
|
||||
{
|
||||
info.bDontBroadcast = bDontBroadcast;
|
||||
info.pEvent = m_EventCopies.front();
|
||||
info.pEvent = m_EventCopies.top();
|
||||
info.pOwner = NULL;
|
||||
hndl = handlesys->CreateHandle(m_EventType, &info, NULL, g_pCoreIdent, NULL);
|
||||
|
||||
@@ -484,7 +481,7 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast)
|
||||
pForward->PushCell(BAD_HANDLE);
|
||||
}
|
||||
|
||||
pForward->PushString(pHook->name.chars());
|
||||
pForward->PushString(pHook->name.c_str());
|
||||
pForward->PushCell(bDontBroadcast);
|
||||
pForward->Execute(NULL);
|
||||
|
||||
@@ -505,7 +502,7 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast)
|
||||
{
|
||||
assert(pHook->pPostHook == NULL);
|
||||
assert(pHook->pPreHook == NULL);
|
||||
m_EventHooks.remove(pHook->name.chars());
|
||||
m_EventHooks.remove(pHook->name.c_str());
|
||||
delete pHook;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-9
@@ -35,16 +35,14 @@
|
||||
#include "sm_globals.h"
|
||||
#include "sourcemm_api.h"
|
||||
#include <sm_namehashset.h>
|
||||
#include <sh_list.h>
|
||||
#include <sh_stack.h>
|
||||
#include <list>
|
||||
#include <stack>
|
||||
#include <IHandleSys.h>
|
||||
#include <IForwardSys.h>
|
||||
#include <IPluginSys.h>
|
||||
|
||||
class IClient;
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
struct EventInfo
|
||||
{
|
||||
EventInfo()
|
||||
@@ -71,11 +69,15 @@ struct EventHook
|
||||
IChangeableForward *pPostHook;
|
||||
bool postCopy;
|
||||
unsigned int refCount;
|
||||
ke::AString name;
|
||||
std::string name;
|
||||
|
||||
static inline bool matches(const char *name, const EventHook *hook)
|
||||
{
|
||||
return strcmp(name, hook->name.chars()) == 0;
|
||||
return strcmp(name, hook->name.c_str()) == 0;
|
||||
}
|
||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
||||
{
|
||||
return key.hash();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -136,9 +138,9 @@ private: // IGameEventManager2 hooks
|
||||
private:
|
||||
HandleType_t m_EventType;
|
||||
NameHashSet<EventHook *> m_EventHooks;
|
||||
CStack<EventInfo *> m_FreeEvents;
|
||||
CStack<EventHook *> m_EventStack;
|
||||
CStack<IGameEvent *> m_EventCopies;
|
||||
std::stack<EventInfo *> m_FreeEvents;
|
||||
std::stack<EventHook *> m_EventStack;
|
||||
std::stack<IGameEvent *> m_EventCopies;
|
||||
};
|
||||
|
||||
extern EventManager g_EventManager;
|
||||
|
||||
+2
-2
@@ -91,7 +91,7 @@ void GameHooks::OnVSPReceived()
|
||||
|
||||
void GameHooks::Shutdown()
|
||||
{
|
||||
for (size_t i = 0; i < hooks_.length(); i++)
|
||||
for (size_t i = 0; i < hooks_.size(); i++)
|
||||
SH_REMOVE_HOOK_ID(hooks_[i]);
|
||||
hooks_.clear();
|
||||
|
||||
@@ -115,7 +115,7 @@ void GameHooks::OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPla
|
||||
const char *cvarName, const char *cvarValue){
|
||||
int client = IndexOfEdict(pPlayer);
|
||||
|
||||
# if SOURCE_ENGINE == SE_CSGO
|
||||
# if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
if (g_Players.HandleConVarQuery(cookie, client, result, cvarName, cvarValue))
|
||||
return;
|
||||
# endif
|
||||
|
||||
+4
-4
@@ -34,7 +34,7 @@
|
||||
#include <iserverplugin.h>
|
||||
#include <amtl/am-refcounting.h>
|
||||
#include <amtl/am-vector.h>
|
||||
#include <amtl/am-function.h>
|
||||
#include <functional>
|
||||
|
||||
class ConVar;
|
||||
class CCommand;
|
||||
@@ -63,7 +63,7 @@ class CommandHook : public ke::Refcounted<CommandHook>
|
||||
{
|
||||
public:
|
||||
// return false to RETURN_META(MRES_IGNORED), or true to SUPERCEDE.
|
||||
typedef ke::Lambda<bool(int, const ICommandArgs *)> Callback;
|
||||
typedef std::function<bool(int, const ICommandArgs *)> Callback;
|
||||
|
||||
public:
|
||||
CommandHook(ConCommand *cmd, const Callback &callback, bool post);
|
||||
@@ -114,11 +114,11 @@ private:
|
||||
void SetCommandClient(int client);
|
||||
|
||||
private:
|
||||
class HookList : public ke::Vector<int>
|
||||
class HookList : public std::vector<int>
|
||||
{
|
||||
public:
|
||||
HookList &operator += (int hook_id) {
|
||||
this->append(hook_id);
|
||||
this->push_back(hook_id);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
+410
-90
@@ -45,38 +45,29 @@
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#include <cstrike15_usermessages.pb.h>
|
||||
#elif SOURCE_ENGINE == SE_BLADE
|
||||
#include <berimbau_usermessages.pb.h>
|
||||
#elif SOURCE_ENGINE == SE_MCV
|
||||
#include <vietnam_usermessages.pb.h>
|
||||
#elif SOURCE_ENGINE == SE_OUTBREAK
|
||||
#include <terror_usermessages.pb.h>
|
||||
#endif
|
||||
|
||||
#if SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_CSS
|
||||
#define SE_SDK2013_2025
|
||||
#endif
|
||||
|
||||
typedef ICommandLine *(*FakeGetCommandLine)();
|
||||
|
||||
#if defined _WIN32
|
||||
#define TIER0_NAME "tier0.dll"
|
||||
#define VSTDLIB_NAME "vstdlib.dll"
|
||||
#elif defined __APPLE__
|
||||
#define TIER0_NAME "libtier0.dylib"
|
||||
#define VSTDLIB_NAME "libvstdlib.dylib"
|
||||
#elif defined __linux__
|
||||
#if SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_TF2 \
|
||||
|| SOURCE_ENGINE == SE_SDK2013 || SOURCE_ENGINE == SE_LEFT4DEAD2 || SOURCE_ENGINE == SE_NUCLEARDAWN \
|
||||
|| SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_INSURGENCY || SOURCE_ENGINE == SE_DOI
|
||||
#define TIER0_NAME "libtier0_srv.so"
|
||||
#define VSTDLIB_NAME "libvstdlib_srv.so"
|
||||
#elif SOURCE_ENGINE >= SE_LEFT4DEAD
|
||||
#define TIER0_NAME "libtier0.so"
|
||||
#define VSTDLIB_NAME "libvstdlib.so"
|
||||
#else
|
||||
#define TIER0_NAME "tier0_i486.so"
|
||||
#define VSTDLIB_NAME "vstdlib_i486.so"
|
||||
#endif
|
||||
#endif
|
||||
#define TIER0_NAME FORMAT_SOURCE_BIN_NAME("tier0")
|
||||
#define VSTDLIB_NAME FORMAT_SOURCE_BIN_NAME("vstdlib")
|
||||
|
||||
CHalfLife2 g_HL2;
|
||||
ConVar *sv_lan = NULL;
|
||||
|
||||
static void *g_EntList = NULL;
|
||||
static void **g_pEntInfoList = NULL;
|
||||
static int entInfoOffset = -1;
|
||||
static int utlVecOffsetOffset = -1;
|
||||
|
||||
static CEntInfo *EntInfoArray()
|
||||
{
|
||||
@@ -157,9 +148,11 @@ void CHalfLife2::OnSourceModAllInitialized_Post()
|
||||
m_CSGOBadList.add("m_flFallbackWear");
|
||||
m_CSGOBadList.add("m_nFallbackStatTrak");
|
||||
m_CSGOBadList.add("m_iCompetitiveRanking");
|
||||
m_CSGOBadList.add("m_iCompetitiveRankType");
|
||||
m_CSGOBadList.add("m_nActiveCoinRank");
|
||||
m_CSGOBadList.add("m_nMusicID");
|
||||
#endif
|
||||
g_pGameConf->GetOffset("CSendPropExtra_UtlVector::m_Offset", &utlVecOffsetOffset);
|
||||
}
|
||||
|
||||
ConfigResult CHalfLife2::OnSourceModConfigChanged(const char *key, const char *value,
|
||||
@@ -180,7 +173,7 @@ ConfigResult CHalfLife2::OnSourceModConfigChanged(const char *key, const char *v
|
||||
}
|
||||
else
|
||||
{
|
||||
ke::SafeSprintf(error, maxlength, "Invalid value: must be \"yes\" or \"no\"");
|
||||
ke::SafeStrcpy(error, maxlength, "Invalid value: must be \"yes\" or \"no\"");
|
||||
return ConfigResult_Reject;
|
||||
}
|
||||
#endif
|
||||
@@ -197,7 +190,10 @@ void CHalfLife2::InitLogicalEntData()
|
||||
|| SOURCE_ENGINE == SE_CSS \
|
||||
|| SOURCE_ENGINE == SE_SDK2013 \
|
||||
|| SOURCE_ENGINE == SE_BMS \
|
||||
|| SOURCE_ENGINE == SE_NUCLEARDAWN
|
||||
|| SOURCE_ENGINE == SE_BLADE \
|
||||
|| SOURCE_ENGINE == SE_NUCLEARDAWN \
|
||||
|| SOURCE_ENGINE == SE_PVKII \
|
||||
|| SOURCE_ENGINE == SE_OUTBREAK
|
||||
|
||||
if (g_SMAPI->GetServerFactory(false)("VSERVERTOOLS003", nullptr))
|
||||
{
|
||||
@@ -245,7 +241,12 @@ void CHalfLife2::InitLogicalEntData()
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef KE_ARCH_X86
|
||||
g_EntList = *reinterpret_cast<void **>(addr + offset);
|
||||
#elif defined KE_ARCH_X64
|
||||
int32_t varOffset = *reinterpret_cast<int32_t *>(addr + offset);
|
||||
g_EntList = reinterpret_cast<void *>(addr + offset + sizeof(int32_t) + varOffset);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
@@ -329,23 +330,41 @@ bool UTIL_FindInSendTable(SendTable *pTable,
|
||||
sm_sendprop_info_t *info,
|
||||
unsigned int offset)
|
||||
{
|
||||
const char *pname;
|
||||
int props = pTable->GetNumProps();
|
||||
SendProp *prop;
|
||||
|
||||
for (int i=0; i<props; i++)
|
||||
for (int i = 0; i < props; i++)
|
||||
{
|
||||
prop = pTable->GetProp(i);
|
||||
pname = prop->GetName();
|
||||
SendProp *prop = pTable->GetProp(i);
|
||||
|
||||
// Skip InsideArray props (SendPropArray / SendPropArray2),
|
||||
// we'll find them later by their containing array.
|
||||
if (prop->IsInsideArray()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const char *pname = prop->GetName();
|
||||
SendTable *pInnerTable = prop->GetDataTable();
|
||||
|
||||
if (pname && strcmp(name, pname) == 0)
|
||||
{
|
||||
// get true offset of CUtlVector
|
||||
if (utlVecOffsetOffset != -1 && prop->GetOffset() == 0 && pInnerTable && pInnerTable->GetNumProps())
|
||||
{
|
||||
SendProp *pLengthProxy = pInnerTable->GetProp(0);
|
||||
const char *ipname = pLengthProxy->GetName();
|
||||
if (ipname && strcmp(ipname, "lengthproxy") == 0 && pLengthProxy->GetExtraData())
|
||||
{
|
||||
info->prop = prop;
|
||||
info->actual_offset = offset + *reinterpret_cast<size_t *>(reinterpret_cast<intptr_t>(pLengthProxy->GetExtraData()) + utlVecOffsetOffset);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
info->prop = prop;
|
||||
info->actual_offset = offset + info->prop->GetOffset();
|
||||
return true;
|
||||
}
|
||||
if (prop->GetDataTable())
|
||||
if (pInnerTable)
|
||||
{
|
||||
if (UTIL_FindInSendTable(prop->GetDataTable(),
|
||||
if (UTIL_FindInSendTable(pInnerTable,
|
||||
name,
|
||||
info,
|
||||
offset + prop->GetOffset())
|
||||
@@ -387,7 +406,70 @@ bool UTIL_FindDataMapInfo(datamap_t *pMap, const char *name, sm_datatable_info_t
|
||||
pMap = pMap->baseMap;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Table, typename Info>
|
||||
static bool UTIL_FindInTablePath(Table *pTable, const char *name, Info *info,
|
||||
bool (*search)(Table *, const char *, Info *),
|
||||
Table *(*descend)(const Info &))
|
||||
{
|
||||
unsigned int baseOffset = 0;
|
||||
const char *component = name;
|
||||
|
||||
while (true)
|
||||
{
|
||||
const char *dot = strchr(component, '.');
|
||||
size_t len = dot ? (size_t)(dot - component) : strlen(component);
|
||||
|
||||
char buffer[256];
|
||||
if (len == 0 || len >= sizeof(buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(buffer, component, len);
|
||||
buffer[len] = '\0';
|
||||
|
||||
// Search the table for the prop
|
||||
Info local;
|
||||
if (!search(pTable, buffer, &local))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!dot)
|
||||
{
|
||||
info->prop = local.prop;
|
||||
info->actual_offset = baseOffset + local.actual_offset;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle nested properties
|
||||
Table *pNext = descend(local);
|
||||
if (!pNext)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
baseOffset += local.actual_offset;
|
||||
pTable = pNext;
|
||||
component = dot + 1;
|
||||
}
|
||||
}
|
||||
|
||||
static bool UTIL_FindInSendTablePath(SendTable *pTable, const char *name, sm_sendprop_info_t *info)
|
||||
{
|
||||
return UTIL_FindInTablePath<SendTable, sm_sendprop_info_t>(pTable, name, info,
|
||||
[](SendTable *t, const char *n, sm_sendprop_info_t *o) { return UTIL_FindInSendTable(t, n, o, 0); },
|
||||
[](const sm_sendprop_info_t &i) -> SendTable * { return i.prop->GetDataTable(); });
|
||||
}
|
||||
|
||||
static bool UTIL_FindDataMapInfoPath(datamap_t *pMap, const char *name, sm_datatable_info_t *info)
|
||||
{
|
||||
return UTIL_FindInTablePath<datamap_t, sm_datatable_info_t>(pMap, name, info,
|
||||
[](datamap_t *m, const char *n, sm_datatable_info_t *o) { return UTIL_FindDataMapInfo(m, n, o); },
|
||||
[](const sm_datatable_info_t &i) -> datamap_t * { return i.prop->td; });
|
||||
}
|
||||
|
||||
ServerClass *CHalfLife2::FindServerClass(const char *classname)
|
||||
@@ -400,6 +482,21 @@ ServerClass *CHalfLife2::FindServerClass(const char *classname)
|
||||
return pInfo->sc;
|
||||
}
|
||||
|
||||
ServerClass *CHalfLife2::FindEntityServerClass(CBaseEntity *pEntity)
|
||||
{
|
||||
IServerNetworkable* pNetwork = ((IServerUnknown *)pEntity)->GetNetworkable();
|
||||
if (pNetwork == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_OUTBREAK
|
||||
return pNetwork->GetServerClassForModify();
|
||||
#else
|
||||
return pNetwork->GetServerClass();
|
||||
#endif
|
||||
}
|
||||
|
||||
DataTableInfo *CHalfLife2::_FindServerClass(const char *classname)
|
||||
{
|
||||
DataTableInfo *pInfo = NULL;
|
||||
@@ -432,20 +529,29 @@ bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pInfo->lookup.retrieve(offset, info))
|
||||
{
|
||||
sm_sendprop_info_t temp_info;
|
||||
DataTableInfo::SendPropInfo temp;
|
||||
|
||||
if (!UTIL_FindInSendTable(pInfo->sc->m_pTable, offset, &temp_info, 0))
|
||||
if (!pInfo->lookup.retrieve(offset, &temp))
|
||||
{
|
||||
bool found = UTIL_FindInSendTable(pInfo->sc->m_pTable, offset, &temp.info, 0);
|
||||
if (!found && strchr(offset, '.'))
|
||||
{
|
||||
return false;
|
||||
found = UTIL_FindInSendTablePath(pInfo->sc->m_pTable, offset, &temp.info);
|
||||
}
|
||||
temp.name = offset;
|
||||
|
||||
pInfo->lookup.insert(offset, temp);
|
||||
|
||||
if (found)
|
||||
{
|
||||
*info = temp.info;
|
||||
}
|
||||
|
||||
pInfo->lookup.insert(offset, temp_info);
|
||||
*info = temp_info;
|
||||
return found;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
*info = temp.info;
|
||||
return info->prop != nullptr;
|
||||
}
|
||||
|
||||
SendProp *CHalfLife2::FindInSendTable(const char *classname, const char *offset)
|
||||
@@ -479,15 +585,29 @@ bool CHalfLife2::FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatab
|
||||
m_Maps.add(i, pMap, new DataMapCache());
|
||||
|
||||
DataMapCache *cache = i->value;
|
||||
DataMapCacheInfo temp;
|
||||
|
||||
if (!cache->retrieve(offset, pDataTable))
|
||||
if (!cache->retrieve(offset, &temp))
|
||||
{
|
||||
if (!UTIL_FindDataMapInfo(pMap, offset, pDataTable))
|
||||
return false;
|
||||
cache->insert(offset, *pDataTable);
|
||||
bool found = UTIL_FindDataMapInfo(pMap, offset, &temp.info);
|
||||
if (!found && strchr(offset, '.'))
|
||||
{
|
||||
found = UTIL_FindDataMapInfoPath(pMap, offset, &temp.info);
|
||||
}
|
||||
temp.name = offset;
|
||||
|
||||
cache->insert(offset, temp);
|
||||
|
||||
if (found)
|
||||
{
|
||||
*pDataTable = temp.info;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
return true;
|
||||
*pDataTable = temp.info;
|
||||
return pDataTable->prop != nullptr;
|
||||
}
|
||||
|
||||
void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset)
|
||||
@@ -528,9 +648,14 @@ bool CHalfLife2::TextMsg(int client, int dest, const char *msg)
|
||||
char buffer[253];
|
||||
ke::SafeSprintf(buffer, sizeof(buffer), "%s\1\n", msg);
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
#if SOURCE_ENGINE == SE_OUTBREAK
|
||||
CUsrMsg_SayText *pMsg;
|
||||
if ((pMsg = (CUsrMsg_SayText *)g_UserMsgs.StartProtobufMessage(m_SayTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
|
||||
#else
|
||||
CCSUsrMsg_SayText *pMsg;
|
||||
if ((pMsg = (CCSUsrMsg_SayText *)g_UserMsgs.StartProtobufMessage(m_SayTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
|
||||
#endif
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -555,9 +680,14 @@ bool CHalfLife2::TextMsg(int client, int dest, const char *msg)
|
||||
}
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
#if SOURCE_ENGINE == SE_OUTBREAK
|
||||
CUsrMsg_TextMsg *pMsg;
|
||||
if ((pMsg = (CUsrMsg_TextMsg *)g_UserMsgs.StartProtobufMessage(m_MsgTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
|
||||
#else
|
||||
CCSUsrMsg_TextMsg *pMsg;
|
||||
if ((pMsg = (CCSUsrMsg_TextMsg *)g_UserMsgs.StartProtobufMessage(m_MsgTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
|
||||
#endif
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -592,9 +722,14 @@ bool CHalfLife2::HintTextMsg(int client, const char *msg)
|
||||
{
|
||||
cell_t players[] = {client};
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
#if SOURCE_ENGINE == SE_OUTBREAK
|
||||
CUsrMsg_HintText *pMsg;
|
||||
if ((pMsg = (CUsrMsg_HintText *)g_UserMsgs.StartProtobufMessage(m_HinTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
|
||||
#else
|
||||
CCSUsrMsg_HintText *pMsg;
|
||||
if ((pMsg = (CCSUsrMsg_HintText *)g_UserMsgs.StartProtobufMessage(m_HinTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
|
||||
#endif
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -622,9 +757,14 @@ bool CHalfLife2::HintTextMsg(int client, const char *msg)
|
||||
|
||||
bool CHalfLife2::HintTextMsg(cell_t *players, int count, const char *msg)
|
||||
{
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
#if SOURCE_ENGINE == SE_OUTBREAK
|
||||
CUsrMsg_HintText *pMsg;
|
||||
if ((pMsg = (CUsrMsg_HintText *)g_UserMsgs.StartProtobufMessage(m_HinTextMsg, players, count, USERMSG_RELIABLE)) == NULL)
|
||||
#else
|
||||
CCSUsrMsg_HintText *pMsg;
|
||||
if ((pMsg = (CCSUsrMsg_HintText *)g_UserMsgs.StartProtobufMessage(m_HinTextMsg, players, count, USERMSG_RELIABLE)) == NULL)
|
||||
#endif
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -657,9 +797,14 @@ bool CHalfLife2::ShowVGUIMenu(int client, const char *name, KeyValues *data, boo
|
||||
int count = 0;
|
||||
cell_t players[] = {client};
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
#if SOURCE_ENGINE == SE_OUTBREAK
|
||||
CUsrMsg_VGUIMenu *pMsg;
|
||||
if ((pMsg = (CUsrMsg_VGUIMenu *)g_UserMsgs.StartProtobufMessage(m_VGUIMenu, players, 1, USERMSG_RELIABLE)) == NULL)
|
||||
#else
|
||||
CCSUsrMsg_VGUIMenu *pMsg;
|
||||
if ((pMsg = (CCSUsrMsg_VGUIMenu *)g_UserMsgs.StartProtobufMessage(m_VGUIMenu, players, 1, USERMSG_RELIABLE)) == NULL)
|
||||
#endif
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -682,13 +827,17 @@ bool CHalfLife2::ShowVGUIMenu(int client, const char *name, KeyValues *data, boo
|
||||
SubKey = data->GetFirstSubKey();
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
pMsg->set_name(name);
|
||||
pMsg->set_show(show);
|
||||
|
||||
while (SubKey)
|
||||
{
|
||||
#if SOURCE_ENGINE == SE_OUTBREAK
|
||||
CUsrMsg_VGUIMenu_Subkey *key = pMsg->add_subkeys();
|
||||
#else
|
||||
CCSUsrMsg_VGUIMenu_Subkey *key = pMsg->add_subkeys();
|
||||
#endif
|
||||
key->set_name(SubKey->GetName());
|
||||
key->set_str(SubKey->GetString());
|
||||
SubKey = SubKey->GetNextKey();
|
||||
@@ -718,7 +867,7 @@ void CHalfLife2::AddToFakeCliCmdQueue(int client, int userid, const char *cmd)
|
||||
{
|
||||
pFake = new DelayedFakeCliCmd;
|
||||
} else {
|
||||
pFake = m_FreeCmds.front();
|
||||
pFake = m_FreeCmds.top();
|
||||
m_FreeCmds.pop();
|
||||
}
|
||||
|
||||
@@ -748,7 +897,7 @@ void CHalfLife2::ProcessFakeCliCmdQueue()
|
||||
|
||||
bool CHalfLife2::IsLANServer()
|
||||
{
|
||||
sv_lan = icvar->FindVar("sv_lan");
|
||||
static ConVar *sv_lan = icvar->FindVar("sv_lan");
|
||||
|
||||
if (!sv_lan)
|
||||
{
|
||||
@@ -814,7 +963,7 @@ const ICommandArgs *CHalfLife2::PeekCommandStack()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return m_CommandStack.front().args;
|
||||
return m_CommandStack.top().args;
|
||||
}
|
||||
|
||||
void CHalfLife2::PopCommandStack()
|
||||
@@ -825,9 +974,9 @@ void CHalfLife2::PopCommandStack()
|
||||
const char *CHalfLife2::CurrentCommandName()
|
||||
{
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
return m_CommandStack.front().args->Arg(0);
|
||||
return m_CommandStack.top().args->Arg(0);
|
||||
#else
|
||||
return m_CommandStack.front().cmd;
|
||||
return m_CommandStack.top().cmd;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -845,7 +994,7 @@ void CHalfLife2::AddDelayedKick(int client, int userid, const char *msg)
|
||||
|
||||
kick.client = client;
|
||||
kick.userid = userid;
|
||||
ke::SafeSprintf(kick.buffer, sizeof(kick.buffer), "%s", msg);
|
||||
ke::SafeStrcpy(kick.buffer, sizeof(kick.buffer), msg);
|
||||
|
||||
m_DelayedKicks.push(kick);
|
||||
}
|
||||
@@ -940,7 +1089,7 @@ cell_t CHalfLife2::EntityToReference(CBaseEntity *pEntity)
|
||||
{
|
||||
IServerUnknown *pUnknown = (IServerUnknown *)pEntity;
|
||||
CBaseHandle hndl = pUnknown->GetRefEHandle();
|
||||
return (hndl.ToInt() | (1<<31));
|
||||
return (hndl.ToInt() | ENTREF_MASK);
|
||||
}
|
||||
|
||||
CBaseEntity *CHalfLife2::ReferenceToEntity(cell_t entRef)
|
||||
@@ -952,11 +1101,15 @@ CBaseEntity *CHalfLife2::ReferenceToEntity(cell_t entRef)
|
||||
|
||||
CEntInfo *pInfo = NULL;
|
||||
|
||||
if (entRef & (1<<31))
|
||||
if (entRef & ENTREF_MASK)
|
||||
{
|
||||
/* Proper ent reference */
|
||||
int hndlValue = entRef & ~(1<<31);
|
||||
int hndlValue = entRef & ~ENTREF_MASK;
|
||||
#if defined(SE_SDK2013_2025)
|
||||
auto hndl = CBaseHandle::UnsafeFromIndex(hndlValue);
|
||||
#else
|
||||
CBaseHandle hndl(hndlValue);
|
||||
#endif
|
||||
|
||||
pInfo = LookupEntity(hndl.GetEntryIndex());
|
||||
if (!pInfo || pInfo->m_SerialNumber != hndl.GetSerialNumber())
|
||||
@@ -1056,23 +1209,45 @@ int CHalfLife2::ReferenceToIndex(cell_t entRef)
|
||||
return INVALID_EHANDLE_INDEX;
|
||||
}
|
||||
|
||||
if (entRef & (1<<31))
|
||||
if (entRef & ENTREF_MASK)
|
||||
{
|
||||
/* Proper ent reference */
|
||||
int hndlValue = entRef & ~(1<<31);
|
||||
int hndlValue = entRef & ~ENTREF_MASK;
|
||||
#if defined(SE_SDK2013_2025)
|
||||
auto hndl = CBaseHandle::UnsafeFromIndex(hndlValue);
|
||||
#else
|
||||
CBaseHandle hndl(hndlValue);
|
||||
#endif
|
||||
|
||||
CEntInfo *pInfo = LookupEntity(hndl.GetEntryIndex());
|
||||
|
||||
if (pInfo->m_SerialNumber != hndl.GetSerialNumber())
|
||||
if (!pInfo || pInfo->m_SerialNumber != hndl.GetSerialNumber())
|
||||
{
|
||||
return INVALID_EHANDLE_INDEX;
|
||||
}
|
||||
|
||||
return hndl.GetEntryIndex();
|
||||
}
|
||||
else
|
||||
{
|
||||
CEntInfo *pInfo = LookupEntity(entRef);
|
||||
if (!pInfo)
|
||||
{
|
||||
return INVALID_EHANDLE_INDEX;
|
||||
}
|
||||
IServerUnknown *pUnk = static_cast<IServerUnknown *>(pInfo->m_pEntity);
|
||||
if (!pUnk)
|
||||
{
|
||||
return INVALID_EHANDLE_INDEX;
|
||||
}
|
||||
CBaseEntity *pEntity = pUnk->GetBaseEntity();
|
||||
if (!pEntity)
|
||||
{
|
||||
return INVALID_EHANDLE_INDEX;
|
||||
}
|
||||
|
||||
return entRef;
|
||||
return entRef;
|
||||
}
|
||||
}
|
||||
|
||||
cell_t CHalfLife2::EntityToBCompatRef(CBaseEntity *pEntity)
|
||||
@@ -1085,14 +1260,14 @@ cell_t CHalfLife2::EntityToBCompatRef(CBaseEntity *pEntity)
|
||||
IServerUnknown *pUnknown = (IServerUnknown *)pEntity;
|
||||
CBaseHandle hndl = pUnknown->GetRefEHandle();
|
||||
|
||||
if (hndl == INVALID_EHANDLE_INDEX)
|
||||
if (!hndl.IsValid())
|
||||
{
|
||||
return INVALID_EHANDLE_INDEX;
|
||||
}
|
||||
|
||||
if (hndl.GetEntryIndex() >= MAX_EDICTS)
|
||||
{
|
||||
return (hndl.ToInt() | (1<<31));
|
||||
return (hndl.ToInt() | ENTREF_MASK);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1107,8 +1282,12 @@ cell_t CHalfLife2::ReferenceToBCompatRef(cell_t entRef)
|
||||
return INVALID_EHANDLE_INDEX;
|
||||
}
|
||||
|
||||
int hndlValue = entRef & ~(1<<31);
|
||||
int hndlValue = entRef & ~ENTREF_MASK;
|
||||
#if defined(SE_SDK2013_2025)
|
||||
auto hndl = CBaseHandle::UnsafeFromIndex(hndlValue);
|
||||
#else
|
||||
CBaseHandle hndl(hndlValue);
|
||||
#endif
|
||||
|
||||
if (hndl.GetEntryIndex() < MAX_EDICTS)
|
||||
{
|
||||
@@ -1212,7 +1391,7 @@ bool IsWindowsReservedDeviceName(const char *pMapname)
|
||||
};
|
||||
|
||||
size_t reservedCount = sizeof(reservedDeviceNames) / sizeof(reservedDeviceNames[0]);
|
||||
for (int i = 0; i < reservedCount; ++i)
|
||||
for (size_t i = 0; i < reservedCount; ++i)
|
||||
{
|
||||
if (CheckReservedFilename(pMapname, reservedDeviceNames[i]))
|
||||
{
|
||||
@@ -1224,6 +1403,45 @@ bool IsWindowsReservedDeviceName(const char *pMapname)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SOURCE_ENGINE >= SE_LEFT4DEAD && defined PLATFORM_WINDOWS && SOURCE_ENGINE != SE_MOCK
|
||||
// This frees memory allocated by the game using the game's CRT on Windows,
|
||||
// avoiding a crash due to heap corruption (issue #910).
|
||||
template< class T, class I >
|
||||
class CUtlMemoryGlobalMalloc : public CUtlMemory< T, I >
|
||||
{
|
||||
typedef CUtlMemory< T, I > BaseClass;
|
||||
|
||||
public:
|
||||
using BaseClass::BaseClass;
|
||||
|
||||
void Purge()
|
||||
{
|
||||
if (!this->IsExternallyAllocated())
|
||||
{
|
||||
if (this->m_pMemory)
|
||||
{
|
||||
UTLMEMORY_TRACK_FREE();
|
||||
g_pMemAlloc->Free((void*)this->m_pMemory);
|
||||
this->m_pMemory = 0;
|
||||
}
|
||||
this->m_nAllocationCount = 0;
|
||||
}
|
||||
BaseClass::Purge();
|
||||
}
|
||||
};
|
||||
|
||||
void CHalfLife2::FreeUtlVectorUtlString(CUtlVector<CUtlString, CUtlMemoryGlobalMalloc<CUtlString>> &vec)
|
||||
{
|
||||
CUtlMemoryGlobalMalloc<unsigned char> *pMemory;
|
||||
FOR_EACH_VEC(vec, i)
|
||||
{
|
||||
pMemory = (CUtlMemoryGlobalMalloc<unsigned char> *) &vec[i].m_Storage.m_Memory;
|
||||
pMemory->Purge();
|
||||
vec[i].m_Storage.SetLength(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SMFindMapResult CHalfLife2::FindMap(const char *pMapName, char *pFoundMap, size_t nMapNameMax)
|
||||
{
|
||||
/* We need to ensure user input does not contain reserved device names on windows */
|
||||
@@ -1257,8 +1475,13 @@ SMFindMapResult CHalfLife2::FindMap(const char *pMapName, char *pFoundMap, size_
|
||||
|
||||
static size_t helperCmdLen = strlen(pHelperCmd->GetName());
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
CUtlVector<CUtlString, CUtlMemoryGlobalMalloc<CUtlString>> results;
|
||||
pHelperCmd->AutoCompleteSuggest(pMapName, *(CUtlVector<CUtlString, CUtlMemory<CUtlString>>*)&results);
|
||||
#else
|
||||
CUtlVector<CUtlString> results;
|
||||
pHelperCmd->AutoCompleteSuggest(pMapName, results);
|
||||
#endif
|
||||
if (results.Count() == 0)
|
||||
return SMFindMapResult::NotFound;
|
||||
|
||||
@@ -1270,27 +1493,40 @@ SMFindMapResult CHalfLife2::FindMap(const char *pMapName, char *pFoundMap, size_
|
||||
bool bExactMatch = Q_strcmp(pMapName, &results[0][helperCmdLen + 1]) == 0;
|
||||
if (bExactMatch)
|
||||
{
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
FreeUtlVectorUtlString(results);
|
||||
#endif
|
||||
return SMFindMapResult::Found;
|
||||
}
|
||||
else
|
||||
{
|
||||
ke::SafeStrcpy(pFoundMap, nMapNameMax, &results[0][helperCmdLen + 1]);
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
FreeUtlVectorUtlString(results);
|
||||
#endif
|
||||
return SMFindMapResult::FuzzyMatch;
|
||||
}
|
||||
|
||||
#elif SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_BMS
|
||||
static char szTemp[PLATFORM_MAX_PATH];
|
||||
if (pFoundMap == NULL)
|
||||
#elif SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_HL2DM \
|
||||
|| SOURCE_ENGINE == SE_SDK2013 || SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_PVKII
|
||||
static IVEngineServer *engine23 = (IVEngineServer *)(g_SMAPI->GetEngineFactory()("VEngineServer023", nullptr));
|
||||
if (engine23)
|
||||
{
|
||||
ke::SafeStrcpy(szTemp, SM_ARRAYSIZE(szTemp), pMapName);
|
||||
pFoundMap = szTemp;
|
||||
nMapNameMax = 0;
|
||||
}
|
||||
static char szTemp[PLATFORM_MAX_PATH];
|
||||
if (pFoundMap == NULL)
|
||||
{
|
||||
ke::SafeStrcpy(szTemp, SM_ARRAYSIZE(szTemp), pMapName);
|
||||
pFoundMap = szTemp;
|
||||
nMapNameMax = 0;
|
||||
}
|
||||
|
||||
return static_cast<SMFindMapResult>(engine->FindMap(pFoundMap, static_cast<int>(nMapNameMax)));
|
||||
#elif SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_SDK2013
|
||||
static IVEngineServer *engine21 = (IVEngineServer *)(g_SMAPI->GetEngineFactory()("VEngineServer021", nullptr));
|
||||
return engine21->IsMapValid(pMapName) == 0 ? SMFindMapResult::NotFound : SMFindMapResult::Found;
|
||||
return static_cast<SMFindMapResult>(engine->FindMap(pFoundMap, static_cast<int>(nMapNameMax)));
|
||||
}
|
||||
else
|
||||
{
|
||||
static IVEngineServer *engine21 = (IVEngineServer *)(g_SMAPI->GetEngineFactory()("VEngineServer021", nullptr));
|
||||
return engine21->IsMapValid(pMapName) == 0 ? SMFindMapResult::NotFound : SMFindMapResult::Found;
|
||||
}
|
||||
#else
|
||||
return engine->IsMapValid(pMapName) == 0 ? SMFindMapResult::NotFound : SMFindMapResult::Found;
|
||||
#endif
|
||||
@@ -1321,8 +1557,36 @@ bool CHalfLife2::IsMapValid(const char *map)
|
||||
return FindMap(map) != SMFindMapResult::NotFound;
|
||||
}
|
||||
|
||||
// TODO: Add ep1 support for this. (No IServerTools available there)
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
#if SOURCE_ENGINE < SE_ORANGEBOX
|
||||
class VKeyValuesSS_Helper {};
|
||||
static bool VKeyValuesSS(CBaseEntity* pThisPtr, const char *pszKey, const char *pszValue, int offset)
|
||||
{
|
||||
void** this_ptr = *reinterpret_cast<void***>(&pThisPtr);
|
||||
void** vtable = *reinterpret_cast<void***>(pThisPtr);
|
||||
void* vfunc = vtable[offset];
|
||||
|
||||
union
|
||||
{
|
||||
bool (VKeyValuesSS_Helper::* mfpnew)(const char *, const char *);
|
||||
#ifndef PLATFORM_POSIX
|
||||
void* addr;
|
||||
} u;
|
||||
u.addr = vfunc;
|
||||
#else
|
||||
struct
|
||||
{
|
||||
void* addr;
|
||||
intptr_t adjustor;
|
||||
} s;
|
||||
} u;
|
||||
u.s.addr = vfunc;
|
||||
u.s.adjustor = 0;
|
||||
#endif
|
||||
|
||||
return (bool)(reinterpret_cast<VKeyValuesSS_Helper*>(this_ptr)->*u.mfpnew)(pszKey, pszValue);
|
||||
}
|
||||
#endif
|
||||
|
||||
string_t CHalfLife2::AllocPooledString(const char *pszValue)
|
||||
{
|
||||
// This is admittedly a giant hack, but it's a relatively safe method for
|
||||
@@ -1332,32 +1596,62 @@ string_t CHalfLife2::AllocPooledString(const char *pszValue)
|
||||
// current targetname string_t, set it to our string to insert via SetKeyValue,
|
||||
// read back the new targetname value, restore the old value, and return the new one.
|
||||
|
||||
#if SOURCE_ENGINE < SE_ORANGEBOX
|
||||
CBaseEntity* pEntity = nullptr;
|
||||
for (int i = 0; i < gpGlobals->maxEntities; ++i)
|
||||
{
|
||||
pEntity = ReferenceToEntity(i);
|
||||
if (pEntity)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pEntity)
|
||||
{
|
||||
logger->LogError("Failed to locate a valid entity for AllocPooledString.");
|
||||
return NULL_STRING;
|
||||
}
|
||||
|
||||
#else
|
||||
CBaseEntity *pEntity = ((IServerUnknown *) servertools->FirstEntity())->GetBaseEntity();
|
||||
#endif
|
||||
auto *pDataMap = GetDataMap(pEntity);
|
||||
assert(pDataMap);
|
||||
|
||||
static int offset = -1;
|
||||
if (offset == -1)
|
||||
static int iNameOffset = -1;
|
||||
if (iNameOffset == -1)
|
||||
{
|
||||
sm_datatable_info_t info;
|
||||
bool found = FindDataMapInfo(pDataMap, "m_iName", &info);
|
||||
assert(found);
|
||||
offset = info.actual_offset;
|
||||
iNameOffset = info.actual_offset;
|
||||
}
|
||||
|
||||
string_t *pProp = (string_t *) ((intp) pEntity + offset);
|
||||
string_t* pProp = (string_t*)((intp)pEntity + iNameOffset);
|
||||
string_t backup = *pProp;
|
||||
|
||||
#if SOURCE_ENGINE < SE_ORANGEBOX
|
||||
static int iFuncOffset;
|
||||
if (!g_pGameConf->GetOffset("DispatchKeyValue", &iFuncOffset) || !iFuncOffset)
|
||||
{
|
||||
logger->LogError("Failed to locate DispatchKeyValue in core gamedata. AllocPooledString unsupported.");
|
||||
return NULL_STRING;
|
||||
}
|
||||
VKeyValuesSS(pEntity, "targetname", pszValue, iFuncOffset);
|
||||
#else
|
||||
servertools->SetKeyValue(pEntity, "targetname", pszValue);
|
||||
#endif
|
||||
|
||||
string_t newString = *pProp;
|
||||
*pProp = backup;
|
||||
|
||||
return newString;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool CHalfLife2::GetServerSteam3Id(char *pszOut, size_t len) const
|
||||
{
|
||||
CSteamID sid(GetServerSteamId64());
|
||||
CSteamID sid((uint64)GetServerSteamId64());
|
||||
|
||||
switch (sid.GetEAccountType())
|
||||
{
|
||||
@@ -1398,10 +1692,13 @@ uint64_t CHalfLife2::GetServerSteamId64() const
|
||||
|| SOURCE_ENGINE == SE_EYE \
|
||||
|| SOURCE_ENGINE == SE_HL2DM \
|
||||
|| SOURCE_ENGINE == SE_INSURGENCY \
|
||||
|| SOURCE_ENGINE == SE_DOI \
|
||||
|| SOURCE_ENGINE == SE_DOI \
|
||||
|| SOURCE_ENGINE == SE_SDK2013 \
|
||||
|| SOURCE_ENGINE == SE_ALIENSWARM \
|
||||
|| SOURCE_ENGINE == SE_TF2
|
||||
|| SOURCE_ENGINE == SE_TF2 \
|
||||
|| SOURCE_ENGINE == SE_PVKII \
|
||||
|| SOURCE_ENGINE == SE_MCV \
|
||||
|| SOURCE_ENGINE == SE_OUTBREAK
|
||||
const CSteamID *sid = engine->GetGameServerSteamID();
|
||||
if (sid)
|
||||
{
|
||||
@@ -1427,3 +1724,26 @@ uint64_t CHalfLife2::GetServerSteamId64() const
|
||||
|
||||
return 1ULL;
|
||||
}
|
||||
|
||||
void CHalfLife2::RemoveDataTableCache(datamap_t *pMap)
|
||||
{
|
||||
if (pMap == nullptr)
|
||||
{
|
||||
m_Maps.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
m_Maps.removeIfExists(pMap);
|
||||
}
|
||||
|
||||
bool CHalfLife2::RemoveSendPropCache(const char *classname)
|
||||
{
|
||||
if (classname == nullptr)
|
||||
{
|
||||
m_Classes.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
return m_Classes.remove(classname);
|
||||
}
|
||||
|
||||
|
||||
+86
-21
@@ -32,13 +32,12 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_CHALFLIFE2_H_
|
||||
#define _INCLUDE_SOURCEMOD_CHALFLIFE2_H_
|
||||
|
||||
#include <sh_list.h>
|
||||
#include <sh_string.h>
|
||||
#include <sh_tinyhash.h>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <am-utility.h>
|
||||
#include <am-hashset.h>
|
||||
#include <am-hashmap.h>
|
||||
#include <sm_stringhashmap.h>
|
||||
#include <sm_hashmap.h>
|
||||
#include <sm_namehashset.h>
|
||||
#include "sm_globals.h"
|
||||
#include "sm_queue.h"
|
||||
@@ -54,49 +53,105 @@ namespace SourceMod {
|
||||
class ICommandArgs;
|
||||
} // namespace SourceMod
|
||||
|
||||
using namespace SourceHook;
|
||||
using namespace SourceMod;
|
||||
|
||||
static const int ENTREF_MASK = (1 << 31);
|
||||
|
||||
#define HUD_PRINTTALK 3
|
||||
#define HUD_PRINTCENTER 4
|
||||
|
||||
#if defined _WIN32
|
||||
#define SOURCE_BIN_PREFIX ""
|
||||
#define SOURCE_BIN_SUFFIX ""
|
||||
#define SOURCE_BIN_EXT ".dll"
|
||||
#elif defined __APPLE__
|
||||
#define SOURCE_BIN_PREFIX ""
|
||||
#define SOURCE_BIN_SUFFIX ""
|
||||
#define SOURCE_BIN_EXT ".dylib"
|
||||
#elif defined __linux__
|
||||
#if SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_TF2 \
|
||||
|| SOURCE_ENGINE == SE_SDK2013 || SOURCE_ENGINE == SE_LEFT4DEAD2 || SOURCE_ENGINE == SE_NUCLEARDAWN \
|
||||
|| SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_INSURGENCY || SOURCE_ENGINE == SE_DOI
|
||||
#define SOURCE_BIN_PREFIX "lib"
|
||||
#define SOURCE_BIN_SUFFIX "_srv"
|
||||
#elif SOURCE_ENGINE >= SE_LEFT4DEAD || SOURCE_ENGINE == SE_PVKII
|
||||
#define SOURCE_BIN_PREFIX "lib"
|
||||
#define SOURCE_BIN_SUFFIX ""
|
||||
#else
|
||||
#define SOURCE_BIN_PREFIX ""
|
||||
#define SOURCE_BIN_SUFFIX "_i486"
|
||||
#endif
|
||||
#define SOURCE_BIN_EXT ".so"
|
||||
#endif
|
||||
|
||||
#define FORMAT_SOURCE_BIN_NAME(basename) \
|
||||
(SOURCE_BIN_PREFIX basename SOURCE_BIN_SUFFIX SOURCE_BIN_EXT)
|
||||
|
||||
struct DataTableInfo
|
||||
{
|
||||
struct SendPropPolicy
|
||||
struct SendPropInfo
|
||||
{
|
||||
static inline bool matches(const char *name, const sm_sendprop_info_t &info)
|
||||
static inline bool matches(const char *name, const SendPropInfo &info)
|
||||
{
|
||||
return strcmp(name, info.prop->GetName()) == 0;
|
||||
return strcmp(name, info.name.c_str()) == 0;
|
||||
}
|
||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
||||
{
|
||||
return key.hash();
|
||||
}
|
||||
|
||||
SendPropInfo()
|
||||
: name(), info{nullptr, 0}
|
||||
{
|
||||
}
|
||||
|
||||
std::string name;
|
||||
sm_sendprop_info_t info;
|
||||
};
|
||||
|
||||
static inline bool matches(const char *name, const DataTableInfo *info)
|
||||
{
|
||||
return strcmp(name, info->sc->GetName()) == 0;
|
||||
}
|
||||
|
||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
||||
{
|
||||
return key.hash();
|
||||
}
|
||||
|
||||
DataTableInfo(ServerClass *sc)
|
||||
: sc(sc)
|
||||
{
|
||||
}
|
||||
|
||||
ServerClass *sc;
|
||||
NameHashSet<sm_sendprop_info_t, SendPropPolicy> lookup;
|
||||
NameHashSet<SendPropInfo> lookup;
|
||||
};
|
||||
|
||||
struct DataMapCachePolicy
|
||||
struct DataMapCacheInfo
|
||||
{
|
||||
static inline bool matches(const char *name, const sm_datatable_info_t &info)
|
||||
static inline bool matches(const char *name, const DataMapCacheInfo &info)
|
||||
{
|
||||
return strcmp(name, info.prop->fieldName) == 0;
|
||||
return strcmp(name, info.name.c_str()) == 0;
|
||||
}
|
||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
||||
{
|
||||
return key.hash();
|
||||
}
|
||||
|
||||
DataMapCacheInfo()
|
||||
: name(), info{nullptr, 0}
|
||||
{
|
||||
}
|
||||
|
||||
std::string name;
|
||||
sm_datatable_info_t info;
|
||||
};
|
||||
|
||||
typedef NameHashSet<sm_datatable_info_t, DataMapCachePolicy> DataMapCache;
|
||||
typedef NameHashSet<DataMapCacheInfo> DataMapCache;
|
||||
|
||||
struct DelayedFakeCliCmd
|
||||
{
|
||||
String cmd;
|
||||
std::string cmd;
|
||||
int client;
|
||||
int userid;
|
||||
};
|
||||
@@ -140,6 +195,12 @@ enum class SMFindMapResult : cell_t {
|
||||
PossiblyAvailable
|
||||
};
|
||||
|
||||
#if SOURCE_ENGINE >= SE_LEFT4DEAD && defined PLATFORM_WINDOWS
|
||||
template< class T, class I = int >
|
||||
class CUtlMemoryGlobalMalloc;
|
||||
class CUtlString;
|
||||
#endif
|
||||
|
||||
class CHalfLife2 :
|
||||
public SMGlobalClass,
|
||||
public IGameHelpers
|
||||
@@ -160,6 +221,7 @@ public: //IGameHelpers
|
||||
bool FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info);
|
||||
datamap_t *GetDataMap(CBaseEntity *pEntity);
|
||||
ServerClass *FindServerClass(const char *classname);
|
||||
ServerClass *FindEntityServerClass(CBaseEntity *pEntity);
|
||||
typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
|
||||
bool FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatable_info_t *pDataTable);
|
||||
void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
|
||||
@@ -190,12 +252,15 @@ public: //IGameHelpers
|
||||
bool IsMapValid(const char *map);
|
||||
SMFindMapResult FindMap(char *pMapName, size_t nMapNameMax);
|
||||
SMFindMapResult FindMap(const char *pMapName, char *pFoundMap = NULL, size_t nMapNameMax = 0);
|
||||
bool GetMapDisplayName(const char *pMapName, char *pDisplayname, size_t nMapNameMax);
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
string_t AllocPooledString(const char *pszValue);
|
||||
#if SOURCE_ENGINE >= SE_LEFT4DEAD && defined PLATFORM_WINDOWS && SOURCE_ENGINE != SE_MOCK
|
||||
void FreeUtlVectorUtlString(CUtlVector<CUtlString, CUtlMemoryGlobalMalloc<CUtlString>> &vec);
|
||||
#endif
|
||||
bool GetMapDisplayName(const char *pMapName, char *pDisplayname, size_t nMapNameMax);
|
||||
string_t AllocPooledString(const char *pszValue);
|
||||
bool GetServerSteam3Id(char *pszOut, size_t len) const override;
|
||||
uint64_t GetServerSteamId64() const override;
|
||||
void RemoveDataTableCache(datamap_t *pMap = nullptr);
|
||||
bool RemoveSendPropCache(const char *classname = nullptr);
|
||||
public:
|
||||
void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
|
||||
void ProcessFakeCliCmdQueue();
|
||||
@@ -221,8 +286,8 @@ private:
|
||||
int m_SayTextMsg;
|
||||
int m_VGUIMenu;
|
||||
Queue<DelayedFakeCliCmd *> m_CmdQueue;
|
||||
CStack<DelayedFakeCliCmd *> m_FreeCmds;
|
||||
CStack<CachedCommandInfo> m_CommandStack;
|
||||
std::stack<DelayedFakeCliCmd *> m_FreeCmds;
|
||||
std::stack<CachedCommandInfo> m_CommandStack;
|
||||
Queue<DelayedKickInfo> m_DelayedKicks;
|
||||
void *m_pGetCommandLine;
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
@@ -232,7 +297,7 @@ public:
|
||||
return !m_bFollowCSGOServerGuidelines || !m_CSGOBadList.has(pszPropName);
|
||||
}
|
||||
private:
|
||||
ke::HashSet<ke::AString, detail::StringHashMapPolicy> m_CSGOBadList;
|
||||
ke::HashSet<std::string, detail::StringHashMapPolicy> m_CSGOBadList;
|
||||
bool m_bFollowCSGOServerGuidelines = true;
|
||||
#endif
|
||||
};
|
||||
|
||||
+32
-29
@@ -38,6 +38,7 @@
|
||||
#include "sourcemm_api.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "MenuStyle_Valve.h"
|
||||
#include <IGameConfigs.h>
|
||||
#include "sourcemm_api.h"
|
||||
#include "logic_bridge.h"
|
||||
|
||||
@@ -68,6 +69,29 @@ void MenuManager::OnSourceModAllInitialized()
|
||||
m_StyleType = handlesys->CreateType("IMenuStyle", this, 0, NULL, &access, g_pCoreIdent, NULL);
|
||||
}
|
||||
|
||||
void MenuManager::OnSourceModAllInitialized_Post()
|
||||
{
|
||||
const char* pTmp;
|
||||
|
||||
pTmp = g_pGameConf->GetKeyValue("MenuItemSound");
|
||||
if (nullptr != pTmp)
|
||||
{
|
||||
m_SelectSound = pTmp;
|
||||
}
|
||||
|
||||
pTmp = g_pGameConf->GetKeyValue("MenuExitSound");
|
||||
if (nullptr != pTmp)
|
||||
{
|
||||
m_ExitSound = pTmp;
|
||||
}
|
||||
|
||||
pTmp = g_pGameConf->GetKeyValue("MenuExitBackSound");
|
||||
if (nullptr != pTmp)
|
||||
{
|
||||
m_ExitBackSound = pTmp;
|
||||
}
|
||||
}
|
||||
|
||||
void MenuManager::OnSourceModAllShutdown()
|
||||
{
|
||||
handlesys->RemoveType(m_MenuType, g_pCoreIdent);
|
||||
@@ -308,7 +332,7 @@ IMenuPanel *MenuManager::RenderMenu(int client, menu_states_t &md, ItemOrder ord
|
||||
{
|
||||
ItemDrawInfo &dr = drawItems[foundItems].draw;
|
||||
/* Is the item valid? */
|
||||
if (menu->GetItemInfo(i, &dr) != NULL)
|
||||
if (menu->GetItemInfo(i, &dr, client) != NULL)
|
||||
{
|
||||
/* Ask the user to change the style, if necessary */
|
||||
mh->OnMenuDrawItem(menu, client, i, dr.style);
|
||||
@@ -398,7 +422,7 @@ IMenuPanel *MenuManager::RenderMenu(int client, menu_states_t &md, ItemOrder ord
|
||||
}
|
||||
while (++lastItem < totalItems)
|
||||
{
|
||||
if (menu->GetItemInfo(lastItem, &dr) != NULL)
|
||||
if (menu->GetItemInfo(lastItem, &dr, client) != NULL)
|
||||
{
|
||||
mh->OnMenuDrawItem(menu, client, lastItem, dr.style);
|
||||
if (IsSlotItem(panel, dr.style))
|
||||
@@ -420,7 +444,7 @@ IMenuPanel *MenuManager::RenderMenu(int client, menu_states_t &md, ItemOrder ord
|
||||
lastItem--;
|
||||
while (lastItem != 0)
|
||||
{
|
||||
if (menu->GetItemInfo(lastItem, &dr) != NULL)
|
||||
if (menu->GetItemInfo(lastItem, &dr, client) != NULL)
|
||||
{
|
||||
mh->OnMenuDrawItem(menu, client, lastItem, dr.style);
|
||||
if (IsSlotItem(panel, dr.style))
|
||||
@@ -699,30 +723,9 @@ bool MenuManager::MenuSoundsEnabled()
|
||||
return (sm_menu_sounds.GetInt() != 0);
|
||||
}
|
||||
|
||||
ConfigResult MenuManager::OnSourceModConfigChanged(const char *key,
|
||||
const char *value,
|
||||
ConfigSource source,
|
||||
char *error,
|
||||
size_t maxlength)
|
||||
std::string *MenuManager::GetMenuSound(ItemSelection sel)
|
||||
{
|
||||
if (strcmp(key, "MenuItemSound") == 0)
|
||||
{
|
||||
m_SelectSound.assign(value);
|
||||
return ConfigResult_Accept;
|
||||
} else if (strcmp(key, "MenuExitBackSound") == 0) {
|
||||
m_ExitBackSound.assign(value);
|
||||
return ConfigResult_Accept;
|
||||
} else if (strcmp(key, "MenuExitSound") == 0) {
|
||||
m_ExitSound.assign(value);
|
||||
return ConfigResult_Accept;
|
||||
}
|
||||
|
||||
return ConfigResult_Ignore;
|
||||
}
|
||||
|
||||
const char *MenuManager::GetMenuSound(ItemSelection sel)
|
||||
{
|
||||
const char *sound = NULL;
|
||||
std::string *sound = nullptr;
|
||||
|
||||
switch (sel)
|
||||
{
|
||||
@@ -732,7 +735,7 @@ const char *MenuManager::GetMenuSound(ItemSelection sel)
|
||||
{
|
||||
if (m_SelectSound.size() > 0)
|
||||
{
|
||||
sound = m_SelectSound.c_str();
|
||||
sound = &m_SelectSound;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -740,7 +743,7 @@ const char *MenuManager::GetMenuSound(ItemSelection sel)
|
||||
{
|
||||
if (m_ExitBackSound.size() > 0)
|
||||
{
|
||||
sound = m_ExitBackSound.c_str();
|
||||
sound = &m_ExitBackSound;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -748,7 +751,7 @@ const char *MenuManager::GetMenuSound(ItemSelection sel)
|
||||
{
|
||||
if (m_ExitSound.size() > 0)
|
||||
{
|
||||
sound = m_ExitSound.c_str();
|
||||
sound = &m_ExitSound;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
+10
-15
@@ -33,14 +33,13 @@
|
||||
#define _INCLUDE_SOURCEMOD_MENUMANAGER_H_
|
||||
|
||||
#include <IMenuManager.h>
|
||||
#include <sh_vector.h>
|
||||
#include <sh_stack.h>
|
||||
#include <sh_list.h>
|
||||
#include <sh_string.h>
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
#include <list>
|
||||
#include "sm_globals.h"
|
||||
#include <string>
|
||||
|
||||
using namespace SourceMod;
|
||||
using namespace SourceHook;
|
||||
|
||||
class MenuManager :
|
||||
public IMenuManager,
|
||||
@@ -55,12 +54,8 @@ public:
|
||||
MenuManager();
|
||||
public: //SMGlobalClass
|
||||
void OnSourceModAllInitialized();
|
||||
void OnSourceModAllInitialized_Post();
|
||||
void OnSourceModAllShutdown();
|
||||
ConfigResult OnSourceModConfigChanged(const char *key,
|
||||
const char *value,
|
||||
ConfigSource source,
|
||||
char *error,
|
||||
size_t maxlength);
|
||||
void OnSourceModLevelChange(const char *mapName);
|
||||
public: //IMenuManager
|
||||
virtual const char *GetInterfaceName()
|
||||
@@ -99,19 +94,19 @@ public:
|
||||
HandleError ReadStyleHandle(Handle_t handle, IMenuStyle **style);
|
||||
public:
|
||||
bool MenuSoundsEnabled();
|
||||
const char *GetMenuSound(ItemSelection sel);
|
||||
std::string *GetMenuSound(ItemSelection sel);
|
||||
protected:
|
||||
Handle_t CreateMenuHandle(IBaseMenu *menu, IdentityToken_t *pOwner);
|
||||
Handle_t CreateStyleHandle(IMenuStyle *style);
|
||||
private:
|
||||
int m_ShowMenu;
|
||||
IMenuStyle *m_pDefaultStyle;
|
||||
CVector<IMenuStyle *> m_Styles;
|
||||
std::vector<IMenuStyle *> m_Styles;
|
||||
HandleType_t m_StyleType;
|
||||
HandleType_t m_MenuType;
|
||||
String m_SelectSound;
|
||||
String m_ExitBackSound;
|
||||
String m_ExitSound;
|
||||
std::string m_SelectSound = "";
|
||||
std::string m_ExitBackSound = "";
|
||||
std::string m_ExitSound = "";
|
||||
};
|
||||
|
||||
extern MenuManager g_Menus;
|
||||
|
||||
+114
-48
@@ -36,7 +36,7 @@
|
||||
#include "MenuManager.h"
|
||||
#include "CellRecipientFilter.h"
|
||||
#if defined MENU_DEBUG
|
||||
#include "Logger.h"
|
||||
#include <bridge/include/ILogger.h>
|
||||
#endif
|
||||
#include "logic_bridge.h"
|
||||
#include "AutoHandleRooter.h"
|
||||
@@ -59,7 +59,7 @@ Handle_t BaseMenuStyle::GetHandle()
|
||||
void BaseMenuStyle::AddClientToWatch(int client)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] AddClientToWatch(%d)", client);
|
||||
logger->LogMessage("[SM_MENU] AddClientToWatch(%d)", client);
|
||||
#endif
|
||||
m_WatchList.push_back(client);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ void BaseMenuStyle::AddClientToWatch(int client)
|
||||
void BaseMenuStyle::RemoveClientFromWatch(int client)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] RemoveClientFromWatch(%d)", client);
|
||||
logger->LogMessage("[SM_MENU] RemoveClientFromWatch(%d)", client);
|
||||
#endif
|
||||
m_WatchList.remove(client);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ void BaseMenuStyle::RemoveClientFromWatch(int client)
|
||||
void BaseMenuStyle::_CancelClientMenu(int client, MenuCancelReason reason, bool bAutoIgnore/* =false */)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] _CancelClientMenu() (client %d) (bAutoIgnore %d) (reason %d)", client, bAutoIgnore, reason);
|
||||
logger->LogMessage("[SM_MENU] _CancelClientMenu() (client %d) (bAutoIgnore %d) (reason %d)", client, bAutoIgnore, reason);
|
||||
#endif
|
||||
CBaseMenuPlayer *player = GetMenuPlayer(client);
|
||||
menu_states_t &states = player->states;
|
||||
@@ -97,6 +97,9 @@ void BaseMenuStyle::_CancelClientMenu(int client, MenuCancelReason reason, bool
|
||||
RemoveClientFromWatch(client);
|
||||
}
|
||||
|
||||
Handle_t hndl = menu ? menu->GetHandle() : BAD_HANDLE;
|
||||
AutoHandleRooter ahr(hndl);
|
||||
|
||||
/* Fire callbacks */
|
||||
mh->OnMenuCancel(menu, client, reason);
|
||||
|
||||
@@ -115,7 +118,7 @@ void BaseMenuStyle::_CancelClientMenu(int client, MenuCancelReason reason, bool
|
||||
void BaseMenuStyle::CancelMenu(CBaseMenu *menu)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] CancelMenu() (menu %p)", menu);
|
||||
logger->LogMessage("[SM_MENU] CancelMenu() (menu %p)", menu);
|
||||
#endif
|
||||
int maxClients = g_Players.GetMaxClients();
|
||||
for (int i=1; i<=maxClients; i++)
|
||||
@@ -135,7 +138,7 @@ void BaseMenuStyle::CancelMenu(CBaseMenu *menu)
|
||||
bool BaseMenuStyle::CancelClientMenu(int client, bool autoIgnore)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] CancelClientMenu() (client %d) (bAutoIgnore %d)", client, autoIgnore);
|
||||
logger->LogMessage("[SM_MENU] CancelClientMenu() (client %d) (bAutoIgnore %d)", client, autoIgnore);
|
||||
#endif
|
||||
if (client < 1 || client > g_Players.MaxClients())
|
||||
{
|
||||
@@ -191,7 +194,7 @@ MenuSource BaseMenuStyle::GetClientMenu(int client, void **object)
|
||||
void BaseMenuStyle::OnClientDisconnected(int client)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] OnClientDisconnected(%d)", client);
|
||||
logger->LogMessage("[SM_MENU] OnClientDisconnected(%d)", client);
|
||||
#endif
|
||||
CBaseMenuPlayer *player = GetMenuPlayer(client);
|
||||
if (!player->bInMenu)
|
||||
@@ -214,7 +217,7 @@ void BaseMenuStyle::ProcessWatchList()
|
||||
}
|
||||
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("BaseMenuStyle::ProcessWatchList(%d,%d,%d,%d,%d,%p)",
|
||||
logger->LogMessage("BaseMenuStyle::ProcessWatchList(%d,%d,%d,%d,%d,%p)",
|
||||
m_WatchList.m_Size,
|
||||
m_WatchList.m_FirstLink,
|
||||
m_WatchList.m_FreeNodes,
|
||||
@@ -232,7 +235,7 @@ void BaseMenuStyle::ProcessWatchList()
|
||||
#if defined MENU_DEBUG
|
||||
if (total)
|
||||
{
|
||||
g_Logger.LogMessage("[SM_MENU] ProcessWatchList() found %d clients", total);
|
||||
logger->LogMessage("[SM_MENU] ProcessWatchList() found %d clients", total);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -244,7 +247,7 @@ void BaseMenuStyle::ProcessWatchList()
|
||||
client = do_lookup[i];
|
||||
player = GetMenuPlayer(client);
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] ProcessWatchList() (client %d) (bInMenu %d) (menuHoldTime %d) (curTime %f) (menuStartTime %f)",
|
||||
logger->LogMessage("[SM_MENU] ProcessWatchList() (client %d) (bInMenu %d) (menuHoldTime %d) (curTime %f) (menuStartTime %f)",
|
||||
client,
|
||||
player->bInMenu,
|
||||
player->menuHoldTime,
|
||||
@@ -254,7 +257,7 @@ void BaseMenuStyle::ProcessWatchList()
|
||||
if (!player->bInMenu || !player->menuHoldTime)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] ProcessWatchList() removing client %d", client);
|
||||
logger->LogMessage("[SM_MENU] ProcessWatchList() removing client %d", client);
|
||||
#endif
|
||||
m_WatchList.remove(client);
|
||||
continue;
|
||||
@@ -269,7 +272,7 @@ void BaseMenuStyle::ProcessWatchList()
|
||||
void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] ClientPressedKey() (client %d) (key_press %d)", client, key_press);
|
||||
logger->LogMessage("[SM_MENU] ClientPressedKey() (client %d) (key_press %d)", client, key_press);
|
||||
#endif
|
||||
CBaseMenuPlayer *player = GetMenuPlayer(client);
|
||||
|
||||
@@ -311,9 +314,9 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
|
||||
clients[0] = client;
|
||||
filter.Initialize(clients, 1);
|
||||
|
||||
const char *sound = g_Menus.GetMenuSound(type);
|
||||
std::string *sound = g_Menus.GetMenuSound(type);
|
||||
|
||||
if (sound != NULL)
|
||||
if (nullptr != sound && !sound->empty())
|
||||
{
|
||||
edict_t *pEdict = PEntityOfEntIndex(client);
|
||||
if (pEdict)
|
||||
@@ -327,10 +330,10 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
|
||||
client,
|
||||
CHAN_AUTO,
|
||||
#if SOURCE_ENGINE >= SE_PORTAL2
|
||||
sound,
|
||||
sound->c_str(),
|
||||
-1,
|
||||
#endif
|
||||
sound,
|
||||
sound->c_str(),
|
||||
VOL_NORM,
|
||||
ATTN_NORM,
|
||||
#if SOURCE_ENGINE >= SE_PORTAL2
|
||||
@@ -339,7 +342,7 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
|
||||
0,
|
||||
PITCH_NORM,
|
||||
#if SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS \
|
||||
|| SOURCE_ENGINE == SE_SDK2013 || SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_TF2
|
||||
|| SOURCE_ENGINE == SE_SDK2013 || SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_PVKII
|
||||
0,
|
||||
#endif
|
||||
&pos);
|
||||
@@ -412,14 +415,14 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
|
||||
bool BaseMenuStyle::DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] DoClientMenu() (client %d) (panel %p) (mh %p) (time %d)",
|
||||
logger->LogMessage("[SM_MENU] DoClientMenu() (client %d) (panel %p) (mh %p) (time %d)",
|
||||
client,
|
||||
menu,
|
||||
mh,
|
||||
time);
|
||||
#endif
|
||||
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
|
||||
if (!pPlayer || pPlayer->IsFakeClient() || !pPlayer->IsInGame())
|
||||
if (!pPlayer || !pPlayer->IsInGame())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -475,7 +478,7 @@ bool BaseMenuStyle::DoClientMenu(int client,
|
||||
unsigned int time)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] DoClientMenu() (client %d) (menu %p) (mh %p) (time %d)",
|
||||
logger->LogMessage("[SM_MENU] DoClientMenu() (client %d) (menu %p) (mh %p) (time %d)",
|
||||
client,
|
||||
menu,
|
||||
mh,
|
||||
@@ -487,7 +490,7 @@ bool BaseMenuStyle::DoClientMenu(int client,
|
||||
if (!pPlayer || pPlayer->IsFakeClient() || !pPlayer->IsInGame())
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Failed to display to client %d", client);
|
||||
logger->LogMessage("[SM_MENU] DoClientMenu(): Failed to display to client %d", client);
|
||||
#endif
|
||||
mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay);
|
||||
mh->OnMenuEnd(menu, MenuEnd_Cancelled);
|
||||
@@ -498,7 +501,7 @@ bool BaseMenuStyle::DoClientMenu(int client,
|
||||
if (player->bAutoIgnore)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Client %d is autoIgnoring", client);
|
||||
logger->LogMessage("[SM_MENU] DoClientMenu(): Client %d is autoIgnoring", client);
|
||||
#endif
|
||||
mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay);
|
||||
mh->OnMenuEnd(menu, MenuEnd_Cancelled);
|
||||
@@ -517,7 +520,7 @@ bool BaseMenuStyle::DoClientMenu(int client,
|
||||
if (player->bInMenu)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Cancelling old menu to client %d", client);
|
||||
logger->LogMessage("[SM_MENU] DoClientMenu(): Cancelling old menu to client %d", client);
|
||||
#endif
|
||||
_CancelClientMenu(client, MenuCancel_Interrupted, true);
|
||||
}
|
||||
@@ -532,7 +535,7 @@ bool BaseMenuStyle::DoClientMenu(int client,
|
||||
if (!display)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Failed to render to client %d", client);
|
||||
logger->LogMessage("[SM_MENU] DoClientMenu(): Failed to render to client %d", client);
|
||||
#endif
|
||||
player->bAutoIgnore = false;
|
||||
player->bInMenu = false;
|
||||
@@ -562,7 +565,7 @@ bool BaseMenuStyle::DoClientMenu(int client,
|
||||
player->bAutoIgnore = false;
|
||||
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] DoClientMenu() finished successfully (client %d)", client);
|
||||
logger->LogMessage("[SM_MENU] DoClientMenu() finished successfully (client %d)", client);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
@@ -571,17 +574,19 @@ bool BaseMenuStyle::DoClientMenu(int client,
|
||||
bool BaseMenuStyle::RedoClientMenu(int client, ItemOrder order)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] RedoClientMenu() (client %d) (order %d)", client, order);
|
||||
logger->LogMessage("[SM_MENU] RedoClientMenu() (client %d) (order %d)", client, order);
|
||||
#endif
|
||||
CBaseMenuPlayer *player = GetMenuPlayer(client);
|
||||
menu_states_t &states = player->states;
|
||||
|
||||
AutoHandleRooter ahr(states.menu ? states.menu->GetHandle() : BAD_HANDLE);
|
||||
|
||||
player->bAutoIgnore = true;
|
||||
IMenuPanel *display = g_Menus.RenderMenu(client, states, order);
|
||||
if (!display)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] RedoClientMenu(): Failed to render menu");
|
||||
logger->LogMessage("[SM_MENU] RedoClientMenu(): Failed to render menu");
|
||||
#endif
|
||||
if (player->menuHoldTime)
|
||||
{
|
||||
@@ -598,7 +603,7 @@ bool BaseMenuStyle::RedoClientMenu(int client, ItemOrder order)
|
||||
player->bAutoIgnore = false;
|
||||
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] RedoClientMenu(): Succeeded to client %d", client);
|
||||
logger->LogMessage("[SM_MENU] RedoClientMenu(): Succeeded to client %d", client);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
@@ -628,49 +633,49 @@ Handle_t CBaseMenu::GetHandle()
|
||||
bool CBaseMenu::AppendItem(const char *info, const ItemDrawInfo &draw)
|
||||
{
|
||||
if (m_Pagination == (unsigned)MENU_NO_PAGINATION
|
||||
&& m_items.length() >= m_pStyle->GetMaxPageItems())
|
||||
&& m_items.size() >= m_pStyle->GetMaxPageItems())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CItem item;
|
||||
CItem item(m_items.size());
|
||||
|
||||
item.info = info;
|
||||
if (draw.display)
|
||||
item.display = new ke::AString(draw.display);
|
||||
item.display = std::make_unique<std::string>(draw.display);
|
||||
item.style = draw.style;
|
||||
|
||||
m_items.append(ke::Move(item));
|
||||
m_items.push_back(std::move(item));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBaseMenu::InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw)
|
||||
{
|
||||
if (m_Pagination == (unsigned)MENU_NO_PAGINATION &&
|
||||
m_items.length() >= m_pStyle->GetMaxPageItems())
|
||||
m_items.size() >= m_pStyle->GetMaxPageItems())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (position >= m_items.length())
|
||||
if (position >= m_items.size())
|
||||
return false;
|
||||
|
||||
CItem item;
|
||||
CItem item(position);
|
||||
item.info = info;
|
||||
if (draw.display)
|
||||
item.display = new ke::AString(draw.display);
|
||||
item.display = std::make_unique<std::string>(draw.display);
|
||||
item.style = draw.style;
|
||||
|
||||
m_items.insert(position, ke::Move(item));
|
||||
m_items.emplace(m_items.begin() + position, std::move(item));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBaseMenu::RemoveItem(unsigned int position)
|
||||
{
|
||||
if (position >= m_items.length())
|
||||
if (position >= m_items.size())
|
||||
return false;
|
||||
|
||||
m_items.remove(position);
|
||||
m_items.erase(m_items.begin() + position);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -679,23 +684,84 @@ void CBaseMenu::RemoveAllItems()
|
||||
m_items.clear();
|
||||
}
|
||||
|
||||
const char *CBaseMenu::GetItemInfo(unsigned int position, ItemDrawInfo *draw/* =NULL */)
|
||||
const char *CBaseMenu::GetItemInfo(unsigned int position, ItemDrawInfo *draw/* =NULL */, int client/* =0 */)
|
||||
{
|
||||
if (position >= m_items.length())
|
||||
if (position >= m_items.size())
|
||||
return NULL;
|
||||
|
||||
if (client > 0 && position < m_RandomMaps[client].size())
|
||||
{
|
||||
position = m_RandomMaps[client][position];
|
||||
}
|
||||
|
||||
if (draw)
|
||||
{
|
||||
draw->display = m_items[position].display->chars();
|
||||
draw->display = m_items[position].display->c_str();
|
||||
draw->style = m_items[position].style;
|
||||
}
|
||||
|
||||
return m_items[position].info.chars();
|
||||
return m_items[position].info.c_str();
|
||||
}
|
||||
|
||||
void CBaseMenu::ShufflePerClient(int start, int stop)
|
||||
{
|
||||
// limit map len to 255 items since it's using uint8
|
||||
int length = MIN(GetItemCount(), 255);
|
||||
if (stop >= 0)
|
||||
length = MIN(length, stop);
|
||||
|
||||
for (int i = 1; i <= SM_MAXPLAYERS; i++)
|
||||
{
|
||||
// populate per-client map ...
|
||||
m_RandomMaps[i].resize(length);
|
||||
for (int j = 0; j < length; j++)
|
||||
m_RandomMaps[i][j] = j;
|
||||
|
||||
// ... and random shuffle it
|
||||
for (int j = length - 1; j > start; j--)
|
||||
{
|
||||
int x = rand() % (j - start + 1) + start;
|
||||
uint8_t tmp = m_RandomMaps[i][x];
|
||||
m_RandomMaps[i][x] = m_RandomMaps[i][j];
|
||||
m_RandomMaps[i][j] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CBaseMenu::SetClientMapping(int client, int *array, int length)
|
||||
{
|
||||
length = MIN(length, 255);
|
||||
m_RandomMaps[client].resize(length);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
m_RandomMaps[client][i] = array[i];
|
||||
}
|
||||
}
|
||||
|
||||
bool CBaseMenu::IsPerClientShuffled()
|
||||
{
|
||||
for (int i = 1; i <= SM_MAXPLAYERS; i++)
|
||||
{
|
||||
if(m_RandomMaps[i].size() > 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int CBaseMenu::GetRealItemIndex(int client, unsigned int position)
|
||||
{
|
||||
if (client > 0 && position < m_RandomMaps[client].size())
|
||||
{
|
||||
position = m_RandomMaps[client][position];
|
||||
return m_items[position].index;
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
unsigned int CBaseMenu::GetItemCount()
|
||||
{
|
||||
return m_items.length();
|
||||
return m_items.size();
|
||||
}
|
||||
|
||||
bool CBaseMenu::SetPagination(unsigned int itemsPerPage)
|
||||
@@ -733,7 +799,7 @@ void CBaseMenu::SetDefaultTitle(const char *message)
|
||||
|
||||
const char *CBaseMenu::GetDefaultTitle()
|
||||
{
|
||||
return m_Title.chars();
|
||||
return m_Title.c_str();
|
||||
}
|
||||
|
||||
void CBaseMenu::Cancel()
|
||||
@@ -744,7 +810,7 @@ void CBaseMenu::Cancel()
|
||||
}
|
||||
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] CBaseMenu::Cancel(%p) (m_bShouldDelete %d)",
|
||||
logger->LogMessage("[SM_MENU] CBaseMenu::Cancel(%p) (m_bShouldDelete %d)",
|
||||
this,
|
||||
m_bShouldDelete);
|
||||
#endif
|
||||
@@ -768,7 +834,7 @@ void CBaseMenu::Destroy(bool releaseHandle)
|
||||
}
|
||||
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] CBaseMenu::Destroy(%p) (release %d) (m_bCancelling %d) (m_bShouldDelete %d)",
|
||||
logger->LogMessage("[SM_MENU] CBaseMenu::Destroy(%p) (release %d) (m_bCancelling %d) (m_bShouldDelete %d)",
|
||||
this,
|
||||
releaseHandle,
|
||||
m_bCancelling,
|
||||
@@ -825,5 +891,5 @@ IMenuHandler *CBaseMenu::GetHandler()
|
||||
|
||||
unsigned int CBaseMenu::GetBaseMemUsage()
|
||||
{
|
||||
return m_Title.length() + (m_items.length() * sizeof(CItem));
|
||||
return m_Title.size() + (m_items.size() * sizeof(CItem));
|
||||
}
|
||||
|
||||
+22
-10
@@ -32,6 +32,9 @@
|
||||
#ifndef _INCLUDE_MENUSTYLE_BASE_H
|
||||
#define _INCLUDE_MENUSTYLE_BASE_H
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <IMenuManager.h>
|
||||
#include <IPlayerHelpers.h>
|
||||
#include <am-string.h>
|
||||
@@ -43,30 +46,34 @@ using namespace SourceMod;
|
||||
class CItem
|
||||
{
|
||||
public:
|
||||
CItem()
|
||||
CItem(unsigned int index)
|
||||
{
|
||||
this->index = index;
|
||||
style = 0;
|
||||
access = 0;
|
||||
}
|
||||
CItem(CItem &&other)
|
||||
: info(ke::Move(other.info)),
|
||||
display(ke::Move(other.display))
|
||||
: info(std::move(other.info)),
|
||||
display(std::move(other.display))
|
||||
{
|
||||
index = other.index;
|
||||
style = other.style;
|
||||
access = other.access;
|
||||
}
|
||||
CItem & operator =(CItem &&other)
|
||||
{
|
||||
info = ke::Move(other.info);
|
||||
display = ke::Move(other.display);
|
||||
index = other.index;
|
||||
info = std::move(other.info);
|
||||
display = std::move(other.display);
|
||||
style = other.style;
|
||||
access = other.access;
|
||||
return *this;
|
||||
}
|
||||
|
||||
public:
|
||||
ke::AString info;
|
||||
ke::AutoPtr<ke::AString> display;
|
||||
unsigned int index;
|
||||
std::string info;
|
||||
std::unique_ptr<std::string> display;
|
||||
unsigned int style;
|
||||
unsigned int access;
|
||||
|
||||
@@ -137,7 +144,7 @@ public:
|
||||
virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw);
|
||||
virtual bool RemoveItem(unsigned int position);
|
||||
virtual void RemoveAllItems();
|
||||
virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw=NULL);
|
||||
virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw=NULL, int client=0);
|
||||
virtual unsigned int GetItemCount();
|
||||
virtual bool SetPagination(unsigned int itemsPerPage);
|
||||
virtual unsigned int GetPagination();
|
||||
@@ -151,14 +158,18 @@ public:
|
||||
virtual unsigned int GetMenuOptionFlags();
|
||||
virtual void SetMenuOptionFlags(unsigned int flags);
|
||||
virtual IMenuHandler *GetHandler();
|
||||
virtual void ShufflePerClient(int start, int stop);
|
||||
virtual void SetClientMapping(int client, int *array, int length);
|
||||
virtual bool IsPerClientShuffled();
|
||||
virtual unsigned int GetRealItemIndex(int client, unsigned int position);
|
||||
unsigned int GetBaseMemUsage();
|
||||
private:
|
||||
void InternalDelete();
|
||||
protected:
|
||||
ke::AString m_Title;
|
||||
std::string m_Title;
|
||||
IMenuStyle *m_pStyle;
|
||||
unsigned int m_Pagination;
|
||||
ke::Vector<CItem> m_items;
|
||||
std::vector<CItem> m_items;
|
||||
bool m_bShouldDelete;
|
||||
bool m_bCancelling;
|
||||
IdentityToken_t *m_pOwner;
|
||||
@@ -167,6 +178,7 @@ protected:
|
||||
Handle_t m_hHandle;
|
||||
IMenuHandler *m_pHandler;
|
||||
unsigned int m_nFlags;
|
||||
std::vector<uint8_t> m_RandomMaps[SM_MAXPLAYERS+1];
|
||||
};
|
||||
|
||||
#endif //_INCLUDE_MENUSTYLE_BASE_H
|
||||
|
||||
+42
-12
@@ -35,7 +35,7 @@
|
||||
#include <IGameConfigs.h>
|
||||
#include "PlayerManager.h"
|
||||
#if defined MENU_DEBUG
|
||||
#include "Logger.h"
|
||||
#include <bridge/include/ILogger.h>
|
||||
#endif
|
||||
#include "logic_bridge.h"
|
||||
|
||||
@@ -45,6 +45,12 @@
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#include <game/shared/csgo/protobuf/cstrike15_usermessages.pb.h>
|
||||
#elif SOURCE_ENGINE == SE_BLADE
|
||||
#include <game/shared/berimbau/protobuf/berimbau_usermessages.pb.h>
|
||||
#elif SOURCE_ENGINE == SE_MCV
|
||||
#include <game/shared/vietnam/protobuf/vietnam_usermessages.pb.h>
|
||||
#elif SOURCE_ENGINE == SE_OUTBREAK
|
||||
#include <game/shared/protobuf/base_usermessages.pb.h>
|
||||
#endif
|
||||
|
||||
extern const char *g_RadioNumTable[];
|
||||
@@ -59,7 +65,7 @@ unsigned int g_RadioMenuTimeout = 0;
|
||||
#define MAX_MENUSLOT_KEYS 10
|
||||
|
||||
static unsigned int s_RadioMaxPageItems = MAX_MENUSLOT_KEYS;
|
||||
|
||||
static bool s_RadioClosesOnInvalidSlot = false;
|
||||
|
||||
CRadioStyle::CRadioStyle()
|
||||
{
|
||||
@@ -122,6 +128,12 @@ void CRadioStyle::OnSourceModLevelChange(const char *mapName)
|
||||
}
|
||||
}
|
||||
|
||||
const char *closes = g_pGameConf->GetKeyValue("RadioMenuClosesOnInvalidSlot");
|
||||
if (closes != nullptr && strcmp(closes, "yes") == 0)
|
||||
{
|
||||
s_RadioClosesOnInvalidSlot = true;
|
||||
}
|
||||
|
||||
g_Menus.SetDefaultStyle(this);
|
||||
|
||||
g_UserMsgs.HookUserMessage(g_ShowMenuId, this, false);
|
||||
@@ -134,7 +146,7 @@ void CRadioStyle::OnSourceModShutdown()
|
||||
|
||||
while (!m_FreeDisplays.empty())
|
||||
{
|
||||
delete m_FreeDisplays.front();
|
||||
delete m_FreeDisplays.top();
|
||||
m_FreeDisplays.pop();
|
||||
}
|
||||
}
|
||||
@@ -174,8 +186,10 @@ void CRadioStyle::OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFil
|
||||
{
|
||||
int count = pFilter->GetRecipientCount();
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV
|
||||
int c = ((CCSUsrMsg_ShowMenu &)msg).display_time();
|
||||
#elif SOURCE_ENGINE == SE_OUTBREAK
|
||||
int c = ((CUsrMsg_ShowMenu &)msg).display_time();
|
||||
#else
|
||||
bf_read br(bf->GetBasePointer(), 3);
|
||||
|
||||
@@ -197,7 +211,7 @@ void CRadioStyle::OnUserMessageSent(int msg_id)
|
||||
{
|
||||
int client = g_last_clients[i];
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] CRadioStyle got ShowMenu (client %d) (bInMenu %d)",
|
||||
logger->LogMessage("[SM_MENU] CRadioStyle got ShowMenu (client %d) (bInMenu %d)",
|
||||
client,
|
||||
m_players[client].bInExternMenu);
|
||||
#endif
|
||||
@@ -251,7 +265,7 @@ CRadioDisplay *CRadioStyle::MakeRadioDisplay(CRadioMenu *menu)
|
||||
}
|
||||
else
|
||||
{
|
||||
display = m_FreeDisplays.front();
|
||||
display = m_FreeDisplays.top();
|
||||
m_FreeDisplays.pop();
|
||||
display->Reset();
|
||||
}
|
||||
@@ -458,12 +472,20 @@ void CRadioMenuPlayer::Radio_Init(int keys, const char *title, const char *text)
|
||||
}
|
||||
else
|
||||
{
|
||||
display_len = ke::SafeSprintf(display_pkt,
|
||||
display_len = ke::SafeStrcpy(display_pkt,
|
||||
sizeof(display_pkt),
|
||||
"%s",
|
||||
text);
|
||||
}
|
||||
display_keys = keys;
|
||||
|
||||
// Some games have implemented CHudMenu::SelectMenuItem to close the menu
|
||||
// even if an invalid slot has been selected, which causes us a problem as
|
||||
// we'll never get any notification from the client and we'll keep the menu
|
||||
// alive on our end indefinitely. For these games, pretend that every slot
|
||||
// is valid for selection so we're guaranteed to get a menuselect command.
|
||||
// We don't want to do this for every game as the common SelectMenuItem
|
||||
// implementation ignores invalid selections and keeps the menu open, which
|
||||
// is a much nicer user experience.
|
||||
display_keys = s_RadioClosesOnInvalidSlot ? 0x7ff : keys;
|
||||
}
|
||||
|
||||
void CRadioMenuPlayer::Radio_Refresh()
|
||||
@@ -484,9 +506,17 @@ void CRadioMenuPlayer::Radio_Refresh()
|
||||
time = menuHoldTime - (unsigned int)(gpGlobals->curtime - menuStartTime);
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
// TODO: find what happens past 240 on CS:GO
|
||||
CCSUsrMsg_ShowMenu *msg = (CCSUsrMsg_ShowMenu *)g_UserMsgs.StartProtobufMessage(g_ShowMenuId, players, 1, USERMSG_BLOCKHOOKS);
|
||||
#if SOURCE_ENGINE == SE_OUTBREAK
|
||||
CUsrMsg_ShowMenu *msg = (CUsrMsg_ShowMenu *)g_UserMsgs.StartProtobufMessage(g_ShowMenuId, players, 1, USERMSG_BLOCKHOOKS);
|
||||
#else
|
||||
CCSUsrMsg_ShowMenu *msg = (CCSUsrMsg_ShowMenu *)g_UserMsgs.StartProtobufMessage(g_ShowMenuId, players, 1, USERMSG_BLOCKHOOKS);
|
||||
#endif
|
||||
if (!msg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
msg->set_bits_valid_slots(display_keys);
|
||||
msg->set_display_time(time);
|
||||
msg->set_menu_string(ptr);
|
||||
@@ -577,7 +607,7 @@ bool CRadioMenu::DisplayAtItem(int client,
|
||||
IMenuHandler *alt_handler)
|
||||
{
|
||||
#if defined MENU_DEBUG
|
||||
g_Logger.LogMessage("[SM_MENU] CRadioMenu::Display(%p) (client %d) (time %d)",
|
||||
logger->LogMessage("[SM_MENU] CRadioMenu::Display(%p) (client %d) (time %d)",
|
||||
this,
|
||||
client,
|
||||
time);
|
||||
|
||||
@@ -39,7 +39,8 @@
|
||||
#include <IPlayerHelpers.h>
|
||||
#include "UserMessages.h"
|
||||
#include "sm_fastlink.h"
|
||||
#include <sh_stack.h>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <compat_wrappers.h>
|
||||
#include "logic/common_logic.h"
|
||||
#include "AutoHandleRooter.h"
|
||||
@@ -105,7 +106,7 @@ public:
|
||||
CRadioMenuPlayer *GetRadioMenuPlayer(int client);
|
||||
private:
|
||||
CRadioMenuPlayer *m_players;
|
||||
CStack<CRadioDisplay *> m_FreeDisplays;
|
||||
std::stack<CRadioDisplay *> m_FreeDisplays;
|
||||
};
|
||||
|
||||
class CRadioDisplay : public IMenuPanel
|
||||
@@ -132,8 +133,8 @@ public: //IMenuPanel
|
||||
unsigned int GetApproxMemUsage();
|
||||
bool DirectSet(const char *str);
|
||||
private:
|
||||
String m_BufferText;
|
||||
String m_Title;
|
||||
std::string m_BufferText;
|
||||
std::string m_Title;
|
||||
unsigned int m_NextPos;
|
||||
int keys;
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ SH_DECL_HOOK4_void(IServerPluginHelpers, CreateMessage, SH_NOATTRIB, false, edic
|
||||
ValveMenuStyle g_ValveMenuStyle;
|
||||
extern const char *g_OptionNumTable[];
|
||||
extern const char *g_OptionCmdTable[];
|
||||
CallClass<IServerPluginHelpers> *g_pSPHCC = NULL;
|
||||
SourceHook::CallClass<IServerPluginHelpers> *g_pSPHCC = NULL;
|
||||
|
||||
ValveMenuStyle::ValveMenuStyle() : m_players(new CValveMenuPlayer[256+1])
|
||||
{
|
||||
|
||||
+30
-5
@@ -41,6 +41,7 @@
|
||||
#include <const.h>
|
||||
#include <ITranslator.h>
|
||||
#include "logic_bridge.h"
|
||||
#include "AutoHandleRooter.h"
|
||||
|
||||
float g_next_vote = 0.0f;
|
||||
|
||||
@@ -171,6 +172,12 @@ void VoteMenuHandler::OnClientDisconnected(int client)
|
||||
assert((unsigned)item < m_Items);
|
||||
assert(m_Votes[item] > 0);
|
||||
m_Votes[item]--;
|
||||
|
||||
if (sm_vote_hintbox.GetBool())
|
||||
{
|
||||
BuildVoteLeaders();
|
||||
DrawHintProgress();
|
||||
}
|
||||
}
|
||||
m_ClientVotes[client] = VOTE_NOT_VOTING;
|
||||
}
|
||||
@@ -273,6 +280,12 @@ bool VoteMenuHandler::RedrawToClient(int client, bool revotes)
|
||||
m_ClientVotes[client] = VOTE_PENDING;
|
||||
m_Revoting[client] = true;
|
||||
m_NumVotes--;
|
||||
|
||||
if (sm_vote_hintbox.GetBool())
|
||||
{
|
||||
BuildVoteLeaders();
|
||||
DrawHintProgress();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_nMenuTime == MENU_TIME_FOREVER)
|
||||
@@ -351,7 +364,14 @@ void VoteMenuHandler::StartVoting()
|
||||
|
||||
m_bStarted = true;
|
||||
|
||||
m_pHandler->OnMenuVoteStart(m_pCurMenu);
|
||||
IBaseMenu *menu = m_pCurMenu;
|
||||
AutoHandleRooter ahr(menu->GetHandle());
|
||||
m_pHandler->OnMenuVoteStart(menu);
|
||||
|
||||
if (!m_bStarted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_displayTimer = g_Timers.CreateTimer(this, 1.0, NULL, TIMER_FLAG_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
|
||||
@@ -414,6 +434,7 @@ void VoteMenuHandler::EndVoting()
|
||||
IBaseMenu *menu = m_pCurMenu;
|
||||
IMenuHandler *handler = m_pHandler;
|
||||
InternalReset();
|
||||
AutoHandleRooter ahr(menu ? menu->GetHandle() : BAD_HANDLE);
|
||||
handler->OnMenuVoteCancel(menu, VoteCancel_Generic);
|
||||
handler->OnMenuEnd(menu, MenuEnd_VotingCancelled);
|
||||
return;
|
||||
@@ -443,6 +464,7 @@ void VoteMenuHandler::EndVoting()
|
||||
IBaseMenu *menu = m_pCurMenu;
|
||||
IMenuHandler *handler = m_pHandler;
|
||||
InternalReset();
|
||||
AutoHandleRooter ahr(menu ? menu->GetHandle() : BAD_HANDLE);
|
||||
handler->OnMenuVoteCancel(menu, VoteCancel_NoVotes);
|
||||
handler->OnMenuEnd(menu, MenuEnd_VotingCancelled);
|
||||
return;
|
||||
@@ -474,6 +496,7 @@ void VoteMenuHandler::EndVoting()
|
||||
InternalReset();
|
||||
|
||||
/* Send vote info */
|
||||
AutoHandleRooter ahr(menu ? menu->GetHandle() : BAD_HANDLE);
|
||||
handler->OnMenuVoteResults(menu, &vote);
|
||||
handler->OnMenuEnd(menu, MenuEnd_VotingDone);
|
||||
}
|
||||
@@ -514,15 +537,16 @@ void VoteMenuHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int ite
|
||||
/* Check by our item count, NOT the vote array size */
|
||||
if (item < m_Items)
|
||||
{
|
||||
m_ClientVotes[client] = item;
|
||||
m_Votes[item]++;
|
||||
unsigned int index = menu->GetRealItemIndex(client, item);
|
||||
m_ClientVotes[client] = index;
|
||||
m_Votes[index]++;
|
||||
m_NumVotes++;
|
||||
|
||||
if (sm_vote_chat.GetBool() || sm_vote_console.GetBool() || sm_vote_client_console.GetBool())
|
||||
{
|
||||
static char buffer[1024];
|
||||
ItemDrawInfo dr;
|
||||
menu->GetItemInfo(item, &dr);
|
||||
menu->GetItemInfo(item, &dr, client);
|
||||
|
||||
if (sm_vote_console.GetBool())
|
||||
{
|
||||
@@ -560,7 +584,7 @@ void VoteMenuHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int ite
|
||||
|
||||
if (sm_vote_client_console.GetBool())
|
||||
{
|
||||
ClientConsolePrint(pPlayer->GetEdict(), buffer);
|
||||
ClientConsolePrint(pPlayer->GetEdict(), "%s", buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -649,6 +673,7 @@ void VoteMenuHandler::BuildVoteLeaders()
|
||||
{
|
||||
if (m_NumVotes == 0 || !sm_vote_hintbox.GetBool())
|
||||
{
|
||||
m_leaderList[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -34,11 +34,10 @@
|
||||
|
||||
#include <IMenuManager.h>
|
||||
#include <IPlayerHelpers.h>
|
||||
#include <sh_vector.h>
|
||||
#include <vector>
|
||||
#include "sm_globals.h"
|
||||
#include <TimerSys.h>
|
||||
|
||||
using namespace SourceHook;
|
||||
using namespace SourceMod;
|
||||
|
||||
class VoteMenuHandler :
|
||||
@@ -97,7 +96,7 @@ private:
|
||||
unsigned int m_Clients;
|
||||
unsigned int m_TotalClients;
|
||||
unsigned int m_Items;
|
||||
CVector<unsigned int> m_Votes;
|
||||
std::vector<unsigned int> m_Votes;
|
||||
IBaseMenu *m_pCurMenu;
|
||||
bool m_bStarted;
|
||||
bool m_bCancelled;
|
||||
|
||||
+30
-20
@@ -63,11 +63,7 @@ bool g_forcedChange = false;
|
||||
|
||||
void NextMapManager::OnSourceModAllInitialized_Post()
|
||||
{
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
SH_ADD_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false);
|
||||
#else
|
||||
SH_ADD_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false);
|
||||
#endif
|
||||
|
||||
ConCommand *pCmd = FindCommand("changelevel");
|
||||
if (pCmd != NULL)
|
||||
@@ -79,19 +75,14 @@ void NextMapManager::OnSourceModAllInitialized_Post()
|
||||
|
||||
void NextMapManager::OnSourceModShutdown()
|
||||
{
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
SH_REMOVE_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false);
|
||||
#else
|
||||
SH_REMOVE_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false);
|
||||
#endif
|
||||
|
||||
if (changeLevelCmd != NULL)
|
||||
{
|
||||
SH_REMOVE_HOOK(ConCommand, Dispatch, changeLevelCmd, SH_STATIC(CmdChangeLevelCallback), false);
|
||||
}
|
||||
|
||||
SourceHook::List<MapChangeData *>::iterator iter;
|
||||
iter = m_mapHistory.begin();
|
||||
auto iter = m_mapHistory.begin();
|
||||
|
||||
while (iter != m_mapHistory.end())
|
||||
{
|
||||
@@ -117,6 +108,8 @@ bool NextMapManager::SetNextMap(const char *map)
|
||||
return true;
|
||||
}
|
||||
|
||||
static char g_nextMap[PLATFORM_MAX_PATH];
|
||||
|
||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||
void NextMapManager::HookChangeLevel(const char *map, const char *unknown)
|
||||
#else
|
||||
@@ -130,16 +123,24 @@ void NextMapManager::HookChangeLevel(const char *map, const char *unknown, const
|
||||
}
|
||||
|
||||
const char *newmap = sm_nextmap.GetString();
|
||||
if (newmap[0] != '\0') {
|
||||
ke::SafeStrcpy(g_nextMap, sizeof(g_nextMap), newmap);
|
||||
newmap = g_nextMap;
|
||||
|
||||
if (newmap[0] == 0 || !g_HL2.IsMapValid(newmap))
|
||||
// Clear the value so that if the map load fails later we don't get stuck in a loop.
|
||||
// This might cause us to go off-cycle for a map, but nextmap will get us back on track.
|
||||
sm_nextmap.SetValue("");
|
||||
}
|
||||
|
||||
if (newmap[0] == '\0' || !g_HL2.IsMapValid(newmap))
|
||||
{
|
||||
RETURN_META(MRES_IGNORED);
|
||||
}
|
||||
|
||||
logger->LogMessage("[SM] Changed map to \"%s\"", newmap);
|
||||
|
||||
ke::SafeSprintf(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), newmap);
|
||||
ke::SafeSprintf(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "Normal level change");
|
||||
ke::SafeStrcpy(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), newmap);
|
||||
ke::SafeStrcpy(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "Normal level change");
|
||||
|
||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||
RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::ChangeLevel, (newmap, unknown));
|
||||
@@ -150,6 +151,15 @@ void NextMapManager::HookChangeLevel(const char *map, const char *unknown, const
|
||||
|
||||
void NextMapManager::OnSourceModLevelChange( const char *mapName )
|
||||
{
|
||||
// If we were controlling the map change, reset sm_nextmap to be the name of the map we successfully changed to.
|
||||
// This maintains an old API contract on the plugin side. We use the real map name even if it was different from
|
||||
// the expected map name as if the expected map failed to load we let the game take over instead, but the nextmap
|
||||
// plugin compares the sm_nextmap value to the current map to decide if it should advance the mapcycle.
|
||||
if (g_nextMap[0] != '\0') {
|
||||
sm_nextmap.SetValue(mapName);
|
||||
g_nextMap[0] = '\0';
|
||||
}
|
||||
|
||||
/* Skip the first 'mapchange' when the server starts up */
|
||||
if (m_tempChangeInfo.startTime != 0)
|
||||
{
|
||||
@@ -175,7 +185,7 @@ void NextMapManager::OnSourceModLevelChange( const char *mapName )
|
||||
historydiff = (m_mapHistory.size() * -1);
|
||||
}
|
||||
|
||||
for (SourceHook::List<MapChangeData *>::iterator iter = m_mapHistory.begin(); historydiff++ < 0; iter = m_mapHistory.erase(iter))
|
||||
for (auto iter = m_mapHistory.begin(); historydiff++ < 0; iter = m_mapHistory.erase(iter))
|
||||
{
|
||||
delete (MapChangeData *)*iter;
|
||||
}
|
||||
@@ -184,14 +194,14 @@ void NextMapManager::OnSourceModLevelChange( const char *mapName )
|
||||
m_tempChangeInfo.m_mapName[0] ='\0';
|
||||
m_tempChangeInfo.m_changeReason[0] = '\0';
|
||||
m_tempChangeInfo.startTime = time(NULL);
|
||||
ke::SafeSprintf(lastMap, sizeof(lastMap), "%s", mapName);
|
||||
ke::SafeStrcpy(lastMap, sizeof(lastMap), mapName);
|
||||
}
|
||||
|
||||
void NextMapManager::ForceChangeLevel( const char *mapName, const char* changeReason )
|
||||
{
|
||||
/* Store the mapname and reason */
|
||||
ke::SafeSprintf(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), "%s", mapName);
|
||||
ke::SafeSprintf(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "%s", changeReason);
|
||||
ke::SafeStrcpy(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), mapName);
|
||||
ke::SafeStrcpy(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), changeReason);
|
||||
|
||||
/* Change level and skip our hook */
|
||||
g_forcedChange = true;
|
||||
@@ -202,7 +212,7 @@ void NextMapManager::ForceChangeLevel( const char *mapName, const char* changeRe
|
||||
NextMapManager::NextMapManager()
|
||||
{
|
||||
m_tempChangeInfo = MapChangeData();
|
||||
m_mapHistory = SourceHook::List<MapChangeData *>();
|
||||
m_mapHistory = std::list<MapChangeData *>();
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
@@ -221,7 +231,7 @@ void CmdChangeLevelCallback()
|
||||
|
||||
if (g_NextMap.m_tempChangeInfo.m_mapName[0] == '\0')
|
||||
{
|
||||
ke::SafeSprintf(g_NextMap.m_tempChangeInfo.m_mapName, sizeof(g_NextMap.m_tempChangeInfo.m_mapName), command.Arg(1));
|
||||
ke::SafeSprintf(g_NextMap.m_tempChangeInfo.m_changeReason, sizeof(g_NextMap.m_tempChangeInfo.m_changeReason), "changelevel Command");
|
||||
ke::SafeStrcpy(g_NextMap.m_tempChangeInfo.m_mapName, sizeof(g_NextMap.m_tempChangeInfo.m_mapName), command.Arg(1));
|
||||
ke::SafeStrcpy(g_NextMap.m_tempChangeInfo.m_changeReason, sizeof(g_NextMap.m_tempChangeInfo.m_changeReason), "changelevel Command");
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -34,7 +34,7 @@
|
||||
|
||||
#include "sm_globals.h"
|
||||
#include <eiface.h>
|
||||
#include "sh_list.h"
|
||||
#include <list>
|
||||
#include "sm_stringutil.h"
|
||||
#include <amtl/am-string.h>
|
||||
|
||||
@@ -92,11 +92,11 @@ public:
|
||||
#endif
|
||||
|
||||
public:
|
||||
SourceHook::List<MapChangeData *> m_mapHistory;
|
||||
std::list<MapChangeData *> m_mapHistory;
|
||||
|
||||
private:
|
||||
MapChangeData m_tempChangeInfo;
|
||||
char lastMap[32];
|
||||
char lastMap[PLATFORM_MAX_PATH];
|
||||
};
|
||||
|
||||
extern NextMapManager g_NextMap;
|
||||
|
||||
+316
-192
File diff suppressed because it is too large
Load Diff
+34
-17
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* vim: set ts=4 sts=8 sw=4 tw=99 noet :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2015 AlliedModders LLC. All rights reserved.
|
||||
@@ -39,16 +39,15 @@
|
||||
#include <IPlayerHelpers.h>
|
||||
#include <IAdminSystem.h>
|
||||
#include <ITranslator.h>
|
||||
#include <sh_string.h>
|
||||
#include <sh_list.h>
|
||||
#include <sh_vector.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <am-string.h>
|
||||
#include <am-deque.h>
|
||||
#include "ConVarManager.h"
|
||||
|
||||
#include <steam/steamclientpublic.h>
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
class IClient;
|
||||
|
||||
#define PLAYER_LIFE_UNKNOWN 0
|
||||
@@ -95,6 +94,7 @@ public:
|
||||
bool IsInKickQueue();
|
||||
IPlayerInfo *GetPlayerInfo();
|
||||
unsigned int GetLanguageId();
|
||||
unsigned int GetOriginalLanguageId();
|
||||
void SetLanguageId(unsigned int id);
|
||||
int GetUserId();
|
||||
bool RunAdminCacheChecks();
|
||||
@@ -123,35 +123,38 @@ private:
|
||||
bool IsAuthStringValidated();
|
||||
bool SetEngineString();
|
||||
bool SetCSteamID();
|
||||
void ClearNetchannelQueue(void);
|
||||
private:
|
||||
bool m_IsConnected = false;
|
||||
bool m_IsInGame = false;
|
||||
bool m_IsAuthorized = false;
|
||||
bool m_bIsInKickQueue = false;
|
||||
String m_Name;
|
||||
String m_Ip;
|
||||
String m_IpNoPort;
|
||||
ke::AString m_AuthID;
|
||||
ke::AString m_Steam2Id;
|
||||
ke::AString m_Steam3Id;
|
||||
std::string m_Name;
|
||||
std::string m_Ip;
|
||||
std::string m_IpNoPort;
|
||||
std::string m_AuthID;
|
||||
std::string m_Steam2Id;
|
||||
std::string m_Steam3Id;
|
||||
AdminId m_Admin = INVALID_ADMIN_ID;
|
||||
bool m_TempAdmin = false;
|
||||
edict_t *m_pEdict = nullptr;
|
||||
IPlayerInfo *m_Info = nullptr;
|
||||
IClient *m_pIClient = nullptr;
|
||||
String m_LastPassword;
|
||||
std::string m_LastPassword;
|
||||
bool m_bAdminCheckSignalled = false;
|
||||
int m_iIndex;
|
||||
unsigned int m_LangId = SOURCEMOD_LANGUAGE_ENGLISH;
|
||||
unsigned int m_OriginalLangId = SOURCEMOD_LANGUAGE_ENGLISH;
|
||||
int m_UserId = -1;
|
||||
bool m_bFakeClient = false;
|
||||
bool m_bIsSourceTV = false;
|
||||
bool m_bIsReplay = false;
|
||||
serial_t m_Serial;
|
||||
CSteamID m_SteamId;
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
QueryCvarCookie_t m_LanguageCookie = InvalidQueryCvarCookie;
|
||||
#endif
|
||||
std::deque<std::string> m_PrintfBuffer;
|
||||
};
|
||||
|
||||
class PlayerManager :
|
||||
@@ -189,7 +192,17 @@ public:
|
||||
#endif
|
||||
void OnClientSettingsChanged(edict_t *pEntity);
|
||||
//void OnClientSettingsChanged_Pre(edict_t *pEntity);
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX && SOURCE_ENGINE != SE_MOCK
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
void OnNetworkIDValidated(const char *pszUserName, const char *pszNetworkID, CSteamID steamID);
|
||||
#else
|
||||
void OnNetworkIDValidated(const char *pszUserName, const char *pszNetworkID);
|
||||
#endif
|
||||
#endif
|
||||
void OnClientLanguageChanged(int client, unsigned int language);
|
||||
void OnServerHibernationUpdate(bool bHibernating);
|
||||
void OnClientPrintf(edict_t *pEdict, const char *szMsg);
|
||||
void OnPrintfFrameAction(unsigned int serial);
|
||||
public: //IPlayerManager
|
||||
void AddClientListener(IClientListener *listener);
|
||||
void RemoveClientListener(IClientListener *listener);
|
||||
@@ -230,14 +243,14 @@ public:
|
||||
{
|
||||
return m_bInCCKVHook;
|
||||
}
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
bool HandleConVarQuery(QueryCvarCookie_t cookie, int client, EQueryCvarValueStatus result, const char *cvarName, const char *cvarValue);
|
||||
#endif
|
||||
private:
|
||||
void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
|
||||
void InvalidatePlayer(CPlayer *pPlayer);
|
||||
private:
|
||||
List<IClientListener *> m_hooks;
|
||||
std::list<IClientListener *> m_hooks;
|
||||
IForward *m_clconnect;
|
||||
IForward *m_clconnect_post;
|
||||
IForward *m_cldisconnect;
|
||||
@@ -248,6 +261,7 @@ private:
|
||||
IForward *m_clcommandkv_post;
|
||||
IForward *m_clinfochanged;
|
||||
IForward *m_clauth;
|
||||
IForward *m_cllang;
|
||||
IForward *m_onActivate;
|
||||
IForward *m_onActivate2;
|
||||
CPlayer *m_Players;
|
||||
@@ -257,7 +271,7 @@ private:
|
||||
int m_PlayersSinceActive;
|
||||
bool m_bServerActivated;
|
||||
unsigned int *m_AuthQueue;
|
||||
String m_PassInfoVar;
|
||||
std::string m_PassInfoVar;
|
||||
bool m_QueryLang;
|
||||
bool m_bAuthstringValidation; // are we validating admins with steam before authorizing?
|
||||
bool m_bIsListenServer;
|
||||
@@ -267,6 +281,9 @@ private:
|
||||
int m_SourceTVUserId;
|
||||
int m_ReplayUserId;
|
||||
bool m_bInCCKVHook;
|
||||
private:
|
||||
static const int NETMSG_TYPE_BITS = 5; // SVC_Print overhead for netmsg type
|
||||
static const int SVC_Print_BufferSize = 2048 - 1; // -1 for terminating \0
|
||||
};
|
||||
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
|
||||
+95
-69
@@ -36,12 +36,12 @@
|
||||
#include "ConVarManager.h"
|
||||
#include "logic_bridge.h"
|
||||
|
||||
#define TIMER_MIN_ACCURACY 0.1
|
||||
#define TIMER_MIN_ACCURACY 0.1
|
||||
|
||||
TimerSystem g_Timers;
|
||||
double g_fUniversalTime = 0.0f;
|
||||
float g_fGameStartTime = 0.0f; /* Game game start time, non-universal */
|
||||
double g_fTimerThink = 0.0f; /* Timer's next think time */
|
||||
float g_fGameStartTime = 0.0f; /* Game game start time, non-universal */
|
||||
double g_fTimerThink = 0.0f; /* Timer's next think time */
|
||||
const double *g_pUniversalTime = &g_fUniversalTime;
|
||||
ConVar *mp_timelimit = NULL;
|
||||
int g_TimeLeftMode = 0;
|
||||
@@ -69,6 +69,13 @@ class DefaultMapTimer :
|
||||
public IConVarChangeListener
|
||||
{
|
||||
public:
|
||||
|
||||
#if SOURCE_ENGINE == SE_BMS
|
||||
static constexpr int kMapTimeScaleFactor = 60;
|
||||
#else
|
||||
static constexpr int kMapTimeScaleFactor = 1;
|
||||
#endif
|
||||
|
||||
DefaultMapTimer()
|
||||
{
|
||||
m_bInUse = false;
|
||||
@@ -81,7 +88,7 @@ public:
|
||||
|
||||
int GetMapTimeLimit()
|
||||
{
|
||||
return mp_timelimit->GetInt();
|
||||
return (mp_timelimit->GetInt() / kMapTimeScaleFactor);
|
||||
}
|
||||
|
||||
void SetMapTimerStatus(bool enabled)
|
||||
@@ -105,7 +112,7 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
extra_time /= 60;
|
||||
extra_time /= (60 / kMapTimeScaleFactor);
|
||||
|
||||
mp_timelimit->SetValue(mp_timelimit->GetInt() + extra_time);
|
||||
}
|
||||
@@ -139,9 +146,10 @@ private:
|
||||
*/
|
||||
inline double CalcNextThink(double last, float interval)
|
||||
{
|
||||
if (g_fUniversalTime - last - interval <= TIMER_MIN_ACCURACY)
|
||||
const double next = last + interval;
|
||||
if (g_fUniversalTime - next <= TIMER_MIN_ACCURACY)
|
||||
{
|
||||
return last + interval;
|
||||
return next;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -149,7 +157,7 @@ inline double CalcNextThink(double last, float interval)
|
||||
}
|
||||
}
|
||||
|
||||
void ITimer::Initialize(ITimedEvent *pCallbacks, float fInterval, float fToExec, void *pData, int flags)
|
||||
void ITimer::Initialize(ITimedEvent *pCallbacks, float fInterval, double fToExec, void *pData, int flags)
|
||||
{
|
||||
m_Listener = pCallbacks;
|
||||
m_Interval = fInterval;
|
||||
@@ -170,12 +178,11 @@ TimerSystem::TimerSystem()
|
||||
|
||||
TimerSystem::~TimerSystem()
|
||||
{
|
||||
CStack<ITimer *>::iterator iter;
|
||||
for (iter=m_FreeTimers.begin(); iter!=m_FreeTimers.end(); iter++)
|
||||
while (!m_FreeTimers.empty())
|
||||
{
|
||||
delete (*iter);
|
||||
delete m_FreeTimers.top();
|
||||
m_FreeTimers.pop();
|
||||
}
|
||||
m_FreeTimers.popall();
|
||||
}
|
||||
|
||||
void TimerSystem::OnSourceModAllInitialized()
|
||||
@@ -227,10 +234,11 @@ void TimerSystem::GameFrame(bool simulating)
|
||||
m_fLastTickedTime = gpGlobals->curtime;
|
||||
m_bHasMapTickedYet = true;
|
||||
|
||||
if (g_fUniversalTime >= g_fTimerThink)
|
||||
{
|
||||
RunFrame();
|
||||
const bool timerThink = g_fUniversalTime >= g_fTimerThink;
|
||||
RunFrame(timerThink);
|
||||
|
||||
if (timerThink)
|
||||
{
|
||||
g_fTimerThink = CalcNextThink(g_fTimerThink, TIMER_MIN_ACCURACY);
|
||||
}
|
||||
|
||||
@@ -242,31 +250,12 @@ void TimerSystem::GameFrame(bool simulating)
|
||||
}
|
||||
}
|
||||
|
||||
void TimerSystem::RunFrame()
|
||||
void TimerSystem::ProcessRepeatTimers(double curtime, std::list<ITimer*>& timerList)
|
||||
{
|
||||
ITimer *pTimer;
|
||||
TimerIter iter;
|
||||
ITimer *pTimer;
|
||||
|
||||
double curtime = GetSimulatedTime();
|
||||
for (iter=m_SingleTimers.begin(); iter!=m_SingleTimers.end(); )
|
||||
{
|
||||
pTimer = (*iter);
|
||||
if (curtime >= pTimer->m_ToExec)
|
||||
{
|
||||
pTimer->m_InExec = true;
|
||||
pTimer->m_Listener->OnTimer(pTimer, pTimer->m_pData);
|
||||
pTimer->m_Listener->OnTimerEnd(pTimer, pTimer->m_pData);
|
||||
iter = m_SingleTimers.erase(iter);
|
||||
m_FreeTimers.push(pTimer);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ResultType res;
|
||||
for (iter=m_LoopTimers.begin(); iter!=m_LoopTimers.end(); )
|
||||
ResultType res;
|
||||
for (auto iter=timerList.begin(); iter!=timerList.end(); )
|
||||
{
|
||||
pTimer = (*iter);
|
||||
if (curtime >= pTimer->m_ToExec)
|
||||
@@ -276,7 +265,7 @@ void TimerSystem::RunFrame()
|
||||
if (pTimer->m_KillMe || (res == Pl_Stop))
|
||||
{
|
||||
pTimer->m_Listener->OnTimerEnd(pTimer, pTimer->m_pData);
|
||||
iter = m_LoopTimers.erase(iter);
|
||||
iter = timerList.erase(iter);
|
||||
m_FreeTimers.push(pTimer);
|
||||
continue;
|
||||
}
|
||||
@@ -287,17 +276,57 @@ void TimerSystem::RunFrame()
|
||||
}
|
||||
}
|
||||
|
||||
void TimerSystem::RunFrame(bool timerThink)
|
||||
{
|
||||
const double curtime = GetSimulatedTime();
|
||||
|
||||
//// One-off timers
|
||||
ITimer *pTimer;
|
||||
for (auto iter=m_SingleTimers.begin(); iter!=m_SingleTimers.end(); )
|
||||
{
|
||||
pTimer = (*iter);
|
||||
|
||||
// m_SingleTimers is sorted
|
||||
if (curtime < pTimer->m_ToExec)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (timerThink || pTimer->m_Flags & TIMER_FLAG_TICK_PRECISE)
|
||||
{
|
||||
pTimer->m_InExec = true;
|
||||
pTimer->m_Listener->OnTimer(pTimer, pTimer->m_pData);
|
||||
pTimer->m_Listener->OnTimerEnd(pTimer, pTimer->m_pData);
|
||||
iter = m_SingleTimers.erase(iter);
|
||||
m_FreeTimers.push(pTimer);
|
||||
}
|
||||
else
|
||||
{
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
|
||||
//// Repeating timers
|
||||
// Most repeating timers do not need to be updated every frame
|
||||
if (timerThink)
|
||||
{
|
||||
ProcessRepeatTimers(curtime, m_LowSpeedLoopTimers);
|
||||
}
|
||||
|
||||
// High speed repeating timers will always update
|
||||
ProcessRepeatTimers(curtime, m_HighSpeedLoopTimers);
|
||||
}
|
||||
|
||||
ITimer *TimerSystem::CreateTimer(ITimedEvent *pCallbacks, float fInterval, void *pData, int flags)
|
||||
{
|
||||
ITimer *pTimer;
|
||||
TimerIter iter;
|
||||
float to_exec = GetSimulatedTime() + fInterval;
|
||||
const double to_exec = GetSimulatedTime() + fInterval;
|
||||
|
||||
if (m_FreeTimers.empty())
|
||||
{
|
||||
pTimer = new ITimer;
|
||||
} else {
|
||||
pTimer = m_FreeTimers.front();
|
||||
pTimer = m_FreeTimers.top();
|
||||
m_FreeTimers.pop();
|
||||
}
|
||||
|
||||
@@ -305,20 +334,21 @@ ITimer *TimerSystem::CreateTimer(ITimedEvent *pCallbacks, float fInterval, void
|
||||
|
||||
if (flags & TIMER_FLAG_REPEAT)
|
||||
{
|
||||
m_LoopTimers.push_back(pTimer);
|
||||
std::list<ITimer*>& timerList = pTimer->m_Flags & TIMER_FLAG_TICK_PRECISE ? m_HighSpeedLoopTimers : m_LowSpeedLoopTimers;
|
||||
timerList.push_back(pTimer);
|
||||
goto return_timer;
|
||||
}
|
||||
|
||||
if (m_SingleTimers.size() >= 1)
|
||||
{
|
||||
iter = --m_SingleTimers.end();
|
||||
auto iter = --m_SingleTimers.end();
|
||||
if ((*iter)->m_ToExec <= to_exec)
|
||||
{
|
||||
goto normal_insert_end;
|
||||
}
|
||||
}
|
||||
|
||||
for (iter=m_SingleTimers.begin(); iter!=m_SingleTimers.end(); iter++)
|
||||
for (auto iter=m_SingleTimers.begin(); iter!=m_SingleTimers.end(); iter++)
|
||||
{
|
||||
if ((*iter)->m_ToExec >= to_exec)
|
||||
{
|
||||
@@ -363,8 +393,10 @@ void TimerSystem::FireTimerOnce(ITimer *pTimer, bool delayExec)
|
||||
pTimer->m_InExec = false;
|
||||
return;
|
||||
}
|
||||
|
||||
std::list<ITimer*>& timerList = pTimer->m_Flags & TIMER_FLAG_TICK_PRECISE ? m_HighSpeedLoopTimers : m_LowSpeedLoopTimers;
|
||||
pTimer->m_Listener->OnTimerEnd(pTimer, pTimer->m_pData);
|
||||
m_LoopTimers.remove(pTimer);
|
||||
timerList.remove(pTimer);
|
||||
m_FreeTimers.push(pTimer);
|
||||
}
|
||||
}
|
||||
@@ -382,12 +414,13 @@ void TimerSystem::KillTimer(ITimer *pTimer)
|
||||
return;
|
||||
}
|
||||
|
||||
pTimer->m_InExec = true; /* The timer it's not really executed but this check needs to be done */
|
||||
pTimer->m_InExec = true; /* The timer is not really executed but this check needs to be done */
|
||||
pTimer->m_Listener->OnTimerEnd(pTimer, pTimer->m_pData);
|
||||
|
||||
if (pTimer->m_Flags & TIMER_FLAG_REPEAT)
|
||||
{
|
||||
m_LoopTimers.remove(pTimer);
|
||||
std::list<ITimer*>& timerList = pTimer->m_Flags & TIMER_FLAG_TICK_PRECISE ? m_HighSpeedLoopTimers : m_LowSpeedLoopTimers;
|
||||
timerList.remove(pTimer);
|
||||
} else {
|
||||
m_SingleTimers.remove(pTimer);
|
||||
}
|
||||
@@ -395,33 +428,27 @@ void TimerSystem::KillTimer(ITimer *pTimer)
|
||||
m_FreeTimers.push(pTimer);
|
||||
}
|
||||
|
||||
CStack<ITimer *> s_tokill;
|
||||
std::stack<ITimer *> s_tokill;
|
||||
void TimerSystem::RemoveMapChangeTimers()
|
||||
{
|
||||
ITimer *pTimer;
|
||||
TimerIter iter;
|
||||
const auto KillMapchangeTimers = [](std::list<ITimer*>& timerList) {
|
||||
for (ITimer* pTimer : timerList)
|
||||
{
|
||||
if (pTimer->m_Flags & TIMER_FLAG_NO_MAPCHANGE)
|
||||
{
|
||||
s_tokill.push(pTimer);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (iter=m_SingleTimers.begin(); iter!=m_SingleTimers.end(); iter++)
|
||||
{
|
||||
pTimer = (*iter);
|
||||
if (pTimer->m_Flags & TIMER_FLAG_NO_MAPCHANGE)
|
||||
{
|
||||
s_tokill.push(pTimer);
|
||||
}
|
||||
}
|
||||
KillMapchangeTimers(m_SingleTimers);
|
||||
|
||||
for (iter=m_LoopTimers.begin(); iter!=m_LoopTimers.end(); iter++)
|
||||
{
|
||||
pTimer = (*iter);
|
||||
if (pTimer->m_Flags & TIMER_FLAG_NO_MAPCHANGE)
|
||||
{
|
||||
s_tokill.push(pTimer);
|
||||
}
|
||||
}
|
||||
KillMapchangeTimers(m_LowSpeedLoopTimers);
|
||||
KillMapchangeTimers(m_HighSpeedLoopTimers);
|
||||
|
||||
while (!s_tokill.empty())
|
||||
{
|
||||
KillTimer(s_tokill.front());
|
||||
KillTimer(s_tokill.top());
|
||||
s_tokill.pop();
|
||||
}
|
||||
}
|
||||
@@ -484,4 +511,3 @@ bool TimerSystem::GetMapTimeLeft(float *time_left)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+10
-11
@@ -33,21 +33,17 @@
|
||||
#define _INCLUDE_SOURCEMOD_CTIMERSYS_H_
|
||||
|
||||
#include <ITimerSystem.h>
|
||||
#include <sh_stack.h>
|
||||
#include <sh_list.h>
|
||||
#include <stack>
|
||||
#include <list>
|
||||
#include "sourcemm_api.h"
|
||||
#include "sm_globals.h"
|
||||
|
||||
using namespace SourceHook;
|
||||
using namespace SourceMod;
|
||||
|
||||
typedef List<ITimer *> TimerList;
|
||||
typedef List<ITimer *>::iterator TimerIter;
|
||||
|
||||
class SourceMod::ITimer
|
||||
{
|
||||
public:
|
||||
void Initialize(ITimedEvent *pCallbacks, float fInterval, float fToExec, void *pData, int flags);
|
||||
void Initialize(ITimedEvent *pCallbacks, float fInterval, double fToExec, void *pData, int flags);
|
||||
ITimedEvent *m_Listener;
|
||||
void *m_pData;
|
||||
float m_Interval;
|
||||
@@ -80,13 +76,16 @@ public: //ITimerSystem
|
||||
bool GetMapTimeLeft(float *pTime);
|
||||
IMapTimer *GetMapTimer();
|
||||
public:
|
||||
void RunFrame();
|
||||
void RunFrame(bool timerThink);
|
||||
void RemoveMapChangeTimers();
|
||||
void GameFrame(bool simulating);
|
||||
private:
|
||||
List<ITimer *> m_SingleTimers;
|
||||
List<ITimer *> m_LoopTimers;
|
||||
CStack<ITimer *> m_FreeTimers;
|
||||
void ProcessRepeatTimers(double curtime, std::list<ITimer*>& timerList);
|
||||
private:
|
||||
std::list<ITimer*> m_SingleTimers;
|
||||
std::list<ITimer*> m_LowSpeedLoopTimers;
|
||||
std::list<ITimer*> m_HighSpeedLoopTimers;
|
||||
std::stack<ITimer *> m_FreeTimers;
|
||||
IMapTimer *m_pMapTimer;
|
||||
|
||||
/* This is stuff for our manual ticking escapades. */
|
||||
|
||||
+97
-22
@@ -32,6 +32,10 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_SMPBMESSAGE_H_
|
||||
#define _INCLUDE_SOURCEMOD_SMPBMESSAGE_H_
|
||||
|
||||
#ifdef GetMessage
|
||||
#undef GetMessage
|
||||
#endif
|
||||
|
||||
#include <sh_list.h>
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <amtl/am-string.h>
|
||||
@@ -85,7 +89,7 @@
|
||||
return false; \
|
||||
}
|
||||
|
||||
typedef List<Handle_t> PBHandleList;
|
||||
typedef std::list<Handle_t> PBHandleList;
|
||||
|
||||
class SMProtobufMessage
|
||||
{
|
||||
@@ -97,7 +101,7 @@ public:
|
||||
|
||||
~SMProtobufMessage()
|
||||
{
|
||||
PBHandleList::iterator iter = childHandles.begin();
|
||||
auto iter = childHandles.begin();
|
||||
while (iter != childHandles.end())
|
||||
{
|
||||
Handle_t &hndl = (*iter);
|
||||
@@ -118,6 +122,13 @@ public:
|
||||
return msg;
|
||||
}
|
||||
|
||||
inline bool HasField(const char *pszFieldName)
|
||||
{
|
||||
GETCHECK_FIELD();
|
||||
CHECK_FIELD_NOT_REPEATED();
|
||||
return msg->GetReflection()->HasField(*msg, field);
|
||||
}
|
||||
|
||||
inline bool GetInt32(const char *pszFieldName, int32 *out)
|
||||
{
|
||||
GETCHECK_FIELD();
|
||||
@@ -341,6 +352,20 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool GetInt64OrUnsigned(const char *pszFieldName, int64 *out)
|
||||
{
|
||||
GETCHECK_FIELD();
|
||||
CHECK_FIELD_TYPE2(INT64, UINT64);
|
||||
CHECK_FIELD_NOT_REPEATED();
|
||||
|
||||
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT64)
|
||||
*out = (int64)msg->GetReflection()->GetUInt64(*msg, field);
|
||||
else
|
||||
*out = msg->GetReflection()->GetInt64(*msg, field);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool SetInt32OrUnsignedOrEnum(const char *pszFieldName, int32 value)
|
||||
{
|
||||
@@ -367,6 +392,24 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool SetInt64OrUnsigned(const char *pszFieldName, int64 value)
|
||||
{
|
||||
GETCHECK_FIELD();
|
||||
CHECK_FIELD_TYPE2(INT64, UINT64);
|
||||
CHECK_FIELD_NOT_REPEATED();
|
||||
|
||||
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT64)
|
||||
{
|
||||
msg->GetReflection()->SetUInt64(msg, field, (uint64)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg->GetReflection()->SetInt64(msg, field, value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool GetRepeatedInt32OrUnsignedOrEnum(const char *pszFieldName, int index, int32 *out)
|
||||
{
|
||||
@@ -384,6 +427,21 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool GetRepeatedInt64OrUnsigned(const char *pszFieldName, int index, int64 *out)
|
||||
{
|
||||
GETCHECK_FIELD();
|
||||
CHECK_FIELD_TYPE2(INT64, UINT64);
|
||||
CHECK_FIELD_REPEATED();
|
||||
CHECK_REPEATED_ELEMENT(index);
|
||||
|
||||
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT64)
|
||||
*out = (int64)msg->GetReflection()->GetRepeatedUInt64(*msg, field, index);
|
||||
else
|
||||
*out = msg->GetReflection()->GetRepeatedInt64(*msg, field, index);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool SetRepeatedInt32OrUnsignedOrEnum(const char *pszFieldName, int index, int32 value)
|
||||
{
|
||||
@@ -411,6 +469,25 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool SetRepeatedInt64OrUnsigned(const char *pszFieldName, int index, int64 value)
|
||||
{
|
||||
GETCHECK_FIELD();
|
||||
CHECK_FIELD_TYPE2(INT64, UINT64);
|
||||
CHECK_FIELD_REPEATED();
|
||||
CHECK_REPEATED_ELEMENT(index);
|
||||
|
||||
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT64)
|
||||
{
|
||||
msg->GetReflection()->SetRepeatedUInt64(msg, field, index, (uint64)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg->GetReflection()->SetRepeatedInt64(msg, field, index, value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool AddInt32OrUnsignedOrEnum(const char *pszFieldName, int32 value)
|
||||
{
|
||||
@@ -437,6 +514,24 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool AddInt64OrUnsigned(const char *pszFieldName, int64 value)
|
||||
{
|
||||
GETCHECK_FIELD();
|
||||
CHECK_FIELD_TYPE2(INT64, UINT64);
|
||||
CHECK_FIELD_REPEATED();
|
||||
|
||||
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT64)
|
||||
{
|
||||
msg->GetReflection()->AddUInt64(msg, field, (uint64)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg->GetReflection()->AddInt64(msg, field, value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool GetBool(const char *pszFieldName, bool *out)
|
||||
{
|
||||
@@ -725,9 +820,6 @@ public:
|
||||
|
||||
inline bool GetColor(const char *pszFieldName, Color *out)
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
return false;
|
||||
#else
|
||||
GETCHECK_FIELD();
|
||||
CHECK_FIELD_TYPE(MESSAGE);
|
||||
CHECK_FIELD_NOT_REPEATED();
|
||||
@@ -741,14 +833,10 @@ public:
|
||||
);
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool SetColor(const char *pszFieldName, const Color &value)
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
return false;
|
||||
#else
|
||||
GETCHECK_FIELD();
|
||||
CHECK_FIELD_TYPE(MESSAGE);
|
||||
CHECK_FIELD_NOT_REPEATED();
|
||||
@@ -760,14 +848,10 @@ public:
|
||||
msgRGBA->set_a(value.a());
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool GetRepeatedColor(const char *pszFieldName, int index, Color *out)
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
return false;
|
||||
#else
|
||||
GETCHECK_FIELD();
|
||||
CHECK_FIELD_TYPE(MESSAGE);
|
||||
CHECK_FIELD_REPEATED();
|
||||
@@ -782,14 +866,10 @@ public:
|
||||
);
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool SetRepeatedColor(const char *pszFieldName, int index, const Color &value)
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
return false;
|
||||
#else
|
||||
GETCHECK_FIELD();
|
||||
CHECK_FIELD_TYPE(MESSAGE);
|
||||
CHECK_FIELD_REPEATED();
|
||||
@@ -802,14 +882,10 @@ public:
|
||||
msgRGBA->set_a(value.a());
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool AddColor(const char *pszFieldName, const Color &value)
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
return false;
|
||||
#else
|
||||
GETCHECK_FIELD();
|
||||
CHECK_FIELD_TYPE(MESSAGE);
|
||||
CHECK_FIELD_REPEATED();
|
||||
@@ -821,7 +897,6 @@ public:
|
||||
msgRGBA->set_a(value.a());
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool GetVector2D(const char *pszFieldName, Vector2D *out)
|
||||
|
||||
+67
-31
@@ -35,12 +35,19 @@
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#include <cstrike15_usermessage_helpers.h>
|
||||
#elif SOURCE_ENGINE == SE_BLADE
|
||||
#include <berimbau_usermessage_helpers.h>
|
||||
#elif SOURCE_ENGINE == SE_MCV
|
||||
#include <vietnam_usermessage_helpers.h>
|
||||
#elif SOURCE_ENGINE == SE_OUTBREAK
|
||||
#include <base_usermessage_helpers.h>
|
||||
#include <terror_usermessage_helpers.h>
|
||||
#endif
|
||||
#include <amtl/am-string.h>
|
||||
|
||||
UserMessages g_UserMsgs;
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
SH_DECL_HOOK3_void(IVEngineServer, SendUserMessage, SH_NOATTRIB, 0, IRecipientFilter &, int, const protobuf::Message &);
|
||||
#else
|
||||
#if SOURCE_ENGINE >= SE_LEFT4DEAD
|
||||
@@ -49,7 +56,7 @@ SH_DECL_HOOK3(IVEngineServer, UserMessageBegin, SH_NOATTRIB, 0, bf_write *, IRec
|
||||
SH_DECL_HOOK2(IVEngineServer, UserMessageBegin, SH_NOATTRIB, 0, bf_write *, IRecipientFilter *, int);
|
||||
#endif
|
||||
SH_DECL_HOOK0_void(IVEngineServer, MessageEnd, SH_NOATTRIB, 0);
|
||||
#endif // ==SE_CSGO
|
||||
#endif // ==SE_CSGO || ==SE_BLADE || ==SE_MCV || ==SE_OUTBREAK
|
||||
|
||||
UserMessages::UserMessages()
|
||||
#ifndef USE_PROTOBUF_USERMESSAGES
|
||||
@@ -68,12 +75,11 @@ UserMessages::UserMessages()
|
||||
|
||||
UserMessages::~UserMessages()
|
||||
{
|
||||
CStack<ListenerInfo *>::iterator iter;
|
||||
for (iter=m_FreeListeners.begin(); iter!=m_FreeListeners.end(); iter++)
|
||||
while (!m_FreeListeners.empty())
|
||||
{
|
||||
delete (*iter);
|
||||
delete m_FreeListeners.top();
|
||||
m_FreeListeners.pop();
|
||||
}
|
||||
m_FreeListeners.popall();
|
||||
}
|
||||
|
||||
void UserMessages::OnSourceModStartup(bool late)
|
||||
@@ -93,7 +99,7 @@ void UserMessages::OnSourceModAllShutdown()
|
||||
{
|
||||
if (m_HookCount)
|
||||
{
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Pre), false);
|
||||
SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Post), true);
|
||||
#else
|
||||
@@ -111,6 +117,13 @@ int UserMessages::GetMessageIndex(const char *msg)
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
// Can split this per engine and/or game later
|
||||
return g_Cstrike15UsermessageHelpers.GetIndex(msg);
|
||||
#elif SOURCE_ENGINE == SE_BLADE
|
||||
return g_BerimbauUsermessageHelpers.GetIndex(msg);
|
||||
#elif SOURCE_ENGINE == SE_MCV
|
||||
return g_VietnamUsermessageHelpers.GetIndex(msg);
|
||||
#elif SOURCE_ENGINE == SE_OUTBREAK
|
||||
int idx = g_TerrorUsermessageHelpers.GetIndex(msg);
|
||||
return idx == -1 ? g_BaseUsermessageHelpers.GetIndex(msg) : idx;
|
||||
#else
|
||||
|
||||
int msgid;
|
||||
@@ -148,6 +161,14 @@ bool UserMessages::GetMessageName(int msgid, char *buffer, size_t maxlength) con
|
||||
#ifdef USE_PROTOBUF_USERMESSAGES
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
const char *pszName = g_Cstrike15UsermessageHelpers.GetName(msgid);
|
||||
#elif SOURCE_ENGINE == SE_BLADE
|
||||
const char *pszName = g_BerimbauUsermessageHelpers.GetName(msgid);
|
||||
#elif SOURCE_ENGINE == SE_MCV
|
||||
const char *pszName = g_VietnamUsermessageHelpers.GetName(msgid);
|
||||
#elif SOURCE_ENGINE == SE_OUTBREAK
|
||||
const char *pszName = g_TerrorUsermessageHelpers.GetName(msgid);
|
||||
if (pszName == nullptr)
|
||||
pszName = g_BaseUsermessageHelpers.GetName(msgid);
|
||||
#endif
|
||||
if (!pszName)
|
||||
return false;
|
||||
@@ -297,7 +318,7 @@ bool UserMessages::EndMessage()
|
||||
return false;
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
if (m_CurFlags & USERMSG_BLOCKHOOKS)
|
||||
{
|
||||
ENGINE_CALL(SendUserMessage)(static_cast<IRecipientFilter &>(m_CellRecFilter), m_CurId, *m_FakeEngineBuffer);
|
||||
@@ -327,7 +348,7 @@ bool UserMessages::EndMessage()
|
||||
} else {
|
||||
engine->MessageEnd();
|
||||
}
|
||||
#endif // SE_CSGO
|
||||
#endif // SE_CSGO || SE_BLADE || SE_MCV || SE_OUTBREAK
|
||||
|
||||
m_InExec = false;
|
||||
m_CurFlags = 0;
|
||||
@@ -401,7 +422,7 @@ bool UserMessages::InternalHook(int msg_id, IBitBufUserMessageListener *pListene
|
||||
{
|
||||
pInfo = new ListenerInfo;
|
||||
} else {
|
||||
pInfo = m_FreeListeners.front();
|
||||
pInfo = m_FreeListeners.top();
|
||||
m_FreeListeners.pop();
|
||||
}
|
||||
|
||||
@@ -412,7 +433,7 @@ bool UserMessages::InternalHook(int msg_id, IBitBufUserMessageListener *pListene
|
||||
|
||||
if (!m_HookCount++)
|
||||
{
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
SH_ADD_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Pre), false);
|
||||
SH_ADD_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Post), true);
|
||||
#else
|
||||
@@ -438,6 +459,15 @@ const protobuf::Message *UserMessages::GetMessagePrototype(int msg_type)
|
||||
{
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
return g_Cstrike15UsermessageHelpers.GetPrototype(msg_type);
|
||||
#elif SOURCE_ENGINE == SE_BLADE
|
||||
return g_BerimbauUsermessageHelpers.GetPrototype(msg_type);
|
||||
#elif SOURCE_ENGINE == SE_MCV
|
||||
return g_VietnamUsermessageHelpers.GetPrototype(msg_type);
|
||||
#elif SOURCE_ENGINE == SE_OUTBREAK
|
||||
auto *msg = g_TerrorUsermessageHelpers.GetPrototype(msg_type);
|
||||
if (msg == nullptr)
|
||||
msg = g_BaseUsermessageHelpers.GetPrototype(msg_type);
|
||||
return msg;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -449,7 +479,6 @@ bool UserMessages::InternalUnhook(int msg_id, IBitBufUserMessageListener *pListe
|
||||
#endif
|
||||
{
|
||||
MsgList *pList;
|
||||
MsgIter iter;
|
||||
ListenerInfo *pInfo;
|
||||
bool deleted = false;
|
||||
|
||||
@@ -459,7 +488,7 @@ bool UserMessages::InternalUnhook(int msg_id, IBitBufUserMessageListener *pListe
|
||||
}
|
||||
|
||||
pList = (intercept) ? &m_msgIntercepts[msg_id] : &m_msgHooks[msg_id];
|
||||
for (iter=pList->begin(); iter!=pList->end(); iter++)
|
||||
for (auto iter=pList->begin(); iter!=pList->end(); iter++)
|
||||
{
|
||||
pInfo = (*iter);
|
||||
if (pInfo->Callback == pListener && pInfo->IsNew == isNew)
|
||||
@@ -487,7 +516,7 @@ void UserMessages::_DecRefCounter()
|
||||
{
|
||||
if (--m_HookCount == 0)
|
||||
{
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Pre), false);
|
||||
SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Post), true);
|
||||
#else
|
||||
@@ -499,12 +528,23 @@ void UserMessages::_DecRefCounter()
|
||||
}
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
void UserMessages::OnSendUserMessage_Pre(IRecipientFilter &filter, int msg_type, const protobuf::Message &msg)
|
||||
{
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
OnStartMessage_Pre(&filter, msg_type, g_Cstrike15UsermessageHelpers.GetName(msg_type));
|
||||
const char *pszName = g_Cstrike15UsermessageHelpers.GetName(msg_type);
|
||||
#elif SOURCE_ENGINE == SE_BLADE
|
||||
const char *pszName = g_BerimbauUsermessageHelpers.GetName(msg_type);
|
||||
#elif SOURCE_ENGINE == SE_MCV
|
||||
const char *pszName = g_VietnamUsermessageHelpers.GetName(msg_type);
|
||||
#elif SOURCE_ENGINE == SE_OUTBREAK
|
||||
const char *pszName = g_TerrorUsermessageHelpers.GetName(msg_type);
|
||||
if (pszName == nullptr)
|
||||
pszName = g_BaseUsermessageHelpers.GetName(msg_type);
|
||||
#endif
|
||||
|
||||
OnStartMessage_Pre(&filter, msg_type, pszName);
|
||||
|
||||
if (m_FakeMetaRes == MRES_SUPERCEDE)
|
||||
{
|
||||
int size = msg.ByteSize();
|
||||
@@ -517,9 +557,7 @@ void UserMessages::OnSendUserMessage_Pre(IRecipientFilter &filter, int msg_type,
|
||||
m_FakeEngineBuffer = &const_cast<protobuf::Message &>(msg);
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
OnStartMessage_Post(&filter, msg_type, g_Cstrike15UsermessageHelpers.GetName(msg_type));
|
||||
#endif
|
||||
OnStartMessage_Post(&filter, msg_type, pszName);
|
||||
|
||||
OnMessageEnd_Pre();
|
||||
if (m_FakeMetaRes == MRES_SUPERCEDE)
|
||||
@@ -551,7 +589,7 @@ void UserMessages::OnSendUserMessage_Post(IRecipientFilter &filter, int msg_type
|
||||
RETURN_META(res)
|
||||
#endif
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
protobuf::Message *UserMessages::OnStartMessage_Pre(IRecipientFilter *filter, int msg_type, const char *msg_name)
|
||||
#elif SOURCE_ENGINE >= SE_LEFT4DEAD
|
||||
bf_write *UserMessages::OnStartMessage_Pre(IRecipientFilter *filter, int msg_type, const char *msg_name)
|
||||
@@ -591,7 +629,7 @@ bf_write *UserMessages::OnStartMessage_Pre(IRecipientFilter *filter, int msg_typ
|
||||
UM_RETURN_META_VALUE(MRES_IGNORED, NULL);
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
protobuf::Message *UserMessages::OnStartMessage_Post(IRecipientFilter *filter, int msg_type, const char *msg_name)
|
||||
#elif SOURCE_ENGINE >= SE_LEFT4DEAD
|
||||
bf_write *UserMessages::OnStartMessage_Post(IRecipientFilter *filter, int msg_type, const char *msg_name)
|
||||
@@ -624,13 +662,12 @@ void UserMessages::OnMessageEnd_Post()
|
||||
}
|
||||
|
||||
MsgList *pList;
|
||||
MsgIter iter;
|
||||
ListenerInfo *pInfo;
|
||||
|
||||
m_InHook = false;
|
||||
|
||||
pList = &m_msgIntercepts[m_CurId];
|
||||
for (iter=pList->begin(); iter!=pList->end(); )
|
||||
for (auto iter=pList->begin(); iter!=pList->end(); )
|
||||
{
|
||||
pInfo = (*iter);
|
||||
if (m_BlockEndPost && !pInfo->IsNew)
|
||||
@@ -657,7 +694,7 @@ void UserMessages::OnMessageEnd_Post()
|
||||
}
|
||||
|
||||
pList = &m_msgHooks[m_CurId];
|
||||
for (iter=pList->begin(); iter!=pList->end(); )
|
||||
for (auto iter=pList->begin(); iter!=pList->end(); )
|
||||
{
|
||||
pInfo = (*iter);
|
||||
if (m_BlockEndPost && !pInfo->IsNew)
|
||||
@@ -692,7 +729,6 @@ void UserMessages::OnMessageEnd_Pre()
|
||||
}
|
||||
|
||||
MsgList *pList;
|
||||
MsgIter iter;
|
||||
ListenerInfo *pInfo;
|
||||
|
||||
ResultType res;
|
||||
@@ -700,7 +736,7 @@ void UserMessages::OnMessageEnd_Pre()
|
||||
bool handled = false;
|
||||
|
||||
pList = &m_msgIntercepts[m_CurId];
|
||||
for (iter=pList->begin(); iter!=pList->end(); )
|
||||
for (auto iter=pList->begin(); iter!=pList->end(); )
|
||||
{
|
||||
pInfo = (*iter);
|
||||
pInfo->IsHooked = true;
|
||||
@@ -756,7 +792,7 @@ void UserMessages::OnMessageEnd_Pre()
|
||||
|
||||
if (!handled && intercepted)
|
||||
{
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
ENGINE_CALL(SendUserMessage)(static_cast<IRecipientFilter &>(*m_CurRecFilter), m_CurId, *m_InterceptBuffer);
|
||||
#else
|
||||
bf_write *engine_bfw;
|
||||
@@ -768,11 +804,11 @@ void UserMessages::OnMessageEnd_Pre()
|
||||
m_ReadBuffer.StartReading(m_InterceptBuffer.GetBasePointer(), m_InterceptBuffer.GetNumBytesWritten());
|
||||
engine_bfw->WriteBitsFromBuffer(&m_ReadBuffer, m_InterceptBuffer.GetNumBitsWritten());
|
||||
ENGINE_CALL(MessageEnd)();
|
||||
#endif // SE_CSGO
|
||||
#endif // SE_CSGO || SE_BLADE || SE_MCV || SE_OUTBREAK
|
||||
}
|
||||
|
||||
{
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
int size = m_OrigBuffer->ByteSize();
|
||||
uint8 *data = (uint8 *)stackalloc(size);
|
||||
m_OrigBuffer->SerializePartialToArray(data, size);
|
||||
@@ -784,7 +820,7 @@ void UserMessages::OnMessageEnd_Pre()
|
||||
#endif
|
||||
|
||||
pList = &m_msgHooks[m_CurId];
|
||||
for (iter=pList->begin(); iter!=pList->end(); )
|
||||
for (auto iter=pList->begin(); iter!=pList->end(); )
|
||||
{
|
||||
pInfo = (*iter);
|
||||
pInfo->IsHooked = true;
|
||||
@@ -802,7 +838,7 @@ void UserMessages::OnMessageEnd_Pre()
|
||||
iter++;
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
delete pTempMsg;
|
||||
#endif
|
||||
}
|
||||
|
||||
+13
-12
@@ -34,21 +34,23 @@
|
||||
|
||||
#include <IUserMessages.h>
|
||||
#include "sourcemm_api.h"
|
||||
#include <sm_stringhashmap.h>
|
||||
#include <sm_hashmap.h>
|
||||
#include "sm_stringutil.h"
|
||||
#include "CellRecipientFilter.h"
|
||||
#include "sm_globals.h"
|
||||
#include <sh_list.h>
|
||||
#include <sh_stack.h>
|
||||
#include <list>
|
||||
#include <stack>
|
||||
|
||||
using namespace SourceHook;
|
||||
using namespace SourceMod;
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
#define USE_PROTOBUF_USERMESSAGES
|
||||
#endif
|
||||
|
||||
#ifdef USE_PROTOBUF_USERMESSAGES
|
||||
#ifdef GetMessage
|
||||
#undef GetMessage
|
||||
#endif
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <netmessages.pb.h>
|
||||
@@ -72,8 +74,7 @@ struct ListenerInfo
|
||||
bool IsNew;
|
||||
};
|
||||
|
||||
typedef List<ListenerInfo *> MsgList;
|
||||
typedef List<ListenerInfo *>::iterator MsgIter;
|
||||
typedef std::list<ListenerInfo *> MsgList;
|
||||
|
||||
class UserMessages :
|
||||
public IUserMessages,
|
||||
@@ -102,12 +103,12 @@ public: //IUserMessages
|
||||
bool intercept=false);
|
||||
UserMessageType GetUserMessageType() const;
|
||||
public:
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
void OnSendUserMessage_Pre(IRecipientFilter &filter, int msg_type, const protobuf::Message &msg);
|
||||
void OnSendUserMessage_Post(IRecipientFilter &filter, int msg_type, const protobuf::Message &msg);
|
||||
#endif
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
protobuf::Message *OnStartMessage_Pre(IRecipientFilter *filter, int msg_type, const char *msg_name);
|
||||
protobuf::Message *OnStartMessage_Post(IRecipientFilter *filter, int msg_type, const char *msg_name);
|
||||
#elif SOURCE_ENGINE >= SE_LEFT4DEAD
|
||||
@@ -130,9 +131,9 @@ private:
|
||||
#endif
|
||||
void _DecRefCounter();
|
||||
private:
|
||||
List<ListenerInfo *> m_msgHooks[255];
|
||||
List<ListenerInfo *> m_msgIntercepts[255];
|
||||
CStack<ListenerInfo *> m_FreeListeners;
|
||||
std::list<ListenerInfo *> m_msgHooks[255];
|
||||
std::list<ListenerInfo *> m_msgIntercepts[255];
|
||||
std::stack<ListenerInfo *> m_FreeListeners;
|
||||
IRecipientFilter *m_CurRecFilter;
|
||||
#ifndef USE_PROTOBUF_USERMESSAGES
|
||||
unsigned char m_pBase[2500];
|
||||
|
||||
+26
-21
@@ -26,7 +26,7 @@
|
||||
// or <http://www.sourcemod.net/license.php>.
|
||||
|
||||
#include "sm_globals.h"
|
||||
#include <sh_list.h>
|
||||
#include <list>
|
||||
#include <convar.h>
|
||||
#include "concmd_cleaner.h"
|
||||
#include "sm_stringutil.h"
|
||||
@@ -36,13 +36,15 @@
|
||||
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
SH_DECL_HOOK1_void(ICvar, UnregisterConCommand, SH_NOATTRIB, 0, ConCommandBase *);
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
SH_DECL_HOOK2_void(ICvar, RegisterConCommand, SH_NOATTRIB, 0, ConCommandBase *, bool);
|
||||
#else
|
||||
SH_DECL_HOOK1_void(ICvar, RegisterConCommand, SH_NOATTRIB, 0, ConCommandBase *);
|
||||
#endif
|
||||
#else
|
||||
SH_DECL_HOOK1_void(ICvar, RegisterConCommandBase, SH_NOATTRIB, 0, ConCommandBase *);
|
||||
#endif
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
struct ConCommandInfo
|
||||
{
|
||||
ConCommandBase *pBase;
|
||||
@@ -50,7 +52,7 @@ struct ConCommandInfo
|
||||
char name[64];
|
||||
};
|
||||
|
||||
List<ConCommandInfo *> tracked_bases;
|
||||
std::list<ConCommandInfo *> tracked_bases;
|
||||
IConCommandLinkListener *IConCommandLinkListener::head = NULL;
|
||||
|
||||
ConCommandBase *FindConCommandBase(const char *name);
|
||||
@@ -78,7 +80,11 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV || SOURCE_ENGINE == SE_OUTBREAK
|
||||
void LinkConCommandBase(ConCommandBase *pBase, bool unknown)
|
||||
#else
|
||||
void LinkConCommandBase(ConCommandBase *pBase)
|
||||
#endif
|
||||
{
|
||||
IConCommandLinkListener *listener = IConCommandLinkListener::head;
|
||||
while (listener)
|
||||
@@ -91,7 +97,7 @@ public:
|
||||
void UnlinkConCommandBase(ConCommandBase *pBase)
|
||||
{
|
||||
ConCommandInfo *pInfo;
|
||||
List<ConCommandInfo *>::iterator iter = tracked_bases.begin();
|
||||
auto iter = tracked_bases.begin();
|
||||
|
||||
IConCommandLinkListener *listener = IConCommandLinkListener::head;
|
||||
while (listener)
|
||||
@@ -100,20 +106,20 @@ public:
|
||||
listener = listener->next;
|
||||
}
|
||||
|
||||
while (iter != tracked_bases.end())
|
||||
{
|
||||
if ((*iter)->pBase == pBase)
|
||||
{
|
||||
pInfo = (*iter);
|
||||
iter = tracked_bases.erase(iter);
|
||||
pInfo->cls->OnUnlinkConCommandBase(pBase, pBase->GetName());
|
||||
delete pInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
while (iter != tracked_bases.end())
|
||||
{
|
||||
if ((*iter)->pBase == pBase)
|
||||
{
|
||||
pInfo = (*iter);
|
||||
iter = tracked_bases.erase(iter);
|
||||
pInfo->cls->OnUnlinkConCommandBase(pBase, pBase->GetName());
|
||||
delete pInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AddTarget(ConCommandBase *pBase, IConCommandTracker *cls)
|
||||
@@ -129,10 +135,9 @@ public:
|
||||
|
||||
void RemoveTarget(ConCommandBase *pBase, IConCommandTracker *cls)
|
||||
{
|
||||
List<ConCommandInfo *>::iterator iter;
|
||||
ConCommandInfo *pInfo;
|
||||
|
||||
iter = tracked_bases.begin();
|
||||
auto iter = tracked_bases.begin();
|
||||
while (iter != tracked_bases.end())
|
||||
{
|
||||
pInfo = (*iter);
|
||||
|
||||
@@ -1,551 +0,0 @@
|
||||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Workfile: $
|
||||
// $Date: 2006-08-13 06:34:30 -0500 (Sun, 13 Aug 2006) $
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef CONVAR_H
|
||||
#define CONVAR_H
|
||||
#if _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/dbg.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define FORCEINLINE_CVAR FORCEINLINE
|
||||
#elif _LINUX
|
||||
#define FORCEINLINE_CVAR __inline__ FORCEINLINE
|
||||
#else
|
||||
#error "implement me"
|
||||
#endif
|
||||
|
||||
// The default, no flags at all
|
||||
#define FCVAR_NONE 0
|
||||
|
||||
// Command to ConVars and ConCommands
|
||||
// ConVar Systems
|
||||
#define FCVAR_UNREGISTERED (1<<0) // If this is set, don't add to linked list, etc.
|
||||
#define FCVAR_LAUNCHER (1<<1) // defined by launcher
|
||||
#define FCVAR_GAMEDLL (1<<2) // defined by the game DLL
|
||||
#define FCVAR_CLIENTDLL (1<<3) // defined by the client DLL
|
||||
#define FCVAR_MATERIAL_SYSTEM (1<<4) // Defined by the material system.
|
||||
#define FCVAR_DATACACHE (1<<19) // Defined by the datacache system.
|
||||
#define FCVAR_STUDIORENDER (1<<15) // Defined by the studiorender system.
|
||||
#define FCVAR_FILESYSTEM (1<<21) // Defined by the file system.
|
||||
#define FCVAR_PLUGIN (1<<18) // Defined by a 3rd party plugin.
|
||||
#define FCVAR_TOOLSYSTEM (1<<20) // Defined by an IToolSystem library
|
||||
#define FCVAR_SOUNDSYSTEM (1<<23) // Defined by the soundsystem library
|
||||
#define FCVAR_INPUTSYSTEM (1<<25) // Defined by the inputsystem dll
|
||||
#define FCVAR_NETWORKSYSTEM (1<<26) // Defined by the network system
|
||||
// NOTE!! if you add a cvar system, add it here too!!!!
|
||||
// the engine lacks a cvar flag, but needs it for xbox
|
||||
// an engine cvar is thus a cvar not marked with any other system
|
||||
#define FCVAR_NON_ENGINE ((FCVAR_LAUNCHER|FCVAR_GAMEDLL|FCVAR_CLIENTDLL|FCVAR_MATERIAL_SYSTEM|FCVAR_DATACACHE|FCVAR_STUDIORENDER|FCVAR_FILESYSTEM|FCVAR_PLUGIN|FCVAR_TOOLSYSTEM|FCVAR_SOUNDSYSTEM|FCVAR_INPUTSYSTEM|FCVAR_NETWORKSYSTEM))
|
||||
|
||||
// ConVar only
|
||||
#define FCVAR_PROTECTED (1<<5) // It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as value
|
||||
#define FCVAR_SPONLY (1<<6) // This cvar cannot be changed by clients connected to a multiplayer server.
|
||||
#define FCVAR_ARCHIVE (1<<7) // set to cause it to be saved to vars.rc
|
||||
#define FCVAR_NOTIFY (1<<8) // notifies players when changed
|
||||
#define FCVAR_USERINFO (1<<9) // changes the client's info string
|
||||
#define FCVAR_CHEAT (1<<14) // Only useable in singleplayer / debug / multiplayer & sv_cheats
|
||||
|
||||
#define FCVAR_PRINTABLEONLY (1<<10) // This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ).
|
||||
#define FCVAR_UNLOGGED (1<<11) // If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log
|
||||
#define FCVAR_NEVER_AS_STRING (1<<12) // never try to print that cvar
|
||||
|
||||
// It's a ConVar that's shared between the client and the server.
|
||||
// At signon, the values of all such ConVars are sent from the server to the client (skipped for local
|
||||
// client, of course )
|
||||
// If a change is requested it must come from the console (i.e., no remote client changes)
|
||||
// If a value is changed while a server is active, it's replicated to all connected clients
|
||||
#define FCVAR_REPLICATED (1<<13) // server setting enforced on clients, TODO rename to FCAR_SERVER at some time
|
||||
#define FCVAR_DEMO (1<<16) // record this cvar when starting a demo file
|
||||
#define FCVAR_DONTRECORD (1<<17) // don't record these command in demofiles
|
||||
|
||||
#define FCVAR_NOT_CONNECTED (1<<22) // cvar cannot be changed by a client that is connected to a server
|
||||
|
||||
#define FCVAR_ARCHIVE_XBOX (1<<24) // cvar written to config.cfg on the Xbox
|
||||
|
||||
|
||||
// #define FCVAR_AVAILABLE (1<<27)
|
||||
// #define FCVAR_AVAILABLE (1<<28)
|
||||
// #define FCVAR_AVAILABLE (1<<29)
|
||||
// #define FCVAR_AVAILABLE (1<<30)
|
||||
// #define FCVAR_AVAILABLE (1<<31)
|
||||
|
||||
|
||||
class ConVar;
|
||||
class ConCommand;
|
||||
class ConCommandBase;
|
||||
|
||||
// Any executable that wants to use ConVars need to implement one of
|
||||
// these to hook up access to console variables.
|
||||
class IConCommandBaseAccessor
|
||||
{
|
||||
public:
|
||||
// Flags is a combination of FCVAR flags in cvar.h.
|
||||
// hOut is filled in with a handle to the variable.
|
||||
virtual bool RegisterConCommandBase( ConCommandBase *pVar )=0;
|
||||
};
|
||||
|
||||
|
||||
// You don't have to instantiate one of these, just call its
|
||||
// OneTimeInit function when your executable is initializing.
|
||||
class ConCommandBaseMgr
|
||||
{
|
||||
public:
|
||||
// Call this ONCE when the executable starts up.
|
||||
static void OneTimeInit( IConCommandBaseAccessor *pAccessor );
|
||||
#ifdef _XBOX
|
||||
static bool Fixup( ConCommandBase* pConCommandBase );
|
||||
#ifndef _RETAIL
|
||||
static void PublishCommands( bool bForce );
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
// Called when a ConVar changes value
|
||||
typedef void ( *FnChangeCallback )( ConVar *var, char const *pOldString );
|
||||
|
||||
// Called when a ConCommand needs to execute
|
||||
typedef void ( *FnCommandCallback )( void );
|
||||
|
||||
#define COMMAND_COMPLETION_MAXITEMS 64
|
||||
#define COMMAND_COMPLETION_ITEM_LENGTH 64
|
||||
|
||||
// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings
|
||||
typedef int ( *FnCommandCompletionCallback )( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: The base console invoked command/cvar interface
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConCommandBase
|
||||
{
|
||||
friend class ConCommandBaseMgr;
|
||||
friend class CCvar;
|
||||
friend class ConVar;
|
||||
friend class ConCommand;
|
||||
|
||||
public:
|
||||
ConCommandBase( void );
|
||||
ConCommandBase( char const *pName, char const *pHelpString = 0,
|
||||
int flags = 0 );
|
||||
|
||||
virtual ~ConCommandBase( void );
|
||||
|
||||
virtual bool IsCommand( void ) const;
|
||||
|
||||
// Check flag
|
||||
virtual bool IsBitSet( int flag ) const;
|
||||
// Set flag
|
||||
virtual void AddFlags( int flags );
|
||||
|
||||
// Return name of cvar
|
||||
virtual char const *GetName( void ) const;
|
||||
|
||||
// Return help text for cvar
|
||||
virtual char const *GetHelpText( void ) const;
|
||||
|
||||
// Deal with next pointer
|
||||
const ConCommandBase *GetNext( void ) const;
|
||||
void SetNext( ConCommandBase *next );
|
||||
|
||||
virtual bool IsRegistered( void ) const;
|
||||
|
||||
// Global methods
|
||||
static ConCommandBase const *GetCommands( void );
|
||||
static void AddToList( ConCommandBase *var );
|
||||
static void RemoveFlaggedCommands( int flag );
|
||||
static void RevertFlaggedCvars( int flag );
|
||||
static ConCommandBase const *FindCommand( char const *name );
|
||||
|
||||
protected:
|
||||
virtual void Create( char const *pName, char const *pHelpString = 0,
|
||||
int flags = 0 );
|
||||
|
||||
// Used internally by OneTimeInit to initialize.
|
||||
virtual void Init();
|
||||
|
||||
// Internal copy routine ( uses new operator from correct module )
|
||||
char *CopyString( char const *from );
|
||||
|
||||
// Next ConVar in chain
|
||||
ConCommandBase *m_pNext;
|
||||
|
||||
private:
|
||||
// Has the cvar been added to the global list?
|
||||
bool m_bRegistered;
|
||||
|
||||
// Static data
|
||||
char const *m_pszName;
|
||||
char const *m_pszHelpString;
|
||||
|
||||
// ConVar flags
|
||||
int m_nFlags;
|
||||
|
||||
protected:
|
||||
|
||||
// ConVars add themselves to this list for the executable. Then ConVarMgr::Init() runs through
|
||||
// all the console variables and registers them.
|
||||
static ConCommandBase *s_pConCommandBases;
|
||||
|
||||
// ConVars in this executable use this 'global' to access values.
|
||||
static IConCommandBaseAccessor *s_pAccessor;
|
||||
|
||||
public: // Hackalicous
|
||||
inline int GetFlags() const
|
||||
{
|
||||
return m_nFlags;
|
||||
}
|
||||
inline void SetFlags(int flags)
|
||||
{
|
||||
m_nFlags = flags;
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: The console invoked command
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConCommand : public ConCommandBase
|
||||
{
|
||||
friend class ConCommandBaseMgr;
|
||||
friend class CCvar;
|
||||
#ifdef _STATIC_LINKED
|
||||
friend class G_ConCommand;
|
||||
friend class C_ConCommand;
|
||||
friend class M_ConCommand;
|
||||
friend class S_ConCommand;
|
||||
friend class D_ConCommand;
|
||||
#endif
|
||||
|
||||
public:
|
||||
typedef ConCommandBase BaseClass;
|
||||
|
||||
ConCommand( void );
|
||||
ConCommand( char const *pName, FnCommandCallback callback,
|
||||
char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
|
||||
|
||||
virtual ~ConCommand( void );
|
||||
|
||||
virtual bool IsCommand( void ) const;
|
||||
|
||||
virtual int AutoCompleteSuggest( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
|
||||
|
||||
virtual bool CanAutoComplete( void );
|
||||
|
||||
// Invoke the function
|
||||
virtual void Dispatch( void );
|
||||
private:
|
||||
virtual void Create( char const *pName, FnCommandCallback callback,
|
||||
char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
|
||||
|
||||
// Call this function when executing the command
|
||||
FnCommandCallback m_fnCommandCallback;
|
||||
|
||||
FnCommandCompletionCallback m_fnCompletionCallback;
|
||||
bool m_bHasCompletionCallback;
|
||||
public: // Hackalicous
|
||||
inline FnCommandCallback GetCallback() const
|
||||
{
|
||||
return m_fnCommandCallback;
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: A console variable
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConVar : public ConCommandBase
|
||||
{
|
||||
friend class ConCommandBaseMgr;
|
||||
friend class CCvar;
|
||||
friend class CDefaultCvar;
|
||||
#ifdef _STATIC_LINKED
|
||||
friend class G_ConVar;
|
||||
friend class C_ConVar;
|
||||
friend class M_ConVar;
|
||||
friend class S_ConVar;
|
||||
friend class D_ConVar;
|
||||
#endif
|
||||
|
||||
public:
|
||||
typedef ConCommandBase BaseClass;
|
||||
|
||||
ConVar( char const *pName, char const *pDefaultValue, int flags = 0);
|
||||
|
||||
ConVar( char const *pName, char const *pDefaultValue, int flags,
|
||||
char const *pHelpString );
|
||||
ConVar( char const *pName, char const *pDefaultValue, int flags,
|
||||
char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax );
|
||||
ConVar( char const *pName, char const *pDefaultValue, int flags,
|
||||
char const *pHelpString, FnChangeCallback callback );
|
||||
ConVar( char const *pName, char const *pDefaultValue, int flags,
|
||||
char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax,
|
||||
FnChangeCallback callback );
|
||||
|
||||
virtual ~ConVar( void );
|
||||
|
||||
virtual bool IsBitSet( int flag ) const;
|
||||
virtual char const* GetHelpText( void ) const;
|
||||
virtual bool IsRegistered( void ) const;
|
||||
virtual char const *GetName( void ) const;
|
||||
virtual void AddFlags( int flags );
|
||||
virtual bool IsCommand( void ) const;
|
||||
|
||||
// Install a change callback (there shouldn't already be one....)
|
||||
void InstallChangeCallback( FnChangeCallback callback );
|
||||
|
||||
// Retrieve value
|
||||
FORCEINLINE_CVAR float GetFloat( void ) const;
|
||||
FORCEINLINE_CVAR int GetInt( void ) const;
|
||||
FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); }
|
||||
FORCEINLINE_CVAR char const *GetString( void ) const;
|
||||
|
||||
// Any function that allocates/frees memory needs to be virtual or else you'll have crashes
|
||||
// from alloc/free across dll/exe boundaries.
|
||||
|
||||
// These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue).
|
||||
virtual void SetValue( char const *value );
|
||||
virtual void SetValue( float value );
|
||||
virtual void SetValue( int value );
|
||||
|
||||
// Reset to default value
|
||||
void Revert( void );
|
||||
|
||||
// True if it has a min/max setting
|
||||
bool GetMin( float& minVal ) const;
|
||||
bool GetMax( float& maxVal ) const;
|
||||
char const *GetDefault( void ) const;
|
||||
|
||||
static void RevertAll( void );
|
||||
private:
|
||||
// Called by CCvar when the value of a var is changing.
|
||||
virtual void InternalSetValue(char const *value);
|
||||
// For CVARs marked FCVAR_NEVER_AS_STRING
|
||||
virtual void InternalSetFloatValue( float fNewValue );
|
||||
virtual void InternalSetIntValue( int nValue );
|
||||
|
||||
virtual bool ClampValue( float& value );
|
||||
virtual void ChangeStringValue( char const *tempVal );
|
||||
|
||||
virtual void Create( char const *pName, char const *pDefaultValue, int flags = 0,
|
||||
char const *pHelpString = 0, bool bMin = false, float fMin = 0.0,
|
||||
bool bMax = false, float fMax = false, FnChangeCallback callback = 0 );
|
||||
|
||||
// Used internally by OneTimeInit to initialize.
|
||||
virtual void Init();
|
||||
|
||||
private:
|
||||
|
||||
// This either points to "this" or it points to the original declaration of a ConVar.
|
||||
// This allows ConVars to exist in separate modules, and they all use the first one to be declared.
|
||||
// m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar).
|
||||
ConVar *m_pParent;
|
||||
|
||||
// Static data
|
||||
char const *m_pszDefaultValue;
|
||||
|
||||
// Value
|
||||
// Dynamically allocated
|
||||
char *m_pszString;
|
||||
int m_StringLength;
|
||||
|
||||
// Values
|
||||
float m_fValue;
|
||||
int m_nValue;
|
||||
|
||||
// Min/Max values
|
||||
bool m_bHasMin;
|
||||
float m_fMinVal;
|
||||
bool m_bHasMax;
|
||||
float m_fMaxVal;
|
||||
|
||||
// Call this function when ConVar changes
|
||||
FnChangeCallback m_fnChangeCallback;
|
||||
public: // Hackalicous
|
||||
inline FnChangeCallback GetCallback() const
|
||||
{
|
||||
return m_fnChangeCallback;
|
||||
}
|
||||
inline void SetMin(bool set, float min=0.0)
|
||||
{
|
||||
m_bHasMin = set;
|
||||
m_fMinVal = min;
|
||||
}
|
||||
inline void SetMax(bool set, float max=0.0)
|
||||
{
|
||||
m_bHasMax = set;
|
||||
m_fMaxVal = max;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as a float
|
||||
// Output : float
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR float ConVar::GetFloat( void ) const
|
||||
{
|
||||
return m_pParent->m_fValue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as an int
|
||||
// Output : int
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR int ConVar::GetInt( void ) const
|
||||
{
|
||||
return m_pParent->m_nValue;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
|
||||
// Output : char const *
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR char const *ConVar::GetString( void ) const
|
||||
{
|
||||
if ( m_nFlags & FCVAR_NEVER_AS_STRING )
|
||||
{
|
||||
return "FCVAR_NEVER_AS_STRING";
|
||||
}
|
||||
|
||||
return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : "";
|
||||
}
|
||||
|
||||
|
||||
#ifdef _STATIC_LINKED
|
||||
// identifies subsystem via piggybacking constructors with flags
|
||||
class G_ConCommand : public ConCommand
|
||||
{
|
||||
public:
|
||||
G_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) : ConCommand(pName, callback, pHelpString, flags|FCVAR_GAMEDLL, completionFunc) {}
|
||||
};
|
||||
|
||||
class C_ConCommand : public ConCommand
|
||||
{
|
||||
public:
|
||||
C_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) : ConCommand(pName, callback, pHelpString, flags|FCVAR_CLIENTDLL, completionFunc) {}
|
||||
};
|
||||
|
||||
class M_ConCommand : public ConCommand
|
||||
{
|
||||
public:
|
||||
M_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) : ConCommand(pName, callback, pHelpString, flags|FCVAR_MATERIAL_SYSTEM, completionFunc) {}
|
||||
};
|
||||
|
||||
class S_ConCommand : public ConCommand
|
||||
{
|
||||
public:
|
||||
S_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) : ConCommand(pName, callback, pHelpString, flags|FCVAR_STUDIORENDER, completionFunc) {}
|
||||
};
|
||||
|
||||
class D_ConCommand : public ConCommand
|
||||
{
|
||||
public:
|
||||
D_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) : ConCommand(pName, callback, pHelpString, flags|FCVAR_DATACACHE, completionFunc) {}
|
||||
};
|
||||
|
||||
typedef void ( *G_FnChangeCallback )( G_ConVar *var, char const *pOldString );
|
||||
typedef void ( *C_FnChangeCallback )( C_ConVar *var, char const *pOldString );
|
||||
typedef void ( *M_FnChangeCallback )( M_ConVar *var, char const *pOldString );
|
||||
typedef void ( *S_FnChangeCallback )( S_ConVar *var, char const *pOldString );
|
||||
typedef void ( *D_FnChangeCallback )( D_ConVar *var, char const *pOldString );
|
||||
|
||||
class G_ConVar : public ConVar
|
||||
{
|
||||
public:
|
||||
G_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL) {}
|
||||
G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString ) {}
|
||||
G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString, bMin, fMin, bMax, fMax) {}
|
||||
G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, G_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString, (FnChangeCallback)callback ) {}
|
||||
G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, G_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {}
|
||||
};
|
||||
|
||||
class C_ConVar : public ConVar
|
||||
{
|
||||
public:
|
||||
C_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL) {}
|
||||
C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString ) {}
|
||||
C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString, bMin, fMin, bMax, fMax) {}
|
||||
C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, C_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString, (FnChangeCallback)callback ) {}
|
||||
C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, C_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {}
|
||||
};
|
||||
|
||||
class M_ConVar : public ConVar
|
||||
{
|
||||
public:
|
||||
M_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM) {}
|
||||
M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString ) {}
|
||||
M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString, bMin, fMin, bMax, fMax) {}
|
||||
M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, M_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString, (FnChangeCallback)callback ) {}
|
||||
M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, M_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {}
|
||||
};
|
||||
|
||||
class S_ConVar : public ConVar
|
||||
{
|
||||
public:
|
||||
S_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER) {}
|
||||
S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString ) {}
|
||||
S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString, bMin, fMin, bMax, fMax) {}
|
||||
S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, M_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString, (FnChangeCallback)callback ) {}
|
||||
S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, S_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {}
|
||||
};
|
||||
|
||||
class D_ConVar : public ConVar
|
||||
{
|
||||
public:
|
||||
D_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE) {}
|
||||
D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString ) {}
|
||||
D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString, bMin, fMin, bMax, fMax) {}
|
||||
D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, M_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString, (FnChangeCallback)callback ) {}
|
||||
D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, D_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {}
|
||||
};
|
||||
|
||||
// redirect these declarations to their specific subsystem
|
||||
#ifdef GAME_DLL
|
||||
#define ConCommand G_ConCommand
|
||||
#define ConVar G_ConVar
|
||||
#endif
|
||||
#ifdef CLIENT_DLL
|
||||
#define ConCommand C_ConCommand
|
||||
#define ConVar C_ConVar
|
||||
#endif
|
||||
#ifdef MATERIALSYSTEM_DLL
|
||||
#define ConCommand M_ConCommand
|
||||
#define ConVar M_ConVar
|
||||
#endif
|
||||
#ifdef STUDIORENDER_DLL
|
||||
#define ConCommand S_ConCommand
|
||||
#define ConVar S_ConVar
|
||||
#endif
|
||||
#ifdef DATACACHE_DLL
|
||||
#define ConCommand D_ConCommand
|
||||
#define ConVar D_ConVar
|
||||
#endif
|
||||
#endif // _STATIC_LINKED
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Utility to quicky generate a simple console command
|
||||
//-----------------------------------------------------------------------------
|
||||
#define CON_COMMAND( name, description ) \
|
||||
static void name(); \
|
||||
static ConCommand name##_command( #name, name, description ); \
|
||||
static void name()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Utility to quicky generate a simple console command
|
||||
//-----------------------------------------------------------------------------
|
||||
#define CON_COMMAND_F( name, description, flags ) \
|
||||
static void name(); \
|
||||
static ConCommand name##_command( #name, name, description, flags ); \
|
||||
static void name()
|
||||
|
||||
|
||||
#endif // CONVAR_H
|
||||
@@ -1,718 +0,0 @@
|
||||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Workfile: $
|
||||
// $Date: $
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef CONVAR_H
|
||||
#define CONVAR_H
|
||||
|
||||
#if _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/dbg.h"
|
||||
#include "tier1/iconvar.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "icvar.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define FORCEINLINE_CVAR FORCEINLINE
|
||||
#elif defined _LINUX || defined __APPLE__
|
||||
#define FORCEINLINE_CVAR inline
|
||||
#else
|
||||
#error "implement me"
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConVar;
|
||||
class CCommand;
|
||||
class ConCommand;
|
||||
class ConCommandBase;
|
||||
struct characterset_t;
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Any executable that wants to use ConVars need to implement one of
|
||||
// these to hook up access to console variables.
|
||||
//-----------------------------------------------------------------------------
|
||||
class IConCommandBaseAccessor
|
||||
{
|
||||
public:
|
||||
// Flags is a combination of FCVAR flags in cvar.h.
|
||||
// hOut is filled in with a handle to the variable.
|
||||
virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helper method for console development
|
||||
//-----------------------------------------------------------------------------
|
||||
#if defined( _X360 ) && !defined( _RETAIL )
|
||||
void ConVar_PublishToVXConsole();
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when a ConCommand needs to execute
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef void ( *FnCommandCallbackV1_t )( void );
|
||||
typedef void ( *FnCommandCallback_t )( const CCommand &command );
|
||||
|
||||
#define COMMAND_COMPLETION_MAXITEMS 64
|
||||
#define COMMAND_COMPLETION_ITEM_LENGTH 64
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef int ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Interface version
|
||||
//-----------------------------------------------------------------------------
|
||||
class ICommandCallback
|
||||
{
|
||||
public:
|
||||
virtual void CommandCallback( const CCommand &command ) = 0;
|
||||
};
|
||||
|
||||
class ICommandCompletionCallback
|
||||
{
|
||||
public:
|
||||
virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: The base console invoked command/cvar interface
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConCommandBase
|
||||
{
|
||||
friend class CCvar;
|
||||
friend class ConVar;
|
||||
friend class ConCommand;
|
||||
friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor );
|
||||
friend void ConVar_PublishToVXConsole();
|
||||
|
||||
// FIXME: Remove when ConVar changes are done
|
||||
friend class CDefaultCvar;
|
||||
|
||||
public:
|
||||
ConCommandBase( void );
|
||||
ConCommandBase( const char *pName, const char *pHelpString = 0,
|
||||
int flags = 0 );
|
||||
|
||||
virtual ~ConCommandBase( void );
|
||||
|
||||
virtual bool IsCommand( void ) const;
|
||||
|
||||
// Check flag
|
||||
virtual bool IsFlagSet( int flag ) const;
|
||||
// Set flag
|
||||
virtual void AddFlags( int flags );
|
||||
// Remove flag
|
||||
virtual void RemoveFlags( int flags );
|
||||
// Get flags
|
||||
virtual int GetFlags( void ) const;
|
||||
|
||||
// Return name of cvar
|
||||
virtual const char *GetName( void ) const;
|
||||
|
||||
// Return help text for cvar
|
||||
virtual const char *GetHelpText( void ) const;
|
||||
|
||||
// Deal with next pointer
|
||||
const ConCommandBase *GetNext( void ) const;
|
||||
ConCommandBase *GetNext( void );
|
||||
|
||||
inline void SetNext(ConCommandBase *pBase)
|
||||
{
|
||||
m_pNext = pBase;
|
||||
}
|
||||
|
||||
virtual bool IsRegistered( void ) const;
|
||||
|
||||
// Returns the DLL identifier
|
||||
virtual CVarDLLIdentifier_t GetDLLIdentifier() const;
|
||||
|
||||
protected:
|
||||
virtual void Create( const char *pName, const char *pHelpString = 0,
|
||||
int flags = 0 );
|
||||
|
||||
// Used internally by OneTimeInit to initialize/shutdown
|
||||
virtual void Init();
|
||||
void Shutdown();
|
||||
|
||||
// Internal copy routine ( uses new operator from correct module )
|
||||
char *CopyString( const char *from );
|
||||
|
||||
private:
|
||||
// Next ConVar in chain
|
||||
// Prior to register, it points to the next convar in the DLL.
|
||||
// Once registered, though, m_pNext is reset to point to the next
|
||||
// convar in the global list
|
||||
ConCommandBase *m_pNext;
|
||||
|
||||
// Has the cvar been added to the global list?
|
||||
bool m_bRegistered;
|
||||
|
||||
// Static data
|
||||
const char *m_pszName;
|
||||
const char *m_pszHelpString;
|
||||
|
||||
// ConVar flags
|
||||
int m_nFlags;
|
||||
|
||||
protected:
|
||||
// ConVars add themselves to this list for the executable.
|
||||
// Then ConVar_Register runs through all the console variables
|
||||
// and registers them into a global list stored in vstdlib.dll
|
||||
static ConCommandBase *s_pConCommandBases;
|
||||
|
||||
// ConVars in this executable use this 'global' to access values.
|
||||
static IConCommandBaseAccessor *s_pAccessor;
|
||||
public:
|
||||
inline void SetFlags(int flags)
|
||||
{
|
||||
m_nFlags = flags;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Command tokenizer
|
||||
//-----------------------------------------------------------------------------
|
||||
class CCommand
|
||||
{
|
||||
public:
|
||||
CCommand();
|
||||
CCommand( int nArgC, const char **ppArgV );
|
||||
bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL );
|
||||
void Reset();
|
||||
|
||||
int ArgC() const;
|
||||
const char **ArgV() const;
|
||||
const char *ArgS() const; // All args that occur after the 0th arg, in string form
|
||||
const char *GetCommandString() const; // The entire command in string form, including the 0th arg
|
||||
const char *operator[]( int nIndex ) const; // Gets at arguments
|
||||
const char *Arg( int nIndex ) const; // Gets at arguments
|
||||
|
||||
// Helper functions to parse arguments to commands.
|
||||
const char* FindArg( const char *pName ) const;
|
||||
int FindArgInt( const char *pName, int nDefaultVal ) const;
|
||||
|
||||
static int MaxCommandLength();
|
||||
static characterset_t* DefaultBreakSet();
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
COMMAND_MAX_ARGC = 64,
|
||||
COMMAND_MAX_LENGTH = 512,
|
||||
};
|
||||
|
||||
int m_nArgc;
|
||||
int m_nArgv0Size;
|
||||
char m_pArgSBuffer[ COMMAND_MAX_LENGTH ];
|
||||
char m_pArgvBuffer[ COMMAND_MAX_LENGTH ];
|
||||
const char* m_ppArgv[ COMMAND_MAX_ARGC ];
|
||||
};
|
||||
|
||||
inline int CCommand::MaxCommandLength()
|
||||
{
|
||||
return COMMAND_MAX_LENGTH - 1;
|
||||
}
|
||||
|
||||
inline int CCommand::ArgC() const
|
||||
{
|
||||
return m_nArgc;
|
||||
}
|
||||
|
||||
inline const char **CCommand::ArgV() const
|
||||
{
|
||||
return m_nArgc ? (const char**)m_ppArgv : NULL;
|
||||
}
|
||||
|
||||
inline const char *CCommand::ArgS() const
|
||||
{
|
||||
return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : "";
|
||||
}
|
||||
|
||||
inline const char *CCommand::GetCommandString() const
|
||||
{
|
||||
return m_nArgc ? m_pArgSBuffer : "";
|
||||
}
|
||||
|
||||
inline const char *CCommand::Arg( int nIndex ) const
|
||||
{
|
||||
// FIXME: Many command handlers appear to not be particularly careful
|
||||
// about checking for valid argc range. For now, we're going to
|
||||
// do the extra check and return an empty string if it's out of range
|
||||
if ( nIndex < 0 || nIndex >= m_nArgc )
|
||||
return "";
|
||||
return m_ppArgv[nIndex];
|
||||
}
|
||||
|
||||
inline const char *CCommand::operator[]( int nIndex ) const
|
||||
{
|
||||
return Arg( nIndex );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: The console invoked command
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConCommand : public ConCommandBase
|
||||
{
|
||||
friend class CCvar;
|
||||
|
||||
public:
|
||||
typedef ConCommandBase BaseClass;
|
||||
|
||||
ConCommand( const char *pName, FnCommandCallbackV1_t callback,
|
||||
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
|
||||
ConCommand( const char *pName, FnCommandCallback_t callback,
|
||||
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
|
||||
ConCommand( const char *pName, ICommandCallback *pCallback,
|
||||
const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 );
|
||||
|
||||
virtual ~ConCommand( void );
|
||||
|
||||
virtual bool IsCommand( void ) const;
|
||||
|
||||
virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands );
|
||||
|
||||
virtual bool CanAutoComplete( void );
|
||||
|
||||
// Invoke the function
|
||||
virtual void Dispatch( const CCommand &command );
|
||||
|
||||
private:
|
||||
// NOTE: To maintain backward compat, we have to be very careful:
|
||||
// All public virtual methods must appear in the same order always
|
||||
// since engine code will be calling into this code, which *does not match*
|
||||
// in the mod code; it's using slightly different, but compatible versions
|
||||
// of this class. Also: Be very careful about adding new fields to this class.
|
||||
// Those fields will not exist in the version of this class that is instanced
|
||||
// in mod code.
|
||||
|
||||
// Call this function when executing the command
|
||||
union
|
||||
{
|
||||
FnCommandCallbackV1_t m_fnCommandCallbackV1;
|
||||
FnCommandCallback_t m_fnCommandCallback;
|
||||
ICommandCallback *m_pCommandCallback;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
FnCommandCompletionCallback m_fnCompletionCallback;
|
||||
ICommandCompletionCallback *m_pCommandCompletionCallback;
|
||||
};
|
||||
|
||||
bool m_bHasCompletionCallback : 1;
|
||||
bool m_bUsingNewCommandCallback : 1;
|
||||
bool m_bUsingCommandCallbackInterface : 1;
|
||||
public:
|
||||
inline FnCommandCallback_t GetCallback() const
|
||||
{
|
||||
return m_fnCommandCallback;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: A console variable
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConVar : public ConCommandBase, public IConVar
|
||||
{
|
||||
friend class CCvar;
|
||||
friend class ConVarRef;
|
||||
|
||||
public:
|
||||
typedef ConCommandBase BaseClass;
|
||||
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags = 0);
|
||||
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||
const char *pHelpString );
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||
const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax );
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||
const char *pHelpString, FnChangeCallback_t callback );
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||
const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax,
|
||||
FnChangeCallback_t callback );
|
||||
|
||||
virtual ~ConVar( void );
|
||||
|
||||
virtual bool IsCommand( void ) const;
|
||||
virtual bool IsFlagSet( int flag ) const;
|
||||
virtual void AddFlags( int flags );
|
||||
virtual int GetFlags( void ) const;
|
||||
virtual const char *GetName( void ) const;
|
||||
virtual const char* GetHelpText( void ) const;
|
||||
virtual bool IsRegistered( void ) const;
|
||||
|
||||
// Install a change callback (there shouldn't already be one....)
|
||||
void InstallChangeCallback( FnChangeCallback_t callback );
|
||||
|
||||
// Retrieve value
|
||||
FORCEINLINE_CVAR float GetFloat( void ) const;
|
||||
FORCEINLINE_CVAR int GetInt( void ) const;
|
||||
FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); }
|
||||
FORCEINLINE_CVAR char const *GetString( void ) const;
|
||||
|
||||
// Used internally by OneTimeInit to initialize.
|
||||
virtual void Init();
|
||||
|
||||
virtual const char *GetBaseName( void ) const;
|
||||
virtual int GetSplitScreenPlayerSlot ( void ) const;
|
||||
|
||||
// Any function that allocates/frees memory needs to be virtual or else you'll have crashes
|
||||
// from alloc/free across dll/exe boundaries.
|
||||
|
||||
// These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue).
|
||||
virtual void SetValue( const char *value );
|
||||
virtual void SetValue( float value );
|
||||
virtual void SetValue( int value );
|
||||
#if SOURCE_ENGINE >= SE_NUCLEARDAWN
|
||||
virtual void SetValue( Color value );
|
||||
#endif
|
||||
|
||||
// Reset to default value
|
||||
void Revert( void );
|
||||
|
||||
// True if it has a min/max setting
|
||||
bool GetMin( float& minVal ) const;
|
||||
bool GetMax( float& maxVal ) const;
|
||||
const char *GetDefault( void ) const;
|
||||
|
||||
private:
|
||||
// Called by CCvar when the value of a var is changing.
|
||||
virtual void InternalSetValue(const char *value);
|
||||
// For CVARs marked FCVAR_NEVER_AS_STRING
|
||||
virtual void InternalSetFloatValue( float fNewValue );
|
||||
virtual void InternalSetIntValue( int nValue );
|
||||
#if SOURCE_ENGINE >= SE_LEFT4DEAD2
|
||||
virtual void InternalSetColorValue( Color value );
|
||||
#endif
|
||||
|
||||
virtual bool ClampValue( float& value );
|
||||
virtual void ChangeStringValue( const char *tempVal, float flOldValue );
|
||||
|
||||
virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0,
|
||||
const char *pHelpString = 0, bool bMin = false, float fMin = 0.0,
|
||||
bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 );
|
||||
|
||||
private:
|
||||
|
||||
// This either points to "this" or it points to the original declaration of a ConVar.
|
||||
// This allows ConVars to exist in separate modules, and they all use the first one to be declared.
|
||||
// m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar).
|
||||
ConVar *m_pParent;
|
||||
|
||||
// Static data
|
||||
const char *m_pszDefaultValue;
|
||||
|
||||
// Value
|
||||
// Dynamically allocated
|
||||
char *m_pszString;
|
||||
int m_StringLength;
|
||||
|
||||
// Values
|
||||
float m_fValue;
|
||||
int m_nValue;
|
||||
|
||||
// Min/Max values
|
||||
bool m_bHasMin;
|
||||
float m_fMinVal;
|
||||
bool m_bHasMax;
|
||||
float m_fMaxVal;
|
||||
|
||||
// Call this function when ConVar changes
|
||||
FnChangeCallback_t m_fnChangeCallback;
|
||||
public:
|
||||
inline FnChangeCallback_t GetCallback() const
|
||||
{
|
||||
return m_fnChangeCallback;
|
||||
}
|
||||
inline void SetMin(bool set, float min=0.0)
|
||||
{
|
||||
m_bHasMin = set;
|
||||
m_fMinVal = min;
|
||||
}
|
||||
inline void SetMax(bool set, float max=0.0)
|
||||
{
|
||||
m_bHasMax = set;
|
||||
m_fMaxVal = max;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as a float
|
||||
// Output : float
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR float ConVar::GetFloat( void ) const
|
||||
{
|
||||
return m_pParent->m_fValue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as an int
|
||||
// Output : int
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR int ConVar::GetInt( void ) const
|
||||
{
|
||||
return m_pParent->m_nValue;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
|
||||
// Output : const char *
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR const char *ConVar::GetString( void ) const
|
||||
{
|
||||
if ( m_nFlags & FCVAR_NEVER_AS_STRING )
|
||||
return "FCVAR_NEVER_AS_STRING";
|
||||
|
||||
return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : "";
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to read/write convars that already exist (replaces the FindVar method)
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConVarRef
|
||||
{
|
||||
public:
|
||||
ConVarRef( const char *pName );
|
||||
ConVarRef( const char *pName, bool bIgnoreMissing );
|
||||
ConVarRef( IConVar *pConVar );
|
||||
|
||||
void Init( const char *pName, bool bIgnoreMissing );
|
||||
bool IsValid() const;
|
||||
bool IsFlagSet( int nFlags ) const;
|
||||
IConVar *GetLinkedConVar();
|
||||
|
||||
// Get/Set value
|
||||
float GetFloat( void ) const;
|
||||
int GetInt( void ) const;
|
||||
bool GetBool() const { return !!GetInt(); }
|
||||
const char *GetString( void ) const;
|
||||
|
||||
void SetValue( const char *pValue );
|
||||
void SetValue( float flValue );
|
||||
void SetValue( int nValue );
|
||||
void SetValue( bool bValue );
|
||||
|
||||
const char *GetName() const;
|
||||
|
||||
const char *GetDefault() const;
|
||||
|
||||
private:
|
||||
// High-speed method to read convar data
|
||||
IConVar *m_pConVar;
|
||||
ConVar *m_pConVarState;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Did we find an existing convar of that name?
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const
|
||||
{
|
||||
return ( m_pConVar->IsFlagSet( nFlags ) != 0 );
|
||||
}
|
||||
|
||||
FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar()
|
||||
{
|
||||
return m_pConVar;
|
||||
}
|
||||
|
||||
FORCEINLINE_CVAR const char *ConVarRef::GetName() const
|
||||
{
|
||||
return m_pConVar->GetName();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as a float
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const
|
||||
{
|
||||
return m_pConVarState->m_fValue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as an int
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const
|
||||
{
|
||||
return m_pConVarState->m_nValue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const
|
||||
{
|
||||
Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
|
||||
return m_pConVarState->m_pszString;
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue )
|
||||
{
|
||||
m_pConVar->SetValue( pValue );
|
||||
}
|
||||
|
||||
FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue )
|
||||
{
|
||||
m_pConVar->SetValue( flValue );
|
||||
}
|
||||
|
||||
FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue )
|
||||
{
|
||||
m_pConVar->SetValue( nValue );
|
||||
}
|
||||
|
||||
FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue )
|
||||
{
|
||||
m_pConVar->SetValue( bValue ? 1 : 0 );
|
||||
}
|
||||
|
||||
FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const
|
||||
{
|
||||
return m_pConVarState->m_pszDefaultValue;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called by the framework to register ConCommands with the ICVar
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL );
|
||||
void ConVar_Unregister( );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Utility methods
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar_PrintFlags( const ConCommandBase *var );
|
||||
void ConVar_PrintDescription( const ConCommandBase *pVar );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Utility class to quickly allow ConCommands to call member methods
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable : 4355 )
|
||||
#endif
|
||||
|
||||
template< class T >
|
||||
class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback
|
||||
{
|
||||
typedef ConCommand BaseClass;
|
||||
typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command );
|
||||
typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands );
|
||||
|
||||
public:
|
||||
CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0,
|
||||
int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) :
|
||||
BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL )
|
||||
{
|
||||
m_pOwner = pOwner;
|
||||
m_Func = callback;
|
||||
m_CompletionFunc = completionFunc;
|
||||
}
|
||||
|
||||
~CConCommandMemberAccessor()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
void SetOwner( T* pOwner )
|
||||
{
|
||||
m_pOwner = pOwner;
|
||||
}
|
||||
|
||||
virtual void CommandCallback( const CCommand &command )
|
||||
{
|
||||
Assert( m_pOwner && m_Func );
|
||||
(m_pOwner->*m_Func)( command );
|
||||
}
|
||||
|
||||
virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands )
|
||||
{
|
||||
Assert( m_pOwner && m_CompletionFunc );
|
||||
return (m_pOwner->*m_CompletionFunc)( pPartial, commands );
|
||||
}
|
||||
|
||||
private:
|
||||
T* m_pOwner;
|
||||
FnMemberCommandCallback_t m_Func;
|
||||
FnMemberCommandCompletionCallback_t m_CompletionFunc;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning ( default : 4355 )
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Utility macros to quicky generate a simple console command
|
||||
//-----------------------------------------------------------------------------
|
||||
#define CON_COMMAND( name, description ) \
|
||||
static void name( const CCommand &args ); \
|
||||
static ConCommand name##_command( #name, name, description ); \
|
||||
static void name( const CCommand &args )
|
||||
|
||||
#define CON_COMMAND_F( name, description, flags ) \
|
||||
static void name( const CCommand &args ); \
|
||||
static ConCommand name##_command( #name, name, description, flags ); \
|
||||
static void name( const CCommand &args )
|
||||
|
||||
#define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \
|
||||
static void name( const CCommand &args ); \
|
||||
static ConCommand name##_command( #name, name, description, flags, completion ); \
|
||||
static void name( const CCommand &args )
|
||||
|
||||
#define CON_COMMAND_EXTERN( name, _funcname, description ) \
|
||||
void _funcname( const CCommand &args ); \
|
||||
static ConCommand name##_command( #name, _funcname, description ); \
|
||||
void _funcname( const CCommand &args )
|
||||
|
||||
#define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \
|
||||
void _funcname( const CCommand &args ); \
|
||||
static ConCommand name##_command( #name, _funcname, description, flags ); \
|
||||
void _funcname( const CCommand &args )
|
||||
|
||||
#define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \
|
||||
void _funcname( const CCommand &args ); \
|
||||
friend class CCommandMemberInitializer_##_funcname; \
|
||||
class CCommandMemberInitializer_##_funcname \
|
||||
{ \
|
||||
public: \
|
||||
CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \
|
||||
{ \
|
||||
m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \
|
||||
} \
|
||||
private: \
|
||||
CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \
|
||||
}; \
|
||||
\
|
||||
CCommandMemberInitializer_##_funcname m_##_funcname##_register; \
|
||||
|
||||
|
||||
#endif // CONVAR_H
|
||||
@@ -1,709 +0,0 @@
|
||||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Workfile: $
|
||||
// $Date: $
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef CONVAR_H
|
||||
#define CONVAR_H
|
||||
|
||||
#if _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/dbg.h"
|
||||
#include "tier1/iconvar.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "icvar.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define FORCEINLINE_CVAR FORCEINLINE
|
||||
#elif defined _LINUX || defined __APPLE__
|
||||
#define FORCEINLINE_CVAR inline
|
||||
#else
|
||||
#error "implement me"
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConVar;
|
||||
class CCommand;
|
||||
class ConCommand;
|
||||
class ConCommandBase;
|
||||
struct characterset_t;
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Any executable that wants to use ConVars need to implement one of
|
||||
// these to hook up access to console variables.
|
||||
//-----------------------------------------------------------------------------
|
||||
class IConCommandBaseAccessor
|
||||
{
|
||||
public:
|
||||
// Flags is a combination of FCVAR flags in cvar.h.
|
||||
// hOut is filled in with a handle to the variable.
|
||||
virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helper method for console development
|
||||
//-----------------------------------------------------------------------------
|
||||
#if defined( _X360 ) && !defined( _RETAIL )
|
||||
void ConVar_PublishToVXConsole();
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when a ConCommand needs to execute
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef void ( *FnCommandCallbackV1_t )( void );
|
||||
typedef void ( *FnCommandCallback_t )( const CCommand &command );
|
||||
|
||||
#define COMMAND_COMPLETION_MAXITEMS 64
|
||||
#define COMMAND_COMPLETION_ITEM_LENGTH 64
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef int ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Interface version
|
||||
//-----------------------------------------------------------------------------
|
||||
class ICommandCallback
|
||||
{
|
||||
public:
|
||||
virtual void CommandCallback( const CCommand &command ) = 0;
|
||||
};
|
||||
|
||||
class ICommandCompletionCallback
|
||||
{
|
||||
public:
|
||||
virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: The base console invoked command/cvar interface
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConCommandBase
|
||||
{
|
||||
friend class CCvar;
|
||||
friend class ConVar;
|
||||
friend class ConCommand;
|
||||
friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor );
|
||||
friend void ConVar_PublishToVXConsole();
|
||||
|
||||
// FIXME: Remove when ConVar changes are done
|
||||
friend class CDefaultCvar;
|
||||
|
||||
public:
|
||||
ConCommandBase( void );
|
||||
ConCommandBase( const char *pName, const char *pHelpString = 0,
|
||||
int flags = 0 );
|
||||
|
||||
virtual ~ConCommandBase( void );
|
||||
|
||||
virtual bool IsCommand( void ) const;
|
||||
|
||||
// Check flag
|
||||
virtual bool IsFlagSet( int flag ) const;
|
||||
// Set flag
|
||||
virtual void AddFlags( int flags );
|
||||
|
||||
// Return name of cvar
|
||||
virtual const char *GetName( void ) const;
|
||||
|
||||
// Return help text for cvar
|
||||
virtual const char *GetHelpText( void ) const;
|
||||
|
||||
// Deal with next pointer
|
||||
const ConCommandBase *GetNext( void ) const;
|
||||
ConCommandBase *GetNext( void );
|
||||
|
||||
void SetNext(ConCommandBase *pBase)
|
||||
{
|
||||
m_pNext = pBase;
|
||||
}
|
||||
|
||||
virtual bool IsRegistered( void ) const;
|
||||
|
||||
// Returns the DLL identifier
|
||||
virtual CVarDLLIdentifier_t GetDLLIdentifier() const;
|
||||
|
||||
protected:
|
||||
virtual void Create( const char *pName, const char *pHelpString = 0,
|
||||
int flags = 0 );
|
||||
|
||||
// Used internally by OneTimeInit to initialize/shutdown
|
||||
virtual void Init();
|
||||
void Shutdown();
|
||||
|
||||
// Internal copy routine ( uses new operator from correct module )
|
||||
char *CopyString( const char *from );
|
||||
|
||||
private:
|
||||
// Next ConVar in chain
|
||||
// Prior to register, it points to the next convar in the DLL.
|
||||
// Once registered, though, m_pNext is reset to point to the next
|
||||
// convar in the global list
|
||||
ConCommandBase *m_pNext;
|
||||
|
||||
// Has the cvar been added to the global list?
|
||||
bool m_bRegistered;
|
||||
|
||||
// Static data
|
||||
const char *m_pszName;
|
||||
const char *m_pszHelpString;
|
||||
|
||||
// ConVar flags
|
||||
int m_nFlags;
|
||||
|
||||
protected:
|
||||
// ConVars add themselves to this list for the executable.
|
||||
// Then ConVar_Register runs through all the console variables
|
||||
// and registers them into a global list stored in vstdlib.dll
|
||||
static ConCommandBase *s_pConCommandBases;
|
||||
|
||||
// ConVars in this executable use this 'global' to access values.
|
||||
static IConCommandBaseAccessor *s_pAccessor;
|
||||
public: // Hackalicous
|
||||
inline int GetFlags() const
|
||||
{
|
||||
return m_nFlags;
|
||||
}
|
||||
inline void SetFlags(int flags)
|
||||
{
|
||||
m_nFlags = flags;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Command tokenizer
|
||||
//-----------------------------------------------------------------------------
|
||||
class CCommand
|
||||
{
|
||||
public:
|
||||
CCommand();
|
||||
CCommand( int nArgC, const char **ppArgV );
|
||||
bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL );
|
||||
void Reset();
|
||||
|
||||
int ArgC() const;
|
||||
const char **ArgV() const;
|
||||
const char *ArgS() const; // All args that occur after the 0th arg, in string form
|
||||
const char *GetCommandString() const; // The entire command in string form, including the 0th arg
|
||||
const char *operator[]( int nIndex ) const; // Gets at arguments
|
||||
const char *Arg( int nIndex ) const; // Gets at arguments
|
||||
|
||||
// Helper functions to parse arguments to commands.
|
||||
const char* FindArg( const char *pName ) const;
|
||||
int FindArgInt( const char *pName, int nDefaultVal ) const;
|
||||
|
||||
static int MaxCommandLength();
|
||||
static characterset_t* DefaultBreakSet();
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
COMMAND_MAX_ARGC = 64,
|
||||
COMMAND_MAX_LENGTH = 512,
|
||||
};
|
||||
|
||||
int m_nArgc;
|
||||
int m_nArgv0Size;
|
||||
char m_pArgSBuffer[ COMMAND_MAX_LENGTH ];
|
||||
char m_pArgvBuffer[ COMMAND_MAX_LENGTH ];
|
||||
const char* m_ppArgv[ COMMAND_MAX_ARGC ];
|
||||
};
|
||||
|
||||
inline int CCommand::MaxCommandLength()
|
||||
{
|
||||
return COMMAND_MAX_LENGTH - 1;
|
||||
}
|
||||
|
||||
inline int CCommand::ArgC() const
|
||||
{
|
||||
return m_nArgc;
|
||||
}
|
||||
|
||||
inline const char **CCommand::ArgV() const
|
||||
{
|
||||
return m_nArgc ? (const char**)m_ppArgv : NULL;
|
||||
}
|
||||
|
||||
inline const char *CCommand::ArgS() const
|
||||
{
|
||||
return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : "";
|
||||
}
|
||||
|
||||
inline const char *CCommand::GetCommandString() const
|
||||
{
|
||||
return m_nArgc ? m_pArgSBuffer : "";
|
||||
}
|
||||
|
||||
inline const char *CCommand::Arg( int nIndex ) const
|
||||
{
|
||||
// FIXME: Many command handlers appear to not be particularly careful
|
||||
// about checking for valid argc range. For now, we're going to
|
||||
// do the extra check and return an empty string if it's out of range
|
||||
if ( nIndex < 0 || nIndex >= m_nArgc )
|
||||
return "";
|
||||
return m_ppArgv[nIndex];
|
||||
}
|
||||
|
||||
inline const char *CCommand::operator[]( int nIndex ) const
|
||||
{
|
||||
return Arg( nIndex );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: The console invoked command
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConCommand : public ConCommandBase
|
||||
{
|
||||
friend class CCvar;
|
||||
|
||||
public:
|
||||
typedef ConCommandBase BaseClass;
|
||||
|
||||
ConCommand( const char *pName, FnCommandCallbackV1_t callback,
|
||||
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
|
||||
ConCommand( const char *pName, FnCommandCallback_t callback,
|
||||
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
|
||||
ConCommand( const char *pName, ICommandCallback *pCallback,
|
||||
const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 );
|
||||
|
||||
virtual ~ConCommand( void );
|
||||
|
||||
virtual bool IsCommand( void ) const;
|
||||
|
||||
virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands );
|
||||
|
||||
virtual bool CanAutoComplete( void );
|
||||
|
||||
// Invoke the function
|
||||
virtual void Dispatch( const CCommand &command );
|
||||
|
||||
private:
|
||||
// NOTE: To maintain backward compat, we have to be very careful:
|
||||
// All public virtual methods must appear in the same order always
|
||||
// since engine code will be calling into this code, which *does not match*
|
||||
// in the mod code; it's using slightly different, but compatible versions
|
||||
// of this class. Also: Be very careful about adding new fields to this class.
|
||||
// Those fields will not exist in the version of this class that is instanced
|
||||
// in mod code.
|
||||
|
||||
// Call this function when executing the command
|
||||
union
|
||||
{
|
||||
FnCommandCallbackV1_t m_fnCommandCallbackV1;
|
||||
FnCommandCallback_t m_fnCommandCallback;
|
||||
ICommandCallback *m_pCommandCallback;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
FnCommandCompletionCallback m_fnCompletionCallback;
|
||||
ICommandCompletionCallback *m_pCommandCompletionCallback;
|
||||
};
|
||||
|
||||
bool m_bHasCompletionCallback : 1;
|
||||
bool m_bUsingNewCommandCallback : 1;
|
||||
bool m_bUsingCommandCallbackInterface : 1;
|
||||
public: // Hackalicous
|
||||
inline FnCommandCallback_t GetCallback() const
|
||||
{
|
||||
return m_fnCommandCallback;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: A console variable
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConVar : public ConCommandBase, public IConVar
|
||||
{
|
||||
friend class CCvar;
|
||||
friend class ConVarRef;
|
||||
|
||||
public:
|
||||
typedef ConCommandBase BaseClass;
|
||||
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags = 0);
|
||||
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||
const char *pHelpString );
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||
const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax );
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||
const char *pHelpString, FnChangeCallback_t callback );
|
||||
ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||
const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax,
|
||||
FnChangeCallback_t callback );
|
||||
|
||||
virtual ~ConVar( void );
|
||||
|
||||
virtual bool IsFlagSet( int flag ) const;
|
||||
virtual const char* GetHelpText( void ) const;
|
||||
virtual bool IsRegistered( void ) const;
|
||||
virtual const char *GetName( void ) const;
|
||||
virtual void AddFlags( int flags );
|
||||
virtual bool IsCommand( void ) const;
|
||||
|
||||
// Install a change callback (there shouldn't already be one....)
|
||||
void InstallChangeCallback( FnChangeCallback_t callback );
|
||||
|
||||
// Retrieve value
|
||||
FORCEINLINE_CVAR float GetFloat( void ) const;
|
||||
FORCEINLINE_CVAR int GetInt( void ) const;
|
||||
FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); }
|
||||
FORCEINLINE_CVAR char const *GetString( void ) const;
|
||||
|
||||
// Any function that allocates/frees memory needs to be virtual or else you'll have crashes
|
||||
// from alloc/free across dll/exe boundaries.
|
||||
|
||||
// These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue).
|
||||
virtual void SetValue( const char *value );
|
||||
virtual void SetValue( float value );
|
||||
virtual void SetValue( int value );
|
||||
|
||||
// Reset to default value
|
||||
void Revert( void );
|
||||
|
||||
// True if it has a min/max setting
|
||||
bool GetMin( float& minVal ) const;
|
||||
bool GetMax( float& maxVal ) const;
|
||||
const char *GetDefault( void ) const;
|
||||
|
||||
private:
|
||||
// Called by CCvar when the value of a var is changing.
|
||||
virtual void InternalSetValue(const char *value);
|
||||
// For CVARs marked FCVAR_NEVER_AS_STRING
|
||||
virtual void InternalSetFloatValue( float fNewValue );
|
||||
virtual void InternalSetIntValue( int nValue );
|
||||
|
||||
virtual bool ClampValue( float& value );
|
||||
virtual void ChangeStringValue( const char *tempVal, float flOldValue );
|
||||
|
||||
virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0,
|
||||
const char *pHelpString = 0, bool bMin = false, float fMin = 0.0,
|
||||
bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 );
|
||||
|
||||
// Used internally by OneTimeInit to initialize.
|
||||
virtual void Init();
|
||||
|
||||
private:
|
||||
|
||||
// This either points to "this" or it points to the original declaration of a ConVar.
|
||||
// This allows ConVars to exist in separate modules, and they all use the first one to be declared.
|
||||
// m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar).
|
||||
ConVar *m_pParent;
|
||||
|
||||
// Static data
|
||||
const char *m_pszDefaultValue;
|
||||
|
||||
// Value
|
||||
// Dynamically allocated
|
||||
char *m_pszString;
|
||||
int m_StringLength;
|
||||
|
||||
// Values
|
||||
float m_fValue;
|
||||
int m_nValue;
|
||||
|
||||
// Min/Max values
|
||||
bool m_bHasMin;
|
||||
float m_fMinVal;
|
||||
bool m_bHasMax;
|
||||
float m_fMaxVal;
|
||||
|
||||
// Call this function when ConVar changes
|
||||
FnChangeCallback_t m_fnChangeCallback;
|
||||
public: // Hackalicous
|
||||
inline FnChangeCallback_t GetCallback() const
|
||||
{
|
||||
return m_fnChangeCallback;
|
||||
}
|
||||
inline void SetMin(bool set, float min=0.0)
|
||||
{
|
||||
m_bHasMin = set;
|
||||
m_fMinVal = min;
|
||||
}
|
||||
inline void SetMax(bool set, float max=0.0)
|
||||
{
|
||||
m_bHasMax = set;
|
||||
m_fMaxVal = max;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as a float
|
||||
// Output : float
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR float ConVar::GetFloat( void ) const
|
||||
{
|
||||
return m_pParent->m_fValue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as an int
|
||||
// Output : int
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR int ConVar::GetInt( void ) const
|
||||
{
|
||||
return m_pParent->m_nValue;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
|
||||
// Output : const char *
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR const char *ConVar::GetString( void ) const
|
||||
{
|
||||
if ( m_nFlags & FCVAR_NEVER_AS_STRING )
|
||||
return "FCVAR_NEVER_AS_STRING";
|
||||
|
||||
return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : "";
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to read/write convars that already exist (replaces the FindVar method)
|
||||
//-----------------------------------------------------------------------------
|
||||
class ConVarRef
|
||||
{
|
||||
public:
|
||||
ConVarRef( const char *pName );
|
||||
ConVarRef( const char *pName, bool bIgnoreMissing );
|
||||
ConVarRef( IConVar *pConVar );
|
||||
|
||||
void Init( const char *pName, bool bIgnoreMissing );
|
||||
bool IsValid() const;
|
||||
bool IsFlagSet( int nFlags ) const;
|
||||
IConVar *GetLinkedConVar();
|
||||
|
||||
// Get/Set value
|
||||
float GetFloat( void ) const;
|
||||
int GetInt( void ) const;
|
||||
bool GetBool() const { return !!GetInt(); }
|
||||
const char *GetString( void ) const;
|
||||
|
||||
void SetValue( const char *pValue );
|
||||
void SetValue( float flValue );
|
||||
void SetValue( int nValue );
|
||||
void SetValue( bool bValue );
|
||||
|
||||
const char *GetName() const;
|
||||
|
||||
const char *GetDefault() const;
|
||||
|
||||
private:
|
||||
// High-speed method to read convar data
|
||||
IConVar *m_pConVar;
|
||||
ConVar *m_pConVarState;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Did we find an existing convar of that name?
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const
|
||||
{
|
||||
return ( m_pConVar->IsFlagSet( nFlags ) != 0 );
|
||||
}
|
||||
|
||||
FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar()
|
||||
{
|
||||
return m_pConVar;
|
||||
}
|
||||
|
||||
FORCEINLINE_CVAR const char *ConVarRef::GetName() const
|
||||
{
|
||||
return m_pConVar->GetName();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as a float
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const
|
||||
{
|
||||
return m_pConVarState->m_fValue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as an int
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const
|
||||
{
|
||||
return m_pConVarState->m_nValue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const
|
||||
{
|
||||
Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
|
||||
return m_pConVarState->m_pszString;
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue )
|
||||
{
|
||||
m_pConVar->SetValue( pValue );
|
||||
}
|
||||
|
||||
FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue )
|
||||
{
|
||||
m_pConVar->SetValue( flValue );
|
||||
}
|
||||
|
||||
FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue )
|
||||
{
|
||||
m_pConVar->SetValue( nValue );
|
||||
}
|
||||
|
||||
FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue )
|
||||
{
|
||||
m_pConVar->SetValue( bValue ? 1 : 0 );
|
||||
}
|
||||
|
||||
FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const
|
||||
{
|
||||
return m_pConVarState->m_pszDefaultValue;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called by the framework to register ConCommands with the ICVar
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL );
|
||||
void ConVar_Unregister( );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Utility methods
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar_PrintFlags( const ConCommandBase *var );
|
||||
void ConVar_PrintDescription( const ConCommandBase *pVar );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Utility class to quickly allow ConCommands to call member methods
|
||||
//-----------------------------------------------------------------------------
|
||||
#if defined _MSC_VER
|
||||
#pragma warning (disable : 4355 )
|
||||
#endif
|
||||
|
||||
template< class T >
|
||||
class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback
|
||||
{
|
||||
typedef ConCommand BaseClass;
|
||||
typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command );
|
||||
typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands );
|
||||
|
||||
public:
|
||||
CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0,
|
||||
int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) :
|
||||
BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL )
|
||||
{
|
||||
m_pOwner = pOwner;
|
||||
m_Func = callback;
|
||||
m_CompletionFunc = completionFunc;
|
||||
}
|
||||
|
||||
~CConCommandMemberAccessor()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
void SetOwner( T* pOwner )
|
||||
{
|
||||
m_pOwner = pOwner;
|
||||
}
|
||||
|
||||
virtual void CommandCallback( const CCommand &command )
|
||||
{
|
||||
Assert( m_pOwner && m_Func );
|
||||
(m_pOwner->*m_Func)( command );
|
||||
}
|
||||
|
||||
virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands )
|
||||
{
|
||||
Assert( m_pOwner && m_CompletionFunc );
|
||||
return (m_pOwner->*m_CompletionFunc)( pPartial, commands );
|
||||
}
|
||||
|
||||
private:
|
||||
T* m_pOwner;
|
||||
FnMemberCommandCallback_t m_Func;
|
||||
FnMemberCommandCompletionCallback_t m_CompletionFunc;
|
||||
};
|
||||
|
||||
#if defined _MSC_VER
|
||||
#pragma warning ( default : 4355 )
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Utility macros to quicky generate a simple console command
|
||||
//-----------------------------------------------------------------------------
|
||||
#define CON_COMMAND( name, description ) \
|
||||
static void name( const CCommand &args ); \
|
||||
static ConCommand name##_command( #name, name, description ); \
|
||||
static void name( const CCommand &args )
|
||||
|
||||
#define CON_COMMAND_F( name, description, flags ) \
|
||||
static void name( const CCommand &args ); \
|
||||
static ConCommand name##_command( #name, name, description, flags ); \
|
||||
static void name( const CCommand &args )
|
||||
|
||||
#define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \
|
||||
static void name( const CCommand &args ); \
|
||||
static ConCommand name##_command( #name, name, description, flags, completion ); \
|
||||
static void name( const CCommand &args )
|
||||
|
||||
#define CON_COMMAND_EXTERN( name, _funcname, description ) \
|
||||
void _funcname( const CCommand &args ); \
|
||||
static ConCommand name##_command( #name, _funcname, description ); \
|
||||
void _funcname( const CCommand &args )
|
||||
|
||||
#define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \
|
||||
void _funcname( const CCommand &args ); \
|
||||
static ConCommand name##_command( #name, _funcname, description, flags ); \
|
||||
void _funcname( const CCommand &args )
|
||||
|
||||
#define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \
|
||||
void _funcname( const CCommand &args ); \
|
||||
friend class CCommandMemberInitializer_##_funcname; \
|
||||
class CCommandMemberInitializer_##_funcname \
|
||||
{ \
|
||||
public: \
|
||||
CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \
|
||||
{ \
|
||||
m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \
|
||||
} \
|
||||
private: \
|
||||
CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \
|
||||
}; \
|
||||
\
|
||||
CCommandMemberInitializer_##_funcname m_##_funcname##_register; \
|
||||
|
||||
|
||||
#endif // CONVAR_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -45,6 +45,7 @@ static Queue<FrameAction> *frame_actions;
|
||||
static float g_LastMenuTime = 0.0f;
|
||||
static float g_LastAuthCheck = 0.0f;
|
||||
bool g_PendingInternalPush = false;
|
||||
bool g_PendingAuthCheck = false;
|
||||
|
||||
class FrameActionInit : public SMGlobalClass
|
||||
{
|
||||
@@ -114,9 +115,16 @@ void RunFrameHooks(bool simulating)
|
||||
g_LastMenuTime = curtime;
|
||||
}
|
||||
|
||||
if (*g_NumPlayersToAuth && curtime - g_LastAuthCheck >= 0.7f)
|
||||
/* g_PendingAuthCheck is set by the NetworkIDValidated hook so that a client
|
||||
* whose Steam ticket was just validated is authorized on the next frame rather
|
||||
* than waiting up to 0.7s for the periodic check. It's deferred to the next frame
|
||||
* (instead of authorizing inline in the hook) because the engine doesn't flag the
|
||||
* client as fully authenticated until after the NetworkIDValidated callback returns.
|
||||
*/
|
||||
if (*g_NumPlayersToAuth && (g_PendingAuthCheck || curtime - g_LastAuthCheck >= 0.7f))
|
||||
{
|
||||
g_Players.RunAuthChecks();
|
||||
g_LastAuthCheck = curtime;
|
||||
g_PendingAuthCheck = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ struct FrameAction
|
||||
};
|
||||
|
||||
extern bool g_PendingInternalPush;
|
||||
extern bool g_PendingAuthCheck;
|
||||
|
||||
void AddFrameAction(const FrameAction & action);
|
||||
void RunFrameHooks(bool simulating);
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
#include <IADTFactory.h>
|
||||
#include "common_logic.h"
|
||||
#include <sm_stringhashmap.h>
|
||||
#include <sm_hashmap.h>
|
||||
|
||||
using namespace SourceMod;
|
||||
|
||||
|
||||
+95
-85
@@ -1,92 +1,102 @@
|
||||
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
|
||||
import os
|
||||
|
||||
binary = SM.Library(builder, 'sourcemod.logic')
|
||||
binary.compiler.cxxincludes += [
|
||||
builder.sourcePath,
|
||||
os.path.join(builder.sourcePath, 'core', 'logic'),
|
||||
os.path.join(builder.sourcePath, 'public'),
|
||||
os.path.join(builder.sourcePath, 'sourcepawn', 'include'),
|
||||
os.path.join(builder.sourcePath, 'public', 'amtl', 'amtl'),
|
||||
os.path.join(builder.sourcePath, 'public', 'amtl'),
|
||||
os.path.join(SM.mms_root, 'core', 'sourcehook')
|
||||
]
|
||||
binary.compiler.defines += [
|
||||
'SM_DEFAULT_THREADER',
|
||||
'SM_LOGIC'
|
||||
]
|
||||
for cxx in builder.targets:
|
||||
binary = SM.Library(builder, cxx, 'sourcemod.logic')
|
||||
binary.compiler.cxxincludes += [
|
||||
builder.sourcePath,
|
||||
os.path.join(builder.sourcePath, 'core', 'logic'),
|
||||
os.path.join(builder.sourcePath, 'public'),
|
||||
os.path.join(builder.sourcePath, 'sourcepawn', 'include'),
|
||||
os.path.join(builder.sourcePath, 'sourcepawn'),
|
||||
os.path.join(builder.sourcePath, 'sourcepawn', 'vm'),
|
||||
os.path.join(builder.sourcePath, 'public', 'amtl', 'amtl'),
|
||||
os.path.join(builder.sourcePath, 'public', 'amtl'),
|
||||
os.path.join(SM.mms_root, 'core', 'sourcehook')
|
||||
]
|
||||
binary.compiler.defines += [
|
||||
'SM_DEFAULT_THREADER',
|
||||
'SM_LOGIC'
|
||||
]
|
||||
SP.AddVmFlags(binary)
|
||||
|
||||
if builder.target.platform == 'linux':
|
||||
binary.compiler.postlink += ['-lpthread', '-lrt']
|
||||
elif builder.target.platform == 'mac':
|
||||
binary.compiler.cflags += ['-Wno-deprecated-declarations']
|
||||
binary.compiler.postlink += ['-framework', 'CoreServices']
|
||||
if binary.compiler.target.platform == 'linux':
|
||||
binary.compiler.postlink += ['-lpthread', '-lrt', '-lm']
|
||||
elif binary.compiler.target.platform == 'mac':
|
||||
binary.compiler.cflags += ['-Wno-deprecated-declarations']
|
||||
binary.compiler.postlink += ['-framework', 'CoreServices', '-lm']
|
||||
|
||||
if binary.compiler.family == 'gcc' or binary.compiler.family == 'clang':
|
||||
binary.compiler.cxxflags += ['-fno-rtti']
|
||||
elif binary.compiler.family == 'msvc':
|
||||
binary.compiler.cxxflags += ['/GR-']
|
||||
target = binary.compiler.target
|
||||
binary.compiler.linkflags += [
|
||||
SP.static_libsp[target],
|
||||
SP.libamtl[target],
|
||||
SP.zlib[target],
|
||||
SP.mimalloc[target],
|
||||
]
|
||||
|
||||
binary.sources += [
|
||||
'common_logic.cpp',
|
||||
'smn_adt_array.cpp',
|
||||
'smn_sorting.cpp',
|
||||
'smn_maplists.cpp',
|
||||
'ADTFactory.cpp',
|
||||
'smn_adt_stack.cpp',
|
||||
'thread/ThreadWorker.cpp',
|
||||
'thread/BaseWorker.cpp',
|
||||
'ThreadSupport.cpp',
|
||||
'smn_float.cpp',
|
||||
'TextParsers.cpp',
|
||||
'smn_textparse.cpp',
|
||||
'smn_adt_trie.cpp',
|
||||
'smn_functions.cpp',
|
||||
'smn_timers.cpp',
|
||||
'smn_players.cpp',
|
||||
'MemoryUtils.cpp',
|
||||
'smn_admin.cpp',
|
||||
'smn_banning.cpp',
|
||||
'smn_filesystem.cpp',
|
||||
'stringutil.cpp',
|
||||
'Translator.cpp',
|
||||
'PhraseCollection.cpp',
|
||||
'smn_lang.cpp',
|
||||
'smn_string.cpp',
|
||||
'smn_handles.cpp',
|
||||
'smn_datapacks.cpp',
|
||||
'smn_gameconfigs.cpp',
|
||||
'smn_fakenatives.cpp',
|
||||
'GameConfigs.cpp',
|
||||
'sm_crc32.cpp',
|
||||
'smn_profiler.cpp',
|
||||
'ShareSys.cpp',
|
||||
'PluginSys.cpp',
|
||||
'HandleSys.cpp',
|
||||
'NativeOwner.cpp',
|
||||
'ExtensionSys.cpp',
|
||||
'DebugReporter.cpp',
|
||||
'Database.cpp',
|
||||
'smn_database.cpp',
|
||||
'ForwardSys.cpp',
|
||||
'AdminCache.cpp',
|
||||
'sm_trie.cpp',
|
||||
'smn_console.cpp',
|
||||
'ProfileTools.cpp',
|
||||
'Logger.cpp',
|
||||
'smn_core.cpp',
|
||||
'smn_menus.cpp',
|
||||
'sprintf.cpp',
|
||||
'LibrarySys.cpp',
|
||||
'RootConsoleMenu.cpp',
|
||||
'CDataPack.cpp',
|
||||
'frame_tasks.cpp',
|
||||
'smn_halflife.cpp',
|
||||
'FrameIterator.cpp',
|
||||
]
|
||||
if builder.target.platform == 'windows':
|
||||
binary.sources += ['thread/WinThreads.cpp']
|
||||
else:
|
||||
binary.sources += ['thread/PosixThreads.cpp']
|
||||
if binary.compiler.family == 'gcc' or binary.compiler.family == 'clang':
|
||||
binary.compiler.cxxflags += ['-fno-rtti', '-Wno-invalid-offsetof']
|
||||
elif binary.compiler.family == 'msvc':
|
||||
binary.compiler.cxxflags += ['/GR-']
|
||||
|
||||
SM.binaries += [builder.Add(binary)]
|
||||
binary.sources += [
|
||||
'common_logic.cpp',
|
||||
'smn_adt_array.cpp',
|
||||
'smn_sorting.cpp',
|
||||
'smn_maplists.cpp',
|
||||
'ADTFactory.cpp',
|
||||
'smn_adt_stack.cpp',
|
||||
'BaseWorker.cpp',
|
||||
'ThreadSupport.cpp',
|
||||
'smn_float.cpp',
|
||||
'TextParsers.cpp',
|
||||
'smn_textparse.cpp',
|
||||
'smn_adt_trie.cpp',
|
||||
'smn_functions.cpp',
|
||||
'smn_timers.cpp',
|
||||
'smn_players.cpp',
|
||||
'MemoryUtils.cpp',
|
||||
'smn_admin.cpp',
|
||||
'smn_banning.cpp',
|
||||
'smn_filesystem.cpp',
|
||||
'stringutil.cpp',
|
||||
'Translator.cpp',
|
||||
'PhraseCollection.cpp',
|
||||
'smn_lang.cpp',
|
||||
'smn_string.cpp',
|
||||
'smn_handles.cpp',
|
||||
'smn_datapacks.cpp',
|
||||
'smn_gameconfigs.cpp',
|
||||
'smn_fakenatives.cpp',
|
||||
'GameConfigs.cpp',
|
||||
'sm_crc32.cpp',
|
||||
'smn_profiler.cpp',
|
||||
'ShareSys.cpp',
|
||||
'PluginSys.cpp',
|
||||
'HandleSys.cpp',
|
||||
'NativeOwner.cpp',
|
||||
'ExtensionSys.cpp',
|
||||
'DebugReporter.cpp',
|
||||
'Database.cpp',
|
||||
'smn_database.cpp',
|
||||
'ForwardSys.cpp',
|
||||
'AdminCache.cpp',
|
||||
'sm_trie.cpp',
|
||||
'smn_console.cpp',
|
||||
'ProfileTools.cpp',
|
||||
'Logger.cpp',
|
||||
'smn_core.cpp',
|
||||
'smn_menus.cpp',
|
||||
'sprintf.cpp',
|
||||
'LibrarySys.cpp',
|
||||
'RootConsoleMenu.cpp',
|
||||
'CDataPack.cpp',
|
||||
'frame_tasks.cpp',
|
||||
'smn_halflife.cpp',
|
||||
'FrameIterator.cpp',
|
||||
'DatabaseConfBuilder.cpp',
|
||||
'LumpManager.cpp',
|
||||
'smn_entitylump.cpp'
|
||||
]
|
||||
|
||||
SM.binaries += [builder.Add(binary)]
|
||||
|
||||
+17
-23
@@ -233,8 +233,7 @@ AdminCache::~AdminCache()
|
||||
DumpAdminCache(AdminCache_Overrides, false);
|
||||
DumpAdminCache(AdminCache_Groups, false);
|
||||
|
||||
List<AuthMethod *>::iterator iter;
|
||||
for (iter=m_AuthMethods.begin();
|
||||
for (auto iter=m_AuthMethods.begin();
|
||||
iter!=m_AuthMethods.end();
|
||||
iter++)
|
||||
{
|
||||
@@ -759,8 +758,7 @@ bool AdminCache::GetGroupCommandOverride(GroupId id, const char *name, OverrideT
|
||||
|
||||
AuthMethod *AdminCache::GetMethodByIndex(unsigned int index)
|
||||
{
|
||||
List<AuthMethod *>::iterator iter;
|
||||
for (iter=m_AuthMethods.begin();
|
||||
for (auto iter=m_AuthMethods.begin();
|
||||
iter!=m_AuthMethods.end();
|
||||
iter++)
|
||||
{
|
||||
@@ -974,8 +972,7 @@ void AdminCache::InvalidateAdminCache(bool unlink_admins)
|
||||
}
|
||||
}
|
||||
/* Wipe the identity cache first */
|
||||
List<AuthMethod *>::iterator iter;
|
||||
for (iter=m_AuthMethods.begin();
|
||||
for (auto iter=m_AuthMethods.begin();
|
||||
iter!=m_AuthMethods.end();
|
||||
iter++)
|
||||
{
|
||||
@@ -998,7 +995,6 @@ void AdminCache::InvalidateAdminCache(bool unlink_admins)
|
||||
|
||||
void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild)
|
||||
{
|
||||
List<IAdminListener *>::iterator iter;
|
||||
IAdminListener *pListener;
|
||||
|
||||
if (part == AdminCache_Overrides)
|
||||
@@ -1007,7 +1003,7 @@ void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild)
|
||||
DumpCommandOverrideCache(Override_CommandGroup);
|
||||
if (rebuild && !m_destroying)
|
||||
{
|
||||
for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
|
||||
for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
|
||||
{
|
||||
pListener = (*iter);
|
||||
pListener->OnRebuildOverrideCache();
|
||||
@@ -1021,7 +1017,7 @@ void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild)
|
||||
InvalidateGroupCache();
|
||||
if (rebuild && !m_destroying)
|
||||
{
|
||||
for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
|
||||
for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
|
||||
{
|
||||
pListener = (*iter);
|
||||
pListener->OnRebuildGroupCache();
|
||||
@@ -1033,7 +1029,7 @@ void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild)
|
||||
InvalidateAdminCache(true);
|
||||
if (rebuild && !m_destroying)
|
||||
{
|
||||
for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
|
||||
for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
|
||||
{
|
||||
pListener = (*iter);
|
||||
pListener->OnRebuildAdminCache((part == AdminCache_Groups));
|
||||
@@ -1058,9 +1054,8 @@ const char *AdminCache::GetAdminName(AdminId id)
|
||||
|
||||
bool AdminCache::GetMethodIndex(const char *name, unsigned int *_index)
|
||||
{
|
||||
List<AuthMethod *>::iterator iter;
|
||||
unsigned int index = 0;
|
||||
for (iter=m_AuthMethods.begin();
|
||||
for (auto iter=m_AuthMethods.begin();
|
||||
iter!=m_AuthMethods.end();
|
||||
iter++,index++)
|
||||
{
|
||||
@@ -1090,14 +1085,14 @@ bool AdminCache::GetUnifiedSteamIdentity(const char *ident, char *out, size_t ma
|
||||
else if (len >= 11 && !strncmp(ident, "STEAM_", 6) && ident[8] != '_')
|
||||
{
|
||||
// non-bot/lan Steam2 Id, strip off the STEAM_* part
|
||||
snprintf(out, maxlen, "%s", &ident[8]);
|
||||
ke::SafeStrcpy(out, maxlen, &ident[8]);
|
||||
return true;
|
||||
}
|
||||
else if (len >= 7 && !strncmp(ident, "[U:", 3) && ident[len-1] == ']')
|
||||
{
|
||||
// Steam3 Id, replicate the Steam2 Post-"STEAM_" part
|
||||
uint32_t accountId = strtoul(&ident[5], nullptr, 10);
|
||||
snprintf(out, maxlen, "%u:%u", accountId & 1, accountId >> 1);
|
||||
ke::SafeSprintf(out, maxlen, "%u:%u", accountId & 1, accountId >> 1);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -1124,7 +1119,7 @@ bool AdminCache::GetUnifiedSteamIdentity(const char *ident, char *out, size_t ma
|
||||
&& accountType == k_EAccountTypeIndividual && accountInstance <= k_unSteamUserWebInstance
|
||||
)
|
||||
{
|
||||
snprintf(out, maxlen, "%u:%u", accountId & 1, accountId >> 1);
|
||||
ke::SafeSprintf(out, maxlen, "%u:%u", accountId & 1, accountId >> 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1581,7 +1576,7 @@ bool AdminCache::CanAdminTarget(AdminId id, AdminId target)
|
||||
{
|
||||
id = grp_table[i];
|
||||
num = GetGroupImmunityCount(id);
|
||||
for (unsigned int j=0; j<num; i++)
|
||||
for (unsigned int j=0; j<num; j++)
|
||||
{
|
||||
other = GetGroupImmunity(id, j);
|
||||
for (unsigned int k=0; k<pUser->grp_count; k++)
|
||||
@@ -1843,13 +1838,13 @@ bool AdminCache::DumpCache(const char *filename)
|
||||
fprintf(fp, "\n\t\t\"Overrides\"\n\t\t{\n");
|
||||
if (pGroup->pCmdGrpTable != NULL)
|
||||
{
|
||||
for (OverrideMap::iterator iter = pGroup->pCmdTable->iter(); !iter.empty(); iter.next())
|
||||
iterator_group_grp_override(fp, iter->key.chars(), iter->value);
|
||||
for (OverrideMap::iterator iter = pGroup->pCmdGrpTable->iter(); !iter.empty(); iter.next())
|
||||
iterator_group_grp_override(fp, iter->key.c_str(), iter->value);
|
||||
}
|
||||
if (pGroup->pCmdTable != NULL)
|
||||
{
|
||||
for (OverrideMap::iterator iter = pGroup->pCmdTable->iter(); !iter.empty(); iter.next())
|
||||
iterator_group_basic_override(fp, iter->key.chars(), iter->value);
|
||||
iterator_group_basic_override(fp, iter->key.c_str(), iter->value);
|
||||
}
|
||||
fprintf(fp, "\t\t}\n");
|
||||
|
||||
@@ -1924,9 +1919,9 @@ bool AdminCache::DumpCache(const char *filename)
|
||||
|
||||
fprintf(fp, "\"Overrides\"\n{\n");
|
||||
for (FlagMap::iterator iter = m_CmdGrpOverrides.iter(); !iter.empty(); iter.next())
|
||||
iterator_glob_grp_override(fp, iter->key.chars(), iter->value);
|
||||
iterator_glob_grp_override(fp, iter->key.c_str(), iter->value);
|
||||
for (FlagMap::iterator iter = m_CmdOverrides.iter(); !iter.empty(); iter.next())
|
||||
iterator_glob_basic_override(fp, iter->key.chars(), iter->value);
|
||||
iterator_glob_basic_override(fp, iter->key.c_str(), iter->value);
|
||||
fprintf(fp, "}\n");
|
||||
|
||||
fclose(fp);
|
||||
@@ -1962,8 +1957,7 @@ AdminUser *AdminCache::GetUser(AdminId aid)
|
||||
|
||||
const char *AdminCache::GetMethodName(unsigned int index)
|
||||
{
|
||||
List<AuthMethod *>::iterator iter;
|
||||
for (iter=m_AuthMethods.begin();
|
||||
for (auto iter=m_AuthMethods.begin();
|
||||
iter!=m_AuthMethods.end();
|
||||
iter++)
|
||||
{
|
||||
|
||||
+10
-8
@@ -36,14 +36,12 @@
|
||||
#include <IAdminSystem.h>
|
||||
#include "sm_memtable.h"
|
||||
#include <sm_trie.h>
|
||||
#include <sh_list.h>
|
||||
#include <sh_string.h>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <IForwardSys.h>
|
||||
#include <sm_stringhashmap.h>
|
||||
#include <sm_hashmap.h>
|
||||
#include <sm_namehashset.h>
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
#define GRP_MAGIC_SET 0xDEADFADE
|
||||
#define GRP_MAGIC_UNSET 0xFACEFACE
|
||||
#define USR_MAGIC_SET 0xDEADFACE
|
||||
@@ -70,7 +68,7 @@ struct AdminGroup
|
||||
|
||||
struct AuthMethod
|
||||
{
|
||||
String name;
|
||||
std::string name;
|
||||
StringHashMap<AdminId> identities;
|
||||
|
||||
AuthMethod(const char *name)
|
||||
@@ -82,6 +80,10 @@ struct AuthMethod
|
||||
{
|
||||
return strcmp(name, method->name.c_str()) == 0;
|
||||
}
|
||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
||||
{
|
||||
return key.hash();
|
||||
}
|
||||
};
|
||||
|
||||
struct UserAuth
|
||||
@@ -210,8 +212,8 @@ public:
|
||||
int m_LastGroup;
|
||||
int m_FreeGroupList;
|
||||
StringHashMap<GroupId> m_Groups;
|
||||
List<IAdminListener *> m_hooks;
|
||||
List<AuthMethod *> m_AuthMethods;
|
||||
std::list<IAdminListener *> m_hooks;
|
||||
std::list<AuthMethod *> m_AuthMethods;
|
||||
NameHashSet<AuthMethod *> m_AuthTables;
|
||||
IForward *m_pCacheFwd;
|
||||
int m_FirstUser;
|
||||
|
||||
@@ -40,7 +40,7 @@ BaseWorker::BaseWorker(IThreadWorkerCallbacks *hooks) :
|
||||
|
||||
BaseWorker::~BaseWorker()
|
||||
{
|
||||
if (m_state != Worker_Stopped || m_state != Worker_Invalid)
|
||||
if (m_state != Worker_Stopped && m_state != Worker_Invalid)
|
||||
Stop(true);
|
||||
|
||||
if (m_ThreadQueue.size())
|
||||
@@ -109,10 +109,9 @@ SWThreadHandle *BaseWorker::PopThreadFromQueue()
|
||||
if (!m_ThreadQueue.size())
|
||||
return NULL;
|
||||
|
||||
SourceHook::List<SWThreadHandle *>::iterator begin;
|
||||
SWThreadHandle *swt;
|
||||
|
||||
begin = m_ThreadQueue.begin();
|
||||
auto begin = m_ThreadQueue.begin();
|
||||
swt = (*begin);
|
||||
m_ThreadQueue.erase(begin);
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_BASEWORKER_H
|
||||
#define _INCLUDE_SOURCEMOD_BASEWORKER_H
|
||||
|
||||
#include "sh_list.h"
|
||||
#include <list>
|
||||
#include "ThreadSupport.h"
|
||||
|
||||
#define SM_DEFAULT_THREADS_PER_FRAME 1
|
||||
@@ -43,6 +43,7 @@ class BaseWorker;
|
||||
class SWThreadHandle : public IThreadHandle
|
||||
{
|
||||
friend class BaseWorker;
|
||||
friend class CompatWorker;
|
||||
public:
|
||||
SWThreadHandle(IThreadCreator *parent, const ThreadParams *p, IThread *thread);
|
||||
IThread *GetThread();
|
||||
@@ -95,7 +96,7 @@ public: //BaseWorker
|
||||
virtual void AddThreadToQueue(SWThreadHandle *pHandle);
|
||||
virtual SWThreadHandle *PopThreadFromQueue();
|
||||
protected:
|
||||
SourceHook::List<SWThreadHandle *> m_ThreadQueue;
|
||||
std::list<SWThreadHandle *> m_ThreadQueue;
|
||||
unsigned int m_perFrame;
|
||||
volatile WorkerState m_state;
|
||||
IThreadWorkerCallbacks *m_pHooks;
|
||||
+205
-258
@@ -31,327 +31,274 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "CDataPack.h"
|
||||
#include <amtl/am-autoptr.h>
|
||||
#include <amtl/am-vector.h>
|
||||
|
||||
using namespace ke;
|
||||
|
||||
#define DATAPACK_INITIAL_SIZE 64
|
||||
|
||||
CDataPack::CDataPack()
|
||||
{
|
||||
m_pBase = (char *)malloc(DATAPACK_INITIAL_SIZE);
|
||||
m_capacity = DATAPACK_INITIAL_SIZE;
|
||||
Initialize();
|
||||
}
|
||||
|
||||
CDataPack::~CDataPack()
|
||||
{
|
||||
free(m_pBase);
|
||||
}
|
||||
|
||||
static Vector<AutoPtr<CDataPack>> sDataPackCache;
|
||||
|
||||
IDataPack * CDataPack::New()
|
||||
{
|
||||
if (sDataPackCache.empty())
|
||||
return new CDataPack();
|
||||
|
||||
CDataPack *pack = sDataPackCache.back().take();
|
||||
sDataPackCache.pop();
|
||||
pack->Initialize();
|
||||
return pack;
|
||||
}
|
||||
|
||||
void
|
||||
CDataPack::Free(IDataPack *pack)
|
||||
{
|
||||
sDataPackCache.append(static_cast<CDataPack *>(pack));
|
||||
Initialize();
|
||||
}
|
||||
|
||||
void CDataPack::Initialize()
|
||||
{
|
||||
m_curptr = m_pBase;
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
void CDataPack::CheckSize(size_t typesize)
|
||||
{
|
||||
if (m_curptr - m_pBase + typesize <= m_capacity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
size_t pos = m_curptr - m_pBase;
|
||||
position = 0;
|
||||
|
||||
do
|
||||
{
|
||||
m_capacity *= 2;
|
||||
} while (pos + typesize > m_capacity);
|
||||
|
||||
m_pBase = (char *)realloc(m_pBase, m_capacity);
|
||||
m_curptr = m_pBase + pos;
|
||||
} while (this->RemoveItem());
|
||||
|
||||
elements.clear();
|
||||
}
|
||||
|
||||
void CDataPack::ResetSize()
|
||||
{
|
||||
m_size = 0;
|
||||
Initialize();
|
||||
}
|
||||
|
||||
size_t CDataPack::CreateMemory(size_t size, void **addr)
|
||||
{
|
||||
CheckSize(sizeof(char) + sizeof(size_t) + size);
|
||||
size_t pos = m_curptr - m_pBase;
|
||||
InternalPack val;
|
||||
val.type = CDataPackType::Raw;
|
||||
val.pData.vval = new uint8_t[size + sizeof(size)];
|
||||
reinterpret_cast<size_t *>(val.pData.vval)[0] = size;
|
||||
elements.emplace(elements.begin() + position, val);
|
||||
|
||||
*(char *)m_curptr = Raw;
|
||||
m_curptr += sizeof(char);
|
||||
|
||||
*(size_t *)m_curptr = size;
|
||||
m_curptr += sizeof(size_t);
|
||||
|
||||
if (addr)
|
||||
{
|
||||
*addr = m_curptr;
|
||||
}
|
||||
|
||||
m_curptr += size;
|
||||
m_size += sizeof(char) + sizeof(size_t) + size;
|
||||
|
||||
return pos;
|
||||
return position++;
|
||||
}
|
||||
|
||||
void CDataPack::PackCell(cell_t cell)
|
||||
{
|
||||
CheckSize(sizeof(char) + sizeof(size_t) + sizeof(cell_t));
|
||||
|
||||
*(char *)m_curptr = Cell;
|
||||
m_curptr += sizeof(char);
|
||||
|
||||
*(size_t *)m_curptr = sizeof(cell_t);
|
||||
m_curptr += sizeof(size_t);
|
||||
|
||||
*(cell_t *)m_curptr = cell;
|
||||
m_curptr += sizeof(cell_t);
|
||||
|
||||
m_size += sizeof(char) + sizeof(size_t) + sizeof(cell_t);
|
||||
InternalPack val;
|
||||
val.type = CDataPackType::Cell;
|
||||
val.pData.cval = cell;
|
||||
elements.emplace(elements.begin() + position, val);
|
||||
position++;
|
||||
}
|
||||
|
||||
void CDataPack::PackFloat(float val)
|
||||
void CDataPack::PackFunction(cell_t function)
|
||||
{
|
||||
CheckSize(sizeof(char) + sizeof(size_t) + sizeof(float));
|
||||
InternalPack val;
|
||||
val.type = CDataPackType::Function;
|
||||
val.pData.cval = function;
|
||||
elements.emplace(elements.begin() + position, val);
|
||||
position++;
|
||||
}
|
||||
|
||||
*(char *)m_curptr = Float;
|
||||
m_curptr += sizeof(char);
|
||||
|
||||
*(size_t *)m_curptr = sizeof(float);
|
||||
m_curptr += sizeof(size_t);
|
||||
|
||||
*(float *)m_curptr = val;
|
||||
m_curptr += sizeof(float);
|
||||
|
||||
m_size += sizeof(char) + sizeof(size_t) + sizeof(float);
|
||||
void CDataPack::PackFloat(float floatval)
|
||||
{
|
||||
InternalPack val;
|
||||
val.type = CDataPackType::Float;
|
||||
val.pData.fval = floatval;
|
||||
elements.emplace(elements.begin() + position, val);
|
||||
position++;
|
||||
}
|
||||
|
||||
void CDataPack::PackString(const char *string)
|
||||
{
|
||||
size_t len = strlen(string);
|
||||
size_t maxsize = sizeof(char) + sizeof(size_t) + len + 1;
|
||||
CheckSize(maxsize);
|
||||
InternalPack val;
|
||||
val.type = CDataPackType::String;
|
||||
std::string *sval = new std::string(string);
|
||||
val.pData.sval = sval;
|
||||
elements.emplace(elements.begin() + position, val);
|
||||
position++;
|
||||
}
|
||||
|
||||
*(char *)m_curptr = String;
|
||||
m_curptr += sizeof(char);
|
||||
void CDataPack::PackCellArray(cell_t const *vals, cell_t count)
|
||||
{
|
||||
InternalPack val;
|
||||
val.type = CDataPackType::CellArray;
|
||||
|
||||
// Pack the string length first for buffer overrun checking.
|
||||
*(size_t *)m_curptr = len;
|
||||
m_curptr += sizeof(size_t);
|
||||
val.pData.aval = new cell_t [count + 1];
|
||||
memcpy(&val.pData.aval[1], vals, sizeof(cell_t) * count);
|
||||
val.pData.aval[0] = count;
|
||||
elements.emplace(elements.begin() + position, val);
|
||||
position++;
|
||||
}
|
||||
|
||||
// Now pack the string.
|
||||
memcpy(m_curptr, string, len);
|
||||
m_curptr[len] = '\0';
|
||||
m_curptr += len + 1;
|
||||
void CDataPack::PackFloatArray(cell_t const *vals, cell_t count)
|
||||
{
|
||||
InternalPack val;
|
||||
val.type = CDataPackType::FloatArray;
|
||||
|
||||
m_size += maxsize;
|
||||
val.pData.aval = new cell_t [count + 1];
|
||||
memcpy(&val.pData.aval[1], vals, sizeof(cell_t) * count);
|
||||
val.pData.aval[0] = count;
|
||||
elements.emplace(elements.begin() + position, val);
|
||||
position++;
|
||||
}
|
||||
|
||||
void CDataPack::Reset() const
|
||||
{
|
||||
m_curptr = m_pBase;
|
||||
position = 0;
|
||||
}
|
||||
|
||||
size_t CDataPack::GetPosition() const
|
||||
{
|
||||
return static_cast<size_t>(m_curptr - m_pBase);
|
||||
return position;
|
||||
}
|
||||
|
||||
bool CDataPack::SetPosition(size_t pos) const
|
||||
{
|
||||
if (pos > m_size)
|
||||
{
|
||||
if (pos > elements.size())
|
||||
return false;
|
||||
}
|
||||
m_curptr = m_pBase + pos;
|
||||
|
||||
position = pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
cell_t CDataPack::ReadCell() const
|
||||
{
|
||||
if (!IsReadable(sizeof(char) + sizeof(size_t) + sizeof(cell_t)))
|
||||
{
|
||||
if (!IsReadable() || elements[position].type != CDataPackType::Cell)
|
||||
return 0;
|
||||
}
|
||||
if (*reinterpret_cast<char *>(m_curptr) != Cell)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
m_curptr += sizeof(char);
|
||||
|
||||
if (*reinterpret_cast<size_t *>(m_curptr) != sizeof(cell_t))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_curptr += sizeof(size_t);
|
||||
|
||||
cell_t val = *reinterpret_cast<cell_t *>(m_curptr);
|
||||
m_curptr += sizeof(cell_t);
|
||||
return val;
|
||||
}
|
||||
|
||||
float CDataPack::ReadFloat() const
|
||||
{
|
||||
if (!IsReadable(sizeof(char) + sizeof(size_t) + sizeof(float)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (*reinterpret_cast<char *>(m_curptr) != Float)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
m_curptr += sizeof(char);
|
||||
|
||||
if (*reinterpret_cast<size_t *>(m_curptr) != sizeof(float))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_curptr += sizeof(size_t);
|
||||
|
||||
float val = *reinterpret_cast<float *>(m_curptr);
|
||||
m_curptr += sizeof(float);
|
||||
return val;
|
||||
}
|
||||
|
||||
bool CDataPack::IsReadable(size_t bytes) const
|
||||
{
|
||||
return (bytes + (m_curptr - m_pBase) > m_size) ? false : true;
|
||||
}
|
||||
|
||||
const char *CDataPack::ReadString(size_t *len) const
|
||||
{
|
||||
if (!IsReadable(sizeof(char) + sizeof(size_t)))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (*reinterpret_cast<char *>(m_curptr) != String)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
m_curptr += sizeof(char);
|
||||
|
||||
size_t real_len = *(size_t *)m_curptr;
|
||||
|
||||
m_curptr += sizeof(size_t);
|
||||
char *str = (char *)m_curptr;
|
||||
|
||||
if ((strlen(str) != real_len) || !(IsReadable(real_len+1)))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (len)
|
||||
{
|
||||
*len = real_len;
|
||||
}
|
||||
|
||||
m_curptr += real_len + 1;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void *CDataPack::GetMemory() const
|
||||
{
|
||||
return m_curptr;
|
||||
}
|
||||
|
||||
void *CDataPack::ReadMemory(size_t *size) const
|
||||
{
|
||||
if (!IsReadable(sizeof(size_t)))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (*reinterpret_cast<char *>(m_curptr) != Raw)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
m_curptr += sizeof(char);
|
||||
|
||||
size_t bytecount = *(size_t *)m_curptr;
|
||||
m_curptr += sizeof(size_t);
|
||||
|
||||
if (!IsReadable(bytecount))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *ptr = m_curptr;
|
||||
|
||||
if (size)
|
||||
{
|
||||
*size = bytecount;
|
||||
}
|
||||
|
||||
m_curptr += bytecount;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void CDataPack::PackFunction(cell_t function)
|
||||
{
|
||||
CheckSize(sizeof(char) + sizeof(size_t) + sizeof(cell_t));
|
||||
|
||||
*(char *)m_curptr = Function;
|
||||
m_curptr += sizeof(char);
|
||||
|
||||
*(size_t *)m_curptr = sizeof(cell_t);
|
||||
m_curptr += sizeof(size_t);
|
||||
|
||||
*(cell_t *)m_curptr = function;
|
||||
m_curptr += sizeof(cell_t);
|
||||
|
||||
m_size += sizeof(char) + sizeof(size_t) + sizeof(cell_t);
|
||||
|
||||
return elements[position++].pData.cval;
|
||||
}
|
||||
|
||||
cell_t CDataPack::ReadFunction() const
|
||||
{
|
||||
if (!IsReadable(sizeof(char) + sizeof(size_t) + sizeof(cell_t)))
|
||||
{
|
||||
if (!IsReadable() || elements[position].type != CDataPackType::Function)
|
||||
return 0;
|
||||
}
|
||||
if (*reinterpret_cast<char *>(m_curptr) != Function)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
m_curptr += sizeof(char);
|
||||
|
||||
if (*reinterpret_cast<size_t *>(m_curptr) != sizeof(cell_t))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_curptr += sizeof(size_t);
|
||||
|
||||
cell_t val = *reinterpret_cast<cell_t *>(m_curptr);
|
||||
m_curptr += sizeof(cell_t);
|
||||
return val;
|
||||
|
||||
return elements[position++].pData.cval;
|
||||
}
|
||||
|
||||
float CDataPack::ReadFloat() const
|
||||
{
|
||||
if (!IsReadable() || elements[position].type != CDataPackType::Float)
|
||||
return 0;
|
||||
|
||||
return elements[position++].pData.fval;
|
||||
}
|
||||
|
||||
bool CDataPack::IsReadable(size_t bytes) const
|
||||
{
|
||||
return (position < elements.size());
|
||||
}
|
||||
|
||||
const char *CDataPack::ReadString(size_t *len) const
|
||||
{
|
||||
if (!IsReadable() || elements[position].type != CDataPackType::String)
|
||||
{
|
||||
if (len)
|
||||
*len = 0;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const std::string &val = *elements[position++].pData.sval;
|
||||
if (len)
|
||||
*len = val.size();
|
||||
|
||||
return val.c_str();
|
||||
}
|
||||
|
||||
cell_t *CDataPack::ReadCellArray(cell_t *size) const
|
||||
{
|
||||
if (!IsReadable() || elements[position].type != CDataPackType::CellArray)
|
||||
{
|
||||
if(size)
|
||||
*size = 0;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
cell_t *val = elements[position].pData.aval;
|
||||
cell_t *ptr = &(val[1]);
|
||||
++position;
|
||||
|
||||
if (size)
|
||||
*size = val[0];
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
cell_t *CDataPack::ReadFloatArray(cell_t *size) const
|
||||
{
|
||||
if (!IsReadable() || elements[position].type != CDataPackType::FloatArray)
|
||||
{
|
||||
if(size)
|
||||
*size = 0;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
cell_t *val = elements[position].pData.aval;
|
||||
cell_t *ptr = &(val[1]);
|
||||
++position;
|
||||
|
||||
if (size)
|
||||
*size = val[0];
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *CDataPack::ReadMemory(size_t *size) const
|
||||
{
|
||||
void *ptr = nullptr;
|
||||
if (!IsReadable() || elements[position].type != CDataPackType::Raw)
|
||||
return ptr;
|
||||
|
||||
size_t *val = reinterpret_cast<size_t *>(elements[position].pData.vval);
|
||||
ptr = &(val[1]);
|
||||
++position;
|
||||
|
||||
if (size)
|
||||
*size = val[0]; /* Egor!!!! */
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
bool CDataPack::RemoveItem(size_t pos)
|
||||
{
|
||||
if (!elements.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pos == static_cast<size_t>(-1))
|
||||
{
|
||||
pos = position;
|
||||
}
|
||||
|
||||
if (pos >= elements.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pos < position) // we're deleting under us, step back
|
||||
{
|
||||
--position;
|
||||
}
|
||||
|
||||
switch (elements[pos].type)
|
||||
{
|
||||
case CDataPackType::Raw:
|
||||
{
|
||||
delete [] elements[pos].pData.vval;
|
||||
break;
|
||||
}
|
||||
|
||||
case CDataPackType::String:
|
||||
{
|
||||
delete elements[pos].pData.sval;
|
||||
break;
|
||||
}
|
||||
|
||||
case CDataPackType::CellArray:
|
||||
case CDataPackType::FloatArray:
|
||||
{
|
||||
delete [] elements[pos].pData.aval;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
elements.erase(elements.begin() + pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
+164
-23
@@ -32,54 +32,195 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_CDATAPACK_H_
|
||||
#define _INCLUDE_SOURCEMOD_CDATAPACK_H_
|
||||
|
||||
#include <IDataPack.h>
|
||||
#include <ISourceMod.h>
|
||||
#include <amtl/am-vector.h>
|
||||
#include <amtl/am-string.h>
|
||||
|
||||
using namespace SourceMod;
|
||||
|
||||
class CDataPack : public IDataPack
|
||||
enum CDataPackType {
|
||||
Raw,
|
||||
Cell,
|
||||
Float,
|
||||
String,
|
||||
Function,
|
||||
CellArray,
|
||||
FloatArray,
|
||||
};
|
||||
|
||||
class CDataPack
|
||||
{
|
||||
public:
|
||||
CDataPack();
|
||||
~CDataPack();
|
||||
|
||||
static IDataPack *New();
|
||||
static void Free(IDataPack *pack);
|
||||
public: //IDataReader
|
||||
public: // Originally IDataReader
|
||||
/**
|
||||
* @brief Resets the position in the data stream to the beginning.
|
||||
*/
|
||||
void Reset() const;
|
||||
|
||||
/**
|
||||
* @brief Retrieves the current stream position.
|
||||
*
|
||||
* @return Index into the stream.
|
||||
*/
|
||||
size_t GetPosition() const;
|
||||
|
||||
/**
|
||||
* @brief Sets the current stream position.
|
||||
*
|
||||
* @param pos Index to set the stream at.
|
||||
* @return True if succeeded, false if out of bounds.
|
||||
*/
|
||||
bool SetPosition(size_t pos) const;
|
||||
|
||||
/**
|
||||
* @brief Reads one cell from the data stream.
|
||||
*
|
||||
* @return A cell read from the current position.
|
||||
*/
|
||||
cell_t ReadCell() const;
|
||||
|
||||
/**
|
||||
* @brief Reads one float from the data stream.
|
||||
*
|
||||
* @return A float read from the current position.
|
||||
*/
|
||||
float ReadFloat() const;
|
||||
bool IsReadable(size_t bytes) const;
|
||||
|
||||
/**
|
||||
* @brief Reads an array of values from the data stream.
|
||||
*
|
||||
* @param len The size of the array stored at this position to return.
|
||||
* @return A cell array read from the current position.
|
||||
*/
|
||||
cell_t *ReadCellArray(cell_t *len) const;
|
||||
/**
|
||||
* @brief Reads an array of values from the data stream.
|
||||
*
|
||||
* @param len The size of the array stored at this position to return.
|
||||
* @return A cell array read from the current position.
|
||||
*/
|
||||
cell_t *ReadFloatArray(cell_t *len) const;
|
||||
|
||||
/**
|
||||
* @brief Returns whether or not a specified number of bytes from the current stream
|
||||
* position to the end can be read.
|
||||
*
|
||||
* @param bytes Number of bytes to simulate reading.
|
||||
* @return True if can be read, false otherwise.
|
||||
*/
|
||||
bool IsReadable(size_t bytes = 0) const;
|
||||
|
||||
/**
|
||||
* @brief Reads a string from the data stream.
|
||||
*
|
||||
* @param len Optional pointer to store the string length.
|
||||
* @return Pointer to the string, or NULL if out of bounds.
|
||||
*/
|
||||
const char *ReadString(size_t *len) const;
|
||||
void *GetMemory() const;
|
||||
|
||||
/**
|
||||
* @brief Reads the current position as a generic data type.
|
||||
*
|
||||
* @param size Optional pointer to store the size of the data type.
|
||||
* @return Pointer to the data, or NULL if out of bounds.
|
||||
*/
|
||||
void *ReadMemory(size_t *size) const;
|
||||
|
||||
/**
|
||||
* @brief Reads a function pointer from the data stream.
|
||||
*
|
||||
* @return A function pointer read from the current position.
|
||||
*/
|
||||
cell_t ReadFunction() const;
|
||||
public: //IDataPack
|
||||
|
||||
public: // Originally IDataPack
|
||||
/**
|
||||
* @brief Resets the used size of the stream back to zero.
|
||||
*/
|
||||
void ResetSize();
|
||||
|
||||
/**
|
||||
* @brief Packs one cell into the data stream.
|
||||
*
|
||||
* @param cell Cell value to write.
|
||||
*/
|
||||
void PackCell(cell_t cell);
|
||||
|
||||
/**
|
||||
* @brief Packs one float into the data stream.
|
||||
*
|
||||
* @param val Float value to write.
|
||||
*/
|
||||
void PackFloat(float val);
|
||||
|
||||
/**
|
||||
* @brief Packs one string into the data stream.
|
||||
* The length is recorded as well for buffer overrun protection.
|
||||
*
|
||||
* @param string String to write.
|
||||
*/
|
||||
void PackString(const char *string);
|
||||
|
||||
/**
|
||||
* @brief Packs an array of cells into the data stream.
|
||||
*
|
||||
* @param vals Cells to write.
|
||||
* @param count Number of cells.
|
||||
*/
|
||||
void PackCellArray(cell_t const *vals, cell_t count);
|
||||
/**
|
||||
* @brief Packs an array of cells into the data stream.
|
||||
*
|
||||
* @param vals Cells to write.
|
||||
* @param count Number of cells.
|
||||
*/
|
||||
void PackFloatArray(cell_t const *vals, cell_t count);
|
||||
|
||||
/**
|
||||
* @brief Creates a generic block of memory in the stream.
|
||||
*
|
||||
* Note that the pointer it returns can be invalidated on further
|
||||
* writing, since the stream size may grow. You may need to double back
|
||||
* and fetch the pointer again.
|
||||
*
|
||||
* @param size Size of the memory to create in the stream.
|
||||
* @param addr Optional pointer to store the relocated memory address.
|
||||
* @return Current position of the stream beforehand.
|
||||
*/
|
||||
size_t CreateMemory(size_t size, void **addr);
|
||||
|
||||
/**
|
||||
* @brief Packs one function pointer into the data stream.
|
||||
*
|
||||
* @param function The function pointer to write.
|
||||
*/
|
||||
void PackFunction(cell_t function);
|
||||
|
||||
public:
|
||||
void Initialize();
|
||||
inline size_t GetCapacity() const { return m_capacity; }
|
||||
private:
|
||||
void CheckSize(size_t sizetype);
|
||||
private:
|
||||
char *m_pBase;
|
||||
mutable char *m_curptr;
|
||||
size_t m_capacity;
|
||||
size_t m_size;
|
||||
inline size_t GetCapacity() const { return this->elements.size(); };
|
||||
inline CDataPackType GetCurrentType(void) const { return this->elements[this->position].type; };
|
||||
bool RemoveItem(size_t pos = -1);
|
||||
|
||||
enum DataPackType {
|
||||
Raw,
|
||||
Cell,
|
||||
Float,
|
||||
String,
|
||||
Function
|
||||
};
|
||||
private:
|
||||
typedef union {
|
||||
cell_t cval;
|
||||
float fval;
|
||||
uint8_t *vval;
|
||||
std::string *sval;
|
||||
cell_t *aval;
|
||||
} InternalPackValue;
|
||||
|
||||
typedef struct {
|
||||
InternalPackValue pData;
|
||||
CDataPackType type;
|
||||
} InternalPack;
|
||||
|
||||
std::vector<InternalPack> elements;
|
||||
mutable size_t position;
|
||||
};
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_CDATAPACK_H_
|
||||
|
||||
+20
-9
@@ -35,6 +35,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ICellArray.h>
|
||||
#include <amtl/am-bits.h>
|
||||
|
||||
extern HandleType_t htCellArray;
|
||||
|
||||
@@ -214,24 +215,34 @@ private:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
size_t newAllocSize = m_AllocSize;
|
||||
/* Set a base allocation size of 8 items */
|
||||
if (!m_AllocSize)
|
||||
if (!newAllocSize)
|
||||
{
|
||||
m_AllocSize = 8;
|
||||
newAllocSize = 8;
|
||||
}
|
||||
if (!ke::IsUintPtrAddSafe(m_Size, count))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/* If it's not enough, keep doubling */
|
||||
while (m_Size + count > m_AllocSize)
|
||||
while (m_Size + count > newAllocSize)
|
||||
{
|
||||
m_AllocSize *= 2;
|
||||
if (!ke::IsUintPtrMultiplySafe(newAllocSize, 2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
newAllocSize *= 2;
|
||||
}
|
||||
/* finally, allocate the new block */
|
||||
if (m_Data)
|
||||
cell_t *data = static_cast<cell_t*>(realloc(m_Data, sizeof(cell_t) * m_BlockSize * newAllocSize));
|
||||
/* Update state if allocation was successful */
|
||||
if (data)
|
||||
{
|
||||
m_Data = (cell_t *)realloc(m_Data, sizeof(cell_t) * m_BlockSize * m_AllocSize);
|
||||
} else {
|
||||
m_Data = (cell_t *)malloc(sizeof(cell_t) * m_BlockSize * m_AllocSize);
|
||||
m_AllocSize = newAllocSize;
|
||||
m_Data = data;
|
||||
}
|
||||
return (m_Data != NULL);
|
||||
return (data != nullptr);
|
||||
}
|
||||
private:
|
||||
cell_t *m_Data;
|
||||
|
||||
+233
-286
@@ -34,21 +34,24 @@
|
||||
#include "HandleSys.h"
|
||||
#include "ExtensionSys.h"
|
||||
#include "PluginSys.h"
|
||||
#include <chrono>
|
||||
#include <amtl/am-thread.h>
|
||||
#include <stdlib.h>
|
||||
#include <IThreader.h>
|
||||
#include <bridge/include/ILogger.h>
|
||||
#include <bridge/include/CoreProvider.h>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
#define DBPARSE_LEVEL_NONE 0
|
||||
#define DBPARSE_LEVEL_MAIN 1
|
||||
#define DBPARSE_LEVEL_DATABASE 2
|
||||
|
||||
DBManager g_DBMan;
|
||||
static bool s_OneTimeThreaderErrorMsg = false;
|
||||
|
||||
DBManager::DBManager()
|
||||
: m_Terminate(false),
|
||||
m_ParseLevel(0),
|
||||
m_ParseState(0),
|
||||
m_ActiveOperation(NULL),
|
||||
m_pDefault(NULL)
|
||||
{
|
||||
}
|
||||
@@ -65,38 +68,29 @@ void DBManager::OnSourceModAllInitialized()
|
||||
g_HandleSys.InitAccessDefaults(NULL, &sec);
|
||||
sec.access[HandleAccess_Delete] |= HANDLE_RESTRICT_IDENTITY;
|
||||
sec.access[HandleAccess_Clone] |= HANDLE_RESTRICT_IDENTITY;
|
||||
|
||||
|
||||
m_DriverType = g_HandleSys.CreateType("IDriver", this, 0, NULL, &sec, g_pCoreIdent, NULL);
|
||||
m_DatabaseType = g_HandleSys.CreateType("IDatabase", this, 0, NULL, NULL, g_pCoreIdent, NULL);
|
||||
|
||||
g_ShareSys.AddInterface(NULL, this);
|
||||
|
||||
g_pSM->BuildPath(Path_SM, m_Filename, sizeof(m_Filename), "configs/databases.cfg");
|
||||
|
||||
g_PluginSys.AddPluginsListener(this);
|
||||
m_Builder.SetPath(m_Filename);
|
||||
|
||||
g_PluginSys.AddPluginsListener(this);
|
||||
|
||||
g_pSM->AddGameFrameHook(&FrameHook);
|
||||
|
||||
auto sm_reload_databases = [this] (int client, const ICommandArgs *args) -> bool {
|
||||
m_Builder.StartParse();
|
||||
return true;
|
||||
};
|
||||
bridge->DefineCommand("sm_reload_databases", "Reparse database configurations file", sm_reload_databases);
|
||||
}
|
||||
|
||||
void DBManager::OnSourceModLevelChange(const char *mapName)
|
||||
{
|
||||
SMCError err;
|
||||
SMCStates states = {0, 0};
|
||||
|
||||
/* We lock and don't give up the lock until we're done.
|
||||
* This way the thread's search won't be searching through a
|
||||
* potentially empty/corrupt list, which would be very bad.
|
||||
*/
|
||||
ke::AutoLock lock(&m_ConfigLock);
|
||||
if ((err = textparsers->ParseFile_SMC(m_Filename, this, &states)) != SMCError_Okay)
|
||||
{
|
||||
logger->LogError("[SM] Detected parse error(s) in file \"%s\"", m_Filename);
|
||||
if (err != SMCError_Custom)
|
||||
{
|
||||
const char *txt = textparsers->GetSMCErrorString(err);
|
||||
logger->LogError("[SM] Line %d: %s", states.line, txt);
|
||||
}
|
||||
}
|
||||
m_Builder.StartParse();
|
||||
}
|
||||
|
||||
void DBManager::OnSourceModShutdown()
|
||||
@@ -106,7 +100,6 @@ void DBManager::OnSourceModShutdown()
|
||||
g_PluginSys.RemovePluginsListener(this);
|
||||
g_HandleSys.RemoveType(m_DatabaseType, g_pCoreIdent);
|
||||
g_HandleSys.RemoveType(m_DriverType, g_pCoreIdent);
|
||||
ClearConfigs();
|
||||
}
|
||||
|
||||
unsigned int DBManager::GetInterfaceVersion()
|
||||
@@ -134,136 +127,10 @@ void DBManager::OnHandleDestroy(HandleType_t type, void *object)
|
||||
}
|
||||
}
|
||||
|
||||
void DBManager::ReadSMC_ParseStart()
|
||||
{
|
||||
ClearConfigs();
|
||||
m_ParseLevel = 0;
|
||||
m_ParseState = DBPARSE_LEVEL_NONE;
|
||||
m_DefDriver.clear();
|
||||
}
|
||||
|
||||
void DBManager::ClearConfigs()
|
||||
{
|
||||
List<ConfDbInfo *>::iterator iter;
|
||||
for (iter=m_confs.begin(); iter!=m_confs.end(); iter++)
|
||||
delete (*iter);
|
||||
m_confs.clear();
|
||||
}
|
||||
|
||||
ConfDbInfo s_CurInfo;
|
||||
SMCResult DBManager::ReadSMC_NewSection(const SMCStates *states, const char *name)
|
||||
{
|
||||
if (m_ParseLevel)
|
||||
{
|
||||
m_ParseLevel++;
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
|
||||
if (m_ParseState == DBPARSE_LEVEL_NONE)
|
||||
{
|
||||
if (strcmp(name, "Databases") == 0)
|
||||
{
|
||||
m_ParseState = DBPARSE_LEVEL_MAIN;
|
||||
} else {
|
||||
m_ParseLevel++;
|
||||
}
|
||||
} else if (m_ParseState == DBPARSE_LEVEL_MAIN) {
|
||||
s_CurInfo = ConfDbInfo();
|
||||
s_CurInfo.name = name;
|
||||
m_ParseState = DBPARSE_LEVEL_DATABASE;
|
||||
} else if (m_ParseState == DBPARSE_LEVEL_DATABASE) {
|
||||
m_ParseLevel++;
|
||||
}
|
||||
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
|
||||
SMCResult DBManager::ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
|
||||
{
|
||||
if (m_ParseLevel)
|
||||
{
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
|
||||
if (m_ParseState == DBPARSE_LEVEL_MAIN)
|
||||
{
|
||||
if (strcmp(key, "driver_default") == 0)
|
||||
{
|
||||
m_DefDriver.assign(value);
|
||||
}
|
||||
} else if (m_ParseState == DBPARSE_LEVEL_DATABASE) {
|
||||
if (strcmp(key, "driver") == 0)
|
||||
{
|
||||
if (strcmp(value, "default") != 0)
|
||||
{
|
||||
s_CurInfo.driver = value;
|
||||
}
|
||||
} else if (strcmp(key, "database") == 0) {
|
||||
s_CurInfo.database = value;
|
||||
} else if (strcmp(key, "host") == 0) {
|
||||
s_CurInfo.host = value;
|
||||
} else if (strcmp(key, "user") == 0) {
|
||||
s_CurInfo.user = value;
|
||||
} else if (strcmp(key, "pass") == 0) {
|
||||
s_CurInfo.pass = value;
|
||||
} else if (strcmp(key, "timeout") == 0) {
|
||||
s_CurInfo.info.maxTimeout = atoi(value);
|
||||
} else if (strcmp(key, "port") == 0) {
|
||||
s_CurInfo.info.port = atoi(value);
|
||||
}
|
||||
}
|
||||
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
|
||||
SMCResult DBManager::ReadSMC_LeavingSection(const SMCStates *states)
|
||||
{
|
||||
if (m_ParseLevel)
|
||||
{
|
||||
m_ParseLevel--;
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
|
||||
if (m_ParseState == DBPARSE_LEVEL_DATABASE)
|
||||
{
|
||||
ConfDbInfo *cdb = new ConfDbInfo();
|
||||
|
||||
cdb->name = s_CurInfo.name;
|
||||
cdb->driver = s_CurInfo.driver;
|
||||
cdb->host = s_CurInfo.host;
|
||||
cdb->user = s_CurInfo.user;
|
||||
cdb->pass = s_CurInfo.pass;
|
||||
cdb->database = s_CurInfo.database;
|
||||
cdb->realDriver = s_CurInfo.realDriver;
|
||||
cdb->info.maxTimeout = s_CurInfo.info.maxTimeout;
|
||||
cdb->info.port = s_CurInfo.info.port;
|
||||
|
||||
cdb->info.driver = cdb->driver.c_str();
|
||||
cdb->info.database = cdb->database.c_str();
|
||||
cdb->info.host = cdb->host.c_str();
|
||||
cdb->info.user = cdb->user.c_str();
|
||||
cdb->info.pass = cdb->pass.c_str();
|
||||
|
||||
/* Save it.. */
|
||||
m_confs.push_back(cdb);
|
||||
|
||||
/* Go up one level */
|
||||
m_ParseState = DBPARSE_LEVEL_MAIN;
|
||||
} else if (m_ParseState == DBPARSE_LEVEL_MAIN) {
|
||||
m_ParseState = DBPARSE_LEVEL_NONE;
|
||||
return SMCResult_Halt;
|
||||
}
|
||||
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
|
||||
void DBManager::ReadSMC_ParseEnd(bool halted, bool failed)
|
||||
{
|
||||
}
|
||||
|
||||
bool DBManager::Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool persistent, char *error, size_t maxlength)
|
||||
{
|
||||
ConfDbInfo *pInfo = GetDatabaseConf(name);
|
||||
ConfDbInfoList &list = m_Builder.GetConfigList();
|
||||
ke::RefPtr<ConfDbInfo> pInfo = list.GetDatabaseConf(name);
|
||||
|
||||
if (!pInfo)
|
||||
{
|
||||
@@ -282,11 +149,12 @@ bool DBManager::Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool
|
||||
/* Try to assign a real driver pointer */
|
||||
if (pInfo->info.driver[0] == '\0')
|
||||
{
|
||||
if (!m_pDefault && m_DefDriver.size() > 0)
|
||||
std::string defaultDriver = list.GetDefaultDriver();
|
||||
if (!m_pDefault && defaultDriver.length() > 0)
|
||||
{
|
||||
m_pDefault = FindOrLoadDriver(m_DefDriver.c_str());
|
||||
m_pDefault = FindOrLoadDriver(defaultDriver.c_str());
|
||||
}
|
||||
dname = m_DefDriver.size() ? m_DefDriver.c_str() : "default";
|
||||
dname = defaultDriver.length() ? defaultDriver.c_str() : "default";
|
||||
pInfo->realDriver = m_pDefault;
|
||||
} else {
|
||||
pInfo->realDriver = FindOrLoadDriver(pInfo->info.driver);
|
||||
@@ -310,7 +178,6 @@ bool DBManager::Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool
|
||||
*pdb = NULL;
|
||||
|
||||
g_pSM->Format(error, maxlength, "Driver \"%s\" not found", dname);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -323,7 +190,7 @@ void DBManager::AddDriver(IDBDriver *pDriver)
|
||||
*/
|
||||
KillWorkerThread();
|
||||
|
||||
m_drivers.push_back(pDriver);
|
||||
m_drivers.push_back(pDriver);
|
||||
}
|
||||
|
||||
void DBManager::RemoveDriver(IDBDriver *pDriver)
|
||||
@@ -338,19 +205,16 @@ void DBManager::RemoveDriver(IDBDriver *pDriver)
|
||||
{
|
||||
if (m_drivers[i] == pDriver)
|
||||
{
|
||||
m_drivers.erase(m_drivers.iterAt(i));
|
||||
m_drivers.erase(m_drivers.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure NOTHING references this! */
|
||||
List<ConfDbInfo *>::iterator iter;
|
||||
for (iter=m_confs.begin(); iter!=m_confs.end(); iter++)
|
||||
{
|
||||
ConfDbInfo &db = *(*iter);
|
||||
if (db.realDriver == pDriver)
|
||||
ConfDbInfoList &list = m_Builder.GetConfigList();
|
||||
for (auto conf : list) {
|
||||
if (conf->realDriver == pDriver)
|
||||
{
|
||||
db.realDriver = NULL;
|
||||
conf->realDriver = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,18 +244,16 @@ void DBManager::RemoveDriver(IDBDriver *pDriver)
|
||||
for (qiter = templist.begin();
|
||||
qiter != templist.end();
|
||||
qiter++)
|
||||
{
|
||||
IDBThreadOperation *op = (*qiter);
|
||||
op->CancelThinkPart();
|
||||
op->Destroy();
|
||||
}
|
||||
FinalizeOperation(*qiter, true);
|
||||
}
|
||||
|
||||
IDBDriver *DBManager::GetDefaultDriver()
|
||||
{
|
||||
if (!m_pDefault && m_DefDriver.size() > 0)
|
||||
ConfDbInfoList &list = m_Builder.GetConfigList();
|
||||
std::string defaultDriver = list.GetDefaultDriver();
|
||||
if (!m_pDefault && defaultDriver.length() > 0)
|
||||
{
|
||||
m_pDefault = FindOrLoadDriver(m_DefDriver.c_str());
|
||||
m_pDefault = FindOrLoadDriver(defaultDriver.c_str());
|
||||
}
|
||||
|
||||
return m_pDefault;
|
||||
@@ -454,29 +316,25 @@ IDBDriver *DBManager::GetDriver(unsigned int index)
|
||||
|
||||
const DatabaseInfo *DBManager::FindDatabaseConf(const char *name)
|
||||
{
|
||||
ConfDbInfo *info = GetDatabaseConf(name);
|
||||
ConfDbInfoList &list = m_Builder.GetConfigList();
|
||||
ke::RefPtr<ConfDbInfo> info = list.GetDatabaseConf(name);
|
||||
if (!info)
|
||||
{
|
||||
return NULL;
|
||||
// couldn't find requested conf, return default if exists
|
||||
info = list.GetDefaultConfiguration();
|
||||
if (!info)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return &info->info;
|
||||
}
|
||||
|
||||
ConfDbInfo *DBManager::GetDatabaseConf(const char *name)
|
||||
ke::RefPtr<ConfDbInfo> DBManager::GetDatabaseConf(const char *name)
|
||||
{
|
||||
List<ConfDbInfo *>::iterator iter;
|
||||
|
||||
for (iter=m_confs.begin(); iter!=m_confs.end(); iter++)
|
||||
{
|
||||
ConfDbInfo &conf = *(*iter);
|
||||
if (conf.name == name)
|
||||
{
|
||||
return &conf;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
ConfDbInfoList &list = m_Builder.GetConfigList();
|
||||
return list.GetDatabaseConf(name);
|
||||
}
|
||||
|
||||
IDBDriver *DBManager::FindOrLoadDriver(const char *name)
|
||||
@@ -515,49 +373,136 @@ void DBManager::KillWorkerThread()
|
||||
if (m_Worker)
|
||||
{
|
||||
{
|
||||
ke::AutoLock lock(&m_QueueEvent);
|
||||
std::lock_guard<std::mutex> lock(m_Lock);
|
||||
m_Terminate = true;
|
||||
m_QueueEvent.Notify();
|
||||
m_QueueEvent.notify_all();
|
||||
}
|
||||
m_Worker->Join();
|
||||
m_Worker->join();
|
||||
m_Worker = nullptr;
|
||||
s_OneTimeThreaderErrorMsg = false;
|
||||
m_Terminate = false;
|
||||
}
|
||||
}
|
||||
|
||||
void DBManager::FinalizeOperation(IDBThreadOperation *op, bool driver_unloading)
|
||||
{
|
||||
bool cancelled = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Lock);
|
||||
m_OperationOwners.erase(op);
|
||||
auto iter = m_CancelledOperations.find(op);
|
||||
if (iter != m_CancelledOperations.end())
|
||||
{
|
||||
cancelled = true;
|
||||
m_CancelledOperations.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
if (cancelled)
|
||||
{
|
||||
op->Destroy();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (driver_unloading)
|
||||
op->CancelThinkPart();
|
||||
else
|
||||
op->RunThinkPart();
|
||||
op->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void DBManager::CancelPluginOperations(IdentityToken_t *identity)
|
||||
{
|
||||
Queue<IDBThreadOperation *> cancelled;
|
||||
bool active_in_think_queue = false;
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_Lock);
|
||||
auto owns = [this, identity](IDBThreadOperation *op) {
|
||||
auto iter = m_OperationOwners.find(op);
|
||||
return iter != m_OperationOwners.end() && iter->second == identity;
|
||||
};
|
||||
for (PrioQueueLevel priority : {PrioQueue_High, PrioQueue_Normal, PrioQueue_Low})
|
||||
{
|
||||
Queue<IDBThreadOperation *> &queue = m_OpQueue.GetQueue(priority);
|
||||
for (auto iter = queue.begin(); iter != queue.end();)
|
||||
{
|
||||
IDBThreadOperation *op = *iter;
|
||||
if (owns(op))
|
||||
{
|
||||
cancelled.push(op);
|
||||
m_OperationOwners.erase(op);
|
||||
iter = queue.erase(iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IDBThreadOperation *active = m_ActiveOperation;
|
||||
bool cancelling_active = active && owns(active);
|
||||
{
|
||||
std::lock_guard<std::mutex> think_lock(m_ThinkLock);
|
||||
for (auto iter = m_ThinkQueue.begin(); iter != m_ThinkQueue.end();)
|
||||
{
|
||||
IDBThreadOperation *op = *iter;
|
||||
if (owns(op))
|
||||
{
|
||||
if (op == active)
|
||||
active_in_think_queue = true;
|
||||
cancelled.push(op);
|
||||
m_OperationOwners.erase(op);
|
||||
iter = m_ThinkQueue.erase(iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cancelling_active)
|
||||
{
|
||||
if (active_in_think_queue)
|
||||
m_ActiveOperation = nullptr;
|
||||
else
|
||||
m_CancelledOperations.insert(active);
|
||||
}
|
||||
lock.unlock();
|
||||
|
||||
while (!cancelled.empty())
|
||||
{
|
||||
IDBThreadOperation *op = cancelled.first();
|
||||
cancelled.pop();
|
||||
op->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
static IdentityToken_t *s_pAddBlock = NULL;
|
||||
|
||||
bool DBManager::AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio)
|
||||
{
|
||||
if (s_pAddBlock && op->GetOwner() == s_pAddBlock)
|
||||
IdentityToken_t *owner = op->GetOwner();
|
||||
if (s_pAddBlock && owner == s_pAddBlock)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_Worker)
|
||||
{
|
||||
m_Worker = new ke::Thread([this]() -> void {
|
||||
m_Worker = ke::NewThread("SM Database Worker", [this]() -> void {
|
||||
Run();
|
||||
}, "SM SQL Worker");
|
||||
if (!m_Worker->Succeeded())
|
||||
{
|
||||
if (!s_OneTimeThreaderErrorMsg)
|
||||
{
|
||||
logger->LogError("[SM] Unable to create db threader (error unknown)");
|
||||
s_OneTimeThreaderErrorMsg = true;
|
||||
}
|
||||
m_Worker = nullptr;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* Add to the queue */
|
||||
{
|
||||
ke::AutoLock lock(&m_QueueEvent);
|
||||
std::lock_guard<std::mutex> lock(m_Lock);
|
||||
Queue<IDBThreadOperation *> &queue = m_OpQueue.GetQueue(prio);
|
||||
m_OperationOwners.emplace(op, owner);
|
||||
queue.push(op);
|
||||
m_QueueEvent.Notify();
|
||||
m_QueueEvent.notify_one();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -588,7 +533,7 @@ void DBManager::Run()
|
||||
|
||||
void DBManager::ThreadMain()
|
||||
{
|
||||
ke::AutoLock lock(&m_QueueEvent);
|
||||
std::unique_lock<std::mutex> lock(m_Lock);
|
||||
|
||||
while (true) {
|
||||
// The lock has been acquired. Grab everything we can out of the
|
||||
@@ -596,66 +541,62 @@ void DBManager::ThreadMain()
|
||||
// we process all operations we can before checking to terminate.
|
||||
// There's no risk of starvation since the main thread blocks on us
|
||||
// terminating.
|
||||
while (true)
|
||||
{
|
||||
Queue<IDBThreadOperation *> &queue = m_OpQueue.GetLikelyQueue();
|
||||
if (queue.empty())
|
||||
break;
|
||||
auto queue = &m_OpQueue.GetLikelyQueue();
|
||||
if (queue->empty()) {
|
||||
// If the queue is empty and we've been asked to stop, leave now.
|
||||
if (m_Terminate)
|
||||
return;
|
||||
|
||||
IDBThreadOperation *op = queue.first();
|
||||
queue.pop();
|
||||
|
||||
// Unlock the queue when we run the query, so the main thread can
|
||||
// keep pumping events. We re-acquire the lock to check for more
|
||||
// items. It's okay if we terminate while unlocked; the main
|
||||
// thread would be blocked and we'd need to flush the queue
|
||||
// anyway, so after we've depleted the queue here, we'll just
|
||||
// reach the terminate at the top of the loop.
|
||||
{
|
||||
ke::AutoUnlock unlock(&m_QueueEvent);
|
||||
op->RunThreadPart();
|
||||
|
||||
ke::AutoLock lock(&m_ThinkLock);
|
||||
m_ThinkQueue.push(op);
|
||||
}
|
||||
|
||||
|
||||
if (!m_Terminate)
|
||||
{
|
||||
ke::AutoUnlock unlock(&m_QueueEvent);
|
||||
#ifdef _WIN32
|
||||
Sleep(20);
|
||||
#else
|
||||
usleep(20000);
|
||||
#endif
|
||||
}
|
||||
// Otherwise, wait for something to happen.
|
||||
m_QueueEvent.wait(lock);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_Terminate)
|
||||
return;
|
||||
IDBThreadOperation *op = queue->first();
|
||||
queue->pop();
|
||||
m_ActiveOperation = op;
|
||||
|
||||
// Release the lock and wait for a signal.
|
||||
m_QueueEvent.Wait();
|
||||
// Unlock the queue when we run the query, so the main thread can
|
||||
// keep pumping events. We re-acquire the lock to check for more
|
||||
// items. It's okay if we terminate while unlocked; the main
|
||||
// thread would be blocked and we'd need to flush the queue
|
||||
// anyway, so after we've depleted the queue here, we'll just
|
||||
// reach the terminate at the top of the loop.
|
||||
lock.unlock();
|
||||
op->RunThreadPart();
|
||||
|
||||
// Re-acquire the lock and give the data back to the main thread
|
||||
// immediately. We use a separate lock to minimize game thread
|
||||
// contention.
|
||||
{
|
||||
std::lock_guard<std::mutex> think_lock(m_ThinkLock);
|
||||
m_ThinkQueue.push(op);
|
||||
}
|
||||
lock.lock();
|
||||
m_ActiveOperation = nullptr;
|
||||
lock.unlock();
|
||||
|
||||
// Note that we add a 20ms delay after processing a query. This is
|
||||
// questionable but the intent is to avoid starving the game thread.
|
||||
if (!m_Terminate)
|
||||
std::this_thread::sleep_for(20ms);
|
||||
|
||||
lock.lock();
|
||||
}
|
||||
}
|
||||
|
||||
void DBManager::RunFrame()
|
||||
{
|
||||
/* Don't bother if we're empty */
|
||||
if (!m_ThinkQueue.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Dump one thing per-frame so the server stays sane. */
|
||||
IDBThreadOperation *op;
|
||||
{
|
||||
ke::AutoLock lock(&m_ThinkLock);
|
||||
std::lock_guard<std::mutex> lock(m_ThinkLock);
|
||||
if (m_ThinkQueue.empty())
|
||||
return;
|
||||
op = m_ThinkQueue.first();
|
||||
m_ThinkQueue.pop();
|
||||
}
|
||||
op->RunThinkPart();
|
||||
op->Destroy();
|
||||
FinalizeOperation(op, false);
|
||||
}
|
||||
|
||||
void DBManager::OnSourceModIdentityDropped(IdentityToken_t *pToken)
|
||||
@@ -674,7 +615,8 @@ void DBManager::OnSourceModIdentityDropped(IdentityToken_t *pToken)
|
||||
while (iter != m_ThinkQueue.end())
|
||||
{
|
||||
IDBThreadOperation *op = (*iter);
|
||||
if (op->GetOwner() == pToken)
|
||||
auto owner = m_OperationOwners.find(op);
|
||||
if (owner != m_OperationOwners.end() && owner->second == pToken)
|
||||
{
|
||||
templist.push(op);
|
||||
iter = m_ThinkQueue.erase(iter);
|
||||
@@ -686,66 +628,71 @@ void DBManager::OnSourceModIdentityDropped(IdentityToken_t *pToken)
|
||||
for (iter = templist.begin();
|
||||
iter != templist.end();
|
||||
iter++)
|
||||
{
|
||||
IDBThreadOperation *op = (*iter);
|
||||
op->RunThinkPart();
|
||||
op->Destroy();
|
||||
}
|
||||
FinalizeOperation(*iter, false);
|
||||
|
||||
s_pAddBlock = NULL;
|
||||
}
|
||||
|
||||
void DBManager::OnPluginWillUnload(IPlugin *plugin)
|
||||
bool DBManager::ShouldDiscardPluginOperations()
|
||||
{
|
||||
/* Kill the thread so we can flush everything into the think queue... */
|
||||
KillWorkerThread();
|
||||
const char *behavior = g_pSM->GetCoreConfigValue("DatabasePluginUnload");
|
||||
return !behavior || strcasecmp(behavior, "wait") != 0;
|
||||
}
|
||||
|
||||
/* Mark the plugin as being unloaded so future database calls will ignore threading... */
|
||||
void DBManager::WaitForPluginOperations(IPlugin *plugin)
|
||||
{
|
||||
KillWorkerThread();
|
||||
plugin->SetProperty("DisallowDBThreads", NULL);
|
||||
|
||||
/* Run all of the think operations.
|
||||
* Unlike the driver unloading example, we'll let these calls go through,
|
||||
* since a plugin unloading is far more normal.
|
||||
*/
|
||||
Queue<IDBThreadOperation *>::iterator iter = m_ThinkQueue.begin();
|
||||
Queue<IDBThreadOperation *> templist;
|
||||
while (iter != m_ThinkQueue.end())
|
||||
Queue<IDBThreadOperation *> operations;
|
||||
{
|
||||
IDBThreadOperation *op = (*iter);
|
||||
if (op->GetOwner() == plugin->GetIdentity())
|
||||
std::lock_guard<std::mutex> lock(m_Lock);
|
||||
std::lock_guard<std::mutex> think_lock(m_ThinkLock);
|
||||
for (auto iter = m_ThinkQueue.begin(); iter != m_ThinkQueue.end();)
|
||||
{
|
||||
templist.push(op);
|
||||
iter = m_ThinkQueue.erase(iter);
|
||||
} else {
|
||||
iter++;
|
||||
IDBThreadOperation *op = *iter;
|
||||
auto owner = m_OperationOwners.find(op);
|
||||
if (owner != m_OperationOwners.end() && owner->second == plugin->GetIdentity())
|
||||
{
|
||||
operations.push(op);
|
||||
iter = m_ThinkQueue.erase(iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (iter = templist.begin(); iter != templist.end(); iter++)
|
||||
while (!operations.empty())
|
||||
{
|
||||
IDBThreadOperation *op = (*iter);
|
||||
op->RunThinkPart();
|
||||
op->Destroy();
|
||||
IDBThreadOperation *op = operations.first();
|
||||
operations.pop();
|
||||
FinalizeOperation(op, false);
|
||||
}
|
||||
}
|
||||
|
||||
void DBManager::LockConfig()
|
||||
void DBManager::DiscardPluginOperations(IPlugin *plugin)
|
||||
{
|
||||
m_ConfigLock.Lock();
|
||||
plugin->SetProperty("DisallowDBThreads", NULL);
|
||||
CancelPluginOperations(plugin->GetIdentity());
|
||||
}
|
||||
|
||||
void DBManager::UnlockConfig()
|
||||
void DBManager::OnPluginWillUnload(IPlugin *plugin)
|
||||
{
|
||||
m_ConfigLock.Unlock();
|
||||
if (ShouldDiscardPluginOperations())
|
||||
DiscardPluginOperations(plugin);
|
||||
else
|
||||
WaitForPluginOperations(plugin);
|
||||
}
|
||||
|
||||
const char *DBManager::GetDefaultDriverName()
|
||||
std::string DBManager::GetDefaultDriverName()
|
||||
{
|
||||
return m_DefDriver.c_str();
|
||||
ConfDbInfoList &list = m_Builder.GetConfigList();
|
||||
return list.GetDefaultDriver();
|
||||
}
|
||||
|
||||
void DBManager::AddDependency(IExtension *myself, IDBDriver *driver)
|
||||
{
|
||||
g_Extensions.AddRawDependency(myself, driver->GetIdentity(), driver);
|
||||
}
|
||||
|
||||
|
||||
+28
-44
@@ -32,39 +32,26 @@
|
||||
#ifndef _INCLUDE_DATABASE_MANAGER_H_
|
||||
#define _INCLUDE_DATABASE_MANAGER_H_
|
||||
|
||||
#include <IDBDriver.h>
|
||||
#include "common_logic.h"
|
||||
#include <sh_vector.h>
|
||||
#include <sh_string.h>
|
||||
#include <sh_list.h>
|
||||
#include <ITextParsers.h>
|
||||
#include <vector>
|
||||
#include <am-string.h>
|
||||
#include <list>
|
||||
#include <IThreader.h>
|
||||
#include <IPluginSys.h>
|
||||
#include <am-thread-utils.h>
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include "sm_simple_prioqueue.h"
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
struct ConfDbInfo
|
||||
{
|
||||
ConfDbInfo() : realDriver(NULL)
|
||||
{
|
||||
}
|
||||
String name;
|
||||
String driver;
|
||||
String host;
|
||||
String user;
|
||||
String pass;
|
||||
String database;
|
||||
IDBDriver *realDriver;
|
||||
DatabaseInfo info;
|
||||
};
|
||||
#include <am-refcounting.h>
|
||||
#include "DatabaseConfBuilder.h"
|
||||
|
||||
class DBManager :
|
||||
public IDBManager,
|
||||
public SMGlobalClass,
|
||||
public IHandleTypeDispatch,
|
||||
public ITextListener_SMC,
|
||||
public IPluginsListener
|
||||
{
|
||||
public:
|
||||
@@ -83,6 +70,7 @@ public: //IDBManager
|
||||
void AddDriver(IDBDriver *pDrivera);
|
||||
void RemoveDriver(IDBDriver *pDriver);
|
||||
const DatabaseInfo *FindDatabaseConf(const char *name);
|
||||
ke::RefPtr<ConfDbInfo> GetDatabaseConf(const char *name);
|
||||
bool Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool persistent, char *error, size_t maxlength);
|
||||
unsigned int GetDriverCount();
|
||||
IDBDriver *GetDriver(unsigned int index);
|
||||
@@ -90,25 +78,18 @@ public: //IDBManager
|
||||
HandleError ReadHandle(Handle_t hndl, DBHandleType type, void **ptr);
|
||||
HandleError ReleaseHandle(Handle_t hndl, DBHandleType type, IdentityToken_t *token);
|
||||
void AddDependency(IExtension *myself, IDBDriver *driver);
|
||||
public: //ITextListener_SMC
|
||||
void ReadSMC_ParseStart();
|
||||
SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
|
||||
SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
|
||||
SMCResult ReadSMC_LeavingSection(const SMCStates *states);
|
||||
void ReadSMC_ParseEnd(bool halted, bool failed);
|
||||
public: //ke::IRunnable
|
||||
void Run();
|
||||
void ThreadMain();
|
||||
public: //IPluginsListener
|
||||
void OnPluginWillUnload(IPlugin *plugin);
|
||||
public:
|
||||
ConfDbInfo *GetDatabaseConf(const char *name);
|
||||
IDBDriver *FindOrLoadDriver(const char *name);
|
||||
IDBDriver *GetDefaultDriver();
|
||||
const char *GetDefaultDriverName();
|
||||
std::string GetDefaultDriverName();
|
||||
bool AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio);
|
||||
void LockConfig();
|
||||
void UnlockConfig();
|
||||
bool ShouldDiscardPluginOperations();
|
||||
void DiscardPluginOperations(IPlugin *plugin);
|
||||
void RunFrame();
|
||||
inline HandleType_t GetDatabaseType()
|
||||
{
|
||||
@@ -117,26 +98,29 @@ public:
|
||||
private:
|
||||
void ClearConfigs();
|
||||
void KillWorkerThread();
|
||||
void WaitForPluginOperations(IPlugin *plugin);
|
||||
void CancelPluginOperations(IdentityToken_t *identity);
|
||||
void FinalizeOperation(IDBThreadOperation *op, bool driver_unloading);
|
||||
private:
|
||||
CVector<IDBDriver *> m_drivers;
|
||||
std::vector<IDBDriver *> m_drivers;
|
||||
|
||||
/* Threading stuff */
|
||||
PrioQueue<IDBThreadOperation *> m_OpQueue;
|
||||
Queue<IDBThreadOperation *> m_ThinkQueue;
|
||||
CVector<bool> m_drSafety; /* which drivers are safe? */
|
||||
ke::AutoPtr<ke::Thread> m_Worker;
|
||||
ke::ConditionVariable m_QueueEvent;
|
||||
ke::Mutex m_ConfigLock;
|
||||
ke::Mutex m_ThinkLock;
|
||||
std::vector<bool> m_drSafety; /* which drivers are safe? */
|
||||
std::unique_ptr<std::thread> m_Worker;
|
||||
std::condition_variable m_QueueEvent;
|
||||
std::mutex m_ThinkLock;
|
||||
std::mutex m_Lock;
|
||||
bool m_Terminate;
|
||||
IDBThreadOperation *m_ActiveOperation;
|
||||
std::unordered_map<IDBThreadOperation *, IdentityToken_t *> m_OperationOwners;
|
||||
std::unordered_set<IDBThreadOperation *> m_CancelledOperations;
|
||||
|
||||
List<ConfDbInfo *> m_confs;
|
||||
DatabaseConfBuilder m_Builder;
|
||||
HandleType_t m_DriverType;
|
||||
HandleType_t m_DatabaseType;
|
||||
String m_DefDriver;
|
||||
char m_Filename[PLATFORM_MAX_PATH];
|
||||
unsigned int m_ParseLevel;
|
||||
unsigned int m_ParseState;
|
||||
IDBDriver *m_pDefault;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
/**
|
||||
* vim: set ts=4 sw=4 tw=99 noet :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2018 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||
* this exception to all derivative works. AlliedModders LLC defines further
|
||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||
* or <http://www.sourcemod.net/license.php>.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
#include "DatabaseConfBuilder.h"
|
||||
#include <bridge/include/ILogger.h>
|
||||
|
||||
#define DBPARSE_LEVEL_NONE 0
|
||||
#define DBPARSE_LEVEL_MAIN 1
|
||||
#define DBPARSE_LEVEL_DATABASE 2
|
||||
|
||||
DatabaseConfBuilder::DatabaseConfBuilder()
|
||||
: m_ParseList(),
|
||||
m_InfoList()
|
||||
{
|
||||
}
|
||||
|
||||
void DatabaseConfBuilder::SetPath(char *str)
|
||||
{
|
||||
m_Filename = str;
|
||||
}
|
||||
|
||||
DatabaseConfBuilder::~DatabaseConfBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
ConfDbInfoList &DatabaseConfBuilder::GetConfigList()
|
||||
{
|
||||
return m_InfoList;
|
||||
}
|
||||
|
||||
void DatabaseConfBuilder::StartParse()
|
||||
{
|
||||
SMCError err;
|
||||
SMCStates states = {0, 0};
|
||||
if ((err = textparsers->ParseFile_SMC(m_Filename.c_str(), this, &states)) != SMCError_Okay)
|
||||
{
|
||||
logger->LogError("[SM] Detected parse error(s) in file \"%s\"", m_Filename.c_str());
|
||||
if (err != SMCError_Custom)
|
||||
{
|
||||
const char *txt = textparsers->GetSMCErrorString(err);
|
||||
logger->LogError("[SM] Line %d: %s", states.line, txt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseConfBuilder::ReadSMC_ParseStart()
|
||||
{
|
||||
m_ParseLevel = 0;
|
||||
m_ParseState = DBPARSE_LEVEL_NONE;
|
||||
|
||||
m_ParseList.clear();
|
||||
}
|
||||
|
||||
SMCResult DatabaseConfBuilder::ReadSMC_NewSection(const SMCStates *states, const char *name)
|
||||
{
|
||||
if (m_ParseLevel)
|
||||
{
|
||||
m_ParseLevel++;
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
|
||||
if (m_ParseState == DBPARSE_LEVEL_NONE)
|
||||
{
|
||||
if (strcmp(name, "Databases") == 0)
|
||||
{
|
||||
m_ParseState = DBPARSE_LEVEL_MAIN;
|
||||
} else {
|
||||
m_ParseLevel++;
|
||||
}
|
||||
} else if (m_ParseState == DBPARSE_LEVEL_MAIN) {
|
||||
m_ParseCurrent = new ConfDbInfo();
|
||||
m_ParseCurrent->name = name;
|
||||
m_ParseState = DBPARSE_LEVEL_DATABASE;
|
||||
} else if (m_ParseState == DBPARSE_LEVEL_DATABASE) {
|
||||
m_ParseLevel++;
|
||||
}
|
||||
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
|
||||
SMCResult DatabaseConfBuilder::ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
|
||||
{
|
||||
if (m_ParseLevel)
|
||||
{
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
|
||||
if (m_ParseState == DBPARSE_LEVEL_MAIN)
|
||||
{
|
||||
if (strcmp(key, "driver_default") == 0)
|
||||
{
|
||||
m_ParseList.SetDefaultDriver(value);
|
||||
}
|
||||
} else if (m_ParseState == DBPARSE_LEVEL_DATABASE) {
|
||||
if (strcmp(key, "driver") == 0)
|
||||
{
|
||||
if (strcmp(value, "default") != 0)
|
||||
{
|
||||
m_ParseCurrent->driver = value;
|
||||
}
|
||||
} else if (strcmp(key, "database") == 0) {
|
||||
m_ParseCurrent->database = value;
|
||||
} else if (strcmp(key, "schema") == 0) {
|
||||
m_ParseCurrent->schemaName = value;
|
||||
} else if (strcmp(key, "host") == 0) {
|
||||
m_ParseCurrent->host = value;
|
||||
} else if (strcmp(key, "user") == 0) {
|
||||
m_ParseCurrent->user = value;
|
||||
} else if (strcmp(key, "pass") == 0) {
|
||||
m_ParseCurrent->pass = value;
|
||||
} else if (strcmp(key, "timeout") == 0) {
|
||||
m_ParseCurrent->info.maxTimeout = atoi(value);
|
||||
} else if (strcmp(key, "port") == 0) {
|
||||
m_ParseCurrent->info.port = atoi(value);
|
||||
}
|
||||
}
|
||||
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
|
||||
SMCResult DatabaseConfBuilder::ReadSMC_LeavingSection(const SMCStates *states)
|
||||
{
|
||||
if (m_ParseLevel)
|
||||
{
|
||||
m_ParseLevel--;
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
|
||||
if (m_ParseState == DBPARSE_LEVEL_DATABASE)
|
||||
{
|
||||
m_ParseCurrent->info.driver = m_ParseCurrent->driver.c_str();
|
||||
m_ParseCurrent->info.database = m_ParseCurrent->database.c_str();
|
||||
m_ParseCurrent->info.host = m_ParseCurrent->host.c_str();
|
||||
m_ParseCurrent->info.user = m_ParseCurrent->user.c_str();
|
||||
m_ParseCurrent->info.pass = m_ParseCurrent->pass.c_str();
|
||||
m_ParseCurrent->info.schemaName = m_ParseCurrent->schemaName.c_str();
|
||||
|
||||
/* Save it.. */
|
||||
m_ParseCurrent->AddRef();
|
||||
m_ParseList.push_back(m_ParseCurrent);
|
||||
m_ParseCurrent = nullptr;
|
||||
|
||||
/* Go up one level */
|
||||
m_ParseState = DBPARSE_LEVEL_MAIN;
|
||||
} else if (m_ParseState == DBPARSE_LEVEL_MAIN) {
|
||||
m_ParseState = DBPARSE_LEVEL_NONE;
|
||||
return SMCResult_Halt;
|
||||
}
|
||||
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
|
||||
void DatabaseConfBuilder::ReadSMC_ParseEnd(bool halted, bool failed)
|
||||
{
|
||||
m_InfoList.clear();
|
||||
m_InfoList = m_ParseList;
|
||||
m_ParseList.clear();
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* vim: set ts=4 sw=4 tw=99 noet :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2018 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||
* this exception to all derivative works. AlliedModders LLC defines further
|
||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||
* or <http://www.sourcemod.net/license.php>.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE_DATABASE_CONF_BUILDER_H_
|
||||
#define _INCLUDE_DATABASE_CONF_BUILDER_H_
|
||||
|
||||
#include <IDBDriver.h>
|
||||
#include <ITextParsers.h>
|
||||
#include "common_logic.h"
|
||||
|
||||
#include <am-vector.h>
|
||||
#include <am-string.h>
|
||||
#include <am-refcounting.h>
|
||||
#include <am-refcounting-threadsafe.h>
|
||||
|
||||
class ConfDbInfo : public ke::RefcountedThreadsafe<ConfDbInfo>
|
||||
{
|
||||
public:
|
||||
ConfDbInfo() : realDriver(NULL)
|
||||
{
|
||||
}
|
||||
std::string name;
|
||||
std::string driver;
|
||||
std::string host;
|
||||
std::string user;
|
||||
std::string pass;
|
||||
std::string database;
|
||||
std::string schemaName;
|
||||
IDBDriver *realDriver;
|
||||
DatabaseInfo info;
|
||||
};
|
||||
|
||||
class ConfDbInfoList : public std::vector<ke::RefPtr<ConfDbInfo>>
|
||||
{
|
||||
/* Allow internal usage of ConfDbInfoList */
|
||||
friend class DBManager;
|
||||
friend class DatabaseConfBuilder;
|
||||
private:
|
||||
std::string& GetDefaultDriver() {
|
||||
return m_DefDriver;
|
||||
}
|
||||
|
||||
ke::RefPtr<ConfDbInfo> GetDatabaseConf(const char *name) {
|
||||
for (size_t i = 0; i < this->size(); i++)
|
||||
{
|
||||
ke::RefPtr<ConfDbInfo> current = this->at(i);
|
||||
/* If we run into the default configuration, then we'll save it
|
||||
* for the next call to GetDefaultConfiguration */
|
||||
if (strcmp(current->name.c_str(), "default") == 0)
|
||||
{
|
||||
m_DefaultConfig = current;
|
||||
}
|
||||
if (strcmp(current->name.c_str(), name) == 0)
|
||||
{
|
||||
return current;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ke::RefPtr<ConfDbInfo> GetDefaultConfiguration() {
|
||||
return m_DefaultConfig;
|
||||
}
|
||||
void SetDefaultDriver(const char *input) {
|
||||
m_DefDriver = std::string(input);
|
||||
}
|
||||
private:
|
||||
ke::RefPtr<ConfDbInfo> m_DefaultConfig;
|
||||
std::string m_DefDriver;
|
||||
};
|
||||
|
||||
|
||||
class DatabaseConfBuilder : public ITextListener_SMC
|
||||
{
|
||||
public:
|
||||
DatabaseConfBuilder();
|
||||
~DatabaseConfBuilder();
|
||||
void StartParse();
|
||||
void SetPath(char* path);
|
||||
ConfDbInfoList &GetConfigList();
|
||||
public: //ITextListener_SMC
|
||||
void ReadSMC_ParseStart();
|
||||
SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
|
||||
SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
|
||||
SMCResult ReadSMC_LeavingSection(const SMCStates *states);
|
||||
void ReadSMC_ParseEnd(bool halted, bool failed);
|
||||
|
||||
private:
|
||||
unsigned int m_ParseLevel;
|
||||
unsigned int m_ParseState;
|
||||
ConfDbInfo *m_ParseCurrent;
|
||||
ConfDbInfoList m_ParseList;
|
||||
private:
|
||||
std::string m_Filename;
|
||||
ConfDbInfoList m_InfoList;
|
||||
};
|
||||
|
||||
#endif //_INCLUDE_DATABASE_CONF_BUILDER_H_
|
||||
@@ -29,17 +29,19 @@
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#include <ISourceMod.h>
|
||||
#include <IPluginSys.h>
|
||||
#include <stdarg.h>
|
||||
#include "DebugReporter.h"
|
||||
#include "Logger.h"
|
||||
#include <am-string.h>
|
||||
#include "sourcepawn/vm/base-runtime.h"
|
||||
#include "sourcepawn/vm/environment.h"
|
||||
|
||||
DebugReport g_DbgReporter;
|
||||
|
||||
void DebugReport::OnSourceModAllInitialized()
|
||||
{
|
||||
g_pSourcePawn->SetDebugListener(this);
|
||||
g_pPawnEnv->SetDebugListener(this);
|
||||
}
|
||||
|
||||
void DebugReport::OnDebugSpew(const char *msg, ...)
|
||||
@@ -68,14 +70,14 @@ void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err,
|
||||
char buffer[512];
|
||||
ke::SafeVsprintf(buffer, sizeof(buffer), message, ap);
|
||||
|
||||
const char *plname = pluginsys->FindPluginByContext(ctx->GetContext())->GetFilename();
|
||||
const char *error = g_pSourcePawn2->GetErrorString(err);
|
||||
const char *plname = pluginsys->FindPluginByContext(ctx)->GetFilename();
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_Logger.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error);
|
||||
} else {
|
||||
g_Logger.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err);
|
||||
if (err >= 0) {
|
||||
const char *error = g_pPawnEnv->GetErrorString(err);
|
||||
if (error)
|
||||
g_Logger.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error);
|
||||
else
|
||||
g_Logger.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err);
|
||||
}
|
||||
|
||||
g_Logger.LogError("[SM] %s", buffer);
|
||||
@@ -86,7 +88,7 @@ void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err,
|
||||
{
|
||||
func_idx >>= 1;
|
||||
sp_public_t *function;
|
||||
if (ctx->GetRuntime()->GetPublicByIndex(func_idx, &function) == SP_ERROR_NONE)
|
||||
if (ctx->GetBaseRuntime()->GetPublicByIndex(func_idx, &function) == SP_ERROR_NONE)
|
||||
{
|
||||
g_Logger.LogError("[SM] Unable to call function \"%s\" due to above error(s).", function->name);
|
||||
}
|
||||
@@ -94,45 +96,6 @@ void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err,
|
||||
}
|
||||
}
|
||||
|
||||
void DebugReport::GenerateCodeError(IPluginContext *pContext, uint32_t code_addr, int err, const char *message, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char buffer[512];
|
||||
|
||||
va_start(ap, message);
|
||||
ke::SafeVsprintf(buffer, sizeof(buffer), message, ap);
|
||||
va_end(ap);
|
||||
|
||||
const char *plname = pluginsys->FindPluginByContext(pContext->GetContext())->GetFilename();
|
||||
const char *error = g_pSourcePawn2->GetErrorString(err);
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_Logger.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error);
|
||||
} else {
|
||||
g_Logger.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err);
|
||||
}
|
||||
|
||||
g_Logger.LogError("[SM] %s", buffer);
|
||||
|
||||
IPluginDebugInfo *pDebug;
|
||||
if ((pDebug = pContext->GetRuntime()->GetDebugInfo()) == NULL)
|
||||
{
|
||||
g_Logger.LogError("[SM] Debug mode is not enabled for \"%s\"", plname);
|
||||
g_Logger.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on",
|
||||
_GetPluginIndex(pContext));
|
||||
return;
|
||||
}
|
||||
|
||||
const char *name;
|
||||
if (pDebug->LookupFunction(code_addr, &name) == SP_ERROR_NONE)
|
||||
{
|
||||
g_Logger.LogError("[SM] Unable to call function \"%s\" due to above error(s).", name);
|
||||
} else {
|
||||
g_Logger.LogError("[SM] Unable to call function (name unknown, address \"%x\").", code_addr);
|
||||
}
|
||||
}
|
||||
|
||||
int DebugReport::_GetPluginIndex(IPluginContext *ctx)
|
||||
{
|
||||
int id = 1;
|
||||
@@ -173,7 +136,7 @@ void DebugReport::ReportError(const IErrorReport &report, IFrameIterator &iter)
|
||||
{
|
||||
if (iter.IsScriptedFrame())
|
||||
{
|
||||
IPlugin *plugin = pluginsys->FindPluginByContext(iter.Context()->GetContext());
|
||||
IPlugin *plugin = pluginsys->FindPluginByContext(iter.Context());
|
||||
if (plugin)
|
||||
{
|
||||
blame = plugin->GetFilename();
|
||||
@@ -194,35 +157,53 @@ void DebugReport::ReportError(const IErrorReport &report, IFrameIterator &iter)
|
||||
g_Logger.LogError("[SM] Blaming: %s", blame);
|
||||
}
|
||||
|
||||
if (!iter.Done())
|
||||
std::vector<std::string> arr = GetStackTrace(&iter);
|
||||
for (size_t i = 0; i < arr.size(); i++)
|
||||
{
|
||||
g_Logger.LogError("[SM] Call stack trace:");
|
||||
g_Logger.LogError("%s", arr[i].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
for (int index = 0; !iter.Done(); iter.Next(), index++)
|
||||
std::vector<std::string> DebugReport::GetStackTrace(IFrameIterator *iter)
|
||||
{
|
||||
char temp[3072];
|
||||
std::vector<std::string> trace;
|
||||
iter->Reset();
|
||||
|
||||
if (!iter->Done())
|
||||
{
|
||||
trace.push_back("[SM] Call stack trace:");
|
||||
|
||||
for (int index = 0; !iter->Done(); iter->Next(), index++)
|
||||
{
|
||||
const char *fn = iter.FunctionName();
|
||||
const char *fn = iter->FunctionName();
|
||||
if (!fn)
|
||||
{
|
||||
fn = "<unknown function>";
|
||||
}
|
||||
if (iter.IsNativeFrame())
|
||||
if (iter->IsNativeFrame())
|
||||
{
|
||||
g_Logger.LogError("[SM] [%d] %s", index, fn);
|
||||
g_pSM->Format(temp, sizeof(temp), "[SM] [%d] %s", index, fn);
|
||||
trace.push_back(temp);
|
||||
continue;
|
||||
}
|
||||
if (iter.IsScriptedFrame())
|
||||
if (iter->IsScriptedFrame())
|
||||
{
|
||||
const char *file = iter.FilePath();
|
||||
const char *file = iter->FilePath();
|
||||
if (!file)
|
||||
{
|
||||
file = "<unknown>";
|
||||
}
|
||||
g_Logger.LogError("[SM] [%d] Line %d, %s::%s",
|
||||
g_pSM->Format(temp, sizeof(temp), "[SM] [%d] Line %d, %s::%s",
|
||||
index,
|
||||
iter.LineNumber(),
|
||||
iter->LineNumber(),
|
||||
file,
|
||||
fn);
|
||||
|
||||
trace.push_back(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return trace;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
|
||||
#include "sp_vm_api.h"
|
||||
#include "common_logic.h"
|
||||
#include <am-vector.h>
|
||||
#include <am-string.h>
|
||||
|
||||
class DebugReport :
|
||||
public SMGlobalClass,
|
||||
@@ -45,9 +47,11 @@ public: // IDebugListener
|
||||
void ReportError(const IErrorReport &report, IFrameIterator &iter);
|
||||
void OnDebugSpew(const char *msg, ...);
|
||||
public:
|
||||
// If err is -1, caller assumes the automatic reporting by SourcePawn is
|
||||
// good enough, and only wants the supplemental logging provided here.
|
||||
void GenerateError(IPluginContext *ctx, cell_t func_idx, int err, const char *message, ...);
|
||||
void GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap);
|
||||
void GenerateCodeError(IPluginContext *ctx, uint32_t code_addr, int err, const char *message, ...);
|
||||
std::vector<std::string> GetStackTrace(IFrameIterator *iter);
|
||||
private:
|
||||
int _GetPluginIndex(IPluginContext *ctx);
|
||||
};
|
||||
|
||||
+138
-220
@@ -30,6 +30,9 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ExtensionSys.h"
|
||||
#include <ILibrarySys.h>
|
||||
#include <ISourceMod.h>
|
||||
@@ -72,74 +75,69 @@ CLocalExtension::CLocalExtension(const char *filename, bool bRequired)
|
||||
|
||||
/* Special case for new bintools binary */
|
||||
if (strcmp(filename, "bintools.ext") == 0)
|
||||
{
|
||||
goto normal;
|
||||
}
|
||||
|
||||
/* Zeroth, see if there is an engine specific build in the new place. */
|
||||
g_pSM->BuildPath(Path_SM,
|
||||
path,
|
||||
PLATFORM_MAX_PATH,
|
||||
"extensions/%s.%s." PLATFORM_LIB_EXT,
|
||||
filename,
|
||||
bridge->gamesuffix);
|
||||
|
||||
if (libsys->IsPathFile(path))
|
||||
{
|
||||
goto found;
|
||||
}
|
||||
|
||||
/* COMPAT HACK: One-halfth, if ep2v, see if there is an engine specific build in the new place with old naming */
|
||||
if (strcmp(bridge->gamesuffix, "2.tf2") == 0
|
||||
|| strcmp(bridge->gamesuffix, "2.dods") == 0
|
||||
|| strcmp(bridge->gamesuffix, "2.hl2dm") == 0
|
||||
)
|
||||
{
|
||||
g_pSM->BuildPath(Path_SM,
|
||||
path,
|
||||
PLATFORM_MAX_PATH,
|
||||
"extensions/%s.2.ep2v." PLATFORM_LIB_EXT,
|
||||
"extensions/" PLATFORM_ARCH_FOLDER "%s." PLATFORM_LIB_EXT,
|
||||
filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Zeroth, see if there is an engine specific build in the new place. */
|
||||
g_pSM->BuildPath(Path_SM,
|
||||
path,
|
||||
PLATFORM_MAX_PATH,
|
||||
"extensions/" PLATFORM_ARCH_FOLDER "%s.%s." PLATFORM_LIB_EXT,
|
||||
filename,
|
||||
bridge->gamesuffix);
|
||||
|
||||
if (libsys->IsPathFile(path))
|
||||
if (!libsys->IsPathFile(path))
|
||||
{
|
||||
goto found;
|
||||
/* COMPAT HACK: One-halfth, if ep2v, see if there is an engine specific build in the new place with old naming */
|
||||
if (strcmp(bridge->gamesuffix, "2.tf2") == 0
|
||||
|| strcmp(bridge->gamesuffix, "2.dods") == 0
|
||||
|| strcmp(bridge->gamesuffix, "2.hl2dm") == 0
|
||||
)
|
||||
{
|
||||
g_pSM->BuildPath(Path_SM,
|
||||
path,
|
||||
PLATFORM_MAX_PATH,
|
||||
"extensions/" PLATFORM_ARCH_FOLDER "%s.2.ep2v." PLATFORM_LIB_EXT,
|
||||
filename);
|
||||
}
|
||||
else if (strcmp(bridge->gamesuffix, "2.nd") == 0)
|
||||
{
|
||||
g_pSM->BuildPath(Path_SM,
|
||||
path,
|
||||
PLATFORM_MAX_PATH,
|
||||
"extensions/" PLATFORM_ARCH_FOLDER "%s.2.l4d2." PLATFORM_LIB_EXT,
|
||||
filename);
|
||||
}
|
||||
|
||||
//Try further
|
||||
if (!libsys->IsPathFile(path))
|
||||
{
|
||||
/* First see if there is an engine specific build! */
|
||||
g_pSM->BuildPath(Path_SM,
|
||||
path,
|
||||
PLATFORM_MAX_PATH,
|
||||
"extensions/" PLATFORM_ARCH_FOLDER "auto.%s/%s." PLATFORM_LIB_EXT,
|
||||
filename,
|
||||
bridge->gamesuffix);
|
||||
|
||||
/* Try the "normal" version */
|
||||
if (!libsys->IsPathFile(path))
|
||||
{
|
||||
g_pSM->BuildPath(Path_SM,
|
||||
path,
|
||||
PLATFORM_MAX_PATH,
|
||||
"extensions/" PLATFORM_ARCH_FOLDER "%s." PLATFORM_LIB_EXT,
|
||||
filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (strcmp(bridge->gamesuffix, "2.nd") == 0)
|
||||
{
|
||||
g_pSM->BuildPath(Path_SM,
|
||||
path,
|
||||
PLATFORM_MAX_PATH,
|
||||
"extensions/%s.2.l4d2." PLATFORM_LIB_EXT,
|
||||
filename);
|
||||
|
||||
if (libsys->IsPathFile(path))
|
||||
{
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
|
||||
/* First see if there is an engine specific build! */
|
||||
g_pSM->BuildPath(Path_SM,
|
||||
path,
|
||||
PLATFORM_MAX_PATH,
|
||||
"extensions/auto.%s/%s." PLATFORM_LIB_EXT,
|
||||
filename,
|
||||
bridge->gamesuffix);
|
||||
|
||||
/* Try the "normal" version */
|
||||
if (!libsys->IsPathFile(path))
|
||||
{
|
||||
normal:
|
||||
g_pSM->BuildPath(Path_SM,
|
||||
path,
|
||||
PLATFORM_MAX_PATH,
|
||||
"extensions/%s." PLATFORM_LIB_EXT,
|
||||
filename);
|
||||
}
|
||||
|
||||
found:
|
||||
Initialize(filename, path, bRequired);
|
||||
}
|
||||
|
||||
@@ -176,7 +174,7 @@ bool CLocalExtension::Load(char *error, size_t maxlength)
|
||||
{
|
||||
m_pLib->CloseLibrary();
|
||||
m_pLib = NULL;
|
||||
snprintf(error, maxlength, "Unable to find extension entry point");
|
||||
ke::SafeStrcpy(error, maxlength, "Unable to find extension entry point");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -242,11 +240,13 @@ void CLocalExtension::Unload()
|
||||
m_pLib->CloseLibrary();
|
||||
m_pLib = NULL;
|
||||
}
|
||||
|
||||
m_bFullyLoaded = false;
|
||||
}
|
||||
|
||||
bool CRemoteExtension::Reload(char *error, size_t maxlength)
|
||||
{
|
||||
snprintf(error, maxlength, "Remote extensions do not support reloading");
|
||||
ke::SafeStrcpy(error, maxlength, "Remote extensions do not support reloading");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -280,13 +280,23 @@ bool CExtension::PerformAPICheck(char *error, size_t maxlength)
|
||||
{
|
||||
if (!m_pAPI)
|
||||
{
|
||||
snprintf(error, maxlength, "No IExtensionInterface instance provided");
|
||||
ke::SafeStrcpy(error, maxlength, "No IExtensionInterface instance provided");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_pAPI->GetExtensionVersion() == 10) {
|
||||
ke::SafeSprintf(error, maxlength, "Extension version %d is not supported", m_pAPI->GetExtensionVersion());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_pAPI->GetExtensionVersion() < SMINTERFACE_EXTENSIONAPI_VERSION_MIN) {
|
||||
ke::SafeSprintf(error, maxlength, "Extension version is too old to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION_MIN);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION)
|
||||
{
|
||||
snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
|
||||
ke::SafeSprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -306,7 +316,7 @@ bool CExtension::Load(char *error, size_t maxlength)
|
||||
/* Check if we're past load time */
|
||||
if (!bridge->IsMapLoading())
|
||||
{
|
||||
m_pAPI->OnExtensionsAllLoaded();
|
||||
MarkAllLoaded();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -346,7 +356,7 @@ void CExtension::MarkAllLoaded()
|
||||
void CExtension::AddPlugin(CPlugin *pPlugin)
|
||||
{
|
||||
/* Unfortunately we have to do this :( */
|
||||
if (m_Dependents.find(pPlugin) == m_Dependents.end())
|
||||
if (std::find(m_Dependents.begin(), m_Dependents.end(), pPlugin) == m_Dependents.end())
|
||||
{
|
||||
m_Dependents.push_back(pPlugin);
|
||||
}
|
||||
@@ -389,25 +399,19 @@ bool CLocalExtension::IsLoaded()
|
||||
|
||||
void CExtension::AddDependency(const IfaceInfo *pInfo)
|
||||
{
|
||||
if (m_Deps.find(*pInfo) == m_Deps.end())
|
||||
if (std::find(m_Deps.begin(), m_Deps.end(), *pInfo) == m_Deps.end())
|
||||
{
|
||||
m_Deps.push_back(*pInfo);
|
||||
}
|
||||
}
|
||||
|
||||
bool operator ==(const IfaceInfo &i1, const IfaceInfo &i2)
|
||||
{
|
||||
return (i1.iface == i2.iface) && (i1.owner == i2.owner);
|
||||
}
|
||||
|
||||
void CExtension::AddChildDependent(CExtension *pOther, SMInterface *iface)
|
||||
{
|
||||
IfaceInfo info;
|
||||
info.iface = iface;
|
||||
info.owner = pOther;
|
||||
|
||||
List<IfaceInfo>::iterator iter;
|
||||
for (iter = m_ChildDeps.begin();
|
||||
for (auto iter = m_ChildDeps.begin();
|
||||
iter != m_ChildDeps.end();
|
||||
iter++)
|
||||
{
|
||||
@@ -421,65 +425,20 @@ void CExtension::AddChildDependent(CExtension *pOther, SMInterface *iface)
|
||||
m_ChildDeps.push_back(info);
|
||||
}
|
||||
|
||||
// note: dependency iteration deprecated since 1.10
|
||||
ITERATOR *CExtension::FindFirstDependency(IExtension **pOwner, SMInterface **pInterface)
|
||||
{
|
||||
List<IfaceInfo>::iterator iter = m_Deps.begin();
|
||||
|
||||
if (iter == m_Deps.end())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pOwner)
|
||||
{
|
||||
*pOwner = (*iter).owner;
|
||||
}
|
||||
if (pInterface)
|
||||
{
|
||||
*pInterface = (*iter).iface;
|
||||
}
|
||||
|
||||
List<IfaceInfo>::iterator *pIter = new List<IfaceInfo>::iterator(iter);
|
||||
|
||||
return (ITERATOR *)pIter;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CExtension::FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface)
|
||||
{
|
||||
List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
|
||||
List<IfaceInfo>::iterator _iter;
|
||||
|
||||
if (_iter == m_Deps.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_iter++;
|
||||
|
||||
if (pOwner)
|
||||
{
|
||||
*pOwner = (*_iter).owner;
|
||||
}
|
||||
if (pInterface)
|
||||
{
|
||||
*pInterface = (*_iter).iface;
|
||||
}
|
||||
|
||||
*pIter = _iter;
|
||||
|
||||
if (_iter == m_Deps.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CExtension::FreeDependencyIterator(ITERATOR *iter)
|
||||
{
|
||||
List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
|
||||
|
||||
delete pIter;
|
||||
}
|
||||
|
||||
void CExtension::AddInterface(SMInterface *pInterface)
|
||||
@@ -493,7 +452,7 @@ bool CExtension::IsRunning(char *error, size_t maxlength)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
snprintf(error, maxlength, "%s", m_Error.c_str());
|
||||
ke::SafeStrcpy(error, maxlength, m_Error.c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -532,11 +491,9 @@ void CExtensionManager::OnSourceModShutdown()
|
||||
|
||||
void CExtensionManager::Shutdown()
|
||||
{
|
||||
List<CExtension *>::iterator iter;
|
||||
|
||||
while ((iter = m_Libs.begin()) != m_Libs.end())
|
||||
while (m_Libs.begin() != m_Libs.end())
|
||||
{
|
||||
UnloadExtension((*iter));
|
||||
UnloadExtension((*m_Libs.begin()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -546,7 +503,7 @@ void CExtensionManager::TryAutoload()
|
||||
|
||||
g_pSM->BuildPath(Path_SM, path, sizeof(path), "extensions");
|
||||
|
||||
ke::AutoPtr<IDirectory> pDir(libsys->OpenDirectory(path));
|
||||
std::unique_ptr<IDirectory> pDir(libsys->OpenDirectory(path));
|
||||
if (!pDir)
|
||||
return;
|
||||
|
||||
@@ -575,7 +532,7 @@ void CExtensionManager::TryAutoload()
|
||||
}
|
||||
|
||||
char file[PLATFORM_MAX_PATH];
|
||||
len = ke::SafeSprintf(file, sizeof(file), "%s", lfile);
|
||||
len = ke::SafeStrcpy(file, sizeof(file), lfile);
|
||||
strcpy(&file[len - 9], ".ext");
|
||||
|
||||
LoadAutoExtension(file);
|
||||
@@ -591,7 +548,7 @@ IExtension *CExtensionManager::LoadAutoExtension(const char *path, bool bErrorOn
|
||||
if (strcmp(ext, PLATFORM_LIB_EXT) == 0)
|
||||
{
|
||||
char path2[PLATFORM_MAX_PATH];
|
||||
ke::SafeSprintf(path2, sizeof(path2), "%s", path);
|
||||
ke::SafeStrcpy(path2, sizeof(path2), path);
|
||||
path2[strlen(path) - strlen(PLATFORM_LIB_EXT) - 1] = '\0';
|
||||
return LoadAutoExtension(path2, bErrorOnMissing);
|
||||
}
|
||||
@@ -625,14 +582,13 @@ IExtension *CExtensionManager::LoadAutoExtension(const char *path, bool bErrorOn
|
||||
|
||||
IExtension *CExtensionManager::FindExtensionByFile(const char *file)
|
||||
{
|
||||
List<CExtension *>::iterator iter;
|
||||
CExtension *pExt;
|
||||
|
||||
/* Chomp off the path */
|
||||
char lookup[PLATFORM_MAX_PATH];
|
||||
libsys->GetFileFromPath(lookup, sizeof(lookup), file);
|
||||
|
||||
for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
{
|
||||
pExt = (*iter);
|
||||
if (pExt->IsSameFile(lookup))
|
||||
@@ -646,12 +602,11 @@ IExtension *CExtensionManager::FindExtensionByFile(const char *file)
|
||||
|
||||
IExtension *CExtensionManager::FindExtensionByName(const char *ext)
|
||||
{
|
||||
List<CExtension *>::iterator iter;
|
||||
CExtension *pExt;
|
||||
IExtensionInterface *pAPI;
|
||||
const char *name;
|
||||
|
||||
for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
{
|
||||
pExt = (*iter);
|
||||
if (!pExt->IsLoaded())
|
||||
@@ -678,12 +633,18 @@ IExtension *CExtensionManager::FindExtensionByName(const char *ext)
|
||||
|
||||
IExtension *CExtensionManager::LoadExtension(const char *file, char *error, size_t maxlength)
|
||||
{
|
||||
if (strstr(file, "..") != NULL)
|
||||
{
|
||||
ke::SafeStrcpy(error, maxlength, "Cannot load extensions outside the \"extensions\" folder.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Remove platform extension if it's there. Compat hack. */
|
||||
const char *ext = libsys->GetFileExtension(file);
|
||||
if (strcmp(ext, PLATFORM_LIB_EXT) == 0)
|
||||
if (ext && strcmp(ext, PLATFORM_LIB_EXT) == 0)
|
||||
{
|
||||
char path2[PLATFORM_MAX_PATH];
|
||||
ke::SafeSprintf(path2, sizeof(path2), "%s", file);
|
||||
ke::SafeStrcpy(path2, sizeof(path2), file);
|
||||
path2[strlen(file) - strlen(PLATFORM_LIB_EXT) - 1] = '\0';
|
||||
return LoadExtension(path2, error, maxlength);
|
||||
}
|
||||
@@ -754,9 +715,7 @@ void CExtensionManager::BindChildPlugin(IExtension *pParent, SMPlugin *pPlugin)
|
||||
|
||||
void CExtensionManager::OnPluginDestroyed(IPlugin *plugin)
|
||||
{
|
||||
List<CExtension *>::iterator iter;
|
||||
|
||||
for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
{
|
||||
(*iter)->DropRefsTo(static_cast<CPlugin *>(plugin));
|
||||
}
|
||||
@@ -769,7 +728,7 @@ CExtension *CExtensionManager::FindByOrder(unsigned int num)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
List<CExtension *>::iterator iter = m_Libs.begin();
|
||||
auto iter = m_Libs.begin();
|
||||
|
||||
while (iter != m_Libs.end())
|
||||
{
|
||||
@@ -790,7 +749,8 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt)
|
||||
|
||||
CExtension *pExt = (CExtension *)_pExt;
|
||||
|
||||
if (m_Libs.find(pExt) == m_Libs.end())
|
||||
auto iter = std::find(m_Libs.begin(), m_Libs.end(), pExt);
|
||||
if (iter == m_Libs.end())
|
||||
return false;
|
||||
|
||||
/* Tell it to unload */
|
||||
@@ -804,13 +764,13 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt)
|
||||
g_ShareSys.RemoveInterfaces(_pExt);
|
||||
m_Libs.remove(pExt);
|
||||
|
||||
List<CExtension *> UnloadQueue;
|
||||
std::list<CExtension *> UnloadQueue;
|
||||
|
||||
/* Handle dependencies */
|
||||
if (pExt->IsLoaded())
|
||||
{
|
||||
/* Unload any dependent plugins */
|
||||
List<CPlugin *>::iterator p_iter = pExt->m_Dependents.begin();
|
||||
auto p_iter = pExt->m_Dependents.begin();
|
||||
while (p_iter != pExt->m_Dependents.end())
|
||||
{
|
||||
/* We have to manually unlink ourselves here, since we're no longer being managed */
|
||||
@@ -818,8 +778,7 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt)
|
||||
p_iter = pExt->m_Dependents.erase(p_iter);
|
||||
}
|
||||
|
||||
List<String>::iterator s_iter;
|
||||
for (s_iter = pExt->m_Libraries.begin();
|
||||
for (auto s_iter = pExt->m_Libraries.begin();
|
||||
s_iter != pExt->m_Libraries.end();
|
||||
s_iter++)
|
||||
{
|
||||
@@ -827,10 +786,9 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt)
|
||||
}
|
||||
|
||||
/* Notify and/or unload all dependencies */
|
||||
List<CExtension *>::iterator c_iter;
|
||||
CExtension *pDep;
|
||||
IExtensionInterface *pAPI;
|
||||
for (c_iter = m_Libs.begin(); c_iter != m_Libs.end(); c_iter++)
|
||||
for (auto c_iter = m_Libs.begin(); c_iter != m_Libs.end(); c_iter++)
|
||||
{
|
||||
pDep = (*c_iter);
|
||||
if ((pAPI=pDep->GetAPI()) == NULL)
|
||||
@@ -839,7 +797,7 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt)
|
||||
continue;
|
||||
/* Now, get its dependency list */
|
||||
bool dropped = false;
|
||||
List<IfaceInfo>::iterator i_iter = pDep->m_Deps.begin();
|
||||
auto i_iter = pDep->m_Deps.begin();
|
||||
while (i_iter != pDep->m_Deps.end())
|
||||
{
|
||||
if ((*i_iter).owner == _pExt)
|
||||
@@ -894,8 +852,7 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt)
|
||||
pExt->Unload();
|
||||
delete pExt;
|
||||
|
||||
List<CExtension *>::iterator iter;
|
||||
for (iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++)
|
||||
for (auto iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++)
|
||||
{
|
||||
/* NOTE: This is safe because the unload function backs out of anything not present */
|
||||
UnloadExtension((*iter));
|
||||
@@ -906,10 +863,9 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt)
|
||||
|
||||
void CExtensionManager::MarkAllLoaded()
|
||||
{
|
||||
List<CExtension *>::iterator iter;
|
||||
CExtension *pExt;
|
||||
|
||||
for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
{
|
||||
pExt = (*iter);
|
||||
if (!pExt->IsLoaded())
|
||||
@@ -944,24 +900,10 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
|
||||
const char *cmd = command->Arg(2);
|
||||
if (strcmp(cmd, "list") == 0)
|
||||
{
|
||||
List<CExtension *>::iterator iter;
|
||||
CExtension *pExt;
|
||||
unsigned int num = 1;
|
||||
|
||||
List<CExtension *> required; // List of loaded and required extensions
|
||||
List<CExtension *> optional; // List of non loaded optional extensions
|
||||
|
||||
for (iter = m_Libs.begin(); iter != m_Libs.end(); iter++)
|
||||
{
|
||||
pExt = (*iter);
|
||||
|
||||
if (pExt->IsLoaded() || pExt->IsRequired())
|
||||
required.push_back(pExt);
|
||||
else if (!pExt->IsLoaded() && !pExt->IsRequired())
|
||||
optional.push_back(pExt);
|
||||
}
|
||||
|
||||
switch (required.size())
|
||||
switch (m_Libs.size())
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
@@ -975,11 +917,11 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
|
||||
}
|
||||
default:
|
||||
{
|
||||
rootmenu->ConsolePrint("[SM] Displaying %d extensions:", required.size());
|
||||
rootmenu->ConsolePrint("[SM] Displaying %d extensions:", m_Libs.size());
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (iter = required.begin(); iter != required.end(); iter++,num++)
|
||||
for (auto iter = m_Libs.begin(); iter != m_Libs.end(); iter++,num++)
|
||||
{
|
||||
pExt = (*iter);
|
||||
if (pExt->IsLoaded())
|
||||
@@ -998,32 +940,13 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
|
||||
rootmenu->ConsolePrint("[%02d] %s (%s): %s", num, name, version, descr);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(pExt->IsRequired() || libsys->PathExists(pExt->GetPath()))
|
||||
{
|
||||
rootmenu->ConsolePrint("[%02d] <FAILED> file \"%s\": %s", num, pExt->GetFilename(), pExt->m_Error.c_str());
|
||||
}
|
||||
}
|
||||
if (optional.size())
|
||||
{
|
||||
num = 1;
|
||||
switch (optional.size())
|
||||
else
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
rootmenu->ConsolePrint("\n[SM] Displaying 1 optional extension not found:");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
rootmenu->ConsolePrint("\n[SM] Displaying %d optional extensions not found:", optional.size());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (iter = optional.begin(); iter != optional.end(); iter++,num++)
|
||||
{
|
||||
pExt = (*iter);
|
||||
rootmenu->ConsolePrint("[%02d] \"%s\"", num, pExt->GetFilename());
|
||||
rootmenu->ConsolePrint("[%02d] <OPTIONAL> file \"%s\": %s", num, pExt->GetFilename(), pExt->m_Error.c_str());
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -1087,7 +1010,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
|
||||
return;
|
||||
}
|
||||
|
||||
List<CExtension *>::iterator iter = m_Libs.begin();
|
||||
auto iter = m_Libs.begin();
|
||||
CExtension *pExt = NULL;
|
||||
while (iter != m_Libs.end())
|
||||
{
|
||||
@@ -1168,7 +1091,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
|
||||
if (pExt->unload_code == (unsigned)atoi(unload))
|
||||
{
|
||||
char filename[PLATFORM_MAX_PATH];
|
||||
snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
|
||||
ke::SafeStrcpy(filename, PLATFORM_MAX_PATH, pExt->GetFilename());
|
||||
UnloadExtension(pExt);
|
||||
rootmenu->ConsolePrint("[SM] Extension %s is now unloaded.", filename);
|
||||
}
|
||||
@@ -1183,30 +1106,28 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
|
||||
|| (!pExt->m_ChildDeps.size() && !pExt->m_Dependents.size()))
|
||||
{
|
||||
char filename[PLATFORM_MAX_PATH];
|
||||
snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
|
||||
ke::SafeStrcpy(filename, PLATFORM_MAX_PATH, pExt->GetFilename());
|
||||
UnloadExtension(pExt);
|
||||
rootmenu->ConsolePrint("[SM] Extension %s is now unloaded.", filename);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
List<CPlugin *> plugins;
|
||||
std::list<CPlugin *> plugins;
|
||||
if (pExt->m_ChildDeps.size())
|
||||
{
|
||||
rootmenu->ConsolePrint("[SM] Unloading %s will unload the following extensions: ", pExt->GetFilename());
|
||||
List<CExtension *>::iterator iter;
|
||||
CExtension *pOther;
|
||||
/* Get list of all extensions */
|
||||
for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
{
|
||||
List<IfaceInfo>::iterator i_iter;
|
||||
pOther = (*iter);
|
||||
if (!pOther->IsLoaded() || pOther == pExt)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
/* Get their dependencies */
|
||||
for (i_iter=pOther->m_Deps.begin();
|
||||
for (auto i_iter=pOther->m_Deps.begin();
|
||||
i_iter!=pOther->m_Deps.end();
|
||||
i_iter++)
|
||||
{
|
||||
@@ -1220,12 +1141,12 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
|
||||
{
|
||||
rootmenu->ConsolePrint(" -> %s", pOther->GetFilename());
|
||||
/* Add to plugin unload list */
|
||||
List<CPlugin *>::iterator p_iter;
|
||||
for (p_iter=pOther->m_Dependents.begin();
|
||||
for (auto p_iter=pOther->m_Dependents.begin();
|
||||
p_iter!=pOther->m_Dependents.end();
|
||||
p_iter++)
|
||||
{
|
||||
if (plugins.find((*p_iter)) == plugins.end())
|
||||
auto lookup = std::find(plugins.begin(), plugins.end(), (*p_iter));
|
||||
if (lookup == plugins.end())
|
||||
{
|
||||
plugins.push_back((*p_iter));
|
||||
}
|
||||
@@ -1237,23 +1158,22 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
|
||||
if (pExt->m_Dependents.size())
|
||||
{
|
||||
rootmenu->ConsolePrint("[SM] Unloading %s will unload the following plugins: ", pExt->GetFilename());
|
||||
List<CPlugin *>::iterator iter;
|
||||
CPlugin *pPlugin;
|
||||
for (iter = pExt->m_Dependents.begin(); iter != pExt->m_Dependents.end(); iter++)
|
||||
for (auto iter = pExt->m_Dependents.begin(); iter != pExt->m_Dependents.end(); iter++)
|
||||
{
|
||||
pPlugin = (*iter);
|
||||
if (plugins.find(pPlugin) == plugins.end())
|
||||
auto lookup = std::find(plugins.begin(), plugins.end(), pPlugin);
|
||||
if (lookup == plugins.end())
|
||||
{
|
||||
plugins.push_back(pPlugin);
|
||||
}
|
||||
}
|
||||
for (iter = plugins.begin(); iter != plugins.end(); iter++)
|
||||
for (auto iter = plugins.begin(); iter != plugins.end(); iter++)
|
||||
{
|
||||
pPlugin = (*iter);
|
||||
rootmenu->ConsolePrint(" -> %s", pPlugin->GetFilename());
|
||||
}
|
||||
}
|
||||
srand(static_cast<int>(time(NULL)));
|
||||
pExt->unload_code = (rand() % 877) + 123; //123 to 999
|
||||
rootmenu->ConsolePrint("[SM] To verify unloading %s, please use the following: ", pExt->GetFilename());
|
||||
rootmenu->ConsolePrint("[SM] sm exts unload %d %d", num, pExt->unload_code);
|
||||
@@ -1284,7 +1204,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
|
||||
char filename[PLATFORM_MAX_PATH];
|
||||
char error[255];
|
||||
|
||||
snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
|
||||
ke::SafeStrcpy(filename, PLATFORM_MAX_PATH, pExt->GetFilename());
|
||||
|
||||
if (pExt->Reload(error, sizeof(error)))
|
||||
{
|
||||
@@ -1344,12 +1264,12 @@ bool CExtensionManager::LibraryExists(const char *library)
|
||||
{
|
||||
CExtension *pExt;
|
||||
|
||||
for (List<CExtension *>::iterator iter = m_Libs.begin();
|
||||
for (auto iter = m_Libs.begin();
|
||||
iter != m_Libs.end();
|
||||
iter++)
|
||||
{
|
||||
pExt = (*iter);
|
||||
for (List<String>::iterator s_iter = pExt->m_Libraries.begin();
|
||||
for (auto s_iter = pExt->m_Libraries.begin();
|
||||
s_iter != pExt->m_Libraries.end();
|
||||
s_iter++)
|
||||
{
|
||||
@@ -1392,9 +1312,8 @@ IExtension *CExtensionManager::LoadExternal(IExtensionInterface *pInterface,
|
||||
void CExtensionManager::CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
|
||||
{
|
||||
IExtensionInterface *pAPI;
|
||||
List<CExtension *>::iterator iter;
|
||||
|
||||
for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
{
|
||||
if ((pAPI = (*iter)->GetAPI()) == NULL)
|
||||
{
|
||||
@@ -1410,9 +1329,8 @@ void CExtensionManager::CallOnCoreMapStart(edict_t *pEdictList, int edictCount,
|
||||
void CExtensionManager::CallOnCoreMapEnd()
|
||||
{
|
||||
IExtensionInterface *pAPI;
|
||||
List<CExtension *>::iterator iter;
|
||||
|
||||
for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
|
||||
{
|
||||
if ((pAPI = (*iter)->GetAPI()) == NULL)
|
||||
{
|
||||
@@ -1425,17 +1343,17 @@ void CExtensionManager::CallOnCoreMapEnd()
|
||||
}
|
||||
}
|
||||
|
||||
const CVector<IExtension *> *CExtensionManager::ListExtensions()
|
||||
const std::vector<IExtension *> *CExtensionManager::ListExtensions()
|
||||
{
|
||||
CVector<IExtension *> *list = new CVector<IExtension *>();
|
||||
for (List<CExtension *>::iterator iter = m_Libs.begin(); iter != m_Libs.end(); iter++)
|
||||
std::vector<IExtension *> *list = new std::vector<IExtension *>();
|
||||
for (auto iter = m_Libs.begin(); iter != m_Libs.end(); iter++)
|
||||
list->push_back(*iter);
|
||||
return list;
|
||||
}
|
||||
|
||||
void CExtensionManager::FreeExtensionList(const CVector<IExtension *> *list)
|
||||
void CExtensionManager::FreeExtensionList(const std::vector<IExtension *> *list)
|
||||
{
|
||||
delete const_cast<CVector<IExtension *> *>(list);
|
||||
delete const_cast<std::vector<IExtension *> *>(list);
|
||||
}
|
||||
|
||||
bool CLocalExtension::IsSameFile(const char *file)
|
||||
@@ -1446,7 +1364,7 @@ bool CLocalExtension::IsSameFile(const char *file)
|
||||
|
||||
bool CRemoteExtension::IsSameFile(const char *file)
|
||||
{
|
||||
/* :TODO: this could be better, but no one uses this API anyway. */
|
||||
return strcmp(file, m_Path.c_str()) == 0;
|
||||
/* Check full path and name passed in from LoadExternal */
|
||||
return strcmp(file, m_Path.c_str()) == 0 || strcmp(file, m_File.c_str()) == 0;
|
||||
}
|
||||
|
||||
|
||||
+13
-14
@@ -34,8 +34,8 @@
|
||||
|
||||
#include <IExtensionSys.h>
|
||||
#include <ILibrarySys.h>
|
||||
#include <sh_list.h>
|
||||
#include <sh_string.h>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include "common_logic.h"
|
||||
#include <IPluginSys.h>
|
||||
#include <IRootConsoleMenu.h>
|
||||
@@ -46,7 +46,6 @@
|
||||
class CPlayer;
|
||||
|
||||
using namespace SourceMod;
|
||||
using namespace SourceHook;
|
||||
|
||||
class CExtension;
|
||||
|
||||
@@ -95,14 +94,14 @@ protected:
|
||||
protected:
|
||||
IdentityToken_t *m_pIdentToken;
|
||||
IExtensionInterface *m_pAPI;
|
||||
String m_File;
|
||||
String m_RealFile;
|
||||
String m_Path;
|
||||
String m_Error;
|
||||
List<IfaceInfo> m_Deps; /** Dependencies */
|
||||
List<IfaceInfo> m_ChildDeps; /** Children who might depend on us */
|
||||
List<SMInterface *> m_Interfaces;
|
||||
List<String> m_Libraries;
|
||||
std::string m_File;
|
||||
std::string m_RealFile;
|
||||
std::string m_Path;
|
||||
std::string m_Error;
|
||||
std::list<IfaceInfo> m_Deps; /** Dependencies */
|
||||
std::list<IfaceInfo> m_ChildDeps; /** Children who might depend on us */
|
||||
std::list<SMInterface *> m_Interfaces;
|
||||
std::list<std::string> m_Libraries;
|
||||
unsigned int unload_code;
|
||||
bool m_bFullyLoaded;
|
||||
bool m_bRequired;
|
||||
@@ -178,8 +177,8 @@ public:
|
||||
void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax);
|
||||
void CallOnCoreMapEnd();
|
||||
void AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface);
|
||||
const CVector<IExtension *> *ListExtensions();
|
||||
void FreeExtensionList(const CVector<IExtension *> *list);
|
||||
const std::vector<IExtension *> *ListExtensions();
|
||||
void FreeExtensionList(const std::vector<IExtension *> *list);
|
||||
public:
|
||||
CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
|
||||
void Shutdown();
|
||||
@@ -191,7 +190,7 @@ public:
|
||||
private:
|
||||
CExtension *FindByOrder(unsigned int num);
|
||||
private:
|
||||
List<CExtension *> m_Libs;
|
||||
std::list<CExtension *> m_Libs;
|
||||
};
|
||||
|
||||
extern CExtensionManager g_Extensions;
|
||||
|
||||
+197
-407
@@ -36,6 +36,7 @@
|
||||
#include <ReentrantList.h>
|
||||
|
||||
using namespace ke;
|
||||
using sp::CallArgs;
|
||||
|
||||
CForwardManager g_Forwards;
|
||||
|
||||
@@ -61,7 +62,7 @@ IForward *CForwardManager::CreateForward(const char *name, ExecType et, unsigned
|
||||
{
|
||||
scripts->AddFunctionsToForward(name, fwd);
|
||||
|
||||
m_managed.append(fwd);
|
||||
m_managed.push_back(fwd);
|
||||
}
|
||||
|
||||
return fwd;
|
||||
@@ -78,7 +79,7 @@ IChangeableForward *CForwardManager::CreateForwardEx(const char *name, ExecType
|
||||
|
||||
if (fwd)
|
||||
{
|
||||
m_unmanaged.append(fwd);
|
||||
m_unmanaged.push_back(fwd);
|
||||
}
|
||||
|
||||
return fwd;
|
||||
@@ -137,6 +138,15 @@ IForward *CForwardManager::FindForward(const char *name, IChangeableForward **if
|
||||
void CForwardManager::ReleaseForward(IForward *aForward)
|
||||
{
|
||||
CForward *fwd = static_cast<CForward *>(aForward);
|
||||
|
||||
if (fwd->m_ExecDepth > 0)
|
||||
{
|
||||
/* Still executing (possibly nested); defer the real deletion until
|
||||
* the outermost Execute() call unwinds. */
|
||||
fwd->m_deleted = true;
|
||||
return;
|
||||
}
|
||||
|
||||
m_managed.remove(fwd);
|
||||
m_unmanaged.remove(fwd);
|
||||
delete fwd;
|
||||
@@ -164,24 +174,22 @@ void CForwardManager::OnPluginPauseChange(IPlugin *plugin, bool paused)
|
||||
*************************************/
|
||||
|
||||
CForward::CForward(ExecType et, const char *name, const ParamType *types, unsigned num_params)
|
||||
: m_numparams(0),
|
||||
m_varargs(0),
|
||||
: m_addresses(0),
|
||||
m_numparams(0),
|
||||
m_ExecType(et),
|
||||
m_curparam(0),
|
||||
m_errstate(SP_ERROR_NONE)
|
||||
m_errstate(SP_ERROR_NONE),
|
||||
m_ExecDepth(0),
|
||||
m_deleted(false)
|
||||
{
|
||||
ke::SafeStrcpy(m_name, sizeof(m_name), name ? name : "");
|
||||
|
||||
for (unsigned i = 0; i < num_params; i++)
|
||||
for (unsigned i = 0; i < num_params; i++) {
|
||||
m_types[i] = types[i];
|
||||
|
||||
if (num_params && types[num_params - 1] == Param_VarArgs) {
|
||||
m_varargs = num_params;
|
||||
m_numparams = num_params - 1;
|
||||
} else {
|
||||
m_varargs = 0;
|
||||
m_numparams = num_params;
|
||||
if (types[i] == Param_SMAddress)
|
||||
m_addresses |= 1u << i;
|
||||
}
|
||||
|
||||
m_numparams = num_params;
|
||||
}
|
||||
|
||||
CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int num_params, const ParamType *types, va_list ap)
|
||||
@@ -196,491 +204,273 @@ CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int nu
|
||||
if (types == NULL && num_params)
|
||||
{
|
||||
for (unsigned int i=0; i<num_params; i++)
|
||||
{
|
||||
_types[i] = (ParamType)va_arg(ap, int);
|
||||
if (_types[i] == Param_VarArgs && (i != num_params - 1))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
types = _types;
|
||||
} else {
|
||||
for (unsigned int i=0; i<num_params; i++)
|
||||
{
|
||||
_types[i] = types[i];
|
||||
if (types[i] == Param_VarArgs && (i != num_params - 1))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* First parameter can never be varargs */
|
||||
if (num_params && _types[0] == Param_VarArgs)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new CForward(et, name, _types, num_params);
|
||||
}
|
||||
|
||||
bool InvokePluginFunction(IPluginFunction *func, const CallArgs& args, AddressMask addresses, cell_t *result)
|
||||
{
|
||||
// Plugins compiled before SourceMod 1.13 take an Address as one cell and cannot read an int64 argument. Like DHooks,
|
||||
// pass them the low 32 bits of an Address instead. Any other int64 has no single cell equivalent, so they cannot be
|
||||
// called with one.
|
||||
bool has_int64 = false;
|
||||
for (uint32_t i = 0; i < args.argc; i++)
|
||||
has_int64 |= args.argv[i].type == CallArgs::ARG_INT64;
|
||||
if (!has_int64 || func->GetParentRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE)
|
||||
return func->Invoke(args, result);
|
||||
|
||||
CallArgs legacy_args = args;
|
||||
for (uint32_t i = 0; i < legacy_args.argc; i++) {
|
||||
auto& arg = legacy_args.argv[i];
|
||||
if (arg.type != CallArgs::ARG_INT64)
|
||||
continue;
|
||||
if (!(addresses & (1u << i))) {
|
||||
IPluginContext *ctx = func->GetParentRuntime()->GetDefaultContext();
|
||||
IPlugin *plugin = pluginsys->FindPluginByContext(ctx);
|
||||
ctx->ReportError("Plugin \"%s\" was compiled before SourceMod 1.13 and cannot receive int64 argument %u",
|
||||
plugin ? plugin->GetFilename() : "<unknown>", i + 1);
|
||||
return false;
|
||||
}
|
||||
arg.u.value = static_cast<cell_t>(arg.u.i64);
|
||||
arg.type = CallArgs::ARG_CELL;
|
||||
arg.flags = 0;
|
||||
}
|
||||
return func->Invoke(legacy_args, result);
|
||||
}
|
||||
|
||||
bool CForward::ProcessArguments(const CallArgs& args) {
|
||||
if (args.error)
|
||||
return !SetError(SP_ERROR_PARAMS_MAX);
|
||||
|
||||
for (uint32_t i = 0; i < args.argc; i++) {
|
||||
if (i >= m_numparams)
|
||||
return !SetError(SP_ERROR_PARAM);
|
||||
|
||||
ParamType pt = m_types[i];
|
||||
if (pt == Param_Any)
|
||||
continue;
|
||||
|
||||
auto& arg = args.argv[i];
|
||||
switch (arg.type) {
|
||||
case CallArgs::ARG_CELL:
|
||||
if (arg.flags & CallArgs::FLAG_CELL_TYPE_FLOAT) {
|
||||
if (pt != Param_Float)
|
||||
return !SetError(SP_ERROR_PARAM);
|
||||
} else {
|
||||
if (pt != Param_Cell)
|
||||
return !SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
break;
|
||||
case CallArgs::ARG_CELL_BY_REF:
|
||||
if (arg.flags & CallArgs::FLAG_CELL_TYPE_FLOAT) {
|
||||
if (pt != Param_FloatByRef)
|
||||
return !SetError(SP_ERROR_PARAM);
|
||||
} else {
|
||||
if (pt != Param_CellByRef)
|
||||
return !SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
break;
|
||||
case CallArgs::ARG_ARRAY:
|
||||
if (pt != Param_Array)
|
||||
return !SetError(SP_ERROR_PARAM);
|
||||
break;
|
||||
case CallArgs::ARG_CHAR_ARRAY:
|
||||
if (pt != Param_String)
|
||||
return !SetError(SP_ERROR_PARAM);
|
||||
break;
|
||||
case CallArgs::ARG_INT64:
|
||||
if (pt != Param_Int64 && pt != Param_SMAddress)
|
||||
return !SetError(SP_ERROR_PARAM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int CForward::Execute(cell_t *result, IForwardFilter *filter)
|
||||
{
|
||||
if (m_errstate)
|
||||
{
|
||||
auto args = std::move(default_args_);
|
||||
default_args_.Reset();
|
||||
|
||||
return Execute(args, result, filter);
|
||||
}
|
||||
|
||||
int CForward::Execute(const sp::CallArgs& in_args, cell_t *result, IForwardFilter *filter)
|
||||
{
|
||||
if (m_errstate) {
|
||||
int err = m_errstate;
|
||||
Cancel();
|
||||
return err;
|
||||
}
|
||||
|
||||
cell_t cur_result = 0;
|
||||
auto args = in_args;
|
||||
unsigned int success = 0;
|
||||
cell_t high_result = 0;
|
||||
cell_t low_result = 0;
|
||||
int err;
|
||||
unsigned int success=0;
|
||||
unsigned int num_params = m_curparam;
|
||||
FwdParamInfo temp_info[SP_MAX_EXEC_PARAMS];
|
||||
cell_t cur_result = 0;
|
||||
|
||||
/* Save local, reset */
|
||||
memcpy(temp_info, m_params, sizeof(m_params));
|
||||
m_curparam = 0;
|
||||
if (!ProcessArguments(args)) {
|
||||
int err = m_errstate;
|
||||
Cancel();
|
||||
return err;
|
||||
}
|
||||
|
||||
m_ExecDepth++;
|
||||
|
||||
for (FuncIter iter(m_functions); !iter.done(); iter.next())
|
||||
{
|
||||
IPluginFunction *func = (*iter);
|
||||
|
||||
if (filter)
|
||||
filter->Preprocess(func, temp_info);
|
||||
filter->Preprocess(func, args);
|
||||
|
||||
if (func->GetParentRuntime()->IsPaused())
|
||||
continue;
|
||||
|
||||
for (unsigned int i=0; i<num_params; i++)
|
||||
ExceptionHandler eh(func->GetParentRuntime());
|
||||
|
||||
if (!InvokePluginFunction(func, args, m_addresses, &cur_result))
|
||||
continue;
|
||||
|
||||
success++;
|
||||
switch (m_ExecType)
|
||||
{
|
||||
int err = SP_ERROR_PARAM;
|
||||
FwdParamInfo *param = &temp_info[i];
|
||||
|
||||
ParamType type;
|
||||
if (i >= m_numparams || m_types[i] == Param_Any)
|
||||
type = param->pushedas;
|
||||
else
|
||||
type = m_types[i];
|
||||
|
||||
if ((i >= m_numparams) || (type & SP_PARAMFLAG_BYREF))
|
||||
{
|
||||
/* If we're byref or we're vararg, we always push everything by ref.
|
||||
* Even if they're byval, we must push them byref.
|
||||
*/
|
||||
err = _ExecutePushRef(func, type, param);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If we're not byref or not vararg, our job is a bit easier. */
|
||||
assert(type == Param_Cell || type == Param_Float);
|
||||
err = func->PushCell(param->val);
|
||||
}
|
||||
|
||||
if (err != SP_ERROR_NONE)
|
||||
{
|
||||
g_DbgReporter.GenerateError(func->GetParentContext(),
|
||||
func->GetFunctionID(),
|
||||
err,
|
||||
"Failed to push parameter while executing forward");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* Call the function and deal with the return value. */
|
||||
if ((err=func->Execute(&cur_result)) == SP_ERROR_NONE)
|
||||
{
|
||||
success++;
|
||||
switch (m_ExecType)
|
||||
{
|
||||
case ET_Event:
|
||||
{
|
||||
if (cur_result > high_result)
|
||||
{
|
||||
high_result = cur_result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (cur_result > high_result)
|
||||
high_result = cur_result;
|
||||
break;
|
||||
case ET_Hook:
|
||||
{
|
||||
if (cur_result > high_result)
|
||||
{
|
||||
high_result = cur_result;
|
||||
if ((ResultType)high_result == Pl_Stop)
|
||||
{
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (cur_result > high_result)
|
||||
high_result = cur_result;
|
||||
break;
|
||||
case ET_LowEvent:
|
||||
{
|
||||
/* Check if the current result is the lowest so far (or if it's the first result) */
|
||||
if (cur_result < low_result || success == 1)
|
||||
{
|
||||
low_result = cur_result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* Check if the current result is the lowest so far (or if it's the first result) */
|
||||
if (cur_result < low_result || success == 1)
|
||||
low_result = cur_result;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (m_ExecType == ET_Hook && (ResultType)high_result == Pl_Stop)
|
||||
break;
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
switch (m_ExecType)
|
||||
{
|
||||
case ET_Ignore:
|
||||
{
|
||||
case ET_Ignore:
|
||||
cur_result = 0;
|
||||
break;
|
||||
}
|
||||
case ET_Event:
|
||||
case ET_Hook:
|
||||
{
|
||||
case ET_Event:
|
||||
case ET_Hook:
|
||||
cur_result = high_result;
|
||||
break;
|
||||
}
|
||||
case ET_LowEvent:
|
||||
{
|
||||
case ET_LowEvent:
|
||||
cur_result = low_result;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
*result = cur_result;
|
||||
}
|
||||
}
|
||||
|
||||
/* If a callback we just invoked freed this forward's handle (e.g. the
|
||||
* plugin deletes its own private forward from within one of its own
|
||||
* callbacks), the actual delete is deferred to here so we don't touch
|
||||
* freed memory by continuing to use "this" above. */
|
||||
if (--m_ExecDepth == 0 && m_deleted)
|
||||
{
|
||||
g_Forwards.ReleaseForward(this);
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int CForward::_ExecutePushRef(IPluginFunction *func, ParamType type, FwdParamInfo *param)
|
||||
{
|
||||
/* If we're byref or we're vararg, we always push everything by ref.
|
||||
* Even if they're byval, we must push them byref.
|
||||
*/
|
||||
int err;
|
||||
IPluginRuntime *runtime = func->GetParentRuntime();
|
||||
switch (type)
|
||||
{
|
||||
case Param_String:
|
||||
// Normal string was pushed.
|
||||
if (!param->isnull)
|
||||
return func->PushStringEx((char *)param->byref.orig_addr, param->byref.cells, param->byref.sz_flags, param->byref.flags);
|
||||
|
||||
// If NULL_STRING was pushed, push the reference to the pubvar of the callee instead.
|
||||
uint32_t null_string_idx;
|
||||
err = runtime->FindPubvarByName("NULL_STRING", &null_string_idx);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
cell_t null_string;
|
||||
err = runtime->GetPubvarAddrs(null_string_idx, &null_string, nullptr);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return func->PushCell(null_string);
|
||||
|
||||
case Param_Float:
|
||||
case Param_Cell:
|
||||
return func->PushCellByRef(¶m->val);
|
||||
|
||||
default:
|
||||
assert(type == Param_Array || type == Param_FloatByRef || type == Param_CellByRef);
|
||||
// No NULL_VECTOR was pushed.
|
||||
if (type != Param_Array || !param->isnull)
|
||||
return func->PushArray(param->byref.orig_addr, param->byref.cells, param->byref.flags);
|
||||
|
||||
// If NULL_VECTOR was pushed, push the reference to the pubvar of the callee instead.
|
||||
uint32_t null_vector_idx;
|
||||
err = runtime->FindPubvarByName("NULL_VECTOR", &null_vector_idx);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
cell_t null_vector;
|
||||
err = runtime->GetPubvarAddrs(null_vector_idx, &null_vector, nullptr);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return func->PushCell(null_vector);
|
||||
}
|
||||
}
|
||||
|
||||
int CForward::PushCell(cell_t cell)
|
||||
{
|
||||
if (m_curparam < m_numparams)
|
||||
{
|
||||
if (m_types[m_curparam] == Param_Any)
|
||||
{
|
||||
m_params[m_curparam].pushedas = Param_Cell;
|
||||
} else if (m_types[m_curparam] != Param_Cell) {
|
||||
return SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
} else {
|
||||
if (!m_varargs || m_numparams > SP_MAX_EXEC_PARAMS)
|
||||
{
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
}
|
||||
m_params[m_curparam].pushedas = Param_Cell;
|
||||
}
|
||||
|
||||
m_params[m_curparam].isnull = false;
|
||||
m_params[m_curparam++].val = cell;
|
||||
default_args_.PushCell(cell);
|
||||
if (default_args_.error)
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int CForward::PushInt64(int64_t value)
|
||||
{
|
||||
default_args_.PushInt64(value);
|
||||
if (default_args_.error)
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int CForward::PushFloat(float number)
|
||||
{
|
||||
if (m_curparam < m_numparams)
|
||||
{
|
||||
if (m_types[m_curparam] == Param_Any)
|
||||
{
|
||||
m_params[m_curparam].pushedas = Param_Float;
|
||||
} else if (m_types[m_curparam] != Param_Float) {
|
||||
return SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
} else {
|
||||
if (!m_varargs || m_numparams > SP_MAX_EXEC_PARAMS)
|
||||
{
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
}
|
||||
m_params[m_curparam].pushedas = Param_Float;
|
||||
}
|
||||
|
||||
m_params[m_curparam].isnull = false;
|
||||
m_params[m_curparam++].val = *(cell_t *)&number;
|
||||
|
||||
default_args_.PushFloat(number);
|
||||
if (default_args_.error)
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int CForward::PushCellByRef(cell_t *cell, int flags)
|
||||
{
|
||||
if (m_curparam < m_numparams)
|
||||
{
|
||||
if (m_types[m_curparam] == Param_Any)
|
||||
{
|
||||
m_params[m_curparam].pushedas = Param_CellByRef;
|
||||
} else if (m_types[m_curparam] != Param_CellByRef) {
|
||||
return SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
} else {
|
||||
if (!m_varargs || m_numparams > SP_MAX_EXEC_PARAMS)
|
||||
{
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
}
|
||||
m_params[m_curparam].pushedas = Param_CellByRef;
|
||||
}
|
||||
|
||||
_Int_PushArray(cell, 1, flags);
|
||||
m_curparam++;
|
||||
|
||||
default_args_.PushCellByRef(cell, flags);
|
||||
if (default_args_.error)
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int CForward::PushFloatByRef(float *num, int flags)
|
||||
{
|
||||
if (m_curparam < m_numparams)
|
||||
{
|
||||
if (m_types[m_curparam] == Param_Any)
|
||||
{
|
||||
m_params[m_curparam].pushedas = Param_FloatByRef;
|
||||
} else if (m_types[m_curparam] != Param_FloatByRef) {
|
||||
return SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
} else {
|
||||
if (!m_varargs || m_numparams > SP_MAX_EXEC_PARAMS)
|
||||
{
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
}
|
||||
m_params[m_curparam].pushedas = Param_FloatByRef;
|
||||
}
|
||||
|
||||
_Int_PushArray((cell_t *)num, 1, flags);
|
||||
m_curparam++;
|
||||
|
||||
default_args_.PushFloatByRef(num, flags);
|
||||
if (default_args_.error)
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
void CForward::_Int_PushArray(cell_t *inarray, unsigned int cells, int flags)
|
||||
{
|
||||
m_params[m_curparam].byref.cells = cells;
|
||||
m_params[m_curparam].byref.flags = flags;
|
||||
m_params[m_curparam].byref.orig_addr = inarray;
|
||||
m_params[m_curparam].isnull = false;
|
||||
}
|
||||
|
||||
int CForward::PushArray(cell_t *inarray, unsigned int cells, int flags)
|
||||
{
|
||||
/* Push a reference to the NULL_VECTOR pubvar if NULL was passed. */
|
||||
if (!inarray)
|
||||
{
|
||||
/* Make sure this was intentional. */
|
||||
if (cells == 3)
|
||||
{
|
||||
return PushNullVector();
|
||||
} else {
|
||||
/* We don't allow this here */
|
||||
return SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
if (!inarray) {
|
||||
return SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
|
||||
if (m_curparam < m_numparams)
|
||||
{
|
||||
if (m_types[m_curparam] == Param_Any)
|
||||
{
|
||||
m_params[m_curparam].pushedas = Param_Array;
|
||||
} else if (m_types[m_curparam] != Param_Array) {
|
||||
return SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
} else {
|
||||
if (!m_varargs || m_curparam > SP_MAX_EXEC_PARAMS)
|
||||
{
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
}
|
||||
m_params[m_curparam].pushedas = Param_Array;
|
||||
}
|
||||
|
||||
_Int_PushArray(inarray, cells, flags);
|
||||
|
||||
m_curparam++;
|
||||
|
||||
default_args_.PushArray(inarray, cells, flags);
|
||||
if (default_args_.error)
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
void CForward::_Int_PushString(cell_t *inarray, unsigned int cells, int sz_flags, int cp_flags)
|
||||
{
|
||||
m_params[m_curparam].byref.cells = cells; /* Notice this contains the char count not cell count */
|
||||
m_params[m_curparam].byref.flags = cp_flags;
|
||||
m_params[m_curparam].byref.orig_addr = inarray;
|
||||
m_params[m_curparam].byref.sz_flags = sz_flags;
|
||||
m_params[m_curparam].isnull = false;
|
||||
}
|
||||
|
||||
int CForward::PushString(const char *string)
|
||||
{
|
||||
/* Push a reference to the NULL_STRING pubvar if NULL was passed. */
|
||||
if (!string)
|
||||
{
|
||||
return PushNullString();
|
||||
if (!string) {
|
||||
return SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
|
||||
if (m_curparam < m_numparams)
|
||||
{
|
||||
if (m_types[m_curparam] == Param_Any)
|
||||
{
|
||||
m_params[m_curparam].pushedas = Param_String;
|
||||
} else if (m_types[m_curparam] != Param_String) {
|
||||
return SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
} else {
|
||||
if (!m_varargs || m_curparam > SP_MAX_EXEC_PARAMS)
|
||||
{
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
}
|
||||
m_params[m_curparam].pushedas = Param_String;
|
||||
}
|
||||
|
||||
_Int_PushString((cell_t *)string, strlen(string)+1, SM_PARAM_STRING_COPY, 0);
|
||||
m_curparam++;
|
||||
|
||||
default_args_.PushString(string);
|
||||
if (default_args_.error)
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int CForward::PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags)
|
||||
{
|
||||
if (m_curparam < m_numparams)
|
||||
{
|
||||
if (m_types[m_curparam] == Param_Any)
|
||||
{
|
||||
m_params[m_curparam].pushedas = Param_String;
|
||||
} else if (m_types[m_curparam] != Param_String) {
|
||||
return SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
} else {
|
||||
if (!m_varargs || m_curparam > SP_MAX_EXEC_PARAMS)
|
||||
{
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
}
|
||||
m_params[m_curparam].pushedas = Param_String;
|
||||
}
|
||||
|
||||
_Int_PushString((cell_t *)buffer, length, sz_flags, cp_flags);
|
||||
m_curparam++;
|
||||
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int CForward::PushNullString()
|
||||
{
|
||||
if (m_curparam < m_numparams)
|
||||
{
|
||||
if (m_types[m_curparam] == Param_Any)
|
||||
{
|
||||
m_params[m_curparam].pushedas = Param_String;
|
||||
} else if (m_types[m_curparam] != Param_String) {
|
||||
return SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
} else {
|
||||
if (!m_varargs || m_numparams > SP_MAX_EXEC_PARAMS)
|
||||
{
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
}
|
||||
m_params[m_curparam].pushedas = Param_String;
|
||||
}
|
||||
|
||||
m_params[m_curparam++].isnull = true;
|
||||
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int CForward::PushNullVector()
|
||||
{
|
||||
if (m_curparam < m_numparams)
|
||||
{
|
||||
if (m_types[m_curparam] == Param_Any)
|
||||
{
|
||||
m_params[m_curparam].pushedas = Param_Array;
|
||||
} else if (m_types[m_curparam] != Param_Array) {
|
||||
return SetError(SP_ERROR_PARAM);
|
||||
}
|
||||
} else {
|
||||
if (!m_varargs || m_numparams > SP_MAX_EXEC_PARAMS)
|
||||
{
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
}
|
||||
m_params[m_curparam].pushedas = Param_Array;
|
||||
}
|
||||
|
||||
m_params[m_curparam++].isnull = true;
|
||||
|
||||
default_args_.PushString(buffer, length, sz_flags | cp_flags);
|
||||
if (default_args_.error)
|
||||
return SetError(SP_ERROR_PARAMS_MAX);
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
void CForward::Cancel()
|
||||
{
|
||||
if (!m_curparam)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_curparam = 0;
|
||||
default_args_.Reset();
|
||||
m_errstate = SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
@@ -726,8 +516,8 @@ bool CForward::RemoveFunction(IPluginFunction *func)
|
||||
}
|
||||
|
||||
/* Cancel a call, if any */
|
||||
if (found || m_curparam)
|
||||
func->Cancel();
|
||||
if (found || default_args_.argc)
|
||||
default_args_.Reset();
|
||||
|
||||
return found;
|
||||
}
|
||||
@@ -747,13 +537,13 @@ unsigned int CForward::RemoveFunctionsOfPlugin(IPlugin *plugin)
|
||||
|
||||
bool CForward::AddFunction(IPluginFunction *func)
|
||||
{
|
||||
if (m_curparam)
|
||||
if (default_args_.argc)
|
||||
return false;
|
||||
|
||||
if (func->IsRunnable())
|
||||
m_functions.append(func);
|
||||
m_functions.push_back(func);
|
||||
else
|
||||
m_paused.append(func);
|
||||
m_paused.push_back(func);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -780,7 +570,7 @@ const char *CForward::GetForwardName()
|
||||
|
||||
unsigned int CForward::GetFunctionCount()
|
||||
{
|
||||
return m_functions.length();
|
||||
return m_functions.size();
|
||||
}
|
||||
|
||||
ExecType CForward::GetExecType()
|
||||
|
||||
+24
-10
@@ -39,9 +39,18 @@ typedef ReentrantList<IPluginFunction *>::iterator FuncIter;
|
||||
/* :TODO: a global name max define for sourcepawn, should mirror compiler's sNAMEMAX */
|
||||
#define FORWARDS_NAME_MAX 64
|
||||
|
||||
// The argument positions that hold an Address, one bit per position.
|
||||
using AddressMask = uint32_t;
|
||||
static_assert(SP_MAX_EXEC_PARAMS <= sizeof(AddressMask) * 8, "AddressMask must have a bit for every parameter");
|
||||
|
||||
// Invokes a plugin function, passing the given Address arguments as one cell to plugins compiled before SourceMod 1.13,
|
||||
// and refusing to pass those plugins any other int64 argument.
|
||||
bool InvokePluginFunction(IPluginFunction *func, const sp::CallArgs& args, AddressMask addresses, cell_t *result);
|
||||
|
||||
class CForward : public IChangeableForward
|
||||
{
|
||||
public: //ICallable
|
||||
friend class CForwardManager;
|
||||
public: //IForward
|
||||
virtual int PushCell(cell_t cell);
|
||||
virtual int PushCellByRef(cell_t *cell, int flags);
|
||||
virtual int PushFloat(float number);
|
||||
@@ -49,12 +58,13 @@ public: //ICallable
|
||||
virtual int PushArray(cell_t *inarray, unsigned int cells, int flags);
|
||||
virtual int PushString(const char *string);
|
||||
virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags);
|
||||
virtual int PushInt64(int64_t value);
|
||||
virtual void Cancel();
|
||||
public: //IForward
|
||||
virtual const char *GetForwardName();
|
||||
virtual unsigned int GetFunctionCount();
|
||||
virtual ExecType GetExecType();
|
||||
virtual int Execute(cell_t *result, IForwardFilter *filter);
|
||||
virtual int Execute(const sp::CallArgs& args, cell_t *result = nullptr, IForwardFilter *filter = nullptr);
|
||||
public: //IChangeableForward
|
||||
virtual bool RemoveFunction(IPluginFunction *func);
|
||||
virtual unsigned int RemoveFunctionsOfPlugin(IPlugin *plugin);
|
||||
@@ -72,31 +82,35 @@ private:
|
||||
CForward(ExecType et, const char *name,
|
||||
const ParamType *types, unsigned num_params);
|
||||
|
||||
int PushNullString();
|
||||
int PushNullVector();
|
||||
int _ExecutePushRef(IPluginFunction *func, ParamType type, FwdParamInfo *param);
|
||||
void _Int_PushArray(cell_t *inarray, unsigned int cells, int flags);
|
||||
void _Int_PushString(cell_t *inarray, unsigned int cells, int sz_flags, int cp_flags);
|
||||
inline int SetError(int err)
|
||||
{
|
||||
m_errstate = err;
|
||||
return err;
|
||||
}
|
||||
bool ProcessArguments(const sp::CallArgs& args);
|
||||
|
||||
protected:
|
||||
mutable ReentrantList<IPluginFunction *> m_functions;
|
||||
mutable ReentrantList<IPluginFunction *> m_paused;
|
||||
|
||||
/* Type and name information */
|
||||
FwdParamInfo m_params[SP_MAX_EXEC_PARAMS];
|
||||
sp::CallArgs default_args_;
|
||||
ParamType m_types[SP_MAX_EXEC_PARAMS];
|
||||
AddressMask m_addresses;
|
||||
char m_name[FORWARDS_NAME_MAX+1];
|
||||
unsigned int m_numparams;
|
||||
unsigned int m_varargs;
|
||||
ExecType m_ExecType;
|
||||
|
||||
/* State information */
|
||||
unsigned int m_curparam;
|
||||
int m_errstate;
|
||||
|
||||
/* Reentrancy protection: tracks how many nested Execute() calls are in
|
||||
* progress, and whether the forward was released while still executing
|
||||
* (e.g. a plugin freeing its own private forward handle from within one
|
||||
* of its own callbacks). Actual destruction is deferred until the
|
||||
* outermost Execute() call returns. */
|
||||
unsigned int m_ExecDepth;
|
||||
bool m_deleted;
|
||||
};
|
||||
|
||||
class CForwardManager :
|
||||
|
||||
@@ -36,7 +36,7 @@ SafeFrameIterator::SafeFrameIterator(IFrameIterator *it)
|
||||
while (!it->Done())
|
||||
{
|
||||
FrameInfo info = FrameInfo(it);
|
||||
frames.append(info);
|
||||
frames.push_back(info);
|
||||
it->Next();
|
||||
}
|
||||
|
||||
@@ -46,18 +46,13 @@ SafeFrameIterator::SafeFrameIterator(IFrameIterator *it)
|
||||
|
||||
bool SafeFrameIterator::Done() const
|
||||
{
|
||||
return current == frames.length();
|
||||
return current >= frames.size();
|
||||
}
|
||||
|
||||
bool SafeFrameIterator::Next()
|
||||
{
|
||||
if (!this->Done())
|
||||
{
|
||||
current++;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
current++;
|
||||
return !this->Done();
|
||||
}
|
||||
|
||||
void SafeFrameIterator::Reset()
|
||||
@@ -82,7 +77,7 @@ const char *SafeFrameIterator::FunctionName() const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return frames[current].FunctionName.chars();
|
||||
return frames[current].FunctionName.c_str();
|
||||
}
|
||||
|
||||
const char *SafeFrameIterator::FilePath() const
|
||||
@@ -92,5 +87,5 @@ const char *SafeFrameIterator::FilePath() const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return frames[current].FilePath.chars();
|
||||
return frames[current].FilePath.c_str();
|
||||
}
|
||||
|
||||
@@ -48,16 +48,18 @@ public:
|
||||
*/
|
||||
struct FrameInfo
|
||||
{
|
||||
ke::AString FunctionName;
|
||||
ke::AString FilePath;
|
||||
std::string FunctionName;
|
||||
std::string FilePath;
|
||||
unsigned LineNumber;
|
||||
|
||||
FrameInfo(IFrameIterator *it)
|
||||
{
|
||||
LineNumber = it->LineNumber();
|
||||
|
||||
FunctionName = it->FunctionName();
|
||||
FilePath = it->FilePath();
|
||||
if (it->FunctionName())
|
||||
FunctionName = it->FunctionName();
|
||||
if (it->FilePath())
|
||||
FilePath = it->FilePath();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,5 +75,5 @@ public:
|
||||
|
||||
private:
|
||||
size_t current;
|
||||
ke::Vector<FrameInfo> frames;
|
||||
};
|
||||
std::vector<FrameInfo> frames;
|
||||
};
|
||||
|
||||
+251
-102
@@ -30,8 +30,9 @@
|
||||
#include "common_logic.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sh_list.h>
|
||||
#include <sh_string.h>
|
||||
#include <sstream>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include "GameConfigs.h"
|
||||
#include "stringutil.h"
|
||||
#include <IGameHelpers.h>
|
||||
@@ -46,13 +47,12 @@
|
||||
#include <am-string.h>
|
||||
#include <bridge/include/ILogger.h>
|
||||
#include <bridge/include/CoreProvider.h>
|
||||
#include <bridge/include/IFileSystemBridge.h>
|
||||
|
||||
#if defined PLATFORM_POSIX
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
GameConfigManager g_GameConfigs;
|
||||
IGameConfig *g_pGameConf = NULL;
|
||||
static char g_Game[256];
|
||||
@@ -66,27 +66,31 @@ static const char *g_pParseEngine = NULL;
|
||||
#define PSTATE_GAMEDEFS_OFFSETS 3
|
||||
#define PSTATE_GAMEDEFS_OFFSETS_OFFSET 4
|
||||
#define PSTATE_GAMEDEFS_KEYS 5
|
||||
#define PSTATE_GAMEDEFS_SUPPORTED 6
|
||||
#define PSTATE_GAMEDEFS_SIGNATURES 7
|
||||
#define PSTATE_GAMEDEFS_SIGNATURES_SIG 8
|
||||
#define PSTATE_GAMEDEFS_CRC 9
|
||||
#define PSTATE_GAMEDEFS_CRC_BINARY 10
|
||||
#define PSTATE_GAMEDEFS_CUSTOM 11
|
||||
#define PSTATE_GAMEDEFS_ADDRESSES 12
|
||||
#define PSTATE_GAMEDEFS_ADDRESSES_ADDRESS 13
|
||||
#define PSTATE_GAMEDEFS_ADDRESSES_ADDRESS_READ 14
|
||||
#define PSTATE_GAMEDEFS_KEYS_PLATFORM 6
|
||||
#define PSTATE_GAMEDEFS_SUPPORTED 7
|
||||
#define PSTATE_GAMEDEFS_SIGNATURES 8
|
||||
#define PSTATE_GAMEDEFS_SIGNATURES_SIG 9
|
||||
#define PSTATE_GAMEDEFS_CRC 10
|
||||
#define PSTATE_GAMEDEFS_CRC_BINARY 11
|
||||
#define PSTATE_GAMEDEFS_CUSTOM 12
|
||||
#define PSTATE_GAMEDEFS_ADDRESSES 13
|
||||
#define PSTATE_GAMEDEFS_ADDRESSES_ADDRESS 14
|
||||
#define PSTATE_GAMEDEFS_ADDRESSES_ADDRESS_READ 15
|
||||
|
||||
#if defined KE_ARCH_X86
|
||||
#define PLATFORM_ARCH_SUFFIX ""
|
||||
#elif defined KE_ARCH_X64
|
||||
#define PLATFORM_ARCH_SUFFIX "64"
|
||||
#endif
|
||||
|
||||
#if defined PLATFORM_WINDOWS
|
||||
#define PLATFORM_NAME "windows"
|
||||
#define PLATFORM_SERVER_BINARY "server.dll"
|
||||
#define PLATFORM_NAME "windows" PLATFORM_ARCH_SUFFIX
|
||||
#elif defined PLATFORM_LINUX
|
||||
#define PLATFORM_NAME "linux"
|
||||
#define PLATFORM_COMPAT_ALT "mac" /* Alternate platform name if game data is missing for primary one */
|
||||
#define PLATFORM_SERVER_BINARY "server_i486.so"
|
||||
#define PLATFORM_NAME "linux" PLATFORM_ARCH_SUFFIX
|
||||
#define PLATFORM_COMPAT_ALT "mac" PLATFORM_ARCH_SUFFIX /* Alternate platform name if game data is missing for primary one */
|
||||
#elif defined PLATFORM_APPLE
|
||||
#define PLATFORM_NAME "mac"
|
||||
#define PLATFORM_COMPAT_ALT "linux"
|
||||
#define PLATFORM_SERVER_BINARY "server.dylib"
|
||||
#define PLATFORM_NAME "mac" PLATFORM_ARCH_SUFFIX
|
||||
#define PLATFORM_COMPAT_ALT "linux" PLATFORM_ARCH_SUFFIX
|
||||
#endif
|
||||
|
||||
struct TempSigInfo
|
||||
@@ -99,8 +103,6 @@ struct TempSigInfo
|
||||
char sig[1024];
|
||||
char library[64];
|
||||
} s_TempSig;
|
||||
unsigned int s_ServerBinCRC;
|
||||
bool s_ServerBinCRC_Ok = false;
|
||||
|
||||
static bool DoesGameMatch(const char *value)
|
||||
{
|
||||
@@ -146,6 +148,23 @@ static inline bool IsPlatformCompatible(const char *platform, bool *hadPrimaryMa
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline time_t GetFileModTime(const char *path)
|
||||
{
|
||||
char filepath[PLATFORM_MAX_PATH];
|
||||
g_pSM->BuildPath(Path_SM, filepath, sizeof(filepath), "gamedata/%s.txt", path);
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
struct _stat64 s;
|
||||
if (_stat64(filepath, &s) != 0)
|
||||
#elif defined PLATFORM_POSIX
|
||||
struct stat s;
|
||||
if (stat(filepath, &s) != 0)
|
||||
#endif
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return s.st_mtime;
|
||||
}
|
||||
|
||||
CGameConfig::CGameConfig(const char *file, const char *engine)
|
||||
{
|
||||
strncopy(m_File, file, sizeof(m_File));
|
||||
@@ -153,6 +172,8 @@ CGameConfig::CGameConfig(const char *file, const char *engine)
|
||||
m_CustomLevel = 0;
|
||||
m_CustomHandler = NULL;
|
||||
|
||||
m_ModTime = GetFileModTime(file);
|
||||
|
||||
if (!engine)
|
||||
m_pEngine = bridge->GetSourceEngineName();
|
||||
else
|
||||
@@ -199,7 +220,7 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
||||
{
|
||||
bShouldBeReadingDefault = true;
|
||||
m_ParseState = PSTATE_GAMEDEFS;
|
||||
strncopy(m_Game, name, sizeof(m_Game));
|
||||
m_Game = name;
|
||||
} else {
|
||||
m_IgnoreLevel++;
|
||||
}
|
||||
@@ -215,7 +236,7 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
||||
{
|
||||
m_ParseState = PSTATE_GAMEDEFS_KEYS;
|
||||
}
|
||||
else if ((strcmp(name, "#supported") == 0) && (strcmp(m_Game, "#default") == 0))
|
||||
else if ((strcmp(name, "#supported") == 0) && (m_Game == "#default"))
|
||||
{
|
||||
m_ParseState = PSTATE_GAMEDEFS_SUPPORTED;
|
||||
/* Ignore this section unless we get a game. */
|
||||
@@ -252,18 +273,25 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PSTATE_GAMEDEFS_KEYS:
|
||||
{
|
||||
m_Key = name;
|
||||
m_ParseState = PSTATE_GAMEDEFS_KEYS_PLATFORM;
|
||||
matched_platform = false;
|
||||
break;
|
||||
}
|
||||
case PSTATE_GAMEDEFS_OFFSETS:
|
||||
{
|
||||
m_Prop[0] = '\0';
|
||||
m_Class[0] = '\0';
|
||||
strncopy(m_offset, name, sizeof(m_offset));
|
||||
m_Prop.clear();
|
||||
m_Class.clear();
|
||||
m_offset = name;
|
||||
m_ParseState = PSTATE_GAMEDEFS_OFFSETS_OFFSET;
|
||||
matched_platform = false;
|
||||
break;
|
||||
}
|
||||
case PSTATE_GAMEDEFS_SIGNATURES:
|
||||
{
|
||||
strncopy(m_offset, name, sizeof(m_offset));
|
||||
m_offset = name;
|
||||
s_TempSig.Reset();
|
||||
m_ParseState = PSTATE_GAMEDEFS_SIGNATURES_SIG;
|
||||
matched_platform = false;
|
||||
@@ -273,39 +301,25 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
||||
{
|
||||
char error[255];
|
||||
error[0] = '\0';
|
||||
if (strcmp(name, "server") != 0)
|
||||
GameBinaryInfo binInfo;
|
||||
if (!g_GameConfigs.TryGetGameBinaryInfo(name, &binInfo))
|
||||
{
|
||||
ke::SafeSprintf(error, sizeof(error), "Unrecognized library \"%s\"", name);
|
||||
}
|
||||
else if (!s_ServerBinCRC_Ok)
|
||||
else if (!binInfo.m_crcOK)
|
||||
{
|
||||
FILE *fp;
|
||||
char path[PLATFORM_MAX_PATH];
|
||||
|
||||
g_pSM->BuildPath(Path_Game, path, sizeof(path), "bin/" PLATFORM_SERVER_BINARY);
|
||||
if ((fp = fopen(path, "rb")) == NULL)
|
||||
{
|
||||
ke::SafeSprintf(error, sizeof(error), "Could not open binary: %s", path);
|
||||
} else {
|
||||
size_t size;
|
||||
void *buffer;
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
buffer = malloc(size);
|
||||
fread(buffer, size, 1, fp);
|
||||
s_ServerBinCRC = UTIL_CRC32(buffer, size);
|
||||
free(buffer);
|
||||
s_ServerBinCRC_Ok = true;
|
||||
fclose(fp);
|
||||
}
|
||||
ke::SafeSprintf(error, sizeof(error), "Could not get CRC for binary: %s", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
bCurrentBinCRC_Ok = binInfo.m_crcOK;
|
||||
bCurrentBinCRC = binInfo.m_crc;
|
||||
}
|
||||
|
||||
if (error[0] != '\0')
|
||||
{
|
||||
m_IgnoreLevel = 1;
|
||||
logger->LogError("[SM] Error while parsing CRC section for \"%s\" (%s):", m_Game, m_CurFile);
|
||||
logger->LogError("[SM] Error while parsing CRC section for \"%s\" (%s):", m_Game.c_str(), m_CurFile);
|
||||
logger->LogError("[SM] %s", error);
|
||||
} else {
|
||||
m_ParseState = PSTATE_GAMEDEFS_CRC_BINARY;
|
||||
@@ -320,12 +334,12 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
||||
}
|
||||
case PSTATE_GAMEDEFS_ADDRESSES:
|
||||
{
|
||||
m_Address[0] = '\0';
|
||||
m_AddressSignature[0] = '\0';
|
||||
m_Address.clear();
|
||||
m_AddressSignature.clear();
|
||||
m_AddressReadCount = 0;
|
||||
m_AddressLastIsOffset = false;
|
||||
|
||||
strncopy(m_Address, name, sizeof(m_Address));
|
||||
m_Address = name;
|
||||
m_ParseState = PSTATE_GAMEDEFS_ADDRESSES_ADDRESS;
|
||||
|
||||
break;
|
||||
@@ -338,9 +352,10 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp(name, "linux") != 0 && strcmp(name, "windows") != 0 && strcmp(name, "mac") != 0)
|
||||
if (strcmp(name, "linux") != 0 && strcmp(name, "windows") != 0 && strcmp(name, "mac") != 0 &&
|
||||
strcmp(name, "linux64") != 0 && strcmp(name, "windows64") != 0 && strcmp(name, "mac64") != 0)
|
||||
{
|
||||
logger->LogError("[SM] Error while parsing Address section for \"%s\" (%s):", m_Address, m_CurFile);
|
||||
logger->LogError("[SM] Error while parsing Address section for \"%s\" (%s):", m_Address.c_str(), m_CurFile);
|
||||
logger->LogError("[SM] Unrecognized platform \"%s\"", name);
|
||||
}
|
||||
m_IgnoreLevel = 1;
|
||||
@@ -349,7 +364,7 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
|
||||
}
|
||||
/* No sub-sections allowed:
|
||||
case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
|
||||
case PSTATE_GAMEDEFS_KEYS:
|
||||
case PSTATE_GAMEDEFS_KEYS_PLATFORM:
|
||||
case PSTATE_GAMEDEFS_SUPPORTED:
|
||||
case PSTATE_GAMEDEFS_SIGNATURES_SIG:
|
||||
case PSTATE_GAMEDEFS_CRC_BINARY:
|
||||
@@ -377,15 +392,22 @@ SMCResult CGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key
|
||||
{
|
||||
if (strcmp(key, "class") == 0)
|
||||
{
|
||||
strncopy(m_Class, value, sizeof(m_Class));
|
||||
m_Class = value;
|
||||
} else if (strcmp(key, "prop") == 0) {
|
||||
strncopy(m_Prop, value, sizeof(m_Prop));
|
||||
m_Prop = value;
|
||||
} else if (IsPlatformCompatible(key, &matched_platform)) {
|
||||
m_Offsets.replace(m_offset, atoi(value));
|
||||
m_Offsets.replace(m_offset.c_str(), static_cast<int>(strtol(value, NULL, 0)));
|
||||
}
|
||||
} else if (m_ParseState == PSTATE_GAMEDEFS_KEYS) {
|
||||
ke::AString vstr(value);
|
||||
m_Keys.replace(key, ke::Move(vstr));
|
||||
std::string vstr(value);
|
||||
m_Keys.replace(key, std::move(vstr));
|
||||
}
|
||||
else if (m_ParseState == PSTATE_GAMEDEFS_KEYS_PLATFORM) {
|
||||
if (IsPlatformCompatible(key, &matched_platform))
|
||||
{
|
||||
std::string vstr(value);
|
||||
m_Keys.replace(m_Key.c_str(), std::move(vstr));
|
||||
}
|
||||
} else if (m_ParseState == PSTATE_GAMEDEFS_SUPPORTED) {
|
||||
if (strcmp(key, "game") == 0)
|
||||
{
|
||||
@@ -420,12 +442,12 @@ SMCResult CGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key
|
||||
}
|
||||
} else if (m_ParseState == PSTATE_GAMEDEFS_CRC_BINARY) {
|
||||
if (DoesPlatformMatch(key)
|
||||
&& s_ServerBinCRC_Ok
|
||||
&& bCurrentBinCRC_Ok
|
||||
&& !bShouldBeReadingDefault)
|
||||
{
|
||||
unsigned int crc = 0;
|
||||
sscanf(value, "%08X", &crc);
|
||||
if (s_ServerBinCRC == crc)
|
||||
if (bCurrentBinCRC == crc)
|
||||
{
|
||||
bShouldBeReadingDefault = true;
|
||||
}
|
||||
@@ -435,7 +457,7 @@ SMCResult CGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key
|
||||
int limit = sizeof(m_AddressRead)/sizeof(m_AddressRead[0]);
|
||||
if (m_AddressLastIsOffset)
|
||||
{
|
||||
logger->LogError("[SM] Error parsing Address \"%s\", 'offset' entry must be the last entry (gameconf \"%s\")", m_Address, m_CurFile);
|
||||
logger->LogError("[SM] Error parsing Address \"%s\", 'offset' entry must be the last entry (gameconf \"%s\")", m_Address.c_str(), m_CurFile);
|
||||
}
|
||||
else if (m_AddressReadCount < limit)
|
||||
{
|
||||
@@ -443,15 +465,15 @@ SMCResult CGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key
|
||||
{
|
||||
m_AddressLastIsOffset = true;
|
||||
}
|
||||
m_AddressRead[m_AddressReadCount] = atoi(value);
|
||||
m_AddressRead[m_AddressReadCount] = static_cast<int>(strtol(value, NULL, 0));
|
||||
m_AddressReadCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger->LogError("[SM] Error parsing Address \"%s\", does not support more than %d read offsets (gameconf \"%s\")", m_Address, limit, m_CurFile);
|
||||
logger->LogError("[SM] Error parsing Address \"%s\", does not support more than %d read offsets (gameconf \"%s\")", m_Address.c_str(), limit, m_CurFile);
|
||||
}
|
||||
} else if (strcmp(key, "signature") == 0) {
|
||||
strncopy(m_AddressSignature, value, sizeof(m_AddressSignature));
|
||||
m_AddressSignature = value;
|
||||
}
|
||||
} else if (m_ParseState == PSTATE_GAMEDEFS_CUSTOM) {
|
||||
return m_CustomHandler->ReadSMC_KeyValue(states, key, value);
|
||||
@@ -499,28 +521,32 @@ SMCResult CGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
|
||||
m_ParseState = PSTATE_GAMEDEFS;
|
||||
break;
|
||||
}
|
||||
case PSTATE_GAMEDEFS_KEYS_PLATFORM:
|
||||
{
|
||||
m_ParseState = PSTATE_GAMEDEFS_KEYS;
|
||||
break;
|
||||
}
|
||||
case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
|
||||
{
|
||||
/* Parse the offset... */
|
||||
if (m_Class[0] != '\0'
|
||||
&& m_Prop[0] != '\0')
|
||||
if (!m_Class.empty() && !m_Prop.empty())
|
||||
{
|
||||
SendProp *pProp = gamehelpers->FindInSendTable(m_Class, m_Prop);
|
||||
SendProp *pProp = gamehelpers->FindInSendTable(m_Class.c_str(), m_Prop.c_str());
|
||||
if (pProp)
|
||||
{
|
||||
int val = gamehelpers->GetSendPropOffset(pProp);
|
||||
m_Offsets.replace(m_offset, val);
|
||||
m_Props.replace(m_offset, pProp);
|
||||
m_Offsets.replace(m_offset.c_str(), val);
|
||||
m_Props.replace(m_offset.c_str(), pProp);
|
||||
} else {
|
||||
/* Check if it's a non-default game and no offsets exist */
|
||||
if (((strcmp(m_Game, "*") != 0) && strcmp(m_Game, "#default") != 0)
|
||||
&& (!m_Offsets.retrieve(m_offset)))
|
||||
if ((m_Game != "*" && m_Game != "#default")
|
||||
&& (!m_Offsets.retrieve(m_offset.c_str())))
|
||||
{
|
||||
logger->LogError("[SM] Unable to find property %s.%s (file \"%s\") (mod \"%s\")",
|
||||
m_Class,
|
||||
m_Prop,
|
||||
m_Class.c_str(),
|
||||
m_Prop.c_str(),
|
||||
m_CurFile,
|
||||
m_Game);
|
||||
m_Game.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -558,14 +584,12 @@ SMCResult CGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
|
||||
strncopy(s_TempSig.library, "server", sizeof(s_TempSig.library));
|
||||
}
|
||||
void *addrInBase = NULL;
|
||||
if (strcmp(s_TempSig.library, "server") == 0)
|
||||
GameBinaryInfo binInfo;
|
||||
if (g_GameConfigs.TryGetGameBinaryInfo(s_TempSig.library, &binInfo))
|
||||
{
|
||||
addrInBase = bridge->serverFactory;
|
||||
} else if (strcmp(s_TempSig.library, "engine") == 0) {
|
||||
addrInBase = bridge->engineFactory;
|
||||
} else if (strcmp(s_TempSig.library, "matchmaking_ds") == 0) {
|
||||
addrInBase = bridge->matchmakingDSFactory;
|
||||
addrInBase = binInfo.m_pAddr;
|
||||
}
|
||||
|
||||
void *final_addr = NULL;
|
||||
if (addrInBase == NULL)
|
||||
{
|
||||
@@ -628,7 +652,7 @@ SMCResult CGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
|
||||
}
|
||||
}
|
||||
|
||||
m_Sigs.replace(m_offset, final_addr);
|
||||
m_Sigs.replace(m_offset.c_str(), final_addr);
|
||||
}
|
||||
|
||||
m_ParseState = PSTATE_GAMEDEFS_SIGNATURES;
|
||||
@@ -644,10 +668,10 @@ SMCResult CGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
|
||||
{
|
||||
m_ParseState = PSTATE_GAMEDEFS_ADDRESSES;
|
||||
|
||||
if (m_Address[0] != '\0' && m_AddressSignature[0] != '\0')
|
||||
if (!m_Address.empty() && !m_AddressSignature.empty())
|
||||
{
|
||||
AddressConf addrConf(m_AddressSignature, sizeof(m_AddressSignature), m_AddressReadCount, m_AddressRead, m_AddressLastIsOffset);
|
||||
m_Addresses.replace(m_Address, addrConf);
|
||||
AddressConf addrConf(std::move(m_AddressSignature), m_AddressReadCount, m_AddressRead, m_AddressLastIsOffset);
|
||||
m_Addresses.replace(m_Address.c_str(), addrConf);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -765,7 +789,10 @@ public:
|
||||
(!had_game && matched_engine) ||
|
||||
(matched_engine && matched_game))
|
||||
{
|
||||
fileList->push_back(cur_file);
|
||||
if (std::find(fileList->begin(), fileList->end(), cur_file) == fileList->end())
|
||||
{
|
||||
fileList->push_back(cur_file);
|
||||
}
|
||||
}
|
||||
state = MSTATE_MAIN;
|
||||
}
|
||||
@@ -777,7 +804,7 @@ public:
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
public:
|
||||
List<String> *fileList;
|
||||
std::list<std::string> *fileList;
|
||||
unsigned int state;
|
||||
unsigned int ignoreLevel;
|
||||
char cur_file[PLATFORM_MAX_PATH];
|
||||
@@ -828,7 +855,7 @@ bool CGameConfig::Reparse(char *error, size_t maxlength)
|
||||
/* Otherwise, it's time to parse the master. */
|
||||
SMCError err;
|
||||
SMCStates state = {0, 0};
|
||||
List<String> fileList;
|
||||
std::list<std::string> fileList;
|
||||
master_reader.fileList = &fileList;
|
||||
const char *pEngine[2] = { m_pBaseEngine, m_pEngine };
|
||||
|
||||
@@ -856,8 +883,7 @@ bool CGameConfig::Reparse(char *error, size_t maxlength)
|
||||
}
|
||||
|
||||
/* Go through each file we found and parse it. */
|
||||
List<String>::iterator iter;
|
||||
for (iter = fileList.begin(); iter != fileList.end(); iter++)
|
||||
for (auto iter = fileList.begin(); iter != fileList.end(); iter++)
|
||||
{
|
||||
ke::SafeSprintf(path, sizeof(path), "%s/%s", m_File, (*iter).c_str());
|
||||
if (!EnterFile(path, error, maxlength))
|
||||
@@ -974,10 +1000,10 @@ bool CGameConfig::GetOffset(const char *key, int *value)
|
||||
|
||||
const char *CGameConfig::GetKeyValue(const char *key)
|
||||
{
|
||||
StringHashMap<ke::AString>::Result r = m_Keys.find(key);
|
||||
StringHashMap<std::string>::Result r = m_Keys.find(key);
|
||||
if (!r.found())
|
||||
return NULL;
|
||||
return r->value.chars();
|
||||
return r->value.c_str();
|
||||
}
|
||||
|
||||
//memory addresses below 0x10000 are automatically considered invalid for dereferencing
|
||||
@@ -995,7 +1021,7 @@ bool CGameConfig::GetAddress(const char *key, void **retaddr)
|
||||
AddressConf &addrConf = r->value;
|
||||
|
||||
void *addr;
|
||||
if (!GetMemSig(addrConf.signatureName, &addr))
|
||||
if (!GetMemSig(addrConf.signatureName.c_str(), &addr))
|
||||
{
|
||||
*retaddr = NULL;
|
||||
return false;
|
||||
@@ -1028,11 +1054,11 @@ static inline unsigned minOf(unsigned a, unsigned b)
|
||||
return a <= b ? a : b;
|
||||
}
|
||||
|
||||
CGameConfig::AddressConf::AddressConf(char *sigName, unsigned sigLength, unsigned readCount, int *read, bool lastIsOffset)
|
||||
CGameConfig::AddressConf::AddressConf(std::string&& sigName, unsigned readCount, int *read, bool lastIsOffset)
|
||||
{
|
||||
unsigned readLimit = minOf(readCount, sizeof(this->read) / sizeof(this->read[0]));
|
||||
|
||||
strncopy(signatureName, sigName, sizeof(signatureName) / sizeof(signatureName[0]));
|
||||
this->signatureName = std::move(sigName);
|
||||
this->readCount = readLimit;
|
||||
memcpy(&this->read[0], read, sizeof(this->read[0])*readLimit);
|
||||
|
||||
@@ -1054,6 +1080,47 @@ bool CGameConfig::GetMemSig(const char *key, void **addr)
|
||||
return m_Sigs.retrieve(key, addr);
|
||||
}
|
||||
|
||||
void GameBinPathManager::Init()
|
||||
{
|
||||
char search_path[PLATFORM_MAX_PATH * 8];
|
||||
bridge->filesystem->GetSearchPath("GAMEBIN", false, search_path, sizeof(search_path));
|
||||
|
||||
char addons_folder[12];
|
||||
ke::SafeSprintf(addons_folder, sizeof(addons_folder), "%caddons%c", PLATFORM_SEP_CHAR, PLATFORM_SEP_CHAR);
|
||||
|
||||
std::istringstream iss(search_path);
|
||||
for (std::string path; std::getline(iss, path, ';');)
|
||||
{
|
||||
if (path.length() > 0)
|
||||
{
|
||||
const char* arch_subdir = bridge->filesystem->GetGameBinArchSubdirectory();
|
||||
std::string full_path = path + arch_subdir;
|
||||
if (full_path.find(addons_folder) == std::string::npos
|
||||
&& m_lookup.find(full_path) == m_lookup.cend()
|
||||
)
|
||||
{
|
||||
m_lookup.insert(full_path);
|
||||
m_ordered.push_back(full_path);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iss.clear();
|
||||
|
||||
bridge->filesystem->GetSearchPath("EXECUTABLE_PATH", false, search_path, sizeof(search_path));
|
||||
iss.str(search_path);
|
||||
|
||||
for (std::string path; std::getline(iss, path, ';');)
|
||||
{
|
||||
if (m_lookup.find(path) == m_lookup.cend())
|
||||
{
|
||||
m_lookup.insert(path);
|
||||
m_ordered.push_back(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameConfigManager::GameConfigManager()
|
||||
{
|
||||
}
|
||||
@@ -1064,6 +1131,8 @@ GameConfigManager::~GameConfigManager()
|
||||
|
||||
void GameConfigManager::OnSourceModStartup(bool late)
|
||||
{
|
||||
m_gameBinPathManager.Init();
|
||||
|
||||
LoadGameConfigFile("core.games", &g_pGameConf, NULL, 0);
|
||||
|
||||
strncopy(g_Game, g_pSM->GetGameFolderName(), sizeof(g_Game));
|
||||
@@ -1105,9 +1174,17 @@ bool GameConfigManager::LoadGameConfigFile(const char *file, IGameConfig **_pCon
|
||||
|
||||
if (m_Lookup.retrieve(file, &pConfig))
|
||||
{
|
||||
bool ret = true;
|
||||
time_t modtime = GetFileModTime(file);
|
||||
if (pConfig->m_ModTime != modtime || pConfig->m_ModTime == 0)
|
||||
{
|
||||
pConfig->m_ModTime = modtime;
|
||||
ret = pConfig->Reparse(error, maxlength);
|
||||
}
|
||||
|
||||
pConfig->AddRef();
|
||||
*_pConfig = pConfig;
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
pConfig = new CGameConfig(file);
|
||||
@@ -1178,3 +1255,75 @@ void GameConfigManager::RemoveCachedConfig(CGameConfig *config)
|
||||
{
|
||||
m_Lookup.remove(config->m_File);
|
||||
}
|
||||
|
||||
void GameConfigManager::CacheGameBinaryInfo(const char* pszName)
|
||||
{
|
||||
GameBinaryInfo info;
|
||||
|
||||
char name[64];
|
||||
bridge->FormatSourceBinaryName(pszName, name, sizeof(name));
|
||||
|
||||
char binary_path[PLATFORM_MAX_PATH];
|
||||
for (auto it = m_gameBinPathManager.Paths().begin(); it != m_gameBinPathManager.Paths().end(); ++it)
|
||||
{
|
||||
ke::SafeSprintf(binary_path, sizeof(binary_path), "%s%s%s", it->c_str(), it->back() == PLATFORM_SEP_CHAR ? "" : PLATFORM_SEP, name);
|
||||
#if defined PLATFORM_WINDOWS
|
||||
HMODULE hModule = LoadLibraryA(binary_path);
|
||||
if (hModule)
|
||||
{
|
||||
info.m_pAddr = GetProcAddress(hModule, "CreateInterface");
|
||||
FreeLibrary(hModule);
|
||||
}
|
||||
#else
|
||||
void *pHandle = dlopen(binary_path, RTLD_NOW);
|
||||
if (pHandle)
|
||||
{
|
||||
info.m_pAddr = dlsym(pHandle, "CreateInterface");
|
||||
dlclose(pHandle);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (info.m_pAddr)
|
||||
break;
|
||||
}
|
||||
|
||||
// Don't bother trying to get CRC if we couldn't find the bin loaded
|
||||
if (info.m_pAddr)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
if ((fp = fopen(binary_path, "rb")) == 0)
|
||||
{
|
||||
info.m_crc = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t size;
|
||||
void* buffer;
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
buffer = malloc(size);
|
||||
fread(buffer, size, 1, fp);
|
||||
info.m_crc = UTIL_CRC32(buffer, size);
|
||||
free(buffer);
|
||||
info.m_crcOK = true;
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
// But insert regardless, to cache the first lookup (even as failed)
|
||||
m_gameBinInfos.insert(pszName, info);
|
||||
}
|
||||
|
||||
bool GameConfigManager::TryGetGameBinaryInfo(const char* pszName, GameBinaryInfo* pDest)
|
||||
{
|
||||
if (m_gameBinInfos.retrieve(pszName, pDest))
|
||||
return pDest->m_pAddr != nullptr;
|
||||
|
||||
CacheGameBinaryInfo(pszName);
|
||||
|
||||
return m_gameBinInfos.retrieve(pszName, pDest);
|
||||
}
|
||||
|
||||
+48
-10
@@ -36,8 +36,9 @@
|
||||
#include <IGameConfigs.h>
|
||||
#include <ITextParsers.h>
|
||||
#include <am-refcounting.h>
|
||||
#include <sm_stringhashmap.h>
|
||||
#include <sm_hashmap.h>
|
||||
#include <sm_namehashset.h>
|
||||
#include <unordered_set>
|
||||
|
||||
using namespace SourceMod;
|
||||
|
||||
@@ -72,20 +73,27 @@ public: //NameHashSet
|
||||
{
|
||||
return strcmp(key, value->m_File) == 0;
|
||||
}
|
||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
||||
{
|
||||
return key.hash();
|
||||
}
|
||||
private:
|
||||
char m_File[PLATFORM_MAX_PATH];
|
||||
char m_CurFile[PLATFORM_MAX_PATH];
|
||||
StringHashMap<int> m_Offsets;
|
||||
StringHashMap<SendProp *> m_Props;
|
||||
StringHashMap<ke::AString> m_Keys;
|
||||
StringHashMap<std::string> m_Keys;
|
||||
StringHashMap<void *> m_Sigs;
|
||||
/* Parse states */
|
||||
int m_ParseState;
|
||||
unsigned int m_IgnoreLevel;
|
||||
char m_Class[64];
|
||||
char m_Prop[64];
|
||||
char m_offset[64];
|
||||
char m_Game[256];
|
||||
std::string m_Class;
|
||||
std::string m_Prop;
|
||||
std::string m_offset;
|
||||
std::string m_Game;
|
||||
std::string m_Key;
|
||||
unsigned int bCurrentBinCRC;
|
||||
bool bCurrentBinCRC_Ok = false;
|
||||
bool bShouldBeReadingDefault;
|
||||
bool had_game;
|
||||
bool matched_game;
|
||||
@@ -100,24 +108,49 @@ private:
|
||||
/* Support for reading Addresses */
|
||||
struct AddressConf
|
||||
{
|
||||
char signatureName[64];
|
||||
std::string signatureName;
|
||||
int readCount;
|
||||
int read[8];
|
||||
bool lastIsOffset;
|
||||
|
||||
AddressConf(char *sigName, unsigned sigLength, unsigned readCount, int *read, bool lastIsOffset);
|
||||
AddressConf(std::string&& sigName, unsigned readCount, int *read, bool lastIsOffset);
|
||||
|
||||
AddressConf() {}
|
||||
};
|
||||
|
||||
char m_Address[64];
|
||||
char m_AddressSignature[64];
|
||||
std::string m_Address;
|
||||
std::string m_AddressSignature;
|
||||
int m_AddressReadCount;
|
||||
int m_AddressRead[8];
|
||||
bool m_AddressLastIsOffset;
|
||||
StringHashMap<AddressConf> m_Addresses;
|
||||
const char *m_pEngine;
|
||||
const char *m_pBaseEngine;
|
||||
time_t m_ModTime;
|
||||
};
|
||||
|
||||
struct GameBinaryInfo
|
||||
{
|
||||
void *m_pAddr = nullptr;
|
||||
uint32_t m_crc = 0;
|
||||
bool m_crcOK = false;
|
||||
};
|
||||
|
||||
class GameBinPathManager
|
||||
{
|
||||
public:
|
||||
GameBinPathManager() {}
|
||||
~GameBinPathManager() {}
|
||||
public:
|
||||
void Init();
|
||||
|
||||
inline const std::vector<std::string>& Paths() const
|
||||
{
|
||||
return m_ordered;
|
||||
}
|
||||
private:
|
||||
std::unordered_set<std::string> m_lookup;
|
||||
std::vector<std::string> m_ordered;
|
||||
};
|
||||
|
||||
class GameConfigManager :
|
||||
@@ -142,11 +175,16 @@ public: //SMGlobalClass
|
||||
void OnSourceModAllInitialized();
|
||||
void OnSourceModAllShutdown();
|
||||
public:
|
||||
bool TryGetGameBinaryInfo(const char* pszName, GameBinaryInfo* pDest);
|
||||
void RemoveCachedConfig(CGameConfig *config);
|
||||
private:
|
||||
void CacheGameBinaryInfo(const char* pszName);
|
||||
private:
|
||||
NameHashSet<CGameConfig *> m_Lookup;
|
||||
StringHashMap<GameBinaryInfo> m_gameBinInfos;
|
||||
public:
|
||||
StringHashMap<ITextListener_SMC *> m_customHandlers;
|
||||
GameBinPathManager m_gameBinPathManager;
|
||||
};
|
||||
|
||||
extern GameConfigManager g_GameConfigs;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user