Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rehlds/ReGameDLL_CS
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-up committed Jan 10, 2025
2 parents 2a9dbb8 + f63ad67 commit c6cf29c
Show file tree
Hide file tree
Showing 35 changed files with 206 additions and 114 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,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
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
1 change: 1 addition & 0 deletions 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
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: 3 additions & 5 deletions regamedll/dlls/bot/cs_bot_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,12 +889,10 @@ void CCSBotManager::MaintainBotQuota()
if (m_isLearningMap)
return;

int totalHumansInGame = UTIL_HumansInGame();
int humanPlayersInGame = UTIL_HumansInGame(IGNORE_SPECTATORS);
int spectatorPlayersInGame = UTIL_SpectatorsInGame();
int humanPlayersInGame = UTIL_HumansInGame();

// don't add bots until local player has been registered, to make sure he's player ID #1
if (!IS_DEDICATED_SERVER() && totalHumansInGame == 0)
if (!IS_DEDICATED_SERVER() && humanPlayersInGame == 0)
return;

int desiredBotCount = int(cv_bot_quota.value);
Expand Down Expand Up @@ -949,7 +947,7 @@ void CCSBotManager::MaintainBotQuota()
// wait for a player to join, if necessary
if (cv_bot_join_after_player.value > 0.0)
{
if (humanPlayersInGame == 0 && spectatorPlayersInGame == 0)
if (humanPlayersInGame == 0)
desiredBotCount = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions regamedll/dlls/career_tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void CCareerTask::OnEvent(GameEventType event, CBasePlayer *pVictim, CBasePlayer

while ((pHostage = UTIL_FindEntityByClassname(pHostage, "hostage_entity")))
{
if (pHostage && pHostage->IsDead())
if (pHostage->IsDead())
hostagesCount++;
}

Expand Down Expand Up @@ -389,14 +389,14 @@ void CCareerTaskManager::Reset(bool deleteTasks)
delete task;

m_tasks.clear();
m_nextId = 0;
}
else
{
for (auto task : m_tasks)
task->Reset();
}

m_nextId = 0;
m_finishedTaskTime = 0;
m_finishedTaskRound = 0;
m_shouldLatchRoundEndMessage = false;
Expand Down
4 changes: 3 additions & 1 deletion regamedll/dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,9 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
if (*p == '"')
{
p++;
p[Q_strlen(p) - 1] = '\0';
size_t len = Q_strlen(p);
if (len > 0)
p[len - 1] = '\0';
}

// Check if buffer contains an invalid unicode sequence
Expand Down
2 changes: 0 additions & 2 deletions regamedll/dlls/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ void RadiusDamage(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker
damageRatio = GetAmountOfPlayerVisible(vecSrc, pEntity);
}

damageRatio = GetAmountOfPlayerVisible(vecSrc, pEntity);

float length;
#ifdef REGAMEDLL_ADD
// allow to damage breakable objects
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/ehandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ inline edict_t *EntityHandle<T>::Set(edict_t *pEdict)
{
m_serialnumber = pEdict->serialnumber;
}
else
{
m_serialnumber = 0;
}

return pEdict;
}
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/func_tank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void CFuncTank::ControllerPostFrame()

Assert(m_pController != nullptr);

