Unused variables removed. MasterServer connection updated

This commit is contained in:
EntenKoeniq 2022-03-20 09:21:41 +01:00
parent d64281e582
commit 474cba33fa
11 changed files with 34 additions and 88 deletions

View File

@ -274,7 +274,7 @@ namespace CoopClient
/// otherwise it will align right /// otherwise it will align right
/// </summary> /// </summary>
/// <param name="leftAlign"></param> /// <param name="leftAlign"></param>
public static void SetPlayerListLeftAlign( bool leftAlign ) public static void SetPlayerListLeftAlign(bool leftAlign)
{ {
PlayerList.LeftAlign = leftAlign; PlayerList.LeftAlign = leftAlign;
} }

View File

@ -29,6 +29,7 @@ namespace CoopClient.Entities.NPC
internal Dictionary<byte, short> Clothes { get; set; } internal Dictionary<byte, short> Clothes { get; set; }
internal Vector3 Position { get; set; } internal Vector3 Position { get; set; }
internal Vector3 Velocity { get; set; }
internal Vector3 AimCoords { get; set; } internal Vector3 AimCoords { get; set; }
internal void DisplayLocally() internal void DisplayLocally()

View File

@ -8,15 +8,11 @@ namespace CoopClient.Entities.NPC
{ {
internal partial class EntitiesNPC internal partial class EntitiesNPC
{ {
#region -- ON FOOT -- #region -- VARIABLES --
/// <summary> /// <summary>
/// The latest character rotation (may not have been applied yet) /// The latest character rotation (may not have been applied yet)
/// </summary> /// </summary>
public Vector3 Rotation { get; internal set; } public Vector3 Rotation { get; internal set; }
/// <summary>
/// The latest character velocity (may not have been applied yet)
/// </summary>
public Vector3 Velocity { get; internal set; }
internal byte Speed { get; set; } internal byte Speed { get; set; }
private bool LastIsJumping = false; private bool LastIsJumping = false;
internal bool IsJumping { get; set; } internal bool IsJumping { get; set; }

View File

@ -25,18 +25,7 @@ namespace CoopClient.Entities.NPC
internal short VehicleSeatIndex { get; set; } internal short VehicleSeatIndex { get; set; }
internal Vehicle MainVehicle { get; set; } internal Vehicle MainVehicle { get; set; }
internal Quaternion VehicleRotation { get; set; } internal Quaternion VehicleRotation { get; set; }
internal Vector3 VehicleVelocity { get; set; } internal float VehicleSpeed { get; set; }
private float LastVehicleSpeed { get; set; }
private float CurrentVehicleSpeed { get; set; }
internal float VehicleSpeed
{
get => CurrentVehicleSpeed;
set
{
LastVehicleSpeed = CurrentVehicleSpeed;
CurrentVehicleSpeed = value;
}
}
internal float VehicleSteeringAngle { get; set; } internal float VehicleSteeringAngle { get; set; }
internal bool VehIsEngineRunning { get; set; } internal bool VehIsEngineRunning { get; set; }
internal float VehRPM { get; set; } internal float VehRPM { get; set; }
@ -134,15 +123,15 @@ namespace CoopClient.Entities.NPC
if (Character.IsOnBike && MainVehicle.ClassType == VehicleClass.Cycles) if (Character.IsOnBike && MainVehicle.ClassType == VehicleClass.Cycles)
{ {
bool isFastPedaling = Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "fast_pedal_char", 3); bool isFastPedaling = Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "fast_pedal_char", 3);
if (CurrentVehicleSpeed < 0.2f) if (VehicleSpeed < 0.2f)
{ {
StopPedalingAnim(isFastPedaling); StopPedalingAnim(isFastPedaling);
} }
else if (CurrentVehicleSpeed < 11f && !Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "cruise_pedal_char", 3)) else if (VehicleSpeed < 11f && !Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "cruise_pedal_char", 3))
{ {
StartPedalingAnim(false); StartPedalingAnim(false);
} }
else if (CurrentVehicleSpeed >= 11f && !isFastPedaling) else if (VehicleSpeed >= 11f && !isFastPedaling)
{ {
StartPedalingAnim(true); StartPedalingAnim(true);
} }
@ -252,11 +241,11 @@ namespace CoopClient.Entities.NPC
} }
// Good enough for now, but we need to create a better sync // Good enough for now, but we need to create a better sync
if (CurrentVehicleSpeed > 0.05f && MainVehicle.IsInRange(Position, 7.0f)) if (VehicleSpeed > 0.05f && MainVehicle.IsInRange(Position, 7.0f))
{ {
int forceMultiplier = (Game.Player.Character.IsInVehicle() && MainVehicle.IsTouching(Game.Player.Character.CurrentVehicle)) ? 1 : 3; int forceMultiplier = (Game.Player.Character.IsInVehicle() && MainVehicle.IsTouching(Game.Player.Character.CurrentVehicle)) ? 1 : 3;
MainVehicle.Velocity = VehicleVelocity + forceMultiplier * (Position - MainVehicle.Position); MainVehicle.Velocity = Velocity + forceMultiplier * (Position - MainVehicle.Position);
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f); MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);
VehicleStopTime = Util.GetTickCount64(); VehicleStopTime = Util.GetTickCount64();

