Decompiled source of KomiChallenge v0.1.2

zeeblo.KomiChallenge.dll

Decompiled 3 days 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using KomiChallenge.Comps;
using KomiChallenge.Scripts;
using KomiChallenge.Utils;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Voice.PUN;
using Photon.Voice.Unity;
using UnityEngine;
using UnityEngine.UI;

[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("zeeblo.KomiChallenge")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+8fe6b380e7de1005ac79ba82a8c4713802e5351c")]
[assembly: AssemblyProduct("KomiChallenge")]
[assembly: AssemblyTitle("zeeblo.KomiChallenge")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 KomiChallenge
{
	[BepInPlugin("KomiChallenge.zeeblo.dev", "KomiChallenge", "0.1.2")]
	public class Plugin : BaseUnityPlugin
	{
		public const string modGUID = "KomiChallenge.zeeblo.dev";

		public const string modName = "KomiChallenge";

		public const string modVersion = "0.1.2";

		private readonly Harmony _harmony = new Harmony("KomiChallenge.zeeblo.dev");

		internal static ManualLogSource mls = Logger.CreateLogSource("KomiChallenge.zeeblo.dev");

		public static int localID;

		private void Awake()
		{
			PConfig.AllConfigs(((BaseUnityPlugin)this).Config);
			PatchAllStuff();
			AssignRoles.AppendRoles();
		}

		private void PatchAllStuff()
		{
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
		}

		public static void SendLog(string msg)
		{
			if (PConfig.enableDevLogs.Value)
			{
				mls.LogInfo((object)msg);
			}
		}

		public static bool FoundThisMod(string modID)
		{
			foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
			{
				BepInPlugin metadata = pluginInfo.Value.Metadata;
				if (metadata.GUID.Equals(modID))
				{
					return true;
				}
			}
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "zeeblo.KomiChallenge";

		public const string PLUGIN_NAME = "KomiChallenge";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace KomiChallenge.Utils
{
	public class PConfig
	{
		public static ConfigEntry<bool> enableDevLogs;

		public static void AllConfigs(ConfigFile cfg)
		{
			enableDevLogs = cfg.Bind<bool>("Misc", "Logging", false, (ConfigDescription)null);
		}
	}
	[HarmonyPatch]
	internal class ztests
	{
		[HarmonyPatch(typeof(MountainProgressHandler), "Update")]
		[HarmonyPostfix]
		private static void boopPatch(MountainProgressHandler __instance)
		{
			if (Plugin.FoundThisMod("zeebloTesting.zeeblo.dev"))
			{
			}
		}
	}
}
namespace KomiChallenge.Scripts
{
	public class AssignRoles
	{
		public enum RoleType
		{
			blind,
			deaf,
			mute
		}

		public static List<Role> defaultTypes = new List<Role>();

		public static Dictionary<int, Role> players = new Dictionary<int, Role>();

		public static void RemoveDebuffs()
		{
			AudioListener.volume = 1f;
			((Component)Character.localCharacter).GetComponent<PhotonVoiceView>().RecorderInUse.TransmitEnabled = true;
			Role component = ((Component)Character.localCharacter).GetComponent<Role>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component.blackScreen);
			}
		}

		public static void AppendRoles()
		{
			defaultTypes.Add(new Role("Blind", "Listen to the voices and remember you can still talk", RoleType.blind));
			defaultTypes.Add(new Role("Deaf", "People can hear you but you can't hear them.", RoleType.deaf));
			defaultTypes.Add(new Role("Mute", "Kill them all. No survivors.", RoleType.mute));
		}

		public static void SplitList(List<int> currentPlayers)
		{
			List<int> list = new List<int>();
			List<Role> list2 = new List<Role>();
			foreach (Role defaultType in defaultTypes)
			{
				list2.Add(defaultType);
				Plugin.SendLog(">>> Role: " + defaultType.roleName);
			}
			for (int i = 0; i < list2.Count; i++)
			{
				Plugin.SendLog(">>> Before before");
				if (i > currentPlayers.Count - 1)
				{
					break;
				}
				list.Add(currentPlayers[i]);
				Plugin.SendLog($">>> Added {i}");
			}
			List<int> list3 = new List<int>();
			foreach (int item in list)
			{
				if (!list3.Contains(item))
				{
					list3.Add(item);
				}
			}
			foreach (int item2 in list3)
			{
				if (currentPlayers.Contains(item2))
				{
					currentPlayers.Remove(item2);
				}
			}
			foreach (int item3 in list3)
			{
				long num = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
				string text = $"{num}";
				string s = text.Substring(7, 2);
				int.TryParse(s, out var result);
				Random.InitState(result);
				Plugin.SendLog($">>> Rnd Seed: {result}");
				int num2 = Random.Range(0, list2.Count);
				players.Add(item3, list2[num2]);
				Plugin.SendLog($">>> Rnd Num: {num2}");
				list2.Remove(list2[num2]);
			}
			if (currentPlayers.Count >= 1)
			{
				SplitList(currentPlayers);
			}
		}
	}
	[HarmonyPatch]
	internal class MainGame
	{
		[CompilerGenerated]
		private sealed class <AssginDebuffs>d__9 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			private List<int> <plrIds>5__1;

			private List<Character>.Enumerator <>s__2;

			private Character <plr>5__3;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<plrIds>5__1 = null;
				<>s__2 = default(List<Character>.Enumerator);
				<plr>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(8.4f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<plrIds>5__1 = new List<int>();
					<>s__2 = Character.AllCharacters.GetEnumerator();
					try
					{
						while (<>s__2.MoveNext())
						{
							<plr>5__3 = <>s__2.Current;
							if (!<plr>5__3.isBot)
							{
								<plrIds>5__1.Add(((Component)<plr>5__3).GetComponent<PhotonView>().Owner.ActorNumber);
								Plugin.SendLog($">>> Player: {((Component)<plr>5__3).GetComponent<PhotonView>().Owner.ActorNumber}");
								<plr>5__3 = null;
							}
						}
					}
					finally
					{
						((IDisposable)<>s__2).Dispose();
					}
					<>s__2 = default(List<Character>.Enumerator);
					AssignRoles.SplitList(<plrIds>5__1);
					Plugin.SendLog(">>> Assigned ROLLLES");
					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();
			}
		}

		public static bool enteredAwake;

		[HarmonyPatch(typeof(Player), "Awake")]
		[HarmonyPostfix]
		private static void GiveID(Player __instance)
		{
			PhotonView component = ((Component)__instance).GetComponent<PhotonView>();
		}

		[HarmonyPatch(typeof(Campfire), "Awake")]
		[HarmonyPostfix]
		private static void InGame()
		{
			if (!enteredAwake)
			{
				((MonoBehaviour)GUIManager.instance).StartCoroutine(AssginDebuffs());
				enteredAwake = true;
			}
		}

		[HarmonyPatch(typeof(GUIManager), "SetHeroTitle")]
		[HarmonyPrefix]
		private static bool AnnounceRole(ref string text)
		{
			int actorNumber = ((Component)Character.localCharacter).gameObject.GetComponent<PhotonView>().Owner.ActorNumber;
			if (AssignRoles.players.ContainsKey(actorNumber))
			{
				Role role = ((Component)Character.localCharacter).gameObject.GetComponent<Role>();
				if ((Object)(object)role == (Object)null)
				{
					role = ((Component)Character.localCharacter).gameObject.AddComponent<Role>();
				}
				else
				{
					((Behaviour)role).enabled = true;
				}
				role.roleName = AssignRoles.players[actorNumber].roleName;
				role.roleType = AssignRoles.players[actorNumber].roleType;
				role.desc = AssignRoles.players[actorNumber].desc;
				text = role.roleName;
				Plugin.SendLog(">>> Contains player!");
			}
			return true;
		}

		[HarmonyPatch(typeof(Campfire), "HoverEnter")]
		[HarmonyPostfix]
		private static void CampfirePatch()
		{
			Role component = ((Component)Character.localCharacter).GetComponent<Role>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			AssignRoles.RemoveDebuffs();
			Plugin.SendLog(">>> Removed Debuffs");
		}

		[HarmonyPatch(typeof(Character), "RPCA_Die")]
		[HarmonyPostfix]
		private static void PlayerDiedPatch()
		{
			Character localCharacter = Character.localCharacter;
			if (localCharacter.data.dead)
			{
				Role component = ((Component)localCharacter).GetComponent<Role>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = false;
				}
				AssignRoles.RemoveDebuffs();
				Plugin.SendLog(">>> You died (rip)");
			}
		}

		[HarmonyPatch(typeof(Character), "EndGame")]
		[HarmonyPrefix]
		private static bool EndGamePatch()
		{
			ResetVars("Game has ended");
			return true;
		}

		[HarmonyPatch(typeof(PassportManager), "Awake")]
		[HarmonyPrefix]
		private static bool OnPlayerLeftRoomPatch()
		{
			AssignRoles.players.Clear();
			enteredAwake = false;
			return true;
		}

		private static void ResetVars(string msg = "")
		{
			Character localCharacter = Character.localCharacter;
			if (!((Object)(object)localCharacter == (Object)null))
			{
				Role component = ((Component)localCharacter).GetComponent<Role>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = false;
				}
				AssignRoles.RemoveDebuffs();
				AssignRoles.players.Clear();
				enteredAwake = false;
				Plugin.SendLog(">>> " + msg);
			}
		}

		[IteratorStateMachine(typeof(<AssginDebuffs>d__9))]
		private static IEnumerator AssginDebuffs()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <AssginDebuffs>d__9(0);
		}
	}
}
namespace KomiChallenge.Comps
{
	public class Role : MonoBehaviour
	{
		public Recorder rec;

