using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using CullFactory.Behaviours.API; using CullFactory.Behaviours.CullingMethods; using CullFactory.Behaviours.Visualization; using CullFactory.Data; using CullFactory.Extenders; using CullFactory.Services; using CullFactoryBurst; using DunGen; using DunGen.Graph; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Burst; using Unity.Burst.LowLevel; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: IgnoresAccessChecksTo("ClientNetworkTransform")] [assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")] [assembly: IgnoresAccessChecksTo("DissonanceVoip")] [assembly: IgnoresAccessChecksTo("DunGen")] [assembly: IgnoresAccessChecksTo("DunGen.Integration.ASPP")] [assembly: IgnoresAccessChecksTo("DunGen.Integration.UnityNav")] [assembly: IgnoresAccessChecksTo("EasyTextEffects")] [assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")] [assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")] [assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")] [assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")] [assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")] [assembly: IgnoresAccessChecksTo("Unity.Burst")] [assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")] [assembly: IgnoresAccessChecksTo("Unity.Collections")] [assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")] [assembly: IgnoresAccessChecksTo("Unity.InputSystem")] [assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")] [assembly: IgnoresAccessChecksTo("Unity.Jobs")] [assembly: IgnoresAccessChecksTo("Unity.Mathematics")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")] [assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")] [assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")] [assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")] [assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Components")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")] [assembly: IgnoresAccessChecksTo("Unity.Services.QoS")] [assembly: IgnoresAccessChecksTo("Unity.Services.Relay")] [assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")] [assembly: IgnoresAccessChecksTo("Unity.Timeline")] [assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.XR.CoreUtils")] [assembly: IgnoresAccessChecksTo("Unity.XR.Management")] [assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR")] [assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.ConformanceAutomation")] [assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MetaQuestSupport")] [assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MockRuntime")] [assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.OculusQuestSupport")] [assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.RuntimeDebugger")] [assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")] [assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")] [assembly: IgnoresAccessChecksTo("UnityEngine.SpatialTracking")] [assembly: IgnoresAccessChecksTo("UnityEngine.UI")] [assembly: IgnoresAccessChecksTo("UnityEngine.XR.LegacyInputHelpers")] [assembly: AssemblyCompany("CullFactory")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+a357d0b384da5fabfe8d07aacc7740f4cd1b2b2c")] [assembly: AssemblyProduct("CullFactory")] [assembly: AssemblyTitle("CullFactory")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class IsUnmanagedAttribute : Attribute { } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace CullFactory { public static class Config { private const string DungeonFlowListDescription = "\n\nValue:\nA list of dungeon generators, separated by commas \",\"."; private static readonly Version DefaultVersion = new Version(0, 0, 0); private static readonly string VersionFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, "version"); private static readonly string[] DefaultMoonScenesToBlockCulling = new string[3] { "LevelZeranos", "ProminenceScene", "NotezLevel3Outfall" }; private static readonly string[] DefaultFlowsToBlockCulling = new string[2] { "HadalFlow", "School" }; private static readonly string[] BaseSetOfInteriorsToUseFallbackPortals = new string[2] { "BunkerFlow", "CIDOMFlow" }; private static ConfigEntry Culler; private static ConfigEntry MoonScenesToBlockCulling; private static ConfigEntry MoonScenesToForceCulling; private static ConfigEntry InteriorsToBlockCulling; private static ConfigEntry InteriorsToForceCulling; public static string[] MoonScenesWithDisabledCulling = Array.Empty(); public static string[] InteriorsWithDisabledCulling = Array.Empty(); public static ConfigEntry Logging { get; private set; } public static ConfigEntry UpdateFrequency { get; private set; } public static ConfigEntry DisableShadowDistanceFading { get; private set; } public static ConfigEntry DisableLODCulling { get; private set; } public static ConfigEntry InteriorsToUseFallbackPortals { get; private set; } public static ConfigEntry InteriorsToSkipFallbackPortals { get; private set; } public static ConfigEntry MaxBranchingDepth { get; private set; } public static ConfigEntry CullDistanceEnabled { get; private set; } public static ConfigEntry CullDistance { get; private set; } public static ConfigEntry SurfaceCullDistance { get; private set; } public static ConfigEntry OverrideMapSeed { get; private set; } public static ConfigEntry VisualizePortals { get; private set; } public static ConfigEntry VisualizedPortalOutsetDistance { get; private set; } public static ConfigEntry VisualizeTileBounds { get; private set; } public static ConfigEntry VisualizeFrustums { get; private set; } public static string[] InteriorsWithFallbackPortals { get; private set; } public static void Initialize(ConfigFile configFile) { Culler = configFile.Bind("General", "Culling type", CullingType.PortalOcclusionCulling, "The culling type to use.\n\nOptions:\n\"PortalOcclusionCulling\": Hides all the rooms that aren't visible to the camera (Recommended)\n\"DepthCulling\": Hides rooms that aren't adjacent to the player's current room"); MoonScenesToBlockCulling = configFile.Bind("General", "Disable culling for moons", "", "A list of moon scenes to disable culling on, separated by commas, i.e.\n\"Level2Assurance, Level8Titan\"\n\nValue:\nA list of dungeon generators, separated by commas \",\"."); MoonScenesToForceCulling = configFile.Bind("General", "Force enable culling for moons", "", "A list of moon scenes to have culling force-enabled if not blocked based on other criteria. " + GetBuiltinBlacklistText(DefaultMoonScenesToBlockCulling) + "\n\nValue:\nA list of dungeon generators, separated by commas \",\"."); InteriorsToBlockCulling = configFile.Bind("General", "Disable culling for interiors", "", "A list of dungeon flows to disable culling on, separated by commas, i.e.\n\"Level1Flow, Level2Flow\"\n\nValue:\nA list of dungeon generators, separated by commas \",\"."); InteriorsToForceCulling = configFile.Bind("General", "Force enable culling for interiors", "", "A list of dungeon flows to have culling force-enabled if not blocked based on other criteria. " + GetBuiltinBlacklistText(DefaultFlowsToBlockCulling) + "\n\nValue:\nA list of dungeon generators, separated by commas \",\"."); UpdateFrequency = configFile.Bind("General", "Update frequency", 0f, "Higher values make culling more responsive at the cost of performance.\nCurrently this has no effect when portal occlusion culling is used.\nUpdate interval: 1 / value (seconds)"); DisableShadowDistanceFading = configFile.Bind("General", "Disable shadow distance fading", true, "Prevents lights' shadows from being hidden before the light itself becomes invisible.\nFixes issues that are common in Mansion where some lights will be visible through walls, and allows more lights/tiles to be culled within the interior.\nDisabling may have a negative impact on performance."); DisableLODCulling = configFile.Bind("General", "Disable LOD culling", true, "Forces the last LOD to stay visible for all static objects in the interior. This will prevent the stairs on the factory interior from disappearing at a distance, and should also prevent any other similar disappearing objects.\nObjects that have LOD groups will instead be culled based on visibility, so this has a minimal effect on performance."); InteriorsToUseFallbackPortals = configFile.Bind("Portal occlusion culling", "Use fallback portals for interiors", "", "Uses the maximum possible doorway sizes in each tile for visibility testing in the specified interiors.\nThis is recommended for interiors with incorrect doorway sizes.\n\nValue:\nA list of dungeon generators, separated by commas \",\"."); InteriorsToSkipFallbackPortals = configFile.Bind("Portal occlusion culling", "Skip fallback portals for interiors", "", "Skip using fallback portals on previously problematic interiors:\n" + BaseSetOfInteriorsToUseFallbackPortals.JoinByComma() + "\n\nValue:\nA list of dungeon generators, separated by commas \",\"."); MaxBranchingDepth = configFile.Bind("Depth culling", "Max branching depth", 4, "How many doors can be traversed before a room is culled."); CullDistanceEnabled = configFile.Bind("Distance culling", "Enabled", false, "Whether to override the camera's far plane distance. When this is false, the 'Cull distance' and 'Surface cull distance' options will have no effect.\nIf performance with portal occlusion culling enabled is insufficient this may provide a small boost in performance."); CullDistance = configFile.Bind("Distance culling", "Cull distance", 40f, "The camera's far plane distance.\nObjects that are this far from the player will be culled.\nVanilla value: 400"); SurfaceCullDistance = configFile.Bind("Distance culling", "Surface cull distance", 200f, "The camera's far plane distance when **on the surface**.\nObjects that are this far from the player will be culled.\nVanilla value: 400"); VisualizePortals = configFile.Bind("Debug", "Visualize portals", false, "Shows a rectangle representing the bounds of all portals that are used to determine visibility when portal occlusion culling is enabled. If the portal doesn't block the entirety of the visible portion of the next tile, then culling will not be correct."); VisualizedPortalOutsetDistance = configFile.Bind("Debug", "Visualized portal outset distance", 0.2f, "The distance to offset each side of a portal visualizer out from the actual position of the portal. For doors that don't cover an entire tile wall, this allows seeing the exact bounds it covers."); VisualizeTileBounds = configFile.Bind("Debug", "Visualize tile bounds", false, "Shows a rectangular prism to represent the bounds all tiles. These bounds are used to determine which tile a camera resides in."); VisualizeFrustums = configFile.Bind("Debug", "Visualize visible frustums", false, "Displays a wireframe for each frustum visited during visibility testing."); OverrideMapSeed = configFile.Bind("Debug", "Override map seed", "", "INTENDED FOR BENCHMARKING ONLY. Leave this empty if you are playing normally.\nThis forces the map seed to be whatever is entered here, so that benchmarking numbers can remain as consistent as possible between runs."); Logging = configFile.Bind("Debug", "Show culling logs", false, "View culling activity in the console."); MigrateSettings(); Culler.SettingChanged += delegate { CullingMethod.Initialize(); }; MoonScenesToBlockCulling.SettingChanged += delegate { UpdateMoonScenesWithDisabledCulling(); }; MoonScenesToForceCulling.SettingChanged += delegate { UpdateMoonScenesWithDisabledCulling(); }; InteriorsToBlockCulling.SettingChanged += delegate { UpdateInteriorsWithDisabledCulling(); }; InteriorsToForceCulling.SettingChanged += delegate { UpdateInteriorsWithDisabledCulling(); }; UpdateFrequency.SettingChanged += delegate { CullingMethod.Initialize(); }; DisableShadowDistanceFading.SettingChanged += delegate { RefreshCullingInfoAndMethod(); }; DisableLODCulling.SettingChanged += delegate { RefreshCullingInfoAndMethod(); }; InteriorsToUseFallbackPortals.SettingChanged += delegate { UpdateInteriorsWithFallbackPortals(); }; InteriorsToSkipFallbackPortals.SettingChanged += delegate { UpdateInteriorsWithFallbackPortals(); }; CullDistanceEnabled.SettingChanged += delegate { TeleportExtender.SetInitialFarClipPlane(); }; CullDistance.SettingChanged += delegate { TeleportExtender.SetInitialFarClipPlane(); }; SurfaceCullDistance.SettingChanged += delegate { TeleportExtender.SetInitialFarClipPlane(); }; VisualizePortals.SettingChanged += delegate { CullingVisualizer.Initialize(); }; VisualizedPortalOutsetDistance.SettingChanged += delegate { CullingVisualizer.Initialize(); }; VisualizeTileBounds.SettingChanged += delegate { CullingVisualizer.Initialize(); }; VisualizeFrustums.SettingChanged += delegate { CullingVisualizer.Initialize(); }; UpdateMoonScenesWithDisabledCulling(); UpdateInteriorsWithDisabledCulling(); UpdateInteriorsWithFallbackPortals(); } private static string GetBuiltinBlacklistText(string[] blacklist) { if (blacklist.Length == 0) { return "This will have no effect as the internal blacklist is empty."; } return "This can be used to override the internal blacklist containing " + blacklist.HumanReadableList() + "."; } private static void MigrateSettings() { Version version = (File.Exists(VersionFile) ? Version.Parse(Encoding.UTF8.GetString(File.ReadAllBytes(VersionFile))) : DefaultVersion); if (version <= new Version(0, 8, 0)) { InteriorsToUseFallbackPortals.Value = InteriorsToUseFallbackPortals.Value.SplitByComma().Except(new <>z__ReadOnlyArray(new string[2] { "CastleFlow", "SewerFlow" })).JoinByComma(); } if (version <= new Version(0, 8, 6)) { UpdateFrequency.Value = (float)((ConfigEntryBase)UpdateFrequency).DefaultValue; } using FileStream fileStream = File.Open(VersionFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None); fileStream.Write(Encoding.UTF8.GetBytes("2.0.10")); } private static void UpdateMoonScenesWithDisabledCulling() { MoonScenesWithDisabledCulling = DefaultMoonScenesToBlockCulling.Union(MoonScenesToBlockCulling.Value.SplitByComma()).Except(MoonScenesToForceCulling.Value.SplitByComma()).ToArray(); CullingMethod.Initialize(); } private static void UpdateInteriorsWithDisabledCulling() { InteriorsWithDisabledCulling = DefaultFlowsToBlockCulling.Union(InteriorsToBlockCulling.Value.SplitByComma()).Except(InteriorsToForceCulling.Value.SplitByComma()).ToArray(); CullingMethod.Initialize(); } public static bool ShouldEnableCullingForScene(string sceneName) { return !MoonScenesWithDisabledCulling.Contains(sceneName); } public static bool ShouldEnableCullingForInterior(string dungeonFlowName) { return !InteriorsWithDisabledCulling.Contains(dungeonFlowName); } public static CullingType GetCullingType() { return Culler.Value; } private static void UpdateInteriorsWithFallbackPortals() { InteriorsWithFallbackPortals = BaseSetOfInteriorsToUseFallbackPortals.Union(InteriorsToUseFallbackPortals.Value.SplitByComma()).Except(InteriorsToSkipFallbackPortals.Value.SplitByComma()).ToArray(); RefreshCullingInfoAndMethod(); } private static void RefreshCullingInfoAndMethod() { DungeonCullingInfo.RefreshCullingInfo(); CullingMethod.Initialize(); } } [BepInPlugin("com.fumiko.CullFactory", "CullFactory", "2.0.10")] public class Plugin : BaseUnityPlugin { public const string Guid = "com.fumiko.CullFactory"; public const string Name = "CullFactory"; public const string Version = "2.0.10"; private Harmony _harmony = new Harmony("com.fumiko.CullFactory"); public static Plugin Instance { get; private set; } private void Awake() { Instance = this; Config.Initialize(((BaseUnityPlugin)this).Config); _harmony.PatchAll(typeof(DisableVanillaCulling)); _harmony.PatchAll(typeof(LevelGenerationExtender)); _harmony.PatchAll(typeof(TeleportExtender)); _harmony.PatchAll(typeof(MapSeedOverride)); _harmony.PatchAll(typeof(GrabbableObjectExtender)); QualitySettings.shadowResolution = (ShadowResolution)0; LoadBurstAssembly(); SceneLoadingExtender.Init(); Log("Plugin CullFactory is loaded!"); } private void LoadBurstAssembly() { string text = Path.Combine(new FileInfo(((BaseUnityPlugin)this).Info.Location).DirectoryName, "lib_burst_generated.data"); if (!File.Exists(text)) { LogError("CullFactory's Burst assembly 'lib_burst_generated.data' was not found, culling may be slower than normal."); return; } if (!BurstRuntime.LoadAdditionalLibrary(text)) { LogError("CullFactory's Burst assembly failed to load, culling may be slower than normal."); return; } if (!Plugin.IsRunningBurstLibrary()) { LogError("CullFactory's Burst plugin is not running its Burst-compiled code, culling may be slower than normal."); return; } LogAlways("Loaded CullFactory's Burst assembly."); _harmony.PatchAll(typeof(BurstErrorPrevention)); } public static void LogAlways(string s) { ((BaseUnityPlugin)Instance).Logger.LogInfo((object)s); } public static void Log(string s) { if (Config.Logging.Value) { LogAlways(s); } } public static void LogWarning(string s) { ((BaseUnityPlugin)Instance).Logger.LogWarning((object)s); } public static void LogError(string s) { ((BaseUnityPlugin)Instance).Logger.LogError((object)s); } } } namespace CullFactory.Services { public static class BoundsUtility { private struct AABBFrustumEdge { internal int FaceA; internal int FaceB; internal int VertA; internal int VertB; public AABBFrustumEdge(int faceA, int faceB, int vertA, int vertB) { FaceA = faceA; FaceB = faceB; VertA = vertA; VertB = vertB; } } private struct AABBFrustumData { internal Vector3[] Normals; internal Vector3[] Vertices; internal AABBFrustumEdge[] Edges; } private static readonly AABBFrustumData FrustumData = GetFrustumData(); private static readonly List TempPlanes = new List(9); public static Plane[] GetPlanes(this in Bounds bounds) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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_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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_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_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: 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_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_0119: 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) //IL_0127: 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_0136: Unknown result type (might be due to invalid IL or missing references) Plane[] array = new Plane[6]; Vector3 val = new Vector3(1f, 0f, 0f); Bounds val2 = bounds; array[0] = new Plane(val, 0f - ((Bounds)(ref val2)).min.x); Vector3 val3 = new Vector3(0f, 1f, 0f); val2 = bounds; array[1] = new Plane(val3, 0f - ((Bounds)(ref val2)).min.y); Vector3 val4 = new Vector3(0f, 0f, 1f); val2 = bounds; array[2] = new Plane(val4, 0f - ((Bounds)(ref val2)).min.z); Vector3 val5 = new Vector3(-1f, 0f, 0f); val2 = bounds; array[3] = new Plane(val5, ((Bounds)(ref val2)).max.x); Vector3 val6 = new Vector3(0f, -1f, 0f); val2 = bounds; array[4] = new Plane(val6, ((Bounds)(ref val2)).max.y); Vector3 val7 = new Vector3(0f, 0f, -1f); val2 = bounds; array[5] = new Plane(val7, ((Bounds)(ref val2)).max.z); return (Plane[])(object)array; } public static Vector3[] GetVertices(Vector3 min, Vector3 max) { //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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_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_0038: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_0080: 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_008c: 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_009e: 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) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: 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_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: 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) return (Vector3[])(object)new Vector3[8] { new Vector3(min.x, min.y, min.z), new Vector3(max.x, min.y, min.z), new Vector3(min.x, max.y, min.z), new Vector3(max.x, max.y, min.z), new Vector3(min.x, min.y, max.z), new Vector3(max.x, min.y, max.z), new Vector3(min.x, max.y, max.z), new Vector3(max.x, max.y, max.z) }; } public static Vector3[] GetVertices(this Bounds bounds) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) return GetVertices(((Bounds)(ref bounds)).min, ((Bounds)(ref bounds)).max); } private static AABBFrustumData GetFrustumData() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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_0083: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: 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_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: 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_00c0: Unknown result type (might be due to invalid IL or missing references) Vector3[] array = (Vector3[])(object)new Vector3[6] { Vector3.right, Vector3.up, Vector3.forward, Vector3.left, Vector3.down, Vector3.back }; List verts = new List(8); List list = new List(12); for (int i = 0; i < array.Length; i++) { Vector3 val = array[i]; for (int j = 0; j < array.Length; j++) { Vector3 val2 = array[j]; if (!(Vector3.Dot(val, val2) < 0f)) { Vector3 val3 = Vector3.Cross(val, val2); Vector3 vert2 = val + val2 + val3; Vector3 vert3 = val + val2 - val3; int vertA = AddVert(vert2); int vertB = AddVert(vert3); list.Add(new AABBFrustumEdge(i, j, vertA, vertB)); } } } AABBFrustumData result = default(AABBFrustumData); result.Normals = array; result.Vertices = verts.ToArray(); result.Edges = list.ToArray(); return result; int AddVert(Vector3 vert) { //IL_0006: 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) int num = verts.IndexOf(vert); if (num != -1) { return num; } num = verts.Count; verts.Add(vert); return num; } } private static bool IsFacing(in Bounds bounds, in Vector3 normal, in Vector3 point) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: 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_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) Bounds val = bounds; Vector3 center = ((Bounds)(ref val)).center; val = bounds; Vector3 val2 = center + Vector3.Scale(((Bounds)(ref val)).extents, normal) - point; return Vector3.Dot(normal, val2) < 0f; } public static Plane[] GetFrustumFromPoint(this in Bounds bounds, Vector3 point) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0009: 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_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0091: 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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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_00b9: 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) //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_00ce: 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_00d6: 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_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: 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_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_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_0114: Unknown result type (might be due to invalid IL or missing references) Bounds val = bounds; if (((Bounds)(ref val)).Contains(point)) { return bounds.GetPlanes(); } TempPlanes.Clear(); bounds.AddInsidePlanesFacingPointToTempPlanes(in point); AABBFrustumEdge[] edges = FrustumData.Edges; for (int i = 0; i < edges.Length; i++) { AABBFrustumEdge aABBFrustumEdge = edges[i]; Vector3 normal = FrustumData.Normals[aABBFrustumEdge.FaceA]; Vector3 normal2 = FrustumData.Normals[aABBFrustumEdge.FaceB]; if (IsFacing(in bounds, in normal, in point) && !IsFacing(in bounds, in normal2, in point)) { val = bounds; Vector3 center = ((Bounds)(ref val)).center; Vector3 val2 = FrustumData.Vertices[aABBFrustumEdge.VertA]; val = bounds; Vector3 val3 = center + Vector3.Scale(val2, ((Bounds)(ref val)).extents); val = bounds; Vector3 center2 = ((Bounds)(ref val)).center; Vector3 val4 = FrustumData.Vertices[aABBFrustumEdge.VertB]; val = bounds; Vector3 val5 = center2 + Vector3.Scale(val4, ((Bounds)(ref val)).extents); TempPlanes.Add(new Plane(val3, val5, point)); } } return TempPlanes.ToArray(); } public static void AddInsidePlanesFacingPointToTempPlanes(this in Bounds bounds, in Vector3 point) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_004f: 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) Vector3[] normals = FrustumData.Normals; for (int i = 0; i < normals.Length; i++) { Vector3 normal = normals[i]; if (!IsFacing(in bounds, in normal, in point)) { List tempPlanes = TempPlanes; Vector3 val = -normal; Bounds val2 = bounds; Vector3 center = ((Bounds)(ref val2)).center; val2 = bounds; tempPlanes.Add(new Plane(val, center + Vector3.Scale(((Bounds)(ref val2)).extents, normal))); } } } public static Plane[] GetInsidePlanesFacingPoint(this in Bounds bounds, in Vector3 point) { TempPlanes.Clear(); bounds.AddInsidePlanesFacingPointToTempPlanes(in point); return TempPlanes.ToArray(); } } internal static class CameraUtility { private static NativeArray TempFrustum; public static NativeSlice GetTempFrustum(this Camera camera) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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) if (TempFrustum.Length == 0) { TempFrustum = new NativeArray(5, (Allocator)4, (NativeArrayOptions)0); } return camera.ExtractFrustumPlanes(TempFrustum); } public unsafe static NativeSlice ExtractFrustumPlanes(this Camera camera, NativeArray planes) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) if (planes.Length < 5) { throw new IndexOutOfRangeException("ExtractFrustumPlanes would write out of range"); } camera.ExtractFrustumPlanes(planes.GetPtr()); return NativeSliceExtensions.Slice(planes, 0, 5); } public unsafe static NativeSlice ExtractFrustumPlanes(this Camera camera, NativeSlice planes) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) if (planes.Length < 5) { throw new IndexOutOfRangeException("ExtractFrustumPlanes would write out of range"); } camera.ExtractFrustumPlanes(planes.GetPtr()); return NativeSliceExtensions.Slice(planes, 0, 5); } private unsafe static void ExtractFrustumPlanes(this Camera camera, Plane* planes) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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) Matrix4x4 val = camera.projectionMatrix * camera.worldToCameraMatrix; Geometry.ExtractPlanes(ref val, planes); } } internal static class FrustumMeshBuilder { private struct Edge : IEquatable { public int a; public int b; public Edge(int a, int b) { this.a = Math.Min(a, b); this.b = Math.Max(a, b); } public readonly bool Equals(Edge other) { if (a == other.a) { return b == other.b; } return false; } public override readonly bool Equals(object other) { if (other is Edge other2) { return Equals(other2); } return false; } public override readonly int GetHashCode() { return HashCode.Combine(a, b); } } private sealed class QuantizedVectorComparer : IEqualityComparer { public bool Equals(Vector3 a, Vector3 b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) Vector3 val = a - b; return ((Vector3)(ref val)).sqrMagnitude < 9.999999E-09f; } public int GetHashCode(Vector3 v) { //IL_0000: 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) //IL_0023: Unknown result type (might be due to invalid IL or missing references) int value = Mathf.RoundToInt(v.x * 10000f); int value2 = Mathf.RoundToInt(v.y * 10000f); int value3 = Mathf.RoundToInt(v.z * 10000f); return HashCode.Combine(value, value2, value3); } } private const float PositionEpsilon = 0.0001f; public static bool TryBuildWireframe(List planes, in Bounds clipBounds, Mesh destination) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) destination.Clear(); List> list = CreateBoxFaces(in clipBounds); for (int i = 0; i < planes.Count; i++) { list = ClipByPlane(list, planes[i]); if (list.Count == 0) { return false; } } return FillLineMesh(list, destination); } private static List> CreateBoxFaces(in Bounds bounds) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_000f: 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) //IL_0016: 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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: 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_0086: 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_0092: 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_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: 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_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0153: 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_0162: 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_017e: 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_018e: 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_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: 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_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: 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_01e4: Unknown result type (might be due to invalid IL or missing references) Bounds val = bounds; Vector3 min = ((Bounds)(ref val)).min; val = bounds; Vector3 max = ((Bounds)(ref val)).max; Vector3 item = default(Vector3); ((Vector3)(ref item))..ctor(min.x, min.y, min.z); Vector3 item2 = default(Vector3); ((Vector3)(ref item2))..ctor(max.x, min.y, min.z); Vector3 item3 = default(Vector3); ((Vector3)(ref item3))..ctor(min.x, max.y, min.z); Vector3 item4 = default(Vector3); ((Vector3)(ref item4))..ctor(max.x, max.y, min.z); Vector3 item5 = default(Vector3); ((Vector3)(ref item5))..ctor(min.x, min.y, max.z); Vector3 item6 = default(Vector3); ((Vector3)(ref item6))..ctor(max.x, min.y, max.z); Vector3 item7 = default(Vector3); ((Vector3)(ref item7))..ctor(min.x, max.y, max.z); Vector3 item8 = default(Vector3); ((Vector3)(ref item8))..ctor(max.x, max.y, max.z); return new List>(6) { new List(4) { item, item5, item7, item3 }, new List(4) { item2, item4, item8, item6 }, new List(4) { item, item2, item6, item5 }, new List(4) { item3, item7, item8, item4 }, new List(4) { item, item3, item4, item2 }, new List(4) { item5, item6, item8, item7 } }; } private static List> ClipByPlane(List> faces, Plane plane) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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) List> list = new List>(faces.Count + 1); List list2 = new List(); foreach (List face in faces) { ClipPolygon(face, plane, out List clippedPolygon, out (Vector3, Vector3)? cuttingPlaneEdge); if (clippedPolygon.Count >= 3) { list.Add(clippedPolygon); } if (cuttingPlaneEdge.HasValue) { list2.Add(cuttingPlaneEdge.Value.Item1); list2.Add(cuttingPlaneEdge.Value.Item2); } } List list3 = StitchPlaneFace(list2, plane); if (list3 != null) { list.Add(list3); } return list; } private static void ClipPolygon(List polygon, Plane plane, out List clippedPolygon, out (Vector3 entry, Vector3 exit)? cuttingPlaneEdge) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0091: 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_0096: 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_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: 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_00b1: Unknown result type (might be due to invalid IL or missing references) cuttingPlaneEdge = null; clippedPolygon = new List(polygon.Count + 1); Vector3? val = null; Vector3? val2 = null; for (int i = 0; i < polygon.Count; i++) { Vector3 val3 = polygon[i]; Vector3 val4 = polygon[(i + 1) % polygon.Count]; float distanceToPoint = ((Plane)(ref plane)).GetDistanceToPoint(val3); float distanceToPoint2 = ((Plane)(ref plane)).GetDistanceToPoint(val4); if (distanceToPoint >= 0f) { clippedPolygon.Add(val3); } if (distanceToPoint >= 0f != distanceToPoint2 >= 0f) { float num = distanceToPoint / (distanceToPoint - distanceToPoint2); Vector3 val5 = Vector3.Lerp(val3, val4, num); clippedPolygon.Add(val5); if (distanceToPoint >= 0f) { val2 = val5; } else { val = val5; } } } if (val.HasValue && val2.HasValue) { cuttingPlaneEdge = (val.Value, val2.Value); } } private static List StitchPlaneFace(List edgeEndpoints, Plane plane) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_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_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_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_00f5: 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_0107: 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_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) List list = new List(); foreach (Vector3 edgeEndpoint in edgeEndpoints) { bool flag = false; for (int i = 0; i < list.Count; i++) { Vector3 val = list[i] - edgeEndpoint; if (((Vector3)(ref val)).sqrMagnitude < 9.999999E-09f) { flag = true; break; } } if (!flag) { list.Add(edgeEndpoint); } } if (list.Count < 3) { return null; } Vector3 centroid = Vector3.zero; foreach (Vector3 item in list) { centroid += item; } centroid /= (float)list.Count; Vector3 normal = ((Plane)(ref plane)).normal; Vector3 val2 = ((Mathf.Abs(normal.x) > 0.9f) ? Vector3.up : Vector3.right); Vector3 tangent = Vector3.Normalize(val2 - Vector3.Dot(val2, normal) * normal); Vector3 bitangent = Vector3.Cross(normal, tangent); list.Sort(delegate(Vector3 firstVertex, Vector3 secondVertex) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_0019: 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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) Vector3 val3 = firstVertex - centroid; Vector3 val4 = secondVertex - centroid; float num = Mathf.Atan2(Vector3.Dot(val3, bitangent), Vector3.Dot(val3, tangent)); float value = Mathf.Atan2(Vector3.Dot(val4, bitangent), Vector3.Dot(val4, tangent)); return num.CompareTo(value); }); return list; } private static bool FillLineMesh(List> faces, Mesh destination) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) List vertices = new List(); List list = new List(); HashSet hashSet = new HashSet(); Dictionary vertexIndicesByPosition = new Dictionary(new QuantizedVectorComparer()); foreach (List face in faces) { for (int i = 0; i < face.Count; i++) { int num = GetOrAddVertexIndex(face[i]); int num2 = GetOrAddVertexIndex(face[(i + 1) % face.Count]); if (num != num2 && hashSet.Add(new Edge(num, num2))) { list.Add(num); list.Add(num2); } } } if (list.Count == 0) { return false; } if (vertices.Count > 65535) { destination.indexFormat = (IndexFormat)1; } else { destination.indexFormat = (IndexFormat)0; } destination.SetVertices(vertices); destination.SetIndices(list, (MeshTopology)3, 0, true, 0); return true; int GetOrAddVertexIndex(Vector3 vertex) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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) if (vertexIndicesByPosition.TryGetValue(vertex, out var value)) { return value; } int count = vertices.Count; vertices.Add(vertex); vertexIndicesByPosition[vertex] = count; return count; } } } public class IdentityEqualityComparer : IEqualityComparer { public static readonly IdentityEqualityComparer Instance = new IdentityEqualityComparer(); public bool Equals(T x, T y) { return (object)x == (object)y; } public int GetHashCode(T obj) { return RuntimeHelpers.GetHashCode(obj); } } public static class LightUtility { public const float ExtraShadowFadeDistance = 1.1111112f; public static bool Affects(this Light light, Bounds bounds) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) float range = light.range; if (((Bounds)(ref bounds)).SqrDistance(((Component)light).transform.position) > range * range) { return false; } if ((int)light.type == 0) { return Geometry.SpotLightInfluencesBounds(ref light, ref bounds); } return true; } public static bool Affects(this Light light, TileContents tile) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) return light.Affects(tile.rendererBounds); } public static bool Affects(this Light light, IEnumerable tiles) { foreach (TileContents tile in tiles) { if (light.Affects(tile)) { return true; } } return false; } public static bool HasShadows(this Light light) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 return (int)light.shadows > 0; } public static bool PassesThroughOccluders(this Light light) { if (light.HasShadows()) { HDAdditionalLightData component = ((Component)light).GetComponent(); if (component != null) { return component.shadowDimmer < 1f; } return false; } return true; } public static float GetMinimumShadowFadeDistance(float lightFadeDistance) { return lightFadeDistance * 1.1111112f; } public static bool ShouldDisableShadowFading(this HDAdditionalLightData light) { return (double)light.shadowFadeDistance >= (double)light.fadeDistance * 0.75 - 15.0; } public static bool ShadowFadingAllowsLeakage(this HDAdditionalLightData light) { if (Config.DisableShadowDistanceFading.Value) { return !light.ShouldDisableShadowFading(); } return light.shadowFadeDistance + 0.001f < GetMinimumShadowFadeDistance(light.fadeDistance); } public static bool ShadowFadingAllowsLeakage(this Light light) { return ((Component)light).GetComponent()?.ShadowFadingAllowsLeakage() ?? false; } public static void SetVisible(this Light light, bool visible) { if (!((Object)(object)light == (Object)null)) { if (light.cullingMask != -1 && light.cullingMask != 0) { Plugin.LogWarning($"Light {((Object)light).name}'s culling mask was an unexpected value of {light.cullingMask}."); } light.cullingMask = (visible ? (-1) : 0); } } public static void SetVisible(this IEnumerable lights, bool visible) { foreach (Light light in lights) { light.SetVisible(visible); } } } internal static class NativeCollectionsUtility { public unsafe static T* GetPtr(this NativeArray array) where T : unmanaged { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return (T*)NativeArrayUnsafeUtility.GetUnsafePtr(array); } public unsafe static T* GetPtr(this NativeSlice array) where T : unmanaged { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return (T*)NativeSliceUnsafeUtility.GetUnsafePtr(array); } } public static class ObjectContentsUtility { public static void SetSelfVisible(this IEnumerable tiles, bool visible) { foreach (TileContents tile in tiles) { tile.SetSelfVisible(visible); } } public static void SetVisible(this IEnumerable items, bool visible) { foreach (GrabbableObjectContents item in items) { item.SetVisible(visible); } } public static void AddContentsVisibleToCamera(this ICollection result, Camera camera) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) if (camera.orthographic) { result.AddContentsWithinCameraFrustum(camera); return; } TileContents tileContents = ((Component)camera).transform.position.GetTileContents(); if (tileContents != null) { VisibilityTesting.CallForEachLineOfSight(camera, tileContents, delegate(TileContents[] tiles, NativeSlice[] frustums, int index) { result.Add(tiles[index]); }); } } public static void AddContentsWithinCameraFrustum(this ICollection result, Camera camera) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) NativeSlice tempFrustum = camera.GetTempFrustum(); for (int i = 0; i < DungeonCullingInfo.AllDungeonData.Length; i++) { ref DungeonCullingInfo.DungeonData reference = ref DungeonCullingInfo.AllDungeonData[i]; if (!reference.IsValid || !Geometry.TestPlanesAABB(ref tempFrustum, ref reference.Bounds)) { continue; } TileContents[] allTileContents = reference.AllTileContents; foreach (TileContents tileContents in allTileContents) { if (Geometry.TestPlanesAABB(ref tempFrustum, ref tileContents.bounds)) { result.Add(tileContents); } } } } } public static class StringUtility { public static IEnumerable SplitByComma(this string input) { return from name in input.Split(',', StringSplitOptions.RemoveEmptyEntries) select name.Trim().Trim('"'); } public static string JoinByComma(this IEnumerable input) { return string.Join(", ", input); } public static string HumanReadableList(this IEnumerable input) { IEnumerator enumerator = input.GetEnumerator(); if (!enumerator.MoveNext()) { return ""; } StringBuilder stringBuilder = new StringBuilder(enumerator.Current); if (!enumerator.MoveNext()) { return stringBuilder.ToString(); } string current; while (true) { current = enumerator.Current; if (!enumerator.MoveNext()) { break; } stringBuilder.Append(", "); stringBuilder.Append(current); } stringBuilder.Append(", and "); stringBuilder.Append(current); return stringBuilder.ToString(); } } public static class TransformUtility { public static string GetPath(this Transform obj, Transform stopAt = null) { StringBuilder stringBuilder = new StringBuilder(((Object)obj).name); Transform parent = obj.parent; while ((Object)(object)parent != (Object)(object)stopAt) { stringBuilder.Insert(0, "/"); stringBuilder.Insert(0, ((Object)parent).name); parent = parent.parent; } return stringBuilder.ToString(); } public static bool TryGetComponentInParent(this Transform transform, out T component) { component = ((Component)transform).GetComponentInParent(); return component != null; } } public static class VisibilityTesting { public delegate void LineOfSightCallback(TileContents[] tileStack, NativeSlice[] frustums, int stackIndex); private const int MaxStackCapacity = 32; private static readonly TileContents[] TileStack = new TileContents[32]; private static readonly int[] IndexStack = new int[32]; private static readonly NativeSlice[] Frustums = new NativeSlice[32]; private static readonly NativeArray FrustumPlanes = new NativeArray(192, (Allocator)4, (NativeArrayOptions)1); private static bool warnedThatStackWasExceeded = false; [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void DropTopStackFrame(ref int stackIndex, ref int frustumPlanesCount) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) frustumPlanesCount -= Frustums[stackIndex].Length; Frustums[stackIndex] = default(NativeSlice); stackIndex--; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private unsafe static bool AdvanceToNextTile(Vector3 origin, ref int stackIndex, ref int frustumPlanesCount) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_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) TileContents tileContents = TileStack[stackIndex]; int num = IndexStack[stackIndex]++; if (num >= tileContents.portals.Length) { DropTopStackFrame(ref stackIndex, ref frustumPlanesCount); return false; } Portal portal = tileContents.portals[num]; TileContents nextTile = portal.NextTile; if (nextTile == null) { return false; } if (stackIndex > 0 && nextTile == TileStack[stackIndex - 1]) { return false; } NativeSlice val = NativeSliceExtensions.Slice(FrustumPlanes, 0, frustumPlanesCount); if (!Geometry.TestPlanesAABB(ref val, ref portal.Bounds)) { return false; } stackIndex++; if (stackIndex >= 32) { stackIndex--; if (!warnedThatStackWasExceeded) { Plugin.LogWarning($"Exceeded the maximum portal occlusion culling depth of {32}."); warnedThatStackWasExceeded = true; } return false; } TileStack[stackIndex] = nextTile; IndexStack[stackIndex] = 0; int frustumPlanes = portal.GetFrustumPlanes(in origin, NativeSliceExtensions.Slice(FrustumPlanes, frustumPlanesCount).GetPtr()); Frustums[stackIndex] = NativeSliceExtensions.Slice(FrustumPlanes, frustumPlanesCount, frustumPlanes); frustumPlanesCount += frustumPlanes; return true; } public static void CallForEachLineOfSight(Vector3 origin, TileContents originTile, NativeSlice frustum, LineOfSightCallback callback) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) TileStack[0] = originTile; IndexStack[0] = 0; frustum.CopyTo(FrustumPlanes); Frustums[0] = NativeSliceExtensions.Slice(FrustumPlanes, 0, frustum.Length); int stackIndex = 0; int frustumPlanesCount = Frustums[0].Length; callback(TileStack, Frustums, stackIndex); while (stackIndex >= 0) { if (AdvanceToNextTile(origin, ref stackIndex, ref frustumPlanesCount)) { callback(TileStack, Frustums, stackIndex); } } } public static void CallForEachLineOfSight(Camera camera, TileContents originTile, LineOfSightCallback callback) { //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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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) TileStack[0] = originTile; IndexStack[0] = 0; Frustums[0] = camera.ExtractFrustumPlanes(FrustumPlanes); int stackIndex = 0; int frustumPlanesCount = Frustums[0].Length; callback(TileStack, Frustums, stackIndex); Vector3 position = ((Component)camera).transform.position; while (stackIndex >= 0) { if (AdvanceToNextTile(position, ref stackIndex, ref frustumPlanesCount)) { callback(TileStack, Frustums, stackIndex); } } } public static void CallForEachLineOfSight(Vector3 origin, TileContents originTile, LineOfSightCallback callback) { //IL_001b: 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) TileStack[0] = originTile; IndexStack[0] = 0; Frustums[0] = default(NativeSlice); int stackIndex = 0; int frustumPlanesCount = 0; callback(TileStack, Frustums, stackIndex); while (stackIndex >= 0) { if (AdvanceToNextTile(origin, ref stackIndex, ref frustumPlanesCount)) { callback(TileStack, Frustums, stackIndex); } } } private static bool PlanesIntersectAnyTile(in NativeSlice planes, HashSet tiles) { foreach (TileContents tile in tiles) { if (Geometry.TestPlanesAABB(ref planes, ref tile.bounds)) { return true; } } return false; } public static bool CallForEachLineOfSightTowardTiles(Vector3 origin, TileContents originTile, NativeSlice frustum, HashSet goalTiles, LineOfSightCallback callback) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) TileStack[0] = originTile; IndexStack[0] = 0; frustum.CopyTo(FrustumPlanes); Frustums[0] = NativeSliceExtensions.Slice(FrustumPlanes, 0, frustum.Length); int stackIndex = 0; int frustumPlanesCount = Frustums[0].Length; callback(TileStack, Frustums, stackIndex); bool result = goalTiles.Contains(originTile); if (goalTiles.Count == 0) { return false; } Bounds val = default(Bounds); foreach (TileContents goalTile in goalTiles) { if (((Bounds)(ref val)).Equals(default(Bounds))) { val = goalTile.bounds; } else { ((Bounds)(ref val)).Encapsulate(goalTile.bounds); } } while (stackIndex >= 0) { if (!AdvanceToNextTile(origin, ref stackIndex, ref frustumPlanesCount)) { continue; } if (!Geometry.TestPlanesAABB(ref Frustums[stackIndex], ref val)) { DropTopStackFrame(ref stackIndex, ref frustumPlanesCount); continue; } if (!PlanesIntersectAnyTile(in Frustums[stackIndex], goalTiles)) { DropTopStackFrame(ref stackIndex, ref frustumPlanesCount); continue; } if (goalTiles.Contains(TileStack[stackIndex])) { result = true; } callback(TileStack, Frustums, stackIndex); } return result; } public static bool CallForEachLineOfSightTowardTiles(Vector3 origin, TileContents originTile, HashSet goalTiles, LineOfSightCallback callback) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0004: 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) return CallForEachLineOfSightTowardTiles(origin, originTile, default(NativeSlice), goalTiles, callback); } } } namespace CullFactory.Extenders { internal static class BurstErrorPrevention { [HarmonyTranspiler] [HarmonyPatch(typeof(BurstCompiler), "GetILPPMethodFunctionPointer2")] private static IEnumerable PatchGetILPPMethodFunctionPointer2(IEnumerable instructions) { //IL_0002: 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_0026: Expected O, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldstr, (object)"ilppMethod", (string)null), new CodeMatch((OpCode?)OpCodes.Newobj, (object)typeof(ArgumentNullException).GetConstructor(new Type[1] { typeof(string) }), (string)null), new CodeMatch((OpCode?)OpCodes.Throw, (object)null, (string)null) }); if (val.IsInvalid) { Plugin.LogError("Failed to find Burst function pointer getter's throw statement"); return instructions; } val.RemoveInstructions(3).Insert((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldc_I4_0, (object)null), new CodeInstruction(OpCodes.Ret, (object)null) }); return val.Instructions(); } [HarmonyTranspiler] [HarmonyPatch(typeof(BurstCompiler), "Compile", new Type[] { typeof(object), typeof(MethodInfo), typeof(bool), typeof(bool) })] private static IEnumerable PatchCompile(IEnumerable instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Expected O, but got Unknown //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Expected O, but got Unknown //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Expected O, but got Unknown //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Expected O, but got Unknown //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Expected O, but got Unknown //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Expected O, but got Unknown //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Expected O, but got Unknown //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Expected O, but got Unknown //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Expected O, but got Unknown //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Expected O, but got Unknown //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); MethodInfo method = typeof(BurstCompilerService).GetMethod("GetAsyncCompiledAsyncDelegateMethod", new Type[1] { typeof(int) }); if (method == null) { Plugin.LogError("Failed to find the Burst async compilation method"); return instructions; } val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Call, (object)method, (string)null), new CodeMatch((OpCode?)OpCodes.Stloc_0, (object)null, (string)null) }).Advance(1); Label? label = default(Label?); if (val.IsInvalid || !CodeInstructionExtensions.Branches(val.Instruction, ref label)) { Plugin.LogAlways($"{val.Instruction}"); Plugin.LogError("Failed to find the call to the Burst async compilation method"); return instructions; } val.RemoveInstruction().InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[4] { new CodeInstruction(OpCodes.Ldloc_0, (object)null), new CodeInstruction(OpCodes.Ldc_I4_0, (object)null), new CodeInstruction(OpCodes.Conv_U, (object)null), new CodeInstruction(OpCodes.Bne_Un, (object)label) }); CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[9] { new CodeMatch((OpCode?)OpCodes.Ldloc_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Conv_U, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Bne_Un, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldstr, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)typeof(string).GetMethod("Format", new Type[2] { typeof(string), typeof(object) }), (string)null), new CodeMatch((OpCode?)OpCodes.Newobj, (object)typeof(InvalidOperationException).GetConstructor(new Type[1] { typeof(string) }), (string)null), new CodeMatch((OpCode?)OpCodes.Throw, (object)null, (string)null) }; val.MatchForward(false, array); if (val.IsInvalid) { Plugin.LogError("Failed to find Burst compilation failure throw statement"); return instructions; } List