Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
VersionCheck Bugfix & Camera Layer Change Compatability
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArion authored Jun 4, 2021
1 parent f7fc342 commit d778307
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 32 deletions.
127 changes: 99 additions & 28 deletions Core.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using MelonLoader;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
using VRC.Core;
using VRC.UserCamera;
using Object = UnityEngine.Object;

namespace Dawn.PostProcessing
{
Expand Down Expand Up @@ -56,44 +59,75 @@ internal static void RegisterSettings()
}
internal static void InternalSettingsRefresh()
{
var debugList = new List<string>();
try
{
s_PostProcessing = MelonPreferences.GetEntryValue<bool>(ModID, "PostProcessing");
s_QuickMenu = MelonPreferences.GetEntryValue<bool>(ModID, "QMToggle");

if (!s_UICreated) return; //Prevents Errors when other mods call OnPreferencesSaved();
var ProcessLayer = MainCamera != null ? MainCamera.gameObject != null ? MainCamera.gameObject.GetComponent<PostProcessLayer>() : null : null;
if (ProcessLayer != null) ProcessLayer.enabled = s_PostProcessing;

if (ProcessLayer != null) ProcessLayer.enabled = s_PostProcessing; debugList.Add("Camera");
WorldVolumes.WorldQMToggle = MelonPreferences.GetEntryValue<bool>(ModID, "WorldQMToggle");
WorldVolumes.WorldPostProcessing = MelonPreferences.GetEntryValue<bool>(ModID, "WorldPostProcessing");
WorldVolumes.ToggleWorldVolumes();

WorldVolumes.ToggleWorldVolumes(); debugList.Add("Volumes");
if (!CustomPostProcessing.m_ObjectsCreated) return;
#region Volume Weights
CustomPostProcessing.s_DarkMode.m_PostProcessVolume.weight = (MelonPreferences.GetEntryValue<float>(ModID, "Dark-Weight") / 100).Stabalize(0, 90f);
CustomPostProcessing.s_Bloom.m_PostProcessVolume.weight = (MelonPreferences.GetEntryValue<float>(ModID, "Bloom-Weight") / 100).Stabalize(0, 100f);
CustomPostProcessing.s_Saturation.m_PostProcessVolume.weight = (MelonPreferences.GetEntryValue<float>(ModID, "Saturation-Weight") / 100).Stabalize(0, 100f);
CustomPostProcessing.s_Contrast.m_PostProcessVolume.weight = (MelonPreferences.GetEntryValue<float>(ModID, "Contrast-Weight") / 100).Stabalize(0, 90f);
CustomPostProcessing.s_Temperature.m_PostProcessVolume.weight = (MelonPreferences.GetEntryValue<float>(ModID, "Temperature-Weight") / 100).Stabalize(0, 100f);
#endregion
#region Object States
CustomPostProcessing.s_DarkMode.enabled = MelonPreferences.GetEntryValue<bool>(ModID, "Dark-Mode");
CustomPostProcessing.s_Bloom.enabled = MelonPreferences.GetEntryValue<bool>(ModID, "Bloom");
CustomPostProcessing.s_Saturation.enabled = MelonPreferences.GetEntryValue<bool>(ModID, "Saturation");
CustomPostProcessing.s_Contrast.enabled = MelonPreferences.GetEntryValue<bool>(ModID, "Contrast");
CustomPostProcessing.s_Temperature.enabled = MelonPreferences.GetEntryValue<bool>(ModID, "Temperature");
#endregion
#region Profile Values
CustomPostProcessing.m_DarknessValue = MelonPreferences.GetEntryValue<float>(ModID, "DarknessValue").Stabalize(0, 100);
CustomPostProcessing.m_BloomValue = MelonPreferences.GetEntryValue<float>(ModID, "BloomValue").Stabalize(0, 100);
CustomPostProcessing.m_ContrastValue = MelonPreferences.GetEntryValue<float>(ModID, "ContrastValue").Stabalize(-90, 90);
CustomPostProcessing.m_SaturationValue = MelonPreferences.GetEntryValue<float>(ModID, "SaturationValue").Stabalize(-100, 100);
CustomPostProcessing.m_TemperatureValue = MelonPreferences.GetEntryValue<float>(ModID, "TemperatureValue").Stabalize(-100, 100);
#endregion

#if QM
UpdateWeights(); debugList.Add("Weights");
UpdateStates(); debugList.Add("States");
UpdateProfiles(); debugList.Add("Profiles");

#if QM
QuickMenus.QMPrefsRefresh();
#endif
#endif
}
catch (Exception e)
{
MelonLogger.Error(e);
MelonLogger.Error("Please Post your Latest.Log in the VRCMG Discord and @Mention arion#1223 Please.");
MelonLogger.Error("Debug Dump:");

if (debugList.Count == 0)
{
MelonLogger.Error("Pre Camera");
return;
}
foreach (var debugEntry in debugList)
{
MelonLogger.Error( "Entry: " + debugEntry + "Checked.");
if (debugEntry == "Profiles")
{
MelonLogger.Error("QMPrefs!!");
}
}
}
}

