Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of PlayerMimics v1.1.2
plugins/com.pauluteli.PlayerMimics.dll
Decompiled 2 weeks ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Xml.Linq; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using Coroner; using Dissonance; using Dissonance.Audio.Capture; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using MonoMod.RuntimeDetour; using NAudio.Wave; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using TMPro; using Unity.Netcode; using UnityEngine; using UnityEngine.AI; using UnityEngine.Animations.Rigging; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Networking; using UnityEngine.UI; using com.pauluteli.PlayerMimics.NetcodePatcher; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Pauluteli")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright (c) 2026 Pauluteli")] [assembly: AssemblyFileVersion("1.1.2.0")] [assembly: AssemblyInformationalVersion("1.1.2+25693f93b6d7db0ea0acf0fdb040dc4ab1b18ec7")] [assembly: AssemblyProduct("com.pauluteli.PlayerMimics")] [assembly: AssemblyTitle("PlayerMimics")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/DasPauluteli/PlayerMimics")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.2.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] [module: NetcodePatchedAssembly] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace PlayerMimics { internal static class AudioCodec { internal const int NetRate = 16000; internal const int ChunkBytes = 4000; internal static byte[] MuLawEncode(float[] samples) { byte[] array = new byte[samples.Length]; for (int i = 0; i < samples.Length; i++) { int num = (int)(Math.Max(-1f, Math.Min(1f, samples[i])) * 32635f); int num2 = ((num < 0) ? 128 : 0); if (num < 0) { num = -num; } num += 132; int num3 = 7; int num4 = 16384; while ((num & num4) == 0 && num3 > 0) { num3--; num4 >>= 1; } int num5 = (num >> num3 + 3) & 0xF; array[i] = (byte)(~(num2 | (num3 << 4) | num5)); } return array; } internal static float[] MuLawDecode(byte[] bytes) { float[] array = new float[bytes.Length]; for (int i = 0; i < bytes.Length; i++) { int num = ~bytes[i] & 0xFF; int num2 = num & 0x80; int num3 = (num >> 4) & 7; int num4 = num & 0xF; int num5 = (num4 << 3) + 132 << num3; num5 -= 132; array[i] = (float)((num2 != 0) ? (-num5) : num5) / 32768f; } return array; } internal static float[] Resample(float[] input, int fromRate, int toRate) { if (fromRate == toRate || input.Length == 0) { return input; } int num = (int)((long)input.Length * (long)toRate / fromRate); float[] array = new float[num]; double num2 = (double)fromRate / (double)toRate; for (int i = 0; i < num; i++) { double num3 = (double)i * num2; int num4 = (int)num3; int num5 = Math.Min(num4 + 1, input.Length - 1); float num6 = (float)(num3 - (double)num4); array[i] = input[num4] * (1f - num6) + input[num5] * num6; } return array; } internal static string ToPcm16Base64(float[] samples) { byte[] array = new byte[samples.Length * 2]; for (int i = 0; i < samples.Length; i++) { short num = (short)(Math.Max(-1f, Math.Min(1f, samples[i])) * 32767f); array[i * 2] = (byte)(num & 0xFF); array[i * 2 + 1] = (byte)((num >> 8) & 0xFF); } return Convert.ToBase64String(array); } internal static float[] FromPcm16Base64(string b64) { byte[] array = Convert.FromBase64String(b64); float[] array2 = new float[array.Length / 2]; for (int i = 0; i < array2.Length; i++) { array2[i] = (float)(short)(array[i * 2] | (array[i * 2 + 1] << 8)) / 32768f; } return array2; } internal static void WriteWav(string path, float[] samples, int rate) { Directory.CreateDirectory(Path.GetDirectoryName(path)); using BinaryWriter binaryWriter = new BinaryWriter(File.Create(path)); int num = samples.Length * 2; binaryWriter.Write(Encoding.ASCII.GetBytes("RIFF")); binaryWriter.Write(36 + num); binaryWriter.Write(Encoding.ASCII.GetBytes("WAVEfmt ")); binaryWriter.Write(16); binaryWriter.Write((short)1); binaryWriter.Write((short)1); binaryWriter.Write(rate); binaryWriter.Write(rate * 2); binaryWriter.Write((short)2); binaryWriter.Write((short)16); binaryWriter.Write(Encoding.ASCII.GetBytes("data")); binaryWriter.Write(num); foreach (float val in samples) { binaryWriter.Write((short)(Math.Max(-1f, Math.Min(1f, val)) * 32767f)); } } internal static byte[][] Chunk(byte[] data) { int num = Math.Max(1, (data.Length + 4000 - 1) / 4000); byte[][] array = new byte[num][]; for (int i = 0; i < num; i++) { int num2 = i * 4000; int num3 = Math.Min(4000, data.Length - num2); array[i] = new byte[Math.Max(0, num3)]; if (num3 > 0) { Array.Copy(data, num2, array[i], 0, num3); } } return array; } } internal sealed class ChunkAssembly { private readonly byte[][] parts; private int received; internal readonly float Started; internal int Count => parts.Length; internal ChunkAssembly(int count, float now) { parts = new byte[count][]; Started = now; } internal bool Add(int index, byte[] data) { if (index < 0 || index >= parts.Length || parts[index] != null) { return false; } parts[index] = data; received++; return received == parts.Length; } internal byte[] Join() { int num = 0; byte[][] array = parts; foreach (byte[] array2 in array) { num += array2.Length; } byte[] array3 = new byte[num]; int num2 = 0; byte[][] array4 = parts; foreach (byte[] array5 in array4) { Array.Copy(array5, 0, array3, num2, array5.Length); num2 += array5.Length; } return array3; } } internal static class BetterEmotesCompat { private static bool looked; private static FieldInfo? localField; private static FieldInfo? othersField; private static FieldInfo? signPrefabField; private static FieldInfo? clapsField; internal static readonly string[] EmoteNames = new string[11] { "", "dance", "point", "middle_finger", "clap", "shy", "griddy", "twerk", "salute", "prisyadka", "sign" }; internal const int Sign = 10; internal static bool Installed { get { if (!Chainloader.PluginInfos.ContainsKey("BestEmotes")) { return Chainloader.PluginInfos.ContainsKey("BetterEmotes"); } return true; } } internal static RuntimeAnimatorController? LocalController { get { Look(); object? obj = localField?.GetValue(null); return (RuntimeAnimatorController?)((obj is RuntimeAnimatorController) ? obj : null); } } internal static RuntimeAnimatorController? OthersController { get { Look(); object? obj = othersField?.GetValue(null); return (RuntimeAnimatorController?)((obj is RuntimeAnimatorController) ? obj : null); } } internal static GameObject? SignPrefab { get { Look(); object? obj = signPrefabField?.GetValue(null); return (GameObject?)((obj is GameObject) ? obj : null); } } private static void Look() { if (looked) { return; } looked = true; if (!Installed) { return; } try { Type type = AccessTools.TypeByName("BetterEmote.Patches.EmotePatch"); localField = AccessTools.Field(type, "local"); othersField = AccessTools.Field(type, "others"); Type type2 = AccessTools.TypeByName("BetterEmote.AssetScripts.LocalPlayer"); signPrefabField = AccessTools.Field(type2, "SignPrefab"); clapsField = AccessTools.Field(AccessTools.TypeByName("BetterEmote.AssetScripts.CustomAudioAnimationEvent"), "claps"); } catch (Exception ex) { Plugin.Log.LogWarning((object)("BetterEmotes is installed but its emotes couldn't be found: " + ex.Message)); } } internal static AudioClip? RandomClap() { Look(); if (clapsField?.GetValue(null) is AudioClip[] array && array.Length != 0) { return array[Random.Range(0, array.Length)]; } return null; } internal static int EmoteNumber(string name) { int num = Array.IndexOf(EmoteNames, name); if (num <= 0) { return 0; } if (num > 2 && !Installed) { return 0; } return num; } internal static string[] Available() { if (!Installed) { return new string[2] { "dance", "point" }; } return EmoteNames[1..]; } } internal sealed class ConsentPopup : MonoBehaviour { internal static readonly Color Orange = new Color(1f, 0.42f, 0.11f); private static readonly Color dimColor = new Color(0.98f, 0.62f, 0.38f); private static readonly Color menuTint = new Color(0.42f, 0.15f, 0.05f, 0.75f); private bool showing; private bool lookWasDisabled; private bool moveWasDisabled; private CursorLockMode oldLock; private bool oldVisible; private GameObject? root; private TextMeshProUGUI? body; private TextMeshProUGUI? storageText; private TextMeshProUGUI? footer; private bool shownSaving; private bool shownTraining; private static Sprite? vignetteSprite; private bool NeedsAnswer() { if (Cfg.VoiceConsent.Value == ConsentChoice.Unset) { return true; } if (Cfg.VoiceConsent.Value == ConsentChoice.Allow && !Cfg.ConsentIncludesReplay.Value) { return true; } if (Cfg.VoiceConsent.Value == ConsentChoice.Allow && ModNetwork.HostSavesAudio && !Cfg.ConsentIncludedSaving.Value) { return true; } if (Cfg.VoiceConsent.Value == ConsentChoice.Allow && ModNetwork.HostCollectsText) { return !Cfg.ConsentIncludedTraining.Value; } return false; } private void Update() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) Key value = Cfg.ResetConsentKey.Value; if ((int)value != 0 && Keyboard.current != null && ((ButtonControl)Keyboard.current[value]).wasPressedThisFrame) { Cfg.VoiceConsent.Value = ConsentChoice.Unset; Cfg.ConsentIncludedSaving.Value = false; Cfg.ConsentIncludesReplay.Value = false; Cfg.ConsentIncludedTraining.Value = false; ModNetwork.Instance?.SendConsent(); Plugin.Log.LogInfo((object)"Voice cloning consent cleared"); } PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); bool flag = (Object)(object)val != (Object)null && (Object)(object)ModNetwork.Instance != (Object)null && ModNetwork.HostStatusKnown && NeedsAnswer(); if (flag && !showing) { Open(val); } else if (!flag && showing) { Close(); } if (showing) { if ((Object)(object)val != (Object)null) { val.disableLookInput = true; val.disableMoveInput = true; } Cursor.lockState = (CursorLockMode)0; Cursor.visible = true; if ((Object)(object)body != (Object)null && (shownSaving != ModNetwork.HostSavesAudio || shownTraining != ModNetwork.HostCollectsText)) { SetBody(); } } } private void Open(PlayerControllerB me) { //IL_0008: 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) showing = true; oldLock = Cursor.lockState; oldVisible = Cursor.visible; lookWasDisabled = me.disableLookInput; moveWasDisabled = me.disableMoveInput; me.disableLookInput = true; me.disableMoveInput = true; if ((Object)(object)root == (Object)null) { Build(me, onGameCanvas: true); } SetBody(); root.SetActive(true); if (!root.activeInHierarchy) { Object.Destroy((Object)(object)root); Build(me, onGameCanvas: false); SetBody(); root.SetActive(true); } } private void Close() { //IL_0087: Unknown result type (might be due to invalid IL or missing references) showing = false; if ((Object)(object)root != (Object)null) { root.SetActive(false); } PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); if ((Object)(object)val != (Object)null) { val.disableLookInput = lookWasDisabled; val.disableMoveInput = moveWasDisabled; } bool flag = (Object)(object)val != (Object)null && (Object)(object)val.quickMenuManager != (Object)null && val.quickMenuManager.isMenuOpen; Cursor.lockState = (CursorLockMode)((!flag) ? ((int)oldLock) : 0); Cursor.visible = flag || oldVisible; } private void Choose(bool allow) { Cfg.VoiceConsent.Value = (allow ? ConsentChoice.Allow : ConsentChoice.Deny); Cfg.ConsentIncludedSaving.Value = allow && ModNetwork.HostSavesAudio; Cfg.ConsentIncludedTraining.Value = allow && ModNetwork.HostCollectsText; Cfg.ConsentIncludesReplay.Value = allow; ModNetwork.Instance?.SendConsent(); Close(); } private void OnDestroy() { if ((Object)(object)root != (Object)null) { Object.Destroy((Object)(object)root); } } private void SetBody() { shownSaving = ModNetwork.HostSavesAudio; shownTraining = ModNetwork.HostCollectsText; string text = (shownSaving ? "<color=#ffffff>THE HOST HAS AUDIO SAVING ON (A DEBUG SETTING).</color> Your voice clips are stored as files on the host's computer until they delete them." : (shownTraining ? "Audio is never stored: clips stay in the host's memory only while the game runs." : "Nothing is stored. Clips stay in the host's memory only while the game runs.")); if (shownTraining) { text += "\n\n<color=#ffffff>THE HOST COLLECTS TRAINING DATA.</color> What you say near the AI copies is saved as text (no audio) on the host's computer, to train a better AI for this mod. Nothing is uploaded unless the host shares it."; } ((TMP_Text)body).text = "A mod in this lobby asks to use your voice.\n\nIf you allow it:\n- The voice chat you already send also goes to the host's computer.\n- There it's turned into text, and used to make an AI copy of your voice that can speak in this game. Short things you said can also be played back as they were. Other players can hear both.\n- It all runs on the host's computer. Nothing goes to an online service."; ((TMP_Text)storageText).text = text; ((TMP_Text)footer).text = "If you don't, your voice isn't sent and nothing speaks with your voice.\n<size=80%>Change it later in the config: Voice > VoiceCloningConsent.</size>"; } private static TMP_FontAsset? GameFont() { TMP_FontAsset[] source = Resources.FindObjectsOfTypeAll<TMP_FontAsset>(); return ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name.Contains("3270") && !((Object)f).name.Contains("Outline"))) ?? ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name.Contains("3270"))) ?? TMP_Settings.defaultFontAsset; } private void Build(PlayerControllerB me, bool onGameCanvas) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_0137: 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_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: 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_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_0312: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_0326: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_03ab: Unknown result type (might be due to invalid IL or missing references) //IL_03b9: Unknown result type (might be due to invalid IL or missing references) //IL_03f2: Unknown result type (might be due to invalid IL or missing references) //IL_03f4: Unknown result type (might be due to invalid IL or missing references) //IL_0400: Unknown result type (might be due to invalid IL or missing references) //IL_0406: Unknown result type (might be due to invalid IL or missing references) //IL_0415: Unknown result type (might be due to invalid IL or missing references) //IL_041b: Unknown result type (might be due to invalid IL or missing references) //IL_0420: Unknown result type (might be due to invalid IL or missing references) //IL_043b: Unknown result type (might be due to invalid IL or missing references) //IL_045e: Unknown result type (might be due to invalid IL or missing references) //IL_047d: Unknown result type (might be due to invalid IL or missing references) //IL_048c: Unknown result type (might be due to invalid IL or missing references) //IL_049a: Unknown result type (might be due to invalid IL or missing references) //IL_04a9: Unknown result type (might be due to invalid IL or missing references) //IL_04dc: Unknown result type (might be due to invalid IL or missing references) //IL_04eb: Unknown result type (might be due to invalid IL or missing references) //IL_04f9: Unknown result type (might be due to invalid IL or missing references) //IL_0508: Unknown result type (might be due to invalid IL or missing references) //IL_050d: Unknown result type (might be due to invalid IL or missing references) //IL_0548: Unknown result type (might be due to invalid IL or missing references) //IL_054f: Expected O, but got Unknown //IL_0565: Unknown result type (might be due to invalid IL or missing references) //IL_056a: Unknown result type (might be due to invalid IL or missing references) //IL_056f: Unknown result type (might be due to invalid IL or missing references) //IL_057d: Unknown result type (might be due to invalid IL or missing references) //IL_058c: Unknown result type (might be due to invalid IL or missing references) //IL_0596: Expected O, but got Unknown //IL_05e9: Unknown result type (might be due to invalid IL or missing references) //IL_062f: Unknown result type (might be due to invalid IL or missing references) //IL_0636: Expected O, but got Unknown //IL_066b: Unknown result type (might be due to invalid IL or missing references) //IL_0675: Expected O, but got Unknown //IL_0694: Unknown result type (might be due to invalid IL or missing references) //IL_0699: Unknown result type (might be due to invalid IL or missing references) //IL_06b4: Expected O, but got Unknown //IL_06c7: Unknown result type (might be due to invalid IL or missing references) //IL_06ee: Unknown result type (might be due to invalid IL or missing references) //IL_0735: Unknown result type (might be due to invalid IL or missing references) //IL_0745: Unknown result type (might be due to invalid IL or missing references) //IL_074a: Unknown result type (might be due to invalid IL or missing references) //IL_0754: Unknown result type (might be due to invalid IL or missing references) //IL_075e: Expected O, but got Unknown //IL_0764: Unknown result type (might be due to invalid IL or missing references) //IL_076d: Unknown result type (might be due to invalid IL or missing references) //IL_077f: Unknown result type (might be due to invalid IL or missing references) //IL_0784: Unknown result type (might be due to invalid IL or missing references) //IL_078e: Unknown result type (might be due to invalid IL or missing references) //IL_0798: Expected O, but got Unknown QuickMenuManager quickMenuManager = me.quickMenuManager; RectTransform val = (RectTransform)((onGameCanvas && (Object)(object)quickMenuManager != (Object)null && (Object)(object)quickMenuManager.menuContainer != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); root = new GameObject("PlayerMimicsConsent", new Type[1] { typeof(RectTransform) }); RectTransform rt = (RectTransform)root.transform; float num = 1f; if ((Object)(object)val != (Object)null) { root.transform.SetParent((Transform)(object)val, false); Place(rt, Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero); root.transform.SetAsLastSibling(); Rect rect = val.rect; if (((Rect)(ref rect)).height > 1f) { rect = val.rect; num = ((Rect)(ref rect)).height / 1080f; } } else { Object.DontDestroyOnLoad((Object)(object)root); Canvas val2 = root.AddComponent<Canvas>(); val2.renderMode = (RenderMode)0; val2.sortingOrder = 5000; CanvasScaler val3 = root.AddComponent<CanvasScaler>(); val3.uiScaleMode = (ScaleMode)1; val3.referenceResolution = new Vector2(1920f, 1080f); val3.matchWidthOrHeight = 0.5f; root.AddComponent<GraphicRaycaster>(); } Button val4 = (((Object)(object)quickMenuManager != (Object)null && (Object)(object)quickMenuManager.mainButtonsPanel != (Object)null) ? ((IEnumerable<Button>)quickMenuManager.mainButtonsPanel.GetComponentsInChildren<Button>(true)).FirstOrDefault((Func<Button, bool>)((Button b) => (Object)(object)((Component)b).GetComponentInChildren<TextMeshProUGUI>(true) != (Object)null)) : null); TextMeshProUGUI val5 = (((Object)(object)val4 != (Object)null) ? ((Component)val4).GetComponentInChildren<TextMeshProUGUI>(true) : null); TMP_FontAsset val6 = (TMP_FontAsset)(((Object)(object)val5 != (Object)null) ? ((object)((TMP_Text)val5).font) : ((object)GameFont())); Material material = (((Object)(object)val5 != (Object)null) ? ((TMP_Text)val5).fontSharedMaterial : null); Color color = (((Object)(object)val5 != (Object)null) ? ((Graphic)val5).color : Orange); Plugin.Log.LogDebug((object)("Consent popup: " + (((Object)(object)val != (Object)null) ? "game menu canvas" : "own canvas") + ", font " + (((Object)(object)val6 != (Object)null) ? ((Object)val6).name : "none"))); Image val7 = (((Object)(object)quickMenuManager != (Object)null && (Object)(object)quickMenuManager.BGPanelTransparency != (Object)null) ? ((Component)quickMenuManager.BGPanelTransparency).GetComponent<Image>() : null); RectTransform val8 = Box(root.transform, "Shade", Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero, ((Object)(object)val7 != (Object)null) ? ((Graphic)val7).color : menuTint); if ((Object)(object)val7 != (Object)null && (Object)(object)val7.sprite != (Object)null) { ((Component)val8).GetComponent<Image>().sprite = val7.sprite; ((Component)val8).GetComponent<Image>().type = val7.type; } ((Graphic)((Component)val8).GetComponent<Image>()).raycastTarget = true; RectTransform val9 = Box(root.transform, "Vignette", Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero, Color.black); Image component = ((Component)val9).GetComponent<Image>(); ((Graphic)component).raycastTarget = false; Image val10 = (((Object)(object)quickMenuManager != (Object)null && (Object)(object)quickMenuManager.menuContainer != (Object)null) ? ((IEnumerable<Image>)quickMenuManager.menuContainer.GetComponentsInChildren<Image>(true)).FirstOrDefault((Func<Image, bool>)((Image i) => (Object)(object)i.sprite != (Object)null && ((Object)i.sprite).name.IndexOf("vignette", StringComparison.OrdinalIgnoreCase) >= 0)) : null); if ((Object)(object)val10 != (Object)null) { component.sprite = val10.sprite; component.type = val10.type; ((Graphic)component).color = ((Graphic)val10).color; } else { component.sprite = VignetteSprite(); } Vector2 val11 = default(Vector2); ((Vector2)(ref val11))..ctor(0.5f, 0.5f); RectTransform val12 = Box(root.transform, "Panel", val11, val11, new Vector2(-470f, -300f) * num, new Vector2(470f, 300f) * num, Color.clear); ((Graphic)((Component)val12).GetComponent<Image>()).raycastTarget = false; Brackets(val12, color, num); float num2 = 40f * num; TextMeshProUGUI val13 = Text((Transform)(object)val12, "Title", val6, material, 34f * num, color, (TextAlignmentOptions)257); Place(((TMP_Text)val13).rectTransform, new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(num2, -84f * num), new Vector2(0f - num2, -28f * num)); ((TMP_Text)val13).text = "YOUR VOICE"; ((TMP_Text)val13).characterSpacing = 8f; RectTransform val14 = Box((Transform)(object)val12, "Rule", new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(num2, -92f * num), new Vector2(0f - num2, -90f * num), color); ((Graphic)((Component)val14).GetComponent<Image>()).raycastTarget = false; GameObject val15 = new GameObject("Column", new Type[2] { typeof(RectTransform), typeof(VerticalLayoutGroup) }); val15.transform.SetParent((Transform)(object)val12, false); Place((RectTransform)val15.transform, Vector2.zero, Vector2.one, new Vector2(num2, 112f * num), new Vector2(0f - num2, -112f * num)); VerticalLayoutGroup component2 = val15.GetComponent<VerticalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)component2).spacing = 18f * num; ((HorizontalOrVerticalLayoutGroup)component2).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)component2).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)component2).childForceExpandHeight = false; ((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth = true; float size = 20f * num; body = Text(val15.transform, "Body", val6, material, size, color, (TextAlignmentOptions)257); ((TMP_Text)body).lineSpacing = 6f; GameObject val16 = new GameObject("StorageNote", new Type[2] { typeof(RectTransform), typeof(VerticalLayoutGroup) }); val16.transform.SetParent(val15.transform, false); VerticalLayoutGroup component3 = val16.GetComponent<VerticalLayoutGroup>(); int num3 = Mathf.RoundToInt(12f * num); ((LayoutGroup)component3).padding = new RectOffset(num3, num3, num3, num3); ((HorizontalOrVerticalLayoutGroup)component3).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)component3).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)component3).childForceExpandHeight = false; Border((RectTransform)val16.transform, Color.white, Mathf.Max(1f, 2f * num)); storageText = Text(val16.transform, "Storage", val6, material, size, Color.white, (TextAlignmentOptions)257); footer = Text(val15.transform, "Footer", val6, material, size, color, (TextAlignmentOptions)257); float num4 = 30f * num; Vector2 val17 = default(Vector2); ((Vector2)(ref val17))..ctor((940f * num - 2f * num2 - num4) / 2f, 56f * num); MenuButton((Transform)(object)val12, val6, material, color, "> Allow", new Vector2(num2, 34f * num), val17, num, (UnityAction)delegate { Choose(allow: true); }); MenuButton((Transform)(object)val12, val6, material, color, "> Don't allow", new Vector2(num2 + val17.x + num4, 34f * num), val17, num, (UnityAction)delegate { Choose(allow: false); }); root.SetActive(false); } private static RectTransform Box(Transform parent, string name, Vector2 anchorMin, Vector2 anchorMax, Vector2 offsetMin, Vector2 offsetMax, Color color) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name, new Type[2] { typeof(RectTransform), typeof(Image) }); val.transform.SetParent(parent, false); RectTransform val2 = (RectTransform)val.transform; Place(val2, anchorMin, anchorMax, offsetMin, offsetMax); ((Graphic)val.GetComponent<Image>()).color = color; return val2; } private static Sprite VignetteSprite() { //IL_001c: 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_0029: Expected O, but got Unknown //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)vignetteSprite != (Object)null) { return vignetteSprite; } Texture2D val = new Texture2D(128, 72, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1 }; Color32[] array = (Color32[])(object)new Color32[9216]; for (int i = 0; i < 72; i++) { for (int j = 0; j < 128; j++) { float num = ((float)j + 0.5f) / 128f * 2f - 1f; float num2 = ((float)i + 0.5f) / 72f * 2f - 1f; float num3 = Mathf.Sqrt(num * num + num2 * num2) / Mathf.Sqrt(2f); float num4 = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.55f, 1f, num3)) * 0.85f; array[i * 128 + j] = new Color32((byte)0, (byte)0, (byte)0, (byte)(num4 * 255f)); } } val.SetPixels32(array); val.Apply(); vignetteSprite = Sprite.Create(val, new Rect(0f, 0f, 128f, 72f), new Vector2(0.5f, 0.5f)); return vignetteSprite; } private static void Brackets(RectTransform box, Color color, float scale) { //IL_0028: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: 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_0087: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: 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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) float num = 4f * scale; float num2 = 36f * scale; float num3 = 10f * scale; float num4 = 13f * scale; Vector2[] array = (Vector2[])(object)new Vector2[4] { Vector2.zero, Vector2.up, Vector2.right, Vector2.one }; Vector2 dir = default(Vector2); foreach (Vector2 val in array) { ((Vector2)(ref dir))..ctor((val.x > 0f) ? (-1f) : 1f, (val.y > 0f) ? (-1f) : 1f); Bar(box, val, color, dir, new Vector2(num2, num)); Bar(box, val, color, dir, new Vector2(num, num2)); Bar(box, val, color, dir, new Vector2(num4, num), new Vector2(num2 + num3, 0f)); Bar(box, val, color, dir, new Vector2(num, num4 * 0.6f), new Vector2(0f, num2 + num3)); } } private static void Bar(RectTransform box, Vector2 corner, Color color, Vector2 dir, Vector2 size, Vector2 offset = default(Vector2)) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(offset.x * dir.x, offset.y * dir.y); Vector2 val2 = val + new Vector2(size.x * dir.x, size.y * dir.y); RectTransform val3 = Box((Transform)(object)box, "Bracket", corner, corner, Vector2.Min(val, val2), Vector2.Max(val, val2), color); ((Graphic)((Component)val3).GetComponent<Image>()).raycastTarget = false; } private static void Border(RectTransform box, Color color, float width) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0077: 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) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) Edge(box, new Vector2(0f, 1f), Vector2.one, new Vector2(0f, 0f - width), Vector2.zero, color); Edge(box, Vector2.zero, new Vector2(1f, 0f), Vector2.zero, new Vector2(0f, width), color); Edge(box, Vector2.zero, new Vector2(0f, 1f), Vector2.zero, new Vector2(width, 0f), color); Edge(box, new Vector2(1f, 0f), Vector2.one, new Vector2(0f - width, 0f), Vector2.zero, color); } private static void Edge(RectTransform box, Vector2 anchorMin, Vector2 anchorMax, Vector2 offsetMin, Vector2 offsetMax, Color color) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) RectTransform val = Box((Transform)(object)box, "Edge", anchorMin, anchorMax, offsetMin, offsetMax, color); ((Graphic)((Component)val).GetComponent<Image>()).raycastTarget = false; ((Component)val).gameObject.AddComponent<LayoutElement>().ignoreLayout = true; } private static void Place(RectTransform rt, Vector2 anchorMin, Vector2 anchorMax, Vector2 offsetMin, Vector2 offsetMax) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) rt.anchorMin = anchorMin; rt.anchorMax = anchorMax; rt.offsetMin = offsetMin; rt.offsetMax = offsetMax; } private static TextMeshProUGUI Text(Transform parent, string name, TMP_FontAsset? font, Material? material, float size, Color color, TextAlignmentOptions align) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }); val.transform.SetParent(parent, false); TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>(); if ((Object)(object)font != (Object)null) { ((TMP_Text)val2).font = font; } if ((Object)(object)material != (Object)null) { ((TMP_Text)val2).fontSharedMaterial = material; } ((TMP_Text)val2).fontSize = size; ((Graphic)val2).color = color; ((TMP_Text)val2).alignment = align; ((TMP_Text)val2).enableWordWrapping = true; ((TMP_Text)val2).richText = true; ((Graphic)val2).raycastTarget = false; return val2; } private static void MenuButton(Transform parent, TMP_FontAsset? font, Material? material, Color color, string label, Vector2 bottomLeft, Vector2 size, float scale, UnityAction onClick) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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_000f: 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_0013: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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_00bd: 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_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) RectTransform val = Box(parent, label, Vector2.zero, Vector2.zero, bottomLeft, bottomLeft + size, Orange); Image component = ((Component)val).GetComponent<Image>(); Button val2 = ((Component)val).gameObject.AddComponent<Button>(); ((Selectable)val2).targetGraphic = (Graphic)(object)component; ColorBlock colors = ((Selectable)val2).colors; ((ColorBlock)(ref colors)).normalColor = new Color(1f, 1f, 1f, 0f); ((ColorBlock)(ref colors)).highlightedColor = Color.white; ((ColorBlock)(ref colors)).selectedColor = new Color(1f, 1f, 1f, 0f); ((ColorBlock)(ref colors)).pressedColor = new Color(0.8f, 0.8f, 0.8f, 1f); ((ColorBlock)(ref colors)).fadeDuration = 0.02f; ((Selectable)val2).colors = colors; ((UnityEvent)val2.onClick).AddListener(onClick); TextMeshProUGUI val3 = Text((Transform)(object)val, "Label", font, material, 26f * scale, color, (TextAlignmentOptions)4097); ((TMP_Text)val3).enableWordWrapping = false; Place(((TMP_Text)val3).rectTransform, Vector2.zero, Vector2.one, new Vector2(14f * scale, 0f), new Vector2(-10f * scale, 0f)); ((TMP_Text)val3).text = label; ((Component)val).gameObject.AddComponent<HoverLabel>().Label = val3; } } internal sealed class HoverLabel : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler { internal TextMeshProUGUI? Label; public void OnPointerEnter(PointerEventData e) { SetHover(on: true); } public void OnPointerExit(PointerEventData e) { SetHover(on: false); } private void OnDisable() { SetHover(on: false); } private void SetHover(bool on) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Label != (Object)null) { ((Graphic)Label).color = (Color)(on ? new Color(0.05f, 0.03f, 0.02f) : ConsentPopup.Orange); } } } internal static class CoronerCompat { internal static bool Installed => Chainloader.PluginInfos.ContainsKey("com.elitemastereric.coroner"); internal static void Init() { if (!Installed) { return; } try { CoronerBridge.Init(); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Coroner integration failed to start: " + ex.Message)); } } internal static void OnDisguised(string name) { if (!Installed) { return; } try { CoronerBridge.RegisterFor(name); } catch (Exception ex) { Plugin.Log.LogDebug((object)("Coroner: " + ex.Message)); } } internal static void OnKill(MimicDisguise disguise, PlayerControllerB victim) { if (!Installed) { return; } try { CoronerBridge.ReportKill(disguise.Name, victim); } catch (Exception ex) { Plugin.Log.LogDebug((object)("Coroner: " + ex.Message)); } } } internal static class CoronerBridge { private const string GenericTag = "DeathEnemyPlayerMimic"; private const string SelfTag = "DeathEnemyPlayerMimicSelf"; private static readonly HashSet<string> injected = new HashSet<string>(); [MethodImpl(MethodImplOptions.NoInlining)] internal static void Init() { Inject("DeathEnemyPlayerMimic", new string[12] { "Was killed by a Masked disguised as a crewmate.", "Trusted the wrong crewmate.", "Never asked for a second opinion.", "Walked with the Impostor.", "Counted the crew. Got one too many.", "Was sure it was a friend.", "Didn't notice the extra crewmate.", "Never checked who they were talking to.", "Was led away by a familiar face.", "Heard a friendly voice. It wasn't.", "Let the wrong one carry the scrap.", "Thought everyone made it back to the ship." }); Inject("DeathEnemyPlayerMimicSelf", new string[8] { "Was killed by a Masked disguised as themselves.", "Met their own double. It went badly.", "Was replaced.", "Was killed by their own face.", "Found out what they look like from behind.", "Had a familiar voice in their ear.", "Was outplayed by themselves.", "Lost an argument with themselves." }); Plugin.Log.LogInfo((object)"Coroner integration on"); } [MethodImpl(MethodImplOptions.NoInlining)] internal static void RegisterFor(string name) { Inject(TagFor(name), NamedLines(name)); } [MethodImpl(MethodImplOptions.NoInlining)] internal static void ReportKill(string copiedName, PlayerControllerB victim) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) string text = ((victim.playerUsername == copiedName) ? "DeathEnemyPlayerMimicSelf" : TagFor(copiedName)); if (!API.IsRegistered(text)) { text = "DeathEnemyPlayerMimic"; } API.SetCauseOfDeath(victim, Cause(text)); } private static string[] NamedLines(string name) { return new string[16] { "Was killed by a Masked disguised as " + name + ".", "Trusted " + name + ". It wasn't " + name + ".", "Followed " + name + " somewhere quiet.", "Should have asked " + name + " a security question.", "Got too close to the thing wearing " + name + ".", "Thought " + name + " was acting a bit off.", "Took " + name + " at their word.", "Was walked home by " + name + ". Not the real one.", "Asked " + name + " to wait up. It did.", "Answered when " + name + " called.", "Followed " + name + "'s voice into the dark.", "Was told by " + name + " that it was safe.", "Stuck with " + name + ". Big mistake.", "Never saw what was wearing " + name + ".", "Didn't know " + name + " had already died.", "Learned " + name + " wasn't " + name + "." }; } private static string TagFor(string name) { uint num = 2166136261u; foreach (char c in name) { num = (num ^ c) * 16777619; } return string.Format("{0}As{1:x8}", "DeathEnemyPlayerMimic", num); } private static AdvancedCauseOfDeath Cause(string tag) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (!API.IsRegistered(tag)) { return API.Register(tag); } return AdvancedCauseOfDeath.Registry[tag]; } private static void Inject(string tag, string[] lines) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (injected.Add(tag)) { Cause(tag); XElement xElement = new XElement("strings"); foreach (string value in lines) { xElement.Add(new XElement(tag, new XAttribute("text", value))); } XDocument xDocument = new XDocument(new XElement("base", xElement)); Plugin instance = Plugin.Instance; string[] array = new string[2] { "LanguageHandler", "FallbackLanguageHandler" }; foreach (string text in array) { object obj = AccessTools.Field(typeof(Plugin), text)?.GetValue(instance); ((obj == null) ? null : AccessTools.Method(obj.GetType(), "PopulateLanguageData", (Type[])null, (Type[])null))?.Invoke(obj, new object[2] { xDocument, true }); } } } } internal sealed class DebugTools : MonoBehaviour { private GUIStyle? style; private void Update() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) Key value = Cfg.SpawnMaskedKey.Value; if ((int)value == 0 || Keyboard.current == null || !((ButtonControl)Keyboard.current[value]).wasPressedThisFrame || !HostServices.IsHost || (Object)(object)HostServices.Instance == (Object)null || (Object)(object)RoundManager.Instance == (Object)null) { return; } PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController; if ((Object)(object)localPlayerController == (Object)null || localPlayerController.isPlayerDead || StartOfRound.Instance.inShipPhase) { Plugin.Log.LogInfo((object)"Spawn key: land on a moon first"); return; } string name = Cfg.SpawnCopies.Value.Trim(); PlayerControllerB val = (PlayerControllerB)((name.Length == 0) ? ((object)localPlayerController) : ((object)(((IEnumerable<PlayerControllerB>)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB p) => p.isPlayerControlled && string.Equals(p.playerUsername, name, StringComparison.OrdinalIgnoreCase))) ?? localPlayerController))); Vector3 position = ((Component)localPlayerController).transform.position + ((Component)localPlayerController).transform.forward * 4f; if ((Object)(object)HostServices.Instance.SpawnMasked(position, ((Component)localPlayerController).transform.eulerAngles.y + 180f, val, revived: false) != (Object)null) { Plugin.Log.LogInfo((object)("Spawned a Masked copying " + val.playerUsername)); } } private void OnGUI() { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: 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_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //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_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) bool flag = Cfg.ShowBrainOverlay.Value && HostServices.IsHost; bool flag2 = Cfg.RevealMasked.Value && HostServices.IsHost; if (!flag && !flag2) { return; } Camera val = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.activeCamera : null); if ((Object)(object)val == (Object)null) { return; } if (style == null) { style = new GUIStyle(GUI.skin.label) { fontSize = 13, alignment = (TextAnchor)7, richText = true }; } Vector2 val4 = default(Vector2); foreach (MimicDisguise item in MimicDisguise.All) { if ((Object)(object)item == (Object)null || (Object)(object)item.Masked == (Object)null || ((EnemyAI)item.Masked).isEnemyDead) { continue; } Vector3 val2 = ((Component)item).transform.position + Vector3.up * 2.6f; Vector3 val3 = val.WorldToScreenPoint(val2); if (!(val3.z <= 0f)) { float num = (float)Screen.width / (float)val.pixelWidth; float num2 = (float)Screen.height / (float)val.pixelHeight; ((Vector2)(ref val4))..ctor(val3.x * num, (float)Screen.height - val3.y * num2); if (flag2) { GUI.color = Color.red; GUI.Label(new Rect(val4.x - 60f, val4.y - 20f, 120f, 20f), "<b>MASKED (" + item.Name + ")</b>", style); } if (flag && item.DebugText.Length > 0) { GUI.color = Color.yellow; GUI.Label(new Rect(val4.x - 200f, val4.y - 110f, 400f, 90f), item.DebugText, style); } GUI.color = Color.white; } } } } internal static class GameContext { private static Vector3? outsideDoor; private static Vector3? insideDoor; private static int doorsForRound = -1; private static void FindDoors() { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) int randomMapSeed = StartOfRound.Instance.randomMapSeed; if (doorsForRound != randomMapSeed || !outsideDoor.HasValue) { doorsForRound = randomMapSeed; outsideDoor = RoundManager.FindMainEntrancePosition(false, true); insideDoor = RoundManager.FindMainEntrancePosition(false, false); } } internal static string Interior() { if ((Object)(object)RoundManager.Instance == (Object)null) { return "facility"; } return RoundManager.Instance.currentDungeonType switch { 0 => "factory", 1 => "mansion", 4 => "mineshaft", _ => "facility", }; } internal static string Where(PlayerControllerB p) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (p.isInHangarShipRoom) { return "inside the ship"; } return Where(((Component)p).transform.position, p.isInsideFactory); } internal static string Where(Vector3 pos, bool inside) { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_006a: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) StartOfRound instance = StartOfRound.Instance; FindDoors(); if (inside) { if (insideDoor.HasValue && Vector3.Distance(pos, insideDoor.Value) < 15f) { return "inside the " + Interior() + ", near the main entrance"; } return "inside the " + Interior(); } if ((Object)(object)instance.shipInnerRoomBounds != (Object)null) { Bounds bounds = instance.shipInnerRoomBounds.bounds; if (((Bounds)(ref bounds)).Contains(pos)) { return "inside the ship"; } } float num = Vector3.Distance(pos, instance.elevatorTransform.position); if (num < 18f) { return "outside, right next to the ship"; } if (outsideDoor.HasValue && Vector3.Distance(pos, outsideDoor.Value) < 15f) { return "outside, at the " + Interior() + "'s main entrance"; } return $"outside on the moon, {Mathf.RoundToInt(num / 10f) * 10} m from the ship"; } internal static string Clock(float hour) { int num = Mathf.FloorToInt(hour) % 24; string text = string.Format("{0} {1}", (num % 12 == 0) ? 12 : (num % 12), (num < 12) ? "AM" : "PM"); object obj; switch (num) { case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: obj = "midday"; break; case 5: case 6: case 7: case 8: obj = "the day just started"; break; case 18: case 19: case 20: obj = "it's getting dark, people are heading back soon"; break; default: obj = "it's late night, outside is very dangerous and the ship leaves at midnight"; break; } string text2 = (string)obj; return "the time is " + text + " (" + text2 + ")"; } internal static JObject Round() { //IL_0013: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Expected O, but got Unknown StartOfRound instance = StartOfRound.Instance; SelectableLevel currentLevel = instance.currentLevel; TimeOfDay instance2 = TimeOfDay.Instance; JObject val = new JObject { ["moon"] = JToken.op_Implicit(((Object)(object)currentLevel != (Object)null) ? currentLevel.PlanetName : "unknown"), ["weather"] = JToken.op_Implicit(((Object)(object)currentLevel != (Object)null) ? ((object)Unsafe.As<LevelWeatherType, LevelWeatherType>(ref currentLevel.currentWeather)/*cast due to .constrained prefix*/).ToString().Replace("None", "clear") : "clear"), ["interior"] = JToken.op_Implicit(Interior()) }; if ((Object)(object)instance2 != (Object)null) { val["quota"] = JToken.op_Implicit($"{instance2.quotaFulfilled} of {instance2.profitQuota} credits sold, {instance2.daysUntilDeadline} days left"); } return val; } } internal sealed class HostServices : MonoBehaviour { private float nextHealthCheck; private readonly Dictionary<ulong, bool> consent = new Dictionary<ulong, bool>(); private readonly Dictionary<(ulong client, int utterance), (ChunkAssembly parts, int rate)> uploads = new Dictionary<(ulong, int), (ChunkAssembly, int)>(); private readonly Dictionary<(int seen, int by), float> lastSeen = new Dictionary<(int, int), float>(); private float nextSightCheck; private int nextLineId; private readonly Dictionary<ulong, (int player, bool revived, PlayerControllerB[] witnesses)> pendingCopies = new Dictionary<ulong, (int, bool, PlayerControllerB[])>(); private readonly Dictionary<ulong, PlayerControllerB[]> reviveWitnesses = new Dictionary<ulong, PlayerControllerB[]>(); private EnemyType? maskedType; private bool? wasInShipPhase; private readonly Dictionary<MaskedPlayerEnemy, float> settingUp = new Dictionary<MaskedPlayerEnemy, float>(); private readonly HashSet<MaskedPlayerEnemy> leftVanilla = new HashSet<MaskedPlayerEnemy>(); internal static HostServices? Instance { get; private set; } internal bool AiOnline { get; private set; } internal static bool IsHost { get { if ((Object)(object)NetworkManager.Singleton != (Object)null) { return NetworkManager.Singleton.IsServer; } return false; } } internal bool WantsVoice { get { if (!AiOnline) { return Cfg.RandomClips.Value; } return true; } } internal EnemyType? MaskedType { get { if ((Object)(object)maskedType != (Object)null) { return maskedType; } SelectableLevel[] levels = StartOfRound.Instance.levels; foreach (SelectableLevel val in levels) { List<SpawnableEnemyWithRarity>[] array = new List<SpawnableEnemyWithRarity>[3] { val.Enemies, val.OutsideEnemies, val.DaytimeEnemies }; for (int j = 0; j < array.Length; j++) { SpawnableEnemyWithRarity val2 = array[j]?.FirstOrDefault((Func<SpawnableEnemyWithRarity, bool>)((SpawnableEnemyWithRarity e) => (Object)(object)e.enemyType != (Object)null && e.enemyType.enemyName == "Masked")); if (val2 != null) { return maskedType = val2.enemyType; } } } return null; } } private void Awake() { Instance = this; } internal void OnSessionStart() { consent.Clear(); uploads.Clear(); lastSeen.Clear(); pendingCopies.Clear(); reviveWitnesses.Clear(); AiOnline = false; nextHealthCheck = 0f; wasInShipPhase = null; HabitRecorder.Clear(); MimicClips.Clear(); } internal static string PlayerKey(PlayerControllerB p) { if (p.playerSteamId == 0L) { return $"{p.playerUsername}#{p.playerClientId}"; } return p.playerSteamId.ToString(); } internal static PlayerControllerB? PlayerByClient(ulong clientId) { if (!((Object)(object)StartOfRound.Instance == (Object)null)) { return ((IEnumerable<PlayerControllerB>)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB p) => p.isPlayerControlled && p.actualClientId == clientId)); } return null; } internal void SetConsent(ulong clientId, bool allowed) { //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown bool value; bool flag = consent.TryGetValue(clientId, out value) && value; consent[clientId] = allowed; PlayerControllerB val = PlayerByClient(clientId); Plugin.Log.LogInfo((object)("Voice cloning consent from " + (val?.playerUsername ?? ("client " + clientId)) + ": " + (allowed ? "allowed" : "denied"))); if (flag && !allowed && (Object)(object)val != (Object)null) { MimicClips.Forget(PlayerKey(val)); Post("/forget", new JObject { ["key"] = JToken.op_Implicit(PlayerKey(val)) }, 10, delegate { }); } } internal bool HasConsent(PlayerControllerB p) { bool value; return consent.TryGetValue(p.actualClientId, out value) && value; } private void Update() { if (!IsHost || (Object)(object)StartOfRound.Instance == (Object)null) { return; } if (Time.realtimeSinceStartup >= nextHealthCheck) { nextHealthCheck = Time.realtimeSinceStartup + 10f; ((MonoBehaviour)this).StartCoroutine(CheckHealth()); } if (Time.time >= nextSightCheck) { nextSightCheck = Time.time + 0.25f; TrackSightings(); } HabitRecorder.Sample(); bool inShipPhase = StartOfRound.Instance.inShipPhase; if (wasInShipPhase != inShipPhase) { bool flag = !wasInShipPhase.HasValue; wasInShipPhase = inShipPhase; if (!flag || !inShipPhase) { OnRoundChanged(!inShipPhase); } } foreach (var item in (from u in uploads where Time.realtimeSinceStartup - u.Value.parts.Started > 30f select u.Key).ToList()) { uploads.Remove(item); } } private void OnRoundChanged(bool started) { //IL_005e: 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) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Expected O, but got Unknown MonsterLure.Reset(); lastSeen.Clear(); SelectableLevel currentLevel = StartOfRound.Instance.currentLevel; Plugin.Log.LogInfo((object)(started ? ("Round started on " + (((Object)(object)currentLevel != (Object)null) ? currentLevel.PlanetName : "?")) : "Round ended")); if (AiOnline) { Post("/round", new JObject { ["state"] = JToken.op_Implicit(started ? "started" : "ended"), ["moon"] = JToken.op_Implicit(((Object)(object)currentLevel != (Object)null) ? currentLevel.PlanetName : "") }, 10, delegate { }); } } private IEnumerator CheckHealth() { UnityWebRequest req = UnityWebRequest.Get(Cfg.ServerUrl.Value.TrimEnd('/') + "/health"); try { req.timeout = 3; yield return req.SendWebRequest(); bool flag = (int)req.result == 1; if (flag != AiOnline) { AiOnline = flag; Plugin.Log.LogInfo((object)(flag ? "AI server is online" : ("AI server is offline (" + Cfg.ServerUrl.Value + "); Masked use scripted behaviour"))); ModNetwork.Instance?.BroadcastHostStatus(); } else if ((Object)(object)ModNetwork.Instance != (Object)null && !ModNetwork.HostStatusKnown) { ModNetwork.Instance.BroadcastHostStatus(); } } finally { ((IDisposable)req)?.Dispose(); } } internal void Post(string path, JObject body, int timeoutSeconds, Action<JObject?> done) { ((MonoBehaviour)this).StartCoroutine(PostRoutine(path, ((JToken)body).ToString((Formatting)0, Array.Empty<JsonConverter>()), timeoutSeconds, done)); } private static IEnumerator PostRoutine(string path, string json, int timeoutSeconds, Action<JObject?> done) { UnityWebRequest req = new UnityWebRequest(Cfg.ServerUrl.Value.TrimEnd('/') + path, "POST"); try { req.uploadHandler = (UploadHandler)new UploadHandlerRaw(Encoding.UTF8.GetBytes(json)); req.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer(); req.SetRequestHeader("Content-Type", "application/json"); req.timeout = timeoutSeconds; yield return req.SendWebRequest(); JObject obj = null; if ((int)req.result == 1) { try { obj = JObject.Parse(req.downloadHandler.text); } catch (Exception ex) { Plugin.Log.LogWarning((object)(path + ": bad answer: " + ex.Message)); } } else { ManualLogSource log = Plugin.Log; string[] obj2 = new string[5] { path, " failed: ", req.error, " ", null }; DownloadHandler downloadHandler = req.downloadHandler; obj2[4] = ((downloadHandler != null) ? downloadHandler.text : null); log.LogDebug((object)string.Concat(obj2)); } try { done(obj); } catch (Exception arg) { Plugin.Log.LogError((object)$"{path} handler failed: {arg}"); } } finally { ((IDisposable)req)?.Dispose(); } } internal void ReceiveVoiceChunk(ulong sender, int utterance, int index, int count, int rate, byte[] data) { if (count <= 0 || count > 200 || rate < 8000 || rate > 48000) { return; } PlayerControllerB val = PlayerByClient(sender); if (!((Object)(object)val == (Object)null) && HasConsent(val) && WantsVoice) { (ulong, int) key = (sender, utterance); if (!uploads.TryGetValue(key, out (ChunkAssembly, int) value)) { value = (new ChunkAssembly(count, Time.realtimeSinceStartup), rate); uploads[key] = value; } if (value.Item1.Count == count && value.Item1.Add(index, data)) { uploads.Remove(key); Ingest(val, AudioCodec.MuLawDecode(value.Item1.Join()), rate); } } } internal void Ingest(PlayerControllerB player, float[] samples, int rate) { //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: 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_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Expected O, but got Unknown if (Cfg.SaveAudioToDisk.Value) { string text = Path.Combine(Plugin.AudioDumpDir, MakeSafe(player.playerUsername), $"{DateTime.Now:yyyyMMdd-HHmmss-fff}.wav"); try { AudioCodec.WriteWav(text, samples, rate); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't save " + text + ": " + ex.Message)); } } bool isPlayerDead = player.isPlayerDead; if (Cfg.RandomClips.Value && !isPlayerDead) { MimicClips.Add(PlayerKey(player), samples, rate); } if (!AiOnline) { return; } JObject body = new JObject { ["key"] = JToken.op_Implicit(PlayerKey(player)), ["name"] = JToken.op_Implicit(player.playerUsername), ["sample_rate"] = JToken.op_Implicit(rate), ["pcm16"] = JToken.op_Implicit(AudioCodec.ToPcm16Base64(samples)), ["source"] = JToken.op_Implicit("voice"), ["dead"] = JToken.op_Implicit(isPlayerDead) }; Post("/ingest", body, 30, delegate(JObject? result) { string text2 = ((result != null) ? ((JToken)result).Value<string>((object)"text") : null) ?? ""; if (text2.Length == 0 || (Object)(object)player == (Object)null || player.isPlayerDead) { return; } List<MimicBrain> list = MimicBrain.All.Where((MimicBrain b) => (Object)(object)b != (Object)null).ToList(); MimicBrain mimicBrain = (from b in list select (brain: b, score: b.ReplyScore(player, text2)) into x where x.score >= 0f orderby x.score select x.brain).FirstOrDefault(); foreach (MimicBrain item in list) { item.OnSpeech(player, text2, (Object)(object)item == (Object)(object)mimicBrain); } }); } private static string MakeSafe(string name) { return string.Concat(name.Select((char c) => (!char.IsLetterOrDigit(c) && c != '-' && c != '_') ? '_' : c)); } internal void Speak(MimicBrain brain, string text, string started = "") { if (Cfg.StreamLines.Value) { ((MonoBehaviour)this).StartCoroutine(StreamLine(brain, text, started)); return; } PlayerControllerB copied = brain.Copied; Post("/speak_line", LineRequest(brain, text), 60, delegate(JObject? result) { if (result != null && Alive(brain)) { if (((JToken)result).Value<bool?>((object)"ready") != true) { Plugin.Log.LogDebug((object)("No cloned voice for " + copied.playerUsername + " yet")); } else { float[] array = ReadPcm(result); if (array.Length != 0) { MimicVoice.Fade(array, 160); int seq = 0; MimicBrain brain2 = brain; HostServices hostServices = this; int num = nextLineId; hostServices.nextLineId = num + 1; SendPiece(brain2, num, ref seq, array, start: true, final: true); } } } }); } internal void PlayClip(MimicBrain brain, float[] samples) { MimicVoice.Fade(samples, 160); int seq = 0; SendPiece(brain, nextLineId++, ref seq, samples, start: true, final: true); } private IEnumerator StreamLine(MimicBrain brain, string text, string startedStream = "") { PlayerControllerB copied = brain.Copied; JObject reply = null; bool answered = false; string stream = startedStream; if (stream.Length == 0) { Post("/speak_stream", LineRequest(brain, text), 15, delegate(JObject? r) { reply = r; answered = true; }); yield return (object)new WaitUntil((Func<bool>)(() => answered)); JObject obj = reply; stream = ((obj != null) ? ((JToken)obj).Value<string>((object)"stream") : null) ?? ""; JObject obj2 = reply; if (((obj2 != null) ? ((JToken)obj2).Value<bool?>((object)"ready") : ((bool?)null)) != true || stream.Length == 0) { Plugin.Log.LogDebug((object)("No cloned voice for " + copied.playerUsername + " yet")); yield break; } } int line = nextLineId++; int seq = 0; int offset = 0; int failures = 0; bool started = false; float since = Time.realtimeSinceStartup; JObject val; while (true) { if (!Alive(brain)) { yield break; } reply = null; answered = false; JObject body = new JObject { ["stream"] = JToken.op_Implicit(stream), ["offset"] = JToken.op_Implicit(offset), ["lead"] = JToken.op_Implicit(Cfg.StreamLeadSeconds.Value) }; Post("/speak_poll", body, 10, delegate(JObject? r) { reply = r; answered = true; }); yield return (object)new WaitUntil((Func<bool>)(() => answered)); if (!Alive(brain)) { yield break; } val = reply; bool flag = Time.realtimeSinceStartup - since > 30f; if (val == null) { int num = failures + 1; failures = num; if (num < 5 && !flag) { yield return (object)new WaitForSecondsRealtime(0.2f); continue; } SendPiece(brain, line, ref seq, Array.Empty<float>(), start: false, final: true); yield break; } failures = 0; bool flag2 = ((JToken)val).Value<bool?>((object)"done") ?? true; if (flag && !flag2) { Plugin.Log.LogWarning((object)("Line for " + copied.playerUsername + " took too long; dropped")); SendPiece(brain, line, ref seq, Array.Empty<float>(), start: false, final: true); yield break; } float[] array = ReadPcm(val); offset = ((JToken)val).Value<int?>((object)"offset") ?? offset; float valueOrDefault = ((JToken)val).Value<float?>((object)"speed").GetValueOrDefault(); float num2 = (float)offset / 16000f; bool flag3 = !started && (flag2 || ((JToken)val).Value<bool?>((object)"start_ok") == true); if (array.Length != 0 || flag3 || flag2) { SendPiece(brain, line, ref seq, array, flag3, flag2); } if (flag3) { started = true; Plugin.Log.LogDebug((object)($"Line for {copied.playerUsername}: playing after {Time.realtimeSinceStartup - since:0.00}s " + "(" + (flag2 ? "complete" : $"streaming at {valueOrDefault:0.00}x with {num2:0.0}s ready") + ")")); } if (flag2) { break; } yield return (object)new WaitForSecondsRealtime(0.1f); } string text2 = ((JToken)val).Value<string>((object)"error") ?? ""; if (text2.Length > 0) { Plugin.Log.LogWarning((object)("Line for " + copied.playerUsername + " failed: " + text2)); } } internal JObject? VoiceRequest(MimicBrain brain) { if (!Cfg.StreamLines.Value || !HasConsent(brain.Copied)) { return null; } JObject val = LineRequest(brain, ""); val.Remove("text"); return val; } internal void CancelLine(string stream) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown Post("/speak_cancel", new JObject { ["stream"] = JToken.op_Implicit(stream) }, 5, delegate { }); } private static JObject LineRequest(MimicBrain brain, string text) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown return new JObject { ["key"] = JToken.op_Implicit(PlayerKey(brain.Copied)), ["name"] = JToken.op_Implicit(brain.Copied.playerUsername), ["as_name"] = JToken.op_Implicit(brain.Renamed ? brain.Name : ""), ["text"] = JToken.op_Implicit(text), ["sample_rate"] = JToken.op_Implicit(16000) }; } private static bool Alive(MimicBrain brain) { if ((Object)(object)brain != (Object)null && (Object)(object)brain.Masked != (Object)null && !((EnemyAI)brain.Masked).isEnemyDead) { return (Object)(object)ModNetwork.Instance != (Object)null; } return false; } private static float[] ReadPcm(JObject r) { string text = ((JToken)r).Value<string>((object)"pcm16") ?? ""; if (text.Length == 0) { return Array.Empty<float>(); } int fromRate = ((JToken)r).Value<int?>((object)"sample_rate") ?? 16000; return AudioCodec.Resample(AudioCodec.FromPcm16Base64(text), fromRate, 16000); } private static void SendPiece(MimicBrain brain, int line, ref int seq, float[] samples, bool start, bool final) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) NetworkObjectReference masked = default(NetworkObjectReference); ((NetworkObjectReference)(ref masked))..ctor(((NetworkBehaviour)brain.Masked).NetworkObject); byte[][] array = AudioCodec.Chunk(AudioCodec.MuLawEncode(samples)); for (int i = 0; i < array.Length; i++) { bool flag = i == array.Length - 1; ModNetwork.Instance.VoiceStreamClientRpc(masked, line, seq++, 16000, array[i], start && flag, final && flag); } } internal bool LeftVanilla(MaskedPlayerEnemy masked) { return leftVanilla.Contains(masked); } internal bool SettingUp(MaskedPlayerEnemy masked) { if (settingUp.TryGetValue(masked, out var value)) { return Time.time - value < 5f; } return false; } internal void OnMaskedStart(MaskedPlayerEnemy masked) { settingUp[masked] = Time.time; ((MonoBehaviour)this).StartCoroutine(SetUp(masked)); } private IEnumerator SetUp(MaskedPlayerEnemy masked) { yield return ((MonoBehaviour)this).StartCoroutine(SetupWhenReady(masked)); settingUp.Remove(masked); } private IEnumerator SetupWhenReady(MaskedPlayerEnemy masked) { yield return (object)new WaitForSeconds(0.5f); if ((Object)(object)masked == (Object)null || ((EnemyAI)masked).isEnemyDead || (Object)(object)ModNetwork.Instance == (Object)null || (Object)(object)((Component)masked).GetComponent<MimicDisguise>() != (Object)null) { yield break; } bool revived = false; bool flag = false; PlayerControllerB val; if (pendingCopies.TryGetValue(((NetworkBehaviour)masked).NetworkObjectId, out (int, bool, PlayerControllerB[]) value)) { pendingCopies.Remove(((NetworkBehaviour)masked).NetworkObjectId); val = StartOfRound.Instance.allPlayerScripts[value.Item1]; revived = value.Item2; if (value.Item3.Length != 0) { reviveWitnesses[((NetworkBehaviour)masked).NetworkObjectId] = value.Item3; } } else if ((Object)(object)masked.mimickingPlayer != (Object)null) { val = masked.mimickingPlayer; revived = val.isPlayerDead; } else { val = ChooseCopy(masked); flag = true; } if ((Object)(object)val == (Object)null) { Plugin.Log.LogInfo((object)"No player to copy; leaving this Masked vanilla"); leftVanilla.RemoveWhere((MaskedPlayerEnemy m) => (Object)(object)m == (Object)null); leftVanilla.Add(masked); } else { ModNetwork.Instance.SetupMimic(masked, val, revived, Cfg.MimicName.Value.Trim()); if (flag && Cfg.SpawnWithScrap.Value) { ((MonoBehaviour)this).StartCoroutine(GiveStartingScrap(masked)); } } } private IEnumerator GiveStartingScrap(MaskedPlayerEnemy masked) { SelectableLevel currentLevel = StartOfRound.Instance.currentLevel; RoundManager round = RoundManager.Instance; if ((Object)(object)currentLevel == (Object)null || (Object)(object)round == (Object)null || currentLevel.spawnableScrap == null) { yield break; } List<SpawnableItemWithRarity> list = currentLevel.spawnableScrap.Where((SpawnableItemWithRarity s) => s.rarity > 0 && (Object)(object)s.spawnableItem != (Object)null && (Object)(object)s.spawnableItem.spawnPrefab != (Object)null && s.spawnableItem.isScrap && !s.spawnableItem.twoHanded && s.spawnableItem.weight <= 1.25f).ToList(); if (list.Count == 0) { yield break; } int roll = Random.Range(0, list.Sum((SpawnableItemWithRarity s) => s.rarity)); Item pick = list.First((SpawnableItemWithRarity s) => (roll -= s.rarity) < 0).spawnableItem; Transform val = (((Object)(object)round.spawnedScrapContainer != (Object)null) ? round.spawnedScrapContainer : StartOfRound.Instance.propsContainer); GameObject val2 = Object.Instantiate<GameObject>(pick.spawnPrefab, ((Component)masked).transform.position + Vector3.up, Quaternion.identity, val); GrabbableObject item = val2.GetComponent<GrabbableObject>(); NetworkObject net = val2.GetComponent<NetworkObject>(); if ((Object)(object)item == (Object)null || (Object)(object)net == (Object)null) { Object.Destroy((Object)(object)val2); yield break; } int value = (item.scrapValue = Mathf.Max(1, (int)((float)Random.Range(pick.minValue, pick.maxValue) * round.scrapValueMultiplier))); item.isInFactory = !((EnemyAI)masked).isOutside; net.Spawn(false); yield return (object)new WaitForSeconds(0.3f); if (!((Object)(object)item == (Object)null) && !((Object)(object)masked == (Object)null) && !((EnemyAI)masked).isEnemyDead) { round.SyncScrapValuesClientRpc((NetworkObjectReference[])(object)new NetworkObjectReference[1] { new NetworkObjectReference(net) }, new int[1] { value }); MimicBrain component = ((Component)masked).GetComponent<MimicBrain>(); if (!((Object)(object)component == (Object)null)) { component.GiveStartingItem(item); Plugin.Log.LogInfo((object)$"{component.Copied.playerUsername}'s Masked starts out holding a {pick.itemName} (${value})"); } } } internal PlayerControllerB[] TakeWitnesses(MaskedPlayerEnemy masked) { if (!reviveWitnesses.TryGetValue(((NetworkBehaviour)masked).NetworkObjectId, out PlayerControllerB[] value)) { return Array.Empty<PlayerControllerB>(); } reviveWitnesses.Remove(((NetworkBehaviour)masked).NetworkObjectId); return value; } private PlayerControllerB? ChooseCopy(MaskedPlayerEnemy masked) { List<PlayerControllerB> list = StartOfRound.Instance.allPlayerScripts.Where((PlayerControllerB p) => p.isPlayerControlled && !p.isPlayerDead).ToList(); if (list.Count == 0) { return null; } int fewest = ((IEnumerable<PlayerControllerB>)list).Min((Func<PlayerControllerB, int>)Copies); list = list.Where((PlayerControllerB p) => Copies(p) == fewest).ToList(); List<PlayerControllerB> list2 = list.Where(HasConsent).ToList(); List<PlayerControllerB> source = ((list2.Count > 0 && Random.value < 0.75f) ? list2 : list); return source.OrderByDescending((PlayerControllerB p) => Vector3.Distance(((Component)p).transform.position, ((Component)masked).transform.position) + Random.Range(0f, 30f)).First(); static int Copies(PlayerControllerB p) { return MimicBrain.All.Count((MimicBrain b) => (Object)(object)b != (Object)null && (Object)(object)b.Masked != (Object)null && !((EnemyAI)b.Masked).isEnemyDead && (Object)(object)b.Copied == (Object)(object)p); } } internal MaskedPlayerEnemy? SpawnMasked(Vector3 position, float yRot, PlayerControllerB? copy, bool revived, PlayerControllerB[]? witnesses = null) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005f: 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) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008b: 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) EnemyType val = MaskedType; if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)"Couldn't find the Masked enemy type"); return null; } Vector3 navMeshPosition = RoundManager.Instance.GetNavMeshPosition(position, default(NavMeshHit), 5f, -1); if (!RoundManager.Instance.GotNavMeshPositionResult) { navMeshPosition = RoundManager.Instance.GetNavMeshPosition(position, default(NavMeshHit), 12f, -1); } if (!RoundManager.Instance.GotNavMeshPositionResult) { Plugin.Log.LogWarning((object)"No walkable ground near there; no Masked spawned"); return null; } NetworkObjectReference val2 = RoundManager.Instance.SpawnEnemyGameObject(navMeshPosition, yRot, -1, val); NetworkObject val3 = default(NetworkObject); if (!((NetworkObjectReference)(ref val2)).TryGet(ref val3, (NetworkManager)null)) { return null; } MaskedPlayerEnemy component = ((Component)val3).GetComponent<MaskedPlayerEnemy>(); if ((Object)(object)copy != (Object)null) { pendingCopies[val3.NetworkObjectId] = ((int)copy.playerClientId, revived, witnesses ?? Array.Empty<PlayerControllerB>()); } return component; } private void TrackSightings() { //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_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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) List<PlayerControllerB> list = StartOfRound.Instance.allPlayerScripts.Where((PlayerControllerB p) => p.isPlayerControlled && !p.isPlayerDead).ToList(); float value = Cfg.WatchedRange.Value; foreach (PlayerControllerB item in list) { Vector3 val = ((Component)item).transform.position + Vector3.up * 1.2f; foreach (PlayerControllerB item2 in list) { if ((Object)(object)item2 != (Object)(object)item && item2.HasLineOfSightToPosition(val, 70f, (int)value, -1f, -1)) { lastSeen[((int)item.playerClientId, (int)item2.playerClientId)] = Time.time; } } } } internal void OnPlayerDied(PlayerControllerB player) { foreach (MimicBrain item in MimicBrain.All.ToList()) { item.OnPlayerDied(player); } if (Cfg.ReviveEnabled.Value && !((Object)(object)player.deadBody == (Object)null) && !StartOfRound.Instance.inShipPhase && !StartOfRound.Instance.shipIsLeaving && !player.isInHangarShipRoom && (!((Object)(object)StartOfRound.Instance.currentLevel != (Object)null) || StartOfRound.Instance.currentLevel.levelID != 3)) { PlayerControllerB[] array = Witnesses(player); string text = ((array.Length != 0) ? ("while " + string.Join(", ", array.Select((PlayerControllerB w) => w.playerUsername)) + " watched") : "with nobody watching"); if (array.Length != 0 && Cfg.ReviveOnlyUnobserved.Value) { Plugin.Log.LogInfo((object)(player.playerUsername + " died " + text + "; no revive")); return; } if (Random.Range(0, 100) >= Cfg.ReviveChancePercent.Value) { Plugin.Log.LogInfo((object)$"{player.playerUsername} died {text}; no revive this time ({Cfg.ReviveChancePercent.Value}% chance)"); return; } Plugin.Log.LogInfo((object)$"{player.playerUsername} died {text}; reviving as a Masked in {Cfg.ReviveDelay.Value:0}s"); ((MonoBehaviour)this).StartCoroutine(Revive(player, array)); } } private PlayerControllerB[] Witnesses(PlayerControllerB dead) { float value; return StartOfRound.Instance.allPlayerScripts.Where((PlayerControllerB q) => (Object)(object)q != (Object)(object)dead && q.isPlayerControlled && !q.isPlayerDead && lastSeen.TryGetValue(((int)dead.playerClientId, (int)q.playerClientId), out value) && Time.time - value < 2f).ToArray(); } private IEnumerator Revive(PlayerControllerB player, PlayerControllerB[] witnesses) { yield return (object)new WaitForSeconds(Cfg.ReviveDelay.Value); DeadBodyInfo deadBody = player.deadBody; if (!((Object)(object)deadBody == (Object)null) && !deadBody.deactivated && !deadBody.isInShip && !StartOfRound.Instance.shipIsLeaving && !StartOfRound.Instance.inShipPhase && (!((Object)(object)deadBody.grabBodyObject != (Object)null) || !deadBody.grabBodyObject.isHeld) && player.isPlayerDead) { Vector3 position = ((Component)deadBody).transform.position; MaskedPlayerEnemy val = SpawnMasked(position, Random.Range(0f, 360f), player, revived: true, witnesses); if (!((Object)(object)val == (Object)null)) { ModNetwork.Instance?.HideDeadBodyClientRpc((int)player.playerClientId); player.redirectToEnemy = (EnemyAI)(object)val; } } } } internal sealed class MimicBrain : MonoBehaviour { private enum FleeStyle { Run, BackAway, Sneak } private struct Poi { public Vector3 Pos; public bool Inside; public string Name; } private enum Reaction { Ignore, BackAway, Sneak, Flee } private readonly struct Danger { public readonly string Name; public readonly Reaction Reaction; public readonly float Range; public Danger(string name, Reaction reaction, float range = 0f) { Name = name; Reaction = reaction; Range = range; } } private PlayerControllerB? aloneWith; private float aloneSince = -1f; private float nextAmbushRoll; private bool lunging; private float stalkUntil; internal static readonly List<MimicBrain> All = new List<MimicBrain>(); private static int pendingRequests; internal MaskedPlayerEnemy Masked; internal MimicDisguise Disguise; internal Behaviour Current; internal PlayerControllerB? Target; private float behaviourStarted; private float behaviourUntil; private Behaviour afterEmote; private int emote; private string signText = ""; internal bool CoverBlown; private readonly HashSet<PlayerControllerB> attackWitnesses = new HashSet<PlayerControllerB>(); private readonly Dictionary<int, float> suspicion = new Dictionary<int, float>(); private readonly HashSet<int> knowsTruth = new HashSet<int>(); private readonly List<(float time, string text)> events = new List<(float, string)>(); private readonly Dictionary<string, float> eventCooldowns = new Dictionary<string, float>(); private readonly List<string> saidRecently = new List<string>(); internal float SecondsWithGroup; private float threatenedUntil; private PlayerControllerB? replyTo; private string replyText = ""; private float replyAt = -100f; private string mustTalkWhy = ""; private float mustTalkUntil; private float nextSmallTalk; private float lastHeardAt = -100f; private bool reassureOnContact; private bool requestPending; private bool pendingIsReply; private int requestSeq; private bool redecide; private float nextDecision; private float lastDecisionAt = -100f; private bool urgent; private int eventSerial; private int decidedSerial; private string earlyStream = ""; private string earlyText = ""; private float lastLine = -100f; internal string LastReason = ""; private string lastSay = ""; private MimicVisualState sentState; private bool stateSent; private float lastOverlay; private float nextClip; private static readonly string[] suspiciousWords = new string[25] { "mimic", "masked", "fake", "impostor", "imposter", "monster", "not real", "are you real", "prove", "is that you", "not you", "who are you", "that's not", "thats not", "sus", "you're real", "youre real", "you are real", "totally real", "very real", "don't have to tell me", "dont have to tell me", "suspicious", "bist du echt", "du bist echt" }; private float lastThoughtAt; internal PlayerControllerB? Anchor; private float anchorUntil; private static readonly string[] warningWords = new string[28] { "stay away", "get away", "go away", "back off", "don't come", "dont come", "leave me alone", "it's following", "its following", "following me", "chasing me", "other way", "go first", "you first", "walk in front", "in front of me", "go ahead", "bleib weg", "geh weg", "hau ab", "lauf weg", "renn weg", "verfolgt mich", "komm nicht", "lass mich", "andere richtung", "geh vor", "du zuerst" }; private readonly HashSet<int> foundOut = new HashSet<int>(); private readonly Dictionary<int, float> accusedAt = new Dictionary<int, float>(); private readonly Dictionary<int, float> runningSince = new Dictionary<int, float>(); private readonly Dictionary<int, float> lastLookedAt = new Dictionary<int, float>(); private HabitRecorder.Clip? habit; private float habitStart; private int habitAppliedFrame = -1; private float habitBaseYaw; private float habitMismatchSince = -1f; private bool habitCrouch; private bool habitSprint; private Vector3? habitPoint; private float habitPointSentAt; private PlayerControllerB? habitPlayer; private float lastHabitJump = -10f; private MimicVoice? voice; private const float MineTriggerRange = 0.75f; private const float MineAvoidRange = 1.6f; private const float WebAvoidRange = 0.9f; private const float NoticeRange = 8f; private static readonly List<Landmine> mines = new List<Landmine>(); private static readonly List<SandSpiderWebTrap> webs = new List<SandSpiderWebTrap>(); private static float hazardsFoundAt = -100f; private readonly HashSet<Object> noticedHazards = new HashSet<Object>(); private readonly Dictionary<Object, int> hazardLooks = new Dictionary<Object, int>(); private Landmine? mineUnderfoot; private float frozenOnMineUntil; private SandSpiderWebTrap? stuckInWeb; private float stuckUntil; private readonly HashSet<SandSpiderWebTrap> trippedWebs = new HashSet<SandSpiderWebTrap>(); private Vector3? detour; private Vector3 detourFor; private readonly NavMeshPath hazardPath = new NavMeshPath(); private GrabbableObject? taskItem; private PlayerControllerB? giveTo; private bool dropAll; private bool dropScrapOnly; private EntranceTeleport? taskDoor; private float stepAt; private float finishAt; private float taskReach = 1.4f; private float lastTaskPath = -100f; private bool shipArrived; private Vector3 shipSpot; private bool taskDone; private float shipRoomSince = -1f; private Behaviour resumeBehaviour; private PlayerControllerB? resumeTarget; private bool droppedOnDeath; private float sideLockUntil; private bool sideLockInside; private float doorArriveAt = -1f; private float lastDoorUse = -100f; private EntranceTeleport? routeDoor; private Vector3 routeFor; private float routePauseAt = -1f; private static readonly List<GrabbableObject> items = new List<GrabbableObject>(); private static float itemsFound = -100f; private static readonly List<EntranceTeleport> doors = new List<EntranceTeleport>(); private static float doorsFound = -100f; private float lastPassingGrab = -100f; private readonly HashSet<GrabbableObject> passedOver = new HashSet<GrabbableObject>(); private readonly Dictionary<EntranceTeleport, Vector3> doorSpots = new Dictionary<EntranceTeleport, Vector3>(); private const float SprintMultiplierMax = 2.25f; private const float SprintSeconds = 5f; private const float AttackSpeed = 8f; private float stamina = 1f; private bool exhausted; private float sprintMultiplier = 1f; private bool isSprinting; private bool crouching; private bool wantSprint; private bool wantCrouch; private float speedCap = float.MaxValue; private float lastPositionSync; private PlayerControllerB? lookPlayer; private float lookPlayerUntil; private Vector3? lookPoint; private float lookPointUntil; pr