Use TickCount64 instead of TickCount

This commit is contained in:
EntenKoeniq
2021-11-19 22:08:15 +01:00
parent 6f4544d947
commit 8fc16725ff
8 changed files with 44 additions and 41 deletions

View File

@ -31,7 +31,7 @@ namespace CoopClient
} }
} }
private int LastMessageTime { get; set; } private ulong LastMessageTime { get; set; }
private bool CurrentHidden { get; set; } private bool CurrentHidden { get; set; }
private bool Hidden private bool Hidden
@ -73,7 +73,7 @@ namespace CoopClient
public void Tick() public void Tick()
{ {
if ((Environment.TickCount - LastMessageTime) > 15000 && !Focused && !Hidden) if ((Util.GetTickCount64() - LastMessageTime) > 15000 && !Focused && !Hidden)
{ {
Hidden = true; Hidden = true;
} }
@ -94,7 +94,7 @@ namespace CoopClient
public void AddMessage(string sender, string msg) public void AddMessage(string sender, string msg)
{ {
MainScaleForm.CallFunction("ADD_MESSAGE", sender + ":", msg); MainScaleForm.CallFunction("ADD_MESSAGE", sender + ":", msg);
LastMessageTime = Environment.TickCount; LastMessageTime = Util.GetTickCount64();
Hidden = false; Hidden = false;
} }

View File

@ -15,7 +15,7 @@ namespace CoopClient
{ {
private bool AllDataAvailable = false; private bool AllDataAvailable = false;
public bool LastSyncWasFull { get; set; } = false; public bool LastSyncWasFull { get; set; } = false;
public long LastUpdateReceived { get; set; } public ulong LastUpdateReceived { get; set; }
public float Latency { get; set; } public float Latency { get; set; }
public Ped Character { get; set; } public Ped Character { get; set; }
@ -44,7 +44,7 @@ namespace CoopClient
public Blip PedBlip; public Blip PedBlip;
#region -- IN VEHICLE -- #region -- IN VEHICLE --
private int VehicleStopTime { get; set; } private ulong VehicleStopTime { get; set; }
public bool IsInVehicle { get; set; } public bool IsInVehicle { get; set; }
public int VehicleModelHash { get; set; } public int VehicleModelHash { get; set; }
@ -450,11 +450,11 @@ namespace CoopClient
MainVehicle.Velocity = VehicleVelocity + forceMultiplier * (VehiclePosition - MainVehicle.Position); MainVehicle.Velocity = VehicleVelocity + forceMultiplier * (VehiclePosition - MainVehicle.Position);
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f); MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);
VehicleStopTime = Environment.TickCount; VehicleStopTime = Util.GetTickCount64();
} }
else if ((Environment.TickCount - VehicleStopTime) <= 1000) else if ((Util.GetTickCount64() - 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), Util.GetTickCount64() - VehicleStopTime, 1000);
MainVehicle.PositionNoOffset = posTarget; MainVehicle.PositionNoOffset = posTarget;
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f); MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.Quaternion, VehicleRotation, 0.5f);

View File

