Skip to content

Commit

Permalink
perf: do not render certain renderers in lobby
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Feb 12, 2024
1 parent 7c4de9a commit 8163e12
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions lc-hax/Scripts/Modules/ESPMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,35 @@ internal class ESPMod : MonoBehaviour {
Vector3[] StoryLogVectors { get; set; } = [];

bool InGame { get; set; } = false;
bool IsMapLoaded { get; set; } = false;
bool Enabled { get; set; } = true;

void OnEnable() {
GameListener.OnLevelGenerated += this.Initialise;
GameListener.OnGameStart += this.Initialise;
GameListener.OnGameEnd += this.OnGameEnd;
GameListener.OnLevelGenerated += this.OnMapLoaded;
GameListener.OnShipLeave += this.OnShipLeave;
InputListener.OnPausePress += this.ToggleESP;
}

void OnDisable() {
GameListener.OnLevelGenerated -= this.Initialise;
GameListener.OnGameStart -= this.Initialise;
GameListener.OnGameEnd -= this.OnGameEnd;
GameListener.OnLevelGenerated -= this.OnMapLoaded;
GameListener.OnShipLeave -= this.OnShipLeave;
InputListener.OnPausePress -= this.ToggleESP;
}

void OnGUI() {
if (!this.Enabled || !this.InGame || Helper.CurrentCamera is not Camera camera) return;

this.RenderAlways(camera);
this.RenderWhenMapLoads(camera);
}

void RenderAlways(Camera camera) {
this.PlayerRenderers.ForEach(rendererPair => {
if (rendererPair.GameObject is not PlayerControllerB player) return;
if (player.isPlayerDead || !player.isPlayerControlled) return;
Expand All @@ -44,21 +54,38 @@ void OnGUI() {
);
});

this.LandmineRenderers.WhereIsNotNull().ForEach(renderer => this.RenderBounds(
Helper.Grabbables.WhereIsNotNull().ForEach(grabbableObject => {
Vector3 rendererCentrePoint = camera.WorldToEyesPoint(grabbableObject.transform.position);
if (rendererCentrePoint.z <= 2.0f) {
return;
}
this.RenderLabel($"{grabbableObject.itemProperties.itemName} ${grabbableObject.scrapValue}").Invoke(
Color.gray,
rendererCentrePoint
);
});
}

void RenderWhenMapLoads(Camera camera) {
if (!this.IsMapLoaded) return;

this.LandmineRenderers.ForEach(renderer => this.RenderBounds(
camera,
renderer.bounds,
Color.yellow,
this.RenderLabel("Landmine")
));

this.TurretRenderers.WhereIsNotNull().ForEach(renderer => this.RenderBounds(
this.TurretRenderers.ForEach(renderer => this.RenderBounds(
camera,
renderer.bounds,
Color.yellow,
this.RenderLabel("Turret")
));

this.EntranceRenderers.WhereIsNotNull().ForEach(renderer => this.RenderBounds(
this.EntranceRenderers.ForEach(renderer => this.RenderBounds(
camera,
renderer.bounds,
Color.yellow,
Expand Down Expand Up @@ -95,19 +122,6 @@ void OnGUI() {
);
});

Helper.Grabbables.WhereIsNotNull().ForEach(grabbableObject => {
Vector3 rendererCentrePoint = camera.WorldToEyesPoint(grabbableObject.transform.position);
if (rendererCentrePoint.z <= 2.0f) {
return;
}
this.RenderLabel($"{grabbableObject.itemProperties.itemName} ${grabbableObject.scrapValue}").Invoke(
Color.gray,
rendererCentrePoint
);
});

if (Helper.StartOfRound?.shipBounds is Collider shipBounds) {
this.RenderBounds(
camera,
Expand All @@ -127,6 +141,10 @@ void Initialise() {

void OnGameEnd() => this.InGame = false;

void OnShipLeave() => this.IsMapLoaded = false;

void OnMapLoaded() => this.IsMapLoaded = true;

void ToggleESP() => this.Enabled = !this.Enabled;

Renderer[] GetRenderers<T>() where T : Component =>
Expand Down

0 comments on commit 8163e12

Please sign in to comment.