Account for SA-MP patches for GetWeaponSkill in RenderWeaponPedsForPC

This commit is contained in:
Silent 2019-05-18 11:06:17 +02:00
parent 7ce4c99cb9
commit 21d6ed5cc3
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
3 changed files with 24 additions and 3 deletions

View File

@ -3,7 +3,7 @@
#include "VehicleSA.h"
static void* varGetWeaponSkill = AddressByVersion<void*>(0x5E6580, 0x5E6DA0, 0x6039F0);
WRAPPER unsigned char CPed::GetWeaponSkill() { VARJMP(varGetWeaponSkill); }
WRAPPER uint8_t CPed::GetWeaponSkill() { VARJMP(varGetWeaponSkill); }
static void* varSetGunFlashAlpha = AddressByVersion<void*>(0x5DF400, 0x5DFC20, 0x5FC120);
WRAPPER void CPed::SetGunFlashAlpha(bool bSecondWeapon) { WRAPARG(bSecondWeapon); VARJMP(varSetGunFlashAlpha); }
@ -81,7 +81,7 @@ void CPed::RenderWeapon(bool bWeapon, bool bMuzzleFlash, bool bForShadow)
}
// Dual weapons
if ( CWeaponInfo::GetWeaponInfo(weaponSlots[m_bActiveWeapon].m_eWeaponType, GetWeaponSkill())->hexFlags >> 11 & 1 )
if ( CWeaponInfo::GetWeaponInfo(weaponSlots[m_bActiveWeapon].m_eWeaponType, GetWeaponSkillForRenderWeaponPedsForPC())->hexFlags >> 11 & 1 )
{
*RwFrameGetMatrix(pFrame) = RpHAnimHierarchyGetMatrixArray(pAnimHierarchy)[RpHAnimIDGetIndex(pAnimHierarchy, 34)];
@ -132,3 +132,10 @@ void CPed::GiveWeapon_SP(uint32_t weapon, uint32_t ammo, bool flag)
if ( ammo == 0 ) ammo = 1;
(this->*(orgGiveWeapon))( weapon, ammo, flag );
}
uint8_t CPed::GetWeaponSkillForRenderWeaponPedsForPC_SAMP()
{
uint8_t (CPed::*funcCall)();
Memory::ReadCall( 0x7330A2, funcCall );
return std::invoke( funcCall, this );
}

View File

@ -309,7 +309,7 @@ public:
bool IsPlayer() const
{ return pedType == 0 || pedType == 1; }
unsigned char GetWeaponSkill();
uint8_t GetWeaponSkill();
void ResetGunFlashAlpha();
void SetGunFlashAlpha(bool bSecondWeapon);
void Say(uint16_t phrase, uint32_t param2 = 0, float volume = 1.0f, bool param4 = false, bool param5 = false, bool param6 = false);
@ -320,6 +320,15 @@ public:
static void (CPed::*orgGiveWeapon)(uint32_t weapon, uint32_t ammo, bool flag);
void GiveWeapon_SP( uint32_t weapon, uint32_t ammo, bool flag );
// Extension to accommodate for SA-MP hooking GetWeaponSkill in RenderWeaponPedsForPC dynamically
static inline uint8_t (CPed::*orgGetWeaponSkillForRenderWeaponPedsForPC)() = &GetWeaponSkill;
uint8_t GetWeaponSkillForRenderWeaponPedsForPC()
{
return std::invoke( orgGetWeaponSkillForRenderWeaponPedsForPC, this );
}
uint8_t GetWeaponSkillForRenderWeaponPedsForPC_SAMP();
template<uint16_t blackSample>
void Say_SampleBlackList(uint16_t phrase, uint32_t param2 = 0, float volume = 1.0f, bool param4 = false, bool param5 = false, bool param6 = false)
{

View File

@ -2588,6 +2588,11 @@ BOOL InjectDelayedPatches_10()
// Weapons rendering
if ( !bOutfit )
{
if ( bSAMP )
{
CPed::orgGetWeaponSkillForRenderWeaponPedsForPC = &CPed::GetWeaponSkillForRenderWeaponPedsForPC_SAMP;
}
InjectHook(0x5E7859, RenderWeapon);
InjectHook(0x732F30, RenderWeaponPedsForPC, PATCH_JUMP);
}