Skip to content
Permalink
Browse files

Add more data to getPedAnimation (#892)

* Add more data to getPedAnimation

* Remove new line

Co-Authored-By: Dezash <Drakath13@gmail.com>

* Enclose extra animation data in a table

* Create a struct for animation data

* Fix strName type

* Refactor GetPedAnimation function

Co-authored-by: Qais Patankar <qaisjp@gmail.com>
Co-authored-by: saml1er <danishroar@gmail.com>
  • Loading branch information
3 people committed Mar 16, 2020
1 parent 1c9c3dc commit 67576459fd5504fc47ad374cfa0c22d1cc0de40d
@@ -159,14 +159,9 @@ void CClientPed::Init(CClientManager* pManager, unsigned long ulModelID, bool bI
m_bSunbathing = false;
m_bDestroyingSatchels = false;
m_bDoingGangDriveby = false;

m_pAnimationBlock = NULL;
m_bRequestedAnimation = false;
m_iTimeAnimation = -1;
m_iBlendAnimation = 250;
m_bLoopAnimation = false;
m_bUpdatePositionAnimation = false;
m_bInterruptableAnimation = false;
m_bFreezeLastFrameAnimation = true;
m_bHeadless = false;
m_bFrozen = false;
m_bFrozenWaitingForGroundToLoad = false;
@@ -2836,10 +2831,10 @@ void CClientPed::StreamedInPulse(bool bDoStandardPulses)
m_bRequestedAnimation = false;

// Copy our name incase it gets deleted
SString strAnimName = m_strAnimationName;
SString strAnimName = m_AnimationCache.strName;
// Run our animation
RunNamedAnimation(m_pAnimationBlock, strAnimName, m_iTimeAnimation, m_iBlendAnimation, m_bLoopAnimation, m_bUpdatePositionAnimation,
m_bInterruptableAnimation, m_bFreezeLastFrameAnimation);
RunNamedAnimation(m_pAnimationBlock, strAnimName, m_AnimationCache.iTime, m_AnimationCache.iBlend, m_AnimationCache.bLoop, m_AnimationCache.bUpdatePosition,
m_AnimationCache.bInterruptable, m_AnimationCache.bFreezeLastFrame);
}
}

@@ -3676,17 +3671,17 @@ void CClientPed::_CreateModel()
}

// Are we still playing a looped animation?
if (m_bLoopAnimation && m_pAnimationBlock)
if (m_AnimationCache.bLoop && m_pAnimationBlock)
{
if (m_bisCurrentAnimationCustom)
{
m_bisNextAnimationCustom = true;
}
// Copy our anim name incase it gets deleted
SString strAnimName = m_strAnimationName;
SString strAnimName = m_AnimationCache.strName;
// Run our animation
RunNamedAnimation(m_pAnimationBlock, strAnimName, m_iTimeAnimation, m_iBlendAnimation, m_bLoopAnimation, m_bUpdatePositionAnimation,
m_bInterruptableAnimation, m_bFreezeLastFrameAnimation);
RunNamedAnimation(m_pAnimationBlock, strAnimName, m_AnimationCache.iTime, m_AnimationCache.iBlend, m_AnimationCache.bLoop, m_AnimationCache.bUpdatePosition,
m_AnimationCache.bInterruptable, m_AnimationCache.bFreezeLastFrame);
}

// Set the voice that corresponds to our model
@@ -3968,18 +3963,18 @@ void CClientPed::_ChangeModel()
m_bDontChangeRadio = false;

// Are we still playing a looped animation?
if (m_bLoopAnimation && m_pAnimationBlock)
if (m_AnimationCache.bLoop && m_pAnimationBlock)
{
if (m_bisCurrentAnimationCustom)
{
m_bisNextAnimationCustom = true;
}

// Copy our anim name incase it gets deleted
SString strAnimName = m_strAnimationName;
SString strAnimName = m_AnimationCache.strName;
// Run our animation
RunNamedAnimation(m_pAnimationBlock, strAnimName, m_iTimeAnimation, m_iBlendAnimation, m_bLoopAnimation, m_bUpdatePositionAnimation,
m_bInterruptableAnimation, m_bFreezeLastFrameAnimation);
RunNamedAnimation(m_pAnimationBlock, strAnimName, m_AnimationCache.iTime, m_AnimationCache.iBlend, m_AnimationCache.bLoop, m_AnimationCache.bUpdatePosition,
m_AnimationCache.bInterruptable, m_AnimationCache.bFreezeLastFrame);
}

