using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Beautify.Universal;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.UI;
using YAPYAP;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GraphicsEnhancerMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GraphicsEnhancerMod")]
[assembly: AssemblyTitle("GraphicsEnhancerMod")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
[BepInPlugin("com.yapyap.mod.graphicsenhancer", "YapYap Graphics Enhancer", "1.0.1")]
public sealed class GraphicsEnhancerMod : BaseUnityPlugin
{
internal static class State
{
internal static bool MasterBackupDone;
internal static bool ShadowBackupDone;
internal static bool SsaoBackupDone;
internal static bool DecalBackupDone;
internal static bool FogBackupDone;
internal static bool BeautifyBackupDone;
internal static bool VhsBackupDone;
internal static bool LowResBackupDone;
internal static bool UrpBackupDone;
internal static bool BloomBackupDone;
internal static bool MotionBlurBackupDone;
internal static bool OriginalMainLightCastShadows;
internal static bool OriginalAdditionalLightCastShadows;
internal static bool OriginalSsaoEnabled;
internal static bool OriginalSsaoDownsample;
internal static int OriginalSsaoBlurQuality;
internal static int OriginalSsaoSamples;
internal static bool OriginalDecalsEnabled;
internal static bool OriginalFogEnabled;
internal static float OriginalBeautifySharpenClamp;
internal static float OriginalBeautifySharpenRelaxation;
internal static float OriginalBeautifySharpenMotionSensibility;
internal static float OriginalBeautifySharpenIntensity;
internal static float OriginalBloomIntensity;
internal static float OriginalBrightness;
internal static bool OriginalMotionBlurEnabled;
internal static bool OriginalVhsEnabled;
internal static bool VhsOverrideHasValue;
internal static bool VhsOverrideEnabled;
internal static bool OriginalLowResUseVertexSnap;
internal static float OriginalUrpRenderScale;
}
[CompilerGenerated]
private sealed class <DelayedApplySettings>d__18 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <DelayedApplySettings>d__18(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(3f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
ApplyAllSettings(force: true);
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static GraphicsEnhancerMod _instance;
private Harmony _harmony;
private static List<Volume> _cachedVolumes = new List<Volume>();
private static float _lastCacheTime = 0f;
private const float CacheInterval = 5f;
private const string LogPrefix = "[柠檬][GraphicsEnhancer] ";
public static ConfigEntry<bool> ConfigMasterEnabled;
public static ConfigEntry<int> ConfigClarityQuality;
public static ConfigEntry<int> ConfigVhsBlurQuality;
public static ConfigEntry<int> ConfigShadowQuality;
public static ConfigEntry<int> ConfigAdditionalShadowQuality;
public static ConfigEntry<int> ConfigSsaoQuality;
public static ConfigEntry<int> ConfigDecalQuality;
public static ConfigEntry<int> ConfigFogQuality;
public static ConfigEntry<int> ConfigBloomIntensity;
public static ConfigEntry<int> ConfigMotionBlurQuality;
public static ConfigEntry<float> ConfigBrightness;
private static bool? _lastVhsEnabled;
private static List<VHSProVolumeComponent> _cachedVhsComponents = new List<VHSProVolumeComponent>();
private static float _lastVhsCacheTime = 0f;
private void Awake()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
_instance = this;
_harmony = new Harmony("com.yapyap.mod.graphicsenhancer");
ConfigMasterEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "MasterEnabled", false, "是否启用画质增强预设 / Enable Graphics Preset");
ConfigClarityQuality = ((BaseUnityPlugin)this).Config.Bind<int>("Graphics", "ClarityQuality", 1, "画面清晰度 (0:低, 1:中, 2:高) / Image Clarity");
ConfigVhsBlurQuality = ((BaseUnityPlugin)this).Config.Bind<int>("Graphics", "VhsBlurQuality", 0, "VHS 模糊效果 / VHS Blur Effect");
ConfigShadowQuality = ((BaseUnityPlugin)this).Config.Bind<int>("Graphics", "ShadowQuality", 1, "阴影质量 / Shadow Quality");
ConfigAdditionalShadowQuality = ((BaseUnityPlugin)this).Config.Bind<int>("Graphics", "AdditionalShadowQuality", 1, "附加光源阴影 (影响房子性能) / Additional Light Shadows");
ConfigSsaoQuality = ((BaseUnityPlugin)this).Config.Bind<int>("Graphics", "SsaoQuality", 1, "环境光遮蔽质量 / SSAO Quality");
ConfigDecalQuality = ((BaseUnityPlugin)this).Config.Bind<int>("Graphics", "DecalQuality", 1, "贴花特效质量 / Decal Quality");
ConfigFogQuality = ((BaseUnityPlugin)this).Config.Bind<int>("Graphics", "FogQuality", 1, "雾效质量 / Fog Quality");
ConfigBloomIntensity = ((BaseUnityPlugin)this).Config.Bind<int>("Graphics", "BloomIntensity", 1, "辉光强度 / Bloom Intensity");
ConfigMotionBlurQuality = ((BaseUnityPlugin)this).Config.Bind<int>("Graphics", "MotionBlurQuality", 0, "运动模糊 (0:关闭, 1:开启) / Motion Blur");
ConfigBrightness = ((BaseUnityPlugin)this).Config.Bind<float>("Graphics", "Brightness", 1f, "画面亮度 / Brightness (0.5 - 2.0)");
((BaseUnityPlugin)this).Logger.LogInfo((object)("[柠檬][GraphicsEnhancer] " + GetLocalizedText("画质优化 MOD 加载中...", "Graphics Enhancer MOD loading...")));
_harmony.PatchAll(typeof(GraphicsEnhancerMod).Assembly);
((MonoBehaviour)this).StartCoroutine(DelayedApplySettings());
((BaseUnityPlugin)this).Logger.LogInfo((object)("[柠檬][GraphicsEnhancer] " + GetLocalizedText("画质优化 MOD 已加载。", "Graphics Enhancer MOD loaded.")));
}
[IteratorStateMachine(typeof(<DelayedApplySettings>d__18))]
private IEnumerator DelayedApplySettings()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <DelayedApplySettings>d__18(0);
}
private void Update()
{
if (ConfigMasterEnabled.Value && Time.frameCount % 300 == 0)
{
ApplyAllSettings(force: true);
}
}
private static void RefreshVolumeCache(bool force = false)
{
if (force || !(Time.time - _lastCacheTime < 5f))
{
_lastCacheTime = Time.time;
_cachedVolumes.Clear();
Volume[] array = Object.FindObjectsByType<Volume>((FindObjectsInactive)1, (FindObjectsSortMode)0);
if (array != null)
{
_cachedVolumes.AddRange(array);
}
}
}
private void OnDestroy()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("[柠檬][GraphicsEnhancer] " + GetLocalizedText("画质优化 MOD 卸载中...", "Graphics Enhancer MOD unloading...")));
if (_harmony != null)
{
_harmony.UnpatchSelf();
_harmony = null;
}
if ((Object)(object)_instance == (Object)(object)this)
{
_instance = null;
}
}
internal static void Log(string message)
{
if ((Object)(object)_instance != (Object)null)
{
((BaseUnityPlugin)_instance).Logger.LogInfo((object)("[柠檬][GraphicsEnhancer] " + message));
}
}
internal static string GetLocalizedText(string zhCn, string en)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
if (!IsChineseLanguage(Application.systemLanguage))
{
return en;
}
return zhCn;
}
internal static bool IsChineseLanguage(SystemLanguage systemLanguage)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Invalid comparison between Unknown and I4
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Invalid comparison between Unknown and I4
if ((int)systemLanguage == 6 || systemLanguage - 40 <= 1)
{
return true;
}
return false;
}
internal static void OnModToggleChanged(bool enabled)
{
ConfigMasterEnabled.Value = enabled;
try
{
if (enabled)
{
ConfigClarityQuality.Value = 2;
ConfigShadowQuality.Value = 2;
ConfigAdditionalShadowQuality.Value = 1;
ConfigSsaoQuality.Value = 2;
ConfigFogQuality.Value = 2;
ConfigMotionBlurQuality.Value = 0;
if (ConfigBrightness.Value < 1.3f)
{
ConfigBrightness.Value = 1.3f;
}
ApplyAllSettings(force: true);
Log(GetLocalizedText("已开启极致画质预设组合", "Ultra graphics preset enabled"));
}
else
{
ConfigClarityQuality.Value = 0;
ConfigShadowQuality.Value = 0;
ConfigSsaoQuality.Value = 0;
ConfigFogQuality.Value = 0;
ConfigBrightness.Value = 1f;
RestoreAllToVanilla();
ApplyAllSettings(force: true);
Log(GetLocalizedText("已关闭画质增强组合,恢复原版设置", "Graphics enhancement disabled, restored vanilla settings"));
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换画质预设失败: ", "Failed to toggle graphics preset: ") + ex.Message);
}
}
private static void RestoreAllToVanilla()
{
RefreshVolumeCache(force: true);
ColorAdjustments val2 = default(ColorAdjustments);
LiftGammaGain val3 = default(LiftGammaGain);
ShadowsMidtonesHighlights val4 = default(ShadowsMidtonesHighlights);
Vignette val5 = default(Vignette);
FilmGrain val6 = default(FilmGrain);
MotionBlur val7 = default(MotionBlur);
DepthOfField val8 = default(DepthOfField);
Bloom val9 = default(Bloom);
Tonemapping val10 = default(Tonemapping);
foreach (Volume cachedVolume in _cachedVolumes)
{
if ((Object)(object)cachedVolume == (Object)null)
{
continue;
}
VolumeProfile val = (((Object)(object)cachedVolume.profile != (Object)null) ? cachedVolume.profile : cachedVolume.sharedProfile);
if ((Object)(object)val == (Object)null)
{
continue;
}
if (val.TryGet<ColorAdjustments>(ref val2))
{
((VolumeComponent)val2).active = false;
}
if (val.TryGet<LiftGammaGain>(ref val3))
{
((VolumeComponent)val3).active = false;
}
if (val.TryGet<ShadowsMidtonesHighlights>(ref val4))
{
((VolumeComponent)val4).active = false;
}
if (val.TryGet<Vignette>(ref val5))
{
((VolumeComponent)val5).active = false;
}
if (val.TryGet<FilmGrain>(ref val6))
{
((VolumeComponent)val6).active = false;
}
if (val.TryGet<MotionBlur>(ref val7))
{
((VolumeComponent)val7).active = false;
}
if (val.TryGet<DepthOfField>(ref val8))
{
((VolumeComponent)val8).active = false;
}
if (val.TryGet<Bloom>(ref val9))
{
((VolumeComponent)val9).active = true;
if (State.BeautifyBackupDone)
{
((VolumeParameter<float>)(object)val9.intensity).value = State.OriginalBloomIntensity;
}
}
if (val.TryGet<Tonemapping>(ref val10))
{
((VolumeComponent)val10).active = true;
}
}
if ((Object)(object)BeautifySettings.settings != (Object)null && State.BeautifyBackupDone)
{
Beautify settings = BeautifySettings.settings;
((VolumeParameter<float>)(object)settings.sharpenIntensity).value = State.OriginalBeautifySharpenIntensity;
((VolumeParameter<float>)(object)settings.sharpenClamp).value = State.OriginalBeautifySharpenClamp;
((VolumeParameter<float>)(object)settings.sharpenRelaxation).value = State.OriginalBeautifySharpenRelaxation;
((VolumeParameter<float>)(object)settings.sharpenMotionSensibility).value = State.OriginalBeautifySharpenMotionSensibility;
((VolumeParameter<float>)(object)settings.bloomIntensity).value = State.OriginalBloomIntensity;
((VolumeParameter<float>)(object)settings.blurIntensity).value = 0f;
((VolumeParameter<float>)(object)settings.lensDirtIntensity).value = 0.2f;
((VolumeParameter<float>)(object)settings.anamorphicFlaresIntensity).value = 0f;
}
RestoreGraphicsState();
Log("All settings restored to vanilla.");
}
internal static void ApplyAllSettings(bool force = false)
{
if (!ConfigMasterEnabled.Value && !force)
{
return;
}
try
{
BackupGraphicsState();
ApplyClarityQuality(null, ConfigClarityQuality.Value);
OnShadowQualityChanged(ConfigShadowQuality.Value);
OnAdditionalShadowQualityChanged(ConfigAdditionalShadowQuality.Value);
OnSsaoQualityChanged(ConfigSsaoQuality.Value);
OnDecalQualityChanged(ConfigDecalQuality.Value);
OnFogQualityChanged(ConfigFogQuality.Value);
OnVhsToggleChanged(null, ConfigVhsBlurQuality.Value > 0, force);
OnMotionBlurQualityChanged(ConfigMotionBlurQuality.Value);
OnBrightnessChanged(ConfigBrightness.Value, force);
UpdateGlobalPostProcessing();
}
catch (Exception ex)
{
Log("Error in ApplyAllSettings: " + ex.Message);
}
}
private static void UpdateGlobalPostProcessing()
{
float value = ConfigBrightness.Value;
RefreshVolumeCache();
ColorAdjustments val2 = default(ColorAdjustments);
foreach (Volume cachedVolume in _cachedVolumes)
{
if (!((Object)(object)cachedVolume == (Object)null))
{
VolumeProfile val = (((Object)(object)cachedVolume.profile != (Object)null) ? cachedVolume.profile : cachedVolume.sharedProfile);
if (!((Object)(object)val == (Object)null) && val.TryGet<ColorAdjustments>(ref val2))
{
((VolumeComponent)val2).active = true;
((VolumeParameter<float>)(object)val2.contrast).value = 50f + (value - 1f) * 160f;
((VolumeParameter<float>)(object)val2.saturation).value = 10f;
}
}
}
if (ConfigSsaoQuality.Value > 0)
{
GraphicsUtility.SSAOEnabled = true;
GraphicsUtility.SSAOIntensity = 0.5f;
}
}
private static void BackupGraphicsState()
{
try
{
if (!State.MasterBackupDone)
{
State.OriginalMainLightCastShadows = GraphicsUtility.MainLightCastShadows;
State.OriginalAdditionalLightCastShadows = GraphicsUtility.AdditionalLightCastShadows;
State.OriginalSsaoEnabled = GraphicsUtility.SSAOEnabled;
State.OriginalSsaoDownsample = GraphicsUtility.SSAODownsample;
State.OriginalSsaoBlurQuality = GraphicsUtility.SSAOBlurQuality;
State.OriginalSsaoSamples = GraphicsUtility.SSAOSamples;
State.OriginalDecalsEnabled = GraphicsUtility.DecalsEnabled;
State.OriginalFogEnabled = GraphicsUtility.ButoEnabled;
if ((Object)(object)BeautifySettings.settings != (Object)null)
{
Beautify settings = BeautifySettings.settings;
State.OriginalBeautifySharpenIntensity = ((VolumeParameter<float>)(object)settings.sharpenIntensity).value;
State.OriginalBeautifySharpenClamp = ((VolumeParameter<float>)(object)settings.sharpenClamp).value;
State.OriginalBeautifySharpenRelaxation = ((VolumeParameter<float>)(object)settings.sharpenRelaxation).value;
State.OriginalBeautifySharpenMotionSensibility = ((VolumeParameter<float>)(object)settings.sharpenMotionSensibility).value;
State.OriginalBloomIntensity = ((VolumeParameter<float>)(object)settings.bloomIntensity).value;
State.BeautifyBackupDone = true;
}
State.MasterBackupDone = true;
Log("Original graphics state backed up.");
}
}
catch (Exception ex)
{
Log(GetLocalizedText("备份原始画质设置失败: ", "Failed to backup original graphics settings: ") + ex.Message);
}
}
private static void RestoreGraphicsState()
{
try
{
if (State.MasterBackupDone)
{
GraphicsUtility.MainLightCastShadows = State.OriginalMainLightCastShadows;
GraphicsUtility.AdditionalLightCastShadows = State.OriginalAdditionalLightCastShadows;
GraphicsUtility.SSAOEnabled = State.OriginalSsaoEnabled;
GraphicsUtility.SSAODownsample = State.OriginalSsaoDownsample;
GraphicsUtility.SSAOBlurQuality = State.OriginalSsaoBlurQuality;
GraphicsUtility.SSAOSamples = State.OriginalSsaoSamples;
GraphicsUtility.DecalsEnabled = State.OriginalDecalsEnabled;
GraphicsUtility.ButoEnabled = State.OriginalFogEnabled;
State.MasterBackupDone = false;
State.BeautifyBackupDone = false;
}
}
catch (Exception ex)
{
Log(GetLocalizedText("恢复原始画质设置失败: ", "Failed to restore original graphics settings: ") + ex.Message);
}
}
internal static void OnShadowToggleChanged(bool enabled)
{
try
{
if (enabled)
{
if (!State.ShadowBackupDone)
{
State.OriginalMainLightCastShadows = GraphicsUtility.MainLightCastShadows;
State.OriginalAdditionalLightCastShadows = GraphicsUtility.AdditionalLightCastShadows;
State.ShadowBackupDone = true;
}
GraphicsUtility.MainLightCastShadows = true;
GraphicsUtility.AdditionalLightCastShadows = true;
}
else if (State.ShadowBackupDone)
{
GraphicsUtility.MainLightCastShadows = State.OriginalMainLightCastShadows;
GraphicsUtility.AdditionalLightCastShadows = State.OriginalAdditionalLightCastShadows;
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换阴影增强失败: ", "Failed to toggle shadow enhancement: ") + ex.Message);
}
}
internal static void OnSsaoToggleChanged(bool enabled)
{
try
{
if (enabled)
{
if (!State.SsaoBackupDone)
{
State.OriginalSsaoEnabled = GraphicsUtility.SSAOEnabled;
State.OriginalSsaoDownsample = GraphicsUtility.SSAODownsample;
State.OriginalSsaoBlurQuality = GraphicsUtility.SSAOBlurQuality;
State.OriginalSsaoSamples = GraphicsUtility.SSAOSamples;
State.SsaoBackupDone = true;
}
GraphicsUtility.SSAOEnabled = true;
GraphicsUtility.SSAODownsample = false;
GraphicsUtility.SSAOBlurQuality = 0;
GraphicsUtility.SSAOSamples = 0;
}
else if (State.SsaoBackupDone)
{
GraphicsUtility.SSAOEnabled = State.OriginalSsaoEnabled;
GraphicsUtility.SSAODownsample = State.OriginalSsaoDownsample;
GraphicsUtility.SSAOBlurQuality = State.OriginalSsaoBlurQuality;
GraphicsUtility.SSAOSamples = State.OriginalSsaoSamples;
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换环境光遮蔽增强失败: ", "Failed to toggle SSAO enhancement: ") + ex.Message);
}
}
internal static void OnDecalToggleChanged(bool enabled)
{
try
{
if (enabled)
{
if (!State.DecalBackupDone)
{
State.OriginalDecalsEnabled = GraphicsUtility.DecalsEnabled;
State.DecalBackupDone = true;
}
GraphicsUtility.DecalsEnabled = true;
}
else if (State.DecalBackupDone)
{
GraphicsUtility.DecalsEnabled = State.OriginalDecalsEnabled;
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换贴花特效增强失败: ", "Failed to toggle decal enhancement: ") + ex.Message);
}
}
internal static void OnFogToggleChanged(bool enabled)
{
try
{
if (enabled)
{
if (!State.FogBackupDone)
{
State.OriginalFogEnabled = GraphicsUtility.ButoEnabled;
State.FogBackupDone = true;
}
GraphicsUtility.ButoEnabled = true;
}
else if (State.FogBackupDone)
{
GraphicsUtility.ButoEnabled = State.OriginalFogEnabled;
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换雾效增强失败: ", "Failed to toggle fog enhancement: ") + ex.Message);
}
}
internal static void OnShadowQualityChanged(int selectedModeId)
{
ConfigShadowQuality.Value = selectedModeId;
try
{
RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
UniversalRenderPipelineAsset val = (UniversalRenderPipelineAsset)(object)((currentRenderPipeline is UniversalRenderPipelineAsset) ? currentRenderPipeline : null);
switch (selectedModeId)
{
case 0:
QualitySettings.shadows = (ShadowQuality)2;
GraphicsUtility.MainLightCastShadows = true;
GraphicsUtility.MainLightShadowResolution = (ShadowResolution)1024;
if ((Object)(object)val != (Object)null)
{
val.shadowCascadeCount = 1;
val.shadowDistance = 50f;
}
break;
case 1:
QualitySettings.shadows = (ShadowQuality)2;
GraphicsUtility.MainLightCastShadows = true;
GraphicsUtility.MainLightShadowResolution = (ShadowResolution)2048;
if ((Object)(object)val != (Object)null)
{
val.shadowCascadeCount = 2;
val.shadowDistance = 100f;
}
break;
case 2:
QualitySettings.shadows = (ShadowQuality)2;
GraphicsUtility.MainLightCastShadows = true;
GraphicsUtility.MainLightShadowResolution = (ShadowResolution)4096;
if ((Object)(object)val != (Object)null)
{
val.shadowCascadeCount = 4;
val.shadowDistance = 180f;
}
break;
}
OnAdditionalShadowQualityChanged(ConfigAdditionalShadowQuality.Value);
}
catch (Exception ex)
{
Log(GetLocalizedText("切换阴影质量失败: ", "Failed to switch shadow quality: ") + ex.Message);
}
}
internal static void OnAdditionalShadowQualityChanged(int selectedModeId)
{
ConfigAdditionalShadowQuality.Value = selectedModeId;
try
{
switch (selectedModeId)
{
case 0:
GraphicsUtility.AdditionalLightCastShadows = false;
break;
case 1:
GraphicsUtility.AdditionalLightCastShadows = true;
GraphicsUtility.AdditionalLightShadowResolution = (ShadowResolution)512;
break;
case 2:
GraphicsUtility.AdditionalLightCastShadows = true;
GraphicsUtility.AdditionalLightShadowResolution = (ShadowResolution)1024;
break;
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换附加光源阴影失败: ", "Failed to switch additional shadow quality: ") + ex.Message);
}
}
internal static void OnSsaoQualityChanged(int selectedModeId)
{
ConfigSsaoQuality.Value = selectedModeId;
try
{
switch (selectedModeId)
{
case 0:
GraphicsUtility.SSAOEnabled = false;
break;
case 1:
GraphicsUtility.SSAOEnabled = true;
GraphicsUtility.SSAODownsample = true;
GraphicsUtility.SSAOBlurQuality = 1;
GraphicsUtility.SSAOSamples = 2;
GraphicsUtility.SSAOIntensity = 0.4f;
break;
case 2:
GraphicsUtility.SSAOEnabled = true;
GraphicsUtility.SSAODownsample = false;
GraphicsUtility.SSAODownsample = true;
GraphicsUtility.SSAOBlurQuality = 0;
GraphicsUtility.SSAOSamples = 1;
GraphicsUtility.SSAOIntensity = 0.5f;
break;
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换环境光遮蔽质量失败: ", "Failed to switch SSAO quality: ") + ex.Message);
}
}
internal static void OnDecalQualityChanged(int selectedModeId)
{
ConfigDecalQuality.Value = selectedModeId;
try
{
switch (selectedModeId)
{
case 0:
GraphicsUtility.DecalsEnabled = false;
break;
case 1:
case 2:
GraphicsUtility.DecalsEnabled = true;
break;
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换贴花特效质量失败: ", "Failed to switch decal quality: ") + ex.Message);
}
}
internal static void OnFogQualityChanged(int selectedModeId)
{
ConfigFogQuality.Value = selectedModeId;
try
{
switch (selectedModeId)
{
case 0:
GraphicsUtility.ButoEnabled = false;
break;
case 1:
case 2:
GraphicsUtility.ButoEnabled = true;
break;
}
RefreshVolumeCache();
foreach (Volume cachedVolume in _cachedVolumes)
{
if ((Object)(object)cachedVolume == (Object)null)
{
continue;
}
VolumeProfile val = (((Object)(object)cachedVolume.profile != (Object)null) ? cachedVolume.profile : cachedVolume.sharedProfile);
if ((Object)(object)val == (Object)null)
{
continue;
}
foreach (VolumeComponent component in val.components)
{
if (((Object)component).name.Contains("Fog") || ((object)component).GetType().Name.Contains("Fog"))
{
switch (selectedModeId)
{
case 0:
component.active = false;
break;
case 1:
case 2:
component.active = true;
break;
}
}
}
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换雾效质量失败: ", "Failed to switch fog quality: ") + ex.Message);
}
}
internal static void ApplyClarityQuality(UISettings uiSettings, int selectedModeId)
{
ConfigClarityQuality.Value = selectedModeId;
try
{
Beautify settings = BeautifySettings.settings;
Action<Beautify> action = delegate(Beautify b)
{
if (!((Object)(object)b == (Object)null))
{
if (!State.BeautifyBackupDone)
{
State.BeautifyBackupDone = true;
State.OriginalBeautifySharpenClamp = ((VolumeParameter<float>)(object)b.sharpenClamp).value;
State.OriginalBeautifySharpenRelaxation = ((VolumeParameter<float>)(object)b.sharpenRelaxation).value;
State.OriginalBeautifySharpenMotionSensibility = ((VolumeParameter<float>)(object)b.sharpenMotionSensibility).value;
State.OriginalBeautifySharpenIntensity = ((VolumeParameter<float>)(object)b.sharpenIntensity).value;
}
switch (selectedModeId)
{
case 0:
((VolumeParameter<float>)(object)b.sharpenIntensity).value = 10f;
((VolumeParameter<float>)(object)b.sharpenClamp).value = 0.1f;
break;
case 1:
((VolumeParameter<float>)(object)b.sharpenIntensity).value = 80f;
((VolumeParameter<float>)(object)b.sharpenClamp).value = 0.85f;
((VolumeParameter<float>)(object)b.sharpenRelaxation).value = 0f;
break;
case 2:
((VolumeParameter<float>)(object)b.sharpenIntensity).value = 250f;
((VolumeParameter<float>)(object)b.sharpenClamp).value = 1f;
((VolumeParameter<float>)(object)b.sharpenRelaxation).value = 0f;
break;
}
if (ConfigVhsBlurQuality.Value == 0)
{
ClampedFloatParameter sharpenIntensity = b.sharpenIntensity;
((VolumeParameter<float>)(object)sharpenIntensity).value = ((VolumeParameter<float>)(object)sharpenIntensity).value * 1.2f;
}
}
};
action(settings);
RefreshVolumeCache();
Beautify obj = default(Beautify);
Beautify obj2 = default(Beautify);
foreach (Volume cachedVolume in _cachedVolumes)
{
if (!((Object)(object)cachedVolume == (Object)null))
{
if ((Object)(object)cachedVolume.sharedProfile != (Object)null && cachedVolume.sharedProfile.TryGet<Beautify>(ref obj))
{
action(obj);
}
if ((Object)(object)cachedVolume.profile != (Object)null && cachedVolume.profile.TryGet<Beautify>(ref obj2))
{
action(obj2);
}
}
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换画面清晰度失败: ", "Failed to switch clarity quality: ") + ex.Message);
}
}
internal static void OnVhsToggleChanged(UISettings uiSettings, bool enabled, bool force = false)
{
//IL_0341: Unknown result type (might be due to invalid IL or missing references)
//IL_0317: Unknown result type (might be due to invalid IL or missing references)
if (!force && _lastVhsEnabled.HasValue && _lastVhsEnabled.Value == enabled)
{
return;
}
_lastVhsEnabled = enabled;
ConfigVhsBlurQuality.Value = (enabled ? 1 : 0);
try
{
State.VhsOverrideHasValue = true;
State.VhsOverrideEnabled = enabled;
RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
UniversalRenderPipelineAsset val = (UniversalRenderPipelineAsset)(object)((currentRenderPipeline is UniversalRenderPipelineAsset) ? currentRenderPipeline : null);
if ((Object)(object)val != (Object)null)
{
val.renderScale = 1f;
}
if (Time.time - _lastVhsCacheTime > 5f)
{
_lastVhsCacheTime = Time.time;
_cachedVhsComponents.Clear();
VHSProVolumeComponent[] array = Object.FindObjectsByType<VHSProVolumeComponent>((FindObjectsInactive)1, (FindObjectsSortMode)0);
if (array != null)
{
_cachedVhsComponents.AddRange(array);
}
}
if (_cachedVhsComponents != null)
{
foreach (VHSProVolumeComponent cachedVhsComponent in _cachedVhsComponents)
{
if ((Object)(object)cachedVhsComponent == (Object)null)
{
continue;
}
((VolumeComponent)cachedVhsComponent).active = enabled;
if (enabled)
{
((VolumeParameter<bool>)(object)cachedVhsComponent.pixelOn).value = false;
((VolumeParameter<int>)(object)cachedVhsComponent.screenWidth).value = 1920;
((VolumeParameter<int>)(object)cachedVhsComponent.screenHeight).value = 1080;
((VolumeParameter<bool>)(object)cachedVhsComponent.lineNoiseOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.filmgrainOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.ditherOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.jitterHOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.jitterVOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.twitchHOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.twitchVOn).value = false;
if (cachedVhsComponent.colorOn != null)
{
((VolumeParameter<bool>)(object)cachedVhsComponent.colorOn).value = false;
}
((VolumeParameter<bool>)(object)cachedVhsComponent.bleedOn).value = true;
((VolumeParameter<float>)(object)cachedVhsComponent.bleedAmount).value = 0.05f;
((VolumeParameter<bool>)(object)cachedVhsComponent.tapeNoiseOn).value = true;
((VolumeParameter<float>)(object)cachedVhsComponent.tapeNoiseAmt).value = 0.15f;
((VolumeParameter<bool>)(object)cachedVhsComponent.signalNoiseOn).value = true;
((VolumeParameter<float>)(object)cachedVhsComponent.signalNoiseAmount).value = 0.05f;
if (cachedVhsComponent.scanLinesOn != null)
{
((VolumeParameter<bool>)(object)cachedVhsComponent.scanLinesOn).value = false;
}
if (cachedVhsComponent.feedbackOn != null)
{
((VolumeParameter<bool>)(object)cachedVhsComponent.feedbackOn).value = false;
}
}
else
{
((VolumeComponent)cachedVhsComponent).active = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.pixelOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.tapeNoiseOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.jitterHOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.jitterVOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.twitchHOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.twitchVOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.bleedOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.signalNoiseOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.feedbackOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.filmgrainOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.lineNoiseOn).value = false;
((VolumeParameter<bool>)(object)cachedVhsComponent.ditherOn).value = false;
}
}
}
ScriptableRendererFeature rendererFeature = GraphicsUtility.GetRendererFeature("LowResRendererFeature");
LowResRendererFeature val2 = (LowResRendererFeature)(object)((rendererFeature is LowResRendererFeature) ? rendererFeature : null);
if ((Object)(object)val2 != (Object)null)
{
if (enabled)
{
((ScriptableRendererFeature)val2).SetActive(true);
val2.useVertexSnap = true;
val2.vertexSnapLines = 240;
Shader.SetGlobalVector("_VertexSnapResolution", new Vector4(320f, 240f, 0f, 0f));
}
else
{
((ScriptableRendererFeature)val2).SetActive(false);
val2.useVertexSnap = false;
val2.vertexSnapLines = 8192;
Shader.SetGlobalVector("_VertexSnapResolution", Vector4.zero);
}
}
if (!enabled)
{
ApplyClarityQuality(null, ConfigClarityQuality.Value);
}
RefreshVolumeCache();
DepthOfField val3 = default(DepthOfField);
FilmGrain val4 = default(FilmGrain);
ChromaticAberration val5 = default(ChromaticAberration);
LensDistortion val6 = default(LensDistortion);
MotionBlur val7 = default(MotionBlur);
foreach (Volume cachedVolume in _cachedVolumes)
{
if ((Object)(object)cachedVolume == (Object)null || !((Object)(object)cachedVolume.profile != (Object)null))
{
continue;
}
if (cachedVolume.profile.TryGet<DepthOfField>(ref val3))
{
((VolumeComponent)val3).active = enabled;
}
if (cachedVolume.profile.TryGet<FilmGrain>(ref val4))
{
((VolumeComponent)val4).active = enabled;
}
if (!enabled)
{
if (cachedVolume.profile.TryGet<ChromaticAberration>(ref val5))
{
((VolumeComponent)val5).active = false;
}
if (cachedVolume.profile.TryGet<LensDistortion>(ref val6))
{
((VolumeComponent)val6).active = false;
}
if (cachedVolume.profile.TryGet<MotionBlur>(ref val7))
{
((VolumeComponent)val7).active = false;
}
}
}
if (!enabled && (Object)(object)BeautifySettings.settings != (Object)null)
{
Beautify settings = BeautifySettings.settings;
((VolumeParameter<float>)(object)settings.blurIntensity).value = 0f;
((VolumeParameter<float>)(object)settings.lensDirtIntensity).value = 0f;
FloatParameter bloomIntensity = settings.bloomIntensity;
((VolumeParameter<float>)(object)bloomIntensity).value = ((VolumeParameter<float>)(object)bloomIntensity).value * 0.3f;
((VolumeParameter<float>)(object)settings.anamorphicFlaresIntensity).value = 0f;
((VolumeParameter<bool>)(object)settings.depthOfField).value = false;
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换 VHS 效果失败: ", "Failed to toggle VHS: ") + ex.Message);
}
}
internal static void OnBloomIntensityChanged(int level)
{
ConfigBloomIntensity.Value = level;
try
{
Beautify settings = BeautifySettings.settings;
if (!((Object)(object)settings == (Object)null))
{
if (!State.BloomBackupDone)
{
State.OriginalBloomIntensity = ((VolumeParameter<float>)(object)settings.bloomIntensity).value;
State.BloomBackupDone = true;
}
switch (level)
{
case 0:
((VolumeParameter<float>)(object)settings.bloomIntensity).value = 0f;
break;
case 1:
((VolumeParameter<float>)(object)settings.bloomIntensity).value = ((State.OriginalBloomIntensity > 0f) ? State.OriginalBloomIntensity : 1f);
((VolumeParameter<float>)(object)settings.bloomThreshold).value = 0.8f;
break;
case 2:
((VolumeParameter<float>)(object)settings.bloomIntensity).value = 5.5f;
((VolumeParameter<float>)(object)settings.bloomThreshold).value = 0.5f;
((VolumeParameter<float>)(object)settings.bloomWeight0).value = 0.5f;
((VolumeParameter<float>)(object)settings.bloomWeight1).value = 0.5f;
((VolumeParameter<float>)(object)settings.bloomWeight2).value = 0.5f;
((VolumeParameter<float>)(object)settings.bloomWeight3).value = 0.5f;
((VolumeParameter<float>)(object)settings.bloomWeight4).value = 0.5f;
break;
}
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换泛光强度失败: ", "Failed to switch bloom intensity: ") + ex.Message);
}
}
internal static void OnMotionBlurQualityChanged(int selectedModeId)
{
ConfigMotionBlurQuality.Value = selectedModeId;
bool active = selectedModeId > 0;
try
{
MotionBlur val = null;
RefreshVolumeCache();
foreach (Volume cachedVolume in _cachedVolumes)
{
if ((Object)(object)cachedVolume == (Object)null)
{
continue;
}
VolumeProfile val2 = (((Object)(object)cachedVolume.sharedProfile != (Object)null) ? cachedVolume.sharedProfile : cachedVolume.profile);
if ((Object)(object)val2 != (Object)null && val2.TryGet<MotionBlur>(ref val))
{
if (!State.MotionBlurBackupDone)
{
State.OriginalMotionBlurEnabled = ((VolumeComponent)val).active;
State.MotionBlurBackupDone = true;
}
((VolumeComponent)val).active = active;
}
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换运动模糊失败: ", "Failed to toggle motion blur: ") + ex.Message);
}
}
internal static void OnBrightnessChanged(float value, bool force = false)
{
ConfigBrightness.Value = value;
try
{
Action<VolumeProfile> action = delegate(VolumeProfile profile)
{
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0329: Unknown result type (might be due to invalid IL or missing references)
//IL_0351: Unknown result type (might be due to invalid IL or missing references)
//IL_0379: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)profile == (Object)null))
{
ColorAdjustments val = default(ColorAdjustments);
if (profile.TryGet<ColorAdjustments>(ref val))
{
((VolumeComponent)val).active = true;
if (value > 1f)
{
float value2 = (value - 1f) * 0.45f;
((VolumeParameter<float>)(object)val.postExposure).value = value2;
((VolumeParameter<float>)(object)val.contrast).value = 40f + (value - 1f) * 150f;
((VolumeParameter<float>)(object)val.saturation).value = 8f;
}
else
{
((VolumeParameter<float>)(object)val.postExposure).value = 0.15f;
((VolumeParameter<float>)(object)val.contrast).value = 80f;
((VolumeParameter<float>)(object)val.saturation).value = 20f;
}
}
LiftGammaGain val2 = default(LiftGammaGain);
if (profile.TryGet<LiftGammaGain>(ref val2))
{
((VolumeComponent)val2).active = true;
if (value > 1f)
{
float num = (value - 1f) * 0.8f;
Vector4 value3 = ((VolumeParameter<Vector4>)(object)val2.gamma).value;
value3.w = num * 1.5f;
((VolumeParameter<Vector4>)(object)val2.gamma).value = value3;
Vector4 value4 = ((VolumeParameter<Vector4>)(object)val2.lift).value;
value4.w = num * 0.6f;
((VolumeParameter<Vector4>)(object)val2.lift).value = value4;
Vector4 value5 = ((VolumeParameter<Vector4>)(object)val2.gain).value;
value5.w = num * 0.2f;
((VolumeParameter<Vector4>)(object)val2.gain).value = value5;
}
else
{
((VolumeParameter<Vector4>)(object)val2.gamma).value = Vector4.zero;
((VolumeParameter<Vector4>)(object)val2.lift).value = new Vector4(1f, 1f, 1f, -0.15f);
((VolumeParameter<Vector4>)(object)val2.gain).value = Vector4.zero;
}
}
Vignette val3 = default(Vignette);
if (profile.TryGet<Vignette>(ref val3))
{
((VolumeComponent)val3).active = false;
((VolumeParameter<float>)(object)val3.intensity).value = 0f;
}
Bloom val4 = default(Bloom);
if (profile.TryGet<Bloom>(ref val4))
{
if (value > 1f)
{
((VolumeParameter<float>)(object)val4.threshold).value = 10f;
((VolumeParameter<float>)(object)val4.intensity).value = (float)ConfigBloomIntensity.Value * 0.01f;
try
{
((VolumeParameter<float>)(object)val4.dirtIntensity).value = 0f;
}
catch
{
}
}
else
{
((VolumeComponent)val4).active = false;
((VolumeParameter<float>)(object)val4.threshold).value = 10f;
((VolumeParameter<float>)(object)val4.intensity).value = 0f;
try
{
((VolumeParameter<float>)(object)val4.dirtIntensity).value = 0f;
}
catch
{
}
}
}
Tonemapping val5 = default(Tonemapping);
if (profile.TryGet<Tonemapping>(ref val5))
{
((VolumeComponent)val5).active = false;
}
foreach (VolumeComponent component in profile.components)
{
if (((Object)component).name.Contains("Fog") || ((object)component).GetType().Name.Contains("Fog"))
{
component.active = false;
}
}
ShadowsMidtonesHighlights val6 = default(ShadowsMidtonesHighlights);
if (profile.TryGet<ShadowsMidtonesHighlights>(ref val6))
{
((VolumeComponent)val6).active = true;
if (value > 1f)
{
float num2 = (value - 1f) * 0.5f;
((VolumeParameter<Vector4>)(object)val6.shadows).value = new Vector4(1f, 1f, 1f, num2);
((VolumeParameter<Vector4>)(object)val6.midtones).value = new Vector4(1f, 1f, 1f, num2 * 0.7f);
((VolumeParameter<Vector4>)(object)val6.highlights).value = new Vector4(1f, 1f, 1f, num2 * 0.2f);
}
else
{
((VolumeParameter<Vector4>)(object)val6.shadows).value = new Vector4(1f, 1f, 1f, 0f);
((VolumeParameter<Vector4>)(object)val6.midtones).value = new Vector4(1f, 1f, 1f, 0f);
((VolumeParameter<Vector4>)(object)val6.highlights).value = new Vector4(1f, 1f, 1f, 0f);
}
}
if ((Object)(object)BeautifySettings.settings != (Object)null)
{
if (value > 1f)
{
try
{
((VolumeParameter<float>)(object)BeautifySettings.settings.lensDirtIntensity).value = 0f;
}
catch
{
}
try
{
OnBloomIntensityChanged(ConfigBloomIntensity.Value);
FloatParameter bloomIntensity = BeautifySettings.settings.bloomIntensity;
((VolumeParameter<float>)(object)bloomIntensity).value = ((VolumeParameter<float>)(object)bloomIntensity).value * 0.3f;
}
catch
{
}
}
else
{
OnBloomIntensityChanged(ConfigBloomIntensity.Value);
try
{
((VolumeParameter<float>)(object)BeautifySettings.settings.lensDirtIntensity).value = 0.2f;
}
catch
{
}
}
}
FilmGrain val7 = default(FilmGrain);
if (profile.TryGet<FilmGrain>(ref val7))
{
((VolumeComponent)val7).active = false;
}
Tonemapping val8 = default(Tonemapping);
if (profile.TryGet<Tonemapping>(ref val8))
{
((VolumeComponent)val8).active = false;
}
Shader.SetGlobalFloat("_Dithering", 0f);
Shader.DisableKeyword("_DISTORTION_ON");
}
};
if ((Object)(object)BeautifySettings.settings != (Object)null)
{
((VolumeParameter<float>)(object)BeautifySettings.settings.brightness).value = value;
if (value > 1.5f)
{
((VolumeParameter<float>)(object)BeautifySettings.settings.contrast).value = 0.9f;
}
}
RefreshVolumeCache();
foreach (Volume cachedVolume in _cachedVolumes)
{
if (!((Object)(object)cachedVolume == (Object)null))
{
if ((Object)(object)cachedVolume.profile != (Object)null)
{
action(cachedVolume.profile);
}
if ((Object)(object)cachedVolume.sharedProfile != (Object)null)
{
action(cachedVolume.sharedProfile);
}
}
}
try
{
if ((Object)(object)CameraManager.Instance != (Object)null)
{
float brightness = (value - 1f) * 100f;
CameraManager.Instance.SetBrightness(brightness);
}
}
catch
{
}
if (!force)
{
Log($"Brightness V6 applied: {value}");
}
}
catch (Exception ex)
{
Log(GetLocalizedText("切换亮度失败: ", "Failed to switch brightness: ") + ex.Message);
}
}
}
[HarmonyPatch(typeof(UISettings))]
internal static class GraphicsEnhancerMod_UISettingsPatches
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
private static void UISettings_Awake_Postfix(UISettings __instance)
{
try
{
GraphicsEnhancerUiInjector.TryInjectModSection(__instance);
}
catch (Exception ex)
{
GraphicsEnhancerMod.Log(GraphicsEnhancerMod.GetLocalizedText("注入画质优化选项卡失败: ", "Failed to inject graphics enhancer tab: ") + ex.Message);
}
}
[HarmonyPostfix]
[HarmonyPatch("Initialise")]
private static void UISettings_Initialise_Postfix(UISettings __instance)
{
try
{
GraphicsEnhancerUiInjector.TryInjectModSection(__instance);
}
catch (Exception ex)
{
GraphicsEnhancerMod.Log(GraphicsEnhancerMod.GetLocalizedText("Initialise 阶段注入失败: ", "Injection after Initialise failed: ") + ex.Message);
}
}
[HarmonyPostfix]
[HarmonyPatch("ChangeSection")]
private static void UISettings_ChangeSection_Postfix(UISettings __instance, object targetSection)
{
try
{
GraphicsEnhancerUiInjector.OnSectionChanged(__instance, targetSection);
}
catch (Exception ex)
{
GraphicsEnhancerMod.Log(GraphicsEnhancerMod.GetLocalizedText("ChangeSection 阶段处理失败: ", "ChangeSection handling failed: ") + ex.Message);
}
}
}
[HarmonyPatch(typeof(VHSProRenderPass))]
internal static class GraphicsEnhancerMod_VHSPatches
{
[HarmonyPrefix]
[HarmonyPatch("RecordRenderGraph")]
private static bool RecordRenderGraph_Prefix()
{
if (GraphicsEnhancerMod.State.VhsOverrideHasValue && !GraphicsEnhancerMod.State.VhsOverrideEnabled)
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(UISettingToggle))]
internal static class GraphicsEnhancerMod_UISettingTogglePatches
{
[HarmonyPostfix]
[HarmonyPatch("UpdateValueLabel")]
private static void UpdateValueLabel_Postfix(UISettingToggle __instance, bool value)
{
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
try
{
string name = ((Object)((Component)__instance).gameObject).name;
if (!name.Contains("GraphicsEnhancerMod") && !name.Contains("VHS") && !name.Contains("Master"))
{
return;
}
LocalisedTMP component = ((Component)__instance).GetComponent<LocalisedTMP>();
if ((Object)(object)component != (Object)null)
{
((Behaviour)component).enabled = false;
}
FieldInfo field = typeof(UISettingToggle).GetField("localisedLabelText", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
field.SetValue(__instance, null);
}
FieldInfo field2 = typeof(UISettingElement<bool>).GetField("valueLabel", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field2 != null)
{
object? value2 = field2.GetValue(__instance);
TMP_Text val = (TMP_Text)((value2 is TMP_Text) ? value2 : null);
if ((Object)(object)val != (Object)null)
{
bool flag = GraphicsEnhancerMod.IsChineseLanguage(Application.systemLanguage);
string text = ((!value) ? (flag ? "禁用" : "Disabled") : (flag ? "启用" : "Enabled"));
val.text = text;
((Graphic)val).color = (value ? new Color(0.2f, 1f, 0.2f, 1f) : new Color(0.7f, 0.7f, 0.7f, 1f));
((Graphic)val).SetAllDirty();
val.ForceMeshUpdate(false, false);
}
}
}
catch (Exception)
{
}
}
}
internal static class GraphicsEnhancerUiInjector
{
public class TooltipTrigger : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
{
[CompilerGenerated]
private sealed class <PositionUpdater>d__8 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public TooltipTrigger <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <PositionUpdater>d__8(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
int num = <>1__state;
TooltipTrigger tooltipTrigger = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
break;
case 1:
<>1__state = -1;
break;
}
if ((Object)(object)tooltipObj != (Object)null && tooltipObj.activeSelf)
{
tooltipTrigger.UpdatePosition();
<>2__current = null;
<>1__state = 1;
return true;
}
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public string tooltipText;
public TMP_FontAsset font;
private static GameObject tooltipObj;
private static TextMeshProUGUI textComp;
public void OnPointerEnter(PointerEventData eventData)
{
ShowTooltip();
}
public void OnPointerExit(PointerEventData eventData)
{
HideTooltip();
}
private void ShowTooltip()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)tooltipObj == (Object)null)
{
tooltipObj = new GameObject("ModTooltip");
Canvas val = Object.FindAnyObjectByType<Canvas>();
if ((Object)(object)val != (Object)null)
{
tooltipObj.transform.SetParent(((Component)val).transform, false);
}
GameObject val2 = new GameObject("Background");
val2.transform.SetParent(tooltipObj.transform, false);
((Graphic)val2.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.95f);
val2.GetComponent<RectTransform>().sizeDelta = new Vector2(420f, 120f);
GameObject val3 = new GameObject("Text");
val3.transform.SetParent(tooltipObj.transform, false);
textComp = val3.AddComponent<TextMeshProUGUI>();
((TMP_Text)textComp).fontSize = 15f;
((TMP_Text)textComp).alignment = (TextAlignmentOptions)513;
((Graphic)textComp).color = Color.white;
((TMP_Text)textComp).lineSpacing = 5f;
val3.GetComponent<RectTransform>().sizeDelta = new Vector2(380f, 80f);
tooltipObj.AddComponent<CanvasGroup>().blocksRaycasts = false;
tooltipObj.transform.SetAsLastSibling();
}
if ((Object)(object)textComp != (Object)null)
{
((TMP_Text)textComp).text = tooltipText;
if ((Object)(object)font != (Object)null)
{
((TMP_Text)textComp).font = font;
}
RectTransform component = ((Component)tooltipObj.transform.Find("Background")).GetComponent<RectTransform>();
int num = tooltipText.Split('\n').Length;
component.sizeDelta = new Vector2(400f, (float)(40 + num * 22));
}
tooltipObj.SetActive(true);
UpdatePosition();
((MonoBehaviour)this).StartCoroutine(PositionUpdater());
}
private void HideTooltip()
{
if ((Object)(object)tooltipObj != (Object)null)
{
tooltipObj.SetActive(false);
}
((MonoBehaviour)this).StopAllCoroutines();
}
[IteratorStateMachine(typeof(<PositionUpdater>d__8))]
private IEnumerator PositionUpdater()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <PositionUpdater>d__8(0)
{
<>4__this = this
};
}
private void UpdatePosition()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)tooltipObj != (Object)null)
{
Vector2 val = Vector2.op_Implicit(Input.mousePosition);
tooltipObj.transform.position = Vector2.op_Implicit(val + new Vector2(25f, 25f));
}
}
}
private static object s_modSection;
private static string GetButtonLabelText(Button button)
{
if ((Object)(object)button == (Object)null)
{
return null;
}
TMP_Text val = ((Component)button).GetComponentsInChildren<TMP_Text>(true).FirstOrDefault();
if ((Object)(object)val != (Object)null && !string.IsNullOrEmpty(val.text))
{
return val.text;
}
Text val2 = ((Component)button).GetComponentsInChildren<Text>(true).FirstOrDefault();
if ((Object)(object)val2 != (Object)null && !string.IsNullOrEmpty(val2.text))
{
return val2.text;
}
return null;
}
internal static void OnSectionChanged(UISettings uiSettings, object targetSection)
{
if ((Object)(object)uiSettings == (Object)null || targetSection == null)
{
return;
}
FieldInfo field = targetSection.GetType().GetField("SectionObj", BindingFlags.Instance | BindingFlags.Public);
if (field == null)
{
return;
}
object? value = field.GetValue(targetSection);
GameObject val = (GameObject)((value is GameObject) ? value : null);
if (!((Object)(object)val == (Object)null) && !(((Object)val).name != "GraphicsEnhancerMod_SectionContainer"))
{
if (!val.activeSelf)
{
val.SetActive(true);
}
_ = val.transform;
ScrollRect componentInChildren = val.GetComponentInChildren<ScrollRect>(true);
if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.content != (Object)null)
{
_ = componentInChildren.content;
((Component)componentInChildren).gameObject.SetActive(true);
}
SetupModSectionContent(val);
}
}
internal static void TryInjectModSection(UISettings uiSettings)
{
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_022e: Unknown result type (might be due to invalid IL or missing references)
//IL_0252: Unknown result type (might be due to invalid IL or missing references)
//IL_0267: Unknown result type (might be due to invalid IL or missing references)
//IL_026e: Expected O, but got Unknown
//IL_028a: Unknown result type (might be due to invalid IL or missing references)
//IL_0295: Unknown result type (might be due to invalid IL or missing references)
//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
//IL_02bf: Expected O, but got Unknown
//IL_02de: Unknown result type (might be due to invalid IL or missing references)
//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
//IL_030d: Unknown result type (might be due to invalid IL or missing references)
//IL_0312: Unknown result type (might be due to invalid IL or missing references)
//IL_0338: Unknown result type (might be due to invalid IL or missing references)
//IL_034e: Unknown result type (might be due to invalid IL or missing references)
//IL_0364: Unknown result type (might be due to invalid IL or missing references)
//IL_037a: Unknown result type (might be due to invalid IL or missing references)
//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
//IL_03c7: Expected O, but got Unknown
//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
//IL_0402: Unknown result type (might be due to invalid IL or missing references)
//IL_0417: Unknown result type (might be due to invalid IL or missing references)
//IL_042c: Unknown result type (might be due to invalid IL or missing references)
//IL_0440: Unknown result type (might be due to invalid IL or missing references)
//IL_0465: Unknown result type (might be due to invalid IL or missing references)
//IL_0485: Unknown result type (might be due to invalid IL or missing references)
//IL_048c: Expected O, but got Unknown
//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
//IL_04db: Unknown result type (might be due to invalid IL or missing references)
//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
//IL_051b: Unknown result type (might be due to invalid IL or missing references)
//IL_058d: Unknown result type (might be due to invalid IL or missing references)
//IL_0597: Expected O, but got Unknown
if ((Object)(object)uiSettings == (Object)null)
{
return;
}
Type typeFromHandle = typeof(UISettings);
FieldInfo field = typeFromHandle.GetField("sections", BindingFlags.Instance | BindingFlags.NonPublic);
if (field == null || !(field.GetValue(uiSettings) is Array array) || array.Length == 0)
{
return;
}
int length = array.Length;
for (int i = 0; i < length; i++)
{
object value = array.GetValue(i);
if (value == null)
{
continue;
}
FieldInfo field2 = value.GetType().GetField("SectionObj", BindingFlags.Instance | BindingFlags.Public);
if (field2 != null)
{
object? value2 = field2.GetValue(value);
GameObject val = (GameObject)((value2 is GameObject) ? value2 : null);
if ((Object)(object)val != (Object)null && ((Object)val).name == "GraphicsEnhancerMod_SectionContainer")
{
GraphicsEnhancerMod.Log(GraphicsEnhancerMod.GetLocalizedText("已检测到画质增强 MOD 容器,跳过注入。", "Graphics enhancer MOD container already present, skipping injection."));
return;
}
}
}
object value3 = array.GetValue(length - 1);
if (value3 == null)
{
return;
}
Type type = value3.GetType();
FieldInfo field3 = type.GetField("SectionObj", BindingFlags.Instance | BindingFlags.Public);
FieldInfo field4 = type.GetField("TabButton", BindingFlags.Instance | BindingFlags.Public);
FieldInfo field5 = type.GetField("Indictor", BindingFlags.Instance | BindingFlags.Public);
object? value4 = field3.GetValue(value3);
GameObject val2 = (GameObject)((value4 is GameObject) ? value4 : null);
object? value5 = field4.GetValue(value3);
Button val3 = (Button)((value5 is Button) ? value5 : null);
object? value6 = field5.GetValue(value3);
UIFader val4 = (UIFader)((value6 is UIFader) ? value6 : null);
if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
{
return;
}
GameObject val5 = Object.Instantiate<GameObject>(val2, val2.transform.parent);
((Object)val5).name = "GraphicsEnhancerMod_SectionContainer";
MonoBehaviour[] components = val5.GetComponents<MonoBehaviour>();
foreach (MonoBehaviour val6 in components)
{
if ((Object)(object)val6 != (Object)null)
{
Object.DestroyImmediate((Object)(object)val6);
}
}
foreach (Transform item in val5.transform)
{
Object.DestroyImmediate((Object)(object)((Component)item).gameObject);
}
GameObject val7 = new GameObject("Background");
val7.transform.SetParent(val5.transform, false);
RectTransform obj = val7.AddComponent<RectTransform>();
obj.anchorMin = Vector2.zero;
obj.anchorMax = Vector2.one;
obj.sizeDelta = Vector2.zero;
Image obj2 = val7.AddComponent<Image>();
((Graphic)obj2).color = new Color(0f, 0f, 0f, 0.98f);
((Graphic)obj2).raycastTarget = true;
GameObject val8 = new GameObject("Scroll View");
val8.transform.SetParent(val5.transform, false);
RectTransform obj3 = val8.AddComponent<RectTransform>();
obj3.anchorMin = Vector2.zero;
obj3.anchorMax = Vector2.one;
obj3.sizeDelta = new Vector2(-40f, -40f);
GameObject val9 = new GameObject("Viewport");
val9.transform.SetParent(val8.transform, false);
RectTransform val10 = val9.AddComponent<RectTransform>();
val10.anchorMin = Vector2.zero;
val10.anchorMax = Vector2.one;
val10.sizeDelta = Vector2.zero;
val9.AddComponent<RectMask2D>();
GameObject val11 = new GameObject("Content");
val11.transform.SetParent(val9.transform, false);
RectTransform val12 = val11.AddComponent<RectTransform>();
val12.anchorMin = new Vector2(0f, 1f);
val12.anchorMax = new Vector2(1f, 1f);
val12.pivot = new Vector2(0.5f, 1f);
val12.sizeDelta = new Vector2(0f, 1000f);
ScrollRect obj4 = val8.AddComponent<ScrollRect>();
obj4.content = val12;
obj4.viewport = val10;
obj4.horizontal = false;
obj4.vertical = true;
obj4.scrollSensitivity = 25f;
obj4.movementType = (MovementType)2;
GameObject val13 = new GameObject("Scrollbar Vertical");
val13.transform.SetParent(val8.transform, false);
RectTransform obj5 = val13.AddComponent<RectTransform>();
obj5.anchorMin = new Vector2(1f, 0f);
obj5.anchorMax = new Vector2(1f, 1f);
obj5.pivot = new Vector2(1f, 1f);
obj5.sizeDelta = new Vector2(20f, 0f);
obj5.anchoredPosition = new Vector2(5f, 0f);
((Graphic)val13.AddComponent<Image>()).color = new Color(0.1f, 0.1f, 0.1f, 0.8f);
Scrollbar val14 = val13.AddComponent<Scrollbar>();
val14.direction = (Direction)2;
GameObject val15 = new GameObject("Sliding Area");
val15.transform.SetParent(val13.transform, false);
RectTransform obj6 = val15.AddComponent<RectTransform>();
obj6.anchorMin = Vector2.zero;
obj6.anchorMax = Vector2.one;
obj6.sizeDelta = new Vector2(-10f, -10f);
GameObject val16 = new GameObject("Handle");
val16.transform.SetParent(val15.transform, false);
RectTransform val17 = val16.AddComponent<RectTransform>();
val17.sizeDelta = Vector2.zero;
((Graphic)val16.AddComponent<Image>()).color = new Color(0.6f, 0.6f, 0.6f, 1f);
val14.handleRect = val17;
obj4.verticalScrollbar = val14;
obj4.verticalScrollbarVisibility = (ScrollbarVisibility)2;
obj4.verticalScrollbarSpacing = 5f;
obj4.scrollSensitivity = 40f;
GameObject val18 = Object.Instantiate<GameObject>(((Component)val3).gameObject, ((Component)val3).transform.parent);
((Object)val18).name = "GraphicsEnhancerMod_TabButton";
Button component = val18.GetComponent<Button>();
if ((Object)(object)component != (Object)null)
{
component.onClick = new ButtonClickedEvent();
}
Button component2 = val18.GetComponent<Button>();
UIFader val19 = val18.GetComponentInChildren<UIFader>(true);
if ((Object)(object)val19 == (Object)null)
{
val19 = val4;
}
object obj7 = Activator.CreateInstance(type);
field3.SetValue(obj7, val5);
field4.SetValue(obj7, component2);
field5.SetValue(obj7, val19);
s_modSection = obj7;
Array array2 = Array.CreateInstance(type, length + 1);
for (int k = 0; k < length; k++)
{
array2.SetValue(array.GetValue(k), k);
}
array2.SetValue(obj7, length);
field.SetValue(uiSettings, array2);
string localizedText = GraphicsEnhancerMod.GetLocalizedText("画质增强", "Graphics");
SetLabel(val18, localizedText);
LocalisedTMP componentInChildren = val18.GetComponentInChildren<LocalisedTMP>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
Object.DestroyImmediate((Object)(object)componentInChildren);
}
LocalisedTMP[] componentsInChildren = val18.GetComponentsInChildren<LocalisedTMP>(true);
for (int j = 0; j < componentsInChildren.Length; j++)
{
Object.DestroyImmediate((Object)(object)componentsInChildren[j]);
}
val5.SetActive(false);
val18.SetActive(true);
LayoutElement val20 = val18.GetComponent<LayoutElement>();
if ((Object)(object)val20 == (Object)null)
{
val20 = val18.AddComponent<LayoutElement>();
}
val20.preferredWidth = 160f;
val20.minWidth = 120f;
SetupModSectionContent(val5);
GraphicsEnhancerMod.Log(GraphicsEnhancerMod.GetLocalizedText("画质增强选项卡注入完成。", "Graphics enhancer tab injected."));
MethodInfo method = typeFromHandle.GetMethod("InitSections", BindingFlags.Instance | BindingFlags.NonPublic);
if (method != null)
{
method.Invoke(uiSettings, null);
}
}
private static void SetupModSectionContent(GameObject sectionObj)
{
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Expected O, but got Unknown
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Expected O, but got Unknown
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Expected O, but got Unknown
//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
//IL_031e: Unknown result type (might be due to invalid IL or missing references)
//IL_0323: Unknown result type (might be due to invalid IL or missing references)
//IL_0330: Unknown result type (might be due to invalid IL or missing references)
//IL_038f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)sectionObj == (Object)null)
{
return;
}
try
{
bool activeSelf = sectionObj.activeSelf;
sectionObj.SetActive(false);
MonoBehaviour[] components = sectionObj.GetComponents<MonoBehaviour>();
foreach (MonoBehaviour val in components)
{
if (!((Object)(object)val == (Object)null))
{
string name = ((object)val).GetType().Name;
if (name.Contains("Section") || name.Contains("Accessibility") || name.Contains("Localised"))
{
Object.DestroyImmediate((Object)(object)val);
}
}
}
Transform val2 = sectionObj.transform.Find("Content");
if ((Object)(object)val2 == (Object)null)
{
val2 = sectionObj.transform.Find("Scroll View/Viewport/Content");
}
if ((Object)(object)val2 == (Object)null)
{
val2 = FindChildRecursive(sectionObj.transform, "Content");
}
if ((Object)(object)val2 == (Object)null)
{
val2 = sectionObj.transform;
}
List<GameObject> list = new List<GameObject>();
foreach (Transform item in val2)
{
Transform val3 = item;
if (!((Object)(object)val3 == (Object)null))
{
list.Add(((Component)val3).gameObject);
}
}
foreach (GameObject item2 in list)
{
if ((Object)(object)item2 != (Object)null)
{
Object.DestroyImmediate((Object)(object)item2);
}
}
LayoutGroup[] components2 = ((Component)val2).GetComponents<LayoutGroup>();
for (int i = 0; i < components2.Length; i++)
{
Object.DestroyImmediate((Object)(object)components2[i]);
}
ContentSizeFitter[] components3 = ((Component)val2).GetComponents<ContentSizeFitter>();
for (int i = 0; i < components3.Length; i++)
{
Object.DestroyImmediate((Object)(object)components3[i]);
}
VerticalLayoutGroup obj = ((Component)val2).gameObject.AddComponent<VerticalLayoutGroup>();
((LayoutGroup)obj).childAlignment = (TextAnchor)1;
((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
((HorizontalOrVerticalLayoutGroup)obj).spacing = 10f;
((LayoutGroup)obj).padding = new RectOffset(30, 30, 20, 30);
((Component)val2).gameObject.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
if (!Object.op_Implicit((Object)(object)val2.Find("ModTitle")))
{
GameObject val4 = new GameObject("ModTitle");
val4.transform.SetParent(val2, false);
TextMeshProUGUI val5 = val4.AddComponent<TextMeshProUGUI>();
TMP_FontAsset val6 = null;
TMP_Text[] array = Object.FindObjectsByType<TMP_Text>((FindObjectsInactive)1, (FindObjectsSortMode)0);
foreach (TMP_Text val7 in array)
{
if ((Object)(object)val7 != (Object)null && (Object)(object)val7.font != (Object)null && ((Object)val7.font).name != "Liberation Sans SDF")
{
val6 = val7.font;
break;
}
}
if ((Object)(object)val6 != (Object)null)
{
((TMP_Text)val5).font = val6;
}
((TMP_Text)val5).text = GraphicsEnhancerMod.GetLocalizedText("画质增强 MOD (柠檬)", "Graphics Enhancer MOD (Lemon)");
((TMP_Text)val5).fontSize = 32f;
((TMP_Text)val5).alignment = (TextAlignmentOptions)514;
((Graphic)val5).color = Color.white;
((TMP_Text)val5).fontStyle = (FontStyles)1;
LayoutElement obj2 = val4.AddComponent<LayoutElement>();
obj2.preferredHeight = 60f;
obj2.flexibleWidth = 1f;
GameObject val8 = new GameObject("ModAuthor");
val8.transform.SetParent(val2, false);
TextMeshProUGUI val9 = val8.AddComponent<TextMeshProUGUI>();
if ((Object)(object)val6 != (Object)null)
{
((TMP_Text)val9).font = val6;
}
((TMP_Text)val9).text = GraphicsEnhancerMod.GetLocalizedText("本MOD由哔哩哔哩-华丽的小柠檬啊 制作", "Created by Bilibili - 华丽的小柠檬啊");
((TMP_Text)val9).fontSize = 14f;
((TMP_Text)val9).alignment = (TextAlignmentOptions)514;
((Graphic)val9).color = new Color(0.8f, 0.8f, 0.8f, 1f);
LayoutElement obj3 = val8.AddComponent<LayoutElement>();
obj3.preferredHeight = 25f;
obj3.flexibleWidth = 1f;
}
EnsureModControlsInSection(null, sectionObj, val2);
sectionObj.SetActive(activeSelf);
}
catch (Exception ex)
{
GraphicsEnhancerMod.Log("Error in SetupModSectionContent: " + ex.Message);
}
}
private static void EnsureModControlsInSection(UISettings uiSettings, GameObject sectionObj, Transform parent)
{
if ((Object)(object)sectionObj == (Object)null || (Object)(object)parent == (Object)null)
{
return;
}
try
{
GameObject val = null;
GameObject val2 = null;
TMP_FontAsset font = null;
TMP_Text[] array = Object.FindObjectsByType<TMP_Text>((FindObjectsInactive)1, (FindObjectsSortMode)0);
foreach (TMP_Text val3 in array)
{
if ((Object)(object)val3 != (Object)null && (Object)(object)val3.font != (Object)null && ((Object)val3.font).name != "Liberation Sans SDF" && ((Object)val3.font).name.Length > 2)
{
font = val3.font;
if (((Object)val3.font).name.Contains("Chinese") || ((Object)val3.font).name.Contains("Main") || ((Object)val3.font).name.Contains("SDF"))
{
break;
}
}
}
UISettingToggle[] array2 = Object.FindObjectsByType<UISettingToggle>((FindObjectsInactive)1, (FindObjectsSortMode)0);
GraphicsEnhancerMod.Log($"Found {array2.Length} toggles in scene.");
UISettingToggle[] array3 = array2;
foreach (UISettingToggle val4 in array3)
{
if ((Object)(object)val4 != (Object)null && (Object)(object)((Component)val4).gameObject != (Object)null && !((Object)((Component)val4).gameObject).name.StartsWith("GraphicsEnhancerMod"))
{
val = ((Component)val4).gameObject;
GraphicsEnhancerMod.Log("Selected toggle template: " + ((Object)val).name);
break;
}
}
UISettingDropdown[] array4 = Object.FindObjectsByType<UISettingDropdown>((FindObjectsInactive)1, (FindObjectsSortMode)0);
GraphicsEnhancerMod.Log($"Found {array4.Length} dropdowns in scene.");
UISettingDropdown[] array5 = array4;
foreach (UISettingDropdown val5 in array5)
{
if ((Object)(object)val5 != (Object)null && (Object)(object)((Component)val5).gameObject != (Object)null && !((Object)((Component)val5).gameObject).name.StartsWith("GraphicsEnhancerMod"))
{
val2 = ((Component)val5).gameObject;
GraphicsEnhancerMod.Log("Selected dropdown template: " + ((Object)val2).name);
break;
}
}
if ((Object)(object)val == (Object)null)
{
GraphicsEnhancerMod.Log("Error: Could not find UI templates! Searching more aggressively...");
GameObject val6 = GameObject.Find("UISettingToggle");
if ((Object)(object)val6 != (Object)null)
{
val = val6;
}
}
if ((Object)(object)val == (Object)null)
{
GraphicsEnhancerMod.Log("CRITICAL: No toggle template found, cannot create controls.");
return;
}
List<string> options = new List<string>
{
GraphicsEnhancerMod.GetLocalizedText("低", "Low"),
GraphicsEnhancerMod.GetLocalizedText("中", "Medium"),
GraphicsEnhancerMod.GetLocalizedText("高", "High")
};
if ((Object)(object)val2 != (Object)null)
{
CreateDropdown(val2, parent, "GraphicsEnhancerMod_MasterToggle", GraphicsEnhancerMod.GetLocalizedText("画质增强预设 (总开关)", "Graphics Preset"), new List<string>
{
GraphicsEnhancerMod.GetLocalizedText("禁用", "Disabled"),
GraphicsEnhancerMod.GetLocalizedText("启用", "Enabled")
}, delegate(int value)
{
GraphicsEnhancerMod.OnModToggleChanged(value == 1);
}, GraphicsEnhancerMod.ConfigMasterEnabled.Value ? 1 : 0, font, GraphicsEnhancerMod.GetLocalizedText("一键开启所有画质增强选项。\n禁用: 恢复原版 / 启用: 开启增强组合", "Enable all graphics enhancement options."));
}
if ((Object)(object)val2 != (Object)null)
{
CreateDropdown(val2, parent, "GraphicsEnhancerMod_ClarityQuality", GraphicsEnhancerMod.GetLocalizedText("画面清晰度 (锐化)", "Image Clarity"), options, delegate(int value)
{
GraphicsEnhancerMod.ApplyClarityQuality(null, value);
}, GraphicsEnhancerMod.ConfigClarityQuality.Value, font, GraphicsEnhancerMod.GetLocalizedText("控制画面的清晰程度(锐化强度)。\n低: 原版 / 中: 显著提升 / 高: 极致清晰", "Controls the sharpness of the image."));
}
if ((Object)(object)val2 != (Object)null)
{
CreateDropdown(val2, parent, "GraphicsEnhancerMod_VHSToggle", GraphicsEnhancerMod.GetLocalizedText("VHS 模糊效果 (开关)", "VHS Blur Effect"), new List<string>
{
GraphicsEnhancerMod.GetLocalizedText("关闭 (现代高清)", "Off (Modern HD)"),
GraphicsEnhancerMod.GetLocalizedText("开启 (复古模糊)", "On (Retro Blur)")
}, delegate(int value)
{
GraphicsEnhancerMod.OnVhsToggleChanged(null, value == 1);
}, (GraphicsEnhancerMod.ConfigVhsBlurQuality.Value > 0) ? 1 : 0, font, GraphicsEnhancerMod.GetLocalizedText("控制 VHS 滤镜。关闭后将强制 1:1 渲染,消除所有马赛克感。\n关闭: 画面最清晰 / 开启: 复古感", "Toggle VHS filter. Disabling forces 1:1 rendering."));
}
if ((Object)(object)val2 != (Object)null)
{
CreateDropdown(val2, parent, "GraphicsEnhancerMod_ShadowQuality", GraphicsEnhancerMod.GetLocalizedText("阴影质量", "Shadow Quality"), options, delegate(int value)
{
GraphicsEnhancerMod.OnShadowQualityChanged(value);
}, GraphicsEnhancerMod.ConfigShadowQuality.Value, font, GraphicsEnhancerMod.GetLocalizedText("控制阴影的分辨率和渲染距离。\n低: 1024 / 中: 2048+额外级联 / 高: 4096+全级联", "Controls shadow resolution and clarity.\nLow: 1024 / Medium: 2048+Extra / High: 4096+Full"));
}
if ((Object)(object)val2 != (Object)null)
{
CreateDropdown(val2, parent, "GraphicsEnhancerMod_AdditionalShadowQuality", GraphicsEnhancerMod.GetLocalizedText("附加光源阴影 (看房子卡顿调这个)", "Additional Light Shadows"), options, delegate(int value)
{
GraphicsEnhancerMod.OnAdditionalShadowQualityChanged(value);
}, GraphicsEnhancerMod.ConfigAdditionalShadowQuality.Value, font, GraphicsEnhancerMod.GetLocalizedText("控制小灯泡等附加光源的阴影。看房子 GPU 飙升时建议调低或关闭。\n低: 关闭 / 中: 512 / 高: 1024", "Controls shadows from additional lights. Lower this if looking at houses causes GPU spikes.\nLow: Off / Medium: 512 / High: 1024"));
}
if ((Object)(object)val2 != (Object)null)
{
CreateDropdown(val2, parent, "GraphicsEnhancerMod_SSAOQuality", GraphicsEnhancerMod.GetLocalizedText("环境光遮蔽质量", "SSAO Quality"), options, delegate(int value)
{
GraphicsEnhancerMod.OnSsaoQualityChanged(value);
}, GraphicsEnhancerMod.ConfigSsaoQuality.Value, font, GraphicsEnhancerMod.GetLocalizedText("控制物体接触面的阴影细节(环境光遮蔽)。\n低: 关闭 / 中: 性能模式 / 高: 高质量细节", "Controls shadow detail at object contact points (SSAO).\nLow: Off / Medium: Performance / High: High Quality"));
}
if ((Object)(object)val2 != (Object)null)
{
CreateDropdown(val2, parent, "GraphicsEnhancerMod_DecalQuality", GraphicsEnhancerMod.GetLocalizedText("贴花特效质量", "Decal Quality"), options, delegate(int value)
{
GraphicsEnhancerMod.OnDecalQualityChanged(value);
}, GraphicsEnhancerMod.ConfigDecalQuality.Value, font, GraphicsEnhancerMod.GetLocalizedText("控制地面血迹、污渍等贴花的渲染质量。\n低: 关闭 / 中: 开启 / 高: 开启", "Controls rendering quality of blood, stains, etc.\nLow: Off / Medium: On / High: On"));
}
if ((Object)(object)val2 != (Object)null)
{
CreateDropdown(val2, parent, "GraphicsEnhancerMod_FogQuality", GraphicsEnhancerMod.GetLocalizedText("雾效质量", "Fog Quality"), options, delegate(int value)
{
GraphicsEnhancerMod.OnFogQualityChanged(value);
}, GraphicsEnhancerMod.ConfigFogQuality.Value, font, GraphicsEnhancerMod.GetLocalizedText("控制场景迷雾和体积光效果。\n低: 关闭 / 中: 开启 / 高: 开启", "Controls volumetric fog and lighting.\nLow: Off / Medium: On / High: On"));
}
if ((Object)(object)val2 != (Object)null)
{
CreateDropdown(val2, parent, "GraphicsEnhancerMod_BloomIntensity", GraphicsEnhancerMod.GetLocalizedText("泛光强度 (Bloom)", "Bloom Intensity"), options, delegate(int value)
{
GraphicsEnhancerMod.OnBloomIntensityChanged(value);
}, GraphicsEnhancerMod.ConfigBloomIntensity.Value, font, GraphicsEnhancerMod.GetLocalizedText("控制发光物体的亮度溢出感。\n低: 关闭 / 中: 正常 / 高: 电影感强光", "Controls the glow intensity of bright objects.\nLow: Off / Medium: Normal / High: Cinematic Glow"));
}
if ((Object)(object)val2 != (Object)null)
{
CreateDropdown(val2, parent, "GraphicsEnhancerMod_MotionBlur", GraphicsEnhancerMod.GetLocalizedText("运动模糊 (建议关闭)", "Motion Blur"), new List<string>
{
GraphicsEnhancerMod.GetLocalizedText("禁用", "Disabled"),
GraphicsEnhancerMod.GetLocalizedText("启用", "Enabled")
}, delegate(int value)
{
GraphicsEnhancerMod.OnMotionBlurQualityChanged(value);
}, GraphicsEnhancerMod.ConfigMotionBlurQuality.Value, font, GraphicsEnhancerMod.GetLocalizedText("控制视角移动时的模糊感。建议关闭以获得更清晰的画面。\n开启: 电影感 / 关闭: 画面清晰", "Toggle blur during camera movement. Disable for better clarity."));
}
if ((Object)(object)val2 != (Object)null)
{
new List<string>
{
GraphicsEnhancerMod.GetLocalizedText("较暗 (0.8x)", "Dim (0.8x)"),
GraphicsEnhancerMod.GetLocalizedText("标准 (1.0x)", "Standard (1.0x)"),
GraphicsEnhancerMod.GetLocalizedText("明亮 (1.2x)", "Bright (1.2x)"),
GraphicsEnhancerMod.GetLocalizedText("极亮 (1.5x)", "Ultra (1.5x)")
};
float[] brightnessValues = new float[5] { 0.8f, 1f, 1.3f, 1.6f, 2f };
int initialValue = 1;
float value2 = GraphicsEnhancerMod.ConfigBrightness.Value;
float num = float.MaxValue;
for (int j = 0; j < brightnessValues.Length; j++)
{
float num2 = Math.Abs(brightnessValues[j] - value2);
if (num2 < num)
{
num = num2;
initialValue = j;
}
}
CreateDropdown(val2, parent, "GraphicsEnhancerMod_Brightness", GraphicsEnhancerMod.GetLocalizedText("画面亮度/曝光 (暗部增强)", "Brightness/Exposure (Darkness Boost)"), new List<string>
{
GraphicsEnhancerMod.GetLocalizedText("较暗 (0.8x)", "Dim (0.8x)"),
GraphicsEnhancerMod.GetLocalizedText("标准 (1.0x)", "Standard (1.0x)"),
GraphicsEnhancerMod.GetLocalizedText("明亮 (1.3x)", "Bright (1.3x)"),
GraphicsEnhancerMod.GetLocalizedText("极亮 (1.6x)", "Ultra (1.6x)"),
GraphicsEnhancerMod.GetLocalizedText("夜视 (2.0x)", "Night Vision (2.0x)")
}, delegate(int value)
{
GraphicsEnhancerMod.OnBrightnessChanged(brightnessValues[value]);
}, initialValue, font, GraphicsEnhancerMod.GetLocalizedText("控制地图内的整体明暗程度。觉得太暗可以调高此项。\n标准: 1.0 / 明亮: 1.3 / 夜视: 2.0 (大幅拉升暗部)", "Controls overall map brightness. Increase this if the scene feels too dark."));
}
GraphicsEnhancerMod.Log("All controls injected successfully.");
}
catch (Exception ex)
{
GraphicsEnhancerMod.Log("Error in EnsureModControlsInSection: " + ex.ToString());
}
}
private static void SetLabel(GameObject obj, string label, TMP_FontAsset font = null, string tooltipText = "")
{
if ((Object)(object)obj == (Object)null)
{
return;
}
LocalisedTMP[] componentsInChildren = obj.GetComponentsInChildren<LocalisedTMP>(true);
foreach (LocalisedTMP val in componentsInChildren)
{
if ((Object)(object)val != (Object)null)
{
Object.DestroyImmediate((Object)(object)val);
}
}
Transform val2 = obj.transform.Find("Label");
if ((Object)(object)val2 == (Object)null)
{
val2 = obj.transform.Find("Title");
}
if ((Object)(object)val2 != (Object)null)
{
LocalisedTMP component = ((Component)val2).GetComponent<LocalisedTMP>();
if ((Object)(object)component != (Object)null)
{
Object.DestroyImmediate((Object)(object)component);
}
TMP_Text component2 = ((Component)val2).GetComponent<TMP_Text>();
if ((Object)(object)component2 != (Object)null)
{
if ((Object)(object)font != (Object)null)
{
component2.font = font;
}
component2.text = label;
}
else
{
Text component3 = ((Component)val2).GetComponent<Text>();
if ((Object)(object)component3 != (Object)null)
{
component3.text = label;
}
}
}
else
{
TMP_Text[] componentsInChildren2 = obj.GetComponentsInChildren<TMP_Text>(true);
TMP_Text[] array = componentsInChildren2;
foreach (TMP_Text val3 in array)
{
if (!(((Object)((Component)val3).gameObject).name == "Item Label"))
{
LocalisedTMP component4 = ((Component)val3).gameObject.GetComponent<LocalisedTMP>();
if ((Object)(object)component4 != (Object)null)
{
Object.DestroyImmediate((Object)(object)component4);
}
if ((Object)(object)font != (Object)null)
{
val3.font = font;
}
val3.text = label;
}
}
if (componentsInChildren2.Length == 0)
{
Text[] componentsInChildren3 = obj.GetComponentsInChildren<Text>(true);
for (int i = 0; i < componentsInChildren3.Length; i++)
{
componentsInChildren3[i].text = label;
}
}
}
if (!string.IsNullOrEmpty(tooltipText))
{
AddTooltipToElement(obj, tooltipText, font);
}
}
private static void AddTooltipToElement(GameObject obj, string text, TMP_FontAsset font)
{
try
{
if ((Object)(object)obj.GetComponent("TooltipTrigger") == (Object)null)
{
GameObject val = GameObject.Find("UISettingToggle");
if ((Object)(object)val != (Object)null)
{
Component component = val.GetComponent("TooltipTrigger");
if ((Object)(object)component != (Object)null)
{
Component val2 = obj.AddComponent(((object)component).GetType());
FieldInfo field = ((object)val2).GetType().GetField("tooltipText", BindingFlags.Instance | BindingFlags.Public);
if (field != null)
{
field.SetValue(val2, text);
}
return;
}
}
}
TooltipTrigger tooltipTrigger = obj.GetComponent<TooltipTrigger>();
if ((Object)(object)tooltipTrigger == (Object)null)
{
tooltipTrigger = obj.AddComponent<TooltipTrigger>();
}
tooltipTrigger.tooltipText = text;
tooltipTrigger.font = font;
Image component2 = obj.GetComponent<Image>();
if ((Object)(object)component2 != (Object)null)
{
((Graphic)component2).raycastTarget = true;
}
}
catch (Exception ex)
{
GraphicsEnhancerMod.Log("Tooltip error: " + ex.Message);
}
}
private static void CreateToggle(GameObject template, Transform parent, string name, string label, UnityAction<bool> callback, bool initialValue, TMP_FontAsset font, string tooltip = "")
{
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
Transform val2 = parent.Find(name);
if ((Object)(object)val2 != (Object)null)
{
Object.DestroyImmediate((Object)(object)((Component)val2).gameObject);
}
GameObject val3 = Object.Instantiate<GameObject>(template, parent);
((Object)val3).name = name;
val3.SetActive(true);
UISettingToggle toggle = val3.GetComponent<UISettingToggle>();
if ((Object)(object)toggle != (Object)null)
{
SetLabel(val3, label, font, tooltip);
LocalisedTMP componentInChildren = val3.GetComponentInChildren<LocalisedTMP>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
Object.DestroyImmediate((Object)(object)componentInChildren);
}
((UnityEventBase)((UISettingElement<bool>)(object)toggle).OnSettingChanged).RemoveAllListeners();
((UISettingElement<bool>)(object)toggle).OnSettingChanged.AddListener((UnityAction<bool>)delegate(bool val)
{
GraphicsEnhancerMod.Log($"Toggle '{label}' changed to: {val}");
callback.Invoke(val);
((UISettingElement<bool>)(object)toggle).DisplayValue(val);
});
((UISettingElement<bool>)(object)toggle).SetValueNoNotify(initialValue);
((UISettingElement<bool>)(object)toggle).DisplayValue(initialValue);
}
val3.transform.localScale = Vector3.one;
}
private static void CreateDropdown(GameObject template, Transform parent, string name, string label, List<string> options, UnityAction<int> callback, int initialValue, TMP_FontAsset font, string tooltip = "")
{
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
Transform val2 = parent.Find(name);
if ((Object)(object)val2 != (Object)null)
{
Object.DestroyImmediate((Object)(object)((Component)val2).gameObject);
}
GameObject val3 = Object.Instantiate<GameObject>(template, parent);
((Object)val3).name = name;
val3.SetActive(true);
UISettingDropdown component = val3.GetComponent<UISettingDropdown>();
if ((Object)(object)component != (Object)null)
{
SetLabel(val3, label, font, tooltip);
LocalisedTMP componentInChildren = val3.GetComponentInChildren<LocalisedTMP>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
Object.DestroyImmediate((Object)(object)componentInChildren);
}
component.PopulateOptions(options);
((UnityEventBase)((UISettingElement<int>)(object)component).OnSettingChanged).RemoveAllListeners();
((UISettingElement<int>)(object)component).OnSettingChanged.AddListener((UnityAction<int>)delegate(int val)
{
GraphicsEnhancerMod.Log($"Dropdown '{label}' changed to index: {val}");
callback.Invoke(val);
});
((UISettingElement<int>)(object)component).SetValueNoNotify(initialValue);
((UISettingElement<int>)(object)component).DisplayValue(initialValue);
TMP_Dropdown componentInChildren2 = ((Component)component).GetComponentInChildren<TMP_Dropdown>(true);
if ((Object)(object)componentInChildren2 != (Object)null && (Object)(object)font != (Object)null)
{
if ((Object)(object)componentInChildren2.captionText != (Object)null)
{
componentInChildren2.captionText.font = font;
}
if ((Object)(object)componentInChildren2.itemText != (Object)null)
{
componentInChildren2.itemText.font = font;
}
if ((Object)(object)componentInChildren2.template != (Object)null)
{
TMP_Text[] componentsInChildren = ((Component)componentInChildren2.template).GetComponentsInChildren<TMP_Text>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
componentsInChildren[i].font = font;
}
}
}
}
val3.transform.localScale = Vector3.one;
}
private static Transform FindChildRecursive(Transform parent, string name)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Expected O, but got Unknown
foreach (Transform item in parent)
{
Transform val = item;
if (((Object)val).name == name)
{
return val;
}
Transform val2 = FindChildRecursive(val, name);
if ((Object)(object)val2 != (Object)null)
{
return val2;
}
}
return null;
}
private static string GetGameObjectPath(Transform t)
{
string text = ((Object)t).name;
while ((Object)(object)t.parent != (Object)null)
{
t = t.parent;
text = ((Object)t).name + "/" + text;
}
return text;
}
}