Optimize imports

This commit is contained in:
Sardelka9515
2023-02-13 17:51:18 +08:00
parent ac07edfe68
commit f555fef48d
22 changed files with 77 additions and 81 deletions

View File

@ -31,10 +31,10 @@ namespace RageCoop.Client
internal static Settings Settings = null; internal static Settings Settings = null;
internal static Chat MainChat = null; internal static Chat MainChat = null;
internal static Stopwatch Counter = new Stopwatch(); internal static Stopwatch Counter = new Stopwatch();
internal static Logger Logger = null; internal static Logger Log = null;
internal static ulong Ticked = 0; internal static ulong Ticked = 0;
internal static Vector3 PlayerPosition; internal static Vector3 PlayerPosition;
internal static Resources Resources = null; internal static Resources MainRes = null;
public static Ped P; public static Ped P;
public static float FPS; public static float FPS;
@ -59,7 +59,7 @@ namespace RageCoop.Client
Util.SaveSettings(); Util.SaveSettings();
} }
Logger = new Logger() Log = new Logger()
{ {
Writers = new List<StreamWriter> { CoreUtils.OpenWriter(LogPath) }, Writers = new List<StreamWriter> { CoreUtils.OpenWriter(LogPath) },
#if DEBUG #if DEBUG
@ -68,7 +68,7 @@ namespace RageCoop.Client
LogLevel = Settings.LogLevel, LogLevel = Settings.LogLevel,
#endif #endif
}; };
Logger.OnFlush += (line, formatted) => Log.OnFlush += (line, formatted) =>
{ {
switch (line.LogLevel) switch (line.LogLevel)
{ {
@ -102,14 +102,14 @@ namespace RageCoop.Client
WorldThread.DoQueuedActions(); WorldThread.DoQueuedActions();
if (IsUnloading) if (IsUnloading)
{ {
Logger.Dispose(); Log.Dispose();
Networking.Peer?.Dispose(); Networking.Peer?.Dispose();
ThreadManager.OnUnload(); ThreadManager.OnUnload();
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Error(ex); Log.Error(ex);
} }
} }
protected override void OnStart() protected override void OnStart()
@ -121,11 +121,11 @@ namespace RageCoop.Client
throw new NotSupportedException("Please update your GTA5 to v1.0.1290 or newer!"); throw new NotSupportedException("Please update your GTA5 to v1.0.1290 or newer!");
} }
Resources = new Resources(); MainRes = new Resources();
Logger.Info( Log.Info(
$"Main script initialized"); $"Main script initialized");
BaseScript.OnStart(); BaseScript.OnStart();
@ -160,7 +160,7 @@ namespace RageCoop.Client
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Error(ex); Log.Error(ex);
} }
@ -198,7 +198,7 @@ namespace RageCoop.Client
{ {
P.Health = 1; P.Health = 1;
Game.Player.WantedLevel = 0; Game.Player.WantedLevel = 0;
Logger.Debug("Player died."); Log.Debug("Player died.");
API.Events.InvokePlayerDied(); API.Events.InvokePlayerDied();
} }
@ -387,14 +387,14 @@ namespace RageCoop.Client
Notification.Show("~g~Connected!"); Notification.Show("~g~Connected!");
}); });
Logger.Info(">> Connected <<"); Log.Info(">> Connected <<");
} }
public static void CleanUp(string reason) public static void CleanUp(string reason)
{ {
if (reason != "Abort") if (reason != "Abort")
{ {
Logger.Info($">> Disconnected << reason: {reason}"); Log.Info($">> Disconnected << reason: {reason}");
API.QueueAction(() => { Notification.Show("~r~Disconnected: " + reason); }); API.QueueAction(() => { Notification.Show("~r~Disconnected: " + reason); });
} }
@ -412,7 +412,7 @@ namespace RageCoop.Client
Call(SET_ENABLE_VEHICLE_SLIPSTREAMING, false); Call(SET_ENABLE_VEHICLE_SLIPSTREAMING, false);
CoopMenu.DisconnectedMenuSetting(); CoopMenu.DisconnectedMenuSetting();
LocalPlayerID = default; LocalPlayerID = default;
Resources.Unload(); MainRes.Unload();
}); });
Memory.RestorePatches(); Memory.RestorePatches();
#if CEF #if CEF

