Skip to content

Commit

Permalink
directly access count to prevent out of range index
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddio0141 committed Sep 1, 2023
1 parent d18afba commit 02db6c5
Showing 1 changed file with 16 additions and 36 deletions.
52 changes: 16 additions & 36 deletions UniTAS/Patcher/Utils/MonoBehaviourEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,12 @@ public static event Action OnLastUpdateActual

public static void InvokeLastUpdate()
{
var unconditionalCount = LastUpdatesUnconditional.Count;
for (var i = 0; i < unconditionalCount; i++)
for (var i = 0; i < LastUpdatesUnconditional.Count; i++)
{
LastUpdatesUnconditional[i]();
}

var actualCount = LastUpdatesActual.Count;
for (var i = 0; i < actualCount; i++)
for (var i = 0; i < LastUpdatesActual.Count; i++)
{
var lastUpdate = LastUpdatesActual[i];
if (MonoBehaviourController.PausedExecution || MonoBehaviourController.PausedUpdate) continue;
Expand All @@ -159,14 +157,12 @@ public static void InvokeLastUpdate()
// calls awake before any other script
public static void InvokeAwake()
{
var unconditionalCount = AwakesUnconditional.Count;
for (var i = 0; i < unconditionalCount; i++)
for (var i = 0; i < AwakesUnconditional.Count; i++)
{
AwakesUnconditional[i]();
}

var actualCount = AwakesActual.Count;
for (var i = 0; i < actualCount; i++)
for (var i = 0; i < AwakesActual.Count; i++)
{
var awake = AwakesActual[i];
if (!MonoBehaviourController.PausedExecution)
Expand All @@ -177,14 +173,12 @@ public static void InvokeAwake()
// calls onEnable before any other script
public static void InvokeOnEnable()
{
var unconditionalCount = EnablesUnconditional.Count;
for (var i = 0; i < unconditionalCount; i++)
for (var i = 0; i < EnablesUnconditional.Count; i++)
{
EnablesUnconditional[i]();
}

var actualCount = EnablesActual.Count;
for (var i = 0; i < actualCount; i++)
for (var i = 0; i < EnablesActual.Count; i++)
{
var enable = EnablesActual[i];
if (!MonoBehaviourController.PausedExecution)
Expand All @@ -195,18 +189,12 @@ public static void InvokeOnEnable()
// calls start before any other script
public static void InvokeStart()
{
OnStartUnconditional?.Invoke();
if (!MonoBehaviourController.PausedExecution)
OnStartActual?.Invoke();
}
var unconditionalCount = StartsUnconditional.Count;
for (var i = 0; i < unconditionalCount; i++)
for (var i = 0; i < StartsUnconditional.Count; i++)
{
StartsUnconditional[i]();
}

var actualCount = StartsActual.Count;
for (var i = 0; i < actualCount; i++)
for (var i = 0; i < StartsActual.Count; i++)
{
var start = StartsActual[i];
if (!MonoBehaviourController.PausedExecution)
Expand All @@ -227,14 +215,12 @@ public static void InvokeUpdate()
InvokeCallOnPreUpdate();
}

var unconditionalCount = UpdatesUnconditional.Count;
for (var i = 0; i < unconditionalCount; i++)
for (var i = 0; i < UpdatesUnconditional.Count; i++)
{
UpdatesUnconditional[i]();
}

var actualCount = UpdatesActual.Count;
for (var i = 0; i < actualCount; i++)
for (var i = 0; i < UpdatesActual.Count; i++)
{
var update = UpdatesActual[i];
if (MonoBehaviourController.PausedExecution || MonoBehaviourController.PausedUpdate) continue;
Expand All @@ -256,14 +242,12 @@ public static void InvokeFixedUpdate()

InvokeCallOnPreUpdate();

var unconditionalCount = FixedUpdatesUnconditional.Count;
for (var i = 0; i < unconditionalCount; i++)
for (var i = 0; i < FixedUpdatesUnconditional.Count; i++)
{
FixedUpdatesUnconditional[i]();
}

var actualCount = FixedUpdatesActual.Count;
for (var i = 0; i < actualCount; i++)
for (var i = 0; i < FixedUpdatesActual.Count; i++)
{
var fixedUpdate = FixedUpdatesActual[i];
if (!MonoBehaviourController.PausedExecution)
Expand All @@ -274,14 +258,12 @@ public static void InvokeFixedUpdate()
public static void InvokeOnGUI()
{
// currently, this doesn't get called before other scripts
var unconditionalCount = GUIsUnconditional.Count;
for (var i = 0; i < unconditionalCount; i++)
for (var i = 0; i < GUIsUnconditional.Count; i++)
{
GUIsUnconditional[i]();
}

var actualCount = GUIsActual.Count;
for (var i = 0; i < actualCount; i++)
for (var i = 0; i < GUIsActual.Count; i++)
{
var gui = GUIsActual[i];
if (!MonoBehaviourController.PausedExecution)
Expand All @@ -291,14 +273,12 @@ public static void InvokeOnGUI()

private static void InvokeCallOnPreUpdate()
{
var unconditionalCount = PreUpdatesUnconditional.Count;
for (var i = 0; i < unconditionalCount; i++)
for (var i = 0; i < PreUpdatesUnconditional.Count; i++)
{
PreUpdatesUnconditional[i]();
}

var actualCount = PreUpdatesActual.Count;
for (var i = 0; i < actualCount; i++)
for (var i = 0; i < PreUpdatesActual.Count; i++)
{
var preUpdate = PreUpdatesActual[i];
if (!MonoBehaviourController.PausedExecution)
Expand Down

0 comments on commit 02db6c5

Please sign in to comment.