using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Threading; using BepInEx; using HarmonyLib; using Newtonsoft.Json; using TMPro; using ULTRAKILL.Portal; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.AddressableAssets.Initialization; using UnityEngine.Events; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.SceneManagement; using UnityEngine.UI; using VolumetricSkyboxes.Assets; using VolumetricSkyboxes.Collections; using VolumetricSkyboxes.Components; using VolumetricSkyboxes.Models; using VolumetricSkyboxes.UI; using VolumetricSkyboxes.Utils; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("0.0.0.0")] namespace VolumetricSkyboxes { public class VolumetricSkyboxContainer : IDisposable { public readonly GameObject SkyboxGameObject; public readonly VolumetricSkyboxData Data; private readonly AsyncOperationHandle _dataHandle; private readonly AsyncOperationHandle _gameObjectHandle; public static VolumetricSkyboxContainer FromGuid(string guid) { string text = Path.Combine(PathsUtils.UnpackedSkyboxesPath, guid); string path = Path.Combine(text, "data.json"); string text2 = Path.Combine(text, "catalog.json"); if (!Directory.Exists(text) || !File.Exists(path) || !File.Exists(text2)) { Debug.LogWarning((object)("Can't locate unpacked skybox [guid=" + guid + "]")); return null; } return new VolumetricSkyboxContainer(JsonConvert.DeserializeObject(File.ReadAllText(path)), text2); } private VolumetricSkyboxContainer(VolumetricSkyboxBundleData data, string catalogPath) { //IL_0009: 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_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_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) Addressables.LoadContentCatalogAsync(catalogPath, false, (string)null).WaitForCompletion(); _dataHandle = Addressables.LoadAssetAsync((object)data.dataPath); _gameObjectHandle = Addressables.LoadAssetAsync((object)data.prefabPath); Data = _dataHandle.WaitForCompletion(); SkyboxGameObject = _gameObjectHandle.WaitForCompletion(); } public void Dispose() { //IL_0001: 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) Addressables.Release(_dataHandle); Addressables.Release(_gameObjectHandle); } } [BepInProcess("ULTRAKILL.exe")] [BepInPlugin("dev.flazhik.volumetric-skyboxes", "Volumetric Skyboxes", "1.0.0")] public class VolumetricSkyboxesPlugin : BaseUnityPlugin { [AddressableAsset("Assets/VolumetricSkyboxes/Bootstrap.prefab", typeof(GameObject))] private static GameObject _bootstrap; private static readonly string CatalogDir; private static Harmony _harmony; private static bool _init; static VolumetricSkyboxesPlugin() { AssemblyUtils.LoadAssembly("VolumetricSkyboxesScripts.dll"); CatalogDir = Path.Combine(PathsUtils.AssemblyPath, "Assets"); } private void Awake() { //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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; SetAddressableProperties(); Addressables.InitializeAsync().WaitForCompletion(); Addressables.LoadContentCatalogAsync(Path.Combine(CatalogDir, "catalog.json"), true, (string)null).WaitForCompletion(); _harmony = new Harmony("dev.flazhik.volumetric-skyboxes"); Startup(); } private void Startup() { _harmony.PatchAll(); SceneManager.sceneLoaded += OnSceneLoaded; } private void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode) { //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) if (scene != SceneManager.GetActiveScene()) { return; } string currentScene = SceneHelper.CurrentScene; if (!(currentScene == "Main Menu")) { if (currentScene == "Endless") { Object.Instantiate(_bootstrap); } } else if (!_init) { PrepareFileSystem(); MonoSingleton.Instance.RegisterPrefabs(Assembly.GetExecutingAssembly()); VolumetricSkyboxesManager instance = MonoSingleton.Instance; instance.ReloadSkyboxes(); instance.ClearCache(); _init = true; } } private static void PrepareFileSystem() { string[] array = new string[3] { PathsUtils.SkyboxesPath, PathsUtils.DataPath, PathsUtils.UnpackedSkyboxesPath }; foreach (string path in array) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } } string text = Path.Combine(PathsUtils.AssemblyPath, "Skyboxes"); if (Directory.Exists(text)) { array = Directory.GetDirectories(text, "*", SearchOption.AllDirectories); for (int i = 0; i < array.Length; i++) { Directory.CreateDirectory(array[i].Replace(text, PathsUtils.SkyboxesPath)); } array = Directory.GetFiles(text, "*.*", SearchOption.AllDirectories); foreach (string obj in array) { File.Copy(obj, obj.Replace(text, PathsUtils.SkyboxesPath), overwrite: true); } Directory.Delete(text, recursive: true); } } private void SetAddressableProperties() { AddressablesRuntimeProperties.SetPropertyValue("UnpackedVolumetricSkyboxesPath", PathsUtils.UnpackedSkyboxesPath); AddressablesRuntimeProperties.SetPropertyValue("VolumetricSkyboxesRuntimePath", PathsUtils.AssemblyPath); AddressablesRuntimeProperties.SetPropertyValue("VolumetricSkyboxesAssetsPath", CatalogDir); } } internal static class PluginInfo { public const string Guid = "dev.flazhik.volumetric-skyboxes"; public const string Name = "Volumetric Skyboxes"; public const string Version = "1.0.0"; } } namespace VolumetricSkyboxes.Utils { public static class AssemblyUtils { public static void LoadAssembly(string scriptName) { Assembly.Load(File.ReadAllBytes(Path.Combine(PathsUtils.AssemblyPath, scriptName))); } } public static class ReflectionUtils { private const BindingFlags PrivateFields = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; public static T GetPrivate(this object instance, string field) { FieldInfo field2 = instance.GetType().GetField(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); return (T)((field2 != null) ? field2.GetValue(instance) : null); } public static T GetPrivateProperty(this object instance, string field) { PropertyInfo property = instance.GetType().GetProperty(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); return (T)((property != null) ? property.GetValue(instance) : null); } public static void SetPrivate(this object instance, string field, TV value) { FieldInfo field2 = instance.GetType().GetField(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetField); if (field2 != null) { field2.SetValue(instance, value); } } } public static class SkyboxFileUtility { public static VolumetricSkyboxBundleData UnpackSkybox(string path, bool forced = false) { //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown FileInfo path2 = new FileInfo(path); if (!File.Exists(path) || !PathsUtils.HasValidExtenstion(path2)) { return null; } VolumetricSkyboxBundleData bundleData = GetBundleData(path); if (bundleData == null || bundleData.guid == null) { return null; } string text = Path.Combine(PathsUtils.UnpackedSkyboxesPath, bundleData.guid); bool flag = Directory.Exists(text); bool num = flag && File.Exists(Path.Combine(text, "data.json")) && File.Exists(Path.Combine(text, "catalog.json")); bool flag2 = true; if (num) { VolumetricSkyboxBundleData val = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(text, "data.json"))); if (val.guid != null && val.buildHash == bundleData.buildHash && !forced) { flag2 = false; } } if (!flag2) { return bundleData; } try { if (flag) { Directory.Delete(text, recursive: true); } Directory.CreateDirectory(text); ZipArchive val2 = new ZipArchive((Stream)File.Open(path, FileMode.Open, FileAccess.Read)); try { val2.ExtractToDirectory(text); return bundleData; } finally { ((IDisposable)val2)?.Dispose(); } } catch (Exception ex) { Debug.LogError((object)("Error unpacking skybox guid=[" + bundleData.guid + "]")); Debug.LogException(ex); return null; } } private static VolumetricSkyboxBundleData GetBundleData(string path) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown using FileStream fileStream = File.Open(path, FileMode.Open, FileAccess.Read); ZipArchive val = new ZipArchive((Stream)fileStream); try { ZipArchiveEntry entry = val.GetEntry("data.json"); if (entry == null) { return null; } using StreamReader streamReader = new StreamReader(entry.Open()); return JsonConvert.DeserializeObject(streamReader.ReadToEnd()); } finally { ((IDisposable)val)?.Dispose(); } } } public static class RenderingUtils { public static readonly int SandboxGrabbableLayer = LayerMask.NameToLayer("SandboxGrabbable"); public static readonly int SpecialLightingLayer = LayerMask.NameToLayer("SpecialLighting"); public static readonly int SandboxGrabbableMask = 1 << SandboxGrabbableLayer; public static readonly int SpecialLightingLayerMask = 1 << SpecialLightingLayer; public static readonly int BackgroundLayersMask = SandboxGrabbableMask | SpecialLightingLayerMask; } public static class PathsUtils { public const string SkyboxExtension = ".cgvsb"; private static readonly string AppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); public static readonly string ApplicationPath = Path.Combine(Directory.GetParent(Application.dataPath)?.FullName); public static readonly string SkyboxesPath = Path.Combine(ApplicationPath, "Cybergrind", "VolumetricSkyboxes"); public static readonly string PreferencesPath = Path.Combine(ApplicationPath, "Preferences"); public static readonly string AssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); public static readonly string DataPath = Path.Combine(AppData, "VolumetricSkyboxes"); public static readonly string UnpackedSkyboxesPath = Path.Combine(DataPath, "Unpacked"); public static bool HasValidExtenstion(FileInfo path) { return ".cgvsb".Equals(path.Extension.ToLower()); } } } namespace VolumetricSkyboxes.UI { [RequireComponent(typeof(Button))] public class ControllerPointerToggle : MonoBehaviour { [Serializable] public class ToggleEvent : UnityEvent { } [SerializeField] public Image onImage; public ToggleEvent onValueChanged = new ToggleEvent(); [SerializeField] private bool m_IsOn; private Button _button; public bool isOn { get { return m_IsOn; } set { m_IsOn = value; ((UnityEvent)onValueChanged).Invoke(m_IsOn); } } private void Awake() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown _button = ((Component)this).GetComponent