using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Threading;
using Microsoft.CodeAnalysis;
using Mirror;
using Steamworks;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BigWalk.Mimics")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BigWalk.Mimics")]
[assembly: AssemblyTitle("BigWalk.Mimics")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[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 BigWalk.Mimics
{
internal sealed class CatchWindow
{
private readonly float _graceUntil;
private uint _target;
private float _since;
internal CatchWindow(float spawnedAt)
{
_graceUntil = spawnedAt + 2.5f;
}
internal bool Update(uint target, float now)
{
if (now < _graceUntil)
{
target = 0u;
}
if (target != _target)
{
_target = target;
_since = now;
}
if (target != 0)
{
return now - _since >= 0.45f;
}
return false;
}
}
internal sealed class MimicActor
{
internal readonly uint Id;
internal readonly uint Model;
private readonly CharacterController Collider;
internal float NextVoice;
private readonly GameObject _root;
private readonly AudioSource _speaker;
private MimicAvatar _avatar;
private PlayerCharacter _avatarSource;
private AudioClip _voiceClip;
private float _bob;
private float _gait;
private float _verticalSpeed;
private float _jump;
private float _yawGoal;
private float _nextStep;
private Vector3 _stride;
private MovementMemory.Step[] _route;
private int _routeIndex;
private MimicState _target;
internal Vector3 Position => _root.transform.position;
internal MimicState State => new MimicState(Id, Model, Position, _root.transform.eulerAngles.y, _bob);
internal MimicActor(MimicState state, PlayerCharacter source)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_0044: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
Id = state.Id;
Model = state.Model;
_target = state;
_root = new GameObject("Big Walk Mimic");
_root.transform.SetPositionAndRotation(state.Position, Quaternion.Euler(0f, state.Yaw, 0f));
_yawGoal = state.Yaw;
Collider = _root.AddComponent<CharacterController>();
Collider.height = 1.55f;
Collider.radius = 0.36f;
Collider.center = new Vector3(0f, 0.8f, 0f);
Collider.stepOffset = 0.24f;
Collider.slopeLimit = 50f;
Collider.minMoveDistance = 0f;
_speaker = _root.AddComponent<AudioSource>();
_speaker.playOnAwake = false;
_speaker.spatialBlend = 1f;
_speaker.minDistance = 2f;
_speaker.maxDistance = 18f;
_speaker.rolloffMode = (AudioRolloffMode)1;
_speaker.dopplerLevel = 0f;
NextVoice = Time.unscaledTime + 3.5f;
SetAppearance(source);
}
internal void SetAppearance(PlayerCharacter source)
{
if (_avatar == null || (!((Object)(object)_avatarSource == (Object)(object)source) && !((Object)(object)source == (Object)null) && source.looks != null))
{
_avatar?.Dispose();
_avatar = new MimicAvatar(_root.transform, source);
_avatarSource = source;
}
}
internal void Simulate(float now, MovementMemory memory, PlayerCharacter target, bool chase)
{
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_029e: Unknown result type (might be due to invalid IL or missing references)
//IL_029f: 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_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0215: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_021d: Unknown result type (might be due to invalid IL or missing references)
//IL_0222: Unknown result type (might be due to invalid IL or missing references)
//IL_0226: Unknown result type (might be due to invalid IL or missing references)
if (now >= _nextStep)
{
if (_route == null || _routeIndex >= _route.Length)
{
_route = memory?.Pick();
_routeIndex = 0;
}
if (_route == null)
{
_stride = Vector3.zero;
_jump = 0f;
}
else
{
MovementMemory.Step step = _route[_routeIndex++];
_yawGoal += Mathf.Clamp(step.Turn, -55f, 55f);
_stride = Vector3.ClampMagnitude(step.Velocity, 5.6f);
_jump = Mathf.Clamp(_jump + step.Velocity.y * 0.125f, 0f, 0.75f);
if (Mathf.Abs(step.Velocity.y) < 0.25f)
{
_jump = Mathf.MoveTowards(_jump, 0f, 0.18f);
}
}
_nextStep = now + 0.125f;
}
Transform transform = _root.transform;
Vector3 val = (((Object)(object)target != (Object)null) ? (((Component)target).transform.position - transform.position) : Vector3.zero);
val.y = 0f;
Vector3 val2 = Quaternion.Euler(0f, _yawGoal, 0f) * new Vector3(_stride.x, 0f, _stride.z);
if (chase && (Object)(object)target != (Object)null && ((Vector3)(ref val)).sqrMagnitude > 0.0001f)
{
float num = ((target.tunings != null) ? target.tunings.forwardSprintSpeed : 0f);
float num2 = ((num > 0f) ? Mathf.Clamp(num * 0.9f, 1.5f, 5.2f) : 3.6f);
val2 = ((Vector3)(ref val)).normalized * num2;
Quaternion val3 = Quaternion.LookRotation(val2);
_yawGoal = ((Quaternion)(ref val3)).eulerAngles.y;
_jump = Mathf.MoveTowards(_jump, 0f, Time.deltaTime * 2f);
}
float num3 = Mathf.Min(Time.deltaTime, 0.05f);
_verticalSpeed = (Collider.isGrounded ? (-1.5f) : Mathf.Max(-20f, _verticalSpeed - 18f * num3));
Collider.Move((val2 + Vector3.up * _verticalSpeed) * num3);
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0f, _yawGoal, 0f), 400f * num3);
_gait += num3 * ((Vector3)(ref val2)).magnitude * 5f;
SetBob(_jump + Mathf.Sin(_gait) * Mathf.Min(0.055f, ((Vector3)(ref val2)).magnitude * 0.025f));
}
internal void Receive(MimicState state)
{
_target = state;
}
internal void Interpolate()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: 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_0056: 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)
Transform transform = _root.transform;
float num = 1f - Mathf.Exp(-16f * Time.unscaledDeltaTime);
transform.SetPositionAndRotation(Vector3.Lerp(transform.position, _target.Position, num), Quaternion.Slerp(transform.rotation, Quaternion.Euler(0f, _target.Yaw, 0f), num));
SetBob(Mathf.Lerp(_bob, _target.Bob, num));
}
private void SetBob(float value)
{
//IL_0012: 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)
_bob = value;
_avatar.Body.localPosition = Vector3.up * value;
}
internal bool CanSee(PlayerCharacter player)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: 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_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_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = Position + Vector3.up * 1.15f;
Vector3 val2 = ((Component)player).transform.position + Vector3.up * 0.9f - val;
RaycastHit val3 = default(RaycastHit);
if (Physics.Raycast(val, ((Vector3)(ref val2)).normalized, ref val3, ((Vector3)(ref val2)).magnitude, -5, (QueryTriggerInteraction)1))
{
return ((Component)((RaycastHit)(ref val3)).collider).transform.IsChildOf(((Component)player).transform);
}
return true;
}
internal void Play(byte[] pcm)
{
StopVoice();
_voiceClip = VoiceMemory.MakeClip(pcm);
if ((Object)(object)_voiceClip != (Object)null)
{
_speaker.PlayOneShot(_voiceClip);
}
}
internal void StopVoice()
{
_speaker.Stop();
if ((Object)(object)_voiceClip != (Object)null)
{
Object.Destroy((Object)(object)_voiceClip);
}
_voiceClip = null;
}
internal void Dispose()
{
StopVoice();
_avatar.Dispose();
Object.Destroy((Object)(object)_root);
}
}
internal sealed class MimicAvatar
{
private readonly List<Mesh> _bakedMeshes = new List<Mesh>();
private readonly List<Material> _materials = new List<Material>();
internal readonly Transform Body;
internal MimicAvatar(Transform parent, PlayerCharacter source)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
Body = new GameObject("Mimic body").transform;
Body.SetParent(parent, false);
if ((Object)(object)source != (Object)null && source.looks != null)
{
CopyPart(((Component)source).transform, source.looks.headRenderers);
CopyPart(((Component)source).transform, source.looks.torsoRenderers);
CopyPart(((Component)source).transform, source.looks.legsRenderers);
}
if (Body.childCount < 2)
{
BuildFallback();
}
}
private void CopyPart(Transform player, Il2CppReferenceArray<LooksRenderer> variants)
{
if (variants == null)
{
return;
}
bool flag = false;
foreach (LooksRenderer item in (Il2CppArrayBase<LooksRenderer>)(object)variants)
{
if (item != null && item.remote && (Object)(object)item.renderer != (Object)null)
{
flag |= CopyRenderer(player, item.renderer);
}
}
if (flag)
{
return;
}
foreach (LooksRenderer item2 in (Il2CppArrayBase<LooksRenderer>)(object)variants)
{
if (item2 != null && (Object)(object)item2.renderer != (Object)null && item2.renderer.enabled && ((Component)item2.renderer).gameObject.activeInHierarchy)
{
CopyRenderer(player, item2.renderer);
}
}
}
private bool CopyRenderer(Transform player, Renderer source)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//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_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: 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_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Expected O, but got Unknown
SkinnedMeshRenderer val = ((Il2CppObjectBase)source).TryCast<SkinnedMeshRenderer>();
Mesh val2;
if ((Object)(object)val != (Object)null)
{
if ((Object)(object)val.sharedMesh == (Object)null)
{
return false;
}
val2 = new Mesh();
val.BakeMesh(val2);
if (val2.vertexCount == 0)
{
Object.Destroy((Object)(object)val2);
return false;
}
_bakedMeshes.Add(val2);
}
else
{
MeshFilter component = ((Component)source).GetComponent<MeshFilter>();
if ((Object)(object)component == (Object)null || (Object)(object)component.sharedMesh == (Object)null)
{
return false;
}
val2 = component.sharedMesh;
}
GameObject val3 = new GameObject("Copied appearance");
val3.transform.SetParent(Body, false);
val3.transform.localPosition = player.InverseTransformPoint(((Component)source).transform.position);
val3.transform.localRotation = Quaternion.Inverse(player.rotation) * ((Component)source).transform.rotation;
val3.transform.localScale = ((Component)source).transform.lossyScale;
val3.AddComponent<MeshFilter>().sharedMesh = val2;
MeshRenderer obj = val3.AddComponent<MeshRenderer>();
((Renderer)obj).sharedMaterials = source.sharedMaterials;
MaterialPropertyBlock val4 = new MaterialPropertyBlock();
source.GetPropertyBlock(val4);
((Renderer)obj).SetPropertyBlock(val4);
return true;
}
private void BuildFallback()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: 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_0068: 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_009e: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
AddShape((PrimitiveType)1, new Vector3(0f, 0.65f, 0f), new Vector3(0.64f, 0.59f, 0.53f), new Color(0.29f, 0.15f, 0.38f));
AddShape((PrimitiveType)0, new Vector3(0f, 1.35f, 0f), new Vector3(0.7f, 0.57f, 0.63f), new Color(0.44f, 0.23f, 0.53f));
for (int i = -1; i <= 1; i += 2)
{
AddShape((PrimitiveType)0, new Vector3((float)i * 0.16f, 1.4f, 0.27f), new Vector3(0.13f, 0.17f, 0.11f), new Color(1f, 0.79f, 0.41f));
}
}
private void AddShape(PrimitiveType type, Vector3 position, Vector3 scale, Color color)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: 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)
GameObject obj = GameObject.CreatePrimitive(type);
obj.transform.SetParent(Body, false);
obj.transform.localPosition = position;
obj.transform.localScale = scale;
Collider component = obj.GetComponent<Collider>();
component.enabled = false;
Object.Destroy((Object)(object)component);
Material material = obj.GetComponent<Renderer>().material;
material.color = color;
_materials.Add(material);
}
internal void Dispose()
{
Object.Destroy((Object)(object)((Component)Body).gameObject);
foreach (Mesh bakedMesh in _bakedMeshes)
{
Object.Destroy((Object)(object)bakedMesh);
}
foreach (Material material in _materials)
{
Object.Destroy((Object)(object)material);
}
}
}
public sealed class MimicMode : MonoBehaviour
{
private readonly Dictionary<uint, PlayerCharacter> _players = new Dictionary<uint, PlayerCharacter>();
private readonly Dictionary<uint, MovementMemory> _movement = new Dictionary<uint, MovementMemory>();
private readonly Dictionary<uint, MimicActor> _mimics = new Dictionary<uint, MimicActor>();
private readonly Dictionary<ulong, uint> _steamPlayers = new Dictionary<ulong, uint>();
private readonly Dictionary<ulong, ulong> _joined = new Dictionary<ulong, ulong>();
private readonly Dictionary<uint, float> _lastVoiceSubmission = new Dictionary<uint, float>();
private readonly HashSet<uint> _participants = new HashSet<uint>();
private readonly HashSet<uint> _eliminated = new HashSet<uint>();
private readonly List<uint> _alive = new List<uint>();
private readonly Spectator _spectator = new Spectator();
private readonly Dictionary<uint, CatchWindow> _catch = new Dictionary<uint, CatchWindow>();
private readonly List<uint> _ordered = new List<uint>();
private readonly List<Vector3> _positions = new List<Vector3>();
private readonly SplitSpawn _split = new SplitSpawn();
private readonly List<uint> _remove = new List<uint>();
private readonly List<ulong> _close = new List<ulong>();
private readonly VoiceMemory _voice = new VoiceMemory();
private SteamChannel _channel;
private Camera _camera;
private PlayerCharacter _local;
private bool _host;
private bool _smoke;
private bool _loggedError;
private bool _roundOver;
private SteamChannel _smokeChannel;
private ulong _smokePeer;
private bool _smokeJoinReceived;
private bool _smokeVoiceReceived;
private float _smokeProbeAt;
private float _smokeProbeEnds;
private int _scene = -1;
private uint _nextId;
private uint _sequence;
private uint _lastSequence;
private ulong _steamHost;
private ulong _round;
private ulong _joinTag;
private float _observeAt;
private float _joinAt;
private float _syncAt;
private float _autoAt;
private float _receivedAt;
private float _statusUntil;
private string _status = "";
public MimicMode(IntPtr ptr)
: base(ptr)
{
}
private void Awake()
{
_smoke = Array.Exists(Environment.GetCommandLineArgs(), (string arg) => arg == "--bigwalk-mimics-smoke");
}
private void Update()
{
try
{
UpdateMode();
_loggedError = false;
}
catch (Exception ex)
{
if (!_loggedError)
{
((BasePlugin)Plugin.Instance).Log.LogError((object)ex);
_loggedError = true;
}
}
}
private void UpdateMode()
{
//IL_004d: 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_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_0269: Unknown result type (might be due to invalid IL or missing references)
//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
if (_smoke)
{
_smoke = false;
SmokeTest();
_smokeProbeAt = Time.unscaledTime + 8f;
}
if (_smokeProbeAt > 0f || _smokeChannel != null)
{
ProbeSteam();
}
PlayerCharacter localPlayerCharacter = WorldManager.localPlayerCharacter;
Scene activeScene = SceneManager.GetActiveScene();
int num = SceneHandle.op_Implicit(((Scene)(ref activeScene)).handle);
bool flag = (Object)(object)localPlayerCharacter != (Object)null && NetworkServer.active;
if (_scene != num || (Object)(object)_local != (Object)(object)localPlayerCharacter || _host != flag)
{
ResetWorld();
_scene = num;
_local = localPlayerCharacter;
_host = flag;
_joinTag = NewTag();
_round = (flag ? NewTag() : 0);
if ((Object)(object)localPlayerCharacter != (Object)null)
{
Status(flag ? "Mimics spawn when the group splits" : "Looking for the host's Mimics mod");
}
}
if ((Object)(object)localPlayerCharacter == (Object)null || ((NetworkBehaviour)localPlayerCharacter).netId == 0)
{
return;
}
WorldManager instance = WorldManager.instance;
_camera = (((Object)(object)instance != (Object)null && (Object)(object)instance.playerCameraReferences != (Object)null) ? instance.playerCameraReferences.playerCamera : null);
if ((Object)(object)_camera == (Object)null && (Object)(object)localPlayerCharacter.cameraTransform != (Object)null)
{
_camera = ((Component)localPlayerCharacter.cameraTransform).GetComponent<Camera>();
}
if ((Object)(object)_camera == (Object)null)
{
_camera = Camera.main;
}
float unscaledTime = Time.unscaledTime;
bool flag2 = unscaledTime >= _observeAt;
if (flag2)
{
ObservePlayers();
_observeAt = unscaledTime + 0.125f;
}
if (_host ? (_steamPlayers.Count > 0) : (_steamHost != 0))
{
UpdateNetwork(unscaledTime);
}
Plugin instance2 = Plugin.Instance;
if (Input.GetKeyDown(instance2.Clear.Value))
{
_voice.Cancel();
StopVoices(((NetworkBehaviour)localPlayerCharacter).netId);
if (_host)
{
Withdraw(((NetworkBehaviour)localPlayerCharacter).netId);
}
else if (_round != 0L)
{
SteamChannel.Send(_steamHost, Wire.Write(Message.Withdraw, _round), reliable: true);
}
Status("Your mimic voice samples were cleared");
}
if (_eliminated.Contains(((NetworkBehaviour)localPlayerCharacter).netId))
{
_voice.Cancel();
}
if (Input.GetKeyDown(instance2.Record.Value) && !_voice.Recording && !_eliminated.Contains(((NetworkBehaviour)localPlayerCharacter).netId))
{
if (_round == 0L)
{
Status("The host's Mimics mod hasn't connected yet");
}
else
{
Status(_voice.Start() ? "Recording a mimic line (4 seconds max)" : "Enable your game mic before recording a mimic line");
}
}
if (_voice.Recording && _voice.Poll(Input.GetKey(instance2.Record.Value), out var pcm))
{
if (pcm == null)
{
Status("No voice captured");
}
else if (_host)
{
_voice.Add(((NetworkBehaviour)localPlayerCharacter).netId, pcm);
Status("Mimic voice line saved");
}
else if (_round != 0L && SteamChannel.Send(_steamHost, Wire.Write(Message.Sample, _round, delegate(BinaryWriter writer)
{
writer.Write(pcm);
}), reliable: true))
{
Status("Mimic voice line sent to the host");
}
else
{
Status("Mimic voice line could not reach the host");
}
}
if (!_host)
{
foreach (MimicActor value2 in _mimics.Values)
{
value2.Interpolate();
}
return;
}
if (Input.GetKeyDown(instance2.Restart.Value))
{
RestartHunt();
}
RebuildSurvivors();
if (_roundOver)
{
return;
}
if (flag2)
{
UpdateAutomaticSpawn(unscaledTime, instance2.AutoSpawn.Value);
}
foreach (MimicActor mimic in _mimics.Values)
{
_movement.TryGetValue(mimic.Model, out var value);
PlayerCharacter val = FindTarget(mimic);
mimic.Simulate(unscaledTime, value, val, (Object)(object)val != (Object)null);
TrackCatch(mimic, val, unscaledTime);
if (unscaledTime < mimic.NextVoice)
{
continue;
}
mimic.NextVoice = unscaledTime + Random.Range(7f, 15f);
if (_voice.TryPick(mimic.Model, out var line))
{
mimic.Play(line);
Broadcast(Wire.Write(Message.Play, _round, delegate(BinaryWriter writer)
{
writer.Write(mimic.Id);
writer.Write(line);
}), reliable: true);
}
}
if (_alive.Count == 0 && _eliminated.Count > 0)
{
_roundOver = true;
RemoveAll();
_syncAt = 0f;
}
}
private void ObservePlayers()
{
//IL_00c8: 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_0100: Invalid comparison between Unknown and I4
_players.Clear();
_ordered.Clear();
_steamPlayers.Clear();
ulong num = 0uL;
List<PlayerCharacter> allPlayerCharacters = PlayerCharacter.allPlayerCharacters;
if (allPlayerCharacters != null)
{
Enumerator<PlayerCharacter> enumerator = allPlayerCharacters.GetEnumerator();
while (enumerator.MoveNext())
{
PlayerCharacter current = enumerator.Current;
if ((Object)(object)current == (Object)null || ((NetworkBehaviour)current).netId == 0 || !((Component)current).gameObject.activeInHierarchy)
{
continue;
}
uint netId = ((NetworkBehaviour)current).netId;
if (!_players.TryAdd(netId, current))
{
continue;
}
_ordered.Add(netId);
if (_host)
{
if (!_movement.TryGetValue(netId, out var value))
{
value = (_movement[netId] = new MovementMemory());
}
value.Observe(((Component)current).transform.position, Heading(current));
}
PlayerNetworking playerNetworking = current.playerNetworking;
if ((Object)(object)current == (Object)(object)_local || (Object)(object)playerNetworking == (Object)null || (int)playerNetworking.platform != 2)
{
continue;
}
ulong result = playerNetworking.userPlatformId;
if (result >> 56 != 1 || ((result >> 52) & 0xF) != 1)
{
ulong.TryParse(playerNetworking.userPlatformIdString, out result);
}
if (result >> 56 == 1 && ((result >> 52) & 0xF) == 1)
{
_steamPlayers[result] = netId;
if (playerNetworking.isHost)
{
num = result;
}
}
}
}
_ordered.Sort();
if (!_host && _steamHost != num)
{
if (_steamHost != 0L)
{
CloseQuietly(_steamHost);
}
_steamHost = num;
_joinAt = 0f;
DisconnectClient();
}
if (!_host)
{
return;
}
_remove.Clear();
foreach (uint key in _movement.Keys)
{
if (!_players.ContainsKey(key))
{
_remove.Add(key);
}
}
foreach (uint item in _remove)
{
_movement.Remove(item);
_lastVoiceSubmission.Remove(item);
Withdraw(item);
}
_close.Clear();
foreach (ulong key2 in _joined.Keys)
{
if (!_steamPlayers.ContainsKey(key2))
{
_close.Add(key2);
}
}
foreach (ulong item2 in _close)
{
_joined.Remove(item2);
CloseQuietly(item2);
}
}
private void UpdateNetwork(float now)
{
if (_channel == null)
{
_channel = new SteamChannel();
}
if (now >= _joinAt)
{
_joinAt = now + 2f;
if (_host)
{
foreach (ulong key in _steamPlayers.Keys)
{
if (!_joined.ContainsKey(key))
{
SteamChannel.Accept(key);
}
}
}
else if (_round == 0L)
{
SteamChannel.Send(_steamHost, Wire.Write(Message.Join, _joinTag), reliable: true);
}
}
_channel.Read((ulong peer) => (!_host) ? (peer == _steamHost) : _steamPlayers.ContainsKey(peer), ReceivePacket);
if (_host && _joined.Count > 0 && now >= _syncAt)
{
_syncAt = now + 0.1f;
Broadcast(Wire.Write(Message.State, _round, delegate(BinaryWriter writer)
{
writer.Write(++_sequence);
writer.Write((byte)_mimics.Count);
foreach (MimicActor value in _mimics.Values)
{
Wire.WriteState(writer, value.State);
}
Wire.WriteRoster(writer, _roundOver, _alive, _eliminated);
}), reliable: false);
}
else if (!_host && _round != 0L && now - _receivedAt > 8f)
{
DisconnectClient();
_joinTag = NewTag();
Status("Mimic connection interrupted");
}
}
private void ReceivePacket(ulong peer, byte[] payload)
{
try
{
using BinaryReader reader = new BinaryReader(new MemoryStream(payload, writable: false));
if (Wire.Read(reader, out var kind, out var tag))
{
if (_host)
{
ReceiveFromPlayer(peer, kind, tag, reader);
}
else
{
ReceiveFromHost(kind, tag, reader);
}
}
}
catch (InvalidDataException)
{
}
catch (EndOfStreamException)
{
}
}
private void ReceiveFromPlayer(ulong peer, Message kind, ulong tag, BinaryReader reader)
{
if (!_steamPlayers.TryGetValue(peer, out var value))
{
return;
}
int num = Wire.Remaining(reader);
if (kind == Message.Join && num == 0)
{
_joined[peer] = tag;
SteamChannel.Send(peer, Wire.Write(Message.Welcome, tag, delegate(BinaryWriter writer)
{
writer.Write(_round);
}), reliable: true);
}
else
{
if (tag != _round || !_joined.ContainsKey(peer))
{
return;
}
if (kind == Message.Sample && num >= 3000 && num <= 48000)
{
float unscaledTime = Time.unscaledTime;
if (!_lastVoiceSubmission.TryGetValue(value, out var value2) || !(unscaledTime - value2 < 0.5f))
{
_lastVoiceSubmission[value] = unscaledTime;
_voice.Add(value, reader.ReadBytes(num));
}
}
else if (kind == Message.Withdraw && num == 0)
{
Withdraw(value);
}
}
}
private void ReceiveFromHost(Message kind, ulong tag, BinaryReader reader)
{
int num = Wire.Remaining(reader);
if (kind == Message.Welcome && tag == _joinTag && num == 8)
{
ulong num2 = reader.ReadUInt64();
if (num2 != 0L && _round != num2)
{
DisconnectClient();
_round = num2;
_receivedAt = Time.unscaledTime;
Status("Mimic hunt connected / Run if one spots you");
}
}
else
{
if (_round == 0L || tag != _round)
{
return;
}
if (kind == Message.State && num >= 8)
{
ReceiveState(reader);
}
else if (kind == Message.Play && num >= 3004 && num <= 48004)
{
if (_mimics.TryGetValue(reader.ReadUInt32(), out var value))
{
value.Play(reader.ReadBytes(num - 4));
}
}
else if (kind == Message.Stop && num == 4)
{
StopVoices(reader.ReadUInt32());
}
}
}
private void ReceiveState(BinaryReader reader)
{
uint num = reader.ReadUInt32();
int num2 = reader.ReadByte();
if (num <= _lastSequence || num2 > 2 || Wire.Remaining(reader) < num2 * 28 + 3)
{
return;
}
MimicState[] array = new MimicState[num2];
for (int i = 0; i < num2; i++)
{
array[i] = Wire.ReadState(reader);
for (int j = 0; j < i; j++)
{
if (array[i].Id == array[j].Id)
{
return;
}
}
}
HuntRoster huntRoster = Wire.ReadRoster(reader);
_roundOver = huntRoster.RoundOver;
_alive.Clear();
_alive.AddRange(huntRoster.Alive);
_eliminated.Clear();
_eliminated.UnionWith(huntRoster.Eliminated);
_lastSequence = num;
_receivedAt = Time.unscaledTime;
_remove.Clear();
foreach (KeyValuePair<uint, MimicActor> pair in _mimics)
{
if (!Array.Exists(array, (MimicState mimicState) => mimicState.Id == pair.Key))
{
_remove.Add(pair.Key);
}
}
foreach (uint item in _remove)
{
Remove(item);
}
MimicState[] array2 = array;
for (int num3 = 0; num3 < array2.Length; num3++)
{
MimicState state = array2[num3];
_players.TryGetValue(state.Model, out var value);
if (!_mimics.TryGetValue(state.Id, out var value2))
{
_mimics[state.Id] = new MimicActor(state, value);
continue;
}
value2.SetAppearance(value);
value2.Receive(state);
}
}
private void Broadcast(byte[] packet, bool reliable)
{
foreach (ulong key in _joined.Keys)
{
SteamChannel.Send(key, packet, reliable);
}
}
private void RebuildSurvivors()
{
_participants.Clear();
if ((Object)(object)_local != (Object)null)
{
_participants.Add(((NetworkBehaviour)_local).netId);
}
foreach (ulong key in _joined.Keys)
{
if (_steamPlayers.TryGetValue(key, out var value))
{
_participants.Add(value);
}
}
_eliminated.IntersectWith(_participants);
_alive.Clear();
foreach (uint item in _ordered)
{
if (_participants.Contains(item) && !_eliminated.Contains(item))
{
_alive.Add(item);
}
}
}
private PlayerCharacter FindTarget(MimicActor mimic)
{
//IL_0033: 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_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)
PlayerCharacter result = null;
float num = 196f;
foreach (uint item in _alive)
{
PlayerCharacter val = _players[item];
Vector3 val2 = ((Component)val).transform.position - mimic.Position;
float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
if (!(sqrMagnitude >= num) && mimic.CanSee(val))
{
num = sqrMagnitude;
result = val;
}
}
return result;
}
private void TrackCatch(MimicActor mimic, PlayerCharacter player, float now)
{
//IL_003d: 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_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
if (!_catch.TryGetValue(mimic.Id, out var value))
{
value = (_catch[mimic.Id] = new CatchWindow(now));
}
int num;
if ((Object)(object)player != (Object)null)
{
Vector3 val = ((Component)player).transform.position - mimic.Position;
if (((Vector3)(ref val)).sqrMagnitude <= 1.9599999f && mimic.CanSee(player))
{
num = (int)((NetworkBehaviour)player).netId;
goto IL_006e;
}
}
num = 0;
goto IL_006e;
IL_006e:
uint num2 = (uint)num;
if (value.Update(num2, now))
{
_eliminated.Add(num2);
_alive.Remove(num2);
_syncAt = 0f;
}
}
private void RestartHunt()
{
RemoveAll();
_eliminated.Clear();
_roundOver = false;
_split.Reset();
_autoAt = 0f;
_syncAt = 0f;
Status("The hunt restarted");
}
private void UpdateAutomaticSpawn(float now, bool enabled)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
if (!enabled)
{
_split.Reset();
return;
}
_positions.Clear();
foreach (uint item in _alive)
{
_positions.Add(((Component)_players[item]).transform.position);
}
if (_split.Ready(_positions, now, out var anchor, out var model) && !(now < _autoAt) && _mimics.Count < 2)
{
_autoAt = now + (Spawn(_players[_alive[anchor]], _players[_alive[model]]) ? Random.Range(45f, 75f) : 10f);
}
}
private bool Spawn(PlayerCharacter anchor, PlayerCharacter model)
{
//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_0015: 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_001f: 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_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: 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_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_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)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//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_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: 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_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = ((Component)anchor).transform.position + Vector3.up * 0.8f;
float num = Random.Range(0f, 360f);
float num2 = Random.Range(7f, 11f);
float[] array = new float[6] { 0f, 45f, -45f, 90f, -90f, 180f };
RaycastHit val3 = default(RaycastHit);
foreach (float num3 in array)
{
Vector3 val2 = Quaternion.Euler(0f, num + num3, 0f) * Vector3.forward;
if (!Physics.Raycast(val, val2, num2, -5, (QueryTriggerInteraction)1) && Physics.Raycast(val + num2 * val2 + Vector3.up, Vector3.down, ref val3, 4f, -5, (QueryTriggerInteraction)1) && !(((RaycastHit)(ref val3)).normal.y < 0.55f))
{
Vector3 val4 = ((RaycastHit)(ref val3)).point + Vector3.up * 0.05f;
if (!Physics.CheckCapsule(val4 + Vector3.up * 0.42f, val4 + Vector3.up * 1.23f, 0.34f, -5, (QueryTriggerInteraction)1))
{
uint num4 = ++_nextId;
_mimics.Add(num4, new MimicActor(new MimicState(num4, ((NetworkBehaviour)model).netId, val4, Heading(model), 0f), model));
_syncAt = 0f;
return true;
}
}
}
return false;
}
private static float Heading(PlayerCharacter player)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)player.kernal != (Object)null))
{
return ((Component)player).transform.eulerAngles.y;
}
return player.kernal.eulerAngles.y;
}
private void Withdraw(uint player)
{
_voice.Withdraw(player);
StopVoices(player);
if (_joined.Count > 0)
{
Broadcast(Wire.Write(Message.Stop, _round, delegate(BinaryWriter writer)
{
writer.Write(player);
}), reliable: true);
}
}
private void StopVoices(uint player)
{
foreach (MimicActor value in _mimics.Values)
{
if (value.Model == player)
{
value.StopVoice();
}
}
}
private void Status(string value)
{
_status = value;
_statusUntil = Time.unscaledTime + 4.5f;
}
private void LateUpdate()
{
if ((Object)(object)_local == (Object)null || !_eliminated.Contains(((NetworkBehaviour)_local).netId))
{
_spectator.Exit();
return;
}
_spectator.Enter(_local, _camera);
PlayerMenu menu = _local.menu;
if (menu != null)
{
menu.Update();
}
int count = _alive.Count;
if (count != 0)
{
int num = _alive.IndexOf(_spectator.Target);
if (num < 0)
{
num = 0;
}
else if (Input.GetKeyDown((KeyCode)275))
{
num = (num + 1) % count;
}
else if (Input.GetKeyDown((KeyCode)276))
{
num = (num + count - 1) % count;
}
uint num2 = _alive[num];
if (_players.TryGetValue(num2, out var value) && !((Object)(object)value == (Object)null))
{
_spectator.Select(num2);
_spectator.Track(((Component)value).transform, Heading(value));
}
}
}
private void OnGUI()
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_local == (Object)null)
{
return;
}
if (_voice.Recording || Time.unscaledTime < _statusUntil)
{
GUI.Box(new Rect((float)(Screen.width - 480) / 2f, (float)(Screen.height - 110), 480f, 25f), _status);
}
if (!_eliminated.Contains(((NetworkBehaviour)_local).netId))
{
return;
}
string text = (_roundOver ? "Everyone was caught" : "Caught — spectating");
if (!_roundOver && _players.TryGetValue(_spectator.Target, out var value) && (Object)(object)value != (Object)null)
{
PlayerNetworking playerNetworking = value.playerNetworking;
string text2 = ((playerNetworking != null) ? playerNetworking.username : null);
if (!string.IsNullOrWhiteSpace(text2))
{
text = "Spectating " + text2;
}
}
GUI.Box(new Rect((float)(Screen.width - 420) / 2f, 24f, 420f, 46f), text + "\n" + ((!_roundOver) ? "Left / Right arrows to switch" : (_host ? "F11 to restart the hunt" : "Waiting for the host to restart")));
}
private void Remove(uint id)
{
if (_mimics.Remove(id, out var value))
{
value.Dispose();
}
_catch.Remove(id);
}
private void RemoveAll()
{
foreach (MimicActor value in _mimics.Values)
{
value.Dispose();
}
_mimics.Clear();
_catch.Clear();
}
private void DisconnectClient()
{
RemoveAll();
_voice.Clear();
_round = 0uL;
_lastSequence = 0u;
}
private void ResetWorld()
{
DisconnectClient();
_spectator.Exit();
_alive.Clear();
_participants.Clear();
_eliminated.Clear();
_roundOver = false;
if (_steamHost != 0L)
{
CloseQuietly(_steamHost);
}
foreach (ulong key in _joined.Keys)
{
CloseQuietly(key);
}
_joined.Clear();
_steamPlayers.Clear();
_players.Clear();
_ordered.Clear();
_movement.Clear();
_lastVoiceSubmission.Clear();
_steamHost = 0uL;
_nextId = (_sequence = 0u);
_split.Reset();
_positions.Clear();
_observeAt = (_joinAt = (_syncAt = (_autoAt = (_statusUntil = 0f))));
}
private static void CloseQuietly(ulong peer)
{
try
{
SteamChannel.Close(peer);
}
catch (Exception ex)
{
((BasePlugin)Plugin.Instance).Log.LogDebug((object)ex);
}
}
private static ulong NewTag()
{
Span<byte> obj = stackalloc byte[8];
RandomNumberGenerator.Fill(obj);
return BitConverter.ToUInt64(obj) | 1;
}
private void OnDestroy()
{
ResetWorld();
}
private void ProbeSteam()
{
//IL_002d: 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_0034: 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_00d4: Expected O, but got Unknown
float unscaledTime = Time.unscaledTime;
if (_smokeProbeAt > 0f && unscaledTime >= _smokeProbeAt)
{
_smokeProbeAt = 0f;
CSteamID steamID = SteamUser.GetSteamID();
_smokePeer = steamID.m_SteamID;
if (_smokePeer == 0L)
{
((BasePlugin)Plugin.Instance).Log.LogWarning((object)"Steam smoke probe could not obtain a local player ID.");
return;
}
_smokeChannel = new SteamChannel();
_smokeProbeEnds = unscaledTime + 8f;
bool flag = SteamChannel.Send(_smokePeer, Wire.Write(Message.Join, 7uL), reliable: true);
bool flag2 = SteamChannel.Send(_smokePeer, Wire.Write(Message.Play, 7uL, delegate(BinaryWriter writer)
{
writer.Write(1u);
writer.Write(new byte[48000]);
}), reliable: true);
ManualLogSource log = ((BasePlugin)Plugin.Instance).Log;
bool flag3 = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(45, 2, ref flag3);
if (flag3)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Steam loopback sends accepted: join ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(flag);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", voice ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(flag2);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
}
log.LogInfo(val);
}
if (_smokeChannel == null)
{
return;
}
_smokeChannel.Read((ulong peer) => peer == _smokePeer, delegate(ulong _, byte[] bytes)
{
using BinaryReader reader = new BinaryReader(new MemoryStream(bytes));
if (Wire.Read(reader, out var kind, out var tag) && tag == 7)
{
_smokeJoinReceived |= kind == Message.Join && Wire.Remaining(reader) == 0;
_smokeVoiceReceived |= kind == Message.Play && Wire.Remaining(reader) == 48004;
if (_smokeJoinReceived && _smokeVoiceReceived)
{
((BasePlugin)Plugin.Instance).Log.LogInfo((object)"Steam loopback received both the join and max-size voice packets.");
_smokeProbeEnds = 0f;
}
}
});
if (!(unscaledTime < _smokeProbeEnds))
{
if (_smokeProbeEnds != 0f)
{
((BasePlugin)Plugin.Instance).Log.LogWarning((object)"Steam loopback send produced no received packet.");
}
CloseQuietly(_smokePeer);
_smokeChannel = null;
}
}
private static void TestHuntState()
{
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Expected O, but got Unknown
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Expected O, but got Unknown
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Invalid comparison between Unknown and I4
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_0200: Unknown result type (might be due to invalid IL or missing references)
//IL_0243: Unknown result type (might be due to invalid IL or missing references)
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
//IL_0258: Unknown result type (might be due to invalid IL or missing references)
CatchWindow catchWindow = new CatchWindow(2f);
if (catchWindow.Update(1u, 3f) || catchWindow.Update(1u, 4.5f) || catchWindow.Update(1u, 4.75f) || catchWindow.Update(0u, 4.8f) || catchWindow.Update(1u, 4.9f) || catchWindow.Update(2u, 5.1f) || !catchWindow.Update(2u, 5.6f))
{
throw new InvalidOperationException("Mimic contact grace, escape or elimination timing failed.");
}
using BinaryReader reader = new BinaryReader(new MemoryStream(Wire.Write(Message.State, 8uL, delegate(BinaryWriter writer)
{
Wire.WriteRoster(writer, roundOver: false, new uint[1] { 1u }, (IReadOnlyCollection<uint>)(object)new uint[2] { 2u, 3u });
})));
if (!Wire.Read(reader, out var kind, out var tag) || kind != Message.State || tag != 8)
{
throw new InvalidOperationException("Hunt packet header failed.");
}
HuntRoster huntRoster = Wire.ReadRoster(reader);
if (huntRoster.RoundOver || huntRoster.Alive.Length != 1 || huntRoster.Alive[0] != 1 || huntRoster.Eliminated.Length != 2 || huntRoster.Eliminated[1] != 3)
{
throw new InvalidOperationException("Survivors and spectating players did not round-trip.");
}
GameObject val = new GameObject("Spectator smoke fixture");
val.SetActive(false);
GameObject val2 = new GameObject("Spectator smoke target");
try
{
PlayerCharacter val3 = val.AddComponent<PlayerCharacter>();
val3.rb = val.AddComponent<Rigidbody>();
Camera val4 = val.AddComponent<Camera>();
Spectator spectator = new Spectator();
Vector3 localPosition = ((Component)val4).transform.localPosition;
RigidbodyConstraints constraints = val3.rb.constraints;
spectator.Enter(val3, val4);
if (!val3.bypassUpdate || !val3.bypassLateUpdate || !val3.bypassFixedUpdate || (int)val3.rb.constraints != 126)
{
throw new InvalidOperationException("Spectator failed to lock player controls.");
}
spectator.Select(4u);
val2.transform.position = new Vector3(0f, -550f, 0f);
spectator.Track(val2.transform, 0f);
if (spectator.Target != 4 || ((Component)val4).transform.position.y > -500f)
{
throw new InvalidOperationException("Spectator camera did not follow the survivor.");
}
spectator.Exit();
if (val3.bypassUpdate || val3.bypassLateUpdate || val3.bypassFixedUpdate || val3.rb.constraints != constraints || ((Component)val4).transform.localPosition != localPosition)
{
throw new InvalidOperationException("Spectator failed to restore player controls or camera.");
}
}
finally
{
Object.Destroy((Object)(object)val);
Object.Destroy((Object)(object)val2);
}
}
private void SmokeTest()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_002a: 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_0036: 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_0053: 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_005f: 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_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: 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_0097: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: 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_00ca: 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_00d9: 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_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_0233: Unknown result type (might be due to invalid IL or missing references)
SplitSpawn splitSpawn = new SplitSpawn();
Vector3[] positions = (Vector3[])(object)new Vector3[3]
{
Vector3.zero,
Vector3.right * 3f,
Vector3.right * 6f
};
Vector3[] positions2 = (Vector3[])(object)new Vector3[3]
{
Vector3.zero,
Vector3.right * 4f,
Vector3.right * 30f
};
Vector3[] positions3 = (Vector3[])(object)new Vector3[4]
{
Vector3.zero,
Vector3.right * 4f,
Vector3.right * 30f,
Vector3.right * 34f
};
if (splitSpawn.Ready((IReadOnlyList<Vector3>)(object)new Vector3[1] { Vector3.zero }, 0f, out var anchor, out var model) || splitSpawn.Ready(positions, 0f, out model, out anchor) || splitSpawn.Ready(positions2, 1f, out anchor, out model) || splitSpawn.Ready(positions2, 5f, out model, out anchor) || splitSpawn.Ready(positions, 6f, out anchor, out model) || splitSpawn.Ready(positions2, 8f, out model, out anchor) || !splitSpawn.Ready(positions2, 14f, out var anchor2, out var model2) || anchor2 != 2 || model2 == 2)
{
throw new InvalidOperationException("Timed split spawning failed");
}
splitSpawn.Reset();
if (splitSpawn.Ready(positions3, 20f, out anchor, out model) || !splitSpawn.Ready(positions3, 26f, out var anchor3, out var model3) || anchor3 > 1 || model3 < 2)
{
throw new InvalidOperationException("Two-group split spawning failed");
}
MovementMemory movementMemory = new MovementMemory();
for (int i = 0; i <= 40; i++)
{
movementMemory.Observe(new Vector3((float)i * 0.25f, 0f, 0f), 90f);
}
MovementMemory.Step[] array = movementMemory.Pick();
if (array == null || array.Length != 40)
{
throw new InvalidOperationException("Movement sampling failed");
}
MimicState example = new MimicState(1u, 5u, new Vector3(0f, -500f, 0f), 85f, 0.12f);
MimicActor mimicActor = new MimicActor(example, null);
try
{
using BinaryReader reader = new BinaryReader(new MemoryStream(Wire.Write(Message.State, 7uL, delegate(BinaryWriter writer)
{
Wire.WriteState(writer, example);
})));
if (!Wire.Read(reader, out var kind, out var tag) || tag != 7 || kind != Message.State || Wire.Remaining(reader) != 28 || Wire.ReadState(reader) != example)
{
throw new InvalidOperationException("State packet did not round trip");
}
byte[] array2 = new byte[3000];
Array.Fill(array2, (byte)128);
_voice.Add(example.Model, array2);
if (!_voice.TryPick(example.Model, out var pcm))
{
throw new InvalidOperationException("Voice bank failed");
}
mimicActor.Play(pcm);
_voice.Withdraw(example.Model);
if (_voice.TryPick(example.Model, out var _))
{
throw new InvalidOperationException("Voice withdrawal failed");
}
TestHuntState();
((BasePlugin)Plugin.Instance).Log.LogInfo((object)"Survival smoke passed: split timing, capture timing, spectator state encoding, movement and voice playback.");
}
finally
{
mimicActor.Dispose();
}
}
}
internal sealed class MovementMemory
{
internal readonly record struct Step(Vector3 Velocity, float Turn);
internal const float Interval = 0.125f;
private const int SegmentLength = 40;
private const int SegmentLimit = 8;
private readonly List<Step[]> _segments = new List<Step[]>();
private readonly List<Step> _steps = new List<Step>();
private Vector3 _position;
private float _yaw;
private int _movingSteps;
private bool _started;
internal void Observe(Vector3 position, float yaw)
{
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: 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_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: 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_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
if (_started)
{
Vector3 val = position - _position;
if (((Vector3)(ref val)).sqrMagnitude > 4f)
{
_steps.Clear();
_movingSteps = 0;
}
else
{
float num = Mathf.DeltaAngle(_yaw, yaw);
Vector3 velocity = Quaternion.Euler(0f, 0f - _yaw, 0f) * (val / 0.125f);
_steps.Add(new Step(velocity, num));
if (((Vector3)(ref val)).sqrMagnitude > 0.0064f || Mathf.Abs(num) > 9f)
{
_movingSteps++;
}
if (_steps.Count == 40)
{
if (_movingSteps >= 10)
{
if (_segments.Count == 8)
{
_segments.RemoveAt(0);
}
_segments.Add(_steps.ToArray());
}
_steps.Clear();
_movingSteps = 0;
}
}
}
_position = position;
_yaw = yaw;
_started = true;
}
internal Step[] Pick()
{
if (_segments.Count != 0)
{
return _segments[Random.Range(0, _segments.Count)];
}
if (_movingSteps < 10)
{
return null;
}
return _steps.ToArray();
}
}
[BepInPlugin("scout.bigwalk.mimics", "Big Walk Mimics", "0.4.0")]
public sealed class Plugin : BasePlugin
{
public const string Id = "scout.bigwalk.mimics";
internal static Plugin Instance;
internal ConfigEntry<KeyCode> Record;
internal ConfigEntry<KeyCode> Clear;
internal ConfigEntry<KeyCode> Restart;
internal ConfigEntry<bool> AutoSpawn;
public override void Load()
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Expected O, but got Unknown
Instance = this;
Record = ((BasePlugin)this).Config.Bind<KeyCode>("Keys", "RecordVoice", (KeyCode)288, "Hold to give the mimic a voice line.");
Clear = ((BasePlugin)this).Config.Bind<KeyCode>("Keys", "ClearVoice", (KeyCode)287, "Withdraw your voice samples from this session.");
Restart = ((BasePlugin)this).Config.Bind<KeyCode>("Keys", "RestartHunt", (KeyCode)292, "Host: restart the hunt and revive everyone.");
AutoSpawn = ((BasePlugin)this).Config.Bind<bool>("Host", "AutoSpawn", true, "Spawn mimics when the group splits up.");
ClassInjector.RegisterTypeInIl2Cpp<MimicMode>();
GameObject val = new GameObject("Big Walk Mimics");
Object.DontDestroyOnLoad((Object)val);
val.AddComponent<MimicMode>();
((BasePlugin)this).Log.LogInfo((object)"Ready. Run from mimics. Caught players spectate. F11 restarts the hunt (host).");
}
}
internal sealed class Spectator
{
private PlayerCharacter _player;
private Camera _camera;
private Rigidbody _body;
private RigidbodyConstraints _constraints;
private Vector3 _cameraPosition;
private Quaternion _cameraRotation;
private bool _bypassUpdate;
private bool _bypassLateUpdate;
private bool _bypassFixedUpdate;
private bool _snap;
private uint _target;
internal uint Target => _target;
internal void Enter(PlayerCharacter player, Camera camera)
{
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_player != (Object)(object)player)
{
Exit();
_player = player;
_bypassUpdate = player.bypassUpdate;
_bypassLateUpdate = player.bypassLateUpdate;
_bypassFixedUpdate = player.bypassFixedUpdate;
bool flag = (player.bypassFixedUpdate = true);
bool bypassUpdate = (player.bypassLateUpdate = flag);
player.bypassUpdate = bypassUpdate;
_body = player.rb;
if ((Object)(object)_body != (Object)null)
{
_constraints = _body.constraints;
_body.constraints = (RigidbodyConstraints)126;
}
}
if (!((Object)(object)camera == (Object)null) && !((Object)(object)_camera == (Object)(object)camera))
{
RestoreCamera();
_camera = camera;
_cameraPosition = ((Component)camera).transform.localPosition;
_cameraRotation = ((Component)camera).transform.localRotation;
_snap = true;
}
}
internal void Select(uint target)
{
if (_target != target)
{
_target = target;
_snap = true;
}
}
internal void Track(Transform subject, float yaw)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_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_003d: 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_0056: 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_0064: 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_006b: 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_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: 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)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)_camera == (Object)null) && !((Object)(object)subject == (Object)null))
{
Vector3 val = subject.position + Vector3.up * 1.65f;
Vector3 val2 = Quaternion.Euler(0f, yaw, 0f) * new Vector3(0f, 1.15f, -3.4f);
float num = ((Vector3)(ref val2)).magnitude;
Vector3 val3 = val2 / num;
RaycastHit val4 = default(RaycastHit);
if (Physics.SphereCast(val, 0.16f, val3, ref val4, num, -5, (QueryTriggerInteraction)1))
{
num = Mathf.Max(0.25f, ((RaycastHit)(ref val4)).distance - 0.1f);
}
Vector3 val5 = val + val3 * num;
Quaternion val6 = Quaternion.LookRotation(val - val5);
Transform transform = ((Component)_camera).transform;
float num2 = (_snap ? 1f : (1f - Mathf.Exp(-12f * Time.unscaledDeltaTime)));
transform.SetPositionAndRotation(Vector3.Lerp(transform.position, val5, num2), Quaternion.Slerp(transform.rotation, val6, num2));
_snap = false;
}
}
internal void Exit()
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
RestoreCamera();
if ((Object)(object)_player != (Object)null)
{
_player.bypassUpdate = _bypassUpdate;
_player.bypassLateUpdate = _bypassLateUpdate;
_player.bypassFixedUpdate = _bypassFixedUpdate;
}
if ((Object)(object)_body != (Object)null)
{
_body.constraints = _constraints;
}
_player = null;
_body = null;
_target = 0u;
}
private void RestoreCamera()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_camera != (Object)null)
{
((Component)_camera).transform.localPosition = _cameraPosition;
((Component)_camera).transform.localRotation = _cameraRotation;
}
_camera = null;
}
}
internal sealed class SplitSpawn
{
private const float DistanceSquared = 324f;
private const float Delay = 6f;
private int[] _group = Array.Empty<int>();
private int[] _queue = Array.Empty<int>();
private float _since = -1f;
internal bool Ready(IReadOnlyList<Vector3> positions, float now, out int anchor, out int model)
{
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
anchor = (model = -1);
int count = positions.Count;
if (_group.Length < count)
{
_group = new int[count];
_queue = new int[count];
}
Array.Fill(_group, -1, 0, count);
int num = 0;
int num2 = count + 1;
for (int i = 0; i < count; i++)
{
if (_group[i] >= 0)
{
continue;
}
int num3 = 1;
_queue[0] = i;
_group[i] = num;
for (int j = 0; j < num3; j++)
{
Vector3 val = positions[_queue[j]];
for (int k = 0; k < count; k++)
{
if (_group[k] < 0)
{
Vector3 val2 = val - positions[k];
if (!(((Vector3)(ref val2)).sqrMagnitude >= 324f))
{
_group[k] = num;
_queue[num3++] = k;
}
}
}
}
if (num3 < num2)
{
num2 = num3;
anchor = i;
}
num++;
}
if (num < 2)
{
Reset();
return false;
}
if (_since < 0f)
{
_since = now;
}
if (now - _since < 6f)
{
return false;
}
for (int l = 0; l < count; l++)
{
if (_group[l] != _group[anchor])
{
model = l;
break;
}
}
return true;
}
internal void Reset()
{
_since = -1f;
}
}
internal sealed class SteamChannel
{
private const int Channel = 21974;
private const int MaxPacket = 48017;
private readonly Il2CppStructArray<IntPtr> _incoming = new Il2CppStructArray<IntPtr>(16L);
internal static void Accept(ulong player)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
SteamNetworkingIdentity val = new SteamNetworkingIdentity();
val.SetSteamID64(player);
SteamNetworkingMessages.AcceptSessionWithUser(ref val);
}
internal static void Close(ulong player)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
SteamNetworkingIdentity val = new SteamNetworkingIdentity();
val.SetSteamID64(player);
SteamNetworkingMessages.CloseChannelWithUser(ref val, 21974);
}
internal static bool Send(ulong player, byte[] payload, bool reliable)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Invalid comparison between Unknown and I4
SteamNetworkingIdentity val = new SteamNetworkingIdentity();
val.SetSteamID64(player);
GCHandle gCHandle = GCHandle.Alloc(payload, GCHandleType.Pinned);
try
{
int num = (reliable ? Constants.k_nSteamNetworkingSend_ReliableNoNagle : Constants.k_nSteamNetworkingSend_UnreliableNoDelay);
num |= Constants.k_nSteamNetworkingSend_AutoRestartBrokenSession;
return (int)SteamNetworkingMessages.SendMessageToUser(ref val, gCHandle.AddrOfPinnedObject(), (uint)payload.Length, num, 21974) == 1;
}
finally
{
gCHandle.Free();
}
}
internal void Read(Func<ulong, bool> allowed, Action<ulong, byte[]> receive)
{
int num = SteamNetworkingMessages.ReceiveMessagesOnChannel(21974, _incoming, ((Il2CppArrayBase<IntPtr>)(object)_incoming).Length);
for (int i = 0; i < num; i++)
{
IntPtr intPtr = ((Il2CppArrayBase<IntPtr>)(object)_incoming)[i];
try
{
SteamNetworkingMessage_t val = SteamNetworkingMessage_t.FromIntPtr(intPtr);
ulong steamID = val.m_identityPeer.GetSteamID64();
if (allowed(steamID) && val.m_cbSize >= 13 && val.m_cbSize <= 48017)
{
byte[] array = new byte[val.m_cbSize];
Marshal.Copy(val.m_pData, array, 0, array.Length);
receive(steamID, array);
}
}
finally
{
SteamNetworkingMessage_t.Release(intPtr);
}
}
}
}
internal sealed class VoiceMemory
{
internal const int Rate = 12000;
internal const int MaxLength = 48000;
internal const int MinLength = 3000;
private readonly Dictionary<uint, Queue<byte[]>> _voices = new Dictionary<uint, Queue<byte[]>>();
private readonly List<float> _recording = new List<float>(192000);
private LocalVoiceProvider _source;
private int _lastHead;
private int _sampleRate;
private int _channels;
private float _stop;
internal bool Recording => (Object)(object)_source != (Object)null;
internal bool Start()
{
WorldManager instance = WorldManager.instance;
LocalVoiceProvider val = (((Object)(object)instance != (Object)null) ? instance.localVoiceProvider : null);
if ((Object)(object)val == (Object)null || val._format == null || val.CachedVoiceData == null || ((Il2CppArrayBase<float>)(object)val.CachedVoiceData).Length == 0)
{
return false;
}
_sampleRate = val._format.SampleRate;
_channels = val._channelCount;
int sampleRate = _sampleRate;
bool flag = ((sampleRate < 8000 || sampleRate > 192000) ? true : false);
bool flag2 = flag;
if (!flag2)
{
int channels = _channels;
bool flag3 = ((channels < 1 || channels > 8) ? true : false);
flag2 = flag3;
}
if (flag2)
{
return false;
}
_lastHead = val.CachedVoiceWriteHead;
_recording.Clear();
_stop = Time.unscaledTime + 4f;
_source = val;
return true;
}
internal bool Poll(bool held, out byte[] sample)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Expected O, but got Unknown
sample = null;
LocalVoiceProvider source = _source;
Il2CppStructArray<float> val = (((Object)(object)source != (Object)null) ? source.CachedVoiceData : null);
if (val != null && ((Il2CppArrayBase<float>)(object)val).Length >= _channels)
{
Object val2 = new Object(((Il2CppObjectBase)val).Pointer);
Monitor.Enter(val2);
try
{
int cachedVoiceWriteHead = source.CachedVoiceWriteHead;
int num = cachedVoiceWriteHead - _lastHead;
if (num < 0)
{
num += ((Il2CppArrayBase<float>)(object)val).Length;
}
if (num > 0 && num <= Math.Min(((Il2CppArrayBase<float>)(object)val).Length, _sampleRate * _channels / 2))
{
for (int i = 0; i + _channels <= num; i += _channels)
{
if (_recording.Count >= _sampleRate * 4)
{
break;
}
_recording.Add(((Il2CppArrayBase<float>)(object)val)[(_lastHead + i) % ((Il2CppArrayBase<float>)(object)val).Length]);
}
}
_lastHead = cachedVoiceWriteHead;
}
finally
{
Monitor.Exit(val2);
}
}
if (held && (Object)(object)source != (Object)null && Time.unscaledTime < _stop)
{
return false;
}
_source = null;
int num2 = Mathf.Min(48000, (int)((long)_recording.Count * 12000L / _sampleRate));
if (num2 >= 3000)
{
sample = new byte[num2];
float num3 = 0f;
for (int j = 0; j < num2; j++)
{
int num4 = (int)((long)j * (long)_sampleRate / 12000);
int num5 = Math.Max(num4 + 1, (int)((long)(j + 1) * (long)_sampleRate / 12000));
float num6 = 0f;
for (int k = num4; k < num5; k++)
{
num6 += _recording[k];
}
float num7 = num6 / (float)(num5 - num4);
if (!float.IsFinite(num7))
{
num7 = 0f;
}
num3 = Mathf.Max(num3, Mathf.Abs(num7));
sample[j] = (byte)Mathf.RoundToInt(128f + Mathf.Clamp(num7, -1f, 1f) * 127f);
}
if (num3 < 0.008f)
{
sample = null;
}
}
_recording.Clear();
return true;
}
internal void Add(uint player, byte[] pcm)
{
if (!_voices.TryGetValue(player, out var value))
{
value = (_voices[player] = new Queue<byte[]>(4));
}
if (value.Count == 4)
{
value.Dequeue();
}
value.Enqueue(pcm);
}
internal void Withdraw(uint player)
{
_voices.Remove(player);
}
internal bool TryPick(uint player, out byte[] pcm)
{
pcm = null;
if (!_voices.TryGetValue(player, out var value) || value.Count == 0)
{
return false;
}
pcm = value.Dequeue();
value.Enqueue(pcm);
return true;
}
internal static AudioClip MakeClip(byte[] pcm)
{
float[] array = new float[pcm.Length];
for (int i = 0; i < array.Length; i++)
{
array[i] = (float)(pcm[i] - 128) / 127f;
}
AudioClip val = AudioClip.Create("Mimic voice", array.Length, 1, 12000, false);
if ((Object)(object)val == (Object)null || val.SetData(Il2CppStructArray<float>.op_Implicit(array), 0))
{
return val;
}
Object.Destroy((Object)(object)val);
return null;
}
internal void Cancel()
{
_source = null;
_recording.Clear();
}
internal void Clear()
{
Cancel();
_voices.Clear();
}
}
internal enum Message : byte
{
Join,
Welcome,
State,
Sample,
Withdraw,
Play,
Stop
}
internal static class Wire
{
private const uint Magic = 877483842u;
internal const int HeaderSize = 13;
internal const int MaxMimics = 2;
internal const int MaxPlayers = 12;
internal const int StateSize = 28;
internal static byte[] Write(Message kind, ulong tag, Action<BinaryWriter> write = null)
{
using MemoryStream memoryStream = new MemoryStream();
using BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(877483842u);
binaryWriter.Write((byte)kind);
binaryWriter.Write(tag);
write?.Invoke(binaryWriter);
return memoryStream.ToArray();
}
internal static bool Read(BinaryReader reader, out Message kind, out ulong tag)
{
kind = Message.Join;
tag = 0uL;
if (reader.BaseStream.Length < 13 || reader.ReadUInt32() != 877483842)
{
return false;
}
kind = (Message)reader.ReadByte();
tag = reader.ReadUInt64();
return tag != 0;
}
internal static int Remaining(BinaryReader reader)
{
return (int)(reader.BaseStream.Length - reader.BaseStream.Position);
}
internal static void WriteState(BinaryWriter writer, MimicState state)
{
//IL_001d: 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_0041: Unknown result type (might be due to invalid IL or missing references)
writer.Write(state.Id);
writer.Write(state.Model);
writer.Write(state.Position.x);
writer.Write(state.Position.y);
writer.Write(state.Position.z);
writer.Write(state.Yaw);
writer.Write(state.Bob);
}
internal static MimicState ReadState(BinaryReader reader)
{
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
uint num = reader.ReadUInt32();
uint num2 = reader.ReadUInt32();
Vector3 position = default(Vector3);
((Vector3)(ref position))..ctor(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
float num3 = reader.ReadSingle();
float num4 = reader.ReadSingle();
bool flag = num == 0 || num2 == 0 || !float.IsFinite(((Vector3)(ref position)).sqrMagnitude) || ((Vector3)(ref position)).sqrMagnitude > 1E+12f || !float.IsFinite(num3);
if (!flag)
{
bool flag2 = ((num4 < -1f || num4 > 2f) ? true : false);
flag = flag2;
}
if (flag || !float.IsFinite(num4))
{
throw new InvalidDataException("Invalid mimic state.");
}
return new MimicState(num, num2, position, num3, num4);
}
internal static void WriteRoster(BinaryWriter writer, bool roundOver, IReadOnlyList<uint> alive, IReadOnlyCollection<uint> eliminated)
{
writer.Write(roundOver);
writer.Write((byte)alive.Count);
foreach (uint item in alive)
{
writer.Write(item);
}
writer.Write((byte)eliminated.Count);
foreach (uint item2 in eliminated)
{
writer.Write(item2);
}
}
internal static HuntRoster ReadRoster(BinaryReader reader)
{
byte num = reader.ReadByte();
if (num > 1)
{
throw new InvalidDataException("Invalid hunt status.");
}
HashSet<uint> hashSet = new HashSet<uint>();
uint[] alive = ReadPlayers(reader, hashSet);
uint[] eliminated = ReadPlayers(reader, hashSet);
if (hashSet.Count > 12 || Remaining(reader) != 0)
{
throw new InvalidDataException("Invalid hunt roster.");
}
return new HuntRoster(num == 1, alive, eliminated);
}
private static uint[] ReadPlayers(BinaryReader reader, HashSet<uint> seen)
{
byte num = reader.ReadByte();
if (num > 12)
{
throw new InvalidDataException("Too many players in hunt roster.");
}
uint[] array = new uint[num];
for (int i = 0; i < array.Length; i++)
{
uint num2 = reader.ReadUInt32();
if (num2 == 0 || !seen.Add(num2))
{
throw new InvalidDataException("Duplicate or invalid hunt player.");
}
array[i] = num2;
}
return array;
}
}
internal readonly record struct MimicState(uint Id, uint Model, Vector3 Position, float Yaw, float Bob);
internal readonly record struct HuntRoster(bool RoundOver, uint[] Alive, uint[] Eliminated);
}