using System;
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 DarkMachine.UI;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("wk.barackobusiness.wideangle")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.0.1.0")]
[assembly: AssemblyInformationalVersion("2.0.1+958284acd913e4486f7cd62df3521052b3fc9997")]
[assembly: AssemblyProduct("Wide Angle Camera")]
[assembly: AssemblyTitle("wk.barackobusiness.wideangle")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.1.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 WideAngleCamera
{
public class CameraManager : MonoBehaviour
{
public static CameraManager Instance;
private Camera front;
private Camera back;
private Camera right;
private Camera left;
private Camera up;
private Camera down;
private RenderTexture cubemap;
private Material screen;
private float curFOV;
private float sprintFOV;
private float smoothedFOV;
private ENT_Player player;
private FieldInfo sliding;
internal void Init(MeshRenderer projector, bool useBack, int size)
{
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Expected O, but got Unknown
Instance = this;
curFOV = SettingsManager.settings.playerFOV;
sprintFOV = curFOV + 15f;
smoothedFOV = curFOV;
player = ENT_Player.GetPlayer();
sliding = typeof(ENT_Player).GetField("isSliding", BindingFlags.Instance | BindingFlags.NonPublic);
front = ((Component)((Component)this).transform.GetChild(0)).GetComponent<Camera>();
SetupCam(front, Camera.main, size);
left = ((Component)((Component)this).transform.GetChild(1)).GetComponent<Camera>();
SetupCam(left, Camera.main, size);
right = ((Component)((Component)this).transform.GetChild(2)).GetComponent<Camera>();
SetupCam(right, Camera.main, size);
down = ((Component)((Component)this).transform.GetChild(3)).GetComponent<Camera>();
SetupCam(down, Camera.main, size);
up = ((Component)((Component)this).transform.GetChild(4)).GetComponent<Camera>();
SetupCam(up, Camera.main, size);
if (useBack)
{
GameObject gameObject = ((Component)((Component)this).transform.GetChild(5)).gameObject;
gameObject.SetActive(true);
back = gameObject.GetComponent<Camera>();
SetupCam(back, Camera.main, size);
}
cubemap = new RenderTexture(size, size, 16);
((Texture)cubemap).dimension = (TextureDimension)4;
screen = ((Renderer)projector).material;
screen.mainTexture = (Texture)(object)cubemap;
SetFOV(curFOV);
}
private void Update()
{
if ((Object)(object)screen == (Object)null)
{
return;
}
Graphics.CopyTexture((Texture)(object)front.targetTexture, 0, (Texture)(object)cubemap, 4);
if ((Object)(object)back != (Object)null)
{
Graphics.CopyTexture((Texture)(object)back.targetTexture, 0, (Texture)(object)cubemap, 5);
}
Graphics.CopyTexture((Texture)(object)right.targetTexture, 0, (Texture)(object)cubemap, 0);
Graphics.CopyTexture((Texture)(object)left.targetTexture, 0, (Texture)(object)cubemap, 1);
Graphics.CopyTexture((Texture)(object)up.targetTexture, 0, (Texture)(object)cubemap, 3);
Graphics.CopyTexture((Texture)(object)down.targetTexture, 0, (Texture)(object)cubemap, 2);
if (!player.IsLocked())
{
curFOV = Mathf.Clamp(curFOV + player.curBuffs.GetBuff("addFOV"), 60f, 315f);
smoothedFOV = Math.ExpDecay(smoothedFOV, curFOV, 5f, Time.deltaTime);
curFOV = SettingsManager.settings.playerFOV;
sprintFOV = curFOV + 15f;
SetFOV(smoothedFOV);
}
if (!player.IsMoveLocked() && !CommandConsole.IsConsoleVisible())
{
bool flag = (bool)sliding.GetValue(player);
if (player.IsSprinting() && player.IsGrounded(false) && !flag)
{
curFOV = sprintFOV;
}
}
}
private void OnDestroy()
{
cubemap.Release();
}
private void SetupCam(Camera cam, Camera orig, int size)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Expected O, but got Unknown
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
RenderTexture targetTexture = new RenderTexture(size, size, 16);
cam.targetTexture = targetTexture;
cam.depth = orig.depth;
cam.clearFlags = orig.clearFlags;
cam.cullingMask = orig.cullingMask;
cam.depthTextureMode = (DepthTextureMode)1;
}
public float GetFOV()
{
return screen.GetFloat("_FOV");
}
public void SetFOV(float fov)
{
screen.SetFloat("_FOV", fov);
}
}
[BepInPlugin("wk.barackobusiness.wideangle", "Wide Angle Camera", "2.0.1")]
public class WideAnglePlugin : BaseUnityPlugin
{
private enum Quality
{
VeryLow = 0x100,
Low = 0x200,
Normal = 0x400,
Extreme = 0x800
}
private enum Projection
{
Stereographic,
Panini
}
private ConfigEntry<Quality> quality;
private ConfigEntry<bool> renderBackface;
private ConfigEntry<Projection> projection;
private GameObject wideAngleCamera;
private Shader wideAngleShader;
private Harmony patcher;
private void Awake()
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Expected O, but got Unknown
quality = ((BaseUnityPlugin)this).Config.Bind<Quality>("General", "Cubemap Resolution", Quality.Low, "The default side length of a face on the cubemap. This setting controls quality and performance.");
renderBackface = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable backface", false, "Whether to render behind the player or not. Incurs additional performance cost and is only useful for extreme fields of view which make gameplay impractical.");
projection = ((BaseUnityPlugin)this).Config.Bind<Projection>("Projection Configuration", "Projection Technique", Projection.Stereographic, "The technique used to project the environment onto your screen. Stereographic projects from a sphere onto your view. Panini projects from a cylinder onto your view.");
if (LoadAssetBundle())
{
SceneManager.sceneLoaded += OnSceneLoaded;
patcher = new Harmony("wk.barackobusiness.wideangle");
patcher.PatchAll(typeof(UT_CameraTakeoverPatches));
((BaseUnityPlugin)this).Logger.LogInfo((object)"Wide angle views are NOW possible");
}
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
if (!(((Scene)(ref scene)).name == "Intro"))
{
if (((Scene)(ref scene)).name == "Main-Menu")
{
GameObject.Find("Canvas - Screens/Screens/Canvas - Screen - Settings/Settings Menu/SettingsParent/Settings Pane/Video Settings/Options Tab/Video/SliderAsset - FOV/Slider").GetComponent<SubmitSlider>().maxValue = 270f;
return;
}
((Component)GameObject.Find("Pause").transform.GetChild(0).GetChild(3).GetChild(0)
.GetChild(0)
.GetChild(4)
.GetChild(1)
.GetChild(0)
.GetChild(7)
.GetChild(1)).GetComponent<SubmitSlider>().maxValue = 270f;
Transform transform = ((Component)Camera.main).transform;
GameObject val = SetupProjector();
((Renderer)val.GetComponent<MeshRenderer>()).material = new Material(wideAngleShader);
val.transform.localPosition = new Vector3(0f, 0f, 0.5f);
val.transform.SetParent(transform, false);
val.layer = 31;
GameObject obj = Object.Instantiate<GameObject>(wideAngleCamera, transform, false);
((Object)obj).name = "Wide Angle Camera";
obj.AddComponent<CameraManager>().Init(val.GetComponent<MeshRenderer>(), renderBackface.Value, (int)quality.Value);
Camera.main.nearClipPlane = 0f;
Camera.main.farClipPlane = 1f;
Camera.main.cullingMask = int.MinValue;
Camera.main.orthographic = true;
Camera.main.orthographicSize = 0.75f;
Camera.main.useOcclusionCulling = false;
Camera.main.clearFlags = (CameraClearFlags)4;
}
}
private GameObject SetupProjector()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_0029: 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_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_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_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Expected O, but got Unknown
Mesh val = new Mesh();
((Object)val).name = "Triangle";
val.vertices = (Vector3[])(object)new Vector3[3]
{
new Vector3(-1f, -1f, 0f),
new Vector3(3f, -1f, 0f),
new Vector3(-1f, 3f, 0f)
};
val.uv = (Vector2[])(object)new Vector2[3]
{
new Vector2(0f, 0f),
new Vector2(2f, 0f),
new Vector2(0f, 2f)
};
val.triangles = new int[3] { 2, 1, 0 };
val.RecalculateBounds();
GameObject val2 = new GameObject("Projector Screen");
MeshFilter val3 = val2.AddComponent<MeshFilter>();
MeshRenderer obj = val2.AddComponent<MeshRenderer>();
((Renderer)obj).receiveShadows = false;
((Renderer)obj).lightProbeUsage = (LightProbeUsage)0;
((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)obj).motionVectorGenerationMode = (MotionVectorGenerationMode)2;
((Renderer)obj).reflectionProbeUsage = (ReflectionProbeUsage)0;
val3.sharedMesh = val;
return val2;
}
private bool LoadAssetBundle()
{
AssetBundle val = AssetBundle.LoadFromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\WideAngleAssets");
if ((Object)(object)val == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Wide angle views are NOT possible, please ensure the asset bundle is present in the same folder as the plugin");
return false;
}
wideAngleCamera = val.LoadAsset<GameObject>("Wide Angle Camera");
Shader[] array = val.LoadAllAssets<Shader>();
foreach (Shader val2 in array)
{
if (((Object)val2).name == "Custom/" + projection.Value)
{
wideAngleShader = val2;
}
}
if ((Object)(object)wideAngleCamera == (Object)null || (Object)(object)wideAngleShader == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Wide angle views are NOT possible, please reacquire the asset bundle from https://github.com/BarackOBusiness/WKWideAngleCamera");
}
Object.DontDestroyOnLoad((Object)(object)wideAngleCamera);
Object.DontDestroyOnLoad((Object)(object)wideAngleShader);
return true;
}
}
public static class Math
{
public static float ExpDecay(float a, float b, float decay, float dt)
{
return b + (a - b) * Mathf.Exp((0f - decay) * dt);
}
}
public static class UT_CameraTakeoverPatches
{
[HarmonyPatch(typeof(UT_CameraTakeover), "Start")]
[HarmonyPostfix]
public static void Postfix_Start(UT_CameraTakeover __instance)
{
__instance.fov = 90f * Camera.main.aspect;
}
[HarmonyPatch(typeof(UT_CameraTakeover), "Update")]
[HarmonyPostfix]
public static void Postfix_Update(UT_CameraTakeover __instance, ref bool ___active)
{
CameraManager instance = CameraManager.Instance;
if (___active)
{
instance.SetFOV(Math.ExpDecay(instance.GetFOV(), __instance.fov, __instance.speed, Time.deltaTime));
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "wk.barackobusiness.wideangle";
public const string PLUGIN_NAME = "Wide Angle Camera";
public const string PLUGIN_VERSION = "2.0.1";
}
}