Compare commits
167
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b635dace11 | ||
|
|
d990f956f9 | ||
|
|
955f1e0d3a | ||
|
|
b4cd559186 | ||
|
|
46e89891e1 | ||
|
|
080e2563c3 | ||
|
|
e1e0c33f2c | ||
|
|
0160d3cc71 | ||
|
|
81f0d82c67 | ||
|
|
b5276b435a | ||
|
|
16aecfb404 | ||
|
|
7054ef56f6 | ||
|
|
bfae78d1ec | ||
|
|
c82f2b4659 | ||
|
|
46d71790be | ||
|
|
647811f930 | ||
|
|
7ca80d1c7c | ||
|
|
8823bab3f3 | ||
|
|
b9d5b59bd1 | ||
|
|
7fc892d38b | ||
|
|
09040231a0 | ||
|
|
16541a5668 | ||
|
|
e1b3b14311 | ||
|
|
300632db86 | ||
|
|
d1776dd641 | ||
|
|
22cee6a2dd | ||
|
|
a2194df273 | ||
|
|
27e20996dd | ||
|
|
b5f16142e5 | ||
|
|
23f1f9e148 | ||
|
|
990f99af5a | ||
|
|
6ca9d86e8f | ||
|
|
fae8b4d49a | ||
|
|
7f2d9dd8eb | ||
|
|
8ae1b3e1e7 | ||
|
|
c77c853c02 | ||
|
|
2b0daba573 | ||
|
|
ba4aa4d37f | ||
|
|
e3f31af5d3 | ||
|
|
bc0bf4e270 | ||
|
|
60c5ad6324 | ||
|
|
e996a00675 | ||
|
|
0be3f0afed | ||
|
|
86bdfa2205 | ||
|
|
56c87e927f | ||
|
|
be54443918 | ||
|
|
676ea8b29c | ||
|
|
d77ff38428 | ||
|
|
d3256ef339 | ||
|
|
3d11742f91 | ||
|
|
a2aa5d1cda | ||
|
|
8860e18026 | ||
|
|
7dba540b97 | ||
|
|
0dd9a5b842 | ||
|
|
e6c3565544 | ||
|
|
8cacba922a | ||
|
|
767396d4ee | ||
|
|
07a51a0d4e | ||
|
|
9f042625d0 | ||
|
|
fc29f4249a | ||
|
|
5ca5ecee85 | ||
|
|
c79d547492 | ||
|
|
f079773195 | ||
|
|
e6ead8b5aa | ||
|
|
9eba6402eb | ||
|
|
f95be3b10c | ||
|
|
2220cc961e | ||
|
|
cfc6b2fee9 | ||
|
|
d188859fc5 | ||
|
|
96a8003448 | ||
|
|
696f702204 | ||
|
|
8b26ce73c2 | ||
|
|
ee5f488aa2 | ||
|
|
3a5cf80e2b | ||
|
|
3e4f7af96a | ||
|
|
a1a483fa27 | ||
|
|
b32f8a4803 | ||
|
|
96ee6dbf8a | ||
|
|
ac07cf95e1 | ||
|
|
8f51e33167 | ||
|
|
8366f371ad | ||
|
|
9b44dfea11 | ||
|
|
7ede8e0924 | ||
|
|
9fe2d9c1cf | ||
|
|
1836ec9d45 | ||
|
|
380d7adc09 | ||
|
|
4109d0df39 | ||
|
|
9cab1e3ab7 | ||
|
|
e9d8bfcdfc | ||
|
|
f134602991 | ||
|
|
b493532ee1 | ||
|
|
84dec75fb8 | ||
|
|
b1094f87c6 | ||
|
|
284b4bfe20 | ||
|
|
b46537ddd5 | ||
|
|
c9446c4d7d | ||
|
|
d4610ab340 | ||
|
|
0016b8ef2f | ||
|
|
72e08f7e44 | ||
|
|
b06cfa5414 | ||
|
|
a7742cae3d | ||
|
|
8a78285659 | ||
|
|
6847c8eec0 | ||
|
|
66790254ac | ||
|
|
86b8a0b16a | ||
|
|
25fced78e8 | ||
|
|
22d11160ba | ||
|
|
8d65b3e94e | ||
|
|
5518544ecd | ||
|
|
af3523bd2d | ||
|
|
8646cca538 | ||
|
|
c7cea1b40b | ||
|
|
58914f71bd | ||
|
|
3841e98c4f | ||
|
|
acd025dba2 | ||
|
|
78c2206628 | ||
|
|
5c47bf8803 | ||
|
|
8e78ee6f57 | ||
|
|
a2da4cc868 | ||
|
|
00e44ad3c3 | ||
|
|
29ba84fc5c | ||
|
|
283f1f012d | ||
|
|
fff17f8043 | ||
|
|
847eaf38f9 | ||
|
|
1d59a329eb | ||
|
|
5689888682 | ||
|
|
a01768525a | ||
|
|
e3d2ddf278 | ||
|
|
b3e48b0ad7 | ||
|
|
6d528b5c55 | ||
|
|
22daf26e3e | ||
|
|
73061969da | ||
|
|
4653530095 | ||
|
|
ef5faaaa4a | ||
|
|
f52ea98eb4 | ||
|
|
d315d4bf53 | ||
|
|
eaef2a46fb | ||
|
|
b0304a89a6 | ||
|
|
a4790f0358 | ||
|
|
d3d5cd8181 | ||
|
|
64be2bc5a0 | ||
|
|
30e476c35e | ||
|
|
88af208cdd | ||
|
|
b64751c1af | ||
|
|
2e158a72e2 | ||
|
|
c8fb05dd4b | ||
|
|
860af1e6cb | ||
|
|
5c1cadb64e | ||
|
|
bfb97a4207 | ||
|
|
7e26691b99 | ||
|
|
ca469a218a | ||
|
|
6052ddaa64 | ||
|
|
0ddc675472 | ||
|
|
9412f687cb | ||
|
|
0e865c0618 | ||
|
|
462b5213d7 | ||
|
|
f52e84730f | ||
|
|
b8873efa0d | ||
|
|
4132b9bd21 | ||
|
|
c0caa9f158 | ||
|
|
7346b0c081 | ||
|
|
6a361e3045 | ||
|
|
61d7519ef5 | ||
|
|
3e1a78703e | ||
|
|
bb195a9b2d | ||
|
|
6f095a064c | ||
|
|
eb334f5fe2 |
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"project_id" : "sourcemod",
|
|
||||||
"conduit_uri" : "https://phabricator.alliedmods.net/",
|
|
||||||
"history.immutable" : false
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
# Contributing to SourceMod
|
|
||||||
|
|
||||||
## Issue reports
|
|
||||||
|
|
||||||
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). 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 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 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.
|
|
||||||
* What is your end goal, or what are you trying to accomplish?
|
|
||||||
* Why is this necessary, or what benefit do you see with it?
|
|
||||||
* Will this be useful to others?
|
|
||||||
|
|
||||||
#### Issues with security implications
|
|
||||||
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 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 contributing changes to the project!
|
|
||||||
|
|
||||||
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 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.*
|
|
||||||
|
|
||||||
> If you send us a patch without coordinating it with us first, it will probably be immediately rejected, or sit in limbo for a long time and eventually be rejected. The reasons we do this vary from patch to patch, but some of the most common reasons are:
|
|
||||||
>
|
|
||||||
> **Unjustifiable Costs**: We support code in the upstream forever. Support is enormously expensive and takes up a huge amount of our time. The cost to support a change over its lifetime is often 10x or 100x or 1000x greater than the cost to write the first version of it. Many uncoordinated patches we receive are "white elephants", which would cost much more to maintain than the value they provide.
|
|
||||||
>
|
|
||||||
> As an author, it may look like you're giving us free work and we're rejecting it as too expensive, but this viewpoint doesn't align with the reality of a large project which is actively supported by a small, experienced team. Writing code is cheap; maintaining it is expensive.
|
|
||||||
>
|
|
||||||
> By coordinating with us first, you can make sure the patch is something we consider valuable enough to put long-term support resources behind, and that you're building it in a way that we're comfortable taking over.
|
|
||||||
>
|
|
||||||
> **Not a Good Fit**: Many patches aren't good fits for the upstream: they implement features we simply don't want. You can find more information in Contributing Feature Requests. Coordinating with us first helps make sure we're on the same page and interested in a feature.
|
|
||||||
>
|
|
||||||
> The most common type of patch along these lines is a patch which adds new configuration options. We consider additional configuration options to have an exceptionally high lifetime support cost and are very unlikely to accept them. Coordinate with us first.
|
|
||||||
>
|
|
||||||
> **Not a Priority**: If you send us a patch against something which isn't a priority, we probably won't have time to look at it. We don't give special treatment to low-priority issues just because there's code written: we'd still be spending time on something lower-priority when we could be spending it on something higher-priority instead.
|
|
||||||
>
|
|
||||||
> If you coordinate with us first, you can make sure your patch is in an area of the codebase that we can prioritize.
|
|
||||||
>
|
|
||||||
> **Overly Ambitious Patches**: Sometimes we'll get huge patches from new contributors. These can have a lot of fundamental problems and require a huge amount of our time to review and correct. If you're interested in contributing, you'll have more success if you start small and learn as you go.
|
|
||||||
>
|
|
||||||
> We can help you break a large change into smaller pieces and learn how the codebase works as you proceed through the implementation, but only if you coordinate with us first.
|
|
||||||
>
|
|
||||||
> **Generality**: We often receive several feature requests which ask for similar features, and can come up with a general approach which covers all of the use cases. If you send us a patch for your use case only, the approach may be too specific. When a cleaner and more general approach is available, we usually prefer to pursue it.
|
|
||||||
>
|
|
||||||
> By coordinating with us first, we can make you aware of similar use cases and opportunities to generalize an approach. These changes are often small, but can have a big impact on how useful a piece of code is.
|
|
||||||
>
|
|
||||||
> **Infrastructure and Sequencing**: Sometimes patches are written against a piece of infrastructure with major planned changes. We don't want to accept these because they'll make the infrastructure changes more difficult to implement.
|
|
||||||
>
|
|
||||||
> Coordinate with us first to make sure a change doesn't need to wait on other pieces of infrastructure. We can help you identify technical blockers and possibly guide you through resolving them if you're interested.
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
# 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
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
# Help us help you
|
|
||||||
- [ ] I have checked that my issue [doesn't exist yet](https://github.com/alliedmodders/sourcemod/issues).
|
|
||||||
- [ ] I have tried my absolute best to reduce the problem-space and have provided the absolute smallest test-case possible.
|
|
||||||
- [ ] I can always reproduce the issue with the provided description below.
|
|
||||||
|
|
||||||
# Environment
|
|
||||||
* Operating System version:
|
|
||||||
* Game/AppID (with version if applicable):
|
|
||||||
* Current SourceMod version:
|
|
||||||
* Current SourceMod snapshot:
|
|
||||||
* Current Metamod: Source snapshot:
|
|
||||||
- [ ] I have updated SourceMod to the [latest version](https://www.sourcemod.net/downloads.php) and it still happens.
|
|
||||||
- [ ] I have updated SourceMod to the [latest snapshot](https://www.sourcemod.net/downloads.php?branch=dev) and it still happens.
|
|
||||||
- [ ] I have updated SourceMM to the [latest snapshot](https://sourcemm.net/downloads.php?branch=dev) and it still happens.
|
|
||||||
|
|
||||||
# Description
|
|
||||||
|
|
||||||
|
|
||||||
# Problematic Code (or Steps to Reproduce)
|
|
||||||
```
|
|
||||||
// TODO(you): code here to reproduce the problem
|
|
||||||
```
|
|
||||||
|
|
||||||
# Logs
|
|
||||||
* Please attach in separate files: game output, library logs, kernel logs, and any other supporting information.
|
|
||||||
* In case of a crash, please attach minidump or dump analyze output.
|
|
||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
# Binaries
|
|
||||||
*.dll
|
|
||||||
*.dylib
|
|
||||||
*.exe
|
|
||||||
*.so
|
|
||||||
|
|
||||||
# Files generated by Visual Studio
|
|
||||||
*.aps
|
|
||||||
*.ipch
|
|
||||||
*.ncb
|
|
||||||
*.opensdf
|
|
||||||
*.sdf
|
|
||||||
*.suo
|
|
||||||
*.user
|
|
||||||
|
|
||||||
# Build directories
|
|
||||||
CrazyDebug*/
|
|
||||||
Debug*/
|
|
||||||
Release*/
|
|
||||||
LIB-Release/
|
|
||||||
LIB-Debug/
|
|
||||||
|
|
||||||
# Files generated by Mac OS X Finder
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# Files generated by Windows Explorer
|
|
||||||
[Dd]esktop.ini
|
|
||||||
[Tt]humbs.db
|
|
||||||
|
|
||||||
# AMBuild build directories
|
|
||||||
build/
|
|
||||||
obj-*/
|
|
||||||
*~
|
|
||||||
*.rej
|
|
||||||
*.orig
|
|
||||||
*.smx
|
|
||||||
*.swp
|
|
||||||
*.gdb_history
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
[submodule "public/amtl"]
|
|
||||||
path = public/amtl
|
|
||||||
url = https://github.com/alliedmodders/amtl
|
|
||||||
[submodule "sourcepawn"]
|
|
||||||
path = sourcepawn
|
|
||||||
url = https://github.com/alliedmodders/sourcepawn
|
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# Binaries
|
||||||
|
\.dll$
|
||||||
|
\.dylib$
|
||||||
|
\.exe$
|
||||||
|
\.so$
|
||||||
|
|
||||||
|
# Files generated by Visual Studio
|
||||||
|
\.aps$
|
||||||
|
\.ipch$
|
||||||
|
\.ncb$
|
||||||
|
\.opensdf$
|
||||||
|
\.sdf$
|
||||||
|
\.suo$
|
||||||
|
\.user$
|
||||||
|
|
||||||
|
# Build directories
|
||||||
|
/CrazyDebug.*
|
||||||
|
/Debug.*
|
||||||
|
/Release.*
|
||||||
|
|
||||||
|
# Files generated by Mac OS X Finder
|
||||||
|
(^|/)\.DS_Store$
|
||||||
|
|
||||||
|
# Files generated by Windows Explorer
|
||||||
|
(^|/)[dD]esktop\.ini$
|
||||||
|
(^|/)[tT]humbs\.db$
|
||||||
|
syntax: glob
|
||||||
|
build/*
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
54539fa4e51f98d7841c853c1370dff6ccd3cdf2 sourcemod-1.0.0
|
||||||
|
e6ef5ecdf8d75740ca2685a709bf321f8873bc3b sourcemod-1.1.0
|
||||||
|
e877885fac80be71822641f7a9122cebc9812521 sourcemod-1.1.1
|
||||||
|
b3ffa8a4511c4eadaf533fc790aa6b14f7f0c6ea sourcemod-1.1.2
|
||||||
|
3a73bbf60f34befa9b66be03fa5974b394bb3411 sourcemod-1.2.0
|
||||||
|
78a1f1b1c6fa86fd7691c70ebf48a9fb3dfb3c11 sourcemod-1.5.0
|
||||||
|
5574bfe07731b7dba171c1300f6022319d2dbc89 sourcemod-1.5.1
|
||||||
-118
@@ -1,118 +0,0 @@
|
|||||||
git:
|
|
||||||
depth: 3
|
|
||||||
|
|
||||||
sudo: false
|
|
||||||
language: cpp
|
|
||||||
os: linux
|
|
||||||
dist: trusty
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
- llvm-toolchain-trusty-3.9
|
|
||||||
- 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
|
|
||||||
- clang-3.9
|
|
||||||
- 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"
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
fast_finish: true
|
|
||||||
include:
|
|
||||||
- os: linux
|
|
||||||
sudo: false
|
|
||||||
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"']
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
sudo: false
|
|
||||||
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"']
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
sudo: false
|
|
||||||
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"
|
|
||||||
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- CHECKOUT_DIR=$PWD && cd .. && $CHECKOUT_DIR/tools/checkout-deps.sh && cd $CHECKOUT_DIR
|
|
||||||
script:
|
|
||||||
- mkdir build && cd build
|
|
||||||
- PATH="~/.local/bin:$PATH"
|
|
||||||
- eval "${MATRIX_EVAL}"
|
|
||||||
- python ../configure.py --enable-optimize --sdks=episode1,css,tf2,l4d2,csgo,dota
|
|
||||||
- ambuild
|
|
||||||
+492
-664
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
CONFIGURE YOUR IDENTITY FOR MERCURIAL!
|
||||||
|
IF YOU ARE A DEVELOPER WITH PUSH ACCESS, DO IT NOW KPLZTHX.
|
||||||
|
|
||||||
|
http://wiki.alliedmods.net/Mercurial_Tutorial#Identity
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
SourceMod
|
|
||||||
=========
|
|
||||||
|
|
||||||
General
|
|
||||||
-------
|
|
||||||
- [SourceMod website](http://www.sourcemod.net): Source Engine scripting and server administration
|
|
||||||
- [Forum](https://forums.alliedmods.net/forumdisplay.php?f=52): Discussion forum including plugin/extension development
|
|
||||||
- [General documentation](https://wiki.alliedmods.net/Category:SourceMod_Documentation): Miscellaneous information about SourceMod
|
|
||||||
- [Stable builds](http://www.sourcemod.net/downloads.php?branch=stable): The latest stable SourceMod releases
|
|
||||||
- [Dev builds](http://www.sourcemod.net/downloads.php?branch=dev): Builds of recent development versions
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
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.
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet:
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_BRIDGE_API_H_
|
|
||||||
#define _INCLUDE_SOURCEMOD_BRIDGE_API_H_
|
|
||||||
|
|
||||||
#include <bridge/include/CoreProvider.h>
|
|
||||||
#include <bridge/include/LogicProvider.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
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 - 57;
|
|
||||||
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
typedef void (*LogicInitFunction)(SourceMod::CoreProvider *core, SourceMod::sm_logic_t *logic);
|
|
||||||
typedef LogicInitFunction (*LogicLoadFunction)(uint32_t magic);
|
|
||||||
typedef SourceMod::ITextParsers *(*GetITextParsers)();
|
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_BRIDGE_API_H_
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet:
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_CORE_PROVIDER_API_H_
|
|
||||||
#define _INCLUDE_SOURCEMOD_CORE_PROVIDER_API_H_
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <IAdminSystem.h>
|
|
||||||
#include <amtl/am-function.h>
|
|
||||||
|
|
||||||
namespace SourcePawn {
|
|
||||||
class ISourcePawnEngine;
|
|
||||||
class ISourcePawnEngine2;
|
|
||||||
} // namespace SourcePawn
|
|
||||||
|
|
||||||
// SDK types.
|
|
||||||
#if defined(SM_LOGIC)
|
|
||||||
class ConCommandBase {};
|
|
||||||
class ConVar : public ConCommandBase {};
|
|
||||||
#else
|
|
||||||
class ConCommandBase;
|
|
||||||
class ConVar;
|
|
||||||
#endif
|
|
||||||
class KeyValues;
|
|
||||||
|
|
||||||
struct ServerGlobals
|
|
||||||
{
|
|
||||||
const double *universalTime;
|
|
||||||
float *interval_per_tick;
|
|
||||||
float *frametime;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace SourceMod {
|
|
||||||
|
|
||||||
class ISourceMod;
|
|
||||||
class IVEngineServerBridge;
|
|
||||||
class IFileSystemBridge;
|
|
||||||
class ITimerSystem;
|
|
||||||
class IPlayerManager;
|
|
||||||
class IGameHelpers;
|
|
||||||
class IMenuManager;
|
|
||||||
struct DatabaseInfo;
|
|
||||||
class IPlayerInfoBridge;
|
|
||||||
class ICommandArgs;
|
|
||||||
|
|
||||||
typedef ke::Lambda<bool(int client, const ICommandArgs*)> CommandFunc;
|
|
||||||
|
|
||||||
class CoreProvider
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/* Objects */
|
|
||||||
ISourceMod *sm;
|
|
||||||
IVEngineServerBridge *engine;
|
|
||||||
IFileSystemBridge *filesystem;
|
|
||||||
IPlayerInfoBridge *playerInfo;
|
|
||||||
ITimerSystem *timersys;
|
|
||||||
IPlayerManager *playerhelpers;
|
|
||||||
IGameHelpers *gamehelpers;
|
|
||||||
IMenuManager *menus;
|
|
||||||
SourcePawn::ISourcePawnEngine **spe1;
|
|
||||||
SourcePawn::ISourcePawnEngine2 **spe2;
|
|
||||||
const char *gamesuffix;
|
|
||||||
/* Data */
|
|
||||||
ServerGlobals *serverGlobals;
|
|
||||||
void * serverFactory;
|
|
||||||
void * engineFactory;
|
|
||||||
void * matchmakingDSFactory;
|
|
||||||
SMGlobalClass * listeners;
|
|
||||||
|
|
||||||
// ConVar functions.
|
|
||||||
virtual ConVar *FindConVar(const char *name) = 0;
|
|
||||||
virtual const char *GetCvarString(ConVar *cvar) = 0;
|
|
||||||
virtual bool GetCvarBool(ConVar* cvar) = 0;
|
|
||||||
|
|
||||||
// Command functions.
|
|
||||||
virtual void DefineCommand(const char *cmd, const char *help, const CommandFunc &callback) = 0;
|
|
||||||
|
|
||||||
// Game description functions.
|
|
||||||
virtual bool GetGameName(char *buffer, size_t maxlength) = 0;
|
|
||||||
virtual const char *GetGameDescription() = 0;
|
|
||||||
virtual const char *GetSourceEngineName() = 0;
|
|
||||||
virtual bool SymbolsAreHidden() = 0;
|
|
||||||
|
|
||||||
// Game state and helper functions.
|
|
||||||
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 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;
|
|
||||||
|
|
||||||
// Game engine helper functions.
|
|
||||||
virtual bool IsClientConVarQueryingSupported() = 0;
|
|
||||||
virtual int QueryClientConVar(int client, const char *cvar) = 0;
|
|
||||||
|
|
||||||
// Metamod:Source functions.
|
|
||||||
virtual int LoadMMSPlugin(const char *file, bool *ok, char *error, size_t maxlength) = 0;
|
|
||||||
virtual void UnloadMMSPlugin(int id) = 0;
|
|
||||||
|
|
||||||
const char * (*GetCoreConfigValue)(const char*);
|
|
||||||
void (*DoGlobalPluginLoads)();
|
|
||||||
bool (*AreConfigsExecuted)();
|
|
||||||
void (*ExecuteConfigs)(IPluginContext *ctx);
|
|
||||||
void (*GetDBInfoFromKeyValues)(KeyValues *, DatabaseInfo *);
|
|
||||||
int (*GetActivityFlags)();
|
|
||||||
int (*GetImmunityMode)();
|
|
||||||
void (*UpdateAdminCmdFlags)(const char *cmd, OverrideType type, FlagBits bits, bool remove);
|
|
||||||
bool (*LookForCommandAdminFlags)(const char *cmd, FlagBits *pFlags);
|
|
||||||
int (*GetGlobalTarget)();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_CORE_PROVIDER_API_H_
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet:
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_BRIDGE_INCLUDE_IEXTBRIDGE_H_
|
|
||||||
#define _INCLUDE_SOURCEMOD_BRIDGE_INCLUDE_IEXTBRIDGE_H_
|
|
||||||
|
|
||||||
#include <sp_vm_api.h>
|
|
||||||
#include <IExtensionSys.h>
|
|
||||||
#include <sh_vector.h>
|
|
||||||
|
|
||||||
struct edict_t;
|
|
||||||
|
|
||||||
namespace SourceMod {
|
|
||||||
|
|
||||||
using namespace SourceHook;
|
|
||||||
using namespace SourcePawn;
|
|
||||||
class SMPlugin;
|
|
||||||
|
|
||||||
class IExtensionSys : public IExtensionManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual IExtension *LoadAutoExtension(const char *name, bool bErrorOnMissing=true) = 0;
|
|
||||||
virtual void TryAutoload() = 0;
|
|
||||||
virtual void Shutdown() = 0;
|
|
||||||
virtual IExtension *FindExtensionByFile(const char *name) = 0;
|
|
||||||
virtual bool LibraryExists(const char *name) = 0;
|
|
||||||
virtual void CallOnCoreMapStart(edict_t *edictList, int edictCount, int maxClients) = 0;
|
|
||||||
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 void CallOnCoreMapEnd() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class AutoExtensionList
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AutoExtensionList(IExtensionSys *extensions)
|
|
||||||
: extensions_(extensions), list_(extensions_->ListExtensions())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
~AutoExtensionList()
|
|
||||||
{
|
|
||||||
extensions_->FreeExtensionList(list_);
|
|
||||||
}
|
|
||||||
const CVector<IExtension *> *operator ->()
|
|
||||||
{
|
|
||||||
return list_;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
IExtensionSys *extensions_;
|
|
||||||
const CVector<IExtension *> *list_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_BRIDGE_INCLUDE_IEXTBRIDGE_H_
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet:
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_BRIDGE_IFILESYSTEM_H_
|
|
||||||
#define _INCLUDE_SOURCEMOD_BRIDGE_IFILESYSTEM_H_
|
|
||||||
|
|
||||||
typedef void * FileHandle_t;
|
|
||||||
typedef int FileFindHandle_t;
|
|
||||||
|
|
||||||
namespace SourceMod {
|
|
||||||
|
|
||||||
class IFileSystemBridge
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual const char *FindFirstEx(const char *pWildCard, const char *pPathID, FileFindHandle_t *pHandle) = 0;
|
|
||||||
virtual const char *FindNext(FileFindHandle_t handle) = 0;
|
|
||||||
virtual bool FindIsDirectory(FileFindHandle_t handle) = 0;
|
|
||||||
virtual void FindClose(FileFindHandle_t handle) = 0;
|
|
||||||
virtual FileHandle_t Open(const char *pFileName, const char *pOptions, const char *pathID = 0) = 0;
|
|
||||||
virtual void Close(FileHandle_t file) = 0;
|
|
||||||
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(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;
|
|
||||||
virtual void Seek(FileHandle_t file, int post, int seekType) = 0;
|
|
||||||
virtual unsigned int Tell(FileHandle_t file) = 0;
|
|
||||||
virtual int FPrint(FileHandle_t file, const char *pData) = 0;
|
|
||||||
virtual void Flush(FileHandle_t file) = 0;
|
|
||||||
virtual bool IsOk(FileHandle_t file) = 0;
|
|
||||||
virtual void RemoveFile(const char *pRelativePath, const char *pathID = 0) = 0;
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_BRIDGE_IFILESYSTEM_H_
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet:
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_BRIDGE_LOGGER_H_
|
|
||||||
#define _INCLUDE_SOURCEMOD_BRIDGE_LOGGER_H_
|
|
||||||
|
|
||||||
namespace SourceMod {
|
|
||||||
|
|
||||||
class ILogger
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual void LogMessage(const char *msg, ...) = 0;
|
|
||||||
virtual void LogError(const char *msg, ...) = 0;
|
|
||||||
virtual void LogFatal(const char *msg, ...) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_BRIDGE_LOGGER_H_
|
|
||||||
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet:
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_BRIDGE_INCLUDE_IPLAYERINFO_H_
|
|
||||||
#define _INCLUDE_SOURCEMOD_BRIDGE_INCLUDE_IPLAYERINFO_H_
|
|
||||||
|
|
||||||
class IPlayerInfo;
|
|
||||||
|
|
||||||
namespace SourceMod {
|
|
||||||
|
|
||||||
class IPlayerInfoBridge
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual bool IsObserver(IPlayerInfo *pInfo) = 0;
|
|
||||||
virtual int GetTeamIndex(IPlayerInfo *pInfo) = 0;
|
|
||||||
virtual int GetFragCount(IPlayerInfo *pInfo) = 0;
|
|
||||||
virtual int GetDeathCount(IPlayerInfo *pInfo) = 0;
|
|
||||||
virtual int GetArmorValue(IPlayerInfo *pInfo) = 0;
|
|
||||||
virtual void GetAbsOrigin(IPlayerInfo *pInfo, float *x, float *y, float *z) = 0;
|
|
||||||
virtual void GetAbsAngles(IPlayerInfo *pInfo, float *x, float *y, float *z) = 0;
|
|
||||||
virtual void GetPlayerMins(IPlayerInfo *pInfo, float *x, float *y, float *z) = 0;
|
|
||||||
virtual void GetPlayerMaxs(IPlayerInfo *pInfo, float *x, float *y, float *z) = 0;
|
|
||||||
virtual const char *GetWeaponName(IPlayerInfo *pInfo) = 0;
|
|
||||||
virtual const char *GetModelName(IPlayerInfo *pInfo) = 0;
|
|
||||||
virtual int GetHealth(IPlayerInfo *pInfo) = 0;
|
|
||||||
virtual void ChangeTeam(IPlayerInfo *pInfo, int iTeamNum) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_BRIDGE_INCLUDE_IPLAYERINFO_H_
|
|
||||||
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet:
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_BRIDGE_INCLUDE_IPROVIDERCALLBACK_H_
|
|
||||||
#define _INCLUDE_SOURCEMOD_BRIDGE_INCLUDE_IPROVIDERCALLBACK_H_
|
|
||||||
|
|
||||||
namespace SourceMod {
|
|
||||||
|
|
||||||
// Global callbacks provided to Core.
|
|
||||||
class IProviderCallbacks
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// Called when a log message is printed. Return true to supercede.
|
|
||||||
virtual bool OnLogPrint(const char *msg) = 0;
|
|
||||||
|
|
||||||
// Called each frame tick.
|
|
||||||
virtual void OnThink(bool simulating) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_BRIDGE_INCLUDE_IPROVIDERCALLBACK_H_
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet:
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_BRIDGE_INCLUDE_ISCRIPTMANAGER_H_
|
|
||||||
#define _INCLUDE_SOURCEMOD_BRIDGE_INCLUDE_ISCRIPTMANAGER_H_
|
|
||||||
|
|
||||||
#include <sp_vm_api.h>
|
|
||||||
#include <IPluginSys.h>
|
|
||||||
#include <sh_vector.h>
|
|
||||||
#include <sh_string.h>
|
|
||||||
|
|
||||||
namespace SourceMod {
|
|
||||||
|
|
||||||
using namespace SourceHook;
|
|
||||||
using namespace SourcePawn;
|
|
||||||
|
|
||||||
class IChangeableForward;
|
|
||||||
|
|
||||||
enum LibraryAction
|
|
||||||
{
|
|
||||||
LibraryAction_Removed,
|
|
||||||
LibraryAction_Added
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AutoConfig
|
|
||||||
{
|
|
||||||
SourceHook::String autocfg;
|
|
||||||
SourceHook::String folder;
|
|
||||||
bool create;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SMPlugin : public IPlugin
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual size_t GetConfigCount() = 0;
|
|
||||||
virtual AutoConfig *GetConfig(size_t i) = 0;
|
|
||||||
virtual void AddLibrary(const char *name) = 0;
|
|
||||||
virtual void AddConfig(bool create, const char *cfg, const char *folder) = 0;
|
|
||||||
virtual void EvictWithError(PluginStatus status, const char *fmt, ...) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class IScriptManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual void LoadAll(const char *config_path, const char *plugins_path) = 0;
|
|
||||||
virtual void RefreshAll() = 0;
|
|
||||||
virtual void Shutdown() = 0;
|
|
||||||
virtual IdentityToken_t *GetIdentity() = 0;
|
|
||||||
virtual void SyncMaxClients(int maxClients) = 0;
|
|
||||||
virtual void AddPluginsListener(IPluginsListener *listener) = 0;
|
|
||||||
virtual void RemovePluginsListener(IPluginsListener *listener) = 0;
|
|
||||||
virtual IPluginIterator *GetPluginIterator() = 0;
|
|
||||||
virtual void OnLibraryAction(const char *name, LibraryAction action) = 0;
|
|
||||||
virtual bool LibraryExists(const char *name) = 0;
|
|
||||||
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 void AddFunctionsToForward(const char *name, IChangeableForward *fwd) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class AutoPluginList
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AutoPluginList(IScriptManager *scripts)
|
|
||||||
: scripts_(scripts), list_(scripts->ListPlugins())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
~AutoPluginList()
|
|
||||||
{
|
|
||||||
scripts_->FreePluginList(list_);
|
|
||||||
}
|
|
||||||
const CVector<SMPlugin *> *operator ->()
|
|
||||||
{
|
|
||||||
return list_;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
IScriptManager *scripts_;
|
|
||||||
const CVector<SMPlugin *> *list_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_BRIDGE_INCLUDE_ISCRIPTMANAGER_H_
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet:
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_BRIDGE_IVENGINESERVER_H_
|
|
||||||
#define _INCLUDE_SOURCEMOD_BRIDGE_IVENGINESERVER_H_
|
|
||||||
|
|
||||||
struct edict_t;
|
|
||||||
|
|
||||||
namespace SourceMod {
|
|
||||||
|
|
||||||
class IVEngineServerBridge
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual bool IsDedicatedServer() = 0;
|
|
||||||
virtual void InsertServerCommand(const char *cmd) = 0;
|
|
||||||
virtual void ServerCommand(const char *cmd) = 0;
|
|
||||||
virtual void ServerExecute() = 0;
|
|
||||||
virtual const char *GetClientConVarValue(int clientIndex, const char *name) = 0;
|
|
||||||
virtual void ClientCommand(edict_t *pEdict, const char *szCommand) = 0;
|
|
||||||
virtual void FakeClientCommand(edict_t *pEdict, const char *szCommand) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_BRIDGE_IVENGINESERVER_H_
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet:
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_LOGIC_PROVIDER_API_H_
|
|
||||||
#define _INCLUDE_SOURCEMOD_LOGIC_PROVIDER_API_H_
|
|
||||||
|
|
||||||
#include <sp_vm_api.h>
|
|
||||||
|
|
||||||
class SMGlobalClass;
|
|
||||||
|
|
||||||
namespace SourceMod {
|
|
||||||
|
|
||||||
using namespace SourcePawn;
|
|
||||||
|
|
||||||
class CoreProvider;
|
|
||||||
class IThreader;
|
|
||||||
class ITranslator;
|
|
||||||
class IGameConfig;
|
|
||||||
class IScriptManager;
|
|
||||||
class IShareSys;
|
|
||||||
class IHandleSys;
|
|
||||||
class ICommandArgs;
|
|
||||||
class IForwardManager;
|
|
||||||
class IAdminSystem;
|
|
||||||
class IRootConsole;
|
|
||||||
class IProviderCallbacks;
|
|
||||||
class IExtensionSys;
|
|
||||||
class ITextParsers;
|
|
||||||
class ILogger;
|
|
||||||
class ICellArray;
|
|
||||||
|
|
||||||
struct sm_logic_t
|
|
||||||
{
|
|
||||||
SMGlobalClass *head;
|
|
||||||
IThreader *threader;
|
|
||||||
ITranslator *translator;
|
|
||||||
const char *(*stristr)(const char *, const char *);
|
|
||||||
size_t (*atcprintf)(char *, size_t, const char *, IPluginContext *, const cell_t *, int *);
|
|
||||||
bool (*CoreTranslate)(char *, size_t, const char *, unsigned int, size_t *, ...);
|
|
||||||
void (*AddCorePhraseFile)(const char *filename);
|
|
||||||
unsigned int (*ReplaceAll)(char*, size_t, const char *, const char *, bool);
|
|
||||||
char *(*ReplaceEx)(char *, size_t, const char *, size_t, const char *, size_t, bool);
|
|
||||||
size_t (*DecodeHexString)(unsigned char *, size_t, const char *);
|
|
||||||
IGameConfig * (*GetCoreGameConfig)();
|
|
||||||
IDebugListener *debugger;
|
|
||||||
void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...);
|
|
||||||
void (*AddNatives)(sp_nativeinfo_t *natives);
|
|
||||||
void (*RegisterProfiler)(IProfilingTool *tool);
|
|
||||||
ICellArray * (*CreateCellArray)(size_t blocksize);
|
|
||||||
void (*FreeCellArray)(ICellArray *arr);
|
|
||||||
void * (*FromPseudoAddress)(uint32_t pseudoAddr);
|
|
||||||
uint32_t (*ToPseudoAddress)(void *addr);
|
|
||||||
IScriptManager *scripts;
|
|
||||||
IShareSys *sharesys;
|
|
||||||
IExtensionSys *extsys;
|
|
||||||
IHandleSys *handlesys;
|
|
||||||
IForwardManager *forwardsys;
|
|
||||||
IAdminSystem *adminsys;
|
|
||||||
IdentityToken_t *core_ident;
|
|
||||||
ILogger *logger;
|
|
||||||
IRootConsole *rootmenu;
|
|
||||||
IProviderCallbacks *callbacks;
|
|
||||||
float sentinel;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_LOGIC_PROVIDER_API_H_
|
|
||||||
|
|
||||||
+410
@@ -1,5 +1,415 @@
|
|||||||
SourceMod Changelog
|
SourceMod Changelog
|
||||||
|
|
||||||
|
SourceMod 1.5.2 [2013-10-29]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.5.2_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
- Updated gamedata support for TF2, CS:S, CS:GO, and HL2:DM.
|
||||||
|
- Fixed crash from regression in SDKTools SetClientListening hook refcounting (bug 5956) (KyleS).
|
||||||
|
- Fixed potential crash when having maps with format characters in name.
|
||||||
|
- Fixed some nextmap issues with long map names.
|
||||||
|
- SDKTools no longer requires gamedata for sm_dump_datamaps on TF2, CS:S, HL2:DM, and DoD:S (bug 5968).
|
||||||
|
|
||||||
|
Developer Changes:
|
||||||
|
- Updated TFCond and TF custom dmg enums.
|
||||||
|
- Updated TF2 critical hit detection logic in TF2_OnCalcIsAttackCritical to handle more cases, including when criticals are disabled (bug 5894).
|
||||||
|
- Fixed GetEngineVersion native returning a bad value when running on MM:S 1.9.x or earlier (bug 5697).
|
||||||
|
|
||||||
|
----------------------------------------------------------
|
||||||
|
SourceMod 1.5.1 [2013-09-10]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.5.1_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
- Updated gamedata support for TF2.
|
||||||
|
- Added missing DispatchKeyValue gamedata for HL2 CTF (bug 5114) (peace-maker).
|
||||||
|
- Fixed translations not being loaded if identifier was not two or three characters (fixes Portuguese) (bug 5888).
|
||||||
|
- Fixed runoff voting occurring when receiving the exact number of required votes (bug 5890).
|
||||||
|
- Fixed reserve slot plugin hiding too many slots on Orangebox gamesif SourceTV and/or Replay are present (bug 5499).
|
||||||
|
- Fixed some crashes in TF2 and unexpected behavior in all games with SDKHook_TakeDamage due to uninitialized var.
|
||||||
|
- Fixed attempted triggers from gagged users displaying in chat (bug 5918).
|
||||||
|
- Fixed errors in Italian translation (Oktober).
|
||||||
|
- Added Norwegian translation (checkster).
|
||||||
|
|
||||||
|
Developer Changes:
|
||||||
|
- Added CS_UpdateClientModel native to CStrike extension for CS:S and CS:GO (bug 5905) (Drifter).
|
||||||
|
- Fixed setting weapon param in SDKHook_TakeDamage overwriting attacker instead of setting weapon (bug 5911) (KyleS)
|
||||||
|
|
||||||
|
----------------------------------------------------------
|
||||||
|
SourceMod 1.5.0 [2013-08-25]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.5.0_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
|
||||||
|
- Added support for Counter-Strike: Global Offensive (bug 5299, bug 5579).
|
||||||
|
- Split CS:S, TF2, DoD:S, HL2:DM, and ND to separate binaries (bug 5370, bug 5813).
|
||||||
|
- Added support for runoff voting in mapchooser (bug 4218).
|
||||||
|
- Added option to require Steam validation before granting admin access (bug 4837) (VoiDeD).
|
||||||
|
- Added localization support for many more core and base plugin messages (bug 5120, bug 5146).
|
||||||
|
- Added the ability to override RegConsoleCommand-created commands (bug 5199).
|
||||||
|
- Added support for "fuzzy" (partial) map names in map-related natives and cmds for L4D and later (bug 5599).
|
||||||
|
- Updated Reserved Slots to use max humans as max count (bug 5444).
|
||||||
|
- Added support for custom maxitems on radio menus (bug 5371).
|
||||||
|
- Improved console config editing (bug 5470).
|
||||||
|
- Increased map name buffer sizes in mapchooser to better account for nested maps (bug 5609) (Peace-Maker).
|
||||||
|
- Fixed JIT conflicts with SELinux (bug 5581).
|
||||||
|
- Added logged error when PlayerRunCommand offset lookup fails (bug 5535) (GoD-Tony).
|
||||||
|
- Fixed double print when sending psay to self (bug 5649) (Peace-Maker).
|
||||||
|
- Fixed check against uninitialized string in extension loader (bug 5546) (KyleS).
|
||||||
|
- Fixed possible runtime errors in basetriggers for not-ingame clients (bug 5191) (Peace-Maker).
|
||||||
|
- Check all possible mapcycle paths on newer orangebox games (bug 5719).
|
||||||
|
- Fixed ReadMapList not seeing maps in all valve search paths (bug 5715) (VoiDeD).
|
||||||
|
- Fixed typo in too-many-params native error message (Peace-Maker).
|
||||||
|
- Fixed various issues in clientprefs (bug 5538) (KyleS).
|
||||||
|
- Removed debug printout from PerformGravity (bug 5679) (KyleS).
|
||||||
|
- Fixed broken translating in some plugins and natives (bug 5612) (KyleS).
|
||||||
|
- Fixed issues with COMMAND_FILTER_NO_BOTS and @bots multi-target.
|
||||||
|
- Fixed crash in SDKHooks when throwing bad ent type error on logical ent (KyleS).
|
||||||
|
|
||||||
|
Developer Changes:
|
||||||
|
|
||||||
|
- Added support for CS:GO to the CStrike extension (bug 5299) (Drifter).
|
||||||
|
- Added support for new protobuf usermessages used in newer games (bug 5579, bug 5588, bug 5590, bug 5633).
|
||||||
|
- Added latest SDKHooks version as first-party extension.
|
||||||
|
- Updated SQLite to version 3.7.15.1 (bug 5235).
|
||||||
|
- Added natives for changing team score and mvp stars on CSS/CSGO (bug 5295) (Drifter).
|
||||||
|
- Added global pre and post forwards for client chat (bug 5394) (KyleS).
|
||||||
|
- Added TF2_CanPlayerTeleport forward to the TF2 game extension (bug 5283) (VoiDeD).
|
||||||
|
- Added GetEntityAddress native (bug 5269) (ProdigySim).
|
||||||
|
- Added more parameters to PlayerRunCommand forward (bug 5346) (GoD-Tony).
|
||||||
|
- Added forwards to basecomm plugin (bug 5466) (Drifter).
|
||||||
|
- Added symbol lookup support to gamedata on Windows (bug 5511) (GoD-Tony).
|
||||||
|
- Exposed GetLanguageInfo in ITranslator interface (bug 5249) (VoiDeD).
|
||||||
|
- Increase maximum .sp line length to 4095 characters. (bug 5347) (theY4Kman).
|
||||||
|
- Improved netprop dump output (bug 5471).
|
||||||
|
- Added int64 typename to netprop dumps (bug 5655).
|
||||||
|
- Added GetMaxHumanPlayers native exposing IServerGameClients func (bug 5551).
|
||||||
|
- Added WeaponIDToAlias native to CStrike extension (bug 5460) (KyleS).
|
||||||
|
- Fixed OnLibraryAdded/Removed not being called in all plugins (bug 5431).
|
||||||
|
- Made thread worker processing limits configurable at runtime (bug 5326).
|
||||||
|
- Added support in TF2 ext for detection of player conds >= 64 (bug 5565).
|
||||||
|
- Updated button defines in entity_prop_stocks (bug 5564).
|
||||||
|
- Added GetPlayerResourceEntity to SDKTools to replace old, semi-broken TF2-only version (bug 5491).
|
||||||
|
- Exposed third parameter of TF2's AddCond in TF2_AddCondition (bug 5641) (FlaminSarge).
|
||||||
|
- Added GetSteamAccountID function to IPlayerHelpers and native for sp (bug 5548) (KyleS).
|
||||||
|
- Added ISDKHooks interface with entity listeners (bug 5602) (GoD-Tony).
|
||||||
|
- Added file upload support to webternet extension.
|
||||||
|
- Added more alternative names for TFClass_Heavy (bug 5338) (Afronanny).
|
||||||
|
- Throw error instead of crash when calling SetTeamScore between maps (bug 5718) (KyleS).
|
||||||
|
- Fixed clients not being marked as in kick queue in some cases (bug 5746) (SystematicMania).
|
||||||
|
- Made compile.sh set working dir to own dir (bug 5710) (KyleS).
|
||||||
|
- Added CS_IsValidWeaponID native and validity checks to other natives (bug 5566) (Drifter).
|
||||||
|
- Numerous code documentation fixups (bug 5720) (Tsunami).
|
||||||
|
- Fixed cmd listener callback return behavior to match func doc (bug 5882).
|
||||||
|
|
||||||
|
Internal Changes:
|
||||||
|
|
||||||
|
- Fixed handle misuse in clientprefs plugin (bug 5805) (KyleS).
|
||||||
|
- Removed call to getchar() in debug build of compiler (bug 5626) (KyleS).
|
||||||
|
- Fixed instability issues with cloned handles (bug 5245, bug 5240) (KyleS).
|
||||||
|
- Changed extension unload order to avoid exposing finalization window (bug 5556) (KyleS).
|
||||||
|
- Call OnPluginEnd before finalizer hooks have run (bug 4519).
|
||||||
|
- Fixed potential for reading out of library bounds in MemoryUtils::FindPattern.
|
||||||
|
- Fixed typo in TF2 ext asm.c causing accidental assignment instead of compare.
|
||||||
|
- Overhauled versioning information (bug 5453).
|
||||||
|
- Changed from RemoveEdict to using the Kill input for TF2_RemoveWeapon.
|
||||||
|
- Fixed accidental assignment in each of SDKTools and sp compiler (bug 5745) (KyleS).
|
||||||
|
- Fixed potential deadlock in HandleSystem::TryAndFreeSomeHandles (bug 5665) (KyleS).
|
||||||
|
|
||||||
|
----------------------------------------------------------
|
||||||
|
SourceMod 1.4.7 [2013-02-06]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.4.7_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
|
||||||
|
- Updated support for latest Source 2009 engine changes (CS:S, DoD:S, TF2, HL2DM).
|
||||||
|
- Updated gamedata for Left 4 Dead 2, Nuclear Dawn, No More Room in Hell, Zombie Panic Source, CSPromod, GoldenEye Source, Synergy, The Hidden, and PVKII.
|
||||||
|
- Added system to block malware or illegal plugins (bug 5289).
|
||||||
|
- Fixed a potential crash when a bad entity index is passed to certain functions (bug 5539) (KyleS).
|
||||||
|
- Added an error message for when auto plugin configs fail to be created due to write error (bug 5465) (Drifter).
|
||||||
|
- Fixed an issue where a malformed plugin could cause crashes (bug 5478).
|
||||||
|
|
||||||
|
Developer Changes:
|
||||||
|
|
||||||
|
- Added new values to the TFCond TF2 conditions enum (bug 5537) (FlaminSarge).
|
||||||
|
- Updated TFHoliday TF2 holidays enum (bug 5526) (Powerlord).
|
||||||
|
- Fixed regression in SourceMod 1.3.0 causing GetEntPropEnt, GetEntDataEnt2, and GameRules_GetPropEnt to possibly return stale (incorrect) entity indexes in place of -1.
|
||||||
|
- Added support for < 32-bit unsigned sign extension to GameRules_GetProp lookup (already in GetEntProp since SM 1.4.0).
|
||||||
|
- Fixed < 32-bit unsigned sign extension in GetEntProp not being applied for array prop elements (bug 5591).
|
||||||
|
- Fixed value size auto-detection in GetEntProp and GameRules_GetProp for ep2v's new SPROP_VARINT sendprops.
|
||||||
|
- Fixed Sort_Random sort type not including first value in array sorting functions (bug 4292) (Peace-Maker).
|
||||||
|
- Fixed GameRules_SetPropVector writing data to unexpected addresses instead of to the gamerules proxy entity (bug 5592) (ProdigySim).
|
||||||
|
- Fixed VoteMenuToAll stock adding bots to list (bug 5253 (VoiDeD).
|
||||||
|
|
||||||
|
----------------------------------------------------------
|
||||||
|
SourceMod 1.4.6 [2012-09-04]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.4.6_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
|
||||||
|
- Fixed extraneous errors resulting from a bug in 1.4.5.
|
||||||
|
|
||||||
|
----------------------------------------------------------
|
||||||
|
|
||||||
|
SourceMod 1.4.5 [2012-09-03]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.4.5_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
|
||||||
|
- Updated support for latest Source 2009 engine changes (CS:S, DoD:S, TF2, HL2DM, GMod).
|
||||||
|
- Updated Nuclear Dawn, Dino D-Day, and Zombie Panic gamedata.
|
||||||
|
- Added compatibility for running on Metamod:Source 1.9.0.
|
||||||
|
- Fixed very minor memory leaks in CStrike extension (bug 5456) (KyleS).
|
||||||
|
- Fixed crash from plugins accessing netprops too early (bug 5297) (KyleS).
|
||||||
|
- Fixed crash from plugins trying to access nested datadesc members (bug 5446).
|
||||||
|
|
||||||
|
Developer Changes:
|
||||||
|
|
||||||
|
- Added new TF2 weapon and custom dmg defines.
|
||||||
|
- Added new TF2 TFHoliday value (bug 5436) (Powerlord).
|
||||||
|
- Fixed IClientListener::InterceptClientConnect not being able to properly block connections (bug 5461) (PimpinJuice).
|
||||||
|
- Fixed PrepSDKCall_SetSignature native not working with symbol names on L4D2 linux (bug 5440).
|
||||||
|
- Fixed resolution of GetProfilerTime native on non-Windows platforms.
|
||||||
|
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
SourceMod 1.4.4 [2012-07-03]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.4.4_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
|
||||||
|
- Updated support for latest Source 2009 engine changes (CS:S, DoD:S, TF2, HL2DM, GMod).
|
||||||
|
- Updated Nuclear Dawn gamedata.
|
||||||
|
- Fixed a crash that could occur when selecting an option on a clientprefs prefab menu (bug 5374).
|
||||||
|
|
||||||
|
Developer Changes:
|
||||||
|
|
||||||
|
- Added new TF2 weapon and custom dmg defines.
|
||||||
|
- Added new TF2 TFHoliday value (bug 5364) (Powerlord).
|
||||||
|
- Updated sample extension to properly fill ninvoke with INativeInvoker ptr (bug 5340) (Afronanny).
|
||||||
|
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
SourceMod 1.4.3 [2012-06-09]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.4.3_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
|
||||||
|
- Updated support for latest OrangeBox engine changes (CS:S, DoD:S, TF2, HL2DM, GMod).
|
||||||
|
- Made clientprefs attempt to reconnect to the database on map change (bug 4745).
|
||||||
|
- Log functions now respect sv_logecho (bug 5135).
|
||||||
|
- Fixed client console vote output (bug 5290, bug 5205) (FlaminSarge).
|
||||||
|
- Fixed error when reloading dependant plugins using aliased natives (bug 5302).
|
||||||
|
- Fixed intermittent crash when looking for an invalid signature (bug 5301).
|
||||||
|
- Fixed possible crash when reloading a plugin with an invalid binary (bug 5288).
|
||||||
|
- Exposed extensions list to clients (bug 5221) (VoiDeD).
|
||||||
|
- Fixed intermittent crashes in clientprefs (bug 4660).
|
||||||
|
- Fixed crash when passing an invalid entity reference to ReferenceToEntity (bug 5330).
|
||||||
|
- Fixed cstrike extension crash on shutdown (bug 5328).
|
||||||
|
- Lowered threading API think time to 20ms, making threaded MySQL queries complete faster (bug 4733).
|
||||||
|
|
||||||
|
Developer Changes:
|
||||||
|
|
||||||
|
- Fixed client serials not being unique on Windows (bug 5285).
|
||||||
|
- Fixed broken SourceTV detection on L4D1 (bug 5216).
|
||||||
|
- Fixed Float negation operator (bug 5292).
|
||||||
|
- Updated TF2 condition defines (bug 5259) (FlaminSarge).
|
||||||
|
- Adding missing SetMenuNoVoteButton native declaration (bug 4522) (GoD-Tony).
|
||||||
|
- Fixed erroneous const-qualification of name param of GetAdminUsername (bug 5267).
|
||||||
|
- Added GetGameTickCount native (bug 5209) (GoD-Tony).
|
||||||
|
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
SourceMod 1.4.2 [2011-04-13]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.4.2_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
- Updated support for latest OrangeBox engine changes (CS:S, DoD:S, TF2, HL2DM, GMod).
|
||||||
|
- Fixed regression in SourceMod 1.4.0 causing SM to cause load errors on The Ship (bug 5216).
|
||||||
|
- Fixed toggling and player lag issues with sm_drug command (bugs 5217, 5218) (FlaminSarge).
|
||||||
|
|
||||||
|
Developer Changes:
|
||||||
|
- Updated TF2-specific defines and enums (bug 5194).
|
||||||
|
- Fixed StoreToAddress always writing 32 bits and throwing an error (bug 5248) (ProdigySim).
|
||||||
|
- Fixed crash with StoreToAddress if memory wasn't writable (bug 5252) (Dr!fter).
|
||||||
|
- Fixed return value of VoteMenuToAll (bug 5254) (VoiDeD).
|
||||||
|
- Fixed bug in command lower-casing API guarantee
|
||||||
|
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
SourceMod 1.4.1 [2011-12-07]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.4.1_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
|
||||||
|
- Updated support for latest OrangeBox engine changes (CS:S, DoD:S, TF2, HL2DM, GMod).
|
||||||
|
- Added gamedata for Adrenaline Gamer 2 and No More Room in Hell.
|
||||||
|
- Fixed "not connected" error in reserve slots plugin (bug 5158) (ostrel).
|
||||||
|
- Fixed ff trigger output printing to all in triggerer's language (rather than viewer's language) (bug 5161).
|
||||||
|
- Fixed typo in one of basebans ban reasons (bug 5188).
|
||||||
|
- Fixed formatting error in Swedish "Vote Count" phrase (bug 5174).
|
||||||
|
|
||||||
|
Developer Changes:
|
||||||
|
|
||||||
|
- Fixed sp MaxClients not being updated on map changes after load (bug 5160).
|
||||||
|
- Removed GLIBC_2.7 dependency from spcomp.
|
||||||
|
- Increased buffer for sm_rcon command to fit larger responses (bug 5169).
|
||||||
|
- BaseComm now properly registers a library allowing it to be required by other plugins (bug 5156).
|
||||||
|
- Fixed TFHoliday enum values (bug 5155).
|
||||||
|
- Updated TF2_OnIsHolidayActive ret behavior to match doc (bug 5155).
|
||||||
|
- Added new TF2 deathflag and dmg custom defines (bug 5157).
|
||||||
|
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
SourceMod 1.4.0 [2011-10-28]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.4.0_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
|
||||||
|
- Added support for Max OS X (bug 4392).
|
||||||
|
- Added support for Bloody Good Time (bug 4780).
|
||||||
|
- Added support for E.Y.E Divine Cybermancy (bug 5035).
|
||||||
|
- Added gamedata for Nuclear Dawn.
|
||||||
|
- Added gamedata for International Online Soccer: Source (bug 5019).
|
||||||
|
- Added gamedata for Half-Life 2 Capture the Flag (bug 5114).
|
||||||
|
- Updated mapchooser and other base plugins with Nuclear Dawn specific fixes (bug 5117).
|
||||||
|
- Fixed ServerLang value not being read properly on startup (bug 4675).
|
||||||
|
- Added support for aliases in languages.cfg (bug 4858).
|
||||||
|
- Added output display to sm_rcon command (bug 5018).
|
||||||
|
- Flood protection bypass access can now be overridden with command name sm_flood_access (bug 4584).
|
||||||
|
- Added a reset argument to sm cvars command to revset cvar values to default (bug 5043).
|
||||||
|
- Fixed incorrect language identifiers for Chinese (both Trad. and Simplified) and Brazilian Portuguese not matching cl_language values (bug 5067).
|
||||||
|
- Added translation support for Bulgarian (bg).
|
||||||
|
- Fixed incorrect number of slots being hidden for reserve with sm_hideslots on Source 2009 with SourceTV or replay (bug 5094).
|
||||||
|
- sm_hideslots changes now take effect immediately instead of waiting until a client joins or leaves (bug 5094).
|
||||||
|
- Fixed sv_visiblemaxplayers getting stuck at previous max clients in some cases with reserves and SourceTV or replay (bug 5094).
|
||||||
|
- Removed error logging if an optional extension is not found (bug 5112).
|
||||||
|
- Fixed bots with semicolon in name being unkickable (bug 5120).
|
||||||
|
- Changed strings in ice-related funcommands to be translatable (bug 4540).
|
||||||
|
- Changed Bintools extension to use a single build for every engine (bug 4548).
|
||||||
|
|
||||||
|
Developer Changes:
|
||||||
|
- Provided native interface for basecomm (bug 2594).
|
||||||
|
- Client language detection is too late. (bug 3714) (Tony A. "GoD-Tony").
|
||||||
|
- Added ServerCommandEx native to execute server command and retrieve output (bug 3873).
|
||||||
|
- Added ability to update clientprefs cookies values on clients not currently connected (bug 3882) (databomb).
|
||||||
|
- Added library "matchmaking_ds" support to gamedata lookups (bug 4158).
|
||||||
|
- Rooted menu handles to callbacks (bug 4353).
|
||||||
|
- Fixed corner cases with ExplodeString (bug 4629). (Michael "LumiStance").
|
||||||
|
- Fixed return omission with else-after-return (bug 4852).
|
||||||
|
- Added OnConditionAdded and OnConditionRemoved forwards to TF2 extension (bug 4851).
|
||||||
|
- Added new natives and forward to the cstrike extension (bug 4732, bug 4985) (Dr!fter).
|
||||||
|
- Added WaitingForPlayers forwards to the TF2 extension (bug 4704) (CrimsonGT).
|
||||||
|
- Updated and added more TF2 condition, weapon, and damagecustom defines (multiple bug#s).
|
||||||
|
- Fixed TF2_RemoveCondition not always removing conditions (bug 4981).
|
||||||
|
- Fixed MaxClients not being updated correctly in some places with SourceTV or replay active (bug 4986).
|
||||||
|
- Fixed some vars not being marked for init on first compile pass (bug 4643).
|
||||||
|
- Increased symbol name limit to 63 characters (bug 4564) (javalia).
|
||||||
|
- Fixed crash when dynamic arrays run out of memory (bug 4632).
|
||||||
|
- Fixed a crash that could happen from looking up out-of-bounds edict or entity indexes (bug 5080).
|
||||||
|
- Fixed client serials not getting cleared on disconnect (bug 5121).
|
||||||
|
- Added error on declaring arrays that the compiler is too buggy to handle (bug 4977).
|
||||||
|
- Removed reliance on gamedata for multiple SDKTools functions in ep2 and later (bug 4899).
|
||||||
|
- Added InvalidateClient and ReconnectClient natives to SDKTools (bug 4931) (Brian "Afronanny" Simon).
|
||||||
|
- Added ability to lookup and set values on the gamerules class (bug 4983.
|
||||||
|
- BaseComm now uses AddCommandListener for chat hooks (bug 4991).
|
||||||
|
- Fixed shutdown bug in SDKTools (bug 5063).
|
||||||
|
- Fixed MM-enabled extensions continuing to load after failing MM attach (bug 5042).
|
||||||
|
- Added GetDistGainFromSoundLevel native to SDKTools (bug 5066) (javalia).
|
||||||
|
- Added CheckAccess native to check an AdminId's command access (bug 5083).
|
||||||
|
- Fixed GetEntProp not sign-extending unsigned values less than 32 bits (bug 5105).
|
||||||
|
- Fixed crashing when calling CreateEntityByName or CreateFakeClient when no map is running (now errors) (bug 5119).
|
||||||
|
- Fixed erring in kick function (e. bad translation) causing client to become unkickable until disconnect (bug 5120).
|
||||||
|
- Fixed KickClientEx not immediately kicking client if client was in kick queue (bug 5120).
|
||||||
|
- Added IsClientSourceTV and IsClientReplay natives (bug 5124).
|
||||||
|
- Added support for getting and setting individual array elements with Get/Set EntProp functions (bug 4160).
|
||||||
|
- Added support for threaded query handles to SQL_GetInsertId and SQL_GetAffectedRows (bug 4699) (Nephyrin).
|
||||||
|
- Added a GetGameRules function to ISDKTools for extensions to easily get the GameRules class pointer (bug 4707).
|
||||||
|
- Added GetMessageName to IUserMessages (bug 4573) (Zach "theY4Kman" Kanzler)
|
||||||
|
- Added HintTextMsg to IGameHelpers (bug 4950).
|
||||||
|
- Added ProcessTargetString simple filter API (bug 4404).
|
||||||
|
- Moved much functionality from core bins to logic bin (bug 4406, bug 4402).
|
||||||
|
- Fixed bogus asserts in sp compiler (bug 4486, bug 4487).
|
||||||
|
- Greatly improved sp compiler performance (~5x overall speedup) (bug 3820, bug 4493, bug 4495).
|
||||||
|
- Changed entity output detours to use CDetour (bug 4416).
|
||||||
|
- Enhanced nominations API (bug 4677) (CrimsonGT).
|
||||||
|
- Added Linux support for profiling natives (bug 4927).
|
||||||
|
- Added a new ValveCallType that allows for arbitrary |this| parameters, as well as associated features in gamedata and for reading/writing memory (bug 3520) (Downtown1).
|
||||||
|
- Updated TF2 extension to handle Valve's changes to the "holiday" system (bug 5150).
|
||||||
|
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
SourceMod 1.3.8 [2011-06-23]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.3.8_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
|
||||||
|
- Updated support for latest OrangeBox engine changes (CS:S, DoD:S, TF2, HL2DM, GMod).
|
||||||
|
- Updated support for various games, including Garry's Mod, Zombie Panic, and Dino D-Day.
|
||||||
|
- Added gamedata for Eternal Silence.
|
||||||
|
- Fixed libgcc_s.so.1 load error present on some systems (bug 4876).
|
||||||
|
- Handle leak notices now print to error log (in addition fatal log) (bug 4929).
|
||||||
|
- Translator now properly falls back on bad server language (bug 4861).
|
||||||
|
- Fixed invalid client errors from bad MaxClients value when SourceTV is late-loaded (bug 4881).
|
||||||
|
- Fixed crash on plugin unload when two commands exist with same name, different casing (bug 4698).
|
||||||
|
|
||||||
|
Developer Changes:
|
||||||
|
|
||||||
|
- Updated TF2 condition defines (bug 4916).
|
||||||
|
- Fixed var names and docs for TF2_MakeBleed native (bug 4928).
|
||||||
|
- Removed compiler double include check (bug 4863).
|
||||||
|
- Fixed plugin compile errors when using GetEntityClassname (bug 4798).
|
||||||
|
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
SourceMod 1.3.7 [2011-04-15]
|
||||||
|
|
||||||
|
URL: http://wiki.alliedmods.net/SourceMod_1.3.7_Release_Notes
|
||||||
|
|
||||||
|
User Changes:
|
||||||
|
|
||||||
|
- Updated support for latest OrangeBox engine changes (CS:S, DoD:S, TF2, HL2DM, GMod).
|
||||||
|
- Updated support for various games, including Zombie Panic, CS ProMod, Empires, and GoldenEye: Source.
|
||||||
|
- Added gamedata for Dino D-Day.
|
||||||
|
- Fix precedence of voice mute flag versus specific client overrides (bug 4826).
|
||||||
|
- Fix mistaken unhooking of voice hooks (bug 4804).
|
||||||
|
- Fixed graphical glitches with funcommands effects in L4D1 (bug 3486).
|
||||||
|
- Fixed bug in nominations that could cause "Unknown command" error (bug 4797).
|
||||||
|
- Removed tv_enable hook to fix rare max client count issue (bug 4791).
|
||||||
|
- Added missing unhooking of ClientConnect in PlayerManager (bug 4749).
|
||||||
|
- Fixed sm_rtv printing "unknown command" (bug 4730).
|
||||||
|
- Fixed voting crash when client console, chat, and SourceTV are enabled (bug 4676).
|
||||||
|
- Fixed CDetour crash in TF2 extension when last plugin using forward is unloaded (bug 4713).
|
||||||
|
|
||||||
|
Developer Changes:
|
||||||
|
|
||||||
|
- SetEntProp now marks edict state as changed (bug 4855).
|
||||||
|
- Added GetEntityClassname stock (bug 4798).
|
||||||
|
- Fix compiler hanging when #including a directory (bug 4822).
|
||||||
|
- Added GetEntityFlags and SetEntityFlags natives for better cross-engine compatibility. (bug 4809).
|
||||||
|
- Fixed ClientPrefs natives not being marked optional when REQUIRE_EXTENSIONS not defined (bug 4839).
|
||||||
|
- Changed some instances of LogMessage to LogAction (bug 4649).
|
||||||
|
- Added some new language natives (bug 4613).
|
||||||
|
- Fixed SetTeamScore not updating score on client (bug 2736).
|
||||||
|
- Raised MAXPLAYERS from 64 to 65 (bug 4490).
|
||||||
|
- Added and updated many TF2-specific defines in tf2.inc and tf2_stocks.inc.
|
||||||
|
- Fixed TF2_GetPlayerConditionFlags no longer necessarily returning all set flags (bug 4726).
|
||||||
|
- Fixed profiler flush not clearing, added 'report' and 'clear' (bug 4674).
|
||||||
|
- Fixed GetPlayerDecalFile crash on L4D and L4D2 (bug 4729).
|
||||||
|
- Fixed TF2_OnGetHoliday detour no longer firing under all circumstances (bug 4700).
|
||||||
|
- Added TF2_IsPlayerInDuel native to TF2 extension (bug 4695).
|
||||||
|
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
SourceMod 1.3.6 [2010-10-31]
|
SourceMod 1.3.6 [2010-10-31]
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
"banreasons"
|
|
||||||
{
|
|
||||||
"Abusive" "Abusive"
|
|
||||||
"Racism" "Racism"
|
|
||||||
"General cheating/exploits" "General cheating/exploits"
|
|
||||||
"Wallhack" "Wallhack"
|
|
||||||
"Aimbot" "Aimbot"
|
|
||||||
"Speedhacking" "Speedhacking"
|
|
||||||
"Mic spamming" "Mic spamming"
|
|
||||||
"Admin disrespect" "Admin disrespect"
|
|
||||||
"Camping" "Camping"
|
|
||||||
"Team killing" "Team killing"
|
|
||||||
"Unacceptable Spray" "Unacceptable Spray"
|
|
||||||
"Breaking Server Rules" "Breaking Server Rules"
|
|
||||||
"Other" "Other"
|
|
||||||
}
|
|
||||||
@@ -65,10 +65,6 @@ sm_flood_time 0.75
|
|||||||
// no reserved slot access (spectator players are selected first) is kicked to make room. Thus, the reserved
|
// no reserved slot access (spectator players are selected first) is kicked to make room. Thus, the reserved
|
||||||
// slots always remains free. The only situation where the reserved slot(s) can become properly occupied is
|
// slots always remains free. The only situation where the reserved slot(s) can become properly occupied is
|
||||||
// if the server is full with reserve slot access clients.
|
// if the server is full with reserve slot access clients.
|
||||||
// 2 : The same as sm_reserve_type 1 except once a certain number of admins have been reached, the reserve slot
|
|
||||||
// stops kicking people and anyone can join to fill the server. You can use this to simulate having a large
|
|
||||||
// number of reserved slots with sm_reserve_type 0 but with only need to have 1 slot unavailable when there are
|
|
||||||
// less admins connected.
|
|
||||||
// --
|
// --
|
||||||
// Requires: reservedslots.smx
|
// Requires: reservedslots.smx
|
||||||
// Default: 0
|
// Default: 0
|
||||||
@@ -97,7 +93,7 @@ sm_hide_slots 0
|
|||||||
// Default: 1
|
// Default: 1
|
||||||
sm_chat_mode 1
|
sm_chat_mode 1
|
||||||
|
|
||||||
// Specifies whether or not "timeleft" will automatically be triggered every
|
// Specifies whether or not "timeleft" will automaticly be triggered every
|
||||||
// x seconds. Valid values are 0 (Disabled) to 1800 seconds.
|
// x seconds. Valid values are 0 (Disabled) to 1800 seconds.
|
||||||
// --
|
// --
|
||||||
// Requires: basetriggers.smx
|
// Requires: basetriggers.smx
|
||||||
@@ -109,8 +105,8 @@ sm_timeleft_interval 0
|
|||||||
// 1 (Enabled)
|
// 1 (Enabled)
|
||||||
// --
|
// --
|
||||||
// Requires: basetriggers.smx
|
// Requires: basetriggers.smx
|
||||||
// Default: 0
|
// Default: 1
|
||||||
sm_trigger_show 0
|
sm_trigger_show 1
|
||||||
|
|
||||||
// Specifies whether or not to display vote progress to clients in the
|
// Specifies whether or not to display vote progress to clients in the
|
||||||
// "hint" box (near the bottom of the screen in most games).
|
// "hint" box (near the bottom of the screen in most games).
|
||||||
|
|||||||
+4
-25
@@ -30,12 +30,12 @@
|
|||||||
"ServerLang" "en"
|
"ServerLang" "en"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of characters to use for public chat triggers. Set an empty list to disable.
|
* String to use as the public chat trigger. Set an empty string to disable.
|
||||||
*/
|
*/
|
||||||
"PublicChatTrigger" "!"
|
"PublicChatTrigger" "!"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of characters to use for silent chat triggers. Set an empty list to disable.
|
* String to use as the silent chat trigger. Set an empty string to disable.
|
||||||
*/
|
*/
|
||||||
"SilentChatTrigger" "/"
|
"SilentChatTrigger" "/"
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
* but it does not evaluate to an actual command, it will be displayed
|
* but it does not evaluate to an actual command, it will be displayed
|
||||||
* publicly. This setting allows you to suppress accidental typings.
|
* publicly. This setting allows you to suppress accidental typings.
|
||||||
*
|
*
|
||||||
* The default value is "no". A value of "yes" will suppress.
|
* The default value is "no". A value of "yes" will supress.
|
||||||
*/
|
*/
|
||||||
"SilentFailSuppress" "no"
|
"SilentFailSuppress" "no"
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
* If Steam is down, admins will not be authenticated until Steam comes back up.
|
* If Steam is down, admins will not be authenticated until Steam comes back up.
|
||||||
* This option increases the security of your server, but is still experimental.
|
* This option increases the security of your server, but is still experimental.
|
||||||
*/
|
*/
|
||||||
"SteamAuthstringValidation" "yes"
|
"SteamAuthstringValidation" "no"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables whether SourceMod blocks known or potentially malicious plugins from loading.
|
* Enables or disables whether SourceMod blocks known or potentially malicious plugins from loading.
|
||||||
@@ -125,25 +125,4 @@
|
|||||||
* "no" - Warn about malware or illegal plugins loading
|
* "no" - Warn about malware or illegal plugins loading
|
||||||
*/
|
*/
|
||||||
"BlockBadPlugins" "yes"
|
"BlockBadPlugins" "yes"
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* passed. You can disable this feature by setting the value to "0".
|
|
||||||
*/
|
|
||||||
"SlowScriptTimeout" "8"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Per "http://blog.counter-strike.net/index.php/server_guidelines/", certain plugin
|
|
||||||
* functionality will trigger all of the game server owner's Game Server Login Tokens
|
|
||||||
* (GSLTs) to get banned when executed on a Counter-Strike: Global Offensive game server.
|
|
||||||
*
|
|
||||||
* Enabling this option will block plugins from using functionality that is known to cause this.
|
|
||||||
* This option only has any effect on CS:GO. Note that this does NOT guarantee that you cannot
|
|
||||||
* receive a ban.
|
|
||||||
*
|
|
||||||
* Disable this option at your own risk.
|
|
||||||
*/
|
|
||||||
"FollowCSGOServerGuidelines" "yes"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* Each sub-section of "Plugins" should have a title which specifies a plugin filename.
|
||||||
|
* Filenames have a wildcard of *. Appending .smx is not required.
|
||||||
|
* If the filename has no explicit path, it will be patched to any sub-path in the plugins folder.
|
||||||
|
*
|
||||||
|
* Available properties for plugins are:
|
||||||
|
* "pause" - Whether or not the plugin should load paused - "yes" or "no" (default)
|
||||||
|
* "lifetime" - Lifetime of the plugin. Options:
|
||||||
|
* "mapsync" - Plugins should be reloaded on mapchange if changed (default)
|
||||||
|
* "global" - Plugin will never be unloaded or updated
|
||||||
|
* "blockload" - Plugin will always be blocked from loading. Implicit (automatic) loads
|
||||||
|
* produce no error, but explicit (manual) loads will show an error message.
|
||||||
|
* (Options are one of "yes" or "no")
|
||||||
|
*
|
||||||
|
* You can also have an "Options" section declaring options to pass onto the JIT:
|
||||||
|
* "profile" - Bit flags for profiling level. Add flags together to reach a value.
|
||||||
|
* WARNING: Profiler is _ALPHA_ software! Use it at your own risk for
|
||||||
|
* development cycles only (not production setups).
|
||||||
|
* See the wiki article "SourceMod Profiler" for more information.
|
||||||
|
* 1 - Profile natives
|
||||||
|
* 2 - Profile callbacks
|
||||||
|
* 4 - Profile internal plugin function calls
|
||||||
|
*/
|
||||||
|
|
||||||
|
"Plugins"
|
||||||
|
{
|
||||||
|
"*"
|
||||||
|
{
|
||||||
|
"pause" "no"
|
||||||
|
"lifetime" "mapsync"
|
||||||
|
|
||||||
|
"Options"
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-34
@@ -1,42 +1,15 @@
|
|||||||
# vim: set ts=2 sw=2 tw=99 noet:
|
# vim: set ts=2 sw=2 tw=99 noet:
|
||||||
import sys
|
import sys
|
||||||
try:
|
import ambuild.runner as runner
|
||||||
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)
|
|
||||||
|
|
||||||
def make_objdir_name(p):
|
run = runner.Runner()
|
||||||
return 'obj-' + util.Platform() + '-' + p.target_arch
|
run.options.add_option('--enable-debug', action='store_const', const='1', dest='debug',
|
||||||
|
|
||||||
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('--mysql64-path', type=str, dest='mysql64_path', default=None,
|
|
||||||
help='Path to 64-bit MySQL 5')
|
|
||||||
parser.options.add_option('--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',
|
|
||||||
help='Enable debugging symbols')
|
help='Enable debugging symbols')
|
||||||
parser.options.add_option('--enable-optimize', action='store_const', const='1', dest='opt',
|
run.options.add_option('--enable-optimize', action='store_const', const='1', dest='opt',
|
||||||
help='Enable optimization')
|
help='Enable optimization')
|
||||||
parser.options.add_option('--no-mysql', action='store_false', default=True, dest='hasMySql',
|
run.options.add_option('--no-mysql', action='store_false', default=True, dest='hasMySql',
|
||||||
help='Disable building MySQL extension')
|
help='Disable building MySQL extension')
|
||||||
parser.options.add_option('-s', '--sdks', default='all', dest='sdks',
|
run.options.add_option('-s', '--sdks', default='all', dest='sdks',
|
||||||
help='Build against specified SDKs; valid args are "all", "present", or '
|
help='Build against specified SDKs; valid args are "all", "present", or '
|
||||||
'comma-delimited list of engine names (default: %default)')
|
'comma-delimited list of engine names (default: %default)')
|
||||||
parser.options.add_option('--breakpad-dump', action='store_true', dest='breakpad_dump',
|
run.Configure(sys.path[0])
|
||||||
default=False, help='Dump and upload breakpad symbols')
|
|
||||||
parser.options.add_option('--disable-auto-versioning', action='store_true', dest='disable_auto_versioning',
|
|
||||||
default=False, help='Disable the auto versioning script')
|
|
||||||
parser.Configure()
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ADTFactory.h"
|
#include "ADTFactory.h"
|
||||||
|
#include "sm_globals.h"
|
||||||
#include "ShareSys.h"
|
#include "ShareSys.h"
|
||||||
|
|
||||||
ADTFactory g_AdtFactory;
|
ADTFactory g_AdtFactory;
|
||||||
@@ -56,30 +57,32 @@ IBasicTrie *ADTFactory::CreateBasicTrie()
|
|||||||
|
|
||||||
BaseTrie::BaseTrie()
|
BaseTrie::BaseTrie()
|
||||||
{
|
{
|
||||||
|
m_pTrie = sm_trie_create();
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseTrie::~BaseTrie()
|
BaseTrie::~BaseTrie()
|
||||||
{
|
{
|
||||||
|
sm_trie_destroy(m_pTrie);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseTrie::Insert(const char *key, void *value)
|
bool BaseTrie::Insert(const char *key, void *value)
|
||||||
{
|
{
|
||||||
return map_.insert(key, value);
|
return sm_trie_insert(m_pTrie, key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseTrie::Retrieve(const char *key, void **value)
|
bool BaseTrie::Retrieve(const char *key, void **value)
|
||||||
{
|
{
|
||||||
return map_.retrieve(key, value);
|
return sm_trie_retrieve(m_pTrie, key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseTrie::Delete(const char *key)
|
bool BaseTrie::Delete(const char *key)
|
||||||
{
|
{
|
||||||
return map_.remove(key);
|
return sm_trie_delete(m_pTrie, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTrie::Clear()
|
void BaseTrie::Clear()
|
||||||
{
|
{
|
||||||
map_.clear();
|
sm_trie_clear(m_pTrie);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTrie::Destroy()
|
void BaseTrie::Destroy()
|
||||||
@@ -89,5 +92,5 @@ void BaseTrie::Destroy()
|
|||||||
|
|
||||||
bool BaseTrie::Replace(const char *key, void *value)
|
bool BaseTrie::Replace(const char *key, void *value)
|
||||||
{
|
{
|
||||||
return map_.replace(key, value);
|
return sm_trie_replace(m_pTrie, key, value);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -33,8 +33,8 @@
|
|||||||
#define _INCLUDE_SOURCEMOD_ADTFACTORY_H_
|
#define _INCLUDE_SOURCEMOD_ADTFACTORY_H_
|
||||||
|
|
||||||
#include <IADTFactory.h>
|
#include <IADTFactory.h>
|
||||||
#include "common_logic.h"
|
#include "sm_globals.h"
|
||||||
#include <sm_stringhashmap.h>
|
#include "sm_trie.h"
|
||||||
|
|
||||||
using namespace SourceMod;
|
using namespace SourceMod;
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
virtual void Clear();
|
virtual void Clear();
|
||||||
virtual void Destroy();
|
virtual void Destroy();
|
||||||
private:
|
private:
|
||||||
StringHashMap<void *> map_;
|
Trie *m_pTrie;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ADTFactory :
|
class ADTFactory :
|
||||||
+116
-101
@@ -1,113 +1,128 @@
|
|||||||
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
|
# vim: set ts=2 sw=2 tw=99 noet ft=python:
|
||||||
import os
|
import os
|
||||||
|
from ambuild.command import SymlinkCommand
|
||||||
|
|
||||||
project = SM.HL2Project(builder, 'sourcemod')
|
for i in SM.sdkInfo:
|
||||||
project.sources += [
|
sdk = SM.sdkInfo[i]
|
||||||
'MenuStyle_Valve.cpp',
|
if AMBuild.target['platform'] not in sdk['platform']:
|
||||||
'logic_bridge.cpp',
|
continue
|
||||||
'smn_entities.cpp',
|
|
||||||
'sm_stringutil.cpp',
|
|
||||||
'MenuVoting.cpp',
|
|
||||||
'smn_events.cpp',
|
|
||||||
'frame_hooks.cpp',
|
|
||||||
'smn_nextmap.cpp',
|
|
||||||
'sourcemm_api.cpp',
|
|
||||||
'ChatTriggers.cpp',
|
|
||||||
'smn_player.cpp',
|
|
||||||
'sourcemod.cpp',
|
|
||||||
'concmd_cleaner.cpp',
|
|
||||||
'HalfLife2.cpp',
|
|
||||||
'NextMap.cpp',
|
|
||||||
'ConCmdManager.cpp',
|
|
||||||
'ConVarManager.cpp',
|
|
||||||
'PlayerManager.cpp',
|
|
||||||
'TimerSys.cpp',
|
|
||||||
'CoreConfig.cpp',
|
|
||||||
'Logger.cpp',
|
|
||||||
'smn_halflife.cpp',
|
|
||||||
'smn_console.cpp',
|
|
||||||
'UserMessages.cpp',
|
|
||||||
'MenuManager.cpp',
|
|
||||||
'smn_hudtext.cpp',
|
|
||||||
'smn_usermsgs.cpp',
|
|
||||||
'MenuStyle_Base.cpp',
|
|
||||||
'smn_keyvalues.cpp',
|
|
||||||
'smn_vector.cpp',
|
|
||||||
'EventManager.cpp',
|
|
||||||
'MenuStyle_Radio.cpp',
|
|
||||||
'sm_autonatives.cpp',
|
|
||||||
'ConsoleDetours.cpp',
|
|
||||||
'vprof_tool.cpp',
|
|
||||||
'smn_commandline.cpp',
|
|
||||||
'GameHooks.cpp',
|
|
||||||
]
|
|
||||||
|
|
||||||
for sdk_name in SM.sdks:
|
name = 'sourcemod.' + sdk['ext']
|
||||||
sdk = SM.sdks[sdk_name]
|
|
||||||
for arch in SM.archs:
|
|
||||||
if not arch in sdk.platformSpec[builder.target.platform]:
|
|
||||||
continue
|
|
||||||
|
|
||||||
binary_name = 'sourcemod.' + sdk.ext
|
compiler = SM.DefaultHL2Compiler('core', i)
|
||||||
|
|
||||||
binary = SM.HL2Config(project, binary_name, sdk, arch)
|
if i == 'csgo':
|
||||||
compiler = binary.compiler
|
# Protobuf 2.3 headers have some signed/unsigned compares. I believe that it's fixed in later versions, but Valve.
|
||||||
|
if isinstance(compiler.cxx, Cpp.CompatGCC):
|
||||||
|
compiler.AddToListVar('CFLAGS', '-Wno-sign-compare')
|
||||||
|
compiler['CXXINCLUDES'].append(os.path.join(AMBuild.cache[sdk['sdk']], 'common', 'protobuf-2.3.0', 'src'))
|
||||||
|
compiler['CXXINCLUDES'].append(os.path.join(AMBuild.cache[sdk['sdk']], 'public', 'engine', 'protobuf'))
|
||||||
|
compiler['CXXINCLUDES'].append(os.path.join(AMBuild.cache[sdk['sdk']], 'public', 'game', 'shared', 'csgo', 'protobuf'))
|
||||||
|
|
||||||
compiler.cxxincludes += [
|
extension = AMBuild.AddJob(name)
|
||||||
builder.sourcePath
|
binary = Cpp.LibraryBuilder(name, AMBuild, extension, compiler)
|
||||||
]
|
SM.PreSetupHL2Job(extension, binary, i)
|
||||||
|
|
||||||
if sdk.name == 'csgo':
|
if i == 'csgo':
|
||||||
compiler.cxxincludes += [
|
if AMBuild.target['platform'] == 'linux':
|
||||||
os.path.join(sdk.path, 'common', 'protobuf-2.5.0', 'src'),
|
link = os.path.join(os.path.join(AMBuild.outputFolder, extension.workFolder), 'libprotobuf.a')
|
||||||
os.path.join(sdk.path, 'public', 'engine', 'protobuf'),
|
target = os.path.join(os.path.join(AMBuild.cache[sdk['sdk']], 'lib', 'linux32', 'release'), 'libprotobuf.a')
|
||||||
os.path.join(sdk.path, 'public', 'game', 'shared', 'csgo', 'protobuf')
|
try:
|
||||||
]
|
os.lstat(link)
|
||||||
|
except:
|
||||||
|
extension.AddCommand(SymlinkCommand(link, target))
|
||||||
|
elif AMBuild.target['platform'] == 'darwin':
|
||||||
|
link = os.path.join(os.path.join(AMBuild.outputFolder, extension.workFolder), 'libprotobuf.a')
|
||||||
|
target = os.path.join(os.path.join(AMBuild.cache[sdk['sdk']], 'lib', 'osx32', 'release'), 'libprotobuf.a')
|
||||||
|
try:
|
||||||
|
os.lstat(link)
|
||||||
|
except:
|
||||||
|
extension.AddCommand(SymlinkCommand(link, target))
|
||||||
|
elif AMBuild.target['platform'] == 'windows':
|
||||||
|
libPath = os.path.join(AMBuild.cache[sdk['sdk']], 'lib', 'win32', 'release', 'vs2010', 'libprotobuf.lib')
|
||||||
|
binary.RebuildIfNewer(libPath)
|
||||||
|
binary['POSTLINKFLAGS'].append(libPath)
|
||||||
|
|
||||||
if compiler.like('msvc'):
|
files = [
|
||||||
compiler.defines += ['_ALLOW_KEYWORD_MACROS']
|
'AdminCache.cpp',
|
||||||
if builder.target.platform == 'linux':
|
'ExtensionSys.cpp',
|
||||||
compiler.postlink += ['-lpthread', '-lrt']
|
'MenuStyle_Valve.cpp',
|
||||||
|
'logic_bridge.cpp',
|
||||||
|
'smn_entities.cpp',
|
||||||
|
'sm_stringutil.cpp',
|
||||||
|
'ADTFactory.cpp',
|
||||||
|
'ForwardSys.cpp',
|
||||||
|
'MenuVoting.cpp',
|
||||||
|
'smn_events.cpp',
|
||||||
|
'smn_menus.cpp',
|
||||||
|
'sm_trie.cpp',
|
||||||
|
'CDataPack.cpp',
|
||||||
|
'frame_hooks.cpp',
|
||||||
|
'NativeInvoker.cpp',
|
||||||
|
'smn_fakenatives.cpp',
|
||||||
|
'smn_nextmap.cpp',
|
||||||
|
'sourcemm_api.cpp',
|
||||||
|
'ChatTriggers.cpp',
|
||||||
|
'NativeOwner.cpp',
|
||||||
|
'smn_filesystem.cpp',
|
||||||
|
'smn_player.cpp',
|
||||||
|
'sourcemod.cpp',
|
||||||
|
'concmd_cleaner.cpp',
|
||||||
|
'HalfLife2.cpp',
|
||||||
|
'NextMap.cpp',
|
||||||
|
'ConCmdManager.cpp',
|
||||||
|
'HandleSys.cpp',
|
||||||
|
'ConVarManager.cpp',
|
||||||
|
'LibrarySys.cpp',
|
||||||
|
'PlayerManager.cpp',
|
||||||
|
'TimerSys.cpp',
|
||||||
|
'CoreConfig.cpp',
|
||||||
|
'Logger.cpp',
|
||||||
|
'PluginInfoDatabase.cpp',
|
||||||
|
'smn_halflife.cpp',
|
||||||
|
'PluginSys.cpp',
|
||||||
|
'smn_console.cpp',
|
||||||
|
'UserMessages.cpp',
|
||||||
|
'Database.cpp',
|
||||||
|
'MenuManager.cpp',
|
||||||
|
'smn_core.cpp',
|
||||||
|
'smn_hudtext.cpp',
|
||||||
|
'smn_usermsgs.cpp',
|
||||||
|
'DebugReporter.cpp',
|
||||||
|
'MenuStyle_Base.cpp',
|
||||||
|
'ShareSys.cpp',
|
||||||
|
'smn_database.cpp',
|
||||||
|
'smn_keyvalues.cpp',
|
||||||
|
'smn_vector.cpp',
|
||||||
|
'EventManager.cpp',
|
||||||
|
'MenuStyle_Radio.cpp',
|
||||||
|
'sm_autonatives.cpp',
|
||||||
|
'sm_srvcmds.cpp',
|
||||||
|
'ConsoleDetours.cpp'
|
||||||
|
]
|
||||||
|
|
||||||
|
if i == 'csgo':
|
||||||
|
files.append('smn_protobuf.cpp')
|
||||||
|
else:
|
||||||
|
files.append('smn_bitbuffer.cpp')
|
||||||
|
|
||||||
if sdk.name == 'csgo':
|
binary.AddSourceFiles('core', files)
|
||||||
if builder.target.platform == 'linux':
|
|
||||||
if arch == 'x86':
|
|
||||||
lib_path = os.path.join(sdk.path, 'lib', 'linux32', 'release', 'libprotobuf.a')
|
|
||||||
elif arch == 'x64':
|
|
||||||
lib_path = os.path.join(sdk.path, 'lib', 'linux64', 'release', 'libprotobuf.a')
|
|
||||||
compiler.linkflags += ['-Wl,--exclude-libs=libprotobuf.a']
|
|
||||||
elif builder.target.platform == 'mac':
|
|
||||||
if arch == 'x86':
|
|
||||||
lib_path = os.path.join(sdk.path, 'lib', 'osx32', 'release', 'libprotobuf.a')
|
|
||||||
elif arch == 'x64':
|
|
||||||
lib_path = os.path.join(sdk.path, 'lib', 'osx64', 'release', 'libprotobuf.a')
|
|
||||||
elif builder.target.platform == 'windows':
|
|
||||||
msvc_ver = compiler.version
|
|
||||||
vs_year = ''
|
|
||||||
if msvc_ver == 1800:
|
|
||||||
vs_year = '2013'
|
|
||||||
elif 1900 <= msvc_ver < 2000:
|
|
||||||
vs_year = '2015'
|
|
||||||
else:
|
|
||||||
raise Exception('Cannot find libprotobuf for MSVC version "' + str(compiler.version) + '"')
|
|
||||||
|
|
||||||
if 'DEBUG' in compiler.defines:
|
if i == 'csgo':
|
||||||
lib_path = os.path.join(sdk.path, 'lib', 'win32', 'debug', 'vs' + vs_year, 'libprotobuf.lib')
|
files = [
|
||||||
else:
|
os.path.join('public', 'engine', 'protobuf', 'netmessages.pb.cc'),
|
||||||
lib_path = os.path.join(sdk.path, 'lib', 'win32', 'release', 'vs' + vs_year, 'libprotobuf.lib')
|
os.path.join('public', 'game', 'shared', 'csgo', 'protobuf', 'cstrike15_usermessages.pb.cc'),
|
||||||
compiler.linkflags.insert(0, binary.Dep(lib_path))
|
os.path.join('public', 'game', 'shared', 'csgo', 'protobuf', 'cstrike15_usermessage_helpers.cpp'),
|
||||||
|
]
|
||||||
if sdk.name == 'csgo':
|
binary.AddSourceFiles(AMBuild.cache[sdk['sdk']], files)
|
||||||
binary.sources += ['smn_protobuf.cpp']
|
|
||||||
else:
|
|
||||||
binary.sources += ['smn_bitbuffer.cpp']
|
|
||||||
|
|
||||||
if sdk.name == 'csgo':
|
SM.PostSetupHL2Job(extension, binary, i)
|
||||||
binary.sources += [
|
|
||||||
os.path.join(sdk.path, 'public', 'engine', 'protobuf', 'netmessages.pb.cc'),
|
if i == 'csgo':
|
||||||
os.path.join(sdk.path, 'public', 'game', 'shared', 'csgo', 'protobuf', 'cstrike15_usermessages.pb.cc'),
|
if AMBuild.target['platform'] in ['linux', 'darwin']:
|
||||||
os.path.join(sdk.path, 'public', 'game', 'shared', 'csgo', 'protobuf', 'cstrike15_usermessage_helpers.cpp'),
|
binary.AddObjectFiles(['libprotobuf.a'])
|
||||||
]
|
|
||||||
|
SM.AutoVersion('core', binary)
|
||||||
SM.binaries += builder.Add(project)
|
SM.ExtractDebugInfo(extension, binary)
|
||||||
|
binary.SendToJob()
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,231 +1,208 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||||
* Free Software Foundation.
|
* Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
* details.
|
* details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along with
|
* You should have received a copy of the GNU General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
* 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
|
* 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
|
* "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
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||||
* this exception to all derivative works. AlliedModders LLC defines further
|
* this exception to all derivative works. AlliedModders LLC defines further
|
||||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||||
* or <http://www.sourcemod.net/license.php>.
|
* or <http://www.sourcemod.net/license.php>.
|
||||||
*
|
*
|
||||||
* Version: $Id$
|
* Version: $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_ADMINCACHE_H_
|
#ifndef _INCLUDE_SOURCEMOD_ADMINCACHE_H_
|
||||||
#define _INCLUDE_SOURCEMOD_ADMINCACHE_H_
|
#define _INCLUDE_SOURCEMOD_ADMINCACHE_H_
|
||||||
|
|
||||||
#include "common_logic.h"
|
#include "sm_memtable.h"
|
||||||
#include <IAdminSystem.h>
|
#include <sm_trie.h>
|
||||||
#include "sm_memtable.h"
|
#include <sh_list.h>
|
||||||
#include <sm_trie.h>
|
#include <sh_string.h>
|
||||||
#include <sh_list.h>
|
#include <IAdminSystem.h>
|
||||||
#include <sh_string.h>
|
#include "sm_globals.h"
|
||||||
#include <IForwardSys.h>
|
#include <IForwardSys.h>
|
||||||
#include <sm_stringhashmap.h>
|
|
||||||
#include <sm_namehashset.h>
|
using namespace SourceHook;
|
||||||
|
|
||||||
using namespace SourceHook;
|
#define GRP_MAGIC_SET 0xDEADFADE
|
||||||
|
#define GRP_MAGIC_UNSET 0xFACEFACE
|
||||||
#define GRP_MAGIC_SET 0xDEADFADE
|
#define USR_MAGIC_SET 0xDEADFACE
|
||||||
#define GRP_MAGIC_UNSET 0xFACEFACE
|
#define USR_MAGIC_UNSET 0xFADEDEAD
|
||||||
#define USR_MAGIC_SET 0xDEADFACE
|
|
||||||
#define USR_MAGIC_UNSET 0xFADEDEAD
|
struct AdminGroup
|
||||||
|
{
|
||||||
typedef StringHashMap<OverrideRule> OverrideMap;
|
uint32_t magic; /* Magic flag, for memory validation (ugh) */
|
||||||
|
unsigned int immunity_level; /* Immunity level */
|
||||||
struct AdminGroup
|
/* Immune from target table (-1 = nonexistent)
|
||||||
{
|
* [0] = number of entries
|
||||||
uint32_t magic; /* Magic flag, for memory validation (ugh) */
|
* [1...N] = immune targets
|
||||||
unsigned int immunity_level; /* Immunity level */
|
*/
|
||||||
/* Immune from target table (-1 = nonexistent)
|
int immune_table;
|
||||||
* [0] = number of entries
|
Trie *pCmdTable; /* Command override table (can be NULL) */
|
||||||
* [1...N] = immune targets
|
Trie *pCmdGrpTable; /* Command group override table (can be NULL) */
|
||||||
*/
|
int next_grp; /* Next group in the chain */
|
||||||
int immune_table;
|
int prev_grp; /* Previous group in the chain */
|
||||||
OverrideMap *pCmdTable; /* Command override table (can be NULL) */
|
int nameidx; /* Name */
|
||||||
OverrideMap *pCmdGrpTable; /* Command group override table (can be NULL) */
|
FlagBits addflags; /* Additive flags */
|
||||||
int next_grp; /* Next group in the chain */
|
};
|
||||||
int prev_grp; /* Previous group in the chain */
|
|
||||||
int nameidx; /* Name */
|
struct AuthMethod
|
||||||
FlagBits addflags; /* Additive flags */
|
{
|
||||||
};
|
String name;
|
||||||
|
Trie *table;
|
||||||
struct AuthMethod
|
};
|
||||||
{
|
|
||||||
String name;
|
struct UserAuth
|
||||||
StringHashMap<AdminId> identities;
|
{
|
||||||
|
unsigned int index; /* Index into auth table */
|
||||||
AuthMethod(const char *name)
|
int identidx; /* Index into the string table */
|
||||||
: name(name)
|
};
|
||||||
{
|
|
||||||
}
|
struct AdminUser
|
||||||
|
{
|
||||||
static inline bool matches(const char *name, const AuthMethod *method)
|
uint32_t magic; /* Magic flag, for memory validation */
|
||||||
{
|
FlagBits flags; /* Flags */
|
||||||
return strcmp(name, method->name.c_str()) == 0;
|
FlagBits eflags; /* Effective flags */
|
||||||
}
|
int nameidx; /* Name index */
|
||||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
int password; /* Password index */
|
||||||
{
|
unsigned int grp_count; /* Number of groups */
|
||||||
return key.hash();
|
unsigned int grp_size; /* Size of groups table */
|
||||||
}
|
int grp_table; /* Group table itself */
|
||||||
};
|
int next_user; /* Next user in the list */
|
||||||
|
int prev_user; /* Previous user in the list */
|
||||||
struct UserAuth
|
UserAuth auth; /* Auth method for this user */
|
||||||
{
|
unsigned int immunity_level; /* Immunity level */
|
||||||
unsigned int index; /* Index into auth table */
|
unsigned int serialchange; /* Serial # for changes */
|
||||||
int identidx; /* Index into the string table */
|
};
|
||||||
};
|
|
||||||
|
class AdminCache :
|
||||||
struct AdminUser
|
public IAdminSystem,
|
||||||
{
|
public SMGlobalClass
|
||||||
uint32_t magic; /* Magic flag, for memory validation */
|
{
|
||||||
FlagBits flags; /* Flags */
|
public:
|
||||||
FlagBits eflags; /* Effective flags */
|
AdminCache();
|
||||||
int nameidx; /* Name index */
|
~AdminCache();
|
||||||
int password; /* Password index */
|
public: //SMGlobalClass
|
||||||
unsigned int grp_count; /* Number of groups */
|
void OnSourceModStartup(bool late);
|
||||||
unsigned int grp_size; /* Size of groups table */
|
void OnSourceModAllInitialized();
|
||||||
int grp_table; /* Group table itself */
|
void OnSourceModLevelChange(const char *mapName);
|
||||||
int next_user; /* Next user in the list */
|
void OnSourceModShutdown();
|
||||||
int prev_user; /* Previous user in the list */
|
void OnSourceModPluginsLoaded();
|
||||||
UserAuth auth; /* Auth method for this user */
|
public: //IAdminSystem
|
||||||
unsigned int immunity_level; /* Immunity level */
|
/** Command cache stuff */
|
||||||
unsigned int serialchange; /* Serial # for changes */
|
void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags);
|
||||||
};
|
bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *flags);
|
||||||
|
void UnsetCommandOverride(const char *cmd, OverrideType type);
|
||||||
class AdminCache :
|
/** Group cache stuff */
|
||||||
public IAdminSystem,
|
GroupId AddGroup(const char *group_name);
|
||||||
public SMGlobalClass
|
GroupId FindGroupByName(const char *group_name);
|
||||||
{
|
void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled);
|
||||||
public:
|
bool GetGroupAddFlag(GroupId id, AdminFlag flag);
|
||||||
AdminCache();
|
FlagBits GetGroupAddFlags(GroupId id);
|
||||||
~AdminCache();
|
void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled);
|
||||||
public: //SMGlobalClass
|
bool GetGroupGenericImmunity(GroupId id, ImmunityType type);
|
||||||
void OnSourceModStartup(bool late);
|
void InvalidateGroup(GroupId id);
|
||||||
void OnSourceModAllInitialized();
|
void AddGroupImmunity(GroupId id, GroupId other_id);
|
||||||
void OnSourceModLevelChange(const char *mapName);
|
unsigned int GetGroupImmunityCount(GroupId id);
|
||||||
void OnSourceModShutdown();
|
GroupId GetGroupImmunity(GroupId id, unsigned int number);
|
||||||
void OnSourceModPluginsLoaded();
|
void AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule);
|
||||||
public: //IAdminSystem
|
bool GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule);
|
||||||
/** Command cache stuff */
|
void DumpAdminCache(AdminCachePart part, bool rebuild);
|
||||||
void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags);
|
void AddAdminListener(IAdminListener *pListener);
|
||||||
bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *flags);
|
void RemoveAdminListener(IAdminListener *pListener);
|
||||||
void UnsetCommandOverride(const char *cmd, OverrideType type);
|
/** User stuff */
|
||||||
/** Group cache stuff */
|
void RegisterAuthIdentType(const char *name);
|
||||||
GroupId AddGroup(const char *group_name);
|
AdminId CreateAdmin(const char *name);
|
||||||
GroupId FindGroupByName(const char *group_name);
|
const char *GetAdminName(AdminId id);
|
||||||
void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled);
|
bool BindAdminIdentity(AdminId id, const char *auth, const char *ident);
|
||||||
bool GetGroupAddFlag(GroupId id, AdminFlag flag);
|
virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled);
|
||||||
FlagBits GetGroupAddFlags(GroupId id);
|
bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode);
|
||||||
void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled);
|
FlagBits GetAdminFlags(AdminId id, AccessMode mode);
|
||||||
bool GetGroupGenericImmunity(GroupId id, ImmunityType type);
|
bool AdminInheritGroup(AdminId id, GroupId gid);
|
||||||
void InvalidateGroup(GroupId id);
|
unsigned int GetAdminGroupCount(AdminId id);
|
||||||
void AddGroupImmunity(GroupId id, GroupId other_id);
|
GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name);
|
||||||
unsigned int GetGroupImmunityCount(GroupId id);
|
void SetAdminPassword(AdminId id, const char *password);
|
||||||
GroupId GetGroupImmunity(GroupId id, unsigned int number);
|
const char *GetAdminPassword(AdminId id);
|
||||||
void AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule);
|
AdminId FindAdminByIdentity(const char *auth, const char *identity);
|
||||||
bool GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule);
|
bool InvalidateAdmin(AdminId id);
|
||||||
void DumpAdminCache(AdminCachePart part, bool rebuild);
|
unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize);
|
||||||
void AddAdminListener(IAdminListener *pListener);
|
FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize);
|
||||||
void RemoveAdminListener(IAdminListener *pListener);
|
FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags);
|
||||||
/** User stuff */
|
unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize);
|
||||||
void RegisterAuthIdentType(const char *name);
|
bool CheckAdminFlags(AdminId id, FlagBits bits);
|
||||||
AdminId CreateAdmin(const char *name);
|
bool CanAdminTarget(AdminId id, AdminId target);
|
||||||
const char *GetAdminName(AdminId id);
|
void SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits);
|
||||||
bool BindAdminIdentity(AdminId id, const char *auth, const char *ident);
|
bool FindFlag(const char *str, AdminFlag *pFlag);
|
||||||
virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled);
|
bool FindFlag(char c, AdminFlag *pAdmFlag);
|
||||||
bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode);
|
FlagBits ReadFlagString(const char *flags, const char **end);
|
||||||
FlagBits GetAdminFlags(AdminId id, AccessMode mode);
|
size_t FillFlagString(FlagBits bits, char *buffer, size_t maxlen);
|
||||||
bool AdminInheritGroup(AdminId id, GroupId gid);
|
unsigned int GetAdminSerialChange(AdminId id);
|
||||||
unsigned int GetAdminGroupCount(AdminId id);
|
bool CanAdminUseCommand(int client, const char *cmd);
|
||||||
GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name);
|
const char *GetGroupName(GroupId gid);
|
||||||
void SetAdminPassword(AdminId id, const char *password);
|
unsigned int SetGroupImmunityLevel(GroupId gid, unsigned int level);
|
||||||
const char *GetAdminPassword(AdminId id);
|
unsigned int GetGroupImmunityLevel(GroupId gid);
|
||||||
AdminId FindAdminByIdentity(const char *auth, const char *identity);
|
unsigned int SetAdminImmunityLevel(AdminId id, unsigned int level);
|
||||||
bool InvalidateAdmin(AdminId id);
|
unsigned int GetAdminImmunityLevel(AdminId id);
|
||||||
unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize);
|
bool CheckAccess(int client,
|
||||||
FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize);
|
const char *cmd,
|
||||||
FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags);
|
FlagBits flags,
|
||||||
unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize);
|
bool override_only);
|
||||||
bool CheckAdminFlags(AdminId id, FlagBits bits);
|
bool FindFlagChar(AdminFlag flag, char *c);
|
||||||
bool CanAdminTarget(AdminId id, AdminId target);
|
public:
|
||||||
void SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits);
|
bool IsValidAdmin(AdminId id);
|
||||||
bool FindFlag(const char *str, AdminFlag *pFlag);
|
void DumpCache(FILE *fp);
|
||||||
bool FindFlag(char c, AdminFlag *pAdmFlag);
|
AdminGroup *GetGroup(GroupId gid);
|
||||||
FlagBits ReadFlagString(const char *flags, const char **end);
|
AdminUser *GetUser(AdminId id);
|
||||||
size_t FillFlagString(FlagBits bits, char *buffer, size_t maxlen);
|
const char *GetString(int idx);
|
||||||
unsigned int GetAdminSerialChange(AdminId id);
|
private:
|
||||||
bool CanAdminUseCommand(int client, const char *cmd);
|
void _UnsetCommandOverride(const char *cmd);
|
||||||
const char *GetGroupName(GroupId gid);
|
void _UnsetCommandGroupOverride(const char *group);
|
||||||
unsigned int SetGroupImmunityLevel(GroupId gid, unsigned int level);
|
void InvalidateGroupCache();
|
||||||
unsigned int GetGroupImmunityLevel(GroupId gid);
|
void InvalidateAdminCache(bool unlink_admins);
|
||||||
unsigned int SetAdminImmunityLevel(AdminId id, unsigned int level);
|
void DumpCommandOverrideCache(OverrideType type);
|
||||||
unsigned int GetAdminImmunityLevel(AdminId id);
|
Trie *GetMethodByIndex(unsigned int index);
|
||||||
bool CheckAccess(int client,
|
bool GetMethodIndex(const char *name, unsigned int *_index);
|
||||||
const char *cmd,
|
const char *GetMethodName(unsigned int index);
|
||||||
FlagBits flags,
|
void NameFlag(const char *str, AdminFlag flag);
|
||||||
bool override_only);
|
public:
|
||||||
bool FindFlagChar(AdminFlag flag, char *c);
|
BaseStringTable *m_pStrings;
|
||||||
bool IsValidAdmin(AdminId id);
|
BaseMemTable *m_pMemory;
|
||||||
bool CheckClientCommandAccess(int client, const char *cmd, FlagBits cmdflags);
|
Trie *m_pCmdOverrides;
|
||||||
public:
|
Trie *m_pCmdGrpOverrides;
|
||||||
bool DumpCache(const char *filename);
|
int m_FirstGroup;
|
||||||
AdminGroup *GetGroup(GroupId gid);
|
int m_LastGroup;
|
||||||
AdminUser *GetUser(AdminId id);
|
int m_FreeGroupList;
|
||||||
const char *GetString(int idx);
|
Trie *m_pGroups;
|
||||||
bool CheckAdminCommandAccess(AdminId adm, const char *cmd, FlagBits flags);
|
List<IAdminListener *> m_hooks;
|
||||||
private:
|
List<AuthMethod> m_AuthMethods;
|
||||||
void _UnsetCommandOverride(const char *cmd);
|
Trie *m_pAuthTables;
|
||||||
void _UnsetCommandGroupOverride(const char *group);
|
IForward *m_pCacheFwd;
|
||||||
void InvalidateGroupCache();
|
int m_FirstUser;
|
||||||
void InvalidateAdminCache(bool unlink_admins);
|
int m_LastUser;
|
||||||
void DumpCommandOverrideCache(OverrideType type);
|
int m_FreeUserList;
|
||||||
AuthMethod *GetMethodByIndex(unsigned int index);
|
bool m_InvalidatingAdmins;
|
||||||
bool GetMethodIndex(const char *name, unsigned int *_index);
|
bool m_destroying;
|
||||||
const char *GetMethodName(unsigned int index);
|
Trie *m_pLevelNames;
|
||||||
void NameFlag(const char *str, AdminFlag flag);
|
};
|
||||||
bool GetUnifiedSteamIdentity(const char *ident, char *out, size_t maxlen);
|
|
||||||
public:
|
extern AdminCache g_Admins;
|
||||||
typedef StringHashMap<FlagBits> FlagMap;
|
|
||||||
|
#endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_
|
||||||
BaseStringTable *m_pStrings;
|
|
||||||
BaseMemTable *m_pMemory;
|
|
||||||
FlagMap m_CmdOverrides;
|
|
||||||
FlagMap m_CmdGrpOverrides;
|
|
||||||
int m_FirstGroup;
|
|
||||||
int m_LastGroup;
|
|
||||||
int m_FreeGroupList;
|
|
||||||
StringHashMap<GroupId> m_Groups;
|
|
||||||
List<IAdminListener *> m_hooks;
|
|
||||||
List<AuthMethod *> m_AuthMethods;
|
|
||||||
NameHashSet<AuthMethod *> m_AuthTables;
|
|
||||||
IForward *m_pCacheFwd;
|
|
||||||
int m_FirstUser;
|
|
||||||
int m_LastUser;
|
|
||||||
int m_FreeUserList;
|
|
||||||
bool m_InvalidatingAdmins;
|
|
||||||
bool m_destroying;
|
|
||||||
StringHashMap<AdminFlag> m_LevelNames;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern AdminCache g_Admins;
|
|
||||||
|
|
||||||
#endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_
|
|
||||||
@@ -0,0 +1,259 @@
|
|||||||
|
/**
|
||||||
|
* vim: set ts=4 :
|
||||||
|
* =============================================================================
|
||||||
|
* SourceMod
|
||||||
|
* Copyright (C) 2004-2008 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "CDataPack.h"
|
||||||
|
|
||||||
|
#define DATAPACK_INITIAL_SIZE 512
|
||||||
|
|
||||||
|
CDataPack::CDataPack()
|
||||||
|
{
|
||||||
|
m_pBase = (char *)malloc(DATAPACK_INITIAL_SIZE);
|
||||||
|
m_capacity = DATAPACK_INITIAL_SIZE;
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
CDataPack::~CDataPack()
|
||||||
|
{
|
||||||
|
free(m_pBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
m_capacity *= 2;
|
||||||
|
m_pBase = (char *)realloc(m_pBase, m_capacity);
|
||||||
|
m_curptr = m_pBase + pos;
|
||||||
|
} while (m_curptr - m_pBase + typesize > m_capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDataPack::ResetSize()
|
||||||
|
{
|
||||||
|
m_size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t CDataPack::CreateMemory(size_t size, void **addr)
|
||||||
|
{
|
||||||
|
CheckSize(sizeof(size_t) + size);
|
||||||
|
size_t pos = m_curptr - m_pBase;
|
||||||
|
|
||||||
|
*(size_t *)m_curptr = size;
|
||||||
|
m_curptr += sizeof(size_t);
|
||||||
|
|
||||||
|
if (addr)
|
||||||
|
{
|
||||||
|
*addr = m_curptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_curptr += size;
|
||||||
|
m_size += sizeof(size_t) + size;
|
||||||
|
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDataPack::PackCell(cell_t cell)
|
||||||
|
{
|
||||||
|
CheckSize(sizeof(size_t) + sizeof(cell_t));
|
||||||
|
|
||||||
|
*(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(size_t) + sizeof(cell_t);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDataPack::PackFloat(float val)
|
||||||
|
{
|
||||||
|
CheckSize(sizeof(size_t) + sizeof(float));
|
||||||
|
|
||||||
|
*(size_t *)m_curptr = sizeof(float);
|
||||||
|
m_curptr += sizeof(size_t);
|
||||||
|
|
||||||
|
*(float *)m_curptr = val;
|
||||||
|
m_curptr += sizeof(float);
|
||||||
|
|
||||||
|
m_size += sizeof(size_t) + sizeof(float);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDataPack::PackString(const char *string)
|
||||||
|
{
|
||||||
|
size_t len = strlen(string);
|
||||||
|
size_t maxsize = sizeof(size_t) + len + 1;
|
||||||
|
CheckSize(maxsize);
|
||||||
|
|
||||||
|
// Pack the string length first for buffer overrun checking.
|
||||||
|
*(size_t *)m_curptr = len;
|
||||||
|
m_curptr += sizeof(size_t);
|
||||||
|
|
||||||
|
// Now pack the string.
|
||||||
|
memcpy(m_curptr, string, len);
|
||||||
|
m_curptr[len] = '\0';
|
||||||
|
m_curptr += len + 1;
|
||||||
|
|
||||||
|
m_size += maxsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDataPack::Reset() const
|
||||||
|
{
|
||||||
|
m_curptr = m_pBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t CDataPack::GetPosition() const
|
||||||
|
{
|
||||||
|
return static_cast<size_t>(m_curptr - m_pBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CDataPack::SetPosition(size_t pos) const
|
||||||
|
{
|
||||||
|
if (pos > m_size-1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_curptr = m_pBase + pos;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
cell_t CDataPack::ReadCell() const
|
||||||
|
{
|
||||||
|
if (!IsReadable(sizeof(size_t) + sizeof(cell_t)))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
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(size_t) + sizeof(float)))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
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(size_t)))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -1,77 +1,71 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2017 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||||
* Free Software Foundation.
|
* Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
* details.
|
* details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along with
|
* You should have received a copy of the GNU General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
* 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
|
* 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
|
* "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
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||||
* this exception to all derivative works. AlliedModders LLC defines further
|
* this exception to all derivative works. AlliedModders LLC defines further
|
||||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||||
* or <http://www.sourcemod.net/license.php>.
|
* or <http://www.sourcemod.net/license.php>.
|
||||||
*
|
*
|
||||||
* Version: $Id$
|
* Version: $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sp_vm_api.h"
|
#ifndef _INCLUDE_SOURCEMOD_CDATAPACK_H_
|
||||||
#include <am-vector.h>
|
#define _INCLUDE_SOURCEMOD_CDATAPACK_H_
|
||||||
#include <am-string.h>
|
|
||||||
|
#include <IDataPack.h>
|
||||||
using namespace SourcePawn;
|
|
||||||
|
using namespace SourceMod;
|
||||||
/**
|
|
||||||
* Frame iterator cache which is safe for plugins to hold handles to,
|
class CDataPack : public IDataPack
|
||||||
* unlike what you'd recieve from IPluginContext::CreateFrameIterator.
|
{
|
||||||
*/
|
public:
|
||||||
class SafeFrameIterator
|
CDataPack();
|
||||||
{
|
~CDataPack();
|
||||||
public:
|
public: //IDataReader
|
||||||
|
void Reset() const;
|
||||||
/**
|
size_t GetPosition() const;
|
||||||
* Struct which holds all of the cached values for each individual frame.
|
bool SetPosition(size_t pos) const;
|
||||||
*/
|
cell_t ReadCell() const;
|
||||||
struct FrameInfo
|
float ReadFloat() const;
|
||||||
{
|
bool IsReadable(size_t bytes) const;
|
||||||
ke::AString FunctionName;
|
const char *ReadString(size_t *len) const;
|
||||||
ke::AString FilePath;
|
void *GetMemory() const;
|
||||||
unsigned LineNumber;
|
void *ReadMemory(size_t *size) const;
|
||||||
|
public: //IDataPack
|
||||||
FrameInfo(IFrameIterator *it)
|
void ResetSize();
|
||||||
{
|
void PackCell(cell_t cell);
|
||||||
LineNumber = it->LineNumber();
|
void PackFloat(float val);
|
||||||
|
void PackString(const char *string);
|
||||||
FunctionName = it->FunctionName();
|
size_t CreateMemory(size_t size, void **addr);
|
||||||
FilePath = it->FilePath();
|
public:
|
||||||
}
|
void Initialize();
|
||||||
};
|
private:
|
||||||
|
void CheckSize(size_t sizetype);
|
||||||
SafeFrameIterator(IFrameIterator *);
|
private:
|
||||||
|
char *m_pBase;
|
||||||
bool Done() const;
|
mutable char *m_curptr;
|
||||||
bool Next();
|
size_t m_capacity;
|
||||||
void Reset();
|
size_t m_size;
|
||||||
|
};
|
||||||
int LineNumber() const;
|
|
||||||
const char *FunctionName() const;
|
#endif //_INCLUDE_SOURCEMOD_CDATAPACK_H_
|
||||||
const char *FilePath() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
size_t current;
|
|
||||||
ke::Vector<FrameInfo> frames;
|
|
||||||
};
|
|
||||||
@@ -81,17 +81,11 @@ inline int CellRecipientFilter::GetRecipientCount() const
|
|||||||
|
|
||||||
inline int CellRecipientFilter::GetRecipientIndex(int slot) const
|
inline int CellRecipientFilter::GetRecipientIndex(int slot) const
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
if ((slot < 0) || (slot >= GetRecipientCount()))
|
if ((slot < 0) || (slot >= GetRecipientCount()))
|
||||||
{
|
{
|
||||||
ret = -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
return static_cast<int>(m_Players[slot]);
|
||||||
{
|
|
||||||
ret = static_cast<int>(m_Players[slot]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void CellRecipientFilter::SetToInit(bool isinitmsg)
|
inline void CellRecipientFilter::SetToInit(bool isinitmsg)
|
||||||
|
|||||||
+199
-174
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
* This program is free software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||||
* Free Software Foundation.
|
* Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
@@ -36,21 +36,37 @@
|
|||||||
#include "PlayerManager.h"
|
#include "PlayerManager.h"
|
||||||
#include "HalfLife2.h"
|
#include "HalfLife2.h"
|
||||||
#include "logic_bridge.h"
|
#include "logic_bridge.h"
|
||||||
#include "sourcemod.h"
|
|
||||||
#include "provider.h"
|
/* :HACKHACK: We can't SH_DECL here because ConCmdManager.cpp does.
|
||||||
#include <bridge/include/ILogger.h>
|
* While the OB build only runs on MM:S 1.6.0+ (SH 5+), the older one
|
||||||
#include <amtl/am-string.h>
|
* can technically be compiled against any MM:S version after 1.4.2.
|
||||||
|
*/
|
||||||
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
|
extern bool __SourceHook_FHRemoveConCommandDispatch(void *, bool, class fastdelegate::FastDelegate1<const CCommand &, void>);
|
||||||
|
extern int __SourceHook_FHAddConCommandDispatch(void *, ISourceHook::AddHookMode, bool, class fastdelegate::FastDelegate1<const CCommand &, void>);
|
||||||
|
#else
|
||||||
|
extern bool __SourceHook_FHRemoveConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
|
||||||
|
#if SH_IMPL_VERSION >= 5
|
||||||
|
extern int __SourceHook_FHAddConCommandDispatch(void *, ISourceHook::AddHookMode, bool, class fastdelegate::FastDelegate0<void>);
|
||||||
|
#elif SH_IMPL_VERSION == 4
|
||||||
|
extern int __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
|
||||||
|
#elif SH_IMPL_VERSION == 3
|
||||||
|
extern bool __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
|
||||||
|
#endif //SH_IMPL_VERSION
|
||||||
|
#endif //SE_ORANGEBOX
|
||||||
|
|
||||||
ChatTriggers g_ChatTriggers;
|
ChatTriggers g_ChatTriggers;
|
||||||
bool g_bSupressSilentFails = false;
|
bool g_bSupressSilentFails = false;
|
||||||
|
|
||||||
ChatTriggers::ChatTriggers() : m_bWillProcessInPost(false),
|
ChatTriggers::ChatTriggers() : m_pSayCmd(NULL), m_bWillProcessInPost(false),
|
||||||
m_ReplyTo(SM_REPLY_CONSOLE), m_ArgSBackup(NULL)
|
m_ReplyTo(SM_REPLY_CONSOLE)
|
||||||
{
|
{
|
||||||
m_PubTrigger = "!";
|
m_PubTrigger = sm_strdup("!");
|
||||||
m_PrivTrigger = "/";
|
m_PrivTrigger = sm_strdup("/");
|
||||||
|
m_PubTriggerSize = 1;
|
||||||
|
m_PrivTriggerSize = 1;
|
||||||
m_bIsChatTrigger = false;
|
m_bIsChatTrigger = false;
|
||||||
m_bPluginIgnored = true;
|
m_bPluginIgnored = false;
|
||||||
#if SOURCE_ENGINE == SE_EPISODEONE
|
#if SOURCE_ENGINE == SE_EPISODEONE
|
||||||
m_bIsINS = false;
|
m_bIsINS = false;
|
||||||
#endif
|
#endif
|
||||||
@@ -58,47 +74,30 @@ ChatTriggers::ChatTriggers() : m_bWillProcessInPost(false),
|
|||||||
|
|
||||||
ChatTriggers::~ChatTriggers()
|
ChatTriggers::~ChatTriggers()
|
||||||
{
|
{
|
||||||
delete [] m_ArgSBackup;
|
delete [] m_PubTrigger;
|
||||||
m_ArgSBackup = NULL;
|
m_PubTrigger = NULL;
|
||||||
|
delete [] m_PrivTrigger;
|
||||||
|
m_PrivTrigger = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatTriggers::SetChatTrigger(ChatTriggerType type, const char *value)
|
ConfigResult ChatTriggers::OnSourceModConfigChanged(const char *key,
|
||||||
{
|
const char *value,
|
||||||
ke::AutoPtr<char[]> filtered(new char[strlen(value) + 1]);
|
|
||||||
|
|
||||||
const char *src = value;
|
|
||||||
char *dest = filtered.get();
|
|
||||||
char c;
|
|
||||||
while ((c = *src++) != '\0') {
|
|
||||||
if (c <= ' ' || c == '"' || c == '\'' || (c >= '0' && c <= '9') || c == ';' || (c >= 'A' && c <= 'Z') || c == '\\' || (c >= 'a' && c <= 'z') || c >= 0x7F) {
|
|
||||||
logger->LogError("Ignoring %s chat trigger character '%c', not in valid set: %s", (type == ChatTrigger_Private ? "silent" : "public"), c, "!#$%&()*+,-./:<=>?@[]^_`{|}~");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
*dest++ = c;
|
|
||||||
}
|
|
||||||
*dest = '\0';
|
|
||||||
|
|
||||||
if (type == ChatTrigger_Private) {
|
|
||||||
m_PrivTrigger = filtered.get();
|
|
||||||
} else {
|
|
||||||
m_PubTrigger = filtered.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigResult ChatTriggers::OnSourceModConfigChanged(const char *key,
|
|
||||||
const char *value,
|
|
||||||
ConfigSource source,
|
ConfigSource source,
|
||||||
char *error,
|
char *error,
|
||||||
size_t maxlength)
|
size_t maxlength)
|
||||||
{
|
{
|
||||||
if (strcmp(key, "PublicChatTrigger") == 0)
|
if (strcmp(key, "PublicChatTrigger") == 0)
|
||||||
{
|
{
|
||||||
SetChatTrigger(ChatTrigger_Public, value);
|
delete [] m_PubTrigger;
|
||||||
|
m_PubTrigger = sm_strdup(value);
|
||||||
|
m_PubTriggerSize = strlen(m_PubTrigger);
|
||||||
return ConfigResult_Accept;
|
return ConfigResult_Accept;
|
||||||
}
|
}
|
||||||
else if (strcmp(key, "SilentChatTrigger") == 0)
|
else if (strcmp(key, "SilentChatTrigger") == 0)
|
||||||
{
|
{
|
||||||
SetChatTrigger(ChatTrigger_Private, value);
|
delete [] m_PrivTrigger;
|
||||||
|
m_PrivTrigger = sm_strdup(value);
|
||||||
|
m_PrivTriggerSize = strlen(m_PrivTrigger);
|
||||||
return ConfigResult_Accept;
|
return ConfigResult_Accept;
|
||||||
}
|
}
|
||||||
else if (strcmp(key, "SilentFailSuppress") == 0)
|
else if (strcmp(key, "SilentFailSuppress") == 0)
|
||||||
@@ -112,10 +111,10 @@ ConfigResult ChatTriggers::OnSourceModConfigChanged(const char *key,
|
|||||||
|
|
||||||
void ChatTriggers::OnSourceModAllInitialized()
|
void ChatTriggers::OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
m_pShouldFloodBlock = forwardsys->CreateForward("OnClientFloodCheck", ET_Event, 1, NULL, Param_Cell);
|
m_pShouldFloodBlock = g_Forwards.CreateForward("OnClientFloodCheck", ET_Event, 1, NULL, Param_Cell);
|
||||||
m_pDidFloodBlock = forwardsys->CreateForward("OnClientFloodResult", ET_Event, 2, NULL, Param_Cell, Param_Cell);
|
m_pDidFloodBlock = g_Forwards.CreateForward("OnClientFloodResult", ET_Event, 2, NULL, Param_Cell, Param_Cell);
|
||||||
m_pOnClientSayCmd = forwardsys->CreateForward("OnClientSayCommand", ET_Event, 3, NULL, Param_Cell, Param_String, Param_String);
|
m_pOnClientSayCmd = g_Forwards.CreateForward("OnClientSayCommand", ET_Event, 3, NULL, Param_Cell, Param_String, Param_String);
|
||||||
m_pOnClientSayCmd_Post = forwardsys->CreateForward("OnClientSayCommand_Post", ET_Ignore, 3, NULL, Param_Cell, Param_String, Param_String);
|
m_pOnClientSayCmd_Post = g_Forwards.CreateForward("OnClientSayCommand_Post", ET_Ignore, 3, NULL, Param_Cell, Param_String, Param_String);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatTriggers::OnSourceModAllInitialized_Post()
|
void ChatTriggers::OnSourceModAllInitialized_Post()
|
||||||
@@ -125,133 +124,121 @@ void ChatTriggers::OnSourceModAllInitialized_Post()
|
|||||||
|
|
||||||
void ChatTriggers::OnSourceModGameInitialized()
|
void ChatTriggers::OnSourceModGameInitialized()
|
||||||
{
|
{
|
||||||
ConCommand *say_team = FindCommand("say_team");
|
m_pSayCmd = FindCommand("say");
|
||||||
|
m_pSayTeamCmd = FindCommand("say_team");
|
||||||
|
|
||||||
CommandHook::Callback pre_hook = [this] (int client, const ICommandArgs *args) -> bool {
|
if (m_pSayCmd)
|
||||||
return this->OnSayCommand_Pre(client, args);
|
{
|
||||||
};
|
SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Pre, false);
|
||||||
CommandHook::Callback post_hook = [this] (int client, const ICommandArgs *args) -> bool {
|
SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Post, true);
|
||||||
return this->OnSayCommand_Post(client, args);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (ConCommand *say = FindCommand("say")) {
|
|
||||||
hooks_.append(sCoreProviderImpl.AddCommandHook(say, pre_hook));
|
|
||||||
hooks_.append(sCoreProviderImpl.AddPostCommandHook(say, post_hook));
|
|
||||||
}
|
}
|
||||||
if (ConCommand *say_team = FindCommand("say_team")) {
|
if (m_pSayTeamCmd)
|
||||||
hooks_.append(sCoreProviderImpl.AddCommandHook(say_team, pre_hook));
|
{
|
||||||
hooks_.append(sCoreProviderImpl.AddPostCommandHook(say_team, post_hook));
|
SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayTeamCmd, this, &ChatTriggers::OnSayCommand_Pre, false);
|
||||||
|
SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayTeamCmd, this, &ChatTriggers::OnSayCommand_Post, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SOURCE_ENGINE == SE_EPISODEONE
|
#if SOURCE_ENGINE == SE_EPISODEONE
|
||||||
m_bIsINS = (strcmp(g_SourceMod.GetGameFolderName(), "insurgency") == 0);
|
m_bIsINS = (strcmp(g_SourceMod.GetGameFolderName(), "insurgency") == 0);
|
||||||
if (m_bIsINS) {
|
|
||||||
if (ConCommand *say2 = FindCommand("say2")) {
|
if (m_bIsINS)
|
||||||
hooks_.append(sCoreProviderImpl.AddCommandHook(say2, pre_hook));
|
{
|
||||||
hooks_.append(sCoreProviderImpl.AddPostCommandHook(say2, post_hook));
|
m_pSay2Cmd = FindCommand("say2");
|
||||||
|
if (m_pSay2Cmd)
|
||||||
|
{
|
||||||
|
SH_ADD_HOOK(ConCommand, Dispatch, m_pSay2Cmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Pre), false);
|
||||||
|
SH_ADD_HOOK(ConCommand, Dispatch, m_pSay2Cmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Post), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#elif SOURCE_ENGINE == SE_NUCLEARDAWN
|
#elif SOURCE_ENGINE == SE_NUCLEARDAWN
|
||||||
if (ConCommand *say_squad = FindCommand("say_squad")) {
|
m_pSaySquadCmd = FindCommand("say_squad");
|
||||||
hooks_.append(sCoreProviderImpl.AddCommandHook(say_squad, pre_hook));
|
|
||||||
hooks_.append(sCoreProviderImpl.AddPostCommandHook(say_squad, post_hook));
|
if (m_pSaySquadCmd)
|
||||||
|
{
|
||||||
|
SH_ADD_HOOK(ConCommand, Dispatch, m_pSaySquadCmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Pre), false);
|
||||||
|
SH_ADD_HOOK(ConCommand, Dispatch, m_pSaySquadCmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Post), true);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatTriggers::OnSourceModShutdown()
|
void ChatTriggers::OnSourceModShutdown()
|
||||||
{
|
{
|
||||||
hooks_.clear();
|
if (m_pSayCmd)
|
||||||
|
{
|
||||||
|
SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Post, true);
|
||||||
|
SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Pre, false);
|
||||||
|
}
|
||||||
|
|
||||||
forwardsys->ReleaseForward(m_pShouldFloodBlock);
|
if (m_pSayTeamCmd)
|
||||||
forwardsys->ReleaseForward(m_pDidFloodBlock);
|
{
|
||||||
forwardsys->ReleaseForward(m_pOnClientSayCmd);
|
SH_REMOVE_HOOK(ConCommand, Dispatch, m_pSayTeamCmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Post), true);
|
||||||
forwardsys->ReleaseForward(m_pOnClientSayCmd_Post);
|
SH_REMOVE_HOOK(ConCommand, Dispatch, m_pSayTeamCmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Pre), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if SOURCE_ENGINE == SE_EPISODEONE
|
||||||
|
if (m_bIsINS && m_pSay2Cmd)
|
||||||
|
{
|
||||||
|
SH_REMOVE_HOOK(ConCommand, Dispatch, m_pSay2Cmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Pre), false);
|
||||||
|
SH_REMOVE_HOOK(ConCommand, Dispatch, m_pSay2Cmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Post), true);
|
||||||
|
}
|
||||||
|
#elif SOURCE_ENGINE == SE_NUCLEARDAWN
|
||||||
|
if (m_pSaySquadCmd)
|
||||||
|
{
|
||||||
|
SH_REMOVE_HOOK(ConCommand, Dispatch, m_pSaySquadCmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Pre), false);
|
||||||
|
SH_REMOVE_HOOK(ConCommand, Dispatch, m_pSaySquadCmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Post), true);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
g_Forwards.ReleaseForward(m_pShouldFloodBlock);
|
||||||
|
g_Forwards.ReleaseForward(m_pDidFloodBlock);
|
||||||
|
g_Forwards.ReleaseForward(m_pOnClientSayCmd);
|
||||||
|
g_Forwards.ReleaseForward(m_pOnClientSayCmd_Post);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatTriggers::OnSayCommand_Pre(int client, const ICommandArgs *command)
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
|
void ChatTriggers::OnSayCommand_Pre(const CCommand &command)
|
||||||
{
|
{
|
||||||
|
#else
|
||||||
|
void ChatTriggers::OnSayCommand_Pre()
|
||||||
|
{
|
||||||
|
CCommand command;
|
||||||
|
#endif
|
||||||
|
int client = g_ConCmds.GetCommandClient();
|
||||||
m_bIsChatTrigger = false;
|
m_bIsChatTrigger = false;
|
||||||
m_bWasFloodedMessage = false;
|
m_bWasFloodedMessage = false;
|
||||||
m_bPluginIgnored = true;
|
m_bPluginIgnored = false;
|
||||||
|
|
||||||
const char *args = command->ArgS();
|
|
||||||
|
|
||||||
|
const char *args = command.ArgS();
|
||||||
|
|
||||||
if (!args)
|
if (!args)
|
||||||
return false;
|
{
|
||||||
|
RETURN_META(MRES_IGNORED);
|
||||||
|
}
|
||||||
|
|
||||||
/* Save these off for post hook as the command data returned from the engine in older engine versions
|
/* Save these off for post hook as the command data returned from the engine in older engine versions
|
||||||
* can be NULL, despite the data still being there and valid. */
|
* can be NULL, despite the data still being there and valid. */
|
||||||
m_Arg0Backup = command->Arg(0);
|
m_Arg0Backup = command.Arg(0);
|
||||||
size_t len = strlen(args);
|
m_ArgSBackup = command.ArgS();
|
||||||
|
|
||||||
#if SOURCE_ENGINE == SE_EPISODEONE
|
|
||||||
if (m_bIsINS)
|
|
||||||
{
|
|
||||||
if (strcmp(m_Arg0Backup, "say2") == 0 && len >= 4)
|
|
||||||
{
|
|
||||||
args += 4;
|
|
||||||
len -= 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len == 0)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* The first pair of quotes are stripped from client say commands, but not console ones.
|
|
||||||
* We do not want the forwards to differ from what is displayed.
|
|
||||||
* So only strip the first pair of quotes from client say commands. */
|
|
||||||
bool is_quoted = false;
|
|
||||||
|
|
||||||
if (
|
|
||||||
#if SOURCE_ENGINE == SE_EPISODEONE
|
|
||||||
!m_bIsINS &&
|
|
||||||
#endif
|
|
||||||
client != 0 && args[0] == '"' && args[len-1] == '"')
|
|
||||||
{
|
|
||||||
/* The server normally won't display empty say commands, but in this case it does.
|
|
||||||
* I don't think it's desired so let's block it. */
|
|
||||||
if (len <= 2)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
args++;
|
|
||||||
len--;
|
|
||||||
is_quoted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Some? engines strip the last quote when printing the string to chat.
|
|
||||||
* This results in having a double-quoted message passed to the OnClientSayCommand ("message") forward,
|
|
||||||
* but losing the last quote in the OnClientSayCommand_Post ("message) forward.
|
|
||||||
* To compensate this, we copy the args into our own buffer where the engine won't mess with
|
|
||||||
* and strip the quotes. */
|
|
||||||
delete [] m_ArgSBackup;
|
|
||||||
m_ArgSBackup = new char[CCommand::MaxCommandLength()+1];
|
|
||||||
memcpy(m_ArgSBackup, args, len+1);
|
|
||||||
|
|
||||||
/* Strip the quotes from the argument */
|
|
||||||
if (is_quoted)
|
|
||||||
{
|
|
||||||
if (m_ArgSBackup[len-1] == '"')
|
|
||||||
{
|
|
||||||
m_ArgSBackup[--len] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The server console cannot do this */
|
/* The server console cannot do this */
|
||||||
if (client == 0)
|
if (client == 0)
|
||||||
{
|
{
|
||||||
if (CallOnClientSayCommand(client) >= Pl_Handled)
|
cell_t res = CallOnClientSayCommand(client);
|
||||||
return true;
|
if (res >= Pl_Handled)
|
||||||
|
{
|
||||||
return false;
|
m_bPluginIgnored = (res >= Pl_Stop);
|
||||||
|
RETURN_META(MRES_SUPERCEDE);
|
||||||
|
}
|
||||||
|
RETURN_META(MRES_IGNORED);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
|
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
|
||||||
|
|
||||||
/* We guarantee the client is connected */
|
/* We guarantee the client is connected */
|
||||||
if (!pPlayer || !pPlayer->IsConnected())
|
if (!pPlayer || !pPlayer->IsConnected())
|
||||||
return false;
|
{
|
||||||
|
RETURN_META(MRES_IGNORED);
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if we need to block this message from being sent */
|
/* Check if we need to block this message from being sent */
|
||||||
if (ClientIsFlooding(client))
|
if (ClientIsFlooding(client))
|
||||||
@@ -259,38 +246,54 @@ bool ChatTriggers::OnSayCommand_Pre(int client, const ICommandArgs *command)
|
|||||||
char buffer[128];
|
char buffer[128];
|
||||||
|
|
||||||
if (!logicore.CoreTranslate(buffer, sizeof(buffer), "%T", 2, NULL, "Flooding the server", &client))
|
if (!logicore.CoreTranslate(buffer, sizeof(buffer), "%T", 2, NULL, "Flooding the server", &client))
|
||||||
ke::SafeSprintf(buffer, sizeof(buffer), "You are flooding the server!");
|
UTIL_Format(buffer, sizeof(buffer), "You are flooding the server!");
|
||||||
|
|
||||||
/* :TODO: we should probably kick people who spam too much. */
|
/* :TODO: we should probably kick people who spam too much. */
|
||||||
|
|
||||||
char fullbuffer[192];
|
char fullbuffer[192];
|
||||||
ke::SafeSprintf(fullbuffer, sizeof(fullbuffer), "[SM] %s", buffer);
|
UTIL_Format(fullbuffer, sizeof(fullbuffer), "[SM] %s", buffer);
|
||||||
g_HL2.TextMsg(client, HUD_PRINTTALK, fullbuffer);
|
g_HL2.TextMsg(client, HUD_PRINTTALK, fullbuffer);
|
||||||
|
|
||||||
m_bWasFloodedMessage = true;
|
m_bWasFloodedMessage = true;
|
||||||
return true;
|
|
||||||
|
RETURN_META(MRES_SUPERCEDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Handle quoted string sets */
|
||||||
|
bool is_quoted = false;
|
||||||
|
if (args[0] == '"')
|
||||||
|
{
|
||||||
|
args++;
|
||||||
|
is_quoted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if SOURCE_ENGINE == SE_EPISODEONE
|
||||||
|
if (m_bIsINS && strcmp(m_Arg0Backup, "say2") == 0 && strlen(args) >= 4)
|
||||||
|
{
|
||||||
|
args += 4;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool is_trigger = false;
|
bool is_trigger = false;
|
||||||
bool is_silent = false;
|
bool is_silent = false;
|
||||||
|
|
||||||
// Prefer the silent trigger in case of clashes.
|
/* Check for either trigger */
|
||||||
if (strchr(m_PrivTrigger.chars(), m_ArgSBackup[0])) {
|
if (m_PubTriggerSize && strncmp(args, m_PubTrigger, m_PubTriggerSize) == 0)
|
||||||
|
{
|
||||||
|
is_trigger = true;
|
||||||
|
args = &args[m_PubTriggerSize];
|
||||||
|
}
|
||||||
|
else if (m_PrivTriggerSize && strncmp(args, m_PrivTrigger, m_PrivTriggerSize) == 0)
|
||||||
|
{
|
||||||
is_trigger = true;
|
is_trigger = true;
|
||||||
is_silent = true;
|
is_silent = true;
|
||||||
} else if (strchr(m_PubTrigger.chars(), m_ArgSBackup[0])) {
|
args = &args[m_PrivTriggerSize];
|
||||||
is_trigger = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_trigger) {
|
|
||||||
// Bump the args past the chat trigger - we only support single-character triggers now.
|
|
||||||
args = &m_ArgSBackup[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if this is actually a command!
|
* Test if this is actually a command!
|
||||||
*/
|
*/
|
||||||
if (is_trigger && PreProcessTrigger(PEntityOfEntIndex(client), args))
|
if (is_trigger && PreProcessTrigger(PEntityOfEntIndex(client), args, is_quoted))
|
||||||
{
|
{
|
||||||
m_bIsChatTrigger = true;
|
m_bIsChatTrigger = true;
|
||||||
|
|
||||||
@@ -300,31 +303,48 @@ bool ChatTriggers::OnSayCommand_Pre(int client, const ICommandArgs *command)
|
|||||||
m_bWillProcessInPost = true;
|
m_bWillProcessInPost = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_silent && (m_bIsChatTrigger || (g_bSupressSilentFails && pPlayer->GetAdminId() != INVALID_ADMIN_ID)))
|
cell_t res = CallOnClientSayCommand(client);
|
||||||
return true;
|
|
||||||
|
|
||||||
if (CallOnClientSayCommand(client) >= Pl_Handled)
|
if (res >= Pl_Handled)
|
||||||
return true;
|
{
|
||||||
|
m_bPluginIgnored = (res >= Pl_Stop);
|
||||||
|
RETURN_META(MRES_SUPERCEDE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_silent && (m_bIsChatTrigger || (g_bSupressSilentFails && pPlayer->GetAdminId() != INVALID_ADMIN_ID)))
|
||||||
|
{
|
||||||
|
RETURN_META(MRES_SUPERCEDE);
|
||||||
|
}
|
||||||
|
|
||||||
/* Otherwise, let the command continue */
|
/* Otherwise, let the command continue */
|
||||||
return false;
|
RETURN_META(MRES_IGNORED);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatTriggers::OnSayCommand_Post(int client, const ICommandArgs *command)
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
|
void ChatTriggers::OnSayCommand_Post(const CCommand &command)
|
||||||
|
#else
|
||||||
|
void ChatTriggers::OnSayCommand_Post()
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
|
int client = g_ConCmds.GetCommandClient();
|
||||||
|
|
||||||
if (m_bWillProcessInPost)
|
if (m_bWillProcessInPost)
|
||||||
{
|
{
|
||||||
/* Reset this for re-entrancy */
|
/* Reset this for re-entrancy */
|
||||||
m_bWillProcessInPost = false;
|
m_bWillProcessInPost = false;
|
||||||
|
|
||||||
/* Execute the cached command */
|
/* Execute the cached command */
|
||||||
unsigned int old = SetReplyTo(SM_REPLY_CHAT);
|
unsigned int old = SetReplyTo(SM_REPLY_CHAT);
|
||||||
serverpluginhelpers->ClientCommand(PEntityOfEntIndex(client), m_ToExecute);
|
serverpluginhelpers->ClientCommand(PEntityOfEntIndex(client), m_ToExecute);
|
||||||
SetReplyTo(old);
|
SetReplyTo(old);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_bPluginIgnored && m_pOnClientSayCmd_Post->GetFunctionCount() != 0)
|
if (m_bPluginIgnored)
|
||||||
{
|
{
|
||||||
|
m_bPluginIgnored = false;
|
||||||
|
}
|
||||||
|
else if (!m_bWasFloodedMessage && !m_bIsChatTrigger && m_pOnClientSayCmd_Post->GetFunctionCount() != 0)
|
||||||
|
{
|
||||||
m_pOnClientSayCmd_Post->PushCell(client);
|
m_pOnClientSayCmd_Post->PushCell(client);
|
||||||
m_pOnClientSayCmd_Post->PushString(m_Arg0Backup);
|
m_pOnClientSayCmd_Post->PushString(m_Arg0Backup);
|
||||||
m_pOnClientSayCmd_Post->PushString(m_ArgSBackup);
|
m_pOnClientSayCmd_Post->PushString(m_ArgSBackup);
|
||||||
@@ -333,17 +353,16 @@ bool ChatTriggers::OnSayCommand_Post(int client, const ICommandArgs *command)
|
|||||||
|
|
||||||
m_bIsChatTrigger = false;
|
m_bIsChatTrigger = false;
|
||||||
m_bWasFloodedMessage = false;
|
m_bWasFloodedMessage = false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args)
|
bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args, bool is_quoted)
|
||||||
{
|
{
|
||||||
/* Extract a command. This is kind of sloppy. */
|
/* Extract a command. This is kind of sloppy. */
|
||||||
char cmd_buf[64];
|
char cmd_buf[64];
|
||||||
size_t cmd_len = 0;
|
size_t cmd_len = 0;
|
||||||
const char *inptr = args;
|
const char *inptr = args;
|
||||||
while (*inptr != '\0'
|
while (*inptr != '\0'
|
||||||
&& !textparsers->IsWhitespace(inptr)
|
&& !textparsers->IsWhitespace(inptr)
|
||||||
&& *inptr != '"'
|
&& *inptr != '"'
|
||||||
&& cmd_len < sizeof(cmd_buf) - 1)
|
&& cmd_len < sizeof(cmd_buf) - 1)
|
||||||
{
|
{
|
||||||
@@ -366,36 +385,45 @@ bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now, prepend. Don't worry about the buffers. This will
|
/* Now, prepend. Don't worry about the buffers. This will
|
||||||
* work because the sizes are limited from earlier.
|
* work because the sizes are limited from earlier.
|
||||||
*/
|
*/
|
||||||
char new_buf[80];
|
char new_buf[80];
|
||||||
strcpy(new_buf, "sm_");
|
strcpy(new_buf, "sm_");
|
||||||
ke::SafeStrcpy(&new_buf[3], sizeof(new_buf)-3, cmd_buf);
|
strncopy(&new_buf[3], cmd_buf, sizeof(new_buf)-3);
|
||||||
|
|
||||||
/* Recheck */
|
/* Recheck */
|
||||||
if (!g_ConCmds.LookForSourceModCommand(new_buf))
|
if (!g_ConCmds.LookForSourceModCommand(new_buf))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
prepended = true;
|
prepended = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See if we need to do extra string manipulation */
|
/* See if we need to do extra string manipulation */
|
||||||
if (prepended)
|
if (is_quoted || prepended)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
/* Check if we need to prepend sm_ */
|
/* Check if we need to prepend sm_ */
|
||||||
if (prepended)
|
if (prepended)
|
||||||
{
|
{
|
||||||
len = ke::SafeSprintf(m_ToExecute, sizeof(m_ToExecute), "sm_%s", args);
|
len = UTIL_Format(m_ToExecute, sizeof(m_ToExecute), "sm_%s", args);
|
||||||
} else {
|
} else {
|
||||||
len = ke::SafeStrcpy(m_ToExecute, sizeof(m_ToExecute), args);
|
len = strncopy(m_ToExecute, args, sizeof(m_ToExecute));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if we need to strip a quote */
|
||||||
|
if (is_quoted)
|
||||||
|
{
|
||||||
|
if (m_ToExecute[len-1] == '"')
|
||||||
|
{
|
||||||
|
m_ToExecute[--len] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ke::SafeStrcpy(m_ToExecute, sizeof(m_ToExecute), args);
|
strncopy(m_ToExecute, args, sizeof(m_ToExecute));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -404,16 +432,13 @@ bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args)
|
|||||||
cell_t ChatTriggers::CallOnClientSayCommand(int client)
|
cell_t ChatTriggers::CallOnClientSayCommand(int client)
|
||||||
{
|
{
|
||||||
cell_t res = Pl_Continue;
|
cell_t res = Pl_Continue;
|
||||||
if (m_pOnClientSayCmd->GetFunctionCount() != 0)
|
if (!m_bIsChatTrigger && m_pOnClientSayCmd->GetFunctionCount() != 0)
|
||||||
{
|
{
|
||||||
m_pOnClientSayCmd->PushCell(client);
|
m_pOnClientSayCmd->PushCell(client);
|
||||||
m_pOnClientSayCmd->PushString(m_Arg0Backup);
|
m_pOnClientSayCmd->PushString(m_Arg0Backup);
|
||||||
m_pOnClientSayCmd->PushString(m_ArgSBackup);
|
m_pOnClientSayCmd->PushString(m_ArgSBackup);
|
||||||
m_pOnClientSayCmd->Execute(&res);
|
m_pOnClientSayCmd->Execute(&res);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bPluginIgnored = (res >= Pl_Stop);
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+25
-19
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
* This program is free software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||||
* Free Software Foundation.
|
* Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
@@ -34,11 +34,9 @@
|
|||||||
|
|
||||||
#include "sm_globals.h"
|
#include "sm_globals.h"
|
||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include "GameHooks.h"
|
|
||||||
#include <IGameHelpers.h>
|
#include <IGameHelpers.h>
|
||||||
#include <compat_wrappers.h>
|
#include <compat_wrappers.h>
|
||||||
#include <IForwardSys.h>
|
#include <IForwardSys.h>
|
||||||
#include <amtl/am-string.h>
|
|
||||||
|
|
||||||
class ChatTriggers : public SMGlobalClass
|
class ChatTriggers : public SMGlobalClass
|
||||||
{
|
{
|
||||||
@@ -50,32 +48,40 @@ public: //SMGlobalClass
|
|||||||
void OnSourceModAllInitialized_Post();
|
void OnSourceModAllInitialized_Post();
|
||||||
void OnSourceModGameInitialized();
|
void OnSourceModGameInitialized();
|
||||||
void OnSourceModShutdown();
|
void OnSourceModShutdown();
|
||||||
ConfigResult OnSourceModConfigChanged(const char *key,
|
ConfigResult OnSourceModConfigChanged(const char *key,
|
||||||
const char *value,
|
const char *value,
|
||||||
ConfigSource source,
|
ConfigSource source,
|
||||||
char *error,
|
char *error,
|
||||||
size_t maxlength);
|
size_t maxlength);
|
||||||
private: //ConCommand
|
private: //ConCommand
|
||||||
bool OnSayCommand_Pre(int client, const ICommandArgs *args);
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
bool OnSayCommand_Post(int client, const ICommandArgs *args);
|
void OnSayCommand_Pre(const CCommand &command);
|
||||||
|
void OnSayCommand_Post(const CCommand &command);
|
||||||
|
#else
|
||||||
|
void OnSayCommand_Pre();
|
||||||
|
void OnSayCommand_Post();
|
||||||
|
#endif
|
||||||
public:
|
public:
|
||||||
unsigned int GetReplyTo();
|
unsigned int GetReplyTo();
|
||||||
unsigned int SetReplyTo(unsigned int reply);
|
unsigned int SetReplyTo(unsigned int reply);
|
||||||
bool IsChatTrigger();
|
bool IsChatTrigger();
|
||||||
bool WasFloodedMessage();
|
bool WasFloodedMessage();
|
||||||
private:
|
private:
|
||||||
enum ChatTriggerType {
|
bool PreProcessTrigger(edict_t *pEdict, const char *args, bool is_quoted);
|
||||||
ChatTrigger_Public,
|
|
||||||
ChatTrigger_Private,
|
|
||||||
};
|
|
||||||
void SetChatTrigger(ChatTriggerType type, const char *value);
|
|
||||||
bool PreProcessTrigger(edict_t *pEdict, const char *args);
|
|
||||||
bool ClientIsFlooding(int client);
|
bool ClientIsFlooding(int client);
|
||||||
cell_t CallOnClientSayCommand(int client);
|
cell_t CallOnClientSayCommand(int client);
|
||||||
private:
|
private:
|
||||||
ke::Vector<ke::RefPtr<CommandHook>> hooks_;
|
ConCommand *m_pSayCmd;
|
||||||
ke::AString m_PubTrigger;
|
ConCommand *m_pSayTeamCmd;
|
||||||
ke::AString m_PrivTrigger;
|
#if SOURCE_ENGINE == SE_EPISODEONE
|
||||||
|
ConCommand *m_pSay2Cmd;
|
||||||
|
#elif SOURCE_ENGINE == SE_NUCLEARDAWN
|
||||||
|
ConCommand *m_pSaySquadCmd;
|
||||||
|
#endif
|
||||||
|
char *m_PubTrigger;
|
||||||
|
size_t m_PubTriggerSize;
|
||||||
|
char *m_PrivTrigger;
|
||||||
|
size_t m_PrivTriggerSize;
|
||||||
bool m_bWillProcessInPost;
|
bool m_bWillProcessInPost;
|
||||||
bool m_bIsChatTrigger;
|
bool m_bIsChatTrigger;
|
||||||
bool m_bWasFloodedMessage;
|
bool m_bWasFloodedMessage;
|
||||||
@@ -83,7 +89,7 @@ private:
|
|||||||
unsigned int m_ReplyTo;
|
unsigned int m_ReplyTo;
|
||||||
char m_ToExecute[300];
|
char m_ToExecute[300];
|
||||||
const char *m_Arg0Backup;
|
const char *m_Arg0Backup;
|
||||||
char *m_ArgSBackup;
|
const char *m_ArgSBackup;
|
||||||
IForward *m_pShouldFloodBlock;
|
IForward *m_pShouldFloodBlock;
|
||||||
IForward *m_pDidFloodBlock;
|
IForward *m_pDidFloodBlock;
|
||||||
IForward *m_pOnClientSayCmd;
|
IForward *m_pOnClientSayCmd;
|
||||||
|
|||||||
+547
-232
File diff suppressed because it is too large
Load Diff
+48
-58
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -34,82 +34,60 @@
|
|||||||
|
|
||||||
#include "sm_globals.h"
|
#include "sm_globals.h"
|
||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include <IForwardSys.h>
|
#include "ForwardSys.h"
|
||||||
|
#include "sm_trie.h"
|
||||||
|
#include "sm_memtable.h"
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include <sh_string.h>
|
#include <sh_string.h>
|
||||||
#include <IRootConsoleMenu.h>
|
#include <IRootConsoleMenu.h>
|
||||||
#include <IAdminSystem.h>
|
#include <IAdminSystem.h>
|
||||||
#include "concmd_cleaner.h"
|
#include "concmd_cleaner.h"
|
||||||
#include "GameHooks.h"
|
|
||||||
#include <am-autoptr.h>
|
|
||||||
#include <sm_stringhashmap.h>
|
|
||||||
#include <am-utility.h>
|
|
||||||
#include <am-inlinelist.h>
|
|
||||||
#include <am-linkedlist.h>
|
|
||||||
#include <am-refcounting.h>
|
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
|
|
||||||
struct CmdHook;
|
enum CmdType
|
||||||
struct ConCmdInfo;
|
|
||||||
|
|
||||||
struct CommandGroup : public ke::Refcounted<CommandGroup>
|
|
||||||
{
|
{
|
||||||
ke::LinkedList<CmdHook *> hooks;
|
Cmd_Server,
|
||||||
|
Cmd_Admin,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AdminCmdInfo
|
struct AdminCmdInfo
|
||||||
{
|
{
|
||||||
AdminCmdInfo(const ke::RefPtr<CommandGroup> &group, FlagBits flags)
|
AdminCmdInfo()
|
||||||
: group(group),
|
|
||||||
flags(flags),
|
|
||||||
eflags(0)
|
|
||||||
{
|
{
|
||||||
|
cmdGrpId = -1;
|
||||||
|
flags = 0;
|
||||||
|
eflags = 0;
|
||||||
}
|
}
|
||||||
ke::RefPtr<CommandGroup> group;
|
int cmdGrpId; /* index into cmdgroup string table */
|
||||||
FlagBits flags; /* default flags */
|
FlagBits flags; /* default flags */
|
||||||
FlagBits eflags; /* effective flags */
|
FlagBits eflags; /* effective flags */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CmdHook : public ke::InlineListNode<CmdHook>
|
struct CmdHook
|
||||||
{
|
{
|
||||||
enum Type {
|
CmdHook()
|
||||||
Server,
|
|
||||||
Client
|
|
||||||
};
|
|
||||||
|
|
||||||
CmdHook(Type type, ConCmdInfo *cmd, IPluginFunction *fun, const char *description)
|
|
||||||
: type(type),
|
|
||||||
info(cmd),
|
|
||||||
pf(fun),
|
|
||||||
helptext(description)
|
|
||||||
{
|
{
|
||||||
|
pf = NULL;
|
||||||
|
pAdmin = NULL;
|
||||||
}
|
}
|
||||||
|
IPluginFunction *pf; /* function hook */
|
||||||
Type type;
|
String helptext; /* help text */
|
||||||
ConCmdInfo *info;
|
AdminCmdInfo *pAdmin; /* admin requirements, if any */
|
||||||
IPluginFunction *pf; /* function hook */
|
|
||||||
ke::AString helptext; /* help text */
|
|
||||||
ke::AutoPtr<AdminCmdInfo> admin; /* admin requirements, if any */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef ke::InlineList<CmdHook> CmdHookList;
|
|
||||||
|
|
||||||
struct ConCmdInfo
|
struct ConCmdInfo
|
||||||
{
|
{
|
||||||
ConCmdInfo()
|
ConCmdInfo()
|
||||||
{
|
{
|
||||||
pPlugin = nullptr;
|
|
||||||
sourceMod = false;
|
sourceMod = false;
|
||||||
pCmd = nullptr;
|
pCmd = NULL;
|
||||||
eflags = 0;
|
|
||||||
}
|
}
|
||||||
bool sourceMod; /**< Determines whether or not concmd was created by a SourceMod plugin */
|
bool sourceMod; /**< Determines whether or not concmd was created by a SourceMod plugin */
|
||||||
ConCommand *pCmd; /**< Pointer to the command itself */
|
ConCommand *pCmd; /**< Pointer to the command itself */
|
||||||
CmdHookList hooks; /**< Hook list */
|
List<CmdHook *> srvhooks; /**< Hooks as a server command */
|
||||||
FlagBits eflags; /**< Effective admin flags */
|
List<CmdHook *> conhooks; /**< Hooks as a console command */
|
||||||
ke::RefPtr<CommandHook> sh_hook; /**< SourceHook hook, if any. */
|
AdminCmdInfo admin; /**< Admin info, if any */
|
||||||
IPlugin *pPlugin; /**< Owning plugin handle. */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef List<ConCmdInfo *> ConCmdList;
|
typedef List<ConCmdInfo *> ConCmdList;
|
||||||
@@ -120,7 +98,11 @@ class ConCmdManager :
|
|||||||
public IPluginsListener,
|
public IPluginsListener,
|
||||||
public IConCommandTracker
|
public IConCommandTracker
|
||||||
{
|
{
|
||||||
friend void CommandCallback(DISPATCH_ARGS);
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
|
friend void CommandCallback(const CCommand &command);
|
||||||
|
#else
|
||||||
|
friend void CommandCallback();
|
||||||
|
#endif
|
||||||
public:
|
public:
|
||||||
ConCmdManager();
|
ConCmdManager();
|
||||||
~ConCmdManager();
|
~ConCmdManager();
|
||||||
@@ -130,28 +112,32 @@ public: //SMGlobalClass
|
|||||||
public: //IPluginsListener
|
public: //IPluginsListener
|
||||||
void OnPluginDestroyed(IPlugin *plugin);
|
void OnPluginDestroyed(IPlugin *plugin);
|
||||||
public: //IRootConsoleCommand
|
public: //IRootConsoleCommand
|
||||||
void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override;
|
void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
|
||||||
public: //IConCommandTracker
|
public: //IConCommandTracker
|
||||||
void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name) override;
|
void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe);
|
||||||
public:
|
public:
|
||||||
bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags, IPlugin *pPlugin);
|
bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
|
||||||
bool AddAdminCommand(IPluginFunction *pFunction,
|
bool AddAdminCommand(IPluginFunction *pFunction,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *group,
|
const char *group,
|
||||||
int adminflags,
|
int adminflags,
|
||||||
const char *description,
|
const char *description,
|
||||||
int flags,
|
int flags);
|
||||||
IPlugin *pPlugin);
|
|
||||||
ResultType DispatchClientCommand(int client, const char *cmd, int args, ResultType type);
|
ResultType DispatchClientCommand(int client, const char *cmd, int args, ResultType type);
|
||||||
void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits, bool remove);
|
void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits, bool remove);
|
||||||
bool LookForSourceModCommand(const char *cmd);
|
bool LookForSourceModCommand(const char *cmd);
|
||||||
bool LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags);
|
bool LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags);
|
||||||
|
bool CheckClientCommandAccess(int client, const char *cmd, FlagBits flags);
|
||||||
|
bool CheckAdminCommandAccess(AdminId adm, const char *cmd, FlagBits flags);
|
||||||
private:
|
private:
|
||||||
bool InternalDispatch(int client, const ICommandArgs *args);
|
void InternalDispatch(const CCommand &command);
|
||||||
ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
|
ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
|
||||||
ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags, IPlugin *pPlugin);
|
ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags);
|
||||||
|
void SetCommandClient(int client);
|
||||||
void AddToCmdList(ConCmdInfo *info);
|
void AddToCmdList(ConCmdInfo *info);
|
||||||
void RemoveConCmd(ConCmdInfo *info, const char *cmd, bool untrack);
|
void RemoveConCmd(ConCmdInfo *info, const char *cmd, bool is_read_safe, bool untrack);
|
||||||
|
void RemoveConCmds(List<CmdHook *> &cmdlist);
|
||||||
|
void RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext);
|
||||||
bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin);
|
bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin);
|
||||||
|
|
||||||
// Case insensitive
|
// Case insensitive
|
||||||
@@ -160,16 +146,20 @@ private:
|
|||||||
// Case sensitive
|
// Case sensitive
|
||||||
ConCmdInfo *FindInTrie(const char *name);
|
ConCmdInfo *FindInTrie(const char *name);
|
||||||
public:
|
public:
|
||||||
|
inline int GetCommandClient()
|
||||||
|
{
|
||||||
|
return m_CmdClient;
|
||||||
|
}
|
||||||
inline const List<ConCmdInfo *> & GetCommandList()
|
inline const List<ConCmdInfo *> & GetCommandList()
|
||||||
{
|
{
|
||||||
return m_CmdList;
|
return m_CmdList;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
typedef StringHashMap<ke::RefPtr<CommandGroup> > GroupMap;
|
Trie *m_pCmds; /* command lookup */
|
||||||
|
Trie *m_pCmdGrps; /* command group lookup */
|
||||||
StringHashMap<ConCmdInfo *> m_Cmds; /* command lookup */
|
|
||||||
GroupMap m_CmdGrps; /* command group map */
|
|
||||||
ConCmdList m_CmdList; /* command list */
|
ConCmdList m_CmdList; /* command list */
|
||||||
|
int m_CmdClient; /* current client */
|
||||||
|
BaseStringTable m_Strings; /* string table */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ConCmdManager g_ConCmds;
|
extern ConCmdManager g_ConCmds;
|
||||||
|
|||||||
+165
-83
@@ -29,19 +29,34 @@
|
|||||||
|
|
||||||
#include "ConVarManager.h"
|
#include "ConVarManager.h"
|
||||||
#include "HalfLife2.h"
|
#include "HalfLife2.h"
|
||||||
|
#include "PluginSys.h"
|
||||||
|
#include "ForwardSys.h"
|
||||||
|
#include "HandleSys.h"
|
||||||
|
#include "sm_srvcmds.h"
|
||||||
#include "sm_stringutil.h"
|
#include "sm_stringutil.h"
|
||||||
#include <sh_vector.h>
|
#include <sh_vector.h>
|
||||||
#include <sm_namehashset.h>
|
#include <sm_trie_tpl.h>
|
||||||
#include "logic_bridge.h"
|
|
||||||
#include "sourcemod.h"
|
|
||||||
#include "provider.h"
|
|
||||||
#include <bridge/include/IScriptManager.h>
|
|
||||||
|
|
||||||
ConVarManager g_ConVarManager;
|
ConVarManager g_ConVarManager;
|
||||||
|
|
||||||
|
#if SOURCE_ENGINE <= SE_DARKMESSIAH
|
||||||
|
#define CallGlobalChangeCallbacks CallGlobalChangeCallback
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
|
SH_DECL_HOOK3_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *, float);
|
||||||
|
#else
|
||||||
|
SH_DECL_HOOK2_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||||
|
SH_DECL_HOOK5_void(IServerGameDLL, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *);
|
||||||
|
SH_DECL_HOOK5_void(IServerPluginCallbacks, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *);
|
||||||
|
#endif
|
||||||
|
|
||||||
const ParamType CONVARCHANGE_PARAMS[] = {Param_Cell, Param_String, Param_String};
|
const ParamType CONVARCHANGE_PARAMS[] = {Param_Cell, Param_String, Param_String};
|
||||||
typedef List<const ConVar *> ConVarList;
|
typedef List<const ConVar *> ConVarList;
|
||||||
NameHashSet<ConVarInfo *> convar_cache;
|
KTrie<ConVarInfo *> convar_cache;
|
||||||
|
|
||||||
class ConVarReentrancyGuard
|
class ConVarReentrancyGuard
|
||||||
{
|
{
|
||||||
@@ -77,7 +92,7 @@ public:
|
|||||||
|
|
||||||
ConVarReentrancyGuard *ConVarReentrancyGuard::chain = NULL;
|
ConVarReentrancyGuard *ConVarReentrancyGuard::chain = NULL;
|
||||||
|
|
||||||
ConVarManager::ConVarManager() : m_ConVarType(0)
|
ConVarManager::ConVarManager() : m_ConVarType(0), m_bIsDLLQueryHooked(false), m_bIsVSPQueryHooked(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,17 +110,28 @@ void ConVarManager::OnSourceModStartup(bool late)
|
|||||||
sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER;
|
sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER;
|
||||||
|
|
||||||
/* Create the 'ConVar' handle type */
|
/* Create the 'ConVar' handle type */
|
||||||
m_ConVarType = handlesys->CreateType("ConVar", this, 0, NULL, &sec, g_pCoreIdent, NULL);
|
m_ConVarType = g_HandleSys.CreateType("ConVar", this, 0, NULL, &sec, g_pCoreIdent, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConVarManager::OnSourceModAllInitialized()
|
void ConVarManager::OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
g_Players.AddClientListener(this);
|
/**
|
||||||
|
* Episode 2 has this function by default, but the older versions do not.
|
||||||
|
*/
|
||||||
|
#if SOURCE_ENGINE == SE_EPISODEONE
|
||||||
|
if (g_SMAPI->GetGameDLLVersion() >= 6)
|
||||||
|
{
|
||||||
|
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, OnQueryCvarValueFinished, gamedll, this, &ConVarManager::OnQueryCvarValueFinished, false);
|
||||||
|
m_bIsDLLQueryHooked = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
scripts->AddPluginsListener(this);
|
SH_ADD_HOOK_STATICFUNC(ICvar, CallGlobalChangeCallbacks, icvar, OnConVarChanged, false);
|
||||||
|
|
||||||
|
g_PluginSys.AddPluginsListener(this);
|
||||||
|
|
||||||
/* Add the 'convars' option to the 'sm' console command */
|
/* Add the 'convars' option to the 'sm' console command */
|
||||||
rootmenu->AddRootConsoleCommand3("cvars", "View convars created by a plugin", this);
|
g_RootMenu.AddRootConsoleCommand("cvars", "View convars created by a plugin", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConVarManager::OnSourceModShutdown()
|
void ConVarManager::OnSourceModShutdown()
|
||||||
@@ -120,10 +146,10 @@ void ConVarManager::OnSourceModShutdown()
|
|||||||
|
|
||||||
iter = m_ConVars.erase(iter);
|
iter = m_ConVars.erase(iter);
|
||||||
|
|
||||||
handlesys->FreeHandle(pInfo->handle, &sec);
|
g_HandleSys.FreeHandle(pInfo->handle, &sec);
|
||||||
if (pInfo->pChangeForward != NULL)
|
if (pInfo->pChangeForward != NULL)
|
||||||
{
|
{
|
||||||
forwardsys->ReleaseForward(pInfo->pChangeForward);
|
g_Forwards.ReleaseForward(pInfo->pChangeForward);
|
||||||
}
|
}
|
||||||
if (pInfo->sourceMod)
|
if (pInfo->sourceMod)
|
||||||
{
|
{
|
||||||
@@ -151,23 +177,79 @@ void ConVarManager::OnSourceModShutdown()
|
|||||||
}
|
}
|
||||||
convar_cache.clear();
|
convar_cache.clear();
|
||||||
|
|
||||||
g_Players.RemoveClientListener(this);
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||||
|
/* Unhook things */
|
||||||
|
if (m_bIsDLLQueryHooked)
|
||||||
|
{
|
||||||
|
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, OnQueryCvarValueFinished, gamedll, this, &ConVarManager::OnQueryCvarValueFinished, false);
|
||||||
|
m_bIsDLLQueryHooked = false;
|
||||||
|
}
|
||||||
|
else if (m_bIsVSPQueryHooked)
|
||||||
|
{
|
||||||
|
SH_REMOVE_HOOK_MEMFUNC(IServerPluginCallbacks, OnQueryCvarValueFinished, vsp_interface, this, &ConVarManager::OnQueryCvarValueFinished, false);
|
||||||
|
m_bIsVSPQueryHooked = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SH_REMOVE_HOOK_STATICFUNC(ICvar, CallGlobalChangeCallbacks, icvar, OnConVarChanged, false);
|
||||||
|
|
||||||
/* Remove the 'convars' option from the 'sm' console command */
|
/* Remove the 'convars' option from the 'sm' console command */
|
||||||
rootmenu->RemoveRootConsoleCommand("cvars", this);
|
g_RootMenu.RemoveRootConsoleCommand("cvars", this);
|
||||||
|
|
||||||
scripts->RemovePluginsListener(this);
|
g_PluginSys.RemovePluginsListener(this);
|
||||||
|
|
||||||
/* Remove the 'ConVar' handle type */
|
/* Remove the 'ConVar' handle type */
|
||||||
handlesys->RemoveType(m_ConVarType, g_pCoreIdent);
|
g_HandleSys.RemoveType(m_ConVarType, g_pCoreIdent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Orange Box will never use this.
|
||||||
|
*/
|
||||||
|
void ConVarManager::OnSourceModVSPReceived()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Don't bother if the DLL is already hooked.
|
||||||
|
*/
|
||||||
|
if (m_bIsDLLQueryHooked)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* For later MM:S versions, use the updated API, since it's cleaner. */
|
||||||
|
#if defined METAMOD_PLAPI_VERSION || PLAPI_VERSION >= 11
|
||||||
|
int engine = g_SMAPI->GetSourceEngineBuild();
|
||||||
|
if (engine == SOURCE_ENGINE_ORIGINAL || vsp_version < 2)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (g_HL2.IsOriginalEngine() || vsp_version < 2)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||||
|
SH_ADD_HOOK_MEMFUNC(IServerPluginCallbacks, OnQueryCvarValueFinished, vsp_interface, this, &ConVarManager::OnQueryCvarValueFinished, false);
|
||||||
|
m_bIsVSPQueryHooked = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool convar_cache_lookup(const char *name, ConVarInfo **pVar)
|
bool convar_cache_lookup(const char *name, ConVarInfo **pVar)
|
||||||
{
|
{
|
||||||
return convar_cache.retrieve(name, pVar);
|
ConVarInfo **pLookup = convar_cache.retrieve(name);
|
||||||
|
if (pLookup != NULL)
|
||||||
|
{
|
||||||
|
*pVar = *pLookup;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConVarManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name)
|
void ConVarManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe)
|
||||||
{
|
{
|
||||||
/* Only check convars that have not been created by SourceMod's core */
|
/* Only check convars that have not been created by SourceMod's core */
|
||||||
ConVarInfo *pInfo;
|
ConVarInfo *pInfo;
|
||||||
@@ -183,7 +265,7 @@ void ConVarManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *na
|
|||||||
convar_cache.remove(name);
|
convar_cache.remove(name);
|
||||||
|
|
||||||
/* Now make sure no plugins are referring to this pointer */
|
/* Now make sure no plugins are referring to this pointer */
|
||||||
IPluginIterator *pl_iter = scripts->GetPluginIterator();
|
IPluginIterator *pl_iter = g_PluginSys.GetPluginIterator();
|
||||||
while (pl_iter->MorePlugins())
|
while (pl_iter->MorePlugins())
|
||||||
{
|
{
|
||||||
IPlugin *pl = pl_iter->GetPlugin();
|
IPlugin *pl = pl_iter->GetPlugin();
|
||||||
@@ -199,7 +281,7 @@ void ConVarManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *na
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Free resources */
|
/* Free resources */
|
||||||
handlesys->FreeHandle(pInfo->handle, &sec);
|
g_HandleSys.FreeHandle(pInfo->handle, &sec);
|
||||||
delete pInfo;
|
delete pInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,35 +296,14 @@ void ConVarManager::OnPluginUnloaded(IPlugin *plugin)
|
|||||||
delete pConVarList;
|
delete pConVarList;
|
||||||
}
|
}
|
||||||
|
|
||||||
const IPluginRuntime * pRuntime = plugin->GetRuntime();
|
|
||||||
|
|
||||||
/* Remove convar queries for this plugin that haven't returned results yet */
|
/* Remove convar queries for this plugin that haven't returned results yet */
|
||||||
for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end();)
|
for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end(); iter++)
|
||||||
{
|
{
|
||||||
ConVarQuery &query = (*iter);
|
ConVarQuery &query = (*iter);
|
||||||
if (query.pCallback->GetParentRuntime() == pRuntime)
|
if (query.pCallback->GetParentRuntime() == plugin->GetRuntime())
|
||||||
{
|
{
|
||||||
iter = m_ConVarQueries.erase(iter);
|
m_ConVarQueries.erase(iter);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
++iter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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();)
|
|
||||||
{
|
|
||||||
ConVarQuery &query = (*iter);
|
|
||||||
if (query.client == client)
|
|
||||||
{
|
|
||||||
iter = m_ConVarQueries.erase(iter);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
++iter;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,27 +317,27 @@ bool ConVarManager::GetHandleApproxSize(HandleType_t type, void *object, unsigne
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
|
void ConVarManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
|
||||||
{
|
{
|
||||||
int argcount = command->ArgC();
|
int argcount = command.ArgC();
|
||||||
if (argcount >= 3)
|
if (argcount >= 3)
|
||||||
{
|
{
|
||||||
bool wantReset = false;
|
bool wantReset = false;
|
||||||
|
|
||||||
/* Get plugin index that was passed */
|
/* Get plugin index that was passed */
|
||||||
const char *arg = command->Arg(2);
|
const char *arg = command.Arg(2);
|
||||||
if (argcount >= 4 && strcmp(arg, "reset") == 0)
|
if (argcount >= 4 && strcmp(arg, "reset") == 0)
|
||||||
{
|
{
|
||||||
wantReset = true;
|
wantReset = true;
|
||||||
arg = command->Arg(3);
|
arg = command.Arg(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get plugin object */
|
/* Get plugin object */
|
||||||
IPlugin *plugin = scripts->FindPluginByConsoleArg(arg);
|
CPlugin *plugin = g_PluginSys.FindPluginByConsoleArg(arg);
|
||||||
|
|
||||||
if (!plugin)
|
if (!plugin)
|
||||||
{
|
{
|
||||||
UTIL_ConsolePrint("[SM] Plugin \"%s\" was not found.", arg);
|
g_RootMenu.ConsolePrint("[SM] Plugin \"%s\" was not found.", arg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,14 +351,14 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
|
|||||||
/* If no convar list... */
|
/* If no convar list... */
|
||||||
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList))
|
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList))
|
||||||
{
|
{
|
||||||
UTIL_ConsolePrint("[SM] No convars found for: %s", plname);
|
g_RootMenu.ConsolePrint("[SM] No convars found for: %s", plname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wantReset)
|
if (!wantReset)
|
||||||
{
|
{
|
||||||
UTIL_ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname);
|
g_RootMenu.ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname);
|
||||||
UTIL_ConsolePrint(" %-32.31s %s", "[Name]", "[Value]");
|
g_RootMenu.ConsolePrint(" %-32.31s %s", "[Name]", "[Value]");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Iterate convar list and display/reset each one */
|
/* Iterate convar list and display/reset each one */
|
||||||
@@ -306,7 +367,7 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
|
|||||||
/*const */ConVar *pConVar = const_cast<ConVar *>(*iter);
|
/*const */ConVar *pConVar = const_cast<ConVar *>(*iter);
|
||||||
if (!wantReset)
|
if (!wantReset)
|
||||||
{
|
{
|
||||||
UTIL_ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString());
|
g_RootMenu.ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString());
|
||||||
} else {
|
} else {
|
||||||
pConVar->Revert();
|
pConVar->Revert();
|
||||||
}
|
}
|
||||||
@@ -314,14 +375,14 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
|
|||||||
|
|
||||||
if (wantReset)
|
if (wantReset)
|
||||||
{
|
{
|
||||||
UTIL_ConsolePrint("[SM] Reset %d convars for: %s", pConVarList->size(), plname);
|
g_RootMenu.ConsolePrint("[SM] Reset %d convars for: %s", pConVarList->size(), plname);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Display usage of subcommand */
|
/* Display usage of subcommand */
|
||||||
UTIL_ConsolePrint("[SM] Usage: sm cvars [reset] <plugin #>");
|
g_RootMenu.ConsolePrint("[SM] Usage: sm cvars [reset] <plugin #>");
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle_t ConVarManager::CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal, const char *description, int flags, bool hasMin, float min, bool hasMax, float max)
|
Handle_t ConVarManager::CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal, const char *description, int flags, bool hasMin, float min, bool hasMax, float max)
|
||||||
@@ -353,7 +414,7 @@ Handle_t ConVarManager::CreateConVar(IPluginContext *pContext, const char *name,
|
|||||||
pInfo->pVar = pConVar;
|
pInfo->pVar = pConVar;
|
||||||
|
|
||||||
/* If we don't, then create a new handle from the convar */
|
/* If we don't, then create a new handle from the convar */
|
||||||
hndl = handlesys->CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL);
|
hndl = g_HandleSys.CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL);
|
||||||
if (hndl == BAD_HANDLE)
|
if (hndl == BAD_HANDLE)
|
||||||
{
|
{
|
||||||
delete pInfo;
|
delete pInfo;
|
||||||
@@ -384,7 +445,7 @@ Handle_t ConVarManager::CreateConVar(IPluginContext *pContext, const char *name,
|
|||||||
pInfo->pChangeForward = NULL;
|
pInfo->pChangeForward = NULL;
|
||||||
|
|
||||||
/* Create a handle from the new convar */
|
/* Create a handle from the new convar */
|
||||||
hndl = handlesys->CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL);
|
hndl = g_HandleSys.CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL);
|
||||||
if (hndl == BAD_HANDLE)
|
if (hndl == BAD_HANDLE)
|
||||||
{
|
{
|
||||||
delete pInfo;
|
delete pInfo;
|
||||||
@@ -413,13 +474,7 @@ Handle_t ConVarManager::FindConVar(const char *name)
|
|||||||
ConVarInfo *pInfo;
|
ConVarInfo *pInfo;
|
||||||
Handle_t hndl;
|
Handle_t hndl;
|
||||||
|
|
||||||
/* Check convar cache to find out if we already have a handle */
|
/* Search for convar */
|
||||||
if (convar_cache_lookup(name, &pInfo))
|
|
||||||
{
|
|
||||||
return pInfo->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Couldn't find it in cache, so search for it */
|
|
||||||
pConVar = icvar->FindVar(name);
|
pConVar = icvar->FindVar(name);
|
||||||
|
|
||||||
/* If it doesn't exist, then return an invalid handle */
|
/* If it doesn't exist, then return an invalid handle */
|
||||||
@@ -428,6 +483,12 @@ Handle_t ConVarManager::FindConVar(const char *name)
|
|||||||
return BAD_HANDLE;
|
return BAD_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* At this point, the convar exists. So, find out if we already have a handle */
|
||||||
|
if (convar_cache_lookup(name, &pInfo))
|
||||||
|
{
|
||||||
|
return pInfo->handle;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create and initialize ConVarInfo structure */
|
/* Create and initialize ConVarInfo structure */
|
||||||
pInfo = new ConVarInfo();
|
pInfo = new ConVarInfo();
|
||||||
pInfo->sourceMod = false;
|
pInfo->sourceMod = false;
|
||||||
@@ -435,7 +496,7 @@ Handle_t ConVarManager::FindConVar(const char *name)
|
|||||||
pInfo->pVar = pConVar;
|
pInfo->pVar = pConVar;
|
||||||
|
|
||||||
/* If we don't have a handle, then create a new one */
|
/* If we don't have a handle, then create a new one */
|
||||||
hndl = handlesys->CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL);
|
hndl = g_HandleSys.CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL);
|
||||||
if (hndl == BAD_HANDLE)
|
if (hndl == BAD_HANDLE)
|
||||||
{
|
{
|
||||||
delete pInfo;
|
delete pInfo;
|
||||||
@@ -493,7 +554,7 @@ void ConVarManager::HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction
|
|||||||
/* If forward does not exist, create it */
|
/* If forward does not exist, create it */
|
||||||
if (!pForward)
|
if (!pForward)
|
||||||
{
|
{
|
||||||
pForward = forwardsys->CreateForwardEx(NULL, ET_Ignore, 3, CONVARCHANGE_PARAMS);
|
pForward = g_Forwards.CreateForwardEx(NULL, ET_Ignore, 3, CONVARCHANGE_PARAMS);
|
||||||
pInfo->pChangeForward = pForward;
|
pInfo->pChangeForward = pForward;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,7 +594,7 @@ void ConVarManager::UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFuncti
|
|||||||
!ConVarReentrancyGuard::IsCvarInChain(pConVar))
|
!ConVarReentrancyGuard::IsCvarInChain(pConVar))
|
||||||
{
|
{
|
||||||
/* Free this forward */
|
/* Free this forward */
|
||||||
forwardsys->ReleaseForward(pForward);
|
g_Forwards.ReleaseForward(pForward);
|
||||||
pInfo->pChangeForward = NULL;
|
pInfo->pChangeForward = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -541,13 +602,26 @@ void ConVarManager::UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFuncti
|
|||||||
|
|
||||||
QueryCvarCookie_t ConVarManager::QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback, Handle_t hndl)
|
QueryCvarCookie_t ConVarManager::QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback, Handle_t hndl)
|
||||||
{
|
{
|
||||||
QueryCvarCookie_t cookie = sCoreProviderImpl.QueryClientConVar(IndexOfEdict(pPlayer), name);
|
QueryCvarCookie_t cookie = 0;
|
||||||
|
|
||||||
if (pCallback != NULL)
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||||
|
/* Call StartQueryCvarValue() in either the IVEngineServer or IServerPluginHelpers depending on situation */
|
||||||
|
if (m_bIsDLLQueryHooked)
|
||||||
{
|
{
|
||||||
ConVarQuery query = { cookie, pCallback, (cell_t) hndl, IndexOfEdict(pPlayer) };
|
cookie = engine->StartQueryCvarValue(pPlayer, name);
|
||||||
m_ConVarQueries.push_back(query);
|
|
||||||
}
|
}
|
||||||
|
else if (m_bIsVSPQueryHooked)
|
||||||
|
{
|
||||||
|
cookie = serverpluginhelpers->StartQueryCvarValue(pPlayer, name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return InvalidQueryCvarCookie;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConVarQuery query = {cookie, pCallback, hndl};
|
||||||
|
m_ConVarQueries.push_back(query);
|
||||||
|
#endif
|
||||||
|
|
||||||
return cookie;
|
return cookie;
|
||||||
}
|
}
|
||||||
@@ -559,7 +633,7 @@ void ConVarManager::AddConVarToPluginList(IPluginContext *pContext, const ConVar
|
|||||||
bool inserted = false;
|
bool inserted = false;
|
||||||
const char *orig = pConVar->GetName();
|
const char *orig = pConVar->GetName();
|
||||||
|
|
||||||
IPlugin *plugin = scripts->FindPluginByContext(pContext->GetContext());
|
IPlugin *plugin = g_PluginSys.FindPluginByContext(pContext->GetContext());
|
||||||
|
|
||||||
/* Check plugin for an existing convar list */
|
/* Check plugin for an existing convar list */
|
||||||
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList))
|
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList))
|
||||||
@@ -590,7 +664,11 @@ void ConVarManager::AddConVarToPluginList(IPluginContext *pContext, const ConVar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue)
|
void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue)
|
||||||
|
#else
|
||||||
|
void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
/* If the values are the same, exit early in order to not trigger callbacks */
|
/* If the values are the same, exit early in order to not trigger callbacks */
|
||||||
if (strcmp(pConVar->GetString(), oldValue) == 0)
|
if (strcmp(pConVar->GetString(), oldValue) == 0)
|
||||||
@@ -610,8 +688,16 @@ void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue, float
|
|||||||
|
|
||||||
if (pInfo->changeListeners.size() != 0)
|
if (pInfo->changeListeners.size() != 0)
|
||||||
{
|
{
|
||||||
for (auto i = pInfo->changeListeners.begin(); i != pInfo->changeListeners.end(); i++)
|
for (List<IConVarChangeListener *>::iterator i = pInfo->changeListeners.begin();
|
||||||
|
i != pInfo->changeListeners.end();
|
||||||
|
i++)
|
||||||
|
{
|
||||||
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
(*i)->OnConVarChanged(pConVar, oldValue, flOldValue);
|
(*i)->OnConVarChanged(pConVar, oldValue, flOldValue);
|
||||||
|
#else
|
||||||
|
(*i)->OnConVarChanged(pConVar, oldValue, atof(oldValue));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pForward != NULL)
|
if (pForward != NULL)
|
||||||
@@ -628,15 +714,11 @@ void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue, float
|
|||||||
|
|
||||||
bool ConVarManager::IsQueryingSupported()
|
bool ConVarManager::IsQueryingSupported()
|
||||||
{
|
{
|
||||||
return sCoreProviderImpl.IsClientConVarQueryingSupported();
|
return (m_bIsDLLQueryHooked || m_bIsVSPQueryHooked);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||||
void ConVarManager::OnClientQueryFinished(QueryCvarCookie_t cookie,
|
void ConVarManager::OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, const char *cvarName, const char *cvarValue)
|
||||||
int client,
|
|
||||||
EQueryCvarValueStatus result,
|
|
||||||
const char *cvarName,
|
|
||||||
const char *cvarValue)
|
|
||||||
{
|
{
|
||||||
IPluginFunction *pCallback = NULL;
|
IPluginFunction *pCallback = NULL;
|
||||||
cell_t value = 0;
|
cell_t value = 0;
|
||||||
@@ -658,7 +740,7 @@ void ConVarManager::OnClientQueryFinished(QueryCvarCookie_t cookie,
|
|||||||
cell_t ret;
|
cell_t ret;
|
||||||
|
|
||||||
pCallback->PushCell(cookie);
|
pCallback->PushCell(cookie);
|
||||||
pCallback->PushCell(client);
|
pCallback->PushCell(IndexOfEdict(pPlayer));
|
||||||
pCallback->PushCell(result);
|
pCallback->PushCell(result);
|
||||||
pCallback->PushString(cvarName);
|
pCallback->PushString(cvarName);
|
||||||
|
|
||||||
@@ -684,7 +766,7 @@ HandleError ConVarManager::ReadConVarHandle(Handle_t hndl, ConVar **pVar)
|
|||||||
ConVarInfo *pInfo;
|
ConVarInfo *pInfo;
|
||||||
HandleError error;
|
HandleError error;
|
||||||
|
|
||||||
if ((error = handlesys->ReadHandle(hndl, m_ConVarType, NULL, (void **)&pInfo)) != HandleError_None)
|
if ((error = g_HandleSys.ReadHandle(hndl, m_ConVarType, NULL, (void **)&pInfo)) != HandleError_None)
|
||||||
{
|
{
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-31
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -39,11 +39,13 @@
|
|||||||
#include <IForwardSys.h>
|
#include <IForwardSys.h>
|
||||||
#include <IHandleSys.h>
|
#include <IHandleSys.h>
|
||||||
#include <IRootConsoleMenu.h>
|
#include <IRootConsoleMenu.h>
|
||||||
#include <IPlayerHelpers.h>
|
|
||||||
#include <compat_wrappers.h>
|
#include <compat_wrappers.h>
|
||||||
#include "concmd_cleaner.h"
|
#include "concmd_cleaner.h"
|
||||||
#include "PlayerManager.h"
|
|
||||||
#include <sm_stringhashmap.h>
|
#if SOURCE_ENGINE == SE_DARKMESSIAH
|
||||||
|
class EQueryCvarValueStatus;
|
||||||
|
typedef int QueryCvarCookie_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
|
|
||||||
@@ -63,15 +65,6 @@ struct ConVarInfo
|
|||||||
IChangeableForward *pChangeForward; /**< Forward associated with convar */
|
IChangeableForward *pChangeForward; /**< Forward associated with convar */
|
||||||
ConVar *pVar; /**< The actual convar */
|
ConVar *pVar; /**< The actual convar */
|
||||||
List<IConVarChangeListener *> changeListeners;
|
List<IConVarChangeListener *> changeListeners;
|
||||||
|
|
||||||
static inline bool matches(const char *name, const ConVarInfo *info)
|
|
||||||
{
|
|
||||||
return strcmp(name, info->pVar->GetName()) == 0;
|
|
||||||
}
|
|
||||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
|
||||||
{
|
|
||||||
return key.hash();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,7 +75,6 @@ struct ConVarQuery
|
|||||||
QueryCvarCookie_t cookie; /**< Cookie that identifies query */
|
QueryCvarCookie_t cookie; /**< Cookie that identifies query */
|
||||||
IPluginFunction *pCallback; /**< Function that will be called when query is finished */
|
IPluginFunction *pCallback; /**< Function that will be called when query is finished */
|
||||||
cell_t value; /**< Optional value passed to query function */
|
cell_t value; /**< Optional value passed to query function */
|
||||||
cell_t client; /**< Only used for cleaning up on client disconnection */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConVarManager :
|
class ConVarManager :
|
||||||
@@ -90,8 +82,7 @@ class ConVarManager :
|
|||||||
public IHandleTypeDispatch,
|
public IHandleTypeDispatch,
|
||||||
public IPluginsListener,
|
public IPluginsListener,
|
||||||
public IRootConsoleCommand,
|
public IRootConsoleCommand,
|
||||||
public IConCommandTracker,
|
public IConCommandTracker
|
||||||
public IClientListener
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ConVarManager();
|
ConVarManager();
|
||||||
@@ -100,17 +91,16 @@ public: // SMGlobalClass
|
|||||||
void OnSourceModStartup(bool late);
|
void OnSourceModStartup(bool late);
|
||||||
void OnSourceModAllInitialized();
|
void OnSourceModAllInitialized();
|
||||||
void OnSourceModShutdown();
|
void OnSourceModShutdown();
|
||||||
|
void OnSourceModVSPReceived();
|
||||||
public: // IHandleTypeDispatch
|
public: // IHandleTypeDispatch
|
||||||
void OnHandleDestroy(HandleType_t type, void *object);
|
void OnHandleDestroy(HandleType_t type, void *object);
|
||||||
bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
|
bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
|
||||||
public: // IPluginsListener
|
public: // IPluginsListener
|
||||||
void OnPluginUnloaded(IPlugin *plugin);
|
void OnPluginUnloaded(IPlugin *plugin);
|
||||||
public: //IRootConsoleCommand
|
public: //IRootConsoleCommand
|
||||||
void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override;
|
void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
|
||||||
public: //IConCommandTracker
|
public: //IConCommandTracker
|
||||||
void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name) override;
|
void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe);
|
||||||
public: //IClientListener
|
|
||||||
void OnClientDisconnected(int client);
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Create a convar and return a handle to it.
|
* Create a convar and return a handle to it.
|
||||||
@@ -146,26 +136,34 @@ public:
|
|||||||
|
|
||||||
HandleError ReadConVarHandle(Handle_t hndl, ConVar **pVar);
|
HandleError ReadConVarHandle(Handle_t hndl, ConVar **pVar);
|
||||||
|
|
||||||
// Called via game hooks.
|
|
||||||
void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue);
|
|
||||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
|
||||||
void OnClientQueryFinished(
|
|
||||||
QueryCvarCookie_t cookie,
|
|
||||||
int client,
|
|
||||||
EQueryCvarValueStatus result,
|
|
||||||
const char *cvarName,
|
|
||||||
const char *cvarValue);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Adds a convar to a plugin's list.
|
* Adds a convar to a plugin's list.
|
||||||
*/
|
*/
|
||||||
static void AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar);
|
static void AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static callback that Valve's ConVar object executes when the convar's value changes.
|
||||||
|
*/
|
||||||
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
|
static void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue);
|
||||||
|
#else
|
||||||
|
static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for when StartQueryCvarValue() has finished.
|
||||||
|
*/
|
||||||
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||||
|
void OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result,
|
||||||
|
const char *cvarName, const char *cvarValue);
|
||||||
|
#endif
|
||||||
private:
|
private:
|
||||||
HandleType_t m_ConVarType;
|
HandleType_t m_ConVarType;
|
||||||
List<ConVarInfo *> m_ConVars;
|
List<ConVarInfo *> m_ConVars;
|
||||||
List<ConVarQuery> m_ConVarQueries;
|
List<ConVarQuery> m_ConVarQueries;
|
||||||
|
bool m_bIsDLLQueryHooked;
|
||||||
|
bool m_bIsVSPQueryHooked;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ConVarManager g_ConVarManager;
|
extern ConVarManager g_ConVarManager;
|
||||||
|
|||||||
+385
-47
@@ -49,11 +49,7 @@
|
|||||||
#include "ConCmdManager.h"
|
#include "ConCmdManager.h"
|
||||||
#include "HalfLife2.h"
|
#include "HalfLife2.h"
|
||||||
#include "ConCommandBaseIterator.h"
|
#include "ConCommandBaseIterator.h"
|
||||||
#include "logic_bridge.h"
|
#include "ShareSys.h"
|
||||||
#include "command_args.h"
|
|
||||||
#include "provider.h"
|
|
||||||
#include <am-utility.h>
|
|
||||||
#include <bridge/include/ILogger.h>
|
|
||||||
|
|
||||||
#if defined PLATFORM_POSIX
|
#if defined PLATFORM_POSIX
|
||||||
# include <dlfcn.h>
|
# include <dlfcn.h>
|
||||||
@@ -62,12 +58,24 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
#if SH_IMPL_VERSION >= 5
|
||||||
|
# if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
|
SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
|
||||||
#else
|
# else
|
||||||
SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
|
SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# if SH_IMPL_VERSION >= 4
|
||||||
|
extern int __SourceHook_FHVPAddConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0<void>,bool);
|
||||||
|
extern int __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
|
||||||
|
# else
|
||||||
|
extern bool __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
|
||||||
|
# endif
|
||||||
|
extern bool __SourceHook_FHRemoveConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if SH_IMPL_VERSION >= 4
|
||||||
|
|
||||||
class GenericCommandHooker : public IConCommandLinkListener
|
class GenericCommandHooker : public IConCommandLinkListener
|
||||||
{
|
{
|
||||||
struct HackInfo
|
struct HackInfo
|
||||||
@@ -123,16 +131,16 @@ class GenericCommandHooker : public IConCommandLinkListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
# if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
void Dispatch(const CCommand& args)
|
void Dispatch(const CCommand& args)
|
||||||
#else
|
# else
|
||||||
void Dispatch()
|
void Dispatch()
|
||||||
#endif
|
# endif
|
||||||
{
|
{
|
||||||
cell_t res = ConsoleDetours::Dispatch(META_IFACEPTR(ConCommand)
|
cell_t res = ConsoleDetours::Dispatch(META_IFACEPTR(ConCommand)
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
# if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
, args
|
, args
|
||||||
#endif
|
# endif
|
||||||
);
|
);
|
||||||
if (res >= Pl_Handled)
|
if (res >= Pl_Handled)
|
||||||
RETURN_META(MRES_SUPERCEDE);
|
RETURN_META(MRES_SUPERCEDE);
|
||||||
@@ -182,7 +190,7 @@ class GenericCommandHooker : public IConCommandLinkListener
|
|||||||
size_t index;
|
size_t index;
|
||||||
if (!FindVtable(vtable, index))
|
if (!FindVtable(vtable, index))
|
||||||
{
|
{
|
||||||
logger->LogError("Console detour tried to unhook command \"%s\" but it wasn't found", pBase->GetName());
|
g_Logger.LogError("Console detour tried to unhook command \"%s\" but it wasn't found", pBase->GetName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +214,7 @@ public:
|
|||||||
|
|
||||||
if (dispatch.thisptroffs < 0)
|
if (dispatch.thisptroffs < 0)
|
||||||
{
|
{
|
||||||
logger->LogError("Command filter could not determine ConCommand layout");
|
g_Logger.LogError("Command filter could not determine ConCommand layout");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +223,7 @@ public:
|
|||||||
|
|
||||||
if (!vtables.size())
|
if (!vtables.size())
|
||||||
{
|
{
|
||||||
logger->LogError("Command filter could not find any cvars!");
|
g_Logger.LogError("Command filter could not find any cvars!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,6 +257,308 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* END DVP HOOK VERSION
|
||||||
|
*/
|
||||||
|
|
||||||
|
#else /* SH_IMPL_VERSION >= 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BEGIN ENGINE DETOUR VERSION
|
||||||
|
*/
|
||||||
|
|
||||||
|
# include <jit/jit_helpers.h>
|
||||||
|
# include <jit/x86/x86_macros.h>
|
||||||
|
|
||||||
|
class GenericCommandHooker
|
||||||
|
{
|
||||||
|
struct Patch
|
||||||
|
{
|
||||||
|
Patch() : applied(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool applied;
|
||||||
|
void *base;
|
||||||
|
unsigned char search[16];
|
||||||
|
size_t search_len;
|
||||||
|
size_t offset;
|
||||||
|
size_t saveat;
|
||||||
|
int regparam;
|
||||||
|
void *detour;
|
||||||
|
};
|
||||||
|
|
||||||
|
Patch ces;
|
||||||
|
Patch cgc;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void DelayedActivation(void *inparam)
|
||||||
|
{
|
||||||
|
GenericCommandHooker *cdtrs = reinterpret_cast<GenericCommandHooker*>(inparam);
|
||||||
|
/* Safe to re-enter because the frame queue is lock+swapped. */
|
||||||
|
if ((!cdtrs->ces.applied || !cdtrs->cgc.applied) &&
|
||||||
|
g_HL2.PeekCommandStack() != NULL)
|
||||||
|
{
|
||||||
|
g_SourceMod.AddFrameAction(GenericCommandHooker::DelayedActivation, cdtrs);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cdtrs->ces.applied)
|
||||||
|
cdtrs->ApplyPatch(&cdtrs->ces);
|
||||||
|
if (!cdtrs->cgc.applied)
|
||||||
|
cdtrs->ApplyPatch(&cdtrs->cgc);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Enable()
|
||||||
|
{
|
||||||
|
const char *platform = NULL;
|
||||||
|
# if defined(PLATFORM_WINDOWS)
|
||||||
|
platform = "Windows";
|
||||||
|
# else
|
||||||
|
void *addrInBase = (void *)g_SMAPI->GetEngineFactory(false);
|
||||||
|
Dl_info info;
|
||||||
|
if (!dladdr(addrInBase, &info))
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Command filter could not find engine name");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (strstr(info.dli_fname, "engine_i486"))
|
||||||
|
{
|
||||||
|
platform = "Linux_486";
|
||||||
|
}
|
||||||
|
else if (strstr(info.dli_fname, "engine_i686"))
|
||||||
|
{
|
||||||
|
platform = "Linux_686";
|
||||||
|
}
|
||||||
|
else if (strstr(info.dli_fname, "engine_amd"))
|
||||||
|
{
|
||||||
|
platform = "Linux_AMD";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Command filter could not determine engine (%s)", info.dli_fname);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
if (!PrepPatch("Cmd_ExecuteString", "CES", platform, &ces))
|
||||||
|
return false;
|
||||||
|
if (!PrepPatch("CGameClient::ExecuteString", "CGC", platform, &cgc))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (g_HL2.PeekCommandStack() != NULL)
|
||||||
|
{
|
||||||
|
g_SourceMod.AddFrameAction(GenericCommandHooker::DelayedActivation, this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplyPatch(&ces);
|
||||||
|
ApplyPatch(&cgc);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Disable()
|
||||||
|
{
|
||||||
|
UndoPatch(&ces);
|
||||||
|
UndoPatch(&cgc);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
# if !defined PLATFORM_WINDOWS
|
||||||
|
# define PAGE_READWRITE PROT_READ|PROT_WRITE
|
||||||
|
# define PAGE_EXECUTE_READ PROT_READ|PROT_EXEC
|
||||||
|
|
||||||
|
static inline uintptr_t AddrToPage(uintptr_t address)
|
||||||
|
{
|
||||||
|
return (address & ~(uintptr_t(sysconf(_SC_PAGE_SIZE) - 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
# endif
|
||||||
|
|
||||||
|
void Protect(void *addr, size_t length, int prot)
|
||||||
|
{
|
||||||
|
# if defined PLATFORM_WINDOWS
|
||||||
|
DWORD ignore;
|
||||||
|
VirtualProtect(addr, length, prot, &ignore);
|
||||||
|
# else
|
||||||
|
uintptr_t startPage = AddrToPage(uintptr_t(addr));
|
||||||
|
length += (uintptr_t(addr) - startPage);
|
||||||
|
mprotect((void*)startPage, length, prot);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void UndoPatch(Patch *patch)
|
||||||
|
{
|
||||||
|
if (!patch->applied || patch->detour == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_pSourcePawn->FreePageMemory(patch->detour);
|
||||||
|
|
||||||
|
unsigned char *source = (unsigned char *)patch->base + patch->offset;
|
||||||
|
Protect(source, patch->search_len, PAGE_READWRITE);
|
||||||
|
for (size_t i = 0; i < patch->search_len; i++)
|
||||||
|
source[i] = patch->search[i];
|
||||||
|
Protect(source, patch->search_len, PAGE_EXECUTE_READ);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplyPatch(Patch *patch)
|
||||||
|
{
|
||||||
|
assert(!patch->applied);
|
||||||
|
|
||||||
|
size_t length = 0;
|
||||||
|
void *callback = (void*)&ConsoleDetours::Dispatch;
|
||||||
|
|
||||||
|
/* Bogus assignment to make compiler is doing the right thing. */
|
||||||
|
patch->detour = callback;
|
||||||
|
|
||||||
|
/* Assemgle the detour. */
|
||||||
|
JitWriter writer;
|
||||||
|
writer.outbase = NULL;
|
||||||
|
writer.outptr = NULL;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
/* Need a specific register, or value on stack? */
|
||||||
|
if (patch->regparam != -1)
|
||||||
|
IA32_Push_Reg(&writer, patch->regparam);
|
||||||
|
/* Call real function. */
|
||||||
|
IA32_Write_Jump32_Abs(&writer, IA32_Call_Imm32(&writer, 0), callback);
|
||||||
|
/* Restore stack. */
|
||||||
|
if (patch->regparam != -1)
|
||||||
|
IA32_Pop_Reg(&writer, patch->regparam);
|
||||||
|
/* Copy any saved bytes */
|
||||||
|
if (patch->saveat)
|
||||||
|
{
|
||||||
|
for (size_t i = patch->saveat; i < patch->search_len; i++)
|
||||||
|
{
|
||||||
|
writer.write_ubyte(patch->search[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Jump back to the caller. */
|
||||||
|
unsigned char *target = (unsigned char *)patch->base + patch->offset + patch->search_len;
|
||||||
|
IA32_Jump_Imm32_Abs(&writer, target);
|
||||||
|
/* Assemble, if we can. */
|
||||||
|
if (writer.outbase == NULL)
|
||||||
|
{
|
||||||
|
length = writer.outptr - writer.outbase;
|
||||||
|
patch->detour = g_pSourcePawn->AllocatePageMemory(length);
|
||||||
|
if (patch->detour == NULL)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Ran out of memory!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
g_pSourcePawn->SetReadWrite(patch->detour);
|
||||||
|
writer.outbase = (jitcode_t)patch->detour;
|
||||||
|
writer.outptr = writer.outbase;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (true);
|
||||||
|
|
||||||
|
g_pSourcePawn->SetReadExecute(patch->detour);
|
||||||
|
|
||||||
|
unsigned char *source = (unsigned char *)patch->base + patch->offset;
|
||||||
|
Protect(source, 6, PAGE_READWRITE);
|
||||||
|
source[0] = 0xFF;
|
||||||
|
source[1] = 0x25;
|
||||||
|
*(void **)&source[2] = &patch->detour;
|
||||||
|
Protect(source, 6, PAGE_EXECUTE_READ);
|
||||||
|
|
||||||
|
patch->applied = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PrepPatch(const char *signature, const char *name, const char *platform, Patch *patch)
|
||||||
|
{
|
||||||
|
/* Get the base address of the function. */
|
||||||
|
if (!g_pGameConf->GetMemSig(signature, &patch->base) || patch->base == NULL)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Command filter could not find signature: %s", signature);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *value;
|
||||||
|
char keyname[255];
|
||||||
|
|
||||||
|
/* Get the verification bytes that will be written over. */
|
||||||
|
UTIL_Format(keyname, sizeof(keyname), "%s_Patch_%s", name, platform);
|
||||||
|
if ((value = g_pGameConf->GetKeyValue(keyname)) == NULL)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Command filter could not find key: %s", keyname);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
patch->search_len = UTIL_DecodeHexString(patch->search, sizeof(patch->search), value);
|
||||||
|
if (patch->search_len < 6)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Error decoding %s value, or not long enough", keyname);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the offset into the function. */
|
||||||
|
UTIL_Format(keyname, sizeof(keyname), "%s_Offset_%s", name, platform);
|
||||||
|
if ((value = g_pGameConf->GetKeyValue(keyname)) == NULL)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Command filter could not find key: %s", keyname);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
patch->offset = atoi(value);
|
||||||
|
if (patch->offset > 20000)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Command filter %s value is bogus", keyname);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the number of bytes to save from what was written over. */
|
||||||
|
patch->saveat = 0;
|
||||||
|
UTIL_Format(keyname, sizeof(keyname), "%s_Save_%s", name, platform);
|
||||||
|
if ((value = g_pGameConf->GetKeyValue(keyname)) != NULL)
|
||||||
|
{
|
||||||
|
patch->saveat = atoi(value);
|
||||||
|
if (patch->saveat >= patch->search_len)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Command filter %s value is too large", keyname);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get register for parameter, if any. */
|
||||||
|
patch->regparam = -1;
|
||||||
|
UTIL_Format(keyname, sizeof(keyname), "%s_Reg_%s", name, platform);
|
||||||
|
if ((value = g_pGameConf->GetKeyValue(keyname)) != NULL)
|
||||||
|
{
|
||||||
|
patch->regparam = atoi(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Everything loaded from gamedata, make sure the patch will succeed. */
|
||||||
|
unsigned char *address = (unsigned char *)patch->base + patch->offset;
|
||||||
|
for (size_t i = 0; i < patch->search_len; i++)
|
||||||
|
{
|
||||||
|
if (address[i] != patch->search[i])
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Command filter %s has changed (byte %x is not %x sub-offset %d)",
|
||||||
|
name, address[i], patch->search[i], i);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool dummy_hook_set = false;
|
||||||
|
void DummyHook()
|
||||||
|
{
|
||||||
|
if (dummy_hook_set)
|
||||||
|
{
|
||||||
|
dummy_hook_set = false;
|
||||||
|
RETURN_META(MRES_SUPERCEDE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BEGIN THE ACTUALLY GENERIC CODE.
|
* BEGIN THE ACTUALLY GENERIC CODE.
|
||||||
*/
|
*/
|
||||||
@@ -264,21 +574,23 @@ ConsoleDetours::ConsoleDetours() : status(FeatureStatus_Unknown)
|
|||||||
|
|
||||||
void ConsoleDetours::OnSourceModAllInitialized()
|
void ConsoleDetours::OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
m_pForward = forwardsys->CreateForwardEx("OnAnyCommand", ET_Hook, 3, NULL, Param_Cell,
|
m_pForward = g_Forwards.CreateForwardEx("OnAnyCommand", ET_Hook, 3, NULL, Param_Cell,
|
||||||
Param_String, Param_Cell);
|
Param_String, Param_Cell);
|
||||||
sharesys->AddCapabilityProvider(NULL, this, FEATURECAP_COMMANDLISTENER);
|
g_ShareSys.AddCapabilityProvider(NULL, this, FEATURECAP_COMMANDLISTENER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleDetours::OnSourceModShutdown()
|
void ConsoleDetours::OnSourceModShutdown()
|
||||||
{
|
{
|
||||||
for (StringHashMap<IChangeableForward *>::iterator iter = m_Listeners.iter();
|
List<Listener*>::iterator iter = m_Listeners.begin();
|
||||||
!iter.empty();
|
while (iter != m_Listeners.end())
|
||||||
iter.next())
|
|
||||||
{
|
{
|
||||||
forwardsys->ReleaseForward(iter->value);
|
Listener *listener = (*iter);
|
||||||
|
g_Forwards.ReleaseForward(listener->forward);
|
||||||
|
delete listener;
|
||||||
|
iter = m_Listeners.erase(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
forwardsys->ReleaseForward(m_pForward);
|
g_Forwards.ReleaseForward(m_pForward);
|
||||||
s_GenericHooker.Disable();
|
s_GenericHooker.Disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,15 +619,22 @@ bool ConsoleDetours::AddListener(IPluginFunction *fun, const char *command)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ke::AutoPtr<char[]> str(UTIL_ToLowerCase(command));
|
const char *str = UTIL_ToLowerCase(command);
|
||||||
IChangeableForward *forward;
|
Listener *listener;
|
||||||
if (!m_Listeners.retrieve(str.get(), &forward))
|
Listener **plistener = m_CmdLookup.retrieve(str);
|
||||||
|
if (plistener == NULL)
|
||||||
{
|
{
|
||||||
forward = forwardsys->CreateForwardEx(NULL, ET_Hook, 3, NULL, Param_Cell,
|
listener = new Listener;
|
||||||
Param_String, Param_Cell);
|
listener->forward = g_Forwards.CreateForwardEx(NULL, ET_Hook, 3, NULL, Param_Cell,
|
||||||
m_Listeners.insert(str.get(), forward);
|
Param_String, Param_Cell);
|
||||||
|
m_CmdLookup.insert(str, listener);
|
||||||
}
|
}
|
||||||
forward->AddFunction(fun);
|
else
|
||||||
|
{
|
||||||
|
listener = *plistener;
|
||||||
|
}
|
||||||
|
listener->forward->AddFunction(fun);
|
||||||
|
delete [] str;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -329,18 +648,21 @@ bool ConsoleDetours::RemoveListener(IPluginFunction *fun, const char *command)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ke::AutoPtr<char[]> str(UTIL_ToLowerCase(command));
|
const char *str = UTIL_ToLowerCase(command);
|
||||||
IChangeableForward *forward;
|
Listener *listener;
|
||||||
if (!m_Listeners.retrieve(str.get(), &forward))
|
Listener **plistener = m_CmdLookup.retrieve(str);
|
||||||
|
delete [] str;
|
||||||
|
if (plistener == NULL)
|
||||||
return false;
|
return false;
|
||||||
return forward->RemoveFunction(fun);
|
listener = *plistener;
|
||||||
|
return listener->forward->RemoveFunction(fun);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cell_t ConsoleDetours::InternalDispatch(int client, const ICommandArgs *args)
|
cell_t ConsoleDetours::InternalDispatch(int client, const CCommand& args)
|
||||||
{
|
{
|
||||||
char name[255];
|
char name[255];
|
||||||
const char *realname = args->Arg(0);
|
const char *realname = args.Arg(0);
|
||||||
size_t len = strlen(realname);
|
size_t len = strlen(realname);
|
||||||
|
|
||||||
// Disallow command strings that are too long, for now.
|
// Disallow command strings that are too long, for now.
|
||||||
@@ -359,7 +681,7 @@ cell_t ConsoleDetours::InternalDispatch(int client, const ICommandArgs *args)
|
|||||||
cell_t result = Pl_Continue;
|
cell_t result = Pl_Continue;
|
||||||
m_pForward->PushCell(client);
|
m_pForward->PushCell(client);
|
||||||
m_pForward->PushString(name);
|
m_pForward->PushString(name);
|
||||||
m_pForward->PushCell(args->ArgC() - 1);
|
m_pForward->PushCell(args.ArgC() - 1);
|
||||||
m_pForward->Execute(&result, NULL);
|
m_pForward->Execute(&result, NULL);
|
||||||
|
|
||||||
/* Don't let plugins block this. */
|
/* Don't let plugins block this. */
|
||||||
@@ -369,17 +691,18 @@ cell_t ConsoleDetours::InternalDispatch(int client, const ICommandArgs *args)
|
|||||||
if (result >= Pl_Handled)
|
if (result >= Pl_Handled)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
IChangeableForward *forward;
|
Listener **plistener = m_CmdLookup.retrieve(name);
|
||||||
if (!m_Listeners.retrieve(name, &forward))
|
if (plistener == NULL)
|
||||||
return result;
|
return result;
|
||||||
if (forward->GetFunctionCount() == 0)
|
Listener *listener = *plistener;
|
||||||
|
if (listener->forward->GetFunctionCount() == 0)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
cell_t result2 = Pl_Continue;
|
cell_t result2 = Pl_Continue;
|
||||||
forward->PushCell(client);
|
listener->forward->PushCell(client);
|
||||||
forward->PushString(name);
|
listener->forward->PushString(name);
|
||||||
forward->PushCell(args->ArgC() - 1);
|
listener->forward->PushCell(args.ArgC() - 1);
|
||||||
forward->Execute(&result2, NULL);
|
listener->forward->Execute(&result2, NULL);
|
||||||
|
|
||||||
if (result2 > result)
|
if (result2 > result)
|
||||||
result = result2;
|
result = result2;
|
||||||
@@ -398,12 +721,27 @@ cell_t ConsoleDetours::Dispatch(ConCommand *pBase)
|
|||||||
{
|
{
|
||||||
CCommand args;
|
CCommand args;
|
||||||
#endif
|
#endif
|
||||||
EngineArgs cargs(args);
|
g_HL2.PushCommandStack(&args);
|
||||||
cell_t res;
|
cell_t res = g_ConsoleDetours.InternalDispatch(g_ConCmds.GetCommandClient(), args);
|
||||||
|
g_HL2.PopCommandStack();
|
||||||
|
|
||||||
|
#if SH_IMPL_VERSION < 4
|
||||||
|
if (res >= Pl_Handled)
|
||||||
{
|
{
|
||||||
AutoEnterCommand autoEnterCommand(&cargs);
|
/* See bug 4020 - we can't optimize this because looking at the vtable
|
||||||
res = g_ConsoleDetours.InternalDispatch(sCoreProviderImpl.CommandClient(), &cargs);
|
* is probably more expensive, since there's no SH_GET_ORIG_VFNPTR_ENTRY.
|
||||||
|
*/
|
||||||
|
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pBase, DummyHook, false);
|
||||||
|
dummy_hook_set = true;
|
||||||
|
pBase->Dispatch();
|
||||||
|
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, pBase, DummyHook, false);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Make sure the command gets invoked. See bug 4019 on making this better. */
|
||||||
|
pBase->Dispatch();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,12 +33,8 @@
|
|||||||
|
|
||||||
#include "sm_globals.h"
|
#include "sm_globals.h"
|
||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include <IForwardSys.h>
|
#include "ForwardSys.h"
|
||||||
#include <sm_stringhashmap.h>
|
#include <sm_trie_tpl.h>
|
||||||
|
|
||||||
namespace SourceMod {
|
|
||||||
class ICommandArgs;
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
class ConsoleDetours :
|
class ConsoleDetours :
|
||||||
public SMGlobalClass,
|
public SMGlobalClass,
|
||||||
@@ -47,6 +43,10 @@ class ConsoleDetours :
|
|||||||
friend class PlayerManager;
|
friend class PlayerManager;
|
||||||
friend class GenericCommandHooker;
|
friend class GenericCommandHooker;
|
||||||
|
|
||||||
|
struct Listener
|
||||||
|
{
|
||||||
|
IChangeableForward *forward;
|
||||||
|
};
|
||||||
public:
|
public:
|
||||||
ConsoleDetours();
|
ConsoleDetours();
|
||||||
public: //SMGlobalClass
|
public: //SMGlobalClass
|
||||||
@@ -58,7 +58,7 @@ public:
|
|||||||
bool AddListener(IPluginFunction *fun, const char *command);
|
bool AddListener(IPluginFunction *fun, const char *command);
|
||||||
bool RemoveListener(IPluginFunction *fun, const char *command);
|
bool RemoveListener(IPluginFunction *fun, const char *command);
|
||||||
private:
|
private:
|
||||||
cell_t InternalDispatch(int client, const SourceMod::ICommandArgs *args);
|
cell_t InternalDispatch(int client, const CCommand& args);
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
static cell_t Dispatch(ConCommand *pBase, const CCommand& args);
|
static cell_t Dispatch(ConCommand *pBase, const CCommand& args);
|
||||||
#else
|
#else
|
||||||
@@ -73,7 +73,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
FeatureStatus status;
|
FeatureStatus status;
|
||||||
IChangeableForward *m_pForward;
|
IChangeableForward *m_pForward;
|
||||||
StringHashMap<IChangeableForward *> m_Listeners;
|
KTrie<Listener*> m_CmdLookup;
|
||||||
|
List<Listener*> m_Listeners;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ConsoleDetours g_ConsoleDetours;
|
extern ConsoleDetours g_ConsoleDetours;
|
||||||
|
|||||||
+85
-98
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -33,20 +33,14 @@
|
|||||||
#include "CoreConfig.h"
|
#include "CoreConfig.h"
|
||||||
#include "sourcemod.h"
|
#include "sourcemod.h"
|
||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include "sm_stringutil.h"
|
#include "sm_srvcmds.h"
|
||||||
#include "Logger.h"
|
|
||||||
#include "frame_hooks.h"
|
|
||||||
#include "logic_bridge.h"
|
|
||||||
#include "compat_wrappers.h"
|
|
||||||
#include <sourcemod_version.h>
|
#include <sourcemod_version.h>
|
||||||
#include <amtl/os/am-path.h>
|
#include "sm_stringutil.h"
|
||||||
#include <amtl/os/am-fsutil.h>
|
#include "LibrarySys.h"
|
||||||
#include <sh_list.h>
|
#include "Logger.h"
|
||||||
#include <IForwardSys.h>
|
#include "PluginSys.h"
|
||||||
#include <bridge/include/IScriptManager.h>
|
#include "ForwardSys.h"
|
||||||
#include <bridge/include/ILogger.h>
|
#include "frame_hooks.h"
|
||||||
|
|
||||||
using namespace SourceHook;
|
|
||||||
|
|
||||||
#ifdef PLATFORM_WINDOWS
|
#ifdef PLATFORM_WINDOWS
|
||||||
ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file");
|
ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file");
|
||||||
@@ -70,9 +64,17 @@ void CheckAndFinalizeConfigs();
|
|||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
|
SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
|
||||||
void Hook_ExecDispatchPre(const CCommand &cmd)
|
void Hook_ExecDispatchPre(const CCommand &cmd)
|
||||||
#else
|
#elif SOURCE_ENGINE == SE_DARKMESSIAH
|
||||||
SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
|
SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
|
||||||
void Hook_ExecDispatchPre()
|
void Hook_ExecDispatchPre()
|
||||||
|
#else
|
||||||
|
# if SH_IMPL_VERSION >= 4
|
||||||
|
extern int __SourceHook_FHAddConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0<void>);
|
||||||
|
# else
|
||||||
|
extern bool __SourceHook_FHAddConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0<void>);
|
||||||
|
# endif
|
||||||
|
extern bool __SourceHook_FHRemoveConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0<void>);
|
||||||
|
void Hook_ExecDispatchPre()
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE <= SE_DARKMESSIAH
|
#if SOURCE_ENGINE <= SE_DARKMESSIAH
|
||||||
@@ -111,13 +113,13 @@ void CheckAndFinalizeConfigs()
|
|||||||
|
|
||||||
void CoreConfig::OnSourceModAllInitialized()
|
void CoreConfig::OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
rootmenu->AddRootConsoleCommand3("config", "Set core configuration options", this);
|
g_RootMenu.AddRootConsoleCommand("config", "Set core configuration options", this);
|
||||||
g_pOnServerCfg = forwardsys->CreateForward("OnServerCfg", ET_Ignore, 0, NULL);
|
g_pOnServerCfg = g_Forwards.CreateForward("OnServerCfg", ET_Ignore, 0, NULL);
|
||||||
g_pOnConfigsExecuted = forwardsys->CreateForward("OnConfigsExecuted", ET_Ignore, 0, NULL);
|
g_pOnConfigsExecuted = g_Forwards.CreateForward("OnConfigsExecuted", ET_Ignore, 0, NULL);
|
||||||
g_pOnAutoConfigsBuffered = forwardsys->CreateForward("OnAutoConfigsBuffered", ET_Ignore, 0, NULL);
|
g_pOnAutoConfigsBuffered = g_Forwards.CreateForward("OnAutoConfigsBuffered", ET_Ignore, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreConfig::CoreConfig()
|
CoreConfig::CoreConfig() : m_Strings(512)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,15 +129,15 @@ CoreConfig::~CoreConfig()
|
|||||||
|
|
||||||
void CoreConfig::OnSourceModShutdown()
|
void CoreConfig::OnSourceModShutdown()
|
||||||
{
|
{
|
||||||
rootmenu->RemoveRootConsoleCommand("config", this);
|
g_RootMenu.RemoveRootConsoleCommand("config", this);
|
||||||
forwardsys->ReleaseForward(g_pOnServerCfg);
|
g_Forwards.ReleaseForward(g_pOnServerCfg);
|
||||||
forwardsys->ReleaseForward(g_pOnConfigsExecuted);
|
g_Forwards.ReleaseForward(g_pOnConfigsExecuted);
|
||||||
forwardsys->ReleaseForward(g_pOnAutoConfigsBuffered);
|
g_Forwards.ReleaseForward(g_pOnAutoConfigsBuffered);
|
||||||
|
|
||||||
if (g_pExecPtr != NULL)
|
if (g_pExecPtr != NULL)
|
||||||
{
|
{
|
||||||
SH_REMOVE_HOOK(ConCommand, Dispatch, g_pExecPtr, SH_STATIC(Hook_ExecDispatchPre), false);
|
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPre, false);
|
||||||
SH_REMOVE_HOOK(ConCommand, Dispatch, g_pExecPtr, SH_STATIC(Hook_ExecDispatchPost), true);
|
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPost, true);
|
||||||
g_pExecPtr = NULL;
|
g_pExecPtr = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,8 +162,8 @@ void CoreConfig::OnSourceModLevelChange(const char *mapName)
|
|||||||
g_pExecPtr = FindCommand("exec");
|
g_pExecPtr = FindCommand("exec");
|
||||||
if (g_pExecPtr != NULL)
|
if (g_pExecPtr != NULL)
|
||||||
{
|
{
|
||||||
SH_ADD_HOOK(ConCommand, Dispatch, g_pExecPtr, SH_STATIC(Hook_ExecDispatchPre), false);
|
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPre, false);
|
||||||
SH_ADD_HOOK(ConCommand, Dispatch, g_pExecPtr, SH_STATIC(Hook_ExecDispatchPost), true);
|
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPost, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -177,45 +179,44 @@ void CoreConfig::OnSourceModLevelChange(const char *mapName)
|
|||||||
g_bGotTrigger = false;
|
g_bGotTrigger = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreConfig::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
|
void CoreConfig::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
|
||||||
{
|
{
|
||||||
int argcount = command->ArgC();
|
int argcount = command.ArgC();
|
||||||
if (argcount >= 4)
|
if (argcount >= 4)
|
||||||
{
|
{
|
||||||
const char *option = command->Arg(2);
|
const char *option = command.Arg(2);
|
||||||
const char *value = command->Arg(3);
|
const char *value = command.Arg(3);
|
||||||
|
|
||||||
char error[255];
|
char error[255];
|
||||||
|
|
||||||
ConfigResult res = SetConfigOption(option, value, ConfigSource_Console, error, sizeof(error));
|
ConfigResult res = SetConfigOption(option, value, ConfigSource_Console, error, sizeof(error));
|
||||||
|
|
||||||
if (res == ConfigResult_Reject)
|
if (res == ConfigResult_Reject)
|
||||||
{
|
{
|
||||||
UTIL_ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\". (%s)", option, value, error);
|
g_RootMenu.ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\". (%s)", option, value, error);
|
||||||
|
} else if (res == ConfigResult_Ignore) {
|
||||||
|
g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option);
|
||||||
} else {
|
} else {
|
||||||
if (res == ConfigResult_Ignore) {
|
g_RootMenu.ConsolePrint("[SM] Config option \"%s\" successfully set to \"%s\".", option, value);
|
||||||
UTIL_ConsolePrint("[SM] WARNING: Config option \"%s\" is not registered.", option);
|
|
||||||
}
|
|
||||||
|
|
||||||
UTIL_ConsolePrint("[SM] Config option \"%s\" set to \"%s\".", option, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else if (argcount >= 3) {
|
} else if (argcount >= 3) {
|
||||||
const char *option = command->Arg(2);
|
const char *option = command.Arg(2);
|
||||||
|
|
||||||
const char *value = GetCoreConfigValue(option);
|
const char *value = GetCoreConfigValue(option);
|
||||||
|
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
{
|
{
|
||||||
UTIL_ConsolePrint("[SM] No such config option \"%s\" exists.", option);
|
g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option);
|
||||||
} else {
|
} else {
|
||||||
UTIL_ConsolePrint("[SM] Config option \"%s\" is set to \"%s\".", option, value);
|
g_RootMenu.ConsolePrint("[SM] Config option \"%s\" is set to \"%s\".", option, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UTIL_ConsolePrint("[SM] Usage: sm config <option> [value]");
|
g_RootMenu.ConsolePrint("[SM] Usage: sm config <option> [value]");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreConfig::Initialize()
|
void CoreConfig::Initialize()
|
||||||
@@ -232,7 +233,7 @@ void CoreConfig::Initialize()
|
|||||||
*/
|
*/
|
||||||
if (corecfg)
|
if (corecfg)
|
||||||
{
|
{
|
||||||
ke::path::Format(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), corecfg);
|
g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), corecfg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -241,23 +242,24 @@ void CoreConfig::Initialize()
|
|||||||
/* Format path to config file */
|
/* Format path to config file */
|
||||||
if (basepath)
|
if (basepath)
|
||||||
{
|
{
|
||||||
ke::path::Format(filePath, sizeof(filePath), "%s/%s/%s", g_SourceMod.GetGamePath(), basepath, "configs/core.cfg");
|
g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s/%s", g_SourceMod.GetGamePath(), basepath, "configs/core.cfg");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ke::path::Format(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), sm_corecfgfile.GetDefault());
|
g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), sm_corecfgfile.GetDefault());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset cached key values */
|
/* Reset cached key values */
|
||||||
m_KeyValues.clear();
|
m_KeyValues.clear();
|
||||||
|
m_Strings.Reset();
|
||||||
|
|
||||||
/* Parse config file */
|
/* Parse config file */
|
||||||
if ((err=textparsers->ParseFile_SMC(filePath, this, NULL)) != SMCError_Okay)
|
if ((err=textparsers->ParseFile_SMC(filePath, this, NULL)) != SMCError_Okay)
|
||||||
{
|
{
|
||||||
/* :TODO: This won't actually log or print anything :( - So fix that somehow */
|
/* :TODO: This won't actually log or print anything :( - So fix that somehow */
|
||||||
const char *error = textparsers->GetSMCErrorString(err);
|
const char *error = textparsers->GetSMCErrorString(err);
|
||||||
logger->LogFatal("[SM] Error encountered parsing core config file: %s", error ? error : "");
|
g_Logger.LogFatal("[SM] Error encountered parsing core config file: %s", error ? error : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +271,7 @@ SMCResult CoreConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key,
|
|||||||
if (err == ConfigResult_Reject)
|
if (err == ConfigResult_Reject)
|
||||||
{
|
{
|
||||||
/* This is a fatal error */
|
/* This is a fatal error */
|
||||||
logger->LogFatal("Config error (key: %s) (value: %s) %s", key, value, error);
|
g_Logger.LogFatal("Config error (key: %s) (value: %s) %s", key, value, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SMCResult_Continue;
|
return SMCResult_Continue;
|
||||||
@@ -277,7 +279,7 @@ SMCResult CoreConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key,
|
|||||||
|
|
||||||
ConfigResult CoreConfig::SetConfigOption(const char *option, const char *value, ConfigSource source, char *error, size_t maxlength)
|
ConfigResult CoreConfig::SetConfigOption(const char *option, const char *value, ConfigSource source, char *error, size_t maxlength)
|
||||||
{
|
{
|
||||||
ConfigResult result = ConfigResult_Ignore;
|
ConfigResult result;
|
||||||
|
|
||||||
/* Notify! */
|
/* Notify! */
|
||||||
SMGlobalClass *pBase = SMGlobalClass::head;
|
SMGlobalClass *pBase = SMGlobalClass::head;
|
||||||
@@ -285,23 +287,24 @@ ConfigResult CoreConfig::SetConfigOption(const char *option, const char *value,
|
|||||||
{
|
{
|
||||||
if ((result = pBase->OnSourceModConfigChanged(option, value, source, error, maxlength)) != ConfigResult_Ignore)
|
if ((result = pBase->OnSourceModConfigChanged(option, value, source, error, maxlength)) != ConfigResult_Ignore)
|
||||||
{
|
{
|
||||||
break;
|
return result;
|
||||||
}
|
}
|
||||||
pBase = pBase->m_pGlobalClassNext;
|
pBase = pBase->m_pGlobalClassNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
ke::AString vstr(value);
|
m_KeyValues.replace(option, m_Strings.AddString(value));
|
||||||
m_KeyValues.replace(option, ke::Move(vstr));
|
|
||||||
|
|
||||||
return result;
|
return ConfigResult_Ignore;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CoreConfig::GetCoreConfigValue(const char *key)
|
const char *CoreConfig::GetCoreConfigValue(const char *key)
|
||||||
{
|
{
|
||||||
StringHashMap<ke::AString>::Result r = m_KeyValues.find(key);
|
int *pKey = m_KeyValues.retrieve(key);
|
||||||
if (!r.found())
|
if (pKey == NULL)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
return r->value.chars();
|
}
|
||||||
|
return m_Strings.GetString(*pKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SM_AreConfigsExecuted()
|
bool SM_AreConfigsExecuted()
|
||||||
@@ -318,7 +321,7 @@ inline bool IsPathSepChar(char c)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create)
|
bool SM_ExecuteConfig(CPlugin *pl, AutoConfig *cfg, bool can_create)
|
||||||
{
|
{
|
||||||
bool will_create = false;
|
bool will_create = false;
|
||||||
|
|
||||||
@@ -336,12 +339,12 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create)
|
|||||||
|
|
||||||
g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "cfg/%s", folder);
|
g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "cfg/%s", folder);
|
||||||
|
|
||||||
if (!ke::file::IsDirectory(path))
|
if (!g_LibSys.IsPathDirectory(path))
|
||||||
{
|
{
|
||||||
char *cur_ptr = path;
|
char *cur_ptr = path;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
ke::path::Format(path, sizeof(path), "%s", folder);
|
g_LibSys.PathFormat(path, sizeof(path), "%s", folder);
|
||||||
len = g_SourceMod.BuildPath(Path_Game, build, sizeof(build), "cfg");
|
len = g_SourceMod.BuildPath(Path_Game, build, sizeof(build), "cfg");
|
||||||
|
|
||||||
do
|
do
|
||||||
@@ -362,12 +365,14 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create)
|
|||||||
{
|
{
|
||||||
next_ptr = NULL;
|
next_ptr = NULL;
|
||||||
}
|
}
|
||||||
len += ke::path::Format(&build[len],
|
len += g_LibSys.PathFormat(&build[len],
|
||||||
sizeof(build)-len,
|
sizeof(build)-len,
|
||||||
"/%s",
|
"/%s",
|
||||||
cur_ptr);
|
cur_ptr);
|
||||||
if (!ke::file::CreateDirectory(build))
|
if (!g_LibSys.CreateFolder(build))
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
cur_ptr = next_ptr;
|
cur_ptr = next_ptr;
|
||||||
} while (cur_ptr);
|
} while (cur_ptr);
|
||||||
}
|
}
|
||||||
@@ -379,13 +384,13 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create)
|
|||||||
|
|
||||||
if (cfg->folder.size())
|
if (cfg->folder.size())
|
||||||
{
|
{
|
||||||
ke::path::Format(local,
|
g_LibSys.PathFormat(local,
|
||||||
sizeof(local),
|
sizeof(local),
|
||||||
"%s/%s.cfg",
|
"%s/%s.cfg",
|
||||||
cfg->folder.c_str(),
|
cfg->folder.c_str(),
|
||||||
cfg->autocfg.c_str());
|
cfg->autocfg.c_str());
|
||||||
} else {
|
} else {
|
||||||
ke::path::Format(local,
|
g_LibSys.PathFormat(local,
|
||||||
sizeof(local),
|
sizeof(local),
|
||||||
"%s.cfg",
|
"%s.cfg",
|
||||||
cfg->autocfg.c_str());
|
cfg->autocfg.c_str());
|
||||||
@@ -393,7 +398,7 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create)
|
|||||||
|
|
||||||
g_SourceMod.BuildPath(Path_Game, file, sizeof(file), "cfg/%s", local);
|
g_SourceMod.BuildPath(Path_Game, file, sizeof(file), "cfg/%s", local);
|
||||||
|
|
||||||
bool file_exists = ke::file::IsFile(file);
|
bool file_exists = g_LibSys.IsPathFile(file);
|
||||||
if (!file_exists && will_create)
|
if (!file_exists && will_create)
|
||||||
{
|
{
|
||||||
List<const ConVar *> *convars = NULL;
|
List<const ConVar *> *convars = NULL;
|
||||||
@@ -403,7 +408,7 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create)
|
|||||||
FILE *fp = fopen(file, "wt");
|
FILE *fp = fopen(file, "wt");
|
||||||
if (fp)
|
if (fp)
|
||||||
{
|
{
|
||||||
fprintf(fp, "// This file was auto-generated by SourceMod (v%s)\n", SOURCEMOD_VERSION);
|
fprintf(fp, "// This file was auto-generated by SourceMod (v%s)\n", SM_VERSION_STRING);
|
||||||
fprintf(fp, "// ConVars for plugin \"%s\"\n", pl->GetFilename());
|
fprintf(fp, "// ConVars for plugin \"%s\"\n", pl->GetFilename());
|
||||||
fprintf(fp, "\n\n");
|
fprintf(fp, "\n\n");
|
||||||
|
|
||||||
@@ -412,11 +417,8 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create)
|
|||||||
for (iter = convars->begin(); iter != convars->end(); iter++)
|
for (iter = convars->begin(); iter != convars->end(); iter++)
|
||||||
{
|
{
|
||||||
const ConVar *cvar = (*iter);
|
const ConVar *cvar = (*iter);
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
|
||||||
if (cvar->IsFlagSet(FCVAR_DONTRECORD))
|
if ((cvar->GetFlags() & FCVAR_DONTRECORD) == FCVAR_DONTRECORD)
|
||||||
#else
|
|
||||||
if (cvar->IsBitSet(FCVAR_DONTRECORD))
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -425,7 +427,7 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create)
|
|||||||
char *dptr = descr;
|
char *dptr = descr;
|
||||||
|
|
||||||
/* Print comments until there is no more */
|
/* Print comments until there is no more */
|
||||||
ke::SafeStrcpy(descr, sizeof(descr), cvar->GetHelpText());
|
strncopy(descr, cvar->GetHelpText(), sizeof(descr));
|
||||||
while (*dptr != '\0')
|
while (*dptr != '\0')
|
||||||
{
|
{
|
||||||
/* Find the next line */
|
/* Find the next line */
|
||||||
@@ -465,7 +467,7 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger->LogError("Failed to auto generate config for %s, make sure the directory has write permission.", pl->GetFilename());
|
g_Logger.LogError("Failed to auto generate config for %s, make sure the directory has write permission.", pl->GetFilename());
|
||||||
return can_create;
|
return can_create;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -474,7 +476,7 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create)
|
|||||||
if (file_exists)
|
if (file_exists)
|
||||||
{
|
{
|
||||||
char cmd[255];
|
char cmd[255];
|
||||||
ke::SafeSprintf(cmd, sizeof(cmd), "exec %s\n", local);
|
UTIL_Format(cmd, sizeof(cmd), "exec %s\n", local);
|
||||||
engine->ServerCommand(cmd);
|
engine->ServerCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,10 +500,10 @@ void SM_DoSingleExecFwds(IPluginContext *ctx)
|
|||||||
|
|
||||||
void SM_ConfigsExecuted_Plugin(unsigned int serial)
|
void SM_ConfigsExecuted_Plugin(unsigned int serial)
|
||||||
{
|
{
|
||||||
IPluginIterator *iter = scripts->GetPluginIterator();
|
IPluginIterator *iter = g_PluginSys.GetPluginIterator();
|
||||||
while (iter->MorePlugins())
|
while (iter->MorePlugins())
|
||||||
{
|
{
|
||||||
IPlugin *plugin = iter->GetPlugin();
|
CPlugin *plugin = (CPlugin *)(iter->GetPlugin());
|
||||||
if (plugin->GetSerial() == serial)
|
if (plugin->GetSerial() == serial)
|
||||||
{
|
{
|
||||||
SM_DoSingleExecFwds(plugin->GetBaseContext());
|
SM_DoSingleExecFwds(plugin->GetBaseContext());
|
||||||
@@ -514,7 +516,7 @@ void SM_ConfigsExecuted_Plugin(unsigned int serial)
|
|||||||
|
|
||||||
void SM_ExecuteForPlugin(IPluginContext *ctx)
|
void SM_ExecuteForPlugin(IPluginContext *ctx)
|
||||||
{
|
{
|
||||||
SMPlugin *plugin = scripts->FindPluginByContext(ctx->GetContext());
|
CPlugin *plugin = (CPlugin *)g_PluginSys.GetPluginByCtx(ctx->GetContext());
|
||||||
|
|
||||||
unsigned int num = plugin->GetConfigCount();
|
unsigned int num = plugin->GetConfigCount();
|
||||||
if (!num)
|
if (!num)
|
||||||
@@ -529,7 +531,7 @@ void SM_ExecuteForPlugin(IPluginContext *ctx)
|
|||||||
can_create = SM_ExecuteConfig(plugin, plugin->GetConfig(i), can_create);
|
can_create = SM_ExecuteConfig(plugin, plugin->GetConfig(i), can_create);
|
||||||
}
|
}
|
||||||
char cmd[255];
|
char cmd[255];
|
||||||
ke::SafeSprintf(cmd, sizeof(cmd), "sm_internal 2 %d\n", plugin->GetSerial());
|
UTIL_Format(cmd, sizeof(cmd), "sm internal 2 %d\n", plugin->GetSerial());
|
||||||
engine->ServerCommand(cmd);
|
engine->ServerCommand(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -543,17 +545,19 @@ void SM_ExecuteAllConfigs()
|
|||||||
|
|
||||||
engine->ServerCommand("exec sourcemod/sourcemod.cfg\n");
|
engine->ServerCommand("exec sourcemod/sourcemod.cfg\n");
|
||||||
|
|
||||||
AutoPluginList plugins(scripts);
|
IPluginIterator *iter = g_PluginSys.GetPluginIterator();
|
||||||
for (size_t i = 0; i < plugins->size(); i++)
|
while (iter->MorePlugins())
|
||||||
{
|
{
|
||||||
SMPlugin *plugin = plugins->at(i);
|
CPlugin *plugin = (CPlugin *)(iter->GetPlugin());
|
||||||
unsigned int num = plugin->GetConfigCount();
|
unsigned int num = plugin->GetConfigCount();
|
||||||
bool can_create = true;
|
bool can_create = true;
|
||||||
for (unsigned int i=0; i<num; i++)
|
for (unsigned int i=0; i<num; i++)
|
||||||
{
|
{
|
||||||
can_create = SM_ExecuteConfig(plugin, plugin->GetConfig(i), can_create);
|
can_create = SM_ExecuteConfig(plugin, plugin->GetConfig(i), can_create);
|
||||||
}
|
}
|
||||||
|
iter->NextPlugin();
|
||||||
}
|
}
|
||||||
|
iter->Release();
|
||||||
|
|
||||||
g_bGotServerStart = true;
|
g_bGotServerStart = true;
|
||||||
CheckAndFinalizeConfigs();
|
CheckAndFinalizeConfigs();
|
||||||
@@ -576,24 +580,7 @@ void SM_InternalCmdTrigger()
|
|||||||
{
|
{
|
||||||
/* Order is important here. We need to buffer things before we send the command out. */
|
/* Order is important here. We need to buffer things before we send the command out. */
|
||||||
g_pOnAutoConfigsBuffered->Execute(NULL);
|
g_pOnAutoConfigsBuffered->Execute(NULL);
|
||||||
engine->ServerCommand("sm_internal 1\n");
|
engine->ServerCommand("sm internal 1\n");
|
||||||
g_PendingInternalPush = false;
|
g_PendingInternalPush = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CON_COMMAND(sm_internal, "")
|
|
||||||
{
|
|
||||||
#if SOURCE_ENGINE <= SE_DARKMESSIAH
|
|
||||||
CCommand args;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (args.ArgC() < 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const char *arg = args.Arg(1);
|
|
||||||
if (strcmp(arg, "1") == 0) {
|
|
||||||
SM_ConfigsExecuted_Global();
|
|
||||||
} else if (strcmp(arg, "2") == 0) {
|
|
||||||
if (args.ArgC() >= 3)
|
|
||||||
SM_ConfigsExecuted_Plugin(atoi(args.Arg(2)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+6
-5
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -35,8 +35,8 @@
|
|||||||
#include "sm_globals.h"
|
#include "sm_globals.h"
|
||||||
#include <ITextParsers.h>
|
#include <ITextParsers.h>
|
||||||
#include <IRootConsoleMenu.h>
|
#include <IRootConsoleMenu.h>
|
||||||
#include <am-string.h>
|
#include <sm_trie_tpl.h>
|
||||||
#include <sm_stringhashmap.h>
|
#include "sm_memtable.h"
|
||||||
|
|
||||||
using namespace SourceMod;
|
using namespace SourceMod;
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ public: // SMGlobalClass
|
|||||||
public: // ITextListener_SMC
|
public: // ITextListener_SMC
|
||||||
SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
|
SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
|
||||||
public: // IRootConsoleCommand
|
public: // IRootConsoleCommand
|
||||||
void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override;
|
void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Initializes CoreConfig by reading from core.cfg file
|
* Initializes CoreConfig by reading from core.cfg file
|
||||||
@@ -68,7 +68,8 @@ private:
|
|||||||
*/
|
*/
|
||||||
ConfigResult SetConfigOption(const char *option, const char *value, ConfigSource, char *Error, size_t maxlength);
|
ConfigResult SetConfigOption(const char *option, const char *value, ConfigSource, char *Error, size_t maxlength);
|
||||||
private:
|
private:
|
||||||
StringHashMap<ke::AString> m_KeyValues;
|
BaseStringTable m_Strings;
|
||||||
|
KTrie<int> m_KeyValues;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern bool SM_AreConfigsExecuted();
|
extern bool SM_AreConfigsExecuted();
|
||||||
|
|||||||
@@ -0,0 +1,199 @@
|
|||||||
|
/**
|
||||||
|
* vim: set ts=4 :
|
||||||
|
* =============================================================================
|
||||||
|
* SourceMod
|
||||||
|
* Copyright (C) 2004-2008 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 "sm_globals.h"
|
||||||
|
#include "sourcemm_api.h"
|
||||||
|
#include "Tlhelp32.h"
|
||||||
|
#include "LibrarySys.h"
|
||||||
|
#include "minidump.h"
|
||||||
|
#include "sm_stringutil.h"
|
||||||
|
|
||||||
|
bool HookImportAddrTable(BYTE *base, const char *func, DWORD hookfunc, char *err, size_t maxlength)
|
||||||
|
{
|
||||||
|
IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *)base;
|
||||||
|
if (dos->e_magic != IMAGE_DOS_SIGNATURE)
|
||||||
|
{
|
||||||
|
UTIL_Format(err, maxlength, "%s", "Could not detect valid DOS signature");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMAGE_NT_HEADERS *nt = (IMAGE_NT_HEADERS *)(base + dos->e_lfanew);
|
||||||
|
if (nt->Signature != IMAGE_NT_SIGNATURE)
|
||||||
|
{
|
||||||
|
UTIL_Format(err, maxlength, "%s", "Could not detect valid NT signature");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMAGE_IMPORT_DESCRIPTOR *desc =
|
||||||
|
(IMAGE_IMPORT_DESCRIPTOR *)
|
||||||
|
(base + nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
|
||||||
|
if (base == (BYTE *)desc)
|
||||||
|
{
|
||||||
|
UTIL_Format(err, maxlength, "%s", "Could not find IAT");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool entryFound = false;
|
||||||
|
while (desc->Name)
|
||||||
|
{
|
||||||
|
if (desc->FirstThunk != 0)
|
||||||
|
{
|
||||||
|
IMAGE_THUNK_DATA *data = (IMAGE_THUNK_DATA *)(base + desc->OriginalFirstThunk);
|
||||||
|
DWORD *iat = (DWORD *)(base + desc->FirstThunk);
|
||||||
|
while (data->u1.Function)
|
||||||
|
{
|
||||||
|
if ((data->u1.Ordinal & IMAGE_ORDINAL_FLAG32) != IMAGE_ORDINAL_FLAG32)
|
||||||
|
{
|
||||||
|
IMAGE_IMPORT_BY_NAME *import = (IMAGE_IMPORT_BY_NAME *)(base + data->u1.AddressOfData);
|
||||||
|
if (strcmp((char *)import->Name, func) == 0)
|
||||||
|
{
|
||||||
|
DWORD oldprot, oldprot2;
|
||||||
|
VirtualProtect(iat, 4, PAGE_READWRITE, &oldprot);
|
||||||
|
*iat = hookfunc;
|
||||||
|
VirtualProtect(iat, 4, oldprot, &oldprot2);
|
||||||
|
entryFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data++;
|
||||||
|
iat++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
desc++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!entryFound)
|
||||||
|
{
|
||||||
|
UTIL_Format(err, maxlength, "Could not find IAT entry for %s", func);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL
|
||||||
|
WINAPI
|
||||||
|
MiniDumpWriteDump2(
|
||||||
|
IN HANDLE hProcess,
|
||||||
|
IN DWORD ProcessId,
|
||||||
|
IN HANDLE hFile,
|
||||||
|
IN MINIDUMP_TYPE DumpType,
|
||||||
|
IN CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, OPTIONAL
|
||||||
|
IN CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, OPTIONAL
|
||||||
|
IN CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam OPTIONAL
|
||||||
|
)
|
||||||
|
{
|
||||||
|
DumpType = (MINIDUMP_TYPE)((int)DumpType|MiniDumpWithFullMemory|MiniDumpWithHandleData);
|
||||||
|
return MiniDumpWriteDump(hProcess, ProcessId, hFile, DumpType, ExceptionParam, UserStreamParam, CallbackParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
FARPROC WINAPI GetProcAddress2(HMODULE hModule, LPCSTR lpProcName)
|
||||||
|
{
|
||||||
|
if (strcmp(lpProcName, "MiniDumpWriteDump") == 0)
|
||||||
|
{
|
||||||
|
return (FARPROC)MiniDumpWriteDump2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetProcAddress(hModule, lpProcName);
|
||||||
|
}
|
||||||
|
|
||||||
|
HMODULE WINAPI LoadLibraryEx2(LPCTSTR lpFileName, HANDLE hFile, DWORD dwFlags)
|
||||||
|
{
|
||||||
|
HMODULE lib = LoadLibraryEx(lpFileName, hFile, dwFlags);
|
||||||
|
|
||||||
|
/* Steam.dll seems to get loaded using an abs path, thus the use of stristr() */
|
||||||
|
if (stristr(lpFileName, "steam.dll"))
|
||||||
|
{
|
||||||
|
char err[64];
|
||||||
|
if (!HookImportAddrTable((BYTE *)lib, "GetProcAddress", (DWORD)GetProcAddress2, err, sizeof(err)))
|
||||||
|
{
|
||||||
|
Error("[SM] %s in steam.dll\n", err);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lib;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CrazyWindowsDebugger : public SMGlobalClass
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void OnSourceModAllInitialized()
|
||||||
|
{
|
||||||
|
HANDLE hModuleList = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
|
||||||
|
MODULEENTRY32 me32;
|
||||||
|
BYTE *engine = NULL;
|
||||||
|
BYTE *steam = NULL;
|
||||||
|
char err[64];
|
||||||
|
|
||||||
|
me32.dwSize = sizeof(MODULEENTRY32);
|
||||||
|
|
||||||
|
if (!Module32First(hModuleList, &me32))
|
||||||
|
{
|
||||||
|
Error("Could not initialize crazy debugger!");
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (strcasecmp(me32.szModule, "engine.dll") == 0)
|
||||||
|
{
|
||||||
|
engine = me32.modBaseAddr;
|
||||||
|
}
|
||||||
|
else if (strcasecmp(me32.szModule, "steam.dll") == 0)
|
||||||
|
{
|
||||||
|
steam = me32.modBaseAddr;
|
||||||
|
}
|
||||||
|
} while (Module32Next(hModuleList, &me32));
|
||||||
|
|
||||||
|
CloseHandle(hModuleList);
|
||||||
|
|
||||||
|
/* This really should not happen, but ... */
|
||||||
|
if (!engine)
|
||||||
|
{
|
||||||
|
Error("[SM] Could not find engine.dll\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Steam.dll isn't loaded yet */
|
||||||
|
if (!steam)
|
||||||
|
{
|
||||||
|
if (!HookImportAddrTable(engine, "LoadLibraryExA", (DWORD)LoadLibraryEx2, err, sizeof(err)))
|
||||||
|
{
|
||||||
|
Error("[SM] %s in engine.dll)\n", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!HookImportAddrTable(steam, "GetProcAddress", (DWORD)GetProcAddress2, err, sizeof(err)))
|
||||||
|
{
|
||||||
|
Error("[SM] %s in steam.dll)\n", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} s_CrazyDebugger;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -30,14 +30,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Database.h"
|
#include "Database.h"
|
||||||
#include "ISourceMod.h"
|
|
||||||
#include "HandleSys.h"
|
#include "HandleSys.h"
|
||||||
|
#include "ShareSys.h"
|
||||||
|
#include "sourcemod.h"
|
||||||
|
#include "sm_stringutil.h"
|
||||||
|
#include "Logger.h"
|
||||||
#include "ExtensionSys.h"
|
#include "ExtensionSys.h"
|
||||||
#include "PluginSys.h"
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <IThreader.h>
|
#include <IThreader.h>
|
||||||
#include <bridge/include/ILogger.h>
|
|
||||||
#include <bridge/include/CoreProvider.h>
|
|
||||||
|
|
||||||
#define DBPARSE_LEVEL_NONE 0
|
#define DBPARSE_LEVEL_NONE 0
|
||||||
#define DBPARSE_LEVEL_MAIN 1
|
#define DBPARSE_LEVEL_MAIN 1
|
||||||
@@ -47,16 +47,10 @@ DBManager g_DBMan;
|
|||||||
static bool s_OneTimeThreaderErrorMsg = false;
|
static bool s_OneTimeThreaderErrorMsg = false;
|
||||||
|
|
||||||
DBManager::DBManager()
|
DBManager::DBManager()
|
||||||
: m_Terminate(false),
|
: m_ParseLevel(0), m_ParseState(0), m_pDefault(NULL)
|
||||||
m_pDefault(NULL)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FrameHook(bool simulating)
|
|
||||||
{
|
|
||||||
g_DBMan.RunFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBManager::OnSourceModAllInitialized()
|
void DBManager::OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
HandleAccess sec;
|
HandleAccess sec;
|
||||||
@@ -64,38 +58,53 @@ void DBManager::OnSourceModAllInitialized()
|
|||||||
g_HandleSys.InitAccessDefaults(NULL, &sec);
|
g_HandleSys.InitAccessDefaults(NULL, &sec);
|
||||||
sec.access[HandleAccess_Delete] |= HANDLE_RESTRICT_IDENTITY;
|
sec.access[HandleAccess_Delete] |= HANDLE_RESTRICT_IDENTITY;
|
||||||
sec.access[HandleAccess_Clone] |= HANDLE_RESTRICT_IDENTITY;
|
sec.access[HandleAccess_Clone] |= HANDLE_RESTRICT_IDENTITY;
|
||||||
|
|
||||||
m_DriverType = g_HandleSys.CreateType("IDriver", this, 0, NULL, &sec, g_pCoreIdent, NULL);
|
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);
|
m_DatabaseType = g_HandleSys.CreateType("IDatabase", this, 0, NULL, NULL, g_pCoreIdent, NULL);
|
||||||
|
|
||||||
g_ShareSys.AddInterface(NULL, this);
|
g_ShareSys.AddInterface(NULL, this);
|
||||||
|
|
||||||
g_pSM->BuildPath(Path_SM, m_Filename, sizeof(m_Filename), "configs/databases.cfg");
|
g_SourceMod.BuildPath(Path_SM, m_Filename, sizeof(m_Filename), "configs/databases.cfg");
|
||||||
m_Builder.SetPath(m_Filename);
|
|
||||||
|
m_pConfigLock = g_pThreader->MakeMutex();
|
||||||
|
m_pThinkLock = g_pThreader->MakeMutex();
|
||||||
|
m_pQueueLock = g_pThreader->MakeMutex();
|
||||||
|
|
||||||
g_PluginSys.AddPluginsListener(this);
|
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)
|
void DBManager::OnSourceModLevelChange(const char *mapName)
|
||||||
{
|
{
|
||||||
m_Builder.StartParse();
|
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.
|
||||||
|
*/
|
||||||
|
m_pConfigLock->Lock();
|
||||||
|
if ((err = textparsers->ParseFile_SMC(m_Filename, this, &states)) != SMCError_Okay)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("[SM] Detected parse error(s) in file \"%s\"", m_Filename);
|
||||||
|
if (err != SMCError_Custom)
|
||||||
|
{
|
||||||
|
const char *txt = textparsers->GetSMCErrorString(err);
|
||||||
|
g_Logger.LogError("[SM] Line %d: %s", states.line, txt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_pConfigLock->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBManager::OnSourceModShutdown()
|
void DBManager::OnSourceModShutdown()
|
||||||
{
|
{
|
||||||
g_pSM->RemoveGameFrameHook(&FrameHook);
|
|
||||||
KillWorkerThread();
|
KillWorkerThread();
|
||||||
g_PluginSys.RemovePluginsListener(this);
|
g_PluginSys.RemovePluginsListener(this);
|
||||||
|
m_pConfigLock->DestroyThis();
|
||||||
|
m_pThinkLock->DestroyThis();
|
||||||
|
m_pQueueLock->DestroyThis();
|
||||||
g_HandleSys.RemoveType(m_DatabaseType, g_pCoreIdent);
|
g_HandleSys.RemoveType(m_DatabaseType, g_pCoreIdent);
|
||||||
g_HandleSys.RemoveType(m_DriverType, g_pCoreIdent);
|
g_HandleSys.RemoveType(m_DriverType, g_pCoreIdent);
|
||||||
|
ClearConfigs();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int DBManager::GetInterfaceVersion()
|
unsigned int DBManager::GetInterfaceVersion()
|
||||||
@@ -123,10 +132,136 @@ 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)
|
bool DBManager::Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool persistent, char *error, size_t maxlength)
|
||||||
{
|
{
|
||||||
ConfDbInfoList *list = m_Builder.GetConfigList();
|
ConfDbInfo *pInfo = GetDatabaseConf(name);
|
||||||
ke::RefPtr<ConfDbInfo> pInfo = list->GetDatabaseConf(name);
|
|
||||||
|
|
||||||
if (!pInfo)
|
if (!pInfo)
|
||||||
{
|
{
|
||||||
@@ -135,7 +270,7 @@ bool DBManager::Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool
|
|||||||
*pdr = NULL;
|
*pdr = NULL;
|
||||||
}
|
}
|
||||||
*pdb = NULL;
|
*pdb = NULL;
|
||||||
g_pSM->Format(error, maxlength, "Configuration \"%s\" not found", name);
|
UTIL_Format(error, maxlength, "Configuration \"%s\" not found", name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,12 +280,11 @@ bool DBManager::Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool
|
|||||||
/* Try to assign a real driver pointer */
|
/* Try to assign a real driver pointer */
|
||||||
if (pInfo->info.driver[0] == '\0')
|
if (pInfo->info.driver[0] == '\0')
|
||||||
{
|
{
|
||||||
ke::AString defaultDriver = list->GetDefaultDriver();
|
if (!m_pDefault && m_DefDriver.size() > 0)
|
||||||
if (!m_pDefault && defaultDriver.length() > 0)
|
|
||||||
{
|
{
|
||||||
m_pDefault = FindOrLoadDriver(defaultDriver.chars());
|
m_pDefault = FindOrLoadDriver(m_DefDriver.c_str());
|
||||||
}
|
}
|
||||||
dname = defaultDriver.length() ? defaultDriver.chars() : "default";
|
dname = m_DefDriver.size() ? m_DefDriver.c_str() : "default";
|
||||||
pInfo->realDriver = m_pDefault;
|
pInfo->realDriver = m_pDefault;
|
||||||
} else {
|
} else {
|
||||||
pInfo->realDriver = FindOrLoadDriver(pInfo->info.driver);
|
pInfo->realDriver = FindOrLoadDriver(pInfo->info.driver);
|
||||||
@@ -173,7 +307,8 @@ bool DBManager::Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool
|
|||||||
}
|
}
|
||||||
*pdb = NULL;
|
*pdb = NULL;
|
||||||
|
|
||||||
g_pSM->Format(error, maxlength, "Driver \"%s\" not found", dname);
|
UTIL_Format(error, maxlength, "Driver \"%s\" not found", dname);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +321,7 @@ void DBManager::AddDriver(IDBDriver *pDriver)
|
|||||||
*/
|
*/
|
||||||
KillWorkerThread();
|
KillWorkerThread();
|
||||||
|
|
||||||
m_drivers.push_back(pDriver);
|
m_drivers.push_back(pDriver);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBManager::RemoveDriver(IDBDriver *pDriver)
|
void DBManager::RemoveDriver(IDBDriver *pDriver)
|
||||||
@@ -206,23 +341,17 @@ void DBManager::RemoveDriver(IDBDriver *pDriver)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfDbInfoList *list = m_Builder.GetConfigList();
|
/* Make sure NOTHING references this! */
|
||||||
for (size_t i = 0; i < list->length(); i++)
|
List<ConfDbInfo *>::iterator iter;
|
||||||
|
for (iter=m_confs.begin(); iter!=m_confs.end(); iter++)
|
||||||
{
|
{
|
||||||
ke::RefPtr<ConfDbInfo> current = list->at(i);
|
ConfDbInfo &db = *(*iter);
|
||||||
if (current->realDriver == pDriver)
|
if (db.realDriver == pDriver)
|
||||||
{
|
{
|
||||||
current->realDriver = NULL;
|
db.realDriver = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Someone unloaded the default driver? Silly.. */
|
|
||||||
if (pDriver == m_pDefault)
|
|
||||||
{
|
|
||||||
m_pDefault = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now that the driver is gone, we have to test the think queue.
|
/* Now that the driver is gone, we have to test the think queue.
|
||||||
* Whatever happens therein is up to the db op!
|
* Whatever happens therein is up to the db op!
|
||||||
*/
|
*/
|
||||||
@@ -252,11 +381,9 @@ void DBManager::RemoveDriver(IDBDriver *pDriver)
|
|||||||
|
|
||||||
IDBDriver *DBManager::GetDefaultDriver()
|
IDBDriver *DBManager::GetDefaultDriver()
|
||||||
{
|
{
|
||||||
ConfDbInfoList *list = m_Builder.GetConfigList();
|
if (!m_pDefault && m_DefDriver.size() > 0)
|
||||||
ke::AString defaultDriver = list->GetDefaultDriver();
|
|
||||||
if (!m_pDefault && defaultDriver.length() > 0)
|
|
||||||
{
|
{
|
||||||
m_pDefault = FindOrLoadDriver(defaultDriver.chars());
|
m_pDefault = FindOrLoadDriver(m_DefDriver.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_pDefault;
|
return m_pDefault;
|
||||||
@@ -319,16 +446,10 @@ IDBDriver *DBManager::GetDriver(unsigned int index)
|
|||||||
|
|
||||||
const DatabaseInfo *DBManager::FindDatabaseConf(const char *name)
|
const DatabaseInfo *DBManager::FindDatabaseConf(const char *name)
|
||||||
{
|
{
|
||||||
ConfDbInfoList *list = m_Builder.GetConfigList();
|
ConfDbInfo *info = GetDatabaseConf(name);
|
||||||
ke::RefPtr<ConfDbInfo> info = list->GetDatabaseConf(name);
|
|
||||||
if (!info)
|
if (!info)
|
||||||
{
|
{
|
||||||
// couldn't find requested conf, return default if exists
|
return NULL;
|
||||||
info = list->GetDefaultConfiguration();
|
|
||||||
if (!info)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &info->info;
|
return &info->info;
|
||||||
@@ -336,9 +457,18 @@ const DatabaseInfo *DBManager::FindDatabaseConf(const char *name)
|
|||||||
|
|
||||||
ConfDbInfo *DBManager::GetDatabaseConf(const char *name)
|
ConfDbInfo *DBManager::GetDatabaseConf(const char *name)
|
||||||
{
|
{
|
||||||
ConfDbInfoList *list = m_Builder.GetConfigList();
|
List<ConfDbInfo *>::iterator iter;
|
||||||
ke::RefPtr<ConfDbInfo> info(list->GetDatabaseConf(name));
|
|
||||||
return info;
|
for (iter=m_confs.begin(); iter!=m_confs.end(); iter++)
|
||||||
|
{
|
||||||
|
ConfDbInfo &conf = *(*iter);
|
||||||
|
if (conf.name == name)
|
||||||
|
{
|
||||||
|
return &conf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
IDBDriver *DBManager::FindOrLoadDriver(const char *name)
|
IDBDriver *DBManager::FindOrLoadDriver(const char *name)
|
||||||
@@ -353,7 +483,7 @@ IDBDriver *DBManager::FindOrLoadDriver(const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char filename[PLATFORM_MAX_PATH];
|
char filename[PLATFORM_MAX_PATH];
|
||||||
g_pSM->Format(filename, sizeof(filename), "dbi.%s.ext", name);
|
UTIL_Format(filename, sizeof(filename), "dbi.%s.ext", name);
|
||||||
|
|
||||||
IExtension *pExt = g_Extensions.LoadAutoExtension(filename);
|
IExtension *pExt = g_Extensions.LoadAutoExtension(filename);
|
||||||
if (!pExt || !pExt->IsLoaded() || m_drivers.size() <= last_size)
|
if (!pExt || !pExt->IsLoaded() || m_drivers.size() <= last_size)
|
||||||
@@ -374,17 +504,12 @@ IDBDriver *DBManager::FindOrLoadDriver(const char *name)
|
|||||||
|
|
||||||
void DBManager::KillWorkerThread()
|
void DBManager::KillWorkerThread()
|
||||||
{
|
{
|
||||||
if (m_Worker)
|
if (m_pWorker)
|
||||||
{
|
{
|
||||||
{
|
m_pWorker->Stop(false);
|
||||||
ke::AutoLock lock(&m_QueueEvent);
|
g_pThreader->DestroyWorker(m_pWorker);
|
||||||
m_Terminate = true;
|
m_pWorker = NULL;
|
||||||
m_QueueEvent.Notify();
|
|
||||||
}
|
|
||||||
m_Worker->Join();
|
|
||||||
m_Worker = nullptr;
|
|
||||||
s_OneTimeThreaderErrorMsg = false;
|
s_OneTimeThreaderErrorMsg = false;
|
||||||
m_Terminate = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,108 +522,99 @@ bool DBManager::AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_Worker)
|
if (!m_pWorker)
|
||||||
{
|
{
|
||||||
m_Worker = new ke::Thread([this]() -> void {
|
m_pWorker = g_pThreader->MakeWorker(this, true);
|
||||||
Run();
|
if (!m_pWorker)
|
||||||
}, "SM SQL Worker");
|
|
||||||
if (!m_Worker->Succeeded())
|
|
||||||
{
|
{
|
||||||
if (!s_OneTimeThreaderErrorMsg)
|
if (!s_OneTimeThreaderErrorMsg)
|
||||||
{
|
{
|
||||||
logger->LogError("[SM] Unable to create db threader (error unknown)");
|
g_Logger.LogError("[SM] Unable to create db threader (error unknown)");
|
||||||
s_OneTimeThreaderErrorMsg = true;
|
s_OneTimeThreaderErrorMsg = true;
|
||||||
}
|
}
|
||||||
m_Worker = nullptr;
|
return false;
|
||||||
|
}
|
||||||
|
if (!m_pWorker->Start())
|
||||||
|
{
|
||||||
|
if (!s_OneTimeThreaderErrorMsg)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("[SM] Unable to start db threader (error unknown)");
|
||||||
|
s_OneTimeThreaderErrorMsg = true;
|
||||||
|
}
|
||||||
|
g_pThreader->DestroyWorker(m_pWorker);
|
||||||
|
m_pWorker = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add to the queue */
|
/* Add to the queue */
|
||||||
{
|
{
|
||||||
ke::AutoLock lock(&m_QueueEvent);
|
m_pQueueLock->Lock();
|
||||||
Queue<IDBThreadOperation *> &queue = m_OpQueue.GetQueue(prio);
|
Queue<IDBThreadOperation *> &queue = m_OpQueue.GetQueue(prio);
|
||||||
queue.push(op);
|
queue.push(op);
|
||||||
m_QueueEvent.Notify();
|
m_pQueueLock->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Make the thread */
|
||||||
|
m_pWorker->MakeThread(this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBManager::Run()
|
void DBManager::OnWorkerStart(IThreadWorker *pWorker)
|
||||||
{
|
{
|
||||||
// Initialize DB threadsafety.
|
m_drSafety.clear();
|
||||||
for (size_t i=0; i < m_drivers.size(); i++)
|
for (size_t i=0; i<m_drivers.size(); i++)
|
||||||
{
|
{
|
||||||
if (m_drivers[i]->IsThreadSafe())
|
if (m_drivers[i]->IsThreadSafe())
|
||||||
|
{
|
||||||
m_drSafety.push_back(m_drivers[i]->InitializeThreadSafety());
|
m_drSafety.push_back(m_drivers[i]->InitializeThreadSafety());
|
||||||
else
|
} else {
|
||||||
m_drSafety.push_back(false);
|
m_drSafety.push_back(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Run actual worker thread logic.
|
void DBManager::OnWorkerStop(IThreadWorker *pWorker)
|
||||||
ThreadMain();
|
{
|
||||||
|
|
||||||
// Shutdown DB threadsafety.
|
|
||||||
for (size_t i=0; i<m_drivers.size(); i++)
|
for (size_t i=0; i<m_drivers.size(); i++)
|
||||||
{
|
{
|
||||||
if (m_drSafety[i])
|
if (m_drSafety[i])
|
||||||
|
{
|
||||||
m_drivers[i]->ShutdownThreadSafety();
|
m_drivers[i]->ShutdownThreadSafety();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_drSafety.clear();
|
m_drSafety.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBManager::ThreadMain()
|
void DBManager::RunThread(IThreadHandle *pThread)
|
||||||
{
|
{
|
||||||
ke::AutoLock lock(&m_QueueEvent);
|
IDBThreadOperation *op = NULL;
|
||||||
|
|
||||||
while (true) {
|
/* Get something from the queue */
|
||||||
// The lock has been acquired. Grab everything we can out of the
|
{
|
||||||
// queue. Since we want to flush the queue even if we're terminated,
|
m_pQueueLock->Lock();
|
||||||
// we process all operations we can before checking to terminate.
|
Queue<IDBThreadOperation *> &queue = m_OpQueue.GetLikelyQueue();
|
||||||
// There's no risk of starvation since the main thread blocks on us
|
if (!queue.empty())
|
||||||
// terminating.
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
Queue<IDBThreadOperation *> &queue = m_OpQueue.GetLikelyQueue();
|
op = queue.first();
|
||||||
if (queue.empty())
|
|
||||||
break;
|
|
||||||
|
|
||||||
IDBThreadOperation *op = queue.first();
|
|
||||||
queue.pop();
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
m_pQueueLock->Unlock();
|
||||||
if (m_Terminate)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Release the lock and wait for a signal.
|
|
||||||
m_QueueEvent.Wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* whoa. hi. did we get something? we should have. */
|
||||||
|
if (!op)
|
||||||
|
{
|
||||||
|
/* wtf? */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
op->RunThreadPart();
|
||||||
|
|
||||||
|
m_pThinkLock->Lock();
|
||||||
|
m_ThinkQueue.push(op);
|
||||||
|
m_pThinkLock->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBManager::RunFrame()
|
void DBManager::RunFrame()
|
||||||
@@ -510,16 +626,19 @@ void DBManager::RunFrame()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Dump one thing per-frame so the server stays sane. */
|
/* Dump one thing per-frame so the server stays sane. */
|
||||||
IDBThreadOperation *op;
|
m_pThinkLock->Lock();
|
||||||
{
|
IDBThreadOperation *op = m_ThinkQueue.first();
|
||||||
ke::AutoLock lock(&m_ThinkLock);
|
m_ThinkQueue.pop();
|
||||||
op = m_ThinkQueue.first();
|
m_pThinkLock->Unlock();
|
||||||
m_ThinkQueue.pop();
|
|
||||||
}
|
|
||||||
op->RunThinkPart();
|
op->RunThinkPart();
|
||||||
op->Destroy();
|
op->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DBManager::OnTerminate(IThreadHandle *pThread, bool cancel)
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
}
|
||||||
|
|
||||||
void DBManager::OnSourceModIdentityDropped(IdentityToken_t *pToken)
|
void DBManager::OnSourceModIdentityDropped(IdentityToken_t *pToken)
|
||||||
{
|
{
|
||||||
s_pAddBlock = pToken;
|
s_pAddBlock = pToken;
|
||||||
@@ -557,7 +676,7 @@ void DBManager::OnSourceModIdentityDropped(IdentityToken_t *pToken)
|
|||||||
s_pAddBlock = NULL;
|
s_pAddBlock = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBManager::OnPluginWillUnload(IPlugin *plugin)
|
void DBManager::OnPluginUnloaded(IPlugin *plugin)
|
||||||
{
|
{
|
||||||
/* Kill the thread so we can flush everything into the think queue... */
|
/* Kill the thread so we can flush everything into the think queue... */
|
||||||
KillWorkerThread();
|
KillWorkerThread();
|
||||||
@@ -583,7 +702,9 @@ void DBManager::OnPluginWillUnload(IPlugin *plugin)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (iter = templist.begin(); iter != templist.end(); iter++)
|
for (iter = templist.begin();
|
||||||
|
iter != templist.end();
|
||||||
|
iter++)
|
||||||
{
|
{
|
||||||
IDBThreadOperation *op = (*iter);
|
IDBThreadOperation *op = (*iter);
|
||||||
op->RunThinkPart();
|
op->RunThinkPart();
|
||||||
@@ -591,13 +712,23 @@ void DBManager::OnPluginWillUnload(IPlugin *plugin)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ke::AString DBManager::GetDefaultDriverName()
|
void DBManager::LockConfig()
|
||||||
{
|
{
|
||||||
ConfDbInfoList *list = m_Builder.GetConfigList();
|
m_pConfigLock->Lock();
|
||||||
return list->GetDefaultDriver();
|
}
|
||||||
|
|
||||||
|
void DBManager::UnlockConfig()
|
||||||
|
{
|
||||||
|
m_pConfigLock->Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *DBManager::GetDefaultDriverName()
|
||||||
|
{
|
||||||
|
return m_DefDriver.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBManager::AddDependency(IExtension *myself, IDBDriver *driver)
|
void DBManager::AddDependency(IExtension *myself, IDBDriver *driver)
|
||||||
{
|
{
|
||||||
g_Extensions.AddRawDependency(myself, driver->GetIdentity(), driver);
|
g_Extensions.AddRawDependency(myself, driver->GetIdentity(), driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -32,24 +32,41 @@
|
|||||||
#ifndef _INCLUDE_DATABASE_MANAGER_H_
|
#ifndef _INCLUDE_DATABASE_MANAGER_H_
|
||||||
#define _INCLUDE_DATABASE_MANAGER_H_
|
#define _INCLUDE_DATABASE_MANAGER_H_
|
||||||
|
|
||||||
#include "common_logic.h"
|
#include <IDBDriver.h>
|
||||||
|
#include "sm_globals.h"
|
||||||
#include <sh_vector.h>
|
#include <sh_vector.h>
|
||||||
#include <am-string.h>
|
#include <sh_string.h>
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
|
#include <ITextParsers.h>
|
||||||
|
#include "sm_memtable.h"
|
||||||
#include <IThreader.h>
|
#include <IThreader.h>
|
||||||
#include <IPluginSys.h>
|
|
||||||
#include <am-thread-utils.h>
|
|
||||||
#include "sm_simple_prioqueue.h"
|
#include "sm_simple_prioqueue.h"
|
||||||
#include <am-refcounting.h>
|
#include "PluginSys.h"
|
||||||
#include "DatabaseConfBuilder.h"
|
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
|
|
||||||
|
struct ConfDbInfo
|
||||||
|
{
|
||||||
|
ConfDbInfo() : realDriver(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
String name;
|
||||||
|
String driver;
|
||||||
|
String host;
|
||||||
|
String user;
|
||||||
|
String pass;
|
||||||
|
String database;
|
||||||
|
IDBDriver *realDriver;
|
||||||
|
DatabaseInfo info;
|
||||||
|
};
|
||||||
|
|
||||||
class DBManager :
|
class DBManager :
|
||||||
public IDBManager,
|
public IDBManager,
|
||||||
public SMGlobalClass,
|
public SMGlobalClass,
|
||||||
public IHandleTypeDispatch,
|
public IHandleTypeDispatch,
|
||||||
|
public ITextListener_SMC,
|
||||||
|
public IThread,
|
||||||
|
public IThreadWorkerCallbacks,
|
||||||
public IPluginsListener
|
public IPluginsListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -68,7 +85,6 @@ public: //IDBManager
|
|||||||
void AddDriver(IDBDriver *pDrivera);
|
void AddDriver(IDBDriver *pDrivera);
|
||||||
void RemoveDriver(IDBDriver *pDriver);
|
void RemoveDriver(IDBDriver *pDriver);
|
||||||
const DatabaseInfo *FindDatabaseConf(const char *name);
|
const DatabaseInfo *FindDatabaseConf(const char *name);
|
||||||
ConfDbInfo *GetDatabaseConf(const char *name);
|
|
||||||
bool Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool persistent, char *error, size_t maxlength);
|
bool Connect(const char *name, IDBDriver **pdr, IDatabase **pdb, bool persistent, char *error, size_t maxlength);
|
||||||
unsigned int GetDriverCount();
|
unsigned int GetDriverCount();
|
||||||
IDBDriver *GetDriver(unsigned int index);
|
IDBDriver *GetDriver(unsigned int index);
|
||||||
@@ -76,16 +92,28 @@ public: //IDBManager
|
|||||||
HandleError ReadHandle(Handle_t hndl, DBHandleType type, void **ptr);
|
HandleError ReadHandle(Handle_t hndl, DBHandleType type, void **ptr);
|
||||||
HandleError ReleaseHandle(Handle_t hndl, DBHandleType type, IdentityToken_t *token);
|
HandleError ReleaseHandle(Handle_t hndl, DBHandleType type, IdentityToken_t *token);
|
||||||
void AddDependency(IExtension *myself, IDBDriver *driver);
|
void AddDependency(IExtension *myself, IDBDriver *driver);
|
||||||
public: //ke::IRunnable
|
public: //ITextListener_SMC
|
||||||
void Run();
|
void ReadSMC_ParseStart();
|
||||||
void ThreadMain();
|
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: //IThread
|
||||||
|
void RunThread(IThreadHandle *pThread);
|
||||||
|
void OnTerminate(IThreadHandle *pThread, bool cancel);
|
||||||
|
public: //IThreadWorkerCallbacks
|
||||||
|
void OnWorkerStart(IThreadWorker *pWorker);
|
||||||
|
void OnWorkerStop(IThreadWorker *pWorker);
|
||||||
public: //IPluginsListener
|
public: //IPluginsListener
|
||||||
void OnPluginWillUnload(IPlugin *plugin);
|
void OnPluginUnloaded(IPlugin *plugin);
|
||||||
public:
|
public:
|
||||||
|
ConfDbInfo *GetDatabaseConf(const char *name);
|
||||||
IDBDriver *FindOrLoadDriver(const char *name);
|
IDBDriver *FindOrLoadDriver(const char *name);
|
||||||
IDBDriver *GetDefaultDriver();
|
IDBDriver *GetDefaultDriver();
|
||||||
ke::AString GetDefaultDriverName();
|
const char *GetDefaultDriverName();
|
||||||
bool AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio);
|
bool AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio);
|
||||||
|
void LockConfig();
|
||||||
|
void UnlockConfig();
|
||||||
void RunFrame();
|
void RunFrame();
|
||||||
inline HandleType_t GetDatabaseType()
|
inline HandleType_t GetDatabaseType()
|
||||||
{
|
{
|
||||||
@@ -101,15 +129,18 @@ private:
|
|||||||
PrioQueue<IDBThreadOperation *> m_OpQueue;
|
PrioQueue<IDBThreadOperation *> m_OpQueue;
|
||||||
Queue<IDBThreadOperation *> m_ThinkQueue;
|
Queue<IDBThreadOperation *> m_ThinkQueue;
|
||||||
CVector<bool> m_drSafety; /* which drivers are safe? */
|
CVector<bool> m_drSafety; /* which drivers are safe? */
|
||||||
ke::AutoPtr<ke::Thread> m_Worker;
|
IThreadWorker *m_pWorker; /* Worker thread object */
|
||||||
ke::ConditionVariable m_QueueEvent;
|
IMutex *m_pConfigLock; /* Configuration lock */
|
||||||
ke::Mutex m_ThinkLock;
|
IMutex *m_pQueueLock; /* Queue safety lock */
|
||||||
bool m_Terminate;
|
IMutex *m_pThinkLock; /* Think-queue lock */
|
||||||
|
|
||||||
DatabaseConfBuilder m_Builder;
|
List<ConfDbInfo *> m_confs;
|
||||||
HandleType_t m_DriverType;
|
HandleType_t m_DriverType;
|
||||||
HandleType_t m_DatabaseType;
|
HandleType_t m_DatabaseType;
|
||||||
|
String m_DefDriver;
|
||||||
char m_Filename[PLATFORM_MAX_PATH];
|
char m_Filename[PLATFORM_MAX_PATH];
|
||||||
|
unsigned int m_ParseLevel;
|
||||||
|
unsigned int m_ParseState;
|
||||||
IDBDriver *m_pDefault;
|
IDBDriver *m_pDefault;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -29,11 +29,10 @@
|
|||||||
* Version: $Id$
|
* Version: $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ISourceMod.h>
|
|
||||||
#include <IPluginSys.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include "DebugReporter.h"
|
#include "DebugReporter.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "PluginSys.h"
|
||||||
|
#include "sm_stringutil.h"
|
||||||
|
|
||||||
DebugReport g_DbgReporter;
|
DebugReport g_DbgReporter;
|
||||||
|
|
||||||
@@ -48,7 +47,7 @@ void DebugReport::OnDebugSpew(const char *msg, ...)
|
|||||||
char buffer[512];
|
char buffer[512];
|
||||||
|
|
||||||
va_start(ap, msg);
|
va_start(ap, msg);
|
||||||
ke::SafeVsprintf(buffer, sizeof(buffer), msg, ap);
|
UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
g_Logger.LogMessage("[SM] %s", buffer);
|
g_Logger.LogMessage("[SM] %s", buffer);
|
||||||
@@ -66,9 +65,9 @@ void DebugReport::GenerateError(IPluginContext *ctx, cell_t func_idx, int err, c
|
|||||||
void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap)
|
void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap)
|
||||||
{
|
{
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
ke::SafeVsprintf(buffer, sizeof(buffer), message, ap);
|
UTIL_FormatArgs(buffer, sizeof(buffer), message, ap);
|
||||||
|
|
||||||
const char *plname = pluginsys->FindPluginByContext(ctx->GetContext())->GetFilename();
|
const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename();
|
||||||
const char *error = g_pSourcePawn2->GetErrorString(err);
|
const char *error = g_pSourcePawn2->GetErrorString(err);
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
@@ -100,10 +99,10 @@ void DebugReport::GenerateCodeError(IPluginContext *pContext, uint32_t code_addr
|
|||||||
char buffer[512];
|
char buffer[512];
|
||||||
|
|
||||||
va_start(ap, message);
|
va_start(ap, message);
|
||||||
ke::SafeVsprintf(buffer, sizeof(buffer), message, ap);
|
UTIL_FormatArgs(buffer, sizeof(buffer), message, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
const char *plname = pluginsys->FindPluginByContext(pContext->GetContext())->GetFilename();
|
const char *plname = g_PluginSys.FindPluginByContext(pContext->GetContext())->GetFilename();
|
||||||
const char *error = g_pSourcePawn2->GetErrorString(err);
|
const char *error = g_pSourcePawn2->GetErrorString(err);
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
@@ -133,10 +132,55 @@ void DebugReport::GenerateCodeError(IPluginContext *pContext, uint32_t code_addr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *error)
|
||||||
|
{
|
||||||
|
const char *lastname;
|
||||||
|
const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename();
|
||||||
|
int n_err = error->GetErrorCode();
|
||||||
|
|
||||||
|
if (n_err != SP_ERROR_NATIVE)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("[SM] Plugin encountered error %d: %s",
|
||||||
|
n_err,
|
||||||
|
error->GetErrorString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((lastname=error->GetLastNative(NULL)) != NULL)
|
||||||
|
{
|
||||||
|
const char *custerr;
|
||||||
|
if ((custerr=error->GetCustomErrorString()) != NULL)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("[SM] Native \"%s\" reported: %s", lastname, custerr);
|
||||||
|
} else {
|
||||||
|
g_Logger.LogError("[SM] Native \"%s\" encountered a generic error.", lastname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!error->DebugInfoAvailable())
|
||||||
|
{
|
||||||
|
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(ctx));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CallStackInfo stk_info;
|
||||||
|
int i = 0;
|
||||||
|
g_Logger.LogError("[SM] Displaying call stack trace for plugin \"%s\":", plname);
|
||||||
|
while (error->GetTraceInfo(&stk_info))
|
||||||
|
{
|
||||||
|
g_Logger.LogError("[SM] [%d] Line %d, %s::%s()",
|
||||||
|
i++,
|
||||||
|
stk_info.line,
|
||||||
|
stk_info.filename,
|
||||||
|
stk_info.function);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int DebugReport::_GetPluginIndex(IPluginContext *ctx)
|
int DebugReport::_GetPluginIndex(IPluginContext *ctx)
|
||||||
{
|
{
|
||||||
int id = 1;
|
int id = 1;
|
||||||
IPluginIterator *iter = pluginsys->GetPluginIterator();
|
IPluginIterator *iter = g_PluginSys.GetPluginIterator();
|
||||||
|
|
||||||
for (; iter->MorePlugins(); iter->NextPlugin(), id++)
|
for (; iter->MorePlugins(); iter->NextPlugin(), id++)
|
||||||
{
|
{
|
||||||
@@ -152,95 +196,6 @@ int DebugReport::_GetPluginIndex(IPluginContext *ctx)
|
|||||||
|
|
||||||
/* If we don't know which plugin this is, it's one being loaded. Fake its index for now. */
|
/* If we don't know which plugin this is, it's one being loaded. Fake its index for now. */
|
||||||
|
|
||||||
return pluginsys->GetPluginCount() + 1;
|
return g_PluginSys.GetPluginCount() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugReport::ReportError(const IErrorReport &report, IFrameIterator &iter)
|
|
||||||
{
|
|
||||||
// Don't log an error if a function wasn't runnable.
|
|
||||||
// This is necassary due to the way SM is handling and exposing
|
|
||||||
// scripted functions. It's too late to change that now.
|
|
||||||
if (report.Code() == SP_ERROR_NOT_RUNNABLE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const char *blame = nullptr;
|
|
||||||
if (report.Blame())
|
|
||||||
{
|
|
||||||
blame = report.Blame()->DebugName();
|
|
||||||
} else {
|
|
||||||
// Find the nearest plugin to blame.
|
|
||||||
for (; !iter.Done(); iter.Next())
|
|
||||||
{
|
|
||||||
if (iter.IsScriptedFrame())
|
|
||||||
{
|
|
||||||
IPlugin *plugin = pluginsys->FindPluginByContext(iter.Context()->GetContext());
|
|
||||||
if (plugin)
|
|
||||||
{
|
|
||||||
blame = plugin->GetFilename();
|
|
||||||
} else {
|
|
||||||
blame = iter.Context()->GetRuntime()->GetFilename();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
iter.Reset();
|
|
||||||
|
|
||||||
g_Logger.LogError("[SM] Exception reported: %s", report.Message());
|
|
||||||
|
|
||||||
if (blame)
|
|
||||||
{
|
|
||||||
g_Logger.LogError("[SM] Blaming: %s", blame);
|
|
||||||
}
|
|
||||||
|
|
||||||
ke::Vector<ke::AString> arr = GetStackTrace(&iter);
|
|
||||||
for (size_t i = 0; i < arr.length(); i++)
|
|
||||||
{
|
|
||||||
g_Logger.LogError("%s", arr[i].chars());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ke::Vector<ke::AString> DebugReport::GetStackTrace(IFrameIterator *iter)
|
|
||||||
{
|
|
||||||
char temp[3072];
|
|
||||||
ke::Vector<ke::AString> trace;
|
|
||||||
iter->Reset();
|
|
||||||
|
|
||||||
if (!iter->Done())
|
|
||||||
{
|
|
||||||
trace.append("[SM] Call stack trace:");
|
|
||||||
|
|
||||||
for (int index = 0; !iter->Done(); iter->Next(), index++)
|
|
||||||
{
|
|
||||||
const char *fn = iter->FunctionName();
|
|
||||||
if (!fn)
|
|
||||||
{
|
|
||||||
fn = "<unknown function>";
|
|
||||||
}
|
|
||||||
if (iter->IsNativeFrame())
|
|
||||||
{
|
|
||||||
g_pSM->Format(temp, sizeof(temp), "[SM] [%d] %s", index, fn);
|
|
||||||
trace.append(temp);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (iter->IsScriptedFrame())
|
|
||||||
{
|
|
||||||
const char *file = iter->FilePath();
|
|
||||||
if (!file)
|
|
||||||
{
|
|
||||||
file = "<unknown>";
|
|
||||||
}
|
|
||||||
g_pSM->Format(temp, sizeof(temp), "[SM] [%d] Line %d, %s::%s",
|
|
||||||
index,
|
|
||||||
iter->LineNumber(),
|
|
||||||
file,
|
|
||||||
fn);
|
|
||||||
|
|
||||||
trace.append(temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return trace;
|
|
||||||
}
|
|
||||||
@@ -33,9 +33,7 @@
|
|||||||
#define _INCLUDE_SOURCEMOD_CDBGREPORTER_H_
|
#define _INCLUDE_SOURCEMOD_CDBGREPORTER_H_
|
||||||
|
|
||||||
#include "sp_vm_api.h"
|
#include "sp_vm_api.h"
|
||||||
#include "common_logic.h"
|
#include "sm_globals.h"
|
||||||
#include <am-vector.h>
|
|
||||||
#include <am-string.h>
|
|
||||||
|
|
||||||
class DebugReport :
|
class DebugReport :
|
||||||
public SMGlobalClass,
|
public SMGlobalClass,
|
||||||
@@ -44,13 +42,12 @@ class DebugReport :
|
|||||||
public: // SMGlobalClass
|
public: // SMGlobalClass
|
||||||
void OnSourceModAllInitialized();
|
void OnSourceModAllInitialized();
|
||||||
public: // IDebugListener
|
public: // IDebugListener
|
||||||
void ReportError(const IErrorReport &report, IFrameIterator &iter);
|
void OnContextExecuteError(IPluginContext *ctx, IContextTrace *error);
|
||||||
void OnDebugSpew(const char *msg, ...);
|
void OnDebugSpew(const char *msg, ...);
|
||||||
public:
|
public:
|
||||||
void GenerateError(IPluginContext *ctx, cell_t func_idx, int err, const char *message, ...);
|
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 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, ...);
|
void GenerateCodeError(IPluginContext *ctx, uint32_t code_addr, int err, const char *message, ...);
|
||||||
ke::Vector<ke::AString> GetStackTrace(IFrameIterator *iter);
|
|
||||||
private:
|
private:
|
||||||
int _GetPluginIndex(IPluginContext *ctx);
|
int _GetPluginIndex(IPluginContext *ctx);
|
||||||
};
|
};
|
||||||
+39
-39
@@ -30,11 +30,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "EventManager.h"
|
#include "EventManager.h"
|
||||||
|
#include "ForwardSys.h"
|
||||||
|
#include "HandleSys.h"
|
||||||
|
#include "PluginSys.h"
|
||||||
#include "sm_stringutil.h"
|
#include "sm_stringutil.h"
|
||||||
#include "PlayerManager.h"
|
|
||||||
|
|
||||||
#include "logic_bridge.h"
|
|
||||||
#include <bridge/include/IScriptManager.h>
|
|
||||||
|
|
||||||
EventManager g_EventManager;
|
EventManager g_EventManager;
|
||||||
|
|
||||||
@@ -59,10 +58,14 @@ public:
|
|||||||
|
|
||||||
EventManager::EventManager() : m_EventType(0)
|
EventManager::EventManager() : m_EventType(0)
|
||||||
{
|
{
|
||||||
|
/* Create an event lookup trie */
|
||||||
|
m_EventHooks = sm_trie_create();
|
||||||
}
|
}
|
||||||
|
|
||||||
EventManager::~EventManager()
|
EventManager::~EventManager()
|
||||||
{
|
{
|
||||||
|
sm_trie_destroy(m_EventHooks);
|
||||||
|
|
||||||
/* Free memory used by EventInfo structs if any */
|
/* Free memory used by EventInfo structs if any */
|
||||||
CStack<EventInfo *>::iterator iter;
|
CStack<EventInfo *>::iterator iter;
|
||||||
for (iter = m_FreeEvents.begin(); iter != m_FreeEvents.end(); iter++)
|
for (iter = m_FreeEvents.begin(); iter != m_FreeEvents.end(); iter++)
|
||||||
@@ -76,8 +79,8 @@ EventManager::~EventManager()
|
|||||||
void EventManager::OnSourceModAllInitialized()
|
void EventManager::OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
/* Add a hook for IGameEventManager2::FireEvent() */
|
/* Add a hook for IGameEventManager2::FireEvent() */
|
||||||
SH_ADD_HOOK(IGameEventManager2, FireEvent, gameevents, SH_MEMBER(this, &EventManager::OnFireEvent), false);
|
SH_ADD_HOOK_MEMFUNC(IGameEventManager2, FireEvent, gameevents, this, &EventManager::OnFireEvent, false);
|
||||||
SH_ADD_HOOK(IGameEventManager2, FireEvent, gameevents, SH_MEMBER(this, &EventManager::OnFireEvent_Post), true);
|
SH_ADD_HOOK_MEMFUNC(IGameEventManager2, FireEvent, gameevents, this, &EventManager::OnFireEvent_Post, true);
|
||||||
|
|
||||||
HandleAccess sec;
|
HandleAccess sec;
|
||||||
|
|
||||||
@@ -87,17 +90,17 @@ void EventManager::OnSourceModAllInitialized()
|
|||||||
sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER;
|
sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER;
|
||||||
|
|
||||||
/* Create the 'GameEvent' handle type */
|
/* Create the 'GameEvent' handle type */
|
||||||
m_EventType = handlesys->CreateType("GameEvent", this, 0, NULL, &sec, g_pCoreIdent, NULL);
|
m_EventType = g_HandleSys.CreateType("GameEvent", this, 0, NULL, &sec, g_pCoreIdent, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventManager::OnSourceModShutdown()
|
void EventManager::OnSourceModShutdown()
|
||||||
{
|
{
|
||||||
/* Remove hook for IGameEventManager2::FireEvent() */
|
/* Remove hook for IGameEventManager2::FireEvent() */
|
||||||
SH_REMOVE_HOOK(IGameEventManager2, FireEvent, gameevents, SH_MEMBER(this, &EventManager::OnFireEvent), false);
|
SH_REMOVE_HOOK_MEMFUNC(IGameEventManager2, FireEvent, gameevents, this, &EventManager::OnFireEvent, false);
|
||||||
SH_REMOVE_HOOK(IGameEventManager2, FireEvent, gameevents, SH_MEMBER(this, &EventManager::OnFireEvent_Post), true);
|
SH_REMOVE_HOOK_MEMFUNC(IGameEventManager2, FireEvent, gameevents, this, &EventManager::OnFireEvent_Post, true);
|
||||||
|
|
||||||
/* Remove the 'GameEvent' handle type */
|
/* Remove the 'GameEvent' handle type */
|
||||||
handlesys->RemoveType(m_EventType, g_pCoreIdent);
|
g_HandleSys.RemoveType(m_EventType, g_pCoreIdent);
|
||||||
|
|
||||||
/* Remove ourselves as listener for events */
|
/* Remove ourselves as listener for events */
|
||||||
gameevents->RemoveListener(this);
|
gameevents->RemoveListener(this);
|
||||||
@@ -135,12 +138,12 @@ void EventManager::OnPluginUnloaded(IPlugin *plugin)
|
|||||||
{
|
{
|
||||||
if (pHook->pPreHook)
|
if (pHook->pPreHook)
|
||||||
{
|
{
|
||||||
forwardsys->ReleaseForward(pHook->pPreHook);
|
g_Forwards.ReleaseForward(pHook->pPreHook);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pHook->pPostHook)
|
if (pHook->pPostHook)
|
||||||
{
|
{
|
||||||
forwardsys->ReleaseForward(pHook->pPostHook);
|
g_Forwards.ReleaseForward(pHook->pPostHook);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete pHook;
|
delete pHook;
|
||||||
@@ -181,10 +184,10 @@ EventHookError EventManager::HookEvent(const char *name, IPluginFunction *pFunct
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If a hook structure does not exist... */
|
/* If a hook structure does not exist... */
|
||||||
if (!m_EventHooks.retrieve(name, &pHook))
|
if (!sm_trie_retrieve(m_EventHooks, name, (void **)&pHook))
|
||||||
{
|
{
|
||||||
EventHookList *pHookList;
|
EventHookList *pHookList;
|
||||||
IPlugin *plugin = scripts->FindPluginByContext(pFunction->GetParentContext()->GetContext());
|
IPlugin *plugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext());
|
||||||
|
|
||||||
/* Check plugin for an existing EventHook list */
|
/* Check plugin for an existing EventHook list */
|
||||||
if (!plugin->GetProperty("EventHooks", (void **)&pHookList))
|
if (!plugin->GetProperty("EventHooks", (void **)&pHookList))
|
||||||
@@ -199,12 +202,12 @@ EventHookError EventManager::HookEvent(const char *name, IPluginFunction *pFunct
|
|||||||
if (mode == EventHookMode_Pre)
|
if (mode == EventHookMode_Pre)
|
||||||
{
|
{
|
||||||
/* Create forward for a pre hook */
|
/* Create forward for a pre hook */
|
||||||
pHook->pPreHook = forwardsys->CreateForwardEx(NULL, ET_Hook, 3, GAMEEVENT_PARAMS);
|
pHook->pPreHook = g_Forwards.CreateForwardEx(NULL, ET_Hook, 3, GAMEEVENT_PARAMS);
|
||||||
/* Add to forward list */
|
/* Add to forward list */
|
||||||
pHook->pPreHook->AddFunction(pFunction);
|
pHook->pPreHook->AddFunction(pFunction);
|
||||||
} else {
|
} else {
|
||||||
/* Create forward for a post hook */
|
/* Create forward for a post hook */
|
||||||
pHook->pPostHook = forwardsys->CreateForwardEx(NULL, ET_Ignore, 3, GAMEEVENT_PARAMS);
|
pHook->pPostHook = g_Forwards.CreateForwardEx(NULL, ET_Ignore, 3, GAMEEVENT_PARAMS);
|
||||||
/* Should we copy data from a pre hook to the post hook? */
|
/* Should we copy data from a pre hook to the post hook? */
|
||||||
pHook->postCopy = (mode == EventHookMode_Post);
|
pHook->postCopy = (mode == EventHookMode_Post);
|
||||||
/* Add to forward list */
|
/* Add to forward list */
|
||||||
@@ -212,14 +215,14 @@ EventHookError EventManager::HookEvent(const char *name, IPluginFunction *pFunct
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Cache the name for post hooks */
|
/* Cache the name for post hooks */
|
||||||
pHook->name = name;
|
pHook->name = sm_strdup(name);
|
||||||
|
|
||||||
/* Increase reference count */
|
/* Increase reference count */
|
||||||
pHook->refCount++;
|
pHook->refCount++;
|
||||||
|
|
||||||
/* Add hook structure to hook lists */
|
/* Add hook structure to hook lists */
|
||||||
pHookList->push_back(pHook);
|
pHookList->push_back(pHook);
|
||||||
m_EventHooks.insert(name, pHook);
|
sm_trie_insert(m_EventHooks, name, pHook);
|
||||||
|
|
||||||
return EventHookErr_Okay;
|
return EventHookErr_Okay;
|
||||||
}
|
}
|
||||||
@@ -231,7 +234,7 @@ EventHookError EventManager::HookEvent(const char *name, IPluginFunction *pFunct
|
|||||||
/* Create pre hook forward if necessary */
|
/* Create pre hook forward if necessary */
|
||||||
if (!pHook->pPreHook)
|
if (!pHook->pPreHook)
|
||||||
{
|
{
|
||||||
pHook->pPreHook = forwardsys->CreateForwardEx(NULL, ET_Event, 3, GAMEEVENT_PARAMS);
|
pHook->pPreHook = g_Forwards.CreateForwardEx(NULL, ET_Event, 3, GAMEEVENT_PARAMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add plugin function to forward list */
|
/* Add plugin function to forward list */
|
||||||
@@ -240,7 +243,7 @@ EventHookError EventManager::HookEvent(const char *name, IPluginFunction *pFunct
|
|||||||
/* Create post hook forward if necessary */
|
/* Create post hook forward if necessary */
|
||||||
if (!pHook->pPostHook)
|
if (!pHook->pPostHook)
|
||||||
{
|
{
|
||||||
pHook->pPostHook = forwardsys->CreateForwardEx(NULL, ET_Ignore, 3, GAMEEVENT_PARAMS);
|
pHook->pPostHook = g_Forwards.CreateForwardEx(NULL, ET_Ignore, 3, GAMEEVENT_PARAMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If postCopy is false, then we may want to set it to true */
|
/* If postCopy is false, then we may want to set it to true */
|
||||||
@@ -265,7 +268,7 @@ EventHookError EventManager::UnhookEvent(const char *name, IPluginFunction *pFun
|
|||||||
IChangeableForward **pEventForward;
|
IChangeableForward **pEventForward;
|
||||||
|
|
||||||
/* If hook does not exist at all */
|
/* If hook does not exist at all */
|
||||||
if (!m_EventHooks.retrieve(name, &pHook))
|
if (!sm_trie_retrieve(m_EventHooks, name, (void **)&pHook))
|
||||||
{
|
{
|
||||||
return EventHookErr_NotActive;
|
return EventHookErr_NotActive;
|
||||||
}
|
}
|
||||||
@@ -287,7 +290,7 @@ EventHookError EventManager::UnhookEvent(const char *name, IPluginFunction *pFun
|
|||||||
/* If forward's list contains 0 functions now, free it */
|
/* If forward's list contains 0 functions now, free it */
|
||||||
if ((*pEventForward)->GetFunctionCount() == 0)
|
if ((*pEventForward)->GetFunctionCount() == 0)
|
||||||
{
|
{
|
||||||
forwardsys->ReleaseForward(*pEventForward);
|
g_Forwards.ReleaseForward(*pEventForward);
|
||||||
*pEventForward = NULL;
|
*pEventForward = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,7 +300,7 @@ EventHookError EventManager::UnhookEvent(const char *name, IPluginFunction *pFun
|
|||||||
/* If reference count is now 0, free hook structure */
|
/* If reference count is now 0, free hook structure */
|
||||||
|
|
||||||
EventHookList *pHookList;
|
EventHookList *pHookList;
|
||||||
IPlugin *plugin = scripts->FindPluginByContext(pFunction->GetParentContext()->GetContext());
|
IPlugin *plugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext());
|
||||||
|
|
||||||
/* Get plugin's event hook list */
|
/* Get plugin's event hook list */
|
||||||
if (!plugin->GetProperty("EventHooks", (void**)&pHookList))
|
if (!plugin->GetProperty("EventHooks", (void**)&pHookList))
|
||||||
@@ -315,7 +318,10 @@ EventHookError EventManager::UnhookEvent(const char *name, IPluginFunction *pFun
|
|||||||
pHookList->remove(pHook);
|
pHookList->remove(pHook);
|
||||||
|
|
||||||
/* Delete entry in trie */
|
/* Delete entry in trie */
|
||||||
m_EventHooks.remove(name);
|
sm_trie_delete(m_EventHooks, name);
|
||||||
|
|
||||||
|
/* Free the cached name */
|
||||||
|
delete pHook->name;
|
||||||
|
|
||||||
/* And finally free structure memory */
|
/* And finally free structure memory */
|
||||||
delete pHook;
|
delete pHook;
|
||||||
@@ -362,13 +368,6 @@ void EventManager::FireEvent(EventInfo *pInfo, bool bDontBroadcast)
|
|||||||
m_FreeEvents.push(pInfo);
|
m_FreeEvents.push(pInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventManager::FireEventToClient(EventInfo *pInfo, IClient *pClient)
|
|
||||||
{
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventManager::CancelCreatedEvent(EventInfo *pInfo)
|
void EventManager::CancelCreatedEvent(EventInfo *pInfo)
|
||||||
{
|
{
|
||||||
/* Free event from IGameEventManager2 */
|
/* Free event from IGameEventManager2 */
|
||||||
@@ -398,7 +397,7 @@ bool EventManager::OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast)
|
|||||||
|
|
||||||
name = pEvent->GetName();
|
name = pEvent->GetName();
|
||||||
|
|
||||||
if (m_EventHooks.retrieve(name, &pHook))
|
if (sm_trie_retrieve(m_EventHooks, name, reinterpret_cast<void **>(&pHook)))
|
||||||
{
|
{
|
||||||
/* Push the event onto the event stack. The reference count is increased to make sure
|
/* Push the event onto the event stack. The reference count is increased to make sure
|
||||||
* the structure is not garbage collected in between now and the post hook.
|
* the structure is not garbage collected in between now and the post hook.
|
||||||
@@ -412,7 +411,7 @@ bool EventManager::OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast)
|
|||||||
{
|
{
|
||||||
EventInfo info(pEvent, NULL);
|
EventInfo info(pEvent, NULL);
|
||||||
HandleSecurity sec(NULL, g_pCoreIdent);
|
HandleSecurity sec(NULL, g_pCoreIdent);
|
||||||
Handle_t hndl = handlesys->CreateHandle(m_EventType, &info, NULL, g_pCoreIdent, NULL);
|
Handle_t hndl = g_HandleSys.CreateHandle(m_EventType, &info, NULL, g_pCoreIdent, NULL);
|
||||||
|
|
||||||
info.bDontBroadcast = bDontBroadcast;
|
info.bDontBroadcast = bDontBroadcast;
|
||||||
|
|
||||||
@@ -425,7 +424,7 @@ bool EventManager::OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast)
|
|||||||
|
|
||||||
broadcast = info.bDontBroadcast;
|
broadcast = info.bDontBroadcast;
|
||||||
|
|
||||||
handlesys->FreeHandle(hndl, &sec);
|
g_HandleSys.FreeHandle(hndl, &sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pHook->postCopy)
|
if (pHook->postCopy)
|
||||||
@@ -433,7 +432,7 @@ bool EventManager::OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast)
|
|||||||
m_EventCopies.push(gameevents->DuplicateEvent(pEvent));
|
m_EventCopies.push(gameevents->DuplicateEvent(pEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res >= Pl_Handled)
|
if (res)
|
||||||
{
|
{
|
||||||
gameevents->FreeEvent(pEvent);
|
gameevents->FreeEvent(pEvent);
|
||||||
RETURN_META_VALUE(MRES_SUPERCEDE, false);
|
RETURN_META_VALUE(MRES_SUPERCEDE, false);
|
||||||
@@ -477,14 +476,14 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast)
|
|||||||
info.bDontBroadcast = bDontBroadcast;
|
info.bDontBroadcast = bDontBroadcast;
|
||||||
info.pEvent = m_EventCopies.front();
|
info.pEvent = m_EventCopies.front();
|
||||||
info.pOwner = NULL;
|
info.pOwner = NULL;
|
||||||
hndl = handlesys->CreateHandle(m_EventType, &info, NULL, g_pCoreIdent, NULL);
|
hndl = g_HandleSys.CreateHandle(m_EventType, &info, NULL, g_pCoreIdent, NULL);
|
||||||
|
|
||||||
pForward->PushCell(hndl);
|
pForward->PushCell(hndl);
|
||||||
} else {
|
} else {
|
||||||
pForward->PushCell(BAD_HANDLE);
|
pForward->PushCell(BAD_HANDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
pForward->PushString(pHook->name.chars());
|
pForward->PushString(pHook->name);
|
||||||
pForward->PushCell(bDontBroadcast);
|
pForward->PushCell(bDontBroadcast);
|
||||||
pForward->Execute(NULL);
|
pForward->Execute(NULL);
|
||||||
|
|
||||||
@@ -492,7 +491,7 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast)
|
|||||||
{
|
{
|
||||||
/* Free handle */
|
/* Free handle */
|
||||||
HandleSecurity sec(NULL, g_pCoreIdent);
|
HandleSecurity sec(NULL, g_pCoreIdent);
|
||||||
handlesys->FreeHandle(hndl, &sec);
|
g_HandleSys.FreeHandle(hndl, &sec);
|
||||||
|
|
||||||
/* Free event structure */
|
/* Free event structure */
|
||||||
gameevents->FreeEvent(info.pEvent);
|
gameevents->FreeEvent(info.pEvent);
|
||||||
@@ -505,7 +504,8 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast)
|
|||||||
{
|
{
|
||||||
assert(pHook->pPostHook == NULL);
|
assert(pHook->pPostHook == NULL);
|
||||||
assert(pHook->pPreHook == NULL);
|
assert(pHook->pPreHook == NULL);
|
||||||
m_EventHooks.remove(pHook->name.chars());
|
sm_trie_delete(m_EventHooks, pHook->name);
|
||||||
|
delete pHook->name;
|
||||||
delete pHook;
|
delete pHook;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-16
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
|
||||||
@@ -34,15 +34,13 @@
|
|||||||
|
|
||||||
#include "sm_globals.h"
|
#include "sm_globals.h"
|
||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include <sm_namehashset.h>
|
#include "sm_trie.h"
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include <sh_stack.h>
|
#include <sh_stack.h>
|
||||||
#include <IHandleSys.h>
|
#include <IHandleSys.h>
|
||||||
#include <IForwardSys.h>
|
#include <IForwardSys.h>
|
||||||
#include <IPluginSys.h>
|
#include <IPluginSys.h>
|
||||||
|
|
||||||
class IClient;
|
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
|
|
||||||
struct EventInfo
|
struct EventInfo
|
||||||
@@ -71,16 +69,7 @@ struct EventHook
|
|||||||
IChangeableForward *pPostHook;
|
IChangeableForward *pPostHook;
|
||||||
bool postCopy;
|
bool postCopy;
|
||||||
unsigned int refCount;
|
unsigned int refCount;
|
||||||
ke::AString name;
|
char *name;
|
||||||
|
|
||||||
static inline bool matches(const char *name, const EventHook *hook)
|
|
||||||
{
|
|
||||||
return strcmp(name, hook->name.chars()) == 0;
|
|
||||||
}
|
|
||||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
|
||||||
{
|
|
||||||
return key.hash();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum EventHookMode
|
enum EventHookMode
|
||||||
@@ -132,14 +121,13 @@ public:
|
|||||||
EventHookError UnhookEvent(const char *name, IPluginFunction *pFunction, EventHookMode mode=EventHookMode_Post);
|
EventHookError UnhookEvent(const char *name, IPluginFunction *pFunction, EventHookMode mode=EventHookMode_Post);
|
||||||
EventInfo *CreateEvent(IPluginContext *pContext, const char *name, bool force=false);
|
EventInfo *CreateEvent(IPluginContext *pContext, const char *name, bool force=false);
|
||||||
void FireEvent(EventInfo *pInfo, bool bDontBroadcast=false);
|
void FireEvent(EventInfo *pInfo, bool bDontBroadcast=false);
|
||||||
void FireEventToClient(EventInfo *pInfo, IClient *pClient);
|
|
||||||
void CancelCreatedEvent(EventInfo *pInfo);
|
void CancelCreatedEvent(EventInfo *pInfo);
|
||||||
private: // IGameEventManager2 hooks
|
private: // IGameEventManager2 hooks
|
||||||
bool OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast);
|
bool OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast);
|
||||||
bool OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast);
|
bool OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast);
|
||||||
private:
|
private:
|
||||||
HandleType_t m_EventType;
|
HandleType_t m_EventType;
|
||||||
NameHashSet<EventHook *> m_EventHooks;
|
Trie *m_EventHooks;
|
||||||
CStack<EventInfo *> m_FreeEvents;
|
CStack<EventInfo *> m_FreeEvents;
|
||||||
CStack<EventHook *> m_EventStack;
|
CStack<EventHook *> m_EventStack;
|
||||||
CStack<IGameEvent *> m_EventCopies;
|
CStack<IGameEvent *> m_EventCopies;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -36,12 +36,14 @@
|
|||||||
#include <ILibrarySys.h>
|
#include <ILibrarySys.h>
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include <sh_string.h>
|
#include <sh_string.h>
|
||||||
#include "common_logic.h"
|
#include <sm_trie_tpl.h>
|
||||||
|
#include "sm_globals.h"
|
||||||
|
#include "ShareSys.h"
|
||||||
|
#include <ISmmAPI.h>
|
||||||
#include <IPluginSys.h>
|
#include <IPluginSys.h>
|
||||||
#include <IRootConsoleMenu.h>
|
#include <IRootConsoleMenu.h>
|
||||||
|
#include "PluginSys.h"
|
||||||
#include "NativeOwner.h"
|
#include "NativeOwner.h"
|
||||||
#include "ShareSys.h"
|
|
||||||
#include <bridge/include/IExtensionBridge.h>
|
|
||||||
|
|
||||||
class CPlayer;
|
class CPlayer;
|
||||||
|
|
||||||
@@ -80,7 +82,6 @@ public:
|
|||||||
void AddPlugin(CPlugin *pPlugin);
|
void AddPlugin(CPlugin *pPlugin);
|
||||||
void MarkAllLoaded();
|
void MarkAllLoaded();
|
||||||
void AddLibrary(const char *library);
|
void AddLibrary(const char *library);
|
||||||
bool IsRequired();
|
|
||||||
public:
|
public:
|
||||||
virtual bool Load(char *error, size_t maxlength);
|
virtual bool Load(char *error, size_t maxlength);
|
||||||
virtual bool IsLoaded() =0;
|
virtual bool IsLoaded() =0;
|
||||||
@@ -88,7 +89,7 @@ public:
|
|||||||
virtual bool Reload(char *error, size_t maxlength) =0;
|
virtual bool Reload(char *error, size_t maxlength) =0;
|
||||||
virtual bool IsSameFile(const char* file) =0;
|
virtual bool IsSameFile(const char* file) =0;
|
||||||
protected:
|
protected:
|
||||||
void Initialize(const char *filename, const char *path, bool bRequired = true);
|
void Initialize(const char *filename, const char *path);
|
||||||
bool PerformAPICheck(char *error, size_t maxlength);
|
bool PerformAPICheck(char *error, size_t maxlength);
|
||||||
void CreateIdentity();
|
void CreateIdentity();
|
||||||
void DestroyIdentity();
|
void DestroyIdentity();
|
||||||
@@ -105,13 +106,12 @@ protected:
|
|||||||
List<String> m_Libraries;
|
List<String> m_Libraries;
|
||||||
unsigned int unload_code;
|
unsigned int unload_code;
|
||||||
bool m_bFullyLoaded;
|
bool m_bFullyLoaded;
|
||||||
bool m_bRequired;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CLocalExtension : public CExtension
|
class CLocalExtension : public CExtension
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CLocalExtension(const char *filename, bool bRequired = true);
|
CLocalExtension(const char *filename);
|
||||||
public:
|
public:
|
||||||
bool Load(char *error, size_t maxlength);
|
bool Load(char *error, size_t maxlength);
|
||||||
bool IsLoaded();
|
bool IsLoaded();
|
||||||
@@ -120,7 +120,7 @@ public:
|
|||||||
bool IsExternal();
|
bool IsExternal();
|
||||||
bool IsSameFile(const char *file);
|
bool IsSameFile(const char *file);
|
||||||
private:
|
private:
|
||||||
int m_PlId;
|
PluginId m_PlId;
|
||||||
ILibrary *m_pLib;
|
ILibrary *m_pLib;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class CExtensionManager :
|
class CExtensionManager :
|
||||||
public IExtensionSys,
|
public IExtensionManager,
|
||||||
public SMGlobalClass,
|
public SMGlobalClass,
|
||||||
public IPluginsListener,
|
public IPluginsListener,
|
||||||
public IRootConsoleCommand
|
public IRootConsoleCommand
|
||||||
@@ -164,22 +164,21 @@ public: //IExtensionManager
|
|||||||
public: //IPluginsListener
|
public: //IPluginsListener
|
||||||
void OnPluginDestroyed(IPlugin *plugin);
|
void OnPluginDestroyed(IPlugin *plugin);
|
||||||
public: //IRootConsoleCommand
|
public: //IRootConsoleCommand
|
||||||
void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override;
|
void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
|
||||||
public:
|
public:
|
||||||
IExtension *LoadAutoExtension(const char *path, bool bErrorOnMissing=true);
|
IExtension *LoadAutoExtension(const char *path, bool bErrorOnMissing=true);
|
||||||
void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);
|
void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);
|
||||||
void AddInterface(IExtension *pOwner, SMInterface *pInterface);
|
void AddInterface(IExtension *pOwner, SMInterface *pInterface);
|
||||||
void BindChildPlugin(IExtension *pParent, SMPlugin *pPlugin);
|
void BindChildPlugin(IExtension *pParent, CPlugin *pPlugin);
|
||||||
void MarkAllLoaded();
|
void MarkAllLoaded();
|
||||||
void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload);
|
void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload);
|
||||||
void TryAutoload();
|
void TryAutoload();
|
||||||
void AddLibrary(IExtension *pSource, const char *library);
|
void AddLibrary(IExtension *pSource, const char *library);
|
||||||
bool LibraryExists(const char *library);
|
bool LibraryExists(const char *library);
|
||||||
void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax);
|
void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax);
|
||||||
void CallOnCoreMapEnd();
|
|
||||||
void AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface);
|
void AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface);
|
||||||
const CVector<IExtension *> *ListExtensions();
|
public:
|
||||||
void FreeExtensionList(const CVector<IExtension *> *list);
|
void ListExtensionsToClient(CPlayer *player, const CCommand &args);
|
||||||
public:
|
public:
|
||||||
CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
|
CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
@@ -1,67 +1,87 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet :
|
/**
|
||||||
// =============================================================================
|
* vim: set ts=4 sw=4 tw=99 noet :
|
||||||
// SourceMod
|
* =============================================================================
|
||||||
// Copyright (C) 2004-2015 AlliedModders LLC. All rights reserved.
|
* SourceMod
|
||||||
// =============================================================================
|
* Copyright (C) 2004-2008 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
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
// Free Software Foundation.
|
* 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
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
// details.
|
* 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/>.
|
* 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
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||||
// "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||||
// by the Valve Corporation. You must obey the GNU General Public License in
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||||
// all respects for all other code used. Additionally, AlliedModders LLC grants
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||||
// this exception to all derivative works. AlliedModders LLC defines further
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||||
// exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
* this exception to all derivative works. AlliedModders LLC defines further
|
||||||
// or <http://www.sourcemod.net/license.php>.
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||||
|
* or <http://www.sourcemod.net/license.php>.
|
||||||
|
*
|
||||||
|
* Version: $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "ForwardSys.h"
|
#include "ForwardSys.h"
|
||||||
|
#include "PluginSys.h"
|
||||||
|
#include "ShareSys.h"
|
||||||
#include "DebugReporter.h"
|
#include "DebugReporter.h"
|
||||||
#include "common_logic.h"
|
|
||||||
#include <bridge/include/IScriptManager.h>
|
|
||||||
#include <amtl/am-string.h>
|
|
||||||
#include <ReentrantList.h>
|
|
||||||
|
|
||||||
using namespace ke;
|
|
||||||
|
|
||||||
CForwardManager g_Forwards;
|
CForwardManager g_Forwards;
|
||||||
|
|
||||||
// Genesis turns to its source, reduction occurs stepwise although the essence
|
/**
|
||||||
// is all one. End of line. FTL system check.
|
* Genesis turns to its source, reduction occurs stepwise although the essence is all one.
|
||||||
|
* End of line. FTL system check.
|
||||||
|
*
|
||||||
|
* :TODO: WHAT NEEDS TO BE TESTED IN THIS BEAST
|
||||||
|
* VARARG FUNCTIONS:
|
||||||
|
* - Pushing no varargs
|
||||||
|
*/
|
||||||
|
|
||||||
|
// :TODO: IMPORTANT!!! The result pointer arg in the execute function maybe invalid if the forward fails
|
||||||
|
// so later evaluation of this result may cause problems on higher levels of abstraction. DOCUMENT OR FIX ALL FORWARDS!
|
||||||
|
|
||||||
|
CForwardManager::~CForwardManager()
|
||||||
|
{
|
||||||
|
CStack<CForward *>::iterator iter;
|
||||||
|
for (iter=m_FreeForwards.begin(); iter!=m_FreeForwards.end(); iter++)
|
||||||
|
{
|
||||||
|
delete (*iter);
|
||||||
|
}
|
||||||
|
m_FreeForwards.popall();
|
||||||
|
}
|
||||||
|
|
||||||
void CForwardManager::OnSourceModAllInitialized()
|
void CForwardManager::OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
scripts->AddPluginsListener(this);
|
g_PluginSys.AddPluginsListener(this);
|
||||||
sharesys->AddInterface(NULL, this);
|
g_ShareSys.AddInterface(NULL, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
IForward *CForwardManager::CreateForward(const char *name, ExecType et, unsigned int num_params, const ParamType *types, ...)
|
IForward *CForwardManager::CreateForward(const char *name, ExecType et, unsigned int num_params, const ParamType *types, ...)
|
||||||
{
|
{
|
||||||
|
CForward *fwd;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, types);
|
va_start(ap, types);
|
||||||
|
|
||||||
CForward *fwd = CForward::CreateForward(name, et, num_params, types, ap);
|
fwd = CForward::CreateForward(name, et, num_params, types, ap);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (fwd)
|
if (fwd)
|
||||||
{
|
{
|
||||||
scripts->AddFunctionsToForward(name, fwd);
|
g_PluginSys.AddFunctionsToForward(name, fwd);
|
||||||
|
|
||||||
m_managed.append(fwd);
|
m_managed.push_back(fwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fwd;
|
return fwd;
|
||||||
@@ -69,16 +89,17 @@ IForward *CForwardManager::CreateForward(const char *name, ExecType et, unsigned
|
|||||||
|
|
||||||
IChangeableForward *CForwardManager::CreateForwardEx(const char *name, ExecType et, int num_params, const ParamType *types, ...)
|
IChangeableForward *CForwardManager::CreateForwardEx(const char *name, ExecType et, int num_params, const ParamType *types, ...)
|
||||||
{
|
{
|
||||||
|
CForward *fwd;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, types);
|
va_start(ap, types);
|
||||||
|
|
||||||
CForward *fwd = CForward::CreateForward(name, et, num_params, types, ap);
|
fwd = CForward::CreateForward(name, et, num_params, types, ap);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (fwd)
|
if (fwd)
|
||||||
{
|
{
|
||||||
m_unmanaged.append(fwd);
|
m_unmanaged.push_back(fwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fwd;
|
return fwd;
|
||||||
@@ -87,103 +108,115 @@ IChangeableForward *CForwardManager::CreateForwardEx(const char *name, ExecType
|
|||||||
void CForwardManager::OnPluginLoaded(IPlugin *plugin)
|
void CForwardManager::OnPluginLoaded(IPlugin *plugin)
|
||||||
{
|
{
|
||||||
/* Attach any globally managed forwards */
|
/* Attach any globally managed forwards */
|
||||||
for (ForwardIter iter(m_managed); !iter.done(); iter.next()) {
|
List<CForward *>::iterator iter;
|
||||||
CForward *fwd = (*iter);
|
CForward *fwd;
|
||||||
|
|
||||||
|
for (iter=m_managed.begin(); iter!=m_managed.end(); iter++)
|
||||||
|
{
|
||||||
|
fwd = (*iter);
|
||||||
IPluginFunction *pFunc = plugin->GetBaseContext()->GetFunctionByName(fwd->GetForwardName());
|
IPluginFunction *pFunc = plugin->GetBaseContext()->GetFunctionByName(fwd->GetForwardName());
|
||||||
if (pFunc)
|
if (pFunc)
|
||||||
fwd->AddFunction(pFunc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CForwardManager::OnPluginUnloaded(IPlugin *plugin)
|
|
||||||
{
|
|
||||||
for (ForwardIter iter(m_managed); !iter.done(); iter.next()) {
|
|
||||||
CForward *fwd = (*iter);
|
|
||||||
fwd->RemoveFunctionsOfPlugin(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ForwardIter iter(m_unmanaged); !iter.done(); iter.next()) {
|
|
||||||
CForward *fwd = (*iter);
|
|
||||||
fwd->RemoveFunctionsOfPlugin(plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IForward *CForwardManager::FindForward(const char *name, IChangeableForward **ifchng)
|
|
||||||
{
|
|
||||||
for (ForwardIter iter(m_managed); !iter.done(); iter.next()) {
|
|
||||||
CForward *fwd = (*iter);
|
|
||||||
if (strcmp(fwd->GetForwardName(), name) == 0) {
|
|
||||||
if (ifchng)
|
|
||||||
*ifchng = NULL;
|
|
||||||
return fwd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ForwardIter iter(m_unmanaged); !iter.done(); iter.next()) {
|
|
||||||
CForward *fwd = (*iter);
|
|
||||||
if (strcmp(fwd->GetForwardName(), name) == 0) {
|
|
||||||
if (ifchng)
|
|
||||||
*ifchng = fwd;
|
|
||||||
return fwd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ifchng)
|
|
||||||
*ifchng = NULL;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CForwardManager::ReleaseForward(IForward *aForward)
|
|
||||||
{
|
|
||||||
CForward *fwd = static_cast<CForward *>(aForward);
|
|
||||||
m_managed.remove(fwd);
|
|
||||||
m_unmanaged.remove(fwd);
|
|
||||||
delete fwd;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CForwardManager::OnPluginPauseChange(IPlugin *plugin, bool paused)
|
|
||||||
{
|
|
||||||
if (paused)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Attach any globally managed forwards */
|
|
||||||
for (ForwardIter iter(m_managed); !iter.done(); iter.next()) {
|
|
||||||
CForward *fwd = (*iter);
|
|
||||||
IPluginFunction *pFunc = plugin->GetBaseContext()->GetFunctionByName(fwd->GetForwardName());
|
|
||||||
// Only add functions, if they aren't registered yet!
|
|
||||||
if (pFunc && !fwd->IsFunctionRegistered(pFunc))
|
|
||||||
{
|
{
|
||||||
fwd->AddFunction(pFunc);
|
fwd->AddFunction(pFunc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CForwardManager::OnPluginUnloaded(IPlugin *plugin)
|
||||||
|
{
|
||||||
|
List<CForward *>::iterator iter;
|
||||||
|
CForward *fwd;
|
||||||
|
|
||||||
|
for (iter=m_managed.begin(); iter!=m_managed.end(); iter++)
|
||||||
|
{
|
||||||
|
fwd = (*iter);
|
||||||
|
fwd->RemoveFunctionsOfPlugin(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (iter=m_unmanaged.begin(); iter!=m_unmanaged.end(); iter++)
|
||||||
|
{
|
||||||
|
fwd = (*iter);
|
||||||
|
fwd->RemoveFunctionsOfPlugin(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IForward *CForwardManager::FindForward(const char *name, IChangeableForward **ifchng)
|
||||||
|
{
|
||||||
|
List<CForward *>::iterator iter;
|
||||||
|
CForward *fwd;
|
||||||
|
|
||||||
|
for (iter=m_managed.begin(); iter!=m_managed.end(); iter++)
|
||||||
|
{
|
||||||
|
fwd = (*iter);
|
||||||
|
if (strcmp(fwd->GetForwardName(), name) == 0)
|
||||||
|
{
|
||||||
|
if (ifchng)
|
||||||
|
{
|
||||||
|
*ifchng = NULL;
|
||||||
|
}
|
||||||
|
return fwd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (iter=m_unmanaged.begin(); iter!=m_unmanaged.end(); iter++)
|
||||||
|
{
|
||||||
|
fwd = (*iter);
|
||||||
|
if (strcmp(fwd->GetForwardName(), name) == 0)
|
||||||
|
{
|
||||||
|
if (ifchng)
|
||||||
|
{
|
||||||
|
*ifchng = fwd;
|
||||||
|
}
|
||||||
|
return fwd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ifchng)
|
||||||
|
{
|
||||||
|
*ifchng = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CForwardManager::ReleaseForward(IForward *forward)
|
||||||
|
{
|
||||||
|
ForwardFree(static_cast<CForward *>(forward));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CForwardManager::ForwardFree(CForward *fwd)
|
||||||
|
{
|
||||||
|
if (fwd == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_FreeForwards.push(fwd);
|
||||||
|
m_managed.remove(fwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
CForward *CForwardManager::ForwardMake()
|
||||||
|
{
|
||||||
|
CForward *fwd;
|
||||||
|
if (m_FreeForwards.empty())
|
||||||
|
{
|
||||||
|
fwd = new CForward;
|
||||||
|
} else {
|
||||||
|
fwd = m_FreeForwards.front();
|
||||||
|
m_FreeForwards.pop();
|
||||||
|
}
|
||||||
|
return fwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CForwardManager::OnPluginPauseChange(IPlugin *plugin, bool paused)
|
||||||
|
{
|
||||||
|
/* No longer used */
|
||||||
|
}
|
||||||
|
|
||||||
/*************************************
|
/*************************************
|
||||||
* ACTUAL FORWARD API IMPLEMENTATION *
|
* ACTUAL FORWARD API IMPLEMENTATION *
|
||||||
*************************************/
|
*************************************/
|
||||||
|
|
||||||
CForward::CForward(ExecType et, const char *name, const ParamType *types, unsigned num_params)
|
|
||||||
: m_numparams(0),
|
|
||||||
m_varargs(0),
|
|
||||||
m_ExecType(et),
|
|
||||||
m_curparam(0),
|
|
||||||
m_errstate(SP_ERROR_NONE)
|
|
||||||
{
|
|
||||||
ke::SafeStrcpy(m_name, sizeof(m_name), name ? name : "");
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int num_params, const ParamType *types, va_list ap)
|
CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int num_params, const ParamType *types, va_list ap)
|
||||||
{
|
{
|
||||||
ParamType _types[SP_MAX_EXEC_PARAMS];
|
ParamType _types[SP_MAX_EXEC_PARAMS];
|
||||||
@@ -221,7 +254,30 @@ CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int nu
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CForward(et, name, _types, num_params);
|
CForward *pForward = g_Forwards.ForwardMake();
|
||||||
|
pForward->m_IterGuard = NULL;
|
||||||
|
pForward->m_curparam = 0;
|
||||||
|
pForward->m_ExecType = et;
|
||||||
|
snprintf(pForward->m_name, FORWARDS_NAME_MAX, "%s", name ? name : "");
|
||||||
|
|
||||||
|
for (unsigned int i=0; i<num_params; i++)
|
||||||
|
{
|
||||||
|
pForward->m_types[i] = _types[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num_params && _types[num_params-1] == Param_VarArgs)
|
||||||
|
{
|
||||||
|
pForward->m_varargs = num_params--;
|
||||||
|
} else {
|
||||||
|
pForward->m_varargs = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pForward->m_numparams = num_params;
|
||||||
|
pForward->m_errstate = SP_ERROR_NONE;
|
||||||
|
|
||||||
|
pForward->m_functions.clear();
|
||||||
|
|
||||||
|
return pForward;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CForward::Execute(cell_t *result, IForwardFilter *filter)
|
int CForward::Execute(cell_t *result, IForwardFilter *filter)
|
||||||
@@ -233,6 +289,8 @@ int CForward::Execute(cell_t *result, IForwardFilter *filter)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FuncIter iter = m_functions.begin();
|
||||||
|
IPluginFunction *func;
|
||||||
cell_t cur_result = 0;
|
cell_t cur_result = 0;
|
||||||
cell_t high_result = 0;
|
cell_t high_result = 0;
|
||||||
cell_t low_result = 0;
|
cell_t low_result = 0;
|
||||||
@@ -240,38 +298,54 @@ int CForward::Execute(cell_t *result, IForwardFilter *filter)
|
|||||||
unsigned int success=0;
|
unsigned int success=0;
|
||||||
unsigned int num_params = m_curparam;
|
unsigned int num_params = m_curparam;
|
||||||
FwdParamInfo temp_info[SP_MAX_EXEC_PARAMS];
|
FwdParamInfo temp_info[SP_MAX_EXEC_PARAMS];
|
||||||
|
FwdParamInfo *param;
|
||||||
|
ParamType type;
|
||||||
|
|
||||||
/* Save local, reset */
|
/* Save local, reset */
|
||||||
memcpy(temp_info, m_params, sizeof(m_params));
|
memcpy(temp_info, m_params, sizeof(m_params));
|
||||||
m_curparam = 0;
|
m_curparam = 0;
|
||||||
|
|
||||||
for (FuncIter iter(m_functions); !iter.done(); iter.next())
|
FuncIteratorGuard guard(&m_IterGuard, &iter);
|
||||||
|
|
||||||
|
while (iter != m_functions.end())
|
||||||
{
|
{
|
||||||
IPluginFunction *func = (*iter);
|
func = (*iter);
|
||||||
|
|
||||||
if (filter)
|
if (filter)
|
||||||
filter->Preprocess(func, temp_info);
|
filter->Preprocess(func, temp_info);
|
||||||
|
|
||||||
if (func->GetParentRuntime()->IsPaused())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (unsigned int i=0; i<num_params; i++)
|
for (unsigned int i=0; i<num_params; i++)
|
||||||
{
|
{
|
||||||
int err = SP_ERROR_PARAM;
|
int err = SP_ERROR_PARAM;
|
||||||
FwdParamInfo *param = &temp_info[i];
|
param = &temp_info[i];
|
||||||
|
|
||||||
ParamType type;
|
|
||||||
if (i >= m_numparams || m_types[i] == Param_Any)
|
if (i >= m_numparams || m_types[i] == Param_Any)
|
||||||
|
{
|
||||||
type = param->pushedas;
|
type = param->pushedas;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
type = m_types[i];
|
type = m_types[i];
|
||||||
|
}
|
||||||
|
|
||||||
if ((i >= m_numparams) || (type & SP_PARAMFLAG_BYREF))
|
if ((i >= m_numparams) || (type & SP_PARAMFLAG_BYREF))
|
||||||
{
|
{
|
||||||
/* If we're byref or we're vararg, we always push everything by ref.
|
/* If we're byref or we're vararg, we always push everything by ref.
|
||||||
* Even if they're byval, we must push them byref.
|
* Even if they're byval, we must push them byref.
|
||||||
*/
|
*/
|
||||||
err = _ExecutePushRef(func, type, param);
|
if (type == Param_String)
|
||||||
|
{
|
||||||
|
err = func->PushStringEx((char *)param->byref.orig_addr, param->byref.cells, param->byref.sz_flags, param->byref.flags);
|
||||||
|
}
|
||||||
|
else if (type == Param_Float || type == Param_Cell)
|
||||||
|
{
|
||||||
|
err = func->PushCellByRef(¶m->val);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
err = func->PushArray(param->byref.orig_addr, param->byref.cells, param->byref.flags);
|
||||||
|
assert(type == Param_Array || type == Param_FloatByRef || type == Param_CellByRef);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -331,6 +405,9 @@ int CForward::Execute(cell_t *result, IForwardFilter *filter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!guard.Triggered())
|
||||||
|
iter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
@@ -370,58 +447,6 @@ done:
|
|||||||
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)
|
int CForward::PushCell(cell_t cell)
|
||||||
{
|
{
|
||||||
if (m_curparam < m_numparams)
|
if (m_curparam < m_numparams)
|
||||||
@@ -440,7 +465,6 @@ int CForward::PushCell(cell_t cell)
|
|||||||
m_params[m_curparam].pushedas = Param_Cell;
|
m_params[m_curparam].pushedas = Param_Cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_params[m_curparam].isnull = false;
|
|
||||||
m_params[m_curparam++].val = cell;
|
m_params[m_curparam++].val = cell;
|
||||||
|
|
||||||
return SP_ERROR_NONE;
|
return SP_ERROR_NONE;
|
||||||
@@ -464,7 +488,6 @@ int CForward::PushFloat(float number)
|
|||||||
m_params[m_curparam].pushedas = Param_Float;
|
m_params[m_curparam].pushedas = Param_Float;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_params[m_curparam].isnull = false;
|
|
||||||
m_params[m_curparam++].val = *(cell_t *)&number;
|
m_params[m_curparam++].val = *(cell_t *)&number;
|
||||||
|
|
||||||
return SP_ERROR_NONE;
|
return SP_ERROR_NONE;
|
||||||
@@ -523,22 +546,14 @@ void CForward::_Int_PushArray(cell_t *inarray, unsigned int cells, int flags)
|
|||||||
m_params[m_curparam].byref.cells = cells;
|
m_params[m_curparam].byref.cells = cells;
|
||||||
m_params[m_curparam].byref.flags = flags;
|
m_params[m_curparam].byref.flags = flags;
|
||||||
m_params[m_curparam].byref.orig_addr = inarray;
|
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)
|
int CForward::PushArray(cell_t *inarray, unsigned int cells, int flags)
|
||||||
{
|
{
|
||||||
/* Push a reference to the NULL_VECTOR pubvar if NULL was passed. */
|
/* We don't allow this here */
|
||||||
if (!inarray)
|
if (!inarray)
|
||||||
{
|
{
|
||||||
/* Make sure this was intentional. */
|
return SetError(SP_ERROR_PARAM);
|
||||||
if (cells == 3)
|
|
||||||
{
|
|
||||||
return PushNullVector();
|
|
||||||
} else {
|
|
||||||
/* We don't allow this here */
|
|
||||||
return SetError(SP_ERROR_PARAM);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_curparam < m_numparams)
|
if (m_curparam < m_numparams)
|
||||||
@@ -570,17 +585,10 @@ void CForward::_Int_PushString(cell_t *inarray, unsigned int cells, int sz_flags
|
|||||||
m_params[m_curparam].byref.flags = cp_flags;
|
m_params[m_curparam].byref.flags = cp_flags;
|
||||||
m_params[m_curparam].byref.orig_addr = inarray;
|
m_params[m_curparam].byref.orig_addr = inarray;
|
||||||
m_params[m_curparam].byref.sz_flags = sz_flags;
|
m_params[m_curparam].byref.sz_flags = sz_flags;
|
||||||
m_params[m_curparam].isnull = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CForward::PushString(const char *string)
|
int CForward::PushString(const char *string)
|
||||||
{
|
{
|
||||||
/* Push a reference to the NULL_STRING pubvar if NULL was passed. */
|
|
||||||
if (!string)
|
|
||||||
{
|
|
||||||
return PushNullString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_curparam < m_numparams)
|
if (m_curparam < m_numparams)
|
||||||
{
|
{
|
||||||
if (m_types[m_curparam] == Param_Any)
|
if (m_types[m_curparam] == Param_Any)
|
||||||
@@ -627,52 +635,6 @@ int CForward::PushStringEx(char *buffer, size_t length, int sz_flags, int cp_fla
|
|||||||
return SP_ERROR_NONE;
|
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;
|
|
||||||
|
|
||||||
return SP_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CForward::Cancel()
|
void CForward::Cancel()
|
||||||
{
|
{
|
||||||
if (!m_curparam)
|
if (!m_curparam)
|
||||||
@@ -710,69 +672,75 @@ bool CForward::RemoveFunction(IPluginContext *pContext, funcid_t index)
|
|||||||
|
|
||||||
bool CForward::RemoveFunction(IPluginFunction *func)
|
bool CForward::RemoveFunction(IPluginFunction *func)
|
||||||
{
|
{
|
||||||
ReentrantList<IPluginFunction *> *lst;
|
|
||||||
if (func->IsRunnable())
|
|
||||||
lst = &m_functions;
|
|
||||||
else
|
|
||||||
lst = &m_paused;
|
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (FuncIter iter(lst); !iter.done(); iter.next()) {
|
FuncIter iter;
|
||||||
if (*iter == func) {
|
List<IPluginFunction *> *lst;
|
||||||
iter.remove();
|
|
||||||
|
if (func->IsRunnable())
|
||||||
|
{
|
||||||
|
lst = &m_functions;
|
||||||
|
} else {
|
||||||
|
lst = &m_paused;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (iter=m_functions.begin(); iter!=m_functions.end(); iter++)
|
||||||
|
{
|
||||||
|
if ((*iter) == func)
|
||||||
|
{
|
||||||
|
m_IterGuard->FixIteratorChain(iter);
|
||||||
found = true;
|
found = true;
|
||||||
|
lst->erase(iter);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cancel a call, if any */
|
/* Cancel a call, if any */
|
||||||
if (found || m_curparam)
|
if (found || m_curparam)
|
||||||
|
{
|
||||||
func->Cancel();
|
func->Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CForward::RemoveFunctionsOfPlugin(IPlugin *plugin)
|
unsigned int CForward::RemoveFunctionsOfPlugin(IPlugin *plugin)
|
||||||
{
|
{
|
||||||
|
FuncIter iter;
|
||||||
|
IPluginFunction *func;
|
||||||
unsigned int removed = 0;
|
unsigned int removed = 0;
|
||||||
for (FuncIter iter(m_functions); !iter.done(); iter.next()) {
|
IPluginContext *pContext = plugin->GetBaseContext();
|
||||||
IPluginFunction *func = *iter;
|
for (iter=m_functions.begin(); iter!=m_functions.end();)
|
||||||
if (func->GetParentContext() == plugin->GetBaseContext()) {
|
{
|
||||||
iter.remove();
|
func = (*iter);
|
||||||
|
if (func->GetParentContext() == pContext)
|
||||||
|
{
|
||||||
|
iter = m_functions.erase(iter);
|
||||||
removed++;
|
removed++;
|
||||||
|
} else {
|
||||||
|
iter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CForward::AddFunction(IPluginFunction *func)
|
bool CForward::AddFunction(IPluginFunction *func)
|
||||||
{
|
{
|
||||||
if (m_curparam)
|
if (m_curparam)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (func->IsRunnable())
|
if (func->IsRunnable())
|
||||||
m_functions.append(func);
|
{
|
||||||
else
|
m_functions.push_back(func);
|
||||||
m_paused.append(func);
|
} else {
|
||||||
|
m_paused.push_back(func);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CForward::IsFunctionRegistered(IPluginFunction *func)
|
|
||||||
{
|
|
||||||
ReentrantList<IPluginFunction *> *lst;
|
|
||||||
if (func->IsRunnable())
|
|
||||||
lst = &m_functions;
|
|
||||||
else
|
|
||||||
lst = &m_paused;
|
|
||||||
|
|
||||||
for (FuncIter iter(lst); !iter.done(); iter.next()) {
|
|
||||||
if ((*iter) == func)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *CForward::GetForwardName()
|
const char *CForward::GetForwardName()
|
||||||
{
|
{
|
||||||
return m_name;
|
return m_name;
|
||||||
@@ -780,7 +748,7 @@ const char *CForward::GetForwardName()
|
|||||||
|
|
||||||
unsigned int CForward::GetFunctionCount()
|
unsigned int CForward::GetFunctionCount()
|
||||||
{
|
{
|
||||||
return m_functions.length();
|
return m_functions.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecType CForward::GetExecType()
|
ExecType CForward::GetExecType()
|
||||||
@@ -0,0 +1,211 @@
|
|||||||
|
/**
|
||||||
|
* vim: set ts=4 :
|
||||||
|
* =============================================================================
|
||||||
|
* SourceMod
|
||||||
|
* Copyright (C) 2004-2008 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_SOURCEMOD_FORWARDSYSTEM_H_
|
||||||
|
#define _INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
|
||||||
|
|
||||||
|
#include <IForwardSys.h>
|
||||||
|
#include <IPluginSys.h>
|
||||||
|
#include "sm_globals.h"
|
||||||
|
#include <sh_list.h>
|
||||||
|
#include <sh_stack.h>
|
||||||
|
#include "sourcemod.h"
|
||||||
|
|
||||||
|
using namespace SourceHook;
|
||||||
|
|
||||||
|
typedef List<IPluginFunction *>::iterator FuncIter;
|
||||||
|
|
||||||
|
/* :TODO: a global name max define for sourcepawn, should mirror compiler's sNAMEMAX */
|
||||||
|
#define FORWARDS_NAME_MAX 64
|
||||||
|
|
||||||
|
struct ByrefInfo
|
||||||
|
{
|
||||||
|
unsigned int cells;
|
||||||
|
cell_t *orig_addr;
|
||||||
|
int flags;
|
||||||
|
int sz_flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FwdParamInfo
|
||||||
|
{
|
||||||
|
cell_t val;
|
||||||
|
ByrefInfo byref;
|
||||||
|
ParamType pushedas;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SourceMod::IForwardFilter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void Preprocess(IPluginFunction *fun, FwdParamInfo *params)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class FuncIteratorGuard
|
||||||
|
{
|
||||||
|
bool triggered;
|
||||||
|
FuncIteratorGuard **pprev;
|
||||||
|
FuncIter *iter;
|
||||||
|
FuncIteratorGuard *next;
|
||||||
|
public:
|
||||||
|
FuncIteratorGuard(FuncIteratorGuard **pprev, FuncIter *iter)
|
||||||
|
: triggered(false), pprev(pprev), iter(iter), next(*pprev)
|
||||||
|
{
|
||||||
|
*pprev = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
~FuncIteratorGuard()
|
||||||
|
{
|
||||||
|
*pprev = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Triggered()
|
||||||
|
{
|
||||||
|
bool t = triggered;
|
||||||
|
triggered = false;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This should not read from |this| before the NULL check, because FwdSys
|
||||||
|
* can call (NULL)->FixIteratorChain().
|
||||||
|
*/
|
||||||
|
void FixIteratorChain(FuncIter &other)
|
||||||
|
{
|
||||||
|
FuncIteratorGuard *guard = this;
|
||||||
|
while (guard != NULL)
|
||||||
|
{
|
||||||
|
if (*guard->iter == other)
|
||||||
|
{
|
||||||
|
*(guard->iter) = ++(*(guard->iter));
|
||||||
|
guard->triggered = true;
|
||||||
|
}
|
||||||
|
guard = guard->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CForward : public IChangeableForward
|
||||||
|
{
|
||||||
|
public: //ICallable
|
||||||
|
virtual int PushCell(cell_t cell);
|
||||||
|
virtual int PushCellByRef(cell_t *cell, int flags);
|
||||||
|
virtual int PushFloat(float number);
|
||||||
|
virtual int PushFloatByRef(float *number, int flags);
|
||||||
|
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 void Cancel();
|
||||||
|
public: //IForward
|
||||||
|
virtual const char *GetForwardName();
|
||||||
|
virtual unsigned int GetFunctionCount();
|
||||||
|
virtual ExecType GetExecType();
|
||||||
|
virtual int Execute(cell_t *result, IForwardFilter *filter);
|
||||||
|
public: //IChangeableForward
|
||||||
|
virtual bool RemoveFunction(IPluginFunction *func);
|
||||||
|
virtual unsigned int RemoveFunctionsOfPlugin(IPlugin *plugin);
|
||||||
|
virtual bool AddFunction(IPluginFunction *func);
|
||||||
|
virtual bool AddFunction(IPluginContext *ctx, funcid_t index);
|
||||||
|
virtual bool RemoveFunction(IPluginContext *ctx, funcid_t index);
|
||||||
|
public:
|
||||||
|
static CForward *CreateForward(const char *name,
|
||||||
|
ExecType et,
|
||||||
|
unsigned int num_params,
|
||||||
|
const ParamType *types,
|
||||||
|
va_list ap);
|
||||||
|
private:
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
/* :TODO: I want a caching list type here.
|
||||||
|
* Destroying these things and using new/delete for their members feels bad.
|
||||||
|
*/
|
||||||
|
mutable List<IPluginFunction *> m_functions;
|
||||||
|
mutable List<IPluginFunction *> m_paused;
|
||||||
|
FuncIteratorGuard *m_IterGuard;
|
||||||
|
|
||||||
|
/* Type and name information */
|
||||||
|
FwdParamInfo m_params[SP_MAX_EXEC_PARAMS];
|
||||||
|
ParamType m_types[SP_MAX_EXEC_PARAMS];
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CForwardManager :
|
||||||
|
public IForwardManager,
|
||||||
|
public IPluginsListener,
|
||||||
|
public SMGlobalClass
|
||||||
|
{
|
||||||
|
friend class CForward;
|
||||||
|
public:
|
||||||
|
~CForwardManager();
|
||||||
|
public: //IForwardManager
|
||||||
|
IForward *CreateForward(const char *name,
|
||||||
|
ExecType et,
|
||||||
|
unsigned int num_params,
|
||||||
|
const ParamType *types,
|
||||||
|
...);
|
||||||
|
IChangeableForward *CreateForwardEx(const char *name,
|
||||||
|
ExecType et,
|
||||||
|
int num_params,
|
||||||
|
const ParamType *types,
|
||||||
|
...);
|
||||||
|
IForward *FindForward(const char *name, IChangeableForward **ifchng);
|
||||||
|
void ReleaseForward(IForward *forward);
|
||||||
|
public: //IPluginsListener
|
||||||
|
void OnPluginLoaded(IPlugin *plugin);
|
||||||
|
void OnPluginUnloaded(IPlugin *plugin);
|
||||||
|
void OnPluginPauseChange(IPlugin *plugin, bool paused);
|
||||||
|
public: //SMGlobalClass
|
||||||
|
void OnSourceModAllInitialized();
|
||||||
|
protected:
|
||||||
|
CForward *ForwardMake();
|
||||||
|
void ForwardFree(CForward *fwd);
|
||||||
|
private:
|
||||||
|
CStack<CForward *> m_FreeForwards;
|
||||||
|
List<CForward *> m_managed;
|
||||||
|
List<CForward *> m_unmanaged;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern CForwardManager g_Forwards;
|
||||||
|
|
||||||
|
#endif //_INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
|
||||||
@@ -1,171 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet :
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#include "GameHooks.h"
|
|
||||||
#include "sourcemod.h"
|
|
||||||
#include "ConVarManager.h"
|
|
||||||
#include "command_args.h"
|
|
||||||
#include "provider.h"
|
|
||||||
|
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
|
||||||
SH_DECL_HOOK3_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *, float);
|
|
||||||
#else
|
|
||||||
SH_DECL_HOOK2_void(ICvar, CallGlobalChangeCallback, SH_NOATTRIB, false, ConVar *, const char *);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
|
||||||
SH_DECL_HOOK5_void(IServerGameDLL, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *);
|
|
||||||
SH_DECL_HOOK5_void(IServerPluginCallbacks, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
|
||||||
SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
|
|
||||||
#else
|
|
||||||
SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, false, int);
|
|
||||||
|
|
||||||
GameHooks::GameHooks()
|
|
||||||
: client_cvar_query_mode_(ClientCvarQueryMode::Unavailable),
|
|
||||||
last_command_client_(-1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameHooks::Start()
|
|
||||||
{
|
|
||||||
// Hook ICvar::CallGlobalChangeCallbacks.
|
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
|
||||||
hooks_ += SH_ADD_HOOK(ICvar, CallGlobalChangeCallbacks, icvar, SH_STATIC(OnConVarChanged), false);
|
|
||||||
#else
|
|
||||||
hooks_ += SH_ADD_HOOK(ICvar, CallGlobalChangeCallback, icvar, SH_STATIC(OnConVarChanged), false);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Episode 2 has this function by default, but the older versions do not.
|
|
||||||
#if SOURCE_ENGINE == SE_EPISODEONE
|
|
||||||
if (g_SMAPI->GetGameDLLVersion() >= 6) {
|
|
||||||
hooks_ += SH_ADD_HOOK(IServerGameDLL, OnQueryCvarValueFinished, gamedll, SH_MEMBER(this, &GameHooks::OnQueryCvarValueFinished), false);
|
|
||||||
client_cvar_query_mode_ = ClientCvarQueryMode::DLL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
hooks_ += SH_ADD_HOOK(IServerGameClients, SetCommandClient, serverClients, SH_MEMBER(this, &GameHooks::SetCommandClient), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameHooks::OnVSPReceived()
|
|
||||||
{
|
|
||||||
if (client_cvar_query_mode_ != ClientCvarQueryMode::Unavailable)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (g_SMAPI->GetSourceEngineBuild() == SOURCE_ENGINE_ORIGINAL || vsp_version < 2)
|
|
||||||
return;
|
|
||||||
|
|
||||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
|
||||||
hooks_ += SH_ADD_HOOK(IServerPluginCallbacks, OnQueryCvarValueFinished, vsp_interface, SH_MEMBER(this, &GameHooks::OnQueryCvarValueFinished), false);
|
|
||||||
client_cvar_query_mode_ = ClientCvarQueryMode::VSP;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameHooks::Shutdown()
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < hooks_.length(); i++)
|
|
||||||
SH_REMOVE_HOOK_ID(hooks_[i]);
|
|
||||||
hooks_.clear();
|
|
||||||
|
|
||||||
client_cvar_query_mode_ = ClientCvarQueryMode::Unavailable;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
|
||||||
void GameHooks::OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue)
|
|
||||||
#else
|
|
||||||
void GameHooks::OnConVarChanged(ConVar *pConVar, const char *oldValue)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
#if SOURCE_ENGINE < SE_ORANGEBOX
|
|
||||||
float flOldValue = atof(oldValue);
|
|
||||||
#endif
|
|
||||||
g_ConVarManager.OnConVarChanged(pConVar, oldValue, flOldValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
|
||||||
void GameHooks::OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result,
|
|
||||||
const char *cvarName, const char *cvarValue){
|
|
||||||
int client = IndexOfEdict(pPlayer);
|
|
||||||
|
|
||||||
# if SOURCE_ENGINE == SE_CSGO
|
|
||||||
if (g_Players.HandleConVarQuery(cookie, client, result, cvarName, cvarValue))
|
|
||||||
return;
|
|
||||||
# endif
|
|
||||||
g_ConVarManager.OnClientQueryFinished(cookie, client, result, cvarName, cvarValue);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ke::RefPtr<CommandHook>
|
|
||||||
GameHooks::AddCommandHook(ConCommand *cmd, const CommandHook::Callback &callback)
|
|
||||||
{
|
|
||||||
return new CommandHook(cmd, callback, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
ke::RefPtr<CommandHook>
|
|
||||||
GameHooks::AddPostCommandHook(ConCommand *cmd, const CommandHook::Callback &callback)
|
|
||||||
{
|
|
||||||
return new CommandHook(cmd, callback, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameHooks::SetCommandClient(int client)
|
|
||||||
{
|
|
||||||
last_command_client_ = client + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandHook::CommandHook(ConCommand *cmd, const Callback &callback, bool post)
|
|
||||||
: hook_id_(0),
|
|
||||||
callback_(callback)
|
|
||||||
{
|
|
||||||
hook_id_ = SH_ADD_HOOK(ConCommand, Dispatch, cmd, SH_MEMBER(this, &CommandHook::Dispatch), post);
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandHook::~CommandHook()
|
|
||||||
{
|
|
||||||
if (hook_id_)
|
|
||||||
SH_REMOVE_HOOK_ID(hook_id_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandHook::Dispatch(DISPATCH_ARGS)
|
|
||||||
{
|
|
||||||
DISPATCH_PROLOGUE;
|
|
||||||
EngineArgs args(command);
|
|
||||||
|
|
||||||
AddRef();
|
|
||||||
bool rval = callback_(sCoreProviderImpl.CommandClient(), &args);
|
|
||||||
Release();
|
|
||||||
if (rval)
|
|
||||||
RETURN_META(MRES_SUPERCEDE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandHook::Zap()
|
|
||||||
{
|
|
||||||
hook_id_ = 0;
|
|
||||||
}
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet :
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_PROVIDER_GAME_HOOKS_H_
|
|
||||||
#define _INCLUDE_SOURCEMOD_PROVIDER_GAME_HOOKS_H_
|
|
||||||
|
|
||||||
// Needed for CEntityIndex, edict_t, etc.
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <eiface.h>
|
|
||||||
#include <iserverplugin.h>
|
|
||||||
#include <amtl/am-refcounting.h>
|
|
||||||
#include <amtl/am-vector.h>
|
|
||||||
#include <amtl/am-function.h>
|
|
||||||
|
|
||||||
class ConVar;
|
|
||||||
class CCommand;
|
|
||||||
struct CCommandContext;
|
|
||||||
|
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
|
||||||
# define DISPATCH_ARGS const CCommand &command
|
|
||||||
# define DISPATCH_PROLOGUE
|
|
||||||
#else
|
|
||||||
# define DISPATCH_ARGS
|
|
||||||
# define DISPATCH_PROLOGUE CCommand command
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace SourceMod {
|
|
||||||
|
|
||||||
// Describes the mechanism in which client cvar queries are implemented.
|
|
||||||
enum class ClientCvarQueryMode {
|
|
||||||
Unavailable,
|
|
||||||
DLL,
|
|
||||||
VSP
|
|
||||||
};
|
|
||||||
|
|
||||||
class ICommandArgs;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CommandHook(ConCommand *cmd, const Callback &callback, bool post);
|
|
||||||
~CommandHook();
|
|
||||||
void Dispatch(DISPATCH_ARGS);
|
|
||||||
void Zap();
|
|
||||||
|
|
||||||
private:
|
|
||||||
int hook_id_;
|
|
||||||
Callback callback_;
|
|
||||||
};
|
|
||||||
|
|
||||||
class GameHooks
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GameHooks();
|
|
||||||
|
|
||||||
void Start();
|
|
||||||
void Shutdown();
|
|
||||||
void OnVSPReceived();
|
|
||||||
|
|
||||||
ClientCvarQueryMode GetClientCvarQueryMode() const {
|
|
||||||
return client_cvar_query_mode_;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
ke::RefPtr<CommandHook> AddCommandHook(ConCommand *cmd, const CommandHook::Callback &callback);
|
|
||||||
ke::RefPtr<CommandHook> AddPostCommandHook(ConCommand *cmd, const CommandHook::Callback &callback);
|
|
||||||
|
|
||||||
int CommandClient() const {
|
|
||||||
return last_command_client_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
// Static callback that Valve's ConVar object executes when the convar's value changes.
|
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
|
||||||
static void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue);
|
|
||||||
#else
|
|
||||||
static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Callback for when StartQueryCvarValue() has finished.
|
|
||||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
|
||||||
void OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result,
|
|
||||||
const char *cvarName, const char *cvarValue);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void SetCommandClient(int client);
|
|
||||||
|
|
||||||
private:
|
|
||||||
class HookList : public ke::Vector<int>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
HookList &operator += (int hook_id) {
|
|
||||||
this->append(hook_id);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
HookList hooks_;
|
|
||||||
|
|
||||||
ClientCvarQueryMode client_cvar_query_mode_;
|
|
||||||
int last_command_client_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_PROVIDER_GAME_HOOKS_H_
|
|
||||||
+240
-458
@@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2016 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
@@ -38,10 +38,9 @@
|
|||||||
#include <IGameConfigs.h>
|
#include <IGameConfigs.h>
|
||||||
#include <compat_wrappers.h>
|
#include <compat_wrappers.h>
|
||||||
#include <Logger.h>
|
#include <Logger.h>
|
||||||
#include <amtl/os/am-shared-library.h>
|
#include "LibrarySys.h"
|
||||||
#include "logic_bridge.h"
|
#include "logic_bridge.h"
|
||||||
#include <tier0/mem.h>
|
#include <tier0/mem.h>
|
||||||
#include <bridge/include/ILogger.h>
|
|
||||||
|
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
#if SOURCE_ENGINE == SE_CSGO
|
||||||
#include <cstrike15_usermessages.pb.h>
|
#include <cstrike15_usermessages.pb.h>
|
||||||
@@ -50,54 +49,100 @@
|
|||||||
|
|
||||||
typedef ICommandLine *(*FakeGetCommandLine)();
|
typedef ICommandLine *(*FakeGetCommandLine)();
|
||||||
|
|
||||||
#define TIER0_NAME FORMAT_SOURCE_BIN_NAME("tier0")
|
#if defined _WIN32
|
||||||
#define VSTDLIB_NAME FORMAT_SOURCE_BIN_NAME("vstdlib")
|
#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_LEFT4DEAD2
|
||||||
|
#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
|
||||||
|
|
||||||
CHalfLife2 g_HL2;
|
CHalfLife2 g_HL2;
|
||||||
ConVar *sv_lan = NULL;
|
ConVar *sv_lan = NULL;
|
||||||
|
|
||||||
static void *g_EntList = NULL;
|
static void *g_EntList = NULL;
|
||||||
static void **g_pEntInfoList = NULL;
|
|
||||||
static int entInfoOffset = -1;
|
static int entInfoOffset = -1;
|
||||||
|
|
||||||
static CEntInfo *EntInfoArray()
|
namespace SourceHook
|
||||||
{
|
{
|
||||||
if (g_EntList != NULL)
|
template<>
|
||||||
|
int HashFunction<datamap_t *>(datamap_t * const &k)
|
||||||
{
|
{
|
||||||
return (CEntInfo *)((intp)g_EntList + entInfoOffset);
|
return reinterpret_cast<int>(k);
|
||||||
}
|
}
|
||||||
else if (g_pEntInfoList)
|
|
||||||
|
template<>
|
||||||
|
int Compare<datamap_t *>(datamap_t * const &k1, datamap_t * const &k2)
|
||||||
{
|
{
|
||||||
return *(CEntInfo **)g_pEntInfoList;
|
return (k1-k2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CHalfLife2::CHalfLife2()
|
CHalfLife2::CHalfLife2()
|
||||||
{
|
{
|
||||||
m_Maps.init();
|
m_pClasses = sm_trie_create();
|
||||||
|
|
||||||
m_pGetCommandLine = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CHalfLife2::~CHalfLife2()
|
CHalfLife2::~CHalfLife2()
|
||||||
{
|
{
|
||||||
for (NameHashSet<DataTableInfo *>::iterator iter = m_Classes.iter(); !iter.empty(); iter.next())
|
sm_trie_destroy(m_pClasses);
|
||||||
delete *iter;
|
|
||||||
|
|
||||||
for (DataTableMap::iterator iter = m_Maps.iter(); !iter.empty(); iter.next())
|
List<DataTableInfo *>::iterator iter;
|
||||||
delete iter->value;
|
DataTableInfo *pInfo;
|
||||||
|
for (iter=m_Tables.begin(); iter!=m_Tables.end(); iter++)
|
||||||
|
{
|
||||||
|
pInfo = (*iter);
|
||||||
|
delete pInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Tables.clear();
|
||||||
|
|
||||||
|
THash<datamap_t *, DataMapTrie>::iterator h_iter;
|
||||||
|
for (h_iter=m_Maps.begin(); h_iter!=m_Maps.end(); h_iter++)
|
||||||
|
{
|
||||||
|
if (h_iter->val.trie)
|
||||||
|
{
|
||||||
|
sm_trie_destroy(h_iter->val.trie);
|
||||||
|
h_iter->val.trie = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Maps.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||||
CSharedEdictChangeInfo *g_pSharedChangeInfo = NULL;
|
CSharedEdictChangeInfo *g_pSharedChangeInfo = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined METAMOD_PLAPI_VERSION || PLAPI_VERSION < 11
|
||||||
|
bool is_original_engine = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
void CHalfLife2::OnSourceModStartup(bool late)
|
void CHalfLife2::OnSourceModStartup(bool late)
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||||
if (g_SMAPI->GetSourceEngineBuild() != SOURCE_ENGINE_ORIGINAL && !g_pSharedChangeInfo)
|
|
||||||
|
/* The Ship currently is the only known game to use an older version of the engine */
|
||||||
|
#if defined METAMOD_PLAPI_VERSION || PLAPI_VERSION >= 11
|
||||||
|
if (g_SMAPI->GetSourceEngineBuild() == SOURCE_ENGINE_ORIGINAL)
|
||||||
|
#else
|
||||||
|
if (strcasecmp(g_SourceMod.GetGameFolderName(), "ship") == 0)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
is_original_engine = true;
|
||||||
|
}
|
||||||
|
else if (g_pSharedChangeInfo == NULL)
|
||||||
{
|
{
|
||||||
g_pSharedChangeInfo = engine->GetSharedEdictChangeInfo();
|
g_pSharedChangeInfo = engine->GetSharedEdictChangeInfo();
|
||||||
}
|
}
|
||||||
@@ -110,84 +155,17 @@ void CHalfLife2::OnSourceModAllInitialized()
|
|||||||
m_HinTextMsg = g_UserMsgs.GetMessageIndex("HintText");
|
m_HinTextMsg = g_UserMsgs.GetMessageIndex("HintText");
|
||||||
m_SayTextMsg = g_UserMsgs.GetMessageIndex("SayText");
|
m_SayTextMsg = g_UserMsgs.GetMessageIndex("SayText");
|
||||||
m_VGUIMenu = g_UserMsgs.GetMessageIndex("VGUIMenu");
|
m_VGUIMenu = g_UserMsgs.GetMessageIndex("VGUIMenu");
|
||||||
sharesys->AddInterface(NULL, this);
|
g_ShareSys.AddInterface(NULL, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHalfLife2::OnSourceModAllInitialized_Post()
|
void CHalfLife2::OnSourceModAllInitialized_Post()
|
||||||
{
|
{
|
||||||
InitLogicalEntData();
|
InitLogicalEntData();
|
||||||
InitCommandLine();
|
InitCommandLine();
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
|
||||||
m_CSGOBadList.init();
|
|
||||||
m_CSGOBadList.add("m_iItemDefinitionIndex");
|
|
||||||
m_CSGOBadList.add("m_iEntityLevel");
|
|
||||||
m_CSGOBadList.add("m_iItemIDHigh");
|
|
||||||
m_CSGOBadList.add("m_iItemIDLow");
|
|
||||||
m_CSGOBadList.add("m_iAccountID");
|
|
||||||
m_CSGOBadList.add("m_iEntityQuality");
|
|
||||||
m_CSGOBadList.add("m_bInitialized");
|
|
||||||
m_CSGOBadList.add("m_szCustomName");
|
|
||||||
m_CSGOBadList.add("m_iAttributeDefinitionIndex");
|
|
||||||
m_CSGOBadList.add("m_iRawValue32");
|
|
||||||
m_CSGOBadList.add("m_iRawInitialValue32");
|
|
||||||
m_CSGOBadList.add("m_nRefundableCurrency");
|
|
||||||
m_CSGOBadList.add("m_bSetBonus");
|
|
||||||
m_CSGOBadList.add("m_OriginalOwnerXuidLow");
|
|
||||||
m_CSGOBadList.add("m_OriginalOwnerXuidHigh");
|
|
||||||
m_CSGOBadList.add("m_nFallbackPaintKit");
|
|
||||||
m_CSGOBadList.add("m_nFallbackSeed");
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigResult CHalfLife2::OnSourceModConfigChanged(const char *key, const char *value,
|
|
||||||
ConfigSource source, char *error, size_t maxlength)
|
|
||||||
{
|
|
||||||
if (strcasecmp(key, "FollowCSGOServerGuidelines") == 0)
|
|
||||||
{
|
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
|
||||||
if (strcasecmp(value, "no") == 0)
|
|
||||||
{
|
|
||||||
m_bFollowCSGOServerGuidelines = false;
|
|
||||||
return ConfigResult_Accept;
|
|
||||||
}
|
|
||||||
else if (strcasecmp(value, "yes") == 0)
|
|
||||||
{
|
|
||||||
m_bFollowCSGOServerGuidelines = true;
|
|
||||||
return ConfigResult_Accept;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ke::SafeStrcpy(error, maxlength, "Invalid value: must be \"yes\" or \"no\"");
|
|
||||||
return ConfigResult_Reject;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return ConfigResult_Ignore;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHalfLife2::InitLogicalEntData()
|
void CHalfLife2::InitLogicalEntData()
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE == SE_TF2 \
|
|
||||||
|| SOURCE_ENGINE == SE_DODS \
|
|
||||||
|| SOURCE_ENGINE == SE_HL2DM \
|
|
||||||
|| SOURCE_ENGINE == SE_CSS \
|
|
||||||
|| SOURCE_ENGINE == SE_SDK2013 \
|
|
||||||
|| SOURCE_ENGINE == SE_BMS \
|
|
||||||
|| SOURCE_ENGINE == SE_NUCLEARDAWN
|
|
||||||
|
|
||||||
if (g_SMAPI->GetServerFactory(false)("VSERVERTOOLS003", nullptr))
|
|
||||||
{
|
|
||||||
g_EntList = servertools->GetEntityList();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *addr = NULL;
|
char *addr = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -197,103 +175,108 @@ void CHalfLife2::InitLogicalEntData()
|
|||||||
* If symbols aren't present (Windows or stripped Linux/Mac),
|
* If symbols aren't present (Windows or stripped Linux/Mac),
|
||||||
* attempt find via LevelShutdown + offset
|
* attempt find via LevelShutdown + offset
|
||||||
*/
|
*/
|
||||||
if (!g_EntList)
|
if (g_pGameConf->GetMemSig("gEntList", (void **)&addr))
|
||||||
{
|
{
|
||||||
if (g_pGameConf->GetMemSig("gEntList", (void **) &addr))
|
#if !defined PLATFORM_WINDOWS
|
||||||
|
if (!addr)
|
||||||
{
|
{
|
||||||
#if !defined PLATFORM_WINDOWS
|
// Key exists so notify if lookup fails, but try other method.
|
||||||
if (!addr)
|
g_Logger.LogError("Failed lookup of gEntList directly - Reverting to lookup via LevelShutdown");
|
||||||
{
|
|
||||||
// Key exists so notify if lookup fails, but try other method.
|
|
||||||
logger->LogError("Failed lookup of gEntList directly - Reverting to lookup via LevelShutdown");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
g_EntList = reinterpret_cast<void *>(addr);
|
|
||||||
#if !defined PLATFORM_WINDOWS
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
g_EntList = reinterpret_cast<void *>(addr);
|
||||||
|
#if !defined PLATFORM_WINDOWS
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!g_EntList)
|
if (!g_EntList)
|
||||||
{
|
{
|
||||||
if (g_pGameConf->GetMemSig("LevelShutdown", (void **) &addr) && addr)
|
if (!g_pGameConf->GetMemSig("LevelShutdown", (void **)&addr))
|
||||||
{
|
{
|
||||||
int offset;
|
g_Logger.LogError("Logical Entities not supported by this mod (LevelShutdown) - Reverting to networkable entities only");
|
||||||
if (!g_pGameConf->GetOffset("gEntList", &offset))
|
return;
|
||||||
{
|
|
||||||
logger->LogError("Logical Entities not supported by this mod (gEntList) - Reverting to networkable entities only");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef PLATFORM_X86
|
|
||||||
g_EntList = *reinterpret_cast<void **>(addr + offset);
|
|
||||||
#elif defined PLATFORM_X64
|
|
||||||
int32_t varOffset = *reinterpret_cast<int32_t *>(addr + offset);
|
|
||||||
g_EntList = reinterpret_cast<void *>(addr + offset + sizeof(int32_t) + varOffset);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If we have g_EntList from either of the above methods, make sure we can get the offset from it to EntInfo as well
|
if (!addr)
|
||||||
if (g_EntList && !g_pGameConf->GetOffset("EntInfo", &entInfoOffset))
|
{
|
||||||
|
g_Logger.LogError("Failed lookup of LevelShutdown - Reverting to networkable entities only");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int offset;
|
||||||
|
if (!g_pGameConf->GetOffset("gEntList", &offset))
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Logical Entities not supported by this mod (gEntList) - Reverting to networkable entities only");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_EntList = *reinterpret_cast<void **>(addr + offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_EntList)
|
||||||
{
|
{
|
||||||
logger->LogError("Logical Entities not supported by this mod (EntInfo) - Reverting to networkable entities only");
|
g_Logger.LogError("Failed lookup of gEntList - Reverting to networkable entities only");
|
||||||
g_EntList = NULL;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't have g_EntList or have it but don't know where EntInfo is on it, use fallback.
|
if (!g_pGameConf->GetOffset("EntInfo", &entInfoOffset))
|
||||||
if (!g_EntList || entInfoOffset == -1)
|
|
||||||
{
|
{
|
||||||
g_pGameConf->GetAddress("EntInfosPtr", (void **)&g_pEntInfoList);
|
g_Logger.LogError("Logical Entities not supported by this mod (EntInfo) - Reverting to networkable entities only");
|
||||||
}
|
|
||||||
|
|
||||||
if (!g_EntList && !g_pEntInfoList)
|
|
||||||
{
|
|
||||||
logger->LogError("Failed lookup of gEntList - Reverting to networkable entities only");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHalfLife2::InitCommandLine()
|
void CHalfLife2::InitCommandLine()
|
||||||
{
|
{
|
||||||
|
char path[PLATFORM_MAX_PATH];
|
||||||
char error[256];
|
char error[256];
|
||||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
|
||||||
if (g_SMAPI->GetSourceEngineBuild() != SOURCE_ENGINE_ORIGINAL)
|
|
||||||
{
|
|
||||||
ke::RefPtr<ke::SharedLib> lib = ke::SharedLib::Open(TIER0_NAME, error, sizeof(error));
|
|
||||||
if (!lib) {
|
|
||||||
logger->LogError("Could not load %s: %s", TIER0_NAME, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_pGetCommandLine = lib->get<decltype(m_pGetCommandLine)>("CommandLine_Tier0");
|
|
||||||
|
|
||||||
/* '_Tier0' dropped on Alien Swarm version */
|
|
||||||
if (m_pGetCommandLine == NULL)
|
|
||||||
{
|
|
||||||
m_pGetCommandLine = lib->get<decltype(m_pGetCommandLine)>("CommandLine");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
ke::RefPtr<ke::SharedLib> lib = ke::SharedLib::Open(VSTDLIB_NAME, error, sizeof(error));
|
|
||||||
if (!lib) {
|
|
||||||
logger->LogError("Could not load %s: %s", VSTDLIB_NAME, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_pGetCommandLine = lib->get<decltype(m_pGetCommandLine)>("CommandLine");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_pGetCommandLine == NULL)
|
g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "../bin/" TIER0_NAME);
|
||||||
|
|
||||||
|
if (!g_LibSys.IsPathFile(path))
|
||||||
{
|
{
|
||||||
logger->LogError("Could not locate any command line functionality");
|
g_Logger.LogError("Could not find path for: " TIER0_NAME);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ILibrary *lib = g_LibSys.OpenLibrary(path, error, sizeof(error));
|
||||||
|
m_pGetCommandLine = lib->GetSymbolAddress("CommandLine_Tier0");
|
||||||
|
|
||||||
|
/* '_Tier0' dropped on Alien Swarm version */
|
||||||
|
if (m_pGetCommandLine == NULL)
|
||||||
|
{
|
||||||
|
m_pGetCommandLine = lib->GetSymbolAddress("CommandLine");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_pGetCommandLine == NULL)
|
||||||
|
{
|
||||||
|
/* We probably have a Ship engine. */
|
||||||
|
lib->CloseLibrary();
|
||||||
|
g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "../bin/" VSTDLIB_NAME);
|
||||||
|
if (!g_LibSys.IsPathFile(path))
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Could not find path for: " VSTDLIB_NAME);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((lib = g_LibSys.OpenLibrary(path, error, sizeof(error))) == NULL)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Could not load %s: %s", path, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pGetCommandLine = lib->GetSymbolAddress("CommandLine");
|
||||||
|
|
||||||
|
if (m_pGetCommandLine == NULL)
|
||||||
|
{
|
||||||
|
g_Logger.LogError("Could not locate any command line functionality");
|
||||||
|
}
|
||||||
|
|
||||||
|
lib->CloseLibrary();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,6 +288,13 @@ ICommandLine *CHalfLife2::GetValveCommandLine()
|
|||||||
return ((FakeGetCommandLine)((FakeGetCommandLine *)m_pGetCommandLine))();
|
return ((FakeGetCommandLine)((FakeGetCommandLine *)m_pGetCommandLine))();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined METAMOD_PLAPI_VERSION || PLAPI_VERSION < 11
|
||||||
|
bool CHalfLife2::IsOriginalEngine()
|
||||||
|
{
|
||||||
|
return is_original_engine;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||||
IChangeInfoAccessor *CBaseEdict::GetChangeAccessor()
|
IChangeInfoAccessor *CBaseEdict::GetChangeAccessor()
|
||||||
{
|
{
|
||||||
@@ -347,11 +337,16 @@ bool UTIL_FindInSendTable(SendTable *pTable,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UTIL_FindDataMapInfo(datamap_t *pMap, const char *name, sm_datatable_info_t *pDataTable)
|
typedescription_t *UTIL_FindInDataMap(datamap_t *pMap, const char *name, bool *isNested)
|
||||||
{
|
{
|
||||||
|
if (isNested)
|
||||||
|
{
|
||||||
|
*isNested = false;
|
||||||
|
}
|
||||||
|
|
||||||
while (pMap)
|
while (pMap)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < pMap->dataNumFields; ++i)
|
for (int i=0; i<pMap->dataNumFields; i++)
|
||||||
{
|
{
|
||||||
if (pMap->dataDesc[i].fieldName == NULL)
|
if (pMap->dataDesc[i].fieldName == NULL)
|
||||||
{
|
{
|
||||||
@@ -359,23 +354,32 @@ bool UTIL_FindDataMapInfo(datamap_t *pMap, const char *name, sm_datatable_info_t
|
|||||||
}
|
}
|
||||||
if (strcmp(name, pMap->dataDesc[i].fieldName) == 0)
|
if (strcmp(name, pMap->dataDesc[i].fieldName) == 0)
|
||||||
{
|
{
|
||||||
pDataTable->prop = &(pMap->dataDesc[i]);
|
return &(pMap->dataDesc[i]);
|
||||||
pDataTable->actual_offset = GetTypeDescOffs(pDataTable->prop);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (pMap->dataDesc[i].td == NULL || !UTIL_FindDataMapInfo(pMap->dataDesc[i].td, name, pDataTable))
|
if (pMap->dataDesc[i].td)
|
||||||
{
|
{
|
||||||
continue;
|
if (isNested)
|
||||||
|
{
|
||||||
|
*isNested = (UTIL_FindInDataMap(pMap->dataDesc[i].td, name, NULL) != NULL);
|
||||||
|
if (*isNested)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else { // Use the old behaviour, we dont want to spring this on extensions - even if they're doing bad things.
|
||||||
|
typedescription_t *_td;
|
||||||
|
if ((_td=UTIL_FindInDataMap(pMap->dataDesc[i].td, name, NULL)) != NULL)
|
||||||
|
{
|
||||||
|
return _td;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pDataTable->actual_offset += GetTypeDescOffs(&(pMap->dataDesc[i]));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pMap = pMap->baseMap;
|
pMap = pMap->baseMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerClass *CHalfLife2::FindServerClass(const char *classname)
|
ServerClass *CHalfLife2::FindServerClass(const char *classname)
|
||||||
@@ -383,7 +387,9 @@ ServerClass *CHalfLife2::FindServerClass(const char *classname)
|
|||||||
DataTableInfo *pInfo = _FindServerClass(classname);
|
DataTableInfo *pInfo = _FindServerClass(classname);
|
||||||
|
|
||||||
if (!pInfo)
|
if (!pInfo)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return pInfo->sc;
|
return pInfo->sc;
|
||||||
}
|
}
|
||||||
@@ -391,21 +397,26 @@ ServerClass *CHalfLife2::FindServerClass(const char *classname)
|
|||||||
DataTableInfo *CHalfLife2::_FindServerClass(const char *classname)
|
DataTableInfo *CHalfLife2::_FindServerClass(const char *classname)
|
||||||
{
|
{
|
||||||
DataTableInfo *pInfo = NULL;
|
DataTableInfo *pInfo = NULL;
|
||||||
if (!m_Classes.retrieve(classname, &pInfo))
|
|
||||||
|
if (!sm_trie_retrieve(m_pClasses, classname, (void **)&pInfo))
|
||||||
{
|
{
|
||||||
ServerClass *sc = gamedll->GetAllServerClasses();
|
ServerClass *sc = gamedll->GetAllServerClasses();
|
||||||
while (sc)
|
while (sc)
|
||||||
{
|
{
|
||||||
if (strcmp(classname, sc->GetName()) == 0)
|
if (strcmp(classname, sc->GetName()) == 0)
|
||||||
{
|
{
|
||||||
pInfo = new DataTableInfo(sc);
|
pInfo = new DataTableInfo;
|
||||||
m_Classes.insert(classname, pInfo);
|
pInfo->sc = sc;
|
||||||
|
sm_trie_insert(m_pClasses, classname, pInfo);
|
||||||
|
m_Tables.push_back(pInfo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sc = sc->m_pNext;
|
sc = sc->m_pNext;
|
||||||
}
|
}
|
||||||
if (!pInfo)
|
if (!pInfo)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pInfo;
|
return pInfo;
|
||||||
@@ -414,13 +425,14 @@ DataTableInfo *CHalfLife2::_FindServerClass(const char *classname)
|
|||||||
bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info)
|
bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info)
|
||||||
{
|
{
|
||||||
DataTableInfo *pInfo;
|
DataTableInfo *pInfo;
|
||||||
|
sm_sendprop_info_t *prop;
|
||||||
|
|
||||||
if ((pInfo = _FindServerClass(classname)) == NULL)
|
if ((pInfo = _FindServerClass(classname)) == NULL)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pInfo->lookup.retrieve(offset, info))
|
if ((prop = pInfo->lookup.retrieve(offset)) == NULL)
|
||||||
{
|
{
|
||||||
sm_sendprop_info_t temp_info;
|
sm_sendprop_info_t temp_info;
|
||||||
|
|
||||||
@@ -432,6 +444,10 @@ bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_
|
|||||||
pInfo->lookup.insert(offset, temp_info);
|
pInfo->lookup.insert(offset, temp_info);
|
||||||
*info = temp_info;
|
*info = temp_info;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*info = *prop;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -450,32 +466,27 @@ SendProp *CHalfLife2::FindInSendTable(const char *classname, const char *offset)
|
|||||||
|
|
||||||
typedescription_t *CHalfLife2::FindInDataMap(datamap_t *pMap, const char *offset)
|
typedescription_t *CHalfLife2::FindInDataMap(datamap_t *pMap, const char *offset)
|
||||||
{
|
{
|
||||||
sm_datatable_info_t dt_info;
|
return this->FindInDataMap(pMap, offset, NULL);
|
||||||
|
|
||||||
if (!(this->FindDataMapInfo(pMap, offset, &dt_info)))
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dt_info.prop;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CHalfLife2::FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatable_info_t *pDataTable)
|
typedescription_t *CHalfLife2::FindInDataMap(datamap_t *pMap, const char *offset, bool *isNested)
|
||||||
{
|
{
|
||||||
DataTableMap::Insert i = m_Maps.findForAdd(pMap);
|
typedescription_t *td = NULL;
|
||||||
if (!i.found())
|
DataMapTrie &val = m_Maps[pMap];
|
||||||
m_Maps.add(i, pMap, new DataMapCache());
|
|
||||||
|
|
||||||
DataMapCache *cache = i->value;
|
if (!val.trie)
|
||||||
|
|
||||||
if (!cache->retrieve(offset, pDataTable))
|
|
||||||
{
|
{
|
||||||
if (!UTIL_FindDataMapInfo(pMap, offset, pDataTable))
|
val.trie = sm_trie_create();
|
||||||
return false;
|
}
|
||||||
cache->insert(offset, *pDataTable);
|
if (!sm_trie_retrieve(val.trie, offset, (void **)&td))
|
||||||
|
{
|
||||||
|
if ((td = UTIL_FindInDataMap(pMap, offset, isNested)) != NULL)
|
||||||
|
{
|
||||||
|
sm_trie_insert(val.trie, offset, td);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return td;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset)
|
void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset)
|
||||||
@@ -501,7 +512,7 @@ void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset)
|
|||||||
|
|
||||||
bool CHalfLife2::TextMsg(int client, int dest, const char *msg)
|
bool CHalfLife2::TextMsg(int client, int dest, const char *msg)
|
||||||
{
|
{
|
||||||
#ifndef USE_PROTOBUF_USERMESSAGES
|
#if SOURCE_ENGINE != SE_CSGO
|
||||||
bf_write *pBitBuf = NULL;
|
bf_write *pBitBuf = NULL;
|
||||||
#endif
|
#endif
|
||||||
cell_t players[] = {client};
|
cell_t players[] = {client};
|
||||||
@@ -513,8 +524,8 @@ bool CHalfLife2::TextMsg(int client, int dest, const char *msg)
|
|||||||
/* Use SayText user message instead */
|
/* Use SayText user message instead */
|
||||||
if (chat_saytext != NULL && strcmp(chat_saytext, "yes") == 0)
|
if (chat_saytext != NULL && strcmp(chat_saytext, "yes") == 0)
|
||||||
{
|
{
|
||||||
char buffer[253];
|
char buffer[192];
|
||||||
ke::SafeSprintf(buffer, sizeof(buffer), "%s\1\n", msg);
|
UTIL_Format(buffer, sizeof(buffer), "%s\1\n", msg);
|
||||||
|
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
#if SOURCE_ENGINE == SE_CSGO
|
||||||
CCSUsrMsg_SayText *pMsg;
|
CCSUsrMsg_SayText *pMsg;
|
||||||
@@ -565,10 +576,6 @@ bool CHalfLife2::TextMsg(int client, int dest, const char *msg)
|
|||||||
|
|
||||||
pBitBuf->WriteByte(dest);
|
pBitBuf->WriteByte(dest);
|
||||||
pBitBuf->WriteString(msg);
|
pBitBuf->WriteString(msg);
|
||||||
pBitBuf->WriteString("");
|
|
||||||
pBitBuf->WriteString("");
|
|
||||||
pBitBuf->WriteString("");
|
|
||||||
pBitBuf->WriteString("");
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_UserMsgs.EndMessage();
|
g_UserMsgs.EndMessage();
|
||||||
@@ -730,7 +737,6 @@ void CHalfLife2::ProcessFakeCliCmdQueue()
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_CmdQueue.pop();
|
m_CmdQueue.pop();
|
||||||
m_FreeCmds.push(pFake);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -748,7 +754,11 @@ bool CHalfLife2::IsLANServer()
|
|||||||
|
|
||||||
bool CHalfLife2::KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID)
|
bool CHalfLife2::KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID)
|
||||||
{
|
{
|
||||||
|
#if defined METAMOD_PLAPI_VERSION || PLAPI_VERSION >= 11
|
||||||
if (g_SMAPI->GetSourceEngineBuild() == SOURCE_ENGINE_ORIGINAL)
|
if (g_SMAPI->GetSourceEngineBuild() == SOURCE_ENGINE_ORIGINAL)
|
||||||
|
#else
|
||||||
|
if (strcasecmp(g_SourceMod.GetGameFolderName(), "ship") == 0)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
Assert(filesystem);
|
Assert(filesystem);
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@@ -783,19 +793,19 @@ bool CHalfLife2::KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHalfLife2::PushCommandStack(const ICommandArgs *cmd)
|
void CHalfLife2::PushCommandStack(const CCommand *cmd)
|
||||||
{
|
{
|
||||||
CachedCommandInfo info;
|
CachedCommandInfo info;
|
||||||
|
|
||||||
info.args = cmd;
|
info.args = cmd;
|
||||||
#if SOURCE_ENGINE <= SE_DARKMESSIAH
|
#if SOURCE_ENGINE <= SE_DARKMESSIAH
|
||||||
ke::SafeStrcpy(info.cmd, sizeof(info.cmd), cmd->Arg(0));
|
strncopy(info.cmd, cmd->Arg(0), sizeof(info.cmd));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_CommandStack.push(info);
|
m_CommandStack.push(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ICommandArgs *CHalfLife2::PeekCommandStack()
|
const CCommand *CHalfLife2::PeekCommandStack()
|
||||||
{
|
{
|
||||||
if (m_CommandStack.empty())
|
if (m_CommandStack.empty())
|
||||||
{
|
{
|
||||||
@@ -833,7 +843,7 @@ void CHalfLife2::AddDelayedKick(int client, int userid, const char *msg)
|
|||||||
|
|
||||||
kick.client = client;
|
kick.client = client;
|
||||||
kick.userid = userid;
|
kick.userid = userid;
|
||||||
ke::SafeStrcpy(kick.buffer, sizeof(kick.buffer), msg);
|
UTIL_Format(kick.buffer, sizeof(kick.buffer), "%s", msg);
|
||||||
|
|
||||||
m_DelayedKicks.push(kick);
|
m_DelayedKicks.push(kick);
|
||||||
}
|
}
|
||||||
@@ -983,9 +993,7 @@ CEntInfo *CHalfLife2::LookupEntity(int entIndex)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CEntInfo *entInfos = EntInfoArray();
|
if (!g_EntList || entInfoOffset == -1)
|
||||||
|
|
||||||
if (!entInfos)
|
|
||||||
{
|
{
|
||||||
/* Attempt to use engine interface instead */
|
/* Attempt to use engine interface instead */
|
||||||
static CEntInfo tempInfo;
|
static CEntInfo tempInfo;
|
||||||
@@ -1012,7 +1020,8 @@ CEntInfo *CHalfLife2::LookupEntity(int entIndex)
|
|||||||
return &tempInfo;
|
return &tempInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
return &entInfos[entIndex];
|
CEntInfo *pArray = (CEntInfo *)(((unsigned char *)g_EntList) + entInfoOffset);
|
||||||
|
return &pArray[entIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1144,281 +1153,54 @@ const char *CHalfLife2::GetEntityClassname(CBaseEntity *pEntity)
|
|||||||
static int offset = -1;
|
static int offset = -1;
|
||||||
if (offset == -1)
|
if (offset == -1)
|
||||||
{
|
{
|
||||||
CBaseEntity *pGetterEnt = ReferenceToEntity(0);
|
datamap_t *pMap = GetDataMap(pEntity);
|
||||||
if (pGetterEnt == NULL)
|
typedescription_t *pDesc = FindInDataMap(pMap, "m_iClassname");
|
||||||
{
|
offset = GetTypeDescOffs(pDesc);
|
||||||
// If we don't have a world entity yet, we'll have to rely on the given entity
|
|
||||||
pGetterEnt = pEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
datamap_t *pMap = GetDataMap(pGetterEnt);
|
|
||||||
|
|
||||||
sm_datatable_info_t info;
|
|
||||||
if (!FindDataMapInfo(pMap, "m_iClassname", &info))
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = info.actual_offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return *(const char **)(((unsigned char *)pEntity) + offset);
|
return *(const char **)(((unsigned char *)pEntity) + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
SMFindMapResult CHalfLife2::FindMap(char *pMapName, size_t nMapNameMax)
|
|
||||||
{
|
|
||||||
return this->FindMap(pMapName, pMapName, nMapNameMax);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef PLATFORM_WINDOWS
|
|
||||||
bool CheckReservedFilename(const char *in, const char *reservedName)
|
|
||||||
{
|
|
||||||
size_t nameLen = strlen(reservedName);
|
|
||||||
for (size_t i = 0; i < nameLen; ++i)
|
|
||||||
{
|
|
||||||
if (reservedName[i] != tolower(in[i]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in[nameLen] == '\0' || in[nameLen] == '.')
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsWindowsReservedDeviceName(const char *pMapname)
|
|
||||||
{
|
|
||||||
static const char * const reservedDeviceNames[] = {
|
|
||||||
"con", "prn", "aux", "clock$", "nul", "com1",
|
|
||||||
"com2", "com3", "com4", "com5", "com6", "com7",
|
|
||||||
"com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4",
|
|
||||||
"lpt5", "lpt6", "lpt7", "lpt8", "lpt9"
|
|
||||||
};
|
|
||||||
|
|
||||||
size_t reservedCount = sizeof(reservedDeviceNames) / sizeof(reservedDeviceNames[0]);
|
|
||||||
for (size_t i = 0; i < reservedCount; ++i)
|
|
||||||
{
|
|
||||||
if (CheckReservedFilename(pMapname, reservedDeviceNames[i]))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#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 */
|
|
||||||
#ifdef PLATFORM_WINDOWS
|
|
||||||
if (IsWindowsReservedDeviceName(pMapName))
|
|
||||||
{
|
|
||||||
return SMFindMapResult::NotFound;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ke::SafeStrcpy(pFoundMap, nMapNameMax, pMapName);
|
|
||||||
|
|
||||||
#if SOURCE_ENGINE >= SE_LEFT4DEAD
|
#if SOURCE_ENGINE >= SE_LEFT4DEAD
|
||||||
static char mapNameTmp[PLATFORM_MAX_PATH];
|
static bool ResolveFuzzyMapName(const char *fuzzyName, char *outFullname, int size)
|
||||||
g_SourceMod.Format(mapNameTmp, sizeof(mapNameTmp), "maps%c%s.bsp", PLATFORM_SEP_CHAR, pMapName);
|
{
|
||||||
if (filesystem->FileExists(mapNameTmp, "GAME"))
|
|
||||||
{
|
|
||||||
// If this is already an exact match, don't attempt to autocomplete it further (de_dust -> de_dust2).
|
|
||||||
// ... but still check that map file is actually valid.
|
|
||||||
// We check FileExists first to avoid console message about IsMapValid with invalid map.
|
|
||||||
return engine->IsMapValid(pMapName) == 0 ? SMFindMapResult::NotFound : SMFindMapResult::Found;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ConCommand *pHelperCmd = g_pCVar->FindCommand("changelevel");
|
static ConCommand *pHelperCmd = g_pCVar->FindCommand("changelevel");
|
||||||
|
|
||||||
// This shouldn't happen.
|
|
||||||
if (!pHelperCmd || !pHelperCmd->CanAutoComplete())
|
if (!pHelperCmd || !pHelperCmd->CanAutoComplete())
|
||||||
{
|
return false;
|
||||||
return engine->IsMapValid(pMapName) == 0 ? SMFindMapResult::NotFound : SMFindMapResult::Found;
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t helperCmdLen = strlen(pHelperCmd->GetName());
|
static size_t helperCmdLen = strlen(pHelperCmd->GetName());
|
||||||
|
|
||||||
CUtlVector<CUtlString> results;
|
CUtlVector<CUtlString> results;
|
||||||
pHelperCmd->AutoCompleteSuggest(pMapName, results);
|
pHelperCmd->AutoCompleteSuggest(fuzzyName, results);
|
||||||
if (results.Count() == 0)
|
if (results.Count() == 0)
|
||||||
return SMFindMapResult::NotFound;
|
return false;
|
||||||
|
|
||||||
// Results come back as you'd see in autocomplete. (ie. "changelevel fullmapnamehere"),
|
// Results come back as you'd see in autocomplete. (ie. "changelevel fullmapnamehere"),
|
||||||
// so skip ahead to start of map path/name
|
// so skip ahead to start of map path/name
|
||||||
|
|
||||||
// Like the engine, we're only going to deal with the first match.
|
// Like the engine, we're only going to deal with the first match.
|
||||||
|
|
||||||
bool bExactMatch = Q_strcmp(pMapName, &results[0][helperCmdLen + 1]) == 0;
|
strncopy(outFullname, &results[0][helperCmdLen + 1], size);
|
||||||
if (bExactMatch)
|
|
||||||
{
|
|
||||||
return SMFindMapResult::Found;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ke::SafeStrcpy(pFoundMap, nMapNameMax, &results[0][helperCmdLen + 1]);
|
|
||||||
return SMFindMapResult::FuzzyMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
#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
|
|
||||||
static IVEngineServer *engine23 = (IVEngineServer *)(g_SMAPI->GetEngineFactory()("VEngineServer023", nullptr));
|
|
||||||
if (engine23)
|
|
||||||
{
|
|
||||||
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)));
|
|
||||||
}
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CHalfLife2::GetMapDisplayName(const char *pMapName, char *pDisplayname, size_t nMapNameMax)
|
|
||||||
{
|
|
||||||
SMFindMapResult result = FindMap(pMapName, pDisplayname, nMapNameMax);
|
|
||||||
|
|
||||||
if (result == SMFindMapResult::NotFound)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
char *pPos;
|
|
||||||
if ((pPos = strrchr(pDisplayname, '/')) != NULL || (pPos = strrchr(pDisplayname, '\\')) != NULL)
|
|
||||||
ke::SafeStrcpy(pDisplayname, nMapNameMax, &pPos[1]);
|
|
||||||
|
|
||||||
if ((pPos = strstr(pDisplayname, ".ugc")) != NULL)
|
|
||||||
pPos[0] = '\0';
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool CHalfLife2::IsMapValid(const char *map)
|
bool CHalfLife2::IsMapValid(const char *map)
|
||||||
{
|
{
|
||||||
if (!map || !map[0])
|
if (!map || !map[0])
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return FindMap(map) != SMFindMapResult::NotFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Add ep1 support for this. (No IServerTools available there)
|
bool ret = engine->IsMapValid(map);
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
#if SOURCE_ENGINE >= SE_LEFT4DEAD
|
||||||
string_t CHalfLife2::AllocPooledString(const char *pszValue)
|
if (!ret)
|
||||||
{
|
|
||||||
// This is admittedly a giant hack, but it's a relatively safe method for
|
|
||||||
// inserting a string into the game's string pool that isn't likely to break.
|
|
||||||
//
|
|
||||||
// We find the first valid ent (should always be worldspawn), save off it's
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
CBaseEntity *pEntity = ((IServerUnknown *) servertools->FirstEntity())->GetBaseEntity();
|
|
||||||
auto *pDataMap = GetDataMap(pEntity);
|
|
||||||
assert(pDataMap);
|
|
||||||
|
|
||||||
static int offset = -1;
|
|
||||||
if (offset == -1)
|
|
||||||
{
|
{
|
||||||
sm_datatable_info_t info;
|
static char szFuzzyName[PLATFORM_MAX_PATH];
|
||||||
bool found = FindDataMapInfo(pDataMap, "m_iName", &info);
|
if (ResolveFuzzyMapName(map, szFuzzyName, sizeof(szFuzzyName)))
|
||||||
assert(found);
|
|
||||||
offset = info.actual_offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
string_t *pProp = (string_t *) ((intp) pEntity + offset);
|
|
||||||
string_t backup = *pProp;
|
|
||||||
servertools->SetKeyValue(pEntity, "targetname", pszValue);
|
|
||||||
string_t newString = *pProp;
|
|
||||||
*pProp = backup;
|
|
||||||
|
|
||||||
return newString;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool CHalfLife2::GetServerSteam3Id(char *pszOut, size_t len) const
|
|
||||||
{
|
|
||||||
CSteamID sid((uint64)GetServerSteamId64());
|
|
||||||
|
|
||||||
switch (sid.GetEAccountType())
|
|
||||||
{
|
|
||||||
case k_EAccountTypeAnonGameServer:
|
|
||||||
ke::SafeSprintf(pszOut, len, "[A:%u:%u:%u]", sid.GetEUniverse(), sid.GetAccountID(), sid.GetUnAccountInstance());
|
|
||||||
break;
|
|
||||||
case k_EAccountTypeGameServer:
|
|
||||||
ke::SafeSprintf(pszOut, len, "[G:%u:%u]", sid.GetEUniverse(), sid.GetAccountID());
|
|
||||||
break;
|
|
||||||
case k_EAccountTypeInvalid:
|
|
||||||
ke::SafeSprintf(pszOut, len, "[I:%u:%u]", sid.GetEUniverse(), sid.GetAccountID());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined( PLATFORM_WINDOWS )
|
|
||||||
#define STEAM_LIB_PREFIX
|
|
||||||
#define STEAM_LIB_SUFFIX
|
|
||||||
#elif defined( PLATFORM_LINUX )
|
|
||||||
#define STEAM_LIB_PREFIX "lib"
|
|
||||||
#define STEAM_LIB_SUFFIX ".so"
|
|
||||||
#elif defined( PLATFORM_APPLE )
|
|
||||||
#define STEAM_LIB_PREFIX "lib"
|
|
||||||
#define STEAM_LIB_SUFFIX ".dylib"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint64_t CHalfLife2::GetServerSteamId64() const
|
|
||||||
{
|
|
||||||
#if SOURCE_ENGINE == SE_BLADE \
|
|
||||||
|| SOURCE_ENGINE == SE_BMS \
|
|
||||||
|| SOURCE_ENGINE == SE_CSGO \
|
|
||||||
|| SOURCE_ENGINE == SE_CSS \
|
|
||||||
|| SOURCE_ENGINE == SE_DODS \
|
|
||||||
|| SOURCE_ENGINE == SE_EYE \
|
|
||||||
|| SOURCE_ENGINE == SE_HL2DM \
|
|
||||||
|| SOURCE_ENGINE == SE_INSURGENCY \
|
|
||||||
|| SOURCE_ENGINE == SE_DOI \
|
|
||||||
|| SOURCE_ENGINE == SE_SDK2013 \
|
|
||||||
|| SOURCE_ENGINE == SE_ALIENSWARM \
|
|
||||||
|| SOURCE_ENGINE == SE_TF2
|
|
||||||
const CSteamID *sid = engine->GetGameServerSteamID();
|
|
||||||
if (sid)
|
|
||||||
{
|
|
||||||
return sid->ConvertToUint64();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
typedef uint64_t(* GetServerSteamIdFn)(void);
|
|
||||||
static GetServerSteamIdFn fn = nullptr;
|
|
||||||
if (!fn)
|
|
||||||
{
|
|
||||||
ke::SharedLib steam_api(STEAM_LIB_PREFIX "steam_api" STEAM_LIB_SUFFIX);
|
|
||||||
if (steam_api.valid())
|
|
||||||
{
|
{
|
||||||
fn = (GetServerSteamIdFn)steam_api.lookup("SteamGameServer_GetSteamID");
|
ret = engine->IsMapValid(szFuzzyName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fn)
|
|
||||||
{
|
|
||||||
return fn();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
return ret;
|
||||||
return 1ULL;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-126
@@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2016 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
@@ -35,11 +35,8 @@
|
|||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include <sh_string.h>
|
#include <sh_string.h>
|
||||||
#include <sh_tinyhash.h>
|
#include <sh_tinyhash.h>
|
||||||
#include <am-utility.h>
|
#include <sm_trie_tpl.h>
|
||||||
#include <am-hashset.h>
|
#include "sm_trie.h"
|
||||||
#include <am-hashmap.h>
|
|
||||||
#include <sm_stringhashmap.h>
|
|
||||||
#include <sm_namehashset.h>
|
|
||||||
#include "sm_globals.h"
|
#include "sm_globals.h"
|
||||||
#include "sm_queue.h"
|
#include "sm_queue.h"
|
||||||
#include <IGameHelpers.h>
|
#include <IGameHelpers.h>
|
||||||
@@ -48,11 +45,11 @@
|
|||||||
#include <datamap.h>
|
#include <datamap.h>
|
||||||
#include <ihandleentity.h>
|
#include <ihandleentity.h>
|
||||||
#include <tier0/icommandline.h>
|
#include <tier0/icommandline.h>
|
||||||
|
#if SOURCE_ENGINE >= SE_PORTAL2
|
||||||
#include <string_t.h>
|
#include <string_t.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace SourceMod {
|
class CCommand;
|
||||||
class ICommandArgs;
|
|
||||||
} // namespace SourceMod
|
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
using namespace SourceMod;
|
using namespace SourceMod;
|
||||||
@@ -60,79 +57,18 @@ using namespace SourceMod;
|
|||||||
#define HUD_PRINTTALK 3
|
#define HUD_PRINTTALK 3
|
||||||
#define HUD_PRINTCENTER 4
|
#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
|
|
||||||
#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 DataTableInfo
|
||||||
{
|
{
|
||||||
struct SendPropPolicy
|
|
||||||
{
|
|
||||||
static inline bool matches(const char *name, const sm_sendprop_info_t &info)
|
|
||||||
{
|
|
||||||
return strcmp(name, info.prop->GetName()) == 0;
|
|
||||||
}
|
|
||||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
|
||||||
{
|
|
||||||
return key.hash();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
ServerClass *sc;
|
||||||
NameHashSet<sm_sendprop_info_t, SendPropPolicy> lookup;
|
KTrie<sm_sendprop_info_t> lookup;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DataMapCachePolicy
|
struct DataMapTrie
|
||||||
{
|
{
|
||||||
static inline bool matches(const char *name, const sm_datatable_info_t &info)
|
DataMapTrie() : trie(NULL) {}
|
||||||
{
|
Trie *trie;
|
||||||
return strcmp(name, info.prop->fieldName) == 0;
|
|
||||||
}
|
|
||||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
|
||||||
{
|
|
||||||
return key.hash();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef NameHashSet<sm_datatable_info_t, DataMapCachePolicy> DataMapCache;
|
|
||||||
|
|
||||||
struct DelayedFakeCliCmd
|
struct DelayedFakeCliCmd
|
||||||
{
|
{
|
||||||
String cmd;
|
String cmd;
|
||||||
@@ -142,7 +78,7 @@ struct DelayedFakeCliCmd
|
|||||||
|
|
||||||
struct CachedCommandInfo
|
struct CachedCommandInfo
|
||||||
{
|
{
|
||||||
const ICommandArgs *args;
|
const CCommand *args;
|
||||||
#if SOURCE_ENGINE <= SE_DARKMESSIAH
|
#if SOURCE_ENGINE <= SE_DARKMESSIAH
|
||||||
char cmd[300];
|
char cmd[300];
|
||||||
#endif
|
#endif
|
||||||
@@ -169,21 +105,10 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// Corresponds to TF2's eFindMapResult in eiface.h
|
|
||||||
// Not yet in other games, but eventually in others on same branch.
|
|
||||||
enum class SMFindMapResult : cell_t {
|
|
||||||
Found,
|
|
||||||
NotFound,
|
|
||||||
FuzzyMatch,
|
|
||||||
NonCanonical,
|
|
||||||
PossiblyAvailable
|
|
||||||
};
|
|
||||||
|
|
||||||
class CHalfLife2 :
|
class CHalfLife2 :
|
||||||
public SMGlobalClass,
|
public SMGlobalClass,
|
||||||
public IGameHelpers
|
public IGameHelpers
|
||||||
{
|
{
|
||||||
friend class AutoEnterCommand;
|
|
||||||
public:
|
public:
|
||||||
CHalfLife2();
|
CHalfLife2();
|
||||||
~CHalfLife2();
|
~CHalfLife2();
|
||||||
@@ -192,15 +117,13 @@ public:
|
|||||||
void OnSourceModAllInitialized();
|
void OnSourceModAllInitialized();
|
||||||
void OnSourceModAllInitialized_Post();
|
void OnSourceModAllInitialized_Post();
|
||||||
/*void OnSourceModAllShutdown();*/
|
/*void OnSourceModAllShutdown();*/
|
||||||
ConfigResult OnSourceModConfigChanged(const char *key, const char *value,
|
|
||||||
ConfigSource source, char *error, size_t maxlength) override;
|
|
||||||
public: //IGameHelpers
|
public: //IGameHelpers
|
||||||
SendProp *FindInSendTable(const char *classname, const char *offset);
|
SendProp *FindInSendTable(const char *classname, const char *offset);
|
||||||
bool FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info);
|
bool FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info);
|
||||||
datamap_t *GetDataMap(CBaseEntity *pEntity);
|
datamap_t *GetDataMap(CBaseEntity *pEntity);
|
||||||
ServerClass *FindServerClass(const char *classname);
|
ServerClass *FindServerClass(const char *classname);
|
||||||
typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
|
typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
|
||||||
bool FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatable_info_t *pDataTable);
|
typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset, bool *isNested);
|
||||||
void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
|
void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
|
||||||
bool TextMsg(int client, int dest, const char *msg);
|
bool TextMsg(int client, int dest, const char *msg);
|
||||||
bool HintTextMsg(int client, const char *msg);
|
bool HintTextMsg(int client, const char *msg);
|
||||||
@@ -227,34 +150,28 @@ public: //IGameHelpers
|
|||||||
const char *GetEntityClassname(edict_t *pEdict);
|
const char *GetEntityClassname(edict_t *pEdict);
|
||||||
const char *GetEntityClassname(CBaseEntity *pEntity);
|
const char *GetEntityClassname(CBaseEntity *pEntity);
|
||||||
bool IsMapValid(const char *map);
|
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);
|
|
||||||
#endif
|
|
||||||
bool GetServerSteam3Id(char *pszOut, size_t len) const override;
|
|
||||||
uint64_t GetServerSteamId64() const override;
|
|
||||||
public:
|
public:
|
||||||
void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
|
void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
|
||||||
void ProcessFakeCliCmdQueue();
|
void ProcessFakeCliCmdQueue();
|
||||||
public:
|
public:
|
||||||
const ICommandArgs *PeekCommandStack();
|
void PushCommandStack(const CCommand *cmd);
|
||||||
|
void PopCommandStack();
|
||||||
|
const CCommand *PeekCommandStack();
|
||||||
const char *CurrentCommandName();
|
const char *CurrentCommandName();
|
||||||
void AddDelayedKick(int client, int userid, const char *msg);
|
void AddDelayedKick(int client, int userid, const char *msg);
|
||||||
void ProcessDelayedKicks();
|
void ProcessDelayedKicks();
|
||||||
|
#if !defined METAMOD_PLAPI_VERSION || PLAPI_VERSION < 11
|
||||||
|
bool IsOriginalEngine();
|
||||||
|
#endif
|
||||||
private:
|
private:
|
||||||
void PushCommandStack(const ICommandArgs *cmd);
|
|
||||||
void PopCommandStack();
|
|
||||||
DataTableInfo *_FindServerClass(const char *classname);
|
DataTableInfo *_FindServerClass(const char *classname);
|
||||||
private:
|
private:
|
||||||
void InitLogicalEntData();
|
void InitLogicalEntData();
|
||||||
void InitCommandLine();
|
void InitCommandLine();
|
||||||
private:
|
private:
|
||||||
typedef ke::HashMap<datamap_t *, DataMapCache *, ke::PointerPolicy<datamap_t> > DataTableMap;
|
Trie *m_pClasses;
|
||||||
|
List<DataTableInfo *> m_Tables;
|
||||||
NameHashSet<DataTableInfo *> m_Classes;
|
THash<datamap_t *, DataMapTrie> m_Maps;
|
||||||
DataTableMap m_Maps;
|
|
||||||
int m_MsgTextMsg;
|
int m_MsgTextMsg;
|
||||||
int m_HinTextMsg;
|
int m_HinTextMsg;
|
||||||
int m_SayTextMsg;
|
int m_SayTextMsg;
|
||||||
@@ -264,31 +181,10 @@ private:
|
|||||||
CStack<CachedCommandInfo> m_CommandStack;
|
CStack<CachedCommandInfo> m_CommandStack;
|
||||||
Queue<DelayedKickInfo> m_DelayedKicks;
|
Queue<DelayedKickInfo> m_DelayedKicks;
|
||||||
void *m_pGetCommandLine;
|
void *m_pGetCommandLine;
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
|
||||||
public:
|
|
||||||
bool CanSetCSGOEntProp(const char *pszPropName)
|
|
||||||
{
|
|
||||||
return !m_bFollowCSGOServerGuidelines || !m_CSGOBadList.has(pszPropName);
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
ke::HashSet<ke::AString, detail::StringHashMapPolicy> m_CSGOBadList;
|
|
||||||
bool m_bFollowCSGOServerGuidelines = true;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CHalfLife2 g_HL2;
|
extern CHalfLife2 g_HL2;
|
||||||
|
|
||||||
bool IndexToAThings(cell_t, CBaseEntity **pEntData, edict_t **pEdictData);
|
bool IndexToAThings(cell_t, CBaseEntity **pEntData, edict_t **pEdictData);
|
||||||
|
|
||||||
class AutoEnterCommand
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AutoEnterCommand(const ICommandArgs *args) {
|
|
||||||
g_HL2.PushCommandStack(args);
|
|
||||||
}
|
|
||||||
~AutoEnterCommand() {
|
|
||||||
g_HL2.PopCommandStack();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //_INCLUDE_SOURCEMOD_CHALFLIFE2_H_
|
#endif //_INCLUDE_SOURCEMOD_CHALFLIFE2_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -30,14 +30,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "HandleSys.h"
|
#include "HandleSys.h"
|
||||||
|
#include "ShareSys.h"
|
||||||
|
#include "PluginSys.h"
|
||||||
|
#include "ExtensionSys.h"
|
||||||
|
#include "Logger.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "common_logic.h"
|
#include "sm_stringutil.h"
|
||||||
#include "ShareSys.h"
|
|
||||||
#include "ExtensionSys.h"
|
|
||||||
#include "PluginSys.h"
|
|
||||||
#include <am-string.h>
|
|
||||||
#include <bridge/include/ILogger.h>
|
|
||||||
|
|
||||||
HandleSystem g_HandleSys;
|
HandleSystem g_HandleSys;
|
||||||
|
|
||||||
@@ -61,6 +60,9 @@ HandleSystem::HandleSystem()
|
|||||||
m_Types = new QHandleType[HANDLESYS_TYPEARRAY_SIZE];
|
m_Types = new QHandleType[HANDLESYS_TYPEARRAY_SIZE];
|
||||||
memset(m_Types, 0, sizeof(QHandleType) * HANDLESYS_TYPEARRAY_SIZE);
|
memset(m_Types, 0, sizeof(QHandleType) * HANDLESYS_TYPEARRAY_SIZE);
|
||||||
|
|
||||||
|
m_TypeLookup = sm_trie_create();
|
||||||
|
m_strtab = new BaseStringTable(512);
|
||||||
|
|
||||||
m_TypeTail = 0;
|
m_TypeTail = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +70,8 @@ HandleSystem::~HandleSystem()
|
|||||||
{
|
{
|
||||||
delete [] m_Handles;
|
delete [] m_Handles;
|
||||||
delete [] m_Types;
|
delete [] m_Types;
|
||||||
|
sm_trie_destroy(m_TypeLookup);
|
||||||
|
delete m_strtab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -141,10 +145,12 @@ HandleType_t HandleSystem::CreateType(const char *name,
|
|||||||
|
|
||||||
if (name && name[0] != '\0')
|
if (name && name[0] != '\0')
|
||||||
{
|
{
|
||||||
if (m_TypeLookup.contains(name))
|
if (sm_trie_retrieve(m_TypeLookup, name, NULL))
|
||||||
{
|
{
|
||||||
if (err)
|
if (err)
|
||||||
|
{
|
||||||
*err = HandleError_Parameter;
|
*err = HandleError_Parameter;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,8 +212,10 @@ HandleType_t HandleSystem::CreateType(const char *name,
|
|||||||
pType->dispatch = dispatch;
|
pType->dispatch = dispatch;
|
||||||
if (name && name[0] != '\0')
|
if (name && name[0] != '\0')
|
||||||
{
|
{
|
||||||
pType->name = new ke::AString(name);
|
pType->nameIdx = m_strtab->AddString(name);
|
||||||
m_TypeLookup.insert(name, pType);
|
sm_trie_insert(m_TypeLookup, name, (void *)pType);
|
||||||
|
} else {
|
||||||
|
pType->nameIdx = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pType->opened = 0;
|
pType->opened = 0;
|
||||||
@@ -235,14 +243,21 @@ HandleType_t HandleSystem::CreateType(const char *name,
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HandleSystem::FindHandleType(const char *name, HandleType_t *aResult)
|
bool HandleSystem::FindHandleType(const char *name, HandleType_t *type)
|
||||||
{
|
{
|
||||||
QHandleType *type;
|
QHandleType *_type;
|
||||||
if (!m_TypeLookup.retrieve(name, &type))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (aResult)
|
if (!sm_trie_retrieve(m_TypeLookup, name, (void **)&_type))
|
||||||
*aResult = type - m_Types;
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int offset = _type - m_Types;
|
||||||
|
|
||||||
|
if (type)
|
||||||
|
{
|
||||||
|
*type = offset;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -645,13 +660,13 @@ void HandleSystem::GetHandleUnchecked(Handle_t hndl, QHandle *& pHandle, unsigne
|
|||||||
|
|
||||||
HandleError HandleSystem::FreeHandle(QHandle *pHandle, unsigned int index)
|
HandleError HandleSystem::FreeHandle(QHandle *pHandle, unsigned int index)
|
||||||
{
|
{
|
||||||
if (pHandle->is_destroying)
|
if (pHandle->is_destroying)
|
||||||
{
|
{
|
||||||
/* Someone tried to free this recursively.
|
/* Someone tried to free this recursively.
|
||||||
* We'll just ignore this safely.
|
* We'll just ignore this safely.
|
||||||
*/
|
*/
|
||||||
return HandleError_None;
|
return HandleError_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHandleType *pType = &m_Types[pHandle->type];
|
QHandleType *pType = &m_Types[pHandle->type];
|
||||||
|
|
||||||
@@ -676,9 +691,9 @@ HandleError HandleSystem::FreeHandle(QHandle *pHandle, unsigned int index)
|
|||||||
/* Type should be the same but do this anyway... */
|
/* Type should be the same but do this anyway... */
|
||||||
pType = &m_Types[pMaster->type];
|
pType = &m_Types[pMaster->type];
|
||||||
pMaster->is_destroying = true;
|
pMaster->is_destroying = true;
|
||||||
if (pMaster->object)
|
if (pMaster->object)
|
||||||
{
|
{
|
||||||
pType->dispatch->OnHandleDestroy(pMaster->type, pMaster->object);
|
pType->dispatch->OnHandleDestroy(pMaster->type, pMaster->object);
|
||||||
}
|
}
|
||||||
ReleasePrimHandle(master);
|
ReleasePrimHandle(master);
|
||||||
}
|
}
|
||||||
@@ -693,9 +708,9 @@ HandleError HandleSystem::FreeHandle(QHandle *pHandle, unsigned int index)
|
|||||||
if (--pHandle->refcount == 0)
|
if (--pHandle->refcount == 0)
|
||||||
{
|
{
|
||||||
pHandle->is_destroying = true;
|
pHandle->is_destroying = true;
|
||||||
if (pHandle->object)
|
if (pHandle->object)
|
||||||
{
|
{
|
||||||
pType->dispatch->OnHandleDestroy(pHandle->type, pHandle->object);
|
pType->dispatch->OnHandleDestroy(pHandle->type, pHandle->object);
|
||||||
}
|
}
|
||||||
ReleasePrimHandle(index);
|
ReleasePrimHandle(index);
|
||||||
} else {
|
} else {
|
||||||
@@ -899,6 +914,10 @@ bool HandleSystem::RemoveType(HandleType_t type, IdentityToken_t *ident)
|
|||||||
m_Types[++m_FreeTypes].freeID = type;
|
m_Types[++m_FreeTypes].freeID = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Invalidate the type now */
|
||||||
|
IHandleTypeDispatch *dispatch = pType->dispatch;
|
||||||
|
pType->dispatch = NULL;
|
||||||
|
|
||||||
/* Make sure nothing is using this type. */
|
/* Make sure nothing is using this type. */
|
||||||
if (pType->opened)
|
if (pType->opened)
|
||||||
{
|
{
|
||||||
@@ -920,12 +939,14 @@ bool HandleSystem::RemoveType(HandleType_t type, IdentityToken_t *ident)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Invalidate the type now */
|
|
||||||
pType->dispatch = NULL;
|
|
||||||
|
|
||||||
/* Remove it from the type cache. */
|
/* Remove it from the type cache. */
|
||||||
if (pType->name)
|
if (pType->nameIdx != -1)
|
||||||
m_TypeLookup.remove(pType->name->chars());
|
{
|
||||||
|
const char *typeName;
|
||||||
|
|
||||||
|
typeName = m_strtab->GetString(pType->nameIdx);
|
||||||
|
sm_trie_delete(m_TypeLookup, typeName);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -959,8 +980,8 @@ bool HandleSystem::InitAccessDefaults(TypeAccess *pTypeAccess, HandleAccess *pHa
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define HANDLE_LOG_VERY_BAD(message, ...) \
|
#define HANDLE_LOG_VERY_BAD(message, ...) \
|
||||||
logger->LogFatal(message, ##__VA_ARGS__); \
|
g_Logger.LogFatal(message, ##__VA_ARGS__); \
|
||||||
logger->LogError(message, ##__VA_ARGS__);
|
g_Logger.LogError(message, ##__VA_ARGS__);
|
||||||
|
|
||||||
bool HandleSystem::TryAndFreeSomeHandles()
|
bool HandleSystem::TryAndFreeSomeHandles()
|
||||||
{
|
{
|
||||||
@@ -1007,82 +1028,17 @@ bool HandleSystem::TryAndFreeSomeHandles()
|
|||||||
HANDLE_LOG_VERY_BAD("[SM] MEMORY LEAK DETECTED IN PLUGIN (file \"%s\")", highest_owner->GetFilename());
|
HANDLE_LOG_VERY_BAD("[SM] MEMORY LEAK DETECTED IN PLUGIN (file \"%s\")", highest_owner->GetFilename());
|
||||||
HANDLE_LOG_VERY_BAD("[SM] Unloading plugin to free %d handles.", highest_handle_count);
|
HANDLE_LOG_VERY_BAD("[SM] Unloading plugin to free %d handles.", highest_handle_count);
|
||||||
HANDLE_LOG_VERY_BAD("[SM] Contact the author(s) of this plugin to correct this error.", highest_handle_count);
|
HANDLE_LOG_VERY_BAD("[SM] Contact the author(s) of this plugin to correct this error.", highest_handle_count);
|
||||||
HANDLE_LOG_VERY_BAD("--------------------------------------------------------------------------");
|
|
||||||
|
|
||||||
const IdentityToken_t *pIdentity = highest_owner->GetIdentity();
|
|
||||||
unsigned int total = 0, highest_index = 0, total_size = 0, size;
|
|
||||||
unsigned int * pCount = new unsigned int[HANDLESYS_TYPEARRAY_SIZE+1];
|
|
||||||
memset(pCount, 0, ((HANDLESYS_TYPEARRAY_SIZE + 1) * sizeof(unsigned int)));
|
|
||||||
|
|
||||||
for (unsigned int i = 1; i <= m_HandleTail; ++i)
|
|
||||||
{
|
|
||||||
const QHandle &Handle = m_Handles[i];
|
|
||||||
if (Handle.set != HandleSet_Used || Handle.owner != pIdentity)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
++pCount[Handle.type];
|
|
||||||
++total;
|
|
||||||
|
|
||||||
if (Handle.type >= highest_index)
|
|
||||||
{
|
|
||||||
highest_index = ((Handle.type) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Handle.clone != 0)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_Types[Handle.type].dispatch->GetHandleApproxSize(Handle.type, Handle.object, &size))
|
|
||||||
{
|
|
||||||
total_size += size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char * pTypeName = NULL;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < highest_index; ++i)
|
|
||||||
{
|
|
||||||
if (pCount[i] == 0)
|
|
||||||
{
|
|
||||||
continue; /* We may have gaps, it's fine. */
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_Types[i].name)
|
|
||||||
pTypeName = m_Types[i].name->chars();
|
|
||||||
else
|
|
||||||
pTypeName = "ANON";
|
|
||||||
|
|
||||||
HANDLE_LOG_VERY_BAD("Type\t%-20.20s|\tCount\t%u", pTypeName, pCount[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
HANDLE_LOG_VERY_BAD("-- Approximately %d bytes of memory are in use by (%u) Handles.\n", total_size, total);
|
|
||||||
delete [] pCount;
|
|
||||||
|
|
||||||
highest_owner->GetBaseContext()->ThrowNativeErrorEx(SP_ERROR_MEMACCESS, "Memory leak");
|
highest_owner->GetBaseContext()->ThrowNativeErrorEx(SP_ERROR_MEMACCESS, "Memory leak");
|
||||||
|
|
||||||
return scripts->UnloadPlugin(highest_owner);
|
return g_PluginSys.UnloadPlugin(highest_owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rep(const HandleReporter &fn, const char *fmt, ...)
|
void HandleSystem::Dump(HANDLE_REPORTER rep)
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
char buffer[1024];
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
ke::SafeVsprintf(buffer, sizeof(buffer), fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
fn(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandleSystem::Dump(const HandleReporter &fn)
|
|
||||||
{
|
{
|
||||||
unsigned int total_size = 0;
|
unsigned int total_size = 0;
|
||||||
rep(fn, "%-10.10s\t%-20.20s\t%-20.20s\t%-10.10s", "Handle", "Owner", "Type", "Memory");
|
rep("%-10.10s\t%-20.20s\t%-20.20s\t%-10.10s", "Handle", "Owner", "Type", "Memory");
|
||||||
rep(fn, "--------------------------------------------------------------------------");
|
rep("--------------------------------------------------------------------------");
|
||||||
for (unsigned int i = 1; i <= m_HandleTail; i++)
|
for (unsigned int i = 1; i <= m_HandleTail; i++)
|
||||||
{
|
{
|
||||||
if (m_Handles[i].set != HandleSet_Used)
|
if (m_Handles[i].set != HandleSet_Used)
|
||||||
@@ -1100,20 +1056,20 @@ void HandleSystem::Dump(const HandleReporter &fn)
|
|||||||
{
|
{
|
||||||
owner = "CORE";
|
owner = "CORE";
|
||||||
}
|
}
|
||||||
else if (pOwner == scripts->GetIdentity())
|
else if (pOwner == g_PluginSys.GetIdentity())
|
||||||
{
|
{
|
||||||
owner = "PLUGINSYS";
|
owner = "PLUGINSYS";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IExtension *ext = g_Extensions.GetExtensionFromIdent(pOwner);
|
CExtension *ext = g_Extensions.GetExtensionFromIdent(pOwner);
|
||||||
if (ext)
|
if (ext)
|
||||||
{
|
{
|
||||||
owner = ext->GetFilename();
|
owner = ext->GetFilename();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SMPlugin *pPlugin = scripts->FindPluginByIdentity(pOwner);
|
CPlugin *pPlugin = g_PluginSys.GetPluginFromIdentity(pOwner);
|
||||||
if (pPlugin)
|
if (pPlugin)
|
||||||
{
|
{
|
||||||
owner = pPlugin->GetFilename();
|
owner = pPlugin->GetFilename();
|
||||||
@@ -1130,39 +1086,41 @@ void HandleSystem::Dump(const HandleReporter &fn)
|
|||||||
unsigned int size = 0;
|
unsigned int size = 0;
|
||||||
unsigned int parentIdx;
|
unsigned int parentIdx;
|
||||||
bool bresult;
|
bool bresult;
|
||||||
if (pType->name)
|
if (pType->nameIdx != -1)
|
||||||
type = pType->name->chars();
|
|
||||||
|
|
||||||
if ((parentIdx = m_Handles[i].clone) != 0)
|
|
||||||
{
|
{
|
||||||
if (m_Handles[parentIdx].refcount > 0)
|
type = m_strtab->GetString(pType->nameIdx);
|
||||||
{
|
|
||||||
size = 0;
|
|
||||||
bresult = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bresult = pType->dispatch->GetHandleApproxSize(m_Handles[parentIdx].type, m_Handles[parentIdx].object, &size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if ((parentIdx = m_Handles[i].clone) != 0)
|
||||||
bresult = pType->dispatch->GetHandleApproxSize(m_Handles[i].type, m_Handles[i].object, &size);
|
{
|
||||||
|
if (m_Handles[parentIdx].refcount > 0)
|
||||||
|
{
|
||||||
|
size = 0;
|
||||||
|
bresult = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bresult = pType->dispatch->GetHandleApproxSize(m_Handles[parentIdx].type, m_Handles[parentIdx].object, &size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bresult = pType->dispatch->GetHandleApproxSize(m_Handles[i].type, m_Handles[i].object, &size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pType->dispatch->GetDispatchVersion() < HANDLESYS_MEMUSAGE_MIN_VERSION
|
if (pType->dispatch->GetDispatchVersion() < HANDLESYS_MEMUSAGE_MIN_VERSION
|
||||||
|| !bresult)
|
|| !bresult)
|
||||||
{
|
{
|
||||||
rep(fn, "0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, "-1");
|
rep("0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, "-1");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
ke::SafeSprintf(buffer, sizeof(buffer), "%d", size);
|
UTIL_Format(buffer, sizeof(buffer), "%d", size);
|
||||||
rep(fn, "0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, buffer);
|
rep("0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, buffer);
|
||||||
total_size += size;
|
total_size += size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rep(fn, "-- Approximately %d bytes of memory are in use by Handles.\n", total_size);
|
rep("-- Approximately %d bytes of memory are in use by Handles.\n", total_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -34,13 +34,12 @@
|
|||||||
|
|
||||||
#include <IHandleSys.h>
|
#include <IHandleSys.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sm_namehashset.h>
|
#include "sm_globals.h"
|
||||||
#include <amtl/am-autoptr.h>
|
#include "sm_trie.h"
|
||||||
#include <amtl/am-string.h>
|
#include "sourcemod.h"
|
||||||
#include <amtl/am-function.h>
|
#include "sm_memtable.h"
|
||||||
#include "common_logic.h"
|
|
||||||
|
|
||||||
#define HANDLESYS_MAX_HANDLES (1<<15)
|
#define HANDLESYS_MAX_HANDLES (1<<14)
|
||||||
#define HANDLESYS_MAX_TYPES (1<<9)
|
#define HANDLESYS_MAX_TYPES (1<<9)
|
||||||
#define HANDLESYS_MAX_SUBTYPES 0xF
|
#define HANDLESYS_MAX_SUBTYPES 0xF
|
||||||
#define HANDLESYS_SUBTYPE_MASK 0xF
|
#define HANDLESYS_SUBTYPE_MASK 0xF
|
||||||
@@ -105,19 +104,10 @@ struct QHandleType
|
|||||||
TypeAccess typeSec;
|
TypeAccess typeSec;
|
||||||
HandleAccess hndlSec;
|
HandleAccess hndlSec;
|
||||||
unsigned int opened;
|
unsigned int opened;
|
||||||
ke::AutoPtr<ke::AString> name;
|
int nameIdx;
|
||||||
|
|
||||||
static inline bool matches(const char *key, const QHandleType *type)
|
|
||||||
{
|
|
||||||
return type->name && type->name->compare(key) == 0;
|
|
||||||
}
|
|
||||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
|
||||||
{
|
|
||||||
return key.hash();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef ke::Lambda<void(const char *)> HandleReporter;
|
typedef void (HANDLE_REPORTER)(const char *str, ...);
|
||||||
|
|
||||||
class HandleSystem :
|
class HandleSystem :
|
||||||
public IHandleSys
|
public IHandleSys
|
||||||
@@ -169,7 +159,7 @@ public: //IHandleSystem
|
|||||||
const HandleAccess *pAccess,
|
const HandleAccess *pAccess,
|
||||||
HandleError *err);
|
HandleError *err);
|
||||||
|
|
||||||
void Dump(const HandleReporter &reporter);
|
void Dump(HANDLE_REPORTER rep);
|
||||||
|
|
||||||
/* Bypasses security checks. */
|
/* Bypasses security checks. */
|
||||||
Handle_t FastCloneHandle(Handle_t hndl);
|
Handle_t FastCloneHandle(Handle_t hndl);
|
||||||
@@ -227,12 +217,13 @@ protected:
|
|||||||
private:
|
private:
|
||||||
QHandle *m_Handles;
|
QHandle *m_Handles;
|
||||||
QHandleType *m_Types;
|
QHandleType *m_Types;
|
||||||
NameHashSet<QHandleType *> m_TypeLookup;
|
Trie *m_TypeLookup;
|
||||||
unsigned int m_TypeTail;
|
unsigned int m_TypeTail;
|
||||||
unsigned int m_FreeTypes;
|
unsigned int m_FreeTypes;
|
||||||
unsigned int m_HandleTail;
|
unsigned int m_HandleTail;
|
||||||
unsigned int m_FreeHandles;
|
unsigned int m_FreeHandles;
|
||||||
unsigned int m_HSerial;
|
unsigned int m_HSerial;
|
||||||
|
BaseStringTable *m_strtab;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern HandleSystem g_HandleSys;
|
extern HandleSystem g_HandleSys;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -34,16 +34,27 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sm_platform.h>
|
#include <sm_platform.h>
|
||||||
|
#include "sm_stringutil.h"
|
||||||
#include "LibrarySys.h"
|
#include "LibrarySys.h"
|
||||||
#include <amtl/am-string.h>
|
|
||||||
#include <amtl/os/am-path.h>
|
|
||||||
#include <amtl/os/am-fsutil.h>
|
|
||||||
|
|
||||||
LibrarySystem g_LibSys;
|
LibrarySystem g_LibSys;
|
||||||
|
|
||||||
CLibrary::CLibrary(ke::RefPtr<ke::SharedLib> lib)
|
CLibrary::~CLibrary()
|
||||||
: lib_(lib)
|
|
||||||
{
|
{
|
||||||
|
if (m_lib)
|
||||||
|
{
|
||||||
|
#if defined PLATFORM_WINDOWS
|
||||||
|
FreeLibrary(m_lib);
|
||||||
|
#elif defined PLATFORM_POSIX
|
||||||
|
dlclose(m_lib);
|
||||||
|
#endif
|
||||||
|
m_lib = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CLibrary::CLibrary(LibraryHandle me)
|
||||||
|
{
|
||||||
|
m_lib = me;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLibrary::CloseLibrary()
|
void CLibrary::CloseLibrary()
|
||||||
@@ -53,7 +64,11 @@ void CLibrary::CloseLibrary()
|
|||||||
|
|
||||||
void *CLibrary::GetSymbolAddress(const char *symname)
|
void *CLibrary::GetSymbolAddress(const char *symname)
|
||||||
{
|
{
|
||||||
return lib_->lookup(symname);
|
#if defined PLATFORM_WINDOWS
|
||||||
|
return GetProcAddress(m_lib, symname);
|
||||||
|
#elif defined PLATFORM_POSIX
|
||||||
|
return dlsym(m_lib, symname);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -66,7 +81,7 @@ CDirectory::CDirectory(const char *path)
|
|||||||
{
|
{
|
||||||
#if defined PLATFORM_WINDOWS
|
#if defined PLATFORM_WINDOWS
|
||||||
char newpath[PLATFORM_MAX_PATH];
|
char newpath[PLATFORM_MAX_PATH];
|
||||||
ke::SafeSprintf(newpath, sizeof(newpath), "%s\\*.*", path);
|
snprintf(newpath, sizeof(newpath), "%s\\*.*", path);
|
||||||
m_dir = FindFirstFileA(newpath, &m_fd);
|
m_dir = FindFirstFileA(newpath, &m_fd);
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
{
|
{
|
||||||
@@ -78,7 +93,7 @@ CDirectory::CDirectory(const char *path)
|
|||||||
{
|
{
|
||||||
/* :TODO: we need to read past "." and ".."! */
|
/* :TODO: we need to read past "." and ".."! */
|
||||||
ep = readdir(m_dir);
|
ep = readdir(m_dir);
|
||||||
ke::SafeStrcpy(m_origpath, PLATFORM_MAX_PATH, path);
|
snprintf(m_origpath, PLATFORM_MAX_PATH, "%s", path);
|
||||||
} else {
|
} else {
|
||||||
ep = NULL;
|
ep = NULL;
|
||||||
}
|
}
|
||||||
@@ -125,10 +140,8 @@ bool CDirectory::IsEntryDirectory()
|
|||||||
return ((m_fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
|
return ((m_fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
|
||||||
#elif defined PLATFORM_POSIX
|
#elif defined PLATFORM_POSIX
|
||||||
char temppath[PLATFORM_MAX_PATH];
|
char temppath[PLATFORM_MAX_PATH];
|
||||||
int ret = ke::SafeSprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName());
|
snprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName());
|
||||||
if (static_cast<size_t>(ret) >= sizeof(temppath))
|
return g_LibSys.IsPathDirectory(temppath);
|
||||||
return false;
|
|
||||||
return ke::file::IsDirectory(temppath);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,10 +151,8 @@ bool CDirectory::IsEntryFile()
|
|||||||
return !(m_fd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE));
|
return !(m_fd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE));
|
||||||
#elif defined PLATFORM_POSIX
|
#elif defined PLATFORM_POSIX
|
||||||
char temppath[PLATFORM_MAX_PATH];
|
char temppath[PLATFORM_MAX_PATH];
|
||||||
int ret = ke::SafeSprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName());
|
snprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName());
|
||||||
if (static_cast<size_t>(ret) >= sizeof(temppath))
|
return g_LibSys.IsPathFile(temppath);
|
||||||
return false;
|
|
||||||
return ke::file::IsFile(temppath);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,17 +187,75 @@ bool CDirectory::IsValid()
|
|||||||
|
|
||||||
bool LibrarySystem::PathExists(const char *path)
|
bool LibrarySystem::PathExists(const char *path)
|
||||||
{
|
{
|
||||||
return ke::file::PathExists(path);
|
#if defined PLATFORM_WINDOWS
|
||||||
|
DWORD attr = GetFileAttributesA(path);
|
||||||
|
|
||||||
|
return (attr != INVALID_FILE_ATTRIBUTES);
|
||||||
|
#elif defined PLATFORM_POSIX
|
||||||
|
struct stat s;
|
||||||
|
|
||||||
|
return (stat(path, &s) == 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LibrarySystem::IsPathFile(const char *path)
|
bool LibrarySystem::IsPathFile(const char *path)
|
||||||
{
|
{
|
||||||
return ke::file::IsFile(path);
|
#if defined PLATFORM_WINDOWS
|
||||||
|
DWORD attr = GetFileAttributes(path);
|
||||||
|
|
||||||
|
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attr & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
#elif defined PLATFORM_POSIX
|
||||||
|
struct stat s;
|
||||||
|
|
||||||
|
if (stat(path, &s) != 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return S_ISREG(s.st_mode) ? true : false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LibrarySystem::IsPathDirectory(const char *path)
|
bool LibrarySystem::IsPathDirectory(const char *path)
|
||||||
{
|
{
|
||||||
return ke::file::IsDirectory(path);
|
#if defined PLATFORM_WINDOWS
|
||||||
|
DWORD attr = GetFileAttributes(path);
|
||||||
|
|
||||||
|
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attr & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined PLATFORM_POSIX
|
||||||
|
struct stat s;
|
||||||
|
|
||||||
|
if (stat(path, &s) != 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (S_ISDIR(s.st_mode))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
IDirectory *LibrarySystem::OpenDirectory(const char *path)
|
IDirectory *LibrarySystem::OpenDirectory(const char *path)
|
||||||
@@ -224,13 +293,13 @@ void LibrarySystem::GetPlatformErrorEx(int code, char *error, size_t maxlength)
|
|||||||
maxlength,
|
maxlength,
|
||||||
NULL) == 0)
|
NULL) == 0)
|
||||||
{
|
{
|
||||||
ke::SafeSprintf(error, maxlength, "error code %08x", code);
|
UTIL_Format(error, maxlength, "error code %08x", code);
|
||||||
}
|
}
|
||||||
#elif defined PLATFORM_LINUX
|
#elif defined PLATFORM_LINUX
|
||||||
const char *ae = strerror_r(code, error, maxlength);
|
const char *ae = strerror_r(code, error, maxlength);
|
||||||
if (ae != error)
|
if (ae != error)
|
||||||
{
|
{
|
||||||
ke::SafeStrcpy(error, maxlength, ae);
|
UTIL_Format(error, maxlength, "%s", ae);
|
||||||
}
|
}
|
||||||
#elif defined PLATFORM_POSIX
|
#elif defined PLATFORM_POSIX
|
||||||
strerror_r(code, error, maxlength);
|
strerror_r(code, error, maxlength);
|
||||||
@@ -238,6 +307,18 @@ void LibrarySystem::GetPlatformErrorEx(int code, char *error, size_t maxlength)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LibrarySystem::GetLoaderError(char *buffer, size_t maxlength)
|
||||||
|
{
|
||||||
|
#if defined PLATFORM_WINDOWS
|
||||||
|
GetPlatformError(buffer, maxlength);
|
||||||
|
#elif defined PLATFORM_POSIX
|
||||||
|
if (buffer != NULL && maxlength)
|
||||||
|
{
|
||||||
|
strncopy(buffer, dlerror(), maxlength);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void LibrarySystem::CloseDirectory(IDirectory *dir)
|
void LibrarySystem::CloseDirectory(IDirectory *dir)
|
||||||
{
|
{
|
||||||
delete dir;
|
delete dir;
|
||||||
@@ -245,9 +326,19 @@ void LibrarySystem::CloseDirectory(IDirectory *dir)
|
|||||||
|
|
||||||
ILibrary *LibrarySystem::OpenLibrary(const char *path, char *error, size_t maxlength)
|
ILibrary *LibrarySystem::OpenLibrary(const char *path, char *error, size_t maxlength)
|
||||||
{
|
{
|
||||||
ke::RefPtr<ke::SharedLib> lib = ke::SharedLib::Open(path, error, maxlength);
|
LibraryHandle lib;
|
||||||
if (!lib)
|
#if defined PLATFORM_WINDOWS
|
||||||
return nullptr;
|
lib = LoadLibraryA(path);
|
||||||
|
#elif defined PLATFORM_POSIX
|
||||||
|
lib = dlopen(path, RTLD_NOW);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (lib == NULL)
|
||||||
|
{
|
||||||
|
GetLoaderError(error, maxlength);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return new CLibrary(lib);
|
return new CLibrary(lib);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,8 +346,23 @@ size_t LibrarySystem::PathFormat(char *buffer, size_t len, const char *fmt, ...)
|
|||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
size_t mylen = ke::path::FormatVa(buffer, len, fmt, ap);
|
size_t mylen = vsnprintf(buffer, len, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
|
if (mylen >= len)
|
||||||
|
{
|
||||||
|
mylen = len - 1;
|
||||||
|
buffer[mylen] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i=0; i<mylen; i++)
|
||||||
|
{
|
||||||
|
if (buffer[i] == PLATFORM_SEP_ALTCHAR)
|
||||||
|
{
|
||||||
|
buffer[i] = PLATFORM_SEP_CHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return mylen;
|
return mylen;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +398,11 @@ const char *LibrarySystem::GetFileExtension(const char *filename)
|
|||||||
|
|
||||||
bool LibrarySystem::CreateFolder(const char *path)
|
bool LibrarySystem::CreateFolder(const char *path)
|
||||||
{
|
{
|
||||||
return ke::file::CreateDirectory(path, 0775);
|
#if defined PLATFORM_WINDOWS
|
||||||
|
return (mkdir(path) != -1);
|
||||||
|
#elif defined PLATFORM_POSIX
|
||||||
|
return (mkdir(path, 0775) != -1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t LibrarySystem::GetFileFromPath(char *buffer, size_t maxlength, const char *path)
|
size_t LibrarySystem::GetFileFromPath(char *buffer, size_t maxlength, const char *path)
|
||||||
@@ -309,12 +419,12 @@ size_t LibrarySystem::GetFileFromPath(char *buffer, size_t maxlength, const char
|
|||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return ke::SafeStrcpy(buffer, maxlength, &path[i+1]);
|
return UTIL_Format(buffer, maxlength, "%s", &path[i+1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We scanned and found no path separator */
|
/* We scanned and found no path separator */
|
||||||
return ke::SafeStrcpy(buffer, maxlength, path);
|
return UTIL_Format(buffer, maxlength, "%s", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LibrarySystem::FileTime(const char *path, FileTimeType type, time_t *pTime)
|
bool LibrarySystem::FileTime(const char *path, FileTimeType type, time_t *pTime)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -33,11 +33,16 @@
|
|||||||
#define _INCLUDE_SOURCEMOD_SYSTEM_LIBRARY_H_
|
#define _INCLUDE_SOURCEMOD_SYSTEM_LIBRARY_H_
|
||||||
|
|
||||||
#include <ILibrarySys.h>
|
#include <ILibrarySys.h>
|
||||||
#include <amtl/os/am-shared-library.h>
|
|
||||||
#include "sm_platform.h"
|
#include "sm_platform.h"
|
||||||
|
|
||||||
using namespace SourceMod;
|
using namespace SourceMod;
|
||||||
|
|
||||||
|
#if defined PLATFORM_WINDOWS
|
||||||
|
typedef HMODULE LibraryHandle;
|
||||||
|
#elif defined PLATFORM_POSIX
|
||||||
|
typedef void * LibraryHandle;
|
||||||
|
#endif
|
||||||
|
|
||||||
class CDirectory : public IDirectory
|
class CDirectory : public IDirectory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -66,12 +71,13 @@ private:
|
|||||||
class CLibrary : public ILibrary
|
class CLibrary : public ILibrary
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CLibrary(ke::RefPtr<ke::SharedLib> lib);
|
CLibrary(LibraryHandle me);
|
||||||
|
~CLibrary();
|
||||||
public:
|
public:
|
||||||
void CloseLibrary() override;
|
void CloseLibrary();
|
||||||
void *GetSymbolAddress(const char *symname) override;
|
void *GetSymbolAddress(const char *symname);
|
||||||
private:
|
private:
|
||||||
ke::RefPtr<ke::SharedLib> lib_;
|
LibraryHandle m_lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LibrarySystem : public ILibrarySys
|
class LibrarySystem : public ILibrarySys
|
||||||
@@ -90,6 +96,7 @@ public:
|
|||||||
bool CreateFolder(const char *path);
|
bool CreateFolder(const char *path);
|
||||||
size_t GetFileFromPath(char *buffer, size_t maxlength, const char *path);
|
size_t GetFileFromPath(char *buffer, size_t maxlength, const char *path);
|
||||||
bool FileTime(const char *path, FileTimeType type, time_t *pTime);
|
bool FileTime(const char *path, FileTimeType type, time_t *pTime);
|
||||||
|
void GetLoaderError(char *buffer, size_t maxlength);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern LibrarySystem g_LibSys;
|
extern LibrarySystem g_LibSys;
|
||||||
+512
-26
@@ -34,37 +34,523 @@
|
|||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include "sm_stringutil.h"
|
#include "sm_stringutil.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "LibrarySys.h"
|
||||||
#include "TimerSys.h"
|
#include "TimerSys.h"
|
||||||
#include "logic_bridge.h"
|
|
||||||
#include <sourcemod_version.h>
|
#include <sourcemod_version.h>
|
||||||
#include <bridge/include/IProviderCallbacks.h>
|
|
||||||
|
Logger g_Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* :TODO: This should be creating the log folder if it doesn't exist
|
||||||
|
*/
|
||||||
|
|
||||||
|
ConfigResult Logger::OnSourceModConfigChanged(const char *key,
|
||||||
|
const char *value,
|
||||||
|
ConfigSource source,
|
||||||
|
char *error,
|
||||||
|
size_t maxlength)
|
||||||
|
{
|
||||||
|
if (strcasecmp(key, "Logging") == 0)
|
||||||
|
{
|
||||||
|
bool state;
|
||||||
|
|
||||||
|
if (strcasecmp(value, "on") == 0)
|
||||||
|
{
|
||||||
|
state = true;
|
||||||
|
} else if (strcasecmp(value, "off") == 0) {
|
||||||
|
state = false;
|
||||||
|
} else {
|
||||||
|
UTIL_Format(error, maxlength, "Invalid value: must be \"on\" or \"off\"");
|
||||||
|
return ConfigResult_Reject;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source == ConfigSource_Console)
|
||||||
|
{
|
||||||
|
state ? EnableLogging() : DisableLogging();
|
||||||
|
} else {
|
||||||
|
m_InitialState = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ConfigResult_Accept;
|
||||||
|
} else if (strcasecmp(key, "LogMode") == 0) {
|
||||||
|
if (strcasecmp(value, "daily") == 0)
|
||||||
|
{
|
||||||
|
m_Mode = LoggingMode_Daily;
|
||||||
|
} else if (strcasecmp(value, "map") == 0) {
|
||||||
|
m_Mode = LoggingMode_PerMap;
|
||||||
|
} else if (strcasecmp(value, "game") == 0) {
|
||||||
|
m_Mode = LoggingMode_Game;
|
||||||
|
} else {
|
||||||
|
UTIL_Format(error, maxlength, "Invalid value: must be [daily|map|game]");
|
||||||
|
return ConfigResult_Reject;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ConfigResult_Accept;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ConfigResult_Ignore;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::OnSourceModStartup(bool late)
|
||||||
|
{
|
||||||
|
InitLogger(m_Mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::OnSourceModAllShutdown()
|
||||||
|
{
|
||||||
|
CloseLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::OnSourceModLevelChange(const char *mapName)
|
||||||
|
{
|
||||||
|
MapChange(mapName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::_NewMapFile()
|
||||||
|
{
|
||||||
|
if (!m_Active)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Append "Log file closed" to previous log file */
|
||||||
|
_CloseFile();
|
||||||
|
|
||||||
|
char _filename[256];
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
time_t t;
|
||||||
|
GetAdjustedTime(&t);
|
||||||
|
tm *curtime = localtime(&t);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
g_SourceMod.BuildPath(Path_SM, _filename, sizeof(_filename), "logs/L%02d%02d%03d.log", curtime->tm_mon + 1, curtime->tm_mday, i);
|
||||||
|
FILE *fp = fopen(_filename, "r");
|
||||||
|
if (!fp)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
m_NrmFileName.assign(_filename);
|
||||||
|
|
||||||
|
FILE *fp = fopen(m_NrmFileName.c_str(), "w");
|
||||||
|
if (!fp)
|
||||||
|
{
|
||||||
|
char error[255];
|
||||||
|
g_LibSys.GetPlatformError(error, sizeof(error));
|
||||||
|
LogFatal("[SM] Unexpected fatal logging error (file \"%s\")", m_NrmFileName.c_str());
|
||||||
|
LogFatal("[SM] Platform returned error: \"%s\"", error);
|
||||||
|
LogFatal("[SM] Logging has been disabled.");
|
||||||
|
m_Active = false;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
char date[32];
|
||||||
|
strftime(date, sizeof(date), "%m/%d/%Y - %H:%M:%S", curtime);
|
||||||
|
fprintf(fp, "L %s: SourceMod log file started (file \"L%02d%02d%03d.log\") (Version \"%s\")\n", date, curtime->tm_mon + 1, curtime->tm_mday, i, SM_VERSION_STRING);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::_CloseFile()
|
||||||
|
{
|
||||||
|
if (!m_Active)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *fp = NULL;
|
||||||
|
if (!m_NrmFileName.empty())
|
||||||
|
{
|
||||||
|
fp = fopen(m_NrmFileName.c_str(), "r+");
|
||||||
|
if (fp)
|
||||||
|
{
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
LogMessage("Log file closed.");
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
m_NrmFileName.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_ErrMapStart)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fp = fopen(m_ErrFileName.c_str(), "r+");
|
||||||
|
if (fp)
|
||||||
|
{
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
LogError("Error log file session closed.");
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
m_ErrFileName.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::InitLogger(LoggingMode mode)
|
||||||
|
{
|
||||||
|
m_Mode = mode;
|
||||||
|
m_Active = m_InitialState;
|
||||||
|
|
||||||
|
time_t t;
|
||||||
|
GetAdjustedTime(&t);
|
||||||
|
tm *curtime = localtime(&t);
|
||||||
|
m_CurDay = curtime->tm_mday;
|
||||||
|
|
||||||
|
char _filename[256];
|
||||||
|
g_SourceMod.BuildPath(Path_SM, _filename, sizeof(_filename), "logs/errors_%04d%02d%02d.log", curtime->tm_year + 1900, curtime->tm_mon + 1, curtime->tm_mday);
|
||||||
|
m_ErrFileName.assign(_filename);
|
||||||
|
|
||||||
|
switch (m_Mode)
|
||||||
|
{
|
||||||
|
case LoggingMode_PerMap:
|
||||||
|
{
|
||||||
|
if (!m_Active)
|
||||||
|
{
|
||||||
|
m_DelayedStart = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LoggingMode_Daily:
|
||||||
|
{
|
||||||
|
g_SourceMod.BuildPath(Path_SM, _filename, sizeof(_filename), "logs/L%04d%02d%02d.log", curtime->tm_year + 1900, curtime->tm_mon + 1, curtime->tm_mday);
|
||||||
|
m_NrmFileName.assign(_filename);
|
||||||
|
m_DailyPrintHdr = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
/* do nothing... */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::CloseLogger()
|
||||||
|
{
|
||||||
|
_CloseFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::LogToOpenFile(FILE *fp, const char *msg, ...)
|
||||||
|
{
|
||||||
|
if (!m_Active)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, msg);
|
||||||
|
LogToOpenFileEx(fp, msg, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::LogToFileOnly(FILE *fp, const char *msg, ...)
|
||||||
|
{
|
||||||
|
if (!m_Active)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, msg);
|
||||||
|
LogToFileOnlyEx(fp, msg, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::LogToOpenFileEx(FILE *fp, const char *msg, va_list ap)
|
||||||
|
{
|
||||||
|
if (!m_Active)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ConVar *sv_logecho = icvar->FindVar("sv_logecho");
|
||||||
|
|
||||||
|
char buffer[3072];
|
||||||
|
UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
|
||||||
|
|
||||||
|
char date[32];
|
||||||
|
time_t t;
|
||||||
|
GetAdjustedTime(&t);
|
||||||
|
tm *curtime = localtime(&t);
|
||||||
|
strftime(date, sizeof(date), "%m/%d/%Y - %H:%M:%S", curtime);
|
||||||
|
|
||||||
|
fprintf(fp, "L %s: %s\n", date, buffer);
|
||||||
|
|
||||||
|
if (!sv_logecho || sv_logecho->GetBool())
|
||||||
|
{
|
||||||
|
g_SMAPI->ConPrintf("L %s: %s\n", date, buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::LogToFileOnlyEx(FILE *fp, const char *msg, va_list ap)
|
||||||
|
{
|
||||||
|
if (!m_Active)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buffer[3072];
|
||||||
|
UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
|
||||||
|
|
||||||
|
char date[32];
|
||||||
|
time_t t;
|
||||||
|
GetAdjustedTime(&t);
|
||||||
|
tm *curtime = localtime(&t);
|
||||||
|
strftime(date, sizeof(date), "%m/%d/%Y - %H:%M:%S", curtime);
|
||||||
|
|
||||||
|
fprintf(fp, "L %s: %s\n", date, buffer);
|
||||||
|
fflush(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::LogMessage(const char *vafmt, ...)
|
||||||
|
{
|
||||||
|
if (!m_Active)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_Mode == LoggingMode_Game)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, vafmt);
|
||||||
|
_PrintToGameLog(vafmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_DelayedStart)
|
||||||
|
{
|
||||||
|
m_DelayedStart = false;
|
||||||
|
_NewMapFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t t;
|
||||||
|
GetAdjustedTime(&t);
|
||||||
|
tm *curtime = localtime(&t);
|
||||||
|
|
||||||
|
FILE *fp = NULL;
|
||||||
|
if (m_Mode == LoggingMode_PerMap)
|
||||||
|
{
|
||||||
|
fp = fopen(m_NrmFileName.c_str(), "a+");
|
||||||
|
if (!fp)
|
||||||
|
{
|
||||||
|
_NewMapFile();
|
||||||
|
fp = fopen(m_NrmFileName.c_str(), "a+");
|
||||||
|
if (!fp)
|
||||||
|
{
|
||||||
|
goto print_error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (m_CurDay != curtime->tm_mday)
|
||||||
|
{
|
||||||
|
char _filename[256];
|
||||||
|
g_SourceMod.BuildPath(Path_SM, _filename, sizeof(_filename), "logs/L%04d%02d%02d.log", curtime->tm_year + 1900, curtime->tm_mon + 1, curtime->tm_mday);
|
||||||
|
m_NrmFileName.assign(_filename);
|
||||||
|
m_CurDay = curtime->tm_mday;
|
||||||
|
m_DailyPrintHdr = true;
|
||||||
|
}
|
||||||
|
fp = fopen(m_NrmFileName.c_str(), "a+");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fp)
|
||||||
|
{
|
||||||
|
if (m_DailyPrintHdr)
|
||||||
|
{
|
||||||
|
char date[32];
|
||||||
|
m_DailyPrintHdr = false;
|
||||||
|
strftime(date, sizeof(date), "%m/%d/%Y - %H:%M:%S", curtime);
|
||||||
|
fprintf(fp, "L %s: SourceMod log file session started (file \"L%04d%02d%02d.log\") (Version \"%s\")\n", date, curtime->tm_year + 1900, curtime->tm_mon + 1, curtime->tm_mday, SM_VERSION_STRING);
|
||||||
|
}
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, vafmt);
|
||||||
|
LogToOpenFileEx(fp, vafmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
fclose(fp);
|
||||||
|
} else {
|
||||||
|
goto print_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
print_error:
|
||||||
|
char error[255];
|
||||||
|
g_LibSys.GetPlatformError(error, sizeof(error));
|
||||||
|
LogFatal("[SM] Unexpected fatal logging error (file \"%s\")", m_NrmFileName.c_str());
|
||||||
|
LogFatal("[SM] Platform returned error: \"%s\"", error);
|
||||||
|
LogFatal("[SM] Logging has been disabled.");
|
||||||
|
m_Active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::LogError(const char *vafmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, vafmt);
|
||||||
|
LogErrorEx(vafmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::LogErrorEx(const char *vafmt, va_list ap)
|
||||||
|
{
|
||||||
|
if (!m_Active)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t t;
|
||||||
|
GetAdjustedTime(&t);
|
||||||
|
tm *curtime = localtime(&t);
|
||||||
|
|
||||||
|
if (curtime->tm_mday != m_CurDay)
|
||||||
|
{
|
||||||
|
char _filename[256];
|
||||||
|
g_SourceMod.BuildPath(Path_SM, _filename, sizeof(_filename), "logs/errors_%04d%02d%02d.log", curtime->tm_year + 1900, curtime->tm_mon + 1, curtime->tm_mday);
|
||||||
|
m_ErrFileName.assign(_filename);
|
||||||
|
m_CurDay = curtime->tm_mday;
|
||||||
|
m_ErrMapStart = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *fp = fopen(m_ErrFileName.c_str(), "a+");
|
||||||
|
if (fp)
|
||||||
|
{
|
||||||
|
if (!m_ErrMapStart)
|
||||||
|
{
|
||||||
|
char date[32];
|
||||||
|
strftime(date, sizeof(date), "%m/%d/%Y - %H:%M:%S", curtime);
|
||||||
|
fprintf(fp, "L %s: SourceMod error session started\n", date);
|
||||||
|
fprintf(fp, "L %s: Info (map \"%s\") (file \"errors_%04d%02d%02d.log\")\n", date, m_CurMapName.c_str(), curtime->tm_year + 1900, curtime->tm_mon + 1, curtime->tm_mday);
|
||||||
|
m_ErrMapStart = true;
|
||||||
|
}
|
||||||
|
LogToOpenFileEx(fp, vafmt, ap);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char error[255];
|
||||||
|
g_LibSys.GetPlatformError(error, sizeof(error));
|
||||||
|
LogFatal("[SM] Unexpected fatal logging error (file \"%s\")", m_NrmFileName.c_str());
|
||||||
|
LogFatal("[SM] Platform returned error: \"%s\"", error);
|
||||||
|
LogFatal("[SM] Logging has been disabled.");
|
||||||
|
m_Active = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::MapChange(const char *mapname)
|
||||||
|
{
|
||||||
|
m_CurMapName.assign(mapname);
|
||||||
|
|
||||||
|
switch (m_Mode)
|
||||||
|
{
|
||||||
|
case LoggingMode_Daily:
|
||||||
|
{
|
||||||
|
LogMessage("-------- Mapchange to %s --------", mapname);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LoggingMode_PerMap:
|
||||||
|
{
|
||||||
|
_NewMapFile();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
/* Do nothing... */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_ErrMapStart)
|
||||||
|
{
|
||||||
|
LogError("Error log file session closed.");
|
||||||
|
}
|
||||||
|
m_ErrMapStart = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::_PrintToGameLog(const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
char msg[3072];
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
len = vsnprintf(msg, sizeof(msg)-2, fmt, ap);
|
||||||
|
len = (len >= sizeof(msg)) ? (sizeof(msg) - 2) : len;
|
||||||
|
|
||||||
|
msg[len++] = '\n';
|
||||||
|
msg[len] = '\0';
|
||||||
|
|
||||||
|
Engine_LogPrintWrapper(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Logger::GetLogFileName(LogType type) const
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case LogType_Normal:
|
||||||
|
{
|
||||||
|
return m_NrmFileName.c_str();
|
||||||
|
}
|
||||||
|
case LogType_Error:
|
||||||
|
{
|
||||||
|
return m_ErrFileName.c_str();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LoggingMode Logger::GetLoggingMode() const
|
||||||
|
{
|
||||||
|
return m_Mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::EnableLogging()
|
||||||
|
{
|
||||||
|
if (m_Active)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_Active = true;
|
||||||
|
LogMessage("[SM] Logging enabled manually by user.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::DisableLogging()
|
||||||
|
{
|
||||||
|
if (!m_Active)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LogMessage("[SM] Logging disabled manually by user.");
|
||||||
|
m_Active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::LogFatal(const char *msg, ...)
|
||||||
|
{
|
||||||
|
/* :TODO: make this print all pretty-like
|
||||||
|
* In fact, the pretty log printing function should be abstracted.
|
||||||
|
* It's already implemented twice which is bad.
|
||||||
|
*/
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
char path[PLATFORM_MAX_PATH];
|
||||||
|
|
||||||
|
g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "sourcemod_fatal.log");
|
||||||
|
|
||||||
|
FILE *fp = fopen(path, "at");
|
||||||
|
if (fp)
|
||||||
|
{
|
||||||
|
m_Active = true;
|
||||||
|
va_start(ap, msg);
|
||||||
|
LogToOpenFileEx(fp, msg, ap);
|
||||||
|
va_end(ap);
|
||||||
|
m_Active = false;
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool g_in_game_log_hook = false;
|
bool g_in_game_log_hook = false;
|
||||||
|
|
||||||
static LoggerCore g_LoggerCore;
|
|
||||||
|
|
||||||
SH_DECL_HOOK1_void(IVEngineServer, LogPrint, SH_NOATTRIB, false, const char *);
|
|
||||||
|
|
||||||
static void HookLogPrint(const char *message)
|
|
||||||
{
|
|
||||||
g_in_game_log_hook = true;
|
|
||||||
bool stopped = logicore.callbacks->OnLogPrint(message);
|
|
||||||
g_in_game_log_hook = false;
|
|
||||||
|
|
||||||
if (stopped)
|
|
||||||
RETURN_META(MRES_SUPERCEDE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoggerCore::OnSourceModStartup(bool late)
|
|
||||||
{
|
|
||||||
SH_ADD_HOOK(IVEngineServer, LogPrint, engine, SH_STATIC(HookLogPrint), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoggerCore::OnSourceModAllShutdown()
|
|
||||||
{
|
|
||||||
SH_REMOVE_HOOK(IVEngineServer, LogPrint, engine, SH_STATIC(HookLogPrint), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Engine_LogPrintWrapper(const char *msg)
|
void Engine_LogPrintWrapper(const char *msg)
|
||||||
{
|
{
|
||||||
if (g_in_game_log_hook)
|
if (g_in_game_log_hook)
|
||||||
|
|||||||
+61
-1
@@ -38,13 +38,73 @@
|
|||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
|
|
||||||
class LoggerCore : public SMGlobalClass
|
enum LogType
|
||||||
{
|
{
|
||||||
|
LogType_Normal,
|
||||||
|
LogType_Error
|
||||||
|
};
|
||||||
|
|
||||||
|
enum LoggingMode
|
||||||
|
{
|
||||||
|
LoggingMode_Daily,
|
||||||
|
LoggingMode_PerMap,
|
||||||
|
LoggingMode_Game
|
||||||
|
};
|
||||||
|
|
||||||
|
class Logger : public SMGlobalClass
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Logger() : m_Mode(LoggingMode_Daily), m_ErrMapStart(false),
|
||||||
|
m_Active(false), m_DelayedStart(false), m_DailyPrintHdr(false),
|
||||||
|
m_InitialState(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
public: //SMGlobalClass
|
public: //SMGlobalClass
|
||||||
|
ConfigResult OnSourceModConfigChanged(const char *key,
|
||||||
|
const char *value,
|
||||||
|
ConfigSource source,
|
||||||
|
char *error,
|
||||||
|
size_t maxlength);
|
||||||
void OnSourceModStartup(bool late);
|
void OnSourceModStartup(bool late);
|
||||||
void OnSourceModAllShutdown();
|
void OnSourceModAllShutdown();
|
||||||
|
void OnSourceModLevelChange(const char *mapName);
|
||||||
|
public:
|
||||||
|
void InitLogger(LoggingMode mode);
|
||||||
|
void CloseLogger();
|
||||||
|
void EnableLogging();
|
||||||
|
void DisableLogging();
|
||||||
|
void LogMessage(const char *msg, ...);
|
||||||
|
void LogError(const char *msg, ...);
|
||||||
|
void LogErrorEx(const char *msg, va_list ap);
|
||||||
|
void LogFatal(const char *msg, ...);
|
||||||
|
void LogToOpenFile(FILE *fp, const char *msg, ...);
|
||||||
|
void LogToOpenFileEx(FILE *fp, const char *msg, va_list ap);
|
||||||
|
/* This version does not print to console, and is thus thread-safe */
|
||||||
|
void LogToFileOnly(FILE *fp, const char *msg, ...);
|
||||||
|
void LogToFileOnlyEx(FILE *fp, const char *msg, va_list ap);
|
||||||
|
void MapChange(const char *mapname);
|
||||||
|
const char *GetLogFileName(LogType type) const;
|
||||||
|
LoggingMode GetLoggingMode() const;
|
||||||
|
private:
|
||||||
|
void _CloseFile();
|
||||||
|
void _NewMapFile();
|
||||||
|
void _PrintToGameLog(const char *fmt, va_list ap);
|
||||||
|
private:
|
||||||
|
String m_NrmFileName;
|
||||||
|
String m_ErrFileName;
|
||||||
|
String m_CurMapName;
|
||||||
|
LoggingMode m_Mode;
|
||||||
|
int m_CurDay;
|
||||||
|
bool m_ErrMapStart;
|
||||||
|
bool m_Active;
|
||||||
|
bool m_DelayedStart;
|
||||||
|
bool m_DailyPrintHdr;
|
||||||
|
bool m_InitialState;
|
||||||
};
|
};
|
||||||
|
|
||||||
void Engine_LogPrintWrapper(const char *msg);
|
void Engine_LogPrintWrapper(const char *msg);
|
||||||
|
|
||||||
|
extern bool g_in_game_log_hook;
|
||||||
|
extern Logger g_Logger;
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_CLOGGER_H_
|
#endif // _INCLUDE_SOURCEMOD_CLOGGER_H_
|
||||||
|
|||||||
+216
@@ -0,0 +1,216 @@
|
|||||||
|
# (C)2004-2008 SourceMod Development Team
|
||||||
|
# Makefile written by David "BAILOPAN" Anderson
|
||||||
|
|
||||||
|
SMSDK = ..
|
||||||
|
HL2SDK_ORIG = ../../hl2sdk
|
||||||
|
HL2SDK_OB = ../../hl2sdk-ob
|
||||||
|
HL2SDK_CSS = ../../hl2sdk-css
|
||||||
|
HL2SDK_OB_VALVE = ../../hl2sdk-ob-valve
|
||||||
|
HL2SDK_L4D = ../../hl2sdk-l4d
|
||||||
|
HL2SDK_L4D2 = ../../hl2sdk-l4d2
|
||||||
|
HL2SDK_CSGO = ../../hl2sdk-csgo
|
||||||
|
MMSOURCE = ../../mmsource-central
|
||||||
|
|
||||||
|
#####################################
|
||||||
|
### EDIT BELOW FOR OTHER PROJECTS ###
|
||||||
|
#####################################
|
||||||
|
|
||||||
|
OBJECTS = AdminCache.cpp CDataPack.cpp ConCmdManager.cpp ConVarManager.cpp CoreConfig.cpp \
|
||||||
|
Database.cpp DebugReporter.cpp EventManager.cpp HalfLife2.cpp Logger.cpp \
|
||||||
|
PlayerManager.cpp TimerSys.cpp UserMessages.cpp \
|
||||||
|
sm_autonatives.cpp sm_srvcmds.cpp sm_stringutil.cpp sm_trie.cpp \
|
||||||
|
sourcemm_api.cpp sourcemod.cpp MenuStyle_Base.cpp MenuStyle_Valve.cpp MenuManager.cpp \
|
||||||
|
MenuStyle_Radio.cpp ChatTriggers.cpp ADTFactory.cpp MenuVoting.cpp \
|
||||||
|
frame_hooks.cpp concmd_cleaner.cpp NextMap.cpp \
|
||||||
|
NativeOwner.cpp logic_bridge.cpp ConsoleDetours.cpp
|
||||||
|
OBJECTS += smn_bitbuffer.cpp smn_console.cpp smn_core.cpp \
|
||||||
|
smn_database.cpp smn_entities.cpp smn_events.cpp \
|
||||||
|
smn_fakenatives.cpp smn_filesystem.cpp smn_halflife.cpp \
|
||||||
|
smn_keyvalues.cpp smn_player.cpp \
|
||||||
|
smn_usermsgs.cpp smn_menus.cpp smn_vector.cpp \
|
||||||
|
smn_hudtext.cpp smn_nextmap.cpp
|
||||||
|
OBJECTS += ExtensionSys.cpp \
|
||||||
|
ForwardSys.cpp \
|
||||||
|
HandleSys.cpp \
|
||||||
|
LibrarySys.cpp \
|
||||||
|
PluginInfoDatabase.cpp \
|
||||||
|
PluginSys.cpp \
|
||||||
|
ShareSys.cpp \
|
||||||
|
NativeInvoker.cpp
|
||||||
|
|
||||||
|
##############################################
|
||||||
|
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
|
||||||
|
##############################################
|
||||||
|
|
||||||
|
C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing
|
||||||
|
C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
|
||||||
|
C_GCC4_FLAGS = -fvisibility=hidden
|
||||||
|
CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
|
||||||
|
CPP = gcc
|
||||||
|
|
||||||
|
override ENGSET = false
|
||||||
|
|
||||||
|
ifneq (,$(filter original orangebox css orangeboxvalve left4dead left4dead2 csgo,$(ENGINE)))
|
||||||
|
override ENGSET = true
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq "$(ENGINE)" "original"
|
||||||
|
HL2SDK = $(HL2SDK_ORIG)
|
||||||
|
HL2LIB = $(HL2SDK)/linux_sdk
|
||||||
|
CFLAGS += -DSOURCE_ENGINE=1
|
||||||
|
METAMOD = $(MMSOURCE)/core-legacy
|
||||||
|
INCLUDE += -I$(HL2SDK)/public/dlls
|
||||||
|
BINARY = sourcemod.1.ep1.so
|
||||||
|
endif
|
||||||
|
ifeq "$(ENGINE)" "orangebox"
|
||||||
|
HL2SDK = $(HL2SDK_OB)
|
||||||
|
HL2LIB = $(HL2SDK)/lib/linux
|
||||||
|
CFLAGS += -DSOURCE_ENGINE=3
|
||||||
|
METAMOD = $(MMSOURCE)/core
|
||||||
|
INCLUDE += -I$(HL2SDK)/public/game/server
|
||||||
|
BINARY = sourcemod.2.ep2.so
|
||||||
|
endif
|
||||||
|
ifeq "$(ENGINE)" "css"
|
||||||
|
HL2SDK = $(HL2SDK_CSS)
|
||||||
|
HL2LIB = $(HL2SDK)/lib/linux
|
||||||
|
CFLAGS += -DSOURCE_ENGINE=6
|
||||||
|
METAMOD = $(MMSOURCE)/core
|
||||||
|
INCLUDE += -I$(HL2SDK)/public/game/server
|
||||||
|
BINARY = sourcemod.2.css.so
|
||||||
|
endif
|
||||||
|
ifeq "$(ENGINE)" "orangeboxvalve"
|
||||||
|
HL2SDK = $(HL2SDK_OB_VALVE)
|
||||||
|
HL2LIB = $(HL2SDK)/lib/linux
|
||||||
|
CFLAGS += -DSOURCE_ENGINE=7
|
||||||
|
METAMOD = $(MMSOURCE)/core
|
||||||
|
INCLUDE += -I$(HL2SDK)/public/game/server
|
||||||
|
BINARY = sourcemod.2.ep2v.so
|
||||||
|
endif
|
||||||
|
ifeq "$(ENGINE)" "left4dead"
|
||||||
|
HL2SDK = $(HL2SDK_L4D)
|
||||||
|
HL2LIB = $(HL2SDK)/lib/linux
|
||||||
|
CFLAGS += -DSOURCE_ENGINE=8
|
||||||
|
METAMOD = $(MMSOURCE)/core
|
||||||
|
INCLUDE += -I$(HL2SDK)/public/game/server
|
||||||
|
BINARY = sourcemod.2.l4d.so
|
||||||
|
endif
|
||||||
|
ifeq "$(ENGINE)" "left4dead2"
|
||||||
|
HL2SDK = $(HL2SDK_L4D2)
|
||||||
|
HL2LIB = $(HL2SDK)/lib/linux
|
||||||
|
CFLAGS += -DSOURCE_ENGINE=9
|
||||||
|
METAMOD = $(MMSOURCE)/core
|
||||||
|
INCLUDE += -I$(HL2SDK)/public/game/server
|
||||||
|
BINARY = sourcemod.2.l4d2.so
|
||||||
|
endif
|
||||||
|
ifeq "$(ENGINE)" "csgo"
|
||||||
|
HL2SDK = $(HL2SDK_CSGO)
|
||||||
|
HL2LIB = $(HL2SDK)/lib/linux
|
||||||
|
CFLAGS += -DSOURCE_ENGINE=12
|
||||||
|
METAMOD = $(MMSOURCE)/core
|
||||||
|
INCLUDE += -I$(HL2SDK)/public/game/server
|
||||||
|
BINARY = sourcemod.2.csgo.so
|
||||||
|
endif
|
||||||
|
|
||||||
|
HL2PUB = $(HL2SDK)/public
|
||||||
|
|
||||||
|
OS := $(shell uname -s)
|
||||||
|
|
||||||
|
ifeq "$(OS)" "Darwin"
|
||||||
|
LIB_EXT = dylib
|
||||||
|
HL2LIB = $(HL2SDK)/lib/mac
|
||||||
|
else
|
||||||
|
LIB_EXT = so
|
||||||
|
ifeq "$(ENGINE)" "original"
|
||||||
|
HL2LIB = $(HL2SDK)/linux_sdk
|
||||||
|
else
|
||||||
|
HL2LIB = $(HL2SDK)/lib/linux
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq (,$(filter original orangebox left4dead,$(ENGINE)))
|
||||||
|
LIB_SUFFIX = _i486.$(LIB_EXT)
|
||||||
|
else
|
||||||
|
LIB_PREFIX = lib
|
||||||
|
ifneq (,$(filter orangeboxvalve css,$(ENGINE)))
|
||||||
|
ifneq "$(OS)" "Darwin"
|
||||||
|
LIB_SUFFIX = _srv.$(LIB_EXT)
|
||||||
|
else
|
||||||
|
LIB_SUFFIX = .$(LIB_EXT)
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
LIB_SUFFIX = .$(LIB_EXT)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS += -DSE_EPISODEONE=1 -DSE_DARKMESSIAH=2 -DSE_ORANGEBOX=3 -DSE_BLOODYGOODTIME=4 -DSE_EYE=5 \
|
||||||
|
-DSE_CSS=6 -DSE_ORANGEBOXVALVE=7 -DSE_LEFT4DEAD=8 -DSE_LEFT4DEAD2=9 -DSE_ALIENSWARM=10 \
|
||||||
|
-DSE_PORTAL2=11 -DSE_CSGO=12
|
||||||
|
|
||||||
|
LINK += $(HL2LIB)/tier1_i486.a $(HL2LIB)/mathlib_i486.a $(LIB_PREFIX)vstdlib$(LIB_SUFFIX) \
|
||||||
|
$(LIB_PREFIX)tier0$(LIB_SUFFIX) -static-libgcc
|
||||||
|
|
||||||
|
ifeq "$(ENGINE)" "csgo"
|
||||||
|
LINK += $(HL2LIB)/interfaces_i486.a
|
||||||
|
endif
|
||||||
|
|
||||||
|
INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/mathlib -I$(HL2PUB)/vstdlib \
|
||||||
|
-I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 -I$(METAMOD) -I$(METAMOD)/sourcehook \
|
||||||
|
-I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn
|
||||||
|
|
||||||
|
CFLAGS += -D_LINUX -DPOSIX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \
|
||||||
|
-D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror \
|
||||||
|
-Wno-uninitialized -Wno-unused -Wno-switch -mfpmath=sse -msse -DSOURCEMOD_BUILD -DHAVE_STDINT_H \
|
||||||
|
-DSM_DEFAULT_THREADER -m32 -DCOMPILER_GCC
|
||||||
|
CPPFLAGS += -Wno-non-virtual-dtor -Wno-overloaded-virtual -fno-threadsafe-statics -fno-exceptions -fno-rtti
|
||||||
|
|
||||||
|
################################################
|
||||||
|
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
|
||||||
|
################################################
|
||||||
|
|
||||||
|
ifeq "$(DEBUG)" "true"
|
||||||
|
BIN_DIR = Debug.$(ENGINE)
|
||||||
|
CFLAGS += $(C_DEBUG_FLAGS)
|
||||||
|
else
|
||||||
|
BIN_DIR = Release.$(ENGINE)
|
||||||
|
CFLAGS += $(C_OPT_FLAGS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1)
|
||||||
|
ifeq "$(GCC_VERSION)" "4"
|
||||||
|
CFLAGS += $(C_GCC4_FLAGS)
|
||||||
|
CPPFLAGS += $(CPP_GCC4_FLAGS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
|
||||||
|
OBJ_LINUX := $(OBJ_LINUX:%.c=$(BIN_DIR)/%.o)
|
||||||
|
|
||||||
|
$(BIN_DIR)/%.o: %.cpp
|
||||||
|
$(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
|
$(BIN_DIR)/%.o: %.c
|
||||||
|
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
|
all: check
|
||||||
|
mkdir -p $(BIN_DIR)
|
||||||
|
ln -sf $(HL2LIB)/$(LIB_PREFIX)vstdlib$(LIB_SUFFIX)
|
||||||
|
ln -sf $(HL2LIB)/$(LIB_PREFIX)tier0$(LIB_SUFFIX)
|
||||||
|
$(MAKE) -f Makefile sourcemod
|
||||||
|
|
||||||
|
check:
|
||||||
|
if [ "$(ENGSET)" = "false" ]; then \
|
||||||
|
echo "You must supply one of the following values for ENGINE:"; \
|
||||||
|
echo "csgo, left4dead2, left4dead, orangeboxvalve, css, orangebox, or original"; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
sourcemod: check $(OBJ_LINUX)
|
||||||
|
$(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
|
||||||
|
|
||||||
|
debug:
|
||||||
|
$(MAKE) -f Makefile all DEBUG=true
|
||||||
|
|
||||||
|
default: all
|
||||||
|
|
||||||
|
clean: check
|
||||||
|
rm -rf $(BIN_DIR)/*.o
|
||||||
|
rm -rf $(BIN_DIR)/$(BINARY)
|
||||||
+18
-16
@@ -38,6 +38,8 @@
|
|||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include "PlayerManager.h"
|
#include "PlayerManager.h"
|
||||||
#include "MenuStyle_Valve.h"
|
#include "MenuStyle_Valve.h"
|
||||||
|
#include "ShareSys.h"
|
||||||
|
#include "HandleSys.h"
|
||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include "logic_bridge.h"
|
#include "logic_bridge.h"
|
||||||
|
|
||||||
@@ -54,24 +56,24 @@ MenuManager::MenuManager()
|
|||||||
|
|
||||||
void MenuManager::OnSourceModAllInitialized()
|
void MenuManager::OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
sharesys->AddInterface(NULL, this);
|
g_ShareSys.AddInterface(NULL, this);
|
||||||
|
|
||||||
HandleAccess access;
|
HandleAccess access;
|
||||||
handlesys->InitAccessDefaults(NULL, &access);
|
g_HandleSys.InitAccessDefaults(NULL, &access);
|
||||||
|
|
||||||
/* Deny cloning to menus */
|
/* Deny cloning to menus */
|
||||||
access.access[HandleAccess_Clone] = HANDLE_RESTRICT_OWNER|HANDLE_RESTRICT_IDENTITY;
|
access.access[HandleAccess_Clone] = HANDLE_RESTRICT_OWNER|HANDLE_RESTRICT_IDENTITY;
|
||||||
m_MenuType = handlesys->CreateType("IBaseMenu", this, 0, NULL, &access, g_pCoreIdent, NULL);
|
m_MenuType = g_HandleSys.CreateType("IBaseMenu", this, 0, NULL, &access, g_pCoreIdent, NULL);
|
||||||
|
|
||||||
/* Also deny deletion to styles */
|
/* Also deny deletion to styles */
|
||||||
access.access[HandleAccess_Delete] = HANDLE_RESTRICT_OWNER|HANDLE_RESTRICT_IDENTITY;
|
access.access[HandleAccess_Delete] = HANDLE_RESTRICT_OWNER|HANDLE_RESTRICT_IDENTITY;
|
||||||
m_StyleType = handlesys->CreateType("IMenuStyle", this, 0, NULL, &access, g_pCoreIdent, NULL);
|
m_StyleType = g_HandleSys.CreateType("IMenuStyle", this, 0, NULL, &access, g_pCoreIdent, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuManager::OnSourceModAllShutdown()
|
void MenuManager::OnSourceModAllShutdown()
|
||||||
{
|
{
|
||||||
handlesys->RemoveType(m_MenuType, g_pCoreIdent);
|
g_HandleSys.RemoveType(m_MenuType, g_pCoreIdent);
|
||||||
handlesys->RemoveType(m_StyleType, g_pCoreIdent);
|
g_HandleSys.RemoveType(m_StyleType, g_pCoreIdent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuManager::OnHandleDestroy(HandleType_t type, void *object)
|
void MenuManager::OnHandleDestroy(HandleType_t type, void *object)
|
||||||
@@ -110,7 +112,7 @@ Handle_t MenuManager::CreateMenuHandle(IBaseMenu *menu, IdentityToken_t *pOwner)
|
|||||||
return BAD_HANDLE;
|
return BAD_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return handlesys->CreateHandle(m_MenuType, menu, pOwner, g_pCoreIdent, NULL);
|
return g_HandleSys.CreateHandle(m_MenuType, menu, pOwner, g_pCoreIdent, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle_t MenuManager::CreateStyleHandle(IMenuStyle *style)
|
Handle_t MenuManager::CreateStyleHandle(IMenuStyle *style)
|
||||||
@@ -120,7 +122,7 @@ Handle_t MenuManager::CreateStyleHandle(IMenuStyle *style)
|
|||||||
return BAD_HANDLE;
|
return BAD_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return handlesys->CreateHandle(m_StyleType, style, g_pCoreIdent, g_pCoreIdent, NULL);
|
return g_HandleSys.CreateHandle(m_StyleType, style, g_pCoreIdent, g_pCoreIdent, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleError MenuManager::ReadMenuHandle(Handle_t handle, IBaseMenu **menu)
|
HandleError MenuManager::ReadMenuHandle(Handle_t handle, IBaseMenu **menu)
|
||||||
@@ -130,7 +132,7 @@ HandleError MenuManager::ReadMenuHandle(Handle_t handle, IBaseMenu **menu)
|
|||||||
sec.pIdentity = g_pCoreIdent;
|
sec.pIdentity = g_pCoreIdent;
|
||||||
sec.pOwner = NULL;
|
sec.pOwner = NULL;
|
||||||
|
|
||||||
return handlesys->ReadHandle(handle, m_MenuType, &sec, (void **)menu);
|
return g_HandleSys.ReadHandle(handle, m_MenuType, &sec, (void **)menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleError MenuManager::ReadStyleHandle(Handle_t handle, IMenuStyle **style)
|
HandleError MenuManager::ReadStyleHandle(Handle_t handle, IMenuStyle **style)
|
||||||
@@ -140,7 +142,7 @@ HandleError MenuManager::ReadStyleHandle(Handle_t handle, IMenuStyle **style)
|
|||||||
sec.pIdentity = g_pCoreIdent;
|
sec.pIdentity = g_pCoreIdent;
|
||||||
sec.pOwner = g_pCoreIdent;
|
sec.pOwner = g_pCoreIdent;
|
||||||
|
|
||||||
return handlesys->ReadHandle(handle, m_StyleType, &sec, (void **)style);
|
return g_HandleSys.ReadHandle(handle, m_StyleType, &sec, (void **)style);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MenuManager::SetDefaultStyle(IMenuStyle *style)
|
bool MenuManager::SetDefaultStyle(IMenuStyle *style)
|
||||||
@@ -446,7 +448,7 @@ skip_search:
|
|||||||
char text[50];
|
char text[50];
|
||||||
if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "No Vote", &client))
|
if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "No Vote", &client))
|
||||||
{
|
{
|
||||||
ke::SafeStrcpy(text, sizeof(text), "No Vote");
|
UTIL_Format(text, sizeof(text), "No Vote");
|
||||||
}
|
}
|
||||||
ItemDrawInfo dr(text, 0);
|
ItemDrawInfo dr(text, 0);
|
||||||
position = panel->DrawItem(dr);
|
position = panel->DrawItem(dr);
|
||||||
@@ -570,7 +572,7 @@ skip_search:
|
|||||||
/* If there are no control options,
|
/* If there are no control options,
|
||||||
* Instead just pad with invisible slots.
|
* Instead just pad with invisible slots.
|
||||||
*/
|
*/
|
||||||
if (!displayNext && !displayPrev)
|
if (!displayPrev && !displayPrev)
|
||||||
{
|
{
|
||||||
padItem.style = ITEMDRAW_NOTEXT;
|
padItem.style = ITEMDRAW_NOTEXT;
|
||||||
}
|
}
|
||||||
@@ -606,7 +608,7 @@ skip_search:
|
|||||||
{
|
{
|
||||||
if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Back", &client))
|
if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Back", &client))
|
||||||
{
|
{
|
||||||
ke::SafeStrcpy(text, sizeof(text), "Back");
|
UTIL_Format(text, sizeof(text), "Back");
|
||||||
}
|
}
|
||||||
dr.style = ITEMDRAW_CONTROL;
|
dr.style = ITEMDRAW_CONTROL;
|
||||||
position = panel->DrawItem(dr);
|
position = panel->DrawItem(dr);
|
||||||
@@ -616,7 +618,7 @@ skip_search:
|
|||||||
{
|
{
|
||||||
if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Previous", &client))
|
if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Previous", &client))
|
||||||
{
|
{
|
||||||
ke::SafeStrcpy(text, sizeof(text), "Previous");
|
UTIL_Format(text, sizeof(text), "Previous");
|
||||||
}
|
}
|
||||||
dr.style = (displayPrev ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL;
|
dr.style = (displayPrev ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL;
|
||||||
position = panel->DrawItem(dr);
|
position = panel->DrawItem(dr);
|
||||||
@@ -637,7 +639,7 @@ skip_search:
|
|||||||
{
|
{
|
||||||
if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Next", &client))
|
if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Next", &client))
|
||||||
{
|
{
|
||||||
ke::SafeStrcpy(text, sizeof(text), "Next");
|
UTIL_Format(text, sizeof(text), "Next");
|
||||||
}
|
}
|
||||||
dr.style = (displayNext ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL;
|
dr.style = (displayNext ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL;
|
||||||
position = panel->DrawItem(dr);
|
position = panel->DrawItem(dr);
|
||||||
@@ -668,7 +670,7 @@ skip_search:
|
|||||||
{
|
{
|
||||||
if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Exit", &client))
|
if (!logicore.CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Exit", &client))
|
||||||
{
|
{
|
||||||
ke::SafeStrcpy(text, sizeof(text), "Exit");
|
UTIL_Format(text, sizeof(text), "Exit");
|
||||||
}
|
}
|
||||||
dr.style = ITEMDRAW_CONTROL;
|
dr.style = ITEMDRAW_CONTROL;
|
||||||
position = panel->DrawItem(dr);
|
position = panel->DrawItem(dr);
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include <sh_stack.h>
|
#include <sh_stack.h>
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include <sh_string.h>
|
#include <sh_string.h>
|
||||||
|
#include "sm_memtable.h"
|
||||||
#include "sm_globals.h"
|
#include "sm_globals.h"
|
||||||
|
|
||||||
using namespace SourceMod;
|
using namespace SourceMod;
|
||||||
|
|||||||
+46
-26
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -34,12 +34,11 @@
|
|||||||
#include "MenuStyle_Base.h"
|
#include "MenuStyle_Base.h"
|
||||||
#include "PlayerManager.h"
|
#include "PlayerManager.h"
|
||||||
#include "MenuManager.h"
|
#include "MenuManager.h"
|
||||||
|
#include "HandleSys.h"
|
||||||
#include "CellRecipientFilter.h"
|
#include "CellRecipientFilter.h"
|
||||||
#if defined MENU_DEBUG
|
#if defined MENU_DEBUG
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#endif
|
#endif
|
||||||
#include "logic_bridge.h"
|
|
||||||
#include "AutoHandleRooter.h"
|
|
||||||
|
|
||||||
BaseMenuStyle::BaseMenuStyle() : m_WatchList(256), m_hHandle(BAD_HANDLE)
|
BaseMenuStyle::BaseMenuStyle() : m_WatchList(256), m_hHandle(BAD_HANDLE)
|
||||||
{
|
{
|
||||||
@@ -338,8 +337,7 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
|
|||||||
#endif
|
#endif
|
||||||
0,
|
0,
|
||||||
PITCH_NORM,
|
PITCH_NORM,
|
||||||
#if SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS \
|
#if SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_TF2
|
||||||
|| SOURCE_ENGINE == SE_SDK2013 || SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_TF2
|
|
||||||
0,
|
0,
|
||||||
#endif
|
#endif
|
||||||
&pos);
|
&pos);
|
||||||
@@ -605,7 +603,7 @@ bool BaseMenuStyle::RedoClientMenu(int client, ItemOrder order)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CBaseMenu::CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner) :
|
CBaseMenu::CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner) :
|
||||||
m_pStyle(pStyle), m_Pagination(7), m_bShouldDelete(false), m_bCancelling(false),
|
m_pStyle(pStyle), m_Strings(512), m_Pagination(7), m_bShouldDelete(false), m_bCancelling(false),
|
||||||
m_pOwner(pOwner ? pOwner : g_pCoreIdent), m_bDeleting(false), m_bWillFreeHandle(false),
|
m_pOwner(pOwner ? pOwner : g_pCoreIdent), m_bDeleting(false), m_bWillFreeHandle(false),
|
||||||
m_hHandle(BAD_HANDLE), m_pHandler(pHandler), m_nFlags(MENUFLAG_BUTTON_EXIT)
|
m_hHandle(BAD_HANDLE), m_pHandler(pHandler), m_nFlags(MENUFLAG_BUTTON_EXIT)
|
||||||
{
|
{
|
||||||
@@ -628,74 +626,94 @@ Handle_t CBaseMenu::GetHandle()
|
|||||||
bool CBaseMenu::AppendItem(const char *info, const ItemDrawInfo &draw)
|
bool CBaseMenu::AppendItem(const char *info, const ItemDrawInfo &draw)
|
||||||
{
|
{
|
||||||
if (m_Pagination == (unsigned)MENU_NO_PAGINATION
|
if (m_Pagination == (unsigned)MENU_NO_PAGINATION
|
||||||
&& m_items.length() >= m_pStyle->GetMaxPageItems())
|
&& m_items.size() >= m_pStyle->GetMaxPageItems())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CItem item;
|
CItem item;
|
||||||
|
|
||||||
item.info = info;
|
item.infoString = m_Strings.AddString(info);
|
||||||
if (draw.display)
|
if (draw.display)
|
||||||
item.display = new ke::AString(draw.display);
|
{
|
||||||
|
item.displayString = m_Strings.AddString(draw.display);
|
||||||
|
}
|
||||||
item.style = draw.style;
|
item.style = draw.style;
|
||||||
|
|
||||||
m_items.append(ke::Move(item));
|
m_items.push_back(item);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBaseMenu::InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw)
|
bool CBaseMenu::InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw)
|
||||||
{
|
{
|
||||||
if (m_Pagination == (unsigned)MENU_NO_PAGINATION &&
|
if (m_Pagination == (unsigned)MENU_NO_PAGINATION
|
||||||
m_items.length() >= m_pStyle->GetMaxPageItems())
|
&& m_items.size() >= m_pStyle->GetMaxPageItems())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position >= m_items.length())
|
if (position >= m_items.size())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
CItem item;
|
CItem item;
|
||||||
item.info = info;
|
item.infoString = m_Strings.AddString(info);
|
||||||
if (draw.display)
|
if (draw.display)
|
||||||
item.display = new ke::AString(draw.display);
|
{
|
||||||
|
item.displayString = m_Strings.AddString(draw.display);
|
||||||
|
}
|
||||||
item.style = draw.style;
|
item.style = draw.style;
|
||||||
|
|
||||||
m_items.insert(position, ke::Move(item));
|
CVector<CItem>::iterator iter = m_items.iterAt(position);
|
||||||
|
m_items.insert(iter, item);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBaseMenu::RemoveItem(unsigned int position)
|
bool CBaseMenu::RemoveItem(unsigned int position)
|
||||||
{
|
{
|
||||||
if (position >= m_items.length())
|
if (position >= m_items.size())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_items.erase(m_items.iterAt(position));
|
||||||
|
|
||||||
|
if (m_items.size() == 0)
|
||||||
|
{
|
||||||
|
m_Strings.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
m_items.remove(position);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBaseMenu::RemoveAllItems()
|
void CBaseMenu::RemoveAllItems()
|
||||||
{
|
{
|
||||||
m_items.clear();
|
m_items.clear();
|
||||||
|
m_Strings.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CBaseMenu::GetItemInfo(unsigned int position, ItemDrawInfo *draw/* =NULL */)
|
const char *CBaseMenu::GetItemInfo(unsigned int position, ItemDrawInfo *draw/* =NULL */)
|
||||||
{
|
{
|
||||||
if (position >= m_items.length())
|
if (position >= m_items.size())
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (draw)
|
if (draw)
|
||||||
{
|
{
|
||||||
draw->display = m_items[position].display->chars();
|
draw->display = m_Strings.GetString(m_items[position].displayString);
|
||||||
draw->style = m_items[position].style;
|
draw->style = m_items[position].style;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_items[position].info.chars();
|
return m_Strings.GetString(m_items[position].infoString);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CBaseMenu::GetItemCount()
|
unsigned int CBaseMenu::GetItemCount()
|
||||||
{
|
{
|
||||||
return m_items.length();
|
return m_items.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBaseMenu::SetPagination(unsigned int itemsPerPage)
|
bool CBaseMenu::SetPagination(unsigned int itemsPerPage)
|
||||||
@@ -728,12 +746,12 @@ IMenuStyle *CBaseMenu::GetDrawStyle()
|
|||||||
|
|
||||||
void CBaseMenu::SetDefaultTitle(const char *message)
|
void CBaseMenu::SetDefaultTitle(const char *message)
|
||||||
{
|
{
|
||||||
m_Title = message;
|
m_Title.assign(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CBaseMenu::GetDefaultTitle()
|
const char *CBaseMenu::GetDefaultTitle()
|
||||||
{
|
{
|
||||||
return m_Title.chars();
|
return m_Title.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBaseMenu::Cancel()
|
void CBaseMenu::Cancel()
|
||||||
@@ -800,7 +818,7 @@ void CBaseMenu::InternalDelete()
|
|||||||
|
|
||||||
m_hHandle = BAD_HANDLE;
|
m_hHandle = BAD_HANDLE;
|
||||||
m_bDeleting = true;
|
m_bDeleting = true;
|
||||||
handlesys->FreeHandle(hndl, &sec);
|
g_HandleSys.FreeHandle(hndl, &sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pHandler->OnMenuDestroy(this);
|
m_pHandler->OnMenuDestroy(this);
|
||||||
@@ -825,5 +843,7 @@ IMenuHandler *CBaseMenu::GetHandler()
|
|||||||
|
|
||||||
unsigned int CBaseMenu::GetBaseMemUsage()
|
unsigned int CBaseMenu::GetBaseMemUsage()
|
||||||
{
|
{
|
||||||
return m_Title.length() + (m_items.length() * sizeof(CItem));
|
return m_Title.size()
|
||||||
|
+ m_Strings.GetMemTable()->GetMemUsage()
|
||||||
|
+ (m_items.size() * sizeof(CItem));
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-28
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -34,46 +34,29 @@
|
|||||||
|
|
||||||
#include <IMenuManager.h>
|
#include <IMenuManager.h>
|
||||||
#include <IPlayerHelpers.h>
|
#include <IPlayerHelpers.h>
|
||||||
#include <am-autoptr.h>
|
#include <sh_string.h>
|
||||||
#include <am-string.h>
|
#include <sh_vector.h>
|
||||||
#include <am-vector.h>
|
#include "sm_memtable.h"
|
||||||
#include "sm_fastlink.h"
|
#include "sm_fastlink.h"
|
||||||
|
|
||||||
using namespace SourceMod;
|
using namespace SourceMod;
|
||||||
|
using namespace SourceHook;
|
||||||
|
|
||||||
class CItem
|
class CItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CItem()
|
CItem()
|
||||||
{
|
{
|
||||||
|
infoString = -1;
|
||||||
|
displayString = -1;
|
||||||
style = 0;
|
style = 0;
|
||||||
access = 0;
|
access = 0;
|
||||||
}
|
}
|
||||||
CItem(CItem &&other)
|
|
||||||
: info(ke::Move(other.info)),
|
|
||||||
display(ke::Move(other.display))
|
|
||||||
{
|
|
||||||
style = other.style;
|
|
||||||
access = other.access;
|
|
||||||
}
|
|
||||||
CItem & operator =(CItem &&other)
|
|
||||||
{
|
|
||||||
info = ke::Move(other.info);
|
|
||||||
display = ke::Move(other.display);
|
|
||||||
style = other.style;
|
|
||||||
access = other.access;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ke::AString info;
|
int infoString;
|
||||||
ke::AutoPtr<ke::AString> display;
|
int displayString;
|
||||||
unsigned int style;
|
unsigned int style;
|
||||||
unsigned int access;
|
unsigned int access;
|
||||||
|
|
||||||
private:
|
|
||||||
CItem(const CItem &other) = delete;
|
|
||||||
CItem &operator =(const CItem &other) = delete;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CBaseMenuPlayer
|
class CBaseMenuPlayer
|
||||||
@@ -156,10 +139,11 @@ public:
|
|||||||
private:
|
private:
|
||||||
void InternalDelete();
|
void InternalDelete();
|
||||||
protected:
|
protected:
|
||||||
ke::AString m_Title;
|
String m_Title;
|
||||||
IMenuStyle *m_pStyle;
|
IMenuStyle *m_pStyle;
|
||||||
|
BaseStringTable m_Strings;
|
||||||
unsigned int m_Pagination;
|
unsigned int m_Pagination;
|
||||||
ke::Vector<CItem> m_items;
|
CVector<CItem> m_items;
|
||||||
bool m_bShouldDelete;
|
bool m_bShouldDelete;
|
||||||
bool m_bCancelling;
|
bool m_bCancelling;
|
||||||
IdentityToken_t *m_pOwner;
|
IdentityToken_t *m_pOwner;
|
||||||
|
|||||||
+19
-13
@@ -83,10 +83,6 @@ void CRadioStyle::OnSourceModLevelChange(const char *mapName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_bRadioInit = true;
|
g_bRadioInit = true;
|
||||||
|
|
||||||
// Always register the style. Use IsSupported() to check for validity before use.
|
|
||||||
g_Menus.AddStyle(this);
|
|
||||||
|
|
||||||
const char *msg = g_pGameConf->GetKeyValue("HudRadioMenuMsg");
|
const char *msg = g_pGameConf->GetKeyValue("HudRadioMenuMsg");
|
||||||
if (!msg || msg[0] == '\0')
|
if (!msg || msg[0] == '\0')
|
||||||
{
|
{
|
||||||
@@ -122,6 +118,7 @@ void CRadioStyle::OnSourceModLevelChange(const char *mapName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_Menus.AddStyle(this);
|
||||||
g_Menus.SetDefaultStyle(this);
|
g_Menus.SetDefaultStyle(this);
|
||||||
|
|
||||||
g_UserMsgs.HookUserMessage(g_ShowMenuId, this, false);
|
g_UserMsgs.HookUserMessage(g_ShowMenuId, this, false);
|
||||||
@@ -174,7 +171,7 @@ void CRadioStyle::OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFil
|
|||||||
{
|
{
|
||||||
int count = pFilter->GetRecipientCount();
|
int count = pFilter->GetRecipientCount();
|
||||||
|
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
||||||
int c = ((CCSUsrMsg_ShowMenu &)msg).display_time();
|
int c = ((CCSUsrMsg_ShowMenu &)msg).display_time();
|
||||||
#else
|
#else
|
||||||
bf_read br(bf->GetBasePointer(), 3);
|
bf_read br(bf->GetBasePointer(), 3);
|
||||||
@@ -258,6 +255,15 @@ CRadioDisplay *CRadioStyle::MakeRadioDisplay(CRadioMenu *menu)
|
|||||||
return display;
|
return display;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMenuPanel *CRadioStyle::MakeRadioDisplay(const char *str, int keys)
|
||||||
|
{
|
||||||
|
CRadioDisplay *pPanel = MakeRadioDisplay(NULL);
|
||||||
|
|
||||||
|
pPanel->DirectSet(str, keys);
|
||||||
|
|
||||||
|
return pPanel;
|
||||||
|
}
|
||||||
|
|
||||||
void CRadioStyle::FreeRadioDisplay(CRadioDisplay *display)
|
void CRadioStyle::FreeRadioDisplay(CRadioDisplay *display)
|
||||||
{
|
{
|
||||||
m_FreeDisplays.push(display);
|
m_FreeDisplays.push(display);
|
||||||
@@ -324,12 +330,11 @@ void CRadioDisplay::Reset()
|
|||||||
keys = 0;
|
keys = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CRadioDisplay::DirectSet(const char *str)
|
void CRadioDisplay::DirectSet(const char *str, int keymap)
|
||||||
{
|
{
|
||||||
m_Title.clear();
|
m_Title.clear();
|
||||||
m_BufferText.assign(str);
|
m_BufferText.assign(str);
|
||||||
|
keys = keymap;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CRadioDisplay::GetCurrentKey()
|
unsigned int CRadioDisplay::GetCurrentKey()
|
||||||
@@ -450,7 +455,7 @@ void CRadioMenuPlayer::Radio_Init(int keys, const char *title, const char *text)
|
|||||||
{
|
{
|
||||||
if (title[0] != '\0')
|
if (title[0] != '\0')
|
||||||
{
|
{
|
||||||
display_len = ke::SafeSprintf(display_pkt,
|
display_len = UTIL_Format(display_pkt,
|
||||||
sizeof(display_pkt),
|
sizeof(display_pkt),
|
||||||
"%s\n%s",
|
"%s\n%s",
|
||||||
title,
|
title,
|
||||||
@@ -458,8 +463,9 @@ void CRadioMenuPlayer::Radio_Init(int keys, const char *title, const char *text)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
display_len = ke::SafeStrcpy(display_pkt,
|
display_len = UTIL_Format(display_pkt,
|
||||||
sizeof(display_pkt),
|
sizeof(display_pkt),
|
||||||
|
"%s",
|
||||||
text);
|
text);
|
||||||
}
|
}
|
||||||
display_keys = keys;
|
display_keys = keys;
|
||||||
@@ -467,7 +473,7 @@ void CRadioMenuPlayer::Radio_Init(int keys, const char *title, const char *text)
|
|||||||
|
|
||||||
void CRadioMenuPlayer::Radio_Refresh()
|
void CRadioMenuPlayer::Radio_Refresh()
|
||||||
{
|
{
|
||||||
cell_t players[1] = { (cell_t)m_index };
|
cell_t players[1] = {m_index};
|
||||||
char *ptr = display_pkt;
|
char *ptr = display_pkt;
|
||||||
char save = 0;
|
char save = 0;
|
||||||
size_t len = display_len;
|
size_t len = display_len;
|
||||||
@@ -483,7 +489,8 @@ void CRadioMenuPlayer::Radio_Refresh()
|
|||||||
time = menuHoldTime - (unsigned int)(gpGlobals->curtime - menuStartTime);
|
time = menuHoldTime - (unsigned int)(gpGlobals->curtime - menuStartTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
||||||
|
// If or when we need to support multiple games per engine with this, we can switch to reflection
|
||||||
// TODO: find what happens past 240 on CS:GO
|
// TODO: find what happens past 240 on CS:GO
|
||||||
CCSUsrMsg_ShowMenu *msg = (CCSUsrMsg_ShowMenu *)g_UserMsgs.StartProtobufMessage(g_ShowMenuId, players, 1, USERMSG_BLOCKHOOKS);
|
CCSUsrMsg_ShowMenu *msg = (CCSUsrMsg_ShowMenu *)g_UserMsgs.StartProtobufMessage(g_ShowMenuId, players, 1, USERMSG_BLOCKHOOKS);
|
||||||
msg->set_bits_valid_slots(display_keys);
|
msg->set_bits_valid_slots(display_keys);
|
||||||
@@ -586,7 +593,6 @@ bool CRadioMenu::DisplayAtItem(int client,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoHandleRooter ahr(this->GetHandle());
|
|
||||||
return g_RadioMenuStyle.DoClientMenu(client,
|
return g_RadioMenuStyle.DoClientMenu(client,
|
||||||
this,
|
this,
|
||||||
start_item,
|
start_item,
|
||||||
|
|||||||
@@ -41,8 +41,6 @@
|
|||||||
#include "sm_fastlink.h"
|
#include "sm_fastlink.h"
|
||||||
#include <sh_stack.h>
|
#include <sh_stack.h>
|
||||||
#include <compat_wrappers.h>
|
#include <compat_wrappers.h>
|
||||||
#include "logic/common_logic.h"
|
|
||||||
#include "AutoHandleRooter.h"
|
|
||||||
|
|
||||||
using namespace SourceMod;
|
using namespace SourceMod;
|
||||||
|
|
||||||
@@ -103,6 +101,7 @@ public:
|
|||||||
CRadioDisplay *MakeRadioDisplay(CRadioMenu *menu=NULL);
|
CRadioDisplay *MakeRadioDisplay(CRadioMenu *menu=NULL);
|
||||||
void FreeRadioDisplay(CRadioDisplay *display);
|
void FreeRadioDisplay(CRadioDisplay *display);
|
||||||
CRadioMenuPlayer *GetRadioMenuPlayer(int client);
|
CRadioMenuPlayer *GetRadioMenuPlayer(int client);
|
||||||
|
IMenuPanel *MakeRadioDisplay(const char *str, int keys);
|
||||||
private:
|
private:
|
||||||
CRadioMenuPlayer *m_players;
|
CRadioMenuPlayer *m_players;
|
||||||
CStack<CRadioDisplay *> m_FreeDisplays;
|
CStack<CRadioDisplay *> m_FreeDisplays;
|
||||||
@@ -130,7 +129,8 @@ public: //IMenuPanel
|
|||||||
bool SetCurrentKey(unsigned int key);
|
bool SetCurrentKey(unsigned int key);
|
||||||
int GetAmountRemaining();
|
int GetAmountRemaining();
|
||||||
unsigned int GetApproxMemUsage();
|
unsigned int GetApproxMemUsage();
|
||||||
bool DirectSet(const char *str);
|
public:
|
||||||
|
void DirectSet(const char *str, int keymap);
|
||||||
private:
|
private:
|
||||||
String m_BufferText;
|
String m_BufferText;
|
||||||
String m_Title;
|
String m_Title;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -66,14 +66,14 @@ bool ValveMenuStyle::OnClientCommand(int client, const char *cmdname, const CCom
|
|||||||
void ValveMenuStyle::OnSourceModAllInitialized()
|
void ValveMenuStyle::OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
g_Players.AddClientListener(this);
|
g_Players.AddClientListener(this);
|
||||||
SH_ADD_HOOK(IServerPluginHelpers, CreateMessage, serverpluginhelpers, SH_MEMBER(this, &ValveMenuStyle::HookCreateMessage), false);
|
SH_ADD_HOOK_MEMFUNC(IServerPluginHelpers, CreateMessage, serverpluginhelpers, this, &ValveMenuStyle::HookCreateMessage, false);
|
||||||
g_pSPHCC = SH_GET_CALLCLASS(serverpluginhelpers);
|
g_pSPHCC = SH_GET_CALLCLASS(serverpluginhelpers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValveMenuStyle::OnSourceModShutdown()
|
void ValveMenuStyle::OnSourceModShutdown()
|
||||||
{
|
{
|
||||||
SH_RELEASE_CALLCLASS(g_pSPHCC);
|
SH_RELEASE_CALLCLASS(g_pSPHCC);
|
||||||
SH_REMOVE_HOOK(IServerPluginHelpers, CreateMessage, serverpluginhelpers, SH_MEMBER(this, &ValveMenuStyle::HookCreateMessage), false);
|
SH_REMOVE_HOOK_MEMFUNC(IServerPluginHelpers, CreateMessage, serverpluginhelpers, this, &ValveMenuStyle::HookCreateMessage, false);
|
||||||
g_Players.RemoveClientListener(this);
|
g_Players.RemoveClientListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,7 +293,7 @@ unsigned int CValveMenuDisplay::DrawItem(const ItemDrawInfo &item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char buffer[255];
|
char buffer[255];
|
||||||
ke::SafeSprintf(buffer, sizeof(buffer), "%d. %s", m_NextPos, item.display);
|
UTIL_Format(buffer, sizeof(buffer), "%d. %s", m_NextPos, item.display);
|
||||||
|
|
||||||
KeyValues *ki = m_pKv->FindKey(g_OptionNumTable[m_NextPos], true);
|
KeyValues *ki = m_pKv->FindKey(g_OptionNumTable[m_NextPos], true);
|
||||||
ki->SetString("command", g_OptionCmdTable[m_NextPos]);
|
ki->SetString("command", g_OptionCmdTable[m_NextPos]);
|
||||||
@@ -378,7 +378,7 @@ bool CValveMenu::SetExtOption(MenuOption option, const void *valuePtr)
|
|||||||
{
|
{
|
||||||
if (option == MenuOption_IntroMessage)
|
if (option == MenuOption_IntroMessage)
|
||||||
{
|
{
|
||||||
ke::SafeStrcpy(m_IntroMsg, sizeof(m_IntroMsg), (const char *)valuePtr);
|
strncopy(m_IntroMsg, (const char *)valuePtr, sizeof(m_IntroMsg));
|
||||||
return true;
|
return true;
|
||||||
} else if (option == MenuOption_IntroColor) {
|
} else if (option == MenuOption_IntroColor) {
|
||||||
unsigned int *array = (unsigned int *)valuePtr;
|
unsigned int *array = (unsigned int *)valuePtr;
|
||||||
@@ -404,7 +404,6 @@ bool CValveMenu::DisplayAtItem(int client,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoHandleRooter ahr(this->GetHandle());
|
|
||||||
return g_ValveMenuStyle.DoClientMenu(client, this, start_item, alt_handler ? alt_handler : m_pHandler, time);
|
return g_ValveMenuStyle.DoClientMenu(client, this, start_item, alt_handler ? alt_handler : m_pHandler, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,6 @@
|
|||||||
#include "KeyValues.h"
|
#include "KeyValues.h"
|
||||||
#include "sm_fastlink.h"
|
#include "sm_fastlink.h"
|
||||||
#include <compat_wrappers.h>
|
#include <compat_wrappers.h>
|
||||||
#include "logic/common_logic.h"
|
|
||||||
#include "AutoHandleRooter.h"
|
|
||||||
|
|
||||||
using namespace SourceMod;
|
using namespace SourceMod;
|
||||||
|
|
||||||
@@ -77,7 +75,6 @@ public: //IMenuStyle
|
|||||||
IBaseMenu *CreateMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner);
|
IBaseMenu *CreateMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner);
|
||||||
unsigned int GetMaxPageItems();
|
unsigned int GetMaxPageItems();
|
||||||
unsigned int GetApproxMemUsage();
|
unsigned int GetApproxMemUsage();
|
||||||
bool IsSupported() { return true; }
|
|
||||||
private:
|
private:
|
||||||
void HookCreateMessage(edict_t *pEdict, DIALOG_TYPE type, KeyValues *kv, IServerPluginCallbacks *plugin);
|
void HookCreateMessage(edict_t *pEdict, DIALOG_TYPE type, KeyValues *kv, IServerPluginCallbacks *plugin);
|
||||||
private:
|
private:
|
||||||
@@ -108,7 +105,6 @@ public:
|
|||||||
bool SetCurrentKey(unsigned int key);
|
bool SetCurrentKey(unsigned int key);
|
||||||
int GetAmountRemaining();
|
int GetAmountRemaining();
|
||||||
unsigned int GetApproxMemUsage();
|
unsigned int GetApproxMemUsage();
|
||||||
bool DirectSet(const char *str) { return false; }
|
|
||||||
private:
|
private:
|
||||||
KeyValues *m_pKv;
|
KeyValues *m_pKv;
|
||||||
unsigned int m_NextPos;
|
unsigned int m_NextPos;
|
||||||
|
|||||||
@@ -0,0 +1,379 @@
|
|||||||
|
/**
|
||||||
|
* vim: set ts=4 :
|
||||||
|
* =============================================================================
|
||||||
|
* SourcePawn
|
||||||
|
* Copyright (C) 2004-2009 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 "NativeInvoker.h"
|
||||||
|
#include "ShareSys.h"
|
||||||
|
|
||||||
|
NativeInterface g_NInvoke;
|
||||||
|
|
||||||
|
NativeInvoker::NativeInvoker()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NativeInvoker::~NativeInvoker()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *NativeInterface::GetInterfaceName()
|
||||||
|
{
|
||||||
|
return SMINTERFACE_NINVOKE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int NativeInterface::GetInterfaceVersion()
|
||||||
|
{
|
||||||
|
return SMINTERFACE_NINVOKE_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeInterface::OnSourceModAllInitialized()
|
||||||
|
{
|
||||||
|
g_ShareSys.AddInterface(NULL, &g_NInvoke);
|
||||||
|
}
|
||||||
|
|
||||||
|
IPluginRuntime *NativeInterface::CreateRuntime(const char *name, size_t bytes)
|
||||||
|
{
|
||||||
|
return g_pSourcePawn2->CreateEmptyRuntime(name, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
INativeInvoker *NativeInterface::CreateInvoker()
|
||||||
|
{
|
||||||
|
return new NativeInvoker();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NativeInvoker::Start(IPluginContext *pContext, const char *name)
|
||||||
|
{
|
||||||
|
NativeEntry *entry;
|
||||||
|
|
||||||
|
entry = g_ShareSys.FindNative(name);
|
||||||
|
if (entry == NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
native = NULL;
|
||||||
|
if (entry->replacement.owner != NULL)
|
||||||
|
{
|
||||||
|
native = entry->replacement.func;
|
||||||
|
}
|
||||||
|
else if (entry->owner != NULL)
|
||||||
|
{
|
||||||
|
native = entry->func;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (native == NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->pContext = pContext;
|
||||||
|
|
||||||
|
m_curparam = 0;
|
||||||
|
m_errorstate = SP_ERROR_NONE;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
cell_t NativeInvoker::PushCell(cell_t cell)
|
||||||
|
{
|
||||||
|
if (m_curparam >= SP_MAX_EXEC_PARAMS)
|
||||||
|
{
|
||||||
|
return SetError(SP_ERROR_PARAMS_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_info[m_curparam].marked = false;
|
||||||
|
m_params[m_curparam] = cell;
|
||||||
|
m_curparam++;
|
||||||
|
|
||||||
|
return SP_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NativeInvoker::PushCellByRef(cell_t *cell, int flags)
|
||||||
|
{
|
||||||
|
return PushArray(cell, 1, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
int NativeInvoker::PushFloat(float number)
|
||||||
|
{
|
||||||
|
cell_t val = *(cell_t *)&number;
|
||||||
|
|
||||||
|
return PushCell(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
int NativeInvoker::PushFloatByRef(float *number, int flags)
|
||||||
|
{
|
||||||
|
return PushCellByRef((cell_t *)number, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
int NativeInvoker::PushArray(cell_t *inarray, unsigned int cells, int copyback)
|
||||||
|
{
|
||||||
|
if (m_curparam >= SP_MAX_EXEC_PARAMS)
|
||||||
|
{
|
||||||
|
return SetError(SP_ERROR_PARAMS_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamInfo *info = &m_info[m_curparam];
|
||||||
|
|
||||||
|
info->flags = inarray ? copyback : 0;
|
||||||
|
info->marked = true;
|
||||||
|
info->size = cells;
|
||||||
|
info->str.is_sz = false;
|
||||||
|
info->orig_addr = inarray;
|
||||||
|
|
||||||
|
m_curparam++;
|
||||||
|
|
||||||
|
return SP_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NativeInvoker::PushString(const char *string)
|
||||||
|
{
|
||||||
|
return _PushString(string, SM_PARAM_STRING_COPY, 0, strlen(string)+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int NativeInvoker::PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags)
|
||||||
|
{
|
||||||
|
return _PushString(buffer, sz_flags, cp_flags, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
int NativeInvoker::_PushString(const char *string, int sz_flags, int cp_flags, size_t len)
|
||||||
|
{
|
||||||
|
if (m_curparam >= SP_MAX_EXEC_PARAMS)
|
||||||
|
{
|
||||||
|
return SetError(SP_ERROR_PARAMS_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamInfo *info = &m_info[m_curparam];
|
||||||
|
|
||||||
|
info->marked = true;
|
||||||
|
info->orig_addr = (cell_t *)string;
|
||||||
|
info->flags = cp_flags;
|
||||||
|
info->size = len;
|
||||||
|
info->str.sz_flags = sz_flags;
|
||||||
|
info->str.is_sz = true;
|
||||||
|
|
||||||
|
m_curparam++;
|
||||||
|
|
||||||
|
return SP_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeInvoker::Cancel()
|
||||||
|
{
|
||||||
|
if (pContext == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_errorstate = SP_ERROR_NONE;
|
||||||
|
m_curparam = 0;
|
||||||
|
pContext = NULL;
|
||||||
|
native = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NativeInvoker::SetError(int err)
|
||||||
|
{
|
||||||
|
m_errorstate = err;
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NativeInvoker::Invoke(cell_t *result)
|
||||||
|
{
|
||||||
|
int err = SP_ERROR_NONE;
|
||||||
|
|
||||||
|
if (pContext == NULL)
|
||||||
|
{
|
||||||
|
return SP_ERROR_INVALID_NATIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_errorstate != SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
err = m_errorstate;
|
||||||
|
Cancel();
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
cell_t tresult;
|
||||||
|
|
||||||
|
if (result == NULL)
|
||||||
|
{
|
||||||
|
result = &tresult;
|
||||||
|
}
|
||||||
|
|
||||||
|
//This is for re-entrancy!
|
||||||
|
IPluginContext *ctx = pContext;
|
||||||
|
cell_t _temp_params[SP_MAX_EXEC_PARAMS + 1];
|
||||||
|
cell_t *temp_params = &_temp_params[1];
|
||||||
|
ParamInfo temp_info[SP_MAX_EXEC_PARAMS];
|
||||||
|
unsigned int numparams = m_curparam;
|
||||||
|
unsigned int i;
|
||||||
|
bool docopies = true;
|
||||||
|
|
||||||
|
if (numparams)
|
||||||
|
{
|
||||||
|
//Save the info locally, then reset it for re-entrant calls.
|
||||||
|
memcpy(temp_info, m_info, numparams * sizeof(ParamInfo));
|
||||||
|
}
|
||||||
|
m_curparam = 0;
|
||||||
|
pContext = NULL;
|
||||||
|
|
||||||
|
/* Initialize 0th parameter */
|
||||||
|
_temp_params[0] = numparams;
|
||||||
|
|
||||||
|
/* Browse the parameters and build arrays */
|
||||||
|
for (i = 0; i < numparams; i++)
|
||||||
|
{
|
||||||
|
/* Is this marked as an array? */
|
||||||
|
if (temp_info[i].marked)
|
||||||
|
{
|
||||||
|
if (!temp_info[i].str.is_sz)
|
||||||
|
{
|
||||||
|
/* Allocate a normal/generic array */
|
||||||
|
if ((err = ctx->HeapAlloc(temp_info[i].size,
|
||||||
|
&temp_info[i].local_addr,
|
||||||
|
&temp_info[i].phys_addr))
|
||||||
|
!= SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (temp_info[i].orig_addr)
|
||||||
|
{
|
||||||
|
memcpy(temp_info[i].phys_addr, temp_info[i].orig_addr, sizeof(cell_t) * temp_info[i].size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Calculate cells required for the string */
|
||||||
|
size_t cells = (temp_info[i].size + sizeof(cell_t) - 1) / sizeof(cell_t);
|
||||||
|
|
||||||
|
/* Allocate the buffer */
|
||||||
|
if ((err = ctx->HeapAlloc(cells,
|
||||||
|
&temp_info[i].local_addr,
|
||||||
|
&temp_info[i].phys_addr))
|
||||||
|
!= SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* Copy original string if necessary */
|
||||||
|
if ((temp_info[i].str.sz_flags & SM_PARAM_STRING_COPY) && (temp_info[i].orig_addr != NULL))
|
||||||
|
{
|
||||||
|
/* Cut off UTF-8 properly */
|
||||||
|
if (temp_info[i].str.sz_flags & SM_PARAM_STRING_UTF8)
|
||||||
|
{
|
||||||
|
if ((err = ctx->StringToLocalUTF8(temp_info[i].local_addr,
|
||||||
|
temp_info[i].size,
|
||||||
|
(const char *)temp_info[i].orig_addr,
|
||||||
|
NULL))
|
||||||
|
!= SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Copy a binary blob */
|
||||||
|
else if (temp_info[i].str.sz_flags & SM_PARAM_STRING_BINARY)
|
||||||
|
{
|
||||||
|
memmove(temp_info[i].phys_addr, temp_info[i].orig_addr, temp_info[i].size);
|
||||||
|
}
|
||||||
|
/* Copy ASCII characters */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((err = ctx->StringToLocal(temp_info[i].local_addr,
|
||||||
|
temp_info[i].size,
|
||||||
|
(const char *)temp_info[i].orig_addr))
|
||||||
|
!= SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} /* End array/string calculation */
|
||||||
|
/* Update the pushed parameter with the byref local address */
|
||||||
|
temp_params[i] = temp_info[i].local_addr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Just copy the value normally */
|
||||||
|
temp_params[i] = m_params[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make the call if we can */
|
||||||
|
if (err == SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
*result = native(ctx, _temp_params);
|
||||||
|
if (ctx->GetLastNativeError() != SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
docopies = false;
|
||||||
|
ctx->ClearLastNativeError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
docopies = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* i should be equal to the last valid parameter + 1 */
|
||||||
|
while (i--)
|
||||||
|
{
|
||||||
|
if (!temp_info[i].marked)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (docopies && (temp_info[i].flags & SM_PARAM_COPYBACK))
|
||||||
|
{
|
||||||
|
if (temp_info[i].orig_addr)
|
||||||
|
{
|
||||||
|
if (temp_info[i].str.is_sz)
|
||||||
|
{
|
||||||
|
memcpy(temp_info[i].orig_addr, temp_info[i].phys_addr, temp_info[i].size);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (temp_info[i].size == 1)
|
||||||
|
{
|
||||||
|
*temp_info[i].orig_addr = *(temp_info[i].phys_addr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(temp_info[i].orig_addr,
|
||||||
|
temp_info[i].phys_addr,
|
||||||
|
temp_info[i].size * sizeof(cell_t));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((err = ctx->HeapPop(temp_info[i].local_addr)) != SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
/**
|
||||||
|
* vim: set ts=4 :
|
||||||
|
* =============================================================================
|
||||||
|
* SourceMod
|
||||||
|
* Copyright (C) 2004-2009 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_SOURCEMOD_NATIVE_INVOKER_H_
|
||||||
|
#define _INCLUDE_SOURCEMOD_NATIVE_INVOKER_H_
|
||||||
|
|
||||||
|
#include "sm_globals.h"
|
||||||
|
#include <INativeInvoker.h>
|
||||||
|
|
||||||
|
struct ParamInfo
|
||||||
|
{
|
||||||
|
int flags; /* Copy-back flags */
|
||||||
|
bool marked; /* Whether this is marked as being used */
|
||||||
|
cell_t local_addr; /* Local address to free */
|
||||||
|
cell_t *phys_addr; /* Physical address of our copy */
|
||||||
|
cell_t *orig_addr; /* Original address to copy back to */
|
||||||
|
ucell_t size; /* Size of array in bytes */
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
bool is_sz; /* is a string */
|
||||||
|
int sz_flags; /* has sz flags */
|
||||||
|
} str;
|
||||||
|
};
|
||||||
|
|
||||||
|
class NativeInvoker : public INativeInvoker
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NativeInvoker();
|
||||||
|
~NativeInvoker();
|
||||||
|
public: /* ICallable */
|
||||||
|
int PushCell(cell_t cell);
|
||||||
|
int PushCellByRef(cell_t *cell, int flags=SM_PARAM_COPYBACK);
|
||||||
|
int PushFloat(float number);
|
||||||
|
int PushFloatByRef(float *number, int flags=SM_PARAM_COPYBACK);
|
||||||
|
int PushArray(cell_t *inarray, unsigned int cells, int flags=0);
|
||||||
|
int PushString(const char *string);
|
||||||
|
int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags);
|
||||||
|
void Cancel();
|
||||||
|
public: /* INativeInvoker */
|
||||||
|
bool Start(IPluginContext *pContext, const char *name);
|
||||||
|
int Invoke(cell_t *result);
|
||||||
|
private:
|
||||||
|
int _PushString(const char *string, int sz_flags, int cp_flags, size_t len);
|
||||||
|
int SetError(int err);
|
||||||
|
private:
|
||||||
|
IPluginContext *pContext;
|
||||||
|
SPVM_NATIVE_FUNC native;
|
||||||
|
cell_t m_params[SP_MAX_EXEC_PARAMS];
|
||||||
|
ParamInfo m_info[SP_MAX_EXEC_PARAMS];
|
||||||
|
unsigned int m_curparam;
|
||||||
|
int m_errorstate;
|
||||||
|
};
|
||||||
|
|
||||||
|
class NativeInterface :
|
||||||
|
public INativeInterface,
|
||||||
|
public SMGlobalClass
|
||||||
|
{
|
||||||
|
public: /* SMGlobalClass */
|
||||||
|
void OnSourceModAllInitialized();
|
||||||
|
public: /* SMInterface */
|
||||||
|
unsigned int GetInterfaceVersion();
|
||||||
|
const char *GetInterfaceName();
|
||||||
|
public: /* INativeInvoker */
|
||||||
|
IPluginRuntime *CreateRuntime(const char *name, size_t bytes);
|
||||||
|
INativeInvoker *CreateInvoker();
|
||||||
|
};
|
||||||
|
|
||||||
|
extern NativeInterface g_NInvoke;
|
||||||
|
|
||||||
|
#endif /* _INCLUDE_SOURCEMOD_NATIVE_INVOKER_H_ */
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
#include "NativeOwner.h"
|
||||||
|
#include "ShareSys.h"
|
||||||
|
#include "PluginSys.h"
|
||||||
|
|
||||||
|
CNativeOwner::CNativeOwner() : m_nMarkSerial(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::SetMarkSerial(unsigned int serial)
|
||||||
|
{
|
||||||
|
m_nMarkSerial = serial;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CNativeOwner::GetMarkSerial()
|
||||||
|
{
|
||||||
|
return m_nMarkSerial;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::AddDependent(CPlugin *pPlugin)
|
||||||
|
{
|
||||||
|
m_Dependents.push_back(pPlugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::AddWeakRef(const WeakNative & ref)
|
||||||
|
{
|
||||||
|
m_WeakRefs.push_back(ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::AddNatives(const sp_nativeinfo_t *natives)
|
||||||
|
{
|
||||||
|
NativeEntry *pEntry;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; natives[i].func != NULL && natives[i].name != NULL; i++)
|
||||||
|
{
|
||||||
|
if ((pEntry = g_ShareSys.AddNativeToCache(this, &natives[i])) == NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Natives.push_back(pEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::PropogateMarkSerial(unsigned int serial)
|
||||||
|
{
|
||||||
|
CNativeOwner *pOwner;
|
||||||
|
List<CPlugin *>::iterator iter;
|
||||||
|
|
||||||
|
for (iter = m_Dependents.begin();
|
||||||
|
iter != m_Dependents.end();
|
||||||
|
iter++)
|
||||||
|
{
|
||||||
|
pOwner = (*iter);
|
||||||
|
pOwner->SetMarkSerial(serial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::UnbindWeakRef(const WeakNative & ref)
|
||||||
|
{
|
||||||
|
sp_native_t *native;
|
||||||
|
IPluginContext *pContext;
|
||||||
|
|
||||||
|
pContext = ref.pl->GetBaseContext();
|
||||||
|
if ((pContext->GetNativeByIndex(ref.idx, &native)) == SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
/* If there is no reference, the native must be unbound */
|
||||||
|
if (ref.entry == NULL)
|
||||||
|
{
|
||||||
|
native->status = SP_NATIVE_UNBOUND;
|
||||||
|
native->pfn = NULL;
|
||||||
|
}
|
||||||
|
/* If we've cached a reference, it's a core native we can
|
||||||
|
* rebind back to its original (this was a replacement).
|
||||||
|
*/
|
||||||
|
else
|
||||||
|
{
|
||||||
|
native->pfn = ref.entry->func;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::DropEverything()
|
||||||
|
{
|
||||||
|
NativeEntry *pEntry;
|
||||||
|
List<WeakNative>::iterator iter;
|
||||||
|
List<NativeEntry *>::iterator ntv_iter;
|
||||||
|
|
||||||
|
/* Unbind and remove all weak references to us */
|
||||||
|
iter = m_WeakRefs.begin();
|
||||||
|
while (iter != m_WeakRefs.end())
|
||||||
|
{
|
||||||
|
UnbindWeakRef((*iter));
|
||||||
|
iter = m_WeakRefs.erase(iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Unmark our replacement natives */
|
||||||
|
ntv_iter = m_ReplacedNatives.begin();
|
||||||
|
while (ntv_iter != m_ReplacedNatives.end())
|
||||||
|
{
|
||||||
|
pEntry = (*ntv_iter);
|
||||||
|
pEntry->replacement.func = NULL;
|
||||||
|
pEntry->replacement.owner = NULL;
|
||||||
|
ntv_iter = m_ReplacedNatives.erase(ntv_iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Strip all of our natives from the cache */
|
||||||
|
ntv_iter = m_Natives.begin();
|
||||||
|
while (ntv_iter != m_Natives.end())
|
||||||
|
{
|
||||||
|
g_ShareSys.ClearNativeFromCache(this, (*ntv_iter)->name);
|
||||||
|
ntv_iter = m_Natives.erase(ntv_iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::DropWeakRefsTo(CPlugin *pPlugin)
|
||||||
|
{
|
||||||
|
List<WeakNative>::iterator iter;
|
||||||
|
|
||||||
|
iter = m_WeakRefs.begin();
|
||||||
|
while (iter != m_WeakRefs.end())
|
||||||
|
{
|
||||||
|
WeakNative & ref = (*iter);
|
||||||
|
|
||||||
|
if (ref.pl == pPlugin)
|
||||||
|
{
|
||||||
|
iter = m_WeakRefs.erase(iter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::DropRefsTo(CPlugin *pPlugin)
|
||||||
|
{
|
||||||
|
m_Dependents.remove(pPlugin);
|
||||||
|
DropWeakRefsTo(pPlugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::AddReplacedNative(NativeEntry *pEntry)
|
||||||
|
{
|
||||||
|
m_ReplacedNatives.push_back(pEntry);
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
#ifndef _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
|
||||||
|
#define _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
|
||||||
|
|
||||||
|
#include <sp_vm_types.h>
|
||||||
|
#include <sh_list.h>
|
||||||
|
|
||||||
|
class CPlugin;
|
||||||
|
struct NativeEntry;
|
||||||
|
|
||||||
|
struct WeakNative
|
||||||
|
{
|
||||||
|
WeakNative(CPlugin *plugin, uint32_t index) :
|
||||||
|
pl(plugin), idx(index), entry(NULL)
|
||||||
|
{
|
||||||
|
pl = plugin;
|
||||||
|
idx = index;
|
||||||
|
}
|
||||||
|
WeakNative(CPlugin *plugin, uint32_t index, NativeEntry *pEntry) :
|
||||||
|
pl(plugin), idx(index), entry(pEntry)
|
||||||
|
{
|
||||||
|
pl = plugin;
|
||||||
|
idx = index;
|
||||||
|
}
|
||||||
|
CPlugin *pl;
|
||||||
|
uint32_t idx;
|
||||||
|
NativeEntry *entry;
|
||||||
|
};
|
||||||
|
|
||||||
|
using namespace SourceHook;
|
||||||
|
|
||||||
|
class CNativeOwner
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CNativeOwner();
|
||||||
|
public:
|
||||||
|
virtual void DropEverything();
|
||||||
|
public:
|
||||||
|
void AddNatives(const sp_nativeinfo_t *info);
|
||||||
|
public:
|
||||||
|
void SetMarkSerial(unsigned int serial);
|
||||||
|
unsigned int GetMarkSerial();
|
||||||
|
void PropogateMarkSerial(unsigned int serial);
|
||||||
|
public:
|
||||||
|
void AddDependent(CPlugin *pPlugin);
|
||||||
|
void AddWeakRef(const WeakNative & ref);
|
||||||
|
void DropRefsTo(CPlugin *pPlugin);
|
||||||
|
void AddReplacedNative(NativeEntry *pEntry);
|
||||||
|
private:
|
||||||
|
void DropWeakRefsTo(CPlugin *pPlugin);
|
||||||
|
void UnbindWeakRef(const WeakNative & ref);
|
||||||
|
protected:
|
||||||
|
List<CPlugin *> m_Dependents;
|
||||||
|
unsigned int m_nMarkSerial;
|
||||||
|
List<WeakNative> m_WeakRefs;
|
||||||
|
List<NativeEntry *> m_Natives;
|
||||||
|
List<NativeEntry *> m_ReplacedNatives;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //_INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
|
||||||
+29
-29
@@ -35,10 +35,7 @@
|
|||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include "sm_stringutil.h"
|
#include "sm_stringutil.h"
|
||||||
#include "sourcehook.h"
|
#include "sourcehook.h"
|
||||||
#include "logic_bridge.h"
|
#include "sm_srvcmds.h"
|
||||||
#include "compat_wrappers.h"
|
|
||||||
#include <time.h>
|
|
||||||
#include <bridge/include/ILogger.h>
|
|
||||||
|
|
||||||
NextMapManager g_NextMap;
|
NextMapManager g_NextMap;
|
||||||
|
|
||||||
@@ -50,14 +47,20 @@ SH_DECL_HOOK4_void(IVEngineServer, ChangeLevel, SH_NOATTRIB, 0, const char *, co
|
|||||||
|
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
|
SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
|
||||||
#else
|
#elif SOURCE_ENGINE == SE_DARKMESSIAH
|
||||||
SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
|
SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
|
||||||
|
#else
|
||||||
|
# if SH_IMPL_VERSION >= 4
|
||||||
|
extern int __SourceHook_FHAddConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0<void>);
|
||||||
|
# else
|
||||||
|
extern bool __SourceHook_FHAddConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0<void>);
|
||||||
|
#endif
|
||||||
|
extern bool __SourceHook_FHRemoveConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0<void>);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ConCommand *changeLevelCmd = NULL;
|
ConCommand *changeLevelCmd = NULL;
|
||||||
|
|
||||||
ConVar sm_nextmap("sm_nextmap", "", FCVAR_NOTIFY);
|
ConVar sm_nextmap("sm_nextmap", "", FCVAR_NOTIFY);
|
||||||
ConVar sm_maphistory_size("sm_maphistory_size", "20");
|
|
||||||
|
|
||||||
bool g_forcedChange = false;
|
bool g_forcedChange = false;
|
||||||
|
|
||||||
@@ -66,13 +69,13 @@ void NextMapManager::OnSourceModAllInitialized_Post()
|
|||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
SH_ADD_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false);
|
SH_ADD_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false);
|
||||||
#else
|
#else
|
||||||
SH_ADD_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false);
|
SH_ADD_HOOK_MEMFUNC(IVEngineServer, ChangeLevel, engine, this, &NextMapManager::HookChangeLevel, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ConCommand *pCmd = FindCommand("changelevel");
|
ConCommand *pCmd = FindCommand("changelevel");
|
||||||
if (pCmd != NULL)
|
if (pCmd != NULL)
|
||||||
{
|
{
|
||||||
SH_ADD_HOOK(ConCommand, Dispatch, pCmd, SH_STATIC(CmdChangeLevelCallback), false);
|
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pCmd, CmdChangeLevelCallback, false);
|
||||||
changeLevelCmd = pCmd;
|
changeLevelCmd = pCmd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,12 +85,12 @@ void NextMapManager::OnSourceModShutdown()
|
|||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
SH_REMOVE_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false);
|
SH_REMOVE_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false);
|
||||||
#else
|
#else
|
||||||
SH_REMOVE_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, ChangeLevel, engine, this, &NextMapManager::HookChangeLevel, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (changeLevelCmd != NULL)
|
if (changeLevelCmd != NULL)
|
||||||
{
|
{
|
||||||
SH_REMOVE_HOOK(ConCommand, Dispatch, changeLevelCmd, SH_STATIC(CmdChangeLevelCallback), false);
|
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, changeLevelCmd, CmdChangeLevelCallback, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceHook::List<MapChangeData *>::iterator iter;
|
SourceHook::List<MapChangeData *>::iterator iter;
|
||||||
@@ -125,7 +128,7 @@ void NextMapManager::HookChangeLevel(const char *map, const char *unknown, const
|
|||||||
{
|
{
|
||||||
if (g_forcedChange)
|
if (g_forcedChange)
|
||||||
{
|
{
|
||||||
logger->LogMessage("[SM] Changed map to \"%s\"", map);
|
g_Logger.LogMessage("[SM] Changed map to \"%s\"", map);
|
||||||
RETURN_META(MRES_IGNORED);
|
RETURN_META(MRES_IGNORED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,10 +139,10 @@ void NextMapManager::HookChangeLevel(const char *map, const char *unknown, const
|
|||||||
RETURN_META(MRES_IGNORED);
|
RETURN_META(MRES_IGNORED);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger->LogMessage("[SM] Changed map to \"%s\"", newmap);
|
g_Logger.LogMessage("[SM] Changed map to \"%s\"", newmap);
|
||||||
|
|
||||||
ke::SafeStrcpy(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), newmap);
|
UTIL_Format(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), newmap);
|
||||||
ke::SafeStrcpy(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "Normal level change");
|
UTIL_Format(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "Normal level change");
|
||||||
|
|
||||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||||
RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::ChangeLevel, (newmap, unknown));
|
RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::ChangeLevel, (newmap, unknown));
|
||||||
@@ -162,36 +165,33 @@ void NextMapManager::OnSourceModLevelChange( const char *mapName )
|
|||||||
{
|
{
|
||||||
/* Something intercepted the mapchange */
|
/* Something intercepted the mapchange */
|
||||||
char newReason[255];
|
char newReason[255];
|
||||||
ke::SafeSprintf(newReason, sizeof(newReason), "%s (Map overridden)", m_tempChangeInfo.m_changeReason);
|
UTIL_Format(newReason, sizeof(newReason), "%s (Map overridden)", m_tempChangeInfo.m_changeReason);
|
||||||
m_mapHistory.push_back(new MapChangeData(lastMap, newReason, m_tempChangeInfo.startTime));
|
m_mapHistory.push_back(new MapChangeData(lastMap, newReason, m_tempChangeInfo.startTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
int historydiff = sm_maphistory_size.GetInt();
|
/* TODO: Should this be customizable? */
|
||||||
if (historydiff > 0)
|
if (m_mapHistory.size() > 20)
|
||||||
{
|
{
|
||||||
historydiff -= m_mapHistory.size();
|
SourceHook::List<MapChangeData *>::iterator iter;
|
||||||
} else if (historydiff < 0)
|
iter = m_mapHistory.begin();
|
||||||
{
|
|
||||||
historydiff = (m_mapHistory.size() * -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (SourceHook::List<MapChangeData *>::iterator iter = m_mapHistory.begin(); historydiff++ < 0; iter = m_mapHistory.erase(iter))
|
|
||||||
{
|
|
||||||
delete (MapChangeData *)*iter;
|
delete (MapChangeData *)*iter;
|
||||||
|
|
||||||
|
m_mapHistory.erase(iter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_tempChangeInfo.m_mapName[0] ='\0';
|
m_tempChangeInfo.m_mapName[0] ='\0';
|
||||||
m_tempChangeInfo.m_changeReason[0] = '\0';
|
m_tempChangeInfo.m_changeReason[0] = '\0';
|
||||||
m_tempChangeInfo.startTime = time(NULL);
|
m_tempChangeInfo.startTime = time(NULL);
|
||||||
ke::SafeStrcpy(lastMap, sizeof(lastMap), mapName);
|
UTIL_Format(lastMap, sizeof(lastMap), "%s", mapName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NextMapManager::ForceChangeLevel( const char *mapName, const char* changeReason )
|
void NextMapManager::ForceChangeLevel( const char *mapName, const char* changeReason )
|
||||||
{
|
{
|
||||||
/* Store the mapname and reason */
|
/* Store the mapname and reason */
|
||||||
ke::SafeStrcpy(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), mapName);
|
UTIL_Format(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), "%s", mapName);
|
||||||
ke::SafeStrcpy(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), changeReason);
|
UTIL_Format(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "%s", changeReason);
|
||||||
|
|
||||||
/* Change level and skip our hook */
|
/* Change level and skip our hook */
|
||||||
g_forcedChange = true;
|
g_forcedChange = true;
|
||||||
@@ -221,7 +221,7 @@ void CmdChangeLevelCallback()
|
|||||||
|
|
||||||
if (g_NextMap.m_tempChangeInfo.m_mapName[0] == '\0')
|
if (g_NextMap.m_tempChangeInfo.m_mapName[0] == '\0')
|
||||||
{
|
{
|
||||||
ke::SafeStrcpy(g_NextMap.m_tempChangeInfo.m_mapName, sizeof(g_NextMap.m_tempChangeInfo.m_mapName), command.Arg(1));
|
UTIL_Format(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");
|
UTIL_Format(g_NextMap.m_tempChangeInfo.m_changeReason, sizeof(g_NextMap.m_tempChangeInfo.m_changeReason), "changelevel Command");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -33,17 +33,16 @@
|
|||||||
#define _INCLUDE_SOURCEMOD_NEXTMAP_H_
|
#define _INCLUDE_SOURCEMOD_NEXTMAP_H_
|
||||||
|
|
||||||
#include "sm_globals.h"
|
#include "sm_globals.h"
|
||||||
#include <eiface.h>
|
#include "eiface.h"
|
||||||
#include "sh_list.h"
|
#include "sh_list.h"
|
||||||
#include "sm_stringutil.h"
|
#include "sm_stringutil.h"
|
||||||
#include <amtl/am-string.h>
|
|
||||||
|
|
||||||
struct MapChangeData
|
struct MapChangeData
|
||||||
{
|
{
|
||||||
MapChangeData(const char *mapName, const char *changeReason, time_t time)
|
MapChangeData(const char *mapName, const char *changeReason, time_t time)
|
||||||
{
|
{
|
||||||
ke::SafeStrcpy(m_mapName, sizeof(m_mapName), mapName);
|
UTIL_Format(m_mapName, sizeof(m_mapName), mapName);
|
||||||
ke::SafeStrcpy(m_changeReason, sizeof(m_changeReason), changeReason);
|
UTIL_Format(m_changeReason, sizeof(m_changeReason), changeReason);
|
||||||
startTime = time;
|
startTime = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+223
-780
File diff suppressed because it is too large
Load Diff
+22
-61
@@ -2,7 +2,7 @@
|
|||||||
* vim: set ts=4 :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2015 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
@@ -38,19 +38,13 @@
|
|||||||
#include <IForwardSys.h>
|
#include <IForwardSys.h>
|
||||||
#include <IPlayerHelpers.h>
|
#include <IPlayerHelpers.h>
|
||||||
#include <IAdminSystem.h>
|
#include <IAdminSystem.h>
|
||||||
#include <ITranslator.h>
|
|
||||||
#include <sh_string.h>
|
#include <sh_string.h>
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include <sh_vector.h>
|
#include <sh_vector.h>
|
||||||
#include <am-string.h>
|
|
||||||
#include "ConVarManager.h"
|
#include "ConVarManager.h"
|
||||||
|
|
||||||
#include <steam/steamclientpublic.h>
|
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
|
|
||||||
class IClient;
|
|
||||||
|
|
||||||
#define PLAYER_LIFE_UNKNOWN 0
|
#define PLAYER_LIFE_UNKNOWN 0
|
||||||
#define PLAYER_LIFE_ALIVE 1
|
#define PLAYER_LIFE_ALIVE 1
|
||||||
#define PLAYER_LIFE_DEAD 2
|
#define PLAYER_LIFE_DEAD 2
|
||||||
@@ -77,10 +71,6 @@ public:
|
|||||||
const char *GetIPAddress();
|
const char *GetIPAddress();
|
||||||
const char *GetAuthString(bool validated = true);
|
const char *GetAuthString(bool validated = true);
|
||||||
unsigned int GetSteamAccountID(bool validated = true);
|
unsigned int GetSteamAccountID(bool validated = true);
|
||||||
const CSteamID &GetSteamId(bool validated = true);
|
|
||||||
uint64_t GetSteamId64(bool validated = true) { return GetSteamId(validated).ConvertToUint64(); }
|
|
||||||
const char *GetSteam2Id(bool validated = true);
|
|
||||||
const char *GetSteam3Id(bool validated = true);
|
|
||||||
edict_t *GetEdict();
|
edict_t *GetEdict();
|
||||||
bool IsInGame();
|
bool IsInGame();
|
||||||
bool WasCountedAsInGame();
|
bool WasCountedAsInGame();
|
||||||
@@ -100,58 +90,44 @@ public:
|
|||||||
bool RunAdminCacheChecks();
|
bool RunAdminCacheChecks();
|
||||||
void NotifyPostAdminChecks();
|
void NotifyPostAdminChecks();
|
||||||
unsigned int GetSerial();
|
unsigned int GetSerial();
|
||||||
int GetIndex() const;
|
|
||||||
void PrintToConsole(const char *pMsg);
|
|
||||||
void ClearAdmin();
|
|
||||||
public:
|
public:
|
||||||
void DoBasicAdminChecks();
|
void DoBasicAdminChecks();
|
||||||
void MarkAsBeingKicked();
|
void MarkAsBeingKicked();
|
||||||
int GetLifeState();
|
int GetLifeState();
|
||||||
|
|
||||||
// This can be NULL for fakeclients due to limitations in our impl
|
|
||||||
IClient *GetIClient() const;
|
|
||||||
private:
|
private:
|
||||||
void Initialize(const char *name, const char *ip, edict_t *pEntity);
|
void Initialize(const char *name, const char *ip, edict_t *pEntity);
|
||||||
void Connect();
|
void Connect();
|
||||||
void Disconnect();
|
void Disconnect();
|
||||||
void SetName(const char *name);
|
void SetName(const char *name);
|
||||||
void DumpAdmin(bool deleting);
|
void DumpAdmin(bool deleting);
|
||||||
void UpdateAuthIds();
|
void SetAuthString(const char *auth);
|
||||||
void Authorize();
|
void Authorize();
|
||||||
void Authorize_Post();
|
void Authorize_Post();
|
||||||
void DoPostConnectAuthorization();
|
void DoPostConnectAuthorization();
|
||||||
bool IsAuthStringValidated();
|
bool IsAuthStringValidated();
|
||||||
bool SetEngineString();
|
|
||||||
bool SetCSteamID();
|
|
||||||
private:
|
private:
|
||||||
bool m_IsConnected = false;
|
bool m_IsConnected;
|
||||||
bool m_IsInGame = false;
|
bool m_IsInGame;
|
||||||
bool m_IsAuthorized = false;
|
bool m_IsAuthorized;
|
||||||
bool m_bIsInKickQueue = false;
|
bool m_bIsInKickQueue;
|
||||||
String m_Name;
|
String m_Name;
|
||||||
String m_Ip;
|
String m_Ip;
|
||||||
String m_IpNoPort;
|
String m_IpNoPort;
|
||||||
ke::AString m_AuthID;
|
String m_AuthID;
|
||||||
ke::AString m_Steam2Id;
|
AdminId m_Admin;
|
||||||
ke::AString m_Steam3Id;
|
bool m_TempAdmin;
|
||||||
AdminId m_Admin = INVALID_ADMIN_ID;
|
edict_t *m_pEdict;
|
||||||
bool m_TempAdmin = false;
|
IPlayerInfo *m_Info;
|
||||||
edict_t *m_pEdict = nullptr;
|
|
||||||
IPlayerInfo *m_Info = nullptr;
|
|
||||||
IClient *m_pIClient = nullptr;
|
|
||||||
String m_LastPassword;
|
String m_LastPassword;
|
||||||
bool m_bAdminCheckSignalled = false;
|
bool m_bAdminCheckSignalled;
|
||||||
int m_iIndex;
|
int m_iIndex;
|
||||||
unsigned int m_LangId = SOURCEMOD_LANGUAGE_ENGLISH;
|
unsigned int m_LangId;
|
||||||
int m_UserId = -1;
|
int m_UserId;
|
||||||
bool m_bFakeClient = false;
|
bool m_bFakeClient;
|
||||||
bool m_bIsSourceTV = false;
|
bool m_bIsSourceTV;
|
||||||
bool m_bIsReplay = false;
|
bool m_bIsReplay;
|
||||||
serial_t m_Serial;
|
serial_t m_Serial;
|
||||||
CSteamID m_SteamId;
|
unsigned int m_SteamAccountID;
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
|
||||||
QueryCvarCookie_t m_LanguageCookie = InvalidQueryCvarCookie;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class PlayerManager :
|
class PlayerManager :
|
||||||
@@ -163,7 +139,6 @@ public:
|
|||||||
PlayerManager();
|
PlayerManager();
|
||||||
~PlayerManager();
|
~PlayerManager();
|
||||||
public: //SMGlobalClass
|
public: //SMGlobalClass
|
||||||
void OnSourceModStartup(bool late) override;
|
|
||||||
void OnSourceModAllInitialized();
|
void OnSourceModAllInitialized();
|
||||||
void OnSourceModShutdown();
|
void OnSourceModShutdown();
|
||||||
void OnSourceModLevelEnd();
|
void OnSourceModLevelEnd();
|
||||||
@@ -172,6 +147,8 @@ public: //SMGlobalClass
|
|||||||
public:
|
public:
|
||||||
CPlayer *GetPlayerByIndex(int client) const;
|
CPlayer *GetPlayerByIndex(int client) const;
|
||||||
void RunAuthChecks();
|
void RunAuthChecks();
|
||||||
|
void ClearAdminId(AdminId id);
|
||||||
|
void ClearAllAdmins();
|
||||||
public:
|
public:
|
||||||
bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
|
bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
|
||||||
bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
|
bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
|
||||||
@@ -180,16 +157,11 @@ public:
|
|||||||
void OnClientDisconnect_Post(edict_t *pEntity);
|
void OnClientDisconnect_Post(edict_t *pEntity);
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
void OnClientCommand(edict_t *pEntity, const CCommand &args);
|
void OnClientCommand(edict_t *pEntity, const CCommand &args);
|
||||||
#if SOURCE_ENGINE >= SE_EYE
|
|
||||||
void OnClientCommandKeyValues(edict_t *pEntity, KeyValues *pCommand);
|
|
||||||
void OnClientCommandKeyValues_Post(edict_t *pEntity, KeyValues *pCommand);
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
void OnClientCommand(edict_t *pEntity);
|
void OnClientCommand(edict_t *pEntity);
|
||||||
#endif
|
#endif
|
||||||
void OnClientSettingsChanged(edict_t *pEntity);
|
void OnClientSettingsChanged(edict_t *pEntity);
|
||||||
//void OnClientSettingsChanged_Pre(edict_t *pEntity);
|
//void OnClientSettingsChanged_Pre(edict_t *pEntity);
|
||||||
void OnServerHibernationUpdate(bool bHibernating);
|
|
||||||
public: //IPlayerManager
|
public: //IPlayerManager
|
||||||
void AddClientListener(IClientListener *listener);
|
void AddClientListener(IClientListener *listener);
|
||||||
void RemoveClientListener(IClientListener *listener);
|
void RemoveClientListener(IClientListener *listener);
|
||||||
@@ -205,8 +177,6 @@ public: //IPlayerManager
|
|||||||
void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
|
void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
|
||||||
void ProcessCommandTarget(cmd_target_info_t *info);
|
void ProcessCommandTarget(cmd_target_info_t *info);
|
||||||
int GetClientFromSerial(unsigned int serial);
|
int GetClientFromSerial(unsigned int serial);
|
||||||
void ClearAdminId(AdminId id);
|
|
||||||
void RecheckAnyAdmins();
|
|
||||||
public:
|
public:
|
||||||
inline int MaxClients()
|
inline int MaxClients()
|
||||||
{
|
{
|
||||||
@@ -223,16 +193,10 @@ public:
|
|||||||
bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
|
bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
|
||||||
bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id);
|
bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id);
|
||||||
const char *GetPassInfoVar();
|
const char *GetPassInfoVar();
|
||||||
|
void RecheckAnyAdmins();
|
||||||
unsigned int GetReplyTo();
|
unsigned int GetReplyTo();
|
||||||
unsigned int SetReplyTo(unsigned int reply);
|
unsigned int SetReplyTo(unsigned int reply);
|
||||||
void MaxPlayersChanged(int newvalue = -1);
|
void MaxPlayersChanged(int newvalue = -1);
|
||||||
inline bool InClientCommandKeyValuesHook()
|
|
||||||
{
|
|
||||||
return m_bInCCKVHook;
|
|
||||||
}
|
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
|
||||||
bool HandleConVarQuery(QueryCvarCookie_t cookie, int client, EQueryCvarValueStatus result, const char *cvarName, const char *cvarValue);
|
|
||||||
#endif
|
|
||||||
private:
|
private:
|
||||||
void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
|
void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
|
||||||
void InvalidatePlayer(CPlayer *pPlayer);
|
void InvalidatePlayer(CPlayer *pPlayer);
|
||||||
@@ -244,8 +208,6 @@ private:
|
|||||||
IForward *m_cldisconnect_post;
|
IForward *m_cldisconnect_post;
|
||||||
IForward *m_clputinserver;
|
IForward *m_clputinserver;
|
||||||
IForward *m_clcommand;
|
IForward *m_clcommand;
|
||||||
IForward *m_clcommandkv;
|
|
||||||
IForward *m_clcommandkv_post;
|
|
||||||
IForward *m_clinfochanged;
|
IForward *m_clinfochanged;
|
||||||
IForward *m_clauth;
|
IForward *m_clauth;
|
||||||
IForward *m_onActivate;
|
IForward *m_onActivate;
|
||||||
@@ -255,7 +217,7 @@ private:
|
|||||||
int m_maxClients;
|
int m_maxClients;
|
||||||
int m_PlayerCount;
|
int m_PlayerCount;
|
||||||
int m_PlayersSinceActive;
|
int m_PlayersSinceActive;
|
||||||
bool m_bServerActivated;
|
bool m_FirstPass;
|
||||||
unsigned int *m_AuthQueue;
|
unsigned int *m_AuthQueue;
|
||||||
String m_PassInfoVar;
|
String m_PassInfoVar;
|
||||||
bool m_QueryLang;
|
bool m_QueryLang;
|
||||||
@@ -266,7 +228,6 @@ private:
|
|||||||
bool m_bIsReplayActive;
|
bool m_bIsReplayActive;
|
||||||
int m_SourceTVUserId;
|
int m_SourceTVUserId;
|
||||||
int m_ReplayUserId;
|
int m_ReplayUserId;
|
||||||
bool m_bInCCKVHook;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
|
|||||||
@@ -0,0 +1,349 @@
|
|||||||
|
/**
|
||||||
|
* vim: set ts=4 :
|
||||||
|
* =============================================================================
|
||||||
|
* SourceMod
|
||||||
|
* Copyright (C) 2004-2008 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 <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "PluginInfoDatabase.h"
|
||||||
|
#include "PluginSys.h"
|
||||||
|
|
||||||
|
void PluginSettings::Init()
|
||||||
|
{
|
||||||
|
name = -1;
|
||||||
|
pause_val = false;
|
||||||
|
type_val = PluginType_MapUpdated;
|
||||||
|
optarray = -1;
|
||||||
|
opts_num = 0;
|
||||||
|
opts_size = 0;
|
||||||
|
blockload_val = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* :TODO: write the logger, make these errors log instead of being static
|
||||||
|
* NOTE: once we do that, we will have to change some code to ignore sections
|
||||||
|
*/
|
||||||
|
|
||||||
|
CPluginInfoDatabase::CPluginInfoDatabase()
|
||||||
|
{
|
||||||
|
m_strtab = NULL;
|
||||||
|
m_infodb_count = 0;
|
||||||
|
m_infodb_size = 0;
|
||||||
|
m_infodb = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CPluginInfoDatabase::~CPluginInfoDatabase()
|
||||||
|
{
|
||||||
|
delete m_strtab;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPluginInfoDatabase::ReadSMC_ParseStart()
|
||||||
|
{
|
||||||
|
/* Create or reset our string table */
|
||||||
|
if (m_strtab)
|
||||||
|
{
|
||||||
|
m_strtab->Reset();
|
||||||
|
} else {
|
||||||
|
m_strtab = new BaseStringTable(1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set our internal states to the beginning */
|
||||||
|
in_plugins = false;
|
||||||
|
cur_plugin = -1;
|
||||||
|
in_options = false;
|
||||||
|
m_infodb_size = 0;
|
||||||
|
m_infodb_count = 0;
|
||||||
|
m_infodb = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SMCResult CPluginInfoDatabase::MakeError(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char buffer[512];
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(buffer, sizeof(buffer), fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
m_errmsg = m_strtab->AddString(buffer);
|
||||||
|
|
||||||
|
return SMCResult_HaltFail;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CPluginInfoDatabase::GetSettingsNum()
|
||||||
|
{
|
||||||
|
return m_infodb_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginSettings *CPluginInfoDatabase::GetSettingsIfMatch(unsigned int index, const char *filename)
|
||||||
|
{
|
||||||
|
BaseMemTable *memtab = m_strtab->GetMemTable();
|
||||||
|
int *table = (int *)memtab->GetAddress(m_infodb);
|
||||||
|
|
||||||
|
if (!table || index >= m_infodb_count)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginSettings *plugin = (PluginSettings *)memtab->GetAddress(table[index]);
|
||||||
|
|
||||||
|
const char *name = m_strtab->GetString(plugin->name);
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_PluginSys.TestAliasMatch(name, filename))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPluginInfoDatabase::GetOptionsForPlugin(PluginSettings *settings, unsigned int opt_num, const char **key, const char **val)
|
||||||
|
{
|
||||||
|
PluginOpts *table = (PluginOpts *)m_strtab->GetMemTable()->GetAddress(settings->optarray);
|
||||||
|
if (!table)
|
||||||
|
{
|
||||||
|
*key = NULL;
|
||||||
|
*val = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt_num >= settings->opts_num)
|
||||||
|
{
|
||||||
|
*key = NULL;
|
||||||
|
*val = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*key = m_strtab->GetString(table[opt_num].key);
|
||||||
|
*val = m_strtab->GetString(table[opt_num].val);
|
||||||
|
}
|
||||||
|
|
||||||
|
SMCResult CPluginInfoDatabase::ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
|
||||||
|
{
|
||||||
|
if (cur_plugin != -1)
|
||||||
|
{
|
||||||
|
PluginSettings *plugin = (PluginSettings *)m_strtab->GetMemTable()->GetAddress(cur_plugin);
|
||||||
|
if (!in_options)
|
||||||
|
{
|
||||||
|
if (strcmp(key, "pause") == 0)
|
||||||
|
{
|
||||||
|
if (strcasecmp(value, "yes") == 0)
|
||||||
|
{
|
||||||
|
plugin->pause_val = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugin->pause_val = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (strcmp(key, "lifetime") == 0)
|
||||||
|
{
|
||||||
|
if (strcasecmp(value, "private") == 0)
|
||||||
|
{
|
||||||
|
plugin->type_val = PluginType_Private;
|
||||||
|
}
|
||||||
|
else if (strcasecmp(value, "mapsync") == 0)
|
||||||
|
{
|
||||||
|
plugin->type_val = PluginType_MapUpdated;
|
||||||
|
}
|
||||||
|
else if (strcasecmp(value, "maponly") == 0)
|
||||||
|
{
|
||||||
|
plugin->type_val = PluginType_MapOnly;
|
||||||
|
}
|
||||||
|
else if (strcasecmp(value, "global") == 0)
|
||||||
|
{
|
||||||
|
plugin->type_val = PluginType_Global;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return MakeError("Unknown value for key \"lifetime\": \"%s\"", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (strcmp(key, "blockload") == 0)
|
||||||
|
{
|
||||||
|
plugin->blockload_val = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return MakeError("Unknown property key: \"%s\"", key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Cache every option, valid or not */
|
||||||
|
int keyidx = m_strtab->AddString(key);
|
||||||
|
int validx = m_strtab->AddString(value);
|
||||||
|
PluginOpts *table;
|
||||||
|
BaseMemTable *memtab = m_strtab->GetMemTable();
|
||||||
|
plugin = (PluginSettings *)memtab->GetAddress(cur_plugin);
|
||||||
|
if (plugin->opts_num + 1 > plugin->opts_size)
|
||||||
|
{
|
||||||
|
unsigned int oldsize = plugin->opts_size;
|
||||||
|
if (oldsize == 0)
|
||||||
|
{
|
||||||
|
//right now we don't have many
|
||||||
|
plugin->opts_size = 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugin->opts_size *= 2;
|
||||||
|
}
|
||||||
|
int newidx = memtab->CreateMem(plugin->opts_size * sizeof(PluginOpts), (void **)&table);
|
||||||
|
/* in case it resized */
|
||||||
|
plugin = (PluginSettings *)memtab->GetAddress(cur_plugin);
|
||||||
|
if (plugin->optarray != -1)
|
||||||
|
{
|
||||||
|
void *oldtable = memtab->GetAddress(plugin->optarray);
|
||||||
|
memcpy(table, oldtable, oldsize * sizeof(PluginOpts));
|
||||||
|
}
|
||||||
|
plugin->optarray = newidx;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
table = (PluginOpts *)memtab->GetAddress(plugin->optarray);
|
||||||
|
}
|
||||||
|
PluginOpts *opt = &table[plugin->opts_num++];
|
||||||
|
opt->key = keyidx;
|
||||||
|
opt->val = validx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (in_plugins)
|
||||||
|
{
|
||||||
|
return MakeError("Unknown property key: \"%s\"", key);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Ignore anything we don't know about! */
|
||||||
|
}
|
||||||
|
|
||||||
|
return SMCResult_Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SMCResult CPluginInfoDatabase::ReadSMC_LeavingSection(const SMCStates *states)
|
||||||
|
{
|
||||||
|
if (in_plugins)
|
||||||
|
{
|
||||||
|
if (cur_plugin != -1)
|
||||||
|
{
|
||||||
|
if (in_options)
|
||||||
|
{
|
||||||
|
in_options = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* If the plugin is ending, add it to the table */
|
||||||
|
BaseMemTable *memtab = m_strtab->GetMemTable();
|
||||||
|
int *table;
|
||||||
|
if (m_infodb_count + 1 > m_infodb_size)
|
||||||
|
{
|
||||||
|
unsigned int oldsize = m_infodb_size;
|
||||||
|
if (!m_infodb_size)
|
||||||
|
{
|
||||||
|
m_infodb_size = 8;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_infodb_size *= 2;
|
||||||
|
}
|
||||||
|
int newidx = memtab->CreateMem(m_infodb_size * sizeof(int), (void **)&table);
|
||||||
|
if (m_infodb != -1)
|
||||||
|
{
|
||||||
|
void *oldtable = (int *)memtab->GetAddress(m_infodb);
|
||||||
|
memcpy(table, oldtable, oldsize * sizeof(int));
|
||||||
|
}
|
||||||
|
m_infodb = newidx;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
table = (int *)memtab->GetAddress(m_infodb);
|
||||||
|
}
|
||||||
|
/* Assign to table and scrap the current plugin */
|
||||||
|
table[m_infodb_count++] = cur_plugin;
|
||||||
|
cur_plugin = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
in_plugins = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SMCResult_Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SMCResult CPluginInfoDatabase::ReadSMC_NewSection(const SMCStates *states, const char *name)
|
||||||
|
{
|
||||||
|
if (!in_plugins)
|
||||||
|
{
|
||||||
|
/* If we're not in the main Plugins section, and we don't get it for the name, error out */
|
||||||
|
if (strcmp(name, "Plugins") != 0)
|
||||||
|
{
|
||||||
|
return MakeError("Unknown root section: \"%s\"", name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Otherwise set our states */
|
||||||
|
in_plugins = true;
|
||||||
|
cur_plugin = -1;
|
||||||
|
in_options = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (cur_plugin == -1)
|
||||||
|
{
|
||||||
|
/* If we get a plugin node and we don't have a current plugin, create a new one */
|
||||||
|
PluginSettings *plugin;
|
||||||
|
int i_name = m_strtab->AddString(name);
|
||||||
|
cur_plugin = m_strtab->GetMemTable()->CreateMem(sizeof(PluginSettings), (void **)&plugin);
|
||||||
|
plugin->Init();
|
||||||
|
plugin->name = i_name;
|
||||||
|
in_options = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!in_options && strcmp(name, "Options") == 0)
|
||||||
|
{
|
||||||
|
in_options = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return MakeError("Unknown plugin sub-section: \"%s\"", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SMCResult_Continue;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/**
|
||||||
|
* vim: set ts=4 :
|
||||||
|
* =============================================================================
|
||||||
|
* SourceMod
|
||||||
|
* Copyright (C) 2004-2008 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_SOURCEMOD_CORE_SYSTEM_PLUGININFODATABASE_H_
|
||||||
|
#define _INCLUDE_SOURCEMOD_CORE_SYSTEM_PLUGININFODATABASE_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file parses plugin_settings.cfg and stores the information in cached memory.
|
||||||
|
* It provides simplistic abstraction to retrieving the info.
|
||||||
|
* :TODO: currently untested
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sm_memtable.h"
|
||||||
|
#include "ITextParsers.h"
|
||||||
|
#include "IPluginSys.h"
|
||||||
|
#include "sm_globals.h"
|
||||||
|
|
||||||
|
struct PluginOpts
|
||||||
|
{
|
||||||
|
int key;
|
||||||
|
int val;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PluginSettings
|
||||||
|
{
|
||||||
|
void Init();
|
||||||
|
int name;
|
||||||
|
bool pause_val;
|
||||||
|
PluginType type_val;
|
||||||
|
int optarray;
|
||||||
|
size_t opts_num;
|
||||||
|
size_t opts_size;
|
||||||
|
bool blockload_val;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CPluginInfoDatabase : public ITextListener_SMC
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CPluginInfoDatabase();
|
||||||
|
~CPluginInfoDatabase();
|
||||||
|
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);
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Returns the number of plugin settings available.
|
||||||
|
*/
|
||||||
|
unsigned int GetSettingsNum();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an index, returns the plugin settings block if the filename matches.
|
||||||
|
* Otherwise, returns NULL.
|
||||||
|
*/
|
||||||
|
PluginSettings *GetSettingsIfMatch(unsigned int index, const char *filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a plugin settings struct and an index,
|
||||||
|
* returns the given JIT key/value option pair at that index.
|
||||||
|
* If the input is invalid, key and val will be set to NULL.
|
||||||
|
*/
|
||||||
|
void GetOptionsForPlugin(PluginSettings *settings, unsigned int opt_num, const char **key, const char **val);
|
||||||
|
private:
|
||||||
|
SMCResult MakeError(const char *fmt, ...);
|
||||||
|
private:
|
||||||
|
BaseStringTable *m_strtab;
|
||||||
|
int m_errmsg;
|
||||||
|
bool in_plugins;
|
||||||
|
bool in_options;
|
||||||
|
int m_infodb;
|
||||||
|
size_t m_infodb_count;
|
||||||
|
size_t m_infodb_size;
|
||||||
|
int cur_plugin;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //_INCLUDE_SOURCEMOD_CORE_SYSTEM_PLUGININFODATABASE_H_
|
||||||
+2764
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
|
||||||
@@ -42,29 +42,85 @@
|
|||||||
#include <sh_stack.h>
|
#include <sh_stack.h>
|
||||||
#include <sh_vector.h>
|
#include <sh_vector.h>
|
||||||
#include <sh_string.h>
|
#include <sh_string.h>
|
||||||
#include "common_logic.h"
|
#include "sm_globals.h"
|
||||||
|
#include "PluginInfoDatabase.h"
|
||||||
|
#include "sm_trie.h"
|
||||||
|
#include "sourcemod.h"
|
||||||
#include <IRootConsoleMenu.h>
|
#include <IRootConsoleMenu.h>
|
||||||
#include <sm_stringhashmap.h>
|
#if SOURCE_ENGINE >= SE_ALIENSWARM
|
||||||
#include <sm_namehashset.h>
|
#include "convar_sm_swarm.h"
|
||||||
|
#elif SOURCE_ENGINE >= SE_LEFT4DEAD
|
||||||
|
#include "convar_sm_l4d.h"
|
||||||
|
#elif SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
|
#include "convar_sm_ob.h"
|
||||||
|
#else
|
||||||
|
#include "convar_sm.h"
|
||||||
|
#endif
|
||||||
#include "ITranslator.h"
|
#include "ITranslator.h"
|
||||||
#include "IGameConfigs.h"
|
#include "IGameConfigs.h"
|
||||||
#include "NativeOwner.h"
|
#include "NativeOwner.h"
|
||||||
#include "ShareSys.h"
|
#include "ShareSys.h"
|
||||||
#include "PhraseCollection.h"
|
|
||||||
#include <am-string.h>
|
|
||||||
#include <bridge/include/IScriptManager.h>
|
|
||||||
#include <am-function.h>
|
|
||||||
#include <ReentrantList.h>
|
|
||||||
|
|
||||||
class CPlayer;
|
class CPlayer;
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NOTES:
|
||||||
|
*
|
||||||
|
* UPDATE 2008-03-11: These comments are horribly out of date. They paint a good overall
|
||||||
|
* picture of how PluginSys works, but things like dependencies and fake natives have
|
||||||
|
* complicated things quite a bit.
|
||||||
|
*
|
||||||
|
* Currently this system needs a lot of work but it's good skeletally. Plugin creation
|
||||||
|
* is done without actually compiling anything. This is done by Load functions in the
|
||||||
|
* manager. This will need a rewrite when we add context switching.
|
||||||
|
*
|
||||||
|
* The plugin object itself has a few things to note. The most important is that it stores
|
||||||
|
* a table of function objects. The manager marshals allocation and freeing of these objects.
|
||||||
|
* The plugin object can be in erroneous states, they are:
|
||||||
|
* Plugin_Error --> Some error occurred any time during or after compilation.
|
||||||
|
* This error can be cleared since the plugin itself is valid.
|
||||||
|
* However, the state itself being set prevents any runtime action.
|
||||||
|
* Plugin_BadLoad --> The plugin failed to load entirely and nothing can be done to save it.
|
||||||
|
*
|
||||||
|
* If a plugin fails to load externally, it is never added to the internal tracker. However,
|
||||||
|
* plugins that failed to load from the internal loading mechanism are always tracked. This
|
||||||
|
* allows users to see which automatically loaded plugins failed, and makes the interface a bit
|
||||||
|
* more flexible.
|
||||||
|
*
|
||||||
|
* Once a plugin is compiled, it sets its own state to Plugin_Created. This state is still invalid
|
||||||
|
* for execution. SourceMod is a two pass system, and even though the second pass is not implemented
|
||||||
|
* yet, it is structured so Plugin_Created must be switched to Plugin_Running in the second pass. When
|
||||||
|
* implemented, a Created plugin will be switched to Error in the second pass if it not loadable.
|
||||||
|
*
|
||||||
|
* The two pass loading mechanism is described below. Modules/natives are not implemented yet.
|
||||||
|
* PASS ONE: All loadable plugins are found and have the following steps performed:
|
||||||
|
* 1. Loading and compilation is attempted.
|
||||||
|
* 2. If successful, all natives from Core are added.
|
||||||
|
* 3. OnPluginLoad() is called.
|
||||||
|
* 4. If failed, any user natives are scrapped and the process halts here.
|
||||||
|
* 5. If successful, the plugin is ready for Pass 2.
|
||||||
|
* INTERMEDIATE:
|
||||||
|
* 1. All forced modules are loaded.
|
||||||
|
* PASS TWO: All loaded plugins are found and have these steps performed:
|
||||||
|
* 1. Any modules referenced in the plugin that are not already loaded, are loaded.
|
||||||
|
* 2. If any module fails to load and the plugin requires it, load fails and jump to step 6.
|
||||||
|
* 3. If any natives are unresolved, check if they are found in the user-natives pool.
|
||||||
|
* 4. If yes, load succeeds. If not, natives are passed through a native acceptance filter.
|
||||||
|
* 5. If the filter fails, the plugin is marked as failed.
|
||||||
|
* 6. If the plugin has failed to load at this point, any dynamic natives it has added are scrapped.
|
||||||
|
* Furthermore, any plugin that referenced these natives must now have pass 2 re-ran.
|
||||||
|
* PASS THREE (not a real pass):
|
||||||
|
* 7. Once all plugins are deemed to be loaded, OnPluginStart() is called
|
||||||
|
*/
|
||||||
|
|
||||||
enum LoadRes
|
enum LoadRes
|
||||||
{
|
{
|
||||||
LoadRes_Successful,
|
LoadRes_Successful,
|
||||||
LoadRes_AlreadyLoaded,
|
LoadRes_AlreadyLoaded,
|
||||||
LoadRes_Failure,
|
LoadRes_Failure,
|
||||||
|
LoadRes_SilentFailure,
|
||||||
LoadRes_NeverLoad
|
LoadRes_NeverLoad
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -75,27 +131,27 @@ enum APLRes
|
|||||||
APLRes_SilentFailure
|
APLRes_SilentFailure
|
||||||
};
|
};
|
||||||
|
|
||||||
// Plugin membership state.
|
enum LibraryAction
|
||||||
enum class PluginState
|
|
||||||
{
|
{
|
||||||
// The plugin has not yet been added to the global plugin list.
|
LibraryAction_Removed,
|
||||||
Unregistered,
|
LibraryAction_Added
|
||||||
|
|
||||||
// The plugin is a member of the global plugin list.
|
|
||||||
Registered,
|
|
||||||
|
|
||||||
// The plugin has been evicted.
|
|
||||||
Evicted,
|
|
||||||
|
|
||||||
// The plugin is waiting to be unloaded.
|
|
||||||
WaitingToUnload,
|
|
||||||
WaitingToUnloadAndReload,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AutoConfig
|
||||||
|
{
|
||||||
|
String autocfg;
|
||||||
|
String folder;
|
||||||
|
bool create;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CPlugin;
|
||||||
|
|
||||||
class CPlugin :
|
class CPlugin :
|
||||||
public SMPlugin,
|
public IPlugin,
|
||||||
public CNativeOwner
|
public CNativeOwner
|
||||||
{
|
{
|
||||||
|
friend class CPluginManager;
|
||||||
|
friend class CFunction;
|
||||||
public:
|
public:
|
||||||
CPlugin(const char *file);
|
CPlugin(const char *file);
|
||||||
~CPlugin();
|
~CPlugin();
|
||||||
@@ -107,8 +163,8 @@ public:
|
|||||||
const char *GetFilename();
|
const char *GetFilename();
|
||||||
bool IsDebugging();
|
bool IsDebugging();
|
||||||
PluginStatus GetStatus();
|
PluginStatus GetStatus();
|
||||||
PluginStatus Status() const;
|
|
||||||
bool IsSilentlyFailed();
|
bool IsSilentlyFailed();
|
||||||
|
void SetSilentlyFailed(bool sf);
|
||||||
const sm_plugininfo_t *GetPublicInfo();
|
const sm_plugininfo_t *GetPublicInfo();
|
||||||
bool SetPauseState(bool paused);
|
bool SetPauseState(bool paused);
|
||||||
unsigned int GetSerial();
|
unsigned int GetSerial();
|
||||||
@@ -118,21 +174,6 @@ public:
|
|||||||
bool GetProperty(const char *prop, void **ptr, bool remove=false);
|
bool GetProperty(const char *prop, void **ptr, bool remove=false);
|
||||||
void DropEverything();
|
void DropEverything();
|
||||||
SourcePawn::IPluginRuntime *GetRuntime();
|
SourcePawn::IPluginRuntime *GetRuntime();
|
||||||
CNativeOwner *ToNativeOwner() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ExtVar {
|
|
||||||
char *name;
|
|
||||||
char *file;
|
|
||||||
bool autoload;
|
|
||||||
bool required;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef ke::Lambda<bool(const sp_pubvar_t *, const ExtVar& ext)> ExtVarCallback;
|
|
||||||
bool ForEachExtVar(const ExtVarCallback& callback);
|
|
||||||
|
|
||||||
void ForEachLibrary(ke::Lambda<void(const char *)> callback);
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Creates a plugin object with default values.
|
* Creates a plugin object with default values.
|
||||||
@@ -141,187 +182,142 @@ public:
|
|||||||
* If an error buffer is not specified, the error will be copied to an internal buffer and
|
* If an error buffer is not specified, the error will be copied to an internal buffer and
|
||||||
* a valid (but error-stated) CPlugin will be returned.
|
* a valid (but error-stated) CPlugin will be returned.
|
||||||
*/
|
*/
|
||||||
static CPlugin *Create(const char *file);
|
static CPlugin *CreatePlugin(const char *file, char *error, size_t maxlength);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Evicts the plugin from memory and sets an error state.
|
|
||||||
void EvictWithError(PluginStatus status, const char *error_fmt, ...);
|
|
||||||
void FinishEviction();
|
|
||||||
|
|
||||||
// Initializes the plugin's identity information
|
/**
|
||||||
|
* Sets an error state on the plugin
|
||||||
|
*/
|
||||||
|
void SetErrorState(PluginStatus status, const char *error_fmt, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the plugin's identity information
|
||||||
|
*/
|
||||||
void InitIdentity();
|
void InitIdentity();
|
||||||
|
|
||||||
// Calls the OnPluginLoad function, and sets any failed states if necessary.
|
/**
|
||||||
// After invoking AskPluginLoad, its state is either Running or Failed.
|
* Calls the OnPluginLoad function, and sets any failed states if necessary.
|
||||||
APLRes AskPluginLoad();
|
* NOTE: Valid pre-states are: Plugin_Created
|
||||||
|
* NOTE: If validated, plugin state is changed to Plugin_Loaded
|
||||||
|
*
|
||||||
|
* If the error buffer is NULL, the error message is cached locally.
|
||||||
|
*/
|
||||||
|
APLRes Call_AskPluginLoad(char *error, size_t maxlength);
|
||||||
|
|
||||||
// Transition to the fully running state, if possible.
|
/**
|
||||||
bool OnPluginStart();
|
* Calls the OnPluginStart function.
|
||||||
|
* NOTE: Valid pre-states are: Plugin_Created
|
||||||
|
* NOTE: Post-state will be Plugin_Running
|
||||||
|
*/
|
||||||
|
void Call_OnPluginStart();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the OnPluginEnd function.
|
||||||
|
*/
|
||||||
void Call_OnPluginEnd();
|
void Call_OnPluginEnd();
|
||||||
void Call_OnAllPluginsLoaded();
|
|
||||||
void Call_OnLibraryAdded(const char *lib);
|
|
||||||
|
|
||||||
// Returns true if a plugin is usable.
|
/**
|
||||||
|
* Calls the OnAllPluginsLoaded function.
|
||||||
|
*/
|
||||||
|
void Call_OnAllPluginsLoaded();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if a plugin is usable.
|
||||||
|
*/
|
||||||
bool IsRunnable();
|
bool IsRunnable();
|
||||||
|
|
||||||
// Get languages info.
|
/**
|
||||||
|
* Get languages info.
|
||||||
|
*/
|
||||||
IPhraseCollection *GetPhrases();
|
IPhraseCollection *GetPhrases();
|
||||||
|
|
||||||
PluginState State() const {
|
|
||||||
return m_state;
|
|
||||||
}
|
|
||||||
void SetRegistered();
|
|
||||||
void SetWaitingToUnload(bool andReload=false);
|
|
||||||
|
|
||||||
PluginStatus GetDisplayStatus() const {
|
|
||||||
return m_status;
|
|
||||||
}
|
|
||||||
bool IsEvictionCandidate() const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Returns true if the plugin was running, but is now invalid.
|
/**
|
||||||
|
* Returns the modification time during last plugin load.
|
||||||
|
*/
|
||||||
|
time_t GetTimeStamp();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current modification time of the plugin file.
|
||||||
|
*/
|
||||||
|
time_t GetFileTimeStamp();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the plugin was running, but is now invalid.
|
||||||
|
*/
|
||||||
bool WasRunning();
|
bool WasRunning();
|
||||||
|
|
||||||
Handle_t GetMyHandle();
|
Handle_t GetMyHandle();
|
||||||
|
|
||||||
bool AddFakeNative(IPluginFunction *pFunc, const char *name, SPVM_FAKENATIVE_FUNC func);
|
bool AddFakeNative(IPluginFunction *pFunc, const char *name, SPVM_FAKENATIVE_FUNC func);
|
||||||
void AddConfig(bool autoCreate, const char *cfg, const char *folder);
|
void AddConfig(bool autoCreate, const char *cfg, const char *folder);
|
||||||
size_t GetConfigCount();
|
unsigned int GetConfigCount();
|
||||||
AutoConfig *GetConfig(size_t i);
|
AutoConfig *GetConfig(unsigned int i);
|
||||||
inline void AddLibrary(const char *name) {
|
inline void AddLibrary(const char *name)
|
||||||
|
{
|
||||||
m_Libraries.push_back(name);
|
m_Libraries.push_back(name);
|
||||||
}
|
}
|
||||||
inline bool HasLibrary(const char *name) {
|
|
||||||
return m_Libraries.find(name) != m_Libraries.end();
|
|
||||||
}
|
|
||||||
void LibraryActions(LibraryAction action);
|
void LibraryActions(LibraryAction action);
|
||||||
void SyncMaxClients(int max_clients);
|
void SyncMaxClients(int max_clients);
|
||||||
|
|
||||||
// Returns true if the plugin's underlying file structure has a newer
|
|
||||||
// modification time than either when it was first instantiated or
|
|
||||||
// since the last call to HasUpdatedFile().
|
|
||||||
bool HasUpdatedFile();
|
|
||||||
|
|
||||||
const char *GetDateTime() const {
|
|
||||||
return m_DateTime;
|
|
||||||
}
|
|
||||||
int GetFileVersion() const {
|
|
||||||
return m_FileVersion;
|
|
||||||
}
|
|
||||||
const char *GetErrorMsg() const {
|
|
||||||
assert(m_status != Plugin_Running && m_status != Plugin_Loaded);
|
|
||||||
return m_errormsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddRequiredLib(const char *name);
|
|
||||||
bool ForEachRequiredLib(ke::Lambda<bool(const char *)> callback);
|
|
||||||
|
|
||||||
bool HasMissingFakeNatives() const {
|
|
||||||
return m_FakeNativesMissing;
|
|
||||||
}
|
|
||||||
bool HasMissingLibrary() const {
|
|
||||||
return m_LibraryMissing;
|
|
||||||
}
|
|
||||||
bool HasFakeNatives() const {
|
|
||||||
return m_fakes.length() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// True if we got far enough into the second pass to call OnPluginLoaded
|
|
||||||
// in the listener list.
|
|
||||||
bool EnteredSecondPass() const {
|
|
||||||
return m_EnteredSecondPass;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsInErrorState() const {
|
|
||||||
if (m_status == Plugin_Running || m_status == Plugin_Loaded)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TryCompile();
|
|
||||||
void BindFakeNativesTo(CPlugin *other);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool UpdateInfo();
|
||||||
|
void SetTimeStamp(time_t t);
|
||||||
void DependencyDropped(CPlugin *pOwner);
|
void DependencyDropped(CPlugin *pOwner);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
time_t GetFileTimeStamp();
|
PluginType m_type;
|
||||||
bool ReadInfo();
|
|
||||||
void DestroyIdentity();
|
|
||||||
|
|
||||||
private:
|
|
||||||
// This information is static for the lifetime of the plugin.
|
|
||||||
char m_filename[PLATFORM_MAX_PATH];
|
char m_filename[PLATFORM_MAX_PATH];
|
||||||
unsigned int m_serial;
|
|
||||||
|
|
||||||
PluginStatus m_status;
|
PluginStatus m_status;
|
||||||
PluginState m_state;
|
bool m_bSilentlyFailed;
|
||||||
bool m_AddedLibraries;
|
unsigned int m_serial;
|
||||||
bool m_EnteredSecondPass;
|
sm_plugininfo_t m_info;
|
||||||
|
char m_errormsg[256];
|
||||||
// Statuses that are set during failure.
|
time_t m_LastAccess;
|
||||||
bool m_SilentFailure;
|
IdentityToken_t *m_ident;
|
||||||
|
Handle_t m_handle;
|
||||||
|
bool m_WasRunning;
|
||||||
|
IPhraseCollection *m_pPhrases;
|
||||||
|
List<String> m_RequiredLibs;
|
||||||
|
List<String> m_Libraries;
|
||||||
|
Trie *m_pProps;
|
||||||
bool m_FakeNativesMissing;
|
bool m_FakeNativesMissing;
|
||||||
bool m_LibraryMissing;
|
bool m_LibraryMissing;
|
||||||
char m_errormsg[256];
|
|
||||||
|
|
||||||
// Internal properties that must by reset if the runtime is evicted.
|
|
||||||
ke::AutoPtr<IPluginRuntime> m_pRuntime;
|
|
||||||
ke::AutoPtr<CPhraseCollection> m_pPhrases;
|
|
||||||
IPluginContext *m_pContext;
|
|
||||||
sp_pubvar_t *m_MaxClientsVar;
|
|
||||||
StringHashMap<void *> m_Props;
|
|
||||||
CVector<AutoConfig *> m_configs;
|
CVector<AutoConfig *> m_configs;
|
||||||
List<String> m_Libraries;
|
|
||||||
bool m_bGotAllLoaded;
|
bool m_bGotAllLoaded;
|
||||||
int m_FileVersion;
|
int m_FileVersion;
|
||||||
|
|
||||||
// Information that survives past eviction.
|
|
||||||
List<String> m_RequiredLibs;
|
|
||||||
IdentityToken_t *m_ident;
|
|
||||||
time_t m_LastFileModTime;
|
|
||||||
Handle_t m_handle;
|
|
||||||
char m_DateTime[256];
|
char m_DateTime[256];
|
||||||
|
IPluginRuntime *m_pRuntime;
|
||||||
// Cached.
|
IPluginContext *m_pContext;
|
||||||
sm_plugininfo_t m_info;
|
sp_pubvar_t *m_MaxClientsVar;
|
||||||
ke::AString info_name_;
|
|
||||||
ke::AString info_author_;
|
|
||||||
ke::AString info_description_;
|
|
||||||
ke::AString info_version_;
|
|
||||||
ke::AString info_url_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CPluginManager :
|
class CPluginManager :
|
||||||
public IScriptManager,
|
public IPluginManager,
|
||||||
public SMGlobalClass,
|
public SMGlobalClass,
|
||||||
public IHandleTypeDispatch,
|
public IHandleTypeDispatch,
|
||||||
public IRootConsoleCommand
|
public IRootConsoleCommand
|
||||||
{
|
{
|
||||||
|
friend class CPlugin;
|
||||||
public:
|
public:
|
||||||
CPluginManager();
|
CPluginManager();
|
||||||
~CPluginManager();
|
~CPluginManager();
|
||||||
public:
|
public:
|
||||||
/* Implements iterator class */
|
/* Implements iterator class */
|
||||||
class CPluginIterator
|
class CPluginIterator : public IPluginIterator
|
||||||
: public IPluginIterator,
|
|
||||||
public IPluginsListener
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CPluginIterator(ReentrantList<CPlugin *>& in);
|
CPluginIterator(List<CPlugin *> *mylist);
|
||||||
virtual ~CPluginIterator();
|
virtual ~CPluginIterator();
|
||||||
virtual bool MorePlugins();
|
virtual bool MorePlugins();
|
||||||
virtual IPlugin *GetPlugin();
|
virtual IPlugin *GetPlugin();
|
||||||
virtual void NextPlugin();
|
virtual void NextPlugin();
|
||||||
void Release();
|
void Release();
|
||||||
void OnPluginDestroyed(IPlugin *plugin) override;
|
public:
|
||||||
|
void Reset();
|
||||||
private:
|
private:
|
||||||
ke::LinkedList<CPlugin *> mylist;
|
List<CPlugin *> *mylist;
|
||||||
ke::LinkedList<CPlugin *>::iterator current;
|
List<CPlugin *>::iterator current;
|
||||||
};
|
};
|
||||||
friend class CPluginManager::CPluginIterator;
|
friend class CPluginManager::CPluginIterator;
|
||||||
public: //IScriptManager
|
public: //IPluginManager
|
||||||
IPlugin *LoadPlugin(const char *path,
|
IPlugin *LoadPlugin(const char *path,
|
||||||
bool debug,
|
bool debug,
|
||||||
PluginType type,
|
PluginType type,
|
||||||
@@ -334,27 +330,6 @@ public: //IScriptManager
|
|||||||
IPluginIterator *GetPluginIterator();
|
IPluginIterator *GetPluginIterator();
|
||||||
void AddPluginsListener(IPluginsListener *listener);
|
void AddPluginsListener(IPluginsListener *listener);
|
||||||
void RemovePluginsListener(IPluginsListener *listener);
|
void RemovePluginsListener(IPluginsListener *listener);
|
||||||
void LoadAll(const char *config_path, const char *plugins_path);
|
|
||||||
void RefreshAll();
|
|
||||||
SMPlugin *FindPluginByOrder(unsigned num) {
|
|
||||||
return GetPluginByOrder(num);
|
|
||||||
}
|
|
||||||
SMPlugin *FindPluginByIdentity(IdentityToken_t *ident) {
|
|
||||||
return GetPluginFromIdentity(ident);
|
|
||||||
}
|
|
||||||
SMPlugin *FindPluginByContext(IPluginContext *ctx) {
|
|
||||||
return GetPluginByCtx(ctx->GetContext());
|
|
||||||
}
|
|
||||||
SMPlugin *FindPluginByContext(sp_context_t *ctx) {
|
|
||||||
return GetPluginByCtx(ctx);
|
|
||||||
}
|
|
||||||
SMPlugin *FindPluginByConsoleArg(const char *text);
|
|
||||||
SMPlugin *FindPluginByHandle(Handle_t hndl, HandleError *errp) {
|
|
||||||
return static_cast<SMPlugin *>(PluginFromHandle(hndl, errp));
|
|
||||||
}
|
|
||||||
const CVector<SMPlugin *> *ListPlugins();
|
|
||||||
void FreePluginList(const CVector<SMPlugin *> *plugins);
|
|
||||||
|
|
||||||
public: //SMGlobalClass
|
public: //SMGlobalClass
|
||||||
void OnSourceModAllInitialized();
|
void OnSourceModAllInitialized();
|
||||||
void OnSourceModShutdown();
|
void OnSourceModShutdown();
|
||||||
@@ -364,7 +339,7 @@ public: //IHandleTypeDispatch
|
|||||||
void OnHandleDestroy(HandleType_t type, void *object);
|
void OnHandleDestroy(HandleType_t type, void *object);
|
||||||
bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
|
bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
|
||||||
public: //IRootConsoleCommand
|
public: //IRootConsoleCommand
|
||||||
void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override;
|
void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Loads all plugins not yet loaded
|
* Loads all plugins not yet loaded
|
||||||
@@ -376,6 +351,17 @@ public:
|
|||||||
*/
|
*/
|
||||||
void LoadAll_SecondPass();
|
void LoadAll_SecondPass();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests a plugin file mask against a local folder.
|
||||||
|
* The alias is searched backwards from localdir - i.e., given this input:
|
||||||
|
* csdm/ban csdm/ban
|
||||||
|
* ban csdm/ban
|
||||||
|
* csdm/ban optional/csdm/ban
|
||||||
|
* All of these will return true for an alias match.
|
||||||
|
* Wildcards are allowed in the filename.
|
||||||
|
*/
|
||||||
|
bool TestAliasMatch(const char *alias, const char *localdir);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether anything loaded will be a late load.
|
* Returns whether anything loaded will be a late load.
|
||||||
*/
|
*/
|
||||||
@@ -403,6 +389,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
const char *GetStatusText(PluginStatus status);
|
const char *GetStatusText(PluginStatus status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload or update plugins on level shutdown.
|
||||||
|
*/
|
||||||
|
void ReloadOrUnloadPlugins();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add public functions from all running or paused
|
* Add public functions from all running or paused
|
||||||
* plugins to the specified forward if the names match.
|
* plugins to the specified forward if the names match.
|
||||||
@@ -422,19 +413,17 @@ public:
|
|||||||
|
|
||||||
bool LibraryExists(const char *lib);
|
bool LibraryExists(const char *lib);
|
||||||
|
|
||||||
bool ReloadPlugin(CPlugin *pl, bool print=false);
|
bool ReloadPlugin(CPlugin *pl);
|
||||||
|
|
||||||
void UnloadAll();
|
void UnloadAll();
|
||||||
|
|
||||||
|
CPlugin *FindPluginByConsoleArg(const char *arg);
|
||||||
|
|
||||||
void SyncMaxClients(int max_clients);
|
void SyncMaxClients(int max_clients);
|
||||||
|
|
||||||
void ListPluginsToClient(CPlayer *player, const CCommand &args);
|
void ListPluginsToClient(CPlayer *player, const CCommand &args);
|
||||||
|
|
||||||
void _SetPauseState(CPlugin *pPlugin, bool pause);
|
|
||||||
|
|
||||||
void ForEachPlugin(ke::Lambda<void(CPlugin *)> callback);
|
|
||||||
private:
|
private:
|
||||||
LoadRes LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type);
|
LoadRes _LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength);
|
||||||
|
|
||||||
void LoadAutoPlugin(const char *plugin);
|
void LoadAutoPlugin(const char *plugin);
|
||||||
|
|
||||||
@@ -448,66 +437,40 @@ private:
|
|||||||
*/
|
*/
|
||||||
void AddPlugin(CPlugin *pPlugin);
|
void AddPlugin(CPlugin *pPlugin);
|
||||||
|
|
||||||
// First pass for loading a plugin, and its helpers.
|
/**
|
||||||
CPlugin *CompileAndPrep(const char *path);
|
* Runs the second loading pass on a plugin.
|
||||||
bool MalwareCheckPass(CPlugin *pPlugin);
|
*/
|
||||||
|
bool RunSecondPass(CPlugin *pPlugin, char *error, size_t maxlength);
|
||||||
|
|
||||||
// Runs the second loading pass on a plugin.
|
/**
|
||||||
bool RunSecondPass(CPlugin *pPlugin);
|
* Runs an extension pass on a plugin.
|
||||||
void LoadExtensions(CPlugin *pPlugin);
|
*/
|
||||||
bool RequireExtensions(CPlugin *pPlugin);
|
bool LoadOrRequireExtensions(CPlugin *pPlugin, unsigned int pass, char *error, size_t maxlength);
|
||||||
bool FindOrRequirePluginDeps(CPlugin *pPlugin);
|
|
||||||
|
|
||||||
void UnloadPluginImpl(CPlugin *plugin);
|
/**
|
||||||
void ReloadPluginImpl(int id, const char filename[], PluginType ptype, bool print);
|
* Manages required natives.
|
||||||
|
*/
|
||||||
|
bool FindOrRequirePluginDeps(CPlugin *pPlugin, char *error, size_t maxlength);
|
||||||
|
|
||||||
void Purge(CPlugin *plugin);
|
void _SetPauseState(CPlugin *pPlugin, bool pause);
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* Caching internal objects
|
||||||
|
*/
|
||||||
|
void ReleaseIterator(CPluginIterator *iter);
|
||||||
public:
|
public:
|
||||||
inline IdentityToken_t *GetIdentity()
|
inline IdentityToken_t *GetIdentity()
|
||||||
{
|
{
|
||||||
return m_MyIdent;
|
return m_MyIdent;
|
||||||
}
|
}
|
||||||
IPluginManager *GetOldAPI();
|
|
||||||
private:
|
private:
|
||||||
void TryRefreshDependencies(CPlugin *pOther);
|
void TryRefreshDependencies(CPlugin *pOther);
|
||||||
private:
|
private:
|
||||||
ReentrantList<IPluginsListener *> m_listeners;
|
List<IPluginsListener *> m_listeners;
|
||||||
ReentrantList<CPlugin *> m_plugins;
|
List<CPlugin *> m_plugins;
|
||||||
ke::LinkedList<CPluginIterator *> m_iterators;
|
CStack<CPluginManager::CPluginIterator *> m_iters;
|
||||||
|
CPluginInfoDatabase m_PluginInfo;
|
||||||
typedef decltype(m_listeners)::iterator ListenerIter;
|
Trie *m_LoadLookup;
|
||||||
typedef decltype(m_plugins)::iterator PluginIter;
|
|
||||||
|
|
||||||
struct CPluginPolicy
|
|
||||||
{
|
|
||||||
static inline uint32_t hash(const detail::CharsAndLength &key)
|
|
||||||
{
|
|
||||||
/* For windows & mac, we convert the path to lower-case in order to avoid duplicate plugin loading */
|
|
||||||
#if defined PLATFORM_WINDOWS || defined PLATFORM_APPLE
|
|
||||||
ke::AString original(key.chars());
|
|
||||||
ke::AString lower = original.lowercase();
|
|
||||||
|
|
||||||
return detail::CharsAndLength(lower.chars()).hash();
|
|
||||||
#else
|
|
||||||
return key.hash();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool matches(const char *file, const CPlugin *plugin)
|
|
||||||
{
|
|
||||||
const char *pluginFileChars = const_cast<CPlugin*>(plugin)->GetFilename();
|
|
||||||
#if defined PLATFORM_WINDOWS || defined PLATFORM_APPLE
|
|
||||||
ke::AString pluginFile = ke::AString(pluginFileChars).lowercase();
|
|
||||||
ke::AString input = ke::AString(file).lowercase();
|
|
||||||
|
|
||||||
return pluginFile == input;
|
|
||||||
#else
|
|
||||||
return strcmp(pluginFileChars, file) == 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
};
|
|
||||||
NameHashSet<CPlugin *, CPluginPolicy> m_LoadLookup;
|
|
||||||
|
|
||||||
bool m_AllPluginsLoaded;
|
bool m_AllPluginsLoaded;
|
||||||
IdentityToken_t *m_MyIdent;
|
IdentityToken_t *m_MyIdent;
|
||||||
|
|
||||||
@@ -0,0 +1,611 @@
|
|||||||
|
/**
|
||||||
|
* vim: set ts=4 :
|
||||||
|
* =============================================================================
|
||||||
|
* SourceMod
|
||||||
|
* Copyright (C) 2004-2008 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 "ShareSys.h"
|
||||||
|
#include "HandleSys.h"
|
||||||
|
#include "ExtensionSys.h"
|
||||||
|
#include "LibrarySys.h"
|
||||||
|
#include "PluginSys.h"
|
||||||
|
#include "sm_stringutil.h"
|
||||||
|
|
||||||
|
ShareSystem g_ShareSys;
|
||||||
|
static unsigned int g_mark_serial = 0;
|
||||||
|
|
||||||
|
ShareSystem::ShareSystem()
|
||||||
|
{
|
||||||
|
m_IdentRoot.ident = 0;
|
||||||
|
m_TypeRoot = 0;
|
||||||
|
m_IfaceType = 0;
|
||||||
|
m_CoreType = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentityToken_t *ShareSystem::CreateCoreIdentity()
|
||||||
|
{
|
||||||
|
if (!m_CoreType)
|
||||||
|
{
|
||||||
|
m_CoreType = CreateIdentType("CORE");
|
||||||
|
}
|
||||||
|
|
||||||
|
return CreateIdentity(m_CoreType, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::Initialize()
|
||||||
|
{
|
||||||
|
TypeAccess sec;
|
||||||
|
|
||||||
|
g_HandleSys.InitAccessDefaults(&sec, NULL);
|
||||||
|
sec.ident = GetIdentRoot();
|
||||||
|
|
||||||
|
m_TypeRoot = g_HandleSys.CreateType("Identity", this, 0, &sec, NULL, NULL, NULL);
|
||||||
|
m_IfaceType = g_HandleSys.CreateType("Interface", this, 0, NULL, NULL, GetIdentRoot(), NULL);
|
||||||
|
|
||||||
|
/* Initialize our static identity handle */
|
||||||
|
m_IdentRoot.ident = g_HandleSys.CreateHandle(m_TypeRoot, NULL, NULL, GetIdentRoot(), NULL);
|
||||||
|
|
||||||
|
/* Add the Handle System and others... they are too innocent and pure to do it themselves */
|
||||||
|
AddInterface(NULL, &g_HandleSys);
|
||||||
|
AddInterface(NULL, &g_LibSys);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::OnSourceModShutdown()
|
||||||
|
{
|
||||||
|
if (m_CoreType)
|
||||||
|
{
|
||||||
|
g_HandleSys.RemoveType(m_CoreType, GetIdentRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
g_HandleSys.RemoveType(m_IfaceType, GetIdentRoot());
|
||||||
|
g_HandleSys.RemoveType(m_TypeRoot, GetIdentRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentityType_t ShareSystem::FindIdentType(const char *name)
|
||||||
|
{
|
||||||
|
HandleType_t type;
|
||||||
|
|
||||||
|
if (g_HandleSys.FindHandleType(name, &type))
|
||||||
|
{
|
||||||
|
if (g_HandleSys.TypeCheck(type, m_TypeRoot))
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentityType_t ShareSystem::CreateIdentType(const char *name)
|
||||||
|
{
|
||||||
|
if (!m_TypeRoot)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_HandleSys.CreateType(name, this, m_TypeRoot, NULL, NULL, GetIdentRoot(), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::OnHandleDestroy(HandleType_t type, void *object)
|
||||||
|
{
|
||||||
|
/* THIS WILL NEVER BE CALLED FOR ANYTHING WITH THE IDENTITY TYPE */
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentityToken_t *ShareSystem::CreateIdentity(IdentityType_t type, void *ptr)
|
||||||
|
{
|
||||||
|
if (!m_TypeRoot)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* :TODO: Cache? */
|
||||||
|
IdentityToken_t *pToken = new IdentityToken_t;
|
||||||
|
|
||||||
|
HandleSecurity sec;
|
||||||
|
sec.pOwner = sec.pIdentity = GetIdentRoot();
|
||||||
|
|
||||||
|
pToken->ident = g_HandleSys.CreateHandleInt(type, NULL, &sec, NULL, NULL, true);
|
||||||
|
pToken->ptr = ptr;
|
||||||
|
pToken->type = type;
|
||||||
|
|
||||||
|
return pToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShareSystem::AddInterface(IExtension *myself, SMInterface *iface)
|
||||||
|
{
|
||||||
|
if (!iface)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
IfaceInfo info;
|
||||||
|
|
||||||
|
info.owner = myself;
|
||||||
|
info.iface = iface;
|
||||||
|
|
||||||
|
m_Interfaces.push_back(info);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShareSystem::RequestInterface(const char *iface_name,
|
||||||
|
unsigned int iface_vers,
|
||||||
|
IExtension *myself,
|
||||||
|
SMInterface **pIface)
|
||||||
|
{
|
||||||
|
/* See if the interface exists */
|
||||||
|
List<IfaceInfo>::iterator iter;
|
||||||
|
SMInterface *iface;
|
||||||
|
IExtension *iface_owner;
|
||||||
|
bool found = false;
|
||||||
|
for (iter=m_Interfaces.begin(); iter!=m_Interfaces.end(); iter++)
|
||||||
|
{
|
||||||
|
IfaceInfo &info = (*iter);
|
||||||
|
iface = info.iface;
|
||||||
|
if (strcmp(iface->GetInterfaceName(), iface_name) == 0)
|
||||||
|
{
|
||||||
|
if (iface->GetInterfaceVersion() == iface_vers
|
||||||
|
|| iface->IsVersionCompatible(iface_vers))
|
||||||
|
{
|
||||||
|
iface_owner = info.owner;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add a dependency node */
|
||||||
|
if (iface_owner)
|
||||||
|
{
|
||||||
|
IfaceInfo info;
|
||||||
|
info.iface = iface;
|
||||||
|
info.owner = iface_owner;
|
||||||
|
g_Extensions.BindDependency(myself, &info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pIface)
|
||||||
|
{
|
||||||
|
*pIface = iface;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::AddNatives(IExtension *myself, const sp_nativeinfo_t *natives)
|
||||||
|
{
|
||||||
|
CNativeOwner *pOwner;
|
||||||
|
|
||||||
|
pOwner = g_Extensions.GetNativeOwner(myself);
|
||||||
|
|
||||||
|
pOwner->AddNatives(natives);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::DestroyIdentity(IdentityToken_t *identity)
|
||||||
|
{
|
||||||
|
HandleSecurity sec;
|
||||||
|
|
||||||
|
sec.pOwner = GetIdentRoot();
|
||||||
|
sec.pIdentity = GetIdentRoot();
|
||||||
|
|
||||||
|
g_HandleSys.FreeHandle(identity->ident, &sec);
|
||||||
|
delete identity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::DestroyIdentType(IdentityType_t type)
|
||||||
|
{
|
||||||
|
g_HandleSys.RemoveType(type, GetIdentRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::RemoveInterfaces(IExtension *pExtension)
|
||||||
|
{
|
||||||
|
List<IfaceInfo>::iterator iter = m_Interfaces.begin();
|
||||||
|
|
||||||
|
while (iter != m_Interfaces.end())
|
||||||
|
{
|
||||||
|
if ((*iter).owner == pExtension)
|
||||||
|
{
|
||||||
|
iter = m_Interfaces.erase(iter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::AddDependency(IExtension *myself, const char *filename, bool require, bool autoload)
|
||||||
|
{
|
||||||
|
g_Extensions.AddDependency(myself, filename, require, autoload);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::RegisterLibrary(IExtension *myself, const char *name)
|
||||||
|
{
|
||||||
|
g_Extensions.AddLibrary(myself, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::OverrideNatives(IExtension *myself, const sp_nativeinfo_t *natives)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
NativeEntry *pEntry;
|
||||||
|
CNativeOwner *pOwner;
|
||||||
|
|
||||||
|
pOwner = g_Extensions.GetNativeOwner(myself);
|
||||||
|
|
||||||
|
for (i = 0; natives[i].func != NULL && natives[i].name != NULL; i++)
|
||||||
|
{
|
||||||
|
if ((pEntry = FindNative(natives[i].name)) == NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEntry->owner != g_pCoreNatives)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEntry->replacement.owner != NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now it's safe to add the override */
|
||||||
|
pEntry->replacement.func = natives[i].func;
|
||||||
|
pEntry->replacement.owner = pOwner;
|
||||||
|
pOwner->AddReplacedNative(pEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NativeEntry *ShareSystem::FindNative(const char *name)
|
||||||
|
{
|
||||||
|
NativeEntry **ppEntry;
|
||||||
|
|
||||||
|
if ((ppEntry = m_NtvCache.retrieve(name)) == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *ppEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::BindNativesToPlugin(CPlugin *pPlugin, bool bCoreOnly)
|
||||||
|
{
|
||||||
|
NativeEntry *pEntry;
|
||||||
|
sp_native_t *native;
|
||||||
|
uint32_t i, native_count;
|
||||||
|
IPluginContext *pContext;
|
||||||
|
|
||||||
|
pContext = pPlugin->GetBaseContext();
|
||||||
|
|
||||||
|
/* Generate a new serial ID, mark our dependencies with it. */
|
||||||
|
g_mark_serial++;
|
||||||
|
pPlugin->PropogateMarkSerial(g_mark_serial);
|
||||||
|
|
||||||
|
native_count = pContext->GetNativesNum();
|
||||||
|
for (i = 0; i < native_count; i++)
|
||||||
|
{
|
||||||
|
if (pContext->GetNativeByIndex(i, &native) != SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we're bound, check if there is a replacement available.
|
||||||
|
* If not, this native is totally finalized.
|
||||||
|
*/
|
||||||
|
if (native->status == SP_NATIVE_BOUND)
|
||||||
|
{
|
||||||
|
pEntry = (NativeEntry *)native->user;
|
||||||
|
assert(pEntry != NULL);
|
||||||
|
if (pEntry->replacement.owner == NULL
|
||||||
|
|| (pEntry->replacement.owner != NULL
|
||||||
|
&& pEntry->replacement.func == native->pfn))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Otherwise, the native must be in our cache. */
|
||||||
|
else if ((pEntry = FindNative(native->name)) == NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bCoreOnly && pEntry->owner != g_pCoreNatives)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
BindNativeToPlugin(pPlugin, native, i, pEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::BindNativeToPlugin(CPlugin *pPlugin, NativeEntry *pEntry)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
sp_native_t *native;
|
||||||
|
IPluginContext *pContext;
|
||||||
|
|
||||||
|
pContext = pPlugin->GetBaseContext();
|
||||||
|
|
||||||
|
if (pContext->FindNativeByName(pEntry->name, &i) != SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pContext->GetNativeByIndex(i, &native) != SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (native->status == SP_NATIVE_BOUND)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BindNativeToPlugin(pPlugin, native, i, pEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::BindNativeToPlugin(CPlugin *pPlugin,
|
||||||
|
sp_native_t *native,
|
||||||
|
uint32_t index,
|
||||||
|
NativeEntry *pEntry)
|
||||||
|
{
|
||||||
|
/* Mark as bound... we do the rest next. */
|
||||||
|
native->status = SP_NATIVE_BOUND;
|
||||||
|
native->user = pEntry;
|
||||||
|
|
||||||
|
/* See if a replacement is available. */
|
||||||
|
if (pEntry->replacement.owner != NULL)
|
||||||
|
{
|
||||||
|
/* Perform a replacement bind. */
|
||||||
|
native->pfn = pEntry->replacement.func;
|
||||||
|
pEntry->replacement.owner->AddWeakRef(WeakNative(pPlugin, index, pEntry));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Perform a normal bind. */
|
||||||
|
native->pfn = pEntry->func;
|
||||||
|
|
||||||
|
/* We don't bother with dependency crap if the owner is Core. */
|
||||||
|
if (pEntry->owner != g_pCoreNatives)
|
||||||
|
{
|
||||||
|
/* The native is optional, this is a special case */
|
||||||
|
if ((native->flags & SP_NTVFLAG_OPTIONAL) == SP_NTVFLAG_OPTIONAL)
|
||||||
|
{
|
||||||
|
/* Only add if there is a valid owner. */
|
||||||
|
if (pEntry->owner != NULL)
|
||||||
|
{
|
||||||
|
pEntry->owner->AddWeakRef(WeakNative(pPlugin, index));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
native->status = SP_NATIVE_UNBOUND;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Otherwise, we're a strong dependent and not a weak one */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* See if this has already been marked as a dependent.
|
||||||
|
* If it has, it means this relationship has already occurred,
|
||||||
|
* and there is no reason to do it again.
|
||||||
|
*/
|
||||||
|
if (pEntry->owner != pPlugin
|
||||||
|
&& pEntry->owner->GetMarkSerial() != g_mark_serial)
|
||||||
|
{
|
||||||
|
/* This has not been marked as a dependency yet */
|
||||||
|
//pPlugin->AddDependency(pEntry->owner);
|
||||||
|
pEntry->owner->AddDependent(pPlugin);
|
||||||
|
pEntry->owner->SetMarkSerial(g_mark_serial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NativeEntry *ShareSystem::AddNativeToCache(CNativeOwner *pOwner, const sp_nativeinfo_t *ntv)
|
||||||
|
{
|
||||||
|
NativeEntry *pEntry;
|
||||||
|
|
||||||
|
if ((pEntry = FindNative(ntv->name)) == NULL)
|
||||||
|
{
|
||||||
|
pEntry = new NativeEntry;
|
||||||
|
|
||||||
|
pEntry->owner = pOwner;
|
||||||
|
pEntry->name = ntv->name;
|
||||||
|
pEntry->func = ntv->func;
|
||||||
|
pEntry->replacement.func = NULL;
|
||||||
|
pEntry->replacement.owner = NULL;
|
||||||
|
pEntry->fake = NULL;
|
||||||
|
|
||||||
|
m_NtvCache.insert(ntv->name, pEntry);
|
||||||
|
|
||||||
|
return pEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEntry->owner != NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pEntry->owner = pOwner;
|
||||||
|
pEntry->func = ntv->func;
|
||||||
|
pEntry->name = ntv->name;
|
||||||
|
|
||||||
|
return pEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::ClearNativeFromCache(CNativeOwner *pOwner, const char *name)
|
||||||
|
{
|
||||||
|
NativeEntry *pEntry;
|
||||||
|
|
||||||
|
if ((pEntry = FindNative(name)) == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEntry->owner != pOwner)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEntry->fake != NULL)
|
||||||
|
{
|
||||||
|
g_pSourcePawn2->DestroyFakeNative(pEntry->func);
|
||||||
|
delete pEntry->fake;
|
||||||
|
pEntry->fake = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pEntry->func = NULL;
|
||||||
|
pEntry->name = NULL;
|
||||||
|
pEntry->owner = NULL;
|
||||||
|
pEntry->replacement.func = NULL;
|
||||||
|
pEntry->replacement.owner = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
NativeEntry *ShareSystem::AddFakeNative(IPluginFunction *pFunc, const char *name, SPVM_FAKENATIVE_FUNC func)
|
||||||
|
{
|
||||||
|
FakeNative *pFake;
|
||||||
|
NativeEntry *pEntry;
|
||||||
|
SPVM_NATIVE_FUNC gate;
|
||||||
|
|
||||||
|
if ((pEntry = FindNative(name)) != NULL && pEntry->owner != NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pFake = new FakeNative;
|
||||||
|
|
||||||
|
if ((gate = g_pSourcePawn2->CreateFakeNative(func, pFake)) == NULL)
|
||||||
|
{
|
||||||
|
delete pFake;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEntry == NULL)
|
||||||
|
{
|
||||||
|
pEntry = new NativeEntry;
|
||||||
|
m_NtvCache.insert(name, pEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
pFake->call = pFunc;
|
||||||
|
pFake->ctx = pFunc->GetParentContext();
|
||||||
|
strncopy(pFake->name, name, sizeof(pFake->name));
|
||||||
|
|
||||||
|
pEntry->fake = pFake;
|
||||||
|
pEntry->func = gate;
|
||||||
|
pEntry->name = pFake->name;
|
||||||
|
pEntry->owner = g_PluginSys.GetPluginByCtx(pFake->ctx->GetContext());
|
||||||
|
pEntry->replacement.func = NULL;
|
||||||
|
pEntry->replacement.owner = NULL;
|
||||||
|
|
||||||
|
return pEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::AddCapabilityProvider(IExtension *myself, IFeatureProvider *provider,
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
if (m_caps.retrieve(name) != NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Capability cap;
|
||||||
|
cap.ext = myself;
|
||||||
|
cap.provider = provider;
|
||||||
|
|
||||||
|
m_caps.insert(name, cap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShareSystem::DropCapabilityProvider(IExtension *myself, IFeatureProvider *provider,
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
Capability *pCap = m_caps.retrieve(name);
|
||||||
|
if (pCap == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (pCap->ext != myself || pCap->provider != provider)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_caps.remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
FeatureStatus ShareSystem::TestFeature(IPluginRuntime *pRuntime, FeatureType feature,
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
switch (feature)
|
||||||
|
{
|
||||||
|
case FeatureType_Native:
|
||||||
|
return TestNative(pRuntime, name);
|
||||||
|
case FeatureType_Capability:
|
||||||
|
return TestCap(name);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FeatureStatus_Unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
FeatureStatus ShareSystem::TestNative(IPluginRuntime *pRuntime, const char *name)
|
||||||
|
{
|
||||||
|
uint32_t index;
|
||||||
|
|
||||||
|
if (pRuntime->FindNativeByName(name, &index) == SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
sp_native_t *native;
|
||||||
|
if (pRuntime->GetNativeByIndex(index, &native) == SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
if (native->status == SP_NATIVE_BOUND)
|
||||||
|
return FeatureStatus_Available;
|
||||||
|
else
|
||||||
|
return FeatureStatus_Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NativeEntry *entry = FindNative(name);
|
||||||
|
if (entry == NULL)
|
||||||
|
return FeatureStatus_Unknown;
|
||||||
|
|
||||||
|
if ((entry->replacement.owner != NULL || entry->owner != NULL) &&
|
||||||
|
(entry->replacement.func != NULL || entry->func != NULL))
|
||||||
|
{
|
||||||
|
return FeatureStatus_Available;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FeatureStatus_Unavailable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FeatureStatus ShareSystem::TestCap(const char *name)
|
||||||
|
{
|
||||||
|
Capability *cap = m_caps.retrieve(name);
|
||||||
|
if (cap == NULL)
|
||||||
|
return FeatureStatus_Unknown;
|
||||||
|
|
||||||
|
return cap->provider->GetFeatureStatus(FeatureType_Capability, name);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@@ -34,14 +34,10 @@
|
|||||||
|
|
||||||
#include <IShareSys.h>
|
#include <IShareSys.h>
|
||||||
#include <IHandleSys.h>
|
#include <IHandleSys.h>
|
||||||
#include <am-string.h>
|
|
||||||
#include <am-utility.h>
|
|
||||||
#include <am-refcounting.h>
|
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include <sm_stringhashmap.h>
|
#include <sm_trie_tpl.h>
|
||||||
#include <sm_namehashset.h>
|
#include "sm_globals.h"
|
||||||
#include "common_logic.h"
|
#include "sourcemod.h"
|
||||||
#include "Native.h"
|
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
|
|
||||||
@@ -67,6 +63,29 @@ struct IfaceInfo
|
|||||||
|
|
||||||
class CNativeOwner;
|
class CNativeOwner;
|
||||||
class CPlugin;
|
class CPlugin;
|
||||||
|
struct NativeEntry;
|
||||||
|
|
||||||
|
struct ReplaceNative
|
||||||
|
{
|
||||||
|
CNativeOwner *owner;
|
||||||
|
SPVM_NATIVE_FUNC func;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FakeNative
|
||||||
|
{
|
||||||
|
char name[64];
|
||||||
|
IPluginContext *ctx;
|
||||||
|
IPluginFunction *call;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NativeEntry
|
||||||
|
{
|
||||||
|
CNativeOwner *owner;
|
||||||
|
SPVM_NATIVE_FUNC func;
|
||||||
|
const char *name;
|
||||||
|
ReplaceNative replacement;
|
||||||
|
FakeNative *fake;
|
||||||
|
};
|
||||||
|
|
||||||
struct Capability
|
struct Capability
|
||||||
{
|
{
|
||||||
@@ -119,25 +138,25 @@ public:
|
|||||||
return &m_IdentRoot;
|
return &m_IdentRoot;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
void BeginBindingFor(CPlugin *pPlugin);
|
|
||||||
void BindNativesToPlugin(CPlugin *pPlugin, bool bCoreOnly);
|
void BindNativesToPlugin(CPlugin *pPlugin, bool bCoreOnly);
|
||||||
void BindNativeToPlugin(CPlugin *pPlugin, const ke::RefPtr<Native> &pEntry);
|
void BindNativeToPlugin(CPlugin *pPlugin, NativeEntry *pEntry);
|
||||||
ke::AlreadyRefed<Native> AddFakeNative(IPluginFunction *pFunc, const char *name, SPVM_FAKENATIVE_FUNC func);
|
NativeEntry *AddFakeNative(IPluginFunction *pFunc, const char *name, SPVM_FAKENATIVE_FUNC func);
|
||||||
ke::RefPtr<Native> FindNative(const char *name);
|
NativeEntry *FindNative(const char *name);
|
||||||
private:
|
private:
|
||||||
ke::AlreadyRefed<Native> AddNativeToCache(CNativeOwner *pOwner, const sp_nativeinfo_t *ntv);
|
NativeEntry *AddNativeToCache(CNativeOwner *pOwner, const sp_nativeinfo_t *ntv);
|
||||||
void ClearNativeFromCache(CNativeOwner *pOwner, const char *name);
|
void ClearNativeFromCache(CNativeOwner *pOwner, const char *name);
|
||||||
void BindNativeToPlugin(CPlugin *pPlugin, const sp_native_t *ntv, uint32_t index, const ke::RefPtr<Native> &pEntry);
|
void BindNativeToPlugin(CPlugin *pPlugin,
|
||||||
|
sp_native_t *ntv,
|
||||||
|
uint32_t index,
|
||||||
|
NativeEntry *pEntry);
|
||||||
private:
|
private:
|
||||||
typedef NameHashSet<ke::RefPtr<Native>, Native> NativeCache;
|
|
||||||
|
|
||||||
List<IfaceInfo> m_Interfaces;
|
List<IfaceInfo> m_Interfaces;
|
||||||
HandleType_t m_TypeRoot;
|
HandleType_t m_TypeRoot;
|
||||||
IdentityToken_t m_IdentRoot;
|
IdentityToken_t m_IdentRoot;
|
||||||
HandleType_t m_IfaceType;
|
HandleType_t m_IfaceType;
|
||||||
IdentityType_t m_CoreType;
|
IdentityType_t m_CoreType;
|
||||||
NativeCache m_NtvCache;
|
KTrie<NativeEntry *> m_NtvCache;
|
||||||
StringHashMap<Capability> m_caps;
|
KTrie<Capability> m_caps;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ShareSystem g_ShareSys;
|
extern ShareSystem g_ShareSys;
|
||||||
+6
-6
@@ -31,10 +31,10 @@
|
|||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "TimerSys.h"
|
#include "TimerSys.h"
|
||||||
|
#include "ForwardSys.h"
|
||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include "frame_hooks.h"
|
#include "frame_hooks.h"
|
||||||
#include "ConVarManager.h"
|
#include "ConVarManager.h"
|
||||||
#include "logic_bridge.h"
|
|
||||||
|
|
||||||
#define TIMER_MIN_ACCURACY 0.1
|
#define TIMER_MIN_ACCURACY 0.1
|
||||||
|
|
||||||
@@ -180,9 +180,9 @@ TimerSystem::~TimerSystem()
|
|||||||
|
|
||||||
void TimerSystem::OnSourceModAllInitialized()
|
void TimerSystem::OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
sharesys->AddInterface(NULL, this);
|
g_ShareSys.AddInterface(NULL, this);
|
||||||
m_pOnGameFrame = forwardsys->CreateForward("OnGameFrame", ET_Ignore, 0, NULL);
|
m_pOnGameFrame = g_Forwards.CreateForward("OnGameFrame", ET_Ignore, 0, NULL);
|
||||||
m_pOnMapTimeLeftChanged = forwardsys->CreateForward("OnMapTimeLeftChanged", ET_Ignore, 0, NULL);
|
m_pOnMapTimeLeftChanged = g_Forwards.CreateForward("OnMapTimeLeftChanged", ET_Ignore, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimerSystem::OnSourceModGameInitialized()
|
void TimerSystem::OnSourceModGameInitialized()
|
||||||
@@ -198,8 +198,8 @@ void TimerSystem::OnSourceModGameInitialized()
|
|||||||
void TimerSystem::OnSourceModShutdown()
|
void TimerSystem::OnSourceModShutdown()
|
||||||
{
|
{
|
||||||
SetMapTimer(NULL);
|
SetMapTimer(NULL);
|
||||||
forwardsys->ReleaseForward(m_pOnGameFrame);
|
g_Forwards.ReleaseForward(m_pOnGameFrame);
|
||||||
forwardsys->ReleaseForward(m_pOnMapTimeLeftChanged);
|
g_Forwards.ReleaseForward(m_pOnMapTimeLeftChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimerSystem::OnSourceModLevelEnd()
|
void TimerSystem::OnSourceModLevelEnd()
|
||||||
|
|||||||
+1
-1
@@ -32,11 +32,11 @@
|
|||||||
#ifndef _INCLUDE_SOURCEMOD_CTIMERSYS_H_
|
#ifndef _INCLUDE_SOURCEMOD_CTIMERSYS_H_
|
||||||
#define _INCLUDE_SOURCEMOD_CTIMERSYS_H_
|
#define _INCLUDE_SOURCEMOD_CTIMERSYS_H_
|
||||||
|
|
||||||
|
#include "ShareSys.h"
|
||||||
#include <ITimerSystem.h>
|
#include <ITimerSystem.h>
|
||||||
#include <sh_stack.h>
|
#include <sh_stack.h>
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include "sm_globals.h"
|
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
using namespace SourceMod;
|
using namespace SourceMod;
|
||||||
|
|||||||
+20
-199
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2013 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2013 AlliedModders LLC. All rights reserved.
|
||||||
@@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include <google/protobuf/descriptor.h>
|
#include <google/protobuf/descriptor.h>
|
||||||
#include <amtl/am-string.h>
|
|
||||||
|
|
||||||
#define GETCHECK_FIELD() \
|
#define GETCHECK_FIELD() \
|
||||||
const protobuf::FieldDescriptor *field = msg->GetDescriptor()->FindFieldByName(pszFieldName); \
|
const protobuf::FieldDescriptor *field = msg->GetDescriptor()->FindFieldByName(pszFieldName); \
|
||||||
@@ -57,15 +56,6 @@
|
|||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK_FIELD_TYPE3(type1, type2, type3) \
|
|
||||||
protobuf::FieldDescriptor::CppType fieldType = field->cpp_type(); \
|
|
||||||
if (fieldType != protobuf::FieldDescriptor::CPPTYPE_##type1 \
|
|
||||||
&& fieldType != protobuf::FieldDescriptor::CPPTYPE_##type2 \
|
|
||||||
&& fieldType != protobuf::FieldDescriptor::CPPTYPE_##type3) \
|
|
||||||
{ \
|
|
||||||
return false; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CHECK_FIELD_REPEATED() \
|
#define CHECK_FIELD_REPEATED() \
|
||||||
if (field->label() != protobuf::FieldDescriptor::LABEL_REPEATED) \
|
if (field->label() != protobuf::FieldDescriptor::LABEL_REPEATED) \
|
||||||
{ \
|
{ \
|
||||||
@@ -103,7 +93,7 @@ public:
|
|||||||
Handle_t &hndl = (*iter);
|
Handle_t &hndl = (*iter);
|
||||||
HandleSecurity sec;
|
HandleSecurity sec;
|
||||||
sec.pIdentity = g_pCoreIdent;
|
sec.pIdentity = g_pCoreIdent;
|
||||||
handlesys->FreeHandle(hndl, &sec);
|
g_HandleSys.FreeHandle(hndl, &sec);
|
||||||
iter = childHandles.erase(iter);
|
iter = childHandles.erase(iter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,13 +108,6 @@ public:
|
|||||||
return msg;
|
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)
|
inline bool GetInt32(const char *pszFieldName, int32 *out)
|
||||||
{
|
{
|
||||||
GETCHECK_FIELD();
|
GETCHECK_FIELD();
|
||||||
@@ -333,199 +316,75 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool GetInt32OrUnsignedOrEnum(const char *pszFieldName, int32 *out)
|
inline bool GetInt32OrUnsigned(const char *pszFieldName, int32 *out)
|
||||||
{
|
{
|
||||||
GETCHECK_FIELD();
|
GETCHECK_FIELD();
|
||||||
CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
|
CHECK_FIELD_TYPE2(INT32, UINT32);
|
||||||
CHECK_FIELD_NOT_REPEATED();
|
CHECK_FIELD_NOT_REPEATED();
|
||||||
|
|
||||||
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
|
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
|
||||||
*out = (int32)msg->GetReflection()->GetUInt32(*msg, field);
|
*out = (int32)msg->GetReflection()->GetUInt32(*msg, field);
|
||||||
else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
|
|
||||||
*out = msg->GetReflection()->GetInt32(*msg, field);
|
|
||||||
else // CPPTYPE_ENUM
|
|
||||||
*out = msg->GetReflection()->GetEnum(*msg, field)->number();
|
|
||||||
|
|
||||||
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
|
else
|
||||||
*out = msg->GetReflection()->GetInt64(*msg, field);
|
*out = msg->GetReflection()->GetInt32(*msg, field);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool SetInt32OrUnsignedOrEnum(const char *pszFieldName, int32 value)
|
inline bool SetInt32OrUnsigned(const char *pszFieldName, int32 value)
|
||||||
{
|
{
|
||||||
GETCHECK_FIELD();
|
GETCHECK_FIELD();
|
||||||
CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
|
CHECK_FIELD_TYPE2(INT32, UINT32);
|
||||||
CHECK_FIELD_NOT_REPEATED();
|
CHECK_FIELD_NOT_REPEATED();
|
||||||
|
|
||||||
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
|
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
|
||||||
{
|
|
||||||
msg->GetReflection()->SetUInt32(msg, field, (uint32)value);
|
msg->GetReflection()->SetUInt32(msg, field, (uint32)value);
|
||||||
}
|
|
||||||
else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
|
|
||||||
{
|
|
||||||
msg->GetReflection()->SetInt32(msg, field, value);
|
|
||||||
}
|
|
||||||
else // CPPTYPE_ENUM
|
|
||||||
{
|
|
||||||
const protobuf::EnumValueDescriptor *pEnumValue = field->enum_type()->FindValueByNumber(value);
|
|
||||||
if (!pEnumValue)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
msg->GetReflection()->SetEnum(msg, field, pEnumValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
else
|
||||||
{
|
msg->GetReflection()->SetInt32(msg, field, value);
|
||||||
msg->GetReflection()->SetInt64(msg, field, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool GetRepeatedInt32OrUnsignedOrEnum(const char *pszFieldName, int index, int32 *out)
|
inline bool GetRepeatedInt32OrUnsigned(const char *pszFieldName, int index, int32 *out)
|
||||||
{
|
{
|
||||||
GETCHECK_FIELD();
|
GETCHECK_FIELD();
|
||||||
CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
|
CHECK_FIELD_TYPE2(INT32, UINT32);
|
||||||
CHECK_FIELD_REPEATED();
|
CHECK_FIELD_REPEATED();
|
||||||
CHECK_REPEATED_ELEMENT(index);
|
CHECK_REPEATED_ELEMENT(index);
|
||||||
|
|
||||||
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
|
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
|
||||||
*out = (int32)msg->GetReflection()->GetRepeatedUInt32(*msg, field, index);
|
*out = (int32)msg->GetReflection()->GetRepeatedUInt32(*msg, field, index);
|
||||||
else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
|
else
|
||||||
*out = msg->GetReflection()->GetRepeatedInt32(*msg, field, index);
|
*out = msg->GetReflection()->GetRepeatedInt32(*msg, field, index);
|
||||||
else // CPPTYPE_ENUM
|
|
||||||
*out = msg->GetReflection()->GetRepeatedEnum(*msg, field, index)->number();
|
|
||||||
|
|
||||||
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool SetRepeatedInt32OrUnsignedOrEnum(const char *pszFieldName, int index, int32 value)
|
inline bool SetRepeatedInt32OrUnsigned(const char *pszFieldName, int index, int32 value)
|
||||||
{
|
{
|
||||||
GETCHECK_FIELD();
|
GETCHECK_FIELD();
|
||||||
CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
|
CHECK_FIELD_TYPE2(INT32, UINT32);
|
||||||
CHECK_FIELD_REPEATED();
|
CHECK_FIELD_REPEATED();
|
||||||
CHECK_REPEATED_ELEMENT(index);
|
CHECK_REPEATED_ELEMENT(index);
|
||||||
|
|
||||||
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
|
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
|
||||||
{
|
|
||||||
msg->GetReflection()->SetRepeatedUInt32(msg, field, index, (uint32)value);
|
msg->GetReflection()->SetRepeatedUInt32(msg, field, index, (uint32)value);
|
||||||
}
|
|
||||||
else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
|
|
||||||
{
|
|
||||||
msg->GetReflection()->SetRepeatedInt32(msg, field, index, value);
|
|
||||||
}
|
|
||||||
else // CPPTYPE_ENUM
|
|
||||||
{
|
|
||||||
const protobuf::EnumValueDescriptor *pEnumValue = field->enum_type()->FindValueByNumber(value);
|
|
||||||
if (!pEnumValue)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
msg->GetReflection()->SetRepeatedEnum(msg, field, index, pEnumValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
else
|
||||||
{
|
msg->GetReflection()->SetRepeatedInt32(msg, field, index, value);
|
||||||
msg->GetReflection()->SetRepeatedInt64(msg, field, index, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool AddInt32OrUnsignedOrEnum(const char *pszFieldName, int32 value)
|
inline bool AddInt32OrUnsigned(const char *pszFieldName, int32 value)
|
||||||
{
|
{
|
||||||
GETCHECK_FIELD();
|
GETCHECK_FIELD();
|
||||||
CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
|
CHECK_FIELD_TYPE2(INT32, UINT32);
|
||||||
CHECK_FIELD_REPEATED();
|
CHECK_FIELD_REPEATED();
|
||||||
|
|
||||||
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
|
if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
|
||||||
{
|
|
||||||
msg->GetReflection()->AddUInt32(msg, field, (uint32)value);
|
msg->GetReflection()->AddUInt32(msg, field, (uint32)value);
|
||||||
}
|
|
||||||
else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
|
|
||||||
{
|
|
||||||
msg->GetReflection()->AddInt32(msg, field, value);
|
|
||||||
}
|
|
||||||
else // CPPTYPE_ENUM
|
|
||||||
{
|
|
||||||
const protobuf::EnumValueDescriptor *pEnumValue = field->enum_type()->FindValueByNumber(value);
|
|
||||||
if (!pEnumValue)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
msg->GetReflection()->AddEnum(msg, field, pEnumValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
else
|
||||||
{
|
msg->GetReflection()->AddInt32(msg, field, value);
|
||||||
msg->GetReflection()->AddInt64(msg, field, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -764,7 +623,7 @@ public:
|
|||||||
CHECK_FIELD_NOT_REPEATED();
|
CHECK_FIELD_NOT_REPEATED();
|
||||||
|
|
||||||
std::string scratch;
|
std::string scratch;
|
||||||
ke::SafeStrcpy(out, size, msg->GetReflection()->GetStringReference(*msg, field, &scratch).c_str());
|
strncopy(out, msg->GetReflection()->GetStringReference(*msg, field, &scratch).c_str(), size);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -787,7 +646,7 @@ public:
|
|||||||
CHECK_REPEATED_ELEMENT(index);
|
CHECK_REPEATED_ELEMENT(index);
|
||||||
|
|
||||||
std::string scratch;
|
std::string scratch;
|
||||||
ke::SafeStrcpy(out, size, msg->GetReflection()->GetRepeatedStringReference(*msg, field, index, &scratch).c_str());
|
strncopy(out, msg->GetReflection()->GetRepeatedStringReference(*msg, field, index, &scratch).c_str(), size);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -816,9 +675,6 @@ public:
|
|||||||
|
|
||||||
inline bool GetColor(const char *pszFieldName, Color *out)
|
inline bool GetColor(const char *pszFieldName, Color *out)
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE != SE_CSGO
|
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
GETCHECK_FIELD();
|
GETCHECK_FIELD();
|
||||||
CHECK_FIELD_TYPE(MESSAGE);
|
CHECK_FIELD_TYPE(MESSAGE);
|
||||||
CHECK_FIELD_NOT_REPEATED();
|
CHECK_FIELD_NOT_REPEATED();
|
||||||
@@ -832,14 +688,10 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool SetColor(const char *pszFieldName, const Color &value)
|
inline bool SetColor(const char *pszFieldName, const Color &value)
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE != SE_CSGO
|
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
GETCHECK_FIELD();
|
GETCHECK_FIELD();
|
||||||
CHECK_FIELD_TYPE(MESSAGE);
|
CHECK_FIELD_TYPE(MESSAGE);
|
||||||
CHECK_FIELD_NOT_REPEATED();
|
CHECK_FIELD_NOT_REPEATED();
|
||||||
@@ -851,14 +703,10 @@ public:
|
|||||||
msgRGBA->set_a(value.a());
|
msgRGBA->set_a(value.a());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool GetRepeatedColor(const char *pszFieldName, int index, Color *out)
|
inline bool GetRepeatedColor(const char *pszFieldName, int index, Color *out)
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE != SE_CSGO
|
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
GETCHECK_FIELD();
|
GETCHECK_FIELD();
|
||||||
CHECK_FIELD_TYPE(MESSAGE);
|
CHECK_FIELD_TYPE(MESSAGE);
|
||||||
CHECK_FIELD_REPEATED();
|
CHECK_FIELD_REPEATED();
|
||||||
@@ -873,14 +721,10 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool SetRepeatedColor(const char *pszFieldName, int index, const Color &value)
|
inline bool SetRepeatedColor(const char *pszFieldName, int index, const Color &value)
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE != SE_CSGO
|
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
GETCHECK_FIELD();
|
GETCHECK_FIELD();
|
||||||
CHECK_FIELD_TYPE(MESSAGE);
|
CHECK_FIELD_TYPE(MESSAGE);
|
||||||
CHECK_FIELD_REPEATED();
|
CHECK_FIELD_REPEATED();
|
||||||
@@ -893,14 +737,10 @@ public:
|
|||||||
msgRGBA->set_a(value.a());
|
msgRGBA->set_a(value.a());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool AddColor(const char *pszFieldName, const Color &value)
|
inline bool AddColor(const char *pszFieldName, const Color &value)
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE != SE_CSGO
|
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
GETCHECK_FIELD();
|
GETCHECK_FIELD();
|
||||||
CHECK_FIELD_TYPE(MESSAGE);
|
CHECK_FIELD_TYPE(MESSAGE);
|
||||||
CHECK_FIELD_REPEATED();
|
CHECK_FIELD_REPEATED();
|
||||||
@@ -912,7 +752,6 @@ public:
|
|||||||
msgRGBA->set_a(value.a());
|
msgRGBA->set_a(value.a());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool GetVector2D(const char *pszFieldName, Vector2D *out)
|
inline bool GetVector2D(const char *pszFieldName, Vector2D *out)
|
||||||
@@ -1185,24 +1024,6 @@ public:
|
|||||||
return msg->GetReflection()->FieldSize(*msg, field);
|
return msg->GetReflection()->FieldSize(*msg, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool RemoveRepeatedFieldValue(const char *pszFieldName, int index)
|
|
||||||
{
|
|
||||||
GETCHECK_FIELD();
|
|
||||||
CHECK_FIELD_REPEATED();
|
|
||||||
CHECK_REPEATED_ELEMENT(index);
|
|
||||||
|
|
||||||
// Protobuf guarantees that repeated field values will stay in order and so must we.
|
|
||||||
const protobuf::Reflection *pReflection = msg->GetReflection();
|
|
||||||
for (int i = index; i < elemCount - 1; ++i)
|
|
||||||
{
|
|
||||||
pReflection->SwapElements(msg, field, i, i + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
pReflection->RemoveLast(msg, field);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
protobuf::Message *msg;
|
protobuf::Message *msg;
|
||||||
PBHandleList childHandles;
|
PBHandleList childHandles;
|
||||||
|
|||||||
+38
-50
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
|
||||||
@@ -31,12 +31,10 @@
|
|||||||
|
|
||||||
#include "UserMessages.h"
|
#include "UserMessages.h"
|
||||||
#include "sm_stringutil.h"
|
#include "sm_stringutil.h"
|
||||||
#include "logic_bridge.h"
|
|
||||||
|
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
#if SOURCE_ENGINE == SE_CSGO
|
||||||
#include <cstrike15_usermessage_helpers.h>
|
#include <cstrike15_usermessage_helpers.h>
|
||||||
#endif
|
#endif
|
||||||
#include <amtl/am-string.h>
|
|
||||||
|
|
||||||
UserMessages g_UserMsgs;
|
UserMessages g_UserMsgs;
|
||||||
|
|
||||||
@@ -55,6 +53,7 @@ UserMessages::UserMessages()
|
|||||||
#ifndef USE_PROTOBUF_USERMESSAGES
|
#ifndef USE_PROTOBUF_USERMESSAGES
|
||||||
: m_InterceptBuffer(m_pBase, 2500)
|
: m_InterceptBuffer(m_pBase, 2500)
|
||||||
{
|
{
|
||||||
|
m_Names = sm_trie_create();
|
||||||
#else
|
#else
|
||||||
: m_InterceptBuffer(NULL)
|
: m_InterceptBuffer(NULL)
|
||||||
{
|
{
|
||||||
@@ -68,6 +67,10 @@ UserMessages::UserMessages()
|
|||||||
|
|
||||||
UserMessages::~UserMessages()
|
UserMessages::~UserMessages()
|
||||||
{
|
{
|
||||||
|
#ifndef USE_PROTOBUF_USERMESSAGES
|
||||||
|
sm_trie_destroy(m_Names);
|
||||||
|
#endif
|
||||||
|
|
||||||
CStack<ListenerInfo *>::iterator iter;
|
CStack<ListenerInfo *>::iterator iter;
|
||||||
for (iter=m_FreeListeners.begin(); iter!=m_FreeListeners.end(); iter++)
|
for (iter=m_FreeListeners.begin(); iter!=m_FreeListeners.end(); iter++)
|
||||||
{
|
{
|
||||||
@@ -86,7 +89,7 @@ void UserMessages::OnSourceModStartup(bool late)
|
|||||||
|
|
||||||
void UserMessages::OnSourceModAllInitialized()
|
void UserMessages::OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
sharesys->AddInterface(NULL, this);
|
g_ShareSys.AddInterface(NULL, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserMessages::OnSourceModAllShutdown()
|
void UserMessages::OnSourceModAllShutdown()
|
||||||
@@ -94,13 +97,13 @@ void UserMessages::OnSourceModAllShutdown()
|
|||||||
if (m_HookCount)
|
if (m_HookCount)
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
#if SOURCE_ENGINE == SE_CSGO
|
||||||
SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Pre), false);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, SendUserMessage, engine, this, &UserMessages::OnSendUserMessage_Pre, false);
|
||||||
SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Post), true);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, SendUserMessage, engine, this, &UserMessages::OnSendUserMessage_Post, true);
|
||||||
#else
|
#else
|
||||||
SH_REMOVE_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Pre), false);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, UserMessageBegin, engine, this, &UserMessages::OnStartMessage_Pre, false);
|
||||||
SH_REMOVE_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Post), true);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, UserMessageBegin, engine, this, &UserMessages::OnStartMessage_Post, true);
|
||||||
SH_REMOVE_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Pre), false);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, MessageEnd, engine, this, &UserMessages::OnMessageEnd_Pre, false);
|
||||||
SH_REMOVE_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Post), true);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, MessageEnd, engine, this, &UserMessages::OnMessageEnd_Post, true);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
m_HookCount = 0;
|
m_HookCount = 0;
|
||||||
@@ -112,9 +115,9 @@ int UserMessages::GetMessageIndex(const char *msg)
|
|||||||
// Can split this per engine and/or game later
|
// Can split this per engine and/or game later
|
||||||
return g_Cstrike15UsermessageHelpers.GetIndex(msg);
|
return g_Cstrike15UsermessageHelpers.GetIndex(msg);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int msgid;
|
int msgid;
|
||||||
if (!m_Names.retrieve(msg, &msgid))
|
|
||||||
|
if (!sm_trie_retrieve(m_Names, msg, reinterpret_cast<void **>(&msgid)))
|
||||||
{
|
{
|
||||||
if (m_FallbackSearch)
|
if (m_FallbackSearch)
|
||||||
{
|
{
|
||||||
@@ -126,7 +129,7 @@ int UserMessages::GetMessageIndex(const char *msg)
|
|||||||
{
|
{
|
||||||
if (strcmp(msgbuf, msg) == 0)
|
if (strcmp(msgbuf, msg) == 0)
|
||||||
{
|
{
|
||||||
m_Names.insert(msg, msgid);
|
sm_trie_insert(m_Names, msg, reinterpret_cast<void *>(msgid));
|
||||||
return msgid;
|
return msgid;
|
||||||
}
|
}
|
||||||
msgid++;
|
msgid++;
|
||||||
@@ -136,7 +139,9 @@ int UserMessages::GetMessageIndex(const char *msg)
|
|||||||
msgid = g_SMAPI->FindUserMessage(msg);
|
msgid = g_SMAPI->FindUserMessage(msg);
|
||||||
|
|
||||||
if (msgid != INVALID_MESSAGE_ID)
|
if (msgid != INVALID_MESSAGE_ID)
|
||||||
m_Names.insert(msg, msgid);
|
{
|
||||||
|
sm_trie_insert(m_Names, msg, reinterpret_cast<void *>(msgid));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return msgid;
|
return msgid;
|
||||||
@@ -145,14 +150,12 @@ int UserMessages::GetMessageIndex(const char *msg)
|
|||||||
|
|
||||||
bool UserMessages::GetMessageName(int msgid, char *buffer, size_t maxlength) const
|
bool UserMessages::GetMessageName(int msgid, char *buffer, size_t maxlength) const
|
||||||
{
|
{
|
||||||
#ifdef USE_PROTOBUF_USERMESSAGES
|
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
#if SOURCE_ENGINE == SE_CSGO
|
||||||
const char *pszName = g_Cstrike15UsermessageHelpers.GetName(msgid);
|
const char *pszName = g_Cstrike15UsermessageHelpers.GetName(msgid);
|
||||||
#endif
|
|
||||||
if (!pszName)
|
if (!pszName)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ke::SafeStrcpy(buffer, maxlength, pszName);
|
strncopy(buffer, pszName, maxlength);
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
if (m_FallbackSearch)
|
if (m_FallbackSearch)
|
||||||
@@ -165,7 +168,7 @@ bool UserMessages::GetMessageName(int msgid, char *buffer, size_t maxlength) con
|
|||||||
|
|
||||||
if (msg)
|
if (msg)
|
||||||
{
|
{
|
||||||
ke::SafeStrcpy(buffer, maxlength, msg);
|
strncopy(buffer, msg, maxlength);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +259,7 @@ google::protobuf::Message *UserMessages::StartProtobufMessage(int msg_id, const
|
|||||||
if (m_CurFlags & USERMSG_BLOCKHOOKS)
|
if (m_CurFlags & USERMSG_BLOCKHOOKS)
|
||||||
{
|
{
|
||||||
// direct message creation, return buffer "from engine". keep track
|
// direct message creation, return buffer "from engine". keep track
|
||||||
m_FakeEngineBuffer = GetMessagePrototype(msg_id)->New();
|
m_FakeEngineBuffer = g_Cstrike15UsermessageHelpers.GetPrototype(msg_id)->New();
|
||||||
buffer = m_FakeEngineBuffer;
|
buffer = m_FakeEngineBuffer;
|
||||||
} else {
|
} else {
|
||||||
char messageName[32];
|
char messageName[32];
|
||||||
@@ -271,12 +274,12 @@ google::protobuf::Message *UserMessages::StartProtobufMessage(int msg_id, const
|
|||||||
{
|
{
|
||||||
case MRES_IGNORED:
|
case MRES_IGNORED:
|
||||||
case MRES_HANDLED:
|
case MRES_HANDLED:
|
||||||
m_FakeEngineBuffer = GetMessagePrototype(msg_id)->New();
|
m_FakeEngineBuffer = g_Cstrike15UsermessageHelpers.GetPrototype(msg_id)->New();
|
||||||
buffer = m_FakeEngineBuffer;
|
buffer = m_FakeEngineBuffer;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MRES_OVERRIDE:
|
case MRES_OVERRIDE:
|
||||||
m_FakeEngineBuffer = GetMessagePrototype(msg_id)->New();
|
m_FakeEngineBuffer = g_Cstrike15UsermessageHelpers.GetPrototype(msg_id)->New();
|
||||||
// fallthrough
|
// fallthrough
|
||||||
case MRES_SUPERCEDE:
|
case MRES_SUPERCEDE:
|
||||||
buffer = msg;
|
buffer = msg;
|
||||||
@@ -413,13 +416,13 @@ bool UserMessages::InternalHook(int msg_id, IBitBufUserMessageListener *pListene
|
|||||||
if (!m_HookCount++)
|
if (!m_HookCount++)
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
#if SOURCE_ENGINE == SE_CSGO
|
||||||
SH_ADD_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Pre), false);
|
SH_ADD_HOOK_MEMFUNC(IVEngineServer, SendUserMessage, engine, this, &UserMessages::OnSendUserMessage_Pre, false);
|
||||||
SH_ADD_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Post), true);
|
SH_ADD_HOOK_MEMFUNC(IVEngineServer, SendUserMessage, engine, this, &UserMessages::OnSendUserMessage_Post, true);
|
||||||
#else
|
#else
|
||||||
SH_ADD_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Pre), false);
|
SH_ADD_HOOK_MEMFUNC(IVEngineServer, UserMessageBegin, engine, this, &UserMessages::OnStartMessage_Pre, false);
|
||||||
SH_ADD_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Post), true);
|
SH_ADD_HOOK_MEMFUNC(IVEngineServer, UserMessageBegin, engine, this, &UserMessages::OnStartMessage_Post, true);
|
||||||
SH_ADD_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Pre), false);
|
SH_ADD_HOOK_MEMFUNC(IVEngineServer, MessageEnd, engine, this, &UserMessages::OnMessageEnd_Pre, false);
|
||||||
SH_ADD_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Post), true);
|
SH_ADD_HOOK_MEMFUNC(IVEngineServer, MessageEnd, engine, this, &UserMessages::OnMessageEnd_Post, true);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,15 +436,6 @@ bool UserMessages::InternalHook(int msg_id, IBitBufUserMessageListener *pListene
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_PROTOBUF_USERMESSAGES
|
|
||||||
const protobuf::Message *UserMessages::GetMessagePrototype(int msg_type)
|
|
||||||
{
|
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
|
||||||
return g_Cstrike15UsermessageHelpers.GetPrototype(msg_type);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_PROTOBUF_USERMESSAGES
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
||||||
bool UserMessages::InternalUnhook(int msg_id, IProtobufUserMessageListener *pListener, bool intercept, bool isNew)
|
bool UserMessages::InternalUnhook(int msg_id, IProtobufUserMessageListener *pListener, bool intercept, bool isNew)
|
||||||
#else
|
#else
|
||||||
@@ -488,13 +482,13 @@ void UserMessages::_DecRefCounter()
|
|||||||
if (--m_HookCount == 0)
|
if (--m_HookCount == 0)
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
#if SOURCE_ENGINE == SE_CSGO
|
||||||
SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Pre), false);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, SendUserMessage, engine, this, &UserMessages::OnSendUserMessage_Pre, false);
|
||||||
SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Post), true);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, SendUserMessage, engine, this, &UserMessages::OnSendUserMessage_Post, true);
|
||||||
#else
|
#else
|
||||||
SH_REMOVE_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Pre), false);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, UserMessageBegin, engine, this, &UserMessages::OnStartMessage_Pre, false);
|
||||||
SH_REMOVE_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Post), true);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, UserMessageBegin, engine, this, &UserMessages::OnStartMessage_Post, true);
|
||||||
SH_REMOVE_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Pre), false);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, MessageEnd, engine, this, &UserMessages::OnMessageEnd_Pre, false);
|
||||||
SH_REMOVE_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Post), true);
|
SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, MessageEnd, engine, this, &UserMessages::OnMessageEnd_Post, true);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -502,9 +496,7 @@ void UserMessages::_DecRefCounter()
|
|||||||
#if SOURCE_ENGINE == SE_CSGO
|
#if SOURCE_ENGINE == SE_CSGO
|
||||||
void UserMessages::OnSendUserMessage_Pre(IRecipientFilter &filter, int msg_type, const protobuf::Message &msg)
|
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));
|
OnStartMessage_Pre(&filter, msg_type, g_Cstrike15UsermessageHelpers.GetName(msg_type));
|
||||||
#endif
|
|
||||||
if (m_FakeMetaRes == MRES_SUPERCEDE)
|
if (m_FakeMetaRes == MRES_SUPERCEDE)
|
||||||
{
|
{
|
||||||
int size = msg.ByteSize();
|
int size = msg.ByteSize();
|
||||||
@@ -517,9 +509,7 @@ void UserMessages::OnSendUserMessage_Pre(IRecipientFilter &filter, int msg_type,
|
|||||||
m_FakeEngineBuffer = &const_cast<protobuf::Message &>(msg);
|
m_FakeEngineBuffer = &const_cast<protobuf::Message &>(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
|
||||||
OnStartMessage_Post(&filter, msg_type, g_Cstrike15UsermessageHelpers.GetName(msg_type));
|
OnStartMessage_Post(&filter, msg_type, g_Cstrike15UsermessageHelpers.GetName(msg_type));
|
||||||
#endif
|
|
||||||
|
|
||||||
OnMessageEnd_Pre();
|
OnMessageEnd_Pre();
|
||||||
if (m_FakeMetaRes == MRES_SUPERCEDE)
|
if (m_FakeMetaRes == MRES_SUPERCEDE)
|
||||||
@@ -579,8 +569,7 @@ bf_write *UserMessages::OnStartMessage_Pre(IRecipientFilter *filter, int msg_typ
|
|||||||
#ifdef USE_PROTOBUF_USERMESSAGES
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
||||||
if (m_InterceptBuffer)
|
if (m_InterceptBuffer)
|
||||||
delete m_InterceptBuffer;
|
delete m_InterceptBuffer;
|
||||||
m_InterceptBuffer = GetMessagePrototype(msg_type)->New();
|
m_InterceptBuffer = g_Cstrike15UsermessageHelpers.GetPrototype(msg_type)->New();
|
||||||
|
|
||||||
UM_RETURN_META_VALUE(MRES_SUPERCEDE, m_InterceptBuffer);
|
UM_RETURN_META_VALUE(MRES_SUPERCEDE, m_InterceptBuffer);
|
||||||
#else
|
#else
|
||||||
m_InterceptBuffer.Reset();
|
m_InterceptBuffer.Reset();
|
||||||
@@ -776,8 +765,7 @@ void UserMessages::OnMessageEnd_Pre()
|
|||||||
int size = m_OrigBuffer->ByteSize();
|
int size = m_OrigBuffer->ByteSize();
|
||||||
uint8 *data = (uint8 *)stackalloc(size);
|
uint8 *data = (uint8 *)stackalloc(size);
|
||||||
m_OrigBuffer->SerializePartialToArray(data, size);
|
m_OrigBuffer->SerializePartialToArray(data, size);
|
||||||
|
protobuf::Message *pTempMsg = g_Cstrike15UsermessageHelpers.GetPrototype(m_CurId)->New();
|
||||||
protobuf::Message *pTempMsg = GetMessagePrototype(m_CurId)->New();
|
|
||||||
pTempMsg->ParsePartialFromArray(data, size);
|
pTempMsg->ParsePartialFromArray(data, size);
|
||||||
#else
|
#else
|
||||||
bf_write *pTempMsg = m_OrigBuffer;
|
bf_write *pTempMsg = m_OrigBuffer;
|
||||||
|
|||||||
+4
-7
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 sw=4 tw=99 noet :
|
* vim: set ts=4 :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
|
||||||
@@ -32,14 +32,12 @@
|
|||||||
#ifndef _INCLUDE_SOURCEMOD_CUSERMESSAGES_H_
|
#ifndef _INCLUDE_SOURCEMOD_CUSERMESSAGES_H_
|
||||||
#define _INCLUDE_SOURCEMOD_CUSERMESSAGES_H_
|
#define _INCLUDE_SOURCEMOD_CUSERMESSAGES_H_
|
||||||
|
|
||||||
|
#include "ShareSys.h"
|
||||||
#include <IUserMessages.h>
|
#include <IUserMessages.h>
|
||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include <sm_stringhashmap.h>
|
#include "sm_trie.h"
|
||||||
#include "sm_stringutil.h"
|
#include "sm_stringutil.h"
|
||||||
#include "CellRecipientFilter.h"
|
#include "CellRecipientFilter.h"
|
||||||
#include "sm_globals.h"
|
|
||||||
#include <sh_list.h>
|
|
||||||
#include <sh_stack.h>
|
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
using namespace SourceMod;
|
using namespace SourceMod;
|
||||||
@@ -121,7 +119,6 @@ public:
|
|||||||
void OnMessageEnd_Post();
|
void OnMessageEnd_Post();
|
||||||
private:
|
private:
|
||||||
#ifdef USE_PROTOBUF_USERMESSAGES
|
#ifdef USE_PROTOBUF_USERMESSAGES
|
||||||
const protobuf::Message *GetMessagePrototype(int msg_type);
|
|
||||||
bool InternalHook(int msg_id, IProtobufUserMessageListener *pListener, bool intercept, bool isNew);
|
bool InternalHook(int msg_id, IProtobufUserMessageListener *pListener, bool intercept, bool isNew);
|
||||||
bool InternalUnhook(int msg_id, IProtobufUserMessageListener *pListener, bool intercept, bool isNew);
|
bool InternalUnhook(int msg_id, IProtobufUserMessageListener *pListener, bool intercept, bool isNew);
|
||||||
#else
|
#else
|
||||||
@@ -153,7 +150,7 @@ private:
|
|||||||
#ifndef USE_PROTOBUF_USERMESSAGES
|
#ifndef USE_PROTOBUF_USERMESSAGES
|
||||||
bool m_FallbackSearch;
|
bool m_FallbackSearch;
|
||||||
|
|
||||||
StringHashMap<int> m_Names;
|
Trie *m_Names;
|
||||||
#endif
|
#endif
|
||||||
CellRecipientFilter m_CellRecFilter;
|
CellRecipientFilter m_CellRecFilter;
|
||||||
bool m_InExec;
|
bool m_InExec;
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 noet :
|
|
||||||
// =============================================================================
|
|
||||||
// SourceMod
|
|
||||||
// Copyright (C) 2004-2015 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>.
|
|
||||||
#ifndef _INCLUDE_SOURCEMOD_CCOMMANDARGS_IMPL_H_
|
|
||||||
#define _INCLUDE_SOURCEMOD_CCOMMANDARGS_IMPL_H_
|
|
||||||
|
|
||||||
#include "sourcemm_api.h"
|
|
||||||
#include <IRootConsoleMenu.h>
|
|
||||||
#include <compat_wrappers.h>
|
|
||||||
|
|
||||||
#if SOURCE_ENGINE==SE_EPISODEONE || SOURCE_ENGINE==SE_DARKMESSIAH
|
|
||||||
class EngineArgs : public ICommandArgs
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
EngineArgs(const CCommand& _cmd)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
const char *Arg(int n) const
|
|
||||||
{
|
|
||||||
return engine->Cmd_Argv(n);
|
|
||||||
}
|
|
||||||
int ArgC() const
|
|
||||||
{
|
|
||||||
return engine->Cmd_Argc();
|
|
||||||
}
|
|
||||||
const char *ArgS() const
|
|
||||||
{
|
|
||||||
return engine->Cmd_Args();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#else
|
|
||||||
class EngineArgs : public ICommandArgs
|
|
||||||
{
|
|
||||||
const CCommand *cmd;
|
|
||||||
public:
|
|
||||||
EngineArgs(const CCommand& _cmd) : cmd(&_cmd)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
const char *Arg(int n) const
|
|
||||||
{
|
|
||||||
return cmd->Arg(n);
|
|
||||||
}
|
|
||||||
int ArgC() const
|
|
||||||
{
|
|
||||||
return cmd->ArgC();
|
|
||||||
}
|
|
||||||
const char *ArgS() const
|
|
||||||
{
|
|
||||||
return cmd->ArgS();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_CCOMMANDARGS_IMPL_H_
|
|
||||||
+72
-56
@@ -1,29 +1,33 @@
|
|||||||
// vim: set ts=4 sw=4 tw=99 et:
|
/**
|
||||||
// =============================================================================
|
* vim: set ts=4 :
|
||||||
// SourceMod
|
* =============================================================================
|
||||||
// Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* SourceMod
|
||||||
// =============================================================================
|
* Copyright (C) 2004-2008 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
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
// Free Software Foundation.
|
* 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
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
// details.
|
* 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/>.
|
* 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
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||||
// "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||||
// by the Valve Corporation. You must obey the GNU General Public License in
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||||
// all respects for all other code used. Additionally, AlliedModders LLC grants
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||||
// this exception to all derivative works. AlliedModders LLC defines further
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||||
// exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
* this exception to all derivative works. AlliedModders LLC defines further
|
||||||
// or <http://www.sourcemod.net/license.php>.
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||||
|
* or <http://www.sourcemod.net/license.php>.
|
||||||
|
*
|
||||||
|
* Version: $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
#include "sm_globals.h"
|
#include "sm_globals.h"
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
@@ -32,15 +36,10 @@
|
|||||||
#include "sm_stringutil.h"
|
#include "sm_stringutil.h"
|
||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include "compat_wrappers.h"
|
#include "compat_wrappers.h"
|
||||||
#include <amtl/am-string.h>
|
|
||||||
|
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
SH_DECL_HOOK1_void(ICvar, UnregisterConCommand, SH_NOATTRIB, 0, ConCommandBase *);
|
SH_DECL_HOOK1_void(ICvar, UnregisterConCommand, SH_NOATTRIB, 0, ConCommandBase *);
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
|
||||||
SH_DECL_HOOK2_void(ICvar, RegisterConCommand, SH_NOATTRIB, 0, ConCommandBase *, bool);
|
|
||||||
#else
|
|
||||||
SH_DECL_HOOK1_void(ICvar, RegisterConCommand, SH_NOATTRIB, 0, ConCommandBase *);
|
SH_DECL_HOOK1_void(ICvar, RegisterConCommand, SH_NOATTRIB, 0, ConCommandBase *);
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
SH_DECL_HOOK1_void(ICvar, RegisterConCommandBase, SH_NOATTRIB, 0, ConCommandBase *);
|
SH_DECL_HOOK1_void(ICvar, RegisterConCommandBase, SH_NOATTRIB, 0, ConCommandBase *);
|
||||||
#endif
|
#endif
|
||||||
@@ -65,28 +64,24 @@ public:
|
|||||||
void OnSourceModAllInitialized()
|
void OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
SH_ADD_HOOK(ICvar, UnregisterConCommand, icvar, SH_MEMBER(this, &ConCommandCleaner::UnlinkConCommandBase), false);
|
SH_ADD_HOOK_MEMFUNC(ICvar, UnregisterConCommand, icvar, this, &ConCommandCleaner::UnlinkConCommandBase, false);
|
||||||
SH_ADD_HOOK(ICvar, RegisterConCommand, icvar, SH_MEMBER(this, &ConCommandCleaner::LinkConCommandBase), false);
|
SH_ADD_HOOK_MEMFUNC(ICvar, RegisterConCommand, icvar, this, &ConCommandCleaner::LinkConCommandBase, false);
|
||||||
#else
|
#else
|
||||||
SH_ADD_HOOK(ICvar, RegisterConCommandBase, icvar, SH_MEMBER(this, &ConCommandCleaner::LinkConCommandBase), false);
|
SH_ADD_HOOK_MEMFUNC(ICvar, RegisterConCommandBase, icvar, this, &ConCommandCleaner::LinkConCommandBase, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSourceModShutdown()
|
void OnSourceModShutdown()
|
||||||
{
|
{
|
||||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||||
SH_REMOVE_HOOK(ICvar, UnregisterConCommand, icvar, SH_MEMBER(this, &ConCommandCleaner::UnlinkConCommandBase), false);
|
SH_REMOVE_HOOK_MEMFUNC(ICvar, UnregisterConCommand, icvar, this, &ConCommandCleaner::UnlinkConCommandBase, false);
|
||||||
SH_REMOVE_HOOK(ICvar, RegisterConCommand, icvar, SH_MEMBER(this, &ConCommandCleaner::LinkConCommandBase), false);
|
SH_REMOVE_HOOK_MEMFUNC(ICvar, RegisterConCommand, icvar, this, &ConCommandCleaner::LinkConCommandBase, false);
|
||||||
#else
|
#else
|
||||||
SH_REMOVE_HOOK(ICvar, RegisterConCommandBase, icvar, SH_MEMBER(this, &ConCommandCleaner::LinkConCommandBase), false);
|
SH_REMOVE_HOOK_MEMFUNC(ICvar, RegisterConCommandBase, icvar, this, &ConCommandCleaner::LinkConCommandBase, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SOURCE_ENGINE == SE_CSGO
|
|
||||||
void LinkConCommandBase(ConCommandBase *pBase, bool unknown)
|
|
||||||
#else
|
|
||||||
void LinkConCommandBase(ConCommandBase *pBase)
|
void LinkConCommandBase(ConCommandBase *pBase)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
IConCommandLinkListener *listener = IConCommandLinkListener::head;
|
IConCommandLinkListener *listener = IConCommandLinkListener::head;
|
||||||
while (listener)
|
while (listener)
|
||||||
@@ -108,20 +103,41 @@ public:
|
|||||||
listener = listener->next;
|
listener = listener->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (iter != tracked_bases.end())
|
if (pBase)
|
||||||
{
|
{
|
||||||
if ((*iter)->pBase == pBase)
|
while (iter != tracked_bases.end())
|
||||||
{
|
{
|
||||||
pInfo = (*iter);
|
if ((*iter)->pBase == pBase)
|
||||||
iter = tracked_bases.erase(iter);
|
{
|
||||||
pInfo->cls->OnUnlinkConCommandBase(pBase, pBase->GetName());
|
pInfo = (*iter);
|
||||||
delete pInfo;
|
iter = tracked_bases.erase(iter);
|
||||||
}
|
pInfo->cls->OnUnlinkConCommandBase(pBase, pBase->GetName(), true);
|
||||||
else
|
delete pInfo;
|
||||||
{
|
}
|
||||||
iter++;
|
else
|
||||||
}
|
{
|
||||||
}
|
iter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (iter != tracked_bases.end())
|
||||||
|
{
|
||||||
|
/* This is just god-awful! */
|
||||||
|
if (FindCommandBase((*iter)->name) != (*iter)->pBase)
|
||||||
|
{
|
||||||
|
pInfo = (*iter);
|
||||||
|
iter = tracked_bases.erase(iter);
|
||||||
|
pInfo->cls->OnUnlinkConCommandBase(pBase, pInfo->name, false);
|
||||||
|
delete pInfo;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddTarget(ConCommandBase *pBase, IConCommandTracker *cls)
|
void AddTarget(ConCommandBase *pBase, IConCommandTracker *cls)
|
||||||
@@ -130,7 +146,7 @@ public:
|
|||||||
|
|
||||||
info->pBase = pBase;
|
info->pBase = pBase;
|
||||||
info->cls = cls;
|
info->cls = cls;
|
||||||
ke::SafeStrcpy(info->name, sizeof(info->name), pBase->GetName());
|
strncopy(info->name, pBase->GetName(), sizeof(info->name));
|
||||||
|
|
||||||
tracked_bases.push_back(info);
|
tracked_bases.push_back(info);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
class IConCommandTracker
|
class IConCommandTracker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name) = 0;
|
virtual void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void TrackConCommandBase(ConCommandBase *pBase, IConCommandTracker *me);
|
void TrackConCommandBase(ConCommandBase *pBase, IConCommandTracker *me);
|
||||||
|
|||||||
@@ -0,0 +1,551 @@
|
|||||||
|
//========= 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
|
||||||
@@ -0,0 +1,718 @@
|
|||||||
|
//===== 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
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user