2
0
mirror of https://github.com/rehlds/rehlds.git synced 2024-12-27 07:05:43 +03:00

Merge branch 'rehlds:master' into master

This commit is contained in:
cris840 2024-11-24 06:40:55 -05:00 committed by GitHub
commit 03f7e060c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
37 changed files with 2450 additions and 433 deletions

View File

@ -25,12 +25,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1.1.3
uses: microsoft/setup-msbuild@v2
- name: Build and Run unittests
run: |
@ -70,7 +70,7 @@ jobs:
move msvc\${{ env.buildRelease }}\director.pdb publish\debug\director.pdb
- name: Deploy artifacts
uses: actions/upload-artifact@v3.1.1
uses: actions/upload-artifact@v4
with:
name: win32
path: publish/*
@ -78,90 +78,66 @@ jobs:
testdemos:
name: 'Test demos'
runs-on: ubuntu-latest
container: s1lentq/testdemos:latest
container: rehldsorg/testdemos:latest
needs: [windows]
env:
WINEDEBUG: -all
WINEDLLOVERRIDES: mshtml=
defaults:
run:
shell: bash
working-directory: ../../../opt/HLDS
working-directory: /opt/HLDS
strategy:
fail-fast: false
matrix:
test: [
{ file: 'cstrike-muliplayer-1', desc: 'CS: Multiplayer' },
{ file: 'rehlds-phys-single1', desc: 'Half-Life: Physics singleplayer' },
{ file: 'crossfire-1-multiplayer-1', desc: 'Half-Life: Multiplayer on crossfire map' },
{ file: 'shooting-hl-1', desc: 'Half-Life: Shooting with several weapons' },
]
steps:
- name: Deploying windows artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: win32
- name: Play demos
- name: Setup dependencies
run: |
chown root ~
rsync -a deps/rehlds/* .
mv $GITHUB_WORKSPACE/tests/swds.dll .
descs=(
"CS: Multiplayer"
"Half-Life: Physics singleplayer"
"Half-Life: Multiplayer on crossfire map"
"Half-Life: Shooting with several weapons"
)
demos=(
"cstrike-muliplayer-1"
"rehlds-phys-single1"
"crossfire-1-multiplayer-1"
"shooting-hl-1"
)
retVal=0
for i in "${!demos[@]}"; do
params=$(cat "testdemos/${demos[i]}.params")
echo -e "\e[1m[$((i + 1))/${#demos[@]}] \e[1;36m${descs[i]} testing...\e[0m"
echo -e " - \e[0;33mParameters $params\e[0m"
wine hlds.exe --rehlds-enable-all-hooks --rehlds-test-play "testdemos/${demos[i]}.bin" $params &> result.log || retVal=$?
if [ $retVal -ne 777 ] && [ $retVal -ne 9 ]; then
# Print with catchy messages
while read line; do
echo -e " \e[0;33m$line"
done <<< $(cat result.log | sed '0,/demo failed/I!d;/wine:/d;/./,$!d')
echo " 🔸 🔸 🔸 🔸 🔸 🔸 🔸 🔸 🔸 🔸"
while read line; do
echo -e " \e[1;31m$line";
done < rehlds_demo_error.txt
echo -e " \e[30;41mExit code: $retVal\e[0m"
echo -e "\e[1m[$((i + 1))/${#demos[@]}] \e[1;36m${descs[i]} testing...\e[1;31m Failed ❌"
exit 6 # Test demo failed
else
# Print result HLDS console
while read line; do
echo -e " \e[0;33m$line"
done <<< $(cat result.log | sed '/wine:/d;/./,$!d')
echo -e " \e[30;43mExit code: $retVal\e[0m"
echo -e "\e[1m[$((i + 1))/${#demos[@]}] \e[1;36m${descs[i]} testing...\e[1;32m Succeed ✔"
fi
done
- name: Play test
env:
demo: ${{ matrix.test.file }}
desc: ${{ matrix.test.desc }}
run: ./runTest.sh
linux:
name: 'Linux'
runs-on: ubuntu-latest
container: s1lentq/linux86buildtools:latest
container: debian:11-slim
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
run: |
dpkg --add-architecture i386
apt-get update
apt-get install -y \
gcc-multilib g++-multilib \
build-essential \
libc6-dev libc6-dev-i386 \
git cmake rsync \
g++ gcc
- name: Build and Run unittests
run: |
rm -rf build && CC=icc CXX=icpc cmake -DCMAKE_BUILD_TYPE=Unittests -B build && cmake --build build -j8
rm -rf build && cmake -DCMAKE_BUILD_TYPE=Unittests -B build && cmake --build build -j8
retVal=0
export LD_LIBRARY_PATH="rehlds/lib/linux32:$LD_LIBRARY_PATH"
./build/rehlds/engine_i486 2> /dev/null > result.log || retVal=$?
@ -183,9 +159,9 @@ jobs:
fi
shell: bash
- name: Build using Intel C++ Compiler
- name: Build using GCC Compiler
run: |
rm -rf build && CC=icc CXX=icpc cmake -B build && cmake --build build -j8
rm -rf build && cmake -B build && cmake --build build -j8
- name: Prepare HLSDK
run: |
@ -228,18 +204,12 @@ jobs:
shell: bash
- name: Deploy artifacts
uses: actions/upload-artifact@v3.1.1
uses: actions/upload-artifact@v4
id: upload-job
with:
name: linux32
path: publish/*
- name: Cleanup temporary artifacts
if: success() && steps.upload-job.outcome == 'success'
run: |
rm -rf hlsdk
rm -f appversion.h
publish:
name: 'Publish'
runs-on: ubuntu-latest
@ -247,12 +217,12 @@ jobs:
steps:
- name: Deploying linux artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: linux32
- name: Deploying windows artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: win32
@ -281,7 +251,7 @@ jobs:
7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -aoa rehlds-dbg-${{ env.APP_VERSION }}.7z debug/
- name: Publish artifacts
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
id: publish-job
if: |
startsWith(github.ref, 'refs/tags/') &&
@ -292,9 +262,3 @@ jobs:
*.7z
env:
GITHUB_TOKEN: ${{ secrets.API_TOKEN }}
- name: Cleanup temporary artifacts
if: success() && steps.publish-job.outcome == 'success'
run: |
rm -rf bin debug hlsdk
rm -f *.7z *.zip appversion.h

238
CHANGELOG.md Normal file
View File

@ -0,0 +1,238 @@
# [ReHLDS](https://github.com/ReHLDS/ReHLDS) Changelog
**ReHLDS** is a result of reverse engineering of original `HLDS` (build `6152`/`6153`) using `DWARF` debug info embedded into linux version of `HLDS`, `engine_i486.so`.
Along with reverse engineering, a lot of defects and (potential) bugs were found and fixed.
---
## [`3.13.0.788`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.13.0.788) - 2023-07-12
### Added
- Added `SV_AllowPhysent` hook by @justgo97 in [(#951)](ttps://github.com/dreamstalker/ReHLDS/pull/951)
- `GetBonePosition`: Added bone index bounds check
- `GetAttachment`: Added attachment index bounds check
- Added more checks for possible `numleaf` overflow
### Fixed
- `SV_BuildSoundMsg`: fix '`\n`' in args check
### Changed
- Revert "change destinition folder for linux build" by @wopox1337 in [(#977)](https://github.com/dreamstalker/ReHLDS/pull/977)
- Allowed the clients to connect on the server of different game: Client should be use `setinfo _gd <game>`
- Increased limit leafs `MAX_MAP_LEAFS` up to `32767`
## New Contributors
- @justgo97 made their first contribution in [(#951)](https://github.com/dreamstalker/ReHLDS/pull/951)
**Full Changelog**: [3.12.0.780...3.13.0.788](https://github.com/ReHLDS/ReHLDS/compare/3.12.0.780...3.13.0.788)
## [`3.12.0.780`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.12.0.780) - 2022-09-19
### Fixed
- `Netchan_CreateFileFragments`: Fixed a very old and rare bug with dlfile while downloading direct from server, when content of resource size is less than header size first fragment.
### Changed
- `API`: Implement `*_Precache_*`, `ClientPrintf`, `CheckUserInfo` and `AddResource` hooks by @ShadowsAdi in [(#903)](https://github.com/dreamstalker/ReHLDS/pull/903)
## New Contributors
* @ShadowsAdi made their first contribution in [(#903)](https://github.com/dreamstalker/ReHLDS/pull/903)
**Full Changelog**: [3.11.0.779...3.12.0.780](https://github.com/ReHLDS/ReHLDS/compare/3.11.0.779...3.12.0.780)
## [`3.11.0.779`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.11.0.779) - 2022-08-24
### Fixed
- `StripUnprintableWorker` did not count the null terminator [e9045e3](https://github.com/dreamstalker/ReHLDS/commit/e9045e3)
- Very old and rare bug in function `Netchan_CreateFileFragments` with dlfile hang while downloading direct from server, when content of resource size is less than header size first fragment [d76b06d](https://github.com/dreamstalker/ReHLDS/commit/d76b06d)
**Full Changelog**: [3.11.0.777...3.11.0.779](https://github.com/ReHLDS/ReHLDS/compare/3.11.0.777...3.11.0.779)
## [`3.11.0.777`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.11.0.777) - 2022-06-20
### Fixed
* Fixed `null or empty` input string in `COM_LoadFile` (`FS_Open` with input empty string `""` will succeed on some POSIX systems)
- Resolved [(#919)](https://github.com/dreamstalker/ReHLDS/issues/919)
**Full Changelog**: [3.11.0.776...3.11.0.777](https://github.com/ReHLDS/ReHLDS/compare/3.11.0.776...3.11.0.777)
## [`3.11.0.776`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.11.0.776) - 2022-04-20
### Fixed
* Fixed typo `ZONE_DYNAMIC_SIZE`
**Full Changelog**: [3.11.0.767...3.11.0.776](https://github.com/ReHLDS/ReHLDS/compare/3.11.0.767...3.11.0.776)
## [`3.11.0.767`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.11.0.767) - 2021-10-25
### Added
* Implement `SV_EmitPings()` hook by @francoromaniello in [(#858)](https://github.com/ReHLDS/ReHLDS/pull/858)
* Implement `Con_Printf()` hook by @francoromaniello in [(#861)](https://github.com/ReHLDS/ReHLDS/pull/861)
### Changed
* `API`: Add hooks `ED_Alloc()` & `ED_Free()`. by @StevenKal in [(#867)](https://github.com/ReHLDS/ReHLDS/pull/867)
* `SV_HullForEntity`: better log in `Sys_Error` by @wopox1337 in [(#843)](https://github.com/ReHLDS/ReHLDS/pull/843)
* Update on grammar/spelling by @mlgpero in [(#865)](https://github.com/ReHLDS/ReHLDS/pull/865)
## New Contributors
* @StevenKal made their first contribution in [(#867)](https://github.com/ReHLDS/ReHLDS/pull/867)
* @francoromaniello made their first contribution in [(#858)](https://github.com/ReHLDS/ReHLDS/pull/858)
* @Urufusan made their first contribution in [(#865)](https://github.com/ReHLDS/ReHLDS/pull/865)
**Full Changelog**: [v3.10.0.761...3.11.0.767](https://github.com/ReHLDS/ReHLDS/compare/v3.10.0.761...3.11.0.767)
## [`3.10.0.760`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.10.0.760) - 2021-06-23
### Changed
- Changed the destination folder for `Linux build` [(#842)](https://github.com/ReHLDS/ReHLDS/pull/842).
- Temporary removed `Windows build`. :warning:
**Full Changelog**: [3.10.0.759...3.10.0.760](https://github.com/ReHLDS/ReHLDS/compare/3.10.0.759...3.10.0.760)
## [`3.10.0.761`](https://github.com/ReHLDS/ReHLDS/releases/tag/v3.10.0.761) - 2021-06-23
### Changed
- Reset `m_bSentNewResponse` to allow new connection when the client goes through the full stage of connection (`cl:connect` -> `sv:S2C_CONNECTION` -> `cl:new` -> `SV_New_f`)
- Related [3a9bfb9](https://github.com/ReHLDS/ReHLDS/commit/3a9bfb9)
**Full Changelog**: [3.10.0.760...v3.10.0.761](https://github.com/ReHLDS/ReHLDS/compare/3.10.0.760...v3.10.0.761)
## [`3.10.0.760`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.10.0.760) - 2021-06-23
### Changed
- Changed the destination folder for `Linux build` [(#842)](https://github.com/ReHLDS/ReHLDS/pull/842).
- Temporary removed `Windows build`. :warning:
**Full Changelog**: [3.10.0.759...3.10.0.760](https://github.com/ReHLDS/ReHLDS/compare/3.10.0.759...3.10.0.760)
## [`3.10.0.759`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.10.0.759) - 2021-06-22
### Fixed
- Fixed volume checking in emit sound [(#341)](https://github.com/ReHLDS/ReHLDS/pull/341)
- `static_map.h`: fix lowercase convert [(#806)](https://github.com/ReHLDS/ReHLDS/pull/806)
- `SV_New_f`: Deny new connection twice at a time if user messages are received;
- `SV_ReadClientMessage`: Fixed empty names on bad read.
### Changed
- `sv_user.cpp`: Small code refactoring [(#810)](https://github.com/ReHLDS/ReHLDS/pull/810)
- `ReHLDS API`: Enhanced IGameClient/IRehldsServerData/IRehldsServerStatic interfaces
- `sv_main.cpp`: SV_New_f() uses Q_snprintf() unsafe format. #807 [()](https://github.com/ReHLDS/ReHLDS/pull/807)
**Full Changelog**: [3.9.0.752...3.10.0.759](https://github.com/ReHLDS/ReHLDS/compare/3.9.0.752...3.10.0.759)
## [`3.9.0.752`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.9.0.752) - 2021-06-14
### Added
- `ReHLDS API`: Add GetEntityInit hook [(#832)](https://github.com/ReHLDS/ReHLDS/pull/832)
- Implement CVar `sv_usercmd_custom_random_seed` [(#837)](https://github.com/ReHLDS/ReHLDS/pull/837)
### Fixed
- `HLTV`: Fix crash in ProcessStringCmd [(#838)](https://github.com/ReHLDS/ReHLDS/pull/838)
### Changed
- `SV_ParseMove`, `SV_ParseConsistencyResponse`: check length
**Full Changelog**: [3.8.0.739...3.9.0.752](https://github.com/ReHLDS/ReHLDS/compare/3.8.0.739...3.9.0.752)
## [`3.8.0.739`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.8.0.739) - 2021-04-21
### Added
* Added libraries libm/librt built on `GLIBC` `2.11.1` [(#827)](https://github.com/ReHLDS/ReHLDS/pull/827)
### Fixed
* `QuaternionSlerp`: Fixed wrong values [(#763)](https://github.com/ReHLDS/ReHLDS/pull/763)
### Changed
* Updated `Intel C++ Compiler` version `17.0` up to `19.0`
**Full Changelog**: [3.8.0.723...3.8.0.739](https://github.com/ReHLDS/ReHLDS/compare/3.8.0.723...3.8.0.739)
## [`3.8.0.723`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.8.0.723) - 2021-03-23
### Fixed
* `CalcSurfaceExtents:` Fixed a fatal error on some maps due loss of floating point
* `HLTV:` ExecuteString Fix parser [(#821)](https://github.com/ReHLDS/ReHLDS/pull/821)
### Changed
* `HLTV:` Downgrade GLIBC version
**Full Changelog**: [3.8.0.715...3.8.0.723](https://github.com/ReHLDS/ReHLDS/compare/3.8.0.715...3.8.0.723)
## [`3.8.0.715`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.8.0.715) - 2021-03-18
### Fixed
* Make sure the `timer` is high precision [(#799)](https://github.com/ReHLDS/ReHLDS/pull/799)
**Full Changelog**: [3.8.0.711...3.8.0.715](https://github.com/ReHLDS/ReHLDS/compare/3.8.0.711...3.8.0.715)
## [`3.8.0.711`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.8.0.711) - 2021-02-06
### Added
* `HLTV`: Added new chatdelay command [(#777)](https://github.com/ReHLDS/ReHLDS/pull/777)
* `HLTV`: prevent clients from setting userinfo * keys with setinfo command [(#792)](https://github.com/ReHLDS/ReHLDS/pull/792)
* `Cbuf_Execute`: Add checks commented out for multi-lines [(#719)](https://github.com/ReHLDS/ReHLDS/pull/719)
### Fixed
* Fixed local-buffer overrun, may undefined behavior with hitboxes blending or crash (reverse-engineering mistake) [722e19d](https://github.com/ReHLDS/ReHLDS/commit/722e19d)
* Fixed dos attack on connection challenges system [(#802)](https://github.com/ReHLDS/ReHLDS/pull/802)
* Fixed crash `COM_ListMaps` [(#791)](https://github.com/ReHLDS/ReHLDS/pull/791)
**Full Changelog**: [3.8.0.702...3.8.0.711](https://github.com/ReHLDS/ReHLDS/compare/3.8.0.702...3.8.0.711)
## [`3.8.0.702`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.8.0.702) - 2020-11-09
### Fixed
* Fixed crash `MSG_ReadFloat`
### Changed
* **ReHLDS API:** Implemented `SV_ShouldSendConsistencyList`
* **ReHLDS API:** Bump minor
**Full Changelog**: [3.7.0.698...3.8.0.702](https://github.com/ReHLDS/ReHLDS/compare/3.7.0.698...3.8.0.702)
## [`3.7.0.698`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.7.0.698) - 2020-08-19
### Added
* Graceful shutdown on sigterm [(#776)](https://github.com/ReHLDS/ReHLDS/pull/776)
- Add players kick on `SIGINT \ SIGTERM`
- Add SIGINT & SIGTERM handling linux console
### Changed
* Changed shutdown method
**Full Changelog**: [3.7.0.697...3.7.0.698](https://github.com/ReHLDS/ReHLDS/compare/3.7.0.697...3.7.0.698)
## [`3.7.0.697`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.7.0.697) - 2020-08-10
### Fixed
* **SV_ProcessFile:** Wrap `Con_Printf` in `Con_NetPrintf` to avoid spam in HLDS console
**Full Changelog**: [3.7.0.696...3.7.0.697](https://github.com/ReHLDS/ReHLDS/compare/3.7.0.696...3.7.0.697)
## [`3.7.0.696`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.7.0.696) - 2020-05-18
### Added
* Implement `svc_exec` support in the engine and HLTV [(#737)](https://github.com/ReHLDS/ReHLDS/pull/737)
- Added `svc_exec` to the list of svc commands in engine
- Added `svc_exec` support to HLTV code
- Made the engine code forward-compatible with future svc_* additions
- Added reserved svc_* slots in the enumerations
**Full Changelog**: [3.7.0.695...3.7.0.696](https://github.com/ReHLDS/ReHLDS/compare/3.7.0.695...3.7.0.696)
## [`3.7.0.695`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.7.0.695) - 2020-04-06
### Fixed
* Vulnerability fix WAD part 2
- Client-side: Fixed a potential vulnerability from bogus `tempdecal.wad`
**Full Changelog**: [3.7.0.694...3.7.0.695](https://github.com/ReHLDS/ReHLDS/compare/3.7.0.694...3.7.0.695)
## [`3.7.0.694`](https://github.com/ReHLDS/ReHLDS/releases/tag/3.7.0.694) - 2020-03-20
### Fixed
* Vulnerability fix WAD part 1
- Server-side: Fixed a potential vulnerability from bogus `tempdecal.wad`
**Full Changelog**: [3.7.0.694](https://github.com/ReHLDS/ReHLDS/commits/3.7.0.694)

View File

@ -1,4 +1,4 @@
# ReHLDS [![C/C++ CI](https://github.com/dreamstalker/rehlds/actions/workflows/build.yml/badge.svg)](https://github.com/dreamstalker/rehlds/actions/workflows/build.yml) [![Download](https://camo.githubusercontent.com/7ab483250adb4037b26e9575331218ee51108190d0938b7836d32f1209ccf907/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f647265616d7374616c6b65722f7265686c64732e737667)](https://github.com/dreamstalker/rehlds/releases/latest) [![Downloads](https://camo.githubusercontent.com/d37654956d99bb9fb7a348fdac39b214d6ae14a7cfb9f96bf873c6b46cdf9ef6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f647265616d7374616c6b65722f7265686c64732f746f74616c3f636f6c6f723d696d706f7274616e74)]() [![Percentage of issues still open](http://isitmaintained.com/badge/open/dreamstalker/rehlds.svg)](http://isitmaintained.com/project/dreamstalker/rehlds "Percentage of issues still open") [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) <img align="right" src="https://user-images.githubusercontent.com/5860435/111066129-040e5e00-84f0-11eb-9e1f-7a7e8611da2b.png" alt="ReHLDS" />
# ReHLDS [![C/C++ CI](https://github.com/rehlds/ReHLDS/actions/workflows/build.yml/badge.svg)](https://github.com/rehlds/ReHLDS/actions/workflows/build.yml) [![GitHub release (by tag)](https://img.shields.io/github/downloads/rehlds/ReHLDS/latest/total)](https://github.com/rehlds/ReHLDS/releases/latest) ![GitHub all releases](https://img.shields.io/github/downloads/rehlds/ReHLDS/total) [![Percentage of issues still open](http://isitmaintained.com/badge/open/rehlds/ReHLDS.svg)](http://isitmaintained.com/project/rehlds/ReHLDS "Percentage of issues still open") [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) <img align="right" src="https://user-images.githubusercontent.com/5860435/111066129-040e5e00-84f0-11eb-9e1f-7a7e8611da2b.png" alt="ReHLDS" />
Reverse-engineered (and bugfixed) HLDS
## What is this?
@ -15,7 +15,7 @@ You can try playing on one of many servers that are using ReHLDS: [Game Tracker]
</ul>
## How can use it?
ReHLDS is fully compatible with the official pre-anniversary edition of HLDS (engine version <= 8684) downloaded by steamcmd. All you have to do is to download rehlds binaries and replace original swds.dll/engine_i486.so. For windows you can also copy a swds.pdb file with a debug information.
ReHLDS is fully compatible with the official pre-anniversary edition of HLDS (engine version <= 8684) downloaded by steamcmd. All you have to do is to download ReHLDS binaries and replace original swds.dll/engine_i486.so. For windows you can also copy a swds.pdb file with a debug information.
<b>Warning!</b> ReHLDS is not compatible with an old 5xxx or below platforms downloaded by hldsupdatetool.
@ -27,13 +27,13 @@ app_update 90 -beta steam_legacy validate
```
## Downloads
* [Release builds](https://github.com/dreamstalker/rehlds/releases)
* [Dev builds](https://github.com/dreamstalker/rehlds/actions/workflows/build.yml)
* [Release builds](https://github.com/rehlds/ReHLDS/releases)
* [Dev builds](https://github.com/rehlds/ReHLDS/actions/workflows/build.yml)
ReHLDS binaries require `SSE`, `SSE2` and `SSE3` instruction sets to run and can benefit from `SSE4.1` and `SSE4.2`
<b>Warning!</b> ReHLDS is not binary compatible with original hlds since it's compiled with compilers other than ones used for original hlds.
This means that plugins that do binary code analysis (Orpheu for example) probably will not work with rehlds.
This means that plugins that do binary code analysis (Orpheu for example) probably will not work with ReHLDS.
## Configuring
<details>
@ -57,13 +57,18 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
<li>sv_rehlds_stringcmdrate_avg_punish // Time in minutes for which the player will be banned (0 - Permanent, use a negative number for a kick). Default: 5
<li>sv_rehlds_stringcmdrate_max_burst // Max burst level of 'string' cmds for ban. Default: 400
<li>sv_rehlds_stringcmdrate_burst_punish // Time in minutes for which the player will be banned (0 - Permanent, use a negative number for a kick). Default: 5
<li>sv_rehlds_userinfo_transmitted_fields // Userinfo fields only with these keys will be transmitted to clients via network. If not set then all fields will be transmitted (except prefixed with underscore). Each key must be prefixed by backslash, for example "\name\model\*sid\*hltv\bottomcolor\topcolor". See [wiki](https://github.com/dreamstalker/rehlds/wiki/Userinfo-keys) to collect sufficient set of keys for your server. Default: ""
<li>sv_rehlds_userinfo_transmitted_fields // Userinfo fields only with these keys will be transmitted to clients via network. If not set then all fields will be transmitted (except prefixed with underscore). Each key must be prefixed by backslash, for example "\name\model\*sid\*hltv\bottomcolor\topcolor". See [wiki](https://github.com/rehlds/ReHLDS/wiki/Userinfo-keys) to collect sufficient set of keys for your server. Default: ""
<li>sv_rehlds_attachedentities_playeranimationspeed_fix // Fixes bug with gait animation speed increase when player has some attached entities (aiments). Can cause animation lags when cl_updaterate is low. Default: 0
<li>sv_rehlds_maxclients_from_single_ip // Limit number of connections at the same time from single IP address, not confuse to already connected players. Default: 5
<li>sv_rehlds_local_gametime &lt;1|0&gt; // A feature of local gametime which decrease "lags" if you run same map for a long time. Default: 0
<li>sv_use_entity_file // Use custom entity file for a map. Path to an entity file will be "maps/[map name].ent". 0 - use original entities. 1 - use .ent files from maps directory. 2 - use .ent files from maps directory and create new .ent file if not exist.
<li>sv_usercmd_custom_random_seed // When enabled server will populate an additional random seed independent of the client. Default: 0
<li>sv_net_incoming_decompression <1|0> // When enabled server will decompress of incoming compressed file transfer payloads. Default: 1
<li>sv_net_incoming_decompression_max_ratio <0|100> // Sets the max allowed ratio between compressed and uncompressed data for file transfer. (A ratio close to 90 indicates large uncompressed data with low entropy) Default: 80.0
<li>sv_net_incoming_decompression_max_size <16|65536> // Sets the max allowed size for decompressed file transfer data. Default: 65536 bytes
<li>sv_net_incoming_decompression_punish // Time in minutes for which the player will be banned for malformed/abnormal bzip2 fragments (0 - Permanent, use a negative number for a kick). Default: -1
<li>sv_tags &lt;comma-delimited string list of tags&gt; // Sets a string defining the "gametags" for this server, this is optional, but if it is set it allows users/scripts to filter in the matchmaking/server-browser interfaces based on the value. Default: ""
<li>sv_filterban &lt;-1|0|1&gt;// Set packet filtering by IP mode. -1 - All players will be rejected without any exceptions. 0 - No checks will happen. 1 - All incoming players will be checked if they're IP banned (if they have an IP filter entry), if they are, they will be kicked. Default: 1
</ul>
</details>
@ -78,7 +83,7 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
## Build instructions
### Checking requirements
There are several software requirements for building rehlds:
There are several software requirements for building ReHLDS:
#### Windows
<pre>

View File

@ -182,6 +182,7 @@ set(ENGINE_SRCS
rehlds/public_amalgamation.cpp
rehlds/rehlds_api_impl.cpp
rehlds/rehlds_interfaces_impl.cpp
rehlds/rehlds_messagemngr_impl.cpp
rehlds/rehlds_security.cpp
)

View File

@ -1060,15 +1060,18 @@ void World::ParseClientData(BitBuffer *stream, unsigned int deltaSeqNr, BitBuffe
}
}
// When a delta command is received from the server
// We need to grab the entity # out of it any the bit settings, too
int World::ParseDeltaHeader(BitBuffer *stream, bool &remove, bool &custom, int &numbase, bool &newbl, int &newblindex, bool full, int &offset)
{
int num;
bool isdelta, isnext;
bool isdelta;
offset = 0;
custom = false;
newbl = false;
newbl = false;
// This full update (non-delta)
if (full)
{
isdelta = stream->ReadBit() ? true : false;
@ -1077,6 +1080,8 @@ int World::ParseDeltaHeader(BitBuffer *stream, bool &remove, bool &custom, int &
else
{
isdelta = false;
// the entity was removed from server or not
remove = stream->ReadBit() ? true : false;
}
@ -1088,11 +1093,11 @@ int World::ParseDeltaHeader(BitBuffer *stream, bool &remove, bool &custom, int &
{
if (stream->ReadBit())
{
num = stream->ReadBits(11);
num = stream->ReadBits(MAX_EDICT_BITS);
}
else
{
int delta = stream->ReadBits(6);
int delta = stream->ReadBits(DELTA_OFFSET_BITS);
num = delta + numbase;
}
}
@ -1105,20 +1110,19 @@ int World::ParseDeltaHeader(BitBuffer *stream, bool &remove, bool &custom, int &
if (m_MaxInstanced_BaseLine)
{
isnext = stream->ReadBit() ? true : false;
if (isnext)
newbl = stream->ReadBit() ? true : false;
if (newbl)
{
newbl = true;
newblindex = stream->ReadBits(6);
newblindex = stream->ReadBits(MAX_BASELINE_BITS);
}
}
if (full && !newbl)
{
isnext = stream->ReadBit() ? true : false;
if (isnext)
if (stream->ReadBit() != 0)
{
offset = stream->ReadBits(6);
offset = stream->ReadBits(MAX_BASELINE_BITS);
}
}
}
@ -1152,10 +1156,10 @@ int World::CompressFrame(frame_t *from, BitBuffer *stream)
unsigned char *start = stream->CurrentByte();
for (auto entnum = 0u; entnum < from->entitynum; entnum++)
{
header.num = entities[entnum].number;
header.custom = (entities[entnum].entityType & ENTITY_BEAM) == ENTITY_BEAM;
header.num = entities[entnum].number;
header.custom = (entities[entnum].entityType & ENTITY_BEAM) == ENTITY_BEAM;
header.newblindex = 0;
header.newbl = false;
header.newbl = false;
entity_state_t *baseline = &m_BaseLines[header.num];
header.offset = FindBestBaseline(entnum, &baseline, entities, header.num, header.custom);
@ -1273,26 +1277,25 @@ bool World::GetDeltaFromCache(unsigned int seqNr, unsigned int deltaNr, BitBuffe
return 0;
}
// marker an entity index that not in an old packet (for svc_packetentities)
#define ENTITY_SENTINEL 9999
void World::WritePacketEntities(BitBuffer *stream, frame_t *frame, frame_t *deltaframe)
{
int oldmax;
int oldindex;
int newindex;
int newnum;
int oldnum;
entity_state_t *frameEntities;
entity_state_t *deltaEntities;
unsigned int oldmax, oldindex, newindex;
int newnum, oldnum;
entity_state_t *frameEntities, *deltaEntities;
deltacallback_t header;
header.instanced_baseline = (m_MaxInstanced_BaseLine > 0) ? true : false;
header.num = 0;
header.offset = 0;
header.numbase = 0;
header.num = 0;
header.offset = 0;
header.numbase = 0;
header.newblindex = 0;
header.full = false;
header.newbl = false;
header.remove = false;
header.custom = false;
header.newbl = false;
header.remove = false;
header.full = false;
header.custom = false;
if (frame->delta || deltaframe->delta) {
m_System->Errorf("World::WritePacketEntities: frame and delta frame must be uncompressed.\n");
@ -1302,79 +1305,82 @@ void World::WritePacketEntities(BitBuffer *stream, frame_t *frame, frame_t *delt
m_Delta.SetTime(frame->time);
oldmax = deltaframe->entitynum;
newnum = 0; // index in frame->entities
oldnum = 0; // index in deltaframe->entities
newindex = 0; // index in frame->entities
oldindex = 0; // index in deltaframe->entities
frameEntities = (entity_state_t *)frame->entities;
deltaEntities = (entity_state_t *)deltaframe->entities;
stream->StartBitMode();
while (true)
while (newindex < frame->entitynum || oldindex < oldmax)
{
if ((unsigned)newnum < frame->entitynum)
{
newindex = frameEntities[newnum].number;
}
else
{
if (oldnum >= oldmax)
break;
newnum = (newindex >= frame->entitynum) ? ENTITY_SENTINEL : frameEntities[newindex].number;
oldnum = (oldindex >= oldmax) ? ENTITY_SENTINEL : deltaEntities[oldindex].number;
// TODO: Unreachable code
if ((unsigned)newnum < frame->entitynum)
newindex = frameEntities[newnum].number;
else
newindex = 9999;
}
if (oldnum < oldmax)
oldindex = deltaEntities[oldnum].number;
else
oldindex = 9999;
if (newindex == oldindex)
// this is a delta update of the entity from previous position
if (newnum == oldnum)
{
header.custom = (frameEntities[newnum].entityType & ENTITY_BEAM) == ENTITY_BEAM;
header.num = newindex;
// delta update from old position
// because the force parm is false, this will not result
// in any bytes being emitted if the entity has not changed at all
// note that players are always 'newentities', this updates their oldorigin always
// and prevents warping
header.custom = (frameEntities[newindex].entityType & ENTITY_BEAM) == ENTITY_BEAM;
header.num = newnum;
header.newblindex = 0;
header.newbl = false;
header.remove = false;
header.newbl = false;
header.remove = false;
delta_t *delta = GetDeltaEncoder(newindex, header.custom);
m_Delta.WriteDelta(stream, (byte *)&deltaEntities[oldnum], (byte *)&frameEntities[newnum], true, delta, &header);
delta_t *delta = GetDeltaEncoder(newnum, header.custom);
m_Delta.WriteDelta(stream, (byte *)&deltaEntities[oldindex], (byte *)&frameEntities[newindex], false, delta, &header);
oldnum++;
newnum++;
oldindex++;
newindex++;
continue;
}
if (newindex >= oldindex)
// Figure out how we want to update the entity
// This is a new entity, send it from the baseline
if (newnum < oldnum)
{
if (newindex > oldindex)
{
header.num = oldindex;
header.remove = true;
header.newbl = false;
header.newblindex = 0;
//
// If the entity was not in the old packet (oldnum == 9999),
// then delta from the baseline since this is a new entity
header.custom = (frameEntities[newindex].entityType & ENTITY_BEAM) == ENTITY_BEAM;
header.num = newnum;
header.newblindex = 0;
header.newbl = false;
header.remove = false;
m_Delta.WriteHeader(stream, &header);
++oldnum;
}
delta_t *delta = GetDeltaEncoder(newnum, header.custom);
m_Delta.WriteDelta(stream, (byte *)&m_BaseLines[newnum], (byte *)&frameEntities[newindex], true, delta, &header);
newindex++;
continue;
}
header.custom = (frameEntities[newnum].entityType & ENTITY_BEAM) == ENTITY_BEAM;
header.newblindex = 0;
header.num = newindex;
header.remove = false;
header.newbl = false;
// the old entity isn't present in the new message
if (newnum > oldnum)
{
//
// If the entity was in the old list, but is not in the new list (newindex == 9999),
// then construct a special remove message
delta_t *delta = GetDeltaEncoder(newindex, header.custom);
m_Delta.WriteDelta(stream, (byte *)&m_BaseLines[oldnum], (byte *)&frameEntities[newnum], true, delta, &header);
newnum++;
header.num = oldnum;
header.newblindex = 0;
header.newbl = false;
header.remove = true; // tell the client that entity was removed from server
m_Delta.WriteHeader(stream, &header);
oldindex++;
continue;
}
}
// No more entities.. (end of packet entities)
stream->WriteBits(0, 16);
stream->EndBitMode();
}
@ -1467,13 +1473,14 @@ double World::GetTime()
return m_WorldTime;
}
// An svc_packetentities has just been parsed, deal with the rest of the data stream
bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream, unsigned int from)
{
int newnum, oldnum;
int oldindex, newindex;
int newnum, oldnum;
unsigned int oldindex, newindex;
bool remove, custom, newbl;
int newblindex, numbase, offset;
bool remove, custom, newbl;
int newblindex, numbase, offset;
frame_t deltaFrame;
if (!GetUncompressedFrame(from, &deltaFrame)) {
@ -1485,11 +1492,15 @@ bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream, unsi
oldindex = 0;
newindex = 0;
remove = false;
custom = false;
newbl = false;
numbase = 0;
newblindex = 0;
numbase = 0;
newbl = false;
remove = false;
custom = false;
//
// Parse uncompress entities
//
m_Delta.SetTime(frame->time);
stream->StartBitMode();
@ -1500,60 +1511,75 @@ bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream, unsi
while (stream->PeekBits(16))
{
newnum = ParseDeltaHeader(stream, remove, custom, numbase, newbl, newblindex, false, offset);
oldnum = (oldindex >= deltaFrame.entitynum) ? ENTITY_SENTINEL : deltaEntity[oldindex].number;
if ((unsigned)oldindex < deltaFrame.entitynum)
oldnum = deltaEntity[oldindex].number;
else
oldnum = 9999;
while (newnum > oldnum)
while (oldnum < newnum)
{
//
// one or more entities from the old packet are unchanged
if (newindex >= MAX_PACKET_ENTITIES)
{
m_System->DPrintf("WARNING!World::UncompressEntitiesFromStream: newindex >= MAX_PACKET_ENTITIES.\n");
stream->m_Overflowed = true;
}
// copy one of the old entities over to the new packet unchanged
Q_memcpy(&entity[newindex], &deltaEntity[oldindex], sizeof(entity[newindex]));
newindex++;
oldindex++;
if ((unsigned)oldindex < deltaFrame.entitynum)
oldnum = deltaEntity[oldindex].number;
else
oldnum = 9999;
// lookup next index
oldnum = (oldindex >= deltaFrame.entitynum) ? ENTITY_SENTINEL : deltaEntity[oldindex].number;
}
if (newnum >= oldnum)
// delta from previous state
if (newnum == oldnum)
{
if (newnum == oldnum)
if (remove)
{
if (remove)
{
++oldindex;
}
else
{
entity[newindex].entityType = custom ? ENTITY_BEAM : ENTITY_NORMAL;
delta_t *delta = GetDeltaEncoder(newnum, custom);
m_Delta.ParseDelta(stream, (byte *)&deltaEntity[oldindex], (byte *)&entity[newindex], delta);
entity[newindex].number = newnum;
++newindex;
++oldindex;
}
oldindex++;
continue;
}
//
// Insert new the entity to frame
entity[newindex].entityType = custom ? ENTITY_BEAM : ENTITY_NORMAL;
delta_t *delta = GetDeltaEncoder(newnum, custom);
m_Delta.ParseDelta(stream, (byte *)&deltaEntity[oldindex], (byte *)&entity[newindex], delta);
entity[newindex].number = newnum;
newindex++;
oldindex++;
continue;
}
else if (!remove)
// Figure out how we want to update the entity
// This is a new entity, sent it from the baseline
if (newnum < oldnum)
{
//
// If the entity was not in the old packet (oldnum == 9999),
// then delta from the baseline since this is a new entity
if (remove)
{
continue;
}
if (newindex >= MAX_PACKET_ENTITIES)
{
m_System->DPrintf("World::UncompressEntitiesFromStream: newindex >= MAX_PACKET_ENTITIES.\n");
stream->m_Overflowed = true;
}
//
// Insert new the entity to frame
entity_state_t *baseline;
if (newbl)
{
@ -1574,9 +1600,12 @@ bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream, unsi
m_Delta.ParseDelta(stream, (byte *)baseline, (byte *)&entity[newindex], delta);
entity[newindex].number = newnum;
newindex++;
continue;
}
}
// peek bit == 0 end of packet entities
if (stream->ReadShort())
{
m_System->DPrintf("WARNING! World::UncompressEntitiesFromStream: missing end tag.\n");
@ -1585,7 +1614,10 @@ bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream, unsi
stream->EndBitMode();
while ((unsigned)oldindex < deltaFrame.entitynum)
// Copy all the rest of the entities from the old packet
//
while (oldindex != ENTITY_SENTINEL && oldindex < deltaFrame.entitynum)
{
if (newindex >= MAX_PACKET_ENTITIES)
{
@ -1593,33 +1625,22 @@ bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream, unsi
stream->m_Overflowed = true;
}
// copy everything to the new state we are delta'ing
Q_memcpy(&entity[newindex], &deltaEntity[oldindex], sizeof(entity[newindex]));
newindex++;
oldindex++;
}
if (newindex != frame->entitynum) {
m_System->DPrintf("WARNING! World::UncompressEntitiesFromStream: newindex != frame->entitynum.\n");
}
return true;
}
bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream)
{
int num;
int newindex = 0;
int entnum = frame->entitynum;
int num, newindex = 0;
int entnum = frame->entitynum;
entity_state_t *baseline;
bool remove, custom, newbl;
int newblindex, numbase, offset;
newblindex = 0;
numbase = 0;
remove = false;
custom = false;
newbl = false;
bool remove = false, custom = false, newbl = false;
int newblindex = 0, numbase = 0, offset;
entity_state_t *entities = (entity_state_t *)frame->entities;
m_Delta.SetTime(frame->time);
@ -2240,8 +2261,8 @@ void World::RearrangeFrame(frame_t *frame, int seqNrOffset, float timeOffset)
BitBuffer tempStream(frame->entities, frame->entitiesSize);
Q_memset(frame->entities, 0, frame->entitiesSize);
int newsize = CompressFrame(&fullFrame, &tempStream);
if ((unsigned)newsize > frame->entitiesSize || tempStream.IsOverflowed()) {
unsigned int newsize = CompressFrame(&fullFrame, &tempStream);
if (newsize > frame->entitiesSize || tempStream.IsOverflowed()) {
m_System->Printf("WARNING! World::RearrangeFrame: wrong entities size (%i != %i).\n", frame->entitiesSize, newsize);
return;
}

View File

@ -39,6 +39,9 @@
#define RESOURCE_INDEX_BITS 12
#define RESOURCE_MAX_COUNT (1 << RESOURCE_INDEX_BITS)
#define MAX_BASELINE_BITS 6
#define MAX_BASELINES (1 << MAX_BASELINE_BITS)
class World: public IWorld, public BaseSystemModule {
public:
World() {}

View File

@ -98,6 +98,9 @@
// Max size of udp packet payload
#define MAX_UDP_PACKET 4010 // 9 bytes SPLITHEADER + 4000 payload?
#define DELTA_OFFSET_BITS 6
#define DELTA_OFFSET_MAX ((1 << DELTA_OFFSET_BITS) - 1)
enum svc_commands_e
{
svc_bad,

View File

@ -195,7 +195,7 @@ bool ObjectDictionary::RemoveIndex(int index, bool freeObjectMemory)
CheckSize();
ClearCache();
return false;
return true;
}
bool ObjectDictionary::RemoveIndexRange(int minIndex, int maxIndex)

View File

@ -29,6 +29,9 @@
typedef int BOOL;
// The maximum user messages
#define MAX_USERMESSAGES 256
// user message
#define MAX_USER_MSG_DATA 192

View File

@ -717,14 +717,9 @@ NOXREF qboolean Draw_CacheReload(cachewad_t *wad, int i, lumpinfo_t *pLump, cach
qboolean Draw_ValidateCustomLogo(cachewad_t *wad, unsigned char *data, lumpinfo_t *lump)
{
texture_t tex;
miptex_t *mip;
miptex_t tmp;
int pix;
int pixoffset;
int paloffset;
int palettesize;
int nPalleteCount;
int nSize;
miptex_t *mip, tmp;
int i, pix, paloffset, palettesize;
int size;
if (wad->cacheExtra != DECAL_EXTRASIZE)
{
@ -734,58 +729,54 @@ qboolean Draw_ValidateCustomLogo(cachewad_t *wad, unsigned char *data, lumpinfo_
tex = *(texture_t *)data;
mip = (miptex_t *)(data + wad->cacheExtra);
tmp = *mip;
// Copy mip texture data
tmp = *mip;
tex.width = LittleLong(tmp.width);
tex.height = LittleLong(tmp.height);
tex.anim_max = 0;
tex.anim_min = 0;
tex.anim_total = 0;
tex.alternate_anims = NULL;
tex.anim_next = NULL;
tex.anim_total = tex.anim_min = tex.anim_max = 0;
tex.alternate_anims = tex.anim_next = NULL;
if (!tex.width || tex.width > 256 || tex.height > 256)
{
Con_Printf("%s: Bad wad dimensions %s\n", __func__, wad->name);
return FALSE;
}
for (int i = 0; i < MIPLEVELS; i++)
for (i = 0; i < MIPLEVELS; i++)
tex.offsets[i] = wad->cacheExtra + LittleLong(tmp.offsets[i]);
if (tex.width <= 0 || tex.height <= 0 ||
// Check if texture dimensions exceed limits
tex.width > 256 || tex.height > 256)
{
Con_Printf("%s: Bad cached wad tex size %ux%u on %s\n", __func__, tex.width, tex.height, wad->name);
return FALSE;
}
pix = tex.width * tex.height;
pixoffset = pix + (pix >> 2) + (pix >> 4) + (pix >> 6);
size = pix + (pix >> 2) + (pix >> 4) + (pix >> 6);
#ifdef REHLDS_FIXES
// Ensure that pixoffset won't be exceed the pre allocated buffer
// This can happen when there are no color palettes in payload
if ((pixoffset + sizeof(texture_t)) >= (unsigned)(wad->cacheExtra + lump->size))
if ((unsigned)(size + sizeof(miptex_t)) >= (unsigned)(lump->size + wad->cacheExtra))
{
Con_Printf("%s: Bad wad payload size %s\n", __func__, wad->name);
return FALSE;
Con_Printf("%s: Bad cached wad size %i/%i on %s\n", __func__, size + sizeof(miptex_t), lump->size + wad->cacheExtra, wad->name);
}
#endif
paloffset = (pix >> 2) + tmp.offsets[0] + pix;
palettesize = (pix >> 4) + paloffset;
paloffset = size + sizeof(miptex_t);
palettesize = *(u_short *)(data + wad->cacheExtra + paloffset); // Get palette size
if ((tmp.offsets[0] + pix != tmp.offsets[1])
|| paloffset != tmp.offsets[2]
|| palettesize != tmp.offsets[3])
for (i = 0; i < 3; i++)
{
Con_Printf("%s: Bad cached wad %s\n", __func__, wad->name);
// Check if offsets are valid for mip levels
if (pix + tmp.offsets[i] != tmp.offsets[i + 1])
{
Con_Printf("%s: Bad cached wad %s\n", __func__, wad->name);
return FALSE;
}
pix >>= 2;
}
if (palettesize > 256)
{
Con_Printf("%s: Bad cached wad palette size %i on %s\n", __func__, palettesize, wad->name);
return FALSE;
}
nPalleteCount = *(u_short *)(data + pixoffset + sizeof(texture_t));
if (nPalleteCount > 256)
{
Con_Printf("%s: Bad cached wad palette size %i on %s\n", __func__, nPalleteCount, wad->name);
return FALSE;
}
nSize = pixoffset + LittleLong(tmp.offsets[0]) + 3 * nPalleteCount + 2;
if (nSize > lump->disksize)
if ((palettesize + 2 * (palettesize + 1) + size + LittleLong(tmp.offsets[0])) > lump->disksize)
{
Con_Printf("%s: Bad cached wad %s\n", __func__, wad->name);
return FALSE;

View File

@ -30,6 +30,9 @@
#include "entity_state.h"
// marker an entity index that not in an old packet (for svc_packetentities)
#define ENTITY_SENTINEL 9999
typedef struct packet_entities_s
{
int num_entities;

View File

@ -620,7 +620,9 @@ qboolean HPAK_ResourceForHash(char *pakname, unsigned char *hash, struct resourc
fp = FS_Open(name, "rb");
if (!fp)
{
#ifndef REHLDS_FIXES
Con_Printf("ERROR: couldn't open %s.\n", name);
#endif
return FALSE;
}
FS_Read(&header, sizeof(hash_pack_header_t), 1, fp);

View File

@ -375,7 +375,8 @@ void EXT_FUNC SV_ClientPrintf_internal(const char *Dest)
{
char string[1024];
Q_strlcpy(string, Dest, min(strlen(Dest) + 1, sizeof(string)));
Q_strlcpy(string, Dest);
MSG_WriteByte(&host_client->netchan.message, svc_print);
MSG_WriteString(&host_client->netchan.message, string);
}

View File

@ -891,7 +891,7 @@ void CalcSurfaceExtents(msurface_t *s)
s->texturemins[i] = bmins[i] * 16;
s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
if (!(tex->flags & TEX_SPECIAL) && s->extents[i] > 256)
if (!(tex->flags & TEX_SPECIAL) && s->extents[i] > MAX_SURFACE_TEXTURE_SIZE)
Sys_Error("%s: Bad surface extents", __func__);
}
}

View File

@ -36,6 +36,12 @@ cvar_t net_showpackets = { "net_showpackets", "0", 0, 0.0f, nullptr};
cvar_t net_showdrop = { "net_showdrop", "0", 0, 0.0f, nullptr};
cvar_t net_drawslider = { "net_drawslider", "0", 0, 0.0f, nullptr};
cvar_t net_chokeloopback = { "net_chokeloop", "0", 0, 0.0f, nullptr};
cvar_t sv_net_incoming_decompression = { "sv_net_incoming_decompression", "1", 0, 1.0f, nullptr };
cvar_t sv_net_incoming_decompression_max_ratio = { "sv_net_incoming_decompression_max_ratio", "80.0", 0, 80.0f, nullptr };
cvar_t sv_net_incoming_decompression_max_size = { "sv_net_incoming_decompression_max_size", "65536", 0, 65536.0f, nullptr };
cvar_t sv_net_incoming_decompression_punish = { "sv_net_incoming_decompression_punish", "-1", 0, -1.0f, NULL };
cvar_t sv_filetransfercompression = { "sv_filetransfercompression", "1", 0, 0.0f, nullptr};
cvar_t sv_filetransfermaxsize = { "sv_filetransfermaxsize", "10485760", 0, 0.0f, nullptr};
@ -1203,7 +1209,9 @@ int Netchan_CreateFileFragments(qboolean server, netchan_t *chan, const char *fi
if (!FS_FileExists(filename))
return FALSE;
if (FS_FileSize(filename) > sv_filetransfermaxsize.value)
unsigned int nSize = FS_FileSize(filename);
if (nSize == 0 || nSize > sv_filetransfermaxsize.value)
return FALSE;
auto wait = (fragbufwaiting_t *)Mem_ZeroMalloc(sizeof(fragbufwaiting_t));
@ -1431,6 +1439,9 @@ qboolean Netchan_CopyNormalFragments(netchan_t *chan)
p = chan->incomingbufs[FRAG_NORMAL_STREAM];
chan->incomingbufs[FRAG_NORMAL_STREAM] = nullptr;
chan->incomingready[FRAG_NORMAL_STREAM] = FALSE;
SZ_Clear(&net_message);
MSG_BeginReading();
@ -1468,27 +1479,87 @@ qboolean Netchan_CopyNormalFragments(netchan_t *chan)
}
SZ_Clear(&net_message);
chan->incomingbufs[FRAG_NORMAL_STREAM] = nullptr;
chan->incomingready[FRAG_NORMAL_STREAM] = FALSE;
return FALSE;
}
#endif // REHLDS_FIXES
qboolean success = TRUE;
if (*(uint32 *)net_message.data == MAKEID('B', 'Z', '2', '\0'))
{
// Determine whether decompression of compressed data is allowed
#ifdef REHLDS_FIXES
if (!sv_net_incoming_decompression.value)
{
if (chan->player_slot == 0)
{
Con_DPrintf("Incoming compressed data disallowed from\n");
return FALSE;
}
// compressed data is expected only after requesting resource list
else if (host_client->m_sendrescount == 0)
{
Con_DPrintf("%s:Incoming compressed data disallowed from %s\n", NET_AdrToString(chan->remote_address), host_client->name);
return FALSE;
}
}
#endif
char uncompressed[65536];
unsigned int uncompressedSize = 65536;
BZ2_bzBuffToBuffDecompress(uncompressed, &uncompressedSize, (char*)net_message.data + 4, net_message.cursize - 4, 1, 0);
Q_memcpy(net_message.data, uncompressed, uncompressedSize);
net_message.cursize = uncompressedSize;
unsigned int uncompressedSize = clamp((int)sv_net_incoming_decompression_max_size.value, 16, 65536); // valid range (16 - 65536) bytes
unsigned int compressedSize = net_message.cursize - 4;
// Decompress net buffer data
if (success && (BZ2_bzBuffToBuffDecompress(uncompressed, &uncompressedSize, (char *)net_message.data + 4, compressedSize, 1, 0) == BZ_OK))
{
#ifdef REHLDS_FIXES
// Check for an abnormal size ratio between compressed and uncompressed data
if (sv_net_incoming_decompression_max_ratio.value > 0 && compressedSize < uncompressedSize)
{
float ratio = ((float)(uncompressedSize - compressedSize) / uncompressedSize) * 100.0f;
if (ratio >= sv_net_incoming_decompression_max_ratio.value)
{
if (chan->player_slot == 0)
Con_DPrintf("Incoming abnormal uncompressed size with ratio %.2f\n", ratio);
else
Con_DPrintf("%s:Incoming abnormal uncompressed size with ratio %.2f from %s\n", NET_AdrToString(chan->remote_address), ratio, host_client->name);
success = FALSE;
}
}
#endif
// Copy uncompressed data back to the net buffer
Q_memcpy(net_message.data, uncompressed, uncompressedSize);
net_message.cursize = uncompressedSize;
}
else
{
// malformed data or compressed data exceeding sv_net_incoming_decompression_max_size
success = FALSE;
}
// Drop client if decompression was unsuccessful
if (!success)
{
if ((chan->player_slot - 1) == host_client - g_psvs.clients)
{
#ifdef REHLDS_FIXES
if (sv_net_incoming_decompression_punish.value >= 0)
{
Con_DPrintf("%s:Banned for malformed/abnormal bzip2 fragments from %s\n", NET_AdrToString(chan->remote_address), host_client->name);
Cbuf_AddText(va("addip %.1f %s\n", sv_net_incoming_decompression_punish.value, NET_BaseAdrToString(chan->remote_address)));
}
#endif
SV_DropClient(host_client, FALSE, "Malformed/abnormal compressed data");
}
SZ_Clear(&net_message);
}
}
chan->incomingbufs[FRAG_NORMAL_STREAM] = nullptr;
chan->incomingready[FRAG_NORMAL_STREAM] = FALSE;
return TRUE;
return success;
}
qboolean Netchan_CopyFileFragments(netchan_t *chan)
@ -1824,6 +1895,12 @@ void Netchan_Init(void)
Cvar_RegisterVariable(&net_chokeloopback);
Cvar_RegisterVariable(&net_drawslider);
Cvar_RegisterVariable(&sv_filetransfercompression);
#ifdef REHLDS_FIXES
Cvar_RegisterVariable(&sv_net_incoming_decompression);
Cvar_RegisterVariable(&sv_net_incoming_decompression_max_ratio);
Cvar_RegisterVariable(&sv_net_incoming_decompression_max_size);
Cvar_RegisterVariable(&sv_net_incoming_decompression_punish);
#endif
Cvar_RegisterVariable(&sv_filetransfermaxsize);
}

View File

@ -2124,7 +2124,7 @@ void EXT_FUNC PF_MessageBegin_I(int msg_dest, int msg_type, const float *pOrigin
if (msg_type == 0)
Sys_Error("%s: Tried to create a message with a bogus message type ( 0 )", __func__);
gMsgStarted = 1;
gMsgStarted = TRUE;
gMsgType = msg_type;
gMsgEntity = ed;
gMsgDest = msg_dest;
@ -2151,7 +2151,7 @@ void EXT_FUNC PF_MessageEnd_I(void)
qboolean MsgIsVarLength = 0;
if (!gMsgStarted)
Sys_Error("%s: called with no active message\n", __func__);
gMsgStarted = 0;
gMsgStarted = FALSE;
if (gMsgEntity && (gMsgEntity->v.flags & FL_FAKECLIENT))
return;
@ -2275,6 +2275,7 @@ void EXT_FUNC PF_WriteByte_I(int iValue)
{
if (!gMsgStarted)
Sys_Error("%s: called with no active message\n", __func__);
MSG_WriteByte(&gMsgBuffer, iValue);
}

View File

@ -95,13 +95,6 @@ typedef enum redirect_e
RD_PACKET = 2,
} redirect_t;
typedef enum server_state_e
{
ss_dead = 0,
ss_loading = 1,
ss_active = 2,
} server_state_t;
typedef struct server_s
{
qboolean active;
@ -468,6 +461,7 @@ void SV_QueryMovevarsChanged(void);
void SV_SendServerinfo(sizebuf_t *msg, client_t *client);
void SV_SendServerinfo_internal(sizebuf_t *msg, client_t *client);
void SV_SendResources(sizebuf_t *msg);
void SV_SendResources_internal(sizebuf_t *msg);
void SV_WriteClientdataToMessage(client_t *client, sizebuf_t *msg);
void SV_WriteSpawn(sizebuf_t *msg);
void SV_SendUserReg(sizebuf_t *msg);

View File

@ -1199,6 +1199,11 @@ void SV_SendServerinfo_internal(sizebuf_t *msg, client_t *client)
}
void SV_SendResources(sizebuf_t *msg)
{
g_RehldsHookchains.m_SV_SendResources.callChain(SV_SendResources_internal, msg);
}
void EXT_FUNC SV_SendResources_internal(sizebuf_t *msg)
{
unsigned char nullbuffer[32];
Q_memset(nullbuffer, 0, sizeof(nullbuffer));
@ -3778,6 +3783,12 @@ void SV_ProcessFile(client_t *cl, char *filename)
return;
}
if (!sv_allow_upload.value)
{
Con_NetPrintf("Ignoring incoming customization file upload of %s from %s\n", filename, NET_AdrToString(cl->netchan.remote_address));
return;
}
COM_HexConvert(filename + 4, 32, md5);
resource = cl->resourcesneeded.pNext;
bFound = FALSE;
@ -3836,13 +3847,20 @@ void SV_ProcessFile(client_t *cl, char *filename)
qboolean SV_FilterPacket(void)
{
// sv_filterban filtering IP mode
// -1: all players will be rejected without any exceptions
// 0: no checks will happen
// 1: all incoming players will be checked if they're IP banned (if they have an IP filter entry), if they are, they will be kicked
qboolean bNegativeFilter = (sv_filterban.value == 1) ? TRUE : FALSE;
for (int i = numipfilters - 1; i >= 0; i--)
{
ipfilter_t* curFilter = &ipfilters[i];
if (curFilter->compare.u32 == 0xFFFFFFFF || curFilter->banEndTime == 0.0f || curFilter->banEndTime > realtime)
{
if ((*(uint32*)net_from.ip & curFilter->mask) == curFilter->compare.u32)
return (int)sv_filterban.value;
return bNegativeFilter;
}
else
{
@ -3852,7 +3870,8 @@ qboolean SV_FilterPacket(void)
--numipfilters;
}
}
return sv_filterban.value == 0.0f;
return !bNegativeFilter;
}
void SV_SendBan(void)
@ -4516,15 +4535,20 @@ int SV_CreatePacketEntities(sv_delta_t type, client_t *client, packet_entities_t
return g_RehldsHookchains.m_SV_CreatePacketEntities.callChain(SV_CreatePacketEntities_api, type, GetRehldsApiClient(client), to, msg);
}
// Computes either a compressed, or uncompressed delta buffer for the client
// Returns the size IN BITS of the message buffer created
int SV_CreatePacketEntities_internal(sv_delta_t type, client_t *client, packet_entities_t *to, sizebuf_t *msg)
{
packet_entities_t *from;
int oldindex;
int newindex;
int oldnum;
int newnum;
int oldmax;
int numbase;
edict_t *ent;
client_frame_t *fromframe;
packet_entities_t *from; // Entity packet for that frame
delta_t *delta;
int oldindex, newindex;
int oldnum, newnum;
int oldmax;
qboolean custom = FALSE;
int offset;
int numbase = 0;
// fix for https://github.com/dreamstalker/rehlds/issues/24
#ifdef REHLDS_FIXES
@ -4532,159 +4556,163 @@ int SV_CreatePacketEntities_internal(sv_delta_t type, client_t *client, packet_e
uint64 toBaselinesForceMask[MAX_PACKET_ENTITIES];
#endif
numbase = 0;
// See if this is a full update
if (type == sv_packet_delta)
{
client_frame_t *fromframe = &client->frames[SV_UPDATE_MASK & client->delta_sequence];
// This is the frame that we are going to delta update from
fromframe = &client->frames[SV_UPDATE_MASK & client->delta_sequence];
from = &fromframe->entities;
_mm_prefetch((const char*)&from->entities[0], _MM_HINT_T0);
_mm_prefetch(((const char*)&from->entities[0]) + 64, _MM_HINT_T0);
oldmax = from->num_entities;
MSG_WriteByte(msg, svc_deltapacketentities);
MSG_WriteShort(msg, to->num_entities);
MSG_WriteByte(msg, client->delta_sequence);
oldmax = fromframe->entities.num_entities;
MSG_WriteByte(msg, svc_deltapacketentities); // This is a delta
MSG_WriteShort(msg, to->num_entities); // This is how many ents are in the new packet
MSG_WriteByte(msg, client->delta_sequence); // This is the sequence # that we are updating from
}
else
{
oldmax = 0;
oldmax = 0; // no delta update
from = NULL;
MSG_WriteByte(msg, svc_packetentities);
MSG_WriteShort(msg, to->num_entities);
MSG_WriteByte(msg, svc_packetentities); // Just a packet update.
MSG_WriteShort(msg, to->num_entities); // This is the # of entities we are sending.
}
newnum = 0; //index in to->entities
oldnum = 0; //index in from->entities
newindex = 0; // index in to->entities
oldindex = 0; // index in from->entities
MSG_StartBitWriting(msg);
while (1)
while (newindex < to->num_entities || oldindex < oldmax)
{
if (newnum < to->num_entities)
{
newindex = to->entities[newnum].number;
}
else
{
if (oldnum >= oldmax)
break;
newnum = (newindex >= to->num_entities) ? ENTITY_SENTINEL : to->entities[newindex].number;
oldnum = (!from || oldindex >= oldmax) ? ENTITY_SENTINEL : from->entities[oldindex].number; // FIXED: from can be null
if (newnum < to->num_entities)
newindex = to->entities[newnum].number;
// this is a delta update of the entity from old position
if (newnum == oldnum)
{
// delta update from old position
// because the force parm is false, this will not result
// in any bytes being emitted if the entity has not changed at all
// note that players are always 'newentities', this updates their oldorigin always
// and prevents warping
entity_state_t *baseline = &to->entities[newindex];
custom = (baseline->entityType == ENTITY_BEAM) ? TRUE : FALSE;
SV_SetCallback(newnum, FALSE, custom, &numbase, FALSE, 0);
DELTA_WriteDelta((uint8 *)&from->entities[oldindex], (uint8 *)baseline, FALSE, custom ? g_pcustomentitydelta : (SV_IsPlayerIndex(newnum) ? g_pplayerdelta : g_pentitydelta), &SV_InvokeCallback);
oldindex++;
_mm_prefetch((const char*)&from->entities[oldindex], _MM_HINT_T0);
_mm_prefetch(((const char*)&from->entities[oldindex]) + 64, _MM_HINT_T0);
newindex++;
continue;
}
// Figure out how we want to update the entity
// This is a new entity, send it from the baseline
if (newnum < oldnum)
{
//
// If the entity was not in the old packet (oldnum == 9999),
// then delta from the baseline since this is a new entity
ent = EDICT_NUM(newnum);
custom = (to->entities[newindex].entityType == ENTITY_BEAM) ? TRUE : FALSE;
if (from == NULL)
SV_SetCallback(newnum, FALSE, custom, &numbase, TRUE, 0);
else
newindex = 9999;
}
SV_SetCallback(newnum, FALSE, custom, &numbase, FALSE, 0);
#ifdef REHLDS_FIXES
if (oldnum < oldmax && from)
#else
if (oldnum < oldmax)
#endif
oldindex = from->entities[oldnum].number;
else
oldindex = 9999;
// this is a new entity, send it from the baseline
entity_state_t *baseline = &g_psv.baselines[newnum];
if (newindex == oldindex)
{
entity_state_t *baseline_ = &to->entities[newnum];
qboolean custom = baseline_->entityType & 0x2 ? TRUE : FALSE;
SV_SetCallback(newindex, FALSE, custom, &numbase, FALSE, 0);
DELTA_WriteDelta((uint8 *)&from->entities[oldnum], (uint8 *)baseline_, FALSE, custom ? g_pcustomentitydelta : (SV_IsPlayerIndex(newindex) ? g_pplayerdelta : g_pentitydelta), &SV_InvokeCallback);
++oldnum;
_mm_prefetch((const char*)&from->entities[oldnum], _MM_HINT_T0);
_mm_prefetch(((const char*)&from->entities[oldnum]) + 64, _MM_HINT_T0);
++newnum;
continue;
}
if (newindex >= oldindex)
{
if (newindex > oldindex)
if (sv_instancedbaseline.value && g_psv.instance_baselines->number != 0 && newnum > sv_lastnum)
{
SV_WriteDeltaHeader(oldindex, TRUE, FALSE, &numbase, FALSE, 0, FALSE, 0);
++oldnum;
_mm_prefetch((const char*)&from->entities[oldnum], _MM_HINT_T0);
_mm_prefetch(((const char*)&from->entities[oldnum]) + 64, _MM_HINT_T0);
}
continue;
}
edict_t *ent = EDICT_NUM(newindex);
qboolean custom = to->entities[newnum].entityType & 0x2 ? TRUE : FALSE;
SV_SetCallback(
newindex,
FALSE,
custom,
&numbase,
from == NULL,
0);
entity_state_t *baseline_ = &g_psv.baselines[newindex];
if (sv_instancedbaseline.value != 0.0f && g_psv.instance_baselines->number != 0 && newindex > sv_lastnum)
{
for (int i = 0; i < g_psv.instance_baselines->number; i++)
{
if (g_psv.instance_baselines->classname[i] == ent->v.classname)
for (int i = 0; i < g_psv.instance_baselines->number; i++)
{
SV_SetNewInfo(i);
baseline_ = &g_psv.instance_baselines->baseline[i];
break;
if (g_psv.instance_baselines->classname[i] == ent->v.classname)
{
SV_SetNewInfo(i);
baseline = &g_psv.instance_baselines->baseline[i];
break;
}
}
}
}
else
{
if (!from)
else
{
int offset = SV_FindBestBaseline(newnum, &baseline_, to->entities, newindex, custom);
_mm_prefetch((const char*)baseline_, _MM_HINT_T0);
_mm_prefetch(((const char*)baseline_) + 64, _MM_HINT_T0);
if (offset)
SV_SetCallback(newindex, FALSE, custom, &numbase, TRUE, offset);
// If this is full update
if (!from)
{
offset = SV_FindBestBaseline(newindex, &baseline, to->entities, newnum, custom);
_mm_prefetch((const char*)baseline, _MM_HINT_T0);
_mm_prefetch(((const char*)baseline) + 64, _MM_HINT_T0);
if (offset)
SV_SetCallback(newnum, FALSE, custom, &numbase, TRUE, offset);
// fix for https://github.com/dreamstalker/rehlds/issues/24
// fix for https://github.com/dreamstalker/rehlds/issues/24
#ifdef REHLDS_FIXES
if (offset)
baselineToIdx = newnum - offset;
if (offset)
baselineToIdx = newindex - offset;
#endif
}
}
delta = custom ? g_pcustomentitydelta : (SV_IsPlayerIndex(newnum) ? g_pplayerdelta : g_pentitydelta);
// fix for https://github.com/dreamstalker/rehlds/issues/24
#ifdef REHLDS_FIXES
DELTA_WriteDeltaForceMask(
(uint8 *)baseline,
(uint8 *)&to->entities[newindex],
TRUE,
delta,
&SV_InvokeCallback,
baselineToIdx != -1 ? &toBaselinesForceMask[baselineToIdx] : NULL
);
baselineToIdx = -1;
uint64 origMask = DELTA_GetOriginalMask(delta);
uint64 usedMask = DELTA_GetMaskU64(delta);
uint64 diffMask = origMask ^ usedMask;
// Remember changed fields that was marked in original mask, but unmarked by the conditional encoder
toBaselinesForceMask[newindex] = diffMask & origMask;
#else // REHLDS_FIXES
DELTA_WriteDelta(
(uint8 *)baseline,
(uint8 *)&to->entities[newindex],
TRUE,
delta,
&SV_InvokeCallback
);
#endif // REHLDS_FIXES
newindex++;
continue;
}
// the old entity isn't present in the new message
if (newnum > oldnum)
{
//
// If the entity was in the old list, but is not in the new list (newnum == 9999),
// then construct a special remove message
delta_t* delta = custom ? g_pcustomentitydelta : (SV_IsPlayerIndex(newindex) ? g_pplayerdelta : g_pentitydelta);
// fix for https://github.com/dreamstalker/rehlds/issues/24
#ifdef REHLDS_FIXES
DELTA_WriteDeltaForceMask(
(uint8 *)baseline_,
(uint8 *)&to->entities[newnum],
TRUE,
delta,
&SV_InvokeCallback,
baselineToIdx != -1 ? &toBaselinesForceMask[baselineToIdx] : NULL
);
baselineToIdx = -1;
uint64 origMask = DELTA_GetOriginalMask(delta);
uint64 usedMask = DELTA_GetMaskU64(delta);
uint64 diffMask = origMask ^ usedMask;
//Remember changed fields that was marked in original mask, but unmarked by the conditional encoder
toBaselinesForceMask[newnum] = diffMask & origMask;
#else //REHLDS_FIXES
DELTA_WriteDelta(
(uint8 *)baseline_,
(uint8 *)&to->entities[newnum],
TRUE,
delta,
&SV_InvokeCallback
);
#endif //REHLDS_FIXES
++newnum;
// remove = TRUE, tell the client that entity was removed from server
SV_WriteDeltaHeader(oldnum, TRUE, FALSE, &numbase, FALSE, 0, FALSE, 0);
oldindex++;
_mm_prefetch((const char*)&from->entities[oldindex], _MM_HINT_T0);
_mm_prefetch(((const char*)&from->entities[oldindex]) + 64, _MM_HINT_T0);
continue;
}
}
// No more entities.. (end of packet entities)
MSG_WriteBits(0, 16);
MSG_EndBitWriting(msg);
return msg->cursize;
}
@ -5748,6 +5776,12 @@ void SV_PropagateCustomizations(void)
if (pCust->bInUse)
{
pResource = &pCust->resource;
#ifdef REHLDS_FIXES
if ((pResource->ucFlags & RES_CUSTOM) && !sv_send_logos.value)
continue;
#endif
MSG_WriteByte(&host_client->netchan.message, svc_customization);
MSG_WriteByte(&host_client->netchan.message, i);
MSG_WriteByte(&host_client->netchan.message, pResource->type);
@ -6549,7 +6583,13 @@ void SV_ClearEntities(void)
}
int EXT_FUNC RegUserMsg(const char *pszName, int iSize)
{
if (giNextUserMsg > 255 || !pszName || Q_strlen(pszName) > 11 || iSize > 192)
if (giNextUserMsg >= MAX_USERMESSAGES)
return 0;
if (iSize > MAX_USER_MSG_DATA)
return 0;
if (!pszName || Q_strlen(pszName) >= MAX_USERMESSAGES_LENGTH - 1)
return 0;
UserMsg *pUserMsgs = sv_gpUserMsgs;

View File

@ -138,13 +138,16 @@ void SV_CreateCustomizationList(client_t *pHost)
{
pCust->nUserData2 = nLumps;
gEntityInterface.pfnPlayerCustomization(pHost->edict, pCust);
#ifdef REHLDS_FIXES
SV_Customization(pHost, pResource, TRUE);
#endif
}
else
{
if (sv_allow_upload.value == 0.0f)
Con_Printf("Ignoring custom decal from %s\n", pHost->name);
Con_DPrintf("Ignoring custom decal from %s\n", pHost->name);
else
Con_Printf("Ignoring invalid custom decal from %s\n", pHost->name);
Con_DPrintf("Ignoring invalid custom decal from %s\n", pHost->name);
}
}
}
@ -157,6 +160,11 @@ void SV_Customization(client_t *pPlayer, resource_t *pResource, qboolean bSkipPl
int nPlayerNumber;
client_t *pHost;
#ifdef REHLDS_FIXES
if ((pResource->ucFlags & RES_CUSTOM) && !sv_send_logos.value)
return;
#endif
// Get originating player id
for (i = 0, pHost = g_psvs.clients; i < g_psvs.maxclients; i++, pHost++)
{
@ -199,18 +207,13 @@ void SV_Customization(client_t *pPlayer, resource_t *pResource, qboolean bSkipPl
// Creates customizations list for the current player and sends resources to other players.
void SV_RegisterResources(void)
{
resource_t *pResource;
client_t *pHost = host_client;
pHost->uploading = FALSE;
#ifdef REHLDS_FIXES
SV_CreateCustomizationList(pHost); // FIXED: Call this function only once. It was crazy to call it for each resource available.
for (pResource = pHost->resourcesonhand.pNext; pResource != &pHost->resourcesonhand; pResource = pResource->pNext)
{
SV_Customization(pHost, pResource, TRUE);
}
#else // REHLDS_FIXES
for (pResource = pHost->resourcesonhand.pNext; pResource != &pHost->resourcesonhand; pResource = pResource->pNext)
for (resource_t *pResource = pHost->resourcesonhand.pNext; pResource != &pHost->resourcesonhand; pResource = pResource->pNext)
{
SV_CreateCustomizationList(pHost);
SV_Customization(pHost, pResource, TRUE);
@ -509,8 +512,13 @@ void SV_ParseResourceList(client_t *pSenderClient)
}
}
host_client->uploading = TRUE;
host_client->uploaddoneregistering = FALSE;
#ifdef REHLDS_FIXES
if (sv_allow_upload.value != 0.0f)
#endif //REHLDS_FIXES
{
host_client->uploading = TRUE;
host_client->uploaddoneregistering = FALSE;
SV_BatchUploadRequest(host_client);
SV_BatchUploadRequest(host_client);
}
}

View File

@ -884,7 +884,11 @@ void SV_RunCmd(usercmd_t *ucmd, int random_seed)
pmove->spectator = 0;
pmove->waterjumptime = sv_player->v.teleport_time;
#ifdef REHLDS_FIXES
Q_memcpy(&pmove->cmd, ucmd, sizeof(pmove->cmd));
#else
Q_memcpy(&pmove->cmd, &cmd, sizeof(pmove->cmd));
#endif
pmove->dead = sv_player->v.health <= 0.0;
pmove->movetype = sv_player->v.movetype;

View File

@ -1083,6 +1083,10 @@ void LoadThisDll(const char *szDllFilename)
goto IgnoreThisDLL;
}
#ifdef REHLDS_API
MessageManager().Init();
#endif
pfnGiveFnptrsToDll(&g_engfuncsExportedToDlls, &gGlobalVariables);
if (g_iextdllMac == MAX_EXTENSION_DLL)
{

View File

@ -31,11 +31,14 @@
#include "maintypes.h"
#include "quakedef.h"
// The maximum length of a usermessage name in a network transmission
#define MAX_USERMESSAGES_LENGTH 16
typedef struct _UserMsg
{
int iMsg;
int iSize;
char szName[16];
char szName[MAX_USERMESSAGES_LENGTH];
struct _UserMsg *next;
pfnUserMsgHook pfn;
} UserMsg;

View File

@ -119,6 +119,7 @@
<ClCompile Include="..\rehlds\FlightRecorderImpl.cpp" />
<ClCompile Include="..\rehlds\flight_recorder.cpp" />
<ClCompile Include="..\rehlds\main.cpp" />
<ClCompile Include="..\rehlds\rehlds_messagemngr_impl.cpp" />
<ClCompile Include="..\rehlds\rehlds_api_impl.cpp" />
<ClCompile Include="..\rehlds\rehlds_interfaces_impl.cpp" />
<ClCompile Include="..\rehlds\hookchains_impl.cpp" />
@ -386,6 +387,7 @@
<ClInclude Include="..\public\rehlds\eiface.h" />
<ClInclude Include="..\public\rehlds\FlightRecorder.h" />
<ClInclude Include="..\public\rehlds\hookchains.h" />
<ClInclude Include="..\public\rehlds\IMessageManager.h" />
<ClInclude Include="..\public\rehlds\keydefs.h" />
<ClInclude Include="..\public\rehlds\maintypes.h" />
<ClInclude Include="..\public\rehlds\model.h" />
@ -439,6 +441,7 @@
<ClInclude Include="..\rehlds\FlightRecorderImpl.h" />
<ClInclude Include="..\rehlds\flight_recorder.h" />
<ClInclude Include="..\rehlds\hookchains_impl.h" />
<ClInclude Include="..\rehlds\rehlds_messagemngr_impl.h" />
<ClInclude Include="..\rehlds\platform.h" />
<ClInclude Include="..\rehlds\precompiled.h" />
<ClInclude Include="..\rehlds\RehldsRuntimeConfig.h" />

View File

@ -341,6 +341,9 @@
<ClCompile Include="..\testsuite\memory.cpp">
<Filter>testsuite</Filter>
</ClCompile>
<ClCompile Include="..\rehlds\rehlds_messagemngr_impl.cpp">
<Filter>rehlds</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\version\version.h">
@ -1060,5 +1063,11 @@
<ClInclude Include="..\testsuite\memory.h">
<Filter>testsuite</Filter>
</ClInclude>
<ClInclude Include="..\rehlds\rehlds_messagemngr_impl.h">
<Filter>rehlds</Filter>
</ClInclude>
<ClInclude Include="..\public\rehlds\IMessageManager.h">
<Filter>public\rehlds</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,337 @@
/*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* 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, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#pragma once
/**
* @brief Interface for defining message parameters and behavior for a individual message object
*/
class IMessage
{
public:
/**
* @brief The parameter types for a message
*/
enum class ParamType : uint8
{
Byte,
Char,
Short,
Long,
Angle,
Coord,
String,
Entity,
};
/**
* @brief Blocking behavior types for messages
*/
enum class BlockType : uint8
{
Not, // Not a block
Once, // Block once
Set // Set block
};
/**
* @brief Message destinations
*/
enum class Dest : uint8
{
BROADCAST, // Unreliable to all
ONE, // Reliable to one (msg_entity)
ALL, // Reliable to all
INIT, // Write to the init string
PVS, // Ents in PVS of org
PAS, // Ents in PAS of org
PVS_R, // Reliable to PVS
PAS_R, // Reliable to PAS
ONE_UNRELIABLE, // Send to one client, but don't put in reliable stream, put in unreliable datagram
SPEC, // Sends to all spectator proxies
};
/**
* @brief Data types for message data
*/
enum class DataType : uint8
{
Any, // Any part of the message
Dest, // Destination of the message
Index, // Index of the message
Origin, // Origin of the message
Edict, // Pointer to the edict of the recipient client
Param, // Parameter of the message
Max
};
virtual ~IMessage() = default;
/**
* @brief Returns the number of parameters in the message
* @return The number of parameters
*/
virtual int getParamCount() const = 0;
/**
* @brief Returns the type of the parameter at the given index
* @param index The index of the parameter
* @return The type of the parameter
*/
virtual ParamType getParamType(size_t index) const = 0;
/**
* @brief Returns the integer value of the parameter at the given index
* @param index The index of the parameter
* @return The integer value of the parameter
*/
virtual int getParamInt(size_t index) const = 0;
/**
* @brief Returns the float value of the parameter at the given index
* @param index The index of the parameter
* @return The float value of the parameter
*/
virtual float getParamFloat(size_t index) const = 0;
/**
* @brief Returns the string value of the parameter at the given index
* @param index The index of the parameter
* @return The string value of the parameter
*/
virtual const char* getParamString(size_t index) const = 0;
/**
* @brief Sets the integer value of the parameter at the given index
* @param index The index of the parameter
* @param value The integer value to set
*/
virtual void setParamInt(size_t index, int value) = 0;
/**
* @brief Sets the float value of the parameter at the given index
* @param index The index of the parameter
* @param value The float value to set
*/
virtual void setParamFloat(size_t index, float value) = 0;
/**
* @brief Sets the vector value of the parameter at the given index
* @param index The index of the parameter
* @param pos The vector value to set
*/
virtual void setParamVec(size_t index, const float *pos) = 0;
/**
* @brief Sets the string value of the parameter at the given index
* @param index The index of the parameter
* @param string The string value to set
*/
virtual void setParamString(size_t index, const char *string) = 0;
/**
* @brief Returns the destination of the message
* @return The destination of the message
*/
virtual Dest getDest() const = 0;
/**
* @brief Returns the index of the message
* @return The index of the message
*/
virtual int getId() const = 0;
/**
* @brief Returns the origin of the message
* @return The origin of the message
*/
virtual const float* getOrigin() const = 0;
/**
* @brief Returns the edict associated with the message
* @return The edict associated with the message
*/
virtual struct edict_s* getEdict() const = 0;
/**
* @brief Checks if the specified type of message data has been modified
*
* This function allows you to check if any part of the message data, such as its
* destination, type, origin, edict, or any specific parameter, has been modified
*
* @param type The type of the data to check for modification
* This can be one of the following:
* - DataType::Any: Check if any part of the message has been modified
* - DataType::Dest: Check if the destination has been modified
* - DataType::Index: Check if the message ID has been modified
* - DataType::Origin: Check if the origin has been modified
* - DataType::Edict: Check if the edict pointer has been modified
* - DataType::Param: Check if a specific parameter has been modified
*
* @param index The index of the parameter to check for modification (used only when type is DataType::Param)
* Default value is -1, which means the parameter index is not applicable
*
* @return True if the specified data type has been modified, false otherwise
*/
virtual bool isDataModified(DataType type = DataType::Any, size_t index = -1) const = 0;
/**
* @brief Resets a specific type of message data to its original value
*
* @param type The type of data to reset to its original value
* This can be one of the following:
* - DataType::Any: Reset all modified message data to its original values
* - DataType::Dest: Reset the destination to its original value
* - DataType::Index: Reset the message ID to its original value
* - DataType::Origin: Reset the origin to its original value
* - DataType::Edict: Reset the edict pointer of the recipient client to its original value
* - DataType::Param: Reset a specific parameter to its original value
*
* @param index The index of the parameter to reset (used only when type is DataType::Param)
* Default value is -1, which means the parameter index is not applicable
*
* @return True if the modified data type was reset, false otherwise
*/
virtual bool resetModifiedData(DataType type = DataType::Any, size_t index = -1) = 0;
/**
* @brief Sets the destination of the message
*/
virtual void setDest(Dest dest) = 0;
/**
* @brief Sets the index of the message
*/
virtual void setId(int msg_id) = 0;
/**
* @brief Sets the origin of the message
*/
virtual void setOrigin(const float *origin) = 0;
/**
* @brief Sets the edict associated with the message
*/
virtual void setEdict(struct edict_s *pEdict) = 0;
/**
* @brief Returns the original destination of the message before any modifications
* @return The original destination of the message
*/
virtual Dest getOriginalDest() const = 0;
/**
* @brief Returns the original type of the message before any modifications
* @return The original type of the message
*/
virtual int getOriginalId() const = 0;
/**
* @brief Returns the original origin of the message before any modifications
* @return The original origin of the message
*/
virtual const float* getOriginalOrigin() const = 0;
/**
* @brief Returns the original edict associated with the message before any modifications
* @return The original edict associated with the message
*/
virtual struct edict_s* getOriginalEdict() const = 0;
/**
* @brief Returns the original integer value of the parameter at the given index before any modifications
* @param index The index of the parameter
* @return The original integer value of the parameter
*/
virtual int getOriginalParamInt(size_t index) const = 0;
/**
* @brief Returns the original float value of the parameter at the given index before any modifications
* @param index The index of the parameter
* @return The original float value of the parameter
*/
virtual float getOriginalParamFloat(size_t index) const = 0;
/**
* @brief Returns the original string value of the parameter at the given index before any modifications
* @param index The index of the parameter
* @return The original string value of the parameter
*/
virtual const char* getOriginalParamString(size_t index) const = 0;
// This must be the last virtual function in class
#ifdef REHLDS_SELF
// Set the copyback buffer for the message
virtual void setCopybackBuffer(struct sizebuf_s *pbuf) = 0;
#endif
};
#define MESSAGEMNGR_VERSION_MAJOR 2
#define MESSAGEMNGR_VERSION_MINOR 0
/**
* @brief Interface manages hooks and blocking behavior game messages
*/
class IMessageManager
{
public:
using hookfunc_t = void (*)(IVoidHookChain<IMessage *> *chain, IMessage *msg);
virtual ~IMessageManager() = default;
/**
* @brief Returns the major version of the MessageManager
* @return The major version
*/
virtual int getMajorVersion() const = 0;
/**
* @brief Returns the minor version of the MessageManager
* @return The minor version
*/
virtual int getMinorVersion() const = 0;
/**
* @brief Returns the blocking behavior for the given message type
* @param msg_id The message type
* @return The blocking behavior for the given message type
*/
virtual IMessage::BlockType getMessageBlock(int msg_id) const = 0;
/**
* @brief Sets the blocking behavior for the given message type
* @param msg_id The message type
* @param blockType The blocking behavior to set
*/
virtual void setMessageBlock(int msg_id, IMessage::BlockType blockType) = 0;
/**
* @brief Registers a hook function for the given message type
* @param msg_id The message type to register the hook for
* @param handler The hook function to register
* @param priority The priority of the hook function (see enum HookChainPriority)
*/
virtual void registerHook(int msg_id, hookfunc_t handler, int priority = HC_PRIORITY_DEFAULT) = 0;
/**
* @brief Unregisters a hook function for the given message type
* @param msg_id The message type to unregister the hook for
* @param handler The hook function to unregister
*/
virtual void unregisterHook(int msg_id, hookfunc_t handler) = 0;
};

