Add nozzle and deluxo transformation sync.

This commit is contained in:
Sardelka 2022-05-29 18:16:32 +08:00
parent 93db7d3de6
commit 08aa1370de
17 changed files with 249 additions and 45 deletions

View File

@ -23,7 +23,7 @@ namespace RageCoop.Client
private bool _gameLoaded = false;
private static bool _isGoingToCar = false;
public static readonly string CurrentVersion = "V0_2";
public static readonly string CurrentVersion = "V0_3";
public static int LocalPlayerID=0;
public static bool NPCsAllowed = false;

View File

@ -29,7 +29,7 @@ namespace RageCoop.Client
d1.Activated+=(sender,e) =>
{
try{ SyncParameters.PositioinPrediction =float.Parse(Game.GetUserInput(WindowTitle.EnterMessage20, SyncParameters.PositioinPrediction.ToString(), 20));}
try{ SyncParameters.PositioinPredictionDefault =float.Parse(Game.GetUserInput(WindowTitle.EnterMessage20, SyncParameters.PositioinPredictionDefault.ToString(), 20));}
catch { }
Update();
};
@ -55,7 +55,7 @@ namespace RageCoop.Client
private static void Update()
{
d1.AltTitle = SyncParameters.PositioinPrediction.ToString();
d1.AltTitle = SyncParameters.PositioinPredictionDefault.ToString();
}
}
}

View File

@ -156,8 +156,8 @@ namespace RageCoop.Client
public static Vector3 RotationToDirection(Vector3 rotation)
{
double z = DegToRad(rotation.Z);
double x = DegToRad(rotation.X);
double z = MathExtensions.DegToRad(rotation.Z);
double x = MathExtensions.DegToRad(rotation.X);
double num = Math.Abs(Math.Cos(x));
return new Vector3
@ -530,12 +530,15 @@ namespace RageCoop.Client
{
flags |= VehicleDataFlags.IsAircraft;
}
if (veh.Model.Hash==1483171323 && veh.IsDeluxoHovering())
{
flags|= VehicleDataFlags.IsDeluxoHovering;
}
return flags;
}
public static bool HasFlag(this PedDataFlags flagToCheck,PedDataFlags flag)
{
return (flagToCheck & flag)!=0;
@ -641,6 +644,44 @@ namespace RageCoop.Client
return ps;
}
public static void SetDeluxoHoverState(this Vehicle deluxo,bool hover)
{
Function.Call(Hash._SET_VEHICLE_HOVER_TRANSFORM_PERCENTAGE, deluxo, hover? 1f: 0f);
}
public static bool IsDeluxoHovering(this Vehicle deluxo)
{
return Math.Abs(deluxo.Bones[27].ForwardVector.GetCosTheta(deluxo.ForwardVector)-1)>0.05;
}
public static float GetNozzleAngel(this Vehicle plane)
{
return Function.Call<float>(Hash._GET_VEHICLE_FLIGHT_NOZZLE_POSITION, plane);
}
public static bool HasNozzle(this Vehicle v)
{
switch (v.Model.Hash)
{
// Hydra
case 970385471:
return true;
// Avenger
case -2118308144:
return true;
// Avenger
case 408970549:
return true;
}
return false;
}
public static void SetNozzleAngel(this Vehicle plane,float ratio)
{
Function.Call(Hash.SET_VEHICLE_FLIGHT_NOZZLE_POSITION, plane, ratio);
}
public static void SetDamageModel(this Vehicle veh, VehicleDamageModel model, bool leavedoors = true)
{
for (int i = 0; i < 8; i++)
@ -697,7 +738,10 @@ namespace RageCoop.Client
veh.IsLeftHeadLightBroken = model.LeftHeadLightBroken > 0;
veh.IsRightHeadLightBroken = model.RightHeadLightBroken > 0;
}
public static Vector3 PredictPosition(this Entity e)
{
return e.Position+e.Velocity*(SyncParameters.PositioinPredictionDefault+Networking.Latency);
}
#endregion
@ -730,10 +774,6 @@ namespace RageCoop.Client
}
public static double DegToRad(double deg)
{
return deg * Math.PI / 180.0;
}
@ -793,7 +833,7 @@ namespace RageCoop.Client
/// <summary>
///
/// </summary>
public static class VectorExtensions
public static class MathExtensions
{
/// <summary>
///
@ -898,6 +938,71 @@ namespace RageCoop.Client
W = vec.W
};
}
public static double DegToRad(double deg)
{
return deg * Math.PI / 180.0;
}
public static Vector3 ToEulerRotation(this Vector3 dir,Vector3 up)
{
var rot = Quaternion.LookRotation(dir.Normalized,up).ToEulerAngles().ToDegree();
return rot;
}
public static Vector3 ToDegree(this Vector3 radian)
{
return radian*(float)(180/Math.PI);
}
public static Vector3 ToEulerAngles(this Quaternion q)
{
Vector3 angles = new Vector3();
// roll / x
double sinr_cosp = 2 * (q.W * q.X + q.Y * q.Z);
double cosr_cosp = 1 - 2 * (q.X * q.X + q.Y * q.Y);
angles.X = (float)Math.Atan2(sinr_cosp, cosr_cosp);
// pitch / y
double sinp = 2 * (q.W * q.Y - q.Z * q.X);
if (Math.Abs(sinp) >= 1)
{
angles.Y = CopySign(Math.PI / 2, sinp);
}
else
{
angles.Y = (float)Math.Asin(sinp);
}
// yaw / z
double siny_cosp = 2 * (q.W * q.Z + q.X * q.Y);
double cosy_cosp = 1 - 2 * (q.Y * q.Y + q.Z * q.Z);
angles.Z = (float)Math.Atan2(siny_cosp, cosy_cosp);
return angles;
}
private static float CopySign(double x, double y)
{
bool isPositive = y>=0;
if (isPositive)
{
if (x>=0) { return (float)x; } else { return (float)-x; }
}
else
{
if (x>=0) { return (float)-x; } else { return (float)x; }
}
}
public static double AngelTo(this Vector3 v1, Vector3 v2)
{
return Math.Acos(v1.GetCosTheta(v2));
}
public static float GetCosTheta(this Vector3 v1, Vector3 v2)
{
return Vector3.Dot(v1, v2)/(v1.Length()*v2.Length());
}
}
}

