Skip to content

Commit

Permalink
Add Unity markup for Console Messages
Browse files Browse the repository at this point in the history
- Adds Unity markup (colors, bold, etc.) to the console messages such as the kill feed
- Adds a console message for when a player disconnects
- Adds a console message for when a map is loaded
- Adds a console message for when a game ends in a draw
- Adds a console message for when a round has begun
  • Loading branch information
data-bomb committed Jul 10, 2024
1 parent 3d66601 commit 82c6370
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions Si_Logging/Si_Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ You should have received a copy of the GNU General Public License
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Runtime.CompilerServices;

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

Expand All @@ -52,8 +53,6 @@ namespace Si_Logging
// https://developer.valvesoftware.com/wiki/HL_Log_Standard
public class HL_Logging : MelonMod
{
const string defaultConsoleColor = "<color=#FDE8BB>";

static int[] teamResourcesCollected = new int[SiConstants.MaxPlayableTeams + 1];
static Player?[]? lastCommander;

Expand Down Expand Up @@ -212,6 +211,12 @@ public override void OnSceneWasLoaded(int buildIndex, string sceneName)

string LogLine = "Loading map \"" + sceneName + "\"";
PrintLogLine(LogLine);

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = "<b>Loading map \"" + sceneName + "\"</b>";
HelperMethods.SendConsoleMessage(ConsoleLine);
}
}
catch (Exception error)
{
Expand Down Expand Up @@ -290,6 +295,12 @@ public static void Prefix(GameMode __instance, Player __0)

string LogLine = "\"" + __0.PlayerName + "<" + userID + "><" + GetPlayerID(__0) + "><" + teamName + ">\" disconnected";
PrintLogLine(LogLine);

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = "<b>" + HelperMethods.GetTeamColor(__0) + __0.PlayerName + "</color></b> disconnected.";
HelperMethods.SendConsoleMessage(ConsoleLine);
}
}
}
catch (Exception error)
Expand Down Expand Up @@ -317,6 +328,7 @@ public static void Postfix(Player __0)
{
teamName = __0.Team.TeamShortName;
}