View File

@ -59,6 +59,7 @@ namespace CoopClient.Entities.Player
/// The latest character position (may not have been applied yet) /// The latest character position (may not have been applied yet)
/// </summary> /// </summary>
public Vector3 Position { get; internal set; } public Vector3 Position { get; internal set; }
internal Vector3 Velocity { get; set; }
internal Blip PedBlip = null; internal Blip PedBlip = null;
internal Vector3 AimCoords { get; set; } internal Vector3 AimCoords { get; set; }

View File

@ -9,15 +9,11 @@ namespace CoopClient.Entities.Player
{ {
public partial class EntitiesPlayer public partial class EntitiesPlayer
{ {
#region -- ON FOOT -- #region -- VARIABLES --
/// <summary> /// <summary>
/// The latest character rotation (may not have been applied yet) /// The latest character rotation (may not have been applied yet)
/// </summary> /// </summary>
public Vector3 Rotation { get; internal set; } public Vector3 Rotation { get; internal set; }
/// <summary>
/// The latest character velocity (may not have been applied yet)
/// </summary>
public Vector3 Velocity { get; internal set; }
internal byte Speed { get; set; } internal byte Speed { get; set; }
private bool LastIsJumping = false; private bool LastIsJumping = false;
internal bool IsJumping { get; set; } internal bool IsJumping { get; set; }

View File

@ -13,20 +13,10 @@ namespace CoopClient.Entities.Player
private ulong VehicleStopTime { get; set; } private ulong VehicleStopTime { get; set; }
internal bool IsInVehicle { get; set; } internal bool IsInVehicle { get; set; }
private int LastVehicleModelHash = 0;
private int CurrentVehicleModelHash = 0;
/// <summary> /// <summary>
/// The latest vehicle model hash (may not have been applied yet) /// The latest vehicle model hash (may not have been applied yet)
/// </summary> /// </summary>
public int VehicleModelHash public int VehicleModelHash { get; internal set; }
{
get => CurrentVehicleModelHash;
internal set
{
LastVehicleModelHash = CurrentVehicleModelHash == 0 ? value : CurrentVehicleModelHash;
CurrentVehicleModelHash = value;
}
}
private byte[] LastVehicleColors = new byte[] { 0, 0 }; private byte[] LastVehicleColors = new byte[] { 0, 0 };
internal byte[] VehicleColors { get; set; } internal byte[] VehicleColors { get; set; }
private Dictionary<int, int> LastVehicleMods = new Dictionary<int, int>(); private Dictionary<int, int> LastVehicleMods = new Dictionary<int, int>();
@ -42,18 +32,7 @@ namespace CoopClient.Entities.Player
/// The latest vehicle rotation (may not have been applied yet) /// The latest vehicle rotation (may not have been applied yet)
/// </summary> /// </summary>
public Quaternion VehicleRotation { get; internal set; } public Quaternion VehicleRotation { get; internal set; }
internal Vector3 VehicleVelocity { get; set; } internal float VehicleSpeed { get; set; }
private float LastVehicleSpeed { get; set; }
private float CurrentVehicleSpeed { get; set; }
internal float VehicleSpeed
{
get => CurrentVehicleSpeed;
set
{
LastVehicleSpeed = CurrentVehicleSpeed;
CurrentVehicleSpeed = value;
}
}
internal float VehicleSteeringAngle { get; set; } internal float VehicleSteeringAngle { get; set; }
private int LastVehicleAim; private int LastVehicleAim;
internal bool VehIsEngineRunning { get; set; } internal bool VehIsEngineRunning { get; set; }
@ -73,11 +52,11 @@ namespace CoopClient.Entities.Player
private void DisplayInVehicle() private void DisplayInVehicle()
{ {
if (MainVehicle == null || !MainVehicle.Exists() || MainVehicle.Model.Hash != CurrentVehicleModelHash) if (MainVehicle == null || !MainVehicle.Exists() || MainVehicle.Model.Hash != VehicleModelHash)
{ {
bool vehFound = false; bool vehFound = false;
Vehicle targetVehicle = World.GetClosestVehicle(Position, 7f, new Model[] { CurrentVehicleModelHash }); Vehicle targetVehicle = World.GetClosestVehicle(Position, 7f, new Model[] { VehicleModelHash });
if (targetVehicle != null) if (targetVehicle != null)
{ {
@ -90,7 +69,7 @@ namespace CoopClient.Entities.Player
if (!vehFound) if (!vehFound)
{ {
Model vehicleModel = CurrentVehicleModelHash.ModelRequest(); Model vehicleModel = VehicleModelHash.ModelRequest();
if (vehicleModel == null) if (vehicleModel == null)
{ {
//GTA.UI.Notification.Show($"~r~(Vehicle)Model ({CurrentVehicleModelHash}) cannot be loaded!"); //GTA.UI.Notification.Show($"~r~(Vehicle)Model ({CurrentVehicleModelHash}) cannot be loaded!");
@ -157,15 +136,15 @@ namespace CoopClient.Entities.Player
if (Character.IsOnBike && MainVehicle.ClassType == VehicleClass.Cycles) if (Character.IsOnBike && MainVehicle.ClassType == VehicleClass.Cycles)
{ {
bool isFastPedaling = Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "fast_pedal_char", 3); bool isFastPedaling = Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "fast_pedal_char", 3);
if (CurrentVehicleSpeed < 0.2f) if (VehicleSpeed < 0.2f)
{ {
StopPedalingAnim(isFastPedaling); StopPedalingAnim(isFastPedaling);
} }
else if (CurrentVehicleSpeed < 11f && !Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "cruise_pedal_char", 3)) else if (VehicleSpeed < 11f && !Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "cruise_pedal_char", 3))
{ {
StartPedalingAnim(false); StartPedalingAnim(false);
} }
else if (CurrentVehicleSpeed >= 11f && !isFastPedaling) else if (VehicleSpeed >= 11f && !isFastPedaling)
{ {
StartPedalingAnim(true); StartPedalingAnim(true);
} }
@ -275,11 +254,11 @@ namespace CoopClient.Entities.Player
} }
// Good enough for now, but we need to create a better sync // Good enough for now, but we need to create a better sync
if (CurrentVehicleSpeed > 0.05f && MainVehicle.IsInRange(Position, 7.0f)) if (VehicleSpeed > 0.05f && MainVehicle.IsInRange(Position, 7.0f))
{ {
int forceMultiplier = (Game.Player.Character.IsInVehicle() && MainVehicle.IsTouching(Game.Player.Character.CurrentVehicle)) ? 1 : 3; int forceMultiplier = (Game.Player.Character.IsInVehicle() && MainVehicle.IsTouching(Game.Player.Character.CurrentVehicle)) ? 1 : 3;
MainVehicle.Velocity = VehicleVelocity + forceMultiplier * (Position - MainVehicle.Position); MainVehicle.Velocity = Velocity + forceMultiplier * (Position - MainVehicle.Position);
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f); MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);
VehicleStopTime = Util.GetTickCount64(); VehicleStopTime = Util.GetTickCount64();
@ -306,7 +285,7 @@ namespace CoopClient.Entities.Player
private string PedalingAnimDict() private string PedalingAnimDict()
{ {
switch ((VehicleHash)CurrentVehicleModelHash) switch ((VehicleHash)VehicleModelHash)
{ {
case VehicleHash.Bmx: case VehicleHash.Bmx:
return "veh@bicycle@bmx@front@base"; return "veh@bicycle@bmx@front@base";

View File

@ -210,7 +210,6 @@ namespace CoopClient
ulong currentTimestamp = Util.GetTickCount64(); ulong currentTimestamp = Util.GetTickCount64();
PlayerList.Pressed = (currentTimestamp - PlayerList.Pressed) < 5000 ? (currentTimestamp - 6000) : currentTimestamp; PlayerList.Pressed = (currentTimestamp - PlayerList.Pressed) < 5000 ? (currentTimestamp - 6000) : currentTimestamp;
} }
return;
} }
else if (Game.IsControlJustPressed(GTA.Control.MpTextChatAll)) else if (Game.IsControlJustPressed(GTA.Control.MpTextChatAll))
{ {
@ -218,7 +217,6 @@ namespace CoopClient
{ {
MainChat.Focused = true; MainChat.Focused = true;
} }
return;
} }
break; break;
} }
@ -239,7 +237,6 @@ namespace CoopClient
ulong currentTimestamp = Util.GetTickCount64(); ulong currentTimestamp = Util.GetTickCount64();
PlayerList.Pressed = (currentTimestamp - PlayerList.Pressed) < 5000 ? (currentTimestamp - 6000) : currentTimestamp; PlayerList.Pressed = (currentTimestamp - PlayerList.Pressed) < 5000 ? (currentTimestamp - 6000) : currentTimestamp;
} }
return;
} }
else if (Game.IsControlJustPressed(GTA.Control.MpTextChatAll)) else if (Game.IsControlJustPressed(GTA.Control.MpTextChatAll))
{ {
@ -247,7 +244,6 @@ namespace CoopClient
{ {
MainChat.Focused = true; MainChat.Focused = true;
} }
return;
} }
} }
#endif #endif
@ -399,7 +395,7 @@ namespace CoopClient
DebugSyncPed.VehicleRotation = veh.Quaternion; DebugSyncPed.VehicleRotation = veh.Quaternion;
DebugSyncPed.VehicleEngineHealth = veh.EngineHealth; DebugSyncPed.VehicleEngineHealth = veh.EngineHealth;
DebugSyncPed.VehRPM = veh.CurrentRPM; DebugSyncPed.VehRPM = veh.CurrentRPM;
DebugSyncPed.VehicleVelocity = veh.Velocity; DebugSyncPed.Velocity = veh.Velocity;
DebugSyncPed.VehicleSpeed = veh.Speed; DebugSyncPed.VehicleSpeed = veh.Speed;
DebugSyncPed.VehicleSteeringAngle = veh.SteeringAngle; DebugSyncPed.VehicleSteeringAngle = veh.SteeringAngle;
DebugSyncPed.AimCoords = veh.IsTurretSeat((int)player.SeatIndex) ? Util.GetVehicleAimCoords() : new GTA.Math.Vector3(); DebugSyncPed.AimCoords = veh.IsTurretSeat((int)player.SeatIndex) ? Util.GetVehicleAimCoords() : new GTA.Math.Vector3();

View File

@ -526,7 +526,7 @@ namespace CoopClient
player.VehicleRotation = packet.VehRotation.ToQuaternion(); player.VehicleRotation = packet.VehRotation.ToQuaternion();
player.VehicleEngineHealth = packet.VehEngineHealth; player.VehicleEngineHealth = packet.VehEngineHealth;
player.VehRPM = packet.VehRPM; player.VehRPM = packet.VehRPM;
player.VehicleVelocity = packet.VehVelocity.ToVector(); player.Velocity = packet.VehVelocity.ToVector();
player.VehicleSpeed = packet.VehSpeed; player.VehicleSpeed = packet.VehSpeed;
player.VehicleSteeringAngle = packet.VehSteeringAngle; player.VehicleSteeringAngle = packet.VehSteeringAngle;
player.AimCoords = packet.VehAimCoords.ToVector(); player.AimCoords = packet.VehAimCoords.ToVector();
@ -593,7 +593,7 @@ namespace CoopClient
player.VehicleSeatIndex = packet.VehSeatIndex; player.VehicleSeatIndex = packet.VehSeatIndex;
player.Position = packet.Position.ToVector(); player.Position = packet.Position.ToVector();
player.VehicleRotation = packet.VehRotation.ToQuaternion(); player.VehicleRotation = packet.VehRotation.ToQuaternion();
player.VehicleVelocity = packet.VehVelocity.ToVector(); player.Velocity = packet.VehVelocity.ToVector();
player.VehicleSpeed = packet.VehSpeed; player.VehicleSpeed = packet.VehSpeed;
player.VehicleSteeringAngle = packet.VehSteeringAngle; player.VehicleSteeringAngle = packet.VehSteeringAngle;
player.AimCoords = packet.AimCoords.ToVector(); player.AimCoords = packet.AimCoords.ToVector();
@ -829,7 +829,7 @@ namespace CoopClient
npc.VehicleRotation = packet.VehRotation.ToQuaternion(); npc.VehicleRotation = packet.VehRotation.ToQuaternion();
npc.VehicleEngineHealth = packet.VehEngineHealth; npc.VehicleEngineHealth = packet.VehEngineHealth;
npc.VehRPM = packet.VehRPM; npc.VehRPM = packet.VehRPM;
npc.VehicleVelocity = packet.VehVelocity.ToVector(); npc.Velocity = packet.VehVelocity.ToVector();
npc.VehicleSpeed = packet.VehSpeed; npc.VehicleSpeed = packet.VehSpeed;
npc.VehicleSteeringAngle = packet.VehSteeringAngle; npc.VehicleSteeringAngle = packet.VehSteeringAngle;
npc.VehicleColors = packet.VehColors; npc.VehicleColors = packet.VehColors;
@ -864,7 +864,7 @@ namespace CoopClient
VehicleRotation = packet.VehRotation.ToQuaternion(), VehicleRotation = packet.VehRotation.ToQuaternion(),
VehicleEngineHealth = packet.VehEngineHealth, VehicleEngineHealth = packet.VehEngineHealth,
VehRPM = packet.VehRPM, VehRPM = packet.VehRPM,
VehicleVelocity = packet.VehVelocity.ToVector(), Velocity = packet.VehVelocity.ToVector(),
VehicleSpeed = packet.VehSpeed, VehicleSpeed = packet.VehSpeed,
VehicleSteeringAngle = packet.VehSteeringAngle, VehicleSteeringAngle = packet.VehSteeringAngle,
VehicleColors = packet.VehColors, VehicleColors = packet.VehColors,

View File

@ -19,7 +19,7 @@ namespace CoopClient
private ulong LastUpdate = Util.GetTickCount64(); private ulong LastUpdate = Util.GetTickCount64();
internal static ulong Pressed { get; set; } internal static ulong Pressed { get; set; }
public static bool LeftAlign = true; internal static bool LeftAlign = true;
/// <summary> /// <summary>
/// Don't use it! /// Don't use it!
@ -56,7 +56,7 @@ namespace CoopClient
) )
{ {
Function.Call(Hash.DRAW_SCALEFORM_MOVIE, MainScaleform.Handle, Function.Call(Hash.DRAW_SCALEFORM_MOVIE, MainScaleform.Handle,
LeftAlign? LEFT_POSITION:RIGHT_POSITION, 0.3f, LeftAlign ? LEFT_POSITION : RIGHT_POSITION, 0.3f,
0.28f, 0.6f, 0.28f, 0.6f,
255, 255, 255, 255, 0); 255, 255, 255, 255, 0);
} }