View File

@ -62,7 +62,7 @@ namespace RageCoop.Client
} }
catch (Exception ex) catch (Exception ex)
{ {
Main.Logger.Error(ex); Log.Error(ex);
} }
}; };
Menu.Add(SimulatedLatencyItem); Menu.Add(SimulatedLatencyItem);

View File

@ -59,7 +59,7 @@ namespace RageCoop.Client.Menus
var realUrl = Main.Settings.MasterServer; var realUrl = Main.Settings.MasterServer;
serverList = null; serverList = null;
try { serverList = JsonDeserialize<List<ServerInfo>>(DownloadString(realUrl)); } try { serverList = JsonDeserialize<List<ServerInfo>>(DownloadString(realUrl)); }
catch (Exception ex) { Main.Logger.Error(ex); } catch (Exception ex) { Log.Error(ex); }
// Need to be processed in main thread // Need to be processed in main thread
API.QueueAction(() => API.QueueAction(() =>

View File

@ -33,7 +33,7 @@ namespace RageCoop.Client
var packet = new Packets.FileTransferComplete(); var packet = new Packets.FileTransferComplete();
packet.Deserialize(data); packet.Deserialize(data);
Main.Logger.Debug($"Finalizing download:{packet.ID}"); Log.Debug($"Finalizing download:{packet.ID}");
Complete(packet.ID); Complete(packet.ID);
// Inform the server that the download is completed // Inform the server that the download is completed
@ -48,13 +48,13 @@ namespace RageCoop.Client
try try
{ {
Directory.CreateDirectory(ResourceFolder); Directory.CreateDirectory(ResourceFolder);
Main.Resources.Load(ResourceFolder, _resources.ToArray()); MainRes.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) catch (Exception ex)
{ {
Main.Logger.Error("Error occurred when loading server resource"); Log.Error("Error occurred when loading server resource");
Main.Logger.Error(ex); Log.Error(ex);
return new Packets.FileTransferResponse { ID = 0, Response = FileResponse.LoadFailed }; return new Packets.FileTransferResponse { ID = 0, Response = FileResponse.LoadFailed };
} }
}); });
@ -68,13 +68,13 @@ namespace RageCoop.Client
public static bool AddFile(int id, string name, long length) public static bool AddFile(int id, string name, long length)
{ {
var path = $"{ResourceFolder}\\{name}"; var path = $"{ResourceFolder}\\{name}";
Main.Logger.Debug($"Downloading file to {path} , id:{id}"); Log.Debug($"Downloading file to {path} , id:{id}");
if (!Directory.Exists(Directory.GetParent(path).FullName)) if (!Directory.Exists(Directory.GetParent(path).FullName))
Directory.CreateDirectory(Directory.GetParent(path).FullName); Directory.CreateDirectory(Directory.GetParent(path).FullName);
if (FileAlreadyExists(ResourceFolder, name, length)) if (FileAlreadyExists(ResourceFolder, name, length))
{ {
Main.Logger.Debug($"File already exists! canceling download:{name}"); Log.Debug($"File already exists! canceling download:{name}");
DownloadCompleted?.Invoke(null, Path.Combine(ResourceFolder, name)); DownloadCompleted?.Invoke(null, Path.Combine(ResourceFolder, name));
return false; return false;
} }
@ -82,7 +82,7 @@ namespace RageCoop.Client
/* /*
if (!name.EndsWith(".zip")) if (!name.EndsWith(".zip"))
{ {
Main.Logger.Error($"File download blocked! [{name}]"); Log.Error($"File download blocked! [{name}]");
return false; return false;
} }
*/ */
@ -114,7 +114,6 @@ namespace RageCoop.Client
if (File.Exists(filePath)) if (File.Exists(filePath))
{ {
if (new FileInfo(filePath).Length == length) return true; if (new FileInfo(filePath).Length == length) return true;
// Delete the file because the length is wrong (maybe the file was updated) // Delete the file because the length is wrong (maybe the file was updated)
File.Delete(filePath); File.Delete(filePath);
} }
@ -129,7 +128,7 @@ namespace RageCoop.Client
if (InProgressDownloads.TryGetValue(id, out var file)) if (InProgressDownloads.TryGetValue(id, out var file))
file.Stream.Write(chunk, 0, chunk.Length); file.Stream.Write(chunk, 0, chunk.Length);
else else
Main.Logger.Trace($"Received unhandled file chunk:{id}"); Log.Trace($"Received unhandled file chunk:{id}");
} }
} }
@ -139,12 +138,12 @@ namespace RageCoop.Client
{ {
InProgressDownloads.Remove(id); InProgressDownloads.Remove(id);
f.Dispose(); f.Dispose();
Main.Logger.Info($"Download finished:{f.FileName}"); Log.Info($"Download finished:{f.FileName}");
DownloadCompleted?.Invoke(null, Path.Combine(ResourceFolder, f.FileName)); DownloadCompleted?.Invoke(null, Path.Combine(ResourceFolder, f.FileName));
} }
else else
{ {
Main.Logger.Error($"Download not found! {id}"); Log.Error($"Download not found! {id}");
} }
} }

