Decompiled source of FakeSpinbot v1.0.3

Hikaria.FakeSpinbot.dll

Decompiled 2 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using Agents;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using CellMenu;
using Gear;
using HarmonyLib;
using Hikaria.FakeSpinbot.Handlers;
using Hikaria.FakeSpinbot.Utils;
using Il2CppInterop.Runtime.Injection;
using Player;
using SNetwork;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Hikaria.FakeSpinHack")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Hikaria.FakeSpinHack")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ba1c7ea2-f252-4009-bf2c-590492ea77b2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Hikaria.FakeSpinbot
{
	[BepInPlugin("Hikaria.FakeSpinbot", "FakeSpinbot", "1.0.3")]
	public class EntryPoint : BasePlugin
	{
		private Harmony m_Harmony;

		public static EntryPoint Instance { get; private set; }

		public override void Load()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Instance = this;
			Initializer.RegisterTypesInIl2Cpp();
			m_Harmony = new Harmony("Hikaria.FakeSpinbot");
			m_Harmony.PatchAll();
			Logs.LogMessage("OK!");
		}
	}
	internal class Initializer
	{
		private static GameObject comps;

		internal static void InstallComponent()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if ((Object)(object)comps == (Object)null)
			{
				comps = new GameObject("FakeSpinbot");
			}
			if ((Object)(object)comps.GetComponent<GameEventLogManager>() == (Object)null)
			{
				Logs.LogInfo("安装组件: GameEventLogManager");
				comps.AddComponent<GameEventLogManager>();
			}
			if ((Object)(object)comps.GetComponent<ChatManager>() == (Object)null)
			{
				Logs.LogInfo("安装组件: ChatManager");
				comps.AddComponent<ChatManager>();
			}
			if ((Object)(object)comps.GetComponent<FakeSpinbotHandler>() == (Object)null)
			{
				Logs.LogInfo("安装组件: SpinHack");
				comps.AddComponent<FakeSpinbotHandler>();
			}
		}

		internal static void RegisterTypesInIl2Cpp()
		{
			Logs.LogInfo("注入组件: GameEventLogManager");
			ClassInjector.RegisterTypeInIl2Cpp<GameEventLogManager>();
			Logs.LogInfo("注入组件: ChatManager");
			ClassInjector.RegisterTypeInIl2Cpp<ChatManager>();
			Logs.LogInfo("注入组件: SpinHack");
			ClassInjector.RegisterTypeInIl2Cpp<FakeSpinbotHandler>();
		}
	}
	internal sealed class Logs
	{
		public static void LogDebug(object data)
		{
			((BasePlugin)EntryPoint.Instance).Log.LogDebug(data);
		}

		public static void LogError(object data)
		{
			((BasePlugin)EntryPoint.Instance).Log.LogError(data);
		}

		public static void LogFatal(object data)
		{
			((BasePlugin)EntryPoint.Instance).Log.LogFatal(data);
		}

		public static void LogInfo(object data)
		{
			((BasePlugin)EntryPoint.Instance).Log.LogInfo(data);
		}

		public static void LogMessage(object data)
		{
			((BasePlugin)EntryPoint.Instance).Log.LogMessage(data);
		}

		public static void LogWarning(object data)
		{
			((BasePlugin)EntryPoint.Instance).Log.LogWarning(data);
		}
	}
}
namespace Hikaria.FakeSpinbot.Utils
{
	internal class ChatManager : MonoBehaviour
	{
		public static List<string> queue = new List<string>();

		public static int front = 0;

		private void Update()
		{
			try
			{
				if (queue[front] != null)
				{
					Speak(queue[front]);
					front++;
				}
			}
			catch (Exception)
			{
			}
		}

		private static string[] getstr(string strs, int len)
		{
			string[] array = new string[int.Parse(Math.Ceiling((double)strs.Length / (double)len).ToString())];
			for (int i = 0; i < array.Length; i++)
			{
				len = ((len <= strs.Length) ? len : strs.Length);
				array[i] = strs.Substring(0, len);
				strs = strs.Substring(len, strs.Length - len);
			}
			return array;
		}

		public static void SpeakInSeparate(string str, int len = 50)
		{
			if (str.Length > len)
			{
				string[] array = getstr(str, len);
				foreach (string item in array)
				{
					queue.Add(item);
				}
			}
			else
			{
				queue.Add(str);
			}
		}

