Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into defuser-code-clean
Browse files Browse the repository at this point in the history
  • Loading branch information
dystopm committed Jul 19, 2023
2 parents 9b02c04 + 9427767 commit 0745cfa
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 42 deletions.
1 change: 1 addition & 0 deletions regamedll/dlls/API/CAPI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ GAMEHOOK_REGISTRY(CBasePlayer_DeathSound);
GAMEHOOK_REGISTRY(CBasePlayer_JoiningThink);

GAMEHOOK_REGISTRY(FreeGameRules);
GAMEHOOK_REGISTRY(PM_LadderMove);

int CReGameApi::GetMajorVersion() {
return REGAMEDLL_API_VERSION_MAJOR;
Expand Down
7 changes: 7 additions & 0 deletions regamedll/dlls/API/CAPI_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ typedef IHookChainRegistryImpl<void, struct playermove_s *, int> CReGameHookRegi
typedef IHookChainImpl<void, int> CReGameHook_PM_AirMove;
typedef IHookChainRegistryImpl<void, int> CReGameHookRegistry_PM_AirMove;

// PM_LadderMove hook
typedef IHookChainImpl<void, struct physent_s *> CReGameHook_PM_LadderMove;
typedef IHookChainRegistryImpl<void, struct physent_s *> CReGameHookRegistry_PM_LadderMove;

// HandleMenu_ChooseAppearance hook
typedef IHookChainImpl<void, CBasePlayer *, int> CReGameHook_HandleMenu_ChooseAppearance;
typedef IHookChainRegistryImpl<void, CBasePlayer *, int> CReGameHookRegistry_HandleMenu_ChooseAppearance;
Expand Down Expand Up @@ -777,6 +781,8 @@ class CReGameHookchains: public IReGameHookchains {
CReGameHookRegistry_CBasePlayer_Pain m_CBasePlayer_Pain;
CReGameHookRegistry_CBasePlayer_DeathSound m_CBasePlayer_DeathSound;
CReGameHookRegistry_CBasePlayer_JoiningThink m_CBasePlayer_JoiningThink;

CReGameHookRegistry_PM_LadderMove m_PM_LadderMove;

CReGameHookRegistry_FreeGameRules m_FreeGameRules;

Expand Down Expand Up @@ -912,6 +918,7 @@ class CReGameHookchains: public IReGameHookchains {
virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink();

virtual IReGameHookRegistry_FreeGameRules *FreeGameRules();
virtual IReGameHookRegistry_PM_LadderMove *PM_LadderMove();
};

extern CReGameHookchains g_ReGameHookchains;
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/API/CSPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ EXT_FUNC bool CCSPlayer::JoinTeam(TeamName team)
pPlayer->StartObserver(pentSpawnSpot->v.origin, pentSpawnSpot->v.angles);

// do we have fadetoblack on? (need to fade their screen back in)
if (fadetoblack.value)
if (fadetoblack.value == FADETOBLACK_STAY)
{
UTIL_ScreenFade(pPlayer, Vector(0, 0, 0), 0.001, 0, 0, FFADE_IN);
}
Expand Down
5 changes: 5 additions & 0 deletions regamedll/dlls/animating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ NOXREF int CBaseAnimating::GetBodygroup(int iGroup)
return ::GetBodygroup(GET_MODEL_PTR(ENT(pev)), pev, iGroup);
}

float CBaseAnimating::GetSequenceDuration() const
{
return ::GetSequenceDuration(GET_MODEL_PTR(ENT(pev)), pev);
}

int CBaseAnimating::ExtractBbox(int sequence, float *mins, float *maxs)
{
return ::ExtractBbox(GET_MODEL_PTR(ENT(pev)), sequence, mins, maxs);
Expand Down
15 changes: 15 additions & 0 deletions regamedll/dlls/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@ void GetSequenceInfo(void *pmodel, entvars_t *pev, float *pflFrameRate, float *p
*pflGroundSpeed = *pflGroundSpeed * pseqdesc->fps / (pseqdesc->numframes - 1);
}

float GetSequenceDuration(void *pmodel, entvars_t *pev)
{
studiohdr_t *pstudiohdr = (studiohdr_t *)pmodel;
if (!pstudiohdr)
return 0; // model ptr is not valid

if (pev->sequence < 0 || pev->sequence >= pstudiohdr->numseq)
return 0; // sequence is not valid

// get current sequence time
mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + int(pev->sequence);

return pseqdesc->numframes / pseqdesc->fps;
}

int GetSequenceFlags(void *pmodel, entvars_t *pev)
{
studiohdr_t *pstudiohdr = (studiohdr_t *)pmodel;
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int LookupActivity(void *pmodel, entvars_t *pev, int activity);
int LookupActivityHeaviest(void *pmodel, entvars_t *pev, int activity);
int LookupSequence(void *pmodel, const char *label);
void GetSequenceInfo(void *pmodel, entvars_t *pev, float *pflFrameRate, float *pflGroundSpeed);
float GetSequenceDuration(void *pmodel, entvars_t *pev);
int GetSequenceFlags(void *pmodel, entvars_t *pev);
float SetController(void *pmodel, entvars_t *pev, int iController, float flValue);
float SetBlending(void *pmodel, entvars_t *pev, int iBlender, float flValue);
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ class CBaseAnimating: public CBaseDelay {
float SetBoneController(int iController, float flValue = 0.0f);
void InitBoneControllers();

float GetSequenceDuration() const;
float SetBlending(int iBlender, float flValue);
void GetBonePosition(int iBone, Vector &origin, Vector &angles);
void GetAutomovement(Vector &origin, Vector &angles, float flInterval = 0.1f);
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ BOOL EXT_FUNC __API_HOOK(HandleMenu_ChooseTeam)(CBasePlayer *pPlayer, int slot)
MESSAGE_END();
#endif
// do we have fadetoblack on? (need to fade their screen back in)
if (fadetoblack.value)
if (fadetoblack.value == FADETOBLACK_STAY)
{
UTIL_ScreenFade(pPlayer, Vector(0, 0, 0), 0.001, 0, 0, FFADE_IN);
}
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ void PlayerBlind(CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAt
{
UTIL_ScreenFade(pPlayer, color, fadeTime, fadeHold, alpha, 0);

if (!fadetoblack.value)
if (fadetoblack.value != FADETOBLACK_STAY)
{
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
Expand Down
9 changes: 5 additions & 4 deletions regamedll/dlls/gib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ LINK_ENTITY_TO_CLASS(gib, CGib, CCSGib)
void CGib::LimitVelocity()
{
float length = pev->velocity.Length();
float topspeed = CVAR_GET_FLOAT("sv_maxvelocity") * 0.75f;

// ceiling at 1500. The gib velocity equation is not bounded properly. Rather than tune it
// ceiling at topspeed. The gib velocity equation is not bounded properly. Rather than tune it
// in 3 separate places again, I'll just limit it here.
if (length > 1500.0)
if (length > topspeed)
{
// This should really be sv_maxvelocity * 0.75 or something
pev->velocity = pev->velocity.Normalize() * 1500;
// DONE: This should really be sv_maxvelocity * 0.75 or something
pev->velocity = pev->velocity.Normalize() * topspeed;
}
}

Expand Down
6 changes: 3 additions & 3 deletions regamedll/dlls/multiplay_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2393,7 +2393,7 @@ void CHalfLifeMultiplay::Think()
MESSAGE_BEGIN(MSG_ALL, gmsgForceCam);
WRITE_BYTE(forcecamera.value != 0);
WRITE_BYTE(forcechasecam.value != 0);
WRITE_BYTE(fadetoblack.value != 0);
WRITE_BYTE(fadetoblack.value == FADETOBLACK_STAY);
MESSAGE_END();

m_flForceCameraValue = forcecamera.value;
Expand Down Expand Up @@ -3456,7 +3456,7 @@ void CHalfLifeMultiplay::InitHUD(CBasePlayer *pl)
MESSAGE_BEGIN(MSG_ONE, gmsgForceCam, nullptr, pl->edict());
WRITE_BYTE(forcecamera.value != 0);
WRITE_BYTE(forcechasecam.value != 0);
WRITE_BYTE(fadetoblack.value != 0);
WRITE_BYTE(fadetoblack.value == FADETOBLACK_STAY);
MESSAGE_END();

if (m_bGameOver)
Expand Down Expand Up @@ -3874,7 +3874,7 @@ BOOL EXT_FUNC CHalfLifeMultiplay::__API_HOOK(FPlayerCanRespawn)(CBasePlayer *pPl
{
// If this player just connected and fadetoblack is on, then maybe
// the server admin doesn't want him peeking around.
if (fadetoblack.value != 0.0f)
if (fadetoblack.value == FADETOBLACK_STAY)
{
UTIL_ScreenFade(pPlayer, Vector(0, 0, 0), 3, 3, 255, (FFADE_OUT | FFADE_STAYOUT));
}
Expand Down
4 changes: 2 additions & 2 deletions regamedll/dlls/observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int __API_HOOK(GetForceCamera)(CBasePlayer *pObserver)
{
int retVal;

if (!fadetoblack.value)
if (fadetoblack.value != FADETOBLACK_STAY)
{
retVal = int(CVAR_GET_FLOAT("mp_forcechasecam"));

Expand Down Expand Up @@ -51,7 +51,7 @@ void UpdateClientEffects(CBasePlayer *pObserver, int oldMode)
{
bool clearProgress = false;
bool clearBlindness = false;
bool blindnessOk = (fadetoblack.value == 0);
bool blindnessOk = (fadetoblack.value != FADETOBLACK_STAY);
bool clearNightvision = false;

if (pObserver->GetObserverMode() == OBS_IN_EYE)
Expand Down
6 changes: 6 additions & 0 deletions regamedll/dlls/observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
#define CAMERA_MODE_SPEC_ONLY_TEAM 1
#define CAMERA_MODE_SPEC_ONLY_FIRST_PERSON 2

enum FadeToBlack {
FADETOBLACK_OFF,
FADETOBLACK_STAY,
FADETOBLACK_AT_DYING,
};

int GetForceCamera(CBasePlayer *pObserver);
void UpdateClientEffects(CBasePlayer *pObserver, int oldMode);

Expand Down
53 changes: 25 additions & 28 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,8 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)
UTIL_ScreenFade(this, Vector(0, 0, 0), 3, 3, 255, (FFADE_OUT | FFADE_STAYOUT));
}
#else

float flDyingDuration = GetSequenceDuration() + CGameRules::GetDyingTime();
switch ((int)fadetoblack.value)
{
default:
Expand All @@ -2299,12 +2301,12 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)

break;
}
case 1:
case FADETOBLACK_STAY:
{
UTIL_ScreenFade(this, Vector(0, 0, 0), 3, 3, 255, (FFADE_OUT | FFADE_STAYOUT));
UTIL_ScreenFade(this, Vector(0, 0, 0), 0.8f, flDyingDuration, 255, (FFADE_OUT | FFADE_STAYOUT));
break;
}
case 2:
case FADETOBLACK_AT_DYING:
{
pev->iuser1 = OBS_CHASE_FREE;
pev->iuser2 = ENTINDEX(edict());
Expand All @@ -2315,15 +2317,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)
MESSAGE_BEGIN(MSG_ONE, gmsgADStop, nullptr, pev);
MESSAGE_END();

for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer* pObserver = UTIL_PlayerByIndex(i);

if (pObserver == this || (pObserver && pObserver->IsObservingPlayer(this)))
{
UTIL_ScreenFade(pObserver, Vector(0, 0, 0), 1, 4, 255, (FFADE_OUT));
}
}
UTIL_ScreenFade(this, Vector(0, 0, 0), 0.8f, flDyingDuration, 255, (FFADE_OUT));

break;
}
Expand Down Expand Up @@ -8776,6 +8770,23 @@ int GetPlayerGaitsequence(const edict_t *pEdict)
return pPlayer->m_iGaitsequence;
}

float CBasePlayer::GetDyingAnimationDuration() const
{
float animDuration = -1.0f;

if (CGameRules::GetDyingTime() < DEATH_ANIMATION_TIME) // a short time, timeDiff estimates to be small
{
float flSequenceDuration = GetSequenceDuration();
if (flSequenceDuration > 0)
animDuration = flSequenceDuration;
}

if (animDuration <= 0)
animDuration = CGameRules::GetDyingTime(); // in case of failure

return animDuration;
}

void CBasePlayer::SpawnClientSideCorpse()
{
#ifdef REGAMEDLL_FIXES
Expand All @@ -8798,21 +8809,7 @@ void CBasePlayer::SpawnClientSideCorpse()
#ifdef REGAMEDLL_ADD
if (CGameRules::GetDyingTime() < DEATH_ANIMATION_TIME) // a short time, timeDiff estimates to be small
{
float animDuration = -1.0;

studiohdr_t *pstudiohdr = (studiohdr_t *)GET_MODEL_PTR(ENT(pev));
if (pstudiohdr && pev->sequence < pstudiohdr->numseq) // model ptr and sequence validation
{
// get current sequence time
mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + int(pev->sequence);
animDuration = pseqdesc->numframes / pseqdesc->fps;
}

if (animDuration <= 0.0)
{
// in case of failure
animDuration = DEATH_ANIMATION_TIME;
}
float animDuration = GetDyingAnimationDuration();

// client receives a negative value
animDuration *= -1.0;
Expand Down Expand Up @@ -9896,7 +9893,7 @@ void CBasePlayer::UpdateLocation(bool forceUpdate)

const char *placeName = "";

if (pev->deadflag == DEAD_NO && AreRunningCZero())
if (pev->deadflag == DEAD_NO && AreBotsAllowed())
{
// search the place name where is located the player
Place playerPlace = TheNavAreaGrid.GetPlace(&pev->origin);
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ class CBasePlayer: public CBaseMonster {
static CBasePlayer *Instance(entvars_t *pev) { return Instance(ENT(pev)); }
static CBasePlayer *Instance(int offset) { return Instance(ENT(offset)); }

float GetDyingAnimationDuration() const;
void SpawnClientSideCorpse();
void Observer_FindNextPlayer(bool bReverse, const char *name = nullptr);
CBasePlayer *Observer_IsValidTarget(int iPlayerIndex, bool bSameTeam);
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/tutor_base_tutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ char *TutorMessageEvent::GetNextParameter(char *buf, int buflen)
Q_strncpy(buf, param->m_data, buflen);

#ifdef REGAMEDLL_FIXES
buf[buflen] = '\0';
buf[buflen - 1] = '\0';
#endif

delete param;
Expand Down
4 changes: 3 additions & 1 deletion regamedll/pm_shared/pm_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,9 @@ void PM_Duck()
}
}

void PM_LadderMove(physent_t *pLadder)
LINK_HOOK_VOID_CHAIN(PM_LadderMove, (physent_t *pLadder), pLadder);

void EXT_FUNC __API_HOOK(PM_LadderMove)(physent_t *pLadder)
{
vec3_t ladderCenter;
trace_t trace;
Expand Down
2 changes: 2 additions & 0 deletions regamedll/pm_shared/pm_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ void PM_Init(struct playermove_s *ppmove);
void PM_Move(struct playermove_s *ppmove, int server);
char PM_FindTextureType(char *name);
void PM_AirMove_internal();
void PM_LadderMove(physent_t *pLadder);

#ifdef REGAMEDLL_API
void PM_Init_OrigFunc(struct playermove_s *ppmove);
void PM_Move_OrigFunc(struct playermove_s *ppmove, int server);
void PM_AirMove_OrigFunc(int playerIndex = 0);
void PM_UpdateStepSound_OrigFunc();
void PM_LadderMove_OrigFunc(physent_t *pLadder);
#else
void PM_AirMove(int playerIndex = 0);
#endif
Expand Down
5 changes: 5 additions & 0 deletions regamedll/public/regamedll/regamedll_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ typedef IHookChainRegistry<void, struct playermove_s *, int> IReGameHookRegistry
typedef IHookChain<void, int> IReGameHook_PM_AirMove;
typedef IHookChainRegistry<void, int> IReGameHookRegistry_PM_AirMove;

// PM_LadderMove hook
typedef IHookChain<void, struct physent_s *> IReGameHook_PM_LadderMove;
typedef IHookChainRegistry<void, struct physent_s *> IReGameHookRegistry_PM_LadderMove;

// HandleMenu_ChooseAppearance hook
typedef IHookChain<void, class CBasePlayer *, int> IReGameHook_HandleMenu_ChooseAppearance;
typedef IHookChainRegistry<void, class CBasePlayer *, int> IReGameHookRegistry_HandleMenu_ChooseAppearance;
Expand Down Expand Up @@ -659,6 +663,7 @@ class IReGameHookchains {
virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink() = 0;

virtual IReGameHookRegistry_FreeGameRules *FreeGameRules() = 0;
virtual IReGameHookRegistry_PM_LadderMove *PM_LadderMove() = 0;
};

struct ReGameFuncs_t {
Expand Down

0 comments on commit 0745cfa

Please sign in to comment.