// Set the voice that corresponds to the new model
@@ -5638,6 +5633,25 @@ void CClientPed::SetDoingGangDriveby(bool bDriveby)
}
}

bool CClientPed::GetRunningAnimationName(SString& strBlockName, SString& strAnimName)
{
if (IsRunningAnimation())
{
if (IsCustomAnimationPlaying())
{
strBlockName = GetNextAnimationCustomBlockName();
strAnimName = GetNextAnimationCustomName();
}
else
{
strBlockName = GetAnimationBlock()->GetName();
strAnimName = m_AnimationCache.strName;
}
return true;
}
return false;
}

bool CClientPed::IsRunningAnimation()
{
if (m_pPlayerPed)
@@ -5649,7 +5663,7 @@ bool CClientPed::IsRunningAnimation()
}
return false;
}
return (m_bLoopAnimation && m_pAnimationBlock);
return (m_AnimationCache.bLoop && m_pAnimationBlock);
}

void CClientPed::RunAnimation(AssocGroupId animGroup, AnimationId animID)
@@ -5752,13 +5766,13 @@ void CClientPed::RunNamedAnimation(std::unique_ptr<CAnimBlock>& pBlock, const ch
{
m_pAnimationBlock = g_pGame->GetAnimManager()->GetAnimBlock(pBlock->GetInterface());
}
m_strAnimationName = szAnimName;
m_iTimeAnimation = iTime;
m_iBlendAnimation = iBlend;
m_bLoopAnimation = bLoop;
m_bUpdatePositionAnimation = bUpdatePosition;
m_bInterruptableAnimation = bInterruptable;
m_bFreezeLastFrameAnimation = bFreezeLastFrame;
m_AnimationCache.strName = szAnimName;
m_AnimationCache.iTime = iTime;
m_AnimationCache.iBlend = iBlend;
m_AnimationCache.bLoop = bLoop;
m_AnimationCache.bUpdatePosition = bUpdatePosition;
m_AnimationCache.bInterruptable = bInterruptable;
m_AnimationCache.bFreezeLastFrame = bFreezeLastFrame;
}

void CClientPed::KillAnimation()
@@ -5778,7 +5792,7 @@ void CClientPed::KillAnimation()
}
}
m_pAnimationBlock = NULL;
m_strAnimationName = "";
m_AnimationCache.strName = "";
m_bRequestedAnimation = false;
SetNextAnimationNormal();
}
@@ -5791,10 +5805,6 @@ std::unique_ptr<CAnimBlock> CClientPed::GetAnimationBlock()
}
return nullptr;
}
const char* CClientPed::GetAnimationName()
{
return m_strAnimationName;
}

void CClientPed::PostWeaponFire()
{
@@ -119,6 +119,27 @@ struct SReplacedAnimation
CAnimBlendHierarchySAInterface* pAnimationHierarchy;
};

struct SAnimationCache
{
SString strName;
int iTime;
bool bLoop;
bool bUpdatePosition;
bool bInterruptable;
bool bFreezeLastFrame;
int iBlend;

SAnimationCache()
{
iTime = -1;
bLoop = false;
bUpdatePosition = false;
bInterruptable = false;
bFreezeLastFrame = true;
iBlend = 250;
}
};

class CClientObject;

// To hide the ugly "pointer truncation from DWORD* to unsigned long warning
@@ -418,14 +439,15 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
bool IsDoingGangDriveby();
void SetDoingGangDriveby(bool bDriveby);

bool GetRunningAnimationName(SString& strBlockName, SString& strAnimName);
bool IsRunningAnimation();
void RunAnimation(AssocGroupId animGroup, AnimationId animID);
void RunNamedAnimation(std::unique_ptr<CAnimBlock>& pBlock, const char* szAnimName, int iTime = -1, int iBlend = 250, bool bLoop = true,
bool bUpdatePosition = true, bool bInterruptable = false, bool bFreezeLastFrame = true, bool bRunInSequence = false,
bool bOffsetPed = false, bool bHoldLastFrame = false);
void KillAnimation();
std::unique_ptr<CAnimBlock> GetAnimationBlock();
const char* GetAnimationName();
const SAnimationCache& GetAnimationCache() { return m_AnimationCache; }

bool IsUsingGun();

@@ -471,11 +493,11 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule

