From 21d6ed5cc317cf2e3a656dbd4326a4f6b8a4315a Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 18 May 2019 11:06:17 +0200 Subject: [PATCH] Account for SA-MP patches for GetWeaponSkill in RenderWeaponPedsForPC --- SilentPatchSA/PedSA.cpp | 11 +++++++++-- SilentPatchSA/PedSA.h | 11 ++++++++++- SilentPatchSA/SilentPatchSA.cpp | 5 +++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/SilentPatchSA/PedSA.cpp b/SilentPatchSA/PedSA.cpp index af6362b..f35a5a9 100644 --- a/SilentPatchSA/PedSA.cpp +++ b/SilentPatchSA/PedSA.cpp @@ -3,7 +3,7 @@ #include "VehicleSA.h" static void* varGetWeaponSkill = AddressByVersion(0x5E6580, 0x5E6DA0, 0x6039F0); -WRAPPER unsigned char CPed::GetWeaponSkill() { VARJMP(varGetWeaponSkill); } +WRAPPER uint8_t CPed::GetWeaponSkill() { VARJMP(varGetWeaponSkill); } static void* varSetGunFlashAlpha = AddressByVersion(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 ); +} \ No newline at end of file diff --git a/SilentPatchSA/PedSA.h b/SilentPatchSA/PedSA.h index bf8b05b..4928988 100644 --- a/SilentPatchSA/PedSA.h +++ b/SilentPatchSA/PedSA.h @@ -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 void Say_SampleBlackList(uint16_t phrase, uint32_t param2 = 0, float volume = 1.0f, bool param4 = false, bool param5 = false, bool param6 = false) { diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 469ed27..075eaa1 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -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); }