Decompiled source of PEAKInvitationMod v1.0.1

PEAKInvitation.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PEAKInvitation")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PEAKInvitation")]
[assembly: AssemblyTitle("PEAKInvitation")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace PEAKInvitation
{
	[BepInPlugin("PEAKInvitation", "Peak Invitation Mod", "1.0.1")]
	public class PEAKInvitation : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(CharacterVoiceHandler))]
		[HarmonyPatch("Start")]
		public class CharacterVoiceHandler_Start_Patch
		{
			private static void Postfix(CharacterVoiceHandler __instance)
			{
				FieldInfo field = typeof(CharacterVoiceHandler).GetField("m_character", BindingFlags.Instance | BindingFlags.NonPublic);
				FieldInfo field2 = typeof(CharacterVoiceHandler).GetField("m_Recorder", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null && field2 != null)
				{
					object value = field.GetValue(__instance);
					object value2 = field2.GetValue(__instance);
					if (value != null && (bool)value.GetType().GetProperty("IsLocal").GetValue(value))
					{
						value2.GetType().GetProperty("TransmitEnabled").SetValue(value2, false);
					}
				}
			}
		}

		public class EventComponent : MonoBehaviour
		{
			private void Update()
			{
				if (Input.GetKeyDown((KeyCode)288) && (Object)(object)Instance != (Object)null)
				{
					Instance.showUI = !Instance.showUI;
					Instance.IsInviteCodeUIOpen = Instance.showUI;
				}
			}
		}

		[CompilerGenerated]
		private sealed class <EnableUIAfterDelay>d__25 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public float delay;

			public PEAKInvitation <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <EnableUIAfterDelay>d__25(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(delay);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.showUI = true;
					isInviteCodeUIOpen = true;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		internal static ManualLogSource Log;

		private bool isUlongDec = false;

		public bool showUI = false;

		private static bool isInviteCodeUIOpen = false;

		private static string currentInviteCode = string.Empty;

		private static string latestInviteCode = string.Empty;

		private string joinInviteCodeInput = string.Empty;

		private GUIStyle windowStyle;

		private GUIStyle greenButtonStyle;

		private const int MAX_SPAWN_COUNT = 8;

		private const float SPAWN_TIME_LIMIT = 6f;

		private Vector2 windowPosition = new Vector2(100f, 100f);

		private const int windowWidth = 380;

		private const int windowHeight = 300;

		public static PEAKInvitation Instance { get; private set; }

		public static string CurrentInviteCode
		{
			get
			{
				return currentInviteCode;
			}
			set
			{
				currentInviteCode = value;
			}
		}

		public bool IsInviteCodeUIOpen
		{
			get
			{
				return isInviteCodeUIOpen;
			}
			set
			{
				isInviteCodeUIOpen = value;
			}
		}

		private void Awake()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				new Harmony("PEAKInvitation").PatchAll();
			}
			catch (Exception)
			{
			}
			List<string> list = CheckForCheatingPlugins();
			if (list.Count > 0)
			{
				isUlongDec = true;
				Application.Quit();
			}
			else
			{
				((MonoBehaviour)this).StartCoroutine(EnableUIAfterDelay(5f));
				((Component)this).gameObject.AddComponent<EventComponent>();
			}
		}

		[IteratorStateMachine(typeof(<EnableUIAfterDelay>d__25))]
		private IEnumerator EnableUIAfterDelay(float delay)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <EnableUIAfterDelay>d__25(0)
			{
				<>4__this = this,
				delay = delay
			};
		}

		private void OnGUI()
		{
			//IL_0040: 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_005d: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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)
			if (IsInviteCodeUIOpen)
			{
				InitializeStyles();
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(windowPosition.x, windowPosition.y, 380f, 300f);
				val = GUI.Window(0, val, new WindowFunction(DrawWindow), "", windowStyle);
				windowPosition = ((Rect)(ref val)).position;
			}
		}

		private void InitializeStyles()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_0111: 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_0131: Expected O, but got Unknown
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Expected O, but got Unknown
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Expected O, but got Unknown
			//IL_01a8: 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_01ce: 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_01f8: Expected O, but got Unknown
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Expected O, but got Unknown
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Expected O, but got Unknown
			Color col = default(Color);
			((Color)(ref col))..ctor(0.18431373f, 0.20784314f, 22f / 85f);
			Color col2 = default(Color);
			((Color)(ref col2))..ctor(13f / 85f, 58f / 85f, 32f / 85f);
			Color col3 = default(Color);
			((Color)(ref col3))..ctor(0.18039216f, 0.8f, 0.44313726f);
			Color col4 = default(Color);
			((Color)(ref col4))..ctor(0.18039216f, 0.8f, 0.44313726f);
			Color white = Color.white;
			Color textColor = default(Color);
			((Color)(ref textColor))..ctor(0.905f, 0.298f, 0.235f, 1f);
			Color textColor2 = default(Color);
			((Color)(ref textColor2))..ctor(0.905f, 0.298f, 0.235f, 1f);
			Texture2D background = MakeTex(2, 2, col);
			Texture2D background2 = MakeTex(2, 2, col2);
			Texture2D background3 = MakeTex(2, 2, col3);
			Texture2D background4 = MakeTex(2, 2, col4);
			windowStyle = new GUIStyle();
			windowStyle.normal.background = background;
			windowStyle.active.background = background;
			windowStyle.hover.background = background;
			windowStyle.normal.textColor = white;
			windowStyle.border = new RectOffset(10, 10, 10, 10);
			windowStyle.padding = new RectOffset(10, 10, 10, 10);
			windowStyle.fontSize = 16;
			greenButtonStyle = new GUIStyle();
			greenButtonStyle.normal.background = background2;
			greenButtonStyle.hover.background = background3;
			greenButtonStyle.active.background = background4;
			greenButtonStyle.normal.textColor = white;
			greenButtonStyle.hover.textColor = textColor;
			greenButtonStyle.active.textColor = textColor2;
			greenButtonStyle.fontSize = 16;
			greenButtonStyle.border = new RectOffset(5, 5, 5, 5);
			greenButtonStyle.padding = new RectOffset(10, 10, 5, 5);
			greenButtonStyle.margin = new RectOffset(5, 5, 5, 5);
			greenButtonStyle.alignment = (TextAnchor)4;
		}

		private void DrawWindow(int windowID)
		{
			//IL_0015: 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_0030: Expected O, but got Unknown
			//IL_003f: 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_00bf: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			GUI.DragWindow(new Rect(0f, 0f, 380f, 50f));
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontSize = 16;
			val.normal.textColor = Color.white;
			val.fontStyle = (FontStyle)1;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			GUILayout.Label("Isotope's PEAK Invite Mod v1.0.1", val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(25f) });
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUILayout.Space(5f);
			Color col = default(Color);
			((Color)(ref col))..ctor(29f / 85f, 32f / 85f, 37f / 85f);
			GUIStyle val2 = new GUIStyle(GUI.skin.textField);
			val2.normal.background = MakeTex(2, 2, col);
			val2.normal.textColor = Color.white;
			val2.fontSize = 26;
			val2.alignment = (TextAnchor)4;
			GUI.enabled = false;
			CurrentInviteCode = GUILayout.TextField(CurrentInviteCode, val2, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Height(40f),
				GUILayout.Width(362f)
			});
			GUI.enabled = true;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			CSteamID lobbyID = default(CSteamID);
			if (GUILayout.Button("Create Invite Code", greenButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Height(50f),
				GUILayout.Width(178f)
			}) && GameHandler.GetService<SteamLobbyHandler>().InSteamLobby(ref lobbyID))
			{
				CurrentInviteCode = GenerateInviteCode(lobbyID);
				latestInviteCode = CurrentInviteCode;
			}
			if (GUILayout.Button("Copy Invite Code", greenButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Height(50f),
				GUILayout.Width(178f)
			}))
			{
				GUIUtility.systemCopyBuffer = CurrentInviteCode;
			}
			GUILayout.EndHorizontal();
			joinInviteCodeInput = GUILayout.TextField(joinInviteCodeInput ?? "", val2, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Height(40f),
				GUILayout.Width(362f)
			});
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Join Lobby", greenButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Height(50f),
				GUILayout.Width(178f)
			}))
			{
				JoinLobbyByInviteCode(joinInviteCodeInput);
			}
			if (GUILayout.Button("Paste Invite Code", greenButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Height(50f),
				GUILayout.Width(178f)
			}))
			{
				joinInviteCodeInput = GUIUtility.systemCopyBuffer;
			}
			GUILayout.EndHorizontal();
			if (GUILayout.Button("Close", greenButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Height(40f),
				GUILayout.Width(362f)
			}))
			{
				IsInviteCodeUIOpen = false;
			}
		}

		private Texture2D MakeTex(int width, int height, Color col)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0019: 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)
			Texture2D val = new Texture2D(width, height);
			Color[] array = (Color[])(object)new Color[width * height];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = col;
			}
			val.SetPixels(array);
			val.Apply();
			return val;
		}

		private List<string> CheckForCheatingPlugins()
		{
			List<string> list = new List<string>();
			List<string> list2 = new List<string>
			{
				"Everything", "com.you.InjectZorroConsole", "Inject Zorro Console", "com.onigremlin.peakaio", "PEAK AIO Mod", "Cherry.Cherry", "Cherry PEAK Menu", "synq.peak.atlas", "Atlas Peak", "Atlas",
				"Peak Atlas", "Cherry Menu", "Cherry", "Atlas Menu"
			};
			foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
			{
				PluginInfo value = pluginInfo.Value;
				if (list2.Contains(value.Metadata.GUID) || list2.Contains(value.Metadata.Name))
				{
					list.Add(value.Metadata.Name + " (GUID: " + value.Metadata.GUID + ")");
				}
			}
			return list;
		}

		public string ULongToBase36(ulong value)
		{
			string text = string.Empty;
			do
			{
				text = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)(value % 36)] + text;
				value /= 36;
			}
			while (value != 0);
			return text;
		}

		public ulong Base36ToULong(string value)
		{
			ulong num = 0uL;
			foreach (char c in value)
			{
				num = num * 36 + (ulong)((c >= '0' && c <= '9') ? (c - 48) : (c - 97 + 10));
			}
			return num;
		}

		public static string GenerateInviteCode(CSteamID lobbyID)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (Instance.isUlongDec)
			{
				return string.Empty;
			}
			string baseCode = Instance.ULongToBase36(lobbyID.m_SteamID);
			string randomChars = GenerateRandomString(8);
			string result = (CurrentInviteCode = InsertRandomCharacters(baseCode, randomChars));
			latestInviteCode = CurrentInviteCode;
			return result;
		}

		private static string GenerateRandomString(int length)
		{
			char[] array = new char[length];
			Random random = new Random();
			for (int i = 0; i < length; i++)
			{
				array[i] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"[random.Next("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".Length)];
			}
			return new string(array);
		}

		private static string InsertRandomCharacters(string baseCode, string randomChars)
		{
			char[] array = new char[baseCode.Length + randomChars.Length];
			int num = 0;
			for (int i = 0; i < array.Length; i++)
			{
				if (i == 1 || i == 2 || i == 3 || i == 5 || i == 7 || i == 10 || i == 13 || i == 15)
				{
					array[i] = randomChars[num++];
				}
				else
				{
					array[i] = baseCode[i - num];
				}
			}
			return new string(array);
		}

		public CSteamID DecodeInviteCode(string inviteCode)
		{
			//IL_0036: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(inviteCode) || inviteCode.Length < 5)
			{
				throw new FormatException("Invite code cannot be null, empty, or too short.");
			}
			string value = ExtractNaryID(inviteCode);
			ulong num = Base36ToULong(value);
			return new CSteamID(num);
		}

		private string ExtractNaryID(string inviteCode)
		{
			char[] array = inviteCode.ToCharArray();
			List<char> list = new List<char>();
			for (int i = 0; i < array.Length; i++)
			{
				if (i != 1 && i != 2 && i != 3 && i != 5 && i != 7 && i != 10 && i != 13 && i != 15)
				{
					list.Add(array[i]);
				}
			}
			return new string(list.ToArray());
		}

		public void JoinLobbyByInviteCode(string inviteCode)
		{
			//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_001f: Unknown result type (might be due to invalid IL or missing references)
			if (isUlongDec)
			{
				return;
			}
			try
			{
				CSteamID val = DecodeInviteCode(inviteCode);
				SteamLobbyHandler service = GameHandler.GetService<SteamLobbyHandler>();
				service.TryJoinLobby(val);
			}
			catch (FormatException)
			{
			}
		}
	}
}