Skip to content

Commit

Permalink
Fix nullptr check before return in CAnimMangerSA methods
Browse files Browse the repository at this point in the history
- This is a part of rewriting CAnimMangerSA methods, dynamic memory allocation was used along with raw pointers, so I switched to std::unique_ptr which requires us to return nullptr for the method if the interface is NULL after calling the function from memory.
- Applied Source Formatting
- Removed void for empty parameters from CAnimBlendAssociation and CAnimBlendStaticAssociation functions
- Deleted CAnimManagerSA::GetAnimBlendAssociation2
  • Loading branch information
codenulls committed Jul 6, 2018
1 parent 8512aa6 commit def10ef
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
13 changes: 6 additions & 7 deletions Client/core/CKeyBinds.cpp
Expand Up @@ -776,9 +776,8 @@ bool CKeyBinds::SetCommandActive(const char* szKey, const char* szCommand, bool
if ((*iter)->GetType() == KEY_BIND_COMMAND)
{
CCommandBind* pBind = static_cast<CCommandBind*>(*iter);
if (!szKey
|| (stricmp(pBind->boundKey->szKey, szKey) == 0)
|| (bConsiderDefaultKey && pBind->bIsReplacingScriptKey && stricmp(pBind->strOriginalScriptKey, szKey) == 0))
if (!szKey || (stricmp(pBind->boundKey->szKey, szKey) == 0) ||
(bConsiderDefaultKey && pBind->bIsReplacingScriptKey && stricmp(pBind->strOriginalScriptKey, szKey) == 0))
{
if (pBind->szResource && (strcmp(pBind->szResource, szResource) == 0))
{
Expand All @@ -800,7 +799,8 @@ bool CKeyBinds::SetCommandActive(const char* szKey, const char* szCommand, bool
return false;
}

void CKeyBinds::SetAllCommandsActive(const char* szResource, bool bActive, const char* szCommand, bool bState, const char* szArguments, bool checkHitState, const char* szOnlyWithDefaultKey)
void CKeyBinds::SetAllCommandsActive(const char* szResource, bool bActive, const char* szCommand, bool bState, const char* szArguments, bool checkHitState,
const char* szOnlyWithDefaultKey)
{
NullEmptyStrings(szCommand, szArguments);

Expand All @@ -818,9 +818,8 @@ void CKeyBinds::SetAllCommandsActive(const char* szResource, bool bActive, const
{
if (!szArguments || (pBind->szArguments && strcmp(pBind->szArguments, szArguments) == 0))
{
if (!szOnlyWithDefaultKey
|| (pBind->bIsReplacingScriptKey && stricmp(pBind->strOriginalScriptKey, szOnlyWithDefaultKey) == 0)
|| stricmp(pBind->boundKey->szKey, szOnlyWithDefaultKey) == 0)
if (!szOnlyWithDefaultKey || (pBind->bIsReplacingScriptKey && stricmp(pBind->strOriginalScriptKey, szOnlyWithDefaultKey) == 0) ||
stricmp(pBind->boundKey->szKey, szOnlyWithDefaultKey) == 0)
{
pBind->bActive = bActive;
}
Expand Down
10 changes: 5 additions & 5 deletions Client/game_sa/CAnimBlendAssociationSA.h
Expand Up @@ -47,12 +47,12 @@ class CAnimBlendAssociationSA : public CAnimBlendAssociation

CAnimBlendAssociationSAInterface* Constructor(CAnimBlendStaticAssociationSAInterface& StaticAssociationByReference);
CAnimBlendAssociationSAInterface* Constructor(RpClump* pClump, CAnimBlendHierarchySAInterface* pAnimHierarchy);
CAnimBlendAssociationSAInterface* GetInterface(void) { return m_pInterface; }
AssocGroupId GetAnimGroup(void) { return (AssocGroupId)m_pInterface->sAnimGroup; }
AnimationId GetAnimID(void) { return (AnimationId)m_pInterface->sAnimID; }
std::unique_ptr<CAnimBlendHierarchy> GetAnimHierarchy(void);
CAnimBlendAssociationSAInterface* GetInterface() { return m_pInterface; }
AssocGroupId GetAnimGroup() { return (AssocGroupId)m_pInterface->sAnimGroup; }
AnimationId GetAnimID() { return (AnimationId)m_pInterface->sAnimID; }
std::unique_ptr<CAnimBlendHierarchy> GetAnimHierarchy();

float GetBlendAmount(void) { return m_pInterface->fBlendAmount; }
float GetBlendAmount() { return m_pInterface->fBlendAmount; }
void SetBlendAmount(float fAmount) { m_pInterface->fBlendAmount = fAmount; }
void SetCurrentProgress(float fProgress);
void SetAnimID(short sAnimID) { m_pInterface->sAnimID = sAnimID; }
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Expand Up @@ -6035,7 +6035,7 @@ void CClientPed::SetNextAnimationCustom(const std::shared_ptr<CClientIFP>& pIFP,
m_u32CustomAnimationNameHash = HashString(strAnimationName.ToLower());
}

void CClientPed::ReplaceAnimation(std::unique_ptr<CAnimBlendHierarchy> & pInternalAnimHierarchy, const std::shared_ptr<CClientIFP>& pIFP,
void CClientPed::ReplaceAnimation(std::unique_ptr<CAnimBlendHierarchy>& pInternalAnimHierarchy, const std::shared_ptr<CClientIFP>& pIFP,
CAnimBlendHierarchySAInterface* pCustomAnimHierarchy)
{
SReplacedAnimation replacedAnimation;
Expand All @@ -6044,7 +6044,7 @@ void CClientPed::ReplaceAnimation(std::unique_ptr<CAnimBlendHierarchy> & pIntern
m_mapOfReplacedAnimations[pInternalAnimHierarchy->GetInterface()] = replacedAnimation;
}

void CClientPed::RestoreAnimation(std::unique_ptr<CAnimBlendHierarchy> & pInternalAnimHierarchy)
void CClientPed::RestoreAnimation(std::unique_ptr<CAnimBlendHierarchy>& pInternalAnimHierarchy)
{
m_mapOfReplacedAnimations.erase(pInternalAnimHierarchy->GetInterface());
}
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CClientPed.h
Expand Up @@ -493,9 +493,9 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
const unsigned int& GetCustomAnimationBlockNameHash(void) { return m_u32CustomBlockNameHash; }
const unsigned int& GetCustomAnimationNameHash(void) { return m_u32CustomAnimationNameHash; }

void ReplaceAnimation(std::unique_ptr<CAnimBlendHierarchy> & pInternalAnimHierarchy, const std::shared_ptr<CClientIFP>& pIFP,
void ReplaceAnimation(std::unique_ptr<CAnimBlendHierarchy>& pInternalAnimHierarchy, const std::shared_ptr<CClientIFP>& pIFP,
CAnimBlendHierarchySAInterface* pCustomAnimHierarchy);
void RestoreAnimation(std::unique_ptr<CAnimBlendHierarchy> & pInternalAnimHierarchy);
void RestoreAnimation(std::unique_ptr<CAnimBlendHierarchy>& pInternalAnimHierarchy);
void RestoreAnimations(const std::shared_ptr<CClientIFP>& IFP);
void RestoreAnimations(CAnimBlock& animationBlock);
void RestoreAllAnimations(void);
Expand Down

0 comments on commit def10ef

Please sign in to comment.