using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyCompany("CubemapMaker")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Create 360 Cubemaps from within Unity games")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+94cb7304d9a75b6f165e36fd69ddc94d5a6b0341")]
[assembly: AssemblyProduct("CubemapMaker")]
[assembly: AssemblyTitle("CubemapMaker")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace CubemapMaker
{
[BepInPlugin("CubemapMaker", "CubemapMaker", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
internal static Harmony harmony;
internal static ConfigFile config;
internal static ConfigEntry<string> configCaptureKeybind;
internal static ConfigEntry<string> configTransCaptureKeybind;
internal static ConfigEntry<string> configOutputPath;
internal static ConfigEntry<string> configCaptureOrientation;
internal static ConfigEntry<bool> configCaptureUI;
internal static ConfigEntry<int> configOutputWidth;
internal static Camera renderCam;
private void Awake()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading Plugin CubemapMaker...");
Log = ((BaseUnityPlugin)this).Logger;
Log.LogInfo((object)"Created Global Logger");
harmony = new Harmony("CubemapMaker");
harmony.PatchAll();
Log.LogInfo((object)"Applied All Patches");
SetupConfig();
Log.LogInfo((object)"Plugin CubemapMaker is loaded!");
}
private void OnDestroy()
{
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
}
private void SetupConfig()
{
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Expected O, but got Unknown
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Expected O, but got Unknown
string text = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\CubemapMaker";
string text2 = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Cubemaps";
Directory.CreateDirectory(text);
if (!File.Exists(Path.Combine(text, "config.cfg")) && Directory.Exists(Path.Combine(Application.dataPath, "..\\..\\ULTRAKILL")))
{
text2 = Path.GetFullPath(Path.Combine(Application.dataPath, "..\\..\\ULTRAKILL\\Cybergrind\\Textures\\Skyboxes\\Captured"));
Log.LogInfo((object)"Found ULTRAKILL Install! Set the capture output to the Cybergrind directory");
}
config = new ConfigFile(Path.Combine(text, "config.cfg"), true);
configOutputPath = config.Bind<string>("General", "OutputPath", text2, "The path that cubemaps will be outputed to");
configOutputWidth = config.Bind<int>("General", "OutputWidth", 4096, "The width of the outputed cubemap");
configCaptureUI = config.Bind<bool>("General", "CaptureUI", true, "Whether to capture UI in a cubemap or not");
configCaptureOrientation = config.Bind<string>("General", "CaptureOrientation", "Yaw", new ConfigDescription("The orientation used to capture the cubemap in\nYaw: This will capture the cubemap in the direction your facing but will keep the world upright\nAccurate: This will accuratly capture rotation in the cubemap, so whereever you are looking will be the forward position\nNone: This won't take the camera's orientation into account at all", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Yaw", "Accurate", "None" }), Array.Empty<object>()));
configCaptureKeybind = config.Bind<string>("General.Keybinds", "CaptureButton", "f10", "The key used to capture a cubemap");
configTransCaptureKeybind = config.Bind<string>("General.Keybinds", "TransparentCaptureButton", "f11", "The key used to capture a cubemap with a transparent skybox");
text2 = configOutputPath.Value;
Directory.CreateDirectory(text2);
Log.LogInfo((object)"Loaded Config");
}
private void CaptureCubemap(bool transparent, bool cgSecondPlayer = false)
{
//IL_003a: 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_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Expected O, but got Unknown
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Expected O, but got Unknown
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Expected O, but got Unknown
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: 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_029b: 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_01cf: Unknown result type (might be due to invalid IL or missing references)
//IL_0327: Unknown result type (might be due to invalid IL or missing references)
if (renderCam == null)
{
renderCam = ((Component)this).gameObject.AddComponent<Camera>();
}
renderCam.CopyFrom(Camera.main);
((Component)renderCam).transform.rotation = ((Component)Camera.main).transform.rotation;
((Component)renderCam).transform.position = ((Component)Camera.main).transform.position;
if (transparent)
{
Log.LogInfo((object)"Capturing Transparent Cubemap");
}
else
{
Log.LogInfo((object)"Capturing Cubemap");
}
if (cgSecondPlayer)
{
if (SceneHelper.CurrentScene != "Endless")
{
cgSecondPlayer = false;
Log.LogWarning((object)"Tried capturing a CG Second Player cubemap outside of the cyber grind. Capturing normal cubemap instead");
}
else if (Application.productName != "ULTRAKILL")
{
cgSecondPlayer = false;
Log.LogWarning((object)"Tried capturing a CG Second Player cubemap in a game that isn't ULTRAKILL. Capturing normal cubemap instead");
}
else
{
Log.LogInfo((object)"Capturing CG Second Player Cubemap");
}
}
string path = $"{Application.productName} {DateTime.Now:yyyy-MM-dd HH-mm-ss}.png";
string fullPath = Path.GetFullPath(Path.Combine(configOutputPath.Value, path));
RenderTexture val = new RenderTexture(configOutputWidth.Value, configOutputWidth.Value, 32);
RenderTexture val2 = new RenderTexture(((Texture)val).width, (int)((float)((Texture)val).width * 0.5f), 32);
Texture2D val3 = new Texture2D(((Texture)val2).width, ((Texture)val2).height);
if (!cgSecondPlayer)
{
string text = configCaptureOrientation.Value.ToLower();
if (!(text == "none"))
{
if (!(text == "accurate"))
{
((Component)renderCam).transform.eulerAngles = new Vector3(0f, ((Component)renderCam).transform.eulerAngles.y, 0f);
}
}
else
{
((Component)renderCam).transform.eulerAngles = Vector3.zero;
}
}
else
{
((Component)renderCam).transform.eulerAngles = Vector3.zero;
((Component)renderCam).transform.position = new Vector3(500f, 30f, 50f);
}
if (transparent)
{
renderCam.clearFlags = (CameraClearFlags)2;
renderCam.backgroundColor = Color.clear;
}
Dictionary<Canvas, bool> dictionary = new Dictionary<Canvas, bool>();
if (!configCaptureUI.Value)
{
Canvas[] array = Object.FindObjectsOfType<Canvas>();
foreach (Canvas val4 in array)
{
dictionary.Add(val4, ((Behaviour)val4).enabled);
((Behaviour)val4).enabled = false;
}
}
((Texture)val).dimension = (TextureDimension)4;
((Component)renderCam).transform.Rotate(new Vector3(0f, 90f, 0f));
renderCam.RenderToCubemap(val, 63);
val.ConvertToEquirect(val2, (MonoOrStereoscopicEye)2);
if (!configCaptureUI.Value)
{
foreach (KeyValuePair<Canvas, bool> item in dictionary)
{
((Behaviour)item.Key).enabled = item.Value;
}
}
RenderTexture.active = val2;
val3.ReadPixels(new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), 0, 0);
RenderTexture.active = null;
Directory.CreateDirectory(configOutputPath.Value);
File.WriteAllBytes(fullPath, ImageConversion.EncodeToPNG(val3));
Log.LogInfo((object)("Captured cubemap to \"" + fullPath + "\""));
}
private void Update()
{
if (Input.GetKeyDown(configCaptureKeybind.Value.ToLower()))
{
CaptureCubemap(transparent: false, Input.GetKey((KeyCode)304));
}
if (Input.GetKeyDown(configTransCaptureKeybind.Value.ToLower()))
{
CaptureCubemap(transparent: true, Input.GetKey((KeyCode)304));
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "CubemapMaker";
public const string PLUGIN_NAME = "CubemapMaker";
public const string PLUGIN_VERSION = "1.0.0";
}
}