using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using FreeLookCamera.Managers; using FreeLookCamera.Settings; using FreeLookCamera.Utilities; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("FreeLookCamera")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+6e4df0c0aa30f61de02a01f931b425faaca8f085")] [assembly: AssemblyProduct("FreeLookCamera")] [assembly: AssemblyTitle("FreeLookCamera")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [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; } } } internal sealed class ConfigurationManagerAttributes { public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput); public bool? ShowRangeAsPercent; public Action CustomDrawer = null; public CustomHotkeyDrawerFunc CustomHotkeyDrawer = null; public bool? Browsable; public string Category; public object DefaultValue; public bool? HideDefaultButton; public bool? HideSettingName; public string Description; public string DispName; public int? Order; public bool? ReadOnly; public bool? IsAdvanced; public Func ObjToStr; public Func StrToObj; } namespace FreeLookCamera { [BepInPlugin("com.kydl.freelookCamera", "FreeLook Camera", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string ModGuid = "com.kydl.freelookCamera"; public const string ModName = "FreeLook Camera"; public const string ModVersion = "1.0.0"; private void Awake() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown Log.Initialize(((BaseUnityPlugin)this).Logger); ConfigManager.Initialize(((BaseUnityPlugin)this).Config); ((BaseUnityPlugin)this).Logger.LogInfo((object)"FreeLook Camera loaded!"); Log.Info("FreeLook Camera: Unity logging works!"); Harmony val = new Harmony("com.kydl.freelookCamera"); val.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"FreeLook Camera :Harmony patches applied."); } } } namespace FreeLookCamera.Utilities { public static class Log { public static ManualLogSource Logger { get; private set; } public static void Initialize(ManualLogSource logger) { Logger = logger; } public static void Info(string message) { Logger.LogInfo((object)message); } public static void Warning(string message) { Logger.LogWarning((object)message); } public static void Error(string message) { Logger.LogError((object)message); } public static void Debug(string message) { Logger.LogDebug((object)message); } } } namespace FreeLookCamera.Settings { public enum ActivationMode { Hold, Toggle } public enum FreeLookMode { Normal, FreeLook, Returning } public enum ReturnMode { Snap, Smooth } } namespace FreeLookCamera.Patches { [HarmonyPatch(typeof(GameCamera), "GetCameraPosition")] public static class GameCameraPatch { private static void Postfix(ref Quaternion rot) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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) if (FreeLookState.HasOffset) { float num = (ConfigManager.EnablePitch.Value ? FreeLookState.PitchOffset : 0f); rot *= Quaternion.Euler(num, FreeLookState.YawOffset, 0f); } } } [HarmonyPatch(typeof(Player), "SetMouseLook")] public static class MouseLookPatch { private static bool _loggedPlayerInfo; private static bool Prefix(Player __instance) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_0070: Unknown result type (might be due to invalid IL or missing references) bool key = Input.GetKey(ConfigManager.FreeLookKey.Value); if (FreeLookState.Active) { if (!_loggedPlayerInfo) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { Log.Info($"Player position: {((Component)localPlayer).transform.position}"); Quaternion rotation = ((Character)localPlayer).m_eye.rotation; Log.Info($"Eye rotation: {((Quaternion)(ref rotation)).eulerAngles}"); } _loggedPlayerInfo = true; } } else { _loggedPlayerInfo = false; } return !key; } private static void Reset() { if (ConfigManager.ResetSettings.Value) { ConfigManager.ResetAllSettings(); ConfigManager.ResetSettings.Value = false; Log.Info("FreeLook: Settings were reset to default."); } } private static void ActivationType(bool keyDown) { switch (ConfigManager.ActivationMode.Value) { case ActivationMode.Hold: { bool active = FreeLookState.Active; FreeLookState.Active = keyDown; if (active != FreeLookState.Active) { Log.Info("FreeLook: " + (FreeLookState.Active ? "Enabled." : "Disabled.")); } FreeLookState.Active = keyDown; break; } case ActivationMode.Toggle: if (keyDown && !FreeLookState.PreviousKeyState) { FreeLookState.Active = !FreeLookState.Active; Log.Info("FreeLook: " + (FreeLookState.Active ? "Enabled!" : "Disabled!")); if (FreeLookState.Active) { FreeLookState.YawVelocity = 0f; FreeLookState.PitchVelocity = 0f; } } break; } } private static void ComebackMode() { switch (ConfigManager.ReturnMode.Value) { case ReturnMode.Snap: FreeLookState.YawOffset = 0f; FreeLookState.PitchOffset = 0f; break; case ReturnMode.Smooth: FreeLookState.YawOffset = Mathf.SmoothDampAngle(FreeLookState.YawOffset, 0f, ref FreeLookState.YawVelocity, ConfigManager.ReturnSmoothTime.Value); if (Mathf.Abs(FreeLookState.YawOffset) < 0.01f) { FreeLookState.YawOffset = 0f; FreeLookState.YawVelocity = 0f; } FreeLookState.PitchOffset = Mathf.SmoothDampAngle(FreeLookState.PitchOffset, 0f, ref FreeLookState.PitchVelocity, ConfigManager.ReturnSmoothTime.Value); if (Mathf.Abs(FreeLookState.PitchOffset) < 0.01f) { FreeLookState.PitchOffset = 0f; FreeLookState.PitchVelocity = 0f; } break; } } private static bool Prefix(Vector2 mouseLook) { //IL_0006: 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_008d: Unknown result type (might be due to invalid IL or missing references) bool key = Input.GetKey(ConfigManager.FreeLookKey.Value); Reset(); ActivationType(key); if (ConfigManager.ActivationMode.Value == ActivationMode.Hold && key && !FreeLookState.PreviousKeyState) { FreeLookState.YawOffset = 0f; FreeLookState.PitchOffset = 0f; } FreeLookState.PreviousKeyState = key; if (!FreeLookState.Active) { ComebackMode(); return true; } FreeLookState.YawOffset += mouseLook.x * ConfigManager.HorizontalSensitivity.Value; VerticalAdjustments(mouseLook.y); FreeLookState.YawOffset = Mathf.Clamp(FreeLookState.YawOffset, 0f - ConfigManager.MaxYaw.Value, ConfigManager.MaxYaw.Value); return true; } private static void VerticalAdjustments(float yPitch) { if (ConfigManager.EnablePitch.Value) { float num = yPitch; if (ConfigManager.InvertY.Value) { num = 0f - num; } FreeLookState.PitchOffset += num * ConfigManager.VerticalSensitivity.Value; FreeLookState.PitchOffset = Mathf.Clamp(FreeLookState.PitchOffset, 0f - ConfigManager.MaxPitch.Value, ConfigManager.MaxPitch.Value); } } } } namespace FreeLookCamera.Managers { public class ConfigManager { private static ConfigFile _config; public static ConfigEntry FreeLookKey; public static ConfigEntry HorizontalSensitivity; public static ConfigEntry VerticalSensitivity; public static ConfigEntry MaxYaw; public static ConfigEntry MaxPitch; public static ConfigEntry ActivationMode; public static ConfigEntry ReturnMode; public static ConfigEntry ReturnSmoothTime; public static ConfigEntry InvertY; public static ConfigEntry ResetSettings; public static ConfigEntry EnablePitch; public static void Initialize(ConfigFile config) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Expected O, but got Unknown //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Expected O, but got Unknown //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Expected O, but got Unknown //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Expected O, but got Unknown //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Expected O, but got Unknown //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Expected O, but got Unknown //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Expected O, but got Unknown //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Expected O, but got Unknown //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Expected O, but got Unknown _config = config; FreeLookKey = config.Bind("1 - General", "FreeLookKey", (KeyCode)308, new ConfigDescription("Use this key to enable freelook", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 16 } })); EnablePitch = config.Bind("1 - General", "Enable Pitch adjustments", false, new ConfigDescription("Allow vertical freelook movement. Can be disturbing for some players.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 15 } })); ActivationMode = config.Bind("1 - General", "Activation Mode", FreeLookCamera.Settings.ActivationMode.Hold, new ConfigDescription("Choose whether freelook is active while holding the key or toggled on/off(cannot move the normal player camera while toggled on).", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 14 } })); HorizontalSensitivity = config.Bind("2 - Camera - Horizontal", "Horizontal Sensitivity", 1f, new ConfigDescription("Camera horizontal sensitivity", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 35 } })); MaxYaw = config.Bind("2 - Camera - Horizontal", "Max Yaw", 360f, new ConfigDescription("Maximum horizontal rotation allowed. Some games allow maximum 120.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 30 } })); VerticalSensitivity = config.Bind("3 - Camera - Vertical", "Vertical Sensitivity", 0.25f, new ConfigDescription("Camera vertical sensitivity.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 40 } })); MaxPitch = config.Bind("3 - Camera - Vertical", "Max Pitch", 45f, new ConfigDescription("Maximum vertical rotation allowed. Only works if 'EnablePitch' is active.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 45 } })); InvertY = config.Bind("3 - Camera - Vertical", "Invert Y", false, new ConfigDescription("Invert vertical freelook movement.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 46 } })); ReturnMode = config.Bind("4 - Return", "Return Mode", FreeLookCamera.Settings.ReturnMode.Snap, new ConfigDescription("Snap instantly or smoothly return to player view center", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 65 } })); ReturnSmoothTime = config.Bind("4 - Return", "Return Smooth Time", 0.2f, new ConfigDescription("Time in seconds for the camera to return to center when Smooth return is active. Smaller value makes it faster", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 60 } })); ResetSettings = config.Bind("5 - Advanced", "Reset Settings", false, new ConfigDescription("Set true to reset all settings.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { IsAdvanced = true, Order = 100 } })); } public static void ResetAllSettings() { ((ConfigEntryBase)FreeLookKey).BoxedValue = ((ConfigEntryBase)FreeLookKey).DefaultValue; ((ConfigEntryBase)EnablePitch).BoxedValue = ((ConfigEntryBase)EnablePitch).DefaultValue; ((ConfigEntryBase)ActivationMode).BoxedValue = ((ConfigEntryBase)ActivationMode).DefaultValue; ((ConfigEntryBase)HorizontalSensitivity).BoxedValue = ((ConfigEntryBase)HorizontalSensitivity).DefaultValue; ((ConfigEntryBase)MaxYaw).BoxedValue = ((ConfigEntryBase)MaxYaw).DefaultValue; ((ConfigEntryBase)MaxPitch).BoxedValue = ((ConfigEntryBase)MaxPitch).DefaultValue; ((ConfigEntryBase)VerticalSensitivity).BoxedValue = ((ConfigEntryBase)VerticalSensitivity).DefaultValue; ((ConfigEntryBase)InvertY).BoxedValue = ((ConfigEntryBase)InvertY).DefaultValue; ((ConfigEntryBase)ReturnMode).BoxedValue = ((ConfigEntryBase)ReturnMode).DefaultValue; ((ConfigEntryBase)ReturnSmoothTime).BoxedValue = ((ConfigEntryBase)ReturnSmoothTime).DefaultValue; FreeLookState.Reset(); FreeLookState.YawVelocity = 0f; FreeLookState.PitchVelocity = 0f; _config.Save(); } } public class FreeLookState { public static bool Active; public static bool PreviousKeyState; public static float YawOffset; public static float YawVelocity; public static float PitchOffset; public static float PitchVelocity; public static bool HasOffset => Mathf.Abs(YawOffset) > 0.01f || Mathf.Abs(PitchOffset) > 0.01f; public static void Reset() { Active = false; PreviousKeyState = false; YawOffset = 0f; PitchOffset = 0f; } } }