Fix persisting mask and NullReferenceException

This commit is contained in:
LimboFPS 2023-09-17 20:21:26 -04:00
parent b270b68eb1
commit 718527d28f

View File

@ -2,22 +2,26 @@ using UnityEngine;
using BSG.CameraEffects;
using Aki.Reflection.Patching;
using System.Reflection;
using Comfort.Common;
using EFT;
namespace ClearVision {
public class GogglesPatches : ModulePatch {
protected override MethodBase GetTargetMethod() {
Debug.Log("GogglesPatches GTM()");
var result = typeof(NightVision).GetMethod("method_1", BindingFlags.Instance | BindingFlags.NonPublic);
return result;
}
[PatchPostfix]
static void Postfix() {
if(Plugin.GlobalEnabled.Value) { // sanity check
if(Plugin.GlobalEnabled.Value && Singleton<GameWorld>.Instantiated) { // sanity check
// Get Camera
GameObject maincam = GameObject.Find("FPS Camera");
NightVision nv = maincam.GetComponent<NightVision>();
CC_Vintage vintage = maincam.GetComponent<CC_Vintage>();
if(nv != null && (nv.On || nv.InProcessSwitching)) {
if(nv != null && nv.On) {
Debug.Log("nv is not null and is enabled/being enabled");
nv.Intensity = Plugin.NVGIntensity.Value;
nv.NoiseIntensity = Plugin.NVGNoiseIntensity.Value;
nv.NoiseScale = Plugin.NVGNoiseScale.Value;
@ -31,10 +35,12 @@ namespace ClearVision {
nv.Color = Plugin.NVGColor.Value;
vintage.enabled = false;
nv.ApplySettings();
return;
}
else {
vintage.enabled = true;
nv.ApplySettings();
return;
}
}
@ -44,29 +50,28 @@ namespace ClearVision {
public class ScopePatches : ModulePatch {
protected override MethodBase GetTargetMethod() {
Debug.LogError("ScopePatches GTM()");
Debug.Log("ScopePatches GTM()");
var result = typeof(ThermalVision).GetMethod("method_1", BindingFlags.Instance | BindingFlags.NonPublic);
return result;
}
[PatchPostfix]
static void Postfix() {
Debug.LogError("ScopePatches Postfix()");
if(Plugin.GlobalEnabled.Value) { // sanity check
if(Plugin.GlobalEnabled.Value && Singleton<GameWorld>.Instantiated) { // sanity check
// Get Camera
GameObject maincam = GameObject.Find("FPS Camera");
ThermalVision t7 = maincam.GetComponent<ThermalVision>();
CC_Vintage vintage = maincam.GetComponent<CC_Vintage>();
// Get BaseOpticScope(Clone) obj, but need to check if it actually exists
GameObject scope = GameObject.FindGameObjectWithTag("OpticCamera");
ThermalVision thermal = scope.GetComponent<ThermalVision>();
if(t7 != null && (t7.On || t7.InProcessSwitching)) {
if(t7 != null && t7.On) {
Debug.Log("t7 is not null and is on!");
t7.IsGlitch = Plugin.T7Glitch.Value;
t7.IsPixelated = Plugin.T7Pixel.Value;
t7.IsNoisy = Plugin.T7Glitch.Value;
t7.IsFpsStuck = Plugin.T7Glitch.Value;
if (Plugin.T7Fps.Value) {
t7.IsNoisy = Plugin.T7Noise.Value;
t7.IsMotionBlurred = Plugin.T7MotionBlur.Value;
t7.IsFpsStuck = Plugin.T7FpsLock.Value;
if (Plugin.T7FpsLock.Value) {
t7.StuckFpsUtilities.MaxFramerate = Plugin.T7FpsMax.Value;
t7.StuckFpsUtilities.MinFramerate = Plugin.T7FpsMax.Value;
}
@ -77,29 +82,25 @@ namespace ClearVision {
else{
t7.TextureMask.enabled = false;
}
vintage.enabled = false;
// Far/near clip plane distance is done on the optic_camera for each "mode" acording to UABEA,
// just need to see where it is in the data structure
return;
}
else if (scope != null && thermal != null && (thermal.On || t7.InProcessSwitching)) {
//scope.
else if (scope != null && thermal != null && thermal.On && !t7.On) {
Debug.Log("scope and thermal script are not null and is on!");
thermal.IsGlitch = Plugin.ThermalGlitch.Value;
thermal.IsPixelated = Plugin.ThermalPixel.Value;
thermal.IsNoisy = Plugin.ThermalGlitch.Value;
thermal.IsFpsStuck = Plugin.ThermalGlitch.Value;
if (Plugin.ThermalGlitch.Value) {
thermal.IsNoisy = Plugin.ThermalNoise.Value;
thermal.IsMotionBlurred = Plugin.ThermalMotionBlur.Value;
thermal.IsFpsStuck = Plugin.ThermalFpsLock.Value;
if (Plugin.ThermalFpsLock.Value) {
thermal.StuckFpsUtilities.MaxFramerate = Plugin.ThermalFpsMax.Value;
thermal.StuckFpsUtilities.MinFramerate = Plugin.ThermalFpsMax.Value;
}
vintage.enabled = false;
return;
}
else {
vintage.enabled = true;
else
return;
}
}
else
return;