Skip to content

Commit b55cc8e

Browse files
committed
Fix skate
1 parent e7ad026 commit b55cc8e

File tree

3 files changed

+77
-47
lines changed

3 files changed

+77
-47
lines changed

Client/game_sa/CPedSA.cpp

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "TaskSA.h"
2626
#include "CAnimBlendHierarchySA.h"
2727

28+
#include "enums/AdhesionGroup.h"
29+
2830
extern CGameSA* pGame;
2931

3032
static bool g_onlyUpdateRotations = false;
@@ -582,11 +584,11 @@ void CPedSA::GetAttachedSatchels(std::vector<SSatchelsData>& satchelsList) const
582584

583585
void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
584586
{
585-
auto* firstAssoc = ((CAnimBlendAssociationSAInterface * (__cdecl*)(RpClump*))0x4D15E0)(ped->m_pRwObject);
587+
auto firstAssoc = pGame->GetAnimManager()->RpAnimBlendClumpGetFirstAssociation(ped->m_pRwObject);
586588
if (!firstAssoc)
587589
return;
588590

589-
eAnimID animID = (eAnimID)firstAssoc->sAnimID;
591+
eAnimID animID = firstAssoc->GetAnimID();
590592

591593
bool isMovingAnim = false;
592594
if (animID == eAnimID::ANIM_ID_WALK || animID == eAnimID::ANIM_ID_RUN || animID == eAnimID::ANIM_ID_SPRINT)
@@ -605,29 +607,21 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
605607

606608
CAnimBlendAssociationSAInterface* walkAnim = nullptr;
607609
float walkBlendTotal = 0.0f;
608-
float idleBlendTotal = 0.0f;
610+
float idleBlendTotal = 0.0f;
609611

610-
for (auto& assoc = firstAssoc; assoc != nullptr; assoc = ((CAnimBlendAssociationSAInterface * (__cdecl*)(CAnimBlendAssociationSAInterface*))0x4D6AB0)(assoc))
612+
for (auto& assoc = firstAssoc; assoc != nullptr; assoc = pGame->GetAnimManager()->RpAnimBlendGetNextAssociation(assoc))
611613
{
612-
if (assoc->m_walkAnim)
614+
CAnimBlendAssociationSAInterface* assocInterface = assoc->GetInterface();
615+
616+
if (assocInterface->m_walkAnim)
613617
{
614-
walkAnim = assoc;
615-
walkBlendTotal += assoc->fBlendAmount;
618+
walkAnim = assocInterface;
619+
walkBlendTotal += assocInterface->fBlendAmount;
616620
}
617-
else if (!assoc->m_bAddAnimBlendToTotalBlend && assoc->sAnimID != 223 && (assoc->m_bPartial || !ped->pedFlags.bIsDucking))
618-
idleBlendTotal += assoc->fBlendAmount;
621+
else if (!assocInterface->m_bAddAnimBlendToTotalBlend && assoc->GetAnimID() != eAnimID::ANIM_ID_FIGHT_IDLE && (assocInterface->m_bPartial || !ped->pedFlags.bIsDucking))
622+
idleBlendTotal += assocInterface->fBlendAmount;
619623
}
620624

621-
/* if (!walkAnim)
622-
{
623-
walkAnim = ((CAnimBlendAssociationSAInterface * (__cdecl*)(RpClump*))0x4D15E0)(ped->m_pRwObject);
624-
625-
if (walkAnim->m_walkAnim)
626-
walkBlendTotal = walkAnim->fBlendAmount;
627-
else if (walkAnim->m_bAddAnimBlendToTotalBlend && walkAnim->sAnimID != 223 && (walkAnim->m_bPartial || ped->pedFlags.bIsDucking))
628-
idleBlendTotal = walkAnim->fBlendAmount;
629-
}*/
630-
631625
auto handleLanding = [](CPedSAInterface* ped)
632626
{
633627
if (!ped) return;
@@ -638,9 +632,9 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
638632
auto* task = ((CTaskSAInterface* (__thiscall*)(void*))0x6819D0)(&ped->pPedIntelligence->taskManager);
639633
if (!task) return;
640634

641-
DWORD taskType = reinterpret_cast<int(__thiscall*)(void*)>(task->VTBL->GetTaskType)(task);
642-
643-
if (taskType == 0xF2) // TASK_SIMPLE_LAND
635+
eTaskType taskType = reinterpret_cast<eTaskType(__thiscall*)(void*)>(task->VTBL->GetTaskType)(task);
636+
637+
if (taskType == TASK_SIMPLE_LAND)
644638
{
645639
// CTaskSimpleLand::RightFootLanded
646640
if (((bool(__thiscall*)(void*))0x678FE0)((void*)task))
@@ -678,7 +672,7 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
678672
soundSpeed = 0.9f;
679673
}
680674

681-
if (ped->iMoveAnimGroup == 69)
675+
if (ped->iMoveAnimGroup == 69) // ANIM_GROUP_PLAYERSNEAK
682676
{
683677
volumeOffset -= 6.0f;
684678
soundSpeed -= 0.1f;
@@ -702,15 +696,25 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
702696
{
703697
CVector pos{};
704698

699+
// CMemoryMgr::Malloc
700+
// 0x2C = size of CEventSoundQuiet
705701
void* mem = ((void*(__cdecl*)(int))0x72F420)(0x2C);
706702

703+
// CEventSoundQuiet::CEventSoundQuiet
707704
((void*(__thiscall*)(void*, CEntitySAInterface*, float, int, CVector*))0x5E05B0)(mem, ped, soundLevel, -1, &pos);
708705

706+
// GetEventGlobalGroup
709707
void* eventGlobalGroup = ((void*(__cdecl*)())0x4ABA50)();
708+
709+
// CEventGroup::Add
710710
((void(__thiscall*)(void*, void*, int))0x4AB420)(eventGlobalGroup, mem, 0);
711711

712+
// CEventSoundQuiet::~CEventSoundQuiet
712713
((void(__thiscall*)(void*))0x5DEA00)(mem);
713714

715+
// CMemoryMgr::Free
716+
((void(__cdecl*)(void*))0x72F430)(mem);
717+
714718
DoFootstep(ped, true);
715719
};
716720

@@ -729,22 +733,21 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
729733
maxAnimTime += 0.2f;
730734
}
731735

732-
CPedStatSAInterface** ms_apPedStats = reinterpret_cast<CPedStatSAInterface**>(0xC0BBEC);
733-
float animTimeMult = 0.0f;
734-
735-
float volumeMult = 0.0f;
736-
737-
if (ped->pPedStats == ms_apPedStats[40])
736+
if (ped->pPedStats->id == 40) // STAT_SKATER
738737
{
739-
animTimeMult = 0.533f;
740-
if (walkAnim->sAnimID != 0)
738+
float volumeMult = 1.0f;
739+
float animTimeMult = 0.533f;
740+
741+
if (static_cast<eAnimID>(walkAnim->sAnimID) != eAnimID::ANIM_ID_WALK)
741742
animTimeMult = 0.33f;
742743

743-
int surface = ((int(__thiscall*)(void*, int))0x55E5C0)((void*)0xB79538, ped->m_ucCollisionContactSurfaceType) - 3;
744-
if (surface > 0)
744+
// SurfaceInfos_c::GetAdhesionGroup
745+
// 0xB79538 = g_surfaceInfos
746+
AdhesionGroups::Enum surface = ((AdhesionGroups::Enum(__thiscall*)(void*, int))0x55E5C0)((void*)0xB79538, ped->m_ucCollisionContactSurfaceType);
747+
748+
switch (surface)
745749
{
746-
int prevSurface = surface - 1;
747-
if (prevSurface == 0)
750+
case AdhesionGroups::Enum::SAND:
748751
{
749752
if (rand() % 64 > 0)
750753
{
@@ -754,35 +757,35 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
754757
handleLanding(ped);
755758
return;
756759
}
760+
case AdhesionGroups::Enum::LOOSE:
761+
{
762+
if (rand() % 128 > 0)
763+
{
764+
ped->vecAnimMovingShiftLocal *= 0.5f;
765+
}
757766

758-
if (prevSurface == 1)
767+
volumeMult = 0.5f;
768+
break;
769+
}
770+
case AdhesionGroups::Enum::WET:
759771
{
760772
ped->vecAnimMovingShiftLocal *= 0.3f;
761773
handleLanding(ped);
762774
return;
763775
}
764-
765-
volumeMult = 1.0f;
766-
}
767-
else
768-
{
769-
if (rand() % 128 > 0)
770-
{
771-
ped->vecAnimMovingShiftLocal *= 0.5f;
772-
}
773-
774-
volumeMult = 0.5f;
775776
}
776777

777778
if (walkAnim->fCurrentTime <= 0.0f || walkAnim->fCurrentTime - walkAnim->fTimeStep > 0.0f)
778779
{
779780
if (volumeMult > 0.2f && walkAnim->fCurrentTime > animTimeMult && walkAnim->fCurrentTime - walkAnim->fTimeStep <= animTimeMult && ped->pedAudio.canAddEvent)
780781
{
782+
// CAEPedAudioEntity::AddAudioEvent
781783
((void(__thiscall*)(CPedSoundEntitySAInterface*, int, float, float, CEntitySAInterface*, int, int, int))0x4E2BB0)(&ped->pedAudio, 57, std::log10(volumeMult), walkAnim->sAnimID == 0 ? 0.5 : 1.0f, nullptr, 0, 0, 0);
782784
}
783785
}
784786
else if (ped->pedAudio.canAddEvent)
785787
{
788+
// CAEPedAudioEntity::AddAudioEvent
786789
((void(__thiscall*)(CPedSoundEntitySAInterface*, int, float, float, CEntitySAInterface*, int, int, int))0x4E2BB0)(&ped->pedAudio, 56, std::log10(volumeMult), walkAnim->sAnimID == 0 ? 0.5 : 1.0f, nullptr, 0, 0, 0);
787790
}
788791

@@ -807,6 +810,7 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
807810
CPlayerPedDataSAInterface* playerData = ped->pPlayerData;
808811
if (playerData)
809812
{
813+
// CPedClothesDesc::GetIsWearingBalaclava
810814
bool wearingBalaclava = ((bool(__fastcall*)(CPedClothesDesc*, int))0x5A7950)(playerData->m_pClothes, 0);
811815
if (ped->moveState >= PedMoveState::Enum::PEDMOVE_JOG)
812816
{

Client/game_sa/CPedSA.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static_assert(sizeof(CPedAcquaintanceSAInterface) == 0x14, "Invalid size for CPe
211211

212212
class CPedStatSAInterface
213213
{
214+
public:
214215
std::uint32_t id;
215216
char name[24];
216217
float fleedDistance;

Shared/sdk/enums/AdhesionGroup.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: sdk/AdhesionGroup.h
6+
* PURPOSE: Header for common definitions
7+
*
8+
* Multi Theft Auto is available from https://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
12+
#pragma once
13+
14+
namespace AdhesionGroups
15+
{
16+
enum Enum
17+
{
18+
RUBBER = 0,
19+
HARD,
20+
ROAD,
21+
LOOSE,
22+
SAND,
23+
WET
24+
};
25+
}

0 commit comments

Comments
 (0)