View File

@ -67,4 +67,12 @@ typedef enum sv_delta_s
sv_packet_delta,
} sv_delta_t;
// From engine/server.h
typedef enum server_state_e
{
ss_dead = 0,
ss_loading = 1,
ss_active = 2,
} server_state_t;
#endif // MAINTYPES_H

View File

@ -144,6 +144,13 @@ struct msurface_s
// surface generation data
struct surfcache_s *cachespots[MIPLEVELS];
// Maximum s/t texture size on the surface
#if defined(GLQUAKE) || defined(SWDS)
#define MAX_SURFACE_TEXTURE_SIZE 512
#else
#define MAX_SURFACE_TEXTURE_SIZE 256 // Software rendering is limited to 256
#endif
short texturemins[2]; // smallest s/t position on the surface.
short extents[2]; // ?? s/t texture size, 1..256 for all non-sky surfaces

View File

@ -31,13 +31,14 @@
#include "rehlds_interfaces.h"
#include "hookchains.h"
#include "FlightRecorder.h"
#include "IMessageManager.h"
#include "interface.h"
#include "model.h"
#include "ObjectList.h"
#include "pr_dlls.h"
#define REHLDS_API_VERSION_MAJOR 3
#define REHLDS_API_VERSION_MINOR 13
#define REHLDS_API_VERSION_MINOR 14
//Steam_NotifyClientConnect hook
typedef IHookChain<qboolean, IGameClient*, const void*, unsigned int> IRehldsHook_Steam_NotifyClientConnect;
@ -259,6 +260,10 @@ typedef IVoidHookChainRegistry<const char *> IRehldsHookRegistry_SV_ClientPrintf
typedef IHookChain<bool, edict_t*, edict_t*> IRehldsHook_SV_AllowPhysent;
typedef IHookChainRegistry<bool, edict_t*, edict_t*> IRehldsHookRegistry_SV_AllowPhysent;
//SV_SendResources hook
typedef IVoidHookChain<sizebuf_t *> IRehldsHook_SV_SendResources;
typedef IVoidHookChainRegistry<sizebuf_t *> IRehldsHookRegistry_SV_SendResources;
class IRehldsHookchains {
public:
virtual ~IRehldsHookchains() { }
@ -318,6 +323,7 @@ public:
virtual IRehldsHookRegistry_SV_AddResource* SV_AddResource() = 0;
virtual IRehldsHookRegistry_SV_ClientPrintf* SV_ClientPrintf() = 0;
virtual IRehldsHookRegistry_SV_AllowPhysent* SV_AllowPhysent() = 0;
virtual IRehldsHookRegistry_SV_SendResources* SV_SendResources() = 0;
};
struct RehldsFuncs_t {
@ -441,6 +447,7 @@ public:
virtual IRehldsServerStatic* GetServerStatic() = 0;
virtual IRehldsServerData* GetServerData() = 0;
virtual IRehldsFlightRecorder* GetFlightRecorder() = 0;
virtual IMessageManager *GetMessageManager() = 0;
};
#define VREHLDS_HLDS_API_VERSION "VREHLDS_HLDS_API_VERSION001"

