Skip to content

Add animation related functions #3734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Client/game_sa/CAnimBlendAssociationSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ std::unique_ptr<CAnimBlendHierarchy> CAnimBlendAssociationSA::GetAnimHierarchy()
return pGame->GetAnimManager()->GetAnimBlendHierarchy(m_pInterface->pAnimHierarchy);
}

const std::unique_ptr<CAnimBlendHierarchy> CAnimBlendAssociationSA::GetAnimHierarchy() const noexcept
{
return pGame->GetAnimManager()->GetAnimBlendHierarchy(m_pInterface->pAnimHierarchy);
}

void CAnimBlendAssociationSA::SetCurrentProgress(float fProgress)
{
float fTime = m_pInterface->pAnimHierarchy->fTotalTime * fProgress;
Expand Down
6 changes: 5 additions & 1 deletion Client/game_sa/CAnimBlendAssociationSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <CVector.h>
#include <game/RenderWare.h>
#include <game/CAnimBlendAssociation.h>
#include <game/CAnimBlendHierarchy.h>
#include "CAnimBlendNodeSA.h"

class CAnimBlendAssocGroupSA;
Expand Down Expand Up @@ -159,12 +160,15 @@ class CAnimBlendAssociationSA : public CAnimBlendAssociation
eAnimGroup GetAnimGroup() { return static_cast<eAnimGroup>(m_pInterface->sAnimGroup); }
eAnimID GetAnimID() { return static_cast<eAnimID>(m_pInterface->sAnimID); }
std::unique_ptr<CAnimBlendHierarchy> GetAnimHierarchy();
const std::unique_ptr<CAnimBlendHierarchy> GetAnimHierarchy() const noexcept;

float GetBlendAmount() { return m_pInterface->fBlendAmount; }
void SetBlendAmount(float fAmount) { m_pInterface->fBlendAmount = fAmount; }
void SetCurrentProgress(float fProgress);
float GetCurrentSpeed() { return m_pInterface->fSpeed; }
float GetCurrentProgress() const noexcept { return m_pInterface->fCurrentTime; }
float GetCurrentSpeed() const noexcept { return m_pInterface->fSpeed; }
void SetCurrentSpeed(float fSpeed) { m_pInterface->fSpeed = fSpeed; }
float GetLength() const noexcept { return GetAnimHierarchy()->GetTotalTime(); }
void SetAnimID(short sAnimID) { m_pInterface->sAnimID = sAnimID; }
void SetAnimGroup(short sAnimGroup) { m_pInterface->sAnimGroup = sAnimGroup; }
void SetFlags(short sFlags) { m_pInterface->m_nFlags = sFlags; }
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/CAnimBlendHierarchySA.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CAnimBlendHierarchySA : public CAnimBlendHierarchy
void RemoveFromUncompressedCache();
void RemoveQuaternionFlips();
void CalculateTotalTime();
float GetTotalTime() const noexcept { return m_pInterface->fTotalTime; }
CAnimBlendSequenceSAInterface* GetSequence(DWORD dwIndex);
CAnimBlendSequenceSAInterface* GetSequences() { return m_pInterface->pSequences; }
unsigned short GetNumSequences() { return m_pInterface->usNumSequences; }
Expand Down
21 changes: 21 additions & 0 deletions Client/game_sa/TaskBasicSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@
#include "TaskBasicSA.h"
#include "CPedSA.h"


CTaskSimpleRunNamedAnimSAInterface* CTaskSimpleRunNamedAnimSA::GetAnimationInterface() noexcept
{
return reinterpret_cast<CTaskSimpleRunNamedAnimSAInterface*>(this->GetInterface());
}

const CTaskSimpleRunNamedAnimSAInterface* CTaskSimpleRunNamedAnimSA::GetAnimationInterface() const noexcept
{
return reinterpret_cast<const CTaskSimpleRunNamedAnimSAInterface*>(this->GetInterface());
}

const char* CTaskSimpleRunNamedAnimSA::GetAnimName() const noexcept
{
return GetAnimationInterface()->m_animName;
}

const char* CTaskSimpleRunNamedAnimSA::GetGroupName() const noexcept
{
return GetAnimationInterface()->m_animGroupName;
}

CTaskComplexUseMobilePhoneSA::CTaskComplexUseMobilePhoneSA(const int iDuration)
{
CreateTaskInterface(sizeof(CTaskComplexUseMobilePhoneSAInterface));
Expand Down
6 changes: 6 additions & 0 deletions Client/game_sa/TaskBasicSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ class CTaskSimpleRunNamedAnimSA : public virtual CTaskSimpleAnimSA, public virtu
CTaskSimpleRunNamedAnimSA(const char* pAnimName, const char* pAnimGroupName, const int flags, const float fBlendDelta, const int iTime = -1,
const bool bDontInterrupt = false, const bool bRunInSequence = false, const bool bOffsetPed = false,
const bool bHoldLastFrame = false);

CTaskSimpleRunNamedAnimSAInterface* GetAnimationInterface() noexcept;
const CTaskSimpleRunNamedAnimSAInterface* GetAnimationInterface() const noexcept;

const char* GetAnimName() const noexcept override;
const char* GetGroupName() const noexcept override;
};

class CTaskComplexDieSAInterface : public CTaskComplexSAInterface
Expand Down
3 changes: 2 additions & 1 deletion Client/game_sa/TaskSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class CTaskSA : public virtual CTask

// our function(s)
void SetInterface(CTaskSAInterface* pInterface) { TaskInterface = pInterface; };
CTaskSAInterface* GetInterface() { return TaskInterface; }
CTaskSAInterface* GetInterface() noexcept { return TaskInterface; }
const CTaskSAInterface* GetInterface() const noexcept { return TaskInterface; }
bool IsValid() { return GetInterface() != NULL; }

void CreateTaskInterface(size_t nSize);
Expand Down
22 changes: 0 additions & 22 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5691,28 +5691,6 @@ bool CClientPed::IsRunningAnimation()
return (m_AnimationCache.bLoop && m_pAnimationBlock);
}