View File

@ -27,7 +27,7 @@ namespace RageCoop.Client
if (p.InternalEndPoint != null && p.ExternalEndPoint != null && (p.Connection == null || if (p.InternalEndPoint != null && p.ExternalEndPoint != null && (p.Connection == null ||
p.Connection.Status == NetConnectionStatus.Disconnected)) p.Connection.Status == NetConnectionStatus.Disconnected))
{ {
Main.Logger.Trace( Log.Trace(
$"Sending HolePunch message to {p.InternalEndPoint},{p.ExternalEndPoint}. {p.Username}:{p.ID}"); $"Sending HolePunch message to {p.InternalEndPoint},{p.ExternalEndPoint}. {p.Username}:{p.ID}");
var msg = Networking.Peer.CreateMessage(); var msg = Networking.Peer.CreateMessage();
new Packets.HolePunch new Packets.HolePunch
@ -41,7 +41,7 @@ namespace RageCoop.Client
} }
catch (Exception ex) catch (Exception ex)
{ {
Main.Logger.Error(ex); Log.Error(ex);
} }
} }
@ -49,31 +49,31 @@ namespace RageCoop.Client
{ {
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"); Log.Debug($"{p.TargetID},{player.Username} added to HolePunch target");
player.InternalEndPoint = CoreUtils.StringToEndPoint(p.TargetInternal); player.InternalEndPoint = CoreUtils.StringToEndPoint(p.TargetInternal);
player.ExternalEndPoint = CoreUtils.StringToEndPoint(p.TargetExternal); player.ExternalEndPoint = CoreUtils.StringToEndPoint(p.TargetExternal);
player.ConnectWhenPunched = p.Connect; player.ConnectWhenPunched = p.Connect;
} }
else else
{ {
Main.Logger.Warning("No player with specified TargetID found for hole punching:" + p.TargetID); Log.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}"); Log.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); Log.Debug("Puncher identified as: " + puncher.Username);
puncher.HolePunchStatus = (byte)(p.Status + 1); puncher.HolePunchStatus = (byte)(p.Status + 1);
if (p.Status >= 3) if (p.Status >= 3)
{ {
Main.Logger.Debug("HolePunch sucess: " + from + ", " + puncher.ID); Log.Debug("HolePunch sucess: " + from + ", " + puncher.ID);
if (puncher.ConnectWhenPunched && (puncher.Connection == null || if (puncher.ConnectWhenPunched && (puncher.Connection == null ||
puncher.Connection.Status == NetConnectionStatus.Disconnected)) puncher.Connection.Status == NetConnectionStatus.Disconnected))
{ {
Main.Logger.Debug("Connecting to peer: " + from); Log.Debug("Connecting to peer: " + from);
var msg = Networking.Peer.CreateMessage(); var msg = Networking.Peer.CreateMessage();
new Packets.P2PConnect { ID = Main.LocalPlayerID }.Pack(msg); new Packets.P2PConnect { ID = Main.LocalPlayerID }.Pack(msg);
puncher.Connection = Networking.Peer.Connect(from, msg); puncher.Connection = Networking.Peer.Connect(from, msg);

View File

@ -30,7 +30,7 @@ namespace RageCoop.Client
static Networking() static Networking()
{ {
Security = new Security(Main.Logger); Security = new Security(Log);
} }
public static float Latency => ServerConnection.AverageRoundtripTime / 2; public static float Latency => ServerConnection.AverageRoundtripTime / 2;
@ -113,7 +113,7 @@ namespace RageCoop.Client
} }
catch (Exception ex) catch (Exception ex)
{ {
Main.Logger.Error(ex); Log.Error(ex);
} }
}; };
API.QueueAction(() => { Notification.Show("~y~Trying to connect..."); }); API.QueueAction(() => { Notification.Show("~y~Trying to connect..."); });
@ -149,7 +149,7 @@ namespace RageCoop.Client
} }
catch (Exception ex) catch (Exception ex)
{ {
Main.Logger.Error("Cannot connect to server: ", ex); Log.Error("Cannot connect to server: ", ex);
API.QueueAction(() => Notification.Show("Cannot connect to server: " + ex.Message)); API.QueueAction(() => Notification.Show("Cannot connect to server: " + ex.Message));
} }
@ -185,7 +185,7 @@ namespace RageCoop.Client
}; };
PlayerList.SetPlayer(packet.PedID, packet.Username); PlayerList.SetPlayer(packet.PedID, packet.Username);
Main.Logger.Debug($"player connected:{p.Username}"); Log.Debug($"player connected:{p.Username}");
API.QueueAction(() => API.QueueAction(() =>
Notification.Show($"~h~{p.Username}~h~ connected.")); Notification.Show($"~h~{p.Username}~h~ connected."));
} }