@ -26,7 +26,7 @@ namespace CoopClient.Entities
{ {
localNpcs = new Dictionary<long, EntitiesNpc>(Main.Npcs); localNpcs = new Dictionary<long, EntitiesNpc>(Main.Npcs);
int tickCount = Environment.TickCount; ulong tickCount = Util.GetTickCount64();
foreach (KeyValuePair<long, EntitiesNpc> npc in new Dictionary<long, EntitiesNpc>(localNpcs)) foreach (KeyValuePair<long, EntitiesNpc> npc in new Dictionary<long, EntitiesNpc>(localNpcs))
{ {
if ((tickCount - npc.Value.LastUpdateReceived) > 3000) if ((tickCount - npc.Value.LastUpdateReceived) > 3000)

View File

@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
@ -95,7 +94,7 @@ namespace CoopClient
public static bool IsPlayerListVisible() public static bool IsPlayerListVisible()
{ {
return Environment.TickCount - PlayerList.Pressed < 5000; return Util.GetTickCount64() - PlayerList.Pressed < 5000;
} }
public static string GetCurrentVersion() public static string GetCurrentVersion()

View File

@ -51,7 +51,7 @@ namespace CoopClient
Util.NativeMemory(); Util.NativeMemory();
} }
private int LastDataSend; private ulong LastDataSend;
private void OnTick(object sender, EventArgs e) private void OnTick(object sender, EventArgs e)
{ {
if (Game.IsLoading) if (Game.IsLoading)
@ -104,14 +104,14 @@ namespace CoopClient
} }
#endif #endif
if ((Environment.TickCount - LastDataSend) < (1000 / 60)) if ((Util.GetTickCount64() - LastDataSend) < (1000 / 60))
{ {
return; return;
} }
MainNetworking.SendPlayerData(); MainNetworking.SendPlayerData();
LastDataSend = Environment.TickCount; LastDataSend = Util.GetTickCount64();
} }
#if !NON_INTERACTIVE #if !NON_INTERACTIVE
@ -164,7 +164,7 @@ namespace CoopClient
{ {
if (MainNetworking.IsOnServer()) if (MainNetworking.IsOnServer())
{ {
int currentTimestamp = Environment.TickCount; ulong currentTimestamp = Util.GetTickCount64();
PlayerList.Pressed = (currentTimestamp - PlayerList.Pressed) < 5000 ? (currentTimestamp - 6000) : currentTimestamp; PlayerList.Pressed = (currentTimestamp - PlayerList.Pressed) < 5000 ? (currentTimestamp - 6000) : currentTimestamp;
} }
return; return;
@ -217,9 +217,9 @@ namespace CoopClient
} }
#if DEBUG #if DEBUG
private int ArtificialLagCounter; private ulong ArtificialLagCounter;
public static EntitiesPlayer DebugSyncPed; public static EntitiesPlayer DebugSyncPed;
public static int LastFullDebugSync = 0; public static ulong LastFullDebugSync = 0;
public static bool UseDebug = false; public static bool UseDebug = false;
private void Debug() private void Debug()
@ -231,12 +231,12 @@ namespace CoopClient
DebugSyncPed = Players[0]; DebugSyncPed = Players[0];
} }
if ((Environment.TickCount - ArtificialLagCounter) < 157) if ((Util.GetTickCount64() - ArtificialLagCounter) < 157)
{ {
return; return;
} }
bool fullSync = (Environment.TickCount - LastFullDebugSync) > 1500; bool fullSync = (Util.GetTickCount64() - LastFullDebugSync) > 1500;
if (fullSync) if (fullSync)
{ {
@ -316,7 +316,7 @@ namespace CoopClient
} }
} }
int currentTimestamp = Environment.TickCount; ulong currentTimestamp = Util.GetTickCount64();
DebugSyncPed.LastUpdateReceived = currentTimestamp; DebugSyncPed.LastUpdateReceived = currentTimestamp;
DebugSyncPed.Latency = currentTimestamp - ArtificialLagCounter; DebugSyncPed.Latency = currentTimestamp - ArtificialLagCounter;

View File