void CClientPed::RunAnimation(AssocGroupId animGroup, AnimationId animID)
{
KillAnimation();

if (m_pPlayerPed)
{
// Remove jetpack now so it doesn't stay on (#9522#c25612)
if (HasJetPack())
SetHasJetPack(false);

// Let's not choke them any longer
if (IsChoking())
SetChoking(false);

CTask* pTask = g_pGame->GetTasks()->CreateTaskSimpleRunAnim(animGroup, animID, 4.0f, TASK_SIMPLE_ANIM, "TASK_SIMPLE_ANIM");
if (pTask)
{
pTask->SetAsPedTask(m_pPlayerPed, TASK_PRIORITY_PRIMARY);
}
}
}

void CClientPed::RunNamedAnimation(std::unique_ptr<CAnimBlock>& pBlock, const char* szAnimName, int iTime, int iBlend, bool bLoop, bool bUpdatePosition,
bool bInterruptable, bool bFreezeLastFrame, bool bRunInSequence, bool bOffsetPed, bool bHoldLastFrame)
{
Expand Down
1 change: 0 additions & 1 deletion Client/mods/deathmatch/logic/CClientPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <game/CWeaponStat.h>
#include <game/CWeaponStatManager.h>
#include <game/CBuildingRemoval.h>
#include <game/Task.h>
#include <game/TaskBasic.h>

using std::list;

Expand Down
6 changes: 4 additions & 2 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ class CStaticFunctionDefinitions
static bool SetPedCanBeKnockedOffBike(CClientEntity& Entity, bool bCanBeKnockedOffBike);
static bool SetPedAnimation(CClientEntity& Entity, const SString& strBlockName, const char* szAnimName, int iTime, int iBlend, bool bLoop,
bool bUpdatePosition, bool bInterruptable, bool bFreezeLastFrame);
static bool SetPedAnimationProgress(CClientEntity& Entity, const SString& strAnimName, float fProgress);
static bool SetPedAnimationSpeed(CClientEntity& Entity, const SString& strAnimName, float fSpeed);

static bool SetPedAnimationProgress(CClientEntity& Entity, const SString& strAnimName, float fProgress);
static bool SetPedAnimationSpeed(CClientEntity& Entity, const SString& strAnimName, float fSpeed);

static bool SetPedMoveAnim(CClientEntity& Entity, unsigned int iMoveAnim);
static bool AddPedClothes(CClientEntity& Entity, const char* szTexture, const char* szModel, unsigned char ucType);
static bool RemovePedClothes(CClientEntity& Entity, unsigned char ucType);
Expand Down
182 changes: 125 additions & 57 deletions Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include "StdInc.h"
#include <game/CWeapon.h>
#include "lua/CLuaFunctionParser.h"
#include "CMatrix_Pad.h"
#include <game/CTasks.h>
#include <game/TaskBasic.h>
#include <game/CAnimManager.h>

#define MIN_CLIENT_REQ_REMOVEPEDFROMVEHICLE_CLIENTSIDE "1.3.0-9.04482"
#define MIN_CLIENT_REQ_WARPPEDINTOVEHICLE_CLIENTSIDE "1.3.0-9.04482"
Expand All @@ -23,70 +25,26 @@ void CLuaPedDefs::LoadFunctions()
{"createPed", CreatePed},
{"detonateSatchels", DetonateSatchels},
{"killPed", KillPed},

{"resetPedVoice", ArgumentParser<ResetPedVoice>},
{"getPedVoice", GetPedVoice},
{"updateElementRpHAnim", ArgumentParser<UpdateElementRpHAnim>},
{"addPedClothes", AddPedClothes},
{"removePedClothes", RemovePedClothes},
{"warpPedIntoVehicle", WarpPedIntoVehicle},
{"removePedFromVehicle", RemovePedFromVehicle},
{"givePedWeapon", GivePedWeapon},

{"setPedVoice", SetPedVoice},
{"getPedRotation", GetPedRotation},
{"canPedBeKnockedOffBike", CanPedBeKnockedOffBike},
{"getPedContactElement", GetPedContactElement},
{"isPedInVehicle", IsPedInVehicle},
{"doesPedHaveJetPack", DoesPedHaveJetPack},
{"isPedWearingJetpack", DoesPedHaveJetPack}, // introduced in 1.5.5-9.13846
{"isPedOnGround", IsPedOnGround},
{"getPedTask", GetPedTask},
{"getPedSimplestTask", GetPedSimplestTask},
{"isPedDoingTask", IsPedDoingTask},
{"getPedTarget", GetPedTarget},
{"getPedTargetStart", GetPedTargetStart},
{"getPedTargetEnd", GetPedTargetEnd},
{"getPedTargetCollision", GetPedTargetCollision},
{"getPedWeaponSlot", GetPedWeaponSlot},
{"getPedWeapon", GetPedWeapon},
{"getPedAmmoInClip", GetPedAmmoInClip},
{"getPedTotalAmmo", GetPedTotalAmmo},
{"getPedOccupiedVehicle", GetPedOccupiedVehicle},
{"getPedOccupiedVehicleSeat", GetPedOccupiedVehicleSeat},
{"getPedArmor", GetPedArmor},
{"isPedChoking", IsPedChoking},
{"isPedDucked", IsPedDucked},
{"getPedStat", GetPedStat},
{"getPedBonePosition", GetPedBonePosition},
{"setElementBonePosition", ArgumentParser<SetElementBonePosition>},
{"setElementBoneRotation", ArgumentParser<SetElementBoneRotation>},
{"setElementBoneQuaternion", ArgumentParser<SetElementBoneQuaternion>},
{"getElementBonePosition", ArgumentParser<GetElementBonePosition>},
{"getElementBoneRotation", ArgumentParser<GetElementBoneRotation>},
{"getElementBoneQuaternion", ArgumentParser<GetElementBoneQuaternion>},
{"setElementBoneMatrix", ArgumentParser<SetElementBoneMatrix>},
{"getElementBoneMatrix", ArgumentParser<GetElementBoneMatrix>},
{"updateElementRpHAnim", ArgumentParser<UpdateElementRpHAnim>},
{"getPedClothes", GetPedClothes},
{"getPedControlState", GetPedControlState},
{"getPedAnalogControlState", GetPedAnalogControlState},
{"isPedDead", IsPedDead},

{"isPedDoingGangDriveby", IsPedDoingGangDriveby},
{"getPedFightingStyle", GetPedFightingStyle},
{"getPedAnimation", GetPedAnimation},
{"getPedMoveState", GetPedMoveState},
{"getPedWalkingStyle", GetPedMoveAnim},
{"isPedHeadless", IsPedHeadless},
{"isPedFrozen", IsPedFrozen},
{"isPedFootBloodEnabled", IsPedFootBloodEnabled},
{"getPedCameraRotation", GetPedCameraRotation},
{"getPedOxygenLevel", GetPedOxygenLevel},
{"isPedBleeding", ArgumentParser<IsPedBleeding>},

{"setPedWeaponSlot", SetPedWeaponSlot},
{"setPedRotation", SetPedRotation},
{"setPedWeaponSlot", SetPedWeaponSlot},
{"setPedCanBeKnockedOffBike", SetPedCanBeKnockedOffBike},
{"setPedAnimation", SetPedAnimation},
{"setPedAnimationProgress", SetPedAnimationProgress},
{"setPedAnimationSpeed", SetPedAnimationSpeed},
{"setPedWalkingStyle", SetPedMoveAnim},
{"addPedClothes", AddPedClothes},
{"removePedClothes", RemovePedClothes},
{"setPedControlState", SetPedControlState},
{"setPedAnalogControlState", SetPedAnalogControlState},
{"setPedDoingGangDriveby", SetPedDoingGangDriveby},
Expand All @@ -98,15 +56,65 @@ void CLuaPedDefs::LoadFunctions()
{"setPedCameraRotation", SetPedCameraRotation},
{"setPedAimTarget", SetPedAimTarget},
{"setPedStat", SetPedStat},
{"warpPedIntoVehicle", WarpPedIntoVehicle},
{"removePedFromVehicle", RemovePedFromVehicle},
{"setPedOxygenLevel", SetPedOxygenLevel},
{"setPedArmor", ArgumentParser<SetPedArmor>},
{"givePedWeapon", GivePedWeapon},
{"isPedReloadingWeapon", IsPedReloadingWeapon},
{"setPedEnterVehicle", ArgumentParser<SetPedEnterVehicle>},
{"setPedExitVehicle", ArgumentParser<SetPedExitVehicle>},
{"setPedBleeding", ArgumentParser<SetPedBleeding>},

{"getPedVoice", GetPedVoice},
{"getElementBonePosition", ArgumentParser<GetElementBonePosition>},
{"getElementBoneRotation", ArgumentParser<GetElementBoneRotation>},
{"getElementBoneQuaternion", ArgumentParser<GetElementBoneQuaternion>},
{"getElementBoneMatrix", ArgumentParser<GetElementBoneMatrix>},
{"getPedRotation", GetPedRotation},
{"getPedWeaponSlot", GetPedWeaponSlot},
{"canPedBeKnockedOffBike", CanPedBeKnockedOffBike},
{"getPedAnimation", GetPedAnimation},
{"getPedAnimationProgress", ArgumentParser<GetPedAnimationProgress>},
{"getPedAnimationSpeed", ArgumentParser<GetPedAnimationSpeed>},
{"getPedAnimationLength", ArgumentParser<GetPedAnimationLength>},
{"getPedWalkingStyle", GetPedMoveAnim},
{"getPedControlState", GetPedControlState},
{"getPedAnalogControlState", GetPedAnalogControlState},
{"isPedDoingGangDriveby", IsPedDoingGangDriveby},
{"getPedFightingStyle", GetPedFightingStyle},

{"isPedHeadless", IsPedHeadless},
{"isPedFrozen", IsPedFrozen},
{"isPedFootBloodEnabled", IsPedFootBloodEnabled},
{"getPedCameraRotation", GetPedCameraRotation},

{"getPedStat", GetPedStat},
{"getPedOxygenLevel", GetPedOxygenLevel},
{"getPedArmor", GetPedArmor},
{"isPedBleeding", ArgumentParser<IsPedBleeding>},

{"getPedContactElement", GetPedContactElement},
{"getPedTask", GetPedTask},
{"getPedSimplestTask", GetPedSimplestTask},
{"getPedTarget", GetPedTarget},
{"getPedTargetStart", GetPedTargetStart},
{"getPedTargetEnd", GetPedTargetEnd},
{"getPedTargetCollision", GetPedTargetCollision},
{"getPedWeapon", GetPedWeapon},
{"getPedAmmoInClip", GetPedAmmoInClip},
{"getPedTotalAmmo", GetPedTotalAmmo},
{"getPedOccupiedVehicle", GetPedOccupiedVehicle},
{"getPedOccupiedVehicleSeat", GetPedOccupiedVehicleSeat},
{"getPedBonePosition", GetPedBonePosition},
{"getPedClothes", GetPedClothes},
{"getPedMoveState", GetPedMoveState},

{"doesPedHaveJetPack", DoesPedHaveJetPack},
{"isPedInVehicle", IsPedInVehicle},
{"isPedWearingJetpack", DoesPedHaveJetPack},
{"isPedOnGround", IsPedOnGround},
{"isPedDoingTask", IsPedDoingTask},
{"isPedChoking", IsPedChoking},
{"isPedDucked", IsPedDucked},
{"isPedDead", IsPedDead},
{"isPedReloadingWeapon", IsPedReloadingWeapon},
};