View File

@ -403,6 +403,7 @@ namespace RageCoop.Client
v.Transformed = packet.Flag.HasFlag(VehicleDataFlags.IsTransformed);
v.Passengers=new Dictionary<VehicleSeat, SyncedPed>();
v.LockStatus=packet.LockStatus;
v.Flags=packet.Flag;
foreach (KeyValuePair<int, int> pair in packet.Passengers)
{
if (EntityPool.PedExists(pair.Value))

View File

@ -76,7 +76,7 @@ namespace RageCoop.Client
{
ID =v.ID,
SteeringAngle = veh.SteeringAngle,
Position = veh.Position.ToLVector(),
Position = veh.PredictPosition().ToLVector(),
Rotation = veh.Rotation.ToLVector(),
Velocity = veh.Velocity.ToLVector(),
RotationVelocity=veh.RotationVelocity.ToLVector(),
@ -117,7 +117,7 @@ namespace RageCoop.Client
{
ID =sp.ID,
ShooterID=sp.ShooterID,
Position=p.Position.ToLVector(),
Position=p.PredictPosition().ToLVector(),
Rotation=p.Rotation.ToLVector(),
Velocity=p.Velocity.ToLVector(),
WeaponHash=(uint)p.WeaponHash,

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyVersion("0.3.0.0")]
[assembly: AssemblyFileVersion("0.3.0.0")]

View File

@ -304,7 +304,6 @@ namespace RageCoop.Client
private int _lastWeaponObj = 0;
#endregion
private bool _isPlayingAnimation = false;
private string[] _currentAnimation = new string[2] { "", "" };
private void DisplayOnFoot()
@ -514,12 +513,6 @@ namespace RageCoop.Client
*/
SmoothTransition();
}
else if (_currentAnimation[1] == "reload_aim")
{
MainPed.Task.ClearAnimation(_currentAnimation[0], _currentAnimation[1]);
_isPlayingAnimation = false;
_currentAnimation = new string[2] { "", "" };
}
else if (IsInCover)
{
@ -569,7 +562,6 @@ namespace RageCoop.Client
}
#region WEAPON
WeaponHash appliedWeaponhash = WeaponHash.Unarmed;
private void CheckCurrentWeapon()
{
if (MainPed.Weapons.Current.Hash != (WeaponHash)CurrentWeaponHash || !WeaponComponents.Compare(_lastWeaponComponents))
@ -676,7 +668,7 @@ namespace RageCoop.Client
MainPed.PositionNoOffset=Position;
return;
}
var f = dist*(Position+SyncParameters.PositioinPrediction*Velocity-MainPed.Position)+(Velocity-MainPed.Velocity)*0.2f;
var f = dist*(Position+SyncParameters.PositioinPredictionDefault*Velocity-MainPed.Position)+(Velocity-MainPed.Velocity)*0.2f;
if (!localRagdoll) { f*=5; }
if (!(localRagdoll|| MainPed.IsDead))
{

View File

@ -66,6 +66,7 @@ namespace RageCoop.Client
#endregion
#region -- VEHICLE STATE --
public VehicleDataFlags Flags { get; set; }
public bool EngineRunning { get; set; }
private bool _lastTransformed = false;
public bool Transformed { get; set; }
@ -129,7 +130,7 @@ namespace RageCoop.Client
}
if (MainVehicle.Position.DistanceTo(Position)<5)
{
MainVehicle.Velocity = Velocity+5*(Position+Velocity*SyncParameters.PositioinPrediction - MainVehicle.Position);
MainVehicle.Velocity = Velocity+5*(Position+Velocity*SyncParameters.PositioinPredictionDefault - MainVehicle.Position);
_lastPositionCalibrated=Main.Counter.ElapsedMilliseconds;
}
else
@ -303,7 +304,20 @@ namespace RageCoop.Client
}
MainVehicle.LockStatus=LockStatus;
if (Flags.HasFlag(VehicleDataFlags.IsDeluxoHovering))
{
if (!MainVehicle.IsDeluxoHovering())
{
MainVehicle.SetDeluxoHoverState(true);
}
}
else if(ModelHash==1483171323)
{
if (MainVehicle.IsDeluxoHovering())
{
MainVehicle.SetDeluxoHoverState(false);
}
}
#endregion
}
@ -385,7 +399,9 @@ namespace RageCoop.Client
}
#endregion
#region OUTGOING
public float LastNozzleAngle { get; set; }
#endregion
}
}

