Skip to content

Commit

Permalink
fix: errors in ESPMod
Browse files Browse the repository at this point in the history
there were tons of NullReferenceException and IndexOutOfRangeException in the BepInEx console after end of round
  • Loading branch information
armorfid committed Jan 4, 2024
1 parent 9e97750 commit f04f572
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 9 additions & 0 deletions lc-hax/Scripts/Helpers/FindNonNullObjectsOfType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Hax;

public static partial class Helper {
public static IEnumerable<T> FindNonNullObjectsOfType<T>() where T : Object => Object.FindObjectsOfType<T>().Where(obj => obj != null);
}
12 changes: 6 additions & 6 deletions lc-hax/Scripts/Modules/ESPMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Generic;
using GameNetcodeStuff;
using UnityEngine;
using UnityObject = UnityEngine.Object;

namespace Hax;

Expand Down Expand Up @@ -31,7 +30,7 @@ void OnGUI() {
if (!this.InGame || !Helper.CurrentCamera.IsNotNull(out Camera camera)) return;

this.PlayerRenderers.ForEach(rendererPair => {
if (rendererPair.GameObject.isPlayerDead) return;
if (rendererPair.GameObject.Unfake()?.isPlayerDead ?? true) return;
this.RenderBounds(
camera,
Expand Down Expand Up @@ -64,10 +63,11 @@ void OnGUI() {
HaxObjects.Instance?.EnemyAIs.ForEach(nullableEnemy => {
if (!nullableEnemy.IsNotNull(out EnemyAI enemy)) return;
if (enemy is DocileLocustBeesAI or DoublewingAI) return;
if (!enemy.skinnedMeshRenderers.FirstOrDefault().IsNotNull(out SkinnedMeshRenderer meshRenderer)) return;
this.RenderBounds(
camera,
enemy.skinnedMeshRenderers[0],
meshRenderer,
Color.red,
this.RenderEnemy(enemy)
);
Expand All @@ -86,15 +86,15 @@ void InitialiseRenderers() {
new RendererPair<PlayerControllerB, SkinnedMeshRenderer>(player, player.thisPlayerModel)
);

this.LandmineRenderers = UnityObject.FindObjectsOfType<Landmine>().Select(landmine =>
this.LandmineRenderers = Helper.FindNonNullObjectsOfType<Landmine>().Select(landmine =>
landmine.GetComponent<Renderer>()
);

this.TurretRenderers = UnityObject.FindObjectsOfType<Turret>().Select(turret =>
this.TurretRenderers = Helper.FindNonNullObjectsOfType<Turret>().Select(turret =>
turret.GetComponent<Renderer>()
);

this.EntranceRenderers = UnityObject.FindObjectsOfType<EntranceTeleport>().Select(entrance =>
this.EntranceRenderers = Helper.FindNonNullObjectsOfType<EntranceTeleport>().Select(entrance =>
entrance.GetComponent<Renderer>()
);
}
Expand Down

0 comments on commit f04f572

Please sign in to comment.