using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Peak;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[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;
}
}
}
namespace SpinMaster
{
[BepInPlugin("peak.spinmaster", "原地旋转", "0.3.0")]
public class Plugin : BaseUnityPlugin
{
public const string Id = "peak.spinmaster";
public const string Name = "原地旋转";
public const string Version = "0.3.0";
internal static ManualLogSource Log;
internal static Plugin Instance;
private Harmony _harmony;
public static KeyCode SpinKey = (KeyCode)109;
public static float SpinSpeed = 1440f;
public static float CameraDistance = 3f;
public static float CameraHeight = 1.8f;
public static float TransitionSpeed = 4f;
public static float MouseSensitivityX = 0.5f;
public static float MouseSensitivityY = 0.3f;
private void Awake()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_0046: 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_0057: Expected O, but got Unknown
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
LoadConfig();
_harmony = new Harmony("peak.spinmaster");
_harmony.PatchAll(typeof(Plugin).Assembly);
GameObject val = new GameObject("SpinMaster_Host");
val.AddComponent<SpinController>();
Object.DontDestroyOnLoad((Object)val);
Log.LogInfo((object)string.Format("{0} {1} loaded. SpinKey={2} SpinSpeed={3}", "原地旋转", "0.3.0", SpinKey, SpinSpeed));
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private void LoadConfig()
{
//IL_001c: 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)
SpinKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "SpinKey", (KeyCode)109, "旋转按键(按一下开始/停止)").Value;
SpinSpeed = Mathf.Clamp(((BaseUnityPlugin)this).Config.Bind<float>("General", "SpinSpeed", 1440f, "旋转速度(度/秒,默认1440=4圈/秒)").Value, 360f, 7200f);
CameraDistance = Mathf.Clamp(((BaseUnityPlugin)this).Config.Bind<float>("Camera", "Distance", 3f, "第三人称摄像机距离").Value, 1f, 10f);
CameraHeight = Mathf.Clamp(((BaseUnityPlugin)this).Config.Bind<float>("Camera", "Height", 1.8f, "第三人称摄像机高度").Value, 0.5f, 5f);
TransitionSpeed = Mathf.Clamp(((BaseUnityPlugin)this).Config.Bind<float>("Camera", "TransitionSpeed", 4f, "视角切换过渡速度").Value, 1f, 20f);
MouseSensitivityX = Mathf.Clamp(((BaseUnityPlugin)this).Config.Bind<float>("Camera", "MouseSensitivityX", 0.5f, "旋转期间鼠标水平灵敏度(仅旋转时生效)").Value, 0.05f, 5f);
MouseSensitivityY = Mathf.Clamp(((BaseUnityPlugin)this).Config.Bind<float>("Camera", "MouseSensitivityY", 0.3f, "旋转期间鼠标垂直灵敏度(仅旋转时生效)").Value, 0.05f, 5f);
}
}
[DefaultExecutionOrder(9999)]
public class SpinController : MonoBehaviour
{
internal static SpinController Instance;
internal static bool IsSpinning;
internal static float CurrentOffsetFactor;
private float _stableYaw;
private float _stablePitch;
private bool _camInit;
private Camera _mainCam;
private CameraOverride _camOverride;
private GameObject _overrideObj;
private int _debugFrame;
private Vector3 _lastCharPos;
private static FieldInfo _camOverrideField;
private Camera GetMainCam()
{
if ((Object)(object)_mainCam == (Object)null && (Object)(object)MainCamera.instance != (Object)null)
{
_mainCam = ((Component)MainCamera.instance).GetComponent<Camera>();
}
return _mainCam;
}
private CameraOverride GetOrCreateOverride()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
if ((Object)(object)_camOverride == (Object)null)
{
_overrideObj = new GameObject("SpinMaster_CameraOverride");
_camOverride = _overrideObj.AddComponent<CameraOverride>();
_overrideObj.SetActive(false);
}
return _camOverride;
}
private static bool HasCamOverride()
{
if (_camOverrideField == null)
{
_camOverrideField = typeof(MainCamera).GetField("camOverride", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
if (_camOverrideField == null)
{
return false;
}
return _camOverrideField.GetValue(MainCamera.instance) != null;
}
private void Awake()
{
Instance = this;
}
private void Update()
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: 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_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: 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_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_0269: Unknown result type (might be due to invalid IL or missing references)
//IL_026e: Unknown result type (might be due to invalid IL or missing references)
//IL_026f: Unknown result type (might be due to invalid IL or missing references)
//IL_0276: Unknown result type (might be due to invalid IL or missing references)
//IL_027b: Unknown result type (might be due to invalid IL or missing references)
//IL_0280: Unknown result type (might be due to invalid IL or missing references)
//IL_0282: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_0291: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_0298: Unknown result type (might be due to invalid IL or missing references)
//IL_029d: Unknown result type (might be due to invalid IL or missing references)
//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_030a: Unknown result type (might be due to invalid IL or missing references)
//IL_030f: Unknown result type (might be due to invalid IL or missing references)
//IL_0317: Unknown result type (might be due to invalid IL or missing references)
//IL_031c: Unknown result type (might be due to invalid IL or missing references)
//IL_0324: Unknown result type (might be due to invalid IL or missing references)
//IL_0329: Unknown result type (might be due to invalid IL or missing references)
//IL_032b: Unknown result type (might be due to invalid IL or missing references)
//IL_032e: Unknown result type (might be due to invalid IL or missing references)
//IL_0333: Unknown result type (might be due to invalid IL or missing references)
//IL_0338: Unknown result type (might be due to invalid IL or missing references)
//IL_0344: Unknown result type (might be due to invalid IL or missing references)
//IL_0346: Unknown result type (might be due to invalid IL or missing references)
//IL_037c: Unknown result type (might be due to invalid IL or missing references)
//IL_0388: Unknown result type (might be due to invalid IL or missing references)
//IL_0394: Unknown result type (might be due to invalid IL or missing references)
//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
//IL_03de: Unknown result type (might be due to invalid IL or missing references)
//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0439: Unknown result type (might be due to invalid IL or missing references)
//IL_0444: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
Character localCharacter = Character.localCharacter;
if ((Object)(object)localCharacter == (Object)null || localCharacter.refs == null || (Object)(object)localCharacter.data == (Object)null)
{
if (IsSpinning)
{
StopSpin();
}
return;
}
if (Input.GetKeyDown(Plugin.SpinKey))
{
if (IsSpinning)
{
StopSpin();
}
else
{
StartSpin();
}
}
if (!IsSpinning)
{
return;
}
localCharacter.data.lookValues.x += Plugin.SpinSpeed * Time.deltaTime;
if ((Object)(object)MainCamera.instance == (Object)null)
{
return;
}
Camera mainCam = GetMainCam();
if ((Object)(object)mainCam == (Object)null)
{
return;
}
CurrentOffsetFactor = 1f;
if (!_camInit)
{
Vector3 forward = ((Component)mainCam).transform.forward;
forward.y = 0f;
if (((Vector3)(ref forward)).sqrMagnitude > 0.01f)
{
_stableYaw = Mathf.Atan2(forward.x, forward.z) * 57.29578f;
}
else
{
_stableYaw = ((Component)this).transform.eulerAngles.y;
}
Vector3 eulerAngles = ((Component)mainCam).transform.eulerAngles;
_stablePitch = Mathf.DeltaAngle(eulerAngles.x, 0f);
if (_stablePitch > 180f)
{
_stablePitch -= 360f;
}
_stablePitch = Mathf.Clamp(_stablePitch, -80f, 80f);
_camInit = true;
}
Vector2 lookInput = localCharacter.input.lookInput;
_stableYaw += lookInput.x * Plugin.MouseSensitivityX;
_stablePitch -= lookInput.y * Plugin.MouseSensitivityY;
_stablePitch = Mathf.Clamp(_stablePitch, -80f, 80f);
float axis = Input.GetAxis("Mouse ScrollWheel");
if (axis != 0f)
{
Plugin.CameraDistance -= axis * 5f;
Plugin.CameraDistance = Mathf.Clamp(Plugin.CameraDistance, 1f, 10f);
}
float num = _stableYaw * ((float)Math.PI / 180f);
float num2 = _stablePitch * ((float)Math.PI / 180f);
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor((0f - Mathf.Sin(num)) * Mathf.Cos(num2), 0f - Mathf.Sin(num2), (0f - Mathf.Cos(num)) * Mathf.Cos(num2));
Vector3 val2 = localCharacter.Center + Vector3.up * 1.4f;
Vector3 val3 = val2 + val * Plugin.CameraDistance;
Vector3 val4 = val2 + Vector3.up * 0.15f - val3;
Quaternion val5 = Quaternion.LookRotation(((Vector3)(ref val4)).normalized);
CameraOverride orCreateOverride = GetOrCreateOverride();
((Component)orCreateOverride).transform.position = val3;
((Component)orCreateOverride).transform.rotation = val5;
orCreateOverride.fov = mainCam.fieldOfView;
((Component)mainCam).transform.SetPositionAndRotation(val3, val5);
_debugFrame++;
if (_debugFrame % 30 == 0)
{
Vector3 center = localCharacter.Center;
Vector3 position = ((Component)localCharacter).transform.position;
Vector3 position2 = ((Component)mainCam).transform.position;
val4 = center - _lastCharPos;
float magnitude = ((Vector3)(ref val4)).magnitude;
_lastCharPos = center;
bool flag = HasCamOverride();
Plugin.Log.LogInfo((object)($"[SpinMaster] frame={_debugFrame} " + $"root=({position.x:F2},{position.y:F2},{position.z:F2}) " + $"torso=({center.x:F2},{center.y:F2},{center.z:F2}) " + $"cam=({position2.x:F2},{position2.y:F2},{position2.z:F2}) " + $"moved={magnitude:F3} yaw={_stableYaw:F1} pitch={_stablePitch:F1} " + $"lookInput=({lookInput.x:F2},{lookInput.y:F2}) " + $"ovActive={((Component)orCreateOverride).gameObject.activeSelf} mainOv={flag}"));
}
}
private void LateUpdate()
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
if (IsSpinning)
{
Camera mainCam = GetMainCam();
if (!((Object)(object)mainCam == (Object)null))
{
CameraOverride orCreateOverride = GetOrCreateOverride();
((Component)mainCam).transform.SetPositionAndRotation(((Component)orCreateOverride).transform.position, ((Component)orCreateOverride).transform.rotation);
}
}
}
private void StartSpin()
{
//IL_0015: 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)
IsSpinning = true;
_camInit = false;
_debugFrame = 0;
_lastCharPos = Vector3.zero;
CameraOverride orCreateOverride = GetOrCreateOverride();
((Component)orCreateOverride).gameObject.SetActive(true);
MainCamera.instance.SetCameraOverride(orCreateOverride);
}
private void StopSpin()
{
IsSpinning = false;
CurrentOffsetFactor = 0f;
if ((Object)(object)MainCamera.instance != (Object)null)
{
MainCamera.instance.SetCameraOverride((CameraOverride)null);
}
if ((Object)(object)_overrideObj != (Object)null)
{
_overrideObj.SetActive(false);
}
}
private void OnDestroy()
{
StopSpin();
}
}
[HarmonyPatch(typeof(LookWithCamera), "LateUpdate")]
internal static class LookWithCameraPatch
{
private static bool Prefix()
{
return SpinController.CurrentOffsetFactor < 0.01f;
}
}
[HarmonyPatch(typeof(Character), "CalculateWorldMovementDir")]
internal static class CalculateWorldMovementDirPatch
{
private static void Postfix(Character __instance)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: 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_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_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: 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_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: 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_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
if (!SpinController.IsSpinning || (Object)(object)__instance != (Object)(object)Character.localCharacter)
{
return;
}
MainCamera instance = MainCamera.instance;
if (!((Object)(object)instance == (Object)null))
{
Vector3 forward = ((Component)instance).transform.forward;
forward.y = 0f;
((Vector3)(ref forward)).Normalize();
if (!(((Vector3)(ref forward)).sqrMagnitude < 0.01f))
{
Vector3 val = Vector3.Cross(Vector3.up, forward);
Vector2 movementInput = __instance.input.movementInput;
Vector3 val2 = forward * movementInput.y + val * movementInput.x;
val2 = Vector3.ClampMagnitude(val2, 1f);
__instance.data.worldMovementInput = val2;
__instance.data.worldMovementInput_Grounded = val2;
__instance.data.worldMovementInput_Lerp = val2;
}
}
}
}
}