View File

@ -94,7 +94,7 @@ namespace CoopServer
try try
{ {
string data = await httpClient.GetStringAsync("https://wimip.info/json"); string data = await httpClient.GetStringAsync("https://ipinfo.io/json");
info = JsonConvert.DeserializeObject<IpInfo>(data); info = JsonConvert.DeserializeObject<IpInfo>(data);
} }
@ -103,8 +103,6 @@ namespace CoopServer
info = new() { ip = MainNetServer.Configuration.LocalAddress.ToString(), country = "?" }; info = new() { ip = MainNetServer.Configuration.LocalAddress.ToString(), country = "?" };
} }
byte errorCounter = 3;
while (!Program.ReadyToStop) while (!Program.ReadyToStop)
{ {
string msg = string msg =
@ -133,7 +131,7 @@ namespace CoopServer
} }
catch (Exception ex) catch (Exception ex)
{ {
Logging.Error(ex.Message); Logging.Error($"MasterServer: {ex.Message}");
break; break;
} }
@ -141,21 +139,11 @@ namespace CoopServer
{ {
Logging.Error($"MasterServer: [{(int)response.StatusCode}]{response.StatusCode}"); Logging.Error($"MasterServer: [{(int)response.StatusCode}]{response.StatusCode}");
if (errorCounter != 0) // Wait 5 seconds before trying again
{ Thread.Sleep(5000);
Logging.Error($"MasterServer: Remaining attempts {errorCounter--} ..."); continue;
// Wait 5 seconds before trying again
Thread.Sleep(5000);
continue;
}
break;
} }
// Reset errorCounter
errorCounter = 3;
// Sleep for 12.5s // Sleep for 12.5s
Thread.Sleep(12500); Thread.Sleep(12500);
} }