using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MoreCompany.Cosmetics;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;
using _3rdPerson.Helper;
[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("3rdPerson")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("3rdPerson")]
[assembly: AssemblyTitle("3rdPerson")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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]
[Microsoft.CodeAnalysis.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;
}
}
}
namespace _3rdPerson
{
[BepInPlugin("verity.3rdperson", "3rd Person", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
public static readonly Harmony Harmony = new Harmony("verity.3rdperson");
public static ManualLogSource LogSource = null;
public static ConfigEntry<string> KeybindEntry = null;
public static ConfigEntry<string> OrbitKeybindEntry = null;
public static ConfigEntry<float> OrbitSpeedEntry = null;
public static ConfigEntry<float> Distance = null;
public static ConfigEntry<float> RightOffset = null;
public static ConfigEntry<float> UpOffset = null;
public static ConfigEntry<bool> MoreCompanyCosmetics = null;
private void Awake()
{
//IL_0005: 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)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
GameObject val = new GameObject("3rdPerson");
val.AddComponent<PluginLoader>();
((Object)val).hideFlags = (HideFlags)61;
Object.DontDestroyOnLoad((Object)val);
LogSource = ((BaseUnityPlugin)this).Logger;
LogSource.LogInfo((object)"3rd Person Mod Loaded.");
KeybindEntry = ((BaseUnityPlugin)this).Config.Bind<string>("Camera Settings", "Keybind", "c", "The keybind used to toggle third person.");
Distance = ((BaseUnityPlugin)this).Config.Bind<float>("Camera Settings", "Distance", 2f, "Distance of the camera from the player.");
RightOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Camera Settings", "Right-Offset", 0.6f, "Offset of the camera to the right from the player.");
UpOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Camera Settings", "Up-Offset", 0.1f, "Offset of the camera upwards from the player.");
OrbitKeybindEntry = ((BaseUnityPlugin)this).Config.Bind<string>("Orbit Settings", "Keybind", "<Mouse>/middleButton", "The keybind used to 'orbit' around the player.");
OrbitSpeedEntry = ((BaseUnityPlugin)this).Config.Bind<float>("Orbit Settings", "Orbit-Speed", 75f, "The speed/sensitivity of the orbiting.");
MoreCompanyCosmetics = ((BaseUnityPlugin)this).Config.Bind<bool>("Mod Support", "MoreCompany-Cosmetic-Support", false, "Displays MoreCompany Cosmetics in third person, this can mess with first person visibility if you have glasses on.");
}
}
public class PluginLoader : MonoBehaviour
{
private void Start()
{
LocalPlayer localPlayer = ((Component)this).gameObject.AddComponent<LocalPlayer>();
((Object)localPlayer).hideFlags = (HideFlags)61;
Object.DontDestroyOnLoad((Object)(object)localPlayer);
Keybinding keybinding = ((Component)this).gameObject.AddComponent<Keybinding>();
((Object)keybinding).hideFlags = (HideFlags)61;
Object.DontDestroyOnLoad((Object)(object)keybinding);
ThirdPersonCamera thirdPersonCamera = ((Component)this).gameObject.AddComponent<ThirdPersonCamera>();
((Object)thirdPersonCamera).hideFlags = (HideFlags)61;
Object.DontDestroyOnLoad((Object)(object)thirdPersonCamera);
Hooks.Init();
}
}
}
namespace _3rdPerson.Helper
{
public static class Hooks
{
private class HarmonyHooks
{
private static bool _previousState;
public static void MenuOpenedHook()
{
_previousState = ThirdPersonCamera.ViewState;
if (LocalPlayer.IsActive() && ThirdPersonCamera.ViewState)
{
LocalPlayer.GetController().quickMenuManager.isMenuOpen = false;
ThirdPersonCamera.Toggle();
}
}
public static void MenuClosedHook()
{
if (LocalPlayer.IsActive() && _previousState)
{
LocalPlayer.GetController().inTerminalMenu = false;
ThirdPersonCamera.Toggle();
}
}
public static void MoreCompanyHook()
{
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
CosmeticApplication val = Object.FindObjectOfType<CosmeticApplication>();
if (CosmeticRegistry.locallySelectedCosmetics.Count <= 0 || val.spawnedCosmetics.Count > 0)
{
return;
}
foreach (string locallySelectedCosmetic in CosmeticRegistry.locallySelectedCosmetics)
{
val.ApplyCosmetic(locallySelectedCosmetic, true);
}
foreach (CosmeticInstance spawnedCosmetic in val.spawnedCosmetics)
{
Transform transform = ((Component)spawnedCosmetic).transform;
transform.localScale *= 0.38f;
SetAllChildrenLayer(((Component)spawnedCosmetic).transform, 29);
}
}
private static void SetAllChildrenLayer(Transform transform, int layer)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
((Component)transform).gameObject.layer = layer;
foreach (Transform item in transform)
{
SetAllChildrenLayer(item, layer);
}
}
public static bool PlayerInputHook()
{
if (ThirdPersonCamera.ViewState)
{
return !Keybinding.orbitAction.IsPressed();
}
return true;
}
public static void KillPlayerHook()
{
if (ThirdPersonCamera.ViewState)
{
ThirdPersonCamera.Toggle();
}
}
}
public static void Init()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Expected O, but got Unknown
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Expected O, but got Unknown
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Expected O, but got Unknown
//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Expected O, but got Unknown
//IL_0241: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: Expected O, but got Unknown
MethodInfo method = typeof(QuickMenuManager).GetMethod("OpenQuickMenu");
MethodInfo method2 = typeof(HarmonyHooks).GetMethod("MenuOpenedHook");
Plugin.Harmony.Patch((MethodBase)method, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.LogSource.LogInfo((object)"Open Menu Hooked.");
MethodInfo method3 = typeof(QuickMenuManager).GetMethod("CloseQuickMenu");
MethodInfo method4 = typeof(HarmonyHooks).GetMethod("MenuClosedHook");
Plugin.Harmony.Patch((MethodBase)method3, new HarmonyMethod(method4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.LogSource.LogInfo((object)"Close Menu Hooked.");
MethodInfo method5 = typeof(Terminal).GetMethod("BeginUsingTerminal");
MethodInfo method6 = typeof(HarmonyHooks).GetMethod("MenuOpenedHook");
Plugin.Harmony.Patch((MethodBase)method5, new HarmonyMethod(method6), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.LogSource.LogInfo((object)"Open Terminal Hooked.");
MethodInfo method7 = typeof(Terminal).GetMethod("QuitTerminal");
MethodInfo method8 = typeof(HarmonyHooks).GetMethod("MenuClosedHook");
Plugin.Harmony.Patch((MethodBase)method7, new HarmonyMethod(method8), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.LogSource.LogInfo((object)"Close Terminal Hooked.");
MethodInfo method9 = typeof(PlayerControllerB).GetMethod("PlayerLookInput", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo method10 = typeof(HarmonyHooks).GetMethod("PlayerInputHook");
Plugin.Harmony.Patch((MethodBase)method9, new HarmonyMethod(method10), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.LogSource.LogInfo((object)"Player Look Input Hooked.");
MethodInfo method11 = typeof(PlayerControllerB).GetMethod("KillPlayer");
MethodInfo method12 = typeof(HarmonyHooks).GetMethod("KillPlayerHook");
Plugin.Harmony.Patch((MethodBase)method11, new HarmonyMethod(method12), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.LogSource.LogInfo((object)"Player Killed Hooked.");
if (Chainloader.PluginInfos.ContainsKey("me.swipez.melonloader.morecompany") && Plugin.MoreCompanyCosmetics.Value)
{
MethodInfo method13 = typeof(HUDManager).GetMethod("AddPlayerChatMessageClientRpc", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo method14 = typeof(HarmonyHooks).GetMethod("MoreCompanyHook");
Plugin.Harmony.Patch((MethodBase)method13, (HarmonyMethod)null, new HarmonyMethod(method14), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.LogSource.LogInfo((object)"MoreCompany Cosmetics Added.");
}
Plugin.LogSource.LogInfo((object)"Hooks Initialized.");
}
}
public class Keybinding : MonoBehaviour
{
public static InputAction orbitAction;
private void Awake()
{
//IL_0019: 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_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
InputAction val = new InputAction((string)null, (InputActionType)0, "<Keyboard>/" + Plugin.KeybindEntry.Value, (string)null, (string)null, (string)null);
val.performed += KeyPressed;
val.Enable();
orbitAction = new InputAction("MouseLeftClick", (InputActionType)0, Plugin.OrbitKeybindEntry.Value ?? "", (string)null, (string)null, (string)null);
orbitAction.Enable();
}
private void KeyPressed(CallbackContext obj)
{
ThirdPersonCamera.Toggle();
}
private void OnEnable()
{
Plugin.LogSource.LogInfo((object)("Keybinding Initialized, Current Keybind " + Plugin.KeybindEntry.Value + "."));
}
}
public class LocalPlayer : MonoBehaviour
{
private static PlayerControllerB? _playerController;
public void OnEnable()
{
Plugin.LogSource.LogInfo((object)"Local Player Caching Initialized.");
}
private void Update()
{
if (GameNetworkManager.Instance != null)
{
_playerController = GameNetworkManager.Instance.localPlayerController;
}
}
public static bool IsActive()
{
if ((Object)(object)_playerController != (Object)null)
{
return !_playerController.isPlayerDead;
}
return false;
}
public static PlayerControllerB GetController()
{
return _playerController;
}
}
public class ThirdPersonCamera : MonoBehaviour
{
private static Camera _camera;
public static bool ViewState;
public static Camera GetCamera => _camera;
private void Awake()
{
_camera = ((Component)this).gameObject.AddComponent<Camera>();
((Object)_camera).hideFlags = (HideFlags)61;
_camera.fieldOfView = 66f;
_camera.nearClipPlane = 0.1f;
_camera.cullingMask = 557520895;
if (Chainloader.PluginInfos.ContainsKey("quackandcheese.mirrordecor"))
{
_camera.cullingMask = 557520887;
}
((Behaviour)_camera).enabled = false;
Object.DontDestroyOnLoad((Object)(object)_camera);
}
private void OnEnable()
{
Plugin.LogSource.LogInfo((object)"Third Person Camera Initialized.");
}
private void Update()
{
if (!LocalPlayer.IsActive() || LocalPlayer.GetController().quickMenuManager.isMenuOpen || LocalPlayer.GetController().inTerminalMenu || LocalPlayer.GetController().isPlayerDead)
{
return;
}
if (Object.FindObjectsOfType<CentipedeAI>().Any((CentipedeAI centipede) => (Object)(object)centipede.clingingToPlayer != (Object)null && centipede.clingingToPlayer.playerClientId == NetworkManager.Singleton.LocalClientId))
{
Plugin.LogSource.LogInfo((object)"Centipede On Player!");
if (ViewState)
{
Toggle();
}
}
else if (!Keybinding.orbitAction.IsPressed())
{
ThirdPersonUpdate();
}
else
{
ThirdPersonOrbitUpdate();
}
}
private void ThirdPersonUpdate()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: 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)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: 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_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_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_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)
//IL_007a: 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)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: 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_008b: 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)
Camera gameplayCamera = LocalPlayer.GetController().gameplayCamera;
Vector3 val = ((Component)gameplayCamera).transform.forward * -1f;
Vector3 val2 = ((Component)gameplayCamera).transform.TransformDirection(Vector3.right) * Plugin.RightOffset.Value;
Vector3 val3 = Vector3.up * Plugin.UpOffset.Value;
float value = Plugin.Distance.Value;
((Component)_camera).transform.position = ((Component)gameplayCamera).transform.position + val * value + val2 + val3;
((Component)_camera).transform.rotation = Quaternion.LookRotation(((Component)gameplayCamera).transform.forward);
}
private void ThirdPersonOrbitUpdate()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: 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_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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_00a7: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: 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)
MovementActions movement = LocalPlayer.GetController().playerActions.Movement;
Vector2 val = ((MovementActions)(ref movement)).Look.ReadValue<Vector2>() * (0.008f * (float)IngamePlayerSettings.Instance.settings.lookSensitivity);
if (IngamePlayerSettings.Instance.settings.invertYAxis)
{
val.y *= -1f;
}
((Component)_camera).transform.Rotate(Vector3.right, val.y * Plugin.OrbitSpeedEntry.Value * Time.deltaTime);
((Component)_camera).transform.RotateAround(((Component)LocalPlayer.GetController().gameplayCamera).transform.position, Vector3.up, val.x * Plugin.OrbitSpeedEntry.Value * Time.deltaTime);
float value = Plugin.Distance.Value;
((Component)_camera).transform.position = ((Component)LocalPlayer.GetController().gameplayCamera).transform.position - ((Component)_camera).transform.forward * value;
}
public static void Toggle()
{
if (!LocalPlayer.IsActive() || LocalPlayer.GetController().isTypingChat || LocalPlayer.GetController().quickMenuManager.isMenuOpen || LocalPlayer.GetController().inTerminalMenu || LocalPlayer.GetController().isPlayerDead)
{
return;
}
ViewState = !ViewState;
GameObject val = GameObject.Find("Systems/UI/Canvas/Panel/");
Canvas component = GameObject.Find("Systems/UI/Canvas/").GetComponent<Canvas>();
if (ViewState)
{
if (!Chainloader.PluginInfos.ContainsKey("quackandcheese.mirrordecor"))
{
((Renderer)LocalPlayer.GetController().thisPlayerModel).shadowCastingMode = (ShadowCastingMode)1;
}
val.SetActive(false);
component.worldCamera = _camera;
component.renderMode = (RenderMode)0;
GameObject.Find("Systems/Rendering/PlayerHUDHelmetModel/").SetActive(false);
((Renderer)LocalPlayer.GetController().thisPlayerModelArms).enabled = false;
((Behaviour)LocalPlayer.GetController().gameplayCamera).enabled = false;
((Behaviour)_camera).enabled = true;
}
else
{
if (!Chainloader.PluginInfos.ContainsKey("quackandcheese.mirrordecor"))
{
((Renderer)LocalPlayer.GetController().thisPlayerModel).shadowCastingMode = (ShadowCastingMode)3;
}
val.SetActive(true);
component.worldCamera = GameObject.Find("UICamera").GetComponent<Camera>();
component.renderMode = (RenderMode)1;
GameObject.Find("Systems/Rendering/PlayerHUDHelmetModel/").SetActive(true);
((Renderer)LocalPlayer.GetController().thisPlayerModelArms).enabled = true;
((Behaviour)LocalPlayer.GetController().gameplayCamera).enabled = true;
((Behaviour)_camera).enabled = false;
}
}
}
}