Some mods may be broken due to the recent Alloyed Collective update.
Decompiled source of True First Person v1.0.2
TrueFirstPerson.dll
Decompiled 6 months agousing 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.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using EmotesAPI; using HG.Reflection; using On.RoR2; using RiskOfOptions; using RiskOfOptions.Options; using RoR2; using RoR2.UI; using UnityEngine; using UnityEngine.Networking; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: OptIn] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("TrueFirstPerson")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+6111d1b57b7eac400caae9bff148a6d40c4646d2")] [assembly: AssemblyProduct("TrueFirstPerson")] [assembly: AssemblyTitle("TrueFirstPerson")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] namespace TrueFirstPerson; public static class EmoteCompatability { public const string customEmotesApiGUID = "com.weliveinasociety.CustomEmotesAPI"; public static string CurrentEmote() { if (Object.op_Implicit((Object)(object)CustomEmotesAPI.localMapper)) { return CustomEmotesAPI.localMapper.currentClipName; } return "none"; } public static Quaternion GetHeadRotation() { //IL_002a: 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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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) if (Object.op_Implicit((Object)(object)CustomEmotesAPI.localMapper)) { return ((Component)CustomEmotesAPI.localMapper).GetComponent<Animator>().GetBoneTransform((HumanBodyBones)10).rotation; } return Quaternion.identity; } public static Transform GetHeadBone() { if (Object.op_Implicit((Object)(object)CustomEmotesAPI.localMapper)) { return ((Component)CustomEmotesAPI.localMapper).GetComponent<Animator>().GetBoneTransform((HumanBodyBones)10); } return null; } } [Serializable] [BepInPlugin("com.brynzananas.truefirstperson", "True First Person", "1.0.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Main : BaseUnityPlugin { public class FirstPersonCameraComponent : MonoBehaviour { private float previousFov = 60f; private Vector3 previousPosition = Vector3.zero; public Transform transformToChange; private Transform previousTransform; private Quaternion emoteStartQuaternion; private Vector3 emoteStartVector; private float emoteStartAngle; private bool emoteStart = false; private GameObject delta; private string previousEmote = "none"; public void OnEnable() { //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_009b: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)previousCamera)) { previousCamera.SetActive(false); previousFov = previousMainCameraRigController.baseFov; transformToChange = ((Component)((Component)this).transform.root).GetComponent<CharacterModel>().body.aimOriginTransform; if ((Object)(object)transformToChange != (Object)null) { previousPosition = transformToChange.localPosition; previousTransform = transformToChange.parent; transformToChange.SetParent(((Component)this).transform, false); transformToChange.localPosition = Vector3.zero; } previousMainCameraRigController.baseFov = FieldOfViewConfig.Value; if (Object.op_Implicit((Object)(object)camera) && Object.op_Implicit((Object)(object)camera.GetComponent<Camera>())) { previousMainCameraRigController.sceneCam = camera.GetComponent<Camera>(); } } } public void LateUpdate() { //IL_0047: 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) if (emotesEnabled && EmoteLookLockMode.Value && EmoteCompatability.CurrentEmote() != "none") { if (emoteStart) { ((Component)this).transform.rotation = delta.transform.rotation; } } else if (EnableLook.Value && Object.op_Implicit((Object)(object)previousMainCamera)) { ((Component)this).transform.rotation = previousMainCamera.transform.rotation; } } public void EarlyUpdate() { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_0089: Unknown result type (might be due to invalid IL or missing references) if (emotesEnabled && EmoteLookLockMode.Value && EmoteCompatability.CurrentEmote() != "none" && EmoteCompatability.CurrentEmote() == previousEmote) { if (!emoteStart) { delta = new GameObject("delta"); delta.transform.SetParent(EmoteCompatability.GetHeadBone(), false); delta.transform.rotation = ((Component)this).transform.root.rotation; emoteStart = true; } return; } previousEmote = EmoteCompatability.CurrentEmote(); if (emoteStart) { if (Object.op_Implicit((Object)(object)delta)) { Object.Destroy((Object)(object)delta); } emoteStart = false; } } public void OnDisable() { //IL_006b: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)previousCamera)) { previousMainCameraRigController.sceneCam = previousCamera.GetComponent<Camera>(); previousMainCameraRigController.baseFov = previousFov; previousCamera.SetActive(true); } if (Object.op_Implicit((Object)(object)transformToChange)) { transformToChange.SetParent(previousTransform, false); transformToChange.localPosition = previousPosition; } } } public const string ModGuid = "com.brynzananas.truefirstperson"; public const string ModName = "True First Person"; public const string ModVer = "1.0.2"; public static ConfigEntry<KeyboardShortcut> FirstPersonToggle; public static ConfigEntry<float> FieldOfViewConfig; public static ConfigEntry<float> CurrentClip; public static ConfigEntry<bool> EnableLook; public static ConfigEntry<bool> EmoteLookLockMode; public static ConfigEntry<bool> EnableDebugKeys; private static bool emotesEnabled = false; public static Dictionary<string, string> survivorDefaultBoneOverride = new Dictionary<string, string>(); public static Dictionary<string, ConfigEntry<Color>> sceneSunColor = new Dictionary<string, ConfigEntry<Color>>(); public static Dictionary<string, ConfigEntry<string>> survivorBoneOverride = new Dictionary<string, ConfigEntry<string>>(); public static Dictionary<string, float> survivorClipDefaultValues = new Dictionary<string, float>(); public static Dictionary<string, ConfigEntry<float>> survivorClipValues = new Dictionary<string, ConfigEntry<float>>(); private bool set = false; private float angle = -69420f; private Quaternion initialQuaternion = Quaternion.identity; private Vector3 initialVector = Vector3.zero; private bool emoteAngles = false; public static MPEventSystem eventSystem = null; public static Vector2 rotationCamera = Vector2.zero; public static GameObject previousCamera = null; public static GameObject head = null; public static GameObject camera = null; public static GameObject UIcamera = null; public static GameObject previousMainCamera = null; public static CameraRigController previousMainCameraRigController = null; public static GameObject mainCamera = null; public bool toggle = true; public static PluginInfo PInfo { get; private set; } public void Awake() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Expected O, but got Unknown //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Expected O, but got Unknown //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Expected O, but got Unknown //IL_029d: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Expected O, but got Unknown //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Expected O, but got Unknown //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Expected O, but got Unknown //IL_02cd: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Expected O, but got Unknown //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Expected O, but got Unknown //IL_02ed: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Expected O, but got Unknown //IL_0347: Unknown result type (might be due to invalid IL or missing references) //IL_034d: Expected O, but got Unknown //IL_038e: Unknown result type (might be due to invalid IL or missing references) //IL_039d: Unknown result type (might be due to invalid IL or missing references) FirstPersonToggle = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "First Person Toggle", new KeyboardShortcut((KeyCode)111, Array.Empty<KeyCode>()), "Key to toggle first person"); FieldOfViewConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Field Of View", 90f, "I don't need to explain this"); CurrentClip = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Current Camera Near Clip Parameter", 0.3f, "Current value of near camera clipping"); EnableLook = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Input Camera Direction?", true, "Enable first person camera rotation to follow input rotation?"); EmoteLookLockMode = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Emote Camera Lock", true, "Enable first person camera rotation to follow head rotation while emoting?"); EnableDebugKeys = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Control Keys?", true, "Enable keys to control FOV and Near Clip values in game?\n\nUse +/- buttons to increase/decrease FOV value. Hold Shift to change Near Clip value"); survivorDefaultBoneOverride.Add("RobPaladinBody", "Armature/base/spine.001/spine.002/spine.003/spine.004/neck/head"); survivorDefaultBoneOverride.Add("HuntressBody", "HuntressArmature/ROOT/base/stomach/chest/head"); emotesEnabled = Chainloader.PluginInfos.ContainsKey("com.weliveinasociety.CustomEmotesAPI"); PlayerCharacterMasterController.Update += new hook_Update(SetCamera); PlayerCharacterMasterController.OnBodyStart += new hook_OnBodyStart(PlayerCharacterMasterController_OnBodyStart); SurvivorCatalog.Init += new hook_Init(SurvivorCatalog_Init); survivorClipDefaultValues.Add("Bandit2Body", 0.21f); survivorClipDefaultValues.Add("CommandoBody", 0.03337884f); survivorClipDefaultValues.Add("CrocoBody", 0.5f); survivorClipDefaultValues.Add("HereticBody", 0.755f); survivorClipDefaultValues.Add("LoaderBody", 0.06564139f); survivorClipDefaultValues.Add("MageBody", 0.03318632f); survivorClipDefaultValues.Add("MercBody", 0.0266057f); survivorClipDefaultValues.Add("ToolbotBody", 0.51f); survivorClipDefaultValues.Add("TreebotBody", 1f); survivorClipDefaultValues.Add("RailgunnerBody", 0.2f); survivorClipDefaultValues.Add("VoidSurvivorBody", 0.2f); survivorClipDefaultValues.Add("RobPaladinBody", 0.3795359f); survivorClipDefaultValues.Add("EngiBody", 0.01989561f); survivorClipDefaultValues.Add("HuntressBody", 0.2203578f); survivorClipDefaultValues.Add("BidenBody", 0.1532053f); survivorClipDefaultValues.Add("CaptainBody", 0.01986642f); ModSettingsManager.AddOption((BaseOption)new KeyBindOption(FirstPersonToggle)); ModSettingsManager.AddOption((BaseOption)new FloatFieldOption(FieldOfViewConfig)); ModSettingsManager.AddOption((BaseOption)new FloatFieldOption(CurrentClip)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(EnableLook)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(EmoteLookLockMode)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(EnableDebugKeys)); FieldOfViewConfig.SettingChanged += FieldOfViewConfig_SettingChanged; CurrentClip.SettingChanged += FieldOfViewConfig_SettingChanged; EnableLook.SettingChanged += EnableLook_SettingChanged; Texture2D val = new Texture2D(256, 256); using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TrueFirstPerson.modicon.png"); using BinaryReader binaryReader = new BinaryReader(stream); ImageConversion.LoadImage(val, binaryReader.ReadBytes((int)stream.Length)); Sprite modIcon = Sprite.Create(val, new Rect(0f, 0f, 256f, 256f), new Vector2(0f, 0f)); ModSettingsManager.SetModIcon(modIcon); } private void PlayerCharacterMasterController_OnBodyStart(orig_OnBodyStart orig, PlayerCharacterMasterController self) { orig.Invoke(self); toggle = true; } private void SaveValue() { if (Object.op_Implicit((Object)(object)camera)) { string text = ((Object)((Component)camera.transform.root).GetComponent<CharacterModel>().body).name; while (text.Contains("(Clone)")) { text = text.Replace("(Clone)", ""); } survivorClipValues[text].Value = CurrentClip.Value; } } private void EnableLook_SettingChanged(object sender, EventArgs e) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)camera)) { camera.transform.localRotation = Quaternion.identity; } } private void FieldOfViewConfig_SettingChanged(object sender, EventArgs e) { if (Object.op_Implicit((Object)(object)camera)) { Camera component = camera.GetComponent<Camera>(); previousMainCameraRigController.baseFov = FieldOfViewConfig.Value; component.nearClipPlane = CurrentClip.Value; string text = ((Object)((Component)camera.transform.root).GetComponent<CharacterModel>().body).name; while (text.Contains("(Clone)")) { text = text.Replace("(Clone)", ""); } survivorClipValues[text].Value = CurrentClip.Value; } } private void SurvivorCatalog_Init(orig_Init orig) { //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Expected O, but got Unknown //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Expected O, but got Unknown orig.Invoke(); if (set) { return; } set = true; foreach (SurvivorDef allSurvivorDef in SurvivorCatalog.allSurvivorDefs) { string name = ((Object)allSurvivorDef.bodyPrefab).name; float num = 0.3f; if (survivorClipDefaultValues.ContainsKey(name)) { num = survivorClipDefaultValues[name]; } string text = ""; if (survivorDefaultBoneOverride.ContainsKey(name)) { text = survivorDefaultBoneOverride[name]; } name = name.Replace("Body", ""); name = CleanUpString(name); ConfigEntry<float> val = ((BaseUnityPlugin)this).Config.Bind<float>("Survivors Config", name + " Clip Value", num, "Near clip value for " + name + " survivor"); ModSettingsManager.AddOption((BaseOption)new FloatFieldOption(val)); survivorClipValues.Add(((Object)allSurvivorDef.bodyPrefab).name, val); ConfigEntry<string> val2 = ((BaseUnityPlugin)this).Config.Bind<string>("Survivors Config", name + " Path Override", text, "Manual camera parenting path override"); ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(val2)); survivorBoneOverride.Add(((Object)allSurvivorDef.bodyPrefab).name, val2); } } public void SetHead(CharacterBody body = null) { //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0212: 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_022f: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)body == (Object)null) { CharacterMaster master = NetworkUser.readOnlyLocalPlayersList[0].master; body = ((master != null) ? master.GetBody() : null); } if ((Object)(object)body == (Object)null) { return; } string text = ((Object)body).name; while (text.Contains("(Clone)")) { text = text.Replace("(Clone)", ""); } Transform modelTransform = ((Component)body).GetComponent<ModelLocator>().modelTransform; HurtBoxGroup component = ((Component)modelTransform).GetComponent<HurtBoxGroup>(); if (survivorBoneOverride.ContainsKey(text) && survivorBoneOverride[text].Value != "") { try { head = ((Component)modelTransform.Find(survivorBoneOverride[text].Value)).gameObject; } catch { } } if ((Object)(object)head == (Object)null) { HurtBox[] hurtBoxes = component.hurtBoxes; foreach (HurtBox val in hurtBoxes) { if (val.isSniperTarget && (Object)(object)val != (Object)(object)component.mainHurtBox) { head = ((Component)val).gameObject; break; } } } if ((Object)(object)((Component)modelTransform).GetComponent<ChildLocator>() == (Object)null) { return; } if ((Object)(object)head == (Object)null) { NameTransformPair[] transformPairs = ((Component)modelTransform).GetComponent<ChildLocator>().transformPairs; foreach (NameTransformPair val2 in transformPairs) { if (val2.name.ToLower().Contains("head") && !val2.name.ToLower().Contains("cannon")) { head = ((Component)val2.transform).gameObject; break; } } } if (!((Object)(object)head == (Object)null)) { return; } NameTransformPair[] transformPairs2 = ((Component)modelTransform).GetComponent<ChildLocator>().transformPairs; foreach (NameTransformPair val3 in transformPairs2) { if (val3.name.ToLower().Contains("chest")) { head = ((Component)val3.transform).gameObject; break; } } } public void SetCameraLocalPosition() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: 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_006d: Unknown result type (might be due to invalid IL or missing references) Vector3 localPosition = Vector3.zero; if (Object.op_Implicit((Object)(object)head.GetComponent<HurtBox>())) { if (Object.op_Implicit((Object)(object)((Component)head.GetComponent<HurtBox>()).GetComponent<SphereCollider>())) { localPosition = ((Component)head.GetComponent<HurtBox>()).GetComponent<SphereCollider>().center; } if (Object.op_Implicit((Object)(object)head.GetComponent<CapsuleCollider>())) { localPosition = head.GetComponent<CapsuleCollider>().center; } } if (Object.op_Implicit((Object)(object)head.GetComponent<SphereCollider>())) { localPosition = head.GetComponent<SphereCollider>().center; } if (Object.op_Implicit((Object)(object)head.GetComponent<CapsuleCollider>())) { localPosition = head.GetComponent<CapsuleCollider>().center; } camera.transform.localPosition = localPosition; } public string CleanUpString(string stringName) { char[] array = new char[4] { '[', ']', '"', '\'' }; char[] array2 = array; foreach (char oldChar in array2) { stringName = stringName.Replace(oldChar, ' '); } return stringName; } private void SetCamera(orig_Update orig, PlayerCharacterMasterController self) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) orig.Invoke(self); KeyboardShortcut value = FirstPersonToggle.Value; if (Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey) && !PauseManager.isPaused && (!Object.op_Implicit((Object)(object)((Component)self.networkUser.cameraRigController.hud).GetComponentInChildren<ChatBox>()) || !((Component)self.networkUser.cameraRigController.hud).GetComponentInChildren<ChatBox>().showInput) && Object.op_Implicit((Object)(object)self.body)) { if ((Object)(object)previousMainCamera == (Object)null) { previousMainCamera = ((Component)self.networkUser.cameraRigController).gameObject; previousMainCameraRigController = self.networkUser.cameraRigController; } if ((Object)(object)eventSystem == (Object)null) { eventSystem = ((Component)previousMainCameraRigController.hud).GetComponent<MPEventSystemProvider>().eventSystem; } if ((Object)(object)previousCamera == (Object)null) { previousCamera = ((Component)previousMainCameraRigController.sceneCam).gameObject; } if (toggle) { Transform modelTransform = ((Component)self.body).GetComponent<ModelLocator>().modelTransform; HurtBoxGroup component = ((Component)modelTransform).GetComponent<HurtBoxGroup>(); string text = ((Object)self.body).name; while (text.Contains("(Clone)")) { text = text.Replace("(Clone)", ""); } SetHead(self.body); if ((Object)(object)head == (Object)null) { if (!Object.op_Implicit((Object)(object)mainCamera)) { } return; } if ((Object)(object)camera == (Object)null) { camera = Object.Instantiate<GameObject>(previousCamera, head.transform); SetCameraLocalPosition(); camera.GetComponent<SceneCamera>().cameraRigController = previousMainCameraRigController; FirstPersonCameraComponent firstPersonCameraComponent = camera.AddComponent<FirstPersonCameraComponent>(); } camera.transform.localRotation = Quaternion.identity; Camera component2 = camera.GetComponent<Camera>(); component2.fieldOfView = FieldOfViewConfig.Value; float num = 0.3f; if (survivorClipValues.ContainsKey(text)) { num = survivorClipValues[text].Value; } component2.nearClipPlane = num; CurrentClip.Value = num; toggle = false; } else { if (Object.op_Implicit((Object)(object)camera)) { Object.Destroy((Object)(object)camera); } toggle = true; } } if (!Object.op_Implicit((Object)(object)camera)) { return; } if (EnableLook.Value && Object.op_Implicit((Object)(object)head) && head.activeInHierarchy && NetworkServer.active) { self.body.inputBank.aimDirection = camera.transform.forward; } if (Input.GetKey((KeyCode)304)) { if (Input.GetKey((KeyCode)61) || Input.GetKey((KeyCode)43)) { Increment(CurrentClip, Time.deltaTime); } if (Input.GetKey((KeyCode)45)) { Increment(CurrentClip, 0f - Time.deltaTime); } } else { if (Input.GetKey((KeyCode)61) || Input.GetKey((KeyCode)43)) { Increment(FieldOfViewConfig, Time.deltaTime * 15f); } if (Input.GetKey((KeyCode)45)) { Increment(FieldOfViewConfig, (0f - Time.deltaTime) * 15f); } } static void Increment(ConfigEntry<float> config, float number) { config.Value += number; } } }