private static void UpdateWeights()
{
CustomPostProcessing.s_DarkMode.m_PostProcessVolume.weight = (MelonPreferences.GetEntryValue<float>(ModID, "Dark-Weight") / 100).Stabalize(0, 90f);
CustomPostProcessing.s_Bloom.m_PostProcessVolume.weight = (MelonPreferences.GetEntryValue<float>(ModID, "Bloom-Weight") / 100).Stabalize(0, 100f);
CustomPostProcessing.s_Saturation.m_PostProcessVolume.weight = (MelonPreferences.GetEntryValue<float>(ModID, "Saturation-Weight") / 100).Stabalize(0, 100f);
CustomPostProcessing.s_Contrast.m_PostProcessVolume.weight = (MelonPreferences.GetEntryValue<float>(ModID, "Contrast-Weight") / 100).Stabalize(0, 90f);
CustomPostProcessing.s_Temperature.m_PostProcessVolume.weight = (MelonPreferences.GetEntryValue<float>(ModID, "Temperature-Weight") / 100).Stabalize(0, 100f);
}

private static void UpdateStates()
{
CustomPostProcessing.s_DarkMode.enabled = MelonPreferences.GetEntryValue<bool>(ModID, "Dark-Mode");
CustomPostProcessing.s_Bloom.enabled = MelonPreferences.GetEntryValue<bool>(ModID, "Bloom");
CustomPostProcessing.s_Saturation.enabled = MelonPreferences.GetEntryValue<bool>(ModID, "Saturation");
CustomPostProcessing.s_Contrast.enabled = MelonPreferences.GetEntryValue<bool>(ModID, "Contrast");
CustomPostProcessing.s_Temperature.enabled = MelonPreferences.GetEntryValue<bool>(ModID, "Temperature");
}

private static void UpdateProfiles()
{
CustomPostProcessing.m_DarknessValue = MelonPreferences.GetEntryValue<float>(ModID, "DarknessValue").Stabalize(0, 100);
CustomPostProcessing.m_BloomValue = MelonPreferences.GetEntryValue<float>(ModID, "BloomValue").Stabalize(0, 100);
CustomPostProcessing.m_ContrastValue = MelonPreferences.GetEntryValue<float>(ModID, "ContrastValue").Stabalize(-90, 90);
CustomPostProcessing.m_SaturationValue = MelonPreferences.GetEntryValue<float>(ModID, "SaturationValue").Stabalize(-100, 100);
CustomPostProcessing.m_TemperatureValue = MelonPreferences.GetEntryValue<float>(ModID, "TemperatureValue").Stabalize(-100, 100);
}

private static float Stabalize(this float InputValue, float MinValue, float MaxValue) // An attempt to prevent "Why my screen brack!?" Posts in #bug-report
{
Expand All @@ -103,6 +137,31 @@ private static float Stabalize(this float InputValue, float MinValue, float MaxV
}
return InputValue <= MinValue ? MinValue : InputValue;
}

private static UserCameraController cachedController;
private static UserCameraController controller => cachedController ??= Object.FindObjectOfType<UserCameraController>();

