2022-07-20 17:50:01 +08:00
|
|
|
|
using GTA;
|
2022-08-08 17:03:41 +08:00
|
|
|
|
using GTA.Math;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
using GTA.Native;
|
2022-07-20 17:50:01 +08:00
|
|
|
|
using RageCoop.Core;
|
|
|
|
|
using System.Collections.Generic;
|
2022-08-08 17:03:41 +08:00
|
|
|
|
using Lidgren.Network;
|
|
|
|
|
using System.Net;
|
2022-08-11 15:38:19 +08:00
|
|
|
|
using System.Linq;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2022-05-22 15:55:26 +08:00
|
|
|
|
namespace RageCoop.Client
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2022-06-12 15:39:32 +08:00
|
|
|
|
internal static class PlayerList
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2022-02-24 21:29:04 -07:00
|
|
|
|
private const float LEFT_POSITION = 0.122f;
|
|
|
|
|
private const float RIGHT_POSITION = 0.9f;
|
2022-05-23 16:59:49 +08:00
|
|
|
|
private static readonly Scaleform _mainScaleform = new Scaleform("mp_mm_card_freemode");
|
|
|
|
|
private static ulong _lastUpdate = Util.GetTickCount64();
|
|
|
|
|
public static ulong Pressed { get; set; }
|
2022-02-24 21:29:04 -07:00
|
|
|
|
|
2022-05-23 16:59:49 +08:00
|
|
|
|
public static bool LeftAlign = true;
|
2022-08-08 17:03:41 +08:00
|
|
|
|
public static Dictionary<int, Player> Players = new Dictionary<int, Player> { };
|
2022-05-23 16:59:49 +08:00
|
|
|
|
public static void Tick()
|
2021-08-13 15:20:26 +02:00
|
|
|
|
{
|
2022-05-25 11:32:34 +08:00
|
|
|
|
if (!Networking.IsOnServer)
|
2021-08-13 15:20:26 +02:00
|
|
|
|
{
|
2021-08-17 15:04:50 +02:00
|
|
|
|
return;
|
2021-08-13 15:20:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-10 14:34:55 +02:00
|
|
|
|
if ((Util.GetTickCount64() - _lastUpdate) >= 1000)
|
2021-08-13 15:20:26 +02:00
|
|
|
|
{
|
2022-08-08 17:03:41 +08:00
|
|
|
|
Update();
|
2021-08-13 15:20:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 22:08:15 +01:00
|
|
|
|
if ((Util.GetTickCount64() - Pressed) < 5000 && !Main.MainChat.Focused
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#if !NON_INTERACTIVE
|
2022-05-31 09:14:30 +08:00
|
|
|
|
&& !Menus.CoopMenu.MenuPool.AreAnyVisible
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#endif
|
|
|
|
|
)
|
2021-08-13 15:20:26 +02:00
|
|
|
|
{
|
2022-07-20 17:50:01 +08:00
|
|
|
|
Function.Call(Hash.DRAW_SCALEFORM_MOVIE, _mainScaleform.Handle,
|
2022-03-20 09:21:41 +01:00
|
|
|
|
LeftAlign ? LEFT_POSITION : RIGHT_POSITION, 0.3f,
|
2022-02-24 21:29:04 -07:00
|
|
|
|
0.28f, 0.6f,
|
|
|
|
|
255, 255, 255, 255, 0);
|
2021-08-13 15:20:26 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-08 17:03:41 +08:00
|
|
|
|
private static void Update()
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_lastUpdate = Util.GetTickCount64();
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_mainScaleform.CallFunction("SET_DATA_SLOT_EMPTY", 0);
|
2022-07-29 20:35:39 +08:00
|
|
|
|
|
|
|
|
|
int i=0;
|
2022-07-20 17:50:01 +08:00
|
|
|
|
|
2022-08-08 17:03:41 +08:00
|
|
|
|
foreach (var player in Players.Values)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2022-08-08 17:03:41 +08:00
|
|
|
|
_mainScaleform.CallFunction("SET_DATA_SLOT", i++, $"{(player.PedID==Main.LocalPlayerID ? Networking.Latency : player.Latency) * 1000:N0}ms", player.Username, 116, 0, i - 1, "", "", 2, "", "", ' ');
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-29 20:35:39 +08:00
|
|
|
|
_mainScaleform.CallFunction("SET_TITLE", "Player list", $"{Players.Count} players");
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_mainScaleform.CallFunction("DISPLAY_VIEW");
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
2022-07-20 17:50:01 +08:00
|
|
|
|
public static void SetPlayer(int id, string username, float latency = 0)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-07-29 20:35:39 +08:00
|
|
|
|
Main.Logger.Debug($"{id},{username},{latency}");
|
2022-08-08 17:03:41 +08:00
|
|
|
|
Player p;
|
2022-07-20 17:50:01 +08:00
|
|
|
|
if (Players.TryGetValue(id, out p))
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
|
|
|
|
p.Username=username;
|
|
|
|
|
p.PedID=id;
|
2022-08-08 17:03:41 +08:00
|
|
|
|
p._latencyToServer=latency;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-08-08 17:03:41 +08:00
|
|
|
|
p = new Player { PedID=id, Username=username, _latencyToServer=latency };
|
2022-07-20 17:50:01 +08:00
|
|
|
|
Players.Add(id, p);
|
2022-06-22 14:18:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static void UpdatePlayer(Packets.PlayerInfoUpdate packet)
|
|
|
|
|
{
|
|
|
|
|
var p = GetPlayer(packet.PedID);
|
2022-07-30 12:03:57 +08:00
|
|
|
|
if (p!=null)
|
|
|
|
|
{
|
2022-08-08 17:03:41 +08:00
|
|
|
|
p._latencyToServer = packet.Latency;
|
|
|
|
|
p.Position = packet.Position;
|
2022-08-08 17:47:09 +08:00
|
|
|
|
|
|
|
|
|
Main.QueueAction(() =>
|
|
|
|
|
{
|
2022-08-08 18:07:22 +08:00
|
|
|
|
if (p.FakeBlip?.Exists()!=true)
|
|
|
|
|
{
|
|
|
|
|
p.FakeBlip=World.CreateBlip(p.Position);
|
|
|
|
|
}
|
2022-08-08 17:47:09 +08:00
|
|
|
|
if (p.Position.DistanceTo(Main.PlayerPosition)>500)
|
|
|
|
|
{
|
|
|
|
|
p.FakeBlip.Color=Scripting.API.Config.BlipColor;
|
|
|
|
|
p.FakeBlip.Scale=Scripting.API.Config.BlipScale;
|
|
|
|
|
p.FakeBlip.Sprite=Scripting.API.Config.BlipSprite;
|
|
|
|
|
p.FakeBlip.DisplayType=BlipDisplayType.Default;
|
|
|
|
|
p.FakeBlip.Position=p.Position;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
p.FakeBlip.DisplayType=BlipDisplayType.NoDisplay;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-07-30 12:03:57 +08:00
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
2022-08-08 17:03:41 +08:00
|
|
|
|
public static Player GetPlayer(int id)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-08-08 17:03:41 +08:00
|
|
|
|
Player p;
|
2022-06-22 14:18:20 +08:00
|
|
|
|
Players.TryGetValue(id, out p);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
2022-08-08 17:03:41 +08:00
|
|
|
|
public static Player GetPlayer(SyncedPed p)
|
2022-06-22 14:18:20 +08:00
|
|
|
|
{
|
|
|
|
|
var player = GetPlayer(p.ID);
|
2022-07-11 10:08:21 +08:00
|
|
|
|
if (player!=null)
|
|
|
|
|
{
|
|
|
|
|
player.Character=p;
|
|
|
|
|
}
|
2022-06-22 14:18:20 +08:00
|
|
|
|
return player;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
2022-05-23 16:59:49 +08:00
|
|
|
|
public static void RemovePlayer(int id)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-08-11 15:38:19 +08:00
|
|
|
|
if (Players.TryGetValue(id,out var player))
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-06-22 14:18:20 +08:00
|
|
|
|
Players.Remove(id);
|
2022-08-11 15:38:19 +08:00
|
|
|
|
Main.QueueAction(() => player.FakeBlip?.Delete());
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-23 16:59:49 +08:00
|
|
|
|
public static void Cleanup()
|
|
|
|
|
{
|
2022-08-11 15:38:19 +08:00
|
|
|
|
foreach(var p in Players.Values.ToArray())
|
|
|
|
|
{
|
|
|
|
|
p.FakeBlip?.Delete();
|
|
|
|
|
}
|
2022-08-08 17:03:41 +08:00
|
|
|
|
Players=new Dictionary<int, Player> { };
|
2022-05-23 16:59:49 +08:00
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
2022-06-22 08:58:36 +08:00
|
|
|
|
|
2022-08-08 17:03:41 +08:00
|
|
|
|
internal class Player
|
2022-06-22 08:58:36 +08:00
|
|
|
|
{
|
2022-08-10 20:42:47 +08:00
|
|
|
|
public byte HolePunchStatus { get; set; } = 1;
|
2022-06-22 08:58:36 +08:00
|
|
|
|
public string Username { get; internal set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Universal character ID.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int PedID
|
|
|
|
|
{
|
|
|
|
|
get; internal set;
|
|
|
|
|
}
|
2022-08-10 20:42:47 +08:00
|
|
|
|
public IPEndPoint InternalEndPoint { get; set; }
|
|
|
|
|
public IPEndPoint ExternalEndPoint { get; set; }
|
|
|
|
|
public bool ConnectWhenPunched { get; set; }
|
2022-08-08 17:47:09 +08:00
|
|
|
|
public Blip FakeBlip { get; set; }
|
2022-08-08 17:03:41 +08:00
|
|
|
|
public Vector3 Position { get; set; }
|
2022-06-22 14:18:20 +08:00
|
|
|
|
public SyncedPed Character { get; set; }
|
2022-06-22 08:58:36 +08:00
|
|
|
|
/// <summary>
|
2022-08-08 17:03:41 +08:00
|
|
|
|
/// Player Latency in seconds, will be the latency to server if not using P2P connection.
|
2022-06-22 08:58:36 +08:00
|
|
|
|
/// </summary>
|
2022-08-08 17:03:41 +08:00
|
|
|
|
public float Latency => HasDirectConnection ? Connection.AverageRoundtripTime/2 : _latencyToServer;
|
|
|
|
|
public float PacketTravelTime => HasDirectConnection ? Connection.AverageRoundtripTime/2 : Networking.Latency+_latencyToServer;
|
|
|
|
|
public float _latencyToServer = 0;
|
2022-07-09 19:32:11 +08:00
|
|
|
|
public bool DisplayNameTag { get; set; } = true;
|
2022-08-08 17:03:41 +08:00
|
|
|
|
public NetConnection Connection { get; set; }
|
|
|
|
|
public bool HasDirectConnection => Connection?.Status==NetConnectionStatus.Connected;
|
2022-06-22 08:58:36 +08:00
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|