Skip to content

Commit

Permalink
Fix #3037: Add ResetPedVoice function - Bug fix (#3129)
Browse files Browse the repository at this point in the history
The function ResetPedVoice never worked (it was added in PR #3037) but now it does.
  • Loading branch information
TracerDS committed May 25, 2024
1 parent 77ab3e6 commit 3d8bd50
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 79 deletions.
18 changes: 6 additions & 12 deletions Client/game_sa/CPedSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,8 @@ extern CGameSA* pGame;

int g_bOnlyUpdateRotations = false;

CPedSA::CPedSA() : m_pPedIntelligence(NULL), m_pPedInterface(NULL), m_pPedSound(NULL),
m_pDefaultPedSound(NULL), m_iCustomMoveAnim(0)
{
MemSetFast(m_pWeapons, 0, sizeof(CWeaponSA*) * WEAPONSLOT_MAX);
}

CPedSA::CPedSA(CPedSAInterface* pPedInterface) : m_pPedIntelligence(NULL), m_pPedInterface(pPedInterface),
m_pPedSound(NULL), m_pDefaultPedSound(NULL), m_iCustomMoveAnim(0)
CPedSA::CPedSA(CPedSAInterface* pPedInterface) noexcept
: m_pPedInterface(pPedInterface)
{
MemSetFast(m_pWeapons, 0, sizeof(CWeaponSA*) * WEAPONSLOT_MAX);
}
Expand All @@ -50,8 +44,6 @@ CPedSA::~CPedSA()
delete m_pPedIntelligence;
if (m_pPedSound)
delete m_pPedSound;
if (m_pDefaultPedSound)
delete m_pDefaultPedSound;

for (int i = 0; i < WEAPONSLOT_MAX; i++)
{
Expand Down Expand Up @@ -94,7 +86,9 @@ void CPedSA::Init()
CPedIntelligenceSAInterface* m_pPedIntelligenceInterface = (CPedIntelligenceSAInterface*)(dwPedIntelligence);
m_pPedIntelligence = new CPedIntelligenceSA(m_pPedIntelligenceInterface, this);
m_pPedSound = new CPedSoundSA(&pedInterface->pedSound);
m_pDefaultPedSound = new CPedSoundSA(&pedInterface->pedSound);

m_sDefaultVoiceType = m_pPedSound->GetVoiceTypeID();
m_sDefaultVoiceID = m_pPedSound->GetVoiceID();

for (int i = 0; i < WEAPONSLOT_MAX; i++)
m_pWeapons[i] = new CWeaponSA(&(pedInterface->Weapons[i]), this, (eWeaponSlot)i);
Expand Down Expand Up @@ -953,7 +947,7 @@ void CPedSA::SetVoice(const char* szVoiceType, const char* szVoice)

void CPedSA::ResetVoice()
{
SetVoice(m_pDefaultPedSound->GetVoiceTypeID(), m_pDefaultPedSound->GetVoiceID());
SetVoice(m_sDefaultVoiceType, m_sDefaultVoiceID);
}

// GetCurrentWeaponStat will only work if the game ped context is currently set to this ped
Expand Down
19 changes: 10 additions & 9 deletions Client/game_sa/CPedSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,23 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
friend class CPoolsSA;

private:
CWeaponSA* m_pWeapons[WEAPONSLOT_MAX];
CPedIKSA* m_pPedIK;
CPedIntelligenceSA* m_pPedIntelligence;
CPedSAInterface* m_pPedInterface;
CPedSoundSA* m_pPedSound;
CPedSoundSA* m_pDefaultPedSound;
CWeaponSA* m_pWeapons[WEAPONSLOT_MAX]{};
CPedIKSA* m_pPedIK{};
CPedIntelligenceSA* m_pPedIntelligence{};
CPedSAInterface* m_pPedInterface{};
CPedSoundSA* m_pPedSound{};

short m_sDefaultVoiceType;
short m_sDefaultVoiceID;

DWORD m_dwType;
unsigned char m_ucOccupiedSeat;

protected:
int m_iCustomMoveAnim;
int m_iCustomMoveAnim{ 0 };

public:
CPedSA();
CPedSA(CPedSAInterface* pedInterface);
CPedSA(CPedSAInterface* pedInterface = nullptr) noexcept;
~CPedSA();

void SetInterface(CEntitySAInterface* intInterface);
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientBuilding.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CClientBuilding : public CClientEntity
uint16_t GetModel() const noexcept { return m_usModelId; };
void SetModel(uint16_t ulModel);

eClientEntityType GetType() const noexcept { return CCLIENTBUILDING; }
eClientEntityType GetType() const { return CCLIENTBUILDING; }

void Create();
void Destroy();
Expand Down
133 changes: 76 additions & 57 deletions Client/mods/deathmatch/logic/CClientPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,24 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
CClientPed(CClientManager* pManager, unsigned long ulModelID, ElementID ID);
~CClientPed();

void Unlink(){};
void Unlink() {};

virtual eClientEntityType GetType() const { return CCLIENTPED; }

CPlayerPed* GetGamePlayer() { return m_pPlayerPed; }
CEntity* GetGameEntity() { return m_pPlayerPed; }
const CEntity* GetGameEntity() const { return m_pPlayerPed; }
CPlayerPed* GetGamePlayer() noexcept { return m_pPlayerPed; }
CEntity* GetGameEntity() noexcept { return m_pPlayerPed; }
const CEntity* GetGameEntity() const noexcept { return m_pPlayerPed; }

bool IsLocalPlayer() { return m_bIsLocalPlayer; }
bool IsSyncing() { return m_bIsSyncing; }
bool IsLocalPlayer() const noexcept { return m_bIsLocalPlayer; }
bool IsSyncing() const noexcept { return m_bIsSyncing; }
void SetSyncing(bool bIsSyncing);

bool GetMatrix(CMatrix& Matrix) const;
bool SetMatrix(const CMatrix& Matrix);
virtual CSphere GetWorldBoundingSphere();

void GetPosition(CVector& vecPosition) const;
void SetPosition(const CVector& vecPosition) { SetPosition(vecPosition, true, true); }
void SetPosition(const CVector& vecPosition) noexcept { SetPosition(vecPosition, true, true); }
void SetPosition(const CVector& vecPosition, bool bResetInterpolation, bool bAllowGroundLoadFreeze = true);

void SetInterior(unsigned char ucInterior);
Expand Down Expand Up @@ -231,19 +231,24 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule

void SetTargetTarget(unsigned long ulDelay, const CVector& vecSource, const CVector& vecTarget);

int GetVehicleInOutState() { return m_iVehicleInOutState; };
void SetVehicleInOutState(int iState) { m_iVehicleInOutState = iState; };
int GetVehicleInOutState() const noexcept { return m_iVehicleInOutState; };
void SetVehicleInOutState(int iState) noexcept { m_iVehicleInOutState = iState; };

unsigned long GetModel() { return m_ulModel; };
unsigned long GetModel() const noexcept { return m_ulModel; };
bool SetModel(unsigned long ulModel, bool bTemp = false);

bool GetCanBeKnockedOffBike();
void SetCanBeKnockedOffBike(bool bCanBeKnockedOffBike);

bool IsInVehicle() { return GetOccupiedVehicle() != NULL; };
CClientVehicle* GetOccupiedVehicle() { return m_pOccupiedVehicle; };
unsigned int GetOccupiedVehicleSeat() { return m_uiOccupiedVehicleSeat; };
CClientVehicle* GetOccupyingVehicle() { return m_pOccupyingVehicle; };
bool IsInVehicle() const noexcept { return GetOccupiedVehicle() != NULL; };

CClientVehicle* GetOccupiedVehicle() noexcept { return m_pOccupiedVehicle; };
const CClientVehicle* GetOccupiedVehicle() const noexcept { return m_pOccupiedVehicle; };

unsigned int GetOccupiedVehicleSeat() const noexcept { return m_uiOccupiedVehicleSeat; };

CClientVehicle* GetOccupyingVehicle() noexcept { return m_pOccupyingVehicle; };
const CClientVehicle* GetOccupyingVehicle() const noexcept { return m_pOccupyingVehicle; };

CClientVehicle* GetRealOccupiedVehicle();
CClientVehicle* GetClosestEnterableVehicle(bool bGetPositionFromClosestDoor, bool bCheckDriverDoor, bool bCheckPassengerDoors,
Expand Down Expand Up @@ -274,21 +279,21 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule

void LockHealth(float fHealth);
void LockArmor(float fArmor);
void UnlockHealth() { m_bHealthLocked = false; };
void UnlockArmor() { m_bArmorLocked = false; };
bool IsHealthLocked() const { return m_bHealthLocked; };
bool IsArmorLocked() const { return m_bArmorLocked; };
void UnlockHealth() noexcept { m_bHealthLocked = false; };
void UnlockArmor() noexcept { m_bArmorLocked = false; };
bool IsHealthLocked() const noexcept { return m_bHealthLocked; };
bool IsArmorLocked() const noexcept { return m_bArmorLocked; };

bool IsDying();
bool IsDead();
void SetIsDead(bool bDead) { m_bDead = bDead; };
void SetIsDead(bool bDead) noexcept { m_bDead = bDead; };
void Kill(eWeaponType weaponType, unsigned char ucBodypart, bool bStealth = false, bool bSetDirectlyDead = false, AssocGroupId animGroup = 0,
AnimationId animID = 15);
void StealthKill(CClientPed* pPed);
void BeHit(CClientPed* pClientPedAttacker, ePedPieceTypes hitBodyPart, int hitBodySide, int weaponId);

int GetRespawnState() { return m_pRespawnState; };
void SetRespawnState(int iRespawnState) { m_pRespawnState = iRespawnState; };
int GetRespawnState() const noexcept { return m_pRespawnState; };
void SetRespawnState(int iRespawnState) noexcept { m_pRespawnState = iRespawnState; };

CWeapon* GiveWeapon(eWeaponType weaponType, unsigned int uiAmmo, bool bSetAsCurrent = false);
bool SetCurrentWeaponSlot(eWeaponSlot weaponSlot);
Expand Down Expand Up @@ -328,9 +333,9 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
}
};
CVector GetAim() const;
const CVector& GetAimSource() { return m_shotSyncData->m_vecShotOrigin; };
const CVector& GetAimTarget() { return m_shotSyncData->m_vecShotTarget; };
eVehicleAimDirection GetVehicleAimAnim() { return m_shotSyncData->m_cInVehicleAimDirection; };
const CVector& GetAimSource() const noexcept { return m_shotSyncData->m_vecShotOrigin; };
const CVector& GetAimTarget() const noexcept { return m_shotSyncData->m_vecShotTarget; };
eVehicleAimDirection GetVehicleAimAnim() const noexcept { return m_shotSyncData->m_cInVehicleAimDirection; };
void SetAim(float fArmDirectionX, float fArmDirectionY, eVehicleAimDirection cInVehicleAimAnim);
void SetAimInterpolated(unsigned long ulDelay, float fArmDirectionX, float fArmDirectionY, bool bAkimboAimUp, eVehicleAimDirection cInVehicleAimAnim);
void SetAimingData(unsigned long ulDelay, const CVector& vecTargetPosition, float fArmDirectionX, float fArmDirectionY,
Expand All @@ -356,7 +361,8 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
float GetStat(unsigned short usStat);
void ResetStats();

CClientPlayerClothes* GetClothes() { return m_pClothes; }
CClientPlayerClothes* GetClothes() noexcept { return m_pClothes; }
const CClientPlayerClothes* GetClothes() const noexcept { return m_pClothes; }

// This is kinda hacky, should be private but something depends on this. Should depend on some
// streamer func. Perhaps use SetNeverStreamOut, but need something to reset that.
Expand All @@ -375,13 +381,14 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
bool IsOnGround();

bool IsClimbing();
bool IsRadioOn() { return m_bRadioOn; };
bool IsRadioOn() const noexcept { return m_bRadioOn; };
void NextRadioChannel();
void PreviousRadioChannel();
bool SetCurrentRadioChannel(unsigned char ucChannel);
unsigned char GetCurrentRadioChannel() { return m_ucRadioChannel; };
unsigned char GetCurrentRadioChannel() const noexcept { return m_ucRadioChannel; };

CTaskManager* GetTaskManager() { return m_pTaskManager; }
CTaskManager* GetTaskManager() noexcept { return m_pTaskManager; }
const CTaskManager* GetTaskManager() const noexcept { return m_pTaskManager; }

bool GetShotData(CVector* pvecOrigin, CVector* pvecTarget = NULL, CVector* pvecGunMuzzle = NULL, CVector* pvecFireOffset = NULL, float* fAimX = NULL,
float* fAimY = NULL);
Expand All @@ -399,10 +406,14 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
std::list<CClientProjectile*>::iterator ProjectilesEnd() { return m_Projectiles.end(); }
unsigned int CountProjectiles(eWeaponType weaponType = WEAPONTYPE_UNARMED);

std::list<CClientProjectile*>& GetProjectiles() noexcept { return m_Projectiles; }
const std::list<CClientProjectile*>& GetProjectiles() const noexcept { return m_Projectiles; }

void RemoveAllProjectiles();
void DestroySatchelCharges(bool bBlow = true, bool bDestroy = true);

CRemoteDataStorage* GetRemoteData() { return m_remoteDataStorage; }
CRemoteDataStorage* GetRemoteData() noexcept { return m_remoteDataStorage; }
const CRemoteDataStorage* GetRemoteData() const noexcept { return m_remoteDataStorage; }

bool IsEnteringVehicle();
bool IsLeavingVehicle();
Expand All @@ -416,11 +427,12 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule

float GetDistanceFromCentreOfMassToBaseOfModel();

unsigned char GetAlpha() { return m_ucAlpha; }
unsigned char GetAlpha() const noexcept { return m_ucAlpha; }
void SetAlpha(unsigned char ucAlpha);

bool HasTargetPosition() { return (m_interp.pos.ulFinishTime != 0); }
CClientEntity* GetTargetOriginSource() { return m_interp.pTargetOriginSource; }
bool HasTargetPosition() const noexcept { return m_interp.pos.ulFinishTime != 0; }
CClientEntity* GetTargetOriginSource() noexcept { return m_interp.pTargetOriginSource; }
const CClientEntity* GetTargetOriginSource() const noexcept { return m_interp.pTargetOriginSource; }
void GetTargetPosition(CVector& vecPosition);
void SetTargetPosition(const CVector& vecPosition, unsigned long ulDelay, CClientEntity* pTargetOriginSource = NULL);
void RemoveTargetPosition();
Expand All @@ -430,8 +442,9 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
CClientEntity* GetTargetedEntity();
CClientPed* GetTargetedPed();

CClientEntity* GetCurrentContactEntity() { return m_pCurrentContactEntity; }
void SetCurrentContactEntity(CClientEntity* pEntity) { m_pCurrentContactEntity = pEntity; }
CClientEntity* GetCurrentContactEntity() noexcept { return m_pCurrentContactEntity; }
const CClientEntity* GetCurrentContactEntity() const noexcept { return m_pCurrentContactEntity; }
void SetCurrentContactEntity(CClientEntity* pEntity) noexcept { m_pCurrentContactEntity = pEntity; }

bool IsSunbathing();
void SetSunbathing(bool bSunbathing, bool bStartStanding = true);
Expand All @@ -453,22 +466,22 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
bool bOffsetPed = false, bool bHoldLastFrame = false);
void KillAnimation();
std::unique_ptr<CAnimBlock> GetAnimationBlock();
const SAnimationCache& GetAnimationCache() { return m_AnimationCache; }
const SAnimationCache& GetAnimationCache() const noexcept { return m_AnimationCache; }

bool IsUsingGun();

bool IsHeadless() { return m_bHeadless; }
bool IsHeadless() const noexcept { return m_bHeadless; }
void SetHeadless(bool bHeadless);

bool IsFrozen() const { return m_bFrozen; }
bool IsFrozen() const noexcept { return m_bFrozen; }
void SetFrozen(bool bFrozen);
bool IsFrozenWaitingForGroundToLoad() const;
void SetFrozenWaitingForGroundToLoad(bool bFrozen);

bool IsFootBloodEnabled();
void SetFootBloodEnabled(bool bHasFootBlood);

bool IsBleeding() const { return m_bBleeding; };
bool IsBleeding() const noexcept { return m_bBleeding; };
void SetBleeding(bool bBleeding);

bool IsOnFire();
Expand Down Expand Up @@ -502,27 +515,33 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
std::unique_ptr<CAnimBlendAssociation> GetFirstAnimation();

void DereferenceCustomAnimationBlock() { m_pCustomAnimationIFP = nullptr; }
std::shared_ptr<CClientIFP> GetCustomAnimationIFP() { return m_pCustomAnimationIFP; }
bool IsCustomAnimationPlaying() { return ((m_bRequestedAnimation || m_AnimationCache.bLoop) && m_pAnimationBlock && m_bisCurrentAnimationCustom); }
void SetCustomAnimationUntriggerable()
std::shared_ptr<CClientIFP> GetCustomAnimationIFP() const noexcept { return m_pCustomAnimationIFP; }
bool IsCustomAnimationPlaying() noexcept
{
return (m_bRequestedAnimation || m_AnimationCache.bLoop)
&& m_pAnimationBlock && m_bisCurrentAnimationCustom;
}
void SetCustomAnimationUntriggerable() noexcept
{
m_bRequestedAnimation = false;
m_AnimationCache.bLoop = false;
}
bool IsNextAnimationCustom() { return m_bisNextAnimationCustom; }
bool IsNextAnimationCustom() const noexcept { return m_bisNextAnimationCustom; }
void SetNextAnimationCustom(const std::shared_ptr<CClientIFP>& pIFP, const SString& strAnimationName);
void SetCurrentAnimationCustom(bool bCustom) { m_bisCurrentAnimationCustom = bCustom; }
bool IsCurrentAnimationCustom() { return m_bisCurrentAnimationCustom; }
CIFPAnimations* GetIFPAnimationsPointer() { return m_pIFPAnimations; }
void SetIFPAnimationsPointer(CIFPAnimations* pIFPAnimations) { m_pIFPAnimations = pIFPAnimations; }
void SetCurrentAnimationCustom(bool bCustom) noexcept { m_bisCurrentAnimationCustom = bCustom; }
bool IsCurrentAnimationCustom() const noexcept { return m_bisCurrentAnimationCustom; }
CIFPAnimations* GetIFPAnimationsPointer() noexcept { return m_pIFPAnimations; }
const CIFPAnimations* GetIFPAnimationsPointer() const noexcept { return m_pIFPAnimations; }

void SetIFPAnimationsPointer(CIFPAnimations* pIFPAnimations) noexcept { m_pIFPAnimations = pIFPAnimations; }

// This will indicate that we have played custom animation, so next animation can be internal GTA animation
// You must call this function after playing a custom animation
void SetNextAnimationNormal() { m_bisNextAnimationCustom = false; }
const SString& GetNextAnimationCustomBlockName() { return m_strCustomIFPBlockName; }
const SString& GetNextAnimationCustomName() { return m_strCustomIFPAnimationName; }
const unsigned int& GetCustomAnimationBlockNameHash() { return m_u32CustomBlockNameHash; }
const unsigned int& GetCustomAnimationNameHash() { return m_u32CustomAnimationNameHash; }
void SetNextAnimationNormal() noexcept { m_bisNextAnimationCustom = false; }
const SString& GetNextAnimationCustomBlockName() const noexcept { return m_strCustomIFPBlockName; }
const SString& GetNextAnimationCustomName() const noexcept { return m_strCustomIFPAnimationName; }
const unsigned int& GetCustomAnimationBlockNameHash() const noexcept { return m_u32CustomBlockNameHash; }
const unsigned int& GetCustomAnimationNameHash() const noexcept { return m_u32CustomAnimationNameHash; }

void ReplaceAnimation(std::unique_ptr<CAnimBlendHierarchy>& pInternalAnimHierarchy, const std::shared_ptr<CClientIFP>& pIFP,
CAnimBlendHierarchySAInterface* pCustomAnimHierarchy);
Expand Down Expand Up @@ -579,13 +598,13 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule

void Respawn(CVector* pvecPosition = NULL, bool bRestoreState = false, bool bCameraCut = false);

void SetTaskToBeRestoredOnAnimEnd(bool bSetOnEnd) { m_bTaskToBeRestoredOnAnimEnd = bSetOnEnd; }
bool IsTaskToBeRestoredOnAnimEnd() { return m_bTaskToBeRestoredOnAnimEnd; }
void SetTaskTypeToBeRestoredOnAnimEnd(eTaskType taskType) { m_eTaskTypeToBeRestoredOnAnimEnd = taskType; }
eTaskType GetTaskTypeToBeRestoredOnAnimEnd() { return m_eTaskTypeToBeRestoredOnAnimEnd; }
void SetTaskToBeRestoredOnAnimEnd(bool bSetOnEnd) noexcept { m_bTaskToBeRestoredOnAnimEnd = bSetOnEnd; }
bool IsTaskToBeRestoredOnAnimEnd() const noexcept { return m_bTaskToBeRestoredOnAnimEnd; }
void SetTaskTypeToBeRestoredOnAnimEnd(eTaskType taskType) noexcept { m_eTaskTypeToBeRestoredOnAnimEnd = taskType; }
eTaskType GetTaskTypeToBeRestoredOnAnimEnd() const noexcept { return m_eTaskTypeToBeRestoredOnAnimEnd; }

bool IsWarpInToVehicleRequired() { return m_bWarpInToVehicleRequired; }
void SetWarpInToVehicleRequired(bool warp) { m_bWarpInToVehicleRequired = warp; }
bool IsWarpInToVehicleRequired() const noexcept { return m_bWarpInToVehicleRequired; }
void SetWarpInToVehicleRequired(bool warp) noexcept { m_bWarpInToVehicleRequired = warp; }

void NotifyCreate();
void NotifyDestroy();
Expand Down

0 comments on commit 3d8bd50

Please sign in to comment.