string LogLine = "Kick: \"" + __0.PlayerName + "<" + userID + "><" + GetPlayerID(__0) + "><" + teamName + "\" was kicked by \"Console\" (message \"\")";
PrintLogLine(LogLine);
}
Expand Down Expand Up @@ -356,7 +368,7 @@ public static void Postfix(StrategyMode __instance, Unit __0, EDamageType __1, U
bool isVictimHuman = (victimPlayer != null);
bool isAttackerHuman = (attackerPlayer != null);

#pragma warning disable CS8602 // Dereference of a possibly null reference.
#pragma warning disable CS8602 // Dereference of a possibly null reference.
if (isVictimHuman)
{

Expand All @@ -379,7 +391,7 @@ public static void Postfix(StrategyMode __instance, Unit __0, EDamageType __1, U

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = victimPlayer.PlayerName + " (" + __2.ToString().Split('(')[0] + ") committed suicide";
string ConsoleLine = "<b>" + HelperMethods.GetTeamColor(victimPlayer) + victimPlayer.PlayerName + "</color></b> (" + __2.ToString().Split('(')[0] + ") committed suicide";
HelperMethods.SendConsoleMessage(ConsoleLine);
}
}
Expand All @@ -392,7 +404,7 @@ public static void Postfix(StrategyMode __instance, Unit __0, EDamageType __1, U

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = attackerPlayer.PlayerName + " (" + __2.ToString().Split('(')[0] + ") killed " + victimPlayer.PlayerName + " (" + __0.ToString().Split('(')[0] + ")";
string ConsoleLine = "<b>" + HelperMethods.GetTeamColor(attackerPlayer) + attackerPlayer.PlayerName + "</color></b> (" + __2.ToString().Split('(')[0] + ") killed <b>" + HelperMethods.GetTeamColor(victimPlayer) + victimPlayer.PlayerName + "</color></b> (" + __0.ToString().Split('(')[0] + ")";
HelperMethods.SendConsoleMessage(ConsoleLine);
}
}
Expand All @@ -405,7 +417,7 @@ public static void Postfix(StrategyMode __instance, Unit __0, EDamageType __1, U

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = "AI (" + __2.ToString().Split('(')[0] + ")" + " killed " + victimPlayer.PlayerName + " (" + __0.ToString().Split('(')[0] + ")";
string ConsoleLine = "<b>AI</b> (" + __2.ToString().Split('(')[0] + ")" + " killed <b>" + HelperMethods.GetTeamColor(victimPlayer) + victimPlayer.PlayerName + "</color></b> (" + __0.ToString().Split('(')[0] + ")";
HelperMethods.SendConsoleMessage(ConsoleLine);
}
}
Expand All @@ -419,7 +431,7 @@ public static void Postfix(StrategyMode __instance, Unit __0, EDamageType __1, U

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = attackerPlayer.PlayerName + " (" + __2.ToString().Split('(')[0] + ") killed " + "AI (" + __0.ToString().Split('(')[0] + ")";
string ConsoleLine = "<b>" + HelperMethods.GetTeamColor(attackerPlayer) + attackerPlayer.PlayerName + "</color></b> (" + __2.ToString().Split('(')[0] + ") killed " + "<b>AI</b> (" + __0.ToString().Split('(')[0] + ")";
HelperMethods.SendConsoleMessage(ConsoleLine);
}
}
Expand Down Expand Up @@ -474,14 +486,7 @@ public static void Postfix(MP_Strategy __instance, Player __0, Team __1, Team __
if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = string.Empty;
if (__1 == null)
{
ConsoleLine = __0.PlayerName + " joined team " + __2.TeamShortName;
}
else
{
ConsoleLine = __0.PlayerName + " changed teams to " + __2.TeamShortName;
}
ConsoleLine = "<b>" + HelperMethods.GetTeamColor(__0) + __0.PlayerName + "</color></b> " + (__1 == null ? "joined team " : "changed teams ") + HelperMethods.GetTeamColor(__2) + __2.TeamShortName + "</color>";

HelperMethods.SendConsoleMessage(ConsoleLine);
}
Expand Down Expand Up @@ -697,7 +702,7 @@ public static void Postfix(MP_Strategy __instance, Structure __0, EDamageType __

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = attackerPlayer.PlayerName + " destroyed a structure (" + structName + ")";
string ConsoleLine = "<b>" + HelperMethods.GetTeamColor(attackerPlayer) + attackerPlayer.PlayerName + "</color></b> destroyed a structure (" + HelperMethods.GetTeamColor(__0.Team) + structName + "</color>)";
HelperMethods.SendConsoleMessageToTeam(attackerPlayer.Team, ConsoleLine);
}
}
Expand Down Expand Up @@ -772,6 +777,13 @@ public static void Postfix(MusicJukeboxHandler __instance, GameMode __0, Team __
{
string RoundWinLogEarlyLine = "World triggered \"Round_Win\" (gametype \"" + versusMode.ToString() + "\")";
PrintLogLine(RoundWinLogEarlyLine);

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = "<b>Round is over. Game is a draw.</b>";
HelperMethods.SendConsoleMessage(ConsoleLine);
}

return;
}

Expand All @@ -780,7 +792,7 @@ public static void Postfix(MusicJukeboxHandler __instance, GameMode __0, Team __

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = "Team " + __1.TeamShortName + " is victorious!";
string ConsoleLine = "<b>Team " + HelperMethods.GetTeamColor(__1) + __1.TeamShortName + "</color> is victorious!</b>";
HelperMethods.SendConsoleMessage(ConsoleLine);
}

Expand Down Expand Up @@ -897,7 +909,6 @@ public static void Postfix(ConstructionSite constructionSite, bool wasCompleted)
{
HelperMethods.PrintError(error, "Failed to run OnSetConstructionSite");
}

}
}

Expand All @@ -923,6 +934,12 @@ public static void Prefix(MusicJukeboxHandler __instance, GameMode __0)
initializeRound(ref currTiers);

firedRoundEndOnce = false;

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = "<b>Round has begun.</b>";
HelperMethods.SendConsoleMessage(ConsoleLine);
}
}
catch (Exception error)
{
Expand Down

0 comments on commit 82c6370

Please sign in to comment.