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)
{
npc.DisplayLocally();
npc.Update();
}
// 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 int Health { get; set; }
private int LastModelHash = 0;
private int CurrentModelHash = 0;
private int _lastModelHash = 0;
private int _currentModelHash = 0;
internal int ModelHash
{
get => CurrentModelHash;
get => _currentModelHash;
set
{
LastModelHash = LastModelHash == 0 ? value : CurrentModelHash;
CurrentModelHash = value;
_lastModelHash = _lastModelHash == 0 ? value : _currentModelHash;
_currentModelHash = value;
}
}
private Dictionary<byte, short> LastClothes = null;
private Dictionary<byte, short> _lastClothes = null;
internal Dictionary<byte, short> Clothes { get; set; }
internal Vector3 Position { get; set; }
internal Vector3 Velocity { get; set; }
internal Vector3 AimCoords { get; set; }
internal void DisplayLocally()
internal void Update()
{
#region NOT_IN_RANGE
if (!Game.Player.Character.IsInRange(Position, 500f))
@ -61,7 +60,7 @@ namespace CoopClient.Entities.NPC
}
else if (LastSyncWasFull)
{
if (CurrentModelHash != LastModelHash)
if (_currentModelHash != _lastModelHash)
{
Character.Kill();
Character.Delete();
@ -71,14 +70,9 @@ namespace CoopClient.Entities.NPC
return;
}
}
else if (!Clothes.Compare(LastClothes))
else if (!Clothes.Compare(_lastClothes))
{
foreach (KeyValuePair<byte, short> cloth in Clothes)
{
Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, cloth.Key, cloth.Value, 0, 0);
}
LastClothes = Clothes;
SetClothes();
}
}
@ -117,7 +111,7 @@ namespace CoopClient.Entities.NPC
private bool CreateCharacter()
{
Model characterModel = CurrentModelHash.ModelRequest();
Model characterModel = _currentModelHash.ModelRequest();
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_CAN_ATTACK_FRIENDLY, Character.Handle, true, true);
SetClothes();
return true;
}
private void SetClothes()
{
foreach (KeyValuePair<byte, short> cloth in Clothes)
{
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>
public Vector3 Rotation { get; internal set; }
internal byte Speed { get; set; }
private bool LastIsJumping = false;
private bool _lastIsJumping = false;
internal bool IsJumping { get; set; }
internal bool IsRagdoll { get; set; }
internal bool IsOnFire { get; set; }
@ -22,9 +22,9 @@ namespace CoopClient.Entities.NPC
internal bool IsShooting { get; set; }
internal bool IsReloading { 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;
private int LastWeaponObj = 0;
private int _lastWeaponObj = 0;
#endregion
private void DisplayOnFoot()
@ -57,12 +57,12 @@ namespace CoopClient.Entities.NPC
}
}
if (IsJumping && !LastIsJumping)
if (IsJumping && !_lastIsJumping)
{
Character.Task.Jump();
}
LastIsJumping = IsJumping;
_lastIsJumping = IsJumping;
if (IsRagdoll)
{
@ -98,7 +98,7 @@ namespace CoopClient.Entities.NPC
return;
}
if (Character.Weapons.Current.Hash != (WeaponHash)CurrentWeaponHash || !WeaponComponents.Compare(LastWeaponComponents))
if (Character.Weapons.Current.Hash != (WeaponHash)CurrentWeaponHash || !WeaponComponents.Compare(_lastWeaponComponents))
{
Character.Weapons.RemoveAll();
@ -110,21 +110,21 @@ namespace CoopClient.Entities.NPC
}
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)
{
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)

View File

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

View File

