Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Check* Hooks #963

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
190ceec
Implement Check* Hooks
JohanCorn May 25, 2024
85c9878
Update gamerules.h
JohanCorn Jun 10, 2024
8b6d659
Implemented simple player movement version control to avoid desync
s1lentq Aug 16, 2024
a8fd512
Fix linux build
s1lentq Aug 16, 2024
12f4e9b
remove unnecessary version consistency for some player movement code
s1lentq Aug 16, 2024
dc16b12
[skip ci] VisualStudio: Add auto visualizer for some structures/classes
s1lentq Aug 24, 2024
3cf66de
fix mp_kill_filled_spawn (#1011)
Vaqtincha Sep 12, 2024
19714af
get rid of unsafe string functions
s1lentq Sep 12, 2024
3f628ea
DeathSound: Don't interrupt pain sounds with death sound, use any ava…
s1lentq Sep 16, 2024
9b7b169
escape feature for bots (#1012)
Vaqtincha Sep 17, 2024
9b626b1
add desc to readme (#1014)
Vaqtincha Sep 18, 2024
535ea84
client.cpp: Use macros for pfnPrecacheEvent (#1019)
Nord1cWarr1or Oct 23, 2024
7738142
CI Workflow Refactor and Fixes (#1016)
wopox1337 Oct 29, 2024
476b5f7
fix typo
s1lentq Dec 9, 2024
df7944a
Disable broken angle adjustment with throw direction in Killed to avo…
s1lentq Dec 10, 2024
942f2e6
Removed -bots and -host-improve command line params in favor of using…
s1lentq Dec 10, 2024
3efc5ad
AUG/SG552: Reset maxspeed when zooming
s1lentq Dec 10, 2024
8a77bba
always consider all human players on the server to use bot_auto_vacat…
s1lentq Dec 10, 2024
6f0d17b
fixed issues reported by static analyzer
s1lentq Dec 11, 2024
1a17ef4
Reset bot morale on new match(game) (#1025)
Vaqtincha Dec 11, 2024
17ae24e
fix build
s1lentq Dec 11, 2024
1579273
Add target_cdaudio in fgd (Closes #1030)
s1lentq Dec 11, 2024
f63ad67
Hostage minor fixes
s1lentq Dec 14, 2024
07c843d
Implement Check* Hooks
JohanCorn May 25, 2024
fe50005
Update gamerules.h
JohanCorn Jun 10, 2024
de64fa6
Merge branch 'Implement-Check-Hooks' of https://github.com/JohanCorn/…
JohanCorn Jan 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 34 additions & 72 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
with:
vs-version: '16.8'
vs-version: '16'

- name: Build and Run unittests
run: |
Expand All @@ -58,95 +58,68 @@ jobs:
move msvc\${{ env.buildRelease }}\mp.pdb publish\debug\mp.pdb

- name: Deploy artifacts
uses: actions/upload-artifact@v3.1.1
uses: actions/upload-artifact@v4
with:
name: win32
path: publish/*

testdemos:
name: 'Test demos'
runs-on: ubuntu-20.04
container: s1lentq/testdemos:latest
runs-on: ubuntu-latest
container: rehldsorg/testdemos:latest
needs: [windows]

env:
WINEDEBUG: -all
WINEDLLOVERRIDES: mshtml=
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true

defaults:
run:
shell: bash
working-directory: ../../../opt/HLDS
working-directory: /opt/HLDS

strategy:
fail-fast: false
matrix:
test: [
{ file: 'cstrike-basic-1', desc: 'CS: Testing jumping, scenarios, shooting etc' },
]

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/regamedll/* .
mv $GITHUB_WORKSPACE/tests/mp.dll cstrike/dlls/mp.dll

descs=(
"CS: Testing jumping, scenarios, shooting etc"
)

demos=(
"cstrike-basic-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-20.04
runs-on: ubuntu-latest
container: debian:11-slim

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true

- name: Check dependencies
- name: Install dependencies
run: |
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib
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: |
Expand All @@ -171,7 +144,7 @@ jobs:
fi
shell: bash

- name: Build
- name: Build using GCC Compiler
run: |
rm -rf build && CC=gcc CXX=g++ cmake -B build && cmake --build build -j8

Expand Down Expand Up @@ -199,31 +172,25 @@ 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 cssdk
rm -f appversion.h

publish:
name: 'Publish'
runs-on: ubuntu-latest
needs: [windows, testdemos, linux]

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

Expand Down Expand Up @@ -264,8 +231,3 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.API_TOKEN }}

- name: Cleanup temporary artifacts
if: success() && steps.publish-job.outcome == 'success'
run: |
rm -rf bin dist debug cssdk
rm -f *.zip appversion.h
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
| swapteams | Swap the teams and restart the game (1 sec delay to restart by default).<br/> Args: <br/>`0` - swap teams without restart. <br/> `>0.001` - time delay in seconds to restart the round after swap. |
| give | Give weapon command.<br/> Args:<br/><weapon_name><br/>Usage:<br/>`give weapon_ak47`<br/>`give weapon_usp`<br/><br/>NOTE: `sv_cheats 1` required. |
| impulse 255 | Give all weapons.<br/><br/>NOTE: `sv_cheats 1` required. |
| impulse 200 | Noclip with air acceleration.<br/><br/>NOTE: `sv_cheats 1` required. |

## Configuration (cvars)
<details>
Expand Down Expand Up @@ -127,11 +128,11 @@ This means that plugins that do binary code analysis (Orpheu for example) probab

## How to install zBot for CS 1.6?
* Extract all the files from an [archive](regamedll/extra/zBot/bot_profiles.zip?raw=true)
* Enter `-bots` option at the command line HLDS
* Enable CVar `bot_enable 1` in `cstrike/game_init.cfg` (if this config file does not exist, create it)

## How to install CSCZ hostage AI for CS 1.6?
## How to install CS:CZ hostage AI for CS 1.6?
* Extract all the files from an [archive](regamedll/extra/HostageImprov/host_improv.zip?raw=true)
* Enter `-host-improv` option at the command line HLDS
* Enable CVar `hostage_ai_enable 1` in `cstrike/game_init.cfg` (if this config file does not exist, create it)

## Build instructions
### Checking requirements
Expand Down
15 changes: 15 additions & 0 deletions dist/game_init.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Enables ZBots for the server
// NOTE: ZBots are always enabled on a listen server, regardless of this cvar
// 0 - disabled
// 1 - enabled
//
// Default value: "0"
bot_enable "0"

// Enables the improve AI for hostages from CS:CZ
// 0 - disabled (classic hostage)
// 1 - enabled (improved hostage)
//
// Default value: "0"
hostage_ai_enable "0"

// Sets mins/maxs hull bounds for the player.
// 0 - disabled (default behaviour, sets engine)
// 1 - enabled (sets gamedll)
Expand Down
1 change: 1 addition & 0 deletions regamedll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ target_compile_definitions(regamedll PRIVATE
_strnicmp=strncasecmp
_strdup=strdup
_unlink=unlink
_snprintf=snprintf
_vsnprintf=vsnprintf
_write=write
_close=close
Expand Down
6 changes: 6 additions & 0 deletions regamedll/dlls/API/CAPI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ GAMEHOOK_REGISTRY(CBasePlayer_PlayerDeathThink);
GAMEHOOK_REGISTRY(CBasePlayer_Observer_Think);
GAMEHOOK_REGISTRY(CBasePlayer_RemoveAllItems);

GAMEHOOK_REGISTRY(CSGameRules_CheckGameOver);
GAMEHOOK_REGISTRY(CSGameRules_CheckTimeLimit);
GAMEHOOK_REGISTRY(CSGameRules_CheckFragLimit);
GAMEHOOK_REGISTRY(CSGameRules_CheckMaxRounds);
GAMEHOOK_REGISTRY(CSGameRules_CheckWinLimit);

int CReGameApi::GetMajorVersion() {
return REGAMEDLL_API_VERSION_MAJOR;
}
Expand Down
32 changes: 32 additions & 0 deletions regamedll/dlls/API/CAPI_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,26 @@ typedef IHookChainRegistryClassImpl<void, CBasePlayer> CReGameHookRegistry_CBase
typedef IHookChainClassImpl<void, CBasePlayer, BOOL> CReGameHook_CBasePlayer_RemoveAllItems;
typedef IHookChainRegistryClassImpl<void, CBasePlayer, BOOL> CReGameHookRegistry_CBasePlayer_RemoveAllItems;

// CHalfLifeMultiplay::CheckGameOver hook
typedef IHookChainClassImpl<BOOL, class CHalfLifeMultiplay> CReGameHook_CSGameRules_CheckGameOver;
typedef IHookChainRegistryClassEmptyImpl<BOOL, class CHalfLifeMultiplay> CReGameHookRegistry_CSGameRules_CheckGameOver;

// CHalfLifeMultiplay::CheckTimeLimit hook
typedef IHookChainClassImpl<BOOL, class CHalfLifeMultiplay> CReGameHook_CSGameRules_CheckTimeLimit;
typedef IHookChainRegistryClassEmptyImpl<BOOL, class CHalfLifeMultiplay> CReGameHookRegistry_CSGameRules_CheckTimeLimit;

// CHalfLifeMultiplay::CheckFragLimit hook
typedef IHookChainClassImpl<BOOL, class CHalfLifeMultiplay> CReGameHook_CSGameRules_CheckFragLimit;
typedef IHookChainRegistryClassEmptyImpl<BOOL, class CHalfLifeMultiplay> CReGameHookRegistry_CSGameRules_CheckFragLimit;

// CHalfLifeMultiplay::CheckMaxRounds hook
typedef IHookChainClassImpl<BOOL, class CHalfLifeMultiplay> CReGameHook_CSGameRules_CheckMaxRounds;
typedef IHookChainRegistryClassEmptyImpl<BOOL, class CHalfLifeMultiplay> CReGameHookRegistry_CSGameRules_CheckMaxRounds;

// CHalfLifeMultiplay::CheckWinLimit hook
typedef IHookChainClassImpl<BOOL, class CHalfLifeMultiplay> CReGameHook_CSGameRules_CheckWinLimit;
typedef IHookChainRegistryClassEmptyImpl<BOOL, class CHalfLifeMultiplay> CReGameHookRegistry_CSGameRules_CheckWinLimit;

class CReGameHookchains: public IReGameHookchains {
public:
// CBasePlayer virtual
Expand Down Expand Up @@ -911,6 +931,12 @@ class CReGameHookchains: public IReGameHookchains {
CReGameHookRegistry_CBasePlayer_Observer_Think m_CBasePlayer_Observer_Think;
CReGameHookRegistry_CBasePlayer_RemoveAllItems m_CBasePlayer_RemoveAllItems;

CReGameHookRegistry_CSGameRules_CheckGameOver m_CSGameRules_CheckGameOver;
CReGameHookRegistry_CSGameRules_CheckTimeLimit m_CSGameRules_CheckTimeLimit;
CReGameHookRegistry_CSGameRules_CheckFragLimit m_CSGameRules_CheckFragLimit;
CReGameHookRegistry_CSGameRules_CheckMaxRounds m_CSGameRules_CheckMaxRounds;
CReGameHookRegistry_CSGameRules_CheckWinLimit m_CSGameRules_CheckWinLimit;

public:
virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn();
virtual IReGameHookRegistry_CBasePlayer_Precache *CBasePlayer_Precache();
Expand Down Expand Up @@ -1070,6 +1096,12 @@ class CReGameHookchains: public IReGameHookchains {
virtual IReGameHookRegistry_CBasePlayer_PlayerDeathThink *CBasePlayer_PlayerDeathThink();
virtual IReGameHookRegistry_CBasePlayer_Observer_Think *CBasePlayer_Observer_Think();
virtual IReGameHookRegistry_CBasePlayer_RemoveAllItems *CBasePlayer_RemoveAllItems();

virtual IReGameHookRegistry_CSGameRules_CheckGameOver *CSGameRules_CheckGameOver();
virtual IReGameHookRegistry_CSGameRules_CheckTimeLimit *CSGameRules_CheckTimeLimit();
virtual IReGameHookRegistry_CSGameRules_CheckFragLimit *CSGameRules_CheckFragLimit();
virtual IReGameHookRegistry_CSGameRules_CheckMaxRounds *CSGameRules_CheckMaxRounds();
virtual IReGameHookRegistry_CSGameRules_CheckWinLimit *CSGameRules_CheckWinLimit();
};

extern CReGameHookchains g_ReGameHookchains;
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void CBasePlayerAmmo::Spawn()
BOOL CBasePlayerAmmo::AddAmmo(CBaseEntity *pOther)
{
auto ammoInfo = GetAmmoInfo(pev->classname);
if (pOther->GiveAmmo(ammoInfo->buyClipSize, ammoInfo->ammoName2) == -1)
if (!ammoInfo || pOther->GiveAmmo(ammoInfo->buyClipSize, ammoInfo->ammoName2) == -1)
{
return FALSE;
}
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/bot/cs_bot_chatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ bool BotPhraseManager::Initialize(const char *filename, int bankIndex)
phraseData = SharedParse(phraseData);
if (!phraseData)
{
if (phrase) delete phrase;
CONSOLE_ECHO("Error parsing '%s' - expected identifier\n", filename);
FREE_FILE(phraseDataFile);
return false;
Expand Down
5 changes: 5 additions & 0 deletions regamedll/dlls/bot/cs_bot_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ void CCSBot::OnEvent(GameEventType event, CBaseEntity *pEntity, CBaseEntity *pOt
DecreaseMorale();
}
break;
#ifdef REGAMEDLL_FIXES
case EVENT_NEW_MATCH:
m_morale = POSITIVE; // starting a new round makes everyone a little happy
break;
#endif
}

if (!IsAlive())
Expand Down
3 changes: 2 additions & 1 deletion regamedll/dlls/bot/cs_bot_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "precompiled.h"

cvar_t cv_bot_enable = { "bot_enable", "0", 0, 0.0f, nullptr };
cvar_t cv_bot_traceview = { "bot_traceview", "0", FCVAR_SERVER, 0.0f, nullptr };
cvar_t cv_bot_stop = { "bot_stop", "0", FCVAR_SERVER, 0.0f, nullptr };
cvar_t cv_bot_show_nav = { "bot_show_nav", "0", FCVAR_SERVER, 0.0f, nullptr };
Expand Down Expand Up @@ -332,7 +333,7 @@ void CCSBot::SpawnBot()
TheCSBots()->ValidateMapData();
ResetValues();

Q_strcpy(m_name, STRING(pev->netname));
Q_strlcpy(m_name, STRING(pev->netname));

SetState(&m_buyState);
SetTouch(&CCSBot::BotTouch);
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/bot/cs_bot_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#pragma once

extern cvar_t cv_bot_enable;
extern cvar_t cv_bot_traceview;
extern cvar_t cv_bot_stop;
extern cvar_t cv_bot_show_nav;
Expand Down
8 changes: 4 additions & 4 deletions regamedll/dlls/bot/cs_bot_learn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,14 @@ void CCSBot::StartSaveProcess()

void CCSBot::UpdateSaveProcess()
{
char filename[256];
char msg[256];
char cmd[128];

GET_GAME_DIR(filename);
char gd[64]{};
GET_GAME_DIR(gd);

Q_strcat(filename, "\\");
Q_strcat(filename, TheBots->GetNavMapFilename());
char filename[MAX_OSPATH];
Q_snprintf(filename, sizeof(filename), "%s\\%s", gd, TheBots->GetNavMapFilename());

HintMessageToAllPlayers("Saving...");
SaveNavigationMap(filename);
Expand Down
Loading