@ -256,7 +256,7 @@ namespace CoopClient
{ {
SocialClubName = packet.SocialClubName, SocialClubName = packet.SocialClubName,
Username = packet.Username, Username = packet.Username,
LastUpdateReceived = Environment.TickCount LastUpdateReceived = Util.GetTickCount64()
}; };
Main.Players.Add(packet.ID, player); Main.Players.Add(packet.ID, player);
@ -304,7 +304,7 @@ namespace CoopClient
player.IsInVehicle = false; player.IsInVehicle = false;
player.Latency = packet.Extra.Latency; player.Latency = packet.Extra.Latency;
player.LastUpdateReceived = Environment.TickCount; player.LastUpdateReceived = Util.GetTickCount64();
} }
} }
@ -340,7 +340,7 @@ namespace CoopClient
player.VehicleDead = (packet.Flag.Value & (byte)VehicleDataFlags.IsDead) > 0; player.VehicleDead = (packet.Flag.Value & (byte)VehicleDataFlags.IsDead) > 0;
player.Latency = packet.Extra.Latency; player.Latency = packet.Extra.Latency;
player.LastUpdateReceived = Environment.TickCount; player.LastUpdateReceived = Util.GetTickCount64();
} }
} }
@ -367,7 +367,7 @@ namespace CoopClient
player.IsInVehicle = false; player.IsInVehicle = false;
player.Latency = packet.Extra.Latency; player.Latency = packet.Extra.Latency;
player.LastUpdateReceived = Environment.TickCount; player.LastUpdateReceived = Util.GetTickCount64();
} }
} }
@ -395,7 +395,7 @@ namespace CoopClient
player.VehicleDead = (packet.Flag.Value & (byte)VehicleDataFlags.IsDead) > 0; player.VehicleDead = (packet.Flag.Value & (byte)VehicleDataFlags.IsDead) > 0;
player.Latency = packet.Extra.Latency; player.Latency = packet.Extra.Latency;
player.LastUpdateReceived = Environment.TickCount; player.LastUpdateReceived = Util.GetTickCount64();
} }
} }
@ -409,7 +409,7 @@ namespace CoopClient
player.Position = packet.Extra.Position.ToVector(); player.Position = packet.Extra.Position.ToVector();
player.Latency = packet.Extra.Latency; player.Latency = packet.Extra.Latency;
player.LastUpdateReceived = Environment.TickCount; player.LastUpdateReceived = Util.GetTickCount64();
} }
} }
@ -463,7 +463,7 @@ namespace CoopClient
{ {
EntitiesNpc npc = Main.Npcs[packet.ID]; EntitiesNpc npc = Main.Npcs[packet.ID];
npc.LastUpdateReceived = Environment.TickCount; npc.LastUpdateReceived = Util.GetTickCount64();
npc.ModelHash = packet.ModelHash; npc.ModelHash = packet.ModelHash;
npc.Props = packet.Props; npc.Props = packet.Props;
@ -487,7 +487,7 @@ namespace CoopClient
{ {
Main.Npcs.Add(packet.ID, new EntitiesNpc() Main.Npcs.Add(packet.ID, new EntitiesNpc()
{ {
LastUpdateReceived = Environment.TickCount, LastUpdateReceived = Util.GetTickCount64(),
ModelHash = packet.ModelHash, ModelHash = packet.ModelHash,
Props = packet.Props, Props = packet.Props,
@ -519,7 +519,7 @@ namespace CoopClient
{ {
EntitiesNpc npc = Main.Npcs[packet.ID]; EntitiesNpc npc = Main.Npcs[packet.ID];
npc.LastUpdateReceived = Environment.TickCount; npc.LastUpdateReceived = Util.GetTickCount64();
npc.ModelHash = packet.ModelHash; npc.ModelHash = packet.ModelHash;
npc.Props = packet.Props; npc.Props = packet.Props;
@ -549,7 +549,7 @@ namespace CoopClient
{ {
Main.Npcs.Add(packet.ID, new EntitiesNpc() Main.Npcs.Add(packet.ID, new EntitiesNpc()
{ {
LastUpdateReceived = Environment.TickCount, LastUpdateReceived = Util.GetTickCount64(),
ModelHash = packet.ModelHash, ModelHash = packet.ModelHash,
Props = packet.Props, Props = packet.Props,
@ -582,7 +582,7 @@ namespace CoopClient
#endregion #endregion
#region -- SEND -- #region -- SEND --
private int LastPlayerFullSync = 0; private ulong LastPlayerFullSync = 0;
public void SendPlayerData() public void SendPlayerData()
{ {
Ped player = Game.Player.Character; Ped player = Game.Player.Character;
@ -590,7 +590,7 @@ namespace CoopClient
NetOutgoingMessage outgoingMessage = Client.CreateMessage(); NetOutgoingMessage outgoingMessage = Client.CreateMessage();
NetDeliveryMethod messageType; NetDeliveryMethod messageType;
if ((Environment.TickCount - LastPlayerFullSync) > 500) if ((Util.GetTickCount64() - LastPlayerFullSync) > 500)
{ {
messageType = NetDeliveryMethod.UnreliableSequenced; messageType = NetDeliveryMethod.UnreliableSequenced;
@ -681,7 +681,7 @@ namespace CoopClient
}.PacketToNetOutGoingMessage(outgoingMessage); }.PacketToNetOutGoingMessage(outgoingMessage);
} }
LastPlayerFullSync = Environment.TickCount; LastPlayerFullSync = Util.GetTickCount64();
} }
else else
{ {

View File

@ -11,8 +11,8 @@ namespace CoopClient
public class PlayerList : Script public class PlayerList : Script
{ {
private readonly Scaleform MainScaleform = new Scaleform("mp_mm_card_freemode"); private readonly Scaleform MainScaleform = new Scaleform("mp_mm_card_freemode");
private int LastUpdate = Environment.TickCount; private ulong LastUpdate = Util.GetTickCount64();
public static int Pressed { get; set; } public static ulong Pressed { get; set; }
public PlayerList() public PlayerList()
{ {
@ -28,12 +28,12 @@ namespace CoopClient
return; return;
} }
if ((Environment.TickCount - LastUpdate) >= 1000) if ((Util.GetTickCount64() - LastUpdate) >= 1000)
{ {
Update(Main.Players, Main.MainSettings.Username); Update(Main.Players, Main.MainSettings.Username);
} }
if ((Environment.TickCount - Pressed) < 5000 && !Main.MainChat.Focused if ((Util.GetTickCount64() - Pressed) < 5000 && !Main.MainChat.Focused
#if !NON_INTERACTIVE #if !NON_INTERACTIVE
&& !Main.MainMenu.MenuPool.AreAnyVisible && !Main.MainMenu.MenuPool.AreAnyVisible
#endif #endif
@ -53,7 +53,7 @@ namespace CoopClient
private void Update(Dictionary<long, EntitiesPlayer> players, string localUsername) private void Update(Dictionary<long, EntitiesPlayer> players, string localUsername)
{ {
LastUpdate = Environment.TickCount; LastUpdate = Util.GetTickCount64();
MainScaleform.CallFunction("SET_DATA_SLOT_EMPTY", 0); MainScaleform.CallFunction("SET_DATA_SLOT_EMPTY", 0);
MainScaleform.CallFunction("SET_DATA_SLOT", 0, $"{Main.MainNetworking.Latency * 1000:N0}ms", localUsername, 116, 0, 0, "", "", 2, "", "", ' '); MainScaleform.CallFunction("SET_DATA_SLOT", 0, $"{Main.MainNetworking.Latency * 1000:N0}ms", localUsername, 116, 0, 0, "", "", 2, "", "", ' ');

View File

@ -3,6 +3,7 @@ using System.IO;
using System.Xml.Serialization; using System.Xml.Serialization;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices;
using static System.Runtime.InteropServices.Marshal; using static System.Runtime.InteropServices.Marshal;
using GTA; using GTA;
@ -104,7 +105,7 @@ namespace CoopClient
return Comparer<T>.Default.Compare(item, start) >= 0 && Comparer<T>.Default.Compare(item, end) <= 0; return Comparer<T>.Default.Compare(item, start) >= 0 && Comparer<T>.Default.Compare(item, end) <= 0;
} }
public static Vector3 LinearVectorLerp(Vector3 start, Vector3 end, int currentTime, int duration) public static Vector3 LinearVectorLerp(Vector3 start, Vector3 end, ulong currentTime, int duration)
{ {
return new Vector3() return new Vector3()
{ {
@ -114,7 +115,7 @@ namespace CoopClient
}; };
} }
public static float LinearFloatLerp(float start, float end, int currentTime, int duration) public static float LinearFloatLerp(float start, float end, ulong currentTime, int duration)
{ {
return (end - start) * currentTime / duration + start; return (end - start) * currentTime / duration + start;
} }
@ -468,5 +469,8 @@ namespace CoopClient
return camPos + dir * raycastToDist; return camPos + dir * raycastToDist;
} }
[DllImport("kernel32.dll")]
public static extern ulong GetTickCount64();
} }
} }