Decompiled source of Projectile Cam v0.1.34
plugins/ProjectileCam.dll
Decompiled 3 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using AzNean.SotfCommon; using Ballistics; using BepInEx; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using HarmonyLib; using Il2CppInterop.Runtime.Attributes; using Il2CppInterop.Runtime.Injection; using Il2CppInterop.Runtime.InteropTypes; using Il2CppSystem; using Il2CppSystem.Collections.Generic; using Il2CppSystem.Reflection; using Microsoft.CodeAnalysis; using ProjectileCam.Logic; using ProjectileCam.Patches; using Sons.Ai.Vail; using Sons.Gui; using Sons.Inventory; using Sons.Items.Core; using Sons.StatSystem; using Sons.Weapon; using TheForest.Utils; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("ProjectileCam")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.34.0")] [assembly: AssemblyInformationalVersion("0.1.34+5dc04048c6c0c9b83c5e7635553a6455b4ccab8a")] [assembly: AssemblyProduct("ProjectileCam")] [assembly: AssemblyTitle("ProjectileCam")] [assembly: AssemblyVersion("0.1.34.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [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 static class SettingMove { internal static void Move(ConfigFile config, string oldSection, string oldKey, ConfigEntryBase to) { bool saveOnConfigSet = config.SaveOnConfigSet; config.SaveOnConfigSet = false; try { ConfigEntry<string> val = config.Bind<string>(oldSection, oldKey, "\u0001", "Old place of a moved setting."); bool num = val.Value != "\u0001"; if (num) { to.SetSerializedValue(((ConfigEntryBase)val).GetSerializedValue()); } config.Remove(((ConfigEntryBase)val).Definition); if (num) { config.Save(); } } finally { config.SaveOnConfigSet = saveOnConfigSet; } } } namespace AzNean.SotfCommon { internal static class ModLog { private static ManualLogSource _log; private static ConfigEntry<bool> _full; private static readonly HashSet<string> _once = new HashSet<string>(); private static readonly Dictionary<(int, string), int> _state = new Dictionary<(int, string), int>(); internal static bool Full => _full.Value; internal static void Init(ManualLogSource log, ConfigEntry<bool> full) { _log = log; _full = full; } internal static void Trace(string message) { if (_full.Value) { _log.LogInfo((object)message); } } internal static bool Changed(int id, string what, int state) { if (!_full.Value || (_state.TryGetValue((id, what), out var value) && value == state)) { return false; } _state[(id, what)] = state; return true; } internal static void Once(string key, string message, LogLevel level = (LogLevel)16) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) if (_once.Add(key)) { _log.Log(level, (object)message); } } } } namespace ProjectileCam { public class CamWatcher : MonoBehaviour { private enum Phase { Idle, Preview, Riding, Lingering, Fading } private const float StuckSeconds = 0.15f; private const float FirstFrameWarnSeconds = 0.1f; private const float LandingWarnMetres = 2f; private const float ImpactMatchMetres = 5f; private const float CameraRadius = 0.2f; private const int CanvasOrder = 500; private const float ControllerWaitSeconds = 3f; private const float RetrySeconds = 5f; private static CamWatcher _instance; private float _retryAt; private static readonly HashSet<string> ErrorsLogged = new HashSet<string>(); private RangedWeapon _pending; private int _lastShotId; private IntPtr _lastShotPtr; private Phase _phase; private View _view; private string _item; private Bullet _bullet; private GameObject _bulletObject; private Transform _bulletTransform; private int _bulletId; private RangedWeaponController _controller; private HealthStat _health; private int _wallMask; private bool _impactKnown; private bool _shown; private bool _snap; private bool _wasAiming; private bool _aimHeld; private Vector3 _impact; private Vector3 _incoming; private Vector3 _lastPos; private Vector3 _dir; private Vector3 _offset; private Quaternion _rotation; private Color _frameColour; private float _timer; private float _still; private float _lastHealth; private int _heldId; private RangedWeapon _heldWeapon; private RangedWeaponController _heldController; private string _heldItem; private bool _heldBow; private bool _boxesMade; private bool _heldGameLanding; private float _nextPreview; private float _heldSince; private Vector3 _previewPos; private Quaternion _previewRot; private string _previewCutBy; private float _baseFrameMs; private float _frameSum; private int _frames; private int _stillFrames; private int _gameRides; private int _lateRides; private int _bulletsFrame; private int _rodeFrame; private Vector3? _shotPredicted; private bool _covered; private long _codeTicks; private Camera _cam; private Transform _camTransform; private HDAdditionalCameraData _hd; private RenderTexture _rt; private GameObject _ui; private RectTransform _frameRect; private RectTransform _imageRect; private Image _frame; private RawImage _image; private IntPtr _shotWeapon; private Vector3 _pendingDir; private LaunchFrom _previewFrom; private Vector3 _launchDir; private bool _upscalerLogged; private string _noPreview; private static readonly FrameSettingsField[] CostlyEffects; private bool _costlyWarned; private bool Resting => Time.unscaledTime < _retryAt; public CamWatcher(IntPtr ptr) : base(ptr) { } private void Awake() { _instance = this; } internal static void Fired(RangedWeapon weapon, Vector3 direction) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) CamWatcher instance = _instance; if ((Object)(object)instance == (Object)null || instance.Resting) { return; } try { instance.OnFired(weapon, direction); } catch (Exception e) { instance.Fail(e); } } internal static void Hit(Vector3 point, Weapon weapon) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) CamWatcher instance = _instance; if ((Object)(object)instance == (Object)null || instance.Resting || instance._phase != Phase.Riding) { return; } if ((Object)(object)weapon != (Object)null && instance._shotWeapon != IntPtr.Zero && ((Il2CppObjectBase)weapon).Pointer != instance._shotWeapon) { if (ModLog.Changed(instance._bulletId, "other weapon impact", 1)) { ModLog.Trace(instance._item + ": another weapon's impact ignored, the followed flight goes on"); } return; } try { instance.OnHit(point); } catch (Exception e) { instance.Fail(e); } } private void OnHit(Vector3 point) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_0053: 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_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Expected O, but got Unknown //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) Vector3 val = point - _lastPos; if (((Vector3)(ref val)).sqrMagnitude > 25f) { if (ModLog.Changed(_bulletId, "far impact", 1)) { ModLog.Trace($"{_item}: an impact {Vector3.Distance(point, _lastPos):F1} m from the followed projectile ignored (farther than {5f} m: another projectile)"); } return; } _phase = Phase.Lingering; _timer = 0f; Vector3? shotPredicted = _shotPredicted; if (shotPredicted.HasValue) { Vector3 valueOrDefault = shotPredicted.GetValueOrDefault(); if (Vector3.Distance(valueOrDefault, point) > 2f) { ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(96, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(_item); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": landed "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(Vector3.Distance(valueOrDefault, point), "F1"); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" m from where the game's simulation said at the shot: the aim preview looked elsewhere."); } logger.LogWarning(val2); } } _shotPredicted = null; if (ModLog.Full) { ModLog.Trace($"{_item}: game impact {Vector3.Distance(point, _lastPos):F1} m from the followed projectile after {_frames} frames, view frozen"); } } internal static void AfterBullets() { CamWatcher instance = _instance; if ((Object)(object)instance == (Object)null || instance.Resting) { return; } instance._bulletsFrame = Time.frameCount; if (instance._phase != Phase.Riding || instance._covered) { return; } instance._gameRides++; try { instance.Ride(Time.deltaTime); } catch (Exception e) { instance.Fail(e); } } private void Ride(float dt) { _rodeFrame = Time.frameCount; string text = LandedWhy(); if (text == null) { Place(dt); return; } if (ModLog.Full) { ModLog.Trace($"{_item}: {text} after {_frames} frames, view frozen"); } _phase = Phase.Lingering; _timer = 0f; } private void LateUpdate() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) if (Resting) { return; } long timestamp = Stopwatch.GetTimestamp(); try { if ((Object)(object)_pending != (Object)null) { RangedWeapon pending = _pending; _pending = null; OnFired(pending, _pendingDir); if ((Object)(object)_pending != (Object)null) { ModLog.Trace("Shot by " + ((Object)pending).name + ": projectile still not recorded a frame later, no view"); _pending = null; } } if (_phase >= Phase.Riding) { Follow(); } else { PreviewTick(); } } catch (Exception e) { Fail(e); } _codeTicks += Stopwatch.GetTimestamp() - timestamp; } [HideFromIl2Cpp] private void Fail(Exception e) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown _retryAt = Time.unscaledTime + 5f; if (ErrorsLogged.Add(e.ToString())) { ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(88, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("ProjectileCam error, view closed, trying again in "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(5f); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" s (this error is not written again): "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(e); } logger.LogError(val); } try { EndView("an error"); } catch { } } [HideFromIl2Cpp] private void OnFired(RangedWeapon weapon, Vector3 direction) { //IL_00a4: 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_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_031b: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) if (weapon._controlledByAI || !LocalPlayer.IsInWorld) { return; } ItemInstance rightHandItem = LocalPlayer.Inventory.RightHandItem; GameObject val = ((rightHandItem != null) ? rightHandItem.ItemObject : null); if (!weapon._isLocalPlayer && !((Component)weapon).transform.IsChildOf(LocalPlayer.Transform) && (!((Object)(object)val != (Object)null) || !((Component)weapon).transform.IsChildOf(val.transform))) { if (ModLog.Full) { ModLog.Trace("Shot ignored, not ours: " + ((Object)weapon).name); } return; } _shotWeapon = ((Il2CppObjectBase)weapon).Pointer; Bullet lastFiredProjectile = weapon.LastFiredProjectile; if ((Object)(object)lastFiredProjectile == (Object)null) { _pending = weapon; _pendingDir = direction; ((Behaviour)this).enabled = true; return; } _pending = null; if (lastFiredProjectile.Id != _lastShotId || !(((Il2CppObjectBase)lastFiredProjectile).Pointer == _lastShotPtr)) { _lastShotId = lastFiredProjectile.Id; _lastShotPtr = ((Il2CppObjectBase)lastFiredProjectile).Pointer; RangedWeaponController rangedWeaponController = weapon._rangedWeaponController; if ((Object)(object)rangedWeaponController == (Object)null) { weapon.TryGetRangedWeaponController(ref rangedWeaponController); } string text = ItemName(weapon); bool flag = Plugin.IsChosen(text); Prediction p = (flag ? Predict(weapon, aiming: false) : default(Prediction)); _launchDir = ((Vector3)(ref direction)).normalized; string value = ((flag && (Object)(object)weapon._impactTargetInstance == (Object)null) ? LaunchCheck(weapon, text, _launchDir) : ""); View view = Decision.Choose(flag, Plugin.FullScreenWhen.Value, Plugin.WindowWhen.Value, p, Plugin.SkipMisses.Value, Plugin.MinDistanceMetres.Value, Plugin.FollowEveryShot.Value); string text2 = (ModLog.Full ? $"Shot: {text} ({((Object)weapon).name}, {(((Object)(object)rangedWeaponController != (Object)null) ? ((MemberInfo)((Object)rangedWeaponController).GetIl2CppType()).Name : "no ranged controller")}), followed={flag}{Plugin.ChosenWhy(text)}, prediction known={p.Known} hits={p.HitsSomething} creature={p.HitsCreature} distance={p.ImpactDistance:F0} m{value} -> {view}" : null); Vector3? shotPredicted = ((p.HitsSomething && !p.HitsCreature && _impactKnown) ? new Vector3?(_impact) : ((Vector3?)null)); if (view != View.None) { RangedWeaponController controller = rangedWeaponController; LayerMask hitMask = weapon.GetHitMask(); StartView(lastFiredProjectile, view, text, controller, ((LayerMask)(ref hitMask)).value, text2); _shotPredicted = shotPredicted; } else if (text2 != null) { ModLog.Trace(text2 + ": " + NoViewWhy(flag, p)); } } } [HideFromIl2Cpp] private static string NoViewWhy(bool chosen, Prediction p) { if (chosen) { if (!Plugin.FollowEveryShot.Value && Decision.Skip(p, Plugin.SkipMisses.Value, Plugin.MinDistanceMetres.Value)) { if (!p.HitsSomething) { return "its predicted path hits nothing ([Skip] SkipMisses)"; } return "it lands closer than [Skip] MinDistanceMetres"; } return "no view set for it (Never, or AimedAtCreature and no creature aimed at)"; } if (!Plugin.Enabled.Value) { return "the mod is off"; } return "its [Weapons] box is off"; } private static string ItemName(RangedWeapon w) { ItemData itemData = w.ItemData; return Decision.BoxKey(((Object)(object)itemData != (Object)null) ? itemData._name : ((Object)((Component)w).gameObject).name); } [HideFromIl2Cpp] private Prediction Predict(RangedWeapon weapon, bool aiming) { //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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_0067: 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_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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) //IL_010d: Unknown result type (might be due to invalid IL or missing references) _impactKnown = false; Ammo ammo = weapon.GetAmmo(); Transform physicalSpawnPoint = ((Weapon)weapon).physicalSpawnPoint; if (ammo != null && (Object)(object)ammo._properties != (Object)null && (Object)(object)physicalSpawnPoint != (Object)null) { weapon._simulatedBulletInfo = (BulletInfo)(object)ammo._properties.ProjectileInfo; Vector3 start; Vector3 dir; TrajectoryData val; if (aiming) { _previewFrom = PreviewStart(weapon, physicalSpawnPoint, out start, out dir, out var gamePath); val = gamePath ?? weapon.SimulateTrajectory(start, dir); } else { weapon.SimulateTrajectory(); start = physicalSpawnPoint.position; dir = physicalSpawnPoint.forward; val = weapon.SimulateTrajectory(start, dir); } if (!val.surfaceImpactDetected) { return new Prediction(known: true, hitsSomething: false, hitsCreature: false, 0f); } List<Vector3> arcPoints = val.arcPoints; int count = arcPoints.Count; Vector3 incoming; if (count < 2) { incoming = dir; } else { Vector3 val2 = arcPoints[count - 1] - arcPoints[count - 2]; incoming = ((Vector3)(ref val2)).normalized; } _incoming = incoming; RaycastHit rayHit = val.resultingSurfaceImpactInfo.rayHit; return Landing(((RaycastHit)(ref rayHit)).point, ((RaycastHit)(ref rayHit)).collider, start); } Camera main = Camera.main; if ((Object)(object)main != (Object)null) { Transform transform = ((Component)main).transform; Vector3 position = transform.position; Vector3 forward = transform.forward; float value = Plugin.CreatureCheckMetres.Value; LayerMask hitMask = weapon.GetHitMask(); RaycastHit val3 = default(RaycastHit); if (Physics.Raycast(position, forward, ref val3, value, ((LayerMask)(ref hitMask)).value)) { _incoming = transform.forward; return Landing(((RaycastHit)(ref val3)).point, ((RaycastHit)(ref val3)).collider, transform.position); } } return new Prediction(known: false, hitsSomething: false, hitsCreature: false, 0f); } [HideFromIl2Cpp] private LaunchFrom PreviewStart(RangedWeapon weapon, Transform spawn, out Vector3 start, out Vector3 dir, out TrajectoryData gamePath) { //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: 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_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_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: 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_008b: Unknown result type (might be due to invalid IL or missing references) LaunchFrom launchFrom = Launch.From((Object)(object)spawn == (Object)(object)weapon._projectilePhysicalSpawnPoint, weapon.HasLaserSight(), weapon._useModifiedScreenPostion, weapon.IsAiming, weapon._isLocalPlayer); TrajectoryData val = weapon.SimulateTrajectory(); gamePath = null; Transform val2 = spawn; switch (launchFrom) { case LaunchFrom.GameScreenAim: { List<Vector3> arcPoints = val.arcPoints; if (arcPoints != null && arcPoints.Count >= 2) { start = arcPoints[0]; Vector3 val3 = arcPoints[1] - arcPoints[0]; dir = ((Vector3)(ref val3)).normalized; gamePath = val; return launchFrom; } break; } case LaunchFrom.ProjectilePose: val2 = weapon.GetProjectileTransform() ?? spawn; break; case LaunchFrom.AimTransform: val2 = (((Object)(object)weapon._aimTransform != (Object)null) ? weapon._aimTransform : weapon._projectileTransform); if ((Object)(object)val2 == (Object)null) { val2 = spawn; } break; } start = val2.position; dir = val2.forward; return launchFrom; } [HideFromIl2Cpp] private string LaunchCheck(RangedWeapon weapon, string item, Vector3 real) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) Transform physicalSpawnPoint = ((Weapon)weapon).physicalSpawnPoint; if ((Object)(object)physicalSpawnPoint == (Object)null || ((Vector3)(ref real)).sqrMagnitude < 0.5f) { return ""; } Vector3 start; Vector3 dir; TrajectoryData gamePath; LaunchFrom launchFrom = PreviewStart(weapon, physicalSpawnPoint, out start, out dir, out gamePath); float num = Launch.AngleDegrees(dir.x, dir.y, dir.z, real.x, real.y, real.z); if (Launch.PreviewMissed(num)) { ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(82, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": the aim preview's start ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<LaunchFrom>(launchFrom); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") is "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(num, "F1"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("° off the real shot: the preview looked elsewhere."); } logger.LogWarning(val); } Camera main = Camera.main; if (!ModLog.Full) { return ""; } return $", launched {(((Object)(object)main != (Object)null) ? Vector3.Angle(real, ((Component)main).transform.forward) : (-1f)):F1}° from the camera's aim, preview start {launchFrom} {num:F1}° off"; } [HideFromIl2Cpp] private Prediction Landing(Vector3 point, Collider collider, Vector3 from) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) _impactKnown = true; _impact = point; bool hitsCreature = (Object)(object)collider != (Object)null && (Object)(object)((Component)collider).GetComponentInParent<VailActor>() != (Object)null; return new Prediction(known: true, hitsSomething: true, hitsCreature, Vector3.Distance(from, point)); } [HideFromIl2Cpp] private void StartView(Bullet b, View view, string item, RangedWeaponController controller, int wallMask, string shot) { //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) EndView("a new shot is followed"); if (!PrepareCamera(view, Plugin.FieldOfView.Value)) { if (shot != null) { ModLog.Trace(shot + ": not opened, no player camera"); } return; } _view = view; _item = item; _bullet = b; _bulletObject = ((Component)b).gameObject; _bulletTransform = ((Component)b).transform; _stillFrames = 0; _gameRides = 0; _lateRides = 0; _bulletId = b.Id; _controller = controller; _wallMask = wallMask; _health = (((Object)(object)LocalPlayer.Vitals != (Object)null) ? LocalPlayer.Vitals.Health : null); _lastHealth = ((_health != null) ? ((Stat)_health)._currentValue : 0f); _wasAiming = (Object)(object)controller != (Object)null && controller.IsAiming; _aimHeld = HeldAimed(); if (shot != null) { Rigidbody componentInChildren = _bulletObject.GetComponentInChildren<Rigidbody>(); ModLog.Trace($"{shot}: opened; projectile {(((Object)(object)componentInChildren == (Object)null) ? "without Rigidbody" : $"Rigidbody kinematic={componentInChildren.isKinematic}, interpolation={componentInChildren.interpolation}")}, forward axis {(((Object)(object)Camera.main != (Object)null) ? Vector3.Angle(_bulletTransform.forward, ((Component)Camera.main).transform.forward) : (-1f)):F0}° from the aim (above a few degrees it tumbles or flies sideways), still aimed as it left={_aimHeld}"); } _lastPos = _bulletTransform.position; _dir = ((((Vector3)(ref _launchDir)).sqrMagnitude > 0.5f) ? _launchDir : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.forward : _bulletTransform.forward)); _still = 0f; _timer = 0f; _phase = Phase.Riding; _snap = true; Place(0f); _shown = false; Show(shown: true); } [HideFromIl2Cpp] private bool PrepareCamera(View view, float fov) { //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) Camera main = Camera.main; if ((Object)(object)main == (Object)null) { return false; } if ((Object)(object)_cam == (Object)null) { Build(); } _cam.CopyFrom(main); if (fov > 0f && fov < 180f) { _cam.fieldOfView = fov; } else { ModLog.Once($"fov {fov}", $"Field of view {fov} refused (must be between 0 and 180 degrees): using your own view's angle", (LogLevel)4); } _cam.depth = main.depth - 1f; HDAdditionalCameraData component = ((Component)main).GetComponent<HDAdditionalCameraData>(); if ((Object)(object)component != (Object)null) { component.CopyTo(_hd); } if (!_upscalerLogged) { ModLog.Trace($"Upscaler turned off for the projectile camera (player's view: dynamic resolution {main.allowDynamicResolution}/{(Object)(object)component != (Object)null && component.allowDynamicResolution}, DLSS {(Object)(object)component != (Object)null && component.allowDeepLearningSuperSampling})"); } _upscalerLogged = true; _cam.allowDynamicResolution = false; _hd.allowDynamicResolution = false; _hd.allowDeepLearningSuperSampling = false; if (Plugin.LightRendering.Value) { TurnOffCostlyEffects(); } Layout(view); _cam.targetTexture = _rt; _image.texture = (Texture)(object)_rt; _frameColour = FrameColour(); SetAlpha(1f); _frames = 0; _frameSum = 0f; _codeTicks = 0L; _baseFrameMs = Time.smoothDeltaTime * 1000f; return true; } private void PreviewTick() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0196: 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_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: 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) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0205: 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_0224: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_033b: Unknown result type (might be due to invalid IL or missing references) //IL_03d5: Unknown result type (might be due to invalid IL or missing references) //IL_03db: Unknown result type (might be due to invalid IL or missing references) if (_phase == Phase.Preview) { float num = Decision.SmoothStep(Plugin.Smoothing.Value, Time.deltaTime); _camTransform.SetPositionAndRotation(Vector3.Lerp(_camTransform.position, _previewPos, num), Quaternion.Slerp(_camTransform.rotation, _previewRot, num)); int value = Plugin.PreviewRenderEveryFrames.Value; ((Behaviour)_cam).enabled = value <= 1 || Time.frameCount % value == 0; _frames++; _frameSum += Time.unscaledDeltaTime; FirstFrames("aim preview"); } if (Time.unscaledTime < _nextPreview) { return; } _nextPreview = Time.unscaledTime + Plugin.PreviewUpdateSeconds.Value; if (!_boxesMade) { _boxesMade = Plugin.BoxRangedItems(); } bool flag = HeldAimed(); if (!flag || !PredictionWanted()) { bool flag2 = ModLog.Changed(_heldId, "preview", _noPreview.GetHashCode()); if (_phase == Phase.Preview) { EndView(_noPreview); } else if (flag && flag2) { ModLog.Trace("Aim preview not opened for " + _heldItem + ": " + _noPreview); } return; } ModLog.Changed(_heldId, "preview", 0); Vector3 val = _impact - _incoming * Plugin.PreviewDistance.Value + Vector3.up * Plugin.PreviewHeight.Value; Vector3 val2 = _impact + Vector3.up * 0.2f; Vector3 val3 = val - val2; float magnitude = ((Vector3)(ref val3)).magnitude; string text = null; RaycastHit val4 = default(RaycastHit); if (Plugin.AvoidWalls.Value && magnitude > 0.001f && Physics.SphereCast(val2, 0.2f, val3 / magnitude, ref val4, magnitude, _wallMask)) { val = val2 + val3 / magnitude * Mathf.Max(((RaycastHit)(ref val4)).distance - 0.1f, 0f); text = ((ModLog.Full && (Object)(object)((RaycastHit)(ref val4)).collider != (Object)null) ? ((Object)((RaycastHit)(ref val4)).collider).name : "a wall"); } _previewPos = val; Vector3 val5 = _impact - val; _previewRot = Quaternion.LookRotation((((Vector3)(ref val5)).sqrMagnitude > 1E-06f) ? val5 : _incoming); string text2 = ((ModLog.Full && (_phase != Phase.Preview || text != _previewCutBy)) ? PreviewSight(val, text) : null); _previewCutBy = text; if (_phase != Phase.Preview) { if (!PrepareCamera(View.Window, Plugin.PreviewFieldOfView.Value)) { if (ModLog.Changed(_heldId, "preview camera", 0)) { ModLog.Trace("Aim preview not opened for " + _heldItem + ": no player camera"); } return; } _phase = Phase.Preview; _view = View.Window; _item = _heldItem; _camTransform.SetPositionAndRotation(_previewPos, _previewRot); _shown = false; Show(shown: true); if (text2 != null) { ModLog.Trace($"Aim preview opened: {_heldItem}{Plugin.ChosenWhy(_heldItem)}, start {(_heldGameLanding ? "the game's own target" : _previewFrom.ToString())}, landing {Vector3.Distance(LocalPlayer.Transform.position, _impact):F0} m away; {text2}"); } } else if (text2 != null) { ModLog.Trace("Aim preview of " + _heldItem + " moved: " + text2); } } [HideFromIl2Cpp] private string PreviewSight(Vector3 camPos, string cutBy) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000d: 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_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) float num = Vector3.Distance(camPos, _impact); RaycastHit val = default(RaycastHit); string value = (Physics.Linecast(camPos, _impact, ref val, -1, (QueryTriggerInteraction)1) ? $"{(((Object)(object)((RaycastHit)(ref val)).collider != (Object)null) ? ((Object)((RaycastHit)(ref val)).collider).name : "?")} (layer {(((Object)(object)((RaycastHit)(ref val)).collider != (Object)null) ? ((Component)((RaycastHit)(ref val)).collider).gameObject.layer : (-1))}), {Vector3.Distance(((RaycastHit)(ref val)).point, _impact):F2} m before the landing" : "nothing"); return $"camera {num:F1} m from the landing{((num <= 0.4f) ? " (pulled onto it: the landing is at or behind the camera)" : "")}, pulled in by a wall: {cutBy ?? "no"}, first thing on the line of sight: {value}"; } [HideFromIl2Cpp] private bool No(string why) { _noPreview = why; return false; } private static bool Aimed(RangedWeaponController c, bool bow) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Invalid comparison between Unknown and I4 if (!bow) { return c.IsAiming; } if (c._isCharging) { return (int)c._attackState == 2; } return false; } private bool HeldAimed() { if (Plugin.PreviewWhen.Value == When.Never || !Plugin.Enabled.Value) { return No("off in the settings (PreviewWhen Never, or the mod off)"); } if (!LocalPlayer.IsInWorld || PauseMenu.IsActive || LocalPlayer.IsInInventory) { return No("a menu or the backpack is open"); } ItemInstance rightHandItem = LocalPlayer.Inventory.RightHandItem; GameObject val = ((rightHandItem != null) ? rightHandItem.ItemObject : null); int num = ((!((Object)(object)val == (Object)null)) ? ((Object)val).GetInstanceID() : 0); if (num != _heldId) { _heldId = num; _heldSince = Time.unscaledTime; _heldWeapon = (((Object)(object)val == (Object)null) ? null : val.GetComponentInChildren<RangedWeapon>(true)); _heldController = null; _heldBow = false; _heldItem = (((Object)(object)_heldWeapon == (Object)null) ? null : ItemName(_heldWeapon)); } if ((Object)(object)_heldWeapon == (Object)null) { return No("no ranged weapon in hand"); } if ((Object)(object)_heldController == (Object)null && Time.unscaledTime - _heldSince <= 3f) { _heldController = val.GetComponentInChildren<RangedWeaponController>(true); _heldBow = (Object)(object)_heldController != (Object)null && (Object)(object)((Il2CppObjectBase)_heldController).TryCast<BowWeaponController>() != (Object)null; } GameObject impactTargetInstance = _heldWeapon._impactTargetInstance; _heldGameLanding = (Object)(object)impactTargetInstance != (Object)null && impactTargetInstance.activeInHierarchy; if (!_heldGameLanding && ((Object)(object)_heldController == (Object)null || !Aimed(_heldController, _heldBow))) { return No("not aimed"); } if (!Plugin.IsChosen(_heldItem)) { return No("its [Weapons] box is off"); } return true; } [HideFromIl2Cpp] private Prediction GameLanding(RangedWeapon weapon, int mask) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_005a: 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_0068: 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //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) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0089: 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_00a5: Unknown result type (might be due to invalid IL or missing references) Vector3 position = weapon._impactTargetInstance.transform.position; LineRenderer trajectoryPathInstance = weapon._trajectoryPathInstance; int num = (((Object)(object)trajectoryPathInstance != (Object)null) ? trajectoryPathInstance.positionCount : 0); Vector3 position2 = LocalPlayer.Transform.position; Vector3 val; Vector3 normalized; if (num < 2) { val = position - position2; normalized = ((Vector3)(ref val)).normalized; } else { val = trajectoryPathInstance.GetPosition(num - 1) - trajectoryPathInstance.GetPosition(num - 2); normalized = ((Vector3)(ref val)).normalized; } _incoming = normalized; RaycastHit val2 = default(RaycastHit); Physics.Raycast(position - _incoming * 0.2f, _incoming, ref val2, 0.4f, mask); return Landing(position, ((RaycastHit)(ref val2)).collider, position2); } private bool PredictionWanted() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) LayerMask hitMask = _heldWeapon.GetHitMask(); _wallMask = ((LayerMask)(ref hitMask)).value; Prediction p = (_heldGameLanding ? GameLanding(_heldWeapon, _wallMask) : Predict(_heldWeapon, aiming: true)); if (!_impactKnown) { return No("no landing predicted (no ammo, or the path hits nothing in range)"); } if (Decision.Choose(weaponChosen: true, When.Never, Plugin.PreviewWhen.Value, p, Plugin.SkipMisses.Value, Plugin.MinDistanceMetres.Value, Plugin.FollowEveryShot.Value) != View.Window) { return No(NoViewWhy(chosen: true, p)); } return true; } private void Follow() { if ((Object)(object)LocalPlayer.Inventory == (Object)null) { EndView("left the game"); return; } bool flag = (_covered = PauseMenu.IsActive || !LocalPlayer.IsInWorld); if (flag && _view == View.FullScreen) { EndView("a menu or the backpack opened"); return; } if (flag == _shown) { ModLog.Trace($"{_item}: {_view} view {(flag ? "hidden behind a menu or the backpack" : "shown again")}"); } Show(!flag); if (flag) { return; } float num = ((_health != null) ? ((Stat)_health)._currentValue : _lastHealth); bool flag2 = (Object)(object)_controller != (Object)null && _controller.IsAiming; bool flag3 = _health != null && num <= 0f; bool flag4 = num < _lastHealth; bool num2 = Decision.LeaveEarly(_view, flag3, flag4, flag2 && !_wasAiming); _lastHealth = num; _wasAiming = flag2; if (num2) { EndView(flag3 ? "you died" : (flag4 ? "you lost health" : "you aimed again")); } else { if (AimTakesOver()) { return; } float deltaTime = Time.deltaTime; _timer += deltaTime; _frames++; _frameSum += Time.unscaledDeltaTime; FirstFrames(_view.ToString() + " view"); switch (_phase) { case Phase.Riding: if (_rodeFrame != Time.frameCount && _bulletsFrame < Time.frameCount - 1) { _lateRides++; Ride(deltaTime); } break; case Phase.Lingering: if (!(_timer < Plugin.LingerSeconds.Value)) { ((Behaviour)_cam).enabled = false; _phase = Phase.Fading; _timer = 0f; } break; case Phase.Fading: { float value = Plugin.FadeSeconds.Value; if (_timer >= value) { EndView("faded out after the impact"); } else { SetAlpha(1f - _timer / value); } break; } } } } private bool AimTakesOver() { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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_0088: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.PreviewTakesOver.Value || Time.unscaledTime < _nextPreview) { return false; } _nextPreview = Time.unscaledTime + Plugin.PreviewUpdateSeconds.Value; if (!HeldAimed()) { _aimHeld = false; return false; } if (_aimHeld) { return false; } bool impactKnown = _impactKnown; Vector3 impact = _impact; Vector3 incoming = _incoming; int wallMask = _wallMask; Vector3 val = incoming; Vector3 val2 = impact; bool flag = impactKnown; if (!PredictionWanted()) { bool impactKnown2 = flag; Vector3 impact2 = val2; Vector3 incoming2 = val; int wallMask2 = wallMask; _impactKnown = impactKnown2; _impact = impact2; _incoming = incoming2; _wallMask = wallMask2; if (ModLog.Changed(_bulletId, "takeover", _noPreview.GetHashCode())) { ModLog.Trace($"{_item}: aimed again during the {_view} view ({_phase}), the view is kept: no aim preview, {_noPreview}"); } return false; } EndView($"aimed again during the {_phase} phase: the aim preview takes over"); _nextPreview = 0f; PreviewTick(); return true; } [HideFromIl2Cpp] private string LandedWhy() { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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) //IL_0080: 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_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_bullet == (Object)null || (Object)(object)_bulletTransform == (Object)null) { return "projectile gone (recycled by the game)"; } if (!_bulletObject.activeInHierarchy) { return "projectile hidden by the game"; } if (_bullet.Id != _bulletId) { return "projectile reused for another shot"; } if (_timer > Plugin.MaxFlightSeconds.Value) { return "flight longer than [Camera] MaxFlightSeconds"; } Vector3 position = _bulletTransform.position; Vector3 val = position - _lastPos; _lastPos = position; if (((Vector3)(ref val)).sqrMagnitude <= 1E-06f) { _stillFrames++; } if (((Vector3)(ref val)).sqrMagnitude > 1E-06f) { _dir = ((Vector3)(ref val)).normalized; _still = 0f; return null; } _still += Time.deltaTime; if (!(_still > 0.15f)) { return null; } return "projectile stopped moving (stuck in something)"; } private void Place(float dt) { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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_007c: 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_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_0096: 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) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //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_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_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0122: 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_012c: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: 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_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_017a: 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_0187: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0220: 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) Framing value = Plugin.CameraFraming.Value; if (value == Framing.Ride) { Quaternion val = Quaternion.LookRotation(_dir, Vector3.up); _camTransform.SetPositionAndRotation(_lastPos + val * new Vector3(0f, Plugin.Height.Value, 0f - Plugin.Distance.Value), val); _snap = false; return; } Vector3 val2 = Vector3.up * Plugin.Height.Value; Vector3 val3 = -_dir * Plugin.Distance.Value + val2; if (value == Framing.Side) { Vector3 val4 = Vector3.Cross(Vector3.up, _dir); val4 = ((((Vector3)(ref val4)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val4)).normalized : Vector3.right); val3 += val4 * Plugin.SideMetres.Value; } float num = (_snap ? 1f : Decision.SmoothStep(Plugin.Smoothing.Value, dt)); _offset = Vector3.Lerp(_offset, val3, num); Vector3 val5 = _lastPos + _offset; float magnitude = ((Vector3)(ref _offset)).magnitude; RaycastHit val6 = default(RaycastHit); if (Plugin.AvoidWalls.Value && magnitude > 0.001f && Physics.SphereCast(_lastPos, 0.2f, _offset / magnitude, ref val6, magnitude, _wallMask)) { val5 = _lastPos + _offset / magnitude * Mathf.Max(((RaycastHit)(ref val6)).distance - 0.1f, 0f); } Vector3 val7 = ((value == Framing.Side) ? (_lastPos - val5) : _dir); if (value != Framing.Behind && _impactKnown) { float num2 = Decision.TurnBlend(Vector3.Distance(_lastPos, _impact), Plugin.TurnMetres.Value); if (num2 > 0f) { Vector3 normalized = ((Vector3)(ref val7)).normalized; Vector3 val8 = _impact - val5; val7 = Vector3.Slerp(normalized, ((Vector3)(ref val8)).normalized, num2); } } if (((Vector3)(ref val7)).sqrMagnitude < 1E-06f) { val7 = _dir; } _rotation = Quaternion.Slerp(_rotation, Quaternion.LookRotation(val7), num); _camTransform.SetPositionAndRotation(val5, _rotation); _snap = false; } [HideFromIl2Cpp] private void FirstFrames(string what) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown if (_frames < 2 || _frames > 3) { return; } if (Time.unscaledDeltaTime > 0.1f) { ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(54, 5, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(_item); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(what); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": frame "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_frames); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" took "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(Time.unscaledDeltaTime * 1000f, "F0"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ms as the camera appeared (usual "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(_baseFrameMs, "F0"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ms)."); } logger.LogWarning(val); } if (_frames == 2 && (_cam.allowDynamicResolution || _hd.allowDynamicResolution || _hd.allowDeepLearningSuperSampling)) { ModLog.Once("upscaler back", "Projectile camera: the player's upscaler (dynamic resolution or DLSS) is on again: the window may show black with the image in a corner.", (LogLevel)4); } } [HideFromIl2Cpp] private void EndView(string why) { //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Expected O, but got Unknown if (_phase != Phase.Idle && ModLog.Full) { int num = Math.Max(_frames, 1); ModLog.Trace($"{_item} {((_phase == Phase.Preview) ? "aim preview" : (_view.ToString() + " view"))} closed: {why}; {_frames} frames, frame time {_baseFrameMs:F1} ms before, {_frameSum * 1000f / (float)num:F1} ms during, mod code {(double)_codeTicks * 1000000.0 / (double)Stopwatch.Frequency / (double)num:F0} µs per frame" + ((_phase == Phase.Preview) ? "" : $", {_stillFrames} frames where the projectile did not move, camera placed right after the game moved the projectile on {_gameRides} flight frames, by our LateUpdate fallback on {_lateRides}")); } if (_phase != Phase.Idle && _phase != Phase.Preview && _gameRides == 0 && _lateRides > 0) { ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(121, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(_item); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<View>(_view); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" view: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_lateRides); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" flight frames placed by our LateUpdate fallback, none right after the game moved the projectile: it may stutter."); } logger.LogWarning(val); } _phase = Phase.Idle; _bullet = null; _bulletObject = null; _bulletTransform = null; _controller = null; _health = null; if ((Object)(object)_cam != (Object)null) { ((Behaviour)_cam).enabled = false; } if ((Object)(object)_ui != (Object)null) { _ui.SetActive(false); } _shown = false; } private void Show(bool shown) { if (shown != _shown) { _shown = shown; _ui.SetActive(shown); ((Behaviour)_cam).enabled = shown && _phase != Phase.Fading; } } private void SetAlpha(float a) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_0039: Unknown result type (might be due to invalid IL or missing references) Color color = ((Graphic)_image).color; color.a = a; ((Graphic)_image).color = color; Color frameColour = _frameColour; frameColour.a *= a; ((Graphic)_frame).color = frameColour; } private static Color FrameColour() { //IL_0048: 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) Color result = default(Color); if (ColorUtility.TryParseHtmlString(Plugin.FrameColor.Value, ref result)) { return result; } ModLog.Once("frame colour " + Plugin.FrameColor.Value, "[Window] FrameColor \"" + Plugin.FrameColor.Value + "\" refused (not #RRGGBB or #RRGGBBAA): black frame", (LogLevel)4); return Color.black; } [HideFromIl2Cpp] private void Layout(View view) { //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: 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_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) int val; int val2; if (view == View.FullScreen) { Stretch(_frameRect, 0); Stretch(_imageRect, 0); ((Behaviour)_frame).enabled = false; float value = Plugin.FullScreenResolution.Value; val = (int)((float)Screen.width * value); val2 = (int)((float)Screen.height * value); } else { int value2 = Plugin.FrameThickness.Value; Corner value3 = Plugin.WindowCorner.Value; bool flag = ((value3 == Corner.TopRight || value3 == Corner.BottomRight) ? true : false); float num = (flag ? 1f : 0f); bool flag2 = (uint)value3 <= 1u; Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(num, flag2 ? 1f : 0f); RectTransform frameRect = _frameRect; RectTransform frameRect2 = _frameRect; Vector2 val4 = (_frameRect.pivot = val3); Vector2 anchorMin = (frameRect2.anchorMax = val4); frameRect.anchorMin = anchorMin; _frameRect.sizeDelta = new Vector2((float)(Plugin.WindowWidth.Value + 2 * value2), (float)(Plugin.WindowHeight.Value + 2 * value2)); _frameRect.anchoredPosition = new Vector2((float)((val3.x > 0f) ? (-Plugin.MarginX.Value) : Plugin.MarginX.Value), (float)((val3.y > 0f) ? (-Plugin.MarginY.Value) : Plugin.MarginY.Value)); Stretch(_imageRect, value2); ((Behaviour)_frame).enabled = value2 > 0; float num2 = Plugin.WindowResolution.Value * (float)Screen.height / 1080f; val = (int)((float)Plugin.WindowWidth.Value * num2); val2 = (int)((float)Plugin.WindowHeight.Value * num2); } val = Math.Max(val, 16); val2 = Math.Max(val2, 16); if (!((Object)(object)_rt != (Object)null) || ((Texture)_rt).width != val || ((Texture)_rt).height != val2) { if ((Object)(object)_rt != (Object)null) { _cam.targetTexture = null; _rt.Release(); Object.Destroy((Object)(object)_rt); } _rt = new RenderTexture(val, val2, 24) { name = "ProjectileCam.Texture" }; _rt.Create(); } } private static void Stretch(RectTransform r, int inset) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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_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_004c: Unknown result type (might be due to invalid IL or missing references) r.anchorMin = Vector2.zero; r.anchorMax = Vector2.one; r.pivot = new Vector2(0.5f, 0.5f); r.anchoredPosition = Vector2.zero; r.offsetMin = new Vector2((float)inset, (float)inset); r.offsetMax = new Vector2((float)(-inset), (float)(-inset)); } private void TurnOffCostlyEffects() { //IL_0012: 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_0018: Unknown result type (might be due to invalid IL or missing references) //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_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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_003f: 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_004b: Expected I4, but got Unknown //IL_004d: 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_0065: 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) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) try { _hd.customRenderingSettings = true; FrameSettingsOverrideMask renderingPathCustomFrameSettingsOverrideMask = _hd.renderingPathCustomFrameSettingsOverrideMask; BitArray128 mask = renderingPathCustomFrameSettingsOverrideMask.mask; FrameSettings renderingPathCustomFrameSettings = _hd.renderingPathCustomFrameSettings; FrameSettingsField[] costlyEffects = CostlyEffects; foreach (FrameSettingsField val in costlyEffects) { ((BitArray128)(ref mask))[(uint)(int)val] = true; ((FrameSettings)(ref renderingPathCustomFrameSettings)).SetEnabled(val, false); } renderingPathCustomFrameSettingsOverrideMask.mask = mask; _hd.renderingPathCustomFrameSettingsOverrideMask = renderingPathCustomFrameSettingsOverrideMask; _hd.renderingPathCustomFrameSettings = renderingPathCustomFrameSettings; } catch (Exception ex) { if (!_costlyWarned) { ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(41, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Could not lighten the projectile camera: "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message); } logger.LogWarning(val2); } _costlyWarned = true; } } private void Build() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Expected O, but got Unknown //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Expected O, but got Unknown GameObject val = new GameObject("ProjectileCam.Camera"); Object.DontDestroyOnLoad((Object)(object)val); _cam = val.AddComponent<Camera>(); ((Behaviour)_cam).enabled = false; _camTransform = val.transform; _hd = val.AddComponent<HDAdditionalCameraData>(); _hd.hasPersistentHistory = true; _ui = new GameObject("ProjectileCam.Ui"); Object.DontDestroyOnLoad((Object)(object)_ui); Canvas obj = _ui.AddComponent<Canvas>(); obj.renderMode = (RenderMode)0; obj.sortingOrder = 500; CanvasScaler obj2 = _ui.AddComponent<CanvasScaler>(); obj2.uiScaleMode = (ScaleMode)1; obj2.referenceResolution = new Vector2(1920f, 1080f); obj2.matchWidthOrHeight = 1f; GameObject val2 = new GameObject("Frame"); val2.transform.SetParent(_ui.transform, false); _frameRect = val2.AddComponent<RectTransform>(); _frame = val2.AddComponent<Image>(); ((Graphic)_frame).raycastTarget = false; GameObject val3 = new GameObject("View"); val3.transform.SetParent(val2.transform, false); _imageRect = val3.AddComponent<RectTransform>(); _image = val3.AddComponent<RawImage>(); ((Graphic)_image).raycastTarget = false; _ui.SetActive(false); ModLog.Trace("Projectile camera built"); } static CamWatcher() { FrameSettingsField[] array = new FrameSettingsField[10]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); CostlyEffects = (FrameSettingsField[])(object)array; } } [BepInPlugin("aznan.sotf.projectilecam", "ProjectileCam", "0.1.34")] public class Plugin : BasePlugin { internal const string Version = "0.1.34"; internal static ManualLogSource Logger; private static readonly Dictionary<string, ConfigEntry<bool>> Chosen = new Dictionary<string, ConfigEntry<bool>>(); private static ConfigFile _config; internal static ConfigEntry<When> FullScreenWhen; internal static ConfigEntry<When> WindowWhen; internal static ConfigEntry<When> PreviewWhen; internal static ConfigEntry<Corner> WindowCorner; internal static ConfigEntry<Framing> CameraFraming; internal static ConfigEntry<int> PreviewRenderEveryFrames; internal static ConfigEntry<int> WindowWidth; internal static ConfigEntry<int> WindowHeight; internal static ConfigEntry<int> MarginX; internal static ConfigEntry<int> MarginY; internal static ConfigEntry<int> FrameThickness; internal static ConfigEntry<string> FrameColor; internal static ConfigEntry<float> FieldOfView; internal static ConfigEntry<float> Distance; internal static ConfigEntry<float> Height; internal static ConfigEntry<float> LingerSeconds; internal static ConfigEntry<float> FadeSeconds; internal static ConfigEntry<float> MaxFlightSeconds; internal static ConfigEntry<float> CreatureCheckMetres; internal static ConfigEntry<float> PreviewDistance; internal static ConfigEntry<float> PreviewHeight; internal static ConfigEntry<float> PreviewFieldOfView; internal static ConfigEntry<float> PreviewUpdateSeconds; internal static ConfigEntry<float> WindowResolution; internal static ConfigEntry<float> FullScreenResolution; internal static ConfigEntry<float> TurnMetres; internal static ConfigEntry<float> SideMetres; internal static ConfigEntry<float> Smoothing; internal static ConfigEntry<float> MinDistanceMetres; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> FollowEveryShot; internal static ConfigEntry<bool> LightRendering; internal static ConfigEntry<bool> AvoidWalls; internal static ConfigEntry<bool> SkipMisses; internal static ConfigEntry<bool> FullLogging; internal static ConfigEntry<bool> PreviewTakesOver; private static readonly string GunsMarker = Path.Combine(Paths.ConfigPath, "aznan.sotf.projectilecam.guns-0.1.27.done"); private static bool? _gunsMigrated; private static Dictionary<string, string> _oldBoxes; internal static bool IsChosen(string item) { if (Enabled.Value) { if (!FollowEveryShot.Value) { return Box(item).Value; } return true; } return false; } internal static string ChosenWhy(string item) { if (!FollowEveryShot.Value || Box(item).Value) { return ""; } return " (FollowEveryShot on, its [Weapons] box is off)"; } internal static ConfigEntry<bool> Box(string item, int id = 0) { //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Expected O, but got Unknown if (Chosen.TryGetValue(item, out var value)) { return value; } bool saveOnConfigSet = _config.SaveOnConfigSet; _config.SaveOnConfigSet = false; try { string text = FileValue(_config, "Weapons", item); bool flag = Decision.OnByDefault(item); value = _config.Bind<bool>("Weapons", item, flag, $"Follow the projectiles of this item ({item}{((id != 0) ? $", item id {id}" : "")}) and show its aim preview. Default {(flag ? "true" : "false: guns are off by default, the rope gun excepted")}."); string text2 = text ?? OldValue(Decision.OldBox(item)); if (text2 != null) { ((ConfigEntryBase)value).SetSerializedValue(text2); } if (text2 != null && value.Value && !GunsMigrated() && Array.IndexOf(Decision.GunsOffSince0127, item) >= 0) { value.Value = false; ManualLogSource logger = Logger; bool flag2 = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(64, 1, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Weapons] "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": off, the new default (was still on, the old default)"); } logger.LogInfo(val); } Chosen[item] = value; _config.Save(); ModLog.Trace($"[Weapons] {item}: box made, {value.Value} ({((text != null) ? "from the file" : ((text2 != null) ? "from its 0.1.23 family box" : "default"))})"); return value; } finally { _config.SaveOnConfigSet = saveOnConfigSet; } } internal static bool BoxRangedItems() { //IL_003a: 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 ((Object)(object)ItemDatabaseManager._instance == (Object)null) { return false; } List<ItemData> items = ItemDatabaseManager.Items; if (items == null || items.Count == 0) { return false; } int num = 0; for (int i = 0; i < items.Count; i++) { ItemData val = items[i]; if (!((Object)(object)val == (Object)null) && (val._type & 0x200) != 0) { Box(Decision.BoxKey(val._name), val._id); num++; } } ModLog.Trace($"[Weapons] {num} ranged items found in the game's item list"); if (!GunsMigrated()) { File.WriteAllText(GunsMarker, "Flare and StunGun boxes moved to their 0.1.27 default (off) once."); } _gunsMigrated = true; return true; } private static string FileValue(ConfigFile config, string section, string key) { ConfigEntry<string> val = config.Bind<string>(section, key, "\u0001", "Probe of an old line."); config.Remove(((ConfigEntryBase)val).Definition); if (!(val.Value == "\u0001")) { return val.Value; } return null; } private static bool GunsMigrated() { bool valueOrDefault = _gunsMigrated == true; if (!_gunsMigrated.HasValue) { valueOrDefault = File.Exists(GunsMarker); _gunsMigrated = valueOrDefault; return valueOrDefault; } return valueOrDefault; } private static string OldValue(string family) { if (_oldBoxes == null) { _oldBoxes = new Dictionary<string, string>(); string[] oldBoxes = Decision.OldBoxes; foreach (string key in oldBoxes) { string text = FileValue(_config, "Weapons", key); if (text != null) { _oldBoxes[key] = text; } } if (!File.Exists(Path.Combine(Paths.ConfigPath, "aznan.sotf.projectilecam.thrown-0.1.22.done")) && _oldBoxes.TryGetValue("Thrown", out var value) && bool.TryParse(value.Trim(), out var result) && !result) { _oldBoxes["Thrown"] = "true"; } } if (family == null || !_oldBoxes.TryGetValue(family, out var value2)) { return null; } return value2; } public override void Load() { //IL_0642: Unknown result type (might be due to invalid IL or missing references) //IL_0648: Expected O, but got Unknown //IL_0674: Unknown result type (might be due to invalid IL or missing references) //IL_067a: Expected O, but got Unknown //IL_05fe: Unknown result type (might be due to invalid IL or missing references) //IL_0603: Unknown result type (might be due to invalid IL or missing references) //IL_0609: Expected O, but got Unknown //IL_0609: Unknown result type (might be due to invalid IL or missing references) //IL_061c: Unknown result type (might be due to invalid IL or missing references) Logger = ((BasePlugin)this).Log; Decision.SelfCheck(); Launch.SelfCheck(); bool num = File.Exists(((BasePlugin)this).Config.ConfigFilePath) && !File.ReadAllText(((BasePlugin)this).Config.ConfigFilePath).Contains("[Debug]"); Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "True = shots of the weapons ticked in [Weapons] (or all weapons with FollowEveryShot) are followed by the camera. False = no camera from this mod."); FullScreenWhen = ((BasePlugin)this).Config.Bind<When>("General", "FullScreenWhen", When.Never, "Which shots take your whole view along with the projectile (it comes back at once if you lose health or aim again). AimedAtCreature = the predicted path hits an animal or enemy."); FollowEveryShot = ((BasePlugin)this).Config.Bind<bool>("General", "FollowEveryShot", false, "True = every shot of every weapon is followed: all conditions are lifted at once (the [Weapons] boxes, shots that hit nothing, shots landing close in [Skip], and AimedAtCreature, which then counts as all shots). FullScreenWhen or WindowWhen set to Never still never opens that view. Default false."); WindowWhen = ((BasePlugin)this).Config.Bind<When>("General", "WindowWhen", When.AllShots, "Which shots open the small window that follows the projectile (when the full-screen view does not already take them)."); PreviewWhen = ((BasePlugin)this).Config.Bind<When>("General", "PreviewWhen", When.AllShots, "While you aim (bow drawn, other weapons aimed), the window shows where the shot will land, seen from where the projectile will come. Never = no preview. AimedAtCreature = only when the predicted landing is on an animal or enemy. AllShots = whenever a landing is predicted. Weapons with the game's own indicator (thrown spear, thrown items, rope gun, flare gun) look at the game's own landing target. Default AllShots."); WindowCorner = ((BasePlugin)this).Config.Bind<Corner>("Window", "Corner", Corner.TopRight, "Screen corner of the window."); WindowWidth = ((BasePlugin)this).Config.Bind<int>("Window", "Width", 384, "Window width, in pixels of a 1080p screen (scales with your resolution). Advised: 64 to 1920."); WindowHeight = ((BasePlugin)this).Config.Bind<int>("Window", "Height", 216, "Window height, in pixels of a 1080p screen. Advised: 36 to 1080."); MarginX = ((BasePlugin)this).Config.Bind<int>("Window", "MarginX", 20, "Gap between the window and the left or right screen edge, in pixels of a 1080p screen. Advised: 0 to 1920."); MarginY = ((BasePlugin)this).Config.Bind<int>("Window", "MarginY", 220, "Gap between the window and the top or bottom screen edge, in pixels of a 1080p screen. Advised: 0 to 1080."); FrameThickness = ((BasePlugin)this).Config.Bind<int>("Window", "FrameThickness", 2, "Frame around the window, in pixels of a 1080p screen (scales with your resolution). 0 = no frame. Advised: 0 to 20."); FrameColor = ((BasePlugin)this).Config.Bind<string>("Window", "FrameColor", "#000000BF", "Frame colour, as #RRGGBB or #RRGGBBAA (the last two digits are opacity)."); CameraFraming = ((BasePlugin)this).Config.Bind<Framing>("Camera", "Framing", Framing.Ride, "Ride (default) = fixed on the projectile, Distance behind and Height above it along its flight, no smoothing (like ArrowCam for Valheim). Chase = behind the projectile, turning to the predicted impact near the end. Side = beside the path, keeping projectile and target in frame. Behind = along the flight only."); TurnMetres = ((BasePlugin)this).Config.Bind<float>("Camera", "TurnMetres", 6f, "Chase: over the last metres before the predicted impact, the camera turns to face it. 0 = never turns. Advised: 0 to 50."); SideMetres = ((BasePlugin)this).Config.Bind<float>("Camera", "SideMetres", 2.5f, "Side: how far beside the path the camera rides, in metres. Advised: 0.5 to 20."); Smoothing = ((BasePlugin)this).Config.Bind<float>("Camera", "Smoothing", 0.08f, "Seconds the camera takes to settle on its new place each moment: higher = smoother, lags more. 0 = no smoothing. Advised: 0 to 1."); AvoidWalls = ((BasePlugin)this).Config.Bind<bool>("Camera", "AvoidWalls", true, "Keep the camera in front of trees, rocks and walls instead of seeing through them."); FieldOfView = ((BasePlugin)this).Config.Bind<float>("Camera", "FieldOfView", 60f, "Field of view of the projectile camera, in degrees. Advised: 20 to 120."); Distance = ((BasePlugin)this).Config.Bind<float>("Camera", "Distance", 0.8f, "How far behind the projectile the camera rides, in metres. Advised: 0 to 10."); Height = ((BasePlugin)this).Config.Bind<float>("Camera", "Height", 0.15f, "How far above the projectile the camera rides, in metres. Advised: -2 to 5."); LingerSeconds = ((BasePlugin)this).Config.Bind<float>("Camera", "LingerSeconds", 1.5f, "Seconds the view stays on the impact before fading. Advised: 0 to 10."); FadeSeconds = ((BasePlugin)this).Config.Bind<float>("Camera", "FadeSeconds", 0.4f, "Seconds the view takes to fade out. Advised: 0 to 5."); MaxFlightSeconds = ((BasePlugin)this).Config.Bind<float>("Camera", "MaxFlightSeconds", 8f, "Longest flight followed; past it the view stops as if the projectile had landed. Advised: 1 to 60."); CreatureCheckMetres = ((BasePlugin)this).Config.Bind<float>("Camera", "CreatureCheckMetres", 150f, "For weapons the game cannot predict (thrown spear): how far the screen centre is checked for what the shot is aimed at. Advised: 5 to 500."); PreviewDistance = ((BasePlugin)this).Config.Bind<float>("Preview", "Distance", 4f, "How far back from the landing point the preview camera stands, along the path the projectile will come by, in metres. Default 4. Advised: 1 to 20."); PreviewHeight = ((BasePlugin)this).Config.Bind<float>("Preview", "Height", 1.5f, "How far above the landing point the preview camera stands, in metres. Default 1.5. Advised: 0 to 10."); PreviewFieldOfView = ((BasePlugin)this).Config.Bind<float>("Preview", "FieldOfView", 50f, "Field of view of the preview camera, in degrees. Default 50. Advised: 20 to 90."); PreviewUpdateSeconds = ((BasePlugin)this).Config.Bind<float>("Preview", "UpdateSeconds", 0.1f, "Seconds between two checks of your aim and of the predicted landing point; the camera glides between them. Lower = follows your aim more closely, costs a little more. Default 0.1. Advised: 0.05 to 0.5."); PreviewTakesOver = ((BasePlugin)this).Config.Bind<bool>("Preview", "TakesOver", true, "True = aiming again while a shot is still followed (window or full screen) switches at once to the aim preview; the followed shot is dropped. A weapon still aimed as its shot leaves (slingshot, crossbow) counts once you aim it again. False = the followed shot keeps the view until it ends, the preview comes after. Default true."); SkipMisses = ((BasePlugin)this).Config.Bind<bool>("Skip", "SkipMisses", true, "No view for a shot whose predicted path hits nothing."); MinDistanceMetres = ((BasePlugin)this).Config.Bind<float>("Skip", "MinDistanceMetres", 8f, "No view when the predicted impact is closer than this, in metres (the flight would be too short to see). 0 = always. Advised: 0 to 100."); WindowResolution = ((BasePlugin)this).Config.Bind<float>("Performance", "WindowResolution", 1f, "Sharpness of the window: 1 = one image pixel per screen pixel (default, as sharp as your own view), 0.5 = half (cheaper, blurrier). The projectile camera only draws while a projectile is followed. Advised: 0.5 to 1."); FullScreenResolution = ((BasePlugin)this).Config.Bind<float>("Performance", "FullScreenResolution", 1f, "Same, for the full-screen view (default 1). Advised: 0.5 to 1."); PreviewRenderEveryFrames = ((BasePlugin)this).Config.Bind<int>("Performance", "PreviewRenderEveryFrames", 1, "The aim preview draws the scene once every this many frames: 1 = every frame (smoothest), 2 = every other frame (half the cost of the preview). Default 1. Advised: 1 to 4."); LightRendering = ((BasePlugin)this).Config.Bind<bool>("Performance", "LightRendering", false, "True = skip the costliest effects (volumetric fog, screen-space reflections and shadows, ambient occlusion, motion blur, depth of field) on the projectile camera only: cheaper, but flatter and foggier than your own view. Default false."); FullLogging = ((BasePlugin)this).Config.Bind<bool>("Debug", "FullLogging", false, "True = the BepInEx log gets every step useful to diagnose a problem: each shot seen, its prediction and why it opened a view or not, and what each view cost (frame time before and during, mod code per frame). False = only loading, version and errors. Default false."); ModLog.Init(Logger, FullLogging); if (num) { if (WindowResolution.Value == 0.5f) { WindowResolution.Value = 1f; } if (FullScreenResolution.Value == 0.5f) { FullScreenResolution.Value = 1f; } if (LightRendering.Value) { LightRendering.Value = false; } } SettingMove.Move(((BasePlugin)this).Config, "View", "FullScreenWhen", (ConfigEntryBase)(object)FullScreenWhen); SettingMove.Move(((BasePlugin)this).Config, "View", "WindowWhen", (ConfigEntryBase)(object)WindowWhen); bool value = FullLogging.Value; SettingMove.Move(((BasePlugin)this).Config, "Debug", "LogShots", (ConfigEntryBase)(object)FullLogging); if (value) { FullLogging.Value = true; } _config = ((BasePlugin)this).Config; ClassInjector.RegisterTypeInIl2Cpp<CamWatcher>(); GameObject val = new GameObject("ProjectileCam"); Object.DontDestroyOnLoad((Object)val); ((Object)val).hideFlags = (HideFlags)61; val.AddComponent<CamWatcher>(); bool flag = default(bool); try { new Harmony("aznan.sotf.projectilecam").PatchAll(typeof(ShotPatches).Assembly); } catch (Exception ex) { ManualLogSource logger = Logger; BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(47, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Shot patches not installed, no view will open: "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message); } logger.LogError(val2); } ManualLogSource logger2 = Logger; BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("ProjectileCam "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>("0.1.34"); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" loaded"); } logger2.LogInfo(val3); } } } namespace ProjectileCam.Patches { public static class ShotPatches { [HarmonyPatch(typeof(RangedWeapon), "Shoot", new Type[] { typeof(Vector3), typeof(float), typeof(int) })] public static class Shoot { private static void Postfix(RangedWeapon __instance, Vector3 direction) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) CamWatcher.Fired(__instance, direction); } } [HarmonyPatch(typeof(RangedWeapon), "Throw")] public static class Throw { private static void Postfix(RangedWeapon __instance, Vector3 direction) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) CamWatcher.Fired(__instance, direction); } } [HarmonyPatch(typeof(BulletHandler), "UpdateBullets")] public static class BulletsMoved { private static void Postfix() { CamWatcher.AfterBullets(); } } [HarmonyPatch(typeof(ProjectileImpactObject), "Impact")] public static class Impact { private static void Prefix(SurfaceImpactInfo surfaceImpactInfo) { //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_0009: Unknown result type (might be due to invalid IL or missing references) RaycastHit rayHit = surfaceImpactInfo.rayHit; CamWatcher.Hit(((RaycastHit)(ref rayHit)).point, surfaceImpactInfo.weapon); } } } } namespace ProjectileCam.Logic { public enum When { Never, AimedAtCreature, AllShots } public enum View { None, Window, FullScreen } public enum Corner { TopRight, TopLeft, BottomRight, BottomLeft } public enum Framing { Ride, Chase, Side, Behind } public readonly struct Prediction { public readonly bool Known; public readonly bool HitsSomething; public readonly bool HitsCreature; public readonly float ImpactDistance; public Prediction(bool known, bool hitsSomething, bool hitsCreature, float impactDistance) { Known = known; HitsSomething = hitsSomething; HitsCreature = hitsCreature; ImpactDistance = impactDistance; } } public static class Decision { public static readonly string[] OldBoxes = new string[5] { "Bow", "Spear", "FlareGun", "Thrown", "Firearm" }; public static readonly string[] GunsOffSince0127 = new string[2] { "Flare", "StunGun" }; public static string OldBox(string item) { switch (item) { case "CraftedBow": case "TacticalBow": return "Bow"; case "CraftedSpear": return "Spear"; case "Flare": return "FlareGun"; case "SeveredArm": case "SeveredLeg": case "Grenade": case "Molotov": case "TimeBomb": case "SmallRock": return "Thrown"; case "Rifle": case "Revolver": case "CompactPistol": case "ShotgunPumpAction": return "Firearm"; default: return null; } } public static bool OnByDefault(string item) { if (OldBox(item) != "Firearm") { return Array.IndexOf(GunsOffSince0127, item) < 0; } return false; } public static string BoxKey(string name) { char[] array = (name ?? "").ToCharArray(); for (int i = 0; i < array.Length; i++) { if ("=\n\t\\\"'[]".IndexOf(array[i]) >= 0) { array[i] = '_'; } } string text = new string(array).Trim(); if (text.Length <= 0) { return "Unnamed"; } return text; } private static bool Meets(When when, bool aimedAtCreature) { if (when != When.AllShots) { return when == When.AimedAtCreature && aimedAtCreature; } return true; } public static bool Skip(Prediction p, bool skipMisses, float minDistance) { if (!p.Known) { return false; } if (!p.HitsSomething) { return skipMisses; } if (minDistance > 0f) { return p.ImpactDistance < minDistance; } return false; } public static View Choose(bool weaponChosen, When fullScreen, When window, Prediction p, bool skipMisses, float minDistance, bool everyShot) { if (!weaponChosen || (!everyShot && Skip(p, skipMisses, minDistance))) { return View.None; } bool aimedAtCreature = everyShot || p.HitsCreature; if (Meets(fullScreen, aimedAtCreature)) { return View.FullScreen; } if (!Meets(window, aimedAtCreature)) { return View.None; } return View.Window; } public static bool LeaveEarly(View view, bool dead, bool lostHealth, bool startedAiming) { if (!dead) { if (view == View.FullScreen) { return lostHealth || startedAiming; } return false; } return true; } public static float TurnBlend(float distanceLeft, float turnDistance) { if (!(turnDistance <= 0f)) { return Math.Clamp(1f - distanceLeft / turnDistance, 0f, 1f); } return 0f; } public static float SmoothStep(float smoothingSeconds, float deltaTime) { if (!(smoothingSeconds <= 0f)) { return 1f - (float)Math.Exp((0f - deltaTime) / smoothingSeconds); } return 1f; } public static void SelfCheck() { Prediction p = new Prediction(known: false, hitsSomething: false, hitsCreature: false, 0f); Prediction p2 = new Prediction(known: true, hitsSomething: false, hitsCreature: false, 0f); Prediction p3 = new Prediction(known: true, hitsSomething: true, hitsCreature: false, 3f); Prediction p4 = new Prediction(known: true, hitsSomething: true, hitsCreature: false, 30f); Prediction p5 = new Prediction(known: true, hitsSomething: true, hitsCreature: true, 30f); if (!OnByDefault("CraftedBow") || !OnByDefault("CraftedSpear") || OnByDefault("Rifle") || OnByDefault("ShotgunPumpAction") || !OnByDefault("Grenade") || !OnByDefault("RopeGun") || OnByDefault("StunGun") || OnByDefault("Flare") || !OnByDefault("SomeModdedLauncher") || OldBox("SeveredLeg") != "Thrown" || OldBox("Crossbow") != null) { throw new InvalidOperationException("Decision defaults are wrong."); } if (BoxKey("Crafted Bow") != "Crafted Bow" || BoxKey(" a=b[c] ") != "a_b_c_" || BoxKey("") != "Unnamed") { throw new InvalidOperationException("Decision.BoxKey is wrong."); } if (Skip(p, skipMisses: true, 8f) || !Skip(p2, skipMisses: true, 8f) || Skip(p2, skipMisses: false, 8f) || !Skip(p3, skipMisses: true, 8f) || Skip(p3, skipMisses: true, 0f) || Skip(p4, skipMisses: true, 8f)) { throw new InvalidOperationException("Decision.Skip is wrong."); } if (Choose(weaponChosen: false, When.AllShots, When.AllShots, p5, skipMisses: true, 8f, everyShot: false) != View.None || Choose(weaponChosen: true, When.Never, When.AllShots, p4, skipMisses: true, 8f, everyShot: false) != View.Window || Choose(weaponChosen: true, When.AimedAtCreature, When.AllShots, p4, skipMisses: true, 8f, everyShot: false) != View.Window || Choose(weaponChosen: true, When.AimedAtCreature, When.AllShots, p5, skipMisses: true, 8f, everyShot: false) != View.FullScreen || Choose(weaponChosen: true, When.Never, When.AimedAtCreature, p4, skipMisses: true, 8f, everyShot: false) != View.None || Choose(weaponChosen: true, When.AllShots, When.Never, p, skipMisses: true, 8f, everyShot: false) != View.FullScreen || Choose(weaponChosen: true, When.AllShots, When.AllShots, p2, skipMisses: true, 8f, everyShot: false) != View.None || Choose(weaponChosen: true, When.Never, When.AllShots, p2, skipMisses: true, 8f, everyShot: true) != View.Window || Choose(weaponChosen: true, When.Never, When.AimedAtCreature, p3, skipMisses: true, 8f, everyShot: true) != View.Window || Choose(weaponChosen: true, When.AimedAtCreature, When.AllShots, p4, skipMisses: true, 8f, everyShot: true) != View.FullScreen || Choose(weaponChosen: true, When.Never, When.Never, p5, skipMisses: true, 8f, everyShot: true) != View.None || Choose(weaponChosen: false, When.AllShots, When.AllShots, p5, skipMisses: true, 8f, everyShot: true) != View.None) { throw new InvalidOperationException("Decision.Choose is wrong."); } if (LeaveEarly(View.Window, dead: false, lostHealth: true, startedAiming: true) || !LeaveEarly(View.Window, dead: true, lostHealth: false, startedAiming: false) || !LeaveEarly(View.FullScreen, dead: false, lostHealth: true, startedAiming: false) || !LeaveEarly(View.FullScreen, dead: false, lostHealth: false, startedAiming: true) || LeaveEarly(View.FullScreen, dead: false, lostHealth: false, startedAiming: false)) { throw new InvalidOperationException("Decision.LeaveEarly is wrong."); } if (TurnBlend(20f, 6f) != 0f || TurnBlend(0f, 6f) != 1f || TurnBlend(3f, 6f) != 0.5f || TurnBlend(1f, 0f) != 0f) { throw new InvalidOperationException("Decision.TurnBlend is wrong."); } if (SmoothStep(0f, 0.016f) != 1f || SmoothStep(0.1f, 0.016f) <= 0f || SmoothStep(0.1f, 0.016f) >= 1f) { throw new InvalidOperationException("Decision.SmoothStep is wrong."); } } } public enum LaunchFrom { SpawnPoint, ProjectilePose, AimTransform, GameScreenAim } public static class Launch { public const float MaxOffDegrees = 1f; public static LaunchFrom From(bool sameSpawn, bool laserSight, bool modifiedScreen, bool weaponAiming, bool localPlayer) { if (!sameSpawn) { return LaunchFrom.SpawnPoint; } if (laserSight) { return LaunchFrom.ProjectilePose; } if (!modifiedScreen) { return LaunchFrom.SpawnPoint; } if (!weaponAiming) { return LaunchFrom.GameScreenAim; } if (!localPlayer) { return LaunchFrom.SpawnPoint; } return LaunchFrom.AimTransform; } public static bool PreviewMissed(float offDegrees) { return offDegrees > 1f;