View File

@ -50,11 +50,11 @@ namespace RageCoop.Client
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"); Log.Debug($"Direct connection to {player.Username} established");
} }
else else
{ {
Main.Logger.Info( Log.Info(
$"Unidentified peer connection from {message.SenderEndPoint} was rejected."); $"Unidentified peer connection from {message.SenderEndPoint} was rejected.");
message.SenderConnection.Disconnect("eat poop"); message.SenderConnection.Disconnect("eat poop");
} }
@ -104,7 +104,7 @@ namespace RageCoop.Client
} }
else else
{ {
Main.Logger.Debug("Did not find a request handler of type: " + realType); Log.Debug("Did not find a request handler of type: " + realType);
} }
break; break;
@ -123,8 +123,8 @@ namespace RageCoop.Client
Notification.Show($"~r~~h~Packet Error {ex.Message}"); Notification.Show($"~r~~h~Packet Error {ex.Message}");
return true; return true;
}); });
Main.Logger.Error($"[{packetType}] {ex.Message}"); Log.Error($"[{packetType}] {ex.Message}");
Main.Logger.Error(ex); Log.Error(ex);
Peer.Shutdown($"Packet Error [{packetType}]"); Peer.Shutdown($"Packet Error [{packetType}]");
} }
@ -156,7 +156,7 @@ namespace RageCoop.Client
case NetIncomingMessageType.ErrorMessage: case NetIncomingMessageType.ErrorMessage:
case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.VerboseDebugMessage:
Main.Logger.Trace(message.ReadString()); Log.Trace(message.ReadString());
break; break;
} }
@ -277,7 +277,7 @@ namespace RageCoop.Client
{ {
var c = EntityPool.GetPedByID(packet.ID); var c = EntityPool.GetPedByID(packet.ID);
if (c == null) if (c == null)
// Main.Logger.Debug($"Creating character for incoming sync:{packet.ID}"); // Log.Debug($"Creating character for incoming sync:{packet.ID}");
EntityPool.ThreadSafe.Add(c = new SyncedPed(packet.ID)); EntityPool.ThreadSafe.Add(c = new SyncedPed(packet.ID));
var flags = packet.Flags; var flags = packet.Flags;
c.ID = packet.ID; c.ID = packet.ID;
@ -360,7 +360,7 @@ namespace RageCoop.Client
if (p == null) if (p == null)
{ {
if (packet.Flags.HasProjDataFlag(ProjectileDataFlags.Exploded)) return; if (packet.Flags.HasProjDataFlag(ProjectileDataFlags.Exploded)) return;
// Main.Logger.Debug($"Creating new projectile: {(WeaponHash)packet.WeaponHash}"); // Log.Debug($"Creating new projectile: {(WeaponHash)packet.WeaponHash}");
EntityPool.ThreadSafe.Add(p = new SyncedProjectile(packet.ID)); EntityPool.ThreadSafe.Add(p = new SyncedProjectile(packet.ID));
} }

View File

@ -47,7 +47,7 @@ namespace RageCoop.Client
var veh = ped.CurrentVehicle?.GetSyncEntity() ?? var veh = ped.CurrentVehicle?.GetSyncEntity() ??
ped.VehicleTryingToEnter?.GetSyncEntity() ?? ped.LastVehicle?.GetSyncEntity(); ped.VehicleTryingToEnter?.GetSyncEntity() ?? ped.LastVehicle?.GetSyncEntity();
p.VehicleID = veh?.ID ?? 0; p.VehicleID = veh?.ID ?? 0;
if (p.VehicleID == 0) Main.Logger.Error("Invalid vehicle"); if (p.VehicleID == 0) Log.Error("Invalid vehicle");
if (p.Speed == 5) if (p.Speed == 5)
p.Seat = ped.GetSeatTryingToEnter(); p.Seat = ped.GetSeatTryingToEnter();
else else

View File

@ -58,7 +58,7 @@ namespace RageCoop.Client
public static void SetPlayer(int id, string username, float latency = 0) public static void SetPlayer(int id, string username, float latency = 0)
{ {
Main.Logger.Debug($"{id},{username},{latency}"); Log.Debug($"{id},{username},{latency}");
if (Players.TryGetValue(id, out var p)) if (Players.TryGetValue(id, out var p))
{ {
p.Username = username; p.Username = username;

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<NoAotCompile>false</NoAotCompile> <NoAotCompile>true</NoAotCompile>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch> <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>

View File

@ -76,7 +76,7 @@ namespace RageCoop.Client.Scripting
} }
catch (Exception ex) catch (Exception ex)
{ {
Main.Logger.Error(ex); Log.Error(ex);
SetLastResult(ex.ToString()); SetLastResult(ex.ToString());
return 0; return 0;
} }

View File

@ -168,7 +168,7 @@ namespace RageCoop.Client.Scripting
{ {
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()); // Log.Debug($"CustomEvent:\n"+args.Args.DumpWithType());
if (CustomEventHandlers.TryGetValue(p.Hash, out var handlers)) if (CustomEventHandlers.TryGetValue(p.Hash, out var handlers))
handlers.ForEach(x => { x.Invoke(args); }); handlers.ForEach(x => { x.Invoke(args); });
@ -400,7 +400,7 @@ namespace RageCoop.Client.Scripting
[Remoting] [Remoting]
public static ClientResource GetResource(string name) public static ClientResource GetResource(string name)
{ {
if (Main.Resources.LoadedResources.TryGetValue(name, out var resource)) if (MainRes.LoadedResources.TryGetValue(name, out var resource))
return resource; return resource;
return null; return null;

View File

@ -34,7 +34,7 @@ namespace RageCoop.Client.Scripting
public Resources() public Resources()
{ {
Logger = Main.Logger; Logger = Log;
} }
private Logger Logger { get; } private Logger Logger { get; }
@ -52,20 +52,18 @@ namespace RageCoop.Client.Scripting
Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories).Where(x => x.CanBeIgnored()) Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories).Where(x => x.CanBeIgnored())
.ForEach(File.Delete); .ForEach(File.Delete);
// TODO Core.ScheduleLoad()... // TODO: Core.ScheduleLoad()...
} }
public void Unload() public void Unload()
{ {
// TODO Core.ScheduleUnload()... // TODO: Core.ScheduleUnload()...
} }
private ClientResource Unpack(string zipPath, string dataFolderRoot) private ClientResource Unpack(string zipPath, string dataFolderRoot)
{ {
var r = new ClientResource var r = new ClientResource
{ {
Logger = Logger,
Scripts = new List<ClientScript>(),
Name = Path.GetFileNameWithoutExtension(zipPath), Name = Path.GetFileNameWithoutExtension(zipPath),
DataFolder = Path.Combine(dataFolderRoot, Path.GetFileNameWithoutExtension(zipPath)), DataFolder = Path.Combine(dataFolderRoot, Path.GetFileNameWithoutExtension(zipPath)),
ScriptsDirectory = Path.Combine(TempPath, Path.GetFileNameWithoutExtension(zipPath)) ScriptsDirectory = Path.Combine(TempPath, Path.GetFileNameWithoutExtension(zipPath))
@ -86,7 +84,6 @@ namespace RageCoop.Client.Scripting
IsDirectory = true, IsDirectory = true,
Name = dir.Substring(scriptsDir.Length + 1).Replace('\\', '/') Name = dir.Substring(scriptsDir.Length + 1).Replace('\\', '/')
}); });
var assemblies = new Dictionary<ResourceFile, Assembly>();
foreach (var file in Directory.GetFiles(scriptsDir, "*", SearchOption.AllDirectories)) foreach (var file in Directory.GetFiles(scriptsDir, "*", SearchOption.AllDirectories))
{ {
if (Path.GetFileName(file).CanBeIgnored()) if (Path.GetFileName(file).CanBeIgnored())
@ -105,9 +102,8 @@ namespace RageCoop.Client.Scripting
} }
var relativeName = file.Substring(scriptsDir.Length + 1).Replace('\\', '/'); var relativeName = file.Substring(scriptsDir.Length + 1).Replace('\\', '/');
var rfile = new ResourceFile var rfile = new ClientFile
{ {
GetStream = () => { return new FileStream(file, FileMode.Open, FileAccess.Read); },
IsDirectory = false, IsDirectory = false,
Name = relativeName Name = relativeName
}; };

View File

@ -3,6 +3,7 @@ global using GTA.Native;
global using static GTA.Native.Function; global using static GTA.Native.Function;
global using static GTA.Native.Hash; global using static GTA.Native.Hash;
global using static RageCoop.Client.Shared; global using static RageCoop.Client.Shared;
global using static RageCoop.Client.Main;
global using Console = GTA.Console; global using Console = GTA.Console;
global using static RageCoop.Core.Shared; global using static RageCoop.Core.Shared;
using System.IO; using System.IO;

View File

@ -175,7 +175,7 @@ namespace RageCoop.Client
{ {
if (MainPed.Exists()) if (MainPed.Exists())
{ {
// Main.Logger.Debug($"Removing ped {ID}. Reason:CreateCharacter"); // Log.Debug($"Removing ped {ID}. Reason:CreateCharacter");
MainPed.Kill(); MainPed.Kill();
MainPed.MarkAsNoLongerNeeded(); MainPed.MarkAsNoLongerNeeded();
MainPed.Delete(); MainPed.Delete();

View File

@ -102,11 +102,11 @@ namespace RageCoop.Client
var player = GetPedByID(Main.LocalPlayerID); var player = GetPedByID(Main.LocalPlayerID);
if (player == null) if (player == null)
{ {
Main.Logger.Debug($"Creating SyncEntity for player, handle:{p.Handle}"); Log.Debug($"Creating SyncEntity for player, handle:{p.Handle}");
var c = new SyncedPed(p); var c = new SyncedPed(p);
Main.LocalPlayerID = c.OwnerID = c.ID; Main.LocalPlayerID = c.OwnerID = c.ID;
Add(c); Add(c);
Main.Logger.Debug($"Local player ID is:{c.ID}"); Log.Debug($"Local player ID is:{c.ID}");
PlayerList.SetPlayer(c.ID, Main.Settings.Username); PlayerList.SetPlayer(c.ID, Main.Settings.Username);
return true; return true;
} }
@ -155,7 +155,7 @@ namespace RageCoop.Client
if (p != null) if (p != null)
{ {
if (PedsByHandle.ContainsKey(p.Handle)) PedsByHandle.Remove(p.Handle); if (PedsByHandle.ContainsKey(p.Handle)) PedsByHandle.Remove(p.Handle);
// Main.Logger.Debug($"Removing ped {c.ID}. Reason:{reason}"); // Log.Debug($"Removing ped {c.ID}. Reason:{reason}");
p.AttachedBlip?.Delete(); p.AttachedBlip?.Delete();
p.Kill(); p.Kill();
p.Model.MarkAsNoLongerNeeded(); p.Model.MarkAsNoLongerNeeded();
@ -208,7 +208,7 @@ namespace RageCoop.Client
if (veh != null) if (veh != null)
{ {
if (VehiclesByHandle.ContainsKey(veh.Handle)) VehiclesByHandle.Remove(veh.Handle); if (VehiclesByHandle.ContainsKey(veh.Handle)) VehiclesByHandle.Remove(veh.Handle);
// Main.Logger.Debug($"Removing vehicle {v.ID}. Reason:{reason}"); // Log.Debug($"Removing vehicle {v.ID}. Reason:{reason}");
veh.AttachedBlip?.Delete(); veh.AttachedBlip?.Delete();
veh.Model.MarkAsNoLongerNeeded(); veh.Model.MarkAsNoLongerNeeded();
veh.MarkAsNoLongerNeeded(); veh.MarkAsNoLongerNeeded();
@ -255,7 +255,7 @@ namespace RageCoop.Client
if (p != null) if (p != null)
{ {
if (ProjectilesByHandle.ContainsKey(p.Handle)) ProjectilesByHandle.Remove(p.Handle); if (ProjectilesByHandle.ContainsKey(p.Handle)) ProjectilesByHandle.Remove(p.Handle);
Main.Logger.Debug($"Removing projectile {sp.ID}. Reason:{reason}"); Log.Debug($"Removing projectile {sp.ID}. Reason:{reason}");
p.Explode(); p.Explode();
} }
@ -364,7 +364,7 @@ namespace RageCoop.Client
continue; continue;
} }
// Main.Logger.Trace($"Creating SyncEntity for ped, handle:{p.Handle}"); // Log.Trace($"Creating SyncEntity for ped, handle:{p.Handle}");
c = new SyncedPed((Ped)Entity.FromHandle(p)); c = new SyncedPed((Ped)Entity.FromHandle(p));
Add(c); Add(c);
@ -441,7 +441,7 @@ namespace RageCoop.Client
continue; continue;
} }
} }
// Main.Logger.Debug($"Creating SyncEntity for vehicle, handle:{veh.Handle}"); // Log.Debug($"Creating SyncEntity for vehicle, handle:{veh.Handle}");
Add(new SyncedVehicle(cveh)); Add(new SyncedVehicle(cveh));
} }

View File

@ -74,7 +74,7 @@ namespace RageCoop.Client
{ {
return; return;
// p = Game.Player.Character; // p = Game.Player.Character;
// Main.Logger.Warning("Failed to find owner for bullet"); // Log.Warning("Failed to find owner for bullet");
} }
var damage = (int)p.GetWeaponDamage(weaponHash); var damage = (int)p.GetWeaponDamage(weaponHash);

View File

@ -40,15 +40,15 @@ namespace RageCoop.Client
catch (ThreadInterruptedException) { } catch (ThreadInterruptedException) { }
catch (Exception ex) catch (Exception ex)
{ {
Main.Logger.Error($"Unhandled exception caught in thread {Environment.CurrentManagedThreadId}", ex); Log.Error($"Unhandled exception caught in thread {Environment.CurrentManagedThreadId}", ex);
} }
finally finally
{ {
Main.Logger.Debug($"Thread stopped: " + Environment.CurrentManagedThreadId); Log.Debug($"Thread stopped: " + Environment.CurrentManagedThreadId);
} }
}); });
created.Name = name; created.Name = name;
Main.Logger.Debug($"Thread created: {name}, id: {created.ManagedThreadId}"); Log.Debug($"Thread created: {name}, id: {created.ManagedThreadId}");
_threads.Add(created); _threads.Add(created);
if (startNow) created.Start(); if (startNow) created.Start();
return created; return created;
@ -63,7 +63,7 @@ namespace RageCoop.Client
{ {
if (thread.IsAlive) if (thread.IsAlive)
{ {
Main.Logger.Debug($"Waiting for thread {thread.ManagedThreadId} to stop"); Log.Debug($"Waiting for thread {thread.ManagedThreadId} to stop");
// thread.Interrupt(); PlatformNotSupportedException ? // thread.Interrupt(); PlatformNotSupportedException ?
thread.Join(); thread.Join();
} }

View File

@ -309,7 +309,7 @@ namespace RageCoop.Client
case WeaponHash.MG: case WeaponHash.MG:
return new string[2] { "weapons@machinegun@mg_str", "reload_aim" }; return new string[2] { "weapons@machinegun@mg_str", "reload_aim" };
default: default:
Main.Logger.Warning( Log.Warning(
$"~r~Reloading failed! Weapon ~g~[{ped.Weapons.Current.Hash}]~r~ could not be found!"); $"~r~Reloading failed! Weapon ~g~[{ped.Weapons.Current.Hash}]~r~ could not be found!");
return null; return null;
} }

