2022-10-23 19:02:39 +08:00
|
|
|
|
using System;
|
2022-10-08 12:43:24 +08:00
|
|
|
|
using System.Collections.Concurrent;
|
2022-07-20 17:50:01 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
2022-08-02 17:43:18 +08:00
|
|
|
|
using System.Drawing;
|
2022-09-06 21:46:35 +08:00
|
|
|
|
using System.IO;
|
2023-02-12 22:06:57 +08:00
|
|
|
|
using System.Reflection;
|
2023-01-28 20:51:29 +08:00
|
|
|
|
using System.Threading;
|
2022-10-23 19:02:39 +08:00
|
|
|
|
using GTA;
|
|
|
|
|
using GTA.Math;
|
|
|
|
|
using GTA.Native;
|
|
|
|
|
using GTA.UI;
|
|
|
|
|
using LemonUI.Elements;
|
|
|
|
|
using LemonUI.Menus;
|
|
|
|
|
using Lidgren.Network;
|
|
|
|
|
using RageCoop.Client.Menus;
|
|
|
|
|
using RageCoop.Client.Scripting;
|
|
|
|
|
using RageCoop.Core;
|
|
|
|
|
using Control = GTA.Control;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
namespace RageCoop.Client
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
[ScriptAttributes(Author = "RageCoop", SupportURL = "https://github.com/RAGECOOP/RAGECOOP-V", NoScriptThread = true)]
|
2022-05-23 11:10:11 +08:00
|
|
|
|
internal class Main : Script
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2023-02-13 20:44:50 +08:00
|
|
|
|
internal static Version ModVersion = typeof(Main).Assembly.GetName().Version;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2022-07-20 17:50:01 +08:00
|
|
|
|
internal static int LocalPlayerID = 0;
|
2022-05-31 09:14:30 +08:00
|
|
|
|
|
2022-05-23 11:10:11 +08:00
|
|
|
|
internal static RelationshipGroup SyncedPedsGroup;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2023-02-13 20:44:50 +08:00
|
|
|
|
internal static ClientSettings Settings = null;
|
2022-06-12 15:39:32 +08:00
|
|
|
|
internal static Chat MainChat = null;
|
2023-02-13 20:44:50 +08:00
|
|
|
|
internal static Stopwatch Counter = new();
|
2023-02-13 17:51:18 +08:00
|
|
|
|
internal static Logger Log = null;
|
2022-06-12 15:39:32 +08:00
|
|
|
|
internal static ulong Ticked = 0;
|
2022-07-17 11:15:02 +08:00
|
|
|
|
internal static Vector3 PlayerPosition;
|
2023-02-13 17:51:18 +08:00
|
|
|
|
internal static Resources MainRes = null;
|
2022-10-23 19:02:39 +08:00
|
|
|
|
|
|
|
|
|
public static Ped P;
|
|
|
|
|
public static float FPS;
|
|
|
|
|
private static bool _lastDead;
|
2022-11-05 18:35:39 +08:00
|
|
|
|
public static bool CefRunning;
|
2023-01-28 20:51:29 +08:00
|
|
|
|
public static bool IsUnloading { get; private set; }
|
2022-10-23 19:02:39 +08:00
|
|
|
|
|
2021-12-03 20:30:00 +01:00
|
|
|
|
/// <summary>
|
2022-10-23 19:02:39 +08:00
|
|
|
|
/// Don't use it!
|
2021-12-03 20:30:00 +01:00
|
|
|
|
/// </summary>
|
2021-07-07 13:36:25 +02:00
|
|
|
|
public Main()
|
2022-08-27 14:23:28 +08:00
|
|
|
|
{
|
2022-11-16 17:37:31 +08:00
|
|
|
|
Directory.CreateDirectory(DataPath);
|
2022-07-14 17:59:41 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Settings = Util.ReadSettings();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2022-11-16 17:37:31 +08:00
|
|
|
|
Notification.Show("Malformed configuration, overwriting with default values...");
|
2023-02-13 20:44:50 +08:00
|
|
|
|
Settings = new();
|
2022-07-14 17:59:41 +08:00
|
|
|
|
Util.SaveSettings();
|
|
|
|
|
}
|
2022-10-23 19:02:39 +08:00
|
|
|
|
|
2023-02-13 17:51:18 +08:00
|
|
|
|
Log = new Logger()
|
2022-05-31 19:35:01 -08:00
|
|
|
|
{
|
2022-10-15 13:52:49 +08:00
|
|
|
|
Writers = new List<StreamWriter> { CoreUtils.OpenWriter(LogPath) },
|
2022-05-31 19:35:01 -08:00
|
|
|
|
#if DEBUG
|
|
|
|
|
LogLevel = 0,
|
|
|
|
|
#else
|
2022-10-10 16:45:58 +08:00
|
|
|
|
LogLevel = Settings.LogLevel,
|
2022-05-31 19:35:01 -08:00
|
|
|
|
#endif
|
|
|
|
|
};
|
2023-02-13 17:51:18 +08:00
|
|
|
|
Log.OnFlush += (line, formatted) =>
|
2022-10-15 11:09:17 +08:00
|
|
|
|
{
|
|
|
|
|
switch (line.LogLevel)
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
// case LogLevel.Trace:
|
|
|
|
|
case LogLevel.Debug:
|
2023-01-28 20:51:29 +08:00
|
|
|
|
Console.PrintInfo(line.Message);
|
2022-10-15 11:09:17 +08:00
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
case LogLevel.Info:
|
2023-01-28 20:51:29 +08:00
|
|
|
|
Console.PrintInfo(line.Message);
|
2022-10-15 11:09:17 +08:00
|
|
|
|
break;
|
|
|
|
|
case LogLevel.Warning:
|
2023-01-28 20:51:29 +08:00
|
|
|
|
Console.PrintWarning(line.Message);
|
2022-10-15 11:09:17 +08:00
|
|
|
|
break;
|
|
|
|
|
case LogLevel.Error:
|
2023-01-28 20:51:29 +08:00
|
|
|
|
Console.PrintError(line.Message);
|
2022-10-15 11:09:17 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-11-30 19:08:52 +08:00
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
2022-08-14 13:04:39 +08:00
|
|
|
|
|
2023-01-28 20:51:29 +08:00
|
|
|
|
protected override void OnAborted(AbortedEventArgs e)
|
2022-10-08 12:43:24 +08:00
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
base.OnAborted(e);
|
2022-10-08 12:43:24 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
IsUnloading = e.IsUnloading;
|
2022-11-05 18:35:39 +08:00
|
|
|
|
CleanUp("Abort");
|
2022-10-10 16:45:58 +08:00
|
|
|
|
WorldThread.DoQueuedActions();
|
2023-01-28 20:51:29 +08:00
|
|
|
|
if (IsUnloading)
|
|
|
|
|
{
|
2023-02-03 13:30:37 +08:00
|
|
|
|
ThreadManager.OnUnload();
|
2023-02-13 20:44:50 +08:00
|
|
|
|
Log.Dispose();
|
2023-01-28 20:51:29 +08:00
|
|
|
|
}
|
2022-10-08 12:43:24 +08:00
|
|
|
|
}
|
2022-10-08 23:49:48 +08:00
|
|
|
|
catch (Exception ex)
|
2022-10-08 12:43:24 +08:00
|
|
|
|
{
|
2023-02-13 17:51:18 +08:00
|
|
|
|
Log.Error(ex);
|
2022-10-08 12:43:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-28 20:51:29 +08:00
|
|
|
|
protected override void OnStart()
|
2022-10-08 12:43:24 +08:00
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
base.OnStart();
|
|
|
|
|
|
|
|
|
|
if (Game.Version < GameVersion.v1_0_1290_1_Steam)
|
2022-10-23 19:02:39 +08:00
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
throw new NotSupportedException("Please update your GTA5 to v1.0.1290 or newer!");
|
2022-10-23 19:02:39 +08:00
|
|
|
|
}
|
2022-10-08 12:43:24 +08:00
|
|
|
|
|
2023-02-13 17:51:18 +08:00
|
|
|
|
MainRes = new Resources();
|
2023-01-28 20:51:29 +08:00
|
|
|
|
|
2023-02-12 22:06:57 +08:00
|
|
|
|
|
2023-01-28 20:51:29 +08:00
|
|
|
|
|
2023-02-13 17:51:18 +08:00
|
|
|
|
Log.Info(
|
2023-01-28 20:51:29 +08:00
|
|
|
|
$"Main script initialized");
|
|
|
|
|
|
|
|
|
|
BaseScript.OnStart();
|
|
|
|
|
SyncedPedsGroup = World.AddRelationshipGroup("SYNCPED");
|
|
|
|
|
Game.Player.Character.RelationshipGroup.SetRelationshipBetweenGroups(SyncedPedsGroup, Relationship.Neutral,
|
|
|
|
|
true);
|
|
|
|
|
MainChat = new Chat();
|
|
|
|
|
|
|
|
|
|
Util.NativeMemory();
|
|
|
|
|
Counter.Restart();
|
2023-02-12 22:06:57 +08:00
|
|
|
|
|
2023-01-28 20:51:29 +08:00
|
|
|
|
}
|
|
|
|
|
protected override void OnTick()
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
base.OnTick();
|
2022-09-06 21:46:35 +08:00
|
|
|
|
P = Game.Player.Character;
|
|
|
|
|
PlayerPosition = P.ReadPosition();
|
|
|
|
|
FPS = Game.FPS;
|
2023-01-28 20:51:29 +08:00
|
|
|
|
#if CEF
|
2022-11-05 18:35:39 +08:00
|
|
|
|
if (CefRunning)
|
|
|
|
|
{
|
|
|
|
|
CefManager.Tick();
|
|
|
|
|
}
|
2023-01-28 20:51:29 +08:00
|
|
|
|
#endif
|
2022-05-25 11:32:34 +08:00
|
|
|
|
if (!Networking.IsOnServer)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-30 19:08:52 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
EntityPool.DoSync();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-02-13 17:51:18 +08:00
|
|
|
|
Log.Error(ex);
|
2022-11-30 19:08:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-28 20:51:29 +08:00
|
|
|
|
|
2022-11-30 19:08:52 +08:00
|
|
|
|
if (Game.TimeScale != 1.0f)
|
2022-04-11 15:10:27 +02:00
|
|
|
|
{
|
2022-09-06 21:46:35 +08:00
|
|
|
|
Game.TimeScale = 1;
|
2022-04-11 15:10:27 +02:00
|
|
|
|
}
|
2022-07-20 17:50:01 +08:00
|
|
|
|
|
2022-05-23 16:59:49 +08:00
|
|
|
|
if (Networking.ShowNetworkInfo)
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
new ScaledText(new PointF(200, 0),
|
2022-11-05 18:35:39 +08:00
|
|
|
|
$"L: {Networking.Latency * 1000:N0}ms", 0.5f)
|
2023-01-28 20:51:29 +08:00
|
|
|
|
{ Alignment = Alignment.Center }.Draw();
|
|
|
|
|
new ScaledText(new PointF(200, 30),
|
2022-10-23 19:02:39 +08:00
|
|
|
|
$"R: {NetUtility.ToHumanReadable(Statistics.BytesDownPerSecond)}/s", 0.5f)
|
2023-01-28 20:51:29 +08:00
|
|
|
|
{ Alignment = Alignment.Center }.Draw();
|
|
|
|
|
new ScaledText(new PointF(200, 60),
|
2022-10-23 19:02:39 +08:00
|
|
|
|
$"S: {NetUtility.ToHumanReadable(Statistics.BytesUpPerSecond)}/s", 0.5f)
|
2023-01-28 20:51:29 +08:00
|
|
|
|
{ Alignment = Alignment.Center }.Draw();
|
2021-08-18 11:47:59 +02:00
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
MainChat.Tick();
|
2022-05-23 16:59:49 +08:00
|
|
|
|
PlayerList.Tick();
|
2022-10-08 12:43:24 +08:00
|
|
|
|
if (!API.Config.EnableAutoRespawn)
|
2022-05-31 02:16:12 -08:00
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
Call(PAUSE_DEATH_ARREST_RESTART, true);
|
|
|
|
|
Call(IGNORE_NEXT_RESTART, true);
|
|
|
|
|
Call(FORCE_GAME_STATE_PLAYING);
|
|
|
|
|
Call(TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "respawn_controller");
|
2022-05-31 02:16:12 -08:00
|
|
|
|
if (P.IsDead)
|
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
Call(SET_FADE_OUT_AFTER_DEATH, false);
|
2022-07-20 17:50:01 +08:00
|
|
|
|
|
2022-09-06 21:46:35 +08:00
|
|
|
|
if (P.Health != 1)
|
2022-05-31 02:16:12 -08:00
|
|
|
|
{
|
2022-09-06 21:46:35 +08:00
|
|
|
|
P.Health = 1;
|
|
|
|
|
Game.Player.WantedLevel = 0;
|
2023-02-13 17:51:18 +08:00
|
|
|
|
Log.Debug("Player died.");
|
2022-10-08 12:43:24 +08:00
|
|
|
|
API.Events.InvokePlayerDied();
|
2022-05-31 02:16:12 -08:00
|
|
|
|
}
|
2022-10-23 19:02:39 +08:00
|
|
|
|
|
2023-01-28 20:51:29 +08:00
|
|
|
|
Screen.StopEffects();
|
2022-05-31 02:16:12 -08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
Call(DISPLAY_HUD, true);
|
2022-05-31 02:16:12 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-21 08:41:05 +08:00
|
|
|
|
else if (P.IsDead && !_lastDead)
|
|
|
|
|
{
|
2022-10-08 23:49:48 +08:00
|
|
|
|
API.Events.InvokePlayerDied();
|
2022-07-21 08:41:05 +08:00
|
|
|
|
}
|
2022-09-06 21:46:35 +08:00
|
|
|
|
|
|
|
|
|
_lastDead = P.IsDead;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
Ticked++;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
2022-10-23 19:02:39 +08:00
|
|
|
|
|
2023-01-28 20:51:29 +08:00
|
|
|
|
protected override void OnKeyUp(GTA.KeyEventArgs e)
|
2022-11-05 18:35:39 +08:00
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
base.OnKeyUp(e);
|
|
|
|
|
#if CEF
|
2022-11-05 18:35:39 +08:00
|
|
|
|
if (CefRunning)
|
|
|
|
|
{
|
|
|
|
|
CefManager.KeyUp(e.KeyCode);
|
|
|
|
|
}
|
2023-01-28 20:51:29 +08:00
|
|
|
|
#endif
|
2022-11-05 18:35:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-28 20:51:29 +08:00
|
|
|
|
protected unsafe override void OnKeyDown(KeyEventArgs e)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
base.OnKeyDown(e);
|
2022-08-13 02:19:40 +02:00
|
|
|
|
if (MainChat.Focused)
|
|
|
|
|
{
|
|
|
|
|
MainChat.OnKeyDown(e.KeyCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-28 20:51:29 +08:00
|
|
|
|
#if CEF
|
2022-11-05 18:35:39 +08:00
|
|
|
|
if (CefRunning)
|
|
|
|
|
{
|
|
|
|
|
CefManager.KeyDown(e.KeyCode);
|
|
|
|
|
}
|
2023-01-28 20:51:29 +08:00
|
|
|
|
#endif
|
2022-08-13 02:19:40 +02:00
|
|
|
|
if (Networking.IsOnServer)
|
2022-08-13 00:52:34 +02:00
|
|
|
|
{
|
2022-08-15 16:13:53 +08:00
|
|
|
|
if (Voice.WasInitialized())
|
2022-08-13 00:52:34 +02:00
|
|
|
|
{
|
2022-10-23 19:02:39 +08:00
|
|
|
|
if (Game.IsControlPressed(Control.PushToTalk))
|
2022-08-13 03:39:11 +02:00
|
|
|
|
{
|
2022-08-15 16:13:53 +08:00
|
|
|
|
Voice.StartRecording();
|
2022-08-13 03:39:11 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-05 18:35:39 +08:00
|
|
|
|
|
|
|
|
|
if (Voice.IsRecording())
|
2022-08-13 03:39:11 +02:00
|
|
|
|
{
|
2022-08-15 16:13:53 +08:00
|
|
|
|
Voice.StopRecording();
|
2022-08-13 03:39:11 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-08-13 00:52:34 +02:00
|
|
|
|
}
|
2022-09-06 21:46:35 +08:00
|
|
|
|
|
2022-10-23 19:02:39 +08:00
|
|
|
|
if (Game.IsControlPressed(Control.FrontendPause))
|
2022-05-25 21:54:25 +08:00
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
Call(ACTIVATE_FRONTEND_MENU,
|
2023-02-12 22:06:57 +08:00
|
|
|
|
SHVDN.NativeMemory.GetHashKey("FE_MENU_VERSION_SP_PAUSE"), false, 0);
|
2022-05-25 21:54:25 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-10-23 19:02:39 +08:00
|
|
|
|
|
|
|
|
|
if (Game.IsControlPressed(Control.FrontendPauseAlternate) && Settings.DisableAlternatePause)
|
2022-05-25 21:54:25 +08:00
|
|
|
|
{
|
2023-01-28 20:51:29 +08:00
|
|
|
|
Call(ACTIVATE_FRONTEND_MENU,
|
2023-02-12 22:06:57 +08:00
|
|
|
|
SHVDN.NativeMemory.GetHashKey("FE_MENU_VERSION_SP_PAUSE"), false, 0);
|
2022-05-25 21:54:25 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-25 11:32:34 +08:00
|
|
|
|
}
|
2022-10-23 19:02:39 +08:00
|
|
|
|
|
2022-05-25 11:32:34 +08:00
|
|
|
|
if (e.KeyCode == Settings.MenuKey)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-05-31 09:14:30 +08:00
|
|
|
|
if (CoopMenu.MenuPool.AreAnyVisible)
|
2022-05-23 11:10:11 +08:00
|
|
|
|
{
|
2022-10-23 19:02:39 +08:00
|
|
|
|
CoopMenu.MenuPool.ForEach<NativeMenu>(x =>
|
2022-05-31 09:14:30 +08:00
|
|
|
|
{
|
|
|
|
|
if (x.Visible)
|
|
|
|
|
{
|
2022-09-06 21:46:35 +08:00
|
|
|
|
CoopMenu.LastMenu = x;
|
|
|
|
|
x.Visible = false;
|
2022-05-31 09:14:30 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2022-05-23 11:10:11 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-05-31 09:14:30 +08:00
|
|
|
|
CoopMenu.LastMenu.Visible = true;
|
2022-05-23 11:10:11 +08:00
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
2022-10-23 19:02:39 +08:00
|
|
|
|
else if (Game.IsControlJustPressed(Control.MpTextChatAll))
|
2022-08-16 22:16:18 +08:00
|
|
|
|
{
|
|
|
|
|
if (Networking.IsOnServer)
|
|
|
|
|
{
|
|
|
|
|
MainChat.Focused = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-23 19:02:39 +08:00
|
|
|
|
else if (MainChat.Focused)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (Game.IsControlJustPressed(Control.MultiplayerInfo))
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-05-25 11:32:34 +08:00
|
|
|
|
if (Networking.IsOnServer)
|
2022-05-23 11:10:11 +08:00
|
|
|
|
{
|
|
|
|
|
ulong currentTimestamp = Util.GetTickCount64();
|
2022-10-23 19:02:39 +08:00
|
|
|
|
PlayerList.Pressed = (currentTimestamp - PlayerList.Pressed) < 5000
|
|
|
|
|
? (currentTimestamp - 6000)
|
|
|
|
|
: currentTimestamp;
|
2022-05-23 11:10:11 +08:00
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
2022-09-06 21:46:35 +08:00
|
|
|
|
else if (e.KeyCode == Settings.PassengerKey)
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-11-05 18:35:39 +08:00
|
|
|
|
if (P == null || P.IsInVehicle())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-20 17:50:01 +08:00
|
|
|
|
|
2022-11-05 18:35:39 +08:00
|
|
|
|
if (P.IsTaskActive(TaskType.CTaskEnterVehicle))
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-11-05 18:35:39 +08:00
|
|
|
|
P.Task.ClearAll();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var V = World.GetClosestVehicle(P.ReadPosition(), 15);
|
2022-05-23 11:10:11 +08:00
|
|
|
|
|
2022-11-05 18:35:39 +08:00
|
|
|
|
if (V != null)
|
|
|
|
|
{
|
|
|
|
|
var seat = P.GetNearestSeat(V);
|
|
|
|
|
var p = V.GetPedOnSeat(seat);
|
|
|
|
|
if (p != null && !p.IsDead)
|
2022-05-23 11:10:11 +08:00
|
|
|
|
{
|
2022-11-05 18:35:39 +08:00
|
|
|
|
for (int i = -1; i < V.PassengerCapacity; i++)
|
2022-08-21 14:12:44 +08:00
|
|
|
|
{
|
2022-11-05 18:35:39 +08:00
|
|
|
|
seat = (VehicleSeat)i;
|
|
|
|
|
p = V.GetPedOnSeat(seat);
|
|
|
|
|
if (p == null || p.IsDead)
|
2022-08-21 14:12:44 +08:00
|
|
|
|
{
|
2022-11-05 18:35:39 +08:00
|
|
|
|
break;
|
2022-08-21 14:12:44 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-23 11:10:11 +08:00
|
|
|
|
}
|
2022-11-05 18:35:39 +08:00
|
|
|
|
|
|
|
|
|
P.Task.EnterVehicle(V, seat, -1, 5, EnterVehicleFlags.None);
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
2022-10-23 19:02:39 +08:00
|
|
|
|
|
2022-09-06 21:46:35 +08:00
|
|
|
|
internal static void Connected()
|
|
|
|
|
{
|
|
|
|
|
Memory.ApplyPatches();
|
|
|
|
|
if (Settings.Voice && !Voice.WasInitialized())
|
|
|
|
|
{
|
|
|
|
|
Voice.Init();
|
|
|
|
|
}
|
2022-10-23 19:02:39 +08:00
|
|
|
|
|
2022-10-09 11:15:09 +08:00
|
|
|
|
API.QueueAction(() =>
|
2022-09-06 21:46:35 +08:00
|
|
|
|
{
|
|
|
|
|
WorldThread.Traffic(!Settings.DisableTraffic);
|
2023-01-28 20:51:29 +08:00
|
|
|
|
Call(SET_ENABLE_VEHICLE_SLIPSTREAMING, true);
|
2022-09-06 21:46:35 +08:00
|
|
|
|
CoopMenu.ConnectedMenuSetting();
|
|
|
|
|
MainChat.Init();
|
2022-10-23 19:02:39 +08:00
|
|
|
|
Notification.Show("~g~Connected!");
|
2022-09-06 21:46:35 +08:00
|
|
|
|
});
|
|
|
|
|
|
2023-02-13 17:51:18 +08:00
|
|
|
|
Log.Info(">> Connected <<");
|
2022-09-06 21:46:35 +08:00
|
|
|
|
}
|
2022-10-23 19:02:39 +08:00
|
|
|
|
|
2023-02-13 20:44:50 +08:00
|
|
|
|
private static readonly object _cleanupLock = new();
|
2022-11-05 18:35:39 +08:00
|
|
|
|
public static void CleanUp(string reason)
|
2021-08-06 12:31:25 +02:00
|
|
|
|
{
|
2023-02-13 20:44:50 +08:00
|
|
|
|
lock (_cleanupLock)
|
2022-11-05 18:35:39 +08:00
|
|
|
|
{
|
|
|
|
|
|
2023-02-13 20:44:50 +08:00
|
|
|
|
if (reason != "Abort")
|
|
|
|
|
{
|
|
|
|
|
Log.Info($">> Disconnected << reason: {reason}");
|
|
|
|
|
Notification.Show("~r~Disconnected: " + reason);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-06 21:46:35 +08:00
|
|
|
|
if (MainChat.Focused)
|
|
|
|
|
{
|
|
|
|
|
MainChat.Focused = false;
|
|
|
|
|
}
|
2022-10-23 19:02:39 +08:00
|
|
|
|
|
2022-09-07 09:52:40 +08:00
|
|
|
|
PlayerList.Cleanup();
|
2022-09-06 21:46:35 +08:00
|
|
|
|
MainChat.Clear();
|
|
|
|
|
EntityPool.Cleanup();
|
|
|
|
|
WorldThread.Traffic(true);
|
2023-01-28 20:51:29 +08:00
|
|
|
|
Call(SET_ENABLE_VEHICLE_SLIPSTREAMING, false);
|
2022-09-06 21:46:35 +08:00
|
|
|
|
CoopMenu.DisconnectedMenuSetting();
|
2022-09-07 09:52:40 +08:00
|
|
|
|
LocalPlayerID = default;
|
2023-02-13 17:51:18 +08:00
|
|
|
|
MainRes.Unload();
|
2023-02-13 20:44:50 +08:00
|
|
|
|
Memory.RestorePatches();
|
2023-01-28 20:51:29 +08:00
|
|
|
|
#if CEF
|
2022-11-16 17:37:31 +08:00
|
|
|
|
if (CefRunning)
|
|
|
|
|
{
|
|
|
|
|
CefManager.CleanUp();
|
|
|
|
|
}
|
2023-01-28 20:51:29 +08:00
|
|
|
|
#endif
|
2022-11-16 17:40:07 +08:00
|
|
|
|
|
2023-02-13 20:44:50 +08:00
|
|
|
|
DownloadManager.Cleanup();
|
|
|
|
|
Voice.ClearAll();
|
|
|
|
|
Networking.Peer?.Dispose();
|
|
|
|
|
Networking.Peer = null;
|
|
|
|
|
}
|
2021-08-05 20:30:27 -03:00
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
2022-10-23 19:02:39 +08:00
|
|
|
|
}
|