@ -20,7 +20,7 @@ namespace CoopClient.Entities.Player
/// </summary>
public string Username { get; set; } = "Player";
private bool AllDataAvailable = false;
private bool _allDataAvailable = false;
internal bool LastSyncWasFull { get; set; } = false;
/// <summary>
/// Get the last update = TickCount64()
@ -39,21 +39,21 @@ namespace CoopClient.Entities.Player
/// The latest character health (may not have been applied yet)
/// </summary>
public int Health { get; internal set; }
private int LastModelHash = 0;
private int CurrentModelHash = 0;
private int _lastModelHash = 0;
private int _currentModelHash = 0;
/// <summary>
/// The latest character model hash (may not have been applied yet)
/// </summary>
public int ModelHash
{
get => CurrentModelHash;
get => _currentModelHash;
internal set
{
LastModelHash = LastModelHash == 0 ? value : CurrentModelHash;
CurrentModelHash = value;
_lastModelHash = _lastModelHash == 0 ? value : _currentModelHash;
_currentModelHash = value;
}
}
private Dictionary<byte, short> LastClothes = null;
private Dictionary<byte, short> _lastClothes = null;
internal Dictionary<byte, short> Clothes { get; set; }
/// <summary>
/// The latest character position (may not have been applied yet)
@ -63,10 +63,10 @@ namespace CoopClient.Entities.Player
internal Blip PedBlip = null;
internal Vector3 AimCoords { get; set; }
internal void DisplayLocally(string username)
internal void Update()
{
// Check beforehand whether ped has all the required data
if (!AllDataAvailable)
if (!_allDataAvailable)
{
if (!LastSyncWasFull)
{
@ -81,14 +81,14 @@ namespace CoopClient.Entities.Player
PedBlip = World.CreateBlip(Position);
PedBlip.Color = BlipColor.White;
PedBlip.Scale = 0.8f;
PedBlip.Name = username;
PedBlip.Name = Username;
}
}
return;
}
AllDataAvailable = true;
_allDataAvailable = true;
}
#region NOT_IN_RANGE
@ -109,19 +109,16 @@ namespace CoopClient.Entities.Player
MainVehicle = null;
}
if (username != null)
if (PedBlip != null && PedBlip.Exists())
{
if (PedBlip != null && PedBlip.Exists())
{
PedBlip.Position = Position;
}
else
{
PedBlip = World.CreateBlip(Position);
PedBlip.Color = BlipColor.White;
PedBlip.Scale = 0.8f;
PedBlip.Name = username;
}
PedBlip.Position = Position;
}
else
{
PedBlip = World.CreateBlip(Position);
PedBlip.Color = BlipColor.White;
PedBlip.Scale = 0.8f;
PedBlip.Name = Username;
}
return;
@ -133,62 +130,30 @@ namespace CoopClient.Entities.Player
if (!characterExist)
{
if (!CreateCharacter(username))
if (!CreateCharacter())
{
return;
}
}
else if (LastSyncWasFull)
{
if (CurrentModelHash != LastModelHash)
if (ModelHash != _lastModelHash)
{
Character.Kill();
Character.Delete();
if (!CreateCharacter(username))
if (!CreateCharacter())
{
return;
}
}
else if (!Clothes.Compare(LastClothes))
else if (!Clothes.Compare(_lastClothes))
{
foreach (KeyValuePair<byte, short> cloth in Clothes)
{
Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, cloth.Key, cloth.Value, 0, 0);
}
LastClothes = Clothes;
SetClothes();
}
}
if (username != null && 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);
}
RenderNameTag();
if (Character.IsDead)
{
@ -223,7 +188,39 @@ namespace CoopClient.Entities.Player
#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())
{
@ -231,7 +228,7 @@ namespace CoopClient.Entities.Player
PedBlip = null;
}
Model characterModel = CurrentModelHash.ModelRequest();
Model characterModel = ModelHash.ModelRequest();
if (characterModel == null)
{
@ -258,7 +255,7 @@ namespace CoopClient.Entities.Player
Character.AddBlip();
Character.AttachedBlip.Color = BlipColor.White;
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_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_CAN_ATTACK_FRIENDLY, Character.Handle, true, true);
SetClothes();
return true;
}
private void SetClothes()
{
foreach (KeyValuePair<byte, short> cloth in Clothes)
{
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>
public Vector3 Rotation { get; internal set; }
internal byte Speed { get; set; }
private bool LastIsJumping = false;
private bool _lastIsJumping = false;
internal bool IsJumping { get; set; }
internal bool IsOnLadder { get; set; }
internal bool IsVaulting { get; set; }
@ -28,14 +28,14 @@ namespace CoopClient.Entities.Player
internal bool IsShooting { get; set; }
internal bool IsReloading { 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;
private int LastWeaponObj = 0;
private int _lastWeaponObj = 0;
#endregion
private bool IsPlayingAnimation = false;
private string[] CurrentAnimation = new string[2] { "", ""};
private float AnimationStopTime = 0;
private bool _isPlayingAnimation = false;
private string[] _currentAnimation = new string[2] { "", "" };
private float _animationStopTime = 0;
private void DisplayOnFoot()
{
@ -150,16 +150,16 @@ namespace CoopClient.Entities.Player
if (IsJumping)
{
if (!LastIsJumping)
if (!_lastIsJumping)
{
LastIsJumping = true;
_lastIsJumping = true;
Character.Task.Jump();
}
UpdateOnFootPosition();
return;
}
LastIsJumping = false;
_lastIsJumping = false;
if (IsRagdoll)
{
@ -181,9 +181,9 @@ namespace CoopClient.Entities.Player
Character.CanRagdoll = false;
Character.Task.ClearAllImmediately();
IsPlayingAnimation = true;
CurrentAnimation = new string[2] { "anim@sports@ballgame@handball@", "ball_get_up" };
AnimationStopTime = 0.7f;
_isPlayingAnimation = true;
_currentAnimation = new string[2] { "anim@sports@ballgame@handball@", "ball_get_up" };
_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);
return;
@ -226,7 +226,7 @@ namespace CoopClient.Entities.Player
#region WEAPON
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();
@ -238,21 +238,21 @@ namespace CoopClient.Entities.Player
}
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)
{
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()
{
if (!IsPlayingAnimation)
if (!_isPlayingAnimation)
{
return true;
}
switch (CurrentAnimation[0])
switch (_currentAnimation[0])
{
case "anim@sports@ballgame@handball@":
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;
}
break;
}
Character.Task.ClearAnimation(CurrentAnimation[0], CurrentAnimation[1]);
Character.Task.ClearAnimation(_currentAnimation[0], _currentAnimation[1]);
Character.Task.ClearAll();
IsPlayingAnimation = false;
CurrentAnimation = new string[2] { "", "" };
AnimationStopTime = 0;
_isPlayingAnimation = false;
_currentAnimation = new string[2] { "", "" };
_animationStopTime = 0;
return true;
}

View File

@ -10,16 +10,16 @@ namespace CoopClient.Entities.Player
public partial class EntitiesPlayer
{
#region -- VARIABLES --
private ulong VehicleStopTime { get; set; }
private ulong _vehicleStopTime { get; set; }
internal bool IsInVehicle { get; set; }
/// <summary>
/// The latest vehicle model hash (may not have been applied yet)
/// </summary>
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; }
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 bool VehicleDead { get; set; }
internal float VehicleEngineHealth { get; set; }
@ -34,12 +34,12 @@ namespace CoopClient.Entities.Player
public Quaternion VehicleRotation { get; internal set; }
internal float VehicleSpeed { get; set; }
internal float VehicleSteeringAngle { get; set; }
private int LastVehicleAim;
private int _lastVehicleAim = 0;
internal bool VehIsEngineRunning { get; set; }
internal float VehRPM { get; set; }
private bool LastTransformed = false;
private bool _lastTransformed = false;
internal bool Transformed { get; set; }
private bool LastHornActive = false;
private bool _lastHornActive = false;
internal bool IsHornActive { get; set; }
internal bool VehAreLightsOn { get; set; }
internal bool VehAreBrakeLightsOn = false;
@ -113,10 +113,10 @@ namespace CoopClient.Entities.Player
if (MainVehicle.IsTurretSeat(VehicleSeatIndex))
{
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);
LastVehicleAim = gameTime;
_lastVehicleAim = gameTime;
}
}
}
@ -126,11 +126,11 @@ namespace CoopClient.Entities.Player
return;
}
if (VehicleColors != null && VehicleColors != LastVehicleColors)
if (VehicleColors != null && VehicleColors != _lastVehicleColors)
{
Function.Call(Hash.SET_VEHICLE_COLOURS, MainVehicle, VehicleColors[0], VehicleColors[1]);
LastVehicleColors = VehicleColors;
_lastVehicleColors = VehicleColors;
}
if (Character.IsOnBike && MainVehicle.ClassType == VehicleClass.Cycles)
@ -151,7 +151,7 @@ namespace CoopClient.Entities.Player
}
else
{
if (VehicleMods != null && !VehicleMods.Compare(LastVehicleMods))
if (VehicleMods != null && !VehicleMods.Compare(_lastVehicleMods))
{
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;
}
LastVehicleMods = VehicleMods;
_lastVehicleMods = VehicleMods;
}
MainVehicle.EngineHealth = VehicleEngineHealth;
@ -193,14 +193,17 @@ namespace CoopClient.Entities.Player
if (MainVehicle.IsSubmarineCar)
{
if (Transformed && !LastTransformed)
if (Transformed)
{
LastTransformed = true;
Function.Call(Hash._TRANSFORM_VEHICLE_TO_SUBMARINE, MainVehicle.Handle, false);
if (!_lastTransformed)
{
_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);
}
}
@ -219,14 +222,17 @@ namespace CoopClient.Entities.Player
MainVehicle.IsSirenActive = VehIsSireneActive;
}
if (IsHornActive && !LastHornActive)
if (IsHornActive)
{
LastHornActive = true;
MainVehicle.SoundHorn(99999);
if (!_lastHornActive)
{
_lastHornActive = true;
MainVehicle.SoundHorn(99999);
}
}
else if (!IsHornActive && LastHornActive)
else if (_lastHornActive)
{
LastHornActive = false;
_lastHornActive = false;
MainVehicle.SoundHorn(1);
}
@ -261,11 +267,11 @@ namespace CoopClient.Entities.Player
MainVehicle.Velocity = Velocity + forceMultiplier * (Position - MainVehicle.Position);
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.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);

