diff --git a/Si_AdminMod/AdminMethods.cs b/Si_AdminMod/AdminMethods.cs index 99adafc..0fadb3d 100644 --- a/Si_AdminMod/AdminMethods.cs +++ b/Si_AdminMod/AdminMethods.cs @@ -59,7 +59,10 @@ public static void RegisterAdminCommand(String adminCommand, HelperMethods.Comma if (addAdminConsoleCmd != null) { Dictionary s_Commands = (Dictionary)commandField.GetValue(null); - MelonLogger.Msg(addAdminConsoleCmd.Key.ToLower() + " console command registered."); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg(addAdminConsoleCmd.Key.ToLower() + " console command registered."); + } s_Commands.Add(addAdminConsoleCmd.Key.ToLower(), addAdminConsoleCmd); commandField.SetValue(null, s_Commands); } diff --git a/Si_AdminMod/ChatVotes.cs b/Si_AdminMod/ChatVotes.cs index 414d992..fe1bcb2 100644 --- a/Si_AdminMod/ChatVotes.cs +++ b/Si_AdminMod/ChatVotes.cs @@ -62,7 +62,10 @@ public static void Command_VoteChat(Player? callerPlayer, String args) return; } - MelonLogger.Msg("Reached vote callback for: " + args); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Reached vote callback for: " + args); + } foreach (OptionVoteResult currentVoteResult in currentVoteResults.DetailedResults) { @@ -132,7 +135,10 @@ public static void HoldVote(ChatVoteBallot ballot) private static void StartVoteDurationTimer() { - MelonLogger.Msg("Starting vote timer with duration " + SiAdminMod.Pre_Admin_VoteDuration.Value.ToString()); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Starting vote timer with duration " + SiAdminMod.Pre_Admin_VoteDuration.Value.ToString()); + } voteInProgress = true; HelperMethods.StartTimer(ref Timer_TallyVote); } @@ -178,7 +184,10 @@ public static void Postfix(MusicJukeboxHandler __instance) winningResult = currentVoteResult; } - MelonLogger.Msg("Found command " + currentVoteResult.Command + " with votes " + currentVoteResult.Votes); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Found command " + currentVoteResult.Command + " with votes " + currentVoteResult.Votes); + } // unregister commands for current vote PlayerMethods.UnregisterPlayerPhrase(currentVoteResult.Command); diff --git a/Si_AdminMod/Event_Netcode.cs b/Si_AdminMod/Event_Netcode.cs index 24944a6..73d7602 100644 --- a/Si_AdminMod/Event_Netcode.cs +++ b/Si_AdminMod/Event_Netcode.cs @@ -88,12 +88,19 @@ static void Prefix(GameByteStreamReader __result, ref byte[] __0, int __1, uint return; } - MelonLogger.Msg("Firing OnRequestPlayerChatEvent for player (size=" + __1.ToString() + "): " + chatterPlayer.PlayerName); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Firing OnRequestPlayerChatEvent for player (size=" + __1.ToString() + "): " + chatterPlayer.PlayerName); + } + OnRequestPlayerChatArgs onRequestPlayerChatArgs = FireOnRequestPlayerChatEvent(chatterPlayer, chatText, chatTeamOnly); if (onRequestPlayerChatArgs.Block) { - MelonLogger.Msg("Blocking chat message for player: " + chatterPlayer.PlayerName); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Blocking chat message for player: " + chatterPlayer.PlayerName); + } __0[1] = (byte)127; } diff --git a/Si_AdminMod/Event_Roles.cs b/Si_AdminMod/Event_Roles.cs index 80c005f..f7189fd 100644 --- a/Si_AdminMod/Event_Roles.cs +++ b/Si_AdminMod/Event_Roles.cs @@ -87,10 +87,17 @@ public static bool Prefix(MP_Strategy __instance, ref GameByteStreamReader __0, if (onRequestCommanderArgs.Block) { - MelonLogger.Msg("Blocking commander role request for " + onRequestCommanderArgs.Requester.PlayerName); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Blocking commander role request for " + onRequestCommanderArgs.Requester.PlayerName); + } + if (!onRequestCommanderArgs.PreventSpawnWhenBlocked) { - MelonLogger.Msg("Preventing Spawn"); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Preventing Spawn"); + } __instance.SpawnUnitForPlayer(requestingPlayer, requestingPlayer.Team); FireOnRoleChangedEvent(requestingPlayer, GameModeExt.ETeamRole.INFANTRY); } @@ -98,7 +105,10 @@ public static bool Prefix(MP_Strategy __instance, ref GameByteStreamReader __0, return false; } - MelonLogger.Msg("Allowing to join commander"); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Allowing to join commander"); + } #if NET6_0 __instance.SetCommander(baseTeamSetup.Team, requestingPlayer); __instance.RPC_SynchCommander(baseTeamSetup.Team); @@ -142,7 +152,10 @@ public static GameByteStreamReader RestoreRPC_RequestRoleReader(Player requestin public static void FireOnRoleChangedEvent(Player player, GameModeExt.ETeamRole role) { - MelonLogger.Msg("Firing Role Change Event for " + player.PlayerName + " to role " + role.ToString()); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Firing Role Change Event for " + player.PlayerName + " to role " + role.ToString()); + } OnRoleChangedArgs onRoleChangedArgs = new OnRoleChangedArgs { diff --git a/Si_AdminMod/Event_Units.cs b/Si_AdminMod/Event_Units.cs index 2efe4d1..493e95e 100644 --- a/Si_AdminMod/Event_Units.cs +++ b/Si_AdminMod/Event_Units.cs @@ -67,11 +67,17 @@ public static bool Prefix(UnitCompartment __instance, Unit __0) if (onRequestEnterUnitArgs.Block) { - MelonLogger.Msg("Blocking player " + __0.ControlledBy.PlayerName + " from entering unit " + __instance.OwnerUnit.ToString()); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Blocking player " + __0.ControlledBy.PlayerName + " from entering unit " + __instance.OwnerUnit.ToString()); + } return false; } - MelonLogger.Msg("Allowing player to enter unit's compartment"); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Allowing player to enter unit's compartment"); + } return true; } diff --git a/Si_AdminMod/ModAttributes.cs b/Si_AdminMod/ModAttributes.cs index 2ecb9e1..27b3c18 100644 --- a/Si_AdminMod/ModAttributes.cs +++ b/Si_AdminMod/ModAttributes.cs @@ -21,7 +21,7 @@ You should have received a copy of the GNU General Public License using SilicaAdminMod; using System.Drawing; -[assembly: MelonInfo(typeof(SiAdminMod), "Admin Mod", "2.0.901", "databomb", "https://github.com/data-bomb/Silica")] +[assembly: MelonInfo(typeof(SiAdminMod), "Admin Mod", "2.0.902", "databomb", "https://github.com/data-bomb/Silica")] [assembly: MelonGame("Bohemia Interactive", "Silica")] // Color.Cyan diff --git a/Si_AdminMod/Patch_ClientChat.cs b/Si_AdminMod/Patch_ClientChat.cs index ac1497d..c176868 100644 --- a/Si_AdminMod/Patch_ClientChat.cs +++ b/Si_AdminMod/Patch_ClientChat.cs @@ -52,7 +52,10 @@ public static void OnRequestPlayerChat(object? sender, OnRequestPlayerChatArgs a return; } - MelonLogger.Msg("Processing admin or player command."); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Processing admin or player command."); + } // ignore team chat if preference is set if (args.TeamOnly && SiAdminMod.Pref_Admin_AcceptTeamChatCommands != null && !SiAdminMod.Pref_Admin_AcceptTeamChatCommands.Value) @@ -64,7 +67,10 @@ public static void OnRequestPlayerChat(object? sender, OnRequestPlayerChatArgs a AdminCommand? adminCommand = GetAdminCommand(args.Text); if (adminCommand != null) { - MelonLogger.Msg("Processing admin command: " + adminCommand.AdminCommandText); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Processing admin command: " + adminCommand.AdminCommandText); + } // are they an admin? if (!args.Player.IsAdmin()) @@ -97,7 +103,10 @@ public static void OnRequestPlayerChat(object? sender, OnRequestPlayerChatArgs a return; } - MelonLogger.Msg("Processing player command: " + playerCommand.CommandName); + if (SiAdminMod.Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg("Processing player command: " + playerCommand.CommandName); + } // run the callback playerCommand.PlayerCommandCallback(args.Player, args.Text); diff --git a/Si_AdminMod/Si_AdminMod.cs b/Si_AdminMod/Si_AdminMod.cs index 644a63e..5daee1d 100644 --- a/Si_AdminMod/Si_AdminMod.cs +++ b/Si_AdminMod/Si_AdminMod.cs @@ -35,7 +35,6 @@ You should have received a copy of the GNU General Public License using System.Collections.Generic; using System.Data; using UnityEngine; -using static MelonLoader.MelonLogger; namespace SilicaAdminMod { @@ -46,6 +45,7 @@ public class SiAdminMod : MelonMod public static MelonPreferences_Entry Pre_Admin_VoteDuration = null!; public static MelonPreferences_Entry Pref_Admin_StopNonAdminCheats = null!; public static MelonPreferences_Entry Pref_Admin_ReplicateCheatsForPasswordedServers = null!; + public static MelonPreferences_Entry Pref_Admin_DebugLogMessages = null!; public static List AdminList = null!; @@ -53,7 +53,6 @@ public override void OnInitializeMelon() { try { - AdminMethods.AdminCommands = new List(); PlayerMethods.PlayerCommands = new List(); PlayerMethods.PlayerPhrases = new List(); @@ -65,7 +64,8 @@ public override void OnInitializeMelon() Pre_Admin_VoteDuration ??= _modCategory.CreateEntry("Admin_VoteDuration_Seconds", 30); Pref_Admin_StopNonAdminCheats ??= _modCategory.CreateEntry("Admin_PreventNonAdminCheats", false); Pref_Admin_ReplicateCheatsForPasswordedServers ??= _modCategory.CreateEntry("Admin_ReplicateCheatsForPrivateServers", true); - + Pref_Admin_DebugLogMessages ??= _modCategory.CreateEntry("Admin_EnableDebugLogging", false); + #if !NET6_0 MelonLogger.Msg("Registering host console commands..."); @@ -75,21 +75,30 @@ public override void OnInitializeMelon() DebugConsole.ICommand addAdminConsoleCmd = (DebugConsole.ICommand)Activator.CreateInstance(typeof(CSAM_AddAdmin)); if (addAdminConsoleCmd != null) { - MelonLogger.Msg(addAdminConsoleCmd.Key.ToLower() + " registered."); + if (Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg(addAdminConsoleCmd.Key.ToLower() + " registered."); + } s_Commands.Add(addAdminConsoleCmd.Key.ToLower(), addAdminConsoleCmd); } DebugConsole.ICommand addSayConsoleCmd = (DebugConsole.ICommand)Activator.CreateInstance(typeof(CSAM_Say)); if (addSayConsoleCmd != null) { - MelonLogger.Msg(addSayConsoleCmd.Key.ToLower() + " registered."); + if (Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg(addSayConsoleCmd.Key.ToLower() + " registered."); + } s_Commands.Add(addSayConsoleCmd.Key.ToLower(), addSayConsoleCmd); } DebugConsole.ICommand cvarConsoleCmd = (DebugConsole.ICommand)Activator.CreateInstance(typeof(CSAM_Cvar)); if (cvarConsoleCmd != null) { - MelonLogger.Msg(cvarConsoleCmd.Key.ToLower() + " registered."); + if (Pref_Admin_DebugLogMessages.Value) + { + MelonLogger.Msg(cvarConsoleCmd.Key.ToLower() + " registered."); + } s_Commands.Add(cvarConsoleCmd.Key.ToLower(), cvarConsoleCmd); }