Some changes

This commit is contained in:
EntenKoeniq
2021-08-13 15:20:26 +02:00
parent a7449d586d
commit bfb697d419
7 changed files with 105 additions and 57 deletions

View File

@ -2,6 +2,6 @@
{
public class EntitiesNpc : EntitiesPed
{
public int LastUpdateReceived { get; set; }
//public int LastUpdateReceived { get; set; }
}
}

View File

@ -15,6 +15,8 @@ namespace CoopClient
{
private bool AllDataAvailable = false;
public bool LastSyncWasFull { get; set; } = false;
public int LastUpdateReceived { get; set; }
public int Latency { get; set; }
public Ped Character { get; set; }
public int Health { get; set; }
@ -351,13 +353,13 @@ namespace CoopClient
{
MainVehicle.Velocity = VehicleVelocity + (VehiclePosition - MainVehicle.Position);
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, Math.Min(1.0f, Latency < 0.5f ? 0.5f : Latency));
VehicleStopTime = Environment.TickCount;
}
else if ((Environment.TickCount - VehicleStopTime) <= 1000)
{
Vector3 posTarget = Util.LinearVectorLerp(MainVehicle.Position, VehiclePosition + (VehiclePosition - MainVehicle.Position), (Environment.TickCount - VehicleStopTime), 1000);
Vector3 posTarget = Util.LinearVectorLerp(MainVehicle.Position, VehiclePosition + (VehiclePosition - MainVehicle.Position), Environment.TickCount - VehicleStopTime, 1000);
MainVehicle.PositionNoOffset = posTarget;
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);
}

View File

@ -27,7 +27,6 @@ namespace CoopClient
public static MenusMain MainMenu = new MenusMain();
public static Chat MainChat = new Chat();
public static PlayerList MainPlayerList = new PlayerList();
public static Networking MainNetworking = new Networking();
@ -75,10 +74,6 @@ namespace CoopClient
}
MainChat.Tick();
if (!MainChat.Focused && !MainMenu.MenuPool.AreAnyVisible)
{
MainPlayerList.Tick();
}
// Display all players
foreach (KeyValuePair<string, EntitiesPlayer> player in Players)
@ -129,9 +124,8 @@ namespace CoopClient
case Keys.Y:
if (MainNetworking.IsOnServer())
{
int time = Environment.TickCount;
MainPlayerList.Pressed = (time - MainPlayerList.Pressed) < 5000 ? (time - 6000) : time;
int currentTimestamp = Environment.TickCount;
PlayerList.Pressed = (currentTimestamp - PlayerList.Pressed) < 5000 ? (currentTimestamp - 6000) : currentTimestamp;
}
break;
case Keys.G:
@ -236,14 +230,14 @@ namespace CoopClient
private void Debug()
{
var player = Game.Player.Character;
Ped player = Game.Player.Character;
if (!Players.ContainsKey("DebugKey"))
{
Players.Add("DebugKey", new EntitiesPlayer() { SocialClubName = "DEBUG", Username = "DebugPlayer" });
DebugSyncPed = Players["DebugKey"];
}
if ((Environment.TickCount - ArtificialLagCounter) < 47)
if ((Environment.TickCount - ArtificialLagCounter) < 27)
{
return;
}
@ -311,6 +305,9 @@ namespace CoopClient
}
}
DebugSyncPed.LastUpdateReceived = Environment.TickCount;
DebugSyncPed.Latency = Environment.TickCount - ArtificialLagCounter;
FullDebugSync = !FullDebugSync;
ArtificialLagCounter = Environment.TickCount;
}

View File