View File

@ -16,7 +16,7 @@ namespace CoopClient
/// </summary>
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;
/// <summary>
@ -29,14 +29,14 @@ namespace CoopClient
private void Ontick(object sender, EventArgs e)
{
if (!Main.MainNetworking.IsOnServer() || ScriptEngines.Count == 0)
if (!Main.MainNetworking.IsOnServer() || _scriptEngines.Count == 0)
{
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"))
{
@ -89,7 +89,7 @@ namespace CoopClient
finally
{
engine.Script.API.InvokeStart();
ScriptEngines.Add(engine);
_scriptEngines.Add(engine);
}
}
}
@ -99,14 +99,14 @@ namespace CoopClient
internal static void StopAll()
{
lock (ScriptEngines)
lock (_scriptEngines)
{
ScriptEngines.ForEach(engine =>
_scriptEngines.ForEach(engine =>
{
engine.Script.API.InvokeStop();
engine.Dispose();
});
ScriptEngines.Clear();
_scriptEngines.Clear();
}
JavascriptLoaded = false;
@ -114,25 +114,25 @@ namespace CoopClient
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)
{
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)
{
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;
private bool GameLoaded = false;
private bool _gameLoaded = false;
internal static readonly string CurrentVersion = "V1_4_0";
internal static bool ShareNPCsWithPlayers = false;
internal static bool DisableTraffic = false;
internal static bool NPCsAllowed = false;
private static bool IsGoingToCar = false;
private static bool _isGoingToCar = false;
internal static Settings MainSettings = null;
internal static Networking MainNetworking = null;
@ -58,10 +58,10 @@ namespace CoopClient
return;
}
if (!GameLoaded)
if (!_gameLoaded)
{
GTA.UI.Notification.Show("~r~Please update your GTA5 to v1.0.1290 or newer!", true);
GameLoaded = true;
_gameLoaded = true;
}
};
return;
@ -85,9 +85,9 @@ namespace CoopClient
}
#if DEBUG
private ulong LastDebugData;
private int DebugBytesSend;
private int DebugBytesReceived;
private ulong _lastDebugData;
private int _debugBytesSend;
private int _debugBytesReceived;
#endif
private void OnTick(object sender, EventArgs e)
{
@ -95,7 +95,7 @@ namespace CoopClient
{
return;
}
else if (!GameLoaded && (GameLoaded = true))
else if (!_gameLoaded && (_gameLoaded = true))
{
RelationshipGroup = World.AddRelationshipGroup("SYNCPED");
Game.Player.Character.RelationshipGroup.SetRelationshipBetweenGroups(RelationshipGroup, Relationship.Neutral, true);
@ -115,9 +115,9 @@ namespace CoopClient
JavascriptHook.LoadAll();
}
if (IsGoingToCar && Game.Player.Character.IsInVehicle())
if (_isGoingToCar && Game.Player.Character.IsInVehicle())
{
IsGoingToCar = false;
_isGoingToCar = false;
}
if (!MainNetworking.IsOnServer())
@ -129,19 +129,19 @@ namespace CoopClient
if (MainNetworking.ShowNetworkInfo)
{
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;
DebugBytesSend = MainNetworking.BytesSend;
_debugBytesSend = MainNetworking.BytesSend;
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, 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, 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();
}
#endif
@ -158,7 +158,7 @@ namespace CoopClient
// Display all players
foreach (KeyValuePair<long, EntitiesPlayer> player in Players)
{
player.Value.DisplayLocally(player.Value.Username);
player.Value.Update();
}
MainNetworking.SendPlayerData();
@ -190,10 +190,10 @@ namespace CoopClient
}
break;
case Keys.G:
if (IsGoingToCar)
if (_isGoingToCar)
{
Game.Player.Character.Task.ClearAll();
IsGoingToCar = false;
_isGoingToCar = false;
}
else if (!Game.Player.Character.IsInVehicle())
{
@ -205,7 +205,7 @@ namespace CoopClient
if (veh.IsSeatFree((VehicleSeat)i))
{
Game.Player.Character.Task.EnterVehicle(veh, (VehicleSeat)i);
IsGoingToCar = true;
_isGoingToCar = true;
break;
}
}
@ -354,7 +354,7 @@ namespace CoopClient
}
#if DEBUG
private ulong ArtificialLagCounter;
private ulong _artificialLagCounter;
internal static EntitiesPlayer DebugSyncPed;
internal static ulong LastFullDebugSync = 0;
internal static bool UseDebug = false;
@ -369,7 +369,7 @@ namespace CoopClient
DebugSyncPed = Players[0];
}
if ((Util.GetTickCount64() - ArtificialLagCounter) < 231)
if ((Util.GetTickCount64() - _artificialLagCounter) < 231)
{
return;
}
@ -465,9 +465,9 @@ namespace CoopClient
ulong currentTimestamp = Util.GetTickCount64();
DebugSyncPed.LastUpdateReceived = currentTimestamp;
DebugSyncPed.Latency = (currentTimestamp - ArtificialLagCounter) / 1000f;
DebugSyncPed.Latency = (currentTimestamp - _artificialLagCounter) / 1000f;
ArtificialLagCounter = currentTimestamp;
_artificialLagCounter = currentTimestamp;
if (fullSync)
{

View File

@ -25,10 +25,10 @@ namespace CoopClient.Menus
#endregion
#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 };
private readonly NativeItem ServerConnectItem = new NativeItem("Connect");
private readonly NativeItem AboutItem = new NativeItem("About", "~y~SOURCE~s~~n~" +
private readonly NativeItem _serverConnectItem = new NativeItem("Connect");
private readonly NativeItem _aboutItem = new NativeItem("About", "~y~SOURCE~s~~n~" +
"https://github.com/RAGECOOP~n~" +
"~y~VERSION~s~~n~" +
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.Title.Color = Color.FromArgb(255, 165, 0);
UsernameItem.Activated += UsernameActivated;
_usernameItem.Activated += UsernameActivated;
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.Add(UsernameItem);
MainMenu.Add(_usernameItem);
MainMenu.Add(ServerIpItem);
MainMenu.Add(ServerConnectItem);
MainMenu.Add(_serverConnectItem);
MainMenu.AddSubMenu(SubSettings.MainMenu);
MainMenu.Add(AboutItem);
MainMenu.Add(_aboutItem);
MenuPool.Add(ServerList.MainMenu);
MenuPool.Add(MainMenu);
@ -63,13 +63,13 @@ namespace CoopClient.Menus
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))
{
Main.MainSettings.Username = newUsername;
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
};
private readonly NativeCheckboxItem DisableTraffic = 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 FlipMenuItem = new NativeCheckboxItem("Flip menu", Main.MainSettings.FlipMenu);
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 _flipMenuItem = new NativeCheckboxItem("Flip menu", Main.MainSettings.FlipMenu);
#if DEBUG
private readonly NativeCheckboxItem UseDebugItem = new NativeCheckboxItem("Debug", Main.UseDebug);
private readonly NativeCheckboxItem ShowNetworkInfo = new NativeCheckboxItem("Show Network Info", Main.MainNetworking.ShowNetworkInfo);
private readonly NativeCheckboxItem _useDebugItem = new NativeCheckboxItem("Debug", Main.UseDebug);
private readonly NativeCheckboxItem _showNetworkInfoItem = new NativeCheckboxItem("Show Network Info", Main.MainNetworking.ShowNetworkInfo);
#endif
/// <summary>
@ -31,59 +31,60 @@ namespace CoopClient.Menus.Sub
MainMenu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
MainMenu.Title.Color = Color.FromArgb(255, 165, 0);
DisableTraffic.CheckboxChanged += DisableTrafficCheckboxChanged;
ShareNPCsItem.CheckboxChanged += (item, check) => { Main.ShareNPCsWithPlayers = ShareNPCsItem.Checked; };
FlipMenuItem.CheckboxChanged += FlipMenuCheckboxChanged;
_disableTrafficItem.CheckboxChanged += DisableTrafficCheckboxChanged;
_shareNPCsItem.CheckboxChanged += (item, check) => { Main.ShareNPCsWithPlayers = _shareNPCsItem.Checked; };
_flipMenuItem.CheckboxChanged += FlipMenuCheckboxChanged;
#if DEBUG
UseDebugItem.CheckboxChanged += UseDebugCheckboxChanged;
ShowNetworkInfo.CheckboxChanged += ShowNetworkInfoCheckboxChanged;
_useDebugItem.CheckboxChanged += UseDebugCheckboxChanged;
_showNetworkInfoItem.CheckboxChanged += ShowNetworkInfoCheckboxChanged;
#endif
MainMenu.Add(DisableTraffic);
MainMenu.Add(ShareNPCsItem);
MainMenu.Add(FlipMenuItem);
MainMenu.Add(_disableTrafficItem);
MainMenu.Add(_shareNPCsItem);
MainMenu.Add(_flipMenuItem);
#if DEBUG
MainMenu.Add(UseDebugItem);
MainMenu.Add(ShowNetworkInfo);
MainMenu.Add(_useDebugItem);
MainMenu.Add(_showNetworkInfoItem);
#endif
}
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)
{
#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
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();
}
#if DEBUG
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())
{
@ -99,7 +100,7 @@ namespace CoopClient.Menus.Sub
internal void ShowNetworkInfoCheckboxChanged(object a, System.EventArgs b)
{
Main.MainNetworking.ShowNetworkInfo = ShowNetworkInfo.Checked;
Main.MainNetworking.ShowNetworkInfo = _showNetworkInfoItem.Checked;
if (!Main.MainNetworking.ShowNetworkInfo)
{

View File

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

View File

@ -18,7 +18,7 @@ namespace CoopClient
static class Util
{
#region -- POINTER --
private static int SteeringAngleOffset { get; set; }
private static int _steeringAngleOffset { get; set; }
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");
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
@ -43,12 +43,12 @@ namespace CoopClient
public static unsafe void CustomSteeringAngle(this Vehicle veh, float value)
{
IntPtr address = new IntPtr((long)veh.MemoryAddress);
if (address == IntPtr.Zero || SteeringAngleOffset == 0)
if (address == IntPtr.Zero || _steeringAngleOffset == 0)
{
return;
}
*(float*)(address + SteeringAngleOffset).ToPointer() = value;
*(float*)(address + _steeringAngleOffset).ToPointer() = value;
}
#endregion

View File

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

View File

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

View File

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

View File

@ -8,7 +8,7 @@ namespace CoopServer
{
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 readonly List<DownloadFile> _files = new();
public static bool AnyFileExists = false;
@ -79,9 +79,9 @@ namespace CoopServer
{
lock (_clients)
{
lock (ClientsToDelete)
lock (_clientsToDelete)
{
foreach (long nethandle in ClientsToDelete)
foreach (long nethandle in _clientsToDelete)
{
DownloadClient client = _clients.FirstOrDefault(x => x.NetHandle == nethandle);
if (client != null)
@ -90,7 +90,7 @@ namespace CoopServer
_clients.Remove(client);
}
}
ClientsToDelete.Clear();
_clientsToDelete.Clear();
}
_clients.ForEach(client =>
@ -151,9 +151,9 @@ namespace CoopServer
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
{
private static readonly object Lock = new();
private static readonly object _lock = new();
public static void Info(string message)
{
lock (Lock)
lock (_lock)
{
string msg = string.Format("[{0}] [INFO] {1}", Date(), message);
@ -24,7 +24,7 @@ namespace CoopServer
public static void Warning(string message)
{
lock (Lock)
lock (_lock)
{
string msg = string.Format("[{0}] [WARNING] {1}", Date(), message);
@ -39,7 +39,7 @@ namespace CoopServer
public static void Error(string message)
{
lock (Lock)
lock (_lock)
{
string msg = string.Format("[{0}] [ERROR] {1}", Date(), message);
@ -59,7 +59,7 @@ namespace CoopServer
return;
}
lock (Lock)
lock (_lock)
{
string msg = string.Format("[{0}] [DEBUG] {1}", Date(), message);

View File

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

View File

@ -22,12 +22,12 @@ namespace CoopServer
internal class Server
{
private static readonly string CompatibleVersion = "V1_4";
private static long CurrentTick = 0;
private static readonly string _compatibleVersion = "V1_4";
private static long _currentTick = 0;
public static readonly Settings MainSettings = Util.Read<Settings>("Settings.xml");
private readonly Blocklist MainBlocklist = Util.Read<Blocklist>("Blocklist.xml");
private readonly Allowlist MainAllowlist = Util.Read<Allowlist>("Allowlist.xml");
private readonly Blocklist _mainBlocklist = Util.Read<Blocklist>("Blocklist.xml");
private readonly Allowlist _mainAllowlist = Util.Read<Allowlist>("Allowlist.xml");
public static NetServer MainNetServer;
@ -40,7 +40,7 @@ namespace CoopServer
{
Logging.Info("================");
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("================");
// 623c92c287cc392406e7aaaac1c0f3b0 = RAGECOOP
@ -110,10 +110,10 @@ namespace CoopServer
"\"address\": \"" + info.ip + "\", " +
"\"port\": \"" + MainSettings.Port + "\", " +
"\"name\": \"" + MainSettings.Name + "\", " +
"\"version\": \"" + CompatibleVersion.Replace("_", ".") + "\", " +
"\"version\": \"" + _compatibleVersion.Replace("_", ".") + "\", " +
"\"players\": \"" + MainNetServer.ConnectionsCount + "\", " +
"\"maxPlayers\": \"" + MainSettings.MaxPlayers + "\", " +
"\"allowlist\": \"" + MainAllowlist.Username.Any() + "\", " +
"\"allowlist\": \"" + _mainAllowlist.Username.Any() + "\", " +
"\"mods\": \"" + MainSettings.ModsAllowed + "\", " +
"\"npcs\": \"" + MainSettings.NpcsAllowed + "\", " +
"\"country\": \"" + info.country + "\"" +
@ -211,7 +211,7 @@ namespace CoopServer
{
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"
@ -604,9 +604,9 @@ namespace CoopServer
{
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;
}
if (string.IsNullOrWhiteSpace(packet.Username))
@ -619,17 +619,17 @@ namespace CoopServer
local.Deny("Username contains special chars!");
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!");
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!");
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!");
return;