		public static void Speak(string text)
		{
			PlayerChatManager.WantToSentTextMessage(PlayerManager.GetLocalPlayerAgent(), text, (PlayerAgent)null);
		}
	}
	internal class GameEventLogManager : MonoBehaviour
	{
		private static List<string> GameEventLogs = new List<string>();

		private float _interval;

		private PUI_GameEventLog _puiGameEventLog;

		private void Update()
		{
			if (_interval > 0f)
			{
				_interval -= Time.deltaTime;
			}
			else if (GameEventLogs.Count > 0)
			{
				_puiGameEventLog.AddLogItem(GameEventLogs[0], (eGameEventChatLogType)2);
				GuiManager.Current.m_playerLayer.m_gameEventLog.AddLogItem(GameEventLogs[0], (eGameEventChatLogType)2);
				GameEventLogs.RemoveAt(0);
				_interval = 1f;
			}
		}

		public static void AddLog(string log)
		{
			GameEventLogs.Add(log);
		}

		private void Start()
		{
			_puiGameEventLog = CM_PageLoadout.Current.m_gameEventLog;
		}

		private static string[] getstr(string strs, int len)
		{
			string[] array = new string[int.Parse(Math.Ceiling((double)strs.Length / (double)len).ToString())];
			for (int i = 0; i < array.Length; i++)
			{
				len = ((len <= strs.Length) ? len : strs.Length);
				array[i] = strs.Substring(0, len);
				strs = strs.Substring(len, strs.Length - len);
			}
			return array;
		}

		public static void AddLogInSeparate(string str, int len = 50)
		{
			if (str.Length > len)
			{
				string[] array = getstr(str, len);
				for (int i = 0; i < array.Length; i++)
				{
					AddLog(array[i]);
				}
			}
			else
			{
				AddLog(str);
			}
		}
	}
}
namespace Hikaria.FakeSpinbot.Patches
{
	[HarmonyPatch]
	internal class Patch_BulletWeapon
	{
		private class Timer
		{
			private int _sec = 6;

			internal void add()
			{
				_sec = 6;
			}

			internal void Start()
			{
				FakeSpinbotHandler.isInWeaponFiring = true;
				while (_sec > 0)
				{
					Thread.Sleep(50);
					_sec--;
				}
				FakeSpinbotHandler.isInWeaponFiring = false;
			}
		}

		private static Dictionary<string, Thread> timers = new Dictionary<string, Thread>();

		private static Dictionary<string, Timer> timersInstance = new Dictionary<string, Timer>();

		[HarmonyPatch(typeof(BulletWeapon), "Fire")]
		[HarmonyPrefix]
		private static void BulletWeapon__Fire__Prefix(BulletWeapon __instance)
		{
			if (CheckWeaponOwner(__instance))
			{
				string text = "weaponfiring";
				if (!timers.ContainsKey(text))
				{
					CreateThread(text, add: true);
				}
				else if (timers[text].IsAlive)
				{
					timersInstance[text].add();
				}
				else
				{
					CreateThread(text, add: false);
				}
			}
		}

		private static bool CheckWeaponOwner(BulletWeapon bw)
		{
			return (Object)(object)((Item)bw).Owner.Owner == (Object)(object)SNet.LocalPlayer;
		}

		private static void CreateThread(string threadName, bool add)
		{
			Timer timer = new Timer();
			Thread thread = new Thread((ThreadStart)delegate
			{
				timer.Start();
			});
			thread.Start();
			if (add)
			{
				timers.Add(threadName, thread);
				timersInstance.Add(threadName, timer);
			}
			else
			{
				timers[threadName] = thread;
				timersInstance[threadName] = timer;
			}
		}
	}
	[HarmonyPatch]
	internal sealed class Patch_LocalPlayerAgent
	{
		[HarmonyPatch(typeof(LocalPlayerAgent), "Setup")]
		[HarmonyPostfix]
		private static void LocalPlayerAgent__Setup__Postfix(LocalPlayerAgent __instance)
		{
			Initializer.InstallComponent();
		}