		public GameObject blackScreen;

		private static bool blinded;

		public string roleName { get; set; }

		public string desc { get; set; }

		public AssignRoles.RoleType roleType { get; set; }

		public Role(string roleName, string desc, AssignRoles.RoleType roleType)
		{
			this.roleName = roleName;
			this.desc = desc;
			this.roleType = roleType;
		}

		private void Start()
		{
			blinded = false;
		}

		private void Update()
		{
			ActivateDebuff();
		}

		private void OnDestroy()
		{
			if ((Object)(object)blackScreen != (Object)null)
			{
				Object.Destroy((Object)(object)blackScreen);
				blinded = false;
			}
		}

		public void ActivateDebuff()
		{
			switch (roleType)
			{
			case AssignRoles.RoleType.blind:
				BlindUser();
				break;
			case AssignRoles.RoleType.deaf:
				DeafUser();
				break;
			case AssignRoles.RoleType.mute:
				MuteUser();
				break;
			}
		}

		private void BlindUser()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_004d: 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)
			if (!blinded)
			{
				GameObject val = GameObject.Find("GAME/GUIManager/Canvas_HUD");
				blackScreen = new GameObject("blackScreen");
				blackScreen.transform.SetParent(val.transform, false);
				((Graphic)blackScreen.AddComponent<Image>()).color = Color.black;
				blackScreen.transform.SetAsFirstSibling();
				RectTransform component = blackScreen.GetComponent<RectTransform>();
				component.sizeDelta = new Vector2(7200f, 7200f);
				blinded = true;
			}
		}

		private void DeafUser()
		{
			AudioListener.volume = 0f;
		}

		private void MuteUser()
		{
			rec = ((Component)Character.localCharacter).GetComponent<PhotonVoiceView>().RecorderInUse;
			rec.TransmitEnabled = false;
		}

		public Sprite GetIcon(Sprite Icon)
		{
			if (roleType == AssignRoles.RoleType.blind)
			{
				return Icon;
			}
			return Icon;
		}
	}
}