commit
b583618e6c
@ -173,13 +173,11 @@ namespace RageCoop.Client
|
||||
|
||||
if (Networking.ShowNetworkInfo)
|
||||
{
|
||||
|
||||
new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 0), $"L: {Networking.Latency * 1000:N0}ms", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw();
|
||||
new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 30), $"R: {Lidgren.Network.NetUtility.ToHumanReadable(Statistics.BytesDownPerSecond)}/s", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw();
|
||||
new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 60), $"S: {Lidgren.Network.NetUtility.ToHumanReadable(Statistics.BytesUpPerSecond)}/s", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw();
|
||||
}
|
||||
|
||||
|
||||
MainChat.Tick();
|
||||
PlayerList.Tick();
|
||||
if (!Scripting.API.Config.EnableAutoRespawn)
|
||||
@ -203,10 +201,8 @@ namespace RageCoop.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Function.Call(Hash.DISPLAY_HUD, true);
|
||||
}
|
||||
|
||||
}
|
||||
else if (P.IsDead && !_lastDead)
|
||||
{
|
||||
|
@ -49,7 +49,6 @@ namespace RageCoop.Client
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Main.Logger.Error("Error occurred when loading server resource:");
|
||||
Main.Logger.Error(ex);
|
||||
return new Packets.FileTransferResponse() { ID=0, Response=FileResponse.LoadFailed };
|
||||
@ -134,7 +133,6 @@ namespace RageCoop.Client
|
||||
Main.Logger.Trace($"Received unhandled file chunk:{id}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void Complete(int id)
|
||||
|
@ -29,6 +29,7 @@ namespace RageCoop.Client
|
||||
Peer?.Shutdown("Bye");
|
||||
if (IsOnServer)
|
||||
{
|
||||
// ?
|
||||
}
|
||||
else if (IsConnecting) {
|
||||
_publicKeyReceived.Set();
|
||||
@ -117,10 +118,7 @@ namespace RageCoop.Client
|
||||
});
|
||||
}
|
||||
}
|
||||
public static bool IsOnServer
|
||||
{
|
||||
get { return ServerConnection?.Status == NetConnectionStatus.Connected; }
|
||||
}
|
||||
public static bool IsOnServer { get => ServerConnection?.Status == NetConnectionStatus.Connected; }
|
||||
|
||||
#region -- PLAYER --
|
||||
private static void PlayerConnect(Packets.PlayerConnect packet)
|
||||
@ -149,7 +147,6 @@ namespace RageCoop.Client
|
||||
|
||||
#endregion // -- PLAYER --
|
||||
#region -- GET --
|
||||
|
||||
private static bool GetServerPublicKey(string address, int timeout = 10000)
|
||||
{
|
||||
Security.ServerRSA=null;
|
||||
@ -181,8 +178,7 @@ namespace RageCoop.Client
|
||||
private static int NewRequestID()
|
||||
{
|
||||
int ID = 0;
|
||||
while ((ID==0)
|
||||
|| PendingResponses.ContainsKey(ID))
|
||||
while ((ID==0) || PendingResponses.ContainsKey(ID))
|
||||
{
|
||||
byte[] rngBytes = new byte[4];
|
||||
|
||||
|
@ -25,7 +25,6 @@ namespace RageCoop.Client
|
||||
return EntityPool.ServerBlips[reader.ReadInt32()].Handle;
|
||||
default:
|
||||
throw new ArgumentException("Cannot resolve server side argument: "+t);
|
||||
|
||||
}
|
||||
};
|
||||
private static readonly AutoResetEvent _publicKeyReceived = new AutoResetEvent(false);
|
||||
@ -43,7 +42,6 @@ namespace RageCoop.Client
|
||||
case NetConnectionStatus.InitiatedConnect:
|
||||
if (message.SenderConnection==ServerConnection)
|
||||
{
|
||||
|
||||
CoopMenu.InitiateConnectionMenuSetting();
|
||||
}
|
||||
break;
|
||||
@ -103,8 +101,7 @@ namespace RageCoop.Client
|
||||
Main.QueueAction(() => Main.CleanUp());
|
||||
CoopMenu.DisconnectedMenuSetting();
|
||||
Main.Logger.Info($">> Disconnected << reason: {reason}");
|
||||
Main.QueueAction(() =>
|
||||
GTA.UI.Notification.Show("~r~Disconnected: " + reason));
|
||||
Main.QueueAction(() => GTA.UI.Notification.Show("~r~Disconnected: " + reason));
|
||||
Main.Resources.Unload();
|
||||
}
|
||||
break;
|
||||
@ -112,12 +109,10 @@ namespace RageCoop.Client
|
||||
break;
|
||||
case NetIncomingMessageType.Data:
|
||||
{
|
||||
|
||||
if (message.LengthBytes==0) { break; }
|
||||
var packetType = PacketType.Unknown;
|
||||
try
|
||||
{
|
||||
|
||||
// Get packet type
|
||||
packetType = (PacketType)message.ReadByte();
|
||||
switch (packetType)
|
||||
@ -246,10 +241,7 @@ namespace RageCoop.Client
|
||||
case PacketType.ChatMessage:
|
||||
{
|
||||
|
||||
Packets.ChatMessage packet = new Packets.ChatMessage((b) =>
|
||||
{
|
||||
return Security.Decrypt(b);
|
||||
});
|
||||
Packets.ChatMessage packet = new Packets.ChatMessage((b) => Security.Decrypt(b));
|
||||
packet.Deserialize(data);
|
||||
|
||||
Main.QueueAction(() => { Main.MainChat.AddMessage(packet.Username, packet.Message); return true; });
|
||||
|
@ -53,14 +53,7 @@ namespace RageCoop.Client
|
||||
c.LastSentStopWatch.Restart();
|
||||
if (full)
|
||||
{
|
||||
if (packet.Flags.HasPedFlag(PedDataFlags.IsInVehicle))
|
||||
{
|
||||
packet.CurrentWeaponHash=(uint)p.VehicleWeapon;
|
||||
}
|
||||
else
|
||||
{
|
||||
packet.CurrentWeaponHash=(uint)p.Weapons.Current.Hash;
|
||||
}
|
||||
packet.CurrentWeaponHash = packet.Flags.HasPedFlag(PedDataFlags.IsInVehicle) ? (uint)p.VehicleWeapon : (uint)p.Weapons.Current.Hash;
|
||||
packet.Flags |= PedDataFlags.IsFullSync;
|
||||
packet.Clothes=p.GetPedClothes();
|
||||
packet.ModelHash=p.Model.Hash;
|
||||
@ -176,13 +169,7 @@ namespace RageCoop.Client
|
||||
#endregion
|
||||
public static void SendChatMessage(string message)
|
||||
{
|
||||
|
||||
|
||||
|
||||
Peer.SendTo(new Packets.ChatMessage(new Func<string, byte[]>((s) =>
|
||||
{
|
||||
return Security.Encrypt(s.GetBytes());
|
||||
}))
|
||||
Peer.SendTo(new Packets.ChatMessage(new Func<string, byte[]>((s) => Security.Encrypt(s.GetBytes())))
|
||||
{ Username = Main.Settings.Username, Message = message },ServerConnection, ConnectionChannel.Chat, NetDeliveryMethod.ReliableOrdered);
|
||||
Peer.FlushSendQueue();
|
||||
}
|
||||
|
@ -137,10 +137,8 @@ namespace RageCoop.Client
|
||||
}
|
||||
Players=new Dictionary<int, Player> { };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
internal class Player
|
||||
{
|
||||
public byte HolePunchStatus { get; set; } = 1;
|
||||
|
@ -15,10 +15,7 @@ namespace RageCoop.Client
|
||||
/// </summary>
|
||||
public bool IsLocal
|
||||
{
|
||||
get
|
||||
{
|
||||
return OwnerID==Main.LocalPlayerID;
|
||||
}
|
||||
get => OwnerID == Main.LocalPlayerID;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -33,10 +30,7 @@ namespace RageCoop.Client
|
||||
/// </summary>
|
||||
public int OwnerID
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ownerID;
|
||||
}
|
||||
get => _ownerID;
|
||||
internal set
|
||||
{
|
||||
if (value==_ownerID && Owner!=null) { return; }
|
||||
@ -51,19 +45,16 @@ namespace RageCoop.Client
|
||||
/// </summary>
|
||||
public bool IsOutOfSync
|
||||
{
|
||||
get
|
||||
{
|
||||
return Main.Ticked-LastSynced>200 && ID!=0;
|
||||
}
|
||||
get => Main.Ticked - LastSynced > 200 && ID != 0;
|
||||
}
|
||||
internal bool IsReady
|
||||
{
|
||||
get { return (LastSynced>0||LastFullSynced==0); }
|
||||
get => LastSynced > 0 || LastFullSynced == 0;
|
||||
}
|
||||
internal bool IsInvincible { get; set; } = false;
|
||||
internal bool NeedUpdate
|
||||
{
|
||||
get { return LastSynced>=LastUpdated; }
|
||||
get => LastSynced >= LastUpdated;
|
||||
}
|
||||
#region LAST STATE
|
||||
/// <summary>
|
||||
@ -100,6 +91,5 @@ namespace RageCoop.Client
|
||||
{
|
||||
LastUpdated=Main.Ticked+frames;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ namespace RageCoop.Client
|
||||
/// <summary>
|
||||
/// Indicates whether this ped is a player
|
||||
/// </summary>
|
||||
public bool IsPlayer { get { return (OwnerID==ID)&&(ID!=0); } }
|
||||
public bool IsPlayer { get => OwnerID == ID && ID != 0; }
|
||||
/// <summary>
|
||||
/// real entity
|
||||
/// </summary>
|
||||
@ -80,7 +80,6 @@ namespace RageCoop.Client
|
||||
|
||||
private WeaponAsset WeaponAsset { get; set; }
|
||||
|
||||
|
||||
internal override void Update()
|
||||
{
|
||||
if (IsPlayer)
|
||||
@ -97,12 +96,7 @@ namespace RageCoop.Client
|
||||
if (!IsReady) { return; }
|
||||
|
||||
// Skip update if no new sync message has arrived.
|
||||
if (!NeedUpdate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!NeedUpdate) { return; }
|
||||
|
||||
if (MainPed == null || !MainPed.Exists())
|
||||
{
|
||||
@ -112,11 +106,6 @@ namespace RageCoop.Client
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Need to update state
|
||||
if (LastFullSynced>=LastUpdated)
|
||||
{
|
||||
@ -126,7 +115,6 @@ namespace RageCoop.Client
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (((byte)BlipColor==255) && (PedBlip!=null))
|
||||
@ -165,8 +153,6 @@ namespace RageCoop.Client
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (MainPed.IsDead)
|
||||
{
|
||||
if (Health>0)
|
||||
@ -201,10 +187,9 @@ namespace RageCoop.Client
|
||||
{
|
||||
DisplayOnFoot();
|
||||
}
|
||||
LastUpdated=Main.Ticked;
|
||||
return;
|
||||
}
|
||||
|
||||
LastUpdated=Main.Ticked;
|
||||
}
|
||||
|
||||
private void RenderNameTag()
|
||||
{
|
||||
@ -225,7 +210,6 @@ namespace RageCoop.Client
|
||||
Color=Owner.HasDirectConnection? Color.FromArgb(179, 229, 252) : Color.White,
|
||||
}.Draw();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private bool CreateCharacter()
|
||||
@ -261,7 +245,6 @@ namespace RageCoop.Client
|
||||
|
||||
Model.MarkAsNoLongerNeeded();
|
||||
|
||||
|
||||
MainPed.BlockPermanentEvents = true;
|
||||
MainPed.CanWrithe=false;
|
||||
MainPed.CanBeDraggedOutOfVehicle = true;
|
||||
@ -278,7 +261,6 @@ namespace RageCoop.Client
|
||||
Function.Call(Hash._SET_PED_CAN_PLAY_INJURED_ANIMS, false);
|
||||
Function.Call(Hash.SET_PED_CAN_EVASIVE_DIVE, MainPed.Handle, false);
|
||||
|
||||
|
||||
MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DrownsInWater, false);
|
||||
MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableHurt, true);
|
||||
MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableExplosionReactions, true);
|
||||
@ -288,10 +270,7 @@ namespace RageCoop.Client
|
||||
|
||||
SetClothes();
|
||||
|
||||
if (IsPlayer)
|
||||
{
|
||||
MainPed.IsInvincible=true;
|
||||
}
|
||||
if (IsPlayer) { MainPed.IsInvincible=true; }
|
||||
if (IsInvincible) { MainPed.IsInvincible=true; }
|
||||
|
||||
lock (EntityPool.PedsLock)
|
||||
@ -517,12 +496,9 @@ namespace RageCoop.Client
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastRagdoll = false;
|
||||
}
|
||||
}
|
||||
|
||||
_lastRagdoll = false;
|
||||
}
|
||||
|
||||
if (IsReloading)
|
||||
{
|
||||
@ -546,8 +522,6 @@ namespace RageCoop.Client
|
||||
}
|
||||
else if (IsInCover)
|
||||
{
|
||||
|
||||
|
||||
if (!_lastInCover)
|
||||
{
|
||||
Function.Call(Hash.TASK_STAY_IN_COVER, MainPed.Handle);
|
||||
@ -563,7 +537,6 @@ namespace RageCoop.Client
|
||||
{
|
||||
SmoothTransition();
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (_lastInCover)
|
||||
{
|
||||
@ -601,17 +574,13 @@ namespace RageCoop.Client
|
||||
{
|
||||
foreach (KeyValuePair<uint, bool> comp in WeaponComponents)
|
||||
{
|
||||
|
||||
if (comp.Value)
|
||||
{
|
||||
Function.Call(Hash.GIVE_WEAPON_COMPONENT_TO_WEAPON_OBJECT, _lastWeaponObj, comp.Key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Function.Call(Hash.GIVE_WEAPON_OBJECT_TO_PED, _lastWeaponObj, MainPed.Handle);
|
||||
|
||||
}
|
||||
_lastWeaponComponents = WeaponComponents;
|
||||
}
|
||||
|
@ -52,8 +52,6 @@ namespace RageCoop.Client
|
||||
|
||||
|
||||
#region LAST STATE
|
||||
|
||||
|
||||
private byte[] _lastVehicleColors = new byte[] { 0, 0 };
|
||||
private Dictionary<int, int> _lastVehicleMods = new Dictionary<int, int>();
|
||||
#endregion
|
||||
@ -67,25 +65,22 @@ namespace RageCoop.Client
|
||||
internal float DeluxoWingRatio { get; set; } = -1;
|
||||
internal bool IsFlipped
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isMotorcycle||((Quaternion*Vector3.RelativeTop).Z - (Quaternion*Vector3.RelativeBottom).Z)<0.5;
|
||||
}
|
||||
get => _isMotorcycle || ((Quaternion * Vector3.RelativeTop).Z - (Quaternion * Vector3.RelativeBottom).Z) < 0.5;
|
||||
}
|
||||
private bool _isMotorcycle;
|
||||
#endregion
|
||||
#region FLAGS
|
||||
internal bool EngineRunning { get { return Flags.HasVehFlag(VehicleDataFlags.IsEngineRunning); } }
|
||||
internal bool EngineRunning { get => Flags.HasVehFlag(VehicleDataFlags.IsEngineRunning); }
|
||||
private bool _lastTransformed = false;
|
||||
internal bool Transformed { get { return Flags.HasVehFlag(VehicleDataFlags.IsTransformed); } }
|
||||
internal bool Transformed { get => Flags.HasVehFlag(VehicleDataFlags.IsTransformed); }
|
||||
private bool _lastHornActive = false;
|
||||
internal bool HornActive { get { return Flags.HasVehFlag(VehicleDataFlags.IsHornActive); } }
|
||||
internal bool LightsOn { get { return Flags.HasVehFlag(VehicleDataFlags.AreLightsOn); } }
|
||||
internal bool BrakeLightsOn { get { return Flags.HasVehFlag(VehicleDataFlags.AreBrakeLightsOn); } }
|
||||
internal bool HighBeamsOn { get { return Flags.HasVehFlag(VehicleDataFlags.AreHighBeamsOn); } }
|
||||
internal bool SireneActive { get { return Flags.HasVehFlag(VehicleDataFlags.IsSirenActive); } }
|
||||
internal bool IsDead { get { return Flags.HasVehFlag(VehicleDataFlags.IsDead); } }
|
||||
internal bool IsDeluxoHovering { get { return Flags.HasVehFlag(VehicleDataFlags.IsDeluxoHovering); } }
|
||||
internal bool HornActive { get => Flags.HasVehFlag(VehicleDataFlags.IsHornActive); }
|
||||
internal bool LightsOn { get => Flags.HasVehFlag(VehicleDataFlags.AreLightsOn); }
|
||||
internal bool BrakeLightsOn { get => Flags.HasVehFlag(VehicleDataFlags.AreBrakeLightsOn); }
|
||||
internal bool HighBeamsOn { get => Flags.HasVehFlag(VehicleDataFlags.AreHighBeamsOn); }
|
||||
internal bool SireneActive { get => Flags.HasVehFlag(VehicleDataFlags.IsSirenActive); }
|
||||
internal bool IsDead { get => Flags.HasVehFlag(VehicleDataFlags.IsDead); }
|
||||
internal bool IsDeluxoHovering { get => Flags.HasVehFlag(VehicleDataFlags.IsDeluxoHovering); }
|
||||
#endregion
|
||||
|
||||
#region -- VEHICLE STATE --
|
||||
@ -139,14 +134,7 @@ namespace RageCoop.Client
|
||||
MainVehicle.ThrottlePower=ThrottlePower;
|
||||
MainVehicle.BrakePower=BrakePower;
|
||||
var v = Main.P.CurrentVehicle;
|
||||
if (v!= null && MainVehicle.IsTouching(v))
|
||||
{
|
||||
DisplayVehicle(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisplayVehicle(false);
|
||||
}
|
||||
DisplayVehicle(v != null && MainVehicle.IsTouching(v));
|
||||
#region FLAGS
|
||||
if (IsDead)
|
||||
{
|
||||
@ -154,10 +142,8 @@ namespace RageCoop.Client
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
MainVehicle.Explode();
|
||||
}
|
||||
|
||||
MainVehicle.Explode();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -280,7 +266,6 @@ namespace RageCoop.Client
|
||||
// check passengers (and driver).
|
||||
if (_checkSeat)
|
||||
{
|
||||
|
||||
var currentPassengers = MainVehicle.GetPassengers();
|
||||
|
||||
lock (Passengers)
|
||||
@ -290,7 +275,6 @@ namespace RageCoop.Client
|
||||
VehicleSeat seat = (VehicleSeat)i;
|
||||
if (Passengers.ContainsKey(seat))
|
||||
{
|
||||
|
||||
SyncedPed c = Passengers[seat];
|
||||
if (c?.ID==Main.LocalPlayerID && (RadioStation!=Function.Call<int>(Hash.GET_PLAYER_RADIO_STATION_INDEX)))
|
||||
{
|
||||
@ -336,8 +320,6 @@ namespace RageCoop.Client
|
||||
_lastVehicleMods = Mods;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (Function.Call<string>(Hash.GET_VEHICLE_NUMBER_PLATE_TEXT, MainVehicle)!=LicensePlate)
|
||||
{
|
||||
Function.Call(Hash.SET_VEHICLE_NUMBER_PLATE_TEXT, MainVehicle, LicensePlate);
|
||||
@ -366,34 +348,32 @@ namespace RageCoop.Client
|
||||
var dist = current.DistanceTo(Position);
|
||||
var cali = ((Velocity.Length()<0.1 && !touching)?dist*4:dist)*(_predictedPos - current);
|
||||
|
||||
if (dist<8)
|
||||
if (dist>=8)
|
||||
{
|
||||
MainVehicle.Position = _predictedPos;
|
||||
MainVehicle.Velocity = Velocity;
|
||||
MainVehicle.ApplyForce(cali);
|
||||
if (IsFlipped)
|
||||
{
|
||||
MainVehicle.Quaternion=Quaternion.Slerp(MainVehicle.ReadQuaternion(), Quaternion, 0.5f);
|
||||
MainVehicle.RotationVelocity=RotationVelocity;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 calirot = GetCalibrationRotation();
|
||||
if (calirot.Length()<50)
|
||||
{
|
||||
MainVehicle.RotationVelocity = RotationVelocity+calirot*0.2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
MainVehicle.Quaternion=Quaternion;
|
||||
MainVehicle.RotationVelocity=RotationVelocity;
|
||||
}
|
||||
}
|
||||
MainVehicle.Quaternion = Quaternion;
|
||||
return;
|
||||
}
|
||||
|
||||
MainVehicle.Velocity = Velocity;
|
||||
MainVehicle.ApplyForce(cali);
|
||||
if (IsFlipped)
|
||||
{
|
||||
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.ReadQuaternion(), Quaternion, 0.5f);
|
||||
MainVehicle.RotationVelocity = RotationVelocity;
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 calirot = GetCalibrationRotation();
|
||||
if (calirot.Length() < 50)
|
||||
{
|
||||
MainVehicle.RotationVelocity = RotationVelocity + calirot * 0.2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
MainVehicle.Position=_predictedPos;
|
||||
MainVehicle.Velocity=Velocity;
|
||||
MainVehicle.Quaternion=Quaternion;
|
||||
MainVehicle.Quaternion = Quaternion;
|
||||
MainVehicle.RotationVelocity = RotationVelocity;
|
||||
}
|
||||
}
|
||||
private Vector3 GetCalibrationRotation()
|
||||
@ -411,7 +391,6 @@ namespace RageCoop.Client
|
||||
if (r.Z>180) { r.Z=r.Z-360; }
|
||||
else if (r.Z<-180) { r.Z=360+r.Z; }
|
||||
return r;
|
||||
|
||||
}
|
||||
private bool CreateVehicle()
|
||||
{
|
||||
@ -489,5 +468,4 @@ namespace RageCoop.Client
|
||||
internal Vector3 LastVelocity { get; set; }
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -46,8 +46,7 @@ namespace RageCoop.Client
|
||||
{
|
||||
foreach (int id in new List<int>(PedsByID.Keys))
|
||||
{
|
||||
if (keepPlayer&&(id==Main.LocalPlayerID)) { continue; }
|
||||
if (keepMine&&(PedsByID[id].OwnerID==Main.LocalPlayerID)) { continue; }
|
||||
if (keepPlayer && (id==Main.LocalPlayerID)|| keepMine && (PedsByID[id].OwnerID == Main.LocalPlayerID)) { continue; }
|
||||
RemovePed(id);
|
||||
}
|
||||
PedsByID.Clear();
|
||||
@ -88,55 +87,44 @@ namespace RageCoop.Client
|
||||
}
|
||||
|
||||
#region PEDS
|
||||
public static SyncedPed GetPedByID(int id)
|
||||
{
|
||||
return PedsByID.ContainsKey(id) ? PedsByID[id] : null;
|
||||
}
|
||||
public static SyncedPed GetPedByHandle(int handle)
|
||||
{
|
||||
return PedsByHandle.ContainsKey(handle) ? PedsByHandle[handle] : null;
|
||||
}
|
||||
public static List<int> GetPedIDs()
|
||||
{
|
||||
return new List<int>(PedsByID.Keys);
|
||||
}
|
||||
public static SyncedPed GetPedByID(int id) => PedsByID.ContainsKey(id) ? PedsByID[id] : null;
|
||||
public static SyncedPed GetPedByHandle(int handle) => PedsByHandle.ContainsKey(handle) ? PedsByHandle[handle] : null;
|
||||
public static List<int> GetPedIDs() => new List<int>(PedsByID.Keys);
|
||||
public static bool AddPlayer()
|
||||
{
|
||||
Ped p = Game.Player.Character;
|
||||
SyncedPed player = GetPedByID(Main.LocalPlayerID);
|
||||
if (player!=null)
|
||||
{
|
||||
if (player.MainPed!=p)
|
||||
{
|
||||
// Player model changed
|
||||
player.MainPed = p;
|
||||
|
||||
// Remove it from Handle_Characters
|
||||
var pairs = PedsByHandle.Where(x => x.Value==player);
|
||||
if (pairs.Any())
|
||||
{
|
||||
var pair = pairs.First();
|
||||
|
||||
// Re-add
|
||||
PedsByHandle.Remove(pair.Key);
|
||||
if (PedsByHandle.ContainsKey(p.Handle))
|
||||
{
|
||||
RemovePed(PedsByHandle[p.Handle].ID);
|
||||
}
|
||||
PedsByHandle.Add(p.Handle, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (player==null)
|
||||
{
|
||||
Main.Logger.Debug($"Creating SyncEntity for player, handle:{p.Handle}");
|
||||
SyncedPed c = new SyncedPed(p);
|
||||
Main.LocalPlayerID=c.OwnerID=c.ID;
|
||||
Main.LocalPlayerID = c.OwnerID = c.ID;
|
||||
Add(c);
|
||||
Main.Logger.Debug($"Local player ID is:{c.ID}");
|
||||
PlayerList.SetPlayer(c.ID, Main.Settings.Username);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (player.MainPed != p)
|
||||
{
|
||||
// Player model changed
|
||||
player.MainPed = p;
|
||||
|
||||
// Remove it from Handle_Characters
|
||||
var pairs = PedsByHandle.Where(x => x.Value == player);
|
||||
if (pairs.Any())
|
||||
{
|
||||
var pair = pairs.First();
|
||||
|
||||
// Re-add
|
||||
PedsByHandle.Remove(pair.Key);
|
||||
if (PedsByHandle.ContainsKey(p.Handle))
|
||||
{
|
||||
RemovePed(PedsByHandle[p.Handle].ID);
|
||||
}
|
||||
PedsByHandle.Add(p.Handle, player);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static void Add(SyncedPed c)
|
||||
@ -194,18 +182,9 @@ namespace RageCoop.Client
|
||||
#endregion
|
||||
|
||||
#region VEHICLES
|
||||
public static SyncedVehicle GetVehicleByID(int id)
|
||||
{
|
||||
return VehiclesByID.ContainsKey(id) ? VehiclesByID[id] : null;
|
||||
}
|
||||
public static SyncedVehicle GetVehicleByHandle(int handle)
|
||||
{
|
||||
return VehiclesByHandle.ContainsKey(handle) ? VehiclesByHandle[handle] : null;
|
||||
}
|
||||
public static List<int> GetVehicleIDs()
|
||||
{
|
||||
return new List<int>(VehiclesByID.Keys);
|
||||
}
|
||||
public static SyncedVehicle GetVehicleByID(int id) => VehiclesByID.ContainsKey(id) ? VehiclesByID[id] : null;
|
||||
public static SyncedVehicle GetVehicleByHandle(int handle) => VehiclesByHandle.ContainsKey(handle) ? VehiclesByHandle[handle] : null;
|
||||
public static List<int> GetVehicleIDs() => new List<int>(VehiclesByID.Keys);
|
||||
public static void Add(SyncedVehicle v)
|
||||
{
|
||||
if (VehiclesByID.ContainsKey(v.ID))
|
||||
@ -300,18 +279,9 @@ namespace RageCoop.Client
|
||||
}
|
||||
}
|
||||
|
||||
public static bool PedExists(int id)
|
||||
{
|
||||
return PedsByID.ContainsKey(id);
|
||||
}
|
||||
public static bool VehicleExists(int id)
|
||||
{
|
||||
return VehiclesByID.ContainsKey(id);
|
||||
}
|
||||
public static bool ProjectileExists(int id)
|
||||
{
|
||||
return ProjectilesByID.ContainsKey(id);
|
||||
}
|
||||
public static bool PedExists(int id) => PedsByID.ContainsKey(id);
|
||||
public static bool VehicleExists(int id) => VehiclesByID.ContainsKey(id);
|
||||
public static bool ProjectileExists(int id) => ProjectilesByID.ContainsKey(id);
|
||||
#endregion
|
||||
static int vehStateIndex;
|
||||
static int pedStateIndex;
|
||||
@ -358,26 +328,21 @@ namespace RageCoop.Client
|
||||
if (!ProjectilesByHandle.ContainsKey(p.Handle))
|
||||
{
|
||||
Add(new SyncedProjectile(p));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach (SyncedProjectile p in ProjectilesByID.Values.ToArray())
|
||||
{
|
||||
|
||||
// Outgoing sync
|
||||
if (p.IsLocal)
|
||||
{
|
||||
if (p.MainProjectile.AttachedEntity==null)
|
||||
{
|
||||
|
||||
// Prevent projectiles from exploding next to vehicle
|
||||
if (WeaponUtil.VehicleProjectileWeapons.Contains((VehicleWeaponHash)p.MainProjectile.WeaponHash))
|
||||
if (WeaponUtil.VehicleProjectileWeapons.Contains((VehicleWeaponHash)p.MainProjectile.WeaponHash) &&
|
||||
p.MainProjectile.WeaponHash != (WeaponHash)VehicleWeaponHash.Tank && p.Origin.DistanceTo(p.MainProjectile.Position) < 2)
|
||||
{
|
||||
if (p.MainProjectile.WeaponHash!=(WeaponHash)VehicleWeaponHash.Tank && p.Origin.DistanceTo(p.MainProjectile.Position)<2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Networking.SendProjectile(p);
|
||||
@ -393,11 +358,8 @@ namespace RageCoop.Client
|
||||
{
|
||||
p.Update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
i=-1;
|
||||
@ -411,20 +373,15 @@ namespace RageCoop.Client
|
||||
SyncedPed c = EntityPool.GetPedByHandle(p.Handle);
|
||||
if (c==null && (p!=Game.Player.Character))
|
||||
{
|
||||
if (allPeds.Length>Main.Settings.WorldPedSoftLimit)
|
||||
if (allPeds.Length>Main.Settings.WorldPedSoftLimit && p.PopulationType != EntityPopulationType.RandomAmbient)
|
||||
{
|
||||
if (p.PopulationType!=EntityPopulationType.RandomAmbient)
|
||||
{
|
||||
p.Delete();
|
||||
continue;
|
||||
}
|
||||
p.Delete();
|
||||
continue;
|
||||
}
|
||||
// Main.Logger.Trace($"Creating SyncEntity for ped, handle:{p.Handle}");
|
||||
c=new SyncedPed(p);
|
||||
|
||||
EntityPool.Add(c);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#if BENCHMARK
|
||||
@ -437,6 +394,7 @@ namespace RageCoop.Client
|
||||
{
|
||||
pedStateIndex=0;
|
||||
}
|
||||
|
||||
foreach (SyncedPed c in ps)
|
||||
{
|
||||
i++;
|
||||
@ -457,7 +415,6 @@ namespace RageCoop.Client
|
||||
|
||||
Networking.SendPed(c, (i-pedStateIndex)<pedStatesPerFrame);
|
||||
#if BENCHMARK
|
||||
|
||||
Debug.TimeStamps[TimeStamp.SendPed]=PerfCounter2.ElapsedTicks-start;
|
||||
#endif
|
||||
}
|
||||
@ -472,13 +429,11 @@ namespace RageCoop.Client
|
||||
RemovePed(c.ID, "OutOfSync");
|
||||
}
|
||||
#if BENCHMARK
|
||||
|
||||
Debug.TimeStamps[TimeStamp.UpdatePed]=PerfCounter2.ElapsedTicks-start;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if BENCHMARK
|
||||
|
||||
Debug.TimeStamps[TimeStamp.PedTotal]=PerfCounter.ElapsedTicks;
|
||||
#endif
|
||||
}
|
||||
@ -487,7 +442,6 @@ namespace RageCoop.Client
|
||||
|
||||
lock (VehiclesLock)
|
||||
{
|
||||
|
||||
foreach (Vehicle veh in allVehicles)
|
||||
{
|
||||
if (!VehiclesByHandle.ContainsKey(veh.Handle))
|
||||
@ -513,12 +467,9 @@ namespace RageCoop.Client
|
||||
// Main.Logger.Debug($"Creating SyncEntity for vehicle, handle:{veh.Handle}");
|
||||
|
||||
Add(new SyncedVehicle(veh));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#if BENCHMARK
|
||||
|
||||
Debug.TimeStamps[TimeStamp.AddVehicles]=PerfCounter.ElapsedTicks;
|
||||
#endif
|
||||
var vs = VehiclesByID.Values.ToArray();
|
||||
@ -527,6 +478,7 @@ namespace RageCoop.Client
|
||||
{
|
||||
vehStateIndex=0;
|
||||
}
|
||||
|
||||
foreach (SyncedVehicle v in vs)
|
||||
{
|
||||
i++;
|
||||
@ -543,20 +495,15 @@ namespace RageCoop.Client
|
||||
SyncEvents.Check(v);
|
||||
|
||||
Networking.SendVehicle(v, (i-vehStateIndex)<vehStatesPerFrame);
|
||||
|
||||
}
|
||||
else // Incoming sync
|
||||
{
|
||||
|
||||
|
||||
v.Update();
|
||||
if (v.IsOutOfSync)
|
||||
{
|
||||
RemoveVehicle(v.ID, "OutOfSync");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if BENCHMARK
|
||||
@ -586,6 +533,7 @@ namespace RageCoop.Client
|
||||
RemovePed(p.ID);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (SyncedVehicle v in VehiclesByID.Values.ToArray())
|
||||
{
|
||||
if (v.OwnerID==playerPedId)
|
||||
@ -598,10 +546,7 @@ namespace RageCoop.Client
|
||||
public static int RequestNewID()
|
||||
{
|
||||
int ID = 0;
|
||||
while ((ID==0)
|
||||
|| PedsByID.ContainsKey(ID)
|
||||
|| VehiclesByID.ContainsKey(ID)
|
||||
|| ProjectilesByID.ContainsKey(ID))
|
||||
while ((ID==0) || PedsByID.ContainsKey(ID) || VehiclesByID.ContainsKey(ID) || ProjectilesByID.ContainsKey(ID))
|
||||
{
|
||||
byte[] rngBytes = new byte[4];
|
||||
|
||||
@ -619,16 +564,14 @@ namespace RageCoop.Client
|
||||
}
|
||||
public static string DumpDebug()
|
||||
{
|
||||
string s = "";
|
||||
s+="\nID_Peds: "+PedsByID.Count;
|
||||
s+="\nHandle_Peds: "+PedsByHandle.Count;
|
||||
s+="\nID_Vehicles: "+VehiclesByID.Count;
|
||||
s+="\nHandle_Vehicles: "+VehiclesByHandle.Count;
|
||||
s+="\nID_Projectiles: "+ProjectilesByID.Count;
|
||||
s+="\nHandle_Projectiles: "+ProjectilesByHandle.Count;
|
||||
s+="\npedStatesPerFrame:"+pedStatesPerFrame;
|
||||
s+="\nvehStatesPerFrame:"+vehStatesPerFrame;
|
||||
return s;
|
||||
return $"\nID_Peds: {PedsByID.Count}" +
|
||||
$"\nHandle_Peds: {PedsByHandle.Count}" +
|
||||
$"\nID_Vehicles: {VehiclesByID.Count}" +
|
||||
$"\nHandle_vehicles: {VehiclesByHandle.Count}" +
|
||||
$"\nID_Projectiles: {ProjectilesByID.Count}" +
|
||||
$"\nHandle_Projectiles: {ProjectilesByHandle.Count}" +
|
||||
$"\npedStatesPerFrame: {pedStatesPerFrame}" +
|
||||
$"\nvehStatesPerFrame: {vehStatesPerFrame}";
|
||||
}
|
||||
public static class ThreadSafe
|
||||
{
|
||||
|
@ -136,12 +136,9 @@ namespace RageCoop.Client
|
||||
var v = EntityPool.GetVehicleByID(vehId);
|
||||
var p = EntityPool.GetPedByID(pedId)?.MainPed;
|
||||
if (v==null||p==null) { return; }
|
||||
if (!v.MainVehicle.IsSeatFree(seat))
|
||||
if (!v.MainVehicle.IsSeatFree(seat) && v.MainVehicle.GetPedOnSeat(seat) != p)
|
||||
{
|
||||
if (v.MainVehicle.GetPedOnSeat(seat)!=p)
|
||||
{
|
||||
v.MainVehicle.GetPedOnSeat(seat).Task.WarpOutOfVehicle(v.MainVehicle);
|
||||
}
|
||||
v.MainVehicle.GetPedOnSeat(seat).Task.WarpOutOfVehicle(v.MainVehicle);
|
||||
}
|
||||
p.SetIntoVehicle(v.MainVehicle, seat);
|
||||
}
|
||||
@ -215,14 +212,10 @@ namespace RageCoop.Client
|
||||
{
|
||||
World.CreateParticleEffectNonLooped(CorePFXAsset, "muz_assault_rifle", p.GetMuzzlePosition(), w.Rotation, 1);
|
||||
}
|
||||
|
||||
}
|
||||
else if (p.VehicleWeapon!=VehicleWeaponHash.Invalid)
|
||||
else if (p.VehicleWeapon!=VehicleWeaponHash.Invalid && p.VehicleWeapon == VehicleWeaponHash.Tank)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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(PacketType type, byte[] data)
|
||||
@ -303,32 +296,10 @@ namespace RageCoop.Client
|
||||
Vector3 endPos = subject.LastWeaponImpactPosition;
|
||||
if (endPos==default)
|
||||
{
|
||||
if (i>5)
|
||||
{
|
||||
endPos=subject.GetAimCoord();
|
||||
if (subject.IsInVehicle() && subject.VehicleWeapon!=VehicleWeaponHash.Invalid)
|
||||
{
|
||||
if (subject.IsOnTurretSeat())
|
||||
{
|
||||
TriggerBulletShot((uint)subject.VehicleWeapon, c, endPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
TriggerVehBulletShot((uint)subject.VehicleWeapon, subject.CurrentVehicle, c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TriggerBulletShot((uint)subject.Weapons.Current.Hash, c, endPos);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
i++;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (subject.IsInVehicle() && subject.VehicleWeapon!=VehicleWeaponHash.Invalid)
|
||||
if (++i<=5) { return false; }
|
||||
|
||||
endPos = subject.GetAimCoord();
|
||||
if (subject.IsInVehicle() && subject.VehicleWeapon != VehicleWeaponHash.Invalid)
|
||||
{
|
||||
if (subject.IsOnTurretSeat())
|
||||
{
|
||||
@ -346,8 +317,25 @@ namespace RageCoop.Client
|
||||
return true;
|
||||
}
|
||||
|
||||
if (subject.IsInVehicle() && subject.VehicleWeapon != VehicleWeaponHash.Invalid)
|
||||
{
|
||||
if (subject.IsOnTurretSeat())
|
||||
{
|
||||
TriggerBulletShot((uint)subject.VehicleWeapon, c, endPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
TriggerVehBulletShot((uint)subject.VehicleWeapon, subject.CurrentVehicle, c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TriggerBulletShot((uint)subject.Weapons.Current.Hash, c, endPos);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!getBulletImpact())
|
||||
{
|
||||
Main.QueueAction(getBulletImpact);
|
||||
@ -357,10 +345,8 @@ namespace RageCoop.Client
|
||||
{
|
||||
TriggerBulletShot((uint)VehicleWeaponHash.Tank, c, subject.LastWeaponImpactPosition);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Vehicles
|
||||
var g = subject.IsGettingIntoVehicle;
|
||||
if (g && (!c._lastEnteringVehicle))
|
||||
@ -368,6 +354,7 @@ namespace RageCoop.Client
|
||||
var v = subject.VehicleTryingToEnter.GetSyncEntity();
|
||||
TriggerEnteringVehicle(c, v, subject.GetSeatTryingToEnter());
|
||||
}
|
||||
|
||||
var currentSitting = subject.IsSittingInVehicle();
|
||||
if (c._lastSittingInVehicle)
|
||||
{
|
||||
@ -391,18 +378,20 @@ namespace RageCoop.Client
|
||||
|
||||
public static void Check(SyncedVehicle v)
|
||||
{
|
||||
if (v.MainVehicle!=null&&v.MainVehicle.HasNozzle())
|
||||
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();
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GTA.Math;
|
||||
using GTA;
|
||||
using SHVDN;
|
||||
@ -40,8 +37,6 @@ internal static unsafe class Memory
|
||||
public static MemPatch TimeScalePatch;
|
||||
static Memory()
|
||||
{
|
||||
|
||||
|
||||
// Weapon/radio wheel slow-mo patch
|
||||
// Thanks @CamxxCore, https://github.com/CamxxCore/GTAVWeaponWheelMod
|
||||
var result = NativeMemory.FindPattern("\x38\x51\x64\x74\x19", "xxxxx");
|
||||
@ -73,27 +68,13 @@ internal static unsafe class Memory
|
||||
public const int MatrixOffset = 96;
|
||||
#endregion
|
||||
#region OPCODE
|
||||
|
||||
const byte XOR_32_64 = 0x31;
|
||||
const byte RET = 0xC3;
|
||||
|
||||
#endregion
|
||||
public static Vector3 ReadPosition(this Entity e)
|
||||
{
|
||||
return ReadVector3(e.MemoryAddress+PositionOffset);
|
||||
}
|
||||
public static Quaternion ReadQuaternion(this Entity e)
|
||||
{
|
||||
return Quaternion.RotationMatrix(e.Matrix);
|
||||
}
|
||||
public static Vector3 ReadRotation(this Entity e)
|
||||
{
|
||||
return e.ReadQuaternion().ToEulerDegrees();
|
||||
}
|
||||
public static Vector3 ReadVelocity(this Ped e)
|
||||
{
|
||||
return ReadVector3(e.MemoryAddress+VelocityOffset);
|
||||
}
|
||||
public static Vector3 ReadPosition(this Entity e) => ReadVector3(e.MemoryAddress + PositionOffset);
|
||||
public static Quaternion ReadQuaternion(this Entity e) => Quaternion.RotationMatrix(e.Matrix);
|
||||
public static Vector3 ReadRotation(this Entity e) => e.ReadQuaternion().ToEulerDegrees();
|
||||
public static Vector3 ReadVelocity(this Ped e) => ReadVector3(e.MemoryAddress+VelocityOffset);
|
||||
public static Vector3 ReadVector3(IntPtr address)
|
||||
{
|
||||
float* ptr = (float*)address.ToPointer();
|
||||
|
@ -28,15 +28,11 @@ namespace RageCoop.Client
|
||||
|
||||
private void OnTick(object sender, EventArgs e)
|
||||
{
|
||||
if (Game.IsLoading)
|
||||
if (Game.IsLoading || !Networking.IsOnServer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Networking.IsOnServer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Game.DisableControlThisFrame(Control.FrontendPause);
|
||||
if (Main.Settings.DisableAlternatePause)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user