Code conventions. Small changes and bug fixes

This commit is contained in:
EntenKoeniq
2022-04-10 14:34:55 +02:00
parent 244b4148cf
commit 75fb2c29d3
20 changed files with 367 additions and 355 deletions

View File

@ -77,7 +77,7 @@ namespace CoopClient.Entities
foreach (NPC.EntitiesNPC npc in localNPCs.Values) foreach (NPC.EntitiesNPC npc in localNPCs.Values)
{ {
npc.DisplayLocally(); npc.Update();
} }
// Only if that player wants to share his NPCs with others // Only if that player wants to share his NPCs with others

View File

@ -13,26 +13,25 @@ namespace CoopClient.Entities.NPC
internal Ped Character { get; set; } internal Ped Character { get; set; }
internal int Health { get; set; } internal int Health { get; set; }
private int LastModelHash = 0; private int _lastModelHash = 0;
private int CurrentModelHash = 0; private int _currentModelHash = 0;
internal int ModelHash internal int ModelHash
{ {
get => CurrentModelHash; get => _currentModelHash;
set set
{ {
LastModelHash = LastModelHash == 0 ? value : CurrentModelHash; _lastModelHash = _lastModelHash == 0 ? value : _currentModelHash;
CurrentModelHash = value; _currentModelHash = value;
} }
} }
private Dictionary<byte, short> LastClothes = null; private Dictionary<byte, short> _lastClothes = null;
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 Velocity { get; set; }
internal Vector3 AimCoords { get; set; } internal Vector3 AimCoords { get; set; }
internal void DisplayLocally() internal void Update()
{ {
#region NOT_IN_RANGE #region NOT_IN_RANGE
if (!Game.Player.Character.IsInRange(Position, 500f)) if (!Game.Player.Character.IsInRange(Position, 500f))
@ -61,7 +60,7 @@ namespace CoopClient.Entities.NPC
} }
else if (LastSyncWasFull) else if (LastSyncWasFull)
{ {
if (CurrentModelHash != LastModelHash) if (_currentModelHash != _lastModelHash)
{ {
Character.Kill(); Character.Kill();
Character.Delete(); Character.Delete();
@ -71,14 +70,9 @@ namespace CoopClient.Entities.NPC
return; return;
} }
} }
else if (!Clothes.Compare(LastClothes)) else if (!Clothes.Compare(_lastClothes))
{ {
foreach (KeyValuePair<byte, short> cloth in Clothes) SetClothes();
{
Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, cloth.Key, cloth.Value, 0, 0);
}
LastClothes = Clothes;
} }
} }
@ -117,7 +111,7 @@ namespace CoopClient.Entities.NPC
private bool CreateCharacter() private bool CreateCharacter()
{ {
Model characterModel = CurrentModelHash.ModelRequest(); Model characterModel = _currentModelHash.ModelRequest();
if (characterModel == null) if (characterModel == null)
{ {
@ -147,12 +141,19 @@ namespace CoopClient.Entities.NPC
Function.Call(Hash.SET_PED_AS_ENEMY, Character.Handle, false); Function.Call(Hash.SET_PED_AS_ENEMY, Character.Handle, false);
Function.Call(Hash.SET_CAN_ATTACK_FRIENDLY, Character.Handle, true, true); Function.Call(Hash.SET_CAN_ATTACK_FRIENDLY, Character.Handle, true, true);
SetClothes();
return true;
}
private void SetClothes()
{
foreach (KeyValuePair<byte, short> cloth in Clothes) foreach (KeyValuePair<byte, short> cloth in Clothes)
{ {
Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, cloth.Key, cloth.Value, 0, 0); Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, cloth.Key, cloth.Value, 0, 0);
} }
return true; _lastClothes = Clothes;
} }
} }
} }

View File

@ -14,7 +14,7 @@ namespace CoopClient.Entities.NPC
/// </summary> /// </summary>
public Vector3 Rotation { get; internal set; } public Vector3 Rotation { 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; }
internal bool IsRagdoll { get; set; } internal bool IsRagdoll { get; set; }
internal bool IsOnFire { get; set; } internal bool IsOnFire { get; set; }
@ -22,9 +22,9 @@ namespace CoopClient.Entities.NPC
internal bool IsShooting { get; set; } internal bool IsShooting { get; set; }
internal bool IsReloading { get; set; } internal bool IsReloading { get; set; }
internal uint CurrentWeaponHash { get; set; } internal uint CurrentWeaponHash { get; set; }
private Dictionary<uint, bool> LastWeaponComponents = null; private Dictionary<uint, bool> _lastWeaponComponents = null;
internal Dictionary<uint, bool> WeaponComponents { get; set; } = null; internal Dictionary<uint, bool> WeaponComponents { get; set; } = null;
private int LastWeaponObj = 0; private int _lastWeaponObj = 0;
#endregion #endregion
private void DisplayOnFoot() private void DisplayOnFoot()
@ -57,12 +57,12 @@ namespace CoopClient.Entities.NPC
} }
} }
if (IsJumping && !LastIsJumping) if (IsJumping && !_lastIsJumping)
{ {
Character.Task.Jump(); Character.Task.Jump();
} }
LastIsJumping = IsJumping; _lastIsJumping = IsJumping;
if (IsRagdoll) if (IsRagdoll)
{ {
@ -98,7 +98,7 @@ namespace CoopClient.Entities.NPC
return; return;
} }
if (Character.Weapons.Current.Hash != (WeaponHash)CurrentWeaponHash || !WeaponComponents.Compare(LastWeaponComponents)) if (Character.Weapons.Current.Hash != (WeaponHash)CurrentWeaponHash || !WeaponComponents.Compare(_lastWeaponComponents))
{ {
Character.Weapons.RemoveAll(); Character.Weapons.RemoveAll();
@ -110,21 +110,21 @@ namespace CoopClient.Entities.NPC
} }
else else
{ {
LastWeaponObj = Function.Call<int>(Hash.CREATE_WEAPON_OBJECT, CurrentWeaponHash, -1, Position.X, Position.Y, Position.Z, true, 0, 0); _lastWeaponObj = Function.Call<int>(Hash.CREATE_WEAPON_OBJECT, CurrentWeaponHash, -1, Position.X, Position.Y, Position.Z, true, 0, 0);
foreach (KeyValuePair<uint, bool> comp in WeaponComponents) foreach (KeyValuePair<uint, bool> comp in WeaponComponents)
{ {
if (comp.Value) if (comp.Value)
{ {
Function.Call(Hash.GIVE_WEAPON_COMPONENT_TO_WEAPON_OBJECT, LastWeaponObj, comp.Key); Function.Call(Hash.GIVE_WEAPON_COMPONENT_TO_WEAPON_OBJECT, _lastWeaponObj, comp.Key);
} }
} }
Function.Call(Hash.GIVE_WEAPON_OBJECT_TO_PED, LastWeaponObj, Character.Handle); Function.Call(Hash.GIVE_WEAPON_OBJECT_TO_PED, _lastWeaponObj, Character.Handle);
} }
} }
LastWeaponComponents = WeaponComponents; _lastWeaponComponents = WeaponComponents;
} }
if (IsShooting) if (IsShooting)

View File

@ -12,13 +12,13 @@ namespace CoopClient.Entities.NPC
{ {
#region -- VARIABLES -- #region -- VARIABLES --
internal long PlayerVehicleHandle = 0; internal long PlayerVehicleHandle = 0;
private ulong VehicleStopTime { get; set; } private ulong _vehicleStopTime { get; set; }
internal bool IsInVehicle { get; set; } internal bool IsInVehicle { get; set; }
internal int VehicleModelHash { get; set; } internal int VehicleModelHash { get; set; }
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>();
internal Dictionary<int, int> VehicleMods { get; set; } internal Dictionary<int, int> VehicleMods { get; set; }
internal bool VehicleDead { get; set; } internal bool VehicleDead { get; set; }
internal float VehicleEngineHealth { get; set; } internal float VehicleEngineHealth { get; set; }
@ -29,9 +29,9 @@ namespace CoopClient.Entities.NPC
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; }
private bool LastTransformed = false; private bool _lastTransformed = false;
internal bool Transformed { get; set; } internal bool Transformed { get; set; }
private bool LastHornActive = false; private bool _lastHornActive = false;
internal bool IsHornActive { get; set; } internal bool IsHornActive { get; set; }
internal bool VehAreLightsOn { get; set; } internal bool VehAreLightsOn { get; set; }
internal bool VehAreBrakeLightsOn = false; internal bool VehAreBrakeLightsOn = false;
@ -126,11 +126,11 @@ namespace CoopClient.Entities.NPC
return; return;
} }
if (VehicleColors != null && VehicleColors != LastVehicleColors) if (VehicleColors != null && VehicleColors != _lastVehicleColors)
{ {
Function.Call(Hash.SET_VEHICLE_COLOURS, MainVehicle, VehicleColors[0], VehicleColors[1]); Function.Call(Hash.SET_VEHICLE_COLOURS, MainVehicle, VehicleColors[0], VehicleColors[1]);
LastVehicleColors = VehicleColors; _lastVehicleColors = VehicleColors;
} }
if (Character.IsOnBike && MainVehicle.ClassType == VehicleClass.Cycles) if (Character.IsOnBike && MainVehicle.ClassType == VehicleClass.Cycles)
@ -151,7 +151,7 @@ namespace CoopClient.Entities.NPC
} }
else else
{ {
if (VehicleMods != null && !VehicleMods.Compare(LastVehicleMods)) if (VehicleMods != null && !VehicleMods.Compare(_lastVehicleMods))
{ {
Function.Call(Hash.SET_VEHICLE_MOD_KIT, MainVehicle, 0); Function.Call(Hash.SET_VEHICLE_MOD_KIT, MainVehicle, 0);
@ -160,7 +160,7 @@ namespace CoopClient.Entities.NPC
MainVehicle.Mods[(VehicleModType)mod.Key].Index = mod.Value; MainVehicle.Mods[(VehicleModType)mod.Key].Index = mod.Value;
} }
LastVehicleMods = VehicleMods; _lastVehicleMods = VehicleMods;
} }
MainVehicle.EngineHealth = VehicleEngineHealth; MainVehicle.EngineHealth = VehicleEngineHealth;
@ -193,14 +193,17 @@ namespace CoopClient.Entities.NPC
if (MainVehicle.IsSubmarineCar) if (MainVehicle.IsSubmarineCar)
{ {
if (Transformed && !LastTransformed) if (Transformed)
{ {
LastTransformed = true; if (!_lastTransformed)
Function.Call(Hash._TRANSFORM_VEHICLE_TO_SUBMARINE, MainVehicle.Handle, false); {
_lastTransformed = true;
Function.Call(Hash._TRANSFORM_VEHICLE_TO_SUBMARINE, MainVehicle.Handle, false);
}
} }
else if (!Transformed && LastTransformed) else if (_lastTransformed)
{ {
LastTransformed = false; _lastTransformed = false;
Function.Call(Hash._TRANSFORM_SUBMARINE_TO_VEHICLE, MainVehicle.Handle, false); Function.Call(Hash._TRANSFORM_SUBMARINE_TO_VEHICLE, MainVehicle.Handle, false);
} }
} }
@ -219,14 +222,17 @@ namespace CoopClient.Entities.NPC
MainVehicle.IsSirenActive = VehIsSireneActive; MainVehicle.IsSirenActive = VehIsSireneActive;
} }
if (IsHornActive && !LastHornActive) if (IsHornActive)
{ {
LastHornActive = true; if (!_lastHornActive)
MainVehicle.SoundHorn(99999); {
_lastHornActive = true;
MainVehicle.SoundHorn(99999);
}
} }
else if (!IsHornActive && LastHornActive) else if (_lastHornActive)
{ {
LastHornActive = false; _lastHornActive = false;
MainVehicle.SoundHorn(1); MainVehicle.SoundHorn(1);
} }
@ -261,11 +267,11 @@ namespace CoopClient.Entities.NPC
MainVehicle.Velocity = Velocity + 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();
} }
else if ((Util.GetTickCount64() - VehicleStopTime) <= 1000) else if ((Util.GetTickCount64() - _vehicleStopTime) <= 1000)
{ {
Vector3 posTarget = Util.LinearVectorLerp(MainVehicle.Position, Position + (Position - MainVehicle.Position), Util.GetTickCount64() - VehicleStopTime, 1000); Vector3 posTarget = Util.LinearVectorLerp(MainVehicle.Position, Position + (Position - MainVehicle.Position), Util.GetTickCount64() - _vehicleStopTime, 1000);
MainVehicle.PositionNoOffset = posTarget; MainVehicle.PositionNoOffset = posTarget;
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f); MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);