View File

@ -111,7 +111,7 @@ namespace RageCoop.Client
} }
catch (Exception ex) catch (Exception ex)
{ {
Main.Logger?.Error(ex); Log?.Error(ex);
File.WriteAllText(path, JsonSerialize(settings = new Settings())); File.WriteAllText(path, JsonSerialize(settings = new Settings()));
} }
@ -131,7 +131,7 @@ namespace RageCoop.Client
} }
catch (Exception ex) catch (Exception ex)
{ {
Main.Logger?.Error(ex); Log?.Error(ex);
return false; return false;
} }
} }

View File

@ -34,7 +34,7 @@ namespace RageCoop.Client
if (File.Exists(WeaponFixDataPath)) if (File.Exists(WeaponFixDataPath))
WeaponFix = JsonDeserialize<WeaponFix>(File.ReadAllText(WeaponFixDataPath)); WeaponFix = JsonDeserialize<WeaponFix>(File.ReadAllText(WeaponFixDataPath));
else else
Main.Logger.Warning("Weapon fix data not found"); Log.Warning("Weapon fix data not found");
} }
public static void DumpWeaponFix(string path) public static void DumpWeaponFix(string path)

View File

@ -50,7 +50,7 @@ namespace RageCoop.Client
} }
catch (Exception ex) catch (Exception ex)
{ {
Main.Logger.Error(ex); Log.Error(ex);
} }
if (!Networking.IsOnServer) return; if (!Networking.IsOnServer) return;
@ -139,7 +139,7 @@ namespace RageCoop.Client
if (c == null || (c.IsLocal && ped.Handle != Game.Player.Character.Handle && if (c == null || (c.IsLocal && ped.Handle != Game.Player.Character.Handle &&
ped.PopulationType != EntityPopulationType.Mission)) ped.PopulationType != EntityPopulationType.Mission))
{ {
Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic"); Log.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic");
ped.CurrentVehicle?.Delete(); ped.CurrentVehicle?.Delete();
ped.Kill(); ped.Kill();
ped.Delete(); ped.Delete();
@ -154,7 +154,7 @@ namespace RageCoop.Client
// Don't delete player's vehicle // Don't delete player's vehicle
continue; continue;
if (v == null || (v.IsLocal && veh.PopulationType != EntityPopulationType.Mission)) if (v == null || (v.IsLocal && veh.PopulationType != EntityPopulationType.Mission))
// Main.Logger.Debug($"Removing Vehicle {veh.Handle}. Reason:ClearTraffic"); // Log.Debug($"Removing Vehicle {veh.Handle}. Reason:ClearTraffic");
veh.Delete(); veh.Delete();
} }
@ -181,7 +181,7 @@ namespace RageCoop.Client
} }
catch (Exception ex) catch (Exception ex)
{ {
Main.Logger.Error(ex); Log.Error(ex);
QueuedActions.Remove(action); QueuedActions.Remove(action);
} }
} }