View File

@ -36,6 +36,7 @@ class IGameClient;
#include "common_rehlds.h"
#include "userid_rehlds.h"
#include "FileSystem.h"
#ifdef REHLDS_SELF
#include "server.h"

View File

@ -90,3 +90,7 @@ void AbstractHookChainRegistry::removeHook(void* hookFunc) {
}
}
}
int AbstractHookChainRegistry::getCount() const {
return m_NumHooks;
}

View File

@ -109,10 +109,11 @@ protected:
protected:
void addHook(void* hookFunc, int priority);
bool findHook(void* hookFunc) const;
void removeHook(void* hookFunc);
public:
int getCount() const;
bool findHook(void* hookFunc) const;
AbstractHookChainRegistry();
};
@ -132,9 +133,14 @@ public:
EXT_FUNC virtual void registerHook(hookfunc_t hook, int priority) {
addHook((void*)hook, priority);
}
EXT_FUNC virtual void unregisterHook(hookfunc_t hook) {
removeHook((void*)hook);
}
bool isEmpty() const {
return getCount() == 0;
}
};
template<typename ...t_args>
@ -157,4 +163,8 @@ public:
EXT_FUNC virtual void unregisterHook(hookfunc_t hook) {
removeHook((void*)hook);
}
bool isEmpty() const {
return getCount() == 0;
}
};