View File

@ -20,7 +20,7 @@ namespace CoopClient.Entities.Player
/// </summary> /// </summary>
public string Username { get; set; } = "Player"; public string Username { get; set; } = "Player";
private bool AllDataAvailable = false; private bool _allDataAvailable = false;
internal bool LastSyncWasFull { get; set; } = false; internal bool LastSyncWasFull { get; set; } = false;
/// <summary> /// <summary>
/// Get the last update = TickCount64() /// Get the last update = TickCount64()
@ -39,21 +39,21 @@ namespace CoopClient.Entities.Player
/// The latest character health (may not have been applied yet) /// The latest character health (may not have been applied yet)
/// </summary> /// </summary>
public int Health { get; internal set; } public int Health { get; internal set; }
private int LastModelHash = 0; private int _lastModelHash = 0;
private int CurrentModelHash = 0; private int _currentModelHash = 0;
/// <summary> /// <summary>
/// The latest character model hash (may not have been applied yet) /// The latest character model hash (may not have been applied yet)
/// </summary> /// </summary>
public int ModelHash public int ModelHash
{ {
get => CurrentModelHash; get => _currentModelHash;
internal set internal set
{ {
LastModelHash = LastModelHash == 0 ? value : CurrentModelHash; _lastModelHash = _lastModelHash == 0 ? value : _currentModelHash;
CurrentModelHash = value; _currentModelHash = value;
} }
} }
private Dictionary<byte, short> LastClothes = null; private Dictionary<byte, short> _lastClothes = null;
internal Dictionary<byte, short> Clothes { get; set; } internal Dictionary<byte, short> Clothes { get; set; }
/// <summary> /// <summary>
/// The latest character position (may not have been applied yet) /// The latest character position (may not have been applied yet)
@ -63,10 +63,10 @@ namespace CoopClient.Entities.Player
internal Blip PedBlip = null; internal Blip PedBlip = null;
internal Vector3 AimCoords { get; set; } internal Vector3 AimCoords { get; set; }
internal void DisplayLocally(string username) internal void Update()
{ {
// Check beforehand whether ped has all the required data // Check beforehand whether ped has all the required data
if (!AllDataAvailable) if (!_allDataAvailable)
{ {
if (!LastSyncWasFull) if (!LastSyncWasFull)
{ {
@ -81,14 +81,14 @@ namespace CoopClient.Entities.Player
PedBlip = World.CreateBlip(Position); PedBlip = World.CreateBlip(Position);
PedBlip.Color = BlipColor.White; PedBlip.Color = BlipColor.White;
PedBlip.Scale = 0.8f; PedBlip.Scale = 0.8f;
PedBlip.Name = username; PedBlip.Name = Username;
} }
} }
return; return;
} }
AllDataAvailable = true; _allDataAvailable = true;
} }
#region NOT_IN_RANGE #region NOT_IN_RANGE
@ -109,19 +109,16 @@ namespace CoopClient.Entities.Player
MainVehicle = null; MainVehicle = null;
} }
if (username != null) if (PedBlip != null && PedBlip.Exists())
{ {
if (PedBlip != null && PedBlip.Exists()) PedBlip.Position = Position;
{ }
PedBlip.Position = Position; else
} {
else PedBlip = World.CreateBlip(Position);
{ PedBlip.Color = BlipColor.White;
PedBlip = World.CreateBlip(Position); PedBlip.Scale = 0.8f;
PedBlip.Color = BlipColor.White; PedBlip.Name = Username;
PedBlip.Scale = 0.8f;
PedBlip.Name = username;
}
} }
return; return;
@ -133,62 +130,30 @@ namespace CoopClient.Entities.Player
if (!characterExist) if (!characterExist)
{ {
if (!CreateCharacter(username)) if (!CreateCharacter())
{ {
return; return;
} }
} }
else if (LastSyncWasFull) else if (LastSyncWasFull)
{ {
if (CurrentModelHash != LastModelHash) if (ModelHash != _lastModelHash)
{ {
Character.Kill(); Character.Kill();
Character.Delete(); Character.Delete();
if (!CreateCharacter(username)) if (!CreateCharacter())
{ {
return; return;
} }
} }
else if (!Clothes.Compare(LastClothes)) else if (!Clothes.Compare(_lastClothes))
{ {
foreach (KeyValuePair<byte, short> cloth in Clothes) SetClothes();
{
Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, cloth.Key, cloth.Value, 0, 0);
}
LastClothes = Clothes;
} }
} }
if (username != null && Character.IsVisible && Character.IsInRange(Game.Player.Character.Position, 20f)) RenderNameTag();
{
float sizeOffset;
if (GameplayCamera.IsFirstPersonAimCamActive)
{
Vector3 targetPos = Character.Bones[Bone.IKHead].Position + new Vector3(0, 0, 0.10f) + (Character.Velocity / Game.FPS);
Function.Call(Hash.SET_DRAW_ORIGIN, targetPos.X, targetPos.Y, targetPos.Z, 0);
sizeOffset = Math.Max(1f - ((GameplayCamera.Position - Character.Position).Length() / 30f), 0.30f);
}
else
{
Vector3 targetPos = Character.Bones[Bone.IKHead].Position + new Vector3(0, 0, 0.35f) + (Character.Velocity / Game.FPS);
Function.Call(Hash.SET_DRAW_ORIGIN, targetPos.X, targetPos.Y, targetPos.Z, 0);
sizeOffset = Math.Max(1f - ((GameplayCamera.Position - Character.Position).Length() / 25f), 0.25f);
}
new ScaledText(new PointF(0, 0), username, 0.4f * sizeOffset, GTA.UI.Font.ChaletLondon)
{
Outline = true,
Alignment = GTA.UI.Alignment.Center
}.Draw();
Function.Call(Hash.CLEAR_DRAW_ORIGIN);
}
if (Character.IsDead) if (Character.IsDead)
{ {
@ -223,7 +188,39 @@ namespace CoopClient.Entities.Player
#endregion #endregion
} }
private bool CreateCharacter(string username) private void RenderNameTag()
{
if (Character.IsVisible && Character.IsInRange(Game.Player.Character.Position, 20f))
{
float sizeOffset;
if (GameplayCamera.IsFirstPersonAimCamActive)
{
Vector3 targetPos = Character.Bones[Bone.IKHead].Position + new Vector3(0, 0, 0.10f) + (Character.Velocity / Game.FPS);
Function.Call(Hash.SET_DRAW_ORIGIN, targetPos.X, targetPos.Y, targetPos.Z, 0);
sizeOffset = Math.Max(1f - ((GameplayCamera.Position - Character.Position).Length() / 30f), 0.30f);
}
else
{
Vector3 targetPos = Character.Bones[Bone.IKHead].Position + new Vector3(0, 0, 0.35f) + (Character.Velocity / Game.FPS);
Function.Call(Hash.SET_DRAW_ORIGIN, targetPos.X, targetPos.Y, targetPos.Z, 0);
sizeOffset = Math.Max(1f - ((GameplayCamera.Position - Character.Position).Length() / 25f), 0.25f);
}
new ScaledText(new PointF(0, 0), Username, 0.4f * sizeOffset, GTA.UI.Font.ChaletLondon)
{
Outline = true,
Alignment = GTA.UI.Alignment.Center
}.Draw();
Function.Call(Hash.CLEAR_DRAW_ORIGIN);
}
}
private bool CreateCharacter()
{ {
if (PedBlip != null && PedBlip.Exists()) if (PedBlip != null && PedBlip.Exists())
{ {
@ -231,7 +228,7 @@ namespace CoopClient.Entities.Player
PedBlip = null; PedBlip = null;
} }
Model characterModel = CurrentModelHash.ModelRequest(); Model characterModel = ModelHash.ModelRequest();
if (characterModel == null) if (characterModel == null)
{ {
@ -258,7 +255,7 @@ namespace CoopClient.Entities.Player
Character.AddBlip(); Character.AddBlip();
Character.AttachedBlip.Color = BlipColor.White; Character.AttachedBlip.Color = BlipColor.White;
Character.AttachedBlip.Scale = 0.8f; Character.AttachedBlip.Scale = 0.8f;
Character.AttachedBlip.Name = username; Character.AttachedBlip.Name = Username;
Function.Call(Hash.SET_PED_CAN_EVASIVE_DIVE, Character.Handle, false); Function.Call(Hash.SET_PED_CAN_EVASIVE_DIVE, Character.Handle, false);
Function.Call(Hash.SET_PED_DROPS_WEAPONS_WHEN_DEAD, Character.Handle, false); Function.Call(Hash.SET_PED_DROPS_WEAPONS_WHEN_DEAD, Character.Handle, false);
@ -268,12 +265,19 @@ namespace CoopClient.Entities.Player
Function.Call(Hash.SET_PED_AS_ENEMY, Character.Handle, false); Function.Call(Hash.SET_PED_AS_ENEMY, Character.Handle, false);
Function.Call(Hash.SET_CAN_ATTACK_FRIENDLY, Character.Handle, true, true); Function.Call(Hash.SET_CAN_ATTACK_FRIENDLY, Character.Handle, true, true);
SetClothes();
return true;
}
private void SetClothes()
{
foreach (KeyValuePair<byte, short> cloth in Clothes) foreach (KeyValuePair<byte, short> cloth in Clothes)
{ {
Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, cloth.Key, cloth.Value, 0, 0); Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, cloth.Key, cloth.Value, 0, 0);
} }
return true; _lastClothes = Clothes;
} }
} }
} }

