From 66773b300fac50ca26d22851ce82d11198b4a95d Mon Sep 17 00:00:00 2001 From: originalnicodr Date: Sun, 5 May 2024 23:36:21 -0300 Subject: [PATCH] Improved post-processing logging messages and improved compatibility with Hellpoint and potentially more games. --- src/UI/Panels/MiscPanel.cs | 45 +++++++++------------------- src/UI/Panels/PostProcessingPanel.cs | 15 ++++++++-- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/UI/Panels/MiscPanel.cs b/src/UI/Panels/MiscPanel.cs index 2543a7e..3e346f3 100644 --- a/src/UI/Panels/MiscPanel.cs +++ b/src/UI/Panels/MiscPanel.cs @@ -41,13 +41,13 @@ namespace UnityExplorer.UI.Panels List disabledCanvases; Toggle HUDToggle; - CacheMethod captureScreenshotFunction = null; + MethodInfo captureScreenshotFunction = null; int superSizeValue = 2; public ScreenshotState screenshotStatus; Toggle HighLodToggle; object qualitySettings = null; - CacheProperty lodBias = null; + PropertyInfo lodBias = null; // We save the current properties of the Renderers and Lights to restore them after editing them with togglers internal Dictionary renderersReceiveShadows = new(); @@ -92,56 +92,39 @@ namespace UnityExplorer.UI.Panels } private void TakeScreenshot(){ - MethodInfo methodInfo = captureScreenshotFunction.MethodInfo; string filename = DateTime.Now.ToString("yyyy-M-d HH-mm-ss"); string screenshotsPath = Path.Combine(ExplorerCore.ExplorerFolder, "Screenshots"); System.IO.Directory.CreateDirectory(screenshotsPath); object[] args = {$"{screenshotsPath}\\{filename}.png", superSizeValue}; - - methodInfo.Invoke(captureScreenshotFunction.DeclaringInstance, args); + try { + captureScreenshotFunction.Invoke(qualitySettings, args); + } + catch { ExplorerCore.LogWarning("Failed to take a screenshot. Chances are the method has been stripped."); } } - + private void FindCaptureScreenshotFunction(){ try { object screenCaptureClass = ReflectionUtility.GetTypeByName("UnityEngine.ScreenCapture"); Type screenCaptureType = screenCaptureClass is Type type ? type : screenCaptureClass.GetActualType(); - ReflectionInspector inspector = Pool.Borrow(); - List members = CacheMemberFactory.GetCacheMembers(screenCaptureType, inspector); - foreach (CacheMember member in members){ - if (member is CacheMethod methodMember){ - if (methodMember.NameForFiltering == "ScreenCapture.CaptureScreenshot(string, int)"){ - captureScreenshotFunction = methodMember; - break; - } - } - } + captureScreenshotFunction = screenCaptureType.GetMethod("CaptureScreenshot", new Type[] {typeof(string), typeof(int)}); } - catch { ExplorerCore.Log("Couldn't find the ScreenCapture class.");} + catch { ExplorerCore.Log("Couldn't find the ScreenCapture class."); } } private void FindQualitySettings(){ qualitySettings = ReflectionUtility.GetTypeByName("UnityEngine.QualitySettings"); } - private void FindLodBias(){ - Type qualitySettingsType = qualitySettings is Type type ? type : qualitySettings.GetActualType(); - ReflectionInspector inspector = Pool.Borrow(); - List members = CacheMemberFactory.GetCacheMembers(qualitySettingsType, inspector); - foreach (CacheMember member in members){ - if (member is CacheProperty propertyMember && propertyMember.NameForFiltering == "QualitySettings.lodBias"){ - lodBias = propertyMember; - break; - } - } - } - private void ToogleHighLods(bool areHighLodsOn){ if (qualitySettings == null) FindQualitySettings(); - if (lodBias == null) FindLodBias(); + if (lodBias == null){ + Type qualitySettingsType = qualitySettings is Type type ? type : qualitySettings.GetActualType(); + lodBias = qualitySettingsType.GetProperty("lodBias"); + } - lodBias.TrySetUserValue(areHighLodsOn ? 10000 : 1); + lodBias.SetValue(null, areHighLodsOn ? 10000 : 1, null); } private void ToggleAllMeshesCastAndRecieveShadows(bool enable){ diff --git a/src/UI/Panels/PostProcessingPanel.cs b/src/UI/Panels/PostProcessingPanel.cs index 8ae4d9a..c1ca4b6 100644 --- a/src/UI/Panels/PostProcessingPanel.cs +++ b/src/UI/Panels/PostProcessingPanel.cs @@ -31,6 +31,7 @@ namespace UnityExplorer.UI.Panels public static Dictionary> postProcessingEffects = null; static ButtonRef updateEffects; List UIElements = new List(); + public bool foundAnyEffect; public class PPEffect { @@ -46,8 +47,6 @@ namespace UnityExplorer.UI.Panels List members = CacheMemberFactory.GetCacheMembers(objType, inspector); foreach (CacheMember member in members){ - //ExplorerCore.LogWarning(entry.NameForFiltering); - if (member.NameForFiltering.EndsWith(".active")){ member.Evaluate(); Active = member; @@ -68,6 +67,8 @@ namespace UnityExplorer.UI.Panels } public void UpdatePPElements(){ + foundAnyEffect = false; + if(postProcessingEffects != null){ // We turn the effects we had back on so they get captured again on refresh foreach (List effects in postProcessingEffects.Values){ @@ -168,6 +169,10 @@ namespace UnityExplorer.UI.Panels catch {} } + if (!foundAnyEffect){ + ExplorerCore.Log("Couldn't find any standard post-processing effect classes."); + } + BuildEffectTogglers(); } @@ -189,8 +194,12 @@ namespace UnityExplorer.UI.Panels postProcessingEffects[effect].Add(entry); } } + + foundAnyEffect = true; + } + catch { + // ExplorerCore.Log($"Couldn't find {baseClass}.{effect}"); } - catch { ExplorerCore.Log($"Couldn't find {baseClass}.{effect}");} } private void SetEffect(bool value, List effects){