diff --git a/RageCoop.Client.Installer/RageCoop.Client.Installer_ki4xybf5_wpftmp.csproj b/RageCoop.Client.Installer/RageCoop.Client.Installer_ki4xybf5_wpftmp.csproj
new file mode 100644
index 0000000..fabeabf
--- /dev/null
+++ b/RageCoop.Client.Installer/RageCoop.Client.Installer_ki4xybf5_wpftmp.csproj
@@ -0,0 +1,72 @@
+
+
+ RageCoop.Client.Installer
+ obj\Debug\
+ obj\
+ M:\SandBox-Shared\repos\RAGECOOP\RAGECOOP-V\RageCoop.Client.Installer\obj\
+ <_TargetAssemblyProjectName>RageCoop.Client.Installer
+
+
+
+ WinExe
+ net48
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+ True
+ True
+ Resource.resx
+
+
+
+
+ ResXFileCodeGenerator
+ Resource.Designer.cs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/RageCoop.Client/Debug.cs b/RageCoop.Client/Debug.cs
index 2746d69..61e7531 100644
--- a/RageCoop.Client/Debug.cs
+++ b/RageCoop.Client/Debug.cs
@@ -36,14 +36,14 @@ namespace RageCoop.Client
string s = "";
foreach (KeyValuePair kvp in d)
{
- s+=kvp.Key+":"+kvp.Value+"\n";
+ s += kvp.Key + ":" + kvp.Value + "\n";
}
return s;
}
public static void ShowTimeStamps()
{
GTA.UI.Notification.Hide(_lastNfHandle);
- _lastNfHandle=GTA.UI.Notification.Show(Debug.TimeStamps.Dump());
+ _lastNfHandle = GTA.UI.Notification.Show(Debug.TimeStamps.Dump());
}
}
diff --git a/RageCoop.Client/DevTools/DevTool.cs b/RageCoop.Client/DevTools/DevTool.cs
index 6a663ac..6c2b48f 100644
--- a/RageCoop.Client/DevTools/DevTool.cs
+++ b/RageCoop.Client/DevTools/DevTool.cs
@@ -16,14 +16,14 @@ namespace RageCoop.Client
public static MuzzleDir Direction = MuzzleDir.Forward;
public DevTool()
{
- Tick+=OnTick;
- KeyDown+=OnKeyDown;
+ Tick += OnTick;
+ KeyDown += OnKeyDown;
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
- if (ToMark==null||(!ToMark.Exists())) { return; }
- if (DevToolMenu.Menu.SelectedItem==DevToolMenu.boneIndexItem)
+ if (ToMark == null || (!ToMark.Exists())) { return; }
+ if (DevToolMenu.Menu.SelectedItem == DevToolMenu.boneIndexItem)
{
switch (e.KeyCode)
@@ -36,7 +36,7 @@ namespace RageCoop.Client
break;
}
}
- else if (DevToolMenu.Menu.SelectedItem==DevToolMenu.secondaryBoneIndexItem)
+ else if (DevToolMenu.Menu.SelectedItem == DevToolMenu.secondaryBoneIndexItem)
{
switch (e.KeyCode)
@@ -54,24 +54,24 @@ namespace RageCoop.Client
private static void Update()
{
- if (Current>ToMark.Bones.Count-1)
+ if (Current > ToMark.Bones.Count - 1)
{
- Current=0;
+ Current = 0;
}
- else if (Current< 0)
+ else if (Current < 0)
{
- Current=ToMark.Bones.Count-1;
+ Current = ToMark.Bones.Count - 1;
}
- DevToolMenu.boneIndexItem.AltTitle= Current.ToString();
- if (Secondary>ToMark.Bones.Count-1)
+ DevToolMenu.boneIndexItem.AltTitle = Current.ToString();
+ if (Secondary > ToMark.Bones.Count - 1)
{
- Secondary=0;
+ Secondary = 0;
}
- else if (Secondary< 0)
+ else if (Secondary < 0)
{
- Secondary=ToMark.Bones.Count-1;
+ Secondary = ToMark.Bones.Count - 1;
}
- DevToolMenu.secondaryBoneIndexItem.AltTitle= Secondary.ToString();
+ DevToolMenu.secondaryBoneIndexItem.AltTitle = Secondary.ToString();
}
private static void OnTick(object sender, EventArgs e)
{
@@ -87,44 +87,44 @@ namespace RageCoop.Client
private static void Draw(int boneindex)
{
var bone = ToMark.Bones[boneindex];
- World.DrawLine(bone.Position, bone.Position+2*bone.ForwardVector, Color.Blue);
- World.DrawLine(bone.Position, bone.Position+2*bone.UpVector, Color.Green);
- World.DrawLine(bone.Position, bone.Position+2*bone.RightVector, Color.Yellow);
+ World.DrawLine(bone.Position, bone.Position + 2 * bone.ForwardVector, Color.Blue);
+ World.DrawLine(bone.Position, bone.Position + 2 * bone.UpVector, Color.Green);
+ World.DrawLine(bone.Position, bone.Position + 2 * bone.RightVector, Color.Yellow);
Vector3 todraw = bone.ForwardVector;
switch ((byte)Direction)
{
case 0:
- todraw=bone.ForwardVector;
+ todraw = bone.ForwardVector;
break;
case 1:
- todraw=bone.RightVector;
+ todraw = bone.RightVector;
break;
case 2:
- todraw=bone.UpVector;
+ todraw = bone.UpVector;
break;
case 3:
- todraw=bone.ForwardVector*-1;
+ todraw = bone.ForwardVector * -1;
break;
case 4:
- todraw=bone.RightVector*-1;
+ todraw = bone.RightVector * -1;
break;
case 5:
- todraw=bone.UpVector*-1;
+ todraw = bone.UpVector * -1;
break;
}
- World.DrawLine(bone.Position, bone.Position+10*todraw, Color.Red);
+ World.DrawLine(bone.Position, bone.Position + 10 * todraw, Color.Red);
}
public static void CopyToClipboard(MuzzleDir dir)
{
- if (ToMark!=null)
+ if (ToMark != null)
{
string s;
if (UseSecondary)
{
- if ((byte)dir<3)
+ if ((byte)dir < 3)
{
- s=$@"
+ s = $@"
// {ToMark.DisplayName}
case {ToMark.Model.Hash}:
return BulletsShot%2==0 ? {Current} : {Secondary};
@@ -132,7 +132,7 @@ namespace RageCoop.Client
}
else
{
- s=$@"
+ s = $@"
// {ToMark.DisplayName}
case {ToMark.Model.Hash}:
return BulletsShot%2==0 ? {Current} : {Secondary};
@@ -141,9 +141,9 @@ namespace RageCoop.Client
}
else
{
- if ((byte)dir<3)
+ if ((byte)dir < 3)
{
- s=$@"
+ s = $@"
// {ToMark.DisplayName}
case {ToMark.Model.Hash}:
return {Current};
@@ -151,7 +151,7 @@ namespace RageCoop.Client
}
else
{
- s=$@"
+ s = $@"
// {ToMark.DisplayName}
case {ToMark.Model.Hash}:
return {Current};
diff --git a/RageCoop.Client/Main.cs b/RageCoop.Client/Main.cs
index 93994a3..0e36a9c 100644
--- a/RageCoop.Client/Main.cs
+++ b/RageCoop.Client/Main.cs
@@ -6,12 +6,11 @@ using RageCoop.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
-using System.IO;
using System.Drawing;
-using System.Linq;
-using System.Windows.Forms;
-using System.Threading.Tasks;
+using System.IO;
using System.Threading;
+using System.Threading.Tasks;
+using System.Windows.Forms;
namespace RageCoop.Client
{
@@ -21,7 +20,7 @@ namespace RageCoop.Client
internal class Main : Script
{
private bool _gameLoaded = false;
- internal static Version Version=typeof(Main).Assembly.GetName().Version;
+ internal static Version Version = typeof(Main).Assembly.GetName().Version;
internal static int LocalPlayerID = 0;
@@ -39,7 +38,7 @@ namespace RageCoop.Client
internal static ulong Ticked = 0;
internal static Vector3 PlayerPosition;
internal static Scripting.Resources Resources = null;
- private static List> QueuedActions = new List>();
+ private static readonly List> QueuedActions = new List>();
public static Worker Worker;
///
@@ -55,14 +54,14 @@ namespace RageCoop.Client
catch
{
GTA.UI.Notification.Show("Malformed configuration, overwriting with default values...");
- Settings=new Settings();
+ Settings = new Settings();
Util.SaveSettings();
}
Directory.CreateDirectory(Settings.DataDirectory);
- Logger=new Logger()
+ Logger = new Logger()
{
- LogPath=$"{Settings.DataDirectory}\\RageCoop.Client.log",
- UseConsole=false,
+ LogPath = $"{Settings.DataDirectory}\\RageCoop.Client.log",
+ UseConsole = false,
#if DEBUG
LogLevel = 0,
#else
@@ -87,7 +86,7 @@ namespace RageCoop.Client
return;
}
BaseScript.OnStart();
- SyncedPedsGroup=World.AddRelationshipGroup("SYNCPED");
+ SyncedPedsGroup = World.AddRelationshipGroup("SYNCPED");
Game.Player.Character.RelationshipGroup.SetRelationshipBetweenGroups(SyncedPedsGroup, Relationship.Neutral, true);
#if !NON_INTERACTIVE
#endif
@@ -95,9 +94,9 @@ namespace RageCoop.Client
Tick += OnTick;
Tick += (s, e) => { Scripting.API.Events.InvokeTick(); };
KeyDown += OnKeyDown;
- KeyDown+=(s, e) => { Scripting.API.Events.InvokeKeyDown(s, e); };
- KeyUp+=(s, e) => { Scripting.API.Events.InvokeKeyUp(s, e); };
- Aborted += (object sender, EventArgs e) => CleanUp();
+ KeyDown += (s, e) => { Scripting.API.Events.InvokeKeyDown(s, e); };
+ KeyUp += (s, e) => { Scripting.API.Events.InvokeKeyUp(s, e); };
+ Aborted += (object sender, EventArgs e) => Disconnected("Abort");
Util.NativeMemory();
Counter.Restart();
@@ -122,9 +121,9 @@ namespace RageCoop.Client
return $"{h1},{h2},{s},{s1}";
}
*/
- P= Game.Player.Character;
- PlayerPosition=P.ReadPosition();
- FPS=Game.FPS;
+ P = Game.Player.Character;
+ PlayerPosition = P.ReadPosition();
+ FPS = Game.FPS;
// World.DrawMarker(MarkerType.DebugSphere, PedExtensions.RaycastEverything(default), default, default, new Vector3(0.2f, 0.2f, 0.2f), Color.AliceBlue);
if (Game.IsLoading)
{
@@ -147,9 +146,9 @@ namespace RageCoop.Client
{
return;
}
- if (Game.TimeScale!=1)
+ if (Game.TimeScale != 1)
{
- Game.TimeScale=1;
+ Game.TimeScale = 1;
}
try
{
@@ -179,10 +178,10 @@ namespace RageCoop.Client
{
Function.Call(Hash.SET_FADE_OUT_AFTER_DEATH, false);
- if (P.Health!=1)
+ if (P.Health != 1)
{
- P.Health=1;
- Game.Player.WantedLevel=0;
+ P.Health = 1;
+ Game.Player.WantedLevel = 0;
Main.Logger.Debug("Player died.");
Scripting.API.Events.InvokePlayerDied();
}
@@ -197,8 +196,8 @@ namespace RageCoop.Client
{
Scripting.API.Events.InvokePlayerDied();
}
-
- _lastDead=P.IsDead;
+
+ _lastDead = P.IsDead;
Ticked++;
}
private void OnKeyDown(object sender, KeyEventArgs e)
@@ -223,13 +222,13 @@ namespace RageCoop.Client
return;
}
}
-
+
if (Game.IsControlPressed(GTA.Control.FrontendPause))
{
Function.Call(Hash.ACTIVATE_FRONTEND_MENU, Function.Call(Hash.GET_HASH_KEY, "FE_MENU_VERSION_SP_PAUSE"), false, 0);
return;
}
- if (Game.IsControlPressed(GTA.Control.FrontendPauseAlternate)&&Settings.DisableAlternatePause)
+ if (Game.IsControlPressed(GTA.Control.FrontendPauseAlternate) && Settings.DisableAlternatePause)
{
Function.Call(Hash.ACTIVATE_FRONTEND_MENU, Function.Call(Hash.GET_HASH_KEY, "FE_MENU_VERSION_SP_PAUSE"), false, 0);
return;
@@ -243,8 +242,8 @@ namespace RageCoop.Client
{
if (x.Visible)
{
- CoopMenu.LastMenu=x;
- x.Visible=false;
+ CoopMenu.LastMenu = x;
+ x.Visible = false;
}
});
}
@@ -269,7 +268,7 @@ namespace RageCoop.Client
PlayerList.Pressed = (currentTimestamp - PlayerList.Pressed) < 5000 ? (currentTimestamp - 6000) : currentTimestamp;
}
}
- else if (e.KeyCode==Settings.PassengerKey)
+ else if (e.KeyCode == Settings.PassengerKey)
{
var P = Game.Player.Character;
@@ -283,13 +282,13 @@ namespace RageCoop.Client
{
var V = World.GetClosestVehicle(P.ReadPosition(), 50);
- if (V!=null)
+ if (V != null)
{
var seat = P.GetNearestSeat(V);
var p = V.GetPedOnSeat(seat);
if (p != null && !p.IsDead)
{
- for(int i = -1; i < V.PassengerCapacity; i++)
+ for (int i = -1; i < V.PassengerCapacity; i++)
{
seat = (VehicleSeat)i;
p = V.GetPedOnSeat(seat);
@@ -299,21 +298,54 @@ namespace RageCoop.Client
}
}
}
- P.Task.EnterVehicle(V, seat,-1,5,EnterVehicleFlags.None);
+ P.Task.EnterVehicle(V, seat, -1, 5, EnterVehicleFlags.None);
}
}
}
}
}
- public static void CleanUp()
+ internal static void Connected()
{
- MainChat.Clear();
+ Memory.ApplyPatches();
+ if (Settings.Voice && !Voice.WasInitialized())
+ {
+ Voice.Init();
+ }
+ QueueAction(() =>
+ {
+ WorldThread.Traffic(!Settings.DisableTraffic);
+ Function.Call(Hash.SET_ENABLE_VEHICLE_SLIPSTREAMING, true);
+ CoopMenu.ConnectedMenuSetting();
+ MainChat.Init();
+ GTA.UI.Notification.Show("~g~Connected!");
+ });
+
+ Logger.Info(">> Connected <<");
+ }
+ public static void Disconnected(string reason)
+ {
+
+ Memory.RestorePatches();
+ DownloadManager.Cleanup();
Voice.ClearAll();
- EntityPool.Cleanup();
PlayerList.Cleanup();
- LocalPlayerID=default;
- WorldThread.Traffic(true);
- Function.Call(Hash.SET_ENABLE_VEHICLE_SLIPSTREAMING, false);
+ LocalPlayerID = default;
+
+ Logger.Info($">> Disconnected << reason: {reason}");
+ QueueAction(() =>
+ {
+ if (MainChat.Focused)
+ {
+ MainChat.Focused = false;
+ }
+ MainChat.Clear();
+ EntityPool.Cleanup();
+ WorldThread.Traffic(true);
+ Function.Call(Hash.SET_ENABLE_VEHICLE_SLIPSTREAMING, false);
+ CoopMenu.DisconnectedMenuSetting();
+ GTA.UI.Notification.Show("~r~Disconnected: " + reason);
+ });
+ Resources.Unload();
}
private static void DoQueuedActions()
{
@@ -371,5 +403,6 @@ namespace RageCoop.Client
QueueAction(a);
});
}
+
}
}
diff --git a/RageCoop.Client/Menus/CoopMenu.cs b/RageCoop.Client/Menus/CoopMenu.cs
index 35cfac2..76ce769 100644
--- a/RageCoop.Client/Menus/CoopMenu.cs
+++ b/RageCoop.Client/Menus/CoopMenu.cs
@@ -1,10 +1,9 @@
using GTA;
+using GTA.Native;
using LemonUI;
-using LemonUI.Elements;
using LemonUI.Menus;
using LemonUI.Scaleform;
using System.Drawing;
-using GTA.Native;
namespace RageCoop.Client.Menus
{
@@ -21,12 +20,12 @@ namespace RageCoop.Client.Menus
};
public static PopUp PopUp = new PopUp()
{
- Title="",
- Prompt="",
+ Title = "",
+ Prompt = "",
Subtitle = "",
- Error="",
+ Error = "",
ShowBackground = true,
- Visible=false,
+ Visible = false,
};
public static NativeMenu LastMenu { get; set; } = Menu;
#region ITEMS
@@ -54,7 +53,7 @@ namespace RageCoop.Client.Menus
Menu.Title.Color = Color.FromArgb(255, 165, 0);
_usernameItem.Activated += UsernameActivated;
- _passwordItem.Activated+=_passwordActivated;
+ _passwordItem.Activated += _passwordActivated;
ServerIpItem.Activated += ServerIpActivated;
_serverConnectItem.Activated += (sender, item) => { Networking.ToggleConnection(Main.Settings.LastServerAddress); };
@@ -86,12 +85,12 @@ namespace RageCoop.Client.Menus
public static bool ShowPopUp(string prompt, string title, string subtitle, string error, bool showbackground)
{
- PopUp.Prompt=prompt;
- PopUp.Title=title;
- PopUp.Subtitle=subtitle;
- PopUp.Error=error;
- PopUp.ShowBackground=showbackground;
- PopUp.Visible=true;
+ PopUp.Prompt = prompt;
+ PopUp.Title = title;
+ PopUp.Subtitle = subtitle;
+ PopUp.Error = error;
+ PopUp.ShowBackground = showbackground;
+ PopUp.Visible = true;
Script.Yield();
while (true)
{
@@ -109,7 +108,7 @@ namespace RageCoop.Client.Menus
scaleform.Render2D();
if (Game.IsControlJustPressed(Control.FrontendAccept))
{
- PopUp.Visible=false;
+ PopUp.Visible = false;
return true;
}
else if (Game.IsControlJustPressed(Control.FrontendCancel))
@@ -117,7 +116,7 @@ namespace RageCoop.Client.Menus
PopUp.Visible = false;
return false;
}
- Script.Yield();
+ Script.Yield();
Game.DisableAllControlsThisFrame();
}
diff --git a/RageCoop.Client/Menus/Sub/DebugMenu.cs b/RageCoop.Client/Menus/Sub/DebugMenu.cs
index 6a2f4bf..4dd0b3c 100644
--- a/RageCoop.Client/Menus/Sub/DebugMenu.cs
+++ b/RageCoop.Client/Menus/Sub/DebugMenu.cs
@@ -1,7 +1,7 @@
using GTA;
using LemonUI.Menus;
-using System.Drawing;
using System;
+using System.Drawing;
namespace RageCoop.Client
{
@@ -27,7 +27,7 @@ namespace RageCoop.Client
Menu.Title.Color = Color.FromArgb(255, 165, 0);
- DiagnosticMenu.Opening+=(sender, e) =>
+ DiagnosticMenu.Opening += (sender, e) =>
{
DiagnosticMenu.Clear();
DiagnosticMenu.Add(new NativeItem("EntityPool", EntityPool.DumpDebug()));
@@ -36,18 +36,18 @@ namespace RageCoop.Client
DiagnosticMenu.Add(new NativeItem(pair.Key.ToString(), pair.Value.ToString(), pair.Value.ToString()));
}
};
- SimulatedLatencyItem.Activated+=(s, e) =>
+ SimulatedLatencyItem.Activated += (s, e) =>
{
try
{
- SimulatedLatencyItem.AltTitle=((Networking.SimulatedLatency=int.Parse(Game.GetUserInput(SimulatedLatencyItem.AltTitle))*0.002f)*500).ToString();
+ SimulatedLatencyItem.AltTitle = ((Networking.SimulatedLatency = int.Parse(Game.GetUserInput(SimulatedLatencyItem.AltTitle)) * 0.002f) * 500).ToString();
}
- catch(Exception ex) { Main.Logger.Error(ex); }
+ catch (Exception ex) { Main.Logger.Error(ex); }
};
ShowNetworkInfoItem.CheckboxChanged += (s, e) => { Networking.ShowNetworkInfo = ShowNetworkInfoItem.Checked; };
ShowOwnerItem.CheckboxChanged += (s, e) => { Main.Settings.ShowEntityOwnerName = ShowOwnerItem.Checked; Util.SaveSettings(); };
Menu.Add(SimulatedLatencyItem);
- Menu.Add(ShowNetworkInfoItem);
+ Menu.Add(ShowNetworkInfoItem);
Menu.Add(ShowOwnerItem);
Menu.AddSubMenu(DiagnosticMenu);
diff --git a/RageCoop.Client/Menus/Sub/DevToolMenu.cs b/RageCoop.Client/Menus/Sub/DevToolMenu.cs
index 37c6eb8..943547b 100644
--- a/RageCoop.Client/Menus/Sub/DevToolMenu.cs
+++ b/RageCoop.Client/Menus/Sub/DevToolMenu.cs
@@ -12,9 +12,9 @@ namespace RageCoop.Client
UseMouse = false,
Alignment = Main.Settings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
};
- private static NativeCheckboxItem enableItem = new NativeCheckboxItem("Enable");
+ private static readonly NativeCheckboxItem enableItem = new NativeCheckboxItem("Enable");
- private static NativeCheckboxItem enableSecondaryItem = new NativeCheckboxItem("Secondary", "Enable if this vehicle have two muzzles");
+ private static readonly NativeCheckboxItem enableSecondaryItem = new NativeCheckboxItem("Secondary", "Enable if this vehicle have two muzzles");
public static NativeItem boneIndexItem = new NativeItem("Current bone index");
public static NativeItem secondaryBoneIndexItem = new NativeItem("Secondary bone index");
public static NativeItem clipboardItem = new NativeItem("Copy to clipboard");
@@ -24,18 +24,18 @@ namespace RageCoop.Client
Menu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
Menu.Title.Color = Color.FromArgb(255, 165, 0);
- enableItem.Activated+=enableItem_Activated;
- enableItem.Checked=false;
- enableSecondaryItem.CheckboxChanged+=EnableSecondaryItem_Changed;
+ enableItem.Activated += enableItem_Activated;
+ enableItem.Checked = false;
+ enableSecondaryItem.CheckboxChanged += EnableSecondaryItem_Changed;
- secondaryBoneIndexItem.Enabled=false;
- clipboardItem.Activated+=ClipboardItem_Activated;
- dirItem.ItemChanged+=DirItem_ItemChanged;
+ secondaryBoneIndexItem.Enabled = false;
+ clipboardItem.Activated += ClipboardItem_Activated;
+ dirItem.ItemChanged += DirItem_ItemChanged;
foreach (var d in Enum.GetValues(typeof(MuzzleDir)))
{
dirItem.Items.Add((MuzzleDir)d);
}
- dirItem.SelectedIndex=0;
+ dirItem.SelectedIndex = 0;
Menu.Add(enableItem);
Menu.Add(boneIndexItem);
@@ -49,19 +49,19 @@ namespace RageCoop.Client
{
if (enableSecondaryItem.Checked)
{
- DevTool.UseSecondary=true;
- secondaryBoneIndexItem.Enabled=true;
+ DevTool.UseSecondary = true;
+ secondaryBoneIndexItem.Enabled = true;
}
else
{
- DevTool.UseSecondary=false;
- secondaryBoneIndexItem.Enabled=false;
+ DevTool.UseSecondary = false;
+ secondaryBoneIndexItem.Enabled = false;
}
}
private static void DirItem_ItemChanged(object sender, ItemChangedEventArgs e)
{
- DevTool.Direction=dirItem.SelectedItem;
+ DevTool.Direction = dirItem.SelectedItem;
}
private static void ClipboardItem_Activated(object sender, EventArgs e)
@@ -73,11 +73,11 @@ namespace RageCoop.Client
{
if (enableItem.Checked)
{
- DevTool.ToMark=Game.Player.Character.CurrentVehicle;
+ DevTool.ToMark = Game.Player.Character.CurrentVehicle;
}
else
{
- DevTool.ToMark=null;
+ DevTool.ToMark = null;
}
}
}
diff --git a/RageCoop.Client/Menus/Sub/ServersMenu.cs b/RageCoop.Client/Menus/Sub/ServersMenu.cs
index ae4e4c5..8879f11 100644
--- a/RageCoop.Client/Menus/Sub/ServersMenu.cs
+++ b/RageCoop.Client/Menus/Sub/ServersMenu.cs
@@ -1,12 +1,12 @@
-using LemonUI.Menus;
+using GTA.UI;
+using LemonUI.Menus;
using Newtonsoft.Json;
+using RageCoop.Core;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Net;
using System.Threading;
-using RageCoop.Core;
-using GTA.UI;
namespace RageCoop.Client.Menus
{
@@ -38,7 +38,7 @@ namespace RageCoop.Client.Menus
Menu.Add(ResultItem = new NativeItem("Loading..."));
// Prevent freezing
- GetServersThread=new Thread(() => GetAllServers());
+ GetServersThread = new Thread(() => GetAllServers());
GetServersThread.Start();
};
Menu.Closing += (object sender, System.ComponentModel.CancelEventArgs e) =>
@@ -84,14 +84,14 @@ namespace RageCoop.Client.Menus
Menu.Visible = false;
if (server.useZT)
{
- address=$"{server.ztAddress}:{server.port}";
+ address = $"{server.ztAddress}:{server.port}";
Notification.Show($"~y~Joining ZeroTier network... {server.ztID}");
- if (ZeroTierHelper.Join(server.ztID)==null)
+ if (ZeroTierHelper.Join(server.ztID) == null)
{
throw new Exception("Failed to obtain ZeroTier network IP");
}
}
- Networking.ToggleConnection(address,null,null,PublicKey.FromServerInfo(server));
+ Networking.ToggleConnection(address, null, null, PublicKey.FromServerInfo(server));
#if !NON_INTERACTIVE
CoopMenu.ServerIpItem.AltTitle = address;
diff --git a/RageCoop.Client/Menus/Sub/SettingsMenu.cs b/RageCoop.Client/Menus/Sub/SettingsMenu.cs
index ad30107..8f6e7d2 100644
--- a/RageCoop.Client/Menus/Sub/SettingsMenu.cs
+++ b/RageCoop.Client/Menus/Sub/SettingsMenu.cs
@@ -18,10 +18,10 @@ namespace RageCoop.Client.Menus
private static readonly NativeCheckboxItem _flipMenuItem = new NativeCheckboxItem("Flip menu", Main.Settings.FlipMenu);
private static readonly NativeCheckboxItem _disablePauseAlt = new NativeCheckboxItem("Disable Alternate Pause", "Don't freeze game time when Esc pressed", Main.Settings.DisableAlternatePause);
private static readonly NativeCheckboxItem _disableVoice = new NativeCheckboxItem("Enable voice", "Check your GTA:V settings to find the right key on your keyboard for PushToTalk and talk to your friends", Main.Settings.Voice);
-
- private static NativeItem _menuKey = new NativeItem("Menu Key", "The key to open menu", Main.Settings.MenuKey.ToString());
- private static NativeItem _passengerKey = new NativeItem("Passenger Key", "The key to enter a vehicle as passenger", Main.Settings.PassengerKey.ToString());
- private static NativeItem _vehicleSoftLimit = new NativeItem("Vehicle limit (soft)", "The game won't spawn more NPC traffic if the limit is exceeded. \n-1 for unlimited (not recommended).", Main.Settings.WorldVehicleSoftLimit.ToString());
+
+ private static readonly NativeItem _menuKey = new NativeItem("Menu Key", "The key to open menu", Main.Settings.MenuKey.ToString());
+ private static readonly NativeItem _passengerKey = new NativeItem("Passenger Key", "The key to enter a vehicle as passenger", Main.Settings.PassengerKey.ToString());
+ private static readonly NativeItem _vehicleSoftLimit = new NativeItem("Vehicle limit (soft)", "The game won't spawn more NPC traffic if the limit is exceeded. \n-1 for unlimited (not recommended).", Main.Settings.WorldVehicleSoftLimit.ToString());
static SettingsMenu()
{
@@ -29,12 +29,12 @@ namespace RageCoop.Client.Menus
Menu.Title.Color = Color.FromArgb(255, 165, 0);
_disableTrafficItem.CheckboxChanged += DisableTrafficCheckboxChanged;
- _disablePauseAlt.CheckboxChanged+= DisablePauseAltCheckboxChanged;
+ _disablePauseAlt.CheckboxChanged += DisablePauseAltCheckboxChanged;
_disableVoice.CheckboxChanged += DisableVoiceCheckboxChanged;
_flipMenuItem.CheckboxChanged += FlipMenuCheckboxChanged;
- _menuKey.Activated+= ChaneMenuKey;
- _passengerKey.Activated+= ChangePassengerKey;
- _vehicleSoftLimit.Activated+= VehicleSoftLimitActivated;
+ _menuKey.Activated += ChaneMenuKey;
+ _passengerKey.Activated += ChangePassengerKey;
+ _vehicleSoftLimit.Activated += VehicleSoftLimitActivated;
Menu.Add(_disableTrafficItem);
Menu.Add(_disablePauseAlt);
@@ -53,7 +53,9 @@ namespace RageCoop.Client.Menus
{
Voice.Init();
}
- } else {
+ }
+ else
+ {
Voice.ClearAll();
}
@@ -63,17 +65,17 @@ namespace RageCoop.Client.Menus
private static void DisablePauseAltCheckboxChanged(object sender, EventArgs e)
{
- Main.Settings.DisableAlternatePause=_disablePauseAlt.Checked;
+ Main.Settings.DisableAlternatePause = _disablePauseAlt.Checked;
Util.SaveSettings();
}
private static void VehicleSoftLimitActivated(object sender, EventArgs e)
{
try
{
- Main.Settings.WorldVehicleSoftLimit =int.Parse(
+ Main.Settings.WorldVehicleSoftLimit = int.Parse(
Game.GetUserInput(WindowTitle.EnterMessage20,
Main.Settings.WorldVehicleSoftLimit.ToString(), 20));
- _menuKey.AltTitle=Main.Settings.WorldVehicleSoftLimit.ToString();
+ _menuKey.AltTitle = Main.Settings.WorldVehicleSoftLimit.ToString();
Util.SaveSettings();
}
catch { }
@@ -82,11 +84,11 @@ namespace RageCoop.Client.Menus
{
try
{
- Main.Settings.MenuKey =(Keys)Enum.Parse(
+ Main.Settings.MenuKey = (Keys)Enum.Parse(
typeof(Keys),
Game.GetUserInput(WindowTitle.EnterMessage20,
Main.Settings.MenuKey.ToString(), 20));
- _menuKey.AltTitle=Main.Settings.MenuKey.ToString();
+ _menuKey.AltTitle = Main.Settings.MenuKey.ToString();
Util.SaveSettings();
}
catch { }
@@ -96,11 +98,11 @@ namespace RageCoop.Client.Menus
{
try
{
- Main.Settings.PassengerKey =(Keys)Enum.Parse(
+ Main.Settings.PassengerKey = (Keys)Enum.Parse(
typeof(Keys),
Game.GetUserInput(WindowTitle.EnterMessage20,
Main.Settings.PassengerKey.ToString(), 20));
- _passengerKey.AltTitle=Main.Settings.PassengerKey.ToString();
+ _passengerKey.AltTitle = Main.Settings.PassengerKey.ToString();
Util.SaveSettings();
}
catch { }
diff --git a/RageCoop.Client/Menus/Sub/UpdateMenu.cs b/RageCoop.Client/Menus/Sub/UpdateMenu.cs
index 598e071..8ea727e 100644
--- a/RageCoop.Client/Menus/Sub/UpdateMenu.cs
+++ b/RageCoop.Client/Menus/Sub/UpdateMenu.cs
@@ -11,10 +11,10 @@ namespace RageCoop.Client.Menus
internal class UpdateMenu
{
public static bool IsUpdating { get; private set; } = false;
- private static NativeItem _updatingItem = new NativeItem("Updating...");
- private static NativeItem _downloadItem = new NativeItem("Download", "Download and update to latest nightly");
+ private static readonly NativeItem _updatingItem = new NativeItem("Updating...");
+ private static readonly NativeItem _downloadItem = new NativeItem("Download", "Download and update to latest nightly");
- private static string _downloadPath = Path.Combine(Main.Settings.DataDirectory, "RageCoop.Client.zip");
+ private static readonly string _downloadPath = Path.Combine(Main.Settings.DataDirectory, "RageCoop.Client.zip");
public static NativeMenu Menu = new NativeMenu("Update", "Update", "Download and install latest nightly build from GitHub")
{
UseMouse = false,
@@ -24,13 +24,13 @@ namespace RageCoop.Client.Menus
{
Menu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
Menu.Title.Color = Color.FromArgb(255, 165, 0);
- Menu.Opening+=Opening;
- _downloadItem.Activated+=StartUpdate;
+ Menu.Opening += Opening;
+ _downloadItem.Activated += StartUpdate;
}
private static void StartUpdate(object sender, EventArgs e)
{
- IsUpdating=true;
+ IsUpdating = true;
Menu.Clear();
Menu.Add(_updatingItem);
Task.Run(() =>
@@ -45,8 +45,8 @@ namespace RageCoop.Client.Menus
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
- client.DownloadProgressChanged += (s, e1) => { Main.QueueAction(() => { _updatingItem.AltTitle=$"{e1.ProgressPercentage}%"; }); };
- client.DownloadFileCompleted +=(s, e2) => { Install(); };
+ client.DownloadProgressChanged += (s, e1) => { Main.QueueAction(() => { _updatingItem.AltTitle = $"{e1.ProgressPercentage}%"; }); };
+ client.DownloadFileCompleted += (s, e2) => { Install(); };
client.DownloadFileAsync(new Uri("https://github.com/RAGECOOP/RAGECOOP-V/releases/download/nightly/RageCoop.Client.zip"), _downloadPath);
}
catch (Exception ex)
@@ -62,21 +62,21 @@ namespace RageCoop.Client.Menus
{
Main.QueueAction(() =>
{
- _updatingItem.AltTitle="Installing...";
+ _updatingItem.AltTitle = "Installing...";
});
Directory.CreateDirectory(@"Scripts\RageCoop");
- foreach(var f in Directory.GetFiles(@"Scripts\RageCoop", "*.dll", SearchOption.AllDirectories))
+ foreach (var f in Directory.GetFiles(@"Scripts\RageCoop", "*.dll", SearchOption.AllDirectories))
{
try { File.Delete(f); }
catch { }
}
new FastZip().ExtractZip(_downloadPath, "Scripts", FastZip.Overwrite.Always, null, null, null, true);
try { File.Delete(_downloadPath); } catch { }
- try { File.Delete(Path.Combine("Scripts","RageCoop.Client.Installer.exe")); } catch { }
+ try { File.Delete(Path.Combine("Scripts", "RageCoop.Client.Installer.exe")); } catch { }
Main.QueueAction(() =>
{
Util.Reload();
- IsUpdating=false;
+ IsUpdating = false;
});
}
catch (Exception ex)
diff --git a/RageCoop.Client/Networking/Chat.cs b/RageCoop.Client/Networking/Chat.cs
index 2a5376d..2dad73b 100644
--- a/RageCoop.Client/Networking/Chat.cs
+++ b/RageCoop.Client/Networking/Chat.cs
@@ -16,7 +16,7 @@ namespace RageCoop.Client
private bool CurrentFocused { get; set; }
public bool Focused
{
- get { return CurrentFocused; }
+ get => CurrentFocused;
set
{
if (value && Hidden)
@@ -35,7 +35,7 @@ namespace RageCoop.Client
private bool CurrentHidden { get; set; }
private bool Hidden
{
- get { return CurrentHidden; }
+ get => CurrentHidden;
set
{
if (value)
diff --git a/RageCoop.Client/Networking/DownloadManager.cs b/RageCoop.Client/Networking/DownloadManager.cs
index 11fbb0c..f711382 100644
--- a/RageCoop.Client/Networking/DownloadManager.cs
+++ b/RageCoop.Client/Networking/DownloadManager.cs
@@ -21,8 +21,8 @@ namespace RageCoop.Client
}
return new Packets.FileTransferResponse()
{
- ID= fr.ID,
- Response=AddFile(fr.ID, fr.Name, fr.FileLength) ? FileResponse.NeedToDownload : FileResponse.AlreadyExists
+ ID = fr.ID,
+ Response = AddFile(fr.ID, fr.Name, fr.FileLength) ? FileResponse.NeedToDownload : FileResponse.AlreadyExists
};
});
Networking.RequestHandlers.Add(PacketType.FileTransferComplete, (data) =>
@@ -36,8 +36,8 @@ namespace RageCoop.Client
// Inform the server that the download is completed
return new Packets.FileTransferResponse()
{
- ID= packet.ID,
- Response=FileResponse.Completed
+ ID = packet.ID,
+ Response = FileResponse.Completed
};
});
Networking.RequestHandlers.Add(PacketType.AllResourcesSent, (data) =>
@@ -45,13 +45,13 @@ namespace RageCoop.Client
try
{
Main.Resources.Load(ResourceFolder, _resources.ToArray());
- return new Packets.FileTransferResponse() { ID=0, Response=FileResponse.Loaded };
+ return new Packets.FileTransferResponse() { ID = 0, Response = FileResponse.Loaded };
}
catch (Exception ex)
{
Main.Logger.Error("Error occurred when loading server resource:");
Main.Logger.Error(ex);
- return new Packets.FileTransferResponse() { ID=0, Response=FileResponse.LoadFailed };
+ return new Packets.FileTransferResponse() { ID = 0, Response = FileResponse.LoadFailed };
}
});
}
@@ -176,7 +176,7 @@ namespace RageCoop.Client
public FileStream Stream { get; set; }
public void Dispose()
{
- if (Stream!= null)
+ if (Stream != null)
{
Stream.Flush();
Stream.Close();
diff --git a/RageCoop.Client/Networking/HolePunch.cs b/RageCoop.Client/Networking/HolePunch.cs
index 16a26ed..acfa7b0 100644
--- a/RageCoop.Client/Networking/HolePunch.cs
+++ b/RageCoop.Client/Networking/HolePunch.cs
@@ -1,12 +1,10 @@
-using System;
+using Lidgren.Network;
+using RageCoop.Core;
+using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Timers;
-using RageCoop.Core;
-using Lidgren.Network;
using System.Net;
+using System.Timers;
namespace RageCoop.Client
{
@@ -15,9 +13,9 @@ namespace RageCoop.Client
static HolePunch()
{
// Periodically send hole punch message as needed
- var timer=new Timer(1000);
- timer.Elapsed+=DoPunch;
- timer.Enabled=true;
+ var timer = new Timer(1000);
+ timer.Elapsed += DoPunch;
+ timer.Enabled = true;
}
private static void DoPunch(object sender, ElapsedEventArgs e)
@@ -27,14 +25,14 @@ namespace RageCoop.Client
if (!Networking.IsOnServer) { return; }
foreach (var p in PlayerList.Players.Values.ToArray())
{
- if (p.InternalEndPoint!=null && p.ExternalEndPoint!=null && (p.Connection==null || p.Connection.Status==NetConnectionStatus.Disconnected))
+ if (p.InternalEndPoint != null && p.ExternalEndPoint != null && (p.Connection == null || p.Connection.Status == NetConnectionStatus.Disconnected))
{
Main.Logger.Trace($"Sending HolePunch message to {p.InternalEndPoint},{p.ExternalEndPoint}. {p.Username}:{p.ID}");
var msg = Networking.Peer.CreateMessage();
new Packets.HolePunch
{
- Puncher=Main.LocalPlayerID,
- Status=p.HolePunchStatus
+ Puncher = Main.LocalPlayerID,
+ Status = p.HolePunchStatus
}.Pack(msg);
Networking.Peer.SendUnconnectedMessage(msg, new List { p.InternalEndPoint, p.ExternalEndPoint });
}
@@ -48,34 +46,34 @@ namespace RageCoop.Client
public static void Add(Packets.HolePunchInit p)
{
- if(PlayerList.Players.TryGetValue(p.TargetID,out var player))
+ if (PlayerList.Players.TryGetValue(p.TargetID, out var player))
{
Main.Logger.Debug($"{p.TargetID},{player.Username} added to HolePunch target");
player.InternalEndPoint = CoreUtils.StringToEndPoint(p.TargetInternal);
player.ExternalEndPoint = CoreUtils.StringToEndPoint(p.TargetExternal);
- player.ConnectWhenPunched=p.Connect;
+ player.ConnectWhenPunched = p.Connect;
}
else
{
- Main.Logger.Warning("No player with specified TargetID found for hole punching:"+p.TargetID);
+ Main.Logger.Warning("No player with specified TargetID found for hole punching:" + p.TargetID);
}
}
- public static void Punched(Packets.HolePunch p,IPEndPoint from)
+ public static void Punched(Packets.HolePunch p, IPEndPoint from)
{
Main.Logger.Debug($"HolePunch message received from:{from}, status:{p.Status}");
- if(PlayerList.Players.TryGetValue(p.Puncher,out var puncher))
+ if (PlayerList.Players.TryGetValue(p.Puncher, out var puncher))
{
- Main.Logger.Debug("Puncher identified as: "+puncher.Username);
- puncher.HolePunchStatus=(byte)(p.Status+1);
- if (p.Status>=3)
+ Main.Logger.Debug("Puncher identified as: " + puncher.Username);
+ puncher.HolePunchStatus = (byte)(p.Status + 1);
+ if (p.Status >= 3)
{
- Main.Logger.Debug("HolePunch sucess: "+from+", "+puncher.ID);
- if (puncher.ConnectWhenPunched && (puncher.Connection==null || puncher.Connection.Status==NetConnectionStatus.Disconnected))
+ Main.Logger.Debug("HolePunch sucess: " + from + ", " + puncher.ID);
+ if (puncher.ConnectWhenPunched && (puncher.Connection == null || puncher.Connection.Status == NetConnectionStatus.Disconnected))
{
- Main.Logger.Debug("Connecting to peer: "+from);
+ Main.Logger.Debug("Connecting to peer: " + from);
var msg = Networking.Peer.CreateMessage();
- new Packets.P2PConnect { ID=Main.LocalPlayerID }.Pack(msg);
- puncher.Connection=Networking.Peer.Connect(from,msg);
+ new Packets.P2PConnect { ID = Main.LocalPlayerID }.Pack(msg);
+ puncher.Connection = Networking.Peer.Connect(from, msg);
Networking.Peer.FlushSendQueue();
}
}
diff --git a/RageCoop.Client/Networking/Networking.cs b/RageCoop.Client/Networking/Networking.cs
index 9c250ba..df73b7b 100644
--- a/RageCoop.Client/Networking/Networking.cs
+++ b/RageCoop.Client/Networking/Networking.cs
@@ -1,41 +1,42 @@
-using Lidgren.Network;
+using GTA.UI;
+using Lidgren.Network;
using RageCoop.Core;
using System;
using System.Collections.Generic;
+using System.Net;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
-using GTA.UI;
-using System.Net;
namespace RageCoop.Client
{
internal static partial class Networking
{
public static CoopPeer Peer;
- public static float Latency => ServerConnection.AverageRoundtripTime/2;
+ public static float Latency => ServerConnection.AverageRoundtripTime / 2;
public static bool ShowNetworkInfo = false;
public static Security Security;
public static NetConnection ServerConnection;
private static readonly Dictionary> PendingResponses = new Dictionary>();
internal static readonly Dictionary> RequestHandlers = new Dictionary>();
- internal static float SimulatedLatency=0;
+ internal static float SimulatedLatency = 0;
public static bool IsConnecting { get; private set; }
public static IPEndPoint _targetServerEP;
static Networking()
{
- Security=new Security(Main.Logger);
+ Security = new Security(Main.Logger);
}
- public static void ToggleConnection(string address, string username = null, string password = null,PublicKey publicKey=null)
+ public static void ToggleConnection(string address, string username = null, string password = null, PublicKey publicKey = null)
{
- Menus.CoopMenu.Menu.Visible=false;
+ Menus.CoopMenu.Menu.Visible = false;
Peer?.Shutdown("Bye");
if (IsOnServer)
{
// ?
}
- else if (IsConnecting) {
+ else if (IsConnecting)
+ {
_publicKeyReceived.Set();
IsConnecting = false;
Notification.Show("Connection has been canceled");
@@ -46,14 +47,14 @@ namespace RageCoop.Client
IsConnecting = true;
password = password ?? Main.Settings.Password;
- username=username ?? Main.Settings.Username;
+ username = username ?? Main.Settings.Username;
// 623c92c287cc392406e7aaaac1c0f3b0 = RAGECOOP
NetPeerConfiguration config = new NetPeerConfiguration("623c92c287cc392406e7aaaac1c0f3b0")
{
AutoFlushSendQueue = false,
- SimulatedMinimumLatency =SimulatedLatency,
- SimulatedRandomLatency=0,
+ SimulatedMinimumLatency = SimulatedLatency,
+ SimulatedRandomLatency = 0,
AcceptIncomingConnections = true,
MaximumConnections = 32,
PingInterval = 5
@@ -78,45 +79,47 @@ namespace RageCoop.Client
PlayerList.Cleanup();
EntityPool.AddPlayer();
- if (publicKey==null && !string.IsNullOrEmpty(password) && !Menus.CoopMenu.ShowPopUp("", "WARNING", "Server's IP can be spoofed when using direct connection, do you wish to continue?", "", true))
+ if (publicKey == null && !string.IsNullOrEmpty(password) && !Menus.CoopMenu.ShowPopUp("", "WARNING", "Server's IP can be spoofed when using direct connection, do you wish to continue?", "", true))
{
- IsConnecting=false;
+ IsConnecting = false;
return;
}
Task.Run(() =>
{
try
{
- _targetServerEP=CoreUtils.StringToEndPoint(address);
+ _targetServerEP = CoreUtils.StringToEndPoint(address);
DownloadManager.Cleanup();
Peer = new CoopPeer(config);
- Peer.OnMessageReceived+= (s, m) =>
+ Peer.OnMessageReceived += (s, m) =>
{
try { ProcessMessage(m); }
catch (Exception ex) { Main.Logger.Error(ex); }
};
Main.QueueAction(() => { Notification.Show($"~y~Trying to connect..."); });
- Menus.CoopMenu._serverConnectItem.Enabled=false;
+ Menus.CoopMenu._serverConnectItem.Enabled = false;
Security.Regen();
- if(publicKey==null){
- if (!GetServerPublicKey(ip[0],int.Parse(ip[1])))
+ if (publicKey == null)
+ {
+ if (!GetServerPublicKey(ip[0], int.Parse(ip[1])))
{
- Menus.CoopMenu._serverConnectItem.Enabled=true;
+ Menus.CoopMenu._serverConnectItem.Enabled = true;
throw new TimeoutException("Failed to retrive server's public key");
}
}
- else{
- Security.SetServerPublicKey(publicKey.Modulus,publicKey.Exponent);
+ else
+ {
+ Security.SetServerPublicKey(publicKey.Modulus, publicKey.Exponent);
}
// Send handshake packet
NetOutgoingMessage outgoingMessage = Peer.CreateMessage();
var handshake = new Packets.Handshake()
{
- PedID = Main.LocalPlayerID,
- Username =username,
+ PedID = Main.LocalPlayerID,
+ Username = username,
ModVersion = Main.Version.ToString(),
- PasswordEncrypted=Security.Encrypt(password.GetBytes()),
+ PasswordEncrypted = Security.Encrypt(password.GetBytes()),
InternalEndPoint = new System.Net.IPEndPoint(CoreUtils.GetLocalAddress(ip[0]), Peer.Port)
};
@@ -128,9 +131,9 @@ namespace RageCoop.Client
catch (Exception ex)
{
Main.Logger.Error("Cannot connect to server: ", ex);
- Main.QueueAction(() => Notification.Show("Cannot connect to server: "+ex.Message));
+ Main.QueueAction(() => Notification.Show("Cannot connect to server: " + ex.Message));
}
- IsConnecting=false;
+ IsConnecting = false;
});
}
}
@@ -142,7 +145,7 @@ namespace RageCoop.Client
var p = new Player
{
ID = packet.PedID,
- Username= packet.Username,
+ Username = packet.Username,
};
PlayerList.SetPlayer(packet.PedID, packet.Username);
@@ -153,9 +156,10 @@ namespace RageCoop.Client
private static void PlayerDisconnect(Packets.PlayerDisconnect packet)
{
var player = PlayerList.GetPlayer(packet.PedID);
- if (player==null) { return; }
+ if (player == null) { return; }
PlayerList.RemovePlayer(packet.PedID);
- Main.QueueAction(() => {
+ Main.QueueAction(() =>
+ {
EntityPool.RemoveAllFromPlayer(packet.PedID);
GTA.UI.Notification.Show($"~h~{player.Username}~h~ left.");
});
@@ -163,13 +167,13 @@ namespace RageCoop.Client
#endregion // -- PLAYER --
#region -- GET --
- private static bool GetServerPublicKey(string host,int port, int timeout = 10000)
+ private static bool GetServerPublicKey(string host, int port, int timeout = 10000)
{
- Security.ServerRSA=null;
+ Security.ServerRSA = null;
var msg = Peer.CreateMessage();
new Packets.PublicKeyRequest().Pack(msg);
Peer.SendUnconnectedMessage(msg, host, port);
- return _publicKeyReceived.WaitOne(timeout) && Security.ServerRSA!=null;
+ return _publicKeyReceived.WaitOne(timeout) && Security.ServerRSA != null;
}
public static void GetResponse(Packet request, Action callback, ConnectionChannel channel = ConnectionChannel.RequestResponse) where T : Packet, new()
@@ -186,14 +190,14 @@ namespace RageCoop.Client
msg.Write((byte)PacketType.Request);
msg.Write(id);
request.Pack(msg);
- Peer.SendMessage(msg,ServerConnection, NetDeliveryMethod.ReliableOrdered, (int)channel);
+ Peer.SendMessage(msg, ServerConnection, NetDeliveryMethod.ReliableOrdered, (int)channel);
}
#endregion
private static int NewRequestID()
{
int ID = 0;
- while ((ID==0) || PendingResponses.ContainsKey(ID))
+ while ((ID == 0) || PendingResponses.ContainsKey(ID))
{
byte[] rngBytes = new byte[4];
diff --git a/RageCoop.Client/Networking/Receive.cs b/RageCoop.Client/Networking/Receive.cs
index 0519aee..3d37ddb 100644
--- a/RageCoop.Client/Networking/Receive.cs
+++ b/RageCoop.Client/Networking/Receive.cs
@@ -3,9 +3,7 @@ using Lidgren.Network;
using RageCoop.Client.Menus;
using RageCoop.Core;
using System;
-using System.Collections.Generic;
using System.Threading;
-using GTA.Native;
namespace RageCoop.Client
{
@@ -15,7 +13,7 @@ namespace RageCoop.Client
///
/// Reduce GC pressure by reusing frequently used packets
///
- static class ReceivedPackets
+ private static class ReceivedPackets
{
public static Packets.PedSync PedPacket = new Packets.PedSync();
public static Packets.VehicleSync VehicelPacket = new Packets.VehicleSync();
@@ -38,7 +36,7 @@ namespace RageCoop.Client
case 60:
return EntityPool.ServerBlips[reader.ReadInt32()].Handle;
default:
- throw new ArgumentException("Cannot resolve server side argument: "+t);
+ throw new ArgumentException("Cannot resolve server side argument: " + t);
}
};
private static readonly AutoResetEvent _publicKeyReceived = new AutoResetEvent(false);
@@ -54,50 +52,36 @@ namespace RageCoop.Client
switch (status)
{
case NetConnectionStatus.InitiatedConnect:
- if (message.SenderConnection==ServerConnection)
+ if (message.SenderConnection == ServerConnection)
{
CoopMenu.InitiateConnectionMenuSetting();
}
break;
case NetConnectionStatus.Connected:
- if (message.SenderConnection==ServerConnection)
+ if (message.SenderConnection == ServerConnection)
{
- Memory.ApplyPatches();
var response = message.SenderConnection.RemoteHailMessage;
- if ((PacketType)response.ReadByte()!=PacketType.HandshakeSuccess)
+ if ((PacketType)response.ReadByte() != PacketType.HandshakeSuccess)
{
throw new Exception("Invalid handshake response!");
}
var p = new Packets.HandshakeSuccess();
p.Deserialize(response.ReadBytes(response.ReadInt32()));
- foreach(var player in p.Players)
+ foreach (var player in p.Players)
{
- PlayerList.SetPlayer(player.ID,player.Username);
+ PlayerList.SetPlayer(player.ID, player.Username);
}
- Main.QueueAction(() =>
- {
- WorldThread.Traffic(!Main.Settings.DisableTraffic);
- Function.Call(Hash.SET_ENABLE_VEHICLE_SLIPSTREAMING, true);
- CoopMenu.ConnectedMenuSetting();
- Main.MainChat.Init();
- if (Main.Settings.Voice && !Voice.WasInitialized())
- {
- Voice.Init();
- }
- GTA.UI.Notification.Show("~g~Connected!");
- });
-
- Main.Logger.Info(">> Connected <<");
+ Main.Connected();
}
else
{
// Self-initiated connection
- if (message.SenderConnection.RemoteHailMessage==null) { return; }
-
+ if (message.SenderConnection.RemoteHailMessage == null) { return; }
+
var p = message.SenderConnection.RemoteHailMessage.GetPacket();
- if (PlayerList.Players.TryGetValue(p.ID,out var player))
+ if (PlayerList.Players.TryGetValue(p.ID, out var player))
{
- player.Connection=message.SenderConnection;
+ player.Connection = message.SenderConnection;
Main.Logger.Debug($"Direct connection to {player.Username} established");
}
else
@@ -108,28 +92,16 @@ namespace RageCoop.Client
}
break;
case NetConnectionStatus.Disconnected:
- if (message.SenderConnection==ServerConnection)
+ if (message.SenderConnection == ServerConnection)
{
- Memory.RestorePatches();
- DownloadManager.Cleanup();
-
- if (Main.MainChat.Focused)
- {
- Main.MainChat.Focused = false;
- }
-
- Main.QueueAction(() => Main.CleanUp());
- CoopMenu.DisconnectedMenuSetting();
- Main.Logger.Info($">> Disconnected << reason: {reason}");
- Main.QueueAction(() => GTA.UI.Notification.Show("~r~Disconnected: " + reason));
- Main.Resources.Unload();
+ Main.Disconnected(reason);
}
break;
}
break;
case NetIncomingMessageType.Data:
{
- if (message.LengthBytes==0) { break; }
+ if (message.LengthBytes == 0) { break; }
var packetType = PacketType.Unknown;
try
{
@@ -158,7 +130,7 @@ namespace RageCoop.Client
response.Write((byte)PacketType.Response);
response.Write(id);
handler(message.ReadBytes(len)).Pack(response);
- Peer.SendMessage(response,ServerConnection, NetDeliveryMethod.ReliableOrdered, message.SequenceChannel);
+ Peer.SendMessage(response, ServerConnection, NetDeliveryMethod.ReliableOrdered, message.SequenceChannel);
Peer.FlushSendQueue();
}
break;
@@ -167,7 +139,7 @@ namespace RageCoop.Client
{
byte[] data = message.ReadBytes(message.ReadInt32());
- HandlePacket(packetType, data,message.SenderConnection);
+ HandlePacket(packetType, data, message.SenderConnection);
break;
}
}
@@ -199,8 +171,8 @@ namespace RageCoop.Client
break;
}
case PacketType.PublicKeyResponse:
- {
- if(message.SenderEndPoint.ToString()!=_targetServerEP.ToString() ||!IsConnecting){break;}
+ {
+ if (message.SenderEndPoint.ToString() != _targetServerEP.ToString() || !IsConnecting) { break; }
var packet = data.GetPacket();
Security.SetServerPublicKey(packet.Modulus, packet.Exponent);
_publicKeyReceived.Set();
@@ -323,34 +295,34 @@ namespace RageCoop.Client
private static void PedSync(Packets.PedSync packet)
{
SyncedPed c = EntityPool.GetPedByID(packet.ID);
- if (c==null)
+ if (c == null)
{
// Main.Logger.Debug($"Creating character for incoming sync:{packet.ID}");
- EntityPool.ThreadSafe.Add(c=new SyncedPed(packet.ID));
+ EntityPool.ThreadSafe.Add(c = new SyncedPed(packet.ID));
}
PedDataFlags flags = packet.Flags;
- c.ID=packet.ID;
- c.OwnerID=packet.OwnerID;
+ c.ID = packet.ID;
+ c.OwnerID = packet.OwnerID;
c.Health = packet.Health;
c.Rotation = packet.Rotation;
c.Velocity = packet.Velocity;
c.Speed = packet.Speed;
- c.Flags=packet.Flags;
- c.Heading=packet.Heading;
+ c.Flags = packet.Flags;
+ c.Heading = packet.Heading;
c.Position = packet.Position;
c.LastSyncedStopWatch.Restart();
if (c.IsRagdoll)
{
- c.HeadPosition=packet.HeadPosition;
- c.RightFootPosition=packet.RightFootPosition;
- c.LeftFootPosition=packet.LeftFootPosition;
+ c.HeadPosition = packet.HeadPosition;
+ c.RightFootPosition = packet.RightFootPosition;
+ c.LeftFootPosition = packet.LeftFootPosition;
}
- else if (c.Speed>=4)
+ else if (c.Speed >= 4)
{
- c.VehicleID=packet.VehicleID;
- c.Seat=packet.Seat;
+ c.VehicleID = packet.VehicleID;
+ c.Seat = packet.Seat;
}
- c.LastSynced = Main.Ticked;
+ c.LastSynced = Main.Ticked;
if (c.IsAiming)
{
c.AimCoords = packet.AimCoords;
@@ -358,13 +330,13 @@ namespace RageCoop.Client
if (packet.Flags.HasPedFlag(PedDataFlags.IsFullSync))
{
c.CurrentWeaponHash = packet.CurrentWeaponHash;
- c.Clothes=packet.Clothes;
- c.WeaponComponents=packet.WeaponComponents;
- c.WeaponTint=packet.WeaponTint;
- c.Model=packet.ModelHash;
- c.BlipColor=packet.BlipColor;
- c.BlipSprite=packet.BlipSprite;
- c.BlipScale=packet.BlipScale;
+ c.Clothes = packet.Clothes;
+ c.WeaponComponents = packet.WeaponComponents;
+ c.WeaponTint = packet.WeaponTint;
+ c.Model = packet.ModelHash;
+ c.BlipColor = packet.BlipColor;
+ c.BlipSprite = packet.BlipSprite;
+ c.BlipScale = packet.BlipScale;
c.LastFullSynced = Main.Ticked;
}
@@ -372,58 +344,58 @@ namespace RageCoop.Client
private static void VehicleSync(Packets.VehicleSync packet)
{
SyncedVehicle v = EntityPool.GetVehicleByID(packet.ID);
- if (v==null)
+ if (v == null)
{
- EntityPool.ThreadSafe.Add(v=new SyncedVehicle(packet.ID));
+ EntityPool.ThreadSafe.Add(v = new SyncedVehicle(packet.ID));
}
if (v.IsLocal) { return; }
- v.ID= packet.ID;
- v.OwnerID= packet.OwnerID;
- v.Flags=packet.Flags;
- v.Position=packet.Position;
- v.Quaternion=packet.Quaternion;
- v.SteeringAngle=packet.SteeringAngle;
- v.ThrottlePower=packet.ThrottlePower;
- v.BrakePower=packet.BrakePower;
- v.Velocity=packet.Velocity;
- v.RotationVelocity=packet.RotationVelocity;
- v.DeluxoWingRatio=packet.DeluxoWingRatio;
- v.LastSynced=Main.Ticked;
+ v.ID = packet.ID;
+ v.OwnerID = packet.OwnerID;
+ v.Flags = packet.Flags;
+ v.Position = packet.Position;
+ v.Quaternion = packet.Quaternion;
+ v.SteeringAngle = packet.SteeringAngle;
+ v.ThrottlePower = packet.ThrottlePower;
+ v.BrakePower = packet.BrakePower;
+ v.Velocity = packet.Velocity;
+ v.RotationVelocity = packet.RotationVelocity;
+ v.DeluxoWingRatio = packet.DeluxoWingRatio;
+ v.LastSynced = Main.Ticked;
v.LastSyncedStopWatch.Restart();
if (packet.Flags.HasVehFlag(VehicleDataFlags.IsFullSync))
{
- v.DamageModel=packet.DamageModel;
- v.EngineHealth=packet.EngineHealth;
- v.Mods=packet.Mods;
- v.Model=packet.ModelHash;
- v.Colors=packet.Colors;
- v.LandingGear=packet.LandingGear;
- v.RoofState=(VehicleRoofState)packet.RoofState;
- v.LockStatus=packet.LockStatus;
- v.RadioStation=packet.RadioStation;
- v.LicensePlate=packet.LicensePlate;
- v.Livery=packet.Livery;
- v.LastFullSynced= Main.Ticked;
+ v.DamageModel = packet.DamageModel;
+ v.EngineHealth = packet.EngineHealth;
+ v.Mods = packet.Mods;
+ v.Model = packet.ModelHash;
+ v.Colors = packet.Colors;
+ v.LandingGear = packet.LandingGear;
+ v.RoofState = (VehicleRoofState)packet.RoofState;
+ v.LockStatus = packet.LockStatus;
+ v.RadioStation = packet.RadioStation;
+ v.LicensePlate = packet.LicensePlate;
+ v.Livery = packet.Livery;
+ v.LastFullSynced = Main.Ticked;
}
}
private static void ProjectileSync(Packets.ProjectileSync packet)
{
var p = EntityPool.GetProjectileByID(packet.ID);
- if (p==null)
+ if (p == null)
{
if (packet.Flags.HasProjDataFlag(ProjectileDataFlags.Exploded)) { return; }
// Main.Logger.Debug($"Creating new projectile: {(WeaponHash)packet.WeaponHash}");
- EntityPool.ThreadSafe.Add(p=new SyncedProjectile(packet.ID));
+ EntityPool.ThreadSafe.Add(p = new SyncedProjectile(packet.ID));
}
- p.Flags=packet.Flags;
- p.Position=packet.Position;
- p.Rotation=packet.Rotation;
- p.Velocity=packet.Velocity;
- p.WeaponHash=(WeaponHash)packet.WeaponHash;
- p.Shooter= packet.Flags.HasProjDataFlag(ProjectileDataFlags.IsShotByVehicle) ?
+ p.Flags = packet.Flags;
+ p.Position = packet.Position;
+ p.Rotation = packet.Rotation;
+ p.Velocity = packet.Velocity;
+ p.WeaponHash = (WeaponHash)packet.WeaponHash;
+ p.Shooter = packet.Flags.HasProjDataFlag(ProjectileDataFlags.IsShotByVehicle) ?
(SyncedEntity)EntityPool.GetVehicleByID(packet.ShooterID) : EntityPool.GetPedByID(packet.ShooterID);
- p.LastSynced=Main.Ticked;
+ p.LastSynced = Main.Ticked;
}
}
}
diff --git a/RageCoop.Client/Networking/Send.cs b/RageCoop.Client/Networking/Send.cs
index 386dc61..48f807d 100644
--- a/RageCoop.Client/Networking/Send.cs
+++ b/RageCoop.Client/Networking/Send.cs
@@ -13,7 +13,7 @@ namespace RageCoop.Client
///
/// Reduce GC pressure by reusing frequently used packets
///
- static class SendPackets
+ private static class SendPackets
{
public static Packets.PedSync PedPacket = new Packets.PedSync();
public static Packets.VehicleSync VehicelPacket = new Packets.VehicleSync();
@@ -25,53 +25,53 @@ namespace RageCoop.Client
{
Peer.SendTo(p, Targets, channel, method);
}
-
+
public static void SendPed(SyncedPed sp, bool full)
{
- if (sp.LastSentStopWatch.ElapsedMilliseconds=4)
+ if (p.Speed >= 4)
{
var veh = ped.CurrentVehicle?.GetSyncEntity() ?? ped.VehicleTryingToEnter?.GetSyncEntity() ?? ped.LastVehicle?.GetSyncEntity();
p.VehicleID = veh?.ID ?? 0;
- if (p.VehicleID==0) { Main.Logger.Error("Invalid vehicle"); }
- if (p.Speed==5)
+ if (p.VehicleID == 0) { Main.Logger.Error("Invalid vehicle"); }
+ if (p.Speed == 5)
{
- p.Seat=ped.GetSeatTryingToEnter();
+ p.Seat = ped.GetSeatTryingToEnter();
}
else
{
- p.Seat=ped.SeatIndex;
+ p.Seat = ped.SeatIndex;
}
- if (!veh.IsLocal && p.Speed==4 && p.Seat==VehicleSeat.Driver)
+ if (!veh.IsLocal && p.Speed == 4 && p.Seat == VehicleSeat.Driver)
{
- veh.OwnerID=Main.LocalPlayerID;
- SyncEvents.TriggerChangeOwner(veh.ID,Main.LocalPlayerID);
+ veh.OwnerID = Main.LocalPlayerID;
+ SyncEvents.TriggerChangeOwner(veh.ID, Main.LocalPlayerID);
}
}
p.Position = ped.ReadPosition();
@@ -80,57 +80,57 @@ namespace RageCoop.Client
if (full)
{
var w = ped.VehicleWeapon;
- p.CurrentWeaponHash = (w!=VehicleWeaponHash.Invalid)? (uint)w:(uint)ped.Weapons.Current.Hash;
+ p.CurrentWeaponHash = (w != VehicleWeaponHash.Invalid) ? (uint)w : (uint)ped.Weapons.Current.Hash;
p.Flags |= PedDataFlags.IsFullSync;
- p.Clothes=ped.GetPedClothes();
- p.ModelHash=ped.Model.Hash;
- p.WeaponComponents=ped.Weapons.Current.GetWeaponComponents();
- p.WeaponTint=(byte)Function.Call(Hash.GET_PED_WEAPON_TINT_INDEX, ped, ped.Weapons.Current.Hash);
+ p.Clothes = ped.GetPedClothes();
+ p.ModelHash = ped.Model.Hash;
+ p.WeaponComponents = ped.Weapons.Current.GetWeaponComponents();
+ p.WeaponTint = (byte)Function.Call(Hash.GET_PED_WEAPON_TINT_INDEX, ped, ped.Weapons.Current.Hash);
Blip b;
if (sp.IsPlayer)
{
- p.BlipColor=Scripting.API.Config.BlipColor;
- p.BlipSprite=Scripting.API.Config.BlipSprite;
- p.BlipScale=Scripting.API.Config.BlipScale;
+ p.BlipColor = Scripting.API.Config.BlipColor;
+ p.BlipSprite = Scripting.API.Config.BlipSprite;
+ p.BlipScale = Scripting.API.Config.BlipScale;
}
- else if ((b = ped.AttachedBlip) !=null)
+ else if ((b = ped.AttachedBlip) != null)
{
- p.BlipColor=b.Color;
- p.BlipSprite=b.Sprite;
+ p.BlipColor = b.Color;
+ p.BlipSprite = b.Sprite;
- if (p.BlipSprite==BlipSprite.PoliceOfficer || p.BlipSprite==BlipSprite.PoliceOfficer2)
+ if (p.BlipSprite == BlipSprite.PoliceOfficer || p.BlipSprite == BlipSprite.PoliceOfficer2)
{
- p.BlipScale=0.5f;
+ p.BlipScale = 0.5f;
}
}
else
{
- p.BlipColor=(BlipColor)255;
+ p.BlipColor = (BlipColor)255;
}
}
SendSync(p, ConnectionChannel.PedSync);
}
public static void SendVehicle(SyncedVehicle v, bool full)
{
- if (v.LastSentStopWatch.ElapsedMilliseconds(Hash.GET_VEHICLE_NUMBER_PLATE_TEXT, veh);
- packet.Livery=Function.Call(Hash.GET_VEHICLE_LIVERY, veh);
- if (v.MainVehicle==Game.Player.LastVehicle)
+ packet.ModelHash = veh.Model.Hash;
+ packet.EngineHealth = veh.EngineHealth;
+ packet.LockStatus = veh.LockStatus;
+ packet.LicensePlate = Function.Call(Hash.GET_VEHICLE_NUMBER_PLATE_TEXT, veh);
+ packet.Livery = Function.Call(Hash.GET_VEHICLE_LIVERY, veh);
+ if (v.MainVehicle == Game.Player.LastVehicle)
{
- packet.RadioStation=Util.GetPlayerRadioIndex();
+ packet.RadioStation = Util.GetPlayerRadioIndex();
}
- if (packet.EngineHealth>v.LastEngineHealth)
+ if (packet.EngineHealth > v.LastEngineHealth)
{
packet.Flags |= VehicleDataFlags.Repaired;
}
- v.LastEngineHealth=packet.EngineHealth;
+ v.LastEngineHealth = packet.EngineHealth;
}
SendSync(packet, ConnectionChannel.VehicleSync);
}
@@ -178,25 +178,25 @@ namespace RageCoop.Client
StartPosition = start,
EndPosition = end,
OwnerID = ownerID,
- WeaponHash=weapon,
+ WeaponHash = weapon,
}, ConnectionChannel.SyncEvents);
}
- public static void SendVehicleBullet(uint hash,SyncedPed owner,EntityBone b)
+ public static void SendVehicleBullet(uint hash, SyncedPed owner, EntityBone b)
{
SendSync(new Packets.VehicleBulletShot
{
StartPosition = b.Position,
- EndPosition = b.Position+b.ForwardVector,
- OwnerID=owner.ID,
- Bone=(ushort)b.Index,
- WeaponHash=hash
+ EndPosition = b.Position + b.ForwardVector,
+ OwnerID = owner.ID,
+ Bone = (ushort)b.Index,
+ WeaponHash = hash
});
}
#endregion
public static void SendChatMessage(string message)
{
Peer.SendTo(new Packets.ChatMessage(new Func((s) => Security.Encrypt(s.GetBytes())))
- { Username = Main.Settings.Username, Message = message },ServerConnection, ConnectionChannel.Chat, NetDeliveryMethod.ReliableOrdered);
+ { Username = Main.Settings.Username, Message = message }, ServerConnection, ConnectionChannel.Chat, NetDeliveryMethod.ReliableOrdered);
Peer.FlushSendQueue();
}
public static void SendVoiceMessage(byte[] buffer, int recorded)
diff --git a/RageCoop.Client/Networking/Statistics.cs b/RageCoop.Client/Networking/Statistics.cs
index 228ea20..c864fe8 100644
--- a/RageCoop.Client/Networking/Statistics.cs
+++ b/RageCoop.Client/Networking/Statistics.cs
@@ -16,8 +16,8 @@ namespace RageCoop.Client
var bu = Networking.Peer.Statistics.SentBytes;
var bd = Networking.Peer.Statistics.ReceivedBytes;
Thread.Sleep(1000);
- BytesUpPerSecond=Networking.Peer.Statistics.SentBytes-bu;
- BytesDownPerSecond=Networking.Peer.Statistics.ReceivedBytes-bd;
+ BytesUpPerSecond = Networking.Peer.Statistics.SentBytes - bu;
+ BytesDownPerSecond = Networking.Peer.Statistics.ReceivedBytes - bd;
}
});
}
diff --git a/RageCoop.Client/PlayerList.cs b/RageCoop.Client/PlayerList.cs
index 9ffcacc..d8d2964 100644
--- a/RageCoop.Client/PlayerList.cs
+++ b/RageCoop.Client/PlayerList.cs
@@ -1,11 +1,11 @@
using GTA;
using GTA.Math;
using GTA.Native;
+using Lidgren.Network;
using RageCoop.Core;
using System.Collections.Generic;
-using Lidgren.Network;
-using System.Net;
using System.Linq;
+using System.Net;
namespace RageCoop.Client
{
@@ -49,12 +49,12 @@ namespace RageCoop.Client
_lastUpdate = Util.GetTickCount64();
_mainScaleform.CallFunction("SET_DATA_SLOT_EMPTY", 0);
-
- int i=0;
+
+ int i = 0;
foreach (var player in Players.Values)
{
- _mainScaleform.CallFunction("SET_DATA_SLOT", i++, $"{player.Ping * 1000:N0}ms", player.Username+(player.IsHost ? " (Host)" : ""), 116, 0, i - 1, "", "", 2, "", "", ' ');
+ _mainScaleform.CallFunction("SET_DATA_SLOT", i++, $"{player.Ping * 1000:N0}ms", player.Username + (player.IsHost ? " (Host)" : ""), 116, 0, i - 1, "", "", 2, "", "", ' ');
}
_mainScaleform.CallFunction("SET_TITLE", "Player list", $"{Players.Count} players");
@@ -66,29 +66,29 @@ namespace RageCoop.Client
Player p;
if (Players.TryGetValue(id, out p))
{
- p.Username=username;
- p.ID=id;
- p._latencyToServer=latency;
+ p.Username = username;
+ p.ID = id;
+ p._latencyToServer = latency;
}
else
{
- p = new Player { ID=id, Username=username, _latencyToServer=latency };
+ p = new Player { ID = id, Username = username, _latencyToServer = latency };
Players.Add(id, p);
}
}
public static void UpdatePlayer(Packets.PlayerInfoUpdate packet)
{
var p = GetPlayer(packet.PedID);
- if (p!=null)
+ if (p != null)
{
p._latencyToServer = packet.Latency;
p.Position = packet.Position;
- p.IsHost= packet.IsHost;
+ p.IsHost = packet.IsHost;
Main.QueueAction(() =>
{
- if (p.FakeBlip?.Exists()!=true)
+ if (p.FakeBlip?.Exists() != true)
{
- p.FakeBlip=World.CreateBlip(p.Position);
+ p.FakeBlip = World.CreateBlip(p.Position);
}
if (EntityPool.PedExists(p.ID))
{
@@ -101,9 +101,9 @@ namespace RageCoop.Client
p.FakeBlip.Sprite = Scripting.API.Config.BlipSprite;
p.FakeBlip.DisplayType = BlipDisplayType.Default;
p.FakeBlip.Position = p.Position;
- }
+ }
});
-
+
}
}
public static Player GetPlayer(int id)
@@ -115,15 +115,15 @@ namespace RageCoop.Client
public static Player GetPlayer(SyncedPed p)
{
var player = GetPlayer(p.ID);
- if (player!=null)
+ if (player != null)
{
- player.Character=p;
+ player.Character = p;
}
return player;
}
public static void RemovePlayer(int id)
{
- if (Players.TryGetValue(id,out var player))
+ if (Players.TryGetValue(id, out var player))
{
Players.Remove(id);
Main.QueueAction(() => player.FakeBlip?.Delete());
@@ -131,11 +131,11 @@ namespace RageCoop.Client
}
public static void Cleanup()
{
- foreach(var p in Players.Values.ToArray())
+ foreach (var p in Players.Values.ToArray())
{
p.FakeBlip?.Delete();
}
- Players=new Dictionary { };
+ Players = new Dictionary { };
}
}
@@ -160,8 +160,8 @@ namespace RageCoop.Client
///
/// Player round-trip time in seconds, will be the rtt to server if not using P2P connection.
///
- public float Ping => Main.LocalPlayerID==ID ? Networking.Latency*2 : (HasDirectConnection ? Connection.AverageRoundtripTime : _latencyToServer*2);
- public float PacketTravelTime => HasDirectConnection ? Connection.AverageRoundtripTime/2 : Networking.Latency+_latencyToServer;
+ public float Ping => Main.LocalPlayerID == ID ? Networking.Latency * 2 : (HasDirectConnection ? Connection.AverageRoundtripTime : _latencyToServer * 2);
+ public float PacketTravelTime => HasDirectConnection ? Connection.AverageRoundtripTime / 2 : Networking.Latency + _latencyToServer;
internal float _latencyToServer = 0;
public bool DisplayNameTag { get; set; } = true;
public NetConnection Connection { get; internal set; }
diff --git a/RageCoop.Client/Properties/AssemblyInfo.cs b/RageCoop.Client/Properties/AssemblyInfo.cs
index 8600f12..3bb1ca1 100644
--- a/RageCoop.Client/Properties/AssemblyInfo.cs
+++ b/RageCoop.Client/Properties/AssemblyInfo.cs
@@ -1,7 +1,5 @@
using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
using System.Resources;
// General Information
@@ -16,7 +14,7 @@ using System.Resources;
// Version informationr(
-[assembly: AssemblyVersion("1.5.3.149")]
-[assembly: AssemblyFileVersion("1.5.3.149")]
-[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
+[assembly: AssemblyVersion("1.5.3.155")]
+[assembly: AssemblyFileVersion("1.5.3.155")]
+[assembly: NeutralResourcesLanguageAttribute("en-US")]
diff --git a/RageCoop.Client/Scripting/API.cs b/RageCoop.Client/Scripting/API.cs
index 82777f8..d64dfa5 100644
--- a/RageCoop.Client/Scripting/API.cs
+++ b/RageCoop.Client/Scripting/API.cs
@@ -1,10 +1,10 @@
#undef DEBUG
using GTA;
+using Newtonsoft.Json;
using RageCoop.Core;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
-using Newtonsoft.Json;
namespace RageCoop.Client.Scripting
{
@@ -40,7 +40,7 @@ namespace RageCoop.Client.Scripting
///
public static string Username
{
- get { return Main.Settings.Username; }
+ get => Main.Settings.Username;
set
{
if (Networking.IsOnServer || string.IsNullOrEmpty(value))
@@ -142,7 +142,7 @@ namespace RageCoop.Client.Scripting
internal static void InvokeCustomEventReceived(Packets.CustomEvent p)
{
- var args = new CustomEventReceivedArgs() { Hash=p.Hash, Args=p.Args };
+ var args = new CustomEventReceivedArgs() { Hash = p.Hash, Args = p.Args };
// Main.Logger.Debug($"CustomEvent:\n"+args.Args.DumpWithType());
@@ -161,53 +161,37 @@ namespace RageCoop.Client.Scripting
/// Get the local player's ID
///
/// PlayerID
- public static int LocalPlayerID
- {
- get { return Main.LocalPlayerID; }
- }
+ public static int LocalPlayerID => Main.LocalPlayerID;
///
/// Check if player is connected to a server
///
- public static bool IsOnServer { get { return Networking.IsOnServer; } }
+ public static bool IsOnServer => Networking.IsOnServer;
///
/// Get an that the player is currently connected to, or null if not connected to the server
///
- public static System.Net.IPEndPoint ServerEndPoint { get { return Networking.IsOnServer ? Networking.ServerConnection?.RemoteEndPoint : null; } }
+ public static System.Net.IPEndPoint ServerEndPoint => Networking.IsOnServer ? Networking.ServerConnection?.RemoteEndPoint : null;
///
/// Check if a RAGECOOP menu is visible
///
- public static bool IsMenuVisible
- {
- get { return Menus.CoopMenu.MenuPool.AreAnyVisible; }
- }
+ public static bool IsMenuVisible => Menus.CoopMenu.MenuPool.AreAnyVisible;
///
/// Check if the RAGECOOP chat is visible
///
- public static bool IsChatFocused
- {
- get { return Main.MainChat.Focused; }
- }
+ public static bool IsChatFocused => Main.MainChat.Focused;
///
/// Check if the RAGECOOP list of players is visible
///
- public static bool IsPlayerListVisible
- {
- get { return Util.GetTickCount64() - PlayerList.Pressed < 5000; }
- }
+ public static bool IsPlayerListVisible => Util.GetTickCount64() - PlayerList.Pressed < 5000;
///
/// Get the version of RAGECOOP
///
- public static Version CurrentVersion
- {
- get { return Main.Version; }
- }
-
+ public static Version CurrentVersion => Main.Version;
///
/// Get a that RAGECOOP is currently using.
@@ -217,7 +201,7 @@ namespace RageCoop.Client.Scripting
///
/// Get all players indexed by their ID
///
- public static Dictionary Players => new Dictionary(PlayerList.Players);
+ public static Dictionary Players => new Dictionary(PlayerList.Players);
#endregion
@@ -254,7 +238,7 @@ namespace RageCoop.Client.Scripting
{
return JsonConvert.DeserializeObject>(HttpHelper.DownloadString(Main.Settings.MasterServer));
}
-
+
///
/// Send a local chat message to this player
///
@@ -299,12 +283,12 @@ namespace RageCoop.Client.Scripting
/// The objects conataing your data, see for a list of supported types
public static void SendCustomEvent(int eventHash, params object[] args)
{
-
+
Networking.Peer.SendTo(new Packets.CustomEvent()
{
- Args=args,
- Hash=eventHash
- },Networking.ServerConnection, ConnectionChannel.Event, Lidgren.Network.NetDeliveryMethod.ReliableOrdered);
+ Args = args,
+ Hash = eventHash
+ }, Networking.ServerConnection, ConnectionChannel.Event, Lidgren.Network.NetDeliveryMethod.ReliableOrdered);
}
///
@@ -337,17 +321,17 @@ namespace RageCoop.Client.Scripting
callback(e);
}
};
- DownloadManager.DownloadCompleted+=handler;
+ DownloadManager.DownloadCompleted += handler;
Networking.GetResponse(new Packets.FileTransferRequest()
{
- Name=name,
+ Name = name,
},
(p) =>
{
if (p.Response != FileResponse.Loaded)
{
- DownloadManager.DownloadCompleted-=handler;
- throw new ArgumentException("Requested file was not found on the server: "+name);
+ DownloadManager.DownloadCompleted -= handler;
+ throw new ArgumentException("Requested file was not found on the server: " + name);
}
});
}
diff --git a/RageCoop.Client/Scripting/BaseScript.cs b/RageCoop.Client/Scripting/BaseScript.cs
index 8fd8888..5b3b2ce 100644
--- a/RageCoop.Client/Scripting/BaseScript.cs
+++ b/RageCoop.Client/Scripting/BaseScript.cs
@@ -14,9 +14,9 @@ namespace RageCoop.Client.Scripting
private bool _isHost = false;
public override void OnStart()
{
- API.Events.OnPedDeleted+=(s, p) => { API.SendCustomEvent(CustomEvents.OnPedDeleted, p.ID); };
- API.Events.OnVehicleDeleted+=(s, p) => { API.SendCustomEvent(CustomEvents.OnVehicleDeleted, p.ID); };
- API.Events.OnPlayerDied+=() => { API.SendCustomEvent(CustomEvents.OnPlayerDied); };
+ API.Events.OnPedDeleted += (s, p) => { API.SendCustomEvent(CustomEvents.OnPedDeleted, p.ID); };
+ API.Events.OnVehicleDeleted += (s, p) => { API.SendCustomEvent(CustomEvents.OnVehicleDeleted, p.ID); };
+ API.Events.OnPlayerDied += () => { API.SendCustomEvent(CustomEvents.OnPlayerDied); };
API.RegisterCustomEventHandler(CustomEvents.SetAutoRespawn, SetAutoRespawn);
API.RegisterCustomEventHandler(CustomEvents.SetDisplayNameTag, SetDisplayNameTag);
@@ -29,7 +29,7 @@ namespace RageCoop.Client.Scripting
API.RegisterCustomEventHandler(CustomEvents.DeleteServerBlip, DeleteServerBlip);
API.RegisterCustomEventHandler(CustomEvents.CreateVehicle, CreateVehicle);
API.RegisterCustomEventHandler(CustomEvents.UpdatePedBlip, UpdatePedBlip);
- API.RegisterCustomEventHandler(CustomEvents.IsHost, (e) => { _isHost=(bool)e.Args[0]; });
+ API.RegisterCustomEventHandler(CustomEvents.IsHost, (e) => { _isHost = (bool)e.Args[0]; });
API.RegisterCustomEventHandler(CustomEvents.WeatherTimeSync, WeatherTimeSync);
API.RegisterCustomEventHandler(CustomEvents.OnPlayerDied, (e) => { GTA.UI.Notification.Show($"~h~{e.Args[0]}~h~ died."); });
Task.Run(() =>
@@ -59,33 +59,33 @@ namespace RageCoop.Client.Scripting
private void WeatherTimeSync(CustomEventReceivedArgs e)
{
- World.CurrentTimeOfDay=new TimeSpan((int)e.Args[0], (int)e.Args[1], (int)e.Args[2]);
+ World.CurrentTimeOfDay = new TimeSpan((int)e.Args[0], (int)e.Args[1], (int)e.Args[2]);
Function.Call(Hash._SET_WEATHER_TYPE_TRANSITION, (int)e.Args[3], (int)e.Args[4], (float)e.Args[5]);
}
private void SetDisplayNameTag(CustomEventReceivedArgs e)
{
var p = PlayerList.GetPlayer((int)e.Args[0]);
- if (p != null) { p.DisplayNameTag=(bool)e.Args[1]; }
+ if (p != null) { p.DisplayNameTag = (bool)e.Args[1]; }
}
private void UpdatePedBlip(CustomEventReceivedArgs e)
{
var p = Entity.FromHandle((int)e.Args[0]);
if (p == null) { return; }
- if (p.Handle==Game.Player.Character.Handle)
+ if (p.Handle == Game.Player.Character.Handle)
{
- API.Config.BlipColor=(BlipColor)(byte)e.Args[1];
- API.Config.BlipSprite=(BlipSprite)(ushort)e.Args[2];
- API.Config.BlipScale=(float)e.Args[3];
+ API.Config.BlipColor = (BlipColor)(byte)e.Args[1];
+ API.Config.BlipSprite = (BlipSprite)(ushort)e.Args[2];
+ API.Config.BlipScale = (float)e.Args[3];
}
else
{
var b = p.AttachedBlip;
- if (b == null) { b=p.AddBlip(); }
- b.Color=(BlipColor)(byte)e.Args[1];
- b.Sprite=(BlipSprite)(ushort)e.Args[2];
- b.Scale=(float)e.Args[3];
+ if (b == null) { b = p.AddBlip(); }
+ b.Color = (BlipColor)(byte)e.Args[1];
+ b.Sprite = (BlipSprite)(ushort)e.Args[2];
+ b.Scale = (float)e.Args[3];
}
}
@@ -94,17 +94,17 @@ namespace RageCoop.Client.Scripting
var vehicleModel = (Model)e.Args[1];
vehicleModel.Request(1000);
Vehicle veh = World.CreateVehicle(vehicleModel, (Vector3)e.Args[2], (float)e.Args[3]);
- while (veh==null)
+ while (veh == null)
{
- veh = World.CreateVehicle(vehicleModel, (Vector3)e.Args[2], (float)e.Args[3]);
+ veh = World.CreateVehicle(vehicleModel, (Vector3)e.Args[2], (float)e.Args[3]);
Thread.Sleep(10);
}
- veh.CanPretendOccupants=false;
+ veh.CanPretendOccupants = false;
var v = new SyncedVehicle()
{
- ID=(int)e.Args[0],
- MainVehicle=veh,
- OwnerID=Main.LocalPlayerID,
+ ID = (int)e.Args[0],
+ MainVehicle = veh,
+ OwnerID = Main.LocalPlayerID,
};
EntityPool.Add(v);
}
@@ -130,7 +130,7 @@ namespace RageCoop.Client.Scripting
Blip blip;
if (!EntityPool.ServerBlips.TryGetValue(id, out blip))
{
- EntityPool.ServerBlips.Add(id, blip=World.CreateBlip(pos));
+ EntityPool.ServerBlips.Add(id, blip = World.CreateBlip(pos));
}
blip.Sprite = sprite;
blip.Color = color;
@@ -152,14 +152,14 @@ namespace RageCoop.Client.Scripting
private void SetNameTag(CustomEventReceivedArgs e)
{
var p = PlayerList.GetPlayer((int)e.Args[0]);
- if (p!= null)
+ if (p != null)
{
- p.DisplayNameTag=(bool)e.Args[1];
+ p.DisplayNameTag = (bool)e.Args[1];
}
}
private void SetAutoRespawn(CustomEventReceivedArgs args)
{
- API.Config.EnableAutoRespawn=(bool)args.Args[0];
+ API.Config.EnableAutoRespawn = (bool)args.Args[0];
}
private void DeleteServerProp(CustomEventReceivedArgs e)
{
@@ -179,13 +179,13 @@ namespace RageCoop.Client.Scripting
{
if (!EntityPool.ServerProps.TryGetValue(id, out prop))
{
- EntityPool.ServerProps.Add(id, prop=new SyncedProp(id));
+ EntityPool.ServerProps.Add(id, prop = new SyncedProp(id));
}
}
- prop.LastSynced=Main.Ticked+1;
- prop.Model= (Model)e.Args[1];
- prop.Position=(Vector3)e.Args[2];
- prop.Rotation=(Vector3)e.Args[3];
+ prop.LastSynced = Main.Ticked + 1;
+ prop.Model = (Model)e.Args[1];
+ prop.Position = (Vector3)e.Args[2];
+ prop.Rotation = (Vector3)e.Args[3];
prop.Update();
}
private void NativeCall(CustomEventReceivedArgs e)
@@ -194,14 +194,14 @@ namespace RageCoop.Client.Scripting
int i;
var ty = (byte)e.Args[0];
TypeCode returnType = (TypeCode)ty;
- i = returnType==TypeCode.Empty ? 1 : 2;
+ i = returnType == TypeCode.Empty ? 1 : 2;
var hash = (Hash)e.Args[i++];
- for (; i
/// Eqivalent of in
///
- public Core.Logger Logger { get { return CurrentResource.Logger; } }
+ public Core.Logger Logger => CurrentResource.Logger;
}
}
diff --git a/RageCoop.Client/Scripting/Resources.cs b/RageCoop.Client/Scripting/Resources.cs
index 4ba3b7d..d41185e 100644
--- a/RageCoop.Client/Scripting/Resources.cs
+++ b/RageCoop.Client/Scripting/Resources.cs
@@ -38,9 +38,11 @@ namespace RageCoop.Client.Scripting
}
internal class Resources
{
+ private readonly List LoadedResources = new List();
+ private const string BaseScriptType = "RageCoop.Client.Scripting.ClientScript";
+ private Logger Logger { get; set; }
public Resources()
{
- BaseScriptType = "RageCoop.Client.Scripting.ClientScript";
Logger = Main.Logger;
}
private void StartAll()
@@ -53,12 +55,12 @@ namespace RageCoop.Client.Scripting
{
try
{
- s.CurrentResource=d;
+ s.CurrentResource = d;
s.OnStart();
}
catch (Exception ex)
{
- Logger.Error("Error occurred when starting script:"+s.GetType().FullName);
+ Logger.Error("Error occurred when starting script:" + s.GetType().FullName);
Logger?.Error(ex);
}
}
@@ -79,7 +81,7 @@ namespace RageCoop.Client.Scripting
}
catch (Exception ex)
{
- Logger.Error("Error occurred when stopping script:"+s.GetType().FullName);
+ Logger.Error("Error occurred when stopping script:" + s.GetType().FullName);
Logger?.Error(ex);
}
}
@@ -106,9 +108,6 @@ namespace RageCoop.Client.Scripting
}
LoadedResources.Clear();
}
- private List LoadedResources = new List();
- private string BaseScriptType;
- public Logger Logger { get; set; }
private void LoadResource(ZipFile file, string dataFolderRoot)
{
@@ -117,22 +116,22 @@ namespace RageCoop.Client.Scripting
{
Logger = Main.Logger,
Scripts = new List(),
- Name=Path.GetFileNameWithoutExtension(file.Name),
- DataFolder=Path.Combine(dataFolderRoot, Path.GetFileNameWithoutExtension(file.Name))
+ Name = Path.GetFileNameWithoutExtension(file.Name),
+ DataFolder = Path.Combine(dataFolderRoot, Path.GetFileNameWithoutExtension(file.Name))
};
Directory.CreateDirectory(r.DataFolder);
foreach (ZipEntry entry in file)
{
ResourceFile rFile;
- r.Files.Add(entry.Name, rFile=new ResourceFile()
+ r.Files.Add(entry.Name, rFile = new ResourceFile()
{
- Name=entry.Name,
- IsDirectory=entry.IsDirectory,
+ Name = entry.Name,
+ IsDirectory = entry.IsDirectory,
});
if (!entry.IsDirectory)
{
- rFile.GetStream=() => { return file.GetInputStream(entry); };
+ rFile.GetStream = () => { return file.GetInputStream(entry); };
if (entry.Name.EndsWith(".dll") && !entry.Name.Contains("/"))
{
// Don't load API assembly
@@ -145,12 +144,12 @@ namespace RageCoop.Client.Scripting
{
continue;
}
- var asm=Assembly.LoadFrom(tmp);
- toLoad.Add(() => LoadScriptsFromAssembly(rFile,asm, entry.Name,r));
+ var asm = Assembly.LoadFrom(tmp);
+ toLoad.Add(() => LoadScriptsFromAssembly(rFile, asm, entry.Name, r));
}
}
}
- foreach(var a in toLoad)
+ foreach (var a in toLoad)
{
a();
}
@@ -174,8 +173,8 @@ namespace RageCoop.Client.Scripting
// Invoke script constructor
var script = constructor.Invoke(null) as ClientScript;
// script.CurrentResource = toload;
- script.CurrentFile=rfile;
- script.CurrentResource=toload;
+ script.CurrentFile = rfile;
+ script.CurrentResource = toload;
toload.Scripts.Add(script);
count++;
}
diff --git a/RageCoop.Client/Security.cs b/RageCoop.Client/Security.cs
index e14a0ce..67a23e3 100644
--- a/RageCoop.Client/Security.cs
+++ b/RageCoop.Client/Security.cs
@@ -7,7 +7,7 @@ namespace RageCoop.Client
{
public RSA ServerRSA { get; set; }
public Aes ClientAes { get; set; } = Aes.Create();
- private Logger Logger;
+ private readonly Logger Logger;
public Security(Logger logger)
{
Logger = logger;
@@ -17,8 +17,8 @@ namespace RageCoop.Client
public void GetSymmetricKeysCrypted(out byte[] cryptedKey, out byte[] cryptedIV)
{
// Logger?.Debug($"Aes.Key:{ClientAes.Key.Dump()}, Aes.IV:{ClientAes.IV.Dump()}");
- cryptedKey =ServerRSA.Encrypt(ClientAes.Key, RSAEncryptionPadding.Pkcs1);
- cryptedIV =ServerRSA.Encrypt(ClientAes.IV, RSAEncryptionPadding.Pkcs1);
+ cryptedKey = ServerRSA.Encrypt(ClientAes.Key, RSAEncryptionPadding.Pkcs1);
+ cryptedIV = ServerRSA.Encrypt(ClientAes.IV, RSAEncryptionPadding.Pkcs1);
}
public byte[] Encrypt(byte[] data)
{
@@ -33,11 +33,11 @@ namespace RageCoop.Client
var para = new RSAParameters();
para.Modulus = modulus;
para.Exponent = exponent;
- ServerRSA=RSA.Create(para);
+ ServerRSA = RSA.Create(para);
}
public void Regen()
{
- ClientAes=Aes.Create();
+ ClientAes = Aes.Create();
ClientAes.GenerateKey();
ClientAes.GenerateIV();
}
diff --git a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Animations.cs b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Animations.cs
index 1f8da33..4ba8442 100644
--- a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Animations.cs
+++ b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Animations.cs
@@ -116,10 +116,10 @@ namespace RageCoop.Client
case unchecked((uint)-1357824103):
case unchecked((uint)-1074790547):
- case unchecked((uint)2132975508):
+ case unchecked(2132975508):
case unchecked((uint)-2084633992):
case unchecked((uint)-952879014):
- case unchecked((uint)100416529):
+ case unchecked(100416529):
case unchecked((uint)WeaponHash.Gusenberg):
case unchecked((uint)WeaponHash.MG):
case unchecked((uint)WeaponHash.CombatMG):
diff --git a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Members.cs b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Members.cs
index 9a17564..c80a419 100644
--- a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Members.cs
+++ b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.Members.cs
@@ -1,12 +1,7 @@
using GTA;
using GTA.Math;
-using GTA.Native;
-using LemonUI.Elements;
using RageCoop.Core;
-using System;
using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
namespace RageCoop.Client
{
@@ -26,7 +21,7 @@ namespace RageCoop.Client
{
if (CurrentVehicle == null || value != CurrentVehicle?.ID)
{
- CurrentVehicle=EntityPool.GetVehicleByID(value);
+ CurrentVehicle = EntityPool.GetVehicleByID(value);
}
}
}
diff --git a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs
index 40b724d..9660aaa 100644
--- a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs
+++ b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs
@@ -22,11 +22,11 @@ namespace RageCoop.Client
///
internal SyncedPed(Ped p)
{
- ID=EntityPool.RequestNewID();
- p.CanWrithe=false;
- p.IsOnlyDamagedByPlayer=false;
- MainPed=p;
- OwnerID=Main.LocalPlayerID;
+ ID = EntityPool.RequestNewID();
+ p.CanWrithe = false;
+ p.IsOnlyDamagedByPlayer = false;
+ MainPed = p;
+ OwnerID = Main.LocalPlayerID;
Function.Call(Hash._SET_PED_CAN_PLAY_INJURED_ANIMS, false);
MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableHurt, true);
@@ -39,13 +39,13 @@ namespace RageCoop.Client
///
internal SyncedPed(int id)
{
- ID=id;
- LastSynced=Main.Ticked;
+ ID = id;
+ LastSynced = Main.Ticked;
}
internal override void Update()
{
- if (Owner==null) { OwnerID=OwnerID;return; }
+ if (Owner == null) { OwnerID = OwnerID; return; }
if (IsPlayer)
{
RenderNameTag();
@@ -66,9 +66,9 @@ namespace RageCoop.Client
}
// Need to update state
- if (LastFullSynced>=LastUpdated)
+ if (LastFullSynced >= LastUpdated)
{
- if (MainPed!=null&& (Model != MainPed.Model.Hash))
+ if (MainPed != null && (Model != MainPed.Model.Hash))
{
if (!CreateCharacter())
{
@@ -76,29 +76,29 @@ namespace RageCoop.Client
}
}
- if (((byte)BlipColor==255) && (PedBlip!=null))
+ if (((byte)BlipColor == 255) && (PedBlip != null))
{
PedBlip.Delete();
- PedBlip=null;
+ PedBlip = null;
}
- else if (((byte)BlipColor != 255) && PedBlip==null)
+ else if (((byte)BlipColor != 255) && PedBlip == null)
{
- PedBlip=MainPed.AddBlip();
+ PedBlip = MainPed.AddBlip();
-
- PedBlip.Color=BlipColor;
- PedBlip.Sprite=BlipSprite;
- PedBlip.Scale=BlipScale;
+
+ PedBlip.Color = BlipColor;
+ PedBlip.Sprite = BlipSprite;
+ PedBlip.Scale = BlipScale;
}
- if (PedBlip!=null)
+ if (PedBlip != null)
{
- if (PedBlip.Color!=BlipColor)
+ if (PedBlip.Color != BlipColor)
{
- PedBlip.Color=BlipColor;
+ PedBlip.Color = BlipColor;
}
- if (PedBlip.Sprite!=BlipSprite)
+ if (PedBlip.Sprite != BlipSprite)
{
- PedBlip.Sprite=BlipSprite;
+ PedBlip.Sprite = BlipSprite;
}
if (IsPlayer)
{
@@ -116,7 +116,7 @@ namespace RageCoop.Client
if (MainPed.IsDead)
{
- if (Health>0)
+ if (Health > 0)
{
if (IsPlayer)
{
@@ -128,7 +128,7 @@ namespace RageCoop.Client
}
}
}
- else if (IsPlayer&&(MainPed.Health != Health))
+ else if (IsPlayer && (MainPed.Health != Health))
{
MainPed.Health = Health;
@@ -140,13 +140,13 @@ namespace RageCoop.Client
}
}
- if (Speed>=4)
+ if (Speed >= 4)
{
DisplayInVehicle();
}
else
{
- if (MainPed.IsInVehicle()) { MainPed.Task.LeaveVehicle(LeaveVehicleFlags.WarpOut);return; }
+ if (MainPed.IsInVehicle()) { MainPed.Task.LeaveVehicle(LeaveVehicleFlags.WarpOut); return; }
DisplayOnFoot();
}
@@ -165,12 +165,12 @@ namespace RageCoop.Client
}
}
- LastUpdated=Main.Ticked;
+ LastUpdated = Main.Ticked;
}
private void RenderNameTag()
{
- if (!Owner.DisplayNameTag || (MainPed==null) || !MainPed.IsVisible || !MainPed.IsInRange(Main.PlayerPosition, 40f))
+ if (!Owner.DisplayNameTag || (MainPed == null) || !MainPed.IsVisible || !MainPed.IsInRange(Main.PlayerPosition, 40f))
{
return;
}
@@ -179,12 +179,12 @@ namespace RageCoop.Client
Point toDraw = default;
if (Util.WorldToScreen(targetPos, ref toDraw))
{
- toDraw.Y-=100;
+ toDraw.Y -= 100;
new ScaledText(toDraw, Owner.Username, 0.4f, GTA.UI.Font.ChaletLondon)
{
Outline = true,
Alignment = GTA.UI.Alignment.Center,
- Color=Owner.HasDirectConnection? Color.FromArgb(179, 229, 252) : Color.White,
+ Color = Owner.HasDirectConnection ? Color.FromArgb(179, 229, 252) : Color.White,
}.Draw();
}
}
@@ -223,12 +223,12 @@ namespace RageCoop.Client
Model.MarkAsNoLongerNeeded();
MainPed.BlockPermanentEvents = true;
- MainPed.CanWrithe=false;
+ MainPed.CanWrithe = false;
MainPed.CanBeDraggedOutOfVehicle = true;
MainPed.IsOnlyDamagedByPlayer = false;
- MainPed.RelationshipGroup=Main.SyncedPedsGroup;
- MainPed.IsFireProof=false;
- MainPed.IsExplosionProof=false;
+ MainPed.RelationshipGroup = Main.SyncedPedsGroup;
+ MainPed.IsFireProof = false;
+ MainPed.IsExplosionProof = false;
Function.Call(Hash.SET_PED_DROPS_WEAPONS_WHEN_DEAD, MainPed.Handle, false);
Function.Call(Hash.SET_PED_CAN_BE_TARGETTED, MainPed.Handle, true);
@@ -251,8 +251,8 @@ namespace RageCoop.Client
SetClothes();
- if (IsPlayer) { MainPed.IsInvincible=true; }
- if (IsInvincible) { MainPed.IsInvincible=true; }
+ if (IsPlayer) { MainPed.IsInvincible = true; }
+ if (IsInvincible) { MainPed.IsInvincible = true; }
lock (EntityPool.PedsLock)
{
@@ -267,7 +267,7 @@ namespace RageCoop.Client
{
for (byte i = 0; i < 12; i++)
{
- Function.Call(Hash.SET_PED_COMPONENT_VARIATION, MainPed.Handle, i, (int)Clothes[i], (int)Clothes[i+12], (int)Clothes[i+24]);
+ Function.Call(Hash.SET_PED_COMPONENT_VARIATION, MainPed.Handle, i, (int)Clothes[i], (int)Clothes[i + 12], (int)Clothes[i + 24]);
}
_lastClothes = Clothes;
}
@@ -419,7 +419,7 @@ namespace RageCoop.Client
}
_lastIsJumping = false;
- if (IsRagdoll || Health==0)
+ if (IsRagdoll || Health == 0)
{
if (!MainPed.IsRagdoll)
{
@@ -429,7 +429,7 @@ namespace RageCoop.Client
if (!_lastRagdoll)
{
_lastRagdoll = true;
- _lastRagdollTime=Main.Ticked;
+ _lastRagdollTime = Main.Ticked;
}
return;
}
@@ -474,11 +474,11 @@ namespace RageCoop.Client
Function.Call(Hash.TASK_STAY_IN_COVER, MainPed.Handle);
}
- _lastInCover=true;
+ _lastInCover = true;
if (IsAiming)
{
DisplayAiming();
- _lastInCover=false;
+ _lastInCover = false;
}
else if (MainPed.IsInCover)
{
@@ -488,7 +488,7 @@ namespace RageCoop.Client
else if (_lastInCover)
{
MainPed.Task.ClearAllImmediately();
- _lastInCover=false;
+ _lastInCover = false;
}
else if (IsAiming)
{
@@ -506,11 +506,11 @@ namespace RageCoop.Client
private void CheckCurrentWeapon()
{
- if (MainPed.Weapons.Current.Hash != (WeaponHash)CurrentWeaponHash || !WeaponComponents.Compare(_lastWeaponComponents) || (Speed <=3 && _weaponObj?.IsVisible != true))
+ if (MainPed.Weapons.Current.Hash != (WeaponHash)CurrentWeaponHash || !WeaponComponents.Compare(_lastWeaponComponents) || (Speed <= 3 && _weaponObj?.IsVisible != true))
{
new WeaponAsset(CurrentWeaponHash).Request();
-
- MainPed.Weapons.RemoveAll();
+
+ MainPed.Weapons.RemoveAll();
_weaponObj = Entity.FromHandle(Function.Call(Hash.CREATE_WEAPON_OBJECT, CurrentWeaponHash, -1, Position.X, Position.Y, Position.Z, true, 0, 0));
if (_weaponObj == null) { return; }
if (CurrentWeaponHash != (uint)WeaponHash.Unarmed)
@@ -529,7 +529,7 @@ namespace RageCoop.Client
}
_lastWeaponComponents = WeaponComponents;
}
- if (Function.Call(Hash.GET_PED_WEAPON_TINT_INDEX, MainPed, CurrentWeaponHash)!=WeaponTint)
+ if (Function.Call(Hash.GET_PED_WEAPON_TINT_INDEX, MainPed, CurrentWeaponHash) != WeaponTint)
{
Function.Call(Hash.SET_PED_WEAPON_TINT_INDEX, MainPed, CurrentWeaponHash, WeaponTint);
}
@@ -537,14 +537,14 @@ namespace RageCoop.Client
private void DisplayAiming()
{
- if (Velocity==default)
+ if (Velocity == default)
{
MainPed.Task.AimAt(AimCoords, 1000);
}
else
{
Function.Call(Hash.TASK_GO_TO_COORD_WHILE_AIMING_AT_COORD, MainPed.Handle,
- Position.X+Velocity.X, Position.Y+Velocity.Y, Position.Z+Velocity.Z,
+ Position.X + Velocity.X, Position.Y + Velocity.Y, Position.Z + Velocity.Z,
AimCoords.X, AimCoords.Y, AimCoords.Z, 3f, false, 0x3F000000, 0x40800000, false, 512, false, 0);
}
@@ -555,7 +555,7 @@ namespace RageCoop.Client
{
MainPed.Task.ClearAll();
Function.Call(Hash.SET_PED_STEALTH_MOVEMENT, MainPed, IsInStealthMode, 0);
- Vector3 predictPosition = Predict(Position)+Velocity;
+ Vector3 predictPosition = Predict(Position) + Velocity;
float range = predictPosition.DistanceToSquared(MainPed.ReadPosition());
switch (Speed)
@@ -609,23 +609,23 @@ namespace RageCoop.Client
var dist = predicted.DistanceTo(MainPed.ReadPosition());
if (IsOff(dist))
{
- MainPed.PositionNoOffset= predicted;
+ MainPed.PositionNoOffset = predicted;
return;
}
if (!(localRagdoll || MainPed.IsDead))
{
if (!IsAiming && !MainPed.IsGettingUp)
{
- var cur=MainPed.Heading;
- var diff=Heading-cur;
+ var cur = MainPed.Heading;
+ var diff = Heading - cur;
if (diff > 180) { diff -= 360; }
else if (diff < -180) { diff += 360; }
-
- MainPed.Heading=cur+diff/2;
+
+ MainPed.Heading = cur + diff / 2;
}
MainPed.Velocity = Velocity + 5 * dist * (predicted - MainPed.ReadPosition());
}
- else if (Main.Ticked-_lastRagdollTime<10)
+ else if (Main.Ticked - _lastRagdollTime < 10)
{
return;
}
@@ -638,10 +638,10 @@ namespace RageCoop.Client
Vector3 amount;
// 20:head, 3:left foot, 6:right foot, 17:right hand,
- amount= 20 * (Predict(HeadPosition) - head.Position);
+ amount = 20 * (Predict(HeadPosition) - head.Position);
if (amount.Length() > 50) { amount = amount.Normalized * 50; }
helper.EqualizeAmount = 1;
- helper.PartIndex=20;
+ helper.PartIndex = 20;
helper.Impulse = amount;
helper.Start();
helper.Stop();
@@ -649,7 +649,7 @@ namespace RageCoop.Client
amount = 20 * (Predict(RightFootPosition) - rightFoot.Position);
if (amount.Length() > 50) { amount = amount.Normalized * 50; }
helper.EqualizeAmount = 1;
- helper.PartIndex=6;
+ helper.PartIndex = 6;
helper.Impulse = amount;
helper.Start();
helper.Stop();
@@ -657,7 +657,7 @@ namespace RageCoop.Client
amount = 20 * (Predict(LeftFootPosition) - leftFoot.Position);
if (amount.Length() > 50) { amount = amount.Normalized * 50; }
helper.EqualizeAmount = 1;
- helper.PartIndex=3;
+ helper.PartIndex = 3;
helper.Impulse = amount;
helper.Start();
helper.Stop();
@@ -665,19 +665,19 @@ namespace RageCoop.Client
else
{
// localRagdoll
- var force = Velocity - MainPed.Velocity+5 * dist * (predicted - MainPed.ReadPosition());
- if (force.Length() > 20) { force = force.Normalized*20; }
+ var force = Velocity - MainPed.Velocity + 5 * dist * (predicted - MainPed.ReadPosition());
+ if (force.Length() > 20) { force = force.Normalized * 20; }
MainPed.ApplyForce(force);
}
}
private void DisplayInVehicle()
{
- if (CurrentVehicle?.MainVehicle==null) { return; }
+ if (CurrentVehicle?.MainVehicle == null) { return; }
switch (Speed)
{
case 4:
- if (MainPed.CurrentVehicle!=CurrentVehicle.MainVehicle || MainPed.SeatIndex != Seat || (!MainPed.IsSittingInVehicle() && !MainPed.IsBeingJacked))
+ if (MainPed.CurrentVehicle != CurrentVehicle.MainVehicle || MainPed.SeatIndex != Seat || (!MainPed.IsSittingInVehicle() && !MainPed.IsBeingJacked))
{
MainPed.SetIntoVehicle(CurrentVehicle.MainVehicle, Seat);
}
@@ -686,7 +686,7 @@ namespace RageCoop.Client
// Function.Call(Hash.SET_VEHICLE_TURRET_SPEED_THIS_FRAME, MainPed.CurrentVehicle, 100);
Function.Call(Hash.TASK_VEHICLE_AIM_AT_COORD, MainPed.Handle, AimCoords.X, AimCoords.Y, AimCoords.Z);
}
- if (MainPed.VehicleWeapon==VehicleWeaponHash.Invalid)
+ if (MainPed.VehicleWeapon == VehicleWeaponHash.Invalid)
{
// World.DrawMarker(MarkerType.DebugSphere,AimCoords,default,default,new Vector3(0.2f,0.2f,0.2f),Color.AliceBlue);
if (IsAiming)
@@ -694,32 +694,32 @@ namespace RageCoop.Client
Function.Call(Hash.SET_DRIVEBY_TASK_TARGET, MainPed, 0, 0, AimCoords.X, AimCoords.Y, AimCoords.Z);
if (!_lastDriveBy)
{
- _lastDriveBy=true;
+ _lastDriveBy = true;
Function.Call(Hash.TASK_DRIVE_BY, MainPed, 0, 0, AimCoords.X, AimCoords.Y, AimCoords.Z, 1, 100, 1, FiringPattern.SingleShot);
}
}
else if (_lastDriveBy || MainPed.IsTaskActive(TaskType.CTaskAimGunVehicleDriveBy))
{
MainPed.Task.ClearAll();
- _lastDriveBy=false;
+ _lastDriveBy = false;
}
}
- else if (MainPed.VehicleWeapon!=(VehicleWeaponHash)CurrentWeaponHash)
+ else if (MainPed.VehicleWeapon != (VehicleWeaponHash)CurrentWeaponHash)
{
- MainPed.VehicleWeapon=(VehicleWeaponHash)CurrentWeaponHash;
+ MainPed.VehicleWeapon = (VehicleWeaponHash)CurrentWeaponHash;
}
break;
case 5:
- if (MainPed.VehicleTryingToEnter!=CurrentVehicle.MainVehicle || MainPed.GetSeatTryingToEnter()!=Seat)
+ if (MainPed.VehicleTryingToEnter != CurrentVehicle.MainVehicle || MainPed.GetSeatTryingToEnter() != Seat)
{
- MainPed.Task.EnterVehicle(CurrentVehicle.MainVehicle,Seat,-1,5,EnterVehicleFlags.AllowJacking);
+ MainPed.Task.EnterVehicle(CurrentVehicle.MainVehicle, Seat, -1, 5, EnterVehicleFlags.AllowJacking);
}
break;
case 6:
if (!MainPed.IsTaskActive(TaskType.CTaskExitVehicle))
{
- MainPed.Task.LeaveVehicle(CurrentVehicle.Velocity.Length() > 5f ? LeaveVehicleFlags.BailOut:LeaveVehicleFlags.None);
+ MainPed.Task.LeaveVehicle(CurrentVehicle.Velocity.Length() > 5f ? LeaveVehicleFlags.BailOut : LeaveVehicleFlags.None);
}
break;
}
diff --git a/RageCoop.Client/Sync/Entities/SyncedEntity.cs b/RageCoop.Client/Sync/Entities/SyncedEntity.cs
index faec6b6..5294377 100644
--- a/RageCoop.Client/Sync/Entities/SyncedEntity.cs
+++ b/RageCoop.Client/Sync/Entities/SyncedEntity.cs
@@ -33,11 +33,12 @@ namespace RageCoop.Client
get => _ownerID;
internal set
{
- if (value==_ownerID && Owner!=null) { return; }
+ if (value == _ownerID && Owner != null) { return; }
_ownerID = value;
- Owner=PlayerList.GetPlayer(value);
- if(this is SyncedPed && Owner!=null){
- Owner.Character=((SyncedPed)this);
+ Owner = PlayerList.GetPlayer(value);
+ if (this is SyncedPed && Owner != null)
+ {
+ Owner.Character = ((SyncedPed)this);
}
}
}
@@ -83,7 +84,7 @@ namespace RageCoop.Client
///
///
///
- internal protected bool _lastFrozen = false;
+ protected internal bool _lastFrozen = false;
internal Model Model { get; set; }
internal Vector3 Position { get; set; }
internal Vector3 Rotation { get; set; }
@@ -93,18 +94,18 @@ namespace RageCoop.Client
internal abstract void Update();
internal void PauseUpdate(ulong frames)
{
- LastUpdated=Main.Ticked+frames;
+ LastUpdated = Main.Ticked + frames;
}
protected Vector3 Predict(Vector3 input)
{
return (Owner.PacketTravelTime + 0.001f * LastSyncedStopWatch.ElapsedMilliseconds) * Velocity + input;
}
- private float _accumulatedOff=0;
- protected bool IsOff(float thisOff, float tolerance=3 , float limit = 30)
+ private float _accumulatedOff = 0;
+ protected bool IsOff(float thisOff, float tolerance = 3, float limit = 30)
{
_accumulatedOff += thisOff - tolerance;
- if (_accumulatedOff < 0) { _accumulatedOff=0;}
- else if (_accumulatedOff>=limit)
+ if (_accumulatedOff < 0) { _accumulatedOff = 0; }
+ else if (_accumulatedOff >= limit)
{
_accumulatedOff = 0;
return true;
diff --git a/RageCoop.Client/Sync/Entities/SyncedProjectile.cs b/RageCoop.Client/Sync/Entities/SyncedProjectile.cs
index 03ac942..1076409 100644
--- a/RageCoop.Client/Sync/Entities/SyncedProjectile.cs
+++ b/RageCoop.Client/Sync/Entities/SyncedProjectile.cs
@@ -1,13 +1,13 @@
using GTA;
using GTA.Math;
-using RageCoop.Core;
using GTA.Native;
+using RageCoop.Core;
namespace RageCoop.Client
{
internal class SyncedProjectile : SyncedEntity
{
- public ProjectileDataFlags Flags { private get; set; }=ProjectileDataFlags.None;
+ public ProjectileDataFlags Flags { private get; set; } = ProjectileDataFlags.None;
public readonly Vector3 Origin;
private bool _firstSend = false;
@@ -29,18 +29,18 @@ namespace RageCoop.Client
private WeaponAsset Asset { get; set; }
public void ExtractData(ref Packets.ProjectileSync p)
{
- p.Position=MainProjectile.Position;
- p.Velocity=MainProjectile.Velocity;
- p.Rotation=MainProjectile.Rotation;
- p.ID=ID;
- p.ShooterID=Shooter.ID;
- p.WeaponHash=(uint)MainProjectile.WeaponHash;
- p.Flags=ProjectileDataFlags.None;
+ p.Position = MainProjectile.Position;
+ p.Velocity = MainProjectile.Velocity;
+ p.Rotation = MainProjectile.Rotation;
+ p.ID = ID;
+ p.ShooterID = Shooter.ID;
+ p.WeaponHash = (uint)MainProjectile.WeaponHash;
+ p.Flags = ProjectileDataFlags.None;
if (MainProjectile.IsDead)
{
p.Flags |= ProjectileDataFlags.Exploded;
}
- if (MainProjectile.AttachedEntity!=null)
+ if (MainProjectile.AttachedEntity != null)
{
p.Flags |= ProjectileDataFlags.IsAttached;
}
@@ -51,44 +51,44 @@ namespace RageCoop.Client
if (_firstSend)
{
p.Flags |= ProjectileDataFlags.IsAttached;
- _firstSend=false;
+ _firstSend = false;
}
-
+
}
public SyncedProjectile(Projectile p)
{
var owner = p.OwnerEntity;
- if (owner==null) { IsValid=false;return; }
- ID=EntityPool.RequestNewID();
+ if (owner == null) { IsValid = false; return; }
+ ID = EntityPool.RequestNewID();
MainProjectile = p;
- Origin=p.Position;
- if(EntityPool.PedsByHandle.TryGetValue(owner.Handle,out var shooter))
+ Origin = p.Position;
+ if (EntityPool.PedsByHandle.TryGetValue(owner.Handle, out var shooter))
{
- if (shooter.MainPed!=null
- && (p.AttachedEntity==shooter.MainPed.Weapons.CurrentWeaponObject
- || p.AttachedEntity== shooter.MainPed))
+ if (shooter.MainPed != null
+ && (p.AttachedEntity == shooter.MainPed.Weapons.CurrentWeaponObject
+ || p.AttachedEntity == shooter.MainPed))
{
// Reloading
- IsValid=false;
+ IsValid = false;
return;
}
- Shooter=shooter;
- IsLocal=shooter.IsLocal;
+ Shooter = shooter;
+ IsLocal = shooter.IsLocal;
}
- else if(EntityPool.VehiclesByHandle.TryGetValue(owner.Handle,out var shooterVeh))
+ else if (EntityPool.VehiclesByHandle.TryGetValue(owner.Handle, out var shooterVeh))
{
- Shooter=shooterVeh;
- IsLocal=shooterVeh.IsLocal;
+ Shooter = shooterVeh;
+ IsLocal = shooterVeh.IsLocal;
}
else
{
- IsValid=false;
+ IsValid = false;
}
}
public SyncedProjectile(int id)
{
- ID= id;
- IsLocal=false;
+ ID = id;
+ IsLocal = false;
}
internal override void Update()
{
@@ -101,27 +101,27 @@ namespace RageCoop.Client
CreateProjectile();
return;
}
- MainProjectile.Velocity=Velocity+(Position+Shooter.Owner.PacketTravelTime*Velocity-MainProjectile.Position);
- MainProjectile.Rotation=Rotation;
- LastUpdated=Main.Ticked;
+ MainProjectile.Velocity = Velocity + (Position + Shooter.Owner.PacketTravelTime * Velocity - MainProjectile.Position);
+ MainProjectile.Rotation = Rotation;
+ LastUpdated = Main.Ticked;
}
private void CreateProjectile()
{
- Asset=new WeaponAsset(WeaponHash);
+ Asset = new WeaponAsset(WeaponHash);
if (!Asset.IsLoaded) { Asset.Request(); return; }
- if(Shooter == null) { return; }
+ if (Shooter == null) { return; }
Entity owner;
- owner=(Shooter as SyncedPed)?.MainPed ?? (Entity)(Shooter as SyncedVehicle)?.MainVehicle;
- var end = Position+Velocity;
- Function.Call(Hash.SHOOT_SINGLE_BULLET_BETWEEN_COORDS_IGNORE_ENTITY, Position.X, Position.Y, Position.Z, end.X, end.Y, end.Z, 0, 1, WeaponHash, owner?.Handle ?? 0, 1, 0, -1,owner);
+ owner = (Shooter as SyncedPed)?.MainPed ?? (Entity)(Shooter as SyncedVehicle)?.MainVehicle;
+ var end = Position + Velocity;
+ Function.Call(Hash.SHOOT_SINGLE_BULLET_BETWEEN_COORDS_IGNORE_ENTITY, Position.X, Position.Y, Position.Z, end.X, end.Y, end.Z, 0, 1, WeaponHash, owner?.Handle ?? 0, 1, 0, -1, owner);
var ps = World.GetAllProjectiles();
- MainProjectile=ps[ps.Length-1];
- MainProjectile.IsCollisionEnabled=false;
- MainProjectile.Position=Position;
- MainProjectile.Rotation =Rotation;
- MainProjectile.Velocity=Velocity;
- Main.Delay(()=>MainProjectile.IsCollisionEnabled=true, 100);
+ MainProjectile = ps[ps.Length - 1];
+ MainProjectile.IsCollisionEnabled = false;
+ MainProjectile.Position = Position;
+ MainProjectile.Rotation = Rotation;
+ MainProjectile.Velocity = Velocity;
+ Main.Delay(() => MainProjectile.IsCollisionEnabled = true, 100);
EntityPool.Add(this);
}
}
diff --git a/RageCoop.Client/Sync/Entities/SyncedProp.cs b/RageCoop.Client/Sync/Entities/SyncedProp.cs
index cce8dd4..bedba2e 100644
--- a/RageCoop.Client/Sync/Entities/SyncedProp.cs
+++ b/RageCoop.Client/Sync/Entities/SyncedProp.cs
@@ -9,7 +9,7 @@ namespace RageCoop.Client
{
internal SyncedProp(int id)
{
- ID= id;
+ ID = id;
}
///
/// The real entity
@@ -27,15 +27,15 @@ namespace RageCoop.Client
{
if (!NeedUpdate) { return; }
- if (MainProp== null || !MainProp.Exists())
+ if (MainProp == null || !MainProp.Exists())
{
- MainProp=World.CreateProp(Model, Position, Rotation, false, false);
- MainProp.IsInvincible=true;
+ MainProp = World.CreateProp(Model, Position, Rotation, false, false);
+ MainProp.IsInvincible = true;
}
- MainProp.Position=Position;
- MainProp.Rotation=Rotation;
+ MainProp.Position = Position;
+ MainProp.Rotation = Rotation;
MainProp.SetFrozen(true);
- LastUpdated=Main.Ticked;
+ LastUpdated = Main.Ticked;
}
}
}
diff --git a/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.Members.cs b/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.Members.cs
index 5f39871..580a838 100644
--- a/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.Members.cs
+++ b/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.Members.cs
@@ -1,13 +1,12 @@
-using System;
-using RageCoop.Core;
using GTA;
-using System.Diagnostics;
-using System.Collections.Generic;
using GTA.Math;
-using GTA.Native;
+using RageCoop.Core;
+using System.Collections.Generic;
-namespace RageCoop.Client{
- public partial class SyncedVehicle{
+namespace RageCoop.Client
+{
+ public partial class SyncedVehicle
+ {
public Vehicle MainVehicle { get; internal set; }
@@ -68,11 +67,10 @@ namespace RageCoop.Client{
private bool _lastHornActive = false;
private bool _lastTransformed = false;
internal int _lastLivery = -1;
- List _predictedTrace = new List();
- List _orgTrace = new List();
+ private readonly List _predictedTrace = new List();
+ private readonly List _orgTrace = new List();
private Vector3 _predictedPosition;
-
- float _elapsed;
+ private readonly float _elapsed;
#endregion
#region OUTGOING
diff --git a/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs b/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs
index 73dfe54..91a692a 100644
--- a/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs
+++ b/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs
@@ -4,8 +4,6 @@ using GTA.Native;
using RageCoop.Core;
using System;
using System.Collections.Generic;
-using System.Diagnostics;
-using System.Drawing;
namespace RageCoop.Client
{
@@ -24,22 +22,23 @@ namespace RageCoop.Client
internal SyncedVehicle(Vehicle v)
{
- ID=EntityPool.RequestNewID();
- MainVehicle=v;
- MainVehicle.CanPretendOccupants=false;
- OwnerID=Main.LocalPlayerID;
+ ID = EntityPool.RequestNewID();
+ MainVehicle = v;
+ MainVehicle.CanPretendOccupants = false;
+ OwnerID = Main.LocalPlayerID;
SetUpFixedData();
-
+
}
- internal void SetUpFixedData(){
+ internal void SetUpFixedData()
+ {
IsAircraft = MainVehicle.IsAircraft;
IsMotorcycle = MainVehicle.IsMotorcycle;
HasRocketBoost = MainVehicle.HasRocketBoost;
HasParachute = MainVehicle.HasParachute;
HasRoof = MainVehicle.HasRoof;
- IsSubmarineCar=MainVehicle.IsSubmarineCar;
- IsDeluxo=MainVehicle.Model==1483171323;
+ IsSubmarineCar = MainVehicle.IsSubmarineCar;
+ IsDeluxo = MainVehicle.Model == 1483171323;
}
///
@@ -51,14 +50,14 @@ namespace RageCoop.Client
}
internal SyncedVehicle(int id)
{
- ID=id;
- LastSynced=Main.Ticked;
+ ID = id;
+ LastSynced = Main.Ticked;
}
#endregion
///
/// VehicleSeat,ID
///
-
+
internal override void Update()
{
#if DEBUG_VEH
@@ -92,14 +91,14 @@ namespace RageCoop.Client
{
return;
}
-
+
if (SteeringAngle != MainVehicle.SteeringAngle)
{
MainVehicle.CustomSteeringAngle((float)(Math.PI / 180) * SteeringAngle);
}
- MainVehicle.ThrottlePower=ThrottlePower;
- MainVehicle.BrakePower=BrakePower;
-
+ MainVehicle.ThrottlePower = ThrottlePower;
+ MainVehicle.BrakePower = BrakePower;
+
if (IsDead)
{
if (MainVehicle.IsDead)
@@ -119,7 +118,7 @@ namespace RageCoop.Client
{
MainVehicle.Repair();
}
- },1000);
+ }, 1000);
}
}
if (MainVehicle.IsOnFire)
@@ -177,15 +176,17 @@ namespace RageCoop.Client
MainVehicle.SoundHorn(1);
}
- if (HasRoof && MainVehicle.RoofState!=RoofState)
+ if (HasRoof && MainVehicle.RoofState != RoofState)
{
- MainVehicle.RoofState=RoofState;
+ MainVehicle.RoofState = RoofState;
}
- if(HasRocketBoost && Flags.HasFlag(VehicleDataFlags.IsRocketBoostActive) != MainVehicle.IsRocketBoostActive()){
+ if (HasRocketBoost && Flags.HasFlag(VehicleDataFlags.IsRocketBoostActive) != MainVehicle.IsRocketBoostActive())
+ {
MainVehicle.SetRocketBoostActive(Flags.HasFlag(VehicleDataFlags.IsRocketBoostActive));
}
- if(HasParachute && Flags.HasFlag(VehicleDataFlags.IsParachuteActive) != MainVehicle.IsParachuteActive()){
+ if (HasParachute && Flags.HasFlag(VehicleDataFlags.IsParachuteActive) != MainVehicle.IsParachuteActive())
+ {
MainVehicle.SetParachuteActive(Flags.HasFlag(VehicleDataFlags.IsParachuteActive));
}
if (IsSubmarineCar)
@@ -204,7 +205,7 @@ namespace RageCoop.Client
Function.Call(Hash._TRANSFORM_SUBMARINE_TO_VEHICLE, MainVehicle.Handle, false);
}
}
- else if(IsDeluxo)
+ else if (IsDeluxo)
{
MainVehicle.SetDeluxoHoverState(IsDeluxoHovering);
if (IsDeluxoHovering)
@@ -214,12 +215,12 @@ namespace RageCoop.Client
}
Function.Call(Hash.SET_VEHICLE_BRAKE_LIGHTS, MainVehicle.Handle, BrakeLightsOn);
-
+
}
- MainVehicle.LockStatus=LockStatus;
+ MainVehicle.LockStatus = LockStatus;
- if (LastFullSynced>=LastUpdated)
+ if (LastFullSynced >= LastUpdated)
{
if (Flags.HasVehFlag(VehicleDataFlags.Repaired))
{
@@ -231,7 +232,7 @@ namespace RageCoop.Client
_lastVehicleColors = Colors;
}
- MainVehicle.EngineHealth=EngineHealth;
+ MainVehicle.EngineHealth = EngineHealth;
if (Mods != null && !Mods.Compare(_lastVehicleMods))
{
Function.Call(Hash.SET_VEHICLE_MOD_KIT, MainVehicle, 0);
@@ -244,21 +245,22 @@ namespace RageCoop.Client
_lastVehicleMods = Mods;
}
- if (Function.Call(Hash.GET_VEHICLE_NUMBER_PLATE_TEXT, MainVehicle)!=LicensePlate)
+ if (Function.Call(Hash.GET_VEHICLE_NUMBER_PLATE_TEXT, MainVehicle) != LicensePlate)
{
Function.Call(Hash.SET_VEHICLE_NUMBER_PLATE_TEXT, MainVehicle, LicensePlate);
}
- if (_lastLivery!=Livery)
+ if (_lastLivery != Livery)
{
Function.Call(Hash.SET_VEHICLE_LIVERY, MainVehicle, Livery);
- _lastLivery=Livery;
+ _lastLivery = Livery;
}
MainVehicle.SetDamageModel(DamageModel);
}
- LastUpdated=Main.Ticked;
+ LastUpdated = Main.Ticked;
}
- void DisplayVehicle()
+
+ private void DisplayVehicle()
{
_predictedPosition = Predict(Position);
var current = MainVehicle.ReadPosition();
@@ -278,7 +280,7 @@ namespace RageCoop.Client
}
Vector3 calirot;
- if (IsFlipped || (calirot = GetCalibrationRotation()).Length()>50)
+ if (IsFlipped || (calirot = GetCalibrationRotation()).Length() > 50)
{
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.ReadQuaternion(), Quaternion, 0.5f);
MainVehicle.RotationVelocity = RotationVelocity;
@@ -288,18 +290,18 @@ namespace RageCoop.Client
}
private Vector3 GetCalibrationRotation()
{
- var rot = Quaternion.LookRotation(Quaternion*Vector3.RelativeFront, Quaternion*Vector3.RelativeTop).ToEulerAngles();
- var curRot = Quaternion.LookRotation(MainVehicle.ReadQuaternion()*Vector3.RelativeFront, MainVehicle.ReadQuaternion()*Vector3.RelativeTop).ToEulerAngles();
+ var rot = Quaternion.LookRotation(Quaternion * Vector3.RelativeFront, Quaternion * Vector3.RelativeTop).ToEulerAngles();
+ var curRot = Quaternion.LookRotation(MainVehicle.ReadQuaternion() * Vector3.RelativeFront, MainVehicle.ReadQuaternion() * Vector3.RelativeTop).ToEulerAngles();
- var r = (rot-curRot).ToDegree();
- if (r.X>180) { r.X=r.X-360; }
- else if (r.X<-180) { r.X=360+r.X; }
+ var r = (rot - curRot).ToDegree();
+ if (r.X > 180) { r.X = r.X - 360; }
+ else if (r.X < -180) { r.X = 360 + r.X; }
- if (r.Y>180) { r.Y=r.Y-360; }
- else if (r.Y<-180) { r.Y=360+r.Y; }
+ if (r.Y > 180) { r.Y = r.Y - 360; }
+ else if (r.Y < -180) { r.Y = 360 + r.Y; }
- if (r.Z>180) { r.Z=r.Z-360; }
- else if (r.Z<-180) { r.Z=360+r.Z; }
+ if (r.Z > 180) { r.Z = r.Z - 360; }
+ else if (r.Z < -180) { r.Z = 360 + r.Z; }
return r;
}
private bool CreateVehicle()
@@ -311,7 +313,7 @@ namespace RageCoop.Client
// GTA.UI.Notification.Show($"~r~(Vehicle)Model ({CurrentVehicleModelHash}) cannot be loaded!");
return false;
}
- if (MainVehicle==null)
+ if (MainVehicle == null)
{
Model.Request();
return false;
@@ -323,13 +325,13 @@ namespace RageCoop.Client
MainVehicle.Quaternion = Quaternion;
if (MainVehicle.HasRoof)
{
- MainVehicle.RoofState=RoofState;
+ MainVehicle.RoofState = RoofState;
}
- foreach(var w in MainVehicle.Wheels)
+ foreach (var w in MainVehicle.Wheels)
{
w.Fix();
}
- if (IsInvincible) { MainVehicle.IsInvincible=true; }
+ if (IsInvincible) { MainVehicle.IsInvincible = true; }
SetUpFixedData();
Model.MarkAsNoLongerNeeded();
return true;
@@ -369,6 +371,6 @@ namespace RageCoop.Client
{
MainVehicle.Driver.Task.ClearAnimation(PedalingAnimDict(), PedalingAnimName(fast));
}
-#endregion
+ #endregion
}
}
diff --git a/RageCoop.Client/Sync/EntityPool.cs b/RageCoop.Client/Sync/EntityPool.cs
index 2d59200..da36223 100644
--- a/RageCoop.Client/Sync/EntityPool.cs
+++ b/RageCoop.Client/Sync/EntityPool.cs
@@ -1,18 +1,17 @@
using GTA;
using GTA.Native;
+using Lidgren.Network;
using RageCoop.Client.Scripting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
-using Lidgren.Network;
namespace RageCoop.Client
{
internal class EntityPool
{
public static object PedsLock = new object();
- public static int CharactersCount { get { return PedsByID.Count; } }
#if BENCHMARK
private static Stopwatch PerfCounter=new Stopwatch();
private static Stopwatch PerfCounter2=Stopwatch.StartNew();
@@ -31,7 +30,7 @@ namespace RageCoop.Client
public static Dictionary ServerProps = new Dictionary();
public static Dictionary ServerBlips = new Dictionary();
-
+
#endregion
#region LOCKS
@@ -46,7 +45,7 @@ namespace RageCoop.Client
{
foreach (int id in new List(PedsByID.Keys))
{
- if (keepPlayer && (id==Main.LocalPlayerID)|| keepMine && (PedsByID[id].OwnerID == Main.LocalPlayerID)) { continue; }
+ if (keepPlayer && (id == Main.LocalPlayerID) || keepMine && (PedsByID[id].OwnerID == Main.LocalPlayerID)) { continue; }
RemovePed(id);
}
PedsByID.Clear();
@@ -54,7 +53,7 @@ namespace RageCoop.Client
foreach (int id in new List(VehiclesByID.Keys))
{
- if (keepMine&&(VehiclesByID[id].OwnerID==Main.LocalPlayerID)) { continue; }
+ if (keepMine && (VehiclesByID[id].OwnerID == Main.LocalPlayerID)) { continue; }
RemoveVehicle(id);
}
VehiclesByID.Clear();
@@ -62,7 +61,7 @@ namespace RageCoop.Client
foreach (var p in ProjectilesByID.Values)
{
- if (p.Shooter.ID!=Main.LocalPlayerID && p.MainProjectile!=null && p.MainProjectile.Exists())
+ if (p.Shooter.ID != Main.LocalPlayerID && p.MainProjectile != null && p.MainProjectile.Exists())
{
p.MainProjectile.Delete();
}
@@ -96,7 +95,7 @@ namespace RageCoop.Client
// var clipset=p.Gender==Gender.Male? "MOVE_M@TOUGH_GUY@" : "MOVE_F@TOUGH_GUY@";
// Function.Call(Hash.SET_PED_MOVEMENT_CLIPSET,p,clipset,1f);
SyncedPed player = GetPedByID(Main.LocalPlayerID);
- if (player==null)
+ if (player == null)
{
Main.Logger.Debug($"Creating SyncEntity for player, handle:{p.Handle}");
SyncedPed c = new SyncedPed(p);
@@ -133,16 +132,16 @@ namespace RageCoop.Client
{
if (PedsByID.ContainsKey(c.ID))
{
- PedsByID[c.ID]=c;
+ PedsByID[c.ID] = c;
}
else
{
PedsByID.Add(c.ID, c);
}
- if (c.MainPed==null) { return; }
+ if (c.MainPed == null) { return; }
if (PedsByHandle.ContainsKey(c.MainPed.Handle))
{
- PedsByHandle[c.MainPed.Handle]=c;
+ PedsByHandle[c.MainPed.Handle] = c;
}
else
{
@@ -159,7 +158,7 @@ namespace RageCoop.Client
{
SyncedPed c = PedsByID[id];
var p = c.MainPed;
- if (p!=null)
+ if (p != null)
{
if (PedsByHandle.ContainsKey(p.Handle))
{
@@ -184,23 +183,23 @@ namespace RageCoop.Client
#endregion
#region VEHICLES
- public static SyncedVehicle GetVehicleByID(int id) => VehiclesByID.TryGetValue(id,out var v) ? v : null;
- public static SyncedVehicle GetVehicleByHandle(int handle) => VehiclesByHandle.TryGetValue(handle,out var v) ? v : null;
+ public static SyncedVehicle GetVehicleByID(int id) => VehiclesByID.TryGetValue(id, out var v) ? v : null;
+ public static SyncedVehicle GetVehicleByHandle(int handle) => VehiclesByHandle.TryGetValue(handle, out var v) ? v : null;
public static List GetVehicleIDs() => new List(VehiclesByID.Keys);
public static void Add(SyncedVehicle v)
{
if (VehiclesByID.ContainsKey(v.ID))
{
- VehiclesByID[v.ID]=v;
+ VehiclesByID[v.ID] = v;
}
else
{
VehiclesByID.Add(v.ID, v);
}
- if (v.MainVehicle==null) { return; }
+ if (v.MainVehicle == null) { return; }
if (VehiclesByHandle.ContainsKey(v.MainVehicle.Handle))
{
- VehiclesByHandle[v.MainVehicle.Handle]=v;
+ VehiclesByHandle[v.MainVehicle.Handle] = v;
}
else
{
@@ -217,7 +216,7 @@ namespace RageCoop.Client
{
SyncedVehicle v = VehiclesByID[id];
var veh = v.MainVehicle;
- if (veh!=null)
+ if (veh != null)
{
if (VehiclesByHandle.ContainsKey(veh.Handle))
{
@@ -239,27 +238,27 @@ namespace RageCoop.Client
#region PROJECTILES
public static SyncedProjectile GetProjectileByID(int id)
{
- return ProjectilesByID.TryGetValue(id,out var p) ? p : null;
+ return ProjectilesByID.TryGetValue(id, out var p) ? p : null;
}
public static void Add(SyncedProjectile p)
{
if (!p.IsValid) { return; }
- if (p.WeaponHash==(WeaponHash)VehicleWeaponHash.Tank)
+ if (p.WeaponHash == (WeaponHash)VehicleWeaponHash.Tank)
{
- Networking.SendBullet(p.Position, p.Position+p.Velocity, (uint)VehicleWeaponHash.Tank, ((SyncedVehicle)p.Shooter).MainVehicle.Driver.GetSyncEntity().ID);
+ Networking.SendBullet(p.Position, p.Position + p.Velocity, (uint)VehicleWeaponHash.Tank, ((SyncedVehicle)p.Shooter).MainVehicle.Driver.GetSyncEntity().ID);
}
if (ProjectilesByID.ContainsKey(p.ID))
{
- ProjectilesByID[p.ID]=p;
+ ProjectilesByID[p.ID] = p;
}
else
{
ProjectilesByID.Add(p.ID, p);
}
- if (p.MainProjectile==null) { return; }
+ if (p.MainProjectile == null) { return; }
if (ProjectilesByHandle.ContainsKey(p.MainProjectile.Handle))
{
- ProjectilesByHandle[p.MainProjectile.Handle]=p;
+ ProjectilesByHandle[p.MainProjectile.Handle] = p;
}
else
{
@@ -272,7 +271,7 @@ namespace RageCoop.Client
{
SyncedProjectile sp = ProjectilesByID[id];
var p = sp.MainProjectile;
- if (p!=null)
+ if (p != null)
{
if (ProjectilesByHandle.ContainsKey(p.Handle))
{
@@ -289,11 +288,11 @@ namespace RageCoop.Client
public static bool VehicleExists(int id) => VehiclesByID.ContainsKey(id);
public static bool ProjectileExists(int id) => ProjectilesByID.ContainsKey(id);
#endregion
- static int vehStateIndex;
- static int pedStateIndex;
- static int vehStatesPerFrame;
- static int pedStatesPerFrame;
- static int i;
+ private static int vehStateIndex;
+ private static int pedStateIndex;
+ private static int vehStatesPerFrame;
+ private static int pedStatesPerFrame;
+ private static int i;
public static Ped[] allPeds = new Ped[0];
public static Vehicle[] allVehicles = new Vehicle[0];
public static Projectile[] allProjectiles = new Projectile[0];
@@ -306,21 +305,10 @@ namespace RageCoop.Client
Debug.TimeStamps[TimeStamp.CheckProjectiles]=PerfCounter.ElapsedTicks;
#endif
allPeds = World.GetAllPeds();
- allVehicles=World.GetAllVehicles();
- allProjectiles=World.GetAllProjectiles();
- vehStatesPerFrame=allVehicles.Length*2/(int)Game.FPS+1;
- pedStatesPerFrame=allPeds.Length*2/(int)Game.FPS+1;
- /*
- if (Main.Ticked%50==0)
- {
- bool flag1 = allVehicles.Length>Main.Settings.WorldVehicleSoftLimit && Main.Settings.WorldVehicleSoftLimit>-1;
- bool flag2 = allPeds.Length>Main.Settings.WorldPedSoftLimit && Main.Settings.WorldPedSoftLimit>-1;
- if ((flag1||flag2) && _trafficSpawning)
- { SetBudget(0); _trafficSpawning=false; }
- else if(!_trafficSpawning)
- { SetBudget(1); _trafficSpawning=true; }
- }
- */
+ allVehicles = World.GetAllVehicles();
+ allProjectiles = World.GetAllProjectiles();
+ vehStatesPerFrame = allVehicles.Length * 2 / (int)Game.FPS + 1;
+ pedStatesPerFrame = allPeds.Length * 2 / (int)Game.FPS + 1;
#if BENCHMARK
Debug.TimeStamps[TimeStamp.GetAllEntities]=PerfCounter.ElapsedTicks;
@@ -342,10 +330,10 @@ namespace RageCoop.Client
// Outgoing sync
if (p.IsLocal)
{
- if (p.MainProjectile.AttachedEntity==null)
+ if (p.MainProjectile.AttachedEntity == null)
{
// Prevent projectiles from exploding next to vehicle
- if (p.WeaponHash==(WeaponHash)VehicleWeaponHash.Tank || p.MainProjectile.Position.DistanceTo(p.Origin)<2)
+ if (p.WeaponHash == (WeaponHash)VehicleWeaponHash.Tank || p.MainProjectile.Position.DistanceTo(p.Origin) < 2)
{
continue;
}
@@ -366,26 +354,26 @@ namespace RageCoop.Client
}
}
- i=-1;
+ i = -1;
lock (PedsLock)
{
- EntityPool.AddPlayer();
+ AddPlayer();
foreach (Ped p in allPeds)
{
- SyncedPed c = EntityPool.GetPedByHandle(p.Handle);
- if (c==null && (p!=Game.Player.Character))
+ SyncedPed c = GetPedByHandle(p.Handle);
+ if (c == null && (p != Game.Player.Character))
{
- if (allPeds.Length>Main.Settings.WorldPedSoftLimit && p.PopulationType != EntityPopulationType.RandomAmbient)
+ if (allPeds.Length > Main.Settings.WorldPedSoftLimit && p.PopulationType != EntityPopulationType.RandomAmbient)
{
p.Delete();
continue;
}
// Main.Logger.Trace($"Creating SyncEntity for ped, handle:{p.Handle}");
- c=new SyncedPed(p);
+ c = new SyncedPed(p);
- EntityPool.Add(c);
+ Add(c);
}
}
#if BENCHMARK
@@ -393,18 +381,18 @@ namespace RageCoop.Client
Debug.TimeStamps[TimeStamp.AddPeds]=PerfCounter.ElapsedTicks;
#endif
var ps = PedsByID.Values.ToArray();
- pedStateIndex+=pedStatesPerFrame;
- if (pedStateIndex>=ps.Length)
+ pedStateIndex += pedStatesPerFrame;
+ if (pedStateIndex >= ps.Length)
{
- pedStateIndex=0;
+ pedStateIndex = 0;
}
foreach (SyncedPed c in ps)
{
i++;
- if ((c.MainPed!=null)&&(!c.MainPed.Exists()))
+ if ((c.MainPed != null) && (!c.MainPed.Exists()))
{
- EntityPool.RemovePed(c.ID, "non-existent");
+ RemovePed(c.ID, "non-existent");
continue;
}
@@ -417,7 +405,7 @@ namespace RageCoop.Client
// event check
SyncEvents.Check(c);
- Networking.SendPed(c, (i-pedStateIndex)Main.Settings.WorldVehicleSoftLimit)
+ if (allVehicles.Length > Main.Settings.WorldVehicleSoftLimit)
{
var type = veh.PopulationType;
- if (type==EntityPopulationType.RandomAmbient || type==EntityPopulationType.RandomParked)
+ if (type == EntityPopulationType.RandomAmbient || type == EntityPopulationType.RandomParked)
{
foreach (var p in veh.Occupants)
{
p.Delete();
- var c = EntityPool.GetPedByHandle(p.Handle);
- if (c!=null)
+ var c = GetPedByHandle(p.Handle);
+ if (c != null)
{
- EntityPool.RemovePed(c.ID, "ThrottleTraffic");
+ RemovePed(c.ID, "ThrottleTraffic");
}
}
veh.Delete();
@@ -476,16 +464,16 @@ namespace RageCoop.Client
Debug.TimeStamps[TimeStamp.AddVehicles]=PerfCounter.ElapsedTicks;
#endif
var vs = VehiclesByID.Values.ToArray();
- vehStateIndex+=vehStatesPerFrame;
- if (vehStateIndex>=vs.Length)
+ vehStateIndex += vehStatesPerFrame;
+ if (vehStateIndex >= vs.Length)
{
- vehStateIndex=0;
+ vehStateIndex = 0;
}
foreach (SyncedVehicle v in vs)
{
i++;
- if ((v.MainVehicle!=null)&&(!v.MainVehicle.Exists()))
+ if ((v.MainVehicle != null) && (!v.MainVehicle.Exists()))
{
RemoveVehicle(v.ID, "non-existent");
continue;
@@ -500,7 +488,7 @@ namespace RageCoop.Client
if (!v.MainVehicle.IsVisible) { continue; }
SyncEvents.Check(v);
- Networking.SendVehicle(v, (i-vehStateIndex)(PlayerList.Players.Count) { Networking.ServerConnection };
+ Networking.Targets = new List(PlayerList.Players.Count) { Networking.ServerConnection };
foreach (var p in PlayerList.Players.Values.ToArray())
{
- if (p.HasDirectConnection && p.Position.DistanceTo(Main.PlayerPosition)<500)
+ if (p.HasDirectConnection && p.Position.DistanceTo(Main.PlayerPosition) < 500)
{
Networking.Targets.Add(p.Connection);
}
@@ -534,7 +523,7 @@ namespace RageCoop.Client
{
foreach (SyncedPed p in PedsByID.Values.ToArray())
{
- if (p.OwnerID==playerPedId)
+ if (p.OwnerID == playerPedId)
{
RemovePed(p.ID);
}
@@ -542,7 +531,7 @@ namespace RageCoop.Client
foreach (SyncedVehicle v in VehiclesByID.Values.ToArray())
{
- if (v.OwnerID==playerPedId)
+ if (v.OwnerID == playerPedId)
{
RemoveVehicle(v.ID);
}
@@ -552,7 +541,7 @@ namespace RageCoop.Client
public static int RequestNewID()
{
int ID = 0;
- while ((ID==0) || PedsByID.ContainsKey(ID) || VehiclesByID.ContainsKey(ID) || ProjectilesByID.ContainsKey(ID))
+ while ((ID == 0) || PedsByID.ContainsKey(ID) || VehiclesByID.ContainsKey(ID) || ProjectilesByID.ContainsKey(ID))
{
byte[] rngBytes = new byte[4];
@@ -583,21 +572,21 @@ namespace RageCoop.Client
{
public static void Add(SyncedVehicle v)
{
- lock (EntityPool.VehiclesLock)
+ lock (VehiclesLock)
{
EntityPool.Add(v);
}
}
public static void Add(SyncedPed p)
{
- lock (EntityPool.PedsLock)
+ lock (PedsLock)
{
EntityPool.Add(p);
}
}
public static void Add(SyncedProjectile sp)
{
- lock (EntityPool.ProjectilesLock)
+ lock (ProjectilesLock)
{
EntityPool.Add(sp);
}
diff --git a/RageCoop.Client/Sync/SyncEvents.cs b/RageCoop.Client/Sync/SyncEvents.cs
index 614d1b9..e5f799e 100644
--- a/RageCoop.Client/Sync/SyncEvents.cs
+++ b/RageCoop.Client/Sync/SyncEvents.cs
@@ -1,10 +1,8 @@
using GTA;
using GTA.Math;
+using Lidgren.Network;
using RageCoop.Core;
using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Lidgren.Network;
namespace RageCoop.Client
{
@@ -13,7 +11,7 @@ namespace RageCoop.Client
#region TRIGGER
public static void TriggerPedKilled(SyncedPed victim)
{
- Networking.SendSync(new Packets.PedKilled() { VictimID=victim.ID }, ConnectionChannel.SyncEvents);
+ Networking.SendSync(new Packets.PedKilled() { VictimID = victim.ID }, ConnectionChannel.SyncEvents);
}
public static void TriggerChangeOwner(int vehicleID, int newOwnerID)
@@ -21,9 +19,9 @@ namespace RageCoop.Client
Networking.SendSync(new Packets.OwnerChanged()
{
- ID= vehicleID,
- NewOwnerID= newOwnerID,
- }, ConnectionChannel.SyncEvents,NetDeliveryMethod.ReliableOrdered);
+ ID = vehicleID,
+ NewOwnerID = newOwnerID,
+ }, ConnectionChannel.SyncEvents, NetDeliveryMethod.ReliableOrdered);
}
@@ -33,11 +31,11 @@ namespace RageCoop.Client
var start = owner.MainPed.GetMuzzlePosition();
- if (owner.MainPed.IsOnTurretSeat()) { start=owner.MainPed.Bones[Bone.SkelHead].Position; }
- if (start.DistanceTo(impactPosition)>10)
+ if (owner.MainPed.IsOnTurretSeat()) { start = owner.MainPed.Bones[Bone.SkelHead].Position; }
+ if (start.DistanceTo(impactPosition) > 10)
{
// Reduce latency
- start=impactPosition-(impactPosition-start).Normalized*10;
+ start = impactPosition - (impactPosition - start).Normalized * 10;
}
Networking.SendBullet(start, impactPosition, hash, owner.ID);
}
@@ -47,14 +45,14 @@ namespace RageCoop.Client
int i;
// ANNIHL
- if (veh.Model.Hash==837858166)
+ if (veh.Model.Hash == 837858166)
{
Networking.SendVehicleBullet(hash, owner, veh.Bones[35]);
Networking.SendVehicleBullet(hash, owner, veh.Bones[36]);
Networking.SendVehicleBullet(hash, owner, veh.Bones[37]);
Networking.SendVehicleBullet(hash, owner, veh.Bones[38]);
}
- else if((i = veh.GetMuzzleIndex())!=-1)
+ else if ((i = veh.GetMuzzleIndex()) != -1)
{
Networking.SendVehicleBullet(hash, owner, veh.Bones[i]);
}
@@ -65,7 +63,7 @@ namespace RageCoop.Client
}
public static void TriggerNozzleTransform(int vehID, bool hover)
{
- Networking.SendSync(new Packets.NozzleTransform() { VehicleID=vehID, Hover=hover }, ConnectionChannel.SyncEvents);
+ Networking.SendSync(new Packets.NozzleTransform() { VehicleID = vehID, Hover = hover }, ConnectionChannel.SyncEvents);
}
#endregion
@@ -73,9 +71,8 @@ namespace RageCoop.Client
#region HANDLE
public static ParticleEffectAsset CorePFXAsset = new ParticleEffectAsset("core");
-
- static WeaponAsset _weaponAsset = default;
- static uint _lastWeaponHash;
+ private static WeaponAsset _weaponAsset = default;
+ private static uint _lastWeaponHash;
private static void HandlePedKilled(Packets.PedKilled p)
{
@@ -84,11 +81,11 @@ namespace RageCoop.Client
private static void HandleOwnerChanged(Packets.OwnerChanged p)
{
var v = EntityPool.GetVehicleByID(p.ID);
- if (v==null) { return; }
- v.OwnerID=p.NewOwnerID;
- v.LastSynced=Main.Ticked;
- v.Position=v.MainVehicle.Position;
- v.Quaternion=v.MainVehicle.Quaternion;
+ if (v == null) { return; }
+ v.OwnerID = p.NewOwnerID;
+ v.LastSynced = Main.Ticked;
+ v.Position = v.MainVehicle.Position;
+ v.Quaternion = v.MainVehicle.Quaternion;
}
private static void HandleNozzleTransform(Packets.NozzleTransform p)
{
@@ -100,47 +97,47 @@ namespace RageCoop.Client
{
// Minigun, not working for some reason
case (uint)WeaponHash.Minigun:
- weaponHash=1176362416;
+ weaponHash = 1176362416;
break;
// Valkyire, not working for some reason
case 2756787765:
- weaponHash=1176362416;
+ weaponHash = 1176362416;
break;
// Tampa3, not working for some reason
case 3670375085:
- weaponHash=1176362416;
+ weaponHash = 1176362416;
break;
// Ruiner2, not working for some reason
case 50118905:
- weaponHash=1176362416;
+ weaponHash = 1176362416;
break;
// SAVAGE
case 1638077257:
- weaponHash=(uint)VehicleWeaponHash.PlayerLazer;
+ weaponHash = (uint)VehicleWeaponHash.PlayerLazer;
break;
case (uint)VehicleWeaponHash.PlayerBuzzard:
- weaponHash=1176362416;
+ weaponHash = 1176362416;
break;
}
var p = EntityPool.GetPedByID(ownerID)?.MainPed;
- if (p == null) { p=Game.Player.Character; Main.Logger.Warning("Failed to find owner for bullet"); }
+ if (p == null) { p = Game.Player.Character; Main.Logger.Warning("Failed to find owner for bullet"); }
if (!CorePFXAsset.IsLoaded) { CorePFXAsset.Request(); }
- if (_lastWeaponHash!=weaponHash)
+ if (_lastWeaponHash != weaponHash)
{
_weaponAsset.MarkAsNoLongerNeeded();
- _weaponAsset=new WeaponAsset(weaponHash);
- _lastWeaponHash=weaponHash;
+ _weaponAsset = new WeaponAsset(weaponHash);
+ _lastWeaponHash = weaponHash;
}
if (!_weaponAsset.IsLoaded) { _weaponAsset.Request(); }
World.ShootBullet(start, end, p, _weaponAsset, (int)p.GetWeaponDamage(weaponHash));
Prop w;
- if (((w = p.Weapons.CurrentWeaponObject) != null)&&(p.VehicleWeapon==VehicleWeaponHash.Invalid))
+ if (((w = p.Weapons.CurrentWeaponObject) != null) && (p.VehicleWeapon == VehicleWeaponHash.Invalid))
{
if (p.Weapons.Current.Components.GetSuppressorComponent().Active)
{
@@ -154,13 +151,13 @@ namespace RageCoop.Client
}
public static void HandleVehicleBulletShot(Packets.VehicleBulletShot p)
{
- HandleBulletShot(p.StartPosition,p.EndPosition,p.WeaponHash,p.OwnerID);
+ HandleBulletShot(p.StartPosition, p.EndPosition, p.WeaponHash, p.OwnerID);
var v = EntityPool.GetPedByID(p.OwnerID)?.MainPed.CurrentVehicle;
- if(v == null) { return; }
+ if (v == null) { return; }
var b = v.Bones[p.Bone];
- World.CreateParticleEffectNonLooped(CorePFXAsset,
+ World.CreateParticleEffectNonLooped(CorePFXAsset,
WeaponUtil.GetFlashFX((WeaponHash)p.WeaponHash),
- b.Position,b.ForwardVector.ToEulerRotation(v.Bones[35].UpVector),1);
+ b.Position, b.ForwardVector.ToEulerRotation(v.Bones[35].UpVector), 1);
}
public static void HandleEvent(PacketType type, byte[] data)
{
@@ -220,9 +217,9 @@ namespace RageCoop.Client
Func getBulletImpact = (() =>
{
Vector3 endPos = subject.LastWeaponImpactPosition;
- if (endPos==default)
+ if (endPos == default)
{
- if (++i<=5) { return false; }
+ if (++i <= 5) { return false; }
endPos = subject.GetAimCoord();
if (subject.IsInVehicle() && subject.VehicleWeapon != VehicleWeaponHash.Invalid)
@@ -267,7 +264,7 @@ namespace RageCoop.Client
Main.QueueAction(getBulletImpact);
}
}
- else if (subject.VehicleWeapon==VehicleWeaponHash.Tank && subject.LastWeaponImpactPosition!=default)
+ else if (subject.VehicleWeapon == VehicleWeaponHash.Tank && subject.LastWeaponImpactPosition != default)
{
TriggerBulletShot((uint)VehicleWeaponHash.Tank, c, subject.LastWeaponImpactPosition);
}
@@ -276,7 +273,7 @@ namespace RageCoop.Client
public static void Check(SyncedVehicle v)
{
- if (v.MainVehicle==null||!v.MainVehicle.HasNozzle())
+ if (v.MainVehicle == null || !v.MainVehicle.HasNozzle())
{
return;
}
diff --git a/RageCoop.Client/Sync/Voice.cs b/RageCoop.Client/Sync/Voice.cs
index ef41f3d..9da150f 100644
--- a/RageCoop.Client/Sync/Voice.cs
+++ b/RageCoop.Client/Sync/Voice.cs
@@ -1,6 +1,5 @@
-using System.Threading;
-
-using NAudio.Wave;
+using NAudio.Wave;
+using System.Threading;
namespace RageCoop.Client
{
diff --git a/RageCoop.Client/Util/Memory.cs b/RageCoop.Client/Util/Memory.cs
index 72d0f9a..791969d 100644
--- a/RageCoop.Client/Util/Memory.cs
+++ b/RageCoop.Client/Util/Memory.cs
@@ -1,18 +1,19 @@
+using GTA;
+using GTA.Math;
+using RageCoop.Core;
+using SHVDN;
using System;
using System.Collections.Generic;
-using GTA.Math;
-using GTA;
-using SHVDN;
-using RageCoop.Core;
using System.Runtime.InteropServices;
namespace RageCoop.Client
{
- internal unsafe class MemPatch{
- private byte[] _data;
- private byte[] _orginal;
- private IntPtr _address;
+ internal unsafe class MemPatch
+ {
+ private readonly byte[] _data;
+ private readonly byte[] _orginal;
+ private readonly IntPtr _address;
public MemPatch(byte* address, byte[] data)
{
_data = data;
@@ -30,7 +31,7 @@ namespace RageCoop.Client
}
}
-internal static unsafe class Memory
+ internal static unsafe class Memory
{
public static MemPatch VignettingPatch;
public static MemPatch VignettingCallPatch;
@@ -40,12 +41,12 @@ internal static unsafe class Memory
// Weapon/radio wheel slow-mo patch
// Thanks @CamxxCore, https://github.com/CamxxCore/GTAVWeaponWheelMod
var result = NativeMemory.FindPattern("\x38\x51\x64\x74\x19", "xxxxx");
- if(result == null) { throw new NotSupportedException("Can't find memory pattern to patch weapon/radio slow-mo"); }
- var address = result+26;
+ if (result == null) { throw new NotSupportedException("Can't find memory pattern to patch weapon/radio slow-mo"); }
+ var address = result + 26;
address = address + *(int*)address + 4u;
- VignettingPatch=new MemPatch(address, new byte[] { RET, 0x90, 0x90, 0x90, 0x90 });
- VignettingCallPatch=new MemPatch(result+8, new byte[]{ 0x90, 0x90, 0x90, 0x90, 0x90});
- TimeScalePatch=new MemPatch(result+34, new byte[] { XOR_32_64, 0xD2 });
+ VignettingPatch = new MemPatch(address, new byte[] { RET, 0x90, 0x90, 0x90, 0x90 });
+ VignettingCallPatch = new MemPatch(result + 8, new byte[] { 0x90, 0x90, 0x90, 0x90, 0x90 });
+ TimeScalePatch = new MemPatch(result + 34, new byte[] { XOR_32_64, 0xD2 });
}
public static void ApplyPatches()
@@ -68,30 +69,30 @@ internal static unsafe class Memory
public const int MatrixOffset = 96;
#endregion
#region OPCODE
- const byte XOR_32_64 = 0x31;
- const byte RET = 0xC3;
+ private const byte XOR_32_64 = 0x31;
+ private const byte RET = 0xC3;
#endregion
public static Vector3 ReadPosition(this Entity e) => ReadVector3(e.MemoryAddress + PositionOffset);
public static Quaternion ReadQuaternion(this Entity e) => Quaternion.RotationMatrix(e.Matrix);
public static Vector3 ReadRotation(this Entity e) => e.ReadQuaternion().ToEulerDegrees();
- public static Vector3 ReadVelocity(this Ped e) => ReadVector3(e.MemoryAddress+VelocityOffset);
+ public static Vector3 ReadVelocity(this Ped e) => ReadVector3(e.MemoryAddress + VelocityOffset);
public static Vector3 ReadVector3(IntPtr address)
{
float* ptr = (float*)address.ToPointer();
return new Vector3()
{
- X=*ptr,
- Y=ptr[1],
- Z=ptr[2]
+ X = *ptr,
+ Y = ptr[1],
+ Z = ptr[2]
};
}
- public static List FindOffset(float toSearch,IntPtr start, int range=1000, float tolerance = 0.01f)
+ public static List FindOffset(float toSearch, IntPtr start, int range = 1000, float tolerance = 0.01f)
{
var foundOffsets = new List(100);
for (int i = 0; i <= range; i++)
{
- var val = NativeMemory.ReadFloat(start+i);
- if (Math.Abs(val-toSearch)(T val) where T : unmanaged
- {
- ulong val64 = 0;
- *(T*)(&val64) = val;
- NativePush64(val64);
- }
+ // These are from ScriptHookV's nativeCaller.h
+ private static unsafe void NativePush(T val) where T : unmanaged
+ {
+ ulong val64 = 0;
+ *(T*)(&val64) = val;
+ NativePush64(val64);
+ }
- public static unsafe R Invoke(ulong hash) where R : unmanaged
- {
- NativeInit(hash);
- return *(R*)(NativeCall());
- }
- public static unsafe R Invoke(Hash hash, params object[] args)
- where R : unmanaged
- {
- NativeInit((ulong)hash);
- var arguments=ConvertPrimitiveArguments(args);
- foreach (var arg in arguments)
- NativePush(arg);
+ public static unsafe R Invoke(ulong hash) where R : unmanaged
+ {
+ NativeInit(hash);
+ return *(R*)(NativeCall());
+ }
+ public static unsafe R Invoke(Hash hash, params object[] args)
+ where R : unmanaged
+ {
+ NativeInit((ulong)hash);
+ var arguments = ConvertPrimitiveArguments(args);
+ foreach (var arg in arguments)
+ NativePush(arg);
- return *(R*)(NativeCall());
- }
+ return *(R*)(NativeCall());
+ }
- ///
- /// Helper function that converts an array of primitive values to a native stack.
- ///
- ///
- ///
- static unsafe ulong[] ConvertPrimitiveArguments(object[] args)
- {
- var result = new ulong[args.Length];
- for (int i = 0; i < args.Length; ++i)
- {
- if (args[i] is bool valueBool)
- {
- result[i] = valueBool ? 1ul : 0ul;
- continue;
- }
- if (args[i] is byte valueByte)
- {
- result[i] = (ulong)valueByte;
- continue;
- }
- if (args[i] is int valueInt32)
- {
- result[i] = (ulong)valueInt32;
- continue;
- }
- if (args[i] is ulong valueUInt64)
- {
- result[i] = valueUInt64;
- continue;
- }
- if (args[i] is float valueFloat)
- {
- result[i] = *(ulong*)&valueFloat;
- continue;
- }
- if (args[i] is IntPtr valueIntPtr)
- {
- result[i] = (ulong)valueIntPtr.ToInt64();
- continue;
- }
+ ///
+ /// Helper function that converts an array of primitive values to a native stack.
+ ///
+ ///
+ ///
+ private static unsafe ulong[] ConvertPrimitiveArguments(object[] args)
+ {
+ var result = new ulong[args.Length];
+ for (int i = 0; i < args.Length; ++i)
+ {
+ if (args[i] is bool valueBool)
+ {
+ result[i] = valueBool ? 1ul : 0ul;
+ continue;
+ }
+ if (args[i] is byte valueByte)
+ {
+ result[i] = valueByte;
+ continue;
+ }
+ if (args[i] is int valueInt32)
+ {
+ result[i] = (ulong)valueInt32;
+ continue;
+ }
+ if (args[i] is ulong valueUInt64)
+ {
+ result[i] = valueUInt64;
+ continue;
+ }
+ if (args[i] is float valueFloat)
+ {
+ result[i] = *(ulong*)&valueFloat;
+ continue;
+ }
+ if (args[i] is IntPtr valueIntPtr)
+ {
+ result[i] = (ulong)valueIntPtr.ToInt64();
+ continue;
+ }
- throw new ArgumentException("Unknown primitive type in native argument list", nameof(args));
- }
+ throw new ArgumentException("Unknown primitive type in native argument list", nameof(args));
+ }
- return result;
- }
- }
+ return result;
+ }
+ }
}
diff --git a/RageCoop.Client/Util/PedExtensions.cs b/RageCoop.Client/Util/PedExtensions.cs
index b09a446..fdf5f00 100644
--- a/RageCoop.Client/Util/PedExtensions.cs
+++ b/RageCoop.Client/Util/PedExtensions.cs
@@ -2,8 +2,8 @@
using GTA.Math;
using GTA.Native;
using RageCoop.Core;
-using System.Collections.Generic;
using System;
+using System.Collections.Generic;
namespace RageCoop.Client
{
@@ -80,9 +80,9 @@ namespace RageCoop.Client
var result = new byte[36];
for (byte i = 0; i < 12; i++)
{
- result[i]=(byte)Function.Call(Hash.GET_PED_DRAWABLE_VARIATION, ped.Handle, i);
- result[i+12]=(byte)Function.Call(Hash.GET_PED_TEXTURE_VARIATION, ped.Handle, i);
- result[i+24]=(byte)Function.Call(Hash.GET_PED_PALETTE_VARIATION, ped.Handle, i);
+ result[i] = (byte)Function.Call(Hash.GET_PED_DRAWABLE_VARIATION, ped.Handle, i);
+ result[i + 12] = (byte)Function.Call(Hash.GET_PED_TEXTURE_VARIATION, ped.Handle, i);
+ result[i + 24] = (byte)Function.Call(Hash.GET_PED_PALETTE_VARIATION, ped.Handle, i);
}
return result;
}
@@ -108,7 +108,7 @@ namespace RageCoop.Client
}
// Fake death
- if (ped.IsRagdoll || (ped.Health==1 && ped.IsPlayer))
+ if (ped.IsRagdoll || (ped.Health == 1 && ped.IsPlayer))
{
flags |= PedDataFlags.IsRagdoll;
}
@@ -144,14 +144,15 @@ namespace RageCoop.Client
flags |= PedDataFlags.IsInCover;
if (ped.IsInCoverFacingLeft)
{
- flags |=PedDataFlags.IsInCover;
+ flags |= PedDataFlags.IsInCover;
}
- if (!Function.Call(Hash.IS_PED_IN_HIGH_COVER, ped)){
- flags|=PedDataFlags.IsInLowCover;
+ if (!Function.Call(Hash.IS_PED_IN_HIGH_COVER, ped))
+ {
+ flags |= PedDataFlags.IsInLowCover;
}
if (ped.IsTaskActive(TaskType.CTaskAimGunBlindFire))
{
- flags|=PedDataFlags.IsBlindFiring;
+ flags |= PedDataFlags.IsBlindFiring;
}
}
@@ -276,7 +277,7 @@ namespace RageCoop.Client
veh,
veh.Bones[text].Index
}));
- bool flag2 = (num2 < distanceToignoreDoors) && (num2 < num)&& IsSeatUsableByPed(ped, veh, dictionary[text]);
+ bool flag2 = (num2 < distanceToignoreDoors) && (num2 < num) && IsSeatUsableByPed(ped, veh, dictionary[text]);
if (flag2)
{
num = num2;
@@ -330,29 +331,29 @@ namespace RageCoop.Client
var v = p.CurrentVehicle;
// Rhino
- if (v!=null && v.Model.Hash==782665360)
+ if (v != null && v.Model.Hash == 782665360)
{
- return v.Bones[35].Position+v.Bones[35].ForwardVector*100;
+ return v.Bones[35].Position + v.Bones[35].ForwardVector * 100;
}
if (p.IsOnTurretSeat()) { return p.GetLookingCoord(); }
- if (weapon!=null)
+ if (weapon != null)
{
// Not very accurate, but doesn't matter
Vector3 dir = weapon.RightVector;
- return weapon.Position+dir*20;
+ return weapon.Position + dir * 20;
}
return GetLookingCoord(p);
}
public static Vector3 GetLookingCoord(this Ped p)
{
- if (p==Main.P && Function.Call(Hash.GET_FOLLOW_PED_CAM_VIEW_MODE)==4)
+ if (p == Main.P && Function.Call(Hash.GET_FOLLOW_PED_CAM_VIEW_MODE) == 4)
{
return RaycastEverything(default);
}
EntityBone b = p.Bones[Bone.FacialForehead];
Vector3 v = b.UpVector.Normalized;
- return b.Position+200*v;
+ return b.Position + 200 * v;
}
public static VehicleSeat GetSeatTryingToEnter(this Ped p)
{
@@ -475,7 +476,7 @@ namespace RageCoop.Client
|| (VehicleHash)veh.Model.Hash == VehicleHash.Cerberus3;
case 0:
return (VehicleHash)veh.Model.Hash == VehicleHash.Apc
- || (VehicleHash)veh.Model.Hash==VehicleHash.Dune3;
+ || (VehicleHash)veh.Model.Hash == VehicleHash.Dune3;
case 1:
return (VehicleHash)veh.Model.Hash == VehicleHash.Valkyrie
|| (VehicleHash)veh.Model.Hash == VehicleHash.Valkyrie2
diff --git a/RageCoop.Client/Util/Util.cs b/RageCoop.Client/Util/Util.cs
index f860084..fd6cdb6 100644
--- a/RageCoop.Client/Util/Util.cs
+++ b/RageCoop.Client/Util/Util.cs
@@ -6,13 +6,10 @@ using System;
using System.Drawing;
using System.IO;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using System.Security.Cryptography;
-using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("RageCoop.Client.Installer")]
namespace RageCoop.Client
@@ -42,7 +39,7 @@ namespace RageCoop.Client
var res = ResolutionMaintainRatio;
if (Function.Call(Hash.GET_SCREEN_COORD_FROM_WORLD_COORD, pos.X, pos.Y, pos.Z, &x, &y))
{
- screenPos =new Point((int)(res.Width*x), (int)(y*1080));
+ screenPos = new Point((int)(res.Width * x), (int)(y * 1080));
return true;
}
}
@@ -114,7 +111,7 @@ namespace RageCoop.Client
#endregion
public static string SettingsPath = "Scripts\\RageCoop\\Data\\RageCoop.Client.Settings.xml";
- public static Settings ReadSettings(string path=null)
+ public static Settings ReadSettings(string path = null)
{
path = path ?? SettingsPath;
XmlSerializer ser = new XmlSerializer(typeof(Settings));
@@ -139,7 +136,7 @@ namespace RageCoop.Client
return settings;
}
- public static bool SaveSettings(string path = null,Settings settings=null)
+ public static bool SaveSettings(string path = null, Settings settings = null)
{
try
{
@@ -192,7 +189,7 @@ namespace RageCoop.Client
{
if (p == null) { return null; }
var c = EntityPool.GetPedByHandle(p.Handle);
- if (c==null) { EntityPool.Add(c=new SyncedPed(p)); }
+ if (c == null) { EntityPool.Add(c = new SyncedPed(p)); }
return c;
}
@@ -200,7 +197,7 @@ namespace RageCoop.Client
{
if (veh == null) { return null; }
var v = EntityPool.GetVehicleByHandle(veh.Handle);
- if (v==null) { EntityPool.Add(v=new SyncedVehicle(veh)); }
+ if (v == null) { EntityPool.Add(v = new SyncedVehicle(veh)); }
return v;
}
@@ -219,7 +216,7 @@ namespace RageCoop.Client
#region WIN32
- const UInt32 WM_KEYDOWN = 0x0100;
+ private const UInt32 WM_KEYDOWN = 0x0100;
public static void Reload()
{
string reloadKey = "None";
@@ -227,18 +224,18 @@ namespace RageCoop.Client
foreach (var l in lines)
{
var ss = l.Split('=');
- if (ss.Length > 0 && ss[0]=="ReloadKey")
+ if (ss.Length > 0 && ss[0] == "ReloadKey")
{
reloadKey = ss[1];
}
}
var lineList = lines.ToList();
- if (reloadKey=="None")
+ if (reloadKey == "None")
{
foreach (var l in lines)
{
var ss = l.Split('=');
- if (ss.Length > 0 && ss[0]=="ReloadKey")
+ if (ss.Length > 0 && ss[0] == "ReloadKey")
{
reloadKey = ss[1];
lineList.Remove(l);
@@ -253,7 +250,7 @@ namespace RageCoop.Client
// Move log file so it doesn't get deleted
Main.Logger.Dispose();
- var path = Main.Logger.LogPath+".last.log";
+ var path = Main.Logger.LogPath + ".last.log";
try
{
if (File.Exists(path)) { File.Delete(path); }
@@ -268,7 +265,7 @@ namespace RageCoop.Client
}
[DllImport("user32.dll")]
- static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
+ private static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
[DllImport("kernel32.dll")]
diff --git a/RageCoop.Client/Util/VehicleExtensions.cs b/RageCoop.Client/Util/VehicleExtensions.cs
index 1644819..6b601f0 100644
--- a/RageCoop.Client/Util/VehicleExtensions.cs
+++ b/RageCoop.Client/Util/VehicleExtensions.cs
@@ -12,7 +12,7 @@ namespace RageCoop.Client
public static VehicleDataFlags GetVehicleFlags(this SyncedVehicle v)
{
- var veh=v.MainVehicle;
+ var veh = v.MainVehicle;
VehicleDataFlags flags = 0;
if (veh.IsEngineRunning)
@@ -75,31 +75,33 @@ namespace RageCoop.Client
flags |= VehicleDataFlags.IsRocketBoostActive;
}
- if(v.HasParachute && veh.IsParachuteActive()){
+ if (v.HasParachute && veh.IsParachuteActive())
+ {
flags |= VehicleDataFlags.IsParachuteActive;
}
if (veh.IsOnFire)
{
- flags|=VehicleDataFlags.IsOnFire;
+ flags |= VehicleDataFlags.IsOnFire;
}
return flags;
}
public static bool IsRocketBoostActive(this Vehicle veh)
{
- return Function.Call(Hash._IS_VEHICLE_ROCKET_BOOST_ACTIVE,veh);
+ return Function.Call(Hash._IS_VEHICLE_ROCKET_BOOST_ACTIVE, veh);
}
- public static bool IsParachuteActive(this Vehicle veh){
- return Function.Call((Hash)0x3DE51E9C80B116CF,veh);
- }
- public static void SetRocketBoostActive(this Vehicle veh,bool toggle)
+ public static bool IsParachuteActive(this Vehicle veh)
{
- Function.Call(Hash._SET_VEHICLE_ROCKET_BOOST_ACTIVE,veh,toggle);
+ return Function.Call((Hash)0x3DE51E9C80B116CF, veh);
}
- public static void SetParachuteActive(this Vehicle veh,bool toggle)
+ public static void SetRocketBoostActive(this Vehicle veh, bool toggle)
{
- Function.Call((Hash)0x0BFFB028B3DD0A97,veh,toggle);
+ Function.Call(Hash._SET_VEHICLE_ROCKET_BOOST_ACTIVE, veh, toggle);
+ }
+ public static void SetParachuteActive(this Vehicle veh, bool toggle)
+ {
+ Function.Call((Hash)0x0BFFB028B3DD0A97, veh, toggle);
}
public static Dictionary GetVehicleMods(this VehicleModCollection mods)
{
@@ -180,7 +182,7 @@ namespace RageCoop.Client
}
if ((model.OpenedDoors & (byte)(1 << i)) != 0)
{
- if ((!door.IsOpen)&&(!door.IsBroken))
+ if ((!door.IsOpen) && (!door.IsBroken))
{
door.Open();
}
@@ -224,7 +226,7 @@ namespace RageCoop.Client
{
Dictionary ps = new Dictionary();
var d = veh.Driver;
- if (d!=null&&d.IsSittingInVehicle())
+ if (d != null && d.IsSittingInVehicle())
{
ps.Add(-1, d.GetSyncEntity().ID);
}
@@ -232,7 +234,7 @@ namespace RageCoop.Client
{
if (p.IsSittingInVehicle())
{
- ps.Add((int)p.SeatIndex, (int)p.GetSyncEntity().ID);
+ ps.Add((int)p.SeatIndex, p.GetSyncEntity().ID);
}
}
return ps;
@@ -244,7 +246,7 @@ namespace RageCoop.Client
}
public static bool IsDeluxoHovering(this Vehicle deluxo)
{
- return Math.Abs(deluxo.Bones[27].ForwardVector.GetCosTheta(deluxo.ForwardVector)-1)>0.05;
+ return Math.Abs(deluxo.Bones[27].ForwardVector.GetCosTheta(deluxo.ForwardVector) - 1) > 0.05;
}
public static void SetDeluxoWingRatio(this Vehicle v, float ratio)
{
@@ -252,7 +254,7 @@ namespace RageCoop.Client
}
public static float GetDeluxoWingRatio(this Vehicle v)
{
- return v.Bones[99].Position.DistanceTo(v.Bones[92].Position)-1.43f;
+ return v.Bones[99].Position.DistanceTo(v.Bones[92].Position) - 1.43f;
}
public static float GetNozzleAngel(this Vehicle plane)
{
diff --git a/RageCoop.Client/Util/WeaponUtil.cs b/RageCoop.Client/Util/WeaponUtil.cs
index cb427ed..215f240 100644
--- a/RageCoop.Client/Util/WeaponUtil.cs
+++ b/RageCoop.Client/Util/WeaponUtil.cs
@@ -2,7 +2,6 @@
using GTA.Math;
using GTA.Native;
using System.Collections.Generic;
-using System.Xml;
namespace RageCoop.Client
{
@@ -11,7 +10,7 @@ namespace RageCoop.Client
public MuzzleInfo(Vector3 pos, Vector3 forward)
{
Position = pos;
- ForawardVector=forward;
+ ForawardVector = forward;
}
public Vector3 Position;
public Vector3 ForawardVector;
@@ -38,7 +37,7 @@ namespace RageCoop.Client
public static Vector3 GetMuzzlePosition(this Ped p)
{
var w = p.Weapons.CurrentWeaponObject;
- if (w!=null)
+ if (w != null)
{
var hash = p.Weapons.Current.Hash;
if (MuzzleBoneIndexes.ContainsKey(hash)) { return w.Bones[MuzzleBoneIndexes[hash]].Position; }
@@ -46,7 +45,8 @@ namespace RageCoop.Client
}
return p.Bones[Bone.SkelRightHand].Position;
}
- static long BulletsShot = 0;
+
+ private static long BulletsShot = 0;
public static float GetWeaponDamage(this Ped P, uint hash)
{
@@ -103,49 +103,49 @@ namespace RageCoop.Client
// ISSI6
case 1239571361:
- return BulletsShot%2==0 ? 12 : 14;
+ return BulletsShot % 2 == 0 ? 12 : 14;
// ISSI5
case 1537277726:
- return BulletsShot%2==0 ? 30 : 32;
+ return BulletsShot % 2 == 0 ? 30 : 32;
// ISSI4
case 628003514:
- return BulletsShot%2==0 ? 14 : 12;
+ return BulletsShot % 2 == 0 ? 14 : 12;
// DOMINATOR6
case -1293924613:
- return BulletsShot%2==0 ? 51 : 55;
+ return BulletsShot % 2 == 0 ? 51 : 55;
// IMPALER4
case -1744505657:
- return BulletsShot%2==0 ? 64 : 63;
+ return BulletsShot % 2 == 0 ? 64 : 63;
// IMPERATOR3
case -755532233:
- return BulletsShot%2==0 ? 86 : 88;
+ return BulletsShot % 2 == 0 ? 86 : 88;
// SLAMVAN6
case 1742022738:
- return BulletsShot%2==0 ? 78 : 76;
+ return BulletsShot % 2 == 0 ? 78 : 76;
// CHAMPION
case -915234475:
- return BulletsShot%2==0 ? 60 : 61;
+ return BulletsShot % 2 == 0 ? 60 : 61;
// MONSTER4
case 840387324:
- return BulletsShot%2==0 ? 63 : 65;
+ return BulletsShot % 2 == 0 ? 63 : 65;
// BRUTUS2
@@ -154,7 +154,7 @@ namespace RageCoop.Client
// BRUISER2
case -1694081890:
- return BulletsShot%2==0 ? 45 : 51;
+ return BulletsShot % 2 == 0 ? 45 : 51;
// TECHNICAL3
@@ -171,11 +171,11 @@ namespace RageCoop.Client
// PATRIOT3
case -670086588:
- return BulletsShot%2==0 ? 87 : 89;
+ return BulletsShot % 2 == 0 ? 87 : 89;
// NIGHTSHARK
case 433954513:
- return BulletsShot%2==0 ? 1 : 2;
+ return BulletsShot % 2 == 0 ? 1 : 2;
/*
// NIGHTSHARK (second)
@@ -185,7 +185,7 @@ namespace RageCoop.Client
// MENACER
case 2044532910:
- return BulletsShot%2==0 ? 91 : 90;
+ return BulletsShot % 2 == 0 ? 91 : 90;
/*
// MENACER
case 2044532910:
@@ -222,11 +222,11 @@ namespace RageCoop.Client
// BLAZER5
case -1590337689:
- return BulletsShot%2==0 ? 17 : 18;
+ return BulletsShot % 2 == 0 ? 17 : 18;
// BRUISER
case 668439077:
- return BulletsShot%2==0 ? 66 : 68;
+ return BulletsShot % 2 == 0 ? 66 : 68;
// BRUTUS
@@ -236,12 +236,12 @@ namespace RageCoop.Client
// MONSTER3
case 1721676810:
- return BulletsShot%2==0 ? 53 : 55;
+ return BulletsShot % 2 == 0 ? 53 : 55;
// BRUISER3
case -2042350822:
- return BulletsShot%2==0 ? 52 : 50;
+ return BulletsShot % 2 == 0 ? 52 : 50;
// BRUTUS3
case 2038858402:
@@ -249,34 +249,34 @@ namespace RageCoop.Client
// MONSTER5
case -715746948:
- return BulletsShot%2==0 ? 63 : 65;
+ return BulletsShot % 2 == 0 ? 63 : 65;
// JB7002
case 394110044:
- return BulletsShot%2==0 ? 54 : 53;
+ return BulletsShot % 2 == 0 ? 54 : 53;
// DOMINATOR5
case -1375060657:
- return BulletsShot%2==0 ? 35 : 36;
+ return BulletsShot % 2 == 0 ? 35 : 36;
// IMPALER3
case -1924800695:
- return BulletsShot%2==0 ? 75 : 76;
+ return BulletsShot % 2 == 0 ? 75 : 76;
// IMPERATOR2
case 1637620610:
- return BulletsShot%2==0 ? 97 : 99;
+ return BulletsShot % 2 == 0 ? 97 : 99;
// SLAMVAN5
case 373261600:
- return BulletsShot%2==0 ? 51 : 53;
+ return BulletsShot % 2 == 0 ? 51 : 53;
// RUINER2
case 941494461:
- return BulletsShot%2==0 ? 65 : 66;
+ return BulletsShot % 2 == 0 ? 65 : 66;
// TAMPA3
@@ -285,52 +285,52 @@ namespace RageCoop.Client
// SCRAMJET
case -638562243:
- return BulletsShot%2==0 ? 44 : 45;
+ return BulletsShot % 2 == 0 ? 44 : 45;
// VIGILANTE
case -1242608589:
- return BulletsShot%2==0 ? 42 : 43;
+ return BulletsShot % 2 == 0 ? 42 : 43;
// ZR380
case 540101442:
- return BulletsShot%2==0 ? 57 : 63;
+ return BulletsShot % 2 == 0 ? 57 : 63;
// ZR3802
case -1106120762:
- return BulletsShot%2==0 ? 57 : 63;
+ return BulletsShot % 2 == 0 ? 57 : 63;
// ZR3803
case -1478704292:
- return BulletsShot%2==0 ? 53 : 59;
+ return BulletsShot % 2 == 0 ? 53 : 59;
// STROMBERG
case 886810209:
- return BulletsShot%2==0 ? 85 : 84;
+ return BulletsShot % 2 == 0 ? 85 : 84;
// SLAMVAN4
case -2061049099:
- return BulletsShot%2==0 ? 76 : 78;
+ return BulletsShot % 2 == 0 ? 76 : 78;
// IMPERATOR
case 444994115:
- return BulletsShot%2==0 ? 88 : 86;
+ return BulletsShot % 2 == 0 ? 88 : 86;
// IMPALER2
case 1009171724:
- return BulletsShot%2==0 ? 63 : 64;
+ return BulletsShot % 2 == 0 ? 63 : 64;
// DOMINATOR4
case -688189648:
- return BulletsShot%2==0 ? 59 : 60;
+ return BulletsShot % 2 == 0 ? 59 : 60;
// SAVAGE
@@ -339,22 +339,22 @@ namespace RageCoop.Client
// BUZZARD
case 788747387:
- return BulletsShot%2==0 ? 28 : 23;
+ return BulletsShot % 2 == 0 ? 28 : 23;
// ANNIHL
case 837858166:
- return (int)BulletsShot%4+35;
+ return (int)BulletsShot % 4 + 35;
// HYDRA
case 970385471:
- return BulletsShot%2==0 ? 29 : 28;
+ return BulletsShot % 2 == 0 ? 29 : 28;
// STARLING
case -1700874274:
- return BulletsShot%2==0 ? 24 : 12;
+ return BulletsShot % 2 == 0 ? 24 : 12;
// RHINO
@@ -369,9 +369,9 @@ namespace RageCoop.Client
{
var vp = p.VehicleWeapon;
var type = Function.Call(Hash.GET_WEAPON_DAMAGE_TYPE, vp);
- if (vp!=VehicleWeaponHash.Invalid)
+ if (vp != VehicleWeaponHash.Invalid)
{
- return type == 3 ? false : VehicleProjectileWeapons.Contains(vp) || (type==5 && !ExplosiveBullets.Contains((uint)vp));
+ return type == 3 ? false : VehicleProjectileWeapons.Contains(vp) || (type == 5 && !ExplosiveBullets.Contains((uint)vp));
}
var w = p.Weapons.Current;
diff --git a/RageCoop.Client/WorldThread.cs b/RageCoop.Client/WorldThread.cs
index 706cbe3..1be7963 100644
--- a/RageCoop.Client/WorldThread.cs
+++ b/RageCoop.Client/WorldThread.cs
@@ -1,8 +1,6 @@
using GTA;
using GTA.Native;
using System;
-using System.Threading.Tasks;
-using System.Threading;
namespace RageCoop.Client
{
@@ -23,7 +21,8 @@ namespace RageCoop.Client
ChangeTraffic(true);
};
}
- static bool _trafficEnabled;
+
+ private static bool _trafficEnabled;
private void OnTick(object sender, EventArgs e)
{
if (Game.IsLoading || !Networking.IsOnServer)
@@ -99,7 +98,7 @@ namespace RageCoop.Client
Function.Call(Hash.SET_DISTANT_CARS_ENABLED, true);
Function.Call(Hash.DISABLE_VEHICLE_DISTANTLIGHTS, false);
}
- else if(Networking.IsOnServer)
+ else if (Networking.IsOnServer)
{
Function.Call(Hash.ADD_SCENARIO_BLOCKING_AREA, -10000.0f, -10000.0f, -1000.0f, 10000.0f, 10000.0f, 1000.0f, 0, 1, 1, 1);
Function.Call(Hash.SET_CREATE_RANDOM_COPS, false);
diff --git a/RageCoop.Server/Client.cs b/RageCoop.Server/Client.cs
index 53cdf6a..ee23108 100644
--- a/RageCoop.Server/Client.cs
+++ b/RageCoop.Server/Client.cs
@@ -28,7 +28,7 @@ namespace RageCoop.Server
///
/// Th client's IP address and port.
///
- public IPEndPoint EndPoint { get { return Connection?.RemoteEndPoint; } }
+ public IPEndPoint EndPoint => Connection?.RemoteEndPoint;
///
/// Internal(LAN) address of this client, used for NAT hole-punching
@@ -62,8 +62,8 @@ namespace RageCoop.Server
///
/// Gets or sets whether to enable automatic respawn for this client's main ped.
///
- public bool EnableAutoRespawn {
- get { return _autoRespawn; }
+ public bool EnableAutoRespawn {
+ get => _autoRespawn;
set {
BaseScript.SetAutoRespawn(this,value);
_autoRespawn=value;
@@ -78,7 +78,7 @@ namespace RageCoop.Server
///
public bool DisplayNameTag
{
- get { return _displayNameTag; }
+ get => _displayNameTag;
set
{
Server.BaseScript.SetNameTag(this,value);
diff --git a/RageCoop.Server/Networking/Server.Background.cs b/RageCoop.Server/Networking/Server.Background.cs
index f601dd9..1dbaa53 100644
--- a/RageCoop.Server/Networking/Server.Background.cs
+++ b/RageCoop.Server/Networking/Server.Background.cs
@@ -170,7 +170,7 @@ namespace RageCoop.Server
{
foreach(var c in ClientsByNetHandle.Values.ToArray())
{
- if (c.EntitiesCount > 100 && Settings.KickSpamming)
+ if (c.EntitiesCount > Settings.SpamLimit && Settings.KickSpamming)
{
c.Kick("Bye bye asshole: spamming");
API.SendChatMessage($"Asshole {c.Username} was kicked: Spamming");
diff --git a/RageCoop.Server/Networking/Server.Connections.cs b/RageCoop.Server/Networking/Server.Connections.cs
index 47cee88..8cb18dc 100644
--- a/RageCoop.Server/Networking/Server.Connections.cs
+++ b/RageCoop.Server/Networking/Server.Connections.cs
@@ -182,7 +182,7 @@ namespace RageCoop.Server
MainNetServer.SendMessage(outgoingMessage, cons, NetDeliveryMethod.ReliableOrdered, 0);
}
Entities.CleanUp(localClient);
- _worker.QueueJob(() => API.Events.InvokePlayerDisconnected(localClient));
+ QueueJob(() => API.Events.InvokePlayerDisconnected(localClient));
Logger?.Info($"Player {localClient.Username} disconnected! ID:{localClient.Player.ID}");
if (ClientsByNetHandle.ContainsKey(localClient.NetHandle)) { ClientsByNetHandle.Remove(localClient.NetHandle); }
if (ClientsByName.ContainsKey(localClient.Username.ToLower())) { ClientsByName.Remove(localClient.Username.ToLower()); }
diff --git a/RageCoop.Server/Networking/Server.EntitySync.cs b/RageCoop.Server/Networking/Server.EntitySync.cs
index 69501aa..7bc5cb5 100644
--- a/RageCoop.Server/Networking/Server.EntitySync.cs
+++ b/RageCoop.Server/Networking/Server.EntitySync.cs
@@ -14,12 +14,12 @@ namespace RageCoop.Server
{
private void PedSync(Packets.PedSync packet, Client client)
{
- _worker.QueueJob(() => Entities.Update(packet, client));
+ QueueJob(() => Entities.Update(packet, client));
bool isPlayer = packet.ID==client.Player.ID;
if (isPlayer)
{
- _worker.QueueJob(() => API.Events.InvokePlayerUpdate(client));
+ QueueJob(() => API.Events.InvokePlayerUpdate(client));
}
if (Settings.UseP2P) { return; }
@@ -49,7 +49,7 @@ namespace RageCoop.Server
}
private void VehicleSync(Packets.VehicleSync packet, Client client)
{
- _worker.QueueJob(() => Entities.Update(packet, client));
+ QueueJob(() => Entities.Update(packet, client));
bool isPlayer = packet.ID==client.Player?.LastVehicle?.ID;
diff --git a/RageCoop.Server/Networking/Server.Listener.cs b/RageCoop.Server/Networking/Server.Listener.cs
index 9fcf69c..e0bc9de 100644
--- a/RageCoop.Server/Networking/Server.Listener.cs
+++ b/RageCoop.Server/Networking/Server.Listener.cs
@@ -86,7 +86,7 @@ namespace RageCoop.Server
else if (status == NetConnectionStatus.Connected)
{
PlayerConnected(sender);
- _worker.QueueJob(() => API.Events.InvokePlayerConnected(sender));
+ QueueJob(() => API.Events.InvokePlayerConnected(sender));
Resources.SendTo(sender);
}
break;
@@ -233,7 +233,7 @@ namespace RageCoop.Server
{
Packets.CustomEvent packet = new Packets.CustomEvent();
packet.Deserialize(data);
- _worker.QueueJob(() => API.Events.InvokeCustomEventReceived(packet, sender));
+ QueueJob(() => API.Events.InvokeCustomEventReceived(packet, sender));
}
break;
default:
diff --git a/RageCoop.Server/Networking/Server.cs b/RageCoop.Server/Networking/Server.cs
index 192364f..dab5553 100644
--- a/RageCoop.Server/Networking/Server.cs
+++ b/RageCoop.Server/Networking/Server.cs
@@ -197,12 +197,12 @@ namespace RageCoop.Server
{
string[] cmdArgs = message.Split(" ");
string cmdName = cmdArgs[0].Remove(0, 1);
- _worker.QueueJob(()=>API.Events.InvokeOnCommandReceived(cmdName, cmdArgs, sender));
+ QueueJob(()=>API.Events.InvokeOnCommandReceived(cmdName, cmdArgs, sender));
return;
}
message = message.Replace("~", "");
- _worker.QueueJob(() => API.Events.InvokeOnChatMessage(message, sender));
+ QueueJob(() => API.Events.InvokeOnChatMessage(message, sender));
foreach(var c in ClientsByNetHandle.Values)
{
@@ -306,11 +306,8 @@ namespace RageCoop.Server
internal void SendFile(Stream stream, string name, Client client,int id=default, Action updateCallback = null)
{
stream.Seek(0, SeekOrigin.Begin);
- // Logger.Debug("1");
id = id ==default? NewFileID(): id ;
- // Logger.Debug("2");
var total = stream.Length;
- // Logger.Debug("3");
if (GetResponse(client, new Packets.FileTransferRequest()
{
FileLength= total,
@@ -319,8 +316,6 @@ namespace RageCoop.Server
}, ConnectionChannel.File)?.Response!=FileResponse.NeedToDownload)
{
Logger?.Info($"Skipping file transfer \"{name}\" to {client.Username}");
- // stream.Close();
- // stream.Dispose();
return;
}
Logger?.Debug($"Initiating file transfer:{name}, {total}");
@@ -361,8 +356,6 @@ namespace RageCoop.Server
{
Logger.Warning($"File trasfer to {client.Username} failed: "+name);
}
- // stream.Close();
- // stream.Dispose();
Logger?.Debug($"All file chunks sent:{name}");
InProgressFileTransfers.Remove(id);
}
diff --git a/RageCoop.Server/Properties/AssemblyInfo.cs b/RageCoop.Server/Properties/AssemblyInfo.cs
index a7151c9..cf07ed0 100644
--- a/RageCoop.Server/Properties/AssemblyInfo.cs
+++ b/RageCoop.Server/Properties/AssemblyInfo.cs
@@ -15,7 +15,7 @@ using System.Resources;
[assembly: AssemblyCulture("")]
// Version information
-[assembly: AssemblyVersion("1.5.3.130")]
-[assembly: AssemblyFileVersion("1.5.3.130")]
+[assembly: AssemblyVersion("1.5.3.137")]
+[assembly: AssemblyFileVersion("1.5.3.137")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
diff --git a/RageCoop.Server/Scripting/API.cs b/RageCoop.Server/Scripting/API.cs
index 913bbf0..aa759df 100644
--- a/RageCoop.Server/Scripting/API.cs
+++ b/RageCoop.Server/Scripting/API.cs
@@ -173,7 +173,7 @@ namespace RageCoop.Server.Scripting
///
/// All synchronized entities on this server.
///
- public ServerEntities Entities { get { return Server.Entities; } }
+ public ServerEntities Entities => Server.Entities;
#region FUNCTIONS
///
@@ -415,7 +415,7 @@ namespace RageCoop.Server.Scripting
///
/// Get a that the server is currently using, you should use to display resource-specific information.
///
- public Logger Logger { get { return Server.Logger; } }
+ public Logger Logger => Server.Logger;
///
@@ -423,7 +423,7 @@ namespace RageCoop.Server.Scripting
///
public Client Host
{
- get { return Server._hostClient; }
+ get => Server._hostClient;
set {
if (Server._hostClient != value)
{
diff --git a/RageCoop.Server/Scripting/Resources.cs b/RageCoop.Server/Scripting/Resources.cs
index 8d7e97c..d706e69 100644
--- a/RageCoop.Server/Scripting/Resources.cs
+++ b/RageCoop.Server/Scripting/Resources.cs
@@ -22,9 +22,8 @@ namespace RageCoop.Server.Scripting
Server = server;
Logger=server.Logger;
}
- private Dictionary> ClientResources=new();
- private Dictionary> ResourceStreams=new();
- private List MemStreams = new();
+ private Dictionary ClientResources=new();
+ private Dictionary ResourceStreams=new();
public void LoadAll()
{
// Packages
@@ -41,15 +40,13 @@ namespace RageCoop.Server.Scripting
if (e.Name.StartsWith("Client") && e.Name.EndsWith(".res"))
{
var stream = pkgZip.GetInputStream(e).ToMemStream();
- MemStreams.Add(stream);
- ClientResources.Add(Path.GetFileNameWithoutExtension(e.Name), () => stream);
+ ClientResources.Add(Path.GetFileNameWithoutExtension(e.Name), stream);
Logger?.Debug("Resource added: "+ Path.GetFileNameWithoutExtension(e.Name));
}
else if (e.Name.StartsWith("Server") && e.Name.EndsWith(".res"))
{
var stream = pkgZip.GetInputStream(e).ToMemStream();
- MemStreams.Add(stream);
- ResourceStreams.Add(Path.GetFileNameWithoutExtension(e.Name), () => stream);
+ ResourceStreams.Add(Path.GetFileNameWithoutExtension(e.Name), stream);
Logger?.Debug("Resource added: " + Path.GetFileNameWithoutExtension(e.Name));
}
}
@@ -91,7 +88,7 @@ namespace RageCoop.Server.Scripting
}
zip.CommitUpdate();
zip.Close();
- ClientResources.Add(Path.GetFileNameWithoutExtension(zipPath), () => File.OpenRead(zipPath));
+ ClientResources.Add(Path.GetFileNameWithoutExtension(zipPath), File.OpenRead(zipPath));
}
catch (Exception ex)
{
@@ -105,7 +102,7 @@ namespace RageCoop.Server.Scripting
{
foreach(var file in packed)
{
- ClientResources.Add(Path.GetFileNameWithoutExtension(file),()=>File.OpenRead(file));
+ ClientResources.Add(Path.GetFileNameWithoutExtension(file),File.OpenRead(file));
}
}
}
@@ -138,7 +135,7 @@ namespace RageCoop.Server.Scripting
}
foreach (var res in Directory.GetFiles(path, "*.res", SearchOption.TopDirectoryOnly))
{
- if (!ResourceStreams.TryAdd(Path.GetFileNameWithoutExtension(res),()=>File.OpenRead(res)))
+ if (!ResourceStreams.TryAdd(Path.GetFileNameWithoutExtension(res),File.OpenRead(res)))
{
Logger?.Warning($"Resource \"{res}\" cannot be loaded, ignoring...");
continue;
@@ -155,7 +152,7 @@ namespace RageCoop.Server.Scripting
continue;
}
Logger?.Info($"Loading resource: "+name);
- var r = ServerResource.LoadFrom(res.Value(),name, Path.Combine("Resources", "Temp", "Server"), dataFolder, Logger);
+ var r = ServerResource.LoadFrom(res.Value, name, Path.Combine("Resources", "Temp", "Server"), dataFolder, Logger);
LoadedResources.Add(r.Name, r);
}
catch(Exception ex)
@@ -215,7 +212,7 @@ namespace RageCoop.Server.Scripting
}
LoadedResources.Clear();
}
- foreach(var s in MemStreams)
+ foreach(var s in ResourceStreams.Values)
{
try
{
@@ -224,10 +221,22 @@ namespace RageCoop.Server.Scripting
}
catch(Exception ex)
{
- Logger?.Error("[Resources.CloseMemStream]",ex);
+ Logger?.Error("[Resources.CloseStream]",ex);
}
}
- }
+ foreach (var s in ClientResources.Values)
+ {
+ try
+ {
+ s.Close();
+ s.Dispose();
+ }
+ catch (Exception ex)
+ {
+ Logger?.Error("[Resources.CloseStream]", ex);
+ }
+ }
+ }
public void SendTo(Client client)
{
Task.Run(() =>
@@ -239,7 +248,7 @@ namespace RageCoop.Server.Scripting
foreach (var rs in ClientResources)
{
Logger?.Debug(rs.Key);
- Server.SendFile(rs.Value(),rs.Key+".res", client);
+ Server.SendFile(rs.Value,rs.Key+".res", client);
}
Logger?.Info($"Resources sent to:{client.Username}");
diff --git a/RageCoop.Server/Scripting/ServerObject.cs b/RageCoop.Server/Scripting/ServerObject.cs
index f446cdd..743d375 100644
--- a/RageCoop.Server/Scripting/ServerObject.cs
+++ b/RageCoop.Server/Scripting/ServerObject.cs
@@ -70,7 +70,7 @@ namespace RageCoop.Server.Scripting
///
public virtual Vector3 Position
{
- get { return _pos; }
+ get => _pos;
set { _pos=value; Owner.SendNativeCall(Hash.SET_ENTITY_COORDS_NO_OFFSET, Handle, value.X, value.Y, value.Z,1, 1,1 ); }
}
internal Vector3 _pos;
@@ -80,7 +80,7 @@ namespace RageCoop.Server.Scripting
///
public virtual Vector3 Rotation
{
- get { return _rot; }
+ get => _rot;
set { _rot=value; Owner.SendNativeCall(Hash.SET_ENTITY_ROTATION, Handle, value.X, value.Y, value.Z ,2,1); }
}
internal Vector3 _rot;
@@ -137,7 +137,7 @@ namespace RageCoop.Server.Scripting
///
public override Vector3 Position
{
- get { return _pos; }
+ get => _pos;
set { _pos=value; Server.API.SendNativeCall(null, Hash.SET_ENTITY_COORDS_NO_OFFSET, Handle, value.X, value.Y, value.Z, 1, 1, 1); }
}
@@ -146,7 +146,7 @@ namespace RageCoop.Server.Scripting
///
public override Vector3 Rotation
{
- get { return _rot; }
+ get => _rot;
set { _rot=value; Server.API.SendNativeCall(null, Hash.SET_ENTITY_ROTATION, Handle, value.X, value.Y, value.Z, 2, 1); }
}
@@ -215,7 +215,7 @@ namespace RageCoop.Server.Scripting
///
public override Vector3 Rotation
{
- get { return _quat.ToEulerAngles().ToDegree(); }
+ get => _quat.ToEulerAngles().ToDegree();
set { Owner.SendNativeCall(Hash.SET_ENTITY_ROTATION, Handle ,value.X, value.Y ,value.Z); }
}
@@ -225,7 +225,7 @@ namespace RageCoop.Server.Scripting
///
public Quaternion Quaternion
{
- get { return _quat; }
+ get => _quat;
set { _quat = value ;Owner.SendNativeCall(Hash.SET_ENTITY_QUATERNION, Handle, value.X, value.Y, value.Z, value.W); }
}
}
@@ -264,7 +264,7 @@ namespace RageCoop.Server.Scripting
/// Color of this blip
///
public BlipColor Color {
- get { return _color; }
+ get => _color;
set { _color=value; Update(); }
}
@@ -273,7 +273,7 @@ namespace RageCoop.Server.Scripting
/// Sprite of this blip
///
public BlipSprite Sprite {
- get { return _sprite; }
+ get => _sprite;
set { _sprite=value; Update();}
}
@@ -283,7 +283,7 @@ namespace RageCoop.Server.Scripting
///
public float Scale
{
- get { return _scale; }
+ get => _scale;
set { _scale=value;Update(); }
}
@@ -293,7 +293,7 @@ namespace RageCoop.Server.Scripting
///
public Vector3 Position
{
- get { return _pos; }
+ get => _pos;
set { _pos=value; Update(); }
}
@@ -303,7 +303,7 @@ namespace RageCoop.Server.Scripting
///
public int Rotation
{
- get { return _rot; }
+ get => _rot;
set { _rot=value; Update(); }
}
@@ -313,7 +313,7 @@ namespace RageCoop.Server.Scripting
///
public string Name
{
- get { return _name;}
+ get => _name;
set { _name=value; Update(); }
}
@@ -372,7 +372,7 @@ namespace RageCoop.Server.Scripting
///
public BlipColor Color
{
- get { return _color; }
+ get => _color;
set { _color=value; Update(); }
}
@@ -382,7 +382,7 @@ namespace RageCoop.Server.Scripting
///
public BlipSprite Sprite
{
- get { return _sprite; }
+ get => _sprite;
set { _sprite=value; Update(); }
}
@@ -392,7 +392,7 @@ namespace RageCoop.Server.Scripting
///
public float Scale
{
- get { return _scale; }
+ get => _scale;
set { _scale=value; Update(); }
}
diff --git a/RageCoop.Server/Scripting/ServerScript.cs b/RageCoop.Server/Scripting/ServerScript.cs
index 609f665..3e700c9 100644
--- a/RageCoop.Server/Scripting/ServerScript.cs
+++ b/RageCoop.Server/Scripting/ServerScript.cs
@@ -30,12 +30,12 @@ namespace RageCoop.Server.Scripting
///
/// Get the that the script belongs to.
///
- public ResourceFile CurrentFile { get; internal set; }
+ public ResourceFile CurrentFile { get; internal set; }
///
/// Eqivalent of in
///
- public Core.Logger Logger { get { return CurrentResource.Logger; } }
+ public Core.Logger Logger => CurrentResource.Logger;
}
///
/// Decorate your method with this attribute and use or to register commands.
diff --git a/RageCoop.Server/Settings.cs b/RageCoop.Server/Settings.cs
index e3b6c80..687111a 100644
--- a/RageCoop.Server/Settings.cs
+++ b/RageCoop.Server/Settings.cs
@@ -119,5 +119,10 @@
/// Kick spamming assholes
///
public bool KickSpamming { get; set; } = true;
+
+ ///
+ /// Player that spawned entities more than this amount will be kicked if is enabled.
+ ///
+ public int SpamLimit { get;set; } = 100;
}
}