// Add functions
Expand Down Expand Up @@ -2279,6 +2287,66 @@ int CLuaPedDefs::SetPedAnimationProgress(lua_State* luaVM)
return 1;
}

float CLuaPedDefs::GetPedAnimationProgress(CClientPed* ped)
{
CTask* currentTask = ped->GetTaskManager()->GetActiveTask();
std::int32_t type = currentTask->GetTaskType();

// check if animation (task type is 401)
if (type != 401)
return -1.0f;

auto* animation = dynamic_cast<CTaskSimpleRunNamedAnim*>(currentTask);
if (!animation)
return -1.0f;

auto animAssociation = g_pGame->GetAnimManager()->RpAnimBlendClumpGetAssociation(ped->GetClump(), animation->GetAnimName());
if (!animAssociation)
return -1.0f;

return animAssociation->GetCurrentProgress() / animAssociation->GetLength();
}

float CLuaPedDefs::GetPedAnimationSpeed(CClientPed* ped)
{
CTask* currentTask = ped->GetTaskManager()->GetActiveTask();
std::int32_t type = currentTask->GetTaskType();

// check if animation (task type is 401)
if (type != 401)
return -1.0f;

auto* animation = dynamic_cast<CTaskSimpleRunNamedAnim*>(currentTask);
if (!animation)
return -1.0f;

auto animAssociation = g_pGame->GetAnimManager()->RpAnimBlendClumpGetAssociation(ped->GetClump(), animation->GetAnimName());
if (!animAssociation)
return -1.0f;

return animAssociation->GetCurrentSpeed();
}

