diff --git a/SilentPatchSA/PedSA.h b/SilentPatchSA/PedSA.h index cd37aa6..69869c3 100644 --- a/SilentPatchSA/PedSA.h +++ b/SilentPatchSA/PedSA.h @@ -314,6 +314,15 @@ public: void RenderForShadow(); }; +class NOVMT CPlayerPed : public CPed +{ +private: + CPed* m_pMouseLockOnRecruitPed; + int m_iMouseLockOnRecruitTimer; +}; + static_assert(sizeof(CPed) == 0x79C, "Wrong size: CPed"); +static_assert(sizeof(CPlayerPed) == 0x7A4, "Wrong size: CPlayerPed"); + #endif \ No newline at end of file diff --git a/SilentPatchSA/PlayerInfoSA.cpp b/SilentPatchSA/PlayerInfoSA.cpp new file mode 100644 index 0000000..1b7dc79 --- /dev/null +++ b/SilentPatchSA/PlayerInfoSA.cpp @@ -0,0 +1,40 @@ +#include "StdAfxSA.h" +#include "PlayerInfoSA.h" + +uint8_t& PlayerInFocus = **AddressByVersion( 0x56E218 + 3, 0, 0 ); // TODO: DO +CPlayerInfo* const Players = *AddressByVersion( 0x56E225 + 2, 0, 0 ); + +CPlayerPed* FindPlayerPed( int playerID ) +{ + return Players[ playerID < 0 ? PlayerInFocus : playerID ].GetPlayerPed(); +} + +CEntity* FindPlayerEntityWithRC( int playerID ) +{ + CPlayerInfo* player = &Players[ playerID < 0 ? PlayerInFocus : playerID ]; + + CPlayerPed* ped = player->GetPlayerPed(); + CVehicle* remoteVehicle = player->GetControlledVehicle(); + if ( remoteVehicle != nullptr ) return remoteVehicle; + if ( ped->GetPedFlags().bInVehicle ) + { + CVehicle* normalVehicle = ped->GetVehiclePtr(); + if ( normalVehicle != nullptr ) return normalVehicle; + } + return ped; +} + +CVehicle* FindPlayerVehicle( int playerID, bool withRC ) +{ + CPlayerInfo* player = &Players[ playerID < 0 ? PlayerInFocus : playerID ]; + + CPlayerPed* ped = player->GetPlayerPed(); + if ( ped == nullptr ) return nullptr; + if ( !ped->GetPedFlags().bInVehicle ) return nullptr; + CVehicle* vehicle = player->GetControlledVehicle(); + if ( !withRC || vehicle == nullptr ) + { + vehicle = ped->GetVehiclePtr(); + } + return vehicle; +} \ No newline at end of file diff --git a/SilentPatchSA/PlayerInfoSA.h b/SilentPatchSA/PlayerInfoSA.h new file mode 100644 index 0000000..dc1fb4a --- /dev/null +++ b/SilentPatchSA/PlayerInfoSA.h @@ -0,0 +1,23 @@ +#pragma once + +#include "PedSA.h" +#include "VehicleSA.h" + +class CPlayerInfo +{ +private: + CPlayerPed* m_pPed; + uint8_t __pad2[0xAC]; + CVehicle* m_pControlledVehicle; + uint8_t __pad[0xDC]; + +public: + CPlayerPed* GetPlayerPed() const { return m_pPed; } + CVehicle* GetControlledVehicle() const { return m_pControlledVehicle; } +}; + +CPlayerPed* FindPlayerPed( int playerID = -1 ); +CEntity* FindPlayerEntityWithRC( int playerID = -1 ); +CVehicle* FindPlayerVehicle( int playerID = -1, bool withRC = false ); + +static_assert(sizeof(CPlayerInfo) == 0x190, "Wrong size: CPlayerInfo"); \ No newline at end of file diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index b574482..9c05475 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -14,6 +14,7 @@ #include "AudioHardwareSA.h" #include "LinkListSA.h" #include "PNGFile.h" +#include "PlayerInfoSA.h" #include "WaveDecoderSA.h" #include "FLACDecoderSA.h" @@ -1335,6 +1336,11 @@ namespace FakeQPC } } +static CVehicle* FindPlayerVehicle_RCWrap( int playerID, bool ) +{ + return FindPlayerVehicle( playerID, true ); +} + #endif #if MEM_VALIDATORS @@ -3407,6 +3413,11 @@ void Patch_SA_10() // unnamed CdStream semaphore Patch( 0x406945, { 0x6A, 0x00 } ); // push 0 \ nop Nop( 0x406945 + 2, 3 ); + + + // Correct streaming when using RC vehicles + InjectHook( 0x55574B, FindPlayerEntityWithRC ); + InjectHook( 0x5557C3, FindPlayerVehicle_RCWrap ); } void Patch_SA_11() diff --git a/SilentPatchSA/SilentPatchSA.vcxproj b/SilentPatchSA/SilentPatchSA.vcxproj index 31e5b8b..a832cf6 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj +++ b/SilentPatchSA/SilentPatchSA.vcxproj @@ -198,6 +198,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio + @@ -232,6 +233,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio + diff --git a/SilentPatchSA/SilentPatchSA.vcxproj.filters b/SilentPatchSA/SilentPatchSA.vcxproj.filters index 52c8ac6..6d3dbfb 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj.filters +++ b/SilentPatchSA/SilentPatchSA.vcxproj.filters @@ -66,6 +66,9 @@ Source Files + + Source Files + @@ -155,6 +158,9 @@ Header Files + + Header Files + diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp index 01ce4d7..c7f3dbc 100644 --- a/SilentPatchSA/VehicleSA.cpp +++ b/SilentPatchSA/VehicleSA.cpp @@ -7,6 +7,7 @@ #include "TimerSA.h" #include "PedSA.h" #include "DelimStringReader.h" +#include "PlayerInfoSA.h" static constexpr float PHOENIX_FLUTTER_PERIOD = 70.0f; static constexpr float PHOENIX_FLUTTER_AMP = 0.13f; @@ -28,8 +29,6 @@ WRAPPER void CVehicle::Render() { VARJMP(varVehicleRender); } static void* varIsLawEnforcementVehicle = AddressByVersion(0x6D2370, 0x6D2BA0, 0x70D8C0); WRAPPER bool CVehicle::IsLawEnforcementVehicle() { VARJMP(varIsLawEnforcementVehicle); } -auto FindPlayerPed = AddressByVersion( 0x56E210, 0, 0 ); // TODO: DO - void (CVehicle::*CVehicle::orgVehiclePreRender)(); void (CAutomobile::*CAutomobile::orgAutomobilePreRender)(); void (CPlane::*CPlane::orgPlanePreRender)(); @@ -472,7 +471,7 @@ CVehicle* CStoredCar::RestoreCar_SilentPatch() if ( vehicle->GetClass() == VEHICLE_AUTOMOBILE || vehicle->GetClass() == VEHICLE_BIKE ) { vehicle->SetBombOnBoard( m_bombType ); - vehicle->SetBombOwner( FindPlayerPed(-1) ); + vehicle->SetBombOwner( FindPlayerPed() ); } }