Decompiled source of PeakOptimizer v2.1.1
PeakOptimizer.dll
Decompiled 15 hours ago
The result has been truncated due to the large size, download it to view full contents!
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<ParticleEntry> s_particles = new List<ParticleEntry>(2048); private static readonly HashSet<int> s_registeredIds = new HashSet<int>(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<Character>() != (Object)null) && !((Object)(object)((Component)ps).GetComponentInParent<Item>() != (Object)null) && !((Object)(object)((Component)ps).GetComponentInParent<ItemComponent>() != (Object)null) && !((Object)(object)((Component)ps).GetComponentInParent<Campfire>() != (Object)null)) { ParticleSystemRenderer component = ((Component)ps).GetComponent<ParticleSystemRenderer>(); 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<ParticleSystem>(true); for (int i = 0; i < componentsInChildren.Length; i++) { RegisterParticleSystem(componentsInChildren[i]); } } } public static void ScanSceneParticles() { try { ParticleSystem[] array = Object.FindObjectsByType<ParticleSystem>((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<Character> 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<Character> 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<RecentActivity> s_recentExplosions = new List<RecentActivity>(32); private static readonly List<RecentActivity> s_recentFlares = new List<RecentActivity>(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<RecentActivity> 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<GameObject>(((Component)___smokeVFXPrefab).gameObject, position, ((Component)__instance).transform.rotation); TrackNetworkedObject component = val.GetComponent<TrackNetworkedObject>(); if ((Object)(object)component != (Object)null) { component.SetObject(___trackable); } if (num >= 3) { ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>(); 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<Character> 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<Character> 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>(); } 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<GrassDataProvider>(); } if ((Object)(object)___DataProvider == (Object)null) { return false; } if (___GrassPointsBuffer == null || ___DataProvider.IsDirty()) { ComputeBuffer obj = ___GrassPointsBuffer; if (obj != null) { obj.Dispose(); } ___GrassPointsBuffer = ___DataProvider.GetData(); } if (___GrassPointsBuffer == null || ___GrassPointsBuffer.count == 0) { return false; } if ((Object)(object)MainCamera.instance == (Object)null) { return false; } Vector3 position = ((Component)MainCamera.instance).transform.position; if (GrassChunking.ShouldDrawChunk(GrassChunking.GetChunkFromPosition(float3.op_Implicit(position)), __instance.CurrentChunk)) { if (___GeometryBuffer == null) { ___GeometryBuffer = new ComputeBuffer(10000, 148, (ComputeBufferType)2); ___ArgumentsBuffer = new ComputeBuffer(1, 16, (ComputeBufferType)256); } ___GeometryBuffer.SetCounterValue(0u); ___ArgumentsBuffer.SetData((Array)___argsBufferReset); int kernelID = ___grassGeometryKernel.kernelID; ComputeShader grassComputeShader = __instance.grassComputeShader; if ((Object)(object)grassComputeShader == (Object)null) { return false; } grassComputeShader.SetBuffer(kernelID, "GeometryBuffer", ___GeometryBuffer); grassComputeShader.SetBuffer(kernelID, "IndirectArgsBuffer", ___ArgumentsBuffer); grassComputeShader.SetBuffer(kernelID, "GrassPoints", ___GrassPointsBuffer); grassComputeShader.SetFloat(TimePropId, Time.realtimeSinceStartup); grassComputeShader.SetVector(CameraWSPosPropId, Vector4.op_Implicit(position)); SharedPropertyBlock.Clear(); SharedPropertyBlock.SetBuffer(GeometryBufferPropId, ___GeometryBuffer); ___grassGeometryKernel.Dispatch(new int3(___GrassPointsBuffer.count, 1, 1)); Bounds val = default(Bounds); ((Bounds)(ref val))..ctor(((Component)__instance).transform.position, Vector3.one * 500f); Graphics.DrawProceduralIndirect(__instance.m_grassRenderMaterial, val, (MeshTopology)0, ___ArgumentsBuffer, 0, (Camera)null, SharedPropertyBlock, (ShadowCastingMode)0, true, 0); } return false; } } [HarmonyPatch(typeof(PostHandler))] public static class HBAOOptimizationPatch { private const float MaxAoDistanceMeters = 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<HBAO>(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<Transform>(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<Transform>(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<Character> 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<Light>((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<Light>((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<Character>() != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent<Item>() != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent<ItemComponent>() != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent<Campfire>() != (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<Quality>)(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<RockEntry> s_rocks = new List<RockEntry>(1024); private static readonly HashSet<int> s_registeredIds = new HashSet<int>(); private static int s_processIndex = 0; private static bool s_hooked = false; public static 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<MeshRenderer>(true); foreach (MeshRenderer val in componentsInChildren) { if ((Object)(object)val == (Object)null) { continue; } int instanceID = ((Object)val).GetInstanceID(); if (s_registeredIds.Contains(instanceID)) { continue; } Bounds bounds = ((Renderer)val).bounds; Vector3 extents = ((Bounds)(ref bounds)).extents; if (((Vector3)(ref extents)).sqrMagnitude <= 2.25f) { int layer = ((Component)val).gameObject.layer; if (layer == 0 || layer == LayerMask.NameToLayer("Terrain")) { s_registeredIds.Add(instanceID); s_rocks.Add(new RockEntry(val, ((Component)val).transform.position)); } } } } [HarmonyPatch(typeof(RockSpawner), "Go")] [HarmonyPostfix] public static void RockSpawner_Go_Postfix(RockSpawner __instance) { if ((Object)(object)__instance != (Object)null) { RegisterSpawnerChildren(((Component)__instance).gameObject); } } [HarmonyPatch(typeof(DecorSpawner), "ExecuteImmediately")] [HarmonyPostfix] public static void DecorSpawner_ExecuteImmediately_Postfix(DecorSpawner __instance) { if ((Object)(object)__instance != (Object)null) { RegisterSpawnerChildren(((Component)__instance).gameObject); } } [HarmonyPatch(typeof(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<VoiceObscuranceFilter, ThreadedFilterState> StateCache = new ConditionalWeakTable<VoiceObscuranceFilter, ThreadedFilterState>(); 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<PeakHandler>.Instance != (Object)null && Singleton<PeakHandler>.Instance.isPlayingCinematic) { ((Behaviour)__instance.highPass).enabled = false; ((Behaviour)__instance.lowPass).enabled = false; ((Behaviour)__instance.reverb).enabled = false; ((Behaviour)__instance.echo).enabled = false; return false; } float 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<Character, ShelterState> s_shelterCache = new ConditionalWeakTable<Character, ShelterState>(); private static readonly BatchPhysicsDispatcher.RaycastContextCallback s_onShelterRaycastCompleted = OnShelterRaycastCompleted; private const float QueryIntervalSeconds = 0.1f; private static readonly AddForceAtPositionDelegate? s_addForceDelegate = AccessTools.MethodDelegate<AddForceAtPositionDelegate>(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<Parasol>(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<float3> Positions; [ReadOnly] public float3 QueryOrigin; [ReadOnly] public float RadiusSqr; [ReadOnly] public float3 LookDirection; [ReadOnly] public float CosMaxAngle; [ReadOnly] public bool UseAngleFilter; [WriteOnly] public NativeArray<int> MatchingIndices; public NativeArray<int> 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<float3> s_positionsBuffer; private static NativeArray<int> s_resultsBuffer; private static NativeArray<int> 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<int>(1, (Allocator)4, (NativeArrayOptions)1); } s_positionsBuffer = new NativeArray<float3>(num, (Allocator)4, (NativeArrayOptions)1); s_resultsBuffer = new NativeArray<int>(num, (Allocator)4, (NativeArrayOptions)1); s_currentCapacity = num; s_isInitialized = true; } } public static void EnsureInitialized() { EnsureCapacity(256); } public static int FilterCharacters(List<Character> characters, Vector3 origin, float radius, Vector3 lookDirection, float maxAngleDegrees, List<Character> 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>(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<T> 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<long, List<VoxelEntry>> _cells = new Dictionary<long, List<VoxelEntry>>(512); private readonly Dictionary<T, long> _itemToCellKey = new Dictionary<T, long>(1024); private readonly List<List<VoxelEntry>> _cellListPool = new List<List<VoxelEntry>>(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<VoxelEntry> 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<VoxelEntry> 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<VoxelEntry> 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) { _ce