/
CPedSA.cpp
1116 lines (981 loc) · 30.2 KB
/
CPedSA.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: game_sa/CPedSA.cpp
* PURPOSE: Ped entity
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/
#include "StdInc.h"
#include <game/TaskTypes.h>
#include "CFireManagerSA.h"
#include "CGameSA.h"
#include "CPedModelInfoSA.h"
#include "CPedSA.h"
#include "CPlayerInfoSA.h"
#include "CProjectileInfoSA.h"
#include "CStatsSA.h"
#include "CTaskManagerSA.h"
#include "CTasksSA.h"
#include "CWeaponInfoSA.h"
#include "CWeaponStatManagerSA.h"
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)
{
MemSetFast(m_pWeapons, 0, sizeof(CWeaponSA*) * WEAPONSLOT_MAX);
}
void CPedSA::SetInterface(CEntitySAInterface* intInterface)
{
m_pInterface = intInterface;
}
CPedSA::~CPedSA()
{
if (m_pPedIntelligence)
delete m_pPedIntelligence;
if (m_pPedSound)
delete m_pPedSound;
if (m_pDefaultPedSound)
delete m_pDefaultPedSound;
for (int i = 0; i < WEAPONSLOT_MAX; i++)
{
if (m_pWeapons[i])
delete m_pWeapons[i];
}
// Make sure this ped is not refed in the flame shot info array
CFlameShotInfo* pInfo = (CFlameShotInfo*)ARRAY_CFlameShotInfo;
for (uint i = 0; i < MAX_FLAME_SHOT_INFOS; i++)
{
if (pInfo->pInstigator == m_pInterface)
{
pInfo->pInstigator = NULL;
pInfo->ucFlag1 = 0;
}
pInfo++;
}
}
// used to init weapons at the moment, called by CPlayerPedSA when its been constructed
// can't use constructor as thats called before the interface pointer has been set the the aforementioned constructor
/**
* \todo Reimplement weapons and PedIK for SA
*/
void CPedSA::Init()
{
CPedSAInterface* pedInterface = GetPedInterface();
DWORD dwPedIntelligence = 0;
DWORD dwFunc = 0x411DE0;
DWORD dwInterface = (DWORD)pedInterface;
_asm
{
mov ecx, dwInterface
call dwFunc
mov dwPedIntelligence, eax
}
CPedIntelligenceSAInterface* m_pPedIntelligenceInterface = (CPedIntelligenceSAInterface*)(dwPedIntelligence);
m_pPedIntelligence = new CPedIntelligenceSA(m_pPedIntelligenceInterface, this);
m_pPedSound = new CPedSoundSA(&pedInterface->pedSound);
m_pDefaultPedSound = new CPedSoundSA(&pedInterface->pedSound);
for (int i = 0; i < WEAPONSLOT_MAX; i++)
m_pWeapons[i] = new CWeaponSA(&(pedInterface->Weapons[i]), this, (eWeaponSlot)i);
// this->m_pPedIK = new Cm_pPedIKSA(&(pedInterface->m_pPedIK));
}
void CPedSA::SetModelIndex(DWORD dwModelIndex)
{
DWORD dwFunction = FUNC_SetModelIndex;
DWORD dwThis = (DWORD)GetInterface();
_asm
{
mov ecx, dwThis
push dwModelIndex
call dwFunction
}
// Also set the voice gender
CPedModelInfoSAInterface* pModelInfo = (CPedModelInfoSAInterface*)pGame->GetModelInfo(dwModelIndex)->GetInterface();
if (pModelInfo)
{
DWORD dwType = pModelInfo->pedType;
GetPedInterface()->pedSound.m_bIsFemale = (dwType == 5 || dwType == 22);
}
}
// Hacky thing done for the local player when changing model
void CPedSA::RemoveGeometryRef()
{
RpClump* pClump = (RpClump*)GetInterface()->m_pRwObject;
RpAtomic* pAtomic = (RpAtomic*)((pClump->atomics.root.next) - 0x8);
RpGeometry* pGeometry = pAtomic->geometry;
if (pGeometry->refs > 1)
pGeometry->refs--;
}
bool CPedSA::IsInWater()
{
CTask* pTask = m_pPedIntelligence->GetTaskManager()->GetTask(TASK_PRIORITY_EVENT_RESPONSE_NONTEMP);
return (pTask && (pTask->GetTaskType() == TASK_COMPLEX_IN_WATER));
}
bool CPedSA::AddProjectile(eWeaponType eWeapon, CVector vecOrigin, float fForce, CVector* target, CEntity* targetEntity)
{
return ((CProjectileInfoSA*)pGame->GetProjectileInfo())->AddProjectile((CEntitySA*)this, eWeapon, vecOrigin, fForce, target, targetEntity);
}
void CPedSA::DetachPedFromEntity()
{
DWORD dwFunc = FUNC_DetachPedFromEntity;
DWORD dwThis = (DWORD)GetInterface();
_asm
{
mov ecx, dwThis
call dwFunc
}
}
bool CPedSA::InternalAttachEntityToEntity(DWORD dwEntityInterface, const CVector* vecPosition, const CVector* vecRotation)
{
AttachPedToEntity(dwEntityInterface, const_cast<CVector*>(vecPosition), 0, 0.0f, WEAPONTYPE_UNARMED, FALSE);
return true;
}
void CPedSA::AttachPedToEntity(DWORD dwEntityInterface, CVector* vector, unsigned short sDirection, float fRotationLimit, eWeaponType weaponType,
bool bChangeCamera)
{
// sDirection and fRotationLimit only apply to first-person shooting (bChangeCamera)
DWORD dwFunc = FUNC_AttachPedToEntity;
DWORD dwThis = (DWORD)GetInterface();
float fX = vector->fX;
float fY = vector->fY;
float fZ = vector->fZ;
BYTE bPedType = ((CPedSAInterface*)GetInterface())->bPedType;
// Hack the CPed type(?) to non-player so the camera doesn't get changed
if (!bChangeCamera)
((CPedSAInterface*)GetInterface())->bPedType = 2;
_asm
{
push weaponType
push fRotationLimit
movzx ecx, sDirection
push ecx
push fZ
push fY
push fX
push dwEntityInterface
mov ecx, dwThis
call dwFunc
}
// Hack the CPed type(?) to whatever it was set to
if (!bChangeCamera)((CPedSAInterface*)GetInterface())->bPedType = bPedType;
}
CVehicle* CPedSA::GetVehicle()
{
if (((CPedSAInterface*)GetInterface())->pedFlags.bInVehicle)
{
CVehicleSAInterface* vehicle = (CVehicleSAInterface*)(((CPedSAInterface*)GetInterface())->CurrentObjective);
if (vehicle)
{
SClientEntity<CVehicleSA>* pVehicleClientEntity = pGame->GetPools()->GetVehicle((DWORD*)vehicle);
return pVehicleClientEntity ? pVehicleClientEntity->pEntity : nullptr;
}
}
return NULL;
}
void CPedSA::Respawn(CVector* position, bool bCameraCut)
{
CPed* pLocalPlayer = pGame->GetPools()->GetPedFromRef((DWORD)1);
if (!bCameraCut)
{
// DISABLE call to CCamera__RestoreWithJumpCut when respawning
MemSet((void*)0x4422EA, 0x90, 20);
}
float fX = position->fX;
float fY = position->fY;
float fZ = position->fZ;
float fUnk = 1.0f;
DWORD dwFunc = FUNC_RestorePlayerStuffDuringResurrection;
DWORD dwThis = (DWORD)GetInterface();
_asm
{
push fUnk
push fZ
push fY
push fX
push dwThis
call dwFunc
add esp, 20
}
#if 0 // Removed to see if it reduces crashes
dwFunc = 0x441440; // CGameLogic::SortOutStreamingAndMemory
fUnk = 10.0f;
_asm
{
push fUnk
push position
call dwFunc
add esp, 8
}
#endif
dwFunc = FUNC_RemoveGogglesModel;
_asm
{
mov ecx, dwThis
call dwFunc
}
if (!bCameraCut)
{
// B9 28 F0 B6 00 E8 4C 9A 0C 00 B9 28 F0 B6 00 E8 B2 97 0C 00
unsigned char szCode[] = {0xB9, 0x28, 0xF0, 0xB6, 0x00, 0xE8, 0x4C, 0x9A, 0x0C, 0x00, 0xB9, 0x28, 0xF0, 0xB6, 0x00, 0xE8, 0xB2, 0x97, 0x0C, 0x00};
// RE-ENABLE call to CCamera__RestoreWithJumpCut when respawning
MemCpy((void*)0x4422EA, szCode, 20);
}
// OutputDebugString ( "Respawn!!!!" );
}
float CPedSA::GetHealth()
{
return GetPedInterface()->fHealth;
}
void CPedSA::SetHealth(float fHealth)
{
GetPedInterface()->fHealth = fHealth;
}
float CPedSA::GetArmor()
{
return GetPedInterface()->fArmor;
}
void CPedSA::SetArmor(float fArmor)
{
GetPedInterface()->fArmor = fArmor;
}
float CPedSA::GetOxygenLevel()
{
return GetPedInterface()->pPlayerData->m_fBreath;
}
void CPedSA::SetOxygenLevel(float fOxygen)
{
GetPedInterface()->pPlayerData->m_fBreath = fOxygen;
}
void CPedSA::SetIsStanding(bool bStanding)
{
DWORD dwFunc = FUNC_SetIsStanding;
DWORD dwThis = (DWORD)GetInterface();
_asm
{
mov ecx, dwThis
push bStanding
call dwFunc
}
}
DWORD CPedSA::GetType()
{
return m_dwType;
}
void CPedSA::SetType(DWORD dwType)
{
m_dwType = dwType;
}
void CPedSA::RemoveWeaponModel(int iModel)
{
DWORD dwFunc = FUNC_RemoveWeaponModel;
DWORD dwThis = (DWORD)GetInterface();
_asm
{
mov ecx, dwThis
push iModel
call dwFunc
}
}
void CPedSA::ClearWeapon(eWeaponType weaponType)
{
DWORD dwFunc = FUNC_ClearWeapon;
DWORD dwThis = (DWORD)GetInterface();
_asm
{
mov ecx, dwThis
push weaponType
call dwFunc
}
}
CWeapon* CPedSA::GiveWeapon(eWeaponType weaponType, unsigned int uiAmmo, eWeaponSkill skill)
{
if (weaponType != WEAPONTYPE_UNARMED)
{
CWeaponInfo* pInfo = pGame->GetWeaponInfo(weaponType, skill);
if (pInfo)
{
int iModel = pInfo->GetModel();
if (iModel)
{
CModelInfo* pWeaponModel = pGame->GetModelInfo(iModel);
if (pWeaponModel)
{
pWeaponModel->Request(BLOCKING, "CPedSA::GiveWeapon");
pWeaponModel->MakeCustomModel();
}
}
// If the weapon is satchels, load the detonator too
if (weaponType == WEAPONTYPE_REMOTE_SATCHEL_CHARGE)
{
/*int iModel = pGame->GetWeaponInfo ( WEAPONTYPE_DETONATOR )->GetModel();
if ( iModel )
{
CModelInfo * pWeaponModel = pGame->GetModelInfo ( iModel );
if ( pWeaponModel )
{
pWeaponModel->Request ( true, true );
}
}*/
// Load the weapon and give it properly so getPedWeapon shows the weapon is there.
GiveWeapon(WEAPONTYPE_DETONATOR, 1, WEAPONSKILL_STD);
}
}
}
DWORD dwReturn = 0;
DWORD dwFunc = FUNC_GiveWeapon;
DWORD dwThis = (DWORD)GetInterface();
_asm
{
mov ecx, dwThis
push 1
push uiAmmo
push weaponType
call dwFunc
mov dwReturn, eax
}
CWeapon* pWeapon = GetWeapon((eWeaponSlot)dwReturn);
return pWeapon;
}
CWeapon* CPedSA::GetWeapon(eWeaponType weaponType)
{
if (weaponType < WEAPONTYPE_LAST_WEAPONTYPE)
{
CWeapon* pWeapon = GetWeapon(pGame->GetWeaponInfo(weaponType)->GetSlot());
if (pWeapon->GetType() == weaponType)
return pWeapon;
}
return NULL;
}
CWeapon* CPedSA::GetWeapon(eWeaponSlot weaponSlot)
{
if (weaponSlot < WEAPONSLOT_MAX)
{
return m_pWeapons[weaponSlot];
}
else
return NULL;
}
void CPedSA::ClearWeapons()
{
// Remove all the weapons
for (unsigned int i = 0; i < WEAPONSLOT_MAX; i++)
{
if (m_pWeapons[i])
{
m_pWeapons[i]->SetAmmoInClip(0);
m_pWeapons[i]->SetAmmoTotal(0);
m_pWeapons[i]->Remove();
}
}
}
void CPedSA::RestoreLastGoodPhysicsState()
{
CPhysicalSA::RestoreLastGoodPhysicsState();
SetCurrentRotation(0);
SetTargetRotation(0);
}
float CPedSA::GetCurrentRotation()
{
return GetPedInterface()->fCurrentRotation;
}
float CPedSA::GetTargetRotation()
{
return GetPedInterface()->fTargetRotation;
}
void CPedSA::SetCurrentRotation(float fRotation)
{
GetPedInterface()->fCurrentRotation = fRotation;
// char szDebug[255] = {'\0'};
// sprintf(szDebug,"CurrentRotate Offset: %d", ((DWORD)&((CPedSAInterface *)GetInterface())->CurrentRotate) - (DWORD)GetInterface());
// OutputDebugString(szDebug);
}
void CPedSA::SetTargetRotation(float fRotation)
{
GetPedInterface()->fTargetRotation = fRotation;
}
eWeaponSlot CPedSA::GetCurrentWeaponSlot()
{
return (eWeaponSlot)GetPedInterface()->bCurrentWeaponSlot;
}
void CPedSA::SetCurrentWeaponSlot(eWeaponSlot weaponSlot)
{
if (weaponSlot < WEAPONSLOT_MAX)
{
eWeaponSlot currentSlot = GetCurrentWeaponSlot();
if (weaponSlot != GetCurrentWeaponSlot())
{
CWeapon* weapon = GetWeapon(currentSlot);
if (weapon)
{
CWeaponInfo* weaponInfo = weapon->GetInfo(WEAPONSKILL_STD);
if (weaponInfo)
RemoveWeaponModel(weaponInfo->GetModel());
}
CPedSAInterface* thisPed = (CPedSAInterface*)GetInterface();
// set the new weapon slot
thisPed->bCurrentWeaponSlot = weaponSlot;
// is the player the local player?
CPed* pPed = pGame->GetPools()->GetPedFromRef((DWORD)1);
// if ( pPed == this && thisPed->pPlayerInfo )
//{
DWORD dwThis = (DWORD)GetInterface();
if (pPed == this)
{
((CPlayerInfoSA*)pGame->GetPlayerInfo())->GetInterface()->PlayerPedData.m_nChosenWeapon = weaponSlot;
DWORD dwFunc = FUNC_MakeChangesForNewWeapon_Slot;
_asm
{
mov ecx, dwThis
push weaponSlot
call dwFunc
}
}
else
{
DWORD dwFunc = FUNC_SetCurrentWeapon;
_asm
{
mov ecx, dwThis
push weaponSlot
call dwFunc
}
}
}
}
}
CVector* CPedSA::GetBonePosition(eBone bone, CVector* vecPosition)
{
ApplySwimAndSlopeRotations();
CEntitySAInterface* entity = GetInterface();
// NOTE(botder): A crash used to occur at 0x749B7B in RpClumpForAllAtomics, because the clump pointer might have been null
// for a broken model.
if (entity->m_pRwObject != nullptr)
{
// void __thiscall CPed::GetBonePosition(struct RwV3d &, unsigned int, bool)
using Signature = void(__thiscall*)(CEntitySAInterface*, CVector*, unsigned int, bool);
const auto GameFunction = reinterpret_cast<Signature>(FUNC_GetBonePosition);
GameFunction(entity, vecPosition, bone, true);
}
// Clamp to a sane range as this function can occasionally return massive values,
// which causes ProcessLineOfSight to effectively freeze
if (!IsValidPosition(*vecPosition))
{
*vecPosition = *GetPosition();
}
return vecPosition;
}
CVector* CPedSA::GetTransformedBonePosition(eBone bone, CVector* vecPosition)
{
ApplySwimAndSlopeRotations();
CEntitySAInterface* entity = GetInterface();
// NOTE(botder): A crash used to occur at 0x7C51A8 in RpHAnimIDGetIndex, because the clump pointer might have been null
// for a broken model.
if (entity->m_pRwObject != nullptr)
{
// void __thiscall CPed::GetTransformedBonePosition(struct RwV3d &, unsigned int, bool)
using Signature = void(__thiscall*)(CEntitySAInterface*, CVector*, unsigned int, bool);
const auto GameFunction = reinterpret_cast<Signature>(FUNC_GetTransformedBonePosition);
GameFunction(entity, vecPosition, bone, true);
}
// Clamp to a sane range as this function can occasionally return massive values,
// which causes ProcessLineOfSight to effectively freeze
if (!IsValidPosition(*vecPosition))
{
*vecPosition = *GetPosition();
}
return vecPosition;
}
//
// Apply the extra ped rotations for slope pitch and swimming.
// Achieved by calling the code at the start of CPed::PreRenderAfterTest
//
void CPedSA::ApplySwimAndSlopeRotations()
{
CPedSAInterface* pPedInterface = GetPedInterface();
if (pPedInterface->pedFlags.bCalledPreRender)
return;
g_bOnlyUpdateRotations = true;
DWORD dwFunc = FUNC_PreRenderAfterTest;
_asm
{
mov ecx, pPedInterface
call dwFunc
}
g_bOnlyUpdateRotations = false;
}
bool CPedSA::IsDucking()
{
return ((CPedSAInterface*)GetInterface())->pedFlags.bIsDucking;
}
void CPedSA::SetDucking(bool bDuck)
{
((CPedSAInterface*)GetInterface())->pedFlags.bIsDucking = bDuck;
}
int CPedSA::GetCantBeKnockedOffBike()
{
return ((CPedSAInterface*)GetInterface())->pedFlags.CantBeKnockedOffBike;
}
void CPedSA::SetCantBeKnockedOffBike(int iCantBeKnockedOffBike)
{
((CPedSAInterface*)GetInterface())->pedFlags.CantBeKnockedOffBike = iCantBeKnockedOffBike;
}
void CPedSA::QuitEnteringCar(CVehicle* vehicle, int iSeat, bool bUnknown)
{
CVehicleSA* pVehicleSA = dynamic_cast<CVehicleSA*>(vehicle);
if (!pVehicleSA)
return;
DWORD dwFunc = FUNC_QuitEnteringCar;
DWORD dwThis = (DWORD)GetInterface();
DWORD dwVehicle = (DWORD)pVehicleSA->GetInterface();
_asm
{
push bUnknown
push iSeat
push dwVehicle
push dwThis
call dwFunc
add esp, 16
}
}
bool CPedSA::IsWearingGoggles()
{
DWORD dwFunc = FUNC_IsWearingGoggles;
DWORD dwThis = (DWORD)GetInterface();
bool bReturn = false;
_asm
{
mov ecx, dwThis
call dwFunc
mov bReturn, al
}
return bReturn;
}
void CPedSA::SetGogglesState(bool bIsWearingThem)
{
DWORD dwFunc = FUNC_TakeOffGoggles;
if (bIsWearingThem)
dwFunc = FUNC_PutOnGoggles;
DWORD dwThis = (DWORD)GetInterface();
_asm
{
mov ecx, dwThis
call dwFunc
}
}
void CPedSA::SetClothesTextureAndModel(const char* szTexture, const char* szModel, int textureType)
{
DWORD dwFunc = FUNC_CPedClothesDesc__SetTextureAndModel;
// DWORD dwThis = (DWORD)this->GetInterface()->PlayerPedData.m_pClothes;
DWORD dwThis = (DWORD)((CPedSAInterface*)GetInterface())->pPlayerData->m_pClothes;
_asm
{
mov ecx, dwThis
push textureType
push szModel
push szTexture
call dwFunc
}
}
void CPedSA::RebuildPlayer()
{
DWORD dwFunc = FUNC_CClothes__RebuildPlayer;
DWORD dwThis = (DWORD)GetInterface();
_asm
{
push 0
push dwThis
call dwFunc
add esp, 8
}
}
eFightingStyle CPedSA::GetFightingStyle()
{
return (eFightingStyle)((CPedSAInterface*)GetInterface())->bFightingStyle;
}
void CPedSA::SetFightingStyle(eFightingStyle style, BYTE bStyleExtra)
{
BYTE bStyle = (BYTE)style;
BYTE* pFightingStyle = &((CPedSAInterface*)GetInterface())->bFightingStyle;
BYTE* pFightingStyleExtra = &((CPedSAInterface*)GetInterface())->bFightingStyleExtra;
if (bStyle != *pFightingStyle)
{
*pFightingStyle = bStyle;
if (bStyleExtra > 0 && bStyleExtra <= 6)
{
bStyleExtra--;
BYTE bTemp = *pFightingStyleExtra;
switch (bStyleExtra)
{
case 0:
break;
case 1:
bTemp |= 1;
break;
case 2:
bTemp |= 2;
break;
case 3:
bTemp |= 4;
break;
case 4:
bTemp |= 8;
break;
case 5:
bTemp |= 16;
break;
}
*pFightingStyleExtra = bTemp;
}
}
}
CEntity* CPedSA::GetContactEntity()
{
CEntitySAInterface* pInterface = ((CPedSAInterface*)GetInterface())->pContactEntity;
if (pInterface)
{
CPools* pPools = pGame->GetPools();
switch (pInterface->nType)
{
case ENTITY_TYPE_VEHICLE:
{
SClientEntity<CVehicleSA>* pVehicleClientEntity = pPools->GetVehicle((DWORD*)pInterface);
if (pVehicleClientEntity)
{
return pVehicleClientEntity->pEntity;
}
break;
}
case ENTITY_TYPE_OBJECT:
{
SClientEntity<CObjectSA>* pObjectClientEntity = pPools->GetObject((DWORD*)pInterface);
if (pObjectClientEntity)
{
return pObjectClientEntity->pEntity;
}
break;
}
default:
{
break;
}
}
}
return nullptr;
}
unsigned char CPedSA::GetRunState()
{
return *(unsigned char*)(((DWORD)(GetInterface()) + 1332));
}
CEntity* CPedSA::GetTargetedEntity()
{
CEntitySAInterface* pInterface = ((CPedSAInterface*)GetInterface())->pTargetedEntity;
if (pInterface)
{
CPools* pPools = pGame->GetPools();
return pPools->GetEntity((DWORD*)pInterface);
}
return nullptr;
}
void CPedSA::SetTargetedEntity(CEntity* pEntity)
{
CEntitySAInterface* pInterface = NULL;
if (pEntity)
{
CEntitySA* pEntitySA = dynamic_cast<CEntitySA*>(pEntity);
if (pEntitySA)
pInterface = pEntitySA->GetInterface();
}
((CPedSAInterface*)GetInterface())->pTargetedEntity = pInterface;
}
bool CPedSA::GetCanBeShotInVehicle()
{
return GetPedInterface()->pedFlags.bCanBeShotInVehicle;
}
bool CPedSA::GetTestForShotInVehicle()
{
return GetPedInterface()->pedFlags.bTestForShotInVehicle;
}
void CPedSA::SetCanBeShotInVehicle(bool bShot)
{
GetPedInterface()->pedFlags.bCanBeShotInVehicle = bShot;
}
void CPedSA::SetTestForShotInVehicle(bool bTest)
{
GetPedInterface()->pedFlags.bTestForShotInVehicle = bTest;
}
void CPedSA::RemoveBodyPart(int i, char c)
{
DWORD dwThis = (DWORD)GetInterface();
DWORD dwFunc = FUNC_CPed_RemoveBodyPart;
_asm
{
mov ecx, dwThis
push c
push i
call dwFunc
}
}
void CPedSA::SetFootBlood(unsigned int uiFootBlood)
{
DWORD dwThis = (DWORD)GetInterface();
// Check if the ped is to have foot blood
if (uiFootBlood > 0)
{
// Make sure the foot blood flag is activated
MemOrFast<unsigned short>(dwThis + 0x46F, 16);
}
else if (*(unsigned short*)(dwThis + 0x46F) & 16)
{
// If the foot blood flag is activated, deactivate it
MemSubFast<unsigned short>(dwThis + 0x46F, 16);
}
// Set the amount of foot blood
MemPutFast<unsigned int>(dwThis + 0x750, uiFootBlood);
}
unsigned int CPedSA::GetFootBlood()
{
DWORD dwThis = (DWORD)GetInterface();
// Check if the ped has the foot blood flag
if (*(unsigned short*)(dwThis + 0x46F) & 16)
{
// If the foot blood flag is activated, return the amount of foot blood
return *(unsigned int*)(dwThis + 0x750);
}
// Otherwise, return zero as there is no foot blood
return 0;
}
bool CPedSA::IsBleeding()
{
return GetPedInterface()->pedFlags.bPedIsBleeding;
}
void CPedSA::SetBleeding(bool bBleeding)
{
GetPedInterface()->pedFlags.bPedIsBleeding = bBleeding;
}
bool CPedSA::IsOnFire()
{
if (GetPedInterface()->pFireOnPed != NULL)
return true;
return false;
}
void CPedSA::SetOnFire(bool bOnFire)
{
CPedSAInterface* pInterface = GetPedInterface();
if (bOnFire)
{
// If we are already on fire, don't apply a new fire
if (pInterface->pFireOnPed == NULL)
{
CFireManagerSA* pFireManager = static_cast<CFireManagerSA*>(pGame->GetFireManager());
CFire* pFire = pFireManager->StartFire(this, NULL, (float)DEFAULT_FIRE_PARTICLE_SIZE);
if (pFire)
{
// Start the fire
pFire->SetTarget(this);
pFire->Ignite();
pFire->SetStrength(1.0f);
// Attach the fire only to the player, do not let it
// create child fires when moving.
pFire->SetNumGenerationsAllowed(0);
pInterface->pFireOnPed = pFire->GetInterface();
}
}
}
else
{
// Make sure that we have some attached fire
if (pInterface->pFireOnPed != NULL)
{
CFireManagerSA* pFireManager = static_cast<CFireManagerSA*>(pGame->GetFireManager());
CFire* pFire = pFireManager->GetFire(static_cast<CFireSAInterface*>(pInterface->pFireOnPed));
if (pFire)
{
pFire->Extinguish();
}
}
}
}
void CPedSA::SetStayInSamePlace(bool bStay)
{
GetPedInterface()->pedFlags.bStayInSamePlace = bStay;
}
void CPedSA::GetVoice(short* psVoiceType, short* psVoiceID)
{
if (psVoiceType)
*psVoiceType = m_pPedSound->GetVoiceTypeID();
if (psVoiceID)
*psVoiceID = m_pPedSound->GetVoiceID();
}
void CPedSA::GetVoice(const char** pszVoiceType, const char** pszVoice)
{
short sVoiceType, sVoiceID;
GetVoice(&sVoiceType, &sVoiceID);
if (pszVoiceType)
*pszVoiceType = CPedSoundSA::GetVoiceTypeNameFromID(sVoiceType);
if (pszVoice)
*pszVoice = CPedSoundSA::GetVoiceNameFromID(sVoiceType, sVoiceID);
}
void CPedSA::SetVoice(short sVoiceType, short sVoiceID)
{
m_pPedSound->SetVoiceTypeID(sVoiceType);
m_pPedSound->SetVoiceID(sVoiceID);
}
void CPedSA::SetVoice(const char* szVoiceType, const char* szVoice)
{
short sVoiceType = CPedSoundSA::GetVoiceTypeIDFromName(szVoiceType);
if (sVoiceType < 0)
return;
short sVoiceID = CPedSoundSA::GetVoiceIDFromName(sVoiceType, szVoice);
if (sVoiceID < 0)
return;
SetVoice(sVoiceType, sVoiceID);
}
void CPedSA::ResetVoice()
{
SetVoice(m_pDefaultPedSound->GetVoiceTypeID(), m_pDefaultPedSound->GetVoiceID());
}
// GetCurrentWeaponStat will only work if the game ped context is currently set to this ped
CWeaponStat* CPedSA::GetCurrentWeaponStat()
{
if (pGame->GetPedContext() != this)
{
OutputDebugLine("WARNING: GetCurrentWeaponStat ped context mismatch");
return NULL;
}
CWeapon* pWeapon = GetWeapon(GetCurrentWeaponSlot());
if (!pWeapon)
return NULL;
eWeaponType eWeapon = pWeapon->GetType();
ushort usStat = pGame->GetStats()->GetSkillStatIndex(eWeapon);
float fSkill = pGame->GetStats()->GetStatValue(usStat);
CWeaponStat* pWeaponStat = pGame->GetWeaponStatManager()->GetWeaponStatsFromSkillLevel(eWeapon, fSkill);
return pWeaponStat;
}
float CPedSA::GetCurrentWeaponRange()
{
CWeaponStat* pWeaponStat = GetCurrentWeaponStat();
if (!pWeaponStat)
return 1;
return pWeaponStat->GetWeaponRange();
}
void CPedSA::AddWeaponAudioEvent(EPedWeaponAudioEventType audioEventType)
{
DWORD dwFunc = FUNC_CAEPedWeaponAudioEntity__AddAudioEvent;
CPedWeaponAudioEntitySAInterface* pThis = &GetPedInterface()->weaponAudioEntity;
_asm
{
mov ecx, pThis
push audioEventType
call dwFunc
}
}