private static Transform tryGetUserCamera
{
get
{
try
{
if (controller != null) return controller.transform;
}
catch (TypeLoadException) // In-Case the class gets Obfuscated.
{
MelonLogger.Warning("<UserCameraController> Could not be Found, utilizing fallback.");
return GameObject.Find("_Application/TrackingVolume/PlayerObjects/UserCamera").transform;
}
MelonLogger.Error("Unable to Find UserCameraController GameObject.");
return null;
}
}
private static Transform cachedPhotoCamera;
private static Transform PhotoCamera => cachedPhotoCamera ??= tryGetUserCamera.Find("PhotoCamera");
private static Transform cachedVideoCamera;
private static Transform VideoCamera => cachedVideoCamera ??= PhotoCamera.Find("VideoCamera");
internal static IEnumerator LayerChange()
{
// 25 Second Timeout
Expand All @@ -111,6 +170,18 @@ internal static IEnumerator LayerChange()
var ProcessLayer = MainCamera.gameObject != null ? MainCamera.gameObject.GetComponent<PostProcessLayer>() : null;
if (ProcessLayer == null) { yield return new WaitForSeconds(1); continue; }
ProcessLayer.enabled = s_PostProcessing;
if (CustomPostProcessing.hasNativePostProcessing)
{
if (controller == null) continue; if (PhotoCamera == null) continue; if (VideoCamera == null) continue;

var photoCameraPostProcessLayer = PhotoCamera.gameObject != null ? PhotoCamera.gameObject.GetComponent<PostProcessLayer>() : null;
var videoCameraPostProcessLayer = VideoCamera.gameObject != null ? VideoCamera.gameObject.GetComponent<PostProcessLayer>() : null;
if (photoCameraPostProcessLayer != null)
{
photoCameraPostProcessLayer.enabled = s_PostProcessing;
if (videoCameraPostProcessLayer != null) videoCameraPostProcessLayer.enabled = s_PostProcessing;
}
}
break;
}
}
Expand Down
3 changes: 3 additions & 0 deletions CustomPostProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ private static void CreateCustomObjects() // Priority Limit: 1223 -> 1250 (For V
}

// private static LayerMask CachedWorldJoinMask;
internal static bool hasNativePostProcessing;
internal static IEnumerator WorldJoin()
{
hasNativePostProcessing = true;
//10 Second Timeout
for (int i = 0; i < 10; i++)
{
Expand All @@ -110,6 +112,7 @@ internal static IEnumerator WorldJoin()
// return;
// }
Log("World is detected to contain no PostProcessLayer. Adding one manually.");
hasNativePostProcessing = false;
SetupPostProcessing().Coroutine();
break;
}
Expand Down
3 changes: 3 additions & 0 deletions QuickMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal static class QuickMenus
private const float QMY = 1.8f;

private static QMToggleButton TPPQM;
private static bool QMInit;

internal static void InitQM()
{
Expand Down Expand Up @@ -58,10 +59,12 @@ internal static void InitQM()
TPPQM.setToggleState(Core.s_PostProcessing);
TPPQM.setActive(Core.s_QuickMenu);
TPPQM.getGameObject().name = "Post-Processing";
QMInit = true;
}

internal static void QMPrefsRefresh()
{
if (!QMInit) return;
if (!Core.s_UICreated) return;
TPPQM.setActive(Core.s_QuickMenu);
if (WorldVolumes.WorldQMToggle)
Expand Down
7 changes: 3 additions & 4 deletions Start.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal sealed class BuildInfo

internal const string Name = "PostProcessing+";

internal const string Version = "2.0.6";
internal const string Version = "2.0.7";
}
internal sealed class Start : MelonMod
{
Expand Down Expand Up @@ -46,10 +46,9 @@ private void UIManager()
}


private bool VersionCheck(string modVersion, string greaterOrEqual)
private static bool VersionCheck(string modVersion, string greaterOrEqual)
{
if (modVersion == greaterOrEqual) return true;
if (Version.TryParse(modVersion, out var owo) && Version.TryParse(greaterOrEqual, out var uwu)) return owo.CompareTo(uwu) < 0;
if (Version.TryParse(modVersion, out var owo) && Version.TryParse(greaterOrEqual, out var uwu)) return uwu.CompareTo(owo) <= 0;
return false;
}
public override void OnSceneWasInitialized(int buildIndex, string sceneName)
Expand Down

0 comments on commit d778307

Please sign in to comment.