View File

@ -15,7 +15,7 @@ namespace CoopClient.Entities.Player
/// </summary> /// </summary>
public Vector3 Rotation { get; internal set; } public Vector3 Rotation { 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; }
internal bool IsOnLadder { get; set; } internal bool IsOnLadder { get; set; }
internal bool IsVaulting { get; set; } internal bool IsVaulting { get; set; }
@ -28,14 +28,14 @@ namespace CoopClient.Entities.Player
internal bool IsShooting { get; set; } internal bool IsShooting { get; set; }
internal bool IsReloading { get; set; } internal bool IsReloading { get; set; }
internal uint CurrentWeaponHash { get; set; } internal uint CurrentWeaponHash { get; set; }
private Dictionary<uint, bool> LastWeaponComponents = null; private Dictionary<uint, bool> _lastWeaponComponents = null;
internal Dictionary<uint, bool> WeaponComponents { get; set; } = null; internal Dictionary<uint, bool> WeaponComponents { get; set; } = null;
private int LastWeaponObj = 0; private int _lastWeaponObj = 0;
#endregion #endregion
private bool IsPlayingAnimation = false; private bool _isPlayingAnimation = false;
private string[] CurrentAnimation = new string[2] { "", ""}; private string[] _currentAnimation = new string[2] { "", "" };
private float AnimationStopTime = 0; private float _animationStopTime = 0;
private void DisplayOnFoot() private void DisplayOnFoot()
{ {
@ -150,16 +150,16 @@ namespace CoopClient.Entities.Player
if (IsJumping) if (IsJumping)
{ {
if (!LastIsJumping) if (!_lastIsJumping)
{ {
LastIsJumping = true; _lastIsJumping = true;
Character.Task.Jump(); Character.Task.Jump();
} }
UpdateOnFootPosition(); UpdateOnFootPosition();
return; return;
} }
LastIsJumping = false; _lastIsJumping = false;
if (IsRagdoll) if (IsRagdoll)
{ {
@ -181,9 +181,9 @@ namespace CoopClient.Entities.Player
Character.CanRagdoll = false; Character.CanRagdoll = false;
Character.Task.ClearAllImmediately(); Character.Task.ClearAllImmediately();
IsPlayingAnimation = true; _isPlayingAnimation = true;
CurrentAnimation = new string[2] { "anim@sports@ballgame@handball@", "ball_get_up" }; _currentAnimation = new string[2] { "anim@sports@ballgame@handball@", "ball_get_up" };
AnimationStopTime = 0.7f; _animationStopTime = 0.7f;
Function.Call(Hash.TASK_PLAY_ANIM, Character.Handle, LoadAnim("anim@sports@ballgame@handball@"), "ball_get_up", 12f, 12f, -1, 0, -10f, 1, 1, 1); Function.Call(Hash.TASK_PLAY_ANIM, Character.Handle, LoadAnim("anim@sports@ballgame@handball@"), "ball_get_up", 12f, 12f, -1, 0, -10f, 1, 1, 1);
return; return;
@ -226,7 +226,7 @@ namespace CoopClient.Entities.Player
#region WEAPON #region WEAPON
private void CheckCurrentWeapon() private void CheckCurrentWeapon()
{ {
if (Character.Weapons.Current.Hash != (WeaponHash)CurrentWeaponHash || !WeaponComponents.Compare(LastWeaponComponents)) if (Character.Weapons.Current.Hash != (WeaponHash)CurrentWeaponHash || !WeaponComponents.Compare(_lastWeaponComponents))
{ {
Character.Weapons.RemoveAll(); Character.Weapons.RemoveAll();
@ -238,21 +238,21 @@ namespace CoopClient.Entities.Player
} }
else else
{ {
LastWeaponObj = Function.Call<int>(Hash.CREATE_WEAPON_OBJECT, CurrentWeaponHash, -1, Position.X, Position.Y, Position.Z, true, 0, 0); _lastWeaponObj = Function.Call<int>(Hash.CREATE_WEAPON_OBJECT, CurrentWeaponHash, -1, Position.X, Position.Y, Position.Z, true, 0, 0);
foreach (KeyValuePair<uint, bool> comp in WeaponComponents) foreach (KeyValuePair<uint, bool> comp in WeaponComponents)
{ {
if (comp.Value) if (comp.Value)
{ {
Function.Call(Hash.GIVE_WEAPON_COMPONENT_TO_WEAPON_OBJECT, LastWeaponObj, comp.Key); Function.Call(Hash.GIVE_WEAPON_COMPONENT_TO_WEAPON_OBJECT, _lastWeaponObj, comp.Key);
} }
} }
Function.Call(Hash.GIVE_WEAPON_OBJECT_TO_PED, LastWeaponObj, Character.Handle); Function.Call(Hash.GIVE_WEAPON_OBJECT_TO_PED, _lastWeaponObj, Character.Handle);
} }
} }
LastWeaponComponents = WeaponComponents; _lastWeaponComponents = WeaponComponents;
} }
} }
@ -288,29 +288,29 @@ namespace CoopClient.Entities.Player
private bool StopAnimation() private bool StopAnimation()
{ {
if (!IsPlayingAnimation) if (!_isPlayingAnimation)
{ {
return true; return true;
} }
switch (CurrentAnimation[0]) switch (_currentAnimation[0])
{ {
case "anim@sports@ballgame@handball@": case "anim@sports@ballgame@handball@":
UpdateOnFootPosition(true, true, false); UpdateOnFootPosition(true, true, false);
float currentTime = Function.Call<float>(Hash.GET_ENTITY_ANIM_CURRENT_TIME, Character.Handle, "anim@sports@ballgame@handball@", CurrentAnimation[1]); float currentTime = Function.Call<float>(Hash.GET_ENTITY_ANIM_CURRENT_TIME, Character.Handle, "anim@sports@ballgame@handball@", _currentAnimation[1]);
if (currentTime < AnimationStopTime) if (currentTime < _animationStopTime)
{ {
return false; return false;
} }
break; break;
} }
Character.Task.ClearAnimation(CurrentAnimation[0], CurrentAnimation[1]); Character.Task.ClearAnimation(_currentAnimation[0], _currentAnimation[1]);
Character.Task.ClearAll(); Character.Task.ClearAll();
IsPlayingAnimation = false; _isPlayingAnimation = false;
CurrentAnimation = new string[2] { "", "" }; _currentAnimation = new string[2] { "", "" };
AnimationStopTime = 0; _animationStopTime = 0;
return true; return true;
} }

View File