float CLuaPedDefs::GetPedAnimationLength(CClientPed* ped)
{
CTask* currentTask = ped->GetTaskManager()->GetActiveTask();
std::int32_t type = currentTask->GetTaskType();

// check if animation (task type is 401)
if (type != 401)
return -1.0f;

auto* animation = dynamic_cast<CTaskSimpleRunNamedAnim*>(currentTask);
if (!animation)
return -1.0f;

auto animAssociation = g_pGame->GetAnimManager()->RpAnimBlendClumpGetAssociation(ped->GetClump(), animation->GetAnimName());
if (!animAssociation)
return -1.0f;

return animAssociation->GetLength();
}

int CLuaPedDefs::SetPedAnimationSpeed(lua_State* luaVM)
{
CClientEntity* pEntity;
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class CLuaPedDefs : public CLuaDefs
LUA_DECLARE(IsPedDoingGangDriveby);
LUA_DECLARE(GetPedFightingStyle);
LUA_DECLARE(GetPedAnimation);
static float GetPedAnimationProgress(CClientPed* ped);
static float GetPedAnimationSpeed(CClientPed* ped);
static float GetPedAnimationLength(CClientPed* ped);
LUA_DECLARE(GetPedMoveState);
LUA_DECLARE(GetPedMoveAnim);
LUA_DECLARE(IsPedHeadless);
Expand Down
Loading
Loading