Fixed client exceptions

This commit is contained in:
EntenKoeniq
2021-12-03 20:30:00 +01:00
parent 52f5ab5b3d
commit 129a4faea1
9 changed files with 124 additions and 61 deletions

View File

@ -8,14 +8,17 @@ using GTA.Native;
namespace CoopClient namespace CoopClient
{ {
internal class Chat /// <summary>
/// Don't use it!
/// </summary>
public class Chat
{ {
private readonly Scaleform MainScaleForm; private readonly Scaleform MainScaleForm;
public string CurrentInput { get; set; } internal string CurrentInput { get; set; }
private bool CurrentFocused { get; set; } private bool CurrentFocused { get; set; }
public bool Focused internal bool Focused
{ {
get { return CurrentFocused; } get { return CurrentFocused; }
set set
@ -55,23 +58,26 @@ namespace CoopClient
} }
} }
/// <summary>
/// Don't use it!
/// </summary>
public Chat() public Chat()
{ {
MainScaleForm = new Scaleform("multiplayer_chat"); MainScaleForm = new Scaleform("multiplayer_chat");
} }
public void Init() internal void Init()
{ {
MainScaleForm.CallFunction("SET_FOCUS", 2, 2, "ALL"); MainScaleForm.CallFunction("SET_FOCUS", 2, 2, "ALL");
MainScaleForm.CallFunction("SET_FOCUS", 1, 2, "ALL"); MainScaleForm.CallFunction("SET_FOCUS", 1, 2, "ALL");
} }
public void Clear() internal void Clear()
{ {
MainScaleForm.CallFunction("RESET"); MainScaleForm.CallFunction("RESET");
} }
public void Tick() internal void Tick()
{ {
if ((Util.GetTickCount64() - LastMessageTime) > 15000 && !Focused && !Hidden) if ((Util.GetTickCount64() - LastMessageTime) > 15000 && !Focused && !Hidden)
{ {
@ -91,14 +97,14 @@ namespace CoopClient
Function.Call(Hash.DISABLE_ALL_CONTROL_ACTIONS, 0); Function.Call(Hash.DISABLE_ALL_CONTROL_ACTIONS, 0);
} }
public void AddMessage(string sender, string msg) internal void AddMessage(string sender, string msg)
{ {
MainScaleForm.CallFunction("ADD_MESSAGE", sender + ":", msg); MainScaleForm.CallFunction("ADD_MESSAGE", sender + ":", msg);
LastMessageTime = Util.GetTickCount64(); LastMessageTime = Util.GetTickCount64();
Hidden = false; Hidden = false;
} }
public void OnKeyDown(Keys key) internal void OnKeyDown(Keys key)
{ {
if (key == Keys.Escape) if (key == Keys.Escape)
{ {
@ -151,12 +157,12 @@ namespace CoopClient
} }
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern int ToUnicodeEx(uint virtualKeyCode, uint scanCode, byte[] keyboardState, internal static extern int ToUnicodeEx(uint virtualKeyCode, uint scanCode, byte[] keyboardState,
[Out, MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)] [Out, MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)]
StringBuilder receivingBuffer, StringBuilder receivingBuffer,
int bufferSize, uint flags, IntPtr kblayout); int bufferSize, uint flags, IntPtr kblayout);
public static string GetCharFromKey(Keys key, bool shift, bool altGr) internal static string GetCharFromKey(Keys key, bool shift, bool altGr)
{ {
StringBuilder buf = new StringBuilder(256); StringBuilder buf = new StringBuilder(256);
byte[] keyboardState = new byte[256]; byte[] keyboardState = new byte[256];

View File

@ -6,8 +6,14 @@ using GTA;
namespace CoopClient.Entities namespace CoopClient.Entities
{ {
internal class EntitiesThread : Script /// <summary>
/// Don't use it!
/// </summary>
public class EntitiesThread : Script
{ {
/// <summary>
/// Don't use it!
/// </summary>
public EntitiesThread() public EntitiesThread()
{ {
Tick += OnTick; Tick += OnTick;

View File

@ -12,31 +12,49 @@ using GTA.Native;
namespace CoopClient namespace CoopClient
{ {
internal class Main : Script /// <summary>
/// Don't use it!
/// </summary>
public class Main : Script
{ {
public static RelationshipGroup RelationshipGroup; internal static RelationshipGroup RelationshipGroup;
private bool GameLoaded = false; private bool GameLoaded = false;
public static readonly string CurrentVersion = "V0_8_0_1"; internal static readonly string CurrentVersion = "V0_8_0_1";
public static bool ShareNpcsWithPlayers = false; internal static bool ShareNpcsWithPlayers = false;
public static bool DisableTraffic = false; internal static bool DisableTraffic = false;
public static bool NpcsAllowed = false; internal static bool NpcsAllowed = false;
private static bool IsGoingToCar = false; private static bool IsGoingToCar = false;
/// <summary>
/// Don't use it!
/// </summary>
public static Settings MainSettings = Util.ReadSettings(); public static Settings MainSettings = Util.ReadSettings();
/// <summary>
/// Don't use it!
/// </summary>
public static Networking MainNetworking = new Networking(); public static Networking MainNetworking = new Networking();
#if !NON_INTERACTIVE #if !NON_INTERACTIVE
/// <summary>
/// Don't use it!
/// </summary>
public static MenusMain MainMenu = new MenusMain(); public static MenusMain MainMenu = new MenusMain();
#endif #endif
/// <summary>
/// Don't use it!
/// </summary>
public static Chat MainChat = new Chat(); public static Chat MainChat = new Chat();
public static long LocalClientID = 0; internal static long LocalClientID = 0;
public static readonly Dictionary<long, EntitiesPlayer> Players = new Dictionary<long, EntitiesPlayer>(); internal static readonly Dictionary<long, EntitiesPlayer> Players = new Dictionary<long, EntitiesPlayer>();
public static readonly Dictionary<long, EntitiesNpc> Npcs = new Dictionary<long, EntitiesNpc>(); internal static readonly Dictionary<long, EntitiesNpc> Npcs = new Dictionary<long, EntitiesNpc>();
/// <summary>
/// Don't use it!
/// </summary>
public Main() public Main()
{ {
Function.Call((Hash)0x0888C3502DBBEEF5); // _LOAD_MP_DLC_MAPS Function.Call((Hash)0x0888C3502DBBEEF5); // _LOAD_MP_DLC_MAPS
@ -184,7 +202,7 @@ namespace CoopClient
} }
#endif #endif
public static void CleanUp() internal static void CleanUp()
{ {
MainChat.Clear(); MainChat.Clear();
@ -209,9 +227,9 @@ namespace CoopClient
#if DEBUG #if DEBUG
private ulong ArtificialLagCounter; private ulong ArtificialLagCounter;
public static EntitiesPlayer DebugSyncPed; internal static EntitiesPlayer DebugSyncPed;
public static ulong LastFullDebugSync = 0; internal static ulong LastFullDebugSync = 0;
public static bool UseDebug = false; internal static bool UseDebug = false;
private void Debug() private void Debug()
{ {

View File

@ -5,16 +5,22 @@ using LemonUI.Menus;
namespace CoopClient.Menus namespace CoopClient.Menus
{ {
internal class MenusMain /// <summary>
/// Don't use it!
/// </summary>
public class MenusMain
{ {
public ObjectPool MenuPool = new ObjectPool(); internal ObjectPool MenuPool = new ObjectPool();
public NativeMenu MainMenu = new NativeMenu("GTACOOP:R", "MAIN") internal NativeMenu MainMenu = new NativeMenu("GTACOOP:R", "MAIN")
{ {
UseMouse = false, UseMouse = false,
Alignment = Main.MainSettings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left Alignment = Main.MainSettings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
}; };
#region SUB #region SUB
/// <summary>
/// Don't use it!
/// </summary>
public Sub.Settings SubSettings = new Sub.Settings(); public Sub.Settings SubSettings = new Sub.Settings();
#endregion #endregion
@ -28,6 +34,9 @@ namespace CoopClient.Menus
Main.CurrentVersion.Replace("_", ".")) { LeftBadge = new LemonUI.Elements.ScaledTexture("commonmenu", "shop_new_star") }; Main.CurrentVersion.Replace("_", ".")) { LeftBadge = new LemonUI.Elements.ScaledTexture("commonmenu", "shop_new_star") };
#endregion #endregion
/// <summary>
/// Don't use it!
/// </summary>
public MenusMain() public MenusMain()
{ {
UsernameItem.Activated += UsernameActivated; UsernameItem.Activated += UsernameActivated;
@ -46,7 +55,7 @@ namespace CoopClient.Menus
MenuPool.Add(SubSettings.MainMenu); MenuPool.Add(SubSettings.MainMenu);
} }
public void UsernameActivated(object a, System.EventArgs b) internal void UsernameActivated(object a, System.EventArgs b)
{ {
string newUsername = Game.GetUserInput(WindowTitle.EnterMessage20, UsernameItem.AltTitle, 20); string newUsername = Game.GetUserInput(WindowTitle.EnterMessage20, UsernameItem.AltTitle, 20);
if (!string.IsNullOrWhiteSpace(newUsername)) if (!string.IsNullOrWhiteSpace(newUsername))
@ -59,7 +68,7 @@ namespace CoopClient.Menus
} }
} }
public void ServerIpActivated(object a, System.EventArgs b) internal void ServerIpActivated(object a, System.EventArgs b)
{ {
string newServerIp = Game.GetUserInput(WindowTitle.EnterMessage60, ServerIpItem.AltTitle, 60); string newServerIp = Game.GetUserInput(WindowTitle.EnterMessage60, ServerIpItem.AltTitle, 60);
if (!string.IsNullOrWhiteSpace(newServerIp) && newServerIp.Contains(":")) if (!string.IsNullOrWhiteSpace(newServerIp) && newServerIp.Contains(":"))
@ -72,14 +81,14 @@ namespace CoopClient.Menus
} }
} }
public void InitiateConnectionMenuSetting() internal void InitiateConnectionMenuSetting()
{ {
MainMenu.Items[0].Enabled = false; MainMenu.Items[0].Enabled = false;
MainMenu.Items[1].Enabled = false; MainMenu.Items[1].Enabled = false;
MainMenu.Items[2].Enabled = false; MainMenu.Items[2].Enabled = false;
} }
public void ConnectedMenuSetting() internal void ConnectedMenuSetting()
{ {
MainMenu.Items[2].Enabled = true; MainMenu.Items[2].Enabled = true;
MainMenu.Items[2].Title = "Disconnect"; MainMenu.Items[2].Title = "Disconnect";
@ -89,7 +98,7 @@ namespace CoopClient.Menus
MenuPool.RefreshAll(); MenuPool.RefreshAll();
} }
public void DisconnectedMenuSetting() internal void DisconnectedMenuSetting()
{ {
MainMenu.Items[0].Enabled = true; MainMenu.Items[0].Enabled = true;
MainMenu.Items[1].Enabled = true; MainMenu.Items[1].Enabled = true;

View File

@ -2,9 +2,12 @@
namespace CoopClient.Menus.Sub namespace CoopClient.Menus.Sub
{ {
internal class Settings /// <summary>
/// Don't use it!
/// </summary>
public class Settings
{ {
public NativeMenu MainMenu = new NativeMenu("GTACOOP:R", "Settings", "Go to the settings") internal NativeMenu MainMenu = new NativeMenu("GTACOOP:R", "Settings", "Go to the settings")
{ {
UseMouse = false, UseMouse = false,
Alignment = Main.MainSettings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left Alignment = Main.MainSettings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
@ -19,6 +22,9 @@ namespace CoopClient.Menus.Sub
private readonly NativeCheckboxItem ShowNetworkInfo = new NativeCheckboxItem("Show Network Info", Main.MainNetworking.ShowNetworkInfo); private readonly NativeCheckboxItem ShowNetworkInfo = new NativeCheckboxItem("Show Network Info", Main.MainNetworking.ShowNetworkInfo);
#endif #endif
/// <summary>
/// Don't use it!
/// </summary>
public Settings() public Settings()
{ {
DisableTraffic.CheckboxChanged += DisableTrafficCheckboxChanged; DisableTraffic.CheckboxChanged += DisableTrafficCheckboxChanged;
@ -40,7 +46,7 @@ namespace CoopClient.Menus.Sub
#endif #endif
} }
public void DisableTrafficCheckboxChanged(object a, System.EventArgs b) internal void DisableTrafficCheckboxChanged(object a, System.EventArgs b)
{ {
Main.DisableTraffic = DisableTraffic.Checked; Main.DisableTraffic = DisableTraffic.Checked;
@ -59,14 +65,14 @@ namespace CoopClient.Menus.Sub
} }
} }
public void StreamedNpcsValueChanged(object a, System.EventArgs b) internal void StreamedNpcsValueChanged(object a, System.EventArgs b)
{ {
Main.MainSettings.StreamedNpc = StreamedNpcsItem.Value; Main.MainSettings.StreamedNpc = StreamedNpcsItem.Value;
Util.SaveSettings(); Util.SaveSettings();
StreamedNpcsItem.Title = string.Format("Streamed Npcs ({0})", Main.MainSettings.StreamedNpc); StreamedNpcsItem.Title = string.Format("Streamed Npcs ({0})", Main.MainSettings.StreamedNpc);
} }
public void FlipMenuCheckboxChanged(object a, System.EventArgs b) internal void FlipMenuCheckboxChanged(object a, System.EventArgs b)
{ {
#if !NON_INTERACTIVE #if !NON_INTERACTIVE
Main.MainMenu.MainMenu.Alignment = FlipMenuItem.Checked ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left; Main.MainMenu.MainMenu.Alignment = FlipMenuItem.Checked ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left;
@ -78,7 +84,7 @@ namespace CoopClient.Menus.Sub
} }
#if DEBUG #if DEBUG
public void UseDebugCheckboxChanged(object a, System.EventArgs b) internal void UseDebugCheckboxChanged(object a, System.EventArgs b)
{ {
Main.UseDebug = UseDebugItem.Checked; Main.UseDebug = UseDebugItem.Checked;
@ -96,7 +102,7 @@ namespace CoopClient.Menus.Sub
} }
} }
public void ShowNetworkInfoCheckboxChanged(object a, System.EventArgs b) internal void ShowNetworkInfoCheckboxChanged(object a, System.EventArgs b)
{ {
Main.MainNetworking.ShowNetworkInfo = ShowNetworkInfo.Checked; Main.MainNetworking.ShowNetworkInfo = ShowNetworkInfo.Checked;

View File

@ -10,17 +10,20 @@ using GTA.Native;
namespace CoopClient namespace CoopClient
{ {
internal class Networking /// <summary>
/// Don't use it!
/// </summary>
public class Networking
{ {
public NetClient Client; internal NetClient Client;
public float Latency; internal float Latency;
public bool ShowNetworkInfo = false; internal bool ShowNetworkInfo = false;
public int BytesReceived = 0; internal int BytesReceived = 0;
public int BytesSend = 0; internal int BytesSend = 0;
public void DisConnectFromServer(string address) internal void DisConnectFromServer(string address)
{ {
if (IsOnServer()) if (IsOnServer())
{ {
@ -66,12 +69,12 @@ namespace CoopClient
} }
} }
public bool IsOnServer() internal bool IsOnServer()
{ {
return Client?.ConnectionStatus == NetConnectionStatus.Connected; return Client?.ConnectionStatus == NetConnectionStatus.Connected;
} }
public void ReceiveMessages() internal void ReceiveMessages()
{ {
if (Client == null) if (Client == null)
{ {
@ -588,7 +591,7 @@ namespace CoopClient
#region -- SEND -- #region -- SEND --
private ulong LastPlayerFullSync = 0; private ulong LastPlayerFullSync = 0;
public void SendPlayerData() internal void SendPlayerData()
{ {
Ped player = Game.Player.Character; Ped player = Game.Player.Character;
@ -760,7 +763,7 @@ namespace CoopClient
#endif #endif
} }
public void SendNpcData(Ped npc) internal void SendNpcData(Ped npc)
{ {
NetOutgoingMessage outgoingMessage = Client.CreateMessage(); NetOutgoingMessage outgoingMessage = Client.CreateMessage();
@ -857,7 +860,7 @@ namespace CoopClient
#endif #endif
} }
public void SendChatMessage(string message) internal void SendChatMessage(string message)
{ {
NetOutgoingMessage outgoingMessage = Client.CreateMessage(); NetOutgoingMessage outgoingMessage = Client.CreateMessage();
new ChatMessagePacket() new ChatMessagePacket()
@ -876,7 +879,7 @@ namespace CoopClient
#endif #endif
} }
public void SendModData(long target, string mod, byte customID, byte[] bytes) internal void SendModData(long target, string mod, byte customID, byte[] bytes)
{ {
NetOutgoingMessage outgoingMessage = Client.CreateMessage(); NetOutgoingMessage outgoingMessage = Client.CreateMessage();
new ModPacket() new ModPacket()

View File

@ -8,12 +8,18 @@ using GTA.Native;
namespace CoopClient namespace CoopClient
{ {
internal class PlayerList : Script /// <summary>
/// Don't use it!
/// </summary>
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 ulong LastUpdate = Util.GetTickCount64(); private ulong LastUpdate = Util.GetTickCount64();
public static ulong Pressed { get; set; } internal static ulong Pressed { get; set; }
/// <summary>
/// Don't use it!
/// </summary>
public PlayerList() public PlayerList()
{ {
Init(); Init();

View File

@ -1,10 +1,13 @@
namespace CoopClient namespace CoopClient
{ {
internal class Settings /// <summary>
/// Don't use it!
/// </summary>
public class Settings
{ {
public string Username { get; set; } = "Player"; internal string Username { get; set; } = "Player";
public string LastServerAddress { get; set; } = "127.0.0.1:4499"; internal string LastServerAddress { get; set; } = "127.0.0.1:4499";
public bool FlipMenu { get; set; } = false; internal bool FlipMenu { get; set; } = false;
public int StreamedNpc { get; set; } = 10; internal int StreamedNpc { get; set; } = 10;
} }
} }

View File

@ -6,10 +6,16 @@ using GTA.Native;
namespace CoopClient namespace CoopClient
{ {
internal class WorldThread : Script /// <summary>
/// Don't use it!
/// </summary>
public class WorldThread : Script
{ {
private static bool LastDisableTraffic = false; private static bool LastDisableTraffic = false;
/// <summary>
/// Don't use it!
/// </summary>
public WorldThread() public WorldThread()
{ {
Tick += OnTick; Tick += OnTick;
@ -23,7 +29,7 @@ namespace CoopClient
}; };
} }
public static void OnTick(object sender, EventArgs e) internal static void OnTick(object sender, EventArgs e)
{ {
if (Game.IsLoading) if (Game.IsLoading)
{ {