Decompiled source of WerewolvesCompany v0.5.5
BepInEx/plugins/Doep-WerewolvesCompany/WerewolvesCompany.dll
Decompiled a week ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Coroner; using GameNetcodeStuff; using HarmonyLib; using LethalCompanyInputUtils.Api; using LethalConfig; using LethalConfig.ConfigItems; using Microsoft.CodeAnalysis; using TMPro; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.SceneManagement; using UnityEngine.UI; using WerewolvesCompany.Config; using WerewolvesCompany.Inputs; using WerewolvesCompany.Managers; using WerewolvesCompany.NetcodePatcher; using WerewolvesCompany.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("WerewolvesCompany")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+f8e70fe58fee8694979eaf20f8d8106b224a6c42")] [assembly: AssemblyProduct("WerewolvesCompany")] [assembly: AssemblyTitle("WerewolvesCompany")] [assembly: AssemblyVersion("1.0.0.0")] [module: NetcodePatchedAssembly] internal class <Module> { static <Module>() { NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<bool>(); NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<bool>(); NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<float>(); NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<float>(); } } 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 WerewolvesCompany { internal class CustomDeaths { public const string WEREWOLF_KEY = "Werewolf"; public static AdvancedCauseOfDeath WEREWOLF = API.Register("Werewolf"); public const string WITCH_KEY = "Witch"; public static AdvancedCauseOfDeath WITCH = API.Register("Witch"); public const string LOVER_KEY = "Lover"; public static AdvancedCauseOfDeath LOVER = API.Register("Lover"); public static Dictionary<string, AdvancedCauseOfDeath> references => GetReferences(); public static Dictionary<string, AdvancedCauseOfDeath> GetReferences() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) Dictionary<string, AdvancedCauseOfDeath> dictionary = new Dictionary<string, AdvancedCauseOfDeath>(); dictionary.Add("Werewolf", WEREWOLF); dictionary.Add("Witch", WITCH); dictionary.Add("Lover", LOVER); return dictionary; } } [BepInPlugin("doep.WerewolvesCompany", "WerewolvesCompany", "0.5.5")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] internal class Plugin : BaseUnityPlugin { private const string GUID = "doep.WerewolvesCompany"; private const string NAME = "WerewolvesCompany"; private const string VERSION = "0.5.5"; internal static InputsKeybinds InputActionsInstance; private readonly Harmony harmony = new Harmony("doep.WerewolvesCompany"); public static Plugin Instance; public GameObject rolesManagerPrefab; public GameObject configManagerPrefab; public ManualLogSource logger; public ManualLogSource logdebug; public Random rng; public ModManager modManager; public RolesManager rolesManager; public ConfigManager configManager; public RoleHUD roleHUD; public CooldownManager cooldownManager; public QuotaManager quotaManager; private void InitializeNetCodeStuff() { Type[] types = Assembly.GetExecutingAssembly().GetTypes(); Type[] array = types; foreach (Type type in array) { MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic); MethodInfo[] array2 = methods; foreach (MethodInfo methodInfo in array2) { object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false); if (customAttributes.Length != 0) { methodInfo.Invoke(null, null); } } } } private void Awake() { //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Expected O, but got Unknown logger = Logger.CreateLogSource("doep.WerewolvesCompany"); logdebug = Logger.CreateLogSource("doep.WerewolvesCompany -- debug"); logger.LogInfo((object)"Plugin is initializing..."); Logger.Sources.Remove((ILogSource)(object)logdebug); InitializeNetCodeStuff(); Instance = this; logdebug.LogInfo((object)"Setting up the config"); ConfigParameters.ConfigSetup(); logdebug.LogInfo((object)"Harmony patching"); harmony.PatchAll(); logdebug.LogInfo((object)"Initiate the random generator"); rng = new Random(); logdebug.LogInfo((object)"Creating the roles manager"); string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "netcodemod"); AssetBundle val = AssetBundle.LoadFromFile(text); rolesManagerPrefab = val.LoadAsset<GameObject>("Assets/WerewolvesCompany/RolesManager.prefab"); rolesManagerPrefab.AddComponent<RolesManager>(); logdebug.LogInfo((object)"Creating the config manager"); configManagerPrefab = val.LoadAsset<GameObject>("Assets/WerewolvesCompany/ConfigManager.prefab"); configManagerPrefab.AddComponent<ConfigManager>(); logger.LogInfo((object)"Plugin.Awake() is creating ModManager."); GameObject val2 = new GameObject("ModManager"); val2.AddComponent<ModManager>(); Object.DontDestroyOnLoad((Object)(object)val2); logger.LogInfo((object)"ModManager GameObject created."); modManager = val2.GetComponent<ModManager>(); RunChecks(); } private void RunChecks() { logdebug.LogInfo((object)"============= Checks ============="); logdebug.LogInfo((object)"Checking for duplicate refInts"); try { References.CheckIndividualRefInt(); logdebug.LogInfo((object)"--> OK"); } catch (Exception ex) { logdebug.LogError((object)"There are duplicate roles refInts"); logdebug.LogError((object)ex); } } public void InitiateInputsSystem() { InputActionsInstance = new InputsKeybinds(); } } public class ModManager : MonoBehaviour { public ManualLogSource logger = Plugin.Instance.logger; public ManualLogSource logdebug = Plugin.Instance.logdebug; public static ModManager Instance { get; private set; } private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); SceneManager.sceneLoaded += OnSceneLoaded; logger.LogInfo((object)"ModManager: Awake() called. Initialization started."); logger.LogInfo((object)"Manually initializing the ModManager"); Start(); logger.LogInfo((object)"ModManager setup is complete."); } else { Object.Destroy((Object)(object)((Component)this).gameObject); } } private void Start() { InitializeRolesManager(); InitializeConfigManager(); InitializeHUD(); } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { logdebug.LogInfo((object)("Scene loaded: " + ((Scene)(ref scene)).name + ". Reinitializing HUD components...")); InitializeHUD(); InitializeQuotaManager(); } private void InitializeRolesManager() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown if ((Object)(object)Object.FindObjectOfType<RolesManager>() == (Object)null) { GameObject val = new GameObject("RolesManager"); val.AddComponent<RolesManager>(); logdebug.LogWarning((object)"RolesManager has been recreated."); Plugin.Instance.rolesManager = val.GetComponent<RolesManager>(); } } private void InitializeConfigManager() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown if ((Object)(object)Object.FindObjectOfType<ConfigManager>() == (Object)null) { GameObject val = new GameObject("ConfigManager"); val.AddComponent<ConfigManager>(); logdebug.LogWarning((object)"ConfigManager has been recreated."); Plugin.Instance.configManager = val.GetComponent<ConfigManager>(); } } private void InitializeHUD() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown if ((Object)(object)Object.FindObjectOfType<RoleHUD>() == (Object)null) { GameObject val = new GameObject("RoleHUD"); val.AddComponent<RoleHUD>(); logdebug.LogWarning((object)"RoleHUD has been recreated."); Plugin.Instance.roleHUD = val.GetComponent<RoleHUD>(); } } private void InitializeQuotaManager() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown if ((Object)(object)Object.FindObjectOfType<QuotaManager>() == (Object)null) { GameObject val = new GameObject("QuotaManager"); val.AddComponent<QuotaManager>(); logdebug.LogWarning((object)"QuotaManager has been recreated."); Plugin.Instance.quotaManager = val.GetComponent<QuotaManager>(); } } } internal class References { public static List<Role> GetAllRoles() { List<Role> list = new List<Role>(); list.Add(new Werewolf()); list.Add(new Villager()); list.Add(new Witch()); list.Add(new Seer()); list.Add(new WildBoy()); list.Add(new Cupid()); list.Add(new Minion()); list.Add(new DrunkenMan()); return list; } public static void CheckIndividualRefInt() { bool flag = true; List<Role> allRoles = GetAllRoles(); List<int> list = new List<int>(); foreach (Role item in allRoles) { if (list.Contains(item.refInt)) { flag = false; break; } list.Add(item.refInt); } if (!flag) { throw new Exception("There are duplicates RefInts within the roles"); } } public static Dictionary<int, Role> references() { List<Role> allRoles = GetAllRoles(); Dictionary<int, Role> dictionary = new Dictionary<int, Role>(); foreach (Role item in allRoles) { dictionary.Add(item.refInt, item); } return dictionary; } public static Role GetRoleByName(string roleName) { foreach (KeyValuePair<int, Role> item in references()) { Role value = item.Value; if (value.roleName.ToLower() == roleName.ToLower()) { return value; } } foreach (KeyValuePair<int, Role> item2 in references()) { Role value2 = item2.Value; if (value2.terminalName.ToLower() == roleName.ToLower()) { return value2; } } throw new Exception("No corresponding role found. This should have been caught earlier."); } } internal class RolesInteractions { public bool isImmune = false; public ulong? isInLoveWith = null; } internal class Role { public ManualLogSource logger = Plugin.Instance.logger; public ManualLogSource logdebug = Plugin.Instance.logdebug; public RolesInteractions interactions = new RolesInteractions(); public RolesManager rolesManager => Plugin.Instance.rolesManager; public ConfigManager configManager => Plugin.Instance.configManager; public virtual string roleName { get; set; } = "Default Role Name"; public virtual string? roleNameColor { get; set; } = null; public string roleNameColored => GetRoleNameColored(); public string terminalName => roleName.Replace(" ", "_"); public string terminalNameColored => GetTerminalRoleNameColored(); public virtual int refInt { get; set; } = -1; public virtual string team { get; set; } = "NoTeam"; public virtual string winCondition { get; set; } = "Role Win Condition"; public virtual string roleShortDescription { get; set; } = "Role Short Description"; public virtual string roleDescription { get; set; } = "Role Description"; public virtual string rolePopUp => winCondition + " " + roleShortDescription; public virtual Sprite roleIcon => null; public ulong? targetInRangeId { get; set; } public string? targetInRangeName { get; set; } public virtual string mainActionKey { get; set; } = "Z"; public virtual string secondaryActionKey { get; set; } = "V"; public virtual string mainActionName { get; set; } = "Main Action Name"; public virtual string secondaryActionName { get; set; } = "Secondary Action Name"; public bool hasMainAction => !mainActionName.Contains("Main Action Name"); public bool hasSecondaryAction => !secondaryActionName.Contains("Secondary Action Name"); public virtual string mainActionText => mainActionName + " " + targetInRangeName; public virtual string mainActionTooltip => GetMainActionTooltip(); public virtual string secondaryActionText => secondaryActionName + " " + targetInRangeName; public virtual string secondaryActionTooltip => GetSecondaryActionTooltip(); public virtual string roleActionText { get { return GetRoleActionText(); } set { roleActionText = value; } } public virtual float interactRange => 0f; public virtual float baseActionCooldown => 0f; public virtual float startOfRoundActionCooldown => 0f; public virtual float currentMainActionCooldown { get; set; } public virtual float currentSecondaryActionCooldown { get; set; } public virtual float baseMainActionCooldown { get; set; } public virtual float baseSecondaryActionCooldown { get; set; } public bool IsMainActionOnCooldown => currentMainActionCooldown > 0f; public bool IsSecondaryActionOnCooldown => currentSecondaryActionCooldown > 0f; public Role() { InitiateCooldowns(); } public virtual void InitiateCooldowns() { baseMainActionCooldown = baseActionCooldown; baseSecondaryActionCooldown = baseActionCooldown; currentMainActionCooldown = startOfRoundActionCooldown; currentSecondaryActionCooldown = startOfRoundActionCooldown; } public string GetRoleActionText() { string text = (hasMainAction ? mainActionTooltip : ""); string text2 = (hasSecondaryAction ? secondaryActionTooltip : ""); return (text + "\n" + text2).Trim('\n'); } public string GetRoleNameColored() { if (roleNameColor == null) { return roleName; } return "<color=" + roleNameColor + ">" + roleName + "</color>"; } public string GetTerminalRoleNameColored() { if (roleNameColor == null) { return terminalName; } return "<color=" + roleNameColor + ">" + terminalName + "</color>"; } public void DisplayRolePopUp() { logdebug.LogInfo((object)"Display the role PopUp"); HUDManager.Instance.DisplayTip(roleNameColored, rolePopUp, false, false, "LC_Tip1"); } public virtual bool IsLocallyAllowedToPerformMainAction() { return !IsMainActionOnCooldown && targetInRangeId.HasValue && IsLocallyAllowedToPerformMainActionRoleSpecific(); } public virtual bool IsLocallyAllowedToPerformSecondaryAction() { return !IsSecondaryActionOnCooldown && targetInRangeId.HasValue && IsLocallyAllowedToPerformMainActionRoleSpecific(); } public virtual bool IsLocallyAllowedToPerformMainActionRoleSpecific() { return true; } public virtual bool IsLocallyAllowedToPerformSecondaryActionRoleSpecific() { return true; } public void GenericPerformMainAction() { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) bool flag = false; try { PerformMainAction(); flag = true; } catch (Exception ex) { HUDManager.Instance.DisplayTip("<color=red>Error</color>", "Failed to perform my Main Action", false, false, "LC_Tip1"); logger.LogError((object)"Failed to perform my role action"); logger.LogError((object)ex); } if (flag) { rolesManager.SuccessFullyPerformedMainActionServerRpc(); } } public void GenericPerformSecondaryAction() { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) bool flag = false; try { PerformSecondaryAction(); flag = true; } catch (Exception ex) { HUDManager.Instance.DisplayTip("<color=red>Error</color>", "Failed to perform my Secondary Action", false, false, "LC_Tip1"); logger.LogError((object)"Failed to perform my secondary action"); logger.LogError((object)ex); } if (flag) { rolesManager.SuccessFullyPerformedSecondaryActionServerRpc(); } } public virtual void PerformMainAction() { logger.LogInfo((object)(roleName + " has no main action.")); } public virtual void PerformSecondaryAction() { logger.LogInfo((object)(roleName + " has no secondary action.")); } public virtual void SetMainActionOnCooldown() { currentMainActionCooldown = baseMainActionCooldown; } public virtual void SetSecondaryActionOnCooldown() { logdebug.LogInfo((object)"Setting my secondary action on cooldown"); currentSecondaryActionCooldown = baseSecondaryActionCooldown; } public void UpdateCooldowns(float deltaTime) { currentMainActionCooldown -= deltaTime; currentSecondaryActionCooldown -= deltaTime; } private string GetCurrentMainActionCooldownText() { if (currentMainActionCooldown <= 0f) { return ""; } return $"({(int)currentMainActionCooldown}s)"; } private string GetCurrentSecondaryActionCooldownText() { if (currentSecondaryActionCooldown <= 0f) { return ""; } return $"({(int)currentSecondaryActionCooldown}s)"; } private string GetMainActionTooltip() { if (currentMainActionCooldown < 5000f) { return ("[" + mainActionKey + "] " + mainActionText + " " + GetCurrentMainActionCooldownText()).Trim(); } return ""; } private string GetSecondaryActionTooltip() { if (currentSecondaryActionCooldown < 5000f) { return ("[" + secondaryActionKey + "] " + secondaryActionText + " " + GetCurrentSecondaryActionCooldownText()).Trim(); } return ""; } public virtual void NotifyMainActionSuccess(string targetPlayerName, Role role) { } public virtual void NotifyMainActionSuccess(ulong targetId) { } public virtual void NotifySecondaryActionSuccess(string targetPlayerName) { HUDManager.Instance.DisplayTip(roleNameColored, "Secondary action success", false, false, "LC_Tip1"); } public virtual void NotifySecondaryActionSuccess(ulong targetId) { HUDManager.Instance.DisplayTip(roleNameColored, "Secondary action success", false, false, "LC_Tip1"); } public virtual void NotifySecondaryActionSuccess() { HUDManager.Instance.DisplayTip(roleNameColored, "Secondary action success", false, false, "LC_Tip1"); } public virtual void NotifyMainActionFailed(string targetPlayerName) { HUDManager.Instance.DisplayTip(roleNameColored, "Main action failed", false, false, "LC_Tip1"); } public virtual void NotifySecondaryActionFailed(string targetPlayerName) { HUDManager.Instance.DisplayTip(roleNameColored, "Secondary action failed", false, false, "LC_Tip1"); } public ulong GrabTargetPlayer() { if (!targetInRangeId.HasValue) { logger.LogError((object)"targetInRange is null. It should have been caught earlier. Halting execution."); throw new Exception("targetInRange should not be null at this point."); } return targetInRangeId.Value; } } internal class Werewolf : Role { public override string roleName { get; set; } = "Werewolf"; public override int refInt { get; set; } = 0; public override string team => "Werewolves"; public override string roleNameColor { get; set; } = "red"; public override string winCondition { get; set; } = "You win by killing all Villagers"; public override string roleShortDescription { get; set; } = "You have the ability to kill other players"; public override string mainActionName { get; set; } = "Kill"; public override string roleDescription { get; set; } = "The Werewolves shall kill other players before ship departure.\nThe Werewolf has the ability to kill another player."; public override float interactRange => base.configManager.WerewolfInteractRange.Value; public override float baseActionCooldown => base.configManager.WerewolfActionCooldown.Value; public override float startOfRoundActionCooldown => base.configManager.WerewolfStartOfRoundActionCooldown.Value; public override void PerformMainAction() { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) logger.LogInfo((object)("The " + roleName + " is hunting!")); ulong num = GrabTargetPlayer(); logger.LogInfo((object)("Killing " + base.rolesManager.GetPlayerById(num).playerUsername + ".")); base.rolesManager.WerewolfKillPlayerServerRpc(num); } public override void NotifyMainActionSuccess(ulong targetId) { string playerUsername = base.rolesManager.GetPlayerById(targetId).playerUsername; logger.LogInfo((object)("Successfully killed " + playerUsername + ".")); HUDManager.Instance.DisplayTip(base.roleNameColored, "You killed " + playerUsername + ".", false, false, "LC_Tip1"); } public override void NotifyMainActionFailed(string targetPlayerName) { logger.LogInfo((object)("Failed to kill " + targetPlayerName + ", he was immune")); HUDManager.Instance.DisplayTip(base.roleNameColored, targetPlayerName + " was immune", false, false, "LC_Tip1"); } } internal class Villager : Role { public override string roleName { get; set; } = "Villager"; public override int refInt { get; set; } = 1; public override string team => "Village"; public override string winCondition { get; set; } = "You win by killing the Werewolves."; public override string roleShortDescription { get; set; } = "You do not have any special ability."; public override string roleActionText { get; set; } = ""; public override string mainActionName { get; set; } = "patpat"; public override string roleDescription { get; set; } = "The Villager shall find and kill the Werewolves before ship departure.\nThe Villager can patpat others players."; public override float interactRange => base.configManager.VillagerInteractRange.Value; public override float baseActionCooldown => base.configManager.VillagerActionCooldown.Value; public override float startOfRoundActionCooldown => base.configManager.VillagerStartOfRoundActionCooldown.Value; public override void PerformMainAction() { logger.LogInfo((object)("The " + roleName + " is staying safe.")); HUDManager.Instance.DisplayTip(base.roleNameColored, "*pat pat*", false, false, "LC_Tip1"); } } internal class Witch : Role { public override string roleName { get; set; } = "Witch"; public override int refInt { get; set; } = 2; public override string team => "Village"; public override string winCondition { get; set; } = "You win by killing the Werewolves."; public override string roleShortDescription { get; set; } = "You have the ability to protect one player, and kill another one."; public override string mainActionName { get; set; } = "Poison"; public override string secondaryActionName { get; set; } = "Protect"; public override string roleDescription { get; set; } = "The Witch is part of the village. She shall find and kill the Werewolves before ship departure.\nThe Witch has two potions, and can do two things:\n- Poison another player and kill him (once per round)\n- Protect another player and make him immune once to a Werewolf attack (once per round). The immune player won't know they has been immunized, nor will they know they loses his immune status. The Witch cannot protect herself."; public override float interactRange => base.configManager.WitchInteractRange.Value; public override float baseActionCooldown => base.configManager.WitchActionCooldown.Value; public override float startOfRoundActionCooldown => base.configManager.WitchStartOfRoundActionCooldown.Value; public override void PerformMainAction() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) logger.LogInfo((object)("The " + roleName + " is poisoning someone.")); ulong targetId = GrabTargetPlayer(); base.rolesManager.WitchPoisonPlayerServerRpc(targetId); } public override void PerformSecondaryAction() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) logger.LogInfo((object)("The " + roleName + " is immunising someone.")); ulong targetId = GrabTargetPlayer(); base.rolesManager.WitchImmunizePlayerServerRpc(targetId); } public override void NotifyMainActionSuccess(ulong targetId) { string playerUsername = base.rolesManager.GetPlayerById(targetId).playerUsername; logger.LogInfo((object)("Successfully poisoned " + playerUsername + ".")); HUDManager.Instance.DisplayTip(base.roleNameColored, "You poisoned " + playerUsername + ".", false, false, "LC_Tip1"); } public override void NotifyMainActionFailed(string targetPlayerName) { HUDManager.Instance.DisplayTip(base.roleNameColored, targetPlayerName + " is so drunk that your poison does not seem that have any effect on him.", false, false, "LC_Tip1"); } public override void NotifySecondaryActionSuccess(string targetPlayerName) { logger.LogInfo((object)("Successfully immunized " + targetPlayerName + ".")); HUDManager.Instance.DisplayTip(base.roleNameColored, "You immunized " + targetPlayerName + ".", false, false, "LC_Tip1"); } } internal class Seer : Role { public override string roleName { get; set; } = "Seer"; public override int refInt { get; set; } = 3; public override string team => "Village"; public override string winCondition { get; set; } = "You win by killing the Werewolves."; public override string roleShortDescription { get; set; } = "You have the ability to see a player's role."; public override string mainActionName { get; set; } = "Seer role"; public override string mainActionText => "Seer " + base.targetInRangeName + "'s role"; public override string roleDescription { get; set; } = "The Seer is part of the village. She shall find and kill the Werewolves before ship departure.\nThe Seer can seer another player's role."; public override float interactRange => base.configManager.SeerInteractRange.Value; public override float baseActionCooldown => base.configManager.SeerActionCooldown.Value; public override float startOfRoundActionCooldown => base.configManager.SeerStartOfRoundActionCooldown.Value; public override void PerformMainAction() { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) logger.LogInfo((object)("The " + roleName + " is omniscient.")); logger.LogInfo((object)"Looking the role of someone"); ulong targetId = GrabTargetPlayer(); base.rolesManager.CheckRoleServerRpc(targetId); } public override void NotifyMainActionSuccess(string targetPlayerName, Role role) { logdebug.LogInfo((object)"Displaying Checked role on HUD"); HUDManager.Instance.DisplayTip(base.roleNameColored, targetPlayerName + " is a " + role.roleNameColored, false, false, "LC_Tip1"); } } internal class WildBoy : Role { public string _roleShortDescription = "You can idolize a player. If they dies, you become a werewolf."; public ulong? idolizedId; public override string roleName { get; set; } = "Wild Boy"; public override int refInt { get; set; } = 4; public override string team => "Village"; public override string winCondition { get; set; } = "For now, you win with the village."; public override string roleShortDescription { get { return _roleShortDescription; } set { _roleShortDescription = value; } } public override string roleDescription { get; set; } = "The Wild Boy wins either with the Villagers or the Werewolves, depending on his status.\nThe Wild Boy can target a player who becomes his idol. If his idol dies, the Wild Boy becomes a Werewolf. As long as his idol is alive, he wins with the Villagers."; public override string mainActionName { get; set; } = "Idolize"; public override float interactRange => base.configManager.WildBoyInteractRange.Value; public override float baseActionCooldown => base.configManager.WildBoyActionCooldown.Value; public override float startOfRoundActionCooldown => base.configManager.WildBoyStartOfRoundActionCooldown.Value; public override void PerformMainAction() { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) logger.LogInfo((object)("The " + roleName + " is loitering.")); logger.LogInfo((object)"Idolizing someone"); ulong targetId = GrabTargetPlayer(); base.rolesManager.IdolizeServerRpc(targetId); } public override void NotifyMainActionSuccess(ulong targetId) { logdebug.LogInfo((object)"I am running the Idolization Confirmation"); idolizedId = targetId; logdebug.LogInfo((object)"I have set my idolization mentor"); string playerUsername = base.rolesManager.GetPlayerById(targetId).playerUsername; roleShortDescription = "You have idolized " + playerUsername + ". If they die, you become a werewolf."; logdebug.LogInfo((object)"Displaying Idolization on HUD"); HUDManager.Instance.DisplayTip(base.roleNameColored, "You have idolized " + playerUsername + ". If they die, you will become a werewolf.", false, false, "LC_Tip1"); } public void BecomeWerewolf() { //IL_007a: 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) HUDManager.Instance.DisplayTip(base.roleNameColored, base.rolesManager.GetPlayerById(idolizedId.Value).playerUsername + " is dead. You have become a <color=red>Werewolf</color>.", false, false, "LC_Tip1"); base.rolesManager.BecomeRole("Werewolf", keepInteractions: true); base.rolesManager.myRole.currentMainActionCooldown = base.configManager.WildBoyActionCooldownOnTransform.Value; base.rolesManager.QueryAllRolesServerRpc(sendToAllPlayers: true); } } internal class Cupid : Role { public List<ulong> lovers = new List<ulong>(); public int romancedPlayersCallbackAmount = 0; public override string roleName { get; set; } = "Cupid"; public override int refInt { get; set; } = 5; public override string team => "Village"; public override string winCondition { get; set; } = "You win with the village."; public override string roleShortDescription { get; set; } = "You can make two players fall in love. They must win together. They also die together."; public override string roleDescription { get; set; } = "Cupid is able to make two players fall deeply in love.\nWhen one lover die, the other one also dies.\nThe lovers win together. If they're part of the same team, they win with their team. If they're part of different teams, they must be the only two survivors."; public override string mainActionName { get; set; } = "Romance"; public override string secondaryActionName { get; set; } = "Romance Myself"; public override string secondaryActionText => secondaryActionName; public override float currentSecondaryActionCooldown => currentMainActionCooldown; public override float baseSecondaryActionCooldown => baseMainActionCooldown; public bool TargetIsAlreadyRomanced => lovers.Contains(base.targetInRangeId.Value); public bool AmIAlreadyRomanced => lovers.Contains(((NetworkBehaviour)Utils.GetLocalPlayerControllerB()).OwnerClientId); public bool AreBothTargetsRomanced => lovers.Count == 2; public override float interactRange => base.configManager.CupidInteractRange.Value; public override float baseActionCooldown => base.configManager.CupidActionCooldown.Value; public override float startOfRoundActionCooldown => base.configManager.CupidStartOfRoundActionCooldown.Value; public override void InitiateCooldowns() { baseMainActionCooldown = baseActionCooldown; currentMainActionCooldown = startOfRoundActionCooldown; } public override void SetSecondaryActionOnCooldown() { SetMainActionOnCooldown(); } public override void SetMainActionOnCooldown() { logdebug.LogInfo((object)"Trying to set main action on cooldown"); if (lovers.Count == 2) { logdebug.LogInfo((object)"Success"); currentMainActionCooldown = baseMainActionCooldown; } } public override void PerformMainAction() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) logger.LogInfo((object)(roleName + " is romancing a target: " + base.targetInRangeName + ".")); base.rolesManager.CupidRomancePlayerServerRpc(base.targetInRangeId.Value); } public override void PerformSecondaryAction() { //IL_002f: 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) logger.LogInfo((object)(roleName + " is romancing himself.")); base.rolesManager.CupidRomancePlayerServerRpc(((NetworkBehaviour)Utils.GetLocalPlayerControllerB()).OwnerClientId); } public override void NotifyMainActionSuccess(ulong targetId) { NotifyRomancingSuccess(targetId); } public override void NotifySecondaryActionSuccess(ulong targetId) { NotifyRomancingSuccess(targetId); } private void NotifyRomancingSuccess(ulong targetId) { //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) logdebug.LogInfo((object)"I am running the Romancing confirmation Confirmation"); lovers.Add(targetId); logdebug.LogInfo((object)"Displaying romancing status on HUD"); if (!AreBothTargetsRomanced) { logdebug.LogInfo((object)"Only one target is romanced. Notifying Cupid"); HUDManager.Instance.DisplayTip(base.roleNameColored, "<color=#ff00ffff>" + base.rolesManager.GetPlayerById(targetId).playerUsername + "</color> will be romanced.", false, false, "LC_Tip1"); } else { logdebug.LogInfo((object)"Both targets are romanced. Sending the lovers their respective lover."); romancedPlayersCallbackAmount = 0; base.rolesManager.CupidSendLoversTheirLoverServerRpc(lovers[0], lovers[1]); } } public void CheckForCallBackOfLover() { logdebug.LogInfo((object)$"Received a callback from a lover. Current value: {romancedPlayersCallbackAmount}"); romancedPlayersCallbackAmount++; if (romancedPlayersCallbackAmount == 2) { logdebug.LogInfo((object)"Received 2 callbacks from lovers, notifying to Cupid."); string playerUsername = base.rolesManager.GetPlayerById(lovers[0]).playerUsername; string playerUsername2 = base.rolesManager.GetPlayerById(lovers[1]).playerUsername; roleShortDescription = "<color=#ff00ffff>" + playerUsername + "</color> and <color=#ff00ffff>" + playerUsername2 + "</color> are deeply in love. They will die together. They must win together."; if (!lovers.Contains(((NetworkBehaviour)Utils.GetLocalPlayerControllerB()).OwnerClientId)) { DisplayRolePopUp(); } logger.LogInfo((object)("Successfully romanced " + playerUsername + " and " + playerUsername2)); SetMainActionOnCooldown(); } } public override bool IsLocallyAllowedToPerformMainActionRoleSpecific() { if (TargetIsAlreadyRomanced) { HUDManager.Instance.DisplayTip(base.roleNameColored, base.targetInRangeName + " is already romanced.", false, false, "LC_Tip1"); return false; } return true; } public override bool IsLocallyAllowedToPerformSecondaryActionRoleSpecific() { if (AreBothTargetsRomanced) { return false; } if (AmIAlreadyRomanced) { HUDManager.Instance.DisplayTip(base.roleNameColored, "You are already romanced.", false, false, "LC_Tip1"); return false; } return true; } public override bool IsLocallyAllowedToPerformSecondaryAction() { return !base.IsSecondaryActionOnCooldown && IsLocallyAllowedToPerformSecondaryActionRoleSpecific(); } } internal class Minion : Role { public override string roleName { get; set; } = "Minion"; public override int refInt { get; set; } = 6; public override string team => "Werewolves"; public override string roleNameColor { get; set; } = "red"; public override string winCondition { get; set; } = "You win with the werewolves."; public override string roleShortDescription { get; set; } = "You can see the werewolves, they cannot see you."; public override string roleDescription { get; set; } = "The minion is part of the werewolves team. He is able to see who the werewolves are, but they cannot see him."; } internal class DrunkenMan : Role { public override string roleName { get; set; } = "Drunken Man"; public override int refInt { get; set; } = 7; public override string team => "Village"; public override string winCondition { get; set; } = "You win with the village."; public override string roleShortDescription { get; set; } = "You've been drinking so much that you are immune to the Witch poison."; public override string roleDescription { get; set; } = "The Drunken Man has spent too much time at the local tavern. He has become immune to all kinds of poison, making him immune to the Witch poison."; public void NotifyOldLadyStrongBeverage(ulong witchId) { string playerUsername = base.rolesManager.GetPlayerById(witchId).playerUsername; HUDManager.Instance.DisplayTip(base.roleNameColored, playerUsername + " has provided you with a really strong beverage. You drank worse than that.", false, false, "LC_Tip1"); } } internal static class Utils { public static ManualLogSource logger => Plugin.Instance.logger; public static ManualLogSource logdebug => Plugin.Instance.logdebug; public static RolesManager rolesManager => Plugin.Instance.rolesManager; public static PlayerControllerB localController => StartOfRound.Instance?.localPlayerController; public static void PrintDictionary<T1, T2>(Dictionary<T1, T2> dictionary) { foreach (KeyValuePair<T1, T2> item in dictionary) { logdebug.LogInfo((object)$"{item.Key} > {item.Value}"); } } public static ClientRpcParams BuildClientRpcParams(ulong targetId) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) ClientRpcParams result = default(ClientRpcParams); result.Send = new ClientRpcSendParams { TargetClientIds = new ulong[1] { targetId } }; return result; } public static PlayerControllerB GetLocalPlayerControllerB() { return StartOfRound.Instance?.localPlayerController; } public static RolesManager GetRolesManager() { return rolesManager; } public static void EditDeathMessage(string message = "[LIFE SUPPORT: OFFLINE]") { GameObject val = GameObject.Find("Systems/UI/Canvas/DeathScreen/GameOverText"); TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>(); ((TMP_Text)component).text = message; } public static int Modulo(int a, int b) { return (a % b + b) % b; } public static bool AreThereAliveVillagers() { logdebug.LogInfo((object)"======================================"); PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if (val.isPlayerControlled && rolesManager.allRoles.ContainsKey(((NetworkBehaviour)val).OwnerClientId) && ((NetworkBehaviour)val).IsSpawned && !val.isPlayerDead && rolesManager.allRoles[((NetworkBehaviour)val).OwnerClientId].team == "Village") { return true; } } return false; } } } namespace WerewolvesCompany.UI { internal class RoleHUD : MonoBehaviour { public RoleHUD Instance; public ManualLogSource logger = Plugin.Instance.logger; public ManualLogSource logdebug = Plugin.Instance.logdebug; private GUIStyle style = new GUIStyle(); public Canvas canvas; public GameObject roleTextContainer; public Text roleText; public GameObject voteWindowContainer; public Text voteText; public Text voteTitleText; public string voteWindowHeaderText = "-------------------------------------\nOpen/Close: [N]\nSelect: UP & DOWN arrows\nVote: ENTER\n-------------------------------------"; public string voteWindowPlayersText = ""; public int voteWindowSelectedPlayer = 0; public int? voteCastedPlayer = null; public RolesManager rolesManager => Utils.GetRolesManager(); public string voteWindowFullText => voteWindowHeaderText + "\n\n" + voteWindowPlayersText; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); } else { logger.LogInfo((object)"Duplicate detected, delted the just-created RoleHUD"); Object.Destroy((Object)(object)((Component)this).gameObject); } CreateRoleHUD(); Start(); } private void Start() { } private void Update() { } public void UpdateHUD() { UpdateRoleDisplay(); UpdateToolTip(); UpdateVoteWindowText(); } private void OnDestroy() { } private void CreateRoleHUD() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)canvas == (Object)null) { canvas = new GameObject("RoleHUDCanvas").AddComponent<Canvas>(); canvas.renderMode = (RenderMode)0; Object.DontDestroyOnLoad((Object)(object)((Component)canvas).gameObject); } if ((Object)(object)roleTextContainer == (Object)null) { CreateRoleText(); } if ((Object)(object)voteWindowContainer == (Object)null) { CreateVoteWindow(); } } public void CreateRoleText() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Expected O, but got Unknown //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) roleTextContainer = new GameObject("RoleTextContainer"); roleTextContainer.transform.SetParent(((Component)canvas).transform); HorizontalLayoutGroup val = roleTextContainer.AddComponent<HorizontalLayoutGroup>(); ((LayoutGroup)val).childAlignment = (TextAnchor)1; ((HorizontalOrVerticalLayoutGroup)val).spacing = 10f; ((LayoutGroup)val).padding = new RectOffset(10, 10, 10, 10); RectTransform component = roleTextContainer.GetComponent<RectTransform>(); component.anchorMin = new Vector2(0.5f, 1f); component.anchorMax = new Vector2(0.5f, 1f); component.pivot = new Vector2(0.5f, 1f); component.anchoredPosition = new Vector2(0f, -5f); component.sizeDelta = new Vector2(500f, 200f); GameObject val2 = new GameObject("RoleText"); val2.transform.SetParent(roleTextContainer.transform); roleText = val2.AddComponent<Text>(); roleText.font = Resources.GetBuiltinResource<Font>("Arial.ttf"); roleText.text = ""; roleText.supportRichText = true; roleText.alignment = (TextAnchor)1; roleText.fontSize = 24; ((Graphic)roleText).color = Color.white; RectTransform component2 = ((Component)roleText).GetComponent<RectTransform>(); component2.sizeDelta = new Vector2(50f, 50f); component2.anchorMin = new Vector2(0.5f, 1f); component2.anchorMax = new Vector2(0.5f, 1f); component2.anchoredPosition = new Vector2(0f, 0f); component2.pivot = new Vector2(0.5f, 1f); } public VerticalLayoutGroup AddLayoutGroup(GameObject gameObject) { VerticalLayoutGroup val = gameObject.AddComponent<VerticalLayoutGroup>(); ((LayoutGroup)val).childAlignment = (TextAnchor)1; ((HorizontalOrVerticalLayoutGroup)val).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)val).childControlWidth = true; return val; } public void CreateVoteWindow() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Expected O, but got Unknown //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Expected O, but got Unknown //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Expected O, but got Unknown //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: 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_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Expected O, but got Unknown //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) //IL_03a6: Unknown result type (might be due to invalid IL or missing references) //IL_03bd: Unknown result type (might be due to invalid IL or missing references) //IL_03d4: Unknown result type (might be due to invalid IL or missing references) //IL_03eb: Unknown result type (might be due to invalid IL or missing references) voteWindowContainer = new GameObject("VoteWindowContainer", new Type[1] { typeof(RectTransform) }); voteWindowContainer.transform.SetParent(((Component)canvas).transform); AddLayoutGroup(voteWindowContainer); RectTransform component = voteWindowContainer.GetComponent<RectTransform>(); component.anchorMin = new Vector2(0.99f, 0.99f); component.anchorMax = new Vector2(0.99f, 0.99f); component.pivot = new Vector2(1f, 1f); component.anchoredPosition = new Vector2(0f, 0f); component.sizeDelta = new Vector2(50f, 50f); ContentSizeFitter val = voteWindowContainer.AddComponent<ContentSizeFitter>(); val.verticalFit = (FitMode)2; val.horizontalFit = (FitMode)2; GameObject val2 = new GameObject("VoteWindowBckg"); val2.transform.SetParent(voteWindowContainer.transform); Image val3 = val2.AddComponent<Image>(); ((Graphic)val3).color = new Color(1f, 1f, 1f, 0.01f); VerticalLayoutGroup val4 = AddLayoutGroup(val2); ((LayoutGroup)val4).padding = new RectOffset(10, 10, 10, 10); ((HorizontalOrVerticalLayoutGroup)val4).spacing = 10f; RectTransform component2 = val2.GetComponent<RectTransform>(); component2.sizeDelta = new Vector2(50f, 50f); component2.anchorMin = new Vector2(0.5f, 0.5f); component2.anchorMax = new Vector2(0.5f, 0.5f); component2.anchoredPosition = new Vector2(0f, 0f); component2.pivot = new Vector2(0.5f, 0.5f); GameObject val5 = new GameObject("VoteWindowTitleText"); val5.transform.SetParent(val2.transform); voteTitleText = val5.AddComponent<Text>(); voteTitleText.font = Resources.GetBuiltinResource<Font>("Arial.ttf"); voteTitleText.text = "Vote Window"; voteTitleText.supportRichText = true; voteTitleText.alignment = (TextAnchor)1; voteTitleText.fontSize = 24; ((Graphic)voteTitleText).color = Color.white; RectTransform rectTransform = ((Graphic)voteTitleText).rectTransform; rectTransform.sizeDelta = new Vector2(50f, 50f); rectTransform.anchorMin = new Vector2(0.5f, 1f); rectTransform.anchorMax = new Vector2(0.5f, 1f); rectTransform.anchoredPosition = new Vector2(0f, 0f); rectTransform.pivot = new Vector2(0.5f, 0.5f); GameObject val6 = new GameObject("VoteWindowPlayersListText"); val6.transform.SetParent(val2.transform); voteText = val6.AddComponent<Text>(); voteText.font = Resources.GetBuiltinResource<Font>("Arial.ttf"); voteWindowPlayersText = "Doep\nBananonymous\nPawaeca\nAlmerit\nCookynou\nSynaeh"; voteText.text = voteWindowFullText; voteText.supportRichText = true; voteText.alignment = (TextAnchor)0; voteText.fontSize = 24; ((Graphic)voteText).color = Color.white; RectTransform rectTransform2 = ((Graphic)voteText).rectTransform; rectTransform2.sizeDelta = new Vector2(50f, 50f); rectTransform2.anchorMin = new Vector2(0.5f, 0.5f); rectTransform2.anchorMax = new Vector2(0.5f, 0.5f); rectTransform2.anchoredPosition = new Vector2(0f, 0f); rectTransform2.pivot = new Vector2(0.5f, 0.5f); voteWindowContainer.SetActive(false); } public void UpdateRoleDisplay() { if ((Object)(object)canvas == (Object)null) { CreateRoleHUD(); } if (rolesManager.myRole == null) { roleText.text = ""; return; } Role myRole = rolesManager.myRole; if ((Object)(object)roleText != (Object)null) { string text = myRole.roleNameColored + "\n[N] " + voteTitleText.text + "\n" + myRole.roleActionText.Replace(" ", " "); roleText.text = text; } } public void UpdateToolTip() { PlayerControllerB localPlayerControllerB = Utils.GetLocalPlayerControllerB(); if ((Object)(object)localPlayerControllerB == (Object)null || rolesManager.myRole == null) { return; } if (((TMP_Text)localPlayerControllerB.cursorTip).text.Contains(rolesManager.myRole.mainActionName)) { ((TMP_Text)localPlayerControllerB.cursorTip).text = ""; } if (!localPlayerControllerB.isPlayerDead) { Role myRole = rolesManager.myRole; if (rolesManager.myRole.targetInRangeId.HasValue) { ((TMP_Text)localPlayerControllerB.cursorTip).text = rolesManager.myRole.roleActionText; } } } public void UpdateVoteWindowText() { if (rolesManager.myRole == null) { return; } string text = ""; for (int i = 0; i < rolesManager.allPlayersList.Count; i++) { ulong key = rolesManager.allPlayersIds[i]; string text2 = rolesManager.allPlayersList[key]; string text3 = text2; if (voteCastedPlayer.HasValue && voteCastedPlayer.Value == i) { text3 = "<color=red>" + text2 + "</color>"; } if (i == voteWindowSelectedPlayer) { text3 = "-> " + text3; } text = text + text3 + "\n"; } voteWindowPlayersText = text.Trim('\n'); voteText.text = voteWindowFullText; float voteKillCurrentCooldown = rolesManager.voteKillCurrentCooldown; string text4 = ((!(voteKillCurrentCooldown > 0f)) ? " Available" : $" ({(int)voteKillCurrentCooldown}s)"); voteTitleText.text = "Vote" + text4; } public void OpenCloseVoteTab() { if (voteWindowContainer.activeSelf) { CloseVoteTab(); } else { OpenVoteTab(); } } private void OpenVoteTab() { voteWindowContainer.SetActive(true); } private void CloseVoteTab() { voteWindowContainer.SetActive(false); } } } namespace WerewolvesCompany.Patches { [HarmonyPatch(typeof(GameNetworkManager))] internal class GameNetworkManagerPatcher { [HarmonyPostfix] [HarmonyPatch("Start")] private static void AddToPrefabs(ref GameNetworkManager __instance) { ((Component)__instance).GetComponent<NetworkManager>().AddNetworkPrefab(Plugin.Instance.rolesManagerPrefab); ((Component)__instance).GetComponent<NetworkManager>().AddNetworkPrefab(Plugin.Instance.configManagerPrefab); } [HarmonyPostfix] [HarmonyPatch("Disconnect")] private static void DisableHUD() { Plugin.Instance.roleHUD.roleTextContainer.SetActive(false); Plugin.Instance.roleHUD.voteWindowContainer.SetActive(false); } } [HarmonyPatch] internal class HUDManagerPatcher { public static ManualLogSource logger => Plugin.Instance.logger; public static ManualLogSource logdebug => Plugin.Instance.logdebug; private static RoleHUD roleHUD => Plugin.Instance.roleHUD; private static QuotaManager quotaManager => Plugin.Instance.quotaManager; private static RolesManager rolesManager => Plugin.Instance.rolesManager; private static ConfigManager configManager => Plugin.Instance.configManager; [HarmonyPostfix] [HarmonyPatch(typeof(HUDManager), "SetSpectatingTextToPlayer")] private static void DisplaySpectatedPlayerRole(PlayerControllerB playerScript, HUDManager __instance) { //IL_001b: 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) logdebug.LogInfo((object)"Called SetSpectatingTextToPlayer"); RolesManager rolesManager = Utils.GetRolesManager(); rolesManager.QueryAllRolesServerRpc(); string text = "(Spectating: " + playerScript.playerUsername + " - <b>" + rolesManager.allRoles[((NetworkBehaviour)playerScript).OwnerClientId].roleNameColored + "</b>)"; logdebug.LogInfo((object)("Displaying Spectating text: " + text)); ((TMP_Text)__instance.spectatingPlayerText).text = text; } [HarmonyPrefix] [HarmonyPatch(typeof(HUDManager), "AddNewScrapFoundToDisplay")] private static bool PreventTooltipOnDropBodyInShip(GrabbableObject GObject) { if (configManager.DisableTooltipWhenBodyDroppedInShip.Value && ((Object)GObject).name.ToLower().Contains("ragdoll")) { logdebug.LogInfo((object)("Skipped tooltip for item: " + ((Object)GObject).name)); return false; } return true; } [HarmonyPrefix] [HarmonyPatch(typeof(HUDManager), "AddNewScrapFoundToDisplay")] private static void AddScrapValueToQuota(GrabbableObject GObject) { logdebug.LogInfo((object)$"Found scrap: {((Object)GObject).name} of value {GObject.scrapValue}"); quotaManager.AddScrapValue(GObject.scrapValue); } } [HarmonyPatch(typeof(PlayerControllerB))] internal class PlayerControllerBPatcher { public static ManualLogSource logger = Plugin.Instance.logger; public static ManualLogSource logdebug = Plugin.Instance.logdebug; private static RoleHUD roleHUD = Plugin.Instance.roleHUD; private static RolesManager rolesManager => Plugin.Instance.rolesManager; private static QuotaManager quotaManager => Plugin.Instance.quotaManager; private static ConfigManager configManager => Plugin.Instance.configManager; [HarmonyPostfix] [HarmonyPatch("LateUpdate")] private static void LateUpdate(PlayerControllerB __instance) { if ((Object)(object)__instance == (Object)(object)Utils.GetLocalPlayerControllerB() && ((NetworkBehaviour)__instance).IsOwner && rolesManager.myRole != null) { PlayerControllerB val = rolesManager.CheckForPlayerInRange(((NetworkBehaviour)__instance).NetworkObjectId); if ((Object)(object)val == (Object)null) { rolesManager.myRole.targetInRangeId = null; rolesManager.myRole.targetInRangeName = null; } else { rolesManager.myRole.targetInRangeId = ((NetworkBehaviour)val).OwnerClientId; rolesManager.myRole.targetInRangeName = val.playerUsername; } roleHUD.UpdateHUD(); } } [HarmonyPostfix] [HarmonyPatch("KillPlayer")] private static void OnDeathLogic(PlayerControllerB __instance) { //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)(object)Utils.GetLocalPlayerControllerB() && ((NetworkBehaviour)__instance).IsOwner) { Plugin.Instance.rolesManager.myRole = References.GetRoleByName(Plugin.Instance.rolesManager.myRole.roleName); logger.LogInfo((object)"Role has been reset due to death"); Plugin.Instance.rolesManager.OnSomebodyDeathServerRpc(((NetworkBehaviour)__instance).OwnerClientId); Plugin.Instance.rolesManager.QueryAllRolesServerRpc(); roleHUD.voteCastedPlayer = null; roleHUD.voteWindowContainer.SetActive(false); roleHUD.roleTextContainer.SetActive(false); } } [HarmonyPrefix] [HarmonyPatch("ShowNameBillboard")] private static void ShowRoleSpecificColor(PlayerControllerB __instance) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) ((Graphic)__instance.usernameBillboardText).color = Color.white; string text = " <color=#ff00ffff><3</color>"; ((TMP_Text)__instance.usernameBillboardText).text = ((TMP_Text)__instance.usernameBillboardText).text.Replace(text, ""); if (configManager.CanWerewolvesSeeEachOther.Value && rolesManager.myRole != null && rolesManager.allRoles.ContainsKey(((NetworkBehaviour)__instance).OwnerClientId) && rolesManager.myRole.roleName == "Werewolf" && rolesManager.allRoles[((NetworkBehaviour)__instance).OwnerClientId].roleName == "Werewolf") { ((Graphic)__instance.usernameBillboardText).color = Color.red; } if (rolesManager.myRole != null && rolesManager.allRoles.ContainsKey(((NetworkBehaviour)__instance).OwnerClientId) && rolesManager.myRole.roleName == "Minion" && rolesManager.allRoles[((NetworkBehaviour)__instance).OwnerClientId].roleName == "Werewolf") { ((Graphic)__instance.usernameBillboardText).color = Color.red; } if (rolesManager.myRole != null && rolesManager.myRole.interactions.isInLoveWith.HasValue && ((NetworkBehaviour)__instance).OwnerClientId == rolesManager.myRole.interactions.isInLoveWith.Value) { TextMeshProUGUI usernameBillboardText = __instance.usernameBillboardText; ((TMP_Text)usernameBillboardText).text = ((TMP_Text)usernameBillboardText).text + text; } } } [HarmonyPatch(typeof(PlayerInput))] internal class PlayerInputPatcher { public static ManualLogSource logger = Plugin.Instance.logger; public static ManualLogSource logdebug = Plugin.Instance.logdebug; [HarmonyPostfix] [HarmonyPatch("InitializeActions")] private static void IntializeCustomKeybinds() { logger.LogInfo((object)"Setting up keybinds"); Plugin.Instance.InitiateInputsSystem(); } } [HarmonyPatch(typeof(RoundManager))] internal class RoundManagerPatcher { public static ManualLogSource logger = Plugin.Instance.logger; public static ManualLogSource logdebug = Plugin.Instance.logdebug; private static RolesManager rolesManager => Plugin.Instance.rolesManager; private static RoleHUD roleHUD => Plugin.Instance.roleHUD; private static QuotaManager quotaManager => Plugin.Instance.quotaManager; [HarmonyPostfix] [HarmonyPatch("SyncScrapValuesClientRpc")] private static void SendPlayersTheirRoleAndSetNewQuota(RoundManager __instance) { if (rolesManager.hasAlreadyDistributedRolesThisRound) { return; } if (((Object)RoundManager.Instance.currentLevel).name == "CompanyBuildingLevel") { quotaManager.CheatValue(); return; } quotaManager.ResetScrapValue(); if (((NetworkBehaviour)__instance).IsHost || ((NetworkBehaviour)__instance).IsServer) { logger.LogInfo((object)"Providing roles"); rolesManager.BuildAndSendRoles(); quotaManager.ComputeAndSetNewDailyQuota(); } } } [HarmonyPatch(typeof(StartMatchLever))] internal class StartMatchLeverPatcher { public static ManualLogSource logger = Plugin.Instance.logger; public static ManualLogSource logdebug = Plugin.Instance.logdebug; private static RoleHUD roleHUD = Plugin.Instance.roleHUD; public static string defaultDisabledHoverTip = ""; private static RolesManager rolesManager => Plugin.Instance.rolesManager; private static QuotaManager quotaManager => Plugin.Instance.quotaManager; [HarmonyPostfix] [HarmonyPatch("Start")] private static void GetDefaultDisabledHoverTip(StartMatchLever __instance) { defaultDisabledHoverTip = __instance.triggerScript.disabledHoverTip; rolesManager.hasAlreadyDistributedRolesThisRound = false; } [HarmonyPostfix] [HarmonyPatch("Update")] private static void HoverLeverCheckForQuotaRequirement(StartMatchLever __instance) { if (StartOfRound.Instance.shipIsLeaving) { __instance.triggerScript.disabledHoverTip = defaultDisabledHoverTip; } else { if (!rolesManager.hasAlreadyDistributedRolesThisRound || !StartOfRound.Instance.shipHasLanded) { return; } if (rolesManager.onlyWerewolvesALive) { __instance.triggerScript.interactable = true; } else if (__instance.triggerScript.hoverTip.Contains("Start ship :")) { if (!quotaManager.isQuotaMet) { __instance.triggerScript.interactable = false; __instance.triggerScript.disabledHoverTip = $"[Daily quota not met {quotaManager.currentScrapValue}/{quotaManager.requiredDailyQuota}]"; } else { __instance.triggerScript.interactable = true; } } } } } [HarmonyPatch(typeof(StartOfRound))] internal class StartOfRoundPatcher { public static ManualLogSource logger = Plugin.Instance.logger; public static ManualLogSource logdebug = Plugin.Instance.logdebug; private static RolesManager rolesManager => Plugin.Instance.rolesManager; private static RoleHUD roleHUD => Plugin.Instance.roleHUD; private static QuotaManager quotaManager => Plugin.Instance.quotaManager; [HarmonyPostfix] [HarmonyPatch("Start")] private static void spawnNetManager(StartOfRound __instance) { if (((NetworkBehaviour)__instance).IsHost) { GameObject val = Object.Instantiate<GameObject>(Plugin.Instance.rolesManagerPrefab); val.GetComponent<NetworkObject>().Spawn(false); GameObject val2 = Object.Instantiate<GameObject>(Plugin.Instance.configManagerPrefab); val2.GetComponent<NetworkObject>().Spawn(false); } } [HarmonyPrefix] [HarmonyPatch("ResetPlayersLoadedValueClientRpc")] private static void ResetRolesToNullOnRoundStart(StartOfRound __instance) { logdebug.LogInfo((object)"Resetting my role to null"); rolesManager.myRole = null; rolesManager.hasAlreadyDistributedRolesThisRound = false; roleHUD.roleTextContainer.SetActive(false); } [HarmonyPrefix] [HarmonyPatch("EndOfGameClientRpc")] private static void EndGameLogic(PlayerControllerB __instance) { rolesManager.DisplayWinningTeam(); logdebug.LogInfo((object)"Resetting my role to null"); rolesManager.myRole = null; roleHUD.roleTextContainer.SetActive(false); } } [HarmonyPatch] internal class TerminalPatcher { public static Terminal terminalInstance; public static bool initializedTerminalNodes = false; public static ManualLogSource logger = Plugin.Instance.logger; public static ManualLogSource logdebug = Plugin.Instance.logdebug; private static RolesManager rolesManager => Plugin.Instance.rolesManager; private static RoleHUD roleHUD => Plugin.Instance.roleHUD; private static QuotaManager quotaManager => Plugin.Instance.quotaManager; public static List<Role> availableRoles => References.GetAllRoles(); [HarmonyPostfix] [HarmonyPatch(typeof(Terminal), "Awake")] private static void InitializeTerminal(Terminal __instance) { terminalInstance = __instance; initializedTerminalNodes = false; EditExistingTerminalNodes(); } private static void EditExistingTerminalNodes() { logdebug.LogInfo((object)"Editting existing terminal nodes"); initializedTerminalNodes = true; foreach (TerminalNode specialNode in terminalInstance.terminalNodes.specialNodes) { if (((Object)specialNode).name == "Start" && !specialNode.displayText.Contains("[WerwolvesCompany]")) { logdebug.LogInfo((object)"Editting Start node"); string text = "Type \"Help\" for a list of commands."; int num = specialNode.displayText.IndexOf(text); if (num != -1) { num += text.Length; string value = "\n\n[Werewolves Company]\nType \"Werewolves\" or \"wc\" for a list of commands."; specialNode.displayText = specialNode.displayText.Insert(num, value); } else { logger.LogError((object)"Failed to add werewolves tip to terminal. Maybe an update broke it?"); } } else if (((Object)specialNode).name == "HelpCommands" && !specialNode.displayText.Contains(">WEREWOLVES")) { logdebug.LogInfo((object)"Editting HelpCommands node"); string value2 = "[numberOfItemsOnRoute]"; int num2 = specialNode.displayText.IndexOf(value2); if (num2 != -1) { string value3 = ">WEREWOLVES\nFor a list of Werewolves commands.\n\n"; specialNode.displayText = specialNode.displayText.Insert(num2, value3); } } } } [HarmonyPostfix] [HarmonyPatch(typeof(Terminal), "BeginUsingTerminal")] private static void OnBeginUsingTerminal(Terminal __instance) { logdebug.LogInfo((object)"I just started using the terminal"); if (!initializedTerminalNodes) { EditExistingTerminalNodes(); } } [HarmonyPrefix] [HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")] private static bool ParsePlayerSentence(ref TerminalNode __result, Terminal __instance) { //IL_0443: Unknown result type (might be due to invalid IL or missing references) //IL_0449: Unknown result type (might be due to invalid IL or missing references) if (__instance.screenText.text.Length <= 0) { logdebug.LogInfo((object)"Apparently the text length was negative?"); return true; } string text = __instance.screenText.text.Substring(__instance.screenText.text.Length - __instance.textAdded).ToLower(); string[] array = text.Split(' '); logdebug.LogInfo((object)("Parsing sentence " + text)); logdebug.LogInfo((object)("Input: " + text + ", with args: " + array.ToString() + " of length " + array.Length)); if (!text.StartsWith("werewolves") && !text.StartsWith("wc")) { logdebug.LogInfo((object)"Not a werewolves command"); return true; } if (text.StartsWith("werewolves") || text.StartsWith("wc")) { logdebug.LogInfo((object)"werewolves command was invoked"); if (array.Length == 1) { logger.LogInfo((object)"Loading WerewolvesCompany Terminal's home menu"); __result = BuildTerminalNodeHome(); } else if (array[1] == "add") { if (array.Length == 4) { string text2 = array[2]; if (!RoleIsAvailable(text2)) { logger.LogInfo((object)("Cannot add the role " + text2 + ", it is not part of the available roles")); __result = BuildRoleNotAvailableNode(text2); } if (int.TryParse(array[3], out var result)) { AddNewRole(text2, result); __result = BuildTerminalNodeHome(); return false; } } for (int i = 2; i < array.Length; i++) { string text3 = array[i]; if (!RoleIsAvailable(text3)) { logger.LogInfo((object)("Cannot add the role " + text3 + ", it is not part of the available roles")); __result = BuildRoleNotAvailableNode(text3); } else { AddNewRole(text3); __result = BuildTerminalNodeHome(); } } } else if (array[1] == "delete" || array[1] == "del") { if (array.Length > 3) { logger.LogInfo((object)"Can only delete roles one at a time"); __result = BuilDeleteRolesOnceAtATimeNode(); return false; } if (array[2] == "*") { DeleteAllRoles(); logger.LogInfo((object)"Deleted all roles"); __result = BuildTerminalNodeHome(); return false; } for (int j = 2; j < array.Length; j++) { string text4 = array[j]; if (!RoleIsInPlay(text4)) { logger.LogInfo((object)("Cannot delete the role " + text4 + ", it is not part of the current roles")); __result = BuildRoleNotInPlayNode(text4); } else { DeleteRole(text4); logger.LogInfo((object)("Removed role " + text4 + " from the current roles")); __result = BuildTerminalNodeHome(); } } } else { if (array[1] == "debug") { __result = BuildTerminalNodeDebug(); if (array.Length == 2) { return false; } if (array[2] == "cd") { rolesManager.ResetAllCooldownsServerRpc(); } else if (array[2] == "distrib" || array[2] == "distribute") { rolesManager.BuildAndSendRolesServerRpc(); } else if (array[2] == "reset") { rolesManager.ResetRolesServerRpc(); } else if (array[2] == "quota") { rolesManager.CheatQuotaServerRpc(); } return false; } if (!RoleIsAvailable(array[1])) { return true; } logger.LogInfo((object)("Displaying terminal information for role " + array[1])); __result = BuildRoleInformationNode(array[1]); } return false; } logdebug.LogInfo((object)"Not a werewolf command, pass."); return true; } private static void AddNewRole(string roleName, int N = 1) { //IL_0067: 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) Role roleByName = References.GetRoleByName(roleName); logger.LogInfo((object)$"Adding role x{N} {roleByName.roleName} to the list"); for (int i = 0; i < N; i++) { rolesManager.currentRolesSetup.Add(roleByName); } rolesManager.UpdateCurrentRolesServerRpc(rolesManager.WrapRolesList(rolesManager.currentRolesSetup)); } private static void DeleteRole(string roleName) { //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < rolesManager.currentRolesSetup.Count; i++) { logdebug.LogInfo((object)("Checking " + roleName + " against " + rolesManager.currentRolesSetup[i].terminalName)); if (rolesManager.currentRolesSetup[i].terminalName.ToLower() == roleName.ToLower()) { rolesManager.currentRolesSetup.RemoveAt(i); rolesManager.UpdateCurrentRolesServerRpc(rolesManager.WrapRolesList(rolesManager.currentRolesSetup)); return; } } throw new Exception("Role " + roleName + " not found in the list of current roles. This shoud have been caught earlier."); } public static void DeleteAllRoles() { //IL_002b: 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) rolesManager.currentRolesSetup = new List<Role>(); rolesManager.UpdateCurrentRolesServerRpc(rolesManager.WrapRolesList(rolesManager.currentRolesSetup)); } private static void RemoveRole(string roleName) { } private static TerminalNode BuildTerminalNodeDebug() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown return new TerminalNode { displayText = "[Werewolves Company]\n\n------------------------------\nDebug commands\n------------------------------\nwc debug -> show this page\nwc debug cd -> set all players cooldowns to 0\nwc debug distrib -> distribute roles\nwc debug reset -> reset all players roles to their initial state\nwc debug quota -> set the current daily quota to max\n\n", clearPreviousText = true, acceptAnything = false }; } private static TerminalNode BuildTerminalNodeHome() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) TerminalNode result = new TerminalNode { displayText = "[Werewolves Company]\n\n------------------------------\n[[[availableRoles]]]\n------------------------------\n[[[currentRolesSetup]]]\n\n", clearPreviousText = true, acceptAnything = false }; rolesManager.QueryCurrentRolesServerRpc(); return result; } private static TerminalNode BuildRoleInformationNode(string roleName) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown return new TerminalNode { displayText = "[Werewolves Company]\n\n------------------------------\n[[[" + roleName.ToLower() + "]]]\n\n", clearPreviousText = true, acceptAnything = false }; } private static TerminalNode BuildRoleNotAvailableNode(string roleName) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown return new TerminalNode { displayText = "[Werewolves Company]\n\n------------------------------\nThe role '" + roleName + "' is not available\n\n", clearPreviousText = true, acceptAnything = false }; } private static TerminalNode BuildRoleNotInPlayNode(string roleName) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown return new TerminalNode { displayText = "[Werewolves Company]\n\n------------------------------\nThe role '" + roleName + "' is not part of the current roles\n\n", clearPreviousText = true, acceptAnything = false }; } private static TerminalNode BuilDeleteRolesOnceAtATimeNode() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown return new TerminalNode { displayText = "[Werewolves Company]\n\n------------------------------\nPlease remove roles one at a time\n\n", clearPreviousText = true, acceptAnything = false }; } [HarmonyPrefix] [HarmonyPatch(typeof(Terminal), "TextPostProcess")] private static void TextPostProcess(ref string modifiedDisplayText, TerminalNode node) { logdebug.LogInfo((object)"I just started text post processing"); if (modifiedDisplayText.Length <= 0) { return; } string text = "[[[availableRoles]]]"; if (modifiedDisplayText.Contains(text)) { int num = modifiedDisplayText.IndexOf(text); int num2 = num + text.Length; string oldValue = modifiedDisplayText.Substring(num, num2 - num); string text2 = ""; text2 += "Available Roles:\n"; foreach (Role availableRole in availableRoles) { text2 = text2 + availableRole.terminalNameColored + "\n"; } modifiedDisplayText = modifiedDisplayText.Replace(oldValue, text2); } string text3 = "[[[currentRolesSetup]]]"; if (modifiedDisplayText.Contains(text3)) { int num3 = modifiedDisplayText.IndexOf(text3); int num4 = num3 + text3.Length; string oldValue2 = modifiedDisplayText.Substring(num3, num4 - num3); string text4 = ""; text4 += "Current Roles Setup:\n"; foreach (Role item in rolesManager.currentRolesSetup) { text4 = text4 + item.terminalNameColored + "\n"; } text4 += "\nRemaining slots will be filled with Villagers\n\n"; text4 += "wc add role_name (N) -> Add (N) roles\n"; text4 += "wc add role1 role2 -> Add roles\n"; text4 += "wc del role_name -> Delete role\n"; text4 += "wc del * -> Delete all roles\n"; text4 += "wc role_name -> Check role informations\n"; text4 += "wc debug -> Debug commands\n\n"; modifiedDisplayText = modifiedDisplayText.Replace(oldValue2, text4); } foreach (Role availableRole2 in availableRoles) { string text5 = "[[[" + availableRole2.terminalName.ToLower() + "]]]"; if (modifiedDisplayText.Contains(text5)) { modifiedDisplayText = modifiedDisplayText.Replace(text5, "-> " + availableRole2.roleName + "\n" + availableRole2.roleDescription); } } } private static bool RoleIsAvailable(string roleName) { foreach (Role availableRole in availableRoles) { if (availableRole.terminalName.ToLower() == roleName.ToLower()) { return true; } } return false; } private static bool RoleIsInPlay(string roleName) { foreach (Role item in rolesManager.currentRolesSetup) { if (item.terminalName.ToLower() == roleName.ToLower()) { return true; } } return false; } } } namespace WerewolvesCompany.Managers { public class CooldownManager : MonoBehaviour { public CooldownManager Instance; public ManualLogSource logger = Plugin.Instance.logger; public ManualLogSource logdebug = Plugin.Instance.logdebug; private RolesManager rolesManager = Utils.GetRolesManager(); private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); } else { logdebug.LogInfo((object)"Duplicate detected, delted the just-created CooldownManager"); Object.Destroy((Object)(object)((Component)this).gameObject); } } public void Update() { if (!((Object)(object)rolesManager == (Object)null) && rolesManager.myRole != null) { rolesManager.myRole.UpdateCooldowns(Time.deltaTime); } } } public class NetworkManagerWerewolvesCompany : NetworkBehaviour { public static NetworkManagerWerewolvesCompany Instance; public ManualLogSource logger = Plugin.Instance.logger; public ManualLogSource logdebug = Plugin.Instance.logdebug; private void Awake() { Instance = this; } protected override void __initializeVariables() { ((NetworkBehaviour)this).__initializeVariables(); } protected internal override string __getTypeName() { return "NetworkManagerWerewolvesCompany"; } } internal class QuotaManager : MonoBehaviour { public QuotaManager Instance; public ManualLogSource logger = Plugin.Instance.logger; public ManualLogSource logdebug = Plugin.Instance.logdebug; public int currentScrapValue = 0; public int requiredDailyQuota = 100; public RolesManager rolesManager => Plugin.Instance.rolesManager; public ConfigManager configManager => Plugin.Instance.configManager; public RoleHUD roleHUD => Plugin.Instance.roleHUD; public bool isQuotaMet => currentScrapValue >= requiredDailyQuota; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); } else { Object.Destroy((Object)(object)((Component)this).gameObject); } } private void Update() { } public void AddScrapValue(int scrapValue) { logdebug.LogInfo((object)$"Added quota value : {scrapValue}"); currentScrapValue += scrapValue; } public void ResetScrapValue() { logger.LogInfo((object)"Quota value has been reset"); currentScrapValue = 0; } public void CheatValue() { logger.LogInfo((object)"Quota value has been cheated to meet the daily quota"); currentScrapValue = requiredDailyQuota; } public void SetNewDailyQuota(int quotaValue) { logger.LogInfo((object)$"Set new daily quota to {quotaValue}"); requiredDailyQuota = quotaValue; } public int ComputeDailyQuota() { int num = Mathf.RoundToInt(RoundManager.Instance.totalScrapValueInLevel); int connectedPlayersAmount = StartOfRound.Instance.connectedPlayersAmount; float num2 = Mathf.Max(0f, (float)connectedPlayersAmount - configManager.quotaNplayersOffset.Value) * configManager.quotaPlayersWeight.Value; float num3 = (float)num * (configManager.quotaMinMultiplier.Value + num2); float num4 = Mathf.Min(num3, (float)num * configManager.quotaMaxMultiplier.Value); return (int)num4; } public void ComputeAndSetNewDailyQuota() { //IL_0020: 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) logger.LogInfo((object)"Computing the new daily Quota"); rolesManager.SetNewDailyQuotaServerRpc(ComputeDailyQuota()); } } internal class RolesManager : NetworkBehaviour { public RolesManager Instance; public ManualLogSource logger = Plugin.Instance.logger; public ManualLogSource logdebug = Plugin.Instance.logdebug; public Random rng = Plugin.Instance.rng; public Dictionary<ulong, Role> allRoles; public Dictionary<ulong, string> allPlayersList; public List<ulong> allPlayersIds; public Dictionary<ulong, ulong?> allPlayersVotes; public List<Role> currentRolesSetup = new List<Role>(); public float voteKillCurrentCooldown = 0f; public bool hasAlreadyDistributedRolesThisRound = false; public RoleHUD roleHUD => Plugin.Instance.roleHUD; public QuotaManager quotaManager => Plugin.Instance.quotaManager; public ConfigManager configManager => Plugin.Instance.configManager; public bool isVoteOnCooldown => voteKillCurrentCooldown > 0f; public Role? myRole { get; set; } public bool onlyWerewolvesALive => !Utils.AreThereAliveVillagers(); public override void OnNetworkSpawn() { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) logdebug.LogInfo((object)"RolesManager NetworkSpawn"); logger.LogInfo((object)"Setup Keybinds CallBacks"); SetupKeybindCallbacks(); if (((NetworkBehaviour)this).IsServer) { logdebug.LogInfo((object)"Making default roles"); MakeDefaultRoles(); } QueryCurrentRolesServerRpc(); } private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); Plugin.Instance.rolesManager = this; } else { logdebug.LogInfo((object)"Duplicate detected, delted the just-created RolesManager"); Object.Destroy((Object)(object)((Component)this).gameObject); } } private void Update() { //IL_0068: 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_0070: Unknown result type (might be due to invalid IL or missing references) if (myRole != null) { myRole.UpdateCooldowns(Time.deltaTime); } voteKillCurrentCooldown -= Time.deltaTime; if (((NetworkBehaviour)this).IsServer && allPlayersVotes != null) { ulong? num = CheckForVotedPlayer(); if (num.HasValue) { ClientRpcParams clientRpcParams = Utils.BuildClientRpcParams(num.Value); VoteKillPlayerClientRpc(clientRpcParams); NotifyAllPlayersOfVoteKillClientRpc(num.Value); ResetVotes(); } } } private void SetupKeybindCallbacks() { Plugin.InputActionsInstance.MainRoleActionKey.performed += KeybindsLogic.OnRoleMainKeyPressed; Plugin.InputActionsInstance.SecondaryRoleActionKey.performed += KeybindsLogic.OnRoleSecondaryKeyPressed; Plugin.InputActionsInstance.PopUpRoleActionKey.performed += KeybindsLogic.OnPopUpRoleActionKeyPressed; Plugin.InputActionsInstance.DistributeRolesKey.performed += KeybindsLogic.OnDistributeRolesKeyPressed; Plugin.InputActionsInstance.OpenCloseVotingWindow.performed += KeybindsLogic.OnOpenCloseVotingWindowKeyPressed; Plugin.InputActionsInstance.VoteScrollUp.performed += KeybindsLogic.OnVoteScrollUpKeyPressed; Plugin.InputActionsInstance.VoteScrollDown.performed += KeybindsLogic.OnVoteScrollDownKeyPressed; Plugin.InputActionsInstance.CastVote.performed += KeybindsLogic.OnCastVoteKeyPressed; } public override void OnDestroy() { ((NetworkBehaviour)this).OnDestroy(); logdebug.LogError((object)(((Object)this).name + " has been destroyed!")); } public void DisplayWinningTeam() { TextMeshProUGUI[] componentsInChildren = ((Component)HUDManager.Instance.endgameStatsAnimator).gameObject.GetComponentsInChildren<TextMeshProUGUI>(); TextMeshProUGUI[] array = componentsInChildren; foreach (TextMeshProUGUI val in array) { if (((Object)val).name == "HeaderText") { if (onlyWerewolvesALive) { ((TMP_Text)val).text = "WEREWOLVES HAVE WON"; } else { ((TMP_Text)val).text = "VILLAGERS HAVE WON"; } return; } } throw new Exception("Did not find the Header Text"); } public PlayerControllerB? CheckForPlayerInRange(ulong myId) { if (myRole == null) { throw new Exception("myRole is null in CheckForPlayerInRange. This should have been caught earlier."); } return CheckForPlayerInRange(myId, myRole.interactRange); } public PlayerControllerB? CheckForPlayerInRange(ulong myId, float checkRange) { //IL_0043: 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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) if (myRole == null) { throw new Exception("myRole is null in CheckForPlayerInRange. This should have been caught earlier."); } GameObject playerByNetworkId = GetPlayerByNetworkId(myId); PlayerControllerB component = playerByNetworkId.GetComponent<PlayerControllerB>(); Camera gameplayCamera = component.gameplayCamera; int num = 1 << playerByNetworkId.layer; Vector3 forward = ((Component)gameplayCamera).transform.forward; Vector3 normalized = ((Vector3)(ref forward)).normalized; RaycastHit[] array = Physics.RaycastAll(((Component)gameplayCamera).transform.position, normalized, checkRange, num); RaycastHit[] array2 = Physics.RaycastAll(((Component)gameplayCamera).transform.position, normalized, checkRange); Array.Sort(array2, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance)); if (array2.Length == 0) { return null; } RaycastHit[] array3 = array2; for (int i = 0; i < array3.Length; i++) { RaycastHit val = array3[i]; GameObject gameObject = ((Component)((RaycastHit)(ref val)).transform).gameObject; if (((Object)gameObject.transform.parent).name.Contains("Player")) { gameObject = ((Component)gameObject.transform.parent).gameObject; } if ((Object)(object)gameObject == (Object)(object)playerByNetworkId) { continue; } string text = ((Object)((RaycastHit)(ref val)).collider).name.ToLower(); if (!text.Contains("lineofsight")) { if (gameObject.layer == playerByNetworkId.layer) { return gameObject.GetComponent<PlayerControllerB>(); } Renderer component2 = gameObject.GetComponent<Renderer>(); if (!((Object)(object)component2 == (Object)null) && component2.enabled && component2.isVisible) { return null; } } } return null; } private static GameObject GetPlayerByNetworkId(ulong playerId) { if (NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(playerId, out var value)) { return ((Component)value).gameObject; } return null; } public PlayerControllerB GetPlayerById(ulong playerId) { GameObject[] allPlayerObjects = StartOfRound.Instance.allPlayerObjects; GameObject[] array = allPlayerObjects; foreach (GameObject val in array) { PlayerControllerB component = val.GetComponent<PlayerControllerB>(); if (playerId == ((NetworkBehaviour)component).OwnerClientId) { return component; } } logger.LogError((object)"Could not find the desired player"); throw new Exception("Could not find the player"); } [ServerRpc(RequireOwnership = false)] public void BuildAndSendRolesServerRpc() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_007c: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager != null && networkManager.IsListening) { if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost)) { ServerRpcParams val = default(ServerRpcParams); FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(37963148u, val, (RpcDelivery)0); ((NetworkBehaviour)this).__endSendServerRpc(ref val2, 37963148u, val, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost)) { BuildAndSendRoles(); } } } public void BuildAndSendRoles() { //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) logger.LogInfo((object)"Roles generation has started"); Dictionary<ulong, Role> dictionary = BuildFinalRolesFromScratch(); logger.LogInfo((object)"Roles generation has finished"); logdebug.LogInfo((object)$"{dictionary}"); logger.LogInfo((object)"Sending roles to each player"); foreach (KeyValuePair<ulong, Role> item in dictionary) { logdebug.LogInfo((object)$"Trying to send role {item.Value} to player id {item.Key}"); ClientRpcParams val = Utils.BuildClientRpcParams(item.Key); logdebug.LogInfo((object)$"Using ClientRpcParams: {val}"); Utils.PrintDictionary(dictionary); logdebug.LogInfo((object)$"{item.Value.refInt}"); logdebug.LogInfo((object)"Invoking the SendRoleClientRpc method"); logger.LogInfo((object)$"Sent role to player: {GetPlayerById(item.Key).playerUsername} with id {item.Key}"); SendRoleClientRpc(item.Value.refInt, val); } allRoles = dictionary; logdebug.LogInfo((object)"Stored all roles in RolesManager."); ResetVotes(); ResetVoteCooldownClientRpc(); logdebug.LogInfo((object)"Trying to send allRoles to all players"); QueryAllRolesFromServer(sendToAllPlayers: true); logdebug.LogInfo((object)"Sent allRoles to all players"); logger.LogInfo((object)"Finished sending roles to each player"); hasAlreadyDistributedRolesThisRound = true; } public void MakeDefaultRoles() { currentRolesSetup = References.GetAllRoles(); } public List<Role> GenerateRoles() { return GenerateRoles(GameNetworkManager.Instance.connectedPlayers); } public List<Role> GenerateRoles(int totalPlayers) { List<Role> list = new List<Role>(); for (int i = 0; i < currentRolesSetup.Count; i++) { list.Add(currentRolesSetup[i]); } for (int j = currentRolesSetup.Count; j < totalPlayers; j++) { list.Add(new Villager()); } for (int num = list.Count - 1; num >= totalPlayers; num--) { list.RemoveAt(list.Count - 1); } return list; } public void ShuffleRoles(List<Role> roles) { int num = roles.Count; while (num > 1) { num--; int index = rng.Next(num + 1); Role value = roles[index]; roles[index] = roles[num]; roles[num] = value; } } public Dictionary<ulong, Role> BuildFinalRolesFromScratch() { logdebug.LogInfo((object)"Getting the list of all connected players"); int connectedPlayers = GameNetworkManager.Instance.connectedPlayers; GameObject[] allPlayerObjects = StartOfRound.Instance.allPlayerObjects; string text = $"Found {connectedPlayers} players : "; for (int i = 0; i < connectedPlayers; i++) { string playerUsername = allPlayerObjects[i].GetComponent<PlayerControllerB>().playerUsername; text += playerUsername; } logdebug.LogInfo((object)text); logdebug.LogInfo((object)"Generate the roles"); List<Role> list = GenerateRoles(); logdebug.LogInfo((object)"Shuffle the roles"); ShuffleRoles(list); logdebug.LogInfo((object)"Show all playerControllers informations"); GameObject[] array = allPlayerObjects; foreach (GameObject val in array) { PlayerControllerB component = val.GetComponent<PlayerControllerB>(); logdebug.LogInfo((object)$"playerName = {component.playerUsername}, playerClientId = {component.playerClientId}, actualClientId = {component.actualClientId}, OwnerClientId = {((NetworkBehaviour)component).OwnerClientId}, NetworkObjectId = {((NetworkBehaviour)component).NetworkObjectId}, NetworkBehaviourId = {((NetworkBehaviour)component).NetworkBehaviourId}"); } logdebug.LogInfo((object)"Players added to the list for roles distribution"); List<ulong> list2 = new List<ulong>(); for (int k = 0; k < connectedPlayers; k++) { GameObject val2 = allPlayerObjects[k]; PlayerControllerB component2 = val2.GetComponent<PlayerControllerB>(); logdebug.LogInfo((object)$"playerName = {component2.playerUsername}, playerClientId = {component2.playerClientId}, actualClientId = {component2.actualClientId}, OwnerClientId = {((NetworkBehaviour)component2).OwnerClientId}, NetworkObjectId = {((NetworkBehaviour)component2).NetworkObjectId}, NetworkBehaviourId = {((NetworkBehaviour)component2).NetworkBehaviourId}"); list2.Add(((NetworkBehaviour)component2).OwnerClientId); } logdebug.LogInfo((object)"Associate each client Id with a role"); Dictionary<ulong, Role> dictionary = new Dictionary<ulong, Role>(); for (int l = 0; l < connectedPlayers; l++) { logdebug.LogInfo((object)$"{list2[l]} {list[l]}"); dictionary.Add(list2[l], list[l]); } return dictionary; } public void BecomeRole(string roleName, bool keepInteractions) { Role roleByName = References.GetRoleByName(roleName); RolesInteractions interactions = myRole.interactions; myRole = roleByName; if (keepInteractions) { myRole.interactions = interactions; } } public void DisplayMyRolePopUp() { if (myRole != null) { logger.LogInfo((object)"Displaying my role tooltip"); logdebug.LogInfo((object)"Grabbing my Role"); myRole.DisplayRolePopUp(); } } [ClientRpc] public void SendRoleClientRpc(int roleInt, ClientRpcParams clientRpcParams = default(ClientRpcParams)) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or