		[HarmonyPatch(typeof(PlayerStamina), "LateUpdate")]
		[HarmonyPostfix]
		private static void PlayerStamina__LateUpdate__Postfix(PlayerStamina __instance)
		{
			if (__instance.m_owner.Owner.IsLocal && FakeSpinbotHandler.disableStamina)
			{
				__instance.ResetStamina();
			}
		}
	}
	[HarmonyPatch]
	internal sealed class Patch_PlayerChatManager
	{
		private static string[] commands = new string[4] { "/fsb smallspin [on|off],开启/关闭小陀螺", "/fsb bigspin [on|off],开启/关闭大陀螺", "/fsb spinspeed [speed],设置大陀螺旋转速度,默认为1.35", "/fsb stamina [on|off],开启/关闭心率锁定为60" };

		[HarmonyPatch(typeof(PlayerChatManager), "PostMessage")]
		[HarmonyPrefix]
		private static void PlayerChatManager__PostMessage__Prefix(PlayerChatManager __instance)
		{
			string text = __instance.m_currentValue;
			try
			{
				if (text.Substring(0, 4).ToLower() == "/fsb")
				{
					text = text.Substring(1, text.Length - 1);
					string[] array = text.Split(new char[1] { ' ' });
					try
					{
						if (array[0].ToLower() == "fsb")
						{
							switch (array[1].ToLower())
							{
							case "help":
								PrintCommands();
								break;
							case "bigspin":
								FakeSpinbotHandler.BigSpin(StringToBool(array[2]));
								break;
							case "smallspin":
								FakeSpinbotHandler.SmallSpin(StringToBool(array[2]));
								break;
							case "spinspeed":
								FakeSpinbotHandler.SpinSpeed(Convert.ToDouble(array[2]));
								break;
							case "stamina":
								FakeSpinbotHandler.Stamina(StringToBool(array[2]));
								break;
							default:
								throw new Exception("Unknown Command");
							}
						}
						return;
					}
					catch (Exception)
					{
						GameEventLogManager.AddLog("<color=red>[FakeSpinbot]</color> 未知命令,输入/fsb help查看帮助");
						return;
					}
					finally
					{
						__instance.m_currentValue = "";
					}
				}
				if (text.ToLower() == "/fsb help")
				{
					throw new Exception("help");
				}
			}
			catch (Exception)
			{
				if (text.ToLower() == "/fsb help")
				{
					PrintCommands();
					__instance.m_currentValue = "";
				}
			}
		}

		public static bool StringToBool(string param)
		{
			param = param.ToLower();
			if (param == "on")
			{
				return true;
			}
			if (!(param == "off"))
			{
				throw new Exception("Illegal character");
			}
			return false;
		}

		private static void PrintCommands()
		{
			GameEventLogManager.AddLog("<color=orange>[FakeSpinbot]</color> 可用命令如下:");
			for (int i = 0; i < commands.Length; i++)
			{
				GameEventLogManager.AddLog(commands[i]);
			}
		}
	}
	[HarmonyPatch]
	internal sealed class Patch_PlayerSync
	{
		[HarmonyPatch(typeof(PlayerSync), "SendLocomotion")]
		[HarmonyPrefix]
		private static bool PlayerSync__SendLocomotion__Prefix(PlayerSync __instance)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Invalid comparison between Unknown and I4
			if (!__instance.Replicator.OwningPlayer.IsLocal)
			{
				return true;
			}
			if ((FakeSpinbotHandler.bigSpin || FakeSpinbotHandler.smallSpin) && (int)FakeSpinbotHandler.LocalPlayer.Locomotion.m_currentStateEnum != 7)
			{
				return false;
			}
			return true;
		}
	}
}
namespace Hikaria.FakeSpinbot.Handlers
{
	internal sealed class FakeSpinbotHandler : MonoBehaviour
	{
		private static FakeSpinbotHandler Instance;

		private double m_degree;

		private Vector3 m_lookdir = new Vector3(0f, -100f, 0f);

		private double m_speed = 3.25;

		public static bool disableStamina;

		public static bool smallSpin { get; internal set; }

		public static bool bigSpin { get; internal set; }

		public static bool isInWeaponFiring { get; internal set; }

		public static PlayerAgent LocalPlayer => PlayerManager.GetLocalPlayerAgent();

		private void Awake()
		{
			Instance = this;
		}

