Skip to content

Commit

Permalink
Merge pull request #327 from CCraigen/tb-invuln-cancel
Browse files Browse the repository at this point in the history
Cancels spawn invuln with TB charge. Also tweaks some of the windows in the packet loss meter.
  • Loading branch information
CCraigen authored Mar 16, 2024
2 parents 83daedb + 9be8253 commit 0339d80
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
15 changes: 8 additions & 7 deletions GameMod/MPPacketStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class MPPacketStatus
{
// do yourself a favour and make sure that holdTime is a multiple of sampleTime
public const int sampleTime = 1; // sample window size in seconds
public const int holdTime = 10; // length of time to hold a visible loss value on-screen
public const int holdTime = 5; // length of time to hold a visible loss value on-screen

public const int holdSize = holdTime / sampleTime; // array size for the stats arrays

Expand Down Expand Up @@ -60,10 +60,11 @@ public static void UpdateStatus()
running = true;
if (Time.unscaledTime >= shortUpdate)
{
int loss = NetworkTransport.GetOutgoingPacketNetworkLossPercent(connection.hostId, connection.connectionId, out _);
int drop = NetworkTransport.GetOutgoingPacketOverflowLossPercent(connection.hostId, connection.connectionId, out _);
//int loss = NetworkTransport.GetOutgoingPacketNetworkLossPercent(connection.hostId, connection.connectionId, out _);
//int drop = NetworkTransport.GetOutgoingPacketOverflowLossPercent(connection.hostId, connection.connectionId, out _);
//outErr = Math.Max(loss + drop, outErr); // this one keeps the max 1/4-second recorded value
outErr += loss + drop; // this one is for the average over the sampleTime
//outErr += loss + drop; // this one is for the average over the sampleTime
outErr += NetworkTransport.GetOutgoingPacketNetworkLossPercent(connection.hostId, connection.connectionId, out _);

shortUpdate = Time.unscaledTime + 0.25f;
}
Expand Down Expand Up @@ -91,8 +92,8 @@ public static void UpdateStatus()
OutStatus = Math.Max(OutStatus, outStats[i]);
}

InColor = Color.Lerp(UIManager.m_col_good_ping, UIManager.m_col_em5, InStatus / 10f); // 10f since anything over 0% is bad, if you're at 10% it's terrible
OutColor = Color.Lerp(UIManager.m_col_good_ping, UIManager.m_col_em5, OutStatus / 10f);
InColor = Color.Lerp(UIManager.m_col_good_ping, UIManager.m_col_em5, InStatus / 20f); // 20f since anything over 0% is bad, if you're at 20% it's terrible
OutColor = Color.Lerp(UIManager.m_col_good_ping, UIManager.m_col_em5, OutStatus / 20f);

if (InStatus > InMin)
{
Expand Down Expand Up @@ -131,7 +132,7 @@ public static void UpdateStatus()
}
}

[HarmonyPatch(typeof(Client), "Update")]
[HarmonyPatch(typeof(Client), "FixedUpdate")]
class MPPacketStatus_Client_Update
{
static void Postfix()
Expand Down
13 changes: 13 additions & 0 deletions GameMod/MPSpawnInvuln.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,17 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> code
}
}
}

// Cancels spawn invuln if a player starts charging Thunderbolt
[HarmonyPatch(typeof(PlayerShip), "ThunderCharge")]
internal class MPSpawnInvuln_PlayerShip_ThunderCharge
{
static void Postfix(Player ___c_player)
{
if (GameplayManager.IsMultiplayerActive && ___c_player.m_spawn_invul_active)
{
___c_player.m_timer_invuln = (float)___c_player.m_timer_invuln - (float)NetworkMatch.m_respawn_shield_seconds;
}
}
}
}

0 comments on commit 0339d80

Please sign in to comment.