View File

@ -49,6 +49,7 @@
#include "rehlds_api_impl.h"
#include "FlightRecorderImpl.h"
#include "flight_recorder.h"
#include "rehlds_messagemngr_impl.h"
#include "rehlds_security.h"
#include "dlls/cdll_dll.h"

View File

@ -885,6 +885,10 @@ IRehldsHookRegistry_SV_AllowPhysent* CRehldsHookchains::SV_AllowPhysent() {
return &m_SV_AllowPhysent;
}
IRehldsHookRegistry_SV_SendResources* CRehldsHookchains::SV_SendResources() {
return &m_SV_SendResources;
}
int EXT_FUNC CRehldsApi::GetMajorVersion()
{
return REHLDS_API_VERSION_MAJOR;
@ -913,6 +917,10 @@ IRehldsServerData* EXT_FUNC CRehldsApi::GetServerData() {
return &g_RehldsServerData;
}
IMessageManager* EXT_FUNC CRehldsApi::GetMessageManager() {
return &MessageManager();
}
IRehldsFlightRecorder* EXT_FUNC CRehldsApi::GetFlightRecorder() {
return g_FlightRecorder;
}

View File

@ -254,6 +254,10 @@ typedef IVoidHookChainRegistryImpl<const char*> CRehldsHookRegistry_SV_ClientPri
typedef IHookChainImpl<bool, edict_t*, edict_t*> CRehldsHook_SV_AllowPhysent;
typedef IHookChainRegistryImpl<bool, edict_t*, edict_t*> CRehldsHookRegistry_SV_AllowPhysent;
//SV_SendResources hook
typedef IVoidHookChainImpl<sizebuf_t *> CRehldsHook_SV_SendResources;
typedef IVoidHookChainRegistryImpl<sizebuf_t *> CRehldsHookRegistry_SV_SendResources;
class CRehldsHookchains : public IRehldsHookchains {
public:
CRehldsHookRegistry_Steam_NotifyClientConnect m_Steam_NotifyClientConnect;
@ -311,6 +315,7 @@ public:
CRehldsHookRegistry_SV_AddResource m_SV_AddResource;
CRehldsHookRegistry_SV_ClientPrintf m_SV_ClientPrintf;
CRehldsHookRegistry_SV_AllowPhysent m_SV_AllowPhysent;
CRehldsHookRegistry_SV_SendResources m_SV_SendResources;
public:
EXT_FUNC virtual IRehldsHookRegistry_Steam_NotifyClientConnect* Steam_NotifyClientConnect();
@ -368,6 +373,7 @@ public:
EXT_FUNC virtual IRehldsHookRegistry_SV_AddResource* SV_AddResource();
EXT_FUNC virtual IRehldsHookRegistry_SV_ClientPrintf* SV_ClientPrintf();
EXT_FUNC virtual IRehldsHookRegistry_SV_AllowPhysent* SV_AllowPhysent();
EXT_FUNC virtual IRehldsHookRegistry_SV_SendResources* SV_SendResources();
};
extern CRehldsHookchains g_RehldsHookchains;
@ -385,6 +391,7 @@ public:
virtual IRehldsServerStatic* GetServerStatic();
virtual IRehldsServerData* GetServerData();
virtual IRehldsFlightRecorder* GetFlightRecorder();
virtual IMessageManager* GetMessageManager();
};
extern sizebuf_t* GetNetMessage_api();

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,183 @@
/*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* 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, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#pragma once
#include "IMessageManager.h"
#include "hookchains.h"
#include <memory> // std::unique_ptr
#include <algorithm> // std::move
/**
* @brief Implementation interface manages hooks and blocking behavior game messages
*/
class MessageManagerImpl: public IMessageManager
{
public:
void Init();
MessageManagerImpl();
~MessageManagerImpl() = default;
/**
* @brief Returns the major version of the MessageManager
* @return The major version
*/
int getMajorVersion() const { return MESSAGEMNGR_VERSION_MAJOR; }
/**
* @brief Returns the minor version of the MessageManager
* @return The minor version
*/
int getMinorVersion() const { return MESSAGEMNGR_VERSION_MINOR; }
/**
* @brief Returns the blocking behavior for the given message type
* @param msg_id The message type
* @return The blocking behavior for the given message type
*/
IMessage::BlockType getMessageBlock(int msg_id) const;
/**
* @brief Sets the blocking behavior for the given message type
* @param msg_id The message type
* @param blockType The blocking behavior to set
*/
void setMessageBlock(int msg_id, IMessage::BlockType blockType);
/**
* @brief Registers a hook function for the given message type
* @param msg_id The message type to register the hook for
* @param handler The hook function to register
* @param priority The priority of the hook function (see enum HookChainPriority)
*/
void registerHook(int msg_id, hookfunc_t handler, int priority = HC_PRIORITY_DEFAULT);
/**
* @brief Unregisters a hook function for the given message type
* @param msg_id The message type to unregister the hook for
* @param handler The hook function to unregister
*/
void unregisterHook(int msg_id, hookfunc_t handler);
private:
friend void PF_MessageBegin_Intercept(int msg_dest, int msg_id, const float *pOrigin, edict_t *ed);
friend void PF_MessageEnd_Intercept();
friend void PF_WriteByte_Intercept(int iValue);
friend void PF_WriteChar_Intercept(int iValue);
friend void PF_WriteShort_Intercept(int iValue);
friend void PF_WriteLong_Intercept(int iValue);
friend void PF_WriteAngle_Intercept(float flValue);
friend void PF_WriteCoord_Intercept(float flValue);
friend void PF_WriteString_Intercept(const char *sz);
friend void PF_WriteEntity_Intercept(int iValue);
bool MessageBegin(int msg_dest, int msg_id, const float *pOrigin, edict_t *ed);
bool MessageEnd();
private:
bool WriteParam(IMessage::ParamType type, size_t length = -1);
bool m_inblock; // Flag indicating whether a message block is currently active
bool m_inhook; // Flag indicating whether a message hook is currently active
/**
* @brief The fixed-size memory pool holds a list of free objects
* @tparam T The type of objects stored in the stack
* @tparam MAX The maximum size of the stack
*/
template <typename T, size_t MAX>
class MessagePool
{
public:
std::unique_ptr<T> acquire()
{
if (_size > 0)
return std::move(_freeObjects[--_size]); // reusing
return std::make_unique<T>(); // initialize constructor for new element
}
void release(std::unique_ptr<T> obj)
{
if (_size < MAX)
_freeObjects[_size++] = std::move(obj);
}
void clear()
{
while (_size > 0)
_freeObjects[--_size].reset();
}
private:
size_t _size{0u};
std::unique_ptr<T> _freeObjects[MAX]{};
};
/**
* @brief Helper a templated MessageStack class to manage a stack of Message objects with fixed size
* @tparam T The type of objects stored in the stack
* @tparam MAX The maximum size of the stack
*/
template <typename T, size_t MAX>
class MessageStack
{
public:
MessageStack(MessagePool<T, MAX> &pool) : _pool(pool) {}
T &push()
{
std::unique_ptr<T> msg = _pool.acquire();
_activeObjects[_size++] = std::move(msg);
return *_activeObjects[_size - 1];
}
void pop()
{
if (_size > 0)
_pool.release(std::move(_activeObjects[--_size]));
}
size_t size() const { return _size; }
size_t max_size() const { return MAX; }
const T &top() const { return *_activeObjects[_size - 1]; }
T &top() { return *_activeObjects[_size - 1]; }
private:
size_t _size{0u};
std::unique_ptr<T> _activeObjects[MAX]{};
MessagePool<T, MAX> &_pool;
};
static const size_t MAX_MSGSTACK = 16; // The maximum size of the message stack, 16 it should be enough
MessagePool<class MessageImpl, MAX_MSGSTACK> m_pool; // A fixed-size memory pool stack for reusable
MessageStack<class MessageImpl, MAX_MSGSTACK> m_stack;
using HookRegistry_t = IVoidHookChainRegistryImpl<IMessage *>;
HookRegistry_t *m_hooks[MAX_USERMESSAGES]{};
IMessage::BlockType m_blocks[MAX_USERMESSAGES]{}; // The array of blocking behaviors for each message type
};
/**
* @brief The singleton instance of the MessageManager
*/
extern MessageManagerImpl &MessageManager();

View File

@ -6,5 +6,5 @@
#pragma once
#define VERSION_MAJOR 3
#define VERSION_MINOR 13
#define VERSION_MINOR 14
#define VERSION_MAINTENANCE 0