@ -10,16 +10,16 @@ namespace CoopClient.Entities.Player
public partial class EntitiesPlayer public partial class EntitiesPlayer
{ {
#region -- VARIABLES -- #region -- VARIABLES --
private ulong VehicleStopTime { get; set; } private ulong _vehicleStopTime { get; set; }
internal bool IsInVehicle { get; set; } internal bool IsInVehicle { get; set; }
/// <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 { get; internal set; } public int VehicleModelHash { get; internal set; }
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>();
internal Dictionary<int, int> VehicleMods { get; set; } internal Dictionary<int, int> VehicleMods { get; set; }
internal bool VehicleDead { get; set; } internal bool VehicleDead { get; set; }
internal float VehicleEngineHealth { get; set; } internal float VehicleEngineHealth { get; set; }
@ -34,12 +34,12 @@ namespace CoopClient.Entities.Player
public Quaternion VehicleRotation { get; internal set; } public Quaternion VehicleRotation { get; internal set; }
internal float VehicleSpeed { get; set; } internal float VehicleSpeed { get; set; }
internal float VehicleSteeringAngle { get; set; } internal float VehicleSteeringAngle { get; set; }
private int LastVehicleAim; private int _lastVehicleAim = 0;
internal bool VehIsEngineRunning { get; set; } internal bool VehIsEngineRunning { get; set; }
internal float VehRPM { get; set; } internal float VehRPM { get; set; }
private bool LastTransformed = false; private bool _lastTransformed = false;
internal bool Transformed { get; set; } internal bool Transformed { get; set; }
private bool LastHornActive = false; private bool _lastHornActive = false;
internal bool IsHornActive { get; set; } internal bool IsHornActive { get; set; }
internal bool VehAreLightsOn { get; set; } internal bool VehAreLightsOn { get; set; }
internal bool VehAreBrakeLightsOn = false; internal bool VehAreBrakeLightsOn = false;
@ -113,10 +113,10 @@ namespace CoopClient.Entities.Player
if (MainVehicle.IsTurretSeat(VehicleSeatIndex)) if (MainVehicle.IsTurretSeat(VehicleSeatIndex))
{ {
int gameTime = Game.GameTime; int gameTime = Game.GameTime;
if (gameTime - LastVehicleAim > 30) if (gameTime - _lastVehicleAim > 30)
{ {
Function.Call(Hash.TASK_VEHICLE_AIM_AT_COORD, Character.Handle, AimCoords.X, AimCoords.Y, AimCoords.Z); Function.Call(Hash.TASK_VEHICLE_AIM_AT_COORD, Character.Handle, AimCoords.X, AimCoords.Y, AimCoords.Z);
LastVehicleAim = gameTime; _lastVehicleAim = gameTime;
} }
} }
} }
@ -126,11 +126,11 @@ namespace CoopClient.Entities.Player
return; return;
} }
if (VehicleColors != null && VehicleColors != LastVehicleColors) if (VehicleColors != null && VehicleColors != _lastVehicleColors)
{ {
Function.Call(Hash.SET_VEHICLE_COLOURS, MainVehicle, VehicleColors[0], VehicleColors[1]); Function.Call(Hash.SET_VEHICLE_COLOURS, MainVehicle, VehicleColors[0], VehicleColors[1]);
LastVehicleColors = VehicleColors; _lastVehicleColors = VehicleColors;
} }
if (Character.IsOnBike && MainVehicle.ClassType == VehicleClass.Cycles) if (Character.IsOnBike && MainVehicle.ClassType == VehicleClass.Cycles)
@ -151,7 +151,7 @@ namespace CoopClient.Entities.Player
} }
else else
{ {
if (VehicleMods != null && !VehicleMods.Compare(LastVehicleMods)) if (VehicleMods != null && !VehicleMods.Compare(_lastVehicleMods))
{ {
Function.Call(Hash.SET_VEHICLE_MOD_KIT, MainVehicle, 0); Function.Call(Hash.SET_VEHICLE_MOD_KIT, MainVehicle, 0);
@ -160,7 +160,7 @@ namespace CoopClient.Entities.Player
MainVehicle.Mods[(VehicleModType)mod.Key].Index = mod.Value; MainVehicle.Mods[(VehicleModType)mod.Key].Index = mod.Value;
} }
LastVehicleMods = VehicleMods; _lastVehicleMods = VehicleMods;
} }
MainVehicle.EngineHealth = VehicleEngineHealth; MainVehicle.EngineHealth = VehicleEngineHealth;
@ -193,14 +193,17 @@ namespace CoopClient.Entities.Player
if (MainVehicle.IsSubmarineCar) if (MainVehicle.IsSubmarineCar)
{ {
if (Transformed && !LastTransformed) if (Transformed)
{ {
LastTransformed = true; if (!_lastTransformed)
Function.Call(Hash._TRANSFORM_VEHICLE_TO_SUBMARINE, MainVehicle.Handle, false); {
_lastTransformed = true;
Function.Call(Hash._TRANSFORM_VEHICLE_TO_SUBMARINE, MainVehicle.Handle, false);
}
} }
else if (!Transformed && LastTransformed) else if (_lastTransformed)
{ {
LastTransformed = false; _lastTransformed = false;
Function.Call(Hash._TRANSFORM_SUBMARINE_TO_VEHICLE, MainVehicle.Handle, false); Function.Call(Hash._TRANSFORM_SUBMARINE_TO_VEHICLE, MainVehicle.Handle, false);
} }
} }
@ -219,14 +222,17 @@ namespace CoopClient.Entities.Player
MainVehicle.IsSirenActive = VehIsSireneActive; MainVehicle.IsSirenActive = VehIsSireneActive;
} }
if (IsHornActive && !LastHornActive) if (IsHornActive)
{ {
LastHornActive = true; if (!_lastHornActive)
MainVehicle.SoundHorn(99999); {
_lastHornActive = true;
MainVehicle.SoundHorn(99999);
}
} }
else if (!IsHornActive && LastHornActive) else if (_lastHornActive)
{ {
LastHornActive = false; _lastHornActive = false;
MainVehicle.SoundHorn(1); MainVehicle.SoundHorn(1);
} }
@ -261,11 +267,11 @@ namespace CoopClient.Entities.Player
MainVehicle.Velocity = Velocity + 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();
} }
else if ((Util.GetTickCount64() - VehicleStopTime) <= 1000) else if ((Util.GetTickCount64() - _vehicleStopTime) <= 1000)
{ {
Vector3 posTarget = Util.LinearVectorLerp(MainVehicle.Position, Position + (Position - MainVehicle.Position), Util.GetTickCount64() - VehicleStopTime, 1000); Vector3 posTarget = Util.LinearVectorLerp(MainVehicle.Position, Position + (Position - MainVehicle.Position), Util.GetTickCount64() - _vehicleStopTime, 1000);
MainVehicle.PositionNoOffset = posTarget; MainVehicle.PositionNoOffset = posTarget;
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f); MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);

View File

@ -16,7 +16,7 @@ namespace CoopClient
/// </summary> /// </summary>
public class JavascriptHook : Script public class JavascriptHook : Script
{ {
private static readonly List<V8ScriptEngine> ScriptEngines = new List<V8ScriptEngine>(); private static readonly List<V8ScriptEngine> _scriptEngines = new List<V8ScriptEngine>();
internal static bool JavascriptLoaded { get; private set; } = false; internal static bool JavascriptLoaded { get; private set; } = false;
/// <summary> /// <summary>
@ -29,14 +29,14 @@ namespace CoopClient
private void Ontick(object sender, EventArgs e) private void Ontick(object sender, EventArgs e)
{ {
if (!Main.MainNetworking.IsOnServer() || ScriptEngines.Count == 0) if (!Main.MainNetworking.IsOnServer() || _scriptEngines.Count == 0)
{ {
return; return;
} }
lock (ScriptEngines) lock (_scriptEngines)
{ {
ScriptEngines.ForEach(engine => engine.Script.API.InvokeTick()); _scriptEngines.ForEach(engine => engine.Script.API.InvokeTick());
} }
} }
@ -60,7 +60,7 @@ namespace CoopClient
} }
} }
lock (ScriptEngines) lock (_scriptEngines)
{ {
foreach (string script in Directory.GetFiles("scripts\\resources\\" + serverAddress, "*.js")) foreach (string script in Directory.GetFiles("scripts\\resources\\" + serverAddress, "*.js"))
{ {
@ -89,7 +89,7 @@ namespace CoopClient
finally finally
{ {
engine.Script.API.InvokeStart(); engine.Script.API.InvokeStart();
ScriptEngines.Add(engine); _scriptEngines.Add(engine);
} }
} }
} }
@ -99,14 +99,14 @@ namespace CoopClient
internal static void StopAll() internal static void StopAll()
{ {
lock (ScriptEngines) lock (_scriptEngines)
{ {
ScriptEngines.ForEach(engine => _scriptEngines.ForEach(engine =>
{ {
engine.Script.API.InvokeStop(); engine.Script.API.InvokeStop();
engine.Dispose(); engine.Dispose();
}); });
ScriptEngines.Clear(); _scriptEngines.Clear();
} }
JavascriptLoaded = false; JavascriptLoaded = false;
@ -114,25 +114,25 @@ namespace CoopClient
internal static void InvokePlayerConnect(string username, long nethandle) internal static void InvokePlayerConnect(string username, long nethandle)
{ {
lock (ScriptEngines) lock (_scriptEngines)
{ {
ScriptEngines.ForEach(engine => engine.Script.API.InvokePlayerConnect(username, nethandle)); _scriptEngines.ForEach(engine => engine.Script.API.InvokePlayerConnect(username, nethandle));
} }
} }
internal static void InvokePlayerDisonnect(string username, long nethandle, string reason = null) internal static void InvokePlayerDisonnect(string username, long nethandle, string reason = null)
{ {
lock (ScriptEngines) lock (_scriptEngines)
{ {
ScriptEngines.ForEach(engine => engine.Script.API.InvokePlayerDisonnect(username, nethandle, reason)); _scriptEngines.ForEach(engine => engine.Script.API.InvokePlayerDisonnect(username, nethandle, reason));
} }
} }
internal static void InvokeChatMessage(string from, string message) internal static void InvokeChatMessage(string from, string message)
{ {
lock (ScriptEngines) lock (_scriptEngines)
{ {
ScriptEngines.ForEach(engine => engine.Script.API.InvokeChatMessage(from, message)); _scriptEngines.ForEach(engine => engine.Script.API.InvokeChatMessage(from, message));
} }
} }
} }

View File

