Skip to content

Commit 4007710

Browse files
committed
Cleanup
1 parent 8af5717 commit 4007710

File tree

7 files changed

+37
-63
lines changed

7 files changed

+37
-63
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,6 +3428,9 @@ void CClientGame::Event_OnIngame()
34283428
pHud->SetComponentVisible(HUD_VITAL_STATS, false);
34293429
pHud->SetComponentVisible(HUD_AREA_NAME, false);
34303430

3431+
// Reset properties
3432+
CLuaPlayerDefs::ResetPlayerHudComponentProperty(HUD_ALL, eHudComponentProperty::ALL_PROPERTIES);
3433+
34313434
g_pMultiplayer->DeleteAndDisableGangTags();
34323435

34333436
g_pGame->GetBuildingRemoval()->ClearRemovedBuildingLists();
@@ -3528,9 +3531,9 @@ void CClientGame::StaticDrawRadarAreasHandler()
35283531
g_pClientGame->DrawRadarAreasHandler();
35293532
}
35303533

3531-
bool CClientGame::StaticDamageHandler(CPed* pDamagePed, CEventDamage* pEvent, CPedSAInterface*& pedInterface)
3534+
bool CClientGame::StaticDamageHandler(CPed* pDamagePed, CEventDamage* pEvent)
35323535
{
3533-
return g_pClientGame->DamageHandler(pDamagePed, pEvent, pedInterface);
3536+
return g_pClientGame->DamageHandler(pDamagePed, pEvent);
35343537
}
35353538

