Cleaned up (Client)

This commit is contained in:
Nick I. A
2022-08-11 14:59:09 +02:00
parent cb7f0290ec
commit b9e22a880f
8 changed files with 12 additions and 68 deletions

View File

@ -173,13 +173,11 @@ namespace RageCoop.Client
if (Networking.ShowNetworkInfo)
{
new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 0), $"L: {Networking.Latency * 1000:N0}ms", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw();
new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 30), $"R: {Lidgren.Network.NetUtility.ToHumanReadable(Statistics.BytesDownPerSecond)}/s", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw();
new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 60), $"S: {Lidgren.Network.NetUtility.ToHumanReadable(Statistics.BytesUpPerSecond)}/s", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw();
}
MainChat.Tick();
PlayerList.Tick();
if (!Scripting.API.Config.EnableAutoRespawn)
@ -203,10 +201,8 @@ namespace RageCoop.Client
}
else
{
Function.Call(Hash.DISPLAY_HUD, true);
}
}
else if (P.IsDead && !_lastDead)
{

View File

@ -49,7 +49,6 @@ namespace RageCoop.Client
}
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 };
@ -134,7 +133,6 @@ namespace RageCoop.Client
Main.Logger.Trace($"Received unhandled file chunk:{id}");
}
}
}
public static void Complete(int id)

View File

@ -29,6 +29,7 @@ namespace RageCoop.Client
Peer?.Shutdown("Bye");
if (IsOnServer)
{
// ?
}
else if (IsConnecting) {
_publicKeyReceived.Set();
@ -117,10 +118,7 @@ namespace RageCoop.Client
});
}
}
public static bool IsOnServer
{
get { return ServerConnection?.Status == NetConnectionStatus.Connected; }
}
public static bool IsOnServer { get => ServerConnection?.Status == NetConnectionStatus.Connected; }
#region -- PLAYER --
private static void PlayerConnect(Packets.PlayerConnect packet)
@ -149,7 +147,6 @@ namespace RageCoop.Client
#endregion // -- PLAYER --
#region -- GET --
private static bool GetServerPublicKey(string address, int timeout = 10000)
{
Security.ServerRSA=null;
@ -181,8 +178,7 @@ namespace RageCoop.Client
private static int NewRequestID()
{
int ID = 0;
while ((ID==0)
|| PendingResponses.ContainsKey(ID))
while ((ID==0) || PendingResponses.ContainsKey(ID))
{
byte[] rngBytes = new byte[4];

View File

@ -25,7 +25,6 @@ namespace RageCoop.Client
return EntityPool.ServerBlips[reader.ReadInt32()].Handle;
default:
throw new ArgumentException("Cannot resolve server side argument: "+t);
}
};
private static readonly AutoResetEvent _publicKeyReceived = new AutoResetEvent(false);
@ -43,7 +42,6 @@ namespace RageCoop.Client
case NetConnectionStatus.InitiatedConnect:
if (message.SenderConnection==ServerConnection)
{
CoopMenu.InitiateConnectionMenuSetting();
}
break;
@ -103,8 +101,7 @@ namespace RageCoop.Client
Main.QueueAction(() => Main.CleanUp());
CoopMenu.DisconnectedMenuSetting();
Main.Logger.Info($">> Disconnected << reason: {reason}");
Main.QueueAction(() =>
GTA.UI.Notification.Show("~r~Disconnected: " + reason));
Main.QueueAction(() => GTA.UI.Notification.Show("~r~Disconnected: " + reason));
Main.Resources.Unload();
}
break;
@ -112,12 +109,10 @@ namespace RageCoop.Client
break;
case NetIncomingMessageType.Data:
{
if (message.LengthBytes==0) { break; }
var packetType = PacketType.Unknown;
try
{
// Get packet type
packetType = (PacketType)message.ReadByte();
switch (packetType)
@ -246,10 +241,7 @@ namespace RageCoop.Client
case PacketType.ChatMessage:
{
Packets.ChatMessage packet = new Packets.ChatMessage((b) =>
{
return Security.Decrypt(b);
});
Packets.ChatMessage packet = new Packets.ChatMessage((b) => Security.Decrypt(b));
packet.Deserialize(data);
Main.QueueAction(() => { Main.MainChat.AddMessage(packet.Username, packet.Message); return true; });

View File

@ -53,14 +53,7 @@ namespace RageCoop.Client
c.LastSentStopWatch.Restart();
if (full)
{
if (packet.Flags.HasPedFlag(PedDataFlags.IsInVehicle))
{
packet.CurrentWeaponHash=(uint)p.VehicleWeapon;
}
else
{
packet.CurrentWeaponHash=(uint)p.Weapons.Current.Hash;
}
packet.CurrentWeaponHash = packet.Flags.HasPedFlag(PedDataFlags.IsInVehicle) ? (uint)p.VehicleWeapon : (uint)p.Weapons.Current.Hash;
packet.Flags |= PedDataFlags.IsFullSync;
packet.Clothes=p.GetPedClothes();
packet.ModelHash=p.Model.Hash;
@ -176,13 +169,7 @@ namespace RageCoop.Client
#endregion
public static void SendChatMessage(string message)
{
Peer.SendTo(new Packets.ChatMessage(new Func<string, byte[]>((s) =>
{
return Security.Encrypt(s.GetBytes());
}))
Peer.SendTo(new Packets.ChatMessage(new Func<string, byte[]>((s) => Security.Encrypt(s.GetBytes())))
{ Username = Main.Settings.Username, Message = message },ServerConnection, ConnectionChannel.Chat, NetDeliveryMethod.ReliableOrdered);
Peer.FlushSendQueue();
}

View File

@ -137,10 +137,8 @@ namespace RageCoop.Client
}
Players=new Dictionary<int, Player> { };
}
}
internal class Player
{
public byte HolePunchStatus { get; set; } = 1;

View File

@ -1,9 +1,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GTA.Math;
using GTA;
using SHVDN;
@ -40,8 +37,6 @@ internal static unsafe class Memory
public static MemPatch TimeScalePatch;
static Memory()
{
// Weapon/radio wheel slow-mo patch
// Thanks @CamxxCore, https://github.com/CamxxCore/GTAVWeaponWheelMod
var result = NativeMemory.FindPattern("\x38\x51\x64\x74\x19", "xxxxx");
@ -73,27 +68,13 @@ internal static unsafe class Memory
public const int MatrixOffset = 96;
#endregion
#region OPCODE
const byte XOR_32_64 = 0x31;
const byte RET = 0xC3;
#endregion
public static Vector3 ReadPosition(this Entity e)
{
return ReadVector3(e.MemoryAddress+PositionOffset);
}
public static Quaternion ReadQuaternion(this Entity e)
{
return Quaternion.RotationMatrix(e.Matrix);
}
public static Vector3 ReadRotation(this Entity e)
{
return e.ReadQuaternion().ToEulerDegrees();
}
public static Vector3 ReadVelocity(this Ped e)
{
return ReadVector3(e.MemoryAddress+VelocityOffset);
}
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 ReadVector3(IntPtr address)
{
float* ptr = (float*)address.ToPointer();

View File

@ -28,15 +28,11 @@ namespace RageCoop.Client
private void OnTick(object sender, EventArgs e)
{
if (Game.IsLoading)
if (Game.IsLoading || !Networking.IsOnServer)
{
return;
}
if (!Networking.IsOnServer)
{
return;
}
Game.DisableControlThisFrame(Control.FrontendPause);
if (Main.Settings.DisableAlternatePause)
{