Decompiled source of FaceBackward v0.1.3

plugins/FaceBackward.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: AssemblyVersion("0.0.0.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;
		}
	}
}
namespace FaceBackward
{
	[HarmonyPatch(typeof(CharacterSyncer), "GetDataToWrite")]
	public static class FaceBackwardPatch
	{
		public static void Postfix(ref CharacterSyncData __result)
		{
			if (Plugin.Enabled.Value && Plugin.YawOffset.Value != 0f)
			{
				__result.lookValues.x += Plugin.YawOffset.Value;
			}
		}
	}
	[BepInPlugin("FaceBackward", "背面朝前", "0.1.3")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Id = "FaceBackward";

		public const string Name = "背面朝前";

		public const string Version = "0.1.3";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<KeyCode> ToggleKey;

		internal static ConfigEntry<float> YawOffset;

		private Harmony _harmony;

		private string _notificationText = "";

		private float _notificationEndTime;

		private GUIStyle _notificationStyle;

		private void Awake()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "是否启用背面朝前效果(其他玩家看到你背面朝前)");
			ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleKey", (KeyCode)108, "游戏中切换开关的按键");
			YawOffset = ((BaseUnityPlugin)this).Config.Bind<float>("General", "YawOffset", 180f, "发送给其他玩家的朝向偏移角度(默认180=背面朝前)");
			_harmony = new Harmony("FaceBackward");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)string.Format("{0} {1} loaded. ToggleKey={2} Enabled={3}", "背面朝前", "0.1.3", ToggleKey.Value, Enabled.Value));
		}

		private void Update()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(ToggleKey.Value))
			{
				Enabled.Value = !Enabled.Value;
				_notificationText = (Enabled.Value ? "背面朝前:已开启" : "背面朝前:已关闭");
				_notificationEndTime = Time.realtimeSinceStartup + 1.5f;
				Log.LogInfo((object)("[背面朝前] " + _notificationText));
			}
		}

		private void OnGUI()
		{
			//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_0092: 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_00c5: 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_002e: 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_0041: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (!(Time.realtimeSinceStartup >= _notificationEndTime))
			{
				if (_notificationStyle == null)
				{
					_notificationStyle = new GUIStyle(GUI.skin.label)
					{
						fontSize = 24,
						fontStyle = (FontStyle)1,
						alignment = (TextAnchor)4
					};
					_notificationStyle.normal.textColor = Color.white;
				}
				float a = Mathf.Clamp01((_notificationEndTime - Time.realtimeSinceStartup) / 0.3f);
				Color textColor = _notificationStyle.normal.textColor;
				textColor.a = a;
				_notificationStyle.normal.textColor = textColor;
				float num = 400f;
				float num2 = 50f;
				Rect val = new Rect(((float)Screen.width - num) / 2f, (float)Screen.height * 0.15f, num, num2);
				GUI.Box(val, "");
				GUI.Label(val, _notificationText, _notificationStyle);
			}
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}