2021-07-07 13:36:25 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Collections.Generic;
|
2021-08-18 11:47:59 +02:00
|
|
|
|
using System.Drawing;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-27 10:15:52 +01:00
|
|
|
|
using CoopClient.Entities.Player;
|
|
|
|
|
using CoopClient.Entities.NPC;
|
2021-08-06 12:31:25 +02:00
|
|
|
|
using CoopClient.Menus;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
using GTA;
|
|
|
|
|
using GTA.Native;
|
|
|
|
|
|
|
|
|
|
namespace CoopClient
|
|
|
|
|
{
|
2021-12-03 20:30:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Don't use it!
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Main : Script
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal static RelationshipGroup RelationshipGroup;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2022-04-10 14:34:55 +02:00
|
|
|
|
private bool _gameLoaded = false;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2022-04-06 02:18:24 +02:00
|
|
|
|
internal static readonly string CurrentVersion = "V1_4_0";
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-14 22:39:15 +01:00
|
|
|
|
internal static bool ShareNPCsWithPlayers = false;
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal static bool DisableTraffic = false;
|
2021-12-14 22:39:15 +01:00
|
|
|
|
internal static bool NPCsAllowed = false;
|
2022-04-10 14:34:55 +02:00
|
|
|
|
private static bool _isGoingToCar = false;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-15 00:25:31 +01:00
|
|
|
|
internal static Settings MainSettings = null;
|
|
|
|
|
internal static Networking MainNetworking = null;
|
2021-08-18 11:47:59 +02:00
|
|
|
|
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#if !NON_INTERACTIVE
|
2021-12-15 00:25:31 +01:00
|
|
|
|
internal static MenusMain MainMenu = null;
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#endif
|
2021-12-15 00:25:31 +01:00
|
|
|
|
internal static Chat MainChat = null;
|
2022-03-28 14:49:26 +02:00
|
|
|
|
internal static PlayerList MainPlayerList = null;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-14 22:39:15 +01:00
|
|
|
|
internal static long LocalNetHandle = 0;
|
2021-12-14 14:20:41 +01:00
|
|
|
|
internal static Dictionary<long, EntitiesPlayer> Players = null;
|
2021-12-27 10:15:52 +01:00
|
|
|
|
internal static Dictionary<long, EntitiesNPC> NPCs = null;
|
2021-12-14 19:33:52 +01:00
|
|
|
|
internal static Dictionary<long, int> NPCsVehicles = null;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-03 20:30:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Don't use it!
|
|
|
|
|
/// </summary>
|
2021-07-07 13:36:25 +02:00
|
|
|
|
public Main()
|
|
|
|
|
{
|
2021-12-14 14:20:41 +01:00
|
|
|
|
// Required for some synchronization!
|
|
|
|
|
if (Game.Version < GameVersion.v1_0_1290_1_Steam)
|
|
|
|
|
{
|
|
|
|
|
Tick += (object sender, EventArgs e) =>
|
|
|
|
|
{
|
|
|
|
|
if (Game.IsLoading)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-10 14:34:55 +02:00
|
|
|
|
if (!_gameLoaded)
|
2021-12-14 14:20:41 +01:00
|
|
|
|
{
|
|
|
|
|
GTA.UI.Notification.Show("~r~Please update your GTA5 to v1.0.1290 or newer!", true);
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_gameLoaded = true;
|
2021-12-14 14:20:41 +01:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainSettings = Util.ReadSettings();
|
|
|
|
|
MainNetworking = new Networking();
|
2021-12-14 20:24:03 -07:00
|
|
|
|
#if !NON_INTERACTIVE
|
2021-12-14 14:20:41 +01:00
|
|
|
|
MainMenu = new MenusMain();
|
2021-12-14 20:24:03 -07:00
|
|
|
|
#endif
|
2021-12-14 14:20:41 +01:00
|
|
|
|
MainChat = new Chat();
|
|
|
|
|
Players = new Dictionary<long, EntitiesPlayer>();
|
2021-12-27 10:15:52 +01:00
|
|
|
|
NPCs = new Dictionary<long, EntitiesNPC>();
|
2021-12-14 19:33:52 +01:00
|
|
|
|
NPCsVehicles = new Dictionary<long, int>();
|
2021-12-14 14:20:41 +01:00
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
Tick += OnTick;
|
|
|
|
|
KeyDown += OnKeyDown;
|
2021-08-21 16:52:17 +02:00
|
|
|
|
Aborted += (object sender, EventArgs e) => CleanUp();
|
2021-07-13 16:32:45 +02:00
|
|
|
|
|
|
|
|
|
Util.NativeMemory();
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-17 19:50:47 +01:00
|
|
|
|
#if DEBUG
|
2022-04-10 14:34:55 +02:00
|
|
|
|
private ulong _lastDebugData;
|
|
|
|
|
private int _debugBytesSend;
|
|
|
|
|
private int _debugBytesReceived;
|
2021-12-17 19:50:47 +01:00
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
private void OnTick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Game.IsLoading)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-04-10 14:34:55 +02:00
|
|
|
|
else if (!_gameLoaded && (_gameLoaded = true))
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
RelationshipGroup = World.AddRelationshipGroup("SYNCPED");
|
2021-12-18 20:31:10 +01:00
|
|
|
|
Game.Player.Character.RelationshipGroup.SetRelationshipBetweenGroups(RelationshipGroup, Relationship.Neutral, true);
|
2021-12-07 22:14:15 -07:00
|
|
|
|
#if !NON_INTERACTIVE
|
2022-04-06 02:18:24 +02:00
|
|
|
|
GTA.UI.Notification.Show(GTA.UI.NotificationIcon.AllPlayersConf, "RAGECOOP", "Welcome!", "Press ~g~F9~s~ to open the menu.");
|
2021-12-07 22:14:15 -07:00
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#if !NON_INTERACTIVE
|
2021-08-06 12:31:25 +02:00
|
|
|
|
MainMenu.MenuPool.Process();
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
MainNetworking.ReceiveMessages();
|
|
|
|
|
|
2022-04-06 05:54:03 +02:00
|
|
|
|
if (!JavascriptHook.JavascriptLoaded && DownloadManager.DownloadComplete)
|
|
|
|
|
{
|
|
|
|
|
JavascriptHook.LoadAll();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-10 14:34:55 +02:00
|
|
|
|
if (_isGoingToCar && Game.Player.Character.IsInVehicle())
|
2021-07-13 08:30:10 +02:00
|
|
|
|
{
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_isGoingToCar = false;
|
2021-07-13 08:30:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
if (!MainNetworking.IsOnServer())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-18 11:47:59 +02:00
|
|
|
|
#if DEBUG
|
|
|
|
|
if (MainNetworking.ShowNetworkInfo)
|
|
|
|
|
{
|
2021-12-17 19:50:47 +01:00
|
|
|
|
ulong time = Util.GetTickCount64();
|
2022-04-10 14:34:55 +02:00
|
|
|
|
if (time - _lastDebugData > 1000)
|
2021-12-17 19:50:47 +01:00
|
|
|
|
{
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_lastDebugData = time;
|
2021-12-17 19:50:47 +01:00
|
|
|
|
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_debugBytesReceived = MainNetworking.BytesReceived;
|
2021-12-17 19:50:47 +01:00
|
|
|
|
MainNetworking.BytesReceived = 0;
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_debugBytesSend = MainNetworking.BytesSend;
|
2021-12-17 19:50:47 +01:00
|
|
|
|
MainNetworking.BytesSend = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-18 11:47:59 +02:00
|
|
|
|
new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 0), $"L: {MainNetworking.Latency * 1000:N0}ms", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw();
|
2022-04-10 14:34:55 +02:00
|
|
|
|
new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 30), $"R: {Lidgren.Network.NetUtility.ToHumanReadable(_debugBytesReceived)}/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(_debugBytesSend)}/s", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw();
|
2021-08-18 11:47:59 +02:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
MainChat.Tick();
|
2022-03-28 14:49:26 +02:00
|
|
|
|
MainPlayerList.Tick();
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-08-18 11:47:59 +02:00
|
|
|
|
#if DEBUG
|
2021-07-07 13:36:25 +02:00
|
|
|
|
if (UseDebug)
|
|
|
|
|
{
|
|
|
|
|
Debug();
|
|
|
|
|
}
|
2021-08-18 11:47:59 +02:00
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-26 23:19:12 +01:00
|
|
|
|
// Display all players
|
|
|
|
|
foreach (KeyValuePair<long, EntitiesPlayer> player in Players)
|
|
|
|
|
{
|
2022-04-10 14:34:55 +02:00
|
|
|
|
player.Value.Update();
|
2021-12-26 23:19:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-21 16:52:17 +02:00
|
|
|
|
MainNetworking.SendPlayerData();
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#if !NON_INTERACTIVE
|
2021-07-07 13:36:25 +02:00
|
|
|
|
private void OnKeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (MainChat.Focused)
|
|
|
|
|
{
|
|
|
|
|
MainChat.OnKeyDown(e.KeyCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (e.KeyCode)
|
|
|
|
|
{
|
2022-03-28 22:34:59 +02:00
|
|
|
|
case Keys.Escape:
|
|
|
|
|
Function.Call(Hash.ACTIVATE_FRONTEND_MENU, Function.Call<int>(Hash.GET_HASH_KEY, "FE_MENU_VERSION_SP_PAUSE"), false, 0);
|
|
|
|
|
break;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
case Keys.F9:
|
2021-08-06 12:31:25 +02:00
|
|
|
|
if (MainMenu.MenuPool.AreAnyVisible)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-08-06 12:31:25 +02:00
|
|
|
|
MainMenu.MainMenu.Visible = false;
|
|
|
|
|
MainMenu.SubSettings.MainMenu.Visible = false;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-08-06 12:31:25 +02:00
|
|
|
|
MainMenu.MainMenu.Visible = true;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
2021-07-13 08:30:10 +02:00
|
|
|
|
case Keys.G:
|
2022-04-10 14:34:55 +02:00
|
|
|
|
if (_isGoingToCar)
|
2021-07-13 08:30:10 +02:00
|
|
|
|
{
|
|
|
|
|
Game.Player.Character.Task.ClearAll();
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_isGoingToCar = false;
|
2021-07-13 08:30:10 +02:00
|
|
|
|
}
|
|
|
|
|
else if (!Game.Player.Character.IsInVehicle())
|
|
|
|
|
{
|
2021-08-20 17:28:13 +02:00
|
|
|
|
Vehicle veh = World.GetNearbyVehicles(Game.Player.Character, 5f).FirstOrDefault();
|
2021-12-10 15:55:45 +01:00
|
|
|
|
if (veh != null)
|
2021-07-13 08:30:10 +02:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < veh.PassengerCapacity; i++)
|
|
|
|
|
{
|
|
|
|
|
if (veh.IsSeatFree((VehicleSeat)i))
|
|
|
|
|
{
|
|
|
|
|
Game.Player.Character.Task.EnterVehicle(veh, (VehicleSeat)i);
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_isGoingToCar = true;
|
2021-07-13 08:30:10 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2021-09-28 14:44:10 +02:00
|
|
|
|
default:
|
|
|
|
|
if (Game.IsControlJustPressed(GTA.Control.MultiplayerInfo))
|
|
|
|
|
{
|
|
|
|
|
if (MainNetworking.IsOnServer())
|
|
|
|
|
{
|
2021-11-19 22:08:15 +01:00
|
|
|
|
ulong currentTimestamp = Util.GetTickCount64();
|
2022-03-28 14:49:26 +02:00
|
|
|
|
MainPlayerList.Pressed = (currentTimestamp - MainPlayerList.Pressed) < 5000 ? (currentTimestamp - 6000) : currentTimestamp;
|
2021-09-28 14:44:10 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (Game.IsControlJustPressed(GTA.Control.MpTextChatAll))
|
|
|
|
|
{
|
|
|
|
|
if (MainNetworking.IsOnServer())
|
|
|
|
|
{
|
|
|
|
|
MainChat.Focused = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-24 21:29:04 -07:00
|
|
|
|
#else
|
|
|
|
|
private void OnKeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (MainChat.Focused)
|
|
|
|
|
{
|
|
|
|
|
MainChat.OnKeyDown(e.KeyCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Game.IsControlJustPressed(GTA.Control.MultiplayerInfo))
|
|
|
|
|
{
|
|
|
|
|
if (MainNetworking.IsOnServer())
|
|
|
|
|
{
|
|
|
|
|
ulong currentTimestamp = Util.GetTickCount64();
|
|
|
|
|
PlayerList.Pressed = (currentTimestamp - PlayerList.Pressed) < 5000 ? (currentTimestamp - 6000) : currentTimestamp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (Game.IsControlJustPressed(GTA.Control.MpTextChatAll))
|
|
|
|
|
{
|
|
|
|
|
if (MainNetworking.IsOnServer())
|
|
|
|
|
{
|
|
|
|
|
MainChat.Focused = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal static void CleanUp()
|
2021-08-06 12:31:25 +02:00
|
|
|
|
{
|
2021-08-18 11:47:59 +02:00
|
|
|
|
MainChat.Clear();
|
|
|
|
|
|
2021-08-16 14:03:05 +02:00
|
|
|
|
foreach (KeyValuePair<long, EntitiesPlayer> player in Players)
|
2021-08-06 12:31:25 +02:00
|
|
|
|
{
|
|
|
|
|
player.Value.Character?.AttachedBlip?.Delete();
|
|
|
|
|
player.Value.Character?.CurrentVehicle?.Delete();
|
|
|
|
|
player.Value.Character?.Kill();
|
|
|
|
|
player.Value.Character?.Delete();
|
|
|
|
|
player.Value.PedBlip?.Delete();
|
2022-01-01 04:16:24 +01:00
|
|
|
|
player.Value.ParachuteProp?.Delete();
|
2021-08-06 12:31:25 +02:00
|
|
|
|
}
|
|
|
|
|
Players.Clear();
|
|
|
|
|
|
2021-12-27 10:15:52 +01:00
|
|
|
|
foreach (KeyValuePair<long, EntitiesNPC> npc in NPCs)
|
2021-08-06 12:31:25 +02:00
|
|
|
|
{
|
2021-12-18 09:46:42 +01:00
|
|
|
|
npc.Value.Character?.CurrentVehicle?.Delete();
|
|
|
|
|
npc.Value.Character?.Kill();
|
|
|
|
|
npc.Value.Character?.Delete();
|
2021-08-06 12:31:25 +02:00
|
|
|
|
}
|
2021-12-14 14:20:41 +01:00
|
|
|
|
NPCs.Clear();
|
2021-12-15 04:31:24 +01:00
|
|
|
|
|
|
|
|
|
NPCsVehicles.Clear();
|
2021-08-05 20:30:27 -03:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 03:25:00 +01:00
|
|
|
|
internal static readonly Dictionary<ulong, byte> CheckNativeHash = new Dictionary<ulong, byte>()
|
|
|
|
|
{
|
2022-03-25 15:45:22 +01:00
|
|
|
|
{ 0xD49F9B0955C367DE, 1 }, // Entities
|
|
|
|
|
{ 0xEF29A16337FACADB, 1 }, //
|
|
|
|
|
{ 0xB4AC7D0CF06BFE8F, 1 }, //
|
|
|
|
|
{ 0x9B62392B474F44A0, 1 }, //
|
|
|
|
|
{ 0x7DD959874C1FD534, 1 }, //
|
|
|
|
|
{ 0xAF35D0D2583051B0, 2 }, // Vehicles
|
|
|
|
|
{ 0x63C6CCA8E68AE8C8, 2 }, //
|
|
|
|
|
{ 0x509D5878EB39E842, 3 }, // Props
|
|
|
|
|
{ 0x9A294B2138ABB884, 3 }, //
|
|
|
|
|
{ 0x46818D79B1F7499A, 4 }, // Blips
|
|
|
|
|
{ 0x5CDE92C702A8FCE7, 4 }, //
|
|
|
|
|
{ 0xBE339365C863BD36, 4 }, //
|
|
|
|
|
{ 0x5A039BB0BCA604B6, 4 }, //
|
|
|
|
|
{ 0x0134F0835AB6BFCB, 5 } // Checkpoints
|
2021-12-26 03:25:00 +01:00
|
|
|
|
};
|
|
|
|
|
internal static Dictionary<int, byte> ServerItems = new Dictionary<int, byte>();
|
|
|
|
|
internal static void CleanUpWorld()
|
|
|
|
|
{
|
|
|
|
|
if (ServerItems.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lock (ServerItems)
|
|
|
|
|
{
|
|
|
|
|
foreach (KeyValuePair<int, byte> item in ServerItems)
|
|
|
|
|
{
|
2021-12-26 23:19:12 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
switch (item.Value)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
World.GetAllEntities().FirstOrDefault(x => x.Handle == item.Key)?.Delete();
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
World.GetAllVehicles().FirstOrDefault(x => x.Handle == item.Key)?.Delete();
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
World.GetAllProps().FirstOrDefault(x => x.Handle == item.Key)?.Delete();
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
Blip blip = new Blip(item.Key);
|
|
|
|
|
if (blip.Exists())
|
|
|
|
|
{
|
|
|
|
|
blip.Delete();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
Checkpoint checkpoint = new Checkpoint(item.Key);
|
|
|
|
|
if (checkpoint.Exists())
|
|
|
|
|
{
|
|
|
|
|
checkpoint.Delete();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
2021-12-26 03:25:00 +01:00
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~CleanUpWorld() Error");
|
|
|
|
|
Logger.Write($"CleanUpWorld(): ~r~Item {item.Value} cannot be deleted!", Logger.LogLevel.Server);
|
2021-12-26 03:25:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerItems.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-22 13:59:15 +02:00
|
|
|
|
#if DEBUG
|
2022-04-10 14:34:55 +02:00
|
|
|
|
private ulong _artificialLagCounter;
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal static EntitiesPlayer DebugSyncPed;
|
|
|
|
|
internal static ulong LastFullDebugSync = 0;
|
|
|
|
|
internal static bool UseDebug = false;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
private void Debug()
|
|
|
|
|
{
|
2021-08-13 15:20:26 +02:00
|
|
|
|
Ped player = Game.Player.Character;
|
2021-12-15 03:31:57 +01:00
|
|
|
|
|
2021-08-16 14:03:05 +02:00
|
|
|
|
if (!Players.ContainsKey(0))
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-12-17 23:58:32 +01:00
|
|
|
|
Players.Add(0, new EntitiesPlayer() { Username = "DebugPlayer" });
|
2021-08-16 14:03:05 +02:00
|
|
|
|
DebugSyncPed = Players[0];
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-10 14:34:55 +02:00
|
|
|
|
if ((Util.GetTickCount64() - _artificialLagCounter) < 231)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-07-10 09:41:17 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2022-04-08 22:30:34 +02:00
|
|
|
|
bool fullSync = (Util.GetTickCount64() - LastFullDebugSync) > 39;
|
2021-08-15 11:33:52 +02:00
|
|
|
|
|
|
|
|
|
if (fullSync)
|
2021-07-10 09:41:17 +02:00
|
|
|
|
{
|
|
|
|
|
DebugSyncPed.ModelHash = player.Model.Hash;
|
2021-12-16 22:05:40 +01:00
|
|
|
|
DebugSyncPed.Clothes = player.GetPedClothes();
|
2021-07-10 09:41:17 +02:00
|
|
|
|
}
|
|
|
|
|
DebugSyncPed.Health = player.Health;
|
|
|
|
|
DebugSyncPed.Position = player.Position;
|
|
|
|
|
|
2021-12-23 22:03:01 +01:00
|
|
|
|
ushort? flags;
|
2021-07-10 23:41:28 +02:00
|
|
|
|
|
2021-12-13 20:35:07 +01:00
|
|
|
|
if (player.IsInVehicle())
|
2021-07-10 09:41:17 +02:00
|
|
|
|
{
|
2021-12-13 20:35:07 +01:00
|
|
|
|
Vehicle veh = player.CurrentVehicle;
|
2021-07-12 07:06:52 +02:00
|
|
|
|
veh.Opacity = 75;
|
|
|
|
|
|
2021-12-23 22:03:01 +01:00
|
|
|
|
flags = player.GetVehicleFlags(veh);
|
2021-07-10 23:41:28 +02:00
|
|
|
|
|
2021-12-16 22:05:40 +01:00
|
|
|
|
byte secondaryColor;
|
|
|
|
|
byte primaryColor;
|
2021-08-13 15:52:30 +02:00
|
|
|
|
unsafe
|
|
|
|
|
{
|
2021-12-16 22:05:40 +01:00
|
|
|
|
Function.Call<byte>(Hash.GET_VEHICLE_COLOURS, veh, &primaryColor, &secondaryColor);
|
2021-08-13 15:52:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 09:41:17 +02:00
|
|
|
|
DebugSyncPed.VehicleModelHash = veh.Model.Hash;
|
2021-12-16 22:05:40 +01:00
|
|
|
|
DebugSyncPed.VehicleSeatIndex = (short)player.SeatIndex;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
DebugSyncPed.Position = veh.Position;
|
2021-07-10 09:41:17 +02:00
|
|
|
|
DebugSyncPed.VehicleRotation = veh.Quaternion;
|
2021-08-17 15:04:50 +02:00
|
|
|
|
DebugSyncPed.VehicleEngineHealth = veh.EngineHealth;
|
2021-11-19 08:40:40 +01:00
|
|
|
|
DebugSyncPed.VehRPM = veh.CurrentRPM;
|
2022-03-20 09:21:41 +01:00
|
|
|
|
DebugSyncPed.Velocity = veh.Velocity;
|
2021-07-10 10:52:43 +02:00
|
|
|
|
DebugSyncPed.VehicleSpeed = veh.Speed;
|
2021-07-13 16:30:33 +02:00
|
|
|
|
DebugSyncPed.VehicleSteeringAngle = veh.SteeringAngle;
|
2021-12-06 00:56:08 +01:00
|
|
|
|
DebugSyncPed.AimCoords = veh.IsTurretSeat((int)player.SeatIndex) ? Util.GetVehicleAimCoords() : new GTA.Math.Vector3();
|
2021-12-16 22:05:40 +01:00
|
|
|
|
DebugSyncPed.VehicleColors = new byte[] { primaryColor, secondaryColor };
|
2021-11-19 08:40:40 +01:00
|
|
|
|
DebugSyncPed.VehicleMods = veh.Mods.GetVehicleMods();
|
2021-12-23 22:03:01 +01:00
|
|
|
|
DebugSyncPed.VehDamageModel = veh.GetVehicleDamageModel();
|
2021-12-13 23:18:15 +01:00
|
|
|
|
DebugSyncPed.LastSyncWasFull = true;
|
2021-11-19 09:24:06 +01:00
|
|
|
|
DebugSyncPed.IsInVehicle = true;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
DebugSyncPed.VehIsEngineRunning = (flags.Value & (ushort)VehicleDataFlags.IsEngineRunning) > 0;
|
|
|
|
|
DebugSyncPed.VehAreLightsOn = (flags.Value & (ushort)VehicleDataFlags.AreLightsOn) > 0;
|
2022-01-01 17:24:55 +01:00
|
|
|
|
DebugSyncPed.VehAreBrakeLightsOn = (flags.Value & (ushort)VehicleDataFlags.AreBrakeLightsOn) > 0;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
DebugSyncPed.VehAreHighBeamsOn = (flags.Value & (ushort)VehicleDataFlags.AreHighBeamsOn) > 0;
|
|
|
|
|
DebugSyncPed.VehIsSireneActive = (flags.Value & (ushort)VehicleDataFlags.IsSirenActive) > 0;
|
|
|
|
|
DebugSyncPed.VehicleDead = (flags.Value & (ushort)VehicleDataFlags.IsDead) > 0;
|
|
|
|
|
DebugSyncPed.IsHornActive = (flags.Value & (ushort)VehicleDataFlags.IsHornActive) > 0;
|
|
|
|
|
DebugSyncPed.Transformed = (flags.Value & (ushort)VehicleDataFlags.IsTransformed) > 0;
|
|
|
|
|
DebugSyncPed.VehRoofOpened = (flags.Value & (ushort)VehicleDataFlags.RoofOpened) > 0;
|
2021-12-14 14:46:10 +01:00
|
|
|
|
DebugSyncPed.VehLandingGear = veh.IsPlane ? (byte)veh.LandingGearState : (byte)0;
|
2022-01-01 17:24:55 +01:00
|
|
|
|
|
2021-08-04 18:54:56 +02:00
|
|
|
|
if (DebugSyncPed.MainVehicle != null && DebugSyncPed.MainVehicle.Exists() && player.IsInVehicle())
|
|
|
|
|
{
|
2021-11-19 10:44:16 +01:00
|
|
|
|
Function.Call(Hash.SET_ENTITY_NO_COLLISION_ENTITY, DebugSyncPed.MainVehicle.Handle, veh.Handle, false);
|
|
|
|
|
Function.Call(Hash.SET_ENTITY_NO_COLLISION_ENTITY, veh.Handle, DebugSyncPed.MainVehicle.Handle, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-13 23:18:15 +01:00
|
|
|
|
flags = player.GetPedFlags(true);
|
2021-11-19 10:44:16 +01:00
|
|
|
|
|
|
|
|
|
DebugSyncPed.Rotation = player.Rotation;
|
|
|
|
|
DebugSyncPed.Velocity = player.Velocity;
|
|
|
|
|
DebugSyncPed.Speed = player.GetPedSpeed();
|
|
|
|
|
DebugSyncPed.AimCoords = player.GetPedAimCoords(false);
|
2021-12-15 03:31:57 +01:00
|
|
|
|
DebugSyncPed.CurrentWeaponHash = (uint)player.Weapons.Current.Hash;
|
2021-12-15 01:25:16 +01:00
|
|
|
|
DebugSyncPed.WeaponComponents = player.Weapons.Current.GetWeaponComponents();
|
2021-12-13 23:18:15 +01:00
|
|
|
|
DebugSyncPed.LastSyncWasFull = true;
|
2021-12-28 19:14:51 +01:00
|
|
|
|
DebugSyncPed.IsAiming = (flags.Value & (ushort)PedDataFlags.IsAiming) > 0;
|
|
|
|
|
DebugSyncPed.IsShooting = (flags.Value & (ushort)PedDataFlags.IsShooting) > 0;
|
|
|
|
|
DebugSyncPed.IsReloading = (flags.Value & (ushort)PedDataFlags.IsReloading) > 0;
|
|
|
|
|
DebugSyncPed.IsJumping = (flags.Value & (ushort)PedDataFlags.IsJumping) > 0;
|
|
|
|
|
DebugSyncPed.IsRagdoll = (flags.Value & (ushort)PedDataFlags.IsRagdoll) > 0;
|
|
|
|
|
DebugSyncPed.IsOnFire = (flags.Value & (ushort)PedDataFlags.IsOnFire) > 0;
|
|
|
|
|
DebugSyncPed.IsInParachuteFreeFall = (flags.Value & (ushort)PedDataFlags.IsInParachuteFreeFall) > 0;
|
2022-01-01 04:16:24 +01:00
|
|
|
|
DebugSyncPed.IsParachuteOpen = (flags.Value & (ushort)PedDataFlags.IsParachuteOpen) > 0;
|
2021-12-28 19:14:51 +01:00
|
|
|
|
DebugSyncPed.IsOnLadder = (flags.Value & (ushort)PedDataFlags.IsOnLadder) > 0;
|
|
|
|
|
DebugSyncPed.IsVaulting = (flags.Value & (ushort)PedDataFlags.IsVaulting) > 0;
|
2021-11-19 10:44:16 +01:00
|
|
|
|
DebugSyncPed.IsInVehicle = false;
|
|
|
|
|
|
|
|
|
|
if (DebugSyncPed.Character != null && DebugSyncPed.Character.Exists())
|
|
|
|
|
{
|
|
|
|
|
Function.Call(Hash.SET_ENTITY_NO_COLLISION_ENTITY, DebugSyncPed.Character.Handle, player.Handle, false);
|
|
|
|
|
Function.Call(Hash.SET_ENTITY_NO_COLLISION_ENTITY, player.Handle, DebugSyncPed.Character.Handle, false);
|
2021-08-04 18:54:56 +02:00
|
|
|
|
}
|
2021-07-10 09:41:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 22:08:15 +01:00
|
|
|
|
ulong currentTimestamp = Util.GetTickCount64();
|
2021-08-15 11:33:52 +02:00
|
|
|
|
|
|
|
|
|
DebugSyncPed.LastUpdateReceived = currentTimestamp;
|
2022-04-10 14:34:55 +02:00
|
|
|
|
DebugSyncPed.Latency = (currentTimestamp - _artificialLagCounter) / 1000f;
|
2021-08-15 11:33:52 +02:00
|
|
|
|
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_artificialLagCounter = currentTimestamp;
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2021-08-15 11:33:52 +02:00
|
|
|
|
if (fullSync)
|
|
|
|
|
{
|
|
|
|
|
LastFullDebugSync = currentTimestamp;
|
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
2021-08-22 13:59:15 +02:00
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|