2019-05-29 16:06:33 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "patcher.h"
|
|
|
|
#include "Weapon.h"
|
2019-06-30 21:50:40 +00:00
|
|
|
#include "Timer.h"
|
|
|
|
#include "WeaponInfo.h"
|
2019-07-25 15:06:24 +00:00
|
|
|
#include "Ped.h"
|
|
|
|
#include "World.h"
|
2019-05-29 16:06:33 +00:00
|
|
|
|
2020-03-28 20:55:23 +00:00
|
|
|
WRAPPER void CWeapon::ShutdownWeapons(void) { EAXJMP(0x55C2F0); }
|
2019-10-18 22:23:40 +00:00
|
|
|
WRAPPER void CWeapon::UpdateWeapons(void) { EAXJMP(0x55C310); }
|
2019-06-20 11:22:44 +00:00
|
|
|
WRAPPER bool CWeapon::Fire(CEntity*, CVector*) { EAXJMP(0x55C380); }
|
2019-07-23 14:39:30 +00:00
|
|
|
WRAPPER void CWeapon::FireFromCar(CAutomobile *car, bool left) { EAXJMP(0x55C940); }
|
2019-06-30 21:50:40 +00:00
|
|
|
WRAPPER void CWeapon::AddGunshell(CEntity*, CVector const&, CVector2D const&, float) { EAXJMP(0x55F770); }
|
2019-07-23 14:39:30 +00:00
|
|
|
WRAPPER void CWeapon::Update(int32 audioEntity) { EAXJMP(0x563A10); }
|
2019-07-25 14:33:37 +00:00
|
|
|
WRAPPER void CWeapon::DoTankDoomAiming(CEntity *playerVehicle, CEntity *playerPed, CVector *start, CVector *end) { EAXJMP(0x563200); }
|
2019-08-15 14:51:39 +00:00
|
|
|
WRAPPER void CWeapon::InitialiseWeapons(void) { EAXJMP(0x55C2D0); }
|
2020-03-31 22:58:40 +00:00
|
|
|
WRAPPER void FireOneInstantHitRound(CVector* shotSource, CVector* shotTarget, int32 damage) { EAXJMP(0x563B00); }
|
2019-06-30 21:50:40 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
CWeapon::Initialise(eWeaponType type, int ammo)
|
|
|
|
{
|
|
|
|
m_eWeaponType = type;
|
|
|
|
m_eWeaponState = WEAPONSTATE_READY;
|
|
|
|
if (ammo > 99999)
|
|
|
|
m_nAmmoTotal = 99999;
|
|
|
|
else
|
|
|
|
m_nAmmoTotal = ammo;
|
|
|
|
m_nAmmoInClip = 0;
|
|
|
|
Reload();
|
|
|
|
m_nTimer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CWeapon::Reload(void)
|
|
|
|
{
|
|
|
|
if (m_nAmmoTotal == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CWeaponInfo *info = CWeaponInfo::GetWeaponInfo(m_eWeaponType);
|
|
|
|
|
|
|
|
if (m_nAmmoTotal >= info->m_nAmountofAmmunition)
|
|
|
|
m_nAmmoInClip = info->m_nAmountofAmmunition;
|
|
|
|
else
|
|
|
|
m_nAmmoInClip = m_nAmmoTotal;
|
|
|
|
}
|
|
|
|
|
2019-07-15 12:11:40 +00:00
|
|
|
bool
|
|
|
|
CWeapon::IsType2Handed(void)
|
|
|
|
{
|
2020-01-07 14:23:09 +00:00
|
|
|
return m_eWeaponType >= WEAPONTYPE_SHOTGUN && m_eWeaponType <= WEAPONTYPE_FLAMETHROWER && m_eWeaponType != WEAPONTYPE_ROCKETLAUNCHER;
|
2019-07-15 12:11:40 +00:00
|
|
|
}
|
|
|
|
|
2019-07-05 22:44:49 +00:00
|
|
|
bool
|
|
|
|
CWeapon::IsTypeMelee(void)
|
|
|
|
{
|
|
|
|
return m_eWeaponType == WEAPONTYPE_UNARMED || m_eWeaponType == WEAPONTYPE_BASEBALLBAT;
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:06:24 +00:00
|
|
|
bool
|
|
|
|
CWeapon::HitsGround(CEntity *holder, CVector *firePos, CEntity *aimingTo)
|
|
|
|
{
|
|
|
|
if (!holder->IsPed() || !((CPed*)holder)->m_pSeekTarget)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
CWeaponInfo *ourType = CWeaponInfo::GetWeaponInfo(m_eWeaponType);
|
|
|
|
CVector adjustedOffset = ourType->m_vecFireOffset;
|
|
|
|
adjustedOffset.z += 0.6f;
|
|
|
|
|
|
|
|
CVector point1, point2;
|
|
|
|
CEntity *foundEnt = nil;
|
|
|
|
CColPoint foundCol;
|
|
|
|
|
|
|
|
if (firePos)
|
|
|
|
point1 = *firePos;
|
|
|
|
else
|
|
|
|
point1 = holder->GetMatrix() * adjustedOffset;
|
|
|
|
|
|
|
|
CEntity *aimEntity = aimingTo ? aimingTo : ((CPed*)holder)->m_pSeekTarget;
|
|
|
|
point2 = aimEntity->GetPosition();
|
|
|
|
point2.z += 0.6f;
|
|
|
|
|
|
|
|
CWorld::ProcessLineOfSight(point1, point2, foundCol, foundEnt, true, false, false, false, false, false, false);
|
|
|
|
if (foundEnt && foundEnt->IsBuilding()) {
|
|
|
|
// That was supposed to be Magnitude, according to leftover code in assembly
|
|
|
|
float diff = (foundCol.point.z - point1.z);
|
|
|
|
if (diff < 0.0f && diff > -3.0f)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-07 14:23:09 +00:00
|
|
|
bool
|
|
|
|
CWeapon::HasWeaponAmmoToBeUsed(void)
|
|
|
|
{
|
|
|
|
switch (m_eWeaponType) {
|
|
|
|
case WEAPONTYPE_UNARMED:
|
|
|
|
case WEAPONTYPE_BASEBALLBAT:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return m_nAmmoTotal != 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-30 21:50:40 +00:00
|
|
|
STARTPATCHES
|
|
|
|
InjectHook(0x55C330, &CWeapon::Initialise, PATCH_JUMP);
|
|
|
|
InjectHook(0x5639D0, &CWeapon::Reload, PATCH_JUMP);
|
2019-07-25 15:06:24 +00:00
|
|
|
InjectHook(0x564890, &CWeapon::HitsGround, PATCH_JUMP);
|
2020-01-07 14:23:09 +00:00
|
|
|
ENDPATCHES
|