2021-07-07 13:36:25 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
using System.Collections.Generic;
|
2021-11-19 22:08:15 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
using GTA;
|
|
|
|
|
using GTA.Native;
|
|
|
|
|
using GTA.Math;
|
|
|
|
|
|
|
|
|
|
namespace CoopClient
|
|
|
|
|
{
|
2021-07-13 12:00:37 +02:00
|
|
|
|
static class Util
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-07-13 16:30:33 +02:00
|
|
|
|
#region -- POINTER --
|
|
|
|
|
private static int SteeringAngleOffset { get; set; }
|
|
|
|
|
|
|
|
|
|
public static unsafe void NativeMemory()
|
|
|
|
|
{
|
2021-11-25 10:17:58 +01:00
|
|
|
|
IntPtr address;
|
2021-07-13 16:30:33 +02:00
|
|
|
|
|
2021-11-25 10:17:58 +01:00
|
|
|
|
address = Game.FindPattern("\x74\x0A\xF3\x0F\x11\xB3\x1C\x09\x00\x00\xEB\x25", "xxxxxx????xx");
|
|
|
|
|
if (address != IntPtr.Zero)
|
2021-07-13 16:30:33 +02:00
|
|
|
|
{
|
|
|
|
|
SteeringAngleOffset = *(int*)(address + 6) + 8;
|
|
|
|
|
}
|
2021-08-02 22:03:07 +02:00
|
|
|
|
|
2021-11-25 10:17:58 +01:00
|
|
|
|
address = Game.FindPattern("\x32\xc0\xf3\x0f\x11\x09", "xxxxxx"); // Weapon / Radio slowdown
|
|
|
|
|
if (address != IntPtr.Zero)
|
2021-08-02 22:03:07 +02:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
{
|
2021-11-25 10:17:58 +01:00
|
|
|
|
*(byte*)(address + i).ToPointer() = 0x90;
|
2021-08-02 22:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-13 16:30:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-25 10:17:58 +01:00
|
|
|
|
public static unsafe void CustomSteeringAngle(this Vehicle veh, float value)
|
2021-07-13 16:30:33 +02:00
|
|
|
|
{
|
2021-11-25 10:17:58 +01:00
|
|
|
|
IntPtr address = new IntPtr((long)veh.MemoryAddress);
|
2021-07-13 16:30:33 +02:00
|
|
|
|
if (address == IntPtr.Zero || SteeringAngleOffset == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-14 08:09:26 +02:00
|
|
|
|
*(float*)(address + SteeringAngleOffset).ToPointer() = value;
|
|
|
|
|
}
|
2021-07-13 16:30:33 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
2021-11-28 22:57:39 +01:00
|
|
|
|
public static T GetGameMs<T>() where T : IConvertible
|
|
|
|
|
{
|
|
|
|
|
return (T)Convert.ChangeType(1f / (Game.FPS > 60f ? 60f : Game.FPS) * 1000f, typeof(T));
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 08:40:40 +01:00
|
|
|
|
public static Model ModelRequest(this int hash)
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
|
|
|
|
Model model = new Model(hash);
|
|
|
|
|
|
2021-12-12 22:00:06 +01:00
|
|
|
|
if (!model.IsValid)
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
2021-12-12 22:52:57 +01:00
|
|
|
|
//GTA.UI.Notification.Show("~y~Not valid!");
|
2021-12-12 22:00:06 +01:00
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-08-18 11:47:59 +02:00
|
|
|
|
|
2021-12-12 22:00:06 +01:00
|
|
|
|
if (!model.IsLoaded)
|
|
|
|
|
{
|
|
|
|
|
return model.Request(1000) ? model : null;
|
2021-08-18 11:47:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-12 22:00:06 +01:00
|
|
|
|
return model;
|
2021-08-18 11:47:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-13 12:00:37 +02:00
|
|
|
|
public static bool IsBetween<T>(this T item, T start, T end)
|
|
|
|
|
{
|
|
|
|
|
return Comparer<T>.Default.Compare(item, start) >= 0 && Comparer<T>.Default.Compare(item, end) <= 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 22:08:15 +01:00
|
|
|
|
public static Vector3 LinearVectorLerp(Vector3 start, Vector3 end, ulong currentTime, int duration)
|
2021-07-11 03:05:07 +02:00
|
|
|
|
{
|
|
|
|
|
return new Vector3()
|
|
|
|
|
{
|
|
|
|
|
X = LinearFloatLerp(start.X, end.X, currentTime, duration),
|
|
|
|
|
Y = LinearFloatLerp(start.Y, end.Y, currentTime, duration),
|
|
|
|
|
Z = LinearFloatLerp(start.Z, end.Z, currentTime, duration),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 22:08:15 +01:00
|
|
|
|
public static float LinearFloatLerp(float start, float end, ulong currentTime, int duration)
|
2021-07-11 03:05:07 +02:00
|
|
|
|
{
|
|
|
|
|
return (end - start) * currentTime / duration + start;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 08:40:40 +01:00
|
|
|
|
public static int GetResponsiblePedHandle(this Vehicle veh)
|
2021-08-16 13:24:32 +02:00
|
|
|
|
{
|
|
|
|
|
if (veh == null || veh.Handle == 0 || !veh.Exists())
|
|
|
|
|
{
|
2021-08-16 16:38:52 +02:00
|
|
|
|
return 0;
|
2021-08-16 13:24:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 16:38:52 +02:00
|
|
|
|
if (!veh.IsSeatFree(VehicleSeat.Driver))
|
2021-08-16 13:24:32 +02:00
|
|
|
|
{
|
2021-08-16 16:38:52 +02:00
|
|
|
|
return veh.GetPedOnSeat(VehicleSeat.Driver).Handle;
|
2021-08-16 13:24:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < veh.PassengerCapacity; i++)
|
|
|
|
|
{
|
2021-08-16 16:38:52 +02:00
|
|
|
|
if (!veh.IsSeatFree((VehicleSeat)i))
|
2021-08-16 13:24:32 +02:00
|
|
|
|
{
|
2021-08-16 16:38:52 +02:00
|
|
|
|
return veh.GetPedOnSeat((VehicleSeat)i).Handle;
|
2021-08-16 13:24:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 16:38:52 +02:00
|
|
|
|
return 0;
|
2021-08-16 13:24:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 08:40:40 +01:00
|
|
|
|
public static byte GetPedSpeed(this Ped ped)
|
2021-07-07 15:37:54 +02:00
|
|
|
|
{
|
2021-07-09 03:28:58 +02:00
|
|
|
|
if (ped.IsSprinting)
|
2021-07-07 15:37:54 +02:00
|
|
|
|
{
|
2021-07-09 03:28:58 +02:00
|
|
|
|
return 3;
|
2021-07-07 15:37:54 +02:00
|
|
|
|
}
|
|
|
|
|
else if (ped.IsRunning)
|
|
|
|
|
{
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
2021-07-09 03:28:58 +02:00
|
|
|
|
else if (ped.IsWalking)
|
2021-07-07 15:37:54 +02:00
|
|
|
|
{
|
2021-07-09 03:28:58 +02:00
|
|
|
|
return 1;
|
2021-07-07 15:37:54 +02:00
|
|
|
|
}
|
2021-07-09 03:28:58 +02:00
|
|
|
|
|
2021-07-07 15:37:54 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 08:40:40 +01:00
|
|
|
|
public static Vector3 GetPedAimCoords(this Ped ped, bool isNpc)
|
2021-07-07 15:37:54 +02:00
|
|
|
|
{
|
|
|
|
|
bool aimOrShoot = ped.IsAiming || ped.IsShooting && ped.Weapons.Current?.AmmoInClip != 0;
|
|
|
|
|
return aimOrShoot ? (isNpc ? GetLastWeaponImpact(ped) : RaycastEverything(new Vector2(0, 0))) : new Vector3();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 00:56:08 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Only works for players NOT NPCs
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Vector3</returns>
|
|
|
|
|
public static Vector3 GetVehicleAimCoords()
|
|
|
|
|
{
|
|
|
|
|
return RaycastEverything(new Vector2(0, 0));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 23:18:15 +01:00
|
|
|
|
public static byte? GetVehicleFlags(this Vehicle veh)
|
2021-07-10 23:41:28 +02:00
|
|
|
|
{
|
|
|
|
|
byte? flags = 0;
|
|
|
|
|
|
|
|
|
|
if (veh.IsEngineRunning)
|
|
|
|
|
{
|
|
|
|
|
flags |= (byte)VehicleDataFlags.IsEngineRunning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (veh.AreLightsOn)
|
|
|
|
|
{
|
|
|
|
|
flags |= (byte)VehicleDataFlags.AreLightsOn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (veh.AreHighBeamsOn)
|
|
|
|
|
{
|
|
|
|
|
flags |= (byte)VehicleDataFlags.AreHighBeamsOn;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-13 12:00:37 +02:00
|
|
|
|
if (veh.IsSirenActive)
|
|
|
|
|
{
|
|
|
|
|
flags |= (byte)VehicleDataFlags.IsSirenActive;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 11:14:34 +02:00
|
|
|
|
if (veh.IsDead)
|
|
|
|
|
{
|
|
|
|
|
flags |= (byte)VehicleDataFlags.IsDead;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 23:18:15 +01:00
|
|
|
|
if (Function.Call<bool>(Hash.IS_HORN_ACTIVE, veh.Handle))
|
|
|
|
|
{
|
|
|
|
|
flags |= (byte)VehicleDataFlags.IsHornActive;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 23:43:02 +01:00
|
|
|
|
if (veh.IsSubmarineCar && Function.Call<bool>(Hash._GET_IS_SUBMARINE_VEHICLE_TRANSFORMED, veh))
|
|
|
|
|
{
|
|
|
|
|
flags |= (byte)VehicleDataFlags.IsTransformed;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 23:41:28 +02:00
|
|
|
|
return flags;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 23:18:15 +01:00
|
|
|
|
public static byte? GetPedFlags(this Ped ped, bool isPlayer = false)
|
2021-07-07 15:37:54 +02:00
|
|
|
|
{
|
|
|
|
|
byte? flags = 0;
|
|
|
|
|
|
|
|
|
|
if (ped.IsAiming)
|
|
|
|
|
{
|
|
|
|
|
flags |= (byte)PedDataFlags.IsAiming;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 03:28:58 +02:00
|
|
|
|
if ((ped.IsShooting || isPlayer && Game.IsControlPressed(Control.Attack)) && ped.Weapons.Current?.AmmoInClip != 0)
|
2021-07-07 15:37:54 +02:00
|
|
|
|
{
|
|
|
|
|
flags |= (byte)PedDataFlags.IsShooting;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ped.IsReloading)
|
|
|
|
|
{
|
|
|
|
|
flags |= (byte)PedDataFlags.IsReloading;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ped.IsJumping)
|
|
|
|
|
{
|
|
|
|
|
flags |= (byte)PedDataFlags.IsJumping;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ped.IsRagdoll)
|
|
|
|
|
{
|
|
|
|
|
flags |= (byte)PedDataFlags.IsRagdoll;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ped.IsOnFire)
|
|
|
|
|
{
|
|
|
|
|
flags |= (byte)PedDataFlags.IsOnFire;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 08:40:40 +01:00
|
|
|
|
public static Dictionary<int, int> GetPedProps(this Ped ped)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
Dictionary<int, int> result = new Dictionary<int, int>();
|
|
|
|
|
for (int i = 0; i < 11; i++)
|
|
|
|
|
{
|
|
|
|
|
int mod = Function.Call<int>(Hash.GET_PED_DRAWABLE_VARIATION, ped.Handle, i);
|
|
|
|
|
result.Add(i, mod);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-15 03:31:57 +01:00
|
|
|
|
public static Dictionary<uint, bool> GetWeaponComponents(this Weapon weapon)
|
2021-12-15 01:25:16 +01:00
|
|
|
|
{
|
2021-12-15 03:31:57 +01:00
|
|
|
|
Dictionary<uint, bool> result = null;
|
2021-12-15 01:25:16 +01:00
|
|
|
|
|
|
|
|
|
if (weapon.Components.Count > 0)
|
|
|
|
|
{
|
2021-12-15 03:31:57 +01:00
|
|
|
|
result = new Dictionary<uint, bool>();
|
2021-12-15 01:25:16 +01:00
|
|
|
|
|
|
|
|
|
foreach (var comp in weapon.Components)
|
|
|
|
|
{
|
2021-12-15 03:31:57 +01:00
|
|
|
|
result.Add((uint)comp.ComponentHash, comp.Active);
|
2021-12-15 01:25:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 08:40:40 +01:00
|
|
|
|
public static Dictionary<int, int> GetVehicleMods(this VehicleModCollection mods)
|
2021-08-14 11:14:34 +02:00
|
|
|
|
{
|
|
|
|
|
Dictionary<int, int> result = new Dictionary<int, int>();
|
2021-11-19 08:40:40 +01:00
|
|
|
|
foreach (VehicleMod mod in mods.ToArray())
|
2021-08-14 11:14:34 +02:00
|
|
|
|
{
|
|
|
|
|
result.Add((int)mod.Type, mod.Index);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 08:40:40 +01:00
|
|
|
|
public static VehicleDoors[] GetVehicleDoors(this VehicleDoorCollection doors)
|
2021-08-14 11:14:34 +02:00
|
|
|
|
{
|
|
|
|
|
int doorLength = doors.ToArray().Length;
|
|
|
|
|
if (doorLength == 0)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VehicleDoors[] result = new VehicleDoors[doorLength];
|
|
|
|
|
for (int i = 0; i < (doorLength - 1); i++)
|
|
|
|
|
{
|
|
|
|
|
VehicleDoors currentDoor = new VehicleDoors()
|
|
|
|
|
{
|
|
|
|
|
AngleRatio = doors[(VehicleDoorIndex)i].AngleRatio,
|
|
|
|
|
Broken = doors[(VehicleDoorIndex)i].IsBroken,
|
|
|
|
|
Open = doors[(VehicleDoorIndex)i].IsOpen,
|
|
|
|
|
FullyOpen = doors[(VehicleDoorIndex)i].IsFullyOpen
|
|
|
|
|
};
|
|
|
|
|
result[i] = currentDoor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 08:40:40 +01:00
|
|
|
|
public static int GetBrokenTires(this VehicleWheelCollection wheels)
|
|
|
|
|
{
|
|
|
|
|
int tyreFlag = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var wheel in wheels.GetAllWheels())
|
|
|
|
|
{
|
|
|
|
|
if (wheel.IsBursted)
|
|
|
|
|
{
|
|
|
|
|
tyreFlag |= (1 << (int)wheel.BoneId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tyreFlag;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
public static Settings ReadSettings()
|
|
|
|
|
{
|
|
|
|
|
XmlSerializer ser = new XmlSerializer(typeof(Settings));
|
|
|
|
|
|
|
|
|
|
string path = Directory.GetCurrentDirectory() + "\\scripts\\CoopSettings.xml";
|
|
|
|
|
Settings settings = null;
|
|
|
|
|
|
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
using (FileStream stream = File.OpenRead(path))
|
|
|
|
|
{
|
|
|
|
|
settings = (Settings)ser.Deserialize(stream);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 11:31:36 +01:00
|
|
|
|
using (FileStream stream = new FileStream(path, FileMode.Truncate, FileAccess.ReadWrite))
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
ser.Serialize(stream, settings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
using (FileStream stream = File.OpenWrite(path))
|
|
|
|
|
{
|
|
|
|
|
ser.Serialize(stream, settings = new Settings());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SaveSettings()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string path = Directory.GetCurrentDirectory() + "\\scripts\\CoopSettings.xml";
|
|
|
|
|
|
|
|
|
|
using (FileStream stream = new FileStream(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite))
|
|
|
|
|
{
|
|
|
|
|
XmlSerializer ser = new XmlSerializer(typeof(Settings));
|
|
|
|
|
ser.Serialize(stream, Main.MainSettings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
GTA.UI.Notification.Show("Error saving player settings: " + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Vector3 GetLastWeaponImpact(Ped ped)
|
|
|
|
|
{
|
|
|
|
|
OutputArgument coord = new OutputArgument();
|
|
|
|
|
if (!Function.Call<bool>(Hash.GET_PED_LAST_WEAPON_IMPACT_COORD, ped.Handle, coord))
|
|
|
|
|
{
|
|
|
|
|
return new Vector3();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return coord.GetResult<Vector3>();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 00:56:08 +01:00
|
|
|
|
public static bool IsTurretSeat(this Vehicle veh, int seat)
|
|
|
|
|
{
|
|
|
|
|
if (!Function.Call<bool>(Hash.DOES_VEHICLE_HAVE_WEAPONS, veh.Handle))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (seat)
|
|
|
|
|
{
|
|
|
|
|
case -1:
|
|
|
|
|
return (VehicleHash)veh.Model.Hash == VehicleHash.Rhino
|
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Khanjari
|
2021-12-10 17:04:33 +01:00
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.FireTruck
|
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Riot2
|
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Cerberus
|
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Cerberus2
|
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Cerberus3;
|
|
|
|
|
case 0:
|
|
|
|
|
return (VehicleHash)veh.Model.Hash == VehicleHash.Apc;
|
2021-12-06 00:56:08 +01:00
|
|
|
|
case 1:
|
|
|
|
|
return (VehicleHash)veh.Model.Hash == VehicleHash.Valkyrie
|
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Valkyrie2
|
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Technical
|
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Technical2
|
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Technical3
|
2021-12-10 17:04:33 +01:00
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.HalfTrack
|
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Barrage;
|
2021-12-06 00:56:08 +01:00
|
|
|
|
case 2:
|
|
|
|
|
return (VehicleHash)veh.Model.Hash == VehicleHash.Valkyrie
|
2021-12-10 17:04:33 +01:00
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Valkyrie2
|
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Barrage;
|
2021-12-06 00:56:08 +01:00
|
|
|
|
case 3:
|
2021-12-10 17:04:33 +01:00
|
|
|
|
return (VehicleHash)veh.Model.Hash == VehicleHash.Limo2
|
|
|
|
|
|| (VehicleHash)veh.Model.Hash == VehicleHash.Dinghy5;
|
2021-12-06 00:56:08 +01:00
|
|
|
|
case 7:
|
|
|
|
|
return (VehicleHash)veh.Model.Hash == VehicleHash.Insurgent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
public static double DegToRad(double deg)
|
|
|
|
|
{
|
|
|
|
|
return deg * Math.PI / 180.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Vector3 RotationToDirection(Vector3 rotation)
|
|
|
|
|
{
|
|
|
|
|
double z = DegToRad(rotation.Z);
|
|
|
|
|
double x = DegToRad(rotation.X);
|
|
|
|
|
double num = Math.Abs(Math.Cos(x));
|
|
|
|
|
|
|
|
|
|
return new Vector3
|
|
|
|
|
{
|
|
|
|
|
X = (float)(-Math.Sin(z) * num),
|
|
|
|
|
Y = (float)(Math.Cos(z) * num),
|
|
|
|
|
Z = (float)Math.Sin(x)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool WorldToScreenRel(Vector3 worldCoords, out Vector2 screenCoords)
|
|
|
|
|
{
|
|
|
|
|
OutputArgument num1 = new OutputArgument();
|
|
|
|
|
OutputArgument num2 = new OutputArgument();
|
|
|
|
|
|
|
|
|
|
if (!Function.Call<bool>(Hash.GET_SCREEN_COORD_FROM_WORLD_COORD, worldCoords.X, worldCoords.Y, worldCoords.Z, num1, num2))
|
|
|
|
|
{
|
|
|
|
|
screenCoords = new Vector2();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
screenCoords = new Vector2((num1.GetResult<float>() - 0.5f) * 2, (num2.GetResult<float>() - 0.5f) * 2);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Vector3 ScreenRelToWorld(Vector3 camPos, Vector3 camRot, Vector2 coord)
|
|
|
|
|
{
|
|
|
|
|
Vector3 camForward = RotationToDirection(camRot);
|
|
|
|
|
Vector3 rotUp = camRot + new Vector3(10, 0, 0);
|
|
|
|
|
Vector3 rotDown = camRot + new Vector3(-10, 0, 0);
|
|
|
|
|
Vector3 rotLeft = camRot + new Vector3(0, 0, -10);
|
|
|
|
|
Vector3 rotRight = camRot + new Vector3(0, 0, 10);
|
|
|
|
|
|
|
|
|
|
Vector3 camRight = RotationToDirection(rotRight) - RotationToDirection(rotLeft);
|
|
|
|
|
Vector3 camUp = RotationToDirection(rotUp) - RotationToDirection(rotDown);
|
|
|
|
|
|
|
|
|
|
double rollRad = -DegToRad(camRot.Y);
|
|
|
|
|
|
|
|
|
|
Vector3 camRightRoll = camRight * (float)Math.Cos(rollRad) - camUp * (float)Math.Sin(rollRad);
|
|
|
|
|
Vector3 camUpRoll = camRight * (float)Math.Sin(rollRad) + camUp * (float)Math.Cos(rollRad);
|
|
|
|
|
|
|
|
|
|
Vector3 point3D = camPos + camForward * 10.0f + camRightRoll + camUpRoll;
|
|
|
|
|
if (!WorldToScreenRel(point3D, out Vector2 point2D))
|
|
|
|
|
{
|
|
|
|
|
return camPos + camForward * 10.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3 point3DZero = camPos + camForward * 10.0f;
|
|
|
|
|
if (!WorldToScreenRel(point3DZero, out Vector2 point2DZero))
|
|
|
|
|
{
|
|
|
|
|
return camPos + camForward * 10.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const double eps = 0.001;
|
|
|
|
|
if (Math.Abs(point2D.X - point2DZero.X) < eps || Math.Abs(point2D.Y - point2DZero.Y) < eps)
|
|
|
|
|
{
|
|
|
|
|
return camPos + camForward * 10.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float scaleX = (coord.X - point2DZero.X) / (point2D.X - point2DZero.X);
|
|
|
|
|
float scaleY = (coord.Y - point2DZero.Y) / (point2D.Y - point2DZero.Y);
|
|
|
|
|
|
|
|
|
|
return camPos + camForward * 10.0f + camRightRoll * scaleX + camUpRoll * scaleY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Vector3 RaycastEverything(Vector2 screenCoord)
|
|
|
|
|
{
|
|
|
|
|
Vector3 camPos = GameplayCamera.Position;
|
|
|
|
|
Vector3 camRot = GameplayCamera.Rotation;
|
|
|
|
|
const float raycastToDist = 100.0f;
|
|
|
|
|
const float raycastFromDist = 1f;
|
|
|
|
|
|
|
|
|
|
Vector3 target3D = ScreenRelToWorld(camPos, camRot, screenCoord);
|
|
|
|
|
Vector3 source3D = camPos;
|
|
|
|
|
|
|
|
|
|
Entity ignoreEntity = Game.Player.Character;
|
|
|
|
|
if (Game.Player.Character.IsInVehicle())
|
|
|
|
|
{
|
|
|
|
|
ignoreEntity = Game.Player.Character.CurrentVehicle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3 dir = target3D - source3D;
|
|
|
|
|
dir.Normalize();
|
|
|
|
|
RaycastResult raycastResults = World.Raycast(source3D + dir * raycastFromDist,
|
|
|
|
|
source3D + dir * raycastToDist,
|
2021-08-18 11:47:59 +02:00
|
|
|
|
IntersectFlags.Everything,
|
2021-07-07 13:36:25 +02:00
|
|
|
|
ignoreEntity);
|
|
|
|
|
|
|
|
|
|
if (raycastResults.DidHit)
|
|
|
|
|
{
|
|
|
|
|
return raycastResults.HitPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return camPos + dir * raycastToDist;
|
|
|
|
|
}
|
2021-11-19 22:08:15 +01:00
|
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll")]
|
|
|
|
|
public static extern ulong GetTickCount64();
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|