Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve clearvision #519

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 110 additions & 85 deletions lc-hax/Scripts/Modules/ClearVisionMod.cs
Original file line number Diff line number Diff line change
@@ -1,115 +1,140 @@
using System.Collections;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
using GameNetcodeStuff;
using Hax;
using System;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;

sealed class ClearVisionMod : MonoBehaviour {
float LightIntensity { get; set; } = 2.0f;

void OnEnable() {
InputListener.OnF4Press += this.DecreaseLightIntensity;
InputListener.OnF5Press += this.IncreaseLightIntensity;
}

void OnDisable() {
InputListener.OnF4Press -= this.DecreaseLightIntensity;
InputListener.OnF5Press -= this.IncreaseLightIntensity;
}

void IncreaseLightIntensity() => this.LightIntensity = Math.Clamp(this.LightIntensity + 1.0f, 0.0f, 10.0f);
internal sealed class ClearVisionMod : MonoBehaviour {
internal static ClearVisionMod? Instance { get; private set; }
private bool IsInsideFactory => Helper.LocalPlayer is PlayerControllerB player && player.isInsideFactory;
private bool IsDead => Helper.LocalPlayer is PlayerControllerB player && player.IsDead();

void DecreaseLightIntensity() => this.LightIntensity = Math.Clamp(this.LightIntensity - 1.0f, 0.0f, 10.0f);
private float LightIntensity_Min => 0f;
private float LightIntensity_Max => 35f;

IEnumerator SetNightVision(object[] args) {
WaitForEndOfFrame waitForEndOfFrame = new();
private float InternalLight { get; set; } = 25.0f;
private float OutsideLight { get; set; } = 0.5f;

while (true) {
if (Helper.StartOfRound is not StartOfRound startOfRound) {
yield return waitForEndOfFrame;
continue;
private float LightIntensity {
get {
float Light = this.IsInsideFactory ? this.InternalLight : this.OutsideLight;
if (this.IsDead) {
Light *= 15f;
}

if (Helper.CurrentCamera is not Camera camera) {
yield return waitForEndOfFrame;
continue;
return Light;
}
set {
if (this.IsInsideFactory) {
this.InternalLight = value;
}

if (Helper.TimeOfDay is not TimeOfDay timeOfDay) {
yield return waitForEndOfFrame;
continue;
else {
this.OutsideLight = value;
}
}
}

if (timeOfDay.sunAnimator is not Animator sunAnimator) {
yield return waitForEndOfFrame;
continue;
}
internal GameObject SunObject { get; set; }
internal Light SunLight { get; set; }
internal HDAdditionalLightData Data { get; set; }
private void Awake() {
if (ClearVisionMod.Instance != null) {
Destroy(this);
return;
}
ClearVisionMod.Instance = this;
this.SpawnSun();
}

if (!timeOfDay.sunIndirect.TryGetComponent(out HDAdditionalLightData lightData)) {
yield return waitForEndOfFrame;
continue;
}
internal void SpawnSun() {
this.SunObject ??= new GameObject("Lc-Hax Sun");
this.SunObject.transform.parent = null;
DontDestroyOnLoad(this.SunObject);
this.SunLight = this.SunObject.GetOrAddComponent<Light>();
this.SunLight.type = LightType.Directional;
this.SunLight.shape = LightShape.Cone;
this.SunLight.color = Color.white;
this.SunLight.transform.position = new Vector3(0F, 1000F, 0F);
this.SunLight.transform.rotation = Quaternion.Euler(90F, 0F, 0F);
this.Data = this.SunLight.GetOrAddComponent<HDAdditionalLightData>();
if (this.Data != null) {
this.Data.lightDimmer = 1;
this.Data.volumetricDimmer = 0;
this.Data.SetLightDimmer(1, 0);
this.Data.EnableShadows(false);
this.Data.distance = float.MaxValue;
}
}

sunAnimator.enabled = false;
timeOfDay.sunIndirect.transform.eulerAngles = new Vector3(90, 0, 0);
timeOfDay.sunIndirect.transform.position = camera.transform.position;
timeOfDay.sunIndirect.color = Color.white;
timeOfDay.sunIndirect.intensity = this.LightIntensity;
timeOfDay.sunIndirect.enabled = true;
timeOfDay.sunDirect.transform.eulerAngles = new Vector3(90, 0, 0);
timeOfDay.sunDirect.enabled = true;
lightData.lightDimmer = float.MaxValue;
lightData.distance = float.MaxValue;
timeOfDay.insideLighting = false;
startOfRound.blackSkyVolume.weight = 0;

yield return waitForEndOfFrame;
private void UpdateNewSun() {
if (this.SunObject == null) return;
if (this.SunLight == null) return;
if (this.Data == null) return;
if (Helper.LocalPlayer is null) return;
if (Helper.TimeOfDay is null) return;
if (Helper.CurrentCamera is null) return;
if (Helper.StartOfRound is not StartOfRound round) {
this.SunLight.enabled = false;
return;
}
if (round.inShipPhase) {
this.SunLight.enabled = false;
return;
}
this.SunLight.enabled = this.enabled;
this.SunLight.intensity = this.LightIntensity;
}

IEnumerator DisableVisor(object[] args) {
WaitForSeconds waitForTenSeconds = new(10.0f);
private void RemoveBlackSkybox() {
if (Helper.StartOfRound is not StartOfRound round) return;

while (true) {
Helper.LocalPlayer?.localVisor.gameObject.SetActive(false);
yield return waitForTenSeconds;
if (round.blackSkyVolume != null) {
round.blackSkyVolume.weight = 0f;
UnityEngine.Object.Destroy(round.blackSkyVolume);
}
}

IEnumerator DisableFog(object[] args) {
WaitForSeconds waitForFiveSeconds = new(5.0f);
private void ToggleFog(bool active) => HaxObjects.Instance?.LocalVolumetricFogs?.ForEach(localVolumetricFog => localVolumetricFog?.gameObject.SetActive(active));

while (true) {
HaxObjects
.Instance?
.LocalVolumetricFogs?
.ForEach(localVolumetricFog =>
localVolumetricFog?.gameObject.SetActive(false)
);

yield return waitForFiveSeconds;
private void ToggleVisor(bool active) {
if (Helper.LocalPlayer?.localVisor.gameObject is not GameObject visor) return;
if (visor.activeSelf != active) {
visor.SetActive(active);
}
}

IEnumerator DisableSteamValves(object[] args) {
WaitForSeconds waitForFiveSeconds = new(5.0f);
private void Update() {
this.UpdateNewSun();
this.RemoveBlackSkybox();
this.ToggleVisor(false);
this.ToggleFog(false);
}

private void IncreaseLightIntensity() {
this.LightIntensity = Math.Clamp(this.LightIntensity + 1.0f, this.LightIntensity_Min, this.LightIntensity_Max);
Console.WriteLine($"LightIntensity: {this.LightIntensity}");
}

while (true) {
HaxObjects
.Instance?
.SteamValves?
.ForEach(valve =>
valve?.valveSteamParticle.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear)
);
private void DecreaseLightIntensity() {
this.LightIntensity = Math.Clamp(this.LightIntensity - 1.0f, this.LightIntensity_Min, this.LightIntensity_Max);
Console.WriteLine($"LightIntensity: {this.LightIntensity}");
}

yield return waitForFiveSeconds;
private void DisableMod() {
if (this.SunLight is not null) {
this.SunLight.enabled = false;
}
this.ToggleFog(true);
this.ToggleVisor(true);
}

void Start() {
_ = this.StartResilientCoroutine(this.DisableFog);
_ = this.StartResilientCoroutine(this.DisableSteamValves);
_ = this.StartResilientCoroutine(this.DisableVisor);
_ = this.StartResilientCoroutine(this.SetNightVision);
private void OnEnable() {
InputListener.OnF4Press += this.DecreaseLightIntensity;
InputListener.OnF5Press += this.IncreaseLightIntensity;
}

private void OnDisable() {
InputListener.OnF4Press -= this.DecreaseLightIntensity;
InputListener.OnF5Press -= this.IncreaseLightIntensity;
this.DisableMod();
}
}