@ -20,14 +20,14 @@ namespace CoopClient
{ {
internal static RelationshipGroup RelationshipGroup; internal static RelationshipGroup RelationshipGroup;
private bool GameLoaded = false; private bool _gameLoaded = false;
internal static readonly string CurrentVersion = "V1_4_0"; internal static readonly string CurrentVersion = "V1_4_0";
internal static bool ShareNPCsWithPlayers = false; internal static bool ShareNPCsWithPlayers = false;
internal static bool DisableTraffic = false; internal static bool DisableTraffic = false;
internal static bool NPCsAllowed = false; internal static bool NPCsAllowed = false;
private static bool IsGoingToCar = false; private static bool _isGoingToCar = false;
internal static Settings MainSettings = null; internal static Settings MainSettings = null;
internal static Networking MainNetworking = null; internal static Networking MainNetworking = null;
@ -58,10 +58,10 @@ namespace CoopClient
return; return;
} }
if (!GameLoaded) if (!_gameLoaded)
{ {
GTA.UI.Notification.Show("~r~Please update your GTA5 to v1.0.1290 or newer!", true); GTA.UI.Notification.Show("~r~Please update your GTA5 to v1.0.1290 or newer!", true);
GameLoaded = true; _gameLoaded = true;
} }
}; };
return; return;
@ -85,9 +85,9 @@ namespace CoopClient
} }
#if DEBUG #if DEBUG
private ulong LastDebugData; private ulong _lastDebugData;
private int DebugBytesSend; private int _debugBytesSend;
private int DebugBytesReceived; private int _debugBytesReceived;
#endif #endif
private void OnTick(object sender, EventArgs e) private void OnTick(object sender, EventArgs e)
{ {
@ -95,7 +95,7 @@ namespace CoopClient
{ {
return; return;
} }
else if (!GameLoaded && (GameLoaded = true)) else if (!_gameLoaded && (_gameLoaded = true))
{ {
RelationshipGroup = World.AddRelationshipGroup("SYNCPED"); RelationshipGroup = World.AddRelationshipGroup("SYNCPED");
Game.Player.Character.RelationshipGroup.SetRelationshipBetweenGroups(RelationshipGroup, Relationship.Neutral, true); Game.Player.Character.RelationshipGroup.SetRelationshipBetweenGroups(RelationshipGroup, Relationship.Neutral, true);
@ -115,9 +115,9 @@ namespace CoopClient
JavascriptHook.LoadAll(); JavascriptHook.LoadAll();
} }
if (IsGoingToCar && Game.Player.Character.IsInVehicle()) if (_isGoingToCar && Game.Player.Character.IsInVehicle())
{ {
IsGoingToCar = false; _isGoingToCar = false;
} }
if (!MainNetworking.IsOnServer()) if (!MainNetworking.IsOnServer())
@ -129,19 +129,19 @@ namespace CoopClient
if (MainNetworking.ShowNetworkInfo) if (MainNetworking.ShowNetworkInfo)
{ {
ulong time = Util.GetTickCount64(); ulong time = Util.GetTickCount64();
if (time - LastDebugData > 1000) if (time - _lastDebugData > 1000)
{ {
LastDebugData = time; _lastDebugData = time;
DebugBytesReceived = MainNetworking.BytesReceived; _debugBytesReceived = MainNetworking.BytesReceived;
MainNetworking.BytesReceived = 0; MainNetworking.BytesReceived = 0;
DebugBytesSend = MainNetworking.BytesSend; _debugBytesSend = MainNetworking.BytesSend;
MainNetworking.BytesSend = 0; MainNetworking.BytesSend = 0;
} }
new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 0), $"L: {MainNetworking.Latency * 1000:N0}ms", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw(); new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 0), $"L: {MainNetworking.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(DebugBytesReceived)}/s", 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(_debugBytesReceived)}/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(DebugBytesSend)}/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(_debugBytesSend)}/s", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw();
} }
#endif #endif
@ -158,7 +158,7 @@ namespace CoopClient
// Display all players // Display all players
foreach (KeyValuePair<long, EntitiesPlayer> player in Players) foreach (KeyValuePair<long, EntitiesPlayer> player in Players)
{ {
player.Value.DisplayLocally(player.Value.Username); player.Value.Update();
} }
MainNetworking.SendPlayerData(); MainNetworking.SendPlayerData();
@ -190,10 +190,10 @@ namespace CoopClient
} }
break; break;
case Keys.G: case Keys.G:
if (IsGoingToCar) if (_isGoingToCar)
{ {
Game.Player.Character.Task.ClearAll(); Game.Player.Character.Task.ClearAll();
IsGoingToCar = false; _isGoingToCar = false;
} }
else if (!Game.Player.Character.IsInVehicle()) else if (!Game.Player.Character.IsInVehicle())
{ {
@ -205,7 +205,7 @@ namespace CoopClient
if (veh.IsSeatFree((VehicleSeat)i)) if (veh.IsSeatFree((VehicleSeat)i))
{ {
Game.Player.Character.Task.EnterVehicle(veh, (VehicleSeat)i); Game.Player.Character.Task.EnterVehicle(veh, (VehicleSeat)i);
IsGoingToCar = true; _isGoingToCar = true;
break; break;
} }
} }
@ -354,7 +354,7 @@ namespace CoopClient
} }
#if DEBUG #if DEBUG
private ulong ArtificialLagCounter; private ulong _artificialLagCounter;
internal static EntitiesPlayer DebugSyncPed; internal static EntitiesPlayer DebugSyncPed;
internal static ulong LastFullDebugSync = 0; internal static ulong LastFullDebugSync = 0;
internal static bool UseDebug = false; internal static bool UseDebug = false;
@ -369,7 +369,7 @@ namespace CoopClient
DebugSyncPed = Players[0]; DebugSyncPed = Players[0];
} }
if ((Util.GetTickCount64() - ArtificialLagCounter) < 231) if ((Util.GetTickCount64() - _artificialLagCounter) < 231)
{ {
return; return;
} }
@ -465,9 +465,9 @@ namespace CoopClient
ulong currentTimestamp = Util.GetTickCount64(); ulong currentTimestamp = Util.GetTickCount64();
DebugSyncPed.LastUpdateReceived = currentTimestamp; DebugSyncPed.LastUpdateReceived = currentTimestamp;
DebugSyncPed.Latency = (currentTimestamp - ArtificialLagCounter) / 1000f; DebugSyncPed.Latency = (currentTimestamp - _artificialLagCounter) / 1000f;
ArtificialLagCounter = currentTimestamp; _artificialLagCounter = currentTimestamp;
if (fullSync) if (fullSync)
{ {

View File

@ -25,10 +25,10 @@ namespace CoopClient.Menus
#endregion #endregion
#region ITEMS #region ITEMS
private readonly NativeItem UsernameItem = new NativeItem("Username") { AltTitle = Main.MainSettings.Username }; private readonly NativeItem _usernameItem = new NativeItem("Username") { AltTitle = Main.MainSettings.Username };
internal readonly NativeItem ServerIpItem = new NativeItem("Server IP") { AltTitle = Main.MainSettings.LastServerAddress }; internal readonly NativeItem ServerIpItem = new NativeItem("Server IP") { AltTitle = Main.MainSettings.LastServerAddress };
private readonly NativeItem ServerConnectItem = new NativeItem("Connect"); private readonly NativeItem _serverConnectItem = new NativeItem("Connect");
private readonly NativeItem AboutItem = new NativeItem("About", "~y~SOURCE~s~~n~" + private readonly NativeItem _aboutItem = new NativeItem("About", "~y~SOURCE~s~~n~" +
"https://github.com/RAGECOOP~n~" + "https://github.com/RAGECOOP~n~" +
"~y~VERSION~s~~n~" + "~y~VERSION~s~~n~" +
Main.CurrentVersion.Replace("_", ".")) { LeftBadge = new LemonUI.Elements.ScaledTexture("commonmenu", "shop_new_star") }; Main.CurrentVersion.Replace("_", ".")) { LeftBadge = new LemonUI.Elements.ScaledTexture("commonmenu", "shop_new_star") };
@ -42,19 +42,19 @@ namespace CoopClient.Menus
MainMenu.Banner.Color = Color.FromArgb(225, 0, 0, 0); MainMenu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
MainMenu.Title.Color = Color.FromArgb(255, 165, 0); MainMenu.Title.Color = Color.FromArgb(255, 165, 0);
UsernameItem.Activated += UsernameActivated; _usernameItem.Activated += UsernameActivated;
ServerIpItem.Activated += ServerIpActivated; ServerIpItem.Activated += ServerIpActivated;
ServerConnectItem.Activated += (sender, item) => { Main.MainNetworking.DisConnectFromServer(Main.MainSettings.LastServerAddress); }; _serverConnectItem.Activated += (sender, item) => { Main.MainNetworking.DisConnectFromServer(Main.MainSettings.LastServerAddress); };
MainMenu.AddSubMenu(ServerList.MainMenu); MainMenu.AddSubMenu(ServerList.MainMenu);
MainMenu.Add(UsernameItem); MainMenu.Add(_usernameItem);
MainMenu.Add(ServerIpItem); MainMenu.Add(ServerIpItem);
MainMenu.Add(ServerConnectItem); MainMenu.Add(_serverConnectItem);
MainMenu.AddSubMenu(SubSettings.MainMenu); MainMenu.AddSubMenu(SubSettings.MainMenu);
MainMenu.Add(AboutItem); MainMenu.Add(_aboutItem);
MenuPool.Add(ServerList.MainMenu); MenuPool.Add(ServerList.MainMenu);
MenuPool.Add(MainMenu); MenuPool.Add(MainMenu);
@ -63,13 +63,13 @@ namespace CoopClient.Menus
internal void UsernameActivated(object a, System.EventArgs b) internal void UsernameActivated(object a, System.EventArgs b)
{ {
string newUsername = Game.GetUserInput(WindowTitle.EnterMessage20, UsernameItem.AltTitle, 20); string newUsername = Game.GetUserInput(WindowTitle.EnterMessage20, _usernameItem.AltTitle, 20);
if (!string.IsNullOrWhiteSpace(newUsername)) if (!string.IsNullOrWhiteSpace(newUsername))
{ {
Main.MainSettings.Username = newUsername; Main.MainSettings.Username = newUsername;
Util.SaveSettings(); Util.SaveSettings();
UsernameItem.AltTitle = newUsername; _usernameItem.AltTitle = newUsername;
} }
} }

View File

@ -15,12 +15,12 @@ namespace CoopClient.Menus.Sub
Alignment = Main.MainSettings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left Alignment = Main.MainSettings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
}; };
private readonly NativeCheckboxItem DisableTraffic = new NativeCheckboxItem("Disable Traffic (NPCs/Vehicles)", "Local traffic only", Main.DisableTraffic); private readonly NativeCheckboxItem _disableTrafficItem = new NativeCheckboxItem("Disable Traffic (NPCs/Vehicles)", "Local traffic only", Main.DisableTraffic);
private readonly NativeCheckboxItem ShareNPCsItem = new NativeCheckboxItem("Share NPCs", "~y~WARNING:~s~ High network traffic!", Main.ShareNPCsWithPlayers) { Enabled = false }; private readonly NativeCheckboxItem _shareNPCsItem = new NativeCheckboxItem("Share NPCs", "~y~WARNING:~s~ High network traffic!", Main.ShareNPCsWithPlayers) { Enabled = false };
private readonly NativeCheckboxItem FlipMenuItem = new NativeCheckboxItem("Flip menu", Main.MainSettings.FlipMenu); private readonly NativeCheckboxItem _flipMenuItem = new NativeCheckboxItem("Flip menu", Main.MainSettings.FlipMenu);
#if DEBUG #if DEBUG
private readonly NativeCheckboxItem UseDebugItem = new NativeCheckboxItem("Debug", Main.UseDebug); private readonly NativeCheckboxItem _useDebugItem = new NativeCheckboxItem("Debug", Main.UseDebug);
private readonly NativeCheckboxItem ShowNetworkInfo = new NativeCheckboxItem("Show Network Info", Main.MainNetworking.ShowNetworkInfo); private readonly NativeCheckboxItem _showNetworkInfoItem = new NativeCheckboxItem("Show Network Info", Main.MainNetworking.ShowNetworkInfo);
#endif #endif
/// <summary> /// <summary>
@ -31,59 +31,60 @@ namespace CoopClient.Menus.Sub
MainMenu.Banner.Color = Color.FromArgb(225, 0, 0, 0); MainMenu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
MainMenu.Title.Color = Color.FromArgb(255, 165, 0); MainMenu.Title.Color = Color.FromArgb(255, 165, 0);
DisableTraffic.CheckboxChanged += DisableTrafficCheckboxChanged; _disableTrafficItem.CheckboxChanged += DisableTrafficCheckboxChanged;
ShareNPCsItem.CheckboxChanged += (item, check) => { Main.ShareNPCsWithPlayers = ShareNPCsItem.Checked; }; _shareNPCsItem.CheckboxChanged += (item, check) => { Main.ShareNPCsWithPlayers = _shareNPCsItem.Checked; };
FlipMenuItem.CheckboxChanged += FlipMenuCheckboxChanged; _flipMenuItem.CheckboxChanged += FlipMenuCheckboxChanged;
#if DEBUG #if DEBUG
UseDebugItem.CheckboxChanged += UseDebugCheckboxChanged; _useDebugItem.CheckboxChanged += UseDebugCheckboxChanged;
ShowNetworkInfo.CheckboxChanged += ShowNetworkInfoCheckboxChanged; _showNetworkInfoItem.CheckboxChanged += ShowNetworkInfoCheckboxChanged;
#endif #endif
MainMenu.Add(DisableTraffic); MainMenu.Add(_disableTrafficItem);
MainMenu.Add(ShareNPCsItem); MainMenu.Add(_shareNPCsItem);
MainMenu.Add(FlipMenuItem); MainMenu.Add(_flipMenuItem);
#if DEBUG #if DEBUG
MainMenu.Add(UseDebugItem); MainMenu.Add(_useDebugItem);
MainMenu.Add(ShowNetworkInfo); MainMenu.Add(_showNetworkInfoItem);
#endif #endif
} }
internal void DisableTrafficCheckboxChanged(object a, System.EventArgs b) internal void DisableTrafficCheckboxChanged(object a, System.EventArgs b)
{ {
Main.DisableTraffic = DisableTraffic.Checked; Main.DisableTraffic = _disableTrafficItem.Checked;
if (DisableTraffic.Checked) if (_disableTrafficItem.Checked)
{ {
if (ShareNPCsItem.Checked) if (_shareNPCsItem.Checked)
{ {
ShareNPCsItem.Checked = false; _shareNPCsItem.Checked = false;
} }
ShareNPCsItem.Enabled = false; _shareNPCsItem.Enabled = false;
} }
else if (Main.NPCsAllowed && !ShareNPCsItem.Enabled) else if (Main.NPCsAllowed && !_shareNPCsItem.Enabled)
{ {
ShareNPCsItem.Enabled = true; _shareNPCsItem.Enabled = true;
} }
} }
internal void FlipMenuCheckboxChanged(object a, System.EventArgs b) internal void FlipMenuCheckboxChanged(object a, System.EventArgs b)
{ {
#if !NON_INTERACTIVE #if !NON_INTERACTIVE
Main.MainMenu.MainMenu.Alignment = FlipMenuItem.Checked ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left; Main.MainMenu.MainMenu.Alignment = _flipMenuItem.Checked ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left;
#endif #endif
MainMenu.Alignment = FlipMenuItem.Checked ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left; MainMenu.Alignment = _flipMenuItem.Checked ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left;
Main.MainMenu.ServerList.MainMenu.Alignment = _flipMenuItem.Checked ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left;
Main.MainSettings.FlipMenu = FlipMenuItem.Checked; Main.MainSettings.FlipMenu = _flipMenuItem.Checked;
Util.SaveSettings(); Util.SaveSettings();
} }
#if DEBUG #if DEBUG
internal void UseDebugCheckboxChanged(object a, System.EventArgs b) internal void UseDebugCheckboxChanged(object a, System.EventArgs b)
{ {
Main.UseDebug = UseDebugItem.Checked; Main.UseDebug = _useDebugItem.Checked;
if (!UseDebugItem.Checked && Main.DebugSyncPed != null) if (!_useDebugItem.Checked && Main.DebugSyncPed != null)
{ {
if (Main.DebugSyncPed.Character.Exists()) if (Main.DebugSyncPed.Character.Exists())
{ {
@ -99,7 +100,7 @@ namespace CoopClient.Menus.Sub
internal void ShowNetworkInfoCheckboxChanged(object a, System.EventArgs b) internal void ShowNetworkInfoCheckboxChanged(object a, System.EventArgs b)
{ {
Main.MainNetworking.ShowNetworkInfo = ShowNetworkInfo.Checked; Main.MainNetworking.ShowNetworkInfo = _showNetworkInfoItem.Checked;
if (!Main.MainNetworking.ShowNetworkInfo) if (!Main.MainNetworking.ShowNetworkInfo)
{ {

View File

@ -11,8 +11,8 @@ namespace CoopClient
{ {
private const float LEFT_POSITION = 0.122f; private const float LEFT_POSITION = 0.122f;
private const float RIGHT_POSITION = 0.9f; private const float RIGHT_POSITION = 0.9f;
private readonly Scaleform MainScaleform = new Scaleform("mp_mm_card_freemode"); private readonly Scaleform _mainScaleform = new Scaleform("mp_mm_card_freemode");
private ulong LastUpdate = Util.GetTickCount64(); private ulong _lastUpdate = Util.GetTickCount64();
internal ulong Pressed { get; set; } internal ulong Pressed { get; set; }
internal bool LeftAlign = true; internal bool LeftAlign = true;
@ -24,7 +24,7 @@ namespace CoopClient
return; return;
} }
if ((Util.GetTickCount64() - LastUpdate) >= 1000) if ((Util.GetTickCount64() - _lastUpdate) >= 1000)
{ {
Update(Main.Players, Main.MainSettings.Username); Update(Main.Players, Main.MainSettings.Username);
} }
@ -35,7 +35,7 @@ namespace CoopClient
#endif #endif
) )
{ {
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);
@ -44,20 +44,20 @@ namespace CoopClient
private void Update(Dictionary<long, EntitiesPlayer> players, string localUsername) private void Update(Dictionary<long, EntitiesPlayer> players, string localUsername)
{ {
LastUpdate = Util.GetTickCount64(); _lastUpdate = Util.GetTickCount64();
MainScaleform.CallFunction("SET_DATA_SLOT_EMPTY", 0); _mainScaleform.CallFunction("SET_DATA_SLOT_EMPTY", 0);
MainScaleform.CallFunction("SET_DATA_SLOT", 0, $"{Main.MainNetworking.Latency * 1000:N0}ms", localUsername, 116, 0, 0, "", "", 2, "", "", ' '); _mainScaleform.CallFunction("SET_DATA_SLOT", 0, $"{Main.MainNetworking.Latency * 1000:N0}ms", localUsername, 116, 0, 0, "", "", 2, "", "", ' ');
int i = 1; int i = 1;
foreach (KeyValuePair<long, EntitiesPlayer> player in players) foreach (KeyValuePair<long, EntitiesPlayer> player in players)
{ {
MainScaleform.CallFunction("SET_DATA_SLOT", i++, $"{player.Value.Latency * 1000:N0}ms", player.Value.Username, 116, 0, i - 1, "", "", 2, "", "", ' '); _mainScaleform.CallFunction("SET_DATA_SLOT", i++, $"{player.Value.Latency * 1000:N0}ms", player.Value.Username, 116, 0, i - 1, "", "", 2, "", "", ' ');
} }
MainScaleform.CallFunction("SET_TITLE", "Player list", (players.Count + 1) + " players"); _mainScaleform.CallFunction("SET_TITLE", "Player list", (players.Count + 1) + " players");
MainScaleform.CallFunction("DISPLAY_VIEW"); _mainScaleform.CallFunction("DISPLAY_VIEW");
} }
} }
} }

View File

@ -18,7 +18,7 @@ namespace CoopClient
static class Util static class Util
{ {
#region -- POINTER -- #region -- POINTER --
private static int SteeringAngleOffset { get; set; } private static int _steeringAngleOffset { get; set; }
public static unsafe void NativeMemory() public static unsafe void NativeMemory()
{ {
@ -27,7 +27,7 @@ namespace CoopClient
address = Game.FindPattern("\x74\x0A\xF3\x0F\x11\xB3\x1C\x09\x00\x00\xEB\x25", "xxxxxx????xx"); address = Game.FindPattern("\x74\x0A\xF3\x0F\x11\xB3\x1C\x09\x00\x00\xEB\x25", "xxxxxx????xx");
if (address != IntPtr.Zero) if (address != IntPtr.Zero)
{ {
SteeringAngleOffset = *(int*)(address + 6) + 8; _steeringAngleOffset = *(int*)(address + 6) + 8;
} }
address = Game.FindPattern("\x32\xc0\xf3\x0f\x11\x09", "xxxxxx"); // Weapon / Radio slowdown address = Game.FindPattern("\x32\xc0\xf3\x0f\x11\x09", "xxxxxx"); // Weapon / Radio slowdown
@ -43,12 +43,12 @@ namespace CoopClient
public static unsafe void CustomSteeringAngle(this Vehicle veh, float value) public static unsafe void CustomSteeringAngle(this Vehicle veh, float value)
{ {
IntPtr address = new IntPtr((long)veh.MemoryAddress); IntPtr address = new IntPtr((long)veh.MemoryAddress);
if (address == IntPtr.Zero || SteeringAngleOffset == 0) if (address == IntPtr.Zero || _steeringAngleOffset == 0)
{ {
return; return;
} }
*(float*)(address + SteeringAngleOffset).ToPointer() = value; *(float*)(address + _steeringAngleOffset).ToPointer() = value;
} }
#endregion #endregion

View File

@ -11,7 +11,7 @@ namespace CoopClient
/// </summary> /// </summary>
public class WorldThread : Script public class WorldThread : Script
{ {
private static bool LastDisableTraffic = false; private static bool _lastDisableTraffic = false;
/// <summary> /// <summary>
/// Don't use it! /// Don't use it!
@ -21,7 +21,7 @@ namespace CoopClient
Tick += OnTick; Tick += OnTick;
Aborted += (sender, e) => Aborted += (sender, e) =>
{ {
if (LastDisableTraffic) if (_lastDisableTraffic)
{ {
Traffic(true); Traffic(true);
} }
@ -43,7 +43,7 @@ namespace CoopClient
if (Main.DisableTraffic) if (Main.DisableTraffic)
{ {
if (!LastDisableTraffic) if (!_lastDisableTraffic)
{ {
Traffic(false); Traffic(false);
} }
@ -56,12 +56,12 @@ namespace CoopClient
Function.Call((Hash)0x2F9A292AD0A3BD89); Function.Call((Hash)0x2F9A292AD0A3BD89);
Function.Call((Hash)0x5F3B7749C112D552); Function.Call((Hash)0x5F3B7749C112D552);
} }
else if (LastDisableTraffic) else if (_lastDisableTraffic)
{ {
Traffic(true); Traffic(true);
} }
LastDisableTraffic = Main.DisableTraffic; _lastDisableTraffic = Main.DisableTraffic;
} }
private void Traffic(bool enable) private void Traffic(bool enable)

View File

@ -6,100 +6,94 @@ namespace CoopServer
{ {
internal class BitReader internal class BitReader
{ {
public int CurrentIndex { get; set; } private int _currentIndex { get; set; } = 0;
private byte[] ResultArray; private byte[] _resultArray = null;
public BitReader(byte[] array) public BitReader(byte[] array)
{ {
CurrentIndex = 0; _resultArray = array;
ResultArray = array;
}
~BitReader()
{
ResultArray = null;
} }
public bool CanRead(int bytes) public bool CanRead(int bytes)
{ {
return ResultArray.Length >= CurrentIndex + bytes; return _resultArray.Length >= _currentIndex + bytes;
} }
public bool ReadBool() public bool ReadBool()
{ {
bool value = BitConverter.ToBoolean(ResultArray, CurrentIndex); bool value = BitConverter.ToBoolean(_resultArray, _currentIndex);
CurrentIndex += 1; _currentIndex += 1;
return value; return value;
} }
public float ReadFloat() public float ReadFloat()
{ {
float value = BitConverter.ToSingle(ResultArray, CurrentIndex); float value = BitConverter.ToSingle(_resultArray, _currentIndex);
CurrentIndex += 4; _currentIndex += 4;
return value; return value;
} }
public byte ReadByte() public byte ReadByte()
{ {
byte value = ResultArray[CurrentIndex]; byte value = _resultArray[_currentIndex];
CurrentIndex += 1; _currentIndex += 1;
return value; return value;
} }
public byte[] ReadByteArray(int length) public byte[] ReadByteArray(int length)
{ {
byte[] value = ResultArray.Skip(CurrentIndex).Take(length).ToArray(); byte[] value = _resultArray.Skip(_currentIndex).Take(length).ToArray();
CurrentIndex += length; _currentIndex += length;
return value; return value;
} }
public short ReadShort() public short ReadShort()
{ {
short value = BitConverter.ToInt16(ResultArray, CurrentIndex); short value = BitConverter.ToInt16(_resultArray, _currentIndex);
CurrentIndex += 2; _currentIndex += 2;
return value; return value;
} }
public ushort ReadUShort() public ushort ReadUShort()
{ {
ushort value = BitConverter.ToUInt16(ResultArray, CurrentIndex); ushort value = BitConverter.ToUInt16(_resultArray, _currentIndex);
CurrentIndex += 2; _currentIndex += 2;
return value; return value;
} }
public int ReadInt() public int ReadInt()
{ {
int value = BitConverter.ToInt32(ResultArray, CurrentIndex); int value = BitConverter.ToInt32(_resultArray, _currentIndex);
CurrentIndex += 4; _currentIndex += 4;
return value; return value;
} }
public uint ReadUInt() public uint ReadUInt()
{ {
uint value = BitConverter.ToUInt32(ResultArray, CurrentIndex); uint value = BitConverter.ToUInt32(_resultArray, _currentIndex);
CurrentIndex += 4; _currentIndex += 4;
return value; return value;
} }
public long ReadLong() public long ReadLong()
{ {
long value = BitConverter.ToInt64(ResultArray, CurrentIndex); long value = BitConverter.ToInt64(_resultArray, _currentIndex);
CurrentIndex += 8; _currentIndex += 8;
return value; return value;
} }
public ulong ReadULong() public ulong ReadULong()
{ {
ulong value = BitConverter.ToUInt64(ResultArray, CurrentIndex); ulong value = BitConverter.ToUInt64(_resultArray, _currentIndex);
CurrentIndex += 8; _currentIndex += 8;
return value; return value;
} }
public string ReadString(int index) public string ReadString(int index)
{ {
string value = Encoding.UTF8.GetString(ResultArray.Skip(CurrentIndex).Take(index).ToArray()); string value = Encoding.UTF8.GetString(_resultArray.Skip(_currentIndex).Take(index).ToArray());
CurrentIndex += index; _currentIndex += index;
return value; return value;
} }
} }

View File

@ -8,13 +8,13 @@ namespace CoopServer
public class Client public class Client
{ {
public long NetHandle = 0; public long NetHandle = 0;
private float CurrentLatency = 0f; private float _currentLatency = 0f;
public float Latency public float Latency
{ {
get => CurrentLatency; get => _currentLatency;
internal set internal set
{ {
CurrentLatency = value; _currentLatency = value;
if ((value * 1000f) > Server.MainSettings.MaxLatency) if ((value * 1000f) > Server.MainSettings.MaxLatency)
{ {
@ -23,8 +23,8 @@ namespace CoopServer
} }
} }
public PlayerData Player; public PlayerData Player;
private readonly Dictionary<string, object> CustomData = new(); private readonly Dictionary<string, object> _customData = new();
private long CallbacksCount = 0; private long _callbacksCount = 0;
internal readonly Dictionary<long, Action<object>> Callbacks = new(); internal readonly Dictionary<long, Action<object>> Callbacks = new();
internal bool FilesReceived = false; internal bool FilesReceived = false;
internal bool FilesSent = false; internal bool FilesSent = false;
@ -34,29 +34,29 @@ namespace CoopServer
{ {
if (HasData(name)) if (HasData(name))
{ {
CustomData[name] = data; _customData[name] = data;
} }
else else
{ {
CustomData.Add(name, data); _customData.Add(name, data);
} }
} }
public bool HasData(string name) public bool HasData(string name)
{ {
return CustomData.ContainsKey(name); return _customData.ContainsKey(name);
} }
public T GetData<T>(string name) public T GetData<T>(string name)
{ {
return HasData(name) ? (T)CustomData[name] : default; return HasData(name) ? (T)_customData[name] : default;
} }
public void RemoveData(string name) public void RemoveData(string name)
{ {
if (HasData(name)) if (HasData(name))
{ {
CustomData.Remove(name); _customData.Remove(name);
} }
} }
#endregion #endregion
@ -139,7 +139,7 @@ namespace CoopServer
return; return;
} }
long id = ++CallbacksCount; long id = ++_callbacksCount;
Callbacks.Add(id, callback); Callbacks.Add(id, callback);
byte returnTypeValue = 0x00; byte returnTypeValue = 0x00;

View File

@ -8,7 +8,7 @@ namespace CoopServer
{ {
internal static class DownloadManager internal static class DownloadManager
{ {
private static readonly List<long> ClientsToDelete = new(); private static readonly List<long> _clientsToDelete = new();
private static List<DownloadClient> _clients = new(); private static List<DownloadClient> _clients = new();
private static readonly List<DownloadFile> _files = new(); private static readonly List<DownloadFile> _files = new();
public static bool AnyFileExists = false; public static bool AnyFileExists = false;
@ -79,9 +79,9 @@ namespace CoopServer
{ {
lock (_clients) lock (_clients)
{ {
lock (ClientsToDelete) lock (_clientsToDelete)
{ {
foreach (long nethandle in ClientsToDelete) foreach (long nethandle in _clientsToDelete)
{ {
DownloadClient client = _clients.FirstOrDefault(x => x.NetHandle == nethandle); DownloadClient client = _clients.FirstOrDefault(x => x.NetHandle == nethandle);
if (client != null) if (client != null)
@ -90,7 +90,7 @@ namespace CoopServer
_clients.Remove(client); _clients.Remove(client);
} }
} }
ClientsToDelete.Clear(); _clientsToDelete.Clear();
} }
_clients.ForEach(client => _clients.ForEach(client =>
@ -151,9 +151,9 @@ namespace CoopServer
public static void AddClientToRemove(long nethandle) public static void AddClientToRemove(long nethandle)
{ {
lock (ClientsToDelete) lock (_clientsToDelete)
{ {
ClientsToDelete.Add(nethandle); _clientsToDelete.Add(nethandle);
} }
} }
} }

View File

@ -5,11 +5,11 @@ namespace CoopServer
{ {
public class Logging public class Logging
{ {
private static readonly object Lock = new(); private static readonly object _lock = new();
public static void Info(string message) public static void Info(string message)
{ {
lock (Lock) lock (_lock)
{ {
string msg = string.Format("[{0}] [INFO] {1}", Date(), message); string msg = string.Format("[{0}] [INFO] {1}", Date(), message);
@ -24,7 +24,7 @@ namespace CoopServer
public static void Warning(string message) public static void Warning(string message)
{ {
lock (Lock) lock (_lock)
{ {
string msg = string.Format("[{0}] [WARNING] {1}", Date(), message); string msg = string.Format("[{0}] [WARNING] {1}", Date(), message);
@ -39,7 +39,7 @@ namespace CoopServer
public static void Error(string message) public static void Error(string message)
{ {
lock (Lock) lock (_lock)
{ {
string msg = string.Format("[{0}] [ERROR] {1}", Date(), message); string msg = string.Format("[{0}] [ERROR] {1}", Date(), message);
@ -59,7 +59,7 @@ namespace CoopServer
return; return;
} }
lock (Lock) lock (_lock)
{ {
string msg = string.Format("[{0}] [DEBUG] {1}", Date(), message); string msg = string.Format("[{0}] [DEBUG] {1}", Date(), message);

View File

@ -4,67 +4,67 @@ namespace CoopServer
{ {
public struct PlayerData public struct PlayerData
{ {
public string Username { get; internal set; } public string Username { get; internal set; } = string.Empty;
private int LastPedHandle { get; set; } private int _lastPedHandle { get; set; } = 0;
private int CurrentPedHandle { get; set; } private int _currentPedHandle { get; set; } = 0;
public int PedHandle public int PedHandle
{ {
get => CurrentPedHandle; get => _currentPedHandle;
internal set internal set
{ {
LastPedHandle = CurrentPedHandle == default ? value : CurrentPedHandle; _lastPedHandle = _currentPedHandle == 0 ? value : _currentPedHandle;
CurrentPedHandle = value; _currentPedHandle = value;
if (CurrentPedHandle != LastPedHandle && Server.RunningResource != null) if (_currentPedHandle != _lastPedHandle && Server.RunningResource != null)
{ {
Server.RunningResource.InvokePlayerPedHandleUpdate(Username); Server.RunningResource.InvokePlayerPedHandleUpdate(Username);
} }
} }
} }
private int LastVehicleHandle { get; set; } private int _lastVehicleHandle { get; set; } = 0;
private int CurrentVehicleHandle { get; set; } private int _currentVehicleHandle { get; set; } = 0;
public int VehicleHandle public int VehicleHandle
{ {
get => CurrentPedHandle; get => _currentVehicleHandle;
internal set internal set
{ {
LastVehicleHandle = CurrentVehicleHandle == default ? value : CurrentVehicleHandle; _lastVehicleHandle = _currentVehicleHandle == 0 ? value : _currentVehicleHandle;
CurrentVehicleHandle = value; _currentVehicleHandle = value;
if (CurrentVehicleHandle != LastVehicleHandle && Server.RunningResource != null) if (_currentVehicleHandle != _lastVehicleHandle && Server.RunningResource != null)
{ {
Server.RunningResource.InvokePlayerPedHandleUpdate(Username); Server.RunningResource.InvokePlayerPedHandleUpdate(Username);
} }
} }
} }
public bool IsInVehicle { get; internal set; } public bool IsInVehicle { get; internal set; } = false;
private LVector3 LastPosition { get; set; } private LVector3 _lastPosition { get; set; } = new LVector3();
private LVector3 CurrentPosition { get; set; } private LVector3 _currentPosition { get; set; } = new LVector3();
public LVector3 Position public LVector3 Position
{ {
get => CurrentPosition; get => _currentPosition;
internal set internal set
{ {
LastPosition = CurrentPosition.Equals(default(LVector3)) ? value : CurrentPosition; _lastPosition = _currentPosition.Equals(default(LVector3)) ? value : _currentPosition;
CurrentPosition = value; _currentPosition = value;
if (Server.RunningResource != null && !LVector3.Equals(CurrentPosition, LastPosition)) if (Server.RunningResource != null && !LVector3.Equals(_currentPosition, _lastPosition))
{ {
Server.RunningResource.InvokePlayerPositionUpdate(Username); Server.RunningResource.InvokePlayerPositionUpdate(Username);
} }
} }
} }
private int LastHealth { get; set; } private int _lastHealth { get; set; } = 0;
private int CurrentHealth { get; set; } private int _currentHealth { get; set; } = 0;
public int Health public int Health
{ {
get => CurrentHealth; get => _currentHealth;
internal set internal set
{ {
LastHealth = CurrentHealth == default ? value : CurrentHealth; _lastHealth = _currentHealth == 0 ? value : _currentHealth;
CurrentHealth = value; _currentHealth = value;
if (CurrentHealth != LastHealth && Server.RunningResource != null) if (_currentHealth != _lastHealth && Server.RunningResource != null)
{ {
Server.RunningResource.InvokePlayerHealthUpdate(Username); Server.RunningResource.InvokePlayerHealthUpdate(Username);
} }

View File

@ -22,12 +22,12 @@ namespace CoopServer
internal class Server internal class Server
{ {
private static readonly string CompatibleVersion = "V1_4"; private static readonly string _compatibleVersion = "V1_4";
private static long CurrentTick = 0; private static long _currentTick = 0;
public static readonly Settings MainSettings = Util.Read<Settings>("Settings.xml"); public static readonly Settings MainSettings = Util.Read<Settings>("Settings.xml");
private readonly Blocklist MainBlocklist = Util.Read<Blocklist>("Blocklist.xml"); private readonly Blocklist _mainBlocklist = Util.Read<Blocklist>("Blocklist.xml");
private readonly Allowlist MainAllowlist = Util.Read<Allowlist>("Allowlist.xml"); private readonly Allowlist _mainAllowlist = Util.Read<Allowlist>("Allowlist.xml");
public static NetServer MainNetServer; public static NetServer MainNetServer;
@ -40,7 +40,7 @@ namespace CoopServer
{ {
Logging.Info("================"); Logging.Info("================");
Logging.Info($"Server version: {Assembly.GetCallingAssembly().GetName().Version}"); Logging.Info($"Server version: {Assembly.GetCallingAssembly().GetName().Version}");
Logging.Info($"Compatible RAGECOOP versions: {CompatibleVersion.Replace('_', '.')}.x"); Logging.Info($"Compatible RAGECOOP versions: {_compatibleVersion.Replace('_', '.')}.x");
Logging.Info("================"); Logging.Info("================");
// 623c92c287cc392406e7aaaac1c0f3b0 = RAGECOOP // 623c92c287cc392406e7aaaac1c0f3b0 = RAGECOOP
@ -110,10 +110,10 @@ namespace CoopServer
"\"address\": \"" + info.ip + "\", " + "\"address\": \"" + info.ip + "\", " +
"\"port\": \"" + MainSettings.Port + "\", " + "\"port\": \"" + MainSettings.Port + "\", " +
"\"name\": \"" + MainSettings.Name + "\", " + "\"name\": \"" + MainSettings.Name + "\", " +
"\"version\": \"" + CompatibleVersion.Replace("_", ".") + "\", " + "\"version\": \"" + _compatibleVersion.Replace("_", ".") + "\", " +
"\"players\": \"" + MainNetServer.ConnectionsCount + "\", " + "\"players\": \"" + MainNetServer.ConnectionsCount + "\", " +
"\"maxPlayers\": \"" + MainSettings.MaxPlayers + "\", " + "\"maxPlayers\": \"" + MainSettings.MaxPlayers + "\", " +
"\"allowlist\": \"" + MainAllowlist.Username.Any() + "\", " + "\"allowlist\": \"" + _mainAllowlist.Username.Any() + "\", " +
"\"mods\": \"" + MainSettings.ModsAllowed + "\", " + "\"mods\": \"" + MainSettings.ModsAllowed + "\", " +
"\"npcs\": \"" + MainSettings.NpcsAllowed + "\", " + "\"npcs\": \"" + MainSettings.NpcsAllowed + "\", " +
"\"country\": \"" + info.country + "\"" + "\"country\": \"" + info.country + "\"" +
@ -211,7 +211,7 @@ namespace CoopServer
{ {
if (RunningResource != null) if (RunningResource != null)
{ {
RunningResource.InvokeTick(++CurrentTick); RunningResource.InvokeTick(++_currentTick);
} }
// Only new clients that did not receive files on connection will receive the current files in "clientside" // Only new clients that did not receive files on connection will receive the current files in "clientside"
@ -604,9 +604,9 @@ namespace CoopServer
{ {
Logging.Debug("New handshake from: [Name: " + packet.Username + " | Address: " + local.RemoteEndPoint.Address.ToString() + "]"); Logging.Debug("New handshake from: [Name: " + packet.Username + " | Address: " + local.RemoteEndPoint.Address.ToString() + "]");
if (!packet.ModVersion.StartsWith(CompatibleVersion)) if (!packet.ModVersion.StartsWith(_compatibleVersion))
{ {
local.Deny($"RAGECOOP version {CompatibleVersion.Replace('_', '.')}.x required!"); local.Deny($"RAGECOOP version {_compatibleVersion.Replace('_', '.')}.x required!");
return; return;
} }
if (string.IsNullOrWhiteSpace(packet.Username)) if (string.IsNullOrWhiteSpace(packet.Username))
@ -619,17 +619,17 @@ namespace CoopServer
local.Deny("Username contains special chars!"); local.Deny("Username contains special chars!");
return; return;
} }
if (MainAllowlist.Username.Any() && !MainAllowlist.Username.Contains(packet.Username.ToLower())) if (_mainAllowlist.Username.Any() && !_mainAllowlist.Username.Contains(packet.Username.ToLower()))
{ {
local.Deny("This Username is not on the allow list!"); local.Deny("This Username is not on the allow list!");
return; return;
} }
if (MainBlocklist.Username.Contains(packet.Username.ToLower())) if (_mainBlocklist.Username.Contains(packet.Username.ToLower()))
{ {
local.Deny("This Username has been blocked by this server!"); local.Deny("This Username has been blocked by this server!");
return; return;
} }
if (MainBlocklist.IP.Contains(local.RemoteEndPoint.ToString().Split(":")[0])) if (_mainBlocklist.IP.Contains(local.RemoteEndPoint.ToString().Split(":")[0]))
{ {
local.Deny("This IP was blocked by this server!"); local.Deny("This IP was blocked by this server!");
return; return;