Skip to content

Commit

Permalink
Code cleanup - Switch to null-forgiving operator
Browse files Browse the repository at this point in the history
- Switch to null-forgiving operator (!) to remove compiler warnings
  • Loading branch information
data-bomb committed Jan 6, 2024
1 parent 2e6d377 commit 9c59a8c
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 82 deletions.
8 changes: 4 additions & 4 deletions Si_AFKManager/Si_AFK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You should have received a copy of the GNU General Public License
using SilicaAdminMod;
using System;

[assembly: MelonInfo(typeof(AwayFromKeyboard), "AFK Manager", "1.2.3", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(AwayFromKeyboard), "AFK Manager", "1.2.4", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand Down Expand Up @@ -64,9 +64,9 @@ public uint Minutes
static bool oneMinuteCheckTime;
static bool skippedFirstCheck;

static MelonPreferences_Category? _modCategory;
static MelonPreferences_Entry<bool>? Pref_AFK_KickIfServerNotFull;
static MelonPreferences_Entry<int>? Pref_AFK_MinutesBeforeKick;
static MelonPreferences_Category _modCategory = null!;
static MelonPreferences_Entry<bool> Pref_AFK_KickIfServerNotFull = null!;
static MelonPreferences_Entry<int> Pref_AFK_MinutesBeforeKick = null!;

public override void OnInitializeMelon()
{
Expand Down
6 changes: 3 additions & 3 deletions Si_AdminMod/Si_AdminMod.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Silica Admin Mod
Copyright (C) 2023 by databomb
Copyright (C) 2024 by databomb
* Description *
Provides basic admin mod system to allow additional admins beyond
Expand Down Expand Up @@ -36,8 +36,8 @@ namespace SilicaAdminMod
{
public class SiAdminMod : MelonMod
{
static MelonPreferences_Category? _modCategory;
public static MelonPreferences_Entry<bool>? Pref_Admin_AcceptTeamChatCommands;
static MelonPreferences_Category _modCategory = null!;
public static MelonPreferences_Entry<bool> Pref_Admin_AcceptTeamChatCommands = null!;

public static List<Admin> AdminList = null!;
public static List<AdminCommand> AdminCommands = null!;
Expand Down
12 changes: 6 additions & 6 deletions Si_Announcements/Si_Announcements.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Silica Announcements Mod
Copyright (C) 2023 by databomb
Copyright (C) 2024 by databomb
* Description *
For Silica listen servers, periodically sends a pre-set announcement
Expand Down Expand Up @@ -36,19 +36,19 @@ You should have received a copy of the GNU General Public License
using SilicaAdminMod;
using System.Linq;

[assembly: MelonInfo(typeof(Announcements), "Server Announcements", "1.1.1", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(Announcements), "Server Announcements", "1.1.2", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

namespace Si_Announcements
{
public class Announcements : MelonMod
{
static MelonPreferences_Category? _modCategory;
static MelonPreferences_Entry<int>? _Announcements_SecondsBetweenMessages;
static MelonPreferences_Entry<bool>? _Announcements_ShowIfLastChatWasAnnouncement;
static MelonPreferences_Category _modCategory = null!;
static MelonPreferences_Entry<int> _Announcements_SecondsBetweenMessages = null!;
static MelonPreferences_Entry<bool> _Announcements_ShowIfLastChatWasAnnouncement = null!;

static System.Timers.Timer? announcementTimer;
static Timer announcementTimer = null!;
static int announcementCount;
static string[]? announcementsText;
static string? lastChatMessage;
Expand Down
10 changes: 5 additions & 5 deletions Si_AntiGrief/Si_AntiGrief.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Silica Anti-Grief Mod
Copyright (C) 2023 by databomb
Copyright (C) 2024 by databomb
* Description *
For Silica servers, automatically identifies players who fall below a
Expand Down Expand Up @@ -33,17 +33,17 @@ You should have received a copy of the GNU General Public License
using Si_AntiGrief;
using SilicaAdminMod;

[assembly: MelonInfo(typeof(AntiGrief), "Anti-Grief", "1.1.3", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(AntiGrief), "Anti-Grief", "1.1.4", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

namespace Si_AntiGrief
{
public class AntiGrief : MelonMod
{
static MelonPreferences_Category? _modCategory;
static MelonPreferences_Entry<int>? _NegativeKillsThreshold;
static MelonPreferences_Entry<bool>? _NegativeKills_Penalty_Ban;
static MelonPreferences_Category _modCategory = null!;
static MelonPreferences_Entry<int> _NegativeKillsThreshold = null!;
static MelonPreferences_Entry<bool> _NegativeKills_Penalty_Ban = null!;

private const string ModCategory = "Silica";

Expand Down
6 changes: 3 additions & 3 deletions Si_AutoTeamsSelect/Si_AutoTeamsSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ You should have received a copy of the GNU General Public License
using SilicaAdminMod;
using System;

[assembly: MelonInfo(typeof(VersusTeamsAutoSelectMod), "Versus Auto-Select Team", "1.1.2", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(VersusTeamsAutoSelectMod), "Versus Auto-Select Team", "1.1.3", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand All @@ -52,8 +52,8 @@ public class VersusTeamsAutoSelectMod : MelonMod

private static System.Timers.Timer? DelayTimer;

static MelonPreferences_Category? _modCategory;
static MelonPreferences_Entry<MP_Strategy.ETeamsVersus>? _versusAutoSelectMode;
static MelonPreferences_Category _modCategory = null!;
static MelonPreferences_Entry<MP_Strategy.ETeamsVersus> _versusAutoSelectMode = null;

Check warning on line 56 in Si_AutoTeamsSelect/Si_AutoTeamsSelect.cs

View workflow job for this annotation

GitHub Actions / build (Si_AutoTeamsSelect)

Cannot convert null literal to non-nullable reference type.

Check warning on line 56 in Si_AutoTeamsSelect/Si_AutoTeamsSelect.cs

View workflow job for this annotation

GitHub Actions / build (Si_AutoTeamsSelect)

Cannot convert null literal to non-nullable reference type.

Check warning on line 56 in Si_AutoTeamsSelect/Si_AutoTeamsSelect.cs

View workflow job for this annotation

GitHub Actions / build (Si_AutoTeamsSelect)

Cannot convert null literal to non-nullable reference type.

Check warning on line 56 in Si_AutoTeamsSelect/Si_AutoTeamsSelect.cs

View workflow job for this annotation

GitHub Actions / build (Si_AutoTeamsSelect)

Cannot convert null literal to non-nullable reference type.

private const string ModCategory = "Silica";
private const string AutoSelectMode = "VersusAutoSelectMode";
Expand Down
12 changes: 6 additions & 6 deletions Si_BasicBanlist/Si_BasicBans.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Silica Basic Banlist Mod
Copyright (C) 2023 by databomb
Copyright (C) 2024 by databomb
* Description *
For Silica listen servers, retains history of kicked players across
Expand Down Expand Up @@ -35,7 +35,7 @@ You should have received a copy of the GNU General Public License
using System.Collections.Generic;
using System.Linq;

[assembly: MelonInfo(typeof(BasicBanlist), "Basic Banlist", "1.3.0", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(BasicBanlist), "Basic Banlist", "1.3.1", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand Down Expand Up @@ -71,8 +71,8 @@ public String? Comments
static readonly String banListFile = System.IO.Path.Combine(MelonEnvironment.UserDataDirectory, "banned_users.json");
static bool AdminModAvailable = false;

static MelonPreferences_Category _modCategory;
static MelonPreferences_Entry<bool> Pref_Ban_KickButton_PermaBan;
static MelonPreferences_Category _modCategory = null!;
static MelonPreferences_Entry<bool> _Pref_Ban_KickButton_PermaBan = null!;

public static void UpdateBanFile()
{
Expand All @@ -86,7 +86,7 @@ public override void OnInitializeMelon()
try
{
_modCategory ??= MelonPreferences.CreateCategory("Silica");
Pref_Ban_KickButton_PermaBan ??= _modCategory.CreateEntry<bool>("Ban_HostKickButton_Permabans", false);
_Pref_Ban_KickButton_PermaBan ??= _modCategory.CreateEntry<bool>("Ban_HostKickButton_Permabans", false);

if (System.IO.File.Exists(banListFile))
{
Expand Down Expand Up @@ -270,7 +270,7 @@ public static void Prefix(Player __0)
}

// if we just intended to kick, we can skip the rest
if (!Pref_Ban_KickButton_PermaBan.Value)
if (!_Pref_Ban_KickButton_PermaBan.Value)
{
MelonLogger.Msg("Kicked player name (" + __0.PlayerName + ") SteamID (" + __0.ToString() + ")");
return;
Expand Down
24 changes: 12 additions & 12 deletions Si_BasicTeamBalance/Si_BasicTeamBalance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ You should have received a copy of the GNU General Public License
using System;
using SilicaAdminMod;

[assembly: MelonInfo(typeof(BasicTeamBalance), "Basic Team Balance", "1.2.1", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(BasicTeamBalance), "Basic Team Balance", "1.2.2", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

namespace Si_BasicTeamBalance
{
public class BasicTeamBalance : MelonMod
{
static MelonPreferences_Category? _modCategory;
static MelonPreferences_Entry<float>? _TwoTeamBalanceDivisor;
static MelonPreferences_Entry<float>? _TwoTeamBalanceAddend;
static MelonPreferences_Entry<float>? _ThreeTeamBalanceDivisor;
static MelonPreferences_Entry<float>? _ThreeTeamBalanceAddend;
static MelonPreferences_Entry<bool>? _PreventEarlyTeamSwitches;
static MelonPreferences_Entry<int>? _AllowTeamSwitchAfterTime;
static MelonPreferences_Category _modCategory = null!;
static MelonPreferences_Entry<float> _TwoTeamBalanceDivisor = null!;
static MelonPreferences_Entry<float> _TwoTeamBalanceAddend = null!;
static MelonPreferences_Entry<float> _ThreeTeamBalanceDivisor = null!;
static MelonPreferences_Entry<float> _ThreeTeamBalanceAddend = null!;
static MelonPreferences_Entry<bool> _PreventEarlyTeamSwitches = null!;
static MelonPreferences_Entry<int> _AllowTeamSwitchAfterTime = null!;

static Player? LastPlayerChatMessage;
static bool preventTeamSwitches;
Expand Down Expand Up @@ -175,7 +175,7 @@ public static int GetNumberOfActiveTeams(MP_Strategy.ETeamsVersus versusMode)
// Team Index 2 - Human (Sol)
public static bool JoinCausesImbalance(Team? TargetTeam)
{
if (TargetTeam == null || _TwoTeamBalanceDivisor == null || _TwoTeamBalanceAddend == null || _ThreeTeamBalanceDivisor == null || _ThreeTeamBalanceAddend == null)
if (TargetTeam == null)
{
return false;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ public static bool Prefix(MP_Strategy __instance, GameByteStreamReader __0, byte
{
try
{
if (__instance == null || __0 == null || _PreventEarlyTeamSwitches == null)
if (__instance == null || __0 == null)
{
return true;
}
Expand Down Expand Up @@ -348,7 +348,7 @@ public static void Postfix(MusicJukeboxHandler __instance, GameMode __0)
{
try
{
if (_PreventEarlyTeamSwitches != null && _PreventEarlyTeamSwitches.Value && _AllowTeamSwitchAfterTime != null)
if (_PreventEarlyTeamSwitches.Value)
{
preventTeamSwitches = true;

Expand Down Expand Up @@ -382,7 +382,7 @@ public static void Postfix(MusicJukeboxHandler __instance, GameMode __0, Team __
{
try
{
if (_PreventEarlyTeamSwitches != null && !_PreventEarlyTeamSwitches.Value || Timer_AllowTeamSwitches == null)
if (!_PreventEarlyTeamSwitches.Value || Timer_AllowTeamSwitches == null)
{
return;
}
Expand Down
8 changes: 4 additions & 4 deletions Si_CommManagement/Si_CmdrMgr.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Silica Commander Management Mod
Copyright (C) 2023 by databomb
Copyright (C) 2024 by databomb
* Description *
For Silica servers, establishes a random selection for commander at the
Expand Down Expand Up @@ -40,16 +40,16 @@ You should have received a copy of the GNU General Public License
using SilicaAdminMod;
using System.Linq;

[assembly: MelonInfo(typeof(CommanderManager), "Commander Management", "1.3.0", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(CommanderManager), "Commander Management", "1.3.1", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

namespace Si_CommanderManagement
{
public class CommanderManager : MelonMod
{
static MelonPreferences_Category? _modCategory;
static MelonPreferences_Entry<bool>? _BlockRoundStartUntilEnoughApplicants;
static MelonPreferences_Category _modCategory = null!;
static MelonPreferences_Entry<bool> _BlockRoundStartUntilEnoughApplicants = null!;

const int MaxTeams = 3;
const int AlienTeam = 0;
Expand Down
31 changes: 13 additions & 18 deletions Si_DefaultUnits/Si_DefaultUnits.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Silica Default Spawn Units
Copyright (C) 2023 by databomb
Copyright (C) 2024 by databomb
* Description *
For Silica servers, allows hosts to modify the default spawn units at
Expand Down Expand Up @@ -42,20 +42,20 @@ namespace Si_DefaultUnits
{
public class DefaultUnits : MelonMod
{
static MelonPreferences_Category? _modCategory;
static MelonPreferences_Category _modCategory = null!;
private const string ModCategory = "Silica";

static MelonPreferences_Entry<string>? _Human_Unit_Tier_0;
static MelonPreferences_Entry<string>? _Human_Unit_Tier_I;
static MelonPreferences_Entry<string>? _Human_Unit_Tier_II;
static MelonPreferences_Entry<string>? _Human_Unit_Tier_III;
static MelonPreferences_Entry<string>? _Human_Unit_Tier_IV;
static MelonPreferences_Entry<string> _Human_Unit_Tier_0 = null!;
static MelonPreferences_Entry<string> _Human_Unit_Tier_I = null!;
static MelonPreferences_Entry<string> _Human_Unit_Tier_II = null!;
static MelonPreferences_Entry<string> _Human_Unit_Tier_III = null!;
static MelonPreferences_Entry<string> _Human_Unit_Tier_IV = null!;

static MelonPreferences_Entry<string>? _Alien_Unit_Tier_0;
static MelonPreferences_Entry<string>? _Alien_Unit_Tier_I;
static MelonPreferences_Entry<string>? _Alien_Unit_Tier_II;
static MelonPreferences_Entry<string>? _Alien_Unit_Tier_III;
static MelonPreferences_Entry<string>? _Alien_Unit_Tier_IV;
static MelonPreferences_Entry<string> _Alien_Unit_Tier_0 = null!;
static MelonPreferences_Entry<string> _Alien_Unit_Tier_I = null!;
static MelonPreferences_Entry<string> _Alien_Unit_Tier_II = null!;
static MelonPreferences_Entry<string> _Alien_Unit_Tier_III = null!;
static MelonPreferences_Entry<string> _Alien_Unit_Tier_IV = null!;

const int MaxTeams = 3;
static int[]? teamTechTiers;
Expand Down Expand Up @@ -219,12 +219,7 @@ static string GetDesiredSpawnConfig(Team team)
{
bool humanTeam = team.TeamName.StartsWith("Human");

if (teamTechTiers == null ||
_Human_Unit_Tier_0 == null || _Alien_Unit_Tier_0 == null ||
_Human_Unit_Tier_I == null || _Alien_Unit_Tier_I == null ||
_Human_Unit_Tier_II == null || _Alien_Unit_Tier_II == null ||
_Human_Unit_Tier_III == null || _Alien_Unit_Tier_III == null ||
_Human_Unit_Tier_IV == null || _Alien_Unit_Tier_IV == null)
if (teamTechTiers == null)
{
return "";
}
Expand Down
16 changes: 7 additions & 9 deletions Si_FriendlyFireLimits/Si_FF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,20 @@ You should have received a copy of the GNU General Public License
using System;
using SilicaAdminMod;

[assembly: MelonInfo(typeof(FriendlyFireLimits), "Friendly Fire Limits", "1.2.1", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(FriendlyFireLimits), "Friendly Fire Limits", "1.2.2", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

namespace Si_FriendlyFireLimits
{
public class FriendlyFireLimits : MelonMod
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
static MelonPreferences_Category _modCategory;
static MelonPreferences_Entry<float> _UnitOnUnitNonExplosionDamageMultipler;
static MelonPreferences_Entry<float> _UnitOnUnitExplosionDamageMultiplier;
static MelonPreferences_Entry<float> _UnitOnStructureExplosionDamageMultiplier;
static MelonPreferences_Entry<float> _UnitOnStructureNonExplosionDamageMultiplier;
static MelonPreferences_Entry<bool> _HarvesterPassthrough;
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
static MelonPreferences_Category _modCategory = null!;
static MelonPreferences_Entry<float> _UnitOnUnitNonExplosionDamageMultipler = null!;
static MelonPreferences_Entry<float> _UnitOnUnitExplosionDamageMultiplier = null!;
static MelonPreferences_Entry<float> _UnitOnStructureExplosionDamageMultiplier = null!;
static MelonPreferences_Entry<float> _UnitOnStructureNonExplosionDamageMultiplier = null!;
static MelonPreferences_Entry<bool> _HarvesterPassthrough = null!;

private const string ModCategory = "Silica";

Expand Down
17 changes: 6 additions & 11 deletions Si_Logging/Si_Logging.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Silica Logging Mod
Copyright (C) 2023 by databomb
Copyright (C) 2024 by databomb
* Description *
For Silica listen servers, creates a log file with console replication
Expand Down Expand Up @@ -37,7 +37,7 @@ You should have received a copy of the GNU General Public License
using SilicaAdminMod;
using System.Collections.Generic;

[assembly: MelonInfo(typeof(HL_Logging), "Half-Life Logger", "1.1.0", "databomb&zawedcvg", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(HL_Logging), "Half-Life Logger", "1.1.1", "databomb&zawedcvg", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand All @@ -49,9 +49,9 @@ public class HL_Logging : MelonMod
const int MaxTeams = 3;
static Player?[]? lastCommander;

static MelonPreferences_Category? _modCategory;
static MelonPreferences_Entry<bool>? Pref_Log_Damage;
static MelonPreferences_Entry<bool>? Pref_Log_Kills_Include_AI_vs_Player;
static MelonPreferences_Category _modCategory = null!;
static MelonPreferences_Entry<bool> Pref_Log_Damage = null!;
static MelonPreferences_Entry<bool> Pref_Log_Kills_Include_AI_vs_Player = null!;

public static void PrintLogLine(string LogMessage, bool suppressConsoleOutput = false)
{
Expand Down Expand Up @@ -290,11 +290,6 @@ public static void Postfix(StrategyMode __instance, Unit __0, EDamageType __1, U
return;
}

if (Pref_Log_Kills_Include_AI_vs_Player == null)
{
return;
}

// Attacker
BaseGameObject attackerBase = GameFuncs.GetBaseGameObject(__2);
if (attackerBase == null)
Expand Down Expand Up @@ -502,7 +497,7 @@ private static class ApplyPatchOnDamageReceived
public static void Postfix(DamageManager __instance, UnityEngine.Collider __0, float __1, EDamageType __2, UnityEngine.GameObject __3, UnityEngine.Vector3 __4)
{
// should we log the damage?
if (Pref_Log_Damage != null && !Pref_Log_Damage.Value)
if (!Pref_Log_Damage.Value)
{
return;
}
Expand Down
Loading

0 comments on commit 9c59a8c

Please sign in to comment.