Skip to content

Commit

Permalink
Logging Game Fixes for v0.8.76+
Browse files Browse the repository at this point in the history
- Fixed changed prototype for OnUnitDestroyed, OnStructureDestroyed, and OnDamageReceived
- Damage type information is missing and shows up as blank (dmgtype "")
  • Loading branch information
data-bomb committed Sep 5, 2024
1 parent 39f3148 commit e64fbe4
Showing 1 changed file with 76 additions and 67 deletions.
143 changes: 76 additions & 67 deletions Si_Logging/Si_Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ You should have received a copy of the GNU General Public License
using System.Text;
using System.Runtime.CompilerServices;

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

Expand Down Expand Up @@ -341,17 +341,17 @@ public static void Postfix(Player __0)
[HarmonyPatch(typeof(StrategyMode), nameof(StrategyMode.OnUnitDestroyed))]
private static class ApplyPatch_StrategyMode_OnUnitDestroyed
{
public static void Postfix(StrategyMode __instance, Unit __0, EDamageType __1, UnityEngine.GameObject __2)
public static void Postfix(StrategyMode __instance, Unit __0, UnityEngine.GameObject __1)
{
try
{
if (__0 == null || __2 == null)
if (__0 == null || __1 == null)
{
return;
}

// Attacker
BaseGameObject attackerBase = GameFuncs.GetBaseGameObject(__2);
BaseGameObject attackerBase = GameFuncs.GetBaseGameObject(__1);
if (attackerBase == null)
{
return;
Expand Down Expand Up @@ -383,38 +383,38 @@ public static void Postfix(StrategyMode __instance, Unit __0, EDamageType __1, U
if (isSuicide)
{

string LogLine = "\"" + victimPlayer.PlayerName + "<" + victimUserID + "><" + GetPlayerID(victimPlayer) + "><" + victimPlayer.Team.TeamShortName + ">\" committed suicide with \"" + __2.ToString().Split('(')[0] + "\" (dmgtype \"" + __1.ToString() + "\")";
string LogLine = "\"" + victimPlayer.PlayerName + "<" + victimUserID + "><" + GetPlayerID(victimPlayer) + "><" + victimPlayer.Team.TeamShortName + ">\" committed suicide with \"" + __1.ToString().Split('(')[0] + "\" (dmgtype \"\")";
PrintLogLine(LogLine);

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = "<b>" + HelperMethods.GetTeamColor(victimPlayer) + victimPlayer.PlayerName + "</color></b> (" + __2.ToString().Split('(')[0] + ") committed suicide";
string ConsoleLine = "<b>" + HelperMethods.GetTeamColor(victimPlayer) + victimPlayer.PlayerName + "</color></b> (" + __1.ToString().Split('(')[0] + ") committed suicide";
HelperMethods.SendConsoleMessage(ConsoleLine);
}
}
// human-controlled player killed another human-controlled player
else
{
int attackerUserID = Math.Abs(attackerPlayer.GetInstanceID());
string LogLine = "\"" + attackerPlayer.PlayerName + "<" + attackerUserID + "><" + GetPlayerID(attackerPlayer) + "><" + attackerPlayer.Team.TeamShortName + ">\" killed \"" + victimPlayer.PlayerName + "<" + victimUserID + "><" + GetPlayerID(victimPlayer) + "><" + victimPlayer.Team.TeamShortName + ">\" with \"" + __2.ToString().Split('(')[0] + "\" (dmgtype \"" + __1.ToString() + "\") (victim \"" + __0.ToString().Split('(')[0] + "\")";
string LogLine = "\"" + attackerPlayer.PlayerName + "<" + attackerUserID + "><" + GetPlayerID(attackerPlayer) + "><" + attackerPlayer.Team.TeamShortName + ">\" killed \"" + victimPlayer.PlayerName + "<" + victimUserID + "><" + GetPlayerID(victimPlayer) + "><" + victimPlayer.Team.TeamShortName + ">\" with \"" + __1.ToString().Split('(')[0] + "\" (dmgtype \"\") (victim \"" + __0.ToString().Split('(')[0] + "\")";
PrintLogLine(LogLine);

if (Pref_Log_PlayerConsole_Enable.Value)
{
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] + ")";
string ConsoleLine = "<b>" + HelperMethods.GetTeamColor(attackerPlayer) + attackerPlayer.PlayerName + "</color></b> (" + __1.ToString().Split('(')[0] + ") killed <b>" + HelperMethods.GetTeamColor(victimPlayer) + victimPlayer.PlayerName + "</color></b> (" + __0.ToString().Split('(')[0] + ")";
HelperMethods.SendConsoleMessage(ConsoleLine);
}
}
}
else if (Pref_Log_Kills_Include_AI_vs_Player.Value)
// Attacker is an AI, Victim is a human
{
string LogLine = "\"" + __2.ToString().Split('(')[0] + "<><><" + attackerBase.Team.TeamShortName + ">\" killed \"" + victimPlayer.PlayerName + "<" + victimUserID + "><" + GetPlayerID(victimPlayer) + "><" + victimPlayer.Team.TeamShortName + ">\" with \"" + __2.ToString().Split('(')[0] + "\" (dmgtype \"" + __1.ToString() + "\") (victim \"" + __0.ToString().Split('(')[0] + "\")";
string LogLine = "\"" + __1.ToString().Split('(')[0] + "<><><" + attackerBase.Team.TeamShortName + ">\" killed \"" + victimPlayer.PlayerName + "<" + victimUserID + "><" + GetPlayerID(victimPlayer) + "><" + victimPlayer.Team.TeamShortName + ">\" with \"" + __1.ToString().Split('(')[0] + "\" (dmgtype \"\") (victim \"" + __0.ToString().Split('(')[0] + "\")";
PrintLogLine(LogLine);

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = "<b>AI</b> (" + __2.ToString().Split('(')[0] + ")" + " killed <b>" + HelperMethods.GetTeamColor(victimPlayer) + victimPlayer.PlayerName + "</color></b> (" + __0.ToString().Split('(')[0] + ")";
string ConsoleLine = "<b>AI</b> (" + __1.ToString().Split('(')[0] + ")" + " killed <b>" + HelperMethods.GetTeamColor(victimPlayer) + victimPlayer.PlayerName + "</color></b> (" + __0.ToString().Split('(')[0] + ")";
HelperMethods.SendConsoleMessage(ConsoleLine);
}
}
Expand All @@ -423,12 +423,12 @@ public static void Postfix(StrategyMode __instance, Unit __0, EDamageType __1, U
// Attacker is a human, Victim is an AI
{
int attackerUserID = Math.Abs(attackerPlayer.GetInstanceID());
string LogLine = "\"" + attackerPlayer.PlayerName + "<" + attackerUserID + "><" + GetPlayerID(attackerPlayer) + "><" + attackerPlayer.Team.TeamShortName + ">\" killed \"" + __0.ToString().Split('(')[0] + "<><><" + __0.Team.TeamShortName + ">\" with \"" + __2.ToString().Split('(')[0] + "\" (dmgtype \"" + __1.ToString() + "\") (victim \"" + __0.ToString().Split('(')[0] + "\")";
string LogLine = "\"" + attackerPlayer.PlayerName + "<" + attackerUserID + "><" + GetPlayerID(attackerPlayer) + "><" + attackerPlayer.Team.TeamShortName + ">\" killed \"" + __0.ToString().Split('(')[0] + "<><><" + __0.Team.TeamShortName + ">\" with \"" + __1.ToString().Split('(')[0] + "\" (dmgtype \"\") (victim \"" + __0.ToString().Split('(')[0] + "\")";
PrintLogLine(LogLine);

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = "<b>" + HelperMethods.GetTeamColor(attackerPlayer) + attackerPlayer.PlayerName + "</color></b> (" + __2.ToString().Split('(')[0] + ") killed " + "<b>AI</b> (" + __0.ToString().Split('(')[0] + ")";
string ConsoleLine = "<b>" + HelperMethods.GetTeamColor(attackerPlayer) + attackerPlayer.PlayerName + "</color></b> (" + __1.ToString().Split('(')[0] + ") killed " + "<b>AI</b> (" + __0.ToString().Split('(')[0] + ")";
HelperMethods.SendConsoleMessage(ConsoleLine);
}
}
Expand Down Expand Up @@ -558,7 +558,7 @@ public static void Postfix(NetworkID __0, int __1, string __2)
#endif
private static class ApplyPatchOnDamageReceived
{
public static void Postfix(DamageManager __instance, UnityEngine.Collider __0, float __1, EDamageType __2, UnityEngine.GameObject __3, UnityEngine.Vector3 __4)
public static void Postfix(DamageManager __instance, float __0, GameObject __1, byte __2, bool __3)
{
// should we log the damage?
if (!Pref_Log_Damage.Value)
Expand All @@ -567,12 +567,12 @@ public static void Postfix(DamageManager __instance, UnityEngine.Collider __0, f
}

// was it a non-human-controlled instigator?
if (__3 == null)
if (__1 == null)
{
return;
}

BaseGameObject attackerBase = GameFuncs.GetBaseGameObject(__3);
BaseGameObject attackerBase = GameFuncs.GetBaseGameObject(__1);
if (attackerBase == null)
{
return;
Expand Down Expand Up @@ -610,15 +610,15 @@ public static void Postfix(DamageManager __instance, UnityEngine.Collider __0, f
}

// was damage less than (or equal to) 1?
int damage = (int)Math.Ceiling(__1);
int damage = (int)Math.Ceiling(__0);
if (damage <= 1)
{
return;
}

int attackerUserID = Math.Abs(attackerPlayer.GetInstanceID());
int victimUserID = Math.Abs(victimPlayer.GetInstanceID());
string LogLine = "\"" + attackerPlayer.PlayerName + "<" + attackerUserID + "><" + GetPlayerID(attackerPlayer) + "><" + attackerPlayer.Team.TeamShortName + ">\" attacked \"" + victimPlayer.PlayerName + "<" + victimUserID + "><" + GetPlayerID(victimPlayer) + "><" + victimPlayer.Team.TeamShortName + ">\" with \"" + __3.ToString().Split('(')[0] + "\"" + " (damage \"" + damage.ToString() + "\")";
string LogLine = "\"" + attackerPlayer.PlayerName + "<" + attackerUserID + "><" + GetPlayerID(attackerPlayer) + "><" + attackerPlayer.Team.TeamShortName + ">\" attacked \"" + victimPlayer.PlayerName + "<" + victimUserID + "><" + GetPlayerID(victimPlayer) + "><" + victimPlayer.Team.TeamShortName + ">\" with \"" + __1.ToString().Split('(')[0] + "\"" + " (damage \"" + damage.ToString() + "\")";
PrintLogLine(LogLine, true);
}
}
Expand All @@ -630,13 +630,16 @@ public static void Postfix(DamageManager __instance, UnityEngine.Collider __0, f
[HarmonyPatch(typeof(MP_Strategy), nameof(MP_Strategy.OnStructureDestroyed))]
private static class ApplyPatchOnStructureDestroyed
{
public static void Postfix(MP_Strategy __instance, Structure __0, EDamageType __1, UnityEngine.GameObject __2)
public static void Postfix(MP_Strategy __instance, Structure __0, UnityEngine.GameObject __1)
{
try
{
//check if the destruction affects the tech tier.
if (__0 == null) return;
if (__0 == null)
{
return;
}

//check if the destruction affects the tech tier.
if (__0.Team != null)
{
Team structureTeam = __0.Team;
Expand All @@ -647,63 +650,69 @@ public static void Postfix(MP_Strategy __instance, Structure __0, EDamageType __
LogTierChange(structureTeam, tier);
}
}
if (__2 == null) return;

// Attacker
BaseGameObject attackerBase = GameFuncs.GetBaseGameObject(__2);
if (__1 == null)
{
return;
}

if (attackerBase != null)
// Attacker
BaseGameObject attackerBase = GameFuncs.GetBaseGameObject(__1);
if (attackerBase == null)
{
NetworkComponent attackerNetComp = attackerBase.NetworkComponent;
// was teamkiller a playable character?
if (attackerNetComp != null)
{
Player attackerPlayer = attackerNetComp.OwnerPlayer;
return;
}

if (attackerPlayer != null)
{
int userID = Math.Abs(attackerPlayer.GetInstanceID());
string structName;
if (__0.ToString().Contains('_'))
{
structName = __0.ToString().Split('_')[0];
}
else if (__0.ToString().Contains('('))
{
structName = __0.ToString().Split('(')[0];
}
else
{
structName = __0.ToString();
}
NetworkComponent attackerNetComp = attackerBase.NetworkComponent;
// was teamkiller a playable character?
if (attackerNetComp == null)
{
return;
}

string attackerPlayerTeam;
if (attackerPlayer.Team == null)
{
attackerPlayerTeam = "";
}
else
{
attackerPlayerTeam = attackerPlayer.Team.TeamShortName;
}
Player attackerPlayer = attackerNetComp.OwnerPlayer;

if (__0.Team == null || attackerPlayer.Team == null)
{
return;
}
if (attackerPlayer != null)
{
int userID = Math.Abs(attackerPlayer.GetInstanceID());
string structName;
if (__0.ToString().Contains('_'))
{
structName = __0.ToString().Split('_')[0];
}
else if (__0.ToString().Contains('('))
{
structName = __0.ToString().Split('(')[0];
}
else
{
structName = __0.ToString();
}

string attackerPlayerTeam;
if (attackerPlayer.Team == null)
{
attackerPlayerTeam = "";
}
else
{
attackerPlayerTeam = attackerPlayer.Team.TeamShortName;
}

string structTeam = __0.Team.TeamShortName;
if (__0.Team == null || attackerPlayer.Team == null)
{
return;
}

string LogLine = "\"" + attackerPlayer.PlayerName + "<" + userID + "><" + GetPlayerID(attackerPlayer) + "><" + attackerPlayerTeam + ">\" triggered \"structure_kill\" (structure \"" + structName + "\") (struct_team \"" + structTeam + "\")";
PrintLogLine(LogLine);
string structTeam = __0.Team.TeamShortName;

if (Pref_Log_PlayerConsole_Enable.Value)
{
string ConsoleLine = "<b>" + HelperMethods.GetTeamColor(attackerPlayer) + attackerPlayer.PlayerName + "</color></b> destroyed a structure (" + HelperMethods.GetTeamColor(__0.Team) + structName + "</color>)";
HelperMethods.SendConsoleMessageToTeam(attackerPlayer.Team, ConsoleLine);
}
}
string LogLine = "\"" + attackerPlayer.PlayerName + "<" + userID + "><" + GetPlayerID(attackerPlayer) + "><" + attackerPlayerTeam + ">\" triggered \"structure_kill\" (structure \"" + structName + "\") (struct_team \"" + structTeam + "\")";
PrintLogLine(LogLine);

if (Pref_Log_PlayerConsole_Enable.Value)
{
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

0 comments on commit e64fbe4

Please sign in to comment.