295 lines
10 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GTA;
2022-06-17 11:08:49 +08:00
using GTA.Native;
using GTA.Math;
namespace RageCoop.Client
{
internal class MuzzleInfo
{
public MuzzleInfo(Vector3 pos,Vector3 forward)
{
Position = pos;
ForawardVector=forward;
}
public Vector3 Position;
public Vector3 ForawardVector;
}
internal static class WeaponUtil
{
public static Vector3 GetMuzzlePosition(this Ped p)
{
var w = p.Weapons.CurrentWeaponObject;
if (w!=null)
{
var hash = p.Weapons.Current.Hash;
if (MuzzleBoneIndexes.ContainsKey(hash)) { return w.Bones[MuzzleBoneIndexes[hash]].Position; }
return w.Position;
}
return p.Bones[Bone.SkelRightHand].Position;
}
2022-06-02 13:52:18 +08:00
static long BulletsShot=0;
2022-06-17 11:08:49 +08:00
public static float GetWeaponDamage(this Ped P, uint hash)
{
var comp = P.Weapons.Current.Components.GetSuppressorComponent();
return Function.Call<float>(Hash.GET_WEAPON_DAMAGE, hash, comp.Active ? comp.ComponentHash : WeaponComponentHash.Invalid);
/*
if (P.IsInVehicle() && (hash!=(uint)P.Weapons.Current.Hash))
{
// This is a vehicle weapon
P.VehicleWeapon=(VehicleWeaponHash)hash;
return 100;
}
switch (P.Weapons.Current.Group)
{
case WeaponGroup.Pistol: return 30;
case WeaponGroup.AssaultRifle: return 30;
case WeaponGroup.SMG: return 20;
case WeaponGroup.MG: return 40;
case WeaponGroup.Shotgun: return 30;
case WeaponGroup.Sniper: return 200;
case WeaponGroup.Heavy: return 30;
}
return 0;
*/
}
public static MuzzleInfo GetMuzzleInfo(this Vehicle v)
{
2022-06-02 13:52:18 +08:00
BulletsShot++;
int i;
switch (v.Model.Hash)
{
// JB7002
case 394110044:
i=BulletsShot%2==0 ? 54 : 53;
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
// DOMINATOR5
case -1375060657:
i=BulletsShot%2==0 ? 35 : 36;
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
// IMPALER3
case -1924800695:
i=BulletsShot%2==0 ? 75 : 76;
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
// IMPERATOR2
case 1637620610:
i=BulletsShot%2==0 ? 97 : 99;
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
// SLAMVAN5
case 373261600:
i=BulletsShot%2==0 ? 51 : 53;
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
2022-07-02 13:21:55 +08:00
// RUINER2
case 941494461:
i=BulletsShot%2==0 ? 65 : 66;
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
2022-07-02 13:12:59 +08:00
// TAMPA3
case -1210451983:
return new MuzzleInfo(v.Bones[87].Position, v.Bones[87].ForwardVector);
2022-06-02 09:27:39 +08:00
// SCRAMJET
case -638562243:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 44 : 45;
2022-06-02 09:27:39 +08:00
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
2022-06-02 09:26:53 +08:00
// VIGILANTE
case -1242608589:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 42 : 43;
2022-06-02 09:26:53 +08:00
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
2022-06-02 09:25:23 +08:00
// ZR380
case 540101442:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 57 : 63;
2022-06-02 09:25:23 +08:00
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
2022-06-02 09:24:37 +08:00
// ZR3802
case -1106120762:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 57 : 63;
2022-06-02 09:24:37 +08:00
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
2022-06-02 09:23:44 +08:00
// ZR3803
case -1478704292:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 53 : 59;
2022-06-02 09:23:44 +08:00
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
2022-06-02 09:21:46 +08:00
// STROMBERG
case 886810209:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 85 : 84;
2022-06-02 09:21:46 +08:00
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
2022-06-02 09:17:19 +08:00
// SLAMVAN4
case -2061049099:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 76 : 78;
2022-06-02 09:17:19 +08:00
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
// IMPERATOR
case 444994115:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 88 : 86;
2022-06-02 09:17:19 +08:00
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
// IMPALER2
case 1009171724:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 63 : 64;
2022-06-02 09:17:19 +08:00
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
// DOMINATOR4
case -688189648:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 59 : 60;
2022-06-02 09:17:19 +08:00
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
2022-06-02 09:15:18 +08:00
// SAVAGE
case -82626025:
return new MuzzleInfo(v.Bones[30].Position, v.Bones[30].ForwardVector);
// BUZZARD
case 788747387:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 28 : 23;
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
// ANNIHL
case 837858166:
2022-06-02 13:52:18 +08:00
i=(int)BulletsShot%4+35;
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
// HYDRA
case 970385471:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 29 : 28;
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
// STARLING
case -1700874274:
2022-06-02 13:52:18 +08:00
i=BulletsShot%2==0 ? 24 : 12;
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].ForwardVector);
// RHINO
case 782665360:
return new MuzzleInfo(v.Bones[35].Position,v.Bones[35].ForwardVector);
default:
return null;
}
}
public static bool IsUsingProjectileWeapon(this Ped p)
{
var vp = p.VehicleWeapon;
if (vp!=VehicleWeaponHash.Invalid)
{
return VehicleProjectileWeapons.Contains(vp);
}
else
{
var w = p.Weapons.Current;
return w.Group==WeaponGroup.Thrown || ProjectileWeapons.Contains(w.Hash);
}
}
2022-06-02 13:52:18 +08:00
public static readonly Dictionary<WeaponHash, int> MuzzleBoneIndexes = new Dictionary<WeaponHash, int>
{
{WeaponHash.HeavySniper,6},
{WeaponHash.MarksmanRifle,9},
{WeaponHash.SniperRifle,9},
{WeaponHash.AdvancedRifle,5},
{WeaponHash.SpecialCarbine,9},
{WeaponHash.BullpupRifle,7},
{WeaponHash.AssaultRifle,9},
{WeaponHash.CarbineRifle,6},
{WeaponHash.MachinePistol,5},
{WeaponHash.SMG,5},
{WeaponHash.AssaultSMG,6},
{WeaponHash.CombatPDW,5},
{WeaponHash.MG,6},
{WeaponHash.CombatMG,7},
{WeaponHash.Gusenberg,7},
{WeaponHash.MicroSMG,10},
{WeaponHash.APPistol,8},
{WeaponHash.StunGun,4},
{WeaponHash.Pistol,8},
{WeaponHash.CombatPistol,8},
{WeaponHash.Pistol50,7},
{WeaponHash.SNSPistol,8},
{WeaponHash.HeavyPistol,8},
{WeaponHash.VintagePistol,8},
{WeaponHash.Railgun,9},
{WeaponHash.Minigun,5},
{WeaponHash.Musket,3},
{WeaponHash.HeavyShotgun,10},
{WeaponHash.PumpShotgun,11},
{WeaponHash.SawnOffShotgun,8},
{WeaponHash.BullpupShotgun,8},
{WeaponHash.AssaultShotgun,9},
{WeaponHash.HeavySniperMk2,11},
{WeaponHash.MarksmanRifleMk2,9},
{WeaponHash.CarbineRifleMk2,13},
{WeaponHash.SpecialCarbineMk2,16},
{WeaponHash.BullpupRifleMk2,8},
{WeaponHash.CompactRifle,7},
{WeaponHash.MilitaryRifle,11},
{WeaponHash.AssaultrifleMk2,17},
{WeaponHash.MiniSMG,5},
{WeaponHash.SMGMk2,6},
{WeaponHash.CombatMGMk2,16},
{WeaponHash.UnholyHellbringer,4},
{WeaponHash.PistolMk2,12},
{WeaponHash.SNSPistolMk2,15},
{WeaponHash.CeramicPistol,10},
{WeaponHash.MarksmanPistol,4},
{WeaponHash.Revolver,7},
{WeaponHash.RevolverMk2,7},
{WeaponHash.DoubleActionRevolver,7},
{WeaponHash.NavyRevolver,7},
{WeaponHash.PericoPistol,4},
{WeaponHash.FlareGun,4},
{WeaponHash.UpNAtomizer,4},
{WeaponHash.HomingLauncher,5},
{WeaponHash.CompactGrenadeLauncher,8},
{WeaponHash.Widowmaker,6},
{WeaponHash.GrenadeLauncher,3},
{WeaponHash.RPG,9},
{WeaponHash.DoubleBarrelShotgun,8},
{WeaponHash.SweeperShotgun,7},
{WeaponHash.CombatShotgun,7},
{WeaponHash.PumpShotgunMk2,7},
};
public static readonly HashSet<WeaponHash> ProjectileWeapons = new HashSet<WeaponHash> {
WeaponHash.HomingLauncher,
WeaponHash.RPG,
WeaponHash.Firework,
WeaponHash.UpNAtomizer,
WeaponHash.GrenadeLauncher,
WeaponHash.GrenadeLauncherSmoke,
WeaponHash.CompactGrenadeLauncher,
WeaponHash.FlareGun,
};
public static readonly HashSet<VehicleWeaponHash> VehicleProjectileWeapons = new HashSet<VehicleWeaponHash> {
VehicleWeaponHash.PlaneRocket,
VehicleWeaponHash.SpaceRocket,
VehicleWeaponHash.Tank,
2022-06-02 14:10:29 +08:00
(VehicleWeaponHash)3565779982, // STROMBERG missiles
(VehicleWeaponHash)3169388763, // SCRAMJET missiles
};
}
}