From 474cba33fa233c5df20a79e4ad1658d5ce856e0a Mon Sep 17 00:00:00 2001
From: EntenKoeniq <81123713+EntenKoeniq@users.noreply.github.com>
Date: Sun, 20 Mar 2022 09:21:41 +0100
Subject: [PATCH] Unused variables removed. MasterServer connection updated
---
Client/COOPAPI.cs | 2 +-
Client/Entities/NPC/EntitiesNPC.cs | 1 +
Client/Entities/NPC/Sync/OnFootSync.cs | 6 +--
Client/Entities/NPC/Sync/VehicleSync.cs | 23 +++---------
Client/Entities/Player/EntitiesPlayer.cs | 1 +
Client/Entities/Player/Sync/OnFootSync.cs | 6 +--
Client/Entities/Player/Sync/VehicleSync.cs | 43 ++++++----------------
Client/Main.cs | 6 +--
Client/Networking.cs | 8 ++--
Client/PlayerList.cs | 4 +-
Server/Server.cs | 22 +++--------
11 files changed, 34 insertions(+), 88 deletions(-)
diff --git a/Client/COOPAPI.cs b/Client/COOPAPI.cs
index 5a82167..28b2b39 100644
--- a/Client/COOPAPI.cs
+++ b/Client/COOPAPI.cs
@@ -274,7 +274,7 @@ namespace CoopClient
/// otherwise it will align right
///
///
- public static void SetPlayerListLeftAlign( bool leftAlign )
+ public static void SetPlayerListLeftAlign(bool leftAlign)
{
PlayerList.LeftAlign = leftAlign;
}
diff --git a/Client/Entities/NPC/EntitiesNPC.cs b/Client/Entities/NPC/EntitiesNPC.cs
index ededc04..12356a2 100644
--- a/Client/Entities/NPC/EntitiesNPC.cs
+++ b/Client/Entities/NPC/EntitiesNPC.cs
@@ -29,6 +29,7 @@ namespace CoopClient.Entities.NPC
internal Dictionary Clothes { get; set; }
internal Vector3 Position { get; set; }
+ internal Vector3 Velocity { get; set; }
internal Vector3 AimCoords { get; set; }
internal void DisplayLocally()
diff --git a/Client/Entities/NPC/Sync/OnFootSync.cs b/Client/Entities/NPC/Sync/OnFootSync.cs
index bf3986a..ef7ed46 100644
--- a/Client/Entities/NPC/Sync/OnFootSync.cs
+++ b/Client/Entities/NPC/Sync/OnFootSync.cs
@@ -8,15 +8,11 @@ namespace CoopClient.Entities.NPC
{
internal partial class EntitiesNPC
{
- #region -- ON FOOT --
+ #region -- VARIABLES --
///
/// The latest character rotation (may not have been applied yet)
///
public Vector3 Rotation { get; internal set; }
- ///
- /// The latest character velocity (may not have been applied yet)
- ///
- public Vector3 Velocity { get; internal set; }
internal byte Speed { get; set; }
private bool LastIsJumping = false;
internal bool IsJumping { get; set; }
diff --git a/Client/Entities/NPC/Sync/VehicleSync.cs b/Client/Entities/NPC/Sync/VehicleSync.cs
index 6db1ed3..972a333 100644
--- a/Client/Entities/NPC/Sync/VehicleSync.cs
+++ b/Client/Entities/NPC/Sync/VehicleSync.cs
@@ -25,18 +25,7 @@ namespace CoopClient.Entities.NPC
internal short VehicleSeatIndex { get; set; }
internal Vehicle MainVehicle { get; set; }
internal Quaternion VehicleRotation { get; set; }
- internal Vector3 VehicleVelocity { get; set; }
- private float LastVehicleSpeed { get; set; }
- private float CurrentVehicleSpeed { get; set; }
- internal float VehicleSpeed
- {
- get => CurrentVehicleSpeed;
- set
- {
- LastVehicleSpeed = CurrentVehicleSpeed;
- CurrentVehicleSpeed = value;
- }
- }
+ internal float VehicleSpeed { get; set; }
internal float VehicleSteeringAngle { get; set; }
internal bool VehIsEngineRunning { get; set; }
internal float VehRPM { get; set; }
@@ -134,15 +123,15 @@ namespace CoopClient.Entities.NPC
if (Character.IsOnBike && MainVehicle.ClassType == VehicleClass.Cycles)
{
bool isFastPedaling = Function.Call(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "fast_pedal_char", 3);
- if (CurrentVehicleSpeed < 0.2f)
+ if (VehicleSpeed < 0.2f)
{
StopPedalingAnim(isFastPedaling);
}
- else if (CurrentVehicleSpeed < 11f && !Function.Call(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "cruise_pedal_char", 3))
+ else if (VehicleSpeed < 11f && !Function.Call(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "cruise_pedal_char", 3))
{
StartPedalingAnim(false);
}
- else if (CurrentVehicleSpeed >= 11f && !isFastPedaling)
+ else if (VehicleSpeed >= 11f && !isFastPedaling)
{
StartPedalingAnim(true);
}
@@ -252,11 +241,11 @@ namespace CoopClient.Entities.NPC
}
// 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;
- MainVehicle.Velocity = VehicleVelocity + forceMultiplier * (Position - MainVehicle.Position);
+ MainVehicle.Velocity = Velocity + forceMultiplier * (Position - MainVehicle.Position);
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);
VehicleStopTime = Util.GetTickCount64();
diff --git a/Client/Entities/Player/EntitiesPlayer.cs b/Client/Entities/Player/EntitiesPlayer.cs
index 9f6398c..eecb994 100644
--- a/Client/Entities/Player/EntitiesPlayer.cs
+++ b/Client/Entities/Player/EntitiesPlayer.cs
@@ -59,6 +59,7 @@ namespace CoopClient.Entities.Player
/// The latest character position (may not have been applied yet)
///
public Vector3 Position { get; internal set; }
+ internal Vector3 Velocity { get; set; }
internal Blip PedBlip = null;
internal Vector3 AimCoords { get; set; }
diff --git a/Client/Entities/Player/Sync/OnFootSync.cs b/Client/Entities/Player/Sync/OnFootSync.cs
index 047f614..5238de6 100644
--- a/Client/Entities/Player/Sync/OnFootSync.cs
+++ b/Client/Entities/Player/Sync/OnFootSync.cs
@@ -9,15 +9,11 @@ namespace CoopClient.Entities.Player
{
public partial class EntitiesPlayer
{
- #region -- ON FOOT --
+ #region -- VARIABLES --
///
/// The latest character rotation (may not have been applied yet)
///
public Vector3 Rotation { get; internal set; }
- ///
- /// The latest character velocity (may not have been applied yet)
- ///
- public Vector3 Velocity { get; internal set; }
internal byte Speed { get; set; }
private bool LastIsJumping = false;
internal bool IsJumping { get; set; }
diff --git a/Client/Entities/Player/Sync/VehicleSync.cs b/Client/Entities/Player/Sync/VehicleSync.cs
index 7bbcd37..63bce69 100644
--- a/Client/Entities/Player/Sync/VehicleSync.cs
+++ b/Client/Entities/Player/Sync/VehicleSync.cs
@@ -13,20 +13,10 @@ namespace CoopClient.Entities.Player
private ulong VehicleStopTime { get; set; }
internal bool IsInVehicle { get; set; }
- private int LastVehicleModelHash = 0;
- private int CurrentVehicleModelHash = 0;
///
/// The latest vehicle model hash (may not have been applied yet)
///
- public int VehicleModelHash
- {
- get => CurrentVehicleModelHash;
- internal set
- {
- LastVehicleModelHash = CurrentVehicleModelHash == 0 ? value : CurrentVehicleModelHash;
- CurrentVehicleModelHash = value;
- }
- }
+ public int VehicleModelHash { get; internal set; }
private byte[] LastVehicleColors = new byte[] { 0, 0 };
internal byte[] VehicleColors { get; set; }
private Dictionary LastVehicleMods = new Dictionary();
@@ -42,18 +32,7 @@ namespace CoopClient.Entities.Player
/// The latest vehicle rotation (may not have been applied yet)
///
public Quaternion VehicleRotation { get; internal set; }
- internal Vector3 VehicleVelocity { get; set; }
- private float LastVehicleSpeed { get; set; }
- private float CurrentVehicleSpeed { get; set; }
- internal float VehicleSpeed
- {
- get => CurrentVehicleSpeed;
- set
- {
- LastVehicleSpeed = CurrentVehicleSpeed;
- CurrentVehicleSpeed = value;
- }
- }
+ internal float VehicleSpeed { get; set; }
internal float VehicleSteeringAngle { get; set; }
private int LastVehicleAim;
internal bool VehIsEngineRunning { get; set; }
@@ -73,11 +52,11 @@ namespace CoopClient.Entities.Player
private void DisplayInVehicle()
{
- if (MainVehicle == null || !MainVehicle.Exists() || MainVehicle.Model.Hash != CurrentVehicleModelHash)
+ if (MainVehicle == null || !MainVehicle.Exists() || MainVehicle.Model.Hash != VehicleModelHash)
{
bool vehFound = false;
- Vehicle targetVehicle = World.GetClosestVehicle(Position, 7f, new Model[] { CurrentVehicleModelHash });
+ Vehicle targetVehicle = World.GetClosestVehicle(Position, 7f, new Model[] { VehicleModelHash });
if (targetVehicle != null)
{
@@ -90,7 +69,7 @@ namespace CoopClient.Entities.Player
if (!vehFound)
{
- Model vehicleModel = CurrentVehicleModelHash.ModelRequest();
+ Model vehicleModel = VehicleModelHash.ModelRequest();
if (vehicleModel == null)
{
//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)
{
bool isFastPedaling = Function.Call(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "fast_pedal_char", 3);
- if (CurrentVehicleSpeed < 0.2f)
+ if (VehicleSpeed < 0.2f)
{
StopPedalingAnim(isFastPedaling);
}
- else if (CurrentVehicleSpeed < 11f && !Function.Call(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "cruise_pedal_char", 3))
+ else if (VehicleSpeed < 11f && !Function.Call(Hash.IS_ENTITY_PLAYING_ANIM, Character.Handle, PedalingAnimDict(), "cruise_pedal_char", 3))
{
StartPedalingAnim(false);
}
- else if (CurrentVehicleSpeed >= 11f && !isFastPedaling)
+ else if (VehicleSpeed >= 11f && !isFastPedaling)
{
StartPedalingAnim(true);
}
@@ -275,11 +254,11 @@ namespace CoopClient.Entities.Player
}
// 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;
- MainVehicle.Velocity = VehicleVelocity + forceMultiplier * (Position - MainVehicle.Position);
+ MainVehicle.Velocity = Velocity + forceMultiplier * (Position - MainVehicle.Position);
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);
VehicleStopTime = Util.GetTickCount64();
@@ -306,7 +285,7 @@ namespace CoopClient.Entities.Player
private string PedalingAnimDict()
{
- switch ((VehicleHash)CurrentVehicleModelHash)
+ switch ((VehicleHash)VehicleModelHash)
{
case VehicleHash.Bmx:
return "veh@bicycle@bmx@front@base";
diff --git a/Client/Main.cs b/Client/Main.cs
index e49dd08..fe67ba0 100644
--- a/Client/Main.cs
+++ b/Client/Main.cs
@@ -210,7 +210,6 @@ namespace CoopClient
ulong currentTimestamp = Util.GetTickCount64();
PlayerList.Pressed = (currentTimestamp - PlayerList.Pressed) < 5000 ? (currentTimestamp - 6000) : currentTimestamp;
}
- return;
}
else if (Game.IsControlJustPressed(GTA.Control.MpTextChatAll))
{
@@ -218,7 +217,6 @@ namespace CoopClient
{
MainChat.Focused = true;
}
- return;
}
break;
}
@@ -239,7 +237,6 @@ namespace CoopClient
ulong currentTimestamp = Util.GetTickCount64();
PlayerList.Pressed = (currentTimestamp - PlayerList.Pressed) < 5000 ? (currentTimestamp - 6000) : currentTimestamp;
}
- return;
}
else if (Game.IsControlJustPressed(GTA.Control.MpTextChatAll))
{
@@ -247,7 +244,6 @@ namespace CoopClient
{
MainChat.Focused = true;
}
- return;
}
}
#endif
@@ -399,7 +395,7 @@ namespace CoopClient
DebugSyncPed.VehicleRotation = veh.Quaternion;
DebugSyncPed.VehicleEngineHealth = veh.EngineHealth;
DebugSyncPed.VehRPM = veh.CurrentRPM;
- DebugSyncPed.VehicleVelocity = veh.Velocity;
+ DebugSyncPed.Velocity = veh.Velocity;
DebugSyncPed.VehicleSpeed = veh.Speed;
DebugSyncPed.VehicleSteeringAngle = veh.SteeringAngle;
DebugSyncPed.AimCoords = veh.IsTurretSeat((int)player.SeatIndex) ? Util.GetVehicleAimCoords() : new GTA.Math.Vector3();
diff --git a/Client/Networking.cs b/Client/Networking.cs
index 5666452..cc2cdd1 100644
--- a/Client/Networking.cs
+++ b/Client/Networking.cs
@@ -526,7 +526,7 @@ namespace CoopClient
player.VehicleRotation = packet.VehRotation.ToQuaternion();
player.VehicleEngineHealth = packet.VehEngineHealth;
player.VehRPM = packet.VehRPM;
- player.VehicleVelocity = packet.VehVelocity.ToVector();
+ player.Velocity = packet.VehVelocity.ToVector();
player.VehicleSpeed = packet.VehSpeed;
player.VehicleSteeringAngle = packet.VehSteeringAngle;
player.AimCoords = packet.VehAimCoords.ToVector();
@@ -593,7 +593,7 @@ namespace CoopClient
player.VehicleSeatIndex = packet.VehSeatIndex;
player.Position = packet.Position.ToVector();
player.VehicleRotation = packet.VehRotation.ToQuaternion();
- player.VehicleVelocity = packet.VehVelocity.ToVector();
+ player.Velocity = packet.VehVelocity.ToVector();
player.VehicleSpeed = packet.VehSpeed;
player.VehicleSteeringAngle = packet.VehSteeringAngle;
player.AimCoords = packet.AimCoords.ToVector();
@@ -829,7 +829,7 @@ namespace CoopClient
npc.VehicleRotation = packet.VehRotation.ToQuaternion();
npc.VehicleEngineHealth = packet.VehEngineHealth;
npc.VehRPM = packet.VehRPM;
- npc.VehicleVelocity = packet.VehVelocity.ToVector();
+ npc.Velocity = packet.VehVelocity.ToVector();
npc.VehicleSpeed = packet.VehSpeed;
npc.VehicleSteeringAngle = packet.VehSteeringAngle;
npc.VehicleColors = packet.VehColors;
@@ -864,7 +864,7 @@ namespace CoopClient
VehicleRotation = packet.VehRotation.ToQuaternion(),
VehicleEngineHealth = packet.VehEngineHealth,
VehRPM = packet.VehRPM,
- VehicleVelocity = packet.VehVelocity.ToVector(),
+ Velocity = packet.VehVelocity.ToVector(),
VehicleSpeed = packet.VehSpeed,
VehicleSteeringAngle = packet.VehSteeringAngle,
VehicleColors = packet.VehColors,
diff --git a/Client/PlayerList.cs b/Client/PlayerList.cs
index 56950a0..87fc4c2 100644
--- a/Client/PlayerList.cs
+++ b/Client/PlayerList.cs
@@ -19,7 +19,7 @@ namespace CoopClient
private ulong LastUpdate = Util.GetTickCount64();
internal static ulong Pressed { get; set; }
- public static bool LeftAlign = true;
+ internal static bool LeftAlign = true;
///
/// Don't use it!
@@ -56,7 +56,7 @@ namespace CoopClient
)
{
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,
255, 255, 255, 255, 0);
}
diff --git a/Server/Server.cs b/Server/Server.cs
index 3da69c8..69511ba 100644
--- a/Server/Server.cs
+++ b/Server/Server.cs
@@ -94,7 +94,7 @@ namespace CoopServer
try
{
- string data = await httpClient.GetStringAsync("https://wimip.info/json");
+ string data = await httpClient.GetStringAsync("https://ipinfo.io/json");
info = JsonConvert.DeserializeObject(data);
}
@@ -103,8 +103,6 @@ namespace CoopServer
info = new() { ip = MainNetServer.Configuration.LocalAddress.ToString(), country = "?" };
}
- byte errorCounter = 3;
-
while (!Program.ReadyToStop)
{
string msg =
@@ -133,7 +131,7 @@ namespace CoopServer
}
catch (Exception ex)
{
- Logging.Error(ex.Message);
+ Logging.Error($"MasterServer: {ex.Message}");
break;
}
@@ -141,21 +139,11 @@ namespace CoopServer
{
Logging.Error($"MasterServer: [{(int)response.StatusCode}]{response.StatusCode}");
- if (errorCounter != 0)
- {
- Logging.Error($"MasterServer: Remaining attempts {errorCounter--} ...");
-
- // Wait 5 seconds before trying again
- Thread.Sleep(5000);
- continue;
- }
-
- break;
+ // Wait 5 seconds before trying again
+ Thread.Sleep(5000);
+ continue;
}
- // Reset errorCounter
- errorCounter = 3;
-
// Sleep for 12.5s
Thread.Sleep(12500);
}