35363539
void CClientGame::StaticDeathHandler(CPed* pKilledPed, unsigned char ucDeathReason, unsigned char ucBodyPart)
@@ -4183,7 +4186,7 @@ void GetDeathAnim(CClientPed* pDamagedPed, CEventDamage* pEvent, AssocGroupId& o
41834186
// returning false ??
41844187
// returning true ??
41854188
//
4186-
bool CClientGame::DamageHandler(CPed* pDamagePed, CEventDamage* pEvent, CPedSAInterface*& pedInterface)
4189+
bool CClientGame::DamageHandler(CPed* pDamagePed, CEventDamage* pEvent)
41874190
{
41884191
// CEventDamage::AffectsPed: This is/can be called more than once for each bit of damage (and may not actually take any more health (even if we return
41894192
// true))
@@ -4220,9 +4223,6 @@ bool CClientGame::DamageHandler(CPed* pDamagePed, CEventDamage* pEvent, CPedSAIn
42204223
if (pPedClientEntity->pClientEntity && pPedClientEntity->pClientEntity->GetGameEntity() != nullptr)
42214224
{
42224225
pDamagedPed = reinterpret_cast<CClientPed*>(pPedClientEntity->pClientEntity);
4223-
4224-
// Update the damaged ped, because it might have been invalidated in onClientPedDamage/onClientPlayerDamage using setElementHealth
4225-
pedInterface = reinterpret_cast<CPedSAInterface*>(pDamagedPed->GetGameEntity()->GetInterface());
42264226
}
42274227
}
42284228
}
@@ -4359,8 +4359,8 @@ bool CClientGame::DamageHandler(CPed* pDamagePed, CEventDamage* pEvent, CPedSAIn
43594359
bool CClientGame::ApplyPedDamageFromGame(eWeaponType weaponUsed, float fDamage, uchar hitZone, CClientPed* pDamagedPed, CClientEntity* pInflictingEntity,
43604360
CEventDamage* pEvent)
43614361
{
4362+
float fPreviousHealth = pDamagedPed->m_fHealth;
43624363
float fCurrentHealth = pDamagedPed->GetGamePlayer()->GetHealth();
4363-
float fPreviousHealth = fCurrentHealth + fDamage;
43644364
float fPreviousArmor = pDamagedPed->m_fArmor;
43654365
float fCurrentArmor = pDamagedPed->GetGamePlayer()->GetArmor();
43664366

@@ -4404,12 +4404,9 @@ bool CClientGame::ApplyPedDamageFromGame(eWeaponType weaponUsed, float fDamage,
44044404
return false;
44054405
}
44064406

4407-
if (pDamagedPed->IsLocalPlayer())
4408-
{
4409-
// Reget values in case they have been changed during onClientPlayerDamage event (Avoid AC#1 kick)
4410-
fCurrentHealth = pDamagedPed->GetGamePlayer()->GetHealth();
4411-
fCurrentArmor = pDamagedPed->GetGamePlayer()->GetArmor();
4412-
}
4407+
// Reget values in case they have been changed during onClientPlayerDamage/onClientPedDamage event (Avoid AC#1 kick)
4408+
fCurrentHealth = pDamagedPed->GetGamePlayer()->GetHealth();
4409+
fCurrentArmor = pDamagedPed->GetGamePlayer()->GetArmor();
44134410

44144411
bool bIsBeingShotWhilstAiming = (weaponUsed >= WEAPONTYPE_PISTOL && weaponUsed <= WEAPONTYPE_MINIGUN && pDamagedPed->IsUsingGun());
44154412
bool bOldBehaviour = !IsGlitchEnabled(GLITCH_HITANIM);

Client/mods/deathmatch/logic/CClientGame.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ class CClientGame
509509

510510
void SetupGlobalLuaEvents();
511511

512-
static bool StaticDamageHandler(CPed* pDamagePed, CEventDamage* pEvent, CPedSAInterface*& pedInterface);
512+
static bool StaticDamageHandler(CPed* pDamagePed, CEventDamage* pEvent);
513513
static void StaticDeathHandler(CPed* pKilledPed, unsigned char ucDeathReason, unsigned char ucBodyPart);
514514
static void StaticFireHandler(CFire* pFire);
515515
static bool StaticBreakTowLinkHandler(CVehicle* pTowedVehicle);
@@ -560,7 +560,7 @@ class CClientGame
560560
static AnimationId StaticDrivebyAnimationHandler(AnimationId animGroup, AssocGroupId animId);
561561
static void StaticAudioZoneRadioSwitchHandler(DWORD dwStationID);
562562

563-
bool DamageHandler(CPed* pDamagePed, CEventDamage* pEvent, CPedSAInterface*& pedInterface);
563+
bool DamageHandler(CPed* pDamagePed, CEventDamage* pEvent);
564564
void DeathHandler(CPed* pKilledPed, unsigned char ucDeathReason, unsigned char ucBodyPart);
565565
void FireHandler(CFire* pFire);
566566
bool BreakTowLinkHandler(CVehicle* pTowedVehicle);

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,10 @@ void CClientPed::StreamedInPulse(bool bDoStandardPulses)
27052705
return;
27062706
}
27072707

2708+
// Re-create ped
2709+
if (m_shouldRecreate)
2710+
ReCreateGameEntity();
2711+
27082712
// Grab some vars here, saves getting them twice
27092713
CClientVehicle* pVehicle = GetOccupiedVehicle();
27102714

@@ -3974,11 +3978,7 @@ void CClientPed::_ChangeModel()
39743978
{
39753979
// ChrML: Changing the skin in certain cases causes player sliding. So we recreate instead.
39763980

3977-
// Kill the old player
3978-
_DestroyModel();
3979-
3980-
// Create the new with the new skin
3981-
_CreateModel();
3981+
m_shouldRecreate = true;
39823982
}
39833983

39843984
// ReAttach satchels
@@ -4012,11 +4012,7 @@ void CClientPed::ReCreateModel()
40124012
m_pLoadedModelInfo->ModelAddRef(BLOCKING, "CClientPed::ReCreateModel");
40134013
}
40144014

4015-
// Destroy the old model
4016-
_DestroyModel();
4017-
4018-
// Create the new model
4019-
_CreateModel();
4015+
m_shouldRecreate = true;
40204016

40214017
// Remove the reference we temporarily added again
40224018
if (bSameModel)
@@ -4026,6 +4022,20 @@ void CClientPed::ReCreateModel()
40264022
}
40274023
}
40284024

4025+
void CClientPed::ReCreateGameEntity()
4026+
{
4027+
if (!m_shouldRecreate)
4028+
return;
4029+
4030+
// Destroy current game entity
4031+
_DestroyModel();
4032+
4033+
// Create the new game entity
4034+
_CreateModel();
4035+
4036+
m_shouldRecreate = false;
4037+
}
4038+
40294039
void CClientPed::ModelRequestCallback(CModelInfo* pModelInfo)
40304040
{
40314041
// If we have a player loaded

Client/mods/deathmatch/logic/CClientPed.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
566566

567567
// Used to destroy the current game ped and create a new one in the same state.
568568
void ReCreateModel();
569+
void ReCreateGameEntity();
569570

570571
void _CreateModel();
571572
void _CreateLocalModel();
@@ -725,6 +726,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
725726
bool m_bPendingRebuildPlayer;
726727
uint m_uiFrameLastRebuildPlayer;
727728
bool m_bIsSyncing;
729+
bool m_shouldRecreate{false};
728730

729731
bool m_bBulletImpactData;
730732
CClientEntityPtr m_pBulletImpactEntity;

Client/multiplayer_sa/CMultiplayerSA_Rendering.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -739,37 +739,6 @@ void _declspec(naked) HOOK_CRenderer_EverythingBarRoads()
739739
}
740740
}
741741