@ -106,7 +106,6 @@ namespace CoopClient
Function.Call(Hash.SET_RANDOM_TRAINS, 0);
Main.MainChat.Init();
Main.MainPlayerList.Init(Main.MainSettings.Username);
// Send player connect packet
NetOutgoingMessage outgoingMessage = Client.CreateMessage();
@ -232,12 +231,11 @@ namespace CoopClient
EntitiesPlayer player = new EntitiesPlayer()
{
SocialClubName = packet.SocialClubName,
Username = packet.Username
Username = packet.Username,
LastUpdateReceived = Environment.TickCount
};
Main.Players.Add(packet.Player, player);
Main.MainPlayerList.Update(Main.Players, Main.MainSettings.Username);
}
private void PlayerDisconnect(PlayerDisconnectPacket packet)
@ -255,8 +253,6 @@ namespace CoopClient
Main.Players.Remove(packet.Player);
}
Main.MainPlayerList.Update(Main.Players, Main.MainSettings.Username);
}
private void FullSyncPlayer(FullSyncPlayerPacket packet)
@ -264,6 +260,11 @@ namespace CoopClient
if (Main.Players.ContainsKey(packet.Player))
{
EntitiesPlayer player = Main.Players[packet.Player];
int currentTimestamp = Environment.TickCount;
player.Latency = currentTimestamp - player.LastUpdateReceived;
player.LastUpdateReceived = currentTimestamp;
player.ModelHash = packet.ModelHash;
player.Props = packet.Props;
player.Health = packet.Health;
@ -289,6 +290,11 @@ namespace CoopClient
if (Main.Players.ContainsKey(packet.Player))
{
EntitiesPlayer player = Main.Players[packet.Player];
int currentTimestamp = Environment.TickCount;
player.Latency = currentTimestamp - player.LastUpdateReceived;
player.LastUpdateReceived = currentTimestamp;
player.ModelHash = packet.ModelHash;
player.Props = packet.Props;
player.Health = packet.Health;
@ -315,6 +321,11 @@ namespace CoopClient
if (Main.Players.ContainsKey(packet.Player))
{
EntitiesPlayer player = Main.Players[packet.Player];
int currentTimestamp = Environment.TickCount;
player.Latency = currentTimestamp - player.LastUpdateReceived;
player.LastUpdateReceived = currentTimestamp;
player.Health = packet.Health;
player.Position = packet.Position.ToVector();
player.Rotation = packet.Rotation.ToVector();
@ -338,6 +349,11 @@ namespace CoopClient
if (Main.Players.ContainsKey(packet.Player))
{
EntitiesPlayer player = Main.Players[packet.Player];
int currentTimestamp = Environment.TickCount;
player.Latency = currentTimestamp - player.LastUpdateReceived;
player.LastUpdateReceived = currentTimestamp;
player.Health = packet.Health;
player.Position = packet.Position.ToVector();
player.VehicleModelHash = packet.VehModelHash;
@ -366,7 +382,9 @@ namespace CoopClient
if (Main.Npcs.ContainsKey(packet.ID))
{
EntitiesNpc npc = Main.Npcs[packet.ID];
npc.LastUpdateReceived = Environment.TickCount;
npc.ModelHash = packet.ModelHash;
npc.Props = packet.Props;
npc.Health = packet.Health;
@ -390,6 +408,7 @@ namespace CoopClient
Main.Npcs.Add(packet.ID, new EntitiesNpc()
{
LastUpdateReceived = Environment.TickCount,
ModelHash = packet.ModelHash,
Props = packet.Props,
Health = packet.Health,
@ -419,7 +438,9 @@ namespace CoopClient
if (Main.Npcs.ContainsKey(packet.ID))
{
EntitiesNpc npc = Main.Npcs[packet.ID];
npc.LastUpdateReceived = Environment.TickCount;
npc.ModelHash = packet.ModelHash;
npc.Props = packet.Props;
npc.Health = packet.Health;
@ -444,6 +465,7 @@ namespace CoopClient
Main.Npcs.Add(packet.ID, new EntitiesNpc()
{
LastUpdateReceived = Environment.TickCount,
ModelHash = packet.ModelHash,
Props = packet.Props,
Health = packet.Health,

View File

@ -12,13 +12,34 @@ namespace CoopClient
#region CLIENT-ONLY
public static class VectorExtensions
{
public static Vector3 ToVector(this Quaternion vec)
{
return new Vector3()
{
X = vec.X,
Y = vec.Y,
Z = vec.Z
};
}
public static Quaternion ToQuaternion(this Vector3 vec, float vW = 0.0f)
{
return new Quaternion()
{
X = vec.X,
Y = vec.Y,
Z = vec.Z,
W = vW
};
}
public static LVector3 ToLVector(this Vector3 vec)
{
return new LVector3()
{
X = vec.X,
Y = vec.Y,
Z = vec.Z,
Z = vec.Z
};
}

View File

@ -8,40 +8,61 @@ using GTA.Native;
namespace CoopClient
{
public class PlayerList
public class PlayerList : Script
{
private readonly Scaleform MainScaleform = new Scaleform("mp_mm_card_freemode");
public int Pressed { get; set; }
private int LastUpdate = Environment.TickCount;
public static int Pressed { get; set; }
public void Init(string localUsername)
public PlayerList()
{
Init();
Tick += OnTick;
}
private void OnTick(object sender, EventArgs e)
{
if ((Environment.TickCount - LastUpdate) >= 1000)
{
Update(Main.Players, Main.MainSettings.Username);
}
if (!Main.MainNetworking.IsOnServer())
{
return;
}
if ((Environment.TickCount - Pressed) < 5000 && !Main.MainChat.Focused && !Main.MainMenu.MenuPool.AreAnyVisible)
{
Function.Call(Hash.DRAW_SCALEFORM_MOVIE, MainScaleform.Handle, 0.122f, 0.3f, 0.28f, 0.6f, 255, 255, 255, 255, 0);
}
}
private void Init()
{
MainScaleform.CallFunction("SET_DATA_SLOT_EMPTY", 0);
MainScaleform.CallFunction("SET_DATA_SLOT", 0, "", localUsername, 116, 0, 0, "", "", 2, "", "", ' ');
MainScaleform.CallFunction("SET_DATA_SLOT", 0, "", "Me", 116, 0, 0, "", "", 2, "", "", ' ');
MainScaleform.CallFunction("SET_TITLE", "Player list", "1 players");
MainScaleform.CallFunction("DISPLAY_VIEW");
}
public void Update(Dictionary<string, EntitiesPlayer> players, string LocalUsername)
private void Update(Dictionary<string, EntitiesPlayer> players, string localUsername)
{
LastUpdate = Environment.TickCount;
MainScaleform.CallFunction("SET_DATA_SLOT_EMPTY", 0);
MainScaleform.CallFunction("SET_DATA_SLOT", 0, "", LocalUsername, 116, 0, 0, "", "", 2, "", "", ' ');
MainScaleform.CallFunction("SET_DATA_SLOT", 0, "", localUsername, 116, 0, 0, "", "", 2, "", "", ' ');
int i = 1;
foreach (KeyValuePair<string, EntitiesPlayer> player in players)
{
MainScaleform.CallFunction("SET_DATA_SLOT", i++, "", player.Value.Username, 116, 0, i - 1, "", "", 2, "", "", ' ');
MainScaleform.CallFunction("SET_DATA_SLOT", i++, player.Value.Latency + "ms", player.Value.Username, 116, 0, i - 1, "", "", 2, "", "", ' ');
}
MainScaleform.CallFunction("SET_TITLE", "Player list", (players.Count + 1) + " players");
MainScaleform.CallFunction("DISPLAY_VIEW");
}
public void Tick()
{
if ((Environment.TickCount - Pressed) < 5000)
{
Function.Call(Hash.DRAW_SCALEFORM_MOVIE, MainScaleform.Handle, 0.122f, 0.3f, 0.28f, 0.6f, 255, 255, 255, 255, 0);
}
}
}
}

View File

@ -16,16 +16,15 @@ namespace CoopClient
#region -- POINTER --
private static int SteeringAngleOffset { get; set; }
delegate ulong GetHandleAddressFuncDelegate(int handle);
static GetHandleAddressFuncDelegate GetEntityAddressFunc;
static unsafe byte* FindPattern(string pattern, string mask)
{
ProcessModule module = Process.GetCurrentProcess().MainModule;
return FindPattern(pattern, mask, module.BaseAddress, (ulong)module.ModuleMemorySize);
}
static unsafe byte* FindPattern(string pattern, string mask, IntPtr startAddress, ulong size)
{
ulong address = (ulong)startAddress.ToInt64();
ulong endAddress = address + size;
ulong address = (ulong)module.BaseAddress.ToInt64();
ulong endAddress = address + (ulong)module.ModuleMemorySize;
for (; address < endAddress; address++)
{
@ -52,12 +51,6 @@ namespace CoopClient
address = FindPattern("\xE8\x00\x00\x00\x00\x48\x8B\xD8\x48\x85\xC0\x74\x2E\x48\x83\x3D", "x????xxxxxxxxxxx");
GetEntityAddressFunc = GetDelegateForFunctionPointer<GetHandleAddressFuncDelegate>(new IntPtr(*(int*)(address + 1) + address + 5));
// use the former pattern if the version is 1.0.1604.0 or newer
int gameVersion = (int)Game.Version;
address = gameVersion >= 46 ?
FindPattern("\xF3\x0F\x10\x9F\xD4\x08\x00\x00\x0F\x2F\xDF\x73\x0A", "xxxx????xxxxx") :
FindPattern("\xF3\x0F\x10\x8F\x68\x08\x00\x00\x88\x4D\x8C\x0F\x2F\xCF", "xxxx????xxx???");
address = FindPattern("\x74\x0A\xF3\x0F\x11\xB3\x1C\x09\x00\x00\xEB\x25", "xxxxxx????xx");
if (address != null)
{
@ -74,17 +67,9 @@ namespace CoopClient
}
}
delegate ulong GetHandleAddressFuncDelegate(int handle);
static GetHandleAddressFuncDelegate GetEntityAddressFunc;
public static IntPtr GetEntityAddress(int handle)
public static unsafe void CustomSteeringAngle(int handle, float value)
{
return new IntPtr((long)GetEntityAddressFunc(handle));
}
public static unsafe void CustomSteeringAngle(int Handle, float value)
{
IntPtr address = GetEntityAddress(Handle);
IntPtr address = new IntPtr((long)GetEntityAddressFunc(handle));
if (address == IntPtr.Zero || SteeringAngleOffset == 0)
{
return;