using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using Atlas;
using Atlas.MappingComponents.Sandbox;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DRNewEngland;
using FistVR;
using JerryDR;
using Sodalite.Api;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace Alloy
{
public static class EnumExtension
{
public static bool HasFlag(this Enum keys, Enum flag)
{
int num = Convert.ToInt32(keys);
int num2 = Convert.ToInt32(flag);
return (num & num2) == num2;
}
}
}
namespace JerryDR
{
public sealed class DRCrowdDistanceManager : MonoBehaviour
{
private sealed class Entry
{
public SosigSpawnPoint point;
public Sosig spawned;
public bool entered;
public float retryAt;
public Transform detachedRoot;
public GameObject[] links;
}
public float Range = 200f;
public float CheckInterval = 0.25f;
public int MaxSpawnsPerFrame = 2;
private Entry[] entries;
private float nextCheck;
private int cursor;
private bool scanning;
private void Awake()
{
SosigSpawnPoint[] componentsInChildren = ((Component)this).GetComponentsInChildren<SosigSpawnPoint>(true);
entries = new Entry[componentsInChildren.Length];
for (int i = 0; i < componentsInChildren.Length; i++)
{
componentsInChildren[i].SpawnOnStart = false;
entries[i] = new Entry
{
point = componentsInChildren[i]
};
}
}
private void Update()
{
//IL_00a1: 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_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_010f: 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)
//IL_0190: 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: Expected O, but got Unknown
//IL_01d5: 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_0225: Unknown result type (might be due to invalid IL or missing references)
//IL_0243: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)GM.CurrentPlayerBody == (Object)null || !((Component)GM.CurrentPlayerBody).gameObject.activeInHierarchy)
{
if (scanning || Time.time >= nextCheck)
{
ClearAll();
nextCheck = Time.time + CheckInterval;
scanning = false;
}
return;
}
if (!scanning)
{
if (Time.time < nextCheck)
{
return;
}
cursor = 0;
scanning = true;
}
Vector3 position = ((Component)GM.CurrentPlayerBody).transform.position;
int num = 0;
float num2 = Range * Range;
while (cursor < entries.Length)
{
Entry entry = entries[cursor++];
if ((Object)(object)entry.point != (Object)null && ((Component)entry.point).gameObject.activeInHierarchy)
{
Vector3 val = ((Component)entry.point).transform.position - position;
if (((Vector3)(ref val)).sqrMagnitude <= num2)
{
if (entry.entered || Time.time < entry.retryAt || (Object)(object)ManagerSingleton<IM>.Instance == (Object)null || ManagerSingleton<IM>.Instance.odicSosigObjsByID == null || !ManagerSingleton<IM>.Instance.odicSosigObjsByID.TryGetValue(entry.point.SosigType, out var value) || (Object)(object)value == (Object)null)
{
continue;
}
try
{
SpawnOptions val2 = new SpawnOptions();
val2.SpawnActivated = entry.point.SpawnActive;
val2.SpawnState = entry.point.SpawnState;
val2.IFF = entry.point.IFF;
val2.SpawnWithFullAmmo = true;
val2.EquipmentMode = (EquipmentSlots)7;
val2.SosigTargetPosition = ((Component)entry.point).transform.position;
val2.SosigTargetRotation = ((Component)entry.point).transform.eulerAngles;
SpawnOptions val3 = val2;
entry.spawned = SosigAPI.Spawn(value, val3, ((Component)entry.point).transform.position, ((Component)entry.point).transform.rotation);
if ((Object)(object)entry.spawned != (Object)null)
{
entry.entered = true;
entry.detachedRoot = entry.spawned.DeParentOnSpawn;
List<GameObject> list = new List<GameObject>();
foreach (SosigLink link in entry.spawned.Links)
{
if ((Object)(object)link != (Object)null)
{
list.Add(((Component)link).gameObject);
}
}
entry.links = list.ToArray();
}
else
{
entry.retryAt = Time.time + 5f;
}
}
catch (Exception ex)
{
entry.retryAt = Time.time + 5f;
Debug.LogException(ex, (Object)(object)this);
}
if (++num < Mathf.Max(1, MaxSpawnsPerFrame))
{
continue;
}
break;
}
}
Clear(entry);
}
if (cursor >= entries.Length)
{
scanning = false;
nextCheck = Time.time + Mathf.Max(0.05f, CheckInterval);
}
}
private void Clear(Entry e)
{
if ((Object)(object)e.spawned != (Object)null)
{
e.spawned.DeSpawnSosig();
}
if (e.links != null)
{
GameObject[] links = e.links;
foreach (GameObject val in links)
{
if ((Object)(object)val != (Object)null)
{
Object.Destroy((Object)(object)val);
}
}
}
if ((Object)(object)e.detachedRoot != (Object)null)
{
Object.Destroy((Object)(object)((Component)e.detachedRoot).gameObject);
}
e.spawned = null;
e.links = null;
e.detachedRoot = null;
e.entered = false;
e.retryAt = 0f;
}
private void ClearAll()
{
if (entries != null)
{
Entry[] array = entries;
foreach (Entry e in array)
{
Clear(e);
}
}
}
private void OnDisable()
{
ClearAll();
scanning = false;
}
private void OnDestroy()
{
ClearAll();
}
}
}
namespace JerryAr.DR_NewEngland
{
public enum PacenoteVoice
{
Male,
Female
}
public static class DRMapConfig
{
public static ConfigEntry<bool> EnableSosigs;
public static ConfigEntry<bool> EnableDistantForest;
public static ConfigEntry<bool> EnableSpectatorDepthFix;
public static ConfigEntry<float> DistantForestDistance;
public static ConfigEntry<float> SpectatorNearClip;
public static ConfigEntry<PacenoteVoice> Voice;
public static ConfigEntry<bool> EnableSharedMap;
public static ConfigEntry<float> ObjectLoadDistance;
public static ConfigEntry<float> SosigLoadDistance;
public static ConfigEntry<bool> EnableTreeShadows;
public static ConfigEntry<float> TreeShadowDistance;
public static ConfigEntry<float> ObjectPreloadBuffer;
public static ConfigEntry<float> ObjectUnloadBuffer;
public static ConfigEntry<float> StreamingBudgetMs;
public static ConfigEntry<int> MaxObjectSpawnsPerFrame;
public static ConfigEntry<int> MaxObjectDespawnsPerFrame;
public static void Bind(ConfigFile config)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Expected O, but got Unknown
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Expected O, but got Unknown
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Expected O, but got Unknown
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Expected O, but got Unknown
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Expected O, but got Unknown
//IL_01c4: 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_0207: Expected O, but got Unknown
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Expected O, but got Unknown
//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
//IL_02ca: Expected O, but got Unknown
EnableDistantForest = config.Bind<bool>("Scenery", "EnableDistantForest", true, "Original low-detail forest billboards, no shadows or collisions. Applied next map load. / 原版远景树林,无碰撞和阴影,下次加载地图生效。");
DistantForestDistance = config.Bind<float>("Scenery", "DistantForestDistance", 1500f, new ConfigDescription("Distant forest visibility in metres. Course surroundings are included up to 3500m from the route. / 远景树林距离(米),资源覆盖赛道周围3500米。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(300f, 2500f), new object[0]));
EnableSpectatorDepthFix = config.Bind<bool>("Camera", "EnableSpectatorDepthFix", true, "Improve depth precision only on H3VR spectator/preview cameras. Does not change VR eyes. / 改善观战摄像机深度精度,不改变VR主视角。");
SpectatorNearClip = config.Bind<float>("Camera", "SpectatorNearClip", 0.3f, new ConfigDescription("Minimum spectator near clip during rendering, in metres. Objects closer than this may be clipped in the spectator image. Original settings restored after each render. / 观战近裁剪距离(米),过近物体可能被裁掉;渲染后恢复原值。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 1f), new object[0]));
EnableTreeShadows = config.Bind<bool>("Scenery", "EnableTreeShadows", true, "Enable nearby tree and bush shadows. / 是否启用近处树木和灌木的阴影,下次加载地图生效。");
TreeShadowDistance = config.Bind<float>("Scenery", "TreeShadowDistance", 80f, new ConfigDescription("Tree shadow distance in metres; does not hide trees. Zero disables tree shadows. / 树木阴影距离(米),0 关闭树木阴影。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), new object[0]));
ObjectPreloadBuffer = config.Bind<float>("Streaming", "ObjectPreloadBuffer", 75f, new ConfigDescription("Create scenery this far beyond ObjectLoadDistance. Buffered renderers are hidden, colliders remain active. / 可见范围外提前加载距离(米),预载物体隐藏但碰撞有效。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 500f), new object[0]));
ObjectUnloadBuffer = config.Bind<float>("Streaming", "ObjectUnloadBuffer", 50f, new ConfigDescription("Extra distance beyond the preload radius before destroying scenery, to prevent border thrashing. / 超出预载范围后再保留的距离(米),避免边界反复创建。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 500f), new object[0]));
MaxObjectSpawnsPerFrame = config.Bind<int>("Streaming", "MaxObjectSpawnsPerFrame", 32, new ConfigDescription("Maximum scenery objects created per frame; nearest first. / 每帧最多创建物体数,优先最近处。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 512), new object[0]));
MaxObjectDespawnsPerFrame = config.Bind<int>("Streaming", "MaxObjectDespawnsPerFrame", 64, new ConfigDescription("Maximum scenery objects destroyed per frame. / 每帧最多回收物体数。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 512), new object[0]));
StreamingBudgetMs = config.Bind<float>("Streaming", "StreamingBudgetMs", 2f, new ConfigDescription("Soft creation/destruction time budget per frame in milliseconds. A single object can exceed it; at least one removal is allowed to prevent starvation. / 每帧创建和回收的软时间预算(毫秒),单个物体操作可能超时。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), new object[0]));
EnableSosigs = config.Bind<bool>("Crowd", "EnableSosigs", true, "Enable Sosig spectators. Disabled removes generated spectators, not spawn points. Applied on the next map load. / 是否生成观众,下次加载地图生效。");
SosigLoadDistance = config.Bind<float>("Crowd", "SosigLoadDistance", 200f, new ConfigDescription("Player distance from each spawn point in metres. Enter to spawn once, leave to despawn, return to spawn again. Applied on map load. / 观众生成和销毁距离(米)。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 2000f), new object[0]));
Voice = config.Bind<PacenoteVoice>("Pacenotes", "Voice", PacenoteVoice.Male, "Male enables pacebookMale; Female enables pacebookFemale. Only one is active per map load. / 男声或女声路书,下次加载地图生效。");
EnableSharedMap = config.Bind<bool>("Scenery", "EnableSharedMap", true, "Enable the R3_Shared_Map scene root. Applied on map load. / 是否启用 R3_Shared_Map,下次加载地图生效。");
ObjectLoadDistance = config.Bind<float>("Scenery", "ObjectLoadDistance", 200f, new ConfigDescription("Visible distance in metres for streamed scenery and legacy distance cullers. Re-enable at 5 metres closer to avoid flicker. Does not change terrain or unmanaged objects. Applied on map load. / 场景物体可见距离(米),预载距离另行设置,不改变地形。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 5000f), new object[0]));
}
public static float SafeDistance(float value, float min, float max)
{
return (!float.IsNaN(value) && !float.IsInfinity(value)) ? Mathf.Clamp(value, min, max) : 200f;
}
public static bool Apply(Scene scene)
{
if (!((Scene)(ref scene)).IsValid() || !((Scene)(ref scene)).isLoaded || EnableSosigs == null)
{
return false;
}
GameObject val = null;
GameObject val2 = null;
GameObject val3 = null;
GameObject[] rootGameObjects = ((Scene)(ref scene)).GetRootGameObjects();
GameObject[] array = rootGameObjects;
foreach (GameObject val4 in array)
{
if (((Object)val4).name == "R3_Shared_Map")
{
val = val4;
}
}
if ((Object)(object)val == (Object)null || !string.Equals(((Scene)(ref scene)).name, "NewEngland", StringComparison.OrdinalIgnoreCase))
{
return false;
}
float num = SafeDistance(ObjectLoadDistance.Value, 10f, 5000f);
float range = SafeDistance(SosigLoadDistance.Value, 10f, 2000f);
GameObject[] array2 = rootGameObjects;
foreach (GameObject val5 in array2)
{
DRDistantForest[] componentsInChildren = val5.GetComponentsInChildren<DRDistantForest>(true);
foreach (DRDistantForest dRDistantForest in componentsInChildren)
{
dRDistantForest.distance = SafeNumber(DistantForestDistance.Value, 1500f, 300f, 2500f);
((Behaviour)dRDistantForest).enabled = EnableDistantForest.Value;
}
DRSpectatorDepthGuard[] componentsInChildren2 = val5.GetComponentsInChildren<DRSpectatorDepthGuard>(true);
foreach (DRSpectatorDepthGuard dRSpectatorDepthGuard in componentsInChildren2)
{
dRSpectatorDepthGuard.nearClip = SafeNumber(SpectatorNearClip.Value, 0.3f, 0.05f, 1f);
((Behaviour)dRSpectatorDepthGuard).enabled = EnableSpectatorDepthFix.Value;
}
Transform[] componentsInChildren3 = val5.GetComponentsInChildren<Transform>(true);
foreach (Transform val6 in componentsInChildren3)
{
if (((Object)val6).name == "pacebookMale")
{
val2 = ((Component)val6).gameObject;
}
if (((Object)val6).name == "pacebookFemale")
{
val3 = ((Component)val6).gameObject;
}
}
DRVegetationDistanceCuller[] componentsInChildren4 = val5.GetComponentsInChildren<DRVegetationDistanceCuller>(true);
foreach (DRVegetationDistanceCuller dRVegetationDistanceCuller in componentsInChildren4)
{
dRVegetationDistanceCuller.disableDistance = num;
dRVegetationDistanceCuller.reenableDistance = Mathf.Max(0f, num - 5f);
}
DRSceneryStreamer[] componentsInChildren5 = val5.GetComponentsInChildren<DRSceneryStreamer>(true);
foreach (DRSceneryStreamer dRSceneryStreamer in componentsInChildren5)
{
dRSceneryStreamer.loadDistance = num;
dRSceneryStreamer.enableTreeShadows = EnableTreeShadows.Value;
dRSceneryStreamer.treeShadowDistance = SafeNumber(TreeShadowDistance.Value, 80f, 0f, 1000f);
dRSceneryStreamer.preloadBuffer = SafeNumber(ObjectPreloadBuffer.Value, 75f, 0f, 500f);
dRSceneryStreamer.unloadBuffer = SafeNumber(ObjectUnloadBuffer.Value, 50f, 10f, 500f);
dRSceneryStreamer.maxSpawnsPerFrame = Mathf.Clamp(MaxObjectSpawnsPerFrame.Value, 1, 512);
dRSceneryStreamer.maxDespawnsPerFrame = Mathf.Clamp(MaxObjectDespawnsPerFrame.Value, 1, 512);
dRSceneryStreamer.frameBudgetMs = SafeNumber(StreamingBudgetMs.Value, 2f, 0.1f, 10f);
}
SosigSpawnPoint[] componentsInChildren6 = val5.GetComponentsInChildren<SosigSpawnPoint>(true);
foreach (SosigSpawnPoint val7 in componentsInChildren6)
{
val7.SpawnOnStart = false;
if ((Object)(object)((Component)val7).GetComponentInParent<DRCrowdDistanceManager>() == (Object)null)
{
((Component)val7).gameObject.AddComponent<DRCrowdDistanceManager>();
}
}
DRCrowdDistanceManager[] componentsInChildren7 = val5.GetComponentsInChildren<DRCrowdDistanceManager>(true);
foreach (DRCrowdDistanceManager dRCrowdDistanceManager in componentsInChildren7)
{
dRCrowdDistanceManager.Range = range;
((Behaviour)dRCrowdDistanceManager).enabled = EnableSosigs.Value;
}
}
if (Voice.Value == PacenoteVoice.Female)
{
if ((Object)(object)val2 != (Object)null)
{
val2.SetActive(false);
}
if ((Object)(object)val3 != (Object)null)
{
val3.SetActive(true);
}
}
else
{
if ((Object)(object)val3 != (Object)null)
{
val3.SetActive(false);
}
if ((Object)(object)val2 != (Object)null)
{
val2.SetActive(true);
}
}
val.SetActive(EnableSharedMap.Value);
return true;
}
private static float SafeNumber(float value, float fallback, float min, float max)
{
return (!float.IsNaN(value) && !float.IsInfinity(value)) ? Mathf.Clamp(value, min, max) : fallback;
}
}
[BepInPlugin("JerryAr.DR_NewEngland", "DR_NewEngland", "1.3.0")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("nrgill28.Atlas", "1.0.1")]
public class DR_NewEnglandPlugin : BaseUnityPlugin
{
private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
internal static ManualLogSource Logger;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
DRMapConfig.Bind(((BaseUnityPlugin)this).Config);
SceneManager.sceneLoaded += OnSceneLoaded;
LoadAssets();
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_001e: 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)
if (!string.Equals(((Scene)(ref scene)).name, "NewEngland", StringComparison.OrdinalIgnoreCase))
{
return;
}
try
{
int num = DRReverbSetup.Apply(scene);
if (num > 0)
{
Logger.LogWarning((object)("Repaired " + num + " invalid New England reverb references before audio initialization."));
}
((BaseUnityPlugin)this).Config.Reload();
if (DRMapConfig.Apply(scene))
{
Logger.LogInfo((object)("Applied New England map configuration: " + ((BaseUnityPlugin)this).Config.ConfigFilePath));
}
}
catch (Exception ex)
{
Logger.LogError((object)("Could not apply New England configuration: " + ex));
}
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
private void LoadAssets()
{
AtlasPlugin.RegisterScene(Path.Combine(BasePath, "newengland"));
}
}
public static class DRReverbSetup
{
public static int Apply(Scene scene)
{
if (!((Scene)(ref scene)).IsValid() || !((Scene)(ref scene)).isLoaded || !string.Equals(((Scene)(ref scene)).name, "NewEngland", StringComparison.OrdinalIgnoreCase))
{
return 0;
}
int num = 0;
GameObject[] rootGameObjects = ((Scene)(ref scene)).GetRootGameObjects();
foreach (GameObject val in rootGameObjects)
{
FVRReverbSystem[] componentsInChildren = val.GetComponentsInChildren<FVRReverbSystem>(true);
foreach (FVRReverbSystem system in componentsInChildren)
{
num += Repair(system);
}
}
return num;
}
public static int Repair(FVRReverbSystem system)
{
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)system == (Object)null)
{
return 0;
}
int num = 0;
if (system.Environments == null)
{
system.Environments = new List<FVRReverbEnvironment>();
num++;
}
for (int num2 = system.Environments.Count - 1; num2 >= 0; num2--)
{
if ((Object)(object)system.Environments[num2] == (Object)null)
{
system.Environments.RemoveAt(num2);
num++;
}
}
if ((Object)(object)system.DefaultEnvironment == (Object)null)
{
FVRReverbEnvironment val = ((Component)system).GetComponent<FVRReverbEnvironment>();
if ((Object)(object)val == (Object)null)
{
val = ((Component)system).gameObject.AddComponent<FVRReverbEnvironment>();
val.Environment = (FVRSoundEnvironment)21;
}
system.DefaultEnvironment = val;
num++;
}
system.DefaultEnvironment.SetPriorityBasedOnType();
if ((Object)(object)system.CurrentReverbEnvironment == (Object)null)
{
system.CurrentReverbEnvironment = system.DefaultEnvironment;
num++;
}
if (system.Environments.Count == 0 && num > 0)
{
system.Environments.Add(system.DefaultEnvironment);
num++;
}
system.m_lowestPriority = 100;
foreach (FVRReverbEnvironment environment in system.Environments)
{
environment.SetPriorityBasedOnType();
system.m_lowestPriority = Mathf.Min(system.m_lowestPriority, environment.Priority);
}
system.hasEnvironmentsToCheck = system.Environments.Count > 0;
return num;
}
}
}
namespace JerryDR
{
public class Lockwithhead : MonoBehaviour
{
private void Update()
{
//IL_0031: 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)
if ((Object)(object)GM.CurrentMovementManager != (Object)null)
{
((Component)this).gameObject.transform.position = ((Component)GM.CurrentMovementManager.Head).gameObject.transform.position;
((Component)this).gameObject.transform.rotation = ((Component)GM.CurrentMovementManager.Head).gameObject.transform.rotation;
}
}
}
public class SpawnVehicle : MonoBehaviour
{
public FVRObject id;
public bool spawned;
public GameObject car;
private void FixedUpdate()
{
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
if (!spawned && (Object)(object)GM.CurrentPlayerBody != (Object)null && ((Component)GM.CurrentPlayerBody).gameObject.activeInHierarchy)
{
if ((Object)(object)car != (Object)null)
{
Object.Destroy((Object)(object)car);
}
car = Object.Instantiate<GameObject>(((AnvilAsset)id).GetGameObject(), ((Component)this).gameObject.transform.position, ((Component)this).gameObject.transform.rotation);
spawned = true;
}
if ((Object)(object)GM.CurrentPlayerBody != (Object)null && !((Component)GM.CurrentPlayerBody).gameObject.activeInHierarchy)
{
spawned = false;
}
if ((Object)(object)GM.CurrentPlayerBody == (Object)null)
{
spawned = false;
}
}
}
}
namespace MeatKit
{
public class HideInNormalInspectorAttribute : PropertyAttribute
{
}
}
[BepInPlugin("MeatKit", "MeatKit Plugin", "1.0.0")]
[BepInProcess("h3vr.exe")]
public class MeatKitPlugin : BaseUnityPlugin
{
private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
internal static ManualLogSource Logger;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
LoadAssets();
}
private void LoadAssets()
{
}
}
namespace SimpleLightProbePlacer
{
[RequireComponent(typeof(LightProbeGroup))]
[AddComponentMenu("Rendering/Light Probe Group Control")]
public class LightProbeGroupControl : MonoBehaviour
{
[SerializeField]
private float m_mergeDistance = 0.5f;
[SerializeField]
private bool m_usePointLights = true;
[SerializeField]
private float m_pointLightRange = 1f;
private int m_mergedProbes;
private LightProbeGroup m_lightProbeGroup;
public float MergeDistance
{
get
{
return m_mergeDistance;
}
set
{
m_mergeDistance = value;
}
}
public int MergedProbes => m_mergedProbes;
public bool UsePointLights
{
get
{
return m_usePointLights;
}
set
{
m_usePointLights = value;
}
}
public float PointLightRange
{
get
{
return m_pointLightRange;
}
set
{
m_pointLightRange = value;
}
}
public LightProbeGroup LightProbeGroup
{
get
{
if ((Object)(object)m_lightProbeGroup != (Object)null)
{
return m_lightProbeGroup;
}
return m_lightProbeGroup = ((Component)this).GetComponent<LightProbeGroup>();
}
}
public void DeleteAll()
{
LightProbeGroup.probePositions = null;
m_mergedProbes = 0;
}
public void Create()
{
DeleteAll();
List<Vector3> list = CreatePositions();
list.AddRange(CreateAroundPointLights(m_pointLightRange));
list = MergeClosestPositions(list, m_mergeDistance, out m_mergedProbes);
ApplyPositions(list);
}
public void Merge()
{
if (LightProbeGroup.probePositions != null)
{
List<Vector3> source = MergeClosestPositions(LightProbeGroup.probePositions.ToList(), m_mergeDistance, out m_mergedProbes);
source = source.Select((Vector3 x) => ((Component)this).transform.TransformPoint(x)).ToList();
ApplyPositions(source);
}
}
private void ApplyPositions(List<Vector3> positions)
{
LightProbeGroup.probePositions = positions.Select((Vector3 x) => ((Component)this).transform.InverseTransformPoint(x)).ToArray();
}
private static List<Vector3> CreatePositions()
{
LightProbeVolume[] array = Object.FindObjectsOfType<LightProbeVolume>();
if (array.Length == 0)
{
return new List<Vector3>();
}
List<Vector3> list = new List<Vector3>();
for (int i = 0; i < array.Length; i++)
{
list.AddRange(array[i].CreatePositions());
}
return list;
}
private static List<Vector3> CreateAroundPointLights(float range)
{
List<Light> list = (from x in Object.FindObjectsOfType<Light>()
where (int)x.type == 2
select x).ToList();
if (list.Count == 0)
{
return new List<Vector3>();
}
List<Vector3> list2 = new List<Vector3>();
for (int num = 0; num < list.Count; num++)
{
list2.AddRange(CreatePositionsAround(((Component)list[num]).transform, range));
}
return list2;
}
private static List<Vector3> MergeClosestPositions(List<Vector3> positions, float distance, out int mergedCount)
{
//IL_00a2: 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_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_0153: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
if (positions == null)
{
mergedCount = 0;
return new List<Vector3>();
}
int count = positions.Count;
bool flag = false;
while (!flag)
{
Dictionary<Vector3, List<Vector3>> dictionary = new Dictionary<Vector3, List<Vector3>>();
for (int i = 0; i < positions.Count; i++)
{
List<Vector3> list = positions.Where(delegate(Vector3 x)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = x - positions[i];
return ((Vector3)(ref val)).magnitude < distance;
}).ToList();
if (list.Count > 0 && !dictionary.ContainsKey(positions[i]))
{
dictionary.Add(positions[i], list);
}
}
positions.Clear();
List<Vector3> list2 = dictionary.Keys.ToList();
for (int num = 0; num < list2.Count; num++)
{
Vector3 center = dictionary[list2[num]].Aggregate(Vector3.zero, (Vector3 result, Vector3 target) => result + target) / (float)dictionary[list2[num]].Count;
if (!positions.Exists((Vector3 x) => x == center))
{
positions.Add(center);
}
}
flag = positions.Select((Vector3 x) => positions.Where(delegate(Vector3 y)
{
//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_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//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)
int result;
if (y != x)
{
Vector3 val = y - x;
result = ((((Vector3)(ref val)).magnitude < distance) ? 1 : 0);
}
else
{
result = 0;
}
return (byte)result != 0;
})).All((IEnumerable<Vector3> x) => !x.Any());
}
mergedCount = count - positions.Count;
return positions;
}
public static List<Vector3> CreatePositionsAround(Transform transform, float range)
{
//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_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_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_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_00b1: 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_00d1: 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_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_0111: 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)
Vector3[] source = (Vector3[])(object)new Vector3[8]
{
new Vector3(-0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, 0.5f, 0.5f),
new Vector3(0.5f, 0.5f, 0.5f),
new Vector3(0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, 0.5f),
new Vector3(0.5f, -0.5f, 0.5f),
new Vector3(0.5f, -0.5f, -0.5f)
};
return source.Select((Vector3 x) => transform.TransformPoint(x * range)).ToList();
}
}
public enum LightProbeVolumeType
{
Fixed,
Float
}
[AddComponentMenu("Rendering/Light Probe Volume")]
public class LightProbeVolume : TransformVolume
{
[SerializeField]
private LightProbeVolumeType m_type = LightProbeVolumeType.Fixed;
[SerializeField]
private Vector3 m_densityFixed = Vector3.one;
[SerializeField]
private Vector3 m_densityFloat = Vector3.one;
public LightProbeVolumeType Type
{
get
{
return m_type;
}
set
{
m_type = value;
}
}
public Vector3 Density
{
get
{
//IL_0018: 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_001d: 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)
return (m_type != LightProbeVolumeType.Fixed) ? m_densityFloat : m_densityFixed;
}
set
{
//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_000d: 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)
if (m_type == LightProbeVolumeType.Fixed)
{
m_densityFixed = value;
}
else
{
m_densityFloat = value;
}
}
}
public static Color EditorColor => new Color(1f, 0.9f, 0.25f);
public List<Vector3> CreatePositions()
{
return CreatePositions(m_type);
}
public List<Vector3> CreatePositions(LightProbeVolumeType type)
{
//IL_0030: 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_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)
return (type != LightProbeVolumeType.Fixed) ? CreatePositionsFloat(((Component)this).transform, base.Origin, base.Size, Density) : CreatePositionsFixed(((Component)this).transform, base.Origin, base.Size, Density);
}
public static List<Vector3> CreatePositionsFixed(Transform volumeTransform, Vector3 origin, Vector3 size, Vector3 density)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_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_005d: 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_008a: 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_0094: 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_0099: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
List<Vector3> list = new List<Vector3>();
Vector3 val = origin;
float num = size.x / (float)Mathf.FloorToInt(density.x);
float num2 = size.y / (float)Mathf.FloorToInt(density.y);
float num3 = size.z / (float)Mathf.FloorToInt(density.z);
val -= size * 0.5f;
for (int i = 0; (float)i <= density.x; i++)
{
for (int j = 0; (float)j <= density.y; j++)
{
for (int k = 0; (float)k <= density.z; k++)
{
Vector3 val2 = val + new Vector3((float)i * num, (float)j * num2, (float)k * num3);
val2 = volumeTransform.TransformPoint(val2);
list.Add(val2);
}
}
}
return list;
}
public static List<Vector3> CreatePositionsFloat(Transform volumeTransform, Vector3 origin, Vector3 size, Vector3 density)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_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_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_005a: 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_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: 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_0122: Unknown result type (might be due to invalid IL or missing references)
List<Vector3> list = new List<Vector3>();
Vector3 val = origin;
int num = Mathf.FloorToInt(size.x / density.x);
int num2 = Mathf.FloorToInt(size.y / density.y);
int num3 = Mathf.FloorToInt(size.z / density.z);
val -= size * 0.5f;
val.x += (size.x - (float)num * density.x) * 0.5f;
val.y += (size.y - (float)num2 * density.y) * 0.5f;
val.z += (size.z - (float)num3 * density.z) * 0.5f;
for (int i = 0; i <= num; i++)
{
for (int j = 0; j <= num2; j++)
{
for (int k = 0; k <= num3; k++)
{
Vector3 val2 = val + new Vector3((float)i * density.x, (float)j * density.y, (float)k * density.z);
val2 = volumeTransform.TransformPoint(val2);
list.Add(val2);
}
}
}
return list;
}
}
[AddComponentMenu("")]
public class TransformVolume : MonoBehaviour
{
[SerializeField]
private Volume m_volume = new Volume(Vector3.zero, Vector3.one);
public Volume Volume
{
get
{
return m_volume;
}
set
{
m_volume = value;
}
}
public Vector3 Origin => m_volume.Origin;
public Vector3 Size => m_volume.Size;
public bool IsInBounds(Vector3[] points)
{
//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)
Bounds bounds = GetBounds();
return ((Bounds)(ref bounds)).Intersects(GetBounds(points));
}
public bool IsOnBorder(Vector3[] points)
{
if (points.All((Vector3 x) => !IsInVolume(x)))
{
return false;
}
return !points.All(IsInVolume);
}
public bool IsInVolume(Vector3[] points)
{
return points.All(IsInVolume);
}
public bool IsInVolume(Vector3 position)
{
//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_0020: Unknown result type (might be due to invalid IL or missing references)
Plane val = default(Plane);
for (int i = 0; i < 6; i++)
{
((Plane)(ref val))..ctor(GetSideDirection(i), GetSidePosition(i));
if (((Plane)(ref val)).GetSide(position))
{
return false;
}
}
return true;
}
public Vector3[] GetCorners()
{
//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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//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_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: 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_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_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: 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)
Vector3[] array = (Vector3[])(object)new Vector3[8]
{
new Vector3(-0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, 0.5f, 0.5f),
new Vector3(0.5f, 0.5f, 0.5f),
new Vector3(0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, 0.5f),
new Vector3(0.5f, -0.5f, 0.5f),
new Vector3(0.5f, -0.5f, -0.5f)
};
for (int i = 0; i < array.Length; i++)
{
ref Vector3 reference = ref array[i];
reference.x *= m_volume.Size.x;
ref Vector3 reference2 = ref array[i];
reference2.y *= m_volume.Size.y;
ref Vector3 reference3 = ref array[i];
reference3.z *= m_volume.Size.z;
ref Vector3 reference4 = ref array[i];
reference4 = ((Component)this).transform.TransformPoint(m_volume.Origin + array[i]);
}
return array;
}
public Bounds GetBounds()
{
//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_0013: Unknown result type (might be due to invalid IL or missing references)
return GetBounds(GetCorners());
}
public Bounds GetBounds(Vector3[] points)
{
//IL_0002: 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_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_0035: 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_0051: 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_006a: 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)
Vector3 val = points.Aggregate(Vector3.zero, (Vector3 val2, Vector3 point) => val2 + point) / (float)points.Length;
Bounds result = default(Bounds);
((Bounds)(ref result))..ctor(val, Vector3.zero);
for (int num = 0; num < points.Length; num++)
{
((Bounds)(ref result)).Encapsulate(points[num]);
}
return result;
}
public GameObject[] GetGameObjectsInBounds(LayerMask layerMask)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: 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)
MeshRenderer[] array = Object.FindObjectsOfType<MeshRenderer>();
List<GameObject> list = new List<GameObject>();
Bounds bounds = GetBounds();
for (int i = 0; i < array.Length; i++)
{
if (!((Object)(object)((Component)array[i]).gameObject == (Object)(object)((Component)((Component)this).transform).gameObject) && !((Object)(object)((Component)array[i]).GetComponent<TransformVolume>() != (Object)null) && ((1 << ((Component)array[i]).gameObject.layer) & ((LayerMask)(ref layerMask)).value) != 0 && ((Bounds)(ref bounds)).Intersects(((Renderer)array[i]).bounds))
{
list.Add(((Component)array[i]).gameObject);
}
}
return list.ToArray();
}
public Vector3 GetSideDirection(int side)
{
//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_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: 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_0021: 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_002e: 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_0040: 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_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: 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_006c: 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_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: 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)
Vector3[] array = (Vector3[])(object)new Vector3[6];
Vector3 right = Vector3.right;
Vector3 up = Vector3.up;
Vector3 forward = Vector3.forward;
array[0] = right;
ref Vector3 reference = ref array[1];
reference = -right;
array[2] = up;
ref Vector3 reference2 = ref array[3];
reference2 = -up;
array[4] = forward;
ref Vector3 reference3 = ref array[5];
reference3 = -forward;
return ((Component)this).transform.TransformDirection(array[side]);
}
public Vector3 GetSidePosition(int side)
{
//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_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: 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_0021: 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_002e: 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_0040: 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_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: 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_006c: 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_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: 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_00aa: 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)
Vector3[] array = (Vector3[])(object)new Vector3[6];
Vector3 right = Vector3.right;
Vector3 up = Vector3.up;
Vector3 forward = Vector3.forward;
array[0] = right;
ref Vector3 reference = ref array[1];
reference = -right;
array[2] = up;
ref Vector3 reference2 = ref array[3];
reference2 = -up;
array[4] = forward;
ref Vector3 reference3 = ref array[5];
reference3 = -forward;
return ((Component)this).transform.TransformPoint(array[side] * GetSizeAxis(side) + m_volume.Origin);
}
public float GetSizeAxis(int side)
{
//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_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
switch (side)
{
case 0:
case 1:
return m_volume.Size.x * 0.5f;
case 2:
case 3:
return m_volume.Size.y * 0.5f;
default:
return m_volume.Size.z * 0.5f;
}
}
}
[Serializable]
public struct Volume
{
[SerializeField]
private Vector3 m_origin;
[SerializeField]
private Vector3 m_size;
public Vector3 Origin => m_origin;
public Vector3 Size => m_size;
public Volume(Vector3 origin, Vector3 size)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_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)
m_origin = origin;
m_size = size;
}
public static bool operator ==(Volume left, Volume right)
{
return left.Equals(right);
}
public static bool operator !=(Volume left, Volume right)
{
return !left.Equals(right);
}
public bool Equals(Volume other)
{
//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)
//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)
return Origin == other.Origin && Size == other.Size;
}
public override bool Equals(object obj)
{
if (object.ReferenceEquals(null, obj))
{
return false;
}
return obj is Volume && Equals((Volume)obj);
}
public override int GetHashCode()
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_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)
return (((object)Origin/*cast due to .constrained prefix*/).GetHashCode() * 397) ^ ((object)Size/*cast due to .constrained prefix*/).GetHashCode();
}
public override string ToString()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
return $"Origin: {Origin}, Size: {Size}";
}
}
}
namespace DRNewEngland
{
public sealed class DRDistantForest : MonoBehaviour
{
public DRDistantForestData data;
public DRSceneryStreamer scenery;
public float distance = 1500f;
private MaterialPropertyBlock properties;
public int LastDrawCalls { get; private set; }
public int LastTriangles { get; private set; }
private void Start()
{
if (!((Object)(object)data != (Object)null))
{
return;
}
Mesh[] meshes = data.meshes;
foreach (Mesh val in meshes)
{
if ((Object)(object)val != (Object)null && val.isReadable)
{
val.UploadMeshData(true);
}
}
}
private void OnEnable()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
Camera.onPreCull = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(Draw));
}
private void OnDisable()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
Camera.onPreCull = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(Draw));
}
public void Draw(Camera camera)
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Invalid comparison between Unknown and I4
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Expected O, but got Unknown
//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_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: 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_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_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_0242: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_0262: Unknown result type (might be due to invalid IL or missing references)
//IL_0267: Unknown result type (might be due to invalid IL or missing references)
//IL_0273: Unknown result type (might be due to invalid IL or missing references)
//IL_0275: Unknown result type (might be due to invalid IL or missing references)
//IL_027a: Unknown result type (might be due to invalid IL or missing references)
//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
LastDrawCalls = 0;
LastTriangles = 0;
if (!((Behaviour)this).isActiveAndEnabled || (Object)(object)data == (Object)null || (Object)(object)data.material == (Object)null || (Object)(object)camera == (Object)null || (int)camera.cameraType == 4 || (camera.cullingMask & (1 << ((Component)this).gameObject.layer)) == 0)
{
return;
}
float num = Mathf.Clamp(distance, 300f, 2500f);
float num2 = ((!((Object)(object)scenery == (Object)null)) ? Mathf.Max(10f, scenery.loadDistance) : 200f);
if (num2 >= num)
{
return;
}
if (properties == null)
{
properties = new MaterialPropertyBlock();
}
properties.SetVector("_Ranges", new Vector4(Mathf.Max(0f, num2 - 30f), num2, Mathf.Max(num2, num - 150f), num));
properties.SetVector("_Observer", Vector4.op_Implicit(((Component)camera).transform.position));
Vector3 position = ((Component)camera).transform.position;
if ((Object)(object)scenery != (Object)null && (Object)(object)scenery.target != (Object)null)
{
position = scenery.target.position;
}
else if ((Object)(object)GM.CurrentPlayerBody != (Object)null)
{
position = ((Component)GM.CurrentPlayerBody).transform.position;
}
else if ((Object)(object)Camera.main != (Object)null)
{
position = ((Component)Camera.main).transform.position;
}
properties.SetVector("_DetailObserver", Vector4.op_Implicit(position));
Plane[] array = GeometryUtility.CalculateFrustumPlanes(camera);
Vector3 position2 = ((Component)camera).transform.position;
for (int i = 0; i < data.meshes.Length; i++)
{
Mesh val = data.meshes[i];
if (!((Object)(object)val == (Object)null))
{
Matrix4x4 val2 = ((Component)this).transform.localToWorldMatrix * Matrix4x4.TRS(data.origins[i], Quaternion.identity, Vector3.one);
Bounds bounds = val.bounds;
((Bounds)(ref bounds)).center = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(((Bounds)(ref bounds)).center);
Vector3 val3 = ((Bounds)(ref bounds)).ClosestPoint(position2);
float num3 = val3.x - position2.x;
float num4 = val3.z - position2.z;
if (!(num3 * num3 + num4 * num4 > num * num) && GeometryUtility.TestPlanesAABB(array, bounds))
{
Graphics.DrawMesh(val, val2, data.material, ((Component)this).gameObject.layer, camera, 0, properties, (ShadowCastingMode)0, false, (Transform)null, false);
LastDrawCalls++;
LastTriangles += val.vertexCount / 2;
}
}
}
}
}
public sealed class DRDistantForestData : ScriptableObject
{
public Mesh[] meshes;
public Vector3[] origins;
public Material material;
}
[RequireComponent(typeof(AudioSource))]
public sealed class DRPacenotePlayer : MonoBehaviour
{
public Transform player;
public DRPacenoteTrack track;
public AudioSource voice;
public float extraLookAheadSeconds = 0f;
public float maximumLookAheadMeters = 60f;
public float distanceOffset = 0f;
public float maximumRouteDistance = 40f;
public float teleportDistance = 40f;
public float maximumLateMeters = 100f;
public float progress;
public string lastCall;
private int segment;
private int nextCue;
private bool initialized;
private Vector3 lastPosition;
private readonly Queue<int> queue = new Queue<int>();
private void Awake()
{
if ((Object)(object)voice == (Object)null)
{
voice = ((Component)this).GetComponent<AudioSource>();
}
voice.playOnAwake = false;
voice.loop = false;
voice.spatialBlend = 0f;
}
private bool Valid()
{
return (Object)(object)player != (Object)null && (Object)(object)track != (Object)null && track.points != null && track.points.Length > 1 && track.distances != null && track.distances.Length == track.points.Length && track.cues != null;
}
public void Resynchronize()
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
if (Valid())
{
queue.Clear();
if ((Object)(object)voice != (Object)null)
{
voice.Stop();
}
progress = Project(player.position, global: true, out var _);
nextCue = 0;
while (nextCue < track.cues.Length && track.cues[nextCue].distance + distanceOffset < progress - 5f)
{
nextCue++;
}
lastPosition = player.position;
initialized = true;
}
}
private float Project(Vector3 p, bool global, out float off)
{
//IL_008a: 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_0094: 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_00ba: 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_00be: 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)
//IL_00c5: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: 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_0100: 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_0103: 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_010c: 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_0116: Unknown result type (might be due to invalid IL or missing references)
int num = ((!global) ? Mathf.Max(0, segment - 5) : 0);
int num2 = ((!global) ? Mathf.Min(track.points.Length - 2, segment + 20) : (track.points.Length - 2));
float num3 = float.MaxValue;
float result = progress;
int num4 = segment;
for (int i = num; i <= num2; i++)
{
Vector3 val = ((Component)this).transform.TransformPoint(track.points[i]);
Vector3 val2 = ((Component)this).transform.TransformPoint(track.points[i + 1]);
Vector3 val3 = val2 - val;
float num5 = ((!(((Vector3)(ref val3)).sqrMagnitude > 1E-05f)) ? 0f : Mathf.Clamp01(Vector3.Dot(p - val, val3) / ((Vector3)(ref val3)).sqrMagnitude));
Vector3 val4 = p - (val + val3 * num5);
float sqrMagnitude = ((Vector3)(ref val4)).sqrMagnitude;
if (sqrMagnitude < num3)
{
num3 = sqrMagnitude;
num4 = i;
result = Mathf.Lerp(track.distances[i], track.distances[i + 1], num5);
}
}
segment = num4;
off = Mathf.Sqrt(num3);
return result;
}
private void Update()
{
//IL_003d: 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_0077: 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_0088: Unknown result type (might be due to invalid IL or missing references)
if (!Valid() || Time.deltaTime <= 0f)
{
return;
}
if (!initialized)
{
Resynchronize();
return;
}
float num = Vector3.Distance(player.position, lastPosition);
if (num > Mathf.Max(1f, teleportDistance))
{
Resynchronize();
return;
}
lastPosition = player.position;
float off;
float num2 = Project(player.position, global: false, out off);
float num3 = Mathf.Clamp((num2 - progress) / Time.deltaTime, 0f, 100f);
progress = num2;
if (off > maximumRouteDistance || num / Time.deltaTime < 0.2f)
{
return;
}
float num4 = Mathf.Clamp(num3 * Mathf.Max(0f, extraLookAheadSeconds), 0f, maximumLookAheadMeters);
while (nextCue < track.cues.Length && track.cues[nextCue].distance + distanceOffset <= progress + num4)
{
DRPacenoteCue dRPacenoteCue = track.cues[nextCue];
if ((Object)(object)dRPacenoteCue.clip != (Object)null && progress <= dRPacenoteCue.distance + distanceOffset + maximumLateMeters && queue.Count < 4)
{
queue.Enqueue(nextCue);
}
nextCue++;
}
if ((Object)(object)voice == (Object)null || voice.isPlaying)
{
return;
}
while (queue.Count > 0)
{
DRPacenoteCue dRPacenoteCue2 = track.cues[queue.Dequeue()];
if (progress > dRPacenoteCue2.distance + distanceOffset + maximumLateMeters || (Object)(object)dRPacenoteCue2.clip == (Object)null)
{
continue;
}
voice.clip = dRPacenoteCue2.clip;
voice.Play();
lastCall = dRPacenoteCue2.name;
break;
}
}
private void OnDisable()
{
initialized = false;
queue.Clear();
if ((Object)(object)voice != (Object)null)
{
voice.Stop();
}
}
private void OnDrawGizmosSelected()
{
//IL_0027: 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_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)track == (Object)null) && track.points != null)
{
Gizmos.color = Color.cyan;
for (int i = 1; i < track.points.Length; i++)
{
Gizmos.DrawLine(((Component)this).transform.TransformPoint(track.points[i - 1]), ((Component)this).transform.TransformPoint(track.points[i]));
}
}
}
}
[Serializable]
public class DRPacenoteCue
{
public string name;
public float distance;
public string hint;
public AudioClip clip;
}
public sealed class DRPacenoteTrack : ScriptableObject
{
public Vector3[] points;
public float[] distances;
public DRPacenoteCue[] cues;
}
public sealed class DRSceneryCatalog : ScriptableObject
{
[Serializable]
public struct Placement
{
public int prefab;
public Vector3 position;
public Quaternion rotation;
public Vector3 scale;
public bool foliage;
}
public GameObject[] prefabs;
public Placement[] placements;
public float cellSize = 50f;
}
public sealed class DRSceneryStreamer : MonoBehaviour
{
private sealed class Resident
{
public GameObject obj;
public Renderer[] renderers;
public bool[] enabled;
public ShadowCastingMode[] shadows;
public bool visible;
public bool casts = true;
public float opacity;
}
private struct Candidate
{
public int id;
public float distance;
}
public DRSceneryCatalog catalog;
public Transform target;
public float loadDistance = 200f;
public float preloadBuffer = 75f;
public float unloadBuffer = 50f;
public float treeShadowDistance = 80f;
public bool enableTreeShadows = true;
public int maxSpawnsPerFrame = 32;
public int maxDespawnsPerFrame = 64;
public float frameBudgetMs = 2f;
public float scanInterval = 0.25f;
public float fadeDuration = 0.3f;
private readonly Dictionary<long, List<int>> grid = new Dictionary<long, List<int>>();
private readonly Dictionary<int, Resident> live = new Dictionary<int, Resident>();
private readonly List<Candidate> pending = new List<Candidate>();
private readonly List<int> retiring = new List<int>();
private readonly List<int> finished = new List<int>();
private readonly HashSet<int> fading = new HashSet<int>();
private int pendingCursor;
private int retireCursor;
private float nextScan;
private float nextCameraCheck;
private Transform cachedCamera;
private Transform staging;
private Vector3 previousScan;
private bool ready;
private bool hasScan;
private MaterialPropertyBlock block;
private int fadeId;
public int ResidentCount => live.Count;
public int LastCandidateChecks { get; private set; }
public int LastCellsVisited { get; private set; }
public int PendingSpawns => pending.Count - pendingCursor;
private float LoadRange => Mathf.Max(10f, loadDistance);
private float PreloadRange => LoadRange + Mathf.Max(0f, preloadBuffer);
private float UnloadRange => PreloadRange + Mathf.Max(10f, unloadBuffer);
private static long Key(int x, int z)
{
return ((long)x << 32) ^ (uint)z;
}
public void Initialize()
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Expected O, but got Unknown
if (ready || (Object)(object)catalog == (Object)null || catalog.placements == null || catalog.prefabs == null)
{
return;
}
block = new MaterialPropertyBlock();
fadeId = Shader.PropertyToID("_DRFade");
float num = Mathf.Max(1f, catalog.cellSize);
for (int i = 0; i < catalog.placements.Length; i++)
{
DRSceneryCatalog.Placement placement = catalog.placements[i];
long key = Key(Mathf.FloorToInt(placement.position.x / num), Mathf.FloorToInt(placement.position.z / num));
if (!grid.TryGetValue(key, out var value))
{
value = new List<int>();
grid.Add(key, value);
}
value.Add(i);
}
GameObject val = new GameObject("SceneryStaging");
val.SetActive(false);
val.transform.SetParent(((Component)this).transform, false);
staging = val.transform;
ready = true;
hasScan = false;
}
private Transform Observer()
{
if ((Object)(object)target != (Object)null)
{
return target;
}
if ((Object)(object)GM.CurrentPlayerBody != (Object)null && ((Component)GM.CurrentPlayerBody).gameObject.activeInHierarchy)
{
return ((Component)GM.CurrentPlayerBody).transform;
}
if (Time.unscaledTime >= nextCameraCheck)
{
Camera main = Camera.main;
cachedCamera = ((!((Object)(object)main == (Object)null)) ? ((Component)main).transform : null);
nextCameraCheck = Time.unscaledTime + 0.5f;
}
return cachedCamera;
}
private void Update()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
Transform val = Observer();
if ((Object)(object)val != (Object)null)
{
Step(val.position, Time.unscaledTime, Time.deltaTime);
}
}
private static float Distance2(Vector3 a, Vector3 b)
{
float num = a.x - b.x;
float num2 = a.z - b.z;
return num * num + num2 * num2;
}
public void Step(Vector3 worldObserver, float now, float delta)
{
//IL_001d: 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_0023: 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_006c: 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_003b: 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_0122: 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_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
Initialize();
if (!ready)
{
return;
}
Vector3 val = ((Component)this).transform.InverseTransformPoint(worldObserver);
if (!hasScan || now >= nextScan || Distance2(val, previousScan) >= catalog.cellSize * catalog.cellSize)
{
Query(val);
previousScan = val;
hasScan = true;
nextScan = now + Mathf.Max(0.05f, scanInterval);
}
Stopwatch stopwatch = Stopwatch.StartNew();
int num = 0;
while (pendingCursor < pending.Count && num < Mathf.Max(1, maxSpawnsPerFrame) && (num <= 0 || !(stopwatch.Elapsed.TotalMilliseconds >= (double)Mathf.Max(0.1f, frameBudgetMs))))
{
int id = pending[pendingCursor++].id;
if (!live.ContainsKey(id) && !(Distance2(catalog.placements[id].position, val) > PreloadRange * PreloadRange))
{
Spawn(id, val);
num++;
}
}
int num2 = 0;
while (retireCursor < retiring.Count && num2 < Mathf.Max(1, maxDespawnsPerFrame) && (num2 <= 0 || !(stopwatch.Elapsed.TotalMilliseconds >= (double)Mathf.Max(0.1f, frameBudgetMs))))
{
int num3 = retiring[retireCursor++];
if (!(Distance2(catalog.placements[num3].position, val) <= UnloadRange * UnloadRange) && live.TryGetValue(num3, out var value))
{
value.obj.SetActive(false);
Release((Object)(object)value.obj);
live.Remove(num3);
fading.Remove(num3);
num2++;
}
}
UpdateFades(Mathf.Max(0f, delta));
}
private void Query(Vector3 observer)
{
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: 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_0114: Unknown result type (might be due to invalid IL or missing references)
pending.Clear();
pendingCursor = 0;
retiring.Clear();
retireCursor = 0;
LastCandidateChecks = 0;
LastCellsVisited = 0;
float num = Mathf.Max(1f, catalog.cellSize);
float preloadRange = PreloadRange;
int num2 = Mathf.FloorToInt((observer.x - preloadRange) / num);
int num3 = Mathf.FloorToInt((observer.x + preloadRange) / num);
int num4 = Mathf.FloorToInt((observer.z - preloadRange) / num);
int num5 = Mathf.FloorToInt((observer.z + preloadRange) / num);
for (int i = num2; i <= num3; i++)
{
for (int j = num4; j <= num5; j++)
{
if (!grid.TryGetValue(Key(i, j), out var value))
{
continue;
}
LastCellsVisited++;
foreach (int item in value)
{
LastCandidateChecks++;
float num6 = Distance2(catalog.placements[item].position, observer);
if (num6 <= preloadRange * preloadRange && !live.ContainsKey(item))
{
pending.Add(new Candidate
{
id = item,
distance = num6
});
}
}
}
}
pending.Sort((Candidate a, Candidate b) => a.distance.CompareTo(b.distance));
foreach (KeyValuePair<int, Resident> item2 in live)
{
int key = item2.Key;
Resident value2 = item2.Value;
float num7 = Distance2(catalog.placements[key].position, observer);
if (num7 > UnloadRange * UnloadRange)
{
retiring.Add(key);
continue;
}
float num8 = ((!value2.visible) ? Mathf.Max(0f, LoadRange - 5f) : LoadRange);
bool flag = num7 <= num8 * num8;
if (flag != value2.visible)
{
value2.visible = flag;
fading.Add(key);
}
ApplyShadows(key, value2, num7);
}
}
private void Spawn(int id, Vector3 observer)
{
//IL_00a7: 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_00cb: 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_014e: Expected I4, but got Unknown
//IL_0166: 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)
DRSceneryCatalog.Placement placement = catalog.placements[id];
if (placement.prefab >= 0 && placement.prefab < catalog.prefabs.Length && !((Object)(object)catalog.prefabs[placement.prefab] == (Object)null))
{
GameObject val = Object.Instantiate<GameObject>(catalog.prefabs[placement.prefab], staging, false);
((Object)val).name = ((Object)catalog.prefabs[placement.prefab]).name;
val.transform.localPosition = placement.position;
val.transform.localRotation = placement.rotation;
val.transform.localScale = placement.scale;
Resident resident = new Resident();
resident.obj = val;
resident.renderers = val.GetComponentsInChildren<Renderer>(true);
Resident resident2 = resident;
resident2.enabled = new bool[resident2.renderers.Length];
resident2.shadows = (ShadowCastingMode[])(object)new ShadowCastingMode[resident2.renderers.Length];
for (int i = 0; i < resident2.renderers.Length; i++)
{
resident2.enabled[i] = resident2.renderers[i].enabled;
resident2.shadows[i] = (ShadowCastingMode)(int)resident2.renderers[i].shadowCastingMode;
}
float num = Distance2(placement.position, observer);
resident2.visible = num <= LoadRange * LoadRange;
SetOpacity(resident2, 0f);
ApplyShadows(id, resident2, num);
val.transform.SetParent(((Component)this).transform, false);
live.Add(id, resident2);
if (resident2.visible)
{
fading.Add(id);
}
}
}
private void ApplyShadows(int id, Resident r, float distance2)
{
if (!catalog.placements[id].foliage)
{
return;
}
float num = Mathf.Max(0f, treeShadowDistance - (float)((!r.casts) ? 5 : 0));
bool flag = enableTreeShadows && treeShadowDistance > 0f && distance2 <= num * num;
if (flag != r.casts)
{
r.casts = flag;
for (int i = 0; i < r.renderers.Length; i++)
{
r.renderers[i].shadowCastingMode = (ShadowCastingMode)(flag ? ((int)r.shadows[i]) : 0);
r.renderers[i].enabled = r.enabled[i] && r.opacity > 0f && (flag || (int)r.shadows[i] != 3);
}
}
}
private void SetOpacity(Resident r, float value)
{
r.opacity = value;
for (int i = 0; i < r.renderers.Length; i++)
{
Renderer val = r.renderers[i];
if (!((Object)(object)val == (Object)null))
{
val.enabled = r.enabled[i] && value > 0f && (r.casts || (int)r.shadows[i] != 3);
val.GetPropertyBlock(block);
block.SetFloat(fadeId, value);
val.SetPropertyBlock(block);
block.Clear();
}
}
}
private void UpdateFades(float delta)
{
finished.Clear();
float num = ((!(fadeDuration <= 0f)) ? (delta / fadeDuration) : 1f);
foreach (int item in fading)
{
if (!live.TryGetValue(item, out var value))
{
finished.Add(item);
continue;
}
float num2 = (value.visible ? 1 : 0);
SetOpacity(value, Mathf.MoveTowards(value.opacity, num2, num));
if (value.opacity == num2)
{
finished.Add(item);
}
}
foreach (int item2 in finished)
{
fading.Remove(item2);
}
}
private static void Release(Object obj)
{
if (Application.isPlaying)
{
Object.Destroy(obj);
}
else
{
Object.DestroyImmediate(obj);
}
}
private void OnDisable()
{
ClearResidents();
}
public void ClearResidents()
{
foreach (KeyValuePair<int, Resident> item in live)
{
if ((Object)(object)item.Value.obj != (Object)null)
{
item.Value.obj.SetActive(false);
Release((Object)(object)item.Value.obj);
}
}
live.Clear();
fading.Clear();
pending.Clear();
retiring.Clear();
pendingCursor = (retireCursor = 0);
hasScan = false;
}
private void OnDestroy()
{
if ((Object)(object)staging != (Object)null)
{
Release((Object)(object)((Component)staging).gameObject);
}
}
}
public sealed class DRSpectatorDepthGuard : MonoBehaviour
{
public float nearClip = 0.3f;
private readonly Dictionary<Camera, float> originals = new Dictionary<Camera, float>();
private void OnEnable()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
Camera.onPreCull = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(Before));
Camera.onPostRender = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPostRender, (Delegate?)new CameraCallback(After));
}
private void OnDisable()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
Camera.onPreCull = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(Before));
Camera.onPostRender = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPostRender, (Delegate?)new CameraCallback(After));
foreach (KeyValuePair<Camera, float> original in originals)
{
if ((Object)(object)original.Key != (Object)null)
{
original.Key.nearClipPlane = original.Value;
}
}
originals.Clear();
}
private void Before(Camera camera)
{
FVRSceneSettings currentSceneSettings = GM.CurrentSceneSettings;
if (!((Object)(object)currentSceneSettings == (Object)null))
{
FVRPlayerBody currentPlayerBody = GM.CurrentPlayerBody;
ApplyTo(camera, currentSceneSettings.m_specCam, currentSceneSettings.m_previewCam, (!((Object)(object)currentPlayerBody == (Object)null)) ? currentPlayerBody.EyeCam : null);
}
}
public bool ApplyTo(Camera camera, Camera spectator, Camera preview, Camera eye)
{
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Invalid comparison between Unknown and I4
if (!((Behaviour)this).isActiveAndEnabled || (Object)(object)camera == (Object)null || (Object)(object)camera == (Object)(object)eye || ((Object)(object)camera != (Object)(object)spectator && (Object)(object)camera != (Object)(object)preview) || camera.stereoEnabled || camera.orthographic || (int)camera.cameraType != 1)
{
return false;
}
float num = ((!float.IsNaN(nearClip) && !float.IsInfinity(nearClip)) ? Mathf.Clamp(nearClip, 0.05f, 1f) : 0.3f);
if (camera.nearClipPlane >= num || camera.farClipPlane <= num || originals.ContainsKey(camera))
{
return false;
}
originals.Add(camera, camera.nearClipPlane);
camera.nearClipPlane = num;
return true;
}
public void After(Camera camera)
{
if ((Object)(object)camera != (Object)null && originals.TryGetValue(camera, out var value))
{
camera.nearClipPlane = value;
originals.Remove(camera);
}
}
}
public sealed class DRVegetationDistanceCuller : MonoBehaviour
{
public Transform target;
public bool useMainCameraIfTargetMissing = true;
public float disableDistance = 100f;
public float reenableDistance = 95f;
public float scanInterval = 0.25f;
public int checksPerFrame = 4096;
public bool horizontalDistanceOnly = true;
[Range(0f, 1f)]
public float fadeDuration = 0.3f;
public List<GameObject> instances = new List<GameObject>();
private Vector3[] positions;
private GameObject[] managed;
private bool[] originallyActive;
private bool[] wanted;
private bool[] sampled;
private float[] opacity;
private int cursor;
private float nextScan;
private float nextCameraLookup;
private bool scanning;
private bool ready;
private bool hadObserver;
private Transform cachedCamera;
private readonly Dictionary<int, Renderer[]> fading = new Dictionary<int, Renderer[]>();
private readonly List<int> finished = new List<int>();
private MaterialPropertyBlock propertyBlock;
private static int fadeId;
private static bool fadeIdReady;
private MaterialPropertyBlock block
{
get
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
if (propertyBlock == null)
{
propertyBlock = new MaterialPropertyBlock();
}
return propertyBlock;
}
}
private static int FadeId
{
get
{
if (!fadeIdReady)
{
fadeId = Shader.PropertyToID("_DRFade");
fadeIdReady = true;
}
return fadeId;
}
}
private void OnEnable()
{
ready = false;
}
private void Start()
{
Rebuild();
}
public void Rebuild()
{
//IL_00ae: 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)
Restore();
managed = instances.ToArray();
int num = managed.Length;
positions = (Vector3[])(object)new Vector3[num];
originallyActive = new bool[num];
wanted = new bool[num];
sampled = new bool[num];
opacity = new float[num];
for (int i = 0; i < num; i++)
{
if (!((Object)(object)managed[i] == (Object)null) && !((Object)(object)managed[i] == (Object)(object)((Component)this).gameObject))
{
ref Vector3 reference = ref positions[i];
reference = managed[i].transform.position;
bool[] array = wanted;
int num2 = i;
bool activeSelf;
originallyActive[i] = (activeSelf = managed[i].activeSelf);
array[num2] = activeSelf;
opacity[i] = 1f;
}
}
cursor = 0;
nextScan = 0f;
scanning = false;
ready = true;
}
private void SetOpacity(Renderer[] renderers, float value)
{
foreach (Renderer val in renderers)
{
if (!((Object)(object)val == (Object)null))
{
val.GetPropertyBlock(block);
block.SetFloat(FadeId, value);
val.SetPropertyBlock(block);
block.Clear();
}
}
}
private void Request(int index, bool active)
{
if (wanted[index] != active)
{
wanted[index] = active;
GameObject val = managed[index];
if (!fading.TryGetValue(index, out var value))
{
value = val.GetComponentsInChildren<Renderer>(true);
fading.Add(index, value);
}
if (active)
{
SetOpacity(value, opacity[index]);
val.SetActive(true);
}
}
}
private void UpdateFades()
{
finished.Clear();
float num = ((!(fadeDuration <= 0f)) ? (Time.deltaTime / fadeDuration) : 1f);
foreach (KeyValuePair<int, Renderer[]> item in fading)
{
int key = item.Key;
if ((Object)(object)managed[key] == (Object)null)
{
finished.Add(key);
continue;
}
float num2 = ((!wanted[key]) ? 0f : 1f);
opacity[key] = Mathf.MoveTowards(opacity[key], num2, num);
SetOpacity(item.Value, opacity[key]);
if (opacity[key] == num2)
{
if (!wanted[key])
{
managed[key].SetActive(false);
}
finished.Add(key);
}
}
foreach (int item2 in finished)
{
fading.Remove(item2);
}
}
private void Update()
{
//IL_012c: 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_019f: 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_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)
if (!ready || managed.Length != instances.Count)
{
Rebuild();
}
Transform val = target;
if ((Object)(object)val == (Object)null && useMainCameraIfTargetMissing)
{
if (Time.unscaledTime >= nextCameraLookup)
{
Camera main = Camera.main;
cachedCamera = ((!((Object)(object)main == (Object)null)) ? ((Component)main).transform : null);
nextCameraLookup = Time.unscaledTime + 0.5f;
}
val = cachedCamera;
}
if ((Object)(object)val == (Object)null)
{
if (hadObserver)
{
Restore();
ready = false;
}
hadObserver = false;
return;
}
hadObserver = true;
UpdateFades();
if (!scanning)
{
if (Time.unscaledTime < nextScan)
{
return;
}
scanning = true;
cursor = 0;
}
float num = Mathf.Max(1f, disableDistance);
float num2 = Mathf.Clamp(reenableDistance, 0f, num);
Vector3 position = val.position;
for (int num3 = Mathf.Min(managed.Length, cursor + Mathf.Max(1, checksPerFrame)); cursor < num3; cursor++)
{
GameObject val2 = managed[cursor];
if ((Object)(object)val2 == (Object)null || !originallyActive[cursor])
{
continue;
}
Vector3 val3 = positions[cursor] - position;
if (horizontalDistanceOnly)
{
val3.y = 0f;
}
float num4 = ((!wanted[cursor]) ? num2 : num);
bool flag = ((Vector3)(ref val3)).sqrMagnitude <= num4 * num4;
if (!sampled[cursor])
{
sampled[cursor] = true;
if (!flag)
{
wanted[cursor] = false;
opacity[cursor] = 0f;
val2.SetActive(false);
continue;
}
}
Request(cursor, flag);
}
if (cursor == managed.Length)
{
scanning = false;
nextScan = Time.unscaledTime + Mathf.Max(0f, scanInterval);
}
}
private void Restore()
{
if (managed == null)
{
return;
}
foreach (KeyValuePair<int, Renderer[]> item in fading)
{
SetOpacity(item.Value, 1f);
}
for (int i = 0; i < managed.Length; i++)
{
if (!((Object)(object)managed[i] == (Object)null) && !((Object)(object)managed[i] == (Object)(object)((Component)this).gameObject))
{
if (sampled[i] && opacity[i] < 1f)
{
SetOpacity(managed[i].GetComponentsInChildren<Renderer>(true), 1f);
}
managed[i].SetActive(originallyActive[i]);
}
}
fading.Clear();
}
private void OnDisable()
{
Restore();
ready = false;
}
}
}