Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Fix impossible bullets
  • Loading branch information
erorcun committed Aug 15, 2021
1 parent 4a5f746 commit 4d2a02c9fa6ad797787040db40981905ae571135
Showing with 69 additions and 11 deletions.
  1. +4 −0 src/peds/PlayerPed.cpp
  2. +5 −0 src/peds/PlayerPed.h
  3. +60 −11 src/weapons/Weapon.cpp
@@ -1342,6 +1342,10 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed)
if ((padUsed->GetTarget() && CAN_AIM_WITH_ARM) || padUsed->GetWeapon()) { if ((padUsed->GetTarget() && CAN_AIM_WITH_ARM) || padUsed->GetWeapon()) {
float limitedCam = CGeneral::LimitRadianAngle(-TheCamera.Orientation); float limitedCam = CGeneral::LimitRadianAngle(-TheCamera.Orientation);


m_cachedCamSource = TheCamera.Cams[TheCamera.ActiveCam].Source;
m_cachedCamFront = TheCamera.Cams[TheCamera.ActiveCam].Front;
m_cachedCamUp = TheCamera.Cams[TheCamera.ActiveCam].Up;

// On this one we can rotate arm. // On this one we can rotate arm.
if (CAN_AIM_WITH_ARM) { if (CAN_AIM_WITH_ARM) {
if (!padUsed->GetWeapon()) { // making this State != ATTACK still stops it after attack. Re-start it immediately! if (!padUsed->GetWeapon()) { // making this State != ATTACK still stops it after attack. Re-start it immediately!
@@ -44,6 +44,11 @@ class CPlayerPed : public CPed
float m_fGunSpinAngle; float m_fGunSpinAngle;
unsigned int m_nPadDownPressedInMilliseconds; unsigned int m_nPadDownPressedInMilliseconds;
unsigned int m_nLastBusFareCollected; unsigned int m_nLastBusFareCollected;
#ifdef FREE_CAM
CVector m_cachedCamSource;
CVector m_cachedCamFront;
CVector m_cachedCamUp;
#endif


static bool bDontAllowWeaponChange; static bool bDontAllowWeaponChange;
#ifndef MASTER #ifndef MASTER
@@ -49,6 +49,29 @@ bool CWeapon::bPhotographHasBeenTaken;
int32 sniperPirateCheck = 0x00797743; // 'Cwy\0' ??? int32 sniperPirateCheck = 0x00797743; // 'Cwy\0' ???
#endif #endif


#ifdef FREE_CAM
static bool
Find3rdPersonCamTargetVectorFromCachedVectors(float dist, CVector pos, CVector& source, CVector& target, CVector camSource, CVector camFront, CVector camUp)
{
if (CPad::GetPad(0)->GetLookBehindForPed()) {
source = pos;
target = dist * FindPlayerPed()->GetForward() + source;
return false;
} else {
float angleX = DEGTORAD((CCamera::m_f3rdPersonCHairMultX - 0.5f) * 1.8f * 0.5f * TheCamera.Cams[TheCamera.ActiveCam].FOV * CDraw::GetAspectRatio());
float angleY = DEGTORAD((0.5f - CCamera::m_f3rdPersonCHairMultY) * 1.8f * 0.5f * TheCamera.Cams[TheCamera.ActiveCam].FOV);
source = camSource;
target = camFront;
target += camUp * Tan(angleY);
target += CrossProduct(camFront, camUp) * Tan(angleX);
target.Normalise();
source += DotProduct(pos - source, target) * target;
target = dist * target + source;
return true;
}
}
#endif

CWeaponInfo * CWeaponInfo *
CWeapon::GetInfo() CWeapon::GetInfo()
{ {
@@ -943,17 +966,23 @@ CWeapon::FireInstantHit(CEntity *shooter, CVector *fireSource)
} }
else if ( shooter == FindPlayerPed() && TheCamera.Cams[0].Using3rdPersonMouseCam() ) else if ( shooter == FindPlayerPed() && TheCamera.Cams[0].Using3rdPersonMouseCam() )
{ {
TheCamera.Find3rdPersonCamTargetVector(info->m_fRange, *fireSource, source, target);
#ifdef FREE_CAM #ifdef FREE_CAM
CPed *shooterPed = (CPed *)shooter; if (CCamera::bFreeCam) {
if((shooterPed->m_pedIK.m_flags & CPedIK::GUN_POINTED_SUCCESSFULLY) == 0) { CPlayerPed* shooterPed = (CPlayerPed*)shooter;
target.x = info->m_fRange; Find3rdPersonCamTargetVectorFromCachedVectors(info->m_fRange, *fireSource, source, target, shooterPed->m_cachedCamSource, shooterPed->m_cachedCamFront, shooterPed->m_cachedCamUp);
target.y = 0.0f;
target.z = 0.0f;


shooterPed->TransformToNode(target, PED_HANDR); if ((shooterPed->m_pedIK.m_flags & CPedIK::GUN_POINTED_SUCCESSFULLY) == 0) {
} target.x = info->m_fRange;
target.y = 0.0f;
target.z = 0.0f;

shooterPed->TransformToNode(target, PED_HANDR);
}
} else
#endif #endif
{
TheCamera.Find3rdPersonCamTargetVector(info->m_fRange, *fireSource, source, target);
}


#ifdef FIX_BUGS #ifdef FIX_BUGS
// fix muzzleflash rotation // fix muzzleflash rotation
@@ -1708,8 +1737,19 @@ CWeapon::FireShotgun(CEntity *shooter, CVector *fireSource)


if ( shooter == FindPlayerPed() && TheCamera.Cams[0].Using3rdPersonMouseCam() ) if ( shooter == FindPlayerPed() && TheCamera.Cams[0].Using3rdPersonMouseCam() )
{ {
TheCamera.Find3rdPersonCamTargetVector(1.0f, *fireSource, source, target); CVector Left;
CVector Left = CrossProduct(TheCamera.Cams[TheCamera.ActiveCam].Front, TheCamera.Cams[TheCamera.ActiveCam].Up); #ifdef FREE_CAM
if (CCamera::bFreeCam) {
CPlayerPed* shooterPed = (CPlayerPed*)shooter;
Find3rdPersonCamTargetVectorFromCachedVectors(1.0f, *fireSource, source, target, shooterPed->m_cachedCamSource, shooterPed->m_cachedCamFront, shooterPed->m_cachedCamUp);
Left = CrossProduct(shooterPed->m_cachedCamFront, shooterPed->m_cachedCamUp);
}
else
#endif
{
TheCamera.Find3rdPersonCamTargetVector(1.0f, *fireSource, source, target);
Left = CrossProduct(TheCamera.Cams[TheCamera.ActiveCam].Front, TheCamera.Cams[TheCamera.ActiveCam].Up);
}


float f = (i - (shootsAtOnce / 2)) * angleBetweenTwoShot; float f = (i - (shootsAtOnce / 2)) * angleBetweenTwoShot;
target = f * Left + target - source; target = f * Left + target - source;
@@ -2151,7 +2191,16 @@ CWeapon::FireAreaEffect(CEntity *shooter, CVector *fireSource)


if ( shooter == FindPlayerPed() && TheCamera.Cams[0].Using3rdPersonMouseCam() ) if ( shooter == FindPlayerPed() && TheCamera.Cams[0].Using3rdPersonMouseCam() )
{ {
TheCamera.Find3rdPersonCamTargetVector(info->m_fRange, *fireSource, source, target); #ifdef FREE_CAM
if (CCamera::bFreeCam) {
CPlayerPed* shooterPed = (CPlayerPed*)shooter;
Find3rdPersonCamTargetVectorFromCachedVectors(info->m_fRange, *fireSource, source, target, shooterPed->m_cachedCamSource, shooterPed->m_cachedCamFront, shooterPed->m_cachedCamUp);
}
else
#endif
{
TheCamera.Find3rdPersonCamTargetVector(info->m_fRange, *fireSource, source, target);
}
float norm = (1.0f / info->m_fRange); float norm = (1.0f / info->m_fRange);
dir = (target - source) * norm; dir = (target - source) * norm;
} }

0 comments on commit 4d2a02c

Please sign in to comment.