Skip to content

Commit

Permalink
Fix null dereference
Browse files Browse the repository at this point in the history
  • Loading branch information
DiFFoZ committed Jun 13, 2024
1 parent 2969b99 commit 00bf0ac
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 17 deletions.
3 changes: 1 addition & 2 deletions Dummy/Actions/Interaction/Actions/ExecuteCommandAction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern alias JetBrainsAnnotations;
using Dummy.API;
using Dummy.API;
using Dummy.Users;
using OpenMod.API.Commands;
using System;
Expand Down
2 changes: 1 addition & 1 deletion Dummy/Commands/CommandDummyCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override async Task OnExecuteAsync()
{
settings = m_Configuration.GetSection("default").Get<ConfigurationSettings>();

settings.CharacterName = name!;
settings!.CharacterName = name!;
settings.NickName = name!;
settings.PlayerName = name!;
}
Expand Down
2 changes: 1 addition & 1 deletion Dummy/Commands/CommandDummyCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override async Task OnExecuteAsync()
{
settings = m_Configuration.GetSection("default").Get<ConfigurationSettings>();

settings.CharacterName = name!;
settings!.CharacterName = name!;
settings.NickName = name!;
settings.PlayerName = name!;
}
Expand Down
2 changes: 1 addition & 1 deletion Dummy/Commands/CommandDummySpawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CommandDummySpawn(IServiceProvider serviceProvider, IDummyProvider dummyP

protected override async Task OnExecuteAsync()
{
var settings = m_Configuration.Get<Configuration>().Default;
var settings = m_Configuration.Get<Configuration>()!.Default;
var name = CommandDummy.s_NameArgument.GetArgument(Context.Parameters);
if (!string.IsNullOrEmpty(name))
{
Expand Down
4 changes: 2 additions & 2 deletions Dummy/ConfigurationEx/NullConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public IChangeToken GetReloadToken()
return NullChangeToken.Singleton;
}

public string this[string key]
public string? this[string key]
{
get => default!;
set {}
set { }
}
}
}
4 changes: 3 additions & 1 deletion Dummy/Events/DummyDeadEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
4 changes: 2 additions & 2 deletions Dummy/NetTransports/DummyTransportConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public DummyTransportConnection(IPluginAccessor<Dummy> pluginAccessor)
var random = new System.Random();
var config = pluginAccessor.Instance!.Configuration.Get<Configuration>();

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);
Expand Down Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion Dummy/Permissions/DummyPermissionCheckProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public DummyPermissionCheckProvider(IPluginAccessor<Dummy> pluginAccessor) : bas
}

var options = pluginAccessor.Instance!.Configuration.GetValue<ConfigurationOptions>("options");
return options.CanExecuteCommands || options.IsAdmin;
return options!.CanExecuteCommands || options.IsAdmin;
})
{
}
Expand Down
2 changes: 1 addition & 1 deletion Dummy/Players/DummyPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions Dummy/Services/DummyUserProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public async Task<DummyUser> AddDummyAsync(CSteamID? id, HashSet<CSteamID>? 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<ulong>(),
Expand All @@ -275,7 +275,7 @@ public async Task<DummyUser> AddDummyAsync(CSteamID? id, HashSet<CSteamID>? owne
}
else
{
settings ??= config.Default;
settings ??= config!.Default;
if (settings is null)
{
throw new ArgumentNullException(nameof(settings));
Expand Down Expand Up @@ -315,7 +315,7 @@ public async Task<DummyUser> AddDummyAsync(CSteamID? id, HashSet<CSteamID>? owne

var logJoinLeave = configuration.GetSection("logs:enableJoinLeaveLog").Get<bool>();

await PreAddDummyAsync(pending, config.Events!, logJoinLeave);
await PreAddDummyAsync(pending, config!.Events!, logJoinLeave);
try
{
await UniTask.SwitchToMainThread();
Expand Down Expand Up @@ -474,7 +474,7 @@ private void ValidateSpawn(CSteamID id)
throw new DummyContainsException(localizer, id.m_SteamID); // or id is taken
}

var amountDummiesConfig = configuration.Get<Configuration>().Options?.AmountDummies ?? 0;
var amountDummiesConfig = configuration.Get<Configuration>()!.Options?.AmountDummies ?? 0;
if (amountDummiesConfig != 0 && DummyUsers.Count + 1 > amountDummiesConfig)
{
throw new DummyOverflowsException(localizer, (byte)DummyUsers.Count, amountDummiesConfig);
Expand Down
2 changes: 1 addition & 1 deletion Dummy/Threads/DummyUserSimulationThread.Equipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class DummyUserSimulationThread

private void SimulateEquipment()
{
if (Player.equipment.isSelected)
if (Player.equipment.HasValidUseable)
{
// todo: simulate useable
return;
Expand Down

0 comments on commit 00bf0ac

Please sign in to comment.