void DereferenceCustomAnimationBlock() { m_pCustomAnimationIFP = nullptr; }
std::shared_ptr<CClientIFP> GetCustomAnimationIFP() { return m_pCustomAnimationIFP; }
bool IsCustomAnimationPlaying() { return ((m_bRequestedAnimation || m_bLoopAnimation) && m_pAnimationBlock && m_bisCurrentAnimationCustom); }
bool IsCustomAnimationPlaying() { return ((m_bRequestedAnimation || m_AnimationCache.bLoop) && m_pAnimationBlock && m_bisCurrentAnimationCustom); }
void SetCustomAnimationUntriggerable()
{
m_bRequestedAnimation = false;
m_bLoopAnimation = false;
m_AnimationCache.bLoop = false;
}
bool IsNextAnimationCustom() { return m_bisNextAnimationCustom; }
void SetNextAnimationCustom(const std::shared_ptr<CClientIFP>& pIFP, const SString& strAnimationName);
@@ -646,14 +668,8 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
bool m_bDestroyingSatchels;
bool m_bDoingGangDriveby;
std::unique_ptr<CAnimBlock> m_pAnimationBlock;
SString m_strAnimationName;
bool m_bRequestedAnimation;
int m_iTimeAnimation;
int m_iBlendAnimation;
bool m_bLoopAnimation;
bool m_bUpdatePositionAnimation;
bool m_bInterruptableAnimation;
bool m_bFreezeLastFrameAnimation;
SAnimationCache m_AnimationCache;
bool m_bHeadless;
bool m_bFrozen;
bool m_bFrozenWaitingForGroundToLoad;
@@ -1715,25 +1715,6 @@ bool CStaticFunctionDefinitions::GetPedFightingStyle(CClientPed& Ped, unsigned c
return true;
}

bool CStaticFunctionDefinitions::GetPedAnimation(CClientPed& Ped, SString& strBlockName, SString& strAnimName)
{
if (Ped.IsRunningAnimation())
{
if (Ped.IsCustomAnimationPlaying())
{
strBlockName = Ped.GetNextAnimationCustomBlockName();
strAnimName = Ped.GetNextAnimationCustomName();
}
else
{
strBlockName = Ped.GetAnimationBlock()->GetName();
strAnimName = Ped.GetAnimationName();
}
return true;
}
return false;
}

bool CStaticFunctionDefinitions::GetPedMoveAnim(CClientPed& Ped, unsigned int& iMoveAnim)
{
iMoveAnim = (unsigned int)Ped.GetMoveAnim();
@@ -142,7 +142,6 @@ class CStaticFunctionDefinitions
static bool GetPedAnalogControlState(CClientPed& Ped, const char* szControl, float& fState, bool bRawInput);
static bool IsPedDoingGangDriveby(CClientPed& Ped, bool& bDoingGangDriveby);
static bool GetPedFightingStyle(CClientPed& Ped, unsigned char& ucStyle);
static bool GetPedAnimation(CClientPed& Ped, SString& strOutBlockName, SString& strOutAnimName);
static bool GetPedMoveAnim(CClientPed& Ped, unsigned int& iMoveAnim);
static bool GetPedMoveState(CClientPed& Ped, std::string& strMoveState);
static bool IsPedHeadless(CClientPed& Ped, bool& bHeadless);
@@ -1214,11 +1214,27 @@ int CLuaPedDefs::GetPedAnimation(lua_State* luaVM)
if (!argStream.HasErrors())
{
SString strBlockName, strAnimName;
if (CStaticFunctionDefinitions::GetPedAnimation(*pPed, strBlockName, strAnimName))
if (pPed->GetRunningAnimationName(strBlockName, strAnimName))
{
const SAnimationCache& animationCache = pPed->GetAnimationCache();
lua_pushstring(luaVM, strBlockName);
lua_pushstring(luaVM, strAnimName);
return 2;
lua_newtable(luaVM);
lua_pushinteger(luaVM, animationCache.iTime);
lua_setfield(luaVM, -2, "time");
lua_pushboolean(luaVM, animationCache.bLoop);
lua_setfield(luaVM, -2, "loop");
lua_pushboolean(luaVM, animationCache.bUpdatePosition);
lua_setfield(luaVM, -2, "updatePosition");
lua_pushboolean(luaVM, animationCache.bInterruptable);
lua_setfield(luaVM, -2, "interruptable");
lua_pushboolean(luaVM, animationCache.bFreezeLastFrame);
lua_setfield(luaVM, -2, "freezeLastFrame");
lua_pushinteger(luaVM, animationCache.iBlend);
lua_setfield(luaVM, -2, "blendTime");
lua_pushboolean(luaVM, pPed->IsTaskToBeRestoredOnAnimEnd());
lua_setfield(luaVM, -2, "restoreTaskOnAnimEnd");
return 3;
}
}
else

0 comments on commit 6757645

Please sign in to comment.
You can’t perform that action at this time.