Skip to content

Commit

Permalink
同步官方分支 (#20)
Browse files Browse the repository at this point in the history
* Update workflows/build.yml
Fix temporarily testdemos

* Fix compiler warnings

* Fixed a bug in spectator move with no apply friction when stopped

* Update build.yml

* Add support IN_RUN key for +speed button in spectator/noclip and walk moves
Add cheat impulse for enable Noclip with air accelerate

* try fix a crash due to the deletion of an item in an unusual way
related rehlds#870, rehlds#752, rehlds#924, rehlds#957

* Extend KickBack functionalities (rehlds#980)

---------

Co-authored-by: s1lentq <s1lentsk@yandex.ru>
Co-authored-by: Francisco Muñoz <fjmunozpena@gmail.com>
  • Loading branch information
3 people authored Aug 11, 2024
1 parent 4a41ef6 commit 5e03f01
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 38 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ jobs:
move msvc\${{ env.buildRelease }}\mp.pdb publish\debug\mp.pdb
- name: Deploy artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v3.1.1
with:
name: win32
path: publish/*

testdemos:
if: false # TODO: FIXME!!
name: 'Test demos (FIXME)'
name: 'Test demos'
runs-on: ubuntu-20.04
container: s1lentq/testdemos:latest
needs: [windows]

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

defaults:
run:
Expand All @@ -81,7 +81,7 @@ jobs:

steps:
- name: Deploying windows artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: win32

Expand Down Expand Up @@ -146,12 +146,11 @@ jobs:
run: |
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y clang
sudo apt-get install -y gcc-multilib g++-multilib
- name: Build and Run unittests
run: |
rm -rf build && CC=clang CXX=clang++ cmake -DCMAKE_BUILD_TYPE=Unittests -B build && cmake --build build -j8
rm -rf build && CC=gcc CXX=g++ cmake -DCMAKE_BUILD_TYPE=Unittests -B build && cmake --build build -j8
retVal=0
./build/regamedll/cs 2> /dev/null > result.log || retVal=$?
while read line; do
Expand All @@ -172,9 +171,9 @@ jobs:
fi
shell: bash

- name: Build using Clang C++ Compiler
- name: Build
run: |
rm -rf build && CC=clang CXX=clang++ cmake -B build && cmake --build build -j8
rm -rf build && CC=gcc CXX=g++ cmake -B build && cmake --build build -j8
- name: Prepare CSSDK
run: |
Expand All @@ -200,7 +199,7 @@ jobs:
shell: bash

- name: Deploy artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v3.1.1
id: upload-job
with:
name: linux32
Expand All @@ -219,12 +218,12 @@ jobs:

steps:
- name: Deploying linux artifacts
uses: actions/download-artifact@v4
uses: actions/download-artifact@v3
with:
name: linux32

- name: Deploying windows artifacts
uses: actions/download-artifact@v4
uses: actions/download-artifact@v3
with:
name: win32

Expand Down
24 changes: 24 additions & 0 deletions regamedll/dlls/cbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,30 @@ void OnFreeEntPrivateData(edict_t *pEnt)
if (!pEntity)
return;

#ifdef REGAMEDLL_FIXES
// FIXED: Ensure this item will be removed from the owner player's inventory 'm_rgpPlayerItems[]'
// to avoid dangling pointers
CBasePlayerItem *pItem = dynamic_cast<CBasePlayerItem *>(pEntity);
if (pItem)
{
CBasePlayer *pOwner = GET_PRIVATE<CBasePlayer>(pItem->pev->owner);
if (pOwner && pOwner->IsPlayer())
{
if (pOwner->m_pActiveItem == pItem && pItem->IsWeapon())
((CBasePlayerWeapon *)pItem)->RetireWeapon();

if (pOwner->RemovePlayerItem(pItem))
{
// Ammo must be dropped, otherwise grenades cannot be buy or picked up
if (IsGrenadeWeapon(pItem->m_iId) || pItem->m_iId == WEAPON_C4)
pOwner->m_rgAmmo[pItem->PrimaryAmmoIndex()] = 0;

pOwner->pev->weapons &= ~(1 << pItem->m_iId);
}
}
}
#endif

#ifdef REGAMEDLL_API
pEntity->OnDestroy();
#endif
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/multiplay_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4293,7 +4293,7 @@ int CHalfLifeMultiplay::ItemShouldRespawn(CItem *pItem)
// At what time in the future may this Item respawn?
float CHalfLifeMultiplay::FlItemRespawnTime(CItem *pItem)
{
#ifdef REGAMEDLL_ADD;
#ifdef REGAMEDLL_ADD
return gpGlobals->time + item_respawn_time.value;
#else
return gpGlobals->time + ITEM_RESPAWN_TIME;
Expand Down
20 changes: 20 additions & 0 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6778,6 +6778,26 @@ void CBasePlayer::CheatImpulseCommands(int iImpulse)

break;
}
#ifdef REGAMEDLL_ADD
// noclip with air acceleration
case 200:
{
if (pev->movetype == MOVETYPE_WALK)
{
pev->movetype = MOVETYPE_NOCLIP;
pev->fuser3 = MAX_PLAYER_RUN_MODIFIER_SPEED; // air acceleration increases xN times
ALERT(at_console, "noclip ON\n");
}
else
{
pev->movetype = MOVETYPE_WALK;
pev->fuser3 = 0;
ALERT(at_console, "noclip OFF\n");
}

break;
}
#endif
case 202:
{
// Random blood splatter
Expand Down
7 changes: 4 additions & 3 deletions regamedll/dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ const int MAX_BUFFER_MENU_BRIEFING = 50;
const float SUIT_UPDATE_TIME = 3.5f;
const float SUIT_FIRST_UPDATE_TIME = 0.1f;

const float MAX_PLAYER_FATAL_FALL_SPEED = 1100.0f;
const float MAX_PLAYER_SAFE_FALL_SPEED = 500.0f;
const float MAX_PLAYER_USE_RADIUS = 64.0f;
const float MAX_PLAYER_FATAL_FALL_SPEED = 1100.0f;
const float MAX_PLAYER_SAFE_FALL_SPEED = 500.0f;
const float MAX_PLAYER_USE_RADIUS = 64.0f;
const float MAX_PLAYER_RUN_MODIFIER_SPEED = 10.0f; // x10 speed run when IN_RUN button is pressed

const float ARMOR_RATIO = 0.5f; // Armor Takes 50% of the damage
const float ARMOR_BONUS = 0.5f; // Each Point of Armor is work 1/x points of health
Expand Down
36 changes: 36 additions & 0 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,41 @@ LINK_HOOK_CLASS_VOID_CHAIN(CBasePlayerWeapon, KickBack, (float up_base, float la

void EXT_FUNC CBasePlayerWeapon::__API_HOOK(KickBack)(float up_base, float lateral_base, float up_modifier, float lateral_modifier, float up_max, float lateral_max, int direction_change)
{
#ifdef REGAMEDLL_ADD
real_t flKickUp = up_base;
float flKickLateral = lateral_base;

if (m_iShotsFired > 1) // consider == 0 case
{
flKickUp += m_iShotsFired * up_modifier;
flKickLateral += m_iShotsFired * lateral_modifier;
}

if (up_max == 0.0f) // boundaryless vertical kick
{
m_pPlayer->pev->punchangle.x -= flKickUp;
}
else if (m_pPlayer->pev->punchangle.x > -up_max) // do not kick when already out of boundaries
{
m_pPlayer->pev->punchangle.x = Q_max<real_t>(m_pPlayer->pev->punchangle.x - flKickUp, -up_max);
}

if (lateral_max == 0.0f) // boundaryless horizontal kick
{
m_pPlayer->pev->punchangle.y += flKickLateral * (m_iDirection * 2 - 1);
}
else if (Q_fabs(m_pPlayer->pev->punchangle.y) < lateral_max) // do not kick when already out of boundaries
{
m_pPlayer->pev->punchangle.y = (m_iDirection == 1) ?
Q_min(m_pPlayer->pev->punchangle.y + flKickLateral, lateral_max) :
Q_max(m_pPlayer->pev->punchangle.y - flKickLateral, -lateral_max);
}

if (direction_change > 0 && !RANDOM_LONG(0, direction_change)) // be sure to not waste RNG consumption
{
m_iDirection = !m_iDirection;
}
#else
real_t flKickUp;
float flKickLateral;

Expand Down Expand Up @@ -764,6 +799,7 @@ void EXT_FUNC CBasePlayerWeapon::__API_HOOK(KickBack)(float up_base, float later
{
m_iDirection = !m_iDirection;
}
#endif
}

void CBasePlayerWeapon::FireRemaining(int &shotsFired, float &shootTime, BOOL bIsGlock)
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_awp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ void CAWP::AWPFire(float flSpread, float flCycleTime, BOOL fUseAutoAim)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2.0f;
#endif
}

void CAWP::Reload()
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_deagle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ void CDEAGLE::DEAGLEFire(float flSpread, float flCycleTime, BOOL fUseSemi)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.8f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2;
#endif
ResetPlayerShieldAnim();
}

Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_elite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ void CELITE::ELITEFire(float flSpread, float flCycleTime, BOOL fUseSemi)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2.0f;
#endif
}

void CELITE::Reload()
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_fiveseven.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ void CFiveSeven::FiveSevenFire(float flSpread, float flCycleTime, BOOL fUseSemi)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2.0f;
#endif
ResetPlayerShieldAnim();
}

Expand Down
7 changes: 7 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_g3sg1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,15 @@ void CG3SG1::G3SG1Fire(float flSpread, float flCycleTime, BOOL fUseAutoAim)

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.8f;

#ifdef REGAMEDLL_ADD
m_iDirection = 1; // force positive Y addition
KickBack(UTIL_SharedRandomFloat(m_pPlayer->random_seed + 4, 0.75, 1.75) + m_pPlayer->pev->punchangle.x * 0.25f,
UTIL_SharedRandomFloat(m_pPlayer->random_seed + 5, -0.75, 0.75),
0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomFloat(m_pPlayer->random_seed + 4, 0.75, 1.75) + m_pPlayer->pev->punchangle.x * 0.25f;
m_pPlayer->pev->punchangle.y += UTIL_SharedRandomFloat(m_pPlayer->random_seed + 5, -0.75, 0.75);
#endif
}

void CG3SG1::Reload()
Expand Down
3 changes: 3 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_glock18.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ void CGLOCK18::GLOCK18Fire(float flSpread, float flCycleTime, BOOL bFireBurst)
m_flGlock18Shoot = gpGlobals->time + 0.1f;
}

#ifdef REGAMEDLL_ADD
KickBack(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0); // dummy call, API useful
#endif
ResetPlayerShieldAnim();
}

Expand Down
7 changes: 7 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_m3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,17 @@ void CM3::PrimaryAttack()

m_fInSpecialReload = 0;

#ifdef REGAMEDLL_ADD
if (m_pPlayer->pev->flags & FL_ONGROUND)
KickBack(UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 4, 6), 0.0, 0.0, 0.0, 0.0, 0.0, 0);
else
KickBack(UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 8, 11), 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
if (m_pPlayer->pev->flags & FL_ONGROUND)
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 4, 6);
else
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 8, 11);
#endif

m_pPlayer->m_flEjectBrass = gpGlobals->time + 0.45f;
}
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_p228.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ void CP228::P228Fire(float flSpread, float flCycleTime, BOOL fUseSemi)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2;
#endif
ResetPlayerShieldAnim();
}

Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_scout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ void CSCOUT::SCOUTFire(float flSpread, float flCycleTime, BOOL fUseAutoAim)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.8f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2.0f;
#endif
}

void CSCOUT::Reload()
Expand Down
7 changes: 7 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_sg550.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,15 @@ void CSG550::SG550Fire(float flSpread, float flCycleTime, BOOL fUseAutoAim)

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.8f;

#ifdef REGAMEDLL_ADD
m_iDirection = 1; // force positive Y addition
KickBack(UTIL_SharedRandomFloat(m_pPlayer->random_seed + 4, 0.75, 1.75) + m_pPlayer->pev->punchangle.x * 0.25,
UTIL_SharedRandomFloat(m_pPlayer->random_seed + 5, -0.75, 0.75),
0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomFloat(m_pPlayer->random_seed + 4, 0.75, 1.25) + m_pPlayer->pev->punchangle.x * 0.25;
m_pPlayer->pev->punchangle.y += UTIL_SharedRandomFloat(m_pPlayer->random_seed + 5, -0.75, 0.75);
#endif
}

void CSG550::Reload()
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_usp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ void CUSP::USPFire(float flSpread, float flCycleTime, BOOL fUseSemi)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2.0f;
#endif
ResetPlayerShieldAnim();
}

Expand Down
7 changes: 7 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_xm1014.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,17 @@ void CXM1014::PrimaryAttack()

m_fInSpecialReload = 0;

#ifdef REGAMEDLL_ADD
if (m_pPlayer->pev->flags & FL_ONGROUND)
KickBack(UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 3, 5), 0.0, 0.0, 0.0, 0.0, 0.0, 0);
else
KickBack(UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 7, 10), 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
if (m_pPlayer->pev->flags & FL_ONGROUND)
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 3, 5);
else
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 7, 10);
#endif
}

void CXM1014::Reload()
Expand Down
Loading

0 comments on commit 5e03f01

Please sign in to comment.