using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HorizonBasedAmbientOcclusion.Universal;
using Microsoft.CodeAnalysis;
using Peak;
using Peak.Island;
using PeakOptimizer.Configuration;
using PeakOptimizer.Patches;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.SceneManagement;
using Zorro.Core;
using Zorro.Core.Compute;
using Zorro.Settings;
[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("PeakOptimizer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PeakOptimizer")]
[assembly: AssemblyTitle("PeakOptimizer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[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;
}
}
}
namespace PeakOptimizer
{
[BepInPlugin("com.reis637.reisoptimizer", "ReisOptimizer", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "com.reis637.reisoptimizer";
public const string PluginName = "ReisOptimizer";
public const string PluginVersion = "1.0.0";
private Harmony? _harmony;
internal static ManualLogSource Logger { get; private set; }
private void Awake()
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
OptimizationConfig.Initialize(((BaseUnityPlugin)this).Config);
if (!OptimizationConfig.MasterEnabled.Value)
{
Logger.LogInfo((object)"ReisOptimizer is disabled in configuration.");
return;
}
if (OptimizationConfig.SuppressRepetitiveHotpathLogs.Value)
{
Application.SetStackTraceLogType((LogType)3, (StackTraceLogType)0);
Application.SetStackTraceLogType((LogType)2, (StackTraceLogType)0);
}
try
{
_harmony = new Harmony("com.reis637.reisoptimizer");
_harmony.PatchAll();
ShadowOptimizationPatch.Initialize();
TerrainAndScalingOptimizationPatch.Initialize();
GPUInstancingBatchingPatch.Initialize();
SmallRockCullingPatch.Initialize();
Logger.LogInfo((object)"ReisOptimizer v1.0.0 loaded successfully.");
}
catch (Exception arg)
{
Logger.LogError((object)string.Format("Failed to apply Harmony patches for {0}: {1}", "ReisOptimizer", arg));
}
}
private void OnDestroy()
{
Harmony? harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
}
namespace PeakOptimizer.Patches
{
[HarmonyPatch(typeof(Bot))]
public static class BotSearchPatch
{
[HarmonyPatch("LookForPlayerHead")]
[HarmonyPrefix]
public static bool LookForPlayerHead_Prefix(Bot __instance, Vector3 searcherHeadPos, float maxRange, float maxAngle, ref Vector3 ___lookDirection, ref Rigidbody? __result)
{
//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)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeBotPlayerSearch.Value)
{
return true;
}
List<Character> allCharacters = Character.AllCharacters;
if (allCharacters == null || allCharacters.Count == 0)
{
__result = null;
return false;
}
Vector3 center = __instance.Center;
Vector3 val = ___lookDirection;
for (int i = 0; i < allCharacters.Count; i++)
{
Character val2 = allCharacters[i];
if ((Object)(object)val2 == (Object)null || val2.isBot || val2.refs == null || (Object)(object)val2.refs.ragdoll == (Object)null || val2.refs.ragdoll.partDict == null || !val2.refs.ragdoll.partDict.TryGetValue((BodypartType)2, out var value) || (Object)(object)value == (Object)null || (Object)(object)value.Rig == (Object)null)
{
continue;
}
Vector3 position = value.Rig.position;
if (!(Vector3.Distance(center, position) > maxRange) && !(Vector3.Angle(position - center, val) > maxAngle) && val2.refs.ragdoll.partDict.TryGetValue((BodypartType)4, out var value2) && !((Object)(object)value2 == (Object)null) && !((Object)(object)value2.Rig == (Object)null))
{
Vector3 position2 = value2.Rig.position;
RaycastHit val3 = HelperFunctions.LineCheck(searcherHeadPos, position2, (LayerType)1, 0f, (QueryTriggerInteraction)1);
if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref val3)).transform))
{
__result = value2.Rig;
return false;
}
}
}
__result = null;
return false;
}
}
[HarmonyPatch(typeof(CharacterItems))]
public static class CharacterItemsSafetyPatch
{
[HarmonyPatch("UpdatePocketBehaviors")]
[HarmonyPrefix]
public static bool UpdatePocketBehaviors_Prefix(Character ___character)
{
if ((Object)(object)___character == (Object)null || (Object)(object)___character.player == (Object)null || ___character.player.itemSlots == null)
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(SwingingAxe))]
public static class CitadelTrapsOptimizationPatch
{
[HarmonyPatch("Update")]
[HarmonyPrefix]
public static bool Update_Prefix(SwingingAxe __instance)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeCitadelTraps.Value)
{
return true;
}
if ((Object)(object)MainCamera.instance == (Object)null)
{
return true;
}
float value = OptimizationConfig.CitadelTrapMaxDistance.Value;
float num = value * value;
Vector3 position = ((Component)MainCamera.instance).transform.position;
Vector3 position2 = ((Component)__instance).transform.position;
Vector3 val = position - position2;
if (((Vector3)(ref val)).sqrMagnitude > num)
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(DynamicBone))]
public static class DynamicBoneOptimizerPatch
{
private const float NearDistanceThresholdMeters = 15f;
private const float MaxDistanceThresholdMeters = 35f;
private const float OptimizedFoliageUpdateRateHz = 30f;
[HarmonyPatch("UpdateDynamicBones")]
[HarmonyPrefix]
public static bool UpdateDynamicBones_Prefix(DynamicBone __instance)
{
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.CullDistantDynamicBones.Value)
{
return true;
}
if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.m_Root == (Object)null)
{
return true;
}
if ((Object)(object)MainCamera.instance == (Object)null)
{
return true;
}
if (__instance.m_UpdateRate > 30f)
{
__instance.m_UpdateRate = 30f;
}
float value = OptimizationConfig.DynamicBoneMaxDistance.Value;
float num = value * value;
Vector3 position = ((Component)MainCamera.instance).transform.position;
Vector3 position2 = ((Component)__instance).transform.position;
Vector3 val = position - position2;
if (((Vector3)(ref val)).sqrMagnitude > num)
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Fog))]
public static class FogPerformancePatch
{
private const float SkeletonInjuryDivisor = 8f;
[HarmonyPatch("MakePlayerCold")]
[HarmonyPrefix]
public static bool MakePlayerCold_Prefix(Fog __instance)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeFogUpdates.Value)
{
return true;
}
Character localCharacter = Character.localCharacter;
if ((Object)(object)localCharacter == (Object)null)
{
return false;
}
if (!(localCharacter.Center.y < ((Component)__instance).transform.position.y))
{
return false;
}
if (localCharacter.data.isSkeleton)
{
float num = __instance.amount / 8f * Time.deltaTime;
localCharacter.refs.afflictions.AddStatus((STATUSTYPE)0, num, false, true, true);
}
else
{
float num2 = __instance.amount * Time.deltaTime;
localCharacter.refs.afflictions.AddStatus((STATUSTYPE)2, num2, false, true, true);
}
return false;
}
}
[HarmonyPatch]
public static class GloomOptimizationPatch
{
private const float MaxPerchSearchRadiusMeters = 140f;
private const float MaxPerchSearchRadiusSqr = 19600f;
[HarmonyPatch(typeof(GloomVoiceConfuser), "AllScoutsFoundEachOther")]
[HarmonyPrefix]
public static bool AllScoutsFoundEachOther_Prefix(GloomVoiceConfuser __instance, List<Character> allScouts, StatusFieldGloom ___fogField, ref bool __result)
{
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeGloomCalculations.Value)
{
return true;
}
if (allScouts == null || allScouts.Count < 2 || (Object)(object)___fogField == (Object)null)
{
__result = true;
return false;
}
float inFogSightDistance = ___fogField.InFogSightDistance;
float num = inFogSightDistance * inFogSightDistance;
int count = allScouts.Count;
for (int i = 0; i < count - 1; i++)
{
Character val = allScouts[i];
if ((Object)(object)val == (Object)null)
{
continue;
}
Vector3 center = val.Center;
for (int j = i + 1; j < count; j++)
{
Character val2 = allScouts[j];
if (!((Object)(object)val2 == (Object)null))
{
Vector3 val3 = center - val2.Center;
if (((Vector3)(ref val3)).sqrMagnitude > num)
{
__result = false;
return false;
}
}
}
}
__result = true;
return false;
}
[HarmonyPatch(typeof(GloomVoiceConfuser), "TryFindBestPerch")]
[HarmonyPrefix]
public static bool TryFindBestPerch_Prefix(GloomVoiceConfuser __instance, List<Character> allScouts, Character lostScout, RavenPerch[] ____validPerches, StatusFieldGloom ___fogField, float ___idealPerchDistance, ref RavenPerch? bestPerch, ref bool __result)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: 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_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeGloomCalculations.Value)
{
return true;
}
bestPerch = null;
if (____validPerches == null || ____validPerches.Length == 0 || (Object)(object)lostScout == (Object)null || allScouts == null || (Object)(object)___fogField == (Object)null)
{
__result = false;
return false;
}
float num = float.MaxValue;
Vector3 center = lostScout.Center;
foreach (RavenPerch val in ____validPerches)
{
if ((Object)(object)val == (Object)null || !val.CanSpawnVoiceStealRavens || (val.IsOccupied && (Object)(object)val.PerchedRaven != (Object)null && val.PerchedRaven.IsLeaving))
{
continue;
}
Vector3 position = ((Component)val).transform.position;
Vector3 val2 = position - center;
if (((Vector3)(ref val2)).sqrMagnitude > 19600f)
{
continue;
}
bool flag = false;
float num2 = 0f;
int num3 = 0;
for (int j = 0; j < allScouts.Count; j++)
{
Character val3 = allScouts[j];
if (!((Object)(object)val3 == (Object)null) && val3.data.fullyConscious && val3 != lostScout)
{
if (!val.IsOccupied && ___fogField.CharacterCanSeePoint(val3, position))
{
flag = true;
break;
}
num3++;
float num4 = Vector3.Distance(val3.Center, position);
num2 += Mathf.Abs(num4 - ___idealPerchDistance);
}
}
if (num3 != 0 && !flag)
{
float num5 = num2 / (float)num3;
if (num5 < num)
{
bestPerch = val;
num = num5;
}
}
}
__result = (Object)(object)bestPerch != (Object)null;
return false;
}
[HarmonyPatch(typeof(StatusFieldGloom), "CharacterCanSeePoint")]
[HarmonyPrefix]
public static bool CharacterCanSeePoint_Prefix(StatusFieldGloom __instance, Character seeker, Vector3 target, float ___sightDistanceThreshold, ref bool __result)
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeGloomCalculations.Value)
{
return true;
}
if ((Object)(object)seeker == (Object)null || seeker.data.dead || seeker.data.fullyPassedOut)
{
__result = false;
return false;
}
Vector3 val = ((Character.localCharacter == seeker && (Object)(object)MainCamera.instance != (Object)null) ? ((Component)MainCamera.instance).transform.position : seeker.Center);
float num = (((StatusFieldBounds)__instance).PointInField(val) ? ___sightDistanceThreshold : 300f);
Vector3 val2 = target - val;
if (((Vector3)(ref val2)).sqrMagnitude > num * num)
{
__result = false;
return false;
}
return true;
}
}
[HarmonyPatch]
public static class GPUInstancingBatchingPatch
{
private static readonly HashSet<int> s_processedMaterialIds = new HashSet<int>();
private static bool s_sceneHooked = false;
public static void Initialize()
{
if (!s_sceneHooked)
{
SceneManager.sceneLoaded += OnSceneLoaded;
s_sceneHooked = true;
}
BatchSceneMaterials();
}
private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
s_processedMaterialIds.Clear();
BatchSceneMaterials();
}
public static void BatchSceneMaterials()
{
if (OptimizationConfig.MasterEnabled.Value && OptimizationConfig.EnableGPUInstancingBatching.Value)
{
MeshRenderer[] array = Object.FindObjectsByType<MeshRenderer>((FindObjectsInactive)0, (FindObjectsSortMode)0);
for (int i = 0; i < array.Length; i++)
{
ProcessRenderer(array[i]);
}
}
}
public static void BatchMaterialsInHierarchy(GameObject root)
{
if (OptimizationConfig.MasterEnabled.Value && OptimizationConfig.EnableGPUInstancingBatching.Value && !((Object)(object)root == (Object)null))
{
MeshRenderer[] componentsInChildren = root.GetComponentsInChildren<MeshRenderer>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
ProcessRenderer(componentsInChildren[i]);
}
}
}
private static void ProcessRenderer(MeshRenderer rend)
{
if ((Object)(object)rend == (Object)null)
{
return;
}
Material[] sharedMaterials = ((Renderer)rend).sharedMaterials;
foreach (Material val in sharedMaterials)
{
if ((Object)(object)val != (Object)null && !s_processedMaterialIds.Contains(((Object)val).GetInstanceID()))
{
s_processedMaterialIds.Add(((Object)val).GetInstanceID());
if (!val.enableInstancing)
{
val.enableInstancing = true;
}
}
}
}
[HarmonyPatch(typeof(RockSpawner), "Go")]
[HarmonyPostfix]
public static void RockSpawner_Go_Postfix(RockSpawner __instance)
{
if ((Object)(object)__instance != (Object)null)
{
BatchMaterialsInHierarchy(((Component)__instance).gameObject);
}
}
[HarmonyPatch(typeof(DecorSpawner), "ExecuteImmediately")]
[HarmonyPostfix]
public static void DecorSpawner_ExecuteImmediately_Postfix(DecorSpawner __instance)
{
if ((Object)(object)__instance != (Object)null)
{
BatchMaterialsInHierarchy(((Component)__instance).gameObject);
}
}
}
[HarmonyPatch(typeof(GrassChunking))]
public static class GrassFrustumOptimizationPatch
{
private static Plane[] s_cameraPlanes = (Plane[])(object)new Plane[6];
private static int s_lastPlaneFrame = -1;
private static readonly Vector3 s_chunkSizeVector = new Vector3(GrassChunking.CHUNK_SIZE, GrassChunking.CHUNK_SIZE, GrassChunking.CHUNK_SIZE);
[HarmonyPatch("ShouldDrawChunk")]
[HarmonyPrefix]
public static bool ShouldDrawChunk_Prefix(int3 cameraChunk, int3 renderChunk, ref bool __result)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeGrassFrustumCulling.Value)
{
return true;
}
if (Mathf.Abs(cameraChunk.x - renderChunk.x) > 1 || Mathf.Abs(cameraChunk.y - renderChunk.y) > 1 || Mathf.Abs(cameraChunk.z - renderChunk.z) > 1)
{
__result = false;
return false;
}
Camera val = Camera.main;
if ((Object)(object)val == (Object)null && (Object)(object)MainCamera.instance != (Object)null)
{
val = ((Component)MainCamera.instance).GetComponent<Camera>();
}
if ((Object)(object)val == (Object)null)
{
__result = true;
return false;
}
int frameCount = Time.frameCount;
if (s_lastPlaneFrame != frameCount)
{
GeometryUtility.CalculateFrustumPlanes(val, s_cameraPlanes);
s_lastPlaneFrame = frameCount;
}
Vector3 val2 = default(Vector3);
((Vector3)(ref val2))..ctor(((float)renderChunk.x + 0.5f) * GrassChunking.CHUNK_SIZE, ((float)renderChunk.y + 0.5f) * GrassChunking.CHUNK_SIZE, ((float)renderChunk.z + 0.5f) * GrassChunking.CHUNK_SIZE);
Bounds val3 = default(Bounds);
((Bounds)(ref val3))..ctor(val2, s_chunkSizeVector);
if (!GeometryUtility.TestPlanesAABB(s_cameraPlanes, val3))
{
__result = false;
return false;
}
__result = true;
return false;
}
}
[HarmonyPatch(typeof(GrassRenderer))]
public static class GrassRendererPatch
{
private static readonly MaterialPropertyBlock SharedPropertyBlock = new MaterialPropertyBlock();
private static readonly int GeometryBufferPropId = Shader.PropertyToID("GeometryBuffer");
private static readonly int TimePropId = Shader.PropertyToID("_Time");
private static readonly int CameraWSPosPropId = Shader.PropertyToID("_CameraWSPos");
private const int MaxGrassCount = 10000;
private const int DrawStride = 148;
private const int IndirectDrawArgsStride = 16;
private const float BoundsExtentMeters = 500f;
[HarmonyPatch("Render")]
[HarmonyPrefix]
public static bool Render_Prefix(GrassRenderer __instance, ref GrassDataProvider ___DataProvider, ref ComputeBuffer ___GrassPointsBuffer, ref ComputeBuffer ___GeometryBuffer, ref ComputeBuffer ___ArgumentsBuffer, ref ComputeKernel ___grassGeometryKernel, ref int[] ___argsBufferReset)
{
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Expected O, but got Unknown
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Expected O, but got Unknown
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.CacheMaterialPropertyBlocks.Value)
{
return true;
}
if (!Object.op_Implicit((Object)(object)___DataProvider))
{
___DataProvider = ((Component)__instance).GetComponent<GrassDataProvider>();
}
if ((Object)(object)___DataProvider == (Object)null)
{
return false;
}
if (___GrassPointsBuffer == null || ___DataProvider.IsDirty())
{
ComputeBuffer obj = ___GrassPointsBuffer;
if (obj != null)
{
obj.Dispose();
}
___GrassPointsBuffer = ___DataProvider.GetData();
}
if (___GrassPointsBuffer == null || ___GrassPointsBuffer.count == 0)
{
return false;
}
if ((Object)(object)MainCamera.instance == (Object)null)
{
return false;
}
Vector3 position = ((Component)MainCamera.instance).transform.position;
if (GrassChunking.ShouldDrawChunk(GrassChunking.GetChunkFromPosition(float3.op_Implicit(position)), __instance.CurrentChunk))
{
if (___GeometryBuffer == null)
{
___GeometryBuffer = new ComputeBuffer(10000, 148, (ComputeBufferType)2);
___ArgumentsBuffer = new ComputeBuffer(1, 16, (ComputeBufferType)256);
}
___GeometryBuffer.SetCounterValue(0u);
___ArgumentsBuffer.SetData((Array)___argsBufferReset);
int kernelID = ___grassGeometryKernel.kernelID;
ComputeShader grassComputeShader = __instance.grassComputeShader;
if ((Object)(object)grassComputeShader == (Object)null)
{
return false;
}
grassComputeShader.SetBuffer(kernelID, "GeometryBuffer", ___GeometryBuffer);
grassComputeShader.SetBuffer(kernelID, "IndirectArgsBuffer", ___ArgumentsBuffer);
grassComputeShader.SetBuffer(kernelID, "GrassPoints", ___GrassPointsBuffer);
grassComputeShader.SetFloat(TimePropId, Time.realtimeSinceStartup);
grassComputeShader.SetVector(CameraWSPosPropId, Vector4.op_Implicit(position));
SharedPropertyBlock.Clear();
SharedPropertyBlock.SetBuffer(GeometryBufferPropId, ___GeometryBuffer);
___grassGeometryKernel.Dispatch(new int3(___GrassPointsBuffer.count, 1, 1));
Bounds val = default(Bounds);
((Bounds)(ref val))..ctor(((Component)__instance).transform.position, Vector3.one * 500f);
Graphics.DrawProceduralIndirect(__instance.m_grassRenderMaterial, val, (MeshTopology)0, ___ArgumentsBuffer, 0, (Camera)null, SharedPropertyBlock, (ShadowCastingMode)0, true, 0);
}
return false;
}
}
[HarmonyPatch(typeof(PostHandler))]
public static class HBAOOptimizationPatch
{
private const float MaxAoDistanceMeters = 40f;
private const float AoDistanceFalloffMeters = 10f;
[HarmonyPatch("LateUpdate")]
[HarmonyPostfix]
public static void LateUpdate_Postfix(PostHandler __instance, Volume ___volume, AOSetting ___AOSetting)
{
HBAO val = default(HBAO);
if (OptimizationConfig.MasterEnabled.Value && OptimizationConfig.OptimizeHBAOPerformance.Value && !((Object)(object)___volume == (Object)null) && !((Object)(object)___volume.sharedProfile == (Object)null) && ___AOSetting != null && ___volume.sharedProfile.TryGet<HBAO>(ref val) && ((VolumeComponent)val).active)
{
val.SetAoMaxDistance(40f);
val.SetAoDistanceFalloff(10f);
val.SetResolution((Resolution)1);
val.SetQuality((Quality)1);
}
}
}
[HarmonyPatch(typeof(ParticleCountCuller))]
public static class ParticleCountCullerPatch
{
private const float MinAttenuationFactor = 0.2f;
private const float MaxAttenuationFactor = 1f;
[HarmonyPatch("Update")]
[HarmonyPrefix]
public static bool Update_Prefix(ParticleCountCuller __instance, ref ParticleSystem ___ps, ref float ___startVal)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.SafeguardParticleCuller.Value)
{
return true;
}
if ((Object)(object)___ps == (Object)null)
{
return false;
}
Character observedCharacter = Character.observedCharacter;
Vector3 val;
if ((Object)(object)observedCharacter != (Object)null)
{
val = observedCharacter.Head;
}
else
{
if (!((Object)(object)MainCamera.instance != (Object)null))
{
return false;
}
val = ((Component)MainCamera.instance).transform.position;
}
float num = Vector3.Distance(((Component)__instance).transform.position, val);
float num2 = Mathf.Max(0.001f, __instance.maxDistance);
float num3 = Mathf.Clamp01((num - __instance.minDistance) / num2);
__instance.attenuationVal = Mathf.Lerp(1f, 0.2f, num3);
EmissionModule emission = ___ps.emission;
((EmissionModule)(ref emission)).rateOverTimeMultiplier = __instance.attenuationVal * ___startVal;
return false;
}
}
[HarmonyPatch]
public static class ShadowOptimizationPatch
{
private const float LowShadowDistanceMeters = 35f;
private const float AntiAcneNormalBias = 1.35f;
private const float AntiAcneDepthBias = 0.85f;
private static bool s_sceneHooked;
public static void Initialize()
{
if (!s_sceneHooked)
{
SceneManager.sceneLoaded += OnSceneLoaded;
s_sceneHooked = true;
}
ApplyOptimizedShadows();
FixDirectionalLightShadowBiases();
FixAdditionalLights();
}
private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
ApplyOptimizedShadows();
FixDirectionalLightShadowBiases();
FixAdditionalLights();
}
public static void FixDirectionalLightShadowBiases()
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Invalid comparison between Unknown and I4
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeShadowDistances.Value)
{
return;
}
Light[] array = Object.FindObjectsByType<Light>((FindObjectsInactive)0, (FindObjectsSortMode)0);
foreach (Light val in array)
{
if ((Object)(object)val != (Object)null && (int)val.type == 1)
{
if (val.shadowNormalBias < 1.35f)
{
val.shadowNormalBias = 1.35f;
}
if (val.shadowBias < 0.85f)
{
val.shadowBias = 0.85f;
}
}
}
}
public static void FixAdditionalLights()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Invalid comparison between Unknown and I4
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeAdditionalLightShadows.Value || !OptimizationConfig.DisableAdditionalLightShadows.Value)
{
return;
}
Light[] array = Object.FindObjectsByType<Light>((FindObjectsInactive)0, (FindObjectsSortMode)0);
foreach (Light val in array)
{
if ((Object)(object)val != (Object)null && ((int)val.type == 2 || (int)val.type == 0) && (int)val.shadows != 0)
{
val.shadows = (LightShadows)0;
}
}
}
public static void ApplyOptimizedShadows()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Expected I4, but got Unknown
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeShadowDistances.Value)
{
return;
}
RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
UniversalRenderPipelineAsset val = (UniversalRenderPipelineAsset)(object)((currentRenderPipeline is UniversalRenderPipelineAsset) ? currentRenderPipeline : null);
if (val != null)
{
ShadowDistanceQuality val2 = (ShadowDistanceQuality)0;
if ((Object)(object)GameHandler.Instance != (Object)null && GameHandler.Instance.SettingsHandler != null)
{
ShadowDistanceSettings setting = GameHandler.Instance.SettingsHandler.GetSetting<ShadowDistanceSettings>();
if (setting != null)
{
val2 = ((EnumSetting<ShadowDistanceQuality>)(object)setting).Value;
}
}
switch ((int)val2)
{
case 0:
val.shadowDistance = OptimizationConfig.OptimizedShadowDistanceHigh.Value;
val.shadowCascadeCount = 2;
break;
case 1:
val.shadowDistance = OptimizationConfig.OptimizedShadowDistanceMedium.Value;
val.shadowCascadeCount = 2;
break;
case 2:
val.shadowDistance = 35f;
val.shadowCascadeCount = 2;
break;
case 3:
val.shadowDistance = 0f;
val.shadowCascadeCount = 1;
break;
}
}
if (OptimizationConfig.OptimizeLODScaling.Value)
{
QualitySettings.lodBias = 0.8f;
}
FixDirectionalLightShadowBiases();
FixAdditionalLights();
}
[HarmonyPatch(typeof(ShadowDistanceSettings), "ApplyValue")]
[HarmonyPrefix]
public static bool ApplyValue_Prefix(ShadowDistanceSettings __instance)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: 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_0048: Expected I4, but got Unknown
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeShadowDistances.Value)
{
return true;
}
RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
UniversalRenderPipelineAsset val = (UniversalRenderPipelineAsset)(object)((currentRenderPipeline is UniversalRenderPipelineAsset) ? currentRenderPipeline : null);
if (val != null)
{
ShadowDistanceQuality value = ((EnumSetting<ShadowDistanceQuality>)(object)__instance).Value;
switch ((int)value)
{
case 0:
val.shadowDistance = OptimizationConfig.OptimizedShadowDistanceHigh.Value;
val.shadowCascadeCount = 2;
break;
case 1:
val.shadowDistance = OptimizationConfig.OptimizedShadowDistanceMedium.Value;
val.shadowCascadeCount = 2;
break;
case 2:
val.shadowDistance = 35f;
val.shadowCascadeCount = 2;
break;
case 3:
val.shadowDistance = 0f;
val.shadowCascadeCount = 1;
break;
}
FixDirectionalLightShadowBiases();
FixAdditionalLights();
return false;
}
return true;
}
[HarmonyPatch(typeof(LodQuality), "ApplyValue")]
[HarmonyPrefix]
public static bool ApplyLod_Prefix(LodQuality __instance)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Invalid comparison between Unknown and I4
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Invalid comparison between Unknown and I4
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeLODScaling.Value)
{
return true;
}
Quality value = ((EnumSetting<Quality>)(object)__instance).Value;
float lodBias = (((int)value == 1) ? 0.7f : (((int)value != 2) ? 0.55f : 0.85f));
QualitySettings.lodBias = lodBias;
return false;
}
[HarmonyPatch(typeof(DayNightManager), "Start")]
[HarmonyPostfix]
public static void DayNightManager_Start_Postfix()
{
FixDirectionalLightShadowBiases();
FixAdditionalLights();
}
}
[HarmonyPatch]
public static class SmallRockCullingPatch
{
private class RockEntry
{
public MeshRenderer Renderer;
public Vector3 Position;
public bool IsVisible;
public RockEntry(MeshRenderer renderer, Vector3 position)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
Renderer = renderer;
Position = position;
IsVisible = true;
}
}
private const float MaxExtentsSqrMagnitude = 2.25f;
private const int RocksPerFrameBatch = 40;
private static readonly List<RockEntry> s_rocks = new List<RockEntry>(1024);
private static readonly HashSet<int> s_registeredIds = new HashSet<int>();
private static int s_processIndex = 0;
private static bool s_hooked = false;
public static void Initialize()
{
if (!s_hooked)
{
SceneManager.sceneLoaded += OnSceneLoaded;
s_hooked = true;
}
}
private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
ClearAndRestore();
}
public static void ClearAndRestore()
{
for (int i = 0; i < s_rocks.Count; i++)
{
RockEntry rockEntry = s_rocks[i];
if (rockEntry != null && (Object)(object)rockEntry.Renderer != (Object)null)
{
((Renderer)rockEntry.Renderer).enabled = true;
}
}
s_rocks.Clear();
s_registeredIds.Clear();
s_processIndex = 0;
}
public static void RegisterSpawnerChildren(GameObject spawnerRoot)
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)spawnerRoot == (Object)null || !OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeSmallRockDecorations.Value)
{
return;
}
MeshRenderer[] componentsInChildren = spawnerRoot.GetComponentsInChildren<MeshRenderer>(true);
foreach (MeshRenderer val in componentsInChildren)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
int instanceID = ((Object)val).GetInstanceID();
if (s_registeredIds.Contains(instanceID))
{
continue;
}
Bounds bounds = ((Renderer)val).bounds;
Vector3 extents = ((Bounds)(ref bounds)).extents;
if (((Vector3)(ref extents)).sqrMagnitude <= 2.25f)
{
int layer = ((Component)val).gameObject.layer;
if (layer == 0 || layer == LayerMask.NameToLayer("Terrain"))
{
s_registeredIds.Add(instanceID);
s_rocks.Add(new RockEntry(val, ((Component)val).transform.position));
}
}
}
}
[HarmonyPatch(typeof(RockSpawner), "Go")]
[HarmonyPostfix]
public static void RockSpawner_Go_Postfix(RockSpawner __instance)
{
if ((Object)(object)__instance != (Object)null)
{
RegisterSpawnerChildren(((Component)__instance).gameObject);
}
}
[HarmonyPatch(typeof(DecorSpawner), "ExecuteImmediately")]
[HarmonyPostfix]
public static void DecorSpawner_ExecuteImmediately_Postfix(DecorSpawner __instance)
{
if ((Object)(object)__instance != (Object)null)
{
RegisterSpawnerChildren(((Component)__instance).gameObject);
}
}
[HarmonyPatch(typeof(MainCamera), "LateUpdate")]
[HarmonyPostfix]
public static void MainCamera_LateUpdate_Postfix(MainCamera __instance)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: 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_0139: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeSmallRockDecorations.Value)
{
return;
}
int count = s_rocks.Count;
if (count == 0 || (Object)(object)__instance == (Object)null)
{
return;
}
Vector3 position = ((Component)__instance).transform.position;
float value = OptimizationConfig.SmallRockCullDistance.Value;
float num = (value - 5f) * (value - 5f);
float num2 = (value + 5f) * (value + 5f);
int num3 = Mathf.Min(40, count);
for (int i = 0; i < num3; i++)
{
if (s_processIndex >= s_rocks.Count)
{
s_processIndex = 0;
}
if (s_rocks.Count == 0)
{
break;
}
RockEntry rockEntry = s_rocks[s_processIndex];
if (rockEntry == null || (Object)(object)rockEntry.Renderer == (Object)null)
{
int index = s_rocks.Count - 1;
s_rocks[s_processIndex] = s_rocks[index];
s_rocks.RemoveAt(index);
continue;
}
if (!((Component)rockEntry.Renderer).gameObject.activeInHierarchy)
{
s_processIndex++;
continue;
}
s_processIndex++;
Vector3 val = position - rockEntry.Position;
float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
if (rockEntry.IsVisible && sqrMagnitude > num2)
{
((Renderer)rockEntry.Renderer).enabled = false;
rockEntry.IsVisible = false;
}
else if (!rockEntry.IsVisible && sqrMagnitude < num)
{
((Renderer)rockEntry.Renderer).enabled = true;
rockEntry.IsVisible = true;
}
}
}
}
[HarmonyPatch]
public static class TerrainAndScalingOptimizationPatch
{
private static bool s_sceneHooked;
public static void Initialize()
{
if (!s_sceneHooked)
{
SceneManager.sceneLoaded += OnSceneLoaded;
s_sceneHooked = true;
}
ApplyRenderingOptimizations();
}
private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
ApplyRenderingOptimizations();
}
public static void ApplyRenderingOptimizations()
{
if (OptimizationConfig.MasterEnabled.Value)
{
if (OptimizationConfig.OptimizeAnisotropicFiltering.Value)
{
QualitySettings.anisotropicFiltering = (AnisotropicFiltering)2;
Texture.SetGlobalAnisotropicFilteringLimits(1, OptimizationConfig.OptimizedAnisotropicLevel.Value);
}
if (OptimizationConfig.OptimizeLODScaling.Value)
{
QualitySettings.lodBias = OptimizationConfig.OptimizedLodBias.Value;
}
}
}
}
[HarmonyPatch(typeof(VoiceObscuranceFilter))]
public static class VoiceObscurancePatch
{
private class FilterState
{
public float NextCheckTime;
public bool IsObstructed;
public float ReverbAlpha;
public bool IsDistant;
}
private static readonly ConditionalWeakTable<VoiceObscuranceFilter, FilterState> StateCache = new ConditionalWeakTable<VoiceObscuranceFilter, FilterState>();
private const float ObstructedCutoff = 1500f;
private const float ClearCutoff = 7500f;
private const float DistanceThresholdMeters = 60f;
[HarmonyPatch("Update")]
[HarmonyPrefix]
public static bool Update_Prefix(VoiceObscuranceFilter __instance, ref bool ____isCharacterVoice, ref CharacterVoiceHandler ____voiceHandler, ref Animator ___anim, ref float ___obstructionMinimum, ref float ___muffleCutoff, ref float ___muffleResonance, ref float ___stolenVoiceCutoff)
{
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeVoiceObscurance.Value)
{
return true;
}
if ((Object)(object)__instance.head == (Object)null)
{
if ((Object)(object)MainCamera.instance != (Object)null)
{
__instance.head = ((Component)MainCamera.instance).transform;
}
if ((Object)(object)__instance.head == (Object)null)
{
return false;
}
}
FilterState orCreateValue = StateCache.GetOrCreateValue(__instance);
float time = Time.time;
if (time >= orCreateValue.NextCheckTime)
{
float num = Mathf.Max(0.02f, OptimizationConfig.VoiceUpdateIntervalSeconds.Value);
orCreateValue.NextCheckTime = time + num;
Vector3 position = ((Component)__instance).transform.position;
Vector3 position2 = __instance.head.position;
orCreateValue.IsObstructed = Physics.Linecast(position, position2, LayerMask.op_Implicit(__instance.layer));
LightVolume val = LightVolume.Instance();
if ((Object)(object)val != (Object)null)
{
orCreateValue.ReverbAlpha = math.saturate(val.SamplePositionAlpha(position, false));
}
orCreateValue.IsDistant = Vector3.Distance(position, position2) > 60f;
}
__instance.reverbAddition = Mathf.Clamp(orCreateValue.ReverbAlpha, ___obstructionMinimum, __instance.maxReverb);
if (____isCharacterVoice && (Object)(object)____voiceHandler != (Object)null)
{
if ((Object)(object)Singleton<PeakHandler>.Instance != (Object)null && Singleton<PeakHandler>.Instance.isPlayingCinematic)
{
((Behaviour)__instance.highPass).enabled = false;
((Behaviour)__instance.lowPass).enabled = false;
((Behaviour)__instance.reverb).enabled = false;
((Behaviour)__instance.echo).enabled = false;
return false;
}
float num2 = (____voiceHandler.IsStolen ? ___stolenVoiceCutoff : 10f);
__instance.highPass.cutoffFrequency = Mathf.Lerp(__instance.highPass.cutoffFrequency, num2, 1f * Time.deltaTime);
__instance.lowPass.lowpassResonanceQ = (____voiceHandler.IsMuffled ? ___muffleResonance : 1f);
if (____voiceHandler.IsMuffled)
{
__instance.lowPass.cutoffFrequency = Mathf.Lerp(__instance.lowPass.cutoffFrequency, ___muffleCutoff, 750f * Time.deltaTime);
}
else
{
float num3 = (orCreateValue.IsObstructed ? 1500f : 7500f);
__instance.lowPass.cutoffFrequency = Mathf.Lerp(__instance.lowPass.cutoffFrequency, num3, 1f * Time.deltaTime);
}
}
else
{
float num4 = (orCreateValue.IsObstructed ? 1500f : 7500f);
__instance.lowPass.cutoffFrequency = Mathf.Lerp(__instance.lowPass.cutoffFrequency, num4, 1f * Time.deltaTime);
}
if (orCreateValue.IsDistant)
{
if ((Object)(object)___anim != (Object)null)
{
___anim.SetFloat("Obscurance", 1f, Time.deltaTime, 0.5f);
}
__instance.echo.wetMix = Mathf.Lerp(__instance.echo.wetMix, 0.35f, 5f * Time.deltaTime);
__instance.echo.dryMix = Mathf.Lerp(__instance.echo.dryMix, 0.5f, 5f * Time.deltaTime);
__instance.echo.decayRatio = Mathf.Lerp(__instance.echo.decayRatio, 0.3f, 5f * Time.deltaTime);
__instance.echo.delay = Mathf.Lerp(__instance.echo.delay, 500f, 5f * Time.deltaTime);
}
else
{
if ((Object)(object)___anim != (Object)null)
{
___anim.SetFloat("Obscurance", __instance.reverbAddition);
}
__instance.echo.wetMix = Mathf.Lerp(__instance.echo.wetMix, 0f, 1f * Time.deltaTime);
__instance.echo.dryMix = Mathf.Lerp(__instance.echo.dryMix, 1f, 1f * Time.deltaTime);
__instance.echo.decayRatio = Mathf.Lerp(__instance.echo.decayRatio, 0f, 1f * Time.deltaTime);
__instance.echo.delay = Mathf.Lerp(__instance.echo.delay, 10f, 1f * Time.deltaTime);
}
return false;
}
}
}
namespace PeakOptimizer.Configuration
{
public static class OptimizationConfig
{
public static ConfigEntry<bool> MasterEnabled { get; private set; }
public static ConfigEntry<bool> OptimizeFogUpdates { get; private set; }
public static ConfigEntry<bool> OptimizeVoiceObscurance { get; private set; }
public static ConfigEntry<float> VoiceUpdateIntervalSeconds { get; private set; }
public static ConfigEntry<bool> OptimizeBotPlayerSearch { get; private set; }
public static ConfigEntry<bool> CacheMaterialPropertyBlocks { get; private set; }
public static ConfigEntry<bool> SafeguardParticleCuller { get; private set; }
public static ConfigEntry<bool> CullDistantDynamicBones { get; private set; }
public static ConfigEntry<float> DynamicBoneMaxDistance { get; private set; }
public static ConfigEntry<bool> OptimizeShadowDistances { get; private set; }
public static ConfigEntry<float> OptimizedShadowDistanceHigh { get; private set; }
public static ConfigEntry<float> OptimizedShadowDistanceMedium { get; private set; }
public static ConfigEntry<bool> OptimizeGrassFrustumCulling { get; private set; }
public static ConfigEntry<bool> OptimizeLODScaling { get; private set; }
public static ConfigEntry<float> OptimizedLodBias { get; private set; }
public static ConfigEntry<bool> OptimizeHBAOPerformance { get; private set; }
public static ConfigEntry<bool> OptimizeAnisotropicFiltering { get; private set; }
public static ConfigEntry<int> OptimizedAnisotropicLevel { get; private set; }
public static ConfigEntry<bool> EnableGPUInstancingBatching { get; private set; }
public static ConfigEntry<bool> OptimizeSmallRockDecorations { get; private set; }
public static ConfigEntry<float> SmallRockCullDistance { get; private set; }
public static ConfigEntry<bool> OptimizeGloomCalculations { get; private set; }
public static ConfigEntry<bool> OptimizeCitadelTraps { get; private set; }
public static ConfigEntry<float> CitadelTrapMaxDistance { get; private set; }
public static ConfigEntry<bool> OptimizeAdditionalLightShadows { get; private set; }
public static ConfigEntry<bool> DisableAdditionalLightShadows { get; private set; }
public static ConfigEntry<bool> SuppressRepetitiveHotpathLogs { get; private set; }
public static void Initialize(ConfigFile config)
{
MasterEnabled = config.Bind<bool>("1. General", "MasterEnabled", true, "Global toggle for PeakOptimizer.");
OptimizeFogUpdates = config.Bind<bool>("2. Fog & Environment", "OptimizeFogUpdates", true, "Removes console spam and allocations in fog zones while keeping exact gameplay values.");
OptimizeVoiceObscurance = config.Bind<bool>("3. Voice Chat & Audio", "OptimizeVoiceObscurance", true, "Limits voice chat occlusion raycasts to a fixed interval.");
VoiceUpdateIntervalSeconds = config.Bind<float>("3. Voice Chat & Audio", "VoiceUpdateIntervalSeconds", 0.1f, "Interval in seconds between voice obstruction checks (0.1 = 10 updates per second).");
OptimizeBotPlayerSearch = config.Bind<bool>("4. AI & Entity Search", "OptimizeBotPlayerSearch", true, "Replaces scene-wide player scans with cached character lists for helper bots.");
CacheMaterialPropertyBlocks = config.Bind<bool>("5. Rendering & GPU", "CacheMaterialPropertyBlocks", true, "Reuses MaterialPropertyBlock instances in grass rendering to avoid heap allocations.");
SafeguardParticleCuller = config.Bind<bool>("5. Rendering & GPU", "SafeguardParticleCuller", true, "Prevents null references and throttles distance checks in particle attenuation.");
CullDistantDynamicBones = config.Bind<bool>("5. Rendering & GPU", "CullDistantDynamicBones", true, "Skips bone physics simulation on distant foliage.");
DynamicBoneMaxDistance = config.Bind<float>("5. Rendering & GPU", "DynamicBoneMaxDistance", 45f, "Distance in meters at which bone physics are simulated.");
OptimizeShadowDistances = config.Bind<bool>("5. Rendering & GPU", "OptimizeShadowDistances", true, "Reduces distant shadow render distances while keeping close-range shadows crisp.");
OptimizedShadowDistanceHigh = config.Bind<float>("5. Rendering & GPU", "OptimizedShadowDistanceHigh", 70f, "Shadow distance in meters when in-game shadow setting is set to High.");
OptimizedShadowDistanceMedium = config.Bind<float>("5. Rendering & GPU", "OptimizedShadowDistanceMedium", 55f, "Shadow distance in meters when in-game shadow setting is set to Medium.");
OptimizeGrassFrustumCulling = config.Bind<bool>("5. Rendering & GPU", "OptimizeGrassFrustumCulling", true, "Skips grass generation for chunks outside the camera view.");
OptimizeLODScaling = config.Bind<bool>("5. Rendering & GPU", "OptimizeLODScaling", true, "Adjusts LOD bias so distant terrain switches to lower detail meshes smoothly.");
OptimizedLodBias = config.Bind<float>("5. Rendering & GPU", "OptimizedLodBias", 0.65f, "LOD bias scaling factor.");
OptimizeHBAOPerformance = config.Bind<bool>("5. Rendering & GPU", "OptimizeHBAOPerformance", true, "Optimizes ambient occlusion settings for smoother frame times.");
OptimizeAnisotropicFiltering = config.Bind<bool>("5. Rendering & GPU", "OptimizeAnisotropicFiltering", true, "Limits global anisotropic filtering to prevent memory bandwidth bottlenecks.");
OptimizedAnisotropicLevel = config.Bind<int>("5. Rendering & GPU", "OptimizedAnisotropicLevel", 4, "Target maximum anisotropic filtering level (4x).");
EnableGPUInstancingBatching = config.Bind<bool>("5. Rendering & GPU", "EnableGPUInstancingBatching", true, "Enables GPU instancing across identical rock and prop materials.");
OptimizeSmallRockDecorations = config.Bind<bool>("5. Rendering & GPU", "OptimizeSmallRockDecorations", true, "Culls tiny decorative pebbles beyond effective visibility range.");
SmallRockCullDistance = config.Bind<float>("5. Rendering & GPU", "SmallRockCullDistance", 50f, "Distance in meters at which decorative pebbles are rendered.");
OptimizeGloomCalculations = config.Bind<bool>("6. Gloom & Citadel", "OptimizeGloomCalculations", true, "Optimizes raven voice-stealing searches and distance checks in Gloom.");
OptimizeCitadelTraps = config.Bind<bool>("6. Gloom & Citadel", "OptimizeCitadelTraps", true, "Suspends physics checks for swinging traps located far away from the player.");
CitadelTrapMaxDistance = config.Bind<float>("6. Gloom & Citadel", "CitadelTrapMaxDistance", 45f, "Distance in meters at which Citadel traps actively compute physics.");
OptimizeAdditionalLightShadows = config.Bind<bool>("6. Gloom & Citadel", "OptimizeAdditionalLightShadows", true, "Optimizes torch and point lights in the Citadel to eliminate excess shadow passes.");
DisableAdditionalLightShadows = config.Bind<bool>("6. Gloom & Citadel", "DisableAdditionalLightShadows", true, "Disables secondary point light shadows while keeping full light color and brightness.");
SuppressRepetitiveHotpathLogs = config.Bind<bool>("7. Logging", "SuppressRepetitiveHotpathLogs", true, "Disables stack trace capture on routine debug logs to prevent micro-stutters.");
}
}
}