742-
743-
//////////////////////////////////////////////////////////////////////////////////////////
744-
//
745-
// CRenderer::RenderEverythingBarRoads
746-
//
747-
// m_pRwObject can be nullptr and crash
748-
// Fix for a crash caused by frequent re-creation of entities.
749-
//
750-
//////////////////////////////////////////////////////////////////////////////////////////
751-
#define HOOKPOS_CRender_EverythingBarRoads_Loop 0x553B07
752-
#define HOOKSIZE_CRender_EverythingBarRoads_Loop 5
753-
static constexpr std::uintptr_t CONTINUE_CRender_EverythingBarRoads_Loop = 0x553C5A;
754-
static constexpr std::uintptr_t RETURN_CRender_EverythingBarRoads_Loop = 0x553B0C;
755-
static void _declspec(naked) HOOK_CRender_EverythingBarRoads_Loop()
756-
{
757-
_asm
758-
{
759-
// check entity->object.m_pRwObject
760-
mov ecx, [esi+18h]
761-
test ecx, ecx
762-
jz skip
763-
764-
mov al, [esi+36h]
765-
and al, 7
766-
jmp RETURN_CRender_EverythingBarRoads_Loop
767-
768-
skip:
769-
jmp CONTINUE_CRender_EverythingBarRoads_Loop
770-
}
771-
}
772-
773742
//////////////////////////////////////////////////////////////////////////////////////////
774743
//
775744
// CMultiplayerSA::InitHooks_Rendering
@@ -794,5 +763,4 @@ void CMultiplayerSA::InitHooks_Rendering()
794763
EZHookInstallChecked(RwCameraSetNearClipPlane);
795764
EZHookInstall(RenderEffects_HeliLight);
796765
EZHookInstall(CRenderer_EverythingBarRoads);
797-
EZHookInstall(CRender_EverythingBarRoads_Loop);
798766
}

Client/multiplayer_sa/multiplayer_shotsync.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ void _declspec(naked) HOOK_CWeapon__Fire_Sniper()
760760
}
761761
}
762762

763-
bool ProcessDamageEvent(CEventDamageSAInterface* event, CPedSAInterface*& affectsPed)
763+
bool ProcessDamageEvent(CEventDamageSAInterface* event, CPedSAInterface* affectsPed)
764764
{
765765
if (m_pDamageHandler && event)
766766
{
@@ -775,7 +775,7 @@ bool ProcessDamageEvent(CEventDamageSAInterface* event, CPedSAInterface*& affect
775775
CEventDamage* pEvent = pGameInterface->GetEventList()->GetEventDamage(event);
776776
pEvent->SetDamageReason(g_GenerateDamageEventReason);
777777
// Call the event
778-
bool bReturn = m_pDamageHandler(pPed, pEvent, affectsPed);
778+
bool bReturn = m_pDamageHandler(pPed, pEvent);
779779
// Destroy the CEventDamageSA (so we dont get a leak)
780780
pEvent->Destroy();
781781
// Finally, return
@@ -819,9 +819,6 @@ void _declspec(naked) HOOK_CEventDamage__AffectsPed()
819819
push esi
820820
mov esi, ecx
821821

822-
mov ecx, affectsPed
823-
mov [esp+14h], ecx
824-
825822
mov ecx, HOOKPOS_CEventDamage__AffectsPed
826823
add ecx, 6
827824
jmp ecx

Client/sdk/multiplayer/CMultiplayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ typedef bool(PreWeaponFireHandler)(class CPlayerPed* pPlayer, bool bStopIfUsingB
8383
typedef void(PostWeaponFireHandler)();
8484
typedef void(BulletImpactHandler)(class CPed* pInitiator, class CEntity* pVictim, const CVector* pvecStartPosition, const CVector* pvecEndPosition);
8585
typedef void(BulletFireHandler)(class CPed* pInitiator, const CVector* pvecStartPosition, const CVector* pvecEndPosition);
86-
typedef bool(DamageHandler)(class CPed* pDamagePed, class CEventDamage* pEvent, class CPedSAInterface*& pedInterface);
86+
typedef bool(DamageHandler)(class CPed* pDamagePed, class CEventDamage* pEvent);
8787
typedef void(DeathHandler)(class CPed* pKilledPed, unsigned char ucDeathReason, unsigned char ucBodyPart);
8888
typedef void(FireHandler)(class CFire* pFire);
8989
typedef bool(ProjectileStopHandler)(class CEntity* owner, enum eWeaponType weaponType, class CVector* origin, float fForce, class CVector* target,

0 commit comments

Comments
 (0)