From 00bf0ac4b604571870884ea7077f05e61a3d8067 Mon Sep 17 00:00:00 2001 From: Leonid <48765566+DiFFoZ@users.noreply.github.com> Date: Thu, 13 Jun 2024 21:07:49 +0700 Subject: [PATCH] Fix null dereference --- Dummy/Actions/Interaction/Actions/ExecuteCommandAction.cs | 3 +-- Dummy/Commands/CommandDummyCopy.cs | 2 +- Dummy/Commands/CommandDummyCreate.cs | 2 +- Dummy/Commands/CommandDummySpawn.cs | 2 +- Dummy/ConfigurationEx/NullConfiguration.cs | 4 ++-- Dummy/Events/DummyDeadEvent.cs | 4 +++- Dummy/NetTransports/DummyTransportConnection.cs | 4 ++-- Dummy/Permissions/DummyPermissionCheckProvider.cs | 2 +- Dummy/Players/DummyPlayer.cs | 2 +- Dummy/Services/DummyUserProvider.cs | 8 ++++---- Dummy/Threads/DummyUserSimulationThread.Equipment.cs | 2 +- 11 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Dummy/Actions/Interaction/Actions/ExecuteCommandAction.cs b/Dummy/Actions/Interaction/Actions/ExecuteCommandAction.cs index 3d7ad19..43f18f9 100644 --- a/Dummy/Actions/Interaction/Actions/ExecuteCommandAction.cs +++ b/Dummy/Actions/Interaction/Actions/ExecuteCommandAction.cs @@ -1,5 +1,4 @@ -extern alias JetBrainsAnnotations; -using Dummy.API; +using Dummy.API; using Dummy.Users; using OpenMod.API.Commands; using System; diff --git a/Dummy/Commands/CommandDummyCopy.cs b/Dummy/Commands/CommandDummyCopy.cs index 5ba07b0..47a9b12 100644 --- a/Dummy/Commands/CommandDummyCopy.cs +++ b/Dummy/Commands/CommandDummyCopy.cs @@ -41,7 +41,7 @@ protected override async Task OnExecuteAsync() { settings = m_Configuration.GetSection("default").Get(); - settings.CharacterName = name!; + settings!.CharacterName = name!; settings.NickName = name!; settings.PlayerName = name!; } diff --git a/Dummy/Commands/CommandDummyCreate.cs b/Dummy/Commands/CommandDummyCreate.cs index d91afc0..c52b0ca 100644 --- a/Dummy/Commands/CommandDummyCreate.cs +++ b/Dummy/Commands/CommandDummyCreate.cs @@ -41,7 +41,7 @@ protected override async Task OnExecuteAsync() { settings = m_Configuration.GetSection("default").Get(); - settings.CharacterName = name!; + settings!.CharacterName = name!; settings.NickName = name!; settings.PlayerName = name!; } diff --git a/Dummy/Commands/CommandDummySpawn.cs b/Dummy/Commands/CommandDummySpawn.cs index 1067367..351ed7a 100644 --- a/Dummy/Commands/CommandDummySpawn.cs +++ b/Dummy/Commands/CommandDummySpawn.cs @@ -27,7 +27,7 @@ public CommandDummySpawn(IServiceProvider serviceProvider, IDummyProvider dummyP protected override async Task OnExecuteAsync() { - var settings = m_Configuration.Get().Default; + var settings = m_Configuration.Get()!.Default; var name = CommandDummy.s_NameArgument.GetArgument(Context.Parameters); if (!string.IsNullOrEmpty(name)) { diff --git a/Dummy/ConfigurationEx/NullConfiguration.cs b/Dummy/ConfigurationEx/NullConfiguration.cs index a04de76..65d2bcd 100644 --- a/Dummy/ConfigurationEx/NullConfiguration.cs +++ b/Dummy/ConfigurationEx/NullConfiguration.cs @@ -29,10 +29,10 @@ public IChangeToken GetReloadToken() return NullChangeToken.Singleton; } - public string this[string key] + public string? this[string key] { get => default!; - set {} + set { } } } } \ No newline at end of file diff --git a/Dummy/Events/DummyDeadEvent.cs b/Dummy/Events/DummyDeadEvent.cs index eb0b15c..bf71be7 100644 --- a/Dummy/Events/DummyDeadEvent.cs +++ b/Dummy/Events/DummyDeadEvent.cs @@ -67,12 +67,14 @@ private static async UniTaskVoid Revive(UnturnedPlayer player) return; } + // todo rewrite to revive and then teleport it back(?) + var life = player.Player.life; var transform = life.transform; life.sendRevive(); s_SendRevive.InvokeAndLoopback(life.GetNetId(), ENetReliability.Reliable, - Provider.EnumerateClients_Remote(), transform.position, + Provider.GatherRemoteClientConnections(), transform.position, MeasurementTool.angleToByte(transform.rotation.eulerAngles.y)); } } diff --git a/Dummy/NetTransports/DummyTransportConnection.cs b/Dummy/NetTransports/DummyTransportConnection.cs index ef04083..3500631 100644 --- a/Dummy/NetTransports/DummyTransportConnection.cs +++ b/Dummy/NetTransports/DummyTransportConnection.cs @@ -18,7 +18,7 @@ public DummyTransportConnection(IPluginAccessor pluginAccessor) var random = new System.Random(); var config = pluginAccessor.Instance!.Configuration.Get(); - m_IP = config.Connection.RandomIp || config.Default.IP == null + m_IP = config!.Connection.RandomIp || config.Default.IP == null ? $"{random.Next(1, 256)}.{random.Next(256)}.{random.Next(256)}.{random.Next(256)}" : (m_Address = config.Default.IP).ToString(); m_Address ??= IPAddress.Parse(m_IP); @@ -75,7 +75,7 @@ public void Send(byte[] buffer, long size, ENetReliability sendType) if (num >= NetReflection.clientMethodsLength) return; - var method = NetReflection.clientMethods[num]; + var method = NetReflection.clientMethods[(int)num]; if (method.declaringType == typeof(PlayerInput) && method.debugName.Contains("ReceiveSimulateMispredictedInputs")) diff --git a/Dummy/Permissions/DummyPermissionCheckProvider.cs b/Dummy/Permissions/DummyPermissionCheckProvider.cs index 30a631d..4a3c910 100644 --- a/Dummy/Permissions/DummyPermissionCheckProvider.cs +++ b/Dummy/Permissions/DummyPermissionCheckProvider.cs @@ -26,7 +26,7 @@ public DummyPermissionCheckProvider(IPluginAccessor pluginAccessor) : bas } var options = pluginAccessor.Instance!.Configuration.GetValue("options"); - return options.CanExecuteCommands || options.IsAdmin; + return options!.CanExecuteCommands || options.IsAdmin; }) { } diff --git a/Dummy/Players/DummyPlayer.cs b/Dummy/Players/DummyPlayer.cs index d6b3b92..6000afc 100644 --- a/Dummy/Players/DummyPlayer.cs +++ b/Dummy/Players/DummyPlayer.cs @@ -26,7 +26,7 @@ public bool Equals(DummyUser other) return other.SteamID.Equals(SteamId); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is DummyPlayer other) return Equals(other); else return false; diff --git a/Dummy/Services/DummyUserProvider.cs b/Dummy/Services/DummyUserProvider.cs index 65de21d..98afae8 100644 --- a/Dummy/Services/DummyUserProvider.cs +++ b/Dummy/Services/DummyUserProvider.cs @@ -262,7 +262,7 @@ public async Task AddDummyAsync(CSteamID? id, HashSet? owne pending = new(GetTransportConnection(), playerID, userSteamPlayer.isPro, userSteamPlayer.face, userSteamPlayer.hair, userSteamPlayer.beard, userSteamPlayer.skin, - userSteamPlayer.color, userSteamPlayer.markerColor, userSteamPlayer.hand, + userSteamPlayer.color, userSteamPlayer.markerColor, userSteamPlayer.IsLeftHanded, (ulong)userSteamPlayer.shirtItem, (ulong)userSteamPlayer.pantsItem, (ulong)userSteamPlayer.hatItem, (ulong)userSteamPlayer.backpackItem, (ulong)userSteamPlayer.vestItem, (ulong)userSteamPlayer.maskItem, (ulong)userSteamPlayer.glassesItem, Array.Empty(), @@ -275,7 +275,7 @@ public async Task AddDummyAsync(CSteamID? id, HashSet? owne } else { - settings ??= config.Default; + settings ??= config!.Default; if (settings is null) { throw new ArgumentNullException(nameof(settings)); @@ -315,7 +315,7 @@ public async Task AddDummyAsync(CSteamID? id, HashSet? owne var logJoinLeave = configuration.GetSection("logs:enableJoinLeaveLog").Get(); - await PreAddDummyAsync(pending, config.Events!, logJoinLeave); + await PreAddDummyAsync(pending, config!.Events!, logJoinLeave); try { await UniTask.SwitchToMainThread(); @@ -474,7 +474,7 @@ private void ValidateSpawn(CSteamID id) throw new DummyContainsException(localizer, id.m_SteamID); // or id is taken } - var amountDummiesConfig = configuration.Get().Options?.AmountDummies ?? 0; + var amountDummiesConfig = configuration.Get()!.Options?.AmountDummies ?? 0; if (amountDummiesConfig != 0 && DummyUsers.Count + 1 > amountDummiesConfig) { throw new DummyOverflowsException(localizer, (byte)DummyUsers.Count, amountDummiesConfig); diff --git a/Dummy/Threads/DummyUserSimulationThread.Equipment.cs b/Dummy/Threads/DummyUserSimulationThread.Equipment.cs index 843698f..b73a758 100644 --- a/Dummy/Threads/DummyUserSimulationThread.Equipment.cs +++ b/Dummy/Threads/DummyUserSimulationThread.Equipment.cs @@ -12,7 +12,7 @@ public partial class DummyUserSimulationThread private void SimulateEquipment() { - if (Player.equipment.isSelected) + if (Player.equipment.HasValidUseable) { // todo: simulate useable return;