if (m_pController->pev->button & IN_ATTACK)
if (m_pController && m_pController->pev->button & IN_ATTACK)
{
Vector vecForward;
UTIL_MakeVectorsPrivate(pev->angles, vecForward, nullptr, nullptr);
Expand Down
17 changes: 10 additions & 7 deletions regamedll/dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ cvar_t legacy_vehicle_block = { "mp_legacy_vehicle_block", "1", 0,
cvar_t dying_time = { "mp_dying_time", "3.0", 0, 3.0f, nullptr };
cvar_t defuser_allocation = { "mp_defuser_allocation", "0", 0, 0.0f, nullptr };
cvar_t location_area_info = { "mp_location_area_info", "0", 0, 0.0f, nullptr };
cvar_t chat_loc_fallback = { "mp_chat_loc_fallback", "1", 1, 0.0f, nullptr };
cvar_t chat_loc_fallback = { "mp_chat_loc_fallback", "1", 0, 1.0f, nullptr };

cvar_t item_respawn_time = { "mp_item_respawn_time", "30", FCVAR_SERVER, 30.0f, nullptr };
cvar_t weapon_respawn_time = { "mp_weapon_respawn_time", "20", FCVAR_SERVER, 20.0f, nullptr };
Expand Down Expand Up @@ -462,13 +462,22 @@ void EXT_FUNC GameDLLInit()
CVAR_REGISTER(&vote_flags);
CVAR_REGISTER(&votemap_min_time);

CVAR_REGISTER(&cv_bot_enable);
CVAR_REGISTER(&cv_hostage_ai_enable);

CVAR_REGISTER(&scoreboard_fix);

// print version
CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n");

// execute initial pre-configurations
SERVER_COMMAND("exec game_init.cfg\n");
SERVER_EXECUTE();

#endif // REGAMEDLL_ADD

Regamedll_Game_Init();

Bot_RegisterCVars();
Tutor_RegisterCVars();
Hostage_RegisterCVars();
Expand All @@ -477,12 +486,6 @@ void EXT_FUNC GameDLLInit()
VoiceGameMgr_RegisterCVars();
#endif

#ifdef REGAMEDLL_ADD
// execute initial pre-configurations
SERVER_COMMAND("exec game_init.cfg\n");
SERVER_EXECUTE();
#endif

}

SpewRetval_t GameDLL_SpewHandler(SpewType_t spewType, int level, const char *pMsg)
Expand Down
1 change: 0 additions & 1 deletion regamedll/dlls/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ BOOL gDisplayTitle;
bool g_bIsBeta = false;
bool g_bIsCzeroGame = false;
bool g_bAllowedCSBot = false;
bool g_bHostageImprov = false;
1 change: 0 additions & 1 deletion regamedll/dlls/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ extern BOOL gDisplayTitle;
extern bool g_bIsBeta;
extern bool g_bIsCzeroGame;
extern bool g_bAllowedCSBot;
extern bool g_bHostageImprov;
1 change: 0 additions & 1 deletion regamedll/dlls/h_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ C_DLLEXPORT void WINAPI GiveFnptrsToDll(enginefuncs_t *pEnginefuncsTable, global
gpGlobals = pGlobals;

FileSystem_Init();
Regamedll_Game_Init();
}

#if defined(_LINUX)
Expand Down
54 changes: 35 additions & 19 deletions regamedll/dlls/hostage/hostage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "precompiled.h"

cvar_t cv_hostage_ai_enable = { "hostage_ai_enable", "0", 0, 0.0f, nullptr };
cvar_t cv_hostage_debug = { "hostage_debug", "0", FCVAR_SERVER, 0.0f, nullptr };
cvar_t cv_hostage_stop = { "hostage_stop", "0", FCVAR_SERVER, 0.0f, nullptr };

Expand Down Expand Up @@ -268,39 +269,48 @@ void CHostage::Spawn()

void CHostage::Precache()
{
if (AreImprovAllowed())
if (cv_hostage_ai_enable.value)
{
string_t model = iStringNull;

static int which = 0;
switch (which)
{
default:
case REGULAR_GUY:
pev->model = MAKE_STRING("models/hostageA.mdl");
model = MAKE_STRING("models/hostageA.mdl");
break;
case OLD_GUY:
pev->model = MAKE_STRING("models/hostageB.mdl");
model = MAKE_STRING("models/hostageB.mdl");
break;
case BLACK_GUY:
pev->model = MAKE_STRING("models/hostageC.mdl");
model = MAKE_STRING("models/hostageC.mdl");
break;
case GOOFY_GUY:
pev->model = MAKE_STRING("models/hostageD.mdl");
break;
default:
model = MAKE_STRING("models/hostageD.mdl");
break;
}

m_whichModel = static_cast<ModelType>(which);

if (++which > 3)
which = 0;
if (++which > GOOFY_GUY)
which = REGULAR_GUY;

if (g_pFileSystem->FileExists(model))
{
pev->model = model;
}
else
{
// It seems that the model is missing, so use classic hostages
CVAR_SET_FLOAT("hostage_ai_enable", 0);
}
}
else

if (pev->model.IsNull())
{
m_whichModel = REGULAR_GUY;
if (pev->model.IsNull())
{
pev->model = MAKE_STRING("models/scientist.mdl");
}
pev->model = MAKE_STRING("models/scientist.mdl");
}

PRECACHE_MODEL(pev->model);
Expand Down Expand Up @@ -342,7 +352,7 @@ void CHostage::IdleThink()
const float giveUpTime = (1 / 30.0f);
float const updateRate = 0.1f;

if (AreImprovAllowed() && !TheNavAreaList.empty())
if (cv_hostage_ai_enable.value && !TheNavAreaList.empty())
{
if (!m_improv)
{
Expand Down Expand Up @@ -619,7 +629,7 @@ void CHostage::TraceAttack(entvars_t *pevAttacker, float flDamage, Vector vecDir
BOOL CHostage::TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType)
{
#ifdef REGAMEDLL_ADD
if (!CanTakeDamage(pevAttacker))
if (pevAttacker && !CanTakeDamage(pevAttacker))
return FALSE;
#endif

Expand Down Expand Up @@ -771,7 +781,7 @@ void CHostage::SetDeathActivity()
return;
}

if (AreImprovAllowed())
if (cv_hostage_ai_enable.value)
{
switch (m_LastHitGroup)
{
Expand Down Expand Up @@ -1397,7 +1407,7 @@ void Hostage_RegisterCVars()
{
// These cvars are only used in czero
#ifdef REGAMEDLL_FIXES
if (!AreImprovAllowed())
if (!cv_hostage_ai_enable.value)
return;
#endif

Expand Down Expand Up @@ -1432,7 +1442,7 @@ void CHostageManager::ServerActivate()
AddHostage(pHostage);
}

if (AreImprovAllowed())
if (cv_hostage_ai_enable.value)
{
for (auto& snd : hostageSoundStruct) {
m_chatter.AddSound(snd.type, snd.fileName);
Expand Down Expand Up @@ -1568,6 +1578,9 @@ void SimpleChatter::AddSound(HostageChatterType type, char *filename)

Q_snprintf(actualFilename, sizeof(actualFilename), "sound\\%s", filename);

if (!g_pFileSystem->FileExists(actualFilename))
return;

chatter->file[chatter->count].filename = CloneString(filename);
chatter->file[chatter->count].duration = (double)GET_APPROX_WAVE_PLAY_LEN(actualFilename) / 1000.0;

Expand Down Expand Up @@ -1605,6 +1618,9 @@ void SimpleChatter::Shuffle(ChatterSet *chatter)
char *SimpleChatter::GetSound(HostageChatterType type, float *duration)
{
ChatterSet *chatter = &m_chatter[type];
if (chatter->count == 0)
return nullptr;

char *sound;

Shuffle(chatter);
Expand Down
7 changes: 1 addition & 6 deletions regamedll/dlls/hostage/hostage.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum HostageChatterType
extern CHostageManager *g_pHostages;
extern int g_iHostageNumber;

extern cvar_t cv_hostage_ai_enable;
extern cvar_t cv_hostage_debug;
extern cvar_t cv_hostage_stop;

Expand Down Expand Up @@ -284,11 +285,5 @@ class CHostageManager
SimpleChatter m_chatter;
};

// Determine whether hostage improv can be used or not
inline bool AreImprovAllowed()
{
return g_bHostageImprov;
}

void Hostage_RegisterCVars();
void InstallHostageManager();
2 changes: 1 addition & 1 deletion regamedll/dlls/hostage/states/hostage_idle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void HostageIdleState::OnUpdate(CHostageImprov *improv)
}
}

if (m_moveState && improv->IsAtMoveGoal())
if (m_moveState != NotMoving && improv->IsAtMoveGoal())
{
m_moveState = NotMoving;

Expand Down
Loading

0 comments on commit c6cf29c

Please sign in to comment.