View File

@ -388,6 +388,7 @@ namespace RageCoop.Client
if (Main.Ticked%20==0)
{
Networking.SendPed(c);
Networking.SendPedState(c);
}
else
@ -449,10 +450,11 @@ namespace RageCoop.Client
// Outgoing sync
if (v.IsMine)
{
SyncEvents.Check(v);
if (Main.Ticked%20==0)
{
Networking.SendVehicle(v);
Networking.SendVehicleState(v);
}
else
{

View File

@ -107,11 +107,20 @@ namespace RageCoop.Client {
if (info==null) { Main.Logger.Warning($"Failed to get muzzle info for vehicle:{veh.DisplayName}");return; }
Networking.SendBulletShot(info.Position,info.Position+info.ForawardVector,hash,owner.ID);
}
public static void TriggerNozzleTransform(int vehID,bool hover)
{
Networking.Send(new Packets.NozzleTransform() { VehicleID=vehID, Hover=hover }, ConnectionChannel.SyncEvents);
}
#endregion
#region HANDLE
private static ParticleEffectAsset CorePFXAsset = default;
static WeaponAsset _weaponAsset = default;
static uint _lastWeaponHash;
private static void HandleLeaveVehicle(Packets.LeaveVehicle p)
{
var ped = EntityPool.GetPedByID(p.ID)?.MainPed;
@ -152,11 +161,10 @@ namespace RageCoop.Client {
v.ModelHash=v.MainVehicle.Model;
// So this vehicle doesn's get re-spawned
}
private static ParticleEffectAsset CorePFXAsset = default;
static WeaponAsset _weaponAsset = default;
static uint _lastWeaponHash;
private static void HandleNozzleTransform(Packets.NozzleTransform p)
{
EntityPool.GetVehicleByID(p.VehicleID)?.MainVehicle?.SetNozzleAngel(p.Hover ? 1 : 0);
}
private static void HandleBulletShot(Vector3 start, Vector3 end, uint weaponHash, int ownerID)
{
if (CorePFXAsset==default) {
@ -185,6 +193,15 @@ namespace RageCoop.Client {
}
}
/*
else if (p.VehicleWeapon!=VehicleWeaponHash.Invalid)
{
if (p.VehicleWeapon==VehicleWeaponHash.Tank)
{
World.CreateParticleEffectNonLooped(CorePFXAsset, "muz_tank", p.CurrentVehicle.GetMuzzleInfo().Position, p.CurrentVehicle.Bones[35].ForwardVector.ToEulerRotation(p.CurrentVehicle.Bones[35].UpVector), 1);
}
}
*/
}
public static void HandleEvent(PacketTypes type,byte[] data)
{
@ -234,6 +251,13 @@ namespace RageCoop.Client {
HandleEnteredVehicle(packet.PedID,packet.VehicleID,(VehicleSeat)packet.VehicleSeat);
break;
}
case PacketTypes.NozzleTransform:
{
var packet = new Packets.NozzleTransform();
packet.Unpack(data);
HandleNozzleTransform(packet);
break;
}
}
}
public static int GetWeaponDamage(this Ped p)
@ -360,7 +384,21 @@ namespace RageCoop.Client {
c._lastEnteringVehicle=g;
}
public static void Check(SyncedVehicle v)
{
if (v.MainVehicle!=null&&v.MainVehicle.HasNozzle())
{
if((v.LastNozzleAngle==1) && (v.MainVehicle.GetNozzleAngel()!=1))
{
TriggerNozzleTransform(v.ID,false);
}
else if((v.LastNozzleAngle==0) && (v.MainVehicle.GetNozzleAngel()!=0))
{
TriggerNozzleTransform(v.ID,true);
}
v.LastNozzleAngle=v.MainVehicle.GetNozzleAngel();
}
}
#endregion
}
}