		private void Update()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_0034: 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_0078: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)LocalPlayer == (Object)null || (int)LocalPlayer.Locomotion.m_currentStateEnum == 7)
			{
				return;
			}
			if (smallSpin)
			{
				Vector3 cameraRayDir = LocalPlayer.FPSCamera.CameraRayDir;
				if (!isInWeaponFiring)
				{
					cameraRayDir.x *= -1f;
					cameraRayDir.z *= -1f;
					cameraRayDir.y = -100f;
				}
				SendLocomotion(LocalPlayer.Locomotion.m_currentStateEnum, ((Agent)LocalPlayer).Position, ((Vector3)(ref cameraRayDir)).normalized, LocalPlayer.Locomotion.VelFwdLocal, LocalPlayer.Locomotion.VelRightLocal);
			}
			else if (bigSpin)
			{
				if (!isInWeaponFiring)
				{
					SendLocomotion(LocalPlayer.Locomotion.m_currentStateEnum, ((Agent)LocalPlayer).Position, ((Vector3)(ref m_lookdir)).normalized, LocalPlayer.Locomotion.VelFwdLocal, LocalPlayer.Locomotion.VelRightLocal);
				}
				else
				{
					SendLocomotion(LocalPlayer.Locomotion.m_currentStateEnum, ((Agent)LocalPlayer).Position, LocalPlayer.FPSCamera.CameraRayDir, LocalPlayer.Locomotion.VelFwdLocal, LocalPlayer.Locomotion.VelRightLocal);
				}
			}
		}

		private void FixedUpdate()
		{
			if (bigSpin)
			{
				m_degree += m_speed;
				m_lookdir.x = (float)Math.Sin(m_degree);
				m_lookdir.z = (float)Math.Cos(m_degree);
				if (m_degree >= 360.0)
				{
					m_degree = 0.0;
				}
			}
		}

		private void SendLocomotion(PLOC_State state, Vector3 pos, Vector3 lookDir, float velFwd, float velRight)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			if ((int)LocalPlayer.Locomotion.m_currentStateEnum != 7)
			{
				pPlayerLocomotion locomotionToSend = LocalPlayer.Sync.m_locomotionToSend;
				((MidResVector3_Normalized)(ref locomotionToSend.LookDir)).Value = lookDir;
				locomotionToSend.State = state;
				locomotionToSend.Pos = pos;
				if (Vector3.Distance(pos, LocalPlayer.Sync.m_locomotionLast.Pos) < 0.25f)
				{
					velFwd = 10f;
					velRight = 10f;
				}
				((SFloat8)(ref locomotionToSend.VelFwd)).Set(velFwd, 10f);
				((SFloat8)(ref locomotionToSend.VelRight)).Set(velRight, 10f);
				if (LocalPlayer.Sync.m_fireCountSyncRef > 255)
				{
					locomotionToSend.FireCount = byte.MaxValue;
				}
				else
				{
					locomotionToSend.FireCount = (byte)LocalPlayer.Sync.m_fireCountSyncRef;
				}
				LocalPlayer.Sync.m_fireCountSyncRef = 0;
				LocalPlayer.Sync.m_locomotionToSend = locomotionToSend;
				LocalPlayer.Sync.m_locomotionPacket.Send(locomotionToSend, (SNet_ChannelType)4);
				LocalPlayer.Sync.m_locomotionLast = locomotionToSend;
				LocalPlayer.Sync.m_lastLookDir = lookDir;
				LocalPlayer.Sync.m_velFwdLast = velFwd;
				LocalPlayer.Sync.m_velRightLast = velRight;
			}
		}

		public static void Stamina(bool enable)
		{
			disableStamina = enable;
			GameEventLogManager.AddLog(string.Format("<color={0}>已{1}心率锁定</color>", disableStamina ? "green" : "red", disableStamina ? "开启" : "关闭"));
		}

		public static void SpinSpeed(double speed)
		{
			Instance.m_speed = speed;
			GameEventLogManager.AddLog($"旋转速度已设置为 {Instance.m_speed}");
		}

		public static void BigSpin(bool enable)
		{
			bigSpin = enable;
			if (bigSpin)
			{
				smallSpin = false;
			}
			GameEventLogManager.AddLog(string.Format("<color={0}>已{1}大陀螺</color>", bigSpin ? "green" : "red", bigSpin ? "开启" : "关闭"));
		}

		public static void SmallSpin(bool enable)
		{
			smallSpin = enable;
			if (smallSpin)
			{
				bigSpin = false;
			}
			GameEventLogManager.AddLog(string.Format("<color={0}>已{1}小陀螺</color>", smallSpin ? "green" : "red", smallSpin ? "开启" : "关闭"));
		}
	}
}