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.Afflictions; using Peak.Island; using PeakOptimizer.Configuration; using PeakOptimizer.Core.Diagnostics; using PeakOptimizer.Core.Lighting; using PeakOptimizer.Core.Physics; using PeakOptimizer.Core.Rendering; using PeakOptimizer.Core.Spatial; using PeakOptimizer.Patches; using Photon.Pun; using Unity.Burst; using Unity.Collections; using Unity.Jobs; using Unity.Mathematics; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.SceneManagement; using Zorro.Core; using Zorro.Core.Compute; using Zorro.Settings; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("PeakOptimizer")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("2.1.1.0")] [assembly: AssemblyInformationalVersion("2.1.1")] [assembly: AssemblyProduct("PeakOptimizer")] [assembly: AssemblyTitle("PeakOptimizer")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("2.1.1.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.reis.peakoptimizer", "PeakOptimizer", "2.1.1")] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "com.reis.peakoptimizer"; public const string PluginName = "PeakOptimizer"; public const string PluginVersion = "2.1.1"; private Harmony? _harmony; internal static ManualLogSource Logger { get; private set; } private void Awake() { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown Logger = ((BaseUnityPlugin)this).Logger; OptimizationConfig.Initialize(((BaseUnityPlugin)this).Config); if (!OptimizationConfig.MasterEnabled.Value) { Logger.LogInfo((object)"PeakOptimizer 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.reis.peakoptimizer"); _harmony.PatchAll(); ShadowOptimizationPatch.Initialize(); TerrainAndScalingOptimizationPatch.Initialize(); SmallRockCullingPatch.Initialize(); AmbientParticleDistanceCullerPatch.Initialize(); LavaAndGloomVisualOptimizationPatch.Initialize(); if (OptimizationConfig.EnableBatchedPhysicsJobs.Value) { BatchPhysicsDispatcher.EnsureInitialized(); } if (OptimizationConfig.EnableAsyncLightSampling.Value) { AsyncLightVolumeCache.EnsureInitialized(); } if (OptimizationConfig.EnableSpatialVoxelCulling.Value) { BurstSimdSpatialEngine.EnsureInitialized(); } if (OptimizationConfig.EnableHiZOcclusionCulling.Value) { HiZOcclusionCuller.EnsureInitialized(); } if (OptimizationConfig.EnableTelemetryHUD.Value) { PeakTelemetryHUD.EnsureInitialized(); } Logger.LogInfo((object)"PeakOptimizer v2.1.1 loaded successfully."); } catch (Exception arg) { Logger.LogError((object)string.Format("Failed to initialize {0}: {1}", "PeakOptimizer", arg)); } } private void OnDestroy() { BurstSimdSpatialEngine.Shutdown(); AmbientParticleDistanceCullerPatch.ClearAndRestore(); if ((Object)(object)PeakTelemetryHUD.Instance != (Object)null) { Object.Destroy((Object)(object)((Component)PeakTelemetryHUD.Instance).gameObject); } if ((Object)(object)BatchPhysicsDispatcher.Instance != (Object)null) { Object.Destroy((Object)(object)((Component)BatchPhysicsDispatcher.Instance).gameObject); } if ((Object)(object)AsyncLightVolumeCache.Instance != (Object)null) { Object.Destroy((Object)(object)((Component)AsyncLightVolumeCache.Instance).gameObject); } if ((Object)(object)HiZOcclusionCuller.Instance != (Object)null) { Object.Destroy((Object)(object)((Component)HiZOcclusionCuller.Instance).gameObject); } Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } } namespace PeakOptimizer.Patches { [HarmonyPatch] public static class AmbientParticleDistanceCullerPatch { private class ParticleEntry { public ParticleSystem ParticleSys; public ParticleSystemRenderer? Renderer; public Transform Transform; public Vector3 CachedPosition; public int InstanceId; public bool IsCulled; public ParticleEntry(ParticleSystem ps, ParticleSystemRenderer? rend, Transform t, Vector3 pos, int id) { //IL_001e: 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) ParticleSys = ps; Renderer = rend; Transform = t; CachedPosition = pos; InstanceId = id; IsCulled = false; } } private const int ParticlesPerFrameBatch = 60; private static readonly List s_particles = new List(2048); private static readonly HashSet s_registeredIds = new HashSet(2048); private static int s_processIndex = 0; private static bool s_hooked = false; public static int TotalRegisteredCount => s_particles.Count; public static int CulledCount { get; private set; } = 0; public static void Initialize() { if (!s_hooked) { SceneManager.sceneLoaded += OnSceneLoaded; s_hooked = true; } } private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { ClearAndRestore(); ScanSceneParticles(); } public static void ClearAndRestore() { for (int i = 0; i < s_particles.Count; i++) { ParticleEntry particleEntry = s_particles[i]; if ((Object)(object)particleEntry?.ParticleSys != (Object)null) { if ((Object)(object)particleEntry.Renderer != (Object)null) { ((Renderer)particleEntry.Renderer).enabled = true; } if (particleEntry.ParticleSys.isPaused) { particleEntry.ParticleSys.Play(false); } particleEntry.IsCulled = false; } } s_particles.Clear(); s_registeredIds.Clear(); s_processIndex = 0; CulledCount = 0; } public static void RegisterParticleSystem(ParticleSystem? ps) { //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_00f1: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ps == (Object)null || !OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.EnableAmbientParticleCulling.Value) { return; } MainModule main = ps.main; if (!((MainModule)(ref main)).loop) { return; } int instanceID = ((Object)ps).GetInstanceID(); if (!s_registeredIds.Contains(instanceID)) { Transform root = ((Component)ps).transform.root; if (!((Component)root).CompareTag("Player") && !((Object)(object)((Component)ps).GetComponentInParent() != (Object)null) && !((Object)(object)((Component)ps).GetComponentInParent() != (Object)null) && !((Object)(object)((Component)ps).GetComponentInParent() != (Object)null) && !((Object)(object)((Component)ps).GetComponentInParent() != (Object)null)) { ParticleSystemRenderer component = ((Component)ps).GetComponent(); Transform transform = ((Component)ps).transform; s_registeredIds.Add(instanceID); s_particles.Add(new ParticleEntry(ps, component, transform, transform.position, instanceID)); } } } public static void RegisterHierarchy(GameObject? rootObj) { if (!((Object)(object)rootObj == (Object)null) && OptimizationConfig.MasterEnabled.Value && OptimizationConfig.EnableAmbientParticleCulling.Value) { ParticleSystem[] componentsInChildren = rootObj.GetComponentsInChildren(true); for (int i = 0; i < componentsInChildren.Length; i++) { RegisterParticleSystem(componentsInChildren[i]); } } } public static void ScanSceneParticles() { try { ParticleSystem[] array = Object.FindObjectsByType((FindObjectsSortMode)0); for (int i = 0; i < array.Length; i++) { RegisterParticleSystem(array[i]); } } catch { } } [HarmonyPatch(typeof(MapHandler), "InitializeMap")] [HarmonyPostfix] public static void MapHandler_InitializeMap_Postfix() { ScanSceneParticles(); } [HarmonyPatch(typeof(DecorSpawner), "ExecuteImmediately")] [HarmonyPostfix] public static void DecorSpawner_ExecuteImmediately_Postfix(DecorSpawner __instance) { if ((Object)(object)__instance != (Object)null) { RegisterHierarchy(((Component)__instance).gameObject); } } [HarmonyPatch(typeof(DesertRockSpawner), "ExecuteImmediately")] [HarmonyPostfix] public static void DesertRockSpawner_ExecuteImmediately_Postfix(DesertRockSpawner __instance) { if ((Object)(object)__instance != (Object)null) { RegisterHierarchy(((Component)__instance).gameObject); } } [HarmonyPatch(typeof(PropSpawner), "Add")] [HarmonyPostfix] public static void PropSpawner_Add_Postfix(PropSpawner __instance) { if ((Object)(object)__instance != (Object)null) { RegisterHierarchy(((Component)__instance).gameObject); } } [HarmonyPatch(typeof(TempleConfig), "CreateTemple_RPC")] [HarmonyPostfix] public static void TempleConfig_CreateTemple_RPC_Postfix(TempleConfig __instance) { if ((Object)(object)__instance != (Object)null) { RegisterHierarchy(((Component)__instance).gameObject); } } [HarmonyPatch(typeof(MainCamera), "LateUpdate")] [HarmonyPostfix] public static void MainCamera_LateUpdate_Postfix(MainCamera __instance) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.EnableAmbientParticleCulling.Value) { return; } int count = s_particles.Count; if (count == 0 || (Object)(object)__instance == (Object)null) { return; } Vector3 position = ((Component)__instance).transform.position; float num = ((OptimizationConfig.AmbientParticleCullDistance != null) ? OptimizationConfig.AmbientParticleCullDistance.Value : 50f); float num2 = (num + 5f) * (num + 5f); float num3 = (num - 3f) * (num - 3f); int num4 = Mathf.Min(60, count); for (int i = 0; i < num4; i++) { if (s_processIndex >= s_particles.Count) { s_processIndex = 0; } if (s_particles.Count == 0) { break; } ParticleEntry particleEntry = s_particles[s_processIndex]; if (particleEntry == null || (Object)(object)particleEntry.ParticleSys == (Object)null || (Object)(object)particleEntry.Transform == (Object)null) { if (particleEntry != null) { s_registeredIds.Remove(particleEntry.InstanceId); } int index = s_particles.Count - 1; s_particles[s_processIndex] = s_particles[index]; s_particles.RemoveAt(index); continue; } if (!((Component)particleEntry.ParticleSys).gameObject.activeInHierarchy) { s_processIndex++; continue; } s_processIndex++; Vector3 cachedPosition = particleEntry.CachedPosition; Vector3 val = position - cachedPosition; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; if (!particleEntry.IsCulled && sqrMagnitude > num2) { particleEntry.ParticleSys.Pause(false); if ((Object)(object)particleEntry.Renderer != (Object)null) { ((Renderer)particleEntry.Renderer).enabled = false; } particleEntry.IsCulled = true; CulledCount++; } else if (particleEntry.IsCulled && sqrMagnitude <= num3) { if ((Object)(object)particleEntry.Renderer != (Object)null) { ((Renderer)particleEntry.Renderer).enabled = true; } particleEntry.ParticleSys.Play(false); particleEntry.IsCulled = false; if (CulledCount > 0) { CulledCount--; } } } } } [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_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_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009b: 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_00b1: 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_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeBotPlayerSearch.Value) { return true; } List allCharacters = Character.AllCharacters; if (allCharacters == null || allCharacters.Count == 0) { __result = null; return false; } Vector3 center = __instance.Center; int count = allCharacters.Count; for (int i = 0; i < count; i++) { Character val = allCharacters[i]; if ((Object)(object)val == (Object)null || val.isBot) { continue; } Vector3 center2 = val.Center; if (Vector3.Distance(center, center2) > maxRange || Vector3.Angle(center2 - center, ___lookDirection) > maxAngle) { continue; } Bodypart val2 = val.refs?.head; if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.Rig == (Object)null)) { Vector3 position = val2.Rig.position; RaycastHit val3 = HelperFunctions.LineCheck(searcherHeadPos, position, (LayerType)1, 0f, (QueryTriggerInteraction)1); if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref val3)).transform)) { __result = val2.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] public static class CitadelTrapsOptimizationPatch { public static bool IsAnyPlayerNear(Vector3 trapPosition, float maxDistSqr) { //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_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_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) List allCharacters = Character.AllCharacters; Vector3 val2; if (allCharacters != null) { int count = allCharacters.Count; for (int i = 0; i < count; i++) { Character val = allCharacters[i]; if ((Object)(object)val != (Object)null && !val.IsGhost) { val2 = val.Center - trapPosition; if (((Vector3)(ref val2)).sqrMagnitude <= maxDistSqr) { return true; } } } return false; } if ((Object)(object)MainCamera.instance != (Object)null) { val2 = ((Component)MainCamera.instance).transform.position - trapPosition; return ((Vector3)(ref val2)).sqrMagnitude <= maxDistSqr; } return true; } [HarmonyPatch(typeof(ArrowShooter), "FixedUpdate")] [HarmonyPrefix] public static bool ArrowShooter_FixedUpdate_Prefix(ArrowShooter __instance) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeCitadelTraps.Value) { return true; } if ((Object)(object)__instance == (Object)null) { return true; } float value = OptimizationConfig.CitadelTrapMaxDistance.Value; float maxDistSqr = value * value; if (!IsAnyPlayerNear(((Component)__instance).transform.position, maxDistSqr)) { return false; } return true; } [HarmonyPatch(typeof(VenusFlyTrap), "FixedUpdate")] [HarmonyPrefix] public static bool VenusFlyTrap_FixedUpdate_Prefix(VenusFlyTrap __instance, bool ____isMunching) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeCitadelTraps.Value) { return true; } if (____isMunching) { return true; } if ((Object)(object)__instance == (Object)null) { return true; } float value = OptimizationConfig.CitadelTrapMaxDistance.Value; float maxDistSqr = value * value; if (!IsAnyPlayerNear(((Component)__instance).transform.position, maxDistSqr)) { return false; } return true; } } [HarmonyPatch(typeof(DynamicBone))] public static class DynamicBoneOptimizerPatch { private const float OptimizedFoliageUpdateRateHz = 30f; [HarmonyPatch("UpdateDynamicBones")] [HarmonyPrefix] public static bool UpdateDynamicBones_Prefix(DynamicBone __instance) { //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_00af: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: 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; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; if (sqrMagnitude > num) { return false; } return true; } } [HarmonyPatch] public static class DynamiteAndExplosionOptimizationPatch { private struct RecentActivity { public Vector3 Position; public float Timestamp; } private static readonly List s_recentExplosions = new List(32); private static readonly List s_recentFlares = new List(32); private const float ClusterRadiusMeters = 3.5f; private const float ClusterWindowSeconds = 1.2f; private const float FlareRadiusMeters = 2.5f; private const float FlareWindowSeconds = 15f; private static void CleanOldRecords(List list, float currentTime, float window) { for (int num = list.Count - 1; num >= 0; num--) { if (currentTime - list[num].Timestamp > window) { list.RemoveAt(num); } } } private static int CountNearbyExplosions(Vector3 pos, float currentTime) { //IL_002a: 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_0030: 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) CleanOldRecords(s_recentExplosions, currentTime, 1.2f); int num = 0; float num2 = 12.25f; for (int i = 0; i < s_recentExplosions.Count; i++) { Vector3 val = s_recentExplosions[i].Position - pos; if (((Vector3)(ref val)).sqrMagnitude <= num2) { num++; } } return num; } private static int CountNearbyFlares(Vector3 pos, float currentTime) { //IL_002a: 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_0030: 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) CleanOldRecords(s_recentFlares, currentTime, 15f); int num = 0; float num2 = 6.25f; for (int i = 0; i < s_recentFlares.Count; i++) { Vector3 val = s_recentFlares[i].Position - pos; if (((Vector3)(ref val)).sqrMagnitude <= num2) { num++; } } return num; } [HarmonyPatch(typeof(ExplosionEffect), "Start")] [HarmonyPrefix] public static bool ExplosionEffect_Start_Prefix(ExplosionEffect __instance) { //IL_0030: 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.EnableEngineBugFixes.Value) { return true; } Vector3 position = ((Component)__instance).transform.position; float time = Time.time; int num = CountNearbyExplosions(position, time); s_recentExplosions.Add(new RecentActivity { Position = position, Timestamp = time }); if (num >= 5) { __instance.explosionPointCount = 1; __instance.subExplosionPointCount = 0; } else if (num >= 2) { __instance.explosionPointCount = 2; __instance.subExplosionPointCount = 1; } return true; } [HarmonyPatch(typeof(Dynamite), "EnableFlareVisuals")] [HarmonyPrefix] public static bool Dynamite_EnableFlareVisuals_Prefix(Dynamite __instance, ref TrackNetworkedObject ___smokeVFXPrefab, ref TrackableNetworkObject ___trackable) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009d: 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_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.EnableEngineBugFixes.Value) { return true; } if ((Object)(object)___smokeVFXPrefab == (Object)null || (Object)(object)___trackable == (Object)null) { return false; } Vector3 position = ((Component)__instance).transform.position; float time = Time.time; int num = CountNearbyFlares(position, time); s_recentFlares.Add(new RecentActivity { Position = position, Timestamp = time }); GameObject val = Object.Instantiate(((Component)___smokeVFXPrefab).gameObject, position, ((Component)__instance).transform.rotation); TrackNetworkedObject component = val.GetComponent(); if ((Object)(object)component != (Object)null) { component.SetObject(___trackable); } if (num >= 3) { ParticleSystem[] componentsInChildren = val.GetComponentsInChildren(); foreach (ParticleSystem val2 in componentsInChildren) { MainModule main = val2.main; ((MainModule)(ref main)).maxParticles = Mathf.Min(((MainModule)(ref main)).maxParticles, 15); EmissionModule emission = val2.emission; ((EmissionModule)(ref emission)).rateOverTimeMultiplier = ((EmissionModule)(ref emission)).rateOverTimeMultiplier * 0.25f; } } return false; } [HarmonyPatch(typeof(TrackNetworkedObject), "TryReattachToTrackedObject")] [HarmonyPrefix] public static bool TrackNetworkedObject_TryReattach_Prefix(TrackNetworkedObject __instance) { if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.EnableEngineBugFixes.Value) { return true; } if ((Object)(object)__instance.trackedObject != (Object)null && ((Component)__instance.trackedObject).gameObject.activeInHierarchy) { 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_0045: 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) 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, false); } else { float num2 = __instance.amount * Time.deltaTime; localCharacter.refs.afflictions.AddStatus((STATUSTYPE)2, num2, false, true, true, false); } 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 allScouts, StatusFieldGloom ___fogField, ref bool __result) { //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_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: 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) 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 allScouts, Character lostScout, RavenPerch[] ____validPerches, StatusFieldGloom ___fogField, float ___idealPerchDistance, ref RavenPerch? bestPerch, ref bool __result) { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: 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_0074: 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) //IL_008c: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: 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; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; if (sqrMagnitude > num * num) { __result = false; return false; } return true; } } [HarmonyPatch(typeof(GrassChunking))] public static class GrassFrustumOptimizationPatch { private static Camera? s_cachedCamera; 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_002c: 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_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0162: 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; } if ((Object)(object)s_cachedCamera == (Object)null && (Object)(object)MainCamera.instance != (Object)null) { s_cachedCamera = ((Component)MainCamera.instance).GetComponent(); } Camera val = (Camera)(((Object)(object)s_cachedCamera != (Object)null) ? ((object)s_cachedCamera) : ((object)Camera.main)); 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_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: 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) //IL_010a: Expected O, but got Unknown //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Expected O, but got Unknown //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_020c: 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(); } 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 = 35f; private const float AoDistanceFalloffMeters = 8f; [HarmonyPatch("Start")] [HarmonyPostfix] public static void Start_Postfix(PostHandler __instance, Volume ___volume) { if (OptimizationConfig.MasterEnabled.Value && OptimizationConfig.OptimizeHBAOPerformance.Value && !((Object)(object)___volume == (Object)null)) { VolumeProfile val = (((Object)(object)___volume.profile != (Object)null) ? ___volume.profile : ___volume.sharedProfile); HBAO val2 = default(HBAO); if (!((Object)(object)val == (Object)null) && val.TryGet(ref val2) && (Object)(object)val2 != (Object)null && ((VolumeComponent)val2).active) { val2.SetAoMaxDistance(35f); val2.SetAoDistanceFalloff(8f); val2.SetResolution((Resolution)1); val2.SetQuality((Quality)1); } } } } [HarmonyPatch] public static class LavaAndGloomVisualOptimizationPatch { private static bool _isInitialized; public static void Initialize() { if (!_isInitialized) { _isInitialized = true; SceneManager.sceneLoaded += OnSceneLoaded; } } private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (OptimizationConfig.MasterEnabled.Value) { OptimizeVolcanoLava(); } } private static void OptimizeVolcanoLava() { GameObject val = GameObject.Find("/Map/Volcano/LavaField/Lava Bubbles"); if ((Object)(object)val != (Object)null && val.activeSelf) { val.SetActive(false); } GameObject val2 = GameObject.Find("Volcano") ?? GameObject.Find("LavaField"); if (!((Object)(object)val2 != (Object)null)) { return; } Transform[] componentsInChildren = val2.GetComponentsInChildren(true); foreach (Transform val3 in componentsInChildren) { if (((Object)val3).name.Equals("Lava Bubbles", StringComparison.OrdinalIgnoreCase) && ((Component)val3).gameObject.activeSelf) { ((Component)val3).gameObject.SetActive(false); } } } [HarmonyPatch(typeof(MovingLava), "Start")] [HarmonyPostfix] public static void MovingLava_Start_Postfix(MovingLava __instance) { if (!OptimizationConfig.MasterEnabled.Value || !((Object)(object)__instance != (Object)null)) { return; } Transform[] componentsInChildren = ((Component)__instance).GetComponentsInChildren(true); foreach (Transform val in componentsInChildren) { if (((Object)val).name.Equals("Lava Bubbles", StringComparison.OrdinalIgnoreCase)) { ((Component)val).gameObject.SetActive(false); } } } } [HarmonyPatch(typeof(LightVolume))] public static class LightVolumeCachePatch { [HarmonyPatch("SamplePositionAlpha")] [HarmonyPrefix] public static bool SamplePositionAlpha_Prefix(Vector3 worldPos, ref float __result) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.EnableAsyncLightSampling.Value) { return true; } AsyncLightVolumeCache.EnsureInitialized(); if ((Object)(object)AsyncLightVolumeCache.Instance == (Object)null) { return true; } __result = AsyncLightVolumeCache.Instance.SampleAlpha(worldPos); return false; } } [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_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_0092: 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_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: 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(typeof(PlayerHandler))] public static class PlayerHandlerZeroGCPatch { [HarmonyPatch("IsAnyPlayerNear")] [HarmonyPrefix] public static bool IsAnyPlayerNear_Prefix(Vector3 point, float threshold, ref bool __result) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: 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) if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.EnableZeroGCBuffers.Value) { return true; } float num = threshold * threshold; List allCharacters = Character.AllCharacters; if (allCharacters != null) { int count = allCharacters.Count; for (int i = 0; i < count; i++) { Character val = allCharacters[i]; if ((Object)(object)val != (Object)null && !val.IsGhost) { Vector3 val2 = val.Center - point; if (((Vector3)(ref val2)).sqrMagnitude <= num) { __result = true; return false; } } } } __result = false; return false; } } [HarmonyPatch] public static class ShadowOptimizationPatch { private const float AntiAcneNormalBias = 0.4f; private const float SafeContactDepthBias = 0.05f; private static bool s_sceneHooked; private const float LodBiasMultiplierHigh = 1.3f; private const float LodBiasMultiplierMedium = 1f; private const float LodBiasMultiplierLow = 0.85f; public static void Initialize() { if (!s_sceneHooked) { SceneManager.sceneLoaded += OnSceneLoaded; s_sceneHooked = true; } FixDirectionalLightShadowBiases(); FixAdditionalLights(); ApplyLodSettings(); } private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { FixDirectionalLightShadowBiases(); FixAdditionalLights(); ApplyLodSettings(); } public static void FixDirectionalLightShadowBiases() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Invalid comparison between Unknown and I4 if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.EnableShadowOptimizations.Value) { return; } Light[] array = Object.FindObjectsByType((FindObjectsInactive)0, (FindObjectsSortMode)0); foreach (Light val in array) { if ((Object)(object)val != (Object)null && (int)val.type == 1) { if (val.shadowNormalBias < 0.4f) { val.shadowNormalBias = 0.4f; } if (val.shadowBias < 0.05f) { val.shadowBias = 0.05f; } } } } public static void FixAdditionalLights() { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Invalid comparison between Unknown and I4 //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Invalid comparison between Unknown and I4 //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Invalid comparison between Unknown and I4 if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.DisableCitadelPointShadows.Value) { return; } Light[] array = Object.FindObjectsByType((FindObjectsInactive)0, (FindObjectsSortMode)0); foreach (Light val in array) { if ((Object)(object)val != (Object)null && ((int)val.type == 2 || (int)val.type == 0) && !((Object)(object)((Component)val).GetComponentInParent() != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent() != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent() != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent() != (Object)null) && (int)val.shadows > 0) { val.shadows = (LightShadows)0; } } } public static void ApplyLodSettings() { if (OptimizationConfig.MasterEnabled.Value && OptimizationConfig.OptimizeLODScaling.Value) { QualitySettings.lodBias = OptimizationConfig.OptimizedLodBias.Value; } } [HarmonyPatch(typeof(LodQuality), "ApplyValue")] [HarmonyPrefix] public static bool ApplyLod_Prefix(LodQuality __instance) { //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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Invalid comparison between Unknown and I4 //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Invalid comparison between Unknown and I4 if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.OptimizeLODScaling.Value) { return true; } float value = OptimizationConfig.OptimizedLodBias.Value; Quality value2 = ((EnumSetting)(object)__instance).Value; if (1 == 0) { } float lodBias = (((int)value2 == 1) ? (value * 1f) : (((int)value2 != 2) ? (value * 0.85f) : (value * 1.3f))); if (1 == 0) { } QualitySettings.lodBias = lodBias; return false; } [HarmonyPatch(typeof(DayNightManager), "Start")] [HarmonyPostfix] public static void DayNightManager_Start_Postfix() { FixDirectionalLightShadowBiases(); FixAdditionalLights(); } } [HarmonyPatch(typeof(ShakyRock))] public static class ShakyRockZeroGCPatch { private const int OverlapBufferSize = 64; private static readonly Collider[] s_overlapBuffer = (Collider[])(object)new Collider[64]; [HarmonyPatch("FixedUpdate")] [HarmonyPrefix] public static bool FixedUpdate_Prefix(ShakyRock __instance, ref bool ___isFinished, ref bool ___isFalling, ref bool ___once, ref Rigidbody ___rig, ref MeshCollider ___meshCollider, ref float ___pushOutForce, ref Vector3 ___scaleOnChange, ref Vector3 ___positionOnChange, ref Quaternion ___rotationOnChange) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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) //IL_00eb: 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_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_0137: 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_0152: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.EnableZeroGCFastBuffers.Value) { return true; } if (___isFinished || !___isFalling) { return false; } if (!___once) { ___rig.AddForce(Vector3.back * ___pushOutForce, (ForceMode)2); ___once = true; } Bounds bounds = ((Collider)___meshCollider).bounds; Vector3 center = ((Bounds)(ref bounds)).center; Vector3 extents = ((Bounds)(ref bounds)).extents; float num = ((Vector3)(ref extents)).magnitude / 2f; int num2 = Physics.OverlapSphereNonAlloc(center, num, s_overlapBuffer); bool flag = false; for (int i = 0; i < num2; i++) { if ((Object)(object)s_overlapBuffer[i] != (Object)(object)___meshCollider) { flag = true; break; } } if (flag) { return false; } int num3 = Physics.OverlapBoxNonAlloc(center, ((Bounds)(ref bounds)).extents, s_overlapBuffer, ((Component)__instance).transform.rotation); float num4 = default(float); for (int j = 0; j < num3; j++) { Collider val = s_overlapBuffer[j]; if (!((Object)(object)val == (Object)(object)___meshCollider) && Physics.ComputePenetration((Collider)(object)___meshCollider, ((Component)___meshCollider).transform.position, ((Component)___meshCollider).transform.rotation, val, ((Component)val).transform.position, ((Component)val).transform.rotation, ref extents, ref num4)) { return false; } } ___scaleOnChange = ((Component)___meshCollider).transform.lossyScale; ___positionOnChange = ((Component)___meshCollider).transform.position; ___rotationOnChange = ((Component)___meshCollider).transform.rotation; ___isFinished = true; ___rig.excludeLayers = LayerMask.op_Implicit(0); return false; } } [HarmonyPatch] public static class SmallRockCullingPatch { private class RockEntry { public MeshRenderer Renderer; public Vector3 Position; public bool IsVisible; public RockEntry(MeshRenderer renderer, Vector3 position) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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 s_rocks = new List(1024); private static readonly HashSet s_registeredIds = new HashSet(); private static int s_processIndex = 0; private static bool s_hooked = false; public static int TotalCount => s_rocks.Count; public static int CulledCount { get; private set; } = 0; 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; CulledCount = 0; } public static void RegisterSpawnerChildren(GameObject? spawnerRoot) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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_00dd: 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(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(DesertRockSpawner), "ExecuteImmediately")] [HarmonyPostfix] public static void DesertRockSpawner_ExecuteImmediately_Postfix(DesertRockSpawner __instance) { if ((Object)(object)__instance != (Object)null) { RegisterSpawnerChildren(((Component)__instance).gameObject); } } [HarmonyPatch(typeof(PropSpawner), "Add")] [HarmonyPostfix] public static void PropSpawner_Add_Postfix(PropSpawner __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_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_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017f: 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 + 2f) * (value + 2f); 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 > num) { ((Renderer)rockEntry.Renderer).enabled = false; rockEntry.IsVisible = false; CulledCount++; } else if (!rockEntry.IsVisible && sqrMagnitude <= num2) { ((Renderer)rockEntry.Renderer).enabled = true; rockEntry.IsVisible = true; if (CulledCount > 0) { CulledCount--; } } } } } [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 && OptimizationConfig.OptimizeLODScaling.Value) { QualitySettings.lodBias = OptimizationConfig.OptimizedLodBias.Value; } } } [HarmonyPatch(typeof(VoiceObscuranceFilter))] public static class VoiceObscurancePatch { private class ThreadedFilterState { public float NextCheckTime; public bool IsObstructed; public float ReverbAlpha; public bool IsDistant; public bool IsQueryPending; } private static readonly ConditionalWeakTable StateCache = new ConditionalWeakTable(); private static readonly BatchPhysicsDispatcher.RaycastContextCallback s_onVoiceLinecastCompleted = OnVoiceLinecastCompleted; private const float ObstructedCutoff = 1500f; private const float ClearCutoff = 7500f; private const float DistanceThresholdMeters = 60f; private static void OnVoiceLinecastCompleted(bool hitOccurred, RaycastHit hitResult, object context) { if (context is ThreadedFilterState threadedFilterState) { threadedFilterState.IsObstructed = hitOccurred; threadedFilterState.IsQueryPending = false; } } [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_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: 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) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: 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; } } ThreadedFilterState orCreateValue = StateCache.GetOrCreateValue(__instance); float time = Time.time; Vector3 val2; if (OptimizationConfig.EnableBatchedPhysicsJobs.Value) { BatchPhysicsDispatcher.EnsureInitialized(); float num = Mathf.Max(0.02f, OptimizationConfig.VoiceUpdateIntervalSeconds.Value); if (time >= orCreateValue.NextCheckTime && !orCreateValue.IsQueryPending) { orCreateValue.NextCheckTime = time + num; orCreateValue.IsQueryPending = true; Vector3 position = ((Component)__instance).transform.position; Vector3 position2 = __instance.head.position; BatchPhysicsDispatcher.Instance?.EnqueueLinecast(position, position2, LayerMask.op_Implicit(__instance.layer), s_onVoiceLinecastCompleted, orCreateValue); if (OptimizationConfig.EnableAsyncLightSampling.Value) { AsyncLightVolumeCache.EnsureInitialized(); if ((Object)(object)AsyncLightVolumeCache.Instance != (Object)null) { orCreateValue.ReverbAlpha = math.saturate(AsyncLightVolumeCache.Instance.SampleAlpha(position)); } } else { LightVolume val = LightVolume.Instance(); if ((Object)(object)val != (Object)null) { orCreateValue.ReverbAlpha = math.saturate(val.SamplePositionAlpha(position, false)); } } val2 = position - position2; orCreateValue.IsDistant = ((Vector3)(ref val2)).sqrMagnitude > 3600f; } } else { float num2 = Mathf.Max(0.02f, OptimizationConfig.VoiceUpdateIntervalSeconds.Value); if (time >= orCreateValue.NextCheckTime) { orCreateValue.NextCheckTime = time + num2; Vector3 position3 = ((Component)__instance).transform.position; Vector3 position4 = __instance.head.position; orCreateValue.IsObstructed = Physics.Linecast(position3, position4, LayerMask.op_Implicit(__instance.layer)); LightVolume val3 = LightVolume.Instance(); if ((Object)(object)val3 != (Object)null) { orCreateValue.ReverbAlpha = math.saturate(val3.SamplePositionAlpha(position3, false)); } val2 = position3 - position4; orCreateValue.IsDistant = ((Vector3)(ref val2)).sqrMagnitude > 3600f; } } __instance.reverbAddition = Mathf.Clamp(orCreateValue.ReverbAlpha, ___obstructionMinimum, __instance.maxReverb); if (____isCharacterVoice && (Object)(object)____voiceHandler != (Object)null) { if ((Object)(object)Singleton.Instance != (Object)null && Singleton.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 num3 = (____voiceHandler.IsStolen ? ___stolenVoiceCutoff : 10f); __instance.highPass.cutoffFrequency = Mathf.Lerp(__instance.highPass.cutoffFrequency, num3, 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 num4 = (orCreateValue.IsObstructed ? 1500f : 7500f); __instance.lowPass.cutoffFrequency = Mathf.Lerp(__instance.lowPass.cutoffFrequency, num4, 1f * Time.deltaTime); } } else { float num5 = (orCreateValue.IsObstructed ? 1500f : 7500f); __instance.lowPass.cutoffFrequency = Mathf.Lerp(__instance.lowPass.cutoffFrequency, num5, 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; } } [HarmonyPatch(typeof(WindChillZone))] public static class WindChillBatchedPhysicsPatch { private class ShelterState { public float ShelterMultiplier = 1f; public float NextQueryTime; public bool IsQueryPending; public float MinDistance; public float MaxDistance; public Vector3 WindDirection; } private delegate void AddForceAtPositionDelegate(Character self, Vector3 force, Vector3 position, float radius); private static readonly ConditionalWeakTable s_shelterCache = new ConditionalWeakTable(); private static readonly BatchPhysicsDispatcher.RaycastContextCallback s_onShelterRaycastCompleted = OnShelterRaycastCompleted; private const float QueryIntervalSeconds = 0.1f; private static readonly AddForceAtPositionDelegate? s_addForceDelegate = AccessTools.MethodDelegate(AccessTools.Method(typeof(Character), "AddForceAtPosition", new Type[3] { typeof(Vector3), typeof(Vector3), typeof(float) }, (Type[])null), (object)null, true); private static void OnShelterRaycastCompleted(bool hitOccurred, RaycastHit hitResult, object context) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) if (context is ShelterState shelterState) { if (hitOccurred) { float num = Mathf.InverseLerp(shelterState.MinDistance, shelterState.MaxDistance, ((RaycastHit)(ref hitResult)).distance); float num2 = Mathf.Clamp01(Vector3.Dot(((RaycastHit)(ref hitResult)).normal, shelterState.WindDirection)); shelterState.ShelterMultiplier = Mathf.Clamp01(num + (1f - num2)); } else { shelterState.ShelterMultiplier = 1f; } shelterState.IsQueryPending = false; } } [HarmonyPatch("AddWindForceToCharacter")] [HarmonyPrefix] public static bool AddWindForceToCharacter_Prefix(WindChillZone __instance, Character character, float mult, bool ___useRaycast, float ___maxRaycastDistance, float ___minRaycastDistance, float ___ragdolledWindForceMult, float ___windForce, float ___windPlayerFactor, float ___forceRadius, Vector3 ___currentWindDirection, bool ___useIntensityCurve, float ___windIntensity) { //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_019e: 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_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.EnableBatchedPhysicsJobs.Value) { return true; } if (s_addForceDelegate == null) { return true; } if (!((MonoBehaviourPun)character).photonView.IsMine || (Object)(object)character.data.currentClimbHandle != (Object)null) { return false; } float num = (___useIntensityCurve ? (Mathf.Clamp01(___windIntensity - 0.5f) * 2f) : 1f); bool flag = false; Parasol val = default(Parasol); if (Object.op_Implicit((Object)(object)character.data.currentItem) && ((Component)character.data.currentItem).TryGetComponent(ref val) && val.isOpen) { num *= 10f; flag = true; } if (character.refs.balloons.currentBalloonCount > 0) { int num2 = ((!flag) ? 2 : 0); num *= (float)(num2 + character.refs.balloons.currentBalloonCount); } Affliction val2 = default(Affliction); if (character.refs.afflictions.HasAfflictionType((AfflictionType)17, ref val2)) { num = 0f; } if (___useRaycast) { ShelterState orCreateValue = s_shelterCache.GetOrCreateValue(character); float time = Time.time; if (time >= orCreateValue.NextQueryTime && !orCreateValue.IsQueryPending) { orCreateValue.NextQueryTime = time + 0.1f; orCreateValue.IsQueryPending = true; orCreateValue.MinDistance = ___minRaycastDistance; orCreateValue.MaxDistance = ___maxRaycastDistance; orCreateValue.WindDirection = ___currentWindDirection; Vector3 center = character.Center; Vector3 val3 = -___currentWindDirection; int layerMask = LayerMask.op_Implicit(HelperFunctions.GetMask((LayerType)1)); BatchPhysicsDispatcher.EnsureInitialized(); BatchPhysicsDispatcher.Instance?.EnqueueLinecast(center, center + val3 * ___maxRaycastDistance, layerMask, s_onShelterRaycastCompleted, orCreateValue); } num *= orCreateValue.ShelterMultiplier; } num *= ((character.data.fallSeconds >= 0.01f) ? ___ragdolledWindForceMult : 1f); num *= mult; Vector3 force = ___currentWindDirection * ___windForce * ___windPlayerFactor * num; s_addForceDelegate(character, force, character.Center, ___forceRadius); return false; } } } namespace PeakOptimizer.Core.Spatial { public static class BurstSimdSpatialEngine { [BurstCompile(/*Could not decode attribute arguments.*/)] public struct SimdRadiusFilterJob : IJob { [ReadOnly] public NativeArray Positions; [ReadOnly] public float3 QueryOrigin; [ReadOnly] public float RadiusSqr; [ReadOnly] public float3 LookDirection; [ReadOnly] public float CosMaxAngle; [ReadOnly] public bool UseAngleFilter; [WriteOnly] public NativeArray MatchingIndices; public NativeArray ResultCount; public void Execute() { //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_0043: 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) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007a: 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_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009f: 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_00ad: 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_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: 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_00fe: 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) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0112: 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_011c: 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_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: 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_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) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0196: 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) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: 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_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_030f: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) int length = Positions.Length; int num = 0; int length2 = MatchingIndices.Length; int num2 = length - length % 4; for (int i = 0; i < num2; i += 4) { float3 val = Positions[i]; float3 val2 = Positions[i + 1]; float3 val3 = Positions[i + 2]; float3 val4 = Positions[i + 3]; float4 val5 = new float4(val.x, val2.x, val3.x, val4.x) - QueryOrigin.x; float4 val6 = new float4(val.y, val2.y, val3.y, val4.y) - QueryOrigin.y; float4 val7 = new float4(val.z, val2.z, val3.z, val4.z) - QueryOrigin.z; float4 val8 = val5 * val5 + val6 * val6 + val7 * val7; bool4 val9 = val8 <= RadiusSqr; if (math.any(val9)) { if (UseAngleFilter) { float4 val10 = math.rsqrt(val8); float4 val11 = val5 * val10 * LookDirection.x + val6 * val10 * LookDirection.y + val7 * val10 * LookDirection.z; bool4 val12 = val8 > 0.0001f; bool4 val13 = val11 >= CosMaxAngle; val9 &= val12 & val13; } if (val9.x && num < length2) { MatchingIndices[num++] = i; } if (val9.y && num < length2) { MatchingIndices[num++] = i + 1; } if (val9.z && num < length2) { MatchingIndices[num++] = i + 2; } if (val9.w && num < length2) { MatchingIndices[num++] = i + 3; } } } for (int j = num2; j < length; j++) { float3 val14 = Positions[j] - QueryOrigin; float num3 = math.lengthsq(val14); if (num3 <= RadiusSqr && (!UseAngleFilter || (num3 > 0.0001f && math.dot(val14 * math.rsqrt(num3), LookDirection) >= CosMaxAngle)) && num < length2) { MatchingIndices[num++] = j; } } ResultCount[0] = num; } } private const int InitialCapacity = 256; private const float MinDistanceSqrGuard = 0.0001f; private const float SentinelCoord = 1000000f; private static NativeArray s_positionsBuffer; private static NativeArray s_resultsBuffer; private static NativeArray s_countBuffer; private static int s_currentCapacity; private static bool s_isInitialized; public static void EnsureCapacity(int requiredCapacity) { //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) //IL_0092: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) if (!s_isInitialized || s_currentCapacity < requiredCapacity) { int num = Mathf.NextPowerOfTwo(Mathf.Max(256, requiredCapacity)); if (s_positionsBuffer.IsCreated) { s_positionsBuffer.Dispose(); } if (s_resultsBuffer.IsCreated) { s_resultsBuffer.Dispose(); } if (!s_countBuffer.IsCreated) { s_countBuffer = new NativeArray(1, (Allocator)4, (NativeArrayOptions)1); } s_positionsBuffer = new NativeArray(num, (Allocator)4, (NativeArrayOptions)1); s_resultsBuffer = new NativeArray(num, (Allocator)4, (NativeArrayOptions)1); s_currentCapacity = num; s_isInitialized = true; } } public static void EnsureInitialized() { EnsureCapacity(256); } public static int FilterCharacters(List characters, Vector3 origin, float radius, Vector3 lookDirection, float maxAngleDegrees, List outResults, bool excludeBots = true) { //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: 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) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0159: 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) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) outResults.Clear(); int count = characters.Count; if (count == 0) { return 0; } EnsureCapacity(count); for (int i = 0; i < count; i++) { Character val = characters[i]; if ((Object)(object)val != (Object)null && (!excludeBots || !val.isBot)) { Vector3 center = val.Center; s_positionsBuffer[i] = new float3(center.x, center.y, center.z); } else { s_positionsBuffer[i] = new float3(1000000f, 1000000f, 1000000f); } } bool flag = maxAngleDegrees < 180f; float cosMaxAngle = (flag ? math.cos(math.radians(maxAngleDegrees)) : (-1f)); float3 lookDirection2 = (flag ? math.normalize(new float3(lookDirection.x, lookDirection.y, lookDirection.z)) : float3.zero); SimdRadiusFilterJob simdRadiusFilterJob = new SimdRadiusFilterJob { Positions = s_positionsBuffer.GetSubArray(0, count), QueryOrigin = new float3(origin.x, origin.y, origin.z), RadiusSqr = radius * radius, LookDirection = lookDirection2, CosMaxAngle = cosMaxAngle, UseAngleFilter = flag, MatchingIndices = s_resultsBuffer, ResultCount = s_countBuffer }; IJobExtensions.Run(simdRadiusFilterJob); int num = s_countBuffer[0]; for (int j = 0; j < num; j++) { int num2 = s_resultsBuffer[j]; if (num2 < count) { Character val2 = characters[num2]; if ((Object)(object)val2 != (Object)null) { outResults.Add(val2); } } } return num; } public static void Shutdown() { if (s_isInitialized) { if (s_positionsBuffer.IsCreated) { s_positionsBuffer.Dispose(); } if (s_resultsBuffer.IsCreated) { s_resultsBuffer.Dispose(); } if (s_countBuffer.IsCreated) { s_countBuffer.Dispose(); } s_isInitialized = false; s_currentCapacity = 0; } } } public class SpatialVoxelGrid where T : class { public struct VoxelEntry { public T Item; public Vector3 Position; public int3 GridCoord; public VoxelEntry(T item, Vector3 position, int3 gridCoord) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) Item = item; Position = position; GridCoord = gridCoord; } } private readonly Dictionary> _cells = new Dictionary>(512); private readonly Dictionary _itemToCellKey = new Dictionary(1024); private readonly List> _cellListPool = new List>(128); public float CellSize => Mathf.Max(1f, OptimizationConfig.VoxelCellSizeMeters.Value); private long GetCellKey(int3 coord) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) long num = coord.x & 0x1FFFFF; long num2 = coord.y & 0x1FFFFF; long num3 = coord.z & 0x1FFFFF; return (num << 42) | (num2 << 21) | num3; } private int3 WorldToGrid(Vector3 worldPos) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //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_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: 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_0032: Unknown result type (might be due to invalid IL or missing references) float cellSize = CellSize; return (int3)math.floor(new float3(worldPos.x, worldPos.y, worldPos.z) / cellSize); } public void InsertOrUpdate(T item, Vector3 position) { //IL_0016: 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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0102: 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_0095: Unknown result type (might be due to invalid IL or missing references) if (item == null) { return; } int3 val = WorldToGrid(position); long cellKey = GetCellKey(val); if (_itemToCellKey.TryGetValue(item, out var value)) { if (value == cellKey) { if (_cells.TryGetValue(value, out List value2) && value2 != null) { for (int i = 0; i < value2.Count; i++) { if (value2[i].Item == item) { value2[i] = new VoxelEntry(item, position, val); return; } } } } else { RemoveFromCell(value, item); } } if (!_cells.TryGetValue(cellKey, out List value3) || value3 == null) { value3 = AllocateCellList(); _cells[cellKey] = value3; } value3.Add(new VoxelEntry(item, position, val)); _itemToCellKey[item] = cellKey; } public void Remove(T item) { if (item != null && _itemToCellKey.TryGetValue(item, out var value)) { RemoveFromCell(value, item); _itemToCellKey.Remove(item); } } private void RemoveFromCell(long key, T item) { if (!_cells.TryGetValue(key, out List value) || value == null) { return; } for (int i = 0; i < value.Count; i++) { if (value[i].Item == item) { int index = value.Count - 1; value[i] = value[index]; value.RemoveAt(index); break; } } if (value.Count == 0) { _cells.Remove(key); RecycleCellList(value); } } public void Clear() { foreach (KeyValuePair> cell in _cells) { RecycleCellList(cell.Value); } _cells.Clear(); _itemToCellKey.Clear(); } public void QueryRadius(Vector3 center, float radius, List results) { //IL_0006: 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_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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: 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_0034: 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_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0116: 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_00f9: 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_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) float num = radius * radius; int3 val = WorldToGrid(center - Vector3.one * radius); int3 val2 = WorldToGrid(center + Vector3.one * radius); for (int i = val.x; i <= val2.x; i++) { for (int j = val.y; j <= val2.y; j++) { for (int k = val.z; k <= val2.z; k++) { long cellKey = GetCellKey(new int3(i, j, k)); if (!_cells.TryGetValue(cellKey, out List value) || value == null) { continue; } int count = value.Count; for (int l = 0; l < count; l++) { VoxelEntry voxelEntry = value[l]; Vector3 val3 = voxelEntry.Position - center; if (((Vector3)(ref val3)).sqrMagnitude <= num) { results.Add(voxelEntry.Item); } } } } } } private List AllocateCellList() { if (_cellListPool.Count > 0) { int index = _cellListPool.Count - 1; List list = _cellListPool[index]; _cellListPool.RemoveAt(index); list.Clear(); return list; } return new List(16); } private void RecycleCellList(List list) { if (list != null) { list.Clear(); if (_cellListPool.Count < 256) { _cellListPool.Add(list); } } } } } namespace PeakOptimizer.Core.Rendering { public class HiZOcclusionCuller : MonoBehaviour { public struct FrameCameraData { public int FrameId; public float4x4 GpuViewProjMatrix; public float3 CameraPosition; public bool GraphicsUVStartsAtTop; public quaternion CapturedRotation; } [BurstCompile(/*Could not decode attribute arguments.*/)] public struct BuildHiZPyramidJob : IJob { [ReadOnly] public NativeArray BaseDepth; public NativeArray PyramidBuffer; [ReadOnly] public NativeArray MipOffsets; [ReadOnly] public bool UsesReversedZ; public void Execute() { int num = 32768; for (int i = 0; i < num; i++) { PyramidBuffer[i] = BaseDepth[i]; } int num2 = 256; int num3 = 128; int num4 = 0; for (int j = 1; j < 9; j++) { int num5 = math.max(1, num2 >> 1); int num6 = math.max(1, num3 >> 1); int num7 = MipOffsets[j]; for (int k = 0; k < num6; k++) { int num8 = k * 2; int num9 = math.min(num3 - 1, num8 + 1); for (int l = 0; l < num5; l++) { int num10 = l * 2; int num11 = math.min(num2 - 1, num10 + 1); float num12 = PyramidBuffer[num4 + num8 * num2 + num10]; float num13 = PyramidBuffer[num4 + num8 * num2 + num11]; float num14 = PyramidBuffer[num4 + num9 * num2 + num10]; float num15 = PyramidBuffer[num4 + num9 * num2 + num11]; float num16 = ((!UsesReversedZ) ? math.max(math.max(num12, num13), math.max(num14, num15)) : math.min(math.min(num12, num13), math.min(num14, num15))); PyramidBuffer[num7 + k * num5 + l] = num16; } } num4 = num7; num2 = num5; num3 = num6; } } } [BurstCompile(/*Could not decode attribute arguments.*/)] public struct BurstHiZChunkCullJob : IJobParallelFor { [ReadOnly] public NativeArray ChunkCenters; [ReadOnly] public NativeArray ChunkExtents; [ReadOnly] public NativeArray PyramidBuffer; [ReadOnly] public NativeArray MipOffsets; [ReadOnly] public float4x4 ViewProjMatrix; [ReadOnly] public float3 CameraPosition; [ReadOnly] public float MinSafeDistanceSqr; [ReadOnly] public float ConservativeDilation; [ReadOnly] public float DepthBias; [ReadOnly] public bool UsesReversedZ; [ReadOnly] public bool GraphicsUVStartsAtTop; [WriteOnly] public NativeArray VisibilityResults; public void Execute(int index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: 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_0070: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: 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_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0112: 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_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) float3 val = ChunkCenters[index]; float3 val2 = ChunkExtents[index]; float3 val3 = val - CameraPosition; if (math.lengthsq(val3) <= MinSafeDistanceSqr) { VisibilityResults[index] = 1; return; } float3 val4 = val2 * (1f + ConservativeDilation); float3 val5 = val - val4; float3 val6 = val + val4; int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; int num5 = 0; int num6 = 0; int num7 = 0; float num8 = 1f; float num9 = 0f; float num10 = 1f; float num11 = 0f; float num12 = (UsesReversedZ ? 0f : 1f); float3 val7 = default(float3); for (int i = 0; i < 8; i++) { ((float3)(ref val7))..ctor(((i & 1) == 0) ? val5.x : val6.x, ((i & 2) == 0) ? val5.y : val6.y, ((i & 4) == 0) ? val5.z : val6.z); float4 val8 = math.mul(ViewProjMatrix, new float4(val7, 1f)); float w = val8.w; if (w <= 0.0001f) { num7++; num5++; continue; } if (val8.x < 0f - w) { num++; } if (val8.x > w) { num2++; } if (val8.y < 0f - w) { num3++; } if (val8.y > w) { num4++; } if (val8.z < 0f) { num5++; } if (val8.z > w) { num6++; } float num13 = 1f / w; float num14 = val8.x * num13 * 0.5f + 0.5f; float num15 = val8.y * num13 * 0.5f + 0.5f; float num16 = val8.z * num13; num8 = math.min(num8, num14); num9 = math.max(num9, num14); num10 = math.min(num10, num15); num11 = math.max(num11, num15); num12 = ((!UsesReversedZ) ? math.min(num12, num16) : math.max(num12, num16)); } if (num == 8 || num2 == 8 || num3 == 8 || num4 == 8 || num5 == 8 || num6 == 8 || num7 == 8) { VisibilityResults[index] = 0; return; } if (num7 > 0) { VisibilityResults[index] = 1; return; } if (GraphicsUVStartsAtTop) { float num17 = num10; num10 = 1f - num11; num11 = 1f - num17; } num8 = math.clamp(num8, 0f, 1f); num9 = math.clamp(num9, 0f, 1f); num10 = math.clamp(num10, 0f, 1f); num11 = math.clamp(num11, 0f, 1f); float num18 = (num9 - num8) * 256f; float num19 = (num11 - num10) * 128f; float num20 = math.max(num18, num19); int num21 = (int)math.clamp(math.ceil(math.log2(math.max(1f, num20))), 0f, 8f); int num22 = math.max(1, 256 >> num21); int num23 = math.max(1, 128 >> num21); int num24 = MipOffsets[num21]; int num25 = (int)math.clamp(math.floor(num8 * (float)num22), 0f, (float)(num22 - 1)); int num26 = (int)math.clamp(math.floor(num9 * (float)num22), 0f, (float)(num22 - 1)); int num27 = (int)math.clamp(math.floor(num10 * (float)num23), 0f, (float)(num23 - 1)); int num28 = (int)math.clamp(math.floor(num11 * (float)num23), 0f, (float)(num23 - 1)); float num29 = (UsesReversedZ ? 1f : 0f); for (int j = num27; j <= num28; j++) { for (int k = num25; k <= num26; k++) { float num30 = PyramidBuffer[num24 + j * num22 + k]; num29 = ((!UsesReversedZ) ? math.max(num29, num30) : math.min(num29, num30)); } } if (UsesReversedZ) { if (num12 < num29 - DepthBias) { VisibilityResults[index] = 0; return; } } else if (num12 > num29 + DepthBias) { VisibilityResults[index] = 0; return; } VisibilityResults[index] = 1; } } private class TrackedProp { public Renderer Renderer = null; public float3 Center; public float3 Extents; public bool IsCulledByMod; } private class SpatialChunk { public int3 GridCoord; public float3 BoundsMin; public float3 BoundsMax; public float3 Center; public float3 Extents; public readonly List Props = new List(64); public bool IsCulledByMod; public int ConsecutiveOccludedFrames; public void RecalculateBounds() { //IL_0028: 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_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: 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_0088: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: 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_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) if (Props.Count != 0) { BoundsMin = new float3(float.MaxValue, float.MaxValue, float.MaxValue); BoundsMax = new float3(float.MinValue, float.MinValue, float.MinValue); for (int i = 0; i < Props.Count; i++) { TrackedProp trackedProp = Props[i]; BoundsMin = math.min(BoundsMin, trackedProp.Center - trackedProp.Extents); BoundsMax = math.max(BoundsMax, trackedProp.Center + trackedProp.Extents); } Center = (BoundsMin + BoundsMax) * 0.5f; Extents = (BoundsMax - BoundsMin) * 0.5f; } } } public const int HiZBaseWidth = 256; public const int HiZBaseHeight = 128; public const int HiZMipLevels = 9; public const int TotalPyramidFloats = 43691; public const int MaxTrackedRenderers = 20480; public const int MaxChunks = 1024; public const float ChunkCellSize = 24f; public const int OcclusionHysteresisThreshold = 4; private static readonly int[] MipOffsets = new int[9] { 0, 32768, 40960, 43008, 43520, 43648, 43680, 43688, 43690 }; private const float UpdateIntervalSeconds = 0.04f; private const float ConservativeDilationAmount = 0.12f; private const float OcclusionDepthBias = 0.003f; private const float InitialPropScanDelay = 3f; public const float AngularVelocityGateDeg = 50f; public const float MaxStaleAngleDeg = 18f; private readonly Dictionary _chunkMap = new Dictionary(512); private readonly List _activeChunks = new List(1024); private readonly HashSet _currentlyCulled = new HashSet(); private readonly Queue _inFlightFrameQueue = new Queue(8); private NativeArray _chunkCenters; private NativeArray _chunkExtents; private NativeArray _hizPyramidBuffer; private NativeArray _visibilityResults; private NativeArray _mipOffsetsBuffer; private RenderTexture? _downsampleDepthRt; private Camera? _cachedCamera; private bool _buffersAllocated = false; private bool _isReadbackPending = false; private float _nextUpdateTime; private bool _pendingInitialScan = false; private float _initialScanTime; private float _readbackTimeoutTime; private quaternion _lastCamRotation = quaternion.identity; private float _cameraAngularVelocityDeg = 0f; public static HiZOcclusionCuller? Instance { get; private set; } public static void EnsureInitialized() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown if (!((Object)(object)Instance != (Object)null)) { GameObject val = new GameObject("[PeakOptimizer_HiZCuller]"); Object.DontDestroyOnLoad((Object)(object)val); Instance = val.AddComponent(); } } private void Awake() { Instance = this; AllocateBuffers(); CreateRenderTexture(); SceneManager.sceneLoaded += OnSceneLoaded; } private void AllocateBuffers() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002a: 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) if (!_buffersAllocated) { _chunkCenters = new NativeArray(1024, (Allocator)4, (NativeArrayOptions)1); _chunkExtents = new NativeArray(1024, (Allocator)4, (NativeArrayOptions)1); _hizPyramidBuffer = new NativeArray(43691, (Allocator)4, (NativeArrayOptions)1); _visibilityResults = new NativeArray(1024, (Allocator)4, (NativeArrayOptions)1); _mipOffsetsBuffer = new NativeArray(9, (Allocator)4, (NativeArrayOptions)1); for (int i = 0; i < 9; i++) { _mipOffsetsBuffer[i] = MipOffsets[i]; } _buffersAllocated = true; } } private void CreateRenderTexture() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown if (!((Object)(object)_downsampleDepthRt != (Object)null)) { _downsampleDepthRt = new RenderTexture(256, 128, 0, (RenderTextureFormat)14) { filterMode = (FilterMode)0, wrapMode = (TextureWrapMode)1, useMipMap = false, name = "PeakOptimizer_HiZ_DepthDownsample" }; _downsampleDepthRt.Create(); } } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { RestoreCulledRenderers(); _chunkMap.Clear(); _activeChunks.Clear(); _inFlightFrameQueue.Clear(); _isReadbackPending = false; _pendingInitialScan = true; _initialScanTime = Time.time + 3f; _nextUpdateTime = Time.time + 3f + 0.2f; } private void RestoreCulledRenderers() { for (int i = 0; i < _activeChunks.Count; i++) { SpatialChunk spatialChunk = _activeChunks[i]; if (!spatialChunk.IsCulledByMod) { continue; } for (int j = 0; j < spatialChunk.Props.Count; j++) { TrackedProp trackedProp = spatialChunk.Props[j]; if (trackedProp.IsCulledByMod && (Object)(object)trackedProp.Renderer != (Object)null) { trackedProp.Renderer.enabled = true; trackedProp.IsCulledByMod = false; } } spatialChunk.IsCulledByMod = false; spatialChunk.ConsecutiveOccludedFrames = 0; } _currentlyCulled.Clear(); } private void ScanProps() { //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02d5: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_0376: Unknown result type (might be due to invalid IL or missing references) //IL_0378: Unknown result type (might be due to invalid IL or missing references) //IL_0380: Unknown result type (might be due to invalid IL or missing references) //IL_038c: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Unknown result type (might be due to invalid IL or missing references) //IL_03a2: Unknown result type (might be due to invalid IL or missing references) //IL_03a7: Unknown result type (might be due to invalid IL or missing references) Renderer[] array = Object.FindObjectsByType((FindObjectsInactive)0, (FindObjectsSortMode)0); int num = LayerMask.GetMask(new string[3] { "Default", "Prop", "Props" }); if (num == 0) { num = 1048577; } int num2 = 0; float3 val2 = default(float3); int3 val3 = default(int3); foreach (Renderer val in array) { if ((Object)(object)val == (Object)null || !val.enabled || !(val is MeshRenderer) || (Object)(object)((Component)val).GetComponentInParent() != (Object)null || (Object)(object)((Component)val).GetComponentInParent() != (Object)null) { continue; } Material sharedMaterial = val.sharedMaterial; if ((Object)(object)sharedMaterial != (Object)null) { if (sharedMaterial.renderQueue >= 2500) { continue; } string text = (((Object)(object)sharedMaterial.shader != (Object)null) ? ((Object)sharedMaterial.shader).name : string.Empty); if (text.IndexOf("Transparent", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Unlit", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Particles", StringComparison.OrdinalIgnoreCase) >= 0) { continue; } } string name = ((Object)((Component)val).gameObject).name; if (name.IndexOf("fog", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("cloud", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("mist", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("water", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("atmosphere", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("sky", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("vfx", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("smoke", StringComparison.OrdinalIgnoreCase) >= 0 || ((1 << ((Component)val).gameObject.layer) & num) == 0 || num2 >= 20480) { continue; } Bounds bounds = val.bounds; ((float3)(ref val2))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).center.y, ((Bounds)(ref bounds)).center.z); ((int3)(ref val3))..ctor((int)math.floor(val2.x / 24f), (int)math.floor(val2.y / 24f), (int)math.floor(val2.z / 24f)); if (!_chunkMap.TryGetValue(val3, out SpatialChunk value)) { if (_activeChunks.Count >= 1024) { continue; } value = new SpatialChunk { GridCoord = val3, IsCulledByMod = false, ConsecutiveOccludedFrames = 0 }; _chunkMap[val3] = value; _activeChunks.Add(value); } bool flag = false; for (int j = 0; j < value.Props.Count; j++) { if ((Object)(object)value.Props[j].Renderer == (Object)(object)val) { flag = true; break; } } if (!flag) { value.Props.Add(new TrackedProp { Renderer = val, Center = val2, Extents = new float3(((Bounds)(ref bounds)).extents.x, ((Bounds)(ref bounds)).extents.y, ((Bounds)(ref bounds)).extents.z), IsCulledByMod = false }); value.RecalculateBounds(); } } } private void Update() { if (_pendingInitialScan && Time.time >= _initialScanTime) { _pendingInitialScan = false; ScanProps(); } } private void LateUpdate() { //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_014b: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_022c: 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_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_024d: 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_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.EnableHiZOcclusionCulling.Value) { if (_currentlyCulled.Count > 0) { RestoreCulledRenderers(); } return; } if (_isReadbackPending && Time.time > _readbackTimeoutTime) { _isReadbackPending = false; _inFlightFrameQueue.Clear(); } if (Time.time < _nextUpdateTime || _isReadbackPending) { return; } _nextUpdateTime = Time.time + 0.04f; if ((Object)(object)_cachedCamera == (Object)null) { if ((Object)(object)MainCamera.instance != (Object)null) { _cachedCamera = ((Component)MainCamera.instance).GetComponent(); } if ((Object)(object)_cachedCamera == (Object)null) { _cachedCamera = Camera.main; } } if ((Object)(object)_cachedCamera == (Object)null || _activeChunks.Count == 0 || (Object)(object)_downsampleDepthRt == (Object)null) { return; } quaternion val = quaternion.op_Implicit(((Component)_cachedCamera).transform.rotation); float num = math.max(0.0001f, Time.deltaTime); float num2 = math.clamp(math.abs(math.dot(val, _lastCamRotation)), 0f, 1f); float num3 = math.degrees(2f * math.acos(num2)); _cameraAngularVelocityDeg = num3 / num; _lastCamRotation = val; if (_cameraAngularVelocityDeg > 50f) { if (_currentlyCulled.Count > 0) { RestoreCulledRenderers(); } return; } Camera? cachedCamera = _cachedCamera; cachedCamera.depthTextureMode = (DepthTextureMode)(cachedCamera.depthTextureMode | 1); Texture globalTexture = Shader.GetGlobalTexture("_CameraDepthTexture"); if ((Object)(object)globalTexture != (Object)null) { Graphics.Blit(globalTexture, _downsampleDepthRt); Matrix4x4 gPUProjectionMatrix = GL.GetGPUProjectionMatrix(_cachedCamera.projectionMatrix, true); Matrix4x4 val2 = gPUProjectionMatrix * _cachedCamera.worldToCameraMatrix; Vector3 position = ((Component)_cachedCamera).transform.position; _inFlightFrameQueue.Enqueue(new FrameCameraData { FrameId = Time.frameCount, GpuViewProjMatrix = float4x4.op_Implicit(val2), CameraPosition = new float3(position.x, position.y, position.z), GraphicsUVStartsAtTop = SystemInfo.graphicsUVStartsAtTop, CapturedRotation = val }); _isReadbackPending = true; _readbackTimeoutTime = Time.time + 0.5f; AsyncGPUReadback.Request((Texture)(object)_downsampleDepthRt, 0, (Action)OnDepthReadbackCompleted); } } private void OnDepthReadbackCompleted(AsyncGPUReadbackRequest request) { //IL_0057: 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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) _isReadbackPending = false; if (!((AsyncGPUReadbackRequest)(ref request)).hasError && _buffersAllocated && (Object)(object)_cachedCamera != (Object)null && _inFlightFrameQueue.Count > 0) { FrameCameraData frameData = _inFlightFrameQueue.Dequeue(); quaternion val = quaternion.op_Implicit(((Component)_cachedCamera).transform.rotation); float num = math.clamp(math.abs(math.dot(frameData.CapturedRotation, val)), 0f, 1f); float num2 = math.degrees(2f * math.acos(num)); if (num2 > 18f) { if (_currentlyCulled.Count > 0) { RestoreCulledRenderers(); } return; } NativeArray data = ((AsyncGPUReadbackRequest)(ref request)).GetData(0); if (data.Length >= 32768) { ExecuteHiZCulling(data, frameData); } } else if (_inFlightFrameQueue.Count > 0) { _inFlightFrameQueue.Dequeue(); } } private void ExecuteHiZCulling(NativeArray rawDepthData, FrameCameraData frameData) { //IL_0045: 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_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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: 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_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: 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_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) int num = math.min(_activeChunks.Count, 1024); if (num == 0) { return; } for (int i = 0; i < num; i++) { SpatialChunk spatialChunk = _activeChunks[i]; _chunkCenters[i] = spatialChunk.Center; _chunkExtents[i] = spatialChunk.Extents; } bool usesReversedZBuffer = SystemInfo.usesReversedZBuffer; BuildHiZPyramidJob buildHiZPyramidJob = new BuildHiZPyramidJob { BaseDepth = rawDepthData, PyramidBuffer = _hizPyramidBuffer, MipOffsets = _mipOffsetsBuffer, UsesReversedZ = usesReversedZBuffer }; JobHandle val = IJobExtensions.Schedule(buildHiZPyramidJob, default(JobHandle)); float value = OptimizationConfig.HiZSafeDistanceMeters.Value; BurstHiZChunkCullJob burstHiZChunkCullJob = new BurstHiZChunkCullJob { ChunkCenters = _chunkCenters, ChunkExtents = _chunkExtents, PyramidBuffer = _hizPyramidBuffer, MipOffsets = _mipOffsetsBuffer, ViewProjMatrix = frameData.GpuViewProjMatrix, CameraPosition = frameData.CameraPosition, MinSafeDistanceSqr = value * value, ConservativeDilation = 0.12f, DepthBias = 0.003f, UsesReversedZ = usesReversedZBuffer, GraphicsUVStartsAtTop = frameData.GraphicsUVStartsAtTop, VisibilityResults = _visibilityResults }; JobHandle val2 = IJobParallelForExtensions.Schedule(burstHiZChunkCullJob, num, 16, val); ((JobHandle)(ref val2)).Complete(); for (int j = 0; j < num; j++) { SpatialChunk spatialChunk2 = _activeChunks[j]; if (_visibilityResults[j] == 1) { spatialChunk2.ConsecutiveOccludedFrames = 0; if (!spatialChunk2.IsCulledByMod) { continue; } for (int k = 0; k < spatialChunk2.Props.Count; k++) { TrackedProp trackedProp = spatialChunk2.Props[k]; if (trackedProp.IsCulledByMod && (Object)(object)trackedProp.Renderer != (Object)null) { trackedProp.Renderer.enabled = true; trackedProp.IsCulledByMod = false; _currentlyCulled.Remove(trackedProp.Renderer); } } spatialChunk2.IsCulledByMod = false; continue; } spatialChunk2.ConsecutiveOccludedFrames++; if (spatialChunk2.ConsecutiveOccludedFrames < 4 || spatialChunk2.IsCulledByMod) { continue; } for (int l = 0; l < spatialChunk2.Props.Count; l++) { TrackedProp trackedProp2 = spatialChunk2.Props[l]; Renderer renderer = trackedProp2.Renderer; if ((Object)(object)renderer != (Object)null && renderer.enabled) { renderer.enabled = false; trackedProp2.IsCulledByMod = true; _currentlyCulled.Add(renderer); } } spatialChunk2.IsCulledByMod = true; } } private void OnDestroy() { SceneManager.sceneLoaded -= OnSceneLoaded; RestoreCulledRenderers(); if (_buffersAllocated) { if (_chunkCenters.IsCreated) { _chunkCenters.Dispose(); } if (_chunkExtents.IsCreated) { _chunkExtents.Dispose(); } if (_hizPyramidBuffer.IsCreated) { _hizPyramidBuffer.Dispose(); } if (_visibilityResults.IsCreated) { _visibilityResults.Dispose(); } if (_mipOffsetsBuffer.IsCreated) { _mipOffsetsBuffer.Dispose(); } _buffersAllocated = false; } if ((Object)(object)_downsampleDepthRt != (Object)null) { _downsampleDepthRt.Release(); Object.Destroy((Object)(object)_downsampleDepthRt); _downsampleDepthRt = null; } if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } } } namespace PeakOptimizer.Core.Physics { public class BatchPhysicsDispatcher : MonoBehaviour { public delegate void RaycastCallback(bool hasHit, RaycastHit hit); public delegate void RaycastContextCallback(bool hasHit, RaycastHit hit, object context); private struct RaycastQuery { public int QueryId; public Vector3 From; public Vector3 Direction; public float Distance; public int LayerMask; public RaycastCallback? Callback; public RaycastContextCallback? ContextCallback; public object? Context; } private const int InitialCapacity = 256; private readonly List _pendingQueries = new List(256); private readonly List _executingQueries = new List(256); private NativeArray _commands; private NativeArray _results; private JobHandle _batchJobHandle; private bool _isJobRunning = false; private int _allocatedCapacity = 0; public static BatchPhysicsDispatcher? Instance { get; private set; } public static void EnsureInitialized() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown if (!((Object)(object)Instance != (Object)null)) { GameObject val = new GameObject("[PeakOptimizer_PhysicsDispatcher]"); Object.DontDestroyOnLoad((Object)(object)val); Instance = val.AddComponent(); } } private void Awake() { Instance = this; ReallocateBuffers(256); } private void ReallocateBuffers(int capacity) { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007b: 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) if (_allocatedCapacity < capacity) { if (_commands.IsCreated) { _commands.Dispose(); } if (_results.IsCreated) { _results.Dispose(); } _allocatedCapacity = Mathf.NextPowerOfTwo(Mathf.Max(256, capacity)); _commands = new NativeArray(_allocatedCapacity, (Allocator)4, (NativeArrayOptions)1); _results = new NativeArray(_allocatedCapacity, (Allocator)4, (NativeArrayOptions)1); } } public void EnqueueLinecast(Vector3 from, Vector3 to, int layerMask, RaycastCallback callback) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_002c: 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) Vector3 val = to - from; float magnitude = ((Vector3)(ref val)).magnitude; if (magnitude <= 0.0001f) { callback?.Invoke(hasHit: false, default(RaycastHit)); return; } Vector3 direction = val / magnitude; _pendingQueries.Add(new RaycastQuery { QueryId = _pendingQueries.Count, From = from, Direction = direction, Distance = magnitude, LayerMask = layerMask, Callback = callback, ContextCallback = null, Context = null }); } public void EnqueueLinecast(Vector3 from, Vector3 to, int layerMask, RaycastContextCallback callback, object context) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0070: 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_002c: 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) Vector3 val = to - from; float magnitude = ((Vector3)(ref val)).magnitude; if (magnitude <= 0.0001f) { callback?.Invoke(hasHit: false, default(RaycastHit), context); return; } Vector3 direction = val / magnitude; _pendingQueries.Add(new RaycastQuery { QueryId = _pendingQueries.Count, From = from, Direction = direction, Distance = magnitude, LayerMask = layerMask, Callback = null, ContextCallback = callback, Context = context }); } private void Update() { //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: 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_00f6: 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_010e: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0113: 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_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) if (!OptimizationConfig.MasterEnabled.Value || !OptimizationConfig.EnableBatchedPhysicsJobs.Value) { return; } CompleteRunningJob(); int count = _pendingQueries.Count; if (count != 0) { ReallocateBuffers(count); _executingQueries.Clear(); _executingQueries.AddRange(_pendingQueries); _pendingQueries.Clear(); QueryParameters val = default(QueryParameters); for (int i = 0; i < count; i++) { RaycastQuery raycastQuery = _executingQueries[i]; ((QueryParameters)(ref val))..ctor(raycastQuery.LayerMask, false, (QueryTriggerInteraction)1, false); _commands[i] = new RaycastCommand(raycastQuery.From, raycastQuery.Direction, val, raycastQuery.Distance); } NativeArray subArray = _commands.GetSubArray(0, count); NativeArray subArray2 = _results.GetSubArray(0, count); int num = Mathf.Max(1, OptimizationConfig.PhysicsBatchSize.Value); _batchJobHandle = RaycastCommand.ScheduleBatch(subArray, subArray2, num, default(JobHandle)); _isJobRunning = true; } } private void LateUpdate() { CompleteRunningJob(); } private void CompleteRunningJob() { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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) if (!_isJobRunning) { return; } ((JobHandle)(ref _batchJobHandle)).Complete(); _isJobRunning = false; int count = _executingQueries.Count; for (int i = 0; i < count; i++) { RaycastHit hit = _results[i]; bool hasHit = (Object)(object)((RaycastHit)(ref hit)).collider != (Object)null; try { RaycastQuery raycastQuery = _executingQueries[i]; raycastQuery.Callback?.Invoke(hasHit, hit); if (raycastQuery.ContextCallback != null && raycastQuery.Context != null) { raycastQuery.ContextCallback(hasHit, hit, raycastQuery.Context); } } catch (Exception arg) { Debug.LogError((object)$"[PeakOptimizer] Exception in physics callback: {arg}"); } } _executingQueries.Clear(); } private void OnDestroy() { if (_isJobRunning) { ((JobHandle)(ref _batchJobHandle)).Complete(); _isJobRunning = false; } if (_commands.IsCreated) { _commands.Dispose(); } if (_results.IsCreated) { _results.Dispose(); } if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } } } namespace PeakOptimizer.Core.Lighting { public class AsyncLightVolumeCache : MonoBehaviour { private struct CachedSample { public float Alpha; public float Timestamp; } private const float QuantizationStep = 1.5f; private const float StalenessThresholdSeconds = 0.2f; private const float PruneIntervalSeconds = 5f; private readonly Dictionary _cache = new Dictionary(256); private readonly List _staleKeys = new List(64); private float _nextPruneTime; public static AsyncLightVolumeCache? Instance { get; private set; } public static void EnsureInitialized() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown if (!((Object)(object)Instance != (Object)null)) { GameObject val = new GameObject("[PeakOptimizer_LightCache]"); Object.DontDestroyOnLoad((Object)(object)val); Instance = val.AddComponent(); } } private void Awake() { Instance = this; } public float SampleAlpha(Vector3 worldPos) { //IL_0001: 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) long key = QuantizePosition(worldPos); float time = Time.time; if (_cache.TryGetValue(key, out var value) && time - value.Timestamp < 0.2f) { return value.Alpha; } float num = ReadFromLightVolume(worldPos); _cache[key] = new CachedSample { Alpha = num, Timestamp = time }; return num; } private void LateUpdate() { if (_cache.Count > 1024 && Time.time >= _nextPruneTime) { _nextPruneTime = Time.time + 5f; PruneDistantEntries(); } } private void PruneDistantEntries() { float time = Time.time; _staleKeys.Clear(); foreach (KeyValuePair item in _cache) { if (time - item.Value.Timestamp > 10f) { _staleKeys.Add(item.Key); } } for (int i = 0; i < _staleKeys.Count; i++) { _cache.Remove(_staleKeys[i]); } } private static float ReadFromLightVolume(Vector3 worldPos) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) LightVolume val = LightVolume.Instance(); if ((Object)(object)val == (Object)null) { return 0f; } try { return val.SamplePosition(worldPos, false).a; } catch { return 0f; } } private static long QuantizePosition(Vector3 pos) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) int num = (int)math.floor(pos.x / 1.5f); int num2 = (int)math.floor(pos.y / 1.5f); int num3 = (int)math.floor(pos.z / 1.5f); long num4 = num & 0x1FFFFF; long num5 = num2 & 0x1FFFFF; long num6 = num3 & 0x1FFFFF; return (num4 << 42) | (num5 << 21) | num6; } public void InvalidateAll() { _cache.Clear(); } private void OnDestroy() { _cache.Clear(); if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } } } namespace PeakOptimizer.Core.Diagnostics { public class PeakTelemetryHUD : MonoBehaviour { private bool _visible = false; private const int FrameBufferSize = 120; private readonly float[] _frameTimeBuffer = new float[120]; private int _frameIndex = 0; private float _fps = 0f; private float _avgFrameTimeMs = 0f; private float _onePercentLowFps = 0f; private float _maxFrameTimeMs = 0f; private const float CensusScanInterval = 0.75f; private float _timeUntilNextScan = 0f; private string _cachedBiomeName = "Unknown"; private int _cachedSegmentIndex = 0; private Vector3 _cachedPlayerPosition = Vector3.zero; private int _totalLights = 0; private int _shadowLights = 0; private int _totalParticleSystems = 0; private int _activeParticleCount = 0; private int _totalMeshRenderers = 0; private int _totalSkinnedRenderers = 0; private int _totalColliders = 0; private int _totalRigidbodies = 0; private long _gcHeapMemoryMb = 0L; private int _gcCollections = 0; private GUIStyle? _windowStyle; private GUIStyle? _headerStyle; private GUIStyle? _sectionStyle; private GUIStyle? _labelStyle; private GUIStyle? _valueGoodStyle; private GUIStyle? _valueWarnStyle; private GUIStyle? _valueAlertStyle; private Texture2D? _bgTexture; public static PeakTelemetryHUD? Instance { get; private set; } public static void EnsureInitialized() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown if (!((Object)(object)Instance != (Object)null)) { GameObject val = new GameObject("PeakOptimizer_TelemetryHUD"); Instance = val.AddComponent(); Object.DontDestroyOnLoad((Object)(object)val); } } private void Awake() { if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this) { Object.Destroy((Object)(object)((Component)this).gameObject); } else { Instance = this; } } private void Update() { if (Input.GetKeyDown((KeyCode)290)) { _visible = !_visible; } if (_visible) { float unscaledDeltaTime = Time.unscaledDeltaTime; if (unscaledDeltaTime > 0.0001f) { _frameTimeBuffer[_frameIndex] = unscaledDeltaTime; _frameIndex = (_frameIndex + 1) % 120; CalculateFrameMetrics(); } _timeUntilNextScan -= Time.unscaledDeltaTime; if (_timeUntilNextScan <= 0f) { _timeUntilNextScan = 0.75f; PerformSceneCensus(); } } } private void CalculateFrameMetrics() { float num = 0f; float num2 = 0f; int num3 = _frameTimeBuffer.Length; for (int i = 0; i < num3; i++) { float num4 = _frameTimeBuffer[i]; num += num4; if (num4 > num2) { num2 = num4; } } float num5 = num / (float)num3; _fps = ((num5 > 0f) ? (1f / num5) : 0f); _avgFrameTimeMs = num5 * 1000f; _maxFrameTimeMs = num2 * 1000f; float num6 = 0f; float num7 = 0f; for (int j = 0; j < num3; j++) { float num8 = _frameTimeBuffer[j]; if (num8 > num6) { num7 = num6; num6 = num8; } else if (num8 > num7) { num7 = num8; } } float num9 = (num6 + num7) * 0.5f; _onePercentLowFps = ((num9 > 0f) ? (1f / num9) : _fps); } private void PerformSceneCensus() { //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: 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_0069: 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_003c: 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_005f: Expected I4, but got Unknown //IL_00a7: 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_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Invalid comparison between Unknown and I4 _gcHeapMemoryMb = GC.GetTotalMemory(forceFullCollection: false) / 1048576; _gcCollections = GC.CollectionCount(0); try { if ((Object)(object)Singleton.Instance != (Object)null) { _cachedBiomeName = ((object)Singleton.Instance.GetCurrentBiome()/*cast due to .constrained prefix*/).ToString(); _cachedSegmentIndex = (int)Singleton.Instance.GetCurrentSegment(); } else { Scene activeScene = SceneManager.GetActiveScene(); _cachedBiomeName = ((Scene)(ref activeScene)).name; } } catch { _cachedBiomeName = "Unavailable"; } try { if ((Object)(object)Character.localCharacter != (Object)null) { _cachedPlayerPosition = ((Component)Character.localCharacter).transform.position; } } catch { _cachedPlayerPosition = Vector3.zero; } try { Light[] array = Object.FindObjectsByType((FindObjectsSortMode)0); _totalLights = array.Length; int num = 0; for (int i = 0; i < array.Length; i++) { if ((Object)(object)array[i] != (Object)null && ((Behaviour)array[i]).isActiveAndEnabled && (int)array[i].shadows > 0) { num++; } } _shadowLights = num; ParticleSystem[] array2 = Object.FindObjectsByType((FindObjectsSortMode)0); _totalParticleSystems = array2.Length; int num2 = 0; for (int j = 0; j < array2.Length; j++) { if ((Object)(object)array2[j] != (Object)null && array2[j].isPlaying) { num2 += array2[j].particleCount; } } _activeParticleCount = num2; _totalMeshRenderers = Object.FindObjectsByType((FindObjectsSortMode)0).Length; _totalSkinnedRenderers = Object.FindObjectsByType((FindObjectsSortMode)0).Length; _totalColliders = Object.FindObjectsByType((FindObjectsSortMode)0).Length; _totalRigidbodies = Object.FindObjectsByType((FindObjectsSortMode)0).Length; } catch { } } private void InitializeStyles() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown //IL_009c: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Expected O, but got Unknown //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0110: 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_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Expected O, but got Unknown //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Expected O, but got Unknown //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Expected O, but got Unknown //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Expected O, but got Unknown //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Expected O, but got Unknown if ((Object)(object)_bgTexture == (Object)null) { _bgTexture = new Texture2D(1, 1); _bgTexture.SetPixel(0, 0, new Color(0.07f, 0.08f, 0.1f, 0.92f)); _bgTexture.Apply(); } if (_windowStyle == null) { GUIStyle val = new GUIStyle(GUI.skin.box); val.normal.background = _bgTexture; val.padding = new RectOffset(14, 14, 12, 12); _windowStyle = val; } if (_headerStyle == null) { GUIStyle val2 = new GUIStyle(GUI.skin.label) { fontSize = 13, fontStyle = (FontStyle)1 }; val2.normal.textColor = new Color(0.35f, 0.85f, 0.95f); _headerStyle = val2; } if (_sectionStyle == null) { GUIStyle val3 = new GUIStyle(GUI.skin.label) { fontSize = 11, fontStyle = (FontStyle)1 }; val3.normal.textColor = new Color(0.85f, 0.85f, 0.85f); _sectionStyle = val3; } if (_labelStyle == null) { GUIStyle val4 = new GUIStyle(GUI.skin.label) { fontSize = 11 }; val4.normal.textColor = new Color(0.7f, 0.72f, 0.75f); _labelStyle = val4; } if (_valueGoodStyle == null) { GUIStyle val5 = new GUIStyle(GUI.skin.label) { fontSize = 11, fontStyle = (FontStyle)1 }; val5.normal.textColor = new Color(0.4f, 0.9f, 0.45f); _valueGoodStyle = val5; } if (_valueWarnStyle == null) { GUIStyle val6 = new GUIStyle(GUI.skin.label) { fontSize = 11, fontStyle = (FontStyle)1 }; val6.normal.textColor = new Color(0.95f, 0.8f, 0.25f); _valueWarnStyle = val6; } if (_valueAlertStyle == null) { GUIStyle val7 = new GUIStyle(GUI.skin.label) { fontSize = 11, fontStyle = (FontStyle)1 }; val7.normal.textColor = new Color(0.95f, 0.35f, 0.35f); _valueAlertStyle = val7; } } private void OnGUI() { //IL_003b: Unknown result type (might be due to invalid IL or missing references) if (_visible) { InitializeStyles(); float num = 360f; float num2 = 440f; Rect val = default(Rect); ((Rect)(ref val))..ctor(16f, 16f, num, num2); GUILayout.BeginArea(val, _windowStyle); GUILayout.Label("PEAK OPTIMIZER TELEMETRY [F9]", _headerStyle, Array.Empty()); DrawHorizontalSeparator(); GUILayout.Label("ENVIRONMENT & LOCATION", _sectionStyle, Array.Empty()); GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label("Biome:", _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }); GUILayout.Label($"{_cachedBiomeName} (Seg {_cachedSegmentIndex})", _valueGoodStyle, Array.Empty()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label("Position:", _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }); GUILayout.Label($"X: {_cachedPlayerPosition.x:F1} | Y: {_cachedPlayerPosition.y:F1} | Z: {_cachedPlayerPosition.z:F1}", _labelStyle, Array.Empty()); GUILayout.EndHorizontal(); DrawHorizontalSeparator(); GUILayout.Label("FRAME TIMING & STABILITY", _sectionStyle, Array.Empty()); GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label("FPS:", _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }); GUIStyle val2 = ((_fps >= 55f) ? _valueGoodStyle : ((_fps >= 30f) ? _valueWarnStyle : _valueAlertStyle)); GUILayout.Label($"{_fps:F0} FPS (1% Low: {_onePercentLowFps:F0})", val2, Array.Empty()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label("Frametime:", _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }); GUILayout.Label($"{_avgFrameTimeMs:F2} ms (Peak Spike: {_maxFrameTimeMs:F1} ms)", _labelStyle, Array.Empty()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label("GC / Heap:", _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }); GUILayout.Label($"{_gcHeapMemoryMb} MB (GC Passes: {_gcCollections})", _labelStyle, Array.Empty()); GUILayout.EndHorizontal(); DrawHorizontalSeparator(); GUILayout.Label("SCENE ENTITY CENSUS", _sectionStyle, Array.Empty()); GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label("Lights:", _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }); GUIStyle val3 = ((_shadowLights > 12) ? _valueWarnStyle : _labelStyle); GUILayout.Label($"{_totalLights} total ({_shadowLights} shadow casters)", val3, Array.Empty()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label("Particles:", _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }); GUIStyle val4 = ((_activeParticleCount > 2500) ? _valueWarnStyle : _labelStyle); GUILayout.Label($"{_totalParticleSystems} systems (~{_activeParticleCount} alive)", val4, Array.Empty()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label("Meshes:", _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }); GUILayout.Label($"{_totalMeshRenderers} static/mesh, {_totalSkinnedRenderers} skinned", _labelStyle, Array.Empty()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label("Physics:", _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }); GUILayout.Label($"{_totalColliders} colliders, {_totalRigidbodies} rigidbodies", _labelStyle, Array.Empty()); GUILayout.EndHorizontal(); DrawHorizontalSeparator(); GUILayout.Label("OPTIMIZER ENGINES", _sectionStyle, Array.Empty()); string text = (OptimizationConfig.EnableBatchedPhysics.Value ? "ACTIVE" : "OFF"); string text2 = (OptimizationConfig.EnableZeroGCBuffers.Value ? "ACTIVE" : "OFF"); string text3 = (OptimizationConfig.EnableFoliageAndTrapCulling.Value ? "ACTIVE" : "OFF"); GUILayout.Label("Threading: " + text + " | Zero-GC: " + text2 + " | Culling: " + text3, _labelStyle, Array.Empty()); int culledCount = SmallRockCullingPatch.CulledCount; int culledCount2 = AmbientParticleDistanceCullerPatch.CulledCount; GUILayout.Label($"Sleeping: {culledCount} props | {culledCount2} particle emitters", _valueGoodStyle, Array.Empty()); GUILayout.EndArea(); } } private void DrawHorizontalSeparator() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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_005a: Unknown result type (might be due to invalid IL or missing references) GUILayout.Space(3f); Rect rect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(1f) }); GUI.color = new Color(0.25f, 0.28f, 0.32f, 0.7f); GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture); GUI.color = Color.white; GUILayout.Space(4f); } private void OnDestroy() { if ((Object)(object)_bgTexture != (Object)null) { Object.Destroy((Object)(object)_bgTexture); } } } } namespace PeakOptimizer.Configuration { public static class OptimizationConfig { public class ConfigEntryWrapper { public T Value { get; } public ConfigEntryWrapper(T value) { Value = value; } } public static readonly ConfigEntryWrapper HiZSafeDistanceMeters = new ConfigEntryWrapper(35f); public static readonly ConfigEntryWrapper PhysicsBatchSize = new ConfigEntryWrapper(16); public static readonly ConfigEntryWrapper VoiceOcclusionUpdateRateSeconds = new ConfigEntryWrapper(0.05f); public static readonly ConfigEntryWrapper VoiceUpdateIntervalSeconds = new ConfigEntryWrapper(0.05f); public static readonly ConfigEntryWrapper VoxelCellSizeMeters = new ConfigEntryWrapper(16f); public static readonly ConfigEntryWrapper SmallRockCullDistance = new ConfigEntryWrapper(50f); public static ConfigEntry MasterEnabled { get; private set; } = null; public static ConfigEntry EnableTelemetryHUD { get; private set; } = null; public static ConfigEntry EnableBatchedPhysics { get; private set; } = null; public static ConfigEntry EnableZeroGCBuffers { get; private set; } = null; public static ConfigEntry EnableMultiplayerFixes { get; private set; } = null; public static ConfigEntry EnableFoliageAndTrapCulling { get; private set; } = null; public static ConfigEntry FoliageAndTrapCullDistance { get; private set; } = null; public static ConfigEntry EnableSmallPropCulling { get; private set; } = null; public static ConfigEntry EnableAmbientParticleCulling { get; private set; } = null; public static ConfigEntry AmbientParticleCullDistance { get; private set; } = null; public static ConfigEntry EnableShadowOptimizations { get; private set; } = null; public static ConfigEntry EnableGrassFrustumCulling { get; private set; } = null; public static ConfigEntry TerrainLodBias { get; private set; } = null; public static ConfigEntry EnableHiZOcclusionCulling { get; private set; } = null; public static ConfigEntry EnableBatchedPhysicsJobs => EnableBatchedPhysics; public static ConfigEntry EnableZeroGCFastBuffers => EnableZeroGCBuffers; public static ConfigEntry EnableSpatialVoxelCulling => EnableMultiplayerFixes; public static ConfigEntry EnableAsyncLightSampling => EnableMultiplayerFixes; public static ConfigEntry EnableDynamicBoneCulling => EnableFoliageAndTrapCulling; public static ConfigEntry EnableCitadelTrapOptimization => EnableFoliageAndTrapCulling; public static ConfigEntry DisableCitadelPointShadows => EnableShadowOptimizations; public static ConfigEntry EnableEngineBugFixes => EnableZeroGCBuffers; public static ConfigEntry OptimizeFogUpdates => EnableZeroGCBuffers; public static ConfigEntry OptimizeVoiceObscurance => EnableBatchedPhysics; public static ConfigEntry OptimizeBotPlayerSearch => EnableMultiplayerFixes; public static ConfigEntry CacheMaterialPropertyBlocks => EnableZeroGCBuffers; public static ConfigEntry SafeguardParticleCuller => EnableZeroGCBuffers; public static ConfigEntry CullDistantDynamicBones => EnableFoliageAndTrapCulling; public static ConfigEntry OptimizeShadowDistances => EnableShadowOptimizations; public static ConfigEntry OptimizeGrassFrustumCulling => EnableGrassFrustumCulling; public static ConfigEntry OptimizeLODScaling => MasterEnabled; public static ConfigEntry OptimizedLodBias => TerrainLodBias; public static ConfigEntry OptimizeSmallRockDecorations => EnableSmallPropCulling; public static ConfigEntry OptimizeGloomCalculations => EnableMultiplayerFixes; public static ConfigEntry OptimizeCitadelTraps => EnableFoliageAndTrapCulling; public static ConfigEntry OptimizeAdditionalLightShadows => EnableShadowOptimizations; public static ConfigEntry DisableAdditionalLightShadows => EnableShadowOptimizations; public static ConfigEntry SuppressRepetitiveHotpathLogs => EnableZeroGCBuffers; public static ConfigEntry OptimizeHBAOPerformance => MasterEnabled; public static ConfigEntryWrapper DynamicBoneMaxDistance => new ConfigEntryWrapper((FoliageAndTrapCullDistance != null) ? FoliageAndTrapCullDistance.Value : 50f); public static ConfigEntryWrapper CitadelTrapMaxDistance => new ConfigEntryWrapper((FoliageAndTrapCullDistance != null) ? FoliageAndTrapCullDistance.Value : 50f); public static void Initialize(ConfigFile config) { MasterEnabled = config.Bind("1. General", "MasterEnabled", true, "Master toggle for all PeakOptimizer systems."); EnableTelemetryHUD = config.Bind("1. General", "EnableTelemetryHUD", false, "Enables the in-game developer telemetry overlay toggled with F9."); EnableBatchedPhysics = config.Bind("2. CPU & Multithreading", "EnableBatchedPhysics", true, "Offloads voice chat linecasts and wind shelter checks to background CPU worker threads."); EnableZeroGCBuffers = config.Bind("2. CPU & Multithreading", "EnableZeroGCBuffers", true, "Eliminates GC heap allocations during rockfalls, dynamite detonations, and continuous physics checks."); EnableMultiplayerFixes = config.Bind("2. CPU & Multithreading", "EnableMultiplayerFixes", true, "Optimizes heavy multiplayer distance loops, Gloom checks, and bot spatial queries."); EnableFoliageAndTrapCulling = config.Bind("3. World & Environment Culling", "EnableFoliageAndTrapCulling", true, "Pauses physics updates for distant foliage and Gloom/Citadel traps beyond the cull distance."); FoliageAndTrapCullDistance = config.Bind("3. World & Environment Culling", "FoliageAndTrapCullDistance", 50f, "Distance in meters beyond which distant foliage physics and Gloom/Citadel traps are paused."); EnableSmallPropCulling = config.Bind("3. World & Environment Culling", "EnableSmallPropCulling", true, "Culls tiny decorative ground pebbles and debris beyond 50 meters."); EnableAmbientParticleCulling = config.Bind("3. World & Environment Culling", "EnableAmbientParticleCulling", true, "Puts distant ambient torches, braziers, and idle trap particle emitters to sleep."); AmbientParticleCullDistance = config.Bind("3. World & Environment Culling", "AmbientParticleCullDistance", 50f, "Distance in meters beyond which distant ambient particle emitters are put to sleep."); EnableShadowOptimizations = config.Bind("4. Graphics & Rendering", "EnableShadowOptimizations", true, "Disables heavy secondary Citadel torch shadows and fixes shadow acne on mountain terrain."); EnableGrassFrustumCulling = config.Bind("4. Graphics & Rendering", "EnableGrassFrustumCulling", true, "Skips compute shader grass generation outside the camera field of view."); TerrainLodBias = config.Bind("4. Graphics & Rendering", "TerrainLodBias", 0.6f, "LOD bias multiplier for distant terrain and rock meshes (0.6 = recommended, 1.0 = vanilla)."); EnableHiZOcclusionCulling = config.Bind("5. Experimental (Use at your own risk)", "EnableHiZOcclusionCulling", false, "Experimental Hi-Z chunk occlusion culling. (Disabled by default. Enable at your own risk)."); } } }