View File

@ -8,6 +8,6 @@ namespace RageCoop.Client
{
internal class SyncParameters
{
public static float PositioinPrediction = 0.03f;
public static float PositioinPredictionDefault = 0.01f;
}
}

View File

@ -148,6 +148,7 @@ namespace RageCoop.Core
EnteredVehicle=34,
OwnerChanged=35,
VehicleBulletShot = 36,
NozzleTransform=37,
#endregion
@ -205,7 +206,7 @@ namespace RageCoop.Core
RoofOpened = 1 << 8,
OnTurretSeat = 1 << 9,
IsAircraft = 1 << 10,
IsHandBrakeOn=1<<11,
IsDeluxoHovering=1 << 11,
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Text;
using Lidgren.Network;
namespace RageCoop.Core
{
public partial class Packets
{
public class NozzleTransform : Packet
{
public int VehicleID { get; set; }
public bool Hover { get; set; }
public override void Pack(NetOutgoingMessage message)
{
#region PacketToNetOutGoingMessage
message.Write((byte)PacketTypes.NozzleTransform);
List<byte> byteArray = new List<byte>();
byteArray.AddInt(VehicleID);
if (Hover) { byteArray.Add(1); }
byte[] result = byteArray.ToArray();
message.Write(result.Length);
message.Write(result);
#endregion
}
public override void Unpack(byte[] array)
{
#region NetIncomingMessageToPacket
BitReader reader = new BitReader(array);
VehicleID=reader.ReadInt();
Hover=reader.CanRead(1);
#endregion
}
}
}
}

View File

@ -6,10 +6,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net6.0\publish\osx-x64\</PublishDir>
<PublishDir>bin\Release\net6.0\publish\linux-arm\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
<RuntimeIdentifier>linux-arm</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishTrimmed>True</PublishTrimmed>

View File

@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<History>True|2022-05-25T02:30:00.0927959Z;True|2022-05-25T10:26:50.6739643+08:00;True|2022-05-25T10:20:36.6658425+08:00;True|2022-05-25T10:19:47.8333108+08:00;True|2022-05-24T11:00:13.3617113+08:00;True|2022-05-22T16:56:31.0481188+08:00;True|2022-05-18T13:35:57.1402751+08:00;True|2022-05-18T13:10:28.4995253+08:00;True|2022-05-01T18:35:01.9624101+08:00;True|2022-05-01T12:32:20.8671319+08:00;False|2022-05-01T12:30:25.4596227+08:00;</History>
<History>True|2022-05-27T07:20:25.7264350Z;True|2022-05-27T15:20:04.2362276+08:00;True|2022-05-27T15:19:21.4852644+08:00;True|2022-05-27T15:18:36.0857345+08:00;True|2022-05-25T10:30:00.0927959+08:00;True|2022-05-25T10:26:50.6739643+08:00;True|2022-05-25T10:20:36.6658425+08:00;True|2022-05-25T10:19:47.8333108+08:00;True|2022-05-24T11:00:13.3617113+08:00;True|2022-05-22T16:56:31.0481188+08:00;True|2022-05-18T13:35:57.1402751+08:00;True|2022-05-18T13:10:28.4995253+08:00;True|2022-05-01T18:35:01.9624101+08:00;True|2022-05-01T12:32:20.8671319+08:00;False|2022-05-01T12:30:25.4596227+08:00;</History>
</PropertyGroup>
</Project>

View File

@ -3,8 +3,8 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<AssemblyVersion>0.2</AssemblyVersion>
<FileVersion>0.2</FileVersion>
<AssemblyVersion>0.3</AssemblyVersion>
<FileVersion>0.3</FileVersion>
<RepositoryUrl>https://github.com/RAGECOOP/RAGECOOP-V</RepositoryUrl>
<PackageProjectUrl>https://ragecoop.online/</PackageProjectUrl>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
@ -12,7 +12,7 @@
<Product>$(AssemblyName)-V</Product>
<PackageId>RAGECOOP-V</PackageId>
<Authors>RAGECOOP</Authors>
<Version>0.2</Version>
<Version>0.3</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -22,7 +22,7 @@ namespace RageCoop.Server
public class Server
{
private static readonly string _compatibleVersion = "V0_2";
private static readonly string _compatibleVersion = "V0_3";
private static long _currentTick = 0;
public static readonly Settings MainSettings = Util.Read<Settings>("Settings.xml");